summaryrefslogtreecommitdiff
path: root/src/V3d/V3d_Viewer.cxx
blob: 42318edc1031f2132541247ad4bbaa390bc7bc3e (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/***********************************************************************
 
     FONCTION :
     ----------
        Classe V3d_Viewer :
 
     HISTORIQUE DES MODIFICATIONS   :
     --------------------------------
      00-09-92 : GG  ; Creation.
      15-11-97 : FMN ; Ajout texture mapping
      02-02-98 : FMN ; Mise a niveau WNT
      23-02-98 : FMN ; Remplacement PI par Standard_PI
      16-07-98 : CAL ; S3892. Ajout grilles 3d.

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

#define GER61351	//GG_15/12/99 Adds SetDefaultBackgroundColor()
//				      and DefaultBackgroundColor() methods

#define IMP240100	//GG 
//			Initalize grid echo fields

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

#include <V3d.hxx>
#include <Visual3d_View.hxx>
#include <Visual3d_Light.hxx>
#include <V3d_Viewer.ixx>
#include <V3d_View.hxx>
#include <Viewer_BadValue.hxx>
#include <V3d_OrthographicView.hxx>
#include <V3d_PerspectiveView.hxx>
#ifdef WNT
#include <WNT_GraphicDevice.hxx>
#endif

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

//-Constructor:
V3d_Viewer::V3d_Viewer(const Handle(Aspect_GraphicDevice)& Device , const Standard_ExtString aName, const Standard_CString aDomain,const Standard_Real ViewSize , const V3d_TypeOfOrientation ViewProj , const Quantity_NameOfColor ViewBackground , const V3d_TypeOfVisualization Visualization , const V3d_TypeOfShadingModel ShadingModel , const V3d_TypeOfUpdate UpdateMode, const Standard_Boolean ComputedMode , const Standard_Boolean DefaultComputedMode , const V3d_TypeOfSurfaceDetail SurfaceDetail )  
:Viewer_Viewer(Device,aName,aDomain,-1),
MyDefinedViews(),
MyActiveViews(),
MyDefinedLights(),
MyActiveLights(),
MyDefinedPlanes(),
myActiveViewsIterator(),
myDefinedViewsIterator(),
myActiveLightsIterator(),
myDefinedLightsIterator(),
myDefinedPlanesIterator(),
myComputedMode(ComputedMode),
myDefaultComputedMode(DefaultComputedMode),
myPrivilegedPlane(gp_Ax3(gp_Pnt(0.,0.,0),gp_Dir(0.,0.,1.),gp_Dir(1.,0.,0.))),
myDisplayPlane(Standard_False),
myDisplayPlaneLength(ViewSize)
#ifdef IMP240100
,myGridEcho(Standard_True),myGridEchoStructure(),myGridEchoGroup()
#endif 
{

  MyViewer = new Visual3d_ViewManager(Device) ;
  // san (16/09/2010): It has been decided to turn depth test ON
  // by default, as this is important for new font rendering
  // (without it, there are numerous texture rendering artefacts)
  MyViewer->SetZBufferAuto (Standard_False);
  SetUpdateMode( UpdateMode ) ;
  SetDefaultViewSize(ViewSize) ;
  SetDefaultViewProj(ViewProj) ;
  SetDefaultBackgroundColor(ViewBackground) ;
  SetDefaultVisualization(Visualization) ;
  SetDefaultShadingModel(ShadingModel) ;
  SetDefaultSurfaceDetail(SurfaceDetail) ; 
  SetDefaultAngle(Standard_PI/2.);
  SetDefaultTypeOfView(V3d_ORTHOGRAPHIC);

  Quantity_Color Color1 (Quantity_NOC_GRAY50);
  Quantity_Color Color2 (Quantity_NOC_GRAY70);
//  Quantity_Color White (Quantity_NOC_WHITE);
  myRGrid = new V3d_RectangularGrid(this,Color1,Color2);
  myCGrid = new V3d_CircularGrid(this,Color1,Color2);
  myGridType = Aspect_GT_Rectangular;
}

//-Methods, in order


Handle(V3d_View) V3d_Viewer::CreateView () {
  if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC) 
    return new V3d_OrthographicView(this);
  else
    return new V3d_PerspectiveView(this);
}

void V3d_Viewer::SetViewOn( ) {

  for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
    SetViewOn(ActiveView());};
}

Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() {

  return MyDefaultOrthographicView;
}

Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {

  return MyDefaultPerspectiveView;
}

void V3d_Viewer::SetViewOff( ) {

  for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
    SetViewOff(ActiveView());};
}

void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {

  Handle(Visual3d_View) MyView = TheView->View() ;
  if( MyView->IsDefined() && !IsActive(TheView)) {
    MyActiveViews.Append(TheView) ;
    MyView->Activate();
    for (InitActiveLights();MoreActiveLights();NextActiveLights()){
      TheView->SetLightOn(ActiveLight());}
    // Grid
    TheView->SetGrid (myPrivilegedPlane, Grid ());
    TheView->SetGridActivity (Grid ()->IsActive ());
    // Update
    MyView->Redraw() ;
  }
}

void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {

  Handle(Visual3d_View) MyView =TheView->View(); 
  if( MyView->IsDefined() && IsActive(TheView) ) {
    MyActiveViews.Remove(TheView);
    MyView->Deactivate() ;
  }
}

Standard_Boolean V3d_Viewer::ComputedMode() const {
  return myComputedMode;
}

Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
  return myDefaultComputedMode;
}

void V3d_Viewer::Update() {

  MyViewer->Update();
}

void V3d_Viewer::Redraw()const  {

  MyViewer->Redraw();
}

void V3d_Viewer::Remove() {

  MyViewer->Remove();
}

void V3d_Viewer::Erase() const {
  
  MyViewer->Erase();
}

void V3d_Viewer::UnHighlight() const {

  //FMN MyViewer->UnHighlight();
}

void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
  Standard_Real V1 = v1 ;
  Standard_Real V2 = v2 ;
  Standard_Real V3 = v3 ;

  if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
  if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
  if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;

  Quantity_Color C(V1,V2,V3,Type) ;
#ifdef GER61351
  SetDefaultBackgroundColor(C);
#else
  MyBackground.SetColor(C) ;
#endif
}

void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name) {

  Quantity_Color C(Name) ;
#ifdef GER61351
  SetDefaultBackgroundColor(C);
#else
  MyBackground.SetColor(C) ;
#endif
}

#ifdef GER61351
void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color) {

  MyBackground.SetColor(Color) ;
}
#endif

void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
                                             const Quantity_NameOfColor Name2,
                                             const Aspect_GradientFillMethod FillStyle){

  Quantity_Color C1(Name1) ;
  Quantity_Color C2(Name2) ;
  MyGradientBackground.SetColors(C1, C2, FillStyle);

} 

void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
                                             const Quantity_Color& Color2,
                                             const Aspect_GradientFillMethod FillStyle ){

  MyGradientBackground.SetColors(Color1, Color2, FillStyle);

}  


void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {

  Viewer_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
  MyViewSize = Size ;
}

void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {

  MyViewProj = Orientation ;
}

void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {

  MyVisualization = Type ;
}
void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
  MyViewer->SetZBufferAuto (Automatic);
}
Standard_Boolean V3d_Viewer::ZBufferManagment() const {
  return MyViewer->ZBufferAuto();
}

void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {

  MyShadingModel = Type ;
}

void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {

  MySurfaceDetail = Type ;
}

void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
  MyDefaultAngle = Angle;
}

void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
  MyDefaultTypeOfView = Type;}


void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
  
  MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
}

void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const {

#ifdef GER61351
  Quantity_Color C = DefaultBackgroundColor();
#else
  Quantity_Color C = MyBackground.Color() ;
#endif
  C.Values(V1,V2,V3,Type) ;
}

#ifdef GER61351
Quantity_Color V3d_Viewer::DefaultBackgroundColor() const {
  return MyBackground.Color() ;
}
#endif

void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const{   
  MyGradientBackground.Colors(Color1,Color2);     
}

Standard_Real V3d_Viewer::DefaultViewSize() const {
  return MyViewSize ;
}

V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
  return MyViewProj ;
}

V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
  return MyVisualization ;
}

V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
  return MyShadingModel ;
}

V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
  return MySurfaceDetail ;
}

Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
  return MyDefaultAngle;
}

V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {

  V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
  return Mode ;
}

Standard_Boolean V3d_Viewer::IfMoreViews() const {
  Standard_Boolean TheStatus = Standard_False ;

#ifdef NEW
  if( MyActiveViews->Length() < Visual3d_View::Limit() )
#endif /*NEW*/
    TheStatus = Standard_True ;
  return TheStatus ;
}

Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
  return MyViewer ;
}

Aspect_Background V3d_Viewer::GetBackgroundColor() const {
  return MyBackground ;
}

Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
  return MyGradientBackground;
}   

void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {

  MyDefinedViews.Append(TheView);
  IncrCount();
}

void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {

  MyActiveViews.Remove(TheView);
  MyDefinedViews.Remove(TheView);
}

void V3d_Viewer::AddPlane( const Handle(V3d_Plane)& ThePlane ) {

  MyDefinedPlanes.Append(ThePlane) ;
}

void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) {
  
  MyDefinedPlanes.Remove(ThePlane);
}