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
24 import SHAPERSTUDY_ORB__POA
26 from SHAPERSTUDY_utils import getEngine, getStudy
31 # converter from the integer values to idl shape_type enumerations
33 0:GEOM.COMPOUND, 1:GEOM.COMPSOLID, 2:GEOM.SOLID,
34 3:GEOM.SHELL, 4:GEOM.FACE, 5:GEOM.WIRE,
35 6:GEOM.EDGE, 7:GEOM.VERTEX, 8:GEOM.SHAPE, 9:GEOM.FLAT}
38 class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object):
40 Construct an instance of SHAPERSTUDY Object.
42 def __init__ ( self, *args):
46 self.type = 1 # by default it is a shape (Import feature in GEOMImpl_Types.hxx)
49 def GetShapeType( self ):
51 Get a GEOM.shape_type of the object value.
55 global __shape_types__
56 return __shape_types__[self.data.type()];
58 def IsMainShape( self ):
60 Returns True if this object is not a sub-shape of another object.
64 def GetSubShapeIndices( self ):
66 Get a list of ID's of sub-shapes in the main shape.
70 def GetMainShape( self ):
72 Get a main shape object to which this object is a sub-shape.
78 Get the TopoDS_Shape, for collocated case only.
79 Called by GEOM_Client to get TopoDS_Shape pointer
83 return self.data.shape()
85 def GetShapeStream( self ):
87 Get geometric shape of the object as a byte stream in BRep format
91 return self.data.shapeStream().encode()
93 def GetOldShapeStream( self ):
95 Get geometric shape of the object as a byte stream in BRep format
99 return self.data.oldShapeStream().encode()
101 def SetShapeByStream(self, theStream):
103 Sets geometric shape content of the object as a byte stream in BRep format
106 self.data.updateShape(theStream)
108 self.data = StudyData_Swig.StudyData_Object(theStream)
111 Methods from BaseObject
115 Get name of the object associated with this object.
117 return self.SO.GetName()
119 def SetEntry( self, theInternalEntry ):
121 Sets internal (unique) entry of the object in the component's data tree.
123 self.entry = theInternalEntry
125 def GetEntry( self ):
127 Get internal (unique) entry of the object in the component's data tree.
133 Get internal type of operation created this object.
134 In SMESH is used to find out if an object is GROUP (type == 37)
138 def SetType( self, theType ):
140 Sets internal type of operation created this object.
141 In SMESH is used to find out if an object is GROUP (type == 37, for shape it is default=1)
147 Get value of a modification counter of the object
150 return self.data.getTick()
153 def GetStudyEntry( self ):
155 Get a Study entry where this object was published.
157 return self.SO.GetID()
161 Return true if geom object represents a shape.
162 For example, method return false for GEOM_MARKER
166 def IsSame( self, other ):
168 Return true if passed object is identical to this object
170 return self.GetType() == other.GetType() and self.GetEntry() == other.GetEntry()
174 Return the engine creating this object
178 def SetSO( self, theSO ):
180 Sets SObject of this object (when it is published)
186 Returns SObject of this object
190 def IsParametrical(self):
192 Returns true if the current object has connection to a parametrical model
193 which can be modified by parameters change.
195 return not self.IsDead() and self.type == 1 # only break link for shapes are accessible now
199 Returns true if the shape is dead - no parametrical link to the SHAPER exists
201 return self.GetEntry().startswith("dead")
205 Makes the dead-copy of the shape and returns it.
208 aBuilder = aStudy.NewBuilder()
209 aRes, aHistSO = self.SO.FindSubObject(2)
210 if not aRes: # create a "history" folder if it does not exist
211 aHistSO = aBuilder.NewObjectToTag(self.SO, 2)
212 aHistSO.SetAttrString("AttributeName", "History")
214 aDeadSO = aBuilder.NewObject(aHistSO)
215 anIndex = aDeadSO.Tag()
216 aDeadSO.SetAttrString("AttributeName", self.SO.GetName() + " (" + str(anIndex) + ")")
217 aDead = SHAPERSTUDY_Object()
218 aDeadEntry = "dead" + str(anIndex) + "_" + self.GetEntry()
219 aDead.SetEntry(aDeadEntry)
220 aDead.SetShapeByStream(self.data.oldShapeStream())
221 aDeadObj = aDead._this()
222 anIOR = salome.orb.object_to_string(aDeadObj)
223 aDeadSO.SetAttrString("AttributeIOR", anIOR)
225 if self.GetTick() > 2:
226 aDead.data.setTick(self.GetTick() - 1) # set the tick of an old shape
227 # make dead-copy also sub-groups
228 aSOIter = aStudy.NewChildIterator(self.SO)
229 while aSOIter.More():
230 aGroupSO = aSOIter.Value()
231 anIOR = aGroupSO.GetIOR()
233 aGroup = salome.orb.string_to_object(anIOR)
234 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
235 aDeadGroup = SHAPERSTUDY_Group()
236 aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
237 aDeadGroup.SetEntry(aDeadGroupEntry)
238 aDeadGroup.SetShapeByPointer(aGroup.getShape())
239 aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
240 aDeadGroup.SetSelection(aGroup.GetSelection())
241 aDeadGroupSO = aBuilder.NewObject(aDeadSO)
242 aDeadGroup.SetSO(aDeadGroupSO)
243 aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
244 aDeadGroupObj = aDeadGroup._this()
245 anIOR = salome.orb.object_to_string(aDeadGroupObj)
246 aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
251 def SetShapeByPointer(self, theShape):
253 Sets the shape by the pointer to the TopoDS_Shape
256 self.data = StudyData_Swig.StudyData_Object()
257 self.data.SetShapeByPointer(theShape)
261 class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
263 Construct an instance of SHAPERSTUDY Group
265 def __init__ ( self, *args):
271 self.type = 37 # a group type
274 def SetSelectionType(self, theType):
276 Sets what is returned in the GEOM_IGroupOperations::GetType
278 self.seltype = theType
280 def GetSelectionType(self):
282 Returns the type of the selected sub-shapes
286 def SetSelection(self, theSelection):
288 Sets what is returned in the GEOM_IGroupOperations::GetObjects
290 self.data = None # nullify the cashed shape when selection is changed
291 self.selection = theSelection
293 def GetSelection(self):
295 Returns the selected sub-shapes indices
297 return self.selection
299 def GetMainShape( self ):
301 Main shape is groups owner
303 return self.SO.GetFather().GetObject()
305 def getShape( self ):
307 Redefinition of the getShape method: here it creates a shape by the
308 main shape and the group index.
311 self.data = StudyData_Swig.StudyData_Object()
312 # convert selection to long list
313 anArg = StudyData_Swig.LongList()
314 for l in self.selection:
316 return self.data.groupShape(self.GetMainShape().getShape(), anArg)
320 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
322 Construct an instance of SHAPERSTUDY Field (inherits selection from a Group object)
324 def __init__ ( self, *args):
330 self.type = 52 # a field type
331 self.valtype = None # type of the values
332 self.steps = [] # list of long
333 self.components = [] # string array, names of the components
334 self.name = None # name, string
337 def SetValuesType( self, theType ):
339 Sets the type of values in the field
341 self.valtype = theType
343 def GetDataType( self ):
345 Returns the type of values in the field in terms of GEOM enumeration
347 if self.valtype == 0:
349 elif self.valtype == 1:
351 elif self.valtype == 2:
352 return GEOM.FDT_Double
353 elif self.valtype == 3:
354 return GEOM.FDT_String
355 return None # unknown case
357 def SetSteps( self, theSteps ):
358 self.steps = theSteps
360 def GetSteps( self ):
363 def SetComponents( self, theComponents ):
364 self.components = theComponents
366 def GetComponents( self ):
367 return self.components
369 def GetDimension( self ):
370 aShapeType = SHAPERSTUDY_Group.GetSelectionType()
372 return -1 # whole part
373 elif aShapeType == 7:
375 elif aShapeType == 6:
377 elif aShapeType == 4:
379 elif aShapeType == 2:
381 return None # unknown case
383 def GetShape( self ):
384 return SHAPERSTUDY_Group.getShape()