0027679: Wrong offset: overlapping edges
[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;
c3282ec1 266
42cf5bc1 267 //! Returns the selection priority setting. -1 indicates that there is none.
268 //! You can modify the selection priority of an owner to
269 //! make one entity more selectionable than another one.
270 //! The default selection priority for an owner is 5, for
271 //! example. To increase selection priority, choose a
272 //! setting between 5 and 10. An entity with priority 7 will
273 //! take priority over one with a setting of 6 if both
274 //! objects are selected at the same time.
275 //! You could give vertices priority 8, edges priority 7,
276 //! faces priority 6, and shapes priority 5. If a vertex, an
277 //! edge and a face are simultaneously detected during
278 //! selection, only the vertex will then be highlighted.
279 //! For trihedra, for example, the default priorities are the following four:
280 //! - priority 1 - a trihedron
281 //! - priority 5 - its origin
282 //! - priority 3 - its axes
283 //! - priority 2 - its planes
284 Standard_Integer SelectionPriority() const;
285
286 //! Allows you to provide a setting aPriority for selection priority.
287 //! You can modify selection priority of an owner to make
288 //! one entity more selectionable than another one. The
289 //! default selection priority for an owner is 5, for
290 //! example. To increase selection priority, choose a
291 //! setting between 5 and 10. An entity with priority 7 will
292 //! take priority over one with a setting of 6.
293 void SetSelectionPriority (const Standard_Integer aPriority);
294
295 //! Removes the setting for selection priority. SelectionPriority then returns -1.
296 void UnsetSelectionPriority();
297
298 //! Returns true if there is a setting for selection priority.
299 //! You can modify selection priority of an owner to make
300 //! one entity more selectionable than another one. The
301 //! default selection priority for an owner is 5, for
302 //! example. To increase selection priority, choose a
303 //! setting between 5 and 10. An entity with priority 7 will
304 //! take priority over one with a setting of 6.
305 Standard_Boolean HasSelectionPriority() const;
306
307 //! Returns true if the Interactive Object is in highlight mode.
308 Standard_Boolean HasHilightMode() const;
309
310 //! Returns the setting for highlight mode.
311 //! At dynamic detection, the presentation echoed by the
312 //! Interactive Context, is by default the presentation
313 //! already on the screen. You can specify a Highlight
314 //! presentation mode which is valid no matter what the
315 //! active representation of the object. It makes no
316 //! difference whether this choice is temporary or
317 //! definitive. To do this, we use the following functions:
318 //! - SetHilightMode
319 //! - UnSetHilightMode
320 //! In the case of a shape, whether it is visualized in
321 //! wireframe presentation or with shading, we want to
322 //! systematically highlight the wireframe presentation.
323 //! Consequently, we set the highlight mode to 0.
324 Standard_Integer HilightMode() const;
325
326 //! Sets the highlight mode anIndex for the interactive object.
327 //! If, for example, you want to systematically highlight
328 //! the wireframe presentation of a shape - whether
329 //! visualized in wireframe presentation or with shading -
330 //! you set the highlight mode to 0.
331 void SetHilightMode (const Standard_Integer anIndex);
332
333 //! Allows the user to take a given Prs for hilight
334 //! ex : for a shape which would be displayed in shading mode
335 //! the hilight Prs is the wireframe mode.
336 //! if No specific hilight mode is defined, the displayed Prs
337 //! will be the hilighted one.
338 void UnsetHilightMode();
339
340 //! Returns true if the Interactive Object has color.
341 Standard_Boolean HasColor() const;
342
343 //! Returns the color setting of the Interactive Object.
344 virtual Quantity_NameOfColor Color() const;
345
346 virtual void Color (Quantity_Color& aColor) const;
347
348 //! Returns true if the Interactive Object has width.
349 Standard_Boolean HasWidth() const;
350
351 //! Returns the width setting of the Interactive Object.
be5c3602 352 Standard_Real Width() const;
42cf5bc1 353
354 //! Returns true if the Interactive Object has a setting for material.
be5c3602 355 Standard_Boolean HasMaterial() const;
42cf5bc1 356
357 //! Returns the current material setting.
358 //! This will be on of the following materials:
359 //! - Brass
360 //! - Bronze
361 //! - Gold
362 //! - Pewter
363 //! - Silver
364 //! - Stone.
be5c3602 365 virtual Graphic3d_NameOfMaterial Material() const;
42cf5bc1 366
367 //! Sets the name aName for material defining this
368 //! display attribute for the interactive object.
369 //! Material aspect determines shading aspect, color and
370 //! transparency of visible entities.
371 Standard_EXPORT virtual void SetMaterial (const Graphic3d_NameOfMaterial aName);
372
373 //! Sets the material aMat defining this display attribute
374 //! for the interactive object.
375 //! Material aspect determines shading aspect, color and
376 //! transparency of visible entities.
377 Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& aName);
378
379 //! Removes the setting for material.
380 Standard_EXPORT virtual void UnsetMaterial();
381
382 //! Attributes a setting aValue for transparency.
383 //! The transparency value should be between 0.0 and 1.0.
384 //! At 0.0 an object will be totally opaque, and at 1.0, fully transparent.
385 //! Warning At a value of 1.0, there may be nothing visible.
386 Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6);
387
388 //! Returns true if there is a transparency setting.
389 Standard_Boolean IsTransparent() const;
390
391 //! Returns the transparency setting.
392 //! This will be between 0.0 and 1.0.
393 //! At 0.0 an object will be totally opaque, and at 1.0, fully transparent.
394 Standard_EXPORT virtual Standard_Real Transparency() const;
395
396 //! Removes the transparency setting. The object is opaque by default.
397 Standard_EXPORT virtual void UnsetTransparency();
398
399 //! Clears settings provided by the drawing tool aDrawer.
400 Standard_EXPORT virtual void UnsetAttributes() Standard_OVERRIDE;
401
402 void State (const Standard_Integer theState);
403
404 Standard_Integer State() const;
405
406 //! Returns TRUE when this object has a presentation
407 //! in the current DisplayMode()
408 Standard_EXPORT Standard_Boolean HasPresentation() const;
409
410 //! Returns the current presentation of this object
411 //! according to the current DisplayMode()
412 Standard_EXPORT Handle(Prs3d_Presentation) Presentation() const;
2831708b 413
42cf5bc1 414 //! Sets the graphic basic aspect to the current presentation.
2831708b 415 Standard_EXPORT void SetAspect (const Handle(Prs3d_BasicAspect)& anAspect);
42cf5bc1 416
417 //! Sets up polygon offsets for this object.
418 //! It modifies all existing presentations of <anObj> (if any),
419 //! so it is reasonable to call this method after <anObj> has been displayed.
420 //! Otherwise, Compute() method should pass Graphic3d_AspectFillArea3d
421 //! aspect from <myDrawer> to Graphic3d_Group to make polygon offsets work.
422 //!
423 //! <aMode> parameter can contain various combinations of
424 //! Aspect_PolygonOffsetMode enumeration elements (Aspect_POM_None means
425 //! that polygon offsets are not changed).
426 //! If <aMode> is different from Aspect_POM_Off and Aspect_POM_None, then <aFactor> and <aUnits>
427 //! arguments are used by graphic renderer to calculate a depth offset value:
428 //!
429 //! offset = <aFactor> * m + <aUnits> * r, where
430 //! m - maximum depth slope for the polygon currently being displayed,
431 //! r - minimum window coordinates depth resolution (implementation-specific).
432 //!
433 //! Deafult settings for OCC 3D viewer: mode = Aspect_POM_Fill, factor = 1., units = 0.
434 //!
435 //! Negative offset values move polygons closer to the viewport,
436 //! while positive values shift polygons away.
437 //! Consult OpenGL reference for details (glPolygonOffset function description).
438 //!
439 //! NOTE: This method has a side effect - it creates own shading aspect
440 //! if not yet created, so it is better to set up object material,
441 //! color, etc. first.
442 Standard_EXPORT virtual void SetPolygonOffsets (const Standard_Integer aMode, const Standard_ShortReal aFactor = 1.0, const Standard_ShortReal aUnits = 0.0);
443
444 //! Returns Standard_True if <myDrawer> has non-null shading aspect
445 Standard_EXPORT virtual Standard_Boolean HasPolygonOffsets() const;
446
447 //! Retrieves current polygon offsets settings from <myDrawer>.
448 Standard_EXPORT virtual void PolygonOffsets (Standard_Integer& aMode, Standard_ShortReal& aFactor, Standard_ShortReal& aUnits) const;
449
450 //! Returns bounding box of object correspondingly to its current display mode.
451 Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
452
5ad8c033 453 //! Enables or disables on-triangulation build of isolines according to the flag given.
454 Standard_EXPORT void SetIsoOnTriangulation (const Standard_Boolean theIsEnabled);
42cf5bc1 455
456friend class AIS_InteractiveContext;
457
458
92efcf78 459 DEFINE_STANDARD_RTTIEXT(AIS_InteractiveObject,SelectMgr_SelectableObject)
42cf5bc1 460
461protected:
462
463
464 //! The TypeOfPresention3d means that the interactive object
c3282ec1 465 //! may have a presentation dependant of the view of Display.
42cf5bc1 466 Standard_EXPORT AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
467
468 Standard_Real myTransparency;
469 Quantity_Color myOwnColor;
470 Graphic3d_NameOfMaterial myOwnMaterial;
471 Standard_Integer myHilightMode;
472 Standard_Real myOwnWidth;
473 Standard_Boolean myInfiniteState;
474 Standard_Boolean hasOwnColor;
475 Standard_Boolean hasOwnMaterial;
476 Aspect_TypeOfFacingModel myCurrentFacingModel;
477 Standard_Boolean myRecomputeEveryPrs;
478 TColStd_ListOfInteger myToRecomputeModes;
479
480
481private:
482
483
484 Standard_EXPORT virtual Standard_Boolean RecomputeEveryPrs() const;
485
486 Standard_EXPORT void MustRecomputePrs (const Standard_Integer aMode) const;
487
488 Standard_EXPORT const TColStd_ListOfInteger& ListOfRecomputeModes() const;
489
490 Standard_EXPORT void SetRecomputeOk();
491
492 AIS_PToContext myCTXPtr;
493 Handle(Standard_Transient) myOwner;
494 TColStd_ListOfTransient myUsers;
495 Standard_Integer mySelPriority;
496 Standard_Integer myDisplayMode;
42cf5bc1 497 Standard_Integer mystate;
498
499
500};
501
502
503#include <AIS_InteractiveObject.lxx>
504
505
506
507
508
509#endif // _AIS_InteractiveObject_HeaderFile