0025133: TKOpenGl - Crash on closing a view containing presentations with capping
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_4.cxx
CommitLineData
b311480e 1// Created on: 2011-10-20
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-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
2166f0fa 16#include <OpenGl_GraphicDriver.hxx>
7fd59977 17
2166f0fa
SK
18#include <NCollection_DataMap.hxx>
19#include <OpenGl_Structure.hxx>
20#include <OpenGl_CView.hxx>
7fd59977 21
63bcc448 22void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView,
23 Graphic3d_CStructure& theCStructure,
24 const Standard_Integer thePriority)
2166f0fa 25{
63bcc448 26 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
27 OpenGl_Structure* aStructure = (OpenGl_Structure* )&theCStructure;
28 if (aCView == NULL)
2166f0fa
SK
29 return;
30
31 aCView->View->DisplayStructure (aStructure, thePriority);
7fd59977 32}
33
63bcc448 34void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
35 Graphic3d_CStructure& theCStructure)
2166f0fa 36{
63bcc448 37 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
38 OpenGl_Structure* aStructure = (OpenGl_Structure* )&theCStructure;
2166f0fa
SK
39 if (aCView == NULL || aStructure == NULL)
40 return;
7fd59977 41
2166f0fa 42 aCView->View->EraseStructure (aStructure);
7fd59977 43}
44
63bcc448 45void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure)
2166f0fa 46{
63bcc448 47 OpenGl_Structure* aStructure = NULL;
48 if (!myMapOfStructure.Find (theCStructure->Id, aStructure))
49 {
2166f0fa 50 return;
63bcc448 51 }
7fd59977 52
63bcc448 53 myMapOfStructure.UnBind (theCStructure->Id);
54 aStructure->Release (GetSharedContext());
55 theCStructure.Nullify();
7fd59977 56}
57
63bcc448 58Handle(Graphic3d_CStructure) OpenGl_GraphicDriver::Structure (const Handle(Graphic3d_StructureManager)& theManager)
2166f0fa 59{
63bcc448 60 Handle(OpenGl_Structure) aStructure = new OpenGl_Structure (theManager);
61 myMapOfStructure.Bind (aStructure->Id, aStructure.operator->());
62 return aStructure;
7fd59977 63}
59f45b7c 64
65//=======================================================================
66//function : ChangeZLayer
67//purpose :
68//=======================================================================
69
70void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
71 const Standard_Integer theLayer)
72{
5e27df78 73 if (!myMapOfStructure.IsBound (theCStructure.Id))
59f45b7c 74 return;
75
5e27df78 76 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 77
78 aStructure->SetZLayer (theLayer);
79}
80
81//=======================================================================
82//function : ChangeZLayer
83//purpose :
84//=======================================================================
85
86void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
87 const Graphic3d_CView& theCView,
88 const Standard_Integer theNewLayerId)
89{
90 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
91
5e27df78 92 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
59f45b7c 93 return;
94
5e27df78 95 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 96
97 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
98}
99
100//=======================================================================
101//function : GetZLayer
102//purpose :
103//=======================================================================
104
105Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
106{
5e27df78 107 if (!myMapOfStructure.IsBound (theCStructure.Id))
59f45b7c 108 return -1;
109
5e27df78 110 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 111
112 return aStructure->GetZLayer();
113}
114
115//=======================================================================
116//function : UnsetZLayer
117//purpose :
118//=======================================================================
119
120void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
121{
5e27df78 122 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
59f45b7c 123 for( ; aStructIt.More (); aStructIt.Next ())
124 {
125 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
126 if (aStruct->GetZLayer () == theLayerId)
127 aStruct->SetZLayer (0);
128 }
129}
b7cd4ba7 130
131//=======================================================================
132//function : ChangePriority
133//purpose :
134//=======================================================================
135void OpenGl_GraphicDriver::ChangePriority (const Graphic3d_CStructure& theCStructure,
136 const Graphic3d_CView& theCView,
137 const Standard_Integer theNewPriority)
138{
139 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
140
141 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
142 return;
143
144 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
145
146 aCView->View->ChangePriority (aStructure, theNewPriority);
147}