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