0027957: Visualization, AIS_InteractiveContext - protect from displaying the same...
[occt.git] / src / AIS / AIS_InteractiveContext.hxx
index 4643ec9..27dbee7 100644 (file)
 #include <Standard_Integer.hxx>
 #include <AIS_DataMapOfILC.hxx>
 #include <AIS_SequenceOfInteractive.hxx>
-#include <MMgt_TShared.hxx>
 #include <AIS_DisplayStatus.hxx>
 #include <AIS_KindOfInteractive.hxx>
 #include <Standard_Real.hxx>
 #include <Aspect_TypeOfFacingModel.hxx>
+#include <Graphic3d_HighlightStyle.hxx>
 #include <Graphic3d_NameOfMaterial.hxx>
 #include <Standard_ShortReal.hxx>
 #include <TColStd_ListOfInteger.hxx>
@@ -66,10 +66,6 @@ class Standard_Transient;
 class SelectMgr_Filter;
 class TCollection_AsciiString;
 
-
-class AIS_InteractiveContext;
-DEFINE_STANDARD_HANDLE(AIS_InteractiveContext, MMgt_TShared)
-
 //! The Interactive Context allows you to manage
 //! graphic behavior and selection of Interactive Objects
 //! in one or more viewers. Class methods make this
@@ -132,19 +128,19 @@ DEFINE_STANDARD_HANDLE(AIS_InteractiveContext, MMgt_TShared)
 //! selection mode is equal to 0, but it might be redefined if needed. Sub-part selection
 //! of the objects without using local context provides a possibility to activate part
 //! selection modes along with global selection mode.
-class AIS_InteractiveContext : public MMgt_TShared
+class AIS_InteractiveContext : public Standard_Transient
 {
-
+  friend class AIS_LocalContext;
+  DEFINE_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
 public:
 
-  
-
   //! Constructs the interactive context object defined by
   //! the principal viewer MainViewer.
   Standard_EXPORT AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer);
-  
-  Standard_EXPORT virtual void Delete() const Standard_OVERRIDE;
-  
+
+  //! Destructor.
+  Standard_EXPORT virtual ~AIS_InteractiveContext();
+
   Standard_EXPORT void SetAutoActivateSelection (const Standard_Boolean Auto);
   
   Standard_EXPORT Standard_Boolean GetAutoActivateSelection() const;
@@ -277,8 +273,11 @@ public:
   //! Standard_False, the presentation of the Interactive
   //! Object activates the selection mode; the object is
   //! displayed but no viewer will be updated.
-  Standard_EXPORT void Hilight (const Handle(AIS_InteractiveObject)& aniobj, const Standard_Boolean updateviewer = Standard_True);
-  
+  Standard_DEPRECATED("Deprecated method Hilight()")
+  void Hilight (const Handle(AIS_InteractiveObject)& theObj, const Standard_Boolean theIsToUpdateViewer = Standard_True)
+  {
+    return HilightWithColor (theObj, mySelStyle, theIsToUpdateViewer);
+  }
 
   //! Changes the color of all the lines of the object in view,
   //! aniobj. It paints these lines the color passed as the
@@ -287,7 +286,9 @@ public:
   //! Standard_False, the presentation of the Interactive
   //! Object activates the selection mode; the object is
   //! displayed but no viewer will be updated.
-  Standard_EXPORT void HilightWithColor (const Handle(AIS_InteractiveObject)& aniobj, const Quantity_NameOfColor aCol, const Standard_Boolean updateviewer = Standard_True);
+  Standard_EXPORT void HilightWithColor (const Handle(AIS_InteractiveObject)& theObj,
+                                         const Handle(Graphic3d_HighlightStyle)& theStyle,
+                                         const Standard_Boolean theIsToUpdate = Standard_True);
   
 
   //! Removes hilighting from the entity aniobj. Updates the viewer.
@@ -559,19 +560,25 @@ public:
   Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(AIS_InteractiveObject)& anIobj) const;
   
   Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(AIS_InteractiveObject)& aniobj, const Standard_Integer aMode) const;
