b311480e |
1 | // Created by: NW,JPB,CAL |
2 | // Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | //-Version |
81bba717 |
17 | //-Design Declaration of variables specific to managers |
81bba717 |
18 | //-Warning Manager manages a set of structures |
7fd59977 |
19 | //-References |
7fd59977 |
20 | //-Language C++ 2.0 |
7fd59977 |
21 | //-Declarations |
7fd59977 |
22 | // for the class |
42cf5bc1 |
23 | |
24 | #include <Graphic3d_AspectFillArea3d.hxx> |
25 | #include <Graphic3d_AspectLine3d.hxx> |
26 | #include <Graphic3d_AspectMarker3d.hxx> |
27 | #include <Graphic3d_AspectText3d.hxx> |
28 | #include <Graphic3d_DataStructureManager.hxx> |
29 | #include <Graphic3d_GraphicDriver.hxx> |
30 | #include <Graphic3d_InitialisationError.hxx> |
31 | #include <Graphic3d_Structure.hxx> |
32 | #include <Graphic3d_StructureManager.hxx> |
42cf5bc1 |
33 | #include <Standard_Transient.hxx> |
34 | #include <Standard_Type.hxx> |
35 | |
92efcf78 |
36 | IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_StructureManager,MMgt_TShared) |
37 | |
7fd59977 |
38 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
92efcf78 |
39 | #include <Graphic3d_CView.hxx> |
7fd59977 |
40 | |
a1954302 |
41 | Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver) |
c357e426 |
42 | : myViewGenId (0, 31) |
a1954302 |
43 | { |
016e5959 |
44 | myAspectLine3d = new Graphic3d_AspectLine3d (); |
45 | myAspectText3d = new Graphic3d_AspectText3d (); |
46 | myAspectMarker3d = new Graphic3d_AspectMarker3d (); |
47 | myAspectFillArea3d = new Graphic3d_AspectFillArea3d (); |
7fd59977 |
48 | |
016e5959 |
49 | myUpdateMode = Aspect_TOU_WAIT; |
50 | myGraphicDriver = theDriver; |
7fd59977 |
51 | |
52 | } |
53 | |
54 | //-Destructors |
55 | |
e6f550da |
56 | Graphic3d_StructureManager::~Graphic3d_StructureManager () |
57 | { |
016e5959 |
58 | myDisplayedStructure.Clear (); |
59 | myHighlightedStructure.Clear (); |
60 | myDefinedViews.Clear(); |
7fd59977 |
61 | |
62 | } |
63 | |
c357e426 |
64 | // ======================================================================== |
65 | // function : SetUpdateMode |
66 | // purpose : |
67 | // ======================================================================== |
68 | void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate theType) |
69 | { |
70 | myUpdateMode = theType; |
71 | } |
7fd59977 |
72 | |
c357e426 |
73 | // ======================================================================== |
74 | // function : UpdateMode |
75 | // purpose : |
76 | // ======================================================================== |
77 | Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode() const |
78 | { |
79 | return myUpdateMode; |
80 | } |
7fd59977 |
81 | |
c357e426 |
82 | // ======================================================================== |
83 | // function : Update |
84 | // purpose : |
85 | // ======================================================================== |
86 | void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode) const |
87 | { |
88 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
89 | { |
90 | aViewIt.Value()->Update (theMode); |
91 | } |
7fd59977 |
92 | } |
93 | |
c357e426 |
94 | // ======================================================================== |
95 | // function : Remove |
96 | // purpose : |
97 | // ======================================================================== |
98 | void Graphic3d_StructureManager::Remove() |
99 | { |
100 | // clear all structures whilst views are alive for correct GPU memory management |
101 | myDisplayedStructure.Clear(); |
102 | myHighlightedStructure.Clear(); |
7fd59977 |
103 | |
c357e426 |
104 | // clear list of managed views |
105 | myDefinedViews.Clear(); |
106 | } |
7fd59977 |
107 | |
c357e426 |
108 | // ======================================================================== |
109 | // function : Erase |
110 | // purpose : |
111 | // ======================================================================== |
112 | void Graphic3d_StructureManager::Erase() |
113 | { |
114 | for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next()) |
115 | { |
116 | anIt.Key()->Erase(); |
117 | } |
7fd59977 |
118 | } |
119 | |
c357e426 |
120 | |
121 | |
122 | |
123 | |
7fd59977 |
124 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) { |
125 | |
c357e426 |
126 | myAspectLine3d = CTX; |
7fd59977 |
127 | |
128 | } |
129 | |
130 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) { |
131 | |
c357e426 |
132 | myAspectFillArea3d = CTX; |
7fd59977 |
133 | |
134 | } |
135 | |
136 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) { |
137 | |
c357e426 |
138 | myAspectText3d = CTX; |
7fd59977 |
139 | |
140 | } |
141 | |
142 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) { |
143 | |
c357e426 |
144 | myAspectMarker3d = CTX; |
7fd59977 |
145 | |
146 | } |
147 | |
148 | void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const { |
149 | |
c357e426 |
150 | CTXL = myAspectLine3d; |
151 | CTXT = myAspectText3d; |
152 | CTXM = myAspectMarker3d; |
153 | CTXF = myAspectFillArea3d; |
7fd59977 |
154 | |
155 | } |
156 | |
157 | Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const { |
158 | |
c357e426 |
159 | return (myAspectLine3d); |
7fd59977 |
160 | |
161 | } |
162 | |
163 | Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const { |
164 | |
c357e426 |
165 | return (myAspectText3d); |
7fd59977 |
166 | |
167 | } |
168 | |
169 | Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const { |
170 | |
c357e426 |
171 | return (myAspectMarker3d); |
7fd59977 |
172 | |
173 | } |
174 | |
175 | Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const { |
176 | |
c357e426 |
177 | return (myAspectFillArea3d); |
7fd59977 |
178 | |
179 | } |
180 | |
7fd59977 |
181 | void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const { |
182 | |
c357e426 |
183 | SG.Assign(myDisplayedStructure); |
7fd59977 |
184 | |
c357e426 |
185 | //JMBStandard_Integer Length = myDisplayedStructure.Length (); |
7fd59977 |
186 | |
187 | //JMBfor (Standard_Integer i=1; i<=Length; i++) |
c357e426 |
188 | //JMB SG.Add (myDisplayedStructure.Value (i)); |
7fd59977 |
189 | |
190 | } |
191 | |
192 | Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const { |
193 | |
c357e426 |
194 | Standard_Integer Length = myDisplayedStructure.Extent (); |
7fd59977 |
195 | |
196 | return (Length); |
197 | |
198 | } |
199 | |
200 | //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const { |
201 | |
c357e426 |
202 | //return (myDisplayedStructure.Value (AnIndex)); |
7fd59977 |
203 | |
204 | //} |
205 | |
206 | void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const { |
207 | |
c357e426 |
208 | SG.Assign(myHighlightedStructure); |
7fd59977 |
209 | |
210 | } |
211 | |
7fd59977 |
212 | Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const { |
213 | |
214 | // Standard_Integer ind=0; |
215 | Standard_Boolean notfound = Standard_True; |
216 | |
217 | Handle(Graphic3d_Structure) StructNull; |
218 | |
c357e426 |
219 | Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure); |
7fd59977 |
220 | |
221 | Handle(Graphic3d_Structure) SGfound; |
222 | |
223 | for (; it.More() && notfound; it.Next()) { |
224 | Handle(Graphic3d_Structure) SG = it.Key(); |
225 | if ( SG->Identification () == AId) { |
226 | notfound = Standard_False; |
227 | SGfound = SG; |
228 | } |
229 | } |
230 | |
231 | |
232 | if (notfound) |
233 | return (StructNull); |
234 | else |
235 | return (SGfound); |
236 | |
237 | } |
238 | |
016e5959 |
239 | const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const |
240 | { |
241 | return (myGraphicDriver); |
7fd59977 |
242 | } |
eb4320f2 |
243 | |
8bb96a97 |
244 | void Graphic3d_StructureManager::RecomputeStructures() |
eb4320f2 |
245 | { |
8bb96a97 |
246 | // Go through all unique structures including child (connected) ones and ensure that they are computed. |
247 | Graphic3d_MapOfStructure aStructNetwork; |
248 | |
c357e426 |
249 | for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next()) |
eb4320f2 |
250 | { |
251 | Handle(Graphic3d_Structure) aStructure = anIter.Key(); |
8bb96a97 |
252 | anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork); |
253 | } |
254 | |
255 | RecomputeStructures (aStructNetwork); |
256 | } |
eb4320f2 |
257 | |
8bb96a97 |
258 | void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures) |
259 | { |
260 | for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next()) |
261 | { |
262 | Handle(Graphic3d_Structure) aStruct = anIter.Key(); |
263 | aStruct->Clear(); |
264 | aStruct->Compute(); |
eb4320f2 |
265 | } |
266 | } |
a272ed94 |
267 | |
268 | Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject) |
269 | { |
270 | Handle(Graphic3d_ViewAffinity) aResult; |
271 | if (myRegisteredObjects.Find (theObject.operator->(), aResult)) |
272 | { |
273 | return aResult; |
274 | } |
275 | |
276 | aResult = new Graphic3d_ViewAffinity(); |
277 | myRegisteredObjects.Bind (theObject.operator->(), aResult); |
278 | return aResult; |
279 | } |
280 | |
281 | void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject) |
282 | { |
283 | myRegisteredObjects.UnBind (theObject.operator->()); |
284 | } |
285 | |
286 | Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const |
287 | { |
288 | Handle(Graphic3d_ViewAffinity) aResult; |
289 | myRegisteredObjects.Find (theObject.operator->(), aResult); |
290 | return aResult; |
291 | } |
c357e426 |
292 | |
293 | // ======================================================================== |
294 | // function : Identification |
295 | // purpose : |
296 | // ======================================================================== |
297 | Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView) |
298 | { |
299 | if (myDefinedViews.Contains (theView)) |
300 | { |
301 | return theView->Identification(); |
302 | } |
303 | |
304 | myDefinedViews.Add (theView); |
305 | return myViewGenId.Next(); |
306 | } |
307 | |
308 | // ======================================================================== |
309 | // function : UnIdentification |
310 | // purpose : |
311 | // ======================================================================== |
312 | void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView) |
313 | { |
314 | if (myDefinedViews.Contains (theView)) |
315 | { |
316 | myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size()); |
317 | myDefinedViews.RemoveLast(); |
318 | myViewGenId.Free (theView->Identification()); |
319 | } |
320 | } |
321 | |
322 | // ======================================================================== |
323 | // function : DefinedViews |
324 | // purpose : |
325 | // ======================================================================== |
326 | const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const |
327 | { |
328 | return myDefinedViews; |
329 | } |
330 | |
331 | // ======================================================================== |
332 | // function : MaxNumOfViews |
333 | // purpose : |
334 | // ======================================================================== |
335 | Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const |
336 | { |
337 | return myViewGenId.Upper() - myViewGenId.Lower() + 1; |
338 | } |
339 | |
340 | // ======================================================================== |
341 | // function : ReCompute |
342 | // purpose : |
343 | // ======================================================================== |
344 | void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure) |
345 | { |
346 | if (!myDisplayedStructure.Contains (theStructure)) |
347 | { |
348 | return; |
349 | } |
350 | |
351 | // Recompute structure for all defined views |
352 | for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt) |
353 | { |
354 | ReCompute (theStructure, myDefinedViews (aViewIt)); |
355 | } |
356 | } |
357 | |
358 | // ======================================================================== |
359 | // function : ReCompute |
360 | // purpose : |
361 | // ======================================================================== |
362 | void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure, |
363 | const Handle(Graphic3d_DataStructureManager)& theProjector) |
364 | { |
365 | Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector); |
366 | |
367 | if (aView.IsNull() |
368 | || !myDefinedViews.Contains (aView.operator->()) |
369 | || !myDisplayedStructure.Contains (theStructure)) |
370 | { |
371 | return; |
372 | } |
373 | |
374 | aView->ReCompute (theStructure); |
375 | } |
376 | |
377 | // ======================================================================== |
378 | // function : Clear |
379 | // purpose : |
380 | // ======================================================================== |
381 | void Graphic3d_StructureManager::Clear (const Handle(Graphic3d_Structure)& theStructure, |
382 | const Standard_Boolean theWithDestruction) |
383 | { |
384 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
385 | { |
386 | aViewIt.Value()->Clear (theStructure, theWithDestruction); |
387 | } |
388 | } |
389 | |
390 | // ======================================================================== |
391 | // function : Connect |
392 | // purpose : |
393 | // ======================================================================== |
394 | void Graphic3d_StructureManager::Connect (const Handle(Graphic3d_Structure)& theMother, |
395 | const Handle(Graphic3d_Structure)& theDaughter) |
396 | { |
397 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
398 | { |
399 | aViewIt.Value()->Connect (theMother, theDaughter); |
400 | } |
401 | } |
402 | |
403 | // ======================================================================== |
404 | // function : Disconnect |
405 | // purpose : |
406 | // ======================================================================== |
407 | void Graphic3d_StructureManager::Disconnect (const Handle(Graphic3d_Structure)& theMother, |
408 | const Handle(Graphic3d_Structure)& theDaughter) |
409 | { |
410 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
411 | { |
412 | aViewIt.Value()->Disconnect (theMother, theDaughter); |
413 | } |
414 | } |
415 | |
416 | // ======================================================================== |
417 | // function : Display |
418 | // purpose : |
419 | // ======================================================================== |
420 | void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure) |
421 | { |
422 | myDisplayedStructure.Add (theStructure); |
423 | |
424 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
425 | { |
426 | aViewIt.Value()->Display (theStructure); |
427 | } |
428 | } |
429 | |
430 | // ======================================================================== |
431 | // function : Erase |
432 | // purpose : |
433 | // ======================================================================== |
434 | void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure) |
435 | { |
436 | myDisplayedStructure .Remove(theStructure); |
437 | myHighlightedStructure.Remove (theStructure); |
438 | |
439 | // Erase structure in all defined views |
440 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
441 | { |
442 | aViewIt.Value()->Erase (theStructure); |
443 | } |
444 | } |
445 | |
446 | // ======================================================================== |
447 | // function : Erase |
448 | // purpose : |
449 | // ======================================================================== |
450 | void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure, |
451 | const Aspect_TypeOfHighlightMethod theMethod) |
452 | { |
453 | myHighlightedStructure.Add (theStructure); |
454 | |
455 | // Highlight in all defined views |
456 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
457 | { |
458 | aViewIt.Value()->Highlight (theStructure, theMethod); |
459 | } |
460 | } |
461 | |
462 | // ======================================================================== |
463 | // function : UnHighlight |
464 | // purpose : |
465 | // ======================================================================== |
466 | void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure) |
467 | { |
468 | myHighlightedStructure.Remove (theStructure); |
469 | |
470 | // UnHighlight in all defined views |
471 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
472 | { |
473 | aViewIt.Value()->UnHighlight (theStructure); |
474 | } |
475 | } |
476 | |
477 | // ======================================================================== |
478 | // function : UnHighlight |
479 | // purpose : |
480 | // ======================================================================== |
481 | void Graphic3d_StructureManager::UnHighlight() |
482 | { |
483 | for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next()) |
484 | { |
485 | anIt.Key()->UnHighlight(); |
486 | } |
487 | } |
488 | |
489 | // ======================================================================== |
490 | // function : SetTransform |
491 | // purpose : |
492 | // ======================================================================== |
493 | void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure, |
494 | const TColStd_Array2OfReal& theTrsf) |
495 | { |
496 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
497 | { |
498 | aViewIt.Value()->SetTransform (theStructure, theTrsf); |
499 | } |
500 | } |
501 | |
502 | // ======================================================================== |
503 | // function : ChangeDisplayPriority |
504 | // purpose : |
505 | // ======================================================================== |
506 | void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure, |
507 | const Standard_Integer theOldPriority, |
508 | const Standard_Integer theNewPriority) |
509 | { |
510 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
511 | { |
512 | aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority); |
513 | } |
514 | } |
515 | |
516 | //======================================================================= |
517 | //function : ChangeZLayer |
518 | //purpose : |
519 | //======================================================================= |
520 | void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, |
521 | const Graphic3d_ZLayerId theLayerId) |
522 | { |
523 | if (!myDisplayedStructure.Contains (theStructure)) |
524 | { |
525 | return; |
526 | } |
527 | |
528 | for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) |
529 | { |
530 | aViewIt.Value()->ChangeZLayer (theStructure, theLayerId); |
531 | } |
532 | } |