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 SetTick( self, theValue ):
198 Sets value of a modification counter of the object
201 return self.data.setTick(theValue)
204 def GetStudyEntry( self ):
206 Get a Study entry where this object was published.
209 return self.SO.GetID()
214 Return true if geom object represents a shape.
215 For example, method return false for GEOM_MARKER
219 def IsSame( self, other ):
221 Return true if passed object is identical to this object
223 return self.GetType() == other.GetType() and self.GetEntry() == other.GetEntry()
227 Return the engine creating this object
230 return e._duplicate( e )
232 def SetSO( self, theSO ):
234 Sets SObject of this object (when it is published)
237 theSO.Register() # I hold a GenericObject!
244 Returns SObject of this object
248 def IsParametrical(self):
250 Returns true if the current object has connection to a parametrical model
251 which can be modified by parameters change.
253 return not self.IsDead() and self.type == 1 # only break link for shapes are accessible now
257 Returns true if the shape is dead - no parametrical link to the SHAPER exists
259 return self.GetEntry().startswith("dead")
263 Makes the dead-copy of the shape and returns it.
266 aBuilder = aStudy.NewBuilder()
267 aRes, aHistSO = self.SO.FindSubObject(10000)
268 if not aRes: # create a "history" folder if it does not exist
269 aHistSO = aBuilder.NewObjectToTag(self.SO, 10000)
270 aHistSO.SetAttrString("AttributeName", "History")
272 aDeadSO = aBuilder.NewObject(aHistSO)
273 anIndex = aDeadSO.Tag()
274 aDeadSO.SetAttrString("AttributeName", self.SO.GetName() + " (" + str(anIndex) + ")")
275 aRes, aPixMap = aBuilder.FindAttribute(self.SO, "AttributePixMap")
277 aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadSO, "AttributePixMap")
278 aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
279 aDead = SHAPERSTUDY_Object()
280 aDeadEntry = "dead" + str(anIndex) + "_" + self.GetEntry()
281 aDead.SetEntry(aDeadEntry)
282 aDead.SetShapeByStream(self.data.oldShapeStream())
283 aDeadObj = aDead._this()
284 anIOR = salome.orb.object_to_string(aDeadObj)
285 aDeadSO.SetAttrString("AttributeIOR", anIOR)
287 if self.GetTick() > 2:
288 aDead.data.setTick(self.GetTick() - 1) # set the tick of an old shape
289 # make dead-copy also sub-groups
290 aSOIter = aStudy.NewChildIterator(self.SO)
291 while aSOIter.More():
292 aGroupSO = aSOIter.Value()
293 anIOR = aGroupSO.GetIOR()
295 aGroup = salome.orb.string_to_object(anIOR)
296 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
297 isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
298 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
299 aDeadGroup = SHAPERSTUDY_Group()
301 aDeadGroup = SHAPERSTUDY_Field()
302 aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
303 aDeadGroup.SetEntry(aDeadGroupEntry)
304 aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
305 aDeadGroup.SetSelection(aGroup.GetSelection())
306 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field): # additional field data
307 aDeadGroup.SetValuesType(aGroup.GetValuesType())
308 aDeadGroup.SetSteps(aGroup.GetSteps())
309 aDeadGroup.SetComponents(aGroup.GetComponents())
310 for aStep in aGroup.GetSteps():
311 aStepObj = aGroup.GetStep(aStep)
312 aDeadGroup.AddFieldStep(aStepObj.GetStamp(), aStep, aStepObj.GetValues())
313 aDeadGroupSO = aBuilder.NewObject(aDeadSO)
314 aDeadGroup.SetSO(aDeadGroupSO)
315 # 15.01.20 groups and fields names stays the same
316 #aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
317 aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName())
318 aRes, aPixMap = aBuilder.FindAttribute(aGroupSO, "AttributePixMap")
320 aDeadPixMap = aBuilder.FindOrCreateAttribute(aDeadGroupSO, "AttributePixMap")
321 aDeadPixMap.SetPixMap(aPixMap.GetPixMap())
322 aDeadGroupObj = aDeadGroup._this()
323 anIOR = salome.orb.object_to_string(aDeadGroupObj)
324 aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
329 def SetShapeByPointer(self, theShape):
331 Sets the shape by the pointer to the TopoDS_Shape
334 self.data = StudyData_Swig.StudyData_Object()
335 self.data.SetShapeByPointer(theShape)
339 class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
341 Constructs an instance of SHAPERSTUDY Group
343 def __init__ ( self, *args):
344 SHAPERSTUDY_GenericObject.__init__(self)
350 self.type = 37 # a group type
353 def SetSelectionType(self, theType):
355 Sets what is returned in the GEOM_IGroupOperations::GetType
357 self.seltype = theType
359 def GetSelectionType(self):
361 Returns the type of the selected sub-shapes
365 def SetSelection(self, theSelection):
367 Sets what is returned in the GEOM_IGroupOperations::GetObjects
369 self.data = None # nullify the cashed shape when selection is changed
370 self.selection = theSelection
372 def GetSelection(self):
374 Returns the selected sub-shapes indices
376 return self.selection
378 def IsMainShape( self ):
380 Returns True if this object is not a sub-shape of another object.
384 def GetMainShape( self ):
386 Main shape is groups owner
388 return self.SO.GetFather().GetObject()
390 def GetSubShapeIndices( self ):
392 Get a list of ID's of sub-shapes in the main shape.
394 return self.selection
396 def getShape( self ):
398 Redefinition of the getShape method: here it creates a shape by the
399 main shape and the group index.
402 self.data = StudyData_Swig.StudyData_Object()
403 # convert selection to long list
404 anArg = StudyData_Swig.LongList()
405 for l in self.selection:
407 return self.data.groupShape(self.GetMainShape().getShape(), anArg)
409 def GetShapeType( self ):
411 Group shape type is always compound.
413 return GEOM.COMPOUND;
417 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
419 Constructs an instance of SHAPERSTUDY Field (inherits selection from a Group object)
421 def __init__ ( self, *args):
422 SHAPERSTUDY_GenericObject.__init__(self)
428 self.type = 52 # a field type
429 self.valtype = None # type of the values
430 self.steps = [] # list of long
431 self.components = [] # string array, names of the components
432 self.name = None # name, string
433 self.fieldsteps = {} # FieldSteps objects identified by step ID
436 def SetValuesType( self, theType ):
438 Sets the type of values in the field
440 self.valtype = theType
442 def GetValuesType( self ):
444 Returns the type of values in the field
449 def GetDataType( self ):
451 Returns the type of values in the field in terms of GEOM enumeration
453 if self.valtype == 0:
455 elif self.valtype == 1:
457 elif self.valtype == 2:
458 return GEOM.FDT_Double
459 elif self.valtype == 3:
460 return GEOM.FDT_String
461 return None # unknown case
463 def GetShape ( self ):
465 Returns the shape the field lies on
467 return super().GetMainShape()
469 def SetSteps( self, theSteps ):
470 self.steps = theSteps
472 def GetSteps( self ):
475 def SetComponents( self, theComponents ):
476 self.components = theComponents
478 def GetComponents( self ):
479 return self.components
481 def GetDimension( self ):
482 aShapeType = super().GetSelectionType()
484 return -1 # whole part
485 elif aShapeType == 7:
487 elif aShapeType == 6:
489 elif aShapeType == 4:
491 elif aShapeType == 2:
493 return None # unknown case
495 def ClearFieldSteps( self ):
498 def AddFieldStep( self, theStampID, theStepID, theValues):
500 if self.valtype == 0:
501 aFieldStep = SHAPER_BoolFieldStep()
502 elif self.valtype == 1:
503 aFieldStep = SHAPER_IntFieldStep()
504 elif self.valtype == 2:
505 aFieldStep = SHAPER_DoubleFieldStep()
507 aFieldStep.SetStep(theStampID, theStepID, theValues)
508 self.fieldsteps[theStepID] = aFieldStep._this()
510 def GetStep( self, theStepID ):
511 return self.fieldsteps[theStepID]
515 class SHAPER_FieldStep:
517 Base class for all step-classes
519 def __init__ ( self, *args):
520 self.stamp = None # long, ID of stamp
521 self.step = None # long, ID of step
522 self.values = None # array of values of the needed type
525 Defines all parameters of the step
527 def SetStep( self, theStamp, theStep, theValues ):
528 self.stamp = theStamp
530 self.values = theValues
535 def GetStamp( self ):
543 Returns a name of a sub-shape if the sub-shape is published in the study
545 def GetSubShape(self, theSubID):
546 # the SHAPER study does not support sub-shapes for now
550 class SHAPER_DoubleFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_DoubleFieldStep, SHAPER_FieldStep):
552 Constructs an instance of SHAPERSTUDY Field step of type Double
554 def __init__ ( self, *args):
558 Returns values as an array of the needed type
560 def GetValues( self ):
561 aResult = [] # to make any type of result, create a corba-type
562 for i in self.values:
563 aResult.append(float(i))
568 class SHAPER_IntFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_IntFieldStep, SHAPER_FieldStep):
570 Constructs an instance of SHAPERSTUDY Field step of type Double
572 def __init__ ( self, *args):
576 Returns values as an array of the needed type
578 def GetValues( self ):
579 aResult = [] # to make any type of result, create a corba-type
580 for i in self.values:
581 aResult.append(int(i))
586 class SHAPER_BoolFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_BoolFieldStep, SHAPER_FieldStep):
588 Constructs an instance of SHAPERSTUDY Field step of type Double
590 def __init__ ( self, *args):
594 Returns values as an array of the needed type
596 def GetValues( self ):
597 aResult = [] # to make any type of result, create a corba-type
598 for i in self.values:
599 aResult.append(int(i))