1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Aspect_Background.hxx>
16 #include <Aspect_GradientBackground.hxx>
17 #include <Aspect_Grid.hxx>
19 #include <Graphic3d_AspectMarker3d.hxx>
20 #include <Graphic3d_GraphicDriver.hxx>
21 #include <Graphic3d_Group.hxx>
22 #include <Graphic3d_Structure.hxx>
23 #include <Quantity_Color.hxx>
25 #include <V3d_AmbientLight.hxx>
26 #include <V3d_BadValue.hxx>
27 #include <V3d_CircularGrid.hxx>
28 #include <V3d_DirectionalLight.hxx>
29 #include <V3d_Light.hxx>
30 #include <V3d_PositionalLight.hxx>
31 #include <V3d_RectangularGrid.hxx>
32 #include <V3d_View.hxx>
33 #include <V3d_Viewer.hxx>
35 void V3d_Viewer::UpdateLights() {
37 for (InitActiveViews();MoreActiveViews();NextActiveViews()){
38 ActiveView()->UpdateLights();
42 void V3d_Viewer::SetLightOn( const Handle(V3d_Light)& TheLight ) {
45 if(!MyActiveLights.Contains(TheLight)) {
46 // V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyDriver->InquireLightLimit(),
47 // "too many lights");
48 MyActiveLights.Append(TheLight) ;
51 for (InitActiveViews();MoreActiveViews();NextActiveViews()){
52 ActiveView()->SetLightOn(TheLight);}
55 void V3d_Viewer::SetLightOff( const Handle(V3d_Light)& TheLight ) {
57 MyActiveLights.Remove(TheLight);
58 for (InitActiveViews();MoreActiveViews();NextActiveViews()) {
59 ActiveView()->SetLightOff(TheLight);}
63 void V3d_Viewer::SetLightOn() {
65 for (InitDefinedLights();MoreDefinedLights();NextDefinedLights()) {
66 if(!MyActiveLights.Contains(DefinedLight())) {
67 // V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyDriver->InquireLightLimit(),
68 // "too many lights");
69 MyActiveLights.Append(DefinedLight());
70 for (InitActiveViews();MoreActiveViews();NextActiveViews()) {
71 ActiveView()->SetLightOn(DefinedLight());}
76 void V3d_Viewer::SetLightOff() {
78 for (InitActiveLights();MoreActiveLights();NextActiveLights()) {
79 for(InitActiveViews();MoreActiveViews();NextActiveViews()){
80 ActiveView()->SetLightOff(ActiveLight());}
82 MyActiveLights.Clear();
85 void V3d_Viewer::SetCurrentSelectedLight(const Handle(V3d_Light)& TheLight) {
86 MyCurrentSelectedLight = TheLight;
89 void V3d_Viewer::ClearCurrentSelectedLight() {
90 MyCurrentSelectedLight.Nullify();
94 Handle(V3d_Light) V3d_Viewer::CurrentSelectedLight() const {
96 return MyCurrentSelectedLight;
99 Standard_Boolean V3d_Viewer::IsGlobalLight(const Handle(V3d_Light)& TheLight)
102 return MyActiveLights.Contains(TheLight);
106 void V3d_Viewer::AddLight( const Handle(V3d_Light)& TheLight ) {
108 MyDefinedLights.Append(TheLight);
111 void V3d_Viewer::DelLight( const Handle(V3d_Light)& TheLight ) {
113 SetLightOff(TheLight);
114 MyDefinedLights.Remove(TheLight);
117 void V3d_Viewer::SetDefaultLights()
119 while (MyDefinedLights.Extent() > 0)
121 DelLight (Handle(V3d_Light)::DownCast (MyDefinedLights.First()));
124 SetLightOn (new V3d_DirectionalLight (this, V3d_Zneg, Quantity_NOC_WHITE, Standard_True));
125 SetLightOn (new V3d_AmbientLight (this));