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