Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0
[modules/shaper.git] / src / XGUI / XGUI_Displayer.h
index c1aded1faf268d1b5419f04e59fa129c8f447ef9..cf35c008302d2284daa9baae23e467d37da95e93 100644 (file)
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ViewerPrs.h>
 
+#include <GeomAPI_ICustomPrs.h>
+
 #include <SelectMgr_AndFilter.hxx>
 
 #include <QString>
 #include <QMap>
+#include <QObject>
+#include <QColor>
 
 class ModelAPI_Feature;
 class XGUI_Workshop;
@@ -32,8 +36,9 @@ class XGUI_Workshop;
  * \ingroup GUI
  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
  */
-class XGUI_EXPORT XGUI_Displayer
+class XGUI_EXPORT XGUI_Displayer: public QObject
 {
+  Q_OBJECT
  public:
    /// \enum DisplayMode display mode
    enum DisplayMode { 
@@ -67,12 +72,20 @@ class XGUI_EXPORT XGUI_Displayer
   /// \param isUpdate the parameter whether the viewer should be update immediatelly
   void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
 
+  /** Redisplay the shape if it was displayed
+   * \param theObject an object instance
+   * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+   */
+  void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
+
   /**
-   * Add presentations which corresponds to the given features to current selection
-   * \param theFeatures a list of features to be selected
+   * Add presentations to current selection. It unhighlight and deselect the current selection.
+   * The shape and result components are processed in the values. If the presentation shape is not
+   * empty, select it, otherwise select the result.
+   * \param theValues a list of presentation to be selected
    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
    */
-  void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
+  void setSelected(const  QList<ModuleBase_ViewerPrs>& theValues, bool isUpdateViewer = true);
 
 
   /// Unselect all objects
@@ -115,7 +128,7 @@ class XGUI_EXPORT XGUI_Displayer
   bool enableUpdateViewer(const bool isEnabled);
 
   /// Updates the viewer
-  void updateViewer();
+  void updateViewer() const;
 
   /// Searches the interactive object by feature
   /// \param theObject the object or presentable feature
@@ -179,10 +192,31 @@ class XGUI_EXPORT XGUI_Displayer
   /// Returns list of displayed objects
   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
 
+  /// Returns list of displayed objects
+  QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
+
   /// Returns true if the given object can be shown in shaded mode
   /// \param theObject object to check
   bool canBeShaded(ObjectPtr theObject) const;
 
+  /// Set color on presentation of an object if it is displayed
+  /// \param theObject an object 
+  /// \param theColor a color which has to be set
+  /// \param toUpdate update viewer flag
+  /// \return previously defined color on the object
+  QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true);
+
+signals:
+  /// Signal on object display
+  /// \param theObject a data object
+  /// \param theAIS a presentation object
+  void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
+
+  /// Signal on before object erase
+  /// \param theObject a data object
+  /// \param theAIS a presentation object
+  void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
+
  protected:
   /// Returns currently installed AIS_InteractiveContext
   Handle(AIS_InteractiveContext) AISContext() const;
@@ -200,15 +234,32 @@ class XGUI_EXPORT XGUI_Displayer
   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
                bool isUpdateViewer = true);
 
-  /** Redisplay the shape if it was displayed
-   * \param theObject an object instance
-   * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-   */
-  void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
+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) const;
 
   /// Opens local context. Does nothing if it is already opened.
   void openLocalContext();
 
+  /** Update the object presentable properties such as color, lines width and other
+   * If the object is result with the color attribute value set, it is used,
+   * otherwise the customize is applyed to the object's feature if it is a custom prs
+   * \param theObject an object instance
+   * \return the true state if there is changes and the presentation is customized
+   */
+  bool customizeObject(ObjectPtr theObject);
+
+  /// Append the objects in the internal map. Checks whether the map already contains the object
+  /// \param theObject an object to display
+  /// \param theAIS AIOS object to display
+  void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
+
+  /// Returns an information about alredy displayed objects
+  /// \return a string representation
+  std::string getResult2AISObjectMapInfo() const;
+
  protected:
    /// Reference to workshop
   XGUI_Workshop* myWorkshop;
@@ -216,6 +267,9 @@ class XGUI_EXPORT XGUI_Displayer
   /// A container for selection filters
   Handle(SelectMgr_AndFilter) myAndFilter;
 
+  /// A default custom presentation, which is used if the displayed feature is not a custom presentation
+  GeomCustomPrsPtr myCustomPrs;
+
   /// Definition of a type of map which defines correspondance between objects and presentations
   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;