#!/bin/bash
###################################
# author: Matthieu Hendriks
# date: 01-2024
# license: free to use and adept, no warranty grom the author
# title: osm OpenScad Menu
# description:
#	just a simple script for a popup menu, for a file selectiopn and to activate the other scripts 
# 	it saves the last working directory to ~/.osm.rc
# installation:
#	sudo apt install yad			# yet another dialogprogramm for file selection and a popup menu
#	sudo cp scad2stl /usr/bin		# included script
#	sudo cp scad2gif /usr/bin		# included script
#	sudo cp scad4include /usr/bin		# included script
#	sudo cp scadcreate /usr/bin		# included script
#	sudo cp osm /usr/bin			# included script
###################################

# set -x		# if you want some debugging
DIR=$(<~/.osm.rc)
cd ${DIR}
if [[ ${PWD} != *"openscad_drawings"* ]]; then
	cd ~/openscad_drawings
fi
file=`yad --file-selection --title="Select scad file" --file-filter=*.scad `
echo "$file"
DIR="$(dirname "${file}")";
file=${file##*/}
if [ "$file" = "" ]; then
	exit
fi
cd $DIR
echo "${DIR}" >~/.osm.rc
chmod +x ~/.osm.rc
opt=`yad --list --height=300 --width=300 --text="Welke functie" --column="Functie:" scad2stl scad4include scad2mp4 Quit`
opt=${opt::-1}		# strip de "|" van de optie
echo "keuze: $opt $file"

if [ "$opt" = "scad2stl" ]; then
	    scad2stl $file
fi
if [ "$opt" = "scad4include" ]; then
	    scad4include $file
fi
if [ "$opt" = "scad2mp4" ]; then
	    scad2mp4 $file
fi
exit

