Adding svn:eol-style=LF property
[occt.git] / samples / qt / Graphic3dDemo / src / Document.cxx
CommitLineData
7fd59977 1#include <qstatusbar.h>
2
3#ifndef WNT
4#include <Graphic3d_GraphicDevice.hxx>
5#else
6#include <Graphic3d_WNTGraphicDevice.hxx>
7#endif
8
9#include <V3d_View.hxx>
10
11#include "Application.h"
12#include "Document.h"
13#include "global.h"
14
15
16
17Handle(V3d_Viewer) Document::Viewer( const Standard_CString aDisplay,
18 const Standard_ExtString aName,
19 const Standard_CString aDomain,
20 const Standard_Real ViewSize )
21{
22#ifndef WNT
23 static Handle(Graphic3d_GraphicDevice) defaultdevice;
24
25 if ( defaultdevice.IsNull() )
26 defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
27
28 return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize,
29 V3d_XposYnegZpos,Quantity_NOC_MIDNIGHTBLUE,
30 V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT);
31#else
32 static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
33 if ( defaultdevice.IsNull() )
34 defaultdevice = new Graphic3d_WNTGraphicDevice();
35
36 return new V3d_Viewer( defaultdevice, aName, aDomain, ViewSize,
37 V3d_XposYnegZpos,Quantity_NOC_MIDNIGHTBLUE,
38 V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT);
39#endif // WNT
40}
41
42Document::Document( int theIndex, Application* app )
43: QObject( app )
c6c9371f 44{
7fd59977 45 myIndex = theIndex;
46 myNbViews = 0;
47 myApp = app;
48
49 TCollection_ExtendedString a3DName("Visual3D");
50 myViewer = Viewer( getenv( "DISPLAY" ), a3DName.ToExtString(), "", 1000.0 );
51 myViewer->SetDefaultLights();
52 myViewer->SetLightOn();
53 myViewer->SetZBufferManagment(false);
c6c9371f 54 myContext = new AIS_InteractiveContext( myViewer );
55
56 createNewView();
7fd59977 57
58 myOperations = new ViewOperations( myContext );
59}
60
61Document::~Document()
c6c9371f 62{
63 qDeleteAll( myViews );
7fd59977 64}
65
66Application* Document::getApplication()
67{
68 return myApp;
69}
70
71void Document::createNewView( V3d_TypeOfView type )
72{
73 QWorkspace* ws = myApp->getWorkspace();
74
75 MDIWindow* w = new MDIWindow( this, ws, type );
c6c9371f 76 myViews.append( w );
7fd59977 77 ws->addWindow( w );
78
79 //connect( w, SIGNAL( message(const QString&, int) ), myApp->statusBar(), SLOT( message(const QString&, int )) );
80 verify( connect( w, SIGNAL( sendCloseView( MDIWindow* ) ),
81 SLOT( onCloseView( MDIWindow* ) ) ) );
82
83 QString aName;
84 w->setWindowTitle( aName.sprintf( "3D Viewer_%d:%d", myIndex, ++myNbViews ) );
85
86 QString dir = Application::getResourceDir();
87 w->setWindowIcon( QPixmap( dir + tr( "ICON_DOC" ) ) );
88
c6c9371f 89 // show the very first window in maximized mode
7fd59977 90 if ( ws->windowList().isEmpty() )
91 w->showMaximized();
92 else
c6c9371f 93 w->show();
7fd59977 94}
95
96void Document::createMagView( int xMin, int yMin, int xMax, int yMax )
97{
98#ifdef old
99 Handle(V3d_View) currentView =
100 ( (MDIWindow*) myApp->getWorkspace()->activeWindow() )->getView();
101 createNewView( false );
102 MDIWindow* newView = myViews.last();
103 Handle(V3d_View) nView = newView->getView();
104
105 newView->show();
106 nView->FitAll();
107 //nView->ZFitAll();
108 //nView->Redraw();
109 //nView->WindowFitAll( xMin, yMin, xMax, yMax );
110 nView->SetMagnify( currentView->Window(), currentView, 10, 10, 100, 100 );
111 //nView->SetMagnify( nView->Window(), currentView, xMin, yMin, xMax, yMax );
112#endif
113}
114
115void Document::onCloseView(MDIWindow* theView)
116{
117 if ( countOfWindow() == 1 )
118 emit sendCloseDocument( this );
119 else
120 removeView( theView );
121}
122
123void Document::removeView(MDIWindow* theView)
124{
125 myViews.removeAll( theView );
126 //delete theView;
127}
128
129int Document::countOfWindow()
130{
131 return myViews.count();
132}
133
134Handle(AIS_InteractiveContext)& Document::getContext()
135{
136 return myContext;
137}
138
139void Document::onWireframe()
140{
141 myOperations->onWireframe();
142}
143
144void Document::onShading()
145{
146 myOperations->onShading();
147}