#!/bin/sh
# IFe_manager
# if no /tmp/ESP directory and default file create...
if test ! -d /tmp/ESP ; then
  mkdir /tmp/ESP
fi
if test ! -f /tmp/ESP/demo_building ; then
  cp -r ${IFE_HOME}/misc/ESP /tmp
fi

# first see if the project manager is available on this machine, if
# so then run it otherwise show an image
if test ! -f ${IFE_HOME}/sys/bin/prj ; then
	echo    "emulation	esp	${IFE_HOME}/lib/images/esp-r.ex"
	${IFE_HOME}/sys/bin/vww -ex ${IFE_HOME}/lib/images/esp-r.ex

# store default esp configuration.
schema=`${IFE_HOME}/sys/bin/dialog -p "Name of the esp configuration file ?" -file "/tmp/ESP/default.cfg " -d "/tmp/ESP/default.cfg" -h1 "The configuration file defines the simulation problem" -h2 "Choose the default if in doubt."`
	echo	"store	attribute	esp	esp	$schema"

	# get petri to shift token to the subsequent transition.
	#echo "shift_next_transition"
	echo "Attribute DTF has exited"

	exit 0
fi

# get step file from DES

finish=no
while ( [ X$finish != "Xyes" ] )
do
   xterm -g 75x35+150+300 -name "DES Transaction" -e ${IFE_HOME}/sys/bin/SCKTncl_stp
#   xterm -g 75x35+150+300 -name "DES Transaction"

   finish=`${IFE_HOME}/sys/bin/dialog -p "Are all DES transactions complete ?" -file "yes" -d "yes" -h1 "type yes or no" -h2 "type yes or no"`

done

# invoke step-to-esp-r mapping and fetch esp-r files 

#finish=no
#while ( [ X$finish != "Xyes" ] )
#do
#   xterm -geometry 75x35+150+300 -name "Step to ESP-r mapping" -e ${IFE_HOME}/sys/bin/SCKTtud_dte
#   xterm -geometry 75x35+150+300 -name "Step to ESP-r mapping"
#   finish=`${IFE_HOME}/sys/bin/dialog -p "*** step-to-ATTRIBUTE mapping complete ***" -file "yes" -d "yes" -h1 "type yes or no" -h2 "type yes or no"`

#done

# invoke ATTRIBUTE

finish=no
while ( [ X$finish != "Xyes" ] )
do

   if [ $# -lt 1 ]; then
     ${IFE_HOME}/sys/bin/prj  -file /tmp/ESP/default.cfg
   else
     ${IFE_HOME}/sys/bin/prj  -file $1
   fi

   finish=`${IFE_HOME}/sys/bin/dialog -p "Are you finished with this DTF ?" -file "yes" -d "yes" -h1 "type yes or no" -h2 "type yes or no"`

done

# Ask user what they just created.
schema=`${IFE_HOME}/sys/bin/dialog -p "Name of the attributed model ?" -file "/tmp/ESP/demo_building+" -d "/tmp/ESP/default.cfg" -h1 "The configuration file defines the simulation problem" -h2 "Choose the default if in doubt."`
if [ ! Y$schema = Y ]; then
	if [ $schema = 'unknown' ]; then
   		echo	"schema is blank"
	else
		echo	"store	attribution	esp	esp	$schema "
	fi
fi

# get petri to shift token to the subsequent transition.
#echo "shift_next_transition"
echo "Attribute DTF has exited"

exit 0
