xBimTeam / XbimGeometry

XbimGeometry contains the CLR interop libraries and the c++ engine used to compute the 3D geometry of models.
https://xbimteam.github.io/
Other
260 stars 131 forks source link

Error while creating IfcSurfaceCurveSweptAreaSolid #446

Open ChernyshevDS opened 1 year ago

ChernyshevDS commented 1 year ago

Hello. I've encountered a problem during opening one of my models: creating Xbim3DModelContext causes the following exception:

System.Exception: General Error Creating IfcSurfaceCurveSweptAreaSolid, #333640
   в Xbim.Geometry.XbimGeometryCreator.Create(IIfcGeometricRepresentationItem geomRep, IIfcAxis2Placement3D objectLocation, ILogger logger) в D:\Projects\Repos\XbimGeometry\Xbim.Geometry.Engine\XbimGeometryCreator.cpp:строка 306
   в Xbim.Geometry.Engine.Interop.XbimGeometryEngine.Create(IIfcGeometricRepresentationItem ifcRepresentation, ILogger logger) в C:\buildagent_os\_work\1\s\Xbim.Geometry.Engine.Interop\XbimGeometryEngine.cs:строка 74
   в Xbim.ModelGeometry.Scene.Xbim3DModelContext.<>c__DisplayClass39_0.<WriteShapeGeometries>b__0(Int32 shapeId) в D:\Projects\Repos\XbimGeometry\Xbim.ModelGeometry.Scene\Xbim3DModelContext.cs:строка 1379
   в System.Threading.Tasks.Parallel.<>c__DisplayClass42_0`2.<PartitionerForEachWorker>b__1()
   в System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   в System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object <p0>)

The exception is raised in the following method: void XbimFace::Init(IIfcSurfaceOfLinearExtrusion^ sLin, bool /*useWorkArounds*/, ILogger^ logger). It has a block of code applying a workaround named #RevitIncorrectArcCentreSweptCurve:

IIfcTrimmedCurve^ tc = ...
...
//the centre has been transformed twice, recalculate the centre
//trim 1 and trim 2 will be cartesian points
IIfcCartesianPoint^ trim1 = dynamic_cast<IIfcCartesianPoint^>(Enumerable::FirstOrDefault(tc->Trim1));
IIfcCartesianPoint^ trim2 = dynamic_cast<IIfcCartesianPoint^>(Enumerable::FirstOrDefault(tc->Trim2));
gp_Pnt p1 = XbimConvert::GetPoint3d(trim1);
gp_Pnt p2 = XbimConvert::GetPoint3d(trim2);
...

The comment indicates that IIfcCartesianPoints are expected, but IfcTrimmedCurve may be defined not only with cartesian points, but with IfcParameterValues too. That is exactly the case in my model - dynamic_cast<IIfcCartesianPoint^> returns nullptr. The simplest fix is just to add a null check on trim1 and trim2, but then the workaround would be skipped and I'm not sure if it should be applied differently in this case.

Assemblies and versions affected:

XbimGeometry 5.1.403, commit https://github.com/xBimTeam/XbimGeometry/commit/24a3db9442b33578eebf9fbf2eb58074cc3afc56

Minimal file to reproduce the issue:

IFC OV L4.ifc.stripped.ifc.txt

ChernyshevDS commented 1 year ago

Upd: may be related to https://github.com/xBimTeam/XbimGeometry/issues/330