-
Notifications
You must be signed in to change notification settings - Fork 7
/
gerberimporter.cpp
123 lines (97 loc) · 3.16 KB
/
gerberimporter.cpp
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
123
/*
* This file is part of pcb2gcode.
*
* Copyright (C) 2009, 2010 Patrick Birnzain <[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/>.
*/
#include "gerberimporter.hpp"
#include <boost/scoped_array.hpp>
GerberImporter::GerberImporter(const string path)
{
project = gerbv_create_project();
const char* cfilename = path.c_str();
boost::scoped_array<char> filename( new char[strlen(cfilename) + 1] );
strcpy(filename.get(), cfilename);
gerbv_open_layer_from_filename(project, filename.get());
if( project->file[0] == NULL)
throw gerber_exception();
}
gdouble
GerberImporter::get_width()
{
if(!project || !project->file[0])
throw gerber_exception();
return project->file[0]->image->info->max_x - project->file[0]->image->info->min_x;
}
gdouble
GerberImporter::get_height()
{
if(!project || !project->file[0])
throw gerber_exception();
return project->file[0]->image->info->max_y - project->file[0]->image->info->min_y;
}
gdouble
GerberImporter::get_min_x()
{
if(!project || !project->file[0])
throw gerber_exception();
return project->file[0]->image->info->min_x;
}
gdouble
GerberImporter::get_max_x()
{
if(!project || !project->file[0])
throw gerber_exception();
return project->file[0]->image->info->max_x;
}
gdouble
GerberImporter::get_min_y()
{
if(!project || !project->file[0])
throw gerber_exception();
return project->file[0]->image->info->min_y;
}
gdouble
GerberImporter::get_max_y()
{
if(!project || !project->file[0])
throw gerber_exception();
return project->file[0]->image->info->max_y;
}
#include <iostream>
void
GerberImporter::render(Cairo::RefPtr<Cairo::ImageSurface> surface,
const guint dpi, const double min_x, const double min_y)
throw (import_exception)
{
gerbv_render_info_t render_info;
render_info.scaleFactorX = dpi;
render_info.scaleFactorY = dpi;
render_info.lowerLeftX = min_x;
render_info.lowerLeftY = min_y;
render_info.displayWidth = surface->get_width();
render_info.displayHeight = surface->get_height();
render_info.renderType = GERBV_RENDER_TYPE_CAIRO_NORMAL;
GdkColor color_saturated_white = { 0xFFFFFFFF, 0xFFFF, 0xFFFF, 0xFFFF };
project->file[0]->color = color_saturated_white;
cairo_t* cr = cairo_create( surface->cobj() );
gerbv_render_layer_to_cairo_target( cr, project->file[0], &render_info );
cairo_destroy(cr);
/// @todo check wheter importing was successful
}
GerberImporter::~GerberImporter()
{
gerbv_destroy_project(project);
}