-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
2,329 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Detect libxml2, then use this priority list to determine | ||
# which library to use: | ||
# | ||
# Priority | ||
# 1. LIBXML2_INCLUDEPATH / LIBXML2_LIBPATH (qmake parameter, not checked it given on commandline) | ||
# 2. OPENSCAD_LIBRARIES (environment variable) | ||
# 3. system's standard include paths from pkg-config | ||
|
||
libxml2 { | ||
# read environment variables | ||
OPENSCAD_LIBRARIES_DIR = $$(OPENSCAD_LIBRARIES) | ||
LIBXML2_DIR = $$(LIBXML2DIR) | ||
|
||
!isEmpty(OPENSCAD_LIBRARIES_DIR) { | ||
isEmpty(LIBXML2_INCLUDEPATH) { | ||
LIBXML2_INCLUDEPATH = $$OPENSCAD_LIBRARIES_DIR/include/libxml2 | ||
LIBXML2_LIBPATH = $$OPENSCAD_LIBRARIES_DIR/lib | ||
} | ||
} | ||
|
||
isEmpty(LIBXML2_INCLUDEPATH) { | ||
LIBXML2_CFLAGS = $$system("pkg-config --cflags libxml-2.0") | ||
} else { | ||
LIBXML2_CFLAGS = -I$$LIBXML2_INCLUDEPATH | ||
} | ||
|
||
isEmpty(LIBXML2_LIBPATH) { | ||
LIBXML2_LIBS = $$system("pkg-config --libs libxml-2.0") | ||
} else { | ||
LIBXML2_LIBS = -L$$LIBXML2_LIBPATH -lxml2 | ||
} | ||
|
||
QMAKE_CXXFLAGS += $$LIBXML2_CFLAGS | ||
LIBS += $$LIBXML2_LIBS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "import.h" | ||
#include "Polygon2d.h" | ||
#include "printutils.h" | ||
#include "libsvg/libsvg.h" | ||
#include "clipper-utils.h" | ||
|
||
Polygon2d *import_svg(const std::string &filename) | ||
{ | ||
libsvg::shapes_list_t *shapes = libsvg::libsvg_read_file(filename.c_str()); | ||
double x_min = 1.0/0.0; | ||
double x_max = -1.0/0.0; | ||
double y_min = 1.0/0.0; | ||
double y_max = -1.0/0.0; | ||
for (libsvg::shapes_list_t::iterator it = shapes->begin();it != shapes->end();it++) { | ||
PRINTD("SVG shape"); | ||
libsvg::shape *s = (*it); | ||
for (libsvg::path_list_t::iterator it = s->get_path_list().begin();it != s->get_path_list().end();it++) { | ||
PRINTD("SVG path"); | ||
libsvg::path_t& p = *it; | ||
for (libsvg::path_t::iterator it2 = p.begin();it2 != p.end();it2++) { | ||
Eigen::Vector3d& v = *it2; | ||
if (v.x() < x_min) { | ||
x_min = v.x(); | ||
} | ||
if (v.x() > x_max) { | ||
x_max = v.x(); | ||
} | ||
if (v.y() < y_min) { | ||
y_min = v.y(); | ||
} | ||
if (v.y() > y_max) { | ||
y_max = v.y(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
double cx = (x_min + x_max) / 2; | ||
double cy = (y_min + y_max) / 2; | ||
|
||
std::vector<const Polygon2d*> polygons; | ||
for (libsvg::shapes_list_t::iterator it = shapes->begin();it != shapes->end();it++) { | ||
Polygon2d *poly = new Polygon2d(); | ||
libsvg::shape *s = (*it); | ||
for (libsvg::path_list_t::iterator it = s->get_path_list().begin();it != s->get_path_list().end();it++) { | ||
libsvg::path_t& p = *it; | ||
|
||
Outline2d outline; | ||
for (libsvg::path_t::iterator it2 = p.begin();it2 != p.end();it2++) { | ||
Eigen::Vector3d& v = *it2; | ||
double x = v.x() - cx; | ||
double y = -v.y() + cy; | ||
outline.vertices.push_back(Vector2d(x, y)); | ||
outline.positive=true; | ||
} | ||
poly->addOutline(outline); | ||
} | ||
polygons.push_back(poly); | ||
} | ||
return ClipperUtils::apply(polygons, ClipperLib::ctUnion); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "circle.h" | ||
|
||
namespace libsvg { | ||
|
||
const std::string circle::name("circle"); | ||
|
||
circle::circle() | ||
{ | ||
} | ||
|
||
circle::circle(const circle& orig) : shape(orig) | ||
{ | ||
r = orig.r; | ||
} | ||
|
||
circle::~circle() | ||
{ | ||
} | ||
|
||
void | ||
circle::set_attrs(attr_map_t& attrs) | ||
{ | ||
shape::set_attrs(attrs); | ||
this->x = parse_double(attrs["cx"]); | ||
this->y = parse_double(attrs["cy"]); | ||
this->r = parse_double(attrs["r"]); | ||
|
||
path_t path; | ||
draw_ellipse(path, get_x(), get_y(), get_radius(), get_radius()); | ||
path_list.push_back(path); | ||
} | ||
|
||
void | ||
circle::dump() | ||
{ | ||
std::cout << get_name() | ||
<< ": x = " << this->x | ||
<< ": y = " << this->y | ||
<< ": r = " << this->r | ||
<< std::endl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef LIBSVG_CIRCLE_H | ||
#define LIBSVG_CIRCLE_H | ||
|
||
#include "shape.h" | ||
|
||
namespace libsvg { | ||
|
||
class circle : public shape { | ||
protected: | ||
double r; | ||
|
||
public: | ||
circle(); | ||
circle(const circle& orig); | ||
virtual ~circle(); | ||
|
||
virtual double get_radius() { return r; } | ||
|
||
virtual void set_attrs(attr_map_t& attrs); | ||
virtual void dump(); | ||
const std::string& get_name() const { return circle::name; }; | ||
|
||
static const std::string name; | ||
}; | ||
|
||
} | ||
|
||
#endif /* LIBSVG_CIRCLE_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <stdlib.h> | ||
#include <iostream> | ||
|
||
#include "ellipse.h" | ||
|
||
namespace libsvg { | ||
|
||
const std::string ellipse::name("ellipse"); | ||
|
||
ellipse::ellipse() | ||
{ | ||
} | ||
|
||
ellipse::ellipse(const ellipse& orig) : shape(orig) | ||
{ | ||
rx = orig.rx; | ||
ry = orig.ry; | ||
} | ||
|
||
ellipse::~ellipse() | ||
{ | ||
} | ||
|
||
void | ||
ellipse::set_attrs(attr_map_t& attrs) | ||
{ | ||
shape::set_attrs(attrs); | ||
this->x = parse_double(attrs["cx"]); | ||
this->y = parse_double(attrs["cy"]); | ||
this->rx = parse_double(attrs["rx"]); | ||
this->ry = parse_double(attrs["ry"]); | ||
|
||
path_t path; | ||
draw_ellipse(path, get_x(), get_y(), get_radius_x(), get_radius_y()); | ||
path_list.push_back(path); | ||
} | ||
|
||
void | ||
ellipse::dump() | ||
{ | ||
std::cout << get_name() | ||
<< ": x = " << this->x | ||
<< ": y = " << this->y | ||
<< ": rx = " << this->rx | ||
<< ": ry = " << this->ry | ||
<< std::endl; | ||
} | ||
|
||
} |
Oops, something went wrong.