2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # File : batchmode_salome.py
26 #import salome_shared_modules
28 from omniORB import CORBA
29 from LifeCycleCORBA import *
32 from SALOME_NamingServicePy import *
34 #--------------------------------------------------------------------------
36 def ImportComponentGUI(ComponentName):
37 libName = "lib" + ComponentName + "_Swig"
38 command = "from " + libName + " import *"
40 constructor = ComponentName + "GUI_Swig()"
41 command = "gui = " + constructor
45 #--------------------------------------------------------------------------
47 def SalomeGUIgetAllSelected(self):
48 selNumber = self.SelectedCount()
50 for i in range(selNumber):
51 listSelected.append(self.getSelected(i))
53 #--------------------------------------------------------------------------
55 def generateName(prefix = None):
57 int = whrandom.randint(1,1000);
59 return "Study" + str(int)
61 return prefix + str(int)
63 #WITHOUTIHMfrom libSALOME_Swig import *
64 ###from SalomePyQt import *
65 #WITHOUTIHMclass SalomeGUI(SALOMEGUI_Swig):
66 #WITHOUTIHMgetAllSelected = SalomeGUIgetAllSelected
68 #WITHOUTIHMdef getDesktop(self) :
69 # return SalomePyQt.getDesktop()
70 #WITHOUTIHMreturn None
72 #WITHOUTIHMdef getSelection(self) :
73 # return SalomePyQt.getSelection()
74 #WITHOUTIHMreturn None
76 #--------------------------------------------------------------------------
80 mySO = myStudy.FindObjectID(id);
82 ok, anAttr = mySO.FindAttribute("AttributeIOR")
84 AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
85 if AtIOR.Value() != "":
86 myObj = orb.string_to_object(AtIOR.Value())
89 def ObjectToSObject(obj):
92 ior = orb.object_to_string(obj)
94 mySO = myStudy.FindObjectIOR(ior)
98 mySO = ObjectToSObject(obj)
104 mySO = myStudy.FindObjectID(id);
107 #--------------------------------------------------------------------------
109 def PersistentPresentation(theStudy, theSO, theWithID):
110 # put the sobject's content (with subchildren) to the string
112 attrs = theSO.GetAllAttributes()
115 for a in range(0,aLen):
117 if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
119 elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
121 elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
122 isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
123 isinstance(attr,SALOMEDS._objref_AttributeName) or \
124 isinstance(attr,SALOMEDS._objref_AttributeComment) or \
125 isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
126 isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
127 isinstance(attr,SALOMEDS._objref_AttributeUserID):
128 aResult += " attribute value: " + str(attr.Value())
129 elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
130 aResult += " attribute: IOR"
131 elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
132 isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
133 aResult += " Sequence: " + str(attr.CorbaSequence())
134 elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
135 aResult += " Drawable: " + str(attr.IsDrawable())
136 elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
137 aResult += " Selectable: " + str(attr.IsSelectable())
138 elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
139 aResult += " Expandable: " + str(attr.IsExpandable())
140 elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
141 aResult += " Opened: " + str(attr.IsOpened())
142 elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
143 aResult += " TextColor: " + str(attr.TextColor())
144 elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
145 aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
146 elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
147 aResult += " PixMap: " + str(attr.GetPixMap())
148 elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
149 isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
150 aResult += " Table with title: " + attr.GetTitle()
151 elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
152 aResult += " PythonObject: " + attr.GetObject()
155 aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
157 aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
158 anIter = theStudy.NewChildIterator(theSO)
160 aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
164 #--------------------------------------------------------------------------
167 # returns the document list tree (as list)
168 aResult = [theSO.GetID()]
169 anIter = myStudy.NewChildIterator(theSO)
171 aResult += GetTree(anIter.Value())
175 #--------------------------------------------------------------------------
177 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
179 while aRoot.GetID() != "0:":
180 aRoot = aRoot.GetFather()
181 aTree = GetTree(aRoot)
182 aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
184 if not myStudyManager.CanCopy(theSO):
185 raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
187 if not myStudyManager.Copy(theSO):
188 raise RuntimeError, "<Copy> for "+theInfo+" returns false"
191 if not myStudyManager.CanPaste(theSO):
192 raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
194 # check: before paste study is not changed check
195 if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
196 raise RuntimeError, "Study is changed before Paste calling for "+theInfo
199 if theComponentPaste:
200 aSObj = theSO.GetFatherComponent()
201 theInfo = theInfo + "(paste for component)"
202 if myStudyManager.Paste(aSObj) == None:
203 raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
204 aNewTree = GetTree(aRoot)
206 for a in range(0,aLen):
207 if aTree[a] != aNewTree[a]:
208 return myStudy.FindObjectID(aNewTree[a])
210 if aLen < len(aNewTree):
211 return myStudy.FindObjectID(aNewTree[aLen])
213 raise RuntimeError, "After Copy calling the tree is not changed"
215 #--------------------------------------------------------------------------
216 def FindFileInDataDir(filename):
218 datadir = os.getenv("DATA_DIR")
219 if datadir is not None:
221 dirs = string.split(datadir, ":")
223 file = dir + "/" + filename
224 if os.path.exists(file):
226 datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
227 file = datadir + filename
228 if os.path.exists(file):
233 #--------------------------------------------------------------------------
239 sleeping_time_max = 1.0
241 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
242 if orb is not None: break
245 time.sleep(sleeping_time)
246 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
250 print "Warning: ORB has not been initialized !!!"
252 # create an LifeCycleCORBA instance
253 lcc = LifeCycleCORBA(orb)
257 sleeping_time_max = 1.0
259 lcc = LifeCycleCORBA(orb)
260 if lcc is not None: break
263 time.sleep(sleeping_time)
264 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
268 print "Warning: LifeCycleCORBA object has not been initialized !!!"
270 #create a naming service instance
271 naming_service = SALOME_NamingServicePy_i(orb)
273 # get Study Manager reference
278 sleeping_time_max = 1.0
280 obj = naming_service.Resolve('myStudyManager')
281 if obj is not None:break
284 time.sleep(sleeping_time)
285 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
288 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
290 if myStudyManager is None:
291 print "Warning: SALOMEDS.StudyManager has not been created !!!"
294 aListOfOpenStudies = myStudyManager.GetOpenStudies();
296 if len(aListOfOpenStudies) == 0 :
297 myStudy = myStudyManager.NewStudy("Study1")
299 myStudyName = aListOfOpenStudies[0]
300 myStudy = myStudyManager.GetStudyByName(myStudyName)
302 myStudyName = myStudy._get_Name()
304 myStudyId = myStudy._get_StudyId()