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_Object
26 from SHAPERSTUDY_utils import getStudy
30 class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations):
32 Construct an instance of SHAPERSTUDY IShapesOperations.
34 def __init__ ( self, *args):
36 self.myop = StudyData_Swig.StudyData_Operation()
39 def GetAllSubShapesIDs( self, theShape, theShapeType, isSorted ):
41 Explode a shape on sub-shapes of a given type.
44 theShape Shape to be exploded.
45 theShapeType Type of sub-shapes to be retrieved.
46 isSorted If this parameter is TRUE, sub-shapes will be
47 sorted by coordinates of their gravity centers.
49 aList = self.myop.GetAllSubShapesIDs(theShape.getShape(), theShapeType, isSorted)
50 self.done = not aList.empty()
53 def GetSharedShapes( self, theShape1, theShape2, theShapeType ):
55 Get sub-shapes, shared by input shapes.
58 theShape1 Shape to find sub-shapes in.
59 theShape2 Shape to find shared sub-shapes with.
60 theShapeType Type of sub-shapes to be retrieved.
62 aList = self.myop.GetSharedShapes(theShape1.getShape(), theShape2.getShape(), theShapeType)
63 self.done = not aList.empty()
66 def GetSubShapeIndex( self, theMainShape, theSubShape ):
68 Get global index of theSubShape in theMainShape.
70 anIndex = self.myop.GetSubShapeIndex(theMainShape.getShape(), theSubShape.getShape())
71 self.done = anIndex != 0
74 def GetSubShape( self, theMainShape, theID ):
76 Get a sub-shape defined by its unique ID within theMainShape
78 aShape = self.myop.GetSubShape(theMainShape.getShape(), theID)
79 self.done = aShape != 0
83 # create a shape-object that contain the internal shape only
84 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
85 aShapeObj.SetShapeByPointer(aShape)
88 def GetInPlace( self, theShapeWhere, theShapeWhat ):
90 Get sub-shape(s) of \a theShapeWhere, which are
91 coincident with \a theShapeWhat or could be a part of it.
94 return SHAPERSTUDY_Object()._this()
96 def GetInPlaceMap( self, theShapeWhere, theShapeWhat ):
98 A sort of GetInPlace functionality, returning for each sub-shape ID of
99 \a theShapeWhat a list of corresponding sub-shape IDs of \a theShapeWhere.
106 To know, if the operation was successfully performed
112 class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
114 Construct an instance of SHAPERSTUDY IShapesOperations.
116 def __init__ ( self, *args):
120 def CreateGroup( self, theMainShape, theShapeType ):
122 Creates a new group which will store sub-shapes of theMainShape
124 if theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
125 print("Error: You could create group of only next type: vertex, edge, face or solid")
128 aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
129 aGroupPtr = aGroup._this()
130 aGroupPtr.SetType(37) # the group type
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 return None # not found
179 def GetType( self, theGroup ):
181 Returns a type (int) of sub-objects stored in the group
183 return theGroup.GetSelectionType()
185 def GetObjects( self, theGroup ):
187 Returns a list of sub-objects ID stored in the group
189 return theGroup.GetSelection()
193 class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations):
195 Construct an instance of SHAPERSTUDY IFieldOperations.
197 def __init__ ( self, *args):
200 def GetFields( self, shape ):
202 Returns all fields on a shape
204 return [ SHAPERSTUDY_Field() ]
209 class SHAPERSTUDY_IMeasureOperations(SHAPERSTUDY_ORB__POA.IMeasureOperations):
211 Construct an instance of SHAPERSTUDY IMeasureOperations.
213 def __init__ ( self, *args):
216 def GetVertexByIndex( self, theShape, theIndex, theUseOri ):
218 Get a vertex sub-shape by index.
221 theShape Shape to find sub-shape.
222 theIndex Index to find vertex by this index (starting from zero)
223 theUseOri To consider edge/wire orientation or not
225 return [ SHAPERSTUDY_Field() ]