Salome HOME
Fix for the bug #37: Error when import image with format not supported.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ImportImageDlg.h"
24
25 #include "HYDROGUI_PrsImage.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_Module.h"
28
29 #include <HYDROData_Lambert93.h>
30 #include <HYDROData_Image.h>
31
32 #include <LightApp_Application.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Session.h>
38
39 #include <QtxDoubleSpinBox.h>
40 #include <QtxIntSpinBox.h>
41
42 #include <QButtonGroup>
43 #include <QComboBox>
44 #include <QGroupBox>
45 #include <QLabel>
46 #include <QLayout>
47 #include <QLineEdit>
48 #include <QPainter>
49 #include <QPicture>
50 #include <QPushButton>
51 #include <QRadioButton>
52 #include <QToolButton>
53 #include <QCheckBox>
54
55 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
56 : HYDROGUI_InputPanel( theModule, theTitle ),
57   myIsInitialized( false )
58 {
59   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
60
61   // Import image from file
62   myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ), this );
63
64   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
65
66   myFileName = new QLineEdit( myFileNameGroup );
67   myFileName->setReadOnly( true );
68
69   QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
70   aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
71
72   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
73   aFileNameLayout->setMargin( 5 );
74   aFileNameLayout->setSpacing( 5 );
75   aFileNameLayout->addWidget( aFileNameLabel );
76   aFileNameLayout->addWidget( myFileName );
77   aFileNameLayout->addWidget( aBrowseBtn );
78
79   // Image name
80   myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
81
82   QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
83   myImageName = new QLineEdit( myImageNameGroup );
84
85   QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
86   anImageNameLayout->setMargin( 5 );
87   anImageNameLayout->setSpacing( 5 );
88   anImageNameLayout->addWidget( anImageNameLabel );
89   anImageNameLayout->addWidget( myImageName );
90
91   // Transform image
92   myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ), this );
93
94   // Make a pixmap for arrow
95   QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
96
97   QPicture anArrowPicture;
98   anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
99
100   QPainter aPainter;
101   aPainter.begin( &anArrowPicture );
102   aPainter.drawPixmap( 0, 0, anArrowPixmap );
103   aPainter.end();
104
105   QRadioButton* aManualGeodesicBtn = new QRadioButton( tr( "MANUALLY_GEODESIC" ), myTransformGroup );
106   QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), 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( aRefImageBtn, HYDROData_Image::ReferenceImage );
113
114   myRefImage = new QComboBox( myTransformGroup );
115
116   QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
117   aTransformLayout->setMargin( 5 );
118   aTransformLayout->setSpacing( 5 );
119
120   QGridLayout* aModeLayout = new QGridLayout( myTransformGroup );
121   aModeLayout->setMargin( 0 );
122   aModeLayout->setSpacing( 5 );
123   aModeLayout->addWidget( aManualGeodesicBtn,   0, 0 );
124   aModeLayout->addWidget( aManualCartesianBtn, 1, 0 );
125   aModeLayout->addWidget( aRefImageBtn,        2, 0 );
126   aModeLayout->addWidget( myRefImage,          2, 1 );
127   aModeLayout->setColumnStretch( 1, 1 );
128
129   aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
130
131   QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
132   QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), myTransformGroup );
133   QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), myTransformGroup );
134   QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), myTransformGroup );
135
136   aTransformLayout->addWidget( aImageCSLabel,  2, 1 );
137   aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
138   aTransformLayout->addWidget( aLambertLabel,  2, 3, 1, 6 );
139   aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
140
141   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
142   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
143   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
144   connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
145   connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
146   connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
147   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
148   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
149   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
150
151   for( int aPointType = HYDROGUI_PrsImage::PointA;
152        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
153   {
154     QString aPointStr;
155     switch( aPointType )
156     {
157       case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
158       case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
159       case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
160     }
161     QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
162     aPointBtn->setCheckable( true );
163
164     QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
165     QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
166
167     QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
168     QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
169
170     QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
171     aPointArrowLabel->setPicture( anArrowPicture );
172
173     QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
174     QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
175     QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
176     QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
177     QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
178     QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
179     myGeodesicLabels << aPointXDegLabel << aPointYDegLabel
180                     << aPointXMinLabel << aPointYMinLabel
181                     << aPointXSecLabel << aPointYSecLabel;
182
183     QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( 0, 360, 1, myTransformGroup );
184     QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 180, 1, myTransformGroup );
185     QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
186     QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
187     QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
188     QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
189
190     QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
191     QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
192
193     QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
194     QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
195
196     int aRow = 4 * aPointType + 3;
197     if ( aPointType == HYDROGUI_PrsImage::PointC )
198     {
199       myPointCEnabler = new QCheckBox( myTransformGroup );
200       aTransformLayout->addWidget( myPointCEnabler, aRow,    0, 1, 2, Qt::AlignHCenter );
201       aTransformLayout->addWidget( aPointBtn,      aRow,     2, 1, 7 );
202     }
203     else
204     {
205       aTransformLayout->addWidget( aPointBtn,      aRow,     0, 1, 9 );
206     }
207
208     aTransformLayout->addWidget( aPointXLabel,     aRow + 1, 0 );
209     aTransformLayout->addWidget( aPointX,          aRow + 1, 1 );
210     aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
211     aTransformLayout->addWidget( aPointXDeg,       aRow + 1, 3 );
212     aTransformLayout->addWidget( aPointXDegLabel,  aRow + 1, 4 );
213     aTransformLayout->addWidget( aPointXMin,       aRow + 1, 5 );
214     aTransformLayout->addWidget( aPointXMinLabel,  aRow + 1, 6 );
215     aTransformLayout->addWidget( aPointXSec,       aRow + 1, 7 );
216     aTransformLayout->addWidget( aPointXSecLabel,  aRow + 1, 8 );
217
218     aTransformLayout->addWidget( aCartPointX,      aRow + 1, 3, 1, 6 );
219     aTransformLayout->addWidget( aRefPointX,       aRow + 1, 3, 1, 6 );
220
221     aTransformLayout->addWidget( aPointYLabel,     aRow + 2, 0 );
222     aTransformLayout->addWidget( aPointY,          aRow + 2, 1 );
223     aTransformLayout->addWidget( aPointYDeg,       aRow + 2, 3 );
224     aTransformLayout->addWidget( aPointYDegLabel,  aRow + 2, 4 );
225     aTransformLayout->addWidget( aPointYMin,       aRow + 2, 5 );
226     aTransformLayout->addWidget( aPointYMinLabel,  aRow + 2, 6 );
227     aTransformLayout->addWidget( aPointYSec,       aRow + 2, 7 );
228     aTransformLayout->addWidget( aPointYSecLabel,  aRow + 2, 8 );
229
230     aTransformLayout->addWidget( aCartPointY,      aRow + 2, 3, 1, 6 );
231     aTransformLayout->addWidget( aRefPointY,       aRow + 2, 3, 1, 6 );
232
233     if( aPointType != HYDROGUI_PrsImage::PointC )
234     {
235       QFrame* aLine = new QFrame( myTransformGroup );
236       aLine->setFrameShape( QFrame::HLine );
237       aLine->setFrameShadow( QFrame::Sunken );
238       aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
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   aTransformLayout->setColumnStretch( 1, 1 ); // double
292   aTransformLayout->setColumnStretch( 3, 1 ); // degrees
293   aTransformLayout->setColumnStretch( 5, 1 ); // minutes
294   aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
295
296   // Common
297   addWidget( myFileNameGroup );
298   addWidget( myImageNameGroup );
299   addWidget( myTransformGroup );
300   addStretch();
301
302   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
303
304   connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
305            this, SLOT( onModeActivated( int ) ) );
306
307   connect( myRefImage, SIGNAL( activated( const QString& ) ),
308            this, SLOT( onRefImageActivated( const QString& ) ) );
309
310   //setTransformationMode( HYDROData_Image::ManualCartesian );
311
312   setMinimumWidth( 350 );
313 }
314
315 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
316 {
317 }
318
319 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
320 {
321   myFileNameGroup->setVisible( !theIsEdit );
322   myImageNameGroup->setEnabled( theIsEdit );
323   myTransformGroup->setEnabled( theIsEdit );
324 }
325
326 void HYDROGUI_ImportImageDlg::reset()
327 {
328   myFileName->clear();
329   myImageName->clear();
330   myImageNameGroup->setEnabled( false );
331   for( int aPointType = HYDROGUI_PrsImage::PointA;
332        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
333   {
334     QPushButton* aBtn = myPointBtnMap[ aPointType ];
335     bool anIsBlocked = aBtn->blockSignals( true );
336     aBtn->setChecked( false );
337     aBtn->blockSignals( anIsBlocked );
338
339     myPointXMap[ aPointType ]->clear();
340     myPointYMap[ aPointType ]->clear();
341     myPointXDegMap[ aPointType ]->clear();
342     myPointYDegMap[ aPointType ]->clear();
343     myPointXMinMap[ aPointType ]->clear();
344     myPointYMinMap[ aPointType ]->clear();
345     myPointXSecMap[ aPointType ]->clear();
346     myPointYSecMap[ aPointType ]->clear();
347
348     myRefPointXMap[ aPointType ]->clear();
349     myRefPointYMap[ aPointType ]->clear();
350
351     myCartPointXMap[ aPointType ]->clear();
352     myCartPointYMap[ aPointType ]->clear();
353   }
354   myPointCEnabler->setChecked( true );
355   myPointCEnabler->toggle();
356   myTransformGroup->setEnabled( false );
357   myRefImage->clear();
358
359   setTransformationMode( HYDROData_Image::ManualCartesian );
360
361   myPrsPointDataList.clear();
362
363   myIsInitialized = false;
364 }
365
366 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
367 {
368   myImageName->setText( theName );
369 }
370
371 QString HYDROGUI_ImportImageDlg::getImageName() const
372 {
373   return myImageName->text();
374 }
375
376 void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
377 {
378   myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
379 }
380
381 QString HYDROGUI_ImportImageDlg::getRefImageName() const
382 {
383   return myRefImage->currentText();
384 }
385
386 QString HYDROGUI_ImportImageDlg::getFileName() const
387 {
388   return myFileName->text();
389 }
390
391 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
392                                             const bool theIsRefImage )
393 {
394   int aWidth = theSize.width();
395   int aHeight = theSize.height();
396   for( int aPointType = HYDROGUI_PrsImage::PointA;
397        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
398   {
399     if( theIsRefImage )
400     {
401       myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
402       myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
403     }
404     else
405     {
406       myPointXMap[ aPointType ]->setRange( 0, aWidth );
407       myPointYMap[ aPointType ]->setRange( 0, aHeight );
408     }
409   }
410 }
411
412 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
413 {
414   myModeGroup->button( theMode )->setChecked( true );
415   onModeActivated( theMode );
416 }
417
418 int HYDROGUI_ImportImageDlg::getTransformationMode() const
419 {
420   return myModeGroup->checkedId();
421 }
422
423 void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
424 {
425   myPointCEnabler->setChecked( !theIsByTwoPoints );
426 }
427
428 bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
429 {
430   return !myPointCEnabler->isChecked();
431 }
432
433 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
434                                                         const bool theIsOnlyInput,
435                                                         const bool theIsRefImage )
436 {
437   blockSignalsGeodesic( true );
438   blockSignalsCartesian( true );
439   for( int aPointType = HYDROGUI_PrsImage::PointA;
440        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
441   {
442     if( theMap.contains( aPointType ) )
443     {
444       const TransformationData& aData = theMap[ aPointType ];
445
446       QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
447       QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
448       aPointX->setValue( aData.ImagePoint.x() );
449       aPointY->setValue( aData.ImagePoint.y() );
450
451       if( !theIsOnlyInput && !theIsRefImage )
452       {
453         QPointF aLPoint = aData.GeodesicPoint;
454         int aXDeg = 0, aYDeg = 0;
455         int aXMin = 0, aYMin = 0;
456         double aXSec = 0, aYSec = 0;
457         HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
458         HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
459
460         myPointXDegMap[ aPointType ]->setValue( aXDeg );
461         myPointYDegMap[ aPointType ]->setValue( aYDeg );
462         myPointXMinMap[ aPointType ]->setValue( aXMin );
463         myPointYMinMap[ aPointType ]->setValue( aYMin );
464         myPointXSecMap[ aPointType ]->setValue( aXSec );
465         myPointYSecMap[ aPointType ]->setValue( aYSec );
466
467         QPointF aCPoint = aData.CartesianPoint;
468         myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
469         myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
470       }
471     }
472   }
473   blockSignalsGeodesic( false );
474   blockSignalsCartesian( false );
475 }
476
477 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
478                                                         const bool theIsRefImage ) const
479 {
480   theMap.clear();
481   for( int aPointType = HYDROGUI_PrsImage::PointA;
482        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
483   {
484     bool anIsOk[10];
485     for( int i = 0; i < 10; i++ )
486       anIsOk[ i ] = true;
487
488     QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
489     QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
490     int aX1 = aPointX->text().toInt( &anIsOk[0] );
491     int aY1 = aPointY->text().toInt( &anIsOk[1] );
492
493     int aXDeg = 0, aYDeg = 0;
494     int aXMin = 0, aYMin = 0;
495     double aXSec = 0, aYSec = 0;
496     double aXCart = 0, aYCart = 0;
497     if( !theIsRefImage )
498     {
499       aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
500       aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
501       aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
502       aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
503       aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
504       aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
505
506       aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
507       aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
508     }
509
510     for( int i = 0; i < 10; i++ )
511       if( !anIsOk[ i ] )
512         return false;
513
514     double aX2 = 0, aY2 = 0;
515     HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
516     HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
517
518     TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
519     theMap[ aPointType ] = aData;
520   }
521   return true;
522 }
523
524 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
525 {
526   myPrsPointDataList = theList;
527
528   if( !myPrsPointDataList.isEmpty() )
529   {
530     myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
531
532     myRefImage->clear();
533     myRefImage->addItem( "" ); // first empty item
534
535     PrsPointDataListIterator anIter( myPrsPointDataList );
536     while( anIter.hasNext() )
537       myRefImage->addItem( anIter.next().first );
538   }
539   else
540     myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
541 }
542
543 void HYDROGUI_ImportImageDlg::initializePointSelection()
544 {
545   if( myIsInitialized )
546     return;
547
548   myIsInitialized = true;
549
550   myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
551
552   double aCartX0 = LAMBERT_X0;
553   double aCartY0 = LAMBERT_Y0;
554
555   blockSignalsCartesian( true );
556
557   myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
558   myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + IMG_DELTA );
559
560   myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + IMG_DELTA );
561   myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + IMG_DELTA );
562
563   myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
564   myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
565
566   for( int aPointType = HYDROGUI_PrsImage::PointA;
567        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
568     onCartesianCoordChanged( aPointType );
569
570   blockSignalsCartesian( false );
571 }
572
573 HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
574   const int      theMode,
575   const QPoint&  theLocalPoint,
576   const QPointF& theGlobalPoint )
577 {
578   TransformationData aResTrsfData;
579   aResTrsfData.ImagePoint = theLocalPoint;
580
581   double arx = theGlobalPoint.x();
582   double ary = theGlobalPoint.y();
583   if ( theMode == HYDROData_Image::ManualGeodesic )
584   {
585     // Geodesic to Cartesian
586     double aXCart = 0, aYCart = 0;
587     HYDROData_Lambert93::toXY( arx, ary, aXCart, aYCart );
588
589     aResTrsfData.GeodesicPoint = theGlobalPoint;
590     aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
591   }
592   else if ( theMode == HYDROData_Image::ManualCartesian )
593   {
594     // Cartesian to Geodesic
595     double aLonDeg = 0, aLatDeg = 0;
596     HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
597
598     aResTrsfData.CartesianPoint = theGlobalPoint;
599     aResTrsfData.GeodesicPoint = QPointF( aLonDeg, aLatDeg );
600   }
601
602   return aResTrsfData;
603 }
604
605 void HYDROGUI_ImportImageDlg::onBrowse()
606 {
607   QString aFilter( tr( "IMAGE_FILTER" ) );
608   QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
609   if( !aFileName.isEmpty() )
610   {
611     QImage anImage( aFileName );
612     if( anImage.isNull() )
613     {
614       QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
615       QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
616         arg( aFileName ).arg( QFileInfo( aFileName ).suffix() );
617       SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
618     }
619     else
620     {
621       myFileName->setText( aFileName );
622       emit createPreview( anImage );
623       myImageNameGroup->setEnabled( true );
624       myTransformGroup->setEnabled( true );
625     }
626   }
627 }
628
629 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
630 {
631   bool anIsManualGeodesic = theMode == HYDROData_Image::ManualGeodesic;
632   bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
633   bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
634
635   myRefImage->setEnabled( anIsRefImage );
636
637   for( int aPointType = HYDROGUI_PrsImage::PointA;
638        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
639   {
640     myPointXDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
641     myPointYDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
642     myPointXMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
643     myPointYMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
644     myPointXSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
645     myPointYSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
646
647     myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
648     myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
649
650     myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
651     myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
652   }
653
654   QListIterator<QLabel*> anIter( myGeodesicLabels );
655   while( anIter.hasNext() )
656     anIter.next()->setVisible( anIsManualGeodesic );
657
658   emit modeActivated( theMode );
659 }
660
661 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
662 {
663   emit refImageActivated( theName );
664 }
665
666 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
667 {
668   int aPointType = HYDROGUI_PrsImage::None;
669   if( theState )
670   {
671     QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
672     while( anIter.hasNext() )
673     {
674       int aBtnPointType = anIter.next().key();
675       QPushButton* aBtn = anIter.value();
676       if( aBtn == sender() )
677         aPointType = aBtnPointType;
678       else
679       {
680         bool anIsBlocked = aBtn->blockSignals( true );
681         aBtn->setChecked( false );
682         aBtn->blockSignals( anIsBlocked );
683       }
684     }
685   }
686   emit activatePointSelection( aPointType );
687 }
688
689 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
690 {
691   QObject* aSender = sender();
692   if( !aSender )
693     return;
694
695   for( int aPointType = HYDROGUI_PrsImage::PointA;
696        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
697   {
698     if( aSender == myPointXMap[ aPointType ] ||
699         aSender == myPointYMap[ aPointType ] )
700     {
701       bool anIsY = aSender == myPointYMap[ aPointType ];
702       emit pointCoordChanged( false, aPointType, anIsY, theValue );
703     }
704     else if( aSender == myRefPointXMap[ aPointType ] ||
705              aSender == myRefPointYMap[ aPointType ] )
706     {
707       bool anIsY = aSender == myRefPointYMap[ aPointType ];
708       emit pointCoordChanged( true, aPointType, anIsY, theValue );
709     }
710   }
711 }
712
713 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged()
714 {
715   QObject* aSender = sender();
716   if( !aSender )
717     return;
718
719   for( int aPointType = HYDROGUI_PrsImage::PointA;
720        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
721   {
722     if( aSender == myPointXDegMap[ aPointType ] ||
723         aSender == myPointYDegMap[ aPointType ] ||
724         aSender == myPointXMinMap[ aPointType ] ||
725         aSender == myPointYMinMap[ aPointType ] ||
726         aSender == myPointXSecMap[ aPointType ] ||
727         aSender == myPointYSecMap[ aPointType ] )
728     {
729       onGeodesicCoordChanged( aPointType );
730       return;
731     }
732   }
733 }
734
735 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged( const int thePointType )
736 {
737   bool anIsOk[6];
738   for( int i = 0; i < 6; i++ )
739     anIsOk[ i ] = true;
740
741   int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
742   int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
743   int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
744   int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
745   double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
746   double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
747
748   for( int i = 0; i < 6; i++ )
749     if( !anIsOk[ i ] )
750       return;
751
752   double aLonDeg = 0, aLatDeg = 0;
753   HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
754   HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
755
756   double aXCart = 0, aYCart = 0;
757   HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
758
759   blockSignalsCartesian( true );
760
761   myCartPointXMap[ thePointType ]->setValue( aXCart );
762   myCartPointYMap[ thePointType ]->setValue( aYCart );
763
764   blockSignalsCartesian( false );
765 }
766
767 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
768 {
769   QObject* aSender = sender();
770   if( !aSender )
771     return;
772
773   for( int aPointType = HYDROGUI_PrsImage::PointA;
774        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
775   {
776     if( aSender == myCartPointXMap[ aPointType ] ||
777         aSender == myCartPointYMap[ aPointType ] )
778     {
779       onCartesianCoordChanged( aPointType );
780       return;
781     }
782   }
783 }
784
785 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
786 {
787   bool anIsOk[2];
788   for( int i = 0; i < 2; i++ )
789     anIsOk[ i ] = true;
790
791   double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
792   double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
793
794   for( int i = 0; i < 2; i++ )
795     if( !anIsOk[ i ] )
796       return;
797
798   double aLonDeg = 0, aLatDeg = 0;
799   HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
800
801   int aXDeg = 0, aYDeg = 0;
802   int aXMin = 0, aYMin = 0;
803   double aXSec = 0, aYSec = 0;
804   HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
805   HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
806
807   blockSignalsGeodesic( true );
808
809   myPointXDegMap[ thePointType ]->setValue( aXDeg );
810   myPointYDegMap[ thePointType ]->setValue( aYDeg );
811   myPointXMinMap[ thePointType ]->setValue( aXMin );
812   myPointYMinMap[ thePointType ]->setValue( aYMin );
813   myPointXSecMap[ thePointType ]->setValue( aXSec );
814   myPointYSecMap[ thePointType ]->setValue( aYSec );
815
816   blockSignalsGeodesic( false );
817 }
818
819 void HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
820 {
821   for( int aPointType = HYDROGUI_PrsImage::PointA;
822        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
823   {
824     myPointXDegMap[ aPointType ]->blockSignals( theState );
825     myPointXMinMap[ aPointType ]->blockSignals( theState );
826     myPointXSecMap[ aPointType ]->blockSignals( theState );
827     myPointYDegMap[ aPointType ]->blockSignals( theState );
828     myPointYMinMap[ aPointType ]->blockSignals( theState );
829     myPointYSecMap[ aPointType ]->blockSignals( theState );
830   }
831 }
832
833 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
834 {
835   for( int aPointType = HYDROGUI_PrsImage::PointA;
836        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
837   {
838     myCartPointXMap[ aPointType ]->blockSignals( theState );
839     myCartPointYMap[ aPointType ]->blockSignals( theState );
840   }
841 }