Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts @ 496:8b6ceae45ba0 bgo-commands-codegen
Finished (untested) C++, html, typescript, tsc & browserify production.
author | bgo-osimis |
---|---|
date | Sat, 23 Feb 2019 15:04:29 +0100 |
parents | |
children | 6d62fc8a6988 |
comparison
equal
deleted
inserted
replaced
495:6405435480ae | 496:8b6ceae45ba0 |
---|---|
1 export var SendMessageToStoneApplication: Function = null; | |
2 | |
3 function SelectTool(toolName: string) { | |
4 var command = { | |
5 command: "selectTool:" + toolName, | |
6 commandType: "generic-no-arg-command", | |
7 args: { | |
8 } | |
9 }; | |
10 SendMessageToStoneApplication(JSON.stringify(command)); | |
11 } | |
12 | |
13 (<any> window).StoneFrameworkModule = { | |
14 preRun: [ | |
15 function() { | |
16 console.log('Loading the Stone Framework using WebAssembly'); | |
17 } | |
18 ], | |
19 postRun: [ | |
20 function() { | |
21 // This function is called by ".js" wrapper once the ".wasm" | |
22 // WebAssembly module has been loaded and compiled by the | |
23 // browser | |
24 console.log('WebAssembly is ready'); | |
25 SendMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']); | |
26 } | |
27 ], | |
28 print: function(text : string) { | |
29 console.log(text); | |
30 }, | |
31 printErr: function(text : string) { | |
32 console.error(text); | |
33 }, | |
34 totalDependencies: 0 | |
35 }; | |
36 | |
37 // install "SelectTool" handlers | |
38 document.querySelectorAll("[tool-selector]").forEach((e) => { | |
39 (e as HTMLButtonElement).addEventListener("click", () => { | |
40 SelectTool(e.attributes["tool-selector"].value); | |
41 }); | |
42 }); | |
43 | |
44 // this method is called "from the C++ code" when the StoneApplication is updated. | |
45 // it can be used to update the UI of the application | |
46 function UpdateWebApplication(statusUpdateMessageString: string) { | |
47 console.log("updating web application: ", statusUpdateMessageString); | |
48 let statusUpdateMessage = JSON.parse(statusUpdateMessageString); | |
49 | |
50 if ("event" in statusUpdateMessage) | |
51 { | |
52 let eventName = statusUpdateMessage["event"]; | |
53 if (eventName == "appStatusUpdated") | |
54 { | |
55 //ui.onAppStatusUpdated(statusUpdateMessage["data"]); | |
56 } | |
57 } | |
58 } |