0030949: Foundation Classes - Dump improvement for OCCT classes
[occt.git] / src / AIS / AIS_InteractiveObject.hxx
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 <AIS_KindOfInteractive.hxx>
21 #include <SelectMgr_SelectableObject.hxx>
22
23 class AIS_InteractiveContext;
24 class Graphic3d_MaterialAspect;
25 class Prs3d_BasicAspect;
26 class Bnd_Box;
27
28 //! Defines a class of objects with display and selection services.
29 //! Entities which are visualized and selected are Interactive Objects.
30 //! Specific attributes of entities such as arrow aspect for dimensions must be loaded in a Prs3d_Drawer.
31 //!
32 //! You can make use of classes of standard Interactive Objects for which all necessary methods have already been programmed,
33 //! or you can implement your own classes of Interactive Objects.
34 //! Key interface methods to be implemented by every Interactive Object:
35 //! * Presentable Object (PrsMgr_PresentableObject)
36 //!   Consider defining an enumeration of supported Display Mode indexes for particular Interactive Object or class of Interactive Objects.
37 //!   - AcceptDisplayMode() accepting display modes implemented by this object;
38 //!   - Compute() computing presentation for the given display mode index;
39 //! * Selectable Object (SelectMgr_SelectableObject)
40 //!   Consider defining an enumeration of supported Selection Mode indexes for particular Interactive Object or class of Interactive Objects.
41 //!   - ComputeSelection() computing selectable entities for the given selection mode index.
42 class AIS_InteractiveObject : public SelectMgr_SelectableObject
43 {
44   friend class AIS_InteractiveContext;
45   DEFINE_STANDARD_RTTIEXT(AIS_InteractiveObject, SelectMgr_SelectableObject)
46 public:
47
48   //! Returns the kind of Interactive Object; AIS_KOI_None by default.
49   virtual AIS_KindOfInteractive Type() const { return AIS_KOI_None; }
50
51   //! Specifies additional characteristics of Interactive Object of Type(); -1 by default.
52   //! Among the datums, this signature is attributed to the shape.
53   //! The remaining datums have the following default signatures:
54   //! - Point          signature 1
55   //! - Axis           signature 2
56   //! - Trihedron      signature 3
57   //! - PlaneTrihedron signature 4
58   //! - Line           signature 5
59   //! - Circle         signature 6
60   //! - Plane          signature 7.
61   virtual Standard_Integer Signature() const { return -1; }
62   
63   //! Updates the active presentation; if <AllModes> = Standard_True
64   //! all the presentations inside are recomputed.
65   //! IMPORTANT: It is preferable to call Redisplay method of
66   //! corresponding AIS_InteractiveContext instance for cases when it
67   //! is accessible. This method just redirects call to myCTXPtr,
68   //! so this class field must be up to date for proper result.
69   Standard_EXPORT void Redisplay (const Standard_Boolean AllModes = Standard_False);
70
71   //! Indicates whether the Interactive Object has a pointer to an interactive context.
72   Standard_Boolean HasInteractiveContext() const { return myCTXPtr != NULL; }
73
74   //! Returns the context pointer to the interactive context.
75   AIS_InteractiveContext* InteractiveContext() const { return myCTXPtr; }
76   
77   //! Sets the interactive context aCtx and provides a link
78   //! to the default drawing tool or "Drawer" if there is none.
79   Standard_EXPORT virtual void SetContext (const Handle(AIS_InteractiveContext)& aCtx);
80   
81   //! Returns true if the object has an owner attributed to it.
82   //! The owner can be a shape for a set of sub-shapes or a sub-shape for sub-shapes which it is composed of, and takes the form of a transient.
83   Standard_Boolean HasOwner() const { return !myOwner.IsNull(); }
84   
85   //! Returns the owner of the Interactive Object.
86   //! The owner can be a shape for a set of sub-shapes or
87   //! a sub-shape for sub-shapes which it is composed of,
88   //! and takes the form of a transient.
89   //! There are two types of owners:
90   //! -   Direct owners, decomposition shapes such as
91   //! edges, wires, and faces.
92   //! -   Users, presentable objects connecting to sensitive
93   //! primitives, or a shape which has been decomposed.
94   const Handle(Standard_Transient)& GetOwner() const { return myOwner; }
95
96   //! Allows you to attribute the owner theApplicativeEntity to
97   //! an Interactive Object. This can be a shape for a set of
98   //! sub-shapes or a sub-shape for sub-shapes which it
99   //! is composed of. The owner takes the form of a transient.
100   void SetOwner (const Handle(Standard_Transient)& theApplicativeEntity) { myOwner = theApplicativeEntity; }
101
102   //! Each Interactive Object has methods which allow us to attribute an Owner to it in the form of a Transient.
103   //! This method removes the owner from the graphic entity.
104   void ClearOwner() { myOwner.Nullify(); }
105
106 public:
107
108   //! Returns the context pointer to the interactive context.
109   Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const;
110
111   //! Returns TRUE when this object has a presentation in the current DisplayMode()
112   Standard_EXPORT Standard_Boolean HasPresentation() const;
113
114   //! Returns the current presentation of this object according to the current DisplayMode()
115   Standard_EXPORT Handle(Prs3d_Presentation) Presentation() const;
116
117   //! Sets the graphic basic aspect to the current presentation.
118   Standard_DEPRECATED("Deprecated method, results might be undefined")
119   Standard_EXPORT void SetAspect (const Handle(Prs3d_BasicAspect)& anAspect);
120
121   //! Dumps the content of me into the stream
122   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const Standard_OVERRIDE;
123 protected:
124
125   //! The TypeOfPresention3d means that the interactive object
126   //! may have a presentation dependant of the view of Display.
127   Standard_EXPORT AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
128
129 protected:
130
131   AIS_InteractiveContext*    myCTXPtr; //!< pointer to Interactive Context, where object is currently displayed; @sa SetContext()
132   Handle(Standard_Transient) myOwner;  //!< application-specific owner object
133
134 };
135
136 DEFINE_STANDARD_HANDLE(AIS_InteractiveObject, SelectMgr_SelectableObject)
137
138 #endif // _AIS_InteractiveObject_HeaderFile