Skip to content

Commit 5e7dbad

Browse files
committed
File Operations
1 parent fce6c37 commit 5e7dbad

4 files changed

Lines changed: 46 additions & 24 deletions

File tree

src/public/component/component.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ function _event_onNodeSelect(event, nIndex)
197197
}
198198
if (bindtonode)
199199
{
200-
console.log("TEST");
201200
selectedNode = event;
202201
selectedNode.Selected = true;
203202
selectedNodeIndex = nIndex;
@@ -318,9 +317,46 @@ function _event_onNavigationSelect(event)
318317
graph.GetPath(start, end);
319318
}
320319
}
320+
else if (navigation === "_navigation_file_new")
321+
{
322+
graph = new Graph();
323+
}
321324
else if (navigation === "_navigation_file_save")
322325
{
323-
graph.ToJson();
326+
let file = new Blob([JSON.stringify(graph.ToJson())], { type: "text/plain" });
327+
let a = document.createElement("a");
328+
a.href = URL.createObjectURL(file);
329+
a.download = "graph.gbench";
330+
a.click();
331+
}
332+
else if (navigation === "_navigation_file_open")
333+
{
334+
let input = document.createElement("input");
335+
input.setAttribute("type", "file");
336+
input.click();
337+
input.onchange = (e) =>
338+
{
339+
let reader = new FileReader();
340+
reader.onload = () =>
341+
{
342+
try
343+
{
344+
graph.FromJson(ME, JSON.parse(reader.result));
345+
}
346+
catch (e)
347+
{
348+
349+
}
350+
}
351+
reader.readAsText(input.files[0]);
352+
}
353+
}
354+
else if (navigation === "_navigation_file_link")
355+
{
356+
let url = window.location;
357+
url += "@" + round(ME.Camera.Location.X, 2) + "," + round(ME.Camera.Location.Y, 2) + "," + round(ME.Camera.Location.Z, 2) + "z" + ((RenderedFloor / 2) + 1);
358+
url += "?graph=" + JSON.stringify(graph.ToJson());
359+
alert(url);
324360
}
325361
}
326362
function _event_onMouseDown(event)

src/public/component/element.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ let Graph = class Graph
191191
}
192192
ToJson()
193193
{
194-
let js = {};
195-
js["nodes"] = [];
194+
let js = {
195+
"nodes": [],
196+
"maxid": nID
197+
};
196198
for (let i = 0; i < this.Nodes.length; i++)
197199
{
198200
let child = {
@@ -248,12 +250,11 @@ let Graph = class Graph
248250
}
249251
js["elements"].push(child);
250252
}
251-
console.log(JSON.stringify(js));
252253
return js;
253254
}
254255
FromJson(ME, js)
255256
{
256-
console.log(js);
257+
nID = js["maxid"];
257258
for (let i = 0; i < js["nodes"].length; i++)
258259
{
259260
let n = new Node(js["nodes"][i]["name"], new Vertex(js["nodes"][i]["location"]["x"], js["nodes"][i]["location"]["y"], js["nodes"][i]["location"]["z"]));
@@ -290,7 +291,6 @@ let Graph = class Graph
290291
let c = js["elements"][i]["indices"][j];
291292
ind.push(new Index(c[0], c[1], c[2]));
292293
}
293-
console.log(v);
294294
let n = new Element(new Object3D(ME, v, ind, "New Object"), js["elements"][i]["name"], js["elements"][i]["type"]);
295295
if (js["elements"][i]["node"] != null)
296296
{

src/src/App.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class App extends Component
383383
};
384384
if (eventKey === "_navigation_node_bulkcreate")
385385
{
386-
let prompt = window.prompt("Shivan", 5);
386+
let prompt = window.prompt("How many nodes do you want to create?", 5);
387387
let num = 5;
388388
if (prompt == null || prompt == "")
389389
{
@@ -457,7 +457,6 @@ class App extends Component
457457
}
458458
_event_onSignalBind(event)
459459
{
460-
console.log("came back");
461460
this.state.SelectedElement.BindToNode(event.detail.node);
462461
this.setState({
463462
Element_Properties: true

src/src/configuration/navigation.json

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,7 @@
1111
"Open": "_navigation_file_open",
1212
"Save": "_navigation_file_save",
1313
"div1": "divider",
14-
"Clear": "_navigation_file_clear",
15-
"Revert": "_navigation_file_revert"
16-
}
17-
},
18-
"Export": {
19-
"type": "dropdown",
20-
"side": "left",
21-
"eventKey": "_navigation_export",
22-
"id": "nav-export-dropdown",
23-
"children": {
24-
"Nodes": "_navigation_export_nodes",
25-
"Elements": "_navigation_export_elements",
26-
"div1": "divider",
27-
"All": "_navigation_export_all"
14+
"Get Link": "_navigation_file_link"
2815
}
2916
},
3017
"View": {
@@ -41,7 +28,7 @@
4128
},
4229
"Path": {
4330
"type": "dropdown",
44-
"side": "right",
31+
"side": "left",
4532
"eventKey": "_navigation_path",
4633
"id": "nav-path-dropdown",
4734
"children": {

0 commit comments

Comments
 (0)