1 // Created on: 1996-12-18
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 #include <AIS_InteractiveObject.hxx>
18
19 #include <AIS_InteractiveContext.hxx>
20 #include <Graphic3d_AspectFillArea3d.hxx>
21 #include <Graphic3d_AspectLine3d.hxx>
22 #include <Graphic3d_AspectMarker3d.hxx>
23 #include <Graphic3d_AspectText3d.hxx>
24 #include <Graphic3d_CStructure.hxx>
25 #include <Graphic3d_Group.hxx>
26 #include <Graphic3d_Structure.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_PointAspect.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <Prs3d_ShadingAspect.hxx>
31 #include <Prs3d_TextAspect.hxx>
32 #include <PrsMgr_PresentationManager.hxx>
33
IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveObject,SelectMgr_SelectableObject)34 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveObject,SelectMgr_SelectableObject)
35
36 //=======================================================================
37 //function : AIS_InteractiveObject
38 //purpose :
39 //=======================================================================
40 AIS_InteractiveObject::AIS_InteractiveObject (const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
41 : SelectMgr_SelectableObject (aTypeOfPresentation3d),
42 myCTXPtr (NULL)
43 {
44 //
45 }
46
47 //=======================================================================
48 //function : Redisplay
49 //purpose :
50 //=======================================================================
Redisplay(const Standard_Boolean AllModes)51 void AIS_InteractiveObject::Redisplay (const Standard_Boolean AllModes)
52 {
53 if (myCTXPtr == NULL)
54 return;
55
56 myCTXPtr->Redisplay (this, Standard_False, AllModes);
57 }
58
59 //=======================================================================
60 //function : ProcessDragging
61 //purpose :
62 //=======================================================================
ProcessDragging(const Handle (AIS_InteractiveContext)&,const Handle (V3d_View)&,const Handle (SelectMgr_EntityOwner)&,const Graphic3d_Vec2i &,const Graphic3d_Vec2i &,const AIS_DragAction)63 Standard_Boolean AIS_InteractiveObject::ProcessDragging (const Handle(AIS_InteractiveContext)&,
64 const Handle(V3d_View)&,
65 const Handle(SelectMgr_EntityOwner)&,
66 const Graphic3d_Vec2i&,
67 const Graphic3d_Vec2i&,
68 const AIS_DragAction)
69 {
70 return Standard_False;
71 }
72
73 //=======================================================================
74 //function :
75 //purpose :
76 //=======================================================================
Handle(AIS_InteractiveContext)77 Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const
78 {
79 return myCTXPtr;
80 }
81
82 //=======================================================================
83 //function : SetContext
84 //purpose :
85 //=======================================================================
SetContext(const Handle (AIS_InteractiveContext)& theCtx)86 void AIS_InteractiveObject::SetContext (const Handle(AIS_InteractiveContext)& theCtx)
87 {
88 if (myCTXPtr == theCtx.get())
89 {
90 return;
91 }
92
93 myCTXPtr = theCtx.get();
94 if (!theCtx.IsNull())
95 {
96 myDrawer->Link (theCtx->DefaultDrawer());
97 }
98 }
99
100 //=======================================================================
101 //function : SetDisplayStatus
102 //purpose :
103 //=======================================================================
SetDisplayStatus(PrsMgr_DisplayStatus theStatus)104 void AIS_InteractiveObject::SetDisplayStatus (PrsMgr_DisplayStatus theStatus)
105 {
106 myDisplayStatus = theStatus;
107 }
108
109 //=======================================================================
110 //function : HasPresentation
111 //purpose :
112 //=======================================================================
HasPresentation() const113 Standard_Boolean AIS_InteractiveObject::HasPresentation() const
114 {
115 return HasInteractiveContext()
116 && myCTXPtr->MainPrsMgr()->HasPresentation (this, myDrawer->DisplayMode());
117 }
118
119 //=======================================================================
120 //function : Presentation
121 //purpose :
122 //=======================================================================
Handle(Prs3d_Presentation)123 Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const
124 {
125 if (!HasInteractiveContext())
126 {
127 return Handle(Prs3d_Presentation)();
128 }
129
130 Handle(PrsMgr_Presentation) aPrs = myCTXPtr->MainPrsMgr()->Presentation (this, myDrawer->DisplayMode(), false);
131 return aPrs;
132 }
133
134 //=======================================================================
135 //function : SetAspect
136 //purpose :
137 //=======================================================================
SetAspect(const Handle (Prs3d_BasicAspect)& theAspect)138 void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& theAspect)
139 {
140
141 if (!HasPresentation())
142 {
143 return;
144 }
145
146 Handle(Prs3d_Presentation) aPrs = Presentation();
147 if (aPrs->Groups().IsEmpty())
148 {
149 return;
150 }
151 const Handle(Graphic3d_Group)& aGroup = aPrs->Groups().Last();
152 if (Handle(Prs3d_ShadingAspect) aShadingAspect = Handle(Prs3d_ShadingAspect)::DownCast(theAspect))
153 {
154 aGroup->SetGroupPrimitivesAspect (aShadingAspect->Aspect());
155 }
156 else if (Handle(Prs3d_LineAspect) aLineAspect = Handle(Prs3d_LineAspect)::DownCast(theAspect))
157 {
158 aGroup->SetGroupPrimitivesAspect (aLineAspect->Aspect());
159 }
160 else if (Handle(Prs3d_PointAspect) aPointAspect = Handle(Prs3d_PointAspect)::DownCast(theAspect))
161 {
162 aGroup->SetGroupPrimitivesAspect (aPointAspect->Aspect());
163 }
164 else if (Handle(Prs3d_TextAspect) aTextAspect = Handle(Prs3d_TextAspect)::DownCast(theAspect))
165 {
166 aGroup->SetGroupPrimitivesAspect (aTextAspect->Aspect());
167 }
168 }
169
170 //=======================================================================
171 //function : DumpJson
172 //purpose :
173 //=======================================================================
DumpJson(Standard_OStream & theOStream,Standard_Integer theDepth) const174 void AIS_InteractiveObject::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
175 {
176 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
177
178 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, SelectMgr_SelectableObject)
179 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myCTXPtr)
180 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myOwner)
181 }
182