|
| 1 | + |
| 2 | + |
| 3 | +#include "mainwindow.h" |
| 4 | +#include <math.h> |
| 5 | + |
| 6 | +#include <QtGui> |
| 7 | + |
| 8 | +MainWindow::MainWindow() |
| 9 | + : QMainWindow() |
| 10 | +{ |
| 11 | + |
| 12 | + |
| 13 | + IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true); |
| 14 | + IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false); |
| 15 | + IfcGeomObjects::Settings(IfcGeomObjects::SEW_SHELLS,true); |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + QMenu *fileMenu = new QMenu(tr("&File"), this); |
| 20 | + QAction *openAction = fileMenu->addAction(tr("&Open...")); |
| 21 | + openAction->setShortcut(QKeySequence(tr("Ctrl+O"))); |
| 22 | + QAction *quitAction = fileMenu->addAction(tr("E&xit")); |
| 23 | + quitAction->setShortcuts(QKeySequence::Quit); |
| 24 | + |
| 25 | + menuBar()->addMenu(fileMenu); |
| 26 | + |
| 27 | + QMenu *viewMenu = new QMenu(tr("&View"), this); |
| 28 | + m_backgroundAction = viewMenu->addAction(tr("&Background")); |
| 29 | + m_backgroundAction->setEnabled(false); |
| 30 | + m_backgroundAction->setCheckable(true); |
| 31 | + m_backgroundAction->setChecked(false); |
| 32 | + //connect(m_backgroundAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewBackground(bool))); |
| 33 | + |
| 34 | + m_outlineAction = viewMenu->addAction(tr("&Outline")); |
| 35 | + m_outlineAction->setEnabled(false); |
| 36 | + m_outlineAction->setCheckable(true); |
| 37 | + m_outlineAction->setChecked(true); |
| 38 | + // connect(m_outlineAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewOutline(bool))); |
| 39 | + |
| 40 | + menuBar()->addMenu(viewMenu); |
| 41 | + |
| 42 | + connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); |
| 43 | + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); |
| 44 | + |
| 45 | + //setCentralWidget((QWidget*)m_v); |
| 46 | + setWindowTitle(tr("IfcOpenShell QT Viewer")); |
| 47 | +} |
| 48 | + |
| 49 | +void MainWindow::openFile(const QString &path) |
| 50 | +{ |
| 51 | + QString fileName; |
| 52 | + if (path.isNull()) |
| 53 | + fileName = QFileDialog::getOpenFileName(this, tr("Open IFC"), |
| 54 | + m_currentPath, "IFC files (*.ifc)"); |
| 55 | + else |
| 56 | + fileName = path; |
| 57 | + |
| 58 | + if (!fileName.isEmpty()) { |
| 59 | + QFile file(fileName); |
| 60 | + if (!file.exists()) { |
| 61 | + QMessageBox::critical(this, tr("Open IFC"), |
| 62 | + QString("Could not open file '%1'.").arg(fileName)); |
| 63 | + |
| 64 | + m_outlineAction->setEnabled(false); |
| 65 | + m_backgroundAction->setEnabled(false); |
| 66 | + return; |
| 67 | + } |
| 68 | + std::stringstream ss; |
| 69 | + if ( ! IfcGeomObjects::Init(fileName.toStdString(),&std::cout,&ss) ) { |
| 70 | + QMessageBox::critical(this, tr("Open IFC"), |
| 71 | + QString("[Error] unable to parse file '%1'. Or no geometrical entities found" ).arg(fileName)); |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + //connect((QWidget*)m_view, SIGNAL(drawNeeded()), this, SLOT(drawIfcObject())); |
| 76 | + |
| 77 | + if (!fileName.startsWith(":/")) { |
| 78 | + m_currentPath = fileName; |
| 79 | + setWindowTitle(tr("%1 - IFCViewer").arg(m_currentPath)); |
| 80 | + } |
| 81 | + |
| 82 | + m_outlineAction->setEnabled(true); |
| 83 | + m_backgroundAction->setEnabled(true); |
| 84 | + |
| 85 | +// resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height())); |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +void MainWindow::draw() |
| 91 | +{ |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +} |
| 96 | + |
| 97 | + |
0 commit comments