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" ), this );
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" ), this );
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" ), this );
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* aTransformLayout = new QGridLayout( myTransformGroup );
112 aTransformLayout->setMargin( 5 );
113 aTransformLayout->setSpacing( 5 );
115 QGridLayout* aModeLayout = new QGridLayout( myTransformGroup );
116 aModeLayout->setMargin( 0 );
117 aModeLayout->setSpacing( 5 );
118 aModeLayout->addWidget( aManualCartesianBtn, 0, 0 );
119 aModeLayout->addWidget( aManualLambertBtn, 1, 0 );
120 aModeLayout->addWidget( aRefImageBtn, 2, 0 );
121 aModeLayout->addWidget( myRefImage, 2, 1 );
122 aModeLayout->setColumnStretch( 1, 1 );
124 aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
126 QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
127 QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), myTransformGroup );
128 QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), myTransformGroup );
129 QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), myTransformGroup );
131 aTransformLayout->addWidget( aImageCSLabel, 2, 1 );
132 aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
133 aTransformLayout->addWidget( aLambertLabel, 2, 3, 1, 6 );
134 aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
136 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
137 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
138 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
139 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
140 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
141 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
142 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
143 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
144 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
146 for( int aPointType = HYDROGUI_PrsImage::PointA;
147 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
152 case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
153 case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
154 case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
156 QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
157 aPointBtn->setCheckable( true );
159 QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
160 QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
162 QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
163 QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
165 QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
166 aPointArrowLabel->setPicture( anArrowPicture );
168 QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
169 QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
170 QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
171 QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
172 QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
173 QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
174 myLambertLabels << aPointXDegLabel << aPointYDegLabel
175 << aPointXMinLabel << aPointYMinLabel
176 << aPointXSecLabel << aPointYSecLabel;
178 QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
179 QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( -90, 90, 1, myTransformGroup );
180 QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
181 QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
182 QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
183 QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
185 QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
186 QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
188 QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
189 QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
191 int aRow = 4 * aPointType + 3;
192 if ( aPointType == HYDROGUI_PrsImage::PointC )
194 myPointCEnabler = new QCheckBox( myTransformGroup );
195 aTransformLayout->addWidget( myPointCEnabler, aRow, 0, 1, 2, Qt::AlignHCenter );
196 aTransformLayout->addWidget( aPointBtn, aRow, 2, 1, 7 );
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 ) ) );
271 // Connect checkbox enabling point C
272 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
273 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
274 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
275 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
276 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
277 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
278 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
279 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
280 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
281 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
282 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
283 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
284 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
286 aTransformLayout->setColumnStretch( 1, 1 ); // double
287 aTransformLayout->setColumnStretch( 3, 1 ); // degrees
288 aTransformLayout->setColumnStretch( 5, 1 ); // minutes
289 aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
292 addWidget( myFileNameGroup );
293 addWidget( myImageNameGroup );
294 addWidget( myTransformGroup );
297 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
299 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
300 this, SLOT( onModeActivated( int ) ) );
302 connect( myRefImage, SIGNAL( activated( const QString& ) ),
303 this, SLOT( onRefImageActivated( const QString& ) ) );
305 setTransformationMode( ManualLambert );
307 setMinimumWidth( 350 );
310 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
314 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
316 myFileNameGroup->setVisible( !theIsEdit );
317 myImageNameGroup->setEnabled( theIsEdit );
318 myTransformGroup->setEnabled( theIsEdit );
321 void HYDROGUI_ImportImageDlg::reset()
324 myImageName->clear();
325 myImageNameGroup->setEnabled( false );
326 for( int aPointType = HYDROGUI_PrsImage::PointA;
327 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
329 QPushButton* aBtn = myPointBtnMap[ aPointType ];
330 bool anIsBlocked = aBtn->blockSignals( true );
331 aBtn->setChecked( false );
332 aBtn->blockSignals( anIsBlocked );
334 myPointXMap[ aPointType ]->clear();
335 myPointYMap[ aPointType ]->clear();
336 myPointXDegMap[ aPointType ]->clear();
337 myPointYDegMap[ aPointType ]->clear();
338 myPointXMinMap[ aPointType ]->clear();
339 myPointYMinMap[ aPointType ]->clear();
340 myPointXSecMap[ aPointType ]->clear();
341 myPointYSecMap[ aPointType ]->clear();
343 myRefPointXMap[ aPointType ]->clear();
344 myRefPointYMap[ aPointType ]->clear();
346 myCartPointXMap[ aPointType ]->clear();
347 myCartPointYMap[ aPointType ]->clear();
349 myPointCEnabler->setChecked( true );
350 myPointCEnabler->toggle();
351 myTransformGroup->setEnabled( false );
354 setTransformationMode( ManualLambert );
356 myPrsPointDataList.clear();
358 myIsInitialized = false;
361 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
363 myImageName->setText( theName );
366 QString HYDROGUI_ImportImageDlg::getImageName() const
368 return myImageName->text();
371 QString HYDROGUI_ImportImageDlg::getFileName() const
373 return myFileName->text();
376 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
377 const bool theIsRefImage )
379 int aWidth = theSize.width();
380 int aHeight = theSize.height();
381 for( int aPointType = HYDROGUI_PrsImage::PointA;
382 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
386 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
387 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
391 myPointXMap[ aPointType ]->setRange( 0, aWidth );
392 myPointYMap[ aPointType ]->setRange( 0, aHeight );
397 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
399 myModeGroup->button( theMode )->setChecked( true );
400 onModeActivated( theMode );
403 int HYDROGUI_ImportImageDlg::getTransformationMode() const
405 return myModeGroup->checkedId();
408 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
409 const bool theIsOnlyInput,
410 const bool theIsRefImage )
412 blockSignalsLambert( true );
413 blockSignalsCartesian( true );
414 for( int aPointType = HYDROGUI_PrsImage::PointA;
415 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
417 if( theMap.contains( aPointType ) )
419 const TransformationData& aData = theMap[ aPointType ];
421 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
422 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
423 aPointX->setValue( aData.ImagePoint.x() );
424 aPointY->setValue( aData.ImagePoint.y() );
426 if( !theIsOnlyInput && !theIsRefImage )
428 QPointF aLPoint = aData.LambertPoint;
429 int aXDeg = 0, aYDeg = 0;
430 int aXMin = 0, aYMin = 0;
431 double aXSec = 0, aYSec = 0;
432 HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
433 HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
435 myPointXDegMap[ aPointType ]->setValue( aXDeg );
436 myPointYDegMap[ aPointType ]->setValue( aYDeg );
437 myPointXMinMap[ aPointType ]->setValue( aXMin );
438 myPointYMinMap[ aPointType ]->setValue( aYMin );
439 myPointXSecMap[ aPointType ]->setValue( aXSec );
440 myPointYSecMap[ aPointType ]->setValue( aYSec );
442 QPointF aCPoint = aData.CartesianPoint;
443 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
444 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
448 blockSignalsLambert( false );
449 blockSignalsCartesian( false );
452 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
453 const bool theIsRefImage ) const
456 for( int aPointType = HYDROGUI_PrsImage::PointA;
457 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
460 for( int i = 0; i < 10; i++ )
463 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
464 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
465 int aX1 = aPointX->text().toInt( &anIsOk[0] );
466 int aY1 = aPointY->text().toInt( &anIsOk[1] );
468 int aXDeg = 0, aYDeg = 0;
469 int aXMin = 0, aYMin = 0;
470 double aXSec = 0, aYSec = 0;
471 double aXCart = 0, aYCart = 0;
474 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
475 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
476 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
477 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
478 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
479 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
481 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
482 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
485 for( int i = 0; i < 10; i++ )
489 double aX2 = 0, aY2 = 0;
490 HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
491 HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
493 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
494 theMap[ aPointType ] = aData;
499 QString HYDROGUI_ImportImageDlg::getRefImageName() const
501 return myRefImage->currentText();
504 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
506 myPrsPointDataList = theList;
508 if( !myPrsPointDataList.isEmpty() )
510 myModeGroup->button( RefImage )->setEnabled( true );
513 myRefImage->addItem( "" ); // first empty item
515 PrsPointDataListIterator anIter( myPrsPointDataList );
516 while( anIter.hasNext() )
517 myRefImage->addItem( anIter.next().first );
520 myModeGroup->button( RefImage )->setEnabled( false );
523 void HYDROGUI_ImportImageDlg::initializePointSelection()
525 if( myIsInitialized )
528 myIsInitialized = true;
530 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
534 blockSignalsLambert( true );
536 myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
537 myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
538 myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
539 myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
540 myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
541 myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
543 myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
544 myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
545 myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
546 myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
547 myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
548 myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
550 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
551 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
552 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
553 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
554 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
555 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
557 for( int aPointType = HYDROGUI_PrsImage::PointA;
558 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
559 onLambertCoordChanged( aPointType );
561 blockSignalsLambert( false );
564 //double aCartX0 = 600000;
565 //double aCartY0 = 6800000;
569 blockSignalsCartesian( true );
571 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
572 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
574 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
575 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
577 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
578 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
580 for( int aPointType = HYDROGUI_PrsImage::PointA;
581 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
582 onCartesianCoordChanged( aPointType );
584 blockSignalsCartesian( false );
587 void HYDROGUI_ImportImageDlg::onBrowse()
589 QString aFilter( tr( "IMAGE_FILTER" ) );
590 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
591 if( !aFileName.isEmpty() )
593 QImage anImage( aFileName );
594 if( !anImage.isNull() )
596 myFileName->setText( aFileName );
597 emit createPreview( anImage );
598 myImageNameGroup->setEnabled( true );
599 myTransformGroup->setEnabled( true );
604 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
606 bool anIsManualLambert = theMode == ManualLambert;
607 bool anIsManualCartesian = theMode == ManualCartesian;
608 bool anIsRefImage = theMode == RefImage;
610 myRefImage->setEnabled( anIsRefImage );
612 for( int aPointType = HYDROGUI_PrsImage::PointA;
613 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
615 myPointXDegMap[ aPointType ]->setVisible( anIsManualLambert );
616 myPointYDegMap[ aPointType ]->setVisible( anIsManualLambert );
617 myPointXMinMap[ aPointType ]->setVisible( anIsManualLambert );
618 myPointYMinMap[ aPointType ]->setVisible( anIsManualLambert );
619 myPointXSecMap[ aPointType ]->setVisible( anIsManualLambert );
620 myPointYSecMap[ aPointType ]->setVisible( anIsManualLambert );
622 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
623 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
625 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
626 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
629 QListIterator<QLabel*> anIter( myLambertLabels );
630 while( anIter.hasNext() )
631 anIter.next()->setVisible( anIsManualLambert );
633 emit modeActivated( theMode );
636 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
638 emit refImageActivated( theName );
641 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
643 int aPointType = HYDROGUI_PrsImage::None;
646 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
647 while( anIter.hasNext() )
649 int aBtnPointType = anIter.next().key();
650 QPushButton* aBtn = anIter.value();
651 if( aBtn == sender() )
652 aPointType = aBtnPointType;
655 bool anIsBlocked = aBtn->blockSignals( true );
656 aBtn->setChecked( false );
657 aBtn->blockSignals( anIsBlocked );
661 emit activatePointSelection( aPointType );
664 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
666 QObject* aSender = sender();
670 for( int aPointType = HYDROGUI_PrsImage::PointA;
671 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
673 if( aSender == myPointXMap[ aPointType ] ||
674 aSender == myPointYMap[ aPointType ] )
676 bool anIsY = aSender == myPointYMap[ aPointType ];
677 emit pointCoordChanged( false, aPointType, anIsY, theValue );
679 else if( aSender == myRefPointXMap[ aPointType ] ||
680 aSender == myRefPointYMap[ aPointType ] )
682 bool anIsY = aSender == myRefPointYMap[ aPointType ];
683 emit pointCoordChanged( true, aPointType, anIsY, theValue );
688 void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
690 QObject* aSender = sender();
694 for( int aPointType = HYDROGUI_PrsImage::PointA;
695 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
697 if( aSender == myPointXDegMap[ aPointType ] ||
698 aSender == myPointYDegMap[ aPointType ] ||
699 aSender == myPointXMinMap[ aPointType ] ||
700 aSender == myPointYMinMap[ aPointType ] ||
701 aSender == myPointXSecMap[ aPointType ] ||
702 aSender == myPointYSecMap[ aPointType ] )
704 onLambertCoordChanged( aPointType );
710 void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
713 for( int i = 0; i < 6; i++ )
716 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
717 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
718 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
719 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
720 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
721 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
723 for( int i = 0; i < 6; i++ )
727 double aLonDeg = 0, aLatDeg = 0;
728 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
729 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
731 double aXCart = 0, aYCart = 0;
732 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
734 blockSignalsCartesian( true );
736 myCartPointXMap[ thePointType ]->setValue( aXCart );
737 myCartPointYMap[ thePointType ]->setValue( aYCart );
739 blockSignalsCartesian( false );
742 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
744 QObject* aSender = sender();
748 for( int aPointType = HYDROGUI_PrsImage::PointA;
749 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
751 if( aSender == myCartPointXMap[ aPointType ] ||
752 aSender == myCartPointYMap[ aPointType ] )
754 onCartesianCoordChanged( aPointType );
760 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
763 for( int i = 0; i < 2; i++ )
766 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
767 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
769 for( int i = 0; i < 2; i++ )
773 double aLonDeg = 0, aLatDeg = 0;
774 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
776 int aXDeg = 0, aYDeg = 0;
777 int aXMin = 0, aYMin = 0;
778 double aXSec = 0, aYSec = 0;
779 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
780 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
782 blockSignalsLambert( true );
784 myPointXDegMap[ thePointType ]->setValue( aXDeg );
785 myPointYDegMap[ thePointType ]->setValue( aYDeg );
786 myPointXMinMap[ thePointType ]->setValue( aXMin );
787 myPointYMinMap[ thePointType ]->setValue( aYMin );
788 myPointXSecMap[ thePointType ]->setValue( aXSec );
789 myPointYSecMap[ thePointType ]->setValue( aYSec );
791 blockSignalsLambert( false );
794 void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
796 for( int aPointType = HYDROGUI_PrsImage::PointA;
797 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
799 myPointXDegMap[ aPointType ]->blockSignals( theState );
800 myPointXMinMap[ aPointType ]->blockSignals( theState );
801 myPointXSecMap[ aPointType ]->blockSignals( theState );
802 myPointYDegMap[ aPointType ]->blockSignals( theState );
803 myPointYMinMap[ aPointType ]->blockSignals( theState );
804 myPointYSecMap[ aPointType ]->blockSignals( theState );
808 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
810 for( int aPointType = HYDROGUI_PrsImage::PointA;
811 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
813 myCartPointXMap[ aPointType ]->blockSignals( theState );
814 myCartPointYMap[ aPointType ]->blockSignals( theState );