]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_OCCSelector.cxx
Salome HOME
750593296731d62ab2f7d1195845b7254b41a14f
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_OCCSelector.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_OCCSelector.h"
20
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_DataObject.h"
23 #include "HYDROGUI_Module.h"
24
25 #include <AIS_ListOfInteractive.hxx>
26 #include <AIS_ListIteratorOfListOfInteractive.hxx>
27
28 #include <LightApp_DataOwner.h>
29
30 HYDROGUI_OCCSelector::HYDROGUI_OCCSelector( HYDROGUI_Module*   theModule,
31                                             OCCViewer_Viewer*  theViewer,
32                                             SUIT_SelectionMgr* theSelMgr )
33 : LightApp_OCCSelector( theViewer, theSelMgr ),
34   myModule( theModule )
35 {
36 }
37
38 HYDROGUI_OCCSelector::~HYDROGUI_OCCSelector()
39 {
40 }
41
42 void HYDROGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
43 {
44   OCCViewer_Viewer* aViewer = viewer();
45   if ( !aViewer )
46     return;
47
48   Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext();
49   bool isLocalContext = aContext->HasOpenedContext();
50
51   AIS_ListOfInteractive aSelList;
52   aViewer->getSelectedObjects( aSelList );
53   for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() )
54     if ( !anIt.Value().IsNull() )
55     {
56       if ( !isLocalContext )
57         aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( entry( anIt.Value() ) ) ) );
58     }
59   // add externally selected objects
60   SUIT_DataOwnerPtrList::const_iterator anExtIter;
61   for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) {
62     aList.append(*anExtIter);
63   }
64 }
65
66 void HYDROGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
67 {
68   OCCViewer_Viewer* aViewer = viewer();
69   if ( !aViewer )
70     return;
71
72   Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext();
73   if ( aContext.IsNull() || aContext->HasOpenedContext() ) {
74     return;
75   }
76
77   //@MZN LightApp_OCCSelector::setSelection( aList );
78   QMap<QString, Handle(AIS_InteractiveObject)> aDisplayed;
79     
80   AIS_ListOfInteractive aDispList, aSelList;
81   aContext->DisplayedObjects( aDispList );
82
83   for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() )
84   {
85     QString entryStr = entry( it.Value() );
86     if ( !entryStr.isEmpty() )
87       aDisplayed.insert( entryStr, it.Value() );
88   }
89   
90   mySelectedExternals.clear();
91
92   for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
93   {
94     const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
95     if ( owner && aDisplayed.contains( owner->entry() ) )
96       aSelList.Append( aDisplayed[owner->entry()] );
97     else
98       mySelectedExternals.append(*itr);
99   }
100
101   //@MZNmyViewer->unHighlightAll( false );
102   aViewer->setObjectsSelected( aSelList );
103 }
104
105 QString HYDROGUI_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const
106 {
107   QString aRes;
108
109   if ( anAIS.IsNull() || !anAIS->HasOwner() )
110     return aRes;
111
112   Handle(HYDROData_Entity) anObj = 
113     Handle(HYDROData_Entity)::DownCast( anAIS->GetOwner() );
114   if ( !anObj.IsNull() )
115     aRes = HYDROGUI_DataObject::dataObjectEntry( anObj );
116
117   return aRes;
118 }