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