0026477: Porting PRODUCTS and OCCT QT samples for OCCT 7.0.0
[occt.git] / src / AIS / AIS_InteractiveObject.hxx
CommitLineData
42cf5bc1 1// Created on: 1996-12-11
2// Created by: Robert COUBLANC
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _AIS_InteractiveObject_HeaderFile
18#define _AIS_InteractiveObject_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <AIS_PToContext.hxx>
24#include <TColStd_ListOfTransient.hxx>
25#include <Standard_Real.hxx>
26#include <Quantity_Color.hxx>
27#include <Graphic3d_NameOfMaterial.hxx>
28#include <Standard_Integer.hxx>
29#include <Standard_Boolean.hxx>
30#include <Aspect_TypeOfFacingModel.hxx>
31#include <TColStd_ListOfInteger.hxx>
32#include <SelectMgr_SelectableObject.hxx>
33#include <PrsMgr_TypeOfPresentation3d.hxx>
34#include <AIS_KindOfInteractive.hxx>
35#include <Quantity_NameOfColor.hxx>
36#include <Standard_ShortReal.hxx>
37class Standard_Transient;
38class AIS_InteractiveContext;
39class Quantity_Color;
40class Graphic3d_MaterialAspect;
41class Prs3d_Presentation;
42class Prs3d_BasicAspect;
43class Bnd_Box;
44
45
46class AIS_InteractiveObject;
47DEFINE_STANDARD_HANDLE(AIS_InteractiveObject, SelectMgr_SelectableObject)
48
49
50//! Defines a class of objects with display and selection services.
51//! Entities which are visualized and selected are
52//! Interactive Objects. You can make use of classes of
53//! standard Interactive Objects for which all necessary
54//! methods have already been programmed, or you can
55//! implement your own classes of Interactive Objects.
56//! Specific attributes of entities such as arrow aspect for
57//! dimensions must be loaded in a Drawer. This Drawer
58//! is then applied to the Interactive Object in view.
59//! There are four types of Interactive Object in AIS: the
60//! construction element or Datum, the Relation, which
61//! includes both dimensions and constraints, the Object,
62//! and finally, when the object is of an unknown type, the None type.
63//! Inside these categories, a signature, or index,
64//! provides the possibility of additional characterization.
65//! By default, the Interactive Object has a None type
66//! and a signature of 0. If you want to give a particular
67//! type and signature to your interactive object, you must
68//! redefine the methods, Signature and Type.
69//! Warning
70//! In the case of attribute methods, methods for
71//! standard attributes are virtual. They must be
72//! redefined by the inheriting classes. Setcolor for a
73//! point and Setcolor for a plane, for example, do not
74//! affect the same attributes in the Drawer.
75class AIS_InteractiveObject : public SelectMgr_SelectableObject
76{
77
78public:
79
80
81
82 //! Returns the kind of Interactive Object:
83 //! - None
84 //! - Datum
85 //! - Relation
86 //! - Object
87 //! By default, the interactive object has a None type.
88 //! Because specific shapes entail different behavior
89 //! according to their sub-shapes, you may need to
90 //! create a Local Context. This will allow you to
91 //! specify the additional characteristics which you
92 //! need to handle these shapes.
93 Standard_EXPORT virtual AIS_KindOfInteractive Type() const;
94
95 //! Specifies additional characteristics of Interactive
96 //! Objects. A signature is, in fact, an index with integer
97 //! values assigned different properties.
98 //! This method is frequently used in conjuction with
99 //! Type to give a particular type and signature to an
100 //! Interactive Object. By default, the Interactive Object
101 //! has a None type and a signature of 0. Among the
102 //! datums, this signature is attributed to the shape
103 //! The remaining datums have the following default signatures:
104 //! - Point signature 1
105 //! - Axis signature 2
106 //! - Trihedron signature 3
107 //! - PlaneTrihedron signature 4
108 //! - Line signature 5
109 //! - Circle signature 6
110 //! - Plane signature 7.
111 Standard_EXPORT virtual Standard_Integer Signature() const;
112
113 //! Informs the graphic context that the interactive Object
114 //! may be decomposed into sub-shapes for dynamic selection.
115 //! The most used Interactive Object is AIS_Shape.
116 //! Activation methods for standard selection modes are
117 //! proposed in the Interactive Context. These include
118 //! selection by vertex or by edges. For datums with the
119 //! same behavior as AIS_Shape, such as vetices and
120 //! edges, we must redefine the virtual method so that
121 //! AcceptShapeDecomposition returns false.
122 //! Rule for selection :
123 //! Mode 0 : Selection of the interactive Object itself
124 //! Mode 1 : Selection of vertices
125 //! Mode 2 : Selection Of Edges
126 //! Mode 3 : Selection Of Wires
127 //! Mode 4 : Selection Of Faces ...
128 virtual Standard_Boolean AcceptShapeDecomposition() const;
129
130 //! change the current facing model apply on polygons for
131 //! SetColor(), SetTransparency(), SetMaterial() methods
132 //! default facing model is Aspect_TOFM_TWO_SIDE. This mean that attributes is
133 //! applying both on the front and back face.
134 Standard_EXPORT void SetCurrentFacingModel (const Aspect_TypeOfFacingModel aModel = Aspect_TOFM_BOTH_SIDE);
135
136 //! Returns the current facing model which is in effect.
137 Standard_EXPORT Aspect_TypeOfFacingModel CurrentFacingModel() const;
138
139 Standard_EXPORT virtual void SetColor (const Quantity_Color& aColor);
140
141 //! only the interactive obj knowns which Drawer attribute
142 //! is affected by the color (ex: for a wire, it's the
143 //! wireaspect field of the drawer, but for a vertex, only
144 //! the point aspect field is affected by the color)
145 //! WARNING : Do not forget to set the corresponding fields
146 //! here (hasOwnColor and myOwnColor)
147 Standard_EXPORT virtual void SetColor (const Quantity_NameOfColor aColor);
148
149 //! Removes color settings. Only the Interactive Object
150 //! knows which Drawer attribute is affected by the color
151 //! setting. For a wire, for example, wire aspect is the
152 //! attribute affected. For a vertex, however, only point
153 //! aspect is affected by the color setting.
154 Standard_EXPORT virtual void UnsetColor();
155
156 //! Allows you to provide the setting aValue for width.
157 //! Only the Interactive Object knows which Drawer
158 //! attribute is affected by the width setting.
159 Standard_EXPORT virtual void SetWidth (const Standard_Real aValue);
160
161 Standard_EXPORT virtual void UnsetWidth();
162
163 //! Returns true if the class of objects accepts the display mode aMode.
164 //! The interactive context can have a default mode of
165 //! representation for the set of Interactive Objects. This
166 //! mode may not be accepted by a given class of
167 //! objects. Consequently, this virtual method allowing us
168 //! to get information about the class in question must be implemented.
169 Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer aMode) const;
170
171 //! Returns the default display mode. This method is to
172 //! be implemented when the main mode is not mode 0.
173 Standard_EXPORT virtual Standard_Integer DefaultDisplayMode() const;
174
175 //! Updates the active presentation; if <AllModes> = Standard_True
176 //! all the presentations inside are recomputed.
177 //! IMPORTANT: It is preferable to call Redisplay method of
178 //! corresponding AIS_InteractiveContext instance for cases when it
179 //! is accessible. This method just redirects call to myCTXPtr,
180 //! so this class field must be up to date for proper result.
181 Standard_EXPORT void Redisplay (const Standard_Boolean AllModes = Standard_False);
182
183 //! Sets the infinite state flag aFlage.
184 //! if <aFlag> = True , the interactiveObject is
185 //! considered as infinite, i.e. its graphic presentations
186 //! are not taken in account for View FitAll...
187 Standard_EXPORT void SetInfiniteState (const Standard_Boolean aFlag = Standard_True);
188
189
190 //! Returns true if the interactive object is infinite. In this
191 //! case, its graphic presentations are not taken into
192 //! account in the fit-all view.
193 Standard_Boolean IsInfinite() const;
194
195 //! Indicates whether the Interactive Object has a pointer
196 //! to an interactive context.
197 Standard_EXPORT Standard_Boolean HasInteractiveContext() const;
198
199 //! Returns the context pointer to the interactive context.
200 Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const;
201
202 //! Sets the interactive context aCtx and provides a link
203 //! to the default drawing tool or "Drawer" if there is none.
204 Standard_EXPORT virtual void SetContext (const Handle(AIS_InteractiveContext)& aCtx);
205
206 //! Returns true if the object has an owner attributed to it.
207 //! The owner can be a shape for a set of sub-shapes or
208 //! a sub-shape for sub-shapes which it is composed of,
209 //! and takes the form of a transient.
210 Standard_EXPORT Standard_Boolean HasOwner() const;
211
212 //! Returns the owner of the Interactive Object.
213 //! The owner can be a shape for a set of sub-shapes or
214 //! a sub-shape for sub-shapes which it is composed of,
215 //! and takes the form of a transient.
216 //! There are two types of owners:
217 //! - Direct owners, decomposition shapes such as
218 //! edges, wires, and faces.
219 //! - Users, presentable objects connecting to sensitive
220 //! primitives, or a shape which has been decomposed.
221 const Handle(Standard_Transient)& GetOwner() const;
222
223 //! Allows you to attribute the owner ApplicativeEntity to
224 //! an Interactive Object. This can be a shape for a set of
225 //! sub-shapes or a sub-shape for sub-shapes which it
226 //! is composed of. The owner takes the form of a transient.
227 void SetOwner (const Handle(Standard_Transient)& ApplicativeEntity);
228
229 //! Each Interactive Object has methods which allow us
230 //! to attribute an Owner to it in the form of a Transient.
231 //! This method removes the owner from the graphic entity.
232 Standard_EXPORT void ClearOwner();
233
234 Standard_EXPORT Standard_Boolean HasUsers() const;
235
236 const TColStd_ListOfTransient& Users() const;
237
238 Standard_EXPORT void AddUser (const Handle(Standard_Transient)& aUser);
239
240 Standard_EXPORT void ClearUsers();
241
242
243 //! Returns true if the Interactive Object has a display
244 //! mode setting. Otherwise, it is displayed in Neutral Point.
245 Standard_Boolean HasDisplayMode() const;
246
247 //! Sets the display mode aMode for the interactive object.
248 //! An object can have its own temporary display mode,
249 //! which is different from that proposed by the interactive context.
250 //! The range of possibilities currently proposed is the following:
251 //! - AIS_WireFrame
252 //! - AIS_Shaded
253 //! This range can, however, be extended through the creation of new display modes.
254 Standard_EXPORT void SetDisplayMode (const Standard_Integer aMode);
255
256 //! Removes display mode settings from the interactive object.
257 void UnsetDisplayMode();
258
259 //! Returns the display mode setting of the Interactive Object.
260 //! The range of possibilities is the following:
261 //! - AIS_WireFrame
262 //! - AIS_Shaded
263 //! This range can, however, be extended through the
264 //! creation of new display modes.
265 Standard_Integer DisplayMode() const;
266
267 //! Allows you to change the selection mode of an
268 //! Interactive Object.
269 //! The default selection mode setting is 0.
270 //! For shapes, for example, the selection modes are as follows:
271 //! - mode 0 - selection of the shape itself
272 //! - mode 1 - selection of vertices
273 //! - mode 2 - selection of edges
274 //! - mode 3 - selection of wires
275 //! - mode 4 - selection of faces
276 //! - mode 5 - selection of shells
277 //! - mode 6 - selection of solids
278 //! - mode 7 - selection of compounds
279 //! For trihedra, on the other hand, the selection modes are the following four:
280 //! - mode 0 - selection of a trihedron
281 //! - mode 1 - selection of its origin
282 //! - mode 2 - selection of its axes
283 //! - mode 3 - selection of its planes
284 Standard_EXPORT Standard_Boolean HasSelectionMode() const;
285
286 //! Returns the selection mode of the interactive object.
287 Standard_EXPORT Standard_Integer SelectionMode() const;
288
289 //! You can change the default selection mode index
290 //! aMode of an Interactive Object.
291 //! This is only of interest if you decide that mode 0
292 //! adopted by convention will not do.
293 Standard_EXPORT void SetSelectionMode (const Standard_Integer aMode);
294
295 //! You can change the default selection mode index of
296 //! an Interactive Object.
297 //! This is only of interest if you decide that the 0 mode
298 //! adopted by convention will not do.
299 void UnsetSelectionMode();
300
301 //! Returns the selection priority setting. -1 indicates that there is none.
302 //! You can modify the selection priority of an owner to
303 //! make one entity more selectionable than another one.
304 //! The default selection priority for an owner is 5, for
305 //! example. To increase selection priority, choose a
306 //! setting between 5 and 10. An entity with priority 7 will
307 //! take priority over one with a setting of 6 if both
308 //! objects are selected at the same time.
309 //! You could give vertices priority 8, edges priority 7,
310 //! faces priority 6, and shapes priority 5. If a vertex, an
311 //! edge and a face are simultaneously detected during
312 //! selection, only the vertex will then be highlighted.
313 //! For trihedra, for example, the default priorities are the following four:
314 //! - priority 1 - a trihedron
315 //! - priority 5 - its origin
316 //! - priority 3 - its axes
317 //! - priority 2 - its planes
318 Standard_Integer SelectionPriority() const;
319
320 //! Allows you to provide a setting aPriority for selection priority.
321 //! You can modify selection priority of an owner to make
322 //! one entity more selectionable than another one. The
323 //! default selection priority for an owner is 5, for
324 //! example. To increase selection priority, choose a
325 //! setting between 5 and 10. An entity with priority 7 will
326 //! take priority over one with a setting of 6.
327 void SetSelectionPriority (const Standard_Integer aPriority);
328
329 //! Removes the setting for selection priority. SelectionPriority then returns -1.
330 void UnsetSelectionPriority();
331
332 //! Returns true if there is a setting for selection priority.
333 //! You can modify selection priority of an owner to make
334 //! one entity more selectionable than another one. The
335 //! default selection priority for an owner is 5, for
336 //! example. To increase selection priority, choose a
337 //! setting between 5 and 10. An entity with priority 7 will
338 //! take priority over one with a setting of 6.
339 Standard_Boolean HasSelectionPriority() const;
340
341 //! Returns true if the Interactive Object is in highlight mode.
342 Standard_Boolean HasHilightMode() const;
343
344 //! Returns the setting for highlight mode.
345 //! At dynamic detection, the presentation echoed by the
346 //! Interactive Context, is by default the presentation
347 //! already on the screen. You can specify a Highlight
348 //! presentation mode which is valid no matter what the
349 //! active representation of the object. It makes no
350 //! difference whether this choice is temporary or
351 //! definitive. To do this, we use the following functions:
352 //! - SetHilightMode
353 //! - UnSetHilightMode
354 //! In the case of a shape, whether it is visualized in
355 //! wireframe presentation or with shading, we want to
356 //! systematically highlight the wireframe presentation.
357 //! Consequently, we set the highlight mode to 0.
358 Standard_Integer HilightMode() const;
359
360 //! Sets the highlight mode anIndex for the interactive object.
361 //! If, for example, you want to systematically highlight
362 //! the wireframe presentation of a shape - whether
363 //! visualized in wireframe presentation or with shading -
364 //! you set the highlight mode to 0.
365 void SetHilightMode (const Standard_Integer anIndex);
366
367 //! Allows the user to take a given Prs for hilight
368 //! ex : for a shape which would be displayed in shading mode
369 //! the hilight Prs is the wireframe mode.
370 //! if No specific hilight mode is defined, the displayed Prs
371 //! will be the hilighted one.
372 void UnsetHilightMode();
373
374 //! Returns true if the Interactive Object has color.
375 Standard_Boolean HasColor() const;
376
377 //! Returns the color setting of the Interactive Object.
378 virtual Quantity_NameOfColor Color() const;
379
380 virtual void Color (Quantity_Color& aColor) const;
381
382 //! Returns true if the Interactive Object has width.
383 Standard_Boolean HasWidth() const;
384
385 //! Returns the width setting of the Interactive Object.
386 Standard_EXPORT Standard_Real Width() const;
387
388 //! Returns true if the Interactive Object has a setting for material.
389 Standard_EXPORT Standard_Boolean HasMaterial() const;
390
391 //! Returns the current material setting.
392 //! This will be on of the following materials:
393 //! - Brass
394 //! - Bronze
395 //! - Gold
396 //! - Pewter
397 //! - Silver
398 //! - Stone.
399 Standard_EXPORT virtual Graphic3d_NameOfMaterial Material() const;
400
401 //! Sets the name aName for material defining this
402 //! display attribute for the interactive object.
403 //! Material aspect determines shading aspect, color and
404 //! transparency of visible entities.
405 Standard_EXPORT virtual void SetMaterial (const Graphic3d_NameOfMaterial aName);
406
407 //! Sets the material aMat defining this display attribute
408 //! for the interactive object.
409 //! Material aspect determines shading aspect, color and
410 //! transparency of visible entities.
411 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& aName);
412
413 //! Removes the setting for material.
414 Standard_EXPORT virtual void UnsetMaterial();
415
416 //! Attributes a setting aValue for transparency.
417 //! The transparency value should be between 0.0 and 1.0.
418 //! At 0.0 an object will be totally opaque, and at 1.0, fully transparent.
419 //! Warning At a value of 1.0, there may be nothing visible.
420 Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6);
421
422 //! Returns true if there is a transparency setting.
423 Standard_Boolean IsTransparent() const;
424
425 //! Returns the transparency setting.
426 //! This will be between 0.0 and 1.0.
427 //! At 0.0 an object will be totally opaque, and at 1.0, fully transparent.
428 Standard_EXPORT virtual Standard_Real Transparency() const;
429
430 //! Removes the transparency setting. The object is opaque by default.
431 Standard_EXPORT virtual void UnsetTransparency();
432
433 //! Clears settings provided by the drawing tool aDrawer.
434 Standard_EXPORT virtual void UnsetAttributes() Standard_OVERRIDE;
435
436 void State (const Standard_Integer theState);
437
438 Standard_Integer State() const;
439
440 //! Returns TRUE when this object has a presentation
441 //! in the current DisplayMode()
442 Standard_EXPORT Standard_Boolean HasPresentation() const;
443
444 //! Returns the current presentation of this object
445 //! according to the current DisplayMode()
446 Standard_EXPORT Handle(Prs3d_Presentation) Presentation() const;
447
448 //! Sets the graphic basic aspect to the current presentation.
449 //! When <globalChange> is TRUE , the full object presentation
450 //! is changed.
451 //! When <globalChange> is FALSE , only the current group
452 //! of the object presentation is changed.
453 Standard_EXPORT void SetAspect (const Handle(Prs3d_BasicAspect)& anAspect, const Standard_Boolean globalChange = Standard_True);
454
455 //! Sets up polygon offsets for this object.
456 //! It modifies all existing presentations of <anObj> (if any),
457 //! so it is reasonable to call this method after <anObj> has been displayed.
458 //! Otherwise, Compute() method should pass Graphic3d_AspectFillArea3d
459 //! aspect from <myDrawer> to Graphic3d_Group to make polygon offsets work.
460 //!
461 //! <aMode> parameter can contain various combinations of
462 //! Aspect_PolygonOffsetMode enumeration elements (Aspect_POM_None means
463 //! that polygon offsets are not changed).
464 //! If <aMode> is different from Aspect_POM_Off and Aspect_POM_None, then <aFactor> and <aUnits>
465 //! arguments are used by graphic renderer to calculate a depth offset value:
466 //!
467 //! offset = <aFactor> * m + <aUnits> * r, where
468 //! m - maximum depth slope for the polygon currently being displayed,
469 //! r - minimum window coordinates depth resolution (implementation-specific).
470 //!
471 //! Deafult settings for OCC 3D viewer: mode = Aspect_POM_Fill, factor = 1., units = 0.
472 //!
473 //! Negative offset values move polygons closer to the viewport,
474 //! while positive values shift polygons away.
475 //! Consult OpenGL reference for details (glPolygonOffset function description).
476 //!
477 //! NOTE: This method has a side effect - it creates own shading aspect
478 //! if not yet created, so it is better to set up object material,
479 //! color, etc. first.
480 Standard_EXPORT virtual void SetPolygonOffsets (const Standard_Integer aMode, const Standard_ShortReal aFactor = 1.0, const Standard_ShortReal aUnits = 0.0);
481
482 //! Returns Standard_True if <myDrawer> has non-null shading aspect
483 Standard_EXPORT virtual Standard_Boolean HasPolygonOffsets() const;
484
485 //! Retrieves current polygon offsets settings from <myDrawer>.
486 Standard_EXPORT virtual void PolygonOffsets (Standard_Integer& aMode, Standard_ShortReal& aFactor, Standard_ShortReal& aUnits) const;
487
488 //! Returns bounding box of object correspondingly to its current display mode.
489 Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
490
491
492friend class AIS_InteractiveContext;
493
494
495 DEFINE_STANDARD_RTTI(AIS_InteractiveObject,SelectMgr_SelectableObject)
496
497protected:
498
499
500 //! The TypeOfPresention3d means that the interactive object
501 //! may have a presentation dependant of the view of Display
502 Standard_EXPORT AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
503
504 Standard_Real myTransparency;
505 Quantity_Color myOwnColor;
506 Graphic3d_NameOfMaterial myOwnMaterial;
507 Standard_Integer myHilightMode;
508 Standard_Real myOwnWidth;
509 Standard_Boolean myInfiniteState;
510 Standard_Boolean hasOwnColor;
511 Standard_Boolean hasOwnMaterial;
512 Aspect_TypeOfFacingModel myCurrentFacingModel;
513 Standard_Boolean myRecomputeEveryPrs;
514 TColStd_ListOfInteger myToRecomputeModes;
515
516
517private:
518
519
520 Standard_EXPORT virtual Standard_Boolean RecomputeEveryPrs() const;
521
522 Standard_EXPORT void MustRecomputePrs (const Standard_Integer aMode) const;
523
524 Standard_EXPORT const TColStd_ListOfInteger& ListOfRecomputeModes() const;
525
526 Standard_EXPORT void SetRecomputeOk();
527
528 AIS_PToContext myCTXPtr;
529 Handle(Standard_Transient) myOwner;
530 TColStd_ListOfTransient myUsers;
531 Standard_Integer mySelPriority;
532 Standard_Integer myDisplayMode;
533 Standard_Integer mySelectionMode;
534 Standard_Integer mystate;
535
536
537};
538
539
540#include <AIS_InteractiveObject.lxx>
541
542
543
544
545
546#endif // _AIS_InteractiveObject_HeaderFile