0030674: Visualization, AIS_InteractiveObject - fix accessibility of several properties
[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
42cf5bc1 19#include <AIS_InteractiveContext.hxx>
7fd59977 20#include <Graphic3d_AspectFillArea3d.hxx>
3ddebf91 21#include <Graphic3d_AspectLine3d.hxx>
22#include <Graphic3d_AspectMarker3d.hxx>
23#include <Graphic3d_AspectText3d.hxx>
f751596e 24#include <Graphic3d_CStructure.hxx>
7fd59977 25#include <Graphic3d_Group.hxx>
26#include <Graphic3d_Structure.hxx>
42cf5bc1 27#include <Prs3d_LineAspect.hxx>
28#include <Prs3d_PointAspect.hxx>
29#include <Prs3d_Presentation.hxx>
42cf5bc1 30#include <Prs3d_ShadingAspect.hxx>
31#include <Prs3d_TextAspect.hxx>
32#include <PrsMgr_ModedPresentation.hxx>
2b886265 33#include <PrsMgr_PresentationManager.hxx>
7fd59977 34
92efcf78 35IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveObject,SelectMgr_SelectableObject)
36
7fd59977 37//=======================================================================
38//function : AIS_InteractiveObject
39//purpose :
40//=======================================================================
f838dac4 41AIS_InteractiveObject::AIS_InteractiveObject (const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
42: SelectMgr_SelectableObject (aTypeOfPresentation3d),
2b886265 43 myCTXPtr (NULL)
7fd59977 44{
2b886265 45 //
7fd59977 46}
47
48//=======================================================================
49//function : Redisplay
36132a2e 50//purpose :
7fd59977 51//=======================================================================
36132a2e 52void AIS_InteractiveObject::Redisplay (const Standard_Boolean AllModes)
7fd59977 53{
36132a2e 54 if (myCTXPtr == NULL)
55 return;
56
57 myCTXPtr->Redisplay (this, Standard_False, AllModes);
7fd59977 58}
59
7fd59977 60//=======================================================================
61//function :
62//purpose :
63//=======================================================================
64Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const
65{
66 return myCTXPtr;
67}
68
69//=======================================================================
2ec85268 70//function : SetContext
71//purpose :
7fd59977 72//=======================================================================
2ec85268 73void AIS_InteractiveObject::SetContext (const Handle(AIS_InteractiveContext)& theCtx)
7fd59977 74{
2ec85268 75 if (myCTXPtr == theCtx.get())
76 {
da0e82aa 77 return;
2ec85268 78 }
79
80 myCTXPtr = theCtx.get();
81 if (!theCtx.IsNull())
82 {
83 myDrawer->Link (theCtx->DefaultDrawer());
84 }
7fd59977 85}
86
7fd59977 87//=======================================================================
88//function : HasPresentation
af324faa 89//purpose :
7fd59977 90//=======================================================================
af324faa 91Standard_Boolean AIS_InteractiveObject::HasPresentation() const
92{
f838dac4 93 return HasInteractiveContext()
94 && myCTXPtr->MainPrsMgr()->HasPresentation (this, myDrawer->DisplayMode());
7fd59977 95}
96
97//=======================================================================
98//function : Presentation
af324faa 99//purpose :
7fd59977 100//=======================================================================
af324faa 101Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const
102{
f838dac4 103 if (!HasInteractiveContext())
104 {
105 return Handle(Prs3d_Presentation)();
106 }
107
108 Handle(PrsMgr_Presentation) aPrs = myCTXPtr->MainPrsMgr()->Presentation (this, myDrawer->DisplayMode(), false);
109 return !aPrs.IsNull()
110 ? aPrs->Presentation()
af324faa 111 : Handle(Prs3d_Presentation)();
7fd59977 112}
113
114//=======================================================================
115//function : SetAspect
116//purpose :
117//=======================================================================
2b886265 118void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& theAspect)
2831708b 119{
7fd59977 120
2b886265 121 if (!HasPresentation())
122 {
123 return;
7fd59977 124 }
7fd59977 125
2b886265 126 Handle(Prs3d_Presentation) aPrs = Presentation();
127 if (aPrs->Groups().IsEmpty())
f751596e 128 {
2b886265 129 return;
f751596e 130 }
2b886265 131 const Handle(Graphic3d_Group)& aGroup = aPrs->Groups().Last();
132 if (Handle(Prs3d_ShadingAspect) aShadingAspect = Handle(Prs3d_ShadingAspect)::DownCast(theAspect))
f751596e 133 {
2b886265 134 aGroup->SetGroupPrimitivesAspect (aShadingAspect->Aspect());
f751596e 135 }
2b886265 136 else if (Handle(Prs3d_LineAspect) aLineAspect = Handle(Prs3d_LineAspect)::DownCast(theAspect))
fb66bb28 137 {
2b886265 138 aGroup->SetGroupPrimitivesAspect (aLineAspect->Aspect());
fb66bb28 139 }
2b886265 140 else if (Handle(Prs3d_PointAspect) aPointAspect = Handle(Prs3d_PointAspect)::DownCast(theAspect))
bf5f0ca2 141 {
2b886265 142 aGroup->SetGroupPrimitivesAspect (aPointAspect->Aspect());
bf5f0ca2 143 }
2b886265 144 else if (Handle(Prs3d_TextAspect) aTextAspect = Handle(Prs3d_TextAspect)::DownCast(theAspect))
bf5f0ca2 145 {
2b886265 146 aGroup->SetGroupPrimitivesAspect (aTextAspect->Aspect());
bf5f0ca2 147 }
148}