Salome HOME
288e0a6051815f1ee7088c07566e4689646d798c
[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
28 #include <HYDROData_Lambert93.h>
29
30 #include <SUIT_FileDlg.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33
34 #include <QtxDoubleSpinBox.h>
35 #include <QtxIntSpinBox.h>
36
37 #include <QButtonGroup>
38 #include <QComboBox>
39 #include <QGroupBox>
40 #include <QLabel>
41 #include <QLayout>
42 #include <QLineEdit>
43 #include <QPainter>
44 #include <QPicture>
45 #include <QPushButton>
46 #include <QRadioButton>
47 #include <QToolButton>
48
49 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
50 : HYDROGUI_InputPanel( theModule, theTitle ),
51   myIsInitialized( false )
52 {
53   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
54
55   // Import image from file
56   myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
57
58   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
59
60   myFileName = new QLineEdit( myFileNameGroup );
61   myFileName->setReadOnly( true );
62
63   QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
64   aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
65
66   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
67   aFileNameLayout->setMargin( 5 );
68   aFileNameLayout->setSpacing( 5 );
69   aFileNameLayout->addWidget( aFileNameLabel );
70   aFileNameLayout->addWidget( myFileName );
71   aFileNameLayout->addWidget( aBrowseBtn );
72
73   // Image name
74   myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
75
76   QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
77   myImageName = new QLineEdit( myImageNameGroup );
78
79   QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
80   anImageNameLayout->setMargin( 5 );
81   anImageNameLayout->setSpacing( 5 );
82   anImageNameLayout->addWidget( anImageNameLabel );
83   anImageNameLayout->addWidget( myImageName );
84
85   // Transform image
86   myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ) );
87
88   // Make a pixmap for arrow
89   QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
90
91   QPicture anArrowPicture;
92   anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
93
94   QPainter aPainter;
95   aPainter.begin( &anArrowPicture );
96   aPainter.drawPixmap( 0, 0, anArrowPixmap );
97   aPainter.end();
98
99   QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup );
100   QRadioButton* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
101   QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
102
103   myModeGroup = new QButtonGroup( myTransformGroup );
104   myModeGroup->addButton( aManualCartesianBtn, ManualCartesian );
105   myModeGroup->addButton( aManualLambertBtn, ManualLambert );
106   myModeGroup->addButton( aRefImageBtn, RefImage );
107
108   myRefImage = new QComboBox( myTransformGroup );
109
110   QGridLayout* aModeLayout = new QGridLayout();
111   aModeLayout->setMargin( 0 );
112   aModeLayout->setSpacing( 5 );
113   aModeLayout->addWidget( aManualCartesianBtn, 0, 0 );
114   aModeLayout->addWidget( aManualLambertBtn,   1, 0 );
115   aModeLayout->addWidget( aRefImageBtn,        2, 0 );
116   aModeLayout->addWidget( myRefImage,          2, 1 );
117   aModeLayout->setColumnStretch( 1, 1 );
118
119   QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
120   aTransformLayout->setMargin( 5 );
121   aTransformLayout->setSpacing( 5 );
122   aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
123
124   QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
125   QLabel* aGeodesicLabel = new QLabel( "GEODESIC", myTransformGroup );
126   QLabel* aLambertLabel = new QLabel( "LAMBERT93", myTransformGroup );
127   QLabel* aRefImageLabel = new QLabel( "REFERENCE_IMAGE_CS", myTransformGroup );
128
129   aTransformLayout->addWidget( aImageCSLabel,  2, 1 );
130   aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
131   aTransformLayout->addWidget( aLambertLabel,  2, 3, 1, 6 );
132   aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
133
134   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
135   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
136   connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
137   connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
138   connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
139   connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
140   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
141   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
142   connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
143
144   for( int aPointType = HYDROGUI_PrsImage::PointA;
145        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
146   {
147     QString aPointStr;
148     switch( aPointType )
149     {
150       case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
151       case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
152       case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
153     }
154     QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
155     aPointBtn->setCheckable( true );
156
157     QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
158     QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
159
160     QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
161     QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
162
163     QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
164     aPointArrowLabel->setPicture( anArrowPicture );
165
166     QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
167     QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
168     QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
169     QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
170     QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
171     QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
172     myLambertLabels << aPointXDegLabel << aPointYDegLabel
173                     << aPointXMinLabel << aPointYMinLabel
174                     << aPointXSecLabel << aPointYSecLabel;
175
176     QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
177     QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( -90, 90, 1, myTransformGroup );
178     QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
179     QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
180     QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
181     QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
182
183     QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
184     QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
185
186     QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
187     QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
188
189     int aRow = 4 * aPointType + 3;
190     aTransformLayout->addWidget( aPointBtn,        aRow,     0, 1, 9 );
191
192     aTransformLayout->addWidget( aPointXLabel,     aRow + 1, 0 );
193     aTransformLayout->addWidget( aPointX,          aRow + 1, 1 );
194     aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
195     aTransformLayout->addWidget( aPointXDeg,       aRow + 1, 3 );
196     aTransformLayout->addWidget( aPointXDegLabel,  aRow + 1, 4 );
197     aTransformLayout->addWidget( aPointXMin,       aRow + 1, 5 );
198     aTransformLayout->addWidget( aPointXMinLabel,  aRow + 1, 6 );
199     aTransformLayout->addWidget( aPointXSec,       aRow + 1, 7 );
200     aTransformLayout->addWidget( aPointXSecLabel,  aRow + 1, 8 );
201
202     aTransformLayout->addWidget( aCartPointX,      aRow + 1, 3, 1, 6 );
203     aTransformLayout->addWidget( aRefPointX,       aRow + 1, 3, 1, 6 );
204
205     aTransformLayout->addWidget( aPointYLabel,     aRow + 2, 0 );
206     aTransformLayout->addWidget( aPointY,          aRow + 2, 1 );
207     aTransformLayout->addWidget( aPointYDeg,       aRow + 2, 3 );
208     aTransformLayout->addWidget( aPointYDegLabel,  aRow + 2, 4 );
209     aTransformLayout->addWidget( aPointYMin,       aRow + 2, 5 );
210     aTransformLayout->addWidget( aPointYMinLabel,  aRow + 2, 6 );
211     aTransformLayout->addWidget( aPointYSec,       aRow + 2, 7 );
212     aTransformLayout->addWidget( aPointYSecLabel,  aRow + 2, 8 );
213
214     aTransformLayout->addWidget( aCartPointY,      aRow + 2, 3, 1, 6 );
215     aTransformLayout->addWidget( aRefPointY,       aRow + 2, 3, 1, 6 );
216
217     if( aPointType != HYDROGUI_PrsImage::PointC )
218     {
219       QFrame* aLine = new QFrame( myTransformGroup );
220       aLine->setFrameShape( QFrame::HLine );
221       aLine->setFrameShadow( QFrame::Sunken );
222       aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
223     }
224
225     myPointBtnMap[ aPointType ] = aPointBtn;
226     myPointXMap[ aPointType ] = aPointX;
227     myPointYMap[ aPointType ] = aPointY;
228     myPointXDegMap[ aPointType ] = aPointXDeg;
229     myPointYDegMap[ aPointType ] = aPointYDeg;
230     myPointXMinMap[ aPointType ] = aPointXMin;
231     myPointYMinMap[ aPointType ] = aPointYMin;
232     myPointXSecMap[ aPointType ] = aPointXSec;
233     myPointYSecMap[ aPointType ] = aPointYSec;
234
235     myCartPointXMap[ aPointType ] = aCartPointX;
236     myCartPointYMap[ aPointType ] = aCartPointY;
237
238     myRefPointXMap[ aPointType ] = aRefPointX;
239     myRefPointYMap[ aPointType ] = aRefPointY;
240
241     connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
242
243     connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
244     connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
245
246     connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
247     connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
248     connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
249     connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
250     connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
251     connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
252
253     connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
254     connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
255
256     connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
257     connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
258   }
259   aTransformLayout->setColumnStretch( 1, 1 ); // double
260   aTransformLayout->setColumnStretch( 3, 1 ); // degrees
261   aTransformLayout->setColumnStretch( 5, 1 ); // minutes
262   aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
263
264   // Common
265   addWidget( myFileNameGroup );
266   addWidget( myImageNameGroup );
267   addWidget( myTransformGroup );
268   addStretch();
269
270   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
271
272   connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
273            this, SLOT( onModeActivated( int ) ) );
274
275   connect( myRefImage, SIGNAL( activated( const QString& ) ),
276            this, SLOT( onRefImageActivated( const QString& ) ) );
277
278   setTransformationMode( ManualLambert );
279
280   setMinimumWidth( 350 );
281 }
282
283 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
284 {
285   delete myFileNameGroup;
286   delete myImageNameGroup;
287   delete myTransformGroup;
288 }
289
290 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
291 {
292   myFileNameGroup->setVisible( !theIsEdit );
293   myImageNameGroup->setEnabled( theIsEdit );
294   myTransformGroup->setEnabled( theIsEdit );
295 }
296
297 void HYDROGUI_ImportImageDlg::reset()
298 {
299   myFileName->clear();
300   myImageName->clear();
301   myImageNameGroup->setEnabled( false );
302   for( int aPointType = HYDROGUI_PrsImage::PointA;
303        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
304   {
305     QPushButton* aBtn = myPointBtnMap[ aPointType ];
306     bool anIsBlocked = aBtn->blockSignals( true );
307     aBtn->setChecked( false );
308     aBtn->blockSignals( anIsBlocked );
309
310     myPointXMap[ aPointType ]->clear();
311     myPointYMap[ aPointType ]->clear();
312     myPointXDegMap[ aPointType ]->clear();
313     myPointYDegMap[ aPointType ]->clear();
314     myPointXMinMap[ aPointType ]->clear();
315     myPointYMinMap[ aPointType ]->clear();
316     myPointXSecMap[ aPointType ]->clear();
317     myPointYSecMap[ aPointType ]->clear();
318
319     myRefPointXMap[ aPointType ]->clear();
320     myRefPointYMap[ aPointType ]->clear();
321
322     myCartPointXMap[ aPointType ]->clear();
323     myCartPointYMap[ aPointType ]->clear();
324   }
325   myTransformGroup->setEnabled( false );
326   myRefImage->clear();
327
328   setTransformationMode( ManualLambert );
329
330   myPrsPointDataList.clear();
331
332   myIsInitialized = false;
333 }
334
335 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
336 {
337   myImageName->setText( theName );
338 }
339
340 QString HYDROGUI_ImportImageDlg::getImageName() const
341 {
342   return myImageName->text();
343 }
344
345 QString HYDROGUI_ImportImageDlg::getFileName() const
346 {
347   return myFileName->text();
348 }
349
350 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
351                                             const bool theIsRefImage )
352 {
353   int aWidth = theSize.width();
354   int aHeight = theSize.height();
355   for( int aPointType = HYDROGUI_PrsImage::PointA;
356        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
357   {
358     if( theIsRefImage )
359     {
360       myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
361       myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
362     }
363     else
364     {
365       myPointXMap[ aPointType ]->setRange( 0, aWidth );
366       myPointYMap[ aPointType ]->setRange( 0, aHeight );
367     }
368   }
369 }
370
371 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
372 {
373   myModeGroup->button( theMode )->setChecked( true );
374   onModeActivated( theMode );
375 }
376
377 int HYDROGUI_ImportImageDlg::getTransformationMode() const
378 {
379   return myModeGroup->checkedId();
380 }
381
382 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
383                                                         const bool theIsOnlyInput,
384                                                         const bool theIsRefImage )
385 {
386   blockSignalsLambert( true );
387   blockSignalsCartesian( true );
388   for( int aPointType = HYDROGUI_PrsImage::PointA;
389        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
390   {
391     if( theMap.contains( aPointType ) )
392     {
393       const TransformationData& aData = theMap[ aPointType ];
394
395       QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
396       QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
397       aPointX->setValue( aData.ImagePoint.x() );
398       aPointY->setValue( aData.ImagePoint.y() );
399
400       if( !theIsOnlyInput && !theIsRefImage )
401       {
402         QPointF aLPoint = aData.LambertPoint;
403         int aXDeg = 0, aYDeg = 0;
404         int aXMin = 0, aYMin = 0;
405         double aXSec = 0, aYSec = 0;
406         HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
407         HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
408
409         myPointXDegMap[ aPointType ]->setValue( aXDeg );
410         myPointYDegMap[ aPointType ]->setValue( aYDeg );
411         myPointXMinMap[ aPointType ]->setValue( aXMin );
412         myPointYMinMap[ aPointType ]->setValue( aYMin );
413         myPointXSecMap[ aPointType ]->setValue( aXSec );
414         myPointYSecMap[ aPointType ]->setValue( aYSec );
415
416         QPointF aCPoint = aData.CartesianPoint;
417         myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
418         myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
419       }
420     }
421   }
422   blockSignalsLambert( false );
423   blockSignalsCartesian( false );
424 }
425
426 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
427                                                         const bool theIsRefImage ) const
428 {
429   theMap.clear();
430   for( int aPointType = HYDROGUI_PrsImage::PointA;
431        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
432   {
433     bool anIsOk[10];
434     for( int i = 0; i < 10; i++ )
435       anIsOk[ i ] = true;
436
437     QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
438     QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
439     int aX1 = aPointX->text().toInt( &anIsOk[0] );
440     int aY1 = aPointY->text().toInt( &anIsOk[1] );
441
442     int aXDeg = 0, aYDeg = 0;
443     int aXMin = 0, aYMin = 0;
444     double aXSec = 0, aYSec = 0;
445     double aXCart = 0, aYCart = 0;
446     if( !theIsRefImage )
447     {
448       aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
449       aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
450       aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
451       aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
452       aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
453       aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
454
455       aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
456       aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
457     }
458
459     for( int i = 0; i < 10; i++ )
460       if( !anIsOk[ i ] )
461         return false;
462
463     double aX2 = 0, aY2 = 0;
464     HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
465     HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
466
467     TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
468     theMap[ aPointType ] = aData;
469   }
470   return true;
471 }
472
473 QString HYDROGUI_ImportImageDlg::getRefImageName() const
474 {
475   return myRefImage->currentText();
476 }
477
478 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
479 {
480   myPrsPointDataList = theList;
481
482   if( !myPrsPointDataList.isEmpty() )
483   {
484     myModeGroup->button( RefImage )->setEnabled( true );
485
486     myRefImage->clear();
487     myRefImage->addItem( "" ); // first empty item
488
489     PrsPointDataListIterator anIter( myPrsPointDataList );
490     while( anIter.hasNext() )
491       myRefImage->addItem( anIter.next().first );
492   }
493   else
494     myModeGroup->button( RefImage )->setEnabled( false );
495 }
496
497 void HYDROGUI_ImportImageDlg::initializePointSelection()
498 {
499   if( myIsInitialized )
500     return;
501
502   myIsInitialized = true;
503
504   myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
505
506   // ouv: tmp
507   /*
508   blockSignalsLambert( true );
509
510   myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
511   myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
512   myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
513   myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
514   myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
515   myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
516
517   myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
518   myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
519   myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
520   myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
521   myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
522   myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
523
524   myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
525   myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
526   myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
527   myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
528   myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
529   myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
530
531   for( int aPointType = HYDROGUI_PrsImage::PointA;
532        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
533     onLambertCoordChanged( aPointType );
534
535   blockSignalsLambert( false );
536   */
537
538   //double aCartX0 = 600000;
539   //double aCartY0 = 6800000;
540   double aCartX0 = 0;
541   double aCartY0 = 0;
542
543   blockSignalsCartesian( true );
544
545   myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
546   myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
547
548   myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
549   myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
550
551   myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
552   myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
553
554   for( int aPointType = HYDROGUI_PrsImage::PointA;
555        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
556     onCartesianCoordChanged( aPointType );
557
558   blockSignalsCartesian( false );
559 }
560
561 void HYDROGUI_ImportImageDlg::onBrowse()
562 {
563   QString aFilter( tr( "IMAGE_FILTER" ) );
564   QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
565   if( !aFileName.isEmpty() )
566   {
567     QImage anImage( aFileName );
568     if( !anImage.isNull() )
569     {
570       myFileName->setText( aFileName );
571       emit createPreview( anImage );
572       myImageNameGroup->setEnabled( true );
573       myTransformGroup->setEnabled( true );
574     }
575   }
576 }
577
578 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
579 {
580   bool anIsManualLambert = theMode == ManualLambert;
581   bool anIsManualCartesian = theMode == ManualCartesian;
582   bool anIsRefImage = theMode == RefImage;
583
584   myRefImage->setEnabled( anIsRefImage );
585
586   for( int aPointType = HYDROGUI_PrsImage::PointA;
587        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
588   {
589     myPointXDegMap[ aPointType ]->setVisible( anIsManualLambert );
590     myPointYDegMap[ aPointType ]->setVisible( anIsManualLambert );
591     myPointXMinMap[ aPointType ]->setVisible( anIsManualLambert );
592     myPointYMinMap[ aPointType ]->setVisible( anIsManualLambert );
593     myPointXSecMap[ aPointType ]->setVisible( anIsManualLambert );
594     myPointYSecMap[ aPointType ]->setVisible( anIsManualLambert );
595
596     myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
597     myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
598
599     myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
600     myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
601   }
602
603   QListIterator<QLabel*> anIter( myLambertLabels );
604   while( anIter.hasNext() )
605     anIter.next()->setVisible( anIsManualLambert );
606
607   emit modeActivated( theMode );
608 }
609
610 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
611 {
612   emit refImageActivated( theName );
613 }
614
615 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
616 {
617   int aPointType = HYDROGUI_PrsImage::None;
618   if( theState )
619   {
620     QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
621     while( anIter.hasNext() )
622     {
623       int aBtnPointType = anIter.next().key();
624       QPushButton* aBtn = anIter.value();
625       if( aBtn == sender() )
626         aPointType = aBtnPointType;
627       else
628       {
629         bool anIsBlocked = aBtn->blockSignals( true );
630         aBtn->setChecked( false );
631         aBtn->blockSignals( anIsBlocked );
632       }
633     }
634   }
635   emit activatePointSelection( aPointType );
636 }
637
638 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
639 {
640   QObject* aSender = sender();
641   if( !aSender )
642     return;
643
644   for( int aPointType = HYDROGUI_PrsImage::PointA;
645        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
646   {
647     if( aSender == myPointXMap[ aPointType ] ||
648         aSender == myPointYMap[ aPointType ] )
649     {
650       bool anIsY = aSender == myPointYMap[ aPointType ];
651       emit pointCoordChanged( false, aPointType, anIsY, theValue );
652     }
653     else if( aSender == myRefPointXMap[ aPointType ] ||
654              aSender == myRefPointYMap[ aPointType ] )
655     {
656       bool anIsY = aSender == myRefPointYMap[ aPointType ];
657       emit pointCoordChanged( true, aPointType, anIsY, theValue );
658     }
659   }
660 }
661
662 void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
663 {
664   QObject* aSender = sender();
665   if( !aSender )
666     return;
667
668   for( int aPointType = HYDROGUI_PrsImage::PointA;
669        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
670   {
671     if( aSender == myPointXDegMap[ aPointType ] ||
672         aSender == myPointYDegMap[ aPointType ] ||
673         aSender == myPointXMinMap[ aPointType ] ||
674         aSender == myPointYMinMap[ aPointType ] ||
675         aSender == myPointXSecMap[ aPointType ] ||
676         aSender == myPointYSecMap[ aPointType ] )
677     {
678       onLambertCoordChanged( aPointType );
679       return;
680     }
681   }
682 }
683
684 void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
685 {
686   bool anIsOk[6];
687   for( int i = 0; i < 6; i++ )
688     anIsOk[ i ] = true;
689
690   int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
691   int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
692   int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
693   int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
694   double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
695   double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
696
697   for( int i = 0; i < 6; i++ )
698     if( !anIsOk[ i ] )
699       return;
700
701   double aLonDeg = 0, aLatDeg = 0;
702   HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
703   HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
704
705   double aXCart = 0, aYCart = 0;
706   HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
707
708   blockSignalsCartesian( true );
709
710   myCartPointXMap[ thePointType ]->setValue( aXCart );
711   myCartPointYMap[ thePointType ]->setValue( aYCart );
712
713   blockSignalsCartesian( false );
714 }
715
716 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
717 {
718   QObject* aSender = sender();
719   if( !aSender )
720     return;
721
722   for( int aPointType = HYDROGUI_PrsImage::PointA;
723        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
724   {
725     if( aSender == myCartPointXMap[ aPointType ] ||
726         aSender == myCartPointYMap[ aPointType ] )
727     {
728       onCartesianCoordChanged( aPointType );
729       return;
730     }
731   }
732 }
733
734 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
735 {
736   bool anIsOk[2];
737   for( int i = 0; i < 2; i++ )
738     anIsOk[ i ] = true;
739
740   double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
741   double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
742
743   for( int i = 0; i < 2; i++ )
744     if( !anIsOk[ i ] )
745       return;
746
747   double aLonDeg = 0, aLatDeg = 0;
748   HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
749
750   int aXDeg = 0, aYDeg = 0;
751   int aXMin = 0, aYMin = 0;
752   double aXSec = 0, aYSec = 0;
753   HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
754   HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
755
756   blockSignalsLambert( true );
757
758   myPointXDegMap[ thePointType ]->setValue( aXDeg );
759   myPointYDegMap[ thePointType ]->setValue( aYDeg );
760   myPointXMinMap[ thePointType ]->setValue( aXMin );
761   myPointYMinMap[ thePointType ]->setValue( aYMin );
762   myPointXSecMap[ thePointType ]->setValue( aXSec );
763   myPointYSecMap[ thePointType ]->setValue( aYSec );
764
765   blockSignalsLambert( false );
766 }
767
768 void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
769 {
770   for( int aPointType = HYDROGUI_PrsImage::PointA;
771        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
772   {
773     myPointXDegMap[ aPointType ]->blockSignals( theState );
774     myPointXMinMap[ aPointType ]->blockSignals( theState );
775     myPointXSecMap[ aPointType ]->blockSignals( theState );
776     myPointYDegMap[ aPointType ]->blockSignals( theState );
777     myPointYMinMap[ aPointType ]->blockSignals( theState );
778     myPointYSecMap[ aPointType ]->blockSignals( theState );
779   }
780 }
781
782 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
783 {
784   for( int aPointType = HYDROGUI_PrsImage::PointA;
785        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
786   {
787     myCartPointXMap[ aPointType ]->blockSignals( theState );
788     myCartPointYMap[ aPointType ]->blockSignals( theState );
789   }
790 }