|
@@ -76,7 +76,6 @@ public class StoreController {
|
|
*/
|
|
*/
|
|
public StoreController(Model model) {
|
|
public StoreController(Model model) {
|
|
this.model = model;
|
|
this.model = model;
|
|
- initNumeration();
|
|
|
|
initGson();
|
|
initGson();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -92,19 +91,19 @@ public class StoreController {
|
|
*/
|
|
*/
|
|
public void writeSaveFile(String path) throws IOException {
|
|
public void writeSaveFile(String path) throws IOException {
|
|
|
|
|
|
|
|
+ initNumeration();
|
|
JsonObject file = new JsonObject();
|
|
JsonObject file = new JsonObject();
|
|
-
|
|
|
|
initialize(MODE.COMPLETE, file);
|
|
initialize(MODE.COMPLETE, file);
|
|
storeCategory(file);
|
|
storeCategory(file);
|
|
storeCanvas(file);
|
|
storeCanvas(file);
|
|
|
|
|
|
FileWriter writer = new FileWriter(path);
|
|
FileWriter writer = new FileWriter(path);
|
|
writer.write(gson.toJson(file));
|
|
writer.write(gson.toJson(file));
|
|
-
|
|
|
|
|
|
+
|
|
writer.flush();
|
|
writer.flush();
|
|
writer.close();
|
|
writer.close();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Writes the Autosave File.
|
|
* Writes the Autosave File.
|
|
*
|
|
*
|
|
@@ -115,14 +114,14 @@ public class StoreController {
|
|
*/
|
|
*/
|
|
public void writeAutosaveFile(String path) throws IOException {
|
|
public void writeAutosaveFile(String path) throws IOException {
|
|
|
|
|
|
-
|
|
|
|
|
|
+ initNumeration();
|
|
JsonObject file = new JsonObject();
|
|
JsonObject file = new JsonObject();
|
|
initialize(MODE.PARTIAL, file);
|
|
initialize(MODE.PARTIAL, file);
|
|
storeCanvas(file);
|
|
storeCanvas(file);
|
|
-
|
|
|
|
|
|
+
|
|
FileWriter writer = new FileWriter(path);
|
|
FileWriter writer = new FileWriter(path);
|
|
writer.write(gson.toJson(file));
|
|
writer.write(gson.toJson(file));
|
|
-
|
|
|
|
|
|
+
|
|
writer.flush();
|
|
writer.flush();
|
|
writer.close();
|
|
writer.close();
|
|
}
|
|
}
|
|
@@ -139,13 +138,13 @@ public class StoreController {
|
|
switch (mode) {
|
|
switch (mode) {
|
|
case COMPLETE:
|
|
case COMPLETE:
|
|
file.add("MODE", new JsonPrimitive(mode.name()));
|
|
file.add("MODE", new JsonPrimitive(mode.name()));
|
|
- file.add("IDCounter", new JsonPrimitive(IdCounter.getCounter()));
|
|
|
|
|
|
+ file.add("IDCOUNTER", new JsonPrimitive(IdCounter.getCounter()));
|
|
file.add("CANVAS_SIZE_X", new JsonPrimitive(model.getCanvasX()));
|
|
file.add("CANVAS_SIZE_X", new JsonPrimitive(model.getCanvasX()));
|
|
file.add("CANVAS_SIZE_Y", new JsonPrimitive(model.getCanvasY()));
|
|
file.add("CANVAS_SIZE_Y", new JsonPrimitive(model.getCanvasY()));
|
|
break;
|
|
break;
|
|
case PARTIAL:
|
|
case PARTIAL:
|
|
file.add("MODE", new JsonPrimitive(mode.name()));
|
|
file.add("MODE", new JsonPrimitive(mode.name()));
|
|
- file.add("IDCounter", new JsonPrimitive(IdCounter.getCounter()));
|
|
|
|
|
|
+ file.add("IDCOUNTER", new JsonPrimitive(IdCounter.getCounter()));
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -162,9 +161,11 @@ public class StoreController {
|
|
// TODO Auto-generated method stub
|
|
// TODO Auto-generated method stub
|
|
for (Category cat : model.getCategories()) {
|
|
for (Category cat : model.getCategories()) {
|
|
String key = "CATEGORY" + getNumerator(NUMTYPE.CATEGORY);
|
|
String key = "CATEGORY" + getNumerator(NUMTYPE.CATEGORY);
|
|
|
|
+
|
|
file.add(key, new JsonPrimitive(cat.getName()));
|
|
file.add(key, new JsonPrimitive(cat.getName()));
|
|
|
|
+
|
|
for (AbstractCpsObject obj : cat.getObjects()) {
|
|
for (AbstractCpsObject obj : cat.getObjects()) {
|
|
- file.add("CATEGORY.OBJECT" + getNumerator(NUMTYPE.OBJECT),
|
|
|
|
|
|
+ file.add("CGOBJECT" + getNumerator(NUMTYPE.OBJECT),
|
|
new JsonPrimitive(gson.toJson(obj, AbstractCpsObject.class)));
|
|
new JsonPrimitive(gson.toJson(obj, AbstractCpsObject.class)));
|
|
if (obj instanceof HolonObject)
|
|
if (obj instanceof HolonObject)
|
|
elementsToJson(TYPE.CATEGORY, gson, file, obj);
|
|
elementsToJson(TYPE.CATEGORY, gson, file, obj);
|
|
@@ -174,7 +175,7 @@ public class StoreController {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Travers through all Objects via BFS and Stores everything relevant
|
|
* Travers through all Objects via BFS and Stores everything relevant
|
|
-
|
|
|
|
|
|
+ *
|
|
* @param file
|
|
* @param file
|
|
*/
|
|
*/
|
|
private void storeCanvas(JsonObject file) {
|
|
private void storeCanvas(JsonObject file) {
|
|
@@ -195,14 +196,15 @@ public class StoreController {
|
|
// TODO Auto-generated catch block
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
- String key = "CANVAS.OBJECT" + getNumerator(NUMTYPE.OBJECT);
|
|
|
|
|
|
+ String key = "CVSOBJECT" + getNumerator(NUMTYPE.OBJECT);
|
|
file.add(key, new JsonPrimitive(gson.toJson(u, AbstractCpsObject.class)));
|
|
file.add(key, new JsonPrimitive(gson.toJson(u, AbstractCpsObject.class)));
|
|
edgeToJson(EDGETYPE.CONNECTION, gson, file, u.getID(), u.getConnections());
|
|
edgeToJson(EDGETYPE.CONNECTION, gson, file, u.getID(), u.getConnections());
|
|
|
|
|
|
if (u instanceof HolonObject)
|
|
if (u instanceof HolonObject)
|
|
elementsToJson(TYPE.CANVAS, gson, file, u);
|
|
elementsToJson(TYPE.CANVAS, gson, file, u);
|
|
if (u instanceof HolonSwitch)
|
|
if (u instanceof HolonSwitch)
|
|
- unitgraphToJson(GRAPHTYPE.SWITCH, gson, file, u.getID(), ((HolonSwitch) u).getGraphPoints());
|
|
|
|
|
|
+ if (((HolonSwitch) u).getGraphPoints().size() != 0)
|
|
|
|
+ unitgraphToJson(GRAPHTYPE.SWITCH, gson, file, u.getID(), ((HolonSwitch) u).getGraphPoints());
|
|
if (u instanceof CpsUpperNode) {
|
|
if (u instanceof CpsUpperNode) {
|
|
for (AbstractCpsObject adjacent : ((CpsUpperNode) u).getNodes()) {
|
|
for (AbstractCpsObject adjacent : ((CpsUpperNode) u).getNodes()) {
|
|
queue.enqueue(adjacent);
|
|
queue.enqueue(adjacent);
|
|
@@ -212,7 +214,7 @@ public class StoreController {
|
|
edgeToJson(EDGETYPE.OLD, gson, file, u.getID(), ((CpsUpperNode) u).getOldEdges());
|
|
edgeToJson(EDGETYPE.OLD, gson, file, u.getID(), ((CpsUpperNode) u).getOldEdges());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
datasetToJson(gson, file);
|
|
datasetToJson(gson, file);
|
|
|
|
|
|
}
|
|
}
|
|
@@ -227,14 +229,24 @@ public class StoreController {
|
|
private void elementsToJson(TYPE type, Gson gson, JsonObject file, AbstractCpsObject obj) {
|
|
private void elementsToJson(TYPE type, Gson gson, JsonObject file, AbstractCpsObject obj) {
|
|
// TODO Auto-generated method stub
|
|
// TODO Auto-generated method stub
|
|
JsonObject temp = new JsonObject();
|
|
JsonObject temp = new JsonObject();
|
|
|
|
+ String key = null;
|
|
|
|
|
|
for (HolonElement ele : ((HolonObject) obj).getElements()) {
|
|
for (HolonElement ele : ((HolonObject) obj).getElements()) {
|
|
temp.add("properties", new JsonPrimitive(gson.toJson(ele)));
|
|
temp.add("properties", new JsonPrimitive(gson.toJson(ele)));
|
|
temp.add("ID", new JsonPrimitive(obj.getID()));
|
|
temp.add("ID", new JsonPrimitive(obj.getID()));
|
|
- if (ele.getEnergyAt().length != 0)
|
|
|
|
|
|
+ if (ele.getGraphPoints().size() != 0)
|
|
unitgraphToJson(GRAPHTYPE.ELEMENT, gson, file, ele.getId(), ele.getGraphPoints());
|
|
unitgraphToJson(GRAPHTYPE.ELEMENT, gson, file, ele.getId(), ele.getGraphPoints());
|
|
-
|
|
|
|
- file.add(type.name() + ".OBJECT.ELEMENT" + getNumerator(NUMTYPE.ELEMENT), gson.toJsonTree(temp));
|
|
|
|
|
|
+ switch (type) {
|
|
|
|
+ case CANVAS:
|
|
|
|
+ key = "CVSELEMENT" + getNumerator(NUMTYPE.ELEMENT);
|
|
|
|
+ break;
|
|
|
|
+ case CATEGORY:
|
|
|
|
+ key = "CGELEMENT" + getNumerator(NUMTYPE.ELEMENT);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ file.add(key, gson.toJsonTree(temp));
|
|
temp = new JsonObject();
|
|
temp = new JsonObject();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -255,10 +267,10 @@ public class StoreController {
|
|
|
|
|
|
switch (type) {
|
|
switch (type) {
|
|
case SWITCH:
|
|
case SWITCH:
|
|
- key = "SWITCH.UNIGRAPH" + getNumerator(NUMTYPE.UNITGRAPH);
|
|
|
|
|
|
+ key = "SWUNITGRAPH" + getNumerator(NUMTYPE.UNITGRAPH);
|
|
break;
|
|
break;
|
|
case ELEMENT:
|
|
case ELEMENT:
|
|
- key = "ELEMENT.UNIGRAPH" + getNumerator(NUMTYPE.UNITGRAPH);
|
|
|
|
|
|
+ key = "ELEUNITGRAPH" + getNumerator(NUMTYPE.UNITGRAPH);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
@@ -290,17 +302,17 @@ public class StoreController {
|
|
|
|
|
|
switch (type) {
|
|
switch (type) {
|
|
case CANVAS:
|
|
case CANVAS:
|
|
- k = "CANVAS.EDGE" + getNumerator(NUMTYPE.EDGE);
|
|
|
|
|
|
+ k = "CVSEDGE" + getNumerator(NUMTYPE.EDGE);
|
|
break;
|
|
break;
|
|
case CONNECTION:
|
|
case CONNECTION:
|
|
- k = "CANVAS.OBJECT.CONNECTION" + getNumerator(NUMTYPE.CONNECTION);
|
|
|
|
|
|
+ k = "OBJCONNECTION" + getNumerator(NUMTYPE.CONNECTION);
|
|
break;
|
|
break;
|
|
case NODE:
|
|
case NODE:
|
|
- k = "CANVAS.UPPERNODE.EDGE" + getNumerator(NUMTYPE.NODEEDGE);
|
|
|
|
|
|
+ k = "NODEEDGE" + getNumerator(NUMTYPE.NODEEDGE);
|
|
temp.add("ID", new JsonPrimitive(id));
|
|
temp.add("ID", new JsonPrimitive(id));
|
|
break;
|
|
break;
|
|
case OLD:
|
|
case OLD:
|
|
- k = "CANVAS.UPPERNODE.OLD" + getNumerator(NUMTYPE.OLDEDGE);
|
|
|
|
|
|
+ k = "OLDEDGE" + getNumerator(NUMTYPE.OLDEDGE);
|
|
temp.add("ID", new JsonPrimitive(id));
|
|
temp.add("ID", new JsonPrimitive(id));
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
@@ -312,10 +324,10 @@ public class StoreController {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void datasetToJson(Gson gson, JsonObject file) {
|
|
private void datasetToJson(Gson gson, JsonObject file) {
|
|
JsonObject temp = new JsonObject();
|
|
JsonObject temp = new JsonObject();
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -331,14 +343,14 @@ public class StoreController {
|
|
// use the builder and make a instance of the Gson
|
|
// use the builder and make a instance of the Gson
|
|
this.gson = builder.create();
|
|
this.gson = builder.create();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Just initialize the Numerators for the Json Keys. Maybe bad Style..
|
|
* Just initialize the Numerators for the Json Keys. Maybe bad Style..
|
|
*/
|
|
*/
|
|
private void initNumeration() {
|
|
private void initNumeration() {
|
|
this.nCat = this.nObj = this.nEle = this.nEdge = this.nConn = this.nNodeEdge = this.nOldEdge = 0;
|
|
this.nCat = this.nObj = this.nEle = this.nEdge = this.nConn = this.nNodeEdge = this.nOldEdge = 0;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Get the wanted numerator and increment it
|
|
* Get the wanted numerator and increment it
|
|
*
|
|
*
|