1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 //-Design Declaration of variables specific to managers
18 //-Warning Manager manages a set of structures
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>
33 #include "Graphic3d_StructureManager.pxx"
34 #include <Standard_Transient.hxx>
35 #include <Standard_Type.hxx>
37 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_StructureManager,MMgt_TShared)
39 static Standard_Boolean Initialisation = Standard_True;
40 static int StructureManager_ArrayId[StructureManager_MAX];
41 static Standard_Integer StructureManager_CurrentId = 0;
43 #include "Graphic3d_Structure.pxx"
44 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
45 #include <Graphic3d_CView.hxx>
47 Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver)
53 Standard_Boolean NotFound = Standard_True;
54 Standard_Integer Limit = Graphic3d_StructureManager::Limit ();
56 /* Initialize PHIGS and start up */
59 Initialisation = Standard_False;
60 /* table to manage IDs of StructureManager */
61 for (i=0; i<Limit; i++) StructureManager_ArrayId[i] = 0;
63 StructureManager_CurrentId = 0;
64 StructureManager_ArrayId[0] = 1;
68 for (i=0; i<Limit && NotFound; i++)
69 if (StructureManager_ArrayId[i] == 0) {
70 NotFound = Standard_False;
71 StructureManager_CurrentId = i;
72 StructureManager_ArrayId[i] = 1;
77 Standard_SStream anErrorDescription;
78 anErrorDescription<<"You are trying to create too many ViewManagers at the same time!\n"<<
79 "The number of simultaneously created ViewManagers can't exceed "<<Limit<<".\n";
80 Graphic3d_InitialisationError::Raise(anErrorDescription);
84 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
85 Aspect_GenId theGenId(
86 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)),
87 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1));
88 myStructGenId = theGenId;
90 myId = StructureManager_CurrentId;
92 myAspectLine3d = new Graphic3d_AspectLine3d ();
93 myAspectText3d = new Graphic3d_AspectText3d ();
94 myAspectMarker3d = new Graphic3d_AspectMarker3d ();
95 myAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
97 myUpdateMode = Aspect_TOU_WAIT;
98 myGraphicDriver = theDriver;
104 Graphic3d_StructureManager::~Graphic3d_StructureManager ()
106 myDisplayedStructure.Clear ();
107 myHighlightedStructure.Clear ();
108 myDefinedViews.Clear();
109 StructureManager_ArrayId[myId] = 0;
113 // ========================================================================
114 // function : SetUpdateMode
116 // ========================================================================
117 void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate theType)
119 myUpdateMode = theType;
122 // ========================================================================
123 // function : UpdateMode
125 // ========================================================================
126 Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode() const
131 // ========================================================================
134 // ========================================================================
135 void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode) const
137 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
139 aViewIt.Value()->Update (theMode);
143 // ========================================================================
146 // ========================================================================
147 void Graphic3d_StructureManager::Remove()
149 // clear all structures whilst views are alive for correct GPU memory management
150 myDisplayedStructure.Clear();
151 myHighlightedStructure.Clear();
153 // clear list of managed views
154 myDefinedViews.Clear();
157 // ========================================================================
160 // ========================================================================
161 void Graphic3d_StructureManager::Erase()
163 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
173 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
175 myAspectLine3d = CTX;
179 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
181 myAspectFillArea3d = CTX;
185 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
187 myAspectText3d = CTX;
191 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
193 myAspectMarker3d = CTX;
197 void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
199 CTXL = myAspectLine3d;
200 CTXT = myAspectText3d;
201 CTXM = myAspectMarker3d;
202 CTXF = myAspectFillArea3d;
206 Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
208 return (myAspectLine3d);
212 Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
214 return (myAspectText3d);
218 Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
220 return (myAspectMarker3d);
224 Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
226 return (myAspectFillArea3d);
230 void Graphic3d_StructureManager::Remove (const Standard_Integer theId) {
232 myStructGenId.Free (theId);
236 void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
238 SG.Assign(myDisplayedStructure);
240 //JMBStandard_Integer Length = myDisplayedStructure.Length ();
242 //JMBfor (Standard_Integer i=1; i<=Length; i++)
243 //JMB SG.Add (myDisplayedStructure.Value (i));
247 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
249 Standard_Integer Length = myDisplayedStructure.Extent ();
255 //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
257 //return (myDisplayedStructure.Value (AnIndex));
261 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
263 SG.Assign(myHighlightedStructure);
267 Standard_Integer Graphic3d_StructureManager::NewIdentification () {
269 Standard_Integer Id = myStructGenId.Next ();
275 Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
277 // Standard_Integer ind=0;
278 Standard_Boolean notfound = Standard_True;
280 Handle(Graphic3d_Structure) StructNull;
282 Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure);
284 Handle(Graphic3d_Structure) SGfound;
286 for (; it.More() && notfound; it.Next()) {
287 Handle(Graphic3d_Structure) SG = it.Key();
288 if ( SG->Identification () == AId) {
289 notfound = Standard_False;
302 Standard_Integer Graphic3d_StructureManager::Identification () const {
308 Standard_Integer Graphic3d_StructureManager::Limit () {
310 return (StructureManager_MAX);
314 Standard_Integer Graphic3d_StructureManager::CurrentId () {
316 return (StructureManager_CurrentId);
320 const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const {
322 return (myGraphicDriver);
326 void Graphic3d_StructureManager::RecomputeStructures()
328 // Go through all unique structures including child (connected) ones and ensure that they are computed.
329 Graphic3d_MapOfStructure aStructNetwork;
331 for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next())
333 Handle(Graphic3d_Structure) aStructure = anIter.Key();
334 anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
337 RecomputeStructures (aStructNetwork);
340 void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures)
342 for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next())
344 Handle(Graphic3d_Structure) aStruct = anIter.Key();
350 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject)
352 Handle(Graphic3d_ViewAffinity) aResult;
353 if (myRegisteredObjects.Find (theObject.operator->(), aResult))
358 aResult = new Graphic3d_ViewAffinity();
359 myRegisteredObjects.Bind (theObject.operator->(), aResult);
363 void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject)
365 myRegisteredObjects.UnBind (theObject.operator->());
368 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
370 Handle(Graphic3d_ViewAffinity) aResult;
371 myRegisteredObjects.Find (theObject.operator->(), aResult);
375 // ========================================================================
376 // function : Identification
378 // ========================================================================
379 Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView)
381 if (myDefinedViews.Contains (theView))
383 return theView->Identification();
386 myDefinedViews.Add (theView);
387 return myViewGenId.Next();
390 // ========================================================================
391 // function : UnIdentification
393 // ========================================================================
394 void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView)
396 if (myDefinedViews.Contains (theView))
398 myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size());
399 myDefinedViews.RemoveLast();
400 myViewGenId.Free (theView->Identification());
404 // ========================================================================
405 // function : DefinedViews
407 // ========================================================================
408 const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const
410 return myDefinedViews;
413 // ========================================================================
414 // function : MaxNumOfViews
416 // ========================================================================
417 Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const
419 return myViewGenId.Upper() - myViewGenId.Lower() + 1;
422 // ========================================================================
423 // function : ReCompute
425 // ========================================================================
426 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure)
428 if (!myDisplayedStructure.Contains (theStructure))
433 // Recompute structure for all defined views
434 for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt)
436 ReCompute (theStructure, myDefinedViews (aViewIt));
440 // ========================================================================
441 // function : ReCompute
443 // ========================================================================
444 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure,
445 const Handle(Graphic3d_DataStructureManager)& theProjector)
447 Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector);
450 || !myDefinedViews.Contains (aView.operator->())
451 || !myDisplayedStructure.Contains (theStructure))
456 aView->ReCompute (theStructure);
459 // ========================================================================
462 // ========================================================================
463 void Graphic3d_StructureManager::Clear (const Handle(Graphic3d_Structure)& theStructure,
464 const Standard_Boolean theWithDestruction)
466 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
468 aViewIt.Value()->Clear (theStructure, theWithDestruction);
472 // ========================================================================
473 // function : Connect
475 // ========================================================================
476 void Graphic3d_StructureManager::Connect (const Handle(Graphic3d_Structure)& theMother,
477 const Handle(Graphic3d_Structure)& theDaughter)
479 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
481 aViewIt.Value()->Connect (theMother, theDaughter);
485 // ========================================================================
486 // function : Disconnect
488 // ========================================================================
489 void Graphic3d_StructureManager::Disconnect (const Handle(Graphic3d_Structure)& theMother,
490 const Handle(Graphic3d_Structure)& theDaughter)
492 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
494 aViewIt.Value()->Disconnect (theMother, theDaughter);
498 // ========================================================================
499 // function : Display
501 // ========================================================================
502 void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure)
504 myDisplayedStructure.Add (theStructure);
506 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
508 aViewIt.Value()->Display (theStructure);
512 // ========================================================================
515 // ========================================================================
516 void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure)
518 myDisplayedStructure .Remove(theStructure);
519 myHighlightedStructure.Remove (theStructure);
521 // Erase structure in all defined views
522 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
524 aViewIt.Value()->Erase (theStructure);
528 // ========================================================================
531 // ========================================================================
532 void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure,
533 const Aspect_TypeOfHighlightMethod theMethod)
535 myHighlightedStructure.Add (theStructure);
537 // Highlight in all defined views
538 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
540 aViewIt.Value()->Highlight (theStructure, theMethod);
544 // ========================================================================
545 // function : UnHighlight
547 // ========================================================================
548 void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
550 myHighlightedStructure.Remove (theStructure);
552 // UnHighlight in all defined views
553 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
555 aViewIt.Value()->UnHighlight (theStructure);
559 // ========================================================================
560 // function : UnHighlight
562 // ========================================================================
563 void Graphic3d_StructureManager::UnHighlight()
565 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next())
567 anIt.Key()->UnHighlight();
571 // ========================================================================
572 // function : SetTransform
574 // ========================================================================
575 void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
576 const TColStd_Array2OfReal& theTrsf)
578 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
580 aViewIt.Value()->SetTransform (theStructure, theTrsf);
584 // ========================================================================
585 // function : ChangeDisplayPriority
587 // ========================================================================
588 void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure,
589 const Standard_Integer theOldPriority,
590 const Standard_Integer theNewPriority)
592 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
594 aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority);
598 //=======================================================================
599 //function : ChangeZLayer
601 //=======================================================================
602 void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
603 const Graphic3d_ZLayerId theLayerId)
605 if (!myDisplayedStructure.Contains (theStructure))
610 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
612 aViewIt.Value()->ChangeZLayer (theStructure, theLayerId);