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