Back to index

salome-kernel  6.5.0
SALOME_StudyEditor.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 // Author: Guillaume Boulant (EDF/R&D) 
00020 
00021 #include "SALOME_StudyEditor.hxx"
00022 #include "SALOME_KernelServices.hxx"
00023 
00025 SALOME_StudyEditor::SALOME_StudyEditor() {
00026 }
00027 
00028 void SALOME_StudyEditor::setStudy(SALOMEDS::Study_ptr study) {
00029   _study = study;
00030   _sbuilder = _study->NewBuilder();    
00031 }
00032 
00033 void SALOME_StudyEditor::setStudyById(int studyId) {
00034   this->setStudy(KERNEL::getStudyManager()->GetStudyByID(studyId));
00035 }
00036 
00037 int SALOME_StudyEditor::getStudyId() {
00038   if ( _study->_is_nil() ) return UNDEFINED; 
00039   return _study->StudyId();
00040 }
00041 
00042 SALOME_StudyEditor::SALOME_StudyEditor(int studyId) {
00043   this->setStudyById(studyId);
00044 }
00045 SALOME_StudyEditor::SALOME_StudyEditor(SALOMEDS::Study_ptr study) {
00046   this->setStudy(study);
00047 }
00048 
00049 SALOMEDS::SObject_ptr SALOME_StudyEditor::newObject(SALOMEDS::SObject_ptr parent) {
00050   return _sbuilder->NewObject(parent);
00051 }
00052 
00053 SALOMEDS::SObject_ptr SALOME_StudyEditor::findObject(const char * entry) {
00054   SALOMEDS::SObject_var sobject = _study->FindObjectID(entry);
00055   return sobject._retn();
00056 }
00057 
00058 SALOMEDS::SComponent_ptr SALOME_StudyEditor::newRoot(const char * moduleName) {
00059   SALOMEDS::SComponent_var sroot = findRoot(moduleName);
00060   if ( sroot->_is_nil() ) {
00061     sroot = _sbuilder->NewComponent(moduleName);
00062     _sbuilder->SetName(sroot,moduleName);
00063   }
00064   return sroot._retn();
00065 }
00066 
00067 bool SALOME_StudyEditor::bindEngine(SALOMEDS::SComponent_var studyRoot,
00068                           Engines::EngineComponent_var engine)
00069 {
00070   // WARN: The engine should be associated to the SComponent IF
00071   // AND ONLY IF it is a SALOMEDS::Driver. Otherwise, there is no
00072   // need to do that, and it could even lead to exception
00073   // raising (eh, you work on SALOME isn't it?)
00074   SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(engine);
00075   if ( driver->_is_nil() || studyRoot->_is_nil() ) return false;
00076   _sbuilder->DefineComponentInstance(studyRoot, engine);
00077   return true;
00078 }
00079 
00080 SALOMEDS::SComponent_ptr SALOME_StudyEditor::findRoot(const char * moduleName) {
00081   return _study->FindComponent(moduleName);
00082 }
00083 
00084 void SALOME_StudyEditor::setName(SALOMEDS::SObject_var sobject, const char * value) {
00085   _sbuilder->SetName(sobject,value);  
00086 }
00087 const char * SALOME_StudyEditor::getName(SALOMEDS::SObject_var sobject) {
00088   if (sobject->_is_nil()) return NULL;
00089   return sobject->GetName();
00090 }
00091 
00102 void SALOME_StudyEditor::setIcon(SALOMEDS::SObject_var sobject, const char * resourcename) {
00103   SALOMEDS::GenericAttribute_var anAttr;
00104   SALOMEDS::AttributePixMap_var aPixmap;
00105   anAttr = _sbuilder->FindOrCreateAttribute(sobject, "AttributePixMap");
00106   aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
00107   aPixmap->SetPixMap(resourcename);
00108 }
00109 
00110 //
00111 // MEM: AttributeParameter
00112 // Note that the AttributeParameter is a multitype dictionnary whose
00113 // keys are the names specified when setting the value
00114 //
00115 
00120 void SALOME_StudyEditor::setParameterInt(SALOMEDS::SObject_var sobject, const char * name, int value) { 
00121   SALOMEDS::GenericAttribute_var anAttr;
00122   SALOMEDS::AttributeParameter_var aParam;
00123   anAttr = _sbuilder->FindOrCreateAttribute(sobject, "AttributeParameter");
00124   aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
00125   aParam->SetInt(name,value);
00126 }
00127 
00128 int SALOME_StudyEditor::getParameterInt(SALOMEDS::SObject_var sobject, const char * name) {
00129   if (sobject->_is_nil()) return UNDEFINED;
00130 
00131   SALOMEDS::GenericAttribute_var anAttr;
00132   SALOMEDS::AttributeParameter_var aParam;
00133   if ( sobject->FindAttribute(anAttr,"AttributeParameter") ) {
00134     aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
00135     return aParam->GetInt(name);
00136   }
00137   return UNDEFINED;
00138 }
00139 
00144 void SALOME_StudyEditor::setParameterBool(SALOMEDS::SObject_var sobject, const char * name, bool value) {
00145   SALOMEDS::GenericAttribute_var anAttr;
00146   SALOMEDS::AttributeParameter_var aParam;
00147   anAttr = _sbuilder->FindOrCreateAttribute(sobject, "AttributeParameter");
00148   aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
00149   aParam->SetBool(name,value);
00150 }
00151 
00152 bool SALOME_StudyEditor::getParameterBool(SALOMEDS::SObject_var sobject, const char * name) {
00153   if (sobject->_is_nil()) return false;
00154   // _GBO_ Q: Maybe it's better in this case to raise an exception?
00155 
00156   SALOMEDS::GenericAttribute_var anAttr;
00157   SALOMEDS::AttributeParameter_var aParam;
00158   if ( sobject->FindAttribute(anAttr,"AttributeParameter") ) {
00159     aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
00160     return aParam->GetBool(name);
00161   }
00162   return false;
00163 
00164 }