MaterialXWeb 0.0.2
Utilities for using MaterialX Packages with Web clients
Loading...
Searching...
No Matches
MaterialXOCIOClient Class Reference
Inheritance diagram for MaterialXOCIOClient:
WebSocketClient

Public Member Functions

 constructor (socketLibrary, server)
 
 convertTableToBootstrapRowCol (container)
 
 updateConfigInfo (message)
 
 updateMaterialXInfo (data)
 
 updateStatus (message, force=false)
 
 emitGetConfigInfo ()
 
 getMaterialXInfo ()
 
 handleServerConfigInfo (data)
 
 handleServerMaterialXInfo (data)
 
 handleServerVersionInfo (data)
 
 setupEventHandlers ()
 
 setupXML ()
 
- Public Member Functions inherited from WebSocketClient
 constructor (socketLibrary, server)
 
async initialize (socketLibrary, server)
 
 setupEventHandlers ()
 
 emit (message, data)
 
 constructor (socketLibrary, server)
 
async initialize (socketLibrary, server)
 
 setupEventHandlers ()
 
 emit (message, data)
 
 constructor (socketLibrary, server)
 
async initialize (socketLibrary, server)
 
 setupEventHandlers ()
 
 emit (message, data)
 

Detailed Description

Definition at line 3 of file materialx_ocio_app.js.

Member Function Documentation

◆ constructor()

MaterialXOCIOClient::constructor ( socketLibrary,
server )

Definition at line 4 of file materialx_ocio_app.js.

4 {
5 // Call parent to setup socket I/O.
6 super(socketLibrary, server);
7
8 // Do other setup
9 this.materialXEditor = null;
10 this.materialXEditor_impl = null;
11 this.materialXEditor_source = null;
12 }

◆ convertTableToBootstrapRowCol()

MaterialXOCIOClient::convertTableToBootstrapRowCol ( container)

Definition at line 14 of file materialx_ocio_app.js.

14 {
15 // Modify the table to make it scrollable using Bootstrap classes
16 const tables = container.querySelectorAll('table');
17 tables.forEach(table => {
18 // Add Bootstrap table classes
19 table.classList.add('table', 'table-dark', 'table-bordered', 'table-hover', 'table-striped');
20
21 // Wrap the table in a div with Bootstrap's 'overflow-auto' class
22 const wrapperDiv = document.createElement('div');
23 wrapperDiv.classList.add('overflow-auto');
24 wrapperDiv.style.maxWidth = '100%';
25 wrapperDiv.style.maxHeight = '300px';
26
27 // Move the table inside the wrapper div
28 table.parentNode.insertBefore(wrapperDiv, table);
29 wrapperDiv.appendChild(table);
30
31 // Add a Bootstrap color class to the table header
32 const thead = table.querySelector('thead');
33 const headerColorClass = 'table-primary';
34 if (thead) {
35 thead.classList.add(headerColorClass);
36 } else {
37 const firstRow = table.querySelector('tr');
38 if (firstRow) {
39 firstRow.classList.add(headerColorClass);
40 }
41 }
42 });
43 }

◆ emitGetConfigInfo()

MaterialXOCIOClient::emitGetConfigInfo ( )

Definition at line 106 of file materialx_ocio_app.js.

106 {
107 this.updateStatus("Emit client_event_get_config_info event");
108 this.emit('client_event_get_config_info', { message: "event 1" });
109 }

◆ getMaterialXInfo()

MaterialXOCIOClient::getMaterialXInfo ( )

Definition at line 111 of file materialx_ocio_app.js.

111 {
112 this.updateStatus("Emit client_event_get_materialx_info event");
113 let checkbox_nodegraphs = document.getElementById('checkbox_nodegraphs').checked
114 this.emit('client_event_get_materialx_info',
115 {
116 nodegraphs: checkbox_nodegraphs
117 }
118 );
119 }

◆ handleServerConfigInfo()

MaterialXOCIOClient::handleServerConfigInfo ( data)

Definition at line 121 of file materialx_ocio_app.js.

121 {
122 this.updateStatus("Received server config info");
123 this.updateConfigInfo(data.message);
124 }

◆ handleServerMaterialXInfo()

MaterialXOCIOClient::handleServerMaterialXInfo ( data)

Definition at line 126 of file materialx_ocio_app.js.

126 {
127 this.updateStatus("Received server materialx info");
128 this.updateMaterialXInfo(data);
129 }

◆ handleServerVersionInfo()

MaterialXOCIOClient::handleServerVersionInfo ( data)

Definition at line 131 of file materialx_ocio_app.js.

131 {
132 this.updateStatus("Received server version info");
133
134 const ocio_version = document.getElementById('ocio_version');
135 const ocio_image = '<img src="https://opencolorio.org/images/ocio_m2x.png" width="48px"></img>';
136 ocio_version.innerHTML = ocio_image + ' version: ' + data.ocio_version;
137
138 const materialx_version = document.getElementById('materialx_version');
139 const mtlx_image = '<img src="https://materialx.org/LogoImages/MaterialXLogo2K.png" width="48px">';
140 materialx_version.innerHTML = mtlx_image + ' version: ' + data.materialx_version;
141 }

