b311480e |
1 | // Created on: 1998-09-30 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1998-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 | |
42cf5bc1 |
17 | |
18 | #include <AIS_InteractiveContext.hxx> |
19 | #include <Standard_GUID.hxx> |
20 | #include <Standard_Type.hxx> |
21 | #include <TDF_Attribute.hxx> |
f47afe53 |
22 | #include <TDF_ChildIterator.hxx> |
7fd59977 |
23 | #include <TDF_Label.hxx> |
42cf5bc1 |
24 | #include <TDF_RelocationTable.hxx> |
f47afe53 |
25 | #include <TDataXtd_Presentation.hxx> |
26 | #include <TPrsStd_AISPresentation.hxx> |
42cf5bc1 |
27 | #include <TPrsStd_AISViewer.hxx> |
28 | #include <V3d_Viewer.hxx> |
7fd59977 |
29 | |
92efcf78 |
30 | IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_AISViewer,TDF_Attribute) |
31 | |
7fd59977 |
32 | //======================================================================= |
33 | //function : GetID |
34 | //purpose : |
35 | //======================================================================= |
7fd59977 |
36 | const Standard_GUID& TPrsStd_AISViewer::GetID () |
37 | { |
38 | static Standard_GUID TPrsStd_AISViewerID("04fb4d05-5690-11d1-8940-080009dc3333"); |
39 | return TPrsStd_AISViewerID; |
40 | } |
41 | //======================================================================= |
42 | //function : New |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces, |
47 | const Handle(V3d_Viewer)& viewer) |
48 | { |
49 | Handle(TPrsStd_AISViewer) V; |
50 | if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { |
51 | Standard_DomainError::Raise("already done"); |
52 | } |
53 | V = new TPrsStd_AISViewer(); |
54 | V->SetInteractiveContext (new AIS_InteractiveContext(viewer)); |
55 | acces.Root().AddAttribute(V); |
f47afe53 |
56 | |
57 | // put TPrsStd_AISPresentation attribute at all labels containing |
58 | // TDataXtd_Presentation attribute |
59 | for (TDF_ChildIterator anIt(acces.Root(), Standard_True); anIt.More(); anIt.Next()) |
60 | { |
61 | Handle(TDataXtd_Presentation) aPrsData; |
62 | if (anIt.Value().FindAttribute(TDataXtd_Presentation::GetID(), aPrsData)) { |
63 | TPrsStd_AISPresentation::Set (anIt.Value(), aPrsData->GetDriverGUID()); |
64 | } |
65 | } |
66 | |
7fd59977 |
67 | return V; |
68 | } |
69 | |
70 | //======================================================================= |
71 | //function : New |
72 | //purpose : |
73 | //======================================================================= |
74 | Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces, |
75 | const Handle(AIS_InteractiveContext)& IC) |
76 | { |
77 | Handle(TPrsStd_AISViewer) V; |
78 | if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { |
79 | Standard_DomainError::Raise("already done"); |
80 | } |
81 | V = new TPrsStd_AISViewer(); |
82 | V->SetInteractiveContext (IC); |
83 | acces.Root().AddAttribute(V); |
f47afe53 |
84 | |
85 | // put TPrsStd_AISPresentation attribute at all labels containing |
86 | // TDataXtd_Presentation attribute |
87 | for (TDF_ChildIterator anIt(acces.Root(), Standard_True); anIt.More(); anIt.Next()) |
88 | { |
89 | Handle(TDataXtd_Presentation) aPrsData; |
90 | if (anIt.Value().FindAttribute(TDataXtd_Presentation::GetID(), aPrsData)) { |
91 | TPrsStd_AISPresentation::Set (anIt.Value(), aPrsData->GetDriverGUID()); |
92 | } |
93 | } |
94 | |
7fd59977 |
95 | return V; |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : Find |
100 | //purpose : |
101 | //======================================================================= |
102 | Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, |
103 | Handle(TPrsStd_AISViewer)& V) |
104 | { |
105 | return (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)); |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : Find |
110 | //purpose : |
111 | //======================================================================= |
112 | Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, |
113 | Handle(AIS_InteractiveContext)& IC) |
114 | { |
115 | Handle(TPrsStd_AISViewer) V; |
116 | if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { |
117 | IC = V->GetInteractiveContext(); |
118 | return Standard_True; |
119 | } |
120 | return Standard_False; |
121 | } |
122 | |
123 | //======================================================================= |
124 | //function : Find |
125 | //purpose : |
126 | //======================================================================= |
127 | |
128 | Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, |
129 | Handle(V3d_Viewer)& VIEW) |
130 | { |
131 | Handle(TPrsStd_AISViewer) V; |
132 | if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { |
133 | VIEW = V->GetInteractiveContext()->CurrentViewer(); |
134 | return Standard_True; |
135 | } |
136 | return Standard_False; |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : Has |
141 | //purpose : |
142 | //======================================================================= |
143 | Standard_Boolean TPrsStd_AISViewer::Has (const TDF_Label& acces) |
144 | { |
145 | return (acces.Root().IsAttribute(TPrsStd_AISViewer::GetID())); |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : Update |
150 | //purpose : |
151 | //======================================================================= |
152 | void TPrsStd_AISViewer::Update (const TDF_Label& acces) |
153 | { |
154 | Handle(TPrsStd_AISViewer) viewer; |
155 | if (Find (acces,viewer)) viewer->Update(); |
156 | } |
157 | |
158 | |
159 | //======================================================================= |
160 | //function : TPrsStd_AISViewer |
161 | //purpose : |
162 | //======================================================================= |
163 | |
164 | TPrsStd_AISViewer::TPrsStd_AISViewer() |
165 | { |
166 | } |
167 | |
168 | //======================================================================= |
169 | //function : Update |
170 | //purpose : |
171 | //======================================================================= |
172 | |
173 | void TPrsStd_AISViewer::Update () const |
174 | { |
175 | myInteractiveContext->UpdateCurrentViewer(); |
176 | } |
177 | |
178 | //======================================================================= |
179 | //function : SetInteractiveContext |
180 | //purpose : |
181 | //======================================================================= |
182 | |
183 | void TPrsStd_AISViewer::SetInteractiveContext(const Handle(AIS_InteractiveContext)& ctx) |
184 | { |
185 | myInteractiveContext = ctx; |
186 | } |
187 | |
188 | //======================================================================= |
189 | //function : GetInteractiveContext |
190 | //purpose : |
191 | //======================================================================= |
192 | |
193 | Handle(AIS_InteractiveContext) TPrsStd_AISViewer::GetInteractiveContext() const |
194 | { |
195 | return myInteractiveContext; |
196 | } |
197 | |
198 | |
199 | //======================================================================= |
200 | //function : ID |
201 | //purpose : |
202 | //======================================================================= |
203 | |
204 | const Standard_GUID& TPrsStd_AISViewer::ID() const { return GetID(); } |
205 | |
206 | |
207 | //======================================================================= |
208 | //function : Restore |
209 | //purpose : |
210 | //======================================================================= |
211 | |
35e08fe8 |
212 | void TPrsStd_AISViewer::Restore(const Handle(TDF_Attribute)&) |
7fd59977 |
213 | { |
214 | } |
215 | |
216 | //======================================================================= |
217 | //function : NewEmpty |
218 | //purpose : |
219 | //======================================================================= |
220 | |
221 | Handle(TDF_Attribute) TPrsStd_AISViewer::NewEmpty() const |
222 | { |
223 | return new TPrsStd_AISViewer(); |
224 | } |
225 | |
226 | //======================================================================= |
227 | //function : Paste |
228 | //purpose : |
229 | //======================================================================= |
230 | |
35e08fe8 |
231 | void TPrsStd_AISViewer::Paste (const Handle(TDF_Attribute)&, |
232 | const Handle(TDF_RelocationTable)&) const |
7fd59977 |
233 | { |
234 | } |
235 | |
236 | |