From 334d8678736466f328b1f1ddf9a233fc44e971d4 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 19 Nov 2018 14:56:21 +0100 Subject: [PATCH 1/2] Fix #498 --- src/ifcgeom/IfcGeomWires.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ifcgeom/IfcGeomWires.cpp b/src/ifcgeom/IfcGeomWires.cpp index ffaad79b7e..f84fa867bb 100644 --- a/src/ifcgeom/IfcGeomWires.cpp +++ b/src/ifcgeom/IfcGeomWires.cpp @@ -91,6 +91,10 @@ #include #include +#include +#include +#include + #include "../ifcgeom/IfcGeom.h" namespace { @@ -419,7 +423,21 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcTrimmedCurve* l, TopoDS_Wire& double parameterFactor = isConic ? getValue(GV_PLANEANGLE_UNIT) : getValue(GV_LENGTH_UNIT); Handle(Geom_Curve) curve; - if ( !convert_curve(basis_curve,curve) ) return false; + if (shape_type(basis_curve) == ST_CURVE) { + if (!convert_curve(basis_curve, curve)) return false; + } else if (shape_type(basis_curve) == ST_WIRE) { + Logger::Warning("Approximating BasisCurve due to possible discontinuities", l->entity); + TopoDS_Wire w; + if (!convert_wire(basis_curve, w)) return false; + BRepAdaptor_CompCurve cc(w, true); + Handle(Adaptor3d_HCurve) hcc = Handle(Adaptor3d_HCurve)(new BRepAdaptor_HCompCurve(cc)); + // @todo, arbitrary numbers here, note they cannot be too high as contiguous memory is allocated based on them. + Approx_Curve3d approx(hcc, getValue(GV_PRECISION), GeomAbs_C0, 10, 10); + curve = approx.Curve(); + } else { + Logger::Error("Unknown BasisCurve", l->entity); + return false; + } bool trim_cartesian = l->MasterRepresentation() != IfcSchema::IfcTrimmingPreference::IfcTrimmingPreference_PARAMETER; IfcEntityList::ptr trims1 = l->Trim1(); From 0018224da779666ac4131c67c713448070074bda Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 19 Nov 2018 16:38:52 +0100 Subject: [PATCH 2/2] Handle python positional arguments in case of derived fields more explicitly --- .../ifcopenshell/entity_instance.py | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/entity_instance.py b/src/ifcopenshell-python/ifcopenshell/entity_instance.py index badbaed3d4..675d35420f 100644 --- a/src/ifcopenshell-python/ifcopenshell/entity_instance.py +++ b/src/ifcopenshell-python/ifcopenshell/entity_instance.py @@ -108,22 +108,33 @@ class entity_instance(object): return entity_instance.wrap_value(self.wrapped_data.get_argument(key)) def __setitem__(self, idx, value): + attr_type = real_attr_type = self.attribute_type(idx).title().replace(' ', '') + real_attr_type = real_attr_type.replace('Derived', 'None') + attr_type = attr_type.replace('Binary', 'String') + attr_type = attr_type.replace('Enumeration', 'String') + if value is None: - self.wrapped_data.setArgumentAsNull(idx) + if attr_type != "Derived": + self.wrapped_data.setArgumentAsNull(idx) else: - attr_type = real_attr_type = self.attribute_type(idx).title().replace(' ', '') - attr_type = attr_type.replace('Binary', 'String') - attr_type = attr_type.replace('Enumeration', 'String') - try: - if isinstance(value, unicode): - value = value.encode("utf-8") - except BaseException: - pass - try: - getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value)) - except BaseException: + valid = attr_type != "Derived" + if valid: + try: + if isinstance(value, unicode): + value = value.encode("utf-8") + except BaseException: + pass + + try: + if attr_type != "Derived": + getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value)) + except BaseException as e: + valid = False + + if not valid: raise ValueError("Expected %s for attribute %s.%s, got %r" % ( real_attr_type, self.is_a(), self.attribute_name(idx), value)) + return value def __len__(self):