changeset 500:329f229c2794 bgo-commands-codegen

Improvements to the integrated demo for TS <--> C++
author bgo-osimis
date Mon, 25 Feb 2019 06:35:21 +0100
parents baa9e1e932db
children 8424b10df93a
files Resources/CodeGeneration/testWasmIntegrated/build-web.sh Resources/CodeGeneration/testWasmIntegrated/main.cpp Resources/CodeGeneration/testWasmIntegrated/styles.css Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.html Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts
diffstat 5 files changed, 114 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/CodeGeneration/testWasmIntegrated/build-web.sh	Sun Feb 24 20:22:56 2019 +0100
+++ b/Resources/CodeGeneration/testWasmIntegrated/build-web.sh	Mon Feb 25 06:35:21 2019 +0100
@@ -22,5 +22,8 @@
 # copy WASM binary to output dir
 cp build-wasm/testWasmIntegratedCpp.wasm  build-final/
 
+echo "...Serving files at http://127.0.0.1:8080/"
+echo "Please open build_final/testWasmIntegrated.html"
+
 sudo python3 serve.py
 
--- a/Resources/CodeGeneration/testWasmIntegrated/main.cpp	Sun Feb 24 20:22:56 2019 +0100
+++ b/Resources/CodeGeneration/testWasmIntegrated/main.cpp	Mon Feb 25 06:35:21 2019 +0100
@@ -15,7 +15,7 @@
 
 #define HANDLE_MESSAGE(Type,value) \
   stringstream ss; \
-  ss << "Received an instance of" #Type ". Here's the dump:\n"; \
+  ss << "Received an instance of:\n" #Type "\n. Here's the dump:\n"; \
   testWasmIntegratedCpp::StoneDumpValue(ss, value, 0); \
   SendFreeTextFromCppJS(ss.str().c_str()); \
   return true;
--- a/Resources/CodeGeneration/testWasmIntegrated/styles.css	Sun Feb 24 20:22:56 2019 +0100
+++ b/Resources/CodeGeneration/testWasmIntegrated/styles.css	Mon Feb 25 06:35:21 2019 +0100
@@ -3,8 +3,8 @@
     grid-template-columns: 0.55fr 0.55fr 0.55fr 0.55fr 0.6fr 1.1fr 1.1fr;
     grid-template-rows: 1.1fr 0.9fr 0.2fr 0.3fr 0.1fr 0.3fr 0.1fr;
     grid-template-areas: 
-        "SerializedInput SerializedInput SerializedInput SerializedInput Trigger CppOutput CppOutput" 
-        "SerializedInput SerializedInput SerializedInput SerializedInput Trigger CppOutput CppOutput" 
+        "SerializedInput SerializedInput SerializedInput SerializedInput ButtonContainer CppOutput CppOutput" 
+        "SerializedInput SerializedInput SerializedInput SerializedInput ButtonContainer CppOutput CppOutput" 
         ". . . . . . ." 
         "Test1 Test2 Test3 Test4 . . ." 
         ". . . . . . ." 
@@ -15,15 +15,33 @@
     height: 480px;
   }
 
+  .TestWasm-ButtonContainer {
+    display: grid;
+    grid-template-columns: 0.2fr 0.8fr 0.2fr;
+    grid-template-rows: 0.2fr 0.5fr 0.2fr 0.5fr 0.2fr 0.5fr 0.2fr;
+    grid-template-areas: 
+        ". . ."
+        ". TriggerButton ." 
+        ". . ."
+        ". ClearButton ." 
+        ". . ."
+        ". ShowSchemaButton ." 
+        ". . ."
+        ;
+  }
+
+  .TestWasm-TriggerButton { grid-area: TriggerButton; }
+  
+  .TestWasm-ClearButton { grid-area: ClearButton; }
+  
+  .TestWasm-ShowSchemaButton { grid-area: ShowSchemaButton; }
+
+
 .TestWasm-SerializedInput { grid-area: SerializedInput; }
 
 .TestWasm-CppOutput { grid-area: CppOutput; }
 
-.TestWasm-Trigger { 
-    grid-area: Trigger; 
-    align-items: center;
-    text-align: center;
-}
+.TestWasm-ButtonContainer { grid-area: ButtonContainer; }
 
 .TestWasm-Test1 { grid-area: Test1; }
 
--- a/Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.html	Sun Feb 24 20:22:56 2019 +0100
+++ b/Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.html	Mon Feb 25 06:35:21 2019 +0100
@@ -13,15 +13,23 @@
     -->
     <body>
     <div class="TestWasm-grid-container">
