1 // Created on: 1997-01-28
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Graphic3d_GraphicDriver.hxx>
19 #include <Graphic3d_Layer.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient)
23 // =======================================================================
24 // function : Graphic3d_GraphicDriver
26 // =======================================================================
27 Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp)
28 : myDisplayConnection (theDisp)
30 // default layers are always presented in display layer sequence and cannot be removed
32 Graphic3d_ZLayerSettings aSettings;
33 aSettings.SetName ("UNDERLAY");
34 aSettings.SetImmediate (Standard_False);
35 aSettings.SetRaytracable (Standard_False);
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());
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);
48 Graphic3d_ZLayerSettings aSettings;
49 aSettings.SetName ("DEFAULT");
50 aSettings.SetImmediate (Standard_False);
51 aSettings.SetRaytracable (Standard_True);
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());
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);
64 Graphic3d_ZLayerSettings aSettings;
65 aSettings.SetName ("TOP");
66 aSettings.SetImmediate (Standard_True);
67 aSettings.SetRaytracable (Standard_False);
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());
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);
80 Graphic3d_ZLayerSettings aSettings;
81 aSettings.SetName ("TOPMOST");
82 aSettings.SetImmediate (Standard_True);
83 aSettings.SetRaytracable (Standard_False);
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());
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);
96 Graphic3d_ZLayerSettings aSettings;
97 aSettings.SetName ("OVERLAY");
98 aSettings.SetImmediate (Standard_True);
99 aSettings.SetRaytracable (Standard_False);
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());
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);
112 // =======================================================================
113 // function : GetDisplayConnection
115 // =======================================================================
116 const Handle(Aspect_DisplayConnection)& Graphic3d_GraphicDriver::GetDisplayConnection() const
118 return myDisplayConnection;
121 // =======================================================================
122 // function : NewIdentification
124 // =======================================================================
125 Standard_Integer Graphic3d_GraphicDriver::NewIdentification()
127 return myStructGenId.Next();
130 // =======================================================================
131 // function : RemoveIdentification
133 // =======================================================================
134 void Graphic3d_GraphicDriver::RemoveIdentification(const Standard_Integer theId)
136 myStructGenId.Free(theId);
139 //=======================================================================
140 //function : ZLayerSettings
142 //=======================================================================
143 const Graphic3d_ZLayerSettings& Graphic3d_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
145 const Handle(Graphic3d_Layer)* aLayer = myLayerIds.Seek (theLayerId);
148 throw Standard_OutOfRange ("Graphic3d_GraphicDriver::ZLayerSettings, Layer with theLayerId does not exist");
150 return (*aLayer)->LayerSettings();
153 //=======================================================================
156 //=======================================================================
157 void Graphic3d_GraphicDriver::ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
161 // append normal layers
162 for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
164 const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
165 if (!aLayer->IsImmediate())
167 theLayerSeq.Append (aLayer->LayerId());
171 // append immediate layers
172 for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
174 const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
175 if (aLayer->IsImmediate())
177 theLayerSeq.Append (aLayer->LayerId());
182 //=======================================================================
183 //function : InsertLayerBefore
185 //=======================================================================
186 void Graphic3d_GraphicDriver::InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
187 const Graphic3d_ZLayerSettings& theSettings,
188 const Graphic3d_ZLayerId theLayerAfter)
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");
195 Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, 1, Handle(Select3D_BVHBuilder3d)());
196 aNewLayer->SetLayerSettings (theSettings);
198 Handle(Graphic3d_Layer) anOtherLayer;
199 if (theLayerAfter != Graphic3d_ZLayerId_UNKNOWN
200 && myLayerIds.Find (theLayerAfter, anOtherLayer))
202 for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
204 if (aLayerIter.Value() == anOtherLayer)
206 myLayers.InsertBefore (aNewLayer, aLayerIter);
213 myLayers.Prepend (aNewLayer);
215 myLayerIds.Bind (theNewLayerId, aNewLayer);
218 //=======================================================================
219 //function : InsertLayerAfter
221 //=======================================================================
222 void Graphic3d_GraphicDriver::InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
223 const Graphic3d_ZLayerSettings& theSettings,
224 const Graphic3d_ZLayerId theLayerBefore)
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");
231 Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, 1, Handle(Select3D_BVHBuilder3d)());
232 aNewLayer->SetLayerSettings (theSettings);
234 Handle(Graphic3d_Layer) anOtherLayer;
235 if (theLayerBefore != Graphic3d_ZLayerId_UNKNOWN
236 && myLayerIds.Find (theLayerBefore, anOtherLayer))
238 for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
240 if (aLayerIter.Value() == anOtherLayer)
242 myLayers.InsertAfter (aNewLayer, aLayerIter);
249 myLayers.Append (aNewLayer);
251 myLayerIds.Bind (theNewLayerId, aNewLayer);
254 //=======================================================================
255 //function : RemoveZLayer
257 //=======================================================================
258 void Graphic3d_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
260 Standard_ASSERT_RAISE (theLayerId > 0,
261 "Graphic3d_GraphicDriver::RemoveZLayer, negative and zero IDs are reserved and cannot be removed");
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);
271 //=======================================================================
272 //function : SetZLayerSettings
274 //=======================================================================
275 void Graphic3d_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
276 const Graphic3d_ZLayerSettings& theSettings)
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);
285 // =======================================================================
286 // function : DumpJson
288 // =======================================================================
289 void Graphic3d_GraphicDriver::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
291 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
293 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myStructGenId)
295 for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator anIter (myLayers); anIter.More(); anIter.Next())
297 const Handle(Graphic3d_Layer)& aLayer = anIter.Value();
298 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aLayer.get())