Salome HOME
refs #669, #677: selection of land covers in extended mode without pressing Shift...
authormkr <mkr@opencascade.com>
Mon, 16 Nov 2015 12:50:03 +0000 (15:50 +0300)
committermkr <mkr@opencascade.com>
Mon, 16 Nov 2015 12:50:03 +0000 (15:50 +0300)
src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index a04f5a1ca1267a996e1a13c46627899fc7415722..2ee439166911441804bb825c3d2974cb7d42f228 100644 (file)
@@ -26,6 +26,7 @@
 #include "HYDROGUI_UpdateFlags.h"
 #include "HYDROGUI_DataObject.h"
 #include "HYDROGUI_ShapeLandCoverMap.h"
+#include "HYDROGUI_OCCSelector.h"
 
 #include <HYDROData_Iterator.h>
 #include <HYDROData_StricklerTable.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
 
 #include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SUIT_ViewWindow.h>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
@@ -44,6 +49,7 @@
 #include <AIS_Shape.hxx>
 
 #include <QApplication>
+#include <QMouseEvent>
 
 HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId )
 : HYDROGUI_Operation( theModule ),
@@ -378,7 +384,34 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview()
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if ( !aCtx.IsNull() )
       {
-        connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+        disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+          aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+        disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
+          aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));        
+
+        connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+            this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+        connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+          this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+
+        LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+        if( aSelectionMgr )
+        {
+          QList<SUIT_Selector*> aSelectorList;
+          aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
+          QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
+          for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
+          {
+            HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
+            if ( aHydroSelector )
+            {
+              disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+              connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+            }
+          }
+        }
+        
+        connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
         myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
       }
     }
@@ -437,6 +470,70 @@ void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
   }
 }
 
+void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
+{
+  myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
+}
+
+void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
+{
+  if (theEvent->button() != Qt::LeftButton) return;
+  if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
+
+  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
+  if (!aView )
+    return;
+
+  OCCViewer_ViewManager* aViewManager = getPreviewManager();
+  if ( !aViewManager )
+    return;
+  
+  OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
+  if ( !aViewer )
+    return;
+
+  Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
+  if ( aCtx.IsNull() )
+    return;
+
+  myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
+
+  if (myStartPnt == myEndPnt)
+  {
+    if ( !aViewer->isPreselectionEnabled() ) {
+      Handle(V3d_View) aView3d = aView->getViewPort()->getView();
+      if ( !aView3d.IsNull() ) {
+        aCtx->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
+      }
+    }
+
+    Handle(StdSelect_ViewerSelector3d) aMainSelector = aCtx->MainSelector();
+    if ( aMainSelector.IsNull() )
+      return;
+    const Standard_Integer aDetectedNb = aMainSelector->NbPicked();
+    if ( aDetectedNb == 0 )
+    {
+      aCtx->ClearSelected( false );
+      emit deselection();
+    }
+
+    for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
+    {
+      Handle(SelectMgr_EntityOwner) anOwner = aMainSelector->Picked (aDetIter);
+      aCtx->AddOrRemoveSelected( anOwner, Standard_False );
+    }
+  }
+  else
+  {
+    aCtx->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
+                      myEndPnt.x(), myEndPnt.y(),
+                      aView->getViewPort()->getView(), Standard_False );
+  }
+
+  aCtx->UpdateCurrentViewer();
+  emit selectionChanged();  
+}
+
 void HYDROGUI_LandCoverMapOp::closePreview()
 {
   if( myPreviewPrs )
@@ -451,6 +548,39 @@ void HYDROGUI_LandCoverMapOp::closePreview()
 
   if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
     aPanel->setApplyEnabled( false );
+
+  OCCViewer_ViewManager* aViewManager = getPreviewManager();
+  if ( aViewManager )
+  {
+    if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+    {
+      disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+        this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+      disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+        this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+      connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+        aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+      connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
+        aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));  
+
+      LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+      if( aSelectionMgr )
+      {
+        QList<SUIT_Selector*> aSelectorList;
+        aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
+        QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
+        for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
+        {
+          HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
+          if ( aHydroSelector )
+          {
+            disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+            connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );            
+          }
+        }
+      }
+    }
+  }
 }
 
 Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
index 1a33bf25a6c2b81388991e1088831bbba576bce9..0c08817e7e3211266589f2618268e3d7b43a5dbb 100644 (file)
@@ -25,6 +25,9 @@
 
 #include <AIS_InteractiveContext.hxx>
 
+class SUIT_ViewWindow;
+class QMouseEvent;
+
 class HYDROGUI_LandCoverMapOp : public HYDROGUI_Operation
 {
   Q_OBJECT
@@ -45,10 +48,16 @@ protected:
 
   virtual HYDROGUI_Shape*        getPreviewShape() const { return myPreviewPrs; };
 
+signals:
+  void                           selectionChanged();
+  void                           deselection();
+
 protected slots:
   void                           onLandCoverMapChanged( const QString& theName );
   void                           onCreatePreview();
   void                           onViewerSelectionChanged();
+  void                           onMousePress(SUIT_ViewWindow*, QMouseEvent*);
+  void                           onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
 
 private:
   void                           closePreview();
@@ -62,6 +71,8 @@ private:
   Handle(HYDROData_LandCoverMap)  myEditedObject;
 
   HYDROGUI_Shape*                 myPreviewPrs;
+
+  QPoint                          myStartPnt, myEndPnt;
 };
 
 #endif
index bc48132d84956280752b5665c13476a6db7d0287..0a58c3f67a972db80bd5d2e2f044f2dfd56c9662 100644 (file)
@@ -88,8 +88,8 @@
       <translation>STRICKLER TABLES</translation>
     </message>
     <message>
-      <source>LAND_COVERS</source>
-      <translation>LAND COVERS</translation>
+      <source>LAND_COVER_MAPS</source>
+      <translation>LAND COVER MAPS</translation>
     </message>
     <message>
       <source>ARTIFICIAL_OBJECTS</source>
@@ -369,10 +369,6 @@ All supported formats (*.brep *.iges *.igs *.step *.stp)</translation>
       <source>RESULTS_ON_GEOMETRY_OBJECTS</source>
       <translation>Results on geometry objects</translation>
     </message>
-    <message>
-      <source>RESULTS_ON_LAND_COVERS</source>
-      <translation>Results on land covers</translation>
-    </message>
     <message>
       <source>REGENERATE_COLORS</source>
       <translation>Regenerate colors</translation>