0027958: Visualization, AIS_Trihedron - add shaded presentation option
[occt.git] / src / AIS / AIS_Trihedron.hxx
index 980b3e9..41afd9b 100644 (file)
 #ifndef _AIS_Trihedron_HeaderFile
 #define _AIS_Trihedron_HeaderFile
 
-#include <Standard.hxx>
-#include <Standard_Type.hxx>
-
-#include <Standard_Boolean.hxx>
-#include <Quantity_NameOfColor.hxx>
 #include <AIS_InteractiveObject.hxx>
-#include <Standard_Real.hxx>
-#include <Standard_Integer.hxx>
+#include <AIS_KindOfInteractive.hxx>
+#include <AIS_TrihedronSelectionMode.hxx>
+#include <Graphic3d_ArrayOfTriangles.hxx>
 #include <PrsMgr_PresentationManager3d.hxx>
+#include <Prs3d_DatumAspect.hxx>
+#include <Prs3d_DatumMode.hxx>
+#include <Prs3d_DatumParts.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_PointAspect.hxx>
 #include <SelectMgr_Selection.hxx>
-#include <AIS_KindOfInteractive.hxx>
 #include <TColgp_Array1OfPnt.hxx>
+#include <Quantity_Color.hxx>
+
 class Geom_Axis2Placement;
-class AIS_InteractiveObject;
 class AIS_Axis;
 class AIS_Point;
 class AIS_Plane;
-class AIS_InteractiveContext;
-class Prs3d_Presentation;
-class Prs3d_Projector;
 class Geom_Transformation;
 class gp_Trsf;
-class Quantity_Color;
-
-
-class AIS_Trihedron;
-DEFINE_STANDARD_HANDLE(AIS_Trihedron, AIS_InteractiveObject)
 
 //! Create a selectable trihedron
-//! there are 4 modes of selection :
-//! mode = 0 to select trihedron   ,priority = 1
-//! mode = 1 to select its origin  ,priority = 5
-//! mode = 2 to select its axis    ,priority = 3
-//! mode = 3 to select its planes  ,priority = 2
-//! a trihedron has 1 origin, 3 axes and 3 planes.
-//! Warning
-//! For the presentation of trihedra, the default unit of
-//! length is the millimeter, and the default value for the
-//! representation of axes is 10. To modify these
-//! dimensions, you must temporarily recover the Drawer.
-//! From inside it, you take the aspect in which the values
-//! for length are stocked. For trihedra, this is FirstAxisLength from 
-//! Prs3d_DatumAspect(). Change the
-//! values inside this Aspect and recalculate the presentation.
-//! If you want to use extended selection modes, different than 0,
-//! you should take care of removing of the shapes from the interactive
-//! context that has been computed for selection; it might be necessary
-//! when you change selection mode. You can use methods Axis, Point,
-//! Plane to retrieve the shapes.
+//! The trihedron includes 1 origin, 3 axes and 3 labels.
+//! Default text of labels are "X", "Y", "Z".
+//! Color of origin and any axis, color of arrows and labels may be changed.
+//! Visual presentation might be shown in two, shaded and wireframe modes, wireframe by default).
+//! There are 4 modes of selection:
+//! - AIS_TrihedronSelectionMode_EntireObject to select trihedron,  priority = 1
+//! - AIS_TrihedronSelectionMode_Origin       to select its origin, priority = 5
+//! - AIS_TrihedronSelectionMode_Axes         to select its axis,   priority = 3
+//! - AIS_TrihedronSelectionMode_MainPlanes   to select its planes, priority = 2
+//!
+//! Warning!
+//! For the presentation of trihedron, the default unit of length is the millimetre,
+//! and the default value for the representation of the axes is 100.
+//! If you modify these dimensions, you must temporarily recover the Drawer.
+//! From inside it, you take the aspect in which the values for length are stocked.
+//! For trihedron, this is Prs3d_Drawer_LineAspect.
+//! You change the values inside this Aspect and recalculate the presentation.
 class AIS_Trihedron : public AIS_InteractiveObject
 {
   DEFINE_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject)
 public:
 
-  
   //! Initializes a trihedron entity.
-  Standard_EXPORT AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent);
-  
+  Standard_EXPORT AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent);
+
+  //! Sets Shading or Wireframe display mode, triangle or segment graphic group is used relatively.
+  void SetDatumDisplayMode (Prs3d_DatumMode theMode) { myTrihDispMode = theMode; }
+
+  //! Returns datum display mode.
+  Prs3d_DatumMode DatumDisplayMode() const { return myTrihDispMode; }
+
   //! Returns the right-handed coordinate system set in SetComponent.
