7fd59977 |
1 | #include "ApplicationCommon.h" |
2 | |
3 | #include "DocumentCommon.h" |
4 | #include "View.h" |
5 | |
55a40de8 |
6 | #include <Standard_WarningsDisable.hxx> |
7fd59977 |
7 | #include <QFrame> |
8 | #include <QVBoxLayout> |
9 | #include <QMenuBar> |
10 | #include <QStatusBar> |
861a7b03 |
11 | #include <QMdiArea> |
12 | #include <QMdiSubWindow> |
7fd59977 |
13 | #include <QMessageBox> |
14 | #include <QApplication> |
15 | #include <QSignalMapper> |
55a40de8 |
16 | #include <Standard_WarningsRestore.hxx> |
7fd59977 |
17 | |
e276548b |
18 | #include <Graphic3d_GraphicDriver.hxx> |
19 | #include <OpenGl_GraphicDriver.hxx> |
1fa16152 |
20 | #include <OSD_Environment.hxx> |
e276548b |
21 | |
7fd59977 |
22 | #include <stdlib.h> |
23 | |
861a7b03 |
24 | static ApplicationCommonWindow* stApp = 0; |
25 | static QMdiArea* stWs = 0; |
7fd59977 |
26 | |
27 | ApplicationCommonWindow::ApplicationCommonWindow() |
aa17dac8 |
28 | : QMainWindow( 0 ), |
29 | myNbDocuments( 0 ), |
30 | myIsDocuments(false), |
31 | myStdToolBar( 0 ), |
7fd59977 |
32 | myCasCadeBar( 0 ), |
aa17dac8 |
33 | myFilePopup( 0 ), |
34 | myWindowPopup( 0 ), |
35 | myFileSeparator(NULL) |
7fd59977 |
36 | { |
7fd59977 |
37 | stApp = this; |
7fd59977 |
38 | |
39 | // create and define the central widget |
40 | QFrame* vb = new QFrame( this ); |
41 | |
42 | QVBoxLayout *layout = new QVBoxLayout( vb ); |
43 | layout->setMargin( 0 ); |
44 | |
45 | vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); |
861a7b03 |
46 | stWs = new QMdiArea( vb ); |
7fd59977 |
47 | layout->addWidget( stWs ); |
48 | setCentralWidget( vb ); |
2ad228f6 |
49 | |
7fd59977 |
50 | createStandardOperations(); |
51 | createCasCadeOperations(); |
52 | |
53 | statusBar()->showMessage( QObject::tr("INF_READY"), 5000 ); |
54 | resize( 1000, 700 ); |
55 | } |
56 | |
57 | ApplicationCommonWindow::~ApplicationCommonWindow() |
58 | { |
59 | } |
60 | |
61 | void ApplicationCommonWindow::createStandardOperations() |
62 | { |
63 | QPixmap newIcon, helpIcon, closeIcon; |
64 | |
65 | QString dir = getResourceDir() + QString( "/" ); |
66 | |
e276548b |
67 | newIcon = QPixmap( dir + QObject::tr("ICON_NEW") ); |
68 | helpIcon = QPixmap( dir + QObject::tr("ICON_HELP") ); |
69 | closeIcon = QPixmap( dir + QObject::tr("ICON_CLOSE") ); |
7fd59977 |
70 | |
e276548b |
71 | QAction * fileNewAction, * fileCloseAction, * filePrefUseVBOAction, |
72 | * fileQuitAction, * viewToolAction, * viewStatusAction, * helpAboutAction; |
7fd59977 |
73 | |
74 | fileNewAction = new QAction( newIcon, QObject::tr("MNU_NEW"), this ); |
75 | fileNewAction->setToolTip( QObject::tr("TBR_NEW") ); |
76 | fileNewAction->setStatusTip( QObject::tr("TBR_NEW") ); |
77 | fileNewAction->setShortcut( QObject::tr("CTRL+N") ); |
3cb77da4 |
78 | connect( fileNewAction, SIGNAL( triggered() ) , this, SLOT( onNewDoc() ) ); |
7fd59977 |
79 | myStdActions.insert( FileNewId, fileNewAction ); |
80 | |
81 | fileCloseAction = new QAction( closeIcon, QObject::tr("MNU_CLOSE"), this ); |
82 | fileCloseAction->setToolTip( QObject::tr("TBR_CLOSE") ); |
83 | fileCloseAction->setStatusTip( QObject::tr("TBR_CLOSE") ); |
84 | fileCloseAction->setShortcut( QObject::tr("CTRL+W") ); |
3cb77da4 |
85 | connect( fileCloseAction, SIGNAL( triggered() ) , this, SLOT( onCloseWindow() ) ); |
7fd59977 |
86 | myStdActions.insert( FileCloseId, fileCloseAction ); |
87 | |
e276548b |
88 | filePrefUseVBOAction = new QAction( QObject::tr("MNU_USE_VBO"), this ); |
89 | filePrefUseVBOAction->setToolTip( QObject::tr("TBR_USE_VBO") ); |
90 | filePrefUseVBOAction->setStatusTip( QObject::tr("TBR_USE_VBO") ); |
91 | filePrefUseVBOAction->setCheckable( true ); |
92 | filePrefUseVBOAction->setChecked( true ); |
a1565817 |
93 | connect( filePrefUseVBOAction, SIGNAL( triggered() ) , this, SLOT( onUseVBO() ) ); |
e276548b |
94 | myStdActions.insert( FilePrefUseVBOId, filePrefUseVBOAction ); |
95 | |
7fd59977 |
96 | fileQuitAction = new QAction( QObject::tr("MNU_QUIT"), this ); |
97 | fileQuitAction->setToolTip( QObject::tr("TBR_QUIT") ); |
98 | fileQuitAction->setStatusTip( QObject::tr("TBR_QUIT") ); |
99 | fileQuitAction->setShortcut( QObject::tr("CTRL+Q") ); |
3cb77da4 |
100 | connect( fileQuitAction, SIGNAL( triggered() ) , qApp, SLOT( closeAllWindows() ) ); |
7fd59977 |
101 | myStdActions.insert( FileQuitId, fileQuitAction ); |
102 | |
103 | viewToolAction = new QAction( QObject::tr("MNU_TOOL_BAR"), this ); |
104 | viewToolAction->setToolTip( QObject::tr("TBR_TOOL_BAR") ); |
105 | viewToolAction->setStatusTip( QObject::tr("TBR_TOOL_BAR") ); |
3cb77da4 |
106 | connect( viewToolAction, SIGNAL( triggered() ) , this, SLOT( onViewToolBar() )); |
7fd59977 |
107 | viewToolAction->setCheckable( true ); |
108 | viewToolAction->setChecked( true ); |
109 | myStdActions.insert( ViewToolId, viewToolAction ); |
110 | |
111 | viewStatusAction = new QAction( QObject::tr("MNU_STATUS_BAR"), this ); |
112 | viewStatusAction->setToolTip( QObject::tr("TBR_STATUS_BAR") ); |
113 | viewStatusAction->setStatusTip( QObject::tr("TBR_STATUS_BAR") ); |
3cb77da4 |
114 | connect( viewStatusAction, SIGNAL( triggered() ), this, SLOT( onViewStatusBar() )); |
7fd59977 |
115 | viewStatusAction->setCheckable( true ); |
116 | viewStatusAction->setChecked( true ); |
117 | myStdActions.insert( ViewStatusId, viewStatusAction ); |
118 | |
119 | helpAboutAction = new QAction( helpIcon, QObject::tr("MNU_ABOUT"), this ); |
120 | helpAboutAction->setToolTip( QObject::tr( "TBR_ABOUT" ) ); |
121 | helpAboutAction->setStatusTip( QObject::tr( "TBR_ABOUT" ) ); |
122 | helpAboutAction->setShortcut( QObject::tr( "F1" ) ); |
3cb77da4 |
123 | connect( helpAboutAction, SIGNAL( triggered() ) , this, SLOT( onAbout() ) ); |
7fd59977 |
124 | myStdActions.insert( HelpAboutId, helpAboutAction ); |
125 | |
e276548b |
126 | // create preferences menu |
127 | QMenu* aPrefMenu = new QMenu( QObject::tr("MNU_PREFERENCES") ); |
128 | aPrefMenu->addAction( filePrefUseVBOAction ); |
2ad228f6 |
129 | |
861a7b03 |
130 | // populate a menu with all actions |
7fd59977 |
131 | myFilePopup = new QMenu( this ); |
132 | myFilePopup = menuBar()->addMenu( QObject::tr("MNU_FILE") ); |
133 | myFilePopup->addAction( fileNewAction ); |
134 | myFilePopup->addAction( fileCloseAction ); |
135 | myFileSeparator = myFilePopup->addSeparator(); |
e276548b |
136 | myFilePopup->addMenu( aPrefMenu ); |
137 | myFileSeparator = myFilePopup->addSeparator(); |
7fd59977 |
138 | myFilePopup->addAction( fileQuitAction ); |
2ad228f6 |
139 | |
140 | // add a view menu |
7fd59977 |
141 | QMenu * view = new QMenu( this ); |
2ad228f6 |
142 | |
7fd59977 |
143 | view = menuBar()->addMenu( QObject::tr("MNU_VIEW") ); |
144 | view->addAction( viewToolAction ); |
145 | view->addAction( viewStatusAction ); |
2ad228f6 |
146 | |
147 | // add a help menu |
7fd59977 |
148 | QMenu * help = new QMenu( this ); |
149 | menuBar()->addSeparator(); |
150 | help = menuBar()->addMenu( QObject::tr("MNU_HELP") ); |
151 | help->addAction( helpAboutAction ); |
152 | |
2ad228f6 |
153 | // populate a tool bar with some actions |
7fd59977 |
154 | myStdToolBar = addToolBar( tr( "File Operations" ) ); |
155 | myStdToolBar->addAction( fileNewAction ); |
156 | myStdToolBar->addAction( helpAboutAction ); |
2ad228f6 |
157 | |
7fd59977 |
158 | myStdActions.at(FileCloseId)->setEnabled(myDocuments.count() > 0); |
e276548b |
159 | |
160 | myStdActions.at(FilePrefUseVBOId)->setEnabled( true ); |
7fd59977 |
161 | } |
162 | |
163 | void ApplicationCommonWindow::createCasCadeOperations() |
164 | { |
165 | createWindowPopup(); |
166 | |
167 | // populate a tool bar with some actions |
168 | myCasCadeBar = addToolBar( tr( "Shape Operations" ) ); |
169 | |
170 | QString dir = ApplicationCommonWindow::getResourceDir() + QString( "/" ); |
171 | QAction* a; |
172 | |
173 | a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_WIRE") ), QObject::tr("MNU_TOOL_WIRE"), this ); |
174 | a->setToolTip( QObject::tr("TBR_TOOL_WIRE") ); |
175 | a->setStatusTip( QObject::tr("TBR_TOOL_WIRE") ); |
3cb77da4 |
176 | connect( a, SIGNAL( triggered() ) , this, SLOT( onToolAction() ) ); |
7fd59977 |
177 | myToolActions.insert( ToolWireframeId, a ); |
178 | |
179 | a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_SHAD") ), QObject::tr("MNU_TOOL_SHAD"), this ); |
180 | a->setToolTip( QObject::tr("TBR_TOOL_SHAD") ); |
181 | a->setStatusTip( QObject::tr("TBR_TOOL_SHAD") ); |
3cb77da4 |
182 | connect( a, SIGNAL( triggered() ) , this, SLOT( onToolAction() ) ); |
7fd59977 |
183 | myToolActions.insert( ToolShadingId, a ); |
184 | |
185 | a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_COLOR") ), QObject::tr("MNU_TOOL_COLOR"), this ); |
186 | a->setToolTip( QObject::tr("TBR_TOOL_COLOR") ); |
187 | a->setStatusTip( QObject::tr("TBR_TOOL_COLOR") ); |
3cb77da4 |
188 | connect( a, SIGNAL( triggered() ) , this, SLOT( onToolAction() ) ); |
7fd59977 |
189 | myToolActions.insert( ToolColorId, a ); |
190 | |
191 | a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_MATER") ), QObject::tr("MNU_TOOL_MATER"), this ); |
192 | a->setToolTip( QObject::tr("TBR_TOOL_MATER") ); |
193 | a->setStatusTip( QObject::tr("TBR_TOOL_MATER") ); |
3cb77da4 |
194 | connect( a, SIGNAL( triggered() ) , this, SLOT( onToolAction() ) ); |
7fd59977 |
195 | myToolActions.insert( ToolMaterialId, a ); |
196 | |
197 | a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_TRANS") ), QObject::tr("MNU_TOOL_TRANS"), this ); |
198 | a->setToolTip( QObject::tr("TBR_TOOL_TRANS") ); |
199 | a->setStatusTip( QObject::tr("TBR_TOOL_TRANS") ); |
3cb77da4 |
200 | connect( a, SIGNAL( triggered() ) , this, SLOT( onToolAction() ) ); |
7fd59977 |
201 | myToolActions.insert( ToolTransparencyId, a ); |
202 | |
203 | a = new QAction( QPixmap( dir+QObject::tr("ICON_TOOL_DEL") ), QObject::tr("MNU_TOOL_DEL"), this ); |
204 | a->setToolTip( QObject::tr("TBR_TOOL_DEL") ); |
205 | a->setStatusTip( QObject::tr("TBR_TOOL_DEL") ); |
861a7b03 |
206 | connect( a, SIGNAL( triggered() ) , this, SLOT( onToolAction() ) ); |
7fd59977 |
207 | myToolActions.insert( ToolDeleteId, a ); |
208 | |
209 | QSignalMapper* sm = new QSignalMapper( this ); |
210 | connect( sm, SIGNAL( mapped( int ) ), this, SLOT( onSetMaterial( int ) ) ); |
211 | |
212 | a = new QAction( QObject::tr("MNU_BRASS"), this ); |
213 | a->setToolTip( QObject::tr("TBR_BRASS") ); |
214 | a->setStatusTip( QObject::tr("TBR_BRASS") ); |
215 | sm->setMapping( a,(int)Graphic3d_NOM_BRASS ); |
3cb77da4 |
216 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
217 | myMaterialActions.insert( Graphic3d_NOM_BRASS, a ); |
218 | |
219 | a = new QAction( QObject::tr("MNU_BRONZE"), this ); |
220 | a->setToolTip( QObject::tr("TBR_BRONZE") ); |
221 | a->setStatusTip( QObject::tr("TBR_BRONZE") ); |
222 | sm->setMapping( a, ( int )Graphic3d_NOM_BRONZE ); |
3cb77da4 |
223 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
224 | myMaterialActions.insert( Graphic3d_NOM_BRONZE, a ); |
225 | |
226 | a = new QAction( QObject::tr("MNU_COPPER"), this ); |
227 | a->setToolTip( QObject::tr("TBR_COPPER") ); |
228 | a->setStatusTip( QObject::tr("TBR_COPER") ); |
229 | sm->setMapping( a, ( int )Graphic3d_NOM_COPPER ); |
3cb77da4 |
230 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
231 | myMaterialActions.insert( Graphic3d_NOM_COPPER, a ); |
232 | |
233 | a = new QAction( QObject::tr("MNU_GOLD"), this ); |
234 | a->setToolTip( QObject::tr("TBR_GOLD") ); |
235 | a->setStatusTip( QObject::tr("TBR_GOLD") ); |
236 | sm->setMapping( a, ( int )Graphic3d_NOM_GOLD ); |
3cb77da4 |
237 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
238 | myMaterialActions.insert( Graphic3d_NOM_GOLD, a ); |
239 | |
240 | a = new QAction( QObject::tr("MNU_PEWTER"), this ); |
241 | a->setToolTip( QObject::tr("TBR_PEWTER") ); |
242 | a->setStatusTip( QObject::tr("TBR_PEWTER") ); |
243 | sm->setMapping( a, ( int )Graphic3d_NOM_PEWTER ); |
3cb77da4 |
244 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
245 | myMaterialActions.insert( Graphic3d_NOM_PEWTER, a ); |
246 | |
247 | a = new QAction( QObject::tr("MNU_PLASTER"), this ); |
248 | a->setToolTip( QObject::tr("TBR_PLASTER") ); |
249 | a->setStatusTip( QObject::tr("TBR_PLASTER") ); |
250 | sm->setMapping( a, ( int )Graphic3d_NOM_PLASTER ); |
3cb77da4 |
251 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
252 | myMaterialActions.insert( Graphic3d_NOM_PLASTER, a ); |
253 | |
254 | a = new QAction( QObject::tr("MNU_PLASTIC"), this ); |
255 | a->setToolTip( QObject::tr("TBR_PLASTIC") ); |
256 | a->setStatusTip( QObject::tr("TBR_PLASTIC") ); |
257 | sm->setMapping( a, ( int )Graphic3d_NOM_PLASTIC ); |
3cb77da4 |
258 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
259 | myMaterialActions.insert( Graphic3d_NOM_PLASTIC, a ); |
260 | |
261 | a = new QAction( QObject::tr("MNU_SILVER"), this ); |
262 | a->setToolTip( QObject::tr("TBR_SILVER") ); |
263 | a->setStatusTip( QObject::tr("TBR_SILVER") ); |
264 | sm->setMapping( a, ( int )Graphic3d_NOM_SILVER ); |
3cb77da4 |
265 | connect( a, SIGNAL( triggered() ), sm, SLOT( map() ) ); |
7fd59977 |
266 | myMaterialActions.insert( Graphic3d_NOM_SILVER, a ); |
267 | |
268 | for ( int i = 0; i < myToolActions.size(); i++ ) |
269 | myCasCadeBar->addAction( myToolActions.at( i ) ); |
270 | myCasCadeBar->hide(); |
271 | } |
272 | |
273 | QList<QAction*>* ApplicationCommonWindow::getToolActions() |
274 | { |
275 | return &myToolActions; |
276 | } |
277 | |
278 | QList<QAction*>* ApplicationCommonWindow::getMaterialActions() |
279 | { |
280 | return &myMaterialActions; |
281 | } |
282 | |
283 | void ApplicationCommonWindow::createWindowPopup() |
284 | { |
285 | if ( !myWindowPopup ) |
286 | { |
287 | myWindowPopup = new QMenu( QObject::tr( "MNU_WINDOW" ), this ); |
2ad228f6 |
288 | connect( myWindowPopup, SIGNAL( aboutToShow() ), |
289 | this, SLOT( windowsMenuAboutToShow() ) ); |
7fd59977 |
290 | } |
291 | } |
292 | |
293 | void ApplicationCommonWindow::windowsMenuAboutToShow() |
294 | { |
295 | myWindowPopup->clear(); |
296 | QAction* a; |
297 | |
298 | QString dir = getResourceDir() + QString( "/" ); |
299 | |
861a7b03 |
300 | a = new QAction( QPixmap( dir + QObject::tr( "ICON_WINDOW_NEW3D" ) ), QObject::tr( "MNU_WINDOW_NEW3D" ), this ); |
301 | a->setToolTip( QObject::tr( "TBR_WINDOW_NEW3D" ) ); |
302 | a->setStatusTip( QObject::tr( "TBR_WINDOW_NEW3D" ) ); |
3cb77da4 |
303 | connect( a, SIGNAL( triggered() ), this, SLOT( onCreateNewView() ) ); |
7fd59977 |
304 | myWindowPopup->addAction( a ); |
305 | |
306 | a = new QAction( QPixmap( dir + QObject::tr( "ICON_WINDOW_CASCADE" ) ), QObject::tr( "MNU_WINDOW_CASCADE" ), this ); |
307 | a->setToolTip( QObject::tr( "TBR_WINDOW_CASCADE" ) ); |
308 | a->setStatusTip( QObject::tr( "TBR_WINDOW_CASCADE" ) ); |
3cb77da4 |
309 | connect( a, SIGNAL( triggered() ), stWs, SLOT( cascade() ) ); |
7fd59977 |
310 | myWindowPopup->addAction( a ); |
311 | |
312 | a = new QAction( QPixmap( dir + QObject::tr( "ICON_WINDOW_TILE" ) ), QObject::tr( "MNU_WINDOW_TILE" ), this ); |
313 | a->setToolTip( QObject::tr( "TBR_WINDOW_TILE" ) ); |
314 | a->setStatusTip( QObject::tr( "TBR_WINDOW_TILE" ) ); |
3cb77da4 |
315 | connect( a, SIGNAL( triggered() ), stWs, SLOT( tile() ) ); |
7fd59977 |
316 | myWindowPopup->addAction( a ); |
317 | |
318 | myWindowPopup->addSeparator(); |
861a7b03 |
319 | QList<QMdiSubWindow *> windows = stWs->subWindowList(); |
320 | for (int i = 0; i < windows.count(); ++i) |
7fd59977 |
321 | { |
2ad228f6 |
322 | QAction* aAction = new QAction( windows.at(i)->windowTitle(), this ); |
7fd59977 |
323 | aAction->setCheckable( true ); |
324 | aAction->setData( i ); |
325 | myWindowPopup->addAction( aAction ); |
326 | connect( aAction, SIGNAL( toggled( bool ) ), this, SLOT( windowsMenuActivated( bool ) ) ); |
861a7b03 |
327 | aAction->setChecked( stWs->activeSubWindow() == windows.at(i) ); |
7fd59977 |
328 | } |
329 | } |
330 | |
331 | void ApplicationCommonWindow::windowsMenuActivated( bool checked ) |
332 | { |
333 | QAction* aSender = qobject_cast<QAction*>( sender() ); |
334 | if ( !aSender ) |
2ad228f6 |
335 | return; |
861a7b03 |
336 | QWidget * w = stWs->subWindowList().at( aSender->data().toInt() ); |
7fd59977 |
337 | if ( w && checked ) |
338 | w->setFocus(); |
339 | } |
340 | |
861a7b03 |
341 | QMdiArea * ApplicationCommonWindow::getWorkspace() |
7fd59977 |
342 | { |
343 | return stWs; |
344 | } |
345 | |
346 | ApplicationCommonWindow* ApplicationCommonWindow::getApplication() |
347 | { |
348 | return stApp; |
349 | } |
350 | |
351 | void ApplicationCommonWindow::updateFileActions() |
352 | { |
aa17dac8 |
353 | if (!myDocuments.isEmpty()) |
7fd59977 |
354 | { |
aa17dac8 |
355 | return; |
356 | } |
357 | |
358 | if ( !myIsDocuments ) |
359 | { |
360 | QAction* fileQuitAction = NULL; |
361 | QAction* windowAction = NULL; |
362 | QList<QAction *> aListActions = myFilePopup->actions(); |
363 | for ( int i = 0; i < aListActions.size(); i++ ) |
7fd59977 |
364 | { |
aa17dac8 |
365 | if( aListActions.at( i )->text() == QObject::tr("MNU_QUIT") ) |
7fd59977 |
366 | { |
aa17dac8 |
367 | fileQuitAction = aListActions.at( i ); |
368 | break; |
7fd59977 |
369 | } |
aa17dac8 |
370 | } |
2ad228f6 |
371 | |
aa17dac8 |
372 | if( !fileQuitAction ) |
373 | return; |
7fd59977 |
374 | |
aa17dac8 |
375 | myIsDocuments = true; |
376 | myCasCadeBar->show(); |
7fd59977 |
377 | |
aa17dac8 |
378 | QList<QAction *> aListMenuActions = menuBar()->actions(); |
379 | for ( int i = 0; i < aListMenuActions.size(); i++ ) |
380 | { |
381 | if( aListMenuActions.at( i )->text() == QObject::tr("MNU_HELP") ) |
7fd59977 |
382 | { |
aa17dac8 |
383 | windowAction= aListMenuActions.at( i ); |
384 | break; |
7fd59977 |
385 | } |
aa17dac8 |
386 | } |
7fd59977 |
387 | |
aa17dac8 |
388 | if( !windowAction ) |
389 | return; |
7fd59977 |
390 | |
aa17dac8 |
391 | menuBar()->insertMenu( windowAction, myWindowPopup ); |
392 | } |
393 | else |
394 | { |
395 | myIsDocuments = false; |
396 | myCasCadeBar->hide(); |
397 | menuBar()->removeAction( myWindowPopup->menuAction() ); |
7fd59977 |
398 | } |
399 | } |
400 | |
401 | DocumentCommon* ApplicationCommonWindow::createNewDocument() |
402 | { |
403 | return new DocumentCommon( ++myNbDocuments, this ); |
404 | } |
405 | |
406 | int& ApplicationCommonWindow::getNbDocument() |
407 | { |
408 | return myNbDocuments; |
409 | } |
410 | |
411 | DocumentCommon* ApplicationCommonWindow::onNewDoc() |
412 | { |
861a7b03 |
413 | updateFileActions(); |
414 | |
415 | DocumentCommon* aDoc = createNewDocument(); |
416 | aDoc->onCreateNewView(); |
417 | onSelectionChanged(); |
418 | |
419 | connect (aDoc, SIGNAL (sendCloseDocument (DocumentCommon*) ), |
420 | this, SLOT (onCloseDocument (DocumentCommon*))); |
421 | connect (stWs, SIGNAL (windowActivated (QWidget*)), |
422 | this, SLOT (onWindowActivated (QWidget*))); |
423 | connect (aDoc, SIGNAL (selectionChanged()), |
424 | this, SLOT (onSelectionChanged())); |
425 | |
426 | myDocuments.append (aDoc); |
427 | myStdActions.at (FileCloseId)->setEnabled (myDocuments.count() > 0); |
428 | |
429 | return aDoc; |
e276548b |
430 | } |
431 | |
432 | void ApplicationCommonWindow::onCloseWindow() |
433 | { |
861a7b03 |
434 | stWs->activeSubWindow()->close(); |
7fd59977 |
435 | } |
436 | |
e276548b |
437 | void ApplicationCommonWindow::onUseVBO() |
438 | { |
861a7b03 |
439 | MDIWindow* aWindow = qobject_cast<MDIWindow*> (stWs->activeSubWindow()->widget()); |
e276548b |
440 | |
861a7b03 |
441 | if (NULL == aWindow) |
442 | return; |
e276548b |
443 | |
861a7b03 |
444 | Handle(AIS_InteractiveContext) aContextAIS = aWindow->getDocument()->getContext(); |
e276548b |
445 | |
861a7b03 |
446 | if (aContextAIS.IsNull()) |
447 | return; |
e276548b |
448 | |
861a7b03 |
449 | Handle(OpenGl_GraphicDriver) aDriver = |
450 | Handle(OpenGl_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Driver()); |
e276548b |
451 | |
861a7b03 |
452 | if (!aDriver.IsNull()) |
453 | { |
454 | aDriver->ChangeOptions().vboDisable = Standard_True; |
455 | } |
e276548b |
456 | } |
457 | |
7fd59977 |
458 | void ApplicationCommonWindow::onCloseDocument(DocumentCommon* theDoc) |
459 | { |
460 | myDocuments.removeAll( theDoc ); |
461 | theDoc->removeViews(); |
462 | delete theDoc; |
463 | updateFileActions(); |
464 | myStdActions.at(FileCloseId)->setEnabled(myDocuments.count() > 0); |
465 | } |
466 | |
467 | void ApplicationCommonWindow::onViewToolBar() |
468 | { |
2ad228f6 |
469 | bool show = myStdActions.at( ViewToolId )->isChecked(); |
470 | if ( show == myStdToolBar->isVisible() ) |
471 | return; |
472 | if ( show ) |
473 | myStdToolBar->show(); |
474 | else |
475 | myStdToolBar->hide(); |
7fd59977 |
476 | } |
477 | |
478 | void ApplicationCommonWindow::onViewStatusBar() |
479 | { |
2ad228f6 |
480 | bool show = myStdActions.at( ViewStatusId )->isChecked(); |
481 | if ( show == statusBar()->isVisible() ) |
482 | return; |
483 | if ( show ) |
484 | statusBar()->show(); |
485 | else |
486 | statusBar()->hide(); |
7fd59977 |
487 | } |
488 | |
489 | void ApplicationCommonWindow::onAbout() |
490 | { |
2ad228f6 |
491 | QMessageBox::information( this, QObject::tr( "TIT_ABOUT" ), QObject::tr( "INF_ABOUT" ), QObject::tr("BTN_OK" ), |
492 | QString::null, QString::null, 0, 0 ); |
7fd59977 |
493 | } |
494 | |
495 | void ApplicationCommonWindow::onCreateNewView() |
496 | { |
861a7b03 |
497 | MDIWindow* window = qobject_cast< MDIWindow* >( stWs->activeSubWindow()->widget() ); |
498 | window->getDocument()->onCreateNewView(); |
e276548b |
499 | } |
500 | |
7fd59977 |
501 | void ApplicationCommonWindow::onWindowActivated ( QWidget * w ) |
502 | { |
e276548b |
503 | if (w == NULL) |
504 | { |
505 | return; |
506 | } |
507 | |
508 | MDIWindow* window = qobject_cast< MDIWindow* >(w); |
509 | |
510 | window->onWindowActivated(); |
7fd59977 |
511 | } |
512 | |
513 | void ApplicationCommonWindow::onToolAction() |
514 | { |
2ad228f6 |
515 | QAction* sentBy = (QAction*) sender(); |
516 | QMdiArea* ws = ApplicationCommonWindow::getWorkspace(); |
517 | DocumentCommon* doc = qobject_cast<MDIWindow*>( ws->activeSubWindow()->widget() )->getDocument(); |
7fd59977 |
518 | |
2ad228f6 |
519 | if( sentBy == myToolActions.at( ToolWireframeId ) ) |
520 | doc->onWireframe(); |
7fd59977 |
521 | |
2ad228f6 |
522 | if( sentBy == myToolActions.at( ToolShadingId ) ) |
523 | doc->onShading(); |
7fd59977 |
524 | |
2ad228f6 |
525 | if( sentBy == myToolActions.at( ToolColorId ) ) |
526 | doc->onColor(); |
7fd59977 |
527 | |
2ad228f6 |
528 | if( sentBy == myToolActions.at( ToolMaterialId ) ) |
529 | doc->onMaterial(); |
7fd59977 |
530 | |
2ad228f6 |
531 | if( sentBy == myToolActions.at( ToolTransparencyId ) ) |
532 | doc->onTransparency(); |
7fd59977 |
533 | |
2ad228f6 |
534 | if( sentBy == myToolActions.at( ToolDeleteId ) ) |
535 | doc->onDelete(); |
7fd59977 |
536 | } |
537 | |
538 | void ApplicationCommonWindow::onSelectionChanged() |
539 | { |
861a7b03 |
540 | QMdiArea* ws = ApplicationCommonWindow::getWorkspace(); |
2ad228f6 |
541 | DocumentCommon* doc; |
7fd59977 |
542 | |
861a7b03 |
543 | if( !qobject_cast<MDIWindow*>( ws->activeSubWindow()->widget() ) ) |
2ad228f6 |
544 | return; |
545 | |
861a7b03 |
546 | doc = ( qobject_cast<MDIWindow*>( ws->activeSubWindow()->widget() ) )->getDocument(); |
547 | Handle(AIS_InteractiveContext) context = doc->getContext(); |
7fd59977 |
548 | |
861a7b03 |
549 | bool OneOrMoreInShading = false; |
550 | bool OneOrMoreInWireframe = false; |
551 | int numSel = context->NbSelected(); |
552 | if ( numSel ) |
553 | { |
404c8936 |
554 | for ( context->InitSelected(); context->MoreSelected(); context->NextSelected() ) |
7fd59977 |
555 | { |
404c8936 |
556 | if ( context->IsDisplayed( context->SelectedInteractive(), 1 ) ) |
861a7b03 |
557 | OneOrMoreInShading = true; |
404c8936 |
558 | if ( context->IsDisplayed( context->SelectedInteractive(), 0 ) ) |
861a7b03 |
559 | OneOrMoreInWireframe = true; |
7fd59977 |
560 | } |
861a7b03 |
561 | myToolActions.at( ToolWireframeId )->setEnabled( OneOrMoreInShading ); |
562 | myToolActions.at( ToolShadingId )->setEnabled( OneOrMoreInWireframe ); |
563 | myToolActions.at( ToolColorId )->setEnabled( true ); |
564 | myToolActions.at( ToolMaterialId )->setEnabled( true ); |
565 | myToolActions.at( ToolTransparencyId )->setEnabled( OneOrMoreInShading ); |
566 | myToolActions.at( ToolDeleteId )->setEnabled( true ); |
567 | } |
568 | else |
569 | { |
570 | myToolActions.at( ToolWireframeId )->setEnabled( false ); |
571 | myToolActions.at( ToolShadingId )->setEnabled( false ); |
572 | myToolActions.at( ToolColorId )->setEnabled( false ); |
573 | myToolActions.at( ToolMaterialId )->setEnabled( false ); |
574 | myToolActions.at( ToolTransparencyId )->setEnabled( false ); |
575 | myToolActions.at( ToolDeleteId )->setEnabled( false ); |
576 | } |
7fd59977 |
577 | } |
578 | |
579 | void ApplicationCommonWindow::onSetMaterial( int theMaterial ) |
580 | { |
861a7b03 |
581 | QMdiArea* ws = getWorkspace(); |
582 | DocumentCommon* doc = qobject_cast<MDIWindow*>( ws->activeSubWindow()->widget() )->getDocument(); |
7fd59977 |
583 | doc->onMaterial( theMaterial ); |
584 | } |
585 | |
586 | QString ApplicationCommonWindow::getResourceDir() |
587 | { |
861a7b03 |
588 | static QString aResourceDir = |
1fa16152 |
589 | QString (OSD_Environment ("CSF_ResourcesDefaults").Value().ToCString()); |
590 | if (aResourceDir.isEmpty()) |
591 | aResourceDir = QString (OSD_Environment ("CSF_OCCTResourcePath").Value().ToCString()) + "/samples"; |
592 | |
861a7b03 |
593 | return aResourceDir; |
7fd59977 |
594 | } |
595 | |
596 | void ApplicationCommonWindow::resizeEvent( QResizeEvent* e ) |
597 | { |
598 | QMainWindow::resizeEvent( e ); |
599 | statusBar()->setSizeGripEnabled( !isMaximized() ); |
600 | } |
601 | |
602 | bool ApplicationCommonWindow::isDocument() |
603 | { |
604 | return myIsDocuments; |
605 | } |
606 | |
607 | QMenu* ApplicationCommonWindow::getFilePopup() |
608 | { |
609 | return myFilePopup; |
610 | } |
611 | |
612 | QAction* ApplicationCommonWindow::getFileSeparator() |
613 | { |
614 | return myFileSeparator; |
615 | } |
616 | |
617 | QToolBar* ApplicationCommonWindow::getCasCadeBar() |
618 | { |
619 | return myCasCadeBar; |
620 | } |