0032433: Visualization, TKService - introduce Wasm_Window implementing Aspect_Window...
[occt.git] / src / DRAWEXE / DRAWEXE.html
1 <!DOCTYPE html>
2 <html lang=en-us>
3 <head>
4 <meta charset=utf-8><meta content="text/html; charset=utf-8" http-equiv=Content-Type>
5 <link rel="shortcut icon" href="lamp.ico" type="image/x-icon" />
6 <title>OCCT Draw Harness</title>
7 </head>
8 <body>
9
10 <h2>OCCT Draw Harness</h2>
11 <div>
12   <canvas id=occViewerCanvas oncontextmenu=event.preventDefault() tabindex=-1 style="border:0 none;background-color:#000" width="409" height="409"></canvas>
13 </div>
14 <h4>For output - open JavaScript console in your Browser.</h4>
15 <p id="output"></p>
16 <script type="text/javascript" src="DRAWEXE.js" charset="utf-8"></script>
17 <script>
18 /**
19  * Class defining an interface to DRAWEXE and WebAssembly Module.
20  */
21 class DrawTerm
22 {
23   /**
24    * Class constructor.
25    */
26   constructor()
27   {
28     // define WebGL canvas for WebAssembly viewer
29     this.canvas = document.getElementById ('occViewerCanvas'); // canvas element for OpenGL context
30     this.canvas.tabIndex = -1;
31     this.canvas.onclick = (theEvent) =>
32     {
33       this.canvas.focus()
34     };
35   }
36
37   /**
38    * C++ std::cout callback redirecting to console.
39    */
40   print (theText)
41   {
42     //var anElement = document.getElementById('output');
43     //anElement.innerHTML += theText + "<br>";
44     console.warn (theText);
45   }
46
47   /**
48    * C++ std::cerr callback redirecting to console.
49    */
50   printErr (theText)
51   {
52     //var anElement = document.getElementById('output');
53     //anElement.innerHTML += theText + "<br>";
54     console.warn (theText);
55   }
56
57   /**
58    * C++ Message::Send() callback redirecting to Terminal.
59    */
60   printMessage (theText, theGravity)
61   {
62     switch (theGravity)
63     {
64       case 0: // trace
65         console.debug (theText);
66         return;
67       case 1: // info
68         console.info (theText);
69         return;
70       case 2: // warning
71         console.warn (theText);
72         return;
73       case 3: // alarm
74       case 4: // fail
75         console.error (theText);
76         return;
77     }
78     console.info (theText);
79   }
80
81   onRuntimeInitialized()
82   {
83     //
84   }
85 };
86 // Define a global DRAWEXE instance (will be initialized asynchronously).
87 var DRAWEXE = new DrawTerm();
88
89 //! Check browser support.
90 function isWasmSupported()
91 {
92   try {
93     if (typeof WebAssembly === "object"
94      && typeof WebAssembly.instantiate === "function") {
95       const aDummyModule = new WebAssembly.Module (Uint8Array.of (0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
96       if (aDummyModule instanceof WebAssembly.Module)
97       {
98         return new WebAssembly.Instance(aDummyModule) instanceof WebAssembly.Instance;
99       }
100     }
101   } catch (e) {}
102   return false;
103 }
104
105 if (!isWasmSupported())
106 {
107   var anElement = document.getElementById('output');
108   anElement.innerHTML += "Browser is too old - WebAssembly support is missing!<br>Please check updates or install a modern browser.<br>";
109 }
110 else
111 {
112   // load DRAWEXE.wasm (asynchronously) and wait initialization completion
113   createDRAWEXE(DRAWEXE).then (function(Module) {
114     //DRAWEXE.printMessage ("Hint: use \"pload ALL\" command to load standard commands\r\n", 1);
115     //DRAWEXE.eval ("dversion");
116   }).catch ((theError) => {
117     DRAWEXE.printMessage ("WebAssebly initialization has failed:\r\n" + theError, 4);
118   });
119 }
120
121 </script>
122 </body>
123 </html>