From 834c7f08a1f839bc1cf11d5c206a9d44298bf508 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 17 Feb 2016 15:45:38 +0300 Subject: [PATCH] SketchPoint feature appeared in origin by restart. Correction: the viewer update is blocked until mouse release position is set. Recursive state is implemented because ModuleBase_ModelWidget::updateObject(called from Point2d::activated()) block/unblock displayer. --- src/ModuleBase/ModuleBase_ModelWidget.h | 8 ++-- src/PartSet/PartSet_SketcherReetntrantMgr.cpp | 10 +++++ src/XGUI/XGUI_Displayer.cpp | 37 +++++++++++++------ src/XGUI/XGUI_Displayer.h | 12 +++--- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 8d6b0be3b..a9f6530b9 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -197,6 +197,10 @@ Q_OBJECT /// \param theObj is object for moving static void moveObject(ObjectPtr theObj); + /// Sends a message about block/unblock viewer updating + /// \param theValue a boolean value + static void blockUpdateViewer(const bool theValue); + signals: /// The signal about widget values are to be changed void beforeValuesChanged(); @@ -276,10 +280,6 @@ protected: /// The method called when widget is activated virtual void activateCustom() {}; - /// Sends a message about block/unblock viewer updating - /// \param theValue a boolean value - static void blockUpdateViewer(const bool theValue); - protected slots: /// Processing of values changed in model widget by store the current value to the feature void onWidgetValuesChanged(); diff --git a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp index ae06c60e4..e063f05da 100755 --- a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp @@ -178,6 +178,14 @@ bool PartSet_SketcherReetntrantMgr::processMouseReleased(ModuleBase_IViewWindow* ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); if (!anActiveWidget || !anActiveWidget->isViewerSelector()) { + + // block of viewer update + // we need to block update content of the viewer because of Sketch Point feature + // in activate() the value of the point is initialized and it can be displayed + // but the default value is [0, 0]. So, we block update viewer contentent until + // onMouseRelease happens, which correct the point position + ModuleBase_ModelWidget::blockUpdateViewer(true); + restartOperation(); aProcessed = true; @@ -189,6 +197,8 @@ bool PartSet_SketcherReetntrantMgr::processMouseReleased(ModuleBase_IViewWindow* if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) { aPoint2DWdg->onMouseRelease(theWnd, theEvent); } + // unblock viewer update + ModuleBase_ModelWidget::blockUpdateViewer(false); } } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 3899d5e37..dd84ebdb7 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -103,10 +103,9 @@ QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QS } XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) - : myWorkshop(theWorkshop), myEnableUpdateViewer(true), myNeedUpdate(false), - myIsTrihedronActive(false) + : myWorkshop(theWorkshop), myNeedUpdate(false), + myIsTrihedronActive(false), myViewerBlockedRecursiveCount(0) { - enableUpdateViewer(true); myCustomPrs = std::shared_ptr(new XGUI_CustomPrs(theWorkshop)); } @@ -253,7 +252,7 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer) Handle(AIS_InteractiveObject) anAIS = anObject->impl(); if (!anAIS.IsNull()) { emit beforeObjectErase(theObject, anObject); - aContext->Remove(anAIS, theUpdateViewer); + aContext->Remove(anAIS); aErased = true; } } @@ -265,6 +264,10 @@ bool XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer) qDebug(QString("erase object: %1").arg(aPtrStr.str().c_str()).toStdString().c_str()); qDebug(getResult2AISObjectMapInfo().c_str()); #endif + + if (theUpdateViewer) + updateViewer(); + return aErased; } @@ -744,20 +747,28 @@ ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled) { - bool aWasEnabled = myEnableUpdateViewer; + bool aWasEnabled = isUpdateEnabled(); + if (isEnabled) + myViewerBlockedRecursiveCount--; + else + myViewerBlockedRecursiveCount++; - myEnableUpdateViewer = isEnabled; - if (myNeedUpdate && myEnableUpdateViewer) { + if (myNeedUpdate && isUpdateEnabled()) { updateViewer(); myNeedUpdate = false; } return aWasEnabled; } +bool XGUI_Displayer::isUpdateEnabled() const +{ + return myViewerBlockedRecursiveCount == 0; +} + void XGUI_Displayer::updateViewer() const { Handle(AIS_InteractiveContext) aContext = AISContext(); - if (!aContext.IsNull() && myEnableUpdateViewer) { + if (!aContext.IsNull() && isUpdateEnabled()) { myWorkshop->viewer()->Zfitall(); aContext->UpdateCurrentViewer(); } else { @@ -770,13 +781,15 @@ void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO, { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (!aContext.IsNull()) { - aContext->Activate(theIO, theMode, theUpdateViewer); + aContext->Activate(theIO, theMode, false); #ifdef DEBUG_ACTIVATE_AIS ObjectPtr anObject = getObject(theIO); anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str()); #endif + if (theUpdateViewer) + updateViewer(); } } @@ -827,7 +840,7 @@ bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSele Handle(AIS_InteractiveContext) aContext = AISContext(); Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); if (!aContext.IsNull() && !anAISIO.IsNull()) { - aContext->Display(anAISIO, 0/*wireframe*/, 0, theUpdateViewer, true, AIS_DS_Displayed); + aContext->Display(anAISIO, 0/*wireframe*/, 0, false/*update viewer*/, true, AIS_DS_Displayed); aDisplayed = true; aContext->Deactivate(anAISIO); aContext->Load(anAISIO); @@ -842,6 +855,8 @@ bool XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSele } } } + if (theUpdateViewer) + updateViewer(); } return aDisplayed; } @@ -853,7 +868,7 @@ bool XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer) if (!aContext.IsNull()) { Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) { - aContext->Remove(anAISIO, theUpdateViewer); + aContext->Remove(anAISIO, false/*update viewer*/); aErased = true; } } diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 5ad16e6bc..5a325fc8c 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -137,12 +137,14 @@ class XGUI_EXPORT XGUI_Displayer: public QObject void removeFilters(); /// Sets a flag to the displayer whether the internal viewer can be updated by - /// the updateViewer method call. If it is not enabled, this method do nothing + /// the updateViewer method call. If it is not enabled, this method do nothing. + /// This state maintain recurse, if the update is blocked twice or three times, the + /// viewer will not be updated until it is unblocked necessary times(twice or three in the example). /// \param isEnabled a boolean value bool enableUpdateViewer(const bool isEnabled); - /// Returns myEnableUpdateViewer flag - bool isUpdateEnabled() const { return myEnableUpdateViewer; } + /// Returns true if the viewer update is not blocked + bool isUpdateEnabled() const; /// Updates the viewer void updateViewer() const; @@ -327,8 +329,8 @@ private: /// Selection modes installed for external objects in local context QIntList myActiveSelectionModes; - /// the enable update viewer flag - bool myEnableUpdateViewer; + /// Number of blocking of the viewer update. The viewer is updated only if it equals zero + int myViewerBlockedRecursiveCount; // Flag: use trihedgon for selection or not bool myIsTrihedronActive; -- 2.39.2