0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / AIS / AIS_Trihedron.hxx
1 // Created on: 1995-10-09
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _AIS_Trihedron_HeaderFile
18 #define _AIS_Trihedron_HeaderFile
19
20 #include <AIS_InteractiveObject.hxx>
21 #include <AIS_KindOfInteractive.hxx>
22 #include <AIS_TrihedronSelectionMode.hxx>
23 #include <Graphic3d_ArrayOfTriangles.hxx>
24 #include <PrsMgr_PresentationManager3d.hxx>
25 #include <Prs3d_DatumAspect.hxx>
26 #include <Prs3d_DatumMode.hxx>
27 #include <Prs3d_DatumParts.hxx>
28 #include <Prs3d_ShadingAspect.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Prs3d_PointAspect.hxx>
31 #include <SelectMgr_Selection.hxx>
32 #include <TColgp_Array1OfPnt.hxx>
33 #include <Quantity_Color.hxx>
34
35 class Geom_Axis2Placement;
36 class AIS_Axis;
37 class AIS_Point;
38 class AIS_Plane;
39 class Geom_Transformation;
40 class gp_Trsf;
41
42 //! Create a selectable trihedron
43 //! The trihedron includes 1 origin, 3 axes and 3 labels.
44 //! Default text of labels are "X", "Y", "Z".
45 //! Color of origin and any axis, color of arrows and labels may be changed.
46 //! Visual presentation might be shown in two, shaded and wireframe modes, wireframe by default).
47 //! There are 4 modes of selection:
48 //! - AIS_TrihedronSelectionMode_EntireObject to select trihedron,  priority = 1
49 //! - AIS_TrihedronSelectionMode_Origin       to select its origin, priority = 5
50 //! - AIS_TrihedronSelectionMode_Axes         to select its axis,   priority = 3
51 //! - AIS_TrihedronSelectionMode_MainPlanes   to select its planes, priority = 2
52 //!
53 //! Warning!
54 //! For the presentation of trihedron, the default unit of length is the millimetre,
55 //! and the default value for the representation of the axes is 100.
56 //! If you modify these dimensions, you must temporarily recover the Drawer.
57 //! From inside it, you take the aspect in which the values for length are stocked.
58 //! For trihedron, this is Prs3d_Drawer_LineAspect.
59 //! You change the values inside this Aspect and recalculate the presentation.
60 class AIS_Trihedron : public AIS_InteractiveObject
61 {
62   DEFINE_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject)
63 public:
64
65   //! Initializes a trihedron entity.
66   Standard_EXPORT AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent);
67
68   //! Sets Shading or Wireframe display mode, triangle or segment graphic group is used relatively.
69   void SetDatumDisplayMode (Prs3d_DatumMode theMode) { myTrihDispMode = theMode; }
70
71   //! Returns datum display mode.
72   Prs3d_DatumMode DatumDisplayMode() const { return myTrihDispMode; }
73
74   //! Returns the right-handed coordinate system set in SetComponent.
75   const Handle(Geom_Axis2Placement)& Component() const { return myComponent; }
76
77   //! Constructs the right-handed coordinate system aComponent.
78   Standard_EXPORT void SetComponent (const Handle(Geom_Axis2Placement)& theComponent);
79
80   //! Returns true if the trihedron object has a size other
81   //! than the default size of 100 mm. along each axis.
82   Standard_Boolean HasOwnSize() const { return myHasOwnSize; }
83
84   //! Sets the size aValue for the trihedron object.
85   //! The default value is 100 mm.
86   Standard_EXPORT void SetSize (const Standard_Real theValue);
87
88   //! Removes any non-default settings for size of this trihedron object.
89   //! If the object has 1 color, the default size of the
90   //! drawer is reproduced, otherwise DatumAspect becomes null.
91   Standard_EXPORT void UnsetSize();
92
93   Standard_EXPORT Standard_Real Size() const;
94
95   //! Returns true if the display mode selected, aMode, is valid for trihedron datums.
96   virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE
97   {
98     return theMode == 0;
99   }
100
101   //! Returns index 3, selection of the planes XOY, YOZ, XOZ.
102   virtual Standard_Integer Signature() const Standard_OVERRIDE { return 3; }
103
104   //! Indicates that the type of Interactive Object is datum.
105   virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KOI_Datum; }
106
107   //! Sets the color theColor for this trihedron object, it changes color of axes.
108   Standard_EXPORT void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
109   
110   //! Sets color of label of trihedron axes.
111   Standard_EXPORT void SetTextColor (const Quantity_Color& theColor);
112
113   //! Returns true if trihedron has own text color
114   Standard_Boolean HasTextColor() const { return myHasOwnTextColor; }
115
116   //! Returns trihedron text color
117   Standard_EXPORT Quantity_Color TextColor() const;
118
119   //! Sets color of arrow of trihedron axes. Used only in wireframe mode
120   Standard_EXPORT void SetArrowColor (const Quantity_Color& theColor);
121
122   //! Returns true if trihedron has own arrow color
123   Standard_Boolean HasArrowColor() const { return myHasOwnArrowColor; }
124
125   //! Returns trihedron arrow color
126   Standard_EXPORT Quantity_Color ArrowColor() const;
127
128   //! Removes the settings for color.
129   Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
130
131   //! Sets color of datum part: origin or some of trihedron axes.
132   //! If presentation is shading mode, this color is set for both sides of facing model
133   Standard_EXPORT void SetDatumPartColor (const Prs3d_DatumParts thePart,
134                                           const Quantity_Color&  theColor);
135
136   //! Returns color of datum part: origin or some of trihedron axes.
137   Standard_EXPORT Quantity_Color DatumPartColor (Prs3d_DatumParts thePart);
138
139   //! Sets color of origin.
140   //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
141   Standard_EXPORT void SetOriginColor (const Quantity_Color& theColor);
142
143   //! Sets color of x-axis.
144   //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
145   Standard_EXPORT void SetXAxisColor (const Quantity_Color& theColor);
146
147   //! Sets color of y-axis.
148   //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
149   Standard_EXPORT void SetYAxisColor (const Quantity_Color& theColor);
150
151   //! Sets color of z-axis.
152   //! Standard_DEPRECATED("This method is deprecated - SetColor() should be called instead")
153   Standard_EXPORT void SetAxisColor (const Quantity_Color& theColor);
154
155   //! Sets priority of selection for owner of the given type
156   void SetSelectionPriority (Prs3d_DatumParts thePart,
157                              Standard_Integer thePriority)
158   {
159     mySelectionPriority.Bind (thePart, thePriority);
160   }
161
162   //! Sets priority of selection for owner of the given type
163   Standard_Integer SelectionPriority (Prs3d_DatumParts thePart)
164   {
165     return mySelectionPriority.Find (thePart);
166   }
167
168   //! Sets text label for trihedron axis. Parameter thePart should be XAxis, YAxis or ZAxis
169   void SetLabel (const Prs3d_DatumParts thePart,
170                  const TCollection_ExtendedString& thePriority)
171   {
172     myLabel.Bind (thePart, thePriority);
173   }
174
175   //! Returns text of axis. Parameter thePart should be XAxis, YAxis or ZAxis
176   const TCollection_ExtendedString& Label (Prs3d_DatumParts thePart)
177   {
178     return myLabel.Find (thePart);
179   }
180
181 public:
182
183   //! Disables auto highlighting to use HilightSelected() and HilightOwnerWithColor() overridden methods.
184   virtual Standard_Boolean IsAutoHilight() const Standard_OVERRIDE { return false; }
185
186   //! Method which clear all selected owners belonging
187   //! to this selectable object ( for fast presentation draw ).
188   Standard_EXPORT virtual void ClearSelected() Standard_OVERRIDE;
189
190   //! Method which draws selected owners ( for fast presentation draw ).
191   Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM,
192                                                 const SelectMgr_SequenceOfOwner& theOwners) Standard_OVERRIDE;
193
194   //! Method which hilight an owner belonging to
195   //! this selectable object  ( for fast presentation draw ).
196   Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
197                                                       const Handle(Prs3d_Drawer)& theStyle,
198                                                       const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
199
200 protected:
201
202   //! Compute trihedron presentation.
203   Standard_EXPORT void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
204                                 const Handle(Prs3d_Presentation)& thePrs,
205                                 const Standard_Integer theMode) Standard_OVERRIDE;
206
207   //! This compute is unavailable for trihedron presentation.
208   void Compute (const Handle(Prs3d_Projector)& , const Handle(Prs3d_Presentation)& ) Standard_OVERRIDE {}
209
210   //! This compute is unavailable for trihedron presentation.
211   Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& theProjector,
212                                         const Handle(Geom_Transformation)& theTrsf,
213                                         const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE;
214
215   //! Compute selection.
216   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
217                                                  const Standard_Integer theMode) Standard_OVERRIDE;
218
219 protected:
220
221   Standard_EXPORT void LoadRecomputable (const Standard_Integer theMode);
222
223   //! Creates a sensitive entity for the datum part that will be used in selection owner creation.
224   Standard_EXPORT Handle(SelectBasics_SensitiveEntity) createSensitiveEntity (const Prs3d_DatumParts thePart,
225                                                      const Handle(SelectBasics_EntityOwner)& theOwner) const;
226
227   //! Computes presentation for display mode equal 1.
228   Standard_EXPORT void computePresentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
229                                             const Handle(Prs3d_Presentation)& thePrs);
230
231   //! Returns own datum aspect of trihedron, create this aspect if it was not created yet.
232   Standard_EXPORT void setOwnDatumAspect();
233
234   //! Returns primitives.
235   Standard_EXPORT Handle(Graphic3d_ArrayOfPrimitives) arrayOfPrimitives(
236                                         Prs3d_DatumParts thePart) const;
237
238   //! Updates graphic groups for the current datum mode
239   //! Parameters of datum position and orientation
240   Standard_EXPORT void updatePrimitives (const Handle(Prs3d_DatumAspect)& theAspect,
241                                          Prs3d_DatumMode theMode,
242                                          const gp_Pnt& theOrigin,
243                                          const gp_Dir& theXDir,
244                                          const gp_Dir& theYDir,
245                                          const gp_Dir& theZDir);
246
247   //! Returns highlight line aspect , create if it is the first call
248   Handle(Prs3d_ShadingAspect) getHighlightAspect();
249   //! Returns highlight line aspect , create if it is the first call
250   Handle(Prs3d_LineAspect) getHighlightLineAspect();
251   //! Returns highlight line aspect , create if it is the first call
252   Handle(Prs3d_PointAspect) getHighlightPointAspect();
253
254 protected:
255   Standard_Boolean myHasOwnSize;
256   Standard_Boolean myHasOwnTextColor;
257   Standard_Boolean myHasOwnArrowColor;
258   Standard_Boolean myHasOwnDatumAspect;
259
260   Prs3d_DatumMode myTrihDispMode;
261   Handle(Geom_Axis2Placement) myComponent;
262
263   NCollection_DataMap<Prs3d_DatumParts, Standard_Integer> mySelectionPriority;
264   NCollection_DataMap<Prs3d_DatumParts, TCollection_ExtendedString> myLabel;
265
266   NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_Group)> myPartToGroup;
267   NCollection_List<Prs3d_DatumParts> mySelectedParts;
268
269   Handle(Prs3d_ShadingAspect) myHighlightAspect;
270   Handle(Prs3d_LineAspect)    myHighlightLineAspect;
271   Handle(Prs3d_PointAspect)   myHighlightPointAspect;
272
273   NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_ArrayOfPrimitives)> myPrimitives;
274 };
275
276 DEFINE_STANDARD_HANDLE(AIS_Trihedron, AIS_InteractiveObject)
277
278 #endif // _AIS_Trihedron_HeaderFile