forked from erichVK5/translate2geda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymbolPolyline.java
144 lines (125 loc) · 4.74 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// KicadSymbolToGEDA - a utility for turning kicad modules to gEDA PCB footprints
// SymbolPolyline.java v1.1
// Copyright (C) 2015 Erich S. Heinzle, [email protected]
// 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 [email protected]
/**
*
* 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 SymbolPolyline()
{
output = "#Hmm, the no arg symbol polygon constructor didn't do much";
}
public void populateBXLElement(String BXLLine) {
output = ""; // blow away the default message
BXLLine = BXLLine.replaceAll("[\"(),]","");
String [] tokens = BXLLine.split(" ");
for (int index = 0; index < tokens.length; index++) {
if (tokens[index].equals("Origin")) {
xCoords[0] = Integer.parseInt(tokens[++index]);
yCoords[0] = Integer.parseInt(tokens[++index]);
updateCoords(0);
} else if (tokens[index].equals("EndPoint")) {
xCoords[1] = Integer.parseInt(tokens[++index]);
yCoords[1] = Integer.parseInt(tokens[++index]);
updateCoords(1);
} else if (tokens[index].equals("Width")) {
lineThickness = Integer.parseInt(tokens[++index]);
}
}
vertices = 2;
}
public void updateCoords(int vertex) {
// 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];
}
}
public void constructor(String arg)
{
output = ""; // blow away the default message
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]);
updateCoords(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;
}
}