diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2817c767e9..c16c2287ba 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -126,6 +126,8 @@ ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap) # Build IfcParseExamples using separate CMakeLists.txt ADD_SUBDIRECTORY(../src/examples examples) +ADD_SUBDIRECTORY(../src/qtviewer qtviewer) + # CMake installation targets SET(include_files_geom ../src/ifcgeom/IfcGeom.h diff --git a/src/qtviewer/CMakeLists.txt b/src/qtviewer/CMakeLists.txt new file mode 100644 index 0000000000..a3e14b476b --- /dev/null +++ b/src/qtviewer/CMakeLists.txt @@ -0,0 +1,47 @@ + +OPTION( QT_USE_QTVIEWER "IfcOpenShell QT GUI Viewer, QT environment required" OFF ) + + +IF (QT_USE_QTVIEWER) + + +# Find QT header files +SET(QT_MIN_VERSION "4.5.0") +FIND_PACKAGE(Qt4 REQUIRED) +FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL) + +INCLUDE(${QT_USE_FILE}) +SET(CMAKE_PACKAGE_QTGUI TRUE) +SET(CMAKE_PACKAGE_QTSVG TRUE) + +# Find QT header files +IF("$ENV{QT_INCLUDE_DIR}" STREQUAL "") + SET(QT_INCLUDE_DIR "/usr/include/QT4/" CACHE FILEPATH "QT4 header files") + MESSAGE(STATUS "Looking for QT4 include files in: ${QT_INCLUDE_DIR}") + MESSAGE(STATUS "Use QT_INCLUDE_DIR to specify another directory") +ELSE() + SET(QT_INCLUDE_DIR $ENV{QT_INCLUDE_DIR} CACHE FILEPATH "QT4 header files") + MESSAGE(STATUS "Looking for QT4 include files in: ${QT_INCLUDE_DIR}") +ENDIF() + + +INCLUDE_DIRECTORIES(${QGLViewer_INCLUDE_DIR}) + +SET(QTviewer_SRCS + ../../src/qtviewer/mainwindow.h + ../../src/qtviewer/mainwindow.cpp + ../../src/qtviewer/main.cpp +) +SET(QTviewer_MOC_SRCS + ../../src/qtviewer/mainwindow.h +) + +QT_WRAP_CPP(QTviewer QTviewer_SRCS ${QTviewer_MOC_SRCS}) + +ADD_EXECUTABLE( QTviewer ${QTviewer_SRCS} ${QTviewer_MOC_SRCS}) +#http://www.qtcentre.org/wiki/index.php?title=Compiling_Qt4_apps_with_CMake + +TARGET_LINK_libRARIES (QTviewer IfcParse IfcGeom ${QT_LIBRARIES} TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet) + + +ENDIF (QT_USE_QTVIEWER) diff --git a/src/qtviewer/main.cpp b/src/qtviewer/main.cpp new file mode 100644 index 0000000000..ac3d6f00bd --- /dev/null +++ b/src/qtviewer/main.cpp @@ -0,0 +1,25 @@ + +#include +#include +#ifndef QT_NO_OPENGL +#include +#endif + +#include "mainwindow.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + //QGLViewer viewer; + + // Restore the previous viewer state. + //viewer.restoreStateFromFile(); + + MainWindow window; + //window.openFile(" "); + + window.show(); + + return app.exec(); +} diff --git a/src/qtviewer/mainwindow.cpp b/src/qtviewer/mainwindow.cpp new file mode 100644 index 0000000000..e824518484 --- /dev/null +++ b/src/qtviewer/mainwindow.cpp @@ -0,0 +1,97 @@ + + +#include "mainwindow.h" +#include + +#include + +MainWindow::MainWindow() + : QMainWindow() +{ + + + IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true); + IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false); + IfcGeomObjects::Settings(IfcGeomObjects::SEW_SHELLS,true); + + + + QMenu *fileMenu = new QMenu(tr("&File"), this); + QAction *openAction = fileMenu->addAction(tr("&Open...")); + openAction->setShortcut(QKeySequence(tr("Ctrl+O"))); + QAction *quitAction = fileMenu->addAction(tr("E&xit")); + quitAction->setShortcuts(QKeySequence::Quit); + + menuBar()->addMenu(fileMenu); + + QMenu *viewMenu = new QMenu(tr("&View"), this); + m_backgroundAction = viewMenu->addAction(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->setEnabled(false); + m_outlineAction->setCheckable(true); + m_outlineAction->setChecked(true); + // connect(m_outlineAction, SIGNAL(toggled(bool)), (QWidget*)m_v, SLOT(setViewOutline(bool))); + + menuBar()->addMenu(viewMenu); + + connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + //setCentralWidget((QWidget*)m_v); + setWindowTitle(tr("IfcOpenShell QT Viewer")); +} + +void MainWindow::openFile(const QString &path) +{ + QString fileName; + if (path.isNull()) + fileName = QFileDialog::getOpenFileName(this, tr("Open IFC"), + m_currentPath, "IFC files (*.ifc)"); + else + fileName = path; + + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.exists()) { + QMessageBox::critical(this, tr("Open IFC"), + QString("Could not open file '%1'.").arg(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; + } + + //connect((QWidget*)m_view, SIGNAL(drawNeeded()), this, SLOT(drawIfcObject())); + + if (!fileName.startsWith(":/")) { + m_currentPath = fileName; + setWindowTitle(tr("%1 - IFCViewer").arg(m_currentPath)); + } + + m_outlineAction->setEnabled(true); + m_backgroundAction->setEnabled(true); + +// resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height())); + } +} + + +void MainWindow::draw() +{ + + + +} + + diff --git a/src/qtviewer/mainwindow.h b/src/qtviewer/mainwindow.h new file mode 100644 index 0000000000..bad918cc8e --- /dev/null +++ b/src/qtviewer/mainwindow.h @@ -0,0 +1,49 @@ + + +#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 + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + + +public Q_SLOTS: + void draw(); + +public slots: + void openFile(const QString &path = QString()); + void setRenderer(QAction *action); + +private: + QAction *m_nativeAction; + QAction *m_glAction; + QAction *m_imageAction; + QAction *m_highQualityAntialiasingAction; + QAction *m_backgroundAction; + QAction *m_outlineAction; + + QString m_currentPath; +}; + +#endif