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"
27 #include "HYDROGUI_Module.h"
29 #include <HYDROData_Lambert93.h>
30 #include <HYDROData_Image.h>
32 #include <LightApp_Application.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Session.h>
39 #include <QtxDoubleSpinBox.h>
40 #include <QtxIntSpinBox.h>
42 #include <QButtonGroup>
50 #include <QPushButton>
51 #include <QRadioButton>
52 #include <QToolButton>
55 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
56 : HYDROGUI_InputPanel( theModule, theTitle ),
57 myIsInitialized( false )
59 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
61 // Import image from file
62 myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ), this );
64 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
66 myFileName = new QLineEdit( myFileNameGroup );
67 myFileName->setReadOnly( true );
69 QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
70 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
72 QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
73 aFileNameLayout->setMargin( 5 );
74 aFileNameLayout->setSpacing( 5 );
75 aFileNameLayout->addWidget( aFileNameLabel );
76 aFileNameLayout->addWidget( myFileName );
77 aFileNameLayout->addWidget( aBrowseBtn );
80 myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
82 QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
83 myImageName = new QLineEdit( myImageNameGroup );
85 QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
86 anImageNameLayout->setMargin( 5 );
87 anImageNameLayout->setSpacing( 5 );
88 anImageNameLayout->addWidget( anImageNameLabel );
89 anImageNameLayout->addWidget( myImageName );
92 myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ), this );
94 // Make a pixmap for arrow
95 QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
97 QPicture anArrowPicture;
98 anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
101 aPainter.begin( &anArrowPicture );
102 aPainter.drawPixmap( 0, 0, anArrowPixmap );
105 QRadioButton* aManualGeodesicBtn = new QRadioButton( tr( "MANUALLY_GEODESIC" ), myTransformGroup );
106 QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
107 QRadioButton* aCartesianFromFileBtn = new QRadioButton( tr( "LAMBERT93_FROM_FILE" ), myTransformGroup );
108 QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
110 myModeGroup = new QButtonGroup( myTransformGroup );
111 myModeGroup->addButton( aManualGeodesicBtn, HYDROData_Image::ManualGeodesic );
112 myModeGroup->addButton( aManualCartesianBtn, HYDROData_Image::ManualCartesian );
113 myModeGroup->addButton( aCartesianFromFileBtn, HYDROData_Image::CartesianFromFile );
114 myModeGroup->addButton( aRefImageBtn, HYDROData_Image::ReferenceImage );
116 myRefImage = new QComboBox( myTransformGroup );
118 QVBoxLayout* aTransformLayout = new QVBoxLayout( myTransformGroup );
119 aTransformLayout->setMargin( 5 );
120 aTransformLayout->setSpacing( 5 );
122 QGridLayout* aModeLayout = new QGridLayout( myTransformGroup );
123 aModeLayout->setMargin( 0 );
124 aModeLayout->setSpacing( 5 );
125 aModeLayout->addWidget( aManualGeodesicBtn, 0, 0 );
126 aModeLayout->addWidget( aManualCartesianBtn, 1, 0 );
127 aModeLayout->addWidget( aCartesianFromFileBtn, 2, 0 );
128 aModeLayout->addWidget( aRefImageBtn, 3, 0 );
129 aModeLayout->addWidget( myRefImage, 3, 1 );
130 aModeLayout->setColumnStretch( 1, 1 );
132 aTransformLayout->addLayout( aModeLayout );
134 // Manual input widget
135 QWidget* aManualInputGroup = new QWidget( myTransformGroup );
136 QGridLayout* aManualInputLayout = new QGridLayout( aManualInputGroup );
137 aManualInputLayout->setMargin( 5 );
138 aManualInputLayout->setSpacing( 5 );
140 QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), aManualInputGroup );
141 QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), aManualInputGroup );
142 QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), aManualInputGroup );
143 QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), aManualInputGroup );
145 aManualInputLayout->addWidget( aImageCSLabel, 0, 1 );
146 aManualInputLayout->addWidget( aGeodesicLabel, 0, 2, 1, 6 );
147 aManualInputLayout->addWidget( aLambertLabel, 0, 2, 1, 6 );
148 aManualInputLayout->addWidget( aRefImageLabel, 0, 2, 1, 6 );
150 for( int aPointType = HYDROGUI_PrsImage::PointA;
151 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
156 case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
157 case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
158 case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
160 QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
161 aPointBtn->setCheckable( true );
163 QLabel* aPointXLabel = new QLabel( "X", aManualInputGroup );
164 QLabel* aPointYLabel = new QLabel( "Y", aManualInputGroup );
166 QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
167 QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
169 QLabel* aPointArrowLabel = new QLabel( aManualInputGroup );
170 aPointArrowLabel->setPicture( anArrowPicture );
172 QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), aManualInputGroup );
173 QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), aManualInputGroup );
174 QLabel* aPointXMinLabel = new QLabel( "'", aManualInputGroup );
175 QLabel* aPointYMinLabel = new QLabel( "'", aManualInputGroup );
176 QLabel* aPointXSecLabel = new QLabel( "\"", aManualInputGroup );
177 QLabel* aPointYSecLabel = new QLabel( "\"", aManualInputGroup );
178 QLabel* aPointLatLabel = new QLabel( tr( "POINT_LATITUDE" ), aManualInputGroup );
179 QLabel* aPointLonLabel = new QLabel( tr( "POINT_LONGITUDE" ), aManualInputGroup );
180 myGeodesicLabels << aPointXDegLabel << aPointYDegLabel
181 << aPointXMinLabel << aPointYMinLabel
182 << aPointXSecLabel << aPointYSecLabel
183 << aPointLonLabel << aPointLatLabel;
185 QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -179, 179, 1, aManualInputGroup );
186 QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 89, 1, aManualInputGroup );
187 QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, aManualInputGroup );
188 QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, aManualInputGroup );
189 QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, aManualInputGroup );
190 QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, aManualInputGroup );
192 QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, aManualInputGroup );
193 QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, aManualInputGroup );
195 QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
196 QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later
198 int aRow = 4 * aPointType;
199 if ( aPointType == HYDROGUI_PrsImage::PointC )
201 myPointCEnabler = new QCheckBox( aManualInputGroup );
202 aManualInputLayout->addWidget( myPointCEnabler, aRow, 0, 1, 2, Qt::AlignHCenter );
203 aManualInputLayout->addWidget( aPointBtn, aRow, 2, 1, 8 );
207 aManualInputLayout->addWidget( aPointBtn, aRow, 0, 1, 10 );
210 aManualInputLayout->addWidget( aPointXLabel, aRow + 1, 0 );
211 aManualInputLayout->addWidget( aPointX, aRow + 1, 1 );
212 aManualInputLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
213 aManualInputLayout->addWidget( aPointXDeg, aRow + 1, 3 );
214 aManualInputLayout->addWidget( aPointXDegLabel, aRow + 1, 4 );
215 aManualInputLayout->addWidget( aPointXMin, aRow + 1, 5 );
216 aManualInputLayout->addWidget( aPointXMinLabel, aRow + 1, 6 );
217 aManualInputLayout->addWidget( aPointXSec, aRow + 1, 7 );
218 aManualInputLayout->addWidget( aPointXSecLabel, aRow + 1, 8 );
219 aManualInputLayout->addWidget( aPointLonLabel, aRow + 1, 9 );
221 aManualInputLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 );
222 aManualInputLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 );
224 aManualInputLayout->addWidget( aPointYLabel, aRow + 2, 0 );
225 aManualInputLayout->addWidget( aPointY, aRow + 2, 1 );
226 aManualInputLayout->addWidget( aPointYDeg, aRow + 2, 3 );
227 aManualInputLayout->addWidget( aPointYDegLabel, aRow + 2, 4 );
228 aManualInputLayout->addWidget( aPointYMin, aRow + 2, 5 );
229 aManualInputLayout->addWidget( aPointYMinLabel, aRow + 2, 6 );
230 aManualInputLayout->addWidget( aPointYSec, aRow + 2, 7 );
231 aManualInputLayout->addWidget( aPointYSecLabel, aRow + 2, 8 );
232 aManualInputLayout->addWidget( aPointLatLabel, aRow + 2, 9 );
234 aManualInputLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 );
235 aManualInputLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
237 if( aPointType != HYDROGUI_PrsImage::PointC )
239 QFrame* aLine = new QFrame( aManualInputGroup );
240 aLine->setFrameShape( QFrame::HLine );
241 aLine->setFrameShadow( QFrame::Sunken );
242 aManualInputLayout->addWidget( aLine, aRow + 3, 0, 1, 10 );
245 myPointBtnMap[ aPointType ] = aPointBtn;
246 myPointXMap[ aPointType ] = aPointX;
247 myPointYMap[ aPointType ] = aPointY;
248 myPointXDegMap[ aPointType ] = aPointXDeg;
249 myPointYDegMap[ aPointType ] = aPointYDeg;
250 myPointXMinMap[ aPointType ] = aPointXMin;
251 myPointYMinMap[ aPointType ] = aPointYMin;
252 myPointXSecMap[ aPointType ] = aPointXSec;
253 myPointYSecMap[ aPointType ] = aPointYSec;
255 myCartPointXMap[ aPointType ] = aCartPointX;
256 myCartPointYMap[ aPointType ] = aCartPointY;
258 myRefPointXMap[ aPointType ] = aRefPointX;
259 myRefPointYMap[ aPointType ] = aRefPointY;
261 connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
263 connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
264 connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
266 connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
267 connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
268 connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
269 connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onGeodesicCoordChanged() ) );
270 connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
271 connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onGeodesicCoordChanged() ) );
273 connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
274 connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
276 connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
277 connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
280 // Connect checkbox enabling point C
281 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
282 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
283 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
284 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
285 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
286 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
287 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
288 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
289 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
290 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
291 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
292 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
293 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
295 connect( myPointCEnabler, SIGNAL( toggled( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
297 aManualInputLayout->setColumnStretch( 1, 1 ); // double
298 aManualInputLayout->setColumnStretch( 3, 1 ); // degrees
299 aManualInputLayout->setColumnStretch( 5, 1 ); // minutes
300 aManualInputLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
302 // Image georeferencement file widget
303 QWidget* aFromFileInputGroup = new QWidget( myTransformGroup );
304 QBoxLayout* aFromFileInputLayout = new QHBoxLayout( aFromFileInputGroup );
305 aFromFileInputLayout->setMargin( 5 );
306 aFromFileInputLayout->setSpacing( 5 );
308 QLabel* aGeoFileNameLabel = new QLabel( tr( "FILE_NAME" ), aFromFileInputGroup );
310 myGeoFileName = new QLineEdit( aFromFileInputGroup );
311 myGeoFileName->setReadOnly( true );
313 QToolButton* aGeoBrowseBtn = new QToolButton( aFromFileInputGroup );
314 aGeoBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
316 aFromFileInputLayout->addWidget( aGeoFileNameLabel );
317 aFromFileInputLayout->addWidget( myGeoFileName );
318 aFromFileInputLayout->addWidget( aGeoBrowseBtn );
320 // Widgets connections
321 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
322 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
323 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
324 connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) );
325 connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
326 connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
327 connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
328 connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) );
329 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
330 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
331 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
332 connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) );
333 connect( aCartesianFromFileBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setVisible ( bool ) ) );
334 connect( aCartesianFromFileBtn, SIGNAL( toggled( bool ) ), aManualInputGroup, SLOT( setHidden ( bool ) ) );
337 aTransformLayout->addWidget( aManualInputGroup );
338 aTransformLayout->addWidget( aFromFileInputGroup );
341 addWidget( myFileNameGroup );
342 addWidget( myImageNameGroup );
343 addWidget( myTransformGroup );
346 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
348 connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
349 this, SLOT( onModeActivated( int ) ) );
351 connect( aGeoBrowseBtn, SIGNAL( clicked() ), this, SLOT( onGeoBrowse() ) );
353 connect( myRefImage, SIGNAL( activated( const QString& ) ),
354 this, SLOT( onRefImageActivated( const QString& ) ) );
356 //setTransformationMode( HYDROData_Image::ManualCartesian );
358 setMinimumWidth( 350 );
361 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
365 void HYDROGUI_ImportImageDlg::onSetCIsUsed( bool theCIsUsed )
367 if ( !theCIsUsed && myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->isChecked() )
369 // Turn on point A selection if point C selection has been activated and we disable point C.
370 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->toggle();
372 emit setCIsUsed( theCIsUsed );
375 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
377 myFileNameGroup->setVisible( !theIsEdit );
378 myImageNameGroup->setEnabled( theIsEdit );
379 myTransformGroup->setEnabled( theIsEdit );
382 void HYDROGUI_ImportImageDlg::reset()
385 myImageName->clear();
386 myImageNameGroup->setEnabled( false );
387 myGeoFileName->clear();
388 for( int aPointType = HYDROGUI_PrsImage::PointA;
389 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
391 QPushButton* aBtn = myPointBtnMap[ aPointType ];
392 bool anIsBlocked = aBtn->blockSignals( true );
393 aBtn->setChecked( false );
394 aBtn->blockSignals( anIsBlocked );
396 myPointXMap[ aPointType ]->clear();
397 myPointYMap[ aPointType ]->clear();
398 myPointXDegMap[ aPointType ]->clear();
399 myPointYDegMap[ aPointType ]->clear();
400 myPointXMinMap[ aPointType ]->clear();
401 myPointYMinMap[ aPointType ]->clear();
402 myPointXSecMap[ aPointType ]->clear();
403 myPointYSecMap[ aPointType ]->clear();
405 myRefPointXMap[ aPointType ]->clear();
406 myRefPointYMap[ aPointType ]->clear();
408 myCartPointXMap[ aPointType ]->clear();
409 myCartPointYMap[ aPointType ]->clear();
412 // Emulate turning off C point usage
413 myPointCEnabler->blockSignals( true );
415 myPointCEnabler->setChecked( false );
416 myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
417 myPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
418 myPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
419 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
420 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
421 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
422 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
423 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
424 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
425 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
426 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
427 myRefPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
428 myRefPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
429 onSetCIsUsed( false );
431 myPointCEnabler->blockSignals( false );
433 myTransformGroup->setEnabled( false );
436 setTransformationMode( HYDROData_Image::ManualCartesian );
438 myPrsPointDataList.clear();
440 myIsInitialized = false;
443 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
445 myImageName->setText( theName );
448 QString HYDROGUI_ImportImageDlg::getImageName() const
450 return myImageName->text();
453 void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
455 myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
458 QString HYDROGUI_ImportImageDlg::getRefImageName() const
460 return myRefImage->currentText();
463 QString HYDROGUI_ImportImageDlg::getFileName() const
465 return myFileName->text();
468 QString HYDROGUI_ImportImageDlg::getGeoreferencementFileName() const
470 return myGeoFileName->text();
473 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
474 const bool theIsRefImage )
476 int aWidth = theSize.width();
477 int aHeight = theSize.height();
478 for( int aPointType = HYDROGUI_PrsImage::PointA;
479 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
483 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
484 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
488 myPointXMap[ aPointType ]->setRange( 0, aWidth );
489 myPointYMap[ aPointType ]->setRange( 0, aHeight );
494 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
496 myModeGroup->button( theMode )->setChecked( true );
497 onModeActivated( theMode );
500 int HYDROGUI_ImportImageDlg::getTransformationMode() const
502 return myModeGroup->checkedId();
505 void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
507 myPointCEnabler->setChecked( !theIsByTwoPoints );
510 bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
512 return !myPointCEnabler->isChecked();
515 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
516 const bool theIsOnlyInput,
517 const bool theIsRefImage )
519 blockSignalsGeodesic( true );
520 blockSignalsCartesian( true );
521 for( int aPointType = HYDROGUI_PrsImage::PointA;
522 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
524 if( theMap.contains( aPointType ) )
526 const TransformationData& aData = theMap[ aPointType ];
528 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
529 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
530 aPointX->setValue( aData.ImagePoint.x() );
531 aPointY->setValue( aData.ImagePoint.y() );
533 if( !theIsOnlyInput && !theIsRefImage )
535 QPointF aLPoint = aData.GeodesicPoint;
536 int aXDeg = 0, aYDeg = 0;
537 int aXMin = 0, aYMin = 0;
538 double aXSec = 0, aYSec = 0;
539 HYDROData_Lambert93::degToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
540 HYDROData_Lambert93::degToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
542 myPointXDegMap[ aPointType ]->setValue( aXDeg );
543 myPointYDegMap[ aPointType ]->setValue( aYDeg );
544 myPointXMinMap[ aPointType ]->setValue( aXMin );
545 myPointYMinMap[ aPointType ]->setValue( aYMin );
546 myPointXSecMap[ aPointType ]->setValue( aXSec );
547 myPointYSecMap[ aPointType ]->setValue( aYSec );
549 QPointF aCPoint = aData.CartesianPoint;
550 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
551 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
555 blockSignalsGeodesic( false );
556 blockSignalsCartesian( false );
559 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
560 const bool theIsRefImage ) const
563 for( int aPointType = HYDROGUI_PrsImage::PointA;
564 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
567 for( int i = 0; i < 10; i++ )
570 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
571 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
572 int aX1 = aPointX->text().toInt( &anIsOk[0] );
573 int aY1 = aPointY->text().toInt( &anIsOk[1] );
575 int aXDeg = 0, aYDeg = 0;
576 int aXMin = 0, aYMin = 0;
577 double aXSec = 0, aYSec = 0;
578 double aXCart = 0, aYCart = 0;
581 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
582 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
583 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
584 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
585 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
586 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
588 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
589 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
592 for( int i = 0; i < 10; i++ )
596 double aX2 = 0, aY2 = 0;
597 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aX2 );
598 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aY2 );
600 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
601 theMap[ aPointType ] = aData;
606 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
608 myPrsPointDataList = theList;
610 if( !myPrsPointDataList.isEmpty() )
612 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
615 myRefImage->addItem( "" ); // first empty item
617 PrsPointDataListIterator anIter( myPrsPointDataList );
618 while( anIter.hasNext() )
619 myRefImage->addItem( anIter.next().first );
622 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
625 void HYDROGUI_ImportImageDlg::initializePointSelection()
627 if( myIsInitialized )
630 myIsInitialized = true;
632 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
634 double aCartX0 = LAMBERT_X0;
635 double aCartY0 = LAMBERT_Y0;
637 blockSignalsCartesian( true );
639 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
640 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + IMG_DELTA );
642 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + IMG_DELTA );
643 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + IMG_DELTA );
645 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
646 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
648 for( int aPointType = HYDROGUI_PrsImage::PointA;
649 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
650 onCartesianCoordChanged( aPointType );
652 blockSignalsCartesian( false );
655 HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
657 const QPoint& theLocalPoint,
658 const QPointF& theGlobalPoint )
660 TransformationData aResTrsfData;
661 aResTrsfData.ImagePoint = theLocalPoint;
663 double arx = theGlobalPoint.x();
664 double ary = theGlobalPoint.y();
665 if ( theMode == HYDROData_Image::ManualGeodesic )
667 // Geodesic to Cartesian
668 double aXCart = 0, aYCart = 0;
669 // Interpreting arY as attitude and arX as longitude
670 HYDROData_Lambert93::toXY( ary, arx, aXCart, aYCart );
672 aResTrsfData.GeodesicPoint = theGlobalPoint;
673 aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
675 else if ( theMode == HYDROData_Image::ManualCartesian )
677 // Cartesian to Geodesic
678 double aLonDeg = 0, aLatDeg = 0;
679 HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
681 aResTrsfData.CartesianPoint = theGlobalPoint;
682 aResTrsfData.GeodesicPoint = QPointF( aLonDeg, aLatDeg );
688 void HYDROGUI_ImportImageDlg::onBrowse()
690 QString aFilter( tr( "IMAGE_FILTER" ) );
691 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
692 if( !aFileName.isEmpty() )
694 QImage anImage( aFileName );
695 if( anImage.isNull() )
697 QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
698 QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
699 arg( aFileName ).arg( QFileInfo( aFileName ).suffix() );
700 SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
704 myFileName->setText( aFileName );
705 emit createPreview( anImage );
706 myImageNameGroup->setEnabled( true );
707 myTransformGroup->setEnabled( true );
712 void HYDROGUI_ImportImageDlg::onGeoBrowse()
714 QString aFilter( tr( "IMAGE_GEOREFERENCEMENT_FILTER" ) );
715 QString aGeoFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_GEO_DATA_FROM_FILE" ), true );
716 if( !aGeoFileName.isEmpty() ) {
717 myGeoFileName->setText( aGeoFileName );
721 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
723 bool anIsManualGeodesic = theMode == HYDROData_Image::ManualGeodesic;
724 bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
725 bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
727 myRefImage->setEnabled( anIsRefImage );
729 for( int aPointType = HYDROGUI_PrsImage::PointA;
730 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
732 myPointXDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
733 myPointYDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
734 myPointXMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
735 myPointYMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
736 myPointXSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
737 myPointYSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
739 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
740 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
742 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
743 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
746 QListIterator<QLabel*> anIter( myGeodesicLabels );
747 while( anIter.hasNext() )
748 anIter.next()->setVisible( anIsManualGeodesic );
750 emit modeActivated( theMode );
753 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
755 emit refImageActivated( theName );
758 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
760 int aPointType = HYDROGUI_PrsImage::None;
763 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
764 while( anIter.hasNext() )
766 int aBtnPointType = anIter.next().key();
767 QPushButton* aBtn = anIter.value();
768 if( aBtn == sender() )
769 aPointType = aBtnPointType;
772 bool anIsBlocked = aBtn->blockSignals( true );
773 aBtn->setChecked( false );
774 aBtn->blockSignals( anIsBlocked );
778 emit activatePointSelection( aPointType );
781 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
783 QObject* aSender = sender();
787 for( int aPointType = HYDROGUI_PrsImage::PointA;
788 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
790 if( aSender == myPointXMap[ aPointType ] ||
791 aSender == myPointYMap[ aPointType ] )
793 bool anIsY = aSender == myPointYMap[ aPointType ];
794 emit pointCoordChanged( false, aPointType, anIsY, theValue );
796 else if( aSender == myRefPointXMap[ aPointType ] ||
797 aSender == myRefPointYMap[ aPointType ] )
799 bool anIsY = aSender == myRefPointYMap[ aPointType ];
800 emit pointCoordChanged( true, aPointType, anIsY, theValue );
805 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged()
807 QObject* aSender = sender();
811 for( int aPointType = HYDROGUI_PrsImage::PointA;
812 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
814 if( aSender == myPointXDegMap[ aPointType ] ||
815 aSender == myPointYDegMap[ aPointType ] ||
816 aSender == myPointXMinMap[ aPointType ] ||
817 aSender == myPointYMinMap[ aPointType ] ||
818 aSender == myPointXSecMap[ aPointType ] ||
819 aSender == myPointYSecMap[ aPointType ] )
821 onGeodesicCoordChanged( aPointType );
827 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged( const int thePointType )
830 for( int i = 0; i < 6; i++ )
833 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
834 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
835 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
836 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
837 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
838 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
840 for( int i = 0; i < 6; i++ )
844 double aLonDeg = 0, aLatDeg = 0;
845 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
846 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
848 double aXCart = 0, aYCart = 0;
849 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
851 blockSignalsCartesian( true );
853 myCartPointXMap[ thePointType ]->setValue( aXCart );
854 myCartPointYMap[ thePointType ]->setValue( aYCart );
856 blockSignalsCartesian( false );
859 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
861 QObject* aSender = sender();
865 for( int aPointType = HYDROGUI_PrsImage::PointA;
866 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
868 if( aSender == myCartPointXMap[ aPointType ] ||
869 aSender == myCartPointYMap[ aPointType ] )
871 onCartesianCoordChanged( aPointType );
877 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
880 for( int i = 0; i < 2; i++ )
883 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
884 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
886 for( int i = 0; i < 2; i++ )
890 double aLonDeg = 0, aLatDeg = 0;
891 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
893 int aXDeg = 0, aYDeg = 0;
894 int aXMin = 0, aYMin = 0;
895 double aXSec = 0, aYSec = 0;
896 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
897 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
899 blockSignalsGeodesic( true );
901 myPointXDegMap[ thePointType ]->setValue( aXDeg );
902 myPointYDegMap[ thePointType ]->setValue( aYDeg );
903 myPointXMinMap[ thePointType ]->setValue( aXMin );
904 myPointYMinMap[ thePointType ]->setValue( aYMin );
905 myPointXSecMap[ thePointType ]->setValue( aXSec );
906 myPointYSecMap[ thePointType ]->setValue( aYSec );
908 blockSignalsGeodesic( false );
911 void HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
913 for( int aPointType = HYDROGUI_PrsImage::PointA;
914 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
916 myPointXDegMap[ aPointType ]->blockSignals( theState );
917 myPointXMinMap[ aPointType ]->blockSignals( theState );
918 myPointXSecMap[ aPointType ]->blockSignals( theState );
919 myPointYDegMap[ aPointType ]->blockSignals( theState );
920 myPointYMinMap[ aPointType ]->blockSignals( theState );
921 myPointYSecMap[ aPointType ]->blockSignals( theState );
925 void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
927 for( int aPointType = HYDROGUI_PrsImage::PointA;
928 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
930 myCartPointXMap[ aPointType ]->blockSignals( theState );
931 myCartPointYMap[ aPointType ]->blockSignals( theState );