0023186: Unable to display Graphic3d_ArrayOfPoints after migrating from OCCT 6.5.2
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_8.cxx
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
20
21 #include <OpenGl_GraphicDriver.hxx>
22
23 #include <OpenGl_CView.hxx>
24 #include <OpenGl_Structure.hxx>
25
26 static Handle(OpenGl_Workspace) myImmediateWS;
27
28 /*----------------------------------------------------------------------*/
29
30 Standard_Boolean OpenGl_GraphicDriver::BeginAddMode (const Graphic3d_CView& ACView)
31 {
32   if (ACView.ViewId == -1)
33     return Standard_False;
34
35   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
36   if (aCView && aCView->WS->BeginAddMode())
37   {
38     myImmediateWS = aCView->WS;
39     return Standard_True;
40   }
41
42   return Standard_False;
43 }
44
45 void OpenGl_GraphicDriver::EndAddMode (void)
46 {
47   if (!myImmediateWS.IsNull())
48   {
49     myImmediateWS->EndAddMode();
50     myImmediateWS.Nullify();
51   }
52 }
53
54 Standard_Boolean OpenGl_GraphicDriver::BeginImmediatMode (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer, const Standard_Boolean DoubleBuffer, const Standard_Boolean RetainMode)
55 {
56   if (ACView.ViewId == -1)
57     return Standard_False;
58
59   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
60   if (aCView && aCView->WS->BeginImmediatMode(ACView, DoubleBuffer, RetainMode))
61   {
62     myImmediateWS = aCView->WS;
63     return Standard_True;
64   }
65
66   return Standard_False;
67 }
68
69 void OpenGl_GraphicDriver::BeginPolyline ()
70 {
71   if (!myImmediateWS.IsNull())
72     myImmediateWS->BeginPolyline();
73 }
74
75 void OpenGl_GraphicDriver::ClearImmediatMode (const Graphic3d_CView& ACView, const Standard_Boolean aFlush)
76 {
77   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
78   if (aCView)
79     aCView->WS->ClearImmediatMode(ACView,aFlush);
80 }
81
82 void OpenGl_GraphicDriver::Draw (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z)
83 {
84   if (!myImmediateWS.IsNull())
85     myImmediateWS->Draw(X,Y,Z);
86 }
87
88 void OpenGl_GraphicDriver::DrawStructure (const Graphic3d_CStructure& ACStructure)
89 {
90   OpenGl_Structure *astructure = (OpenGl_Structure *)ACStructure.ptrStructure;
91   if (!astructure)
92     return;
93
94   if (!myImmediateWS.IsNull())
95     myImmediateWS->DrawStructure(astructure);
96 }
97
98 void OpenGl_GraphicDriver::EndImmediatMode (const Standard_Integer Synchronize)
99 {
100   if (!myImmediateWS.IsNull())
101   {
102     myImmediateWS->EndImmediatMode();
103     myImmediateWS.Nullify();
104   }
105 }
106
107 void OpenGl_GraphicDriver::EndPolyline ()
108 {
109   if (!myImmediateWS.IsNull())
110     myImmediateWS->EndPolyline();
111 }
112
113 void OpenGl_GraphicDriver::Move (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z)
114 {
115   if (!myImmediateWS.IsNull())
116     myImmediateWS->Move(X,Y,Z);
117 }
118
119 void OpenGl_GraphicDriver::SetLineColor (const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B)
120 {
121   if (!myImmediateWS.IsNull())
122     myImmediateWS->SetLineColor(R,G,B);
123 }
124
125 void OpenGl_GraphicDriver::SetLineType (const Standard_Integer Type)
126 {
127   if (!myImmediateWS.IsNull())
128     myImmediateWS->SetLineType(Type);
129 }
130
131 void OpenGl_GraphicDriver::SetLineWidth (const Standard_ShortReal Width)
132 {
133   if (!myImmediateWS.IsNull())
134     myImmediateWS->SetLineWidth(Width);
135 }
136
137 void OpenGl_GraphicDriver::SetMinMax (const Standard_ShortReal X1, const Standard_ShortReal Y1, const Standard_ShortReal Z1, const Standard_ShortReal X2, const Standard_ShortReal Y2, const Standard_ShortReal Z2)
138 {
139   if (!myImmediateWS.IsNull())
140     myImmediateWS->SetMinMax(X1,Y1,Z1,X2,Y2,Z2);
141 }
142
143 void OpenGl_GraphicDriver::Transform (const TColStd_Array2OfReal& AMatrix, const Graphic3d_TypeOfComposition AType)
144 {
145   if (!myImmediateWS.IsNull())
146     myImmediateWS->Transform(AMatrix,AType);
147 }