Use Geom Folders to store structural elements (closes EDF issues #2770 and #1885)

This commit is contained in:
barate 2013-10-23 10:08:14 +00:00
parent fd18eef43f
commit ae9978e570

View File

@ -66,6 +66,7 @@ from salome.kernel.studyedit import getStudyEditor
__all__ = ["parts", "orientation"] __all__ = ["parts", "orientation"]
from salome.geom.geomtools import getGeompy
from salome.geom.structelem import parts from salome.geom.structelem import parts
from salome.geom.structelem.parts import InvalidParameterError from salome.geom.structelem.parts import InvalidParameterError
@ -238,7 +239,8 @@ class StructuralElement:
instantiated directly in the general case. instantiated directly in the general case.
""" """
_counter = 1 _counter = 1
_mainFolderTag = 14725
MAIN_FOLDER_NAME = "Structural Elements"
def __init__(self, studyId = None): def __init__(self, studyId = None):
# _parts is the dictionary mapping group name to structural element # _parts is the dictionary mapping group name to structural element
@ -257,15 +259,18 @@ class StructuralElement:
def _getSObject(self): def _getSObject(self):
""" """
Find or create the study object corresponding to the structural Find or create the study object corresponding to the structural
element. This object is named "SE_N" where N is a numerical ID. element. This object is a Geom Folder named "SE_N" where N is a
numerical ID.
""" """
if self._SObject is None: if self._SObject is None:
geompy = getGeompy(self._studyEditor.studyId)
geomComponent = self._studyEditor.study.FindComponent("GEOM") geomComponent = self._studyEditor.study.FindComponent("GEOM")
mainFolder = self._studyEditor.setItemAtTag(geomComponent, mainFolder = self._studyEditor.findItem(geomComponent,
StructuralElement._mainFolderTag, name = StructuralElement.MAIN_FOLDER_NAME,
name = "Structural Elements") typeId=999)
self._SObject = self._studyEditor.findOrCreateItem(mainFolder, if mainFolder is None:
name = "SE_" + str(self._id)) mainFolder = geompy.NewFolder(StructuralElement.MAIN_FOLDER_NAME)
self._SObject = geompy.NewFolder("SE_" + str(self._id), mainFolder)
return self._SObject return self._SObject
def addPart(self, newpart): def addPart(self, newpart):
@ -334,6 +339,7 @@ class StructuralElement:
different parts of the structural element, and add them to the study. different parts of the structural element, and add them to the study.
""" """
gg = salome.ImportComponentGUI("GEOM") gg = salome.ImportComponentGUI("GEOM")
geompy = getGeompy(self._studyEditor.studyId)
for part in self._parts.itervalues(): for part in self._parts.itervalues():
# Build the structural element part # Build the structural element part
logger.debug("Building %s" % part) logger.debug("Building %s" % part)
@ -347,28 +353,17 @@ class StructuralElement:
continue continue
# Add the new objects to the study # Add the new objects to the study
IOR = self._studyEditor.study.ConvertObjectToIOR(shape)
shapeSObjName = part.name + "_" + part.groupName shapeSObjName = part.name + "_" + part.groupName
icon = None geompy.addToStudy(shape, shapeSObjName)
if salome.hasDesktop(): geompy.PutToFolder(shape, self._getSObject())
icon = gg.getShapeTypeIcon(IOR)
shapeSObj = self._studyEditor.createItem(self._getSObject(),
name = shapeSObjName, IOR = IOR,
icon = icon)
if markers is not None and len(markers) > 0: if markers is not None and len(markers) > 0:
i = 1 for i, marker in enumerate(markers, start = 1):
for marker in markers:
markerIOR = \
self._studyEditor.study.ConvertObjectToIOR(marker)
markerSObjName = "Orient_" + shapeSObjName markerSObjName = "Orient_" + shapeSObjName
if len(markers) > 1: if len(markers) > 1:
markerSObjName += "_%d" % i markerSObjName += "_%d" % i
markerSObj = self._studyEditor.createItem( geompy.addToStudy(marker, markerSObjName)
self._getSObject(), geompy.PutToFolder(marker, self._getSObject())
name = markerSObjName,
IOR = markerIOR,
icon = "ICON_OBJBROWSER_LCS")
i += 1
def display(self): def display(self):
""" """
@ -385,16 +380,17 @@ class StructuralElement:
if theSObject is not None: if theSObject is not None:
gg = salome.ImportComponentGUI("GEOM") gg = salome.ImportComponentGUI("GEOM")
aStudy = theSObject.GetStudy() aStudy = theSObject.GetStudy()
useCaseBuilder = aStudy.GetUseCaseBuilder()
editor = getStudyEditor(aStudy._get_StudyId()) editor = getStudyEditor(aStudy._get_StudyId())
aIterator = aStudy.NewChildIterator(theSObject) aIterator = useCaseBuilder.GetUseCaseIterator(theSObject)
aIterator.Init() aIterator.Init(False)
while aIterator.More(): while aIterator.More():
sobj = aIterator.Value() sobj = aIterator.Value()
icon = editor.getIcon(sobj) icon = editor.getIcon(sobj)
if icon != "ICON_OBJBROWSER_LCS": if icon != "ICON_OBJBROWSER_LCS":
entry = aIterator.Value().GetID() entry = aIterator.Value().GetID()
gg.createAndDisplayGO(entry) gg.createAndDisplayGO(entry)
gg.setDisplayMode(entry, 1) gg.setDisplayMode(entry, 2) # Shading + edges
aIterator.Next() aIterator.Next()