Rev 422 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2014 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 or
* version 2 as published by the Free Software Foundation.
*
* 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.
*/
package test.svg.nod;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import uk.me.parabola.imgfmt.app.Area;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
/**
* Convert a nod file to svg to show the routing relationships.
*
* @author Steve Ratcliffe
*/
public class Main
{
private static final String USAGE_MSG =
"Usage: nod2svg [--node 1dc[, ...] <filename>";
private SvgRouteDoc doc
;
/**
* Create an XML document.
*/
private void createDoc
() {
doc =
new SvgRouteDoc
();
doc.
createDoc();
}
/**
* Write the document.
*/
private void writeDoc
() {
doc.
setTransform(doc.
getLeftOffset(), doc.
getTopOffset());
try {
OutputFormat fmt = OutputFormat.
createPrettyPrint();
XMLWriter output =
new XMLWriter
(new FileWriter( new File("out.svg") ), fmt
);
output.
write(doc.
getDoc());
output.
close();
} catch (IOException e
) {
e.
printStackTrace();
}
}
private void run
(String[] args
) {
createDoc
();
String name =
null;
Set<Integer> nodes =
new HashSet<>();
Set<Integer> centers =
new HashSet<>();
Area area =
null;
int i =
0;
while (i
< args.
length) {
String s = args
[i
];
if (s.
startsWith("--node")) {
String ns = args
[++i
];
for (String s1 : ns.
split("[, ]"))
nodes.
add(Integer.
parseInt(s1,
16));
} else if (s.
startsWith("--center")) {
String ns = args
[++i
];
for (String s1 : ns.
split("[, ]"))
centers.
add(Integer.
parseInt(s1
));
} else if (s.
startsWith("--area")) {
String ns = args
[++i
];
String[] split = ns.
split("[/, \t]");
area =
new Area(Double.
parseDouble(split
[0]),
Double.
parseDouble(split
[1]),
Double.
parseDouble(split
[2]),
Double.
parseDouble(split
[3]));
} else {
name = s
;
}
i++
;
}
if (name ==
null)
System.
out.
println(USAGE_MSG
);
// Draw the route network
Route route =
new Route
();
route.
setArea(area
);
route.
setNodes(nodes
);
route.
setCenters(centers
);
route.
run(doc, name
);
writeDoc
();
}
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println(USAGE_MSG
);
System.
exit(1);
}
Main main =
new Main
();
main.
run(args
);
}
}