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}
37 class SHAPERSTUDY_GenericObject:
39 Implement methods of SALOME::GenericObj
44 Increase the reference count (mark as used by another object).
50 Decrease the reference count (release by another object)
56 Obsolete, left for compatibility reasons only. Use UnRegister() instead
63 class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
64 SHAPERSTUDY_GenericObject):
66 Construct an instance of SHAPERSTUDY Object.
68 def __init__ ( self, *args):
72 self.type = 1 # by default it is a shape (Import feature in GEOMImpl_Types.hxx)
75 def GetShapeType( self ):
77 Get a GEOM.shape_type of the object value.
81 global __shape_types__
82 return __shape_types__[self.data.type()];
84 def IsMainShape( self ):
86 Returns True if this object is not a sub-shape of another object.
90 def GetSubShapeIndices( self ):
92 Get a list of ID's of sub-shapes in the main shape.
96 def GetMainShape( self ):
98 Get a main shape object to which this object is a sub-shape.
102 def getShape( self ):
104 Get the TopoDS_Shape, for collocated case only.
105 Called by GEOM_Client to get TopoDS_Shape pointer
107 if self.data is None:
109 return self.data.shape()
111 def GetShapeStream( self ):
113 Get geometric shape of the object as a byte stream in BRep format
115 if self.data is None:
117 return self.data.shapeStream().encode()
119 def GetOldShapeStream( self ):
121 Get geometric shape of the object as a byte stream in BRep format
123 if self.data is None:
125 return self.data.oldShapeStream().encode()
127 def SetShapeByStream(self, theStream):
129 Sets geometric shape content of the object as a byte stream in BRep format
132 self.data.updateShape(theStream)
134 self.data = StudyData_Swig.StudyData_Object(theStream)
137 Methods from BaseObject
141 Get name of the object associated with this object.
143 return self.SO.GetName()
145 def SetEntry( self, theInternalEntry ):
147 Sets internal (unique) entry of the object in the component's data tree.
149 self.entry = theInternalEntry
151 def GetEntry( self ):
153 Get internal (unique) entry of the object in the component's data tree.
159 Get internal type of operation created this object.
160 In SMESH is used to find out if an object is GROUP (type == 37)
164 def SetType( self, theType ):
166 Sets internal type of operation created this object.
167 In SMESH is used to find out if an object is GROUP (type == 37, for shape it is default=1)
173 Get value of a modification counter of the object
176 return self.data.getTick()
179 def GetStudyEntry( self ):
181 Get a Study entry where this object was published.
183 return self.SO.GetID()
187 Return true if geom object represents a shape.
188 For example, method return false for GEOM_MARKER
192 def IsSame( self, other ):
194 Return true if passed object is identical to this object
196 return self.GetType() == other.GetType() and self.GetEntry() == other.GetEntry()
200 Return the engine creating this object
204 def SetSO( self, theSO ):
206 Sets SObject of this object (when it is published)
212 Returns SObject of this object
216 def IsParametrical(self):
218 Returns true if the current object has connection to a parametrical model
219 which can be modified by parameters change.
221 return not self.IsDead() and self.type == 1 # only break link for shapes are accessible now
225 Returns true if the shape is dead - no parametrical link to the SHAPER exists
227 return self.GetEntry().startswith("dead")
231 Makes the dead-copy of the shape and returns it.
234 aBuilder = aStudy.NewBuilder()
235 aRes, aHistSO = self.SO.FindSubObject(2)
236 if not aRes: # create a "history" folder if it does not exist
237 aHistSO = aBuilder.NewObjectToTag(self.SO, 2)
238 aHistSO.SetAttrString("AttributeName", "History")
240 aDeadSO = aBuilder.NewObject(aHistSO)
241 anIndex = aDeadSO.Tag()
242 aDeadSO.SetAttrString("AttributeName", self.SO.GetName() + " (" + str(anIndex) + ")")
243 aDead = SHAPERSTUDY_Object()
244 aDeadEntry = "dead" + str(anIndex) + "_" + self.GetEntry()
245 aDead.SetEntry(aDeadEntry)
246 aDead.SetShapeByStream(self.data.oldShapeStream())
247 aDeadObj = aDead._this()
248 anIOR = salome.orb.object_to_string(aDeadObj)
249 aDeadSO.SetAttrString("AttributeIOR", anIOR)
251 if self.GetTick() > 2:
252 aDead.data.setTick(self.GetTick() - 1) # set the tick of an old shape
253 # make dead-copy also sub-groups
254 aSOIter = aStudy.NewChildIterator(self.SO)
255 while aSOIter.More():
256 aGroupSO = aSOIter.Value()
257 anIOR = aGroupSO.GetIOR()
259 aGroup = salome.orb.string_to_object(anIOR)
260 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
261 aDeadGroup = SHAPERSTUDY_Group()
262 aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
263 aDeadGroup.SetEntry(aDeadGroupEntry)
264 aDeadGroup.SetShapeByPointer(aGroup.getShape())
265 aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
266 aDeadGroup.SetSelection(aGroup.GetSelection())
267 aDeadGroupSO = aBuilder.NewObject(aDeadSO)
268 aDeadGroup.SetSO(aDeadGroupSO)
269 aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
270 aDeadGroupObj = aDeadGroup._this()
271 anIOR = salome.orb.object_to_string(aDeadGroupObj)
272 aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
277 def SetShapeByPointer(self, theShape):
279 Sets the shape by the pointer to the TopoDS_Shape
282 self.data = StudyData_Swig.StudyData_Object()
283 self.data.SetShapeByPointer(theShape)
287 class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
289 Construct an instance of SHAPERSTUDY Group
291 def __init__ ( self, *args):
297 self.type = 37 # a group type
300 def SetSelectionType(self, theType):
302 Sets what is returned in the GEOM_IGroupOperations::GetType
304 self.seltype = theType
306 def GetSelectionType(self):
308 Returns the type of the selected sub-shapes
312 def SetSelection(self, theSelection):
314 Sets what is returned in the GEOM_IGroupOperations::GetObjects
316 self.data = None # nullify the cashed shape when selection is changed
317 self.selection = theSelection
319 def GetSelection(self):
321 Returns the selected sub-shapes indices
323 return self.selection
325 def GetMainShape( self ):
327 Main shape is groups owner
329 return self.SO.GetFather().GetObject()
331 def getShape( self ):
333 Redefinition of the getShape method: here it creates a shape by the
334 main shape and the group index.
337 self.data = StudyData_Swig.StudyData_Object()
338 # convert selection to long list
339 anArg = StudyData_Swig.LongList()
340 for l in self.selection:
342 return self.data.groupShape(self.GetMainShape().getShape(), anArg)
346 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
348 Construct an instance of SHAPERSTUDY Field (inherits selection from a Group object)
350 def __init__ ( self, *args):
356 self.type = 52 # a field type
357 self.valtype = None # type of the values
358 self.steps = [] # list of long
359 self.components = [] # string array, names of the components
360 self.name = None # name, string
363 def SetValuesType( self, theType ):
365 Sets the type of values in the field
367 self.valtype = theType
369 def GetDataType( self ):
371 Returns the type of values in the field in terms of GEOM enumeration
373 if self.valtype == 0:
375 elif self.valtype == 1:
377 elif self.valtype == 2:
378 return GEOM.FDT_Double
379 elif self.valtype == 3:
380 return GEOM.FDT_String
381 return None # unknown case
383 def SetSteps( self, theSteps ):
384 self.steps = theSteps
386 def GetSteps( self ):
389 def SetComponents( self, theComponents ):
390 self.components = theComponents
392 def GetComponents( self ):
393 return self.components
395 def GetDimension( self ):
396 aShapeType = SHAPERSTUDY_Group.GetSelectionType()
398 return -1 # whole part
399 elif aShapeType == 7:
401 elif aShapeType == 6:
403 elif aShapeType == 4:
405 elif aShapeType == 2:
407 return None # unknown case
409 def GetShape( self ):
410 return SHAPERSTUDY_Group.getShape()