0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- manual
[occt.git] / src / Graphic3d / Graphic3d_StructureManager.cxx
CommitLineData
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>
19286d7c 33#include "Graphic3d_StructureManager.pxx"
42cf5bc1 34#include <Standard_Transient.hxx>
35#include <Standard_Type.hxx>
36
7fd59977 37static Standard_Boolean Initialisation = Standard_True;
38static int StructureManager_ArrayId[StructureManager_MAX];
39static Standard_Integer StructureManager_CurrentId = 0;
40
19286d7c 41#include "Graphic3d_Structure.pxx"
7fd59977 42#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
43
a1954302 44Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver)
c357e426 45: myViewGenId (0, 31)
a1954302 46{
7fd59977 47
48Standard_Real Coef;
49Standard_Integer i;
50Standard_Boolean NotFound = Standard_True;
51Standard_Integer Limit = Graphic3d_StructureManager::Limit ();
52
53 /* Initialize PHIGS and start up */
54 if (Initialisation) {
55
56 Initialisation = Standard_False;
81bba717 57 /* table to manage IDs of StructureManager */
f163f612 58 for (i=0; i<Limit; i++) StructureManager_ArrayId[i] = 0;
7fd59977 59
f163f612 60 StructureManager_CurrentId = 0;
61 StructureManager_ArrayId[0] = 1;
7fd59977 62
63 }
64 else {
f163f612 65 for (i=0; i<Limit && NotFound; i++)
7fd59977 66 if (StructureManager_ArrayId[i] == 0) {
67 NotFound = Standard_False;
68 StructureManager_CurrentId = i;
69 StructureManager_ArrayId[i] = 1;
70 }
71
72 if (NotFound)
f163f612 73 {
74 Standard_SStream anErrorDescription;
75 anErrorDescription<<"You are trying to create too many ViewManagers at the same time!\n"<<
76 "The number of simultaneously created ViewManagers can't exceed "<<Limit<<".\n";
77 Graphic3d_InitialisationError::Raise(anErrorDescription);
78 }
7fd59977 79 }
80
81 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
82 Aspect_GenId theGenId(
f163f612 83 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)),
84 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1));
c357e426 85 myStructGenId = theGenId;
7fd59977 86
c357e426 87 myId = StructureManager_CurrentId;
7fd59977 88
c357e426 89 myAspectLine3d = new Graphic3d_AspectLine3d ();
90 myAspectText3d = new Graphic3d_AspectText3d ();
91 myAspectMarker3d = new Graphic3d_AspectMarker3d ();
92 myAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
7fd59977 93
c357e426 94 myUpdateMode = Aspect_TOU_WAIT;
95 myGraphicDriver = theDriver;
7fd59977 96
97}
98
99//-Destructors
100
101void Graphic3d_StructureManager::Destroy () {
102
c357e426 103 myDisplayedStructure.Clear ();
104 myHighlightedStructure.Clear ();
105 myDefinedViews.Clear();
106 StructureManager_ArrayId[myId] = 0;
7fd59977 107
108}
109
c357e426 110// ========================================================================
111// function : SetUpdateMode
112// purpose :
113// ========================================================================
114void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate theType)
115{
116 myUpdateMode = theType;
117}
7fd59977 118
c357e426 119// ========================================================================
120// function : UpdateMode
121// purpose :
122// ========================================================================
123Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode() const
124{
125 return myUpdateMode;
126}
7fd59977 127
c357e426 128// ========================================================================
129// function : Update
130// purpose :
131// ========================================================================
132void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode) const
133{
134 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
135 {
136 aViewIt.Value()->Update (theMode);
137 }
7fd59977 138}
139
c357e426 140// ========================================================================
141// function : Remove
142// purpose :
143// ========================================================================
144void Graphic3d_StructureManager::Remove()
145{
146 // clear all structures whilst views are alive for correct GPU memory management
147 myDisplayedStructure.Clear();
148 myHighlightedStructure.Clear();
7fd59977 149
c357e426 150 // clear list of managed views
151 myDefinedViews.Clear();
152}
7fd59977 153
c357e426 154// ========================================================================
155// function : Erase
156// purpose :
157// ========================================================================
158void Graphic3d_StructureManager::Erase()
159{
160 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
161 {
162 anIt.Key()->Erase();
163 }
7fd59977 164}
165
c357e426 166
167
168
169
7fd59977 170void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
171
c357e426 172 myAspectLine3d = CTX;
7fd59977 173
174}
175
176void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
177
c357e426 178 myAspectFillArea3d = CTX;
7fd59977 179
180}
181
182void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
183
c357e426 184 myAspectText3d = CTX;
7fd59977 185
186}
187
188void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
189
c357e426 190 myAspectMarker3d = CTX;
7fd59977 191
192}
193
194void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
195
c357e426 196 CTXL = myAspectLine3d;
197 CTXT = myAspectText3d;
198 CTXM = myAspectMarker3d;
199 CTXF = myAspectFillArea3d;
7fd59977 200
201}
202
203Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
204
c357e426 205 return (myAspectLine3d);
7fd59977 206
207}
208
209Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
210
c357e426 211 return (myAspectText3d);
7fd59977 212
213}
214
215Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
216
c357e426 217 return (myAspectMarker3d);
7fd59977 218
219}
220
221Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
222
c357e426 223 return (myAspectFillArea3d);
7fd59977 224
225}
226
c357e426 227void Graphic3d_StructureManager::Remove (const Standard_Integer theId) {
7fd59977 228
c357e426 229 myStructGenId.Free (theId);
7fd59977 230
231}
232
7fd59977 233void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
234
c357e426 235 SG.Assign(myDisplayedStructure);
7fd59977 236
c357e426 237 //JMBStandard_Integer Length = myDisplayedStructure.Length ();
7fd59977 238
239 //JMBfor (Standard_Integer i=1; i<=Length; i++)
c357e426 240 //JMB SG.Add (myDisplayedStructure.Value (i));
7fd59977 241
242}
243
244Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
245
c357e426 246Standard_Integer Length = myDisplayedStructure.Extent ();
7fd59977 247
248 return (Length);
249
250}
251
252//Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
253
c357e426 254//return (myDisplayedStructure.Value (AnIndex));
7fd59977 255
256//}
257
258void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
259
c357e426 260 SG.Assign(myHighlightedStructure);
7fd59977 261
262}
263
7fd59977 264Standard_Integer Graphic3d_StructureManager::NewIdentification () {
265
c357e426 266Standard_Integer Id = myStructGenId.Next ();
7fd59977 267
7fd59977 268 return Id;
269
270}
271
272Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
273
274// Standard_Integer ind=0;
275 Standard_Boolean notfound = Standard_True;
276
277 Handle(Graphic3d_Structure) StructNull;
278
c357e426 279 Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure);
7fd59977 280
281 Handle(Graphic3d_Structure) SGfound;
282
283 for (; it.More() && notfound; it.Next()) {
284 Handle(Graphic3d_Structure) SG = it.Key();
285 if ( SG->Identification () == AId) {
286 notfound = Standard_False;
287 SGfound = SG;
288 }
289 }
290
291
292 if (notfound)
293 return (StructNull);
294 else
295 return (SGfound);
296
297}
298
299Standard_Integer Graphic3d_StructureManager::Identification () const {
300
c357e426 301 return (myId);
7fd59977 302
303}
304
305Standard_Integer Graphic3d_StructureManager::Limit () {
306
307 return (StructureManager_MAX);
308
309}
310
311Standard_Integer Graphic3d_StructureManager::CurrentId () {
312
313 return (StructureManager_CurrentId);
314
315}
316
dc3fe572 317const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const {
7fd59977 318
c357e426 319 return (myGraphicDriver);
7fd59977 320
321}
eb4320f2 322
8bb96a97 323void Graphic3d_StructureManager::RecomputeStructures()
eb4320f2 324{
8bb96a97 325 // Go through all unique structures including child (connected) ones and ensure that they are computed.
326 Graphic3d_MapOfStructure aStructNetwork;
327
c357e426 328 for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next())
eb4320f2 329 {
330 Handle(Graphic3d_Structure) aStructure = anIter.Key();
8bb96a97 331 anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
332 }
333
334 RecomputeStructures (aStructNetwork);
335}
eb4320f2 336
8bb96a97 337void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures)
338{
339 for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next())
340 {
341 Handle(Graphic3d_Structure) aStruct = anIter.Key();
342 aStruct->Clear();
343 aStruct->Compute();
eb4320f2 344 }
345}
a272ed94 346
347Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject)
348{
349 Handle(Graphic3d_ViewAffinity) aResult;
350 if (myRegisteredObjects.Find (theObject.operator->(), aResult))
351 {
352 return aResult;
353 }
354
355 aResult = new Graphic3d_ViewAffinity();
356 myRegisteredObjects.Bind (theObject.operator->(), aResult);
357 return aResult;
358}
359
360void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject)
361{
362 myRegisteredObjects.UnBind (theObject.operator->());
363}
364
365Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
366{
367 Handle(Graphic3d_ViewAffinity) aResult;
368 myRegisteredObjects.Find (theObject.operator->(), aResult);
369 return aResult;
370}
c357e426 371
372// ========================================================================
373// function : Identification
374// purpose :
375// ========================================================================
376Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView)
377{
378 if (myDefinedViews.Contains (theView))
379 {
380 return theView->Identification();
381 }
382
383 myDefinedViews.Add (theView);
384 return myViewGenId.Next();
385}
386
387// ========================================================================
388// function : UnIdentification
389// purpose :
390// ========================================================================
391void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView)
392{
393 if (myDefinedViews.Contains (theView))
394 {
395 myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size());
396 myDefinedViews.RemoveLast();
397 myViewGenId.Free (theView->Identification());
398 }
399}
400
401// ========================================================================
402// function : DefinedViews
403// purpose :
404// ========================================================================
405const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const
406{
407 return myDefinedViews;
408}
409
410// ========================================================================
411// function : MaxNumOfViews
412// purpose :
413// ========================================================================
414Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const
415{
416 return myViewGenId.Upper() - myViewGenId.Lower() + 1;
417}
418
419// ========================================================================
420// function : ReCompute
421// purpose :
422// ========================================================================
423void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure)
424{
425 if (!myDisplayedStructure.Contains (theStructure))
426 {
427 return;
428 }
429
430 // Recompute structure for all defined views
431 for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt)
432 {
433 ReCompute (theStructure, myDefinedViews (aViewIt));
434 }
435}
436
437// ========================================================================
438// function : ReCompute
439// purpose :
440// ========================================================================
441void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure,
442 const Handle(Graphic3d_DataStructureManager)& theProjector)
443{
444 Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector);
445
446 if (aView.IsNull()
447 || !myDefinedViews.Contains (aView.operator->())
448 || !myDisplayedStructure.Contains (theStructure))
449 {
450 return;
451 }
452
453 aView->ReCompute (theStructure);
454}
455
456// ========================================================================
457// function : Clear
458// purpose :
459// ========================================================================
460void Graphic3d_StructureManager::Clear (const Handle(Graphic3d_Structure)& theStructure,
461 const Standard_Boolean theWithDestruction)
462{
463 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
464 {
465 aViewIt.Value()->Clear (theStructure, theWithDestruction);
466 }
467}
468
469// ========================================================================
470// function : Connect
471// purpose :
472// ========================================================================
473void Graphic3d_StructureManager::Connect (const Handle(Graphic3d_Structure)& theMother,
474 const Handle(Graphic3d_Structure)& theDaughter)
475{
476 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
477 {
478 aViewIt.Value()->Connect (theMother, theDaughter);
479 }
480}
481
482// ========================================================================
483// function : Disconnect
484// purpose :
485// ========================================================================
486void Graphic3d_StructureManager::Disconnect (const Handle(Graphic3d_Structure)& theMother,
487 const Handle(Graphic3d_Structure)& theDaughter)
488{
489 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
490 {
491 aViewIt.Value()->Disconnect (theMother, theDaughter);
492 }
493}
494
495// ========================================================================
496// function : Display
497// purpose :
498// ========================================================================
499void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure)
500{
501 myDisplayedStructure.Add (theStructure);
502
503 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
504 {
505 aViewIt.Value()->Display (theStructure);
506 }
507}
508
509// ========================================================================
510// function : Erase
511// purpose :
512// ========================================================================
513void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure)
514{
515 myDisplayedStructure .Remove(theStructure);
516 myHighlightedStructure.Remove (theStructure);
517
518 // Erase structure in all defined views
519 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
520 {
521 aViewIt.Value()->Erase (theStructure);
522 }
523}
524
525// ========================================================================
526// function : Erase
527// purpose :
528// ========================================================================
529void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure,
530 const Aspect_TypeOfHighlightMethod theMethod)
531{
532 myHighlightedStructure.Add (theStructure);
533
534 // Highlight in all defined views
535 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
536 {
537 aViewIt.Value()->Highlight (theStructure, theMethod);
538 }
539}
540
541// ========================================================================
542// function : UnHighlight
543// purpose :
544// ========================================================================
545void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
546{
547 myHighlightedStructure.Remove (theStructure);
548
549 // UnHighlight in all defined views
550 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
551 {
552 aViewIt.Value()->UnHighlight (theStructure);
553 }
554}
555
556// ========================================================================
557// function : UnHighlight
558// purpose :
559// ========================================================================
560void Graphic3d_StructureManager::UnHighlight()
561{
562 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next())
563 {
564 anIt.Key()->UnHighlight();
565 }
566}
567
568// ========================================================================
569// function : SetTransform
570// purpose :
571// ========================================================================
572void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
573 const TColStd_Array2OfReal& theTrsf)
574{
575 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
576 {
577 aViewIt.Value()->SetTransform (theStructure, theTrsf);
578 }
579}
580
581// ========================================================================
582// function : ChangeDisplayPriority
583// purpose :
584// ========================================================================
585void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure,
586 const Standard_Integer theOldPriority,
587 const Standard_Integer theNewPriority)
588{
589 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
590 {
591 aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority);
592 }
593}
594
595//=======================================================================
596//function : ChangeZLayer
597//purpose :
598//=======================================================================
599void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
600 const Graphic3d_ZLayerId theLayerId)
601{
602 if (!myDisplayedStructure.Contains (theStructure))
603 {
604 return;
605 }
606
607 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
608 {
609 aViewIt.Value()->ChangeZLayer (theStructure, theLayerId);
610 }
611}