Salome HOME
c1c23aeb05306fceb62ae648330bd8845d780081
[modules/gui.git] / src / LightApp / LightApp_PV3DSelector.cxx
1 // Copyright (C) 2007-2022  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 "LightApp_PV3DSelector.h"
24 #include "LightApp_DataOwner.h"
25
26 #include "SUIT_Desktop.h"
27
28 #ifndef DISABLE_PV3DVIEWER
29   #include "SPV3D_ViewModel.h"
30   #include "SPV3D_ViewManager.h"
31   #include "SPV3D_ViewWindow.h"
32   #include <vtkRenderer.h>
33 #endif
34
35 #ifndef DISABLE_SALOMEOBJECT
36   // #include "SALOME_Actor.h"
37   // #include "SALOME_ListIO.hxx"
38 #endif
39
40 #include <utilities.h>
41
42 #ifndef DISABLE_PV3DVIEWER
43 /*!
44   Constructor.
45 */
46 LightApp_PV3DSelector::LightApp_PV3DSelector( SPV3D_ViewModel* viewer, SUIT_SelectionMgr* mgr )
47 : SUIT_Selector( mgr, viewer ),
48   myViewer( viewer )
49 {
50   if ( myViewer )
51     connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
52 }
53
54 /*!
55   Gets viewer.
56 */
57 SPV3D_ViewModel* LightApp_PV3DSelector::viewer() const
58 {
59   return myViewer;
60 }
61
62 /*!
63   Gets type of salome PV3D viewer.
64 */
65 QString LightApp_PV3DSelector::type() const
66
67   return myViewer->getType(); 
68 }
69
70 #endif
71
72 /*!
73   On selection changed.
74 */
75 void LightApp_PV3DSelector::onSelectionChanged()
76 {
77   selectionChanged();
78 }
79
80 #ifndef DISABLE_PV3DVIEWER
81
82 /*!
83   Gets list of selected data owners.(output \a aList).
84 */
85 void LightApp_PV3DSelector::getSelection( SUIT_DataOwnerPtrList& /*aList*/ ) const
86 {
87   if ( !myViewer )
88     return;
89
90   if ( !myViewer->isSelectionEnabled() )
91     return;
92
93   // if(SUIT_ViewManager* aViewManager = myViewer->getViewManager()){
94   //   if(PV3DViewer_ViewManager* aViewMgr = dynamic_cast<PV3DViewer_ViewManager*>(aViewManager)){
95   //     if(PV3DViewer_ViewWindow* aView = dynamic_cast<PV3DViewer_ViewWindow*>(aViewMgr->getActiveView())){
96   //       if(SPV3D_Selector* aSelector = aView->GetSelector()){
97   //         const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
98   //         SALOME_ListIteratorOfListIO anIter(aListIO);
99   //         for(; anIter.More(); anIter.Next()){
100   //           Handle(SALOME_InteractiveObject) anIO = anIter.Value();
101   //           if(anIO->hasEntry())
102   //             aList.append(new LightApp_SPV3DDataOwner(anIO,aViewMgr->getDesktop()));
103   //         }
104   //       }
105   //     }
106   //   }
107   // }
108 }
109
110 /*!
111   Sets selection to selector from data owner list \a theList.
112 */
113 void LightApp_PV3DSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
114 {
115   if ( myViewer && ( theList.isEmpty() || myViewer->isSelectionEnabled() )) {
116     //if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager())
117     {
118     //  if(SPV3D_ViewWindow* aView = dynamic_cast<SPV3D_ViewWindow*>(aViewMgr->getActiveView()))
119       {
120         // if(PV3DViewer_Selector* aSelector = aView->GetSelector()){
121         //   SALOME_ListIO anAppendList;
122         //   const SALOME_ListIO& aStoredList = aSelector->StoredIObjects();
123         //   SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin();
124         //   for(; anIter != theList.end(); ++anIter) {
125         //     const SUIT_DataOwner* aDataOwner = (*anIter).get();
126         //     if(const LightApp_SPV3DDataOwner* anOwner = dynamic_cast<const LightApp_SPV3DDataOwner*>(aDataOwner))
127         //     {
128         //       MESSAGE("aSelector->SetSelectionMode("<<anOwner->GetMode()<<");");
129         //       aSelector->SetSelectionMode(anOwner->GetMode());
130         //       Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
131
132         //       aSelector->AddIObject(anIO);
133
134         //       anAppendList.Append(anIO);
135         //       aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false);
136         //     }
137         //     else if(const LightApp_DataOwner* anOwner = dynamic_cast<const LightApp_DataOwner*>(aDataOwner))
138         //     {
139         //       Handle(SALOME_InteractiveObject) anIO =
140         //         new SALOME_InteractiveObject(anOwner->entry().toUtf8(),"");
141         //       aSelector->AddIObject(anIO);
142         //       anAppendList.Append(anIO);
143         //     }
144         //   }
145         //   // To remove IOs, which is not selected.
146         //   QMap< QString, Handle( SALOME_InteractiveObject )> toRemove;
147         //   SALOME_ListIteratorOfListIO anIt( aStoredList );
148         //   for( ; anIt.More(); anIt.Next() )
149         //     if( !anIt.Value().IsNull() )
150         //       toRemove[ anIt.Value()->getEntry() ] = anIt.Value();
151
152         //   anIt = SALOME_ListIteratorOfListIO(anAppendList);
153         //   for( ; anIt.More(); anIt.Next() )
154         //     toRemove.remove( anIt.Value()->getEntry() );
155
156         //   QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(),
157         //     REnd = toRemove.end();
158         //   for( ; RIt!=REnd; RIt++ )
159         //     aSelector->RemoveIObject( RIt.value() );
160
161         //   aView->onSelectionChanged();
162         // }
163       }
164     }
165   }
166 }
167
168 #endif