diff --git a/Modules/Visualization/Monteverdi/include/mvdMainWindow.h b/Modules/Visualization/Monteverdi/include/mvdMainWindow.h index 655938009901bd8144e221d227bb632d40359c8e..f8523b7f5dd5fa4b303b778ca7308d76c559e61a 100644 --- a/Modules/Visualization/Monteverdi/include/mvdMainWindow.h +++ b/Modules/Visualization/Monteverdi/include/mvdMainWindow.h @@ -87,6 +87,7 @@ class KeymapDialog; class LayerStackWidget; class ShaderWidget; class StatusBarWidget; +class ProjectionBarWidget; namespace Ui { @@ -279,6 +280,10 @@ private: */ void InitializeShaderToolBar(); + /** + */ + void InitializeProjectionBarWidget(); + /** */ void InitializeStatusBarWidgets(); @@ -316,6 +321,10 @@ private: */ void ConnectStatusBar(); + /** + */ + void ConnectProjectionBarWidget(); + #if USE_PIXEL_DESCRIPTION /** @@ -426,6 +435,10 @@ private: */ KeymapDialog * m_KeymapDialog; + /** + */ + ProjectionBarWidget * m_ProjectionBarWidget; + /** */ int m_GLSL140; diff --git a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx index 84f7085b12557fd24f2d79a448ea5799071c3294..136343a139cb84f0e804a452e49e6288be0fd154 100644 --- a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx +++ b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx @@ -85,6 +85,7 @@ #include "mvdQuicklookViewRenderer.h" #include "mvdShaderWidget.h" #include "mvdStatusBarWidget.h" +#include "mvdProjectionBarWidget.h" // #include "mvdApplication.h" #include "mvdPreferencesDialog.h" @@ -142,6 +143,7 @@ MainWindow m_ShaderWidget( NULL ), m_FilenameDragAndDropEventFilter( NULL ), m_KeymapDialog( NULL ), + m_ProjectionBarWidget( NULL ), m_GLSL140( -2 ), m_isGLSLAvailable( false ), m_ForceNoGLSL( false ) @@ -309,6 +311,8 @@ MainWindow InitializeStatusBarWidgets(); + InitializeProjectionBarWidget(); + InitializeRenderToolBar(); InitializeShaderToolBar(); @@ -412,6 +416,8 @@ MainWindow ConnectStatusBar(); + ConnectProjectionBarWidget(); + // // When everything is connected, install event-filter. assert( m_ImageView!=NULL ); @@ -624,6 +630,33 @@ MainWindow ); } +/*****************************************************************************/ +void +MainWindow +::ConnectProjectionBarWidget() +{ + assert( m_ProjectionBarWidget!=NULL ); + assert( m_ImageView!=NULL ); + + QObject::connect( + m_ImageView, + SIGNAL( ScaleChanged( double, double ) ), + // to: + m_ProjectionBarWidget, + SLOT( SetProjectionScale( double, double ) ) + ); + + QObject::connect( + m_ProjectionBarWidget, + SIGNAL( ProjectionScaleChanged( double ) ), + // to: + m_ImageView->GetManipulator(), + SLOT( ZoomTo( double ) ) + ); + + +} + /*****************************************************************************/ #if USE_PIXEL_DESCRIPTION @@ -990,7 +1023,6 @@ MainWindow { m_UI->m_RenderToolBar->addSeparator(); - { m_UI->m_RenderToolBar->addWidget( new QLabel( tr( "Proj" ) ) ); @@ -1002,7 +1034,7 @@ MainWindow assert( comboBox!=NULL ); - comboBox->setObjectName( "referenceLayerComboBox" ); + comboBox->setObjectName( REFERENCE_LAYER_COMBOBOX_NAME ); comboBox->setMinimumSize( QSize( #ifdef OTB_DEBUG @@ -1015,7 +1047,7 @@ MainWindow ); m_UI->m_RenderToolBar->addWidget( comboBox ); - } + m_UI->m_RenderToolBar->addWidget( m_ProjectionBarWidget ); } /*****************************************************************************/ @@ -1036,6 +1068,15 @@ MainWindow } } +/*****************************************************************************/ +void +MainWindow +::InitializeProjectionBarWidget() +{ + assert( m_ProjectionBarWidget==NULL ); + m_ProjectionBarWidget = new ProjectionBarWidget( m_UI->m_ShaderToolBar ); +} + /*****************************************************************************/ void MainWindow diff --git a/Modules/Visualization/MonteverdiCore/include/mvdVectorImageSettings.h b/Modules/Visualization/MonteverdiCore/include/mvdVectorImageSettings.h index 73f7427e63e92b6604e1556599496128f6e07e36..441ffdca5fe42a31fac08f3327b8e786f7bcfd43 100644 --- a/Modules/Visualization/MonteverdiCore/include/mvdVectorImageSettings.h +++ b/Modules/Visualization/MonteverdiCore/include/mvdVectorImageSettings.h @@ -600,11 +600,7 @@ VectorImageSettings if( std::equal( m_GrayDynamicsParams.begin(), m_GrayDynamicsParams.end(), params.begin() ) ) - { - assert( false ); - return; - } m_GrayDynamicsParams = params; diff --git a/Modules/Visualization/MonteverdiGui/include/mvdProjectionBarWidget.h b/Modules/Visualization/MonteverdiGui/include/mvdProjectionBarWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..5a2d40ee7936b0b6ddb52cf00c65b7d9318050bc --- /dev/null +++ b/Modules/Visualization/MonteverdiGui/include/mvdProjectionBarWidget.h @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef mvdProjectionBarWidget_h +#define mvdProjectionBarWidget_h + +// +// Configuration include. +//// Included at first position before any other ones. +#include "ConfigureMonteverdi.h" + + +/*****************************************************************************/ +/* INCLUDE SECTION */ +#include <iostream> + +// +// Qt includes (sorted by alphabetic order) +//// Must be included before system/custom includes. +#include <QtGui> +#include <qnamespace.h> + +// +// System includes (sorted by alphabetic order) + +// +// ITK includes (sorted by alphabetic order) + +// +// OTB includes (sorted by alphabetic order) +#include "OTBMonteverdiGUIExport.h" +// +// Monteverdi includes (sorted by alphabetic order) +#include "mvdTypes.h" + + +/*****************************************************************************/ +/* PRE-DECLARATION SECTION */ + +namespace mvd +{ +// +// Internal classes pre-declaration. +namespace Ui +{ +class ProjectionBarWidget; +}; + +/** + * \class ProjectionBarWidget + * \ingroup OTBMonteverdiGUI + * \brief ProjectionBarWidget widget class. + * + * This Widget allow to change the zoom level of the current selected projection. + */ +class OTBMonteverdiGUI_EXPORT ProjectionBarWidget : public QWidget +{ + +Q_OBJECT; + +public: + + /** \brief Constructor. */ + explicit ProjectionBarWidget(QWidget *p = NULL, Qt::WindowFlags flags = Qt::Widget ); + + /** \brief Destructor. */ + ~ProjectionBarWidget() ITK_OVERRIDE; + +public slots: + void SetProjectionScale(double scale_x, double scale_y); + +private: + + /** + * \brief uic generated. + */ + Ui::ProjectionBarWidget *m_UI; + + /** + * emit a signal to change the scale if projectionScaleLineEdit is changed + * and if the input text is valid. + */ + void ChangeScale(); + +private slots: + /** + * When user edit the projection scale line + */ + void on_projectionScaleLineEdit_editingFinished(); + /** + * When user press return + */ + void on_projectionScaleLineEdit_returnPressed(); + +signals: + /** + */ + void ProjectionScaleChanged( double ); + +}; + +} // end namespace mvd + + +#endif //mvdProjectionBarWidget_h diff --git a/Modules/Visualization/MonteverdiGui/src/CMakeLists.txt b/Modules/Visualization/MonteverdiGui/src/CMakeLists.txt index a9c553d73df521120a7e137321da8592f6257a92..d06ac1720cb613741968f59c8ea14093c54aefad 100644 --- a/Modules/Visualization/MonteverdiGui/src/CMakeLists.txt +++ b/Modules/Visualization/MonteverdiGui/src/CMakeLists.txt @@ -50,6 +50,7 @@ set( OTBMonteverdiGUI_SRCS mvdMultiResolutionPyramidWidget.cxx #mvdMyWidget.cxx mvdPixelDescriptionWidget.cxx + mvdProjectionBarWidget.cxx mvdQuicklookViewManipulator.cxx mvdQuicklookViewRenderer.cxx mvdSearchableTreeWidget.cxx @@ -103,6 +104,7 @@ set( OTBMonteverdiGUI_HEADERS_MOC ../include/mvdMultiResolutionPyramidWidget.h #mvdMyWidget.h ../include/mvdPixelDescriptionWidget.h + ../include/mvdProjectionBarWidget.h ../include/mvdQuicklookViewManipulator.h ../include/mvdQuicklookViewRenderer.h ../include/mvdSearchableTreeWidget.h @@ -132,6 +134,7 @@ set( OTBMonteverdiGUI_FORMS mvdMultiResolutionPyramidWidget.ui #mvdMyWidget.ui mvdPixelDescriptionWidget.ui + mvdProjectionBarWidget.ui mvdSearchableTreeWidget.ui mvdShaderWidget.ui mvdStatusBarWidget.ui diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx index 8e2fd736d10bb07373fb79e177e8d8d3f2f0e595..a12e31888cadb5d6a1dbe4070d5a6a82fc9d8779 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx @@ -1587,7 +1587,8 @@ ImageViewWidget // // Apply dynamics to current layer. AbstractLayerModel * layer = layerStack->GetCurrent(); - assert( layer!=NULL ); + if( layer==NULL ) + return; if( layer->inherits( VectorImageModel::staticMetaObject.className() ) ) { @@ -1689,7 +1690,8 @@ ImageViewWidget assert( stackedLayerModel!=NULL ); AbstractLayerModel * layer = stackedLayerModel->GetCurrent(); - assert( layer!=NULL ); + if( layer==NULL ) + return; if( layer->inherits( VectorImageModel::staticMetaObject.className() ) ) { @@ -1778,7 +1780,8 @@ ImageViewWidget assert( stackedLayerModel!=NULL ); AbstractLayerModel * layer = stackedLayerModel->GetCurrent(); - assert( layer!=NULL ); + if( layer==NULL ) + return; if( layer->inherits( VectorImageModel::staticMetaObject.className() ) ) { @@ -2012,6 +2015,9 @@ ImageViewWidget StackedLayerModel * stackedLayerModel = m_Renderer->GetLayerStack(); assert( stackedLayerModel!=NULL ); + if( !stackedLayerModel->HasCurrent() ) + return; + AbstractLayerModel * layer = stackedLayerModel->GetCurrent(); assert( layer!=NULL ); @@ -2071,7 +2077,8 @@ ImageViewWidget assert( stackedLayerModel!=NULL ); AbstractLayerModel * layer = stackedLayerModel->GetCurrent(); - assert( layer!=NULL ); + if( layer==NULL ) + return; if( layer->inherits( VectorImageModel::staticMetaObject.className() ) ) { @@ -2283,7 +2290,8 @@ ImageViewWidget assert( stackedLayerModel!=NULL ); AbstractLayerModel * layer = stackedLayerModel->GetCurrent(); - assert( layer!=NULL ); + if( layer==NULL ) + return; if( layer->inherits( VectorImageModel::staticMetaObject.className() ) ) { @@ -2352,8 +2360,11 @@ ImageViewWidget assert( m_Manipulator!=NULL ); + // Update the Manipulator reference projection. + // Then all view manipulation will use this projection reference. m_Manipulator->SetWkt( image->GetProjectionRef() ); m_Manipulator->SetKeywordList( image->GetImageKeywordlist() ); + m_Manipulator->SetNativeSpacing( imageModel->GetNativeSpacing() ); } else { diff --git a/Modules/Visualization/MonteverdiGui/src/mvdProjectionBarWidget.cxx b/Modules/Visualization/MonteverdiGui/src/mvdProjectionBarWidget.cxx new file mode 100644 index 0000000000000000000000000000000000000000..04db9a66df3c27a61a2aecebd16f0f62b89ee134 --- /dev/null +++ b/Modules/Visualization/MonteverdiGui/src/mvdProjectionBarWidget.cxx @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mvdProjectionBarWidget.h" +#include "ui_mvdProjectionBarWidget.h" + +namespace mvd +{ + +ProjectionBarWidget::ProjectionBarWidget( QWidget* p, Qt::WindowFlags flags ) : + QWidget( p, flags ) + , m_UI( new mvd::Ui::ProjectionBarWidget() ) +{ + m_UI->setupUi( this ); +} + +ProjectionBarWidget::~ProjectionBarWidget() +{ + delete m_UI; + m_UI = NULL; +} + +void ProjectionBarWidget::SetProjectionScale(double scale_x, double ) +{ + QString text = "1:1"; + + if( scale_x>1.0 ) + text = QString( "%1:1" ).arg( scale_x ); + + else if( scale_x<1.0 ) + text = QString( "1:%1" ).arg( 1.0 / scale_x ); + + m_UI->projectionScaleLineEdit->setText(text); +} + +void ProjectionBarWidget::on_projectionScaleLineEdit_returnPressed() +{ + ChangeScale(); +} + +void ProjectionBarWidget::on_projectionScaleLineEdit_editingFinished() +{ + if(m_UI->projectionScaleLineEdit->isModified()) + { + ChangeScale(); + } +} + +void ProjectionBarWidget::ChangeScale() +{ + // Cancel if scale text is empty. + if( m_UI->projectionScaleLineEdit->text().isEmpty() ) + return; + + // Split scale text. + QStringList scale( m_UI->projectionScaleLineEdit->text().split( ':' ) ); + + if( scale.size()!=1 && scale.size()!=2 ) + return; + + // Convert scale numerator. + bool isOk = true; + double numerator = scale.front().toDouble( &isOk ); + + if( !isOk || numerator==0.0 ) + return; + + // Convert scale denominator. + double denominator = 1.0; + + if( scale.size()>1 ) + { + denominator = scale.back().toDouble( &isOk ); + if( !isOk ) + return; + } + + // Emit scale changed. + emit ProjectionScaleChanged( numerator / denominator ); +} + + +} diff --git a/Modules/Visualization/MonteverdiGui/src/mvdProjectionBarWidget.ui b/Modules/Visualization/MonteverdiGui/src/mvdProjectionBarWidget.ui new file mode 100644 index 0000000000000000000000000000000000000000..1434ae19a4768a1c2b24b9509cfb7fcad033bdb5 --- /dev/null +++ b/Modules/Visualization/MonteverdiGui/src/mvdProjectionBarWidget.ui @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>mvd::ProjectionBarWidget</class> + <widget class="QWidget" name="mvd::ProjectionBarWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>204</width> + <height>20</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>0</number> + </property> + <property name="sizeConstraint"> + <enum>QLayout::SetMinimumSize</enum> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="projectionScaleLabel"> + <property name="maximumSize"> + <size> + <width>100</width> + <height>20</height> + </size> + </property> + <property name="text"> + <string comment="projection">Zoom Level</string> + </property> + <property name="textInteractionFlags"> + <set>Qt::LinksAccessibleByMouse</set> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="projectionScaleLineEdit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>150</width> + <height>20</height> + </size> + </property> + <property name="toolTip"> + <string>Current zoom-level of view, relative to reference layer (projection and spacing).</string> + </property> + <property name="locale"> + <locale language="C" country="AnyCountry"/> + </property> + <property name="text"> + <string>1:1</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="placeholderText"> + <string notr="true"/> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Modules/Visualization/MonteverdiGui/src/mvdStatusBarWidget.cxx b/Modules/Visualization/MonteverdiGui/src/mvdStatusBarWidget.cxx index 6091f79e077190b7a0d00e963f3643b6bd0eb11e..484c67ad492af0b14ab4aabf1bf4b072439d7a69 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdStatusBarWidget.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdStatusBarWidget.cxx @@ -159,6 +159,10 @@ StatusBarWidget assert( m_UI->pixelIndexLineEdit!=NULL ); m_UI->pixelRadiometryLabel->setText( text ); + + // mantis-1385 hide scaleLineEdit + m_UI->label_4->hide(); + m_UI->scaleLineEdit->hide(); } /*****************************************************************************/