Salome HOME
1) Data model draft.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ObjSelector.cxx
1 // Copyright (C) 2007-2013  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.
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 "HYDROGUI_ObjSelector.h"
24 #include "HYDROGUI_Module.h"
25
26 #include <GraphicsView_Object.h>
27 #include <LightApp_Application.h>
28 #include <LightApp_GVSelector.h>
29 #include <LightApp_SelectionMgr.h>
30
31 #include <QLayout>
32 #include <QLineEdit>
33 #include <QToolButton>
34
35 HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, QWidget* theParent )
36 : QAbstractButton( theParent ), myModule( theModule )
37 {
38   QHBoxLayout* aLayout = new QHBoxLayout( this );
39   myBtn = new QToolButton( this );
40   myBtn->setCheckable( true );
41   myBtn->setChecked( false );
42   myObjName = new QLineEdit( this );
43   myObjName->setReadOnly( true );
44   aLayout->addWidget( myBtn, 0 );
45   aLayout->addWidget( myObjName, 1 );
46
47   SUIT_SelectionMgr* aSelMgr = theModule->getApp()->selectionMgr();
48
49   connect( myBtn, SIGNAL( toggled( bool ) ), this, SLOT( OnToggled( bool ) ) );
50   connect( aSelMgr, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
51 }
52
53 HYDROGUI_ObjSelector::~HYDROGUI_ObjSelector()
54 {
55 }
56
57 void HYDROGUI_ObjSelector::paintEvent( QPaintEvent* )
58 {
59 }
60
61 bool HYDROGUI_ObjSelector::hitButton( const QPoint& thePnt ) const
62 {
63   return false;
64 }
65
66 void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
67 {
68   if( !isChecked )
69     return;
70
71   QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
72   foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
73     if( aSelector != this )
74       aSelector->myBtn->setChecked( false );
75
76   if( isChecked )
77     OnSelectionChanged();
78 }
79
80 void HYDROGUI_ObjSelector::OnSelectionChanged()
81 {
82   if( !myBtn->isChecked() )
83     return;
84
85   SUIT_SelectionMgr* aSelMgr = myModule->getApp()->selectionMgr();
86   SUIT_DataOwnerPtrList anOwners;
87   aSelMgr->selected( anOwners );
88
89   QString anObjName;
90   foreach( SUIT_DataOwner* anOwner, anOwners )
91   {
92     LightApp_GVDataOwner* aGrDOwner = dynamic_cast<LightApp_GVDataOwner*>( anOwner );
93     if( aGrDOwner )
94     {
95       anObjName = aGrDOwner->object()->getName();
96       break;
97     }
98   }
99   myObjName->setText( anObjName );
100 }
101
102 QString HYDROGUI_ObjSelector::GetName() const
103 {
104   return myObjName->text();
105 }