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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _AIS_InteractiveObject_HeaderFile
18 #define _AIS_InteractiveObject_HeaderFile
20 #include <Aspect_TypeOfFacingModel.hxx>
21 #include <AIS_KindOfInteractive.hxx>
22 #include <Graphic3d_NameOfMaterial.hxx>
23 #include <PrsMgr_TypeOfPresentation3d.hxx>
24 #include <SelectMgr_SelectableObject.hxx>
25 #include <TColStd_ListOfInteger.hxx>
26 #include <TColStd_ListOfTransient.hxx>
27 #include <Quantity_Color.hxx>
29 class AIS_InteractiveContext;
30 class Graphic3d_MaterialAspect;
31 class Prs3d_Presentation;
32 class Prs3d_BasicAspect;
35 //! Defines a class of objects with display and selection services.
36 //! Entities which are visualized and selected are
37 //! Interactive Objects. You can make use of classes of
38 //! standard Interactive Objects for which all necessary
39 //! methods have already been programmed, or you can
40 //! implement your own classes of Interactive Objects.
41 //! Specific attributes of entities such as arrow aspect for
42 //! dimensions must be loaded in a Drawer. This Drawer
43 //! is then applied to the Interactive Object in view.
44 //! There are four types of Interactive Object in AIS: the
45 //! construction element or Datum, the Relation, which
46 //! includes both dimensions and constraints, the Object,
47 //! and finally, when the object is of an unknown type, the None type.
48 //! Inside these categories, a signature, or index,
49 //! provides the possibility of additional characterization.
50 //! By default, the Interactive Object has a None type
51 //! and a signature of 0. If you want to give a particular
52 //! type and signature to your interactive object, you must
53 //! redefine the methods, Signature and Type.
55 //! In the case of attribute methods, methods for
56 //! standard attributes are virtual. They must be
57 //! redefined by the inheriting classes. Setcolor for a
58 //! point and Setcolor for a plane, for example, do not
59 //! affect the same attributes in the Drawer.
60 class AIS_InteractiveObject : public SelectMgr_SelectableObject
62 friend class AIS_InteractiveContext;
63 DEFINE_STANDARD_RTTIEXT(AIS_InteractiveObject, SelectMgr_SelectableObject)
66 //! Returns the kind of Interactive Object:
71 //! By default, the interactive object has a None type.
72 //! Because specific shapes entail different behavior
73 //! according to their sub-shapes, you may need to
74 //! create a Local Context. This will allow you to
75 //! specify the additional characteristics which you
76 //! need to handle these shapes.
77 Standard_EXPORT virtual AIS_KindOfInteractive Type() const;
79 //! Specifies additional characteristics of Interactive
80 //! Objects. A signature is, in fact, an index with integer
81 //! values assigned different properties.
82 //! This method is frequently used in conjuction with
83 //! Type to give a particular type and signature to an
84 //! Interactive Object. By default, the Interactive Object
85 //! has a None type and a signature of 0. Among the
86 //! datums, this signature is attributed to the shape
87 //! The remaining datums have the following default signatures:
88 //! - Point signature 1
89 //! - Axis signature 2
90 //! - Trihedron signature 3
91 //! - PlaneTrihedron signature 4
92 //! - Line signature 5
93 //! - Circle signature 6
94 //! - Plane signature 7.
95 Standard_EXPORT virtual Standard_Integer Signature() const;
97 //! Informs the graphic context that the interactive Object
98 //! may be decomposed into sub-shapes for dynamic selection.
99 //! The most used Interactive Object is AIS_Shape.
100 //! Activation methods for standard selection modes are
101 //! proposed in the Interactive Context. These include
102 //! selection by vertex or by edges. For datums with the
103 //! same behavior as AIS_Shape, such as vetices and
104 //! edges, we must redefine the virtual method so that
105 //! AcceptShapeDecomposition returns false.
106 //! Rule for selection :
107 //! Mode 0 : Selection of the interactive Object itself
108 //! Mode 1 : Selection of vertices
109 //! Mode 2 : Selection Of Edges
110 //! Mode 3 : Selection Of Wires
111 //! Mode 4 : Selection Of Faces ...
112 virtual Standard_Boolean AcceptShapeDecomposition() const { return Standard_False; }
114 //! change the current facing model apply on polygons for
115 //! SetColor(), SetTransparency(), SetMaterial() methods
116 //! default facing model is Aspect_TOFM_TWO_SIDE. This mean that attributes is
117 //! applying both on the front and back face.
118 Standard_EXPORT void SetCurrentFacingModel (const Aspect_TypeOfFacingModel aModel = Aspect_TOFM_BOTH_SIDE);
120 //! Returns the current facing model which is in effect.
121 Standard_EXPORT Aspect_TypeOfFacingModel CurrentFacingModel() const;
123 Standard_EXPORT virtual void SetColor (const Quantity_Color& aColor);
125 //! only the interactive obj knowns which Drawer attribute
126 //! is affected by the color (ex: for a wire, it's the
127 //! wireaspect field of the drawer, but for a vertex, only
128 //! the point aspect field is affected by the color)
129 //! WARNING : Do not forget to set the corresponding fields
130 //! here (hasOwnColor and myOwnColor)
131 Standard_EXPORT virtual void SetColor (const Quantity_NameOfColor aColor);
133 //! Removes color settings. Only the Interactive Object
134 //! knows which Drawer attribute is affected by the color
135 //! setting. For a wire, for example, wire aspect is the
136 //! attribute affected. For a vertex, however, only point
137 //! aspect is affected by the color setting.
138 Standard_EXPORT virtual void UnsetColor();
140 //! Allows you to provide the setting aValue for width.
141 //! Only the Interactive Object knows which Drawer
142 //! attribute is affected by the width setting.
143 Standard_EXPORT virtual void SetWidth (const Standard_Real aValue);
145 Standard_EXPORT virtual void UnsetWidth();
147 //! Returns true if the class of objects accepts the display mode aMode.
148 //! The interactive context can have a default mode of
149 //! representation for the set of Interactive Objects. This
150 //! mode may not be accepted by a given class of
151 //! objects. Consequently, this virtual method allowing us
152 //! to get information about the class in question must be implemented.
153 Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer aMode) const;
155 //! Returns the default display mode. This method is to
156 //! be implemented when the main mode is not mode 0.
157 Standard_EXPORT virtual Standard_Integer DefaultDisplayMode() const;
159 //! Updates the active presentation; if <AllModes> = Standard_True
160 //! all the presentations inside are recomputed.
161 //! IMPORTANT: It is preferable to call Redisplay method of
162 //! corresponding AIS_InteractiveContext instance for cases when it
163 //! is accessible. This method just redirects call to myCTXPtr,
164 //! so this class field must be up to date for proper result.
165 Standard_EXPORT void Redisplay (const Standard_Boolean AllModes = Standard_False);
167 //! Sets the infinite state flag aFlage.
168 //! if <aFlag> = True , the interactiveObject is
169 //! considered as infinite, i.e. its graphic presentations
170 //! are not taken in account for View FitAll...
171 Standard_EXPORT void SetInfiniteState (const Standard_Boolean aFlag = Standard_True);
173 //! Returns true if the interactive object is infinite. In this
174 //! case, its graphic presentations are not taken into
175 //! account in the fit-all view.
176 Standard_Boolean IsInfinite() const { return myInfiniteState; }
178 //! Indicates whether the Interactive Object has a pointer to an interactive context.
179 Standard_Boolean HasInteractiveContext() const { return myCTXPtr != NULL; }
181 //! Returns the context pointer to the interactive context.
182 Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const;
184 //! Sets the interactive context aCtx and provides a link
185 //! to the default drawing tool or "Drawer" if there is none.
186 Standard_EXPORT virtual void SetContext (const Handle(AIS_InteractiveContext)& aCtx);
188 //! Returns true if the object has an owner attributed to it.
189 //! The owner can be a shape for a set of sub-shapes or
190 //! a sub-shape for sub-shapes which it is composed of,
191 //! and takes the form of a transient.
192 Standard_EXPORT Standard_Boolean HasOwner() const;
194 //! Returns the owner of the Interactive Object.
195 //! The owner can be a shape for a set of sub-shapes or
196 //! a sub-shape for sub-shapes which it is composed of,
197 //! and takes the form of a transient.
198 //! There are two types of owners:
199 //! - Direct owners, decomposition shapes such as
200 //! edges, wires, and faces.
201 //! - Users, presentable objects connecting to sensitive
202 //! primitives, or a shape which has been decomposed.
203 const Handle(Standard_Transient)& GetOwner() const { return myOwner; }
205 //! Allows you to attribute the owner theApplicativeEntity to
206 //! an Interactive Object. This can be a shape for a set of
207 //! sub-shapes or a sub-shape for sub-shapes which it
208 //! is composed of. The owner takes the form of a transient.
209 void SetOwner (const Handle(Standard_Transient)& theApplicativeEntity) { myOwner = theApplicativeEntity; }
211 //! Each Interactive Object has methods which allow us
212 //! to attribute an Owner to it in the form of a Transient.
213 //! This method removes the owner from the graphic entity.
214 Standard_EXPORT void ClearOwner();
216 //! Returns true if the Interactive Object has a display
217 //! mode setting. Otherwise, it is displayed in Neutral Point.
218 Standard_Boolean HasDisplayMode() const { return myDisplayMode != -1; }
220 //! Sets the display mode aMode for the interactive object.
221 //! An object can have its own temporary display mode,
222 //! which is different from that proposed by the interactive context.
223 //! The range of possibilities currently proposed is the following:
226 //! This range can, however, be extended through the creation of new display modes.
227 Standard_EXPORT void SetDisplayMode (const Standard_Integer aMode);
229 //! Removes display mode settings from the interactive object.
230 void UnsetDisplayMode() { myDisplayMode = -1; }
232 //! Returns the display mode setting of the Interactive Object.
233 //! The range of possibilities is the following:
236 //! This range can, however, be extended through the
237 //! creation of new display modes.
238 Standard_Integer DisplayMode() const { return myDisplayMode; }
240 //! Returns the selection priority setting. -1 indicates that there is none.
241 //! You can modify the selection priority of an owner to
242 //! make one entity more selectionable than another one.
243 //! The default selection priority for an owner is 5, for
244 //! example. To increase selection priority, choose a
245 //! setting between 5 and 10. An entity with priority 7 will
246 //! take priority over one with a setting of 6 if both
247 //! objects are selected at the same time.
248 //! You could give vertices priority 8, edges priority 7,
249 //! faces priority 6, and shapes priority 5. If a vertex, an
250 //! edge and a face are simultaneously detected during
251 //! selection, only the vertex will then be highlighted.
252 //! For trihedra, for example, the default priorities are the following four:
253 //! - priority 1 - a trihedron
254 //! - priority 5 - its origin
255 //! - priority 3 - its axes
256 //! - priority 2 - its planes
257 Standard_Integer SelectionPriority() const { return mySelPriority; }
259 //! Allows you to provide a setting thePriority for selection priority.
260 //! You can modify selection priority of an owner to make
261 //! one entity more selectionable than another one. The
262 //! default selection priority for an owner is 5, for
263 //! example. To increase selection priority, choose a
264 //! setting between 5 and 10. An entity with priority 7 will
265 //! take priority over one with a setting of 6.
266 void SetSelectionPriority (const Standard_Integer thePriority) { mySelPriority = thePriority; }
268 //! Removes the setting for selection priority. SelectionPriority then returns -1.
269 void UnsetSelectionPriority() { mySelPriority = -1; }
271 //! Returns true if there is a setting for selection priority.
272 //! You can modify selection priority of an owner to make
273 //! one entity more selectionable than another one. The
274 //! default selection priority for an owner is 5, for
275 //! example. To increase selection priority, choose a
276 //! setting between 5 and 10. An entity with priority 7 will
277 //! take priority over one with a setting of 6.
278 Standard_Boolean HasSelectionPriority() const { return mySelPriority != -1; }
280 //! Returns true if the Interactive Object is in highlight mode.
281 Standard_Boolean HasHilightMode() const { return myHilightMode != -1; }
283 //! Returns the setting for highlight mode.
284 //! At dynamic detection, the presentation echoed by the
285 //! Interactive Context, is by default the presentation
286 //! already on the screen. You can specify a Highlight
287 //! presentation mode which is valid no matter what the
288 //! active representation of the object. It makes no
289 //! difference whether this choice is temporary or
290 //! definitive. To do this, we use the following functions:
292 //! - UnSetHilightMode
293 //! In the case of a shape, whether it is visualized in
294 //! wireframe presentation or with shading, we want to
295 //! systematically highlight the wireframe presentation.
296 //! Consequently, we set the highlight mode to 0.
297 Standard_Integer HilightMode() const { return myHilightMode; }
299 //! Sets the highlight mode theMode for the interactive object.
300 //! If, for example, you want to systematically highlight
301 //! the wireframe presentation of a shape - whether
302 //! visualized in wireframe presentation or with shading -
303 //! you set the highlight mode to 0.
304 void SetHilightMode (const Standard_Integer theMode) { myHilightMode = theMode; }
306 //! Allows the user to take a given Prs for hilight
307 //! ex : for a shape which would be displayed in shading mode
308 //! the hilight Prs is the wireframe mode.
309 //! if No specific hilight mode is defined, the displayed Prs
310 //! will be the hilighted one.
311 void UnsetHilightMode() { myHilightMode = -1; }
313 //! Returns true if the Interactive Object has color.
314 Standard_Boolean HasColor() const { return hasOwnColor; }
316 //! Returns the color setting of the Interactive Object.
317 virtual Quantity_NameOfColor Color() const { return myOwnColor.Name(); }
319 virtual void Color (Quantity_Color& theColor) const { theColor = myOwnColor; }
321 //! Returns true if the Interactive Object has width.
322 Standard_Boolean HasWidth() const { return myOwnWidth != 0.0; }
324 //! Returns the width setting of the Interactive Object.
325 Standard_Real Width() const { return myOwnWidth; }
327 //! Returns true if the Interactive Object has a setting for material.
328 Standard_Boolean HasMaterial() const { return hasOwnMaterial; }
330 //! Returns the current material setting.
331 //! This will be on of the following materials:
338 virtual Graphic3d_NameOfMaterial Material() const { return myOwnMaterial; }
340 //! Sets the name aName for material defining this
341 //! display attribute for the interactive object.
342 //! Material aspect determines shading aspect, color and
343 //! transparency of visible entities.
344 Standard_EXPORT virtual void SetMaterial (const Graphic3d_NameOfMaterial aName);
346 //! Sets the material aMat defining this display attribute
347 //! for the interactive object.
348 //! Material aspect determines shading aspect, color and
349 //! transparency of visible entities.
350 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& aName);
352 //! Removes the setting for material.
353 Standard_EXPORT virtual void UnsetMaterial();
355 //! Attributes a setting aValue for transparency.
356 //! The transparency value should be between 0.0 and 1.0.
357 //! At 0.0 an object will be totally opaque, and at 1.0, fully transparent.
358 //! Warning At a value of 1.0, there may be nothing visible.
359 Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6);
361 //! Returns true if there is a transparency setting.
362 Standard_Boolean IsTransparent() const { return myTransparency > 0.005; }
364 //! Returns the transparency setting.
365 //! This will be between 0.0 and 1.0.
366 //! At 0.0 an object will be totally opaque, and at 1.0, fully transparent.
367 Standard_EXPORT virtual Standard_Real Transparency() const;
369 //! Removes the transparency setting. The object is opaque by default.
370 Standard_EXPORT virtual void UnsetTransparency();
372 //! Clears settings provided by the drawing tool aDrawer.
373 Standard_EXPORT virtual void UnsetAttributes() Standard_OVERRIDE;
375 //! Returns TRUE when this object has a presentation
376 //! in the current DisplayMode()
377 Standard_EXPORT Standard_Boolean HasPresentation() const;
379 //! Returns the current presentation of this object
380 //! according to the current DisplayMode()
381 Standard_EXPORT Handle(Prs3d_Presentation) Presentation() const;
383 //! Sets the graphic basic aspect to the current presentation.
384 Standard_EXPORT void SetAspect (const Handle(Prs3d_BasicAspect)& anAspect);
386 //! Sets up polygon offsets for this object.
387 //! It modifies all existing presentations of <anObj> (if any),
388 //! so it is reasonable to call this method after <anObj> has been displayed.
389 //! Otherwise, Compute() method should pass Graphic3d_AspectFillArea3d
390 //! aspect from <myDrawer> to Graphic3d_Group to make polygon offsets work.
392 //! <aMode> parameter can contain various combinations of
393 //! Aspect_PolygonOffsetMode enumeration elements (Aspect_POM_None means
394 //! that polygon offsets are not changed).
395 //! If <aMode> is different from Aspect_POM_Off and Aspect_POM_None, then <aFactor> and <aUnits>
396 //! arguments are used by graphic renderer to calculate a depth offset value:
398 //! offset = <aFactor> * m + <aUnits> * r, where
399 //! m - maximum depth slope for the polygon currently being displayed,
400 //! r - minimum window coordinates depth resolution (implementation-specific).
402 //! Deafult settings for OCC 3D viewer: mode = Aspect_POM_Fill, factor = 1., units = 0.
404 //! Negative offset values move polygons closer to the viewport,
405 //! while positive values shift polygons away.
406 //! Consult OpenGL reference for details (glPolygonOffset function description).
408 //! NOTE: This method has a side effect - it creates own shading aspect
409 //! if not yet created, so it is better to set up object material,
410 //! color, etc. first.
411 Standard_EXPORT virtual void SetPolygonOffsets (const Standard_Integer aMode, const Standard_ShortReal aFactor = 1.0, const Standard_ShortReal aUnits = 0.0);
413 //! Returns Standard_True if <myDrawer> has non-null shading aspect
414 Standard_EXPORT virtual Standard_Boolean HasPolygonOffsets() const;
416 //! Retrieves current polygon offsets settings from <myDrawer>.
417 Standard_EXPORT virtual void PolygonOffsets (Standard_Integer& aMode, Standard_ShortReal& aFactor, Standard_ShortReal& aUnits) const;
419 //! Returns bounding box of object correspondingly to its current display mode.
420 Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
422 //! Enables or disables on-triangulation build of isolines according to the flag given.
423 Standard_EXPORT void SetIsoOnTriangulation (const Standard_Boolean theIsEnabled);
425 //! Synchronize presentation aspects after their modification.
427 //! This method should be called after modifying primitive aspect properties (material, texture, shader)
428 //! so that modifications will take effect on already computed presentation groups (thus avoiding re-displaying the object).
429 Standard_EXPORT void SynchronizeAspects();
433 Standard_EXPORT virtual Standard_Boolean RecomputeEveryPrs() const;
435 Standard_EXPORT void MustRecomputePrs (const Standard_Integer aMode) const;
437 Standard_EXPORT const TColStd_ListOfInteger& ListOfRecomputeModes() const;
439 Standard_EXPORT void SetRecomputeOk();
444 //! The TypeOfPresention3d means that the interactive object
445 //! may have a presentation dependant of the view of Display.
446 Standard_EXPORT AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
448 Standard_Real myTransparency;
449 Quantity_Color myOwnColor;
450 Graphic3d_NameOfMaterial myOwnMaterial;
451 Standard_Integer myHilightMode;
452 Standard_Real myOwnWidth;
453 Standard_Boolean myInfiniteState;
454 Standard_Boolean hasOwnColor;
455 Standard_Boolean hasOwnMaterial;
456 Aspect_TypeOfFacingModel myCurrentFacingModel;
457 Standard_Boolean myRecomputeEveryPrs;
458 TColStd_ListOfInteger myToRecomputeModes;
462 AIS_InteractiveContext* myCTXPtr;
463 Handle(Standard_Transient) myOwner;
464 Standard_Integer mySelPriority;
465 Standard_Integer myDisplayMode;
469 DEFINE_STANDARD_HANDLE(AIS_InteractiveObject, SelectMgr_SelectableObject)
471 #endif // _AIS_InteractiveObject_HeaderFile