Stefan Schuermans commited on 2013-01-27 17:06:35
Showing 3 changed files, with 103 additions and 6 deletions.
... | ... |
@@ -122,7 +122,11 @@ bool CmdParser::procCmd_cut_inside(std::istream &strm) |
122 | 122 |
|
123 | 123 |
// TODO |
124 | 124 |
std::cerr << "TODO: cut_inside" << std::endl; |
125 |
- return false; |
|
125 |
+ Layer newLayer; |
|
126 |
+ polys.writeToLayer(newLayer); |
|
127 |
+ |
|
128 |
+ // convert layer to G-code |
|
129 |
+ newLayer.toGCode(mSettings, mGCode); |
|
126 | 130 |
|
127 | 131 |
return true; |
128 | 132 |
} |
... | ... |
@@ -143,7 +147,11 @@ bool CmdParser::procCmd_cut_outside(std::istream &strm) |
143 | 147 |
|
144 | 148 |
// TODO |
145 | 149 |
std::cerr << "TODO: cut_outside" << std::endl; |
146 |
- return false; |
|
150 |
+ Layer newLayer; |
|
151 |
+ polys.writeToLayer(newLayer); |
|
152 |
+ |
|
153 |
+ // convert layer to G-code |
|
154 |
+ newLayer.toGCode(mSettings, mGCode); |
|
147 | 155 |
|
148 | 156 |
return true; |
149 | 157 |
} |
... | ... |
@@ -164,7 +172,11 @@ bool CmdParser::procCmd_cut_pocket(std::istream &strm) |
164 | 172 |
|
165 | 173 |
// TODO |
166 | 174 |
std::cerr << "TODO: cut_pocket" << std::endl; |
167 |
- return false; |
|
175 |
+ Layer newLayer; |
|
176 |
+ polys.writeToLayer(newLayer); |
|
177 |
+ |
|
178 |
+ // convert layer to G-code |
|
179 |
+ newLayer.toGCode(mSettings, mGCode); |
|
168 | 180 |
|
169 | 181 |
return true; |
170 | 182 |
} |
... | ... |
@@ -7,7 +7,7 @@ |
7 | 7 |
#include <iostream> |
8 | 8 |
#include <vector> |
9 | 9 |
|
10 |
-#include <CGAL/Exact_predicates_exact_constructions_kernel.h> |
|
10 |
+#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> |
|
11 | 11 |
#include <CGAL/Polygon_2.h> |
12 | 12 |
#include <CGAL/Polygon_with_holes_2.h> |
13 | 13 |
#include <CGAL/create_offset_polygons_2.h> |
... | ... |
@@ -147,3 +147,59 @@ bool Polygons::loadLayer(const Layer &layer, double eqDist) |
147 | 147 |
return addLayer(layer, eqDist); |
148 | 148 |
} |
149 | 149 |
|
150 |
+/** |
|
151 |
+ * @brief add all polygons with holes as multiple paths to a layer |
|
152 |
+ * @param[in,out] layer layer to add paths to |
|
153 |
+ */ |
|
154 |
+void Polygons::addToLayer(Layer &layer) const |
|
155 |
+{ |
|
156 |
+ CgPolyHolesVec::const_iterator poly; |
|
157 |
+ for (poly = mPolys.begin(); poly != mPolys.end(); ++poly) |
|
158 |
+ PolyHolesToLayer(*poly, layer); |
|
159 |
+} |
|
160 |
+ |
|
161 |
+/** |
|
162 |
+ * @brief write all polygons with holes as multiple paths to a layer |
|
163 |
+ * @param[in,out] layer layer to write paths to |
|
164 |
+ */ |
|
165 |
+void Polygons::writeToLayer(Layer &layer) const |
|
166 |
+{ |
|
167 |
+ layer.mPaths.clear(); |
|
168 |
+ addToLayer(layer); |
|
169 |
+} |
|
170 |
+ |
|
171 |
+/** |
|
172 |
+ * @brief add a polygon as path to a layer |
|
173 |
+ * @param[in] poly polygon to add to layer |
|
174 |
+ * @param[in,out] layer layer to add path to |
|
175 |
+ */ |
|
176 |
+void Polygons::PolyToLayer(const CgPoly &poly, Layer &layer) |
|
177 |
+{ |
|
178 |
+ // ignore empty polygons |
|
179 |
+ if (poly.vertices_begin() == poly.vertices_end()) |
|
180 |
+ return; |
|
181 |
+ // create new path |
|
182 |
+ layer.mPaths.push_back(Path()); |
|
183 |
+ Path &path = layer.mPaths.back(); |
|
184 |
+ // add all points |
|
185 |
+ CgPoly::Vertex_const_iterator v; |
|
186 |
+ for (v = poly.vertices_begin(); v != poly.vertices_end(); ++v) |
|
187 |
+ path.addPoint(v->x(), v->y()); |
|
188 |
+ // add first point again to close path |
|
189 |
+ v = poly.vertices_begin(); |
|
190 |
+ path.addPoint(v->x(), v->y()); |
|
191 |
+} |
|
192 |
+ |
|
193 |
+/** |
|
194 |
+ * @brief add a polygon with holes as multiple paths to a layer |
|
195 |
+ * @param[in] poly polygon with holes to add to layer |
|
196 |
+ * @param[in,out] layer layer to add paths to |
|
197 |
+ */ |
|
198 |
+void Polygons::PolyHolesToLayer(const CgPolyHoles &poly, Layer &layer) |
|
199 |
+{ |
|
200 |
+ PolyToLayer(poly.outer_boundary(), layer); |
|
201 |
+ CgPolyHoles::Hole_const_iterator hole; |
|
202 |
+ for (hole = poly.holes_begin(); hole != poly.holes_end(); ++hole) |
|
203 |
+ PolyToLayer(*hole, layer); |
|
204 |
+} |
|
205 |
+ |
... | ... |
@@ -9,7 +9,7 @@ |
9 | 9 |
#include <boost/shared_ptr.hpp> |
10 | 10 |
#include <vector> |
11 | 11 |
|
12 |
-#include <CGAL/Exact_predicates_exact_constructions_kernel.h> |
|
12 |
+#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> |
|
13 | 13 |
#include <CGAL/Polygon_2.h> |
14 | 14 |
#include <CGAL/Polygon_with_holes_2.h> |
15 | 15 |
#include <CGAL/create_offset_polygons_2.h> |
... | ... |
@@ -19,7 +19,8 @@ |
19 | 19 |
/// a set of polygons |
20 | 20 |
class Polygons { |
21 | 21 |
public: |
22 |
- typedef CGAL::Exact_predicates_exact_constructions_kernel CgKern; |
|
22 |
+ typedef CGAL::Exact_predicates_inexact_constructions_kernel CgKern; |
|
23 |
+ |
|
23 | 24 |
typedef CgKern::Point_2 CgPoint; |
24 | 25 |
typedef CGAL::Polygon_2<CgKern> CgPoly; |
25 | 26 |
typedef CGAL::Polygon_with_holes_2<CgKern> CgPolyHoles; |
... | ... |
@@ -53,6 +54,34 @@ public: |
53 | 54 |
*/ |
54 | 55 |
bool loadLayer(const Layer &layer, double eqDist); |
55 | 56 |
|
57 |
+ /** |
|
58 |
+ * @brief add all polygons with holes as multiple paths to a layer |
|
59 |
+ * @param[in,out] layer layer to add paths to |
|
60 |
+ */ |
|
61 |
+ void addToLayer(Layer &layer) const; |
|
62 |
+ |
|
63 |
+ /** |
|
64 |
+ * @brief write all polygons with holes as multiple paths to a layer |
|
65 |
+ * @param[in,out] layer layer to write paths to |
|
66 |
+ */ |
|
67 |
+ void writeToLayer(Layer &layer) const; |
|
68 |
+ |
|
69 |
+protected: |
|
70 |
+ /** |
|
71 |
+ * @brief add a polygon as path to a layer |
|
72 |
+ * @param[in] poly polygon to add to layer |
|
73 |
+ * @param[in,out] layer layer to add path to |
|
74 |
+ */ |
|
75 |
+ static void PolyToLayer(const CgPoly &poly, Layer &layer); |
|
76 |
+ |
|
77 |
+ /** |
|
78 |
+ * @brief add a polygon with holes as multiple paths to a layer |
|
79 |
+ * @param[in] poly polygon with holes to add to layer |
|
80 |
+ * @param[in,out] layer layer to add paths to |
|
81 |
+ */ |
|
82 |
+ static void PolyHolesToLayer(const CgPolyHoles &poly, Layer &layer); |
|
83 |
+ |
|
84 |
+public: |
|
56 | 85 |
/// polygons |
57 | 86 |
CgPolyHolesVec mPolys; |
58 | 87 |
}; |
59 | 88 |