◆ setupEventHandlers()

MaterialXOCIOClient::setupEventHandlers ( )

Definition at line 143 of file materialx_ocio_app.js.

143 {
144 // Setup clear status button
145 document.getElementById('clear_status').addEventListener('click', () => {
146 this.updateStatus('Status', true);
147 });
148
149 document.getElementById('button_event_get_config').addEventListener('click', () => {
150 this.emitGetConfigInfo();
151 });
152
153 document.getElementById('button_event_get_materialx').addEventListener('click', () => {
154 this.getMaterialXInfo();
155 });
156
157
158 // Set up socket message event handlers
159 this.webSocketWrapper = new WebSocketEventHandlers(this.socket, {
160 status_message: (data) => { console.log('WEB: status event:', data.message); this.updateStatus(data.message) },
161 server_message_get_config_info: (data) => { this.handleServerConfigInfo(data) },
162 server_message_get_mtlx_info: (data) => { this.handleServerMaterialXInfo(data) },
163 server_message_version_info: (data) => { this.handleServerVersionInfo(data) }
164 });
165
166 this.emit('client_event_get_version_info');
167 }

◆ setupXML()

MaterialXOCIOClient::setupXML ( )

Definition at line 169 of file materialx_ocio_app.js.

169 {
170 // Initialize CodeMirror for MaterialX content
171 const materialX_nodedef = document.getElementById('materialX_nodedef');
172 this.materialXEditor = CodeMirror.fromTextArea(materialX_nodedef, {
173 mode: 'application/xml',
174 lineNumbers: true,
175 theme: 'dracula',
176 });
177 this.materialXEditor.setSize('auto', '300px');
178
179 /*
180 const materialX_impl = document.getElementById('materialX_nodedef');
181 this.materialXEditor_impl = CodeMirror.fromTextArea(materialX_impl, {
182 mode: 'application/xml',
183 lineNumbers: true,
184 theme: 'dracula',
185 });
186 this.materialXEditor_impl.setSize('auto', '100px');
187 //this.materialXEditor_impl.setDisplay('none')
188
189 const materialx_source = document.getElementById('materialx_source');
190 this.materialXEditor_source = CodeMirror.fromTextArea(materialx_source, {
191 mode: 'application/xml',
192 lineNumbers: true,
193 theme: 'dracula',
194 });
195 this.materialXEditor_source.setSize('auto', '100px');
196 //this.materialXEditor_source.setDisplay('none')
197 */
198 }

◆ updateConfigInfo()

MaterialXOCIOClient::updateConfigInfo ( message)

Definition at line 45 of file materialx_ocio_app.js.

45 {
46 const html = marked.parse(message);
47 const configDOM = document.getElementById('config_info')
48 configDOM.innerHTML = html;
49 this.convertTableToBootstrapRowCol(configDOM);
50 }

◆ updateMaterialXInfo()

MaterialXOCIOClient::updateMaterialXInfo ( data)

Definition at line 52 of file materialx_ocio_app.js.

52 {
53 console.log('Nodedef:\n',
54 data.nodedef_string, "\nImpl: ",
55 data.impl_string, "\nSource: ",
56 data.source_string
57 );
58
59 this.materialXEditor.setValue(data.nodedef_string);
60
61 let elem = document.getElementById('materialX_impl');
62 let content = data.impl_string;
63 if (content)
64 {
65 content = content.replace(/^\s*[\r\n]+|[\r\n]+\s*$/g, '');
66 elem.style.display = 'block'
67 elem.value = content;
68 const lines = content.split(/\r?\n/);
69 if (lines.length < 30)
70 elem.rows = lines.length;
71 else
72 elem.rows = 30;
73 }
74 else {
75 elem.style.display = 'none'
76 }
77
78 elem = document.getElementById('materialX_source')
79 content = data.source_string;
80 if (content)
81 {
82 content = content.replace(/^\s*[\r\n]+|[\r\n]+\s*$/g, '');
83 elem.style.display = 'block'
84 elem.value = content;
85 const lines = content.split(/\r?\n/);
86 if (lines.length < 10)
87 elem.rows = lines.length;
88 else
89 elem.rows = 10;
90 }
91 else {
92 elem.style.display = 'none'
93 }
94 }

◆ updateStatus()

MaterialXOCIOClient::updateStatus ( message,
force = false )

Definition at line 96 of file materialx_ocio_app.js.

96 {
97 const inputDOM = document.getElementById('status_message');
98 if (inputDOM.value == 'Status' || force)
99 inputDOM.value = message
100 else
101 inputDOM.value += '\n' + message
102 // Scroll to the bottom of the textarea
103 inputDOM.scrollTop = inputDOM.scrollHeight;
104 }

The documentation for this class was generated from the following file: