1 # Copyright (C) 2019-2020 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 import SHAPERSTUDY_ORB__POA
21 import SHAPERSTUDY_ORB
22 import SHAPERSTUDY_Object
25 from SHAPERSTUDY_utils import getStudy
29 class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations,
30 SHAPERSTUDY_Object.SHAPERSTUDY_GenericObject):
32 Construct an instance of SHAPERSTUDY IShapesOperations.
34 def __init__ ( self, *args):
35 SHAPERSTUDY_Object.SHAPERSTUDY_GenericObject.__init__(self)
37 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)
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)
74 def GetSubShapeIndex( self, theMainShape, theSubShape ):
76 Get global index of theSubShape in theMainShape.
78 anIndex = self.myop.GetSubShapeIndex(theMainShape.getShape(), theSubShape.getShape())
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 ExtractSubShapes(self, aShape, aType, isSorted):
98 Extract shapes (excluding the main shape) of given type.
102 aType The shape type (see geompy.ShapeType)
103 isSorted Boolean flag to switch sorting on/off.
106 List of sub-shapes of type aType, contained in aShape.
108 shapes = self.myop.ExtractSubShapes( aShape.getShape(), aType, isSorted )
111 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
112 aShapeObj.SetShapeByPointer( s )
113 resultList.append( aShapeObj._this() )
118 def NumberOfEdges(self, theShape):
120 Gives quantity of edges in the given shape.
123 theShape Shape to count edges of.
128 nb = self.myop.NumberOfEdges( theShape.getShape() )
129 self.done = ( nb >= 0 )
132 def NumberOfFaces(self, theShape):
134 Gives quantity of faces in the given shape.
137 theShape Shape to count faces of.
142 nb = self.myop.NumberOfFaces( theShape.getShape() )
143 self.done = ( nb >= 0 )
146 def MakeAllSubShapes(self, aShape, aType):
148 Explode a shape on sub-shapes of a given type.
149 If the shape itself matches the type, it is also returned.
152 aShape Shape to be exploded.
153 aType Type of sub-shapes to be retrieved (see geompy.ShapeType)
156 List of sub-shapes of type theShapeType, contained in theShape.
159 return self.myop.MakeAllSubShapes(aShape.getShape(), aType)
161 def MakeSubShapes(self, aShape, anIDs):
163 Get a set of sub-shapes defined by their unique IDs inside theMainShape
167 anIDs List of unique IDs of sub-shapes inside theMainShape.
170 List of GEOM.GEOM_Object, corresponding to found sub-shapes.
173 return self.myop.MakeSubShapes(aShape.getShape(), anIDs)
175 def GetExistingSubObjects(self, theShape, theGroupsOnly = False):
177 Get all sub-shapes and groups of theShape,
178 that were created already by any other methods.
182 theGroupsOnly If this parameter is TRUE, only groups will be
183 returned, else all found sub-shapes and groups.
186 List of existing sub-objects of theShape.
190 SObj = salome.ObjectToSObject( theShape )
191 if not SObj: return ListObj
192 soIter = salome.myStudy.NewChildIterator( SObj )
194 soChild = soIter.Value()
196 obj = soChild.GetObject()
198 if isinstance( obj, SHAPERSTUDY_ORB._objref_SHAPER_Group):
199 ListObj.append( obj )
200 elif isinstance( obj, SHAPERSTUDY_ORB._objref_SHAPER_Object ):
201 ListObj.append( obj )
205 def GetTopologyIndex(self, aMainObj, aSubObj):
207 Return index of a sub-shape
209 i = self.myop.GetTopologyIndex(aMainObj.getShape(), aSubObj.getShape())
210 self.done = ( i > 0 )
213 def GetShapeTypeString(self,aSubObj):
215 Return a shape type as a string
217 s = "%s" % aSubObj.GetShapeType()
222 def GetInPlace( self, theShapeWhere, theShapeWhat ):
224 Get sub-shape(s) of \a theShapeWhere, which are
225 coincident with \a theShapeWhat or could be a part of it.
228 self.errorcode = "Not implemented"
229 return SHAPERSTUDY_Object()._this()
231 def GetInPlaceMap( self, theShapeWhere, theShapeWhat ):
233 A sort of GetInPlace functionality, returning for each sub-shape ID of
234 \a theShapeWhat a list of corresponding sub-shape IDs of \a theShapeWhere.
237 self.errorcode = "Not implemented"
242 To know, if the operation was successfully performed
248 def GetErrorCode( self ):
250 To know a failure reason
252 return self.errorcode
256 class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations,
257 SHAPERSTUDY_IShapesOperations):
259 Construct an instance of SHAPERSTUDY IShapesOperations.
261 def __init__ ( self, *args):
262 SHAPERSTUDY_IShapesOperations.__init__(self)
266 def CreateGroup( self, theMainShape, theShapeType ):
268 Creates a new group which will store sub-shapes of theMainShape
270 if theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
271 print("Error: You could create group of only next type: vertex, edge, face or solid")
274 aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
275 aGroupPtr = aGroup._this()
276 aGroup.SetSelectionType(theShapeType) # create a new field specific for the group python object
280 def FindGroup(self, theOwner, theEntry):
282 Searches existing group of theOwner shape by the entry. Returns NULL if can not find.
285 anIter = aStudy.NewChildIterator(theOwner.GetSO())
287 aGroupObj = anIter.Value().GetObject()
289 if aGroupObj.GetEntry() == theEntry:
294 return None # not found
296 def UnionList( self, theGroup, theSubShapes ):
298 Adds to the group all the given shapes. No errors, if some shapes are already included.
301 indices = theGroup.GetSelection()
302 mainShape = self.GetMainShape( theGroup )
304 self.errorcode = "No main shape"
306 groupType = self.GetType( theGroup )
307 from shaperBuilder import EnumToLong
308 for shape in theSubShapes:
309 shapeType = EnumToLong( shape.GetShapeType() )
310 if not groupType == shapeType:
311 self.errorcode = "Group type and shape type mismatch"
313 i = self.myop.GetSubShapeIndex( mainShape.getShape(), shape.getShape() )
316 theGroup.SetSelection( indices )
320 def GetMainShape( self, theGroup ):
322 Returns a main shape associated with the group
324 aSO = theGroup.GetSO()
327 aFatherSO = aSO.GetFather()
330 anObj = aFatherSO.GetObject()
331 if isinstance( anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object ):
336 def GetType( self, theGroup ):
338 Returns a type (int) of sub-objects stored in the group
340 return theGroup.GetSelectionType()
342 def GetObjects( self, theGroup ):
344 Returns a list of sub-objects ID stored in the group
346 return theGroup.GetSelection()
350 class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations,
351 SHAPERSTUDY_IShapesOperations):
353 Construct an instance of SHAPERSTUDY IFieldOperations.
355 def __init__ ( self, *args):
356 SHAPERSTUDY_IShapesOperations.__init__(self)
359 def CreateFieldByType( self, theMainShape, theShapeType):
361 Creates a new group which will store sub-shapes of theMainShape
363 if theShapeType != 8 and theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2:
364 print("Error: You could create field of only next type: vertex, edge, face or solid, whole part")
367 aField = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
368 aFieldPtr = aField._this()
369 aField.SetSelectionType(theShapeType) # create a new field specific for the group python object
372 def FindField(self, theOwner, theEntry):
374 Searches existing field of theOwner shape by the entry. Returns NULL if can not find.
377 anIter = aStudy.NewChildIterator(theOwner.GetSO())
379 if len(anIter.Value().GetIOR()):
380 aFieldObj = anIter.Value().GetObject()
382 if aFieldObj.GetEntry() == theEntry:
385 return None # not found
388 def GetFields( self, shape ):
390 Returns all fields on a shape
394 anIter = aStudy.NewChildIterator(shape.GetSO())
396 aFieldObj = anIter.Value().GetObject()
397 if aFieldObj and isinstance(aFieldObj, SHAPERSTUDY_ORB._objref_SHAPER_Field):
398 aResList.append(aFieldObj)
405 class SHAPERSTUDY_IMeasureOperations(SHAPERSTUDY_ORB__POA.IMeasureOperations,
406 SHAPERSTUDY_IShapesOperations):
408 Construct an instance of SHAPERSTUDY IMeasureOperations.
410 def __init__ ( self, *args):
411 SHAPERSTUDY_IShapesOperations.__init__(self)
412 self.myop = StudyData_Swig.StudyData_Operation()
415 def GetVertexByIndex( self, theShape, theIndex, theUseOri ):
417 Get a vertex sub-shape by index.
420 theShape Shape to find sub-shape.
421 theIndex Index to find vertex by this index (starting from zero)
422 theUseOri To consider edge/wire orientation or not
424 v = self.myop.GetVertexByIndex( theShape.getShape(), theIndex, theUseOri )
425 self.done = ( v > 0 )
427 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
428 aShapeObj.SetShapeByPointer( v )
429 return aShapeObj._this()
432 def GetMinDistance(self, theShape1, theShape2):
434 Get minimal distance between the given shapes.
437 theShape1,theShape2 Shapes to find minimal distance between.
440 Value of the minimal distance between the given shapes.
442 d = self.myop.MinDistance(theShape1.getShape(), theShape2.getShape())
443 self.done = ( d >= 0 )
444 return d, 0,0,0, 0,0,0
446 def PointCoordinates(self,Point):
448 Get point coordinates
453 d = self.myop.PointCoordinates(Point.getShape())
456 return d[0],d[1],d[2]
459 def GetTolerance(self,theShape):
461 Get min and max tolerances of sub-shapes of theShape
464 theShape Shape, to get tolerances of.
467 [FaceMin,FaceMax, EdgeMin,EdgeMax, VertMin,VertMax]
468 FaceMin,FaceMax: Min and max tolerances of the faces.
469 EdgeMin,EdgeMax: Min and max tolerances of the edges.
470 VertMin,VertMax: Min and max tolerances of the vertices.
472 tol = self.myop.GetTolerance(theShape.getShape())
474 return tol,tol, tol,tol, tol,tol