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.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. for (int i = 0; i < nodeCount; i++) {
  22. //nodes[i].deleted = true;
  23. i_selectedNode = i;
  24. deleteSelectedNode();
  25. }
  26. nodeCount = 0;
  27. for (int i = 0; i < linkCount; i++) {
  28. links[i].active = false;
  29. }
  30. linkCount = 0;
  31. String[] loadString = loadStrings(path);
  32. for (int i = 0; i < loadString.length-1; i++) {
  33. //This is ultra shitty
  34. if (loadString[i].length() == 0) {
  35. addNode(-1000, -1000, " ");
  36. i_selectedNode = nodeCount - 1;
  37. deleteSelectedNode();
  38. //nodes[nodeCount-1].deleted = true;
  39. } else {
  40. String nodeData[] = split(loadString[i], ',');
  41. addNode(int(nodeData[1]), int(nodeData[2]), nodeData[0]);
  42. }
  43. }
  44. for (int i = 0; i < loadString.length-1; i++) {
  45. String nodeData[] = split(loadString[i], ',');
  46. for (int j = 3; j < nodeData.length; j++) {
  47. Link(i, int(nodeData[j]));
  48. }
  49. }
  50. }
  51. void saveCSV(String path) {
  52. String saveString = "";
  53. for (int i = 0; i < nodeCount; i++) {
  54. if (!nodes[i].deleted) {
  55. saveString += nodes[i].title + "," + nodes[i].x + "," + nodes[i].y;
  56. for (int j = 0; j < linkCount; j++) {
  57. if (links[j].parentNode == i && links[j].active) {
  58. saveString += "," + str(links[j].targetNode);
  59. }
  60. }
  61. }
  62. saveString += "\n";
  63. }
  64. String[] saveArray = split(saveString, '\n');
  65. saveStrings(path, saveArray);
  66. }