@huaqiu/js-gerbv 0.0.0-stage → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +151 -0
- package/LICENSE +674 -0
- package/README.md +105 -2
- package/include/config.h +34 -0
- package/include/gettext.h +9 -0
- package/index.js +382 -0
- package/package.json +46 -4
- package/prebuilds/darwin-arm64/gerbv_node.node +0 -0
- package/prebuilds/darwin-arm64/libglib-2.0.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libintl.8.dylib +0 -0
- package/prebuilds/darwin-arm64/libpcre2-8.0.dylib +0 -0
- package/prebuilds/darwin-arm64/meta.json +9 -0
- package/prebuilds/win32-x64/gerbv_node.node +0 -0
- package/prebuilds/win32-x64/libffi-8.dll +0 -0
- package/prebuilds/win32-x64/libgcc_s_seh-1.dll +0 -0
- package/prebuilds/win32-x64/libgio-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libglib-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libgmodule-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libgobject-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libiconv-2.dll +0 -0
- package/prebuilds/win32-x64/libintl-8.dll +0 -0
- package/prebuilds/win32-x64/libpcre2-8-0.dll +0 -0
- package/prebuilds/win32-x64/libstdc++-6.dll +0 -0
- package/prebuilds/win32-x64/libwinpthread-1.dll +0 -0
- package/prebuilds/win32-x64/meta.json +9 -0
- package/prebuilds/win32-x64/zlib1.dll +0 -0
- package/scripts/cmake-build.js +231 -0
- package/scripts/ensure-gerbv.js +42 -0
- package/scripts/pack-prebuild.js +208 -0
- package/scripts/smoke.js +74 -0
- package/shim/gdk/gdk.h +15 -0
- package/shim/gdk/gdkkeysyms.h +3 -0
- package/shim/gtk/gtk.h +7 -0
- package/src/addon.cc +740 -0
- package/src/gerber_min.c +67 -0
- package/src/gerbv_stubs.c +79 -0
- package/vcpkg.json +8 -0
package/src/addon.cc
ADDED
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node N-API 绑定:libgerbv 几何绘制 → RS-274X / Excellon。
|
|
3
|
+
* 内部坐标:英寸(libgerbv)。createImage({ unit, precision }) 在 native 侧换算。
|
|
4
|
+
*/
|
|
5
|
+
#include <napi.h>
|
|
6
|
+
|
|
7
|
+
// glib 2.90 的 gwin32.h 含 C++ 模板,必须在 extern "C" 之外先包含一次;
|
|
8
|
+
// 之后 gerbv.h 内的 glib.h 会被 include guard 跳过。
|
|
9
|
+
// 同时让 libintl.h 在 config.h 定义 gettext 宏之前解析(Linux)。
|
|
10
|
+
#include <glib.h>
|
|
11
|
+
|
|
12
|
+
extern "C" {
|
|
13
|
+
#include "gerbv.h"
|
|
14
|
+
#include "gerber.h"
|
|
15
|
+
#include "gerb_image.h"
|
|
16
|
+
/* gerb_image.c 内部辅助,未进公开头文件 */
|
|
17
|
+
gerbv_net_t* gerb_image_return_aperture_index(
|
|
18
|
+
gerbv_image_t* image, gdouble lineWidth, int* apertureIndex);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#include <algorithm>
|
|
22
|
+
#include <cctype>
|
|
23
|
+
#include <cmath>
|
|
24
|
+
#include <cstdio>
|
|
25
|
+
#include <filesystem>
|
|
26
|
+
#include <string>
|
|
27
|
+
#include <unistd.h>
|
|
28
|
+
#include <utility>
|
|
29
|
+
|
|
30
|
+
namespace {
|
|
31
|
+
|
|
32
|
+
struct ImageHandle {
|
|
33
|
+
gerbv_image_t* image = nullptr;
|
|
34
|
+
/** 用户单位 → inch 的乘数(inch=1,mm=1/25.4) */
|
|
35
|
+
double toInch = 1.0;
|
|
36
|
+
/** 换算到 inch 后保留的小数位;<0 表示不量化 */
|
|
37
|
+
int precision = -1;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** 用户坐标/长度 → libgerbv 内部 inch(可按 precision 量化) */
|
|
41
|
+
double ToInch(const ImageHandle* h, double v) {
|
|
42
|
+
double x = v * h->toInch;
|
|
43
|
+
if (h->precision >= 0) {
|
|
44
|
+
const int p = std::min(15, h->precision);
|
|
45
|
+
const double s = std::pow(10.0, p);
|
|
46
|
+
x = std::round(x * s) / s;
|
|
47
|
+
}
|
|
48
|
+
return x;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
std::string LowerAscii(std::string s) {
|
|
52
|
+
for (char& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
gerbv_net_t* LastNet(gerbv_image_t* image) {
|
|
57
|
+
gerbv_net_t* n = image->netlist;
|
|
58
|
+
for (; n && n->next; n = n->next) {
|
|
59
|
+
}
|
|
60
|
+
return n;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 切换到指定 polarity 的 layer,并挂一个继承该 layer 的净空 net,供后续 create_* 继承。 */
|
|
64
|
+
gerbv_layer_t* EnsurePolarity(gerbv_image_t* image, gerbv_polarity_t pol) {
|
|
65
|
+
gerbv_net_t* current = LastNet(image);
|
|
66
|
+
if (!current || !current->layer) return nullptr;
|
|
67
|
+
if (current->layer->polarity == pol) return current->layer;
|
|
68
|
+
gerbv_layer_t* layer = gerbv_image_return_new_layer(current->layer);
|
|
69
|
+
layer->polarity = pol;
|
|
70
|
+
current = gerber_create_new_net(current, layer, nullptr);
|
|
71
|
+
current->interpolation = GERBV_INTERPOLATION_LINEARx1;
|
|
72
|
+
current->aperture_state = GERBV_APERTURE_STATE_OFF;
|
|
73
|
+
current->start_x = current->stop_x = 0;
|
|
74
|
+
current->start_y = current->stop_y = 0;
|
|
75
|
+
return layer;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
void FreeImage(Napi::Env, ImageHandle* h) {
|
|
79
|
+
if (h) {
|
|
80
|
+
if (h->image) gerbv_destroy_image(h->image);
|
|
81
|
+
delete h;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
using ImageExt = Napi::External<ImageHandle>;
|
|
86
|
+
|
|
87
|
+
ImageHandle* Unwrap(const Napi::Value& v) {
|
|
88
|
+
if (!v.IsExternal()) return nullptr;
|
|
89
|
+
return v.As<ImageExt>().Data();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* createImage() | createImage({ unit?: 'inch'|'mm', precision?: number })
|
|
94
|
+
* unit:输入坐标单位(内部仍转成 inch 交给 libgerbv)
|
|
95
|
+
* precision:转到 inch 后保留的小数位(省略则不量化)
|
|
96
|
+
*/
|
|
97
|
+
Napi::Value CreateImage(const Napi::CallbackInfo& info) {
|
|
98
|
+
Napi::Env env = info.Env();
|
|
99
|
+
auto* h = new ImageHandle();
|
|
100
|
+
h->toInch = 1.0;
|
|
101
|
+
h->precision = -1;
|
|
102
|
+
|
|
103
|
+
if (info.Length() >= 1 && info[0].IsObject()) {
|
|
104
|
+
Napi::Object opts = info[0].As<Napi::Object>();
|
|
105
|
+
if (opts.Has("unit") && !opts.Get("unit").IsUndefined() && !opts.Get("unit").IsNull()) {
|
|
106
|
+
const std::string unit = LowerAscii(opts.Get("unit").ToString().Utf8Value());
|
|
107
|
+
if (unit == "mm" || unit == "metric") {
|
|
108
|
+
h->toInch = 1.0 / 25.4;
|
|
109
|
+
} else if (unit == "inch" || unit == "in" || unit == "imperial") {
|
|
110
|
+
h->toInch = 1.0;
|
|
111
|
+
} else {
|
|
112
|
+
delete h;
|
|
113
|
+
Napi::TypeError::New(env, "createImage: unit must be 'inch' or 'mm'")
|
|
114
|
+
.ThrowAsJavaScriptException();
|
|
115
|
+
return env.Null();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (opts.Has("precision") && opts.Get("precision").IsNumber()) {
|
|
119
|
+
h->precision = opts.Get("precision").As<Napi::Number>().Int32Value();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
h->image = gerbv_create_image(nullptr, "hqpcb-lite");
|
|
124
|
+
if (!h->image) {
|
|
125
|
+
delete h;
|
|
126
|
+
Napi::Error::New(env, "gerbv_create_image failed").ThrowAsJavaScriptException();
|
|
127
|
+
return env.Null();
|
|
128
|
+
}
|
|
129
|
+
return ImageExt::New(env, h, FreeImage);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
Napi::Value AddLine(const Napi::CallbackInfo& info) {
|
|
133
|
+
Napi::Env env = info.Env();
|
|
134
|
+
if (info.Length() < 6) {
|
|
135
|
+
Napi::TypeError::New(env, "addLine(image,x1,y1,x2,y2,width)").ThrowAsJavaScriptException();
|
|
136
|
+
return env.Undefined();
|
|
137
|
+
}
|
|
138
|
+
auto* h = Unwrap(info[0]);
|
|
139
|
+
if (!h || !h->image) {
|
|
140
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
141
|
+
return env.Undefined();
|
|
142
|
+
}
|
|
143
|
+
const double x1 = ToInch(h, info[1].As<Napi::Number>().DoubleValue());
|
|
144
|
+
const double y1 = ToInch(h, info[2].As<Napi::Number>().DoubleValue());
|
|
145
|
+
const double x2 = ToInch(h, info[3].As<Napi::Number>().DoubleValue());
|
|
146
|
+
const double y2 = ToInch(h, info[4].As<Napi::Number>().DoubleValue());
|
|
147
|
+
const double w = ToInch(h, info[5].As<Napi::Number>().DoubleValue());
|
|
148
|
+
EnsurePolarity(h->image, GERBV_POLARITY_DARK);
|
|
149
|
+
gerbv_image_create_line_object(h->image, x1, y1, x2, y2, w, GERBV_APTYPE_CIRCLE);
|
|
150
|
+
return env.Undefined();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 圆弧描边。addArc(image, cx, cy, x1, y1, x2, y2, width, clockwise?=false)
|
|
155
|
+
* 坐标单位由 createImage({ unit }) 决定;导出为 G02/G03。
|
|
156
|
+
*/
|
|
157
|
+
Napi::Value AddArc(const Napi::CallbackInfo& info) {
|
|
158
|
+
Napi::Env env = info.Env();
|
|
159
|
+
if (info.Length() < 8) {
|
|
160
|
+
Napi::TypeError::New(
|
|
161
|
+
env, "addArc(image,cx,cy,x1,y1,x2,y2,width,clockwise?=false)")
|
|
162
|
+
.ThrowAsJavaScriptException();
|
|
163
|
+
return env.Undefined();
|
|
164
|
+
}
|
|
165
|
+
auto* h = Unwrap(info[0]);
|
|
166
|
+
if (!h || !h->image) {
|
|
167
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
168
|
+
return env.Undefined();
|
|
169
|
+
}
|
|
170
|
+
const double cx = ToInch(h, info[1].As<Napi::Number>().DoubleValue());
|
|
171
|
+
const double cy = ToInch(h, info[2].As<Napi::Number>().DoubleValue());
|
|
172
|
+
const double x1 = ToInch(h, info[3].As<Napi::Number>().DoubleValue());
|
|
173
|
+
const double y1 = ToInch(h, info[4].As<Napi::Number>().DoubleValue());
|
|
174
|
+
const double x2 = ToInch(h, info[5].As<Napi::Number>().DoubleValue());
|
|
175
|
+
const double y2 = ToInch(h, info[6].As<Napi::Number>().DoubleValue());
|
|
176
|
+
const double w = ToInch(h, info[7].As<Napi::Number>().DoubleValue());
|
|
177
|
+
const bool clockwise = info.Length() >= 9 && info[8].ToBoolean().Value();
|
|
178
|
+
|
|
179
|
+
const double r = std::hypot(x1 - cx, y1 - cy);
|
|
180
|
+
if (!(r > 1e-12) || !(w > 0)) return env.Undefined();
|
|
181
|
+
|
|
182
|
+
EnsurePolarity(h->image, GERBV_POLARITY_DARK);
|
|
183
|
+
|
|
184
|
+
const double RAD2DEG = 180.0 / 3.14159265358979323846;
|
|
185
|
+
const double a0 = std::atan2(y1 - cy, x1 - cx) * RAD2DEG;
|
|
186
|
+
const double a1 = std::atan2(y2 - cy, x2 - cx) * RAD2DEG;
|
|
187
|
+
|
|
188
|
+
int apertureIndex = 0;
|
|
189
|
+
gerbv_net_t* currentNet =
|
|
190
|
+
gerb_image_return_aperture_index(h->image, w, &apertureIndex);
|
|
191
|
+
if (!currentNet) return env.Undefined();
|
|
192
|
+
|
|
193
|
+
currentNet = gerber_create_new_net(currentNet, currentNet->layer, nullptr);
|
|
194
|
+
currentNet->interpolation =
|
|
195
|
+
clockwise ? GERBV_INTERPOLATION_CW_CIRCULAR : GERBV_INTERPOLATION_CCW_CIRCULAR;
|
|
196
|
+
currentNet->aperture_state = GERBV_APERTURE_STATE_ON;
|
|
197
|
+
currentNet->aperture = apertureIndex;
|
|
198
|
+
currentNet->start_x = x1;
|
|
199
|
+
currentNet->start_y = y1;
|
|
200
|
+
currentNet->stop_x = x2;
|
|
201
|
+
currentNet->stop_y = y2;
|
|
202
|
+
currentNet->cirseg = g_new0(gerbv_cirseg_t, 1);
|
|
203
|
+
currentNet->cirseg->cp_x = cx;
|
|
204
|
+
currentNet->cirseg->cp_y = cy;
|
|
205
|
+
currentNet->cirseg->width = r;
|
|
206
|
+
currentNet->cirseg->height = r;
|
|
207
|
+
currentNet->cirseg->angle1 = a0;
|
|
208
|
+
currentNet->cirseg->angle2 = a1;
|
|
209
|
+
|
|
210
|
+
double angleDiff = a1 - a0;
|
|
211
|
+
if (clockwise) {
|
|
212
|
+
while (angleDiff > 0) angleDiff -= 360.0;
|
|
213
|
+
if (angleDiff == 0) angleDiff = -360.0;
|
|
214
|
+
} else {
|
|
215
|
+
while (angleDiff < 0) angleDiff += 360.0;
|
|
216
|
+
if (angleDiff == 0) angleDiff = 360.0;
|
|
217
|
+
}
|
|
218
|
+
const int steps = std::max(1, static_cast<int>(std::fabs(angleDiff)));
|
|
219
|
+
for (int i = 0; i <= steps; i++) {
|
|
220
|
+
const double a = (a0 + (angleDiff * i) / steps) * (3.14159265358979323846 / 180.0);
|
|
221
|
+
const double tx = cx + r * std::cos(a);
|
|
222
|
+
const double ty = cy + r * std::sin(a);
|
|
223
|
+
gerber_update_min_and_max(
|
|
224
|
+
¤tNet->boundingBox, tx, ty, w / 2, w / 2, w / 2, w / 2);
|
|
225
|
+
}
|
|
226
|
+
gerber_update_image_min_max(¤tNet->boundingBox, 0, 0, h->image);
|
|
227
|
+
return env.Undefined();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
Napi::Value AddFlashCircle(const Napi::CallbackInfo& info) {
|
|
231
|
+
Napi::Env env = info.Env();
|
|
232
|
+
if (info.Length() < 4) {
|
|
233
|
+
Napi::TypeError::New(env, "addFlashCircle(image,x,y,diam)").ThrowAsJavaScriptException();
|
|
234
|
+
return env.Undefined();
|
|
235
|
+
}
|
|
236
|
+
auto* h = Unwrap(info[0]);
|
|
237
|
+
if (!h || !h->image) {
|
|
238
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
239
|
+
return env.Undefined();
|
|
240
|
+
}
|
|
241
|
+
const double x = ToInch(h, info[1].As<Napi::Number>().DoubleValue());
|
|
242
|
+
const double y = ToInch(h, info[2].As<Napi::Number>().DoubleValue());
|
|
243
|
+
const double d = ToInch(h, info[3].As<Napi::Number>().DoubleValue());
|
|
244
|
+
EnsurePolarity(h->image, GERBV_POLARITY_DARK);
|
|
245
|
+
// 同点起止 → libgerbv 走 FLASH
|
|
246
|
+
gerbv_image_create_line_object(h->image, x, y, x, y, d, GERBV_APTYPE_CIRCLE);
|
|
247
|
+
return env.Undefined();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
Napi::Value AddRect(const Napi::CallbackInfo& info) {
|
|
251
|
+
Napi::Env env = info.Env();
|
|
252
|
+
if (info.Length() < 5) {
|
|
253
|
+
Napi::TypeError::New(env, "addRect(image,x,y,width,height)").ThrowAsJavaScriptException();
|
|
254
|
+
return env.Undefined();
|
|
255
|
+
}
|
|
256
|
+
auto* h = Unwrap(info[0]);
|
|
257
|
+
if (!h || !h->image) {
|
|
258
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
259
|
+
return env.Undefined();
|
|
260
|
+
}
|
|
261
|
+
const double x = ToInch(h, info[1].As<Napi::Number>().DoubleValue());
|
|
262
|
+
const double y = ToInch(h, info[2].As<Napi::Number>().DoubleValue());
|
|
263
|
+
const double w = ToInch(h, info[3].As<Napi::Number>().DoubleValue());
|
|
264
|
+
const double ht = ToInch(h, info[4].As<Napi::Number>().DoubleValue());
|
|
265
|
+
EnsurePolarity(h->image, GERBV_POLARITY_DARK);
|
|
266
|
+
gerbv_image_create_rectangle_object(h->image, x, y, w, ht);
|
|
267
|
+
return env.Undefined();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** 区域多边形构建器(G36…G37)。贝塞尔在本侧采样为折线。 */
|
|
271
|
+
struct PolygonHandle {
|
|
272
|
+
ImageHandle* owner = nullptr;
|
|
273
|
+
gerbv_image_t* image = nullptr;
|
|
274
|
+
gerbv_layer_t* layer = nullptr;
|
|
275
|
+
double startX = 0;
|
|
276
|
+
double startY = 0;
|
|
277
|
+
double curX = 0;
|
|
278
|
+
double curY = 0;
|
|
279
|
+
bool hasPoint = false;
|
|
280
|
+
bool finished = false;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
double ToInch(const PolygonHandle* p, double v) {
|
|
284
|
+
return p && p->owner ? ToInch(p->owner, v) : v;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
void FreePolygon(Napi::Env, PolygonHandle* p) { delete p; }
|
|
288
|
+
|
|
289
|
+
using PolygonExt = Napi::External<PolygonHandle>;
|
|
290
|
+
|
|
291
|
+
PolygonHandle* UnwrapPoly(const Napi::Value& v) {
|
|
292
|
+
if (!v.IsExternal()) return nullptr;
|
|
293
|
+
return v.As<PolygonExt>().Data();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
void PolyAppendLine(
|
|
297
|
+
PolygonHandle* p, double x2, double y2, bool penOn) {
|
|
298
|
+
gerbv_net_t* currentNet = LastNet(p->image);
|
|
299
|
+
currentNet = gerber_create_new_net(currentNet, p->layer, nullptr);
|
|
300
|
+
currentNet->interpolation = GERBV_INTERPOLATION_LINEARx1;
|
|
301
|
+
currentNet->aperture_state =
|
|
302
|
+
penOn ? GERBV_APERTURE_STATE_ON : GERBV_APERTURE_STATE_OFF;
|
|
303
|
+
currentNet->start_x = p->curX;
|
|
304
|
+
currentNet->start_y = p->curY;
|
|
305
|
+
currentNet->stop_x = x2;
|
|
306
|
+
currentNet->stop_y = y2;
|
|
307
|
+
if (penOn) {
|
|
308
|
+
gerber_update_min_and_max(
|
|
309
|
+
¤tNet->boundingBox, x2, y2, 0, 0, 0, 0);
|
|
310
|
+
gerber_update_image_min_max(¤tNet->boundingBox, 0, 0, p->image);
|
|
311
|
+
}
|
|
312
|
+
p->curX = x2;
|
|
313
|
+
p->curY = y2;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
void PolyAppendArc(
|
|
317
|
+
PolygonHandle* p, double cx, double cy, double x2, double y2, bool clockwise) {
|
|
318
|
+
const double x1 = p->curX;
|
|
319
|
+
const double y1 = p->curY;
|
|
320
|
+
const double r = std::hypot(x1 - cx, y1 - cy);
|
|
321
|
+
if (!(r > 1e-12)) {
|
|
322
|
+
PolyAppendLine(p, x2, y2, true);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const double RAD2DEG = 180.0 / 3.14159265358979323846;
|
|
326
|
+
const double a0 = std::atan2(y1 - cy, x1 - cx) * RAD2DEG;
|
|
327
|
+
const double a1 = std::atan2(y2 - cy, x2 - cx) * RAD2DEG;
|
|
328
|
+
|
|
329
|
+
gerbv_net_t* currentNet = LastNet(p->image);
|
|
330
|
+
currentNet = gerber_create_new_net(currentNet, p->layer, nullptr);
|
|
331
|
+
currentNet->interpolation =
|
|
332
|
+
clockwise ? GERBV_INTERPOLATION_CW_CIRCULAR : GERBV_INTERPOLATION_CCW_CIRCULAR;
|
|
333
|
+
currentNet->aperture_state = GERBV_APERTURE_STATE_ON;
|
|
334
|
+
currentNet->aperture = 0;
|
|
335
|
+
currentNet->start_x = x1;
|
|
336
|
+
currentNet->start_y = y1;
|
|
337
|
+
currentNet->stop_x = x2;
|
|
338
|
+
currentNet->stop_y = y2;
|
|
339
|
+
currentNet->cirseg = g_new0(gerbv_cirseg_t, 1);
|
|
340
|
+
currentNet->cirseg->cp_x = cx;
|
|
341
|
+
currentNet->cirseg->cp_y = cy;
|
|
342
|
+
currentNet->cirseg->width = r;
|
|
343
|
+
currentNet->cirseg->height = r;
|
|
344
|
+
currentNet->cirseg->angle1 = a0;
|
|
345
|
+
currentNet->cirseg->angle2 = a1;
|
|
346
|
+
|
|
347
|
+
double angleDiff = a1 - a0;
|
|
348
|
+
if (clockwise) {
|
|
349
|
+
while (angleDiff > 0) angleDiff -= 360.0;
|
|
350
|
+
if (angleDiff == 0) angleDiff = -360.0;
|
|
351
|
+
} else {
|
|
352
|
+
while (angleDiff < 0) angleDiff += 360.0;
|
|
353
|
+
if (angleDiff == 0) angleDiff = 360.0;
|
|
354
|
+
}
|
|
355
|
+
const int steps = std::max(1, static_cast<int>(std::fabs(angleDiff)));
|
|
356
|
+
for (int i = 0; i <= steps; i++) {
|
|
357
|
+
const double a = (a0 + (angleDiff * i) / steps) * (3.14159265358979323846 / 180.0);
|
|
358
|
+
gerber_update_min_and_max(
|
|
359
|
+
¤tNet->boundingBox, cx + r * std::cos(a), cy + r * std::sin(a), 0, 0, 0, 0);
|
|
360
|
+
}
|
|
361
|
+
gerber_update_image_min_max(¤tNet->boundingBox, 0, 0, p->image);
|
|
362
|
+
p->curX = x2;
|
|
363
|
+
p->curY = y2;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
void PolyAppendBezierSampled(
|
|
367
|
+
PolygonHandle* p, double c1x, double c1y, double c2x, double c2y, double x2,
|
|
368
|
+
double y2, bool cubic, int steps) {
|
|
369
|
+
const double x0 = p->curX;
|
|
370
|
+
const double y0 = p->curY;
|
|
371
|
+
const int n = std::max(4, steps);
|
|
372
|
+
for (int i = 1; i <= n; i++) {
|
|
373
|
+
const double t = static_cast<double>(i) / n;
|
|
374
|
+
const double u = 1.0 - t;
|
|
375
|
+
double x, y;
|
|
376
|
+
if (cubic) {
|
|
377
|
+
x = u * u * u * x0 + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * x2;
|
|
378
|
+
y = u * u * u * y0 + 3 * u * u * t * c1y + 3 * u * t * t * c2y + t * t * t * y2;
|
|
379
|
+
} else {
|
|
380
|
+
x = u * u * x0 + 2 * u * t * c1x + t * t * x2;
|
|
381
|
+
y = u * u * y0 + 2 * u * t * c1y + t * t * y2;
|
|
382
|
+
}
|
|
383
|
+
PolyAppendLine(p, x, y, true);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
bool PolyEnsureStart(PolygonHandle* p, double x, double y, Napi::Env env) {
|
|
388
|
+
if (p->finished) {
|
|
389
|
+
Napi::Error::New(env, "polygon already ended").ThrowAsJavaScriptException();
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
if (p->hasPoint) return true;
|
|
393
|
+
gerbv_net_t* currentNet = LastNet(p->image);
|
|
394
|
+
currentNet = gerber_create_new_net(currentNet, p->layer, nullptr);
|
|
395
|
+
currentNet->interpolation = GERBV_INTERPOLATION_PAREA_START;
|
|
396
|
+
|
|
397
|
+
p->startX = p->curX = x;
|
|
398
|
+
p->startY = p->curY = y;
|
|
399
|
+
p->hasPoint = true;
|
|
400
|
+
|
|
401
|
+
currentNet = gerber_create_new_net(LastNet(p->image), p->layer, nullptr);
|
|
402
|
+
currentNet->interpolation = GERBV_INTERPOLATION_LINEARx1;
|
|
403
|
+
currentNet->aperture_state = GERBV_APERTURE_STATE_OFF;
|
|
404
|
+
currentNet->start_x = x;
|
|
405
|
+
currentNet->start_y = y;
|
|
406
|
+
currentNet->stop_x = x;
|
|
407
|
+
currentNet->stop_y = y;
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* createPolygon(image, clear?=false) → polygon
|
|
413
|
+
*/
|
|
414
|
+
Napi::Value CreatePolygon(const Napi::CallbackInfo& info) {
|
|
415
|
+
Napi::Env env = info.Env();
|
|
416
|
+
if (info.Length() < 1) {
|
|
417
|
+
Napi::TypeError::New(env, "createPolygon(image, clear?=false)")
|
|
418
|
+
.ThrowAsJavaScriptException();
|
|
419
|
+
return env.Null();
|
|
420
|
+
}
|
|
421
|
+
auto* h = Unwrap(info[0]);
|
|
422
|
+
if (!h || !h->image) {
|
|
423
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
424
|
+
return env.Null();
|
|
425
|
+
}
|
|
426
|
+
const bool clear = info.Length() >= 2 && info[1].ToBoolean().Value();
|
|
427
|
+
gerbv_layer_t* layer =
|
|
428
|
+
EnsurePolarity(h->image, clear ? GERBV_POLARITY_CLEAR : GERBV_POLARITY_DARK);
|
|
429
|
+
if (!layer) {
|
|
430
|
+
Napi::Error::New(env, "empty netlist").ThrowAsJavaScriptException();
|
|
431
|
+
return env.Null();
|
|
432
|
+
}
|
|
433
|
+
auto* poly = new PolygonHandle();
|
|
434
|
+
poly->owner = h;
|
|
435
|
+
poly->image = h->image;
|
|
436
|
+
poly->layer = layer;
|
|
437
|
+
return PolygonExt::New(env, poly, FreePolygon);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** addPolygonLine(polygon, x, y) — 首点为起点,其后为直线边 */
|
|
441
|
+
Napi::Value AddPolygonLine(const Napi::CallbackInfo& info) {
|
|
442
|
+
Napi::Env env = info.Env();
|
|
443
|
+
if (info.Length() < 3) {
|
|
444
|
+
Napi::TypeError::New(env, "addPolygonLine(polygon, x, y)")
|
|
445
|
+
.ThrowAsJavaScriptException();
|
|
446
|
+
return env.Undefined();
|
|
447
|
+
}
|
|
448
|
+
auto* p = UnwrapPoly(info[0]);
|
|
449
|
+
if (!p || !p->image) {
|
|
450
|
+
Napi::Error::New(env, "invalid polygon").ThrowAsJavaScriptException();
|
|
451
|
+
return env.Undefined();
|
|
452
|
+
}
|
|
453
|
+
const double x = ToInch(p, info[1].As<Napi::Number>().DoubleValue());
|
|
454
|
+
const double y = ToInch(p, info[2].As<Napi::Number>().DoubleValue());
|
|
455
|
+
if (!p->hasPoint) {
|
|
456
|
+
if (!PolyEnsureStart(p, x, y, env)) return env.Undefined();
|
|
457
|
+
return env.Undefined();
|
|
458
|
+
}
|
|
459
|
+
PolyAppendLine(p, x, y, true);
|
|
460
|
+
return env.Undefined();
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** addPolygonArc(polygon, cx, cy, x, y, clockwise?=false) */
|
|
464
|
+
Napi::Value AddPolygonArc(const Napi::CallbackInfo& info) {
|
|
465
|
+
Napi::Env env = info.Env();
|
|
466
|
+
if (info.Length() < 5) {
|
|
467
|
+
Napi::TypeError::New(env, "addPolygonArc(polygon, cx, cy, x, y, clockwise?=false)")
|
|
468
|
+
.ThrowAsJavaScriptException();
|
|
469
|
+
return env.Undefined();
|
|
470
|
+
}
|
|
471
|
+
auto* p = UnwrapPoly(info[0]);
|
|
472
|
+
if (!p || !p->image) {
|
|
473
|
+
Napi::Error::New(env, "invalid polygon").ThrowAsJavaScriptException();
|
|
474
|
+
return env.Undefined();
|
|
475
|
+
}
|
|
476
|
+
if (!p->hasPoint) {
|
|
477
|
+
Napi::Error::New(env, "addPolygonArc needs a start point first")
|
|
478
|
+
.ThrowAsJavaScriptException();
|
|
479
|
+
return env.Undefined();
|
|
480
|
+
}
|
|
481
|
+
if (p->finished) {
|
|
482
|
+
Napi::Error::New(env, "polygon already ended").ThrowAsJavaScriptException();
|
|
483
|
+
return env.Undefined();
|
|
484
|
+
}
|
|
485
|
+
const double cx = ToInch(p, info[1].As<Napi::Number>().DoubleValue());
|
|
486
|
+
const double cy = ToInch(p, info[2].As<Napi::Number>().DoubleValue());
|
|
487
|
+
const double x = ToInch(p, info[3].As<Napi::Number>().DoubleValue());
|
|
488
|
+
const double y = ToInch(p, info[4].As<Napi::Number>().DoubleValue());
|
|
489
|
+
const bool cw = info.Length() >= 6 && info[5].ToBoolean().Value();
|
|
490
|
+
PolyAppendArc(p, cx, cy, x, y, cw);
|
|
491
|
+
return env.Undefined();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
bool PolyReadyForEdge(PolygonHandle* p, Napi::Env env, const char* api) {
|
|
495
|
+
if (!p || !p->image) {
|
|
496
|
+
Napi::Error::New(env, "invalid polygon").ThrowAsJavaScriptException();
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
if (!p->hasPoint) {
|
|
500
|
+
Napi::Error::New(env, std::string(api) + " needs a start point first")
|
|
501
|
+
.ThrowAsJavaScriptException();
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
if (p->finished) {
|
|
505
|
+
Napi::Error::New(env, "polygon already ended").ThrowAsJavaScriptException();
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** addPolygonBezier2(polygon, c1x, c1y, x, y) — 二次贝塞尔边(本侧采样) */
|
|
512
|
+
Napi::Value AddPolygonBezier2(const Napi::CallbackInfo& info) {
|
|
513
|
+
Napi::Env env = info.Env();
|
|
514
|
+
if (info.Length() < 5) {
|
|
515
|
+
Napi::TypeError::New(env, "addPolygonBezier2(polygon, c1x, c1y, x, y)")
|
|
516
|
+
.ThrowAsJavaScriptException();
|
|
517
|
+
return env.Undefined();
|
|
518
|
+
}
|
|
519
|
+
auto* p = UnwrapPoly(info[0]);
|
|
520
|
+
if (!PolyReadyForEdge(p, env, "addPolygonBezier2")) return env.Undefined();
|
|
521
|
+
const double c1x = ToInch(p, info[1].As<Napi::Number>().DoubleValue());
|
|
522
|
+
const double c1y = ToInch(p, info[2].As<Napi::Number>().DoubleValue());
|
|
523
|
+
const double x = ToInch(p, info[3].As<Napi::Number>().DoubleValue());
|
|
524
|
+
const double y = ToInch(p, info[4].As<Napi::Number>().DoubleValue());
|
|
525
|
+
PolyAppendBezierSampled(p, c1x, c1y, c1x, c1y, x, y, false, 16);
|
|
526
|
+
return env.Undefined();
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** addPolygonBezier3(polygon, c1x, c1y, c2x, c2y, x, y) — 三次贝塞尔边(本侧采样) */
|
|
530
|
+
Napi::Value AddPolygonBezier3(const Napi::CallbackInfo& info) {
|
|
531
|
+
Napi::Env env = info.Env();
|
|
532
|
+
if (info.Length() < 7) {
|
|
533
|
+
Napi::TypeError::New(env, "addPolygonBezier3(polygon, c1x, c1y, c2x, c2y, x, y)")
|
|
534
|
+
.ThrowAsJavaScriptException();
|
|
535
|
+
return env.Undefined();
|
|
536
|
+
}
|
|
537
|
+
auto* p = UnwrapPoly(info[0]);
|
|
538
|
+
if (!PolyReadyForEdge(p, env, "addPolygonBezier3")) return env.Undefined();
|
|
539
|
+
const double c1x = ToInch(p, info[1].As<Napi::Number>().DoubleValue());
|
|
540
|
+
const double c1y = ToInch(p, info[2].As<Napi::Number>().DoubleValue());
|
|
541
|
+
const double c2x = ToInch(p, info[3].As<Napi::Number>().DoubleValue());
|
|
542
|
+
const double c2y = ToInch(p, info[4].As<Napi::Number>().DoubleValue());
|
|
543
|
+
const double x = ToInch(p, info[5].As<Napi::Number>().DoubleValue());
|
|
544
|
+
const double y = ToInch(p, info[6].As<Napi::Number>().DoubleValue());
|
|
545
|
+
PolyAppendBezierSampled(p, c1x, c1y, c2x, c2y, x, y, true, 20);
|
|
546
|
+
return env.Undefined();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/** endPolygon(polygon) — 自动闭合并写 G37 */
|
|
550
|
+
Napi::Value EndPolygon(const Napi::CallbackInfo& info) {
|
|
551
|
+
Napi::Env env = info.Env();
|
|
552
|
+
if (info.Length() < 1) {
|
|
553
|
+
Napi::TypeError::New(env, "endPolygon(polygon)").ThrowAsJavaScriptException();
|
|
554
|
+
return env.Undefined();
|
|
555
|
+
}
|
|
556
|
+
auto* p = UnwrapPoly(info[0]);
|
|
557
|
+
if (!p || !p->image) {
|
|
558
|
+
Napi::Error::New(env, "invalid polygon").ThrowAsJavaScriptException();
|
|
559
|
+
return env.Undefined();
|
|
560
|
+
}
|
|
561
|
+
if (p->finished) return env.Undefined();
|
|
562
|
+
if (!p->hasPoint) {
|
|
563
|
+
Napi::Error::New(env, "empty polygon").ThrowAsJavaScriptException();
|
|
564
|
+
return env.Undefined();
|
|
565
|
+
}
|
|
566
|
+
if (std::fabs(p->curX - p->startX) > 1e-9 || std::fabs(p->curY - p->startY) > 1e-9) {
|
|
567
|
+
PolyAppendLine(p, p->startX, p->startY, true);
|
|
568
|
+
}
|
|
569
|
+
gerbv_net_t* currentNet = LastNet(p->image);
|
|
570
|
+
currentNet = gerber_create_new_net(currentNet, p->layer, nullptr);
|
|
571
|
+
currentNet->interpolation = GERBV_INTERPOLATION_PAREA_END;
|
|
572
|
+
p->finished = true;
|
|
573
|
+
return env.Undefined();
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
void StrokeBezierSampled(
|
|
577
|
+
gerbv_image_t* image, double x1, double y1, double c1x, double c1y, double c2x,
|
|
578
|
+
double c2y, double x2, double y2, double w, bool cubic, int steps) {
|
|
579
|
+
const int n = std::max(4, steps);
|
|
580
|
+
double px = x1, py = y1;
|
|
581
|
+
for (int i = 1; i <= n; i++) {
|
|
582
|
+
const double t = static_cast<double>(i) / n;
|
|
583
|
+
const double u = 1.0 - t;
|
|
584
|
+
double x, y;
|
|
585
|
+
if (cubic) {
|
|
586
|
+
x = u * u * u * x1 + 3 * u * u * t * c1x + 3 * u * t * t * c2x + t * t * t * x2;
|
|
587
|
+
y = u * u * u * y1 + 3 * u * u * t * c1y + 3 * u * t * t * c2y + t * t * t * y2;
|
|
588
|
+
} else {
|
|
589
|
+
x = u * u * x1 + 2 * u * t * c1x + t * t * x2;
|
|
590
|
+
y = u * u * y1 + 2 * u * t * c1y + t * t * y2;
|
|
591
|
+
}
|
|
592
|
+
gerbv_image_create_line_object(image, px, py, x, y, w, GERBV_APTYPE_CIRCLE);
|
|
593
|
+
px = x;
|
|
594
|
+
py = y;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** addBezier2(image, x1,y1, c1x,c1y, x2,y2, widthInch) — 二次描边 */
|
|
599
|
+
Napi::Value AddBezier2(const Napi::CallbackInfo& info) {
|
|
600
|
+
Napi::Env env = info.Env();
|
|
601
|
+
if (info.Length() < 8) {
|
|
602
|
+
Napi::TypeError::New(env, "addBezier2(image, x1,y1, c1x,c1y, x2,y2, widthInch)")
|
|
603
|
+
.ThrowAsJavaScriptException();
|
|
604
|
+
return env.Undefined();
|
|
605
|
+
}
|
|
606
|
+
auto* h = Unwrap(info[0]);
|
|
607
|
+
if (!h || !h->image) {
|
|
608
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
609
|
+
return env.Undefined();
|
|
610
|
+
}
|
|
611
|
+
EnsurePolarity(h->image, GERBV_POLARITY_DARK);
|
|
612
|
+
const double c1x = ToInch(h, info[3].As<Napi::Number>().DoubleValue());
|
|
613
|
+
const double c1y = ToInch(h, info[4].As<Napi::Number>().DoubleValue());
|
|
614
|
+
StrokeBezierSampled(
|
|
615
|
+
h->image, ToInch(h, info[1].As<Napi::Number>().DoubleValue()),
|
|
616
|
+
ToInch(h, info[2].As<Napi::Number>().DoubleValue()), c1x, c1y, c1x, c1y,
|
|
617
|
+
ToInch(h, info[5].As<Napi::Number>().DoubleValue()),
|
|
618
|
+
ToInch(h, info[6].As<Napi::Number>().DoubleValue()),
|
|
619
|
+
ToInch(h, info[7].As<Napi::Number>().DoubleValue()), false, 16);
|
|
620
|
+
return env.Undefined();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** addBezier3(image, x1,y1, c1x,c1y, c2x,c2y, x2,y2, width) — 三次描边 */
|
|
624
|
+
Napi::Value AddBezier3(const Napi::CallbackInfo& info) {
|
|
625
|
+
Napi::Env env = info.Env();
|
|
626
|
+
if (info.Length() < 10) {
|
|
627
|
+
Napi::TypeError::New(
|
|
628
|
+
env, "addBezier3(image, x1,y1, c1x,c1y, c2x,c2y, x2,y2, width)")
|
|
629
|
+
.ThrowAsJavaScriptException();
|
|
630
|
+
return env.Undefined();
|
|
631
|
+
}
|
|
632
|
+
auto* h = Unwrap(info[0]);
|
|
633
|
+
if (!h || !h->image) {
|
|
634
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
635
|
+
return env.Undefined();
|
|
636
|
+
}
|
|
637
|
+
EnsurePolarity(h->image, GERBV_POLARITY_DARK);
|
|
638
|
+
StrokeBezierSampled(
|
|
639
|
+
h->image, ToInch(h, info[1].As<Napi::Number>().DoubleValue()),
|
|
640
|
+
ToInch(h, info[2].As<Napi::Number>().DoubleValue()),
|
|
641
|
+
ToInch(h, info[3].As<Napi::Number>().DoubleValue()),
|
|
642
|
+
ToInch(h, info[4].As<Napi::Number>().DoubleValue()),
|
|
643
|
+
ToInch(h, info[5].As<Napi::Number>().DoubleValue()),
|
|
644
|
+
ToInch(h, info[6].As<Napi::Number>().DoubleValue()),
|
|
645
|
+
ToInch(h, info[7].As<Napi::Number>().DoubleValue()),
|
|
646
|
+
ToInch(h, info[8].As<Napi::Number>().DoubleValue()),
|
|
647
|
+
ToInch(h, info[9].As<Napi::Number>().DoubleValue()), true, 20);
|
|
648
|
+
return env.Undefined();
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
std::string ReadFileBytes(const char* path) {
|
|
652
|
+
FILE* f = std::fopen(path, "rb");
|
|
653
|
+
if (!f) return {};
|
|
654
|
+
std::fseek(f, 0, SEEK_END);
|
|
655
|
+
long n = std::ftell(f);
|
|
656
|
+
std::fseek(f, 0, SEEK_SET);
|
|
657
|
+
if (n <= 0) {
|
|
658
|
+
std::fclose(f);
|
|
659
|
+
return {};
|
|
660
|
+
}
|
|
661
|
+
std::string out(static_cast<size_t>(n), '\0');
|
|
662
|
+
const size_t got = std::fread(out.data(), 1, static_cast<size_t>(n), f);
|
|
663
|
+
std::fclose(f);
|
|
664
|
+
out.resize(got);
|
|
665
|
+
return out;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
std::string TempPath(const char* suffix) {
|
|
669
|
+
static unsigned counter = 0;
|
|
670
|
+
const auto name =
|
|
671
|
+
"hqpcb-gerbv-" + std::to_string(getpid()) + "-" +
|
|
672
|
+
std::to_string(counter++) + suffix;
|
|
673
|
+
return (std::filesystem::temp_directory_path() / name).string();
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
Napi::Value ExportRs274x(const Napi::CallbackInfo& info) {
|
|
677
|
+
Napi::Env env = info.Env();
|
|
678
|
+
if (info.Length() < 1) {
|
|
679
|
+
Napi::TypeError::New(env, "exportRs274x(image)").ThrowAsJavaScriptException();
|
|
680
|
+
return env.Null();
|
|
681
|
+
}
|
|
682
|
+
auto* h = Unwrap(info[0]);
|
|
683
|
+
if (!h || !h->image) {
|
|
684
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
685
|
+
return env.Null();
|
|
686
|
+
}
|
|
687
|
+
const std::string path = TempPath(".gbr");
|
|
688
|
+
if (!gerbv_export_rs274x_file_from_image(path.c_str(), h->image, nullptr)) {
|
|
689
|
+
Napi::Error::New(env, "gerbv_export_rs274x_file_from_image failed").ThrowAsJavaScriptException();
|
|
690
|
+
return env.Null();
|
|
691
|
+
}
|
|
692
|
+
std::string data = ReadFileBytes(path.c_str());
|
|
693
|
+
std::remove(path.c_str());
|
|
694
|
+
return Napi::Buffer<char>::Copy(env, data.data(), data.size());
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
Napi::Value ExportDrill(const Napi::CallbackInfo& info) {
|
|
698
|
+
Napi::Env env = info.Env();
|
|
699
|
+
if (info.Length() < 1) {
|
|
700
|
+
Napi::TypeError::New(env, "exportDrill(image)").ThrowAsJavaScriptException();
|
|
701
|
+
return env.Null();
|
|
702
|
+
}
|
|
703
|
+
auto* h = Unwrap(info[0]);
|
|
704
|
+
if (!h || !h->image) {
|
|
705
|
+
Napi::Error::New(env, "invalid image").ThrowAsJavaScriptException();
|
|
706
|
+
return env.Null();
|
|
707
|
+
}
|
|
708
|
+
const std::string path = TempPath(".drl");
|
|
709
|
+
if (!gerbv_export_drill_file_from_image(path.c_str(), h->image, nullptr)) {
|
|
710
|
+
Napi::Error::New(env, "gerbv_export_drill_file_from_image failed").ThrowAsJavaScriptException();
|
|
711
|
+
return env.Null();
|
|
712
|
+
}
|
|
713
|
+
std::string data = ReadFileBytes(path.c_str());
|
|
714
|
+
std::remove(path.c_str());
|
|
715
|
+
return Napi::Buffer<char>::Copy(env, data.data(), data.size());
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
719
|
+
exports.Set("createImage", Napi::Function::New(env, CreateImage));
|
|
720
|
+
exports.Set("addLine", Napi::Function::New(env, AddLine));
|
|
721
|
+
exports.Set("addArc", Napi::Function::New(env, AddArc));
|
|
722
|
+
exports.Set("addBezier2", Napi::Function::New(env, AddBezier2));
|
|
723
|
+
exports.Set("addBezier3", Napi::Function::New(env, AddBezier3));
|
|
724
|
+
exports.Set("addFlashCircle", Napi::Function::New(env, AddFlashCircle));
|
|
725
|
+
exports.Set("addRect", Napi::Function::New(env, AddRect));
|
|
726
|
+
exports.Set("createPolygon", Napi::Function::New(env, CreatePolygon));
|
|
727
|
+
exports.Set("addPolygonLine", Napi::Function::New(env, AddPolygonLine));
|
|
728
|
+
exports.Set("addPolygonArc", Napi::Function::New(env, AddPolygonArc));
|
|
729
|
+
exports.Set("addPolygonBezier2", Napi::Function::New(env, AddPolygonBezier2));
|
|
730
|
+
exports.Set("addPolygonBezier3", Napi::Function::New(env, AddPolygonBezier3));
|
|
731
|
+
exports.Set("endPolygon", Napi::Function::New(env, EndPolygon));
|
|
732
|
+
exports.Set("exportRs274x", Napi::Function::New(env, ExportRs274x));
|
|
733
|
+
exports.Set("exportDrill", Napi::Function::New(env, ExportDrill));
|
|
734
|
+
exports.Set("backend", Napi::String::New(env, "libgerbv"));
|
|
735
|
+
return exports;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
} // namespace
|
|
739
|
+
|
|
740
|
+
NODE_API_MODULE(gerbv_node, Init)
|