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 );
196 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), aPointBtn, SLOT( setEnabled( bool ) ) );
200 aTransformLayout->addWidget( aPointBtn, aRow, 0, 1, 9 );
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 );
213 aTransformLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 );
214 aTransformLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 );
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 );
225 aTransformLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 );
226 aTransformLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
228 if( aPointType != HYDROGUI_PrsImage::PointC )
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 );
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;
246 myCartPointXMap[ aPointType ] = aCartPointX;
247 myCartPointYMap[ aPointType ] = aCartPointY;
249 myRefPointXMap[ aPointType ] = aRefPointX;
250 myRefPointYMap[ aPointType ] = aRefPointY;
252 connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
254 connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
255 connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
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() ) );
264 connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
265 connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
267 connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
268 connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
270 aTransformLayout->setColumnStretch( 1, 1 ); // double
271 aTransformLayout->setColumnStretch( 3, 1 ); // degrees
272 aTransformLayout->setColumnStretch( 5, 1 ); // minutes
273 aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
276 addWidget( myFileNameGroup );
277 addWidget( myImageNameGroup );
278 addWidget( myTransformGroup );
281 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
283 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
284 this, SLOT( onModeActivated( int ) ) );
286 connect( myRefImage, SIGNAL( activated( const QString& ) ),
287 this, SLOT( onRefImageActivated( const QString& ) ) );
289 setTransformationMode( ManualLambert );
291 setMinimumWidth( 350 );
294 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
296 delete myFileNameGroup;
297 delete myImageNameGroup;
298 delete myTransformGroup;
301 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
303 myFileNameGroup->setVisible( !theIsEdit );
304 myImageNameGroup->setEnabled( theIsEdit );
305 myTransformGroup->setEnabled( theIsEdit );
308 void HYDROGUI_ImportImageDlg::reset()
311 myImageName->clear();
312 myImageNameGroup->setEnabled( false );
313 for( int aPointType = HYDROGUI_PrsImage::PointA;
314 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
316 QPushButton* aBtn = myPointBtnMap[ aPointType ];
317 bool anIsBlocked = aBtn->blockSignals( true );
318 aBtn->setChecked( false );
319 aBtn->blockSignals( anIsBlocked );
321 myPointXMap[ aPointType ]->clear();
322 myPointYMap[ aPointType ]->clear();
323 myPointXDegMap[ aPointType ]->clear();
324 myPointYDegMap[ aPointType ]->clear();
325 myPointXMinMap[ aPointType ]->clear();
326 myPointYMinMap[ aPointType ]->clear();
327 myPointXSecMap[ aPointType ]->clear();
328 myPointYSecMap[ aPointType ]->clear();
330 myRefPointXMap[ aPointType ]->clear();
331 myRefPointYMap[ aPointType ]->clear();
333 myCartPointXMap[ aPointType ]->clear();
334 myCartPointYMap[ aPointType ]->clear();
336 myPointCEnabler->setChecked( false );
337 myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
338 myTransformGroup->setEnabled( false );
341 setTransformationMode( ManualLambert );
343 myPrsPointDataList.clear();
345 myIsInitialized = false;
348 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
350 myImageName->setText( theName );
353 QString HYDROGUI_ImportImageDlg::getImageName() const
355 return myImageName->text();
358 QString HYDROGUI_ImportImageDlg::getFileName() const
360 return myFileName->text();
363 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
364 const bool theIsRefImage )
366 int aWidth = theSize.width();
367 int aHeight = theSize.height();
368 for( int aPointType = HYDROGUI_PrsImage::PointA;
369 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
373 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
374 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
378 myPointXMap[ aPointType ]->setRange( 0, aWidth );
379 myPointYMap[ aPointType ]->setRange( 0, aHeight );
384 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
386 myModeGroup->button( theMode )->setChecked( true );
387 onModeActivated( theMode );
390 int HYDROGUI_ImportImageDlg::getTransformationMode() const
392 return myModeGroup->checkedId();
395 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
396 const bool theIsOnlyInput,
397 const bool theIsRefImage )
399 blockSignalsLambert( true );
400 blockSignalsCartesian( true );
401 for( int aPointType = HYDROGUI_PrsImage::PointA;
402 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
404 if( theMap.contains( aPointType ) )
406 const TransformationData& aData = theMap[ aPointType ];
408 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
409 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
410 aPointX->setValue( aData.ImagePoint.x() );
411 aPointY->setValue( aData.ImagePoint.y() );
413 if( !theIsOnlyInput && !theIsRefImage )
415 QPointF aLPoint = aData.LambertPoint;
416 int aXDeg = 0, aYDeg = 0;
417 int aXMin = 0, aYMin = 0;
418 double aXSec = 0, aYSec = 0;
419 HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
420 HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
422 myPointXDegMap[ aPointType ]->setValue( aXDeg );
423 myPointYDegMap[ aPointType ]->setValue( aYDeg );
424 myPointXMinMap[ aPointType ]->setValue( aXMin );
425 myPointYMinMap[ aPointType ]->setValue( aYMin );
426 myPointXSecMap[ aPointType ]->setValue( aXSec );
427 myPointYSecMap[ aPointType ]->setValue( aYSec );
429 QPointF aCPoint = aData.CartesianPoint;
430 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
431 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
435 blockSignalsLambert( false );
436 blockSignalsCartesian( false );
439 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
440 const bool theIsRefImage ) const
443 for( int aPointType = HYDROGUI_PrsImage::PointA;
444 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
447 for( int i = 0; i < 10; i++ )
450 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
451 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
452 int aX1 = aPointX->text().toInt( &anIsOk[0] );
453 int aY1 = aPointY->text().toInt( &anIsOk[1] );
455 int aXDeg = 0, aYDeg = 0;
456 int aXMin = 0, aYMin = 0;
457 double aXSec = 0, aYSec = 0;
458 double aXCart = 0, aYCart = 0;
461 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
462 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
463 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
464 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
465 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
466 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
468 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
469 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
472 for( int i = 0; i < 10; i++ )
476 double aX2 = 0, aY2 = 0;
477 HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
478 HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
480 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
481 theMap[ aPointType ] = aData;
486 QString HYDROGUI_ImportImageDlg::getRefImageName() const
488 return myRefImage->currentText();
491 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
493 myPrsPointDataList = theList;
495 if( !myPrsPointDataList.isEmpty() )
497 myModeGroup->button( RefImage )->setEnabled( true );
500 myRefImage->addItem( "" ); // first empty item
502 PrsPointDataListIterator anIter( myPrsPointDataList );
503 while( anIter.hasNext() )
504 myRefImage->addItem( anIter.next().first );
507 myModeGroup->button( RefImage )->setEnabled( false );
510 void HYDROGUI_ImportImageDlg::initializePointSelection()
512 if( myIsInitialized )
515 myIsInitialized = true;
517 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
521 blockSignalsLambert( true );
523 myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
524 myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
525 myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
526 myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
527 myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
528 myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
530 myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
531 myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
532 myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
533 myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
534 myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
535 myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
537 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
538 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
539 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
540 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
541 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
542 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
544 for( int aPointType = HYDROGUI_PrsImage::PointA;
545 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
546 onLambertCoordChanged( aPointType );
548 blockSignalsLambert( false );
551 //double aCartX0 = 600000;
552 //double aCartY0 = 6800000;
556 blockSignalsCartesian( true );
558 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
559 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
561 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
562 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
564 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
565 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
567 for( int aPointType = HYDROGUI_PrsImage::PointA;
568 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
569 onCartesianCoordChanged( aPointType );
571 blockSignalsCartesian( false );
574 void HYDROGUI_ImportImageDlg::onBrowse()
576 QString aFilter( tr( "IMAGE_FILTER" ) );
577 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
578 if( !aFileName.isEmpty() )
580 QImage anImage( aFileName );
581 if( !anImage.isNull() )
583 myFileName->setText( aFileName );
584 emit createPreview( anImage );
585 myImageNameGroup->setEnabled( true );
586 myTransformGroup->setEnabled( true );
591 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
593 bool anIsManualLambert = theMode == ManualLambert;
594 bool anIsManualCartesian = theMode == ManualCartesian;
595 bool anIsRefImage = theMode == RefImage;
597 myRefImage->setEnabled( anIsRefImage );
599 for( int aPointType = HYDROGUI_PrsImage::PointA;
600 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
602 myPointXDegMap[ aPointType ]->setVisible( anIsManualLambert );
603 myPointYDegMap[ aPointType ]->setVisible( anIsManualLambert );
604 myPointXMinMap[ aPointType ]->setVisible( anIsManualLambert );
605 myPointYMinMap[ aPointType ]->setVisible( anIsManualLambert );
606 myPointXSecMap[ aPointType ]->setVisible( anIsManualLambert );
607 myPointYSecMap[ aPointType ]->setVisible( anIsManualLambert );
609 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
610 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
612 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
613 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
616 QListIterator<QLabel*> anIter( myLambertLabels );
617 while( anIter.hasNext() )
618 anIter.next()->setVisible( anIsManualLambert );
620 emit modeActivated( theMode );
623 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
625 emit refImageActivated( theName );
628 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
630 int aPointType = HYDROGUI_PrsImage::None;
633 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
634 while( anIter.hasNext() )
636 int aBtnPointType = anIter.next().key();
637 QPushButton* aBtn = anIter.value();
638 if( aBtn == sender() )
639 aPointType = aBtnPointType;
642 bool anIsBlocked = aBtn->blockSignals( true );
643 aBtn->setChecked( false );
644 aBtn->blockSignals( anIsBlocked );
648 emit activatePointSelection( aPointType );
651 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
653 QObject* aSender = sender();
657 for( int aPointType = HYDROGUI_PrsImage::PointA;
658 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
660 if( aSender == myPointXMap[ aPointType ] ||
661 aSender == myPointYMap[ aPointType ] )
663 bool anIsY = aSender == myPointYMap[ aPointType ];
664 emit pointCoordChanged( false, aPointType, anIsY, theValue );
666 else if( aSender == myRefPointXMap[ aPointType ] ||
667 aSender == myRefPointYMap[ aPointType ] )
669 bool anIsY = aSender == myRefPointYMap[ aPointType ];
670 emit pointCoordChanged( true, aPointType, anIsY, theValue );
675 void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
677 QObject* aSender = sender();
681 for( int aPointType = HYDROGUI_PrsImage::PointA;
682 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
684 if( aSender == myPointXDegMap[ aPointType ] ||
685 aSender == myPointYDegMap[ aPointType ] ||
686 aSender == myPointXMinMap[ aPointType ] ||
687 aSender == myPointYMinMap[ aPointType ] ||
688 aSender == myPointXSecMap[ aPointType ] ||
689 aSender == myPointYSecMap[ aPointType ] )
691 onLambertCoordChanged( aPointType );
697 void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
700 for( int i = 0; i < 6; i++ )
703 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
704 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
705 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
706 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
707 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
708 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
710 for( int i = 0; i < 6; i++ )
714 double aLonDeg = 0, aLatDeg = 0;
715 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
716 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
718 double aXCart = 0, aYCart = 0;
719 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
721 blockSignalsCartesian( true );
723 myCartPointXMap[ thePointType ]->setValue( aXCart );
724 myCartPointYMap[ thePointType ]->setValue( aYCart );
726 blockSignalsCartesian( false );
729 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
731 QObject* aSender = sender();
735 for( int aPointType = HYDROGUI_PrsImage::PointA;
736 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
738 if( aSender == myCartPointXMap[ aPointType ] ||
739 aSender == myCartPointYMap[ aPointType ] )
741 onCartesianCoordChanged( aPointType );
747 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
750 for( int i = 0; i < 2; i++ )
753 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
754 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
756 for( int i = 0; i < 2; i++ )
760 double aLonDeg = 0, aLatDeg = 0;
761 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
763 int aXDeg = 0, aYDeg = 0;
764 int aXMin = 0, aYMin = 0;
765 double aXSec = 0, aYSec = 0;
766 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
767 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
769 blockSignalsLambert( true );
771 myPointXDegMap[ thePointType ]->setValue( aXDeg );
772 myPointYDegMap[ thePointType ]->setValue( aYDeg );
773 myPointXMinMap[ thePointType ]->setValue( aXMin );
774 myPointYMinMap[ thePointType ]->setValue( aYMin );
775 myPointXSecMap[ thePointType ]->setValue( aXSec );
776 myPointYSecMap[ thePointType ]->setValue( aYSec );
778 blockSignalsLambert( false );
781 void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
783 for( int aPointType = HYDROGUI_PrsImage::PointA;
784 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
786 myPointXDegMap[ aPointType ]->blockSignals( theState );
787 myPointXMinMap[ aPointType ]->blockSignals( theState );
788 myPointXSecMap[ aPointType ]->blockSignals( theState );
789 myPointYDegMap[ aPointType ]->blockSignals( theState );
790 myPointYMinMap[ aPointType ]->blockSignals( theState );
791 myPointYSecMap[ aPointType ]->blockSignals( theState );
795 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
797 for( int aPointType = HYDROGUI_PrsImage::PointA;
798 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
800 myCartPointXMap[ aPointType ]->blockSignals( theState );
801 myCartPointYMap[ aPointType ]->blockSignals( theState );