1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 bool isPBlocked = blockSignalsPoints( true );
389 bool isGBlocked = blockSignalsGeodesic( true );
390 bool isCBlocked = blockSignalsCartesian( true );
391 for( int aPointType = HYDROGUI_PrsImage::PointA;
392 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
394 QPushButton* aBtn = myPointBtnMap[ aPointType ];
395 bool anIsBlocked = aBtn->blockSignals( true );
396 aBtn->setChecked( false );
397 aBtn->blockSignals( anIsBlocked );
399 clearSpins( myPointXMap[ aPointType ] );
400 clearSpins( myPointYMap[ aPointType ] );
401 clearSpins( myPointXDegMap[ aPointType ] );
402 clearSpins( myPointYDegMap[ aPointType ] );
403 clearSpins( myPointXMinMap[ aPointType ] );
404 clearSpins( myPointYMinMap[ aPointType ] );
405 clearSpins( myPointXSecMap[ aPointType ] );
406 clearSpins( myPointYSecMap[ aPointType ] );
408 clearSpins( myRefPointXMap[ aPointType ] );
409 clearSpins( myRefPointYMap[ aPointType ] );
411 clearSpins( myCartPointXMap[ aPointType ] );
412 clearSpins( myCartPointYMap[ aPointType ] );
414 blockSignalsPoints( isPBlocked );
415 blockSignalsGeodesic( isGBlocked );
416 blockSignalsCartesian( isCBlocked );
418 // Emulate turning off C point usage
419 myPointCEnabler->blockSignals( true );
421 myPointCEnabler->setChecked( false );
422 myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
423 myPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
424 myPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
425 myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
426 myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
427 myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
428 myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
429 myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
430 myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
431 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
432 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
433 myRefPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
434 myRefPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
435 onSetCIsUsed( false );
437 myPointCEnabler->blockSignals( false );
439 myTransformGroup->setEnabled( false );
442 setTransformationMode( HYDROData_Image::ManualCartesian );
444 myPrsPointDataList.clear();
446 myIsInitialized = false;
449 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
451 myImageName->setText( theName );
454 QString HYDROGUI_ImportImageDlg::getImageName() const
456 return myImageName->text();
459 void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
461 myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
464 QString HYDROGUI_ImportImageDlg::getRefImageName() const
466 return myRefImage->currentText();
469 QString HYDROGUI_ImportImageDlg::getFileName() const
471 return myFileName->text();
474 void HYDROGUI_ImportImageDlg::setFileName( const QString& theName )
476 myFileName->setText( theName );
477 myImageNameGroup->setEnabled( true );
478 myTransformGroup->setEnabled( true );
481 QString HYDROGUI_ImportImageDlg::getGeoreferencementFileName() const
483 return myGeoFileName->text();
486 void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
487 const bool theIsRefImage )
489 int aWidth = theSize.width();
490 int aHeight = theSize.height();
491 for( int aPointType = HYDROGUI_PrsImage::PointA;
492 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
496 myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
497 myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
501 myPointXMap[ aPointType ]->setRange( 0, aWidth );
502 myPointYMap[ aPointType ]->setRange( 0, aHeight );
507 void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
509 myModeGroup->button( theMode )->setChecked( true );
510 onModeActivated( theMode );
513 int HYDROGUI_ImportImageDlg::getTransformationMode() const
515 return myModeGroup->checkedId();
518 void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
520 myPointCEnabler->setChecked( !theIsByTwoPoints );
523 bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
525 return !myPointCEnabler->isChecked();
528 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
529 const bool theIsOnlyInput,
530 const bool theIsRefImage )
532 blockSignalsGeodesic( true );
533 blockSignalsCartesian( true );
534 for( int aPointType = HYDROGUI_PrsImage::PointA;
535 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
537 if( theMap.contains( aPointType ) )
539 const TransformationData& aData = theMap[ aPointType ];
541 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
542 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
543 aPointX->setValue( aData.ImagePoint.x() );
544 aPointY->setValue( aData.ImagePoint.y() );
546 if( !theIsOnlyInput && !theIsRefImage )
548 QPointF aLPoint = aData.GeodesicPoint;
549 int aXDeg = 0, aYDeg = 0;
550 int aXMin = 0, aYMin = 0;
551 double aXSec = 0, aYSec = 0;
552 HYDROData_Lambert93::degToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
553 HYDROData_Lambert93::degToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
555 myPointXDegMap[ aPointType ]->setValue( aXDeg );
556 myPointYDegMap[ aPointType ]->setValue( aYDeg );
557 myPointXMinMap[ aPointType ]->setValue( aXMin );
558 myPointYMinMap[ aPointType ]->setValue( aYMin );
559 myPointXSecMap[ aPointType ]->setValue( aXSec );
560 myPointYSecMap[ aPointType ]->setValue( aYSec );
562 QPointF aCPoint = aData.CartesianPoint;
563 myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
564 myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
568 blockSignalsGeodesic( false );
569 blockSignalsCartesian( false );
572 bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
573 const bool theIsRefImage ) const
576 for( int aPointType = HYDROGUI_PrsImage::PointA;
577 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
580 for( int i = 0; i < 10; i++ )
583 QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
584 QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
585 int aX1 = aPointX->text().toInt( &anIsOk[0] );
586 int aY1 = aPointY->text().toInt( &anIsOk[1] );
588 int aXDeg = 0, aYDeg = 0;
589 int aXMin = 0, aYMin = 0;
590 double aXSec = 0, aYSec = 0;
591 double aXCart = 0, aYCart = 0;
594 aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
595 aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
596 aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
597 aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
598 aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
599 aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
601 aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
602 aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
605 for( int i = 0; i < 10; i++ )
609 double aX2 = 0, aY2 = 0;
610 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aX2 );
611 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aY2 );
613 TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
614 theMap[ aPointType ] = aData;
619 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
621 myPrsPointDataList = theList;
623 if( !myPrsPointDataList.isEmpty() )
625 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
628 myRefImage->addItem( "" ); // first empty item
630 PrsPointDataListIterator anIter( myPrsPointDataList );
631 while( anIter.hasNext() )
632 myRefImage->addItem( anIter.next().first );
635 myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
638 void HYDROGUI_ImportImageDlg::initializePointSelection()
640 if( myIsInitialized )
643 myIsInitialized = true;
645 myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
647 double aCartX0 = LAMBERT_X0;
648 double aCartY0 = LAMBERT_Y0;
650 blockSignalsCartesian( true );
652 myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
653 myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + IMG_DELTA );
655 myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + IMG_DELTA );
656 myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + IMG_DELTA );
658 myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
659 myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
661 for( int aPointType = HYDROGUI_PrsImage::PointA;
662 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
663 onCartesianCoordChanged( aPointType );
665 blockSignalsCartesian( false );
668 HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
670 const QPoint& theLocalPoint,
671 const QPointF& theGlobalPoint )
673 TransformationData aResTrsfData;
674 aResTrsfData.ImagePoint = theLocalPoint;
676 double arx = theGlobalPoint.x();
677 double ary = theGlobalPoint.y();
678 if ( theMode == HYDROData_Image::ManualGeodesic )
680 // Geodesic to Cartesian
681 double aXCart = 0, aYCart = 0;
682 // Interpreting arY as attitude and arX as longitude
683 HYDROData_Lambert93::toXY( ary, arx, aXCart, aYCart );
685 aResTrsfData.GeodesicPoint = theGlobalPoint;
686 aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
688 else if ( theMode == HYDROData_Image::ManualCartesian )
690 // Cartesian to Geodesic
691 double aLonDeg = 0, aLatDeg = 0;
692 HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
694 aResTrsfData.CartesianPoint = theGlobalPoint;
695 aResTrsfData.GeodesicPoint = QPointF( aLonDeg, aLatDeg );
701 void HYDROGUI_ImportImageDlg::onBrowse()
703 QString aFilter( tr( "IMAGE_FILTER" ) );
704 QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
705 if( !aFileName.isEmpty() )
707 QImage anImage( aFileName );
708 if( anImage.isNull() )
710 QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
711 QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
712 arg( aFileName ).arg( QFileInfo( aFileName ).suffix() );
713 SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
717 setFileName( aFileName );
718 emit createPreview( anImage );
723 void HYDROGUI_ImportImageDlg::onGeoBrowse()
725 QString aFilter( tr( "IMAGE_GEOREFERENCEMENT_FILTER" ) );
726 QString aGeoFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_GEO_DATA_FROM_FILE" ), true );
727 if( !aGeoFileName.isEmpty() ) {
728 myGeoFileName->setText( aGeoFileName );
732 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
734 bool anIsManualGeodesic = theMode == HYDROData_Image::ManualGeodesic;
735 bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
736 bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
738 myRefImage->setEnabled( anIsRefImage );
740 for( int aPointType = HYDROGUI_PrsImage::PointA;
741 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
743 myPointXDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
744 myPointYDegMap[ aPointType ]->setVisible( anIsManualGeodesic );
745 myPointXMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
746 myPointYMinMap[ aPointType ]->setVisible( anIsManualGeodesic );
747 myPointXSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
748 myPointYSecMap[ aPointType ]->setVisible( anIsManualGeodesic );
750 myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
751 myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
753 myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
754 myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
757 QListIterator<QLabel*> anIter( myGeodesicLabels );
758 while( anIter.hasNext() )
759 anIter.next()->setVisible( anIsManualGeodesic );
761 emit modeActivated( theMode );
764 void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
766 emit refImageActivated( theName );
769 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
771 int aPointType = HYDROGUI_PrsImage::None;
774 QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
775 while( anIter.hasNext() )
777 int aBtnPointType = anIter.next().key();
778 QPushButton* aBtn = anIter.value();
779 if( aBtn == sender() )
780 aPointType = aBtnPointType;
783 bool anIsBlocked = aBtn->blockSignals( true );
784 aBtn->setChecked( false );
785 aBtn->blockSignals( anIsBlocked );
789 emit activatePointSelection( aPointType );
792 void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
794 QObject* aSender = sender();
798 for( int aPointType = HYDROGUI_PrsImage::PointA;
799 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
801 if( aSender == myPointXMap[ aPointType ] ||
802 aSender == myPointYMap[ aPointType ] )
804 bool anIsY = aSender == myPointYMap[ aPointType ];
805 emit pointCoordChanged( false, aPointType, anIsY, theValue );
807 else if( aSender == myRefPointXMap[ aPointType ] ||
808 aSender == myRefPointYMap[ aPointType ] )
810 bool anIsY = aSender == myRefPointYMap[ aPointType ];
811 emit pointCoordChanged( true, aPointType, anIsY, theValue );
816 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged()
818 QObject* aSender = sender();
822 for( int aPointType = HYDROGUI_PrsImage::PointA;
823 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
825 if( aSender == myPointXDegMap[ aPointType ] ||
826 aSender == myPointYDegMap[ aPointType ] ||
827 aSender == myPointXMinMap[ aPointType ] ||
828 aSender == myPointYMinMap[ aPointType ] ||
829 aSender == myPointXSecMap[ aPointType ] ||
830 aSender == myPointYSecMap[ aPointType ] )
832 onGeodesicCoordChanged( aPointType );
838 void HYDROGUI_ImportImageDlg::onGeodesicCoordChanged( const int thePointType )
841 for( int i = 0; i < 6; i++ )
844 int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
845 int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
846 int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
847 int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
848 double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
849 double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
851 for( int i = 0; i < 6; i++ )
855 double aLonDeg = 0, aLatDeg = 0;
856 HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
857 HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
859 double aXCart = 0, aYCart = 0;
860 HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
862 blockSignalsCartesian( true );
864 myCartPointXMap[ thePointType ]->setValue( aXCart );
865 myCartPointYMap[ thePointType ]->setValue( aYCart );
867 blockSignalsCartesian( false );
870 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
872 QObject* aSender = sender();
876 for( int aPointType = HYDROGUI_PrsImage::PointA;
877 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
879 if( aSender == myCartPointXMap[ aPointType ] ||
880 aSender == myCartPointYMap[ aPointType ] )
882 onCartesianCoordChanged( aPointType );
888 void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
891 for( int i = 0; i < 2; i++ )
894 double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
895 double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
897 for( int i = 0; i < 2; i++ )
901 double aLonDeg = 0, aLatDeg = 0;
902 HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
904 int aXDeg = 0, aYDeg = 0;
905 int aXMin = 0, aYMin = 0;
906 double aXSec = 0, aYSec = 0;
907 HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
908 HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
910 blockSignalsGeodesic( true );
912 myPointXDegMap[ thePointType ]->setValue( aXDeg );
913 myPointYDegMap[ thePointType ]->setValue( aYDeg );
914 myPointXMinMap[ thePointType ]->setValue( aXMin );
915 myPointYMinMap[ thePointType ]->setValue( aYMin );
916 myPointXSecMap[ thePointType ]->setValue( aXSec );
917 myPointYSecMap[ thePointType ]->setValue( aYSec );
919 blockSignalsGeodesic( false );
922 void HYDROGUI_ImportImageDlg::clearSpins( QAbstractSpinBox* theSpin )
924 if ( dynamic_cast<QtxIntSpinBox*>( theSpin ) )
926 QtxIntSpinBox* aSpin = dynamic_cast<QtxIntSpinBox*>( theSpin );
927 aSpin->setValue( aSpin->minimum() );
929 else if ( dynamic_cast<QtxIntSpinBox*>( theSpin ) )
931 QtxDoubleSpinBox* aDblSpin = dynamic_cast<QtxDoubleSpinBox*>( theSpin );
932 aDblSpin->setValue( aDblSpin->minimum() );
938 bool HYDROGUI_ImportImageDlg::blockSignalsPoints( const bool theState )
940 bool isBlocked = false;
941 for( int aPointType = HYDROGUI_PrsImage::PointA;
942 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
945 myPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
946 myPointYMap[ aPointType ]->blockSignals( theState );
948 myRefPointXMap[ aPointType ]->blockSignals( theState );
949 myRefPointYMap[ aPointType ]->blockSignals( theState );
954 bool HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
956 bool isBlocked = false;
957 for( int aPointType = HYDROGUI_PrsImage::PointA;
958 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
961 myPointXDegMap[ aPointType ]->blockSignals( theState ) || isBlocked;
962 myPointXMinMap[ aPointType ]->blockSignals( theState );
963 myPointXSecMap[ aPointType ]->blockSignals( theState );
964 myPointYDegMap[ aPointType ]->blockSignals( theState );
965 myPointYMinMap[ aPointType ]->blockSignals( theState );
966 myPointYSecMap[ aPointType ]->blockSignals( theState );
971 bool HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
973 bool isBlocked = false;
974 for( int aPointType = HYDROGUI_PrsImage::PointA;
975 aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
978 myCartPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
979 myCartPointYMap[ aPointType ]->blockSignals( theState );