34 #include <dxflib/dl_dxf.h>
40 #define DL_STRGRP_END STRGRP_END
42 #ifndef DL_ATTFLAGS_CODE
43 #define DL_ATTFLAGS_CODE ATTFLAGS_CODE
46 #define DL_TXTHI_CODE TXTHI_CODE
48 #ifndef DL_TXT_STYLE_CODE
49 #define DL_TXT_STYLE_CODE TXT_STYLE_CODE
51 #ifndef DL_FIRST_XCOORD_CODE
52 #define DL_FIRST_XCOORD_CODE FIRST_XCOORD_CODE
54 #ifndef DL_FIRST_YCOORD_CODE
55 #define DL_FIRST_YCOORD_CODE FIRST_YCOORD_CODE
57 #ifndef DL_CLOSED_PLINE
58 #define DL_CLOSED_PLINE CLOSED_PLINE
78 DL_Codes::version exportVersion = DL_Codes::AC1015;
79 DL_Dxf* dxf =
new DL_Dxf();
81 gerbv_aperture_t* apert;
85 double x[4], y[4], r, dx, dy, nom;
88 dw = dxf->out(file_name, exportVersion);
91 GERB_MESSAGE(_(
"Can't open file for writing: %s"), file_name);
96 setlocale(LC_NUMERIC,
"C");
101 dxf->writeHeader(*dw);
103 dw->dxfString(DL_STRGRP_END,
"$INSUNITS");
104 dw->dxfInt(DL_ATTFLAGS_CODE, INSUNITS_INCH);
106 dw->dxfString(DL_STRGRP_END,
"$DIMEXE");
107 dw->dxfReal(DL_TXTHI_CODE, 1.25);
109 dw->dxfString(DL_STRGRP_END,
"$TEXTSTYLE");
110 dw->dxfString(DL_TXT_STYLE_CODE,
"Standard");
113 dw->dxfString(DL_STRGRP_END,
"$LIMMIN");
114 dw->dxfReal(DL_FIRST_XCOORD_CODE, 0.0);
115 dw->dxfReal(DL_FIRST_YCOORD_CODE, 0.0);
120 dxf->writeVPort(*dw);
123 #if (DL_VERSION_MAJOR == 3)
124 dw->tableLinetypes(1);
125 dxf->writeLinetype(*dw, DL_LinetypeData(
"ByLayer",
"ByLayer", 0, 0, 0));
127 dw->tableLineTypes(1);
128 dxf->writeLineType(*dw, DL_LineTypeData(
"ByLayer", 0));
136 #if (DL_VERSION_MAJOR == 3)
138 *dw, DL_LayerData(
"0", 0),
147 *dw, DL_LayerData(
"0", 0),
158 #if (DL_VERSION_MAJOR == 3)
159 dxf->writeStyle(*dw, DL_StyleData(
"Standard", 0, 2.5, 1.0, 0.0, 0, 2.5,
"txt",
""));
161 dxf->writeStyle(*dw);
167 dw->tableAppidEntry(0x12);
168 dw->dxfString(2,
"ACAD");
169 dw->dxfInt(DL_ATTFLAGS_CODE, 0);
174 dw->sectionEntities();
176 #if (DL_VERSION_MAJOR == 3)
177 DL_Attributes* attr =
new DL_Attributes(
"0", 0, -1,
"ByLayer", 1.0);
179 DL_Attributes* attr =
new DL_Attributes(
"0", 0, -1,
"ByLayer");
182 for (net = img->
netlist; net != NULL; net = net->
next) {
188 dxf->writePolyline(*dw, DL_PolylineData(1, 0, 0, DL_CLOSED_PLINE), *attr);
194 dxf->writeVertex(*dw, DL_VertexData(COORD2INS(net->
stop_x), COORD2INS(net->
stop_y), 0, 0));
199 dxf->writePolylineEnd(*dw);
206 switch (apert->type) {
210 r = apert->parameter[0] / 2;
211 dxf->writeCircle(*dw, DL_CircleData(x[0], y[0], 0.0, r), *attr);
214 x[0] = net->
stop_x + apert->parameter[0] / 2;
215 y[0] = net->
stop_y + apert->parameter[1] / 2;
217 y[1] = y[0] - apert->parameter[1];
218 x[2] = x[1] - apert->parameter[0];
222 dxf->writePolyline(*dw, DL_PolylineData(4, 0, 0, DL_CLOSED_PLINE), *attr);
223 for (i = 0; i < 4; i++)
224 dxf->writeVertex(*dw, DL_VertexData(x[i], y[i], 0, 0));
225 dxf->writePolylineEnd(*dw);
228 if (apert->parameter[0] > apert->parameter[1]) {
230 r = apert->parameter[1] / 2;
231 dx = apert->parameter[0] / 2 - r;
243 r = apert->parameter[0] / 2;
244 dy = apert->parameter[1] / 2 - r;
256 dxf->writePolyline(*dw, DL_PolylineData(4, 0, 0, DL_CLOSED_PLINE), *attr);
257 dxf->writeVertex(*dw, DL_VertexData(x[3], y[3], 0, -1));
258 dxf->writeVertex(*dw, DL_VertexData(x[0], y[0], 0, 0));
259 dxf->writeVertex(*dw, DL_VertexData(x[1], y[1], 0, -1));
260 dxf->writeVertex(*dw, DL_VertexData(x[2], y[2], 0, 0));
262 dxf->writePolylineEnd(*dw);
267 GERB_COMPILE_WARNING(
268 "%s:%d: aperture type %d is "
270 __func__, __LINE__, apert->type
277 switch (apert->type) {
282 nom = apert->parameter[0] / (2 * sqrt(dx * dx + dy * dy));
298 dxf->writePolyline(*dw, DL_PolylineData(4, 0, 0, DL_CLOSED_PLINE), *attr);
299 dxf->writeVertex(*dw, DL_VertexData(x[3], y[3], 0, -1));
300 dxf->writeVertex(*dw, DL_VertexData(x[0], y[0], 0, 0));
301 dxf->writeVertex(*dw, DL_VertexData(x[1], y[1], 0, -1));
302 dxf->writeVertex(*dw, DL_VertexData(x[2], y[2], 0, 0));
304 dxf->writePolylineEnd(*dw);
307 GERB_COMPILE_WARNING(
308 "%s:%d: aperture type %d is "
310 __func__, __LINE__, apert->type
323 dxf->writeObjects(*dw);
324 dxf->writeObjectsEnd(*dw);
332 setlocale(LC_NUMERIC,
"");
gboolean gerbv_export_dxf_file_from_image(const gchar *file_name, gerbv_image_t *input_img, gerbv_user_transformation_t *trans)
Export an image to a new file in DXF format.
void gerbv_destroy_image(gerbv_image_t *image)
Free an image structure.
gerbv_image_t * gerbv_image_duplicate_image(gerbv_image_t *sourceImage, gerbv_user_transformation_t *transform)
Duplicate an existing image and return the new copy.
The main header file for the libgerbv library.
@ GERBV_APERTURE_STATE_ON
@ GERBV_APERTURE_STATE_FLASH
@ GERBV_INTERPOLATION_PAREA_START
@ GERBV_INTERPOLATION_PAREA_END
gerbv_aperture_t * aperture[APERTURE_MAX]
gerbv_aperture_state_t aperture_state
gerbv_interpolation_t interpolation