1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ImportImageDlg.h"
25 #include "HYDROGUI_PrsImage.h"
26 #include "HYDROGUI_Tool.h"
28 #include <HYDROData_Lambert93.h>
29 #include <HYDROData_Image.h>
31 #include <SUIT_FileDlg.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
35 #include <QtxDoubleSpinBox.h>
36 #include <QtxIntSpinBox.h>
38 #include <QButtonGroup>
46 #include <QPushButton>
47 #include <QRadioButton>
48 #include <QToolButton>
51 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
52 : HYDROGUI_InputPanel( theModule, theTitle ),
53 myIsInitialized( false )
55 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
57 // Import image from file
58 myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ), this );
60 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
62 myFileName = new QLineEdit( myFileNameGroup );
63 myFileName->setReadOnly( true );
65 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
66 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
68 QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
69 aFileNameLayout->setMargin( 5 );
70 aFileNameLayout->setSpacing( 5 );
71 aFileNameLayout->addWidget( aFileNameLabel );
72 aFileNameLayout->addWidget( myFileName );
73 aFileNameLayout->addWidget( aBrowseBtn );
76 myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
78 QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
79 myImageName = new QLineEdit( myImageNameGroup );
81 QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
82 anImageNameLayout->setMargin( 5 );
83 anImageNameLayout->setSpacing( 5 );
84 anImageNameLayout->addWidget( anImageNameLabel );
85 anImageNameLayout->addWidget( myImageName );
88 myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ), this );
90 // Make a pixmap for arrow
91 QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
93 QPicture anArrowPicture;
94 anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
97 aPainter.begin( &anArrowPicture );
98 aPainter.drawPixmap( 0, 0, anArrowPixmap );
101 QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup );
102 QRadioButton* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
103 QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
105 myModeGroup = new QButtonGroup( myTransformGroup );
106 myModeGroup->addButton( aManualCartesianBtn, HYDROData_Image::ManualCartesian );
107 myModeGroup->addButton( aManualLambertBtn, HYDROData_Image::ManualLambert );
108 myModeGroup->addButton( aRefImageBtn, HYDROData_Image::ReferenceImage );
110 myRefImage = new QComboBox( myTransformGroup );
112 QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
113 aTransformLayout->setMargin( 5 );
114 aTransformLayout->setSpacing( 5 );
116 QGridLayout* aModeLayout = new QGridLayout( myTransformGroup );
117 aModeLayout->setMargin( 0 );
118 aModeLayout->setSpacing( 5 );
119 aModeLayout->addWidget( aManualCartesianBtn, 0, 0 );
120 aModeLayout->addWidget( aManualLambertBtn, 1, 0 );
121 aModeLayout->addWidget( aRefImageBtn, 2, 0 );
122 aModeLayout->addWidget( myRefImage, 2, 1 );
123 aModeLayout->setColumnStretch( 1, 1 );
125 aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
127 QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
128 QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), myTransformGroup );
129 QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), myTransformGroup );
130 QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), myTransformGroup );
132 aTransformLayout->addWidget( aImageCSLabel, 2, 1 );
133 aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
134 aTransformLayout->addWidget( aLambertLabel, 2, 3, 1, 6 );
135 aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
137 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
138 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
139 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
140 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
141 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
142 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
143 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
144 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
145 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
147 for( int aPointType = HYDROGUI_PrsImage::PointA;
148 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
153 case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
154 case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
155 case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
157 QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
158 aPointBtn->setCheckable( true );
160 QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
161 QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
163 QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
164 QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
166 QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
167 aPointArrowLabel->setPicture( anArrowPicture );
169 QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
170 QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
171 QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
172 QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
173 QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
174 QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
175 myLambertLabels << aPointXDegLabel << aPointYDegLabel
176 << aPointXMinLabel << aPointYMinLabel
177 << aPointXSecLabel << aPointYSecLabel;
179 QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
180 QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( -90, 90, 1, myTransformGroup );
181 QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
182 QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
183 QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
184 QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
186 QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
187 QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
189 QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
190 QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
192 int aRow = 4 * aPointType + 3;
193 if ( aPointType == HYDROGUI_PrsImage::PointC )
195 myPointCEnabler = new QCheckBox( myTransformGroup );
196 aTransformLayout->addWidget( myPointCEnabler, aRow, 0, 1, 2, Qt::AlignHCenter );
197 aTransformLayout->addWidget( aPointBtn, aRow, 2, 1, 7 );
201 aTransformLayout->addWidget( aPointBtn, aRow, 0, 1, 9 );
204 aTransformLayout->addWidget( aPointXLabel, aRow + 1, 0 );
205 aTransformLayout->addWidget( aPointX, aRow + 1, 1 );
206 aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
207 aTransformLayout->addWidget( aPointXDeg, aRow + 1, 3 );
208 aTransformLayout->addWidget( aPointXDegLabel, aRow + 1, 4 );
209 aTransformLayout->addWidget( aPointXMin, aRow + 1, 5 );
210 aTransformLayout->addWidget( aPointXMinLabel, aRow + 1, 6 );
211 aTransformLayout->addWidget( aPointXSec, aRow + 1, 7 );
212 aTransformLayout->addWidget( aPointXSecLabel, aRow + 1, 8 );
214 aTransformLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 );
215 aTransformLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 );
217 aTransformLayout->addWidget( aPointYLabel, aRow + 2, 0 );
218 aTransformLayout->addWidget( aPointY, aRow + 2, 1 );
219 aTransformLayout->addWidget( aPointYDeg, aRow + 2, 3 );
220 aTransformLayout->addWidget( aPointYDegLabel, aRow + 2, 4 );
221 aTransformLayout->addWidget( aPointYMin, aRow + 2, 5 );
222 aTransformLayout->addWidget( aPointYMinLabel, aRow + 2, 6 );
223 aTransformLayout->addWidget( aPointYSec, aRow + 2, 7 );
224 aTransformLayout->addWidget( aPointYSecLabel, aRow + 2, 8 );
226 aTransformLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 );
227 aTransformLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
229 if( aPointType != HYDROGUI_PrsImage::PointC )
231 QFrame* aLine = new QFrame( myTransformGroup );
232 aLine->setFrameShape( QFrame::HLine );
233 aLine->setFrameShadow( QFrame::Sunken );
234 aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
237 myPointBtnMap[ aPointType ] = aPointBtn;
238 myPointXMap[ aPointType ] = aPointX;
239 myPointYMap[ aPointType ] = aPointY;
240 myPointXDegMap[ aPointType ] = aPointXDeg;
241 myPointYDegMap[ aPointType ] = aPointYDeg;
242 myPointXMinMap[ aPointType ] = aPointXMin;
243 myPointYMinMap[ aPointType ] = aPointYMin;
244 myPointXSecMap[ aPointType ] = aPointXSec;
245 myPointYSecMap[ aPointType ] = aPointYSec;
247 myCartPointXMap[ aPointType ] = aCartPointX;
248 myCartPointYMap[ aPointType ] = aCartPointY;
250 myRefPointXMap[ aPointType ] = aRefPointX;
251 myRefPointYMap[ aPointType ] = aRefPointY;
253 connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
255 connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
256 connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
258 connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
259 connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
260 connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
261 connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
262 connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
263 connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
265 connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
266 connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
268 connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
269 connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
272 // Connect checkbox enabling point C
273 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
274 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
275 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
276 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
277 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
278 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
279 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
280 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
281 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
282 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
283 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
284 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
285 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
287 aTransformLayout->setColumnStretch( 1, 1 ); // double
288 aTransformLayout->setColumnStretch( 3, 1 ); // degrees
289 aTransformLayout->setColumnStretch( 5, 1 ); // minutes
290 aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
293 addWidget( myFileNameGroup );
294 addWidget( myImageNameGroup );
295 addWidget( myTransformGroup );
298 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
300 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
301 this, SLOT( onModeActivated( int ) ) );
303 connect( myRefImage, SIGNAL( activated( const QString& ) ),
304 this, SLOT( onRefImageActivated( const QString& ) ) );
306 setTransformationMode( HYDROData_Image::ManualLambert );
308 setMinimumWidth( 350 );
311 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
315 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
317 myFileNameGroup->setVisible( !theIsEdit );
318 myImageNameGroup->setEnabled( theIsEdit );
319 myTransformGroup->setEnabled( theIsEdit );
322 void HYDROGUI_ImportImageDlg::reset()
325 myImageName->clear();
326 myImageNameGroup->setEnabled( false );
327 for( int aPointType = HYDROGUI_PrsImage::PointA;
328 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
330 QPushButton* aBtn = myPointBtnMap[ aPointType ];
331 bool anIsBlocked = aBtn->blockSignals( true );
332 aBtn->setChecked( false );
333 aBtn->blockSignals( anIsBlocked );
335 myPointXMap[ aPointType ]->clear();
336 myPointYMap[ aPointType ]->clear();
337 myPointXDegMap[ aPointType ]->clear();
338 myPointYDegMap[ aPointType ]->clear();
339 myPointXMinMap[ aPointType ]->clear();
340 myPointYMinMap[ aPointType ]->clear();
341 myPointXSecMap[ aPointType ]->clear();
342 myPointYSecMap[ aPointType ]->clear();
344 myRefPointXMap[ aPointType ]->clear();
345 myRefPointYMap[ aPointType ]->clear();
347 myCartPointXMap[ aPointType ]->clear();
348 myCartPointYMap[ aPointType ]->clear();
350 myPointCEnabler->setChecked( true );
351 myPointCEnabler->toggle();
352 myTransformGroup->setEnabled( false );
355 setTransformationMode( HYDROData_Image::ManualLambert );
357 myPrsPointDataList.clear();
359 myIsInitialized = false;
362 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
364 myImageName->setText( theName );
367 QString HYDROGUI_ImportImageDlg::getImageName() const
369 return myImageName->text();
372 void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
374 myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
377 QString HYDROGUI_ImportImageDlg::getRefImageName() const
379 return myRefImage->currentText();
382 QString HYDROGUI_ImportImageDlg::getFileName() const
384 return myFileName->text();
387 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
388 const bool theIsRefImage )
390 int aWidth = theSize.width();
391 int aHeight = theSize.height();
392 for( int aPointType = HYDROGUI_PrsImage::PointA;
393 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
397 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
398 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
402 myPointXMap[ aPointType ]->setRange( 0, aWidth );
403 myPointYMap[ aPointType ]->setRange( 0, aHeight );
408 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
410 myModeGroup->button( theMode )->setChecked( true );
411 onModeActivated( theMode );
414 int HYDROGUI_ImportImageDlg::getTransformationMode() const
416 return myModeGroup->checkedId();
419 void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
421 myPointCEnabler->setChecked( !theIsByTwoPoints );
424 bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
426 return !myPointCEnabler->isChecked();
429 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
430 const bool theIsOnlyInput,
431 const bool theIsRefImage )
433 blockSignalsLambert( true );
434 blockSignalsCartesian( true );
435 for( int aPointType = HYDROGUI_PrsImage::PointA;
436 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
438 if( theMap.contains( aPointType ) )
440 const TransformationData& aData = theMap[ aPointType ];
442 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
443 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
444 aPointX->setValue( aData.ImagePoint.x() );
445 aPointY->setValue( aData.ImagePoint.y() );
447 if( !theIsOnlyInput && !theIsRefImage )
449 QPointF aLPoint = aData.LambertPoint;
450 int aXDeg = 0, aYDeg = 0;
451 int aXMin = 0, aYMin = 0;
452 double aXSec = 0, aYSec = 0;
453 HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
454 HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
456 myPointXDegMap[ aPointType ]->setValue( aXDeg );
457 myPointYDegMap[ aPointType ]->setValue( aYDeg );
458 myPointXMinMap[ aPointType ]->setValue( aXMin );
459 myPointYMinMap[ aPointType ]->setValue( aYMin );
460 myPointXSecMap[ aPointType ]->setValue( aXSec );
461 myPointYSecMap[ aPointType ]->setValue( aYSec );
463 QPointF aCPoint = aData.CartesianPoint;
464 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
465 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
469 blockSignalsLambert( false );
470 blockSignalsCartesian( false );
473 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
474 const bool theIsRefImage ) const
477 for( int aPointType = HYDROGUI_PrsImage::PointA;
478 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
481 for( int i = 0; i < 10; i++ )
484 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
485 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
486 int aX1 = aPointX->text().toInt( &anIsOk[0] );
487 int aY1 = aPointY->text().toInt( &anIsOk[1] );
489 int aXDeg = 0, aYDeg = 0;
490 int aXMin = 0, aYMin = 0;
491 double aXSec = 0, aYSec = 0;
492 double aXCart = 0, aYCart = 0;
495 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
496 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
497 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
498 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
499 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
500 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
502 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
503 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
506 for( int i = 0; i < 10; i++ )
510 double aX2 = 0, aY2 = 0;
511 HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
512 HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
514 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
515 theMap[ aPointType ] = aData;
520 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
522 myPrsPointDataList = theList;
524 if( !myPrsPointDataList.isEmpty() )
526 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
529 myRefImage->addItem( "" ); // first empty item
531 PrsPointDataListIterator anIter( myPrsPointDataList );
532 while( anIter.hasNext() )
533 myRefImage->addItem( anIter.next().first );
536 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
539 void HYDROGUI_ImportImageDlg::initializePointSelection()
541 if( myIsInitialized )
544 myIsInitialized = true;
546 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
550 blockSignalsLambert( true );
552 myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
553 myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
554 myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
555 myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
556 myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
557 myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
559 myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
560 myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
561 myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
562 myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
563 myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
564 myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
566 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
567 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
568 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
569 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
570 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
571 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
573 for( int aPointType = HYDROGUI_PrsImage::PointA;
574 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
575 onLambertCoordChanged( aPointType );
577 blockSignalsLambert( false );
580 //double aCartX0 = 600000;
581 //double aCartY0 = 6800000;
585 blockSignalsCartesian( true );
587 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
588 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
590 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
591 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
593 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
594 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
596 for( int aPointType = HYDROGUI_PrsImage::PointA;
597 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
598 onCartesianCoordChanged( aPointType );
600 blockSignalsCartesian( false );
603 HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
605 const QPoint& theLocalPoint,
606 const QPointF& theGlobalPoint )
608 TransformationData aResTrsfData;
609 aResTrsfData.ImagePoint = theLocalPoint;
611 double arx = theGlobalPoint.x();
612 double ary = theGlobalPoint.y();
613 if ( theMode == HYDROData_Image::ManualLambert )
615 // Lambert to Cartesian
616 double aXCart = 0, aYCart = 0;
617 HYDROData_Lambert93::toXY( arx, ary, aXCart, aYCart );
619 aResTrsfData.LambertPoint = theGlobalPoint;
620 aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
622 else if ( theMode == HYDROData_Image::ManualCartesian )
624 // Cartesian to Lambert
625 double aLonDeg = 0, aLatDeg = 0;
626 HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
628 aResTrsfData.CartesianPoint = theGlobalPoint;
629 aResTrsfData.LambertPoint = QPointF( aLonDeg, aLatDeg );
635 void HYDROGUI_ImportImageDlg::onBrowse()
637 QString aFilter( tr( "IMAGE_FILTER" ) );
638 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
639 if( !aFileName.isEmpty() )
641 QImage anImage( aFileName );
642 if( !anImage.isNull() )
644 myFileName->setText( aFileName );
645 emit createPreview( anImage );
646 myImageNameGroup->setEnabled( true );
647 myTransformGroup->setEnabled( true );
652 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
654 bool anIsManualLambert = theMode == HYDROData_Image::ManualLambert;
655 bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
656 bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
658 myRefImage->setEnabled( anIsRefImage );
660 for( int aPointType = HYDROGUI_PrsImage::PointA;
661 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
663 myPointXDegMap[ aPointType ]->setVisible( anIsManualCartesian );
664 myPointYDegMap[ aPointType ]->setVisible( anIsManualCartesian );
665 myPointXMinMap[ aPointType ]->setVisible( anIsManualCartesian );
666 myPointYMinMap[ aPointType ]->setVisible( anIsManualCartesian );
667 myPointXSecMap[ aPointType ]->setVisible( anIsManualCartesian );
668 myPointYSecMap[ aPointType ]->setVisible( anIsManualCartesian );
670 myCartPointXMap[ aPointType ]->setVisible( anIsManualLambert );
671 myCartPointYMap[ aPointType ]->setVisible( anIsManualLambert );
673 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
674 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
677 QListIterator<QLabel*> anIter( myLambertLabels );
678 while( anIter.hasNext() )
679 anIter.next()->setVisible( anIsManualLambert );
681 emit modeActivated( theMode );
684 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
686 emit refImageActivated( theName );
689 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
691 int aPointType = HYDROGUI_PrsImage::None;
694 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
695 while( anIter.hasNext() )
697 int aBtnPointType = anIter.next().key();
698 QPushButton* aBtn = anIter.value();
699 if( aBtn == sender() )
700 aPointType = aBtnPointType;
703 bool anIsBlocked = aBtn->blockSignals( true );
704 aBtn->setChecked( false );
705 aBtn->blockSignals( anIsBlocked );
709 emit activatePointSelection( aPointType );
712 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
714 QObject* aSender = sender();
718 for( int aPointType = HYDROGUI_PrsImage::PointA;
719 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
721 if( aSender == myPointXMap[ aPointType ] ||
722 aSender == myPointYMap[ aPointType ] )
724 bool anIsY = aSender == myPointYMap[ aPointType ];
725 emit pointCoordChanged( false, aPointType, anIsY, theValue );
727 else if( aSender == myRefPointXMap[ aPointType ] ||
728 aSender == myRefPointYMap[ aPointType ] )
730 bool anIsY = aSender == myRefPointYMap[ aPointType ];
731 emit pointCoordChanged( true, aPointType, anIsY, theValue );
736 void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
738 QObject* aSender = sender();
742 for( int aPointType = HYDROGUI_PrsImage::PointA;
743 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
745 if( aSender == myPointXDegMap[ aPointType ] ||
746 aSender == myPointYDegMap[ aPointType ] ||
747 aSender == myPointXMinMap[ aPointType ] ||
748 aSender == myPointYMinMap[ aPointType ] ||
749 aSender == myPointXSecMap[ aPointType ] ||
750 aSender == myPointYSecMap[ aPointType ] )
752 onLambertCoordChanged( aPointType );
758 void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
761 for( int i = 0; i < 6; i++ )
764 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
765 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
766 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
767 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
768 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
769 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
771 for( int i = 0; i < 6; i++ )
775 double aLonDeg = 0, aLatDeg = 0;
776 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
777 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
779 double aXCart = 0, aYCart = 0;
780 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
782 blockSignalsCartesian( true );
784 myCartPointXMap[ thePointType ]->setValue( aXCart );
785 myCartPointYMap[ thePointType ]->setValue( aYCart );
787 blockSignalsCartesian( false );
790 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
792 QObject* aSender = sender();
796 for( int aPointType = HYDROGUI_PrsImage::PointA;
797 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
799 if( aSender == myCartPointXMap[ aPointType ] ||
800 aSender == myCartPointYMap[ aPointType ] )
802 onCartesianCoordChanged( aPointType );
808 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
811 for( int i = 0; i < 2; i++ )
814 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
815 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
817 for( int i = 0; i < 2; i++ )
821 double aLonDeg = 0, aLatDeg = 0;
822 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
824 int aXDeg = 0, aYDeg = 0;
825 int aXMin = 0, aYMin = 0;
826 double aXSec = 0, aYSec = 0;
827 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
828 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
830 blockSignalsLambert( true );
832 myPointXDegMap[ thePointType ]->setValue( aXDeg );
833 myPointYDegMap[ thePointType ]->setValue( aYDeg );
834 myPointXMinMap[ thePointType ]->setValue( aXMin );
835 myPointYMinMap[ thePointType ]->setValue( aYMin );
836 myPointXSecMap[ thePointType ]->setValue( aXSec );
837 myPointYSecMap[ thePointType ]->setValue( aYSec );
839 blockSignalsLambert( false );
842 void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
844 for( int aPointType = HYDROGUI_PrsImage::PointA;
845 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
847 myPointXDegMap[ aPointType ]->blockSignals( theState );
848 myPointXMinMap[ aPointType ]->blockSignals( theState );
849 myPointXSecMap[ aPointType ]->blockSignals( theState );
850 myPointYDegMap[ aPointType ]->blockSignals( theState );
851 myPointYMinMap[ aPointType ]->blockSignals( theState );
852 myPointYSecMap[ aPointType ]->blockSignals( theState );
856 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
858 for( int aPointType = HYDROGUI_PrsImage::PointA;
859 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
861 myCartPointXMap[ aPointType ]->blockSignals( theState );
862 myCartPointYMap[ aPointType ]->blockSignals( theState );