Skip to content
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

Ifc serialization improvements #1021

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
eb5621f
Moved IFCExtensions to the IFCToElementsConverters folder
srudenkoamc Aug 29, 2023
775e54e
Added names to walls in door test
srudenkoamc Aug 29, 2023
10744f1
Extended IFC4 test
srudenkoamc Sep 1, 2023
def1390
Added ImportSolid : Solid Operation class
srudenkoamc Sep 7, 2023
898cfc1
Added IIfcProductToElementConverter interface
srudenkoamc Sep 7, 2023
9ea63cc
Created a separate class-converter for each Element we recognize in IFC
srudenkoamc Sep 7, 2023
5bc3e49
Added IfcBuildingElementToElementConverter class
srudenkoamc Sep 7, 2023
688af87
Added CompositeIfcToElementConverter class
srudenkoamc Sep 7, 2023
f09d30e
Added FromIfcModelProvider class
srudenkoamc Sep 7, 2023
070fefa
Use new IfcProduct -> Element logic instead of the old one
srudenkoamc Sep 7, 2023
19c3dcf
IfcExtensions cleanup
srudenkoamc Sep 7, 2023
176749d
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Sep 7, 2023
d01facc
Fix a visual artifact
srudenkoamc Sep 11, 2023
6948d30
Simplified the structure of the namespaces
srudenkoamc Sep 12, 2023
91f560a
Switched visibility of Ifc extensions to internal
srudenkoamc Sep 20, 2023
8ec11cd
Imported the materials extraction code
srudenkoamc Sep 20, 2023
3135b48
Material extractor refactoring
srudenkoamc Sep 21, 2023
585c718
Move building elements to BuildingElements namespace
srudenkoamc Sep 25, 2023
f9d6ee2
Switch expected and actual values in IFCTests.FromIFC4
srudenkoamc Sep 27, 2023
96aca92
Revert 'Move building elements to BuildingElements namespace'
srudenkoamc Sep 27, 2023
a14978c
Added IndexedPolycurve conversion
srudenkoamc Sep 28, 2023
eaf3ed8
Added RepresentationData class and MappingInfo class
srudenkoamc Sep 28, 2023
4fc227f
Added Material extraction by representation item for MaterialExtractor
srudenkoamc Sep 28, 2023
6cb6520
Added separate parsers for IfcRepresentationItems of different types
srudenkoamc Sep 28, 2023
5829905
Added Material and Representation parameters to Door constructor
srudenkoamc Sep 28, 2023
45375aa
Added IfcRepresentationDataExtractor class
srudenkoamc Sep 28, 2023
5637fad
Added a method that creates standard representation data extractor
srudenkoamc Sep 28, 2023
312f8bf
Imported Openings changes
srudenkoamc Sep 28, 2023
8210c6f
Added default Extrude creation for openings
srudenkoamc Sep 28, 2023
63eddd6
Used IfcRepresentationItem parsers to parse representation data for r…
srudenkoamc Sep 28, 2023
a4394c1
Added IfcSite converter
srudenkoamc Sep 28, 2023
101076e
Modified tests
srudenkoamc Sep 28, 2023
e5385e8
Removed redundant methods
srudenkoamc Sep 28, 2023
c9c1149
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Sep 28, 2023
7c80d4d
Changed IfcBuildingElementToElementConverter to FromIfcElementConverter
srudenkoamc Sep 28, 2023
7834d63
Renamed converters from IFC
srudenkoamc Sep 29, 2023
c39ba87
Renamed CompositeIfcToElementConverter
srudenkoamc Oct 2, 2023
5383408
Small refactoring in FromIfcModelProvider
srudenkoamc Oct 5, 2023
74c9262
Fixed missing openings
srudenkoamc Oct 5, 2023
e8b8b30
Door class improvements
srudenkoamc Oct 5, 2023
c61c739
Added instancing for the core types
srudenkoamc Oct 5, 2023
9009802
Included all IfcElements to conversion procedure (openings excluded)
srudenkoamc Oct 5, 2023
50f83cf
Small update of mapping transform
srudenkoamc Oct 5, 2023
717d10c
Updated FromIFC4 test
srudenkoamc Oct 5, 2023
62e2873
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Oct 5, 2023
7a38d72
Default geometric element conversion improvements
srudenkoamc Oct 10, 2023
4e893f8
Merge branch 'ifc-serialization-refactoring' of https://github.com/sr…
srudenkoamc Oct 10, 2023
80b4116
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Oct 10, 2023
d767022
Update IFCTests
srudenkoamc Oct 10, 2023
18b316c
Fixed serialization issue for representations with imported solids
srudenkoamc Oct 11, 2023
d072bf8
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Oct 11, 2023
c40a9cf
Added extraction of solids from the first operand of boolean clipping…
srudenkoamc Oct 11, 2023
cc047be
IFromIfcProductConverter refactoring
srudenkoamc Oct 19, 2023
f3babf4
Removed FromIfcSiteConverter
srudenkoamc Oct 19, 2023
daa7369
Added summary for CompositeFromIfcProductConverter
srudenkoamc Oct 19, 2023
e222c90
Refactoring of FromIfcModelProvider
srudenkoamc Oct 19, 2023
3574f2f
Refactoring of IIfcRepresentationParser
srudenkoamc Oct 19, 2023
217c700
Added summaries to IfcRepresentationDataExtractor
srudenkoamc Oct 19, 2023
874470e
Added summaries for IfcMappedItemParser
srudenkoamc Oct 19, 2023
dea87a6
Added summary for the constructor of IfcBooleanClippingResultParser
srudenkoamc Oct 19, 2023
49c470d
Added summaries to MappingInfo
srudenkoamc Oct 19, 2023
ff8dd01
Added summaries for MaterialExtractor
srudenkoamc Oct 19, 2023
a947d40
Added summaries for RepresentationData
srudenkoamc Oct 19, 2023
0d37e78
Added comments about the future work to the tests
srudenkoamc Oct 19, 2023
02d9039
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Oct 19, 2023
dafdefb
Removed a commented function from IFCExtensions
srudenkoamc Oct 23, 2023
118c554
Fixed Equals for IfcCartesianPoint
srudenkoamc Oct 24, 2023
66eff79
Reverted SolidOperationUtils changes
srudenkoamc Oct 24, 2023
6894f82
FirstOrDefault and TryGetValue comments fixes
srudenkoamc Oct 24, 2023
85b868a
Fixes in FromIfcModelProvider
srudenkoamc Oct 24, 2023
1086b1e
Fixed extrudes null checks in ToOpenings
srudenkoamc Oct 24, 2023
16b01a8
Added missing transforms in ToCurve and ToProfile
srudenkoamc Oct 24, 2023
c081bc6
Added Elements.Door to the Changelog
srudenkoamc Oct 24, 2023
04d4cd9
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Oct 25, 2023
980663e
Remove redundant comment
srudenkoamc Oct 30, 2023
7cdcb81
Added Guid generation for Door
srudenkoamc Oct 30, 2023
fc0204c
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Oct 30, 2023
c5788e6
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Nov 6, 2023
b969133
Merge branch 'master' into ifc-serialization-refactoring
srudenkoamc Nov 6, 2023
6cf0264
update to latest package
anthonie-kramer Nov 8, 2023
20bcf69
Merge branch 'master' into ifc-serialization-refactoring
anthonie-kramer Nov 8, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- `Elements.MEP`
- `GeometricElement.RepresentationInstances`
- `ContentRepresentation`
- `Elements.Door`

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>Hypar.Elements.Serialization.IFC</AssemblyName>
<PackageTitle>Hypar Elements Serialization IFC</PackageTitle>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hypar.IFC4" Version="0.1.4.1" />
<PackageReference Include="Hypar.IFC4" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Elements.Analysis;
using Elements.Geometry;
using Elements.Interfaces;
using Elements.Serialization.IFC.IFCToHypar;
using IFC;
using STEP;
using System;
Expand All @@ -25,141 +27,9 @@ public static class IFCModelExtensions
/// <returns>A model.</returns>
public static Model FromIFC(string path, out List<string> constructionErrors, IList<string> idsToConvert = null)
{
List<STEPError> errors;
var ifcModel = new Document(path, out errors);
foreach (var error in errors)
{
Console.WriteLine("***IFC ERROR***" + error.Message);
}

IEnumerable<IfcSlab> ifcSlabs = null;
IEnumerable<IfcSpace> ifcSpaces = null;
IEnumerable<IfcWallStandardCase> ifcWalls = null;
IEnumerable<IfcBeam> ifcBeams = null;
IEnumerable<IfcColumn> ifcColumns = null;
IEnumerable<IfcRelVoidsElement> ifcVoids = null;
IEnumerable<IfcRelAssociatesMaterial> ifcMaterials = null;
IEnumerable<IfcDoor> ifcDoors = null;

if (idsToConvert != null && idsToConvert.Count > 0)
{
ifcSlabs = ifcModel.AllInstancesOfType<IfcSlab>().Where(i => idsToConvert.Contains(i.GlobalId));
ifcSpaces = ifcModel.AllInstancesOfType<IfcSpace>().Where(i => idsToConvert.Contains(i.GlobalId));
ifcWalls = ifcModel.AllInstancesOfType<IfcWallStandardCase>().Where(i => idsToConvert.Contains(i.GlobalId));
ifcBeams = ifcModel.AllInstancesOfType<IfcBeam>().Where(i => idsToConvert.Contains(i.GlobalId));
ifcColumns = ifcModel.AllInstancesOfType<IfcColumn>().Where(i => idsToConvert.Contains(i.GlobalId));
ifcVoids = ifcModel.AllInstancesOfType<IfcRelVoidsElement>().Where(i => idsToConvert.Contains(i.GlobalId));
ifcMaterials = ifcModel.AllInstancesOfType<IfcRelAssociatesMaterial>().Where(i => idsToConvert.Contains(i.GlobalId));
ifcDoors = ifcModel.AllInstancesOfType<IfcDoor>().Where(i => idsToConvert.Contains(i.GlobalId));
}
else
{
ifcSlabs = ifcModel.AllInstancesOfType<IfcSlab>();
ifcSpaces = ifcModel.AllInstancesOfType<IfcSpace>();
ifcWalls = ifcModel.AllInstancesOfType<IfcWallStandardCase>();
ifcBeams = ifcModel.AllInstancesOfType<IfcBeam>();
ifcColumns = ifcModel.AllInstancesOfType<IfcColumn>();
ifcVoids = ifcModel.AllInstancesOfType<IfcRelVoidsElement>();
ifcMaterials = ifcModel.AllInstancesOfType<IfcRelAssociatesMaterial>();
ifcDoors = ifcModel.AllInstancesOfType<IfcDoor>();
}

constructionErrors = new List<string>();

var slabs = new List<Floor>();
foreach (var s in ifcSlabs)
{
try
{
slabs.Add(s.ToFloor(ifcVoids.Where(v => v.RelatingBuildingElement == s).Select(v => v.RelatedOpeningElement).Cast<IfcOpeningElement>()));
}
catch (Exception ex)
{
constructionErrors.Add(ex.Message);
continue;
}

}

var spaces = new List<Space>();
foreach (var sp in ifcSpaces)
{
try
{
spaces.Add(sp.ToSpace());
}
catch (Exception ex)
{
constructionErrors.Add(ex.Message);
continue;
}
}

var walls = new List<Wall>();
foreach (var w in ifcWalls)
{
try
{
walls.Add(w.ToWall(ifcVoids.Where(v => v.RelatingBuildingElement == w).Select(v => v.RelatedOpeningElement).Cast<IfcOpeningElement>()));
}
catch (Exception ex)
{
constructionErrors.Add(ex.Message);
continue;
}
}

var beams = new List<Beam>();
foreach (var b in ifcBeams)
{
try
{
beams.Add(b.ToBeam());
}
catch (Exception ex)
{
constructionErrors.Add(ex.Message);
continue;
}
}

var columns = new List<Column>();
foreach (var c in ifcColumns)
{
try
{
columns.Add(c.ToColumn());
}
catch (Exception ex)
{
constructionErrors.Add(ex.Message);
continue;
}
}

var doors = new List<Door>();
foreach (var d in ifcDoors)
{
try
{
doors.Add(d.ToDoor(walls));
}
catch (Exception ex)
{
constructionErrors.Add(ex.Message);
continue;
}
}

var model = new Model();
model.AddElements(slabs);
model.AddElements(spaces);
model.AddElements(walls);
model.AddElements(beams);
model.AddElements(columns);
model.AddElements(doors);

return model;
var modelProvider = new FromIfcModelProvider(path, idsToConvert: idsToConvert);
constructionErrors = modelProvider.GetConstructionErrors();
return modelProvider.Model;
}

private static Document CreateIfcDocument(this Model model, bool updateElementsRepresentation = true)
Expand Down Expand Up @@ -304,7 +174,7 @@ public static void ToIFC(this Model model,
{
File.Delete(path);
}
File.WriteAllText(path, ifc.ToSTEP(path));
File.WriteAllText(path, ifc.ToSTEP());
}

/// <summary>
Expand Down
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);
}
}
}
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;
}
}
}
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;
}
}
}
Loading
Loading