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()
55 def GetSharedShapes( self, theShape1, theShape2, theShapeType ):
57 Get sub-shapes, shared by input shapes.
60 theShape1 Shape to find sub-shapes in.
61 theShape2 Shape to find shared sub-shapes with.
62 theShapeType Type of sub-shapes to be retrieved.
64 aList = self.myop.GetSharedShapes(theShape1.getShape(), theShape2.getShape(), theShapeType)
65 self.done = not aList.empty()
68 def GetSubShapeIndex( self, theMainShape, theSubShape ):
70 Get global index of theSubShape in theMainShape.
72 anIndex = self.myop.GetSubShapeIndex(theMainShape.getShape(), theSubShape.getShape())
73 self.done = anIndex != 0
76 def GetSubShape( self, theMainShape, theID ):
78 Get a sub-shape defined by its unique ID within theMainShape
80 aShape = self.myop.GetSubShape(theMainShape.getShape(), theID)
81 self.done = aShape != 0
85 # create a shape-object that contain the internal shape only
86 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
87 aShapeObj.SetShapeByPointer(aShape)
88 return aShapeObj._this()
90 def GetInPlace( self, theShapeWhere, theShapeWhat ):
92 Get sub-shape(s) of \a theShapeWhere, which are
93 coincident with \a theShapeWhat or could be a part of it.
96 return SHAPERSTUDY_Object()._this()
98 def GetInPlaceMap( self, theShapeWhere, theShapeWhat ):
100 A sort of GetInPlace functionality, returning for each sub-shape ID of
101 \a theShapeWhat a list of corresponding sub-shape IDs of \a theShapeWhere.
108 To know, if the operation was successfully performed
114 class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
116 Construct an instance of SHAPERSTUDY IShapesOperations.
118 def __init__ ( self, *args):
122 def CreateGroup( self, theMainShape, theShapeType ):
124 Creates a new group which will store sub-shapes of theMainShape
126 if theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
127 print("Error: You could create group of only next type: vertex, edge, face or solid")
130 aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
131 aGroupPtr = aGroup._this()
132 aGroup.SetSelectionType(theShapeType) # create a new field specific for the group python object
136 def FindGroup(self, theOwner, theEntry):
138 Searches existing group of theOwner shape by the entry. Returns NULL if can not find.
141 anIter = aStudy.NewChildIterator(theOwner.GetSO())
143 aGroupObj = anIter.Value().GetObject()
145 if aGroupObj.GetEntry() == theEntry:
150 return None # not found
152 def UnionList( self, theGroup, theSubShapes ):
154 Adds to the group all the given shapes. No errors, if some shapes are already included.
157 theGroup is a GEOM group to which the new sub-shapes are added.
158 theSubShapes is a list of sub-shapes to be added.
160 # Not needed while SHAPER-STUDY has no sub-shapes in the structure, so,
161 # theSubShapes can not be filled or treated
166 To know, if the operation was successfully performed
170 def GetMainShape( self, theGroup ):
172 Returns a main shape associated with the group
174 aSO = theGroup.GetSO()
175 aFatherSO = aSO.GetFather()
176 return aFatherSO.GetObject()
178 def GetType( self, theGroup ):
180 Returns a type (int) of sub-objects stored in the group
182 return theGroup.GetSelectionType()
184 def GetObjects( self, theGroup ):
186 Returns a list of sub-objects ID stored in the group
188 return theGroup.GetSelection()
192 class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations):
194 Construct an instance of SHAPERSTUDY IFieldOperations.
196 def __init__ ( self, *args):
199 def CreateFieldByType( self, theMainShape, theShapeType):
201 Creates a new group which will store sub-shapes of theMainShape
203 if theShapeType != 8 and theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
204 print("Error: You could create field of only next type: vertex, edge, face or solid, whole part")
207 aField = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
208 aFieldPtr = aField._this()
209 aField.SetSelectionType(theShapeType) # create a new field specific for the group python object
212 def FindField(self, theOwner, theEntry):
214 Searches existing field of theOwner shape by the entry. Returns NULL if can not find.
217 anIter = aStudy.NewChildIterator(theOwner.GetSO())
219 aFieldObj = anIter.Value().GetObject()
221 if aFieldObj.GetEntry() == theEntry:
224 return None # not found
227 def GetFields( self, shape ):
229 Returns all fields on a shape
233 anIter = aStudy.NewChildIterator(shape.GetSO())
235 aFieldObj = anIter.Value().GetObject()
236 if aFieldObj and isinstance(aFieldObj, SHAPERSTUDY_ORB._objref_SHAPER_Field):
237 aResList.append(aFieldObj)
243 class SHAPERSTUDY_IMeasureOperations(SHAPERSTUDY_ORB__POA.IMeasureOperations):
245 Construct an instance of SHAPERSTUDY IMeasureOperations.
247 def __init__ ( self, *args):
250 def GetVertexByIndex( self, theShape, theIndex, theUseOri ):
252 Get a vertex sub-shape by index.
255 theShape Shape to find sub-shape.
256 theIndex Index to find vertex by this index (starting from zero)
257 theUseOri To consider edge/wire orientation or not
259 return [ SHAPERSTUDY_Field() ]