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):
38 self.myop = StudyData_Swig.StudyData_Operation()
41 def GetAllSubShapesIDs( self, theShape, theShapeType, isSorted ):
43 Explode a shape on sub-shapes of a given type.
46 theShape Shape to be exploded.
47 theShapeType Type of sub-shapes to be retrieved.
48 isSorted If this parameter is TRUE, sub-shapes will be
49 sorted by coordinates of their gravity centers.
51 aList = self.myop.GetAllSubShapesIDs(theShape.getShape(), theShapeType, isSorted)
52 self.done = not aList.empty()
58 def GetSharedShapes( self, theShape1, theShape2, theShapeType ):
60 Get sub-shapes, shared by input shapes.
63 theShape1 Shape to find sub-shapes in.
64 theShape2 Shape to find shared sub-shapes with.
65 theShapeType Type of sub-shapes to be retrieved.
67 aList = self.myop.GetSharedShapes(theShape1.getShape(), theShape2.getShape(), theShapeType)
68 self.done = not aList.empty()
74 def GetSubShapeIndex( self, theMainShape, theSubShape ):
76 Get global index of theSubShape in theMainShape.
78 anIndex = self.myop.GetSubShapeIndex(theMainShape.getShape(), theSubShape.getShape())
79 self.done = anIndex != 0
82 def GetSubShape( self, theMainShape, theID ):
84 Get a sub-shape defined by its unique ID within theMainShape
86 aShape = self.myop.GetSubShape(theMainShape.getShape(), theID)
87 self.done = aShape != 0
91 # create a shape-object that contain the internal shape only
92 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
93 aShapeObj.SetShapeByPointer(aShape)
94 return aShapeObj._this()
96 def GetInPlace( self, theShapeWhere, theShapeWhat ):
98 Get sub-shape(s) of \a theShapeWhere, which are
99 coincident with \a theShapeWhat or could be a part of it.
102 return SHAPERSTUDY_Object()._this()
104 def GetInPlaceMap( self, theShapeWhere, theShapeWhat ):
106 A sort of GetInPlace functionality, returning for each sub-shape ID of
107 \a theShapeWhat a list of corresponding sub-shape IDs of \a theShapeWhere.
114 To know, if the operation was successfully performed
120 class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
122 Construct an instance of SHAPERSTUDY IShapesOperations.
124 def __init__ ( self, *args):
128 def CreateGroup( self, theMainShape, theShapeType ):
130 Creates a new group which will store sub-shapes of theMainShape
132 if theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
133 print("Error: You could create group of only next type: vertex, edge, face or solid")
136 aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
137 aGroupPtr = aGroup._this()
138 aGroup.SetSelectionType(theShapeType) # create a new field specific for the group python object
142 def FindGroup(self, theOwner, theEntry):
144 Searches existing group of theOwner shape by the entry. Returns NULL if can not find.
147 anIter = aStudy.NewChildIterator(theOwner.GetSO())
149 aGroupObj = anIter.Value().GetObject()
151 if aGroupObj.GetEntry() == theEntry:
156 return None # not found
158 def UnionList( self, theGroup, theSubShapes ):
160 Adds to the group all the given shapes. No errors, if some shapes are already included.
163 theGroup is a GEOM group to which the new sub-shapes are added.
164 theSubShapes is a list of sub-shapes to be added.
166 # Not needed while SHAPER-STUDY has no sub-shapes in the structure, so,
167 # theSubShapes can not be filled or treated
172 To know, if the operation was successfully performed
176 def GetMainShape( self, theGroup ):
178 Returns a main shape associated with the group
180 aSO = theGroup.GetSO()
181 aFatherSO = aSO.GetFather()
182 return aFatherSO.GetObject()
184 def GetType( self, theGroup ):
186 Returns a type (int) of sub-objects stored in the group
188 return theGroup.GetSelectionType()
190 def GetObjects( self, theGroup ):
192 Returns a list of sub-objects ID stored in the group
194 return theGroup.GetSelection()
198 class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations):
200 Construct an instance of SHAPERSTUDY IFieldOperations.
202 def __init__ ( self, *args):
205 def CreateFieldByType( self, theMainShape, theShapeType):
207 Creates a new group which will store sub-shapes of theMainShape
209 if theShapeType != 8 and theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
210 print("Error: You could create field of only next type: vertex, edge, face or solid, whole part")
213 aField = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
214 aFieldPtr = aField._this()
215 aField.SetSelectionType(theShapeType) # create a new field specific for the group python object
218 def FindField(self, theOwner, theEntry):
220 Searches existing field of theOwner shape by the entry. Returns NULL if can not find.
223 anIter = aStudy.NewChildIterator(theOwner.GetSO())
225 if len(anIter.Value().GetIOR()):
226 aFieldObj = anIter.Value().GetObject()
228 if aFieldObj.GetEntry() == theEntry:
231 return None # not found
234 def GetFields( self, shape ):
236 Returns all fields on a shape
240 anIter = aStudy.NewChildIterator(shape.GetSO())
242 aFieldObj = anIter.Value().GetObject()
243 if aFieldObj and isinstance(aFieldObj, SHAPERSTUDY_ORB._objref_SHAPER_Field):
244 aResList.append(aFieldObj)
251 class SHAPERSTUDY_IMeasureOperations(SHAPERSTUDY_ORB__POA.IMeasureOperations):
253 Construct an instance of SHAPERSTUDY IMeasureOperations.
255 def __init__ ( self, *args):
258 def GetVertexByIndex( self, theShape, theIndex, theUseOri ):
260 Get a vertex sub-shape by index.
263 theShape Shape to find sub-shape.
264 theIndex Index to find vertex by this index (starting from zero)
265 theUseOri To consider edge/wire orientation or not
267 return [ SHAPERSTUDY_Field() ]