]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1326: bathymetry selection tool
authorasl <asl@opencascade.com>
Thu, 28 Sep 2017 11:58:37 +0000 (14:58 +0300)
committerasl <asl@opencascade.com>
Thu, 28 Sep 2017 11:58:37 +0000 (14:58 +0300)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Module.h
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h

index 96cbffbcee1054708d25b9e46258e1e967bee620..81e524bae1d2c7eb78ded23d8b83dc2d952baf6c 100644 (file)
@@ -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 (file)
index 0000000..aa3e0f4
--- /dev/null
@@ -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 <HYDROGUI_BathymetrySelectionOp.h>
+#include <HYDROGUI_Module.h>
+#include <HYDROGUI_BathymetryPrs.h>
+#include <OCCViewer_ViewManager.h>
+#include <LightApp_Application.h>
+
+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<OCCViewer_ViewManager*>
+    ( app->getViewManager( OCCViewer_Viewer::Type(), true ) );
+  Handle(AIS_InteractiveContext) ctx = mgr->getOCCViewer()->getAISContext();
+
+
+  QList<Handle(HYDROGUI_BathymetryPrs)> 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 (file)
index 0000000..60feb72
--- /dev/null
@@ -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 <HYDROGUI_Operation.h>
+
+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
index 2e62e5081b5ee87f1358736728b65e353f29e1a1..73e4acc7da52029898b65966591d2751c53a832c 100644 (file)
@@ -273,6 +273,7 @@ protected:
 protected slots:
   void                            onOperation();
   void                            onDelete();
+  void                            onBathymetrySelection();
 
 
   bool                            onUndo( int theNumActions );
index 8371e64d1dbe85ea64a6e5e8dee481e4aaab7d7a..3fa2afa37f50579a272d8c8d25c3288612d0d0d3 100644 (file)
@@ -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 <HYDROData_Document.h>
 #include <HYDROData_Obstacle.h>
@@ -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<QAction*>( sender() );
+  if( !a )
+    return;
+
+  bool isChecked = a->isChecked();
+  if( isChecked )
+    startOperation( BathymetrySelectionId );
+  else
+    operation( BathymetrySelectionId )->abort();
+}
index 45f95161fc61af151f9cea9a9241233b7d78cd7d..f7916633ecd684747bf3870e0bbb68473b5397f1 100644 (file)
@@ -136,6 +136,8 @@ enum OperationId
 
   LandCoverScalarMapModeOnId,
   LandCoverScalarMapModeOffId,
+
+  BathymetrySelectionId,
 };
 
 #endif