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