-  
-  Standard_EXPORT Standard_Boolean IsHilighted (const Handle(AIS_InteractiveObject)& aniobj) const;
-  
-  //! if <anIObj> is hilighted with a specific color
-  //! <WithColor> will be returned TRUE
-  //! <theHiCol> gives the name of the hilightcolor
-  Standard_EXPORT Standard_Boolean IsHilighted (const Handle(AIS_InteractiveObject)& anIobj, Standard_Boolean& WithColor, Quantity_NameOfColor& theHiCol) const;
 
-  //! if <theOwner> is hilighted with a specific color, than <theIsCustomColor> will be set
-  //! to true and <theCustomColorName> will have the name of the color stored
-  Standard_EXPORT Standard_Boolean IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
-                                                Standard_Boolean& theIsCustomColor,
-                                                Quantity_NameOfColor& theCustomColorName) const;
+  //! Returns true if the object is marked as highlighted via its global
+  //! status
+  //! @param theObj [in] the object to check
+  Standard_EXPORT Standard_Boolean IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const;
+
+  //! Returns true if the owner is marked as selected
+  //! @param theOwner [in] the owner to check
+  Standard_EXPORT Standard_Boolean IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  //! Returns highlight style of the object if it is marked as highlighted via global status
+  //! @param theObj [in] the object to check
+  Standard_EXPORT Standard_Boolean HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
+                                                   Handle(Graphic3d_HighlightStyle)& theStyle) const;
+
+  //! Returns highlight style of the owner if it is selected
+  //! @param theOwner [in] the owner to check
+  Standard_EXPORT Standard_Boolean HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
+                                                   Handle(Graphic3d_HighlightStyle)& theStyle) const;
 
   //! Returns the display priority of the entity anIobj. This
   //! will be display   mode of anIobj if it is in the main
@@ -599,9 +606,16 @@ public:
   Standard_EXPORT void Status (const Handle(AIS_InteractiveObject)& anObj, TCollection_ExtendedString& astatus) const;
   
   //! Sets transform persistence.
-  Standard_EXPORT void SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObj,
-                                                const Graphic3d_TransModeFlags&      theFlag,
-                                                const gp_Pnt&                        thePoint = gp_Pnt (0.0, 0.0, 0.0));
+  Standard_EXPORT void SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
+                                                const Handle(Graphic3d_TransformPers)& theTrsfPers);
+
+  Standard_DEPRECATED("This method is deprecated - SetTransformPersistence() taking Graphic3d_TransformPers should be called instead")
+  void SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObj,
+                                const Graphic3d_TransModeFlags&      theFlag,
+                                const gp_Pnt&                        thePoint = gp_Pnt (0.0, 0.0, 0.0))
+  {
+    SetTransformPersistence (theObj, Graphic3d_TransformPers::FromDeprecatedParams (theFlag, thePoint));
+  }
 
   //! Updates the current viewer, the viewer in Neutral Point.
   //! Objects selected when there is no open local context
@@ -614,15 +628,46 @@ public:
     Standard_Integer DisplayMode() const;
   
 
-  //! Returns the name of the color used to show
-  //! highlighted entities, that is, entities picked out by the mouse.
-    Quantity_NameOfColor HilightColor() const;
-  
+  //! Returns current dynamic highlight style settings.
+  //! By default:
+  //!   - the color of dynamic highlight is Quantity_NOC_CYAN1;
+  //!   - the presentation for dynamic highlight is completely opaque;
+  //!   - the type of highlight is Aspect_TOHM_COLOR.
+  const Handle(Graphic3d_HighlightStyle)& HighlightStyle() const
+  {
+    return myHiStyle;
+  }
+
+  //! Allows to manage the style of dynamic highlighting.
+  //! By default:
+  //!   - the color of dynamic highlight is Quantity_NOC_CYAN1;
+  //!   - the presentation for dynamic highlight is completely opaque;
+  //!   - the type of highlight is Aspect_TOHM_COLOR.
+  Handle(Graphic3d_HighlightStyle)& ChangeHighlightStyle()
+  {
+    return myHiStyle;
+  }
+
+  //! Returns current selection style settings.
+  //! By default:
+  //!   - the color of selection is Quantity_NOC_GRAY80;
+  //!   - the presentation for selection is completely opaque;
+  //!   - the type of highlight is Aspect_TOHM_COLOR.
+  const Handle(Graphic3d_HighlightStyle)& SelectionStyle() const
+  {
+    return mySelStyle;
+  }
+
+  //! Allows to manage the style of selection highlighting.
+  //! By default:
+  //!   - the color of selection is Quantity_NOC_GRAY80;
+  //!   - the presentation for selection is completely opaque;
+  //!   - the type of highlight is Aspect_TOHM_COLOR.
+  Handle(Graphic3d_HighlightStyle)& ChangeSelectionStyle()
+  {
+    return mySelStyle;
+  }
 
