Salome HOME
Refs #288 - the profile section selected and addition mode is activated
[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     QLabel* aPointLatLabel = new QLabel( tr( "POINT_LATITUDE" ), myTransformGroup );
180     QLabel* aPointLonLabel = new QLabel( tr( "POINT_LONGITUDE" ), myTransformGroup );
181     myGeodesicLabels << aPointXDegLabel << aPointYDegLabel
182                     << aPointXMinLabel << aPointYMinLabel
183                     << aPointXSecLabel << aPointYSecLabel
184                     << aPointLonLabel << aPointLatLabel;
185
186     QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -179, 179, 1, myTransformGroup );
187     QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 89, 1, myTransformGroup );
188     QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
189     QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
190     QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
191     QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
192
193     QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
194     QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
195
196     QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
197     QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
198
199     int aRow = 4 * aPointType + 3;
200     if ( aPointType == HYDROGUI_PrsImage::PointC )
201     {
202       myPointCEnabler = new QCheckBox( myTransformGroup );
203       aTransformLayout->addWidget( myPointCEnabler, aRow,    0, 1, 2, Qt::AlignHCenter );
204       aTransformLayout->addWidget( aPointBtn,      aRow,     2, 1, 8 );
205     }
206     else
207     {
208       aTransformLayout->addWidget( aPointBtn,      aRow,     0, 1, 10 );
209     }
210
211     aTransformLayout->addWidget( aPointXLabel,     aRow + 1, 0 );
212     aTransformLayout->addWidget( aPointX,          aRow + 1, 1 );
213     aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
214     aTransformLayout->addWidget( aPointXDeg,       aRow + 1, 3 );
215     aTransformLayout->addWidget( aPointXDegLabel,  aRow + 1, 4 );
216     aTransformLayout->addWidget( aPointXMin,       aRow + 1, 5 );
217     aTransformLayout->addWidget( aPointXMinLabel,  aRow + 1, 6 );
218     aTransformLayout->addWidget( aPointXSec,       aRow + 1, 7 );
219     aTransformLayout->addWidget( aPointXSecLabel,  aRow + 1, 8 );
220     aTransformLayout->addWidget( aPointLonLabel,   aRow + 1, 9 );
221
222     aTransformLayout->addWidget( aCartPointX,      aRow + 1, 3, 1, 6 );
223     aTransformLayout->addWidget( aRefPointX,       aRow + 1, 3, 1, 6 );
224
225     aTransformLayout->addWidget( aPointYLabel,     aRow + 2, 0 );
226     aTransformLayout->addWidget( aPointY,          aRow + 2, 1 );
227     aTransformLayout->addWidget( aPointYDeg,       aRow + 2, 3 );
228     aTransformLayout->addWidget( aPointYDegLabel,  aRow + 2, 4 );
229     aTransformLayout->addWidget( aPointYMin,       aRow + 2, 5 );
230     aTransformLayout->addWidget( aPointYMinLabel,  aRow + 2, 6 );
231     aTransformLayout->addWidget( aPointYSec,       aRow + 2, 7 );
232     aTransformLayout->addWidget( aPointYSecLabel,  aRow + 2, 8 );
233     aTransformLayout->addWidget( aPointLatLabel,   aRow + 2, 9 );
234
235     aTransformLayout->addWidget( aCartPointY,      aRow + 2, 3, 1, 6 );
236     aTransformLayout->addWidget( aRefPointY,       aRow + 2, 3, 1, 6 );
237
238     if( aPointType != HYDROGUI_PrsImage::PointC )
239     {
240       QFrame* aLine = new QFrame( myTransformGroup );
241       aLine->setFrameShape( QFrame::HLine );
242       aLine->setFrameShadow( QFrame::Sunken );
243       aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 10 );
244     }
245
246     myPointBtnMap[ aPointType ] = aPointBtn;
247     myPointXMap[ aPointType ] = aPointX;
248     myPointYMap[ aPointType ] = aPointY;
249     myPointXDegMap[ aPointType ] = aPointXDeg;
250     myPointYDegMap[ aPointType ] = aPointYDeg;
251     myPointXMinMap[ aPointType ] = aPointXMin;
252     myPointYMinMap[ aPointType ] = aPointYMin;
253     myPointXSecMap[ aPointType ] = aPointXSec;
254     myPointYSecMap[ aPointType ] = aPointYSec;
255
256     myCartPointXMap[ aPointType ] = aCartPointX;
257     myCartPointYMap[ aPointType ] = aCartPointY;
258
259     myRefPointXMap[ aPointType ] = aRefPointX;
260     myRefPointYMap[ aPointType ] = aRefPointY;
261
262     connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
263
264     connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
265     connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
266
267     connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
268     connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
269     connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
270     connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
271     connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
272     connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
273
274     connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
275     connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
276
277     connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
278     connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
279   }
280
281   // Connect checkbox enabling point C
282   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
283   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
284   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
285   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
286   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
287   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
288   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
289   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
290   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
291   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
292   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
293   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
294   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
295
296   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
297
298   aTransformLayout->setColumnStretch( 1, 1 ); // double
299   aTransformLayout->setColumnStretch( 3, 1 ); // degrees
300   aTransformLayout->setColumnStretch( 5, 1 ); // minutes
301   aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
302
303   // Common
304   addWidget( myFileNameGroup );
305   addWidget( myImageNameGroup );
306   addWidget( myTransformGroup );
307   addStretch();
308
309   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
310
311   connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
312            this, SLOT( onModeActivated( int ) ) );
313
314   connect( myRefImage, SIGNAL( activated( const QString& ) ),
315            this, SLOT( onRefImageActivated( const QString& ) ) );
316
317   //setTransformationMode( HYDROData_Image::ManualCartesian );
318
319   setMinimumWidth( 350 );
320 }
321
322 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
323 {
324 }
325
326 void HYDROGUI_ImportImageDlg::onSetCIsUsed( bool theCIsUsed )
327 {
328   if ( !theCIsUsed  && myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->isChecked() )
329   {
330     // Turn on point A selection if point C selection has been activated and we disable point C.
331     myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->toggle();
332   }
333   emit setCIsUsed( theCIsUsed );
334 }
335
336 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
337 {
338   myFileNameGroup->setVisible( !theIsEdit );
339   myImageNameGroup->setEnabled( theIsEdit );
340   myTransformGroup->setEnabled( theIsEdit );
341 }
342
343 void HYDROGUI_ImportImageDlg::reset()
344 {
345   myFileName->clear();
346   myImageName->clear();
347   myImageNameGroup->setEnabled( false );
348   for( int aPointType = HYDROGUI_PrsImage::PointA;
349        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
350   {
351     QPushButton* aBtn = myPointBtnMap[ aPointType ];
352     bool anIsBlocked = aBtn->blockSignals( true );
353     aBtn->setChecked( false );
354     aBtn->blockSignals( anIsBlocked );
355
356     myPointXMap[ aPointType ]->clear();
357     myPointYMap[ aPointType ]->clear();
358     myPointXDegMap[ aPointType ]->clear();
359     myPointYDegMap[ aPointType ]->clear();
360     myPointXMinMap[ aPointType ]->clear();
361     myPointYMinMap[ aPointType ]->clear();
362     myPointXSecMap[ aPointType ]->clear();
363     myPointYSecMap[ aPointType ]->clear();
364
365     myRefPointXMap[ aPointType ]->clear();
366     myRefPointYMap[ aPointType ]->clear();
367
368     myCartPointXMap[ aPointType ]->clear();
369     myCartPointYMap[ aPointType ]->clear();
370   }
371   
372   // Emulate turning off C point usage
373   myPointCEnabler->blockSignals( true );
374   
375   myPointCEnabler->setChecked( false );
376   myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
377   myPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
378   myPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
379   myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
380   myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
381   myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
382   myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
383   myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
384   myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
385   myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
386   myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
387   myRefPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
388   myRefPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
389   onSetCIsUsed( false );
390
391   myPointCEnabler->blockSignals( false );
392   
393   myTransformGroup->setEnabled( false );
394   myRefImage->clear();
395
396   setTransformationMode( HYDROData_Image::ManualCartesian );
397
398   myPrsPointDataList.clear();
399
400   myIsInitialized = false;
401 }
402
403 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
404 {
405   myImageName->setText( theName );
406 }
407
408 QString HYDROGUI_ImportImageDlg::getImageName() const
409 {
410   return myImageName->text();
411 }
412
413 void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
414 {
415   myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
416 }
417
418 QString HYDROGUI_ImportImageDlg::getRefImageName() const
419 {
420   return myRefImage->currentText();
421 }
422
423 QString HYDROGUI_ImportImageDlg::getFileName() const
424 {
425   return myFileName->text();
426 }
427
428 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
429                                             const bool theIsRefImage )
430 {
431   int aWidth = theSize.width();
432   int aHeight = theSize.height();
433   for( int aPointType = HYDROGUI_PrsImage::PointA;
434        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
435   {
436     if( theIsRefImage )
437     {
438       myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
439       myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
440     }
441     else
442     {
443       myPointXMap[ aPointType ]->setRange( 0, aWidth );
444       myPointYMap[ aPointType ]->setRange( 0, aHeight );
445     }
446   }
447 }
448
449 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
450 {
451   myModeGroup->button( theMode )->setChecked( true );
452   onModeActivated( theMode );
453 }
454
455 int HYDROGUI_ImportImageDlg::getTransformationMode() const
456 {
457   return myModeGroup->checkedId();
458 }
459
460 void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
461 {
462   myPointCEnabler->setChecked( !theIsByTwoPoints );
463 }
464
465 bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
466 {
467   return !myPointCEnabler->isChecked();
468 }
469
470 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
471                                                         const bool theIsOnlyInput,
472                                                         const bool theIsRefImage )
473 {
474   blockSignalsGeodesic( true );
475   blockSignalsCartesian( true );
476   for( int aPointType = HYDROGUI_PrsImage::PointA;
477        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
478   {
479     if( theMap.contains( aPointType ) )
480     {
481       const TransformationData& aData = theMap[ aPointType ];
482
483       QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
484       QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
485       aPointX->setValue( aData.ImagePoint.x() );
486       aPointY->setValue( aData.ImagePoint.y() );
487
488       if( !theIsOnlyInput && !theIsRefImage )
489       {
490         QPointF aLPoint = aData.GeodesicPoint;
491         int aXDeg = 0, aYDeg = 0;
492         int aXMin = 0, aYMin = 0;
493         double aXSec = 0, aYSec = 0;
494         HYDROData_Lambert93::degToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
495         HYDROData_Lambert93::degToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
496
497         myPointXDegMap[ aPointType ]->setValue( aXDeg );
498         myPointYDegMap[ aPointType ]->setValue( aYDeg );
499         myPointXMinMap[ aPointType ]->setValue( aXMin );
500         myPointYMinMap[ aPointType ]->setValue( aYMin );
501         myPointXSecMap[ aPointType ]->setValue( aXSec );
502         myPointYSecMap[ aPointType ]->setValue( aYSec );
503
504         QPointF aCPoint = aData.CartesianPoint;
505         myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
506         myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
507       }
508     }
509   }
510   blockSignalsGeodesic( false );
511   blockSignalsCartesian( false );
512 }
513
514 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
515                                                         const bool theIsRefImage ) const
516 {
517   theMap.clear();
518   for( int aPointType = HYDROGUI_PrsImage::PointA;
519        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
520   {
521     bool anIsOk[10];
522     for( int i = 0; i < 10; i++ )
523       anIsOk[ i ] = true;
524
525     QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
526     QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
527     int aX1 = aPointX->text().toInt( &anIsOk[0] );
528     int aY1 = aPointY->text().toInt( &anIsOk[1] );
529
530     int aXDeg = 0, aYDeg = 0;
531     int aXMin = 0, aYMin = 0;
532     double aXSec = 0, aYSec = 0;
533     double aXCart = 0, aYCart = 0;
534     if( !theIsRefImage )
535     {
536       aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
537       aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
538       aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
539       aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
540       aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
541       aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
542
543       aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
544       aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
545     }
546
547     for( int i = 0; i < 10; i++ )
548       if( !anIsOk[ i ] )
549         return false;
550
551     double aX2 = 0, aY2 = 0;
552     HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aX2 );
553     HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aY2 );
554
555     TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
556     theMap[ aPointType ] = aData;
557   }
558   return true;
559 }
560
561 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
562 {
563   myPrsPointDataList = theList;
564
565   if( !myPrsPointDataList.isEmpty() )
566   {
567     myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
568
569     myRefImage->clear();
570     myRefImage->addItem( "" ); // first empty item
571
572     PrsPointDataListIterator anIter( myPrsPointDataList );
573     while( anIter.hasNext() )
574       myRefImage->addItem( anIter.next().first );
575   }
576   else
577     myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
578 }
579
580 void HYDROGUI_ImportImageDlg::initializePointSelection()
581 {
582   if( myIsInitialized )
583     return;
584
585   myIsInitialized = true;
586
587   myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
588
589   double aCartX0 = LAMBERT_X0;
590   double aCartY0 = LAMBERT_Y0;
591
592   blockSignalsCartesian( true );
593
594   myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
595   myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + IMG_DELTA );
596
597   myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + IMG_DELTA );
598   myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + IMG_DELTA );
599
600   myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
601   myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
602
603   for( int aPointType = HYDROGUI_PrsImage::PointA;
604        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
605     onCartesianCoordChanged( aPointType );
606
607   blockSignalsCartesian( false );
608 }
609
610 HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
611   const int      theMode,
612   const QPoint&  theLocalPoint,
613   const QPointF& theGlobalPoint )
614 {
615   TransformationData aResTrsfData;
616   aResTrsfData.ImagePoint = theLocalPoint;
617
618   double arx = theGlobalPoint.x();
619   double ary = theGlobalPoint.y();
620   if ( theMode == HYDROData_Image::ManualGeodesic )
621   {
622     // Geodesic to Cartesian
623     double aXCart = 0, aYCart = 0;
624     // Interpreting arY as attitude and arX as longitude
625     HYDROData_Lambert93::toXY( ary, arx, aXCart, aYCart );
626
627     aResTrsfData.GeodesicPoint = theGlobalPoint;
628     aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
629   }
630   else if ( theMode == HYDROData_Image::ManualCartesian )
631   {
632     // Cartesian to Geodesic
633     double aLonDeg = 0, aLatDeg = 0;
634     HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
635
636     aResTrsfData.CartesianPoint = theGlobalPoint;
637     aResTrsfData.GeodesicPoint = QPointF( aLonDeg, aLatDeg );
638   }
639
640   return aResTrsfData;
641 }
642
643 void HYDROGUI_ImportImageDlg::onBrowse()
644 {
645   QString aFilter( tr( "IMAGE_FILTER" ) );
646   QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
647   if( !aFileName.isEmpty() )
648   {
649     QImage anImage( aFileName );
650     if( anImage.isNull() )
651     {
652       QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
653       QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
654         arg( aFileName ).arg( QFileInfo( aFileName ).suffix() );
655       SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
656     }
657     else
658     {
659       myFileName->setText( aFileName );
660       emit createPreview( anImage );
661       myImageNameGroup->setEnabled( true );
662       myTransformGroup->setEnabled( true );
663     }
664   }
665 }
666
667 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
668 {
669   bool anIsManualGeodesic = theMode == HYDROData_Image::ManualGeodesic;
670   bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
671   bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
672
673   myRefImage->setEnabled( anIsRefImage );
674
675   for( int aPointType = HYDROGUI_PrsImage::PointA;
676        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
677   {
678     myPointXDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
679     myPointYDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
680     myPointXMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
681     myPointYMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
682     myPointXSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
683     myPointYSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
684
685     myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
686     myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
687
688     myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
689     myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
690   }
691
692   QListIterator<QLabel*> anIter( myGeodesicLabels );
693   while( anIter.hasNext() )
694     anIter.next()->setVisible( anIsManualGeodesic );
695
696   emit modeActivated( theMode );
697 }
698
699 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
700 {
701   emit refImageActivated( theName );
702 }
703
704 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
705 {
706   int aPointType = HYDROGUI_PrsImage::None;
707   if( theState )
708   {
709     QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
710     while( anIter.hasNext() )
711     {
712       int aBtnPointType = anIter.next().key();
713       QPushButton* aBtn = anIter.value();
714       if( aBtn == sender() )
715         aPointType = aBtnPointType;
716       else
717       {
718         bool anIsBlocked = aBtn->blockSignals( true );
719         aBtn->setChecked( false );
720         aBtn->blockSignals( anIsBlocked );
721       }
722     }
723   }
724   emit activatePointSelection( aPointType );
725 }
726
727 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
728 {
729   QObject* aSender = sender();
730   if( !aSender )
731     return;
732
733   for( int aPointType = HYDROGUI_PrsImage::PointA;
734        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
735   {
736     if( aSender == myPointXMap[ aPointType ] ||
737         aSender == myPointYMap[ aPointType ] )
738     {
739       bool anIsY = aSender == myPointYMap[ aPointType ];
740       emit pointCoordChanged( false, aPointType, anIsY, theValue );
741     }
742     else if( aSender == myRefPointXMap[ aPointType ] ||
743              aSender == myRefPointYMap[ aPointType ] )
744     {
745       bool anIsY = aSender == myRefPointYMap[ aPointType ];
746       emit pointCoordChanged( true, aPointType, anIsY, theValue );
747     }
748   }
749 }
750
751 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged()
752 {
753   QObject* aSender = sender();
754   if( !aSender )
755     return;
756
757   for( int aPointType = HYDROGUI_PrsImage::PointA;
758        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
759   {
760     if( aSender == myPointXDegMap[ aPointType ] ||
761         aSender == myPointYDegMap[ aPointType ] ||
762         aSender == myPointXMinMap[ aPointType ] ||
763         aSender == myPointYMinMap[ aPointType ] ||
764         aSender == myPointXSecMap[ aPointType ] ||
765         aSender == myPointYSecMap[ aPointType ] )
766     {
767       onGeodesicCoordChanged( aPointType );
768       return;
769     }
770   }
771 }
772
773 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged( const int thePointType )
774 {
775   bool anIsOk[6];
776   for( int i = 0; i < 6; i++ )
777     anIsOk[ i ] = true;
778
779   int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
780   int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
781   int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
782   int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
783   double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
784   double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
785
786   for( int i = 0; i < 6; i++ )
787     if( !anIsOk[ i ] )
788       return;
789
790   double aLonDeg = 0, aLatDeg = 0;
791   HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
792   HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
793
794   double aXCart = 0, aYCart = 0;
795   HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
796
797   blockSignalsCartesian( true );
798
799   myCartPointXMap[ thePointType ]->setValue( aXCart );
800   myCartPointYMap[ thePointType ]->setValue( aYCart );
801
802   blockSignalsCartesian( false );
803 }
804
805 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
806 {
807   QObject* aSender = sender();
808   if( !aSender )
809     return;
810
811   for( int aPointType = HYDROGUI_PrsImage::PointA;
812        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
813   {
814     if( aSender == myCartPointXMap[ aPointType ] ||
815         aSender == myCartPointYMap[ aPointType ] )
816     {
817       onCartesianCoordChanged( aPointType );
818       return;
819     }
820   }
821 }
822
823 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
824 {
825   bool anIsOk[2];
826   for( int i = 0; i < 2; i++ )
827     anIsOk[ i ] = true;
828
829   double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
830   double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
831
832   for( int i = 0; i < 2; i++ )
833     if( !anIsOk[ i ] )
834       return;
835
836   double aLonDeg = 0, aLatDeg = 0;
837   HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
838
839   int aXDeg = 0, aYDeg = 0;
840   int aXMin = 0, aYMin = 0;
841   double aXSec = 0, aYSec = 0;
842   HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
843   HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
844
845   blockSignalsGeodesic( true );
846
847   myPointXDegMap[ thePointType ]->setValue( aXDeg );
848   myPointYDegMap[ thePointType ]->setValue( aYDeg );
849   myPointXMinMap[ thePointType ]->setValue( aXMin );
850   myPointYMinMap[ thePointType ]->setValue( aYMin );
851   myPointXSecMap[ thePointType ]->setValue( aXSec );
852   myPointYSecMap[ thePointType ]->setValue( aYSec );
853
854   blockSignalsGeodesic( false );
855 }
856
857 void HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
858 {
859   for( int aPointType = HYDROGUI_PrsImage::PointA;
860        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
861   {
862     myPointXDegMap[ aPointType ]->blockSignals( theState );
863     myPointXMinMap[ aPointType ]->blockSignals( theState );
864     myPointXSecMap[ aPointType ]->blockSignals( theState );
865     myPointYDegMap[ aPointType ]->blockSignals( theState );
866     myPointYMinMap[ aPointType ]->blockSignals( theState );
867     myPointYSecMap[ aPointType ]->blockSignals( theState );
868   }
869 }
870
871 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
872 {
873   for( int aPointType = HYDROGUI_PrsImage::PointA;
874        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
875   {
876     myCartPointXMap[ aPointType ]->blockSignals( theState );
877     myCartPointYMap[ aPointType ]->blockSignals( theState );
878   }
879 }