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>
49 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
50 : HYDROGUI_InputPanel( theModule, theTitle ),
51 myIsInitialized( false )
53 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
55 // Import image from file
56 myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
58 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
60 myFileName = new QLineEdit( myFileNameGroup );
61 myFileName->setReadOnly( true );
63 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
64 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
66 QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
67 aFileNameLayout->setMargin( 5 );
68 aFileNameLayout->setSpacing( 5 );
69 aFileNameLayout->addWidget( aFileNameLabel );
70 aFileNameLayout->addWidget( myFileName );
71 aFileNameLayout->addWidget( aBrowseBtn );
74 myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
76 QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
77 myImageName = new QLineEdit( myImageNameGroup );
79 QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
80 anImageNameLayout->setMargin( 5 );
81 anImageNameLayout->setSpacing( 5 );
82 anImageNameLayout->addWidget( anImageNameLabel );
83 anImageNameLayout->addWidget( myImageName );
86 myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ) );
88 // Make a pixmap for arrow
89 QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
91 QPicture anArrowPicture;
92 anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
95 aPainter.begin( &anArrowPicture );
96 aPainter.drawPixmap( 0, 0, anArrowPixmap );
99 QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup );
100 QRadioButton* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
101 QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
103 myModeGroup = new QButtonGroup( myTransformGroup );
104 myModeGroup->addButton( aManualCartesianBtn, ManualCartesian );
105 myModeGroup->addButton( aManualLambertBtn, ManualLambert );
106 myModeGroup->addButton( aRefImageBtn, RefImage );
108 myRefImage = new QComboBox( myTransformGroup );
110 QGridLayout* aModeLayout = new QGridLayout();
111 aModeLayout->setMargin( 0 );
112 aModeLayout->setSpacing( 5 );
113 aModeLayout->addWidget( aManualCartesianBtn, 0, 0 );
114 aModeLayout->addWidget( aManualLambertBtn, 1, 0 );
115 aModeLayout->addWidget( aRefImageBtn, 2, 0 );
116 aModeLayout->addWidget( myRefImage, 2, 1 );
117 aModeLayout->setColumnStretch( 1, 1 );
119 QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
120 aTransformLayout->setMargin( 5 );
121 aTransformLayout->setSpacing( 5 );
122 aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
124 QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
125 QLabel* aGeodesicLabel = new QLabel( "GEODESIC", myTransformGroup );
126 QLabel* aLambertLabel = new QLabel( "LAMBERT93", myTransformGroup );
127 QLabel* aRefImageLabel = new QLabel( "REFERENCE_IMAGE_CS", myTransformGroup );
129 aTransformLayout->addWidget( aImageCSLabel, 2, 1 );
130 aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
131 aTransformLayout->addWidget( aLambertLabel, 2, 3, 1, 6 );
132 aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
134 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
135 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
136 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
137 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
138 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
139 connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
140 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
141 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
142 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
144 for( int aPointType = HYDROGUI_PrsImage::PointA;
145 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
150 case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
151 case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
152 case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
154 QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
155 aPointBtn->setCheckable( true );
157 QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
158 QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
160 QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
161 QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
163 QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
164 aPointArrowLabel->setPicture( anArrowPicture );
166 QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
167 QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
168 QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
169 QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
170 QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
171 QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
172 myLambertLabels << aPointXDegLabel << aPointYDegLabel
173 << aPointXMinLabel << aPointYMinLabel
174 << aPointXSecLabel << aPointYSecLabel;
176 QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
177 QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( -90, 90, 1, myTransformGroup );
178 QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
179 QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
180 QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
181 QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
183 QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
184 QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
186 QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
187 QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
189 int aRow = 4 * aPointType + 3;
190 aTransformLayout->addWidget( aPointBtn, aRow, 0, 1, 9 );
192 aTransformLayout->addWidget( aPointXLabel, aRow + 1, 0 );
193 aTransformLayout->addWidget( aPointX, aRow + 1, 1 );
194 aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
195 aTransformLayout->addWidget( aPointXDeg, aRow + 1, 3 );
196 aTransformLayout->addWidget( aPointXDegLabel, aRow + 1, 4 );
197 aTransformLayout->addWidget( aPointXMin, aRow + 1, 5 );
198 aTransformLayout->addWidget( aPointXMinLabel, aRow + 1, 6 );
199 aTransformLayout->addWidget( aPointXSec, aRow + 1, 7 );
200 aTransformLayout->addWidget( aPointXSecLabel, aRow + 1, 8 );
202 aTransformLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 );
203 aTransformLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 );
205 aTransformLayout->addWidget( aPointYLabel, aRow + 2, 0 );
206 aTransformLayout->addWidget( aPointY, aRow + 2, 1 );
207 aTransformLayout->addWidget( aPointYDeg, aRow + 2, 3 );
208 aTransformLayout->addWidget( aPointYDegLabel, aRow + 2, 4 );
209 aTransformLayout->addWidget( aPointYMin, aRow + 2, 5 );
210 aTransformLayout->addWidget( aPointYMinLabel, aRow + 2, 6 );
211 aTransformLayout->addWidget( aPointYSec, aRow + 2, 7 );
212 aTransformLayout->addWidget( aPointYSecLabel, aRow + 2, 8 );
214 aTransformLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 );
215 aTransformLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
217 if( aPointType != HYDROGUI_PrsImage::PointC )
219 QFrame* aLine = new QFrame( myTransformGroup );
220 aLine->setFrameShape( QFrame::HLine );
221 aLine->setFrameShadow( QFrame::Sunken );
222 aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
225 myPointBtnMap[ aPointType ] = aPointBtn;
226 myPointXMap[ aPointType ] = aPointX;
227 myPointYMap[ aPointType ] = aPointY;
228 myPointXDegMap[ aPointType ] = aPointXDeg;
229 myPointYDegMap[ aPointType ] = aPointYDeg;
230 myPointXMinMap[ aPointType ] = aPointXMin;
231 myPointYMinMap[ aPointType ] = aPointYMin;
232 myPointXSecMap[ aPointType ] = aPointXSec;
233 myPointYSecMap[ aPointType ] = aPointYSec;
235 myCartPointXMap[ aPointType ] = aCartPointX;
236 myCartPointYMap[ aPointType ] = aCartPointY;
238 myRefPointXMap[ aPointType ] = aRefPointX;
239 myRefPointYMap[ aPointType ] = aRefPointY;
241 connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
243 connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
244 connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
246 connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
247 connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
248 connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
249 connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
250 connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
251 connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
253 connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
254 connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
256 connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
257 connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
259 aTransformLayout->setColumnStretch( 1, 1 ); // double
260 aTransformLayout->setColumnStretch( 3, 1 ); // degrees
261 aTransformLayout->setColumnStretch( 5, 1 ); // minutes
262 aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
265 addWidget( myFileNameGroup );
266 addWidget( myImageNameGroup );
267 addWidget( myTransformGroup );
270 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
272 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
273 this, SLOT( onModeActivated( int ) ) );
275 connect( myRefImage, SIGNAL( activated( const QString& ) ),
276 this, SLOT( onRefImageActivated( const QString& ) ) );
278 setTransformationMode( ManualLambert );
280 setMinimumWidth( 350 );
283 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
285 delete myFileNameGroup;
286 delete myImageNameGroup;
287 delete myTransformGroup;
290 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
292 myFileNameGroup->setVisible( !theIsEdit );
293 myImageNameGroup->setEnabled( theIsEdit );
294 myTransformGroup->setEnabled( theIsEdit );
297 void HYDROGUI_ImportImageDlg::reset()
300 myImageName->clear();
301 myImageNameGroup->setEnabled( false );
302 for( int aPointType = HYDROGUI_PrsImage::PointA;
303 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
305 QPushButton* aBtn = myPointBtnMap[ aPointType ];
306 bool anIsBlocked = aBtn->blockSignals( true );
307 aBtn->setChecked( false );
308 aBtn->blockSignals( anIsBlocked );
310 myPointXMap[ aPointType ]->clear();
311 myPointYMap[ aPointType ]->clear();
312 myPointXDegMap[ aPointType ]->clear();
313 myPointYDegMap[ aPointType ]->clear();
314 myPointXMinMap[ aPointType ]->clear();
315 myPointYMinMap[ aPointType ]->clear();
316 myPointXSecMap[ aPointType ]->clear();
317 myPointYSecMap[ aPointType ]->clear();
319 myRefPointXMap[ aPointType ]->clear();
320 myRefPointYMap[ aPointType ]->clear();
322 myCartPointXMap[ aPointType ]->clear();
323 myCartPointYMap[ aPointType ]->clear();
325 myTransformGroup->setEnabled( false );
328 setTransformationMode( ManualLambert );
330 myPrsPointDataList.clear();
332 myIsInitialized = false;
335 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
337 myImageName->setText( theName );
340 QString HYDROGUI_ImportImageDlg::getImageName() const
342 return myImageName->text();
345 QString HYDROGUI_ImportImageDlg::getFileName() const
347 return myFileName->text();
350 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
351 const bool theIsRefImage )
353 int aWidth = theSize.width();
354 int aHeight = theSize.height();
355 for( int aPointType = HYDROGUI_PrsImage::PointA;
356 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
360 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
361 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
365 myPointXMap[ aPointType ]->setRange( 0, aWidth );
366 myPointYMap[ aPointType ]->setRange( 0, aHeight );
371 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
373 myModeGroup->button( theMode )->setChecked( true );
374 onModeActivated( theMode );
377 int HYDROGUI_ImportImageDlg::getTransformationMode() const
379 return myModeGroup->checkedId();
382 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
383 const bool theIsOnlyInput,
384 const bool theIsRefImage )
386 blockSignalsLambert( true );
387 blockSignalsCartesian( true );
388 for( int aPointType = HYDROGUI_PrsImage::PointA;
389 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
391 if( theMap.contains( aPointType ) )
393 const TransformationData& aData = theMap[ aPointType ];
395 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
396 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
397 aPointX->setValue( aData.ImagePoint.x() );
398 aPointY->setValue( aData.ImagePoint.y() );
400 if( !theIsOnlyInput && !theIsRefImage )
402 QPointF aLPoint = aData.LambertPoint;
403 int aXDeg = 0, aYDeg = 0;
404 int aXMin = 0, aYMin = 0;
405 double aXSec = 0, aYSec = 0;
406 HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
407 HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
409 myPointXDegMap[ aPointType ]->setValue( aXDeg );
410 myPointYDegMap[ aPointType ]->setValue( aYDeg );
411 myPointXMinMap[ aPointType ]->setValue( aXMin );
412 myPointYMinMap[ aPointType ]->setValue( aYMin );
413 myPointXSecMap[ aPointType ]->setValue( aXSec );
414 myPointYSecMap[ aPointType ]->setValue( aYSec );
416 QPointF aCPoint = aData.CartesianPoint;
417 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
418 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
422 blockSignalsLambert( false );
423 blockSignalsCartesian( false );
426 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
427 const bool theIsRefImage ) const
430 for( int aPointType = HYDROGUI_PrsImage::PointA;
431 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
434 for( int i = 0; i < 10; i++ )
437 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
438 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
439 int aX1 = aPointX->text().toInt( &anIsOk[0] );
440 int aY1 = aPointY->text().toInt( &anIsOk[1] );
442 int aXDeg = 0, aYDeg = 0;
443 int aXMin = 0, aYMin = 0;
444 double aXSec = 0, aYSec = 0;
445 double aXCart = 0, aYCart = 0;
448 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
449 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
450 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
451 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
452 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
453 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
455 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
456 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
459 for( int i = 0; i < 10; i++ )
463 double aX2 = 0, aY2 = 0;
464 HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
465 HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
467 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
468 theMap[ aPointType ] = aData;
473 QString HYDROGUI_ImportImageDlg::getRefImageName() const
475 return myRefImage->currentText();
478 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
480 myPrsPointDataList = theList;
482 if( !myPrsPointDataList.isEmpty() )
484 myModeGroup->button( RefImage )->setEnabled( true );
487 myRefImage->addItem( "" ); // first empty item
489 PrsPointDataListIterator anIter( myPrsPointDataList );
490 while( anIter.hasNext() )
491 myRefImage->addItem( anIter.next().first );
494 myModeGroup->button( RefImage )->setEnabled( false );
497 void HYDROGUI_ImportImageDlg::initializePointSelection()
499 if( myIsInitialized )
502 myIsInitialized = true;
504 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
508 blockSignalsLambert( true );
510 myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
511 myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
512 myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
513 myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
514 myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
515 myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
517 myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
518 myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
519 myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
520 myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
521 myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
522 myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
524 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
525 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
526 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
527 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
528 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
529 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
531 for( int aPointType = HYDROGUI_PrsImage::PointA;
532 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
533 onLambertCoordChanged( aPointType );
535 blockSignalsLambert( false );
538 //double aCartX0 = 600000;
539 //double aCartY0 = 6800000;
543 blockSignalsCartesian( true );
545 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
546 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
548 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
549 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
551 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
552 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
554 for( int aPointType = HYDROGUI_PrsImage::PointA;
555 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
556 onCartesianCoordChanged( aPointType );
558 blockSignalsCartesian( false );
561 void HYDROGUI_ImportImageDlg::onBrowse()
563 QString aFilter( tr( "IMAGE_FILTER" ) );
564 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
565 if( !aFileName.isEmpty() )
567 QImage anImage( aFileName );
568 if( !anImage.isNull() )
570 myFileName->setText( aFileName );
571 emit createPreview( anImage );
572 myImageNameGroup->setEnabled( true );
573 myTransformGroup->setEnabled( true );
578 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
580 bool anIsManualLambert = theMode == ManualLambert;
581 bool anIsManualCartesian = theMode == ManualCartesian;
582 bool anIsRefImage = theMode == RefImage;
584 myRefImage->setEnabled( anIsRefImage );
586 for( int aPointType = HYDROGUI_PrsImage::PointA;
587 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
589 myPointXDegMap[ aPointType ]->setVisible( anIsManualLambert );
590 myPointYDegMap[ aPointType ]->setVisible( anIsManualLambert );
591 myPointXMinMap[ aPointType ]->setVisible( anIsManualLambert );
592 myPointYMinMap[ aPointType ]->setVisible( anIsManualLambert );
593 myPointXSecMap[ aPointType ]->setVisible( anIsManualLambert );
594 myPointYSecMap[ aPointType ]->setVisible( anIsManualLambert );
596 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
597 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
599 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
600 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
603 QListIterator<QLabel*> anIter( myLambertLabels );
604 while( anIter.hasNext() )
605 anIter.next()->setVisible( anIsManualLambert );
607 emit modeActivated( theMode );
610 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
612 emit refImageActivated( theName );
615 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
617 int aPointType = HYDROGUI_PrsImage::None;
620 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
621 while( anIter.hasNext() )
623 int aBtnPointType = anIter.next().key();
624 QPushButton* aBtn = anIter.value();
625 if( aBtn == sender() )
626 aPointType = aBtnPointType;
629 bool anIsBlocked = aBtn->blockSignals( true );
630 aBtn->setChecked( false );
631 aBtn->blockSignals( anIsBlocked );
635 emit activatePointSelection( aPointType );
638 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
640 QObject* aSender = sender();
644 for( int aPointType = HYDROGUI_PrsImage::PointA;
645 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
647 if( aSender == myPointXMap[ aPointType ] ||
648 aSender == myPointYMap[ aPointType ] )
650 bool anIsY = aSender == myPointYMap[ aPointType ];
651 emit pointCoordChanged( false, aPointType, anIsY, theValue );
653 else if( aSender == myRefPointXMap[ aPointType ] ||
654 aSender == myRefPointYMap[ aPointType ] )
656 bool anIsY = aSender == myRefPointYMap[ aPointType ];
657 emit pointCoordChanged( true, aPointType, anIsY, theValue );
662 void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
664 QObject* aSender = sender();
668 for( int aPointType = HYDROGUI_PrsImage::PointA;
669 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
671 if( aSender == myPointXDegMap[ aPointType ] ||
672 aSender == myPointYDegMap[ aPointType ] ||
673 aSender == myPointXMinMap[ aPointType ] ||
674 aSender == myPointYMinMap[ aPointType ] ||
675 aSender == myPointXSecMap[ aPointType ] ||
676 aSender == myPointYSecMap[ aPointType ] )
678 onLambertCoordChanged( aPointType );
684 void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
687 for( int i = 0; i < 6; i++ )
690 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
691 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
692 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
693 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
694 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
695 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
697 for( int i = 0; i < 6; i++ )
701 double aLonDeg = 0, aLatDeg = 0;
702 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
703 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
705 double aXCart = 0, aYCart = 0;
706 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
708 blockSignalsCartesian( true );
710 myCartPointXMap[ thePointType ]->setValue( aXCart );
711 myCartPointYMap[ thePointType ]->setValue( aYCart );
713 blockSignalsCartesian( false );
716 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
718 QObject* aSender = sender();
722 for( int aPointType = HYDROGUI_PrsImage::PointA;
723 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
725 if( aSender == myCartPointXMap[ aPointType ] ||
726 aSender == myCartPointYMap[ aPointType ] )
728 onCartesianCoordChanged( aPointType );
734 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
737 for( int i = 0; i < 2; i++ )
740 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
741 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
743 for( int i = 0; i < 2; i++ )
747 double aLonDeg = 0, aLatDeg = 0;
748 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
750 int aXDeg = 0, aYDeg = 0;
751 int aXMin = 0, aYMin = 0;
752 double aXSec = 0, aYSec = 0;
753 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
754 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
756 blockSignalsLambert( true );
758 myPointXDegMap[ thePointType ]->setValue( aXDeg );
759 myPointYDegMap[ thePointType ]->setValue( aYDeg );
760 myPointXMinMap[ thePointType ]->setValue( aXMin );
761 myPointYMinMap[ thePointType ]->setValue( aYMin );
762 myPointXSecMap[ thePointType ]->setValue( aXSec );
763 myPointYSecMap[ thePointType ]->setValue( aYSec );
765 blockSignalsLambert( false );
768 void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
770 for( int aPointType = HYDROGUI_PrsImage::PointA;
771 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
773 myPointXDegMap[ aPointType ]->blockSignals( theState );
774 myPointXMinMap[ aPointType ]->blockSignals( theState );
775 myPointXSecMap[ aPointType ]->blockSignals( theState );
776 myPointYDegMap[ aPointType ]->blockSignals( theState );
777 myPointYMinMap[ aPointType ]->blockSignals( theState );
778 myPointYSecMap[ aPointType ]->blockSignals( theState );
782 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
784 for( int aPointType = HYDROGUI_PrsImage::PointA;
785 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
787 myCartPointXMap[ aPointType ]->blockSignals( theState );
788 myCartPointYMap[ aPointType ]->blockSignals( theState );