diff --git a/.travis.yml b/.travis.yml index 2a3ab600..a4536899 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,11 @@ compiler: gcc before_install: - echo 'yes' | sudo add-apt-repository ppa:chrysn/openscad - sudo apt-get update -qq - - sudo apt-get install -qq build-essential libqt4-dev libqt4-opengl-dev libxmu-dev cmake bison flex git-core libboost-all-dev libXi-dev libmpfr-dev libboost-dev libglew-dev libeigen2-dev libeigen3-dev libcgal-dev libgmp3-dev libgmp-dev python-paramiko curl imagemagick + - sudo apt-get install -qq build-essential libqt4-dev libqt4-opengl-dev libxmu-dev cmake bison flex git-core libboost-all-dev libXi-dev libmpfr-dev libboost-dev libglew-dev libeigen3-dev libcgal-dev libgmp3-dev libgmp-dev curl imagemagick libfontconfig-dev - sudo apt-get install -qq libopencsg-dev + - echo 'yes' | sudo add-apt-repository ppa:mapnik/nightly-trunk + - sudo apt-get update -qq + - sudo apt-get install -qq libharfbuzz-dev branches: only: diff --git a/contrib/OpenSCAD.plist b/contrib/OpenSCAD.plist index 2f8860ca..97451d4f 100644 --- a/contrib/OpenSCAD.plist +++ b/contrib/OpenSCAD.plist @@ -1,6 +1,27 @@ + + BBEditDocumentType CodelessLanguageModule @@ -10,52 +31,150 @@ BBLMIsCaseSensitive + BBLMPredefinedNameList + + + true + false + undef + PI + + + auto + center + invert + size + points + faces + convexity + file + layer + origin + + + % + # + ! + * + + + $fa + $fs + $fn + $t + $vpr + $vpt + + BBLMKeywordList - ! - # - $fa - $fn - $fs - $t - % - * - assign - center - circle - color - cube - cylinder - difference - echo - for - function - hull - if - import_dxf - import_stl - include - intersection - intersection_for - linear_extrude - minkowski - mirror - module - multmatrix - polygon - polyhedron - projection - render - rotate - rotate_extrude - scale - sphere + + square + circle + polygon + + + cube + sphere + cylinder + polyhedron + + + for + intersection_for + if + else + assign + + + ? + + + cos + sin + tan + acos + asin + atan + atan2 + + + abs + ceil + cross + exp + floor + ln + len + log + lookup + max + min + norm + pow + rands + round + sign + sqrt + + str - surface + + + scale + rotate translate + resize + mirror + multmatrix + color + minkowski + hull + + union + difference + intersection + linear_extrude + + + module + children + function + + + import + include use + dxf_cross + + + + + echo + + + render + + + offset + + + surface + + + search + + + version + version_num + parent_module + $parent_modules + BBLMLanguageCode Oscd diff --git a/contrib/scad-mode.el b/contrib/scad-mode.el index 070caaf4..2a772145 100644 --- a/contrib/scad-mode.el +++ b/contrib/scad-mode.el @@ -3,10 +3,10 @@ ;; Author: Len Trigg ;; Maintainer: Len Trigg ;; Created: March 2010 -;; Modified: 06 July 2012 +;; Modified: 24 May 2014 ;; Keywords: languages ;; URL: https://raw.github.com/openscad/openscad/master/contrib/scad-mode.el -;; Version: 90.0 +;; Version: 91.0 ;; 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 @@ -143,6 +143,7 @@ (defvar scad-font-lock-keywords `( ("\\(module\\|function\\)[ \t]+\\(\\sw+\\)" (1 'font-lock-keyword-face nil) (2 'font-lock-function-name-face nil t)) + ("\\(use\\|include\\)[ \t]*<\\([^>]+\\)>" (1 'font-lock-preprocessor-face nil) (2 'font-lock-type-face nil t)) ("<\\(\\sw+\\)>" (1 'font-lock-builtin-face nil)) ("$\\(\\sw+\\)" (1 'font-lock-builtin-face nil)) (,scad-keywords-regexp . font-lock-keyword-face) @@ -173,14 +174,24 @@ ) +;; From: http://stackoverflow.com/questions/14520073/add-words-for-dynamic-expansion-to-emacs-mode +(defun scad-prime-dabbrev () + "Makes a hidden scad-mode buffer containing all the scad keywords, so dabbrev expansion just works." + (unless (get-buffer " *scad words*") + (with-current-buffer (get-buffer-create " *scad words*") + (scad-mode) + (insert "module function use include") ; Explicitly add these -- they're not in the below vars + (insert (mapconcat 'identity (append scad-keywords scad-functions scad-modules) " "))))) +(add-hook 'scad-mode-hook 'scad-prime-dabbrev) + + ;;; Indentation, based on http://www.emacswiki.org/emacs/download/actionscript-mode-haas-7.0.el (defun scad-indent-line () "Indent current line of SCAD code." (interactive) (let ((savep (> (current-column) (current-indentation))) - (indent (condition-case nil (max (scad-calculate-indentation) 0) - (error 0)))) + (indent (max (scad-calculate-indentation) 0))) (if savep (save-excursion (indent-line-to indent)) (indent-line-to indent)))) @@ -224,9 +235,9 @@ ;; Don't count if in string or comment. ((scad-face-at-point (- (point) 1))) ((looking-back "\\s)") - (incf close-count)) + (setq close-count (+ close-count 1))) ((looking-back "\\s(") - (incf open-count)) + (setq open-count (+ open-count 1))) ))) (- open-count close-count)))) diff --git a/scripts/macosx-build-dependencies.sh b/scripts/macosx-build-dependencies.sh index 7466582c..82d03c47 100755 --- a/scripts/macosx-build-dependencies.sh +++ b/scripts/macosx-build-dependencies.sh @@ -721,8 +721,8 @@ build_gettext 0.18.3.1 build_libffi 3.0.13 build_glib2 2.38.2 build_opencsg 1.3.2 -build_harfbuzz 0.9.27 "--with-coretext=auto --with-glib=no" build_freetype 2.5.3 --without-png +build_harfbuzz 0.9.27 "--with-coretext=auto --with-glib=no" export FREETYPE_CFLAGS="-I$DEPLOYDIR/include -I$DEPLOYDIR/include/freetype2" export FREETYPE_LIBS="-L$DEPLOYDIR/lib -lfreetype" build_libxml2 2.9.1 diff --git a/src/CGALRenderer.cc b/src/CGALRenderer.cc index f24389c0..f072e309 100644 --- a/src/CGALRenderer.cc +++ b/src/CGALRenderer.cc @@ -40,7 +40,7 @@ //#include "Preferences.h" -CGALRenderer::CGALRenderer(shared_ptr geom) : polyhedron(NULL) +CGALRenderer::CGALRenderer(shared_ptr geom) { if (shared_ptr ps = dynamic_pointer_cast(geom)) { this->polyset = ps; @@ -51,7 +51,7 @@ CGALRenderer::CGALRenderer(shared_ptr geom) : polyhedron(N else if (shared_ptr new_N = dynamic_pointer_cast(geom)) { assert(new_N->getDimension() == 3); if (!new_N->isEmpty()) { - this->polyhedron = new Polyhedron(); + this->polyhedron.reset(new Polyhedron()); // FIXME: Make independent of Preferences // this->polyhedron->setColor(Polyhedron::CGAL_NEF3_MARKED_FACET_COLOR, // Preferences::inst()->color(Preferences::CGAL_FACE_BACK_COLOR).red(), @@ -62,7 +62,7 @@ CGALRenderer::CGALRenderer(shared_ptr geom) : polyhedron(N // Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).green(), // Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).blue()); - CGAL::OGL::Nef3_Converter::convert_to_OGLPolyhedron(*new_N->p3, this->polyhedron); + CGAL::OGL::Nef3_Converter::convert_to_OGLPolyhedron(*new_N->p3, this->polyhedron.get()); this->polyhedron->init(); } } @@ -70,7 +70,6 @@ CGALRenderer::CGALRenderer(shared_ptr geom) : polyhedron(N CGALRenderer::~CGALRenderer() { - delete this->polyhedron; } void CGALRenderer::draw(bool showfaces, bool showedges) const diff --git a/src/CGALRenderer.h b/src/CGALRenderer.h index 193e1e68..57a0e4ab 100644 --- a/src/CGALRenderer.h +++ b/src/CGALRenderer.h @@ -10,6 +10,6 @@ public: void draw(bool showfaces, bool showedges) const; public: - class Polyhedron *polyhedron; + shared_ptr polyhedron; shared_ptr polyset; }; diff --git a/src/DrawingCallback.h b/src/DrawingCallback.h index 1ebd1728..825b1b8c 100644 --- a/src/DrawingCallback.h +++ b/src/DrawingCallback.h @@ -23,8 +23,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#ifndef DRAWINGCALLBACK_H -#define DRAWINGCALLBACK_H +#pragma once #include #include @@ -62,6 +61,3 @@ private: return pow(1.0 - t, exp); } }; - -#endif /* DRAWINGCALLBACK_H */ - diff --git a/src/FontCache.h b/src/FontCache.h index 1fc7b414..58d79f09 100644 --- a/src/FontCache.h +++ b/src/FontCache.h @@ -23,8 +23,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#ifndef FONTCACHE_H -#define FONTCACHE_H +#pragma once #include #include @@ -96,5 +95,3 @@ private: FT_Face find_face_in_path(std::string path, std::string font); }; -#endif /* FONTCACHE_H */ - diff --git a/src/FontListDialog.h b/src/FontListDialog.h index b1cbaa97..34a4042a 100644 --- a/src/FontListDialog.h +++ b/src/FontListDialog.h @@ -1,5 +1,4 @@ -#ifndef FONTLISTDIALOG_H_ -#define FONTLISTDIALOG_H_ +#pragma once #include @@ -19,5 +18,3 @@ public: private: QStandardItemModel *model; }; - -#endif diff --git a/src/FreetypeRenderer.h b/src/FreetypeRenderer.h index 1332d9cf..c18d9d0d 100644 --- a/src/FreetypeRenderer.h +++ b/src/FreetypeRenderer.h @@ -23,8 +23,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#ifndef FREETYPERENDERER_H -#define FREETYPERENDERER_H +#pragma once #include #include @@ -87,7 +86,7 @@ public: double size, spacing, fn; std::string text, font, direction, language, script, halign, valign; - friend FreetypeRenderer; + friend class FreetypeRenderer; }; FreetypeRenderer(); @@ -136,6 +135,3 @@ private: static int outline_conic_to_func(const FT_Vector *c1, const FT_Vector *to, void *user); static int outline_cubic_to_func(const FT_Vector *c1, const FT_Vector *c2, const FT_Vector *to, void *user); }; - -#endif /* FREETYPERENDERER_H */ - diff --git a/src/Geometry.h b/src/Geometry.h index 042a0658..ffe7bf22 100644 --- a/src/Geometry.h +++ b/src/Geometry.h @@ -1,5 +1,4 @@ -#ifndef GEOMETRY_H_ -#define GEOMETRY_H_ +#pragma once #include #include @@ -29,5 +28,3 @@ public: protected: int convexity; }; - -#endif diff --git a/src/GeometryCache.h b/src/GeometryCache.h index 7dfaad73..5dd380ea 100644 --- a/src/GeometryCache.h +++ b/src/GeometryCache.h @@ -1,5 +1,4 @@ -#ifndef GEOMETRYCACHE_H_ -#define GEOMETRYCACHE_H_ +#pragma once #include "cache.h" #include "memory.h" @@ -32,5 +31,3 @@ private: Cache cache; }; - -#endif diff --git a/src/GeometryEvaluator.cc b/src/GeometryEvaluator.cc index da398b1c..74a66b27 100644 --- a/src/GeometryEvaluator.cc +++ b/src/GeometryEvaluator.cc @@ -97,13 +97,14 @@ GeometryEvaluator::ResultObject GeometryEvaluator::applyToChildren3D(const Abstr if (children.size() == 0) return ResultObject(); if (op == OPENSCAD_HULL) { - CGAL_Polyhedron P; - if (CGALUtils::applyHull(children, P)) { - return ResultObject(new CGAL_Nef_polyhedron(new CGAL_Nef_polyhedron3(P))); - } - else { - return ResultObject(); + PolySet *ps = new PolySet(3); + + if (CGALUtils::applyHull(children, *ps)) { + return ps; } + + delete ps; + return ResultObject(); } // Only one child -> this is a noop @@ -150,10 +151,11 @@ Geometry *GeometryEvaluator::applyHull3D(const AbstractNode &node) { Geometry::ChildList children = collectChildren3D(node); - CGAL_Polyhedron P; - if (CGALUtils::applyHull(children, P)) { - return new CGAL_Nef_polyhedron(new CGAL_Nef_polyhedron3(P)); + PolySet *P = new PolySet(3); + if (CGALUtils::applyHull(children, *P)) { + return P; } + delete P; return NULL; } diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc index 5b768e1e..251e5b4f 100644 --- a/src/PlatformUtils.cc +++ b/src/PlatformUtils.cc @@ -2,6 +2,7 @@ #include "PlatformUtils.h" #include "boosty.h" +#include extern std::vector librarypath; diff --git a/src/Polygon2d.h b/src/Polygon2d.h index 294a0e86..cf28e74d 100644 --- a/src/Polygon2d.h +++ b/src/Polygon2d.h @@ -1,5 +1,4 @@ -#ifndef POLYGON2D_H_ -#define POLYGON2D_H_ +#pragma once #include "Geometry.h" #include "linalg.h" @@ -36,5 +35,3 @@ private: Outlines2d theoutlines; bool sanitized; }; - -#endif diff --git a/src/cgalutils.cc b/src/cgalutils.cc index d619ebcd..aa263275 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -9,6 +9,7 @@ #include "cgal.h" #include +#include #include "svg.h" #include "Reindexer.h" @@ -17,25 +18,26 @@ namespace CGALUtils { - bool applyHull(const Geometry::ChildList &children, CGAL_Polyhedron &result) + bool applyHull(const Geometry::ChildList &children, PolySet &result) { + typedef CGAL::Exact_predicates_inexact_constructions_kernel K; // Collect point cloud - std::vector points; - CGAL_Polyhedron P; + std::set points; BOOST_FOREACH(const Geometry::ChildItem &item, children) { const shared_ptr &chgeom = item.second; const CGAL_Nef_polyhedron *N = dynamic_cast(chgeom.get()); if (N) { for (CGAL_Nef_polyhedron3::Vertex_const_iterator i = N->p3->vertices_begin(); i != N->p3->vertices_end(); ++i) { - points.push_back(i->point()); + points.insert(K::Point_3(to_double(i->point()[0]),to_double(i->point()[1]),to_double(i->point()[2]))); } - } - else { + } else { const PolySet *ps = dynamic_cast(chgeom.get()); - BOOST_FOREACH(const PolySet::Polygon &p, ps->polygons) { - BOOST_FOREACH(const Vector3d &v, p) { - points.push_back(CGAL_Polyhedron::Vertex::Point_3(v[0], v[1], v[2])); + if (ps) { + BOOST_FOREACH(const PolySet::Polygon &p, ps->polygons) { + BOOST_FOREACH(const Vector3d &v, p) { + points.insert(K::Point_3(v[0], v[1], v[2])); + } } } } @@ -43,23 +45,13 @@ namespace CGALUtils { if (points.size() <= 3) return false; - // Remove all duplicated points (speeds up the convex_hull computation significantly) - std::vector unique_points; - Grid3d grid(GRID_FINE); - - BOOST_FOREACH(CGAL_Polyhedron::Vertex::Point_3 const& p, points) { - double x = to_double(p.x()), y = to_double(p.y()), z = to_double(p.z()); - int& v = grid.align(x,y,z); - if (v == 0) { - unique_points.push_back(CGAL_Polyhedron::Vertex::Point_3(x,y,z)); - v = 1; - } - } - // Apply hull if (points.size() >= 4) { - CGAL::convex_hull_3(unique_points.begin(), unique_points.end(), result); - return true; + CGAL::Polyhedron_3 r; + CGAL::convex_hull_3(points.begin(), points.end(), r); + if (!createPolySetFromPolyhedron(r, result)) + return true; + return false; } else { return false; } @@ -345,41 +337,34 @@ namespace CGALUtils { }; -bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, PolySet &ps) +template +bool createPolySetFromPolyhedron(const Polyhedron &p, PolySet &ps) { bool err = false; - typedef CGAL_Polyhedron::Vertex Vertex; - typedef CGAL_Polyhedron::Vertex_const_iterator VCI; - typedef CGAL_Polyhedron::Facet_const_iterator FCI; - typedef CGAL_Polyhedron::Halfedge_around_facet_const_circulator HFCC; + typedef typename Polyhedron::Vertex Vertex; + typedef typename Polyhedron::Vertex_const_iterator VCI; + typedef typename Polyhedron::Facet_const_iterator FCI; + typedef typename Polyhedron::Halfedge_around_facet_const_circulator HFCC; for (FCI fi = p.facets_begin(); fi != p.facets_end(); ++fi) { HFCC hc = fi->facet_begin(); HFCC hc_end = hc; - Vertex v1, v2, v3; - v1 = *VCI((hc++)->vertex()); - v3 = *VCI((hc++)->vertex()); + ps.append_poly(); do { - v2 = v3; - v3 = *VCI((hc++)->vertex()); - double x1 = CGAL::to_double(v1.point().x()); - double y1 = CGAL::to_double(v1.point().y()); - double z1 = CGAL::to_double(v1.point().z()); - double x2 = CGAL::to_double(v2.point().x()); - double y2 = CGAL::to_double(v2.point().y()); - double z2 = CGAL::to_double(v2.point().z()); - double x3 = CGAL::to_double(v3.point().x()); - double y3 = CGAL::to_double(v3.point().y()); - double z3 = CGAL::to_double(v3.point().z()); - ps.append_poly(); - ps.append_vertex(x1, y1, z1); - ps.append_vertex(x2, y2, z2); - ps.append_vertex(x3, y3, z3); + Vertex const& v = *((hc++)->vertex()); + double x = CGAL::to_double(v.point().x()); + double y = CGAL::to_double(v.point().y()); + double z = CGAL::to_double(v.point().z()); + ps.append_vertex(x, y, z); } while (hc != hc_end); } return err; } +template bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, PolySet &ps); +template bool createPolySetFromPolyhedron(const CGAL::Polyhedron_3 &p, PolySet &ps); + + /////// Tessellation begin typedef CGAL::Plane_3 CGAL_Plane_3; diff --git a/src/cgalutils.h b/src/cgalutils.h index 1e0825d3..29295cad 100644 --- a/src/cgalutils.h +++ b/src/cgalutils.h @@ -6,7 +6,7 @@ #include "enums.h" namespace CGALUtils { - bool applyHull(const Geometry::ChildList &children, CGAL_Polyhedron &P); + bool applyHull(const Geometry::ChildList &children, PolySet &P); void applyOperator(const Geometry::ChildList &children, CGAL_Nef_polyhedron &dest, OpenSCADOperator op); void applyBinaryOperator(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedron &src, OpenSCADOperator op); Polygon2d *project(const CGAL_Nef_polyhedron &N, bool cut); @@ -14,7 +14,7 @@ namespace CGALUtils { }; CGAL_Nef_polyhedron *createNefPolyhedronFromGeometry(const class Geometry &geom); -bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, PolySet &ps); +template bool createPolySetFromPolyhedron(const Polyhedron &p, PolySet &ps); bool createPolySetFromNefPolyhedron3(const CGAL_Nef_polyhedron3 &N, PolySet &ps); bool createPolyhedronFromPolySet(const PolySet &ps, CGAL_Polyhedron &p); diff --git a/src/clipper-utils.h b/src/clipper-utils.h index c36c6531..02bbfea1 100644 --- a/src/clipper-utils.h +++ b/src/clipper-utils.h @@ -1,5 +1,4 @@ -#ifndef CLIPPER_UTILS_H_ -#define CLIPPER_UTILS_H_ +#pragma once #include "polyclipping/clipper.hpp" #include "Polygon2d.h" @@ -20,5 +19,3 @@ namespace ClipperUtils { Polygon2d *apply(const std::vector &polygons, ClipperLib::ClipType); Polygon2d *apply(const std::vector &pathsvector, ClipperLib::ClipType); }; - -#endif diff --git a/src/func.cc b/src/func.cc index 10956a69..c6ba7152 100644 --- a/src/func.cc +++ b/src/func.cc @@ -213,7 +213,7 @@ Value builtin_min(const Context *, const EvalContext *evalctx) if (n == 1 && v0.type() == Value::VECTOR && !v0.toVector().empty()) { Value min = v0.toVector()[0]; - for (int i = 1; i < v0.toVector().size(); i++) { + for (size_t i = 1; i < v0.toVector().size(); i++) { if (v0.toVector()[i] < min) min = v0.toVector()[i]; } @@ -246,7 +246,7 @@ Value builtin_max(const Context *, const EvalContext *evalctx) if (n == 1 && v0.type() == Value::VECTOR && !v0.toVector().empty()) { Value max = v0.toVector()[0]; - for (int i = 1; i < v0.toVector().size(); i++) { + for (size_t i = 1; i < v0.toVector().size(); i++) { if (v0.toVector()[i] > max) max = v0.toVector()[i]; } @@ -620,6 +620,85 @@ Value builtin_lookup(const Context *, const EvalContext *evalctx) */ #pragma clang diagnostic ignored "-Wlogical-op-parentheses" + +static Value::VectorType search(const std::string &find, const std::string &table, + unsigned int num_returns_per_match, unsigned int index_col_num) +{ + Value::VectorType returnvec; + //Unicode glyph count for the length + size_t findThisSize = g_utf8_strlen(find.c_str(), find.size()); + size_t searchTableSize = g_utf8_strlen(table.c_str(), table.size()); + for (size_t i = 0; i < findThisSize; i++) { + unsigned int matchCount = 0; + Value::VectorType resultvec; + for (size_t j = 0; j < searchTableSize; j++) { + const gchar *ptr_ft = g_utf8_offset_to_pointer(find.c_str(), i); + const gchar *ptr_st = g_utf8_offset_to_pointer(table.c_str(), j); + if (ptr_ft && ptr_st && (g_utf8_get_char(ptr_ft) == g_utf8_get_char(ptr_st)) ) { + matchCount++; + if (num_returns_per_match == 1) { + returnvec.push_back(Value(double(j))); + break; + } else { + resultvec.push_back(Value(double(j))); + } + if (num_returns_per_match > 1 && matchCount >= num_returns_per_match) { + break; + } + } + } + if (matchCount == 0) { + gchar *ptr_ft = g_utf8_offset_to_pointer(find.c_str(), i); + gchar utf8_of_cp[6] = ""; //A buffer for a single unicode character to be copied into + if (ptr_ft) g_utf8_strncpy(utf8_of_cp, ptr_ft, 1); + PRINTB(" WARNING: search term not found: \"%s\"", utf8_of_cp); + } + if (num_returns_per_match == 0 || num_returns_per_match > 1) { + returnvec.push_back(Value(resultvec)); + } + } + return returnvec; +} + +static Value::VectorType search(const std::string &find, const Value::VectorType &table, + unsigned int num_returns_per_match, unsigned int index_col_num) +{ + Value::VectorType returnvec; + //Unicode glyph count for the length + unsigned int findThisSize = g_utf8_strlen(find.c_str(), find.size()); + unsigned int searchTableSize = table.size(); + for (size_t i = 0; i < findThisSize; i++) { + unsigned int matchCount = 0; + Value::VectorType resultvec; + for (size_t j = 0; j < searchTableSize; j++) { + const gchar *ptr_ft = g_utf8_offset_to_pointer(find.c_str(), i); + const gchar *ptr_st = g_utf8_offset_to_pointer(table[j].toVector()[index_col_num].toString().c_str(), 0); + if (ptr_ft && ptr_st && (g_utf8_get_char(ptr_ft) == g_utf8_get_char(ptr_st)) ) { + matchCount++; + if (num_returns_per_match == 1) { + returnvec.push_back(Value(double(j))); + break; + } else { + resultvec.push_back(Value(double(j))); + } + if (num_returns_per_match > 1 && matchCount >= num_returns_per_match) { + break; + } + } + } + if (matchCount == 0) { + const gchar *ptr_ft = g_utf8_offset_to_pointer(find.c_str(), i); + gchar utf8_of_cp[6] = ""; //A buffer for a single unicode character to be copied into + if (ptr_ft) g_utf8_strncpy(utf8_of_cp, ptr_ft, 1); + PRINTB(" WARNING: search term not found: \"%s\"", utf8_of_cp); + } + if (num_returns_per_match == 0 || num_returns_per_match > 1) { + returnvec.push_back(Value(resultvec)); + } + } + return returnvec; +} + Value builtin_search(const Context *, const EvalContext *evalctx) { if (evalctx->numArgs() < 2) return Value(); @@ -637,59 +716,20 @@ Value builtin_search(const Context *, const EvalContext *evalctx) for (size_t j = 0; j < searchTable.toVector().size(); j++) { const Value& search_element = searchTable.toVector()[j]; - if (index_col_num == 0 && findThis == search_element - || - index_col_num < search_element.toVector().size() && - findThis == search_element.toVector()[index_col_num]) - { + if (index_col_num == 0 && findThis == search_element || + index_col_num < search_element.toVector().size() && + findThis == search_element.toVector()[index_col_num]) { returnvec.push_back(Value(double(j))); matchCount++; if (num_returns_per_match != 0 && matchCount >= num_returns_per_match) break; } } } else if (findThis.type() == Value::STRING) { - unsigned int searchTableSize; - //Unicode glyph count for the length - unsigned int findThisSize = g_utf8_strlen( findThis.toString().c_str(), findThis.toString().size() ); if (searchTable.type() == Value::STRING) { - searchTableSize = g_utf8_strlen( searchTable.toString().c_str(), searchTable.toString().size() ); - } else { - searchTableSize = searchTable.toVector().size(); + returnvec = search(findThis.toString(), searchTable.toString(), num_returns_per_match, index_col_num); } - for (size_t i = 0; i < findThisSize; i++) { - unsigned int matchCount = 0; - Value::VectorType resultvec; - for (size_t j = 0; j < searchTableSize; j++) { - gchar* ptr_ft = g_utf8_offset_to_pointer(findThis.toString().c_str(), i); - gchar* ptr_st = NULL; - if(searchTable.type() == Value::VECTOR) { - ptr_st = g_utf8_offset_to_pointer(searchTable.toVector()[j].toVector()[index_col_num].toString().c_str(), 0); - } else if(searchTable.type() == Value::STRING){ - ptr_st = g_utf8_offset_to_pointer(searchTable.toString().c_str(), j); - } - if( (ptr_ft) && (ptr_st) && (g_utf8_get_char(ptr_ft) == g_utf8_get_char(ptr_st)) ) { - Value resultValue((double(j))); - matchCount++; - if (num_returns_per_match == 1) { - returnvec.push_back(resultValue); - break; - } else { - resultvec.push_back(resultValue); - } - if (num_returns_per_match > 1 && matchCount >= num_returns_per_match) break; - } - } - if (matchCount == 0) { - gchar* ptr_ft = g_utf8_offset_to_pointer(findThis.toString().c_str(), i); - gchar utf8_of_cp[6] = ""; //A buffer for a single unicode character to be copied into - if(ptr_ft) { - g_utf8_strncpy( utf8_of_cp, ptr_ft, 1 ); - } - PRINTB(" WARNING: search term not found: \"%s\"", utf8_of_cp ); - } - if (num_returns_per_match == 0 || num_returns_per_match > 1) { - returnvec.push_back(Value(resultvec)); - } + else { + returnvec = search(findThis.toString(), searchTable.toVector(), num_returns_per_match, index_col_num); } } else if (findThis.type() == Value::VECTOR) { for (size_t i = 0; i < findThis.toVector().size(); i++) { diff --git a/src/mainwin.cc b/src/mainwin.cc index 5c66ad67..d2b2a722 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -164,7 +164,7 @@ bool MainWindow::mdiMode = false; bool MainWindow::undockMode = false; MainWindow::MainWindow(const QString &filename) - : root_inst("group"), tempFile(NULL), progresswidget(NULL), font_list_dialog(NULL) + : root_inst("group"), font_list_dialog(NULL), tempFile(NULL), progresswidget(NULL) { setupUi(this); setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); diff --git a/src/offset.cc b/src/offset.cc index c604ad64..1b2c7160 100644 --- a/src/offset.cc +++ b/src/offset.cc @@ -99,16 +99,18 @@ std::string OffsetNode::toString() const { std::stringstream stream; - stream << this->name() + stream << this->name() << "(delta = " << std::dec << this->delta - << ", join_type = " + << ", join_type = \"" << (this->join_type == ClipperLib::jtSquare ? "bevel" : this->join_type == ClipperLib::jtRound ? "round" - : "miter") - << ", miter_limit = " << this->miter_limit - << ", $fn = " << this->fn + : "miter") << "\""; + if (this->join_type == ClipperLib::jtMiter) { + stream << ", miter_limit = " << this->miter_limit; + } + stream << ", $fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")"; diff --git a/src/offsetnode.h b/src/offsetnode.h index 66bc52de..be651903 100644 --- a/src/offsetnode.h +++ b/src/offsetnode.h @@ -1,5 +1,4 @@ -#ifndef OFFSETNODE_H_ -#define OFFSETNODE_H_ +#pragma once #include "node.h" #include "visitor.h" @@ -19,5 +18,3 @@ public: double fn, fs, fa, delta, miter_limit; ClipperLib::JoinType join_type; }; - -#endif diff --git a/src/polyset-utils.h b/src/polyset-utils.h index 5d284f65..2bdaca03 100644 --- a/src/polyset-utils.h +++ b/src/polyset-utils.h @@ -1,5 +1,4 @@ -#ifndef POLYSET_UTILS_H_ -#define POLYSET_UTILS_H_ +#pragma once class Polygon2d; class PolySet; @@ -10,5 +9,3 @@ namespace PolysetUtils { void tessellate_faces(const PolySet &inps, PolySet &outps); }; - -#endif diff --git a/src/textnode.h b/src/textnode.h index c4c77a16..5b8463e9 100644 --- a/src/textnode.h +++ b/src/textnode.h @@ -1,5 +1,4 @@ -#ifndef TEXTNODE_H_ -#define TEXTNODE_H_ +#pragma once #include "node.h" #include "visitor.h" @@ -26,7 +25,5 @@ public: virtual FreetypeRenderer::Params get_params() const; private: FreetypeRenderer::Params params; - friend TextModule; + friend class TextModule; }; - -#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 15c29c5d..762ffa1c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -455,15 +455,29 @@ inclusion(GLIB2_DIR GLIB2_INCLUDE_DIRS) # find libraries using pkg-config find_package(PkgConfig REQUIRED) +include(PkgConfigTools.cmake) +save_pkg_config_env() -pkg_search_module(FONTCONFIG REQUIRED fontconfig>=2.11.0) -message(STATUS "fontconfig found: ${FONTCONFIG_VERSION}") +if (DEFINED ENV{OPENSCAD_LIBRARIES}) + set(ENV{PKG_CONFIG_PATH} "$ENV{OPENSCAD_LIBRARIES}/lib/pkgconfig") +endif() -pkg_search_module(FREETYPE REQUIRED freetype2>=2.4.9) -message(STATUS "freetype2 found: ${FREETYPE_VERSION}") +pkg_check_modules(FONTCONFIG REQUIRED fontconfig>=2.8.0) +if (FONTCONFIG_VERSION) + message(STATUS "fontconfig ${FONTCONFIG_VERSION} found: ${FONTCONFIG_INCLUDE_DIRS}") +endif() -pkg_search_module(HARFBUZZ REQUIRED harfbuzz>=0.9.19) -message(STATUS "harfbuzz found: ${HARFBUZZ_VERSION}") +pkg_check_modules(FREETYPE REQUIRED freetype2>=2.4.9) +if (FREETYPE_VERSION) + message(STATUS "freetype2 ${FREETYPE_VERSION} found: ${FREETYPE_INCLUDE_DIRS}") +endif() + +pkg_check_modules(HARFBUZZ REQUIRED harfbuzz>=0.9.19) +if (HARFBUZZ_VERSION) + message(STATUS "harfbuzz ${HARFBUZZ_VERSION} found: ${HARFBUZZ_INCLUDE_DIRS}") +endif() + +restore_pkg_config_env() add_definitions(${FONTCONFIG_CFLAGS}) add_definitions(${FREETYPE_CFLAGS}) @@ -663,16 +677,14 @@ if(NULLGL) endif() add_library(tests-core STATIC ${CORE_SOURCES}) -target_link_libraries(tests-core ${OPENGL_LIBRARIES} ${GLIB2_LIBRARIES} ) -set(TESTS-CORE-LIBRARIES ${OPENGL_LIBRARIES} ${GLIB2_LIBRARIES} ${Boost_LIBRARIES} ${COCOA_LIBRARY}) +target_link_libraries(tests-core ${OPENGL_LIBRARIES} ${GLIB2_LIBRARIES} ${FONTCONFIG_LDFLAGS} ${FREETYPE_LDFLAGS} ${HARFBUZZ_LDFLAGS} ${Boost_LIBRARIES} ${COCOA_LIBRARY}) add_library(tests-common STATIC ${COMMON_SOURCES}) target_link_libraries(tests-common tests-core) add_library(tests-cgal STATIC ${CGAL_SOURCES}) set_target_properties(tests-cgal PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}") -target_link_libraries(tests-cgal tests-common) -set(TESTS-CGAL-LIBRARIES ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${GMP_LIBRARIES} ${MPFR_LIBRARIES} ${TESTS-CORE-LIBRARIES}) +target_link_libraries(tests-cgal tests-common ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${GMP_LIBRARIES} ${MPFR_LIBRARIES}) # # Create non-CGAL tests @@ -680,14 +692,12 @@ set(TESTS-CGAL-LIBRARIES ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${GMP_LIBRA if (NOT NULLGL) add_library(tests-nocgal STATIC ${NOCGAL_SOURCES}) target_link_libraries(tests-nocgal tests-common) - set(TESTS-NOCGAL-LIBRARIES ${TESTS-CORE-LIBRARIES}) else() message(STATUS "NULLGL: cannot use GL/GLU tessellator. see dxftess.cc") message(STATUS "NULLGL: non-CGAL tests will use CGAL's tessellator") add_library(tests-nocgal STATIC ${CGAL_SOURCES}) set_target_properties(tests-nocgal PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}") target_link_libraries(tests-nocgal tests-common) - set(TESTS-NOCGAL-LIBRARIES ${TESTS-CGAL-LIBRARIES}) endif() add_library(tests-offscreen STATIC ${OFFSCREEN_SOURCES}) @@ -697,27 +707,27 @@ set_target_properties(tests-offscreen PROPERTIES COMPILE_FLAGS "${ENABLE_OPENCSG # modulecachetest # add_executable(modulecachetest modulecachetest.cc) -target_link_libraries(modulecachetest tests-nocgal ${TESTS-NOCGAL-LIBRARIES} ${Boost_LIBRARIES} ${FONTCONFIG_LDFLAGS} ${FREETYPE_LDFLAGS} ${HARFBUZZ_LDFLAGS}) +target_link_libraries(modulecachetest tests-nocgal) # # csgtexttest # add_executable(csgtexttest csgtexttest.cc CSGTextRenderer.cc CSGTextCache.cc) -target_link_libraries(csgtexttest tests-nocgal ${TESTS-NOCGAL-LIBRARIES} ${FONTCONFIG_LDFLAGS} ${FREETYPE_LDFLAGS} ${HARFBUZZ_LDFLAGS}) +target_link_libraries(csgtexttest tests-nocgal) # # cgalcachetest # add_executable(cgalcachetest cgalcachetest.cc) set_target_properties(cgalcachetest PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}") -target_link_libraries(cgalcachetest tests-cgal ${TESTS-CGAL-LIBRARIES} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${FONTCONFIG_LDFLAGS} ${FREETYPE_LDFLAGS} ${HARFBUZZ_LDFLAGS}) +target_link_libraries(cgalcachetest tests-cgal ${GLEW_LIBRARY}) # # openscad no-qt # add_executable(openscad_nogui ../src/openscad.cc) set_target_properties(openscad_nogui PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -DEIGEN_DONT_ALIGN -DENABLE_CGAL -DENABLE_OPENCSG ${CGAL_CXX_FLAGS_INIT}") -target_link_libraries(openscad_nogui tests-offscreen tests-cgal tests-nocgal ${TESTS-CORE-LIBRARIES} ${TESTS-CGAL-LIBRARIES} ${GLEW_LIBRARY} ${Boost_LIBRARIES} ${OPENCSG_LIBRARY} ${COCOA_LIBRARY} ${APP_SERVICES_LIBRARY} ${FONTCONFIG_LDFLAGS} ${FREETYPE_LDFLAGS} ${HARFBUZZ_LDFLAGS}) +target_link_libraries(openscad_nogui tests-offscreen tests-cgal tests-nocgal ${GLEW_LIBRARY} ${OPENCSG_LIBRARY} ${APP_SERVICES_LIBRARY}) # # GUI binary tests @@ -813,11 +823,12 @@ endfunction() # This functions adds cmd-line tests given files. # # Usage add_cmdline_test(testbasename [EXE ] [ARGS ] +# [SCRIPT