Salome HOME
d30549c99e4276adea882525805bd223ef5db04e
[modules/eficas.git] / src / EFICASGUI / salomedsgui.py
1 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3
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. 
8
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. 
13
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 
17
18 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 #
20 #
21 #
22 #  File   : salomedsgui.py
23 #  Author : Paul RASCLE, EDF
24 #  Module : KERNEL
25 #
26 #--------------------------------------------------------------------------
27
28 import salome
29 import SALOMEDS
30 import string,os
31
32 class guiDS:
33     """
34     Study (SALOMEDS) interface from python gui (ex: IAPP embedded PyQt GUI)
35     """
36     _myStudyManager = None
37     _myStudy = None
38     _myBuilder = None
39     _father = None
40     _component = None
41
42     def __init__(self):
43         self._myStudyManager = salome.myStudyManager
44         self._myStudy = salome.myStudy
45         self._myBuilder = self._myStudy.NewBuilder()
46
47     def enregistre(self,myModule):
48         if self._father is None:
49             father = self._myStudy.FindComponent(myModule)
50             if father is None:
51                 father = self._myBuilder.NewComponent(myModule)
52                 A1 = self._myBuilder.FindOrCreateAttribute(father,"AttributeName")
53                 FName = A1._narrow(SALOMEDS.AttributeName)
54                 FName.SetValue(myModule)
55             self._father   = father
56             self._component = myModule
57         return self._father.GetID()
58
59     def createItemInStudy(self,fatherId,objectName):
60         objId = None
61         if self._component is not None:
62             listSO = self._myStudy.FindObjectByName(objectName,self._component)
63             if len(listSO) == 0:
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()
70         return objId
71
72     def getReference(self,objectId):
73         mySO = self._myStudy.FindObjectID(objectId)
74         boo,RefSO = mySO.ReferencedObject()
75         if boo:
76             objectId=RefSO.GetID()
77         return objectId        
78
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)
92
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)
98         print filename
99         A2 = self._myBuilder.FindOrCreateAttribute(mySO,"AttributeFileType")
100         AFileType = A2._narrow(SALOMEDS.AttributeFileType)
101         print filetype
102         AFileType.SetValue(filetype)
103         print filetype
104                           
105     def getExternalFileAttribute(self,filetype, objectId):
106         print filetype
107         print objectId
108         mySO = self._myStudy.FindObjectID(objectId)
109         boo,RefSO = mySO.ReferencedObject()
110         if boo:
111             print RefSO
112             mySO = RefSO
113         print mySO
114         val=""
115         boo,attr =  self._myBuilder.FindAttribute(mySO,"AttributeFileType")
116         print "AttributeFileType ",boo
117         if boo:
118             boo=0
119             val=attr.Value()
120             print val
121         if val==filetype:
122             boo,attr =  self._myBuilder.FindAttribute(mySO,"AttributeExternalFileDef")
123         val=""
124         if boo: 
125              val=attr.Value()
126         attribute=val
127         return (boo,attribute)
128
129     def getNameAttribute(self, objectId):
130         mySO = self._myStudy.FindObjectID(objectId)
131         boo,RefSO = mySO.ReferencedObject()
132         if boo:
133             mySO = RefSO
134         boo,attr =  self._myBuilder.FindAttribute(mySO,"AttributeName")
135         val=""
136         if boo:
137             val=attr.Value()
138             print val
139         return val
140             
141             
142     def getChildren(self, objectId):
143         children=[]
144         mySO = self._myStudy.FindObjectID(objectId)
145         boo,RefSO = mySO.ReferencedObject()
146         if boo:
147             mySO = RefSO
148         it = self._myStudy.NewChildIterator(mySO)
149         while it.More():
150             CSO = it.Value()
151             children.append(CSO.GetID())
152             it.Next()
153         print children
154         return children