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