Skip to content

Commit ee10dd6

Browse files
authored
Merge pull request #364 from tpaviot/review/overload-repr
Review/overload repr
2 parents a3c66e2 + 8c82f96 commit ee10dd6

File tree

230 files changed

+23905
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+23905
-3
lines changed

src/SWIG_files/common/CommonIncludes.i

+34
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,37 @@ along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
2727
%include <python/std_list.i>
2828
%include <python/std_string.i>
2929
%include <python/std_basic_string.i>
30+
31+
%pythoncode %{
32+
def _dumps_object(klass):
33+
""" Improve string output for any oce object.
34+
By default, __repr__ method returns something like:
35+
<OCC.TopoDS.TopoDS_Shape; proxy of <Swig Object of type 'TopoDS_Shape *' at 0x02BB0758> >
36+
This is too much verbose.
37+
We prefer :
38+
class<'gp_Pnt'>
39+
or
40+
class<'TopoDS_Shape'; Type:Solid; Id:59391729>
41+
"""
42+
klass_name = str(klass.__class__).split(".")[2].split("'")[0]
43+
repr_string = "class<'" + klass_name + "'"
44+
# for TopoDS_Shape, we also look for the base type
45+
if klass_name == "TopoDS_Shape":
46+
st = klass.ShapeType()
47+
types = {OCC.TopAbs.TopAbs_VERTEX:"Vertex",
48+
OCC.TopAbs.TopAbs_SOLID:"Solid",
49+
OCC.TopAbs.TopAbs_EDGE:"Edge",
50+
OCC.TopAbs.TopAbs_FACE:"Face",
51+
OCC.TopAbs.TopAbs_SHELL:"Shell",
52+
OCC.TopAbs.TopAbs_WIRE:"Wire",
53+
OCC.TopAbs.TopAbs_COMPOUND:"Compound",
54+
OCC.TopAbs.TopAbs_COMPSOLID:"Compsolid."}
55+
repr_string += "; Type:%s" % types[st]
56+
# for each class that has an HashCode method define,
57+
# print the id
58+
if hasattr(klass, "HashCode"):
59+
klass_id = hash(klass)
60+
repr_string += "; id:%s" % klass_id
61+
repr_string += ">"
62+
return repr_string
63+
%}

0 commit comments

Comments
 (0)