1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_LandCoverMapDlg.h"
21 #include "HYDROGUI_Operations.h"
22 #include "HYDROGUI_StricklerTypeComboBox.h"
24 #include <HYDROData_Object.h>
25 #include <HYDROData_PolylineXY.h>
27 #include <OCCViewer_ViewManager.h>
29 #include <LightApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <LightApp_DataOwner.h>
33 #include <SUIT_DataObject.h>
41 HYDROGUI_LandCoverMapDlg::HYDROGUI_LandCoverMapDlg( HYDROGUI_Module* theModule,
42 const QString& theTitle,
43 const int theOperationId )
44 : HYDROGUI_InputPanel( theModule, theTitle ),
45 myOperationId( theOperationId ),
46 myFilter( theOperationId )
48 // Land Cover Map name
49 myObjectNameGroup = new QGroupBox( tr( "LAND_COVER_MAP_NAME" ), mainFrame() );
51 myObjectNameCreate = new QLineEdit( myObjectNameGroup );
52 myObjectNameEdit = new QComboBox( myObjectNameGroup );
53 myObjectNameEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
55 QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
56 aNameLayout->setMargin( 5 );
57 aNameLayout->setSpacing( 5 );
58 aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
59 aNameLayout->addWidget( myObjectNameCreate );
60 aNameLayout->addWidget( myObjectNameEdit );
62 myParamGroup = new QGroupBox( tr( "LAND_COVER_MAP_PARAMETERS" ), mainFrame() );
63 QGridLayout* aParamLayout = new QGridLayout( myParamGroup );
64 aParamLayout->setMargin( 5 );
65 aParamLayout->setSpacing( 10 );
68 myPolylinesFacesLabel = new QLabel( tr( "LAND_COVER_MAP_POLYLINE_FACE" ) );
69 aParamLayout->addWidget( myPolylinesFacesLabel, 0, 0, 1, 1 );
70 aParamLayout->addWidget( myPolylinesFaces = new HYDROGUI_ObjComboBox( theModule, "", KIND_UNKNOWN, myParamGroup ), 0, 1, 1, 1 );
71 myPolylinesFaces->setObjectFilter( &myFilter );
73 // Strickler type name
74 myStricklerTypesLabel = new QLabel( tr( "LAND_COVER_MAP_STRICKLER_TYPE" ), myParamGroup );
75 myStricklerTypes = new HYDROGUI_StricklerTypeComboBox( theModule, "", myParamGroup );
76 aParamLayout->addWidget( myStricklerTypesLabel, 1, 0, 1, 1 );
77 aParamLayout->addWidget( myStricklerTypes, 1, 1, 1, 1 );
79 // Label indicated the number of selected land covers
80 QString aDefaultLabel( "0" );
81 mySelectedLandCoversLabel = new QLabel( tr( "LAND_COVER_MAP_SELECTED_FACES" ) + aDefaultLabel, myParamGroup );
82 mySelectedLandCoversLabel->setStyleSheet("QLabel { font: italic; color : red; }");
85 addWidget( myObjectNameGroup );
86 addWidget( myParamGroup );
87 addWidget( mySelectedLandCoversLabel );
91 // Connect signals and slots
92 connect( myObjectNameEdit, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onLandCoverMapChanged() ) );
93 connect( myPolylinesFaces, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onPolylineFaceChanged() ) );
99 HYDROGUI_LandCoverMapDlg::~HYDROGUI_LandCoverMapDlg()
103 void HYDROGUI_LandCoverMapDlg::reset()
105 bool isBlocked = blockSignals( true );
107 myPolylinesFaces->reset();
109 blockSignals( isBlocked );
114 void HYDROGUI_LandCoverMapDlg::setObjectNames( const QStringList& theNames )
116 bool isBlocked = blockSignals( true );
118 myObjectNameEdit->clear();
119 myObjectNameEdit->addItems( theNames );
121 blockSignals( isBlocked );
124 void HYDROGUI_LandCoverMapDlg::setObjectName( const QString& theName )
126 if ( myObjectNameCreate->isVisible() )
127 myObjectNameCreate->setText( theName );
129 myObjectNameEdit->setCurrentIndex( myObjectNameEdit->findText( theName ) );
134 QString HYDROGUI_LandCoverMapDlg::getObjectName() const
136 if ( myObjectNameCreate->isVisible() )
137 return myObjectNameCreate->text();
138 return myObjectNameEdit->currentText();
141 QString HYDROGUI_LandCoverMapDlg::getPolylineFaceName() const
143 return myPolylinesFaces->selectedObject();
146 void HYDROGUI_LandCoverMapDlg::setPolylineFaceName( const QString& theName )
148 myPolylinesFaces->setSelectedObject( theName );
151 Handle(HYDROData_Entity) HYDROGUI_LandCoverMapDlg::getPolylineFace() const
153 return myPolylinesFaces->GetObject();
156 void HYDROGUI_LandCoverMapDlg::setSelectedStricklerTypeName( const QString& theName )
158 myStricklerTypes->setSelectedStricklerTypeName( theName );
161 QString HYDROGUI_LandCoverMapDlg::getSelectedStricklerTypeName() const
163 return myStricklerTypes->getSelectedStricklerTypeName();
166 void HYDROGUI_LandCoverMapDlg::updateSelectedLandCoversLabel( int theNbSelected )
169 aLabel.setNum( theNbSelected );
170 if ( theNbSelected == 0 )
171 mySelectedLandCoversLabel->setStyleSheet("QLabel { font: italic; color : red; }");
173 mySelectedLandCoversLabel->setStyleSheet("QLabel { font: italic; color : black; }");
174 mySelectedLandCoversLabel->setText( tr( "LAND_COVER_MAP_SELECTED_FACES" ) + aLabel );
177 void HYDROGUI_LandCoverMapDlg::onLandCoverMapChanged()
179 if ( signalsBlocked() )
184 emit landCoverMapChanged( getObjectName() );
187 void HYDROGUI_LandCoverMapDlg::onPolylineFaceChanged()
191 emit polylineFaceChanged();
194 void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure )
196 if ( theInitialConfigure )
198 myObjectNameCreate->setVisible( myOperationId == CreateLandCoverMapId );
199 myObjectNameEdit->setVisible( myOperationId != CreateLandCoverMapId );
201 myParamGroup->setVisible( myOperationId != RemoveLandCoverId );
203 bool aShowPolylinesFacesCtrls = ( myOperationId == CreateLandCoverMapId ||
204 myOperationId == AddLandCoverId ||
205 myOperationId == SplitLandCoverId );
206 myPolylinesFacesLabel->setVisible( aShowPolylinesFacesCtrls );
207 myPolylinesFaces->setVisible( aShowPolylinesFacesCtrls );
209 bool aShowStricklerTypesCtrls = ( myOperationId == CreateLandCoverMapId ||
210 myOperationId == AddLandCoverId ||
211 myOperationId == MergeLandCoverId ||
212 myOperationId == ChangeLandCoverTypeId );
213 myStricklerTypesLabel->setVisible( aShowStricklerTypesCtrls );
214 myStricklerTypes->setVisible( aShowStricklerTypesCtrls );
216 bool aShowSelectedLandCoversLabel = ( myOperationId == RemoveLandCoverId ||
217 myOperationId == MergeLandCoverId ||
218 myOperationId == ChangeLandCoverTypeId );
219 mySelectedLandCoversLabel->setVisible( aShowSelectedLandCoversLabel );
223 bool anEmptyObjectName = getObjectName().isEmpty();
225 bool anEmptyPolylineFaceName = false;
226 if ( myPolylinesFaces->isVisible() )
227 anEmptyPolylineFaceName = getPolylineFaceName().isEmpty();
229 setApplyEnabled( !anEmptyObjectName && !anEmptyPolylineFaceName );