]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide selection management in a viewer (Salome or GUI) (issue #31)
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 6 May 2014 13:49:00 +0000 (17:49 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 6 May 2014 13:49:00 +0000 (17:49 +0400)
src/NewGeom/NewGeom_SalomeViewer.cpp
src/NewGeom/NewGeom_SalomeViewer.h
src/XGUI/XGUI_SalomeViewer.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_ViewWindow.h
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h

index c81d706ab769bf52b00f4d2cad4d05f12c0f76e6..5fe0be383819ede7a8b7f2dfe95e8c76778ac3eb 100644 (file)
@@ -12,17 +12,19 @@ NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
 {
 }
 
-
+//**********************************************
 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
 {
   return mySelector->viewer()->getAISContext();
 }
 
+//**********************************************
 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
 {
   return mySelector->viewer()->getViewer3d();
 }
 
+//**********************************************
 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
 {
   OCCViewer_Viewer* aViewer = mySelector->viewer();
@@ -31,6 +33,7 @@ Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
   return aWnd->getViewPort()->getView();
 }
 
+//**********************************************
 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
 {
   if (mySelector) {
@@ -69,33 +72,62 @@ void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
           this, SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
 }
 
-
+//**********************************************
 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
 {
   emit mousePress(theEvent);
 }
 
+//**********************************************
 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
 {
   emit mouseRelease(theEvent);
 }
 
+//**********************************************
 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
 {
   emit mouseDoubleClick(theEvent);
 }
 
+//**********************************************
 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
 {
   emit mouseMove(theEvent);
 }
 
+//**********************************************
 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
 {
   emit keyPress(theEvent);
 }
 
+//**********************************************
 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
 {
   emit keyRelease(theEvent);
 }
+
+//**********************************************
+void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
+{
+  mySelector->viewer()->enableSelection(isEnabled);
+}
+
+//**********************************************
+bool NewGeom_SalomeViewer::isSelectionEnabled() const
+{
+  return mySelector->viewer()->isSelectionEnabled();
+}
+
+//**********************************************
+void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
+{
+  mySelector->viewer()->enableMultiselection(isEnable);
+}
+
+//**********************************************
+bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
+{
+  return mySelector->viewer()->isMultiSelectionEnabled();
+}
index b84c5bc4a5a3e7cde576ef7a9365803ba0cc38a9..a665af3b77298a9767f90d8cac6b125a8cda704d 100644 (file)
@@ -28,6 +28,18 @@ public:
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const;
 
+  //! Enable or disable selection in the viewer
+  virtual void enableSelection(bool isEnabled);
+
+  //! Returns true if selection is enabled
+  virtual bool isSelectionEnabled() const;
+
+  //! Enable or disable multiselection in the viewer
+  virtual void enableMultiselection(bool isEnable);
+
+  //! Returns true if multiselection is enabled
+  virtual bool isMultiSelectionEnabled() const;
+
   void setSelector(NewGeom_OCCSelector* theSel);
 
   NewGeom_OCCSelector* selector() const { return mySelector; }
index 059bbd819975302cd48771e27a067c74effc8627..a1e5054bd81c88a1345e8d37be87cbe2282d2695 100644 (file)
@@ -29,6 +29,18 @@ public:
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const = 0;
 
+  //! Enable or disable selection in the viewer
+  virtual void enableSelection(bool isEnabled) = 0;
+
+  //! Returns true if selection is enabled
+  virtual bool isSelectionEnabled() const = 0;
+
+  //! Enable or disable multiselection in the viewer
+  virtual void enableMultiselection(bool isEnable) = 0;
+
+  //! Returns true if multiselection is enabled
+  virtual bool isMultiSelectionEnabled() const = 0;
+
 signals:
   void lastViewClosed();
   void tryCloseView();
index 18cc941777f8b64faaf6c4956bd05a4031cdf59c..44b64c985d201d65ab8ae591e6401ca298d0df43 100644 (file)
@@ -157,7 +157,7 @@ XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
     myRotationPointSelection(false),
     myClosable(true),
     myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
-    myDrawRect(false), myEnableDrawMode(true), myCursorIsHand(false), myEventStarted(false),
+    myDrawRect(false), myEnableDrawMode(false), myCursorIsHand(false), myEventStarted(false),
     myIsActive(false),
     myLastState(WindowNormalState), myOperation(NOTHING)
 {
@@ -1175,3 +1175,11 @@ void XGUI_ViewWindow::updateToolBar()
   myWindowBar->update();
 }
 
+/*!
+  \brief Update state of enable draw mode state.
+*/
+void XGUI_ViewWindow::updateEnabledDrawMode()
+{
+  myEnableDrawMode = myViewer->isSelectionEnabled() && 
+                     myViewer->isMultiSelectionEnabled();
+}
index 77b966d860a0901ba6eeac2250bab8db8f3c3c03..554eee47b04270156537a074c3ce600742a3369a 100644 (file)
@@ -93,6 +93,9 @@ public:
   //! Returns true if ribbon line drawing enabled
   bool isDrawModeEnabled() const { return myEnableDrawMode; }
 
+  //! Updates drawing mode in the view window
+  void updateEnabledDrawMode();
+
 signals:
   //! Emited whien view transformation operation is started
   void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
index 7e53ec0e7c1ce977601d41855ca103c66ba71353..de3a583746bc0e95608ba2f6df8a5adecbd7aa2a 100644 (file)
@@ -173,14 +173,15 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType)
   //initView( vw );
   // set default background for view window
   //vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
-  //// connect signal from viewport
-    //connect(view->viewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
+  // connect signal from viewport
+  //connect(view->viewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
     //connect(view->viewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
-    if (myViews.size() == 0) 
-        setTrihedronShown(true);
+  if (myViews.size() == 0) 
+    setTrihedronShown(true);
 
-    view->setBackground(XGUI_ViewBackground(XGUI::VerticalGradient, Qt::white, QColor(Qt::blue).lighter()));
+  view->setBackground(XGUI_ViewBackground(XGUI::VerticalGradient, Qt::white, QColor(Qt::blue).lighter()));
   //view->setBackground(XGUI_ViewBackground(Qt::black));
+  view->updateEnabledDrawMode();
 
   QMdiArea* aMDI = myMainWindow->mdiArea();
   QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint);
@@ -374,22 +375,22 @@ bool XGUI_Viewer::computeTrihedronSize(double& theNewSize, double& theSize)
 
 void XGUI_Viewer::onViewClosed(QMdiSubWindow* theView)
 {
-    if ( !theView )
-        return;
-
-    emit deleteView( static_cast<XGUI_ViewWindow*>(theView->widget()) );
-    removeView( theView );
-
-    // if this is last view
-    if (myViews.size() == 0) {
-        Standard_Integer aViewsNb = 0;
-        for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
-            ++aViewsNb;
-        if ( aViewsNb < 2 ) {
-            //clean up presentations before last view is closed
-            myAISContext->RemoveAll(Standard_False);
-        }
+  if ( !theView )
+    return;
+
+  emit deleteView( static_cast<XGUI_ViewWindow*>(theView->widget()) );
+  removeView( theView );
+
+  // if this is last view
+  if (myViews.size() == 0) {
+    Standard_Integer aViewsNb = 0;
+    for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
+      ++aViewsNb;
+    if ( aViewsNb < 2 ) {
+      //clean up presentations before last view is closed
+      myAISContext->RemoveAll(Standard_False);
     }
+  }
 }
 
 /*!Remove view window \a theView from view manager.
@@ -552,3 +553,26 @@ void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEv
   }
   emit selectionChanged();
 }
+
+//******************************************************
+void XGUI_Viewer::setMultiSelectionEnabled(bool toEnable) 
+{ 
+  myMultiSelectionEnabled = toEnable; 
+  updateViewsDrawMode();
+}
+
+//******************************************************
+void XGUI_Viewer::setSelectionEnabled(bool toEnable) 
+{ 
+  mySelectionEnabled = toEnable; 
+  updateViewsDrawMode();
+}
+
+//******************************************************
+void XGUI_Viewer::updateViewsDrawMode() const
+{
+  foreach(QMdiSubWindow* aWnd, myViews){
+    XGUI_ViewWindow* aView = static_cast<XGUI_ViewWindow*>(aWnd->widget());
+    aView->updateEnabledDrawMode();
+  }
+}
index 9222827f36e5374df07e654678215aeb146b4182..4031430a3dc36b11c830143f06bcb918f4a7ccc6 100644 (file)
@@ -79,7 +79,14 @@ public:
 
   /// Enable or disable selectioon in the viewer
   // \param toEnable - true or false (enable or disable selection)
-  void setSelectionEnabled(bool toEnable) { mySelectionEnabled = toEnable; }
+  void setSelectionEnabled(bool toEnable);
+
+  /// Returns true if multi-selection in the viewer is enabled
+  bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
+
+  /// Enable or disable selectioon in the viewer
+  // \param toEnable - true or false (enable or disable selection)
+  void setMultiSelectionEnabled(bool toEnable);
 
   /// Select the object in 3D viewer.
   /// \param theIO - list objects to be selected
@@ -160,6 +167,8 @@ private:
   /*! Removes the View from internal Views list.*/
   void removeView(QMdiSubWindow* theView);
 
+  void updateViewsDrawMode() const;
+
 private:
   XGUI_MainWindow* myMainWindow;
 
index b39b1ce97946f3193ded0fde8140549a393ee512..e07c3693e75ca6e91446ddefc12c7d9d2b16b020 100644 (file)
@@ -143,3 +143,43 @@ void XGUI_ViewerProxy::onKeyRelease(XGUI_ViewWindow*, QKeyEvent* theEvent)
 {
   emit keyRelease(theEvent);
 }
+
+//***************************************
+void XGUI_ViewerProxy::enableSelection(bool isEnabled)
+{
+  if (myWorkshop->isSalomeMode()) {
+    myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
+  } else {
+    myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
+  }
+}
+
+//***************************************
+bool XGUI_ViewerProxy::isSelectionEnabled() const
+{
+  if (myWorkshop->isSalomeMode()) {
+    return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
+  } else {
+    return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
+  }
+}
+
+//***************************************
+void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
+{
+  if (myWorkshop->isSalomeMode()) {
+    myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
+  } else {
+    myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
+  }
+}
+
+//***************************************
+bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
+{
+  if (myWorkshop->isSalomeMode()) {
+    return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
+  } else {
+    return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
+  }
+}
index 17d0bb8c4cd2cd8a85a31982e16dadb870f31880..2d2864dd4f9a7cafd85d8687f25eca655852a23c 100644 (file)
@@ -28,6 +28,18 @@ public:
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const;
 
+  //! Enable or disable selection in the viewer
+  virtual void enableSelection(bool isEnabled);
+
+  //! Returns true if selection is enabled
+  virtual bool isSelectionEnabled() const;
+
+  //! Enable or disable multiselection in the viewer
+  virtual void enableMultiselection(bool isEnable);
+
+  //! Returns true if multiselection is enabled
+  virtual bool isMultiSelectionEnabled() const;
+
   //! Sets the view projection
   /// \param theX the X projection value
   /// \param theY the Y projection value