Skip to content

Commit

Permalink
added batch importing
Browse files Browse the repository at this point in the history
  • Loading branch information
itstorque committed Oct 30, 2022
1 parent db84e25 commit 565fa3f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 30 deletions.
19 changes: 13 additions & 6 deletions LTspiceDraw/built_in_symbols.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# NOTE: when you edit a symbol in here, it won't
# take effect until you reload symbols. Eventually
# add a method to update this user side...

from enum import Enum

class SYMBOLS(Enum):

GND = """LINE Normal 0 0 0 4 2
LINE Normal -12 4 12 4 2
LINE Normal -12 4 0 16 2
LINE Normal 0 16 12 4 2"""
GND = """
LINE Normal -12 0 12 0 2
LINE Normal -12 0 0 12 2
LINE Normal 0 12 12 0 2
"""

NODE = """LINE Normal -4 4 4 4 2
NODE = """
LINE Normal -4 4 4 4 2
LINE Normal -4 4 -4 -4 2
LINE Normal 4 4 4 -4 2
LINE Normal -4 -4 4 -4 2"""
LINE Normal -4 -4 4 -4 2
"""

def __call__(self):
return self.value
2 changes: 2 additions & 0 deletions LTspiceDraw/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ def from_ltspice_gui_command(self, cmd, *args, **kwargs):
elif text[0] == "!":
type = TextNetlist.Command
text = text[1:]
else:
type = None

return Text(Coord(cmd[0], cmd[1]), text, text_align=cmd[2].lower(), font_size=font_size, type=type)

Expand Down
1 change: 0 additions & 1 deletion LTspiceDraw/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def __init__(self, localStorage, key, missing_symbol_handler, directory_invarian
for name, source in self.get_dicts().items():
self.symbols_source[name] = source


if "gnd" not in self.symbols_source or "node" not in self.symbols_source:
self.add_base_symbols()

Expand Down
34 changes: 30 additions & 4 deletions web/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ function tooltip_redraw(event) {

}

function show_toast(title, message) {

$.toast({
title: title,
message: message,
showProgress: 'bottom',
position: 'bottom right',
class: 'teal'
});

}

batch_upload_progress = $('#batch_upload_progress')
function set_batch_upload_count(value) {
batch_upload_progress.progress({
total: value,
text: {
active: '{value} of {total} done'
}
})
}

controlling_canvas.addEventListener('mousedown', onMouseDown);
controlling_canvas.addEventListener('mousemove', onMouseMove);
controlling_canvas.addEventListener('mouseup', onMouseUp);
Expand Down Expand Up @@ -253,6 +275,10 @@ $('#styling_button')
})
;

$('.add_symbol_button').click( () => {
$('#add_symbol').modal('show')
})

// $('#source_code_button')
// .popup({
// popup : $('#source_code'),
Expand Down Expand Up @@ -320,10 +346,10 @@ thickness_slider = $('#line_thickness')

