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>
33 HYDROGUI_LandCoverMapDlg::HYDROGUI_LandCoverMapDlg( HYDROGUI_Module* theModule,
34 const QString& theTitle,
35 const int theOperationId )
36 : HYDROGUI_InputPanel( theModule, theTitle ),
37 HYDROGUI_ObjComboBoxFilter(),
38 myOperationId( theOperationId )
40 // Land Cover Map name
41 myObjectNameGroup = new QGroupBox( tr( "LAND_COVER_MAP_NAME" ), mainFrame() );
43 myObjectNameCreate = new QLineEdit( myObjectNameGroup );
44 myObjectNameEdit = new QComboBox( myObjectNameGroup );
45 myObjectNameEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
47 QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
48 aNameLayout->setMargin( 5 );
49 aNameLayout->setSpacing( 5 );
50 aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
51 aNameLayout->addWidget( myObjectNameCreate );
52 aNameLayout->addWidget( myObjectNameEdit );
54 myParamGroup = new QGroupBox( tr( "LAND_COVER_MAP_PARAMETERS" ), mainFrame() );
55 QGridLayout* aParamLayout = new QGridLayout( myParamGroup );
56 aParamLayout->setMargin( 5 );
57 aParamLayout->setSpacing( 10 );
60 myPolylinesFacesLabel = new QLabel( tr( "LAND_COVER_MAP_POLYLINE_FACE" ) );
61 aParamLayout->addWidget( myPolylinesFacesLabel, 0, 0, 1, 1 );
62 aParamLayout->addWidget( myPolylinesFaces = new HYDROGUI_ObjComboBox( theModule, "", KIND_UNKNOWN, myParamGroup ), 0, 1, 1, 1 );
63 myPolylinesFaces->setObjectFilter( this );
65 // Strickler type name
66 myStricklerTypesLabel = new QLabel( tr( "LAND_COVER_MAP_STRICKLER_TYPE" ), myParamGroup );
67 myStricklerTypes = new HYDROGUI_StricklerTypeComboBox( theModule, "", myParamGroup );
68 aParamLayout->addWidget( myStricklerTypesLabel, 1, 0, 1, 1 );
69 aParamLayout->addWidget( myStricklerTypes, 1, 1, 1, 1 );
72 addWidget( myObjectNameGroup );
73 addWidget( myParamGroup );
77 // Connect signals and slots
78 connect( myObjectNameEdit, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onLandCoverMapChanged() ) );
79 connect( myPolylinesFaces, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onPolylineFaceChanged( const QString& ) ) );
85 HYDROGUI_LandCoverMapDlg::~HYDROGUI_LandCoverMapDlg()
89 void HYDROGUI_LandCoverMapDlg::reset()
91 bool isBlocked = blockSignals( true );
93 myPolylinesFaces->reset();
95 blockSignals( isBlocked );
100 void HYDROGUI_LandCoverMapDlg::setObjectNames( const QStringList& theNames )
102 bool isBlocked = blockSignals( true );
104 myObjectNameEdit->clear();
105 myObjectNameEdit->addItems( theNames );
107 blockSignals( isBlocked );
110 void HYDROGUI_LandCoverMapDlg::setObjectName( const QString& theName )
112 if ( myObjectNameCreate->isVisible() )
113 myObjectNameCreate->setText( theName );
115 myObjectNameEdit->setCurrentIndex( myObjectNameEdit->findText( theName ) );
118 QString HYDROGUI_LandCoverMapDlg::getObjectName() const
120 if ( myObjectNameCreate->isVisible() )
121 return myObjectNameCreate->text();
122 return myObjectNameEdit->currentText();
125 QString HYDROGUI_LandCoverMapDlg::getPolylineFaceName() const
127 return myPolylinesFaces->selectedObject();
130 void HYDROGUI_LandCoverMapDlg::setPolylineFaceName( const QString& theName )
132 myPolylinesFaces->setSelectedObject( theName );
135 Handle(HYDROData_Entity) HYDROGUI_LandCoverMapDlg::getPolylineFace() const
137 return myPolylinesFaces->GetObject();
140 void HYDROGUI_LandCoverMapDlg::setSelectedStricklerTypeName( const QString& theName )
142 myStricklerTypes->setSelectedStricklerTypeName( theName );
145 QString HYDROGUI_LandCoverMapDlg::getSelectedStricklerTypeName() const
147 return myStricklerTypes->getSelectedStricklerTypeName();
150 bool HYDROGUI_LandCoverMapDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const
152 Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast(theEntity);
153 Handle(HYDROData_Object) anObject2d3dPrs = Handle(HYDROData_Object)::DownCast(theEntity);
154 return ( !anObject2d3dPrs.IsNull() ||
155 ( !aPolylineXY.IsNull() && ( ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId ) && aPolylineXY->IsClosed() ||
156 myOperationId == SplitLandCoverId ) ) );
159 void HYDROGUI_LandCoverMapDlg::onLandCoverMapChanged()
161 if ( signalsBlocked() )
166 emit landCoverMapChanged( getObjectName() );
169 void HYDROGUI_LandCoverMapDlg::onPolylineFaceChanged( const QString& )
172 // TODO: select chosen polyline/face in the 3D viewer, if it is not selected yet (i.e. object was chosen not in the viewer, but in combo-box)
175 void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure )
177 if ( theInitialConfigure )
179 myObjectNameCreate->setVisible( myOperationId == CreateLandCoverMapId );
180 myObjectNameEdit->setVisible( myOperationId != CreateLandCoverMapId );
182 myParamGroup->setVisible( myOperationId != RemoveLandCoverId );
184 bool aShowPolylinesFacesCtrls = ( myOperationId == CreateLandCoverMapId ||
185 myOperationId == AddLandCoverId ||
186 myOperationId == SplitLandCoverId );
187 myPolylinesFacesLabel->setVisible( aShowPolylinesFacesCtrls );
188 myPolylinesFaces->setVisible( aShowPolylinesFacesCtrls );
190 bool aShowStricklerTypesCtrls = ( myOperationId == CreateLandCoverMapId ||
191 myOperationId == AddLandCoverId ||
192 myOperationId == MergeLandCoverId ||
193 myOperationId == ChangeLandCoverTypeId );
194 myStricklerTypesLabel->setVisible( aShowStricklerTypesCtrls );
195 myStricklerTypes->setVisible( aShowStricklerTypesCtrls );
199 bool anEmptyObjectName = getObjectName().isEmpty();
201 bool anEmptyPolylineFaceName = false;
202 if ( myPolylinesFaces->isVisible() )
203 anEmptyPolylineFaceName = getPolylineFaceName().isEmpty();
205 setApplyEnabled( !anEmptyObjectName && !anEmptyPolylineFaceName );