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 myGraphicDriver (theDriver)
38 // ========================================================================
39 // function : ~Graphic3d_StructureManager
41 // ========================================================================
42 Graphic3d_StructureManager::~Graphic3d_StructureManager()
44 myDisplayedStructure.Clear();
45 myHighlightedStructure.Clear();
46 myDefinedViews.Clear();
49 // ========================================================================
52 // ========================================================================
53 void Graphic3d_StructureManager::Update (const Graphic3d_ZLayerId theLayerId) const
55 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
57 aViewIt.Value()->Update (theLayerId);
61 // ========================================================================
64 // ========================================================================
65 void Graphic3d_StructureManager::Remove()
67 // clear all structures whilst views are alive for correct GPU memory management
68 myDisplayedStructure.Clear();
69 myHighlightedStructure.Clear();
71 // clear list of managed views
72 myDefinedViews.Clear();
75 // ========================================================================
78 // ========================================================================
79 void Graphic3d_StructureManager::Erase()
81 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
87 void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
89 SG.Assign(myDisplayedStructure);
91 //JMBStandard_Integer Length = myDisplayedStructure.Length ();
93 //JMBfor (Standard_Integer i=1; i<=Length; i++)
94 //JMB SG.Add (myDisplayedStructure.Value (i));
98 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
100 Standard_Integer Length = myDisplayedStructure.Extent ();
106 //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
108 //return (myDisplayedStructure.Value (AnIndex));
112 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
114 SG.Assign(myHighlightedStructure);
118 Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
120 // Standard_Integer ind=0;
121 Standard_Boolean notfound = Standard_True;
123 Handle(Graphic3d_Structure) StructNull;
125 Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure);
127 Handle(Graphic3d_Structure) SGfound;
129 for (; it.More() && notfound; it.Next()) {
130 Handle(Graphic3d_Structure) SG = it.Key();
131 if ( SG->Identification () == AId) {
132 notfound = Standard_False;
145 const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const
147 return (myGraphicDriver);
150 void Graphic3d_StructureManager::RecomputeStructures()
152 // Go through all unique structures including child (connected) ones and ensure that they are computed.
153 Graphic3d_MapOfStructure aStructNetwork;
155 for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next())
157 Handle(Graphic3d_Structure) aStructure = anIter.Key();
158 anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
161 RecomputeStructures (aStructNetwork);
164 void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures)
166 for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next())
168 Handle(Graphic3d_Structure) aStruct = anIter.Key();
174 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject)
176 Handle(Graphic3d_ViewAffinity) aResult;
177 if (myRegisteredObjects.Find (theObject.operator->(), aResult))
182 aResult = new Graphic3d_ViewAffinity();
183 myRegisteredObjects.Bind (theObject.operator->(), aResult);
187 void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject)
189 myRegisteredObjects.UnBind (theObject.operator->());
192 Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
194 Handle(Graphic3d_ViewAffinity) aResult;
195 myRegisteredObjects.Find (theObject.operator->(), aResult);
199 // ========================================================================
200 // function : Identification
202 // ========================================================================
203 Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView)
205 if (myDefinedViews.Contains (theView))
207 return theView->Identification();
210 myDefinedViews.Add (theView);
211 return myViewGenId.Next();
214 // ========================================================================
215 // function : UnIdentification
217 // ========================================================================
218 void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView)
220 if (myDefinedViews.Contains (theView))
222 myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size());
223 myDefinedViews.RemoveLast();
224 myViewGenId.Free (theView->Identification());
228 // ========================================================================
229 // function : DefinedViews
231 // ========================================================================
232 const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const
234 return myDefinedViews;
237 // ========================================================================
238 // function : MaxNumOfViews
240 // ========================================================================
241 Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const
243 return myViewGenId.Upper() - myViewGenId.Lower() + 1;
246 // ========================================================================
247 // function : ReCompute
249 // ========================================================================
250 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure)
252 if (!myDisplayedStructure.Contains (theStructure))
257 // Recompute structure for all defined views
258 for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt)
260 ReCompute (theStructure, myDefinedViews (aViewIt));
264 // ========================================================================
265 // function : ReCompute
267 // ========================================================================
268 void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure,
269 const Handle(Graphic3d_DataStructureManager)& theProjector)
271 Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector);
274 || !myDefinedViews.Contains (aView.operator->())
275 || !myDisplayedStructure.Contains (theStructure))
280 aView->ReCompute (theStructure);
283 // ========================================================================
286 // ========================================================================
287 void Graphic3d_StructureManager::Clear (const Handle(Graphic3d_Structure)& theStructure,
288 const Standard_Boolean theWithDestruction)
290 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
292 aViewIt.Value()->Clear (theStructure, theWithDestruction);
296 // ========================================================================
297 // function : Connect
299 // ========================================================================
300 void Graphic3d_StructureManager::Connect (const Handle(Graphic3d_Structure)& theMother,
301 const Handle(Graphic3d_Structure)& theDaughter)
303 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
305 aViewIt.Value()->Connect (theMother, theDaughter);
309 // ========================================================================
310 // function : Disconnect
312 // ========================================================================
313 void Graphic3d_StructureManager::Disconnect (const Handle(Graphic3d_Structure)& theMother,
314 const Handle(Graphic3d_Structure)& theDaughter)
316 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
318 aViewIt.Value()->Disconnect (theMother, theDaughter);
322 // ========================================================================
323 // function : Display
325 // ========================================================================
326 void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure)
328 myDisplayedStructure.Add (theStructure);
330 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
332 aViewIt.Value()->Display (theStructure);
336 // ========================================================================
339 // ========================================================================
340 void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure)
342 myDisplayedStructure .Remove(theStructure);
343 myHighlightedStructure.Remove (theStructure);
345 // Erase structure in all defined views
346 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
348 aViewIt.Value()->Erase (theStructure);
352 // ========================================================================
355 // ========================================================================
356 void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure)
358 myHighlightedStructure.Add (theStructure);
360 // Highlight in all defined views
361 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
363 aViewIt.Value()->Highlight (theStructure);
367 // ========================================================================
368 // function : UnHighlight
370 // ========================================================================
371 void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
373 myHighlightedStructure.Remove (theStructure);
375 // UnHighlight in all defined views
376 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
378 aViewIt.Value()->UnHighlight (theStructure);
382 // ========================================================================
383 // function : UnHighlight
385 // ========================================================================
386 void Graphic3d_StructureManager::UnHighlight()
388 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next())
390 anIt.Key()->UnHighlight();
394 // ========================================================================
395 // function : SetTransform
397 // ========================================================================
398 void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
399 const Handle(Geom_Transformation)& theTrsf)
401 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
403 aViewIt.Value()->SetTransform (theStructure, theTrsf);
407 // ========================================================================
408 // function : ChangeDisplayPriority
410 // ========================================================================
411 void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure,
412 const Standard_Integer theOldPriority,
413 const Standard_Integer theNewPriority)
415 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
417 aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority);
421 //=======================================================================
422 //function : ChangeZLayer
424 //=======================================================================
425 void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
426 const Graphic3d_ZLayerId theLayerId)
428 if (!myDisplayedStructure.Contains (theStructure))
433 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
435 aViewIt.Value()->ChangeZLayer (theStructure, theLayerId);