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* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
100 QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup );
101 QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
103 myModeGroup = new QButtonGroup( myTransformGroup );
104 myModeGroup->addButton( aManualLambertBtn, ManualLambert );
105 myModeGroup->addButton( aManualCartesianBtn, ManualCartesian );
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( aManualLambertBtn, 0, 0 );
114 aModeLayout->addWidget( aManualCartesianBtn, 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 for( int aPointType = HYDROGUI_PrsImage::PointA;
125 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
130 case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
131 case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
132 case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
134 QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
135 aPointBtn->setCheckable( true );
137 QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
138 QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
140 QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
141 QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
143 QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
144 aPointArrowLabel->setPicture( anArrowPicture );
146 QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
147 QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup );
148 QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup );
149 QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
150 QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
151 QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
152 myLambertLabels << aPointXDegLabel << aPointYDegLabel
153 << aPointXMinLabel << aPointYMinLabel
154 << aPointXSecLabel << aPointYSecLabel;
156 QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
157 QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( -90, 90, 1, myTransformGroup );
158 QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
159 QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
160 QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
161 QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
163 QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
164 QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
166 QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
167 QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
169 int aRow = 4 * aPointType + 2;
170 aTransformLayout->addWidget( aPointBtn, aRow, 0, 1, 9 );
172 aTransformLayout->addWidget( aPointXLabel, aRow + 1, 0 );
173 aTransformLayout->addWidget( aPointX, aRow + 1, 1 );
174 aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
175 aTransformLayout->addWidget( aPointXDeg, aRow + 1, 3 );
176 aTransformLayout->addWidget( aPointXDegLabel, aRow + 1, 4 );
177 aTransformLayout->addWidget( aPointXMin, aRow + 1, 5 );
178 aTransformLayout->addWidget( aPointXMinLabel, aRow + 1, 6 );
179 aTransformLayout->addWidget( aPointXSec, aRow + 1, 7 );
180 aTransformLayout->addWidget( aPointXSecLabel, aRow + 1, 8 );
182 aTransformLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 );
183 aTransformLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 );
185 aTransformLayout->addWidget( aPointYLabel, aRow + 2, 0 );
186 aTransformLayout->addWidget( aPointY, aRow + 2, 1 );
187 aTransformLayout->addWidget( aPointYDeg, aRow + 2, 3 );
188 aTransformLayout->addWidget( aPointYDegLabel, aRow + 2, 4 );
189 aTransformLayout->addWidget( aPointYMin, aRow + 2, 5 );
190 aTransformLayout->addWidget( aPointYMinLabel, aRow + 2, 6 );
191 aTransformLayout->addWidget( aPointYSec, aRow + 2, 7 );
192 aTransformLayout->addWidget( aPointYSecLabel, aRow + 2, 8 );
194 aTransformLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 );
195 aTransformLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
197 if( aPointType != HYDROGUI_PrsImage::PointC )
199 QFrame* aLine = new QFrame( myTransformGroup );
200 aLine->setFrameShape( QFrame::HLine );
201 aLine->setFrameShadow( QFrame::Sunken );
202 aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
205 myPointBtnMap[ aPointType ] = aPointBtn;
206 myPointXMap[ aPointType ] = aPointX;
207 myPointYMap[ aPointType ] = aPointY;
208 myPointXDegMap[ aPointType ] = aPointXDeg;
209 myPointYDegMap[ aPointType ] = aPointYDeg;
210 myPointXMinMap[ aPointType ] = aPointXMin;
211 myPointYMinMap[ aPointType ] = aPointYMin;
212 myPointXSecMap[ aPointType ] = aPointXSec;
213 myPointYSecMap[ aPointType ] = aPointYSec;
215 myCartPointXMap[ aPointType ] = aCartPointX;
216 myCartPointYMap[ aPointType ] = aCartPointY;
218 myRefPointXMap[ aPointType ] = aRefPointX;
219 myRefPointYMap[ aPointType ] = aRefPointY;
221 connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
223 connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
224 connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
226 connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
227 connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
228 connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
229 connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
230 connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
231 connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
233 connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
234 connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
236 connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
237 connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
239 aTransformLayout->setColumnStretch( 1, 1 ); // double
240 aTransformLayout->setColumnStretch( 3, 1 ); // degrees
241 aTransformLayout->setColumnStretch( 5, 1 ); // minutes
242 aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
245 addWidget( myFileNameGroup );
246 addWidget( myImageNameGroup );
247 addWidget( myTransformGroup );
250 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
252 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
253 this, SLOT( onModeActivated( int ) ) );
255 connect( myRefImage, SIGNAL( activated( const QString& ) ),
256 this, SLOT( onRefImageActivated( const QString& ) ) );
258 setTransformationMode( ManualLambert );
260 setMinimumWidth( 350 );
263 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
267 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
269 myFileNameGroup->setVisible( !theIsEdit );
270 myImageNameGroup->setEnabled( theIsEdit );
271 myTransformGroup->setEnabled( theIsEdit );
274 void HYDROGUI_ImportImageDlg::reset()
277 myImageName->clear();
278 myImageNameGroup->setEnabled( false );
279 for( int aPointType = HYDROGUI_PrsImage::PointA;
280 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
282 QPushButton* aBtn = myPointBtnMap[ aPointType ];
283 bool anIsBlocked = aBtn->blockSignals( true );
284 aBtn->setChecked( false );
285 aBtn->blockSignals( anIsBlocked );
287 myPointXMap[ aPointType ]->clear();
288 myPointYMap[ aPointType ]->clear();
289 myPointXDegMap[ aPointType ]->clear();
290 myPointYDegMap[ aPointType ]->clear();
291 myPointXMinMap[ aPointType ]->clear();
292 myPointYMinMap[ aPointType ]->clear();
293 myPointXSecMap[ aPointType ]->clear();
294 myPointYSecMap[ aPointType ]->clear();
296 myRefPointXMap[ aPointType ]->clear();
297 myRefPointYMap[ aPointType ]->clear();
299 myCartPointXMap[ aPointType ]->clear();
300 myCartPointYMap[ aPointType ]->clear();
302 myTransformGroup->setEnabled( false );
305 setTransformationMode( ManualCartesian );
307 myPrsPointDataList.clear();
309 myIsInitialized = false;
312 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
314 myImageName->setText( theName );
317 QString HYDROGUI_ImportImageDlg::getImageName() const
319 return myImageName->text();
322 QString HYDROGUI_ImportImageDlg::getFileName() const
324 return myFileName->text();
327 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
328 const bool theIsRefImage )
330 int aWidth = theSize.width();
331 int aHeight = theSize.height();
332 for( int aPointType = HYDROGUI_PrsImage::PointA;
333 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
337 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
338 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
342 myPointXMap[ aPointType ]->setRange( 0, aWidth );
343 myPointYMap[ aPointType ]->setRange( 0, aHeight );
348 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
350 myModeGroup->button( theMode )->setChecked( true );
351 onModeActivated( theMode );
354 int HYDROGUI_ImportImageDlg::getTransformationMode() const
356 return myModeGroup->checkedId();
359 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
360 const bool theIsOnlyInput,
361 const bool theIsRefImage )
363 blockSignalsLambert( true );
364 blockSignalsCartesian( true );
365 for( int aPointType = HYDROGUI_PrsImage::PointA;
366 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
368 if( theMap.contains( aPointType ) )
370 const TransformationData& aData = theMap[ aPointType ];
372 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
373 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
374 aPointX->setValue( aData.ImagePoint.x() );
375 aPointY->setValue( aData.ImagePoint.y() );
377 if( !theIsOnlyInput && !theIsRefImage )
379 QPointF aLPoint = aData.LambertPoint;
380 int aXDeg = 0, aYDeg = 0;
381 int aXMin = 0, aYMin = 0;
382 double aXSec = 0, aYSec = 0;
383 HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
384 HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
386 myPointXDegMap[ aPointType ]->setValue( aXDeg );
387 myPointYDegMap[ aPointType ]->setValue( aYDeg );
388 myPointXMinMap[ aPointType ]->setValue( aXMin );
389 myPointYMinMap[ aPointType ]->setValue( aYMin );
390 myPointXSecMap[ aPointType ]->setValue( aXSec );
391 myPointYSecMap[ aPointType ]->setValue( aYSec );
393 QPointF aCPoint = aData.CartesianPoint;
394 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
395 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
399 blockSignalsLambert( false );
400 blockSignalsCartesian( false );
403 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
404 const bool theIsRefImage ) const
407 for( int aPointType = HYDROGUI_PrsImage::PointA;
408 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
411 for( int i = 0; i < 10; i++ )
414 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
415 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
416 int aX1 = aPointX->text().toInt( &anIsOk[0] );
417 int aY1 = aPointY->text().toInt( &anIsOk[1] );
419 int aXDeg = 0, aYDeg = 0;
420 int aXMin = 0, aYMin = 0;
421 double aXSec = 0, aYSec = 0;
422 double aXCart = 0, aYCart = 0;
425 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
426 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
427 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
428 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
429 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
430 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
432 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
433 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
436 for( int i = 0; i < 10; i++ )
440 double aX2 = 0, aY2 = 0;
441 HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
442 HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
444 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
445 theMap[ aPointType ] = aData;
450 QString HYDROGUI_ImportImageDlg::getRefImageName() const
452 return myRefImage->currentText();
455 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
457 myPrsPointDataList = theList;
459 if( !myPrsPointDataList.isEmpty() )
461 myModeGroup->button( RefImage )->setEnabled( true );
464 myRefImage->addItem( "" ); // first empty item
466 PrsPointDataListIterator anIter( myPrsPointDataList );
467 while( anIter.hasNext() )
468 myRefImage->addItem( anIter.next().first );
471 myModeGroup->button( RefImage )->setEnabled( false );
474 void HYDROGUI_ImportImageDlg::initializePointSelection()
476 if( myIsInitialized )
479 myIsInitialized = true;
481 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
485 blockSignalsLambert( true );
487 myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
488 myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
489 myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
490 myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
491 myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
492 myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
494 myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
495 myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
496 myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
497 myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
498 myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
499 myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
501 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
502 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
503 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
504 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
505 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
506 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
508 for( int aPointType = HYDROGUI_PrsImage::PointA;
509 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
510 onLambertCoordChanged( aPointType );
512 blockSignalsLambert( false );
515 //double aCartX0 = 600000;
516 //double aCartY0 = 6800000;
520 blockSignalsCartesian( true );
522 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
523 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
525 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
526 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
528 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
529 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
531 for( int aPointType = HYDROGUI_PrsImage::PointA;
532 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
533 onCartesianCoordChanged( aPointType );
535 blockSignalsCartesian( false );
538 void HYDROGUI_ImportImageDlg::onBrowse()
540 QString aFilter( tr( "IMAGE_FILTER" ) );
541 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
542 if( !aFileName.isEmpty() )
544 QImage anImage( aFileName );
545 if( !anImage.isNull() )
547 myFileName->setText( aFileName );
548 emit createPreview( anImage );
549 myImageNameGroup->setEnabled( true );
550 myTransformGroup->setEnabled( true );
555 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
557 bool anIsManualLambert = theMode == ManualLambert;
558 bool anIsManualCartesian = theMode == ManualCartesian;
559 bool anIsRefImage = theMode == RefImage;
561 myRefImage->setEnabled( anIsRefImage );
563 for( int aPointType = HYDROGUI_PrsImage::PointA;
564 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
566 myPointXDegMap[ aPointType ]->setVisible( anIsManualLambert );
567 myPointYDegMap[ aPointType ]->setVisible( anIsManualLambert );
568 myPointXMinMap[ aPointType ]->setVisible( anIsManualLambert );
569 myPointYMinMap[ aPointType ]->setVisible( anIsManualLambert );
570 myPointXSecMap[ aPointType ]->setVisible( anIsManualLambert );
571 myPointYSecMap[ aPointType ]->setVisible( anIsManualLambert );
573 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
574 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
576 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
577 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
580 QListIterator<QLabel*> anIter( myLambertLabels );
581 while( anIter.hasNext() )
582 anIter.next()->setVisible( anIsManualLambert );
584 emit modeActivated( theMode );
587 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
589 emit refImageActivated( theName );
592 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
594 int aPointType = HYDROGUI_PrsImage::None;
597 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
598 while( anIter.hasNext() )
600 int aBtnPointType = anIter.next().key();
601 QPushButton* aBtn = anIter.value();
602 if( aBtn == sender() )
603 aPointType = aBtnPointType;
606 bool anIsBlocked = aBtn->blockSignals( true );
607 aBtn->setChecked( false );
608 aBtn->blockSignals( anIsBlocked );
612 emit activatePointSelection( aPointType );
615 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
617 QObject* aSender = sender();
621 for( int aPointType = HYDROGUI_PrsImage::PointA;
622 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
624 if( aSender == myPointXMap[ aPointType ] ||
625 aSender == myPointYMap[ aPointType ] )
627 bool anIsY = aSender == myPointYMap[ aPointType ];
628 emit pointCoordChanged( false, aPointType, anIsY, theValue );
630 else if( aSender == myRefPointXMap[ aPointType ] ||
631 aSender == myRefPointYMap[ aPointType ] )
633 bool anIsY = aSender == myRefPointYMap[ aPointType ];
634 emit pointCoordChanged( true, aPointType, anIsY, theValue );
639 void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
641 QObject* aSender = sender();
645 for( int aPointType = HYDROGUI_PrsImage::PointA;
646 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
648 if( aSender == myPointXDegMap[ aPointType ] ||
649 aSender == myPointYDegMap[ aPointType ] ||
650 aSender == myPointXMinMap[ aPointType ] ||
651 aSender == myPointYMinMap[ aPointType ] ||
652 aSender == myPointXSecMap[ aPointType ] ||
653 aSender == myPointYSecMap[ aPointType ] )
655 onLambertCoordChanged( aPointType );
661 void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
664 for( int i = 0; i < 6; i++ )
667 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
668 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
669 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
670 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
671 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
672 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
674 for( int i = 0; i < 6; i++ )
678 double aLonDeg = 0, aLatDeg = 0;
679 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
680 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
682 double aXCart = 0, aYCart = 0;
683 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
685 blockSignalsCartesian( true );
687 myCartPointXMap[ thePointType ]->setValue( aXCart );
688 myCartPointYMap[ thePointType ]->setValue( aYCart );
690 blockSignalsCartesian( false );
693 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
695 QObject* aSender = sender();
699 for( int aPointType = HYDROGUI_PrsImage::PointA;
700 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
702 if( aSender == myCartPointXMap[ aPointType ] ||
703 aSender == myCartPointYMap[ aPointType ] )
705 onCartesianCoordChanged( aPointType );
711 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
714 for( int i = 0; i < 2; i++ )
717 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
718 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
720 for( int i = 0; i < 2; i++ )
724 double aLonDeg = 0, aLatDeg = 0;
725 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
727 int aXDeg = 0, aYDeg = 0;
728 int aXMin = 0, aYMin = 0;
729 double aXSec = 0, aYSec = 0;
730 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
731 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
733 blockSignalsLambert( true );
735 myPointXDegMap[ thePointType ]->setValue( aXDeg );
736 myPointYDegMap[ thePointType ]->setValue( aYDeg );
737 myPointXMinMap[ thePointType ]->setValue( aXMin );
738 myPointYMinMap[ thePointType ]->setValue( aYMin );
739 myPointXSecMap[ thePointType ]->setValue( aXSec );
740 myPointYSecMap[ thePointType ]->setValue( aYSec );
742 blockSignalsLambert( false );
745 void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
747 for( int aPointType = HYDROGUI_PrsImage::PointA;
748 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
750 myPointXDegMap[ aPointType ]->blockSignals( theState );
751 myPointXMinMap[ aPointType ]->blockSignals( theState );
752 myPointXSecMap[ aPointType ]->blockSignals( theState );
753 myPointYDegMap[ aPointType ]->blockSignals( theState );
754 myPointYMinMap[ aPointType ]->blockSignals( theState );
755 myPointYSecMap[ aPointType ]->blockSignals( theState );
759 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
761 for( int aPointType = HYDROGUI_PrsImage::PointA;
762 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
764 myCartPointXMap[ aPointType ]->blockSignals( theState );
765 myCartPointYMap[ aPointType ]->blockSignals( theState );