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 *
14 from SALOME_NamingServicePy import *
16 #--------------------------------------------------------------------------
18 def ImportComponentGUI(ComponentName):
19 libName = "lib" + ComponentName + "_Swig"
20 command = "from " + libName + " import *"
22 constructor = ComponentName + "GUI_Swig()"
23 command = "gui = " + constructor
27 #--------------------------------------------------------------------------
29 def SalomeGUIgetAllSelected(self):
30 selNumber = self.SelectedCount()
32 for i in range(selNumber):
33 listSelected.append(self.getSelected(i))
35 #--------------------------------------------------------------------------
37 def generateName(prefix = None):
39 int = whrandom.randint(1,1000);
41 return "Study" + str(int)
43 return prefix + str(int)
45 #WITHOUTIHMfrom libSALOME_Swig import *
46 ###from SalomePyQt import *
47 #WITHOUTIHMclass SalomeGUI(SALOMEGUI_Swig):
48 #WITHOUTIHMgetAllSelected = SalomeGUIgetAllSelected
50 #WITHOUTIHMdef getDesktop(self) :
51 # return SalomePyQt.getDesktop()
52 #WITHOUTIHMreturn None
54 #WITHOUTIHMdef getSelection(self) :
55 # return SalomePyQt.getSelection()
56 #WITHOUTIHMreturn None
58 #--------------------------------------------------------------------------
62 mySO = myStudy.FindObjectID(id);
64 ok, anAttr = mySO.FindAttribute("AttributeIOR")
66 AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
67 if AtIOR.Value() != "":
68 myObj = orb.string_to_object(AtIOR.Value())
71 def ObjectToSObject(obj):
74 ior = orb.object_to_string(obj)
76 mySO = myStudy.FindObjectIOR(ior)
80 mySO = ObjectToSObject(obj)
86 mySO = myStudy.FindObjectID(id);
89 #--------------------------------------------------------------------------
91 def PersistentPresentation(theStudy, theSO, theWithID):
92 # put the sobject's content (with subchildren) to the string
94 attrs = theSO.GetAllAttributes()
97 for a in range(0,aLen):
99 if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
101 elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
103 elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
104 isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
105 isinstance(attr,SALOMEDS._objref_AttributeName) or \
106 isinstance(attr,SALOMEDS._objref_AttributeComment) or \
107 isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
108 isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
109 isinstance(attr,SALOMEDS._objref_AttributeUserID):
110 aResult += " attribute value: " + str(attr.Value())
111 elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
112 aResult += " attribute: IOR"
113 elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
114 isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
115 aResult += " Sequence: " + str(attr.CorbaSequence())
116 elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
117 aResult += " Drawable: " + str(attr.IsDrawable())
118 elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
119 aResult += " Selectable: " + str(attr.IsSelectable())
120 elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
121 aResult += " Expandable: " + str(attr.IsExpandable())
122 elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
123 aResult += " Opened: " + str(attr.IsOpened())
124 elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
125 aResult += " TextColor: " + str(attr.TextColor())
126 elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
127 aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
128 elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
129 aResult += " PixMap: " + str(attr.GetPixMap())
130 elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
131 isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
132 aResult += " Table with title: " + attr.GetTitle()
133 elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
134 aResult += " PythonObject: " + attr.GetObject()
137 aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
139 aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
140 anIter = theStudy.NewChildIterator(theSO)
142 aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
146 #--------------------------------------------------------------------------
149 # returns the document list tree (as list)
150 aResult = [theSO.GetID()]
151 anIter = myStudy.NewChildIterator(theSO)
153 aResult += GetTree(anIter.Value())
157 #--------------------------------------------------------------------------
159 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
161 while aRoot.GetID() != "0:":
162 aRoot = aRoot.GetFather()
163 aTree = GetTree(aRoot)
164 aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
166 if not myStudyManager.CanCopy(theSO):
167 raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
169 if not myStudyManager.Copy(theSO):
170 raise RuntimeError, "<Copy> for "+theInfo+" returns false"
173 if not myStudyManager.CanPaste(theSO):
174 raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
176 # check: before paste study is not changed check
177 if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
178 raise RuntimeError, "Study is changed before Paste calling for "+theInfo
181 if theComponentPaste:
182 aSObj = theSO.GetFatherComponent()
183 theInfo = theInfo + "(paste for component)"
184 if myStudyManager.Paste(aSObj) == None:
185 raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
186 aNewTree = GetTree(aRoot)
188 for a in range(0,aLen):
189 if aTree[a] != aNewTree[a]:
190 return myStudy.FindObjectID(aNewTree[a])
192 if aLen < len(aNewTree):
193 return myStudy.FindObjectID(aNewTree[aLen])
195 raise RuntimeError, "After Copy calling the tree is not changed"
197 #--------------------------------------------------------------------------
198 def FindFileInDataDir(filename):
200 datadir = os.getenv("DATA_DIR")
201 if datadir is not None:
203 dirs = string.split(datadir, ":")
205 file = dir + "/" + filename
206 if os.path.exists(file):
208 datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
209 file = datadir + filename
210 if os.path.exists(file):
215 #--------------------------------------------------------------------------
220 while step < 100 and orb is None:
221 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
226 print "Warning: ORB has not been initialized !!!"
228 # create an LifeCycleCORBA instance
229 lcc = LifeCycleCORBA(orb)
232 while step < 100 and lcc is None:
233 lcc = LifeCycleCORBA(orb)
238 print "Warning: LifeCycleCORBA object has not been initialized !!!"
240 #create a naming service instance
241 naming_service = SALOME_NamingServicePy_i(orb)
243 # get Study Manager reference
247 while step < 100 and obj == None:
248 obj = naming_service.Resolve('myStudyManager')
252 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
254 if myStudyManager is None:
255 print "Warning: SALOMEDS.StudyManager has not been created !!!"
258 aListOfOpenStudies = myStudyManager.GetOpenStudies();
260 if len(aListOfOpenStudies) == 0 :
261 myStudy = myStudyManager.NewStudy("Study1")
263 myStudyName = aListOfOpenStudies[0]
264 myStudy = myStudyManager.GetStudyByName(myStudyName)
266 myStudyName = myStudy._get_Name()
268 myStudyId = myStudy._get_StudyId()