diff options
-rw-r--r-- | bison.pri | 15 | ||||
-rw-r--r-- | boost.pri | 11 | ||||
-rw-r--r-- | cgal.pri | 7 | ||||
-rw-r--r-- | flex.pri | 10 | ||||
-rw-r--r-- | openscad.pro | 33 | ||||
-rw-r--r-- | src/dxfdata.cc | 2 | ||||
-rw-r--r-- | src/dxfdim.cc | 19 | ||||
-rw-r--r-- | src/dxflinextrude.cc | 16 | ||||
-rw-r--r-- | src/dxfrotextrude.cc | 16 | ||||
-rw-r--r-- | src/dxftess-glu.cc | 2 | ||||
-rw-r--r-- | src/func.cc | 5 | ||||
-rw-r--r-- | src/glview.cc | 2 | ||||
-rw-r--r-- | src/grid.h | 2 | ||||
-rw-r--r-- | src/import.cc | 13 | ||||
-rw-r--r-- | src/mainwin.cc | 15 | ||||
-rw-r--r-- | src/mathc99.cc | 18 | ||||
-rw-r--r-- | src/mathc99.h | 18 | ||||
-rw-r--r-- | src/nef2dxf.cc | 2 | ||||
-rw-r--r-- | src/polyset.cc | 14 | ||||
-rw-r--r-- | src/primitives.cc | 28 | ||||
-rw-r--r-- | src/projection.cc | 3 | ||||
-rw-r--r-- | src/value.cc | 2 |
22 files changed, 169 insertions, 84 deletions
diff --git a/bison.pri b/bison.pri new file mode 100644 index 0000000..cf67768 --- /dev/null +++ b/bison.pri @@ -0,0 +1,15 @@ +#setup bison for qmake
+bison.name = Bison ${QMAKE_FILE_IN}
+bison.input = BISONSOURCES
+bison.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.cpp
+bison.commands = bison -d -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.cpp ${QMAKE_FILE_IN}
+bison.CONFIG += target_predeps
+bison.variable_out = GENERATED_SOURCES
+silent:bison.commands = @echo Bison ${QMAKE_FILE_IN} && $$bison.commands
+QMAKE_EXTRA_COMPILERS += bison
+bison_header.input = BISONSOURCES
+bison_header.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.hpp
+bison_header.commands = bison -d -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.cpp ${QMAKE_FILE_IN}
+bison_header.CONFIG += target_predeps no_link
+silent:bison_header.commands = @echo Bison ${QMAKE_FILE_IN} && $$bison.commands
+QMAKE_EXTRA_COMPILERS += bison_header
diff --git a/boost.pri b/boost.pri new file mode 100644 index 0000000..8907b2d --- /dev/null +++ b/boost.pri @@ -0,0 +1,11 @@ +boost {
+ isEmpty(DEPLOYDIR) {
+ # Optionally specify location of boost using the
+ # BOOSTDIR env. variable
+ BOOST_DIR = $$(BOOSTDIR)
+ !isEmpty(BOOST_DIR) {
+ INCLUDEPATH += $$BOOST_DIR
+ message("boost location: $$BOOST_DIR")
+ }
+ }
+}
@@ -12,6 +12,11 @@ cgal { } } - LIBS += -lCGAL -lmpfr -lgmp -lboost_thread + LIBS += -lCGAL -lmpfr -lboost_thread + win32 { + LIBS += -lmpir + } else { + LIBS += -lgmp + } QMAKE_CXXFLAGS += -frounding-math } diff --git a/flex.pri b/flex.pri new file mode 100644 index 0000000..11f6878 --- /dev/null +++ b/flex.pri @@ -0,0 +1,10 @@ +#setup flex for qmake
+
+flex.name = Flex ${QMAKE_FILE_IN}
+flex.input = FLEXSOURCES
+flex.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.lexer.cpp
+flex.commands = flex -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.lexer.cpp ${QMAKE_FILE_IN}
+flex.CONFIG += target_predeps
+flex.variable_out = GENERATED_SOURCES
+silent:flex.commands = @echo Lex ${QMAKE_FILE_IN} && $$flex.commands
+QMAKE_EXTRA_COMPILERS += flex
diff --git a/openscad.pro b/openscad.pro index ee237c5..d83606f 100644 --- a/openscad.pro +++ b/openscad.pro @@ -14,7 +14,30 @@ win32 { isEmpty(VERSION) VERSION = $$system(date "+%Y.%m.%d") } +#configure lex / yacc +win32 { + include(flex.pri) + include(bison.pri) + FLEXSOURCES = src/lexer.l + BISONSOURCES = src/parser.y +} else { + LEXSOURCES += src/lexer.l + YACCSOURCES += src/parser.y +} + +#configure additional directories +win32 { + INCLUDEPATH += $$(MPIRDIR) + INCLUDEPATH += $$(MPFRDIR) +} + DEFINES += OPENSCAD_VERSION=$$VERSION +win32:DEFINES += _USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS + +#disable warning about too long decorated names +win32:QMAKE_CXXFLAGS += -wd4503 + + TEMPLATE = app RESOURCES = openscad.qrc @@ -60,6 +83,7 @@ macx:CONFIG += mdi CONFIG += cgal CONFIG += opencsg CONFIG += progresswidget +CONFIG += boost #Uncomment the following line to enable QCodeEdit #CONFIG += qcodeedit @@ -79,6 +103,7 @@ progresswidget { include(cgal.pri) include(opencsg.pri) include(eigen2.pri) +include(boost.pri) # Standard include path for misc external libs #macx { @@ -89,8 +114,6 @@ include(eigen2.pri) # QMAKE_CXXFLAGS += -pg # QMAKE_LFLAGS += -pg -LEXSOURCES += src/lexer.l -YACCSOURCES += src/parser.y FORMS += src/MainWindow.ui \ src/Preferences.ui @@ -118,7 +141,8 @@ HEADERS += src/CGAL_renderer.h \ src/printutils.h \ src/value.h \ src/progress.h \ - src/editor.h + src/editor.h \ + src/mathc99.h SOURCES += src/openscad.cc \ src/mainwin.cc \ @@ -155,7 +179,8 @@ SOURCES += src/openscad.cc \ src/nef2dxf.cc \ src/Preferences.cc \ src/progress.cc \ - src/editor.cc + src/editor.cc \ + src/mathc99.cc macx { HEADERS += src/AppleEvents.h \ diff --git a/src/dxfdata.cc b/src/dxfdata.cc index e896229..55d00b4 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -33,7 +33,7 @@ #include <QTextStream> #include <QHash> #include <QVector> -#include <math.h> +#include "mathc99.h" #include <assert.h> struct Line { diff --git a/src/dxfdim.cc b/src/dxfdim.cc index c951868..060691b 100644 --- a/src/dxfdim.cc +++ b/src/dxfdim.cc @@ -32,11 +32,10 @@ #include "printutils.h" #include "context.h" -#include <math.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> +#include "mathc99.h" #include <QHash> +#include <QDatetime> +#include <QFileInfo> QHash<QString,Value> dxf_dim_cache; QHash<QString,Value> dxf_cross_cache; @@ -63,12 +62,10 @@ Value builtin_dxf_dim(const Context *ctx, const QVector<QString> &argnames, cons name = args[i].text; } - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); QString key = filename + "|" + layername + "|" + name + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) + - "|" + QString::number(scale) + "|" + QString::number(st.st_mtime) + "|" + QString::number(st.st_size); + "|" + QString::number(scale) + "|" + QString::number(fileInfo.lastModified().toTime_t()) + "|" + QString::number(fileInfo.size()); if (dxf_dim_cache.contains(key)) return dxf_dim_cache[key]; @@ -145,12 +142,10 @@ Value builtin_dxf_cross(const Context *ctx, const QVector<QString> &argnames, co args[i].getnum(scale); } - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); QString key = filename + "|" + layername + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) + - "|" + QString::number(scale) + "|" + QString::number(st.st_mtime) + "|" + QString::number(st.st_size); + "|" + QString::number(scale) + "|" + QString::number(fileInfo.lastModified().toTime_t()) + "|" + QString::number(fileInfo.size()); if (dxf_cross_cache.contains(key)) return dxf_cross_cache[key]; diff --git a/src/dxflinextrude.cc b/src/dxflinextrude.cc index 2f3fcb1..9661066 100644 --- a/src/dxflinextrude.cc +++ b/src/dxflinextrude.cc @@ -35,13 +35,11 @@ #include "progress.h" #include "openscad.h" // get_fragments_from_r() -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - #include <QApplication> #include <QTime> #include <QProgressDialog> +#include <QDateTime> +#include <QFileInfo> class DxfLinearExtrudeModule : public AbstractModule { @@ -321,14 +319,12 @@ QString DxfLinearExtrudeNode::dump(QString indent) const { if (dump_cache.isEmpty()) { QString text; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); text.sprintf("linear_extrude(file = \"%s\", cache = \"%x.%x\", layer = \"%s\", " "height = %g, origin = [ %g %g ], scale = %g, center = %s, convexity = %d", - filename.toAscii().data(), (int)st.st_mtime, (int)st.st_size, - layername.toAscii().data(), height, origin_x, origin_y, scale, - center ? "true" : "false", convexity); + filename.toAscii().data(), (int)fileInfo.lastModified().toTime_t(), + (int)fileInfo.size(), layername.toAscii().data(), height, origin_x, + origin_y, scale, center ? "true" : "false", convexity); if (has_twist) { QString t2; t2.sprintf(", twist = %g, slices = %d", twist, slices); diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc index 2df66be..a7a6cf1 100644 --- a/src/dxfrotextrude.cc +++ b/src/dxfrotextrude.cc @@ -34,13 +34,11 @@ #include "progress.h" #include "openscad.h" // get_fragments_from_r() -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - #include <QTime> #include <QApplication> #include <QProgressDialog> +#include <QDateTime> +#include <QFileInfo> class DxfRotateExtrudeModule : public AbstractModule { @@ -218,15 +216,13 @@ QString DxfRotateExtrudeNode::dump(QString indent) const { if (dump_cache.isEmpty()) { QString text; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(filename.toAscii().data(), &st); + QFileInfo fileInfo(filename); text.sprintf("rotate_extrude(file = \"%s\", cache = \"%x.%x\", layer = \"%s\", " "origin = [ %g %g ], scale = %g, convexity = %d, " "$fn = %g, $fa = %g, $fs = %g) {\n", - filename.toAscii().data(), (int)st.st_mtime, (int)st.st_size, - layername.toAscii().data(), origin_x, origin_y, scale, convexity, - fn, fa, fs); + filename.toAscii().data(), (int)fileInfo.lastModified().toTime_t(), + (int)fileInfo.size(),layername.toAscii().data(), origin_x, origin_y, + scale, convexity, fn, fa, fs); foreach (AbstractNode *v, children) text += v->dump(indent + QString("\t")); text += indent + "}\n"; diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc index ca12ea9..63fa2e5 100644 --- a/src/dxftess-glu.cc +++ b/src/dxftess-glu.cc @@ -9,7 +9,7 @@ # include <GL/glew.h> #endif #include <qgl.h> -#include <math.h> +#include "mathc99.h" #ifdef WIN32 # define STDCALL __stdcall diff --git a/src/func.cc b/src/func.cc index 59821e3..2608960 100644 --- a/src/func.cc +++ b/src/func.cc @@ -29,7 +29,8 @@ #include "context.h" #include "dxfdim.h" #include "builtin.h" -#include <math.h> +#include "mathc99.h" +#include <time.h> AbstractFunction::~AbstractFunction() { @@ -290,7 +291,7 @@ Value builtin_log(const Context *, const QVector<QString>&, const QVector<Value> if (args.size() == 2 && args[0].type == Value::NUMBER && args[1].type == Value::NUMBER) return Value(log(args[1].num) / log(args[0].num)); if (args.size() == 1 && args[0].type == Value::NUMBER) - return Value(log(args[0].num) / log(10)); + return Value(log(args[0].num) / log(10.0)); return Value(); } diff --git a/src/glview.cc b/src/glview.cc index 081c172..870a1c9 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -32,7 +32,7 @@ #include <QMouseEvent> #include <QMessageBox> #include <QTimer> -#include <math.h> +#include "mathc99.h" #include <stdio.h> #define FAR_FAR_AWAY 100000.0 @@ -1,7 +1,7 @@ #ifndef GRID_H_ #define GRID_H_ -#include <math.h> +#include "mathc99.h" #include <stdint.h> #include <stdlib.h> #include <QHash> diff --git a/src/import.cc b/src/import.cc index bd9d387..a924e24 100644 --- a/src/import.cc +++ b/src/import.cc @@ -174,13 +174,24 @@ PolySet *ImportNode::render_polyset(render_mode_e) const { f.read(80-5+4); while (1) { +#ifdef _MSC_VER +#pragma pack(push,1) +#endif struct { float i, j, k; float x1, y1, z1; float x2, y2, z2; float x3, y3, z3; unsigned short acount; - } __attribute__ ((packed)) data; + } +#ifdef __GNUC__ + __attribute__ ((packed)) +#endif + data; +#ifdef _MSC_VER +#pragma pack(pop) +#endif + if (f.read((char*)&data, sizeof(data)) != sizeof(data)) break; p->append_poly(); diff --git a/src/mainwin.cc b/src/mainwin.cc index a5c49f0..e217b1f 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -73,13 +73,6 @@ #include "qlanguagefactory.h" #endif -//for chdir -#include <unistd.h> - -// for stat() -#include <sys/types.h> -#include <sys/stat.h> - #ifdef ENABLE_CGAL #if 1 @@ -993,10 +986,8 @@ void MainWindow::pasteViewportRotation() void MainWindow::checkAutoReload() { QString new_stinfo; - struct stat st; - memset(&st, 0, sizeof(struct stat)); - stat(this->fileName.toAscii().data(), &st); - new_stinfo.sprintf("%x.%x", (int)st.st_mtime, (int)st.st_size); + QFileInfo finfo(this->fileName); + new_stinfo = QString::number(finfo.size()) + QString::number(finfo.lastModified().toTime_t()); if (new_stinfo != autoReloadInfo) actionReloadCompile(); autoReloadInfo = new_stinfo; @@ -1474,7 +1465,7 @@ static void renderGLviaCGAL(void *vp) glColor3f(col2.redF(), col2.greenF(), col2.blueF()); // Extract the boundary, including inner boundaries of the polygons - for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit) + for (fci_t fit = E.faces_begin(), facesend = E.faces_end(); fit != facesend; ++fit) { bool fset = false; double fx = 0.0, fy = 0.0; diff --git a/src/mathc99.cc b/src/mathc99.cc new file mode 100644 index 0000000..335446e --- /dev/null +++ b/src/mathc99.cc @@ -0,0 +1,18 @@ +#include "mathc99.h"
+
+#ifdef WIN32
+#include <algorithm>
+
+double round(double a) {
+ return a > 0 ? floor(a+0.5) : ceil(a-0.5);
+}
+
+float fmin(float a, float b) {
+ return std::min(a,b);
+}
+
+float fmax(float a, float b) {
+ return std::max(a,b);
+}
+
+#endif
diff --git a/src/mathc99.h b/src/mathc99.h new file mode 100644 index 0000000..ebc2d66 --- /dev/null +++ b/src/mathc99.h @@ -0,0 +1,18 @@ +#ifndef MATHC99_H_
+#define MATHC99_H_
+
+#ifdef WIN32
+
+#include <cmath>
+//for native win32 builds we need to provide C99 math functions by ourselves
+double round(double a);
+float fmin(float a, float b);
+float fmax(float a, float b);
+
+#else
+
+#include <math.h>
+
+#endif
+
+#endif
diff --git a/src/nef2dxf.cc b/src/nef2dxf.cc index 1f65637..320d6b8 100644 --- a/src/nef2dxf.cc +++ b/src/nef2dxf.cc @@ -39,7 +39,7 @@ DxfData::DxfData(const struct CGAL_Nef_polyhedron &N) typedef Explorer::Halfedge_around_face_const_circulator heafcc_t; Explorer E = N.p2.explorer(); - for (fci_t fit = E.faces_begin(), fend = E.faces_end(); fit != fend; ++fit) + for (fci_t fit = E.faces_begin(), facesend = E.faces_end(); fit != facesend; ++fit) { heafcc_t fcirc(E.halfedge(fit)), fend(fcirc); int first_point = -1, last_point = -1; diff --git a/src/polyset.cc b/src/polyset.cc index 77ae26e..cccdaad 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -150,7 +150,7 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m #ifdef ENABLE_OPENCSG if (shaderinfo) { glUniform4f(shaderinfo[1], col.redF(), col.greenF(), col.blueF(), 1.0f); - glUniform4f(shaderinfo[2], 255 / 255.0, 236 / 255.0, 94 / 255.0, 1.0); + glUniform4f(shaderinfo[2], 255 / 255.0f, 236 / 255.0f, 94 / 255.0f, 1.0f); } #endif /* ENABLE_OPENCSG */ } @@ -159,8 +159,8 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m glColor3f(col.redF(), col.greenF(), col.blueF()); #ifdef ENABLE_OPENCSG if (shaderinfo) { - glUniform4f(shaderinfo[1], 157 / 255.0, 203 / 255.0, 81 / 255.0, 1.0); - glUniform4f(shaderinfo[2], 171 / 255.0, 216 / 255.0, 86 / 255.0, 1.0); + glUniform4f(shaderinfo[1], 157 / 255.0f, 203 / 255.0f, 81 / 255.0f, 1.0f); + glUniform4f(shaderinfo[2], 171 / 255.0f, 216 / 255.0f, 86 / 255.0f, 1.0f); } #endif /* ENABLE_OPENCSG */ } @@ -168,8 +168,8 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m glColor4ub(255, 157, 81, 128); #ifdef ENABLE_OPENCSG if (shaderinfo) { - glUniform4f(shaderinfo[1], 255 / 255.0, 157 / 255.0, 81 / 255.0, 0.5); - glUniform4f(shaderinfo[2], 255 / 255.0, 171 / 255.0, 86 / 255.0, 0.5); + glUniform4f(shaderinfo[1], 255 / 255.0f, 157 / 255.0f, 81 / 255.0f, 0.5f); + glUniform4f(shaderinfo[2], 255 / 255.0f, 171 / 255.0f, 86 / 255.0f, 0.5f); } #endif /* ENABLE_OPENCSG */ } @@ -177,8 +177,8 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m glColor4ub(180, 180, 180, 128); #ifdef ENABLE_OPENCSG if (shaderinfo) { - glUniform4f(shaderinfo[1], 180 / 255.0, 180 / 255.0, 180 / 255.0, 0.5); - glUniform4f(shaderinfo[2], 150 / 255.0, 150 / 255.0, 150 / 255.0, 0.5); + glUniform4f(shaderinfo[1], 180 / 255.0f, 180 / 255.0f, 180 / 255.0f, 0.5f); + glUniform4f(shaderinfo[2], 150 / 255.0f, 150 / 255.0f, 150 / 255.0f, 0.5f); } #endif /* ENABLE_OPENCSG */ } diff --git a/src/primitives.cc b/src/primitives.cc index 1fb1011..d0cd1b5 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -279,7 +279,7 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e) const }; int rings = get_fragments_from_r(r1, fn, fs, fa); - ring_s ring[rings]; + ring_s *ring = new ring_s[rings]; for (int i = 0; i < rings; i++) { double phi = (M_PI * (i + 0.5)) / rings; @@ -333,6 +333,8 @@ sphere_next_r2: p->append_poly(); for (int i = 0; i < ring[rings-1].fragments; i++) p->insert_vertex(ring[rings-1].points[i].x, ring[rings-1].points[i].y, ring[rings-1].z); + + delete[] ring; } if (type == CYLINDER && h > 0 && r1 >=0 && r2 >= 0 && (r1 > 0 || r2 > 0)) @@ -352,8 +354,8 @@ sphere_next_r2: double x, y; }; - point2d circle1[fragments]; - point2d circle2[fragments]; + point2d *circle1 = new point2d[fragments]; + point2d *circle2 = new point2d[fragments]; for (int i=0; i<fragments; i++) { double phi = (M_PI*2*i) / fragments; @@ -400,6 +402,9 @@ sphere_next_r2: for (int i=0; i<fragments; i++) p->append_vertex(circle2[i].x, circle2[i].y, z2); } + + delete[] circle1; + delete[] circle2; } if (type == POLYHEDRON) @@ -445,22 +450,13 @@ sphere_next_r2: { int fragments = get_fragments_from_r(r1, fn, fs, fa); - struct point2d { - double x, y; - }; - - point2d circle[fragments]; + p->is2d = true; + p->append_poly(); - for (int i=0; i<fragments; i++) { + for (int i=0; i < fragments; i++) { double phi = (M_PI*2*i) / fragments; - circle[i].x = r1*cos(phi); - circle[i].y = r1*sin(phi); + p->append_vertex(r1*cos(phi), r1*sin(phi)); } - - p->is2d = true; - p->append_poly(); - for (int i=0; i<fragments; i++) - p->append_vertex(circle[i].x, circle[i].y); } if (type == POLYGON) diff --git a/src/projection.cc b/src/projection.cc index c709e95..f41ba56 100644 --- a/src/projection.cc +++ b/src/projection.cc @@ -40,9 +40,6 @@ # include <CGAL/exceptions.h> #endif -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <assert.h> #include <QApplication> diff --git a/src/value.cc b/src/value.cc index bf912ac..b0a79a4 100644 --- a/src/value.cc +++ b/src/value.cc @@ -25,7 +25,7 @@ */ #include "value.h" -#include <math.h> +#include "mathc99.h" Value::Value() { |