Simple editor to create custom node network graphs aka ontologies
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

save_load.pde 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Saving and loading is a messy hack!
  3. * You'll get a blank line in your save file for each deleted object.
  4. * That's because of my lack of skills of dodging the garbage collector.
  5. * I didn't loose data to corruption yet.
  6. * Don't touch the save files if you don't want to mess them up!
  7. **/
  8. boolean exporting;
  9. String savePNGpath = dataPath("save.png");
  10. void savePNGFile(File selection) {
  11. savePNGpath = selection.getPath();
  12. exporting = true;
  13. }
  14. void saveCSVFile(File selection) {
  15. saveCSV(selection.getPath());
  16. }
  17. void loadCSVFile(File selection) {
  18. loadCSV(selection.getPath());
  19. }
  20. void loadCSV(String path) {
  21. deleteAll();
  22. String[] loadString = loadStrings(path);
  23. for (int i = 0; i < loadString.length-1; i++) {
  24. //This is ultra shitty
  25. if (loadString[i].length() == 0) {
  26. addNode(-1000, -1000, " ");
  27. i_selectedNode = nodeCount - 1;
  28. deleteSelectedNode();
  29. //nodes[nodeCount-1].deleted = true;
  30. } else {
  31. String nodeData[] = split(loadString[i], ',');
  32. addNode(int(nodeData[1]), int(nodeData[2]), nodeData[0]);
  33. }
  34. }
  35. for (int i = 0; i < loadString.length-1; i++) {
  36. String nodeData[] = split(loadString[i], ',');
  37. for (int j = 3; j < nodeData.length; j++) {
  38. Link(i, int(nodeData[j]));
  39. }
  40. }
  41. }
  42. void saveCSV(String path) {
  43. String saveString = "";
  44. for (int i = 0; i < nodeCount; i++) {
  45. if (!nodes[i].deleted) {
  46. saveString += nodes[i].title + "," + nodes[i].x + "," + nodes[i].y;
  47. for (int j = 0; j < linkCount; j++) {
  48. if (links[j].parentNode == i && links[j].active) {
  49. saveString += "," + str(links[j].targetNode);
  50. }
  51. }
  52. }
  53. saveString += "\n";
  54. }
  55. String[] saveArray = split(saveString, '\n');
  56. saveStrings(path, saveArray);
  57. }