Salome HOME
Issue #1015: The validate icon must be greyed and inactive instead of red and active
[modules/shaper.git] / src / XGUI / XGUI_Displayer.h
index c4ac99b1cde9cd6a71df4aa90a9fd55eae9379f7..b80165b6903a11c5b96cd37203aa7f7b54a17302 100644 (file)
@@ -18,7 +18,6 @@
 #include <ModelAPI_Result.h>
 
 #include <ModuleBase_Definitions.h>
-#include <ModuleBase_ViewerPrs.h>
 
 #include <GeomAPI_ICustomPrs.h>
 
@@ -29,6 +28,7 @@
 #include <QObject>
 #include <QColor>
 
+class ModuleBase_ViewerPrs;
 class ModelAPI_Feature;
 class XGUI_Workshop;
 
@@ -92,7 +92,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject
   /// empty, select it, otherwise select the result.
   /// \param theValues a list of presentation to be selected
   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
-  void setSelected(const  QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer = true);
+  void setSelected(const  QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues, bool theUpdateViewer = true);
 
   /// Unselect all objects
   void clearSelected();
@@ -118,7 +118,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject
   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
   void closeLocalContexts(const bool theUpdateViewer = true);
 
-  // Remove default selection filters of the module from the current viewer
+  /// Remove default selection filters of the module from the current viewer
   void deactivateSelectionFilters();
 
   /// \brief Add selection filter
@@ -137,20 +137,28 @@ 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 true if the viewer update is not blocked
+  bool isUpdateEnabled() const;
+
   /// Updates the viewer
   void updateViewer() const;
 
   /// Activate interactive context
-  /// \param theIO
-  /// \param theMode
+  /// \param theIO an interactive object
+  /// \param theMode activation mode
+  /// \param theUpdateViewer update viewer flag
   void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
                    const bool theUpdateViewer) const;
 
   /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation
+  /// \param theIO an interactive object
+  /// \param theMode a mode to deactivate. When theMode=-1 then all modes will be deactivated
   void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
 
   /// Searches the interactive object by feature
@@ -186,6 +194,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject
   /// Activates in local context displayed outside of the context.
   /// \param theModes - modes on which it has to be activated (can be empty)
   /// \param theObjList - list of objects which has to be activated.
+  /// \param theUpdateViewer an update viewer flag
   void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
                        const bool theUpdateViewer = true);
 
@@ -221,6 +230,35 @@ class XGUI_EXPORT XGUI_Displayer: public QObject
   /// \return previously defined color on the object
   QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
 
+  /// Returns Trihedron object if it is displayed
+  Handle(AIS_InteractiveObject) getTrihedron() const;
+  
+  /// 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; }
+
+  /// Returns list of currently active selection modes
+  /// Selection modes will be returned according to TopAbs_ShapeEnum
+  QIntList activeSelectionModes() const;
+
+
+  /// Converts shape type (TopAbs_ShapeEnum) to selection mode
+  /// \param theShapeType a shape type from TopAbs_ShapeEnum
+  static int getSelectionMode(int theShapeType);
+
+  /// Return true if the object is visible. If the object is feature, it returns true
+  /// if all results of the feature are shown
+  /// \param theDisplayer a displayer
+  /// \param theObject an object
+  /// \return a boolean value
+  static bool isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject);
+
 signals:
   /// Signal on object display
   /// \param theObject a data object
@@ -262,7 +300,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();
@@ -283,6 +322,15 @@ private:
   /// \return a string representation
   std::string getResult2AISObjectMapInfo() const;
 
+  /// Sets the shapes selected in the context. It contains logic of the similar method
+  /// in OCCT but improved for performance. The modification is to iterates by a list
+  /// of owners in the context only once.
+  /// \param theContext a viewer context. It has opened local context
+  /// \param theShapesToBeSelected a map of shapes. Owner's shape is searched in the map and the owner
+  /// is selected if it is found there. Only first owner is processed(according to OCCT logic)
+  static void AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
+                                        const NCollection_Map<TopoDS_Shape>& theShapesToBeSelected);
+
  protected:
    /// Reference to workshop
   XGUI_Workshop* myWorkshop;
@@ -302,8 +350,14 @@ 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;
+
+  /// A flag that update was requested but not done
+  mutable bool myNeedUpdate;
 };
 
 #endif