7fd59977 |
1 | // File: AIS_InteractiveObject.cxx |
2 | // Created: Wed Dec 18 14:44:37 1996 |
3 | // Author: Robert COUBLANC |
4 | // <rob@robox.paris1.matra-dtv.fr> |
5 | |
6 | // Modified : 22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets |
7 | |
8 | #define BUC60577 //GG_101099 Enable to compute correctly |
9 | // transparency with more than one object in the view. |
10 | |
11 | #define GER61351 //GG_171199 Enable to set an object RGB color |
12 | // instead a restricted object NameOfColor. |
13 | // Add SetCurrentFacingModel() method |
14 | // |
15 | |
16 | #define G003 //EUG/GG 260100 DEgenerate mode support |
17 | // Add SetDegenerateModel() methods |
18 | |
19 | #define IMP020200 //GG Add SetTransformation() method |
20 | |
21 | #define IMP140200 //GG Add HasPresentation() and Presentation() methods |
22 | // Add SetAspect() method. |
23 | |
24 | #define BUC60632 //GG 15/03/00 Add protection on SetDisplayMode() |
25 | // method, compute only authorized presentation. |
26 | |
27 | #define IMP220501 //GG CADPAK_V2 Update selection properly |
28 | |
29 | #define OCC708 //SAV unsetting transformation correctly |
30 | |
31 | #include <AIS_InteractiveObject.ixx> |
32 | |
33 | #include <Aspect_PolygonOffsetMode.hxx> |
34 | #include <Prs3d_ShadingAspect.hxx> |
35 | #include <Prs3d_LineAspect.hxx> |
36 | #include <Prs3d_PointAspect.hxx> |
37 | #include <Prs3d_TextAspect.hxx> |
38 | #include <Prs3d_Presentation.hxx> |
39 | #include <Prs3d_Root.hxx> |
40 | #include <PrsMgr_ModedPresentation.hxx> |
41 | #include <PrsMgr_PresentationManager3d.hxx> |
42 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
43 | #include <AIS_GraphicTool.hxx> |
44 | #include <Graphic3d_AspectFillArea3d.hxx> |
45 | #include <Graphic3d_Group.hxx> |
46 | #include <Graphic3d_Structure.hxx> |
47 | |
48 | |
49 | //======================================================================= |
50 | //function : AIS_InteractiveObject |
51 | //purpose : |
52 | //======================================================================= |
53 | |
54 | AIS_InteractiveObject:: |
55 | AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d): |
56 | SelectMgr_SelectableObject(aTypeOfPresentation3d), |
57 | myDrawer(new AIS_Drawer()), |
58 | myTransparency(0.), |
59 | myOwnColor(Quantity_NOC_WHITE), |
60 | myHilightMode(-1), |
61 | myOwnWidth(0.0), |
62 | myInfiniteState(Standard_False), |
63 | hasOwnColor(Standard_False), |
64 | hasOwnMaterial(Standard_False), |
65 | myRecomputeEveryPrs(Standard_True), |
66 | mySelPriority(-1), |
67 | myDisplayMode (-1), |
68 | mySelectionMode(0), |
69 | mystate(0) |
70 | { |
71 | Handle (AIS_InteractiveContext) Bid; |
72 | myCTXPtr = Bid.operator->(); |
73 | #ifdef GER61351 |
74 | SetCurrentFacingModel(); |
75 | #endif |
76 | } |
77 | |
78 | //======================================================================= |
79 | //function : Redisplay |
80 | //purpose : |
81 | //======================================================================= |
82 | |
83 | void AIS_InteractiveObject::Redisplay(const Standard_Boolean AllModes) |
84 | { |
85 | Update(AllModes); |
86 | UpdateSelection(); |
87 | } |
88 | |
89 | //======================================================================= |
90 | //function : Type |
91 | //purpose : |
92 | //======================================================================= |
93 | |
94 | AIS_KindOfInteractive AIS_InteractiveObject::Type() const |
95 | {return AIS_KOI_None;} |
96 | |
97 | //======================================================================= |
98 | //function : Signature |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | Standard_Integer AIS_InteractiveObject::Signature() const |
103 | {return -1;} |
104 | |
105 | //======================================================================= |
106 | //function : RecomputeEveryPrs |
107 | //purpose : |
108 | //======================================================================= |
109 | |
110 | Standard_Boolean AIS_InteractiveObject::RecomputeEveryPrs() const |
111 | {return myRecomputeEveryPrs;} |
112 | |
113 | //======================================================================= |
114 | //function : |
115 | //purpose : |
116 | //======================================================================= |
117 | Standard_Boolean AIS_InteractiveObject::HasInteractiveContext() const |
118 | { |
119 | Handle (AIS_InteractiveContext) aNull; |
120 | return (myCTXPtr != aNull.operator->()); |
121 | } |
122 | |
123 | //======================================================================= |
124 | //function : |
125 | //purpose : |
126 | //======================================================================= |
127 | Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const |
128 | { |
129 | return myCTXPtr; |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : |
134 | //purpose : |
135 | //======================================================================= |
136 | void AIS_InteractiveObject::SetContext(const Handle(AIS_InteractiveContext)& aCtx) |
137 | { |
138 | myCTXPtr = aCtx.operator->(); |
139 | if (myDrawer.IsNull()) { |
140 | myDrawer = new AIS_Drawer; |
141 | #ifdef DEB |
142 | cout << "AIS_InteractiveObject::SetContext DRAWER NUL!" << endl; |
143 | #endif |
144 | } |
145 | myDrawer->Link(aCtx->DefaultDrawer()); |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : |
150 | //purpose : |
151 | //======================================================================= |
152 | Standard_Boolean AIS_InteractiveObject::HasOwner() const |
153 | { |
154 | return (!myOwner.IsNull()); |
155 | } |
156 | |
157 | |
158 | |
159 | //======================================================================= |
160 | //function : |
161 | //purpose : |
162 | //======================================================================= |
163 | void AIS_InteractiveObject::ClearOwner() |
164 | { |
165 | myOwner.Nullify(); |
166 | } |
167 | |
168 | //======================================================================= |
169 | //function : |
170 | //purpose : |
171 | //======================================================================= |
172 | Standard_Boolean AIS_InteractiveObject::HasUsers() const |
173 | { |
174 | return (!myUsers.IsEmpty()); |
175 | } |
176 | |
177 | |
178 | //======================================================================= |
179 | //function : |
180 | //purpose : |
181 | //======================================================================= |
182 | void AIS_InteractiveObject::AddUser(const Handle(Standard_Transient)& aUser) |
183 | { |
184 | myUsers.Append(aUser); |
185 | } |
186 | |
187 | //======================================================================= |
188 | //function : |
189 | //purpose : |
190 | //======================================================================= |
191 | void AIS_InteractiveObject::ClearUsers() |
192 | { |
193 | myUsers.Clear(); |
194 | } |
195 | |
196 | |
197 | //======================================================================= |
198 | //function : |
199 | //purpose : |
200 | //======================================================================= |
201 | void AIS_InteractiveObject::SetDisplayMode(const Standard_Integer aMode) |
202 | { |
203 | #ifdef BUC60632 |
204 | if( AcceptDisplayMode(aMode) ) |
205 | #endif |
206 | myDisplayMode = aMode; |
207 | } |
208 | |
209 | |
210 | //======================================================================= |
211 | //function : |
212 | //purpose : |
213 | //======================================================================= |
214 | void AIS_InteractiveObject::SetSelectionMode(const Standard_Integer aMode) |
215 | { |
216 | mySelectionMode = aMode; |
217 | } |
218 | |
219 | |
220 | |
221 | //======================================================================= |
222 | //function : |
223 | //purpose : |
224 | //======================================================================= |
225 | #ifdef GER61351 |
226 | void AIS_InteractiveObject::SetCurrentFacingModel(const Aspect_TypeOfFacingModel aModel) { |
227 | myCurrentFacingModel = aModel; |
228 | } |
229 | |
230 | //======================================================================= |
231 | //function : CurrentFacingModel |
232 | //purpose : |
233 | //======================================================================= |
234 | |
235 | Aspect_TypeOfFacingModel AIS_InteractiveObject::CurrentFacingModel() const { |
236 | return myCurrentFacingModel; |
237 | } |
238 | #endif |
239 | |
240 | //======================================================================= |
241 | //function : SetColor |
242 | //purpose : |
243 | //======================================================================= |
244 | |
245 | void AIS_InteractiveObject::SetColor(const Quantity_NameOfColor aColor) |
246 | #ifdef GER61351 |
247 | { |
248 | SetColor(Quantity_Color(aColor)); |
249 | } |
250 | |
251 | //======================================================================= |
252 | //function : SetColor |
253 | //purpose : |
254 | //======================================================================= |
255 | |
256 | void AIS_InteractiveObject::SetColor(const Quantity_Color &aColor) |
257 | #endif |
258 | { |
259 | myOwnColor = aColor; |
260 | hasOwnColor = Standard_True; |
261 | } |
262 | |
263 | //======================================================================= |
264 | //function : UnsetColor |
265 | //purpose : |
266 | //======================================================================= |
267 | void AIS_InteractiveObject::UnsetColor() |
268 | { |
269 | hasOwnColor = Standard_False; |
270 | } |
271 | |
272 | //======================================================================= |
273 | //function : |
274 | //purpose : |
275 | //======================================================================= |
276 | void AIS_InteractiveObject::SetWidth(const Standard_Real aValue) |
277 | { |
278 | myOwnWidth = aValue; |
279 | } |
280 | |
281 | //======================================================================= |
282 | //function : |
283 | //purpose : |
284 | //======================================================================= |
285 | void AIS_InteractiveObject::UnsetWidth() |
286 | { |
287 | myOwnWidth = 0.; |
288 | } |
289 | |
290 | |
291 | //======================================================================= |
292 | //function : |
293 | //purpose : |
294 | //======================================================================= |
295 | //POP pour K4L |
296 | void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfMaterial aName) |
297 | //void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfPhysicalMaterial aName) |
298 | { |
299 | if( HasColor() || IsTransparent() || HasMaterial() ) |
300 | { |
301 | myDrawer->ShadingAspect()->SetMaterial(aName); |
302 | } |
303 | else |
304 | { |
305 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
306 | |
307 | myDrawer->ShadingAspect()->SetMaterial(aName); |
308 | #ifndef BUC60577 //??? |
309 | myDrawer->ShadingAspect()->SetColor(AIS_GraphicTool::GetInteriorColor(myDrawer->Link())); |
310 | #endif |
311 | } |
312 | myOwnMaterial = aName; |
313 | hasOwnMaterial = Standard_True; |
314 | } |
315 | //======================================================================= |
316 | //function : SetMaterial |
317 | //purpose : |
318 | //======================================================================= |
319 | |
320 | void AIS_InteractiveObject::SetMaterial(const Graphic3d_MaterialAspect& aMat) |
321 | { |
322 | #ifdef BUC60577 |
323 | if( HasColor() || IsTransparent() || HasMaterial() ) |
324 | #else |
325 | if(hasOwnColor ||(myTransparency==0.0) || hasOwnMaterial ) |
326 | #endif |
327 | { |
328 | myDrawer->ShadingAspect()->SetMaterial(aMat); |
329 | } |
330 | else |
331 | { |
332 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
333 | myDrawer->ShadingAspect()->SetMaterial(aMat); |
334 | } |
335 | hasOwnMaterial = Standard_True; |
336 | |
337 | } |
338 | //======================================================================= |
339 | //function : |
340 | //purpose : |
341 | //======================================================================= |
342 | void AIS_InteractiveObject::UnsetMaterial() |
343 | { |
344 | #ifdef BUC60577 |
345 | if( !HasMaterial() ) return; |
346 | if( HasColor() || IsTransparent()) { |
347 | myDrawer->ShadingAspect()->SetMaterial( |
348 | AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
349 | if( HasColor() ) SetColor(myOwnColor); |
350 | if( IsTransparent() ) SetTransparency(myTransparency); |
351 | } |
352 | #else |
353 | if(!hasOwnMaterial) return; |
354 | if(hasOwnColor ||(myTransparency==0.0)) |
355 | { |
356 | myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
357 | } |
358 | #endif |
359 | else{ |
360 | Handle(Prs3d_ShadingAspect) SA; |
361 | myDrawer->SetShadingAspect(SA); |
362 | } |
363 | hasOwnMaterial = Standard_False; |
364 | } |
365 | |
366 | //======================================================================= |
367 | //function : SetTransparency |
368 | //purpose : |
369 | //======================================================================= |
370 | void AIS_InteractiveObject::SetTransparency(const Standard_Real aValue) |
371 | { |
372 | |
373 | #ifdef BUC60577 // Back & Front material can be different ! |
374 | |
375 | if(!HasColor() && !IsTransparent() && !HasMaterial() ) { |
376 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
377 | if(!myDrawer->Link().IsNull()) |
378 | myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
379 | } |
380 | Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
381 | Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial(); |
382 | FMat.SetTransparency(aValue); BMat.SetTransparency(aValue); |
383 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat); |
384 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat); |
385 | #else |
386 | if(aValue<0.0 || aValue>1.0) return; |
387 | |
388 | if(aValue<=0.05) |
389 | { |
390 | UnsetTransparency(); |
391 | return; |
392 | } |
393 | |
394 | |
395 | if(hasOwnColor || hasOwnMaterial || myTransparency> 0.0) |
396 | { |
397 | Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
398 | Mat.SetTransparency(aValue); |
399 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat); |
400 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat); |
401 | } |
402 | else |
403 | { |
404 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
405 | if(!myDrawer->Link().IsNull()) |
406 | myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link())); |
407 | Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
408 | Mat.SetTransparency(aValue); |
409 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat); |
410 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat); |
411 | } |
412 | #endif |
413 | myTransparency = aValue; |
414 | } |
415 | |
416 | //======================================================================= |
417 | //function : UnsetTransparency |
418 | //purpose : |
419 | //======================================================================= |
420 | void AIS_InteractiveObject::UnsetTransparency() |
421 | { |
422 | #ifdef BUC60577 // Back & Front material can be different ! |
423 | if(HasColor() || HasMaterial() ) |
424 | { |
425 | Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
426 | Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial(); |
427 | FMat.SetTransparency(0.); BMat.SetTransparency(0.); |
428 | myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat); |
429 | myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat); |
430 | } |
431 | #else |
432 | if(hasOwnColor || hasOwnMaterial ) |
433 | { |
434 | Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
435 | Mat.SetTransparency(0.0); |
436 | // myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat); |
437 | // myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat); |
438 | myDrawer->ShadingAspect()->SetMaterial(Mat); |
439 | } |
440 | #endif |
441 | else{ |
442 | Handle (Prs3d_ShadingAspect) SA; |
443 | myDrawer->SetShadingAspect(SA); |
444 | } |
445 | myTransparency =0.0; |
446 | } |
447 | //======================================================================= |
448 | //function : Transparency |
449 | //purpose : |
450 | //======================================================================= |
451 | Standard_Real AIS_InteractiveObject::Transparency() const |
452 | { |
453 | return (myTransparency<=0.05 ? 0 : myTransparency); |
454 | // Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial(); |
455 | // return Mat.Transparency(); |
456 | } |
457 | |
458 | //======================================================================= |
459 | //function : SetAttributes |
460 | //purpose : |
461 | //======================================================================= |
462 | |
463 | void AIS_InteractiveObject::SetAttributes(const Handle(AIS_Drawer)& aDrawer) |
464 | {myDrawer = aDrawer;} |
465 | |
466 | |
467 | //======================================================================= |
468 | //function : UnsetAttributes |
469 | //purpose : |
470 | //======================================================================= |
471 | void AIS_InteractiveObject::UnsetAttributes() |
472 | { |
473 | Handle(AIS_Drawer) dr = new AIS_Drawer(); |
474 | if(myDrawer->HasLink()) |
475 | dr->Link(myDrawer->Link()); |
476 | myDrawer = dr; |
477 | hasOwnColor = Standard_False; |
478 | hasOwnMaterial = Standard_False; |
479 | myOwnWidth = 0.0; |
480 | myTransparency = 0.0; |
481 | } |
482 | |
483 | //======================================================================= |
484 | //function : |
485 | //purpose : |
486 | //======================================================================= |
487 | void AIS_InteractiveObject::MustRecomputePrs(const Standard_Integer ) const |
488 | {} |
489 | |
490 | //======================================================================= |
491 | //function : |
492 | //purpose : |
493 | //======================================================================= |
494 | const TColStd_ListOfInteger& AIS_InteractiveObject::ListOfRecomputeModes() const |
495 | {return myToRecomputeModes;} |
496 | |
497 | //======================================================================= |
498 | //function : |
499 | //purpose : |
500 | //======================================================================= |
501 | void AIS_InteractiveObject::SetRecomputeOk() |
502 | {myToRecomputeModes.Clear();} |
503 | |
504 | |
505 | //======================================================================= |
506 | //function : AcceptDisplayMode |
507 | //purpose : |
508 | //======================================================================= |
509 | |
510 | Standard_Boolean AIS_InteractiveObject::AcceptDisplayMode(const Standard_Integer ) const |
511 | {return Standard_True;} |
512 | |
513 | //======================================================================= |
514 | //function : DefaultDisplayMode |
515 | //purpose : |
516 | //======================================================================= |
517 | |
518 | Standard_Integer AIS_InteractiveObject::DefaultDisplayMode() const |
519 | {return 0;} |
520 | |
521 | |
522 | //======================================================================= |
523 | //function : SetInfiniteState |
524 | //purpose : |
525 | //======================================================================= |
526 | void AIS_InteractiveObject::SetInfiniteState(const Standard_Boolean aFlag) |
527 | { |
528 | myInfiniteState = aFlag; |
529 | Handle(Prs3d_Presentation) P; |
530 | |
531 | for(Standard_Integer i =1; i<=myPresentations.Length();i++){ |
532 | P = Handle(Prs3d_Presentation)::DownCast(myPresentations(i).Presentation()); |
533 | if(!P.IsNull()) |
534 | P->SetInfiniteState(myInfiniteState);} |
535 | } |
536 | |
537 | #ifdef G003 |
538 | //======================================================================= |
539 | //function : SetDegenerateModel |
540 | //purpose : |
541 | //======================================================================= |
542 | void AIS_InteractiveObject::SetDegenerateModel( |
543 | const Aspect_TypeOfDegenerateModel aModel, |
544 | const Quantity_Ratio aRatio ) { |
545 | if( !HasColor() && !IsTransparent() && !HasMaterial() ) { |
546 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
547 | } |
548 | |
549 | myDrawer->ShadingAspect()->Aspect()->SetDegenerateModel(aModel,aRatio); |
550 | |
551 | if(!GetContext().IsNull()){ |
552 | if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){ |
553 | Handle(Prs3d_Presentation) P = |
554 | GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); |
555 | Handle(Graphic3d_AspectFillArea3d) a4bis = |
556 | myDrawer->ShadingAspect()->Aspect(); |
557 | P->SetPrimitivesAspect(a4bis); |
558 | } |
559 | } |
560 | } |
561 | |
562 | //======================================================================= |
563 | //function : DegenerateModel |
564 | //purpose : |
565 | //======================================================================= |
566 | |
567 | Aspect_TypeOfDegenerateModel AIS_InteractiveObject::DegenerateModel( |
568 | Quantity_Ratio& aRatio) const |
569 | { |
570 | return myDrawer->ShadingAspect()->Aspect()->DegenerateModel(aRatio); |
571 | } |
572 | #endif |
573 | |
574 | #ifdef IMP020200 |
575 | //======================================================================= |
576 | //function : SetTransformation |
577 | //purpose : |
578 | //======================================================================= |
579 | void AIS_InteractiveObject::SetTransformation(const Handle(Geom_Transformation)& aTrsf, const Standard_Boolean postConcatenate, const Standard_Boolean updateSelection) { |
580 | |
581 | if(!GetContext().IsNull()){ |
582 | const PrsMgr_Presentations& prs = Presentations(); |
583 | Handle(Prs3d_Presentation) P; |
584 | Standard_Integer mode; |
585 | myHasTransformation = Standard_True; |
586 | for( Standard_Integer i=1 ; i<=prs.Length() ; i++ ) { |
587 | mode = prs(i).Mode(); |
588 | P = GetContext()->MainPrsMgr()->CastPresentation(this,mode)->Presentation(); |
589 | if( postConcatenate ) P->Multiply(aTrsf); |
590 | else P->Transform(aTrsf); |
591 | if( updateSelection ) { |
592 | #ifdef IMP220501 |
593 | myCTXPtr->ClearSelected(Standard_True); |
594 | myCTXPtr->RecomputeSelectionOnly(this); |
595 | #else |
596 | if( HasSelection(mode) ) { |
597 | UpdateSelection(mode); |
598 | } |
599 | #endif |
600 | } |
601 | } |
602 | } |
603 | } |
604 | |
605 | //======================================================================= |
606 | //function : SetTransformation |
607 | //purpose : |
608 | //======================================================================= |
609 | void AIS_InteractiveObject::UnsetTransformation() { |
610 | #ifdef OCC708 |
611 | static Handle(Geom_Transformation) trsf = new Geom_Transformation( gp_Trsf() ); |
612 | #else |
613 | Handle(Geom_Transformation) trsf; |
614 | #endif |
615 | |
616 | SetTransformation(trsf); // Set identity transformation |
617 | myHasTransformation = Standard_False; |
618 | } |
619 | |
620 | //======================================================================= |
621 | //function : Transformation |
622 | //purpose : |
623 | //======================================================================= |
624 | Handle(Geom_Transformation) AIS_InteractiveObject::Transformation() { |
625 | Handle(Geom_Transformation) trsf; |
626 | |
627 | if(!GetContext().IsNull() ) { |
628 | const PrsMgr_Presentations& prs = Presentations(); |
629 | if( prs.Length() > 0 ) { |
630 | Handle(Prs3d_Presentation) P = |
631 | GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation(); |
632 | trsf = P->Transformation(); |
633 | } |
634 | } |
635 | |
636 | return trsf; |
637 | } |
638 | |
639 | //======================================================================= |
640 | //function : HasTransformation |
641 | //purpose : |
642 | //======================================================================= |
643 | Standard_Boolean AIS_InteractiveObject::HasTransformation() const { |
644 | |
645 | return myHasTransformation; |
646 | } |
647 | #endif |
648 | |
649 | #ifdef IMP140200 |
650 | //======================================================================= |
651 | //function : HasPresentation |
652 | //purpose : |
653 | //======================================================================= |
654 | Standard_Boolean AIS_InteractiveObject::HasPresentation() const { |
655 | |
656 | if( !GetContext().IsNull() && |
657 | GetContext()->MainPrsMgr()->HasPresentation(this,myDisplayMode) ) { |
658 | return Standard_True; |
659 | } |
660 | |
661 | return Standard_False; |
662 | } |
663 | |
664 | //======================================================================= |
665 | //function : Presentation |
666 | //purpose : |
667 | //======================================================================= |
668 | Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const { |
669 | Handle(Prs3d_Presentation) prs; |
670 | |
671 | if( HasPresentation() ) { |
672 | prs = GetContext()->MainPrsMgr()-> |
673 | CastPresentation(this,myDisplayMode)->Presentation(); |
674 | } |
675 | |
676 | return prs; |
677 | } |
678 | |
679 | //======================================================================= |
680 | //function : SetAspect |
681 | //purpose : |
682 | //======================================================================= |
683 | void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& anAspect, |
684 | const Standard_Boolean globalChange) { |
685 | |
686 | if( HasPresentation() ) { |
687 | Handle(Prs3d_Presentation) prs = Presentation(); |
688 | { Handle(Prs3d_ShadingAspect) aspect = |
689 | Handle(Prs3d_ShadingAspect)::DownCast(anAspect); |
690 | if( !aspect.IsNull() ) { |
691 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
692 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
693 | return; |
694 | } |
695 | } |
696 | { Handle(Prs3d_LineAspect) aspect = |
697 | Handle(Prs3d_LineAspect)::DownCast(anAspect); |
698 | if( !aspect.IsNull() ) { |
699 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
700 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
701 | return; |
702 | } |
703 | } |
704 | { Handle(Prs3d_PointAspect) aspect = |
705 | Handle(Prs3d_PointAspect)::DownCast(anAspect); |
706 | if( !aspect.IsNull() ) { |
707 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
708 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
709 | return; |
710 | } |
711 | } |
712 | { Handle(Prs3d_TextAspect) aspect = |
713 | Handle(Prs3d_TextAspect)::DownCast(anAspect); |
714 | if( !aspect.IsNull() ) { |
715 | if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect()); |
716 | Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect()); |
717 | return; |
718 | } |
719 | } |
720 | } |
721 | } |
722 | #endif |
723 | |
724 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
725 | |
726 | //======================================================================= |
727 | //function : SetPolygonOffsets |
728 | //purpose : |
729 | //======================================================================= |
730 | void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer aMode, |
731 | const Standard_Real aFactor, |
732 | const Standard_Real aUnits) |
733 | { |
734 | if ( !HasPolygonOffsets() ) |
735 | myDrawer->SetShadingAspect(new Prs3d_ShadingAspect()); |
736 | |
737 | myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode, aFactor, aUnits ); |
738 | |
739 | // Modify existing presentations |
740 | Handle(Graphic3d_Structure) aStruct; |
741 | for( Standard_Integer i = 1, n = myPresentations.Length(); i <= n; i++ ) { |
742 | Handle(PrsMgr_Presentation3d) aPrs3d = |
743 | Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() ); |
744 | if ( !aPrs3d.IsNull() ) { |
745 | aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() ); |
746 | if( !aStruct.IsNull() ) |
747 | aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() ); |
748 | } |
749 | } |
750 | } |
751 | |
752 | |
753 | //======================================================================= |
754 | //function : HasPolygonOffsets |
755 | //purpose : |
756 | //======================================================================= |
757 | Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets() const |
758 | { |
759 | return !( myDrawer->ShadingAspect().IsNull() || |
760 | ( !myDrawer->Link().IsNull() && |
761 | myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect() ) ); |
762 | } |
763 | |
764 | //======================================================================= |
765 | //function : PolygonOffsets |
766 | //purpose : |
767 | //======================================================================= |
768 | void AIS_InteractiveObject::PolygonOffsets(Standard_Integer& aMode, |
769 | Standard_Real& aFactor, |
770 | Standard_Real& aUnits) const |
771 | { |
772 | if( HasPolygonOffsets() ) |
773 | myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode, aFactor, aUnits ); |
774 | } |
775 | |
776 | void AIS_InteractiveObject::Fill(const Handle(PrsMgr_PresentationManager)& aPresentationManager, |
777 | const Handle(PrsMgr_Presentation)& aPresentation, |
778 | const Standard_Integer aMode) |
779 | { |
780 | PrsMgr_PresentableObject::Fill(aPresentationManager, aPresentation, aMode); |
781 | |
782 | // Update polygon offsets for <aPresentation> using <myDrawer> data |
783 | if ( !myDrawer->ShadingAspect().IsNull() ) |
784 | { |
785 | Standard_Integer aMode1 = Aspect_POM_Fill; |
786 | Standard_Real aFactor = 1., aUnits = 0.; |
787 | myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode1, aFactor, aUnits ); |
788 | |
789 | // Here we force this object to have default polygon offsets , if they are not |
790 | // turned on for this object explicitly |
791 | if ( ( aMode1 & Aspect_POM_None ) == Aspect_POM_None ) |
792 | { |
793 | aMode1 = Aspect_POM_Fill; |
794 | aFactor = 1.; |
795 | aUnits = 0.; |
796 | myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode1, aFactor, aUnits ); |
797 | } |
798 | } |
799 | |
800 | Handle(PrsMgr_Presentation3d) aPrs3d = |
801 | Handle(PrsMgr_Presentation3d)::DownCast( aPresentation ); |
802 | if ( !aPrs3d.IsNull() ) { |
803 | Handle(Graphic3d_Structure) aStruct = |
804 | Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() ); |
805 | if( !aStruct.IsNull() ) |
806 | aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() ); |
807 | } |
808 | } |
809 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |