summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-24 22:38:31 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-24 22:38:31 (GMT)
commitbea704f141c92d2076a0102556203dab0246e39f (patch)
tree8e2878c4557165b4cf9222b6cf68994adab90cd1
parentcf15ce518535837fa993ce9a6c631e6c5755165a (diff)
Clifford Wolf:
Added TrownTogether view mode git-svn-id: http://svn.clifford.at/openscad/trunk@18 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r--glview.cc24
-rw-r--r--mainwin.cc132
-rw-r--r--openscad.h35
3 files changed, 130 insertions, 61 deletions
diff --git a/glview.cc b/glview.cc
index db9a303..3260645 100644
--- a/glview.cc
+++ b/glview.cc
@@ -77,30 +77,10 @@ void GLView::paintGL()
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();
- }
+ if (renderfunc)
+ renderfunc(renderfunc_vp);
}
void GLView::wheelEvent(QWheelEvent *event)
diff --git a/mainwin.cc b/mainwin.cc
index 352c62d..67a757f 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -35,10 +35,8 @@ MainWindow::MainWindow(const char *filename)
root_module = NULL;
root_node = NULL;
-#ifdef ENABLE_OPENCSG
root_raw_term = NULL;
root_norm_term = NULL;
-#endif
#ifdef ENABLE_CGAL
root_N = NULL;
#endif
@@ -67,18 +65,26 @@ MainWindow::MainWindow(const char *filename)
#endif
menu->addAction("Display &AST...", this, SLOT(actionDisplayAST()));
menu->addAction("Display CSG &Tree...", this, SLOT(actionDisplayCSGTree()));
-#ifdef ENABLE_OPENCSG
menu->addAction("Display CSG &Products...", this, SLOT(actionDisplayCSGProducts()));
-#endif
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");
+#ifdef ENABLE_OPENCSG
+ actViewModeOpenCSG = menu->addAction("OpenCSG", this, SLOT(viewModeOpenCSG()));
+ actViewModeOpenCSG->setCheckable(true);
+#endif
+#ifdef ENABLE_CGAL
+ actViewModeCGALSurface = menu->addAction("CGAL Surfaces", this, SLOT(viewModeCGALSurface()));
+ actViewModeCGALGrid = menu->addAction("CGAL Grid Only", this, SLOT(viewModeCGALGrid()));
+ actViewModeCGALSurface->setCheckable(true);
+ actViewModeCGALGrid->setCheckable(true);
+#endif
+ actViewModeTrownTogether = menu->addAction("Thrown Together", this, SLOT(viewModeTrownTogether()));
+ actViewModeTrownTogether->setCheckable(true);
+
menu->addSeparator();
menu->addAction("Top");
menu->addAction("Bottom");
@@ -128,12 +134,11 @@ MainWindow::MainWindow(const char *filename)
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();
+#ifdef ENABLE_OPENCSG
+ viewModeOpenCSG();
+#else
+ viewModeTrownTogether();
+#endif
setCentralWidget(s1);
}
@@ -238,7 +243,6 @@ void MainWindow::actionCompile()
return;
}
-#ifdef ENABLE_OPENCSG
console->append("Compiling design (CSG Products generation)...");
QApplication::processEvents();
@@ -277,7 +281,6 @@ void MainWindow::actionCompile()
console->append("Compilation failed!");
return;
}
-#endif /* ENABLE_OPENCSG */
console->append("Compilation finished.");
}
@@ -298,10 +301,16 @@ static void report_func(const class AbstractNode*, void *vp, int mark)
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();
+ if (m->root_N) {
+ CGAL::OGL::Polyhedron P;
+ CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron>::convert_to_OGLPolyhedron(*m->root_N, &P);
+ P.init();
+ if (m->actViewModeCGALSurface->isChecked())
+ P.set_style(CGAL::OGL::SNC_BOUNDARY);
+ if (m->actViewModeCGALGrid->isChecked())
+ P.set_style(CGAL::OGL::SNC_SKELETON);
+ P.draw();
+ }
}
void MainWindow::actionRenderCGAL()
@@ -320,10 +329,11 @@ void MainWindow::actionRenderCGAL()
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();
+ if (!actViewModeCGALSurface->isChecked() && !actViewModeCGALGrid->isChecked()) {
+ viewModeCGALSurface();
+ } else {
+ screen->updateGL();
+ }
}
#endif /* ENABLE_CGAL */
@@ -356,8 +366,6 @@ void MainWindow::actionDisplayCSGTree()
e->resize(600, 400);
}
-#ifdef ENABLE_OPENCSG
-
void MainWindow::actionDisplayCSGProducts()
{
QTextEdit *e = new QTextEdit(NULL);
@@ -368,8 +376,6 @@ void MainWindow::actionDisplayCSGProducts()
e->resize(600, 400);
}
-#endif /* ENABLE_OPENCSG */
-
void MainWindow::actionExportSTL()
{
console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
@@ -380,4 +386,76 @@ void MainWindow::actionExportOFF()
console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
}
+void MainWindow::viewModeActionsUncheck()
+{
+#ifdef ENABLE_OPENCSG
+ actViewModeOpenCSG->setChecked(false);
+#endif
+#ifdef ENABLE_CGAL
+ actViewModeCGALSurface->setChecked(false);
+ actViewModeCGALGrid->setChecked(false);
+#endif
+ actViewModeTrownTogether->setChecked(false);
+}
+
+#ifdef ENABLE_OPENCSG
+
+void MainWindow::viewModeOpenCSG()
+{
+ /* FIXME */
+ viewModeActionsUncheck();
+ actViewModeOpenCSG->setChecked(true);
+ screen->renderfunc = NULL;
+ screen->updateGL();
+}
+
+#endif /* ENABLE_OPENCSG */
+
+#ifdef ENABLE_CGAL
+
+void MainWindow::viewModeCGALSurface()
+{
+ viewModeActionsUncheck();
+ actViewModeCGALSurface->setChecked(true);
+ screen->renderfunc = renderGLviaCGAL;
+ screen->renderfunc_vp = this;
+ screen->updateGL();
+}
+
+void MainWindow::viewModeCGALGrid()
+{
+ viewModeActionsUncheck();
+ actViewModeCGALGrid->setChecked(true);
+ screen->renderfunc = renderGLviaCGAL;
+ screen->renderfunc_vp = this;
+ screen->updateGL();
+}
+
+#endif /* ENABLE_CGAL */
+
+static void renderGLTrownTogether_worker(CSGTerm *t)
+{
+ if (t->left)
+ renderGLTrownTogether_worker(t->left);
+ if (t->right)
+ renderGLTrownTogether_worker(t->right);
+ if (t->polyset)
+ t->polyset->render_opengl();
+}
+
+static void renderGLTrownTogether(void *vp)
+{
+ MainWindow *m = (MainWindow*)vp;
+ if (m->root_raw_term)
+ renderGLTrownTogether_worker(m->root_raw_term);
+}
+
+void MainWindow::viewModeTrownTogether()
+{
+ viewModeActionsUncheck();
+ actViewModeTrownTogether->setChecked(true);
+ screen->renderfunc = renderGLTrownTogether;
+ screen->renderfunc_vp = this;
+ screen->updateGL();
+}
diff --git a/openscad.h b/openscad.h
index af35ee5..e9a7455 100644
--- a/openscad.h
+++ b/openscad.h
@@ -388,14 +388,6 @@ 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;
@@ -434,10 +426,8 @@ public:
Context root_ctx;
AbstractModule *root_module;
AbstractNode *root_node;
-#ifdef ENABLE_OPENCSG
CSGTerm *root_raw_term;
CSGTerm *root_norm_term;
-#endif
#ifdef ENABLE_CGAL
CGAL_Nef_polyhedron *root_N;
#endif
@@ -450,17 +440,38 @@ private slots:
void actionOpen();
void actionSave();
void actionSaveAs();
+
+private slots:
void actionCompile();
#ifdef ENABLE_CGAL
void actionRenderCGAL();
#endif
void actionDisplayAST();
void actionDisplayCSGTree();
-#ifdef ENABLE_OPENCSG
void actionDisplayCSGProducts();
-#endif
void actionExportSTL();
void actionExportOFF();
+
+public:
+#ifdef ENABLE_OPENCSG
+ QAction *actViewModeOpenCSG;
+#endif
+#ifdef ENABLE_CGAL
+ QAction *actViewModeCGALSurface;
+ QAction *actViewModeCGALGrid;
+#endif
+ QAction *actViewModeTrownTogether;
+ void viewModeActionsUncheck();
+
+private slots:
+#ifdef ENABLE_OPENCSG
+ void viewModeOpenCSG();
+#endif
+#ifdef ENABLE_CGAL
+ void viewModeCGALSurface();
+ void viewModeCGALGrid();
+#endif
+ void viewModeTrownTogether();
};
extern AbstractModule *parse(const char *text, int debug);
contact: Jan Huwald // Impressum