From: vsv Date: Tue, 6 May 2014 13:49:00 +0000 (+0400) Subject: Provide selection management in a viewer (Salome or GUI) (issue #31) X-Git-Tag: V_0.2~84 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ff4aad301cd1f42683573988f65334f0db074655;p=modules%2Fshaper.git Provide selection management in a viewer (Salome or GUI) (issue #31) --- diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp index c81d706ab..5fe0be383 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.cpp +++ b/src/NewGeom/NewGeom_SalomeViewer.cpp @@ -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(); +} diff --git a/src/NewGeom/NewGeom_SalomeViewer.h b/src/NewGeom/NewGeom_SalomeViewer.h index b84c5bc4a..a665af3b7 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.h +++ b/src/NewGeom/NewGeom_SalomeViewer.h @@ -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; } diff --git a/src/XGUI/XGUI_SalomeViewer.h b/src/XGUI/XGUI_SalomeViewer.h index 059bbd819..a1e5054bd 100644 --- a/src/XGUI/XGUI_SalomeViewer.h +++ b/src/XGUI/XGUI_SalomeViewer.h @@ -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(); diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index 18cc94177..44b64c985 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -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(); +} diff --git a/src/XGUI/XGUI_ViewWindow.h b/src/XGUI/XGUI_ViewWindow.h index 77b966d86..554eee47b 100644 --- a/src/XGUI/XGUI_ViewWindow.h +++ b/src/XGUI/XGUI_ViewWindow.h @@ -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); diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 7e53ec0e7..de3a58374 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -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(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(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(aWnd->widget()); + aView->updateEnabledDrawMode(); + } +} diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 9222827f3..4031430a3 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -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; diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index b39b1ce97..e07c3693e 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -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(); + } +} diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index 17d0bb8c4..2d2864dd4 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -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