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 SALOME_ComponentPy
26 import SALOME_DriverPy
28 from SHAPERSTUDY_utils import findOrCreateComponent, moduleName, getStudy, getORB
30 import SHAPERSTUDY_Object
36 class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen,
37 SALOME_ComponentPy.SALOME_ComponentPy_i,
38 SALOME_DriverPy.SALOME_DriverPy_i):
41 ShapeType = {"AUTO":-1, "COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8, "FLAT":9}
43 ShaperIcons = {GEOM.COMPOUND:"SHAPER_ICON_COMPSOLID",
44 GEOM.COMPSOLID:"SHAPER_ICON_COMPSOLID",
45 GEOM.SOLID:"SHAPER_ICON_SOLID",
46 GEOM.SHELL:"SHAPER_ICON_SHELL",
47 GEOM.FACE:"SHAPER_ICON_FACE",
48 GEOM.WIRE:"SHAPER_ICON_WIRE",
49 GEOM.EDGE:"SHAPER_ICON_EDGE",
50 GEOM.VERTEX:"SHAPER_ICON_VERTEX",
51 GEOM.SHAPE:"SHAPER_ICON_SOLID",
52 GEOM.FLAT:"SHAPER_ICON_FACE"}
54 def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
56 Construct an instance of SHAPERSTUDY module engine.
57 The class SHAPERSTUDY implements CORBA interface Gen (see SHAPERSTUDY_Gen.idl).
58 It is inherited (via GEOM_Gen) from the classes SALOME_ComponentPy_i (implementation of
59 Engines::EngineComponent CORBA interface - SALOME component) and SALOME_DriverPy_i
60 (implementation of SALOMEDS::Driver CORBA interface - SALOME module's engine).
62 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
63 contID, containerName, instanceName, interfaceName, False)
64 SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
66 #self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
70 def FindOrCreateShape( self, theInternalEntry ):
72 Searches existing or creates a new SHAPERSTUDY_Object to interact with SHAPER
74 # Searching in the study tree
75 aComponent = findOrCreateComponent()
76 aSOIter = getStudy().NewChildIterator(aComponent)
80 anObj = salome.orb.string_to_object(anIOR)
81 if isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
82 if anObj.GetEntry() == theInternalEntry:
86 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
87 aShapeObj.SetEntry(theInternalEntry)
88 return aShapeObj._this()
90 def AddInStudy( self, theObject, theName, theFather ):
92 Adds in theStudy a object theObject under theFather with a name theName,
93 if theFather is not NULL the object is placed under theFather's SObject.
94 Returns a SObject where theObject is placed
97 aBuilder = aStudy.NewBuilder()
99 theFather = findOrCreateComponent()
100 aResultSO = aBuilder.NewObject(theFather);
101 aResultSO.SetAttrString("AttributeName", theName)
104 if theObject is not None:
105 anIOR = salome.orb.object_to_string(theObject)
106 aResultSO.SetAttrString("AttributeIOR", anIOR)
107 theObject.SetSO(aResultSO)
109 aType = theObject.GetShapeType()
110 aAttr = aBuilder.FindOrCreateAttribute(aResultSO, "AttributePixMap")
111 aPixmap = aAttr._narrow(salome.SALOMEDS.AttributePixMap)
112 aPixmap.SetPixMap(SHAPERSTUDY.ShaperIcons[aType])
114 # add a red-reference that means that this is an active reference to SHAPER result
115 aSub = aBuilder.NewObject(aResultSO)
116 aBuilder.Addreference(aSub, aResultSO)
120 def AddSubShape( theMainShape, theIndices ):
122 Add a sub-shape defined by indices in theIndices
123 (contains unique IDs of sub-shapes inside theMainShape)
125 go = SHAPERSTUDY_Object()._this()
128 def RemoveObject( self, theObject ):
130 Removes the object from the component
134 def GetIFieldOperations( self ):
137 return SHAPERSTUDY_IFieldOperations()
139 def GetIGroupOperations( self ):
142 return SHAPERSTUDY_IGroupOperations()
144 def GetIShapesOperations( self ):
147 return SHAPERSTUDY_IShapesOperations()
149 def GetIMeasureOperations( self ):
152 return SHAPERSTUDY_IMeasureOperations()
154 def GetStringFromIOR( self, theObject ):
156 Returns a string which contains an IOR of the SHAPERSTUDY_Object
159 if theObject and getORB():
160 IOR = getORB().object_to_string( theObject )
164 def GetAllDumpNames( self ):
166 Returns all names with which Object's was dumped
167 into python script to avoid the same names in SMESH script
171 def GetDumpName( self, theStudyEntry ):
173 Returns a name with which a GEOM_Object was dumped into python script
176 theStudyEntry is an entry of the Object in the study
182 def Save( self, component, URL, isMultiFile ):
185 Nothing to do here because in our case all data
186 are stored in the SALOMEDS attributes.
190 def Load( self, component, stream, URL, isMultiFile ):
195 __entry2IOR__.clear()
199 def IORToLocalPersistentID(self, sobject, IOR, isMultiFile, isASCII):
201 Gets persistent ID for the CORBA object.
202 It's enough to use study entry.
204 return sobject.GetID()
206 def LocalPersistentIDToIOR(self, sobject, persistentID, isMultiFile, isASCII):
207 "Converts persistent ID of the object to its IOR."
209 if persistentID in __entry2IOR__:
210 return __entry2IOR__[persistentID]
213 def DumpPython( self, isPublished, isMultiFile ):
215 Dump module data to the Python script.
217 return ("".encode(), 1)
221 def CreateGroup( self, theMainShape, theShapeType ):
223 Creates a new group which will store sub-shapes of theMainShape
225 return GetIGroupOperations().CreateGroup( theMainShape, theShapeType );
227 def ExtractShapes( self, aShape, aType, isSorted = False ):
229 Extract shapes (excluding the main shape) of given type.
233 aType The shape type (see geompy.ShapeType)
234 isSorted Boolean flag to switch sorting on/off.
237 List of sub-shapes of type aType, contained in aShape.
239 return [ SHAPERSTUDY_Object()._this() ]
241 def GetSubShape( self, aShape, ListOfID ):
243 Obtain a composite sub-shape of aShape, composed from sub-shapes
244 of aShape, selected by their unique IDs inside aShape
247 aShape Shape to get sub-shape of.
248 ListOfID List of sub-shapes indices.
250 return SHAPERSTUDY_Object()._this()
252 def GetSubShapeID( self, aShape, aSubShape ):
254 Obtain unique ID of sub-shape aSubShape inside aShape
255 of aShape, selected by their unique IDs inside aShape
258 aShape Shape to get sub-shape of.
259 aSubShape Sub-shapes of aShape.
263 def MinDistance( self, theShape1, theShape2 ):
265 Get minimal distance between the given shapes.
269 def NumberOfEdges( self, theShape ):
271 Gives quantity of edges in the given shape.
275 def NumberOfFaces( self, ):
277 Gives quantity of faces in the given shape.
281 def PointCoordinates( self, theVertex ):
283 Get point coordinates
287 def SubShapeAll( self, aShape, aType ):
289 Explode a shape on sub-shapes of a given type.
290 If the shape itself matches the type, it is also returned.
292 return [ SHAPERSTUDY_Object()._this() ]
294 def SubShapeName( self, aSubObj, aMainObj ):
296 Get name for sub-shape aSubObj of shape aMainObj
300 def SubShapes( self, aShape, anIDs ):
302 Get a set of sub-shapes defined by their unique IDs inside theMainShape
304 return [ SHAPERSTUDY_Object()._this() ]
306 def Tolerance( self, theShape ):
308 Get min and max tolerances of sub-shapes of theShape
311 [FaceMin,FaceMax, EdgeMin,EdgeMax, VertMin,VertMax]
313 return [0,0, 0,0, 0,0]
315 def UnionList( self, theGroup, theSubShapes ):
317 Adds to the group all the given shapes. No errors, if some shapes are already included.
319 return GetIGroupOperations().UnionList( theGroup, theSubShapes )
321 def BreakLink(self, theEntry):
323 Breaks links to parametrical mode for parametrical shape
325 print("##### Break parametrical links", theEntry)