1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ObjSelector.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
29 #include <GraphicsView_Object.h>
31 #include <LightApp_Application.h>
32 #include <LightApp_GVSelector.h>
33 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
40 #include <QToolButton>
42 HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule,
43 const ObjectKind theObjectKind,
45 : QAbstractButton( theParent ),
46 myObjectKind( theObjectKind ),
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 );
60 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
61 myBtn->setIcon( QIcon( aResMgr->loadPixmap( "HYDRO", tr( "SELECT_ICO" ) ) ) );
63 SUIT_SelectionMgr* aSelMgr = theModule->getApp()->selectionMgr();
65 connect( myBtn, SIGNAL( toggled( bool ) ), this, SLOT( OnToggled( bool ) ) );
66 connect( aSelMgr, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
69 HYDROGUI_ObjSelector::~HYDROGUI_ObjSelector()
73 void HYDROGUI_ObjSelector::paintEvent( QPaintEvent* )
77 bool HYDROGUI_ObjSelector::hitButton( const QPoint& thePnt ) const
82 void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
87 QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
88 foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
89 if( aSelector != this )
90 aSelector->myBtn->setChecked( false );
96 void HYDROGUI_ObjSelector::OnSelectionChanged()
98 if( !myBtn->isChecked() )
102 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( myModule );
103 if( !anObject.IsNull() )
104 if( myObjectKind == KIND_UNKNOWN || myObjectKind == anObject->GetKind() )
106 anObjName = anObject->GetName();
108 // Check if the same object has not been selected in other selectors of the same parent widget.
109 if ( !anObjName.isEmpty() )
111 QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
112 foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
114 if( aSelector != this && ( aSelector->GetName() == anObjName ) )
116 // Forbid selection of the same object
117 emit alreadySelected( anObjName );
124 SetName( anObjName );
127 void HYDROGUI_ObjSelector::SetName( const QString& theName )
129 myObjName->setText( theName );
132 QString HYDROGUI_ObjSelector::GetName() const
134 return myObjName->text();
137 void HYDROGUI_ObjSelector::Clear()
140 myBtn->setChecked( false );
143 void HYDROGUI_ObjSelector::SetChecked( const bool theState )
145 myBtn->setChecked( theState );