0023000: Improve the way the gradient and textured background is managed in 3d viewer
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager.cxx
CommitLineData
7fd59977 1#include <PrsMgr_PresentationManager.ixx>
2#include <PrsMgr_PresentableObject.hxx>
3#include <PrsMgr_Presentation.hxx>
4#include <PrsMgr_Presentations.hxx>
5#include <PrsMgr_ModedPresentation.hxx>
6#include <TColStd_ListIteratorOfListOfTransient.hxx>
7
8
9PrsMgr_PresentationManager::PrsMgr_PresentationManager ():
10myImmediateMode(Standard_False){}
11
12
13void PrsMgr_PresentationManager::Display(
14 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
15 const Standard_Integer aMode)
16{
17 if (!HasPresentation(aPresentableObject,aMode)){
18 AddPresentation(aPresentableObject,aMode);
19 }
20 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
21 Update(aPresentableObject,aMode);
22 }
23
24 if(myImmediateMode)
25 Add(aPresentableObject,aMode);
26 else
27 Presentation(aPresentableObject,aMode)->Display();
28}
29
30void PrsMgr_PresentationManager::Erase(
31 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
32 const Standard_Integer aMode)
33{
34 if (HasPresentation(aPresentableObject,aMode)){
35 if(myImmediateMode)
36 Remove(aPresentableObject,aMode);
37 else
38 Presentation(aPresentableObject,aMode)->Erase();}
39}
40
41void PrsMgr_PresentationManager::Clear(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
42 const Standard_Integer aMode)
43{
44 if (HasPresentation(aPresentableObject,aMode)){
45 if(myImmediateMode)
46 Remove(aPresentableObject,aMode);
47 else
48 Presentation(aPresentableObject,aMode)->Clear();}
49}
50
51
52void PrsMgr_PresentationManager::Highlight(
53 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
54 const Standard_Integer aMode)
55{
56 if (!HasPresentation(aPresentableObject,aMode)){
57 AddPresentation(aPresentableObject,aMode);
58 }
59 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
60 Update(aPresentableObject,aMode);
61 }
62 Presentation(aPresentableObject,aMode)->Highlight();
63
64 if(myImmediateMode)
65 Add(aPresentableObject,aMode);
66}
67
68void PrsMgr_PresentationManager::Unhighlight(
69 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
70 const Standard_Integer aMode)
71{
72 if (HasPresentation(aPresentableObject,aMode)){
73 Presentation(aPresentableObject,aMode)->Unhighlight();
74 if(myImmediateMode)
75 Remove(aPresentableObject,aMode);
76 }
77}
78
79
80void PrsMgr_PresentationManager::
81SetDisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
82 const Standard_Integer aMode,
83 const Standard_Integer theNewPrior) const
84{
85 if (HasPresentation(aPresentableObject,aMode))
86 Presentation(aPresentableObject,aMode)->SetDisplayPriority(theNewPrior);
87}
88
89Standard_Integer PrsMgr_PresentationManager::
90DisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
91 const Standard_Integer aMode) const
92{
93 if (HasPresentation(aPresentableObject,aMode))
94 return Presentation(aPresentableObject,aMode)->DisplayPriority();
95
96 return 0;
97}
98
99
100Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (
101 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
102 const Standard_Integer aMode) const {
103 if (HasPresentation(aPresentableObject,aMode))
104 return Presentation(aPresentableObject,aMode)->IsDisplayed();
105 return Standard_False;
106 }
107
108Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (
109 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
110 const Standard_Integer aMode) const {
111 if (HasPresentation(aPresentableObject,aMode))
112 return Presentation(aPresentableObject,aMode)->IsHighlighted();
113 return Standard_False;
114 }
115
116void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Standard_Integer aMode ) const {
117 if(HasPresentation(aPresentableObject,aMode)) {
118 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
119 if (!P.IsNull()) {
120 P->Clear();
121 aPresentableObject->Fill(this,P,aMode);
122 P->SetUpdateStatus(Standard_False);
123 }
124 }
125}
126void PrsMgr_PresentationManager::BeginDraw() {
127 myImmediateMode = Standard_True;
128 myImmediateList.Clear();
129}
130
131
132void PrsMgr_PresentationManager::Add(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
133 const Standard_Integer aMode) {
134 if (myImmediateMode ) {
135 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
136 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
137 if(it.Value()==P) return;
138 }
139 myImmediateList.Append(P);
140 }
141}
142void PrsMgr_PresentationManager::Remove(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
143 const Standard_Integer aMode) {
144 if (myImmediateMode ) {
145 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
146 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
147 if(it.Value()==P) {
148 myImmediateList.Remove(it);
149 return;
150 }
151 }
152 }
153}
154
155
156
157
158Standard_Boolean PrsMgr_PresentationManager::HasPresentation
159 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
160 const Standard_Integer aMode) const {
161
162 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
163 Standard_Boolean found = Standard_False;
164 Standard_Integer i=1; Standard_Integer l= S.Length();
165 while (i<= l && !found) {
166// modif WOK++ : operator == is ambiguous
167// found = aMode == S(i).Mode()
168// && this == S(i).Presentation()->PresentationManager();
169 const Handle (PrsMgr_Presentation)& popPrs = S(i).Presentation();
170 const Handle (PrsMgr_PresentationManager)& popPrsMgr = popPrs->PresentationManager();
171 if ( aMode == S(i).Mode() && this == popPrsMgr )
172 found = Standard_True;
173 i++;
174 }
175 return found;
176 }
177
178Handle (PrsMgr_Presentation)
179 PrsMgr_PresentationManager::Presentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
180 const Standard_Integer aMode) const
181{
182 Handle(PrsMgr_Presentation) P;
183 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
184 Standard_Boolean found = Standard_False;
185 Standard_Integer i=1; Standard_Integer l= S.Length();
186 while (i<= l && !found) {
187 P = S(i).Presentation();
188 const Handle (PrsMgr_PresentationManager)& popPrsMgr = P->PresentationManager();
189 if (aMode == S(i).Mode() && this == popPrsMgr) {
190 found = Standard_True;
191
192
193 }
194 i++;
195 }
196
197 return P;
198}
199
200void PrsMgr_PresentationManager::AddPresentation
201 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
202 const Standard_Integer aMode) {
203
204 Handle(PrsMgr_Presentation) P = newPresentation(aPresentableObject);
205 aPresentableObject->Presentations().Append(PrsMgr_ModedPresentation(P,aMode));
206 aPresentableObject->Fill(this,P,aMode);
207 P->SetUpdateStatus(Standard_False);
208}
209
210void PrsMgr_PresentationManager::RemovePresentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
211 const Standard_Integer aMode)
212{
213 PrsMgr_Presentations& S = aPresentableObject->Presentations();
214 Standard_Integer i = 1;
215 Standard_Integer n = S.Length();
216 while (i<= n) {
217 if (aMode == S(i).Mode()) {
218 S.Remove(i);
219 break;
220 }
221 i++;
222 }
223}
224