Skip to content

Commit 41335ab

Browse files
authored
Update CombinationalAnalysis.vue
1 parent a2e14d9 commit 41335ab

File tree

1 file changed

+69
-96
lines changed

1 file changed

+69
-96
lines changed

src/components/DialogBox/CombinationalAnalysis.vue

+69-96
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import { stripTags } from '#/simulator/src/utils'
2424
import { useState } from '#/store/SimulatorStore/state'
2525
import messageBox from '@/MessageBox/messageBox.vue'
26-
import { ref, onMounted, watch } from 'vue'
26+
import { ref } from 'vue'
27+
import { onMounted } from 'vue'
2728
2829
/* imports from combinationalAnalysis.js */
2930
import { GenerateCircuit, solveBooleanFunction } from '#/simulator/src/combinationalAnalysis'
@@ -199,83 +200,78 @@ function createLogicTable() {
199200
alertType.value = 'info'
200201
alertMessage.value =
201202
'Enter Input / Output Variable(s) OR Boolean Function!'
202-
watch(showAlert, () => {
203+
setTimeout(() => {
203204
showAlert.value = false
204-
}, { timeout: 2000 })
205+
}, 2000)
205206
} else {
206207
showAlert.value = true
207208
alertType.value = 'warning'
208209
alertMessage.value =
209210
'Use Either Combinational Analysis Or Boolean Function To Generate Circuit!'
210-
watch(showAlert, () => {
211+
setTimeout(() => {
211212
showAlert.value = false
212-
}, { timeout: 2000 })
213+
}, 2000)
213214
}
214215
}
215216
216-
function createBooleanPrompt(inputList, outputList) {
217-
inputListNames.value = inputList || prompt('Enter inputs separated by commas')?.split(',') || []
218-
outputListNames.value = outputList || prompt('Enter outputs separated by commas')?.split(',') || []
219-
217+
function createBooleanPrompt(inputList, outputList, scope = globalScope) {
218+
inputListNames.value =
219+
inputList || prompt('Enter inputs separated by commas').split(',')
220+
outputListNames.value =
221+
outputList || prompt('Enter outputs separated by commas').split(',')
220222
if (output.value == null) {
221-
outputListNamesInteger.value = outputListNames.value.map((_, i) => 7 * i + 13)
223+
for (var i = 0; i < outputListNames.value.length; i++) {
224+
outputListNamesInteger.value[i] = 7 * i + 13
225+
} // assigning an integer to the value, 7*i + 13 is random
222226
} else {
223227
outputListNamesInteger.value = [13]
224228
}
225-
226-
// Reset table data
227229
tableBody.value = []
228230
tableHeader.value = []
229-
230-
// Add decimal column if checkbox is checked
231-
let columnOffset = 0
232-
if (inputArr.value[4].val === true) {
233-
columnOffset = 1
231+
let fw = 0
232+
if (inputArr.value[4].val == true) {
233+
fw = 1
234234
tableHeader.value.push('dec')
235235
}
236-
237-
// Add input headers
238-
inputListNames.value.forEach(name => {
239-
tableHeader.value.push(name)
240-
})
241-
242-
// Add output headers
236+
for (var i = 0; i < inputListNames.value.length; i++) {
237+
tableHeader.value.push(inputListNames.value[i])
238+
}
243239
if (output.value == null) {
244-
outputListNames.value.forEach(name => {
245-
tableHeader.value.push(name)
246-
})
240+
for (var i = 0; i < outputListNames.value.length; i++) {
241+
tableHeader.value.push(outputListNames.value[i])
242+
}
247243
} else {
248244
tableHeader.value.push(outputListNames.value)
249245
}
250246
251-
// Generate table body
252-
const rowCount = 1 << inputListNames.value.length
253-
tableBody.value = Array(rowCount).fill(null).map((_, rowIndex) => {
254-
const row = new Array(tableHeader.value.length).fill(null)
255-
256-
// Add decimal column if needed
257-
if (columnOffset) {
258-
row[0] = rowIndex
247+
for (var i = 0; i < 1 << inputListNames.value.length; i++) {
248+
tableBody.value[i] = new Array(tableHeader.value.length)
249+
}
250+
for (var i = 0; i < inputListNames.value.length; i++) {
251+
for (var j = 0; j < 1 << inputListNames.value.length; j++) {
252+
tableBody.value[j][i + fw] = +(
253+
(j & (1 << (inputListNames.value.length - i - 1))) !=
254+
0
255+
)
259256
}
260-
261-
// Add input columns
262-
inputListNames.value.forEach((_, colIndex) => {
263-
row[colIndex + columnOffset] = +((rowIndex & (1 << (inputListNames.value.length - colIndex - 1))) !== 0)
264-
})
265-
266-
// Add output columns
267-
if (output.value == null) {
268-
outputListNamesInteger.value.forEach((_, i) => {
269-
row[inputListNames.value.length + columnOffset + i] = 'x'
270-
})
271-
} else {
272-
row[inputListNames.value.length + columnOffset] = output.value[rowIndex]
257+
}
258+
if (inputArr.value[4].val == true) {
259+
for (var j = 0; j < 1 << inputListNames.value.length; j++) {
260+
tableBody.value[j][0] = j
273261
}
274-
275-
return row
276-
})
277-
278-
// Update UI
262+
}
263+
for (var j = 0; j < 1 << inputListNames.value.length; j++) {
264+
for (var i = 0; i < outputListNamesInteger.value.length; i++) {
265+
if (output.value == null) {
266+
tableBody.value[j][inputListNames.value.length + fw + i] = 'x'
267+
}
268+
}
269+
if (output.value != null) {
270+
tableBody.value[j][inputListNames.value.length + fw] =
271+
output.value[j]
272+
}
273+
}
274+
// display Message Box
279275
SimulatorState.dialogBox.combinationalanalysis_dialog = true
280276
buttonArr.value = [
281277
{
@@ -290,50 +286,27 @@ function createBooleanPrompt(inputList, outputList) {
290286
}
291287
292288
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-
`
289+
var sTable = $('.messageBox .v-card-text')[0].innerHTML
316290
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-
}
291+
var style =
292+
`<style>
293+
table {font: 40px Calibri;}
294+
table, th, td {border: solid 1px #DDD;border-collapse: 0;}
295+
tbody {padding: 2px 3px;text-align: center;}
296+
</style>`.replace(/\n/g, "")
297+
var win = window.open('', '', 'height=700,width=700')
298+
var htmlBody = `
299+
<html><head>\
300+
<title>Boolean Logic Table</title>\
301+
${style}\
302+
</head>\
303+
<body>\
304+
<center>${sTable}</center>\
305+
</body></html>
306+
`
307+
win.document.write(htmlBody)
308+
win.document.close()
309+
win.print()
337310
}
338311
</script>
339312

0 commit comments

Comments
 (0)