Skip to content

Commit

Permalink
Рефакторинг
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastroG committed Oct 28, 2024
1 parent 63b47cc commit f1907cd
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 160 deletions.
25 changes: 11 additions & 14 deletions src/RevitOpeningPlacement/GetOpeningTasksCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;

using dosymep.Bim4Everyone;
Expand Down Expand Up @@ -219,22 +216,22 @@ private void GetOpeningsTaskInDocumentMEP(IKernel kernel) {
kernel.Bind<GeometryUtils>()
.ToSelf()
.InSingletonScope();
kernel.Bind<IOutcomingTaskOffsetFinder<Pipe>>()
.To<PipeOffsetFinder>()
kernel.Bind<PipeOffsetFinder>()
.ToSelf()
.InTransientScope();
kernel.Bind<IOutcomingTaskOffsetFinder<Duct>>()
.To<DuctOffsetFinder>()
kernel.Bind<DuctOffsetFinder>()
.ToSelf()
.InTransientScope();
kernel.Bind<IOutcomingTaskOffsetFinder<Conduit>>()
.To<ConduitOffsetFinder>()
kernel.Bind<ConduitOffsetFinder>()
.ToSelf()
.InTransientScope();
kernel.Bind<IOutcomingTaskOffsetFinder<CableTray>>()
.To<CableTrayOffsetFinder>()
kernel.Bind<CableTrayOffsetFinder>()
.ToSelf()
.InTransientScope();
kernel.Bind<IOutcomingTaskOffsetFinder<FamilyInstance>>()
.To<FamilyInstanceOffsetFinder>()
kernel.Bind<FamilyInstanceOffsetFinder>()
.ToSelf()
.InTransientScope();
kernel.Bind<IOutcomingTaskOffsetFinder<Element>>()
kernel.Bind<IOutcomingTaskOffsetFinder>()
.To<ElementOffsetFinder>()
.InTransientScope();

Expand Down
27 changes: 26 additions & 1 deletion src/RevitOpeningPlacement/Services/CableTrayOffsetFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
using RevitClashDetective.Models.Extensions;

using RevitOpeningPlacement.Models.Configs;
using RevitOpeningPlacement.OpeningModels;

namespace RevitOpeningPlacement.Services {
internal class CableTrayOffsetFinder : OutcomingTaskOffsetFinder<CableTray> {
internal class CableTrayOffsetFinder : OutcomingTaskOffsetFinder<CableTray>, IOutcomingTaskOffsetFinder {
private MepCategory _category;

public CableTrayOffsetFinder(
Expand Down Expand Up @@ -50,5 +51,29 @@ protected override Solid GetMepSolid(CableTray cableTray) {
.ToList();
return ElementExtensions.UniteSolids(solids);
}

public double FindHorizontalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindHorizontalOffsetsSum(opening, mepElement as CableTray);
}

public double FindVerticalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindHorizontalOffsetsSum(opening, mepElement as CableTray);
}

public double GetMinHorizontalOffsetSum(Element mepElement) {
return base.GetMinHorizontalOffsetSum(mepElement as CableTray);
}

public double GetMaxHorizontalOffsetSum(Element mepElement) {
return base.GetMaxHorizontalOffsetSum(mepElement as CableTray);
}

public double GetMinVerticalOffsetSum(Element mepElement) {
return base.GetMinVerticalOffsetSum(mepElement as CableTray);
}

public double GetMaxVerticalOffsetSum(Element mepElement) {
return base.GetMaxVerticalOffsetSum(mepElement as CableTray);
}
}
}
27 changes: 26 additions & 1 deletion src/RevitOpeningPlacement/Services/ConduitOffsetFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
using RevitClashDetective.Models.Extensions;

using RevitOpeningPlacement.Models.Configs;
using RevitOpeningPlacement.OpeningModels;

namespace RevitOpeningPlacement.Services {
internal class ConduitOffsetFinder : OutcomingTaskOffsetFinder<Conduit> {
internal class ConduitOffsetFinder : OutcomingTaskOffsetFinder<Conduit>, IOutcomingTaskOffsetFinder {
private MepCategory _category;

public ConduitOffsetFinder(
Expand Down Expand Up @@ -38,5 +39,29 @@ protected override MepCategory GetCategory(Conduit mepElement) {
protected override Solid GetMepSolid(Conduit mepElement) {
return mepElement.GetSolid();
}

public double FindHorizontalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindHorizontalOffsetsSum(opening, mepElement as Conduit);
}

public double FindVerticalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindVerticalOffsetsSum(opening, mepElement as Conduit);
}

public double GetMinHorizontalOffsetSum(Element mepElement) {
return base.GetMinHorizontalOffsetSum(mepElement as Conduit);
}

public double GetMaxHorizontalOffsetSum(Element mepElement) {
return base.GetMaxHorizontalOffsetSum(mepElement as Conduit);
}

public double GetMinVerticalOffsetSum(Element mepElement) {
return base.GetMinVerticalOffsetSum(mepElement as Conduit);
}

public double GetMaxVerticalOffsetSum(Element mepElement) {
return base.GetMaxVerticalOffsetSum(mepElement as Conduit);
}
}
}
27 changes: 26 additions & 1 deletion src/RevitOpeningPlacement/Services/DuctOffsetFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
using RevitClashDetective.Models.Extensions;

using RevitOpeningPlacement.Models.Configs;
using RevitOpeningPlacement.OpeningModels;

namespace RevitOpeningPlacement.Services {
internal class DuctOffsetFinder : OutcomingTaskOffsetFinder<Duct> {
internal class DuctOffsetFinder : OutcomingTaskOffsetFinder<Duct>, IOutcomingTaskOffsetFinder {
private MepCategory _roundCategory;
private MepCategory _rectangleCategory;

Expand Down Expand Up @@ -52,5 +53,29 @@ protected override double GetWidth(Duct mepElement) {
protected override Solid GetMepSolid(Duct mepElement) {
return mepElement.GetSolid();
}

public double FindHorizontalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindHorizontalOffsetsSum(opening, mepElement as Duct);
}

public double FindVerticalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindVerticalOffsetsSum(opening, mepElement as Duct);
}

public double GetMinHorizontalOffsetSum(Element mepElement) {
return base.GetMinHorizontalOffsetSum(mepElement as Duct);
}

public double GetMaxHorizontalOffsetSum(Element mepElement) {
return base.GetMaxHorizontalOffsetSum(mepElement as Duct);
}

public double GetMinVerticalOffsetSum(Element mepElement) {
return base.GetMinVerticalOffsetSum(mepElement as Duct);
}

public double GetMaxVerticalOffsetSum(Element mepElement) {
return base.GetMaxVerticalOffsetSum(mepElement as Duct);
}
}
}
116 changes: 30 additions & 86 deletions src/RevitOpeningPlacement/Services/ElementOffsetFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
using RevitOpeningPlacement.OpeningModels;

namespace RevitOpeningPlacement.Services {
internal class ElementOffsetFinder : IOutcomingTaskOffsetFinder<Element> {
private readonly IOutcomingTaskOffsetFinder<Pipe> _pipeFinder;
private readonly IOutcomingTaskOffsetFinder<Duct> _ductFinder;
private readonly IOutcomingTaskOffsetFinder<Conduit> _conduitFinder;
private readonly IOutcomingTaskOffsetFinder<CableTray> _cableTrayFinder;
private readonly IOutcomingTaskOffsetFinder<FamilyInstance> _familyInstanceFinder;
internal class ElementOffsetFinder : IOutcomingTaskOffsetFinder {
private readonly PipeOffsetFinder _pipeFinder;
private readonly DuctOffsetFinder _ductFinder;
private readonly ConduitOffsetFinder _conduitFinder;
private readonly CableTrayOffsetFinder _cableTrayFinder;
private readonly FamilyInstanceOffsetFinder _familyInstanceFinder;


public ElementOffsetFinder(
IOutcomingTaskOffsetFinder<Pipe> pipeFinder,
IOutcomingTaskOffsetFinder<Duct> ductFinder,
IOutcomingTaskOffsetFinder<Conduit> conduitFinder,
IOutcomingTaskOffsetFinder<CableTray> cableTrayFinder,
IOutcomingTaskOffsetFinder<FamilyInstance> familyInstanceFinder) {
PipeOffsetFinder pipeFinder,
DuctOffsetFinder ductFinder,
ConduitOffsetFinder conduitFinder,
CableTrayOffsetFinder cableTrayFinder,
FamilyInstanceOffsetFinder familyInstanceFinder) {

_pipeFinder = pipeFinder
?? throw new ArgumentNullException(nameof(pipeFinder));
Expand All @@ -37,96 +37,40 @@ public ElementOffsetFinder(


public double FindHorizontalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
if(mepElement is Pipe pipe) {
return _pipeFinder.FindHorizontalOffsetsSum(opening, pipe);
} else if(mepElement is Duct duct) {
return _ductFinder.FindHorizontalOffsetsSum(opening, duct);
} else if(mepElement is Conduit conduit) {
return _conduitFinder.FindHorizontalOffsetsSum(opening, conduit);
} else if(mepElement is CableTray cableTray) {
return _cableTrayFinder.FindHorizontalOffsetsSum(opening, cableTray);
} else if(mepElement is FamilyInstance familyInstance) {
return _familyInstanceFinder.FindHorizontalOffsetsSum(opening, familyInstance);
} else {
throw new InvalidOperationException($"Type doesn't support: {mepElement.GetType().FullName}");
}
return GetOffsetFinder(mepElement).FindHorizontalOffsetsSum(opening, mepElement);
}

public double FindVerticalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
if(mepElement is Pipe pipe) {
return _pipeFinder.FindVerticalOffsetsSum(opening, pipe);
} else if(mepElement is Duct duct) {
return _ductFinder.FindVerticalOffsetsSum(opening, duct);
} else if(mepElement is Conduit conduit) {
return _conduitFinder.FindVerticalOffsetsSum(opening, conduit);
} else if(mepElement is CableTray cableTray) {
return _cableTrayFinder.FindVerticalOffsetsSum(opening, cableTray);
} else if(mepElement is FamilyInstance familyInstance) {
return _familyInstanceFinder.FindVerticalOffsetsSum(opening, familyInstance);
} else {
throw new InvalidOperationException($"Type doesn't support: {mepElement.GetType().FullName}");
}
return GetOffsetFinder(mepElement).FindVerticalOffsetsSum(opening, mepElement);
}

public double GetMaxHorizontalOffsetSum(Element mepElement) {
if(mepElement is Pipe pipe) {
return _pipeFinder.GetMaxHorizontalOffsetSum(pipe);
} else if(mepElement is Duct duct) {
return _ductFinder.GetMaxHorizontalOffsetSum(duct);
} else if(mepElement is Conduit conduit) {
return _conduitFinder.GetMaxHorizontalOffsetSum(conduit);
} else if(mepElement is CableTray cableTray) {
return _cableTrayFinder.GetMaxHorizontalOffsetSum(cableTray);
} else if(mepElement is FamilyInstance familyInstance) {
return _familyInstanceFinder.GetMaxHorizontalOffsetSum(familyInstance);
} else {
throw new InvalidOperationException($"Type doesn't support: {mepElement.GetType().FullName}");
}
return GetOffsetFinder(mepElement).GetMaxHorizontalOffsetSum(mepElement);
}

public double GetMinHorizontalOffsetSum(Element mepElement) {
if(mepElement is Pipe pipe) {
return _pipeFinder.GetMinHorizontalOffsetSum(pipe);
} else if(mepElement is Duct duct) {
return _ductFinder.GetMinHorizontalOffsetSum(duct);
} else if(mepElement is Conduit conduit) {
return _conduitFinder.GetMinHorizontalOffsetSum(conduit);
} else if(mepElement is CableTray cableTray) {
return _cableTrayFinder.GetMinHorizontalOffsetSum(cableTray);
} else if(mepElement is FamilyInstance familyInstance) {
return _familyInstanceFinder.GetMinHorizontalOffsetSum(familyInstance);
} else {
throw new InvalidOperationException($"Type doesn't support: {mepElement.GetType().FullName}");
}
return GetOffsetFinder(mepElement).GetMinHorizontalOffsetSum(mepElement);
}

public double GetMaxVerticalOffsetSum(Element mepElement) {
if(mepElement is Pipe pipe) {
return _pipeFinder.GetMaxVerticalOffsetSum(pipe);
} else if(mepElement is Duct duct) {
return _ductFinder.GetMaxVerticalOffsetSum(duct);
} else if(mepElement is Conduit conduit) {
return _conduitFinder.GetMaxVerticalOffsetSum(conduit);
} else if(mepElement is CableTray cableTray) {
return _cableTrayFinder.GetMaxVerticalOffsetSum(cableTray);
} else if(mepElement is FamilyInstance familyInstance) {
return _familyInstanceFinder.GetMaxVerticalOffsetSum(familyInstance);
} else {
throw new InvalidOperationException($"Type doesn't support: {mepElement.GetType().FullName}");
}
return GetOffsetFinder(mepElement).GetMaxVerticalOffsetSum(mepElement);
}

public double GetMinVerticalOffsetSum(Element mepElement) {
if(mepElement is Pipe pipe) {
return _pipeFinder.GetMinVerticalOffsetSum(pipe);
} else if(mepElement is Duct duct) {
return _ductFinder.GetMinVerticalOffsetSum(duct);
} else if(mepElement is Conduit conduit) {
return _conduitFinder.GetMinVerticalOffsetSum(conduit);
} else if(mepElement is CableTray cableTray) {
return _cableTrayFinder.GetMinVerticalOffsetSum(cableTray);
} else if(mepElement is FamilyInstance familyInstance) {
return _familyInstanceFinder.GetMinVerticalOffsetSum(familyInstance);
return GetOffsetFinder(mepElement).GetMinVerticalOffsetSum(mepElement);
}

private IOutcomingTaskOffsetFinder GetOffsetFinder(Element mepElement) {
if(mepElement is Pipe) {
return _pipeFinder;
} else if(mepElement is Duct) {
return _ductFinder;
} else if(mepElement is Conduit) {
return _conduitFinder;
} else if(mepElement is CableTray) {
return _cableTrayFinder;
} else if(mepElement is FamilyInstance) {
return _familyInstanceFinder;
} else {
throw new InvalidOperationException($"Type doesn't support: {mepElement.GetType().FullName}");
}
Expand Down
27 changes: 26 additions & 1 deletion src/RevitOpeningPlacement/Services/FamilyInstanceOffsetFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
using RevitClashDetective.Models.Extensions;

using RevitOpeningPlacement.Models.Configs;
using RevitOpeningPlacement.OpeningModels;

namespace RevitOpeningPlacement.Services {
internal class FamilyInstanceOffsetFinder : OutcomingTaskOffsetFinder<FamilyInstance> {
internal class FamilyInstanceOffsetFinder : OutcomingTaskOffsetFinder<FamilyInstance>, IOutcomingTaskOffsetFinder {
public FamilyInstanceOffsetFinder(
OpeningConfig openingConfig,
OutcomingTaskGeometryProvider geometryProvider,
Expand Down Expand Up @@ -60,5 +61,29 @@ protected override double GetWidth(FamilyInstance mepElement) {
protected override Solid GetMepSolid(FamilyInstance mepElement) {
return mepElement.GetSolid();
}

public double FindHorizontalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindHorizontalOffsetsSum(opening, mepElement as FamilyInstance);
}

public double FindVerticalOffsetsSum(OpeningMepTaskOutcoming opening, Element mepElement) {
return base.FindVerticalOffsetsSum(opening, mepElement as FamilyInstance);
}

public double GetMinHorizontalOffsetSum(Element mepElement) {
return base.GetMinHorizontalOffsetSum(mepElement as FamilyInstance);
}

public double GetMaxHorizontalOffsetSum(Element mepElement) {
return base.GetMaxHorizontalOffsetSum(mepElement as FamilyInstance);
}

public double GetMinVerticalOffsetSum(Element mepElement) {
return base.GetMinVerticalOffsetSum(mepElement as FamilyInstance);
}

public double GetMaxVerticalOffsetSum(Element mepElement) {
return base.GetMaxVerticalOffsetSum(mepElement as FamilyInstance);
}
}
}
Loading

0 comments on commit f1907cd

Please sign in to comment.