Salome HOME
9b1c236c9537a2a9ed0eb5a78b12d1e52d0008c4
[modules/gui.git] / src / GuiHelpers / SALOME_AppStudyEditor.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author: Guillaume Boulant (EDF/R&D)
21
22 #include "SALOME_AppStudyEditor.hxx"
23 #include "SALOME_GuiServices.hxx"
24
25 #include <SalomeApp_Study.h>
26 #include <SALOME_ListIO.hxx>
27 #include <LightApp_SelectionMgr.h>
28
29 SALOME_AppStudyEditor::SALOME_AppStudyEditor(SalomeApp_Application * salomeApp)
30   : SALOME_StudyEditor()
31 {
32   _salomeApp = salomeApp;
33 }
34
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();
40     }
41   }
42   return SALOMEDS::SObject::_nil();
43 }
44
45 /**
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
49  * active study.
50  */
51 SALOME_StudyEditor::SObjectList * SALOME_AppStudyEditor::getSelectedObjects() {
52
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.
59
60   LightApp_SelectionMgr* aSelectionMgr = _salomeApp->selectionMgr();
61   SALOME_ListIO selectedIObjects;
62   aSelectionMgr->selectedObjects(selectedIObjects);
63   /* 
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.
72    */
73
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);
80     }
81   }
82
83   return listOfSObject;
84 }