9576915ce951bea790af30414bd72571c79e987d
[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   //! Returns true if arrows are to be drawn
156   Standard_EXPORT Standard_Boolean ToDrawArrows() const;
157
158   //! Sets whether to draw the arrows in visualization
159   Standard_EXPORT void SetDrawArrows (const Standard_Boolean theToDraw);
160
161   //! Sets priority of selection for owner of the given type
162   void SetSelectionPriority (Prs3d_DatumParts thePart,
163                              Standard_Integer thePriority)
164   {
165     mySelectionPriority.Bind (thePart, thePriority);
166   }
167
168   //! Sets priority of selection for owner of the given type
169   Standard_Integer SelectionPriority (Prs3d_DatumParts thePart)
170   {
171     return mySelectionPriority.Find (thePart);
172   }
173
174   //! Sets text label for trihedron axis. Parameter thePart should be XAxis, YAxis or ZAxis
175   void SetLabel (const Prs3d_DatumParts thePart,
176                  const TCollection_ExtendedString& thePriority)
177   {
178     myLabel.Bind (thePart, thePriority);
179   }
180
181   //! Returns text of axis. Parameter thePart should be XAxis, YAxis or ZAxis
182   const TCollection_ExtendedString& Label (Prs3d_DatumParts thePart)
183   {
184     return myLabel.Find (thePart);
185   }
186
187 public:
188
189   //! Disables auto highlighting to use HilightSelected() and HilightOwnerWithColor() overridden methods.
190   virtual Standard_Boolean IsAutoHilight() const Standard_OVERRIDE { return false; }
191
192   //! Method which clear all selected owners belonging
193   //! to this selectable object ( for fast presentation draw ).
194   Standard_EXPORT virtual void ClearSelected() Standard_OVERRIDE;
195
196   //! Method which draws selected owners ( for fast presentation draw ).
197   Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM,
198                                                 const SelectMgr_SequenceOfOwner& theOwners) Standard_OVERRIDE;
199
200   //! Method which hilight an owner belonging to
201   //! this selectable object  ( for fast presentation draw ).
202   Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
203                                                       const Handle(Prs3d_Drawer)& theStyle,
204                                                       const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
205
206 protected:
207
208   //! Compute trihedron presentation.
209   Standard_EXPORT void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
210                                 const Handle(Prs3d_Presentation)& thePrs,
211                                 const Standard_Integer theMode) Standard_OVERRIDE;
212
213   //! This compute is unavailable for trihedron presentation.
214   void Compute (const Handle(Prs3d_Projector)& , const Handle(Prs3d_Presentation)& ) Standard_OVERRIDE {}
215
216   //! This compute is unavailable for trihedron presentation.
217   Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& theProjector,
218                                         const Handle(Geom_Transformation)& theTrsf,
219                                         const Handle(Prs3d_Presentation)& thePrs) Standard_OVERRIDE;
220
221   //! Compute selection.
222   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
223                                                  const Standard_Integer theMode) Standard_OVERRIDE;
224
225 protected:
226
227   //! Creates a sensitive entity for the datum part that will be used in selection owner creation.
228   Standard_EXPORT Handle(SelectBasics_SensitiveEntity) createSensitiveEntity (const Prs3d_DatumParts thePart,
229                                                      const Handle(SelectBasics_EntityOwner)& theOwner) const;
230
231   //! Computes presentation for display mode equal 1.
232   Standard_EXPORT void computePresentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
233                                             const Handle(Prs3d_Presentation)& thePrs);
234
235   //! Returns own datum aspect of trihedron, create this aspect if it was not created yet.
236   Standard_EXPORT void setOwnDatumAspect();
237
238   //! Returns primitives.
239   Standard_EXPORT Handle(Graphic3d_ArrayOfPrimitives) arrayOfPrimitives(
240                                         Prs3d_DatumParts thePart) const;
241
242   //! Updates graphic groups for the current datum mode
243   //! Parameters of datum position and orientation
244   Standard_EXPORT void updatePrimitives (const Handle(Prs3d_DatumAspect)& theAspect,
245                                          Prs3d_DatumMode theMode,
246                                          const gp_Pnt& theOrigin,
247                                          const gp_Dir& theXDir,
248                                          const gp_Dir& theYDir,
249                                          const gp_Dir& theZDir);
250
251   //! Returns highlight line aspect , create if it is the first call
252   Handle(Prs3d_ShadingAspect) getHighlightAspect();
253   //! Returns highlight line aspect , create if it is the first call
254   Handle(Prs3d_LineAspect) getHighlightLineAspect();
255   //! Returns highlight line aspect , create if it is the first call
256   Handle(Prs3d_PointAspect) getHighlightPointAspect();
257
258 protected:
259   Standard_Boolean myHasOwnSize;
260   Standard_Boolean myHasOwnTextColor;
261   Standard_Boolean myHasOwnArrowColor;
262   Standard_Boolean myHasOwnDatumAspect;
263
264   Prs3d_DatumMode myTrihDispMode;
265   Handle(Geom_Axis2Placement) myComponent;
266
267   NCollection_DataMap<Prs3d_DatumParts, Standard_Integer> mySelectionPriority;
268   NCollection_DataMap<Prs3d_DatumParts, TCollection_ExtendedString> myLabel;
269
270   NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_Group)> myPartToGroup;
271   NCollection_List<Prs3d_DatumParts> mySelectedParts;
272
273   Handle(Prs3d_ShadingAspect) myHighlightAspect;
274   Handle(Prs3d_LineAspect)    myHighlightLineAspect;
275   Handle(Prs3d_PointAspect)   myHighlightPointAspect;
276
277   NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_ArrayOfPrimitives)> myPrimitives;
278 };
279
280 DEFINE_STANDARD_HANDLE(AIS_Trihedron, AIS_InteractiveObject)
281
282 #endif // _AIS_Trihedron_HeaderFile