-
As I work on adding support for alignments and linear referencing, I am making assumptions about IFC and I want to add assertions so there is automatic notification if the assumptions are incorrect. What is the preferred way to handle this? Some examples IfcOpenShell/src/ifcgeom/mapping/IfcCurveSegment.cpp Lines 256 to 259 in 164125f IfcPolyline must have at least 2 points – is throwing a std::runtime_error the best thing to do? I expect the points defining the IfcPolyline to be 2D when used as the basis curve for IfcCurveSegment. I’m not 100% sure this is a requirement of IFC, but it is an assumption I’m making. If we encounter an IFC file that uses an IfcPolyline with 3D points, I’d like an assertion to fire. Is assert(p1->Coordinates().size() == 2) ok or should the error logger be used?
Alternatively, IfcCurve has a Dim attribute. That could be evaluated, but I don’t know how to get the value. Please point me to an example of how I can get the Dim attribute Lastly, what is the preferred method for dealing with numerical tolerances? IfcOpenShell/src/ifcgeom/mapping/IfcCurveSegment.cpp Lines 281 to 286 in 164125f In this example, I’ve run into cases where the last span is slightly shorter than the last value of u so I changed to IfcOpenShell/src/ifcgeom/taxonomy.h Lines 153 to 161 in 164125f |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I already made comment on the PR before seeing that. We indeed have Logger::Warning, Logger::Error or raise an exception. I would not use assert() because typically in release builds they simply disappear or generally don't result in a nice experience (especially for windows users, I think on linux you get a bit more informative output from them as an enduser). I would say:
This is very much coming from the old days of IFC where if something doesn't show up it's assumed to be the fault of the opening application, because validity and strict usage of IFC wasn't a thing at that time. Also now with 4.3 and alignment geometry I would gravitate towards being as permissive as possible in terms of having 3d output show up (because if the user doesn't see anything visually then there also isn't an element to attach error information to except for the log, which people don't read), but log everything as warnings that you don't like to see in the model. And keep a long list of validation rules for @civilx64 to implement in the official validation service so that IFC becomes stricter. In the end, end-users compare implementations by how many models they can successfully open, not based on how compliant the implementation is to the standard.
In C++ this is unfortunately not possible yet. The Dim attribute is actually a good example of a simple attribute that will, for example in case of a Polyline, will call various functions to eventually return 2 or 3, based on the dimensionality of the points, which is HIINDEX of the coord tuple. We don't have access to this in C++, but we do in Python, because we have a code generator that turns EXPRESS function code into Python. I haven't decided yet on the plan for this. We either have to write an interpreter for EXPRESS (because a code generator is likely not ideal, because of robustness, you can't catch every error in C++, but you can in Python) or we have to embed the Python interpreter into IfcOpenShell C++ so that from C++ you can evaluate Python to interpret the derived attributes. This is something for the future to decide, depends mostly on the community and any potential funding I guess.
There is an attribute Precision on the IfcGeometricRepresentationContext. This is available as A single precision value is hardly enough though, so throughout the codebase sometimes we use arbitrary fixed constants. Especially related to angular things, but also some thicknesses because Open CASCADE does not go below 1.e-8 linear tolerance and we have to add some 'padding' around that. |
Beta Was this translation helpful? Give feedback.
I already made comment on the PR before seeing that. We indeed have Logger::Warning, Logger::Error or raise an exception. I would not use assert() because typically in release builds they simply disappear or generally don't result in a nice experience (especially for windows users, I think on linux you get a bit more informative output from them as an enduser).
I would say: