From a76d5b02bdb8cd7a9d32c2e204c86726d1384c63 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Fri, 10 Feb 2012 20:15:16 -0600 Subject: use Nef_polyhedron3 intersection to do projection(cut). diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 04783e5..54c02e7 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -5,6 +5,7 @@ #include "polyset.h" #include "dxfdata.h" #include "dxftess.h" +#include CGAL_Nef_polyhedron::CGAL_Nef_polyhedron(CGAL_Nef_polyhedron2 *p) { diff --git a/src/CGAL_Nef_polyhedron.h b/src/CGAL_Nef_polyhedron.h index f93905f..0b0784e 100644 --- a/src/CGAL_Nef_polyhedron.h +++ b/src/CGAL_Nef_polyhedron.h @@ -3,6 +3,7 @@ #include "cgalfwd.h" #include "memory.h" +#include class CGAL_Nef_polyhedron { @@ -18,6 +19,7 @@ public: CGAL_Nef_polyhedron &operator-=(const CGAL_Nef_polyhedron &other); CGAL_Nef_polyhedron &minkowski(const CGAL_Nef_polyhedron &other); CGAL_Nef_polyhedron copy() const; + std::string dump_p2() const; int weight() const; class PolySet *convertToPolyset(); class DxfData *convertToDxfData() const; diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index fe58636..d5f774d 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -77,4 +77,29 @@ DxfData *CGAL_Nef_polyhedron::convertToDxfData() const return dxfdata; } +// moved here to reduce compile size/time of CGAL_Nef_polyhedron.cc +std::string CGAL_Nef_polyhedron::dump_p2() const +{ + std::stringstream out; + CGAL_Nef_polyhedron2::Explorer explorer = this->p2->explorer(); + CGAL_Nef_polyhedron2::Explorer::Vertex_const_iterator i; + out << "CGAL_Nef_polyhedron::p2 vertices"; + for (i = explorer.vertices_begin(); i != explorer.vertices_end(); ++i) { + if ( explorer.is_standard( i ) ) { + CGAL_Nef_polyhedron2::Explorer::Point point = explorer.point( i ); + out << "\n Standard vertex x y: " + << CGAL::to_double(point.x()) << " " + << CGAL::to_double(point.y()); + } else { + CGAL_Nef_polyhedron2::Explorer::Ray ray = explorer.ray( i ); + CGAL_Nef_polyhedron2::Explorer::Point point = ray.point( 0 ); + out << "\n Ray x y dx dy: " + << CGAL::to_double(point.x()) << " " << CGAL::to_double(point.y()) + << CGAL::to_double(ray.direction().dx()) << " " << CGAL::to_double(ray.direction().dy()) << "\n"; + } + } + out << "\nCGAL_Nef_polyhedron::p2 vertices end"; + return out.str(); +} + #endif // ENABLE_CGAL diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index c1bdea4..d6d0f87 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -16,11 +16,87 @@ #include "openscad.h" // get_fragments_from_r() #include +// This object 'visits' the Nef Polyhedron 3d, extracting 2d information +// from it for the projection( cut = true ) command. +// http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html +class NefShellVisitor_for_cut { +public: + std::stringstream out; + CGAL_Nef_polyhedron2 tmpnef; + CGAL_Nef_polyhedron2 nefpoly2d; + CGAL_Nef_polyhedron2::Boundary boundary; + NefShellVisitor_for_cut() + { boundary = CGAL_Nef_polyhedron2::INCLUDED; } + std::string dump() + { return out.str(); } + void visit( CGAL_Nef_polyhedron3::Vertex_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::Halfedge_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::SHalfedge_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { + // this method is fed each 'facet' of the Nef_polyhedron3 that's been intersected + // with the flat x-y plane. + // + // So, we assume that all z coordinates are 0. + // + // Now. CGAL_Nef_poly3d objects have two 'half facets' for every flat shape. + // i.e. on a cube, there are 12 'half facets', 6 pointing 'in' and 6 'out'. + // On a flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'. + // We only use the 'down' facets here. Why? Because otherwise you get a double-set of vertices! + // + // Also note, 'up' facets list vertexs in CounterClockwise Order, and 'down' facets list vertexs + // in Clockwise order. (or is it the other way round?). + + CGAL::Direction_3 up(0,0,1); + CGAL::Plane_3 plane = hfacet->plane(); + out << " direction == up? " << ( plane.orthogonal_direction() == up ) << "\n"; + if ( plane.orthogonal_direction() != up ) { + out << "direction == down. skipping\n"; + return; + } + + int numcontours = 0; + CGAL_Nef_polyhedron2::Point point; + CGAL_Nef_polyhedron3::Vertex_const_handle vertex; + CGAL_Nef_polyhedron3::Halfedge_const_handle halfedge; + CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator i; + CGAL_Nef_polyhedron3::SHalfedge_const_handle first_halfedge, j; + for ( i = hfacet->facet_cycles_begin(); i != hfacet->facet_cycles_end(); ++i ) { + j = CGAL_Nef_polyhedron3::SHalfedge_const_handle( i ); + first_halfedge = j; + std::list contour; + do { + // j->source() is a CGAL_Nef_polyhedron3::Nef_polyhedron_S2::SVertex, + // but SVertex is the same thing as CGAL_Nef_polyhedron3::Halfedge + // and Halfedge can give us an actual point. + halfedge = CGAL_Nef_polyhedron3::Halfedge_const_handle( j->source() ); + vertex = CGAL_Nef_polyhedron3::Vertex_const_handle( halfedge->source() ); + point = CGAL_Nef_polyhedron2::Point( vertex->point().x(), vertex->point().y() ); + contour.push_back( point ); + //out << " add xyz " << x << " "<< y << " " <next(); + } while ( j != first_halfedge ); + tmpnef = CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ); + if ( numcontours == 0 ) { + out << " contour is a body. joining." << contour.size() << " points.\n" ; + nefpoly2d = nefpoly2d.join( tmpnef ); + } else { + out << " contour is a hole. intersecting." << contour.size() << "points.\n"; + nefpoly2d = nefpoly2d.intersection( tmpnef ); + } + numcontours++; + } // next facet cycle + } // visit() +}; + PolySetCGALEvaluator::PolySetCGALEvaluator(CGALEvaluator &cgalevaluator) : PolySetEvaluator(cgalevaluator.getTree()), cgalevaluator(cgalevaluator) { } +#include + PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) { // Before projecting, union all children @@ -43,64 +119,33 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) // XY plane. if (node.cut_mode) { - PolySet cube; - double infval = 1e8, eps = 0.1; - double x1 = -infval, x2 = +infval, y1 = -infval, y2 = +infval, z1 = 0, z2 = eps; - - cube.append_poly(); // top - cube.append_vertex(x1, y1, z2); - cube.append_vertex(x2, y1, z2); - cube.append_vertex(x2, y2, z2); - cube.append_vertex(x1, y2, z2); - - cube.append_poly(); // bottom - cube.append_vertex(x1, y2, z1); - cube.append_vertex(x2, y2, z1); - cube.append_vertex(x2, y1, z1); - cube.append_vertex(x1, y1, z1); - - cube.append_poly(); // side1 - cube.append_vertex(x1, y1, z1); - cube.append_vertex(x2, y1, z1); - cube.append_vertex(x2, y1, z2); - cube.append_vertex(x1, y1, z2); - - cube.append_poly(); // side2 - cube.append_vertex(x2, y1, z1); - cube.append_vertex(x2, y2, z1); - cube.append_vertex(x2, y2, z2); - cube.append_vertex(x2, y1, z2); - - cube.append_poly(); // side3 - cube.append_vertex(x2, y2, z1); - cube.append_vertex(x1, y2, z1); - cube.append_vertex(x1, y2, z2); - cube.append_vertex(x2, y2, z2); - - cube.append_poly(); // side4 - cube.append_vertex(x1, y2, z1); - cube.append_vertex(x1, y1, z1); - cube.append_vertex(x1, y1, z2); - cube.append_vertex(x1, y2, z2); - CGAL_Nef_polyhedron Ncube = this->cgalevaluator.evaluateCGALMesh(cube); - - sum *= Ncube; - - // FIXME: Instead of intersecting with a thin volume, we could intersect - // with a plane. This feels like a better solution. However, as the result - // of such an intersection isn't simple, we cannot convert the resulting - // Nef polyhedron to a Polyhedron using convertToPolyset() and we need - // another way of extracting the result. kintel 20120203. -// *sum.p3 = sum.p3->intersection(CGAL_Nef_polyhedron3::Plane_3(0, 0, 1, 0), -// CGAL_Nef_polyhedron3::PLANE_ONLY); - - - if (!sum.p3->is_simple()) { +//---------------------------- + CGAL_Nef_polyhedron3::Plane_3 plane = CGAL_Nef_polyhedron3::Plane_3( 0,0,1,0 ); + *sum.p3 = sum.p3->intersection( plane, CGAL_Nef_polyhedron3::PLANE_ONLY); + + NefShellVisitor_for_cut shell_visitor; + CGAL_Nef_polyhedron3::Volume_const_iterator i; + CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; + CGAL_Nef_polyhedron3::SFace_const_handle sface_handle; + for ( i = sum.p3->volumes_begin(); i != sum.p3->volumes_end(); ++i ) { + for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { + sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); + sum.p3->visit_shell_objects( sface_handle , shell_visitor ); + } + } + + std::cout << "shell visitor\n" << shell_visitor.dump() << "\n"; +//---------------------------- + +/* if (!sum.p3->is_simple()) { PRINT("WARNING: Body of projection(cut = true) isn't valid 2-manifold! Modify your design.."); goto cant_project_non_simple_polyhedron; - } + }*/ - PolySet *ps3 = sum.convertToPolyset(); + CGAL_Nef_polyhedron flat_nef_poly; + *(flat_nef_poly.p2) = shell_visitor.nefpoly2d; + flat_nef_poly.dim = 2; + PolySet *ps3 = flat_nef_poly.convertToPolyset(); if (!ps3) return NULL; // Extract polygons in the XY plane, ignoring all other polygons diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index d1e79ad..15859bd 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -131,6 +131,7 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr // ..maybe it would be better to assert here. But this would // break compatibility with the glu tesselator that handled such // cases just fine. + PRINT( "WARNING: Duplicate vertex during Tessellation. Render may be incorrect." ); continue; } -- cgit v0.10.1 From 319364b59790140b607a0f2af6d6b7e1ab068f51 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 13 Feb 2012 18:43:38 -0600 Subject: use shared_ptr in shell visitor. add dump() code. hide debug cout. diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index d5f774d..412314a 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -77,28 +77,28 @@ DxfData *CGAL_Nef_polyhedron::convertToDxfData() const return dxfdata; } -// moved here to reduce compile size/time of CGAL_Nef_polyhedron.cc +// moved here to reduce compile size/time of compiling CGAL_Nef_polyhedron.cc std::string CGAL_Nef_polyhedron::dump_p2() const { std::stringstream out; CGAL_Nef_polyhedron2::Explorer explorer = this->p2->explorer(); CGAL_Nef_polyhedron2::Explorer::Vertex_const_iterator i; - out << "CGAL_Nef_polyhedron::p2 vertices"; + out << "CGAL_Nef_polyhedron::p2 Vertices"; for (i = explorer.vertices_begin(); i != explorer.vertices_end(); ++i) { if ( explorer.is_standard( i ) ) { CGAL_Nef_polyhedron2::Explorer::Point point = explorer.point( i ); - out << "\n Standard vertex x y: " + out << "\n Point x y: " << CGAL::to_double(point.x()) << " " << CGAL::to_double(point.y()); } else { CGAL_Nef_polyhedron2::Explorer::Ray ray = explorer.ray( i ); CGAL_Nef_polyhedron2::Explorer::Point point = ray.point( 0 ); out << "\n Ray x y dx dy: " - << CGAL::to_double(point.x()) << " " << CGAL::to_double(point.y()) - << CGAL::to_double(ray.direction().dx()) << " " << CGAL::to_double(ray.direction().dy()) << "\n"; + << CGAL::to_double(point.x()) << " " << CGAL::to_double(point.y()) << " " + << CGAL::to_double(ray.direction().dx()) << " " << CGAL::to_double(ray.direction().dy()); } } - out << "\nCGAL_Nef_polyhedron::p2 vertices end"; + out << "\nCGAL_Nef_polyhedron::p2 Vertices end"; return out.str(); } diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index d6d0f87..f256ef8 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -22,37 +22,42 @@ class NefShellVisitor_for_cut { public: std::stringstream out; - CGAL_Nef_polyhedron2 tmpnef; - CGAL_Nef_polyhedron2 nefpoly2d; + shared_ptr tmpnef; + shared_ptr nefpoly2d; CGAL_Nef_polyhedron2::Boundary boundary; NefShellVisitor_for_cut() - { boundary = CGAL_Nef_polyhedron2::INCLUDED; } + { + nefpoly2d.reset( new CGAL_Nef_polyhedron2() ); + boundary = CGAL_Nef_polyhedron2::INCLUDED; + } std::string dump() - { return out.str(); } + { + return out.str(); + } void visit( CGAL_Nef_polyhedron3::Vertex_const_handle ) {} void visit( CGAL_Nef_polyhedron3::Halfedge_const_handle ) {} void visit( CGAL_Nef_polyhedron3::SHalfedge_const_handle ) {} void visit( CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {} void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {} void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { - // this method is fed each 'facet' of the Nef_polyhedron3 that's been intersected - // with the flat x-y plane. + // This method is fed each 'facet' of the Nef_polyhedron3 that's been intersected + // with the flat x-y plane. I.e. it's fed a bunch of flat polygons. // // So, we assume that all z coordinates are 0. // - // Now. CGAL_Nef_poly3d objects have two 'half facets' for every flat shape. - // i.e. on a cube, there are 12 'half facets', 6 pointing 'in' and 6 'out'. + // Now. CGAL_Nef_poly3d objects have two 'half facets'. // On a flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'. - // We only use the 'down' facets here. Why? Because otherwise you get a double-set of vertices! + // Now, we only want the vertexes--- so we only don't need both 'up' and 'down' facets. + // What do we do? Just skip the 'down' facets! // - // Also note, 'up' facets list vertexs in CounterClockwise Order, and 'down' facets list vertexs + // By the way, 'up' facets list vertexs in CounterClockwise Order, and 'down' facets list vertexs // in Clockwise order. (or is it the other way round?). CGAL::Direction_3 up(0,0,1); CGAL::Plane_3 plane = hfacet->plane(); out << " direction == up? " << ( plane.orthogonal_direction() == up ) << "\n"; if ( plane.orthogonal_direction() != up ) { - out << "direction == down. skipping\n"; + // out << "direction == down. skipping"; return; } @@ -77,13 +82,13 @@ public: //out << " add xyz " << x << " "<< y << " " <next(); } while ( j != first_halfedge ); - tmpnef = CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ); + tmpnef.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); if ( numcontours == 0 ) { - out << " contour is a body. joining." << contour.size() << " points.\n" ; - nefpoly2d = nefpoly2d.join( tmpnef ); + //out << " contour is a body. joining. " << contour.size() << " points.\n" ; + *nefpoly2d += *tmpnef; } else { - out << " contour is a hole. intersecting." << contour.size() << "points.\n"; - nefpoly2d = nefpoly2d.intersection( tmpnef ); + //out << " contour is a hole. intersecting. " << contour.size() << "points.\n"; + *nefpoly2d *= *tmpnef; } numcontours++; } // next facet cycle @@ -95,8 +100,6 @@ PolySetCGALEvaluator::PolySetCGALEvaluator(CGALEvaluator &cgalevaluator) { } -#include - PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) { // Before projecting, union all children @@ -112,14 +115,14 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) if (sum.empty()) return NULL; PolySet *ps = new PolySet(); + PolySet *ps3 = NULL; + DxfData *dxf = NULL; + CGAL_Nef_polyhedron np; ps->convexity = node.convexity; ps->is2d = true; - // In cut mode, the model is intersected by a large but very thin box living on the - // XY plane. if (node.cut_mode) { -//---------------------------- CGAL_Nef_polyhedron3::Plane_3 plane = CGAL_Nef_polyhedron3::Plane_3( 0,0,1,0 ); *sum.p3 = sum.p3->intersection( plane, CGAL_Nef_polyhedron3::PLANE_ONLY); @@ -133,26 +136,26 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) sum.p3->visit_shell_objects( sface_handle , shell_visitor ); } } + // std::cout << "shell visitor\n" << shell_visitor.dump() << "\n"; - std::cout << "shell visitor\n" << shell_visitor.dump() << "\n"; -//---------------------------- - -/* if (!sum.p3->is_simple()) { + /*if (!sum.p3->is_simple()) { PRINT("WARNING: Body of projection(cut = true) isn't valid 2-manifold! Modify your design.."); goto cant_project_non_simple_polyhedron; }*/ - CGAL_Nef_polyhedron flat_nef_poly; - *(flat_nef_poly.p2) = shell_visitor.nefpoly2d; - flat_nef_poly.dim = 2; - PolySet *ps3 = flat_nef_poly.convertToPolyset(); + np.p2 = shell_visitor.nefpoly2d; + // std::cout << np.dump_p2() << "\n"; + np.dim = 2; + + ps3 = np.convertToPolyset(); + // std::cout << "----------\n" << ps3->dump() << "\n"; if (!ps3) return NULL; // Extract polygons in the XY plane, ignoring all other polygons - // FIXME: If the polyhedron is really thin, there might be unwanted polygons - // in the XY plane, causing the resulting 2D polygon to be self-intersection - // and cause a crash in CGALEvaluator::PolyReducer. The right solution is to - // filter these polygons here. kintel 20120203. + // FIXME: If the polyhedron is really thin, there might be unwanted polygons + // in the XY plane, causing the resulting 2D polygon to be self-intersection + // and cause a crash in CGALEvaluator::PolyReducer. The right solution is to + // filter these polygons here. kintel 20120203. Grid2d conversion_grid(GRID_COARSE); for (size_t i = 0; i < ps3->polygons.size(); i++) { for (size_t j = 0; j < ps3->polygons[i].size(); j++) { @@ -175,6 +178,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) next_ps3_polygon_cut_mode:; } delete ps3; + } // In projection mode all the triangles are projected manually into the XY plane else @@ -184,9 +188,8 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) goto cant_project_non_simple_polyhedron; } - PolySet *ps3 = sum.convertToPolyset(); + ps3 = sum.convertToPolyset(); if (!ps3) return NULL; - CGAL_Nef_polyhedron np; for (size_t i = 0; i < ps3->polygons.size(); i++) { int min_x_p = -1; @@ -233,12 +236,12 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) (*np.p2) += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED); } } - delete ps3; - DxfData *dxf = np.convertToDxfData(); - dxf_tesselate(ps, *dxf, 0, true, false, 0); - dxf_border_to_ps(ps, *dxf); - delete dxf; } + delete ps3; + dxf = np.convertToDxfData(); + dxf_tesselate(ps, *dxf, 0, true, false, 0); + dxf_border_to_ps(ps, *dxf); + delete dxf; cant_project_non_simple_polyhedron: return ps; diff --git a/src/dxfdata.cc b/src/dxfdata.cc index 52493ac..20fcc71 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include "value.h" @@ -555,3 +556,27 @@ int DxfData::addPoint(double x, double y) return this->points.size()-1; } +std::string DxfData::dump() const +{ + std::stringstream out; + out << "DxfData" + << "\n num points: " << points.size() + << "\n num paths: " << paths.size() + << "\n num dims: " << dims.size() + << "\n points: "; + for ( size_t k = 0 ; k < points.size() ; k++ ) { + out << "\n x y: " << points[k].transpose(); + } + out << "\n paths: "; + for ( size_t i = 0; i < paths.size(); i++ ) { + out << "\n path:" << i + << "\n is_closed: " << paths[i].is_closed + << "\n is_inner: " << paths[i].is_inner ; + DxfData::Path path = paths[i]; + for ( size_t j = 0; j < path.indices.size(); j++ ) { + out << "\n index[" << j << "]==" << path.indices[j]; + } + } + out << "\nDxfData end"; + return out.str(); +} diff --git a/src/dxfdata.h b/src/dxfdata.h index 7eea6a9..64853dc 100644 --- a/src/dxfdata.h +++ b/src/dxfdata.h @@ -44,6 +44,7 @@ public: int addPoint(double x, double y); void fixup_path_direction(); + std::string dump() const; }; #endif diff --git a/src/polyset.cc b/src/polyset.cc index e5553aa..b6df0c2 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -48,6 +48,36 @@ PolySet::~PolySet() { } +std::string PolySet::dump() const +{ + std::stringstream out; + out << "PolySet:" + << "\n dimensions:" << std::string( this->is2d ? "2" : "3" ) + << "\n convexity:" << this->convexity + << "\n num polygons: " << polygons.size() + << "\n num borders: " << borders.size() + << "\n polygons data:"; + for (size_t i = 0; i < polygons.size(); i++) { + out << "\n polygon begin:"; + const Polygon *poly = &polygons[i]; + for (size_t j = 0; j < poly->size(); j++) { + Vector3d v = poly->at(j); + out << "\n vertex:" << v.transpose(); + } + } + out << "\n borders data:"; + for (size_t i = 0; i < borders.size(); i++) { + out << "\n border polygon begin:"; + const Polygon *poly = &borders[i]; + for (size_t j = 0; j < poly->size(); j++) { + Vector3d v = poly->at(j); + out << "\n vertex:" << v.transpose(); + } + } + out << "\nPolySet end"; + return out.str(); +} + void PolySet::append_poly() { polygons.push_back(Polygon()); diff --git a/src/polyset.h b/src/polyset.h index 09a13cb..4ca57bf 100644 --- a/src/polyset.h +++ b/src/polyset.h @@ -5,6 +5,7 @@ #include "grid.h" #include "linalg.h" #include +#include class PolySet { @@ -40,6 +41,7 @@ public: void render_surface(csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo = NULL) const; void render_edges(csgmode_e csgmode) const; + std::string dump() const; }; #endif -- cgit v0.10.1 From fe06b3b03405df81c267cd2bd22e4df8c40f1689 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 13 Feb 2012 19:22:11 -0600 Subject: fix crash. diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index f256ef8..2e56f36 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -41,16 +41,14 @@ public: void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {} void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { // This method is fed each 'facet' of the Nef_polyhedron3 that's been intersected - // with the flat x-y plane. I.e. it's fed a bunch of flat polygons. - // - // So, we assume that all z coordinates are 0. + // with the flat x-y plane. I.e. it's fed a bunch of flat 3d polygons with z==0 at all vertexes. // // Now. CGAL_Nef_poly3d objects have two 'half facets'. // On a flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'. // Now, we only want the vertexes--- so we only don't need both 'up' and 'down' facets. // What do we do? Just skip the 'down' facets! // - // By the way, 'up' facets list vertexs in CounterClockwise Order, and 'down' facets list vertexs + // By the way, 'up' facets list vertexes in CounterClockwise Order, and 'down' facets list vertexes // in Clockwise order. (or is it the other way round?). CGAL::Direction_3 up(0,0,1); @@ -156,6 +154,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) // in the XY plane, causing the resulting 2D polygon to be self-intersection // and cause a crash in CGALEvaluator::PolyReducer. The right solution is to // filter these polygons here. kintel 20120203. + /* Grid2d conversion_grid(GRID_COARSE); for (size_t i = 0; i < ps3->polygons.size(); i++) { for (size_t j = 0; j < ps3->polygons[i].size(); j++) { @@ -177,8 +176,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) } next_ps3_polygon_cut_mode:; } - delete ps3; - + */ } // In projection mode all the triangles are projected manually into the XY plane else -- cgit v0.10.1 From 7fda151957f71d1c4e53e127983886ffa7148bab Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 13 Feb 2012 19:31:11 -0600 Subject: cleanup tabs + wording. diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index 2e56f36..d994286 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -22,9 +22,9 @@ class NefShellVisitor_for_cut { public: std::stringstream out; + CGAL_Nef_polyhedron2::Boundary boundary; shared_ptr tmpnef; shared_ptr nefpoly2d; - CGAL_Nef_polyhedron2::Boundary boundary; NefShellVisitor_for_cut() { nefpoly2d.reset( new CGAL_Nef_polyhedron2() ); @@ -43,14 +43,14 @@ public: // This method is fed each 'facet' of the Nef_polyhedron3 that's been intersected // with the flat x-y plane. I.e. it's fed a bunch of flat 3d polygons with z==0 at all vertexes. // + // It takes the contours of the polygons, and either does join() or intersection() based + // on whether the contour is a 'hole' or 'body'. The result is stored in nefpoly2d. + // // Now. CGAL_Nef_poly3d objects have two 'half facets'. // On a flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'. // Now, we only want the vertexes--- so we only don't need both 'up' and 'down' facets. // What do we do? Just skip the 'down' facets! // - // By the way, 'up' facets list vertexes in CounterClockwise Order, and 'down' facets list vertexes - // in Clockwise order. (or is it the other way round?). - CGAL::Direction_3 up(0,0,1); CGAL::Plane_3 plane = hfacet->plane(); out << " direction == up? " << ( plane.orthogonal_direction() == up ) << "\n"; @@ -124,16 +124,16 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) CGAL_Nef_polyhedron3::Plane_3 plane = CGAL_Nef_polyhedron3::Plane_3( 0,0,1,0 ); *sum.p3 = sum.p3->intersection( plane, CGAL_Nef_polyhedron3::PLANE_ONLY); - NefShellVisitor_for_cut shell_visitor; - CGAL_Nef_polyhedron3::Volume_const_iterator i; - CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; + NefShellVisitor_for_cut shell_visitor; + CGAL_Nef_polyhedron3::Volume_const_iterator i; + CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; CGAL_Nef_polyhedron3::SFace_const_handle sface_handle; - for ( i = sum.p3->volumes_begin(); i != sum.p3->volumes_end(); ++i ) { - for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { + for ( i = sum.p3->volumes_begin(); i != sum.p3->volumes_end(); ++i ) { + for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); - sum.p3->visit_shell_objects( sface_handle , shell_visitor ); - } - } + sum.p3->visit_shell_objects( sface_handle , shell_visitor ); + } + } // std::cout << "shell visitor\n" << shell_visitor.dump() << "\n"; /*if (!sum.p3->is_simple()) { -- cgit v0.10.1 From 7cca215cbe11abbcf3ad792b0e5041291aef1566 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 13 Feb 2012 19:48:18 -0600 Subject: improve documentation diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index d994286..ee19531 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -43,13 +43,12 @@ public: // This method is fed each 'facet' of the Nef_polyhedron3 that's been intersected // with the flat x-y plane. I.e. it's fed a bunch of flat 3d polygons with z==0 at all vertexes. // - // It takes the contours of the polygons, and either does join() or intersection() based + // It takes the contours of the 2d polygons, and either does join() or intersection() based // on whether the contour is a 'hole' or 'body'. The result is stored in nefpoly2d. // - // Now. CGAL_Nef_poly3d objects have two 'half facets'. - // On a flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'. - // Now, we only want the vertexes--- so we only don't need both 'up' and 'down' facets. - // What do we do? Just skip the 'down' facets! + // On a Nef_Poly3 flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'. + // Now, we only want the vertexes--- and we only want one set of them. Not a duplicate set. + // So we don't need both 'up' and 'down' facets. What do we do? Just skip the 'down' facets! // CGAL::Direction_3 up(0,0,1); CGAL::Plane_3 plane = hfacet->plane(); -- cgit v0.10.1 From e747b0bfb52130eb01a02a29585e7688361d5fad Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 13 Feb 2012 19:54:33 -0600 Subject: fix tab spacing. comment out debugging line. diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index ee19531..8e8c8a1 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -52,7 +52,7 @@ public: // CGAL::Direction_3 up(0,0,1); CGAL::Plane_3 plane = hfacet->plane(); - out << " direction == up? " << ( plane.orthogonal_direction() == up ) << "\n"; + // out << " direction == up? " << ( plane.orthogonal_direction() == up ) << "\n"; if ( plane.orthogonal_direction() != up ) { // out << "direction == down. skipping"; return; diff --git a/src/polyset.cc b/src/polyset.cc index b6df0c2..b412f5f 100644 --- a/src/polyset.cc +++ b/src/polyset.cc @@ -50,32 +50,32 @@ PolySet::~PolySet() std::string PolySet::dump() const { - std::stringstream out; - out << "PolySet:" - << "\n dimensions:" << std::string( this->is2d ? "2" : "3" ) - << "\n convexity:" << this->convexity - << "\n num polygons: " << polygons.size() - << "\n num borders: " << borders.size() - << "\n polygons data:"; - for (size_t i = 0; i < polygons.size(); i++) { - out << "\n polygon begin:"; - const Polygon *poly = &polygons[i]; - for (size_t j = 0; j < poly->size(); j++) { - Vector3d v = poly->at(j); - out << "\n vertex:" << v.transpose(); - } - } + std::stringstream out; + out << "PolySet:" + << "\n dimensions:" << std::string( this->is2d ? "2" : "3" ) + << "\n convexity:" << this->convexity + << "\n num polygons: " << polygons.size() + << "\n num borders: " << borders.size() + << "\n polygons data:"; + for (size_t i = 0; i < polygons.size(); i++) { + out << "\n polygon begin:"; + const Polygon *poly = &polygons[i]; + for (size_t j = 0; j < poly->size(); j++) { + Vector3d v = poly->at(j); + out << "\n vertex:" << v.transpose(); + } + } out << "\n borders data:"; - for (size_t i = 0; i < borders.size(); i++) { - out << "\n border polygon begin:"; - const Polygon *poly = &borders[i]; - for (size_t j = 0; j < poly->size(); j++) { - Vector3d v = poly->at(j); - out << "\n vertex:" << v.transpose(); - } - } - out << "\nPolySet end"; - return out.str(); + for (size_t i = 0; i < borders.size(); i++) { + out << "\n border polygon begin:"; + const Polygon *poly = &borders[i]; + for (size_t j = 0; j < poly->size(); j++) { + Vector3d v = poly->at(j); + out << "\n vertex:" << v.transpose(); + } + } + out << "\nPolySet end"; + return out.str(); } void PolySet::append_poly() -- cgit v0.10.1 From 662da67571db010aeabf179a1bdc2997804a0f43 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 13 Feb 2012 19:56:38 -0600 Subject: fix debug printing diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index 8e8c8a1..c33b4e0 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -84,7 +84,7 @@ public: //out << " contour is a body. joining. " << contour.size() << " points.\n" ; *nefpoly2d += *tmpnef; } else { - //out << " contour is a hole. intersecting. " << contour.size() << "points.\n"; + //out << " contour is a hole. intersecting. " << contour.size() << " points.\n"; *nefpoly2d *= *tmpnef; } numcontours++; -- cgit v0.10.1 From 4381762f5aa2e6a56258618e585e1510ead88684 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 13 Feb 2012 20:42:36 -0600 Subject: rewrite documentation of visitor() diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index c33b4e0..9e30bc5 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -40,16 +40,14 @@ public: void visit( CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {} void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {} void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { - // This method is fed each 'facet' of the Nef_polyhedron3 that's been intersected + // This method is fed each 'half-facet' of the Nef_polyhedron3 that's been intersected // with the flat x-y plane. I.e. it's fed a bunch of flat 3d polygons with z==0 at all vertexes. + // It is fed both the 'up' pointing half-facets and the 'down' pointing half-facets. + // We only need one set of vertexes, so we skip all of the 'down' facets. // - // It takes the contours of the 2d polygons, and either does join() or intersection() based - // on whether the contour is a 'hole' or 'body'. The result is stored in nefpoly2d. - // - // On a Nef_Poly3 flat square in 3d space, there are 2 half-facets, one pointing 'up' and one 'down'. - // Now, we only want the vertexes--- and we only want one set of them. Not a duplicate set. - // So we don't need both 'up' and 'down' facets. What do we do? Just skip the 'down' facets! - // + // The vertexes are recorded in lists called 'contours'. Those are 'joined' or 'intersected' + // with the main result polyhedron, 'nefpoly2d', depending on whether it's a "hole" contour + // or a "body" contour. CGAL::Direction_3 up(0,0,1); CGAL::Plane_3 plane = hfacet->plane(); // out << " direction == up? " << ( plane.orthogonal_direction() == up ) << "\n"; -- cgit v0.10.1 From f4d9383d2940f959c207a8ea1cfe74db29fc804d Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 28 May 2012 12:05:35 -0500 Subject: cleanup unneeded #include, documentation diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 046ed12..ba298ad 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -5,7 +5,6 @@ #include "polyset.h" #include "dxfdata.h" #include "dxftess.h" -#include CGAL_Nef_polyhedron::CGAL_Nef_polyhedron(CGAL_Nef_polyhedron2 *p) { diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index 412314a..411a340 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -77,7 +77,7 @@ DxfData *CGAL_Nef_polyhedron::convertToDxfData() const return dxfdata; } -// moved here to reduce compile size/time of compiling CGAL_Nef_polyhedron.cc +// dump the 2 dimensional nef_poly. std::string CGAL_Nef_polyhedron::dump_p2() const { std::stringstream out; -- cgit v0.10.1 From 5b366adf8a9fb1b677eb9340f97ec764a15e5425 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 28 May 2012 12:38:40 -0500 Subject: adding new test images for 'hole' with projection-cut diff --git a/testdata/scad/features/projection-tests.scad b/testdata/scad/features/projection-tests.scad index edb65ba..e6c52ea 100644 --- a/testdata/scad/features/projection-tests.scad +++ b/testdata/scad/features/projection-tests.scad @@ -11,3 +11,10 @@ translate([44,0,0]) linear_extrude(height=20) projection(cut=true) translate([0, // Boundary case: clipping the top of a cube translate([0,-22,0]) linear_extrude(height=5) projection(cut=true) translate([0,0,-4.999999]) cube(10, center=true); + +// holes +translate([0,-44,0]) linear_extrude(height=5) projection(cut=true) + union() { + difference() { cube(5,center=true); cube(4,center=true); } + translate([2.1,2.1]) difference() { cube(5,center=true); cube(4,center=true); } + } diff --git a/tests/regression/cgalpngtest/projection-tests-expected.png b/tests/regression/cgalpngtest/projection-tests-expected.png index 31890b9..2610507 100644 Binary files a/tests/regression/cgalpngtest/projection-tests-expected.png and b/tests/regression/cgalpngtest/projection-tests-expected.png differ diff --git a/tests/regression/dumptest/projection-tests-expected.txt b/tests/regression/dumptest/projection-tests-expected.txt index 77fdbb4..69cd4f6 100644 --- a/tests/regression/dumptest/projection-tests-expected.txt +++ b/tests/regression/dumptest/projection-tests-expected.txt @@ -35,4 +35,22 @@ } } } + multmatrix([[1, 0, 0, 0], [0, 1, 0, -44], [0, 0, 1, 0], [0, 0, 0, 1]]) { + linear_extrude(height = 5, center = false, convexity = 1, $fn = 0, $fa = 12, $fs = 2) { + projection(cut = true, convexity = 0) { + union() { + difference() { + cube(size = [5, 5, 5], center = true); + cube(size = [4, 4, 4], center = true); + } + multmatrix([[1, 0, 0, 2.1], [0, 1, 0, 2.1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + difference() { + cube(size = [5, 5, 5], center = true); + cube(size = [4, 4, 4], center = true); + } + } + } + } + } + } diff --git a/tests/regression/opencsgtest/projection-tests-expected.png b/tests/regression/opencsgtest/projection-tests-expected.png index 98e12e2..9aabe36 100644 Binary files a/tests/regression/opencsgtest/projection-tests-expected.png and b/tests/regression/opencsgtest/projection-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/projection-tests-expected.png b/tests/regression/throwntogethertest/projection-tests-expected.png index 08c2998..3be3ae0 100644 Binary files a/tests/regression/throwntogethertest/projection-tests-expected.png and b/tests/regression/throwntogethertest/projection-tests-expected.png differ -- cgit v0.10.1 From ad041705744b8bbba98efa80337184db77c348a9 Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 29 May 2012 01:25:43 +0200 Subject: paralell build curl diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh new file mode 100755 index 0000000..b56ed05 --- /dev/null +++ b/scripts/linux-build-dependencies.sh @@ -0,0 +1,191 @@ +#!/bin/sh -e +# +# This script builds all library dependencies of OpenSCAD for Linux +# +# This script must be run from the OpenSCAD source root directory +# +# Usage: linux-build-dependencies.sh +# +# Prerequisites: +# - curl +# -- if you dont have curl, but do have wget, uncomment 'build_curl') +# -- and add $BASEDIR/bin to your PATH, i.e. in .bash_profile +# - Qt4 +# + +BASEDIR=$HOME +OPENSCADDIR=$PWD +SRCDIR=$BASEDIR/src +DEPLOYDIR=$BASEDIR +NUMCPU=4 # paralell builds + +printUsage() +{ + echo "Usage: $0" + echo +} + +build_curl() +{ + version=$1 + echo "Building curl" $version "..." + cd $BASEDIR/src + rm -rf curl-$version + if [ ! -f curl-$version.tar.bz2 ]; then + wget http://curl.haxx.se/download/curl-$version.tar.bz2 + fi + tar xjf curl-$version.tar.bz2 + cd curl-$version + mkdir build + cd build + ../configure --prefix=$DEPLOYDIR + make -j$NUMCPU install +} + +build_gmp() +{ + version=$1 + echo "Building gmp" $version "..." + cd $BASEDIR/src + rm -rf gmp-$version + if [ ! -f gmp-$version.tar.bz2 ]; then + curl -O ftp://ftp.gmplib.org/pub/gmp-$version/gmp-$version.tar.bz2 + fi + tar xjf gmp-$version.tar.bz2 + cd gmp-$version + mkdir build + cd build + ../configure --prefix=$DEPLOYDIR --enable-cxx + make install +} + +build_mpfr() +{ + version=$1 + echo "Building mpfr" $version "..." + cd $BASEDIR/src + rm -rf mpfr-$version + if [ ! -f mpfr-$version.tar.bz2 ]; then + curl -O http://www.mpfr.org/mpfr-current/mpfr-$version.tar.bz2 + fi + tar xjf mpfr-$version.tar.bz2 + cd mpfr-$version + curl -O http://www.mpfr.org/mpfr-current/allpatches + patch -N -Z -p1 < allpatches + mkdir build + cd build + ../configure --prefix=$DEPLOYDIR --with-gmp=$DEPLOYDIR + make install + cd .. +} + +build_boost() +{ + version=$1 + bversion=`echo $version | tr "." "_"` + echo "Building boost" $version "..." + cd $BASEDIR/src + rm -rf boost_$bversion + if [ ! -f boost_$bversion.tar.bz2 ]; then + curl -LO http://downloads.sourceforge.net/project/boost/boost/$version/boost_$bversion.tar.bz2 + fi + tar xjf boost_$bversion.tar.bz2 + cd boost_$bversion + # We only need certain portions of boost + ./bootstrap.sh --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem,system,regex + ./bjam + ./bjam install +} + +build_cgal() +{ + version=$1 + echo "Building CGAL" $version "..." + cd $BASEDIR/src + rm -rf CGAL-$version + if [ ! -f CGAL-$version.tar.gz ]; then + #4.0 + curl -O https://gforge.inria.fr/frs/download.php/30387/CGAL-$version.tar.gz + # 3.9 curl -O https://gforge.inria.fr/frs/download.php/29125/CGAL-$version.tar.gz + # 3.8 curl -O https://gforge.inria.fr/frs/download.php/28500/CGAL-$version.tar.gz + # 3.7 curl -O https://gforge.inria.fr/frs/download.php/27641/CGAL-$version.tar.gz + fi + tar xzf CGAL-$version.tar.gz + cd CGAL-$version + cmake -DCMAKE_INSTALL_PREFIX=$DEPLOYDIR -DGMP_INCLUDE_DIR=$DEPLOYDIR/include -DGMP_LIBRARIES=$DEPLOYDIR/lib/libgmp.so -DGMPXX_LIBRARIES=$DEPLOYDIR/lib/libgmpxx.so -DGMPXX_INCLUDE_DIR=$DEPLOYDIR/include -DMPFR_INCLUDE_DIR=$DEPLOYDIR/include -DMPFR_LIBRARIES=$DEPLOYDIR/lib/libmpfr.so -DWITH_CGAL_Qt3=OFF -DWITH_CGAL_Qt4=OFF -DWITH_CGAL_ImageIO=OFF -DBOOST_ROOT=$DEPLOYDIR -DCMAKE_BUILD_TYPE=Debug + make -j$NUMCPU + make install +} + +build_glew() +{ + version=$1 + echo "Building GLEW" $version "..." + cd $BASEDIR/src + rm -rf glew-$version + if [ ! -f glew-$version.tgz ]; then + curl -LO http://downloads.sourceforge.net/project/glew/glew/$version/glew-$version.tgz + fi + tar xzf glew-$version.tgz + cd glew-$version + mkdir -p $DEPLOYDIR/lib/pkgconfig + make GLEW_DEST=$DEPLOYDIR install +} + +build_opencsg() +{ + version=$1 + echo "Building OpenCSG" $version "..." + cd $BASEDIR/src + rm -rf OpenCSG-$version + if [ ! -f OpenCSG-$version.tar.gz ]; then + curl -O http://www.opencsg.org/OpenCSG-$version.tar.gz + fi + tar xzf OpenCSG-$version.tar.gz + cd OpenCSG-$version + sed -i s/example// opencsg.pro # examples might be broken without GLUT + OPENSCAD_LIBRARIES=$DEPLOYDIR qmake + make install +} + +build_eigen() +{ + version=$1 + echo "Building eigen" $version "..." + cd $BASEDIR/src + rm -rf eigen-$version + ## Directory name for v2.0.17 + rm -rf eigen-eigen-b23437e61a07 + if [ ! -f eigen-$version.tar.bz2 ]; then + curl -LO http://bitbucket.org/eigen/eigen/get/$version.tar.bz2 + mv $version.tar.bz2 eigen-$version.tar.bz2 + fi + tar xjf eigen-$version.tar.bz2 + ## File name for v2.0.17 + ln -s eigen-eigen-b23437e61a07 eigen-$version + cd eigen-$version + cmake -DCMAKE_INSTALL_PREFIX=$DEPLOYDIR + make -j$NUMCPU + make install +} + +if [ ! -f $OPENSCADDIR/openscad.pro ]; then + echo "Must be run from the OpenSCAD source root directory" + exit 0 +fi + +if [ ! -d $BASEDIR/bin ]; then + mkdir --parents $BASEDIR/bin +fi + +echo "Using basedir:" $BASEDIR +mkdir -p $SRCDIR $DEPLOYDIR +#build_curl 7.26.0 +build_eigen 2.0.17 +build_gmp 5.0.5 +build_mpfr 3.1.0 +build_boost 1.47.0 +# NB! For CGAL, also update the actual download URL in the function +build_cgal 4.0 +build_glew 1.7.0 +build_opencsg 1.3.2 -- cgit v0.10.1 From 145bc6df6163c74841e722a1ca8e954e4c9ebf6a Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 29 May 2012 01:27:40 +0200 Subject: documentation diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index b56ed05..96c4fff 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -17,7 +17,7 @@ BASEDIR=$HOME OPENSCADDIR=$PWD SRCDIR=$BASEDIR/src DEPLOYDIR=$BASEDIR -NUMCPU=4 # paralell builds +NUMCPU=4 # paralell builds for some libraries printUsage() { -- cgit v0.10.1 From bf5eac68809e1bb2c38f19f63589bc3a05ffcb72 Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 29 May 2012 01:50:31 +0200 Subject: tweaks, add more documentation, fix opencsg.h bug diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index 96c4fff..50c7949 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -144,8 +144,9 @@ build_opencsg() tar xzf OpenCSG-$version.tar.gz cd OpenCSG-$version sed -i s/example// opencsg.pro # examples might be broken without GLUT - OPENSCAD_LIBRARIES=$DEPLOYDIR qmake + OPENSCAD_LIBRARIES=$DEPLOYDIR qmake-qt4 make install + cp -av include/opencsg.h $BASEDIR/include/ # kludge } build_eigen() @@ -180,7 +181,7 @@ fi echo "Using basedir:" $BASEDIR mkdir -p $SRCDIR $DEPLOYDIR -#build_curl 7.26.0 +build_curl 7.26.0 build_eigen 2.0.17 build_gmp 5.0.5 build_mpfr 3.1.0 @@ -189,3 +190,9 @@ build_boost 1.47.0 build_cgal 4.0 build_glew 1.7.0 build_opencsg 1.3.2 + +echo "Now do this:" +echo "export LD_LIBRARY_PATH=$BASEDIR/lib" +echo "OPENSCAD_LIBRARIES=$BASEDIR qmake-qt4" +echo "make" + diff --git a/src/glview.cc b/src/glview.cc index aa2e746..82ca084 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -600,7 +600,7 @@ void GLView::mouseMoveEvent(QMouseEvent *event) double mz = -(dy) * viewer_distance/1000; double my = 0; - if (event->buttons() & Qt::MiddleButton) { + if (event->buttons() & Qt::MidButton) { my = mz; mz = 0; // actually lock the x-position -- cgit v0.10.1 From 26b3c3633c4cce04383d4d12e9e56f8c9cb5230a Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 29 May 2012 02:15:49 +0200 Subject: tweak opencsg installation. diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index 50c7949..be2c8eb 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -144,9 +144,10 @@ build_opencsg() tar xzf OpenCSG-$version.tar.gz cd OpenCSG-$version sed -i s/example// opencsg.pro # examples might be broken without GLUT - OPENSCAD_LIBRARIES=$DEPLOYDIR qmake-qt4 - make install - cp -av include/opencsg.h $BASEDIR/include/ # kludge + qmake-qt4 + make + install -v lib/* $DEPLOYDIR/lib + install -v include/* $DEPLOYDIR/include } build_eigen() @@ -181,14 +182,14 @@ fi echo "Using basedir:" $BASEDIR mkdir -p $SRCDIR $DEPLOYDIR -build_curl 7.26.0 -build_eigen 2.0.17 -build_gmp 5.0.5 -build_mpfr 3.1.0 -build_boost 1.47.0 +#build_curl 7.26.0 +#build_eigen 2.0.17 +#build_gmp 5.0.5 +#build_mpfr 3.1.0 +#build_boost 1.47.0 # NB! For CGAL, also update the actual download URL in the function -build_cgal 4.0 -build_glew 1.7.0 +#build_cgal 4.0 +#build_glew 1.7.0 build_opencsg 1.3.2 echo "Now do this:" -- cgit v0.10.1 From 056f6c6131bfc5067bcac7b0e71a0ac5aa2f5753 Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 29 May 2012 02:29:29 +0200 Subject: add documentation to workaround GLEWDIR bug diff --git a/glew.pri b/glew.pri index 981d14b..f4a6ccd 100644 --- a/glew.pri +++ b/glew.pri @@ -5,6 +5,7 @@ glew { !isEmpty(GLEW_DIR) { QMAKE_INCDIR += $$GLEW_DIR/include QMAKE_LIBDIR += $$GLEW_DIR/lib + QMAKE_LIBDIR += $$GLEW_DIR/lib64 message("GLEW location: $$GLEW_DIR") } diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index be2c8eb..b7f2ffc 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -129,7 +129,8 @@ build_glew() tar xzf glew-$version.tgz cd glew-$version mkdir -p $DEPLOYDIR/lib/pkgconfig - make GLEW_DEST=$DEPLOYDIR install + GLEW_DEST=$DEPLOYDIR make -j$NUMCPU + GLEW_DEST=$DEPLOYDIR make install } build_opencsg() @@ -189,11 +190,11 @@ mkdir -p $SRCDIR $DEPLOYDIR #build_boost 1.47.0 # NB! For CGAL, also update the actual download URL in the function #build_cgal 4.0 -#build_glew 1.7.0 +build_glew 1.7.0 build_opencsg 1.3.2 echo "Now do this:" -echo "export LD_LIBRARY_PATH=$BASEDIR/lib" -echo "OPENSCAD_LIBRARIES=$BASEDIR qmake-qt4" +echo "export LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64" +echo "GLEWDIR=$DEPLOYDIR OPENSCAD_LIBRARIES=$DEPLOYDIR qmake-qt4" echo "make" -- cgit v0.10.1 From 5b454adeef057f3c0bffdd7582cc46ce67344458 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 2 Jun 2012 18:26:44 +0200 Subject: add paralellization flags to various builds diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index b7f2ffc..4adf092 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -39,7 +39,8 @@ build_curl() mkdir build cd build ../configure --prefix=$DEPLOYDIR - make -j$NUMCPU install + make -j$NUMCPU + make install } build_gmp() @@ -93,7 +94,7 @@ build_boost() cd boost_$bversion # We only need certain portions of boost ./bootstrap.sh --prefix=$DEPLOYDIR --with-libraries=thread,program_options,filesystem,system,regex - ./bjam + ./bjam -j$NUMCPU ./bjam install } @@ -182,19 +183,21 @@ if [ ! -d $BASEDIR/bin ]; then fi echo "Using basedir:" $BASEDIR +echo "Using deploydir:" $DEPLOYDIR +echo "Using srcdir:" $SRCDIR mkdir -p $SRCDIR $DEPLOYDIR -#build_curl 7.26.0 -#build_eigen 2.0.17 -#build_gmp 5.0.5 -#build_mpfr 3.1.0 -#build_boost 1.47.0 +build_curl 7.26.0 +build_eigen 2.0.17 +build_gmp 5.0.5 +build_mpfr 3.1.0 +build_boost 1.47.0 # NB! For CGAL, also update the actual download URL in the function -#build_cgal 4.0 +build_cgal 4.0 build_glew 1.7.0 build_opencsg 1.3.2 echo "Now do this:" echo "export LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64" echo "GLEWDIR=$DEPLOYDIR OPENSCAD_LIBRARIES=$DEPLOYDIR qmake-qt4" -echo "make" +echo "make -j$NUMCPU" -- cgit v0.10.1 From a2902a527aaf41cdb9151d0726281f6d914cba9b Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 2 Jun 2012 18:29:50 +0200 Subject: fix glview to work with QT versions less than 4.7 diff --git a/src/glview.cc b/src/glview.cc index 82ca084..bea5856 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -600,7 +600,11 @@ void GLView::mouseMoveEvent(QMouseEvent *event) double mz = -(dy) * viewer_distance/1000; double my = 0; +#if (QT_VERSION < QT_VERSION_CHECK(4, 7, 0)) if (event->buttons() & Qt::MidButton) { +#else + if (event->buttons() & Qt::MiddleButton) { +#endif my = mz; mz = 0; // actually lock the x-position -- cgit v0.10.1 From 8abd201dd87bb423807e18e2980ace581efa171b Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 2 Jun 2012 18:58:08 +0200 Subject: add script to download and build updated cmake version (for CGAL) diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index 4adf092..9097850 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -8,16 +8,18 @@ # # Prerequisites: # - curl -# -- if you dont have curl, but do have wget, uncomment 'build_curl') +# -- you can uncomment 'build_curl' at the bottom # -- and add $BASEDIR/bin to your PATH, i.e. in .bash_profile # - Qt4 +# - cmake 2.8 +# -- you can uncomment 'build_cmake' at the bottom # BASEDIR=$HOME OPENSCADDIR=$PWD SRCDIR=$BASEDIR/src DEPLOYDIR=$BASEDIR -NUMCPU=4 # paralell builds for some libraries +NUMCPU=2 # paralell builds for some libraries printUsage() { @@ -25,6 +27,24 @@ printUsage() echo } +build_cmake() +{ + version=$1 + echo "Building cmake" $version "..." + cd $BASEDIR/src + rm -rf cmake-$version + if [ ! -f cmake-$version.tar.gz ]; then + curl -O http://www.cmake.org/files/v2.8/cmake-$version.tar.gz + fi + tar zxf cmake-$version.tar.gz + cd cmake-$version + mkdir build + cd build + ../configure --prefix=$DEPLOYDIR + make -j$NUMCPU + make install +} + build_curl() { version=$1 @@ -185,8 +205,12 @@ fi echo "Using basedir:" $BASEDIR echo "Using deploydir:" $DEPLOYDIR echo "Using srcdir:" $SRCDIR +echo "Number of CPUs for parallel builds:" $NUMCPU mkdir -p $SRCDIR $DEPLOYDIR -build_curl 7.26.0 + +#build_curl 7.26.0 +# NB! For cmake, also update the actual download URL in the function +#build_cmake 2.8.8 build_eigen 2.0.17 build_gmp 5.0.5 build_mpfr 3.1.0 -- cgit v0.10.1 From cd2d2dabf616e2e82a3d2c4de876ccef05f92e38 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 2 Jun 2012 21:57:28 +0200 Subject: enable CMAKE to find glew on systems that use 'lib64' diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 12b8543..569f631 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -237,7 +237,7 @@ if (NOT GLEW_INCLUDE_DIR) NO_DEFAULT_PATH) find_library(GLEW_LIBRARY NAMES GLEW glew - HINTS ${GLEW_DIR}/lib + HINTS ${GLEW_DIR}/lib ${GLEW_DIR}/lib64 NO_DEFAULT_PATH) if (NOT GLEW_LIBRARY) find_package(GLEW REQUIRED) -- cgit v0.10.1 From 25dca401e701f102e7360dc009064f12f1bf3a13 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 2 Jun 2012 22:15:28 +0200 Subject: improve documentation for test builds under unix/linux diff --git a/doc/testing.txt b/doc/testing.txt index 6990c2f..dbe0791 100644 --- a/doc/testing.txt +++ b/doc/testing.txt @@ -77,6 +77,10 @@ virtual framebuffer program like Xvnc or Xvfb. For example: $ Xvfb :5 -screen 0 800x600x24 & $ DISPLAY=:5 ctest +or + +$ xvfb-run ctest + Some versions of Xvfb may fail, however. 1. Trouble finding libraries on unix @@ -84,13 +88,18 @@ Some versions of Xvfb may fail, however. To help CMAKE find eigen2, OpenCSG, CGAL, Boost, and GLEW, you can use environment variables, just like for the main qmake & openscad.pro. Examples: - OPENSCAD_LIBRARIES=~ cmake . - CGALDIR=~/CGAL-3.9 BOOSTDIR=~/boost-1.47.0 cmake . - + OPENSCAD_LIBRARIES=$HOME cmake . + CGALDIR=$HOME/CGAL-3.9 BOOSTDIR=$HOME/boost-1.47.0 cmake . + Valid variables are as follows: BOOSTDIR, CGALDIR, EIGEN2DIR, GLEWDIR, OPENCSGDIR, OPENSCAD_LIBRARIES + When running, this might help find your locally built libraries (assuming + you installed into $HOME) + + export LD_LIBRARY_PATH=$HOME/lib:$HOME/lib64 + 2. Location of logs Logs of test runs are found in tests/build/Testing/Temporary -- cgit v0.10.1 From 7f803b51a21bc5b66c5e0c8c70382d833fbad864 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 2 Jun 2012 22:42:36 +0200 Subject: mention locale error/workaround in documentation diff --git a/doc/testing.txt b/doc/testing.txt index dbe0791..714a480 100644 --- a/doc/testing.txt +++ b/doc/testing.txt @@ -120,7 +120,16 @@ Comparison method. Your version of imagemagick is old. Upgrade, or pass -DCOMPARATOR=old to cmake. The comparison will be of lowered reliability. -5. Other issues +5. Locale errors + +"terminate called after throwing an instance of 'std::runtime_error' + what(): locale::facet::_S_create_c_locale name not valid" + +Is a boost/libstdc++ bug. Fix like so: + + $ export LC_MESSAGES= + +6. Other issues The OpenSCAD User Manual has a section on buildling. Please check there for updates: -- cgit v0.10.1 From c2f19f450b037fb28a269ad2ff5c228dfa6d5dad Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 3 Jun 2012 16:16:40 +0200 Subject: more reliable way of ensuring GLU is linked on new DSO linux systems. diff --git a/openscad.pro b/openscad.pro index 453ab77..591ed5f 100644 --- a/openscad.pro +++ b/openscad.pro @@ -81,9 +81,13 @@ win32 { CONFIG += qt QT += opengl -# Fedora Linux + DSO fix -linux*:exists(/usr/lib64/libGLU*)|linux*:exists(/usr/lib/libGLU*) { - LIBS += -lGLU +# see http://fedoraproject.org/wiki/UnderstandingDSOLinkChange +# and https://github.com/openscad/openscad/pull/119 +# ( QT += opengl does not automatically link glu on some DSO systems. ) +unix:!macx { + !contains ( QMAKE_LIBS_OPENGL, "-lGLU" ) { + QMAKE_LIBS_OPENGL += -lGLU + } } netbsd* { -- cgit v0.10.1 From bcf02d6013b07bf3481a6b725568fbe5039e34a9 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 4 Jun 2012 07:46:19 +0200 Subject: Minor Mac vs. Linux difference diff --git a/doc/testing.txt b/doc/testing.txt index 714a480..8ab1cee 100644 --- a/doc/testing.txt +++ b/doc/testing.txt @@ -98,7 +98,8 @@ Some versions of Xvfb may fail, however. When running, this might help find your locally built libraries (assuming you installed into $HOME) - export LD_LIBRARY_PATH=$HOME/lib:$HOME/lib64 + Linux: export LD_LIBRARY_PATH=$HOME/lib:$HOME/lib64 + Mac: export DYLD_LIBRARY_PATH=$HOME/lib 2. Location of logs -- cgit v0.10.1 From 38cb06c3f0c62cbbe911a1543128bde610c45031 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 4 Jun 2012 11:22:09 +0200 Subject: Added test cases for issue #123 diff --git a/testdata/scad/features/import_dxf-tests.scad b/testdata/scad/features/import_dxf-tests.scad index 736f26e..50a5416 100644 --- a/testdata/scad/features/import_dxf-tests.scad +++ b/testdata/scad/features/import_dxf-tests.scad @@ -7,3 +7,4 @@ translate([-200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); translate([200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="noname"); translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="Layer with a pretty long name including \\ \"special\" /'\\\\ characters"); +translate([200,0,0]) import(file="/Users/kintel/code/OpenSCAD/openscad/tests/../testdata/dxf/polygons.dxf"); diff --git a/testdata/scad/features/import_stl-tests.scad b/testdata/scad/features/import_stl-tests.scad index 7104078..af42e8d 100644 --- a/testdata/scad/features/import_stl-tests.scad +++ b/testdata/scad/features/import_stl-tests.scad @@ -1,3 +1,4 @@ import_stl("import.stl"); translate([2,0,0]) import("import.stl"); translate([4,0,0]) import("import_bin.stl"); +translate([0,2,0]) import("/Users/kintel/code/OpenSCAD/openscad/tests/../testdata/scad/features/import.stl"); diff --git a/testdata/scad/misc/include-tests-template.scad b/testdata/scad/misc/include-tests-template.scad deleted file mode 100644 index 43bda57..0000000 --- a/testdata/scad/misc/include-tests-template.scad +++ /dev/null @@ -1,55 +0,0 @@ -//Test that the entire path is pushed onto the stack upto the last '/' -include - -//Test that a non existent path/file doesn't screw things up -include - -//Test with empty path -include - -//Test without preceding space -include - -//Test with other strange character that is allowed -include>>>>> - -//Test that filenames with spaces work -include - -//Test with empty file -include - -//Test with empty path and file -include - -//Test with absolute path -include <@CMAKE_SOURCE_DIR@/../testdata/scad/misc/sub2/test7.scad> - -// Test simple MCAD include -include - -// Test MCAD include which includes another file -include - -// Test MCAD include which uses another file -include - -module test1() -{ - test2(); - translate([2,0,0]) test3(); - translate([2,-2,0]) test4(); - translate([-2,0,0]) test5(); - translate([-2,-2,0]) test6(); - translate([0,2,0]) test7(); - - //Just to give a top level object - translate([0,-2,0]) sphere(test2_variable, $fn=16); - - // MCAD - translate([0,-4,0]) cube([TAU/4,0.5,0.5], center=true); - translate([-2,-4,0]) cube([deg(0.5)/20,0.5,0.5], center=true); - translate([2,-4,-0.5]) scale(0.05) alignds420([0,0,0], [0,0,0]); -} - -test1(); diff --git a/testdata/scad/misc/use-tests-template.scad b/testdata/scad/misc/use-tests-template.scad deleted file mode 100644 index 24591f8..0000000 --- a/testdata/scad/misc/use-tests-template.scad +++ /dev/null @@ -1,57 +0,0 @@ -//Test that the entire path is pushed onto the stack upto the last '/' -use - -//Test that a non existent path/file doesn't screw things up -use - -//Test with empty path -use - -//Test without preceding space -use - -//Test with other strange character that is allowed -use>>>>> - -//Test that filenames with spaces work -use - -//Test with empty file -use - -//Test with empty path and file -use - -//Test with absolute path -include <@CMAKE_SOURCE_DIR@/../testdata/scad/misc/sub2/test7.scad> - -// Test simple MCAD library -include - -// Test MCAD library which includes another file -include - -// Test MCAD library which uses another file -include - -module test1() -{ - test2(); - // test3() and test4() are not directly included and thus not imported into - // this scope - translate([4,0,0]) test3(); - translate([4,-2,0]) test4(); - translate([-2,0,0]) test5(); - translate([-2,-2,0]) test6(); - translate([0,2,0]) test7(); - - // test2_variable won't be visible - translate([0,-2,0]) sphere(test2_variable, $fn=16); - - // MCAD - translate([0,-4,0]) teardrop(0.3, 1.5, 90); - translate([-2,-4,0]) cube([deg(0.5)/20,0.5,0.5], center=true); - translate([2,-4,-0.5]) scale(0.05) alignds420([0,0,0], [0,0,0]); -} - -test1(); diff --git a/testdata/scad/templates/import_dxf-tests-template.scad b/testdata/scad/templates/import_dxf-tests-template.scad new file mode 100644 index 0000000..f10dd06 --- /dev/null +++ b/testdata/scad/templates/import_dxf-tests-template.scad @@ -0,0 +1,10 @@ +import(); +translate([-210,0,0]) import(file="../../dxf/polygons.dxf"); +translate([-210,0,0]) import(file="../../dxf/polygons.dxf", origin=[0,110]); +translate([-210,0,0]) import(file="../../dxf/polygons.dxf", origin=[110,110], scale=0.5); +import(file="../../dxf/multiple-layers.dxf"); +translate([-200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); +translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); +translate([200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="noname"); +translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="Layer with a pretty long name including \\ \"special\" /'\\\\ characters"); +translate([200,0,0]) import(file="@CMAKE_SOURCE_DIR@/../testdata/dxf/polygons.dxf"); diff --git a/testdata/scad/templates/import_stl-tests-template.scad b/testdata/scad/templates/import_stl-tests-template.scad new file mode 100644 index 0000000..685b868 --- /dev/null +++ b/testdata/scad/templates/import_stl-tests-template.scad @@ -0,0 +1,4 @@ +import_stl("import.stl"); +translate([2,0,0]) import("import.stl"); +translate([4,0,0]) import("import_bin.stl"); +translate([0,2,0]) import("@CMAKE_SOURCE_DIR@/../testdata/scad/features/import.stl"); diff --git a/testdata/scad/templates/include-tests-template.scad b/testdata/scad/templates/include-tests-template.scad new file mode 100644 index 0000000..43bda57 --- /dev/null +++ b/testdata/scad/templates/include-tests-template.scad @@ -0,0 +1,55 @@ +//Test that the entire path is pushed onto the stack upto the last '/' +include + +//Test that a non existent path/file doesn't screw things up +include + +//Test with empty path +include + +//Test without preceding space +include + +//Test with other strange character that is allowed +include>>>>> + +//Test that filenames with spaces work +include + +//Test with empty file +include + +//Test with empty path and file +include + +//Test with absolute path +include <@CMAKE_SOURCE_DIR@/../testdata/scad/misc/sub2/test7.scad> + +// Test simple MCAD include +include + +// Test MCAD include which includes another file +include + +// Test MCAD include which uses another file +include + +module test1() +{ + test2(); + translate([2,0,0]) test3(); + translate([2,-2,0]) test4(); + translate([-2,0,0]) test5(); + translate([-2,-2,0]) test6(); + translate([0,2,0]) test7(); + + //Just to give a top level object + translate([0,-2,0]) sphere(test2_variable, $fn=16); + + // MCAD + translate([0,-4,0]) cube([TAU/4,0.5,0.5], center=true); + translate([-2,-4,0]) cube([deg(0.5)/20,0.5,0.5], center=true); + translate([2,-4,-0.5]) scale(0.05) alignds420([0,0,0], [0,0,0]); +} + +test1(); diff --git a/testdata/scad/templates/use-tests-template.scad b/testdata/scad/templates/use-tests-template.scad new file mode 100644 index 0000000..24591f8 --- /dev/null +++ b/testdata/scad/templates/use-tests-template.scad @@ -0,0 +1,57 @@ +//Test that the entire path is pushed onto the stack upto the last '/' +use + +//Test that a non existent path/file doesn't screw things up +use + +//Test with empty path +use + +//Test without preceding space +use + +//Test with other strange character that is allowed +use>>>>> + +//Test that filenames with spaces work +use + +//Test with empty file +use + +//Test with empty path and file +use + +//Test with absolute path +include <@CMAKE_SOURCE_DIR@/../testdata/scad/misc/sub2/test7.scad> + +// Test simple MCAD library +include + +// Test MCAD library which includes another file +include + +// Test MCAD library which uses another file +include + +module test1() +{ + test2(); + // test3() and test4() are not directly included and thus not imported into + // this scope + translate([4,0,0]) test3(); + translate([4,-2,0]) test4(); + translate([-2,0,0]) test5(); + translate([-2,-2,0]) test6(); + translate([0,2,0]) test7(); + + // test2_variable won't be visible + translate([0,-2,0]) sphere(test2_variable, $fn=16); + + // MCAD + translate([0,-4,0]) teardrop(0.3, 1.5, 90); + translate([-2,-4,0]) cube([deg(0.5)/20,0.5,0.5], center=true); + translate([2,-4,-0.5]) scale(0.05) alignds420([0,0,0], [0,0,0]); +} + +test1(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 569f631..5ec8be7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -611,10 +611,14 @@ endforeach() set_directory_properties(PROPERTIES TEST_INCLUDE_FILE "${CMAKE_SOURCE_DIR}/EnforceConfig.cmake") # Subst files -configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests-template.scad +configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/templates/include-tests-template.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad) -configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests-template.scad +configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/templates/use-tests-template.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad) +configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/templates/import_stl-tests-template.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/features/import_stl-tests.scad) +configure_file(${CMAKE_SOURCE_DIR}/../testdata/scad/templates/import_dxf-tests-template.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/features/import_dxf-tests.scad) # Find all scad files file(GLOB MINIMAL_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/minimal/*.scad) diff --git a/tests/regression/cgalpngtest/import_dxf-tests-expected.png b/tests/regression/cgalpngtest/import_dxf-tests-expected.png index 7c8a63e..f885b09 100644 Binary files a/tests/regression/cgalpngtest/import_dxf-tests-expected.png and b/tests/regression/cgalpngtest/import_dxf-tests-expected.png differ diff --git a/tests/regression/cgalpngtest/import_stl-tests-expected.png b/tests/regression/cgalpngtest/import_stl-tests-expected.png index 08aa225..de7638a 100644 Binary files a/tests/regression/cgalpngtest/import_stl-tests-expected.png and b/tests/regression/cgalpngtest/import_stl-tests-expected.png differ diff --git a/tests/regression/dumptest/import_dxf-tests-expected.txt b/tests/regression/dumptest/import_dxf-tests-expected.txt index 977efcc..d98b3e2 100644 --- a/tests/regression/dumptest/import_dxf-tests-expected.txt +++ b/tests/regression/dumptest/import_dxf-tests-expected.txt @@ -21,4 +21,7 @@ multmatrix([[1, 0, 0, 0], [0, 1, 0, 200], [0, 0, 1, 0], [0, 0, 0, 1]]) { import(file = "../../dxf/multiple-layers.dxf", layer = "Layer with a pretty long name including \\ \"special\" /'\\\\ characters", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); } + multmatrix([[1, 0, 0, 200], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + import(file = "../../dxf/polygons.dxf", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); + } diff --git a/tests/regression/dumptest/import_stl-tests-expected.txt b/tests/regression/dumptest/import_stl-tests-expected.txt index 648a207..947f137 100644 --- a/tests/regression/dumptest/import_stl-tests-expected.txt +++ b/tests/regression/dumptest/import_stl-tests-expected.txt @@ -5,4 +5,7 @@ multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { import(file = "import_bin.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { + import(file = "import.stl", layer = "", origin = [0, 0], scale = 1, convexity = 1, $fn = 0, $fa = 12, $fs = 2); + } diff --git a/tests/regression/opencsgtest/import_dxf-tests-expected.png b/tests/regression/opencsgtest/import_dxf-tests-expected.png index 6e568c7..010a222 100644 Binary files a/tests/regression/opencsgtest/import_dxf-tests-expected.png and b/tests/regression/opencsgtest/import_dxf-tests-expected.png differ diff --git a/tests/regression/opencsgtest/import_stl-tests-expected.png b/tests/regression/opencsgtest/import_stl-tests-expected.png index 19e233a..0bd9ab6 100644 Binary files a/tests/regression/opencsgtest/import_stl-tests-expected.png and b/tests/regression/opencsgtest/import_stl-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/import_dxf-tests-expected.png b/tests/regression/throwntogethertest/import_dxf-tests-expected.png index e8173d9..f5ef9fc 100644 Binary files a/tests/regression/throwntogethertest/import_dxf-tests-expected.png and b/tests/regression/throwntogethertest/import_dxf-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/import_stl-tests-expected.png b/tests/regression/throwntogethertest/import_stl-tests-expected.png index 19e233a..0bd9ab6 100644 Binary files a/tests/regression/throwntogethertest/import_stl-tests-expected.png and b/tests/regression/throwntogethertest/import_stl-tests-expected.png differ -- cgit v0.10.1 From 9698d1d2fbe6b19573a0e483a6411a8ebd0f6947 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 4 Jun 2012 11:23:37 +0200 Subject: Don't prefix filenames which are already absolute with document path. Fixed #123 diff --git a/src/context.cc b/src/context.cc index f96a45b..f71d2ac 100644 --- a/src/context.cc +++ b/src/context.cc @@ -32,7 +32,7 @@ #include "printutils.h" #include #include -using namespace boost::filesystem; +namespace fs = boost::filesystem; #include "boosty.h" std::vector Context::ctx_stack; @@ -179,8 +179,8 @@ AbstractNode *Context::evaluate_module(const ModuleInstantiation &inst) const */ std::string Context::getAbsolutePath(const std::string &filename) const { - if (!filename.empty()) { - return boosty::absolute(path(this->document_path) / filename).string(); + if (!filename.empty() && !boosty::is_absolute(fs::path(filename))) { + return boosty::absolute(fs::path(this->document_path) / filename).string(); } else { return filename; -- cgit v0.10.1 From f97f09ab0e960e8636493b5fbbe39b819e60025c Mon Sep 17 00:00:00 2001 From: Brad Pitcher Date: Tue, 19 Jun 2012 08:39:06 -0700 Subject: name the file with the correct architecture diff --git a/scripts/release-common.sh b/scripts/release-common.sh index 80c9795..94a8634 100755 --- a/scripts/release-common.sh +++ b/scripts/release-common.sh @@ -186,6 +186,6 @@ case $OS in strip openscad-$VERSION/lib/openscad/* cp scripts/installer-linux.sh openscad-$VERSION/install.sh chmod 755 -R openscad-$VERSION/ - tar cz openscad-$VERSION > openscad-$VERSION.x86-64.tar.gz + tar cz openscad-$VERSION > openscad-$VERSION.x86-$ARCH.tar.gz ;; esac -- cgit v0.10.1 From 32a0fcb892cbc8391ec3fcf545a88fafa83f083d Mon Sep 17 00:00:00 2001 From: Brad Pitcher Date: Tue, 19 Jun 2012 08:39:35 -0700 Subject: update linux snapshot links diff --git a/scripts/update-web.sh b/scripts/update-web.sh index 9036d9b..c611d28 100755 --- a/scripts/update-web.sh +++ b/scripts/update-web.sh @@ -11,6 +11,8 @@ fi if [[ $OSTYPE =~ "darwin" ]]; then OS=MACOSX +elif [[ $OSTYPE == "linux-gnu" ]]; then + OS=LINUX fi indexfile=../openscad.github.com/index.html @@ -21,6 +23,10 @@ if [ -f $indexfile ]; then file2=$2 sed -i .backup -e "s/^\(.*win-snapshot-zip.*\)\(OpenSCAD-.*\.zip\)\(.*\)\(OpenSCAD-.*zip\)\(.*$\)/\\1$file1\\3$file1\\5/" $indexfile sed -i .backup -e "s/^\(.*win-snapshot-exe.*\)\(OpenSCAD-.*-Installer\.exe\)\(.*\)\(OpenSCAD-.*-Installer.exe\)\(.*$\)/\\1$file2\\3$file2\\5/" $indexfile + elif [ $OS == LINUX ]; then + file2=$2 + sed -i .backup -e "s/^\(.*linux-snapshot-32.*\)\(openscad-.*-32\.tar\.gz\)\(.*\)\(openscad-.*-32\.tar\.gz\)\(.*$\)/\\1$file1\\3$file1\\5/" $indexfile + sed -i .backup -e "s/^\(.*linux-snapshot-64.*\)\(openscad-.*-64\.tar\.gz\)\(.*\)\(openscad-.*-64\.tar\.gz\)\(.*$\)/\\1$file2\\3$file2\\5/" $indexfile fi echo "Web page updated. Remember to commit and push openscad.github.com" else -- cgit v0.10.1 From 8e8f090fa48cc883b3197a6a1444841843e4cbc3 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 23 Jun 2012 23:05:06 +0200 Subject: cosmetics diff --git a/tests/dumptest.cc b/tests/dumptest.cc index f923a64..c1fe55b 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -84,7 +84,7 @@ int main(int argc, char **argv) QCoreApplication app(argc, argv); fs::path original_path = fs::current_path(); - currentdir = boosty::stringy( fs::current_path() ); + currentdir = boosty::stringy(fs::current_path()); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); -- cgit v0.10.1 From 0e6b80015504b36363c5545744b6627554c4d10b Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 23 Jun 2012 23:05:46 +0200 Subject: Output filenames relative to document path when exporting .csg files from the command-line. Fixes #128 diff --git a/src/openscad.cc b/src/openscad.cc index 7fe054f..61ac162 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -294,6 +294,7 @@ int main(int argc, char **argv) PRINTB("Can't open file \"%s\" for export", csg_output_file); } else { + fs::current_path(fparent); // Force exported filenames to be relative to document path fstream << tree.getString(*root_node) << "\n"; fstream.close(); } -- cgit v0.10.1 From 22c5f37424e42b69442ef6b020b650c0e685a8c3 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 24 Jun 2012 16:29:28 +0200 Subject: Search for libraries from a list of paths. Preparations for issue #125 diff --git a/src/lexer.l b/src/lexer.l index 188046f..f939330 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -118,7 +118,7 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); } else { usepath = sourcepath() / filename; if (!fs::exists(usepath)) { - usepath = boosty::absolute(fs::path(get_librarydir()) / filename); + usepath = locate_file(filename); } } /* Only accept regular files which exists */ @@ -214,7 +214,7 @@ void includefile() fs::path finfo = dirinfo / filename; if (!exists(finfo)) { - finfo = fs::path(get_librarydir()) / filepath / filename; + finfo = locate_file((fs::path(filepath) / filename).string()); } filepath.clear(); diff --git a/src/parsersettings.cc b/src/parsersettings.cc index a3a02b7..53b34f4 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -1,27 +1,38 @@ #include "parsersettings.h" #include +#include +#include "boosty.h" #include // Needed for Q_ defines - move the offending code somewhere else -using namespace boost::filesystem; -#include "boosty.h" +namespace fs = boost::filesystem; -std::string librarydir; +std::vector librarypath; -void set_librarydir(const std::string &libdir) +void add_librarydir(const std::string &libdir) { - librarydir = libdir; + librarypath.push_back(libdir); } -const std::string &get_librarydir() +/*! + Searces for the given file in library paths and returns the full path if found. + Returns an empty path if file cannot be found. +*/ +std::string locate_file(const std::string &filename) { - return librarydir; + BOOST_FOREACH(const std::string &dir, librarypath) { + fs::path usepath = fs::path(dir) / filename; + if (fs::exists(usepath)) return usepath.string(); + } + return std::string(); } void parser_init(const std::string &applicationpath) { + // FIXME: Append paths from OPENSCADPATH before adding built-in paths + std::string librarydir; - path libdir(applicationpath); - path tmpdir; + fs::path libdir(applicationpath); + fs::path tmpdir; #ifdef Q_WS_MAC libdir /= "../Resources"; // Libraries can be bundled if (!is_directory(libdir / "libraries")) libdir /= "../../.."; @@ -37,5 +48,5 @@ void parser_init(const std::string &applicationpath) if (is_directory(tmpdir = libdir / "libraries")) { librarydir = boosty::stringy( tmpdir ); } - set_librarydir(librarydir); + if (!librarydir.empty()) add_librarydir(librarydir); } diff --git a/src/parsersettings.h b/src/parsersettings.h index a5dc939..007aa9c 100644 --- a/src/parsersettings.h +++ b/src/parsersettings.h @@ -6,7 +6,7 @@ extern int parser_error_pos; void parser_init(const std::string &applicationpath); -void set_librarydir(const std::string &libdir); -const std::string &get_librarydir(); +void add_librarydir(const std::string &libdir); +std::string locate_file(const std::string &filename); #endif diff --git a/testdata/scad/features/import_dxf-tests.scad b/testdata/scad/features/import_dxf-tests.scad deleted file mode 100644 index 50a5416..0000000 --- a/testdata/scad/features/import_dxf-tests.scad +++ /dev/null @@ -1,10 +0,0 @@ -import(); -translate([-210,0,0]) import(file="../../dxf/polygons.dxf"); -translate([-210,0,0]) import(file="../../dxf/polygons.dxf", origin=[0,110]); -translate([-210,0,0]) import(file="../../dxf/polygons.dxf", origin=[110,110], scale=0.5); -import(file="../../dxf/multiple-layers.dxf"); -translate([-200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); -translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="0"); -translate([200,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="noname"); -translate([0,200,0]) import(file="../../dxf/multiple-layers.dxf", layer="Layer with a pretty long name including \\ \"special\" /'\\\\ characters"); -translate([200,0,0]) import(file="/Users/kintel/code/OpenSCAD/openscad/tests/../testdata/dxf/polygons.dxf"); diff --git a/testdata/scad/features/import_stl-tests.scad b/testdata/scad/features/import_stl-tests.scad deleted file mode 100644 index af42e8d..0000000 --- a/testdata/scad/features/import_stl-tests.scad +++ /dev/null @@ -1,4 +0,0 @@ -import_stl("import.stl"); -translate([2,0,0]) import("import.stl"); -translate([4,0,0]) import("import_bin.stl"); -translate([0,2,0]) import("/Users/kintel/code/OpenSCAD/openscad/tests/../testdata/scad/features/import.stl"); diff --git a/tests/cgalcachetest.cc b/tests/cgalcachetest.cc index 18e9efa..46e0e9a 100644 --- a/tests/cgalcachetest.cc +++ b/tests/cgalcachetest.cc @@ -139,7 +139,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgalpngtest.cc b/tests/cgalpngtest.cc index 7c9684a..08e539e 100644 --- a/tests/cgalpngtest.cc +++ b/tests/cgalpngtest.cc @@ -112,7 +112,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgalstlsanitytest.cc b/tests/cgalstlsanitytest.cc index d0d0077..92b4ac1 100644 --- a/tests/cgalstlsanitytest.cc +++ b/tests/cgalstlsanitytest.cc @@ -98,7 +98,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/cgaltest.cc b/tests/cgaltest.cc index 98617a3..e4761db 100644 --- a/tests/cgaltest.cc +++ b/tests/cgaltest.cc @@ -91,7 +91,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtermtest.cc b/tests/csgtermtest.cc index 1bd2468..e793c4a 100644 --- a/tests/csgtermtest.cc +++ b/tests/csgtermtest.cc @@ -77,7 +77,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index cb96940..02cf73c 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -258,7 +258,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) std::string currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/csgtexttest.cc b/tests/csgtexttest.cc index 6e18f20..e050232 100644 --- a/tests/csgtexttest.cc +++ b/tests/csgtexttest.cc @@ -81,7 +81,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/dumptest.cc b/tests/dumptest.cc index c1fe55b..6851fb1 100644 --- a/tests/dumptest.cc +++ b/tests/dumptest.cc @@ -87,7 +87,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy(fs::current_path()); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/echotest.cc b/tests/echotest.cc index d731ee3..bf2f4a4 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -89,7 +89,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); diff --git a/tests/modulecachetest.cc b/tests/modulecachetest.cc index 2ef7a6c..0028114 100644 --- a/tests/modulecachetest.cc +++ b/tests/modulecachetest.cc @@ -77,7 +77,7 @@ int main(int argc, char **argv) currentdir = boosty::stringy( fs::current_path() ); parser_init(QCoreApplication::instance()->applicationDirPath().toStdString()); - set_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); + add_librarydir(boosty::stringy(fs::path(QCoreApplication::instance()->applicationDirPath().toStdString()) / "../libraries")); Context root_ctx; register_builtin(root_ctx); -- cgit v0.10.1 From 431a24b4973069c86728f28efa62930354f92f6d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sat, 30 Jun 2012 23:42:51 +0300 Subject: Update master diff --git a/README.md b/README.md index 13fba4d..b1a618d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # What is OpenSCAD? +[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=openscad&url=http://openscad.org&title=OpenSCAD&language=&tags=github&category=software) OpenSCAD is a software for creating solid 3D CAD objects. It is free software and available for Linux/UNIX, MS Windows and Mac OS X. -- cgit v0.10.1 From 54067c635d1a6de4509930ed9d8593f5373f2ba1 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Sun, 1 Jul 2012 02:08:45 +0200 Subject: Fixed normalization bug: node limit wasn't checked properly and some cases triggered exponential expansion of nodes during normalization. Fixes #127 diff --git a/src/csgtermnormalizer.cc b/src/csgtermnormalizer.cc index 6600758..e2474e9 100644 --- a/src/csgtermnormalizer.cc +++ b/src/csgtermnormalizer.cc @@ -5,25 +5,29 @@ /*! NB! for e.g. empty intersections, this can normalize a tree to nothing and return NULL. */ -shared_ptr CSGTermNormalizer::normalize(const shared_ptr &root, - size_t limit) +shared_ptr CSGTermNormalizer::normalize(const shared_ptr &root) { shared_ptr temp = root; while (1) { + this->rootnode = temp; + this->nodecount = 0; shared_ptr n = normalizePass(temp); if (!n) return n; // If normalized to nothing if (temp == n) break; temp = n; - unsigned int num = count(temp); -#ifdef DEBUG - PRINTB("Normalize count: %d\n", num); -#endif - if (num > limit) { - PRINTB("WARNING: Normalized tree is growing past %d elements. Aborting normalization.\n", limit); - return root; + if (this->nodecount > this->limit) { + PRINTB("WARNING: Normalized tree is growing past %d elements. Aborting normalization.\n", this->limit); + // Clean up any partially evaluated terms + shared_ptr newroot = root, tmproot; + while (newroot != tmproot) { + tmproot = newroot; + newroot = collapse_null_terms(tmproot); + } + return newroot; } } + this->rootnode.reset(); return temp; } @@ -42,7 +46,11 @@ shared_ptr CSGTermNormalizer::normalizePass(shared_ptr term) } do { - while (term && normalize_tail(term)) { } + while (term && match_and_replace(term)) { } + this->nodecount++; + if (nodecount > this->limit) { + return shared_ptr(); + } if (!term || term->type == CSGTerm::TYPE_PRIMITIVE) return term; if (term->left) term->left = normalizePass(term->left); } while (term->type != CSGTerm::TYPE_UNION && @@ -51,6 +59,11 @@ shared_ptr CSGTermNormalizer::normalizePass(shared_ptr term) term->right = normalizePass(term->right); // FIXME: Do we need to take into account any transformation of item here? + return collapse_null_terms(term); +} + +shared_ptr CSGTermNormalizer::collapse_null_terms(const shared_ptr &term) +{ if (!term->right) { if (term->type == CSGTerm::TYPE_UNION || term->type == CSGTerm::TYPE_DIFFERENCE) return term->left; else return term->right; @@ -59,13 +72,14 @@ shared_ptr CSGTermNormalizer::normalizePass(shared_ptr term) if (term->type == CSGTerm::TYPE_UNION) return term->right; else return term->left; } - return term; } -bool CSGTermNormalizer::normalize_tail(shared_ptr &term) +bool CSGTermNormalizer::match_and_replace(shared_ptr &term) { - if (term->type == CSGTerm::TYPE_UNION || term->type == CSGTerm::TYPE_PRIMITIVE) return false; + if (term->type == CSGTerm::TYPE_UNION || term->type == CSGTerm::TYPE_PRIMITIVE) { + return false; + } // Part A: The 'x . (y . z)' expressions @@ -149,8 +163,9 @@ bool CSGTermNormalizer::normalize_tail(shared_ptr &term) return false; } +// Counts all non-leaf nodes unsigned int CSGTermNormalizer::count(const shared_ptr &term) const { if (!term) return 0; - return term->type == CSGTerm::TYPE_PRIMITIVE ? 1 : 0 + count(term->left) + count(term->right); + return term->type == CSGTerm::TYPE_PRIMITIVE ? 0 : 1 + count(term->left) + count(term->right); } diff --git a/src/csgtermnormalizer.h b/src/csgtermnormalizer.h index e5a2eca..c331f11 100644 --- a/src/csgtermnormalizer.h +++ b/src/csgtermnormalizer.h @@ -6,15 +6,20 @@ class CSGTermNormalizer { public: - CSGTermNormalizer() {} + CSGTermNormalizer(size_t limit) : limit(limit) {} ~CSGTermNormalizer() {} - shared_ptr normalize(const shared_ptr &term, size_t limit); + shared_ptr normalize(const shared_ptr &term); private: shared_ptr normalizePass(shared_ptr term) ; - bool normalize_tail(shared_ptr &term); + bool match_and_replace(shared_ptr &term); + shared_ptr collapse_null_terms(const shared_ptr &term); unsigned int count(const shared_ptr &term) const; + + size_t limit; + size_t nodecount; + shared_ptr rootnode; }; #endif diff --git a/src/mainwin.cc b/src/mainwin.cc index 087cb30..08fbec5 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -719,9 +719,9 @@ void MainWindow::compileCSG(bool procevents) if (procevents) QApplication::processEvents(); - CSGTermNormalizer normalizer; size_t normalizelimit = 2 * Preferences::inst()->getValue("advanced/openCSGLimit").toUInt(); - this->root_norm_term = normalizer.normalize(this->root_raw_term, normalizelimit); + CSGTermNormalizer normalizer(normalizelimit); + this->root_norm_term = normalizer.normalize(this->root_raw_term); if (this->root_norm_term) { this->root_chain = new CSGChain(); this->root_chain->import(this->root_norm_term); @@ -741,7 +741,7 @@ void MainWindow::compileCSG(bool procevents) highlights_chain = new CSGChain(); for (unsigned int i = 0; i < highlight_terms.size(); i++) { - highlight_terms[i] = normalizer.normalize(highlight_terms[i], normalizelimit); + highlight_terms[i] = normalizer.normalize(highlight_terms[i]); highlights_chain->import(highlight_terms[i]); } } @@ -754,7 +754,7 @@ void MainWindow::compileCSG(bool procevents) background_chain = new CSGChain(); for (unsigned int i = 0; i < background_terms.size(); i++) { - background_terms[i] = normalizer.normalize(background_terms[i], normalizelimit); + background_terms[i] = normalizer.normalize(background_terms[i]); background_chain->import(background_terms[i]); } } diff --git a/tests/csgtestcore.cc b/tests/csgtestcore.cc index 02cf73c..acc7c31 100644 --- a/tests/csgtestcore.cc +++ b/tests/csgtestcore.cc @@ -302,8 +302,8 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) } // CSG normalization - CSGTermNormalizer normalizer; - csgInfo.root_norm_term = normalizer.normalize(root_raw_term, 5000); + CSGTermNormalizer normalizer(5000); + csgInfo.root_norm_term = normalizer.normalize(root_raw_term); if (csgInfo.root_norm_term) { csgInfo.root_chain = new CSGChain(); csgInfo.root_chain->import(csgInfo.root_norm_term); @@ -319,7 +319,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) csgInfo.highlights_chain = new CSGChain(); for (unsigned int i = 0; i < csgInfo.highlight_terms.size(); i++) { - csgInfo.highlight_terms[i] = normalizer.normalize(csgInfo.highlight_terms[i], 5000); + csgInfo.highlight_terms[i] = normalizer.normalize(csgInfo.highlight_terms[i]); csgInfo.highlights_chain->import(csgInfo.highlight_terms[i]); } } @@ -329,7 +329,7 @@ int csgtestcore(int argc, char *argv[], test_type_e test_type) csgInfo.background_chain = new CSGChain(); for (unsigned int i = 0; i < csgInfo.background_terms.size(); i++) { - csgInfo.background_terms[i] = normalizer.normalize(csgInfo.background_terms[i], 5000); + csgInfo.background_terms[i] = normalizer.normalize(csgInfo.background_terms[i]); csgInfo.background_chain->import(csgInfo.background_terms[i]); } } -- cgit v0.10.1 From cc9fd5b33e42ea5d6f41c8ff649b2a014fa16450 Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 1 Jul 2012 17:07:39 +0200 Subject: Add link to Wikibooks manual for 'not 2-manifold' error on export. diff --git a/src/mainwin.cc b/src/mainwin.cc index 08fbec5..22bc498 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -1359,7 +1359,7 @@ void MainWindow::actionExportSTLorOFF(bool) } if (!this->root_N->p3->is_simple()) { - PRINT("Object isn't a valid 2-manifold! Modify your design.."); + PRINT("Object isn't a valid 2-manifold! Modify your design. See http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/STL_Import_and_Export"); clearCurrentOutput(); return; } -- cgit v0.10.1 From 491caa15ada3e51fd252aaa74de31178f01ff5ad Mon Sep 17 00:00:00 2001 From: don bright Date: Wed, 4 Jul 2012 04:34:00 +0200 Subject: auto-detect curl + cmake. link libs properly. use 'openscad_deps' subdir diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index 9097850..7727c4e 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -15,11 +15,11 @@ # -- you can uncomment 'build_cmake' at the bottom # -BASEDIR=$HOME +BASEDIR=$HOME/openscad_deps OPENSCADDIR=$PWD SRCDIR=$BASEDIR/src DEPLOYDIR=$BASEDIR -NUMCPU=2 # paralell builds for some libraries +NUMCPU=4 # paralell builds for some libraries printUsage() { @@ -87,12 +87,10 @@ build_mpfr() cd $BASEDIR/src rm -rf mpfr-$version if [ ! -f mpfr-$version.tar.bz2 ]; then - curl -O http://www.mpfr.org/mpfr-current/mpfr-$version.tar.bz2 + curl -O http://www.mpfr.org/mpfr-$version/mpfr-$version.tar.bz2 fi tar xjf mpfr-$version.tar.bz2 cd mpfr-$version - curl -O http://www.mpfr.org/mpfr-current/allpatches - patch -N -Z -p1 < allpatches mkdir build cd build ../configure --prefix=$DEPLOYDIR --with-gmp=$DEPLOYDIR @@ -208,19 +206,33 @@ echo "Using srcdir:" $SRCDIR echo "Number of CPUs for parallel builds:" $NUMCPU mkdir -p $SRCDIR $DEPLOYDIR -#build_curl 7.26.0 +export PATH=$BASEDIR/bin:$PATH +export LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64:$LD_LIBRARY_PATH +export LD_RUN_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64:$LD_RUN_PATH +echo "PATH modified" +echo "LD_LIBRARY_PATH modified" +echo "LD_RUN_PATH modified" + +if [ ! "`command -v curl`" ]; then + build_curl 7.26.0 +fi + # NB! For cmake, also update the actual download URL in the function -#build_cmake 2.8.8 +if [ ! "`command -v cmake`" ]; then + build_cmake 2.8.8 +fi + build_eigen 2.0.17 build_gmp 5.0.5 -build_mpfr 3.1.0 +build_mpfr 3.1.1 build_boost 1.47.0 # NB! For CGAL, also update the actual download URL in the function build_cgal 4.0 build_glew 1.7.0 build_opencsg 1.3.2 -echo "Now do this:" +echo "OpenSCAD dependencies built in " $BASEDIR +echo "To build OpenSCAD, copy/paste these lines to your shell prompt: " echo "export LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64" echo "GLEWDIR=$DEPLOYDIR OPENSCAD_LIBRARIES=$DEPLOYDIR qmake-qt4" echo "make -j$NUMCPU" -- cgit v0.10.1 From 9a05c66e1ccbdf44ad5c1bf333faff204b629619 Mon Sep 17 00:00:00 2001 From: don bright Date: Wed, 4 Jul 2012 06:33:04 +0200 Subject: document linux source build. add env variable script for linux src builds diff --git a/README.md b/README.md index b1a618d..1196621 100644 --- a/README.md +++ b/README.md @@ -79,10 +79,10 @@ To build OpenSCAD, you need some libraries and tools. The version numbers in brackets specify the versions which have been used for development. Other versions may or may not work as well. -If you're using Ubuntu, you can install these libraries from -aptitude. If you're using Mac, there is a build script that compiles -the libraries from source. Follow the instructions for the platform -you're compiling on below. +If you're using a newer version of Ubuntu, you can install these +libraries from aptitude. If you're using Mac, or an older Linux, there +are build scripts that download and compile the libraries from source. +Follow the instructions for the platform you're compiling on below. * [Qt4 (4.4 - 4.7)](http://www.qt.nokia.com/) * [CGAL (3.6 - 3.9)](http://www.cgal.org/) @@ -117,15 +117,25 @@ compilation process. After that, follow the Compilation instructions below. -### Building for Ubuntu +### Building for older Linux or without root access -If you have done this and want to contribute, fork the repo and -contribute docs on how to build for windows! +First, make sure that you have compiler tools (build-essential on ubuntu). +Then after you've cloned this git repository, run the script that sets up the +environment variables. + + source ./scripts/setenv-linbuild.sh + +Then run the script to download & compile all the prerequisite libraries above: + + ./scripts/linux-build-dependencies.sh + +After that, follow the Compilation instructions below. ### Building for Windows -If you have done this and want to contribute, fork the repo and -contribute docs on how to build for windows! +OpenSCAD for Windows is usually cross-compiled from Linux. If you wish to +attempt an MSVC build, please see this site: +http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Building_on_Windows ### Compilation diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index 7727c4e..a789e9d 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -7,12 +7,9 @@ # Usage: linux-build-dependencies.sh # # Prerequisites: -# - curl -# -- you can uncomment 'build_curl' at the bottom -# -- and add $BASEDIR/bin to your PATH, i.e. in .bash_profile +# - wget # - Qt4 -# - cmake 2.8 -# -- you can uncomment 'build_cmake' at the bottom +# - cmake 2.8 ( force build_cmake at bottom if yours is too old ) # BASEDIR=$HOME/openscad_deps @@ -209,9 +206,9 @@ mkdir -p $SRCDIR $DEPLOYDIR export PATH=$BASEDIR/bin:$PATH export LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64:$LD_LIBRARY_PATH export LD_RUN_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64:$LD_RUN_PATH -echo "PATH modified" -echo "LD_LIBRARY_PATH modified" -echo "LD_RUN_PATH modified" +echo "PATH modified temporarily" +echo "LD_LIBRARY_PATH modified temporarily" +echo "LD_RUN_PATH modified temporarily" if [ ! "`command -v curl`" ]; then build_curl 7.26.0 @@ -232,8 +229,3 @@ build_glew 1.7.0 build_opencsg 1.3.2 echo "OpenSCAD dependencies built in " $BASEDIR -echo "To build OpenSCAD, copy/paste these lines to your shell prompt: " -echo "export LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64" -echo "GLEWDIR=$DEPLOYDIR OPENSCAD_LIBRARIES=$DEPLOYDIR qmake-qt4" -echo "make -j$NUMCPU" - diff --git a/scripts/setenv-linbuild.sh b/scripts/setenv-linbuild.sh new file mode 100644 index 0000000..a61b55a --- /dev/null +++ b/scripts/setenv-linbuild.sh @@ -0,0 +1,16 @@ +# BASEDIR and DEPLOYDIR must be the same as in linux-build-dependencies.sh +BASEDIR=$HOME/openscad_deps +DEPLOYDIR=$BASEDIR + +PATH=$BASEDIR/bin:$PATH +LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64 +LD_RUN_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64 +OPENSCAD_LIBRARIES=$DEPLOYDIR +GLEWDIR=$DEPLOYDIR + +echo PATH modified +echo LD_LIBRARY_PATH modified +echo LD_RUN_PATH modified +echo OPENSCAD_LIBRARIES modified +echo GLEWDIR modified + -- cgit v0.10.1 From 984f7dc3f916232375ec7efe3b240e4c286a4c3c Mon Sep 17 00:00:00 2001 From: don bright Date: Wed, 4 Jul 2012 06:56:17 +0200 Subject: Add ubuntu package list for aptitude. Add pointer to wikibooks site diff --git a/README.md b/README.md index 1196621..8533e0d 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,15 @@ compilation process. After that, follow the Compilation instructions below. +### Building for newer Ubunutu + +sudo apt-get install libqt4-dev libqt4-opengl-dev libxmu-dev cmake \ + libglew1.5-dev bison flex libeigen2-dev git-core libboost-all-dev \ + libXi-dev libcgal-dev libglut3-dev libopencsg-dev libopencsg1 + +Check your library versions against the list above. After that, follow +the Compilation instructions below. + ### Building for older Linux or without root access First, make sure that you have compiler tools (build-essential on ubuntu). @@ -148,3 +157,5 @@ Then run make. Finally you might run 'make install' as root or simply copy the If you had problems compiling from source, raise a new issue in the [issue tracker on the github page](https://github.com/openscad/openscad/issues). +The four subsections of this site can also be helpful: +http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Building_OpenSCAD_from_Sources -- cgit v0.10.1 From bbef180a218aa59f03ea7bcf389ff3d1a357907d Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 3 Jul 2012 22:27:31 -0700 Subject: kludge-fix for broken Makefiles for opencsg + glew on Fedora 64bit diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index a789e9d..286399b 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -16,7 +16,7 @@ BASEDIR=$HOME/openscad_deps OPENSCADDIR=$PWD SRCDIR=$BASEDIR/src DEPLOYDIR=$BASEDIR -NUMCPU=4 # paralell builds for some libraries +NUMCPU=2 # paralell builds for some libraries printUsage() { @@ -145,6 +145,10 @@ build_glew() tar xzf glew-$version.tgz cd glew-$version mkdir -p $DEPLOYDIR/lib/pkgconfig + + # uncomment this kludge for Fedora 64bit + # sed -i s/"\-lXmu"/"\-L\/usr\/lib64\/libXmu.so.6"/ config/Makefile.linux + GLEW_DEST=$DEPLOYDIR make -j$NUMCPU GLEW_DEST=$DEPLOYDIR make install } @@ -161,6 +165,10 @@ build_opencsg() tar xzf OpenCSG-$version.tar.gz cd OpenCSG-$version sed -i s/example// opencsg.pro # examples might be broken without GLUT + + # uncomment this kludge for Fedora 64bit + # sed -i s/"\-lXmu"/"\-L\/usr\/lib64\/libXmu.so.6"/ src/Makefile + qmake-qt4 make install -v lib/* $DEPLOYDIR/lib -- cgit v0.10.1 From 5b805ed5869d1f2b0bc3a9c18d565b4780a2d163 Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 3 Jul 2012 22:31:22 -0700 Subject: wget or curl required. if curl isnt there, wget will fetch + build it diff --git a/scripts/linux-build-dependencies.sh b/scripts/linux-build-dependencies.sh index 286399b..aef58b9 100755 --- a/scripts/linux-build-dependencies.sh +++ b/scripts/linux-build-dependencies.sh @@ -7,7 +7,7 @@ # Usage: linux-build-dependencies.sh # # Prerequisites: -# - wget +# - wget or curl # - Qt4 # - cmake 2.8 ( force build_cmake at bottom if yours is too old ) # -- cgit v0.10.1 From def43ad3169d4dfbbcc42de41ab405af35f7ec23 Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 3 Jul 2012 22:53:37 -0700 Subject: improve script reporting and functionality (export) diff --git a/scripts/setenv-linbuild.sh b/scripts/setenv-linbuild.sh index a61b55a..d9aeea8 100644 --- a/scripts/setenv-linbuild.sh +++ b/scripts/setenv-linbuild.sh @@ -2,12 +2,14 @@ BASEDIR=$HOME/openscad_deps DEPLOYDIR=$BASEDIR -PATH=$BASEDIR/bin:$PATH -LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64 -LD_RUN_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64 -OPENSCAD_LIBRARIES=$DEPLOYDIR -GLEWDIR=$DEPLOYDIR +export PATH=$BASEDIR/bin:$PATH +export LD_LIBRARY_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64 +export LD_RUN_PATH=$DEPLOYDIR/lib:$DEPLOYDIR/lib64 +export OPENSCAD_LIBRARIES=$DEPLOYDIR +export GLEWDIR=$DEPLOYDIR +echo BASEDIR: $BASEDIR +echo DEPLOYDIR: $DEPLOYDIR echo PATH modified echo LD_LIBRARY_PATH modified echo LD_RUN_PATH modified -- cgit v0.10.1 From 9b0f148d2d71ae0d975912e1b405650a45f6b042 Mon Sep 17 00:00:00 2001 From: don bright Date: Wed, 4 Jul 2012 08:03:38 +0200 Subject: documentation for purpose of file diff --git a/scripts/setenv-linbuild.sh b/scripts/setenv-linbuild.sh index a61b55a..8e3d76d 100644 --- a/scripts/setenv-linbuild.sh +++ b/scripts/setenv-linbuild.sh @@ -1,3 +1,8 @@ +# setup env variables for building OpenSCAD against custom built +# dependency libraries from linux-build-dependencies.sh + +# run this file with 'source setenv-linbuild.sh' + # BASEDIR and DEPLOYDIR must be the same as in linux-build-dependencies.sh BASEDIR=$HOME/openscad_deps DEPLOYDIR=$BASEDIR -- cgit v0.10.1 From b92523eec55ac6768b434fc4d84469c82ecd4b96 Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Thu, 5 Jul 2012 12:46:15 +1000 Subject: add url of scad.el file to header for marmalade diff --git a/contrib/scad.el b/contrib/scad.el index 912b7ae..268ad61 100644 --- a/contrib/scad.el +++ b/contrib/scad.el @@ -4,6 +4,7 @@ ;; Maintainer: Len Trigg ;; Created: March 2010 ;; Modified: November 2011 +;; URL: https://raw.github.com/openscad/openscad/master/contrib/scad.el ;; Version: $Revision: 88 $ ;; This program is free software; you can redistribute it and/or modify -- cgit v0.10.1 From c777559ec4b34f1478cd6c991e1f7549780103af Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Fri, 6 Jul 2012 16:31:27 +1000 Subject: added the comment styles // and /* */ to scad-mode so you can use emacs' comment commands also renamed scad.el to scad-mode.el to be more in keeping with how files are named in emacs diff --git a/contrib/scad-mode.el b/contrib/scad-mode.el new file mode 100644 index 0000000..2244865 --- /dev/null +++ b/contrib/scad-mode.el @@ -0,0 +1,228 @@ +;;; scad.el --- SCAD mode derived mode + +;; Author: Len Trigg +;; Maintainer: Len Trigg +;; Created: March 2010 +;; Modified: November 2011 +;; Version: $Revision: 89 $ + +;; 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; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: +;; +;; This is a separate mode to implement the SCAD constructs and +;; font-locking. +;; +;; To use, insert the following into your emacs startup: +;; +;; (autoload 'scad-mode "scad" "Major mode for editing SCAD code." t) +;; (add-to-list 'auto-mode-alist '("\\.scad$" . scad-mode)) + +;;; To Do: +;; - Support for background/debug/root/disable modifiers +;; - Font lock of non-built-in function calls + +;;; Autoload mode trigger +(add-to-list 'auto-mode-alist '("\\.scad$" . scad-mode)) + +(defcustom scad-command + '"openscad" + "Path to openscad executable" + :type 'string + ) + +(defcustom scad-keywords + '("return" "true" "false") + "SCAD keywords." + :type 'list + :group 'scad-font-lock) + +(defcustom scad-functions + '("cos" "acos" "sin" "asin" "tan" "atan" "atan2" ;;func.cc + "abs" "sign" "rands" "min" "max" + "round" "ceil" "floor" + "pow" "sqrt" "exp" "log" "ln" + "str" + "lookup" "version" "version_num" + "dxf_dim" "dxf_cross" ;;dxfdim.cc + ) + "SCAD functions." + :type 'list + :group 'scad-font-lock) + +(defcustom scad-modules + '("child" "echo" "assign" "for" "intersection_for" "if" ;;control.cc + "cube" "sphere" "cylinder" "polyhedron" "square" "circle" "polygon" ;;primitives.cc + "scale" "rotate" "translate" "mirror" "multmatrix" ;;transform.cc + "union" "difference" "intersection" ;;csgops.cc + "render" ;;render.cc + "color" ;;color.cc + "surface" ;;surface.cc + "dxf_linear_extrude" "linear_extrude" ;;linearextrude.cc + "dxf_rotate_extrude" "rotate_extrude" ;;rotateextrude.cc + "import_stl" "import_off" "import_dxf" "import" ;;import.cc + "group" ;;builtin.cc + "projection" ;;projection.cc + "minkowski" "glide" "subdiv" "hull" ;;cgaladv.cc + ) + "SCAD modules." + :type 'list + :group 'scad-font-lock) + +(defcustom scad-operators + '("+" "-" "*" "/" "%" + "&&" "||" "!" + "<" "<=" "==" "!=" ">" ">=" + "?" ":" "=") + "SCAD operators." + :type 'list + :group 'scad-font-lock) + +(defvar scad-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "\t" 'scad-indent-line) + (define-key map [(control c) (control o)] 'scad-open-current-buffer) + (define-key map [return] 'newline-and-indent) + map) + "Keymap for `scad-mode'.") + +(defvar scad-mode-syntax-table + (let ((st (make-syntax-table))) + ;; support comment style: “// ...” + ;; support comment style: “/* ... */” + (modify-syntax-entry ?\/ ". 124b" st) + (modify-syntax-entry ?\n "> b" st) + (modify-syntax-entry ?* ". 23" st) + + ;; Extra punctuation + (modify-syntax-entry ?+ "." st) + (modify-syntax-entry ?- "." st) + (modify-syntax-entry ?% "." st) + (modify-syntax-entry ?< "." st) + (modify-syntax-entry ?> "." st) + (modify-syntax-entry ?& "." st) + (modify-syntax-entry ?: "." st) + (modify-syntax-entry ?| "." st) + (modify-syntax-entry ?= "." st) + (modify-syntax-entry ?\; "." st) + + ;; _ allowed in word (alternatively "_" as symbol constituent?) + (modify-syntax-entry ?_ "w" st) + + st) + "Syntax table for `scad-mode'.") + +(defvar scad-keywords-regexp (regexp-opt scad-keywords 'words)) +(defvar scad-modules-regexp (regexp-opt scad-modules 'words)) +(defvar scad-functions-regexp (regexp-opt scad-functions 'words)) +(defvar scad-operators-regexp (regexp-opt scad-operators)) + +(defvar scad-font-lock-keywords + `( + ("\\(module\\|function\\)[ \t]+\\(\\sw+\\)" (1 'font-lock-keyword-face nil) (2 'font-lock-function-name-face nil t)) + ("<\\(\\sw+\\)>" (1 'font-lock-builtin-face nil)) + ("$\\(\\sw+\\)" (1 'font-lock-builtin-face nil)) + (,scad-keywords-regexp . font-lock-keyword-face) + (,scad-modules-regexp . font-lock-builtin-face) + (,scad-functions-regexp . font-lock-function-name-face) + ;(,scad-operators-regexp . font-lock-operator-face) ;; This actually looks pretty ugly + ;("\\(\\<\\S +\\>\\)\\s *(" 1 font-lock-function-name-face t) ;; Seems to override other stuff (e.g. in comments and builtins) + ) + "Keyword highlighting specification for `scad-mode'.") + +;(defvar scad-imenu-generic-expression ...) +;(defvar scad-outline-regexp ...) + +;;;###autoload +(define-derived-mode scad-mode fundamental-mode "SCAD" + "A major mode for editing SCAD files." + :syntax-table scad-mode-syntax-table + (set (make-local-variable 'font-lock-defaults) '(scad-font-lock-keywords)) + (set (make-local-variable 'indent-line-function) 'scad-indent-line) + ;(set (make-local-variable 'imenu-generic-expression) scad-imenu-generic-expression) + ;(set (make-local-variable 'outline-regexp) scad-outline-regexp) + ;; set comment styles for scad mode + (set (make-local-variable 'comment-start) "//") + (set (make-local-variable 'comment-end) "") + (set (make-local-variable 'block-comment-start) "/*") + (set (make-local-variable 'block-comment-end) "*/") + + ) + + +;;; 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)))) + (if savep + (save-excursion (indent-line-to indent)) + (indent-line-to indent)))) + +(defun scad-calculate-indentation () + "Return the column to which the current line should be indented." + (save-excursion + (scad-maybe-skip-leading-close-delim) + (let ((pos (point))) + (beginning-of-line) + (if (not (search-backward-regexp "[^\n\t\r ]" 1 0)) + 0 + (progn + (scad-maybe-skip-leading-close-delim) + (+ (current-indentation) (* standard-indent (scad-count-scope-depth (point) pos)))))))) + +(defun scad-maybe-skip-leading-close-delim () + (beginning-of-line) + (forward-to-indentation 0) + (if (looking-at "\\s)") + (forward-char) + (beginning-of-line))) + +(defun scad-face-at-point (pos) + "Return face descriptor for char at point." + (plist-get (text-properties-at pos) 'face)) + +(defun scad-count-scope-depth (rstart rend) + "Return difference between open and close scope delimeters." + (save-excursion + (goto-char rstart) + (let ((open-count 0) + (close-count 0) + opoint) + (while (and (< (point) rend) + (progn (setq opoint (point)) + (re-search-forward "\\s)\\|\\s(" rend t))) + (if (= opoint (point)) + (forward-char 1) + (cond + ;; Don't count if in string or comment. + ((scad-face-at-point (- (point) 1))) + ((looking-back "\\s)") + (incf close-count)) + ((looking-back "\\s(") + (incf open-count)) + ))) + (- open-count close-count)))) + +(defun scad-open-current-buffer () + (interactive) + (call-process scad-command nil 0 nil (buffer-file-name))) + +(provide 'scad) +;;; scad.el ends here -- cgit v0.10.1 From 8fef221ddde948af86697aab2ff0eb23652088c5 Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Fri, 6 Jul 2012 16:32:47 +1000 Subject: remove old scad.el file diff --git a/contrib/scad.el b/contrib/scad.el deleted file mode 100644 index 912b7ae..0000000 --- a/contrib/scad.el +++ /dev/null @@ -1,222 +0,0 @@ -;;; scad.el --- SCAD mode derived mode - -;; Author: Len Trigg -;; Maintainer: Len Trigg -;; Created: March 2010 -;; Modified: November 2011 -;; Version: $Revision: 88 $ - -;; 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; see the file COPYING. If not, write to -;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. - -;;; Commentary: -;; -;; This is a separate mode to implement the SCAD constructs and -;; font-locking. -;; -;; To use, insert the following into your emacs startup: -;; -;; (autoload 'scad-mode "scad" "Major mode for editing SCAD code." t) -;; (add-to-list 'auto-mode-alist '("\\.scad$" . scad-mode)) - -;;; To Do: -;; - Support for background/debug/root/disable modifiers -;; - Font lock of non-built-in function calls - -;;; Autoload mode trigger -(add-to-list 'auto-mode-alist '("\\.scad$" . scad-mode)) - -(defcustom scad-command - '"openscad" - "Path to openscad executable" - :type 'string - ) - -(defcustom scad-keywords - '("return" "true" "false") - "SCAD keywords." - :type 'list - :group 'scad-font-lock) - -(defcustom scad-functions - '("cos" "acos" "sin" "asin" "tan" "atan" "atan2" ;;func.cc - "abs" "sign" "rands" "min" "max" - "round" "ceil" "floor" - "pow" "sqrt" "exp" "log" "ln" - "str" - "lookup" "version" "version_num" - "dxf_dim" "dxf_cross" ;;dxfdim.cc - ) - "SCAD functions." - :type 'list - :group 'scad-font-lock) - -(defcustom scad-modules - '("child" "echo" "assign" "for" "intersection_for" "if" ;;control.cc - "cube" "sphere" "cylinder" "polyhedron" "square" "circle" "polygon" ;;primitives.cc - "scale" "rotate" "translate" "mirror" "multmatrix" ;;transform.cc - "union" "difference" "intersection" ;;csgops.cc - "render" ;;render.cc - "color" ;;color.cc - "surface" ;;surface.cc - "dxf_linear_extrude" "linear_extrude" ;;linearextrude.cc - "dxf_rotate_extrude" "rotate_extrude" ;;rotateextrude.cc - "import_stl" "import_off" "import_dxf" "import" ;;import.cc - "group" ;;builtin.cc - "projection" ;;projection.cc - "minkowski" "glide" "subdiv" "hull" ;;cgaladv.cc - ) - "SCAD modules." - :type 'list - :group 'scad-font-lock) - -(defcustom scad-operators - '("+" "-" "*" "/" "%" - "&&" "||" "!" - "<" "<=" "==" "!=" ">" ">=" - "?" ":" "=") - "SCAD operators." - :type 'list - :group 'scad-font-lock) - -(defvar scad-mode-map - (let ((map (make-sparse-keymap))) - (define-key map "\t" 'scad-indent-line) - (define-key map [(control c) (control o)] 'scad-open-current-buffer) - (define-key map [return] 'newline-and-indent) - map) - "Keymap for `scad-mode'.") - -(defvar scad-mode-syntax-table - (let ((st (make-syntax-table))) - ;; support comment style: “// ...” - ;; support comment style: “/* ... */” - (modify-syntax-entry ?\/ ". 124b" st) - (modify-syntax-entry ?\n "> b" st) - (modify-syntax-entry ?* ". 23" st) - - ;; Extra punctuation - (modify-syntax-entry ?+ "." st) - (modify-syntax-entry ?- "." st) - (modify-syntax-entry ?% "." st) - (modify-syntax-entry ?< "." st) - (modify-syntax-entry ?> "." st) - (modify-syntax-entry ?& "." st) - (modify-syntax-entry ?: "." st) - (modify-syntax-entry ?| "." st) - (modify-syntax-entry ?= "." st) - (modify-syntax-entry ?\; "." st) - - ;; _ allowed in word (alternatively "_" as symbol constituent?) - (modify-syntax-entry ?_ "w" st) - - st) - "Syntax table for `scad-mode'.") - -(defvar scad-keywords-regexp (regexp-opt scad-keywords 'words)) -(defvar scad-modules-regexp (regexp-opt scad-modules 'words)) -(defvar scad-functions-regexp (regexp-opt scad-functions 'words)) -(defvar scad-operators-regexp (regexp-opt scad-operators)) - -(defvar scad-font-lock-keywords - `( - ("\\(module\\|function\\)[ \t]+\\(\\sw+\\)" (1 'font-lock-keyword-face nil) (2 'font-lock-function-name-face nil t)) - ("<\\(\\sw+\\)>" (1 'font-lock-builtin-face nil)) - ("$\\(\\sw+\\)" (1 'font-lock-builtin-face nil)) - (,scad-keywords-regexp . font-lock-keyword-face) - (,scad-modules-regexp . font-lock-builtin-face) - (,scad-functions-regexp . font-lock-function-name-face) - ;(,scad-operators-regexp . font-lock-operator-face) ;; This actually looks pretty ugly - ;("\\(\\<\\S +\\>\\)\\s *(" 1 font-lock-function-name-face t) ;; Seems to override other stuff (e.g. in comments and builtins) - ) - "Keyword highlighting specification for `scad-mode'.") - -;(defvar scad-imenu-generic-expression ...) -;(defvar scad-outline-regexp ...) - -;;;###autoload -(define-derived-mode scad-mode fundamental-mode "SCAD" - "A major mode for editing SCAD files." - :syntax-table scad-mode-syntax-table - (set (make-local-variable 'font-lock-defaults) '(scad-font-lock-keywords)) - (set (make-local-variable 'indent-line-function) 'scad-indent-line) - ;(set (make-local-variable 'imenu-generic-expression) scad-imenu-generic-expression) - ;(set (make-local-variable 'outline-regexp) scad-outline-regexp) - ) - - -;;; 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)))) - (if savep - (save-excursion (indent-line-to indent)) - (indent-line-to indent)))) - -(defun scad-calculate-indentation () - "Return the column to which the current line should be indented." - (save-excursion - (scad-maybe-skip-leading-close-delim) - (let ((pos (point))) - (beginning-of-line) - (if (not (search-backward-regexp "[^\n\t\r ]" 1 0)) - 0 - (progn - (scad-maybe-skip-leading-close-delim) - (+ (current-indentation) (* standard-indent (scad-count-scope-depth (point) pos)))))))) - -(defun scad-maybe-skip-leading-close-delim () - (beginning-of-line) - (forward-to-indentation 0) - (if (looking-at "\\s)") - (forward-char) - (beginning-of-line))) - -(defun scad-face-at-point (pos) - "Return face descriptor for char at point." - (plist-get (text-properties-at pos) 'face)) - -(defun scad-count-scope-depth (rstart rend) - "Return difference between open and close scope delimeters." - (save-excursion - (goto-char rstart) - (let ((open-count 0) - (close-count 0) - opoint) - (while (and (< (point) rend) - (progn (setq opoint (point)) - (re-search-forward "\\s)\\|\\s(" rend t))) - (if (= opoint (point)) - (forward-char 1) - (cond - ;; Don't count if in string or comment. - ((scad-face-at-point (- (point) 1))) - ((looking-back "\\s)") - (incf close-count)) - ((looking-back "\\s(") - (incf open-count)) - ))) - (- open-count close-count)))) - -(defun scad-open-current-buffer () - (interactive) - (call-process scad-command nil 0 nil (buffer-file-name))) - -(provide 'scad) -;;; scad.el ends here -- cgit v0.10.1 From 4c658e6bdb7f5220451b4ab34fa962a2054b1318 Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Fri, 6 Jul 2012 16:38:36 +1000 Subject: updated modified date in header diff --git a/contrib/scad-mode.el b/contrib/scad-mode.el index 2244865..0124b7e 100644 --- a/contrib/scad-mode.el +++ b/contrib/scad-mode.el @@ -3,7 +3,7 @@ ;; Author: Len Trigg ;; Maintainer: Len Trigg ;; Created: March 2010 -;; Modified: November 2011 +;; Modified: 06 July 2012 ;; Version: $Revision: 89 $ ;; This program is free software; you can redistribute it and/or modify -- cgit v0.10.1 From 77c20c0d71b063e446f85d2857898d4449d498aa Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Fri, 6 Jul 2012 16:49:37 +1000 Subject: changed instructions for installing to take into account change in file name diff --git a/contrib/scad-mode.el b/contrib/scad-mode.el index 0124b7e..0a7bd87 100644 --- a/contrib/scad-mode.el +++ b/contrib/scad-mode.el @@ -28,7 +28,7 @@ ;; ;; To use, insert the following into your emacs startup: ;; -;; (autoload 'scad-mode "scad" "Major mode for editing SCAD code." t) +;; (autoload 'scad-mode "scad-mode" "Major mode for editing SCAD code." t) ;; (add-to-list 'auto-mode-alist '("\\.scad$" . scad-mode)) ;;; To Do: -- cgit v0.10.1 From 0fb4614d20fd218e44846f2be9520723a09710a9 Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Sat, 7 Jul 2012 12:02:25 +1000 Subject: fixed file name in comments that are used for elpa/marmalade integration diff --git a/contrib/scad-mode.el b/contrib/scad-mode.el index b4d6e9e..e3eee0d 100644 --- a/contrib/scad-mode.el +++ b/contrib/scad-mode.el @@ -1,4 +1,4 @@ -;;; scad.el --- SCAD mode derived mode +;;; scad-mode.el --- SCAD mode derived mode ;; Author: Len Trigg ;; Maintainer: Len Trigg @@ -226,4 +226,4 @@ (call-process scad-command nil 0 nil (buffer-file-name))) (provide 'scad) -;;; scad.el ends here +;;; scad-mode.el ends here -- cgit v0.10.1