summaryrefslogtreecommitdiff
path: root/src/V3d/V3d_View_2.cxx
blob: 0be0395d6d12fa92b3790631f452b977bcb9b866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/***********************************************************************
 
     FONCTION :
     ----------
        Classe V3d_View_2.cxx :
 
     HISTORIQUE DES MODIFICATIONS   :
     --------------------------------
      00-09-92 : GG  ; Creation.
      24-12-97 : FMN ; Suppression de GEOMLITE
      21-02-00 : GG  ; Add Transparency() method
      23-11-00 : GG  ; Add IsActiveLight() and IsActivePlane() methods

************************************************************************/

#define GER61454	//GG 13-09-99 Activates model clipping planes
//		Use myView->PlaneLimit() instead Visual3d_ClipPlane::Limit()
//		Use myView->LightLimit() instead Visual3d_Light::Limit()



/*----------------------------------------------------------------------*/
/*
 * Includes
 */

#include <V3d_View.jxx>
#include <Visual3d_View.hxx>
#include <Visual3d_Light.hxx>
#include <Visual3d_ClipPlane.hxx>
#include <V3d_Static.hxx>
#include <V3d.hxx>

/*----------------------------------------------------------------------*/

void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {

  if( !MyActiveLights.Contains(TheLight)){
#ifdef GER61454
    Viewer_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
			  "too many lights");
#else
//    Viewer_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(),
//			  "too many lights");
#endif
    MyActiveLights.Append(TheLight) ;
    MyViewContext.SetLightOn(TheLight->Light());
    MyView->SetContext(MyViewContext);
  }
}

void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {

  Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
  
  MyActiveLights.Remove(TheLight);
  MyViewContext.SetLightOff(TheLight->Light()) ;
  MyView->SetContext(MyViewContext) ;
}

Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
  if( aLight.IsNull() ) return Standard_False;
  return  MyActiveLights.Contains(aLight);
}

void V3d_View::SetLightOn( ) {

  for(MyViewer->InitDefinedLights();MyViewer->MoreDefinedLights();MyViewer->NextDefinedLights()){
    if(!MyActiveLights.Contains(MyViewer->DefinedLight())){
      MyActiveLights.Append(MyViewer->DefinedLight()) ;
      MyViewContext.SetLightOn(MyViewer->DefinedLight()->Light());
    }
  }
  MyView->SetContext(MyViewContext) ;
  
}

void V3d_View::SetLightOff( ) {
  
  InitActiveLights();
  while(MoreActiveLights()) {
    if (!MyViewer->IsGlobalLight(ActiveLight())) {
      MyActiveLights.Remove(ActiveLight());
      MyViewContext.SetLightOff(ActiveLight()->Light());
    }
    else
      NextActiveLights();
  }
  MyView->SetContext(MyViewContext) ;

}

void V3d_View::SetTransparency(const Standard_Boolean AnActivity) {

  MyTransparencyFlag = AnActivity;
  MyView->SetTransparency(AnActivity);
}


Standard_Boolean V3d_View::Transparency() const {

  return MyTransparencyFlag;
}

void V3d_View::SetPlaneOn( const Handle(V3d_Plane)& ThePlane ) {

#ifdef GER61454
  if( !MyActivePlanes.Contains(ThePlane)) {
    Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= MyView->PlaneLimit(), "too many planes");
    MyActivePlanes.Append(ThePlane) ;
  }
  MyViewContext.SetClipPlaneOn(ThePlane->Plane()) ;
  MyView->SetContext(MyViewContext);
#else 	//GER61454
  if( !MyActivePlanes.Contains(ThePlane)) {
    Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= Visual3d_ClipPlane::Limit(), "too many planes");
    MyActivePlanes.Append(ThePlane) ;
    MyViewContext.SetClipPlaneOn(ThePlane->Plane()) ;
    
    MyView->SetContext(MyViewContext);
  }
#endif	//GER61454
}

void V3d_View::SetPlaneOff( const Handle(V3d_Plane)& ThePlane ) {

  MyActivePlanes.Remove(ThePlane);
  MyViewContext.SetClipPlaneOff(ThePlane->Plane()) ;
  MyView->SetContext(MyViewContext) ;
}

Standard_Boolean V3d_View::IsActivePlane(const Handle(V3d_Plane)& aPlane) const {
  if( aPlane.IsNull() ) return Standard_False;
  return  MyActivePlanes.Contains(aPlane);
}

void V3d_View::SetPlaneOn( ) {

#ifdef GER61454
  for(MyViewer->InitDefinedPlanes();MyViewer->MoreDefinedPlanes();MyViewer->NextDefinedPlanes()) {
    if(!MyActivePlanes.Contains(MyViewer->DefinedPlane())) {
      Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= MyView->PlaneLimit(), "too many planes");
      MyActivePlanes.Append(MyViewer->DefinedPlane());
    }
    MyViewContext.SetClipPlaneOn(MyViewer->DefinedPlane()->Plane());
  }
  MyView->SetContext(MyViewContext) ;
#else	//GER61454
  for(MyViewer->InitDefinedPlanes();MyViewer->MoreDefinedPlanes();MyViewer->NextDefinedPlanes()) {
    if(!MyActivePlanes.Contains(MyViewer->DefinedPlane())) {
      Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >=  Visual3d_ClipPlane::Limit(),
			    "too many planes");
      MyActivePlanes.Append(MyViewer->DefinedPlane());
      MyViewContext.SetClipPlaneOn(MyViewer->DefinedPlane()->Plane());
      MyView->SetContext(MyViewContext) ;
    }
  }
#endif	//GER61454
}

void V3d_View::SetPlaneOff( ) {

  for(InitActivePlanes();MoreActivePlanes();NextActivePlanes()) {
    MyViewContext.SetClipPlaneOff(ActivePlane()->Plane());}
  MyActivePlanes.Clear();
  MyView->SetContext(MyViewContext) ;
}

void V3d_View::InitActiveLights() {
myActiveLightsIterator.Initialize(MyActiveLights);
}
Standard_Boolean V3d_View::MoreActiveLights () const {
  return myActiveLightsIterator.More();
}
void V3d_View::NextActiveLights () {
  myActiveLightsIterator.Next();
}
Handle(V3d_Light) V3d_View::ActiveLight() const {
  return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}


void V3d_View::InitActivePlanes() {
myActivePlanesIterator.Initialize(MyActivePlanes);
}
Standard_Boolean V3d_View::MoreActivePlanes () const {
  return myActivePlanesIterator.More();
}
void V3d_View::NextActivePlanes () {
  myActivePlanesIterator.Next();
}

Handle(V3d_Plane) V3d_View::ActivePlane() const {
  return (Handle(V3d_Plane)&)(myActivePlanesIterator.Value());}

Standard_Boolean V3d_View::IfMorePlanes() const {

#ifdef GER61454
        return MyActivePlanes.Extent() < MyView->PlaneLimit();
#else
  	return MyActivePlanes.Extent() < Visual3d_ClipPlane::Limit();
#endif

}

Standard_Boolean V3d_View::IfMoreLights() const {

#ifdef GER61454
        return MyActiveLights.Extent() < MyView->LightLimit();
#else
//	return MyActiveLights.Extent() < Visual3d_Light::Limit();
	return MyActiveLights.Extent();
#endif
}