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.
16 #include <Graphic3d_StructureManager.hxx>
18 #include <Graphic3d_DataStructureManager.hxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <Graphic3d_Structure.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_StructureManager,MMgt_TShared)
24 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
25 #include <Graphic3d_CView.hxx>
27 // ========================================================================
28 // function : Graphic3d_StructureManager
30 // ========================================================================
31 Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver)
32 : myViewGenId (0, 31),
33 myUpdateMode (Aspect_TOU_WAIT),
34 myGraphicDriver (theDriver)
39 // ========================================================================
40 // function : ~Graphic3d_StructureManager
42 // ========================================================================
43 Graphic3d_StructureManager::~Graphic3d_StructureManager()
45 myDisplayedStructure.Clear();
46 myHighlightedStructure.Clear();
47 myDefinedViews.Clear();
50 // ========================================================================
53 // ========================================================================
54 void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode,
55 const Graphic3d_ZLayerId theLayerId) const
57 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
59 aViewIt.Value()->Update (theMode, theLayerId);
63 // ========================================================================
66 // ========================================================================
67 void Graphic3d_StructureManager::Remove()
69 // clear all structures whilst views are alive for correct GPU memory management
70 myDisplayedStructure.Clear();
71 myHighlightedStructure.Clear();
73 // clear list of managed views
74 myDefinedViews.Clear();
77 // ========================================================================
80 // ========================================================================
81 void Graphic3d_StructureManager::Erase()
83 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
89 void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
91 SG.Assign(myDisplayedStructure);
93 //JMBStandard_Integer Length = myDisplayedStructure.Length ();
95 //JMBfor (Standard_Integer i=1; i<=Length; i++)
96 //JMB SG.Add (myDisplayedStructure.Value (i));
100 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
102 Standard_Integer Length = myDisplayedStructure.Extent ();
108 //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
110 //return (myDisplayedStructure.Value (AnIndex));
114 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
116 SG.Assign(myHighlightedStructure);
120 Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
122 // Standard_Integer ind=0;
123 Standard_Boolean notfound = Standard_True;
125 Handle(Graphic3d_Structure) StructNull;
127 Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure);
129 Handle(Graphic3d_Structure) SGfound;
131 for (; it.More() && notfound; it.Next()) {
132 Handle(Graphic3d_Structure) SG = it.Key();
133 if ( SG->Identification () == AId) {
134 notfound = Standard_False;
147 const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const
149 return (myGraphicDriver);
152 void Graphic3d_StructureManager::RecomputeStructures()
154 // Go through all unique structures including child (connected) ones and ensure that they are computed.
155 Graphic3d_MapOfStructure aStructNetwork;
157 for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next())
159 Handle(Graphic3d_Structure) aStructure = anIter.Key();
160 anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
163 RecomputeStructures (aStructNetwork);
166 void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures)
168 for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next())
170 Handle(Graphic3d_Structure) aStruct = anIter.Key();
176 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject)
178 Handle(Graphic3d_ViewAffinity) aResult;
179 if (myRegisteredObjects.Find (theObject.operator->(), aResult))
184 aResult = new Graphic3d_ViewAffinity();
185 myRegisteredObjects.Bind (theObject.operator->(), aResult);
189 void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject)
191 myRegisteredObjects.UnBind (theObject.operator->());
194 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
196 Handle(Graphic3d_ViewAffinity) aResult;
197 myRegisteredObjects.Find (theObject.operator->(), aResult);
201 // ========================================================================
202 // function : Identification
204 // ========================================================================
205 Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView)
207 if (myDefinedViews.Contains (theView))
209 return theView->Identification();
212 myDefinedViews.Add (theView);
213 return myViewGenId.Next();
216 // ========================================================================
217 // function : UnIdentification
219 // ========================================================================
220 void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView)
222 if (myDefinedViews.Contains (theView))
224 myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size());
225 myDefinedViews.RemoveLast();
226 myViewGenId.Free (theView->Identification());
230 // ========================================================================
231 // function : DefinedViews
233 // ========================================================================
234 const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const
236 return myDefinedViews;
239 // ========================================================================
240 // function : MaxNumOfViews
242 // ========================================================================
243 Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const
245 return myViewGenId.Upper() - myViewGenId.Lower() + 1;
248 // ========================================================================
249 // function : ReCompute
251 // ========================================================================
252 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure)
254 if (!myDisplayedStructure.Contains (theStructure))
259 // Recompute structure for all defined views
260 for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt)
262 ReCompute (theStructure, myDefinedViews (aViewIt));
266 // ========================================================================
267 // function : ReCompute
269 // ========================================================================
270 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure,
271 const Handle(Graphic3d_DataStructureManager)& theProjector)
273 Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector);
276 || !myDefinedViews.Contains (aView.operator->())
277 || !myDisplayedStructure.Contains (theStructure))
282 aView->ReCompute (theStructure);
285 // ========================================================================
288 // ========================================================================
289 void Graphic3d_StructureManager::Clear (const Handle(Graphic3d_Structure)& theStructure,
290 const Standard_Boolean theWithDestruction)
292 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
294 aViewIt.Value()->Clear (theStructure, theWithDestruction);
298 // ========================================================================
299 // function : Connect
301 // ========================================================================
302 void Graphic3d_StructureManager::Connect (const Handle(Graphic3d_Structure)& theMother,
303 const Handle(Graphic3d_Structure)& theDaughter)
305 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
307 aViewIt.Value()->Connect (theMother, theDaughter);
311 // ========================================================================
312 // function : Disconnect
314 // ========================================================================
315 void Graphic3d_StructureManager::Disconnect (const Handle(Graphic3d_Structure)& theMother,
316 const Handle(Graphic3d_Structure)& theDaughter)
318 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
320 aViewIt.Value()->Disconnect (theMother, theDaughter);
324 // ========================================================================
325 // function : Display
327 // ========================================================================
328 void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure)
330 myDisplayedStructure.Add (theStructure);
332 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
334 aViewIt.Value()->Display (theStructure);
338 // ========================================================================
341 // ========================================================================
342 void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure)
344 myDisplayedStructure .Remove(theStructure);
345 myHighlightedStructure.Remove (theStructure);
347 // Erase structure in all defined views
348 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
350 aViewIt.Value()->Erase (theStructure);
354 // ========================================================================
357 // ========================================================================
358 void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure,
359 const Aspect_TypeOfHighlightMethod theMethod)
361 myHighlightedStructure.Add (theStructure);
363 // Highlight in all defined views
364 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
366 aViewIt.Value()->Highlight (theStructure, theMethod);
370 // ========================================================================
371 // function : UnHighlight
373 // ========================================================================
374 void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
376 myHighlightedStructure.Remove (theStructure);
378 // UnHighlight in all defined views
379 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
381 aViewIt.Value()->UnHighlight (theStructure);
385 // ========================================================================
386 // function : UnHighlight
388 // ========================================================================
389 void Graphic3d_StructureManager::UnHighlight()
391 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next())
393 anIt.Key()->UnHighlight();
397 // ========================================================================
398 // function : SetTransform
400 // ========================================================================
401 void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
402 const TColStd_Array2OfReal& theTrsf)
404 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
406 aViewIt.Value()->SetTransform (theStructure, theTrsf);
410 // ========================================================================
411 // function : ChangeDisplayPriority
413 // ========================================================================
414 void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure,
415 const Standard_Integer theOldPriority,
416 const Standard_Integer theNewPriority)
418 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
420 aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority);
424 //=======================================================================
425 //function : ChangeZLayer
427 //=======================================================================
428 void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
429 const Graphic3d_ZLayerId theLayerId)
431 if (!myDisplayedStructure.Contains (theStructure))
436 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
438 aViewIt.Value()->ChangeZLayer (theStructure, theLayerId);