0025576: Visualization - implement AIS_ConnectedInteractive::AcceptDisplayMode()
[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 NCOLLECTION_HSEQUENCE(AIS_ManipulatorObjectSequence, Handle(AIS_InteractiveObject));
34
35 DEFINE_STANDARD_HANDLE (AIS_Manipulator, AIS_InteractiveObject)
36
37 //! Interactive object class to manipulate local transformation of another interactive
38 //! object or a group of objects via mouse.
39 //! It manages three types of manipulations in 3D space:
40 //! - translation through axis
41 //! - scaling within axis
42 //! - rotation around axis
43 //! To enable one of this modes, selection mode (from 1 to 3) is to be activated.
44 //! There are three orthogonal transformation axes defined by position property of
45 //! the manipulator. Particular transformation mode can be disabled for each
46 //! of the axes or all of them. Furthermore each of the axes can be hidden or
47 //! made visible.
48 //! The following steps demonstrate how to attach, configure and use manipulator
49 //! for an interactive object:
50 //! Step 1. Create manipulator object and adjust it appearance:
51 //! @code
52 //! Handle(AIS_Manipulator) aManipulator = new AIS_Manipulator();
53 //! aManipulator->SetPart (0, AIS_Manipulator::Scaling, Standard_False);
54 //! aManipulator->SetPart (1, AIS_Manipulator::Rotation, Standard_False);
55 //! // Attach manipulator to already displayed object and manage manipulation modes
56 //! aManipulator->AttachToObject (anAISObject);
57 //! aManipulator->EnableMode (AIS_Manipulator::Translation);
58 //! aManipulator->EnableMode (AIS_Manipulator::Rotation);
59 //! aManipulator->EnableMode (AIS_Manipulator::Scaling);
60 //! @endcode
61 //! Note that you can enable only one manipulation mode but have all visual parts displayed.
62 //! This code allows you to view manipulator and select its manipulation parts.
63 //! Note that manipulator activates mode on part selection.
64 //! If this mode is activated, no selection will be performed for manipulator.
65 //! It can be activated with highlighting. To enable this:
66 //! @code
67 //! aManipulator->SetModeActivationOnDetection (Standard_True);
68 //! @endcode
69 //! Step 2. To perform transformation of object use next code in your event processing chain:
70 //! @code
71 //! // catch mouse button down event
72 //! if (aManipulator->HasActiveMode())
73 //! {
74 //!   aManipulator->StartTransform (anXPix, anYPix, aV3dView);
75 //! }
76 //! ...
77 //! // or track mouse move event
78 //! if (aManipulator->HasActiveMode())
79 //! {
80 //!   aManipulator->Transform (anXPix, anYPix, aV3dView);
81 //!   aV3dView->Redraw();
82 //! }
83 //! ...
84 //! // or catch mouse button up event (apply) or escape event (cancel)
85 //! aManipulator->StopTransform(/*Standard_Boolean toApply*/);
86 //! @endcode
87 //! Step 3. To deactivate current manipulation mode use:
88 //! @code aManipulator->DeactivateCurrentMode();
89 //! @endcode
90 //! Step 4. To detach manipulator from object use:
91 //! @code
92 //! aManipulator->Detach();
93 //! @endcode
94 //! The last method erases manipulator object.
95 //! @warning
96 //! On construction an instance of AIS_Manipulator object is bound to Graphic3d_ZLayerId_Topmost layer,
97 //! so make sure to call for your AIS_InteractiveContext the method MainSelector()->SetPickClosest (Standard_False)
98 //! otherwise you may notice issues with activation of modes.
99 class AIS_Manipulator : public AIS_InteractiveObject
100 {
101 public:
102
103   //! Constructs a manipulator object with default placement and all parts to be displayed.
104   Standard_EXPORT AIS_Manipulator();
105
106   //! Constructs a manipulator object with input location and positions of axes and all parts to be displayed.
107   Standard_EXPORT AIS_Manipulator (const gp_Ax2& thePosition);
108
109   //! Destructor.
110   Standard_EXPORT virtual ~AIS_Manipulator() {}
111
112   //! Disable or enable visual parts for translation, rotation or scaling for some axis.
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 Standard_Integer theAxisIndex, 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
163   //! Init start (reference) transformation.
164   //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform
165   //! and is used only for custom transform set. If Transform(const Standard_Integer, const Standard_Integer) is used,
166   //! initial data is set automatically, and it is reset on DeactivateCurrentMode call if it is not reset yet.
167   Standard_EXPORT void StartTransform (const Standard_Integer theX, const Standard_Integer theY, const Handle(V3d_View)& theView);
168
169   //! Apply to the owning objects the input transformation.
170   //! @remark The transformation is set using SetLocalTransformation for owning objects.
171   //! The location of the manipulator is stored also in Local Transformation,
172   //! so that there's no need to redisplay objects.
173   //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform
174   //! and is used only for custom transform set.
175   //! @warning It will does nothing if transformation is not initiated (with StartTransform() call).
176   Standard_EXPORT void Transform (const gp_Trsf& aTrsf);
177
178   //! Reset start (reference) transformation.
179   //! @param theToApply [in] option to apply or to cancel the started transformation.
180   //! @warning It is used in chain with StartTransform-Transform(gp_Trsf)-StopTransform
181   //! and is used only for custom transform set.
182   Standard_EXPORT void StopTransform (const Standard_Boolean theToApply = Standard_True);
183
184   //! Apply transformation made from mouse moving from start position
185   //! (save on the first Tranform() call and reset on DeactivateCurrentMode() call.)
186   //! to the in/out mouse position (theX, theY)
187   Standard_EXPORT gp_Trsf Transform (const Standard_Integer theX, const Standard_Integer theY,
188                                      const Handle(V3d_View)& theView);
189
190   //! Computes transformation of parent object according to the active mode and input motion vector.
191   //! You can use this method to get object transformation according to current mode or use own algorithm
192   //! to implement any other tranformation for modes.
193   //! @return transformation of parent object.
194   Standard_EXPORT Standard_Boolean ObjectTransformation (const Standard_Integer theX, const Standard_Integer theY,
195                                                          const Handle(V3d_View)& theView, gp_Trsf& theTrsf);
196
197   //! Make inactive the current selected manipulator part and reset current axis index and current mode.
198   //! After its call HasActiveMode() returns false.
199   //! @sa HasActiveMode()
200   Standard_EXPORT void DeactivateCurrentMode();
201
202   //! Detaches himself from the owner object, and removes itself from context.
203   Standard_EXPORT void Detach();
204
205   //! @return all owning objects.
206   Standard_EXPORT Handle(AIS_ManipulatorObjectSequence) Objects() const;
207
208   //! @return the first (leading) object of the owning objects.
209   Standard_EXPORT Handle(AIS_InteractiveObject) Object() const;
210
211   //! @return one of the owning objects.
212   //! @warning raises program error if theIndex is more than owning objects count or less than 1.
213   Standard_EXPORT Handle(AIS_InteractiveObject) Object (const Standard_Integer theIndex) const;
214
215   //! @return true if manipulator is attached to some interactive object (has owning object).
216   Standard_Boolean IsAttached() const { return HasOwner(); }
217
218   //! @return true if some part of manipulator is selected (tranformation mode is active, and owning object can be rtansformated).
219   Standard_Boolean HasActiveMode() const { return IsAttached() && myCurrentMode != AIS_MM_None; }
220
221   Standard_Boolean HasActiveTransformation() { return myHasStartedTransformation; }
222
223   gp_Trsf StartTransformation() const { return myStartTrsfs.Size() < 1 ? gp_Trsf() : myStartTrsfs(1); }
224
225   gp_Trsf StartTransformation (const Standard_Integer theIndex) const
226   {
227     Standard_ProgramError_Raise_if (theIndex < 1 || theIndex > Objects()->Upper(),
228       "AIS_Manipulator::StartTransformation(): theIndex is out of bounds");
229     return myStartTrsfs.Size() < 1 ? gp_Trsf() : myStartTrsfs (theIndex);
230   }
231
232 public: //! @name Configuration of graphical transformations
233
234   //! Enable or disable zoom persistence mode for the manipulator. With
235   //! this mode turned on the presentation will keep fixed screen size.
236   //! @warning when turned on this option overrides transform persistence
237   //! properties and local transformation to achieve necessary visual effect.
238   //! @warning revise use of AdjustSize argument of of \sa AttachToObjects method
239   //! when enabling zoom persistence.
240   Standard_EXPORT void SetZoomPersistence (const Standard_Boolean theToEnable);
241
242   //! Returns state of zoom persistence mode, whether it turned on or off.
243   Standard_Boolean ZoomPersistence() const { return myIsZoomPersistentMode; }
244
245   //! Redefines transform persistence management to setup transformation for sub-presentation of axes.
246   //! @warning this interactive object does not support custom transformation persistence when
247   //! using \sa ZoomPersistence mode. In this mode the transformation persistence flags for
248   //! presentations are overriden by this class.
249   //! @warning Invokes debug assertion to catch incompatible usage of the method with \sa ZoomPersistence mode,
250   //! silently does nothing in release mode.
251   //! @warning revise use of AdjustSize argument of of \sa AttachToObjects method
252   //! when enabling zoom persistence.
253   Standard_EXPORT virtual void SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint) Standard_OVERRIDE;
254
255   //! Redefines local transformation management method to inform user of inproper use.
256   //! @warning this interactive object does not support setting custom local transformation,
257   //! this class solely uses this property to implement visual positioning of the manipulator
258   //! without need for recomputing presentation.
259   //! @warning Invokes debug assertion in debug to catch incompatible usage of the
260   //! method, silently does nothing in release mode.
261   Standard_EXPORT virtual void SetLocalTransformation (const gp_Trsf& theTransformation) Standard_OVERRIDE;
262
263 public: //! @name Setters for parameters
264
265   AIS_ManipulatorMode ActiveMode() const { return myCurrentMode; }
266
267   //! @return poition of manipulator interactive object.
268   const gp_Ax2& Position() const { return myPosition; }
269
270   //! Sets position of the manipulator object.
271   Standard_EXPORT void SetPosition (const gp_Ax2& thePosition);
272
273   Standard_ShortReal Size() const { return myAxes[0].Size(); }
274
275   //! Sets size (length of side of the manipulator cubic bounding box.
276   Standard_EXPORT void SetSize (const Standard_ShortReal theSideLength);
277
278   //! Sets gaps between translator, scaler and rotator sub-presentations.
279   Standard_EXPORT void SetGap (const Standard_ShortReal theValue);
280
281 public:
282
283   //! Behavior settings to be applied when performing transformation:
284   //! - FollowTranslation - whether the manipulator will be moved together with an object.
285   //! - FollowRotation - whether the manipulator will be rotated together with an object.
286   struct BehaviorOnTransform {
287
288     BehaviorOnTransform() : FollowTranslation (Standard_True), FollowRotation (Standard_True) {}
289     BehaviorOnTransform& SetFollowTranslation (const Standard_Boolean theApply) { FollowTranslation = theApply; return *this; }
290     BehaviorOnTransform& SetFollowRotation    (const Standard_Boolean theApply) { FollowRotation    = theApply; return *this; }
291
292     Standard_Boolean FollowTranslation;
293     Standard_Boolean FollowRotation;
294   };
295
296   //! Sets behavior settings for transformation action carried on the manipulator,
297   //! whether it translates, rotates together with the transformed object or not.
298   void SetTransformBehavior (const BehaviorOnTransform& theSettings) { myBehaviorOnTransform = theSettings; }
299
300   //! @return behavior settings for transformation action of the manipulator.
301   BehaviorOnTransform& ChangeTransformBehavior() { return myBehaviorOnTransform; }
302
303   //! @return behavior settings for transformation action of the manipulator.
304   const BehaviorOnTransform& TransformBehavior() const { return myBehaviorOnTransform; }
305
306 public: //! @name Presentation computation
307
308   //! Fills presentation.
309   //! @note Manipulator presentation does not use display mode and for all modes has the same presenatation.
310   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
311                                         const Handle(Prs3d_Presentation)& thePrs,
312                                         const Standard_Integer theMode = 0) Standard_OVERRIDE;
313
314   //! Computes selection sensitive zones (triangulation) for manipulator.
315   //! @param theNode [in] Seldction mode that is treated as transformation mode.
316   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
317                                                  const Standard_Integer theMode) Standard_OVERRIDE;
318
319   //! Disables auto highlighting to use HilightSelected() and HilightOwnerWithColor() overriden methods.
320   Standard_EXPORT virtual Standard_Boolean IsAutoHilight() const Standard_OVERRIDE
321   {
322     return Standard_False;
323   }
324
325   //! Method which clear all selected owners belonging
326   //! to this selectable object ( for fast presentation draw ).
327   Standard_EXPORT virtual void ClearSelected() Standard_OVERRIDE;
328
329   //! Method which draws selected owners ( for fast presentation draw ).
330   Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM, const SelectMgr_SequenceOfOwner& theSeq) Standard_OVERRIDE;
331
332   //! Method which hilight an owner belonging to
333   //! this selectable object  ( for fast presentation draw ).
334   Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
335
336 protected:
337
338   Standard_EXPORT void init();
339
340   Standard_EXPORT void updateTransformation();
341
342   Standard_EXPORT Handle(Prs3d_Presentation) getHighlightPresentation (const Handle(SelectMgr_EntityOwner)& theOwner) const;
343
344   Standard_EXPORT Handle(Graphic3d_Group) getGroup (const Standard_Integer theIndex, const AIS_ManipulatorMode theMode) const;
345
346   Standard_EXPORT void attachToBox (const Bnd_Box& theBox);
347
348   Standard_EXPORT void adjustSize (const Bnd_Box& theBox);
349
350   Standard_EXPORT void setTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint);
351
352 protected: //! @name Auxilliary classes to fill presentation with proper primitives
353
354   class Quadric
355   {
356   public:
357
358     virtual ~Quadric()
359     {
360       myTriangulation.Nullify();
361       myArray.Nullify();
362     }
363
364
365     const Handle(Poly_Triangulation)& Triangulation() const { return myTriangulation; }
366
367     const Handle(Graphic3d_ArrayOfTriangles)& Array() const { return myArray; }
368
369   protected:
370
371     Handle(Poly_Triangulation) myTriangulation;
372     Handle(Graphic3d_ArrayOfTriangles) myArray;
373   };
374
375   class Cylinder : public Quadric
376   {
377   public:
378
379     Cylinder()
380     : Quadric(),
381       myBottomRad(1.0f),
382       myTopRad(1.0f),
383       myHeight(1.0f)
384     { }
385
386     virtual ~Cylinder() {}
387
388     void Init (const Standard_ShortReal theBotRad, const Standard_ShortReal theTopRad,
389                const Standard_ShortReal theHeight,
390                const Standard_Integer theSlicesNb, const Standard_Integer theStacksNb,
391                const gp_Ax1& thePosition);
392
393   protected:
394
395     gp_Ax1 myPosition;
396     Standard_ShortReal myBottomRad;
397     Standard_ShortReal myTopRad;
398     Standard_ShortReal myHeight;
399   };
400
401   class Disk : public Quadric
402   {
403   public:
404
405     Disk()
406       : Quadric(),
407       myInnerRad(0.0f),
408       myOuterRad(1.0f)
409     { }
410
411     ~Disk() { }
412
413     void Init (const Standard_ShortReal theInnerRadius,
414                const Standard_ShortReal theOuterRadius,
415                const gp_Ax1& thePosition,
416                const Standard_Integer theSlicesNb = 20,
417                const Standard_Integer theStacksNb = 20);
418
419   protected:
420
421     gp_Ax1             myPosition;
422     Standard_ShortReal myInnerRad;
423     Standard_ShortReal myOuterRad;
424   };
425
426   class Sphere : public Quadric
427   {
428   public:
429     Sphere()
430       : Quadric(),
431       myRadius(1.0f)
432     {}
433
434     void Init (const Standard_ShortReal theRadius,
435                const gp_Pnt& thePosition,
436                const Standard_Integer theSlicesNb = 20,
437                const Standard_Integer theStacksNb = 20);
438
439   protected:
440
441     gp_Pnt myPosition;
442     Standard_ShortReal myRadius;
443   };
444
445   class Cube
446   {
447   public:
448
449     Cube() { }
450     ~Cube() { }
451
452     void Init (const gp_Ax1& thePosition, const Standard_ShortReal myBoxSize);
453
454     const Handle(Poly_Triangulation)& Triangulation() const { return myTriangulation; }
455
456     const Handle(Graphic3d_ArrayOfTriangles)& Array() const { return myArray; }
457
458   private:
459
460     void addTriangle (const Standard_Integer theIndex, const gp_Pnt& theP1, const gp_Pnt& theP2, const gp_Pnt& theP3,
461                       const gp_Dir& theNormal);
462
463   protected:
464
465     Handle(Poly_Triangulation) myTriangulation;
466     Handle(Graphic3d_ArrayOfTriangles) myArray;
467   };
468
469   //! The class describes on axis sub-object.
470   //! It includes sub-objects itself:
471   //! -rotator
472   //! -translator
473   //! -scaler
474   class Axis
475   {
476   public:
477
478     Axis (const gp_Ax1& theAxis              = gp_Ax1(),
479           const Quantity_Color& theColor     = Quantity_Color(),
480           const Standard_ShortReal theLength = 10.0f);
481
482     void Compute (const Handle_PrsMgr_PresentationManager3d& thePrsMgr,
483                   const Handle(Prs3d_Presentation)& thePrs,
484                   const Handle(Prs3d_ShadingAspect)& theAspect);
485
486     const gp_Ax1& ReferenceAxis() const { return myReferenceAxis; }
487
488     void SetPosition (const gp_Ax1& thePosition) { myPosition = thePosition; }
489
490     const gp_Ax1& Position() const { return myPosition; }
491
492     void SetTransformPersistence (const Graphic3d_TransModeFlags& theFlags, const gp_Pnt& thePoint)
493     {
494       if (!myHighlightTranslator.IsNull())
495       {
496         myHighlightTranslator->SetTransformPersistence (theFlags, thePoint);
497       }
498
499       if (!myHighlightScaler.IsNull())
500       {
501         myHighlightScaler->SetTransformPersistence (theFlags, thePoint);
502       }
503
504       if (!myHighlightRotator.IsNull())
505       {
506         myHighlightRotator->SetTransformPersistence (theFlags, thePoint);
507       }
508     }
509
510     Graphic3d_TransModeFlags GetTransformPersistenceMode() const { return myHighlightTranslator->TransformPersistenceMode(); }
511
512     gp_Pnt GetTransformPersistencePoint() const { return myHighlightTranslator->TransformPersistencePoint(); }
513
514     void Transform (const Handle(Geom_Transformation)& theTransformation)
515     {
516       if (!myHighlightTranslator.IsNull())
517       {
518         myHighlightTranslator->Transform (theTransformation);
519       }
520
521       if (!myHighlightScaler.IsNull())
522       {
523         myHighlightScaler->Transform (theTransformation);
524       }
525
526       if (!myHighlightRotator.IsNull())
527       {
528         myHighlightRotator->Transform (theTransformation);
529       }
530     }
531
532     Standard_Boolean HasTranslation() const { return myHasTranslation; }
533
534     Standard_Boolean HasRotation() const { return myHasRotation; }
535
536     Standard_Boolean HasScaling() const { return myHasScaling; }
537
538     void SetTranslation (const Standard_Boolean theIsEnabled) { myHasTranslation = theIsEnabled; }
539
540     void SetRotation (const Standard_Boolean theIsEnabled) { myHasRotation = theIsEnabled; }
541
542     void SetScaling (const Standard_Boolean theIsEnabled) { myHasScaling = theIsEnabled; }
543
544     Quantity_Color Color() const { return myColor; }
545
546     Standard_ShortReal AxisLength() const { return myLength; }
547
548     Standard_ShortReal AxisRadius() const { return myAxisRadius; }
549
550     void SetAxisRadius (const Standard_ShortReal theValue) { myAxisRadius = theValue; }
551
552     const Handle(Prs3d_Presentation)& TranslatorHighlightPrs() const { return myHighlightTranslator; }
553
554     const Handle(Prs3d_Presentation)& RotatorHighlightPrs() const { return myHighlightRotator; }
555
556     const Handle(Prs3d_Presentation)& ScalerHighlightPrs() const { return myHighlightScaler; }
557
558     const Handle(Graphic3d_Group)& TranslatorGroup() const { return myTranslatorGroup; }
559
560     const Handle(Graphic3d_Group)& RotatorGroup() const { return myRotatorGroup; }
561
562     const Handle(Graphic3d_Group)& ScalerGroup() const { return myScalerGroup; }
563
564     void SetIndent (const Standard_ShortReal theValue) { myIndent = theValue; }
565
566     Standard_ShortReal Size() const { return myLength + myBoxSize + myDiskThickness + myIndent * 2.0f; }
567
568     gp_Pnt ScalerCenter (const gp_Pnt& theLocation) const { return theLocation.XYZ() + myPosition.Direction().XYZ() * (myLength + myIndent + myBoxSize * 0.5f); }
569
570     void SetSize (const Standard_ShortReal theValue)
571     {
572       if (myIndent > theValue * 0.1f)
573       {
574         myLength = theValue * 0.7f;
575         myBoxSize = theValue * 0.15f;
576         myDiskThickness = theValue * 0.05f;
577         myIndent = theValue * 0.05f;
578       }
579       else // use pre-set value of predent
580       {
581         Standard_ShortReal aLength = theValue - 2 * myIndent;
582         myLength = aLength * 0.8f;
583         myBoxSize = aLength * 0.15f;
584         myDiskThickness = aLength * 0.05f;
585       }
586       myInnerRadius = myIndent * 2 + myBoxSize + myLength;
587       myAxisRadius = myBoxSize / 4.0f;
588     }
589
590     Standard_Integer FacettesNumber() const { return myFacettesNumber; }
591
592   public:
593
594     const Cylinder& TranslatorCylinder() const { return myCylinder; }
595     const Cylinder& TranslatorArrow() const { return myArrow; }
596     const gp_Pnt& TranslatorTipPosition() const { return myArrowTipPos; }
597     const Disk& TranslatorArrowBottom() const { return myArrowBottom; }
598     const Disk& RotatorDisk() const { return myCircle; }
599     float RotatorDiskRadius() const { return myCircleRadius; }
600     const Cube& ScalerCube() const { return myCube; }
601     const gp_Pnt& ScalerCubePosition() const { return myCubePos; }
602
603   protected:
604
605     gp_Ax1 myReferenceAxis; //!< Returns reference axis assignment.
606     gp_Ax1 myPosition; //!< Position of the axis including local transformation.
607     Quantity_Color myColor;
608
609     Standard_Boolean myHasTranslation;
610     Standard_ShortReal myLength; //!< Length of translation axis.
611     Standard_ShortReal myAxisRadius;
612
613     Standard_Boolean myHasScaling;
614     Standard_ShortReal myBoxSize; //!< Size of scaling cube.
615
616     Standard_Boolean myHasRotation;
617     Standard_ShortReal myInnerRadius; //!< Radius of rotation circle.
618     Standard_ShortReal myDiskThickness;
619     Standard_ShortReal myIndent; //!< Gap between visual part of the manipulator.
620
621   protected:
622
623     Standard_Integer myFacettesNumber;
624
625     Cylinder myCylinder;
626     Cylinder myArrow;
627     gp_Pnt   myArrowTipPos;
628     Disk     myArrowBottom;
629     Disk     myCircle;
630     float    myCircleRadius;
631     Cube     myCube;
632     gp_Pnt   myCubePos;
633
634     Handle(Graphic3d_Group) myTranslatorGroup;
635     Handle(Graphic3d_Group) myScalerGroup;
636     Handle(Graphic3d_Group) myRotatorGroup;
637
638     Handle(Prs3d_Presentation) myHighlightTranslator;
639     Handle(Prs3d_Presentation) myHighlightScaler;
640     Handle(Prs3d_Presentation) myHighlightRotator;
641   };
642
643 protected:
644
645   Axis myAxes[3]; //!< Tree axes of the manipulator.
646   Sphere myCenter; //!< Visual part displaying the center sphere of the manipulator.
647   gp_Ax2 myPosition; //!< Position of the manipualtor object. it displayes its location and position of its axes.
648
649   Standard_Integer myCurrentIndex; //!< Index of active axis.
650   AIS_ManipulatorMode myCurrentMode; //!< Name of active manipualtion mode.
651
652   Standard_Boolean myIsActivationOnDetection; //!< Manual activation of modes (not on parts selection).
653   Standard_Boolean myIsZoomPersistentMode; //!< Zoom persistence mode activation.
654   BehaviorOnTransform myBehaviorOnTransform; //!< Behavior settings applied on manipulator when transforming an object.
655
656 protected: //! @name Fields for interactive trnasformation. Fields only for internal needs. They do not have public interface.
657
658   NCollection_Sequence<gp_Trsf> myStartTrsfs; //!< Owning object transformation for start. It is used internally.
659   Standard_Boolean myHasStartedTransformation; //!< Shows if transformation is processed (sequential calls of Transform()).
660   gp_Ax2 myStartPosition; //! Start position of manipulator.
661   gp_Pnt myStartPick; //! 3d point corresponding to start mouse pick.
662   Standard_Real myPrevState; //! Previous value of angle during rotation.
663
664   //! Aspect used to colour current detected part and current selected part.
665   Handle(Prs3d_ShadingAspect) myHighlightAspect;
666 public:
667
668   DEFINE_STANDARD_RTTIEXT(AIS_Manipulator, AIS_InteractiveObject)
669 };
670 #endif // _AIS_Manipulator_HeaderFile