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