#!/bin/bash
#requires Xyce (SPICE), libreoffice5.0 --calc, xdotool, and xclip
#create a Eeschema schematic using SPICE compatible components
#then do
#menu > Tools > Generate Netlist File > Spice (check Default format)
#point "Simulation command:" to this script then select "Run Simulation"
#sit back while the simulation and plot are done automatically
#if the GUI changes then this script must be updated
#this script is licensed under the GNU GPLv3
mkdir $(dirname $1)/simulation
mv $1 $(dirname $1)/simulation/$(basename $1)
cd $(dirname $1)/simulation
Xyce $(dirname $1)/simulation/$(basename $1)
libreoffice5.0 --calc $(dirname $1)/simulation/$(basename $1).csv &
sleep 2s
xdotool key KP_Enter
sleep 1s
xdotool key Control_L+a Alt_L+i Up Up Up Up KP_Enter
sleep 1s
xdotool key Tab Down Down Down Down Tab Right Right Tab Tab Tab Tab KP_Enter
sleep 1s
xdotool key Tab Tab Tab Tab Tab space Tab Tab Tab Tab Tab Tab Tab Tab Tab Down Down Tab Tab Tab
sleep 1s
xdotool key T i m e space Shift_L+9 s Shift_L+0 Tab
xdotool key V o l t a g e space Shift_L+9 v Shift_L+0
xdotool key KP_Enter
xdotool key Alt_L+o x x KP_Enter
sleep 1s
xdotool key Menu Down Down KP_Enter Tab Tab Tab Down Down
sleep 1s
xdotool key Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Menu Down Down Down KP_Enter Tab Tab Tab Tab 1 0 0 KP_Enter
sleep 1s
xdotool key Escape Menu Down Down KP_Enter Escape Escape Control_L+s
sleep 1s
xclip -selection clipboard -t image/png -o > ./plot.png
xdotool key Alt_L+F4
sleep 1s
xdotool key Escape Alt_L+p i
echo -n "$(dirname $1)/simulation/plot.png" | xclip -selection clipboard
xdotool click 1
sleep 1s
xdotool key Ctrl+v KP_Enter
#option to put the image on the canvas for you
#omit these last three lines if you want tp place it yourself
sleep 1s
xdotool click 1
xdotool key Escape
