~mc.../inkscape/inkscape

« back to all changes in this revision

Viewing changes to src/extension/dxf2svg/dxf2svg.cpp

  • Committer: mental
  • Date: 2006-01-16 02:36:01 UTC
  • Revision ID: mental@users.sourceforge.net-20060116023601-wkr0h7edl5veyudq
moving trunk for module inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Build a SVG from an dxf, will support conversion to Inkscape types
 
3
 *
 
4
 * Author:
 
5
 *   Matt Squires <squiresm@colorado.edu>
 
6
 *
 
7
 * Copyright (C) 2005 Matt Squires
 
8
 *
 
9
 * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details
 
10
 */
 
11
 
 
12
 
 
13
#include<fstream>
 
14
#include<iostream>
 
15
#include"read_dxf.h"
 
16
#include"entities.h"
 
17
#include"blocks.h"
 
18
#include"entities2elements.h"
 
19
 
 
20
 
 
21
 
 
22
 
 
23
 
 
24
 
 
25
 
 
26
 
 
27
int main(int argc,char *argv[]){
 
28
        // Later include options for different conversions like converting as much as possible into paths
 
29
        int ink = 1; // Assume for now there is no inkscape stuff to add extra
 
30
        
 
31
        if(argc > 1){
 
32
                double scaling = 90;  // converstion from in to pt
 
33
                
 
34
                // Read the DXF file
 
35
                std::vector< std::vector< dxfpair > >  output, entities_info, tables_info, blocks_info;
 
36
                //std::cout << "About to read file \n" << std::endl;
 
37
                output =  dxf_get_sections(argv[1]);
 
38
                //std::cout << "Finished reading file \n" << std::endl;
 
39
                
 
40
                entities_info = separate_parts(output[4]); // Entities is the 5th part of the file.
 
41
                entities ents(entities_info); // Sort entities into their respective parts
 
42
                
 
43
                tables_info = separate_parts(output[2]); // Tables is the 3rd part of a dxf file.
 
44
                tables tbls(tables_info);  // Sort the information in the tables
 
45
                        
 
46
                blocks_info = separate_parts(output[3]); // Tables is the 4th part of a dxf file.
 
47
                blocks blks(blocks_info);  // Sort the information in the tables
 
48
                
 
49
                
 
50
                
 
51
                // Get the various file informations
 
52
                /*std::vector< polyline > plines = ents.ret_plines();
 
53
                std::vector< lwpolyline > lwplines = ents.ret_lwplines();
 
54
                std::vector< arc > arcs = ents.ret_arcs();
 
55
                std::vector< circle > circs = ents.ret_circles();
 
56
                std::vector< line > lns = ents.ret_lines();
 
57
                std::vector< text > txts = ents.ret_texts();
 
58
                std::vector< insert > ins = ents.ret_inserts();
 
59
                */
 
60
                
 
61
 
 
62
                std::vector< layer >  layers = tbls.ret_layers();
 
63
                
 
64
                char units[5] = "in";
 
65
                char tmp_char[100000];
 
66
                char layer_string[500];
 
67
                
 
68
                if (ink < 1){
 
69
                        // Write a general svg header
 
70
                        std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n\t\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns=\"http://www.w3.org/2000/svg\"\n\txmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
 
71
                        std::cout << "\tx=\"0.00000000\"\n\ty=\"0.00000000\"\n\twidth=\"744.09448\"\n\theight=\"-1052.3622\"" << std::endl;
 
72
                }
 
73
                else{
 
74
                        std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << std::endl;
 
75
                        std::cout << "<!-- Created with dxf2svg -->" << std::endl;
 
76
                        std::cout << "<svg" << std::endl;
 
77
                        std::cout << "\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"" << std::endl;
 
78
                        std::cout << "\txmlns:cc=\"http://web.resource.org/cc/\"" << std::endl;
 
79
                        std::cout << "\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" << std::endl;
 
80
                        std::cout << "\txmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl;
 
81
                        std::cout << "\txmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
 
82
                        std::cout << "\txmlns:sodipodi=\"http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd\"" << std::endl;
 
83
                        std::cout << "\txmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"" << std::endl;
 
84
                        std::cout << "\t>" << std::endl;
 
85
 
 
86
                }
 
87
 
 
88
                
 
89
                // Now write SVG elements to file
 
90
                if ( layers.size() < 1 ){
 
91
                        write_all(0, ents, tbls, blks, scaling, units, tmp_char);
 
92
                }
 
93
                else{
 
94
                        for (int i = 0; i < layers.size(); i++){
 
95
                                std::cout << "\t<g\n\t\tinkscape:label=\"" << layers[i].name(layer_string) <<  "\"\n\t\tinkscape:groupmode=\"layer\"\n\t\tid=\"layer" << i+1 << "\">" << std::endl;
 
96
                                write_by_layer(0, ents, tbls, blks, scaling, units, layers[i].name(layer_string), tmp_char);
 
97
                                std::cout << "\t</g>" << std::endl;
 
98
                        }
 
99
                }
 
100
                
 
101
                // Close SVG
 
102
                std::cout << "</svg>";
 
103
        }
 
104
        
 
105
        return 0;
 
106
}