0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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
59ec40f8 16#include <Graphic3d_StructureManager.hxx>
17
42cf5bc1 18#include <Graphic3d_DataStructureManager.hxx>
19#include <Graphic3d_GraphicDriver.hxx>
42cf5bc1 20#include <Graphic3d_Structure.hxx>
42cf5bc1 21
25e59720 22IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_StructureManager,Standard_Transient)
92efcf78 23
7fd59977 24#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
92efcf78 25#include <Graphic3d_CView.hxx>
7fd59977 26
c357e426 27// ========================================================================
59ec40f8 28// function : Graphic3d_StructureManager
c357e426 29// purpose :
30// ========================================================================
59ec40f8 31Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver)
32: myViewGenId (0, 31),
851dacdb 33 myGraphicDriver (theDriver),
34 myDeviceLostFlag (Standard_False)
c357e426 35{
59ec40f8 36 //
c357e426 37}
7fd59977 38
c357e426 39// ========================================================================
59ec40f8 40// function : ~Graphic3d_StructureManager
c357e426 41// purpose :
42// ========================================================================
59ec40f8 43Graphic3d_StructureManager::~Graphic3d_StructureManager()
c357e426 44{
b4fd9d00 45 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
46 {
47 anIt.Value()->Remove();
48 }
49
59ec40f8 50 myDisplayedStructure.Clear();
51 myHighlightedStructure.Clear();
52 myDefinedViews.Clear();
c357e426 53}
7fd59977 54
c357e426 55// ========================================================================
56// function : Update
57// purpose :
58// ========================================================================
cfece3ef 59void Graphic3d_StructureManager::Update (const Graphic3d_ZLayerId theLayerId) const
c357e426 60{
61 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
62 {
cfece3ef 63 aViewIt.Value()->Update (theLayerId);
c357e426 64 }
7fd59977 65}
66
c357e426 67// ========================================================================
68// function : Remove
69// purpose :
70// ========================================================================
71void Graphic3d_StructureManager::Remove()
72{
73 // clear all structures whilst views are alive for correct GPU memory management
b4fd9d00 74 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
75 {
76 anIt.Value()->Remove();
77 }
c357e426 78 myDisplayedStructure.Clear();
79 myHighlightedStructure.Clear();
7fd59977 80
c357e426 81 // clear list of managed views
82 myDefinedViews.Clear();
83}
7fd59977 84
c357e426 85// ========================================================================
86// function : Erase
87// purpose :
88// ========================================================================
89void Graphic3d_StructureManager::Erase()
90{
91 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next())
92 {
93 anIt.Key()->Erase();
94 }
7fd59977 95}
96
7fd59977 97void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
98
c357e426 99 SG.Assign(myDisplayedStructure);
7fd59977 100
c357e426 101 //JMBStandard_Integer Length = myDisplayedStructure.Length ();
7fd59977 102
103 //JMBfor (Standard_Integer i=1; i<=Length; i++)
c357e426 104 //JMB SG.Add (myDisplayedStructure.Value (i));
7fd59977 105
106}
107
108Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
109
c357e426 110Standard_Integer Length = myDisplayedStructure.Extent ();
7fd59977 111
112 return (Length);
113
114}
115
116//Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
117
c357e426 118//return (myDisplayedStructure.Value (AnIndex));
7fd59977 119
120//}
121
122void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
123
c357e426 124 SG.Assign(myHighlightedStructure);
7fd59977 125
126}
127
7fd59977 128Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
129
130// Standard_Integer ind=0;
131 Standard_Boolean notfound = Standard_True;
132
133 Handle(Graphic3d_Structure) StructNull;
134
c357e426 135 Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure);
7fd59977 136
137 Handle(Graphic3d_Structure) SGfound;
138
139 for (; it.More() && notfound; it.Next()) {
b2fedee6 140 const Handle(Graphic3d_Structure)& SG = it.Key();
7fd59977 141 if ( SG->Identification () == AId) {
142 notfound = Standard_False;
143 SGfound = SG;
144 }
145 }
146
147
148 if (notfound)
149 return (StructNull);
150 else
151 return (SGfound);
152
153}
154
016e5959 155const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const
156{
157 return (myGraphicDriver);
7fd59977 158}
eb4320f2 159
8bb96a97 160void Graphic3d_StructureManager::RecomputeStructures()
eb4320f2 161{
851dacdb 162 myDeviceLostFlag = Standard_False;
163
8bb96a97 164 // Go through all unique structures including child (connected) ones and ensure that they are computed.
7dd7c146 165 NCollection_Map<Graphic3d_Structure*> aStructNetwork;
c357e426 166 for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next())
eb4320f2 167 {
7dd7c146 168 anIter.Key()->Network (anIter.Key().get(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
8bb96a97 169 }
170
171 RecomputeStructures (aStructNetwork);
172}
eb4320f2 173
7dd7c146 174void Graphic3d_StructureManager::RecomputeStructures (const NCollection_Map<Graphic3d_Structure*>& theStructures)
8bb96a97 175{
7dd7c146 176 for (NCollection_Map<Graphic3d_Structure*>::Iterator anIter (theStructures); anIter.More(); anIter.Next())
8bb96a97 177 {
7dd7c146 178 Graphic3d_Structure* aStruct = anIter.Key();
8bb96a97 179 aStruct->Clear();
180 aStruct->Compute();
eb4320f2 181 }
182}
a272ed94 183
86d6c284 184// ========================================================================
185// function : RegisterObject
186// purpose :
187// ========================================================================
188void Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject,
189 const Handle(Graphic3d_ViewAffinity)& theAffinity)
a272ed94 190{
191 Handle(Graphic3d_ViewAffinity) aResult;
86d6c284 192 if (myRegisteredObjects.Find (theObject.operator->(), aResult)
193 && aResult == theAffinity)
a272ed94 194 {
86d6c284 195 return;
a272ed94 196 }
197
86d6c284 198 myRegisteredObjects.Bind (theObject.operator->(), theAffinity);
a272ed94 199}
200
86d6c284 201// ========================================================================
202// function : UnregisterObject
203// purpose :
204// ========================================================================
a272ed94 205void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject)
206{
207 myRegisteredObjects.UnBind (theObject.operator->());
208}
209
86d6c284 210// ========================================================================
211// function : ObjectAffinity
212// purpose :
213// ========================================================================
214const Handle(Graphic3d_ViewAffinity)& Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
a272ed94 215{
86d6c284 216 const Handle(Graphic3d_ViewAffinity)* aResult = myRegisteredObjects.Seek (theObject.operator->());
217 if (aResult == nullptr)
218 {
219 static const Handle(Graphic3d_ViewAffinity) aDummy;
220 return aDummy;
221 }
222 return *aResult;
a272ed94 223}
c357e426 224
225// ========================================================================
226// function : Identification
227// purpose :
228// ========================================================================
229Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView)
230{
231 if (myDefinedViews.Contains (theView))
232 {
233 return theView->Identification();
234 }
235
236 myDefinedViews.Add (theView);
237 return myViewGenId.Next();
238}
239
240// ========================================================================
241// function : UnIdentification
242// purpose :
243// ========================================================================
244void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView)
245{
246 if (myDefinedViews.Contains (theView))
247 {
248 myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size());
249 myDefinedViews.RemoveLast();
250 myViewGenId.Free (theView->Identification());
251 }
252}
253
254// ========================================================================
255// function : DefinedViews
256// purpose :
257// ========================================================================
258const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const
259{
260 return myDefinedViews;
261}
262
263// ========================================================================
264// function : MaxNumOfViews
265// purpose :
266// ========================================================================
267Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const
268{
269 return myViewGenId.Upper() - myViewGenId.Lower() + 1;
270}
271
272// ========================================================================
273// function : ReCompute
274// purpose :
275// ========================================================================
276void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure)
277{
278 if (!myDisplayedStructure.Contains (theStructure))
279 {
280 return;
281 }
282
283 // Recompute structure for all defined views
284 for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt)
285 {
286 ReCompute (theStructure, myDefinedViews (aViewIt));
287 }
288}
289
290// ========================================================================
291// function : ReCompute
292// purpose :
293// ========================================================================
294void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure,
295 const Handle(Graphic3d_DataStructureManager)& theProjector)
296{
297 Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector);
298
299 if (aView.IsNull()
300 || !myDefinedViews.Contains (aView.operator->())
301 || !myDisplayedStructure.Contains (theStructure))
302 {
303 return;
304 }
305
306 aView->ReCompute (theStructure);
307}
308
309// ========================================================================
310// function : Clear
311// purpose :
312// ========================================================================
7dd7c146 313void Graphic3d_StructureManager::Clear (Graphic3d_Structure* theStructure,
c357e426 314 const Standard_Boolean theWithDestruction)
315{
316 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
317 {
318 aViewIt.Value()->Clear (theStructure, theWithDestruction);
319 }
320}
321
322// ========================================================================
323// function : Connect
324// purpose :
325// ========================================================================
7dd7c146 326void Graphic3d_StructureManager::Connect (const Graphic3d_Structure* theMother,
327 const Graphic3d_Structure* theDaughter)
c357e426 328{
329 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
330 {
331 aViewIt.Value()->Connect (theMother, theDaughter);
332 }
333}
334
335// ========================================================================
336// function : Disconnect
337// purpose :
338// ========================================================================
7dd7c146 339void Graphic3d_StructureManager::Disconnect (const Graphic3d_Structure* theMother,
340 const Graphic3d_Structure* theDaughter)
c357e426 341{
342 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
343 {
344 aViewIt.Value()->Disconnect (theMother, theDaughter);
345 }
346}
347
348// ========================================================================
349// function : Display
350// purpose :
351// ========================================================================
352void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure)
353{
354 myDisplayedStructure.Add (theStructure);
355
356 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
357 {
358 aViewIt.Value()->Display (theStructure);
359 }
360}
361
362// ========================================================================
363// function : Erase
364// purpose :
365// ========================================================================
366void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure)
367{
368 myDisplayedStructure .Remove(theStructure);
369 myHighlightedStructure.Remove (theStructure);
370
371 // Erase structure in all defined views
372 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
373 {
374 aViewIt.Value()->Erase (theStructure);
375 }
376}
377
378// ========================================================================
379// function : Erase
380// purpose :
381// ========================================================================
8e5fb5ea 382void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure)
c357e426 383{
384 myHighlightedStructure.Add (theStructure);
385
386 // Highlight in all defined views
387 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
388 {
8e5fb5ea 389 aViewIt.Value()->Highlight (theStructure);
c357e426 390 }
391}
392
393// ========================================================================
394// function : UnHighlight
395// purpose :
396// ========================================================================
397void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
398{
399 myHighlightedStructure.Remove (theStructure);
400
401 // UnHighlight in all defined views
402 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
403 {
404 aViewIt.Value()->UnHighlight (theStructure);
405 }
406}
407
408// ========================================================================
409// function : UnHighlight
410// purpose :
411// ========================================================================
412void Graphic3d_StructureManager::UnHighlight()
413{
414 for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next())
415 {
416 anIt.Key()->UnHighlight();
417 }
418}
419
420// ========================================================================
421// function : SetTransform
422// purpose :
423// ========================================================================
424void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
7f24b768 425 const Handle(TopLoc_Datum3D)& theTrsf)
c357e426 426{
427 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
428 {
429 aViewIt.Value()->SetTransform (theStructure, theTrsf);
430 }
431}
432
433// ========================================================================
434// function : ChangeDisplayPriority
435// purpose :
436// ========================================================================
437void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure,
e463b2f6 438 const Graphic3d_DisplayPriority theOldPriority,
439 const Graphic3d_DisplayPriority theNewPriority)
c357e426 440{
441 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
442 {
443 aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority);
444 }
445}
446
447//=======================================================================
448//function : ChangeZLayer
449//purpose :
450//=======================================================================
451void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
452 const Graphic3d_ZLayerId theLayerId)
453{
454 if (!myDisplayedStructure.Contains (theStructure))
455 {
456 return;
457 }
458
459 for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
460 {
461 aViewIt.Value()->ChangeZLayer (theStructure, theLayerId);
462 }
463}
a5162275 464
465// =======================================================================
466// function : DumpJson
467// purpose :
468// =======================================================================
469void Graphic3d_StructureManager::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
470{
471 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
472
473 for (Graphic3d_MapOfStructure::Iterator anIter (myDisplayedStructure); anIter.More(); anIter.Next())
474 {
475 const Handle(Graphic3d_Structure)& aDisplayedStructure = anIter.Value();
476 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDisplayedStructure.get())
477 }
478 for (Graphic3d_MapOfStructure::Iterator anIter (myHighlightedStructure); anIter.More(); anIter.Next())
479 {
480 const Handle(Graphic3d_Structure)& aHighlightedStructure = anIter.Value();
481 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aHighlightedStructure.get())
482 }
483 for (Graphic3d_MapOfObject::Iterator anIter (myRegisteredObjects); anIter.More(); anIter.Next())
484 {
485 const Handle(Graphic3d_ViewAffinity)& aRegisteredObject = anIter.Value();
486 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aRegisteredObject.get())
487 }
488
489 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGraphicDriver.get())
490 for (Graphic3d_IndexedMapOfView::Iterator anIter (myDefinedViews); anIter.More(); anIter.Next())
491 {
492 Graphic3d_CView* aDefinedView = anIter.Value();
493 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDefinedView)
494 }
495
496 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDeviceLostFlag)
497}