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:"SHAPER_ICON_COMPSOLID",
51 GEOM.COMPSOLID:"SHAPER_ICON_COMPSOLID",
52 GEOM.SOLID:"SHAPER_ICON_SOLID",
53 GEOM.SHELL:"SHAPER_ICON_SHELL",
54 GEOM.FACE:"SHAPER_ICON_FACE",
55 GEOM.WIRE:"SHAPER_ICON_WIRE",
56 GEOM.EDGE:"SHAPER_ICON_EDGE",
57 GEOM.VERTEX:"SHAPER_ICON_VERTEX",
58 GEOM.SHAPE:"SHAPER_ICON_SOLID",
59 GEOM.FLAT:"SHAPER_ICON_FACE"
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)
91 anObj = salome.orb.string_to_object(anIOR)
92 if isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
93 if anObj.GetEntry() == theInternalEntry:
97 aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
98 aShapeObj.SetEntry(theInternalEntry)
99 return aShapeObj._this()
101 def AddInStudy( self, theObject, theName, theFather ):
103 Adds in theStudy a object theObject under theFather with a name theName,
104 if theFather is not NULL the object is placed under theFather's SObject.
105 Returns a SObject where theObject is placed
107 if not theObject.GetEntry():
108 return None # object not existing in shaper
110 aBuilder = aStudy.NewBuilder()
111 isGroup = theObject.GetType() == 37 or theObject.GetType() == 52
114 return None # Group may be added only under the shape-father
115 theFatherSO = findOrCreateComponent()
117 theFatherSO = theFather.GetSO()
121 anIter = aStudy.NewChildIterator(theFatherSO)
123 if anIter.Value().Tag() == 10000: # skip the history folder
125 aCurrentTag = anIter.Value().Tag() + 1
126 if aTag < aCurrentTag:
129 if aTag == 10000: # to avoid putting the object to the history folder
131 aResultSO = aBuilder.NewObjectToTag(theFatherSO, aTag)
133 aResultSO = aBuilder.NewObject(theFatherSO);
134 aResultSO.SetAttrString("AttributeName", theName)
135 if theObject is not None:
136 anIOR = salome.orb.object_to_string(theObject)
137 aResultSO.SetAttrString("AttributeIOR", anIOR)
138 theObject.SetSO(aResultSO)
140 aAttr = aBuilder.FindOrCreateAttribute(aResultSO, "AttributePixMap")
141 aPixmap = aAttr._narrow(salome.SALOMEDS.AttributePixMap)
144 aType = SHAPERSTUDY_Object.__shape_types__[theObject.GetSelectionType()]
146 aType = theObject.GetShapeType()
147 aPixmap.SetPixMap(self.ShaperIcons[aType])
149 # add a red-reference that means that this is an active reference to SHAPER result
151 aSub = aBuilder.NewObjectToTag(aResultSO, 1)
152 aBuilder.Addreference(aSub, aResultSO)
156 def StoreVariableName(self, theEntry, theVarName):
158 Stores the variable names of the SHAPER dump to python
160 __entry2DumpName__["s" + theEntry] = theVarName
163 def AddSubShape( theMainShape, theIndices ):
165 Add a sub-shape defined by indices in theIndices
166 (contains unique IDs of sub-shapes inside theMainShape)
168 # no sub-shapes for the moment
169 go = SHAPERSTUDY_Object()._this()
172 # For now it is impossible to remove anything from the SHAPER-STUDY
173 def RemoveObject( self, theObject ):
175 Removes the object from the component
177 # can not be removed for the moment
180 def GetIFieldOperations( self ):
183 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IFieldOperations()._this()
185 def GetIGroupOperations( self ):
188 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IGroupOperations()._this()
190 def GetIShapesOperations( self ):
193 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IShapesOperations()._this()
195 def GetIMeasureOperations( self ):
198 return SHAPERSTUDY_IOperations.SHAPERSTUDY_IMeasureOperations()._this()
200 def GetStringFromIOR( self, theObject ):
202 Returns a string which contains an IOR of the SHAPERSTUDY_Object
205 if theObject and getORB():
206 IOR = getORB().object_to_string( theObject )
210 def Save( self, component, URL, isMultiFile ):
212 Saves data: all objects into one file
214 aResult = "" # string-pairs of internal entries and shape streams
216 # get all sub-SObjects with IOR defined
217 anIters = [aStudy.NewChildIterator(findOrCreateComponent())]
220 aLast = anIters[len(anIters) - 1]
226 anIters.append(aStudy.NewChildIterator(aSO))
229 anIters.remove(aLast)
231 for aSO in aSOList: # for each sobject export shapes stream if exists
235 anObj = salome.orb.string_to_object(anIOR)
236 if type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Group:
239 # store internal entry, type and list of indices of the group selection (separated by spaces)
240 aResult += anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
241 aSelList = anObj.GetSelection()
242 aResult += "|" + str(' '.join(str(anI) for anI in aSelList))
243 elif type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Field:
246 # same as for group, but in addition to the second string part - field specifics
247 aResult += anObj.GetEntry() + "|" + str(anObj.GetSelectionType())
248 aResult += " " + str(anObj.GetDataType()) # values type
249 aSteps = anObj.GetSteps()
250 aResult += " " + str(len(aSteps)) # number of steps
251 aComps = anObj.GetComponents()
252 aResult += " " + str(len(aComps)) # number of components
253 for aComp in aComps: # components strings: but before remove spaces and '|'
254 aCoded = aComp.replace(" ", "__space__").replace("|", "__vertical_bar__")
255 aResult += " " + aCoded
256 for aStepNum in range(len(aSteps)):
257 aVals = anObj.GetStep(aStepNum + 1).GetValues()
259 aResult += " " + str(len(aVals)) # first the number of values in the step
260 aResult += " " + str(anObj.GetStep(aStepNum + 1).GetStamp()) # ID of stamp in step
262 aResult += " " + str(aVal) # all values of step
263 aSelList = anObj.GetSelection()
264 aResult += "|" + str(' '.join(str(anI) for anI in aSelList))
265 elif isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
268 # store internal entry + tick, current and old shapes in BRep format
269 aResult += anObj.GetEntry() + " " + str(anObj.GetTick())
270 aResult += "|" + anObj.GetShapeStream().decode()
271 aResult += "|" + anObj.GetOldShapeStream().decode()
273 return aResult.encode()
275 def Load( self, component, stream, URL, isMultiFile ):
280 __entry2IOR__.clear()
281 aList=stream.decode().split('|')
290 aNewShapeStream = aSub
292 else: # create objects by 3 arguments
294 if anId.startswith('group') or (anId.startswith('dead') and anId.count("group") > 0): # group object
295 anObj = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
297 anObj.SetSelection([int(anI) for anI in aSub.split(' ')])
298 anObj.SetSelectionType(int(aNewShapeStream))
299 elif anId.startswith('field') or (anId.startswith('dead') and anId.count("field") > 0): # field object
300 anObj = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
302 anObj.SetSelection([int(anI) for anI in aSub.split(' ')])
303 aParams = aNewShapeStream.split(" ")
304 anObj.SetSelectionType(int(aParams[0]))
305 aTypeStr = aParams[1]
306 if (aTypeStr == "FDT_Bool"):
307 anObj.SetValuesType(0)
308 elif (aTypeStr == "FDT_Int"):
309 anObj.SetValuesType(1)
310 elif (aTypeStr == "FDT_Double"):
311 anObj.SetValuesType(2)
312 elif (aTypeStr == "FDT_String"):
313 anObj.SetValuesType(3)
315 aNumSteps = int(aParams[2])
316 for aVal in range(aNumSteps):
317 aSteps.append(aVal + 1)
318 anObj.SetSteps(aSteps)
319 aCompNum = int(aParams[3])
321 for aCompNameIndex in range(aCompNum):
322 aCompName = aParams[4 + aCompNameIndex].replace("__space__", " ").replace("__vertical_bar__", "|")
323 aCompNames.append(aCompName)
324 anObj.SetComponents(aCompNames)
325 aNumValsInStep = int(aParams[4 + aCompNum])
326 for aStepNum in range(aNumSteps):
327 aStepStartIndex = 4 + aCompNum + aStepNum * (aNumValsInStep + 1) + 1
328 aStampId = int(aParams[aStepStartIndex])
330 for aValIndex in range(aNumValsInStep):
331 aVals.append(float(aParams[aStepStartIndex + aValIndex + 1]))
332 anObj.AddFieldStep(aStampId, aStepNum + 1, aVals)
333 else: # shape object by BRep in the stream: set old first then new
334 anObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
336 anObj.SetShapeByStream(aSub)
337 anObj.SetShapeByStream(aNewShapeStream)
339 anEntryAndTick = anId.split(" ")
340 anObj.SetEntry(anEntryAndTick[0])
341 if len(anEntryAndTick) > 1:
342 anObj.SetTick(int(anEntryAndTick[1]))
343 anIOR = salome.orb.object_to_string(anObj._this())
344 __entry2IOR__[anEntryAndTick[0]] = anIOR
348 def IORToLocalPersistentID(self, sobject, IOR, isMultiFile, isASCII):
350 Gets persistent ID for the CORBA object.
351 The internal entry of the Object is returned.
353 anObj = salome.orb.string_to_object(IOR)
354 if anObj and (isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object) or \
355 isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Field)):
356 return anObj.GetEntry()
359 def LocalPersistentIDToIOR(self, sobject, persistentID, isMultiFile, isASCII):
360 "Converts persistent ID of the object to its IOR."
362 if persistentID in __entry2IOR__:
363 aRes = __entry2IOR__[persistentID]
364 if len(aRes): # set SO from the study, the sobject param is temporary, don't store it
365 salome.orb.string_to_object(aRes).SetSO(getStudy().FindObjectID(sobject.GetID()))
369 def UniqueDumpName( self, theBaseName, theID ):
371 Returns a unique name from the theBaseName. Keeps theBaseName if it was not used yet.
372 Stores the newly generated name into the global map __entry2DumpName__.
374 global __entry2DumpName__
376 # to avoid spaces and parenthesis in the variable name
377 aBaseName = theBaseName.replace(" ", "_").replace("(", "").replace(")", "")
379 while aName in __entry2DumpName__.values():
380 aName = aBaseName + "_" + str(aPrefix)
381 aPrefix = aPrefix + 1
382 __entry2DumpName__[theID] = aName
385 def GetShaperEntry(self, theShapeObj):
387 Returns string in the python dump that generates the SHAPER entry:
388 it may be just entry string, or call for the SHAPER dump variable.
390 global __entry2DumpName__
391 anEntry = "s" + theShapeObj.GetEntry()
392 if anEntry in __entry2DumpName__:
393 return "model.featureStringId(" + __entry2DumpName__[anEntry] + ")"
394 return "\"" + theShapeObj.GetEntry() + "\""
396 def DumpPython( self, isPublished, isMultiFile ):
398 Dump module data to the Python script.
400 global __entry2DumpName__
401 # remove all non-SHAPER entries
403 for anEntry in __entry2DumpName__:
404 if anEntry.startswith("s"):
405 aCopyMap[anEntry] = __entry2DumpName__[anEntry]
406 __entry2DumpName__ = aCopyMap
409 # collect all shape-objects in the SHAPERSTUDY tree
412 aRoots = aStudy.NewChildIterator(findOrCreateComponent())
417 anObj = salome.orb.string_to_object(anIOR)
418 if anObj and type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Object:
419 aShapeObjects.append(anObj)
422 if len(aShapeObjects):
423 script.append("model.publishToShaperStudy()")
424 script.append("import SHAPERSTUDY")
425 for aShapeObj in aShapeObjects:
426 # check this shape also has sub-groups and fields
428 aSOIter = aStudy.NewChildIterator(aShapeObj.GetSO())
429 while aSOIter.More():
430 aGroupSO = aSOIter.Value()
431 anIOR = aGroupSO.GetIOR()
433 aGroup = salome.orb.string_to_object(anIOR)
434 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
435 isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
436 aGroupVarName = self.UniqueDumpName(aGroup.GetName(), aGroupSO.GetID())
437 aGroupVarNames.append(aGroupVarName)
439 aShapeVar = self.UniqueDumpName(aShapeObj.GetName(), aShapeObj.GetSO().GetID())
440 aShapeStr = aShapeVar + ", "
441 for aGName in aGroupVarNames:
442 aShapeStr += aGName + ", "
443 aShapeStr += "= SHAPERSTUDY.shape(" + self.GetShaperEntry(aShapeObj) +")"
444 script.append(aShapeStr)
445 # dump also dead-shapes with groups and fields in the XAO format
446 aRes, aHistSO = aShapeObj.GetSO().FindSubObject(10000) # the History folder
448 aDeads = aStudy.NewChildIterator(aHistSO)
450 aDSO = aDeads.Value()
451 aDIOR = aDSO.GetIOR()
453 aDeadShape = salome.orb.string_to_object(aDIOR)
454 if aDeadShape and type(aDeadShape) == SHAPERSTUDY_ORB._objref_SHAPER_Object:
456 aXAO = StudyData_Swig.StudyData_XAO()
457 aXAO.SetShape(aDeadShape.getShape())
458 anArchiveName = "archive_" + str(anArchiveNum) + ".xao"
459 if len(aStudy.GetDumpPath()):
460 anArchiveName = aStudy.GetDumpPath() + "/" + anArchiveName
462 aDeadVarName = self.UniqueDumpName(aDeadShape.GetName(), aDSO.GetID())
463 aDeadString += aDeadVarName + ", "
464 aDGroupIter = aStudy.NewChildIterator(aDSO)
466 while aDGroupIter.More():
467 aDeadGroup = aDGroupIter.Value().GetObject()
468 if isinstance(aDeadGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
469 aDGroupVarName = self.UniqueDumpName(aDeadGroup.GetName(), aDGroupIter.Value().GetID())
470 aDeadString += aDGroupVarName + ", "
471 aGroupID = aXAO.AddGroup(aDeadGroup.GetSelectionType(), aDGroupVarName)
472 for aSel in aDeadGroup.GetSelection():
473 aXAO.AddGroupSelection(aGroupID, aSel)
474 elif isinstance(aDeadGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
475 aDeadField = aDeadGroup
476 aDFieldVarName = self.UniqueDumpName(aDeadField.GetName(), aDGroupIter.Value().GetID())
477 aDeadString += aDFieldVarName + ", "
478 aComponents = aDeadField.GetComponents()
479 aFieldID = aXAO.AddField(aDeadField.GetValuesType(), aDeadField.GetSelectionType(), \
480 len(aComponents), aDFieldVarName)
481 for aCompIndex in range(len(aComponents)):
482 aXAO.SetFieldComponent(aFieldID, aCompIndex, aComponents[aCompIndex])
483 aSteps = aDeadField.GetSteps()
485 aFieldStep = aDeadField.GetStep(aStep)
486 aXAO.AddStep(aFieldID, aStep, aFieldStep.GetStamp())
487 aStepVals = aFieldStep.GetValues()
488 for aValue in aStepVals:
489 aXAO.AddStepValue(aFieldID, aStep, str(aValue))
491 aXAO.Export(anArchiveName)
492 aDeadString += " = SHAPERSTUDY.archive(" + aShapeVar + ", \"" + anArchiveName + "\")"
493 script.append(aDeadString)
497 script.append("") # to have an end-line in the end
498 result_str = "\n".join(script)
499 encoded_str = result_str.encode() + b'\0' # to avoid garbage symbols in the end
500 return (encoded_str, 1)
502 def GetAllDumpNames( self ):
504 Returns all names with which Object's was dumped
505 into python script to avoid the same names in SMESH script
507 global __entry2DumpName__
509 for anEntry in __entry2DumpName__:
510 aResultList.append(__entry2DumpName__[anEntry])
513 def GetDumpName( self, theStudyEntry ):
515 Returns a name with which a GEOM_Object was dumped into python script
518 theStudyEntry is an entry of the Object in the study
520 global __entry2DumpName__
521 if theStudyEntry in __entry2DumpName__:
522 return __entry2DumpName__[theStudyEntry]
525 def BreakLink(self, theEntry):
527 Breaks links to not-dead shape, make the shape as dead
530 aSO = aStudy.FindObjectID(theEntry)
533 aRes, aSSO = aSO.ReferencedObject()
535 return # only SObjects referenced to the SHAPER STUDY objects are allowed
536 anIOR = aSSO.GetIOR()
538 return # must be referenced to the SHAPER STUDY shape
539 anObj = salome.orb.string_to_object(anIOR)
540 if not anObj or not isinstance(anObj, SHAPERSTUDY_ORB._objref_SHAPER_Object):
543 return # do nothing for reference to already dead shape
544 aDeadShape = anObj.MakeDead()
546 aMeshSObject = aSO.GetFather()
547 aMeshObject = aMeshSObject.GetObject()
549 aBuilder = aStudy.NewBuilder()
550 aBuilder.RemoveReference(aSO) # reset reference to the dead shape
551 aBuilder.Addreference(aSO, aDeadShape.GetSO())
553 # check also sub-structure of the mesh to find references to sub-objects that become dead
554 breakLinkForSubElements(aSO, aDeadShape)
556 # Replace shape object in the parent mesh
557 aMeshObject.ReplaceShape(aDeadShape)
561 Searches a shape object by the SHAPER entry. Used in the python dump script
564 aRoots = aStudy.NewChildIterator(findOrCreateComponent())
569 anObj = salome.orb.string_to_object(anIOR)
570 if anObj and type(anObj) == SHAPERSTUDY_ORB._objref_SHAPER_Object and anObj.GetEntry() == theEntry:
572 # add groups and fields to the result
573 aSOIter = aStudy.NewChildIterator(aSO)
574 while aSOIter.More():
575 aGroupSO = aSOIter.Value()
576 anIOR = aGroupSO.GetIOR()
578 aGroup = salome.orb.string_to_object(anIOR)
579 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group) or \
580 isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
581 aRes = aRes + (aGroup,)
585 return None # not found
587 def archive(theShape, theXAOFile):
589 Creates a dead shapes under the theShape and restores these dead objects state basing on theXAOFile
593 # searching for the last dead
594 aDeads = aStudy.NewChildIterator(theShape.GetSO().FindSubObject(10000)[1])
595 aLastDeadSO = aDeads.Value()
597 aLastDeadSO = aDeads.Value()
600 aDShape = aLastDeadSO.GetObject()
602 aXAO = StudyData_Swig.StudyData_XAO()
603 anError = aXAO.Import(theXAOFile)
605 print("Error of XAO file import: " + anError)
607 aDShape.SetShapeByPointer(aXAO.GetShape())
609 # add groups and fields to the result
612 aSOIter = aStudy.NewChildIterator(aLastDeadSO)
613 while aSOIter.More():
614 aGroupSO = aSOIter.Value()
615 anIOR = aGroupSO.GetIOR()
617 aGroup = salome.orb.string_to_object(anIOR)
618 if isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Group):
620 aGroup.SetSelectionType(aXAO.GetGroupDimension(aGroupIndex))
622 for aSel in aXAO.GetGroupSelection(aGroupIndex):
623 aSelection.append(aSel)
624 aGroup.SetSelection(aSelection)
626 elif isinstance(aGroup, SHAPERSTUDY_ORB._objref_SHAPER_Field):
629 aValType = aXAO.GetValuesType(aFieldIndex)
630 aField.SetValuesType(aValType)
631 aField.SetSelectionType(aXAO.GetSelectionType(aFieldIndex))
633 for aCompName in aXAO.GetComponents(aFieldIndex):
634 aCompNames.append(aCompName)
635 aField.SetComponents(aCompNames)
636 aField.ClearFieldSteps()
637 aXAO.BeginSteps(aFieldIndex)
638 while aXAO.More(aFieldIndex):
640 for aVal in aXAO.GetValues():
641 if aValType == 0: # boolean
642 aValsList.append(int(aVal))
643 elif aValType == 1: # int
644 aValsList.append(int(aVal))
645 elif aValType == 2: # double
646 aValsList.append(float(aVal))
647 aField.AddFieldStep(aXAO.GetStamp(), aXAO.GetStepIndex(), aValsList)
652 return None # not found
654 def isFather(theFather, theChild):
656 Returns true if theChild SObject is a child of theFather SObject
658 aChild = theChild.GetFather()
659 while aChild.Depth() > theFather.Depth():
660 aChild = aChild.GetFather()
661 return aChild.GetID() == theFather.GetID()
663 def breakLinkForSubElements(theMainShapeSO, theDeadShape):
665 Checks sub-structure of the SMESH-mesh to find references to sub-objects that become dead.
666 theMainShapeSO is SObject with reference to real SHAPERSTUDY shape, located under the Mesh node.
667 theDeadShape is a newly created dead shape instance
670 aBuilder = aStudy.NewBuilder()
671 aRoot = theMainShapeSO.GetFather()
672 anIters = [aStudy.NewChildIterator(aRoot)]
674 anOriginShapeSO = theDeadShape.GetSO().GetFather().GetFather()
676 aLast = anIters[len(anIters) - 1]
679 aRes, aSubRef = aSub.ReferencedObject()
680 if aRes and isFather(anOriginShapeSO, aSubRef):
681 aReferenced = aSubRef.GetObject()
682 if aReferenced and not aReferenced.IsDead():
683 aSubList.append(aSub)
684 anIters.append(aStudy.NewChildIterator(aSub))
687 anIters.remove(aLast)
689 # associate the number of sub-objects of the referenced objects
690 aMapSubEntryToIndex = {}
691 aSSOIter = aStudy.NewChildIterator(anOriginShapeSO)
693 while aSSOIter.More():
694 aSub = aSSOIter.Value()
696 aMapSubEntryToIndex[aSub.GetID()] = anIndex
697 anIndex = anIndex + 1
699 for aSubSO in aSubList:
700 aRes, aSubRef = aSubSO.ReferencedObject()
701 if aRes and aSubRef.GetID() in aMapSubEntryToIndex:
702 anIndex = aMapSubEntryToIndex[aSubRef.GetID()]
703 aDeadIter = aStudy.NewChildIterator(theDeadShape.GetSO())
704 while aDeadIter.More(): # iterate dead subs to find object with the same index
705 aDeadSubSO = aDeadIter.Value()
706 if aDeadSubSO.GetIOR():
707 anIndex = anIndex - 1
709 aBuilder.RemoveReference(aSubSO) # reset reference to the dead shape
710 aBuilder.Addreference(aSubSO, aDeadSubSO)