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__POA
24 import SHAPERSTUDY_ORB
25 import SALOME_ComponentPy
26 import SALOME_DriverPy
28 from SHAPERSTUDY_utils import findOrCreateComponent, moduleName, getStudy, getORB
30 import SHAPERSTUDY_Object
31 import SHAPERSTUDY_IOperations
37 # for unit tests correct execution
41 __entry2DumpName__ = {}
43 class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen,
44 SALOME_ComponentPy.SALOME_ComponentPy_i,
45 SALOME_DriverPy.SALOME_DriverPy_i):
48 ShapeType = {"AUTO":-1, "COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8, "FLAT":9}
50 ShaperIcons = {GEOM.COMPOUND:"compsolid.png",
51 GEOM.COMPSOLID:"compsolid.png",
52 GEOM.SOLID:"solid.png",
53 GEOM.SHELL:"shell.png",
57 GEOM.VERTEX:"vertex.png",
58 GEOM.SHAPE:"solid.png",
62 def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
64 Construct an instance of SHAPERSTUDY module engine.
65 The class SHAPERSTUDY implements CORBA interface Gen (see SHAPERSTUDY_Gen.idl).
66 It is inherited (via GEOM_Gen) from the classes SALOME_ComponentPy_i (implementation of
67 Engines::EngineComponent CORBA interface - SALOME component) and SALOME_DriverPy_i
68 (implementation of SALOMEDS::Driver CORBA interface - SALOME module's engine).
70 global __entry2IOR__, __entry2DumpName__
72 __entry2DumpName__.clear()
73 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
74 contID, containerName, instanceName, interfaceName, False)
75 SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
77 #self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
81 def FindOrCreateShape( self, theInternalEntry ):
83 Searches existing or creates a new SHAPERSTUDY_Object to interact with SHAPER
85 # Searching in the study tree
86 aComponent = findOrCreateComponent()
87 aSOIter = getStudy().NewChildIterator(aComponent)
92 anObj = salome.orb.string_to_object(anIOR)
93 if anObj and isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
94 if anObj.GetEntry() == theInternalEntry:
98 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
99 aShapeObj.SetEntry(theInternalEntry)
100 return aShapeObj._this()
102 def AddInStudy( self, theObject, theName, theFather ):
104 Adds in theStudy a object theObject under theFather with a name theName,
105 if theFather is not NULL the object is placed under theFather's SObject.
106 Returns a SObject where theObject is placed
108 if not theObject.GetEntry():
109 return None # object not existing in shaper
111 aBuilder = aStudy.NewBuilder()
112 isGroup = theObject.GetType() == 37 or theObject.GetType() == 52
115 return None # Group may be added only under the shape-father
116 theFatherSO = findOrCreateComponent()
118 theFatherSO = theFather.GetSO()
122 anIter = aStudy.NewChildIterator(theFatherSO)
124 if anIter.Value().Tag() == 10000: # skip the history folder
127 aCurrentTag = anIter.Value().Tag() + 1
129 if aTag < aCurrentTag:
131 if aTag == 10000: # to avoid putting the object to the history folder
133 aResultSO = aBuilder.NewObjectToTag(theFatherSO, aTag)
135 aResultSO = aBuilder.NewObject(theFatherSO);
136 aResultSO.SetAttrString("AttributeName", theName)
137 if theObject is not None:
138 anIOR = salome.orb.object_to_string(theObject)
139 aResultSO.SetAttrString("AttributeIOR", anIOR)
140 theObject.SetSO(aResultSO)
142 aAttr = aBuilder.FindOrCreateAttribute(aResultSO, "AttributePixMap")
143 aPixmap = aAttr._narrow(salome.SALOMEDS.AttributePixMap)
146 aType = SHAPERSTUDY_Object.__shape_types__[theObject.GetSelectionType()]
148 aType = theObject.GetShapeType()
149 aPixmap.SetPixMap(self.ShaperIcons[aType])
151 # add a red-reference that means that this is an active reference to SHAPER result
153 aSub = aBuilder.NewObjectToTag(aResultSO, 1)
154 aBuilder.Addreference(aSub, aResultSO)
158 def StoreVariableName(self, theEntry, theVarName):
160 Stores the variable names of the SHAPER dump to python
162 __entry2DumpName__["s" + theEntry] = theVarName
165 def AddSubShape( theMainShape, theIndices ):
167 Add a sub-shape defined by indices in theIndices
168 (contains unique IDs of sub-shapes inside theMainShape)
170 # no sub-shapes for the moment
171 go = SHAPERSTUDY_Object()._this()
174 # For now it is impossible to remove anything from the SHAPER-STUDY
175 def RemoveObject( self, theObject ):
177 Removes the object from the component
179 # can not be removed for the moment
182 def GetIFieldOperations( self ):
185 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IFieldOperations()._this()
187 def GetIGroupOperations( self ):
190 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IGroupOperations()._this()
192 def GetIShapesOperations( self ):
195 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IShapesOperations()._this()
197 def GetIMeasureOperations( self ):
200 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IMeasureOperations()._this()
202 def GetStringFromIOR( self, theObject ):
204 Returns a string which contains an IOR of the SHAPERSTUDY_Object
207 if theObject and getORB():
208 IOR = getORB().object_to_string( theObject )
212 def Save( self, component, URL, isMultiFile ):
214 Saves data: all objects into one file
216 aResult = "" # string-pairs of internal entries and shape streams
218 # get all sub-SObjects with IOR defined
219 anIters = [aStudy.NewChildIterator(findOrCreateComponent())]
222 aLast = anIters[len(anIters) - 1]
228 anIters.append(aStudy.NewChildIterator(aSO))
231 anIters.remove(aLast)
233 for aSO in aSOList: # for each sobject export shapes stream if exists
237 anObj = salome.orb.string_to_object(anIOR)
238 if type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Group:
241 # store internal entry, type and list of indices of the group selection (separated by spaces)
242 aResult += anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
243 aSelList = anObj.GetSelection()
244 aResult += "|" + str(' '.join(str(anI) for anI in aSelList))
245 aSelListOld = anObj.GetSelectionOld()
246 aResult += ";" + str(' '.join(str(anI) for anI in aSelListOld))
247 elif type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Field:
250 # same as for group, but in addition to the second string part - field specifics
251 aResult += anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
252 aResult += " " + str(anObj.GetDataType()) # values type
253 aSteps = anObj.GetSteps()
254 aResult += " " + str(len(aSteps)) # number of steps
255 aComps = anObj.GetComponents()
256 aResult += " " + str(len(aComps)) # number of components
257 for aComp in aComps: # components strings: but before remove spaces and '|'
258 aCoded = aComp.replace(" ", "__space__").replace("|", "__vertical_bar__")
259 aResult += " " + aCoded
260 for aStepNum in range(len(aSteps)):
261 aVals = anObj.GetStep(aStepNum + 1).GetValues()
263 aResult += " " + str(len(aVals)) # first the number of values in the step
264 aResult += " " + str(anObj.GetStep(aStepNum + 1).GetStamp()) # ID of stamp in step
266 aResult += " " + str(aVal) # all values of step
267 aSelList = anObj.GetSelection()
268 aResult += "|" + str(' '.join(str(anI) for anI in aSelList))
269 aSelListOld = anObj.GetSelectionOld()
270 aResult += ";" + str(' '.join(str(anI) for anI in aSelListOld))
271 elif isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
274 # store internal entry + tick, current and old shapes in BRep format
275 aResult += anObj.GetEntry() + " " + str(anObj.GetTick())
276 aResult += "|" + anObj.GetShapeStream().decode()
277 aResult += "|" + anObj.GetOldShapeStream().decode()
279 return aResult.encode()
281 def Load( self, component, stream, URL, isMultiFile ):
286 __entry2IOR__.clear()
287 aList=stream.decode().split('|')
296 aNewShapeStream = aSub
298 else: # create objects by 3 arguments
300 if anId.startswith('group') or (anId.startswith('dead') and anId.count("group") > 0): # group object
301 anObj = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
303 aSel = aSub.split(";")
305 anObj.SetSelection([int(anI) for anI in aSel[1].split(' ')]) # old selection
306 anObj.SetSelection([int(anI) for anI in aSel[0].split(' ')])
307 anObj.SetSelectionType(int(aNewShapeStream))
308 elif anId.startswith('field') or (anId.startswith('dead') and anId.count("field") > 0): # field object
309 anObj = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
311 aSel = aSub.split(";")
313 anObj.SetSelection([int(anI) for anI in aSel[1].split(' ')]) # old selection
314 anObj.SetSelection([int(anI) for anI in aSel[0].split(' ')])
315 aParams = aNewShapeStream.split(" ")
316 anObj.SetSelectionType(int(aParams[0]))
317 aTypeStr = aParams[1]
318 if (aTypeStr == "FDT_Bool"):
319 anObj.SetValuesType(0)
320 elif (aTypeStr == "FDT_Int"):
321 anObj.SetValuesType(1)
322 elif (aTypeStr == "FDT_Double"):
323 anObj.SetValuesType(2)
324 elif (aTypeStr == "FDT_String"):
325 anObj.SetValuesType(3)
327 aNumSteps = int(aParams[2])
328 for aVal in range(aNumSteps):
329 aSteps.append(aVal + 1)
330 anObj.SetSteps(aSteps)
331 aCompNum = int(aParams[3])
333 for aCompNameIndex in range(aCompNum):
334 aCompName = aParams[4 + aCompNameIndex].replace("__space__", " ").replace("__vertical_bar__", "|")
335 aCompNames.append(aCompName)
336 anObj.SetComponents(aCompNames)
337 aNumValsInStep = int(aParams[4 + aCompNum])
338 for aStepNum in range(aNumSteps):
339 aStepStartIndex = 4 + aCompNum + aStepNum * (aNumValsInStep + 1) + 1
340 aStampId = int(aParams[aStepStartIndex])
342 for aValIndex in range(aNumValsInStep):
343 aVals.append(float(aParams[aStepStartIndex + aValIndex + 1]))
344 anObj.AddFieldStep(aStampId, aStepNum + 1, aVals)
345 else: # shape object by BRep in the stream: set old first then new
346 anObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
348 anObj.SetShapeByStream(aSub)
349 anObj.SetShapeByStream(aNewShapeStream)
351 anEntryAndTick = anId.split(" ")
352 anObj.SetEntry(anEntryAndTick[0])
353 if len(anEntryAndTick) > 1:
354 anObj.SetTick(int(anEntryAndTick[1]))
355 anIOR = salome.orb.object_to_string(anObj._this())
356 __entry2IOR__[anEntryAndTick[0]] = anIOR
360 def IORToLocalPersistentID(self, sobject, IOR, isMultiFile, isASCII):
362 Gets persistent ID for the CORBA object.
363 The internal entry of the Object is returned.
365 anObj = salome.orb.string_to_object(IOR)
366 if anObj and (isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object) or \
367 isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Field)):
368 return anObj.GetEntry()
371 def LocalPersistentIDToIOR(self, sobject, persistentID, isMultiFile, isASCII):
372 "Converts persistent ID of the object to its IOR."
374 if persistentID in __entry2IOR__:
375 aRes = __entry2IOR__[persistentID]
376 if len(aRes): # set SO from the study, the sobject param is temporary, don't store it
377 salome.orb.string_to_object(aRes).SetSO(getStudy().FindObjectID(sobject.GetID()))
381 def UniqueDumpName( self, theBaseName, theID ):
383 Returns a unique name from the theBaseName. Keeps theBaseName if it was not used yet.
384 Stores the newly generated name into the global map __entry2DumpName__.
386 global __entry2DumpName__
388 # to avoid spaces and parenthesis in the variable name
389 aBaseName = theBaseName.replace(" ", "_").replace("(", "").replace(")", "")
391 while aName in __entry2DumpName__.values():
392 aName = aBaseName + "_" + str(aPrefix)
393 aPrefix = aPrefix + 1
394 __entry2DumpName__[theID] = aName
397 def GetShaperEntry(self, theShapeObj):
399 Returns string in the python dump that generates the SHAPER entry:
400 it may be just entry string, or call for the SHAPER dump variable.
402 global __entry2DumpName__
403 anEntry = "s" + theShapeObj.GetEntry()
404 if anEntry in __entry2DumpName__:
406 if anEntry.count(":") == 2: # not first result of the feature, set argument as a number
407 anArg = ", " + anEntry[anEntry.rfind(":") + 1:]
408 return "model.featureStringId(" + __entry2DumpName__[anEntry] + anArg + ")"
409 return "\"" + theShapeObj.GetEntry() + "\""
411 def DumpPython( self, isPublished, isMultiFile ):
413 Dump module data to the Python script.
415 global __entry2DumpName__
416 # remove all non-SHAPER entries
418 for anEntry in __entry2DumpName__:
419 if anEntry.startswith("s"):
420 aCopyMap[anEntry] = __entry2DumpName__[anEntry]
421 __entry2DumpName__ = aCopyMap
424 # collect all shape-objects in the SHAPERSTUDY tree
427 aRoots = aStudy.NewChildIterator(findOrCreateComponent())
432 anObj = salome.orb.string_to_object(anIOR)
433 if anObj and type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Object:
434 aShapeObjects.append(anObj)
437 if len(aShapeObjects):
438 script.append("model.publishToShaperStudy()")
439 script.append("import SHAPERSTUDY")
440 for aShapeObj in aShapeObjects:
441 # check this shape also has sub-groups and fields
443 aSOIter = aStudy.NewChildIterator(aShapeObj.GetSO())
444 while aSOIter.More():
445 aGroupSO = aSOIter.Value()
446 anIOR = aGroupSO.GetIOR()
448 aGroup = salome.orb.string_to_object(anIOR)
449 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
450 isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
451 aGroupVarName = self.UniqueDumpName(aGroup.GetName(), aGroupSO.GetID())
452 aGroupVarNames.append(aGroupVarName)
454 aShapeVar = self.UniqueDumpName(aShapeObj.GetName(), aShapeObj.GetSO().GetID())
455 aShapeStr = aShapeVar + ", "
456 for aGName in aGroupVarNames:
457 aShapeStr += aGName + ", "
458 aShapeStr += "= SHAPERSTUDY.shape(" + self.GetShaperEntry(aShapeObj) +")"
459 script.append(aShapeStr)
460 # dump also dead-shapes with groups and fields in the XAO format
461 aRes, aHistSO = aShapeObj.GetSO().FindSubObject(10000) # the History folder
463 aDeads = aStudy.NewChildIterator(aHistSO)
465 aDSO = aDeads.Value()
466 aDIOR = aDSO.GetIOR()
468 aDeadShape = salome.orb.string_to_object(aDIOR)
469 if aDeadShape and type(aDeadShape) == SHAPERSTUDY_ORB._objref_SHAPER_Object:
471 aXAO = StudyData_Swig.StudyData_XAO()
472 aXAO.SetShape(aDeadShape.getShape())
473 anArchiveName = "archive_" + str(anArchiveNum) + ".xao"
474 if len(aStudy.GetDumpPath()):
475 anArchiveName = aStudy.GetDumpPath() + "/" + anArchiveName
477 aDeadVarName = self.UniqueDumpName(aDeadShape.GetName(), aDSO.GetID())
478 aDeadString += aDeadVarName + ", "
479 aDGroupIter = aStudy.NewChildIterator(aDSO)
481 while aDGroupIter.More():
482 aDeadGroup = aDGroupIter.Value().GetObject()
483 if isinstance(aDeadGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
484 aDGroupVarName = self.UniqueDumpName(aDeadGroup.GetName(), aDGroupIter.Value().GetID())
485 aDeadString += aDGroupVarName + ", "
486 aGroupID = aXAO.AddGroup(aDeadGroup.GetSelectionType(), aDGroupVarName)
487 for aSel in aDeadGroup.GetSelection():
488 aXAO.AddGroupSelection(aGroupID, aSel)
489 elif isinstance(aDeadGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
490 aDeadField = aDeadGroup
491 aDFieldVarName = self.UniqueDumpName(aDeadField.GetName(), aDGroupIter.Value().GetID())
492 aDeadString += aDFieldVarName + ", "
493 aComponents = aDeadField.GetComponents()
494 aFieldID = aXAO.AddField(aDeadField.GetValuesType(), aDeadField.GetSelectionType(), \
495 len(aComponents), aDFieldVarName)
496 for aCompIndex in range(len(aComponents)):
497 aXAO.SetFieldComponent(aFieldID, aCompIndex, aComponents[aCompIndex])
498 aSteps = aDeadField.GetSteps()
500 aFieldStep = aDeadField.GetStep(aStep)
501 aXAO.AddStep(aFieldID, aStep, aFieldStep.GetStamp())
502 aStepVals = aFieldStep.GetValues()
503 for aValue in aStepVals:
504 aXAO.AddStepValue(aFieldID, aStep, str(aValue))
506 aXAO.Export(anArchiveName)
507 aDeadString += " = SHAPERSTUDY.archive(" + aShapeVar + ", \"" + anArchiveName + "\")"
508 script.append(aDeadString)
512 script.append("") # to have an end-line in the end
513 result_str = "\n".join(script)
514 encoded_str = result_str.encode() + b'\0' # to avoid garbage symbols in the end
515 return (encoded_str, 1)
517 def GetAllDumpNames( self ):
519 Returns all names with which Object's was dumped
520 into python script to avoid the same names in SMESH script
522 global __entry2DumpName__
524 for anEntry in __entry2DumpName__:
525 aResultList.append(__entry2DumpName__[anEntry])
528 def GetDumpName( self, theStudyEntry ):
530 Returns a name with which a GEOM_Object was dumped into python script
533 theStudyEntry is an entry of the Object in the study
535 global __entry2DumpName__
536 if theStudyEntry in __entry2DumpName__:
537 return __entry2DumpName__[theStudyEntry]
540 def BreakLink(self, theEntry):
542 Breaks links to not-dead shape, make the shape as dead
545 aSO = aStudy.FindObjectID(theEntry)
548 aRes, aSSO = aSO.ReferencedObject()
550 return # only SObjects referenced to the SHAPER STUDY objects are allowed
551 anIOR = aSSO.GetIOR()
553 return # must be referenced to the SHAPER STUDY shape
554 anObj = salome.orb.string_to_object(anIOR)
555 if not anObj or not isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
558 return # do nothing for reference to already dead shape
559 aDeadShape = anObj.MakeDead()
561 aMeshSObject = aSO.GetFather()
562 aMeshObject = aMeshSObject.GetObject()
564 aBuilder = aStudy.NewBuilder()
565 aBuilder.RemoveReference(aSO) # reset reference to the dead shape
566 aBuilder.Addreference(aSO, aDeadShape.GetSO())
568 # check also sub-structure of the mesh to find references to sub-objects that become dead
569 breakLinkForSubElements(aSO, aDeadShape)
571 # Replace shape object in the parent mesh
572 aMeshObject.ReplaceShape(aDeadShape)
576 Searches a shape object by the SHAPER entry. Used in the python dump script
579 aRoots = aStudy.NewChildIterator(findOrCreateComponent())
584 anObj = salome.orb.string_to_object(anIOR)
585 if anObj and type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Object and anObj.GetEntry() == theEntry:
587 # add groups and fields to the result
588 aSOIter = aStudy.NewChildIterator(aSO)
589 while aSOIter.More():
590 aGroupSO = aSOIter.Value()
591 anIOR = aGroupSO.GetIOR()
593 aGroup = salome.orb.string_to_object(anIOR)
594 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
595 isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
596 aRes = aRes + (aGroup,)
600 return None # not found
602 def archive(theShape, theXAOFile):
604 Creates a dead shapes under the theShape and restores these dead objects state basing on theXAOFile
608 # searching for the last dead
609 aDeads = aStudy.NewChildIterator(theShape.GetSO().FindSubObject(10000)[1])
610 aLastDeadSO = aDeads.Value()
612 aLastDeadSO = aDeads.Value()
615 aDShape = aLastDeadSO.GetObject()
617 aXAO = StudyData_Swig.StudyData_XAO()
618 anError = aXAO.Import(theXAOFile)
620 print("Error of XAO file import: " + anError)
622 aDShape.SetShapeByPointer(aXAO.GetShape())
624 # add groups and fields to the result
627 aSOIter = aStudy.NewChildIterator(aLastDeadSO)
628 while aSOIter.More():
629 aGroupSO = aSOIter.Value()
630 anIOR = aGroupSO.GetIOR()
632 aGroup = salome.orb.string_to_object(anIOR)
633 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
635 aGroup.SetSelectionType(aXAO.GetGroupDimension(aGroupIndex))
637 for aSel in aXAO.GetGroupSelection(aGroupIndex):
638 aSelection.append(aSel)
639 aGroup.SetSelection(aSelection)
641 elif isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
644 aValType = aXAO.GetValuesType(aFieldIndex)
645 aField.SetValuesType(aValType)
646 aField.SetSelectionType(aXAO.GetSelectionType(aFieldIndex))
648 for aCompName in aXAO.GetComponents(aFieldIndex):
649 aCompNames.append(aCompName)
650 aField.SetComponents(aCompNames)
651 aField.ClearFieldSteps()
652 aXAO.BeginSteps(aFieldIndex)
653 while aXAO.More(aFieldIndex):
655 for aVal in aXAO.GetValues():
656 if aValType == 0: # boolean
657 aValsList.append(int(aVal))
658 elif aValType == 1: # int
659 aValsList.append(int(aVal))
660 elif aValType == 2: # double
661 aValsList.append(float(aVal))
662 aField.AddFieldStep(aXAO.GetStamp(), aXAO.GetStepIndex(), aValsList)
667 return None # not found
669 def isFather(theFather, theChild):
671 Returns true if theChild SObject is a child of theFather SObject
673 aChild = theChild.GetFather()
674 while aChild.Depth() > theFather.Depth():
675 aChild = aChild.GetFather()
676 return aChild.GetID() == theFather.GetID()
678 def breakLinkForSubElements(theMainShapeSO, theDeadShape):
680 Checks sub-structure of the SMESH-mesh to find references to sub-objects that become dead.
681 theMainShapeSO is SObject with reference to real SHAPERSTUDY shape, located under the Mesh node.
682 theDeadShape is a newly created dead shape instance
685 aBuilder = aStudy.NewBuilder()
686 aRoot = theMainShapeSO.GetFather()
687 anIters = [aStudy.NewChildIterator(aRoot)]
689 anOriginShapeSO = theDeadShape.GetSO().GetFather().GetFather()
691 aLast = anIters[len(anIters) - 1]
694 aRes, aSubRef = aSub.ReferencedObject()
695 if aRes and isFather(anOriginShapeSO, aSubRef):
696 aReferenced = aSubRef.GetObject()
697 if aReferenced and not aReferenced.IsDead():
698 aSubList.append(aSub)
699 anIters.append(aStudy.NewChildIterator(aSub))
702 anIters.remove(aLast)
704 # associate the number of sub-objects of the referenced objects
705 aMapSubEntryToIndex = {}
706 aSSOIter = aStudy.NewChildIterator(anOriginShapeSO)
708 while aSSOIter.More():
709 aSub = aSSOIter.Value()
711 aMapSubEntryToIndex[aSub.GetID()] = anIndex
712 anIndex = anIndex + 1
714 for aSubSO in aSubList:
715 aRes, aSubRef = aSubSO.ReferencedObject()
716 if aRes and aSubRef.GetID() in aMapSubEntryToIndex:
717 anIndex = aMapSubEntryToIndex[aSubRef.GetID()]
718 aDeadIter = aStudy.NewChildIterator(theDeadShape.GetSO())
719 while aDeadIter.More(): # iterate dead subs to find object with the same index
720 aDeadSubSO = aDeadIter.Value()
721 if aDeadSubSO.GetIOR():
722 anIndex = anIndex - 1
724 aBuilder.RemoveReference(aSubSO) # reset reference to the dead shape
725 aBuilder.Addreference(aSubSO, aDeadSubSO)