/
SymbolPolyline.java
120 lines (103 loc) · 3.91 KB
/
SymbolPolyline.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// KicadSymbolToGEDA - a utility for turning kicad modules to gEDA PCB footprints
// SymbolPolyline.java v1.0
// Copyright (C) 2015 Erich S. Heinzle, a1039181@gmail.com
// see LICENSE-gpl-v2.txt for software license
// see README.txt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// KicadSymbolToGEDA Copyright (C) 2015 Erich S. Heinzle a1039181@gmail.com
/**
*
* This class is passed a Kicad Polyline descriptor string of the form "P Ni x1 y1 x2 y2 ... xi yi fill"
* and implements a method which can generate a gschema line definitions for a gEDA symbol
*
*/
//P Nb parts convert thickness x0 y0 x1 y1 xi yi cc
//With:
//• Nb = a number of points.
//• unit = 0 if common to the parts; if not, number of part (1. .n).
//• convert = 0 if common to the 2 representations, if not 1 or 2.
//• thickness = line thickness.
//• xi yi coordinates of end i.
//• cc = N F or F ( F = filled polygon; f = . filled polygon, N = transparent background)
public class SymbolPolyline extends SymbolElement
{
String polylineDescriptor = "";
String output = "";
int vertices = 0;
long xCoords[] = new long[30];
long yCoords[] = new long[30];
int fillType = 0;
long lineThickness = 0;
long minX = 0;
long minY = 0;
public void SymbolPolyline()
{
output = "#Hmm, the no arg symbol polygon constructor didn't do much";
}
public void constructor(String arg)
{
polylineDescriptor = arg;
arg = arg.replaceAll(" "," ");
arg = arg.replaceAll(" "," ");
// it seems some ulp converted eagle files have a lot of spaces
arg = arg.replaceAll(" "," ");
String[] tokens = arg.split(" ");
vertices = Integer.parseInt(tokens[1]);
// System.out.println("Vertices found: " + vertices);
lineThickness = Integer.parseInt(tokens[4]);
for (int vertex = 0; vertex < vertices; vertex++) {
xCoords[vertex] = Long.parseLong(tokens[vertex*2+5]);
yCoords[vertex] = Long.parseLong(tokens[vertex*2+6]);
// we first update the superclass static variable
super.updateXdimensions(xCoords[vertex]);
super.updateYdimensions(yCoords[vertex]);
// we sort out the local max,min variables
if (minX > xCoords[vertex]) {
minX = xCoords[vertex];
}
if (minY > yCoords[vertex]) {
minY = yCoords[vertex];
}
// System.out.println("(" + xCoords[vertex] + ", " + yCoords[vertex] + ")");
}
}
public long localMinXCoord() {
return minX;
}
public long localMinYCoord() {
return minY;
}
public String toString(long xOffset, long yOffset) {
int colorIndex = 3;
for (int index = 0; index < (vertices - 1); index++) {
output = (output
+ "L "
+ (xCoords[index] + xOffset) + " "
+ (yCoords[index] + yOffset) + " "
+ (xCoords[index+1] + xOffset) + " "
+ (yCoords[index+1] + yOffset) + " "
+ colorIndex + " "
+ lineThickness + " "
+ "0 0 " // for line capstyle (none) and dashstyle (solid)
+ "-1 -1"); // for dashlength and dashspace (not used)
if (index < (vertices - 2)) {
output = output + "\n";
}
}
return output;
}
}