Skip to content

Commit 5416ecc

Browse files
committed
Fixed null shape repr tpaviot#604
1 parent 5883dc8 commit 5416ecc

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/SWIG_files/common/CommonIncludes.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def _dumps_object(klass):
4242
repr_string = "class<'" + klass_name + "'"
4343
# for TopoDS_Shape, we also look for the base type
4444
if klass_name == "TopoDS_Shape":
45+
if klass.IsNull():
46+
repr_string += " : Null>"
47+
return repr_string
4548
st = klass.ShapeType()
4649
types = {OCC.Core.TopAbs.TopAbs_VERTEX: "Vertex",
4750
OCC.Core.TopAbs.TopAbs_SOLID: "Solid",
@@ -57,6 +60,8 @@ def _dumps_object(klass):
5760
if hasattr(klass, "HashCode"):
5861
klass_id = hash(klass)
5962
repr_string += "; id:%s" % klass_id
63+
if klass.IsNull():
64+
repr_string += "; Null"
6065
repr_string += ">"
6166
return repr_string
6267
%}

test/core_wrapper_features_unittest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from OCC.Core.Interface import Interface_Static_SetCVal, Interface_Static_CVal
3636
from OCC.Core.GCE2d import GCE2d_MakeSegment
3737
from OCC.Core.ShapeFix import ShapeFix_Solid, ShapeFix_Wire
38-
from OCC.Core.TopoDS import TopoDS_Compound, TopoDS_Builder, TopoDS_Edge
38+
from OCC.Core.TopoDS import TopoDS_Compound, TopoDS_Builder, TopoDS_Edge, TopoDS_Vertex, TopoDS_Shape
3939
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder
4040
from OCC.Core.TColStd import TColStd_Array1OfReal, TColStd_Array1OfInteger
4141
from OCC.Core.TColgp import TColgp_Array1OfPnt
@@ -593,6 +593,12 @@ def test_array_iterator(self):
593593
for pnt in list_of_points:
594594
self.assertTrue(isinstance(pnt, gp_Pnt))
595595

596+
def test_repr_for_null_topods_shapes(self):
597+
# create null vertex and shape
598+
v = TopoDS_Vertex()
599+
s = TopoDS_Shape()
600+
self.assertTrue('Null' in v.__repr__())
601+
self.assertTrue('Null' in s.__repr__())
596602

597603
def suite():
598604
test_suite = unittest.TestSuite()

0 commit comments

Comments
 (0)