Salome HOME
python_test_driver.py declination of salome_test_driver.py for SSL mode (timeout...
[modules/kernel.git] / src / KernelHelpers / SALOME_StudyEditor.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author: Guillaume Boulant (EDF/R&D) 
21
22 #include "SALOME_StudyEditor.hxx"
23 #include "SALOME_KernelServices.hxx"
24
25 /** Canonic constructor. The object can't be used without a setStudy() */
26 SALOME_StudyEditor::SALOME_StudyEditor() {
27 }
28
29 SALOMEDS::StudyBuilder_var SALOME_StudyEditor::studyBuilder()
30 {
31   return KERNEL::getStudyServant()->NewBuilder();
32 }
33
34 SALOMEDS::SObject_ptr SALOME_StudyEditor::newObject(SALOMEDS::SObject_ptr parent) {
35   return studyBuilder()->NewObject(parent);
36 }
37
38 SALOMEDS::SObject_ptr SALOME_StudyEditor::findObject(const char * entry) {
39   SALOMEDS::SObject_var sobject = KERNEL::getStudyServant()->FindObjectID(entry);
40   return sobject._retn();
41 }
42
43 SALOMEDS::SComponent_ptr SALOME_StudyEditor::newRoot(const char * moduleName) {
44   SALOMEDS::SComponent_var sroot = findRoot(moduleName);
45   if ( sroot->_is_nil() ) {
46     sroot = studyBuilder()->NewComponent(moduleName);
47     studyBuilder()->SetName(sroot,moduleName);
48   }
49   return sroot._retn();
50 }
51
52 bool SALOME_StudyEditor::bindEngine(SALOMEDS::SComponent_var studyRoot,
53                              Engines::EngineComponent_var engine)
54 {
55   // WARN: The engine should be associated to the SComponent IF
56   // AND ONLY IF it is a SALOMEDS::Driver. Otherwise, there is no
57   // need to do that, and it could even lead to exception
58   // raising (eh, you work on SALOME isn't it?)
59   SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(engine);
60   if ( driver->_is_nil() || studyRoot->_is_nil() ) return false;
61   studyBuilder()->DefineComponentInstance(studyRoot, engine);
62   return true;
63 }
64
65 SALOMEDS::SComponent_ptr SALOME_StudyEditor::findRoot(const char * moduleName) {
66   return KERNEL::getStudyServant()->FindComponent(moduleName);
67 }
68
69 void SALOME_StudyEditor::setName(SALOMEDS::SObject_var sobject, const char * value) {
70   studyBuilder()->SetName(sobject,value);  
71 }
72 const char * SALOME_StudyEditor::getName(SALOMEDS::SObject_var sobject) {
73   if (sobject->_is_nil()) return NULL;
74   return sobject->GetName();
75 }
76
77 /**
78  * This function specifies which resource file is to be used to
79  * associate an icon to the specified object. Note that even if the
80  * icon as no sens outside the GUI context, it can be defined here
81  * because only the resource name is provided. The effective rendering
82  * is done in the object browser of course, and use this string
83  * attribute. WARN: note that the resource name is supposed to be the
84  * base name of a file managed by the SALOME resource manager (i.e. a
85  * file located in the directory specified in the SalomeApp.xml).
86  */
87 void SALOME_StudyEditor::setIcon(SALOMEDS::SObject_var sobject, const char * resourcename) {
88   SALOMEDS::GenericAttribute_var anAttr;
89   SALOMEDS::AttributePixMap_var aPixmap;
90   anAttr = studyBuilder()->FindOrCreateAttribute(sobject, "AttributePixMap");
91   aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
92   aPixmap->SetPixMap(resourcename);
93 }
94
95 //
96 // MEM: AttributeParameter
97 // Note that the AttributeParameter is a multitype dictionary whose
98 // keys are the names specified when setting the value
99 //
100
101 /**
102  * Add a parameter attribute of type integer or simply set its value
103  * if it already exists.
104  */
105 void SALOME_StudyEditor::setParameterInt(SALOMEDS::SObject_var sobject, const char * name, int value) { 
106   SALOMEDS::GenericAttribute_var anAttr;
107   SALOMEDS::AttributeParameter_var aParam;
108   anAttr = studyBuilder()->FindOrCreateAttribute(sobject, "AttributeParameter");
109   aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
110   aParam->SetInt(name,value);
111 }
112
113 int SALOME_StudyEditor::getParameterInt(SALOMEDS::SObject_var sobject, const char * name) {
114   if (sobject->_is_nil()) return UNDEFINED;
115
116   SALOMEDS::GenericAttribute_var anAttr;
117   SALOMEDS::AttributeParameter_var aParam;
118   if ( sobject->FindAttribute(anAttr,"AttributeParameter") ) {
119     aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
120     return aParam->GetInt(name);
121   }
122   return UNDEFINED;
123 }
124
125 /**
126  * Add a parameter attribute of type boolean or simply set its value
127  * if it already exists.
128  */
129 void SALOME_StudyEditor::setParameterBool(SALOMEDS::SObject_var sobject, const char * name, bool value) {
130   SALOMEDS::GenericAttribute_var anAttr;
131   SALOMEDS::AttributeParameter_var aParam;
132   anAttr = studyBuilder()->FindOrCreateAttribute(sobject, "AttributeParameter");
133   aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
134   aParam->SetBool(name,value);
135 }
136
137 bool SALOME_StudyEditor::getParameterBool(SALOMEDS::SObject_var sobject, const char * name) {
138   if (sobject->_is_nil()) return false;
139   // _GBO_ Q: Maybe it's better in this case to raise an exception?
140
141   SALOMEDS::GenericAttribute_var anAttr;
142   SALOMEDS::AttributeParameter_var aParam;
143   if ( sobject->FindAttribute(anAttr,"AttributeParameter") ) {
144     aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
145     return aParam->GetBool(name);
146   }
147   return false;
148
149 }