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