0030571: Visualization, TKOpenGl - mapped texture is ignored while drawing points
[occt.git] / src / AIS / AIS_InteractiveObject.cxx
CommitLineData
b311480e 1// Created on: 1996-12-18
2// Created by: Robert COUBLANC
3// Copyright (c) 1996-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
f838dac4 17#include <AIS_InteractiveObject.hxx>
7fd59977 18
7fd59977 19#include <AIS_GraphicTool.hxx>
42cf5bc1 20#include <AIS_InteractiveContext.hxx>
42cf5bc1 21#include <Aspect_PolygonOffsetMode.hxx>
22#include <Bnd_Box.hxx>
7fd59977 23#include <Graphic3d_AspectFillArea3d.hxx>
3ddebf91 24#include <Graphic3d_AspectLine3d.hxx>
25#include <Graphic3d_AspectMarker3d.hxx>
26#include <Graphic3d_AspectText3d.hxx>
f751596e 27#include <Graphic3d_BndBox4f.hxx>
28#include <Graphic3d_CStructure.hxx>
7fd59977 29#include <Graphic3d_Group.hxx>
42cf5bc1 30#include <Graphic3d_MaterialAspect.hxx>
7fd59977 31#include <Graphic3d_Structure.hxx>
42cf5bc1 32#include <Prs3d_BasicAspect.hxx>
33#include <Prs3d_LineAspect.hxx>
34#include <Prs3d_PointAspect.hxx>
35#include <Prs3d_Presentation.hxx>
36#include <Prs3d_Root.hxx>
37#include <Prs3d_ShadingAspect.hxx>
38#include <Prs3d_TextAspect.hxx>
39#include <PrsMgr_ModedPresentation.hxx>
40#include <PrsMgr_PresentationManager3d.hxx>
41#include <Quantity_Color.hxx>
42#include <Standard_Transient.hxx>
43#include <Standard_Type.hxx>
44#include <TColStd_ListIteratorOfListOfInteger.hxx>
7fd59977 45
92efcf78 46IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveObject,SelectMgr_SelectableObject)
47
7fd59977 48//=======================================================================
49//function : AIS_InteractiveObject
50//purpose :
51//=======================================================================
f838dac4 52AIS_InteractiveObject::AIS_InteractiveObject (const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
53: SelectMgr_SelectableObject (aTypeOfPresentation3d),
54 myCTXPtr (NULL),
226fce20 55 myOwnWidth (0.0f),
f838dac4 56 myCurrentFacingModel (Aspect_TOFM_BOTH_SIDE),
57 myInfiniteState (Standard_False),
58 hasOwnColor (Standard_False),
226fce20 59 hasOwnMaterial (Standard_False)
7fd59977 60{
7fd59977 61 SetCurrentFacingModel();
7fd59977 62}
63
64//=======================================================================
65//function : Redisplay
36132a2e 66//purpose :
7fd59977 67//=======================================================================
36132a2e 68void AIS_InteractiveObject::Redisplay (const Standard_Boolean AllModes)
7fd59977 69{
36132a2e 70 if (myCTXPtr == NULL)
71 return;
72
73 myCTXPtr->Redisplay (this, Standard_False, AllModes);
7fd59977 74}
75
76//=======================================================================
77//function : Type
78//purpose :
79//=======================================================================
80
81AIS_KindOfInteractive AIS_InteractiveObject::Type() const
82{return AIS_KOI_None;}
83
84//=======================================================================
85//function : Signature
86//purpose :
87//=======================================================================
88
89Standard_Integer AIS_InteractiveObject::Signature() const
90{return -1;}
91
92//=======================================================================
7fd59977 93//function :
94//purpose :
95//=======================================================================
7fd59977 96Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const
97{
98 return myCTXPtr;
99}
100
101//=======================================================================
2ec85268 102//function : SetContext
103//purpose :
7fd59977 104//=======================================================================
2ec85268 105void AIS_InteractiveObject::SetContext (const Handle(AIS_InteractiveContext)& theCtx)
7fd59977 106{
2ec85268 107 if (myCTXPtr == theCtx.get())
108 {
da0e82aa 109 return;
2ec85268 110 }
111
112 myCTXPtr = theCtx.get();
113 if (!theCtx.IsNull())
114 {
115 myDrawer->Link (theCtx->DefaultDrawer());
116 }
7fd59977 117}
118
119//=======================================================================
120//function :
121//purpose :
122//=======================================================================
123Standard_Boolean AIS_InteractiveObject::HasOwner() const
124{
125 return (!myOwner.IsNull());
126}
127
128
129
130//=======================================================================
131//function :
132//purpose :
133//=======================================================================
134void AIS_InteractiveObject::ClearOwner()
135{
136 myOwner.Nullify();
137}
138
139//=======================================================================
f838dac4 140//function : SetDisplayMode
141//purpose :
7fd59977 142//=======================================================================
f838dac4 143void AIS_InteractiveObject::SetDisplayMode (const Standard_Integer theMode)
7fd59977 144{
f838dac4 145 if (AcceptDisplayMode (theMode))
146 {
147 myDrawer->SetDisplayMode (theMode);
148 }
7fd59977 149}
7fd59977 150
151//=======================================================================
152//function :
153//purpose :
154//=======================================================================
7fd59977 155void AIS_InteractiveObject::SetCurrentFacingModel(const Aspect_TypeOfFacingModel aModel) {
156 myCurrentFacingModel = aModel;
157}
158
159//=======================================================================
160//function : CurrentFacingModel
161//purpose :
162//=======================================================================
163
164Aspect_TypeOfFacingModel AIS_InteractiveObject::CurrentFacingModel() const {
165 return myCurrentFacingModel;
166}
7fd59977 167
168//=======================================================================
169//function : SetColor
170//purpose :
171//=======================================================================
172
f838dac4 173void AIS_InteractiveObject::SetColor(const Quantity_Color& theColor)
7fd59977 174{
f838dac4 175 myDrawer->SetColor (theColor);
7fd59977 176 hasOwnColor = Standard_True;
177}
178
179//=======================================================================
180//function : UnsetColor
181//purpose :
182//=======================================================================
183void AIS_InteractiveObject::UnsetColor()
184{
185 hasOwnColor = Standard_False;
186}
187
188//=======================================================================
189//function :
190//purpose :
191//=======================================================================
192void AIS_InteractiveObject::SetWidth(const Standard_Real aValue)
193{
226fce20 194 myOwnWidth = (Standard_ShortReal )aValue;
7fd59977 195}
196
197//=======================================================================
198//function :
199//purpose :
200//=======================================================================
201void AIS_InteractiveObject::UnsetWidth()
202{
226fce20 203 myOwnWidth = 0.0f;
7fd59977 204}
205
7fd59977 206//=======================================================================
87432b82 207//function : Material
b6472664 208//purpose :
7fd59977 209//=======================================================================
87432b82 210Graphic3d_NameOfMaterial AIS_InteractiveObject::Material() const
7fd59977 211{
87432b82 212 return myDrawer->ShadingAspect()->Material().Name();
7fd59977 213}
189f85a3 214
7fd59977 215//=======================================================================
216//function : SetMaterial
87432b82 217//purpose :
7fd59977 218//=======================================================================
189f85a3 219void AIS_InteractiveObject::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
7fd59977 220{
b6472664 221 if (!myDrawer->HasOwnShadingAspect())
6262338c 222 {
b6472664 223 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
224 if (myDrawer->HasLink())
225 {
226 *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
227 }
6262338c 228 }
87432b82 229
189f85a3 230 myDrawer->ShadingAspect()->SetMaterial (theMaterial);
7fd59977 231 hasOwnMaterial = Standard_True;
7fd59977 232}
189f85a3 233
7fd59977 234//=======================================================================
189f85a3 235//function : UnsetMaterial
236//purpose :
7fd59977 237//=======================================================================
238void AIS_InteractiveObject::UnsetMaterial()
239{
189f85a3 240 if (!HasMaterial())
241 {
242 return;
243 }
244
6262338c 245 if (HasColor() || IsTransparent())
246 {
247 if(myDrawer->HasLink())
248 {
249 myDrawer->ShadingAspect()->SetMaterial (AIS_GraphicTool::GetMaterial (myDrawer->Link()));
250 }
189f85a3 251
252 if (HasColor())
253 {
f838dac4 254 SetColor (myDrawer->Color());
189f85a3 255 }
256
257 if (IsTransparent())
258 {
f838dac4 259 SetTransparency (myDrawer->Transparency());
189f85a3 260 }
7fd59977 261 }
189f85a3 262 else
263 {
264 Handle(Prs3d_ShadingAspect) anAspect;
265 myDrawer->SetShadingAspect (anAspect);
7fd59977 266 }
189f85a3 267
7fd59977 268 hasOwnMaterial = Standard_False;
269}
270
271//=======================================================================
272//function : SetTransparency
4e1bc39a 273//purpose :
7fd59977 274//=======================================================================
4e1bc39a 275void AIS_InteractiveObject::SetTransparency (const Standard_Real theValue)
7fd59977 276{
b6472664 277 if (!myDrawer->HasOwnShadingAspect())
6262338c 278 {
279 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
280 if(myDrawer->HasLink())
281 myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link()));
7fd59977 282 }
4e1bc39a 283
284 myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (Standard_ShortReal(theValue));
285 myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (Standard_ShortReal(theValue));
286 myDrawer->SetTransparency (Standard_ShortReal(theValue));
7fd59977 287}
288
289//=======================================================================
290//function : UnsetTransparency
291//purpose :
292//=======================================================================
293void AIS_InteractiveObject::UnsetTransparency()
294{
6262338c 295 if(HasColor() || HasMaterial() )
296 {
4e1bc39a 297 myDrawer->ShadingAspect()->Aspect()->ChangeFrontMaterial().SetTransparency (0.0f);
298 myDrawer->ShadingAspect()->Aspect()->ChangeBackMaterial() .SetTransparency (0.0f);
6262338c 299 }
7fd59977 300 else{
301 Handle (Prs3d_ShadingAspect) SA;
302 myDrawer->SetShadingAspect(SA);
303 }
f838dac4 304 myDrawer->SetTransparency (0.0f);
7fd59977 305}
306//=======================================================================
307//function : Transparency
308//purpose :
309//=======================================================================
310Standard_Real AIS_InteractiveObject::Transparency() const
311{
f838dac4 312 return (myDrawer->Transparency() <= 0.005f ? 0.0 : myDrawer->Transparency());
7fd59977 313// Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
314// return Mat.Transparency();
315}
316
317//=======================================================================
7fd59977 318//function : UnsetAttributes
319//purpose :
320//=======================================================================
321void AIS_InteractiveObject::UnsetAttributes()
322{
6262338c 323 SelectMgr_SelectableObject::UnsetAttributes();
324
7fd59977 325 hasOwnColor = Standard_False;
326 hasOwnMaterial = Standard_False;
226fce20 327 myOwnWidth = 0.0f;
f838dac4 328 myDrawer->SetTransparency (0.0f);
7fd59977 329}
330
331//=======================================================================
7fd59977 332//function : AcceptDisplayMode
333//purpose :
334//=======================================================================
335
336Standard_Boolean AIS_InteractiveObject::AcceptDisplayMode(const Standard_Integer ) const
337{return Standard_True;}
338
339//=======================================================================
340//function : DefaultDisplayMode
341//purpose :
342//=======================================================================
343
344Standard_Integer AIS_InteractiveObject::DefaultDisplayMode() const
345{return 0;}
346
347
348//=======================================================================
349//function : SetInfiniteState
350//purpose :
351//=======================================================================
352void AIS_InteractiveObject::SetInfiniteState(const Standard_Boolean aFlag)
353{
354 myInfiniteState = aFlag;
355 Handle(Prs3d_Presentation) P;
356
5e5b6f81 357 for(Standard_Integer i =1; i<=myPresentations.Length();i++)
358 {
359 P = myPresentations(i).Presentation()->Presentation();
7fd59977 360 if(!P.IsNull())
5e5b6f81 361 P->SetInfiniteState(myInfiniteState);
362 }
7fd59977 363}
364
7fd59977 365//=======================================================================
7fd59977 366//function : HasPresentation
af324faa 367//purpose :
7fd59977 368//=======================================================================
af324faa 369Standard_Boolean AIS_InteractiveObject::HasPresentation() const
370{
f838dac4 371 return HasInteractiveContext()
372 && myCTXPtr->MainPrsMgr()->HasPresentation (this, myDrawer->DisplayMode());
7fd59977 373}
374
375//=======================================================================
376//function : Presentation
af324faa 377//purpose :
7fd59977 378//=======================================================================
af324faa 379Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const
380{
f838dac4 381 if (!HasInteractiveContext())
382 {
383 return Handle(Prs3d_Presentation)();
384 }
385
386 Handle(PrsMgr_Presentation) aPrs = myCTXPtr->MainPrsMgr()->Presentation (this, myDrawer->DisplayMode(), false);
387 return !aPrs.IsNull()
388 ? aPrs->Presentation()
af324faa 389 : Handle(Prs3d_Presentation)();
7fd59977 390}
391
392//=======================================================================
393//function : SetAspect
394//purpose :
395//=======================================================================
2831708b 396void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& anAspect)
397{
7fd59977 398
399 if( HasPresentation() ) {
400 Handle(Prs3d_Presentation) prs = Presentation();
401 { Handle(Prs3d_ShadingAspect) aspect =
402 Handle(Prs3d_ShadingAspect)::DownCast(anAspect);
403 if( !aspect.IsNull() ) {
7fd59977 404 Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
405 return;
406 }
407 }
408 { Handle(Prs3d_LineAspect) aspect =
409 Handle(Prs3d_LineAspect)::DownCast(anAspect);
410 if( !aspect.IsNull() ) {
7fd59977 411 Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
412 return;
413 }
414 }
415 { Handle(Prs3d_PointAspect) aspect =
416 Handle(Prs3d_PointAspect)::DownCast(anAspect);
417 if( !aspect.IsNull() ) {
7fd59977 418 Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
419 return;
420 }
421 }
422 { Handle(Prs3d_TextAspect) aspect =
423 Handle(Prs3d_TextAspect)::DownCast(anAspect);
424 if( !aspect.IsNull() ) {
7fd59977 425 Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
426 return;
427 }
428 }
429 }
430}
7fd59977 431
432//=======================================================================
433//function : SetPolygonOffsets
434//purpose :
435//=======================================================================
60be1f9b 436void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer aMode,
437 const Standard_ShortReal aFactor,
438 const Standard_ShortReal aUnits)
7fd59977 439{
440 if ( !HasPolygonOffsets() )
441 myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
442
443 myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode, aFactor, aUnits );
bf5f0ca2 444 SynchronizeAspects();
7fd59977 445}
446
7fd59977 447//=======================================================================
448//function : HasPolygonOffsets
449//purpose :
450//=======================================================================
451Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets() const
452{
453 return !( myDrawer->ShadingAspect().IsNull() ||
6262338c 454 ( myDrawer->HasLink() &&
7fd59977 455 myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect() ) );
456}
457
458//=======================================================================
459//function : PolygonOffsets
460//purpose :
461//=======================================================================
60be1f9b 462void AIS_InteractiveObject::PolygonOffsets(Standard_Integer& aMode,
463 Standard_ShortReal& aFactor,
464 Standard_ShortReal& aUnits) const
7fd59977 465{
466 if( HasPolygonOffsets() )
467 myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode, aFactor, aUnits );
468}
f751596e 469
470//=======================================================================
471//function : BoundingBox
472//purpose : Returns bounding box of object correspondingly to its
473// current display mode
474//=======================================================================
475void AIS_InteractiveObject::BoundingBox (Bnd_Box& theBndBox)
476{
f838dac4 477 if (myDrawer->DisplayMode() == -1)
f751596e 478 {
479 if (!myPresentations.IsEmpty())
480 {
481 const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations.First().Presentation();
482 const Handle(Graphic3d_Structure)& aStruct = aPrs3d->Presentation();
7c3ef2f7 483 const Graphic3d_BndBox3d& aBndBox = aStruct->CStructure()->BoundingBox();
b3c433fe 484
485 if (!aBndBox.IsValid())
486 {
487 theBndBox.SetVoid();
488 return;
489 }
490
7c3ef2f7 491 theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(),
492 aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z());
f751596e 493 return;
494 }
495 else
496 {
497 for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (Children()); aPrsIter.More(); aPrsIter.Next())
498 {
c5f3a425 499 Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
f751596e 500 if (aChild.IsNull())
501 {
502 continue;
503 }
504 Bnd_Box aBox;
505 aChild->BoundingBox (aBox);
506 theBndBox.Add (aBox);
507 }
508 return;
509 }
510 }
511 else
512 {
513 for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
514 {
f838dac4 515 if (myPresentations (aPrsIter).Mode() == myDrawer->DisplayMode())
f751596e 516 {
517 const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation();
518 const Handle(Graphic3d_Structure)& aStruct = aPrs3d->Presentation();
7c3ef2f7 519 const Graphic3d_BndBox3d& aBndBox = aStruct->CStructure()->BoundingBox();
b3c433fe 520
521 if (!aBndBox.IsValid())
522 {
523 theBndBox.SetVoid();
524 return;
525 }
526
7c3ef2f7 527 theBndBox.Update (aBndBox.CornerMin().x(), aBndBox.CornerMin().y(), aBndBox.CornerMin().z(),
528 aBndBox.CornerMax().x(), aBndBox.CornerMax().y(), aBndBox.CornerMax().z());
f751596e 529 return;
530 }
531 }
532 }
533}
5ad8c033 534
535//=======================================================================
536//function : SetIsoOnTriangulation
537//purpose : Enables or disables isoline on triangulation building
538//=======================================================================
539void AIS_InteractiveObject::SetIsoOnTriangulation (const Standard_Boolean theIsEnabled)
540{
541 myDrawer->SetIsoOnTriangulation (theIsEnabled);
542}
fb66bb28 543
544//=======================================================================
545//function : SynchronizeAspects
546//purpose :
547//=======================================================================
548void AIS_InteractiveObject::SynchronizeAspects()
549{
550 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
551 {
552 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue().Presentation();
553 if (aPrs3d.IsNull()
554 || aPrs3d->Presentation().IsNull())
555 {
556 continue;
557 }
558
559 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Presentation()->Groups()); aGroupIter.More(); aGroupIter.Next())
560 {
eaac0866 561 if (!aGroupIter.Value().IsNull())
fb66bb28 562 {
eaac0866 563 aGroupIter.ChangeValue()->SynchronizeAspects();
fb66bb28 564 }
565 }
566 }
567}
bf5f0ca2 568
569//=======================================================================
570//function : replaceAspects
571//purpose :
572//=======================================================================
573void AIS_InteractiveObject::replaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap)
574{
575 if (theMap.IsEmpty())
576 {
577 return;
578 }
579
580 for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next())
581 {
582 const Handle(PrsMgr_Presentation)& aPrs3d = aPrsIter.ChangeValue().Presentation();
583 if (aPrs3d.IsNull()
584 || aPrs3d->Presentation().IsNull())
585 {
586 continue;
587 }
588
589 for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPrs3d->Presentation()->Groups()); aGroupIter.More(); aGroupIter.Next())
590 {
591 if (!aGroupIter.Value().IsNull())
592 {
593 aGroupIter.ChangeValue()->ReplaceAspects (theMap);
594 }
595 }
596 }
597}