Salome HOME
Optimization of presentations using definition
authorvsv <vsv@opencascade.com>
Mon, 20 Aug 2018 13:26:53 +0000 (16:26 +0300)
committervsv <vsv@opencascade.com>
Mon, 20 Aug 2018 13:27:08 +0000 (16:27 +0300)
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h

index 99342671c2557ba5ae34287931e792af18114bb3..544d4b5c5a36d3b5fbd8a14bd5d43ab7d3704068 100755 (executable)
@@ -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<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
     foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
+#else
+    QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
+    foreach(AISObjectPtr aAIS, aPrsList) {
+      Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
+#endif
       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
       if (!aDim.IsNull()) {
         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
index 364153dcaf508a16d9e640cae364ef056d284429..3ff7886e03f42dd300e4f0e33aca68a17707ba35 100644 (file)
@@ -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<Handle(AIS_InteractiveObject)>();
       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<Handle(AIS_InteractiveObject)>();
+    if (anAIS == theIO)
+      anObject = aMapIter.key();
+    if (anObject.get())
+      break;
+  }
+#endif
   if (!anObject.get()) {
     std::shared_ptr<GeomAPI_AISObject> 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() << ":";
index 5da345d703014df4c315506532308ff7bcf6ebe8..5989035e77546e069d7ee5703a3ff09ce5c9cfea 100644 (file)
@@ -53,6 +53,7 @@ class VInspectorAPI_CallBack;
 #endif
 
 
+#ifdef OPTIMIZE_PRS
 class XGUI_TwoSidePresentationMap
 {
 public:
@@ -160,22 +161,23 @@ private:
   QMap<ObjectPtr, Handle(AIS_InteractiveObject)> myResultToAISMap;
   QMap<Handle(AIS_InteractiveObject), ObjectPtr> 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<std::shared_ptr<ModuleBase_ViewerPrs>>& 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<Handle(AIS_InteractiveObject)> displayedPresentations() const
   {
     return myResult2AISObjectMap.presentations();
   }
+#else
+  QList<AISObjectPtr> 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<ObjectPtr, AISObjectPtr> 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;