From 5b679606e1f5aa81b438efe5f00cead3bfa85859 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 22 Sep 2015 11:12:45 +0300 Subject: [PATCH] Optimization of Viewer performance up to two times --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 4 +-- src/NewGeom/NewGeom_SalomeViewer.cpp | 9 ++++--- src/PartSet/PartSet_Module.cpp | 11 +++++---- src/PartSet/PartSet_WidgetSketchLabel.cpp | 4 +-- src/XGUI/XGUI_Displayer.cpp | 30 +++++++++++++++-------- src/XGUI/XGUI_Displayer.h | 3 ++- src/XGUI/XGUI_ViewerProxy.cpp | 9 ++++--- src/XGUI/XGUI_WorkshopListener.cpp | 12 ++++++--- 8 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 80aabe71f..75d99535b 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -159,13 +159,13 @@ void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) { - blockUpdateViewer(true); + //blockUpdateViewer(true); static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); Events_Loop::loop()->flush(anEvent); - blockUpdateViewer(false); + //blockUpdateViewer(false); } bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) diff --git a/src/NewGeom/NewGeom_SalomeViewer.cpp b/src/NewGeom/NewGeom_SalomeViewer.cpp index 0494aeec9..636abd69f 100644 --- a/src/NewGeom/NewGeom_SalomeViewer.cpp +++ b/src/NewGeom/NewGeom_SalomeViewer.cpp @@ -301,7 +301,8 @@ void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double th aView3d->SetTwist( theTwist ); aView3d->FitAll(0.01, true); aView3d->SetZSize(0.); - aView3d->DepthFitAll(); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); } } } @@ -395,7 +396,9 @@ void NewGeom_SalomeViewer::Zfitall() OCCViewer_ViewFrame* aView = dynamic_cast(aMgr->getActiveView()); if (aView) { OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW); - aWnd->getViewPort()->getView()->ZFitAll(); - aWnd->getViewPort()->getView()->DepthFitAll(); + Handle(V3d_View) aView3d = aWnd->getViewPort()->getView(); + aView3d->ZFitAll(); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); } } \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 67f1bcf7a..00ba380b2 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -323,11 +323,12 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) mySketchMgr->stopNestedSketch(theOperation); } - if (isModified) { - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); - aDisplayer->updateViewer(); - } + //VSV: Viewer is updated on feature update and redisplay + //if (isModified) { + // XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + // XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + // aDisplayer->updateViewer(); + //} mySketchMgr->onShowConstraintsToggle(myHasConstraintShown); } diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index e4df553d7..e28724ddc 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -181,7 +181,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs // 6. Update sketcher actions XGUI_ActionsMgr* anActMgr = workshop()->actionsMgr(); anActMgr->update(); - myWorkshop->viewer()->update(); + //VSV myWorkshop->viewer()->update(); } std::shared_ptr PartSet_WidgetSketchLabel::plane() const @@ -289,7 +289,7 @@ void PartSet_WidgetSketchLabel::activateCustom() connect(workshop()->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); activateFilters(true); - aDisp->updateViewer(); + //VSV aDisp->updateViewer(); } void PartSet_WidgetSketchLabel::deactivate() diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 7f5932011..b41682090 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -363,8 +363,9 @@ void XGUI_Displayer::deactivateObjects(const QObjectPtrList& theObjList, for (; anIt != aLast; anIt++) { deactivate(*anIt, false); } - if (theUpdateViewer) - updateViewer(); + //VSV It seems that there is no necessity to update viewer on deactivation + //if (theUpdateViewer) + // updateViewer(); } void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes) @@ -439,12 +440,15 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL } AIS_ListIteratorOfListOfInteractive aLIt(aPrsList); + bool isActivationChanged = false; for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ anAISIO = aLIt.Value(); - activate(anAISIO, myActiveSelectionModes, false); + if (activate(anAISIO, myActiveSelectionModes, false)) + isActivationChanged = true; } - if (theUpdateViewer) - updateViewer(); + // VSV It seems that there is no necessity to update viewer on activation + //if (theUpdateViewer && isActivationChanged) + // updateViewer(); } bool XGUI_Displayer::isActive(ObjectPtr theObject) const @@ -691,6 +695,7 @@ bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled) void XGUI_Displayer::updateViewer() const { + static int ai = 0; Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull() && myEnableUpdateViewer) { myWorkshop->viewer()->Zfitall(); @@ -940,14 +945,15 @@ bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const return ::canBeShaded(anAIS); } -void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, +bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes, const bool theUpdateViewer) const { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull() || theIO.IsNull()) - return; - + return false; + + bool isActivationChanged = false; // deactivate object in all modes, which are not in the list of activation // It seems that after the IO deactivation the selected state of the IO's owners // is modified in OCC(version: 6.8.0) and the selection of the object later is lost. @@ -976,8 +982,10 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, // the selection from the previous activation modes should be cleared manually (#26172) theIO->ClearSelected(); aContext->LocalContext()->ClearOutdatedSelection(theIO, true); - if (theUpdateViewer) - updateViewer(); + // For performance issues + //if (theUpdateViewer) + // updateViewer(); + isActivationChanged = true; } // loading the interactive object allowing the decomposition @@ -999,10 +1007,12 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, //aContext->Load(anAISIO, aMode, true); if (!aModesActivatedForIO.contains(aMode)) { activateAIS(theIO, aMode, theUpdateViewer); + isActivationChanged = true; } } } } + return isActivationChanged; } bool XGUI_Displayer::customizeObject(ObjectPtr theObject) diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 9e853afb0..c4ac99b1c 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -253,7 +253,8 @@ private: /// Activates the interactive object in the local context. /// \param theIO an interactive object /// \param theModes - modes on which it has to be activated (can be empty) - void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes, + /// \return a flag is object activated or not + bool activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes, const bool theUpdateViewer) const; /// Deactivates the given object (not allow selection) diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index b18cff14a..293b9c063 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -55,7 +55,8 @@ void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, aView3d->SetTwist( theTwist ); aView3d->FitAll(0.01, true); aView3d->SetZSize(0.); - aView3d->DepthFitAll(); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); } } @@ -331,8 +332,10 @@ void XGUI_ViewerProxy::Zfitall() AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); AppElements_ViewWindow* aView = aViewer->activeViewWindow(); if (aView) { - aView->v3dView()->ZFitAll(); - aView->v3dView()->DepthFitAll(); + Handle(V3d_View) aView3d = aView->v3dView(); + aView3d->ZFitAll(); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); } } } \ No newline at end of file diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index ee65e8a09..434b6cdd8 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -357,10 +357,12 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptrviewer()->fitAll(); - customizeCurrentObject(); - aDisplayer->updateViewer(); + else + aDisplayer->updateViewer(); } } //****************************************************** @@ -415,10 +417,12 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptrprocessEvent(theMsg); if (aDisplayed) { + customizeCurrentObject(); + //VSV FitAll updated viewer by it self if (aFirstVisualizedBody) myWorkshop->viewer()->fitAll(); - customizeCurrentObject(); - workshop()->displayer()->updateViewer(); + else + workshop()->displayer()->updateViewer(); } //if (aHasPart) { // TODO: Avoid activate last part on loading of document // activateLastPart(); -- 2.39.2