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