-  //! Returns the name of the color used to show selected entities.
-  //! By default, this is Quantity_NOC_GRAY80.
-    Quantity_NameOfColor SelectionColor() const;
-  
   //! Returns the name of the color used to show preselection.
   //! By default, this is Quantity_NOC_GREEN.
     Quantity_NameOfColor PreSelectionColor() const;
@@ -633,34 +678,33 @@ public:
     Quantity_NameOfColor DefaultColor() const;
   
 
-  //! Returns the name of the color used to show that an
-  //! object is not currently selected.
+  //! Sub-intensity allows temporary highlighting of particular
+  //! objects with specified color in a manner of selection highlight,
+  //! but without actual selection (e.g., global status and owner's
+  //! selection state will not be updated).
+  //! The method returns the color of such highlighting.
+  //! By default, it is Quantity_NOC_GRAY40.
+  const Quantity_Color& SubIntensityColor() const
+  {
+    return mySubintStyle->Color();
+  }
+
+  //! Sub-intensity allows temporary highlighting of particular
+  //! objects with specified color in a manner of selection highlight,
+  //! but without actual selection (e.g., global status and owner's
+  //! selection state will not be updated).
+  //! The method sets up the color for such highlighting.
   //! By default, this is Quantity_NOC_GRAY40.
-    Quantity_NameOfColor SubIntensityColor() const;
-  
-
-  //! Sets the color used to show highlighted entities, that
-  //! is, entities picked by the mouse.
-  //! By default, this is Quantity_NOC_CYAN1.
-    void SetHilightColor (const Quantity_NameOfColor aHiCol);
-  
-
-  //! Sets the color used to show selected entities.
-  //! By default, this is Quantity_NOC_GRAY80.
-    void SelectionColor (const Quantity_NameOfColor aCol);
-  
+  void SetSubIntensityColor (const Quantity_Color& theColor)
+  {
+    mySubintStyle->SetColor (theColor);
+  }
 
   //! Allows you to set the color used to show preselection.
   //! By default, this is Quantity_NOC_GREEN.
   //! A preselected entity is one which has been selected
   //! as the domain of application of a function such as a fillet.
     void SetPreselectionColor (const Quantity_NameOfColor aCol);
-  
-
-  //! Sets the color used to show that an object is not currently selected.
-  //! By default, this is Quantity_NOC_GRAY40.
-    void SetSubIntensityColor (const Quantity_NameOfColor aCol);
-  
 
   //! Sets the display mode of seen Interactive Objects.
   //! aMode provides the display mode index of the entity aniobj.
@@ -672,7 +716,7 @@ public:
   //! object is displayed but no viewer will be updated.
   //! Note that display mode 3 is only used if you have an
   //! AIS_Textured Shape.
-  Standard_EXPORT void SetDisplayMode (const AIS_DisplayMode AMode, const Standard_Boolean updateviewer = Standard_True);
+  Standard_EXPORT void SetDisplayMode (const Standard_Integer AMode, const Standard_Boolean updateviewer = Standard_True);
   
 
   //! Sets the deviation coefficient aCoefficient.
@@ -881,7 +925,13 @@ public:
   Standard_EXPORT Standard_Integer HilightPreviousDetected (const Handle(V3d_View)& theView, const Standard_Boolean theToRedrawImmediate = Standard_True);
   
   //! Adds object in the selection.
