Back to index

salome-gui  6.5.0
SALOME_AppStudyEditor.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 
00020 // Author: Guillaume Boulant (EDF/R&D)
00021 
00022 #include "SALOME_AppStudyEditor.hxx"
00023 
00024 #include <SalomeApp_Study.h>
00025 #include <SALOME_ListIO.hxx>
00026 #include <LightApp_SelectionMgr.h>
00027 #include <SALOME_ListIteratorOfListIO.hxx>
00028 
00029 SALOME_AppStudyEditor::SALOME_AppStudyEditor(SalomeApp_Application * salomeApp)
00030   : SALOME_StudyEditor()
00031 {
00032   _salomeApp = salomeApp;
00033   updateActiveStudy();
00034 }
00035 
00041 int SALOME_AppStudyEditor::updateActiveStudy() {
00042   int activeStudyId = SALOME_AppStudyEditor::getActiveStudyId(_salomeApp);
00043   if ( activeStudyId != this->getStudyId() ) {
00044     this->setStudyById(activeStudyId);
00045   }
00046   return activeStudyId;
00047 }
00048 
00049 // GUI context only
00050 int SALOME_AppStudyEditor::getActiveStudyId(SalomeApp_Application * salomeApp) {
00051   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*> (salomeApp->activeStudy());
00052   _PTR(Study) aCStudy = appStudy->studyDS();
00053   int studyId = aCStudy->StudyId();
00054   return studyId;
00055 }
00056 
00057 SALOMEDS::SObject_ptr SALOME_AppStudyEditor::IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject) {
00058   if (!iobject.IsNull()) {
00059     if (iobject->hasEntry()) {
00060       SALOMEDS::SObject_var sobject = _study->FindObjectID(iobject->getEntry());
00061       return sobject._retn();
00062     }
00063   }
00064   return SALOMEDS::SObject::_nil();
00065 }
00066 
00073 SALOME_StudyEditor::SObjectList * SALOME_AppStudyEditor::getSelectedObjects() {
00074 
00075   // _GBO_: please note that the use of this function can be
00076   // underoptimal in the case where the number of selected objects is
00077   // high, because we create a vector list of SObjects while the list
00078   // of IObject can be processed directly. In the case where a high
00079   // number of objects is selected (~1000), it's certainly better to
00080   // use directly the SALOME_ListIO and iterators on it.
00081 
00082   LightApp_SelectionMgr* aSelectionMgr = _salomeApp->selectionMgr();
00083   SALOME_ListIO selectedIObjects;
00084   aSelectionMgr->selectedObjects(selectedIObjects);
00085   /* 
00086    * This returns a list containing the selected objects of the objects
00087    * browser. Please note that the objects of the browser ARE NOT the
00088    * objects of the study. What is returned by this function is a list
00089    * of "interactive objects" (IObject) which are objects of the
00090    * graphical context. Each of this IObject is characterized by an
00091    * entry string that corresponds to the entry string of an associated
00092    * "study object" (SObject) in the active study. The mapping can be
00093    * done using the function IObjectToSObject.
00094    */
00095 
00096   SObjectList * listOfSObject = new SObjectList();
00097   SALOME_ListIteratorOfListIO It (selectedIObjects);
00098   for (; It.More(); It.Next()) {
00099     SALOMEDS::SObject_ptr sobject = this->IObjectToSObject(It.Value());
00100     if (!sobject->_is_nil()) {
00101       listOfSObject->push_back(sobject);
00102     }
00103   }
00104 
00105   return listOfSObject;
00106 }