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"
27 #include "HYDROGUI_Module.h"
29 #include <HYDROData_Lambert93.h>
30 #include <HYDROData_Image.h>
32 #include <LightApp_Application.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Session.h>
39 #include <QtxDoubleSpinBox.h>
40 #include <QtxIntSpinBox.h>
42 #include <QButtonGroup>
50 #include <QPushButton>
51 #include <QRadioButton>
52 #include <QToolButton>
55 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
56 : HYDROGUI_InputPanel( theModule, theTitle ),
57 myIsInitialized( false )
59 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
61 // Import image from file
62 myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ), this );
64 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
66 myFileName = new QLineEdit( myFileNameGroup );
67 myFileName->setReadOnly( true );
69 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
70 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
72 QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
73 aFileNameLayout->setMargin( 5 );
74 aFileNameLayout->setSpacing( 5 );
75 aFileNameLayout->addWidget( aFileNameLabel );
76 aFileNameLayout->addWidget( myFileName );
77 aFileNameLayout->addWidget( aBrowseBtn );
80 myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
82 QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
83 myImageName = new QLineEdit( myImageNameGroup );
85 QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
86 anImageNameLayout->setMargin( 5 );
87 anImageNameLayout->setSpacing( 5 );
88 anImageNameLayout->addWidget( anImageNameLabel );
89 anImageNameLayout->addWidget( myImageName );
92 myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ), this );
94 // Make a pixmap for arrow
95 QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
97 QPicture anArrowPicture;
98 anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
101 aPainter.begin( &anArrowPicture );
102 aPainter.drawPixmap( 0, 0, anArrowPixmap );
105 QRadioButton* aManualGeodesicBtn = new QRadioButton( tr( "MANUALLY_GEODESIC" ), myTransformGroup );
106 QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
107 QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
109 myModeGroup = new QButtonGroup( myTransformGroup );
110 myModeGroup->addButton( aManualGeodesicBtn, HYDROData_Image::ManualGeodesic );
111 myModeGroup->addButton( aManualCartesianBtn, HYDROData_Image::ManualCartesian );
112 myModeGroup->addButton( aRefImageBtn, HYDROData_Image::ReferenceImage );
114 myRefImage = new QComboBox( myTransformGroup );
116 QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
117 aTransformLayout->setMargin( 5 );
118 aTransformLayout->setSpacing( 5 );
120 QGridLayout* aModeLayout = new QGridLayout( myTransformGroup );
121 aModeLayout->setMargin( 0 );
122 aModeLayout->setSpacing( 5 );
123 aModeLayout->addWidget( aManualGeodesicBtn, 0, 0 );
124 aModeLayout->addWidget( aManualCartesianBtn, 1, 0 );
125 aModeLayout->addWidget( aRefImageBtn, 2, 0 );
126 aModeLayout->addWidget( myRefImage, 2, 1 );
127 aModeLayout->setColumnStretch( 1, 1 );
129 aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
131 QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
132 QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), myTransformGroup );
133 QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), myTransformGroup );
134 QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), myTransformGroup );
136 aTransformLayout->addWidget( aImageCSLabel, 2, 1 );
137 aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
138 aTransformLayout->addWidget( aLambertLabel, 2, 3, 1, 6 );
139 aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
141 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
142 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
143 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
144 connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
145 connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
146 connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
147 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
148 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
149 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
151 for( int aPointType = HYDROGUI_PrsImage::PointA;
152 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
157 case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
158 case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
159 case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
161 QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
162 aPointBtn->setCheckable( true );
164 QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
165 QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
167 QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
168 QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
170 QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
171 aPointArrowLabel->setPicture( anArrowPicture );
173 QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
174 QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
175 QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
176 QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
177 QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
178 QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
179 myGeodesicLabels << aPointXDegLabel << aPointYDegLabel
180 << aPointXMinLabel << aPointYMinLabel
181 << aPointXSecLabel << aPointYSecLabel;
183 QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
184 QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 90, 1, myTransformGroup );
185 QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
186 QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
187 QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
188 QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
190 QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
191 QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
193 QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
194 QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
196 int aRow = 4 * aPointType + 3;
197 if ( aPointType == HYDROGUI_PrsImage::PointC )
199 myPointCEnabler = new QCheckBox( myTransformGroup );
200 aTransformLayout->addWidget( myPointCEnabler, aRow, 0, 1, 2, Qt::AlignHCenter );
201 aTransformLayout->addWidget( aPointBtn, aRow, 2, 1, 7 );
205 aTransformLayout->addWidget( aPointBtn, aRow, 0, 1, 9 );
208 aTransformLayout->addWidget( aPointXLabel, aRow + 1, 0 );
209 aTransformLayout->addWidget( aPointX, aRow + 1, 1 );
210 aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
211 aTransformLayout->addWidget( aPointXDeg, aRow + 1, 3 );
212 aTransformLayout->addWidget( aPointXDegLabel, aRow + 1, 4 );
213 aTransformLayout->addWidget( aPointXMin, aRow + 1, 5 );
214 aTransformLayout->addWidget( aPointXMinLabel, aRow + 1, 6 );
215 aTransformLayout->addWidget( aPointXSec, aRow + 1, 7 );
216 aTransformLayout->addWidget( aPointXSecLabel, aRow + 1, 8 );
218 aTransformLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 );
219 aTransformLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 );
221 aTransformLayout->addWidget( aPointYLabel, aRow + 2, 0 );
222 aTransformLayout->addWidget( aPointY, aRow + 2, 1 );
223 aTransformLayout->addWidget( aPointYDeg, aRow + 2, 3 );
224 aTransformLayout->addWidget( aPointYDegLabel, aRow + 2, 4 );
225 aTransformLayout->addWidget( aPointYMin, aRow + 2, 5 );
226 aTransformLayout->addWidget( aPointYMinLabel, aRow + 2, 6 );
227 aTransformLayout->addWidget( aPointYSec, aRow + 2, 7 );
228 aTransformLayout->addWidget( aPointYSecLabel, aRow + 2, 8 );
230 aTransformLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 );
231 aTransformLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
233 if( aPointType != HYDROGUI_PrsImage::PointC )
235 QFrame* aLine = new QFrame( myTransformGroup );
236 aLine->setFrameShape( QFrame::HLine );
237 aLine->setFrameShadow( QFrame::Sunken );
238 aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
241 myPointBtnMap[ aPointType ] = aPointBtn;
242 myPointXMap[ aPointType ] = aPointX;
243 myPointYMap[ aPointType ] = aPointY;
244 myPointXDegMap[ aPointType ] = aPointXDeg;
245 myPointYDegMap[ aPointType ] = aPointYDeg;
246 myPointXMinMap[ aPointType ] = aPointXMin;
247 myPointYMinMap[ aPointType ] = aPointYMin;
248 myPointXSecMap[ aPointType ] = aPointXSec;
249 myPointYSecMap[ aPointType ] = aPointYSec;
251 myCartPointXMap[ aPointType ] = aCartPointX;
252 myCartPointYMap[ aPointType ] = aCartPointY;
254 myRefPointXMap[ aPointType ] = aRefPointX;
255 myRefPointYMap[ aPointType ] = aRefPointY;
257 connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
259 connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
260 connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
262 connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
263 connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
264 connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
265 connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
266 connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
267 connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
269 connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
270 connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
272 connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
273 connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
276 // Connect checkbox enabling point C
277 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
278 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
279 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
280 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
281 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
282 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
283 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
284 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
285 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
286 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
287 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
288 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
289 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
291 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), SIGNAL( setIsByTwoPoints( bool ) ) );
293 aTransformLayout->setColumnStretch( 1, 1 ); // double
294 aTransformLayout->setColumnStretch( 3, 1 ); // degrees
295 aTransformLayout->setColumnStretch( 5, 1 ); // minutes
296 aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
299 addWidget( myFileNameGroup );
300 addWidget( myImageNameGroup );
301 addWidget( myTransformGroup );
304 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
306 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
307 this, SLOT( onModeActivated( int ) ) );
309 connect( myRefImage, SIGNAL( activated( const QString& ) ),
310 this, SLOT( onRefImageActivated( const QString& ) ) );
312 //setTransformationMode( HYDROData_Image::ManualCartesian );
314 setMinimumWidth( 350 );
317 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
321 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
323 myFileNameGroup->setVisible( !theIsEdit );
324 myImageNameGroup->setEnabled( theIsEdit );
325 myTransformGroup->setEnabled( theIsEdit );
328 void HYDROGUI_ImportImageDlg::reset()
331 myImageName->clear();
332 myImageNameGroup->setEnabled( false );
333 for( int aPointType = HYDROGUI_PrsImage::PointA;
334 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
336 QPushButton* aBtn = myPointBtnMap[ aPointType ];
337 bool anIsBlocked = aBtn->blockSignals( true );
338 aBtn->setChecked( false );
339 aBtn->blockSignals( anIsBlocked );
341 myPointXMap[ aPointType ]->clear();
342 myPointYMap[ aPointType ]->clear();
343 myPointXDegMap[ aPointType ]->clear();
344 myPointYDegMap[ aPointType ]->clear();
345 myPointXMinMap[ aPointType ]->clear();
346 myPointYMinMap[ aPointType ]->clear();
347 myPointXSecMap[ aPointType ]->clear();
348 myPointYSecMap[ aPointType ]->clear();
350 myRefPointXMap[ aPointType ]->clear();
351 myRefPointYMap[ aPointType ]->clear();
353 myCartPointXMap[ aPointType ]->clear();
354 myCartPointYMap[ aPointType ]->clear();
356 myPointCEnabler->setChecked( true );
357 myPointCEnabler->toggle();
358 myTransformGroup->setEnabled( false );
361 setTransformationMode( HYDROData_Image::ManualCartesian );
363 myPrsPointDataList.clear();
365 myIsInitialized = false;
368 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
370 myImageName->setText( theName );
373 QString HYDROGUI_ImportImageDlg::getImageName() const
375 return myImageName->text();
378 void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
380 myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
383 QString HYDROGUI_ImportImageDlg::getRefImageName() const
385 return myRefImage->currentText();
388 QString HYDROGUI_ImportImageDlg::getFileName() const
390 return myFileName->text();
393 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
394 const bool theIsRefImage )
396 int aWidth = theSize.width();
397 int aHeight = theSize.height();
398 for( int aPointType = HYDROGUI_PrsImage::PointA;
399 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
403 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
404 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
408 myPointXMap[ aPointType ]->setRange( 0, aWidth );
409 myPointYMap[ aPointType ]->setRange( 0, aHeight );
414 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
416 myModeGroup->button( theMode )->setChecked( true );
417 onModeActivated( theMode );
420 int HYDROGUI_ImportImageDlg::getTransformationMode() const
422 return myModeGroup->checkedId();
425 void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
427 myPointCEnabler->setChecked( !theIsByTwoPoints );
430 bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
432 return !myPointCEnabler->isChecked();
435 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
436 const bool theIsOnlyInput,
437 const bool theIsRefImage )
439 blockSignalsGeodesic( true );
440 blockSignalsCartesian( true );
441 for( int aPointType = HYDROGUI_PrsImage::PointA;
442 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
444 if( theMap.contains( aPointType ) )
446 const TransformationData& aData = theMap[ aPointType ];
448 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
449 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
450 aPointX->setValue( aData.ImagePoint.x() );
451 aPointY->setValue( aData.ImagePoint.y() );
453 if( !theIsOnlyInput && !theIsRefImage )
455 QPointF aLPoint = aData.GeodesicPoint;
456 int aXDeg = 0, aYDeg = 0;
457 int aXMin = 0, aYMin = 0;
458 double aXSec = 0, aYSec = 0;
459 HYDROData_Lambert93::degToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
460 HYDROData_Lambert93::degToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
462 myPointXDegMap[ aPointType ]->setValue( aXDeg );
463 myPointYDegMap[ aPointType ]->setValue( aYDeg );
464 myPointXMinMap[ aPointType ]->setValue( aXMin );
465 myPointYMinMap[ aPointType ]->setValue( aYMin );
466 myPointXSecMap[ aPointType ]->setValue( aXSec );
467 myPointYSecMap[ aPointType ]->setValue( aYSec );
469 QPointF aCPoint = aData.CartesianPoint;
470 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
471 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
475 blockSignalsGeodesic( false );
476 blockSignalsCartesian( false );
479 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
480 const bool theIsRefImage ) const
483 for( int aPointType = HYDROGUI_PrsImage::PointA;
484 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
487 for( int i = 0; i < 10; i++ )
490 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
491 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
492 int aX1 = aPointX->text().toInt( &anIsOk[0] );
493 int aY1 = aPointY->text().toInt( &anIsOk[1] );
495 int aXDeg = 0, aYDeg = 0;
496 int aXMin = 0, aYMin = 0;
497 double aXSec = 0, aYSec = 0;
498 double aXCart = 0, aYCart = 0;
501 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
502 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
503 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
504 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
505 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
506 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
508 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
509 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
512 for( int i = 0; i < 10; i++ )
516 double aX2 = 0, aY2 = 0;
517 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aX2 );
518 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aY2 );
520 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
521 theMap[ aPointType ] = aData;
526 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
528 myPrsPointDataList = theList;
530 if( !myPrsPointDataList.isEmpty() )
532 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
535 myRefImage->addItem( "" ); // first empty item
537 PrsPointDataListIterator anIter( myPrsPointDataList );
538 while( anIter.hasNext() )
539 myRefImage->addItem( anIter.next().first );
542 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
545 void HYDROGUI_ImportImageDlg::initializePointSelection()
547 if( myIsInitialized )
550 myIsInitialized = true;
552 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
554 double aCartX0 = LAMBERT_X0;
555 double aCartY0 = LAMBERT_Y0;
557 blockSignalsCartesian( true );
559 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
560 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + IMG_DELTA );
562 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + IMG_DELTA );
563 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + IMG_DELTA );
565 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
566 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
568 for( int aPointType = HYDROGUI_PrsImage::PointA;
569 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
570 onCartesianCoordChanged( aPointType );
572 blockSignalsCartesian( false );
575 HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
577 const QPoint& theLocalPoint,
578 const QPointF& theGlobalPoint )
580 TransformationData aResTrsfData;
581 aResTrsfData.ImagePoint = theLocalPoint;
583 double arx = theGlobalPoint.x();
584 double ary = theGlobalPoint.y();
585 if ( theMode == HYDROData_Image::ManualGeodesic )
587 // Geodesic to Cartesian
588 double aXCart = 0, aYCart = 0;
589 // Interpreting arY as attitude and arX as longitude
590 HYDROData_Lambert93::toXY( ary, arx, aXCart, aYCart );
592 aResTrsfData.GeodesicPoint = theGlobalPoint;
593 aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
595 else if ( theMode == HYDROData_Image::ManualCartesian )
597 // Cartesian to Geodesic
598 double aLonDeg = 0, aLatDeg = 0;
599 HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
601 aResTrsfData.CartesianPoint = theGlobalPoint;
602 aResTrsfData.GeodesicPoint = QPointF( aLonDeg, aLatDeg );
608 void HYDROGUI_ImportImageDlg::onBrowse()
610 QString aFilter( tr( "IMAGE_FILTER" ) );
611 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
612 if( !aFileName.isEmpty() )
614 QImage anImage( aFileName );
615 if( anImage.isNull() )
617 QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
618 QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
619 arg( aFileName ).arg( QFileInfo( aFileName ).suffix() );
620 SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
624 myFileName->setText( aFileName );
625 emit createPreview( anImage );
626 myImageNameGroup->setEnabled( true );
627 myTransformGroup->setEnabled( true );
632 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
634 bool anIsManualGeodesic = theMode == HYDROData_Image::ManualGeodesic;
635 bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
636 bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
638 myRefImage->setEnabled( anIsRefImage );
640 for( int aPointType = HYDROGUI_PrsImage::PointA;
641 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
643 myPointXDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
644 myPointYDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
645 myPointXMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
646 myPointYMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
647 myPointXSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
648 myPointYSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
650 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
651 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
653 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
654 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
657 QListIterator<QLabel*> anIter( myGeodesicLabels );
658 while( anIter.hasNext() )
659 anIter.next()->setVisible( anIsManualGeodesic );
661 emit modeActivated( theMode );
664 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
666 emit refImageActivated( theName );
669 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
671 int aPointType = HYDROGUI_PrsImage::None;
674 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
675 while( anIter.hasNext() )
677 int aBtnPointType = anIter.next().key();
678 QPushButton* aBtn = anIter.value();
679 if( aBtn == sender() )
680 aPointType = aBtnPointType;
683 bool anIsBlocked = aBtn->blockSignals( true );
684 aBtn->setChecked( false );
685 aBtn->blockSignals( anIsBlocked );
689 emit activatePointSelection( aPointType );
692 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
694 QObject* aSender = sender();
698 for( int aPointType = HYDROGUI_PrsImage::PointA;
699 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
701 if( aSender == myPointXMap[ aPointType ] ||
702 aSender == myPointYMap[ aPointType ] )
704 bool anIsY = aSender == myPointYMap[ aPointType ];
705 emit pointCoordChanged( false, aPointType, anIsY, theValue );
707 else if( aSender == myRefPointXMap[ aPointType ] ||
708 aSender == myRefPointYMap[ aPointType ] )
710 bool anIsY = aSender == myRefPointYMap[ aPointType ];
711 emit pointCoordChanged( true, aPointType, anIsY, theValue );
716 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged()
718 QObject* aSender = sender();
722 for( int aPointType = HYDROGUI_PrsImage::PointA;
723 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
725 if( aSender == myPointXDegMap[ aPointType ] ||
726 aSender == myPointYDegMap[ aPointType ] ||
727 aSender == myPointXMinMap[ aPointType ] ||
728 aSender == myPointYMinMap[ aPointType ] ||
729 aSender == myPointXSecMap[ aPointType ] ||
730 aSender == myPointYSecMap[ aPointType ] )
732 onGeodesicCoordChanged( aPointType );
738 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged( const int thePointType )
741 for( int i = 0; i < 6; i++ )
744 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
745 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
746 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
747 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
748 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
749 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
751 for( int i = 0; i < 6; i++ )
755 double aLonDeg = 0, aLatDeg = 0;
756 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
757 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
759 double aXCart = 0, aYCart = 0;
760 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
762 blockSignalsCartesian( true );
764 myCartPointXMap[ thePointType ]->setValue( aXCart );
765 myCartPointYMap[ thePointType ]->setValue( aYCart );
767 blockSignalsCartesian( false );
770 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
772 QObject* aSender = sender();
776 for( int aPointType = HYDROGUI_PrsImage::PointA;
777 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
779 if( aSender == myCartPointXMap[ aPointType ] ||
780 aSender == myCartPointYMap[ aPointType ] )
782 onCartesianCoordChanged( aPointType );
788 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
791 for( int i = 0; i < 2; i++ )
794 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
795 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
797 for( int i = 0; i < 2; i++ )
801 double aLonDeg = 0, aLatDeg = 0;
802 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
804 int aXDeg = 0, aYDeg = 0;
805 int aXMin = 0, aYMin = 0;
806 double aXSec = 0, aYSec = 0;
807 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
808 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
810 blockSignalsGeodesic( true );
812 myPointXDegMap[ thePointType ]->setValue( aXDeg );
813 myPointYDegMap[ thePointType ]->setValue( aYDeg );
814 myPointXMinMap[ thePointType ]->setValue( aXMin );
815 myPointYMinMap[ thePointType ]->setValue( aYMin );
816 myPointXSecMap[ thePointType ]->setValue( aXSec );
817 myPointYSecMap[ thePointType ]->setValue( aYSec );
819 blockSignalsGeodesic( false );
822 void HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
824 for( int aPointType = HYDROGUI_PrsImage::PointA;
825 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
827 myPointXDegMap[ aPointType ]->blockSignals( theState );
828 myPointXMinMap[ aPointType ]->blockSignals( theState );
829 myPointXSecMap[ aPointType ]->blockSignals( theState );
830 myPointYDegMap[ aPointType ]->blockSignals( theState );
831 myPointYMinMap[ aPointType ]->blockSignals( theState );
832 myPointYSecMap[ aPointType ]->blockSignals( theState );
836 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
838 for( int aPointType = HYDROGUI_PrsImage::PointA;
839 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
841 myCartPointXMap[ aPointType ]->blockSignals( theState );
842 myCartPointYMap[ aPointType ]->blockSignals( theState );