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