Salome HOME
Fuse and Cut operations.
[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
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27
28 #include <GraphicsView_Object.h>
29
30 #include <LightApp_Application.h>
31 #include <LightApp_DataOwner.h>
32 #include <LightApp_GVSelector.h>
33 #include <LightApp_SelectionMgr.h>
34
35 #include <QLayout>
36 #include <QLineEdit>
37 #include <QToolButton>
38
39 HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule, QWidget* theParent )
40 : QAbstractButton( theParent ), myModule( theModule )
41 {
42   QHBoxLayout* aLayout = new QHBoxLayout( this );
43   myBtn = new QToolButton( this );
44   myBtn->setCheckable( true );
45   myBtn->setChecked( false );
46   myObjName = new QLineEdit( this );
47   myObjName->setReadOnly( true );
48   aLayout->addWidget( myBtn, 0 );
49   aLayout->addWidget( myObjName, 1 );
50
51   SUIT_SelectionMgr* aSelMgr = theModule->getApp()->selectionMgr();
52
53   connect( myBtn, SIGNAL( toggled( bool ) ), this, SLOT( OnToggled( bool ) ) );
54   connect( aSelMgr, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
55 }
56
57 HYDROGUI_ObjSelector::~HYDROGUI_ObjSelector()
58 {
59 }
60
61 void HYDROGUI_ObjSelector::paintEvent( QPaintEvent* )
62 {
63 }
64
65 bool HYDROGUI_ObjSelector::hitButton( const QPoint& thePnt ) const
66 {
67   return false;
68 }
69
70 void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
71 {
72   if( !isChecked )
73     return;
74
75   QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
76   foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
77     if( aSelector != this )
78       aSelector->myBtn->setChecked( false );
79
80   if( isChecked )
81     OnSelectionChanged();
82 }
83
84 void HYDROGUI_ObjSelector::OnSelectionChanged()
85 {
86   if( !myBtn->isChecked() )
87     return;
88
89   SUIT_SelectionMgr* aSelMgr = myModule->getApp()->selectionMgr();
90   SUIT_DataOwnerPtrList anOwners;
91   aSelMgr->selected( anOwners );
92
93   HYDROGUI_DataModel* aModel = myModule->getDataModel();
94
95   QString anObjName;
96   foreach( SUIT_DataOwner* anOwner, anOwners )
97   {
98     LightApp_DataOwner* aGrDOwner = dynamic_cast<LightApp_DataOwner*>( anOwner );
99     if( aGrDOwner )
100     {
101       QString anEntry = aGrDOwner->entry();
102       Handle(HYDROData_Object) anObject = aModel->objectByEntry( anEntry, KIND_IMAGE );
103       if( !anObject.IsNull() )
104       {
105         anObjName = anObject->GetName();
106         break;
107       }
108     }
109   }
110   myObjName->setText( anObjName );
111 }
112
113 QString HYDROGUI_ObjSelector::GetName() const
114 {
115   return myObjName->text();
116 }