Skip to content

Добавлена фабрика по созданию ревит параметров #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/dosymep.Bim4Everyone/SimpleServices/IRevitParamFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Autodesk.Revit.DB;

namespace dosymep.Bim4Everyone.SimpleServices {
/// <summary>
/// Определяет фабрику для создания экземпляров RevitParam.
/// </summary>
public interface IRevitParamFactory {
/// <summary>
/// Создаёт новый экземпляр класса RevitParam.
/// </summary>
/// <param name="document">Revit-документ, в котором находится параметр.</param>
/// <param name="paramId">Идентификатор создаваемого параметра.</param>
/// <returns>Возвращает экземпляр RevitParam, соответствующий заданному идентификатору параметра.</returns>
RevitParam Create(Document document, ElementId paramId);

/// <summary>
/// Проверяет возможность создания экземпляра RevitParam на основе заданного документа и идентификатора параметра.
/// </summary>
/// <param name="document">Revit-документ, в котором выполняется проверка.</param>
/// <param name="paramId">Идентификатор параметра, для которого требуется проверить возможность создания.</param>
/// <returns>Возвращает true, если возможно создать экземпляр RevitParam; в противном случае возвращает false.</returns>
bool CanCreate(Document document, ElementId paramId);
}
}
71 changes: 71 additions & 0 deletions src/dosymep.Bim4Everyone/SimpleServices/RevitParamFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;

using Autodesk.Revit.DB;

using dosymep.Revit;

namespace dosymep.Bim4Everyone.SimpleServices {
/// <summary>
/// Фабрика для создания экземпляров RevitParam.
/// </summary>
internal class RevitParamFactory : IRevitParamFactory {
private readonly IParamElementService _projectParamsService;
private readonly IParamElementService _sharedParamsService;
private readonly ISystemParamsService _systemParamsService;

public RevitParamFactory(
IProjectParamsService projectParamsService,
ISharedParamsService sharedParamsService,
ISystemParamsService systemParamsService) {
_projectParamsService = projectParamsService;
_sharedParamsService = sharedParamsService;
_systemParamsService = systemParamsService;
}

/// <inheritdoc />
public RevitParam Create(Document document, ElementId paramId) {
if(document == null) {
throw new ArgumentNullException(nameof(document));
}

if(paramId.IsNull()) {
throw new ArgumentNullException(nameof(paramId));
}

return paramId.IsNotSystemId()
? Create(document, document.GetElement(paramId) as ParameterElement)
: _systemParamsService.CreateRevitParam(document, paramId.AsBuiltInParameter());
}

/// <inheritdoc />
public bool CanCreate(Document document, ElementId paramId) {
if(document == null) {
return false;
}

if(paramId.IsNull()) {
return false;
}

if(paramId.IsSystemId()) {
return true;
}

return document.GetElement(paramId) is ParameterElement;
}

private RevitParam Create(Document document, ParameterElement paramElement) {
if(document == null) {
throw new ArgumentNullException(nameof(document));
}

if(paramElement == null) {
throw new ArgumentNullException(nameof(paramElement));
}

return paramElement.IsSharedParam()
? _sharedParamsService.CreateRevitParam(document, paramElement)
: _projectParamsService.CreateRevitParam(document, paramElement);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI;

using dosymep.Bim4Everyone.ProjectParams;
using dosymep.Bim4Everyone.SharedParams;
using dosymep.Bim4Everyone.SimpleServices.InvokeButtons;
using dosymep.Bim4Everyone.SystemParams;
using dosymep.SimpleServices;

using Ninject.Modules;
Expand All @@ -18,15 +21,15 @@ public override void Load() {
Bind<UIApplication>()
.ToConstant(_uiApplication)
.InTransientScope();

Bind<Application>()
.ToConstant(_uiApplication.Application)
.InTransientScope();

Bind<ILanguageService>()
.To<RevitLanguageService>()
.InSingletonScope();

Bind<IPlatformCommandsService>()
.To<PlatformCommandsService>();

Expand All @@ -38,6 +41,22 @@ public override void Load() {
Bind<IBimModelPartsService>()
.To<BimModelPartsService>()
.InSingletonScope();

Bind<IRevitParamFactory>()
.To<RevitParamFactory>()
.InSingletonScope();

Bind<ISystemParamsService>()
.ToConstant(SystemParamsConfig.Instance)
.InSingletonScope();

Bind<ISharedParamsService>()
.ToConstant(SharedParamsConfig.Instance)
.InSingletonScope();

Bind<IProjectParamsService>()
.ToConstant(ProjectParamsConfig.Instance)
.InSingletonScope();
}
}
}
Loading