diff --git a/src/qtviewer/CMakeLists.txt b/src/qtviewer/CMakeLists.txt index 473013a726..1f4df8ce84 100644 --- a/src/qtviewer/CMakeLists.txt +++ b/src/qtviewer/CMakeLists.txt @@ -20,22 +20,39 @@ cmake_minimum_required(VERSION 3.1.3) message("Running CMakeLists.txt in /src/qtviewer") -message("Provide the path to Qt5 via CMAKE_PREFIX_PATH") -find_package(Qt5 COMPONENTS Core Gui OpenGL Widgets REQUIRED) +# Specify the Qt version and components to use +set(QT_VERSION 6 CACHE STRING "Qt version") +set(QT_COMPONENTS Core Gui OpenGL OpenGLWidgets Widgets CACHE STRING "Qt components") + +find_package(Qt${QT_VERSION} COMPONENTS ${QT_COMPONENTS} REQUIRED PATHS ${QT_DIR}) + +if(Qt${QT_VERSION}_FOUND) + message(STATUS "Found Qt Version: ${Qt${QT_VERSION}_VERSION}") +endif() add_executable(QtViewer - ../../src/qtviewer/mainwindow.h - ../../src/qtviewer/mainwindow.cpp - ../../src/qtviewer/main.cpp + IfcViewerWidget.h + IfcViewerWidget.cpp + ParseIfcFile.h + ParseIfcFile.cpp + MainWindow.h + MainWindow.cpp + main.cpp ) set_target_properties(QtViewer PROPERTIES - AUTOMOC On + AUTOMOC On + WIN32_EXECUTABLE ON + MACOSX_BUNDLE ON ) target_link_libraries(QtViewer - ${IFCLIBS} - Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Widgets - ${OPENCASCADE_LIBRARIES} -) \ No newline at end of file + ${IFCLIBS} + Qt${QT_VERSION}::Core + Qt${QT_VERSION}::Gui + Qt${QT_VERSION}::OpenGL + Qt${QT_VERSION}::OpenGLWidgets + Qt${QT_VERSION}::Widgets + ${OPENCASCADE_LIBRARIES} +) diff --git a/src/qtviewer/IfcViewerWidget.cpp b/src/qtviewer/IfcViewerWidget.cpp new file mode 100644 index 0000000000..c2a77bed83 --- /dev/null +++ b/src/qtviewer/IfcViewerWidget.cpp @@ -0,0 +1,27 @@ +#include "IfcViewerWidget.h" + +IfcViewerWidget::IfcViewerWidget(QWidget *parent) + : QOpenGLWidget(parent) +{} + +void IfcViewerWidget::initializeGL() +{ + // Set up the rendering context, load shaders and other resources, etc.: + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); + f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f); +} + +void IfcViewerWidget::resizeGL(int w, int h) +{ + // Update projection matrix and other size related settings: + m_projection.setToIdentity(); + m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f); +} + +void IfcViewerWidget::paintGL() +{ + // Render geometries from the parsed IFC file + // Draw the scene: + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); + f->glClear(GL_COLOR_BUFFER_BIT); +} diff --git a/src/qtviewer/IfcViewerWidget.h b/src/qtviewer/IfcViewerWidget.h new file mode 100644 index 0000000000..8ce7937069 --- /dev/null +++ b/src/qtviewer/IfcViewerWidget.h @@ -0,0 +1,23 @@ +#ifndef IFCVIEWERWIDGET_H +#define IFCVIEWERWIDGET_H + +#include +#include +#include +#include + +class IfcViewerWidget : public QOpenGLWidget +{ +public: + IfcViewerWidget(QWidget *parent = nullptr); + +protected: + void initializeGL() override; + void resizeGL(int w, int h) override; + void paintGL() override; + +private: + QMatrix4x4 m_projection; +}; + +#endif // IFCVIEWERWIDGET_H \ No newline at end of file diff --git a/src/qtviewer/ParseIfcFile.cpp b/src/qtviewer/ParseIfcFile.cpp new file mode 100644 index 0000000000..9a597796d9 --- /dev/null +++ b/src/qtviewer/ParseIfcFile.cpp @@ -0,0 +1,15 @@ +#include "ParseIfcFile.h" + +#include "../ifcparse/Ifc2x3.h" +#define IfcSchema Ifc2x3 + +#include "../ifcgeom/IfcGeom.h" + +ParseIfcFile::ParseIfcFile() {} + +ParseIfcFile::~ParseIfcFile() {} + +void ParseIfcFile::Parse(const std::string& filePath) +{ + //IfcParse::IfcFile ifcFile(filePath); +} \ No newline at end of file diff --git a/src/qtviewer/ParseIfcFile.h b/src/qtviewer/ParseIfcFile.h new file mode 100644 index 0000000000..5c72ed850b --- /dev/null +++ b/src/qtviewer/ParseIfcFile.h @@ -0,0 +1,15 @@ +#ifndef PARSEIFCFILE_H +#define PARSEIFCFILE_H + +#include + +class ParseIfcFile +{ +public: + ParseIfcFile(); + ~ParseIfcFile(); + + void Parse(const std::string& filePath); +}; + +#endif // PARSEIFCFILE_H \ No newline at end of file diff --git a/src/qtviewer/main.cpp b/src/qtviewer/main.cpp index c0171fef3b..b65d413813 100644 --- a/src/qtviewer/main.cpp +++ b/src/qtviewer/main.cpp @@ -1,24 +1,12 @@ - +#include "MainWindow.h" + #include -#include -#ifndef QT_NO_OPENGL -#include -#endif -#include "mainwindow.h" - -int main(int argc, char **argv) +int main(int argc, char *argv[]) { - QApplication app(argc, argv); - - //QGLViewer viewer; - - // Restore the previous viewer state. - //viewer.restoreStateFromFile(); - - MainWindow window; - //window.openFile(" "); + QApplication app(argc, argv); + MainWindow window; window.show(); return app.exec(); diff --git a/src/qtviewer/mainwindow.cpp b/src/qtviewer/mainwindow.cpp index cdc0d18bf3..c666353c82 100644 --- a/src/qtviewer/mainwindow.cpp +++ b/src/qtviewer/mainwindow.cpp @@ -1,97 +1,107 @@ - +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "mainwindow.h" -#include +#include "MainWindow.h" +#include "ParseIfcFile.h" +#include "IfcViewerWidget.h" -#include - -MainWindow::MainWindow() - : QMainWindow() +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) { + this->setWindowTitle("IfcOpenShell Viewer"); + this->resize(800, 600); //temporary reasonable initial size + m_glWidget = new IfcViewerWidget(this); + setCentralWidget(m_glWidget); - IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true); - IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false); - IfcGeomObjects::Settings(IfcGeomObjects::SEW_SHELLS,true); + createActions(); + createMenus(); + createConnections(); +} - - - QMenu *fileMenu = new QMenu(tr("&File"), this); - QAction *openAction = fileMenu->addAction(tr("&Open...")); +void MainWindow::createActions() +{ + openAction = new QAction(tr("&Open"), this); openAction->setShortcut(QKeySequence(tr("Ctrl+O"))); - QAction *quitAction = fileMenu->addAction(tr("E&xit")); - quitAction->setShortcuts(QKeySequence::Quit); - menuBar()->addMenu(fileMenu); + quitAction = new QAction(tr("E&xit"), this); + quitAction->setShortcut(QKeySequence::Quit); - QMenu *viewMenu = new QMenu(tr("&View"), this); - m_backgroundAction = viewMenu->addAction(tr("&Background")); + m_backgroundAction = new QAction(tr("&Background")); m_backgroundAction->setEnabled(false); m_backgroundAction->setCheckable(true); m_backgroundAction->setChecked(false); - //connect(m_backgroundAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewBackground(bool))); - m_outlineAction = viewMenu->addAction(tr("&Outline")); + m_outlineAction = new QAction(tr("&Outline")); m_outlineAction->setEnabled(false); m_outlineAction->setCheckable(true); - m_outlineAction->setChecked(true); - // connect(m_outlineAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewOutline(bool))); + m_outlineAction->setChecked(false); +} - menuBar()->addMenu(viewMenu); +void MainWindow::createMenus() +{ + QMenuBar *menuBar = new QMenuBar(); + setMenuBar(menuBar); + fileMenu = new QMenu(tr("&File"), menuBar); + menuBar->addMenu(fileMenu); + + fileMenu->addAction(openAction); + fileMenu->addAction(quitAction); + + viewMenu = new QMenu(tr("&View"), menuBar); + menuBar->addMenu(viewMenu); + + viewMenu->addAction(m_backgroundAction); + viewMenu->addAction(m_outlineAction); +} + +void MainWindow::createConnections() +{ connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - - //setCentralWidget((QWidget*)m_v); - setWindowTitle(tr("IfcOpenShell QT Viewer")); + //connect(m_backgroundAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewBackground(bool))); + //connect(m_outlineAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewOutline(bool))); } -void MainWindow::openFile(const QString &path) +void MainWindow::openFile() { - QString fileName; - if (path.isNull()) - fileName = QFileDialog::getOpenFileName(this, tr("Open IFC"), - m_currentPath, "IFC files (*.ifc)"); - else - fileName = path; + QString filePath = QFileDialog::getOpenFileName(this, tr("Open IFC File"), + ".", tr("IFC Files (*.ifc)")); - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.exists()) { - QMessageBox::critical(this, tr("Open IFC"), - QString("Could not open file '%1'.").arg(fileName)); + QFileInfo fileInfo(filePath); + QString fileName = fileInfo.fileName(); - m_outlineAction->setEnabled(false); - m_backgroundAction->setEnabled(false); - return; - } - std::stringstream ss; - if ( ! IfcGeomObjects::Init(fileName.toStdString(),&std::cout,&ss) ) { - QMessageBox::critical(this, tr("Open IFC"), - QString("[Error] unable to parse file '%1'. Or no geometrical entities found" ).arg(fileName)); - return; - } + if (fileName.isEmpty()) + return; - //connect((QWidget*)m_view, SIGNAL(drawNeeded()), this, SLOT(drawIfcObject())); + // Check if the file is a Qt resource file + if (fileName.startsWith(":/")) + return; - if (!fileName.startsWith(":/")) { - m_currentPath = fileName; - setWindowTitle(tr("%1 - IFCViewer").arg(m_currentPath)); - } + QFile file(filePath); + if (!file.exists()) { + QMessageBox::critical(this, tr("Open IFC"), + QString("Could not open '%1'.").arg(filePath)); - m_outlineAction->setEnabled(true); - m_backgroundAction->setEnabled(true); - -// resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height())); + m_outlineAction->setEnabled(false); + m_backgroundAction->setEnabled(false); + return; } -} + ParseIfcFile parser; + parser.Parse(filePath.toStdString()); -void MainWindow::draw() -{ - - - -} - + m_currentPath = filePath; + setWindowTitle(tr("%1 - IFCViewer").arg(fileName)); + m_outlineAction->setEnabled(true); + m_backgroundAction->setEnabled(true); +} \ No newline at end of file diff --git a/src/qtviewer/mainwindow.h b/src/qtviewer/mainwindow.h index a62e823815..bee337be3a 100644 --- a/src/qtviewer/mainwindow.h +++ b/src/qtviewer/mainwindow.h @@ -1,39 +1,32 @@ - - -#ifndef MAINWINDOW_H +#ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include #include #include -#include "../ifcgeom/IfcGeomObjects.h" - -class ObjectsView; - -class QGLViewer; - -QT_BEGIN_NAMESPACE -class QAction; -class QGraphicsView; -class QGraphicsScene; -class QGraphicsRectItem; -QT_END_NAMESPACE +#include +#include class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(); - - -public Q_SLOTS: - void draw(); + MainWindow(QWidget *parent = nullptr); public slots: - void openFile(const QString &path = QString()); + void openFile(); private: + void createActions(); + void createMenus(); + void createConnections(); +private: + QMenu *fileMenu; + QAction *openAction; + QAction *quitAction; + + QMenu *viewMenu; QAction *m_nativeAction; QAction *m_glAction; QAction *m_imageAction; @@ -42,6 +35,7 @@ private: QAction *m_outlineAction; QString m_currentPath; + QOpenGLWidget *m_glWidget; }; -#endif +#endif // MAINWINDOW_H