summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-23 19:56:46 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-23 19:56:46 (GMT)
commit4daae374011de97aafa999f2353e2c7d17511046 (patch)
treebc51daf75fb7d4be3d17ed4fd3206f08bf7d0aee
parent0fcdcb6bd6117e8e8ccaff15b0a083c2f76266a6 (diff)
Clifford Wolf:
Added GUI git-svn-id: http://svn.clifford.at/openscad/trunk@13 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r--csg.cc6
-rw-r--r--glview.cc138
-rw-r--r--lexer.l10
-rw-r--r--mainwin.cc273
-rw-r--r--module.cc36
-rw-r--r--openscad.cc31
-rw-r--r--openscad.h95
-rw-r--r--openscad.pro6
-rw-r--r--parser.y7
-rw-r--r--primitive.cc6
-rw-r--r--trans.cc6
11 files changed, 593 insertions, 21 deletions
diff --git a/csg.cc b/csg.cc
index 3ad02d6..de3b6b9 100644
--- a/csg.cc
+++ b/csg.cc
@@ -41,7 +41,9 @@ class CsgNode : public AbstractNode
public:
csg_type_e type;
CsgNode(csg_type_e type) : type(type) { }
+#ifdef ENABLE_CGAL
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
+#endif
virtual QString dump(QString indent) const;
};
@@ -56,6 +58,8 @@ AbstractNode *CsgModule::evaluate(const Context*, const QVector<QString>&, const
return node;
}
+#ifdef ENABLE_CGAL
+
CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const
{
bool first;
@@ -76,6 +80,8 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const
return N;
}
+#endif /* ENABLE_CGAL */
+
QString CsgNode::dump(QString indent) const
{
QString text = indent;
diff --git a/glview.cc b/glview.cc
new file mode 100644
index 0000000..db9a303
--- /dev/null
+++ b/glview.cc
@@ -0,0 +1,138 @@
+/*
+ * OpenSCAD (www.openscad.at)
+ * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "openscad.h"
+
+#include <QWheelEvent>
+#include <QMouseEvent>
+
+#define FAR_FAR_AWAY 100000.0
+
+GLView::GLView(QWidget *parent) : QGLWidget(parent)
+{
+ viewer_distance = 10;
+ object_rot_y = 0;
+ object_rot_z = 0;
+
+ mouse_drag_active = false;
+ last_mouse_x = 0;
+ last_mouse_y = 0;
+
+ renderfunc = NULL;
+ renderfunc_vp = NULL;
+
+ setMouseTracking(true);
+}
+
+void GLView::initializeGL()
+{
+ glEnable(GL_DEPTH_TEST);
+ glDepthRange(-FAR_FAR_AWAY, +FAR_FAR_AWAY);
+
+ glClearColor(1.0, 1.0, 0.9, 0.0);
+}
+
+void GLView::resizeGL(int w, int h)
+{
+ glViewport(0, 0, (GLint)w, (GLint)h);
+}
+
+void GLView::paintGL()
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, +1.0, -1.0, +1.0, +10.0, +FAR_FAR_AWAY);
+ gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glRotated(object_rot_y, 1.0, 0.0, 0.0);
+ glRotated(object_rot_z, 0.0, 0.0, 1.0);
+
+#if 0
+ glColor3d(0.0, 0.0, 1.0);
+ glBegin(GL_LINES);
+ glVertex3d(0, 0, 0); glVertex3d(10, 0, 0);
+ glVertex3d(0, 0, 0); glVertex3d(0, 10, 0);
+ glVertex3d(0, 0, 0); glVertex3d(0, 0, 10);
+ glEnd();
+#endif
+
+ if (renderfunc)
+ renderfunc(renderfunc_vp);
+
+ glColor3d(1.0, 0.0, 0.0);
+ for (int i=0; i<polygons.size(); i++) {
+ Polygon *poly = &polygons[i];
+ glBegin(GL_POLYGON);
+ for (int j=0; j<poly->size(); j++) {
+ const Point *p = &poly->at(j);
+ glVertex3d(p->x, p->y, p->z);
+ }
+ glEnd();
+ }
+
+ glColor3d(0.5, 0.0, 0.0);
+ for (int i=0; i<polygons.size(); i++) {
+ Polygon *poly = &polygons[i];
+ glBegin(GL_LINE_LOOP);
+ for (int j=0; j<poly->size(); j++) {
+ const Point *p = &poly->at(j);
+ glVertex3d(p->x, p->y, p->z);
+ }
+ glEnd();
+ }
+}
+
+void GLView::wheelEvent(QWheelEvent *event)
+{
+ viewer_distance *= pow(0.9, event->delta() / 120.0);
+ updateGL();
+}
+
+void GLView::mousePressEvent(QMouseEvent *event)
+{
+ mouse_drag_active = true;
+ last_mouse_x = event->globalX();
+ last_mouse_y = event->globalY();
+ grabMouse();
+}
+
+void GLView::mouseMoveEvent(QMouseEvent *event)
+{
+ int this_mouse_x = event->globalX();
+ int this_mouse_y = event->globalY();
+ if (mouse_drag_active) {
+ object_rot_y += (this_mouse_y-last_mouse_y) * 0.7;
+ object_rot_z += (this_mouse_x-last_mouse_x) * 0.7;
+ updateGL();
+ }
+ last_mouse_x = this_mouse_x;
+ last_mouse_y = this_mouse_y;
+}
+
+void GLView::mouseReleaseEvent(QMouseEvent*)
+{
+ mouse_drag_active = false;
+ releaseMouse();
+}
+
diff --git a/lexer.l b/lexer.l
index 37dd9b5..56b33e6 100644
--- a/lexer.l
+++ b/lexer.l
@@ -24,6 +24,16 @@
#include "parser_yacc.h"
int lexerget_lineno(void);
+extern const char *parser_input_buffer;
+
+#define YY_INPUT(buf,result,max_size) { \
+ if (*parser_input_buffer) { \
+ result = 1; \
+ buf[0] = *(parser_input_buffer++); \
+ } else { \
+ result = YY_NULL; \
+ } \
+}
%}
diff --git a/mainwin.cc b/mainwin.cc
new file mode 100644
index 0000000..943bf65
--- /dev/null
+++ b/mainwin.cc
@@ -0,0 +1,273 @@
+/*
+ * OpenSCAD (www.openscad.at)
+ * Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#define INCLUDE_ABSTRACT_NODE_DETAILS
+
+#include "openscad.h"
+
+#include <QMenu>
+#include <QMenuBar>
+#include <QSplitter>
+
+MainWindow::MainWindow(const char *filename)
+{
+ root_ctx.functions_p = &builtin_functions;
+ root_ctx.modules_p = &builtin_modules;
+
+ root_module = NULL;
+ root_node = NULL;
+ root_N = NULL;
+
+ if (filename) {
+ this->filename = QString(filename);
+ setWindowTitle(this->filename);
+ } else {
+ setWindowTitle("New Document");
+ }
+
+ {
+ QMenu *menu = menuBar()->addMenu("&File");
+ menu->addAction("&New", this, SLOT(actionNew()));
+ menu->addAction("&Open...", this, SLOT(actionOpen()));
+ menu->addAction("&Save", this, SLOT(actionSave()));
+ menu->addAction("Save &As...", this, SLOT(actionSaveAs()));
+ menu->addAction("&Quit", this, SLOT(close()));
+ }
+
+ {
+ QMenu *menu = menuBar()->addMenu("&Design");
+ menu->addAction("&Compile", this, SLOT(actionCompile()));
+#ifdef ENABLE_CGAL
+ menu->addAction("Compile and &Render (CGAL)", this, SLOT(actionRenderCGAL()));
+#endif
+ menu->addAction("Display &AST...", this, SLOT(actionDisplayAST()));
+ menu->addAction("Display &CSG...", this, SLOT(actionDisplayCSG()));
+ menu->addAction("Export as &STL...", this, SLOT(actionExportSTL()));
+ menu->addAction("Export as &OFF...", this, SLOT(actionExportOFF()));
+ }
+
+ {
+ QMenu *menu = menuBar()->addMenu("&View");
+ menu->addAction("OpenCSG");
+ menu->addAction("CGAL Surfaces");
+ menu->addAction("CGAL Grid Only");
+ menu->addSeparator();
+ menu->addAction("Top");
+ menu->addAction("Bottom");
+ menu->addAction("Left");
+ menu->addAction("Right");
+ menu->addAction("Front");
+ menu->addAction("Back");
+ menu->addAction("Diagonal");
+ menu->addSeparator();
+ menu->addAction("Perspective");
+ menu->addAction("Orthogonal");
+ }
+
+ s1 = new QSplitter(Qt::Horizontal, this);
+ editor = new QTextEdit(s1);
+ s2 = new QSplitter(Qt::Vertical, s1);
+ screen = new GLView(s2);
+ console = new QTextEdit(s2);
+
+ console->setReadOnly(true);
+ console->append("OpenSCAD (www.openscad.at)");
+ console->append("Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>");
+ console->append("");
+ console->append("This program is free software; you can redistribute it and/or modify");
+ console->append("it under the terms of the GNU General Public License as published by");
+ console->append("the Free Software Foundation; either version 2 of the License, or");
+ console->append("(at your option) any later version.");
+ console->append("");
+
+ editor->setTabStopWidth(30);
+
+ if (filename) {
+ QString text;
+ FILE *fp = fopen(filename, "rt");
+ if (!fp) {
+ console->append(QString("Failed to open text file: %1 (%2)").arg(QString(filename), QString(strerror(errno))));
+ } else {
+ char buffer[513];
+ int rc;
+ while ((rc = fread(buffer, 1, 512, fp)) > 0) {
+ buffer[rc] = 0;
+ text += buffer;
+ }
+ fclose(fp);
+ }
+ editor->setPlainText(text);
+ }
+
+ screen->polygons.clear();
+ screen->polygons.append(GLView::Polygon() << GLView::Point(0,0,0) << GLView::Point(1,0,0) << GLView::Point(0,1,0));
+ screen->polygons.append(GLView::Polygon() << GLView::Point(0,0,0) << GLView::Point(1,0,0) << GLView::Point(0,0,1));
+ screen->polygons.append(GLView::Polygon() << GLView::Point(1,0,0) << GLView::Point(0,1,0) << GLView::Point(0,0,1));
+ screen->polygons.append(GLView::Polygon() << GLView::Point(0,1,0) << GLView::Point(0,0,0) << GLView::Point(0,0,1));
+ screen->updateGL();
+
+ setCentralWidget(s1);
+}
+
+MainWindow::~MainWindow()
+{
+ if (root_module)
+ delete root_module;
+ if (root_node)
+ delete root_node;
+ if (root_N)
+ delete root_N;
+}
+
+void MainWindow::actionNew()
+{
+ console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+}
+
+void MainWindow::actionOpen()
+{
+ console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+}
+
+void MainWindow::actionSave()
+{
+ console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+}
+
+void MainWindow::actionSaveAs()
+{
+ console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+}
+
+void MainWindow::actionCompile()
+{
+ if (root_module) {
+ delete root_module;
+ root_module = NULL;
+ }
+
+ console->append("Parsing design (AST generation)...");
+ root_module = parse(editor->toPlainText().toAscii().data(), false);
+
+ if (!root_module) {
+ console->append("Compilation failed!");
+ return;
+ }
+
+ if (root_node) {
+ delete root_node;
+ root_node = NULL;
+ }
+
+ console->append("Compiling design (CSG generation)...");
+ root_node = root_module->evaluate(&root_ctx, QVector<QString>(), QVector<Value>(), QVector<AbstractNode*>());
+
+ if (!root_node) {
+ console->append("Compilation failed!");
+ return;
+ }
+
+ console->append("Compilation finished.");
+}
+
+#ifdef ENABLE_CGAL
+
+static void report_func(const class AbstractNode*, void *vp, int mark)
+{
+ MainWindow *m = (MainWindow*)vp;
+ QString msg;
+ msg.sprintf("CSG rendering progress: %.2f%%", (mark*100.0) / progress_report_count);
+ m->console->append(msg);
+}
+
+#include <CGAL/Nef_3/OGL_helper.h>
+
+static void renderGLviaCGAL(void *vp)
+{
+ MainWindow *m = (MainWindow*)vp;
+
+ CGAL::OGL::Polyhedron P;
+ CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron>::convert_to_OGLPolyhedron(*m->root_N, &P);
+ P.draw();
+}
+
+void MainWindow::actionRenderCGAL()
+{
+ actionCompile();
+
+ if (!root_module || !root_node)
+ return;
+
+ if (root_N) {
+ delete root_N;
+ root_N = NULL;
+ }
+
+ progress_report_prep(root_node, report_func, this);
+ root_N = new CGAL_Nef_polyhedron(root_node->render_cgal_nef_polyhedron());
+ progress_report_fin();
+
+ screen->polygons.clear();
+ screen->renderfunc = renderGLviaCGAL;
+ screen->renderfunc_vp = this;
+ screen->updateGL();
+}
+
+#endif /* ENABLE_CGAL */
+
+void MainWindow::actionDisplayAST()
+{
+ QTextEdit *e = new QTextEdit(NULL);
+ e->setTabStopWidth(30);
+ e->setWindowTitle("AST Dump");
+ if (root_module) {
+ e->setPlainText(root_module->dump("", ""));
+ } else {
+ e->setPlainText("No AST to dump. Please try compiling first...");
+ }
+ e->show();
+ e->resize(600, 400);
+}
+
+void MainWindow::actionDisplayCSG()
+{
+ QTextEdit *e = new QTextEdit(NULL);
+ e->setTabStopWidth(30);
+ e->setWindowTitle("CSG Dump");
+ if (root_node) {
+ e->setPlainText(root_node->dump(""));
+ } else {
+ e->setPlainText("No CSG to dump. Please try compiling first...");
+ }
+ e->show();
+ e->resize(600, 400);
+}
+
+void MainWindow::actionExportSTL()
+{
+ console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+}
+
+void MainWindow::actionExportOFF()
+{
+ console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+}
+
+
diff --git a/module.cc b/module.cc
index 6c443de..9f9a21b 100644
--- a/module.cc
+++ b/module.cc
@@ -135,36 +135,42 @@ AbstractNode *Module::evaluate(const Context *ctx, const QVector<QString> &call_
QString Module::dump(QString indent, QString name) const
{
- QString text = QString("%1module %2(").arg(indent, name);
- for (int i=0; i < argnames.size(); i++) {
- if (i > 0)
- text += QString(", ");
- text += argnames[i];
- if (argexpr[i])
- text += QString(" = ") + argexpr[i]->dump();
+ QString text, tab;
+ if (!name.isEmpty()) {
+ text = QString("%1module %2(").arg(indent, name);
+ for (int i=0; i < argnames.size(); i++) {
+ if (i > 0)
+ text += QString(", ");
+ text += argnames[i];
+ if (argexpr[i])
+ text += QString(" = ") + argexpr[i]->dump();
+ }
+ text += QString(") {\n");
+ tab = "\t";
}
- text += QString(") {\n");
{
QHashIterator<QString, AbstractFunction*> i(functions);
while (i.hasNext()) {
i.next();
- text += i.value()->dump(indent + QString("\t"), i.key());
+ text += i.value()->dump(indent + tab, i.key());
}
}
{
QHashIterator<QString, AbstractModule*> i(modules);
while (i.hasNext()) {
i.next();
- text += i.value()->dump(indent + QString("\t"), i.key());
+ text += i.value()->dump(indent + tab, i.key());
}
}
for (int i = 0; i < assignments_var.size(); i++) {
- text += QString("%1\t%2 = %3;\n").arg(indent, assignments_var[i], assignments_expr[i]->dump());
+ text += QString("%1%2 = %3;\n").arg(indent + tab, assignments_var[i], assignments_expr[i]->dump());
}
for (int i = 0; i < children.size(); i++) {
- text += children[i]->dump(indent + QString("\t"));
+ text += children[i]->dump(indent + tab);
+ }
+ if (!name.isEmpty()) {
+ text += QString("%1}\n").arg(indent);
}
- text += QString("%1}\n").arg(indent);
return text;
}
@@ -192,6 +198,8 @@ AbstractNode::~AbstractNode()
delete v;
}
+#ifdef ENABLE_CGAL
+
CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const
{
CGAL_Nef_polyhedron N;
@@ -201,6 +209,8 @@ CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const
return N;
}
+#endif /* ENABLE_CGAL */
+
QString AbstractNode::dump(QString indent) const
{
QString text = indent + "group() {\n";
diff --git a/openscad.cc b/openscad.cc
index 988b4c2..64eb5bf 100644
--- a/openscad.cc
+++ b/openscad.cc
@@ -18,22 +18,43 @@
*
*/
-#define INCLUDE_ABSTRACT_NODE_DETAILS
+// #define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
+#include <QApplication>
+
+#if 0
void report_func(const class AbstractNode*, void*, int mark)
{
printf("CSG rendering progress: %.2f%%\n", (mark*100.0) / progress_report_count);
}
+#endif
-int main()
+int main(int argc, char **argv)
{
- int rc = 0;
+ int rc;
initialize_builtin_functions();
initialize_builtin_modules();
+ QApplication a(argc, argv);
+ MainWindow *m;
+
+ if (argc > 1)
+ m = new MainWindow(argv[1]);
+ else
+ m = new MainWindow();
+
+ m->show();
+ m->resize(800, 600);
+ m->s1->setSizes(QList<int>() << 400 << 400);
+ m->s2->setSizes(QList<int>() << 400 << 200);
+
+ a.connect(m, SIGNAL(destroyed()), &a, SLOT(quit()));
+ rc = a.exec();
+
+#if 0
Context root_ctx(NULL);
root_ctx.functions_p = &builtin_functions;
root_ctx.modules_p = &builtin_modules;
@@ -67,11 +88,13 @@ int main()
}
outFile << P;
+ delete root_node;
delete root_module;
+#endif
destroy_builtin_functions();
destroy_builtin_modules();
- return rc;
+ return rc;
}
diff --git a/openscad.h b/openscad.h
index f0b1e33..9ca09d9 100644
--- a/openscad.h
+++ b/openscad.h
@@ -23,8 +23,15 @@
#include <QHash>
#include <QVector>
+#include <QMainWindow>
+#include <QSplitter>
+#include <QTextEdit>
+#include <QGLWidget>
+
#include <stdio.h>
+#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <math.h>
#include <fstream>
@@ -222,7 +229,7 @@ public:
const QHash<QString, AbstractFunction*> *functions_p;
const QHash<QString, AbstractModule*> *modules_p;
- Context(const Context *parent) : parent(parent) { }
+ Context(const Context *parent = NULL) : parent(parent) { }
void args(const QVector<QString> &argnames, const QVector<Expression*> &argexpr, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues);
Value lookup_variable(QString name) const;
@@ -234,6 +241,8 @@ public:
// So we only include the declaration of AbstractNode where it is needed...
#ifdef INCLUDE_ABSTRACT_NODE_DETAILS
+#ifdef ENABLE_CGAL
+
#include <CGAL/Gmpq.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Polyhedron_3.h>
@@ -250,6 +259,8 @@ typedef CGAL_Nef_polyhedron::Vector_3 CGAL_Vector;
typedef CGAL_Nef_polyhedron::Plane_3 CGAL_Plane;
typedef CGAL_Nef_polyhedron::Point_3 CGAL_Point;
+#endif /* ENABLE_CGAL */
+
class AbstractNode
{
public:
@@ -260,7 +271,9 @@ public:
void progress_report() const;
virtual ~AbstractNode();
+#ifdef ENABLE_CGAL
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
+#endif
virtual QString dump(QString indent) const;
};
@@ -271,9 +284,87 @@ extern void *progress_report_vp;
void progress_report_prep(AbstractNode *root, void (*f)(const class AbstractNode *node, void *vp, int mark), void *vp);
void progress_report_fin();
+#else
+
+// this is a bit hackish - but a pointer is a pointer..
+struct CGAL_Nef_polyhedron;
+
#endif /* HIDE_ABSTRACT_NODE_DETAILS */
-extern AbstractModule *parse(FILE *f, int debug);
+class GLView : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ struct Point {
+ double x, y, z;
+ Point() : x(0), y(0), z(0) { }
+ Point(double x, double y, double z) : x(x), y(y), z(z) { }
+ };
+ typedef QVector<Point> Polygon;
+ QVector<Polygon> polygons;
+
+ void (*renderfunc)(void*);
+ void *renderfunc_vp;
+
+ double viewer_distance;
+ double object_rot_y;
+ double object_rot_z;
+
+ GLView(QWidget *parent = NULL);
+
+protected:
+ bool mouse_drag_active;
+ int last_mouse_x;
+ int last_mouse_y;
+
+ void wheelEvent(QWheelEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+ void initializeGL();
+ void resizeGL(int w, int h);
+ void paintGL();
+};
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ QString filename;
+ QSplitter *s1, *s2;
+ QTextEdit *editor;
+ GLView *screen;
+ QTextEdit *console;
+
+ Context root_ctx;
+ AbstractModule *root_module;
+ AbstractNode *root_node;
+#ifdef ENABLE_CGAL
+ CGAL_Nef_polyhedron *root_N;
+#endif
+
+ MainWindow(const char *filename = 0);
+ ~MainWindow();
+
+private slots:
+ void actionNew();
+ void actionOpen();
+ void actionSave();
+ void actionSaveAs();
+ void actionCompile();
+#ifdef ENABLE_CGAL
+ void actionRenderCGAL();
+#endif
+ void actionDisplayAST();
+ void actionDisplayCSG();
+ void actionExportSTL();
+ void actionExportOFF();
+};
+
+extern AbstractModule *parse(const char *text, int debug);
#endif
diff --git a/openscad.pro b/openscad.pro
index f8002c8..5e05b0e 100644
--- a/openscad.pro
+++ b/openscad.pro
@@ -2,12 +2,16 @@
CONFIG += qt
TEMPLATE = app
+DEFINES += "ENABLE_CGAL=1"
LIBS += -lCGAL -lmpfr
LEXSOURCES += lexer.l
YACCSOURCES += parser.y
HEADERS += openscad.h
-SOURCES += openscad.cc value.cc expr.cc func.cc module.cc context.cc
+SOURCES += openscad.cc mainwin.cc glview.cc
+SOURCES += value.cc expr.cc func.cc module.cc context.cc
SOURCES += csg.cc trans.cc primitive.cc
+QT += opengl
+
diff --git a/parser.y b/parser.y
index cdeaf07..d4c7255 100644
--- a/parser.y
+++ b/parser.y
@@ -404,8 +404,13 @@ void yyerror (char const *s)
exit(1);
}
-AbstractModule *parse(FILE *f, int debug)
+extern const char *parser_input_buffer;
+const char *parser_input_buffer;
+
+AbstractModule *parse(const char *text, int debug)
{
+ parser_input_buffer = text;
+
module_stack.clear();
module = new Module();
diff --git a/primitive.cc b/primitive.cc
index 48d819f..1f3815d 100644
--- a/primitive.cc
+++ b/primitive.cc
@@ -43,7 +43,9 @@ public:
double x, y, z, h, r1, r2;
primitive_type_e type;
PrimitiveNode(primitive_type_e type) : type(type) { }
+#ifdef ENABLE_CGAL
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
+#endif
virtual QString dump(QString indent) const;
};
@@ -132,6 +134,8 @@ void register_builtin_primitive()
builtin_modules["cylinder"] = new PrimitiveModule(CYLINDER);
}
+#ifdef ENABLE_CGAL
+
static int cube_facets[6][4] = {
{ 0, 1, 2, 3 },
{ 7, 6, 5, 4 },
@@ -246,6 +250,8 @@ CGAL_Nef_polyhedron PrimitiveNode::render_cgal_nef_polyhedron() const
return N;
}
+#endif /* ENABLE_CGAL */
+
QString PrimitiveNode::dump(QString indent) const
{
QString text;
diff --git a/trans.cc b/trans.cc
index 5f0eca2..71498bb 100644
--- a/trans.cc
+++ b/trans.cc
@@ -32,7 +32,9 @@ class TransNode : public AbstractNode
{
public:
double x, y, z;
+#ifdef ENABLE_CGAL
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
+#endif
virtual QString dump(QString indent) const;
};
@@ -53,6 +55,8 @@ AbstractNode *TransModule::evaluate(const Context*, const QVector<QString>&, con
return node;
}
+#ifdef ENABLE_CGAL
+
CGAL_Nef_polyhedron TransNode::render_cgal_nef_polyhedron() const
{
CGAL_Nef_polyhedron N;
@@ -64,6 +68,8 @@ CGAL_Nef_polyhedron TransNode::render_cgal_nef_polyhedron() const
return N;
}
+#endif /* ENABLE_CGAL */
+
QString TransNode::dump(QString indent) const
{
QString text;
contact: Jan Huwald // Impressum