2108d9a2 |
1 | // Created on: 2017-07-25 |
2 | // Created by: Anastasia BOBYLEVA |
3 | // Copyright (c) 2017-2019 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_ViewCube_HeaderFile |
17 | #define _AIS_ViewCube_HeaderFile |
18 | |
19 | #include <AIS_InteractiveObject.hxx> |
20 | #include <Graphic3d_Camera.hxx> |
21 | #include <Graphic3d_Vec2.hxx> |
22 | #include <Prs3d_DatumParts.hxx> |
23 | #include <Prs3d_ShadingAspect.hxx> |
24 | #include <Prs3d_TextAspect.hxx> |
25 | #include <SelectMgr_EntityOwner.hxx> |
26 | #include <V3d_TypeOfOrientation.hxx> |
27 | |
28 | class AIS_AnimationCamera; |
29 | class AIS_ViewCubeOwner; |
30 | class Graphic3d_ArrayOfTriangles; |
caa309aa |
31 | class V3d_View; |
2108d9a2 |
32 | |
33 | //! Interactive object for displaying the view manipulation cube. |
34 | //! |
35 | //! View cube consists of several parts that are responsible for different camera manipulations: |
36 | //! @li Cube sides represent main views: top, bottom, left, right, front and back. |
37 | //! @li Edges represent rotation of one of main views on 45 degrees. |
38 | //! @li Vertices represent rotation of one of man views in two directions. |
39 | //! |
40 | //! The object is expected to behave like a trihedron in the view corner, |
41 | //! therefore its position should be defined using transformation persistence flags: |
42 | //! @code SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER, Graphic3d_Vec2i (100, 100)); @endcode |
43 | //! |
44 | //! View Cube parts are sensitive to detection, or dynamic highlighting (but not selection), |
45 | //! and every its owner AIS_ViewCubeOwner corresponds to camera transformation. |
46 | //! @code |
47 | //! for (aViewCube->StartAnimation (aDetectedOwner); aViewCube->HasAnimation(); ) |
48 | //! { |
49 | //! aViewCube->UpdateAnimation(); |
50 | //! ... // updating of application window |
51 | //! } |
52 | //! @endcode |
53 | //! or |
54 | //! @code aViewCube->HandleClick (aDetectedOwner); @endcode |
55 | //! that includes transformation loop. |
56 | //! This loop allows external actions like application updating. For this purpose AIS_ViewCube has virtual interface onAfterAnimation(), |
57 | //! that is to be redefined on application level. |
58 | class AIS_ViewCube : public AIS_InteractiveObject |
59 | { |
60 | DEFINE_STANDARD_RTTIEXT(AIS_ViewCube, AIS_InteractiveObject) |
61 | public: |
62 | |
63 | //! Return TRUE if specified orientation belongs to box side. |
64 | Standard_EXPORT static bool IsBoxSide (V3d_TypeOfOrientation theOrient); |
65 | |
66 | //! Return TRUE if specified orientation belongs to box edge. |
67 | Standard_EXPORT static bool IsBoxEdge (V3d_TypeOfOrientation theOrient); |
68 | |
69 | //! Return TRUE if specified orientation belongs to box corner (vertex). |
70 | Standard_EXPORT static bool IsBoxCorner (V3d_TypeOfOrientation theOrient); |
71 | |
72 | public: |
73 | |
74 | //! Empty constructor. |
75 | Standard_EXPORT AIS_ViewCube(); |
76 | |
77 | //! Return view animation. |
78 | const Handle(AIS_AnimationCamera)& ViewAnimation() const { return myViewAnimation; } |
79 | |
80 | //! Set view animation. |
81 | void SetViewAnimation (const Handle(AIS_AnimationCamera)& theAnimation) { myViewAnimation = theAnimation; } |
82 | |
83 | //! Return TRUE if automatic camera transformation on selection (highlighting) is enabled; TRUE by default. |
84 | Standard_Boolean ToAutoStartAnimation() const { return myToAutoStartAnim; } |
85 | |
86 | //! Enable/disable automatic camera transformation on selection (highlighting). |
87 | //! The automatic logic can be disabled if application wants performing action manually |
88 | //! basing on picking results (AIS_ViewCubeOwner). |
89 | void SetAutoStartAnimation (bool theToEnable) { myToAutoStartAnim = theToEnable; } |
90 | |
91 | //! Return TRUE if camera animation should be done in uninterruptible loop; TRUE by default. |
92 | Standard_Boolean IsFixedAnimationLoop() const { return myIsFixedAnimation; } |
93 | |
94 | //! Set if camera animation should be done in uninterruptible loop. |
95 | void SetFixedAnimationLoop (bool theToEnable) { myIsFixedAnimation = theToEnable; } |
96 | |
97 | //! Reset all size and style parameters to default. |
98 | //! @warning It doesn't reset position of View Cube |
99 | Standard_EXPORT void ResetStyles(); |
100 | |
101 | protected: |
102 | |
103 | //! Set default visual attributes |
104 | Standard_EXPORT void setDefaultAttributes(); |
105 | |
106 | //! Set default dynamic highlight properties |
107 | Standard_EXPORT void setDefaultHighlightAttributes(); |
108 | |
109 | public: //! @name Geometry management API |
110 | |
111 | //! @return size (width and height) of View cube sides; 100 by default. |
112 | Standard_Real Size() const { return mySize; } |
113 | |
114 | //! Sets size (width and height) of View cube sides. |
115 | //! @param theToAdaptAnother if TRUE, then other parameters will be adapted to specified size |
116 | Standard_EXPORT void SetSize (Standard_Real theValue, |
117 | Standard_Boolean theToAdaptAnother = true); |
118 | |
119 | //! Return box facet extension to edge/corner facet split; 10 by default. |
120 | Standard_Real BoxFacetExtension() const { return myBoxFacetExtension; } |
121 | |
122 | //! Set new value of box facet extension. |
123 | void SetBoxFacetExtension (Standard_Real theValue) |
124 | { |
125 | if (Abs (myBoxFacetExtension - theValue) > Precision::Confusion()) |
126 | { |
127 | myBoxFacetExtension = theValue; |
128 | SetToUpdate(); |
129 | } |
130 | } |
131 | |
132 | //! Return padding between axes and 3D part (box); 10 by default. |
133 | Standard_Real AxesPadding() const { return myAxesPadding; } |
134 | |
135 | //! Set new value of padding between axes and 3D part (box). |
136 | void SetAxesPadding (Standard_Real theValue) |
137 | { |
138 | if (Abs (myAxesPadding - theValue) > Precision::Confusion()) |
139 | { |
140 | myAxesPadding = theValue; |
141 | SetToUpdate(); |
142 | } |
143 | } |
144 | |
145 | //! Return gap between box edges and box sides; 0 by default. |
146 | Standard_Real BoxEdgeGap() const { return myBoxEdgeGap; } |
147 | |
148 | //! Set new value of box edges gap. |
149 | void SetBoxEdgeGap (Standard_Real theValue) |
150 | { |
151 | if (Abs (myBoxEdgeGap - theValue) > Precision::Confusion()) |
152 | { |
153 | myBoxEdgeGap = theValue; |
154 | SetToUpdate(); |
155 | } |
156 | } |
157 | |
158 | //! Return minimal size of box edge; 2 by default. |
159 | Standard_Real BoxEdgeMinSize() const { return myBoxEdgeMinSize; } |
160 | |
161 | //! Set new value of box edge minimal size. |
162 | void SetBoxEdgeMinSize (Standard_Real theValue) |
163 | { |
164 | if (Abs (myBoxEdgeMinSize - theValue) > Precision::Confusion()) |
165 | { |
166 | myBoxEdgeMinSize = theValue; |
167 | SetToUpdate(); |
168 | } |
169 | } |
170 | |
171 | //! Return minimal size of box corner; 2 by default. |
172 | Standard_Real BoxCornerMinSize() const { return myCornerMinSize; } |
173 | |
174 | //! Set new value of box corner minimal size. |
175 | void SetBoxCornerMinSize (Standard_Real theValue) |
176 | { |
177 | if (Abs (myCornerMinSize - theValue) > Precision::Confusion()) |
178 | { |
179 | myCornerMinSize = theValue; |
180 | SetToUpdate(); |
181 | } |
182 | } |
183 | |
184 | //! Return relative radius of side corners (round rectangle); 0.0 by default. |
185 | //! The value in within [0, 0.5] range meaning absolute radius = RoundRadius() / Size(). |
186 | Standard_Real RoundRadius() const { return myRoundRadius; } |
187 | |
188 | //! Set relative radius of View Cube sides corners (round rectangle). |
189 | //! The value should be within [0, 0.5] range. |
190 | Standard_EXPORT void SetRoundRadius (const Standard_Real theValue); |
191 | |
192 | //! @return TRUE if trihedron is drawn; TRUE by default. |
193 | Standard_Boolean ToDrawAxes() const { return myToDisplayAxes; } |
194 | |
195 | //! Enable/disable drawing of trihedron. |
196 | void SetDrawAxes (Standard_Boolean theValue) |
197 | { |
198 | if (myToDisplayAxes != theValue) |
199 | { |
200 | myToDisplayAxes = theValue; |
201 | SetToUpdate(); |
202 | } |
203 | } |
204 | |
205 | //! @return TRUE if edges of View Cube is drawn; TRUE by default. |
206 | Standard_Boolean ToDrawEdges() const { return myToDisplayEdges; } |
207 | |
208 | //! Enable/disable drawing of edges of View Cube. |
209 | void SetDrawEdges (Standard_Boolean theValue) |
210 | { |
211 | if (myToDisplayEdges != theValue) |
212 | { |
213 | myToDisplayEdges = theValue; |
214 | SetToUpdate(); |
215 | } |
216 | } |
217 | |
218 | //! Return TRUE if vertices (vertex) of View Cube is drawn; TRUE by default. |
219 | Standard_Boolean ToDrawVertices() const { return myToDisplayVertices; } |
220 | |
221 | //! Enable/disable drawing of vertices (corners) of View Cube. |
222 | void SetDrawVertices (Standard_Boolean theValue) |
223 | { |
224 | if (myToDisplayVertices != theValue) |
225 | { |
226 | myToDisplayVertices = theValue; |
227 | SetToUpdate(); |
228 | } |
229 | } |
230 | |
231 | //! Return TRUE if application expects Y-up viewer orientation instead of Z-up; FALSE by default. |
232 | Standard_Boolean IsYup() const { return myIsYup; } |
233 | |
234 | //! Set if application expects Y-up viewer orientation instead of Z-up. |
235 | Standard_EXPORT void SetYup (Standard_Boolean theIsYup, |
236 | Standard_Boolean theToUpdateLabels = Standard_True); |
237 | |
238 | public: //! @name Style management API |
239 | |
240 | //! Return shading style of box sides. |
241 | const Handle(Prs3d_ShadingAspect)& BoxSideStyle() const { return myDrawer->ShadingAspect(); } |
242 | |
243 | //! Return shading style of box edges. |
244 | const Handle(Prs3d_ShadingAspect)& BoxEdgeStyle() const { return myBoxEdgeAspect; } |
245 | |
246 | //! Return shading style of box corners. |
247 | const Handle(Prs3d_ShadingAspect)& BoxCornerStyle() const { return myBoxCornerAspect; } |
248 | |
249 | //! Return value of front color for the 3D part of object. |
250 | const Quantity_Color& BoxColor() const { return myDrawer->ShadingAspect()->Color(); } |
251 | |
252 | //! Set new value of front color for the 3D part of object. |
253 | //! @param theColor [in] input color value. |
254 | void SetBoxColor (const Quantity_Color& theColor) |
255 | { |
256 | if (!myDrawer->ShadingAspect()->Color().IsEqual (theColor) |
257 | || !myBoxEdgeAspect ->Color().IsEqual (theColor) |
258 | || !myBoxCornerAspect->Color().IsEqual (theColor)) |
259 | { |
260 | myDrawer->ShadingAspect()->SetColor (theColor); |
261 | myBoxEdgeAspect->SetColor (theColor); |
262 | myBoxCornerAspect->SetColor (theColor); |
263 | SynchronizeAspects(); |
264 | } |
265 | } |
266 | |
267 | //! Return transparency for 3D part of object. |
268 | Standard_Real BoxTransparency() const { return myDrawer->ShadingAspect()->Transparency(); } |
269 | |
270 | //! Set new value of transparency for 3D part of object. |
271 | //! @param theValue [in] input transparency value |
272 | void SetBoxTransparency (Standard_Real theValue) |
273 | { |
274 | if (Abs (myDrawer->ShadingAspect()->Transparency() - theValue) > Precision::Confusion() |
275 | || Abs (myBoxEdgeAspect ->Transparency() - theValue) > Precision::Confusion() |
276 | || Abs (myBoxCornerAspect->Transparency() - theValue) > Precision::Confusion()) |
277 | { |
278 | myDrawer->ShadingAspect()->SetTransparency (theValue); |
279 | myBoxEdgeAspect->SetTransparency (theValue); |
280 | myBoxCornerAspect->SetTransparency (theValue); |
281 | SynchronizeAspects(); |
282 | } |
283 | } |
284 | |
285 | //! Return color of sides back material. |
286 | const Quantity_Color& InnerColor() const { return myDrawer->ShadingAspect()->Color (Aspect_TOFM_BACK_SIDE); } |
287 | |
288 | //! Set color of sides back material. Alias for: |
289 | //! @code Attributes()->ShadingAspect()->Aspect()->ChangeBackMaterial().SetColor() @endcode |
290 | void SetInnerColor (const Quantity_Color& theColor) |
291 | { |
292 | myDrawer->ShadingAspect()->SetColor (theColor, Aspect_TOFM_BACK_SIDE); |
293 | SynchronizeAspects(); |
294 | } |
295 | |
296 | //! Return box side label or empty string if undefined. |
297 | //! Default labels: FRONT, BACK, LEFT, RIGHT, TOP, BOTTOM. |
298 | TCollection_AsciiString BoxSideLabel (V3d_TypeOfOrientation theSide) const |
299 | { |
300 | const TCollection_AsciiString* aLabel = myBoxSideLabels.Seek (theSide); |
301 | return aLabel != NULL ? *aLabel : TCollection_AsciiString(); |
302 | } |
303 | |
304 | //! Set box side label. |
305 | void SetBoxSideLabel (const V3d_TypeOfOrientation theSide, |
306 | const TCollection_AsciiString& theLabel) |
307 | { |
308 | if (!IsBoxSide (theSide)) |
309 | { |
310 | throw Standard_ProgramError ("AIS_ViewCube::SetBoxSideLabel(), invalid enumeration value"); |
311 | } |
312 | myBoxSideLabels.Bind (theSide, theLabel); |
313 | SetToUpdate(); |
314 | } |
315 | |
316 | //! Return text color of labels of box sides; BLACK by default. |
317 | const Quantity_Color& TextColor() const { return myDrawer->TextAspect()->Aspect()->Color(); } |
318 | |
319 | //! Set color of text labels on box sides. Alias for: |
320 | //! @code Attributes()->TextAspect()->SetColor() @endcode |
321 | void SetTextColor (const Quantity_Color& theColor) |
322 | { |
323 | myDrawer->TextAspect()->SetColor (theColor); |
324 | SynchronizeAspects(); |
325 | } |
326 | |
327 | //! Return font name that is used for displaying of sides and axes text. Alias for: |
328 | //! @code Attributes()->TextAspect()->Aspect()->SetFont() @endcode |
329 | const TCollection_AsciiString& Font() const { return myDrawer->TextAspect()->Aspect()->Font(); } |
330 | |
331 | //! Set font name that is used for displaying of sides and axes text. Alias for: |
332 | //! @code Attributes()->TextAspect()->SetFont() @endcode |
333 | void SetFont (const TCollection_AsciiString& theFont) |
334 | { |
335 | myDrawer->TextAspect()->Aspect()->SetFont (theFont); |
336 | SynchronizeAspects(); |
337 | } |
338 | |
339 | //! Return height of font |
340 | Standard_Real FontHeight() const { return myDrawer->TextAspect()->Height(); } |
341 | |
342 | //! Change font height. Alias for: |
343 | //! @code Attributes()->TextAspect()->SetHeight() @endcode |
344 | void SetFontHeight (Standard_Real theValue) |
345 | { |
346 | if (Abs (myDrawer->TextAspect()->Height() - theValue) > Precision::Confusion()) |
347 | { |
348 | myDrawer->TextAspect()->SetHeight (theValue); |
349 | SetToUpdate(); |
350 | } |
351 | } |
352 | |
353 | //! Return axes labels or empty string if undefined. |
354 | //! Default labels: X, Y, Z. |
355 | TCollection_AsciiString AxisLabel (Prs3d_DatumParts theAxis) const |
356 | { |
357 | const TCollection_AsciiString* aLabel = myAxesLabels.Seek (theAxis); |
358 | return aLabel != NULL ? *aLabel : TCollection_AsciiString(); |
359 | } |
360 | |
361 | //! Set axes labels. |
362 | void SetAxesLabels (const TCollection_AsciiString& theX, |
363 | const TCollection_AsciiString& theY, |
364 | const TCollection_AsciiString& theZ) |
365 | { |
366 | myAxesLabels.Bind (Prs3d_DP_XAxis, theX); |
367 | myAxesLabels.Bind (Prs3d_DP_YAxis, theY); |
368 | myAxesLabels.Bind (Prs3d_DP_ZAxis, theZ); |
369 | SetToUpdate(); |
370 | } |
371 | |
372 | public: |
373 | |
374 | //! Set new value of color for the whole object. |
375 | //! @param theColor [in] input color value. |
376 | virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE |
377 | { |
378 | SetBoxColor (theColor); |
379 | } |
380 | |
381 | //! Reset color for the whole object. |
382 | virtual void UnsetColor() Standard_OVERRIDE |
383 | { |
384 | myDrawer->ShadingAspect()->SetColor (Quantity_NOC_WHITE); |
385 | myBoxEdgeAspect ->SetColor (Quantity_NOC_GRAY30); |
386 | myBoxCornerAspect->SetColor (Quantity_NOC_GRAY30); |
387 | SynchronizeAspects(); |
388 | } |
389 | |
390 | //! Set new value of transparency for the whole object. |
391 | //! @param theValue [in] input transparency value. |
392 | virtual void SetTransparency (const Standard_Real theValue) Standard_OVERRIDE |
393 | { |
394 | SetBoxTransparency (theValue); |
395 | } |
396 | |
397 | //! Reset transparency for the whole object. |
398 | virtual void UnsetTransparency() Standard_OVERRIDE |
399 | { |
400 | SetBoxTransparency (0.0f); |
401 | } |
402 | |
403 | //! Sets the material for the interactive object. |
404 | virtual void SetMaterial (const Graphic3d_MaterialAspect& theMat) Standard_OVERRIDE |
405 | { |
406 | myDrawer->ShadingAspect()->SetMaterial (theMat); |
407 | myBoxEdgeAspect ->SetMaterial (theMat); |
408 | myBoxCornerAspect->SetMaterial (theMat); |
409 | SynchronizeAspects(); |
410 | } |
411 | |
412 | //! Sets the material for the interactive object. |
413 | virtual void UnsetMaterial() Standard_OVERRIDE |
414 | { |
415 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_UserDefined); |
416 | aMat.SetColor (Quantity_NOC_WHITE); |
417 | aMat.SetAmbientColor (Quantity_NOC_GRAY60); |
418 | myDrawer->ShadingAspect()->SetMaterial (aMat); |
419 | myBoxEdgeAspect ->SetMaterial (aMat); |
420 | myBoxEdgeAspect ->SetColor (Quantity_NOC_GRAY30); |
421 | myBoxCornerAspect->SetMaterial (aMat); |
422 | myBoxCornerAspect->SetColor (Quantity_NOC_GRAY30); |
423 | SynchronizeAspects(); |
424 | } |
425 | |
426 | public: //! @name animation methods |
427 | |
428 | //! Return duration of animation in seconds; 0.5 sec by default |
429 | Standard_Real Duration() const { return myDuration; } |
430 | |
431 | //! Set duration of animation. |
432 | //! @param theValue [in] input value of duration in seconds |
433 | void SetDuration (Standard_Real theValue) { myDuration = theValue; } |
434 | |
435 | //! Return TRUE if new camera Up direction should be always set to default value for a new camera Direction; FALSE by default. |
436 | //! When this flag is FALSE, the new camera Up will be set as current Up orthogonalized to the new camera Direction, |
437 | //! and will set to default Up on second click. |
438 | Standard_Boolean ToResetCameraUp() const { return myToResetCameraUp; } |
439 | |
440 | //! Set if new camera Up direction should be always set to default value for a new camera Direction. |
441 | void SetResetCamera (Standard_Boolean theToReset) { myToResetCameraUp = theToReset; } |
442 | |
443 | //! Return TRUE if animation should fit selected objects and FALSE to fit entire scene; TRUE by default. |
444 | Standard_Boolean ToFitSelected() const { return myToFitSelected; } |
445 | |
446 | //! Set if animation should fit selected objects or to fit entire scene. |
447 | void SetFitSelected (Standard_Boolean theToFitSelected) { myToFitSelected = theToFitSelected; } |
448 | |
449 | //! @return TRUE if View Cube has unfinished animation of view camera. |
450 | Standard_EXPORT Standard_Boolean HasAnimation() const; |
451 | |
452 | //! Start camera transformation corresponding to the input detected owner. |
453 | //! @param theOwner [in] detected owner. |
454 | Standard_EXPORT virtual void StartAnimation (const Handle(AIS_ViewCubeOwner)& theOwner); |
455 | |
456 | //! Perform one step of current camera transformation. |
457 | //! theToUpdate [in] enable/disable update of view. |
458 | //! @return TRUE if animation is not stopped. |
459 | Standard_EXPORT virtual Standard_Boolean UpdateAnimation (const Standard_Boolean theToUpdate); |
460 | |
461 | //! Perform camera transformation corresponding to the input detected owner. |
462 | Standard_EXPORT virtual void HandleClick (const Handle(AIS_ViewCubeOwner)& theOwner); |
463 | |
464 | protected: |
465 | |
466 | //! Perform internal single step of animation. |
467 | //! @return FALSE if animation has been finished |
468 | Standard_EXPORT Standard_Boolean updateAnimation(); |
469 | |
caa309aa |
470 | //! Fit selected/all into view. |
471 | //! @param theView [in] view definition to retrieve scene bounding box |
472 | //! @param theCamera [in,out] camera definition |
473 | Standard_EXPORT virtual void viewFitAll (const Handle(V3d_View)& theView, |
474 | const Handle(Graphic3d_Camera)& theCamera); |
475 | |
2108d9a2 |
476 | protected: //! @name protected virtual API |
477 | |
478 | //! Method that is called after one step of transformation. |
479 | virtual void onAfterAnimation() {} |
480 | |
481 | //! Method that is called after transformation finish. |
482 | virtual void onAnimationFinished() {} |
483 | |
484 | public: //! @name Presentation computation |
485 | |
486 | //! Return TRUE for supported display mode. |
487 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; } |
488 | |
489 | //! Global selection has no meaning for this class. |
490 | virtual Handle(SelectMgr_EntityOwner) GlobalSelOwner() const Standard_OVERRIDE { return Handle(SelectMgr_EntityOwner)(); } |
491 | |
492 | //! Compute 3D part of View Cube. |
493 | //! @param thePrsMgr [in] presentation manager. |
494 | //! @param thePrs [in] input presentation that is to be filled with flat presentation primitives. |
495 | //! @param theMode [in] display mode. |
496 | //! @warning this object accept only 0 display mode. |
497 | Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
498 | const Handle(Prs3d_Presentation)& thePrs, |
499 | const Standard_Integer theMode = 0) Standard_OVERRIDE; |
500 | |
501 | //! Redefine computing of sensitive entities for View Cube. |
502 | //! @param theSelection [in] input selection object that is to be filled with sensitive entities. |
503 | //! @param theMode [in] selection mode. |
504 | //! @warning object accepts only 0 selection mode. |
505 | Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
506 | const Standard_Integer theMode) Standard_OVERRIDE; |
507 | |
508 | //! Disables auto highlighting to use HilightSelected() and HilightOwnerWithColor() overridden methods. |
509 | virtual Standard_Boolean IsAutoHilight() const Standard_OVERRIDE { return Standard_False; } |
510 | |
511 | //! Method which clear all selected owners belonging to this selectable object. |
512 | //! @warning this object does not support selection. |
513 | virtual void ClearSelected() Standard_OVERRIDE {} |
514 | |
515 | //! Method which highlights input owner belonging to this selectable object. |
516 | //! @param thePM [in] presentation manager |
517 | //! @param theStyle [in] style for dynamic highlighting. |
518 | //! @param theOwner [in] input entity owner. |
519 | Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, |
520 | const Handle(Prs3d_Drawer)& theStyle, |
521 | const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE; |
522 | |
523 | //! Method which draws selected owners. |
524 | Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM, |
525 | const SelectMgr_SequenceOfOwner& theSeq) Standard_OVERRIDE; |
526 | |
527 | //! Set default parameters for visual attributes |
528 | //! @sa Attributes() |
529 | virtual void UnsetAttributes() Standard_OVERRIDE |
530 | { |
531 | setDefaultAttributes(); |
532 | SetToUpdate(); |
533 | } |
534 | |
535 | //! Set default parameters for dynamic highlighting attributes, reset highlight attributes |
536 | virtual void UnsetHilightAttributes() Standard_OVERRIDE |
537 | { |
538 | myHilightDrawer.Nullify(); |
539 | setDefaultHighlightAttributes(); |
540 | SetToUpdate(); |
541 | } |
542 | |
543 | protected: //! @name Auxiliary classes to fill presentation with proper primitives |
544 | |
545 | //! Create triangulation for a box part - for presentation and selection purposes. |
caa309aa |
546 | //! @param theTris [in,out] triangulation to fill, or NULL to return size |
547 | //! @param theNbNodes [in,out] should be incremented by a number of nodes defining this triangulation |
548 | //! @param theNbTris [in,out] should be incremented by a number of triangles defining this triangulation |
549 | //! @param theDir [in] part to define |
550 | Standard_EXPORT virtual void createBoxPartTriangles (const Handle(Graphic3d_ArrayOfTriangles)& theTris, |
551 | Standard_Integer& theNbNodes, |
552 | Standard_Integer& theNbTris, |
553 | V3d_TypeOfOrientation theDir) const; |
2108d9a2 |
554 | |
555 | //! Create triangulation for a box side. |
caa309aa |
556 | //! @param theTris [in,out] triangulation to fill, or NULL to return size |
557 | //! @param theNbNodes [in,out] should be incremented by a number of nodes defining this triangulation |
558 | //! @param theNbTris [in,out] should be incremented by a number of triangles defining this triangulation |
559 | //! @param theDir [in] part to define |
560 | Standard_EXPORT virtual void createBoxSideTriangles (const Handle(Graphic3d_ArrayOfTriangles)& theTris, |
561 | Standard_Integer& theNbNodes, |
562 | Standard_Integer& theNbTris, |
563 | V3d_TypeOfOrientation theDir) const; |
2108d9a2 |
564 | |
565 | //! Create triangulation for a box edge. |
caa309aa |
566 | //! @param theTris [in,out] triangulation to fill, or NULL to return size |
567 | //! @param theNbNodes [in,out] should be incremented by a number of nodes defining this triangulation |
568 | //! @param theNbTris [in,out] should be incremented by a number of triangles defining this triangulation |
569 | //! @param theDir [in] part to define |
570 | Standard_EXPORT virtual void createBoxEdgeTriangles (const Handle(Graphic3d_ArrayOfTriangles)& theTris, |
571 | Standard_Integer& theNbNodes, |
572 | Standard_Integer& theNbTris, |
573 | V3d_TypeOfOrientation theDir) const; |
2108d9a2 |
574 | |
575 | //! Create triangulation for a box corner (vertex). |
caa309aa |
576 | //! @param theTris [in,out] triangulation to fill, or NULL to return size |
577 | //! @param theNbNodes [in,out] should be incremented by a number of nodes defining this triangulation |
578 | //! @param theNbTris [in,out] should be incremented by a number of triangles defining this triangulation |
579 | //! @param theDir [in] part to define |
580 | Standard_EXPORT virtual void createBoxCornerTriangles (const Handle(Graphic3d_ArrayOfTriangles)& theTris, |
581 | Standard_Integer& theNbNodes, |
582 | Standard_Integer& theNbTris, |
583 | V3d_TypeOfOrientation theDir) const; |
2108d9a2 |
584 | |
585 | protected: |
586 | |
587 | //! Create triangulation for a rectangle with round corners. |
caa309aa |
588 | //! @param theTris [in,out] triangulation to fill, or NULL to return size |
589 | //! @param theNbNodes [in,out] should be incremented by a number of nodes defining this triangulation |
590 | //! @param theNbTris [in,out] should be incremented by a number of triangles defining this triangulation |
591 | //! @param theSize [in] rectangle dimensions |
592 | //! @param theRadius [in] radius at corners |
593 | //! @param theTrsf [in] transformation |
594 | Standard_EXPORT static void createRoundRectangleTriangles (const Handle(Graphic3d_ArrayOfTriangles)& theTris, |
595 | Standard_Integer& theNbNodes, |
596 | Standard_Integer& theNbTris, |
597 | const gp_XY& theSize, |
598 | Standard_Real theRadius, |
599 | const gp_Trsf& theTrsf); |
2108d9a2 |
600 | |
601 | protected: |
602 | |
603 | //! Trivial hasher to avoid ambiguity with enumeration type. |
604 | struct IntegerHasher |
605 | { |
606 | static Standard_Integer HashCode (Standard_Integer theValue, Standard_Integer theUpper) { return ::HashCode (theValue, theUpper); } |
607 | static Standard_Boolean IsEqual (Standard_Integer theA, Standard_Integer theB) { return theA == theB; } |
608 | }; |
609 | |
610 | protected: |
611 | |
612 | NCollection_DataMap<V3d_TypeOfOrientation, TCollection_AsciiString, IntegerHasher> |
613 | myBoxSideLabels; //!< map with box side labels |
614 | NCollection_DataMap<Prs3d_DatumParts, TCollection_AsciiString, IntegerHasher> |
615 | myAxesLabels; //!< map with axes labels |
616 | Handle(Prs3d_ShadingAspect) myBoxEdgeAspect; //!< style for box edges |
617 | Handle(Prs3d_ShadingAspect) myBoxCornerAspect; //!< style for box corner |
618 | |
619 | Standard_Real mySize; //!< size of box side, length of one axis |
620 | Standard_Real myBoxEdgeMinSize; //!< minimal size of box edge |
621 | Standard_Real myBoxEdgeGap; //!< gap between box side and box edge |
622 | Standard_Real myBoxFacetExtension; //!< box facet extension |
623 | Standard_Real myAxesPadding; //!< Padding between box and axes |
624 | Standard_Real myCornerMinSize; //!< minimal size of box corner |
625 | Standard_Real myRoundRadius; //!< relative round radius within [0; 0.5] range |
626 | Standard_Boolean myToDisplayAxes; //!< trihedron visibility |
627 | Standard_Boolean myToDisplayEdges; //!< box edges visibility |
628 | Standard_Boolean myToDisplayVertices; //!< box corners (vertices) visibility |
629 | Standard_Boolean myIsYup; //!< flag indicating that application expects Y-up viewer orientation instead of Z-up |
630 | |
631 | protected: //! @name Animation options |
632 | |
633 | Handle(AIS_AnimationCamera) myViewAnimation; //!< Camera animation object |
634 | Handle(Graphic3d_Camera) myStartState; //!< Start state of view camera |
635 | Handle(Graphic3d_Camera) myEndState; //!< End state of view camera |
636 | Standard_Real myDuration; //!< Duration of animation. By default it is half a second |
637 | Standard_Boolean myToAutoStartAnim; //!< start animation automatically on click |
638 | Standard_Boolean myIsFixedAnimation; //!< fixed-loop animation |
639 | Standard_Boolean myToFitSelected; //!< fit selected or fit entire scene |
640 | Standard_Boolean myToResetCameraUp; //!< always reset camera up direction to default |
641 | |
642 | }; |
643 | |
644 | //! Redefined entity owner that is highlighted when owner is detected, |
645 | //! even if Interactive Context highlighted on last detection procedure. |
646 | class AIS_ViewCubeOwner : public SelectMgr_EntityOwner |
647 | { |
648 | DEFINE_STANDARD_RTTIEXT(AIS_ViewCubeOwner, SelectMgr_EntityOwner) |
649 | public: |
650 | |
651 | //! Main constructor. |
652 | AIS_ViewCubeOwner (const Handle(AIS_ViewCube)& theObject, |
653 | V3d_TypeOfOrientation theOrient, |
654 | Standard_Integer thePriority = 5) |
655 | : SelectMgr_EntityOwner ((const Handle(SelectMgr_SelectableObject)& )theObject, thePriority), |
656 | myMainOrient (theOrient) |
657 | { |
658 | myFromDecomposition = true; |
659 | } |
660 | |
661 | //! @return TRUE. This owner will always call method |
662 | //! Hilight for its Selectable Object when the owner is detected. |
663 | virtual Standard_Boolean IsForcedHilight() const Standard_OVERRIDE { return Standard_True; } |
664 | |
665 | //! Return new orientation to set. |
666 | V3d_TypeOfOrientation MainOrientation() const { return myMainOrient; } |
667 | |
668 | //! Handle mouse button click event. |
669 | virtual Standard_Boolean HandleMouseClick (const Graphic3d_Vec2i& thePoint, |
670 | Aspect_VKeyMouse theButton, |
671 | Aspect_VKeyFlags theModifiers, |
672 | bool theIsDoubleClick) Standard_OVERRIDE |
673 | { |
674 | (void )thePoint; (void )theButton; (void )theModifiers; (void )theIsDoubleClick; |
675 | AIS_ViewCube* aCubePrs = dynamic_cast<AIS_ViewCube* >(mySelectable); |
676 | aCubePrs->HandleClick (this); |
677 | return Standard_True; |
678 | } |
679 | |
680 | protected: |
681 | |
682 | V3d_TypeOfOrientation myMainOrient; //!< new orientation to set |
683 | |
684 | }; |
685 | |
686 | #endif // _AIS_ViewCube_HeaderFile |