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