|  | 
| 23 | 23 | import { stripTags } from '#/simulator/src/utils' | 
| 24 | 24 | import { useState } from '#/store/SimulatorStore/state' | 
| 25 | 25 | import messageBox from '@/MessageBox/messageBox.vue' | 
| 26 |  | -import { ref } from 'vue' | 
| 27 |  | -import { onMounted } from 'vue' | 
|  | 26 | +import { ref, onMounted, watch } from 'vue' | 
| 28 | 27 | 
 | 
| 29 | 28 | /* imports from combinationalAnalysis.js */ | 
| 30 | 29 | import { GenerateCircuit, solveBooleanFunction } from '#/simulator/src/combinationalAnalysis' | 
| @@ -200,62 +199,17 @@ function createLogicTable() { | 
| 200 | 199 |         alertType.value = 'info' | 
| 201 | 200 |         alertMessage.value = | 
| 202 | 201 |             'Enter Input / Output Variable(s) OR Boolean Function!' | 
| 203 |  | -        setTimeout(() => { | 
|  | 202 | +        watch(showAlert, () => { | 
| 204 | 203 |             showAlert.value = false | 
| 205 |  | -        }, 2000) | 
|  | 204 | +        }, { timeout: 2000 }) | 
| 206 | 205 |     } else { | 
| 207 | 206 |         showAlert.value = true | 
| 208 | 207 |         alertType.value = 'warning' | 
| 209 | 208 |         alertMessage.value = | 
| 210 | 209 |             'Use Either Combinational Analysis Or Boolean Function To Generate Circuit!' | 
| 211 |  | -        setTimeout(() => { | 
|  | 210 | +        watch(showAlert, () => { | 
| 212 | 211 |             showAlert.value = false | 
| 213 |  | -        }, 2000) | 
| 214 |  | -    } | 
| 215 |  | -} | 
| 216 |  | -
 | 
| 217 |  | -function printBooleanTable() { | 
| 218 |  | -    // Create a new div to hold the table content | 
| 219 |  | -    const tableContent = document.createElement('div') | 
| 220 |  | -    tableContent.innerHTML = tableHeader.value.map((header, index) => ` | 
| 221 |  | -        <tr> | 
| 222 |  | -            <th>${header}</th> | 
| 223 |  | -        </tr> | 
| 224 |  | -    `).join('') +  | 
| 225 |  | -    tableBody.value.map(row => ` | 
| 226 |  | -        <tr> | 
| 227 |  | -            ${row.map(cell => `<td>${cell}</td>`).join('')} | 
| 228 |  | -        </tr> | 
| 229 |  | -    `).join('') | 
| 230 |  | -
 | 
| 231 |  | -    const style = ` | 
| 232 |  | -        <style> | 
| 233 |  | -            table {font: 40px Calibri;} | 
| 234 |  | -            table, th, td {border: solid 1px #DDD; border-collapse: collapse;} | 
| 235 |  | -            tbody {padding: 2px 3px; text-align: center;} | 
| 236 |  | -        </style> | 
| 237 |  | -    `.replace(/\n/g, '') | 
| 238 |  | -
 | 
| 239 |  | -    const win = window.open('', '', 'height=700,width=700') | 
| 240 |  | -    if (win) { | 
| 241 |  | -        const htmlBody = ` | 
| 242 |  | -            <html> | 
| 243 |  | -                <head> | 
| 244 |  | -                    <title>Boolean Logic Table</title> | 
| 245 |  | -                    ${style} | 
| 246 |  | -                </head> | 
| 247 |  | -                <body> | 
| 248 |  | -                    <center> | 
| 249 |  | -                        <table> | 
| 250 |  | -                            ${tableContent.innerHTML} | 
| 251 |  | -                        </table> | 
| 252 |  | -                    </center> | 
| 253 |  | -                </body> | 
| 254 |  | -            </html> | 
| 255 |  | -        ` | 
| 256 |  | -        win.document.write(htmlBody) | 
| 257 |  | -        win.document.close() | 
| 258 |  | -        win.print() | 
|  | 212 | +        }, { timeout: 2000 }) | 
| 259 | 213 |     } | 
| 260 | 214 | } | 
| 261 | 215 | 
 | 
| @@ -334,6 +288,53 @@ function createBooleanPrompt(inputList, outputList, scope = globalScope) { | 
| 334 | 288 |         }, | 
| 335 | 289 |     ] | 
| 336 | 290 | } | 
|  | 291 | +
 | 
|  | 292 | +function printBooleanTable() { | 
|  | 293 | +    // Get the table content using Vue refs | 
|  | 294 | +    const messageBoxContent = document.querySelector('.messageBox .v-card-text')?.innerHTML || '' | 
|  | 295 | +
 | 
|  | 296 | +    const style = ` | 
|  | 297 | +        <style> | 
|  | 298 | +            table { font: 40px Calibri; } | 
|  | 299 | +            table, th, td { border: solid 1px #DDD; border-collapse: collapse; } | 
|  | 300 | +            tbody { padding: 2px 3px; text-align: center; } | 
|  | 301 | +        </style> | 
|  | 302 | +    `.replace(/\n\s*/g, '') | 
|  | 303 | +
 | 
|  | 304 | +    const htmlBody = ` | 
|  | 305 | +        <!DOCTYPE html> | 
|  | 306 | +        <html> | 
|  | 307 | +        <head> | 
|  | 308 | +            <title>Boolean Logic Table</title> | 
|  | 309 | +            ${style} | 
|  | 310 | +        </head> | 
|  | 311 | +        <body> | 
|  | 312 | +            <center>${messageBoxContent}</center> | 
|  | 313 | +        </body> | 
|  | 314 | +        </html> | 
|  | 315 | +    ` | 
|  | 316 | +
 | 
|  | 317 | +    // Create a new window for printing | 
|  | 318 | +    const printWindow = window.open('', '_blank', 'height=700,width=700') | 
|  | 319 | +    if (printWindow) { | 
|  | 320 | +        printWindow.document.write(htmlBody) | 
|  | 321 | +        printWindow.document.close() | 
|  | 322 | +        // Wait for resources to load before printing | 
|  | 323 | +        printWindow.onload = () => { | 
|  | 324 | +            printWindow.print() | 
|  | 325 | +            printWindow.onafterprint = () => { | 
|  | 326 | +                printWindow.close() | 
|  | 327 | +            } | 
|  | 328 | +        } | 
|  | 329 | +    } else { | 
|  | 330 | +        showAlert.value = true | 
|  | 331 | +        alertType.value = 'error' | 
|  | 332 | +        alertMessage.value = 'Please allow popups to print the truth table' | 
|  | 333 | +        watch(showAlert, () => { | 
|  | 334 | +            showAlert.value = false | 
|  | 335 | +        }, { timeout: 3000 }) | 
|  | 336 | +    } | 
|  | 337 | +} | 
| 337 | 338 | </script> | 
| 338 | 339 | 
 | 
| 339 | 340 | <style scoped> | 
|  | 
0 commit comments