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
494 stars 173 forks source link

Xbim.Ifc4x3.GeometryResource.IfcCompositeCurve.Segments throws NotImplementedException #566

Closed santiagoIT closed 3 months ago

santiagoIT commented 4 months ago

Hello,

the following AutoGenerated code: image

throws an exception when called.

I ran into this problem when opening an IFC file. This happens when an XbimWire is initialized from an IIfcCompositeCurve: image

When line 861 is executed, the exception is thrown.

Since the IfcCompositeCurve file is generated by the Xbim.CodeGeneration tool, I have no idea on how to approach this problem. If you provide some guidance I can attempt to solve it.

test.zip

andyward commented 4 months ago

Sounds like there's a few IFC4.3 areas unimplememented on the cross schema interfaces.

So while we code-gen these files, any code within blocks starting and ending //## is preserved when re-generating.

In this case you'd just need to add the implementation as per IFC2x3 in place of the NotImplementedException. E.g. see

https://github.com/xBimTeam/XbimEssentials/blob/master/Xbim.Ifc2x3/Interfaces/IFC4/IfcCompositeCurve.cs

(I'm not sure why, but the IFC2x3 code should have the same //## markers around it in case we regen IFC2x3. But that's a separate issue)

santiagoIT commented 4 months ago

In Ifc4 and lower the segments list is defined as: private readonly ItemSet<IfcCompositeCurveSegment> _segments;

But starting with IFC4x3, the segments list is defined as: private readonly ItemSet<IfcSegment> _segments;

it changed from IfcCompositeCurveSegment to IfcSegment

That is why I just cannot take over the code from earlier implementations.

This is how I implemented it:


[CrossSchemaAttribute(typeof(IIfcCompositeCurve), 1)]
IItemSet<IIfcCompositeCurveSegment> IIfcCompositeCurve.Segments 
{ 
    get
    {
        //##
        var list= new ItemSet<IIfcCompositeCurveSegment>(this, 0, 1);
        list.AddRange(@Segments.Where(x => x is IIfcCompositeCurveSegment).Cast<IIfcCompositeCurveSegment>());
        return new Common.Collections.ProxyItemSet<IIfcCompositeCurveSegment, IIfcCompositeCurveSegment>(list);
        //##
    }
}

Let me know if this looks ok, if so, I can create a pull request.

santiagoIT commented 4 months ago

What I posted above does not work. I get an Operation Out Of Transaction exception.

Trying to find a solution...

santiagoIT commented 4 months ago

This works, The 4.3 ifc file still does not open, but processing continues much further now. There must be some other problem which I will investigate.

` [CrossSchemaAttribute(typeof(IIfcCompositeCurve), 1)] IItemSet IIfcCompositeCurve.Segments { get { //## Custom code - not auto generated var compCurveSegs = @Segments.Where(x => x is IIfcCompositeCurveSegment) .Cast();

            var list = new ItemSet<IIfcCompositeCurveSegment>(this, 0, 1);
            foreach (var seg in compCurveSegs)
            {
                list.InternalAdd(seg); // no transaction available
            }
            return new Common.Collections.ProxyItemSet<IIfcCompositeCurveSegment, IIfcCompositeCurveSegment>(list);
            //##
        }
    }`
santiagoIT commented 3 months ago

@andyward Could you please review this pull request as well. It solves the other issue I ran into when trying to load a particular IFC4x3 model.

https://github.com/xBimTeam/XbimEssentials/pull/570

Thank you!

andyward commented 3 months ago

Should be done. Again I tweaked it. We don't have test coverage on this IIfcCompositeCurve.Segments code so please do retest my implementation.

santiagoIT commented 3 months ago

Tested your implementation, worked 👍