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 <Standard_Transient.hxx>
34 #include <Standard_Type.hxx>
36 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_StructureManager,MMgt_TShared)
38 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
39 #include <Graphic3d_CView.hxx>
41 Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver)
44 myAspectLine3d = new Graphic3d_AspectLine3d ();
45 myAspectText3d = new Graphic3d_AspectText3d ();
46 myAspectMarker3d = new Graphic3d_AspectMarker3d ();
47 myAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
49 myUpdateMode = Aspect_TOU_WAIT;
50 myGraphicDriver = theDriver;
56 Graphic3d_StructureManager::~Graphic3d_StructureManager ()
58 myDisplayedStructure.Clear ();
59 myHighlightedStructure.Clear ();
60 myDefinedViews.Clear();
64 // ========================================================================
65 // function : SetUpdateMode
67 // ========================================================================
68 void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate theType)
70 myUpdateMode = theType;
73 // ========================================================================
74 // function : UpdateMode
76 // ========================================================================
77 Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode() const
82 // ========================================================================
85 // ========================================================================
86 void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode) const
88 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
90 aViewIt.Value()->Update (theMode);
94 // ========================================================================
97 // ========================================================================
98 void Graphic3d_StructureManager::Remove()
100 // clear all structures whilst views are alive for correct GPU memory management
101 myDisplayedStructure.Clear();
102 myHighlightedStructure.Clear();
104 // clear list of managed views
105 myDefinedViews.Clear();
108 // ========================================================================
111 // ========================================================================
112 void Graphic3d_StructureManager::Erase()
114 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
124 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
126 myAspectLine3d = CTX;
130 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
132 myAspectFillArea3d = CTX;
136 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
138 myAspectText3d = CTX;
142 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
144 myAspectMarker3d = CTX;
148 void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
150 CTXL = myAspectLine3d;
151 CTXT = myAspectText3d;
152 CTXM = myAspectMarker3d;
153 CTXF = myAspectFillArea3d;
157 Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
159 return (myAspectLine3d);
163 Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
165 return (myAspectText3d);
169 Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
171 return (myAspectMarker3d);
175 Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
177 return (myAspectFillArea3d);
181 void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
183 SG.Assign(myDisplayedStructure);
185 //JMBStandard_Integer Length = myDisplayedStructure.Length ();
187 //JMBfor (Standard_Integer i=1; i<=Length; i++)
188 //JMB SG.Add (myDisplayedStructure.Value (i));
192 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
194 Standard_Integer Length = myDisplayedStructure.Extent ();
200 //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
202 //return (myDisplayedStructure.Value (AnIndex));
206 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
208 SG.Assign(myHighlightedStructure);
212 Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
214 // Standard_Integer ind=0;
215 Standard_Boolean notfound = Standard_True;
217 Handle(Graphic3d_Structure) StructNull;
219 Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure);
221 Handle(Graphic3d_Structure) SGfound;
223 for (; it.More() && notfound; it.Next()) {
224 Handle(Graphic3d_Structure) SG = it.Key();
225 if ( SG->Identification () == AId) {
226 notfound = Standard_False;
239 const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const
241 return (myGraphicDriver);
244 void Graphic3d_StructureManager::RecomputeStructures()
246 // Go through all unique structures including child (connected) ones and ensure that they are computed.
247 Graphic3d_MapOfStructure aStructNetwork;
249 for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next())
251 Handle(Graphic3d_Structure) aStructure = anIter.Key();
252 anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
255 RecomputeStructures (aStructNetwork);
258 void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures)
260 for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next())
262 Handle(Graphic3d_Structure) aStruct = anIter.Key();
268 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject)
270 Handle(Graphic3d_ViewAffinity) aResult;
271 if (myRegisteredObjects.Find (theObject.operator->(), aResult))
276 aResult = new Graphic3d_ViewAffinity();
277 myRegisteredObjects.Bind (theObject.operator->(), aResult);
281 void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject)
283 myRegisteredObjects.UnBind (theObject.operator->());
286 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
288 Handle(Graphic3d_ViewAffinity) aResult;
289 myRegisteredObjects.Find (theObject.operator->(), aResult);
293 // ========================================================================
294 // function : Identification
296 // ========================================================================
297 Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView)
299 if (myDefinedViews.Contains (theView))
301 return theView->Identification();
304 myDefinedViews.Add (theView);
305 return myViewGenId.Next();
308 // ========================================================================
309 // function : UnIdentification
311 // ========================================================================
312 void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView)
314 if (myDefinedViews.Contains (theView))
316 myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size());
317 myDefinedViews.RemoveLast();
318 myViewGenId.Free (theView->Identification());
322 // ========================================================================
323 // function : DefinedViews
325 // ========================================================================
326 const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const
328 return myDefinedViews;
331 // ========================================================================
332 // function : MaxNumOfViews
334 // ========================================================================
335 Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const
337 return myViewGenId.Upper() - myViewGenId.Lower() + 1;
340 // ========================================================================
341 // function : ReCompute
343 // ========================================================================
344 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure)
346 if (!myDisplayedStructure.Contains (theStructure))
351 // Recompute structure for all defined views
352 for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt)
354 ReCompute (theStructure, myDefinedViews (aViewIt));
358 // ========================================================================
359 // function : ReCompute
361 // ========================================================================
362 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure,
363 const Handle(Graphic3d_DataStructureManager)& theProjector)
365 Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector);
368 || !myDefinedViews.Contains (aView.operator->())
369 || !myDisplayedStructure.Contains (theStructure))
374 aView->ReCompute (theStructure);
377 // ========================================================================
380 // ========================================================================
381 void Graphic3d_StructureManager::Clear (const Handle(Graphic3d_Structure)& theStructure,
382 const Standard_Boolean theWithDestruction)
384 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
386 aViewIt.Value()->Clear (theStructure, theWithDestruction);
390 // ========================================================================
391 // function : Connect
393 // ========================================================================
394 void Graphic3d_StructureManager::Connect (const Handle(Graphic3d_Structure)& theMother,
395 const Handle(Graphic3d_Structure)& theDaughter)
397 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
399 aViewIt.Value()->Connect (theMother, theDaughter);
403 // ========================================================================
404 // function : Disconnect
406 // ========================================================================
407 void Graphic3d_StructureManager::Disconnect (const Handle(Graphic3d_Structure)& theMother,
408 const Handle(Graphic3d_Structure)& theDaughter)
410 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
412 aViewIt.Value()->Disconnect (theMother, theDaughter);
416 // ========================================================================
417 // function : Display
419 // ========================================================================
420 void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure)
422 myDisplayedStructure.Add (theStructure);
424 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
426 aViewIt.Value()->Display (theStructure);
430 // ========================================================================
433 // ========================================================================
434 void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure)
436 myDisplayedStructure .Remove(theStructure);
437 myHighlightedStructure.Remove (theStructure);
439 // Erase structure in all defined views
440 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
442 aViewIt.Value()->Erase (theStructure);
446 // ========================================================================
449 // ========================================================================
450 void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure,
451 const Aspect_TypeOfHighlightMethod theMethod)
453 myHighlightedStructure.Add (theStructure);
455 // Highlight in all defined views
456 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
458 aViewIt.Value()->Highlight (theStructure, theMethod);
462 // ========================================================================
463 // function : UnHighlight
465 // ========================================================================
466 void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
468 myHighlightedStructure.Remove (theStructure);
470 // UnHighlight in all defined views
471 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
473 aViewIt.Value()->UnHighlight (theStructure);
477 // ========================================================================
478 // function : UnHighlight
480 // ========================================================================
481 void Graphic3d_StructureManager::UnHighlight()
483 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next())
485 anIt.Key()->UnHighlight();
489 // ========================================================================
490 // function : SetTransform
492 // ========================================================================
493 void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
494 const TColStd_Array2OfReal& theTrsf)
496 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
498 aViewIt.Value()->SetTransform (theStructure, theTrsf);
502 // ========================================================================
503 // function : ChangeDisplayPriority
505 // ========================================================================
506 void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure,
507 const Standard_Integer theOldPriority,
508 const Standard_Integer theNewPriority)
510 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
512 aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority);
516 //=======================================================================
517 //function : ChangeZLayer
519 //=======================================================================
520 void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
521 const Graphic3d_ZLayerId theLayerId)
523 if (!myDisplayedStructure.Contains (theStructure))
528 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
530 aViewIt.Value()->ChangeZLayer (theStructure, theLayerId);