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 #WITHOUTIHMfrom libSALOME_Swig import *
45 ###from SalomePyQt import *
46 #WITHOUTIHMclass SalomeGUI(SALOMEGUI_Swig):
47 #WITHOUTIHMgetAllSelected = SalomeGUIgetAllSelected
49 #WITHOUTIHMdef getDesktop(self) :
50 # return SalomePyQt.getDesktop()
51 #WITHOUTIHMreturn None
53 #WITHOUTIHMdef getSelection(self) :
54 # return SalomePyQt.getSelection()
55 #WITHOUTIHMreturn None
57 #--------------------------------------------------------------------------
61 mySO = myStudy.FindObjectID(id);
63 ok, anAttr = mySO.FindAttribute("AttributeIOR")
65 AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
66 if AtIOR.Value() != "":
67 myObj = orb.string_to_object(AtIOR.Value())
70 def ObjectToSObject(obj):
73 ior = orb.object_to_string(obj)
75 mySO = myStudy.FindObjectIOR(ior)
79 mySO = ObjectToSObject(obj)
85 mySO = myStudy.FindObjectID(id);
88 #--------------------------------------------------------------------------
90 def PersistentPresentation(theStudy, theSO, theWithID):
91 # put the sobject's content (with subchildren) to the string
93 attrs = theSO.GetAllAttributes()
96 for a in range(0,aLen):
98 if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
100 elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
102 elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
103 isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
104 isinstance(attr,SALOMEDS._objref_AttributeName) or \
105 isinstance(attr,SALOMEDS._objref_AttributeComment) or \
106 isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
107 isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
108 isinstance(attr,SALOMEDS._objref_AttributeUserID):
109 aResult += " attribute value: " + str(attr.Value())
110 elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
111 aResult += " attribute: IOR"
112 elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
113 isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
114 aResult += " Sequence: " + str(attr.CorbaSequence())
115 elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
116 aResult += " Drawable: " + str(attr.IsDrawable())
117 elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
118 aResult += " Selectable: " + str(attr.IsSelectable())
119 elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
120 aResult += " Expandable: " + str(attr.IsExpandable())
121 elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
122 aResult += " Opened: " + str(attr.IsOpened())
123 elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
124 aResult += " TextColor: " + str(attr.TextColor())
125 elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
126 aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
127 elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
128 aResult += " PixMap: " + str(attr.GetPixMap())
129 elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
130 isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
131 aResult += " Table with title: " + attr.GetTitle()
132 elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
133 aResult += " PythonObject: " + attr.GetObject()
136 aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
138 aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
139 anIter = theStudy.NewChildIterator(theSO)
141 aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
145 #--------------------------------------------------------------------------
148 # returns the document list tree (as list)
149 aResult = [theSO.GetID()]
150 anIter = myStudy.NewChildIterator(theSO)
152 aResult += GetTree(anIter.Value())
156 #--------------------------------------------------------------------------
158 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
160 while aRoot.GetID() != "0:":
161 aRoot = aRoot.GetFather()
162 aTree = GetTree(aRoot)
163 aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
165 if not myStudyManager.CanCopy(theSO):
166 raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
168 if not myStudyManager.Copy(theSO):
169 raise RuntimeError, "<Copy> for "+theInfo+" returns false"
172 if not myStudyManager.CanPaste(theSO):
173 raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
175 # check: before paste study is not changed check
176 if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
177 raise RuntimeError, "Study is changed before Paste calling for "+theInfo
180 if theComponentPaste:
181 aSObj = theSO.GetFatherComponent()
182 theInfo = theInfo + "(paste for component)"
183 if myStudyManager.Paste(aSObj) == None:
184 raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
185 aNewTree = GetTree(aRoot)
187 for a in range(0,aLen):
188 if aTree[a] != aNewTree[a]:
189 return myStudy.FindObjectID(aNewTree[a])
191 if aLen < len(aNewTree):
192 return myStudy.FindObjectID(aNewTree[aLen])
194 raise RuntimeError, "After Copy calling the tree is not changed"
196 #--------------------------------------------------------------------------
197 def FindFileInDataDir(filename):
199 datadir = os.getenv("DATA_DIR")
200 if datadir is not None:
202 dirs = string.split(datadir, ":")
204 file = dir + "/" + filename
205 if os.path.exists(file):
207 datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
208 file = datadir + filename
209 if os.path.exists(file):
214 #--------------------------------------------------------------------------
219 while step < 100 and orb is None:
220 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
225 print "Warning: ORB has not been initialized !!!"
227 # create an LifeCycleCORBA instance
228 lcc = LifeCycleCORBA(orb)
231 while step < 100 and lcc._catalog is None:
232 lcc = LifeCycleCORBA(orb)
236 if lcc._catalog is None:
237 print "Warning: LifeCycleCORBA object is incomplete !!!"
239 #create a naming service instance
240 naming_service = SALOME_NamingServicePy_i(orb)
242 # get Study Manager reference
246 while step < 100 and obj == None:
247 obj = naming_service.Resolve('myStudyManager')
251 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
253 if myStudyManager is None:
254 print "Warning: SALOMEDS.StudyManager has not been created !!!"
257 aListOfOpenStudies = myStudyManager.GetOpenStudies();
259 if len(aListOfOpenStudies) == 0 :
260 myStudy = myStudyManager.NewStudy("Study1")
262 myStudyName = aListOfOpenStudies[0]
263 myStudy = myStudyManager.GetStudyByName(myStudyName)
265 myStudyName = myStudy._get_Name()
267 myStudyId = myStudy._get_StudyId()