0024055: Reading a STEP file produces invalid shape
[occt.git] / samples / qt / Common / src / MDIWindow.cxx
CommitLineData
7fd59977 1#include "MDIWindow.h"
2
3#include "View.h"
4#include "DocumentCommon.h"
5#include "ApplicationCommon.h"
6
7#include <QFrame>
8#include <QToolBar>
9#include <QFileDialog>
10#include <QMessageBox>
11#include <QApplication>
12#include <QDir>
13#include <QFile>
14#include <QFileInfo>
15#include <QMainWindow>
16#include <QVBoxLayout>
17
18MDIWindow::MDIWindow(View* aView,
19 DocumentCommon* aDocument,
20 QWidget* parent,
21 Qt::WindowFlags wflags )
22: QMainWindow( parent, wflags )
23{
7fd59977 24 myView = aView;
25 myDocument = aDocument;
26}
27
861a7b03 28MDIWindow::MDIWindow( DocumentCommon* aDocument, QWidget* parent, Qt::WindowFlags wflags)
7fd59977 29: QMainWindow( parent, wflags )
30{
31 QFrame *vb = new QFrame( this );
32
33 QVBoxLayout *layout = new QVBoxLayout( vb );
34 layout->setMargin( 0 );
35
36 vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
37
38 setCentralWidget( vb );
39
40 myDocument = aDocument;
861a7b03 41 myView = new View (myDocument->getContext(), vb);
42 layout->addWidget (myView);
7fd59977 43
44 connect( myView, SIGNAL( selectionChanged() ),
45 this, SIGNAL( selectionChanged() ) );
861a7b03 46
47 createViewActions();
48 createRaytraceActions();
7fd59977 49
50 resize( sizeHint() );
51
52 setFocusPolicy( Qt::StrongFocus );
53}
54
55MDIWindow::~MDIWindow()
56{
57}
58
59DocumentCommon* MDIWindow::getDocument()
60{
61 return myDocument;
62}
63
de75ed09 64void MDIWindow::closeEvent(QCloseEvent* )
7fd59977 65{
66 emit sendCloseView(this);
67}
68
69void MDIWindow::fitAll()
70{
71 myView->fitAll();
72}
73
74void MDIWindow::createViewActions()
75{
76 // populate a tool bar with some actions
77 QToolBar* aToolBar = addToolBar( tr( "View Operations" ) );
78
79 QList<QAction*>* aList = myView->getViewActions();
80 aToolBar->addActions( *aList );
81
82 aToolBar->toggleViewAction()->setVisible(false);
83 aList->at(View::ViewHlrOffId)->setChecked( true );
84}
85
861a7b03 86void MDIWindow::createRaytraceActions()
87{
88 // populate a tool bar with some actions
89 QToolBar* aToolBar = addToolBar( tr( "Ray-tracing Options" ) );
90
91 QList<QAction*>* aList = myView->getRaytraceActions();
92 aToolBar->addActions( *aList );
93
94 aToolBar->toggleViewAction()->setVisible (true);
95 aList->at (View::ToolRaytracingId)->setChecked (false);
96 aList->at (View::ToolShadowsId)->setChecked (true);
97 aList->at (View::ToolReflectionsId)->setChecked (true);
98 aList->at (View::ToolAntialiasingId)->setChecked (false);
99}
100
7fd59977 101void MDIWindow::onWindowActivated ()
102{
103 getDocument()->getApplication()->onSelectionChanged();
104}
105
7fd59977 106void MDIWindow::dump()
107{
861a7b03 108 QString datadir = (QString(qgetenv ("CASROOT").constData()) + "/../data/images");
7fd59977 109 static QString filter;
1d8ec4db 110 filter = "Images Files (*.bmp *.ppm *.png *.jpg *.tiff *.tga *.gif *.exr *.ps *.eps *.tex *.pdf *.svg *.pgf)";
7fd59977 111 QFileDialog fd ( 0 );
112 fd.setModal( true );
861a7b03 113 fd.setNameFilter ( filter );
7fd59977 114 fd.setWindowTitle( QObject::tr("INF_APP_EXPORT") );
115 fd.setFileMode( QFileDialog::AnyFile );
116 int ret = fd.exec();
117
118 /* update the desktop after the dialog is closed */
119 qApp->processEvents();
120
121 QStringList fileNames;
122 fileNames = fd.selectedFiles();
123
124 QString file ( (ret == QDialog::Accepted && !fileNames.isEmpty() )? fileNames[0] : QString::null);
125 if ( !file.isNull() )
126 {
127 QApplication::setOverrideCursor( Qt::WaitCursor );
128 if ( !QFileInfo( file ).completeSuffix().length() )
129 file += QString( ".bmp" );
861a7b03 130
7fd59977 131 bool res = myView->dump( (Standard_CString)file.toLatin1().constData() );
132 QApplication::restoreOverrideCursor();
133 if ( !res )
134 {
135 QWidgetList list = qApp->allWidgets();
136 QWidget* mainWidget;
137 for( int i = 0; i < list.size(); ++i )
138 {
139 if( qobject_cast<ApplicationCommonWindow*>( list.at( i ) ) )
140 mainWidget = qobject_cast<ApplicationCommonWindow*>( list.at( i ) );
141 }
142
143 QMessageBox::information ( mainWidget, QObject::tr("TIT_ERROR"), QObject::tr("INF_ERROR"), QObject::tr("BTN_OK"),
144 QString::null, QString::null, 0, 0 );
145 qApp->processEvents();
146 }
147 }
148}
149
150QSize MDIWindow::sizeHint() const
151{
152 return QSize( 450, 300 );
153}