0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / V3d / V3d_Viewer.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14/***********************************************************************
15
16 FONCTION :
17 ----------
18 Classe V3d_Viewer :
19
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
23 15-11-97 : FMN ; Ajout texture mapping
24 02-02-98 : FMN ; Mise a niveau WNT
25 23-02-98 : FMN ; Remplacement PI par Standard_PI
26 16-07-98 : CAL ; S3892. Ajout grilles 3d.
27
28************************************************************************/
29
b8ddfc2f 30//GER61351 //GG_15/12/99 Adds SetDefaultBackgroundColor() and DefaultBackgroundColor() methods
7fd59977 31
32#define IMP240100 //GG
33// Initalize grid echo fields
34
35/*----------------------------------------------------------------------*/
36/*
37 * Includes
38 */
39
40#include <V3d.hxx>
41#include <Visual3d_View.hxx>
42#include <Visual3d_Light.hxx>
43#include <V3d_Viewer.ixx>
44#include <V3d_View.hxx>
6942f04a 45#include <V3d_BadValue.hxx>
7fd59977 46
47/*----------------------------------------------------------------------*/
48
49//-Constructor:
6942f04a 50V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver,
51 const Standard_ExtString theName,
52 const Standard_CString theDomain,
53 const Standard_Real theViewSize,
54 const V3d_TypeOfOrientation theViewProj,
55 const Quantity_NameOfColor theViewBackground,
56 const V3d_TypeOfVisualization theVisualization,
57 const V3d_TypeOfShadingModel theShadingModel,
58 const V3d_TypeOfUpdate theUpdateMode,
59 const Standard_Boolean theComputedMode,
60 const Standard_Boolean theDefaultComputedMode,
61 const V3d_TypeOfSurfaceDetail theSurfaceDetail)
62:myNextCount (-1),
63myDriver (theDriver),
64myName (TCollection_ExtendedString (theName)),
65myDomain (TCollection_AsciiString (theDomain)),
7fd59977 66MyDefinedViews(),
67MyActiveViews(),
68MyDefinedLights(),
69MyActiveLights(),
7fd59977 70myActiveViewsIterator(),
71myDefinedViewsIterator(),
72myActiveLightsIterator(),
73myDefinedLightsIterator(),
6942f04a 74myComputedMode (theComputedMode),
75myDefaultComputedMode (theDefaultComputedMode),
76myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
77myDisplayPlane (Standard_False),
78myDisplayPlaneLength (theViewSize)
7fd59977 79#ifdef IMP240100
6942f04a 80,myGridEcho (Standard_True), myGridEchoStructure(), myGridEchoGroup()
7fd59977 81#endif
82{
6942f04a 83 MyViewer = new Visual3d_ViewManager (theDriver);
7fd59977 84 // san (16/09/2010): It has been decided to turn depth test ON
85 // by default, as this is important for new font rendering
86 // (without it, there are numerous texture rendering artefacts)
87 MyViewer->SetZBufferAuto (Standard_False);
6942f04a 88 SetUpdateMode (theUpdateMode);
89 SetDefaultViewSize (theViewSize);
90 SetDefaultViewProj (theViewProj);
91 SetDefaultBackgroundColor (theViewBackground);
92 SetDefaultVisualization (theVisualization);
93 SetDefaultShadingModel (theShadingModel);
94 SetDefaultSurfaceDetail (theSurfaceDetail);
95 SetDefaultAngle (M_PI / 2.);
96 SetDefaultTypeOfView (V3d_ORTHOGRAPHIC);
7fd59977 97
98 Quantity_Color Color1 (Quantity_NOC_GRAY50);
99 Quantity_Color Color2 (Quantity_NOC_GRAY70);
100// Quantity_Color White (Quantity_NOC_WHITE);
6942f04a 101 myRGrid = new V3d_RectangularGrid (this, Color1, Color2);
102 myCGrid = new V3d_CircularGrid (this, Color1, Color2);
7fd59977 103 myGridType = Aspect_GT_Rectangular;
104}
105
106//-Methods, in order
107
108
b5ac8292 109Handle(V3d_View) V3d_Viewer::CreateView ()
110{
111 return new V3d_View(this, MyDefaultTypeOfView);
7fd59977 112}
113
114void V3d_Viewer::SetViewOn( ) {
115
116 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
117 SetViewOn(ActiveView());};
118}
119
7fd59977 120void V3d_Viewer::SetViewOff( ) {
121
122 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
123 SetViewOff(ActiveView());};
124}
125
126void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
127
128 Handle(Visual3d_View) MyView = TheView->View() ;
129 if( MyView->IsDefined() && !IsActive(TheView)) {
130 MyActiveViews.Append(TheView) ;
131 MyView->Activate();
132 for (InitActiveLights();MoreActiveLights();NextActiveLights()){
133 TheView->SetLightOn(ActiveLight());}
134 // Grid
135 TheView->SetGrid (myPrivilegedPlane, Grid ());
136 TheView->SetGridActivity (Grid ()->IsActive ());
137 // Update
138 MyView->Redraw() ;
139 }
140}
141
142void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
143
144 Handle(Visual3d_View) MyView =TheView->View();
145 if( MyView->IsDefined() && IsActive(TheView) ) {
146 MyActiveViews.Remove(TheView);
147 MyView->Deactivate() ;
148 }
149}
150
151Standard_Boolean V3d_Viewer::ComputedMode() const {
152 return myComputedMode;
153}
154
155Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
156 return myDefaultComputedMode;
157}
158
159void V3d_Viewer::Update() {
160
161 MyViewer->Update();
162}
163
164void V3d_Viewer::Redraw()const {
165
166 MyViewer->Redraw();
167}
168
169void V3d_Viewer::Remove() {
170
171 MyViewer->Remove();
172}
173
174void V3d_Viewer::Erase() const {
175
176 MyViewer->Erase();
177}
178
179void V3d_Viewer::UnHighlight() const {
180
181 //FMN MyViewer->UnHighlight();
182}
183
184void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
185 Standard_Real V1 = v1 ;
186 Standard_Real V2 = v2 ;
187 Standard_Real V3 = v3 ;
188
189 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
190 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
191 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
192
193 Quantity_Color C(V1,V2,V3,Type) ;
7fd59977 194 SetDefaultBackgroundColor(C);
7fd59977 195}
196
b8ddfc2f 197void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name)
198{
7fd59977 199 Quantity_Color C(Name) ;
7fd59977 200 SetDefaultBackgroundColor(C);
7fd59977 201}
202
b8ddfc2f 203void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color)
204{
7fd59977 205 MyBackground.SetColor(Color) ;
206}
7fd59977 207
208void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
209 const Quantity_NameOfColor Name2,
210 const Aspect_GradientFillMethod FillStyle){
211
212 Quantity_Color C1(Name1) ;
213 Quantity_Color C2(Name2) ;
214 MyGradientBackground.SetColors(C1, C2, FillStyle);
215
216}
217
218void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
219 const Quantity_Color& Color2,
220 const Aspect_GradientFillMethod FillStyle ){
221
222 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
223
224}
225
226
227void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
228
6942f04a 229 V3d_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
7fd59977 230 MyViewSize = Size ;
231}
232
233void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
234
235 MyViewProj = Orientation ;
236}
237
238void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {
239
240 MyVisualization = Type ;
241}
242void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
243 MyViewer->SetZBufferAuto (Automatic);
244}
245Standard_Boolean V3d_Viewer::ZBufferManagment() const {
246 return MyViewer->ZBufferAuto();
247}
248
249void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
250
251 MyShadingModel = Type ;
252}
253
254void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
255
256 MySurfaceDetail = Type ;
257}
258
259void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
260 MyDefaultAngle = Angle;
261}
262
263void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
264 MyDefaultTypeOfView = Type;}
265
266
267void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
268
269 MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
270}
271
b8ddfc2f 272void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const
273{
7fd59977 274 Quantity_Color C = DefaultBackgroundColor();
7fd59977 275 C.Values(V1,V2,V3,Type) ;
276}
277
b8ddfc2f 278Quantity_Color V3d_Viewer::DefaultBackgroundColor() const
279{
7fd59977 280 return MyBackground.Color() ;
281}
7fd59977 282
b8ddfc2f 283void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const
284{
7fd59977 285 MyGradientBackground.Colors(Color1,Color2);
286}
287
288Standard_Real V3d_Viewer::DefaultViewSize() const {
289 return MyViewSize ;
290}
291
292V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
293 return MyViewProj ;
294}
295
296V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
297 return MyVisualization ;
298}
299
300V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
301 return MyShadingModel ;
302}
303
304V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
305 return MySurfaceDetail ;
306}
307
308Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
309 return MyDefaultAngle;
310}
311
312V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
313
314 V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
315 return Mode ;
316}
317
318Standard_Boolean V3d_Viewer::IfMoreViews() const {
319 Standard_Boolean TheStatus = Standard_False ;
320
321#ifdef NEW
322 if( MyActiveViews->Length() < Visual3d_View::Limit() )
323#endif /*NEW*/
324 TheStatus = Standard_True ;
325 return TheStatus ;
326}
327
328Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
329 return MyViewer ;
330}
331
332Aspect_Background V3d_Viewer::GetBackgroundColor() const {
333 return MyBackground ;
334}
335
336Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
337 return MyGradientBackground;
338}
339
340void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
341
342 MyDefinedViews.Append(TheView);
343 IncrCount();
344}
345
346void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
347
348 MyActiveViews.Remove(TheView);
349 MyDefinedViews.Remove(TheView);
350}
351
59f45b7c 352//=======================================================================
353//function : AddZLayer
354//purpose :
355//=======================================================================
356
357Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
358{
359 return MyViewer->AddZLayer (theLayerId);
360}
361
362//=======================================================================
363//function : RemoveZLayer
364//purpose :
365//=======================================================================
366
367Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
368{
369 return MyViewer->RemoveZLayer (theLayerId);
370}
371
372//=======================================================================
373//function : GetAllZLayers
374//purpose :
375//=======================================================================
376
377void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
378{
379 MyViewer->GetAllZLayers (theLayerSeq);
380}
6942f04a 381
382//=======================================================================
383//function : Domain
384//purpose :
385//=======================================================================
386
387Standard_CString V3d_Viewer::Domain() const
388{
389 return myDomain.ToCString();
390}
391
392//=======================================================================
393//function : Driver
394//purpose :
395//=======================================================================
396
397const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const
398{
399 return myDriver;
400}
401
402//=======================================================================
403//function : NextName
404//purpose :
405//=======================================================================
406
407Standard_ExtString V3d_Viewer::NextName() const
408{
409 TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString());
410 aNextName.AssignCat (TCollection_ExtendedString (myNextCount));
411
412 return aNextName.ToExtString();
413}
414
415//=======================================================================
416//function : IncrCount
417//purpose :
418//=======================================================================
419
420void V3d_Viewer::IncrCount()
421{
422 myNextCount++;
973c2be1 423}