Salome HOME
Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverMapDlg.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_LandCoverMapDlg.h"
20
21 #include "HYDROGUI_Operations.h"
22 #include "HYDROGUI_StricklerTypeComboBox.h"
23
24 #include <HYDROData_Object.h>
25 #include <HYDROData_PolylineXY.h>
26
27 #include <QLineEdit>
28 #include <QComboBox>
29 #include <QGroupBox>
30 #include <QLabel>
31 #include <QLayout>
32
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 )
39 {
40   // Land Cover Map name
41   myObjectNameGroup = new QGroupBox( tr( "LAND_COVER_MAP_NAME" ), mainFrame() );
42
43   myObjectNameCreate = new QLineEdit( myObjectNameGroup );
44   myObjectNameEdit = new QComboBox( myObjectNameGroup );
45   myObjectNameEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
46
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 );
53
54   myParamGroup = new QGroupBox( tr( "LAND_COVER_MAP_PARAMETERS" ), mainFrame() );
55   QGridLayout* aParamLayout = new QGridLayout( myParamGroup );
56   aParamLayout->setMargin( 5 );
57   aParamLayout->setSpacing( 10 );
58   
59   // Polyline/Face name
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 );
64
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 );
70
71   // Common
72   addWidget( myObjectNameGroup );
73   addWidget( myParamGroup );
74
75   addStretch();
76
77   connect( myPolylinesFaces, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onPolylineFaceChanged( const QString& ) ) );
78
79   updateState( true );
80 }
81
82 HYDROGUI_LandCoverMapDlg::~HYDROGUI_LandCoverMapDlg()
83 {
84 }
85
86 void HYDROGUI_LandCoverMapDlg::reset()
87 {
88   bool isBlocked = blockSignals( true );
89
90   myPolylinesFaces->reset();
91
92   blockSignals( isBlocked );
93
94   updateState();
95 }
96
97 void HYDROGUI_LandCoverMapDlg::setObjectNames( const QStringList& theNames )
98 {
99   bool isBlocked = blockSignals( true );
100
101   myObjectNameEdit->clear();
102   myObjectNameEdit->addItems( theNames );
103
104   blockSignals( isBlocked );
105 }
106
107 void HYDROGUI_LandCoverMapDlg::setObjectName( const QString& theName )
108 {
109   if ( myObjectNameCreate->isVisible() )
110     myObjectNameCreate->setText( theName );
111   else
112     myObjectNameEdit->setCurrentIndex( myObjectNameEdit->findText( theName ) );
113 }
114
115 QString HYDROGUI_LandCoverMapDlg::getObjectName() const
116 {
117   if ( myObjectNameCreate->isVisible() )
118     return myObjectNameCreate->text();
119   return myObjectNameEdit->currentText();
120 }
121
122 QString HYDROGUI_LandCoverMapDlg::getPolylineFaceName() const
123 {
124   return myPolylinesFaces->selectedObject();
125 }
126
127 void HYDROGUI_LandCoverMapDlg::setPolylineFaceName( const QString& theName )
128 {
129   myPolylinesFaces->setSelectedObject( theName );
130 }
131
132 Handle(HYDROData_Entity) HYDROGUI_LandCoverMapDlg::getPolylineFace() const
133 {
134   return myPolylinesFaces->GetObject();
135 }
136
137 void HYDROGUI_LandCoverMapDlg::setSelectedStricklerTypeName( const QString& theName )
138 {
139   myStricklerTypes->setSelectedStricklerTypeName( theName );
140 }
141
142 QString HYDROGUI_LandCoverMapDlg::getSelectedStricklerTypeName() const
143 {
144   return myStricklerTypes->getSelectedStricklerTypeName();
145 }
146
147 bool HYDROGUI_LandCoverMapDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const
148 {
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 ) ) );
154 }
155
156 void HYDROGUI_LandCoverMapDlg::onPolylineFaceChanged( const QString& )
157 {
158   updateState();
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)
160 }
161
162 void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure )
163 {
164   if ( theInitialConfigure )
165   {
166     myObjectNameCreate->setVisible( myOperationId == CreateLandCoverMapId );
167     myObjectNameEdit->setVisible( myOperationId != CreateLandCoverMapId );
168
169     myParamGroup->setVisible( myOperationId != RemoveLandCoverId );
170
171     bool aShowPolylinesFacesCtrls = ( myOperationId == CreateLandCoverMapId ||
172                                       myOperationId == AddLandCoverId ||
173                                       myOperationId == SplitLandCoverId );
174     myPolylinesFacesLabel->setVisible( aShowPolylinesFacesCtrls );
175     myPolylinesFaces->setVisible( aShowPolylinesFacesCtrls );
176
177     bool aShowStricklerTypesCtrls = ( myOperationId == CreateLandCoverMapId ||
178                                       myOperationId == AddLandCoverId ||
179                                       myOperationId == MergeLandCoverId );
180     myStricklerTypesLabel->setVisible( aShowStricklerTypesCtrls );
181     myStricklerTypes->setVisible( aShowStricklerTypesCtrls );
182   }
183   else
184   {
185     bool anEmptyObjectName = getObjectName().isEmpty();
186
187     bool anEmptyPolylineFaceName = false;
188     if ( myPolylinesFaces->isVisible() )
189       anEmptyPolylineFaceName = getPolylineFaceName().isEmpty();
190
191     setApplyEnabled( !anEmptyObjectName && !anEmptyPolylineFaceName );
192   }
193 }