b311480e |
1 | // Created on: 1997-01-28 |
2 | // Created by: CAL |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
42cf5bc1 |
17 | #include <Graphic3d_GraphicDriver.hxx> |
7fd59977 |
18 | |
1c728f2d |
19 | #include <Graphic3d_Layer.hxx> |
20 | |
25e59720 |
21 | IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient) |
92efcf78 |
22 | |
6146a808 |
23 | // ======================================================================= |
24 | // function : Graphic3d_GraphicDriver |
25 | // purpose : |
26 | // ======================================================================= |
fe9fc669 |
27 | Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp) |
851dacdb |
28 | : myDisplayConnection (theDisp) |
fe9fc669 |
29 | { |
1c728f2d |
30 | // default layers are always presented in display layer sequence and cannot be removed |
d325cb7f |
31 | { |
32 | Graphic3d_ZLayerSettings aSettings; |
1c728f2d |
33 | aSettings.SetName ("UNDERLAY"); |
d325cb7f |
34 | aSettings.SetImmediate (Standard_False); |
1c728f2d |
35 | aSettings.SetRaytracable (Standard_False); |
d325cb7f |
36 | aSettings.SetEnvironmentTexture (Standard_False); |
37 | aSettings.SetEnableDepthTest (Standard_False); |
38 | aSettings.SetEnableDepthWrite (Standard_False); |
39 | aSettings.SetClearDepth (Standard_False); |
40 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); |
1c728f2d |
41 | Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_BotOSD, 1, Handle(Select3D_BVHBuilder3d)()); |
42 | aLayer->SetLayerSettings (aSettings); |
43 | myLayers.Append (aLayer); |
44 | myLayerIds.Bind (aLayer->LayerId(), aLayer); |
d325cb7f |
45 | } |
46 | |
47 | { |
48 | Graphic3d_ZLayerSettings aSettings; |
1c728f2d |
49 | aSettings.SetName ("DEFAULT"); |
d325cb7f |
50 | aSettings.SetImmediate (Standard_False); |
1c728f2d |
51 | aSettings.SetRaytracable (Standard_True); |
d325cb7f |
52 | aSettings.SetEnvironmentTexture (Standard_True); |
53 | aSettings.SetEnableDepthTest (Standard_True); |
54 | aSettings.SetEnableDepthWrite (Standard_True); |
55 | aSettings.SetClearDepth (Standard_False); |
56 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); |
1c728f2d |
57 | Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_Default, 1, Handle(Select3D_BVHBuilder3d)()); |
58 | aLayer->SetLayerSettings (aSettings); |
59 | myLayers.Append (aLayer); |
60 | myLayerIds.Bind (aLayer->LayerId(), aLayer); |
d325cb7f |
61 | } |
62 | |
63 | { |
64 | Graphic3d_ZLayerSettings aSettings; |
1c728f2d |
65 | aSettings.SetName ("TOP"); |
d325cb7f |
66 | aSettings.SetImmediate (Standard_True); |
1c728f2d |
67 | aSettings.SetRaytracable (Standard_False); |
d325cb7f |
68 | aSettings.SetEnvironmentTexture (Standard_True); |
69 | aSettings.SetEnableDepthTest (Standard_True); |
70 | aSettings.SetEnableDepthWrite (Standard_True); |
71 | aSettings.SetClearDepth (Standard_False); |
72 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); |
1c728f2d |
73 | Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_Top, 1, Handle(Select3D_BVHBuilder3d)()); |
74 | aLayer->SetLayerSettings (aSettings); |
75 | myLayers.Append (aLayer); |
76 | myLayerIds.Bind (aLayer->LayerId(), aLayer); |
d325cb7f |
77 | } |
78 | |
79 | { |
80 | Graphic3d_ZLayerSettings aSettings; |
1c728f2d |
81 | aSettings.SetName ("TOPMOST"); |
d325cb7f |
82 | aSettings.SetImmediate (Standard_True); |
1c728f2d |
83 | aSettings.SetRaytracable (Standard_False); |
d325cb7f |
84 | aSettings.SetEnvironmentTexture (Standard_True); |
85 | aSettings.SetEnableDepthTest (Standard_True); |
86 | aSettings.SetEnableDepthWrite (Standard_True); |
87 | aSettings.SetClearDepth (Standard_True); |
88 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); |
1c728f2d |
89 | Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_Topmost, 1, Handle(Select3D_BVHBuilder3d)()); |
90 | aLayer->SetLayerSettings (aSettings); |
91 | myLayers.Append (aLayer); |
92 | myLayerIds.Bind (aLayer->LayerId(), aLayer); |
d325cb7f |
93 | } |
94 | |
95 | { |
96 | Graphic3d_ZLayerSettings aSettings; |
1c728f2d |
97 | aSettings.SetName ("OVERLAY"); |
d325cb7f |
98 | aSettings.SetImmediate (Standard_True); |
1c728f2d |
99 | aSettings.SetRaytracable (Standard_False); |
d325cb7f |
100 | aSettings.SetEnvironmentTexture (Standard_False); |
101 | aSettings.SetEnableDepthTest (Standard_False); |
102 | aSettings.SetEnableDepthWrite (Standard_False); |
103 | aSettings.SetClearDepth (Standard_False); |
104 | aSettings.SetPolygonOffset (Graphic3d_PolygonOffset()); |
1c728f2d |
105 | Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_TopOSD, 1, Handle(Select3D_BVHBuilder3d)()); |
106 | aLayer->SetLayerSettings (aSettings); |
107 | myLayers.Append (aLayer); |
108 | myLayerIds.Bind (aLayer->LayerId(), aLayer); |
d325cb7f |
109 | } |
7fd59977 |
110 | } |
111 | |
6146a808 |
112 | // ======================================================================= |
113 | // function : GetDisplayConnection |
114 | // purpose : |
115 | // ======================================================================= |
dc3fe572 |
116 | const Handle(Aspect_DisplayConnection)& Graphic3d_GraphicDriver::GetDisplayConnection() const |
117 | { |
118 | return myDisplayConnection; |
119 | } |
eb4320f2 |
120 | |
016e5959 |
121 | // ======================================================================= |
122 | // function : NewIdentification |
123 | // purpose : |
124 | // ======================================================================= |
125 | Standard_Integer Graphic3d_GraphicDriver::NewIdentification() |
126 | { |
127 | return myStructGenId.Next(); |
128 | } |
129 | |
130 | // ======================================================================= |
131 | // function : RemoveIdentification |
132 | // purpose : |
133 | // ======================================================================= |
134 | void Graphic3d_GraphicDriver::RemoveIdentification(const Standard_Integer theId) |
135 | { |
136 | myStructGenId.Free(theId); |
d325cb7f |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : ZLayerSettings |
141 | //purpose : |
142 | //======================================================================= |
143 | const Graphic3d_ZLayerSettings& Graphic3d_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const |
144 | { |
1c728f2d |
145 | const Handle(Graphic3d_Layer)* aLayer = myLayerIds.Seek (theLayerId); |
146 | if (aLayer == NULL) |
147 | { |
148 | throw Standard_OutOfRange ("Graphic3d_GraphicDriver::ZLayerSettings, Layer with theLayerId does not exist"); |
149 | } |
150 | return (*aLayer)->LayerSettings(); |
d325cb7f |
151 | } |
152 | |
153 | //======================================================================= |
1c728f2d |
154 | //function : ZLayers |
d325cb7f |
155 | //purpose : |
156 | //======================================================================= |
1c728f2d |
157 | void Graphic3d_GraphicDriver::ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const |
d325cb7f |
158 | { |
1c728f2d |
159 | theLayerSeq.Clear(); |
160 | |
161 | // append normal layers |
162 | for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next()) |
d325cb7f |
163 | { |
1c728f2d |
164 | const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value(); |
165 | if (!aLayer->IsImmediate()) |
d325cb7f |
166 | { |
1c728f2d |
167 | theLayerSeq.Append (aLayer->LayerId()); |
d325cb7f |
168 | } |
169 | } |
170 | |
1c728f2d |
171 | // append immediate layers |
172 | for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next()) |
d325cb7f |
173 | { |
1c728f2d |
174 | const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value(); |
175 | if (aLayer->IsImmediate()) |
176 | { |
177 | theLayerSeq.Append (aLayer->LayerId()); |
178 | } |
d325cb7f |
179 | } |
1c728f2d |
180 | } |
d325cb7f |
181 | |
1c728f2d |
182 | //======================================================================= |
183 | //function : InsertLayerBefore |
184 | //purpose : |
185 | //======================================================================= |
186 | void Graphic3d_GraphicDriver::InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId, |
187 | const Graphic3d_ZLayerSettings& theSettings, |
188 | const Graphic3d_ZLayerId theLayerAfter) |
189 | { |
190 | Standard_ASSERT_RAISE (theNewLayerId > 0, |
191 | "Graphic3d_GraphicDriver::InsertLayerBefore, negative and zero IDs are reserved"); |
192 | Standard_ASSERT_RAISE (!myLayerIds.IsBound (theNewLayerId), |
193 | "Graphic3d_GraphicDriver::InsertLayerBefore, Layer with theLayerId already exists"); |
194 | |
195 | Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, 1, Handle(Select3D_BVHBuilder3d)()); |
196 | aNewLayer->SetLayerSettings (theSettings); |
197 | |
198 | Handle(Graphic3d_Layer) anOtherLayer; |
199 | if (theLayerAfter != Graphic3d_ZLayerId_UNKNOWN |
200 | && myLayerIds.Find (theLayerAfter, anOtherLayer)) |
d325cb7f |
201 | { |
1c728f2d |
202 | for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next()) |
d325cb7f |
203 | { |
1c728f2d |
204 | if (aLayerIter.Value() == anOtherLayer) |
d325cb7f |
205 | { |
1c728f2d |
206 | myLayers.InsertBefore (aNewLayer, aLayerIter); |
207 | break; |
d325cb7f |
208 | } |
d325cb7f |
209 | } |
210 | } |
1c728f2d |
211 | else |
212 | { |
213 | myLayers.Prepend (aNewLayer); |
214 | } |
215 | myLayerIds.Bind (theNewLayerId, aNewLayer); |
d325cb7f |
216 | } |
217 | |
218 | //======================================================================= |
1c728f2d |
219 | //function : InsertLayerAfter |
d325cb7f |
220 | //purpose : |
221 | //======================================================================= |
1c728f2d |
222 | void Graphic3d_GraphicDriver::InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId, |
223 | const Graphic3d_ZLayerSettings& theSettings, |
224 | const Graphic3d_ZLayerId theLayerBefore) |
d325cb7f |
225 | { |
1c728f2d |
226 | Standard_ASSERT_RAISE (theNewLayerId > 0, |
227 | "Graphic3d_GraphicDriver::InsertLayerAfter, negative and zero IDs are reserved"); |
228 | Standard_ASSERT_RAISE (!myLayerIds.IsBound (theNewLayerId), |
229 | "Graphic3d_GraphicDriver::InsertLayerAfter, Layer with theLayerId already exists"); |
230 | |
231 | Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, 1, Handle(Select3D_BVHBuilder3d)()); |
232 | aNewLayer->SetLayerSettings (theSettings); |
233 | |
234 | Handle(Graphic3d_Layer) anOtherLayer; |
235 | if (theLayerBefore != Graphic3d_ZLayerId_UNKNOWN |
236 | && myLayerIds.Find (theLayerBefore, anOtherLayer)) |
d325cb7f |
237 | { |
1c728f2d |
238 | for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next()) |
d325cb7f |
239 | { |
1c728f2d |
240 | if (aLayerIter.Value() == anOtherLayer) |
241 | { |
242 | myLayers.InsertAfter (aNewLayer, aLayerIter); |
243 | break; |
244 | } |
d325cb7f |
245 | } |
246 | } |
247 | else |
248 | { |
1c728f2d |
249 | myLayers.Append (aNewLayer); |
d325cb7f |
250 | } |
1c728f2d |
251 | myLayerIds.Bind (theNewLayerId, aNewLayer); |
252 | } |
253 | |
254 | //======================================================================= |
255 | //function : RemoveZLayer |
256 | //purpose : |
257 | //======================================================================= |
258 | void Graphic3d_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId) |
259 | { |
260 | Standard_ASSERT_RAISE (theLayerId > 0, |
261 | "Graphic3d_GraphicDriver::RemoveZLayer, negative and zero IDs are reserved and cannot be removed"); |
262 | |
263 | Handle(Graphic3d_Layer) aLayerDef; |
264 | myLayerIds.Find (theLayerId, aLayerDef); |
265 | Standard_ASSERT_RAISE (!aLayerDef.IsNull(), |
266 | "Graphic3d_GraphicDriver::RemoveZLayer, Layer with theLayerId does not exist"); |
267 | myLayers.Remove (aLayerDef); |
268 | myLayerIds.UnBind (theLayerId); |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : SetZLayerSettings |
273 | //purpose : |
274 | //======================================================================= |
275 | void Graphic3d_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, |
276 | const Graphic3d_ZLayerSettings& theSettings) |
277 | { |
278 | Handle(Graphic3d_Layer) aLayerDef; |
279 | myLayerIds.Find (theLayerId, aLayerDef); |
280 | Standard_ASSERT_RAISE (!aLayerDef.IsNull(), |
281 | "Graphic3d_GraphicDriver::SetZLayerSettings, Layer with theLayerId does not exist"); |
282 | aLayerDef->SetLayerSettings (theSettings); |
d325cb7f |
283 | } |