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