1 # Copyright (C) 2003 CEA/DEN, EDF R&D
5 # File : batchmode_salome.py
8 import salome_shared_modules
10 from omniORB import CORBA
11 from LifeCycleCORBA import *
13 from SALOME_NamingServicePy import *
15 #--------------------------------------------------------------------------
17 def ImportComponentGUI(ComponentName):
18 libName = "lib" + ComponentName + "_Swig"
19 command = "from " + libName + " import *"
21 constructor = ComponentName + "GUI_Swig()"
22 command = "gui = " + constructor
26 #--------------------------------------------------------------------------
28 def SalomeGUIgetAllSelected(self):
29 selNumber = self.SelectedCount()
31 for i in range(selNumber):
32 listSelected.append(self.getSelected(i))
34 #--------------------------------------------------------------------------
36 def generateName(prefix = None):
38 int = whrandom.randint(1,1000);
40 return "Study" + str(int)
42 return prefix + str(int)
44 from libSALOME_Swig import *
45 ###from SalomePyQt import *
46 class SalomeGUI(SALOMEGUI_Swig):
47 getAllSelected = SalomeGUIgetAllSelected
49 def getDesktop(self) :
50 # return SalomePyQt.getDesktop()
53 def getSelection(self) :
54 # return SalomePyQt.getSelection()
57 #--------------------------------------------------------------------------
60 mySO = myStudy.FindObjectID(id);
62 Builder = myStudy.NewBuilder()
63 anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
64 AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
65 myObj = orb.string_to_object(AtIOR.Value())
69 mySO = myStudy.FindObjectID(id);
72 #--------------------------------------------------------------------------
74 def PersistentPresentation(theStudy, theSO, theWithID):
75 # put the sobject's content (with subchildren) to the string
77 attrs = theSO.GetAllAttributes()
80 for a in range(0,aLen):
82 if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
84 elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
86 elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
87 isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
88 isinstance(attr,SALOMEDS._objref_AttributeName) or \
89 isinstance(attr,SALOMEDS._objref_AttributeComment) or \
90 isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
91 isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
92 isinstance(attr,SALOMEDS._objref_AttributeUserID):
93 aResult += " attribute value: " + str(attr.Value())
94 elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
95 aResult += " attribute: IOR"
96 elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
97 isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
98 aResult += " Sequence: " + str(attr.CorbaSequence())
99 elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
100 aResult += " Drawable: " + str(attr.IsDrawable())
101 elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
102 aResult += " Selectable: " + str(attr.IsSelectable())
103 elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
104 aResult += " Expandable: " + str(attr.IsExpandable())
105 elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
106 aResult += " Opened: " + str(attr.IsOpened())
107 elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
108 aResult += " TextColor: " + str(attr.TextColor())
109 elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
110 aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
111 elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
112 aResult += " PixMap: " + str(attr.GetPixMap())
113 elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
114 isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
115 aResult += " Table with title: " + attr.GetTitle()
116 elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
117 aResult += " PythonObject: " + attr.GetObject()
120 aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
122 aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
123 anIter = theStudy.NewChildIterator(theSO)
125 aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
129 #--------------------------------------------------------------------------
132 # returns the document list tree (as list)
133 aResult = [theSO.GetID()]
134 anIter = myStudy.NewChildIterator(theSO)
136 aResult += GetTree(anIter.Value())
140 #--------------------------------------------------------------------------
142 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
144 while aRoot.GetID() != "0:":
145 aRoot = aRoot.GetFather()
146 aTree = GetTree(aRoot)
147 aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
149 if not myStudyManager.CanCopy(theSO):
150 raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
152 if not myStudyManager.Copy(theSO):
153 raise RuntimeError, "<Copy> for "+theInfo+" returns false"
156 if not myStudyManager.CanPaste(theSO):
157 raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
159 # check: before paste study is not changed check
160 if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
161 raise RuntimeError, "Study is changed before Paste calling for "+theInfo
164 if theComponentPaste:
165 aSObj = theSO.GetFatherComponent()
166 theInfo = theInfo + "(paste for component)"
167 if not myStudyManager.Paste(aSObj):
168 raise RuntimeError, "<Paste> for "+theInfo+" returns false"
169 aNewTree = GetTree(aRoot)
171 for a in range(0,aLen):
172 if aTree[a] != aNewTree[a]:
173 return myStudy.FindObjectID(aNewTree[a])
175 if aLen < len(aNewTree):
176 return myStudy.FindObjectID(aNewTree[aLen])
178 raise RuntimeError, "After Copy calling the tree is not changed"
180 #--------------------------------------------------------------------------
181 def FindFileInDataDir(filename):
183 datadir = os.getenv("DATA_DIR")
184 if datadir is not None:
186 dirs = string.split(datadir, ":")
188 file = dir + "/" + filename
189 if os.path.exists(file):
191 datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
192 file = datadir + filename
193 if os.path.exists(file):
198 #--------------------------------------------------------------------------
200 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
202 # create an LifeCycleCORBA instance
203 lcc = LifeCycleCORBA(orb)
205 #create a naming service instance
206 naming_service = SALOME_NamingServicePy_i(orb)
208 # get Study Manager reference
209 obj = naming_service.Resolve('myStudyManager')
210 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
213 myStudy = myStudyManager.NewStudy("Study1")
215 myStudyName = myStudy._get_Name()
217 myStudyId = myStudy._get_StudyId()