mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 08:33:10 +00:00
Updated to use Qt6; Created initial structure of the viewer with OpenGL widget
This commit is contained in:
@@ -20,22 +20,39 @@
|
|||||||
cmake_minimum_required(VERSION 3.1.3)
|
cmake_minimum_required(VERSION 3.1.3)
|
||||||
|
|
||||||
message("Running CMakeLists.txt in /src/qtviewer")
|
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
|
add_executable(QtViewer
|
||||||
../../src/qtviewer/mainwindow.h
|
IfcViewerWidget.h
|
||||||
../../src/qtviewer/mainwindow.cpp
|
IfcViewerWidget.cpp
|
||||||
../../src/qtviewer/main.cpp
|
ParseIfcFile.h
|
||||||
|
ParseIfcFile.cpp
|
||||||
|
MainWindow.h
|
||||||
|
MainWindow.cpp
|
||||||
|
main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(QtViewer PROPERTIES
|
set_target_properties(QtViewer PROPERTIES
|
||||||
AUTOMOC On
|
AUTOMOC On
|
||||||
|
WIN32_EXECUTABLE ON
|
||||||
|
MACOSX_BUNDLE ON
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(QtViewer
|
target_link_libraries(QtViewer
|
||||||
${IFCLIBS}
|
${IFCLIBS}
|
||||||
Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Widgets
|
Qt${QT_VERSION}::Core
|
||||||
${OPENCASCADE_LIBRARIES}
|
Qt${QT_VERSION}::Gui
|
||||||
|
Qt${QT_VERSION}::OpenGL
|
||||||
|
Qt${QT_VERSION}::OpenGLWidgets
|
||||||
|
Qt${QT_VERSION}::Widgets
|
||||||
|
${OPENCASCADE_LIBRARIES}
|
||||||
)
|
)
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef IFCVIEWERWIDGET_H
|
||||||
|
#define IFCVIEWERWIDGET_H
|
||||||
|
|
||||||
|
#include <QOpenGLWidget>
|
||||||
|
#include <QOpenGLFunctions>
|
||||||
|
#include <QOpenGLContext>
|
||||||
|
#include <QMatrix4x4>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef PARSEIFCFILE_H
|
||||||
|
#define PARSEIFCFILE_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class ParseIfcFile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ParseIfcFile();
|
||||||
|
~ParseIfcFile();
|
||||||
|
|
||||||
|
void Parse(const std::string& filePath);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARSEIFCFILE_H
|
||||||
+5
-17
@@ -1,24 +1,12 @@
|
|||||||
|
#include "MainWindow.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QString>
|
|
||||||
#ifndef QT_NO_OPENGL
|
|
||||||
#include <QGLFormat>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "mainwindow.h"
|
int main(int argc, char *argv[])
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
//QGLViewer viewer;
|
|
||||||
|
|
||||||
// Restore the previous viewer state.
|
|
||||||
//viewer.restoreStateFromFile();
|
|
||||||
|
|
||||||
MainWindow window;
|
|
||||||
//window.openFile(" ");
|
|
||||||
|
|
||||||
|
MainWindow window;
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|||||||
+78
-68
@@ -1,97 +1,107 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "MainWindow.h"
|
||||||
#include <math.h>
|
#include "ParseIfcFile.h"
|
||||||
|
#include "IfcViewerWidget.h"
|
||||||
|
|
||||||
#include <QtGui>
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
: QMainWindow(parent)
|
||||||
MainWindow::MainWindow()
|
|
||||||
: QMainWindow()
|
|
||||||
{
|
{
|
||||||
|
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);
|
createActions();
|
||||||
IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false);
|
createMenus();
|
||||||
IfcGeomObjects::Settings(IfcGeomObjects::SEW_SHELLS,true);
|
createConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createActions()
|
||||||
|
{
|
||||||
QMenu *fileMenu = new QMenu(tr("&File"), this);
|
openAction = new QAction(tr("&Open"), this);
|
||||||
QAction *openAction = fileMenu->addAction(tr("&Open..."));
|
|
||||||
openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
|
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 = new QAction(tr("&Background"));
|
||||||
m_backgroundAction = viewMenu->addAction(tr("&Background"));
|
|
||||||
m_backgroundAction->setEnabled(false);
|
m_backgroundAction->setEnabled(false);
|
||||||
m_backgroundAction->setCheckable(true);
|
m_backgroundAction->setCheckable(true);
|
||||||
m_backgroundAction->setChecked(false);
|
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->setEnabled(false);
|
||||||
m_outlineAction->setCheckable(true);
|
m_outlineAction->setCheckable(true);
|
||||||
m_outlineAction->setChecked(true);
|
m_outlineAction->setChecked(false);
|
||||||
// connect(m_outlineAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewOutline(bool)));
|
}
|
||||||
|
|
||||||
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(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
|
||||||
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
|
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
|
||||||
|
//connect(m_backgroundAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewBackground(bool)));
|
||||||
//setCentralWidget((QWidget*)m_v);
|
//connect(m_outlineAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewOutline(bool)));
|
||||||
setWindowTitle(tr("IfcOpenShell QT Viewer"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openFile(const QString &path)
|
void MainWindow::openFile()
|
||||||
{
|
{
|
||||||
QString fileName;
|
QString filePath = QFileDialog::getOpenFileName(this, tr("Open IFC File"),
|
||||||
if (path.isNull())
|
".", tr("IFC Files (*.ifc)"));
|
||||||
fileName = QFileDialog::getOpenFileName(this, tr("Open IFC"),
|
|
||||||
m_currentPath, "IFC files (*.ifc)");
|
|
||||||
else
|
|
||||||
fileName = path;
|
|
||||||
|
|
||||||
if (!fileName.isEmpty()) {
|
QFileInfo fileInfo(filePath);
|
||||||
QFile file(fileName);
|
QString fileName = fileInfo.fileName();
|
||||||
if (!file.exists()) {
|
|
||||||
QMessageBox::critical(this, tr("Open IFC"),
|
|
||||||
QString("Could not open file '%1'.").arg(fileName));
|
|
||||||
|
|
||||||
m_outlineAction->setEnabled(false);
|
if (fileName.isEmpty())
|
||||||
m_backgroundAction->setEnabled(false);
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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(":/")) {
|
QFile file(filePath);
|
||||||
m_currentPath = fileName;
|
if (!file.exists()) {
|
||||||
setWindowTitle(tr("%1 - IFCViewer").arg(m_currentPath));
|
QMessageBox::critical(this, tr("Open IFC"),
|
||||||
}
|
QString("Could not open '%1'.").arg(filePath));
|
||||||
|
|
||||||
m_outlineAction->setEnabled(true);
|
m_outlineAction->setEnabled(false);
|
||||||
m_backgroundAction->setEnabled(true);
|
m_backgroundAction->setEnabled(false);
|
||||||
|
return;
|
||||||
// resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParseIfcFile parser;
|
||||||
|
parser.Parse(filePath.toStdString());
|
||||||
|
|
||||||
|
m_currentPath = filePath;
|
||||||
|
setWindowTitle(tr("%1 - IFCViewer").arg(fileName));
|
||||||
|
|
||||||
|
m_outlineAction->setEnabled(true);
|
||||||
|
m_backgroundAction->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::draw()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+17
-23
@@ -1,39 +1,32 @@
|
|||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
|
||||||
#ifndef MAINWINDOW_H
|
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <qobject.h>
|
#include <QObject>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "../ifcgeom/IfcGeomObjects.h"
|
#include <QAction>
|
||||||
|
#include <QOpenGLWidget>
|
||||||
class ObjectsView;
|
|
||||||
|
|
||||||
class QGLViewer;
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QAction;
|
|
||||||
class QGraphicsView;
|
|
||||||
class QGraphicsScene;
|
|
||||||
class QGraphicsRectItem;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow();
|
MainWindow(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void draw();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void openFile(const QString &path = QString());
|
void openFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void createActions();
|
||||||
|
void createMenus();
|
||||||
|
void createConnections();
|
||||||
|
private:
|
||||||
|
QMenu *fileMenu;
|
||||||
|
QAction *openAction;
|
||||||
|
QAction *quitAction;
|
||||||
|
|
||||||
|
QMenu *viewMenu;
|
||||||
QAction *m_nativeAction;
|
QAction *m_nativeAction;
|
||||||
QAction *m_glAction;
|
QAction *m_glAction;
|
||||||
QAction *m_imageAction;
|
QAction *m_imageAction;
|
||||||
@@ -42,6 +35,7 @@ private:
|
|||||||
QAction *m_outlineAction;
|
QAction *m_outlineAction;
|
||||||
|
|
||||||
QString m_currentPath;
|
QString m_currentPath;
|
||||||
|
QOpenGLWidget *m_glWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user