Commit 46a32a96 authored by Mathias Haage's avatar Mathias Haage
Browse files

First commit

parents
Pipeline #1974 skipped
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ulund.grafchart</groupId>
<artifactId>grafchart_utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>grafchart_utils</name>
<dependencies>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-runtime</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
</plugin>
</plugins>
</build>
</project>
#!/bin/sh
$JGRAFCHART_HOME/bin/run $1 $2 $3
#
# Source this file to setup environment
#
# Environment for grafchart tools
#
# Edit below:
#
export JGRAFCHART_HOME=/home/mathias/dev/grafchart/JGrafchart-2.6.1
export JGRAFCHART_UTILS_HOME=/home/mathias/dev/grafchart_utils/utils
export PATH=$PATH:$JGRAFCHART_UTILS_HOME/scripts
#!/bin/sh
java -classpath $JGRAFCHART_UTILS_HOME/target/grafchart_utils-0.0.1-SNAPSHOT.jar org.ulund.grafchart.SFCGenerate $1
package org.ulund.grafchart;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager;
import org.ulund.grafchart.nodes.GCDocument;
import org.ulund.grafchart.nodes.GCInitialStep;
import org.ulund.grafchart.nodes.GCStep;
import org.ulund.grafchart.nodes.GCTransition;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
public class SFCGenerate {
public static void main(String[] args) {
ArgumentParser parser = ArgumentParsers.newArgumentParser("sfcgenerate")
.description("Generate SFC state machines for JGraphChart");
parser.addArgument("states")
.required(true)
.dest("states")
.type(String.class)
.action(Arguments.store())
.help("comma-separated list of state names");
try {
Namespace res = parser.parseArgs(args);
if (res.getString("states") == null) {
parser.printHelp();
System.exit(1);
}
String[] states = res.getString("states").split(",");
Set<String> uuidSet = new HashSet<String>();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter w = factory.createXMLStreamWriter(System.out);
GCDocument doc = new GCDocument();
String uuidInitialStep = getUUID(uuidSet);
GCInitialStep gcInitialStep = doc.addGCInitialStep(uuidInitialStep, states[0]);
String[] uuidTransition = new String[states.length-1];
String[] uuidStep = new String[states.length-1];
GCTransition[] gcTransition = new GCTransition[states.length-1];
GCStep[] gcStep = new GCStep[states.length-1];
for (int i=0; i<states.length-1; i++) {
uuidTransition[i] = getUUID(uuidSet);
gcTransition[i] = doc.addGCTransition(uuidTransition[i]);
uuidStep[i] = getUUID(uuidSet);
gcStep[i] = doc.addGCStep(uuidStep[i], states[i+1]);
}
doc.addSocketIntIn();
doc.addSocketIntOut();
doc.addGCLink(gcInitialStep.getId(), gcTransition[0].getId(), gcInitialStep.getX()+30, gcInitialStep.getY()+70, gcTransition[0].getY());
for (int i=0; i<states.length-2; i++) {
doc.addGCLink(gcTransition[i].getId(), gcStep[i].getId(), gcTransition[i].getX()+15, gcTransition[i].getY()+25, gcStep[i].getY());
doc.addGCLink(gcStep[i].getId(), gcTransition[i+1].getId(), gcStep[i].getX()+30, gcStep[i].getY()+70, gcTransition[i+1].getY());
}
doc.addGCLink(gcTransition[states.length-2].getId(), gcStep[states.length-2].getId(), gcTransition[states.length-2].getX()+15, gcTransition[states.length-2].getY()+25, gcStep[states.length-2].getY());
doc.toXml(w);
w.flush();
} catch (ArgumentParserException | XMLStreamException e) {
System.out.println(e);
System.exit(1);
}
}
private static String getUUID(Set<String> uuidSet) {
String uuid = UUID.randomUUID().toString();
while (uuidSet.contains(uuid)) {
uuid = UUID.randomUUID().toString();
}
uuidSet.add(uuid);
return uuid;
}
}
package org.ulund.grafchart;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager;
import org.ulund.grafchart.nodes.GCDocument;
import org.ulund.grafchart.nodes.GCInitialStep;
import org.ulund.grafchart.nodes.GCStep;
import org.ulund.grafchart.nodes.GCTransition;
import org.ulund.kif.BaseURL;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
public class SFCGenerate {
public static void main(String[] args) {
ArgumentParser parser = ArgumentParsers.newArgumentParser("sfcgenerate")
.description("Generate SFC state machines for JGraphChart");
parser.addArgument("states")
.required(true)
.dest("states")
.type(String.class)
.action(Arguments.store())
.help("comma-separated list of state names");
try {
Namespace res = parser.parseArgs(args);
if (res.getString("states") == null) {
parser.printHelp();
System.exit(1);
}
String[] states = res.getString("states").split(",");
Set<String> uuidSet = new HashSet<String>();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter w = factory.createXMLStreamWriter(System.out);
GCDocument doc = new GCDocument();
String uuidInitialStep = getUUID(uuidSet);
GCInitialStep gcInitialStep = doc.addGCInitialStep(uuidInitialStep, states[0]);
String[] uuidTransition = new String[states.length-1];
String[] uuidStep = new String[states.length-1];
GCTransition[] gcTransition = new GCTransition[states.length-1];
GCStep[] gcStep = new GCStep[states.length-1];
for (int i=0; i<states.length-1; i++) {
uuidTransition[i] = getUUID(uuidSet);
gcTransition[i] = doc.addGCTransition(uuidTransition[i]);
uuidStep[i] = getUUID(uuidSet);
gcStep[i] = doc.addGCStep(uuidStep[i], states[i+1]);
}
doc.addSocketIntIn();
doc.addSocketIntOut();
doc.addGCLink(gcInitialStep.getId(), gcTransition[0].getId(), gcInitialStep.getX()+30, gcInitialStep.getY()+70, gcTransition[0].getY());
for (int i=0; i<states.length-2; i++) {
doc.addGCLink(gcTransition[i].getId(), gcStep[i].getId(), gcTransition[i].getX()+15, gcTransition[i].getY()+25, gcStep[i].getY());
doc.addGCLink(gcStep[i].getId(), gcTransition[i+1].getId(), gcStep[i].getX()+30, gcStep[i].getY()+70, gcTransition[i+1].getY());
}
doc.addGCLink(gcTransition[states.length-2].getId(), gcStep[states.length-2].getId(), gcTransition[states.length-2].getX()+15, gcTransition[states.length-2].getY()+25, gcStep[states.length-2].getY());
doc.toXml(w);
w.flush();
} catch (ArgumentParserException | XMLStreamException e) {
System.out.println(e);
System.exit(1);
}
}
private static String getUUID(Set<String> uuidSet) {
String uuid = UUID.randomUUID().toString();
while (uuidSet.contains(uuid)) {
uuid = UUID.randomUUID().toString();
}
uuidSet.add(uuid);
return uuid;
}
}
package org.ulund.grafchart.nodes;
import java.util.ArrayList;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public class GCDocument {
private String color = "-1";
private String dimTicks = "25";
private String dpwsInterface = "";
private String dpwsPort = "-1";
private String height = "608";
private String horizontalScrollBar = "1";
private String modifiable = "1";
private String name = "J1";
private String saveVersion = "8";
private String scale = "1.0";
private String simulationMode = "1";
private String socketHost = "localhost";
private String socketIsServer = "1";
private String socketPort = "4242";
private String socketSendMode = "Changed";
private String threadSpeed = "40";
private String tokenLuminance = "0";
private String verticalScrollBar = "1";
private String viewPositionX = "0";
private String viewPositionY = "0";
private String width = "879";
private String x = "0";
private String y = "0";
private List<Node> nodes = new ArrayList<Node>();
private GCLink prevGCLink = null;
private GCStep prevGCStep = null;
private GCTransition prevGCTransition = null;
public GCInitialStep addGCInitialStep(String uuid, String name) {
GCInitialStep node = new GCInitialStep(uuid, name);
nodes.add(node);
return node;
}
public GCLink addGCLink(String fromObject, String toObject, int x, int y0, int y1) {
GCLink node = new GCLink(fromObject, toObject, x, y0, y1);
//node.update(prevGCLink);
prevGCLink = node;
nodes.add(node);
return node;
}
public GCStep addGCStep(String uuid, String name) {
GCStep node = new GCStep(uuid, name);
node.update(prevGCStep);
prevGCStep = node;
nodes.add(node);
return node;
}
public GCTransition addGCTransition(String uuid) {
GCTransition node = new GCTransition(uuid);
node.update(prevGCTransition);
prevGCTransition = node;
nodes.add(node);
return node;
}
public SocketIntIn addSocketIntIn() {
SocketIntIn node = new SocketIntIn();
nodes.add(node);
return node;
}
public SocketIntOut addSocketIntOut() {
SocketIntOut node = new SocketIntOut();
nodes.add(node);
return node;
}
public void toXml(XMLStreamWriter w) throws XMLStreamException {
w.writeStartDocument("UTF-8", "1.0");
w.writeCharacters("\n");
w.writeStartElement("", "GCDocument", "");
w.writeAttribute("color", color);
w.writeAttribute("dimTicks", dimTicks);
w.writeAttribute("dpwsInterface", dpwsInterface);
w.writeAttribute("dpwsPort", dpwsPort);
w.writeAttribute("height", height);
w.writeAttribute("horizontalScrollBar", horizontalScrollBar);
w.writeAttribute("modifiable", modifiable);
w.writeAttribute("name", name);
w.writeAttribute("saveVersion", saveVersion);
w.writeAttribute("scale", scale);
w.writeAttribute("simulationMode", simulationMode);
w.writeAttribute("socketHost", socketHost);
w.writeAttribute("socketIsServer", socketIsServer);
w.writeAttribute("socketPort", socketPort);
w.writeAttribute("socketSendMode", socketSendMode);
w.writeAttribute("threadSpeed", threadSpeed);
w.writeAttribute("tokenLuminance", tokenLuminance);
w.writeAttribute("verticalScrollBar", verticalScrollBar);
w.writeAttribute("viewPositionX", viewPositionX);
w.writeAttribute("viewPositionY", viewPositionY);
w.writeAttribute("width", width);
w.writeAttribute("x", x);
w.writeAttribute("y", y);
w.writeCharacters("\n");
for (Node node : nodes) {
node.toXml(w);
w.writeCharacters("\n");
}
w.writeEndElement();
w.writeEndDocument();
}
}
package org.ulund.grafchart.nodes;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public class GCInitialStep extends Node {
private String actionBlockVisible = "0";
private String actionText = ";";
private String fileName = "";
private String height = "70";
private String id = "b703845b-364f-408e-b8cb-84ddae55bbfd";
private String name = "";
private String useIcon = "0";
private String width = "60";
private String x = "210";
private String y = "65";
public GCInitialStep(String uuid, String name) {
id = uuid;
this.name = name;
}
public String getId() { return id; }
public int getX() { return Integer.valueOf(x); }
public int getY() { return Integer.valueOf(y); }
@Override
public void toXml(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("GCInitialStep");
w.writeAttribute("actionBlockVisible", actionBlockVisible);
w.writeAttribute("actionText", actionText);
w.writeAttribute("fileName", fileName);
w.writeAttribute("height", height);
w.writeAttribute("id", id);
w.writeAttribute("name", name);
w.writeAttribute("useIcon", useIcon);
w.writeAttribute("width", width);
w.writeAttribute("x", x);
w.writeAttribute("y", y);
w.writeEndElement();
}
}
package org.ulund.grafchart.nodes;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public class GCLink extends Node {
private String fromObject = "b703845b-364f-408e-b8cb-84ddae55bbfd";
private String manAdj = "0";
private String toObject = "8eb5869a-c80e-4f4e-98b3-03dc21f86c2e";
private List<Stroke> strokes = new ArrayList<Stroke>();
public GCLink(String fromObject, String toObject, int x, int y0, int y1) {
this.fromObject = fromObject;
this.toObject = toObject;
addStrokes(x, y0, y1);
}
public void update(GCLink prev) {
if (prev == null) return;
Iterator<Stroke> prevIt = prev.strokes.iterator();
Iterator<Stroke> it = strokes.iterator();
while (it.hasNext()) {
it.next().update(prevIt.next());
}
}
private class Stroke extends Node {
private String x = "";
private String y = "";
public Stroke(int x, int y) {
this.x = Integer.toString(x);
this.y = Integer.toString(y);
}
public void update(Stroke prev) {
y = Integer.toString(Integer.valueOf(prev.y) + 300);
}
@Override
public void toXml(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("Stroke");
w.writeAttribute("x", x);
w.writeAttribute("y", y);
w.writeEndElement();
}
}
private void addStrokes(int x, int y0, int y1) {
strokes.add(new Stroke(x, y0));
strokes.add(new Stroke(x, y0+10));
strokes.add(new Stroke(x, (y0+y1)/2));
strokes.add(new Stroke(x, (y0+y1)/2));
strokes.add(new Stroke(x, y1-10));
strokes.add(new Stroke(x, y1));
}
@Override
public void toXml(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("GCLink");
w.writeAttribute("fromObject", fromObject);
w.writeAttribute("manAdj", manAdj);
w.writeAttribute("toObject", toObject);
for (Stroke stroke : strokes) stroke.toXml(w);
w.writeEndElement();
}
}
package org.ulund.grafchart.nodes;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public class GCStep extends Node {
private String actionBlockVisible = "1";
private String actionText = "s Output = 1;";
private String fileName = "";
private String height = "70";
private String id = "bae8f423-0ce5-41dd-b17f-59ece89a46b6";
private String name = "";
private String useIcon = "0";
private String width = "200";
private String x = "210";
private String y = "325";
private static int outputCounter = 1;
public GCStep(String uuid, String name) {
id = uuid;
this.name = name;
}
public void update(GCStep prev) {
if (prev == null) return;
y = Integer.toString(Integer.valueOf(prev.y) + 250);
outputCounter++;
actionText = String.format("s Output = %d;", outputCounter);
}
public String getId() { return id; }
public int getX() { return Integer.valueOf(x); }
public int getY() { return Integer.valueOf(y); }
@Override
public void toXml(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("GCStep");
w.writeAttribute("actionBlockVisible", actionBlockVisible);
w.writeAttribute("actionText", actionText);
w.writeAttribute("fileName", fileName);
w.writeAttribute("height", height);
w.writeAttribute("id", id);
w.writeAttribute("name", name);
w.writeAttribute("useIcon", useIcon);
w.writeAttribute("width", width);
w.writeAttribute("x", x);
w.writeAttribute("y", y);
w.writeEndElement();
}
}
package org.ulund.grafchart.nodes;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public class GCTransition extends Node {
private String actionText = "Input > 1";
private String conditionVisible = "1";
private String height = "25";
private String id = "8eb5869a-c80e-4f4e-98b3-03dc21f86c2e";
private String width = "30";
private String x = "225";
private String y = "220";
private static int inputCounter = 1;