-    const Handle(Geom_Axis2Placement)& Component() const;
-  
+  const Handle(Geom_Axis2Placement)& Component() const { return myComponent; }
+
   //! Constructs the right-handed coordinate system aComponent.
-  Standard_EXPORT void SetComponent (const Handle(Geom_Axis2Placement)& aComponent);
-  
+  Standard_EXPORT void SetComponent (const Handle(Geom_Axis2Placement)& theComponent);
+
   //! Returns true if the trihedron object has a size other
-  //! than the default size of 10 mm. along each axis.
-    Standard_Boolean HasOwnSize() const;
-  
+  //! than the default size of 100 mm. along each axis.
+  Standard_Boolean HasOwnSize() const { return myHasOwnSize; }
+
   //! Sets the size aValue for the trihedron object.
-  //! The default value is 10 mm.
-  Standard_EXPORT void SetSize (const Standard_Real aValue);
-  
-  //! Removes any non-default settings for size of this
-  //! trihedron object.
+  //! The default value is 100 mm.
+  Standard_EXPORT void SetSize (const Standard_Real theValue);
+
+  //! Removes any non-default settings for size of this trihedron object.
+  //! If the object has 1 color, the default size of the
+  //! drawer is reproduced, otherwise DatumAspect becomes null.
   Standard_EXPORT void UnsetSize();
-  
+
   Standard_EXPORT Standard_Real Size() const;
-  
-  //! Returns the "XAxis".
-  Standard_EXPORT Handle(AIS_Axis) XAxis() const;
-  
-  //! Returns the "YAxis".
-  Standard_EXPORT Handle(AIS_Axis) YAxis() const;
-  
-  //! Returns the main Axis.
-  Standard_EXPORT Handle(AIS_Axis) Axis() const;
-  
-  //! Returns the origine.
-  Standard_EXPORT Handle(AIS_Point) Position() const;
-  
-  //! Returns the "XYPlane".
-  Standard_EXPORT Handle(AIS_Plane) XYPlane() const;
-  
-  //! Returns the "XZPlane".
-  Standard_EXPORT Handle(AIS_Plane) XZPlane() const;
-  
-  //! Returns the "YZPlane".
-  Standard_EXPORT Handle(AIS_Plane) YZPlane() const;
-  
-  //! connection to <aCtx> default drawer implies a recomputation
-  //! of SubObjects values.
-  Standard_EXPORT virtual void SetContext (const Handle(AIS_InteractiveContext)& aCtx) Standard_OVERRIDE;
-  
-  //! Returns true if the display mode selected, aMode, is
-  //! valid for trihedron datums.
-  Standard_EXPORT Standard_Boolean AcceptDisplayMode (const Standard_Integer aMode) const Standard_OVERRIDE;
-  
-  //! Computes the presentation according to a point of view
-  //! given by <aProjector>.
-  //! To be Used when the associated degenerated Presentations
-  //! have been transformed by <aTrsf> which is not a Pure
-  //! Translation. The HLR Prs can't be deducted automatically
-  //! WARNING :<aTrsf> must be applied
-  //! to the object to display before computation  !!!
-  Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTrsf, const Handle(Prs3d_Presentation)& aPresentation) Standard_OVERRIDE;
+
+  //! Returns true if the display mode selected, aMode, is valid for trihedron datums.
+  virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE
+  {
+    return theMode == 0;
+  }
 
   //! Returns index 3, selection of the planes XOY, YOZ, XOZ.
-  Standard_EXPORT virtual Standard_Integer Signature() const Standard_OVERRIDE;
-  
+  virtual Standard_Integer Signature() const Standard_OVERRIDE { return 3; }
+
   //! Indicates that the type of Interactive Object is datum.
