From 4358e3861aab84afe4907e6e2dd30235fdab3588 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 20 Aug 2018 16:26:53 +0300 Subject: [PATCH] Optimization of presentations using definition --- src/PartSet/PartSet_Module.cpp | 6 +++++ src/XGUI/XGUI_Displayer.cpp | 42 ++++++++++++++++++++++++++++++-- src/XGUI/XGUI_Displayer.h | 44 ++++++++++++++++++++++++---------- 3 files changed, 78 insertions(+), 14 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 99342671c..544d4b5c5 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1150,8 +1150,14 @@ void PartSet_Module::onViewTransformed(int theTrsfType) SketcherPrs_Tools::setArrowSize(aLen); const double aCurScale = aViewer->activeView()->Camera()->Scale(); aViewer->SetScale(aViewer->activeView(), aCurScale); +#ifdef OPTIMIZE_PRS QList aPrsList = aDisplayer->displayedPresentations(); foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) { +#else + QList aPrsList = aDisplayer->displayedPresentations(); + foreach(AISObjectPtr aAIS, aPrsList) { + Handle(AIS_InteractiveObject) aAisObj = aAIS->impl(); +#endif Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj); if (!aDim.IsNull()) { aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 364153dca..3ff7886e0 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -556,8 +556,13 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) bool aErased = false; Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull()) { - foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) { +#ifdef OPTIMIZE_PRS + foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) { AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj); +#else + foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) { + AISObjectPtr aAISObj = myResult2AISObjectMap[aObj]; +#endif // erase an object Handle(AIS_InteractiveObject) anIO = aAISObj->impl(); if (!anIO.IsNull()) { @@ -584,7 +589,14 @@ bool XGUI_Displayer::eraseAll(const bool theUpdateViewer) //************************************************************** AISObjectPtr XGUI_Displayer::getAISObject(ObjectPtr theObject) const { +#ifdef OPTIMIZE_PRS return myResult2AISObjectMap.value(theObject); +#else + AISObjectPtr anIO; + if (myResult2AISObjectMap.contains(theObject)) + anIO = myResult2AISObjectMap[theObject]; + return anIO; +#endif } //************************************************************** @@ -597,7 +609,20 @@ ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const //************************************************************** ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const { +#ifdef OPTIMIZE_PRS ObjectPtr anObject = myResult2AISObjectMap.value(theIO); +#else + ObjectPtr anObject; + ResultToAISMap::const_iterator aMapIter = myResult2AISObjectMap.cbegin(); + for (; aMapIter != myResult2AISObjectMap.cend(); aMapIter++) { + const AISObjectPtr& aAIS = aMapIter.value(); + Handle(AIS_InteractiveObject) anAIS = aAIS->impl(); + if (anAIS == theIO) + anObject = aMapIter.key(); + if (anObject.get()) + break; + } +#endif if (!anObject.get()) { std::shared_ptr anAISObj = AISObjectPtr(new GeomAPI_AISObject()); if (!theIO.IsNull()) { @@ -860,7 +885,11 @@ void XGUI_Displayer::removeFilters() //************************************************************** void XGUI_Displayer::showOnly(const QObjectPtrList& theList) { +#ifdef OPTIMIZE_PRS QObjectPtrList aDispList = myResult2AISObjectMap.objects(); +#else + QObjectPtrList aDispList = myResult2AISObjectMap.keys(); +#endif foreach(ObjectPtr aObj, aDispList) { if (!theList.contains(aObj)) erase(aObj, false); @@ -939,7 +968,11 @@ QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, //************************************************************** void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS) { +#ifdef OPTIMIZE_PRS myResult2AISObjectMap.add(theObject, theAIS); +#else + myResult2AISObjectMap[theObject] = theAIS; +#endif #ifdef DEBUG_DISPLAY std::ostringstream aPtrStr; @@ -954,8 +987,13 @@ void XGUI_Displayer::appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS std::string XGUI_Displayer::getResult2AISObjectMapInfo() const { QStringList aContent; - foreach (ObjectPtr aObj, myResult2AISObjectMap.objects()) { +#ifdef OPTIMIZE_PRS + foreach(ObjectPtr aObj, myResult2AISObjectMap.objects()) { AISObjectPtr aAISObj = myResult2AISObjectMap.value(aObj); +#else + foreach(ObjectPtr aObj, myResult2AISObjectMap.keys()) { + AISObjectPtr aAISObj = myResult2AISObjectMap[aObj]; +#endif std::ostringstream aPtrStr; aPtrStr << "aObj = " << aObj.get() << ":"; aPtrStr << "anAIS = " << aAISObj.get() << ":"; diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 5da345d70..5989035e7 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -53,6 +53,7 @@ class VInspectorAPI_CallBack; #endif +#ifdef OPTIMIZE_PRS class XGUI_TwoSidePresentationMap { public: @@ -160,22 +161,23 @@ private: QMap myResultToAISMap; QMap myAIStoResultMap; }; +#endif /**\class XGUI_Displayer * \ingroup GUI * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer */ -class XGUI_EXPORT XGUI_Displayer: public QObject +class XGUI_EXPORT XGUI_Displayer : public QObject { Q_OBJECT - public: - /// \enum DisplayMode display mode - enum DisplayMode { - NoMode = -1, ///< Mode is not defined - Wireframe, ///< Wireframe display mode - Shading ///< Shading display mode - }; +public: + /// \enum DisplayMode display mode + enum DisplayMode { + NoMode = -1, ///< Mode is not defined + Wireframe, ///< Wireframe display mode + Shading ///< Shading display mode + }; /// Constructor /// \param theWorkshop a workshop instance @@ -205,7 +207,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly /// \return true if the object visibility state is changed bool displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes, - const Standard_Integer theDisplayMode = 0, bool theUpdateViewer = true); + const Standard_Integer theDisplayMode = 0, bool theUpdateViewer = true); /// Redisplay the shape if it was displayed /// \param theObject an object instance @@ -222,7 +224,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// \param theValues a list of presentation to be selected /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly void setSelected(const QList>& theValues, - bool theUpdateViewer = true); + bool theUpdateViewer = true); /// Unselect all objects /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly @@ -298,7 +300,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// \param theObjList - list of objects which has to be deactivated. /// \param theUpdateViewer update viewer flag void deactivateObjects(const QObjectPtrList& theObjList, - const bool theUpdateViewer = true); + const bool theUpdateViewer = true); /// Sets display mode for the given object if this object is displayed void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true); @@ -316,13 +318,26 @@ class XGUI_EXPORT XGUI_Displayer: public QObject int objectsCount() const { return myResult2AISObjectMap.size(); } /// Returns list of displayed objects - QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.objects(); } + QObjectPtrList displayedObjects() const { +#ifdef OPTIMIZE_PRS + return myResult2AISObjectMap.objects(); +#else + return myResult2AISObjectMap.keys(); +#endif + } /// Returns list of displayed objects +#ifdef OPTIMIZE_PRS QList displayedPresentations() const { return myResult2AISObjectMap.presentations(); } +#else + QList displayedPresentations() const + { + return myResult2AISObjectMap.values(); + } +#endif /// Returns true if the given object can be shown in shaded mode /// \param theObject object to check @@ -439,7 +454,12 @@ protected: GeomCustomPrsPtr myCustomPrs; /// Definition of a type of map which defines correspondance between objects and presentations +#ifdef OPTIMIZE_PRS XGUI_TwoSidePresentationMap myResult2AISObjectMap; ///< A map of displayed objects +#else + typedef QMap ResultToAISMap; + ResultToAISMap myResult2AISObjectMap; ///< A map of displayed objects +#endif /// Number of blocking of the viewer update. The viewer is updated only if it is zero int myViewerBlockedRecursiveCount; -- 2.39.2