preparing function mapping
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.4.36</version>
|
||||
<version>1.4.37</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -131,6 +131,7 @@ DetermineTrainInBlock : Zug im Block bestimmen
|
||||
Determine, which train is in {} : Bestimmen, welcher Zug sich in {} befindet
|
||||
Direction : Richtung
|
||||
Direction\: heading {} : Richtung: nach {}
|
||||
directional : fahrtrichtungs-abhängig
|
||||
disable : deaktivieren
|
||||
disabled : deaktiviert
|
||||
disable {} : {} deaktivieren
|
||||
@@ -177,7 +178,10 @@ FreeStartBlock : Start-Block freigeben
|
||||
Free tiles behind train : Kacheln hinter dem Zug freigeben
|
||||
Fullscreen : Vollbild
|
||||
Function : Funktion
|
||||
Function {} : Funktion {}
|
||||
Function mapping : Funktionszuordnung
|
||||
Hardware settings : Hardware-Einstellungen
|
||||
Headlight : Spitzenlicht
|
||||
Height : Höhe
|
||||
Help : Hilfe
|
||||
History : Logbuch
|
||||
@@ -252,6 +256,7 @@ No tile moved. : keine Kachel verschoben.
|
||||
no value : kein Wert
|
||||
{} now heading for {} : {} ist nun unterwegs nach {}
|
||||
{} now in auto-mode : {} ist nun im Automatikmodus
|
||||
Number of functions : Anzahl der Funktionen
|
||||
Occupied area : Belegte Abschnitte
|
||||
Off : Aus
|
||||
OFF : aus
|
||||
@@ -298,7 +303,7 @@ Removed train "{}" : Zug „{}“ gelöscht
|
||||
rename : umbenennen
|
||||
Rename plan : Plan umbenennen
|
||||
Report Issue : Problem melden
|
||||
reverse : wenden
|
||||
reverse : rückwärts
|
||||
reverse train : Zug wenden
|
||||
Reversed {}. : {} umgedreht.
|
||||
RIGHT : rechts
|
||||
@@ -391,6 +396,7 @@ Switch power on : Strom anschalten
|
||||
SYSTEM : Betriebssystem
|
||||
Tag : Markierung
|
||||
Tags : Markierungen
|
||||
Tail light : Schlusslicht
|
||||
Task : Aufgabe
|
||||
Task name must not be empty : Aufgaben-Name darf nicht leer sein
|
||||
Task type : Aufgabe
|
||||
|
||||
@@ -41,8 +41,10 @@ public class Decoder extends BaseClass implements Constants, Device {
|
||||
private static final String TRACK = "track";
|
||||
private static final String VALUE = "val";
|
||||
private static final String CV = "cv";
|
||||
private static final String NUM_FUNCTIONS = "numFunctions";
|
||||
private String type;
|
||||
private Locomotive loco;
|
||||
private int numFunctions = 2;
|
||||
|
||||
public static Object action(Params params) {
|
||||
Decoder decoder = BaseClass.get(Id.from(params));
|
||||
@@ -140,7 +142,15 @@ public class Decoder extends BaseClass implements Constants, Device {
|
||||
return this;
|
||||
}
|
||||
|
||||
private Window program(HashMap<String, String> params) {
|
||||
public int numFunctions() {
|
||||
return numFunctions ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Window program(Params params) {
|
||||
String error = null;
|
||||
if (ACTION_PROGRAM.equals(params.get(ACTION))) try {
|
||||
int cv = params.getInt(CV);
|
||||
@@ -215,6 +225,7 @@ public class Decoder extends BaseClass implements Constants, Device {
|
||||
}
|
||||
formInputs.add(t("Protocol"),div);
|
||||
formInputs.add(t("Address"),new Tag("span").content(""+address()));
|
||||
formInputs.add(t("Number of functions"),new Input(NUM_FUNCTIONS,numFunctions).numeric());
|
||||
if (isSet(loco)) formInputs.add(t("Locomotive"),loco.button(loco.name()));
|
||||
postForm.add(programming());
|
||||
return super.properties(preForm, formInputs, postForm, errorMessages);
|
||||
@@ -283,8 +294,19 @@ public class Decoder extends BaseClass implements Constants, Device {
|
||||
@Override
|
||||
protected Window update(Params params) {
|
||||
super.update(params);
|
||||
if (params.containsKey(TYPE)) type = params.get(TYPE);
|
||||
if (params.containsKey(Device.PROTOCOL)) setProtocol(Protocol.valueOf(params.get(Device.PROTOCOL)));
|
||||
if (params.containsKey(TYPE)) type = params.getString(TYPE);
|
||||
if (params.containsKey(Device.PROTOCOL)) setProtocol(Protocol.valueOf(params.getString(Device.PROTOCOL)));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (params.containsKey(NUM_FUNCTIONS)) numFunctions = params.getInt(NUM_FUNCTIONS);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return isSet(loco) ? loco.properties() : properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import de.srsoftware.web4rail.Params;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
import de.srsoftware.web4rail.devices.Decoder;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Checkbox;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
@@ -29,6 +30,14 @@ import de.srsoftware.web4rail.tiles.Block;
|
||||
public class Locomotive extends Car implements Constants{
|
||||
|
||||
public static final String LOCOMOTIVE = "locomotive";
|
||||
private static final String HEADLIGHT = "headlight";
|
||||
private static final String TAILLIGHT = "taillight";
|
||||
private static final String DIRECTIONAL = "directional";
|
||||
private static final String INTERIOR_LIGHT = "interior";
|
||||
private static final String COUPLER = "coupler";
|
||||
private static final String FORWARD = "forward";
|
||||
private static final String REVERSE = "reverse";
|
||||
private static final String ACTION_MAPPING = "mapping";
|
||||
private int speed = 0;
|
||||
private boolean f1,f2,f3,f4;
|
||||
//private TreeMap<Integer,Integer> cvs = new TreeMap<Integer, Integer>();
|
||||
@@ -51,6 +60,8 @@ public class Locomotive extends Car implements Constants{
|
||||
return Locomotive.manager();
|
||||
case ACTION_FASTER10:
|
||||
return loco.faster(Train.defaultSpeedStep);
|
||||
case ACTION_MAPPING:
|
||||
return loco.updateMapping(params);
|
||||
case ACTION_MOVE:
|
||||
return loco.moveUp();
|
||||
case ACTION_PROPS:
|
||||
@@ -79,6 +90,25 @@ public class Locomotive extends Car implements Constants{
|
||||
return t("Unknown action: {}",params.getString(ACTION));
|
||||
}
|
||||
|
||||
private void addDecoderButtons(Window props) {
|
||||
Tag basicProps = props.children().stream().filter(tag -> BaseClass.PROPS_BASIC.equals(tag.get("id"))).findFirst().get();
|
||||
Tag form = basicProps.children().stream().filter(tag -> tag.is("form")).findFirst().get();
|
||||
Table table = (Table) form.children().stream().filter(tag -> tag.is("table")).findFirst().get();
|
||||
Tag div = new Tag("div");
|
||||
if (isSet(decoder)) {
|
||||
decoder.button().addTo(div);
|
||||
decoder.button(t("dismount"), Map.of(ACTION,ACTION_DECOUPLE)).addTo(div);
|
||||
} else {
|
||||
Decoder.selector(true).addTo(div);
|
||||
}
|
||||
table.addRow(t("Decoder"),div);
|
||||
Vector<Tag> cols = table.children();
|
||||
Tag lastRow = cols.lastElement();
|
||||
cols.remove(cols.size()-1);
|
||||
cols.insertElementAt(lastRow, 5);
|
||||
}
|
||||
|
||||
|
||||
public static Fieldset cockpit(BaseClass locoOrTrain) {
|
||||
int speed = 0;
|
||||
String realm = null;
|
||||
@@ -197,6 +227,40 @@ public class Locomotive extends Car implements Constants{
|
||||
public Tag faster(int steps) {
|
||||
return setSpeed(speed + steps);
|
||||
}
|
||||
|
||||
private Fieldset functionMapping() {
|
||||
Fieldset fieldset = new Fieldset(t("Function mapping")).id("props-functions");
|
||||
Form form = new Form("function-mapping");
|
||||
new Input(REALM, REALM_LOCO).hideIn(form);
|
||||
new Input(ACTION, ACTION_MAPPING).hideIn(form);
|
||||
new Input(ID,id()).hideIn(form);
|
||||
for (int i=0; i<decoder.numFunctions(); i++) functionMapping(i).addTo(form);
|
||||
return new Button(t("Save"), form).addTo(form).addTo(fieldset);
|
||||
}
|
||||
|
||||
|
||||
private Tag functionMapping(int index) {
|
||||
Fieldset mapping = new Fieldset(t("Function {}",index));
|
||||
Tag type = new Tag("div");
|
||||
new Checkbox(functionName(index,HEADLIGHT), t("Headlight"), false, true).addTo(type);
|
||||
new Checkbox(functionName(index,TAILLIGHT), t("Tail light"), false, true).addTo(type);
|
||||
new Checkbox(functionName(index,INTERIOR_LIGHT),t("Interior light"),false, true).addTo(type);
|
||||
new Checkbox(functionName(index,COUPLER),t("Coupler"),false, true).addTo(type);
|
||||
|
||||
Tag dir = new Tag("div");
|
||||
new Checkbox(functionName(index,DIRECTIONAL), t("directional"), false, true).addTo(dir);
|
||||
new Checkbox(functionName(index,FORWARD), t("forward"), false, true).addTo(dir);
|
||||
new Checkbox(functionName(index,REVERSE), t("reverse"), false, true).addTo(dir);
|
||||
|
||||
Table table = new Table();
|
||||
table.addHead(t("Type"),t("Direction"));
|
||||
table.addRow(type,dir);
|
||||
return table.addTo(mapping);
|
||||
}
|
||||
|
||||
private static String functionName(int index,String key) {
|
||||
return "function["+index+"]["+key+"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
@@ -271,22 +335,9 @@ public class Locomotive extends Car implements Constants{
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) {
|
||||
preForm.add(cockpit(this));
|
||||
if (isSet(decoder) && decoder.numFunctions()>0) postForm.add(functionMapping());
|
||||
Window props = super.properties(preForm, formInputs, postForm,errors);
|
||||
Tag basicProps = props.children().stream().filter(tag -> BaseClass.PROPS_BASIC.equals(tag.get("id"))).findFirst().get();
|
||||
Tag form = basicProps.children().stream().filter(tag -> tag.is("form")).findFirst().get();
|
||||
Table table = (Table) form.children().stream().filter(tag -> tag.is("table")).findFirst().get();
|
||||
Tag div = new Tag("div");
|
||||
if (isSet(decoder)) {
|
||||
decoder.button().addTo(div);
|
||||
decoder.button(t("dismount"), Map.of(ACTION,ACTION_DECOUPLE)).addTo(div);
|
||||
} else {
|
||||
Decoder.selector(true).addTo(div);
|
||||
}
|
||||
table.addRow(t("Decoder"),div);
|
||||
Vector<Tag> cols = table.children();
|
||||
Tag lastRow = cols.lastElement();
|
||||
cols.remove(cols.size()-1);
|
||||
cols.insertElementAt(lastRow, 5);
|
||||
addDecoderButtons(props);
|
||||
return props;
|
||||
}
|
||||
|
||||
@@ -302,7 +353,7 @@ public class Locomotive extends Car implements Constants{
|
||||
if (isNull(decoder)) return;
|
||||
int step = decoder.protocol().steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
||||
decoder.init();
|
||||
plan.queue(new Command("SET {} GL "+decoder.address()+" "+(orientation == FORWARD ? 0 : 1)+" "+step+" "+decoder.protocol().steps+" "+(f1?1:0)+" "+(f2?1:0)+" "+(f3?1:0)+" "+(f4?1:0)) {
|
||||
plan.queue(new Command("SET {} GL "+decoder.address()+" "+(orientation == Car.FORWARD ? 0 : 1)+" "+step+" "+decoder.protocol().steps+" "+(f1?1:0)+" "+(f2?1:0)+" "+(f3?1:0)+" "+(f4?1:0)) {
|
||||
|
||||
@Override
|
||||
public void onFailure(Reply reply) {
|
||||
@@ -404,4 +455,9 @@ public class Locomotive extends Car implements Constants{
|
||||
}
|
||||
return properties();
|
||||
}
|
||||
|
||||
private Object updateMapping(Params params) {
|
||||
// TODO Auto-generated method stub
|
||||
return properties();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,6 +958,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
if (car instanceof Locomotive) {
|
||||
Locomotive loco = (Locomotive) car;
|
||||
loco.setFunction(num,active);
|
||||
if (active) break;
|
||||
}
|
||||
}
|
||||
return properties();
|
||||
|
||||
@@ -7,11 +7,16 @@ public class Checkbox extends Tag {
|
||||
private static final long serialVersionUID = -7294673319021862994L;
|
||||
|
||||
public Checkbox(String name, String label, boolean preCheck) {
|
||||
this(name,label,preCheck,false);
|
||||
}
|
||||
|
||||
public Checkbox(String name, String label, boolean preCheck, boolean submitDisabled) {
|
||||
super("label");
|
||||
if (submitDisabled) new Input(name,"off").hideIn(this);
|
||||
Tag checkbox = new Tag("input").attr("type", "checkbox").attr("name", name);
|
||||
if (preCheck) checkbox.attr("checked", "checked");
|
||||
checkbox.addTo(this);
|
||||
content(label);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user