0023654: Problem with displaying vertices in OCC view after closing all OCC views...
[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
eb4320f2 69void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
70 const Standard_Integer theMode,
71 const Standard_Boolean theValue)
72{
73 Presentation(thePresentableObject, theMode)->SetVisible (theValue);
74}
7fd59977 75
76void PrsMgr_PresentationManager::Highlight(
77 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
78 const Standard_Integer aMode)
79{
80 if (!HasPresentation(aPresentableObject,aMode)){
81 AddPresentation(aPresentableObject,aMode);
82 }
83 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
84 Update(aPresentableObject,aMode);
85 }
86 Presentation(aPresentableObject,aMode)->Highlight();
87
88 if(myImmediateMode)
89 Add(aPresentableObject,aMode);
90}
91
92void PrsMgr_PresentationManager::Unhighlight(
93 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
94 const Standard_Integer aMode)
95{
96 if (HasPresentation(aPresentableObject,aMode)){
97 Presentation(aPresentableObject,aMode)->Unhighlight();
98 if(myImmediateMode)
99 Remove(aPresentableObject,aMode);
100 }
101}
102
103
104void PrsMgr_PresentationManager::
105SetDisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
106 const Standard_Integer aMode,
107 const Standard_Integer theNewPrior) const
108{
109 if (HasPresentation(aPresentableObject,aMode))
110 Presentation(aPresentableObject,aMode)->SetDisplayPriority(theNewPrior);
111}
112
113Standard_Integer PrsMgr_PresentationManager::
114DisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
115 const Standard_Integer aMode) const
116{
117 if (HasPresentation(aPresentableObject,aMode))
118 return Presentation(aPresentableObject,aMode)->DisplayPriority();
119
120 return 0;
121}
122
123
124Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (
125 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
126 const Standard_Integer aMode) const {
127 if (HasPresentation(aPresentableObject,aMode))
128 return Presentation(aPresentableObject,aMode)->IsDisplayed();
129 return Standard_False;
130 }
131
132Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (
133 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
134 const Standard_Integer aMode) const {
135 if (HasPresentation(aPresentableObject,aMode))
136 return Presentation(aPresentableObject,aMode)->IsHighlighted();
137 return Standard_False;
138 }
139
140void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Standard_Integer aMode ) const {
141 if(HasPresentation(aPresentableObject,aMode)) {
142 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
143 if (!P.IsNull()) {
144 P->Clear();
145 aPresentableObject->Fill(this,P,aMode);
146 P->SetUpdateStatus(Standard_False);
147 }
148 }
149}
150void PrsMgr_PresentationManager::BeginDraw() {
151 myImmediateMode = Standard_True;
152 myImmediateList.Clear();
153}
154
155
156void PrsMgr_PresentationManager::Add(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
157 const Standard_Integer aMode) {
158 if (myImmediateMode ) {
159 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
160 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
161 if(it.Value()==P) return;
162 }
163 myImmediateList.Append(P);
164 }
165}
166void PrsMgr_PresentationManager::Remove(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
167 const Standard_Integer aMode) {
168 if (myImmediateMode ) {
169 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
170 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
171 if(it.Value()==P) {
172 myImmediateList.Remove(it);
173 return;
174 }
175 }
176 }
177}
178
179
180
181
182Standard_Boolean PrsMgr_PresentationManager::HasPresentation
183 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
184 const Standard_Integer aMode) const {
185
186 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
187 Standard_Boolean found = Standard_False;
188 Standard_Integer i=1; Standard_Integer l= S.Length();
189 while (i<= l && !found) {
190// modif WOK++ : operator == is ambiguous
191// found = aMode == S(i).Mode()
192// && this == S(i).Presentation()->PresentationManager();
193 const Handle (PrsMgr_Presentation)& popPrs = S(i).Presentation();
194 const Handle (PrsMgr_PresentationManager)& popPrsMgr = popPrs->PresentationManager();
195 if ( aMode == S(i).Mode() && this == popPrsMgr )
196 found = Standard_True;
197 i++;
198 }
199 return found;
200 }
201
202Handle (PrsMgr_Presentation)
203 PrsMgr_PresentationManager::Presentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
204 const Standard_Integer aMode) const
205{
206 Handle(PrsMgr_Presentation) P;
207 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
208 Standard_Boolean found = Standard_False;
209 Standard_Integer i=1; Standard_Integer l= S.Length();
210 while (i<= l && !found) {
211 P = S(i).Presentation();
212 const Handle (PrsMgr_PresentationManager)& popPrsMgr = P->PresentationManager();
213 if (aMode == S(i).Mode() && this == popPrsMgr) {
214 found = Standard_True;
215
216
217 }
218 i++;
219 }
220
221 return P;
222}
223
224void PrsMgr_PresentationManager::AddPresentation
225 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
226 const Standard_Integer aMode) {
227
228 Handle(PrsMgr_Presentation) P = newPresentation(aPresentableObject);
229 aPresentableObject->Presentations().Append(PrsMgr_ModedPresentation(P,aMode));
230 aPresentableObject->Fill(this,P,aMode);
59f45b7c 231
232 // set layer index accordingly to object's presentations
233 Standard_Integer aZLayerId = GetZLayer (aPresentableObject);
234 if (aZLayerId >= 0)
235 P->SetZLayer (aZLayerId);
236
7fd59977 237 P->SetUpdateStatus(Standard_False);
238}
239
240void PrsMgr_PresentationManager::RemovePresentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
241 const Standard_Integer aMode)
242{
243 PrsMgr_Presentations& S = aPresentableObject->Presentations();
244 Standard_Integer i = 1;
245 Standard_Integer n = S.Length();
246 while (i<= n) {
247 if (aMode == S(i).Mode()) {
248 S.Remove(i);
249 break;
250 }
251 i++;
252 }
253}
254
59f45b7c 255//=======================================================================
256//function : SetZLayer
257//purpose :
258//=======================================================================
259
260void PrsMgr_PresentationManager::SetZLayer
261 (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
262 const Standard_Integer theLayerId)
263{
264 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
265 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
266 {
267 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
268 if (aPrs->PresentationManager () == this)
269 aPrs->SetZLayer (theLayerId);
270 }
271}
272
273//=======================================================================
274//function : GetZLayer
275//purpose :
276//=======================================================================
277
278Standard_Integer PrsMgr_PresentationManager::GetZLayer
279 (const Handle(PrsMgr_PresentableObject)& thePresentableObject) const
280{
281 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
282 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
283 {
284 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
285 if (aPrs->PresentationManager () == this)
286 return aPrs->GetZLayer ();
287 }
288
289 return -1;
290}