From: asl Date: Thu, 28 Sep 2017 11:58:37 +0000 (+0300) Subject: refs #1326: bathymetry selection tool X-Git-Tag: v2.1~66^2~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1f51ca0e21723b3fadfeef326ad23bc1da562ec3;p=modules%2Fhydro.git refs #1326: bathymetry selection tool --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 96cbffbc..81e524ba 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -123,6 +123,7 @@ set(PROJECT_HEADERS HYDROGUI_GeoreferencementOp.h HYDROGUI_Actor.h HYDROGUI_BathymetryBoundsOp.h + HYDROGUI_BathymetrySelectionOp.h HYDROGUI_TranslateObstacleDlg.h HYDROGUI_TranslateObstacleOp.h HYDROGUI_ListModel.h @@ -267,6 +268,7 @@ set(PROJECT_SOURCES HYDROGUI_GeoreferencementOp.cxx HYDROGUI_Actor.cxx HYDROGUI_BathymetryBoundsOp.cxx + HYDROGUI_BathymetrySelectionOp.cxx HYDROGUI_TranslateObstacleDlg.cxx HYDROGUI_TranslateObstacleOp.cxx HYDROGUI_ListModel.cxx diff --git a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx new file mode 100644 index 00000000..aa3e0f4b --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx @@ -0,0 +1,94 @@ +// 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 +//See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include +#include +#include + +HYDROGUI_BathymetrySelectionOp::HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule ) +: HYDROGUI_Operation( theModule ), myIsActive( false ) +{ +} + +HYDROGUI_BathymetrySelectionOp::~HYDROGUI_BathymetrySelectionOp() +{ +} + +void HYDROGUI_BathymetrySelectionOp::startOperation() +{ + activateSelection( true ); +} + +void HYDROGUI_BathymetrySelectionOp::abortOperation() +{ + activateSelection( false ); +} + +void HYDROGUI_BathymetrySelectionOp::commitOperation() +{ + activateSelection( false ); +} + +void HYDROGUI_BathymetrySelectionOp::stopOperation() +{ + activateSelection( false ); +} + +void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive ) +{ + if( myIsActive==isActive ) + return; + + LightApp_Application* app = module()->getApp(); + OCCViewer_ViewManager* mgr = dynamic_cast + ( app->getViewManager( OCCViewer_Viewer::Type(), true ) ); + Handle(AIS_InteractiveContext) ctx = mgr->getOCCViewer()->getAISContext(); + + + QList baths; + + AIS_ListOfInteractive objs; + ctx->DisplayedObjects( objs ); + AIS_ListIteratorOfListOfInteractive it( objs ); + for( ; it.More(); it.Next() ) + { + Handle(HYDROGUI_BathymetryPrs) bath = Handle(HYDROGUI_BathymetryPrs)::DownCast( it.Value() ); + if( !bath.IsNull() ) + baths.append( bath ); + } + + if( isActive ) + { + const int aSelectionMode = 1; + ctx->OpenLocalContext( Standard_True ); + foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths ) + ctx->Activate( bath, aSelectionMode, Standard_True ); + ctx->UpdateCurrentViewer(); + } + else + { + foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths ) + ctx->Deactivate( bath ); + ctx->CloseLocalContext( -1, Standard_True ); + } + + myIsActive = isActive; +} diff --git a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h new file mode 100644 index 00000000..60feb727 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h @@ -0,0 +1,45 @@ +// 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_BATHYMETRY_SELECTION_H +#define HYDROGUI_BATHYMETRY_SELECTION_H + +#include + +class HYDROGUI_BathymetrySelectionOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule ); + virtual ~HYDROGUI_BathymetrySelectionOp(); + +protected: + virtual void startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); + virtual void stopOperation(); + + void activateSelection( bool ); + +private: + bool myIsActive; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 2e62e508..73e4acc7 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -273,6 +273,7 @@ protected: protected slots: void onOperation(); void onDelete(); + void onBathymetrySelection(); bool onUndo( int theNumActions ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 8371e64d..3fa2afa3 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -69,8 +69,8 @@ #include "HYDROGUI_SplitPolylinesOp.h" #include "HYDROGUI_LandCoverColoringOp.h" #include "HYDROGUI_SetTransparencyOp.h" - #include "HYDROGUI_ImportLandCoverMapOp.h" +#include "HYDROGUI_BathymetrySelectionOp.h" #include #include @@ -153,6 +153,8 @@ void HYDROGUI_Module::createActions() createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "IMPORT_BATHYMETRY_ICO", Qt::CTRL + Qt::Key_B ); createAction( EditImportedBathymetryId, "EDIT_IMPORTED_BATHYMETRY", "EDIT_IMPORTED_BATHYMETRY_ICO" ); createAction( BathymetryBoundsId, "BATHYMETRY_BOUNDS", "BATHYMETRY_BOUNDS_ICO" ); + createAction( BathymetrySelectionId, "BATHYMETRY_SELECTION", "BATHYMETRY_SELECTION_ICO", + 0, true, SLOT( onBathymetrySelection() ) ); createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE", "CREATE_IMMERSIBLE_ZONE_ICO" ); createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE", "EDIT_IMMERSIBLE_ZONE_ICO" ); @@ -365,6 +367,9 @@ void HYDROGUI_Module::createToolbars() createTool( FuseImagesId, aToolBar ); createTool( CutImagesId, aToolBar ); createTool( SplitImageId, aToolBar ); + + createTool( separator(), aToolBar ); + createTool( BathymetrySelectionId, aToolBar ); } void HYDROGUI_Module::createUndoRedoActions() @@ -565,6 +570,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case BathymetryBoundsId: anOp = new HYDROGUI_BathymetryBoundsOp( aModule ); break; + case BathymetrySelectionId: + anOp = new HYDROGUI_BathymetrySelectionOp( aModule ); + break; case CreateImmersibleZoneId: case EditImmersibleZoneId: anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId ); @@ -755,3 +763,16 @@ bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theN } return aRes; } + +void HYDROGUI_Module::onBathymetrySelection() +{ + QAction* a = qobject_cast( sender() ); + if( !a ) + return; + + bool isChecked = a->isChecked(); + if( isChecked ) + startOperation( BathymetrySelectionId ); + else + operation( BathymetrySelectionId )->abort(); +} diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 45f95161..f7916633 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -136,6 +136,8 @@ enum OperationId LandCoverScalarMapModeOnId, LandCoverScalarMapModeOffId, + + BathymetrySelectionId, }; #endif