-  Standard_EXPORT virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE;
-  
-  Standard_EXPORT void SetColor (const Quantity_NameOfColor aColor) Standard_OVERRIDE;
-  
-  //! Sets the color aColor for this trihedron object.
-  Standard_EXPORT void SetColor (const Quantity_Color& aColor) Standard_OVERRIDE;
-  
-  Standard_EXPORT void SetTextColor (const Quantity_NameOfColor aColor);
-  
-  Standard_EXPORT Standard_Boolean HasTextColor() const;
-  
-  Standard_EXPORT Quantity_NameOfColor TextColor() const;
-  
-  Standard_EXPORT void SetArrowColor (const Quantity_NameOfColor aColor);
-  
-  Standard_EXPORT Standard_Boolean HasArrowColor() const;
-  
-  Standard_EXPORT Quantity_NameOfColor ArrowColor() const;
-  
-  //! Returns the four extremities of the trihedron from the
-  //! array of points, TheExtrem.
-  Standard_EXPORT void ExtremityPoints (TColgp_Array1OfPnt& TheExtrem) const;
+  virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KOI_Datum; }
+
+  //! Sets the color theColor for this trihedron object, it changes color of axes.
+  void SetColor (const Quantity_NameOfColor theColor) Standard_OVERRIDE
+  {
+    return SetColor (Quantity_Color (theColor));
+  }
+
+  //! Sets the color theColor for this trihedron object, it changes color of axes.
+  Standard_EXPORT void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
   
+  //! Sets color of label of trihedron axes.
+  Standard_EXPORT void SetTextColor (const Quantity_Color& theColor);
+
+  //! Returns true if trihedron has own text color
+  Standard_Boolean HasTextColor() const { return myHasOwnTextColor; }
+
+  //! Returns trihedron text color
+  Standard_EXPORT Quantity_Color TextColor() const;
+
+  //! Sets color of arrow of trihedron axes. Used only in wireframe mode
+  Standard_EXPORT void SetArrowColor (const Quantity_Color& theColor);
+
+  //! Returns true if trihedron has own arrow color
+  Standard_Boolean HasArrowColor() const { return myHasOwnArrowColor; }
+
+  //! Returns trihedron arrow color
+  Standard_EXPORT Quantity_Color ArrowColor() const;
+
   //! Removes the settings for color.
-  Standard_EXPORT void UnsetColor() Standard_OVERRIDE;
-  
-  //! Removes the non-default settings for width set in SetWidth.
-  Standard_EXPORT void UnsetWidth() Standard_OVERRIDE;
+  Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
+
+  //! Sets color of datum part: origin or some of trihedron axes.
+  //! If presentation is shading mode, this color is set for both sides of facing model
+  Standard_EXPORT void SetDatumPartColor (const Prs3d_DatumParts thePart,
+                                          const Quantity_Color&  theColor);
+
+  //! Returns color of datum part: origin or some of trihedron axes.
+  Standard_EXPORT Quantity_Color DatumPartColor (Prs3d_DatumParts thePart);
+
+  //! Sets color of origin.
+  //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
+  Standard_EXPORT void SetOriginColor (const Quantity_Color& theColor);
+
+  //! Sets color of x-axis.
+  //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
+  Standard_EXPORT void SetXAxisColor (const Quantity_Color& theColor);
+
+  //! Sets color of y-axis.
+  //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
+  Standard_EXPORT void SetYAxisColor (const Quantity_Color& theColor);
+
+  //! Sets color of z-axis.
+  //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
+  Standard_EXPORT void SetAxisColor (const Quantity_Color& theColor);
+
+  //! Sets priority of selection for owner of the given type
+  void SetSelectionPriority (Prs3d_DatumParts thePart,
+                             Standard_Integer thePriority)
+  {
+    mySelectionPriority.Bind (thePart, thePriority);
+  }
+
+  //! Sets priority of selection for owner of the given type
+  Standard_Integer SelectionPriority (Prs3d_DatumParts thePart)
+  {
+    return mySelectionPriority.Find (thePart);
+  }
+
+  //! Sets text label for trihedron axis. Parameter thePart should be XAxis, YAxis or ZAxis
+  void SetLabel (const Prs3d_DatumParts thePart,
+                 const TCollection_ExtendedString& thePriority)
+  {
+    myLabel.Bind (thePart, thePriority);
+  }
+
+  //! Returns text of axis. Parameter thePart should be XAxis, YAxis or ZAxis
+  const TCollection_ExtendedString& Label (Prs3d_DatumParts thePart)
+  {
+    return myLabel.Find (thePart);
+  }
+
+public:
+
+  //! Disables auto highlighting to use HilightSelected() and HilightOwnerWithColor() overridden methods.
+  virtual Standard_Boolean IsAutoHilight() const Standard_OVERRIDE { return false; }
+
+  //! Method which clear all selected owners belonging
+  //! to this selectable object ( for fast presentation draw ).
+  Standard_EXPORT virtual void ClearSelected() Standard_OVERRIDE;
+
+  //! Method which draws selected owners ( for fast presentation draw ).
+  Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM,
+                                                const SelectMgr_SequenceOfOwner& theOwners) Standard_OVERRIDE;
+
+  //! Method which hilight an owner belonging to
+  //! this selectable object  ( for fast presentation draw ).
+  Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
+                                                      const Handle(Prs3d_Drawer)& theStyle,
+                                                      const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
 
 protected:
 
