1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # File : batchmode_salome.py
27 from omniORB import CORBA
28 from LifeCycleCORBA import *
31 from SALOME_NamingServicePy import *
33 #--------------------------------------------------------------------------
35 def ImportComponentGUI(ComponentName):
36 libName = "lib" + ComponentName + "_Swig"
37 command = "from " + libName + " import *"
38 exec (command, globals())
39 constructor = ComponentName + "GUI_Swig()"
40 command = "gui = " + constructor
41 exec (command, globals())
44 #--------------------------------------------------------------------------
46 def SalomeGUIgetAllSelected(self):
47 selNumber = self.SelectedCount()
49 for i in range(selNumber):
50 listSelected.append(self.getSelected(i))
52 #--------------------------------------------------------------------------
54 def generateName(prefix = None):
56 int = random.randint(1,1000);
58 return "Study" + str(int)
60 return prefix + str(int)
62 #WITHOUTIHMfrom libSALOME_Swig import *
63 ###from SalomePyQt import *
64 #WITHOUTIHMclass SalomeGUI(SALOMEGUI_Swig):
65 #WITHOUTIHMgetAllSelected = SalomeGUIgetAllSelected
67 #WITHOUTIHMdef getDesktop(self) :
68 # return SalomePyQt.getDesktop()
69 #WITHOUTIHMreturn None
71 #WITHOUTIHMdef getSelection(self) :
72 # return SalomePyQt.getSelection()
73 #WITHOUTIHMreturn None
75 #--------------------------------------------------------------------------
79 mySO = myStudy.FindObjectID(id);
81 ok, anAttr = mySO.FindAttribute("AttributeIOR")
83 AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
84 if AtIOR.Value() != "":
85 myObj = orb.string_to_object(AtIOR.Value())
88 def ObjectToSObject(obj):
91 ior = orb.object_to_string(obj)
93 mySO = myStudy.FindObjectIOR(ior)
97 mySO = ObjectToSObject(obj)
103 mySO = myStudy.FindObjectID(id);
106 #--------------------------------------------------------------------------
108 def PersistentPresentation(theStudy, theSO, theWithID):
109 # put the sobject's content (with subchildren) to the string
111 attrs = theSO.GetAllAttributes()
114 for a in range(0,aLen):
116 if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
118 elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
120 elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
121 isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
122 isinstance(attr,SALOMEDS._objref_AttributeName) or \
123 isinstance(attr,SALOMEDS._objref_AttributeComment) or \
124 isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
125 isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
126 isinstance(attr,SALOMEDS._objref_AttributeUserID):
127 aResult += " attribute value: " + str(attr.Value())
128 elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
129 aResult += " attribute: IOR"
130 elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
131 isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
132 aResult += " Sequence: " + str(attr.CorbaSequence())
133 elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
134 aResult += " Drawable: " + str(attr.IsDrawable())
135 elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
136 aResult += " Selectable: " + str(attr.IsSelectable())
137 elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
138 aResult += " Expandable: " + str(attr.IsExpandable())
139 elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
140 aResult += " Opened: " + str(attr.IsOpened())
141 elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
142 aResult += " TextColor: " + str(attr.TextColor())
143 elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
144 aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
145 elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
146 aResult += " PixMap: " + str(attr.GetPixMap())
147 elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
148 isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
149 aResult += " Table with title: " + attr.GetTitle()
150 elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
151 aResult += " PythonObject: " + attr.GetObject()
154 aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
156 aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
157 anIter = theStudy.NewChildIterator(theSO)
159 aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
163 #--------------------------------------------------------------------------
166 # returns the document list tree (as list)
167 aResult = [theSO.GetID()]
168 anIter = myStudy.NewChildIterator(theSO)
170 aResult += GetTree(anIter.Value())
174 #--------------------------------------------------------------------------
176 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
178 while aRoot.GetID() != "0:":
179 aRoot = aRoot.GetFather()
180 aTree = GetTree(aRoot)
181 aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
183 if not myStudyManager.CanCopy(theSO):
184 raise RuntimeError("<CanCopy> for "+theInfo+" returns false")
186 if not myStudyManager.Copy(theSO):
187 raise RuntimeError("<Copy> for "+theInfo+" returns false")
190 if not myStudyManager.CanPaste(theSO):
191 raise RuntimeError("<CanPaste> for "+theInfo+" returns false")
193 # check: before paste study is not changed check
194 if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
195 raise RuntimeError("Study is changed before Paste calling for "+theInfo)
198 if theComponentPaste:
199 aSObj = theSO.GetFatherComponent()
200 theInfo = theInfo + "(paste for component)"
201 if myStudyManager.Paste(aSObj) == None:
202 raise RuntimeError("<Paste> for "+theInfo+" returns None object")
203 aNewTree = GetTree(aRoot)
205 for a in range(0,aLen):
206 if aTree[a] != aNewTree[a]:
207 return myStudy.FindObjectID(aNewTree[a])
209 if aLen < len(aNewTree):
210 return myStudy.FindObjectID(aNewTree[aLen])
212 raise RuntimeError("After Copy calling the tree is not changed")
214 #--------------------------------------------------------------------------
215 def FindFileInDataDir(filename):
217 datadir = os.getenv("DATA_DIR")
218 if datadir is not None:
220 dirs = string.split(datadir, ":")
222 file = dir + "/" + filename
223 if os.path.exists(file):
225 datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
226 file = datadir + filename
227 if os.path.exists(file):
232 #--------------------------------------------------------------------------
238 sleeping_time_max = 1.0
240 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
241 if orb is not None: break
244 time.sleep(sleeping_time)
245 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
249 print("Warning: ORB has not been initialized !!!")
251 # create an LifeCycleCORBA instance
252 lcc = LifeCycleCORBA(orb)
256 sleeping_time_max = 1.0
258 lcc = LifeCycleCORBA(orb)
259 if lcc is not None: break
262 time.sleep(sleeping_time)
263 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
267 print("Warning: LifeCycleCORBA object has not been initialized !!!")
269 #create a naming service instance
270 naming_service = SALOME_NamingServicePy_i(orb)
272 # get Study Manager reference
277 sleeping_time_max = 1.0
279 obj = naming_service.Resolve('myStudyManager')
280 if obj is not None:break
283 time.sleep(sleeping_time)
284 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
287 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
289 if myStudyManager is None:
290 print("Warning: SALOMEDS.StudyManager has not been created !!!")
293 aListOfOpenStudies = myStudyManager.GetOpenStudies();
295 if len(aListOfOpenStudies) == 0 :
296 myStudy = myStudyManager.NewStudy("Study1")
298 myStudyName = aListOfOpenStudies[0]
299 myStudy = myStudyManager.GetStudyByName(myStudyName)
301 myStudyName = myStudy._get_Name()
303 myStudyId = myStudy._get_StudyId()