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 Constructs 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 # 15.01.20 groups and fields names stays the same
270 #aDeadGroupSO.SetAttrString("AttributeName", aGroupSO.GetName() + " (" + str(anIndex) + ")")
271 aDeadGroupObj = aDeadGroup._this()
272 anIOR = salome.orb.object_to_string(aDeadGroupObj)
273 aDeadGroupSO.SetAttrString("AttributeIOR", anIOR)
278 def SetShapeByPointer(self, theShape):
280 Sets the shape by the pointer to the TopoDS_Shape
283 self.data = StudyData_Swig.StudyData_Object()
284 self.data.SetShapeByPointer(theShape)
288 class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
290 Constructs an instance of SHAPERSTUDY Group
292 def __init__ ( self, *args):
298 self.type = 37 # a group type
301 def SetSelectionType(self, theType):
303 Sets what is returned in the GEOM_IGroupOperations::GetType
305 self.seltype = theType
307 def GetSelectionType(self):
309 Returns the type of the selected sub-shapes
313 def SetSelection(self, theSelection):
315 Sets what is returned in the GEOM_IGroupOperations::GetObjects
317 self.data = None # nullify the cashed shape when selection is changed
318 self.selection = theSelection
320 def GetSelection(self):
322 Returns the selected sub-shapes indices
324 return self.selection
326 def GetMainShape( self ):
328 Main shape is groups owner
330 return self.SO.GetFather().GetObject()
332 def getShape( self ):
334 Redefinition of the getShape method: here it creates a shape by the
335 main shape and the group index.
338 self.data = StudyData_Swig.StudyData_Object()
339 # convert selection to long list
340 anArg = StudyData_Swig.LongList()
341 for l in self.selection:
343 return self.data.groupShape(self.GetMainShape().getShape(), anArg)
347 class SHAPERSTUDY_Field(SHAPERSTUDY_ORB__POA.SHAPER_Field, SHAPERSTUDY_Group):
349 Constructs an instance of SHAPERSTUDY Field (inherits selection from a Group object)
351 def __init__ ( self, *args):
357 self.type = 52 # a field type
358 self.valtype = None # type of the values
359 self.steps = [] # list of long
360 self.components = [] # string array, names of the components
361 self.name = None # name, string
362 self.fieldsteps = {} # FieldSteps objects identified by step ID
365 def SetValuesType( self, theType ):
367 Sets the type of values in the field
369 self.valtype = theType
371 def GetDataType( self ):
373 Returns the type of values in the field in terms of GEOM enumeration
375 if self.valtype == 0:
377 elif self.valtype == 1:
379 elif self.valtype == 2:
380 return GEOM.FDT_Double
381 elif self.valtype == 3:
382 return GEOM.FDT_String
383 return None # unknown case
385 def GetShape ( self ):
387 Returns the shape the field lies on
389 return super().GetMainShape()
391 def SetSteps( self, theSteps ):
392 self.steps = theSteps
394 def GetSteps( self ):
397 def SetComponents( self, theComponents ):
398 self.components = theComponents
400 def GetComponents( self ):
401 return self.components
403 def GetDimension( self ):
404 aShapeType = super().GetSelectionType()
406 return -1 # whole part
407 elif aShapeType == 7:
409 elif aShapeType == 6:
411 elif aShapeType == 4:
413 elif aShapeType == 2:
415 return None # unknown case
417 def ClearFieldSteps( self ):
420 def AddFieldStep( self, theStampID, theStepID, theValues):
422 if self.valtype == 0:
423 aFieldStep = SHAPER_BoolFieldStep()
424 elif self.valtype == 1:
425 aFieldStep = SHAPER_IntFieldStep()
426 elif self.valtype == 2:
427 aFieldStep = SHAPER_DoubleFieldStep()
429 aFieldStep.SetStep(theStampID, theStepID, theValues)
430 self.fieldsteps[theStepID] = aFieldStep._this()
432 def GetStep( self, theStepID ):
433 return self.fieldsteps[theStepID]
437 class SHAPER_FieldStep:
439 Base class for all step-classes
441 def __init__ ( self, *args):
442 self.stamp = None # long, ID of stamp
443 self.step = None # long, ID of step
444 self.values = None # array of values of the needed type
447 Defines all parameters of the step
449 def SetStep( self, theStamp, theStep, theValues ):
450 self.stamp = theStamp
452 self.values = theValues
457 def GetStamp( self ):
465 Returns a name of a sub-shape if the sub-shape is published in the study
467 def GetSubShape(self, theSubID):
468 # the SHAPER study does not support sub-shapes for now
472 class SHAPER_DoubleFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_DoubleFieldStep, SHAPER_FieldStep):
474 Constructs an instance of SHAPERSTUDY Field step of type Double
476 def __init__ ( self, *args):
480 Returns values as an array of the needed type
482 def GetValues( self ):
483 aResult = [] # to make any type of result, create a corba-type
484 for i in self.values:
485 aResult.append(float(i))
490 class SHAPER_IntFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_IntFieldStep, SHAPER_FieldStep):
492 Constructs an instance of SHAPERSTUDY Field step of type Double
494 def __init__ ( self, *args):
498 Returns values as an array of the needed type
500 def GetValues( self ):
501 aResult = [] # to make any type of result, create a corba-type
502 for i in self.values:
503 aResult.append(int(i))
508 class SHAPER_BoolFieldStep(SHAPERSTUDY_ORB__POA.SHAPER_BoolFieldStep, SHAPER_FieldStep):
510 Constructs an instance of SHAPERSTUDY Field step of type Double
512 def __init__ ( self, *args):
516 Returns values as an array of the needed type
518 def GetValues( self ):
519 aResult = [] # to make any type of result, create a corba-type
520 for i in self.values:
521 aResult.append(int(i))