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