Salome HOME
Fix for the bug #42: point C is not activated, but point C is shown in preview in...
[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 #include "HYDROGUI_Tool.h"
28
29 #include <GraphicsView_Object.h>
30
31 #include <LightApp_Application.h>
32 #include <LightApp_GVSelector.h>
33 #include <LightApp_SelectionMgr.h>
34
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37
38 #include <QLayout>
39 #include <QLineEdit>
40 #include <QToolButton>
41
42 HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule,
43                                             const ObjectKind theObjectKind,
44                                             QWidget* theParent )
45 : QAbstractButton( theParent ),
46   myObjectKind( theObjectKind ),
47   myModule( theModule )
48 {
49   QHBoxLayout* aLayout = new QHBoxLayout( this );
50   aLayout->setMargin( 0 );
51   aLayout->setSpacing( 5 );
52   myBtn = new QToolButton( this );
53   myBtn->setCheckable( true );
54   myBtn->setChecked( false );
55   myObjName = new QLineEdit( this );
56   myObjName->setReadOnly( true );
57   aLayout->addWidget( myBtn, 0 );
58   aLayout->addWidget( myObjName, 1 );
59
60   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
61   myBtn->setIcon( QIcon( aResMgr->loadPixmap( "HYDRO", tr( "SELECT_ICO" ) ) ) );
62
63   SUIT_SelectionMgr* aSelMgr = theModule->getApp()->selectionMgr();
64
65   connect( myBtn, SIGNAL( toggled( bool ) ), this, SLOT( OnToggled( bool ) ) );
66   connect( aSelMgr, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
67 }
68
69 HYDROGUI_ObjSelector::~HYDROGUI_ObjSelector()
70 {
71 }
72
73 void HYDROGUI_ObjSelector::paintEvent( QPaintEvent* )
74 {
75 }
76
77 bool HYDROGUI_ObjSelector::hitButton( const QPoint& thePnt ) const
78 {
79   return false;
80 }
81
82 void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
83 {
84   if( !isChecked )
85     return;
86
87   QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
88   foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
89     if( aSelector != this )
90       aSelector->myBtn->setChecked( false );
91
92   if( isChecked )
93     OnSelectionChanged();
94 }
95
96 void HYDROGUI_ObjSelector::OnSelectionChanged()
97 {
98   if( !myBtn->isChecked() )
99     return;
100
101   QString anObjName;
102   Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( myModule );
103   if( !anObject.IsNull() )
104     if( myObjectKind == KIND_UNKNOWN || myObjectKind == anObject->GetKind() )
105       anObjName = anObject->GetName();
106
107   SetName( anObjName );
108 }
109
110 void HYDROGUI_ObjSelector::SetName( const QString& theName )
111 {
112   myObjName->setText( theName );
113 }
114
115 QString HYDROGUI_ObjSelector::GetName() const
116 {
117   return myObjName->text();
118 }
119
120 void HYDROGUI_ObjSelector::Clear()
121 {
122   myObjName->clear();
123   myBtn->setChecked( false );
124 }
125
126 void HYDROGUI_ObjSelector::SetChecked( const bool theState )
127 {
128   myBtn->setChecked( theState );
129 }