forked from pcb2gcode/pcb2gcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
surface.hpp
122 lines (98 loc) · 3.53 KB
/
surface.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* This file is part of pcb2gcode.
*
* Copyright (C) 2009, 2010 Patrick Birnzain <[email protected]>
* Copyright (C) 2010 Bernhard Kubicek <[email protected]>
* Copyright (C) 2013 Erik Schuster <[email protected]>
* Copyright (C) 2015 Nicola Corna <[email protected]>
*
* pcb2gcode 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 3 of the License, or
* (at your option) any later version.
*
* pcb2gcode 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 pcb2gcode. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SURFACE_H
#define SURFACE_H
#include <memory>
#include <vector>
#include <boost/noncopyable.hpp>
#include <glibmm/refptr.h>
#include <gdkmm/pixbuf.h>
#include <glibmm/ustring.h>
#include "geometry.hpp"
#include "mill.hpp"
#include "gerberimporter.hpp"
#include "core.hpp"
struct surface_exception: virtual std::exception, virtual boost::exception
{
};
/******************************************************************************/
/*
*/
/******************************************************************************/
class Surface: public Core, private boost::noncopyable {
public:
Surface(guint dpi, ivalue_t min_x, ivalue_t max_x, ivalue_t min_y,
ivalue_t max_y, std::string name, std::string outputdir, bool tsp_2opt);
void render(std::shared_ptr<RasterLayerImporter> importer);
std::shared_ptr<Surface> deep_copy();
void save_debug_image(std::string);
std::vector<std::pair<coordinate_type_fp, std::vector<std::shared_ptr<icoords>>>> get_toolpath(
std::shared_ptr<RoutingMill> mill, bool mirror);
ivalue_t get_width_in() {
return max_x - min_x;
}
ivalue_t get_height_in() {
return max_y - min_y;
}
void add_mask(std::shared_ptr<Core>);
void enable_filling(double linewidth);
protected:
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
Cairo::RefPtr<Cairo::ImageSurface> cairo_surface;
static const int procmargin = 10;
const ivalue_t dpi;
const ivalue_t min_x, max_x, min_y, max_y;
const int zero_x, zero_y;
const std::string name;
const std::string outputdir;
const bool tsp_2opt;
bool fill;
double linewidth;
void make_the_surface(unsigned int width, unsigned int height);
void fill_outline();
// Image Processing Methods
inline ivalue_t xpt2i(int xpt) {
return ivalue_t(xpt - zero_x) / ivalue_t(dpi);
}
inline ivalue_t ypt2i(int ypt) {
return ivalue_t(ypt - zero_y) / ivalue_t(dpi);
}
inline int xi2pt(ivalue_t xi) {
return int(xi * ivalue_t(dpi)) + zero_x;
}
inline int yi2pt(ivalue_t yi) {
return int(yi * ivalue_t(dpi)) + zero_y;
}
std::vector<std::pair<int, int> > fill_all_components();
void fill_a_component(int x, int y, guint32 argb);
unsigned int grow_a_component(int x, int y, int& contentions);
inline bool allow_grow(int x, int y, guint32 ownclr);
void run_to_border(int& x, int& y);
void calculate_outline(int x, int y, std::vector<std::pair<int, int> >& outside,
std::vector<std::pair<int, int> >& inside);
// Misc. Functions
static void opacify(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
guint32 clr;
guint32 get_an_unused_color();
std::vector<guint32> usedcolors;
};
#endif // SURFACE_H