From: mkr Date: Fri, 13 Nov 2015 15:10:45 +0000 (+0300) Subject: refs #661: implement a transparency feature for land cover maps. X-Git-Tag: v1.5~48 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=70d38dcb6304ea526362782176be0192276107f6;p=modules%2Fhydro.git refs #661: implement a transparency feature for land cover maps. --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 061a7632..40a5fe2f 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -138,6 +138,8 @@ set(PROJECT_HEADERS HYDROGUI_RecognizeContoursDlg.h HYDROGUI_RecognizeContoursOp.h HYDROGUI_LandCoverColoringOp.h + HYDROGUI_SetTransparencyOp.h + HYDROGUI_TransparencyDlg.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -279,6 +281,8 @@ set(PROJECT_SOURCES HYDROGUI_RecognizeContoursDlg.cxx HYDROGUI_RecognizeContoursOp.cxx HYDROGUI_LandCoverColoringOp.cxx + HYDROGUI_SetTransparencyOp.cxx + HYDROGUI_TransparencyDlg.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 05e583ab..f861ac79 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -700,6 +700,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, if ( anIsObjectCanBeColored ) { theMenu->addAction( action( SetColorId ) ); + if ( anIsLandCoverMap ) + theMenu->addAction( action( SetTransparencyId ) ); theMenu->addSeparator(); } } else if ( anAllAreProfiles ) { diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index b88069db..e15ed250 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -68,6 +68,7 @@ #include "HYDROGUI_MergePolylinesOp.h" #include "HYDROGUI_SplitPolylinesOp.h" #include "HYDROGUI_LandCoverColoringOp.h" +#include "HYDROGUI_SetTransparencyOp.h" #include "HYDROGUI_ImportLandCoverMapOp.h" @@ -205,6 +206,7 @@ void HYDROGUI_Module::createActions() SLOT( onDelete() ) ); createAction( SetColorId, "COLOR" ); + createAction( SetTransparencyId, "TRANSPARENCY" ); createAction( SetZLevelId, "ZLEVEL" ); createAction( EditLocalCSId, "EDIT_LOCAL_CS" ); @@ -623,6 +625,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case SetColorId: anOp = new HYDROGUI_SetColorOp( aModule ); break; + case SetTransparencyId: + anOp = new HYDROGUI_SetTransparencyOp( aModule ); + break; case SetZLevelId: anOp = new HYDROGUI_ZLevelsOp( aModule ); break; diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index a048c16f..22ce77dc 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -100,6 +100,7 @@ enum OperationId HideAllId, SetColorId, + SetTransparencyId, SetZLevelId, EditLocalCSId, diff --git a/src/HYDROGUI/HYDROGUI_SetTransparencyOp.cxx b/src/HYDROGUI/HYDROGUI_SetTransparencyOp.cxx new file mode 100644 index 00000000..85d9d68f --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_SetTransparencyOp.cxx @@ -0,0 +1,98 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_SetTransparencyOp.h" + +#include "HYDROGUI_TransparencyDlg.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include + +#include + +/** + Constructor. + @param theModule the module +*/ +HYDROGUI_SetTransparencyOp::HYDROGUI_SetTransparencyOp( HYDROGUI_Module* theModule ) +: HYDROGUI_Operation( theModule ), + myDlg( NULL ) +{ + setName( tr( "SET_TRANSPARENCY" ) ); +} + +/** + Destructor. +*/ +HYDROGUI_SetTransparencyOp::~HYDROGUI_SetTransparencyOp() +{ +} + +void HYDROGUI_SetTransparencyOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if ( !myEditedObject.IsNull() ) + { + myDlg = new HYDROGUI_TransparencyDlg( module()->getApp()->desktop() ); + myDlg->setModal( true ); + myDlg->setWindowTitle( getName() ); + myDlg->setTransparency( myEditedObject->GetTransparency() ); + + connect( myDlg, SIGNAL( applyAndClose() ), this, SLOT( onApplyAndClose() ) ); + connect( myDlg, SIGNAL( apply() ), this, SLOT( onApply() ) ); + connect( myDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) ); + + myDlg->exec(); + } +} + +bool HYDROGUI_SetTransparencyOp::processApply( int& theUpdateFlags, + QString& theErrorMsg, + QStringList& theBrowseObjectsEntries ) +{ + if ( !myDlg || myEditedObject.IsNull() ) + return false; + + myEditedObject->SetTransparency( myDlg->getTransparency() ); + + module()->setIsToUpdate( myEditedObject ); + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; + + return true; +} + +void HYDROGUI_SetTransparencyOp::processCancel() +{ + // Delete the dialog + if ( myDlg ) { + delete myDlg; + myDlg = 0; + } +} + +void HYDROGUI_SetTransparencyOp::onApplyAndClose() +{ + HYDROGUI_Operation::onApplyAndClose(); + if ( myDlg ) + myDlg->reject(); +} diff --git a/src/HYDROGUI/HYDROGUI_SetTransparencyOp.h b/src/HYDROGUI/HYDROGUI_SetTransparencyOp.h new file mode 100644 index 00000000..5cde45b3 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_SetTransparencyOp.h @@ -0,0 +1,51 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_SETTRANSPARENCYOP_H +#define HYDROGUI_SETTRANSPARENCYOP_H + +#include "HYDROGUI_Operation.h" + +#include + +class HYDROGUI_TransparencyDlg; + +class HYDROGUI_SetTransparencyOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_SetTransparencyOp( HYDROGUI_Module* theModule ); + virtual ~HYDROGUI_SetTransparencyOp( ); + +protected: + virtual void startOperation(); + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, + QStringList& theBrowseObjectsEntries ); + virtual void processCancel(); + +protected slots: + virtual void onApplyAndClose(); + +private: + HYDROGUI_TransparencyDlg* myDlg; + + Handle(HYDROData_LandCoverMap) myEditedObject; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 5fb6e381..3d44b09a 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -516,7 +517,8 @@ void HYDROGUI_Shape::buildShape() if ( !myObject.IsNull() ) myShape->SetOwner( myObject ); - myShape->SetTransparency( 0 ); + if ( !myObject->IsKind( STANDARD_TYPE(HYDROData_LandCoverMap) ) ) + myShape->SetTransparency( 0 ); myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode ); myShape->SetSelectionMode( (Standard_Integer)mySelectionMode ); diff --git a/src/HYDROGUI/HYDROGUI_TransparencyDlg.cxx b/src/HYDROGUI/HYDROGUI_TransparencyDlg.cxx new file mode 100644 index 00000000..ef7406ec --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_TransparencyDlg.cxx @@ -0,0 +1,90 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_TransparencyDlg.h" + +#include + +#include +#include +#include + +const double RANGE = 1; +const double STEP = 0.1; +const double PREC = 1; + +/** + Constructor. + @param theParent the parent widget +*/ +HYDROGUI_TransparencyDlg::HYDROGUI_TransparencyDlg( QWidget* theParent ) + : QDialog( theParent ) +{ + myTransparency = new QtxDoubleSpinBox( 0, RANGE, STEP, PREC, PREC, this ); + myTransparency->setValue( 0.5 ); + + // Apply and close buttons + myApplyAndClose = new QPushButton( tr("APPLY_AND_CLOSE") ); + myApplyAndClose->setDefault( true ); + myApply = new QPushButton( tr("APPLY") ); + myClose = new QPushButton( tr("CLOSE") ); + + // Layout + // Spin-box layout + QHBoxLayout* aLayout = new QHBoxLayout(); + aLayout->setMargin( 5 ); + aLayout->setSpacing( 5 ); + aLayout->addWidget( new QLabel( tr( "TRANSPARENCY" ), this ) ); + aLayout->addWidget( myTransparency ); + // Apply and close buttons layout + QHBoxLayout* aDlgButtonsLayout = new QHBoxLayout(); + aDlgButtonsLayout->addWidget( myApplyAndClose ); + aDlgButtonsLayout->addWidget( myApply ); + aDlgButtonsLayout->addWidget( myClose ); + aDlgButtonsLayout->addStretch(); + // Main layout + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); + aMainLayout->setMargin( 5 ); + aMainLayout->setSpacing( 5 ); + aMainLayout->addLayout( aLayout ); + aMainLayout->addLayout( aDlgButtonsLayout ); + + // Connections + connect( myApplyAndClose, SIGNAL( clicked() ), this, SIGNAL( applyAndClose() ) ); + connect( myApply, SIGNAL( clicked() ), this, SIGNAL( apply() ) ); + connect( myClose, SIGNAL( clicked() ), this, SLOT( reject() ) ); + + setFixedSize( 300, 90 ); +} + +/** + Destructor. +*/ +HYDROGUI_TransparencyDlg::~HYDROGUI_TransparencyDlg() +{ +} + +void HYDROGUI_TransparencyDlg::setTransparency( const double& theValue ) +{ + myTransparency->setValue( theValue ); +} + +double HYDROGUI_TransparencyDlg::getTransparency() const +{ + return myTransparency->value(); +} diff --git a/src/HYDROGUI/HYDROGUI_TransparencyDlg.h b/src/HYDROGUI/HYDROGUI_TransparencyDlg.h new file mode 100644 index 00000000..0e26f90f --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_TransparencyDlg.h @@ -0,0 +1,49 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_TRANSPARENCYDLG_H +#define HYDROGUI_TRANSPARENCYDLG_H + +#include + +class QPushButton; +class QtxDoubleSpinBox; + +class HYDROGUI_TransparencyDlg : public QDialog +{ + Q_OBJECT + +public: + HYDROGUI_TransparencyDlg( QWidget* theParent ); + virtual ~HYDROGUI_TransparencyDlg(); + + void setTransparency( const double& theValue ); + double getTransparency() const; + +signals: + void applyAndClose(); + void apply(); + +private: + QtxDoubleSpinBox* myTransparency; + QPushButton* myApplyAndClose; ///< the apply changes and close dialog button + QPushButton* myApply; ///< the apply changes button + QPushButton* myClose; ///< the close dialog button +}; + +#endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 4d904c49..bc48132d 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1060,6 +1060,10 @@ Would you like to remove all references from the image? DSK_COLOR Set object color + + DSK_TRANSPARENCY + Set object transparency + DSK_ZLEVEL Change layer order @@ -1405,6 +1409,10 @@ Would you like to remove all references from the image? MEN_COLOR Color + + MEN_TRANSPARENCY + Transparency + MEN_ZLEVEL Change layer order @@ -1706,6 +1714,10 @@ Would you like to remove all references from the image? STB_COLOR Set object color + + STB_TRANSPARENCY + Set object transparency + STB_ZLEVEL Change layer order @@ -2584,6 +2596,34 @@ file cannot be correctly imported for an Obstacle definition. + + HYDROGUI_SetTransparencyOp + + SET_TRANSPARENCY + Set transparency + + + + + HYDROGUI_TransparencyDlg + + TRANSPARENCY + Transparency + + + APPLY_AND_CLOSE + Apply and Close + + + APPLY + Apply + + + CLOSE + Close + + + HYDROGUI_StreamDlg