xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
506 stars 174 forks source link

IFC4 cartesian point list invalid syntax #584

Open emanuelegoldin opened 1 month ago

emanuelegoldin commented 1 month ago

Creating an IfcStore model from an IFC 4 file held the wrong syntax for the IfcCartesianPointList2D and IfcCartesianPointList3D objects.

Specifically, it adds a trailing attribute after the coordinate list.

Assemblies and versions affected:

Xbim.Ifc4 6.0.445

Steps (or code) to reproduce the issue:

Opening a file with valid syntax for IfcCartesianPointList2D entities and inspecting the model already shows the trailing attribute (no need for additional operations)

// Step 1: load the model
var model = IfcStore.Open("file.ifc");
// Step 2: save to a different file
model.SaveAs("path");

Minimal file to reproduce the issue:

simple_room.zip

Expected behavior:

Saved IFC 4 file after Xbim manipulation held valid ifc coordinates list entities

Actual behavior or exception details:

The saved file fails the validation

Additional Details

Looking into the documentation for various IFC standard versions, we figured that the definition of IfcCartesianPointList2D and IfcCartesianPointList3D changed moving from IFC 4 to IFC 4x3: in the former version, they both have a single attribute CoordList; the latter version introduced a second attribute TagList.

During the validation of the exported IFC file, we got the following error:

Wrong number of attributes on instance with id #304 expected 1 got 2:

#304=IFCCARTESIANPOINTLIST2D(((-0.080000000000029464,-9.3800000000000026),(0.079999999999968818,-9.3800000000000026),(0.080000000000025134,9.379999999999999),(-0.079999999999973148,9.379999999999999),(-0.080000000000029464,-9.3800000000000026)),$);

where you can see that the offended line has an unexpected second attribute (namely $).

Inspecting the IfcCartesianClassPointList2D.cs and IfcCartesianClassPointList3D.cs files in XbimEssential/Xbim.Ifc4/GeometricModelResource it seems that the TagList attribute is wrongly defined in the interface also for version IFC 4:

public partial interface @IIfcCartesianPointList2D : IIfcCartesianPointList
{
    IItemSet<IItemSet<IfcLengthMeasure>> @CoordList { get; }
    IItemSet<IfcLabel> @TagList { get; }

}
andyward commented 1 month ago

A quick bit of investigation. IIfcCartesianPointList3D.TagList was not in IFC4.0 ADD2_TC1 but was added in IFC4.1 RC3, which was integrated in xbim April 2018. It was also in IFC4.2 and remains in IFC4.3_ADD2

However IFC4x1 (and 4x2) were subsequently withdrawn by BuildingSmart with the 4.3 release

Unfortunately IFC4 as a family of schemas doesn't really differentiate the exact schema used in the header. It's just FILE_SCHEMA(('IFC4')); regardless of whether it's IFC4 ADD2 TC1 (official) or a later IFC4x1/x2, so we can't rely on that to indicate schema support.

I guess the options are:

  1. Revert xbim.IFC4 back to IFC4_ADD2_TC1 and lose support for any remaining 4.1/4.2 changes
  2. Introduce some support for IFC4.1/2 export serialisation - given we have an internal concept of XbimSchemaVersion.Ifc4x1 vs XbimSchemaVersion.Ifc4 - i.e. don't serialise Taglist etc if IFC4
  3. Leave alone with this edge-case and acknowledge some extraneous params may be included in exports. (Along with validation errors) - not a great option!

What do you think @martin1cerny?