-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1021 from srudenkoamc/ifc-serialization-refactoring
Ifc serialization improvements
- Loading branch information
Showing
34 changed files
with
125,200 additions
and
914 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Elements.Serialization.IFC/src/IFCToHypar/Converters/CompositeFromIfcProductConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Elements.Serialization.IFC.IFCToHypar.RepresentationsExtraction; | ||
using IFC; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Elements.Serialization.IFC.IFCToHypar.Converters | ||
{ | ||
/// <summary>Uses a list of IFromIfcProductConverter to convert an IfcProduct to a GeometricElement.</summary> | ||
internal class CompositeFromIfcProductConverter : IFromIfcProductConverter | ||
{ | ||
private readonly List<IFromIfcProductConverter> _converters; | ||
private readonly IFromIfcProductConverter _defaultConverter; | ||
|
||
/// <summary> | ||
/// Create a CompositeFromIfcProductConverter that uses <paramref name="converters"/> and <paramref name="defaultConverter"/> | ||
/// to convert an IfcProduct to a GeometricElement. | ||
/// </summary> | ||
/// <param name="converters">A list, where CompositeFromIfcProductConverter looks for a converter that can convert an IfcProduct | ||
/// to a GeometricElement.</param> | ||
/// <param name="defaultConverter">A fallback converter, which will be used if none of <paramref name="converters"/> can convert | ||
/// an IfcProduct to a GeometricElement.</param> | ||
public CompositeFromIfcProductConverter(List<IFromIfcProductConverter> converters, IFromIfcProductConverter defaultConverter) | ||
{ | ||
_converters = converters; | ||
_defaultConverter = defaultConverter; | ||
} | ||
|
||
/// <summary> | ||
/// Looks for a converter that can convert <paramref name="ifcProduct"/> to a GeometricElement within _converters. | ||
/// If none of _converters can do the conversion, _defaultConverter is used instead. | ||
/// Returns null if the conversion was unsuccessful. | ||
/// </summary> | ||
/// <param name="ifcProduct">IfcProduct to convert to a GeometricElement.</param> | ||
/// <param name="representationData">Parsed Representation of <paramref name="ifcProduct"/>.</param> | ||
/// <param name="constructionErrors">The list of construction errors that appeared during conversion.</param> | ||
public GeometricElement ConvertToElement(IfcProduct ifcProduct, RepresentationData representationData, List<string> constructionErrors) | ||
{ | ||
GeometricElement result; | ||
|
||
foreach (var converter in _converters) | ||
{ | ||
if (!converter.CanConvert(ifcProduct)) | ||
{ | ||
continue; | ||
} | ||
|
||
result = converter.ConvertToElement(ifcProduct, representationData, constructionErrors); | ||
|
||
if (result != null) | ||
{ | ||
return result; | ||
} | ||
} | ||
|
||
return _defaultConverter.ConvertToElement(ifcProduct, representationData, constructionErrors); | ||
} | ||
|
||
/// <summary> | ||
/// Returns true, if any of _converters or _defaultConverter can convert <paramref name="ifcProduct"/> to a GeometricElement. | ||
/// </summary> | ||
/// <param name="ifcProduct">IfcProduct that will be checked if it can be converted with this converter.</param> | ||
public bool CanConvert(IfcProduct ifcProduct) | ||
{ | ||
return _converters.Any(converter => converter.CanConvert(ifcProduct)) || _defaultConverter.CanConvert(ifcProduct); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Elements.Serialization.IFC/src/IFCToHypar/Converters/FromIfcBeamConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Elements.Geometry; | ||
using Elements.Geometry.Solids; | ||
using Elements.Serialization.IFC.IFCToHypar.RepresentationsExtraction; | ||
using IFC; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Elements.Serialization.IFC.IFCToHypar.Converters | ||
{ | ||
internal class FromIfcBeamConverter : IFromIfcProductConverter | ||
{ | ||
public GeometricElement ConvertToElement(IfcProduct ifcProduct, RepresentationData repData, List<string> constructionErrors) | ||
{ | ||
if (!(ifcProduct is IfcBeam ifcBeam)) | ||
{ | ||
return null; | ||
} | ||
|
||
var elementTransform = repData.Transform; | ||
|
||
if (repData.Extrude == null) | ||
{ | ||
constructionErrors.Add($"#{ifcProduct.StepId}: Conversion of IfcBeam without extrude or mapped item representation to Beam is not supported."); | ||
return null; | ||
} | ||
|
||
var representation = new Representation(repData.SolidOperations); | ||
|
||
var centerLine = new Line(Vector3.Origin, repData.Extrude.Direction, repData.Extrude.Height); | ||
var transformedLine = centerLine.TransformedLine(repData.ExtrudeTransform); | ||
var result = new Beam(transformedLine, | ||
repData.Extrude.Profile, | ||
0, | ||
0, | ||
0, | ||
elementTransform, | ||
repData.Material, | ||
representation, | ||
false, | ||
IfcGuid.FromIfcGUID(ifcBeam.GlobalId), | ||
ifcBeam.Name); | ||
|
||
return result; | ||
} | ||
|
||
public bool CanConvert(IfcProduct ifcProduct) | ||
{ | ||
return ifcProduct is IfcBeam; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Elements.Serialization.IFC/src/IFCToHypar/Converters/FromIfcColumnConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Elements.Geometry; | ||
using Elements.Geometry.Solids; | ||
using Elements.Serialization.IFC.IFCToHypar.RepresentationsExtraction; | ||
using IFC; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Elements.Serialization.IFC.IFCToHypar.Converters | ||
{ | ||
internal class FromIfcColumnConverter : IFromIfcProductConverter | ||
{ | ||
public GeometricElement ConvertToElement(IfcProduct ifcProduct, RepresentationData repData, List<string> constructionErrors) | ||
{ | ||
if (!(ifcProduct is IfcColumn ifcColumn)) | ||
{ | ||
return null; | ||
} | ||
|
||
var elementTransform = repData.Transform; | ||
|
||
if (repData.Extrude == null) | ||
{ | ||
constructionErrors.Add($"#{ifcProduct.StepId}: Conversion of IfcColumn without extrude or mapped item representation to Column is not supported."); | ||
return null; | ||
} | ||
|
||
var result = new Column(repData.ExtrudeTransform.Origin, | ||
repData.Extrude.Height, | ||
null, | ||
repData.Extrude.Profile, | ||
0, | ||
0, | ||
0, | ||
elementTransform, | ||
repData.Material, | ||
new Representation(repData.SolidOperations), | ||
false, | ||
IfcGuid.FromIfcGUID(ifcColumn.GlobalId), | ||
ifcColumn.Name); | ||
return result; | ||
} | ||
|
||
public bool CanConvert(IfcProduct ifcProduct) | ||
{ | ||
return ifcProduct is IfcColumn; | ||
} | ||
} | ||
} |
Oops, something went wrong.