0024732: OpenGl_Context - retrieve functions up to GL4.4
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#include <PrsMgr_PresentationManager.ixx>
16#include <PrsMgr_PresentableObject.hxx>
17#include <PrsMgr_Presentation.hxx>
18#include <PrsMgr_Presentations.hxx>
19#include <PrsMgr_ModedPresentation.hxx>
20#include <TColStd_ListIteratorOfListOfTransient.hxx>
21
22
23PrsMgr_PresentationManager::PrsMgr_PresentationManager ():
24myImmediateMode(Standard_False){}
25
26
27void PrsMgr_PresentationManager::Display(
28 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
29 const Standard_Integer aMode)
30{
31 if (!HasPresentation(aPresentableObject,aMode)){
32 AddPresentation(aPresentableObject,aMode);
33 }
34 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
35 Update(aPresentableObject,aMode);
36 }
37
38 if(myImmediateMode)
39 Add(aPresentableObject,aMode);
40 else
41 Presentation(aPresentableObject,aMode)->Display();
42}
43
44void PrsMgr_PresentationManager::Erase(
45 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
46 const Standard_Integer aMode)
47{
eef7fc64 48 if (HasPresentation(aPresentableObject,aMode))
49 {
7fd59977 50 if(myImmediateMode)
eef7fc64 51 {
7fd59977 52 Remove(aPresentableObject,aMode);
eef7fc64 53 }
7fd59977 54 else
eef7fc64 55 {
56 Presentation(aPresentableObject,aMode)->Erase();
57 }
58
59 RemovePresentation (aPresentableObject,aMode);
60 }
7fd59977 61}
62
63void PrsMgr_PresentationManager::Clear(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
64 const Standard_Integer aMode)
65{
66 if (HasPresentation(aPresentableObject,aMode)){
67 if(myImmediateMode)
68 Remove(aPresentableObject,aMode);
69 else
70 Presentation(aPresentableObject,aMode)->Clear();}
71}
72
eb4320f2 73void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
74 const Standard_Integer theMode,
75 const Standard_Boolean theValue)
76{
77 Presentation(thePresentableObject, theMode)->SetVisible (theValue);
78}
7fd59977 79
80void PrsMgr_PresentationManager::Highlight(
81 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
82 const Standard_Integer aMode)
83{
84 if (!HasPresentation(aPresentableObject,aMode)){
85 AddPresentation(aPresentableObject,aMode);
86 }
87 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
88 Update(aPresentableObject,aMode);
89 }
90 Presentation(aPresentableObject,aMode)->Highlight();
91
92 if(myImmediateMode)
93 Add(aPresentableObject,aMode);
94}
95
96void PrsMgr_PresentationManager::Unhighlight(
97 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
98 const Standard_Integer aMode)
99{
100 if (HasPresentation(aPresentableObject,aMode)){
101 Presentation(aPresentableObject,aMode)->Unhighlight();
102 if(myImmediateMode)
103 Remove(aPresentableObject,aMode);
104 }
105}
106
107
108void PrsMgr_PresentationManager::
109SetDisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
110 const Standard_Integer aMode,
111 const Standard_Integer theNewPrior) const
112{
113 if (HasPresentation(aPresentableObject,aMode))
114 Presentation(aPresentableObject,aMode)->SetDisplayPriority(theNewPrior);
115}
116
117Standard_Integer PrsMgr_PresentationManager::
118DisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
119 const Standard_Integer aMode) const
120{
121 if (HasPresentation(aPresentableObject,aMode))
122 return Presentation(aPresentableObject,aMode)->DisplayPriority();
123
124 return 0;
125}
126
127
128Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (
129 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
130 const Standard_Integer aMode) const {
131 if (HasPresentation(aPresentableObject,aMode))
132 return Presentation(aPresentableObject,aMode)->IsDisplayed();
133 return Standard_False;
134 }
135
136Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (
137 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
138 const Standard_Integer aMode) const {
139 if (HasPresentation(aPresentableObject,aMode))
140 return Presentation(aPresentableObject,aMode)->IsHighlighted();
141 return Standard_False;
142 }
143
144void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Standard_Integer aMode ) const {
145 if(HasPresentation(aPresentableObject,aMode)) {
146 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
147 if (!P.IsNull()) {
148 P->Clear();
149 aPresentableObject->Fill(this,P,aMode);
150 P->SetUpdateStatus(Standard_False);
151 }
152 }
153}
154void PrsMgr_PresentationManager::BeginDraw() {
155 myImmediateMode = Standard_True;
156 myImmediateList.Clear();
157}
158
159
160void PrsMgr_PresentationManager::Add(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
161 const Standard_Integer aMode) {
162 if (myImmediateMode ) {
163 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
164 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
165 if(it.Value()==P) return;
166 }
167 myImmediateList.Append(P);
168 }
169}
170void PrsMgr_PresentationManager::Remove(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
171 const Standard_Integer aMode) {
172 if (myImmediateMode ) {
173 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
174 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
175 if(it.Value()==P) {
176 myImmediateList.Remove(it);
177 return;
178 }
179 }
180 }
181}
182
183
184
185
186Standard_Boolean PrsMgr_PresentationManager::HasPresentation
187 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
188 const Standard_Integer aMode) const {
189
190 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
191 Standard_Boolean found = Standard_False;
192 Standard_Integer i=1; Standard_Integer l= S.Length();
193 while (i<= l && !found) {
194// modif WOK++ : operator == is ambiguous
195// found = aMode == S(i).Mode()
196// && this == S(i).Presentation()->PresentationManager();
197 const Handle (PrsMgr_Presentation)& popPrs = S(i).Presentation();
198 const Handle (PrsMgr_PresentationManager)& popPrsMgr = popPrs->PresentationManager();
199 if ( aMode == S(i).Mode() && this == popPrsMgr )
200 found = Standard_True;
201 i++;
202 }
203 return found;
204 }
205
206Handle (PrsMgr_Presentation)
207 PrsMgr_PresentationManager::Presentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
208 const Standard_Integer aMode) const
209{
210 Handle(PrsMgr_Presentation) P;
211 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
212 Standard_Boolean found = Standard_False;
213 Standard_Integer i=1; Standard_Integer l= S.Length();
214 while (i<= l && !found) {
215 P = S(i).Presentation();
216 const Handle (PrsMgr_PresentationManager)& popPrsMgr = P->PresentationManager();
217 if (aMode == S(i).Mode() && this == popPrsMgr) {
218 found = Standard_True;
219
220
221 }
222 i++;
223 }
224
225 return P;
226}
227
228void PrsMgr_PresentationManager::AddPresentation
229 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
230 const Standard_Integer aMode) {
231
232 Handle(PrsMgr_Presentation) P = newPresentation(aPresentableObject);
233 aPresentableObject->Presentations().Append(PrsMgr_ModedPresentation(P,aMode));
234 aPresentableObject->Fill(this,P,aMode);
59f45b7c 235
236 // set layer index accordingly to object's presentations
237 Standard_Integer aZLayerId = GetZLayer (aPresentableObject);
238 if (aZLayerId >= 0)
239 P->SetZLayer (aZLayerId);
240
7fd59977 241 P->SetUpdateStatus(Standard_False);
242}
243
244void PrsMgr_PresentationManager::RemovePresentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
245 const Standard_Integer aMode)
246{
247 PrsMgr_Presentations& S = aPresentableObject->Presentations();
248 Standard_Integer i = 1;
249 Standard_Integer n = S.Length();
250 while (i<= n) {
251 if (aMode == S(i).Mode()) {
252 S.Remove(i);
253 break;
254 }
255 i++;
256 }
257}
258
59f45b7c 259//=======================================================================
260//function : SetZLayer
261//purpose :
262//=======================================================================
263
264void PrsMgr_PresentationManager::SetZLayer
265 (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
266 const Standard_Integer theLayerId)
267{
268 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
269 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
270 {
271 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
272 if (aPrs->PresentationManager () == this)
273 aPrs->SetZLayer (theLayerId);
274 }
275}
276
277//=======================================================================
278//function : GetZLayer
279//purpose :
280//=======================================================================
281
282Standard_Integer PrsMgr_PresentationManager::GetZLayer
283 (const Handle(PrsMgr_PresentableObject)& thePresentableObject) const
284{
285 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
286 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
287 {
288 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
289 if (aPrs->PresentationManager () == this)
290 return aPrs->GetZLayer ();
291 }
292
293 return -1;
294}