summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GLView.h4
-rw-r--r--src/MainWindow.ui3
-rw-r--r--src/Preferences.cc9
-rw-r--r--src/Preferences.h2
-rw-r--r--src/Preferences.ui14
-rw-r--r--src/ThrownTogetherRenderer.cc6
-rw-r--r--src/dxftess-cgal.cc33
-rw-r--r--src/dxftess-glu.cc2
-rw-r--r--src/glview.cc72
-rw-r--r--src/grid.h27
-rw-r--r--src/node.cc2
-rw-r--r--src/system-gl.h1
12 files changed, 113 insertions, 62 deletions
diff --git a/src/GLView.h b/src/GLView.h
index 3a36a15..c31e7af 100644
--- a/src/GLView.h
+++ b/src/GLView.h
@@ -79,8 +79,10 @@ private:
void normalizeAngle(GLdouble& angle);
#ifdef ENABLE_OPENCSG
+ bool is_opencsg_capable;
+ bool has_shaders;
private slots:
- void display_opengl20_warning();
+ void display_opencsg_warning();
#endif
signals:
diff --git a/src/MainWindow.ui b/src/MainWindow.ui
index 4d5ff22..dc73c05 100644
--- a/src/MainWindow.ui
+++ b/src/MainWindow.ui
@@ -270,6 +270,9 @@
<property name="text">
<string>&amp;Quit</string>
</property>
+ <property name="shortcut">
+ <string>Ctrl+Q</string>
+ </property>
</action>
<action name="editActionUndo">
<property name="text">
diff --git a/src/Preferences.cc b/src/Preferences.cc
index eb6af61..d240a9f 100644
--- a/src/Preferences.cc
+++ b/src/Preferences.cc
@@ -98,8 +98,8 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
this, SLOT(fontFamilyChanged(const QString &)));
connect(this->fontSize, SIGNAL(editTextChanged(const QString &)),
this, SLOT(fontSizeChanged(const QString &)));
- connect(this->OpenGL20WarningCheckbox, SIGNAL(clicked(bool)),
- this, SLOT(OpenGL20WarningChanged(bool)));
+ connect(this->openCSGWarningBox, SIGNAL(clicked(bool)),
+ this, SLOT(openCSGWarningChanged(bool)));
updateGUI();
}
@@ -151,7 +151,7 @@ void Preferences::fontSizeChanged(const QString &size)
}
void
-Preferences::OpenGL20WarningChanged(bool state)
+Preferences::openCSGWarningChanged(bool state)
{
QSettings settings;
settings.setValue("editor/opengl20_warning_show",state);
@@ -215,8 +215,7 @@ void Preferences::updateGUI()
this->fontSize->setEditText(fontsize);
}
- bool opengl20_warning_show = getValue("editor/opengl20_warning_show").toBool();
- this->OpenGL20WarningCheckbox->setChecked(opengl20_warning_show);
+ this->openCSGWarningBox->setChecked(getValue("editor/opengl20_warning_show").toBool());
}
void Preferences::apply() const
diff --git a/src/Preferences.h b/src/Preferences.h
index 79fa7ab..bdc707d 100644
--- a/src/Preferences.h
+++ b/src/Preferences.h
@@ -34,7 +34,7 @@ public slots:
void colorSchemeChanged();
void fontFamilyChanged(const QString &);
void fontSizeChanged(const QString &);
- void OpenGL20WarningChanged(bool);
+ void openCSGWarningChanged(bool);
signals:
void requestRedraw() const;
diff --git a/src/Preferences.ui b/src/Preferences.ui
index 2ab7646..556172c 100644
--- a/src/Preferences.ui
+++ b/src/Preferences.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>384</width>
+ <width>418</width>
<height>243</height>
</rect>
</property>
@@ -21,7 +21,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
- <number>1</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="page3DView">
<layout class="QVBoxLayout" name="verticalLayout_4">
@@ -181,9 +181,9 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
- <widget class="QCheckBox" name="OpenGL20WarningCheckbox">
+ <widget class="QCheckBox" name="openCSGWarningBox">
<property name="text">
- <string>Show OpenGL 2.0 warning &amp;&amp; rendering info</string>
+ <string>Show OpenCSG capability warning</string>
</property>
</widget>
</item>
@@ -239,7 +239,7 @@
<bool>true</bool>
</property>
<property name="icon">
- <iconset resource="openscad.qrc">
+ <iconset>
<normaloff>:/icons/prefs3DView.png</normaloff>:/icons/prefs3DView.png</iconset>
</property>
<property name="text">
@@ -251,7 +251,7 @@
<bool>true</bool>
</property>
<property name="icon">
- <iconset resource="openscad.qrc">
+ <iconset>
<normaloff>:/icons/prefsAdvanced.png</normaloff>:/icons/prefsAdvanced.png</iconset>
</property>
<property name="text">
@@ -263,7 +263,7 @@
<bool>true</bool>
</property>
<property name="icon">
- <iconset resource="openscad.qrc">
+ <iconset>
<normaloff>:/icons/prefsEditor.png</normaloff>:/icons/prefsEditor.png</iconset>
</property>
<property name="text">
diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc
index 01c7513..336c4c7 100644
--- a/src/ThrownTogetherRenderer.cc
+++ b/src/ThrownTogetherRenderer.cc
@@ -30,6 +30,8 @@
#include "system-gl.h"
+#include <boost/unordered_map.hpp>
+
ThrownTogetherRenderer::ThrownTogetherRenderer(CSGChain *root_chain,
CSGChain *highlights_chain,
CSGChain *background_chain)
@@ -60,9 +62,9 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,
bool fberror) const
{
glDepthFunc(GL_LEQUAL);
- QHash<QPair<PolySet*,Transform3d*>,int> polySetVisitMark;
+ boost::unordered_map<std::pair<PolySet*,Transform3d*>,int> polySetVisitMark;
for (size_t i = 0; i < chain->polysets.size(); i++) {
- if (polySetVisitMark[QPair<PolySet*,Transform3d*>(chain->polysets[i].get(), &chain->matrices[i])]++ > 0)
+ if (polySetVisitMark[std::make_pair(chain->polysets[i].get(), &chain->matrices[i])]++ > 0)
continue;
const Transform3d &m = chain->matrices[i];
double *c = chain->colors[i];
diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc
index a587987..cf5b75d 100644
--- a/src/dxftess-cgal.cc
+++ b/src/dxftess-cgal.cc
@@ -25,6 +25,8 @@ typedef CDT::Point CDTPoint;
#include <CGAL/Mesh_2/Face_badness.h>
+#include <boost/unordered_map.hpp>
+
template <class T> class DummyCriteria {
public:
typedef double Quality;
@@ -51,7 +53,7 @@ struct point_info_t
double x, y;
int pathidx, pointidx;
int max_pointidx_in_path;
- QList<int> triangles;
+ std::vector<int> triangles;
struct point_info_t *neigh_next;
struct point_info_t *neigh_prev;
@@ -61,10 +63,11 @@ struct point_info_t
point_info_t() : x(0), y(0), pathidx(-1), pointidx(-1), max_pointidx_in_path(-1) { }
};
-typedef QPair<point_info_t*,point_info_t*> edge_t;
+typedef std::pair<point_info_t*,point_info_t*> edge_t;
-void mark_inner_outer(QList<struct triangle> &tri, Grid2d<point_info_t> &point_info,
- QHash<edge_t,int> &edge_to_triangle, QHash<edge_t,int> &edge_to_path, int idx, bool inner)
+void mark_inner_outer(std::vector<struct triangle> &tri, Grid2d<point_info_t> &point_info,
+ boost::unordered_map<edge_t,int> &edge_to_triangle,
+ boost::unordered_map<edge_t,int> &edge_to_path, int idx, bool inner)
{
if (tri[idx].is_marked)
return;
@@ -85,8 +88,8 @@ void mark_inner_outer(QList<struct triangle> &tri, Grid2d<point_info_t> &point_i
};
for (int i = 0; i < 3; i++) {
- if (edge_to_triangle.contains(edges[i])) {
- bool next_inner = edge_to_path.contains(edges[i]) ? !inner : inner;
+ if (edge_to_triangle.find(edges[i]) != edge_to_triangle.end()) {
+ bool next_inner = (edge_to_path.find(edges[i]) != edge_to_path.end()) ? !inner : inner;
mark_inner_outer(tri, point_info, edge_to_triangle, edge_to_path,
edge_to_triangle[edges[i]], next_inner);
}
@@ -97,10 +100,10 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr
{
CDT cdt;
- QList<struct triangle> tri;
+ std::vector<struct triangle> tri;
Grid2d<point_info_t> point_info(GRID_FINE);
- QHash<edge_t,int> edge_to_triangle;
- QHash<edge_t,int> edge_to_path;
+ boost::unordered_map<edge_t,int> edge_to_triangle;
+ boost::unordered_map<edge_t,int> edge_to_path;
CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION);
try {
@@ -177,14 +180,14 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr
continue;
int idx = tri.size();
- tri.append(triangle());
+ tri.push_back(triangle());
point_info_t *pi[3];
for (int i=0; i<3; i++) {
double px = iter->vertex(i)->point()[0];
double py = iter->vertex(i)->point()[1];
pi[i] = &point_info.align(px, py);
- pi[i]->triangles.append(idx);
+ pi[i]->triangles.push_back(idx);
tri[idx].p[i].x = px;
tri[idx].p[i].y = py;
}
@@ -200,7 +203,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr
double far_left_x = 0;
struct point_info_t *far_left_p = NULL;
- for (int i = 0; i < tri.size(); i++)
+ for (size_t i = 0; i < tri.size(); i++)
{
if (tri[i].is_marked)
continue;
@@ -219,7 +222,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr
break;
// find one inner triangle and run recursive marking
- for (int i = 0; i < far_left_p->triangles.size(); i++)
+ for (size_t i = 0; i < far_left_p->triangles.size(); i++)
{
int idx = far_left_p->triangles[i];
@@ -273,7 +276,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr
// far left point is in the middle of a vertical segment
// -> it is ok to use any unmarked triangle connected to this point
- for (int i = 0; i < far_left_p->triangles.size(); i++)
+ for (size_t i = 0; i < far_left_p->triangles.size(); i++)
{
int idx = far_left_p->triangles[i];
@@ -288,7 +291,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr
}
// add all inner triangles to target polyset
- for(int i = 0; i < tri.size(); i++)
+ for(size_t i = 0; i < tri.size(); i++)
{
if (!tri[i].is_inner)
continue;
diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc
index 4ad2051..4207bcd 100644
--- a/src/dxftess-glu.cc
+++ b/src/dxftess-glu.cc
@@ -8,6 +8,8 @@
#include "mathc99.h"
#include <QVector>
+#include <QPair>
+#include <QHash>
#ifdef WIN32
# define STDCALL __stdcall
diff --git a/src/glview.cc b/src/glview.cc
index d69e43d..8454cd6 100644
--- a/src/glview.cc
+++ b/src/glview.cc
@@ -46,6 +46,12 @@
# include <opencsg.h>
#endif
+#ifdef _WIN32
+#include <GL/wglew.h>
+#elif !defined(__APPLE__)
+#include <GL/glxew.h>
+#endif
+
#define FAR_FAR_AWAY 100000.0
GLView::GLView(QWidget *parent) : QGLWidget(parent), renderer(NULL)
@@ -83,6 +89,8 @@ void GLView::init()
setMouseTracking(true);
#ifdef ENABLE_OPENCSG
+ this->is_opencsg_capable = false;
+ this->has_shaders = false;
this->opencsg_support = true;
static int sId = 0;
this->opencsg_id = sId++;
@@ -124,11 +132,36 @@ void GLView::initializeGL()
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
}
+
const char *openscad_disable_gl20_env = getenv("OPENSCAD_DISABLE_GL20");
- if (openscad_disable_gl20_env && !strcmp(openscad_disable_gl20_env, "0"))
+ if (openscad_disable_gl20_env && !strcmp(openscad_disable_gl20_env, "0")) {
openscad_disable_gl20_env = NULL;
- if (glewIsSupported("GL_VERSION_2_0") && openscad_disable_gl20_env == NULL)
- {
+ }
+
+ // All OpenGL 2 contexts are OpenCSG capable
+ if (GLEW_VERSION_2_0 && !openscad_disable_gl20_env) this->is_opencsg_capable = true;
+ // If OpenGL < 2, check for extensions
+ else if (GLEW_ARB_framebuffer_object) this->is_opencsg_capable = true;
+ else if (GLEW_EXT_framebuffer_object && GLEW_EXT_packed_depth_stencil) {
+ this->is_opencsg_capable = true;
+ }
+#ifdef WIN32
+ else if (WGLEW_ARB_pbuffer && WGLEW_ARB_pixel_format) this->is_opencsg_capable = true;
+#elif !defined(__APPLE__)
+ else if (GLXEW_SGIX_pbuffer && GLXEW_SGIX_fbconfig) this->is_opencsg_capable = true;
+#endif
+
+ if (GLEW_VERSION_2_0 && !openscad_disable_gl20_env) this->has_shaders = true;
+
+ if (!this->is_opencsg_capable) {
+ opencsg_support = false;
+ QSettings settings;
+ // FIXME: This should be an OpenCSG capability warning, not an OpenGL 2 warning
+ if (settings.value("editor/opengl20_warning_show",true).toBool()) {
+ QTimer::singleShot(0, this, SLOT(display_opencsg_warning()));
+ }
+ }
+ if (opencsg_support && this->has_shaders) {
const char *vs_source =
"uniform float xscale, yscale;\n"
"attribute vec3 pos_b, pos_c;\n"
@@ -212,21 +245,15 @@ void GLView::initializeGL()
fprintf(stderr, "OpenGL Program Validation results:\n%.*s", loglen, logbuffer);
}
}
- } else {
- opencsg_support = false;
- QSettings settings;
- if (settings.value("editor/opengl20_warning_show",true).toBool()) {
- QTimer::singleShot(0, this, SLOT(display_opengl20_warning()));
- }
}
#endif /* ENABLE_OPENCSG */
}
#ifdef ENABLE_OPENCSG
-void GLView::display_opengl20_warning()
+void GLView::display_opencsg_warning()
{
// data
- QString title = QString("GLEW: GL_VERSION_2_0 is not supported!");
+ QString title = QString("OpenGL context is not OpenCSG capable");
QString rendererinfo;
rendererinfo.sprintf("GLEW version %s\n"
@@ -236,10 +263,10 @@ void GLView::display_opengl20_warning()
glGetString(GL_RENDERER), glGetString(GL_VENDOR),
glGetString(GL_VERSION));
- QString message = QString("Warning: No support for OpenGL 2.0 found! OpenCSG View has been disabled.\n\n"
- "It is highly recommended to use OpenSCAD on a system with OpenGL 2.0 "
- "support. Please check if OpenGL 2.0 drivers are available for your "
- "graphics hardware. Your renderer information is as follows:\n\n%1").arg(rendererinfo);
+ QString message = QString("Warning: Missing OpenGL capabilities for OpenCSG - OpenCSG has been disabled.\n\n"
+ "It is highly recommended to use OpenSCAD on a system with OpenGL 2.0, "
+ "or support for the framebuffer_object or pbuffer extensions. "
+ "Your renderer information is as follows:\n\n%1").arg(rendererinfo);
QString note = QString("Uncheck to hide this message in the future");
@@ -269,9 +296,9 @@ void GLView::display_opengl20_warning()
// action
connect(buttonbox, SIGNAL(accepted()), dialog, SLOT(accept()));
connect(checkbox, SIGNAL(clicked(bool)),
- Preferences::inst()->OpenGL20WarningCheckbox, SLOT(setChecked(bool)));
+ Preferences::inst()->openCSGWarningBox, SLOT(setChecked(bool)));
connect(checkbox, SIGNAL(clicked(bool)),
- Preferences::inst(), SLOT(OpenGL20WarningChanged(bool)));
+ Preferences::inst(), SLOT(openCSGWarningChanged(bool)));
dialog->exec();
}
#endif
@@ -508,7 +535,14 @@ void GLView::mouseMoveEvent(QMouseEvent *event)
double dx = (this_mouse.x()-last_mouse.x()) * 0.7;
double dy = (this_mouse.y()-last_mouse.y()) * 0.7;
if (mouse_drag_active) {
- if ((event->buttons() & Qt::LeftButton) != 0) {
+ int i = event->buttons();
+ if (event->buttons() & Qt::LeftButton
+#ifdef Q_WS_MAC
+ && !(event->modifiers() & Qt::MetaModifier)
+#endif
+ ) {
+ // Left button rotates in xz, Shift-left rotates in xy
+ // On Mac, Ctrl-Left is handled as right button on other platforms
object_rot_x += dy;
if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0)
object_rot_y += dx;
@@ -519,6 +553,8 @@ void GLView::mouseMoveEvent(QMouseEvent *event)
normalizeAngle(object_rot_y);
normalizeAngle(object_rot_z);
} else {
+ // Right button pans
+ // Shift-right zooms
if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0) {
viewer_distance += (GLdouble)dy;
} else {
diff --git a/src/grid.h b/src/grid.h
index 74d72f9..2815182 100644
--- a/src/grid.h
+++ b/src/grid.h
@@ -1,7 +1,6 @@
#ifndef GRID_H_
#define GRID_H_
-#include <QHash>
#include "mathc99.h"
#ifdef WIN32
typedef __int64 int64_t;
@@ -9,6 +8,8 @@ typedef __int64 int64_t;
#include <stdint.h>
#endif
#include <stdlib.h>
+#include <boost/unordered_map.hpp>
+#include <utility>
const double GRID_COARSE = 0.001;
const double GRID_FINE = 0.000001;
@@ -18,7 +19,7 @@ class Grid2d
{
public:
double res;
- QHash<QPair<int64_t,int64_t>, T> db;
+ boost::unordered_map<std::pair<int64_t,int64_t>, T> db;
Grid2d(double resolution) {
res = resolution;
@@ -31,11 +32,11 @@ public:
T &align(double &x, double &y) {
int64_t ix = (int64_t)round(x / res);
int64_t iy = (int64_t)round(y / res);
- if (!db.contains(QPair<int64_t,int64_t>(ix, iy))) {
+ if (db.find(std::make_pair(ix, iy)) == db.end()) {
int dist = 10;
for (int64_t jx = ix - 1; jx <= ix + 1; jx++) {
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
- if (!db.contains(QPair<int64_t,int64_t>(jx, jy)))
+ if (db.find(std::make_pair(jx, jy)) == db.end())
continue;
int d = abs(int(ix-jx)) + abs(int(iy-jy));
if (d < dist) {
@@ -47,16 +48,16 @@ public:
}
}
x = ix * res, y = iy * res;
- return db[QPair<int64_t,int64_t>(ix, iy)];
+ return db[std::make_pair(ix, iy)];
}
bool has(double x, double y) const {
int64_t ix = (int64_t)round(x / res);
int64_t iy = (int64_t)round(y / res);
- if (db.contains(QPair<int64_t,int64_t>(ix, iy)))
+ if (db.find(std::make_pair(ix, iy)) != db.end())
return true;
for (int64_t jx = ix - 1; jx <= ix + 1; jx++)
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
- if (db.contains(QPair<int64_t,int64_t>(jx, jy)))
+ if (db.find(std::make_pair(jx, jy)) != db.end())
return true;
}
return false;
@@ -81,7 +82,7 @@ class Grid3d
{
public:
double res;
- QHash<QPair<QPair<int64_t,int64_t>,int64_t>, T> db;
+ boost::unordered_map<std::pair<std::pair<int64_t,int64_t>,int64_t>, T> db;
Grid3d(double resolution) {
res = resolution;
@@ -90,12 +91,12 @@ public:
int64_t ix = (int64_t)round(x / res);
int64_t iy = (int64_t)round(y / res);
int64_t iz = (int64_t)round(z / res);
- if (!db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz))) {
+ if (db.find(std::make_pair(std::make_pair(ix, iy), iz)) == db.end()) {
int dist = 10;
for (int64_t jx = ix - 1; jx <= ix + 1; jx++) {
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
for (int64_t jz = iz - 1; jz <= iz + 1; jz++) {
- if (!db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(jx, jy), jz)))
+ if (db.find(std::make_pair(std::make_pair(jx, jy), jz)) == db.end())
continue;
int d = abs(int(ix-jx)) + abs(int(iy-jy)) + abs(int(iz-jz));
if (d < dist) {
@@ -109,18 +110,18 @@ public:
}
}
x = ix * res, y = iy * res, z = iz * res;
- return db[QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz)];
+ return db[std::make_pair(std::make_pair(ix, iy), iz)];
}
bool has(double x, double y, double z) {
int64_t ix = (int64_t)round(x / res);
int64_t iy = (int64_t)round(y / res);
int64_t iz = (int64_t)round(z / res);
- if (db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz)))
+ if (db.find(std::make_pair(std::make_pair(ix, iy), iz)) != db.end())
return true;
for (int64_t jx = ix - 1; jx <= ix + 1; jx++)
for (int64_t jy = iy - 1; jy <= iy + 1; jy++)
for (int64_t jz = iz - 1; jz <= iz + 1; jz++) {
- if (db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(jx, jy), jz)))
+ if (db.find(std::make_pair(std::make_pair(jx, jy), jz)) != db.end())
return true;
}
return false;
diff --git a/src/node.cc b/src/node.cc
index a4d70be..eccb9a6 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -96,6 +96,8 @@ void AbstractNode::progress_report() const
std::ostream &operator<<(std::ostream &stream, const AbstractNode &node)
{
+ // FIXME: Don't use deep access to modinst members
+ if (node.modinst->tag_background) stream << "%";
stream << node.toString();
return stream;
}
diff --git a/src/system-gl.h b/src/system-gl.h
index cdbf3dc..76b49e7 100644
--- a/src/system-gl.h
+++ b/src/system-gl.h
@@ -2,6 +2,7 @@
#define SYSTEMGL_H_
#include <GL/glew.h>
+
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#else
contact: Jan Huwald // Impressum