-  Standard_EXPORT virtual void setLocalTransformation (const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE;
+  //! Compute trihedron presentation.
+  Standard_EXPORT void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
+                                const Handle(Prs3d_Presentation)& thePrs,
+                                const Standard_Integer theMode) Standard_OVERRIDE;
 
-private:
-  
-  Standard_EXPORT void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode = 0) Standard_OVERRIDE;
-  
-  Standard_EXPORT void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation) Standard_OVERRIDE;
-  
-  Standard_EXPORT void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) Standard_OVERRIDE;
-  
-  Standard_EXPORT void LoadSubObjects();
+  //! This compute is unavailable for trihedron presentation.
+  void Compute (const Handle(Prs3d_Projector)& , const Handle(Prs3d_Presentation)& ) Standard_OVERRIDE {}
+
+  //! This compute is unavailable for trihedron presentation.
+  Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& theProjector,
+                                        const Handle(Geom_Transformation)& theTrsf,
+                                        const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE;
+
+  //! Compute selection.
+  Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+                                                 const Standard_Integer theMode) Standard_OVERRIDE;
 
 protected:
 
-  Handle(Geom_Axis2Placement) myComponent;
-  Handle(AIS_InteractiveObject) myShapes[7];
+  Standard_EXPORT void LoadRecomputable (const Standard_Integer theMode);
+
+  //! Creates a sensitive entity for the datum part that will be used in selection owner creation.
+  Standard_EXPORT Handle(SelectBasics_SensitiveEntity) createSensitiveEntity (const Prs3d_DatumParts thePart,
+                                                     const Handle(SelectBasics_EntityOwner)& theOwner) const;
+
+  //! Computes presentation for display mode equal 1.
+  Standard_EXPORT void computePresentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
+                                            const Handle(Prs3d_Presentation)& thePrs);
+
+  //! Returns own datum aspect of trihedron, create this aspect if it was not created yet.
+  Standard_EXPORT void setOwnDatumAspect();
+
+  //! Returns primitives.
+  Standard_EXPORT Handle(Graphic3d_ArrayOfPrimitives) arrayOfPrimitives(
+                                        Prs3d_DatumParts thePart) const;
+
+  //! Updates graphic groups for the current datum mode
+  //! Parameters of datum position and orientation
+  Standard_EXPORT void updatePrimitives (const Handle(Prs3d_DatumAspect)& theAspect,
+                                         Prs3d_DatumMode theMode,
+                                         const gp_Pnt& theOrigin,
+                                         const gp_Dir& theXDir,
+                                         const gp_Dir& theYDir,
+                                         const gp_Dir& theZDir);
+
+  //! Returns highlight line aspect , create if it is the first call
+  Handle(Prs3d_ShadingAspect) getHighlightAspect();
+  //! Returns highlight line aspect , create if it is the first call
+  Handle(Prs3d_LineAspect) getHighlightLineAspect();
+  //! Returns highlight line aspect , create if it is the first call
+  Handle(Prs3d_PointAspect) getHighlightPointAspect();
+
+protected:
   Standard_Boolean myHasOwnSize;
   Standard_Boolean myHasOwnTextColor;
-  Quantity_NameOfColor myOwnTextColor;
   Standard_Boolean myHasOwnArrowColor;
-  Quantity_NameOfColor myOwnArrowColor;
-};
+  Standard_Boolean myHasOwnDatumAspect;
 
+  Prs3d_DatumMode myTrihDispMode;
+  Handle(Geom_Axis2Placement) myComponent;
 
-#include <AIS_Trihedron.lxx>
+  NCollection_DataMap<Prs3d_DatumParts, Standard_Integer> mySelectionPriority;
+  NCollection_DataMap<Prs3d_DatumParts, TCollection_ExtendedString> myLabel;
 
+  NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_Group)> myPartToGroup;
+  NCollection_List<Prs3d_DatumParts> mySelectedParts;
 
+  Handle(Prs3d_ShadingAspect) myHighlightAspect;
+  Handle(Prs3d_LineAspect)    myHighlightLineAspect;
+  Handle(Prs3d_PointAspect)   myHighlightPointAspect;
 
+  NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_ArrayOfPrimitives)> myPrimitives;
+};
 
+DEFINE_STANDARD_HANDLE(AIS_Trihedron, AIS_InteractiveObject)
 
 #endif // _AIS_Trihedron_HeaderFile