b311480e |
1 | // Created on: 1997-12-16 |
2 | // Created by: Jean Louis Frenkel |
3 | // Copyright (c) 1997-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | // Modified by Rob |
22 | // 16-dec-1997 : Update Flag for Presentations. |
7fd59977 |
23 | |
24 | |
25 | #include <PrsMgr_PresentableObject.ixx> |
26 | #include <PrsMgr_Presentation.hxx> |
7fd59977 |
27 | #include <PrsMgr_Presentation3d.hxx> |
28 | #include <PrsMgr_ModedPresentation.hxx> |
29 | #include <PrsMgr_PresentationManager.hxx> |
30 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
31 | #include <TColStd_MapOfInteger.hxx> |
32 | #include <Graphic3d_TypeOfStructure.hxx> |
33 | #include <Geom_Transformation.hxx> |
34 | |
35 | //======================================================================= |
36 | //function : PrsMgr_PresentableObject |
37 | //purpose : |
38 | //======================================================================= |
39 | |
40 | PrsMgr_PresentableObject::PrsMgr_PresentableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d) |
41 | :myPresentations(),myTypeOfPresentation3d(aTypeOfPresentation3d) |
42 | { |
43 | myTransformPersistence.Flag = 0; |
44 | myTransformPersistence.Point.x = 0.0; |
45 | myTransformPersistence.Point.y = 0.0; |
46 | myTransformPersistence.Point.z = 0.0; |
47 | } |
48 | |
49 | |
50 | //======================================================================= |
51 | //function : Fill |
52 | //purpose : |
53 | //======================================================================= |
54 | void PrsMgr_PresentableObject::Fill(const Handle(PrsMgr_PresentationManager)& aPresentationManager, |
55 | const Handle(PrsMgr_Presentation)& aPresentation, |
56 | const Standard_Integer aMode) { |
128cc8df |
57 | if (aPresentation->DynamicType() == STANDARD_TYPE(PrsMgr_Presentation3d)) { |
7fd59977 |
58 | Compute(((Handle(PrsMgr_PresentationManager3d)&)aPresentationManager),((Handle(PrsMgr_Presentation3d)&)aPresentation)->Presentation(),aMode); |
59 | UpdateLocation(((Handle(PrsMgr_Presentation3d)&)aPresentation)->Presentation()); |
60 | Handle(Graphic3d_Structure) aStruct = Handle(Graphic3d_Structure)::DownCast( ((Handle(PrsMgr_Presentation3d)&)aPresentation)->Presentation() ); |
61 | if ( !aStruct.IsNull() ) { |
62 | aStruct->SetTransformPersistence( GetTransformPersistenceMode(), GetTransformPersistencePoint() ); |
63 | } |
64 | } |
65 | } |
66 | |
128cc8df |
67 | |
7fd59977 |
68 | //======================================================================= |
69 | //function : Compute |
70 | //purpose : |
71 | //======================================================================= |
72 | void PrsMgr_PresentableObject::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
73 | const Handle(Prs3d_Presentation)& /*aPresentation*/, |
74 | const Standard_Integer /*aMode*/) |
75 | { |
76 | Standard_NotImplemented::Raise("cannot compute in a 3d visualizer"); |
77 | } |
78 | //======================================================================= |
79 | //function : Compute |
80 | //purpose : |
81 | //======================================================================= |
82 | void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /*aProjector*/, |
83 | const Handle(Prs3d_Presentation)& /*aPresentation*/) |
84 | { |
85 | Standard_NotImplemented::Raise("cannot compute under a specific projector"); |
86 | } |
87 | //======================================================================= |
88 | //function : Compute |
89 | //purpose : |
90 | //======================================================================= |
91 | void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /* aProjector*/, |
92 | const Handle(Geom_Transformation)& /*aTrsf*/, |
93 | const Handle(Prs3d_Presentation)& /*aPresentation*/) |
94 | { |
95 | Standard_NotImplemented::Raise("cannot compute under a specific projector"); |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : Update |
100 | //purpose : |
101 | //======================================================================= |
102 | void PrsMgr_PresentableObject::Update (const Standard_Boolean AllModes) { |
103 | Standard_Integer l = myPresentations.Length(); |
104 | Handle(PrsMgr_PresentationManager) PM; |
105 | for (Standard_Integer i=1; i <= l; i++) { |
106 | PM = myPresentations(i).Presentation()->PresentationManager(); |
107 | if(AllModes) |
108 | PM->Update(this,myPresentations(i).Mode()); |
109 | else{ |
110 | if(PM->IsDisplayed(this,myPresentations(i).Mode()) || |
111 | PM->IsHighlighted(this,myPresentations(i).Mode())){ |
112 | PM->Update(this,myPresentations(i).Mode()); |
113 | } |
114 | else |
115 | SetToUpdate(myPresentations(i).Mode()); |
116 | } |
117 | } |
118 | } |
119 | //======================================================================= |
120 | //function : Update |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | void PrsMgr_PresentableObject::Update (const Standard_Integer aMode, const Standard_Boolean ClearOther) { |
125 | Standard_Integer l = myPresentations.Length(); |
126 | for (Standard_Integer i=1; i <= l; i++) { |
127 | if( myPresentations(i).Mode() == aMode){ |
128 | Handle(PrsMgr_PresentationManager) PM= |
129 | myPresentations(i).Presentation()->PresentationManager(); |
130 | |
131 | if(PM->IsDisplayed(this,aMode) || |
132 | PM->IsHighlighted(this,aMode)){ |
133 | PM->Update(this,aMode); |
134 | myPresentations(i).Presentation()->SetUpdateStatus(Standard_False); |
135 | |
136 | } |
137 | else |
138 | SetToUpdate(myPresentations(i).Mode()); |
139 | } |
140 | |
141 | } |
142 | if(ClearOther) { |
143 | PrsMgr_Presentations save; |
144 | save = myPresentations; |
145 | myPresentations.Clear(); |
146 | for (Standard_Integer i=1; i <= l; i++) { |
147 | if( save(i).Mode() == aMode) myPresentations.Append(save(i)); |
148 | } |
149 | } |
150 | |
151 | } |
152 | //======================================================================= |
153 | //function : Presentations |
154 | //purpose : |
155 | //======================================================================= |
156 | |
157 | PrsMgr_Presentations& PrsMgr_PresentableObject::Presentations() { |
158 | return myPresentations; |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : HasLocation |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | Standard_Boolean PrsMgr_PresentableObject::HasLocation() const |
167 | { |
168 | return !Location().IsIdentity();} |
169 | |
170 | |
171 | |
172 | //======================================================================= |
173 | //function : SetToUpdate |
174 | //purpose : |
175 | //======================================================================= |
176 | |
177 | void PrsMgr_PresentableObject::SetToUpdate(const Standard_Integer aMode) |
178 | { |
179 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
180 | if(myPresentations(IP).Mode()==aMode) |
181 | myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True); |
182 | } |
183 | } |
184 | void PrsMgr_PresentableObject::SetToUpdate() |
185 | { |
186 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
187 | myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True); |
188 | } |
189 | } |
190 | |
191 | //======================================================================= |
192 | //function : ToBeUpdated |
193 | //purpose : gets the list of modes to be updated |
194 | //======================================================================= |
195 | void PrsMgr_PresentableObject::ToBeUpdated(TColStd_ListOfInteger& OutList) const |
196 | { |
197 | OutList.Clear(); |
198 | // on dimensionne les buckets a la taille de la seq. |
199 | static TColStd_MapOfInteger MI(myPresentations.Length()); |
200 | |
201 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
202 | const PrsMgr_ModedPresentation& MP = myPresentations(IP); |
203 | if(MP.Presentation()->MustBeUpdated()) |
204 | if(!MI.Contains(MP.Mode())){ |
205 | OutList.Append(MP.Mode()); |
206 | MI.Add(MP.Mode()); |
207 | } |
208 | } |
209 | MI.Clear(); |
210 | } |
211 | |
212 | //======================================================================= |
213 | //function : SetTypeOfPresentation |
214 | //purpose : |
215 | //======================================================================= |
216 | |
217 | void PrsMgr_PresentableObject::SetTypeOfPresentation(const PrsMgr_TypeOfPresentation3d aType) |
218 | { |
219 | myTypeOfPresentation3d = aType; |
220 | |
221 | for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){ |
222 | const Handle(PrsMgr_Presentation)& P = myPresentations(IP).Presentation(); |
223 | if(P->KindOfPresentation()==PrsMgr_KOP_3D){ |
224 | Graphic3d_TypeOfStructure Typ = |
225 | (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant)? |
226 | Graphic3d_TOS_COMPUTED : Graphic3d_TOS_ALL; |
227 | (*(Handle(PrsMgr_Presentation3d)*)&P)->Presentation()->SetVisual(Typ); |
228 | } |
229 | } |
230 | } |
231 | |
232 | //======================================================================= |
233 | //function : SetLocation |
234 | //purpose : WARNING : use with only 3D objects... |
235 | //======================================================================= |
236 | void PrsMgr_PresentableObject::SetLocation(const TopLoc_Location& aLoc) |
237 | { |
238 | if(aLoc.IsIdentity()) return; |
239 | myLocation = aLoc; |
240 | UpdateLocation(); |
241 | } |
242 | |
243 | //======================================================================= |
244 | //function : ReSetLocation |
245 | //purpose : |
246 | //======================================================================= |
247 | void PrsMgr_PresentableObject::ResetLocation() |
248 | { |
249 | TopLoc_Location aLoc; |
250 | Handle(Geom_Transformation) G = new Geom_Transformation(aLoc.Transformation()); |
251 | |
252 | for(Standard_Integer i=1;i<=myPresentations.Length();i++){ |
253 | const Handle(PrsMgr_Presentation)& P = myPresentations(i).Presentation(); |
254 | if(P->KindOfPresentation()==PrsMgr_KOP_3D){ |
255 | (*((Handle(PrsMgr_Presentation3d)*)&P))->Transform(G); |
256 | } |
257 | } |
258 | myLocation = aLoc; |
259 | } |
260 | |
261 | void PrsMgr_PresentableObject::UpdateLocation() |
262 | { |
263 | if(!HasLocation()) return; |
264 | Handle(Geom_Transformation) G = new Geom_Transformation(Location().Transformation()); |
265 | if(G->Trsf().Form()==gp_Identity) return; |
266 | for (Standard_Integer i=1;i<=myPresentations.Length();i++){ |
267 | const Handle(PrsMgr_Presentation)& P = myPresentations(i).Presentation(); |
268 | if(P->KindOfPresentation()==PrsMgr_KOP_3D){ |
269 | (*((Handle(PrsMgr_Presentation3d)*)&P))->Transform(G); |
270 | } |
271 | } |
272 | } |
273 | |
274 | |
275 | //======================================================================= |
276 | //function : UpdateLocation |
277 | //purpose : |
278 | //======================================================================= |
279 | |
280 | void PrsMgr_PresentableObject::UpdateLocation(const Handle(Prs3d_Presentation)& P) |
281 | { |
282 | if(myLocation.IsIdentity()) return; |
283 | Handle(Geom_Transformation) G = new Geom_Transformation(Location().Transformation()); |
284 | P->Transform(G); |
285 | |
286 | } |
287 | |
288 | //======================================================================= |
289 | //function : SetTransformPersistence |
290 | //purpose : |
291 | //======================================================================= |
292 | void PrsMgr_PresentableObject::SetTransformPersistence( const Graphic3d_TransModeFlags& TheFlag, |
293 | const gp_Pnt& ThePoint ) |
294 | { |
295 | myTransformPersistence.Flag = TheFlag; |
296 | myTransformPersistence.Point.x = ThePoint.X(); |
297 | myTransformPersistence.Point.y = ThePoint.Y(); |
298 | myTransformPersistence.Point.z = ThePoint.Z(); |
299 | |
300 | Handle(Graphic3d_Structure) aStruct; |
301 | for( Standard_Integer i = 1, n = myPresentations.Length(); i <= n; i++ ) |
302 | { |
303 | Handle(PrsMgr_Presentation3d) aPrs3d = |
304 | Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() ); |
305 | if ( !aPrs3d.IsNull() ) |
306 | { |
307 | aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() ); |
308 | if( !aStruct.IsNull() ) |
309 | aStruct->SetTransformPersistence( TheFlag, ThePoint ); |
310 | } |
311 | } |
312 | } |
313 | |
314 | //======================================================================= |
315 | //function : SetTransformPersistence |
316 | //purpose : |
317 | //======================================================================= |
318 | void PrsMgr_PresentableObject::SetTransformPersistence( |
319 | const Graphic3d_TransModeFlags& TheFlag ) |
320 | { |
321 | SetTransformPersistence( TheFlag, gp_Pnt(0,0,0) ); |
322 | } |
323 | |
324 | //======================================================================= |
325 | //function : GetTransformPersistence |
326 | //purpose : |
327 | //======================================================================= |
328 | Graphic3d_TransModeFlags PrsMgr_PresentableObject::GetTransformPersistenceMode() const |
329 | { |
330 | return myTransformPersistence.Flag; |
331 | } |
332 | |
333 | //======================================================================= |
334 | //function : GetTransformPersistence |
335 | //purpose : |
336 | //======================================================================= |
337 | gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const |
338 | { |
339 | return gp_Pnt( myTransformPersistence.Point.x, myTransformPersistence.Point.y, myTransformPersistence.Point.z ); |
340 | } |
59f45b7c |
341 | |
342 | //======================================================================= |
343 | //function : SetZLayer |
344 | //purpose : |
345 | //======================================================================= |
346 | void PrsMgr_PresentableObject::SetZLayer |
347 | (const Handle(PrsMgr_PresentationManager)& thePrsMgr, |
348 | const Standard_Integer theLayerId) |
349 | { |
350 | if (!thePrsMgr.IsNull()) |
351 | thePrsMgr->SetZLayer (this, theLayerId); |
352 | } |
353 | |
354 | //======================================================================= |
355 | //function : GetZLayer |
356 | //purpose : |
357 | //======================================================================= |
358 | Standard_Integer PrsMgr_PresentableObject::GetZLayer |
359 | (const Handle(PrsMgr_PresentationManager)& thePrsMgr) const |
360 | { |
361 | if (!thePrsMgr.IsNull()) |
362 | return thePrsMgr->GetZLayer (this); |
363 | |
364 | return -1; |
365 | } |