-  Standard_EXPORT AIS_StatusOfPick AddSelect (const Handle(Standard_Transient)& theObject);
+  Standard_EXPORT AIS_StatusOfPick AddSelect (const Handle(SelectMgr_EntityOwner)& theObject);
+
+  //! Adds object in the selection.
+  AIS_StatusOfPick AddSelect (const Handle(AIS_InteractiveObject)& theObject)
+  {
+    return AddSelect (theObject->GlobalSelOwner());
+  }
 
   //! Selects everything found in the bounding rectangle
   //! defined by the pixel minima and maxima, XPMin,
@@ -1489,10 +1539,6 @@ public:
   
   //! Returns true if there is an open context.
     Standard_Boolean HasOpenedContext() const;
-  
-  //! Returns the domain name of the main viewer.
-  Standard_EXPORT Standard_CString DomainOfMainViewer() const;
-  
 
   //! This method is only intended for advanced operation, particularly with
   //! the aim to improve performance when many objects have to be selected
@@ -1548,12 +1594,6 @@ public:
   //! Redraws immediate structures in all views of the viewer given taking into account its visibility.
   Standard_EXPORT void RedrawImmediate (const Handle(V3d_Viewer)& theViewer);
 
-
-friend class AIS_LocalContext;
-
-
-  DEFINE_STANDARD_RTTIEXT(AIS_InteractiveContext,MMgt_TShared)
-
 protected:
 
   Standard_EXPORT void GetDefModes (const Handle(AIS_InteractiveObject)& anIobj, Standard_Integer& Dmode, Standard_Integer& HiMod, Standard_Integer& SelMode) const;
@@ -1577,20 +1617,21 @@ protected:
   //! Helper function to unhighlight all entity owners currently highlighted with seleciton color.
   Standard_EXPORT void unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject);
 
-  //! Helper function that highlights the owner given with <theColor> without
+  //! Helper function that highlights the owner given with <theStyle> without
   //! performing AutoHighlight checks, e.g. is used for dynamic highlight.
-  //! If the parameter <theViewer> is set and <theIsImmediate> is true, highlight will be synchronized
-  //! automatically in all views of the viewer.
   Standard_EXPORT void highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner,
-                                           const Quantity_NameOfColor theColor,
                                            const Handle(V3d_Viewer)& theViewer = NULL);
 
-  //! Helper function that highlights the owner given with <theColor> with check
+  //! Helper function that highlights the owner given with <theStyle> with check
   //! for AutoHighlight, e.g. is used for selection.
-  //! If the parameter <theViewer> is set and <theIsImmediate> is true, selection color will be synchronized
-  //! automatically in all views of the viewer.
-  Standard_EXPORT void highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
-                                          const Quantity_NameOfColor theSelColor);
+  Standard_EXPORT void highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner);
+
+  //! Helper function that highlights global owner of the object given with <theStyle> with check
+  //! for AutoHighlight, e.g. is used for selection.
+  //! If global owner is null, it simply highlights the whole object
+  Standard_EXPORT void highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
+                                        const Handle(Graphic3d_HighlightStyle)& theStyle,
+                                        const Standard_Integer theMode) const;
 
   //! Helper function that unhighlights all owners that are stored in current AIS_Selection.
   //! The function updates global status and selection state of owner and interactive object.
@@ -1598,6 +1639,72 @@ protected:
   //! switched on in AIS_GlobalStatus will be highlighted with context's sub-intensity color.
   Standard_EXPORT void unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity = Standard_False);
 
