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