0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_4.cxx
CommitLineData
b311480e 1// Created on: 2011-10-20
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
2166f0fa 21#include <OpenGl_GraphicDriver.hxx>
7fd59977 22
2166f0fa
SK
23#include <NCollection_DataMap.hxx>
24#include <OpenGl_Structure.hxx>
25#include <OpenGl_CView.hxx>
7fd59977 26
2166f0fa
SK
27void OpenGl_GraphicDriver::ClearStructure (const Graphic3d_CStructure& theCStructure)
28{
29 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
30 if (aStructure == NULL)
31 return;
7fd59977 32
5e27df78 33 aStructure->Clear (GetSharedContext());
2166f0fa 34}
7fd59977 35
2166f0fa
SK
36void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStructure)
37{
38 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
39 if (aStructure == NULL)
40 return;
7fd59977 41
2166f0fa 42 aStructure->SetTransformPersistence (theCStructure.TransformPersistence);
7fd59977 43
2166f0fa
SK
44 if (theCStructure.ContextLine.IsDef)
45 aStructure->SetAspectLine (theCStructure.ContextLine);
7fd59977 46
2166f0fa 47 if (theCStructure.ContextFillArea.IsDef)
fd4a6963 48 aStructure->SetAspectFace (theCStructure.ContextFillArea);
7fd59977 49
2166f0fa 50 if (theCStructure.ContextMarker.IsDef)
fd4a6963 51 aStructure->SetAspectMarker (theCStructure.ContextMarker);
7fd59977 52
2166f0fa
SK
53 if (theCStructure.ContextText.IsDef)
54 aStructure->SetAspectText (theCStructure.ContextText);
7fd59977 55}
56
2166f0fa
SK
57void OpenGl_GraphicDriver::Connect (const Graphic3d_CStructure& theFather,
58 const Graphic3d_CStructure& theSon)
59{
60 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
61 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
62 if (aFather && aSon)
63 aFather->Connect(aSon);
7fd59977 64}
65
2166f0fa
SK
66void OpenGl_GraphicDriver::Disconnect (const Graphic3d_CStructure& theFather,
67 const Graphic3d_CStructure& theSon)
68{
69 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
70 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
71 if (aFather && aSon)
72 aFather->Disconnect(aSon);
7fd59977 73}
74
2166f0fa
SK
75void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView,
76 const Graphic3d_CStructure& theCStructure,
77 const Standard_Integer thePriority)
78{
79 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
80 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
81 if (aCView == NULL || aStructure == NULL)
82 return;
83
84 aCView->View->DisplayStructure (aStructure, thePriority);
7fd59977 85}
86
2166f0fa
SK
87void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
88 const Graphic3d_CStructure& theCStructure)
89{
90 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
91 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
92 if (aCView == NULL || aStructure == NULL)
93 return;
7fd59977 94
2166f0fa 95 aCView->View->EraseStructure (aStructure);
7fd59977 96}
97
2166f0fa
SK
98void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure)
99{
5e27df78 100 if (!myMapOfStructure.IsBound (theCStructure.Id))
2166f0fa 101 return;
7fd59977 102
5e27df78 103 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
104 myMapOfStructure.UnBind (theCStructure.Id);
eef7fc64 105 Graphic3d_CStructure& aCStruct = const_cast<Graphic3d_CStructure&>(theCStructure);
106 aCStruct.ptrStructure = 0;
5e27df78 107 OpenGl_Element::Destroy (GetSharedContext(), aStructure);
7fd59977 108}
109
2166f0fa
SK
110void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure)
111{
112 RemoveStructure (theCStructure);
7fd59977 113
2166f0fa 114 OpenGl_Structure* aStructure = new OpenGl_Structure();
7fd59977 115
2166f0fa
SK
116 Standard_Integer aStatus = 0;
117 if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
118 if (!theCStructure.visible) aStatus |= OPENGL_NS_HIDE;
2166f0fa 119 aStructure->SetNamedStatus (aStatus);
7fd59977 120
2166f0fa 121 theCStructure.ptrStructure = aStructure;
5e27df78 122 myMapOfStructure.Bind (theCStructure.Id, aStructure);
7fd59977 123}
59f45b7c 124
125//=======================================================================
126//function : ChangeZLayer
127//purpose :
128//=======================================================================
129
130void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
131 const Standard_Integer theLayer)
132{
5e27df78 133 if (!myMapOfStructure.IsBound (theCStructure.Id))
59f45b7c 134 return;
135
5e27df78 136 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 137
138 aStructure->SetZLayer (theLayer);
139}
140
141//=======================================================================
142//function : ChangeZLayer
143//purpose :
144//=======================================================================
145
146void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
147 const Graphic3d_CView& theCView,
148 const Standard_Integer theNewLayerId)
149{
150 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
151
5e27df78 152 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
59f45b7c 153 return;
154
5e27df78 155 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 156
157 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
158}
159
160//=======================================================================
161//function : GetZLayer
162//purpose :
163//=======================================================================
164
165Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
166{
5e27df78 167 if (!myMapOfStructure.IsBound (theCStructure.Id))
59f45b7c 168 return -1;
169
5e27df78 170 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 171
172 return aStructure->GetZLayer();
173}
174
175//=======================================================================
176//function : UnsetZLayer
177//purpose :
178//=======================================================================
179
180void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
181{
5e27df78 182 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
59f45b7c 183 for( ; aStructIt.More (); aStructIt.Next ())
184 {
185 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
186 if (aStruct->GetZLayer () == theLayerId)
187 aStruct->SetZLayer (0);
188 }
189}