Skip to content

Commit 887ce9f

Browse files
author
Tiago Leao
committed
QT Viewer main structure.
CMake: added an entry at main CMake script that makes QTViewer an optional build. QT Viewer main structure only, libQGLViewer or any 3D functionality can be added to mainWindow as a widget later on.
1 parent 0a5ddec commit 887ce9f

File tree

5 files changed

+220
-0
lines changed

5 files changed

+220
-0
lines changed

cmake/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap)
126126
# Build IfcParseExamples using separate CMakeLists.txt
127127
ADD_SUBDIRECTORY(../src/examples examples)
128128

129+
ADD_SUBDIRECTORY(../src/qtviewer qtviewer)
130+
129131
# CMake installation targets
130132
SET(include_files_geom
131133
../src/ifcgeom/IfcGeom.h

src/qtviewer/CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
OPTION( QT_USE_QTVIEWER "IfcOpenShell QT GUI Viewer, QT environment required" OFF )
3+
4+
5+
IF (QT_USE_QTVIEWER)
6+
7+
8+
# Find QT header files
9+
SET(QT_MIN_VERSION "4.5.0")
10+
FIND_PACKAGE(Qt4 REQUIRED)
11+
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL)
12+
13+
INCLUDE(${QT_USE_FILE})
14+
SET(CMAKE_PACKAGE_QTGUI TRUE)
15+
SET(CMAKE_PACKAGE_QTSVG TRUE)
16+
17+
# Find QT header files
18+
IF("$ENV{QT_INCLUDE_DIR}" STREQUAL "")
19+
SET(QT_INCLUDE_DIR "/usr/include/QT4/" CACHE FILEPATH "QT4 header files")
20+
MESSAGE(STATUS "Looking for QT4 include files in: ${QT_INCLUDE_DIR}")
21+
MESSAGE(STATUS "Use QT_INCLUDE_DIR to specify another directory")
22+
ELSE()
23+
SET(QT_INCLUDE_DIR $ENV{QT_INCLUDE_DIR} CACHE FILEPATH "QT4 header files")
24+
MESSAGE(STATUS "Looking for QT4 include files in: ${QT_INCLUDE_DIR}")
25+
ENDIF()
26+
27+
28+
INCLUDE_DIRECTORIES(${QGLViewer_INCLUDE_DIR})
29+
30+
SET(QTviewer_SRCS
31+
../../src/qtviewer/mainwindow.h
32+
../../src/qtviewer/mainwindow.cpp
33+
../../src/qtviewer/main.cpp
34+
)
35+
SET(QTviewer_MOC_SRCS
36+
../../src/qtviewer/mainwindow.h
37+
)
38+
39+
QT_WRAP_CPP(QTviewer QTviewer_SRCS ${QTviewer_MOC_SRCS})
40+
41+
ADD_EXECUTABLE( QTviewer ${QTviewer_SRCS} ${QTviewer_MOC_SRCS})
42+
#http://www.qtcentre.org/wiki/index.php?title=Compiling_Qt4_apps_with_CMake
43+
44+
TARGET_LINK_libRARIES (QTviewer IfcParse IfcGeom ${QT_LIBRARIES} TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet)
45+
46+
47+
ENDIF (QT_USE_QTVIEWER)

src/qtviewer/main.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
#include <QApplication>
3+
#include <QString>
4+
#ifndef QT_NO_OPENGL
5+
#include <QGLFormat>
6+
#endif
7+
8+
#include "mainwindow.h"
9+
10+
int main(int argc, char **argv)
11+
{
12+
QApplication app(argc, argv);
13+
14+
//QGLViewer viewer;
15+
16+
// Restore the previous viewer state.
17+
//viewer.restoreStateFromFile();
18+
19+
MainWindow window;
20+
//window.openFile(" ");
21+
22+
window.show();
23+
24+
return app.exec();
25+
}

src/qtviewer/mainwindow.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+

src/qtviewer/mainwindow.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
3+
#ifndef MAINWINDOW_H
4+
#define MAINWINDOW_H
5+
6+
#include <qobject.h>
7+
#include <QMainWindow>
8+
#include <QString>
9+
#include <qobject.h>
10+
#include "../ifcgeom/IfcGeomObjects.h"
11+
12+
class ObjectsView;
13+
14+
class QGLViewer;
15+
16+
QT_BEGIN_NAMESPACE
17+
class QAction;
18+
class QGraphicsView;
19+
class QGraphicsScene;
20+
class QGraphicsRectItem;
21+
QT_END_NAMESPACE
22+
23+
class MainWindow : public QMainWindow
24+
{
25+
Q_OBJECT
26+
27+
public:
28+
MainWindow();
29+
30+
31+
public Q_SLOTS:
32+
void draw();
33+
34+
public slots:
35+
void openFile(const QString &path = QString());
36+
void setRenderer(QAction *action);
37+
38+
private:
39+
QAction *m_nativeAction;
40+
QAction *m_glAction;
41+
QAction *m_imageAction;
42+
QAction *m_highQualityAntialiasingAction;
43+
QAction *m_backgroundAction;
44+
QAction *m_outlineAction;
45+
46+
QString m_currentPath;
47+
};
48+
49+
#endif

0 commit comments

Comments
 (0)