0032709: Samples, MFC - remove samples Viewer2d, Viewer3d, Ocaf, Triangulation, Anima...
[occt.git] / samples / qt / Tutorial / src / ApplicationTut.cxx
1 #include "ApplicationTut.h"
2 #include "DocumentTut.h"
3
4 #include <OSD_Environment.hxx>
5
6 #include <Standard_WarningsDisable.hxx>
7 #include <QFileDialog>
8 #include <QStatusBar>
9 #include <QMdiSubWindow>
10 #include <Standard_WarningsRestore.hxx>
11
12 ApplicationTut::ApplicationTut()
13     : ApplicationCommonWindow( )
14 {
15   createMakeBottleOperation();
16 }
17
18 ApplicationTut::~ApplicationTut()
19 {
20 }
21
22 void ApplicationTut::createMakeBottleOperation(){
23         QPixmap MakeBottleIcon;
24         QString dir = getTutResourceDir() + QString( "/" );
25   MakeBottleIcon = QPixmap( dir+QObject::tr( "ICON_MAKE_BOTTLE" ) );
26         
27   QAction * MakeBottleAction = new QAction( MakeBottleIcon, QObject::tr("TBR_MAKEBOT"), this );
28   MakeBottleAction->setToolTip( QObject::tr( "TBR_MAKEBOT" ) );
29   MakeBottleAction->setStatusTip( QObject::tr("TBR_MAKEBOT") );
30   MakeBottleAction->setShortcut( QObject::tr( "CTRL+M" ) );
31         connect( MakeBottleAction, SIGNAL( triggered() ) , this, SLOT( onMakeBottleAction() ) );
32         
33         myMakeBottleBar = addToolBar( tr( "Make Bottle" ) );
34   insertToolBar( getCasCadeBar(), myMakeBottleBar );
35   myMakeBottleBar->addAction( MakeBottleAction );
36         myMakeBottleBar->hide();
37 }
38
39 void ApplicationTut::updateFileActions()
40 {
41   if ( getWorkspace()->subWindowList().isEmpty() )
42   {
43           if ( !isDocument() )
44                 {
45       myMakeBottleBar->show();
46     }
47     else
48     {
49       myMakeBottleBar->hide();
50     }
51   }
52   ApplicationCommonWindow::updateFileActions();
53 }
54
55 void ApplicationTut::onMakeBottleAction()
56 {
57         QMdiArea* ws = ApplicationCommonWindow::getWorkspace();
58   DocumentTut* doc = (DocumentTut*)( qobject_cast<MDIWindow*>( ws->activeSubWindow()->widget() )->getDocument() );
59         statusBar()->showMessage( QObject::tr("INF_MAKE_BOTTLE"), 5000 );
60         doc->onMakeBottle();
61         statusBar()->showMessage(QObject::tr("INF_DONE"));
62 }
63
64 QString ApplicationTut::getTutResourceDir()
65 {
66   static QString resDir (OSD_Environment ("CSF_TutorialResourcesDefaults").Value().ToCString());
67   if (resDir.isEmpty())
68     resDir = QString (OSD_Environment ("CSF_OCCTResourcePath").Value().ToCString()) + "/samples";
69   return resDir;
70 }