1 # Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 import SHAPERSTUDY_ORB__POA
24 import SHAPERSTUDY_ORB
25 import SHAPERSTUDY_Object
27 from SHAPERSTUDY_utils import getStudy
31 class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations,
32 SHAPERSTUDY_Object.SHAPERSTUDY_GenericObject):
34 Construct an instance of SHAPERSTUDY IShapesOperations.
36 def __init__ ( self, *args):
37 SHAPERSTUDY_Object.SHAPERSTUDY_GenericObject.__init__(self)
39 self.myop = StudyData_Swig.StudyData_Operation()
42 def GetAllSubShapesIDs( self, theShape, theShapeType, isSorted ):
44 Explode a shape on sub-shapes of a given type.
47 theShape Shape to be exploded.
48 theShapeType Type of sub-shapes to be retrieved.
49 isSorted If this parameter is TRUE, sub-shapes will be
50 sorted by coordinates of their gravity centers.
52 aList = self.myop.GetAllSubShapesIDs(theShape.getShape(), theShapeType, isSorted)
53 self.done = not aList.empty()
59 def GetSharedShapes( self, theShape1, theShape2, theShapeType ):
61 Get sub-shapes, shared by input shapes.
64 theShape1 Shape to find sub-shapes in.
65 theShape2 Shape to find shared sub-shapes with.
66 theShapeType Type of sub-shapes to be retrieved.
68 aList = self.myop.GetSharedShapes(theShape1.getShape(), theShape2.getShape(), theShapeType)
69 self.done = not aList.empty()
75 def GetSubShapeIndex( self, theMainShape, theSubShape ):
77 Get global index of theSubShape in theMainShape.
79 anIndex = self.myop.GetSubShapeIndex(theMainShape.getShape(), theSubShape.getShape())
80 self.done = anIndex != 0
83 def GetSubShape( self, theMainShape, theID ):
85 Get a sub-shape defined by its unique ID within theMainShape
87 aShape = self.myop.GetSubShape(theMainShape.getShape(), theID)
88 self.done = aShape != 0
92 # create a shape-object that contain the internal shape only
93 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
94 aShapeObj.SetShapeByPointer(aShape)
95 return aShapeObj._this()
97 def GetInPlace( self, theShapeWhere, theShapeWhat ):
99 Get sub-shape(s) of \a theShapeWhere, which are
100 coincident with \a theShapeWhat or could be a part of it.
103 return SHAPERSTUDY_Object()._this()
105 def GetInPlaceMap( self, theShapeWhere, theShapeWhat ):
107 A sort of GetInPlace functionality, returning for each sub-shape ID of
108 \a theShapeWhat a list of corresponding sub-shape IDs of \a theShapeWhere.
115 To know, if the operation was successfully performed
121 class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
123 Construct an instance of SHAPERSTUDY IShapesOperations.
125 def __init__ ( self, *args):
126 SHAPERSTUDY_IShapesOperations.__init__(self)
130 def CreateGroup( self, theMainShape, theShapeType ):
132 Creates a new group which will store sub-shapes of theMainShape
134 if theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
135 print("Error: You could create group of only next type: vertex, edge, face or solid")
138 aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
139 aGroupPtr = aGroup._this()
140 aGroup.SetSelectionType(theShapeType) # create a new field specific for the group python object
144 def FindGroup(self, theOwner, theEntry):
146 Searches existing group of theOwner shape by the entry. Returns NULL if can not find.
149 anIter = aStudy.NewChildIterator(theOwner.GetSO())
151 aGroupObj = anIter.Value().GetObject()
153 if aGroupObj.GetEntry() == theEntry:
158 return None # not found
160 def UnionList( self, theGroup, theSubShapes ):
162 Adds to the group all the given shapes. No errors, if some shapes are already included.
165 theGroup is a GEOM group to which the new sub-shapes are added.
166 theSubShapes is a list of sub-shapes to be added.
168 # Not needed while SHAPER-STUDY has no sub-shapes in the structure, so,
169 # theSubShapes can not be filled or treated
174 To know, if the operation was successfully performed
178 def GetMainShape( self, theGroup ):
180 Returns a main shape associated with the group
182 aSO = theGroup.GetSO()
183 aFatherSO = aSO.GetFather()
184 if isinstance( anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object ):
189 def GetType( self, theGroup ):
191 Returns a type (int) of sub-objects stored in the group
193 return theGroup.GetSelectionType()
195 def GetObjects( self, theGroup ):
197 Returns a list of sub-objects ID stored in the group
199 return theGroup.GetSelection()
203 class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations):
205 Construct an instance of SHAPERSTUDY IFieldOperations.
207 def __init__ ( self, *args):
208 SHAPERSTUDY_IShapesOperations.__init__(self)
211 def CreateFieldByType( self, theMainShape, theShapeType):
213 Creates a new group which will store sub-shapes of theMainShape
215 if theShapeType != 8 and theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
216 print("Error: You could create field of only next type: vertex, edge, face or solid, whole part")
219 aField = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
220 aFieldPtr = aField._this()
221 aField.SetSelectionType(theShapeType) # create a new field specific for the group python object
224 def FindField(self, theOwner, theEntry):
226 Searches existing field of theOwner shape by the entry. Returns NULL if can not find.
229 anIter = aStudy.NewChildIterator(theOwner.GetSO())
231 if len(anIter.Value().GetIOR()):
232 aFieldObj = anIter.Value().GetObject()
234 if aFieldObj.GetEntry() == theEntry:
237 return None # not found
240 def GetFields( self, shape ):
242 Returns all fields on a shape
246 anIter = aStudy.NewChildIterator(shape.GetSO())
248 aFieldObj = anIter.Value().GetObject()
249 if aFieldObj and isinstance(aFieldObj, SHAPERSTUDY_ORB._objref_SHAPER_Field):
250 aResList.append(aFieldObj)
257 class SHAPERSTUDY_IMeasureOperations(SHAPERSTUDY_ORB__POA.IMeasureOperations):
259 Construct an instance of SHAPERSTUDY IMeasureOperations.
261 def __init__ ( self, *args):
262 SHAPERSTUDY_IShapesOperations.__init__(self)
265 def GetVertexByIndex( self, theShape, theIndex, theUseOri ):
267 Get a vertex sub-shape by index.
270 theShape Shape to find sub-shape.
271 theIndex Index to find vertex by this index (starting from zero)
272 theUseOri To consider edge/wire orientation or not
274 return [ SHAPERSTUDY_Field() ]