]> SALOME platform Git repositories - modules/shaper_study.git/blob - src/PY/SHAPERSTUDY_IOperations.py
Salome HOME
75ec4662c011d39762bd8cb6071d061dec071b42
[modules/shaper_study.git] / src / PY / SHAPERSTUDY_IOperations.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 SHAPERSTUDY_Object
26 import GEOM
27 from SHAPERSTUDY_utils import getStudy
28
29 import StudyData_Swig
30
31 class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations,
32                                     SHAPERSTUDY_Object.SHAPERSTUDY_GenericObject):
33     """
34     Construct an instance of SHAPERSTUDY IShapesOperations.
35     """
36     def __init__ ( self, *args):
37         SHAPERSTUDY_Object.SHAPERSTUDY_GenericObject.__init__(self)
38         self.done = False
39         self.myop = StudyData_Swig.StudyData_Operation()
40         pass
41
42     def GetAllSubShapesIDs( self, theShape, theShapeType, isSorted ):
43         """
44         Explode a shape on sub-shapes of a given type.
45
46         Parameters:
47             theShape Shape to be exploded.
48             theShapeType Type of sub-shapes to be retrieved.
49             isSorted If this parameter is TRUE, sub-shapes will be
50             sorted by coordinates of their gravity centers.
51         """
52         aList = self.myop.GetAllSubShapesIDs(theShape.getShape(), theShapeType, isSorted)
53         self.done = not aList.empty()
54         aResult = []
55         for i in aList:
56           aResult.append(i)
57         return aResult
58
59     def GetSharedShapes( self, theShape1, theShape2, theShapeType ):
60         """
61         Get sub-shapes, shared by input shapes.
62
63         Parameters:
64             theShape1 Shape to find sub-shapes in.
65             theShape2 Shape to find shared sub-shapes with.
66             theShapeType Type of sub-shapes to be retrieved.
67         """
68         aList = self.myop.GetSharedShapes(theShape1.getShape(), theShape2.getShape(), theShapeType)
69         self.done = not aList.empty()
70         aResult = []
71         for i in aList:
72           aResult.append(i)
73         return aResult
74
75     def GetSubShapeIndex( self, theMainShape, theSubShape ):
76         """
77         Get global index of theSubShape in theMainShape.
78         """
79         anIndex = self.myop.GetSubShapeIndex(theMainShape.getShape(), theSubShape.getShape())
80         self.done = anIndex != 0
81         return anIndex
82
83     def GetSubShape( self, theMainShape, theID ):
84         """
85         Get a sub-shape defined by its unique ID within theMainShape
86         """
87         aShape = self.myop.GetSubShape(theMainShape.getShape(), theID)
88         self.done = aShape != 0
89         if not self.done:
90           return None
91
92         # create a shape-object that contain the internal shape only
93         aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
94         aShapeObj.SetShapeByPointer(aShape)
95         return aShapeObj._this()
96
97     def GetInPlace( self, theShapeWhere, theShapeWhat ):
98         """
99         Get sub-shape(s) of \a theShapeWhere, which are
100         coincident with \a theShapeWhat or could be a part of it.
101         """
102         # not done
103         return SHAPERSTUDY_Object()._this()
104         
105     def GetInPlaceMap( self, theShapeWhere, theShapeWhat ):
106         """
107         A sort of GetInPlace functionality, returning for each sub-shape ID of
108         \a theShapeWhat a list of corresponding sub-shape IDs of \a theShapeWhere.
109         """
110         # not done
111         return [[]]
112
113     def IsDone( self ):
114         """
115         To know, if the operation was successfully performed
116         """
117         return self.done
118
119     pass
120
121 class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
122     """
123     Construct an instance of SHAPERSTUDY IShapesOperations.
124     """
125     def __init__ ( self, *args):
126         SHAPERSTUDY_IShapesOperations.__init__(self)
127         self.done = False
128         pass
129
130     def CreateGroup( self, theMainShape, theShapeType ):
131         """
132         Creates a new group which will store sub-shapes of theMainShape
133         """
134         if theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2: 
135           print("Error: You could create group of only next type: vertex, edge, face or solid")
136           return None
137
138         aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
139         aGroupPtr = aGroup._this()
140         aGroup.SetSelectionType(theShapeType) # create a new field specific for the group python object
141         self.done = True
142         return aGroupPtr
143
144     def FindGroup(self, theOwner, theEntry):
145         """
146         Searches existing group of theOwner shape by the entry. Returns NULL if can not find.
147         """
148         aStudy = getStudy()
149         anIter = aStudy.NewChildIterator(theOwner.GetSO())
150         while anIter.More():
151           aGroupObj = anIter.Value().GetObject()
152           if aGroupObj:
153             if aGroupObj.GetEntry() == theEntry:
154               self.done = True
155               return aGroupObj
156           anIter.Next()
157         self.done = False
158         return None # not found
159
160     def UnionList( self, theGroup, theSubShapes ):
161         """
162         Adds to the group all the given shapes. No errors, if some shapes are already included.
163
164         Parameters:
165             theGroup is a GEOM group to which the new sub-shapes are added.
166             theSubShapes is a list of sub-shapes to be added.
167         """
168         # Not needed while SHAPER-STUDY has no sub-shapes in the structure, so, 
169         # theSubShapes can not be filled or treated
170         return
171
172     def IsDone( self ):
173         """
174         To know, if the operation was successfully performed
175         """
176         return self.done
177
178     def GetMainShape( self, theGroup ):
179         """
180         Returns a main shape associated with the group
181         """
182         aSO = theGroup.GetSO()
183         aFatherSO = aSO.GetFather()
184         if isinstance( anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object ):
185             return anObj
186         else:
187             return None
188
189     def GetType( self, theGroup ):
190         """
191         Returns a type (int) of sub-objects stored in the group
192         """
193         return theGroup.GetSelectionType()
194
195     def GetObjects( self, theGroup ):
196         """
197         Returns a list of sub-objects ID stored in the group
198         """
199         return theGroup.GetSelection()
200
201     pass
202
203 class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations):
204     """
205     Construct an instance of SHAPERSTUDY IFieldOperations.
206     """
207     def __init__ ( self, *args):
208         SHAPERSTUDY_IShapesOperations.__init__(self)
209         pass
210
211     def CreateFieldByType( self, theMainShape, theShapeType):
212         """
213         Creates a new group which will store sub-shapes of theMainShape
214         """
215         if theShapeType != 8 and theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2: 
216           print("Error: You could create field of only next type: vertex, edge, face or solid, whole part")
217           return None
218
219         aField = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
220         aFieldPtr = aField._this()
221         aField.SetSelectionType(theShapeType) # create a new field specific for the group python object
222         return aFieldPtr
223
224     def FindField(self, theOwner, theEntry):
225         """
226         Searches existing field of theOwner shape by the entry. Returns NULL if can not find.
227         """
228         aStudy = getStudy()
229         anIter = aStudy.NewChildIterator(theOwner.GetSO())
230         while anIter.More():
231           if len(anIter.Value().GetIOR()):
232             aFieldObj = anIter.Value().GetObject()
233             if aFieldObj:
234               if aFieldObj.GetEntry() == theEntry:
235                 return aFieldObj
236           anIter.Next()
237         return None # not found
238
239
240     def GetFields( self, shape ):
241         """
242         Returns all fields on a shape
243         """
244         aResList = []
245         aStudy = getStudy()
246         anIter = aStudy.NewChildIterator(shape.GetSO())
247         while anIter.More():
248           aFieldObj = anIter.Value().GetObject()
249           if aFieldObj and isinstance(aFieldObj, SHAPERSTUDY_ORB._objref_SHAPER_Field):
250             aResList.append(aFieldObj)
251           anIter.Next()
252         return aResList
253
254     pass
255
256
257 class SHAPERSTUDY_IMeasureOperations(SHAPERSTUDY_ORB__POA.IMeasureOperations):
258     """
259     Construct an instance of SHAPERSTUDY IMeasureOperations.
260     """
261     def __init__ ( self, *args):
262         SHAPERSTUDY_IShapesOperations.__init__(self)
263         pass
264
265     def GetVertexByIndex( self, theShape, theIndex, theUseOri ):
266         """
267         Get a vertex sub-shape by index.
268
269         Parameters:
270         theShape Shape to find sub-shape.
271         theIndex Index to find vertex by this index (starting from zero)
272         theUseOri To consider edge/wire orientation or not
273         """
274         return [ SHAPERSTUDY_Field() ]
275
276     pass