+  //! Helper function that unhighlights global selection owner of given interactive.
+  //! The function does not perform any updates of global or owner status
+  Standard_EXPORT void unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj, const Standard_Integer theMode) const;
+
+  //! Helper function that turns on sub-intensity in global status and highlights
+  //! given objects with sub-intensity color
+  //! @param theObject [in] the object. If NULL is given, than sub-intensity will be turned on for
+  //! all inveractive objects of the context
+  //! @param theDispMode [in] display mode. If -1 is given, sub-intensity will be turned on for
+  //! all display modes in global status's list of modes
+  //! @param theIsDisplayedOnly [in] is true if sub-intensity should be applied only to objects with
+  //! status AIS_DS_Displayed
+  Standard_EXPORT void turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject = NULL,
+                                           const Standard_Integer theDispMode = -1,
+                                           const Standard_Boolean theIsDisplayedOnly = Standard_True) const;
+
+  //! Helper function that highlights the object with sub-intensity color without any checks
+  //! @param theObject [in] the object that will be highlighted
+  //! @param theMode [in] display mode
+  Standard_EXPORT void highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
+                                                  const Standard_Integer theMode) const;
+
+  //! Helper function that highlights the owner with sub-intensity color without any checks
+  //! @param theOwner [in] the owner that will be highlighted
+  //! @param theMode [in] display mode
+  Standard_EXPORT void highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
+                                                  const Standard_Integer theMode) const;
+
+  //! Helper function that returns correct dynamic highlight style for the object:
+  //! if custom style is defined via object's highlight drawer, it will be used. Otherwise,
+  //! dynamic highlight style of interactive context will be returned.
+  //! @param theObj [in] the object to check
+  const Handle(Graphic3d_HighlightStyle)& getHiStyle (const Handle(AIS_InteractiveObject)& theObj) const
+  {
+    const Handle(Prs3d_Drawer)& aHiDrawer = theObj->HilightAttributes();
+    return !aHiDrawer.IsNull() && aHiDrawer->HasOwnHighlightStyle()
+      ? aHiDrawer->HighlightStyle() : myHiStyle;
+  }
+
+  //! Helper function that returns correct selection style for the object:
+  //! if custom style is defined via object's highlight drawer, it will be used. Otherwise,
+  //! selection style of interactive context will be returned.
+  //! @param theObj [in] the object to check
+  const Handle(Graphic3d_HighlightStyle)& getSelStyle (const Handle(AIS_InteractiveObject)& theObj) const
+  {
+    const Handle(Prs3d_Drawer)& aHiDrawer = theObj->HilightAttributes();
+    return !aHiDrawer.IsNull() && aHiDrawer->HasOwnSelectionStyle()
+      ? aHiDrawer->SelectionStyle() : mySelStyle;
+  }
+
+  //! Assign the context to the object or throw exception if object was already assigned to another context.
+  void setContextToObject (const Handle(AIS_InteractiveObject)& theObj)
+  {
+    if (theObj->HasInteractiveContext())
+    {
+      if (theObj->myCTXPtr != this)
+      {
+        Standard_ProgramError::Raise ("AIS_InteractiveContext - object has been already displayed in another context!");
+      }
+    }
+    else
+    {
+      theObj->SetContext (this);
+    }
+  }
+
 protected:
 
   AIS_DataMapOfIOStatus myObjects;
@@ -1615,10 +1722,10 @@ protected:
   Handle(Prs3d_Drawer) myDefaultDrawer;
   Handle(AIS_Selection) mySelection;
   Quantity_NameOfColor myDefaultColor;
-  Quantity_NameOfColor myHilightColor;
-  Quantity_NameOfColor mySelectionColor;
+  Handle(Graphic3d_HighlightStyle) myHiStyle;
+  Handle(Graphic3d_HighlightStyle) mySelStyle;
   Quantity_NameOfColor myPreselectionColor;
-  Quantity_NameOfColor mySubIntensity;
+  Handle(Graphic3d_HighlightStyle) mySubintStyle;
   Standard_Integer myDisplayMode;
   AIS_DataMapOfILC myLocalContexts;
   Standard_Integer myCurLocalIndex;
@@ -1628,14 +1735,10 @@ protected:
   Standard_Boolean myZDetectionFlag;
   Standard_Boolean myIsAutoActivateSelMode;
 
-
 };
 
+DEFINE_STANDARD_HANDLE(AIS_InteractiveContext, Standard_Transient)
 
 #include <AIS_InteractiveContext.lxx>
 
-
-
-
-
 #endif // _AIS_InteractiveContext_HeaderFile