5 /*****************************************************************************
6 ** $Id: main.cpp 2362 2005-04-04 14:56:33Z andrew $
8 ** This is part of the dxflib library
9 ** Copyright (C) 2000-2001 Andrew Mustun
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU Library General Public License as
13 ** published by the Free Software Foundation.
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU Library General Public License for more details.
20 ** You should have received a copy of the GNU Library General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ******************************************************************************/
30 #include "dl_creationadapter.h"
32 #include "test_creationclass.h"
35 void testReading(char* file);
40 * @brief Main function for DXFLib test program.
42 * @param argc Number of delimited items on command line,
43 * including program name.
44 * @param argv Pointer to array of command line items
46 * @retval 0 if missing input file argument or
47 * file couldn't be opened
48 * @retval 1 if file opened
50 int main(int argc, char** argv) {
52 // Check given arguments:
68 * @brief Prints error message if file name not specified as command
72 std::cout << "\nUsage: test <DXF file>\n\n";
76 void testReading(char* file) {
77 // Load DXF file into memory:
78 std::cout << "Reading file " << file << "...\n";
79 Test_CreationClass creationClass;
81 if (!dxf.in(file, &creationClass)) { // if file open failed
82 std::cerr << file << " could not be opened.\n";
91 DL_Codes::version exportVersion = DL_Codes::AC1015;
92 DL_WriterA* dw = dxf.out("myfile.dxf", exportVersion);
94 printf("Cannot open file 'myfile.dxf' \
96 // abort function e.g. with return
100 dw->dxfString(9, "$INSUNITS");
102 // real (double, float) variable:
103 dw->dxfString(9, "$DIMEXE");
104 dw->dxfReal(40, 1.25);
106 dw->dxfString(9, "$TEXTSTYLE");
107 dw->dxfString(7, "Standard");
109 dw->dxfString(9, "$LIMMIN");
110 dw->dxfReal(10, 0.0);
111 dw->dxfReal(20, 0.0);
115 dw->tableLineTypes(25);
116 dxf.writeLineType(*dw, DL_LineTypeData("BYBLOCK", 0));
117 dxf.writeLineType(*dw, DL_LineTypeData("BYLAYER", 0));
118 dxf.writeLineType(*dw,
119 DL_LineTypeData("CONTINUOUS", 0));
120 dxf.writeLineType(*dw,
121 DL_LineTypeData("ACAD_ISO02W100", 0));
122 dxf.writeLineType(*dw,
123 DL_LineTypeData("ACAD_ISO03W100", 0));
124 dxf.writeLineType(*dw,
125 DL_LineTypeData("ACAD_ISO04W100", 0));
126 dxf.writeLineType(*dw,
127 DL_LineTypeData("ACAD_ISO05W100", 0));
128 dxf.writeLineType(*dw, DL_LineTypeData("BORDER", 0));
129 dxf.writeLineType(*dw, DL_LineTypeData("BORDER2", 0));
130 dxf.writeLineType(*dw, DL_LineTypeData("BORDERX2", 0));
131 dxf.writeLineType(*dw, DL_LineTypeData("CENTER", 0));
132 dxf.writeLineType(*dw, DL_LineTypeData("CENTER2", 0));
133 dxf.writeLineType(*dw, DL_LineTypeData("CENTERX2", 0));
134 dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT", 0));
135 dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT2", 0));
136 dxf.writeLineType(*dw,
137 DL_LineTypeData("DASHDOTX2", 0));
138 dxf.writeLineType(*dw, DL_LineTypeData("DASHED", 0));
139 dxf.writeLineType(*dw, DL_LineTypeData("DASHED2", 0));
140 dxf.writeLineType(*dw, DL_LineTypeData("DASHEDX2", 0));
141 dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE", 0));
142 dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE2", 0));
143 dxf.writeLineType(*dw,
144 DL_LineTypeData("DIVIDEX2", 0));
145 dxf.writeLineType(*dw, DL_LineTypeData("DOT", 0));
146 dxf.writeLineType(*dw, DL_LineTypeData("DOT2", 0));
147 dxf.writeLineType(*dw, DL_LineTypeData("DOTX2", 0));
149 int numberOfLayers = 3;
150 dw->tableLayers(numberOfLayers);
153 DL_LayerData("0", 0),
155 std::string(""), // leave empty
156 DL_Codes::black, // default color
157 100, // default width
158 "CONTINUOUS")); // default line style
161 DL_LayerData("mainlayer", 0),
169 DL_LayerData("anotherlayer", 0),
182 dw->tableAppidEntry(0x12);
183 dw->dxfString(2, "ACAD");
186 dxf.writeDimStyle(*dw,
192 dxf.writeBlockRecord(*dw);
193 dxf.writeBlockRecord(*dw, "myblock1");
194 dxf.writeBlockRecord(*dw, "myblock2");
200 DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
201 dxf.writeEndBlock(*dw, "*Model_Space");
204 DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
205 dxf.writeEndBlock(*dw, "*Paper_Space");
208 DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
209 dxf.writeEndBlock(*dw, "*Paper_Space0");
212 DL_BlockData("myblock1", 0, 0.0, 0.0, 0.0));
214 // write block entities e.g. with dxf.writeLine(), ..
216 dxf.writeEndBlock(*dw, "myblock1");
219 DL_BlockData("myblock2", 0, 0.0, 0.0, 0.0));
221 // write block entities e.g. with dxf.writeLine(), ..
223 dxf.writeEndBlock(*dw, "myblock2");
226 dw->sectionEntities();
228 // write all your entities..
234 DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
238 DL_LineData(25.0, // start point
244 DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
247 dxf.writeObjects(*dw);
248 dxf.writeObjectsEnd(*dw);
255 DL_Codes::version exportVersion = DL_Codes::AC1015;
256 DL_WriterA* dw = dxf.out("myfile.dxf", exportVersion);
258 printf("Cannot open file 'myfile.dxf' \
260 // abort function e.g. with return
262 dxf.writeHeader(*dw);
264 dw->dxfString(9, "$INSUNITS");
266 // real (double, float) variable:
267 dw->dxfString(9, "$DIMEXE");
268 dw->dxfReal(40, 1.25);
270 dw->dxfString(9, "$TEXTSTYLE");
271 dw->dxfString(7, "Standard");
273 dw->dxfString(9, "$LIMMIN");
274 dw->dxfReal(10, 0.0);
275 dw->dxfReal(20, 0.0);
279 dw->tableLineTypes(25);
280 dxf.writeLineType(*dw, DL_LineTypeData("BYBLOCK", 0));
281 dxf.writeLineType(*dw, DL_LineTypeData("BYLAYER", 0));
282 dxf.writeLineType(*dw,
283 DL_LineTypeData("CONTINUOUS", 0));
284 dxf.writeLineType(*dw,
285 DL_LineTypeData("ACAD_ISO02W100", 0));
286 dxf.writeLineType(*dw,
287 DL_LineTypeData("ACAD_ISO03W100", 0));
288 dxf.writeLineType(*dw,
289 DL_LineTypeData("ACAD_ISO04W100", 0));
290 dxf.writeLineType(*dw,
291 DL_LineTypeData("ACAD_ISO05W100", 0));
292 dxf.writeLineType(*dw, DL_LineTypeData("BORDER", 0));
293 dxf.writeLineType(*dw, DL_LineTypeData("BORDER2", 0));
294 dxf.writeLineType(*dw, DL_LineTypeData("BORDERX2", 0));
295 dxf.writeLineType(*dw, DL_LineTypeData("CENTER", 0));
296 dxf.writeLineType(*dw, DL_LineTypeData("CENTER2", 0));
297 dxf.writeLineType(*dw, DL_LineTypeData("CENTERX2", 0));
298 dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT", 0));
299 dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT2", 0));
300 dxf.writeLineType(*dw,
301 DL_LineTypeData("DASHDOTX2", 0));
302 dxf.writeLineType(*dw, DL_LineTypeData("DASHED", 0));
303 dxf.writeLineType(*dw, DL_LineTypeData("DASHED2", 0));
304 dxf.writeLineType(*dw, DL_LineTypeData("DASHEDX2", 0));
305 dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE", 0));
306 dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE2", 0));
307 dxf.writeLineType(*dw,
308 DL_LineTypeData("DIVIDEX2", 0));
309 dxf.writeLineType(*dw, DL_LineTypeData("DOT", 0));
310 dxf.writeLineType(*dw, DL_LineTypeData("DOT2", 0));
311 dxf.writeLineType(*dw, DL_LineTypeData("DOTX2", 0));
313 int numberOfLayers = 3;
314 dw->tableLayers(numberOfLayers);
317 DL_LayerData("0", 0),
319 std::string(""), // leave empty
320 DL_Codes::red, // default color
321 100, // default width
322 "CONTINUOUS")); // default line style
325 DL_LayerData("mainlayer", 0),
327 std::string(""), // leave empty
328 DL_Codes::red, // default color
329 100, // default width
330 "CONTINUOUS")); // default line style
333 DL_LayerData("anotherlayer", 0),
346 dw->tableAppidEntry(0x12);
347 dw->dxfString(2, "ACAD");
350 dxf.writeDimStyle(*dw,
356 dxf.writeBlockRecord(*dw);
357 dxf.writeBlockRecord(*dw, "myblock1");
358 dxf.writeBlockRecord(*dw, "myblock2");
364 DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
365 dxf.writeEndBlock(*dw, "*Model_Space");
367 DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
368 dxf.writeEndBlock(*dw, "*Paper_Space");
370 DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
371 dxf.writeEndBlock(*dw, "*Paper_Space0");
373 DL_BlockData("myblock1", 0, 0.0, 0.0, 0.0));
375 // write block entities e.g. with dxf.writeLine(), ..
377 dxf.writeEndBlock(*dw, "myblock1");
379 DL_BlockData("myblock2", 0, 0.0, 0.0, 0.0));
381 // write block entities e.g. with dxf.writeLine(), ..
383 dxf.writeEndBlock(*dw, "myblock2");
385 dw->sectionEntities();
387 // write all your entities..
393 DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
397 DL_LineData(25.0, // start point
403 DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
406 dxf.writeObjects(*dw);
407 dxf.writeObjectsEnd(*dw);