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