mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Updated to use Qt6; Created initial structure of the viewer with OpenGL widget
This commit is contained in:
committed by
Thomas Krijnen
parent
b6f2fdef77
commit
10aca77de4
+27
-10
@@ -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}
|
||||
)
|
||||
${IFCLIBS}
|
||||
Qt${QT_VERSION}::Core
|
||||
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 <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);
|
||||
|
||||
//QGLViewer viewer;
|
||||
|
||||
// Restore the previous viewer state.
|
||||
//viewer.restoreStateFromFile();
|
||||
|
||||
MainWindow window;
|
||||
//window.openFile(" ");
|
||||
QApplication app(argc, argv);
|
||||
|
||||
MainWindow window;
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
|
||||
+76
-66
@@ -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 <math.h>
|
||||
#include "MainWindow.h"
|
||||
#include "ParseIfcFile.h"
|
||||
#include "IfcViewerWidget.h"
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
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);
|
||||
}
|
||||
+17
-23
@@ -1,39 +1,32 @@
|
||||
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <qobject.h>
|
||||
#include <QObject>
|
||||
#include <QMainWindow>
|
||||
#include <QString>
|
||||
#include "../ifcgeom/IfcGeomObjects.h"
|
||||
|
||||
class ObjectsView;
|
||||
|
||||
class QGLViewer;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QGraphicsView;
|
||||
class QGraphicsScene;
|
||||
class QGraphicsRectItem;
|
||||
QT_END_NAMESPACE
|
||||
#include <QAction>
|
||||
#include <QOpenGLWidget>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user