0024167: Compiler warnings 'unreacheable code' and 'conditional expression is constan...
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <PrsMgr_PresentationManager.ixx>
20#include <PrsMgr_PresentableObject.hxx>
21#include <PrsMgr_Presentation.hxx>
22#include <PrsMgr_Presentations.hxx>
23#include <PrsMgr_ModedPresentation.hxx>
24#include <TColStd_ListIteratorOfListOfTransient.hxx>
25
26
27PrsMgr_PresentationManager::PrsMgr_PresentationManager ():
28myImmediateMode(Standard_False){}
29
30
31void PrsMgr_PresentationManager::Display(
32 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
33 const Standard_Integer aMode)
34{
35 if (!HasPresentation(aPresentableObject,aMode)){
36 AddPresentation(aPresentableObject,aMode);
37 }
38 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
39 Update(aPresentableObject,aMode);
40 }
41
42 if(myImmediateMode)
43 Add(aPresentableObject,aMode);
44 else
45 Presentation(aPresentableObject,aMode)->Display();
46}
47
48void PrsMgr_PresentationManager::Erase(
49 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
50 const Standard_Integer aMode)
51{
52 if (HasPresentation(aPresentableObject,aMode)){
53 if(myImmediateMode)
54 Remove(aPresentableObject,aMode);
55 else
56 Presentation(aPresentableObject,aMode)->Erase();}
57}
58
59void PrsMgr_PresentationManager::Clear(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
60 const Standard_Integer aMode)
61{
62 if (HasPresentation(aPresentableObject,aMode)){
63 if(myImmediateMode)
64 Remove(aPresentableObject,aMode);
65 else
66 Presentation(aPresentableObject,aMode)->Clear();}
67}
68
69
70void PrsMgr_PresentationManager::Highlight(
71 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
72 const Standard_Integer aMode)
73{
74 if (!HasPresentation(aPresentableObject,aMode)){
75 AddPresentation(aPresentableObject,aMode);
76 }
77 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
78 Update(aPresentableObject,aMode);
79 }
80 Presentation(aPresentableObject,aMode)->Highlight();
81
82 if(myImmediateMode)
83 Add(aPresentableObject,aMode);
84}
85
86void PrsMgr_PresentationManager::Unhighlight(
87 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
88 const Standard_Integer aMode)
89{
90 if (HasPresentation(aPresentableObject,aMode)){
91 Presentation(aPresentableObject,aMode)->Unhighlight();
92 if(myImmediateMode)
93 Remove(aPresentableObject,aMode);
94 }
95}
96
97
98void PrsMgr_PresentationManager::
99SetDisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
100 const Standard_Integer aMode,
101 const Standard_Integer theNewPrior) const
102{
103 if (HasPresentation(aPresentableObject,aMode))
104 Presentation(aPresentableObject,aMode)->SetDisplayPriority(theNewPrior);
105}
106
107Standard_Integer PrsMgr_PresentationManager::
108DisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
109 const Standard_Integer aMode) const
110{
111 if (HasPresentation(aPresentableObject,aMode))
112 return Presentation(aPresentableObject,aMode)->DisplayPriority();
113
114 return 0;
115}
116
117
118Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (
119 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
120 const Standard_Integer aMode) const {
121 if (HasPresentation(aPresentableObject,aMode))
122 return Presentation(aPresentableObject,aMode)->IsDisplayed();
123 return Standard_False;
124 }
125
126Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (
127 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
128 const Standard_Integer aMode) const {
129 if (HasPresentation(aPresentableObject,aMode))
130 return Presentation(aPresentableObject,aMode)->IsHighlighted();
131 return Standard_False;
132 }
133
134void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Standard_Integer aMode ) const {
135 if(HasPresentation(aPresentableObject,aMode)) {
136 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
137 if (!P.IsNull()) {
138 P->Clear();
139 aPresentableObject->Fill(this,P,aMode);
140 P->SetUpdateStatus(Standard_False);
141 }
142 }
143}
144void PrsMgr_PresentationManager::BeginDraw() {
145 myImmediateMode = Standard_True;
146 myImmediateList.Clear();
147}
148
149
150void PrsMgr_PresentationManager::Add(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
151 const Standard_Integer aMode) {
152 if (myImmediateMode ) {
153 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
154 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
155 if(it.Value()==P) return;
156 }
157 myImmediateList.Append(P);
158 }
159}
160void PrsMgr_PresentationManager::Remove(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) {
166 myImmediateList.Remove(it);
167 return;
168 }
169 }
170 }
171}
172
173
174
175
176Standard_Boolean PrsMgr_PresentationManager::HasPresentation
177 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
178 const Standard_Integer aMode) const {
179
180 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
181 Standard_Boolean found = Standard_False;
182 Standard_Integer i=1; Standard_Integer l= S.Length();
183 while (i<= l && !found) {
184// modif WOK++ : operator == is ambiguous
185// found = aMode == S(i).Mode()
186// && this == S(i).Presentation()->PresentationManager();
187 const Handle (PrsMgr_Presentation)& popPrs = S(i).Presentation();
188 const Handle (PrsMgr_PresentationManager)& popPrsMgr = popPrs->PresentationManager();
189 if ( aMode == S(i).Mode() && this == popPrsMgr )
190 found = Standard_True;
191 i++;
192 }
193 return found;
194 }
195
196Handle (PrsMgr_Presentation)
197 PrsMgr_PresentationManager::Presentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
198 const Standard_Integer aMode) const
199{
200 Handle(PrsMgr_Presentation) P;
201 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
202 Standard_Boolean found = Standard_False;
203 Standard_Integer i=1; Standard_Integer l= S.Length();
204 while (i<= l && !found) {
205 P = S(i).Presentation();
206 const Handle (PrsMgr_PresentationManager)& popPrsMgr = P->PresentationManager();
207 if (aMode == S(i).Mode() && this == popPrsMgr) {
208 found = Standard_True;
209
210
211 }
212 i++;
213 }
214
215 return P;
216}
217
218void PrsMgr_PresentationManager::AddPresentation
219 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
220 const Standard_Integer aMode) {
221
222 Handle(PrsMgr_Presentation) P = newPresentation(aPresentableObject);
223 aPresentableObject->Presentations().Append(PrsMgr_ModedPresentation(P,aMode));
224 aPresentableObject->Fill(this,P,aMode);
59f45b7c 225
226 // set layer index accordingly to object's presentations
227 Standard_Integer aZLayerId = GetZLayer (aPresentableObject);
228 if (aZLayerId >= 0)
229 P->SetZLayer (aZLayerId);
230
7fd59977 231 P->SetUpdateStatus(Standard_False);
232}
233
234void PrsMgr_PresentationManager::RemovePresentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
235 const Standard_Integer aMode)
236{
237 PrsMgr_Presentations& S = aPresentableObject->Presentations();
238 Standard_Integer i = 1;
239 Standard_Integer n = S.Length();
240 while (i<= n) {
241 if (aMode == S(i).Mode()) {
242 S.Remove(i);
243 break;
244 }
245 i++;
246 }
247}
248
59f45b7c 249//=======================================================================
250//function : SetZLayer
251//purpose :
252//=======================================================================
253
254void PrsMgr_PresentationManager::SetZLayer
255 (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
256 const Standard_Integer theLayerId)
257{
258 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
259 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
260 {
261 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
262 if (aPrs->PresentationManager () == this)
263 aPrs->SetZLayer (theLayerId);
264 }
265}
266
267//=======================================================================
268//function : GetZLayer
269//purpose :
270//=======================================================================
271
272Standard_Integer PrsMgr_PresentationManager::GetZLayer
273 (const Handle(PrsMgr_PresentableObject)& thePresentableObject) const
274{
275 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
276 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
277 {
278 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
279 if (aPrs->PresentationManager () == this)
280 return aPrs->GetZLayer ();
281 }
282
283 return -1;
284}