b311480e |
1 | // Created on: 1996-12-18 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
f838dac4 |
17 | #include <AIS_InteractiveObject.hxx> |
7fd59977 |
18 | |
42cf5bc1 |
19 | #include <AIS_InteractiveContext.hxx> |
7fd59977 |
20 | #include <Graphic3d_AspectFillArea3d.hxx> |
3ddebf91 |
21 | #include <Graphic3d_AspectLine3d.hxx> |
22 | #include <Graphic3d_AspectMarker3d.hxx> |
23 | #include <Graphic3d_AspectText3d.hxx> |
f751596e |
24 | #include <Graphic3d_CStructure.hxx> |
7fd59977 |
25 | #include <Graphic3d_Group.hxx> |
26 | #include <Graphic3d_Structure.hxx> |
42cf5bc1 |
27 | #include <Prs3d_LineAspect.hxx> |
28 | #include <Prs3d_PointAspect.hxx> |
29 | #include <Prs3d_Presentation.hxx> |
42cf5bc1 |
30 | #include <Prs3d_ShadingAspect.hxx> |
31 | #include <Prs3d_TextAspect.hxx> |
2b886265 |
32 | #include <PrsMgr_PresentationManager.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveObject,SelectMgr_SelectableObject) |
35 | |
7fd59977 |
36 | //======================================================================= |
37 | //function : AIS_InteractiveObject |
38 | //purpose : |
39 | //======================================================================= |
f838dac4 |
40 | AIS_InteractiveObject::AIS_InteractiveObject (const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d) |
41 | : SelectMgr_SelectableObject (aTypeOfPresentation3d), |
2b886265 |
42 | myCTXPtr (NULL) |
7fd59977 |
43 | { |
2b886265 |
44 | // |
7fd59977 |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Redisplay |
36132a2e |
49 | //purpose : |
7fd59977 |
50 | //======================================================================= |
36132a2e |
51 | void AIS_InteractiveObject::Redisplay (const Standard_Boolean AllModes) |
7fd59977 |
52 | { |
36132a2e |
53 | if (myCTXPtr == NULL) |
54 | return; |
55 | |
56 | myCTXPtr->Redisplay (this, Standard_False, AllModes); |
7fd59977 |
57 | } |
58 | |
7fd59977 |
59 | //======================================================================= |
60 | //function : |
61 | //purpose : |
62 | //======================================================================= |
63 | Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const |
64 | { |
65 | return myCTXPtr; |
66 | } |
67 | |
68 | //======================================================================= |
2ec85268 |
69 | //function : SetContext |
70 | //purpose : |
7fd59977 |
71 | //======================================================================= |
2ec85268 |
72 | void AIS_InteractiveObject::SetContext (const Handle(AIS_InteractiveContext)& theCtx) |
7fd59977 |
73 | { |
2ec85268 |
74 | if (myCTXPtr == theCtx.get()) |
75 | { |
da0e82aa |
76 | return; |
2ec85268 |
77 | } |
78 | |
79 | myCTXPtr = theCtx.get(); |
80 | if (!theCtx.IsNull()) |
81 | { |
82 | myDrawer->Link (theCtx->DefaultDrawer()); |
83 | } |
7fd59977 |
84 | } |
85 | |
7fd59977 |
86 | //======================================================================= |
87 | //function : HasPresentation |
af324faa |
88 | //purpose : |
7fd59977 |
89 | //======================================================================= |
af324faa |
90 | Standard_Boolean AIS_InteractiveObject::HasPresentation() const |
91 | { |
f838dac4 |
92 | return HasInteractiveContext() |
93 | && myCTXPtr->MainPrsMgr()->HasPresentation (this, myDrawer->DisplayMode()); |
7fd59977 |
94 | } |
95 | |
96 | //======================================================================= |
97 | //function : Presentation |
af324faa |
98 | //purpose : |
7fd59977 |
99 | //======================================================================= |
af324faa |
100 | Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const |
101 | { |
f838dac4 |
102 | if (!HasInteractiveContext()) |
103 | { |
104 | return Handle(Prs3d_Presentation)(); |
105 | } |
106 | |
107 | Handle(PrsMgr_Presentation) aPrs = myCTXPtr->MainPrsMgr()->Presentation (this, myDrawer->DisplayMode(), false); |
7dd7c146 |
108 | return aPrs; |
7fd59977 |
109 | } |
110 | |
111 | //======================================================================= |
112 | //function : SetAspect |
113 | //purpose : |
114 | //======================================================================= |
2b886265 |
115 | void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& theAspect) |
2831708b |
116 | { |
7fd59977 |
117 | |
2b886265 |
118 | if (!HasPresentation()) |
119 | { |
120 | return; |
7fd59977 |
121 | } |
7fd59977 |
122 | |
2b886265 |
123 | Handle(Prs3d_Presentation) aPrs = Presentation(); |
124 | if (aPrs->Groups().IsEmpty()) |
f751596e |
125 | { |
2b886265 |
126 | return; |
f751596e |
127 | } |
2b886265 |
128 | const Handle(Graphic3d_Group)& aGroup = aPrs->Groups().Last(); |
129 | if (Handle(Prs3d_ShadingAspect) aShadingAspect = Handle(Prs3d_ShadingAspect)::DownCast(theAspect)) |
f751596e |
130 | { |
2b886265 |
131 | aGroup->SetGroupPrimitivesAspect (aShadingAspect->Aspect()); |
f751596e |
132 | } |
2b886265 |
133 | else if (Handle(Prs3d_LineAspect) aLineAspect = Handle(Prs3d_LineAspect)::DownCast(theAspect)) |
fb66bb28 |
134 | { |
2b886265 |
135 | aGroup->SetGroupPrimitivesAspect (aLineAspect->Aspect()); |
fb66bb28 |
136 | } |
2b886265 |
137 | else if (Handle(Prs3d_PointAspect) aPointAspect = Handle(Prs3d_PointAspect)::DownCast(theAspect)) |
bf5f0ca2 |
138 | { |
2b886265 |
139 | aGroup->SetGroupPrimitivesAspect (aPointAspect->Aspect()); |
bf5f0ca2 |
140 | } |
2b886265 |
141 | else if (Handle(Prs3d_TextAspect) aTextAspect = Handle(Prs3d_TextAspect)::DownCast(theAspect)) |
bf5f0ca2 |
142 | { |
2b886265 |
143 | aGroup->SetGroupPrimitivesAspect (aTextAspect->Aspect()); |
bf5f0ca2 |
144 | } |
145 | } |
0904aa63 |
146 | |
147 | //======================================================================= |
148 | //function : DumpJson |
149 | //purpose : |
150 | //======================================================================= |
bc73b006 |
151 | void AIS_InteractiveObject::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
0904aa63 |
152 | { |
bc73b006 |
153 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
0904aa63 |
154 | |
bc73b006 |
155 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, SelectMgr_SelectableObject) |
156 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myCTXPtr) |
157 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myOwner) |
0904aa63 |
158 | } |