PNGS = aluminium \
	field \
	iso \
	map \
	planes \
	color \
	links \
	vibs \
	vibsxyz

UIS = test_reload \
	test_inter

SVGS = cinchonidine

TESTS = $(PNGS) $(SVGS) $(UIS)

SRCDIR := ../examples

aluminium.args := $(SRCDIR)/aluminium.d3 -r alu.xml
field.args := $(SRCDIR)/aluminium.d3 -p $(SRCDIR)/planes.xml -f $(SRCDIR)/density-sih4.dat -v 0.01:0.05
iso.args := $(SRCDIR)/test_isosurfaces.ascii -i $(SRCDIR)/test_isosurfaces.surf
map.args := $(SRCDIR)/aluminium.d3 -p $(SRCDIR)/planes.xml -f $(SRCDIR)/density-sih4.dat -b 1 -n 10 -o box_show_lengths=1
planes.args := $(SRCDIR)/demo.ascii -p $(SRCDIR)/planes.xml
color.args := -c $(SRCDIR)/diff.dat $(SRCDIR)/diff.ascii -o main_unit=Bohr -d 12 -x 0.05:0:0 --color-clamp 1\#1e-3:5e-2 --scaling-column 2
links.args := link.ascii -o opengl_theta_phi_omega="90 -90 0" -o "pair_link[Au Mo  4.505 4.55]"="1.000 0.000 0.000  1  1  Wire pairs" -o "pair_link[Au Mo  5.495 5.505]"="0.000 1.000 0.000  1  0  Cylinder pairs" -o "pairCylinder_linkRadius[Au Mo  5.495 5.505]"=1. -o "pairCylinder_linkColorType[Au Mo  6.495 6.505]"=1 -o "pair_link[Au Mo  6.495 6.505]"="0.000 1.000 0.000  1  0  Cylinder pairs" -o fog_is_on=0
vibs.args := $(SRCDIR)/anime.ascii --phonon-mode 3 --time-offset 0.25 --phonon-amplitude 0.2 -x 0:0:1 -o fog_start_end="0.4 0.9"
vibsxyz.args := $(SRCDIR)/coord_vib_g_co.xyz --phonon-mode 42 --time-offset 0.25 --phonon-amplitude 2.

test_reload.args := $(SRCDIR)/aluminium.d3
test_inter.args := $(SRCDIR)/aluminium.d3

cinchonidine.args := $(SRCDIR)/cinchonidine.yaml -o opengl_theta_phi_omega="90 50 0" -o "backgroundColor_color"="0.538 0.667 0.699 1.0"

BIN = ../tmp/src/v_sim-dev
IMGDIFF = python imgdiff.py

OUTPUTS = $(PNGS:=.png_diff) $(PNGS:=.PNGlog) $(SVGS:=.svg_diff) $(SVGS:=.svg) $(SVGS:=.png) $(SVGS:=.log) $(UIS:=.ui_diff) $(UIS:=.UIlog) test_resources.log test_resources.diff tmp.res.xml

all: $(OUTPUTS)

clean:
	rm -f $(TESTS:=.diff*) $(OUTPUTS) $(PNGS:=.png) $(PNGS:=.win.png) $(UIS:=.win.png) 

.PHONY: clean
.SUFFIXES: .PNGlog .png_diff .svg .svg_diff .UIlog .ui_diff

#$(PNGS:=.png_diff): $(PNGS:=.PNGlog)
$(SVGS:=.svg_diff): $(SVGS:=.svg)

%.PNGlog: $(@:.PNGlog=)
	$(BIN) $($(@:.PNGlog=.args)) -e $(@:.PNGlog=.png) > $@ 2>&1
	$(BIN) $($(@:.PNGlog=.args)) -o pyScript=dump.v_sim.py >> $@ 2>&1 && mv out.win.png $(@:.PNGlog=.win.png)

.PNGlog.png_diff:
	$(IMGDIFF) $(<:.PNGlog=) $(<:.PNGlog=.ref.png) $(<:.PNGlog=.png) $(<:.PNGlog=.win.png) > $@

%.svg:
	$(BIN) $($(@:.svg=.args)) -e $@ > $(@:.svg=.log) 2>&1

.svg.svg_diff:
	convert $< -resize 600x600  $(<:.svg=.png)
	$(IMGDIFF) $(<:.svg=) $(<:.svg=.ref.png) $(<:.svg=.png) $(<:.svg=.flat.png) > $@

%UIlog: $(@:.UIlog=)
	$(BIN) $($(@:.UIlog=.args)) -o pyScript=$(@:.UIlog=).v_sim.py >> $@ 2>&1 && mv out.win.png $(@:.UIlog=.win.png)

.UIlog.ui_diff:
	$(IMGDIFF) $(<:.UIlog=) $(<:.UIlog=.ref.png) $(<:.UIlog=.win.png) > $@

test_resources.log tmp.res.xml: test_resources.v_sim.py
	$(BIN) -r ./v_sim.res.xml -o pyScript=$< > $@ 2>&1

test_resources.diff: tmp.res.xml
	diff ref.res.xml $< > $@
	@cat $@
