1 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 # File : salomedsgui.py
23 # Author : Paul RASCLE, EDF
26 #--------------------------------------------------------------------------
34 Study (SALOMEDS) interface from python gui (ex: IAPP embedded PyQt GUI)
36 _myStudyManager = None
43 self._myStudyManager = salome.myStudyManager
44 self._myStudy = salome.myStudy
45 self._myBuilder = self._myStudy.NewBuilder()
47 def enregistre(self,myModule):
48 if self._father is None:
49 father = self._myStudy.FindComponent(myModule)
51 father = self._myBuilder.NewComponent(myModule)
52 A1 = self._myBuilder.FindOrCreateAttribute(father,"AttributeName")
53 FName = A1._narrow(SALOMEDS.AttributeName)
54 FName.SetValue(myModule)
56 self._component = myModule
57 return self._father.GetID()
59 def createItemInStudy(self,fatherId,objectName):
61 if self._component is not None:
62 listSO = self._myStudy.FindObjectByName(objectName,self._component)
64 father = self._myStudy.FindObjectID(fatherId)
65 newObj = self._myBuilder.NewObject(father)
66 A1= self._myBuilder.FindOrCreateAttribute(newObj,"AttributeName")
67 FName = A1._narrow(SALOMEDS.AttributeName)
68 FName.SetValue(objectName)
69 objId = newObj.GetID()
72 def getReference(self,objectId):
73 mySO = self._myStudy.FindObjectID(objectId)
74 boo,RefSO = mySO.ReferencedObject()
76 objectId=RefSO.GetID()
79 def addReference(self,fatherId,refId):
80 father = self._myStudy.FindObjectID(fatherId)
81 ref = self._myStudy.FindObjectID(refId)
82 newObj = self._myBuilder.NewObject(father)
83 A1 = self._myBuilder.FindOrCreateAttribute(ref,"AttributeName")
84 FName = A1._narrow(SALOMEDS.AttributeName)
85 Name_ref = FName.Value()
86 path_father , none = string.split(self._myStudy.GetObjectPath(ref),Name_ref)
87 path_father , none = os.path.split(path_father)
88 #print "salomedsgui::addReference : path_father_ref = ",path_father
89 #print "salomedsgui::addReference : Path_father = ",self._myStudy.GetObjectPath(father)
90 if self._myStudy.GetObjectPath(father) != path_father :
91 self._myBuilder.Addreference(newObj,ref)
93 def setExternalFileAttribute(self,objectId,filetype,filename):
94 mySO = self._myStudy.FindObjectID(objectId)
95 A1 = self._myBuilder.FindOrCreateAttribute(mySO,"AttributeExternalFileDef")
96 AFileName = A1._narrow(SALOMEDS.AttributeExternalFileDef)
97 AFileName.SetValue(filename)
99 A2 = self._myBuilder.FindOrCreateAttribute(mySO,"AttributeFileType")
100 AFileType = A2._narrow(SALOMEDS.AttributeFileType)
102 AFileType.SetValue(filetype)
105 def getExternalFileAttribute(self,filetype, objectId):
108 mySO = self._myStudy.FindObjectID(objectId)
109 boo,RefSO = mySO.ReferencedObject()
115 boo,attr = self._myBuilder.FindAttribute(mySO,"AttributeFileType")
116 print "AttributeFileType ",boo
122 boo,attr = self._myBuilder.FindAttribute(mySO,"AttributeExternalFileDef")
127 return (boo,attribute)
129 def getNameAttribute(self, objectId):
130 mySO = self._myStudy.FindObjectID(objectId)
131 boo,RefSO = mySO.ReferencedObject()
134 boo,attr = self._myBuilder.FindAttribute(mySO,"AttributeName")
142 def getChildren(self, objectId):
144 mySO = self._myStudy.FindObjectID(objectId)
145 boo,RefSO = mySO.ReferencedObject()
148 it = self._myStudy.NewChildIterator(mySO)
151 children.append(CSO.GetID())