1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # File : batchmode_salome.py
24 #import salome_shared_modules
26 from omniORB import CORBA
27 from LifeCycleCORBA import *
30 from SALOME_NamingServicePy import *
32 #--------------------------------------------------------------------------
34 def ImportComponentGUI(ComponentName):
35 libName = "lib" + ComponentName + "_Swig"
36 command = "from " + libName + " import *"
38 constructor = ComponentName + "GUI_Swig()"
39 command = "gui = " + constructor
43 #--------------------------------------------------------------------------
45 def SalomeGUIgetAllSelected(self):
46 selNumber = self.SelectedCount()
48 for i in range(selNumber):
49 listSelected.append(self.getSelected(i))
51 #--------------------------------------------------------------------------
53 def generateName(prefix = None):
55 int = whrandom.randint(1,1000);
57 return "Study" + str(int)
59 return prefix + str(int)
61 #WITHOUTIHMfrom libSALOME_Swig import *
62 ###from SalomePyQt import *
63 #WITHOUTIHMclass SalomeGUI(SALOMEGUI_Swig):
64 #WITHOUTIHMgetAllSelected = SalomeGUIgetAllSelected
66 #WITHOUTIHMdef getDesktop(self) :
67 # return SalomePyQt.getDesktop()
68 #WITHOUTIHMreturn None
70 #WITHOUTIHMdef getSelection(self) :
71 # return SalomePyQt.getSelection()
72 #WITHOUTIHMreturn None
74 #--------------------------------------------------------------------------
78 mySO = myStudy.FindObjectID(id);
80 ok, anAttr = mySO.FindAttribute("AttributeIOR")
82 AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
83 if AtIOR.Value() != "":
84 myObj = orb.string_to_object(AtIOR.Value())
87 def ObjectToSObject(obj):
90 ior = orb.object_to_string(obj)
92 mySO = myStudy.FindObjectIOR(ior)
96 mySO = ObjectToSObject(obj)
102 mySO = myStudy.FindObjectID(id);
105 #--------------------------------------------------------------------------
107 def PersistentPresentation(theStudy, theSO, theWithID):
108 # put the sobject's content (with subchildren) to the string
110 attrs = theSO.GetAllAttributes()
113 for a in range(0,aLen):
115 if isinstance(attr,SALOMEDS._objref_AttributeTreeNode):
117 elif isinstance(attr,SALOMEDS._objref_AttributeTarget):
119 elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \
120 isinstance(attr,SALOMEDS._objref_AttributeInteger) or \
121 isinstance(attr,SALOMEDS._objref_AttributeName) or \
122 isinstance(attr,SALOMEDS._objref_AttributeComment) or \
123 isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \
124 isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \
125 isinstance(attr,SALOMEDS._objref_AttributeUserID):
126 aResult += " attribute value: " + str(attr.Value())
127 elif isinstance(attr,SALOMEDS._objref_AttributeIOR):
128 aResult += " attribute: IOR"
129 elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \
130 isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger):
131 aResult += " Sequence: " + str(attr.CorbaSequence())
132 elif isinstance(attr,SALOMEDS._objref_AttributeDrawable):
133 aResult += " Drawable: " + str(attr.IsDrawable())
134 elif isinstance(attr,SALOMEDS._objref_AttributeSelectable):
135 aResult += " Selectable: " + str(attr.IsSelectable())
136 elif isinstance(attr,SALOMEDS._objref_AttributeExpandable):
137 aResult += " Expandable: " + str(attr.IsExpandable())
138 elif isinstance(attr,SALOMEDS._objref_AttributeOpened):
139 aResult += " Opened: " + str(attr.IsOpened())
140 elif isinstance(attr,SALOMEDS._objref_AttributeTextColor):
141 aResult += " TextColor: " + str(attr.TextColor())
142 elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor):
143 aResult += " TextHighlightColor: " + str(attr.TextHighlightColor())
144 elif isinstance(attr,SALOMEDS._objref_AttributePixMap):
145 aResult += " PixMap: " + str(attr.GetPixMap())
146 elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \
147 isinstance(attr,SALOMEDS._objref_AttributeTableOfReal):
148 aResult += " Table with title: " + attr.GetTitle()
149 elif isinstance(attr,SALOMEDS._objref_AttributePythonObject):
150 aResult += " PythonObject: " + attr.GetObject()
153 aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
155 aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n'
156 anIter = theStudy.NewChildIterator(theSO)
158 aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID)
162 #--------------------------------------------------------------------------
165 # returns the document list tree (as list)
166 aResult = [theSO.GetID()]
167 anIter = myStudy.NewChildIterator(theSO)
169 aResult += GetTree(anIter.Value())
173 #--------------------------------------------------------------------------
175 def CheckCopyPaste(theSO, theInfo ,theComponentPaste):
177 while aRoot.GetID() != "0:":
178 aRoot = aRoot.GetFather()
179 aTree = GetTree(aRoot)
180 aStudyPersist = PersistentPresentation(myStudy, aRoot, 1)
182 if not myStudyManager.CanCopy(theSO):
183 raise RuntimeError, "<CanCopy> for "+theInfo+" returns false"
185 if not myStudyManager.Copy(theSO):
186 raise RuntimeError, "<Copy> for "+theInfo+" returns false"
189 if not myStudyManager.CanPaste(theSO):
190 raise RuntimeError, "<CanPaste> for "+theInfo+" returns false"
192 # check: before paste study is not changed check
193 if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1):
194 raise RuntimeError, "Study is changed before Paste calling for "+theInfo
197 if theComponentPaste:
198 aSObj = theSO.GetFatherComponent()
199 theInfo = theInfo + "(paste for component)"
200 if myStudyManager.Paste(aSObj) == None:
201 raise RuntimeError, "<Paste> for "+theInfo+" returns None object"
202 aNewTree = GetTree(aRoot)
204 for a in range(0,aLen):
205 if aTree[a] != aNewTree[a]:
206 return myStudy.FindObjectID(aNewTree[a])
208 if aLen < len(aNewTree):
209 return myStudy.FindObjectID(aNewTree[aLen])
211 raise RuntimeError, "After Copy calling the tree is not changed"
213 #--------------------------------------------------------------------------
214 def FindFileInDataDir(filename):
216 datadir = os.getenv("DATA_DIR")
217 if datadir is not None:
219 dirs = string.split(datadir, ":")
221 file = dir + "/" + filename
222 if os.path.exists(file):
224 datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/"
225 file = datadir + filename
226 if os.path.exists(file):
231 #--------------------------------------------------------------------------
237 sleeping_time_max = 1.0
239 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
240 if orb is not None: break
243 time.sleep(sleeping_time)
244 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
248 print "Warning: ORB has not been initialized !!!"
250 # create an LifeCycleCORBA instance
251 lcc = LifeCycleCORBA(orb)
255 sleeping_time_max = 1.0
257 lcc = LifeCycleCORBA(orb)
258 if lcc is not None: break
261 time.sleep(sleeping_time)
262 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
266 print "Warning: LifeCycleCORBA object has not been initialized !!!"
268 #create a naming service instance
269 naming_service = SALOME_NamingServicePy_i(orb)
271 # get Study Manager reference
276 sleeping_time_max = 1.0
278 obj = naming_service.Resolve('myStudyManager')
279 if obj is not None:break
282 time.sleep(sleeping_time)
283 sleeping_time = max(sleeping_time_max, 2*sleeping_time)
286 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
288 if myStudyManager is None:
289 print "Warning: SALOMEDS.StudyManager has not been created !!!"
292 aListOfOpenStudies = myStudyManager.GetOpenStudies();
294 if len(aListOfOpenStudies) == 0 :
295 myStudy = myStudyManager.NewStudy("Study1")
297 myStudyName = aListOfOpenStudies[0]
298 myStudy = myStudyManager.GetStudyByName(myStudyName)
300 myStudyName = myStudy._get_Name()
302 myStudyId = myStudy._get_StudyId()