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