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 <HYDROData_PolylineXY.h>
31 #include <GraphicsView_Object.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_GVSelector.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_Session.h>
42 #include <QToolButton>
44 HYDROGUI_ObjSelector::HYDROGUI_ObjSelector( HYDROGUI_Module* theModule,
45 const ObjectKind theObjectKind,
47 const int theObjectFlags)
48 : QAbstractButton( theParent ),
49 myObjectKind( theObjectKind ),
50 myModule( theModule ),
51 myObjectFlags( theObjectFlags )
53 QHBoxLayout* aLayout = new QHBoxLayout( this );
54 aLayout->setMargin( 0 );
55 aLayout->setSpacing( 5 );
56 myBtn = new QToolButton( this );
57 myBtn->setCheckable( true );
58 myBtn->setChecked( false );
59 myObjName = new QLineEdit( this );
60 myObjName->setReadOnly( true );
61 aLayout->addWidget( myBtn, 0 );
62 aLayout->addWidget( myObjName, 1 );
64 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
65 myBtn->setIcon( QIcon( aResMgr->loadPixmap( "HYDRO", tr( "SELECT_ICO" ) ) ) );
67 SUIT_SelectionMgr* aSelMgr = theModule->getApp()->selectionMgr();
69 connect( myBtn, SIGNAL( toggled( bool ) ), this, SLOT( OnToggled( bool ) ) );
70 connect( aSelMgr, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
73 HYDROGUI_ObjSelector::~HYDROGUI_ObjSelector()
77 void HYDROGUI_ObjSelector::paintEvent( QPaintEvent* )
81 bool HYDROGUI_ObjSelector::hitButton( const QPoint& thePnt ) const
86 void HYDROGUI_ObjSelector::OnToggled( bool isChecked )
91 QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
92 foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
93 if( aSelector != this )
94 aSelector->myBtn->setChecked( false );
100 void HYDROGUI_ObjSelector::OnSelectionChanged()
102 if( !myBtn->isChecked() )
106 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( myModule );
107 if( !anObject.IsNull() )
108 if( myObjectKind == KIND_UNKNOWN || myObjectKind == anObject->GetKind() )
110 if ( myObjectKind == KIND_POLYLINEXY && ( myObjectFlags & ClosedPolyline ) ) {
111 // check if the polyline is closed
112 Handle(HYDROData_PolylineXY) aPolylineObj =
113 Handle(HYDROData_PolylineXY)::DownCast( anObject );
114 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() ) {
115 anObjName = aPolylineObj->GetName();
118 anObjName = anObject->GetName();
121 // Check if the same object has not been selected in other selectors of the same parent widget.
122 if ( !anObjName.isEmpty() )
124 QList<HYDROGUI_ObjSelector*> aSelectors = parentWidget()->findChildren<HYDROGUI_ObjSelector*>();
125 foreach( HYDROGUI_ObjSelector* aSelector, aSelectors )
127 if( aSelector != this && ( aSelector->GetName() == anObjName ) )
129 // Forbid selection of the same object
130 emit alreadySelected( anObjName );
137 SetName( anObjName );
140 void HYDROGUI_ObjSelector::SetName( const QString& theName )
142 myObjName->setText( theName );
145 QString HYDROGUI_ObjSelector::GetName() const
147 return myObjName->text();
150 void HYDROGUI_ObjSelector::Clear()
153 myBtn->setChecked( false );
156 void HYDROGUI_ObjSelector::SetChecked( const bool theState )
158 myBtn->setChecked( theState );