1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Author: Guillaume Boulant (EDF/R&D)
22 #include "SALOME_StudyEditor.hxx"
23 #include "SALOME_KernelServices.hxx"
25 /** Canonic constructor. The object can't be used without a setStudy() */
26 SALOME_StudyEditor::SALOME_StudyEditor() {
27 _sbuilder = KERNEL::getStudyServant()->NewBuilder();
30 SALOMEDS::SObject_ptr SALOME_StudyEditor::newObject(SALOMEDS::SObject_ptr parent) {
31 return _sbuilder->NewObject(parent);
34 SALOMEDS::SObject_ptr SALOME_StudyEditor::findObject(const char * entry) {
35 SALOMEDS::SObject_var sobject = KERNEL::getStudyServant()->FindObjectID(entry);
36 return sobject._retn();
39 SALOMEDS::SComponent_ptr SALOME_StudyEditor::newRoot(const char * moduleName) {
40 SALOMEDS::SComponent_var sroot = findRoot(moduleName);
41 if ( sroot->_is_nil() ) {
42 sroot = _sbuilder->NewComponent(moduleName);
43 _sbuilder->SetName(sroot,moduleName);
48 bool SALOME_StudyEditor::bindEngine(SALOMEDS::SComponent_var studyRoot,
49 Engines::EngineComponent_var engine)
51 // WARN: The engine should be associated to the SComponent IF
52 // AND ONLY IF it is a SALOMEDS::Driver. Otherwise, there is no
53 // need to do that, and it could even lead to exception
54 // raising (eh, you work on SALOME isn't it?)
55 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(engine);
56 if ( driver->_is_nil() || studyRoot->_is_nil() ) return false;
57 _sbuilder->DefineComponentInstance(studyRoot, engine);
61 SALOMEDS::SComponent_ptr SALOME_StudyEditor::findRoot(const char * moduleName) {
62 return KERNEL::getStudyServant()->FindComponent(moduleName);
65 void SALOME_StudyEditor::setName(SALOMEDS::SObject_var sobject, const char * value) {
66 _sbuilder->SetName(sobject,value);
68 const char * SALOME_StudyEditor::getName(SALOMEDS::SObject_var sobject) {
69 if (sobject->_is_nil()) return NULL;
70 return sobject->GetName();
74 * This function specifies which resource file is to be used to
75 * associate an icon to the specified object. Note that even if the
76 * icon as no sens outside the GUI context, it can be defined here
77 * because only the resource name is provided. The effective rendering
78 * is done in the object browser of course, and use this string
79 * attribute. WARN: note that the resource name is supposed to be the
80 * base name of a file managed by the SALOME resource manager (i.e. a
81 * file located in the directory specified in the SalomeApp.xml).
83 void SALOME_StudyEditor::setIcon(SALOMEDS::SObject_var sobject, const char * resourcename) {
84 SALOMEDS::GenericAttribute_var anAttr;
85 SALOMEDS::AttributePixMap_var aPixmap;
86 anAttr = _sbuilder->FindOrCreateAttribute(sobject, "AttributePixMap");
87 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
88 aPixmap->SetPixMap(resourcename);
92 // MEM: AttributeParameter
93 // Note that the AttributeParameter is a multitype dictionary whose
94 // keys are the names specified when setting the value
98 * Add a parameter attribute of type integer or simply set its value
99 * if it already exists.
101 void SALOME_StudyEditor::setParameterInt(SALOMEDS::SObject_var sobject, const char * name, int value) {
102 SALOMEDS::GenericAttribute_var anAttr;
103 SALOMEDS::AttributeParameter_var aParam;
104 anAttr = _sbuilder->FindOrCreateAttribute(sobject, "AttributeParameter");
105 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
106 aParam->SetInt(name,value);
109 int SALOME_StudyEditor::getParameterInt(SALOMEDS::SObject_var sobject, const char * name) {
110 if (sobject->_is_nil()) return UNDEFINED;
112 SALOMEDS::GenericAttribute_var anAttr;
113 SALOMEDS::AttributeParameter_var aParam;
114 if ( sobject->FindAttribute(anAttr,"AttributeParameter") ) {
115 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
116 return aParam->GetInt(name);
122 * Add a parameter attribute of type boolean or simply set its value
123 * if it already exists.
125 void SALOME_StudyEditor::setParameterBool(SALOMEDS::SObject_var sobject, const char * name, bool value) {
126 SALOMEDS::GenericAttribute_var anAttr;
127 SALOMEDS::AttributeParameter_var aParam;
128 anAttr = _sbuilder->FindOrCreateAttribute(sobject, "AttributeParameter");
129 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
130 aParam->SetBool(name,value);
133 bool SALOME_StudyEditor::getParameterBool(SALOMEDS::SObject_var sobject, const char * name) {
134 if (sobject->_is_nil()) return false;
135 // _GBO_ Q: Maybe it's better in this case to raise an exception?
137 SALOMEDS::GenericAttribute_var anAttr;
138 SALOMEDS::AttributeParameter_var aParam;
139 if ( sobject->FindAttribute(anAttr,"AttributeParameter") ) {
140 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
141 return aParam->GetBool(name);