b311480e |
1 | // Created on: 1998-09-23 |
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 <DDataStd_DrawDriver.hxx> |
19 | #include <DDataStd_DrawPresentation.hxx> |
7fd59977 |
20 | #include <Draw.hxx> |
42cf5bc1 |
21 | #include <Draw_Drawable3D.hxx> |
7fd59977 |
22 | #include <Draw_Viewer.hxx> |
42cf5bc1 |
23 | #include <Standard_GUID.hxx> |
24 | #include <Standard_Type.hxx> |
25 | #include <TDF_Attribute.hxx> |
26 | #include <TDF_AttributeDelta.hxx> |
7fd59977 |
27 | #include <TDF_DefaultDeltaOnModification.hxx> |
28 | #include <TDF_DefaultDeltaOnRemoval.hxx> |
29 | #include <TDF_DeltaOnAddition.hxx> |
42cf5bc1 |
30 | #include <TDF_Label.hxx> |
31 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
32 | #include <TDF_Tool.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(DDataStd_DrawPresentation,TDF_Attribute) |
35 | |
57c28b61 |
36 | #ifndef _WIN32 |
7fd59977 |
37 | extern Draw_Viewer dout; |
38 | #else |
39 | Standard_IMPORT Draw_Viewer dout; |
40 | #endif |
41 | //======================================================================= |
42 | //function : IsDisplayed |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | Standard_Boolean DDataStd_DrawPresentation::IsDisplayed (const TDF_Label& L) |
47 | { |
48 | Handle(DDataStd_DrawPresentation) P; |
49 | if (L.FindAttribute(DDataStd_DrawPresentation::GetID(),P)) { |
50 | return P->IsDisplayed(); |
51 | } |
52 | return Standard_False; |
53 | } |
54 | |
55 | |
56 | //======================================================================= |
57 | //function : HasPresentation |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | Standard_Boolean DDataStd_DrawPresentation::HasPresentation (const TDF_Label& L) |
62 | { |
63 | return (L.IsAttribute(DDataStd_DrawPresentation::GetID())); |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : Display |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | void DDataStd_DrawPresentation::Display (const TDF_Label& L) |
72 | { |
73 | Handle(DDataStd_DrawPresentation) P; |
74 | // set |
75 | if (!L.FindAttribute(DDataStd_DrawPresentation::GetID(),P)) { |
76 | P = new DDataStd_DrawPresentation (); |
77 | L.AddAttribute(P); |
78 | } |
79 | // display |
80 | if (P->IsDisplayed()) return; |
81 | if (P->GetDrawable().IsNull()) P->DrawBuild(); |
82 | DrawDisplay (P->Label(),P); |
83 | P->SetDisplayed(Standard_True); |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : Erase |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | void DDataStd_DrawPresentation::Erase(const TDF_Label& L) |
92 | { |
93 | Handle(DDataStd_DrawPresentation) P; |
94 | if (L.FindAttribute(DDataStd_DrawPresentation::GetID(),P)) { |
95 | if (P->IsDisplayed()) { |
96 | DrawErase (P->Label(),P); |
97 | P->SetDisplayed(Standard_False); |
98 | } |
99 | } |
100 | } |
101 | |
102 | //======================================================================= |
103 | //function : Update |
104 | //purpose : |
105 | //======================================================================= |
106 | |
107 | void DDataStd_DrawPresentation::Update (const TDF_Label& L) |
108 | { |
109 | Handle(DDataStd_DrawPresentation) P; |
110 | if (L.FindAttribute(DDataStd_DrawPresentation::GetID(),P)) { |
111 | DrawErase(P->Label(),P); |
112 | P->Backup(); |
113 | P->DrawBuild(); |
114 | DrawDisplay (P->Label(),P); |
115 | P->SetDisplayed(Standard_True); |
116 | } |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : GetID |
121 | //purpose : idem GUID DDataStd Display |
122 | //======================================================================= |
123 | |
124 | const Standard_GUID& DDataStd_DrawPresentation::GetID() |
125 | { |
126 | static Standard_GUID DDataStd_DrawPresentationID("1c0296d4-6dbc-22d4-b9c8-0070b0ee301b"); |
127 | return DDataStd_DrawPresentationID; |
128 | } |
129 | |
130 | |
131 | //======================================================================= |
132 | //function : DDataStd_DrawPresentation |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | DDataStd_DrawPresentation::DDataStd_DrawPresentation () : isDisplayed(Standard_False) {} |
137 | |
138 | |
139 | //======================================================================= |
140 | //function : SetDisplayed |
141 | //purpose : |
142 | //======================================================================= |
143 | |
144 | void DDataStd_DrawPresentation::SetDisplayed (const Standard_Boolean status) |
145 | { |
146 | isDisplayed = status; |
147 | } |
148 | |
149 | //======================================================================= |
150 | //function : IsDisplayed |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | Standard_Boolean DDataStd_DrawPresentation::IsDisplayed () const |
155 | { |
156 | return isDisplayed; |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : SetDrawable |
161 | //purpose : |
162 | //======================================================================= |
163 | |
164 | void DDataStd_DrawPresentation::SetDrawable (const Handle(Draw_Drawable3D)& D) |
165 | { |
166 | myDrawable = D; |
167 | } |
168 | |
169 | //======================================================================= |
170 | //function : GetDrawable |
171 | //purpose : |
172 | //======================================================================= |
173 | |
174 | Handle(Draw_Drawable3D) DDataStd_DrawPresentation::GetDrawable () const |
175 | { |
176 | return myDrawable; |
177 | } |
178 | |
179 | //======================================================================= |
180 | //function : ID |
181 | //purpose : |
182 | //======================================================================= |
183 | |
184 | const Standard_GUID& DDataStd_DrawPresentation::ID() const { return GetID(); } |
185 | |
186 | |
187 | //======================================================================= |
188 | //function : NewEmpty |
189 | //purpose : |
190 | //======================================================================= |
191 | |
192 | Handle(TDF_Attribute) DDataStd_DrawPresentation::NewEmpty() const |
193 | { |
194 | return new DDataStd_DrawPresentation (); |
195 | } |
196 | |
197 | //======================================================================= |
198 | //function : Restore |
199 | //purpose : |
200 | //======================================================================= |
201 | |
202 | void DDataStd_DrawPresentation::Restore (const Handle(TDF_Attribute)& With) |
203 | { |
204 | //cout<< "DDataStd_DrawPresentation::Restore" << endl; |
205 | isDisplayed = Handle(DDataStd_DrawPresentation)::DownCast (With)->IsDisplayed(); |
206 | myDrawable = Handle(DDataStd_DrawPresentation)::DownCast (With)->GetDrawable(); |
207 | } |
208 | |
209 | //======================================================================= |
210 | //function : Paste |
211 | //purpose : |
212 | //======================================================================= |
213 | |
214 | void DDataStd_DrawPresentation::Paste (const Handle(TDF_Attribute)& Into, |
35e08fe8 |
215 | const Handle(TDF_RelocationTable)&) const |
7fd59977 |
216 | { |
7fd59977 |
217 | Handle(DDataStd_DrawPresentation)::DownCast(Into)->SetDisplayed(isDisplayed); |
218 | Handle(DDataStd_DrawPresentation)::DownCast(Into)->SetDrawable(myDrawable); |
219 | } |
220 | |
221 | //======================================================================= |
222 | //function : AfterAddition |
223 | //purpose : erase if displayed |
224 | //======================================================================= |
225 | |
226 | void DDataStd_DrawPresentation::AfterAddition() |
227 | { |
228 | //cout<< "DDataStd_DrawPresentation::AfterAddition" << endl; |
229 | //if (isDisplayed) DrawDisplay (); |
230 | } |
231 | |
232 | //======================================================================= |
233 | //function : BeforeRemoval |
234 | //purpose : erase if displayed |
235 | //======================================================================= |
236 | |
237 | void DDataStd_DrawPresentation::BeforeRemoval() |
238 | { |
239 | //cout<< "DDataStd_DrawPresentation::BeforeRemoval" << endl; |
240 | //if (isDisplayed) DrawErase (); |
241 | } |
242 | |
243 | //======================================================================= |
244 | //function : BeforeForget |
245 | //purpose : erase if displayed |
246 | //======================================================================= |
247 | |
248 | void DDataStd_DrawPresentation::BeforeForget() |
249 | { |
250 | //cout<< "DDataStd_DrawPresentation::BeforeForget" << endl; |
251 | if (isDisplayed) DrawErase (Label(),this); |
252 | } |
253 | |
254 | |
255 | //======================================================================= |
256 | //function : AfterResume |
257 | //purpose : display if displayed |
258 | //======================================================================= |
259 | |
260 | void DDataStd_DrawPresentation::AfterResume() |
261 | { |
262 | //cout<< "DDataStd_DrawPresentation::AfterResume"<< endl; |
263 | if (isDisplayed) DrawDisplay (Label(),this); |
264 | } |
265 | |
266 | //======================================================================= |
267 | //function : BeforeUndo |
0d969553 |
268 | //purpose : the associated NamedShape should be present |
7fd59977 |
269 | //======================================================================= |
270 | |
271 | Standard_Boolean DDataStd_DrawPresentation::BeforeUndo (const Handle(TDF_AttributeDelta)& AD, |
35e08fe8 |
272 | const Standard_Boolean /*forceIt*/) |
7fd59977 |
273 | { |
274 | Handle(DDataStd_DrawPresentation) Pme = this; |
275 | Handle(DDataStd_DrawPresentation) Pdt = Handle(DDataStd_DrawPresentation)::DownCast(AD->Attribute()); |
276 | Handle(DDataStd_DrawPresentation) Pfw; |
277 | if (AD->Label().FindAttribute(GetID(),Pfw)) { |
278 | //cout<< "DDataStd_DrawPresentation::BeforeUndo : attribute in framework" << endl; |
279 | } |
280 | else { |
281 | //cout<< "DDataStd_DrawPresentation::BeforeUndo : attribute not in framework" << endl; |
282 | } |
283 | // |
284 | if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) { |
285 | //cout<< "DDataStd_DrawPresentation::BeforeUndo : delta on addition" << endl; |
286 | if (Pfw->IsDisplayed()) DrawErase(AD->Label(),Pfw); |
287 | //TDF appelle BeforeRemoval effacer |
288 | } |
289 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) { |
290 | //cout<< "DDataStd_DrawPresentation::BeforeUndo : delta on removal" << endl; |
291 | } |
292 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) { |
293 | //cout<< "DDataStd_DrawPresentation::BeforeUndo : delta on modification" << endl; |
294 | if (Pfw->IsDisplayed()) DrawErase(AD->Label(),Pfw); |
295 | } |
296 | else { |
297 | //cout<< "DDataStd_DrawPresentation::BeforeUndo : unknown delta" << endl; |
298 | } |
299 | //if (Label().IsNull()) cout<< "DDataStd_DrawPresentation::BeforeUndo : null label" << endl; |
300 | return Standard_True; |
301 | } |
302 | |
303 | |
304 | //======================================================================= |
305 | //function : AfterUndo |
0d969553 |
306 | //purpose : associated NamedShape should be present |
7fd59977 |
307 | //======================================================================= |
308 | |
309 | Standard_Boolean DDataStd_DrawPresentation::AfterUndo (const Handle(TDF_AttributeDelta)& AD, |
35e08fe8 |
310 | const Standard_Boolean /*forceIt*/) |
7fd59977 |
311 | { |
312 | Handle(DDataStd_DrawPresentation) Pme = this; |
313 | Handle(DDataStd_DrawPresentation) Pdt = Handle(DDataStd_DrawPresentation)::DownCast(AD->Attribute()); |
314 | Handle(DDataStd_DrawPresentation) Pfw; |
315 | if (AD->Label().FindAttribute(GetID(),Pfw)) { |
316 | //cout<< "DDataStd_DrawPresentation::AfterUndo : attribute in framework" << endl; |
317 | } |
318 | else { |
319 | //cout<< "DDataStd_DrawPresentation::AfterUndo : attribute not in framework" << endl; |
320 | } |
321 | |
322 | // |
323 | if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) { |
324 | //cout<< "DDataStd_DrawPresentation::AfterUndo : delta on addition" << endl; |
325 | } |
326 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) { |
327 | //cout<< "DDataStd_DrawPresentation::AfterUndo : delta on removal" << endl; |
328 | if (Pdt->IsDisplayed()) DrawDisplay(AD->Label(),Pdt); |
329 | } |
330 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) { |
331 | //cout<< "DDataStd_DrawPresentation::AfterUndo : delta on modification" << endl; |
332 | if (Pdt->IsDisplayed()) DrawDisplay(AD->Label(),Pdt); |
333 | } |
334 | else { |
335 | //cout<< "DDataStd_DrawPresentation::AfterUndo : unknown delta" << endl; |
336 | } |
337 | //if (Label().IsNull()) cout<< "DDataStd_DrawPresentation::AfterUndo : null label" << endl; |
338 | return Standard_True; |
339 | } |
340 | |
341 | |
342 | |
343 | //======================================================================= |
344 | //function : DrawBuild |
345 | //purpose : |
346 | //======================================================================= |
347 | |
348 | void DDataStd_DrawPresentation::DrawBuild () |
349 | { |
350 | //cout<< "DDataStd_DrawPresentation::DrawBuild" << endl; |
351 | Handle(DDataStd_DrawDriver) DD = DDataStd_DrawDriver::Get(); |
352 | if (DD.IsNull()) { |
353 | DD = new DDataStd_DrawDriver (); |
354 | DDataStd_DrawDriver::Set(DD); |
355 | } |
356 | Handle(Draw_Drawable3D) D3D = DD->Drawable(Label()); |
357 | if (D3D.IsNull()) cout<< "DDataStd_DrawPresentation::DrawBuild : null drawable" << endl; |
358 | myDrawable = D3D; |
359 | } |
360 | |
361 | |
362 | |
363 | //======================================================================= |
364 | //function : DrawDisplay |
365 | //purpose : |
366 | //======================================================================= |
367 | |
368 | void DDataStd_DrawPresentation::DrawDisplay (const TDF_Label& L, |
369 | const Handle(DDataStd_DrawPresentation)& P) |
370 | { |
371 | if (!L.IsNull()) { |
372 | if (!P->GetDrawable().IsNull()) { |
373 | TCollection_AsciiString S; |
374 | TDF_Tool::Entry(L,S); |
375 | Standard_CString name = S.ToCString(); |
376 | Draw::Set(name,P->GetDrawable()); |
377 | return; |
378 | } |
379 | else { |
380 | //cout<< "DDataStd_DrawPresentation::DrawDisplay : null Drawable" << endl; |
381 | return; |
382 | } |
383 | } |
384 | cout<< "DDataStd_DrawPresentation::DrawDisplay : null Label" << endl; |
385 | } |
386 | |
387 | //======================================================================= |
388 | //function : DrawErase |
389 | //purpose : |
390 | //======================================================================= |
391 | |
392 | void DDataStd_DrawPresentation::DrawErase (const TDF_Label& L, |
393 | const Handle(DDataStd_DrawPresentation)& P) |
394 | { |
395 | if (!L.IsNull()) { |
396 | if (!P->GetDrawable().IsNull()) { |
397 | dout.RemoveDrawable(P->GetDrawable()); |
398 | return; |
399 | } |
400 | else { |
401 | //cout<< "DDataStd_DrawPresentation::DrawErase : null Drawable" << endl; |
402 | return; |
403 | } |
404 | } |
405 | cout<< "DDataStd_DrawPresentation::DrawErase : null Label" << endl; |
406 | } |
407 | |
408 | |
409 | |
410 | |