1 // Copyright (C) 2007-2016 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_AppStudyEditor.hxx"
24 #include <SalomeApp_Study.h>
25 #include <SALOME_ListIO.hxx>
26 #include <LightApp_SelectionMgr.h>
28 SALOME_AppStudyEditor::SALOME_AppStudyEditor(SalomeApp_Application * salomeApp)
29 : SALOME_StudyEditor()
31 _salomeApp = salomeApp;
36 * This updates the editor with the current active study. If the
37 * active study id is identical to the study id currently associated
38 * to this object, then no update is performed.
40 int SALOME_AppStudyEditor::updateActiveStudy() {
41 int activeStudyId = SALOME_AppStudyEditor::getActiveStudyId(_salomeApp);
42 if ( activeStudyId != this->getStudyId() ) {
43 this->setStudyById(activeStudyId);
49 int SALOME_AppStudyEditor::getActiveStudyId(SalomeApp_Application * salomeApp) {
50 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*> (salomeApp->activeStudy());
51 _PTR(Study) aCStudy = appStudy->studyDS();
52 int studyId = aCStudy->StudyId();
56 SALOMEDS::SObject_ptr SALOME_AppStudyEditor::IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject) {
57 if (!iobject.IsNull()) {
58 if (iobject->hasEntry()) {
59 SALOMEDS::SObject_var sobject = _study->FindObjectID(iobject->getEntry());
60 return sobject._retn();
63 return SALOMEDS::SObject::_nil();
67 * This function creates a list of all the "study objects" (SObject)
68 * that map with the selection in the object browser (the "interactive
69 * objects", IObjects). Please note that the objects belongs to the
72 SALOME_StudyEditor::SObjectList * SALOME_AppStudyEditor::getSelectedObjects() {
74 // _GBO_: please note that the use of this function can be
75 // underoptimal in the case where the number of selected objects is
76 // high, because we create a vector list of SObjects while the list
77 // of IObject can be processed directly. In the case where a high
78 // number of objects is selected (~1000), it's certainly better to
79 // use directly the SALOME_ListIO and iterators on it.
81 LightApp_SelectionMgr* aSelectionMgr = _salomeApp->selectionMgr();
82 SALOME_ListIO selectedIObjects;
83 aSelectionMgr->selectedObjects(selectedIObjects);
85 * This returns a list containing the selected objects of the objects
86 * browser. Please note that the objects of the browser ARE NOT the
87 * objects of the study. What is returned by this function is a list
88 * of "interactive objects" (IObject) which are objects of the
89 * graphical context. Each of this IObject is characterized by an
90 * entry string that corresponds to the entry string of an associated
91 * "study object" (SObject) in the active study. The mapping can be
92 * done using the function IObjectToSObject.
95 SObjectList * listOfSObject = new SObjectList();
96 SALOME_ListIteratorOfListIO It (selectedIObjects);
97 for (; It.More(); It.Next()) {
98 SALOMEDS::SObject_ptr sobject = this->IObjectToSObject(It.Value());
99 if (!sobject->_is_nil()) {
100 listOfSObject->push_back(sobject);
104 return listOfSObject;