#!/bin/sh
# IFe_autocad
# if no /tmp/CAD directory and default file create...
if test ! -d /tmp/CAD ; then
  mkdir /tmp/CAD
  chmod a+w /tmp/CAD
fi
if test ! -f /tmp/CAD/default.dxf ; then
  cp ${IFE_HOME}/misc/CAD/default.dxf /tmp/CAD/default.dxf
fi

# echo what is in /tmp/CAD to a backup directory.
if test ! -d /tmp/CAD2 ; then
  mkdir /tmp/CAD2
  chmod a+w /tmp/CAD2
fi
cp -r /tmp/CAD /tmp/CAD2

# first see if autocad is available on this machine, if
# so then run it otherwise show an image
if test ! -f ${IFE_HOME}/sys/bin/acad.remote ; then
	echo    "emulation	aec	${IFE_HOME}/lib/images/acad_image.ex"
	${IFE_HOME}/sys/bin/vww -ex ${IFE_HOME}/lib/images/acad_image.ex

# get petri to shift token to the subsequent transition.
# echo	shift_next_transition

# store the current default dxf file.
schema=`${IFE_HOME}/sys/bin/dialog -p "Name of the Autocad (dxf) file you created?" -file "/tmp/CAD/default.dxf " -d "/tmp/CAD/default.dxf"  -h1 "DXF is the format for this file." -h2 "Give the name unknown if nothing" -h3 " created. Choose the default if in doubt."`
	echo	"store	archcad	autocad	autocad	$schema"
	echo	"archcad_complete	$schema"
	exit 0
fi

# acadx.remote is the shell script which does the actual connect to
# a remote host, change it to work with a different machine etc.
xterm -g 75x35+150+300 -name "remote acad session" -e ${IFE_HOME}/sys/bin/acadx.remote

# get petri to shift token to the subsequent transition.
echo	shift_next_transition
echo	xxxxx

# Ask user what they just created.
schema=`${IFE_HOME}/sys/bin/dialog -p "Name of the dxf file you created?" -file "/tmp/CAD/ " -d "/tmp/CAD/default.dxf" -h1 "The file must have been saved as a dxf file for it" -h2 "to be readable. Give the name unknown if" -h3 "nothing. choose the default if in doubt."`

if [ ! Y$schema = Y ]; then
	if [ $schema = 'unknown' ]; then
		echo	"unknown schema will not be stored..."
		echo	"archcad_complete	unknown"
	else
		echo	"store	archcad	autocad	autocad	$schema"
		echo	"archcad_complete	$schema"
	fi
fi
exit 0
