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( myPolylinesFaces, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onPolylineFaceChanged( const QString& ) ) );
82 HYDROGUI_LandCoverMapDlg::~HYDROGUI_LandCoverMapDlg()
86 void HYDROGUI_LandCoverMapDlg::reset()
88 bool isBlocked = blockSignals( true );
90 myPolylinesFaces->reset();
92 blockSignals( isBlocked );
97 void HYDROGUI_LandCoverMapDlg::setObjectNames( const QStringList& theNames )
99 bool isBlocked = blockSignals( true );
101 myObjectNameEdit->clear();
102 myObjectNameEdit->addItems( theNames );
104 blockSignals( isBlocked );
107 void HYDROGUI_LandCoverMapDlg::setObjectName( const QString& theName )
109 if ( myObjectNameCreate->isVisible() )
110 myObjectNameCreate->setText( theName );
112 myObjectNameEdit->setCurrentIndex( myObjectNameEdit->findText( theName ) );
115 QString HYDROGUI_LandCoverMapDlg::getObjectName() const
117 if ( myObjectNameCreate->isVisible() )
118 return myObjectNameCreate->text();
119 return myObjectNameEdit->currentText();
122 QString HYDROGUI_LandCoverMapDlg::getPolylineFaceName() const
124 return myPolylinesFaces->selectedObject();
127 void HYDROGUI_LandCoverMapDlg::setPolylineFaceName( const QString& theName )
129 myPolylinesFaces->setSelectedObject( theName );
132 Handle(HYDROData_Entity) HYDROGUI_LandCoverMapDlg::getPolylineFace() const
134 return myPolylinesFaces->GetObject();
137 void HYDROGUI_LandCoverMapDlg::setSelectedStricklerTypeName( const QString& theName )
139 myStricklerTypes->setSelectedStricklerTypeName( theName );
142 QString HYDROGUI_LandCoverMapDlg::getSelectedStricklerTypeName() const
144 return myStricklerTypes->getSelectedStricklerTypeName();
147 bool HYDROGUI_LandCoverMapDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const
149 Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast(theEntity);
150 Handle(HYDROData_Object) anObject2d3dPrs = Handle(HYDROData_Object)::DownCast(theEntity);
151 return ( !anObject2d3dPrs.IsNull() ||
152 ( !aPolylineXY.IsNull() && ( ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId ) && aPolylineXY->IsClosed() ||
153 myOperationId == SplitLandCoverId ) ) );
156 void HYDROGUI_LandCoverMapDlg::onPolylineFaceChanged( const QString& )
159 // 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)
162 void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure )
164 if ( theInitialConfigure )
166 myObjectNameCreate->setVisible( myOperationId == CreateLandCoverMapId );
167 myObjectNameEdit->setVisible( myOperationId != CreateLandCoverMapId );
169 myParamGroup->setVisible( myOperationId != RemoveLandCoverId );
171 bool aShowPolylinesFacesCtrls = ( myOperationId == CreateLandCoverMapId ||
172 myOperationId == AddLandCoverId ||
173 myOperationId == SplitLandCoverId );
174 myPolylinesFacesLabel->setVisible( aShowPolylinesFacesCtrls );
175 myPolylinesFaces->setVisible( aShowPolylinesFacesCtrls );
177 bool aShowStricklerTypesCtrls = ( myOperationId == CreateLandCoverMapId ||
178 myOperationId == AddLandCoverId ||
179 myOperationId == MergeLandCoverId );
180 myStricklerTypesLabel->setVisible( aShowStricklerTypesCtrls );
181 myStricklerTypes->setVisible( aShowStricklerTypesCtrls );
185 bool anEmptyObjectName = getObjectName().isEmpty();
187 bool anEmptyPolylineFaceName = false;
188 if ( myPolylinesFaces->isVisible() )
189 anEmptyPolylineFaceName = getPolylineFaceName().isEmpty();
191 setApplyEnabled( !anEmptyObjectName && !anEmptyPolylineFaceName );