]> SALOME platform Git repositories - modules/shaper_study.git/blob - src/PY/SHAPERSTUDY.py
Salome HOME
Implementation of the automatic breaking the link if the shape is modified or deleted
[modules/shaper_study.git] / src / PY / SHAPERSTUDY.py
1 # Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 import SHAPERSTUDY_ORB__POA
24 import SHAPERSTUDY_ORB
25 import SALOME_ComponentPy
26 import SALOME_DriverPy
27 import SALOMEDS
28 from SHAPERSTUDY_utils import findOrCreateComponent, moduleName, getStudy, getORB
29 import salome
30 import SHAPERSTUDY_Object
31
32 __entry2IOR__ = {}
33
34 class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen,
35                   SALOME_ComponentPy.SALOME_ComponentPy_i,
36                   SALOME_DriverPy.SALOME_DriverPy_i):
37
38
39     ShapeType = {"AUTO":-1, "COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8, "FLAT":9}
40
41     def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
42         """
43         Construct an instance of SHAPERSTUDY module engine.
44         The class SHAPERSTUDY implements CORBA interface Gen (see SHAPERSTUDY_Gen.idl).
45         It is inherited (via GEOM_Gen) from the classes SALOME_ComponentPy_i (implementation of
46         Engines::EngineComponent CORBA interface - SALOME component) and SALOME_DriverPy_i
47         (implementation of SALOMEDS::Driver CORBA interface - SALOME module's engine).
48         """
49         SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
50                     contID, containerName, instanceName, interfaceName, False)
51         SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
52         #
53         #self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
54         #
55         pass
56
57     def FindOrCreateShape( self, theInternalEntry ):
58         """
59         Searches existing or creates a new SHAPERSTUDY_Object to interact with SHAPER
60         """
61         # Searching in the study tree
62         aComponent = findOrCreateComponent()
63         aSOIter = getStudy().NewChildIterator(aComponent)
64         while aSOIter.More():
65           aSO = aSOIter.Value()
66           anIOR = aSO.GetIOR()
67           anObj = salome.orb.string_to_object(anIOR)
68           if isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
69             if anObj.GetEntry() == theInternalEntry:
70               return anObj
71           aSOIter.Next()
72
73         aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
74         aShapeObj.SetEntry(theInternalEntry)
75         return aShapeObj._this()
76
77     def AddInStudy( self, theObject, theName, theFather ):
78         """
79         Adds in theStudy a object theObject under theFather with a name theName,
80         if theFather is not NULL the object is placed under theFather's SObject.
81         Returns a SObject where theObject is placed
82         """
83         aStudy = getStudy()
84         aBuilder = aStudy.NewBuilder()
85         if not theFather:
86           theFather = findOrCreateComponent()
87         aResultSO = aBuilder.NewObject(theFather);
88         aResultSO.SetAttrString("AttributeName", theName)
89         if theObject:
90           anIOR = salome.orb.object_to_string(theObject)
91           aResultSO.SetAttrString("AttributeIOR", anIOR)
92           theObject.SetSO(aResultSO)
93         # add a red-reference that means that this is an active reference to SHAPER result
94         aSub = aBuilder.NewObject(aResultSO)
95         aBuilder.Addreference(aSub, aResultSO)
96
97         return aResultSO
98
99     def AddSubShape( theMainShape, theIndices ):
100         """
101         Add a sub-shape defined by indices in theIndices
102         (contains unique IDs of sub-shapes inside theMainShape)
103         """
104         go = SHAPERSTUDY_Object()._this()
105         return go
106
107     def RemoveObject( self, theObject ):
108         """
109         Removes the object from the component
110         """
111         return
112
113     def GetIFieldOperations( self ):
114         """
115         """
116         return SHAPERSTUDY_IFieldOperations()
117
118     def GetIGroupOperations( self ):
119         """
120         """
121         return SHAPERSTUDY_IGroupOperations()
122
123     def GetIShapesOperations( self ):
124         """
125         """
126         return SHAPERSTUDY_IShapesOperations()
127
128     def GetIMeasureOperations( self ):
129         """
130         """
131         return SHAPERSTUDY_IMeasureOperations()
132
133     def GetStringFromIOR( self, theObject ):
134         """
135         Returns a string which contains an IOR of the SHAPERSTUDY_Object
136         """
137         IOR = ""
138         if theObject and getORB():
139             IOR = getORB().object_to_string( theObject )
140             pass
141         return IOR
142
143     def GetAllDumpNames( self ):
144         """
145         Returns all names with which Object's was dumped
146         into python script to avoid the same names in SMESH script
147         """
148         return [""]
149
150     def GetDumpName( self, theStudyEntry ):
151         """
152         Returns a name with which a GEOM_Object was dumped into python script
153
154         Parameters:
155             theStudyEntry is an entry of the Object in the study
156         """
157         print("My Test")
158         return "test"
159
160
161     def Save( self, component, URL, isMultiFile ):
162         """
163         Saves data.
164         Nothing to do here because in our case all data
165         are stored in the SALOMEDS attributes.
166         """
167         return ""
168
169     def Load( self, component, stream, URL, isMultiFile ):
170         """
171         Loads data
172         """
173         global __entry2IOR__
174         __entry2IOR__.clear()
175         #
176         return 1
177         
178     def IORToLocalPersistentID(self, sobject, IOR, isMultiFile, isASCII):
179         """
180         Gets persistent ID for the CORBA object.
181         It's enough to use study entry.
182         """
183         return sobject.GetID()
184
185     def LocalPersistentIDToIOR(self, sobject, persistentID, isMultiFile, isASCII):
186         "Converts persistent ID of the object to its IOR."
187         global __entry2IOR__
188         if persistentID in __entry2IOR__:
189             return __entry2IOR__[persistentID]
190         return ""
191
192     def DumpPython( self, isPublished, isMultiFile ):
193         """
194         Dump module data to the Python script.
195         """
196         return ("".encode(), 1)
197
198
199
200     def CreateGroup( self, theMainShape, theShapeType ):
201         """
202         Creates a new group which will store sub-shapes of theMainShape
203         """
204         return GetIGroupOperations().CreateGroup( theMainShape, theShapeType );
205
206     def ExtractShapes( self, aShape, aType, isSorted = False ):
207         """
208         Extract shapes (excluding the main shape) of given type.
209
210         Parameters:
211             aShape The shape.
212             aType  The shape type (see geompy.ShapeType)
213             isSorted Boolean flag to switch sorting on/off.
214
215         Returns:
216             List of sub-shapes of type aType, contained in aShape.
217         """
218         return [ SHAPERSTUDY_Object()._this() ]
219
220     def GetSubShape( self, aShape, ListOfID ):
221         """
222         Obtain a composite sub-shape of aShape, composed from sub-shapes
223         of aShape, selected by their unique IDs inside aShape
224
225         Parameters:
226             aShape Shape to get sub-shape of.
227             ListOfID List of sub-shapes indices.
228         """
229         return SHAPERSTUDY_Object()._this()
230
231     def GetSubShapeID( self, aShape, aSubShape ):
232         """
233         Obtain unique ID of sub-shape aSubShape inside aShape
234         of aShape, selected by their unique IDs inside aShape
235
236         Parameters:
237            aShape Shape to get sub-shape of.
238            aSubShape Sub-shapes of aShape.
239         """
240         return 1
241
242     def MinDistance( self, theShape1, theShape2 ):
243         """
244         Get minimal distance between the given shapes.
245         """
246         return 0.
247
248     def NumberOfEdges( self, theShape ):
249         """
250         Gives quantity of edges in the given shape.
251         """
252         return 0
253
254     def NumberOfFaces( self,  ):
255         """
256         Gives quantity of faces in the given shape.
257         """
258         return 0
259
260     def PointCoordinates( self, theVertex ):
261         """
262         Get point coordinates
263         """
264         return 0,0,0
265
266     def SubShapeAll( self, aShape, aType ):
267         """
268         Explode a shape on sub-shapes of a given type.
269         If the shape itself matches the type, it is also returned.
270         """
271         return [ SHAPERSTUDY_Object()._this() ]
272
273     def SubShapeName( self, aSubObj, aMainObj ):
274         """
275         Get name for sub-shape aSubObj of shape aMainObj
276         """
277         return ""
278
279     def SubShapes( self, aShape, anIDs ):
280         """
281         Get a set of sub-shapes defined by their unique IDs inside theMainShape
282         """
283         return  [ SHAPERSTUDY_Object()._this() ]
284
285     def Tolerance( self, theShape ):
286         """
287         Get min and max tolerances of sub-shapes of theShape
288
289         Returns:
290             [FaceMin,FaceMax, EdgeMin,EdgeMax, VertMin,VertMax]
291         """
292         return [0,0, 0,0, 0,0]
293
294     def UnionList( self, theGroup, theSubShapes ):
295         """
296         Adds to the group all the given shapes. No errors, if some shapes are already included.
297         """
298         return GetIGroupOperations().UnionList( theGroup, theSubShapes )