Salome HOME
when adjusting a shapefile, modify it's name with a suffix _adj or _split
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageDlg.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_ImportImageDlg.h"
20
21 #include "HYDROGUI_PrsImage.h"
22 #include "HYDROGUI_Tool.h"
23 #include "HYDROGUI_Module.h"
24
25 #include <HYDROData_Lambert93.h>
26 #include <HYDROData_Image.h>
27
28 #include <LightApp_Application.h>
29 #include <SUIT_FileDlg.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Session.h>
34
35 #include <QtxDoubleSpinBox.h>
36 #include <QtxIntSpinBox.h>
37
38 #include <QButtonGroup>
39 #include <QComboBox>
40 #include <QGroupBox>
41 #include <QLabel>
42 #include <QLayout>
43 #include <QLineEdit>
44 #include <QPainter>
45 #include <QPicture>
46 #include <QPushButton>
47 #include <QRadioButton>
48 #include <QToolButton>
49 #include <QCheckBox>
50
51 //#define _DEVDEBUG_
52 #include "HYDRO_trace.hxx"
53
54 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
55 : HYDROGUI_InputPanel( theModule, theTitle ),
56   myIsInitialized( false )
57 {
58   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
59
60   // Import image from file
61   myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ), this );
62
63   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
64
65   myFileName = new QLineEdit( myFileNameGroup );
66   myFileName->setReadOnly( true );
67
68   myBrowseBtn = new QToolButton( myFileNameGroup );
69   myBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
70
71   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
72   aFileNameLayout->setMargin( 5 );
73   aFileNameLayout->setSpacing( 5 );
74   aFileNameLayout->addWidget( aFileNameLabel );
75   aFileNameLayout->addWidget( myFileName );
76   aFileNameLayout->addWidget( myBrowseBtn );
77
78   // Image name
79   myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
80
81   QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
82   myImageName = new QLineEdit( myImageNameGroup );
83
84   QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
85   anImageNameLayout->setMargin( 5 );
86   anImageNameLayout->setSpacing( 5 );
87   anImageNameLayout->addWidget( anImageNameLabel );
88   anImageNameLayout->addWidget( myImageName );
89
90   // Transform image
91   myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ), this );
92
93   // Make a pixmap for arrow
94   QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
95
96   QPicture anArrowPicture;
97   anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
98
99   QPainter aPainter;
100   aPainter.begin( &anArrowPicture );
101   aPainter.drawPixmap( 0, 0, anArrowPixmap );
102   aPainter.end();
103
104   QRadioButton* aManualGeodesicBtn = new QRadioButton( tr( "MANUALLY_GEODESIC" ), myTransformGroup );
105   QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
106   QRadioButton* aCartesianFromFileBtn = new QRadioButton( tr( "LAMBERT93_FROM_FILE" ), myTransformGroup );
107   QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
108
109   myModeGroup = new QButtonGroup( myTransformGroup );
110   myModeGroup->addButton( aManualGeodesicBtn, HYDROData_Image::ManualGeodesic );
111   myModeGroup->addButton( aManualCartesianBtn, HYDROData_Image::ManualCartesian );
112   myModeGroup->addButton( aCartesianFromFileBtn, HYDROData_Image::CartesianFromFile );
113   myModeGroup->addButton( aRefImageBtn, HYDROData_Image::ReferenceImage );
114
115   myRefImage = new QComboBox( myTransformGroup );
116
117   QVBoxLayout* aTransformLayout = new QVBoxLayout( myTransformGroup );
118   aTransformLayout->setMargin( 5 );
119   aTransformLayout->setSpacing( 5 );
120
121   QGridLayout* aModeLayout = new QGridLayout( myTransformGroup );
122   aModeLayout->setMargin( 0 );
123   aModeLayout->setSpacing( 5 );
124   aModeLayout->addWidget( aManualGeodesicBtn,   0, 0 );
125   aModeLayout->addWidget( aManualCartesianBtn, 1, 0 );
126   aModeLayout->addWidget( aCartesianFromFileBtn, 2, 0 );
127   aModeLayout->addWidget( aRefImageBtn,        3, 0 );
128   aModeLayout->addWidget( myRefImage,          3, 1 );
129   aModeLayout->setColumnStretch( 1, 1 );
130
131   aTransformLayout->addLayout( aModeLayout );
132
133   // Manual input widget
134   QWidget* aManualInputGroup = new QWidget( myTransformGroup );
135   QGridLayout* aManualInputLayout = new QGridLayout( aManualInputGroup );
136   aManualInputLayout->setMargin( 5 );
137   aManualInputLayout->setSpacing( 5 );
138
139   QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), aManualInputGroup );
140   QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), aManualInputGroup );
141   QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), aManualInputGroup );
142   QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), aManualInputGroup );
143
144   aManualInputLayout->addWidget( aImageCSLabel,  0, 1 );
145   aManualInputLayout->addWidget( aGeodesicLabel, 0, 2, 1, 6 );
146   aManualInputLayout->addWidget( aLambertLabel,  0, 2, 1, 6 );
147   aManualInputLayout->addWidget( aRefImageLabel, 0, 2, 1, 6 );
148
149   for( int aPointType = HYDROGUI_PrsImage::PointA;
150        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
151   {
152     QString aPointStr;
153     switch( aPointType )
154     {
155       case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
156       case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
157       case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
158     }
159     QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
160     aPointBtn->setCheckable( true );
161
162     QLabel* aPointXLabel = new QLabel( "X", aManualInputGroup );
163     QLabel* aPointYLabel = new QLabel( "Y", aManualInputGroup );
164
165     QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
166     QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
167
168     QLabel* aPointArrowLabel = new QLabel( aManualInputGroup );
169     aPointArrowLabel->setPicture( anArrowPicture );
170
171     QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), aManualInputGroup );
172     QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), aManualInputGroup );
173     QLabel* aPointXMinLabel = new QLabel( "'", aManualInputGroup );
174     QLabel* aPointYMinLabel = new QLabel( "'", aManualInputGroup );
175     QLabel* aPointXSecLabel = new QLabel( "\"", aManualInputGroup );
176     QLabel* aPointYSecLabel = new QLabel( "\"", aManualInputGroup );
177     QLabel* aPointLatLabel = new QLabel( tr( "POINT_LATITUDE" ), aManualInputGroup );
178     QLabel* aPointLonLabel = new QLabel( tr( "POINT_LONGITUDE" ), aManualInputGroup );
179     myGeodesicLabels << aPointXDegLabel << aPointYDegLabel
180                     << aPointXMinLabel << aPointYMinLabel
181                     << aPointXSecLabel << aPointYSecLabel
182                     << aPointLonLabel << aPointLatLabel;
183
184     QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -179, 179, 1, aManualInputGroup );
185     QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 89, 1, aManualInputGroup );
186     QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, aManualInputGroup );
187     QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, aManualInputGroup );
188     QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, aManualInputGroup );
189     QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, aManualInputGroup );
190
191     QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, aManualInputGroup );
192     QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, aManualInputGroup );
193
194     QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
195     QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
196
197     int aRow = 4 * aPointType;
198     if ( aPointType == HYDROGUI_PrsImage::PointC )
199     {
200       myPointCEnabler = new QCheckBox( aManualInputGroup );
201       aManualInputLayout->addWidget( myPointCEnabler, aRow,    0, 1, 2, Qt::AlignHCenter );
202       aManualInputLayout->addWidget( aPointBtn,       aRow,    2, 1, 8 );
203     }
204     else
205     {
206       aManualInputLayout->addWidget( aPointBtn,       aRow,    0, 1, 10 );
207     }
208
209     aManualInputLayout->addWidget( aPointXLabel,     aRow + 1, 0 );
210     aManualInputLayout->addWidget( aPointX,          aRow + 1, 1 );
211     aManualInputLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
212     aManualInputLayout->addWidget( aPointXDeg,       aRow + 1, 3 );
213     aManualInputLayout->addWidget( aPointXDegLabel,  aRow + 1, 4 );
214     aManualInputLayout->addWidget( aPointXMin,       aRow + 1, 5 );
215     aManualInputLayout->addWidget( aPointXMinLabel,  aRow + 1, 6 );
216     aManualInputLayout->addWidget( aPointXSec,       aRow + 1, 7 );
217     aManualInputLayout->addWidget( aPointXSecLabel,  aRow + 1, 8 );
218     aManualInputLayout->addWidget( aPointLonLabel,   aRow + 1, 9 );
219
220     aManualInputLayout->addWidget( aCartPointX,      aRow + 1, 3, 1, 6 );
221     aManualInputLayout->addWidget( aRefPointX,       aRow + 1, 3, 1, 6 );
222
223     aManualInputLayout->addWidget( aPointYLabel,     aRow + 2, 0 );
224     aManualInputLayout->addWidget( aPointY,          aRow + 2, 1 );
225     aManualInputLayout->addWidget( aPointYDeg,       aRow + 2, 3 );
226     aManualInputLayout->addWidget( aPointYDegLabel,  aRow + 2, 4 );
227     aManualInputLayout->addWidget( aPointYMin,       aRow + 2, 5 );
228     aManualInputLayout->addWidget( aPointYMinLabel,  aRow + 2, 6 );
229     aManualInputLayout->addWidget( aPointYSec,       aRow + 2, 7 );
230     aManualInputLayout->addWidget( aPointYSecLabel,  aRow + 2, 8 );
231     aManualInputLayout->addWidget( aPointLatLabel,   aRow + 2, 9 );
232
233     aManualInputLayout->addWidget( aCartPointY,      aRow + 2, 3, 1, 6 );
234     aManualInputLayout->addWidget( aRefPointY,       aRow + 2, 3, 1, 6 );
235
236     if( aPointType != HYDROGUI_PrsImage::PointC )
237     {
238       QFrame* aLine = new QFrame( aManualInputGroup );
239       aLine->setFrameShape( QFrame::HLine );
240       aLine->setFrameShadow( QFrame::Sunken );
241       aManualInputLayout->addWidget( aLine, aRow + 3, 0, 1, 10 );
242     }
243
244     myPointBtnMap[ aPointType ] = aPointBtn;
245     myPointXMap[ aPointType ] = aPointX;
246     myPointYMap[ aPointType ] = aPointY;
247     myPointXDegMap[ aPointType ] = aPointXDeg;
248     myPointYDegMap[ aPointType ] = aPointYDeg;
249     myPointXMinMap[ aPointType ] = aPointXMin;
250     myPointYMinMap[ aPointType ] = aPointYMin;
251     myPointXSecMap[ aPointType ] = aPointXSec;
252     myPointYSecMap[ aPointType ] = aPointYSec;
253
254     myCartPointXMap[ aPointType ] = aCartPointX;
255     myCartPointYMap[ aPointType ] = aCartPointY;
256
257     myRefPointXMap[ aPointType ] = aRefPointX;
258     myRefPointYMap[ aPointType ] = aRefPointY;
259
260     connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
261
262     connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
263     connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
264
265     connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
266     connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
267     connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
268     connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
269     connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
270     connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
271
272     connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
273     connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
274
275     connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
276     connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
277   }
278
279   // Connect checkbox enabling point C
280   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
281   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
282   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
283   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
284   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
285   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
286   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
287   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
288   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
289   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
290   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
291   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
292   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
293
294   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
295
296   aManualInputLayout->setColumnStretch( 1, 1 ); // double
297   aManualInputLayout->setColumnStretch( 3, 1 ); // degrees
298   aManualInputLayout->setColumnStretch( 5, 1 ); // minutes
299   aManualInputLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
300
301   // Image georeferencement file widget
302   QWidget* aFromFileInputGroup = new QWidget( myTransformGroup );
303   QBoxLayout* aFromFileInputLayout = new QHBoxLayout( aFromFileInputGroup );
304   aFromFileInputLayout->setMargin( 5 );
305   aFromFileInputLayout->setSpacing( 5 );
306  
307   QLabel* aGeoFileNameLabel = new QLabel( tr( "FILE_NAME" ), aFromFileInputGroup );
308
309   myGeoFileName = new QLineEdit( aFromFileInputGroup );
310   myGeoFileName->setReadOnly( true );
311
312   QToolButton* aGeoBrowseBtn = new QToolButton( aFromFileInputGroup );
313   aGeoBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
314
315   aFromFileInputLayout->addWidget( aGeoFileNameLabel );
316   aFromFileInputLayout->addWidget( myGeoFileName );
317   aFromFileInputLayout->addWidget( aGeoBrowseBtn );
318
319   // Widgets connections
320   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
321   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
322   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
323   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) );
324   connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
325   connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
326   connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
327   connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) );
328   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
329   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
330   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
331   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) );
332   connect( aCartesianFromFileBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setVisible ( bool ) ) );
333   connect( aCartesianFromFileBtn, SIGNAL( toggled( bool ) ), aManualInputGroup, SLOT( setHidden ( bool ) ) );
334
335   // Input widgets
336   aTransformLayout->addWidget( aManualInputGroup );
337   aTransformLayout->addWidget( aFromFileInputGroup );
338
339   // Common
340   addWidget( myFileNameGroup );
341   addWidget( myImageNameGroup );
342   addWidget( myTransformGroup );
343   addStretch();
344
345   connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
346
347   connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
348            this, SLOT( onModeActivated( int ) ) );
349
350   connect( aGeoBrowseBtn, SIGNAL( clicked() ), this, SLOT( onGeoBrowse() ) );
351
352   connect( myRefImage, SIGNAL( activated( const QString& ) ),
353            this, SLOT( onRefImageActivated( const QString& ) ) );
354
355   //setTransformationMode( HYDROData_Image::ManualCartesian );
356
357   setMinimumWidth( 350 );
358 }
359
360 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
361 {
362 }
363
364 void HYDROGUI_ImportImageDlg::onSetCIsUsed( bool theCIsUsed )
365 {
366   if ( !theCIsUsed  && myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->isChecked() )
367   {
368     // Turn on point A selection if point C selection has been activated and we disable point C.
369     myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->toggle();
370   }
371   emit setCIsUsed( theCIsUsed );
372 }
373
374 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
375 {
376   myFileNameGroup->setVisible( !theIsEdit );
377   myImageNameGroup->setEnabled( theIsEdit );
378   myTransformGroup->setEnabled( theIsEdit );
379 }
380
381 void HYDROGUI_ImportImageDlg::reset()
382 {
383   myFileName->clear();
384   myImageName->clear();
385   myImageNameGroup->setEnabled( false );
386   myGeoFileName->clear();
387   bool isPBlocked = blockSignalsPoints( true );
388   bool isGBlocked = blockSignalsGeodesic( true );
389   bool isCBlocked = blockSignalsCartesian( true );
390   for( int aPointType = HYDROGUI_PrsImage::PointA;
391        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
392   {
393     QPushButton* aBtn = myPointBtnMap[ aPointType ];
394     bool anIsBlocked = aBtn->blockSignals( true );
395     aBtn->setChecked( false );
396     aBtn->blockSignals( anIsBlocked );
397
398     clearSpins( myPointXMap[ aPointType ] );
399     clearSpins( myPointYMap[ aPointType ] );
400     clearSpins( myPointXDegMap[ aPointType ] );
401     clearSpins( myPointYDegMap[ aPointType ] );
402     clearSpins( myPointXMinMap[ aPointType ] );
403     clearSpins( myPointYMinMap[ aPointType ] );
404     clearSpins( myPointXSecMap[ aPointType ] );
405     clearSpins( myPointYSecMap[ aPointType ] );
406
407     clearSpins( myRefPointXMap[ aPointType ] );
408     clearSpins( myRefPointYMap[ aPointType ] );
409
410     clearSpins( myCartPointXMap[ aPointType ] );
411     clearSpins( myCartPointYMap[ aPointType ] );
412   }
413   blockSignalsPoints( isPBlocked );
414   blockSignalsGeodesic( isGBlocked );
415   blockSignalsCartesian( isCBlocked );
416   
417   // Emulate turning off C point usage
418   myPointCEnabler->blockSignals( true );
419   
420   myPointCEnabler->setChecked( false );
421   myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
422   myPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
423   myPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
424   myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
425   myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
426   myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
427   myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
428   myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
429   myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
430   myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
431   myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
432   myRefPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
433   myRefPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
434   onSetCIsUsed( false );
435
436   myPointCEnabler->blockSignals( false );
437   
438   myTransformGroup->setEnabled( false );
439   myRefImage->clear();
440
441   setTransformationMode( HYDROData_Image::ManualCartesian );
442
443   myPrsPointDataList.clear();
444
445   myIsInitialized = false;
446 }
447
448 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
449 {
450   myImageName->setText( theName );
451 }
452
453 QString HYDROGUI_ImportImageDlg::getImageName() const
454 {
455   return myImageName->text();
456 }
457
458 void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
459 {
460   myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
461 }
462
463 QString HYDROGUI_ImportImageDlg::getRefImageName() const
464 {
465   return myRefImage->currentText();
466 }
467
468 QString HYDROGUI_ImportImageDlg::getFileName() const
469 {
470   return myFileName->text();
471 }
472
473 void HYDROGUI_ImportImageDlg::setFileName( const QString& theName )
474 {
475   myFileName->setText( theName );
476   myImageNameGroup->setEnabled( true );
477   myTransformGroup->setEnabled( true );
478 }
479
480 QString HYDROGUI_ImportImageDlg::getGeoreferencementFileName() const
481 {
482   return myGeoFileName->text();
483 }
484
485 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
486                                             const bool theIsRefImage )
487 {
488   int aWidth = theSize.width();
489   int aHeight = theSize.height();
490   for( int aPointType = HYDROGUI_PrsImage::PointA;
491        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
492   {
493     if( theIsRefImage )
494     {
495       myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
496       myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
497     }
498     else
499     {
500       myPointXMap[ aPointType ]->setRange( 0, aWidth );
501       myPointYMap[ aPointType ]->setRange( 0, aHeight );
502     }
503   }
504 }
505
506 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
507 {
508   myModeGroup->button( theMode )->setChecked( true );
509   onModeActivated( theMode );
510 }
511
512 int HYDROGUI_ImportImageDlg::getTransformationMode() const
513 {
514   return myModeGroup->checkedId();
515 }
516
517 void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
518 {
519   myPointCEnabler->setChecked( !theIsByTwoPoints );
520 }
521
522 bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
523 {
524   return !myPointCEnabler->isChecked();
525 }
526
527 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
528                                                         const bool theIsOnlyInput,
529                                                         const bool theIsRefImage )
530 {
531   DEBTRACE("setTransformationDataMap " << theIsOnlyInput << " " << theIsRefImage);
532   blockSignalsGeodesic( true );
533   blockSignalsCartesian( true );
534   for( int aPointType = HYDROGUI_PrsImage::PointA;
535        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
536   {
537     if( theMap.contains( aPointType ) )
538     {
539       const TransformationData& aData = theMap[ aPointType ];
540
541       QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
542       QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
543       aPointX->setValue( aData.ImagePoint.x() );
544       aPointY->setValue( aData.ImagePoint.y() );
545       DEBTRACE("aPointX " << aData.ImagePoint.x() << " aPointY " << aData.ImagePoint.y());
546
547       if( !theIsOnlyInput && !theIsRefImage )
548       {
549         QPointF aLPoint = aData.GeodesicPoint;
550         int aXDeg = 0, aYDeg = 0;
551         int aXMin = 0, aYMin = 0;
552         double aXSec = 0, aYSec = 0;
553         HYDROData_Lambert93::degToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
554         HYDROData_Lambert93::degToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
555
556         myPointXDegMap[ aPointType ]->setValue( aXDeg );
557         myPointYDegMap[ aPointType ]->setValue( aYDeg );
558         myPointXMinMap[ aPointType ]->setValue( aXMin );
559         myPointYMinMap[ aPointType ]->setValue( aYMin );
560         myPointXSecMap[ aPointType ]->setValue( aXSec );
561         myPointYSecMap[ aPointType ]->setValue( aYSec );
562
563         QPointF aCPoint = aData.CartesianPoint;
564         myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
565         myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
566       }
567     }
568   }
569   blockSignalsGeodesic( false );
570   blockSignalsCartesian( false );
571 }
572
573 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
574                                                         const bool theIsRefImage ) const
575 {
576   theMap.clear();
577   for( int aPointType = HYDROGUI_PrsImage::PointA;
578        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
579   {
580     bool anIsOk[10];
581     for( int i = 0; i < 10; i++ )
582       anIsOk[ i ] = true;
583
584     QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
585     QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
586     int aX1 = aPointX->text().toInt( &anIsOk[0] );
587     int aY1 = aPointY->text().toInt( &anIsOk[1] );
588
589     int aXDeg = 0, aYDeg = 0;
590     int aXMin = 0, aYMin = 0;
591     double aXSec = 0, aYSec = 0;
592     double aXCart = 0, aYCart = 0;
593     if( !theIsRefImage )
594     {
595       aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
596       aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
597       aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
598       aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
599       aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
600       aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
601
602       aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
603       aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
604     }
605
606     for( int i = 0; i < 10; i++ )
607       if( !anIsOk[ i ] )
608         return false;
609
610     double aX2 = 0, aY2 = 0;
611     HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aX2 );
612     HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aY2 );
613
614     TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
615     theMap[ aPointType ] = aData;
616   }
617   return true;
618 }
619
620 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
621 {
622   myPrsPointDataList = theList;
623
624   if( !myPrsPointDataList.isEmpty() )
625   {
626     myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
627
628     myRefImage->clear();
629     myRefImage->addItem( "" ); // first empty item
630
631     PrsPointDataListIterator anIter( myPrsPointDataList );
632     while( anIter.hasNext() )
633       myRefImage->addItem( anIter.next().first );
634   }
635   else
636     myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
637 }
638
639 void HYDROGUI_ImportImageDlg::initializePointSelection()
640 {
641   if( myIsInitialized )
642     return;
643
644   myIsInitialized = true;
645
646   myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
647
648   double aCartX0 = LAMBERT_X0;
649   double aCartY0 = LAMBERT_Y0;
650
651   blockSignalsCartesian( true );
652
653   myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
654   myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + IMG_DELTA );
655
656   myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + IMG_DELTA );
657   myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + IMG_DELTA );
658
659   myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
660   myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
661
662   for( int aPointType = HYDROGUI_PrsImage::PointA;
663        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
664     onCartesianCoordChanged( aPointType );
665
666   blockSignalsCartesian( false );
667 }
668
669 void HYDROGUI_ImportImageDlg::ECW_initializePointSelection(HYDROData_Image::ECW_FileInfo* theECW_FileInfo)
670 {
671   if( myIsInitialized )
672     return;
673
674   myIsInitialized = true;
675
676   myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
677   myPointBtnMap[ HYDROGUI_PrsImage::PointB ]->setChecked( true );
678   myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->setChecked( true );
679
680   setByTwoPoints(false);
681
682   HYDROData_Image::ECW_CellUnits Units = theECW_FileInfo->myCellSizeUnits;
683
684   if (Units == HYDROData_Image::ECW_CellUnits::ECW_CellUnits_Deg)
685   {
686     blockSignalsGeodesic( true );
687     double Xa, Ya, Xb, Yb, Xc, Yc;
688     Xa = theECW_FileInfo->myOriginX;
689     Ya = theECW_FileInfo->myOriginY;
690     Xb = theECW_FileInfo->myOriginX;    
691     Yb = theECW_FileInfo->myOriginY + theECW_FileInfo->myCellIncrementY * theECW_FileInfo->myYSize;
692     Xc = theECW_FileInfo->myOriginX + theECW_FileInfo->myCellIncrementX * theECW_FileInfo->myXSize;    
693     Yc = theECW_FileInfo->myOriginY;
694
695     int Deg = 0, Min = 0;
696     double Sec = 0.0;
697     //
698     HYDROData_Lambert93::degToDMS( Xa, Deg, Min, Sec );
699     myPointXDegMap[HYDROGUI_PrsImage::PointA]->setValue(Deg);
700     myPointXMinMap[HYDROGUI_PrsImage::PointA]->setValue(Min);
701     myPointXSecMap[HYDROGUI_PrsImage::PointA]->setValue(Sec);
702     HYDROData_Lambert93::degToDMS( Ya, Deg, Min, Sec );
703     myPointYDegMap[HYDROGUI_PrsImage::PointA]->setValue(Deg);
704     myPointYMinMap[HYDROGUI_PrsImage::PointA]->setValue(Min);
705     myPointYSecMap[HYDROGUI_PrsImage::PointA]->setValue(Sec);
706     //
707     HYDROData_Lambert93::degToDMS( Xb, Deg, Min, Sec );
708     myPointXDegMap[HYDROGUI_PrsImage::PointB]->setValue(Deg);
709     myPointXMinMap[HYDROGUI_PrsImage::PointB]->setValue(Min);
710     myPointXSecMap[HYDROGUI_PrsImage::PointB]->setValue(Sec);
711     HYDROData_Lambert93::degToDMS( Yb, Deg, Min, Sec );
712     myPointYDegMap[HYDROGUI_PrsImage::PointB]->setValue(Deg);
713     myPointYMinMap[HYDROGUI_PrsImage::PointB]->setValue(Min);
714     myPointYSecMap[HYDROGUI_PrsImage::PointB]->setValue(Sec);
715     //
716     HYDROData_Lambert93::degToDMS( Xc, Deg, Min, Sec );
717     myPointXDegMap[HYDROGUI_PrsImage::PointC]->setValue(Deg);
718     myPointXMinMap[HYDROGUI_PrsImage::PointC]->setValue(Min);
719     myPointXSecMap[HYDROGUI_PrsImage::PointC]->setValue(Sec);
720     HYDROData_Lambert93::degToDMS( Yc, Deg, Min, Sec );
721     myPointYDegMap[HYDROGUI_PrsImage::PointC]->setValue(Deg);
722     myPointYMinMap[HYDROGUI_PrsImage::PointC]->setValue(Min);
723     myPointYSecMap[HYDROGUI_PrsImage::PointC]->setValue(Sec);
724     //
725     for( int aPointType = HYDROGUI_PrsImage::PointA; aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
726       onGeodesicCoordChanged( aPointType );
727     blockSignalsGeodesic( false );
728     setTransformationMode( HYDROData_Image::ManualGeodesic );
729   }
730   if (Units == HYDROData_Image::ECW_CellUnits::ECW_CellUnits_Meters ||
731     Units == HYDROData_Image::ECW_CellUnits::ECW_CellUnits_Feet )
732   {
733     double Coeff = 1;
734     if (Units == HYDROData_Image::ECW_CellUnits::ECW_CellUnits_Feet)
735       Coeff = 0.3048; //feets
736     blockSignalsCartesian( true );
737     double X1 = 0, Y1 = 0, X2 = 0, Y2 = 0, X3 = 0, Y3 = 0; 
738     X1 = theECW_FileInfo->myOriginX;
739     Y1 = theECW_FileInfo->myOriginY;
740     X2 = theECW_FileInfo->myOriginX;    
741     Y2 = theECW_FileInfo->myOriginY + Coeff * theECW_FileInfo->myCellIncrementY * theECW_FileInfo->myXSize;
742     X3 = theECW_FileInfo->myOriginX + Coeff * theECW_FileInfo->myCellIncrementX * theECW_FileInfo->myYSize;    
743     Y3 = theECW_FileInfo->myOriginY;
744     
745     //extract to A-point (top-left), B-point (bottom-left), C-Point (top-right)
746     double Xa = 0, Ya = 0, Xb = 0, Yb = 0, Xc = 0, Yc = 0;
747     Xa = Min(X1, Min(X2, X3));
748     Ya = Max(Y1, Max(Y2, Y3));
749     Xb = Max(X1, Max(X2, X3));
750     Yb = Ya;
751     Xc = Xa;
752     Yc = Min(Y1, Min(Y2, Y3));
753
754     myCartPointXMap[HYDROGUI_PrsImage::PointA]->setValue(Xa);
755     myCartPointYMap[HYDROGUI_PrsImage::PointA]->setValue(Ya);
756     //
757     myCartPointXMap[HYDROGUI_PrsImage::PointB]->setValue(Xb);
758     myCartPointYMap[HYDROGUI_PrsImage::PointB]->setValue(Yb);
759     //
760     myCartPointXMap[HYDROGUI_PrsImage::PointC]->setValue(Xc);
761     myCartPointYMap[HYDROGUI_PrsImage::PointC]->setValue(Yc);
762     //
763     for( int aPointType = HYDROGUI_PrsImage::PointA; aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
764       onCartesianCoordChanged( aPointType );
765     blockSignalsCartesian( false );
766     setTransformationMode( HYDROData_Image::ManualCartesian );
767   }
768 }
769
770
771 HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
772   const int      theMode,
773   const QPoint&  theLocalPoint,
774   const QPointF& theGlobalPoint )
775 {
776   TransformationData aResTrsfData;
777   aResTrsfData.ImagePoint = theLocalPoint;
778
779   double arx = theGlobalPoint.x();
780   double ary = theGlobalPoint.y();
781   if ( theMode == HYDROData_Image::ManualGeodesic )
782   {
783     // Geodesic to Cartesian
784     double aXCart = 0, aYCart = 0;
785     // Interpreting arY as attitude and arX as longitude
786     HYDROData_Lambert93::toXY( ary, arx, aXCart, aYCart );
787
788     aResTrsfData.GeodesicPoint = theGlobalPoint;
789     aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
790   }
791   else if ( theMode == HYDROData_Image::ManualCartesian )
792   {
793     // Cartesian to Geodesic
794     double aLonDeg = 0, aLatDeg = 0;
795     HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
796
797     aResTrsfData.CartesianPoint = theGlobalPoint;
798     aResTrsfData.GeodesicPoint = QPointF( aLonDeg, aLatDeg );
799   }
800
801   return aResTrsfData;
802 }
803
804 void HYDROGUI_ImportImageDlg::onBrowse()
805 {
806   QString aFilter( tr( "IMAGE_FILTER_IMPORT" ) );
807   QStringList aFileNamesList = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
808   emit filesSelected( aFileNamesList );
809 }
810
811 void HYDROGUI_ImportImageDlg::ActivateFile( const QString& theFileName, bool isEnableFilesChoice )
812 {
813   myFileName->setEnabled( isEnableFilesChoice );
814   myBrowseBtn->setEnabled( isEnableFilesChoice );
815
816   if( !theFileName.isEmpty() )
817   {
818     QFileInfo aFI( theFileName );
819     QImage anImage;
820     HYDROData_Image::ECW_FileInfo* theECWInfo = NULL;
821     if (aFI.suffix().toLower() == "ecw")
822     {
823       theECWInfo = new HYDROData_Image::ECW_FileInfo;
824       HYDROData_Image::OpenECW(theFileName.toLatin1().data(), anImage, theECWInfo);
825     }
826     else
827       anImage = QImage(theFileName);
828     if( anImage.isNull() )
829     {
830       QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
831       QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
832         arg( theFileName ).arg( QFileInfo( theFileName ).suffix() );
833       SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
834     }
835     else
836     {
837       setFileName( theFileName );
838       setImageName( "" );
839       emit createPreview( anImage, theECWInfo );
840     }
841   }
842 }
843
844 void HYDROGUI_ImportImageDlg::onGeoBrowse()
845 {
846   QString aFilter( tr( "IMAGE_GEOREFERENCEMENT_FILTER" ) );
847   QString aGeoFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_GEO_DATA_FROM_FILE" ), true );
848   if( !aGeoFileName.isEmpty() ) {
849     myGeoFileName->setText( aGeoFileName );
850   }
851 }
852
853 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
854 {
855   bool anIsManualGeodesic = theMode == HYDROData_Image::ManualGeodesic;
856   bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
857   bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
858
859   myRefImage->setEnabled( anIsRefImage );
860
861   for( int aPointType = HYDROGUI_PrsImage::PointA;
862        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
863   {
864     myPointXDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
865     myPointYDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
866     myPointXMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
867     myPointYMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
868     myPointXSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
869     myPointYSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
870
871     myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
872     myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
873
874     myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
875     myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
876   }
877
878   QListIterator<QLabel*> anIter( myGeodesicLabels );
879   while( anIter.hasNext() )
880     anIter.next()->setVisible( anIsManualGeodesic );
881
882   emit modeActivated( theMode );
883 }
884
885 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
886 {
887   emit refImageActivated( theName );
888 }
889
890 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
891 {
892   int aPointType = HYDROGUI_PrsImage::None;
893   if( theState )
894   {
895     QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
896     while( anIter.hasNext() )
897     {
898       int aBtnPointType = anIter.next().key();
899       QPushButton* aBtn = anIter.value();
900       if( aBtn == sender() )
901         aPointType = aBtnPointType;
902       else
903       {
904         bool anIsBlocked = aBtn->blockSignals( true );
905         aBtn->setChecked( false );
906         aBtn->blockSignals( anIsBlocked );
907       }
908     }
909   }
910   emit activatePointSelection( aPointType );
911 }
912
913 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
914 {
915   QObject* aSender = sender();
916   if( !aSender )
917     return;
918
919   for( int aPointType = HYDROGUI_PrsImage::PointA;
920        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
921   {
922     if( aSender == myPointXMap[ aPointType ] ||
923         aSender == myPointYMap[ aPointType ] )
924     {
925       bool anIsY = aSender == myPointYMap[ aPointType ];
926       emit pointCoordChanged( false, aPointType, anIsY, theValue );
927     }
928     else if( aSender == myRefPointXMap[ aPointType ] ||
929              aSender == myRefPointYMap[ aPointType ] )
930     {
931       bool anIsY = aSender == myRefPointYMap[ aPointType ];
932       emit pointCoordChanged( true, aPointType, anIsY, theValue );
933     }
934   }
935 }
936
937 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged()
938 {
939   QObject* aSender = sender();
940   if( !aSender )
941     return;
942
943   for( int aPointType = HYDROGUI_PrsImage::PointA;
944        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
945   {
946     if( aSender == myPointXDegMap[ aPointType ] ||
947         aSender == myPointYDegMap[ aPointType ] ||
948         aSender == myPointXMinMap[ aPointType ] ||
949         aSender == myPointYMinMap[ aPointType ] ||
950         aSender == myPointXSecMap[ aPointType ] ||
951         aSender == myPointYSecMap[ aPointType ] )
952     {
953       onGeodesicCoordChanged( aPointType );
954       return;
955     }
956   }
957 }
958
959 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged( const int thePointType )
960 {
961   bool anIsOk[6];
962   for( int i = 0; i < 6; i++ )
963     anIsOk[ i ] = true;
964
965   int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
966   int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
967   int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
968   int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
969   double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
970   double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
971
972   for( int i = 0; i < 6; i++ )
973     if( !anIsOk[ i ] )
974       return;
975
976   double aLonDeg = 0, aLatDeg = 0;
977   HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
978   HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
979
980   double aXCart = 0, aYCart = 0;
981   HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
982
983   blockSignalsCartesian( true );
984
985   myCartPointXMap[ thePointType ]->setValue( aXCart );
986   myCartPointYMap[ thePointType ]->setValue( aYCart );
987
988   blockSignalsCartesian( false );
989 }
990
991 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
992 {
993   QObject* aSender = sender();
994   if( !aSender )
995     return;
996
997   for( int aPointType = HYDROGUI_PrsImage::PointA;
998        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
999   {
1000     if( aSender == myCartPointXMap[ aPointType ] ||
1001         aSender == myCartPointYMap[ aPointType ] )
1002     {
1003       onCartesianCoordChanged( aPointType );
1004       return;
1005     }
1006   }
1007 }
1008
1009 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
1010 {
1011   bool anIsOk[2];
1012   for( int i = 0; i < 2; i++ )
1013     anIsOk[ i ] = true;
1014
1015   double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
1016   double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
1017
1018   for( int i = 0; i < 2; i++ )
1019     if( !anIsOk[ i ] )
1020       return;
1021
1022   double aLonDeg = 0, aLatDeg = 0;
1023   HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
1024
1025   int aXDeg = 0, aYDeg = 0;
1026   int aXMin = 0, aYMin = 0;
1027   double aXSec = 0, aYSec = 0;
1028   HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
1029   HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
1030
1031   blockSignalsGeodesic( true );
1032
1033   myPointXDegMap[ thePointType ]->setValue( aXDeg );
1034   myPointYDegMap[ thePointType ]->setValue( aYDeg );
1035   myPointXMinMap[ thePointType ]->setValue( aXMin );
1036   myPointYMinMap[ thePointType ]->setValue( aYMin );
1037   myPointXSecMap[ thePointType ]->setValue( aXSec );
1038   myPointYSecMap[ thePointType ]->setValue( aYSec );
1039
1040   blockSignalsGeodesic( false );
1041 }
1042
1043 void HYDROGUI_ImportImageDlg::clearSpins( QAbstractSpinBox* theSpin )
1044 {
1045   if ( dynamic_cast<QtxIntSpinBox*>( theSpin ) )
1046   {
1047     QtxIntSpinBox* aSpin = dynamic_cast<QtxIntSpinBox*>( theSpin );
1048     aSpin->setValue( aSpin->minimum() );
1049   }
1050   else if ( dynamic_cast<QtxDoubleSpinBox*>( theSpin ) )
1051   {
1052     QtxDoubleSpinBox* aDblSpin = dynamic_cast<QtxDoubleSpinBox*>( theSpin );
1053     aDblSpin->setValue( aDblSpin->minimum() );
1054   }
1055
1056   theSpin->clear();
1057 }
1058
1059 bool HYDROGUI_ImportImageDlg::blockSignalsPoints( const bool theState )
1060 {
1061   bool isBlocked = false;
1062   for( int aPointType = HYDROGUI_PrsImage::PointA;
1063        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
1064   {
1065     isBlocked = 
1066     myPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
1067     myPointYMap[ aPointType ]->blockSignals( theState );
1068
1069     myRefPointXMap[ aPointType ]->blockSignals( theState );
1070     myRefPointYMap[ aPointType ]->blockSignals( theState );
1071   }
1072   return isBlocked;
1073 }
1074
1075 bool HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
1076 {
1077   bool isBlocked = false;
1078   for( int aPointType = HYDROGUI_PrsImage::PointA;
1079        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
1080   {
1081     isBlocked = 
1082     myPointXDegMap[ aPointType ]->blockSignals( theState ) || isBlocked;
1083     myPointXMinMap[ aPointType ]->blockSignals( theState );
1084     myPointXSecMap[ aPointType ]->blockSignals( theState );
1085     myPointYDegMap[ aPointType ]->blockSignals( theState );
1086     myPointYMinMap[ aPointType ]->blockSignals( theState );
1087     myPointYSecMap[ aPointType ]->blockSignals( theState );
1088   }
1089   return isBlocked;
1090 }
1091
1092 bool HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
1093 {
1094   bool isBlocked = false;
1095   for( int aPointType = HYDROGUI_PrsImage::PointA;
1096        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
1097   {
1098     isBlocked = 
1099     myCartPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
1100     myCartPointYMap[ aPointType ]->blockSignals( theState );
1101   }
1102   return isBlocked;
1103 }