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):
33 Construct an instance of SHAPERSTUDY IShapesOperations.
35 def __init__ ( self, *args):
37 self.myop = StudyData_Swig.StudyData_Operation()
40 def GetAllSubShapesIDs( self, theShape, theShapeType, isSorted ):
42 Explode a shape on sub-shapes of a given type.
45 theShape Shape to be exploded.
46 theShapeType Type of sub-shapes to be retrieved.
47 isSorted If this parameter is TRUE, sub-shapes will be
48 sorted by coordinates of their gravity centers.
50 aList = self.myop.GetAllSubShapesIDs(theShape.getShape(), theShapeType, isSorted)
51 self.done = not aList.empty()
54 def GetSharedShapes( self, theShape1, theShape2, theShapeType ):
56 Get sub-shapes, shared by input shapes.
59 theShape1 Shape to find sub-shapes in.
60 theShape2 Shape to find shared sub-shapes with.
61 theShapeType Type of sub-shapes to be retrieved.
63 aList = self.myop.GetSharedShapes(theShape1.getShape(), theShape2.getShape(), theShapeType)
64 self.done = not aList.empty()
67 def GetSubShapeIndex( self, theMainShape, theSubShape ):
69 Get global index of theSubShape in theMainShape.
71 anIndex = self.myop.GetSubShapeIndex(theMainShape.getShape(), theSubShape.getShape())
72 self.done = anIndex != 0
75 def GetSubShape( self, theMainShape, theID ):
77 Get a sub-shape defined by its unique ID within theMainShape
79 aShape = self.myop.GetSubShape(theMainShape.getShape(), theID)
80 self.done = aShape != 0
84 # create a shape-object that contain the internal shape only
85 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
86 aShapeObj.SetShapeByPointer(aShape)
89 def GetInPlace( self, theShapeWhere, theShapeWhat ):
91 Get sub-shape(s) of \a theShapeWhere, which are
92 coincident with \a theShapeWhat or could be a part of it.
95 return SHAPERSTUDY_Object()._this()
97 def GetInPlaceMap( self, theShapeWhere, theShapeWhat ):
99 A sort of GetInPlace functionality, returning for each sub-shape ID of
100 \a theShapeWhat a list of corresponding sub-shape IDs of \a theShapeWhere.
107 To know, if the operation was successfully performed
113 class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
115 Construct an instance of SHAPERSTUDY IShapesOperations.
117 def __init__ ( self, *args):
121 def CreateGroup( self, theMainShape, theShapeType ):
123 Creates a new group which will store sub-shapes of theMainShape
125 if theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
126 print("Error: You could create group of only next type: vertex, edge, face or solid")
129 aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
130 aGroupPtr = aGroup._this()
131 aGroup.SetSelectionType(theShapeType) # create a new field specific for the group python object
135 def FindGroup(self, theOwner, theEntry):
137 Searches existing group of theOwner shape by the entry. Returns NULL if can not find.
140 anIter = aStudy.NewChildIterator(theOwner.GetSO())
142 aGroupObj = anIter.Value().GetObject()
144 if aGroupObj.GetEntry() == theEntry:
149 return None # not found
151 def UnionList( self, theGroup, theSubShapes ):
153 Adds to the group all the given shapes. No errors, if some shapes are already included.
156 theGroup is a GEOM group to which the new sub-shapes are added.
157 theSubShapes is a list of sub-shapes to be added.
159 # Not needed while SHAPER-STUDY has no sub-shapes in the structure, so,
160 # theSubShapes can not be filled or treated
165 To know, if the operation was successfully performed
169 def GetMainShape( self, theGroup ):
171 Returns a main shape associated with the group
173 aSO = theGroup.GetSO()
174 aFatherSO = aSO.GetFather()
175 return aFatherSO.GetObject()
177 def GetType( self, theGroup ):
179 Returns a type (int) of sub-objects stored in the group
181 return theGroup.GetSelectionType()
183 def GetObjects( self, theGroup ):
185 Returns a list of sub-objects ID stored in the group
187 return theGroup.GetSelection()
191 class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations):
193 Construct an instance of SHAPERSTUDY IFieldOperations.
195 def __init__ ( self, *args):
198 def CreateFieldByType( self, theMainShape, theShapeType):
200 Creates a new group which will store sub-shapes of theMainShape
202 if theShapeType != 8 and theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
203 print("Error: You could create field of only next type: vertex, edge, face or solid, whole part")
206 aField = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
207 aFieldPtr = aField._this()
208 aField.SetSelectionType(theShapeType) # create a new field specific for the group python object
211 def FindField(self, theOwner, theEntry):
213 Searches existing field of theOwner shape by the entry. Returns NULL if can not find.
216 anIter = aStudy.NewChildIterator(theOwner.GetSO())
218 aFieldObj = anIter.Value().GetObject()
220 if aFieldObj.GetEntry() == theEntry:
223 return None # not found
226 def GetFields( self, shape ):
228 Returns all fields on a shape
232 anIter = aStudy.NewChildIterator(shape.GetSO())
234 aFieldObj = anIter.Value().GetObject()
235 if aFieldObj and isinstance(aFieldObj, SHAPERSTUDY_ORB._objref_SHAPER_Field):
236 aResList.append(aFieldObj)
242 class SHAPERSTUDY_IMeasureOperations(SHAPERSTUDY_ORB__POA.IMeasureOperations):
244 Construct an instance of SHAPERSTUDY IMeasureOperations.
246 def __init__ ( self, *args):
249 def GetVertexByIndex( self, theShape, theIndex, theUseOri ):
251 Get a vertex sub-shape by index.
254 theShape Shape to find sub-shape.
255 theIndex Index to find vertex by this index (starting from zero)
256 theUseOri To consider edge/wire orientation or not
258 return [ SHAPERSTUDY_Field() ]