0023488: Make video recording functionality (OpenGl_AVIWriter) optional
[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
SK
34 InvalidateAllWorkspaces();
35}
7fd59977 36
2166f0fa
SK
37void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStructure)
38{
39 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
40 if (aStructure == NULL)
41 return;
7fd59977 42
2166f0fa 43 aStructure->SetTransformPersistence (theCStructure.TransformPersistence);
7fd59977 44
2166f0fa
SK
45 if (theCStructure.ContextLine.IsDef)
46 aStructure->SetAspectLine (theCStructure.ContextLine);
7fd59977 47
2166f0fa
SK
48 if (theCStructure.ContextFillArea.IsDef)
49 aStructure->SetAspectFace (theCStructure.ContextFillArea);
7fd59977 50
2166f0fa
SK
51 if (theCStructure.ContextMarker.IsDef)
52 aStructure->SetAspectMarker (theCStructure.ContextMarker);
7fd59977 53
2166f0fa
SK
54 if (theCStructure.ContextText.IsDef)
55 aStructure->SetAspectText (theCStructure.ContextText);
7fd59977 56
2166f0fa 57 InvalidateAllWorkspaces();
7fd59977 58}
59
2166f0fa
SK
60void OpenGl_GraphicDriver::Connect (const Graphic3d_CStructure& theFather,
61 const Graphic3d_CStructure& theSon)
62{
63 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
64 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
65 if (aFather && aSon)
66 aFather->Connect(aSon);
7fd59977 67}
68
2166f0fa
SK
69void OpenGl_GraphicDriver::Disconnect (const Graphic3d_CStructure& theFather,
70 const Graphic3d_CStructure& theSon)
71{
72 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
73 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
74 if (aFather && aSon)
75 aFather->Disconnect(aSon);
7fd59977 76}
77
2166f0fa
SK
78void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView,
79 const Graphic3d_CStructure& theCStructure,
80 const Standard_Integer thePriority)
81{
82 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
83 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
84 if (aCView == NULL || aStructure == NULL)
85 return;
86
87 aCView->View->DisplayStructure (aStructure, thePriority);
7fd59977 88}
89
2166f0fa
SK
90void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
91 const Graphic3d_CStructure& theCStructure)
92{
93 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
94 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
95 if (aCView == NULL || aStructure == NULL)
96 return;
7fd59977 97
2166f0fa 98 aCView->View->EraseStructure (aStructure);
7fd59977 99}
100
2166f0fa
SK
101void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure)
102{
5e27df78 103 if (!myMapOfStructure.IsBound (theCStructure.Id))
2166f0fa 104 return;
7fd59977 105
5e27df78 106 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
107 myMapOfStructure.UnBind (theCStructure.Id);
108 OpenGl_Element::Destroy (GetSharedContext(), aStructure);
2166f0fa 109 InvalidateAllWorkspaces();
7fd59977 110}
111
2166f0fa
SK
112void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure)
113{
114 RemoveStructure (theCStructure);
7fd59977 115
2166f0fa 116 OpenGl_Structure* aStructure = new OpenGl_Structure();
7fd59977 117
2166f0fa
SK
118 aStructure->SetDegenerateModel (theCStructure.ContextFillArea.DegenerationMode,
119 theCStructure.ContextFillArea.SkipRatio);
7fd59977 120
2166f0fa
SK
121 Standard_Integer aStatus = 0;
122 if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
123 if (!theCStructure.visible) aStatus |= OPENGL_NS_HIDE;
2166f0fa 124 aStructure->SetNamedStatus (aStatus);
7fd59977 125
2166f0fa 126 theCStructure.ptrStructure = aStructure;
5e27df78 127 myMapOfStructure.Bind (theCStructure.Id, aStructure);
2166f0fa 128 InvalidateAllWorkspaces();
7fd59977 129}
59f45b7c 130
131//=======================================================================
132//function : ChangeZLayer
133//purpose :
134//=======================================================================
135
136void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
137 const Standard_Integer theLayer)
138{
5e27df78 139 if (!myMapOfStructure.IsBound (theCStructure.Id))
59f45b7c 140 return;
141
5e27df78 142 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 143
144 aStructure->SetZLayer (theLayer);
145}
146
147//=======================================================================
148//function : ChangeZLayer
149//purpose :
150//=======================================================================
151
152void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
153 const Graphic3d_CView& theCView,
154 const Standard_Integer theNewLayerId)
155{
156 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
157
5e27df78 158 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
59f45b7c 159 return;
160
5e27df78 161 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 162
163 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
164}
165
166//=======================================================================
167//function : GetZLayer
168//purpose :
169//=======================================================================
170
171Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
172{
5e27df78 173 if (!myMapOfStructure.IsBound (theCStructure.Id))
59f45b7c 174 return -1;
175
5e27df78 176 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
59f45b7c 177
178 return aStructure->GetZLayer();
179}
180
181//=======================================================================
182//function : UnsetZLayer
183//purpose :
184//=======================================================================
185
186void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
187{
5e27df78 188 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
59f45b7c 189 for( ; aStructIt.More (); aStructIt.Next ())
190 {
191 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
192 if (aStruct->GetZLayer () == theLayerId)
193 aStruct->SetZLayer (0);
194 }
195}