Salome HOME
c128219af814ce292cbddd99cb8985980500fc08
[modules/gui.git] / src / LightApp / LightApp_Plot2dSelector.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, 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 #include "LightApp_Plot2dSelector.h"
21
22 #include "LightApp_DataOwner.h"
23 #include "LightApp_DataObject.h"
24 #include "LightApp_Application.h"
25 #include "SUIT_SelectionMgr.h"
26
27 #include <SPlot2d_ViewModel.h>
28
29 #include <SALOME_ListIO.hxx>
30
31 /*!
32   Constructor
33 */
34 LightApp_Plot2dSelector::LightApp_Plot2dSelector( Plot2d_Viewer* v, SUIT_SelectionMgr* mgr )
35   : SUIT_Selector( mgr, v ),
36     myViewer(v)
37 {
38   if ( v )
39     connect( v, SIGNAL( legendSelected( const QString& ) ), this, SLOT( onSelectionChanged( const QString& ) ) );
40     connect( v, SIGNAL( clearSelected() ), this, SLOT( onClearSelected( ) ) );
41 }
42
43 /*!
44   Destructor
45 */
46 LightApp_Plot2dSelector::~LightApp_Plot2dSelector()
47 {
48 }
49
50 /*!
51   Gets selection.
52 */
53 void LightApp_Plot2dSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
54 {
55   if( !myCurEntry.isNull() )
56     theList.append( new LightApp_DataOwner( new SALOME_InteractiveObject(qPrintable(myCurEntry),"","") ) );
57 }
58
59 /*!Sets selection.*/
60 void LightApp_Plot2dSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
61 {
62   SALOME_ListIO anIOList;
63   for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) {
64     const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
65     if ( owner  ) {
66       if( !owner->IO().IsNull() ) {
67         anIOList.Append(owner->IO());
68       } else if ( !owner->entry().isEmpty() ) {
69         anIOList.Append( new SALOME_InteractiveObject(qPrintable(owner->entry()),"","") );
70       }      
71     }
72   }
73   SPlot2d_Viewer* v = dynamic_cast<SPlot2d_Viewer*>(myViewer);
74
75   if(v)
76     v->setObjectsSelected(anIOList);
77 }
78
79 /*!On selection changed.*/
80 void LightApp_Plot2dSelector::onSelectionChanged( const QString& entry )
81 {
82   myCurEntry = entry;
83   selectionChanged();
84   myCurEntry = QString();
85 }
86
87 /*!On clear selected.*/
88 void LightApp_Plot2dSelector::onClearSelected( ) 
89 {
90         selectionMgr()->clearSelected();
91 }