From: nds Date: Thu, 17 Dec 2015 11:39:23 +0000 (+0300) Subject: #1136 - hidden axis are selected in sketch X-Git-Tag: V_2.1.0~163 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed4a3feb663344c4a785133c5f025a2687192c6d;p=modules%2Fshaper.git #1136 - hidden axis are selected in sketch --- diff --git a/src/ModuleBase/ModuleBase_IViewer.h b/src/ModuleBase/ModuleBase_IViewer.h index 4dce665ce..30c233969 100644 --- a/src/ModuleBase/ModuleBase_IViewer.h +++ b/src/ModuleBase/ModuleBase_IViewer.h @@ -8,6 +8,7 @@ #include #include #include +#include class QMouseEvent; class QKeyEvent; @@ -30,6 +31,9 @@ Q_OBJECT //! Returns AIS_InteractiveContext from current OCCViewer virtual Handle(AIS_InteractiveContext) AISContext() const = 0; + //! Trihedron 3d object shown in the viewer + virtual Handle(AIS_Trihedron) trihedron() const = 0; + //! Retrurns V3d_Vioewer from current viewer virtual Handle(V3d_Viewer) v3dViewer() const = 0; @@ -149,6 +153,9 @@ signals: /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType) void viewTransformed(int theTransformation); + /// Signal emited on selection changed + void trihedronVisibilityChanged(bool theState); + protected: /// A map for storing a scale factors dependent on view object QMap myWindowScale; diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp index ac0b1c3b0..f116db233 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.cpp +++ b/src/NewGeom/NewGeom_SalomeViewer.cpp @@ -8,6 +8,8 @@ #include +#include + #include #include @@ -76,6 +78,12 @@ Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const return Handle(V3d_Viewer)(); } +//********************************************** +Handle(AIS_Trihedron) NewGeom_SalomeViewer::trihedron() const +{ + return mySelector->viewer()->getTrihedron(); +} + //********************************************** Handle(V3d_View) NewGeom_SalomeViewer::activeView() const { @@ -237,13 +245,20 @@ void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView) OCCViewer_ViewFrame* aView = dynamic_cast(theView); OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW); - if (aWnd) + if (aWnd) { connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); + OCCViewer_ViewPort3d* aViewPort = aWnd->getViewPort(); + if (aViewPort) + connect(aViewPort, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewPortMapped())); + } + reconnectActions(aWnd, true); myWindowScale.insert (aView->getViewPort()->getView(), aView->getViewPort()->getView()->Camera()->Scale()); emit viewCreated(myView); + + } //********************************************** @@ -297,6 +312,32 @@ bool NewGeom_SalomeViewer::enableDrawMode(bool isEnabled) return false; } +//********************************************** +void NewGeom_SalomeViewer::reconnectActions(SUIT_ViewWindow* theWindow, + const bool theUseNewGeomSlot) +{ + OCCViewer_ViewWindow* aWindow = dynamic_cast(theWindow); + if (!aWindow) + return; + + QAction* anAction = theWindow->toolMgr()->action(OCCViewer_ViewWindow::TrihedronShowId); + if (!anAction) + return; + + if (theUseNewGeomSlot) { + anAction->disconnect(anAction, SIGNAL(toggled(bool)), + theWindow, SLOT(onTrihedronShow(bool))); + anAction->connect(anAction, SIGNAL(toggled(bool)), + this, SIGNAL(trihedronVisibilityChanged(bool))); + } + else { + anAction->connect(anAction, SIGNAL(toggled(bool)), + theWindow, SLOT(onTrihedronShow(bool))); + anAction->disconnect(anAction, SIGNAL(toggled(bool)), + this, SIGNAL(trihedronVisibilityChanged(bool))); + } +} + //********************************************** void NewGeom_SalomeViewer::fitAll() { @@ -387,6 +428,12 @@ void NewGeom_SalomeViewer::onViewTransformed(OCCViewer_ViewWindow::OperationType emit viewTransformed((int) theType); } +//*************************************** +void NewGeom_SalomeViewer::onViewPortMapped() +{ + emit trihedronVisibilityChanged(true); +} + //*************************************** void NewGeom_SalomeViewer::activateViewer(bool toActivate) { @@ -400,6 +447,7 @@ void NewGeom_SalomeViewer::activateViewer(bool toActivate) OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW); connect(aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); + reconnectActions(aWnd, true); } } else { foreach (SUIT_ViewWindow* aView, aViews) { @@ -407,6 +455,7 @@ void NewGeom_SalomeViewer::activateViewer(bool toActivate) OCCViewer_ViewWindow* aWnd = aOCCView->getView(OCCViewer_ViewFrame::MAIN_VIEW); disconnect((OCCViewer_ViewWindow*)aWnd, SIGNAL(vpTransformationFinished(OCCViewer_ViewWindow::OperationType)), this, SLOT(onViewTransformed(OCCViewer_ViewWindow::OperationType))); + reconnectActions(aWnd, false); } } } diff --git a/src/NewGeom/NewGeom_SalomeViewer.h b/src/NewGeom/NewGeom_SalomeViewer.h index a9e9d19e2..e32cfbbdf 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.h +++ b/src/NewGeom/NewGeom_SalomeViewer.h @@ -12,6 +12,7 @@ #include #include +#include class SUIT_ViewWindow; class QMouseEvent; @@ -76,6 +77,9 @@ Q_OBJECT //! Retrurns V3d_Vioewer from current viewer virtual Handle(V3d_Viewer) v3dViewer() const; + //! Trihedron 3d object shown in the viewer + virtual Handle(AIS_Trihedron) trihedron() const; + //! Returns Vsd_View object from currently active view window virtual Handle(V3d_View) activeView() const; @@ -97,6 +101,9 @@ Q_OBJECT //! Enable or disable draw mode in the viewer virtual bool enableDrawMode(bool isEnabled); + //! For some signals it disconnects the window from usual signal and connect it to the module ones + void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseNewGeomSlot); + //! Perfroms the fit all for the active view virtual void fitAll(); @@ -161,6 +168,10 @@ Q_OBJECT void onSelectionChanged(); void onViewTransformed(OCCViewer_ViewWindow::OperationType); + /// Emit signal about trihedron visiblity change because SALOME sets the trihedron visible by this signal. + /// It is necessary to activate the viewer trihedron in the current selection mode + void onViewPortMapped(); + private: NewGeom_OCCSelector* mySelector; NewGeom_SalomeView* myView; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 4fb6a729b..2c24b774a 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -38,6 +38,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -457,7 +460,7 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL Handle(AIS_InteractiveObject) aTrihedron; if (isTrihedronActive()) { aTrihedron = getTrihedron(); - if (!aTrihedron.IsNull()) + if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) aPrsList.Append(aTrihedron); } if (aPrsList.Extent() == 0) @@ -574,42 +577,47 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) return aErased; } -#define DEACTVATE_COMP(TheComp) \ - if (!TheComp.IsNull()) \ - aContext->Deactivate(TheComp); +void deactivateObject(Handle(AIS_InteractiveContext) theContext, + Handle(AIS_InteractiveObject) theObject, + const bool theClear = true) +{ + if (!theObject.IsNull()) { + theContext->Deactivate(theObject); + //if (theClear) { + //theObject->ClearSelected(); + // theContext->LocalContext()->ClearOutdatedSelection(theObject, true); + //} + } +} -void XGUI_Displayer::deactivateTrihedron() const +void XGUI_Displayer::deactivateTrihedron(const bool theUpdateViewer) const { Handle(AIS_InteractiveObject) aTrihedron = getTrihedron(); - if (!aTrihedron.IsNull()) { + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (!aTrihedron.IsNull() && aContext->IsDisplayed(aTrihedron)) { Handle(AIS_Trihedron) aTrie = Handle(AIS_Trihedron)::DownCast(aTrihedron); - Handle(AIS_InteractiveContext) aContext = AISContext(); - aContext->Deactivate(aTrie); - DEACTVATE_COMP(aTrie->XAxis()); - DEACTVATE_COMP(aTrie->YAxis()); - DEACTVATE_COMP(aTrie->Axis()); - DEACTVATE_COMP(aTrie->Position()); - DEACTVATE_COMP(aTrie->XYPlane()); - DEACTVATE_COMP(aTrie->XZPlane()); - DEACTVATE_COMP(aTrie->YZPlane()); + deactivateObject(aContext, aTrie); + + /// #1136 hidden axis are selected in sketch + /// workaround for Cascade: there is a crash in AIS_LocalContext::ClearOutdatedSelection + /// for Position AIS object in SelectionModes. + deactivateObject(aContext, aTrie->XAxis()); + deactivateObject(aContext, aTrie->YAxis()); + deactivateObject(aContext, aTrie->Axis()); + deactivateObject(aContext, aTrie->Position()); + + deactivateObject(aContext, aTrie->XYPlane()); + deactivateObject(aContext, aTrie->XZPlane()); + deactivateObject(aContext, aTrie->YZPlane()); + + if (theUpdateViewer) + updateViewer(); } } Handle(AIS_InteractiveObject) XGUI_Displayer::getTrihedron() const { - Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull()) { - AIS_ListOfInteractive aList; - aContext->DisplayedObjects(aList, true); - AIS_ListIteratorOfListOfInteractive aIt; - for (aIt.Initialize(aList); aIt.More(); aIt.Next()) { - Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value()); - if (!aTrihedron.IsNull()) { - return aTrihedron; - } - } - } - return Handle(AIS_InteractiveObject)(); + return myWorkshop->viewer()->trihedron(); } void XGUI_Displayer::openLocalContext() @@ -795,7 +803,7 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const if (!aContext.IsNull() && !aContext->HasOpenedContext()) { aContext->OpenLocalContext(); if (!isTrihedronActive()) - deactivateTrihedron(); + deactivateTrihedron(true); aContext->DefaultDrawer()->VIsoAspect()->SetNumber(0); aContext->DefaultDrawer()->UIsoAspect()->SetNumber(0); } @@ -1141,6 +1149,38 @@ void XGUI_Displayer::activateTrihedron(bool theIsActive) { myIsTrihedronActive = theIsActive; if (!myIsTrihedronActive) { - deactivateTrihedron(); + deactivateTrihedron(true); } } + +void XGUI_Displayer::displayTrihedron(bool theToDisplay) const +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + + Handle(AIS_Trihedron) aTrihedron = myWorkshop->viewer()->trihedron(); + + if (theToDisplay) { + if (!aContext->IsDisplayed(aTrihedron)) + aContext->Display(aTrihedron, + 0 /*wireframe*/, + -1 /* selection mode */, + Standard_True /* update viewer*/, + Standard_False /* allow decomposition */, + AIS_DS_Displayed /* xdisplay status */); + + if (!isTrihedronActive()) + deactivateTrihedron(false); + else + activate(aTrihedron, myActiveSelectionModes, false); + } else { + deactivateTrihedron(false); + //aContext->LocalContext()->ClearOutdatedSelection(aTrihedron, true); + // the selection from the previous activation modes should be cleared manually (#26172) + + aContext->Erase(aTrihedron); + } + + updateViewer(); +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 78da19457..5ad16e6bc 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -231,9 +231,14 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Returns Trihedron object if it is displayed Handle(AIS_InteractiveObject) getTrihedron() const; - // Set trihedron active (used in selection) or non active + /// Set trihedron active (used in selection) or non active void activateTrihedron(bool theIsActive); + /// Displays/erases thrihedron in current modes. It will be activated or deactivated + /// depending on the trihedron visible state and displayer active trihedron state + void displayTrihedron(bool theToDisplay) const; + + /// Returns true if the trihedron should be activated in current selection modes bool isTrihedronActive() const { return myIsTrihedronActive; } /// Converts shape type (TopAbs_ShapeEnum) to selection mode @@ -281,7 +286,8 @@ private: void deactivate(ObjectPtr theObject, const bool theUpdateViewer); /// Find a trihedron in a list of displayed presentations and deactivate it. - void deactivateTrihedron() const; + /// \param theUpdateViewer an update viewer flag + void deactivateTrihedron(const bool theUpdateViewer) const; /// Opens local context. Does nothing if it is already opened. void openLocalContext(); diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index caeaff5aa..d0b6779e8 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -22,6 +22,17 @@ XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent) { } +void XGUI_ViewerProxy::connectViewProxy() +{ +#ifdef HAVE_SALOME + connect(myWorkshop->salomeConnector()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)), + SIGNAL(trihedronVisibilityChanged(bool))); +#else + connect(myWorkshop->mainWindow()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)), + SLOT(trihedronVisibilityChanged(bool))); +#endif +} + Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const { #ifdef HAVE_SALOME @@ -31,6 +42,15 @@ Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const #endif } +Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const +{ +#ifdef HAVE_SALOME + return myWorkshop->salomeConnector()->viewer()->trihedron(); +#else + return myWorkshop->mainWindow()->viewer()->trihedron(); +#endif +} + Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const { #ifdef HAVE_SALOME diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index bce1db650..1e13f70cd 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -6,6 +6,8 @@ #include "XGUI.h" #include +#include + #ifndef HAVE_SALOME #include #endif @@ -26,9 +28,15 @@ Q_OBJECT /// \param theParent a parent object XGUI_ViewerProxy(XGUI_Workshop* theParent); + /// Connects some signals to the viewer from the module connector + void connectViewProxy(); + //! Returns AIS_InteractiveContext from current OCCViewer virtual Handle(AIS_InteractiveContext) AISContext() const; + //! Trihedron 3d object shown in the viewer + virtual Handle(AIS_Trihedron) trihedron() const; + //! Retrurns V3d_Vioewer from current viewer virtual Handle(V3d_Viewer) v3dViewer() const; @@ -96,6 +104,9 @@ signals: /// Emits by mouse leaving of the view port void leaveViewPort(); + /// Signal emited on selection changed + void trihedronVisibilityChanged(bool theState); + protected: /// processes the application signals to catch the mouse leaving state of the main window /// \param theObject diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 5f7303a78..948f258fa 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -216,6 +216,10 @@ void XGUI_Workshop::startApplication() onNew(); + myViewerProxy->connectViewProxy(); + connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)), + SLOT(onTrihedronVisibilityChanged(bool))); + emit applicationStarted(); } @@ -731,6 +735,14 @@ void XGUI_Workshop::onPreferences() } #endif +//****************************************************** +void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState) +{ + XGUI_Displayer* aDisplayer = displayer(); + if (aDisplayer) + aDisplayer->displayTrihedron(theState); +} + //****************************************************** bool XGUI_Workshop::onSave() { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index c032b9324..9f02d4462 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -337,6 +337,9 @@ signals: void onPreferences(); #endif + /// Activates/deactivates the trihedron in the viewer AIS context + void onTrihedronVisibilityChanged(bool theState); + protected: /// Sets the granted operations for the parameter operation. Firstly, it finds the nested features /// and set them into the operation. Secondly, it asks the module about ids of granted operations.