Salome HOME
fd72ce5a102ce97c6cca3045a52fb1f16cdfb0d1
[modules/geom.git] / src / GEOM_SWIG_WITHIHM / GEOM_Swig_LocalSelector.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "GEOM_Swig_LocalSelector.h"
24 #include <SalomeApp_Study.h>
25 #include <SUIT_Desktop.h>
26 #include <SUIT_Session.h>
27 #include <GeometryGUI.h>
28 #include <SalomeApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
30 #include <SALOMEDSClient_definitions.hxx>
31 #include <vector>
32 #include <utilities.h>
33
34 GEOM_Swig_LocalSelector::GEOM_Swig_LocalSelector(QWidget* parent, SUIT_ViewWindow* wnd, const std::string& shapeEntry, int mode) :
35     GEOMBase_Helper(dynamic_cast<SUIT_Desktop*>(parent), wnd )
36 {
37   MESSAGE("GEOM_Swig_LocalSelector " << shapeEntry << " " << mode);
38   myObject = GEOM::GEOM_Object::_nil();
39   mySubShapesInd = new GEOM::short_array();
40   std::string shapeName = "aShape";
41
42   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(SUIT_Session::session()->activeApplication()->activeStudy());
43   if (study)
44   {
45     _PTR(Study) studyDS = study->studyDS();
46     _PTR(SObject) obj( studyDS->FindObjectID( shapeEntry ) );
47     if ( GeometryGUI::IsInGeomComponent( obj ))
48     {
49       CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(obj);
50       if (!CORBA::is_nil(corbaObj))
51       {
52         myObject = GEOM::GEOM_Object::_narrow(corbaObj);
53         shapeName = myObject->GetName();
54         MESSAGE("shapeName: " << shapeName);
55       }
56     }
57   }
58
59   std::list<int> modes;
60   modes.push_back(mode);
61   localSelection(shapeEntry, shapeName, modes);
62 }
63
64 GEOM_Swig_LocalSelector::~GEOM_Swig_LocalSelector()
65 {
66   MESSAGE("~GEOM_Swig_LocalSelector");
67 }
68
69 std::vector<int> GEOM_Swig_LocalSelector::getSelection()
70 {
71   MESSAGE("getSelection");
72   SalomeApp_Application* app = (SalomeApp_Application*)SUIT_Session::session()->activeApplication();
73   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
74   SALOME_ListIO aSelList;
75   aSelMgr->selectedObjects(aSelList);
76
77   TColStd_IndexedMapOfInteger aMap;
78   MESSAGE("aSelList.Extent(): " << aSelList.Extent());
79   if (aSelList.Extent() > 0)
80     {
81     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
82     aSelMgr->GetIndexes(anIO, aMap);
83     }
84
85   const int n = aMap.Extent();
86   std::vector<int> ids;
87   for (int i = 1; i <= n; i++)
88     ids.push_back(aMap(i));
89   for (int i =0; i < (int)ids.size(); i++)
90     {
91       MESSAGE("ids[" << i << "] = " << ids[i]);
92     }
93
94   return ids;
95 }
96