1818Distributed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
1919View LICENSE for details.
2020
21- Revision History
22- ----------------
23- 12/17/11: Began
24- 01/09/12: Merged shapes and primitives into model.py
25- to 1/11/14: Various Updates
26- 1/20/14: Replaced == None with is None
27-
2821Philosophy
2922----------
3023
60538. Distinction between face, wire, solid, etc. can get muddled after
6154 certain operations, particularly boolean. Ought to be more careful
6255 about this.
56+
57+ 9. Separate compound, compsolid from solid.
6358"""
6459
6560from os import path as _path
6661import sys as _sys
67- import re as _re # Needed for svg
62+ import re as _re # Needed for svg
6863import math as _math
6964
7065#from OCC.ChFi3d import *
124119 _TopOpeBRepTool_FuseEdges )
125120from OCC import TopTools as _TopTools
126121
127- # Generic Functions
128- def _explode_args (args ):
129- """
130- Takes a list of arguments with multiple depths and flattens it.
131- """
132- retval = []
133- for arg in args :
134- try :
135- a = len (arg )
136- except TypeError :
137- a = - 1
138- if a >= 0 and type (a ) != type ('' ):
139- retval = retval + _explode_args (arg )
140- else :
141- retval .append (arg )
142- return retval
143-
144122
145123# Shape Functions
146124def _translate (s1 , pdir ):
@@ -1009,8 +987,10 @@ def _raw_type(raw_shape):
1009987 _TopAbs .TopAbs_EDGE : 'edge' ,
1010988 _TopAbs .TopAbs_VERTEX : 'vertex' ,
1011989 _TopAbs .TopAbs_SHAPE : 'shape' }
1012- return raw_types [raw_shape .ShapeType ()]
1013-
990+ try :
991+ return raw_types [raw_shape .ShapeType ()]
992+ except :
993+ return 'unknown'
1014994
1015995# Classes
1016996class shape (object ):
@@ -1340,7 +1320,7 @@ def __init__(self, s):
13401320 self .shape = b .Vertex ()
13411321 elif isinstance (s , _TopoDS .TopoDS_Vertex ):
13421322 self .shape = s
1343- elif isinstance (s , _TopoDS .TopoDS_Shape ):
1323+ elif isinstance (s , _TopoDS .TopoDS_Shape ) and _raw_type ( s ) == 'vertex' :
13441324 self .shape = _TopoDS_vertex (s )
13451325 else :
13461326 raise TypeError
@@ -1363,7 +1343,7 @@ class edge(shape):
13631343 def __init__ (self , s ):
13641344 if isinstance (s , _TopoDS .TopoDS_Edge ):
13651345 self .shape = s
1366- elif isinstance (s , _TopoDS .TopoDS_Shape ):
1346+ elif isinstance (s , _TopoDS .TopoDS_Shape ) and _raw_type ( s ) == 'edge' :
13671347 self .shape = _TopoDS_edge (s )
13681348 else :
13691349 raise TypeError
@@ -1440,7 +1420,7 @@ def __init__(self, es):
14401420 self .shape = b .Wire ()
14411421 elif isinstance (es , _TopoDS .TopoDS_Wire ):
14421422 self .shape = es
1443- elif isinstance (es , _TopoDS .TopoDS_Shape ):
1423+ elif isinstance (es , _TopoDS .TopoDS_Shape ) and _raw_type ( es ) == 'wire' :
14441424 self .shape = _TopoDS_wire (es )
14451425 else :
14461426 raise TypeError
@@ -1496,7 +1476,7 @@ class face(shape):
14961476 def __init__ (self , s ):
14971477 if isinstance (s , _TopoDS .TopoDS_Face ):
14981478 self .shape = s
1499- elif isinstance (s , _TopoDS .TopoDS_Shape ):
1479+ elif isinstance (s , _TopoDS .TopoDS_Shape ) and _raw_type ( s ) == 'face' :
15001480 self .shape = _TopoDS_face (s )
15011481 else :
15021482 raise TypeError
@@ -1519,7 +1499,7 @@ def fillet(self, rad, vertex_indices=None):
15191499 """
15201500
15211501 raw_vertices = self ._raw ('vertex' )
1522- if type (rad ) == type ( 0.0 ):
1502+ if isinstance (rad , float ):
15231503 # Make real vertex_indices
15241504 if vertex_indices is None :
15251505 vertex_indices = range (len (raw_vertices ))
@@ -1622,7 +1602,7 @@ def __init__(self, fs, tolerance=1e-6):
16221602 print 'sewing type:' , self ._raw_type ()
16231603 elif isinstance (fs , _TopoDS .TopoDS_Shell ):
16241604 self .shape = fs
1625- elif isinstance (fs , _TopoDS .TopoDS_Shape ):
1605+ elif isinstance (fs , _TopoDS .TopoDS_Shape ) and _raw_type ( fs ) == 'shell' :
16261606 self .shape = _TopoDS_shell (fs )
16271607 else :
16281608 raise TypeError
@@ -1659,20 +1639,31 @@ class solid(shape):
16591639 """
16601640 A closed and filled shell. Can be instantiated with a list of
16611641 shells to connect.
1642+
1643+ Currently OCC compund and compsolid are also handled by solid.
1644+ That isn't right. Ultimately, should make them their own classes
1645+ and type check more carefully ***.
16621646 """
16631647
16641648 stype = 'solid'
16651649
16661650 def __init__ (self , ss ):
1667- if isinstance (ss , list ):
1651+ if isinstance (ss , ( list , tuple ) ):
16681652 b = _BRepBuilderAPI .BRepBuilderAPI_MakeSolid ()
16691653 for s in ss :
16701654 b .Add (_TopoDS_shell (s .shape ))
16711655 self .shape = b .Solid ()
16721656 elif isinstance (ss , _TopoDS .TopoDS_Solid ):
16731657 self .shape = ss
16741658 elif isinstance (ss , _TopoDS .TopoDS_Shape ):
1675- self .shape = _TopoDS .TopoDS_solid (ss )
1659+ if _raw_type (ss ) == 'solid' :
1660+ self .shape = _TopoDS .TopoDS_solid (ss )
1661+ elif _raw_type (ss ) == 'compound' :
1662+ self .shape = _TopoDS .TopoDS_compound (ss )
1663+ elif _raw_type (ss ) == 'compsolid' :
1664+ self .shape = _TopoDS .TopoDS_compsolid (ss )
1665+ else :
1666+ raise TypeError
16761667 else :
16771668 raise TypeError
16781669
0 commit comments