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