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>
30 #include <SUIT_FileDlg.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
34 #include <QtxDoubleSpinBox.h>
35 #include <QtxIntSpinBox.h>
37 #include <QButtonGroup>
45 #include <QPushButton>
46 #include <QRadioButton>
47 #include <QToolButton>
50 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
51 : HYDROGUI_InputPanel( theModule, theTitle ),
52 myIsInitialized( false )
54 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
56 // Import image from file
57 myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
59 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
61 myFileName = new QLineEdit( myFileNameGroup );
62 myFileName->setReadOnly( true );
64 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
65 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
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 );
75 myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
77 QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
78 myImageName = new QLineEdit( myImageNameGroup );
80 QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
81 anImageNameLayout->setMargin( 5 );
82 anImageNameLayout->setSpacing( 5 );
83 anImageNameLayout->addWidget( anImageNameLabel );
84 anImageNameLayout->addWidget( myImageName );
87 myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ) );
89 // Make a pixmap for arrow
90 QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
92 QPicture anArrowPicture;
93 anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
96 aPainter.begin( &anArrowPicture );
97 aPainter.drawPixmap( 0, 0, anArrowPixmap );
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 );
104 myModeGroup = new QButtonGroup( myTransformGroup );
105 myModeGroup->addButton( aManualCartesianBtn, ManualCartesian );
106 myModeGroup->addButton( aManualLambertBtn, ManualLambert );
107 myModeGroup->addButton( aRefImageBtn, RefImage );
109 myRefImage = new QComboBox( myTransformGroup );
111 QGridLayout* aModeLayout = new QGridLayout();
112 aModeLayout->setMargin( 0 );
113 aModeLayout->setSpacing( 5 );
114 aModeLayout->addWidget( aManualCartesianBtn, 0, 0 );
115 aModeLayout->addWidget( aManualLambertBtn, 1, 0 );
116 aModeLayout->addWidget( aRefImageBtn, 2, 0 );
117 aModeLayout->addWidget( myRefImage, 2, 1 );
118 aModeLayout->setColumnStretch( 1, 1 );
120 QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
121 aTransformLayout->setMargin( 5 );
122 aTransformLayout->setSpacing( 5 );
123 aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
125 QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
126 QLabel* aGeodesicLabel = new QLabel( "GEODESIC", myTransformGroup );
127 QLabel* aLambertLabel = new QLabel( "LAMBERT93", myTransformGroup );
128 QLabel* aRefImageLabel = new QLabel( "REFERENCE_IMAGE_CS", myTransformGroup );
130 aTransformLayout->addWidget( aImageCSLabel, 2, 1 );
131 aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
132 aTransformLayout->addWidget( aLambertLabel, 2, 3, 1, 6 );
133 aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
135 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
136 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
137 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
138 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
139 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
140 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
141 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
142 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
143 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
145 for( int aPointType = HYDROGUI_PrsImage::PointA;
146 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
151 case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
152 case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
153 case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
155 QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
156 aPointBtn->setCheckable( true );
158 QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
159 QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
161 QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
162 QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
164 QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
165 aPointArrowLabel->setPicture( anArrowPicture );
167 QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
168 QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
169 QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
170 QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
171 QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
172 QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
173 myLambertLabels << aPointXDegLabel << aPointYDegLabel
174 << aPointXMinLabel << aPointYMinLabel
175 << aPointXSecLabel << aPointYSecLabel;
177 QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
178 QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( -90, 90, 1, myTransformGroup );
179 QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
180 QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
181 QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
182 QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
184 QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
185 QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
187 QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
188 QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
190 int aRow = 4 * aPointType + 3;
191 if ( aPointType == HYDROGUI_PrsImage::PointC )
193 myPointCEnabler = new QCheckBox( myTransformGroup );
194 aTransformLayout->addWidget( myPointCEnabler, aRow, 0, 1, 2, Qt::AlignHCenter );
195 aTransformLayout->addWidget( aPointBtn, aRow, 2, 1, 7 );
199 aTransformLayout->addWidget( aPointBtn, aRow, 0, 1, 9 );
202 aTransformLayout->addWidget( aPointXLabel, aRow + 1, 0 );
203 aTransformLayout->addWidget( aPointX, aRow + 1, 1 );
204 aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
205 aTransformLayout->addWidget( aPointXDeg, aRow + 1, 3 );
206 aTransformLayout->addWidget( aPointXDegLabel, aRow + 1, 4 );
207 aTransformLayout->addWidget( aPointXMin, aRow + 1, 5 );
208 aTransformLayout->addWidget( aPointXMinLabel, aRow + 1, 6 );
209 aTransformLayout->addWidget( aPointXSec, aRow + 1, 7 );
210 aTransformLayout->addWidget( aPointXSecLabel, aRow + 1, 8 );
212 aTransformLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 );
213 aTransformLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 );
215 aTransformLayout->addWidget( aPointYLabel, aRow + 2, 0 );
216 aTransformLayout->addWidget( aPointY, aRow + 2, 1 );
217 aTransformLayout->addWidget( aPointYDeg, aRow + 2, 3 );
218 aTransformLayout->addWidget( aPointYDegLabel, aRow + 2, 4 );
219 aTransformLayout->addWidget( aPointYMin, aRow + 2, 5 );
220 aTransformLayout->addWidget( aPointYMinLabel, aRow + 2, 6 );
221 aTransformLayout->addWidget( aPointYSec, aRow + 2, 7 );
222 aTransformLayout->addWidget( aPointYSecLabel, aRow + 2, 8 );
224 aTransformLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 );
225 aTransformLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
227 if( aPointType != HYDROGUI_PrsImage::PointC )
229 QFrame* aLine = new QFrame( myTransformGroup );
230 aLine->setFrameShape( QFrame::HLine );
231 aLine->setFrameShadow( QFrame::Sunken );
232 aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
235 myPointBtnMap[ aPointType ] = aPointBtn;
236 myPointXMap[ aPointType ] = aPointX;
237 myPointYMap[ aPointType ] = aPointY;
238 myPointXDegMap[ aPointType ] = aPointXDeg;
239 myPointYDegMap[ aPointType ] = aPointYDeg;
240 myPointXMinMap[ aPointType ] = aPointXMin;
241 myPointYMinMap[ aPointType ] = aPointYMin;
242 myPointXSecMap[ aPointType ] = aPointXSec;
243 myPointYSecMap[ aPointType ] = aPointYSec;
245 myCartPointXMap[ aPointType ] = aCartPointX;
246 myCartPointYMap[ aPointType ] = aCartPointY;
248 myRefPointXMap[ aPointType ] = aRefPointX;
249 myRefPointYMap[ aPointType ] = aRefPointY;
251 connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
253 connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
254 connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
256 connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
257 connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
258 connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
259 connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
260 connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
261 connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
263 connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
264 connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
266 connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
267 connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
270 // Connect checkbox enabling point C
271 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
272 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
273 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
274 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
275 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
276 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
277 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
278 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
279 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
280 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
281 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
282 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
283 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
285 aTransformLayout->setColumnStretch( 1, 1 ); // double
286 aTransformLayout->setColumnStretch( 3, 1 ); // degrees
287 aTransformLayout->setColumnStretch( 5, 1 ); // minutes
288 aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
291 addWidget( myFileNameGroup );
292 addWidget( myImageNameGroup );
293 addWidget( myTransformGroup );
296 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
298 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
299 this, SLOT( onModeActivated( int ) ) );
301 connect( myRefImage, SIGNAL( activated( const QString& ) ),
302 this, SLOT( onRefImageActivated( const QString& ) ) );
304 setTransformationMode( ManualLambert );
306 setMinimumWidth( 350 );
309 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
311 delete myFileNameGroup;
312 delete myImageNameGroup;
313 delete myTransformGroup;
316 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
318 myFileNameGroup->setVisible( !theIsEdit );
319 myImageNameGroup->setEnabled( theIsEdit );
320 myTransformGroup->setEnabled( theIsEdit );
323 void HYDROGUI_ImportImageDlg::reset()
326 myImageName->clear();
327 myImageNameGroup->setEnabled( false );
328 for( int aPointType = HYDROGUI_PrsImage::PointA;
329 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
331 QPushButton* aBtn = myPointBtnMap[ aPointType ];
332 bool anIsBlocked = aBtn->blockSignals( true );
333 aBtn->setChecked( false );
334 aBtn->blockSignals( anIsBlocked );
336 myPointXMap[ aPointType ]->clear();
337 myPointYMap[ aPointType ]->clear();
338 myPointXDegMap[ aPointType ]->clear();
339 myPointYDegMap[ aPointType ]->clear();
340 myPointXMinMap[ aPointType ]->clear();
341 myPointYMinMap[ aPointType ]->clear();
342 myPointXSecMap[ aPointType ]->clear();
343 myPointYSecMap[ aPointType ]->clear();
345 myRefPointXMap[ aPointType ]->clear();
346 myRefPointYMap[ aPointType ]->clear();
348 myCartPointXMap[ aPointType ]->clear();
349 myCartPointYMap[ aPointType ]->clear();
351 myPointCEnabler->setChecked( true );
352 myPointCEnabler->toggle();
353 myTransformGroup->setEnabled( false );
356 setTransformationMode( ManualLambert );
358 myPrsPointDataList.clear();
360 myIsInitialized = false;
363 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
365 myImageName->setText( theName );
368 QString HYDROGUI_ImportImageDlg::getImageName() const
370 return myImageName->text();
373 QString HYDROGUI_ImportImageDlg::getFileName() const
375 return myFileName->text();
378 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
379 const bool theIsRefImage )
381 int aWidth = theSize.width();
382 int aHeight = theSize.height();
383 for( int aPointType = HYDROGUI_PrsImage::PointA;
384 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
388 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
389 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
393 myPointXMap[ aPointType ]->setRange( 0, aWidth );
394 myPointYMap[ aPointType ]->setRange( 0, aHeight );
399 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
401 myModeGroup->button( theMode )->setChecked( true );
402 onModeActivated( theMode );
405 int HYDROGUI_ImportImageDlg::getTransformationMode() const
407 return myModeGroup->checkedId();
410 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
411 const bool theIsOnlyInput,
412 const bool theIsRefImage )
414 blockSignalsLambert( true );
415 blockSignalsCartesian( true );
416 for( int aPointType = HYDROGUI_PrsImage::PointA;
417 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
419 if( theMap.contains( aPointType ) )
421 const TransformationData& aData = theMap[ aPointType ];
423 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
424 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
425 aPointX->setValue( aData.ImagePoint.x() );
426 aPointY->setValue( aData.ImagePoint.y() );
428 if( !theIsOnlyInput && !theIsRefImage )
430 QPointF aLPoint = aData.LambertPoint;
431 int aXDeg = 0, aYDeg = 0;
432 int aXMin = 0, aYMin = 0;
433 double aXSec = 0, aYSec = 0;
434 HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
435 HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
437 myPointXDegMap[ aPointType ]->setValue( aXDeg );
438 myPointYDegMap[ aPointType ]->setValue( aYDeg );
439 myPointXMinMap[ aPointType ]->setValue( aXMin );
440 myPointYMinMap[ aPointType ]->setValue( aYMin );
441 myPointXSecMap[ aPointType ]->setValue( aXSec );
442 myPointYSecMap[ aPointType ]->setValue( aYSec );
444 QPointF aCPoint = aData.CartesianPoint;
445 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
446 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
450 blockSignalsLambert( false );
451 blockSignalsCartesian( false );
454 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
455 const bool theIsRefImage ) const
458 for( int aPointType = HYDROGUI_PrsImage::PointA;
459 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
462 for( int i = 0; i < 10; i++ )
465 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
466 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
467 int aX1 = aPointX->text().toInt( &anIsOk[0] );
468 int aY1 = aPointY->text().toInt( &anIsOk[1] );
470 int aXDeg = 0, aYDeg = 0;
471 int aXMin = 0, aYMin = 0;
472 double aXSec = 0, aYSec = 0;
473 double aXCart = 0, aYCart = 0;
476 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
477 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
478 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
479 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
480 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
481 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
483 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
484 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
487 for( int i = 0; i < 10; i++ )
491 double aX2 = 0, aY2 = 0;
492 HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
493 HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
495 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
496 theMap[ aPointType ] = aData;
501 QString HYDROGUI_ImportImageDlg::getRefImageName() const
503 return myRefImage->currentText();
506 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
508 myPrsPointDataList = theList;
510 if( !myPrsPointDataList.isEmpty() )
512 myModeGroup->button( RefImage )->setEnabled( true );
515 myRefImage->addItem( "" ); // first empty item
517 PrsPointDataListIterator anIter( myPrsPointDataList );
518 while( anIter.hasNext() )
519 myRefImage->addItem( anIter.next().first );
522 myModeGroup->button( RefImage )->setEnabled( false );
525 void HYDROGUI_ImportImageDlg::initializePointSelection()
527 if( myIsInitialized )
530 myIsInitialized = true;
532 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
536 blockSignalsLambert( true );
538 myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
539 myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
540 myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
541 myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
542 myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
543 myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
545 myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
546 myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
547 myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
548 myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
549 myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
550 myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
552 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
553 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
554 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
555 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
556 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
557 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
559 for( int aPointType = HYDROGUI_PrsImage::PointA;
560 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
561 onLambertCoordChanged( aPointType );
563 blockSignalsLambert( false );
566 //double aCartX0 = 600000;
567 //double aCartY0 = 6800000;
571 blockSignalsCartesian( true );
573 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
574 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
576 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
577 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
579 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
580 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
582 for( int aPointType = HYDROGUI_PrsImage::PointA;
583 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
584 onCartesianCoordChanged( aPointType );
586 blockSignalsCartesian( false );
589 void HYDROGUI_ImportImageDlg::onBrowse()
591 QString aFilter( tr( "IMAGE_FILTER" ) );
592 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
593 if( !aFileName.isEmpty() )
595 QImage anImage( aFileName );
596 if( !anImage.isNull() )
598 myFileName->setText( aFileName );
599 emit createPreview( anImage );
600 myImageNameGroup->setEnabled( true );
601 myTransformGroup->setEnabled( true );
606 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
608 bool anIsManualLambert = theMode == ManualLambert;
609 bool anIsManualCartesian = theMode == ManualCartesian;
610 bool anIsRefImage = theMode == RefImage;
612 myRefImage->setEnabled( anIsRefImage );
614 for( int aPointType = HYDROGUI_PrsImage::PointA;
615 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
617 myPointXDegMap[ aPointType ]->setVisible( anIsManualLambert );
618 myPointYDegMap[ aPointType ]->setVisible( anIsManualLambert );
619 myPointXMinMap[ aPointType ]->setVisible( anIsManualLambert );
620 myPointYMinMap[ aPointType ]->setVisible( anIsManualLambert );
621 myPointXSecMap[ aPointType ]->setVisible( anIsManualLambert );
622 myPointYSecMap[ aPointType ]->setVisible( anIsManualLambert );
624 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
625 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
627 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
628 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
631 QListIterator<QLabel*> anIter( myLambertLabels );
632 while( anIter.hasNext() )
633 anIter.next()->setVisible( anIsManualLambert );
635 emit modeActivated( theMode );
638 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
640 emit refImageActivated( theName );
643 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
645 int aPointType = HYDROGUI_PrsImage::None;
648 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
649 while( anIter.hasNext() )
651 int aBtnPointType = anIter.next().key();
652 QPushButton* aBtn = anIter.value();
653 if( aBtn == sender() )
654 aPointType = aBtnPointType;
657 bool anIsBlocked = aBtn->blockSignals( true );
658 aBtn->setChecked( false );
659 aBtn->blockSignals( anIsBlocked );
663 emit activatePointSelection( aPointType );
666 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
668 QObject* aSender = sender();
672 for( int aPointType = HYDROGUI_PrsImage::PointA;
673 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
675 if( aSender == myPointXMap[ aPointType ] ||
676 aSender == myPointYMap[ aPointType ] )
678 bool anIsY = aSender == myPointYMap[ aPointType ];
679 emit pointCoordChanged( false, aPointType, anIsY, theValue );
681 else if( aSender == myRefPointXMap[ aPointType ] ||
682 aSender == myRefPointYMap[ aPointType ] )
684 bool anIsY = aSender == myRefPointYMap[ aPointType ];
685 emit pointCoordChanged( true, aPointType, anIsY, theValue );
690 void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
692 QObject* aSender = sender();
696 for( int aPointType = HYDROGUI_PrsImage::PointA;
697 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
699 if( aSender == myPointXDegMap[ aPointType ] ||
700 aSender == myPointYDegMap[ aPointType ] ||
701 aSender == myPointXMinMap[ aPointType ] ||
702 aSender == myPointYMinMap[ aPointType ] ||
703 aSender == myPointXSecMap[ aPointType ] ||
704 aSender == myPointYSecMap[ aPointType ] )
706 onLambertCoordChanged( aPointType );
712 void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
715 for( int i = 0; i < 6; i++ )
718 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
719 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
720 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
721 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
722 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
723 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
725 for( int i = 0; i < 6; i++ )
729 double aLonDeg = 0, aLatDeg = 0;
730 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
731 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
733 double aXCart = 0, aYCart = 0;
734 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
736 blockSignalsCartesian( true );
738 myCartPointXMap[ thePointType ]->setValue( aXCart );
739 myCartPointYMap[ thePointType ]->setValue( aYCart );
741 blockSignalsCartesian( false );
744 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
746 QObject* aSender = sender();
750 for( int aPointType = HYDROGUI_PrsImage::PointA;
751 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
753 if( aSender == myCartPointXMap[ aPointType ] ||
754 aSender == myCartPointYMap[ aPointType ] )
756 onCartesianCoordChanged( aPointType );
762 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
765 for( int i = 0; i < 2; i++ )
768 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
769 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
771 for( int i = 0; i < 2; i++ )
775 double aLonDeg = 0, aLatDeg = 0;
776 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
778 int aXDeg = 0, aYDeg = 0;
779 int aXMin = 0, aYMin = 0;
780 double aXSec = 0, aYSec = 0;
781 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
782 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
784 blockSignalsLambert( true );
786 myPointXDegMap[ thePointType ]->setValue( aXDeg );
787 myPointYDegMap[ thePointType ]->setValue( aYDeg );
788 myPointXMinMap[ thePointType ]->setValue( aXMin );
789 myPointYMinMap[ thePointType ]->setValue( aYMin );
790 myPointXSecMap[ thePointType ]->setValue( aXSec );
791 myPointYSecMap[ thePointType ]->setValue( aYSec );
793 blockSignalsLambert( false );
796 void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
798 for( int aPointType = HYDROGUI_PrsImage::PointA;
799 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
801 myPointXDegMap[ aPointType ]->blockSignals( theState );
802 myPointXMinMap[ aPointType ]->blockSignals( theState );
803 myPointXSecMap[ aPointType ]->blockSignals( theState );
804 myPointYDegMap[ aPointType ]->blockSignals( theState );
805 myPointYMinMap[ aPointType ]->blockSignals( theState );
806 myPointYSecMap[ aPointType ]->blockSignals( theState );
810 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
812 for( int aPointType = HYDROGUI_PrsImage::PointA;
813 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
815 myCartPointXMap[ aPointType ]->blockSignals( theState );
816 myCartPointYMap[ aPointType ]->blockSignals( theState );