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