0027900: Coding rules - drop redundant Name parameter from V3d_Viewer constructor
[occt.git] / src / V3d / V3d_Viewer_2.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <Aspect_Background.hxx>
16 #include <Aspect_GradientBackground.hxx>
17 #include <Aspect_Grid.hxx>
18 #include <gp_Ax3.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>
24 #include <V3d.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>
34
35 void V3d_Viewer::UpdateLights() {
36
37   for (InitActiveViews();MoreActiveViews();NextActiveViews()){
38     ActiveView()->UpdateLights();
39   }
40 }
41
42 void V3d_Viewer::SetLightOn( const Handle(V3d_Light)& TheLight ) {
43
44
45   if(!MyActiveLights.Contains(TheLight)) {
46 //    V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyDriver->InquireLightLimit(),
47 //                               "too many lights");
48       MyActiveLights.Append(TheLight) ;
49   }
50   
51   for (InitActiveViews();MoreActiveViews();NextActiveViews()){
52     ActiveView()->SetLightOn(TheLight);}
53 }
54
55 void V3d_Viewer::SetLightOff( const Handle(V3d_Light)& TheLight ) {
56
57   MyActiveLights.Remove(TheLight);
58   for (InitActiveViews();MoreActiveViews();NextActiveViews()) {
59     ActiveView()->SetLightOff(TheLight);}
60 }
61
62
63 void V3d_Viewer::SetLightOn() {
64
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());}
72     }
73   }
74 }
75
76 void V3d_Viewer::SetLightOff() {
77
78   for (InitActiveLights();MoreActiveLights();NextActiveLights()) {
79     for(InitActiveViews();MoreActiveViews();NextActiveViews()){
80       ActiveView()->SetLightOff(ActiveLight());}
81   }
82   MyActiveLights.Clear();
83 }
84
85 void V3d_Viewer::SetCurrentSelectedLight(const Handle(V3d_Light)& TheLight) {
86   MyCurrentSelectedLight = TheLight;
87 }
88
89 void V3d_Viewer::ClearCurrentSelectedLight() {
90   MyCurrentSelectedLight.Nullify();
91 }
92
93
94 Handle(V3d_Light) V3d_Viewer::CurrentSelectedLight() const {
95
96   return MyCurrentSelectedLight;
97 }
98
99 Standard_Boolean V3d_Viewer::IsGlobalLight(const Handle(V3d_Light)& TheLight)
100  const {
101
102    return MyActiveLights.Contains(TheLight);
103 }
104
105
106 void V3d_Viewer::AddLight( const Handle(V3d_Light)& TheLight )  {
107
108   MyDefinedLights.Append(TheLight);
109 }
110   
111 void V3d_Viewer::DelLight( const Handle(V3d_Light)& TheLight ) {
112     
113   SetLightOff(TheLight);   
114   MyDefinedLights.Remove(TheLight);
115 }
116
117 void V3d_Viewer::SetDefaultLights()
118 {
119   while (MyDefinedLights.Extent() > 0)
120   {
121     DelLight (Handle(V3d_Light)::DownCast (MyDefinedLights.First()));
122   }
123
124   SetLightOn (new V3d_DirectionalLight (this, V3d_Zneg, Quantity_NOC_WHITE, Standard_True));
125   SetLightOn (new V3d_AmbientLight (this));
126 }