2
* This program source code file is part of KiCad, a free EDA CAD application.
4
* Copyright (C) 2014 Cirilo Bernardo
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
33
int main( int argc, char **argv )
35
list< string > comments;
39
string dname; // DXF filename
40
string gname; // Geometry Name
41
string pname; // Part Name
42
double height; // extrusion height
43
bool inch = false; // true = inches, false = mm
48
// no arguments; print out usage information
49
cout << "dxf2idf: this program takes line, arc, and circle segments\n";
50
cout << " from a DXF file and creates an IDF component outline file.\n\n";
52
cout << " DXF filename: the input file, must end in '.dxf'\n";
53
cout << " Units: mm, in (millimeters or inches)\n";
54
cout << " Geometry Name: string, as per IDF version 3.0 specification\n";
55
cout << " Part Name: as per IDF version 3.0 specification of Part Number\n";
56
cout << " Height: extruded height of the outline\n";
57
cout << " Comments: all non-empty lines are comments to be added to\n";
58
cout << " the IDF file. An empty line signifies the end of\n";
59
cout << " the comment block.\n";
60
cout << " File name: output filename, must end in '.idf'\n\n";
64
while( line.empty() || line.find( ".dxf" ) == string::npos )
66
cout << "* DXF filename: ";
69
std::getline( cin, line );
74
while( line.compare( "mm" ) && line.compare( "in" )
75
&& line.compare( "MM" ) && line.compare( "IN" ) )
77
cout << "* Units (mm,in): ";
79
std::getline( cin, line );
82
if( line.compare( "mm" ) && line.compare( "MM" ) )
88
cout << "* Geometry name: ";
90
std::getline( cin, line );
92
if( line.find( "\"" ) != string::npos )
94
cerr << "[INFO] geometry name may not contain quotation marks\n";
101
while( line.empty() )
103
cout << "* Part name: ";
105
std::getline( cin, line );
107
if( line.find( "\"" ) != string::npos )
109
cerr << "[INFO] part name may not contain quotation marks\n";
118
cout << "* Height: ";
121
std::getline( cin, line );
126
if( (tstr >> height ) && height > 0.001 )
130
cout << "* COMMENTS: any non-blank line is a comment;\n";
131
cout << " a blank line signifies the end of comments.\n";
136
std::getline( cin, line );
145
line.insert( 0, "# " );
147
comments.push_back( line );
152
while( line.empty() || line.find( ".idf" ) == string::npos )
154
cout << "* File name (*.idf): ";
157
std::getline( cin, line );
162
dxf.ReadDxf( dname.c_str() );
164
FILE* fp = fopen( line.c_str(), "w" );
166
list< string >::const_iterator scom = comments.begin();
167
list< string >::const_iterator ecom = comments.end();
169
while( scom != ecom )
171
fprintf( fp, "%s\n", (*scom).c_str() );
175
fprintf( fp, ".ELECTRICAL\n" );
178
fprintf( fp, "\"%s\" \"%s\" THOU %d\n", gname.c_str(),
179
pname.c_str(), (int) (height * 1000.0) );
181
fprintf( fp, "\"%s\" \"%s\" MM %.3f\n", gname.c_str(),
182
pname.c_str(), height );
184
dxf.WriteOutline( fp, inch );
186
fprintf( fp, ".END_ELECTRICAL\n" );
b'\\ No newline at end of file'