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 | |
17 | Handle(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 | |
42 | Document::Document( int theIndex, Application* app ) |
43 | : QObject( app ) |
44 | {\r |
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); |
54 | myContext = new AIS_InteractiveContext( myViewer );\r |
55 | \r |
56 | createNewView();\r |
57 | |
58 | myOperations = new ViewOperations( myContext ); |
59 | } |
60 | |
61 | Document::~Document() |
62 | {\r |
63 | qDeleteAll( myViews );\r |
64 | } |
65 | |
66 | Application* Document::getApplication() |
67 | { |
68 | return myApp; |
69 | } |
70 | |
71 | void Document::createNewView( V3d_TypeOfView type ) |
72 | { |
73 | QWorkspace* ws = myApp->getWorkspace(); |
74 | |
75 | MDIWindow* w = new MDIWindow( this, ws, type ); |
76 | myViews.append( w );\r |
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 | |
89 | // show the very first window in maximized mode\r |
90 | if ( ws->windowList().isEmpty() ) |
91 | w->showMaximized(); |
92 | else |
93 | w->show();\r |
94 | } |
95 | |
96 | void 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 | |
115 | void Document::onCloseView(MDIWindow* theView) |
116 | { |
117 | if ( countOfWindow() == 1 ) |
118 | emit sendCloseDocument( this ); |
119 | else |
120 | removeView( theView ); |
121 | } |
122 | |
123 | void Document::removeView(MDIWindow* theView) |
124 | { |
125 | myViews.removeAll( theView ); |
126 | //delete theView; |
127 | } |
128 | |
129 | int Document::countOfWindow() |
130 | { |
131 | return myViews.count(); |
132 | } |
133 | |
134 | Handle(AIS_InteractiveContext)& Document::getContext() |
135 | { |
136 | return myContext; |
137 | } |
138 | |
139 | void Document::onWireframe() |
140 | { |
141 | myOperations->onWireframe(); |
142 | } |
143 | |
144 | void Document::onShading() |
145 | { |
146 | myOperations->onShading(); |
147 | } |