1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019 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(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 = myStudy.NewChildIterator(theSO)
159 aResult += PersistentPresentation(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(aRoot, 1)
183 aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
185 if not myStudy.CanCopy(theSO):
186 raise RuntimeError("<CanCopy> for "+theInfo+" returns false")
188 if not myStudy.Copy(theSO):
189 raise RuntimeError("<Copy> for "+theInfo+" returns false")
192 if not myStudy.CanPaste(theSO):
193 raise RuntimeError("<CanPaste> for "+theInfo+" returns false")
195 # check: before paste study is not changed check
196 if aStudyPersist != PersistentPresentation(aRoot, 1):
197 raise RuntimeError("Study is changed before Paste calling for "+theInfo)
200 if theComponentPaste:
201 aSObj = theSO.GetFatherComponent()
202 theInfo = theInfo + "(paste for component)"
203 if myStudy.Paste(aSObj) == None:
204 raise RuntimeError("<Paste> for "+theInfo+" returns None object")
205 aNewTree = GetTree(aRoot)
207 for a in range(0,aLen):
208 if aTree[a] != aNewTree[a]:
209 return myStudy.FindObjectID(aNewTree[a])
211 if aLen < len(aNewTree):
212 return myStudy.FindObjectID(aNewTree[aLen])
214 raise RuntimeError("After Copy calling the tree is not changed")
216 #--------------------------------------------------------------------------
217 def FindFileInDataDir(filename):
219 datadir = os.getenv("DATA_DIR")
220 if datadir is not None:
222 dirs = string.split(datadir, ":")
224 file = dir + "/" + filename
225 if os.path.exists(file):
227 datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
228 file = datadir + filename
229 if os.path.exists(file):
234 #--------------------------------------------------------------------------
240 sleeping_time_max = 1.0
242 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
243 if orb is not None: break
246 time.sleep(sleeping_time)
247 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
251 print("Warning: ORB has not been initialized !!!")
253 # create an LifeCycleCORBA instance
254 lcc = LifeCycleCORBA(orb)
258 sleeping_time_max = 1.0
260 lcc = LifeCycleCORBA(orb)
261 if lcc is not None: break
264 time.sleep(sleeping_time)
265 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
269 print("Warning: LifeCycleCORBA object has not been initialized !!!")
271 #create a naming service instance
272 naming_service = SALOME_NamingServicePy_i(orb)
274 # get Study reference
279 sleeping_time_max = 1.0
281 obj = naming_service.Resolve('/Study')
282 if obj is not None:break
285 time.sleep(sleeping_time)
286 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
289 myStudy = obj._narrow(SALOMEDS.Study)
293 print("Warning: SALOMEDS.Study has not been created !!!")
295 myStudyName = myStudy._get_Name()