1 // Copyright (C) 2007-2021 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"
23 #include "SALOME_GuiServices.hxx"
25 #include <SalomeApp_Study.h>
26 #include <SALOME_ListIO.hxx>
27 #include <LightApp_SelectionMgr.h>
29 SALOME_AppStudyEditor::SALOME_AppStudyEditor(SalomeApp_Application * salomeApp)
30 : SALOME_StudyEditor()
32 _salomeApp = salomeApp;
35 SALOMEDS::SObject_ptr SALOME_AppStudyEditor::IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject) {
36 if (!iobject.IsNull()) {
37 if (iobject->hasEntry()) {
38 SALOMEDS::SObject_var sobject = GUI::getStudyServant()->FindObjectID(iobject->getEntry());
39 return sobject._retn();
42 return SALOMEDS::SObject::_nil();
46 * This function creates a list of all the "study objects" (SObject)
47 * that map with the selection in the object browser (the "interactive
48 * objects", IObjects). Please note that the objects belongs to the
51 SALOME_StudyEditor::SObjectList * SALOME_AppStudyEditor::getSelectedObjects() {
53 // _GBO_: please note that the use of this function can be
54 // underoptimal in the case where the number of selected objects is
55 // high, because we create a vector list of SObjects while the list
56 // of IObject can be processed directly. In the case where a high
57 // number of objects is selected (~1000), it's certainly better to
58 // use directly the SALOME_ListIO and iterators on it.
60 LightApp_SelectionMgr* aSelectionMgr = _salomeApp->selectionMgr();
61 SALOME_ListIO selectedIObjects;
62 aSelectionMgr->selectedObjects(selectedIObjects);
64 * This returns a list containing the selected objects of the objects
65 * browser. Please note that the objects of the browser ARE NOT the
66 * objects of the study. What is returned by this function is a list
67 * of "interactive objects" (IObject) which are objects of the
68 * graphical context. Each of this IObject is characterized by an
69 * entry string that corresponds to the entry string of an associated
70 * "study object" (SObject) in the active study. The mapping can be
71 * done using the function IObjectToSObject.
74 SObjectList * listOfSObject = new SObjectList();
75 SALOME_ListIteratorOfListIO It (selectedIObjects);
76 for (; It.More(); It.Next()) {
77 SALOMEDS::SObject_ptr sobject = this->IObjectToSObject(It.Value());
78 if (!sobject->_is_nil()) {
79 listOfSObject->push_back(sobject);