-        <textarea id="TestWasm-SerializedInput" class="TestWasm-SerializedInput">
-            Serialized data should be put here.
-        </textarea>
-        <textarea id="TestWasm-CppOutput" class="TestWasm-CppOutput">
-            Free text and messages from C++ will appear here.
-        </textarea>
-        <div class="TestWasm-Trigger">
-            <button class="TestWasm-button TestWasm-hvcenter" tool-selector="Trigger">Send message</button>
+        <textarea id="TestWasm-SerializedInput" class="TestWasm-SerializedInput">Serialized data should be put here.</textarea>
+        <textarea id="TestWasm-CppOutput" class="TestWasm-CppOutput">Free text and messages from C++ will appear here.</textarea>
+        <div class="TestWasm-ButtonContainer">
+          <div class="TestWasm-TriggerButton">
+            <button class="TestWasm-button" tool-selector="Trigger">Send message</button>
+          </div>
+          <div class="TestWasm-ClearButton">
+            <button class="TestWasm-button" tool-selector="Clear">Clear</button>
+          </div>
+          <div class="TestWasm-ShowSchemaButton">
+            <button class="TestWasm-button" tool-selector="ShowSchema">Show schema</button>
+          </div>
+           <!-- <button class="TestWasm-button TestWasm-hvcenter" tool-selector="Trigger">Send message</button>
+            <button class="TestWasm-button TestWasm-hvcenter" tool-selector="Clear">Clear</button>
+            <button class="TestWasm-button TestWasm-hvcenter" tool-selector="Show schema">Show schema</button> -->
         </div>
+        
         <div class="TestWasm-Test1">
           <button class="TestWasm-button" tool-selector="Test 1">Test 1</button>
         </div>
--- a/Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts	Sun Feb 24 20:22:56 2019 +0100
+++ b/Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts	Mon Feb 25 06:35:21 2019 +0100
@@ -48,6 +48,53 @@
 |  define stock messages                           |
 +--------------------------------------------------+
 */
+let schemaText: string = `rootName: testWasmIntegratedCpp
+
+struct B:
+  someAs: vector<A>
+  someInts: vector<int32>
+
+struct C:
+  someBs: vector<B>
+  ddd:    vector<string>
+
+struct A:
+  someStrings: vector<string>
+  someInts2: vector<int32>
+  movies: vector<MovieType>
+
+struct Message1:
+  a: int32
+  b: string
+  c: EnumMonth0
+  d: bool
+
+struct Message2:
+  toto: string
+  tata: vector<Message1>
+  tutu: vector<string>
+  titi: map<string, string>
+  lulu: map<string, Message1>
+  movieType: MovieType
+
+enum MovieType:
+  - RomCom
+  - Horror
+  - ScienceFiction
+  - Vegetables
+
+enum CrispType:
+  - SaltAndPepper
+  - CreamAndChives
+  - Paprika
+  - Barbecue
+
+enum EnumMonth0:
+  - January
+  - February
+  - March
+`;
+
 let stockSerializedMessages = new Map<string,string>();
 stockSerializedMessages["Test 1"] = `{
   "type" : "testWasmIntegratedCpp.Message2",
@@ -98,7 +145,15 @@
     ]
   }
 }`;
-stockSerializedMessages["Test 2"] = "Test 2 stock message bccbbbbbb";
+stockSerializedMessages["Test 2"] = ` {
+  "type" : "testWasmIntegratedCpp.Message1",
+  "value" : {
+    "a" : -987,
+    "b" : "Salomé",
+    "c" : 2,
+    "d" : true
+  }
+}`;
 stockSerializedMessages["Test 3"] = "Test 3 stock message sdfsfsdfsdf";
 stockSerializedMessages["Test 4"] = "Test 4 stock message 355345345";
 stockSerializedMessages["Test 5"] = "Test 5 stock message 34535";
@@ -134,7 +189,7 @@
 
 function SendFreeTextFromCpp(txt: string):string
 {
-  setCppOutputValue(getCppOutputValue() + txt);
+  setCppOutputValue(getCppOutputValue() + "\n" + txt);
   return "";
 }
 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp;
@@ -151,6 +206,18 @@
     let SendMessageToCppLocal = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']);
     SendMessageToCppLocal(serializedInputValue);
   }
+  else if(buttonName == 'Clear')
+  {
+    setCppOutputValue("");
+  }
+  else if(buttonName == 'ShowSchema')
+  {
+    setCppOutputValue(schemaText);
+  }
+  else
+  {
+    throw new Error("Internal error!");
+  }
 }