|
@@ -4,10 +4,8 @@ import javafx.collections.ObservableList;
|
|
|
import javafx.scene.Group;
|
|
|
import javafx.scene.Node;
|
|
|
import javafx.scene.input.*;
|
|
|
-import mdd.client.connectable.Connectable;
|
|
|
-import mdd.client.connectable.Connection;
|
|
|
-import mdd.client.connectable.Input;
|
|
|
-import mdd.client.connectable.Output;
|
|
|
+import javafx.scene.layout.VBox;
|
|
|
+import mdd.client.connectable.*;
|
|
|
import org.json.simple.JSONArray;
|
|
|
import org.json.simple.JSONObject;
|
|
|
import org.json.simple.parser.JSONParser;
|
|
@@ -16,9 +14,11 @@ import org.json.simple.parser.ParseException;
|
|
|
import java.util.Vector;
|
|
|
|
|
|
public class Processor extends Module{
|
|
|
- private Group modules = new Group();
|
|
|
- private Group connections = new Group();
|
|
|
- public Group all = new Group(connections, modules);
|
|
|
+ public Group modules;
|
|
|
+ public VBox params_in;
|
|
|
+ public VBox params_out;
|
|
|
+ public Group connections;
|
|
|
+ public Group all;
|
|
|
|
|
|
|
|
|
private boolean detected_drag = false;
|
|
@@ -30,32 +30,6 @@ public class Processor extends Module{
|
|
|
super(json);
|
|
|
Type = "processor";
|
|
|
|
|
|
- if (json.containsKey("modules")){
|
|
|
- for (Object o : (JSONArray) json.get("modules")){
|
|
|
- JSONObject jobj = (JSONObject) o;
|
|
|
- if (jobj.get("type").equals("module")){
|
|
|
- modules.getChildren().add(new Module(jobj));
|
|
|
- }else if(jobj.get("type").equals("processor")){
|
|
|
- modules.getChildren().add(new Processor(jobj));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (json.containsKey("connections")){
|
|
|
- for (Object o : (JSONArray) json.get("connections")){
|
|
|
- JSONObject jobj = (JSONObject) o;
|
|
|
- JSONObject jout = (JSONObject)jobj.get("output");
|
|
|
- for (Object ins : (JSONArray) jobj.get("inputs")){
|
|
|
- JSONObject jin = (JSONObject) ins;
|
|
|
- //TODO update prefix
|
|
|
- int lsize = ((JSONArray)jin.get("prefix")).size()-1;
|
|
|
- Input in = getModule(((JSONArray)jin.get("prefix")).get(lsize).toString()).getInput(jin.get("name").toString()+jin.get("appendix").toString());
|
|
|
- Output out = getModule(((JSONArray)jout.get("prefix")).get(lsize).toString()).getOutput(jout.get("name").toString()+jout.get("appendix").toString());
|
|
|
- connections.getChildren().add(new Connection(in, out));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
modules.addEventHandler(MouseEvent.DRAG_DETECTED, e -> {
|
|
|
// System.out.println("[Module]: dragg event detected!");
|
|
|
if(e.getButton() == MouseButton.PRIMARY) {
|
|
@@ -112,7 +86,7 @@ public class Processor extends Module{
|
|
|
String type = jobj.get("type").toString();
|
|
|
JSONArray jprefix = (JSONArray)jobj.get("prefix");
|
|
|
String sparent = jprefix.get(jprefix.size()-1).toString();
|
|
|
- String sID = jobj.get("name").toString()+jobj.get("appendix").toString();
|
|
|
+ String sID = jobj.get("key").toString()+jobj.get("appendix").toString();
|
|
|
if (type.equals("input")) {
|
|
|
System.out.println("[Processor] Dropped found type = " + "INPUT");
|
|
|
in = getModule(sparent).getInput(sID);
|
|
@@ -148,6 +122,89 @@ public class Processor extends Module{
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void configure(JSONObject json){
|
|
|
+ super.configure(json);
|
|
|
+ if (!json.containsKey("modules") && !json.containsKey("params") && !json.containsKey("connections")){return;}
|
|
|
+ if (modules == null){
|
|
|
+ modules = new Group();
|
|
|
+ params_in = new VBox();
|
|
|
+ params_out = new VBox();
|
|
|
+ connections = new Group();
|
|
|
+ all = new Group();
|
|
|
+ all.getChildren().addAll(connections, modules);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ modules.getChildren().clear();
|
|
|
+ params_in.getChildren().clear();
|
|
|
+ params_out.getChildren().clear();
|
|
|
+ connections.getChildren().clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (json.containsKey("modules")){
|
|
|
+ for (Object o : (JSONArray) json.get("modules")){
|
|
|
+ JSONObject jobj = (JSONObject) o;
|
|
|
+ if (jobj.get("type").equals("module")){
|
|
|
+ modules.getChildren().add(new Module(jobj));
|
|
|
+ }else if(jobj.get("type").equals("processor")){
|
|
|
+ modules.getChildren().add(new Processor(jobj));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (json.containsKey("params")){
|
|
|
+ JSONObject jparam = (JSONObject)json.get("params");
|
|
|
+ //inputs
|
|
|
+ if (jparam.containsKey("inputs")){
|
|
|
+ if (jparam.get("inputs") != null){
|
|
|
+ JSONArray jparam_in = (JSONArray)jparam.get("inputs");
|
|
|
+ for (int i = 0; i < jparam_in.size(); ++i){
|
|
|
+ JSONObject jmod = (JSONObject)jparam_in.get(i);
|
|
|
+ jmod.put("inputs", null);
|
|
|
+ params_in.getChildren().add(new Parameter(jmod));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //outputs
|
|
|
+ if (jparam.containsKey("outputs")){
|
|
|
+ if (jparam.get("outputs") != null){
|
|
|
+ JSONArray jparam_out = (JSONArray)jparam.get("outputs");
|
|
|
+ for (int i = 0; i < jparam_out.size(); ++i){
|
|
|
+ JSONObject jmod = (JSONObject)jparam_out.get(i);
|
|
|
+ jmod.put("outputs", null);
|
|
|
+ params_out.getChildren().add(new Parameter(jmod));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (json.containsKey("connections")){
|
|
|
+ for (Object o : (JSONArray) json.get("connections")){
|
|
|
+ JSONObject jobj = (JSONObject) o;
|
|
|
+ JSONObject jout = (JSONObject)jobj.get("output");
|
|
|
+ for (Object ins : (JSONArray) jobj.get("inputs")){
|
|
|
+ JSONObject jin = (JSONObject) ins;
|
|
|
+ //TODO update prefix
|
|
|
+ int lsize = ((JSONArray)jin.get("prefix")).size()-1;
|
|
|
+ Module min = getModule(((JSONArray)jin.get("prefix")).get(lsize).toString());
|
|
|
+ Module mout = getModule(((JSONArray)jout.get("prefix")).get(lsize).toString());
|
|
|
+ Input in = min.getInput(jin.get("key").toString()+jin.get("appendix").toString());
|
|
|
+ Output out = mout.getOutput(jout.get("key").toString()+jout.get("appendix").toString());
|
|
|
+ Connection con = new Connection(in, out);
|
|
|
+ if (min instanceof Parameter || mout instanceof Parameter){
|
|
|
+ con.setVisible(false);
|
|
|
+ con.setManaged(false);
|
|
|
+ }
|
|
|
+ connections.getChildren().add(con);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public Module getModule(String id){
|
|
|
for (Node node : modules.getChildren()){
|
|
|
if (node instanceof Module){
|
|
@@ -157,6 +214,22 @@ public class Processor extends Module{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ for (Node node : params_in.getChildren()){
|
|
|
+ if (node instanceof Module){
|
|
|
+ Module m = (Module)node;
|
|
|
+ if (m.ID.equals(id)){
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Node node : params_out.getChildren()){
|
|
|
+ if (node instanceof Module){
|
|
|
+ Module m = (Module)node;
|
|
|
+ if (m.ID.equals(id)){
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -181,6 +254,36 @@ public class Processor extends Module{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void close() throws Exception {
|
|
|
+ super.close();
|
|
|
+ for (int i = 0; i < connections.getChildren().size(); ++i)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ ((Connectable)modules.getChildren().get(i)).close();
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < modules.getChildren().size(); ++i)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ Object obj = modules.getChildren().get(i);
|
|
|
+ if (obj instanceof Processor){
|
|
|
+ ((Processor)obj).close();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ((Module)obj).close();
|
|
|
+ }
|
|
|
+ modules.getChildren().remove(i);
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void processGUIEvent(String event, JSONObject args) {
|
|
|
super.processGUIEvent(event, args);
|
|
@@ -192,7 +295,6 @@ public class Processor extends Module{
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("path", getAsPrefix());
|
|
|
_eventHandler.publishEvent("OPEN_PROCESSOR", json);
|
|
|
- System.out.println("[Processor]: published");
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
@@ -249,8 +351,8 @@ public class Processor extends Module{
|
|
|
JSONObject jin = (JSONObject)jobj.get("input");
|
|
|
JSONObject jout = (JSONObject)jobj.get("output");
|
|
|
int lsize = ((JSONArray)jin.get("prefix")).size()-1;
|
|
|
- Input in = getModule(((JSONArray)jin.get("prefix")).get(lsize).toString()).getInput(jin.get("name").toString()+jin.get("appendix").toString());
|
|
|
- Output out = getModule(((JSONArray)jout.get("prefix")).get(lsize).toString()).getOutput(jout.get("name").toString()+jout.get("appendix").toString());
|
|
|
+ Input in = getModule(((JSONArray)jin.get("prefix")).get(lsize).toString()).getInput(jin.get("key").toString()+jin.get("appendix").toString());
|
|
|
+ Output out = getModule(((JSONArray)jout.get("prefix")).get(lsize).toString()).getOutput(jout.get("key").toString()+jout.get("appendix").toString());
|
|
|
if (in != null && out != null) {
|
|
|
if (in.isConnected()) {
|
|
|
for (int i = 0; i < connections.getChildren().size(); ++i) {
|
|
@@ -266,70 +368,71 @@ public class Processor extends Module{
|
|
|
connections.getChildren().add(new Connection(in, out));
|
|
|
break;
|
|
|
case "module":
|
|
|
- modules.getChildren().add(new Module(jobj));
|
|
|
+ if (jobj.get("key").toString().equals("Parameter")){
|
|
|
+ params_in.getChildren().add(new Module(jobj));
|
|
|
+ }else {
|
|
|
+ modules.getChildren().add(new Module(jobj));
|
|
|
+ }
|
|
|
break;
|
|
|
case "processor":
|
|
|
modules.getChildren().add(new Processor(jobj));
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
+ case "change":
|
|
|
+ configure(jobj);
|
|
|
+ break;
|
|
|
case "remove":
|
|
|
- switch (jobj.get("type").toString()) {
|
|
|
- case "module":
|
|
|
- ObservableList gmodule = modules.getChildren();
|
|
|
- for (int i = 0; i < gmodule.size(); ++i) {
|
|
|
- JSONObject json = ((Module) gmodule.get(i)).getJSONIdentifier();
|
|
|
- if (json.equals(jobj)) {
|
|
|
- ObservableList gin = ((Module) gmodule.get(i)).inputs.getChildren();
|
|
|
- for (int j = 0; j < gin.size(); ++j){
|
|
|
- Input in = (Input)gin.get(j);
|
|
|
- if (in.isConnected()){
|
|
|
- ObservableList gcon = connections.getChildren();
|
|
|
- for (int k = 0; k < gcon.size(); ++k){
|
|
|
- Connection con = (Connection)gcon.get(k);
|
|
|
- if (con.in == in){
|
|
|
- try {
|
|
|
- con.close();
|
|
|
- } catch (Exception e) {
|
|
|
- //e.printStackTrace();
|
|
|
- }
|
|
|
- gcon.remove(k);
|
|
|
- break;
|
|
|
- }
|
|
|
+ ObservableList gmodule = modules.getChildren();
|
|
|
+ for (int i = 0; i < gmodule.size(); ++i) {
|
|
|
+ JSONObject json = ((Module) gmodule.get(i)).getJSONIdentifier();
|
|
|
+ if (json.equals(jobj)) {
|
|
|
+ ObservableList gin = ((Module) gmodule.get(i)).inputs.getChildren();
|
|
|
+ for (int j = 0; j < gin.size(); ++j){
|
|
|
+ Input in = (Input)gin.get(j);
|
|
|
+ if (in.isConnected()){
|
|
|
+ ObservableList gcon = connections.getChildren();
|
|
|
+ for (int k = 0; k < gcon.size(); ++k){
|
|
|
+ Connection con = (Connection)gcon.get(k);
|
|
|
+ if (con.in == in){
|
|
|
+ try {
|
|
|
+ con.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //e.printStackTrace();
|
|
|
}
|
|
|
+ gcon.remove(k);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- ObservableList gout = ((Module) gmodule.get(i)).outputs.getChildren();
|
|
|
- for (int j = 0; j < gout.size(); ++j){
|
|
|
- Output out = (Output)gout.get(j);
|
|
|
- if (out.isConnected()){
|
|
|
- ObservableList gcon = connections.getChildren();
|
|
|
- for (int k = 0; k < gcon.size(); ++k){
|
|
|
- Connection con = (Connection)gcon.get(k);
|
|
|
- if (con.out == out){
|
|
|
- try {
|
|
|
- con.close();
|
|
|
- } catch (Exception e) {
|
|
|
- //e.printStackTrace();
|
|
|
- }
|
|
|
- gcon.remove(k);
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ObservableList gout = ((Module) gmodule.get(i)).outputs.getChildren();
|
|
|
+ for (int j = 0; j < gout.size(); ++j){
|
|
|
+ Output out = (Output)gout.get(j);
|
|
|
+ if (out.isConnected()){
|
|
|
+ ObservableList gcon = connections.getChildren();
|
|
|
+ for (int k = 0; k < gcon.size(); ++k){
|
|
|
+ Connection con = (Connection)gcon.get(k);
|
|
|
+ if (con.out == out){
|
|
|
+ try {
|
|
|
+ con.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //e.printStackTrace();
|
|
|
}
|
|
|
+ gcon.remove(k);
|
|
|
}
|
|
|
}
|
|
|
- try {
|
|
|
- ((Module) gmodule.get(i)).close();
|
|
|
- } catch (Exception e) {
|
|
|
- //e.printStackTrace();
|
|
|
- }
|
|
|
- modules.getChildren().remove(i);
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
+ try {
|
|
|
+ ((Module) gmodule.get(i)).close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ modules.getChildren().remove(i);
|
|
|
break;
|
|
|
- case "processor":
|
|
|
- modules.getChildren().add(new Processor(jobj));
|
|
|
- break;
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|