]> Shamusworld >> Repos - architektonas/blob - dxflib/test/main.cpp
Refactored CAD tool bars to use predefined actions.
[architektonas] / dxflib / test / main.cpp
1 /*
2  * @file main.cpp
3  */
4
5 /*****************************************************************************
6 **  $Id: main.cpp 2362 2005-04-04 14:56:33Z andrew $
7 **
8 **  This is part of the dxflib library
9 **  Copyright (C) 2000-2001 Andrew Mustun
10 **
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.
14 **
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.
19 **
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 ******************************************************************************/
24
25 #include <iostream>
26 #include <stdlib.h>
27 #include <stdio.h>
28
29 #include "dl_dxf.h"
30 #include "dl_creationadapter.h"
31
32 #include "test_creationclass.h"
33
34 void usage();
35 void testReading(char* file);
36 void testWriting();
37
38
39 /*
40  * @brief Main function for DXFLib test program.
41  *
42  * @param argc Number of delimited items on command line,
43  *              including program name.
44  * @param argv Pointer to array of command line items
45  *
46  * @retval 0 if missing input file argument or
47  *              file couldn't be opened
48  * @retval 1 if file opened
49  */
50 int main(int argc, char** argv) {
51
52     // Check given arguments:
53     if (argc<2) {
54         usage();
55         return 0;
56     }
57
58     testReading(argv[1]);
59
60     testWriting();
61
62     return 0;
63 }
64
65
66
67 /*
68  * @brief Prints error message if file name not specified as command
69  * line argument.
70  */
71 void usage() {
72     std::cout << "\nUsage: test <DXF file>\n\n";
73 }
74
75
76 void testReading(char* file) {
77     // Load DXF file into memory:
78     std::cout << "Reading file " << file << "...\n";
79     Test_CreationClass creationClass;
80     DL_Dxf dxf;
81     if (!dxf.in(file, &creationClass)) { // if file open failed
82         std::cerr << file << " could not be opened.\n";
83         return;
84     }
85 }
86
87
88
89 void testWriting() {
90 DL_Dxf dxf;
91 DL_Codes::version exportVersion = DL_Codes::AC1015;
92 DL_WriterA* dw = dxf.out("myfile.dxf", exportVersion);
93 if (dw==NULL) {
94     printf("Cannot open file 'myfile.dxf' \
95             for writing.");
96     // abort function e.g. with return
97 }
98 dxf.writeHeader(*dw);
99 // int variable:
100 dw->dxfString(9, "$INSUNITS");
101 dw->dxfInt(70, 4);
102 // real (double, float) variable:
103 dw->dxfString(9, "$DIMEXE");
104 dw->dxfReal(40, 1.25);
105 // string variable:
106 dw->dxfString(9, "$TEXTSTYLE");
107 dw->dxfString(7, "Standard");
108 // vector variable:
109 dw->dxfString(9, "$LIMMIN");
110 dw->dxfReal(10, 0.0);
111 dw->dxfReal(20, 0.0);
112 dw->sectionEnd();
113 dw->sectionTables();
114 dxf.writeVPort(*dw);
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));
148 dw->tableEnd();
149 int numberOfLayers = 3;
150 dw->tableLayers(numberOfLayers);
151
152 dxf.writeLayer(*dw, 
153     DL_LayerData("0", 0), 
154     DL_Attributes(
155         std::string(""),      // leave empty
156         DL_Codes::black,        // default color
157         100,                  // default width
158         "CONTINUOUS"));       // default line style
159
160 dxf.writeLayer(*dw, 
161     DL_LayerData("mainlayer", 0), 
162     DL_Attributes(
163         std::string(""),
164         DL_Codes::red,
165         100,
166         "CONTINUOUS"));
167
168 dxf.writeLayer(*dw, 
169     DL_LayerData("anotherlayer", 0), 
170     DL_Attributes(
171         std::string(""),
172         DL_Codes::black,
173         100,
174         "CONTINUOUS"));
175
176 dw->tableEnd();
177 dxf.writeStyle(*dw);
178 dxf.writeView(*dw);
179 dxf.writeUcs(*dw);
180
181 dw->tableAppid(1);
182 dw->tableAppidEntry(0x12);
183 dw->dxfString(2, "ACAD");
184 dw->dxfInt(70, 0);
185 dw->tableEnd();
186 dxf.writeDimStyle(*dw, 
187     1, 
188     1, 
189     1, 
190     1, 
191     1);
192 dxf.writeBlockRecord(*dw);
193 dxf.writeBlockRecord(*dw, "myblock1");
194 dxf.writeBlockRecord(*dw, "myblock2");
195 dw->tableEnd();
196 dw->sectionEnd();
197 dw->sectionBlocks();
198
199 dxf.writeBlock(*dw, 
200     DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
201 dxf.writeEndBlock(*dw, "*Model_Space");
202
203 dxf.writeBlock(*dw, 
204     DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
205 dxf.writeEndBlock(*dw, "*Paper_Space");
206
207 dxf.writeBlock(*dw, 
208     DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
209 dxf.writeEndBlock(*dw, "*Paper_Space0");
210
211 dxf.writeBlock(*dw,
212     DL_BlockData("myblock1", 0, 0.0, 0.0, 0.0));
213 // ...
214 // write block entities e.g. with dxf.writeLine(), ..
215 // ...
216 dxf.writeEndBlock(*dw, "myblock1");
217
218 dxf.writeBlock(*dw,
219     DL_BlockData("myblock2", 0, 0.0, 0.0, 0.0));
220 // ...
221 // write block entities e.g. with dxf.writeLine(), ..
222 // ...
223 dxf.writeEndBlock(*dw, "myblock2");
224
225 dw->sectionEnd();
226 dw->sectionEntities();
227
228 // write all your entities..
229 dxf.writePoint(
230     *dw,
231     DL_PointData(10.0,
232                  45.0,
233                   0.0),
234     DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
235
236 dxf.writeLine(
237     *dw,
238     DL_LineData(25.0,   // start point
239                 30.0,
240                  0.0,
241                100.0,   // end point
242                120.0,
243                  0.0),
244     DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
245
246 dw->sectionEnd();
247 dxf.writeObjects(*dw);
248 dxf.writeObjectsEnd(*dw);
249 dw->dxfEOF();
250 dw->close();
251 delete dw;
252
253 /*
254     DL_Dxf dxf;
255     DL_Codes::version exportVersion = DL_Codes::AC1015;
256     DL_WriterA* dw = dxf.out("myfile.dxf", exportVersion);
257     if (dw==NULL) {
258         printf("Cannot open file 'myfile.dxf' \
259                for writing.");
260         // abort function e.g. with return
261     }
262     dxf.writeHeader(*dw);
263     // int variable:
264     dw->dxfString(9, "$INSUNITS");
265     dw->dxfInt(70, 4);
266     // real (double, float) variable:
267     dw->dxfString(9, "$DIMEXE");
268     dw->dxfReal(40, 1.25);
269     // string variable:
270     dw->dxfString(9, "$TEXTSTYLE");
271     dw->dxfString(7, "Standard");
272     // vector variable:
273     dw->dxfString(9, "$LIMMIN");
274     dw->dxfReal(10, 0.0);
275     dw->dxfReal(20, 0.0);
276     dw->sectionEnd();
277     dw->sectionTables();
278     dxf.writeVPort(*dw);
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));
312     dw->tableEnd();
313     int numberOfLayers = 3;
314     dw->tableLayers(numberOfLayers);
315     
316         dxf.writeLayer(*dw,
317                    DL_LayerData("0", 0),
318                    DL_Attributes(
319                        std::string(""),      // leave empty
320                        DL_Codes::red,        // default color
321                        100,                  // default width
322                        "CONTINUOUS"));       // default line style
323
324     dxf.writeLayer(*dw,
325                    DL_LayerData("mainlayer", 0),
326                    DL_Attributes(
327                        std::string(""),      // leave empty
328                        DL_Codes::red,        // default color
329                        100,                  // default width
330                        "CONTINUOUS"));       // default line style
331
332     dxf.writeLayer(*dw,
333                    DL_LayerData("anotherlayer", 0),
334                    DL_Attributes(
335                        std::string(""),
336                        DL_Codes::black,
337                        100,
338                        "CONTINUOUS"));
339
340     dw->tableEnd();
341     dxf.writeStyle(*dw);
342     dxf.writeView(*dw);
343     dxf.writeUcs(*dw);
344
345     dw->tableAppid(1);
346     dw->tableAppidEntry(0x12);
347     dw->dxfString(2, "ACAD");
348     dw->dxfInt(70, 0);
349     dw->tableEnd();
350     dxf.writeDimStyle(*dw,
351                       2.5,
352                       1.25,
353                       0.625,
354                       0.625,
355                       2.5);
356     dxf.writeBlockRecord(*dw);
357     dxf.writeBlockRecord(*dw, "myblock1");
358     dxf.writeBlockRecord(*dw, "myblock2");
359     dw->tableEnd();
360     dw->sectionEnd();
361
362         dw->sectionBlocks();
363         dxf.writeBlock(*dw, 
364             DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
365         dxf.writeEndBlock(*dw, "*Model_Space");
366         dxf.writeBlock(*dw, 
367             DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
368         dxf.writeEndBlock(*dw, "*Paper_Space");
369         dxf.writeBlock(*dw, 
370             DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
371         dxf.writeEndBlock(*dw, "*Paper_Space0");
372         dxf.writeBlock(*dw,
373             DL_BlockData("myblock1", 0, 0.0, 0.0, 0.0));
374     // ...
375     // write block entities e.g. with dxf.writeLine(), ..
376     // ...
377     dxf.writeEndBlock(*dw, "myblock1");
378         dxf.writeBlock(*dw,
379             DL_BlockData("myblock2", 0, 0.0, 0.0, 0.0));
380     // ...
381     // write block entities e.g. with dxf.writeLine(), ..
382     // ...
383     dxf.writeEndBlock(*dw, "myblock2");
384     dw->sectionEnd();
385     dw->sectionEntities();
386
387     // write all your entities..
388     dxf.writePoint(
389         *dw,
390         DL_PointData(10.0,
391                      45.0,
392                      0.0),
393         DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
394
395     dxf.writeLine(
396         *dw,
397         DL_LineData(25.0,   // start point
398                     30.0,
399                     0.0,
400                     100.0,   // end point
401                     120.0,
402                     0.0),
403         DL_Attributes("mainlayer", 256, -1, "BYLAYER"));
404
405     dw->sectionEnd();
406     dxf.writeObjects(*dw);
407     dxf.writeObjectsEnd(*dw);
408     dw->dxfEOF();
409     dw->close();
410     delete dw;
411 */
412 }
413
414 // EOF