Small update
[occt.git] / samples / qt / Graphic3dDemo / src / Application.cxx
1 #include <stdio.h>
2 \r
3 #include <AIS_InteractiveContext.hxx>
4 #include <OSD_Timer.hxx>
5 #include <Graphic3d_ArrayOfPrimitives.hxx>
6 #include <AIS_ListOfInteractive.hxx>
7 #include <AIS_ListIteratorOfListOfInteractive.hxx>
8 #include <AIS_Shape.hxx>
9 #include <TopoDS_Shape.hxx>
10 #include <TopExp_Explorer.hxx>
11 #include <TopoDS_Face.hxx>
12 #include <Poly_Triangulation.hxx>
13 #include <BRep_TFace.hxx>
14 #include <TopoDS.hxx>
15 #include <Sphere_Sphere.hxx>
16 #include <AIS_Trihedron.hxx>
17
18 #include <qapplication.h>\r
19 #include <qframe.h>
20 #include <qworkspace.h>
21 #include <qstatusbar.h>
22 #include <qmenubar.h>
23 #include <qmessagebox.h>
24 #include <qtextedit.h> 
25 #include <qlayout.h>\r
26 #include <qevent.h>
27
28 #include "global.h"
29 #include "Application.h"
30 #include "Document.h"
31 #include "MDIWindow.h"
32 #include "Translate.h"
33 #include "ViewOperations.h" // to have access to its enumeration
34 #include "AutoTestDlg.h"
35
36 //#define OUTPUT_WINDOW
37
38 static Application* stApp;
39 static OSD_Timer timer;
40
41 Application::Application() : QMainWindow( 0 )
42 {
43   myNbDocuments = 0;
44   stApp = this;
45   myIsDocuments = false;
46
47   // create and define the central widget\r
48   QFrame* vBox = new QFrame( this );\r
49   vBox->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
50   QVBoxLayout* main = new QVBoxLayout( vBox );\r
51   main->setMargin( 0 );\r
52 \r
53   myWorkSpace = new QWorkspace( vBox );\r
54   main->addWidget( myWorkSpace );
55   setCentralWidget( vBox );\r
56
57         createActions();
58         createCCActions();
59
60   statusBar()->showMessage( tr("INF_READY"), 2001 );
61   resize( 800, 650 );
62   verify( connect( myWorkSpace, SIGNAL( windowActivated( QWidget* ) ),
63                    this,        SLOT( onWindowActivated( QWidget* ) ) ) );
64 #ifdef OUTPUT_WINDOW
65   myOutput = new OutputWindow( 0 );
66   myOutput->show();
67 #else
68   myOutput = 0;
69 #endif\r
70         myViewDlg = NULL;\r
71 }
72
73 Application::~Application()
74 {\r
75         if (myViewDlg) delete myViewDlg; 
76   if (myOutput)  delete myOutput;
77 }
78
79 void Application::createActions()
80 {
81         QString dir = getResourceDir();
82   QPixmap newIcon( dir + tr( "ICON_NEW" ) ),
83           helpIcon( dir + tr( "ICON_HELP" ) ),
84           closeIcon( dir + tr( "ICON_CLOSE" ) ),
85           autoIcon( dir + tr( "ICON_AUTO_TEST" ) ),
86           optimIcon( dir + tr( "ICON_OPTIM" ) ),\r
87                             stopIcon( dir + tr( "ICON_STOP" ) ),
88           tileIcon( dir + tr( "ICON_TILE" ) ),
89           cascadeIcon( dir + tr( "ICON_CASCADE" ) );
90
91   // toolbar with standard actions: new, save...
92   myStdToolBar = new QToolBar( this );\r
93   addToolBar( Qt::TopToolBarArea, myStdToolBar );
94     
95   // menu with all actions
96   myFilePopup = menuBar()->addMenu( tr( "MEN_FILE" ) );
97     
98         // view menu
99         QMenu* view = menuBar()->addMenu( tr( "MEN_VIEW" ) );
100
101   // Tools menu (it is shown or hidden dynamically)
102   myToolsMenu = new QMenu( tr( "MEN_TOOLS" ), this );
103
104   // Window menu
105   myWinMenu = menuBar()->addMenu( tr( "MEN_WINDOWS" ) );
106   verify(connect( myWinMenu, SIGNAL( aboutToShow() ),
107                   this, SLOT( updateWindowList() ) ));
108
109   // add a help menu
110   QMenu* help = menuBar()->addMenu( tr( "MEN_HELP" ) );
111   menuBar()->addSeparator();
112     
113   QAction* a = new QAction( newIcon, tr( "MEN_NEW" ), this );\r
114   a->setToolTip( tr( "TBR_NEW" ) );\r
115   a->setShortcut( Qt::CTRL+Qt::Key_N );
116         verify( connect( a, SIGNAL( activated() ), this, SLOT( onNewDocument() ) ) );
117         myStdActions.insert( FileNewId, a );    \r
118   myStdToolBar->addAction( a );\r
119   myFilePopup ->addAction( a );
120
121   a = new QAction( tr( "MEN_QUIT" ), this );
122   a->setShortcut( Qt::CTRL+Qt::Key_Q );\r
123   a->setToolTip( tr( "TBR_QUIT" ) );\r
124   verify( connect( a, SIGNAL( activated() ), qApp, SLOT( closeAllWindows() ) ) );
125         myStdActions.insert( FileQuitId, a );   
126   myFilePopup ->addAction( a );\r
127
128         a = new QAction( tr( "MEN_TOOL_BAR" ), this );
129   a->setToolTip( tr( "TBR_TOOL_BAR" ) );\r
130         verify( connect( a, SIGNAL( activated() ), this, SLOT( onViewToolBar() ) ) );
131         a->setCheckable(true);
132         a->setChecked( true );
133         myStdActions.insert( ViewToolId, a );   
134   view->addAction( a );\r
135
136         a = new QAction( tr("MEN_STATUS_BAR"), this );
137   a->setToolTip( tr( "TBR_STATUS_BAR" ) );\r
138         verify( connect( a, SIGNAL( activated() ), this, SLOT( onViewStatusBar() ) ) );
139         a->setCheckable(true);
140         a->setChecked( true );
141         myStdActions.insert( ViewStatusId, a ); 
142   view->addAction( a );\r
143
144   a = new QAction( helpIcon, tr( "MEN_ABOUT" ), this );
145   a->setShortcut( Qt::Key_F1 );\r
146   a->setToolTip( tr( "TBR_ABOUT" ) );\r
147         verify( connect( a, SIGNAL( activated() ) , this, SLOT( onAbout() ) ) );
148         myStdActions.insert( HelpAboutId, a );  
149         myStdToolBar->addAction( a );
150         help->addAction( a );\r
151
152   myStdToolBar->addSeparator();
153
154   // Tools menu actions
155   a = new QAction( optimIcon, tr( "MEN_OPTIM" ), this );
156   a->setToolTip( tr( "TBR_OPTIM" ) );\r
157         verify( connect( a, SIGNAL( toggled(bool) ) , this, SLOT( onToggleOptim(bool) ) ) );
158   a->setCheckable(true);
159   a->setChecked(Graphic3d_ArrayOfPrimitives::IsEnable());
160         myStdActions.insert( OptimId, a );      
161   myToolsMenu->addAction( a );\r
162
163   a = new QAction( autoIcon, tr( "TBR_AUTO_TEST" ), this );
164   a->setToolTip( tr( "TBR_AUTO_TEST" ) );\r
165         verify( connect( a, SIGNAL( activated() ) , this, SLOT( onAutoTest() ) ) );
166         myStdActions.insert( AutoTestId, a );   
167   myToolsMenu->addAction( a );\r
168   \r
169   a = new QAction( stopIcon, tr( "TBR_STOP" ), this );\r
170   a->setToolTip( tr( "TBR_STOP" ) );\r
171         verify( connect( a, SIGNAL( activated() ) , this, SLOT( onStop() ) ) );\r
172         myStdActions.insert( StopId, a );       \r
173   myToolsMenu->addAction( a );\r
174
175   // Window menu action
176   a = new QAction( cascadeIcon, tr( "MEN_CASCADE" ), this );
177         verify( connect( a, SIGNAL( activated() ) , myWorkSpace, SLOT( cascade() ) ) );
178         myStdActions.insert( CascadeId, a );    
179   myWinMenu->addAction( a );\r
180
181   a = new QAction( tileIcon, tr( "MEN_TILE" ), this );
182         verify( connect( a, SIGNAL( activated() ), myWorkSpace, SLOT( tile() ) ) );
183         myStdActions.insert( TileId, a );       
184   myWinMenu->addAction( a );\r
185
186 }
187
188 void Application::createCCActions()
189 {
190         createIEPopups();
191 }
192
193 void Application::createIEPopups()
194 {
195         myImportPopup = new QMenu( tr( "MEN_FILE_IMPORT" ), this );
196
197         QAction* a = new QAction( tr( "MEN_IMPORT_BREP" ), this );\r
198   a->setToolTip( tr( "TBR_IMPORT_BREP" ) );
199         verify( connect( a, SIGNAL( activated() ) , SLOT( onTranslate() ) ) );
200         myCCActions.insert( FileImportBREPId, a );      
201         myImportPopup->addAction( a );
202 }
203
204 QWorkspace* Application::getWorkspace()
205 {
206   return getApplication()->workspace();
207 }
208
209 Application* Application::getApplication()
210 {
211         return stApp;
212 }
213
214 void Application::updateWindowList()
215 {
216   while ( myWinMenu->actions().count() > 2)
217     myWinMenu->removeAction(myWinMenu->actions().last());
218
219   QWidgetList lst = myWorkSpace->windowList();
220   if (!lst.isEmpty())
221   {
222     myWinMenu->addSeparator();
223     for ( int i = 0; i < int(lst.count()); ++i )
224     {
225       QAction* a = myWinMenu->addAction( lst.at(i)->windowTitle(),
226         this, SLOT( activateWindow() ) );\r
227       a->setCheckable( true );\r
228       a->setChecked( myWorkSpace->activeWindow() == lst.at(i) );
229     }
230   }
231
232 }
233
234 void Application::activateWindow()
235 {\r
236   QAction* a = qobject_cast<QAction*>( sender() );\r
237   if ( !a ) return;\r
238   int idx = myWinMenu->actions().indexOf( a ) - 3; // tile, cascade and separator
239   QWidget* w = myWorkSpace->windowList().at( idx );
240   if ( w ) {
241     w->showNormal();
242     w->setFocus();\r
243 //      w->setActiveWindow();
244   }
245 }
246
247 void Application::updateActions()
248 {
249         int count = myFilePopup->actions().count() - 1;
250         
251         int popupCount = menuBar()->actions().count();
252         while (myWinMenu->actions().count() > 2)
253                 myWinMenu->removeAction(myWinMenu->actions().last());
254
255         if( myWorkSpace->windowList().isEmpty() )
256   {
257     QAction* optim    = myStdActions.at(OptimId);
258     QAction* autoTest = myStdActions.at(AutoTestId);
259           QAction* stop = myStdActions.at(StopId);\r
260
261     if( myNbDocuments ) {
262       myFilePopup->insertMenu( myFilePopup->actions().last(), myImportPopup );
263                         myFilePopup->insertSeparator( myFilePopup->actions().last() );
264
265       menuBar()->insertMenu( menuBar()->actions().at( popupCount - 3 ), myToolsMenu );
266
267       if (optim) myStdToolBar->addAction( optim );
268       if (autoTest) myStdToolBar->addAction( autoTest );
269             if (stop) myStdToolBar->addAction( stop );\r
270             stop->setEnabled(false);
271                         myIsDocuments = true;
272                 } 
273     else {
274       myFilePopup->actions().removeAt( --count );
275                         myFilePopup->actions().removeAt( --count );
276                         myFilePopup->actions().removeAt( --count );
277
278       menuBar()->actions().removeAt( popupCount - 4 );
279
280       if (optim) myStdToolBar->removeAction( optim );
281       if (autoTest) myStdToolBar->removeAction( autoTest );
282             if (stop) myStdToolBar->removeAction( stop );
283                         myIsDocuments = false;
284     }
285   }
286 }
287
288 Document* Application::onNewDocument()
289 {
290   ++myNbDocuments;
291
292   updateActions();
293
294   Document* aDoc = new Document( myNbDocuments, this );
295   verify( connect( aDoc, SIGNAL( sendCloseDocument( Document* ) ),
296                    SLOT( onCloseDocument( Document* ) ) ) );
297
298   return aDoc;
299 }
300
301 void Application::onCloseDocument(Document* theDoc)
302 {
303   --myNbDocuments;
304   delete theDoc;
305         updateActions();
306 }
307
308 void Application::onTranslate()
309 {
310   const QObject* sentBy = sender();
311   typedef void  (Translate::*LPFN_IMPORT) 
312     ( const Handle( AIS_InteractiveContext ));//, const QString&  );
313
314   static LPFN_IMPORT lpfnImport[] = { &Translate::importBREP };
315
316   static QAction* actions[] = { myCCActions.at( FileImportBREPId ) };
317         
318   for ( int i = 0; i < sizeof(actions)/sizeof(QAction*); i++ )
319   {
320     if ( actions[i] == sentBy ) 
321     {
322       Translate* anTrans = new Translate( 0 );
323       MDIWindow* win = myActiveMDI;//(MDIWindow*) myWorkSpace->activeWindow(); 
324       Handle(AIS_InteractiveContext) aContext = win->getDocument()->getContext();
325       try 
326       {
327         /* import */
328         (anTrans->*lpfnImport[i])( aContext );
329       } 
330       catch ( Standard_Failure )
331       {
332                           /* WARNING: an exception raised but we eat it
333            silently because the shape seems OK
334         */                                                                              
335       }
336       delete anTrans;
337       /* commit transaction */
338       win->activateAction( ViewOperations::ViewFitAllId );
339       break;
340     }
341   }
342 }
343
344 void Application::importBREP()
345 {
346   Translate* anTrans = new Translate( 0 );
347   MDIWindow* win = myActiveMDI;//(MDIWindow*) myWorkSpace->activeWindow(); 
348   Handle(AIS_InteractiveContext) aContext = win->getDocument()->getContext();
349   try {
350     /* import */
351     anTrans->importBREP( aContext );
352   } 
353   catch ( Standard_Failure ) {
354     /* WARNING: an exception raised but we eat it
355        silently because the shape seems OK
356     */                    
357   }
358   delete anTrans;
359   win->activateAction( ViewOperations::ViewFitAllId );
360 }
361
362 QString Application::getResourceDir()
363 {
364   static QString resDir( getenv( "CSF_ResourcesDefaults" ) + QString( "/" ) );
365   return resDir;
366 }
367
368 void Application::onViewToolBar()
369 {
370   bool show = myStdActions.at( ViewToolId )->isChecked();
371   if (  show == myStdToolBar->isVisible() )
372     return;
373   if ( show )
374     myStdToolBar->show();
375   else
376     myStdToolBar->hide();
377 }
378
379 void Application::onViewStatusBar()
380 {
381   bool show = myStdActions.at( ViewStatusId )->isChecked();
382   if (  show == statusBar()->isVisible() )
383     return;\r
384   if ( show )\r
385     statusBar()->show();\r
386   else\r
387     statusBar()->hide();
388 }
389
390 void Application::onAbout()
391 {
392   QMessageBox::information(this,tr("TIT_ABOUT"),tr("INF_ABOUT"), tr("BTN_OK"),
393                                                QString::null, QString::null, 0, 0);
394 }
395
396 void Application::onQuit()
397 {
398 #ifdef aaa
399   QWidgetList aList = stWs->windowList();
400         for(MDIWindow* aWindow = (MDIWindow*) aList.first();aWindow;aWindow = (MDIWindow*) aList.next()) {
401           aWindow->closeEvent(0);
402   }
403
404         emit sendQuit();
405 #endif
406 }
407
408 MDIWindow* Application::getActiveMDI()
409 {
410   return myActiveMDI;
411 }
412
413 void Application::onWindowActivated( QWidget* w )
414 {
415   if ( w != NULL && w->inherits( "MDIWindow" ) ){
416     myActiveMDI = (MDIWindow*)w;\r
417                 w->setFocus();\r
418         }\r
419         else if (myViewDlg)\r
420         {\r
421     delete myViewDlg; myViewDlg = NULL; \r
422   }\r
423 }
424
425 void Application::startTimer()
426 {
427   timer.Reset();
428   timer.Start();
429 }
430
431 void Application::stopTimer( int count, const char* mes, bool addToGraph, int aOpt ) 
432 {
433   Standard_Integer m,h;
434   Standard_Real fps,elaps,cpu;
435   char title[256];
436   const char* message = ( mes == NULL ) ? "" : mes;
437
438   timer.Stop();
439   timer.Show( elaps, m, h, cpu );
440   elaps += m * 60. + h * 3600.;
441   fps = Standard_Real( count ) / elaps;
442   if( fps > 1. )
443     sprintf( title, " ====> '%s'. speed is %f frames/second", message, fps );
444   else {
445     if( count > 1 ) { 
446       elaps /= count; cpu /= count;
447       sprintf( title, " ====> '%s'. average elapsed/cpu time is %f/%f seconds", message, elaps, cpu );
448     }
449     else {
450       sprintf( title," ====> '%s'. elapsed/cpu time is %f/%f seconds.", message, elaps, cpu );
451     }
452   }
453     
454   if (addToGraph)
455   {
456     QString qmes(mes);
457     MDIWindow::ResultType type = MDIWindow::Undefined;
458     bool isOptOn = false;\r
459           if(aOpt >= 0) {\r
460                   isOptOn |= (aOpt > 0);\r
461           } else {\r
462                   isOptOn = Graphic3d_ArrayOfPrimitives::IsEnable();\r
463           }
464     if (qmes.contains(tr("MES_DISPLAY"), Qt::CaseInsensitive))
465       type = isOptOn ? MDIWindow::DisplayOpt : MDIWindow::DisplayNonOpt;
466     else if (qmes.contains(tr("MES_UPDATE"), Qt::CaseInsensitive))
467       type = isOptOn ? MDIWindow::UpdateOpt : MDIWindow::UpdateNonOpt;
468     if (type != MDIWindow::Undefined)
469     {
470       addResult(type, elaps);
471     }
472   }
473
474   QString str( title );
475   cout << title << endl;
476   Application::getApplication()->statusBar()->showMessage( str );
477   Application::getApplication()->showMessage( str );
478   //printf("%s\n",title);
479 }
480
481 void Application::showTimer( const char* mes )
482 {
483   Standard_Integer m,h;
484   Standard_Real elaps,cpu;
485   char title[256];
486   const char* message = ( mes == NULL) ? "" : mes;
487
488   timer.Show( elaps, m, h, cpu );
489   elaps += m * 60. + h * 3600.;
490   sprintf( title," ====> '%s'. elapsed/cpu time is %f/%f seconds", message, elaps, cpu );
491
492   QString str( title );
493   Application::getApplication()->statusBar()->showMessage( str );
494   Application::getApplication()->showMessage( str );
495   cout << title << endl;
496 }
497
498 void Application::showMessage( QString& message )
499 {
500 #ifdef OUTPUT_WINDOW
501   myOutput->print( message );
502 #endif
503 }
504
505 void Application::onToggleOptim(bool state)
506 {
507   state ? Graphic3d_ArrayOfPrimitives::Enable() : Graphic3d_ArrayOfPrimitives::Disable();
508 }
509
510 void Application::addResult(MDIWindow::ResultType item, double value)
511 {
512   MDIWindow* activeWin = getApplication()->getActiveMDI();
513   Handle(AIS_InteractiveContext) activeCtx = activeWin->getDocument()->getContext();
514
515   // Counting triangles...
516   int nbTriangles = 0;
517   AIS_ListOfInteractive displayedObjs;
518   activeCtx->DisplayedObjects(displayedObjs);
519   AIS_ListIteratorOfListOfInteractive dispIt(displayedObjs);
520   for ( ; dispIt.More(); dispIt.Next())
521   {
522     Handle(AIS_InteractiveObject) aisObj = dispIt.Value();
523     if (aisObj->IsKind(STANDARD_TYPE(Sphere_Sphere)))
524     {
525       Handle(Sphere_Sphere) sphere = Handle(Sphere_Sphere)::DownCast(aisObj);
526       Standard_Real rad            = sphere->Radius();
527       Standard_Real defl           = sphere->Sphere_BasicShape::Deflection();
528
529       nbTriangles += Sphere_Sphere::NbItems(Sphere_Sphere::NbPanes(rad, defl));
530     }
531     else if (aisObj->IsKind(STANDARD_TYPE(AIS_Shape)))
532     {
533       Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(aisObj);
534       TopoDS_Shape topoShape = shape->Shape();
535       TopExp_Explorer exp(topoShape, TopAbs_FACE);
536       for ( ; exp.More(); exp.Next())
537       {
538         TopoDS_Face face = TopoDS::Face(exp.Current());
539         if (!face.IsNull())
540         {
541           Handle(Poly_Triangulation) triangles = 
542             Handle(BRep_TFace)::DownCast(face.TShape())->Triangulation();
543           if (!triangles.IsNull()) 
544           {
545             nbTriangles += triangles->NbTriangles();
546           }
547         }
548       }
549     }
550   }
551   activeWin->addResult(item, nbTriangles, value);
552 }
553
554 QWorkspace* Application::workspace() const\r
555 {\r
556   return myWorkSpace;\r
557 }\r
558 \r
559 void Application::keyPressEvent(QKeyEvent* e)
560 {
561   if (e->key() == Qt::Key_Escape)
562     myEscPressed = true;
563 }
564
565 void Application::onAutoTest()
566 {
567   AutoTestDlg autoDlg(getApplication());
568   if (autoDlg.exec() == QDialog::Accepted)
569   {
570     QApplication::setOverrideCursor( Qt::WaitCursor );
571     myEscPressed = false;\r
572           myStopPressed = false;
573           QAction* stop = myStdActions.at(StopId);\r
574 \r
575           stop->setEnabled(true);\r
576
577     // Define the range for testing
578     int startItems = autoDlg.getStartNbItems(); 
579     int stopItems  = autoDlg.getStopNbItems();
580     int step       = autoDlg.getStep();\r
581           bool isTe        = autoDlg.isText();
582     if (stopItems < startItems) stopItems = startItems;
583
584     Standard_Real radius = 100; // default sphere radius
585     gp_Pnt        pos(0, 0, 0); // default sphere center position
586     
587     Handle(AIS_InteractiveContext) ctx = getActiveMDI()->getDocument()->getContext();
588     // Main loop
589     for (int currItems = startItems; currItems <= stopItems; currItems += step)
590     {
591       for (int useOptim = 0; useOptim < 2; useOptim++)
592       {
593         qApp->processEvents();
594         if (myEscPressed || myStopPressed)
595         {
596           QApplication::restoreOverrideCursor();\r
597           stop->setEnabled(false);
598           return;
599         }
600
601         // Toggle optimization
602         useOptim || isTe ? Graphic3d_ArrayOfPrimitives::Enable() : Graphic3d_ArrayOfPrimitives::Disable();
603         
604         // Remove all old objects
605         AIS_ListOfInteractive displayedObjs;
606         ctx->DisplayedObjects(displayedObjs);
607         AIS_ListIteratorOfListOfInteractive dispIt(displayedObjs);
608         for ( ; dispIt.More(); dispIt.Next())
609         {
610           Handle(AIS_InteractiveObject) obj = dispIt.Value();
611           if (!obj->IsKind(STANDARD_TYPE(AIS_Trihedron)))
612             ctx->Remove(obj, false);
613         }
614         ctx->UpdateCurrentViewer();\r
615 \r
616                     getActiveMDI()->getView()->SetScale(3.0316);
617         
618         // Generate new sphere
619         Standard_Integer nbPanes     = Sphere_Sphere::NbPanes(currItems);
620         Standard_Real    deflection  = Sphere_Sphere::Deflection(radius, nbPanes);
621         Handle(Sphere_Sphere) sphere = new Sphere_Sphere(pos, radius, deflection, 
622           1/*myVNormalsFlag*/, 0/*myVColorsFlag*/, 0/*myVTexelsFlag*/, isTe, useOptim);
623         
624         // Display the sphere
625         ctx->SetDisplayMode( sphere, getActiveMDI()->getDisplayMode(), false );
626         Application::startTimer();
627         ctx->Display( sphere, false );
628         Application::stopTimer( 0, "Display Sphere::Sphere", true, useOptim);
629
630         qApp->processEvents();\r
631         if (myEscPressed || myStopPressed)\r
632         {\r
633           QApplication::restoreOverrideCursor();\r
634                       stop->setEnabled(false);\r
635           return;\r
636         }\r
637 \r
638         // Update the viewer
639         Application::startTimer();
640         getActiveMDI()->getView()->Update();
641         Application::stopTimer( 0, "UPDATE", true, useOptim);\r
642       }\r
643     }
644     QApplication::restoreOverrideCursor();\r
645           stop->setEnabled(false);
646   }
647 }
648
649 /* ------------------ class OutputWindow ----------------- */
650 OutputWindow::OutputWindow( QWidget* parent ) : QWidget( parent ), myLineCounter( 0 )
651 {
652   setWindowTitle( "Output window" );
653   resize( 400, 300 );
654
655   QVBoxLayout* topLayout = new QVBoxLayout( this );
656   myLineEdit = new QTextEdit( this );
657
658   topLayout->addWidget( myLineEdit );
659 }
660
661 OutputWindow::~OutputWindow()
662 {
663 }
664
665 void OutputWindow::print( QString& s )
666 {
667   myLineEdit->append( QString().setNum( myLineCounter ) + s );
668   myLineCounter++;
669 }
670 \r
671 void Application::InitApp()\r
672 {\r
673         onNewDocument();\r
674 }\r
675 \r
676 void Application::onStop()\r
677 {\r
678         myStopPressed = true;\r
679 }\r
680 \r
681 void Application::onEditViewProperties()\r
682 {\r
683   if ( !myViewDlg ) {\r
684     myViewDlg = new ViewDlg(this);\r
685     verify( connect( myWorkSpace, SIGNAL( windowActivated( QWidget* ) ),\r
686                      myViewDlg,   SLOT( Update() ) ) );\r
687         }\r
688         myViewDlg->raise();\r
689         myViewDlg->show();\r
690 }\r
691 \r
692 void Application::updateViewDlg()\r
693 {\r
694         if(myViewDlg) myViewDlg->Update();\r
695 }