0031909: Visualization, AIS_Trihedron - replace maps with arrays
[occt.git] / src / AIS / AIS_Manipulator.hxx
1 // Created on: 2015-12-23
2 // Created by: Anastasia BORISOVA
3 // Copyright (c) 2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _AIS_Manipulator_HeaderFile
17 #define _AIS_Manipulator_HeaderFile
18
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_ManipulatorMode.hxx>
21 #include <gp.hxx>
22 #include <gp_Ax1.hxx>
23 #include <gp_Dir.hxx>
24 #include <gp_Pnt.hxx>
25 #include <Graphic3d_ArrayOfQuadrangles.hxx>
26 #include <Graphic3d_ArrayOfTriangles.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <NCollection_HSequence.hxx>
29 #include <Poly_Triangulation.hxx>
30 #include <V3d_View.hxx>
31 #include <Standard_Version.hxx>
32 #include <Standard_DefineHandle.hxx>
33
34 NCOLLECTION_HSEQUENCE(AIS_ManipulatorObjectSequence, Handle(AIS_InteractiveObject))
35
36 DEFINE_STANDARD_HANDLE (AIS_Manipulator, AIS_InteractiveObject)
37
38 //! Interactive object class to manipulate local transformation of another interactive
39 //! object or a group of objects via mouse.
40 //! It manages three types of manipulations in 3D space:
41 //! - translation through axis
42 //! - scaling within axis
43 //! - rotation around axis
44 //! To enable one of this modes, selection mode (from 1 to 3) is to be activated.
45 //! There are three orthogonal transformation axes defined by position property of
46 //! the manipulator. Particular transformation mode can be disabled for each
47 //! of the axes or all of them. Furthermore each of the axes can be hidden or
48 //! made visible.
49 //! The following steps demonstrate how to attach, configure and use manipulator
50 //! for an interactive object:
51 //! Step 1. Create manipulator object and adjust it appearance:
52 //! @code
53 //! Handle(AIS_Manipulator) aManipulator = new AIS_Manipulator();
54 //! aManipulator->SetPart (0, AIS_Manipulator::Scaling, Standard_False);
55 //! aManipulator->SetPart (1, AIS_Manipulator::Rotation, Standard_False);
56 //! // Attach manipulator to already displayed object and manage manipulation modes
57 //! aManipulator->AttachToObject (anAISObject);
58 //! aManipulator->EnableMode (AIS_Manipulator::Translation);
59 //! aManipulator->EnableMode (AIS_Manipulator::Rotation);
60 //! aManipulator->EnableMode (AIS_Manipulator::Scaling);
61 //! @endcode
62 //! Note that you can enable only one manipulation mode but have all visual parts displayed.
63 //! This code allows you to view manipulator and select its manipulation parts.
64 //! Note that manipulator activates mode on part selection.
65 //! If this mode is activated, no selection will be performed for manipulator.
66 //! It can be activated with highlighting. To enable this:
67 //! @code
68 //! aManipulator->SetModeActivationOnDetection (Standard_True);
69 //! @endcode
70 //! Step 2. To perform transformation of object use next code in your event processing chain:
71 //! @code
72 //! // catch mouse button down event
73 //! if (aManipulator->HasActiveMode())
74 //! {
75 //!   aManipulator->StartTransform (anXPix, anYPix, aV3dView);
76 //! }
77 //! ...
78 //! // or track mouse move event
79 //! if (aManipulator->HasActiveMode())
80 //! {
81 //!   aManipulator->Transform (anXPix, anYPix, aV3dView);
82 //!   aV3dView->Redraw();
83 //! }
84 //! ...
85 //! // or catch mouse button up event (apply) or escape event (cancel)
86 //! aManipulator->StopTransform(/*Standard_Boolean toApply*/);
87 //! @endcode
88 //! Step 3. To deactivate current manipulation mode use:
89 //! @code aManipulator->DeactivateCurrentMode();
90 //! @endcode
91 //! Step 4. To detach manipulator from object use:
92 //! @code
93 //! aManipulator->Detach();
94 //! @endcode
95 //! The last method erases manipulator object.
96 class AIS_Manipulator : public AIS_InteractiveObject
97 {
98 public:
99
100   //! Constructs a manipulator object with default placement and all parts to be displayed.
101   Standard_EXPORT AIS_Manipulator();
102
103   //! Constructs a manipulator object with input location and positions of axes and all parts to be displayed.
104   Standard_EXPORT AIS_Manipulator (const gp_Ax2& thePosition);
105
106   //! Disable or enable visual parts for translation, rotation or scaling for some axis.
107   //! By default all parts are enabled (will be displayed).
108   //! @warning Enabling or disabling of visual parts of manipulator does not manage the manipulation (selection) mode.
109   //! @warning Raises program error if axis index is < 0 or > 2.
110   Standard_EXPORT void SetPart (const Standard_Integer theAxisIndex, const AIS_ManipulatorMode theMode, const Standard_Boolean theIsEnabled);
111
112   //! Disable or enable visual parts for translation, rotation or scaling for ALL axes.
113   //! By default all parts are enabled (will be displayed).
114   //! @warning Enabling or disabling of visual parts of manipulator does not manage the manipulation (selection) mode.
115   //! @warning Raises program error if axis index is < 0 or > 2.
116   Standard_EXPORT void SetPart (const AIS_ManipulatorMode theMode, const Standard_Boolean theIsEnabled);
117
118   //! Behavior settings to be applied when performing transformation:
119   //! - FollowTranslation - whether the manipulator will be moved together with an object.
120   //! - FollowRotation - whether the manipulator will be rotated together with an object.
121   struct OptionsForAttach {
122
123     OptionsForAttach() : AdjustPosition (Standard_True), AdjustSize (Standard_False), EnableModes (Standard_True) {}
124     OptionsForAttach& SetAdjustPosition (const Standard_Boolean theApply) { AdjustPosition = theApply; return *this; }
125     OptionsForAttach& SetAdjustSize     (const Standard_Boolean theApply) { AdjustSize     = theApply; return *this; }
126     OptionsForAttach& SetEnableModes    (const Standard_Boolean theApply) { EnableModes    = theApply; return *this; }
127
128     Standard_Boolean AdjustPosition;
129     Standard_Boolean AdjustSize;
130     Standard_Boolean EnableModes;
131   };
132
133   //! Attaches himself to the input interactive object and become displayed in the same context.
134   //! It is placed in the center of object bounding box, and its size is adjusted to the object bounding box.
135   Standard_EXPORT void Attach (const Handle(AIS_InteractiveObject)& theObject, const OptionsForAttach& theOptions = OptionsForAttach());
136
137   //! Attaches himself to the input interactive object group and become displayed in the same context.
138   //! It become attached to the first object, baut manage manipulation of the whole group.
139   //! It is placed in the center of object bounding box, and its size is adjusted to the object bounding box.
140   Standard_EXPORT void Attach (const Handle(AIS_ManipulatorObjectSequence)& theObject, const OptionsForAttach& theOptions = OptionsForAttach());
141
142   //! Enable manipualtion mode.
143   //! @warning It activates selection mode in the current context.
144   //! If manipulator is not displayed, no mode will be activated.
145   Standard_EXPORT void EnableMode (const AIS_ManipulatorMode theMode);
146
147   //! Enables mode activation on detection (highlighting).
148   //! By default, mode is activated on selection of manipulator part.
149   //! @warning If this mode is enabled, selection of parts does nothing.
150   void SetModeActivationOnDetection (const Standard_Boolean theToEnable)
151   {
152     myIsActivationOnDetection = theToEnable;
153   }
154
155   //! @return true if manual mode activation is enabled.
156   Standard_Boolean IsModeActivationOnDetection() const
157   {
158     return myIsActivationOnDetection;
159   }
160
161 public:
162   //! Drag object in the viewer.
163   //! @param theCtx      [in] interactive context
164   //! @param theView     [in] active View
165   //! @param theOwner    [in] the owner of detected entity
166   //! @param theDragFrom [in] drag start point
167   //! @param theDragTo   [in] drag end point
168   //! @param theAction   [in] drag action
169   //! @return FALSE if object rejects dragging action (e.g. AIS_DragAction_Start)
170   Standard_EXPORT virtual Standard_Boolean ProcessDragging (const Handle(AIS_InteractiveContext)& theCtx,
171                                                             const Handle(V3d_View)& theView,
172                                                             const Handle(SelectMgr_EntityOwner)& theOwner,
173                                                             const Graphic3d_Vec2i& theDragFrom,
174                                                             const Graphic3d_Vec2i& theDragTo,
175                                                             const AIS_DragAction theAction) Standard_OVERRIDE;
176
177   //! Init start (reference) transformation.
178   //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform
179   //! and is used only for custom transform set. If Transform(const Standard_Integer, const Standard_Integer) is used,
180   //! initial data is set automatically, and it is reset on DeactivateCurrentMode call if it is not reset yet.
181   Standard_EXPORT void StartTransform (const Standard_Integer theX, const Standard_Integer theY, const Handle(V3d_View)& theView);
182
183   //! Apply to the owning objects the input transformation.
184   //! @remark The transformation is set using SetLocalTransformation for owning objects.
185   //! The location of the manipulator is stored also in Local Transformation,
186   //! so that there's no need to redisplay objects.
187   //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform
188   //! and is used only for custom transform set.
189   //! @warning It will does nothing if transformation is not initiated (with StartTransform() call).
190   Standard_EXPORT void Transform (const gp_Trsf& aTrsf);
191
192   //! Reset start (reference) transformation.
193   //! @param theToApply [in] option to apply or to cancel the started transformation.
194   //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform
195   //! and is used only for custom transform set.
196   Standard_EXPORT void StopTransform (const Standard_Boolean theToApply = Standard_True);
197
198   //! Apply transformation made from mouse moving from start position
199   //! (save on the first Tranform() call and reset on DeactivateCurrentMode() call.)
200   //! to the in/out mouse position (theX, theY)
201   Standard_EXPORT gp_Trsf Transform (const Standard_Integer theX, const Standard_Integer theY,
202                                      const Handle(V3d_View)& theView);
203
204   //! Computes transformation of parent object according to the active mode and input motion vector.
205   //! You can use this method to get object transformation according to current mode or use own algorithm
206   //! to implement any other tranformation for modes.
207   //! @return transformation of parent object.
208   Standard_EXPORT Standard_Boolean ObjectTransformation (const Standard_Integer theX, const Standard_Integer theY,
209                                                          const Handle(V3d_View)& theView, gp_Trsf& theTrsf);
210
211   //! Make inactive the current selected manipulator part and reset current axis index and current mode.
212   //! After its call HasActiveMode() returns false.
213   //! @sa HasActiveMode()
214   Standard_EXPORT void DeactivateCurrentMode();
215
216   //! Detaches himself from the owner object, and removes itself from context.
217   Standard_EXPORT void Detach();
218
219   //! @return all owning objects.
220   Standard_EXPORT Handle(AIS_ManipulatorObjectSequence) Objects() const;
221
222   //! @return the first (leading) object of the owning objects.
223   Standard_EXPORT Handle(AIS_InteractiveObject) Object() const;
224
225   //! @return one of the owning objects.
226   //! @warning raises program error if theIndex is more than owning objects count or less than 1.
227   Standard_EXPORT Handle(AIS_InteractiveObject) Object (const Standard_Integer theIndex) const;
228
229   //! @return true if manipulator is attached to some interactive object (has owning object).
230   Standard_Boolean IsAttached() const { return HasOwner(); }
231
232   //! @return true if some part of manipulator is selected (transformation mode is active, and owning object can be transformed).
233   Standard_Boolean HasActiveMode() const { return IsAttached() && myCurrentMode != AIS_MM_None; }
234
235   Standard_Boolean HasActiveTransformation() { return myHasStartedTransformation; }
236
237   gp_Trsf StartTransformation() const { return !myStartTrsfs.IsEmpty() ? myStartTrsfs.First() : gp_Trsf(); }
238
239   gp_Trsf StartTransformation (Standard_Integer theIndex) const
240   {
241     Standard_ProgramError_Raise_if (theIndex < 1 || theIndex > Objects()->Upper(),
242       "AIS_Manipulator::StartTransformation(): theIndex is out of bounds");
243     return !myStartTrsfs.IsEmpty() ? myStartTrsfs (theIndex) : gp_Trsf();
244   }
245
246 public: //! @name Configuration of graphical transformations
247
248   //! Enable or disable zoom persistence mode for the manipulator. With
249   //! this mode turned on the presentation will keep fixed screen size.
250   //! @warning when turned on this option overrides transform persistence
251   //! properties and local transformation to achieve necessary visual effect.
252   //! @warning revise use of AdjustSize argument of of \sa AttachToObjects method
253   //! when enabling zoom persistence.
254   Standard_EXPORT void SetZoomPersistence (const Standard_Boolean theToEnable);
255
256   //! Returns state of zoom persistence mode, whether it turned on or off.
257   Standard_Boolean ZoomPersistence() const { return myIsZoomPersistentMode; }
258
259   //! Redefines transform persistence management to setup transformation for sub-presentation of axes.
260   //! @warning this interactive object does not support custom transformation persistence when
261   //! using \sa ZoomPersistence mode. In this mode the transformation persistence flags for
262   //! presentations are overridden by this class.
263   //! @warning Invokes debug assertion to catch incompatible usage of the method with \sa ZoomPersistence mode,
264   //! silently does nothing in release mode.
265   //! @warning revise use of AdjustSize argument of of \sa AttachToObjects method
266   //! when enabling zoom persistence.
267   Standard_EXPORT virtual void SetTransformPersistence (const  Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE;
268
269 public: //! @name Setters for parameters
270
271   AIS_ManipulatorMode ActiveMode() const { return myCurrentMode; }
272
273   Standard_Integer ActiveAxisIndex() const { return myCurrentIndex; }
274
275   //! @return poition of manipulator interactive object.
276   const gp_Ax2& Position() const { return myPosition; }
277
278   //! Sets position of the manipulator object.
279   Standard_EXPORT void SetPosition (const gp_Ax2& thePosition);
280
281   Standard_ShortReal Size() const { return myAxes[0].Size(); }
282
283   //! Sets size (length of side of the manipulator cubic bounding box.
284   Standard_EXPORT void SetSize (const Standard_ShortReal theSideLength);
285
286   //! Sets gaps between translator, scaler and rotator sub-presentations.
287   Standard_EXPORT void SetGap (const Standard_ShortReal theValue);
288
289 public:
290
291   //! Behavior settings to be applied when performing transformation:
292   //! - FollowTranslation - whether the manipulator will be moved together with an object.
293   //! - FollowRotation - whether the manipulator will be rotated together with an object.
294   struct BehaviorOnTransform {
295
296     BehaviorOnTransform() : FollowTranslation (Standard_True), FollowRotation (Standard_True), FollowDragging (Standard_True) {}
297     BehaviorOnTransform& SetFollowTranslation (const Standard_Boolean theApply) { FollowTranslation = theApply; return *this; }
298     BehaviorOnTransform& SetFollowRotation    (const Standard_Boolean theApply) { FollowRotation    = theApply; return *this; }
299     BehaviorOnTransform& SetFollowDragging    (const Standard_Boolean theApply) { FollowDragging    = theApply; return *this; }
300
301     Standard_Boolean FollowTranslation;
302     Standard_Boolean FollowRotation;
303     Standard_Boolean FollowDragging;
304   };
305
306   //! Sets behavior settings for transformation action carried on the manipulator,
307   //! whether it translates, rotates together with the transformed object or not.
308   void SetTransformBehavior (const BehaviorOnTransform& theSettings) { myBehaviorOnTransform = theSettings; }
309
310   //! @return behavior settings for transformation action of the manipulator.
311   BehaviorOnTransform& ChangeTransformBehavior() { return myBehaviorOnTransform; }
312
313   //! @return behavior settings for transformation action of the manipulator.
314   const BehaviorOnTransform& TransformBehavior() const { return myBehaviorOnTransform; }
315
316 public: //! @name Presentation computation
317
318   //! Fills presentation.
319   //! @note Manipulator presentation does not use display mode and for all modes has the same presentation.
320   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
321                                         const Handle(Prs3d_Presentation)& thePrs,
322                                         const Standard_Integer theMode = 0) Standard_OVERRIDE;
323
324   //! Computes selection sensitive zones (triangulation) for manipulator.
325   //! @param theNode [in] Selection mode that is treated as transformation mode.
326   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
327                                                  const Standard_Integer theMode) Standard_OVERRIDE;
328
329   //! Disables auto highlighting to use HilightSelected() and HilightOwnerWithColor() overridden methods.
330   virtual Standard_Boolean IsAutoHilight() const Standard_OVERRIDE
331   {
332     return Standard_False;
333   }
334
335   //! Method which clear all selected owners belonging
336   //! to this selectable object ( for fast presentation draw ).
337   Standard_EXPORT virtual void ClearSelected() Standard_OVERRIDE;
338
339   //! Method which draws selected owners ( for fast presentation draw ).
340   Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM, const SelectMgr_SequenceOfOwner& theSeq) Standard_OVERRIDE;
341
342   //! Method which hilight an owner belonging to
343   //! this selectable object  ( for fast presentation draw ).
344   Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
345                                                       const Handle(Prs3d_Drawer)& theStyle,
346                                                       const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
347
348 protected:
349
350   Standard_EXPORT void init();
351
352   Standard_EXPORT void updateTransformation();
353
354   Standard_EXPORT Handle(Prs3d_Presentation) getHighlightPresentation (const Handle(SelectMgr_EntityOwner)& theOwner) const;
355
356   Standard_EXPORT Handle(Graphic3d_Group) getGroup (const Standard_Integer theIndex, const AIS_ManipulatorMode theMode) const;
357
358   Standard_EXPORT void attachToBox (const Bnd_Box& theBox);
359
360   Standard_EXPORT void adjustSize (const Bnd_Box& theBox);
361
362   Standard_EXPORT void setTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers);
363
364   //! Redefines local transformation management method to inform user of inproper use.
365   //! @warning this interactive object does not support setting custom local transformation,
366   //! this class solely uses this property to implement visual positioning of the manipulator
367   //! without need for recomputing presentation.
368   //! @warning Invokes debug assertion in debug to catch incompatible usage of the
369   //! method, silently does nothing in release mode.
370   Standard_EXPORT virtual void setLocalTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE;
371   using AIS_InteractiveObject::SetLocalTransformation; // hide visibility
372
373 protected: //! @name Auxiliary classes to fill presentation with proper primitives
374
375   class Quadric
376   {
377   public:
378
379     virtual ~Quadric()
380     {
381       myTriangulation.Nullify();
382       myArray.Nullify();
383     }
384
385
386     const Handle(Poly_Triangulation)& Triangulation() const { return myTriangulation; }
387
388     const Handle(Graphic3d_ArrayOfTriangles)& Array() const { return myArray; }
389
390   protected:
391
392     Handle(Poly_Triangulation) myTriangulation;
393     Handle(Graphic3d_ArrayOfTriangles) myArray;
394   };
395
396   class Disk : public Quadric
397   {
398   public:
399
400     Disk()
401       : Quadric(),
402       myInnerRad(0.0f),
403       myOuterRad(1.0f)
404     { }
405
406     ~Disk() { }
407
408     void Init (const Standard_ShortReal theInnerRadius,
409                const Standard_ShortReal theOuterRadius,
410                const gp_Ax1& thePosition,
411                const Standard_Integer theSlicesNb = 20,
412                const Standard_Integer theStacksNb = 20);
413
414   protected:
415
416     gp_Ax1             myPosition;
417     Standard_ShortReal myInnerRad;
418     Standard_ShortReal myOuterRad;
419   };
420
421   class Sphere : public Quadric
422   {
423   public:
424     Sphere()
425       : Quadric(),
426       myRadius(1.0f)
427     {}
428
429     void Init (const Standard_ShortReal theRadius,
430                const gp_Pnt& thePosition,
431                const Standard_Integer theSlicesNb = 20,
432                const Standard_Integer theStacksNb = 20);
433
434   protected:
435
436     gp_Pnt myPosition;
437     Standard_ShortReal myRadius;
438   };
439
440   class Cube
441   {
442   public:
443
444     Cube() { }
445     ~Cube() { }
446
447     void Init (const gp_Ax1& thePosition, const Standard_ShortReal myBoxSize);
448
449     const Handle(Poly_Triangulation)& Triangulation() const { return myTriangulation; }
450
451     const Handle(Graphic3d_ArrayOfTriangles)& Array() const { return myArray; }
452
453   private:
454
455     void addTriangle (const Standard_Integer theIndex, const gp_Pnt& theP1, const gp_Pnt& theP2, const gp_Pnt& theP3,
456                       const gp_Dir& theNormal);
457
458   protected:
459
460     Handle(Poly_Triangulation) myTriangulation;
461     Handle(Graphic3d_ArrayOfTriangles) myArray;
462   };
463
464   class Sector : public Quadric
465   {
466   public:
467
468     Sector()
469       : Quadric(),
470       myRadius(0.0f)
471     { }
472
473     ~Sector() { }
474
475     void Init(const Standard_ShortReal theRadius,
476               const gp_Ax1&            thePosition,
477               const gp_Dir&            theXDirection,
478               const Standard_Integer   theSlicesNb = 5,
479               const Standard_Integer   theStacksNb = 5);
480
481   protected:
482
483     gp_Ax1             myPosition;
484     Standard_ShortReal myRadius;
485   };
486
487   //! The class describes on axis sub-object.
488   //! It includes sub-objects itself:
489   //! -rotator
490   //! -translator
491   //! -scaler
492   class Axis
493   {
494   public:
495
496     Axis (const gp_Ax1& theAxis              = gp_Ax1(),
497           const Quantity_Color& theColor     = Quantity_Color(),
498           const Standard_ShortReal theLength = 10.0f);
499
500     void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
501                   const Handle(Prs3d_Presentation)& thePrs,
502                   const Handle(Prs3d_ShadingAspect)& theAspect);
503
504     const gp_Ax1& ReferenceAxis() const { return myReferenceAxis; }
505
506     void SetPosition (const gp_Ax1& thePosition) { myPosition = thePosition; }
507
508     const gp_Ax1& Position() const { return myPosition; }
509
510     void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
511     {
512       if (!myHighlightTranslator.IsNull())
513       {
514         myHighlightTranslator->SetTransformPersistence (theTrsfPers);
515       }
516
517       if (!myHighlightScaler.IsNull())
518       {
519         myHighlightScaler->SetTransformPersistence (theTrsfPers);
520       }
521
522       if (!myHighlightRotator.IsNull())
523       {
524         myHighlightRotator->SetTransformPersistence (theTrsfPers);
525       }
526
527       if (!myHighlightDragger.IsNull())
528       {
529         myHighlightDragger->SetTransformPersistence(theTrsfPers);
530       }
531     }
532
533     void Transform (const Handle(TopLoc_Datum3D)& theTransformation)
534     {
535       if (!myHighlightTranslator.IsNull())
536       {
537         myHighlightTranslator->SetTransformation (theTransformation);
538       }
539
540       if (!myHighlightScaler.IsNull())
541       {
542         myHighlightScaler->SetTransformation (theTransformation);
543       }
544
545       if (!myHighlightRotator.IsNull())
546       {
547         myHighlightRotator->SetTransformation (theTransformation);
548       }
549
550       if (!myHighlightDragger.IsNull())
551       {
552         myHighlightDragger->SetTransformation(theTransformation);
553       }
554     }
555
556     Standard_Boolean HasTranslation() const { return myHasTranslation; }
557
558     Standard_Boolean HasRotation() const { return myHasRotation; }
559
560     Standard_Boolean HasScaling() const { return myHasScaling; }
561
562     Standard_Boolean HasDragging() const { return myHasDragging; }
563
564     void SetTranslation (const Standard_Boolean theIsEnabled) { myHasTranslation = theIsEnabled; }
565
566     void SetRotation (const Standard_Boolean theIsEnabled) { myHasRotation = theIsEnabled; }
567
568     void SetScaling (const Standard_Boolean theIsEnabled) { myHasScaling = theIsEnabled; }
569
570     void SetDragging(const Standard_Boolean theIsEnabled) { myHasDragging = theIsEnabled; }
571
572     Quantity_Color Color() const { return myColor; }
573
574     Standard_ShortReal AxisLength() const { return myLength; }
575
576     Standard_ShortReal AxisRadius() const { return myAxisRadius; }
577
578     void SetAxisRadius (const Standard_ShortReal theValue) { myAxisRadius = theValue; }
579
580     const Handle(Prs3d_Presentation)& TranslatorHighlightPrs() const { return myHighlightTranslator; }
581
582     const Handle(Prs3d_Presentation)& RotatorHighlightPrs() const { return myHighlightRotator; }
583
584     const Handle(Prs3d_Presentation)& ScalerHighlightPrs() const { return myHighlightScaler; }
585
586     const Handle(Prs3d_Presentation)& DraggerHighlightPrs() const { return myHighlightDragger; }
587
588     const Handle(Graphic3d_Group)& TranslatorGroup() const { return myTranslatorGroup; }
589
590     const Handle(Graphic3d_Group)& RotatorGroup() const { return myRotatorGroup; }
591
592     const Handle(Graphic3d_Group)& ScalerGroup() const { return myScalerGroup; }
593
594     const Handle(Graphic3d_Group)& DraggerGroup() const { return myDraggerGroup; }
595
596     const Handle(Graphic3d_ArrayOfTriangles)& TriangleArray() const { return myTriangleArray; }
597
598     void SetIndent (const Standard_ShortReal theValue) { myIndent = theValue; }
599
600     Standard_ShortReal Size() const { return myLength + myBoxSize + myDiskThickness + myIndent * 2.0f; }
601
602     gp_Pnt ScalerCenter (const gp_Pnt& theLocation) const { return theLocation.XYZ() + myPosition.Direction().XYZ() * (myLength + myIndent + myBoxSize * 0.5f); }
603
604     void SetSize (const Standard_ShortReal theValue)
605     {
606       if (myIndent > theValue * 0.1f)
607       {
608         myLength = theValue * 0.7f;
609         myBoxSize = theValue * 0.15f;
610         myDiskThickness = theValue * 0.05f;
611         myIndent = theValue * 0.05f;
612       }
613       else // use pre-set value of predent
614       {
615         Standard_ShortReal aLength = theValue - 2 * myIndent;
616         myLength = aLength * 0.8f;
617         myBoxSize = aLength * 0.15f;
618         myDiskThickness = aLength * 0.05f;
619       }
620       myInnerRadius = myIndent * 2 + myBoxSize + myLength;
621       myAxisRadius = myBoxSize / 4.0f;
622     }
623
624     Standard_Integer FacettesNumber() const { return myFacettesNumber; }
625
626   public:
627
628     const gp_Pnt& TranslatorTipPosition() const { return myArrowTipPos; }
629     const Sector& DraggerSector() const { return mySector; }
630     const Disk& RotatorDisk() const { return myCircle; }
631     float RotatorDiskRadius() const { return myCircleRadius; }
632     const Cube& ScalerCube() const { return myCube; }
633     const gp_Pnt& ScalerCubePosition() const { return myCubePos; }
634
635   protected:
636
637     gp_Ax1 myReferenceAxis; //!< Returns reference axis assignment.
638     gp_Ax1 myPosition; //!< Position of the axis including local transformation.
639     Quantity_Color myColor;
640
641     Standard_Boolean myHasTranslation;
642     Standard_ShortReal myLength; //!< Length of translation axis.
643     Standard_ShortReal myAxisRadius;
644
645     Standard_Boolean myHasScaling;
646     Standard_ShortReal myBoxSize; //!< Size of scaling cube.
647
648     Standard_Boolean myHasRotation;
649     Standard_ShortReal myInnerRadius; //!< Radius of rotation circle.
650     Standard_ShortReal myDiskThickness;
651     Standard_ShortReal myIndent; //!< Gap between visual part of the manipulator.
652
653     Standard_Boolean myHasDragging;
654
655   protected:
656
657     Standard_Integer myFacettesNumber;
658
659     gp_Pnt   myArrowTipPos;
660     Sector   mySector;
661     Disk     myCircle;
662     float    myCircleRadius;
663     Cube     myCube;
664     gp_Pnt   myCubePos;
665
666     Handle(Graphic3d_Group) myTranslatorGroup;
667     Handle(Graphic3d_Group) myScalerGroup;
668     Handle(Graphic3d_Group) myRotatorGroup;
669     Handle(Graphic3d_Group) myDraggerGroup;
670
671     Handle(Prs3d_Presentation) myHighlightTranslator;
672     Handle(Prs3d_Presentation) myHighlightScaler;
673     Handle(Prs3d_Presentation) myHighlightRotator;
674     Handle(Prs3d_Presentation) myHighlightDragger;
675
676     Handle(Graphic3d_ArrayOfTriangles) myTriangleArray;
677
678   };
679
680 protected:
681
682   Axis myAxes[3]; //!< Tree axes of the manipulator.
683   Sphere myCenter; //!< Visual part displaying the center sphere of the manipulator.
684   gp_Ax2 myPosition; //!< Position of the manipulator object. it displays its location and position of its axes.
685
686   Standard_Integer myCurrentIndex; //!< Index of active axis.
687   AIS_ManipulatorMode myCurrentMode; //!< Name of active manipulation mode.
688
689   Standard_Boolean myIsActivationOnDetection; //!< Manual activation of modes (not on parts selection).
690   Standard_Boolean myIsZoomPersistentMode; //!< Zoom persistence mode activation.
691   BehaviorOnTransform myBehaviorOnTransform; //!< Behavior settings applied on manipulator when transforming an object.
692
693 protected: //! @name Fields for interactive transformation. Fields only for internal needs. They do not have public interface.
694
695   NCollection_Sequence<gp_Trsf> myStartTrsfs; //!< Owning object transformation for start. It is used internally.
696   Standard_Boolean myHasStartedTransformation; //!< Shows if transformation is processed (sequential calls of Transform()).
697   gp_Ax2 myStartPosition; //! Start position of manipulator.
698   gp_Pnt myStartPick; //! 3d point corresponding to start mouse pick.
699   Standard_Real myPrevState; //! Previous value of angle during rotation.
700
701   //! Aspect used to color current detected part and current selected part.
702   Handle(Prs3d_ShadingAspect) myHighlightAspect;
703
704   //! Aspect used to color sector part when it's selected.
705   Handle(Prs3d_ShadingAspect) myDraggerHighlight;
706 public:
707
708   DEFINE_STANDARD_RTTIEXT(AIS_Manipulator, AIS_InteractiveObject)
709 };
710 #endif // _AIS_Manipulator_HeaderFile