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
46 Increase the reference count (mark as used by another object).
48 #print(self.GetEntry())
50 #print("Register() --------- ", id(self), self.cnt)
55 Decrease the reference count (release by another object)
58 #print("UnRegister() --------- ", id(self), self.cnt)
60 from SHAPERSTUDY_utils import getPOA
62 oid=poa.servant_to_id(self)
63 poa.deactivate_object(oid)
64 if hasattr(self,"SetSO"):
65 self.SetSO(None) # release a GenericObject SO
66 #print("UnRegister() --------- OK")
71 Obsolete, left for compatibility reasons only. Use UnRegister() instead
79 class SHAPERSTUDY_Object(SHAPERSTUDY_ORB__POA.SHAPER_Object,
80 SHAPERSTUDY_GenericObject):
82 Constructs an instance of SHAPERSTUDY Object.
84 def __init__ ( self, *args):
85 SHAPERSTUDY_GenericObject.__init__(self)
89 self.type = 1 # by default it is a shape (Import feature in GEOMImpl_Types.hxx)
92 def GetShapeType( self ):
94 Get a GEOM.shape_type of the object value.
98 global __shape_types__
99 return __shape_types__[self.data.type()];
101 def IsMainShape( self ):
103 Returns True if this object is not a sub-shape of another object.
107 def GetSubShapeIndices( self ):
109 Get a list of ID's of sub-shapes in the main shape.
113 def GetMainShape( self ):
115 Get a main shape object to which this object is a sub-shape.
119 def getShape( self ):
121 Get the TopoDS_Shape, for collocated case only.
122 Called by GEOM_Client to get TopoDS_Shape pointer
124 if self.data is None:
126 return self.data.shape()
128 def GetShapeStream( self ):
130 Get geometric shape of the object as a byte stream in BRep format
132 if self.data is None:
134 return self.data.shapeStream().encode()
136 def GetOldShapeStream( self ):
138 Get geometric shape of the object as a byte stream in BRep format
140 if self.data is None:
142 return self.data.oldShapeStream().encode()
144 def SetShapeByStream(self, theStream):
146 Sets geometric shape content of the object as a byte stream in BRep format
149 self.data.updateShape(theStream)
151 self.data = StudyData_Swig.StudyData_Object(theStream)
154 Methods from BaseObject
158 Get name of the object associated with this object.
160 return self.SO.GetName()
162 def SetEntry( self, theInternalEntry ):
164 Sets internal (unique) entry of the object in the component's data tree.
166 self.entry = theInternalEntry
168 def GetEntry( self ):
170 Get internal (unique) entry of the object in the component's data tree.
176 Get internal type of operation created this object.
177 In SMESH is used to find out if an object is GROUP (type == 37)
181 def SetType( self, theType ):
183 Sets internal type of operation created this object.
184 In SMESH is used to find out if an object is GROUP (type == 37, for shape it is default=1)
190 Get value of a modification counter of the object
193 return self.data.getTick()
196 def GetStudyEntry( self ):
198 Get a Study entry where this object was published.
201 return self.SO.GetID()
206 Return true if geom object represents a shape.
207 For example, method return false for GEOM_MARKER
211 def IsSame( self, other ):
213 Return true if passed object is identical to this object
215 return self.GetType() == other.GetType() and self.GetEntry() == other.GetEntry()
219 Return the engine creating this object
222 return e._duplicate( e )
224 def SetSO( self, theSO ):
226 Sets SObject of this object (when it is published)
229 theSO.Register() # I hold a GenericObject!
236 Returns SObject of this object
240 def IsParametrical(self):
242 Returns true if the current object has connection to a parametrical model
243 which can be modified by parameters change.
245 return not self.IsDead() and self.type == 1 # only break link for shapes are accessible now
249 Returns true if the shape is dead - no parametrical link to the SHAPER exists
251 return self.GetEntry().startswith("dead")
255 Makes the dead-copy of the shape and returns it.
258 aBuilder = aStudy.NewBuilder()
259 aRes, aHistSO = self.SO.FindSubObject(2)
260 if not aRes: # create a "history" folder if it does not exist
261 aHistSO = aBuilder.NewObjectToTag(self.SO, 2)
262 aHistSO.SetAttrString("AttributeName", "History")
264 aDeadSO = aBuilder.NewObject(aHistSO)
265 anIndex = aDeadSO.Tag()
266 aDeadSO.SetAttrString("AttributeName", self.SO.GetName() + " (" + str(anIndex) + ")")
267 aRes, aPixMap = aBuilder.FindAttribute(self.SO, "AttributePixMap")
269 aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadSO, "AttributePixMap")
270 aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
271 aDead = SHAPERSTUDY_Object()
272 aDeadEntry = "dead" + str(anIndex) + "_" + self.GetEntry()
273 aDead.SetEntry(aDeadEntry)
274 aDead.SetShapeByStream(self.data.oldShapeStream())
275 aDeadObj = aDead._this()
276 anIOR = salome.orb.object_to_string(aDeadObj)
277 aDeadSO.SetAttrString("AttributeIOR", anIOR)
279 if self.GetTick() > 2:
280 aDead.data.setTick(self.GetTick() - 1) # set the tick of an old shape
281 # make dead-copy also sub-groups
282 aSOIter = aStudy.NewChildIterator(self.SO)
283 while aSOIter.More():
284 aGroupSO = aSOIter.Value()
285 anIOR = aGroupSO.GetIOR()
287 aGroup = salome.orb.string_to_object(anIOR)
288 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
289 isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
290 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
291 aDeadGroup = SHAPERSTUDY_Group()
293 aDeadGroup = SHAPERSTUDY_Field()
294 aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
295 aDeadGroup.SetEntry(aDeadGroupEntry)
296 aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
297 aDeadGroup.SetSelection(aGroup.GetSelection())
298 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field): # additional field data
299 aDeadGroup.SetValuesType(aGroup.GetValuesType())
300 aDeadGroup.SetSteps(aGroup.GetSteps())
301 aDeadGroup.SetComponents(aGroup.GetComponents())
302 for aStep in aGroup.GetSteps():
303 aStepObj = aGroup.GetStep(aStep)
304 aDeadGroup.AddFieldStep(aStepObj.GetStamp(), aStep, aStepObj.GetValues())
305 aDeadGroupSO = aBuilder.NewObject(aDeadSO)
306 aDeadGroup.SetSO(aDeadGroupSO)
307 # 15.01.20 groups and fields names stays the same
308 #aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
309 aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName())
310 aRes, aPixMap = aBuilder.FindAttribute(aGroupSO, "AttributePixMap")
312 aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadGroupSO, "AttributePixMap")
313 aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
314 aDeadGroupObj = aDeadGroup._this()
315 anIOR = salome.orb.object_to_string(aDeadGroupObj)
316 aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
321 def SetShapeByPointer(self, theShape):
323 Sets the shape by the pointer to the TopoDS_Shape
326 self.data = StudyData_Swig.StudyData_Object()
327 self.data.SetShapeByPointer(theShape)
331 class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
333 Constructs an instance of SHAPERSTUDY Group
335 def __init__ ( self, *args):
336 SHAPERSTUDY_GenericObject.__init__(self)
342 self.type = 37 # a group type
345 def SetSelectionType(self, theType):
347 Sets what is returned in the GEOM_IGroupOperations::GetType
349 self.seltype = theType
351 def GetSelectionType(self):
353 Returns the type of the selected sub-shapes
357 def SetSelection(self, theSelection):
359 Sets what is returned in the GEOM_IGroupOperations::GetObjects
361 self.data = None # nullify the cashed shape when selection is changed
362 self.selection = theSelection
364 def GetSelection(self):
366 Returns the selected sub-shapes indices
368 return self.selection
370 def GetMainShape( self ):
372 Main shape is groups owner
374 return self.SO.GetFather().GetObject()
376 def GetSubShapeIndices( self ):
378 Get a list of ID's of sub-shapes in the main shape.
380 return self.selection
382 def getShape( self ):
384 Redefinition of the getShape method: here it creates a shape by the
385 main shape and the group index.
388 self.data = StudyData_Swig.StudyData_Object()
389 # convert selection to long list
390 anArg = StudyData_Swig.LongList()
391 for l in self.selection:
393 return self.data.groupShape(self.GetMainShape().getShape(), anArg)
395 def GetShapeType( self ):
397 Group shape type is always compound.
399 return GEOM.COMPOUND;
403 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
405 Constructs an instance of SHAPERSTUDY Field (inherits selection from a Group object)
407 def __init__ ( self, *args):
408 SHAPERSTUDY_GenericObject.__init__(self)
414 self.type = 52 # a field type
415 self.valtype = None # type of the values
416 self.steps = [] # list of long
417 self.components = [] # string array, names of the components
418 self.name = None # name, string
419 self.fieldsteps = {} # FieldSteps objects identified by step ID
422 def SetValuesType( self, theType ):
424 Sets the type of values in the field
426 self.valtype = theType
428 def GetValuesType( self ):
430 Returns the type of values in the field
435 def GetDataType( self ):
437 Returns the type of values in the field in terms of GEOM enumeration
439 if self.valtype == 0:
441 elif self.valtype == 1:
443 elif self.valtype == 2:
444 return GEOM.FDT_Double
445 elif self.valtype == 3:
446 return GEOM.FDT_String
447 return None # unknown case
449 def GetShape ( self ):
451 Returns the shape the field lies on
453 return super().GetMainShape()
455 def SetSteps( self, theSteps ):
456 self.steps = theSteps
458 def GetSteps( self ):
461 def SetComponents( self, theComponents ):
462 self.components = theComponents
464 def GetComponents( self ):
465 return self.components
467 def GetDimension( self ):
468 aShapeType = super().GetSelectionType()
470 return -1 # whole part
471 elif aShapeType == 7:
473 elif aShapeType == 6:
475 elif aShapeType == 4:
477 elif aShapeType == 2:
479 return None # unknown case
481 def ClearFieldSteps( self ):
484 def AddFieldStep( self, theStampID, theStepID, theValues):
486 if self.valtype == 0:
487 aFieldStep = SHAPER_BoolFieldStep()
488 elif self.valtype == 1:
489 aFieldStep = SHAPER_IntFieldStep()
490 elif self.valtype == 2:
491 aFieldStep = SHAPER_DoubleFieldStep()
493 aFieldStep.SetStep(theStampID, theStepID, theValues)
494 self.fieldsteps[theStepID] = aFieldStep._this()
496 def GetStep( self, theStepID ):
497 return self.fieldsteps[theStepID]
501 class SHAPER_FieldStep:
503 Base class for all step-classes
505 def __init__ ( self, *args):
506 self.stamp = None # long, ID of stamp
507 self.step = None # long, ID of step
508 self.values = None # array of values of the needed type
511 Defines all parameters of the step
513 def SetStep( self, theStamp, theStep, theValues ):
514 self.stamp = theStamp
516 self.values = theValues
521 def GetStamp( self ):
529 Returns a name of a sub-shape if the sub-shape is published in the study
531 def GetSubShape(self, theSubID):
532 # the SHAPER study does not support sub-shapes for now
536 class SHAPER_DoubleFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_DoubleFieldStep, SHAPER_FieldStep):
538 Constructs an instance of SHAPERSTUDY Field step of type Double
540 def __init__ ( self, *args):
544 Returns values as an array of the needed type
546 def GetValues( self ):
547 aResult = [] # to make any type of result, create a corba-type
548 for i in self.values:
549 aResult.append(float(i))
554 class SHAPER_IntFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_IntFieldStep, SHAPER_FieldStep):
556 Constructs an instance of SHAPERSTUDY Field step of type Double
558 def __init__ ( self, *args):
562 Returns values as an array of the needed type
564 def GetValues( self ):
565 aResult = [] # to make any type of result, create a corba-type
566 for i in self.values:
567 aResult.append(int(i))
572 class SHAPER_BoolFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_BoolFieldStep, SHAPER_FieldStep):
574 Constructs an instance of SHAPERSTUDY Field step of type Double
576 def __init__ ( self, *args):
580 Returns values as an array of the needed type
582 def GetValues( self ):
583 aResult = [] # to make any type of result, create a corba-type
584 for i in self.values:
585 aResult.append(int(i))