thickness_slider
.slider({
min: 0.1,
max: 5,
start: 2,
step: 0.1,
min: 0.05,
max: 5.0,
start: 1.0,
step: 0.05,
onChange: function(value) {
render();
}
Expand Down
30 changes: 15 additions & 15 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

<body>

<input type="file" id="file-upload" accept=".asc,.asy" hidden>

<canvas id="canvas" style="background-color:#fff; width: 100vw; height: 100vh; position: fixed; top: 0; z-index: -1;"></canvas>
<canvas id="tooltips_canvas" style="width: 100vw; height: 100vh; position: fixed; top: 0; z-index: 0;"></canvas>

Expand All @@ -38,7 +40,7 @@
</py-config>


<py-script output="out" src="./web.py" hidden></py-script>
<py-script src="./web.py" hidden></py-script> <!-- output="out" -->

<div class="ui tiny modal" id="missing_symbol">
<div class="header">Missing Symbol</div>
Expand All @@ -50,7 +52,7 @@ <h5>List Of Missing Symbols:</h5>
<p id="list-of-missing-symbols"></p>
</div>
<div class="actions">
<div class="ui positive button">Add Symbols</div>
<div class="ui positive button add_symbol_button">Add Symbols</div>
<div class="ui cancel button">Ok</div>
</div>
</div>
Expand All @@ -67,29 +69,27 @@ <h5>List Of Missing Symbols:</h5>
<div class="ui tiny modal" id="add_symbol">

<div class="header">Missing Symbol</div>

<p id="out"></p>

<input type="file" id="file-upload" accept=".asc,.asy" hidden>

<label for="file-upload" class="ui labeled green icon button">
<i class="ui upload icon"></i>
Upload Schematic
</label>

<div class="ui teal progress" id="batch_upload_progress">
<div class="bar">
<div class="progress"></div>
</div>
<div class="label"></div>
</div>

<div class="actions">

<input type="file" id="symbol-upload-folder" accept=".asy" webkitdirectory multiple hidden>
<input type="file" id="batch-symbol-upload" accept=".asy" webkitdirectory mozdirectory multiple hidden>
<input type="file" id="symbol-upload" accept=".asy" multiple hidden>

<label for="symbol-upload" class="ui labeled icon button">
<i class="ui folder open icon"></i>
Import Sybmol to Library
Import Sybmols
</label>

<label for="symbol-upload" class="ui labeled icon button">
<label for="batch-symbol-upload" class="ui olive labeled icon button">
<i class="ui folder icon"></i>
Import Sybmol Folder
Batch Import
</label>
</div>
</div>
Expand Down
32 changes: 28 additions & 4 deletions web/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,43 @@ def symbol_missing_method(symbol_name):

def add_symbol_from_source(event):
stash = WebSymbolStash(localStorage, "symbols", symbol_missing_method)
stash.add(event.target.filename.replace(".asy", ""), event.target.result)
stash.add(event.target.filename, event.target.result)

event.target.handler()

def add_symbols(event):
fileList = document.getElementById('symbol-upload').files
def add_symbols(event, fileList=None, handler=None):
if fileList==None:
fileList = document.getElementById('symbol-upload').files

for f in fileList:

reader = FileReader.new()

onload_event = create_proxy(add_symbol_from_source)

reader.filename = f.name
reader.filename = f.name.replace(".asy", "")

if handler == None:
reader.handler = lambda: js.show_toast("Symbol added", "Added symbol " + reader.filename)
else:
reader.handler = handler

reader.onload = onload_event

reader.readAsText(f)

def batch_symbol_upload_handler():
js.batch_upload_progress.progress('increment')

def batch_add_symbols(event):

fileList = document.getElementById('batch-symbol-upload').files

js.set_batch_upload_count(len(fileList))

add_symbols(event, fileList, handler=batch_symbol_upload_handler)


def main():

document.schematic = CircuitSchematic(WebSymbolStash(localStorage, "symbols", symbol_missing_method))
Expand All @@ -138,6 +158,7 @@ def main():
# Create a Python proxy for the callback function
file_event = create_proxy(process_file)
symbol_event = create_proxy(add_symbols)
batch_symbol_event = create_proxy(batch_add_symbols)
redraw_event = create_proxy(redraw)
ui_click = create_proxy(click_canvas)
export_event = create_proxy(export_to)
Expand All @@ -149,6 +170,9 @@ def main():
e = document.getElementById("symbol-upload")
e.addEventListener("change", symbol_event, False)

e = document.getElementById("batch-symbol-upload")
e.addEventListener("change", batch_symbol_event, False)

canvas.addEventListener("redraw", redraw_event, False)
canvas.addEventListener("export_to", export_event, False)
tooltips_canvas.addEventListener("ui_click", ui_click, False)
Expand Down

0 comments on commit 565fa3f

Please sign in to comment.