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
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.
200 return self.SO.GetID()
204 Return true if geom object represents a shape.
205 For example, method return false for GEOM_MARKER
209 def IsSame( self, other ):
211 Return true if passed object is identical to this object
213 return self.GetType() == other.GetType() and self.GetEntry() == other.GetEntry()
217 Return the engine creating this object
220 return e._duplicate( e )
222 def SetSO( self, theSO ):
224 Sets SObject of this object (when it is published)
230 self.SO.Register() # I hold a GenericObject!
234 Returns SObject of this object
238 def IsParametrical(self):
240 Returns true if the current object has connection to a parametrical model
241 which can be modified by parameters change.
243 return not self.IsDead() and self.type == 1 # only break link for shapes are accessible now
247 Returns true if the shape is dead - no parametrical link to the SHAPER exists
249 return self.GetEntry().startswith("dead")
253 Makes the dead-copy of the shape and returns it.
256 aBuilder = aStudy.NewBuilder()
257 aRes, aHistSO = self.SO.FindSubObject(2)
258 if not aRes: # create a "history" folder if it does not exist
259 aHistSO = aBuilder.NewObjectToTag(self.SO, 2)
260 aHistSO.SetAttrString("AttributeName", "History")
262 aDeadSO = aBuilder.NewObject(aHistSO)
263 anIndex = aDeadSO.Tag()
264 aDeadSO.SetAttrString("AttributeName", self.SO.GetName() + " (" + str(anIndex) + ")")
265 aDead = SHAPERSTUDY_Object()
266 aDeadEntry = "dead" + str(anIndex) + "_" + self.GetEntry()
267 aDead.SetEntry(aDeadEntry)
268 aDead.SetShapeByStream(self.data.oldShapeStream())
269 aDeadObj = aDead._this()
270 anIOR = salome.orb.object_to_string(aDeadObj)
271 aDeadSO.SetAttrString("AttributeIOR", anIOR)
273 if self.GetTick() > 2:
274 aDead.data.setTick(self.GetTick() - 1) # set the tick of an old shape
275 # make dead-copy also sub-groups
276 aSOIter = aStudy.NewChildIterator(self.SO)
277 while aSOIter.More():
278 aGroupSO = aSOIter.Value()
279 anIOR = aGroupSO.GetIOR()
281 aGroup = salome.orb.string_to_object(anIOR)
282 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
283 aDeadGroup = SHAPERSTUDY_Group()
284 aDeadGroupEntry = "dead" + str(anIndex) + "_" + aGroup.GetEntry()
285 aDeadGroup.SetEntry(aDeadGroupEntry)
286 aDeadGroup.SetShapeByPointer(aGroup.getShape())
287 aDeadGroup.SetSelectionType(aGroup.GetSelectionType())
288 aDeadGroup.SetSelection(aGroup.GetSelection())
289 aDeadGroupSO = aBuilder.NewObject(aDeadSO)
290 aDeadGroup.SetSO(aDeadGroupSO)
291 # 15.01.20 groups and fields names stays the same
292 #aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
293 aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName())
294 aDeadGroupObj = aDeadGroup._this()
295 anIOR = salome.orb.object_to_string(aDeadGroupObj)
296 aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
301 def SetShapeByPointer(self, theShape):
303 Sets the shape by the pointer to the TopoDS_Shape
306 self.data = StudyData_Swig.StudyData_Object()
307 self.data.SetShapeByPointer(theShape)
311 class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
313 Constructs an instance of SHAPERSTUDY Group
315 def __init__ ( self, *args):
316 SHAPERSTUDY_GenericObject.__init__(self)
322 self.type = 37 # a group type
325 def SetSelectionType(self, theType):
327 Sets what is returned in the GEOM_IGroupOperations::GetType
329 self.seltype = theType
331 def GetSelectionType(self):
333 Returns the type of the selected sub-shapes
337 def SetSelection(self, theSelection):
339 Sets what is returned in the GEOM_IGroupOperations::GetObjects
341 self.data = None # nullify the cashed shape when selection is changed
342 self.selection = theSelection
344 def GetSelection(self):
346 Returns the selected sub-shapes indices
348 return self.selection
350 def GetMainShape( self ):
352 Main shape is groups owner
354 return self.SO.GetFather().GetObject()
356 def GetSubShapeIndices( self ):
358 Get a list of ID's of sub-shapes in the main shape.
360 return self.selection
362 def getShape( self ):
364 Redefinition of the getShape method: here it creates a shape by the
365 main shape and the group index.
368 self.data = StudyData_Swig.StudyData_Object()
369 # convert selection to long list
370 anArg = StudyData_Swig.LongList()
371 for l in self.selection:
373 return self.data.groupShape(self.GetMainShape().getShape(), anArg)
375 def GetShapeType( self ):
377 Group shape type is always compound.
379 return GEOM.COMPOUND;
383 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
385 Constructs an instance of SHAPERSTUDY Field (inherits selection from a Group object)
387 def __init__ ( self, *args):
388 SHAPERSTUDY_GenericObject.__init__(self)
394 self.type = 52 # a field type
395 self.valtype = None # type of the values
396 self.steps = [] # list of long
397 self.components = [] # string array, names of the components
398 self.name = None # name, string
399 self.fieldsteps = {} # FieldSteps objects identified by step ID
402 def SetValuesType( self, theType ):
404 Sets the type of values in the field
406 self.valtype = theType
408 def GetDataType( self ):
410 Returns the type of values in the field in terms of GEOM enumeration
412 if self.valtype == 0:
414 elif self.valtype == 1:
416 elif self.valtype == 2:
417 return GEOM.FDT_Double
418 elif self.valtype == 3:
419 return GEOM.FDT_String
420 return None # unknown case
422 def GetShape ( self ):
424 Returns the shape the field lies on
426 return super().GetMainShape()
428 def SetSteps( self, theSteps ):
429 self.steps = theSteps
431 def GetSteps( self ):
434 def SetComponents( self, theComponents ):
435 self.components = theComponents
437 def GetComponents( self ):
438 return self.components
440 def GetDimension( self ):
441 aShapeType = super().GetSelectionType()
443 return -1 # whole part
444 elif aShapeType == 7:
446 elif aShapeType == 6:
448 elif aShapeType == 4:
450 elif aShapeType == 2:
452 return None # unknown case
454 def ClearFieldSteps( self ):
457 def AddFieldStep( self, theStampID, theStepID, theValues):
459 if self.valtype == 0:
460 aFieldStep = SHAPER_BoolFieldStep()
461 elif self.valtype == 1:
462 aFieldStep = SHAPER_IntFieldStep()
463 elif self.valtype == 2:
464 aFieldStep = SHAPER_DoubleFieldStep()
466 aFieldStep.SetStep(theStampID, theStepID, theValues)
467 self.fieldsteps[theStepID] = aFieldStep._this()
469 def GetStep( self, theStepID ):
470 return self.fieldsteps[theStepID]
474 class SHAPER_FieldStep:
476 Base class for all step-classes
478 def __init__ ( self, *args):
479 self.stamp = None # long, ID of stamp
480 self.step = None # long, ID of step
481 self.values = None # array of values of the needed type
484 Defines all parameters of the step
486 def SetStep( self, theStamp, theStep, theValues ):
487 self.stamp = theStamp
489 self.values = theValues
494 def GetStamp( self ):
502 Returns a name of a sub-shape if the sub-shape is published in the study
504 def GetSubShape(self, theSubID):
505 # the SHAPER study does not support sub-shapes for now
509 class SHAPER_DoubleFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_DoubleFieldStep, SHAPER_FieldStep):
511 Constructs an instance of SHAPERSTUDY Field step of type Double
513 def __init__ ( self, *args):
517 Returns values as an array of the needed type
519 def GetValues( self ):
520 aResult = [] # to make any type of result, create a corba-type
521 for i in self.values:
522 aResult.append(float(i))
527 class SHAPER_IntFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_IntFieldStep, SHAPER_FieldStep):
529 Constructs an instance of SHAPERSTUDY Field step of type Double
531 def __init__ ( self, *args):
535 Returns values as an array of the needed type
537 def GetValues( self ):
538 aResult = [] # to make any type of result, create a corba-type
539 for i in self.values:
540 aResult.append(int(i))
545 class SHAPER_BoolFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_BoolFieldStep, SHAPER_FieldStep):
547 Constructs an instance of SHAPERSTUDY Field step of type Double
549 def __init__ ( self, *args):
553 Returns values as an array of the needed type
555 def GetValues( self ):
556 aResult = [] # to make any type of result, create a corba-type
557 for i in self.values:
558 aResult.append(int(i))