b311480e |
1 | // Created on: 1998-09-30 |
2 | // Created by: Sergey RUIN |
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 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <AIS_InteractiveContext.hxx> |
19 | #include <AIS_InteractiveObject.hxx> |
20 | #include <Standard_GUID.hxx> |
f47afe53 |
21 | #include <Standard_NullObject.hxx> |
22 | #include <Standard_NoMoreObject.hxx> |
42cf5bc1 |
23 | #include <TCollection_ExtendedString.hxx> |
24 | #include <TDF_Attribute.hxx> |
25 | #include <TDF_AttributeDelta.hxx> |
7fd59977 |
26 | #include <TDF_DefaultDeltaOnModification.hxx> |
42cf5bc1 |
27 | #include <TDF_DefaultDeltaOnRemoval.hxx> |
7fd59977 |
28 | #include <TDF_DeltaOnAddition.hxx> |
42cf5bc1 |
29 | #include <TDF_Label.hxx> |
30 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
31 | #include <TDF_Tool.hxx> |
42cf5bc1 |
32 | #include <TPrsStd_AISPresentation.hxx> |
c3282ec1 |
33 | #include <TColStd_ListOfInteger.hxx> |
34 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
f47afe53 |
35 | #include <TDataXtd_Presentation.hxx> |
7fd59977 |
36 | #include <TPrsStd_AISViewer.hxx> |
7fd59977 |
37 | #include <TPrsStd_Driver.hxx> |
38 | #include <TPrsStd_DriverTable.hxx> |
39 | |
92efcf78 |
40 | IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_AISPresentation,TDF_Attribute) |
41 | |
f47afe53 |
42 | #define NO_MORE_OBJECT "TPrsStd_AISPresentation has no associated TDataXtd_PresentationData" |
43 | |
7fd59977 |
44 | //======================================================================= |
f47afe53 |
45 | //function : TPrsStd_AISPresentation |
46 | //purpose : Constructor |
7fd59977 |
47 | //======================================================================= |
f47afe53 |
48 | TPrsStd_AISPresentation::TPrsStd_AISPresentation () |
49 | { |
7fd59977 |
50 | } |
51 | |
52 | |
53 | //======================================================================= |
f47afe53 |
54 | //function : Set |
7fd59977 |
55 | //purpose : |
56 | //======================================================================= |
f47afe53 |
57 | Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set |
58 | ( const TDF_Label& theLabel, const Standard_GUID& theDriver ) |
59 | { |
60 | Handle(TPrsStd_AISPresentation) aPresentation; |
61 | // create associated data (unless already there) |
62 | Handle(TDataXtd_Presentation) aData = TDataXtd_Presentation::Set (theLabel, theDriver); |
63 | if(aData.IsNull()) |
64 | Standard_NoMoreObject::Raise (NO_MORE_OBJECT); |
65 | if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) ) |
66 | { |
67 | aPresentation = new TPrsStd_AISPresentation(); |
f47afe53 |
68 | theLabel.AddAttribute(aPresentation); |
7fd59977 |
69 | } |
7fd59977 |
70 | |
f47afe53 |
71 | return aPresentation; |
72 | } |
7fd59977 |
73 | |
74 | //======================================================================= |
75 | //function : Set |
76 | //purpose : |
77 | //======================================================================= |
f47afe53 |
78 | Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set(const Handle(TDF_Attribute)& theMaster) |
79 | { |
c4a2f61e |
80 | return TPrsStd_AISPresentation::Set(theMaster->Label(), theMaster->ID()); |
7fd59977 |
81 | } |
82 | |
f47afe53 |
83 | //======================================================================= |
84 | //function : Unset |
85 | //purpose : |
86 | //======================================================================= |
87 | void TPrsStd_AISPresentation::Unset (const TDF_Label& theLabel) |
88 | { |
89 | Handle(TPrsStd_AISPresentation) aPresentation; |
90 | if ( theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) ) |
91 | theLabel.ForgetAttribute(aPresentation); |
7fd59977 |
92 | |
f47afe53 |
93 | // remove associated data |
94 | TDataXtd_Presentation::Unset (theLabel); |
95 | } |
7fd59977 |
96 | |
97 | //======================================================================= |
f47afe53 |
98 | //function : getData |
7fd59977 |
99 | //purpose : |
100 | //======================================================================= |
f47afe53 |
101 | Handle(TDataXtd_Presentation) TPrsStd_AISPresentation::getData () const |
7fd59977 |
102 | { |
f47afe53 |
103 | Handle(TDataXtd_Presentation) aData; |
c4a2f61e |
104 | if (!Label().FindAttribute(TDataXtd_Presentation::GetID(), aData)) |
105 | Standard_NoMoreObject::Raise (NO_MORE_OBJECT); |
f47afe53 |
106 | return aData; |
7fd59977 |
107 | } |
108 | |
7fd59977 |
109 | //======================================================================= |
f47afe53 |
110 | //function : GetID |
7fd59977 |
111 | //purpose : |
112 | //======================================================================= |
f47afe53 |
113 | const Standard_GUID& TPrsStd_AISPresentation::GetID() |
114 | { |
115 | static Standard_GUID TPrsStd_AISPresentationID("3680ac6c-47ae-4366-bb94-26abb6e07341"); |
116 | return TPrsStd_AISPresentationID; |
117 | } |
7fd59977 |
118 | |
7fd59977 |
119 | //======================================================================= |
120 | //function : Display |
121 | //purpose : |
122 | //======================================================================= |
f47afe53 |
123 | void TPrsStd_AISPresentation::Display(const Standard_Boolean theIsUpdate) |
7fd59977 |
124 | { |
f47afe53 |
125 | if ( theIsUpdate || myAIS.IsNull() ) |
7fd59977 |
126 | AISUpdate(); |
f47afe53 |
127 | |
128 | AISDisplay(); |
7fd59977 |
129 | } |
130 | |
7fd59977 |
131 | //======================================================================= |
132 | //function : Erase |
133 | //purpose : |
134 | //======================================================================= |
f47afe53 |
135 | void TPrsStd_AISPresentation::Erase(const Standard_Boolean theIsRemove) |
136 | { |
137 | if ( IsDisplayed() ) |
138 | { |
139 | AISErase(theIsRemove); |
f47afe53 |
140 | } |
7fd59977 |
141 | } |
142 | |
143 | //======================================================================= |
144 | //function : Update |
145 | //purpose : |
146 | //======================================================================= |
f47afe53 |
147 | void TPrsStd_AISPresentation::Update() |
148 | { |
7fd59977 |
149 | AISUpdate(); |
150 | } |
151 | |
7fd59977 |
152 | //======================================================================= |
153 | //function : IsDisplayed |
154 | //purpose : |
155 | //======================================================================= |
f47afe53 |
156 | Standard_Boolean TPrsStd_AISPresentation::IsDisplayed() const |
7fd59977 |
157 | { |
c4a2f61e |
158 | return getData()->IsDisplayed(); |
7fd59977 |
159 | } |
160 | |
7fd59977 |
161 | //======================================================================= |
f47afe53 |
162 | //function : SetDisplayed |
7fd59977 |
163 | //purpose : |
164 | //======================================================================= |
f47afe53 |
165 | void TPrsStd_AISPresentation::SetDisplayed(const Standard_Boolean theIsDisplayed) |
7fd59977 |
166 | { |
f47afe53 |
167 | // this method can be called by AISUpdate() in the process of removal, |
168 | // while data attribute may be already removed |
c4a2f61e |
169 | Backup(); |
170 | getData()->SetDisplayed(theIsDisplayed); |
f47afe53 |
171 | } |
7fd59977 |
172 | |
f47afe53 |
173 | //======================================================================= |
174 | //function :SetDriverGUID |
175 | //purpose : |
176 | //======================================================================= |
177 | void TPrsStd_AISPresentation::SetDriverGUID(const Standard_GUID& theGUID) |
178 | { |
c4a2f61e |
179 | Backup(); |
180 | getData()->SetDriverGUID (theGUID); |
7fd59977 |
181 | } |
182 | |
7fd59977 |
183 | //======================================================================= |
184 | //function :GetDriverGUID |
185 | //purpose : |
186 | //======================================================================= |
187 | Standard_GUID TPrsStd_AISPresentation::GetDriverGUID() const |
188 | { |
c4a2f61e |
189 | return getData()->GetDriverGUID(); |
7fd59977 |
190 | } |
191 | |
7fd59977 |
192 | //======================================================================= |
193 | //function :Material |
194 | //purpose : |
195 | //======================================================================= |
196 | Graphic3d_NameOfMaterial TPrsStd_AISPresentation::Material() const |
197 | { |
c4a2f61e |
198 | return (Graphic3d_NameOfMaterial)getData()->MaterialIndex(); |
7fd59977 |
199 | } |
200 | |
201 | //======================================================================= |
202 | //function :HasMaterial |
203 | //purpose : |
204 | //======================================================================= |
205 | Standard_Boolean TPrsStd_AISPresentation::HasOwnMaterial() const |
206 | { |
c4a2f61e |
207 | return getData()->HasOwnMaterial(); |
7fd59977 |
208 | } |
209 | |
210 | //======================================================================= |
f47afe53 |
211 | //function : UnsetMaterial |
7fd59977 |
212 | //purpose : |
213 | //======================================================================= |
214 | void TPrsStd_AISPresentation::UnsetMaterial() |
215 | { |
c4a2f61e |
216 | if ( !getData()->HasOwnMaterial() && !myAIS.IsNull() && !myAIS->HasMaterial() ) |
f47afe53 |
217 | return; |
218 | |
c4a2f61e |
219 | getData()->UnsetMaterial(); |
f47afe53 |
220 | |
221 | if ( myAIS.IsNull() ) |
222 | AISUpdate(); |
223 | |
224 | if ( !myAIS.IsNull() && myAIS->HasMaterial() ) |
225 | { |
226 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
227 | |
228 | if ( !aContext.IsNull() ) |
229 | aContext->UnsetMaterial(myAIS, Standard_False); |
230 | else |
7fd59977 |
231 | myAIS->UnsetMaterial(); |
232 | } |
233 | } |
234 | |
f47afe53 |
235 | |
7fd59977 |
236 | //======================================================================= |
f47afe53 |
237 | //function : SetMaterial |
7fd59977 |
238 | //purpose : |
239 | //======================================================================= |
f47afe53 |
240 | void TPrsStd_AISPresentation::SetMaterial(const Graphic3d_NameOfMaterial theName) |
c4a2f61e |
241 | { |
242 | Backup(); |
243 | if ( getData()->HasOwnMode() && getData()->MaterialIndex() == theName ) |
f47afe53 |
244 | if ( !myAIS.IsNull() && myAIS->HasMaterial() && myAIS->Material() == theName ) |
245 | return; |
246 | |
c4a2f61e |
247 | getData()->SetMaterialIndex(theName); |
f47afe53 |
248 | |
249 | if ( myAIS.IsNull() ) |
250 | AISUpdate(); |
251 | |
252 | if ( !myAIS.IsNull() ) |
253 | { |
254 | if ( myAIS->HasMaterial() && myAIS->Material() == theName ) |
255 | return; // AIS has already had that material |
256 | |
257 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
258 | |
259 | if ( !aContext.IsNull() ) |
260 | aContext->SetMaterial(myAIS, theName, Standard_False); |
261 | else |
262 | myAIS->SetMaterial(theName); |
7fd59977 |
263 | } |
264 | } |
265 | |
7fd59977 |
266 | //======================================================================= |
f47afe53 |
267 | //function :Transparency |
7fd59977 |
268 | //purpose : |
269 | //======================================================================= |
f47afe53 |
270 | Standard_Real TPrsStd_AISPresentation::Transparency() const |
7fd59977 |
271 | { |
c4a2f61e |
272 | return getData()->Transparency(); |
7fd59977 |
273 | } |
274 | |
7fd59977 |
275 | //======================================================================= |
f47afe53 |
276 | //function :SetTransparency |
7fd59977 |
277 | //purpose : |
278 | //======================================================================= |
f47afe53 |
279 | void TPrsStd_AISPresentation::SetTransparency(const Standard_Real theValue) |
7fd59977 |
280 | { |
c4a2f61e |
281 | Backup(); |
282 | if (getData()->HasOwnTransparency() && getData()->Transparency() == theValue) |
f47afe53 |
283 | if ( !myAIS.IsNull() && myAIS->Transparency() == theValue ) |
284 | return; |
285 | |
c4a2f61e |
286 | getData()->SetTransparency(theValue); |
f47afe53 |
287 | |
288 | if ( myAIS.IsNull() ) |
289 | AISUpdate(); |
290 | |
291 | if ( !myAIS.IsNull() ) |
292 | { |
293 | if ( myAIS->Transparency() == theValue ) |
294 | return; // AIS has already had that transparency |
295 | |
296 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
297 | |
298 | if ( !aContext.IsNull() ) |
299 | aContext->SetTransparency(myAIS, theValue, Standard_False); |
300 | else |
301 | myAIS->SetTransparency(theValue); |
302 | } |
7fd59977 |
303 | } |
304 | |
305 | //======================================================================= |
306 | //function :UnsetTransparency |
307 | //purpose : |
308 | //======================================================================= |
309 | void TPrsStd_AISPresentation::UnsetTransparency() |
310 | { |
c4a2f61e |
311 | if (!getData()->HasOwnTransparency()) |
7fd59977 |
312 | return; |
313 | |
c4a2f61e |
314 | getData()->UnsetTransparency(); |
f47afe53 |
315 | |
316 | if ( myAIS.IsNull() ) |
317 | AISUpdate(); |
318 | |
319 | if ( !myAIS.IsNull() ) |
320 | { |
321 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
322 | |
323 | if( !aContext.IsNull() ) |
324 | aContext->UnsetTransparency(myAIS, Standard_False); |
325 | else |
7fd59977 |
326 | myAIS->UnsetTransparency(); |
327 | } |
328 | } |
329 | |
330 | //======================================================================= |
f47afe53 |
331 | //function : HasTransparency |
7fd59977 |
332 | //purpose : |
333 | //======================================================================= |
334 | Standard_Boolean TPrsStd_AISPresentation::HasOwnTransparency() const |
335 | { |
c4a2f61e |
336 | return getData()->HasOwnTransparency(); |
7fd59977 |
337 | } |
338 | |
339 | //======================================================================= |
f47afe53 |
340 | //function : Color |
7fd59977 |
341 | //purpose : |
342 | //======================================================================= |
343 | Quantity_NameOfColor TPrsStd_AISPresentation::Color() const |
344 | { |
c4a2f61e |
345 | return getData()->Color(); |
7fd59977 |
346 | } |
347 | |
348 | //======================================================================= |
f47afe53 |
349 | //function : HasOwnColor |
7fd59977 |
350 | //purpose : |
351 | //======================================================================= |
352 | Standard_Boolean TPrsStd_AISPresentation::HasOwnColor() const |
353 | { |
c4a2f61e |
354 | return getData()->HasOwnColor(); |
7fd59977 |
355 | } |
356 | |
357 | //======================================================================= |
f47afe53 |
358 | //function : UnsetColor |
7fd59977 |
359 | //purpose : |
360 | //======================================================================= |
361 | void TPrsStd_AISPresentation::UnsetColor() |
362 | { |
c4a2f61e |
363 | if (!getData()->HasOwnColor() && ! myAIS.IsNull() && !myAIS->HasColor()) |
f47afe53 |
364 | return; |
c4a2f61e |
365 | getData()->UnsetColor(); |
f47afe53 |
366 | |
367 | if ( myAIS.IsNull() ) |
368 | AISUpdate(); |
369 | |
370 | if ( !myAIS.IsNull() && myAIS->HasColor() ) |
371 | { |
372 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
373 | |
374 | if ( !aContext.IsNull() ) |
375 | aContext->UnsetColor(myAIS, Standard_False); |
376 | else |
7fd59977 |
377 | myAIS->UnsetColor(); |
378 | } |
379 | } |
380 | |
381 | //======================================================================= |
f47afe53 |
382 | //function : SetColor |
7fd59977 |
383 | //purpose : |
384 | //======================================================================= |
f47afe53 |
385 | void TPrsStd_AISPresentation::SetColor(const Quantity_NameOfColor theColor) |
7fd59977 |
386 | { |
c4a2f61e |
387 | Backup(); |
388 | if ( getData()->HasOwnColor() && getData()->Color() == theColor ) |
f47afe53 |
389 | if ( !myAIS.IsNull() && myAIS->HasColor() && myAIS->Color() == theColor ) |
7fd59977 |
390 | return; |
f47afe53 |
391 | |
c4a2f61e |
392 | getData()->SetColor(theColor); |
f47afe53 |
393 | |
394 | if ( myAIS.IsNull() ) |
395 | AISUpdate(); |
396 | |
397 | if ( !myAIS.IsNull() ) |
398 | { |
399 | if ( myAIS->HasColor() && myAIS->Color() == theColor ) |
400 | return; // AIS has already had that color |
401 | |
402 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
403 | |
404 | if( !aContext.IsNull() ) |
405 | aContext->SetColor(myAIS, theColor, Standard_False); |
7fd59977 |
406 | else |
f47afe53 |
407 | myAIS->SetColor(theColor); |
7fd59977 |
408 | } |
409 | } |
410 | |
7fd59977 |
411 | //======================================================================= |
412 | //function :Width |
413 | //purpose : |
414 | //======================================================================= |
415 | Standard_Real TPrsStd_AISPresentation::Width() const |
416 | { |
c4a2f61e |
417 | return getData()->Width(); |
7fd59977 |
418 | } |
419 | |
420 | //======================================================================= |
f47afe53 |
421 | //function : HasWidth |
7fd59977 |
422 | //purpose : |
423 | //======================================================================= |
424 | Standard_Boolean TPrsStd_AISPresentation::HasOwnWidth() const |
425 | { |
c4a2f61e |
426 | return getData()->HasOwnWidth(); |
7fd59977 |
427 | } |
428 | |
429 | //======================================================================= |
f47afe53 |
430 | //function : SetWidth |
7fd59977 |
431 | //purpose : |
432 | //======================================================================= |
f47afe53 |
433 | void TPrsStd_AISPresentation::SetWidth(const Standard_Real theWidth) |
7fd59977 |
434 | { |
c4a2f61e |
435 | Backup(); |
436 | if ( getData()->HasOwnWidth() && getData()->Width() == theWidth ) |
f47afe53 |
437 | if ( !myAIS.IsNull() && myAIS->HasWidth() && myAIS->Width() == theWidth ) |
7fd59977 |
438 | return; |
439 | |
c4a2f61e |
440 | getData()->SetWidth(theWidth); |
f47afe53 |
441 | |
442 | if( !myAIS.IsNull() ) |
443 | { |
444 | if ( myAIS->HasWidth() && myAIS->Width() == theWidth ) |
445 | return; // AIS has already had that width |
446 | |
447 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
448 | |
449 | if( !aContext.IsNull() ) |
450 | aContext->SetWidth(myAIS, theWidth, Standard_False); |
7fd59977 |
451 | else |
f47afe53 |
452 | myAIS->SetWidth(theWidth); |
7fd59977 |
453 | } |
454 | } |
455 | |
456 | //======================================================================= |
f47afe53 |
457 | //function : UnsetWidth |
7fd59977 |
458 | //purpose : |
459 | //======================================================================= |
460 | void TPrsStd_AISPresentation::UnsetWidth() |
461 | { |
c4a2f61e |
462 | if ( !getData()->HasOwnWidth() ) |
f47afe53 |
463 | if ( !myAIS.IsNull() && !myAIS->HasWidth() ) |
7fd59977 |
464 | return; |
465 | |
c4a2f61e |
466 | getData()->UnsetWidth(); |
f47afe53 |
467 | |
468 | if( myAIS.IsNull() ) |
469 | AISUpdate(); |
470 | |
471 | if ( !myAIS.IsNull() && myAIS->HasWidth() ) |
472 | { |
473 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
474 | |
475 | if ( !aContext.IsNull() ) |
476 | aContext->UnsetWidth(myAIS, Standard_False); |
477 | else |
7fd59977 |
478 | myAIS->UnsetWidth(); |
479 | } |
480 | } |
481 | |
7fd59977 |
482 | //======================================================================= |
483 | //function : Mode |
484 | //purpose : |
485 | //======================================================================= |
7fd59977 |
486 | Standard_Integer TPrsStd_AISPresentation::Mode() const |
487 | { |
c4a2f61e |
488 | return getData()->Mode(); |
7fd59977 |
489 | } |
490 | |
491 | //======================================================================= |
f47afe53 |
492 | //function : HasOwnMode |
7fd59977 |
493 | //purpose : |
494 | //======================================================================= |
495 | Standard_Boolean TPrsStd_AISPresentation::HasOwnMode() const |
496 | { |
c4a2f61e |
497 | return getData()->HasOwnMode(); |
7fd59977 |
498 | } |
499 | |
500 | //======================================================================= |
f47afe53 |
501 | //function : SetMode |
7fd59977 |
502 | //purpose : |
503 | //======================================================================= |
f47afe53 |
504 | void TPrsStd_AISPresentation::SetMode(const Standard_Integer theMode) |
7fd59977 |
505 | { |
c4a2f61e |
506 | Backup(); |
507 | if ( getData()->HasOwnMode() && getData()->Mode() == theMode ) |
f47afe53 |
508 | if ( !myAIS.IsNull() && myAIS->DisplayMode() == theMode ) |
7fd59977 |
509 | return; |
510 | |
c4a2f61e |
511 | getData()->SetMode(theMode); |
f47afe53 |
512 | |
513 | if ( myAIS.IsNull() ) |
514 | AISUpdate(); |
515 | |
516 | if ( !myAIS.IsNull() ) |
517 | { |
518 | if ( myAIS->DisplayMode() == theMode ) |
519 | return; // AIS has already had that mode |
520 | |
521 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
522 | |
523 | if( !aContext.IsNull() ) |
524 | aContext->SetDisplayMode(myAIS, theMode, Standard_False); |
7fd59977 |
525 | else |
526 | myAIS->SetDisplayMode(theMode); |
527 | } |
528 | } |
529 | |
530 | //======================================================================= |
f47afe53 |
531 | //function : UnsetMode |
7fd59977 |
532 | //purpose : |
533 | //======================================================================= |
534 | void TPrsStd_AISPresentation::UnsetMode() |
535 | { |
c4a2f61e |
536 | if ( !getData()->HasOwnMode() ) |
f47afe53 |
537 | if ( !myAIS.IsNull() && !myAIS->HasDisplayMode() ) |
7fd59977 |
538 | return; |
539 | |
c4a2f61e |
540 | getData()->UnsetMode(); |
f47afe53 |
541 | |
542 | if ( myAIS.IsNull() ) |
543 | AISUpdate(); |
544 | |
545 | if( !myAIS.IsNull() && myAIS->HasDisplayMode() ) |
546 | { |
547 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
548 | |
549 | if ( !aContext.IsNull() ) |
550 | aContext->UnsetDisplayMode(myAIS, Standard_False); |
551 | else |
552 | myAIS->UnsetDisplayMode(); |
7fd59977 |
553 | } |
554 | } |
555 | |
7fd59977 |
556 | //======================================================================= |
557 | //function : SelectionMode |
558 | //purpose : |
559 | //======================================================================= |
7fd59977 |
560 | Standard_Integer TPrsStd_AISPresentation::SelectionMode() const |
561 | { |
c4a2f61e |
562 | return getData()->SelectionMode(); |
7fd59977 |
563 | } |
564 | |
565 | //======================================================================= |
f47afe53 |
566 | //function : HasOwnSelectionMode |
7fd59977 |
567 | //purpose : |
568 | //======================================================================= |
569 | Standard_Boolean TPrsStd_AISPresentation::HasOwnSelectionMode() const |
570 | { |
c4a2f61e |
571 | return getData()->HasOwnSelectionMode(); |
7fd59977 |
572 | } |
573 | |
574 | //======================================================================= |
f47afe53 |
575 | //function : SetSelectionMode |
7fd59977 |
576 | //purpose : |
577 | //======================================================================= |
f47afe53 |
578 | void TPrsStd_AISPresentation::SetSelectionMode(const Standard_Integer theSelectionMode) |
7fd59977 |
579 | { |
c4a2f61e |
580 | Backup(); |
581 | getData()->SetSelectionMode (theSelectionMode); |
f47afe53 |
582 | AISUpdate(); |
7fd59977 |
583 | } |
584 | |
585 | //======================================================================= |
f47afe53 |
586 | //function : UnsetSelectionMode |
7fd59977 |
587 | //purpose : |
588 | //======================================================================= |
589 | void TPrsStd_AISPresentation::UnsetSelectionMode() |
590 | { |
c4a2f61e |
591 | getData()->UnsetSelectionMode (); |
f47afe53 |
592 | AISUpdate(); |
7fd59977 |
593 | } |
7fd59977 |
594 | |
595 | //======================================================================= |
596 | //function : ID |
597 | //purpose : |
598 | //======================================================================= |
f47afe53 |
599 | const Standard_GUID& TPrsStd_AISPresentation::ID() const |
600 | { |
601 | return GetID(); |
602 | } |
7fd59977 |
603 | |
604 | //======================================================================= |
605 | //function : BackupCopy |
606 | //purpose : |
607 | //======================================================================= |
608 | Handle(TDF_Attribute) TPrsStd_AISPresentation::BackupCopy() const |
609 | { |
f47afe53 |
610 | return new TPrsStd_AISPresentation; |
7fd59977 |
611 | } |
612 | |
613 | |
614 | //======================================================================= |
615 | //function : NewEmpty |
616 | //purpose : |
617 | //======================================================================= |
618 | Handle(TDF_Attribute) TPrsStd_AISPresentation::NewEmpty() const |
619 | { |
f47afe53 |
620 | return new TPrsStd_AISPresentation(); |
7fd59977 |
621 | } |
622 | |
623 | //======================================================================= |
f47afe53 |
624 | //function : Paste |
7fd59977 |
625 | //purpose : |
626 | //======================================================================= |
f47afe53 |
627 | void TPrsStd_AISPresentation::Restore(const Handle(TDF_Attribute)& /*theWith*/) |
628 | { |
7fd59977 |
629 | myAIS.Nullify(); |
7fd59977 |
630 | } |
631 | |
632 | //======================================================================= |
633 | //function : Paste |
634 | //purpose : |
635 | //======================================================================= |
f47afe53 |
636 | void TPrsStd_AISPresentation::Paste (const Handle(TDF_Attribute)& theInto, |
637 | const Handle(TDF_RelocationTable)& ) const |
638 | { |
639 | Handle(TPrsStd_AISPresentation) anInto = |
640 | Handle(TPrsStd_AISPresentation)::DownCast(theInto); |
7fd59977 |
641 | |
f47afe53 |
642 | anInto->Backup(); |
643 | anInto->myAIS.Nullify(); |
7fd59977 |
644 | } |
645 | |
646 | //======================================================================= |
647 | //function : AfterAddition |
648 | //purpose : erase if displayed |
649 | //======================================================================= |
650 | void TPrsStd_AISPresentation::AfterAddition() |
f47afe53 |
651 | { |
7fd59977 |
652 | AfterResume(); |
653 | } |
654 | |
655 | //======================================================================= |
656 | //function : BeforeRemoval |
657 | //purpose : erase if displayed |
658 | //======================================================================= |
659 | void TPrsStd_AISPresentation::BeforeRemoval() |
f47afe53 |
660 | { |
661 | BeforeForget(); |
7fd59977 |
662 | } |
663 | |
664 | //======================================================================= |
665 | //function : BeforeForget |
666 | //purpose : erase if displayed |
667 | //======================================================================= |
668 | void TPrsStd_AISPresentation::BeforeForget() |
669 | { |
f47afe53 |
670 | if ( !myAIS.IsNull() ) |
671 | { // Remove AISObject from context. |
672 | AISErase(Standard_True); |
7fd59977 |
673 | myAIS.Nullify(); |
674 | } |
675 | } |
676 | |
7fd59977 |
677 | //======================================================================= |
678 | //function : AfterResume |
679 | //purpose : display if displayed |
680 | //======================================================================= |
f47afe53 |
681 | void TPrsStd_AISPresentation::AfterResume() |
7fd59977 |
682 | { |
683 | AISUpdate(); |
f47afe53 |
684 | if ( IsDisplayed() ) |
685 | AISDisplay(); |
686 | else |
687 | AISErase(); |
7fd59977 |
688 | } |
689 | |
690 | //======================================================================= |
691 | //function : BeforeUndo |
692 | //purpose : le NamedShape associe doit etre present |
693 | //======================================================================= |
7fd59977 |
694 | Standard_Boolean TPrsStd_AISPresentation::BeforeUndo (const Handle(TDF_AttributeDelta)& AD, |
c4a2f61e |
695 | const Standard_Boolean ) |
7fd59977 |
696 | { |
697 | Handle(TPrsStd_AISPresentation) P; |
f47afe53 |
698 | AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P); |
7fd59977 |
699 | |
f47afe53 |
700 | if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) |
701 | { |
702 | if ( !P.IsNull() ) |
703 | P->BeforeForget(); |
7fd59977 |
704 | } |
705 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) { |
f47afe53 |
706 | } |
707 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) |
708 | { |
709 | if ( !P.IsNull() ) |
710 | P->BeforeForget(); |
711 | } |
7fd59977 |
712 | |
713 | return Standard_True; |
714 | } |
715 | |
7fd59977 |
716 | //======================================================================= |
717 | //function : AfterUndo |
718 | //purpose : le NamedShape associe doit etre present |
719 | //======================================================================= |
7fd59977 |
720 | Standard_Boolean TPrsStd_AISPresentation::AfterUndo (const Handle(TDF_AttributeDelta)& AD, |
f47afe53 |
721 | const Standard_Boolean ) |
7fd59977 |
722 | { |
723 | Handle(TPrsStd_AISPresentation) P; |
724 | AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P); |
725 | |
f47afe53 |
726 | if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) |
727 | {} |
728 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) |
729 | { |
730 | if ( !P.IsNull() ) |
731 | P->AfterAddition(); |
7fd59977 |
732 | } |
f47afe53 |
733 | else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) |
734 | { |
735 | if ( !P.IsNull() ) |
736 | P->AfterResume(); |
7fd59977 |
737 | } |
738 | |
739 | return Standard_True; |
740 | } |
741 | |
7fd59977 |
742 | //======================================================================= |
743 | //function : AISUpdate |
744 | //purpose : |
745 | //======================================================================= |
f47afe53 |
746 | void TPrsStd_AISPresentation::AISUpdate() |
747 | { |
7fd59977 |
748 | Backup(); |
c4a2f61e |
749 | getData()->Backup(); |
f47afe53 |
750 | Handle(AIS_InteractiveContext) aContext; |
751 | if ( !Label().IsNull() ) |
752 | { |
753 | aContext = getAISContext(); |
754 | |
755 | Handle(TPrsStd_Driver) aDriver; |
756 | if ( TPrsStd_DriverTable::Get()->FindDriver(GetDriverGUID(), aDriver) ) |
757 | { |
758 | // Build a new AIS. |
759 | if ( myAIS.IsNull() ) |
760 | { |
761 | Handle(AIS_InteractiveObject) aNewObj; |
762 | if ( aDriver->Update(Label(), aNewObj) ) |
763 | { |
764 | myAIS = aNewObj; |
f47afe53 |
765 | aNewObj->SetOwner(this); |
766 | } |
7fd59977 |
767 | } |
f47afe53 |
768 | else |
769 | { |
770 | Handle(AIS_InteractiveObject) anObj = myAIS; |
771 | if ( aDriver->Update(Label(), anObj) ) |
772 | if ( !(anObj == myAIS) ) |
773 | { |
774 | if ( !aContext.IsNull() ) |
775 | aContext->Remove(myAIS); |
776 | |
777 | // Driver has built new AIS. |
778 | myAIS = anObj; |
f47afe53 |
779 | anObj->SetOwner(this); |
780 | } |
7fd59977 |
781 | } |
782 | } |
783 | } |
784 | else return; |
785 | |
f47afe53 |
786 | // Apply the visualization settings. |
787 | if ( !myAIS.IsNull() ) |
788 | { |
789 | if ( HasOwnColor() ) |
790 | { |
791 | Quantity_NameOfColor aColor = Color(); |
792 | if ( !(myAIS->HasColor()) || (myAIS->HasColor() && myAIS->Color() != aColor) ) |
793 | { |
794 | if ( !aContext.IsNull() ) |
795 | aContext->SetColor(myAIS, aColor, Standard_False); |
796 | else |
797 | myAIS->SetColor(aColor); |
7fd59977 |
798 | } |
f47afe53 |
799 | } |
7fd59977 |
800 | |
f47afe53 |
801 | if ( HasOwnMaterial() ) |
802 | { |
803 | Graphic3d_NameOfMaterial aMaterial = Material(); |
804 | if ( !(myAIS->HasMaterial()) || (myAIS->HasMaterial() && myAIS->Material() != aMaterial) ) |
805 | { |
806 | if ( !aContext.IsNull() ) |
807 | aContext->SetMaterial(myAIS, aMaterial, Standard_False ); |
808 | else |
809 | myAIS->SetMaterial(aMaterial); |
7fd59977 |
810 | } |
f47afe53 |
811 | } |
812 | |
813 | if ( HasOwnTransparency() ) |
814 | { |
815 | const Standard_Real aTransparency = Transparency(); |
816 | if ( myAIS->Transparency() != aTransparency ) |
817 | { |
818 | if( !aContext.IsNull() ) |
819 | aContext->SetTransparency(myAIS, aTransparency, Standard_False); |
820 | else |
821 | myAIS->SetTransparency(aTransparency); |
7fd59977 |
822 | } |
823 | } |
824 | |
f47afe53 |
825 | if ( HasOwnWidth() ) |
826 | { |
827 | const Standard_Real aWidth = Width(); |
828 | if ( !(myAIS->HasWidth()) || (myAIS->HasWidth() && myAIS->Width() != aWidth) ) |
829 | { |
830 | if ( !aContext.IsNull() ) |
831 | aContext->SetWidth(myAIS, aWidth, Standard_False); |
832 | else |
833 | myAIS->SetWidth(aWidth); |
7fd59977 |
834 | } |
835 | } |
836 | |
f47afe53 |
837 | if ( HasOwnMode() ) |
838 | { |
839 | const Standard_Integer aMode = Mode(); |
840 | if ( myAIS->DisplayMode() != aMode ) |
841 | myAIS->SetDisplayMode(aMode); |
7fd59977 |
842 | } |
843 | |
f47afe53 |
844 | if ( !aContext.IsNull() && IsDisplayed() ) |
845 | aContext->Redisplay(myAIS, Standard_False); |
846 | |
847 | if (HasOwnSelectionMode()) { |
c3282ec1 |
848 | if (!aContext.IsNull()) |
849 | { |
850 | TColStd_ListOfInteger anActivatedModes; |
851 | aContext->ActivatedModes (myAIS, anActivatedModes); |
852 | Standard_Boolean isActivated = Standard_False; |
f47afe53 |
853 | Standard_Integer aSelectionMode = SelectionMode(); |
c4a2f61e |
854 | if (aSelectionMode == -1) |
c3282ec1 |
855 | { |
c4a2f61e |
856 | aContext->Deactivate(myAIS); |
857 | } |
858 | else |
859 | { |
860 | for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next()) |
c3282ec1 |
861 | { |
c4a2f61e |
862 | if (aModeIter.Value() == aSelectionMode) |
863 | { |
864 | isActivated = Standard_True; |
865 | break; |
866 | } |
c3282ec1 |
867 | } |
c4a2f61e |
868 | if (!isActivated) |
869 | aContext->Activate (myAIS, aSelectionMode, Standard_False); |
c3282ec1 |
870 | } |
7fd59977 |
871 | } |
872 | } |
7fd59977 |
873 | |
874 | } |
875 | |
f47afe53 |
876 | if (IsDisplayed() && !aContext.IsNull()) |
877 | aContext->Redisplay(myAIS, Standard_False); |
7fd59977 |
878 | } |
879 | |
880 | //======================================================================= |
881 | //function : AISDisplay |
882 | //purpose : |
883 | //======================================================================= |
f47afe53 |
884 | void TPrsStd_AISPresentation::AISDisplay() |
885 | { |
886 | if ( !Label().IsNull() ) |
887 | { |
888 | Handle(AIS_InteractiveContext) aContext = getAISContext(); |
7fd59977 |
889 | |
f47afe53 |
890 | if ( aContext.IsNull() ) |
891 | return; |
892 | |
893 | if ( !myAIS.IsNull() ) |
894 | { |
895 | if ( !(myAIS->GetContext()).IsNull() && (myAIS->GetContext()) != aContext ) |
896 | myAIS->GetContext()->Remove(myAIS); |
7fd59977 |
897 | |
f47afe53 |
898 | if ( IsDisplayed() && aContext->IsDisplayed(myAIS) ) |
899 | return; |
7fd59977 |
900 | |
f47afe53 |
901 | aContext->Display(myAIS, Standard_False); |
7fd59977 |
902 | |
f47afe53 |
903 | if ( aContext->IsDisplayed(myAIS) ) |
904 | SetDisplayed(Standard_True); |
7fd59977 |
905 | } |
906 | } |
907 | } |
908 | |
7fd59977 |
909 | //======================================================================= |
910 | //function : AISErase |
911 | //purpose : |
912 | //======================================================================= |
f47afe53 |
913 | void TPrsStd_AISPresentation::AISErase(const Standard_Boolean theIsRemove) |
914 | { |
915 | Handle(AIS_InteractiveContext) aContext, anOwnContext; |
916 | |
917 | if ( !myAIS.IsNull() ) |
918 | { |
919 | Backup(); |
f47afe53 |
920 | if ( !Label().IsNull() ) |
921 | { |
c4a2f61e |
922 | if (IsAttribute(TDataXtd_Presentation::GetID())) |
923 | SetDisplayed(Standard_False); |
924 | |
f47afe53 |
925 | Handle(TPrsStd_AISViewer) viewer; |
926 | if( !TPrsStd_AISViewer::Find(Label(), viewer) ) |
927 | return; |
928 | anOwnContext = myAIS->GetContext(); |
929 | aContext = viewer->GetInteractiveContext(); |
7fd59977 |
930 | |
f47afe53 |
931 | if ( theIsRemove ) |
932 | { |
933 | if ( !aContext.IsNull() ) |
934 | aContext->Remove(myAIS, Standard_False); |
935 | if ( !anOwnContext.IsNull() && anOwnContext != aContext ) |
936 | anOwnContext->Remove(myAIS, Standard_False); |
7fd59977 |
937 | |
7fd59977 |
938 | myAIS->SetToUpdate(); |
939 | } |
f47afe53 |
940 | else |
941 | { |
942 | if ( !aContext.IsNull() ) |
943 | aContext->Erase(myAIS, Standard_False); |
944 | if ( !anOwnContext.IsNull() && anOwnContext != aContext ) |
945 | anOwnContext->Erase(myAIS, Standard_False); |
7fd59977 |
946 | } |
947 | } |
f47afe53 |
948 | else |
949 | { |
950 | if ( theIsRemove ) |
951 | { |
952 | if ( !anOwnContext.IsNull() ) |
953 | { |
954 | anOwnContext->Remove(myAIS, Standard_False); |
955 | myAIS->SetToUpdate(); |
956 | } |
7fd59977 |
957 | } |
f47afe53 |
958 | else |
959 | if( !anOwnContext.IsNull() ) |
960 | anOwnContext->Erase(myAIS, Standard_False); |
7fd59977 |
961 | } |
962 | } |
963 | } |
964 | |
7fd59977 |
965 | //======================================================================= |
966 | //function :GetAIS |
967 | //purpose : |
968 | //======================================================================= |
969 | Handle(AIS_InteractiveObject) TPrsStd_AISPresentation::GetAIS() const |
970 | { |
971 | return myAIS; |
972 | } |
973 | |
7fd59977 |
974 | //======================================================================= |
f47afe53 |
975 | //function : getAISContext |
7fd59977 |
976 | //purpose : |
977 | //======================================================================= |
f47afe53 |
978 | Handle(AIS_InteractiveContext) TPrsStd_AISPresentation::getAISContext() const |
7fd59977 |
979 | { |
f47afe53 |
980 | Handle(TPrsStd_AISViewer) aViewer; |
981 | if ( TPrsStd_AISViewer::Find(Label(), aViewer) ) |
982 | return aViewer->GetInteractiveContext(); |
7fd59977 |
983 | |
f47afe53 |
984 | return Handle_AIS_InteractiveContext(); |
985 | } |