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