<?xml version="1.0" encoding="UTF-8"?>
<!--
    This file is a test input file for ActionStateMachine.
    The ASM here is very simple:
    - Open an image with the Open Action
    - Name it openedImage
    - Apply a manual threshol on this image
           	- with low threshold to arbitrary set to 58
           	- with high threshold arbitrary set to 153
    - Name the output image thresholdImage
    - Save this output image in the same directory as the input image.
-->
<scxml      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
            xmlns='http://camitk.imag.fr/3/smallScxml'
            xmlns:camitk='http://camitk.imag.fr/3/asm'
            xsi:schemaLocation='http://camitk.imag.fr/3/smallScxml ../resources/smallScxml.xsd'
            applicationName="Simple Mesh Processing"
            initial="Initialize"
>
    <state id="Initialize">
        <onentry>
            <camitk:onState>
                <camitk:description>
<![CDATA[
This Action State Machine performs a very simple mesh processing pipeline.<br/>
<b>Warning!</b> This scxml uses relative path for automatically open file without the
user intervention. It uses the "Set Path To Test Data" action to set the working directory
to the testdata directory before running.
<ul>
    <li>Set current directory (working directory) to CamiTK test data</li>
    <li>Automatically Open the Mesh.off example</li>
    <li>Decimate the mesh</li>
    <li>Close without saving</li>
    <li>Quit the application</li>
]]>
                </camitk:description>
                <camitk:action>
                    <camitk:name>Set Path To Test Data</camitk:name>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Next" target="Open Mesh Example" applyAction="true"/>
    </state>
    
    <state id="Open Mesh Example">
        <onentry>
            <camitk:onState>
                <camitk:description>Open a supported mesh file (default "Mesh.off" from the testdata directory).</camitk:description>
                <camitk:action>
                    <camitk:name>Open File</camitk:name>
                    <camitk:parameters>
                        <camitk:parameter name="File Name" type="QString" value="Mesh.off"/>
                    </camitk:parameters>
                    <camitk:outputs>
                        <camitk:component type="MeshComponent" name="exampleMesh"/>
                    </camitk:outputs>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Back" target="Initialize" applyAction="false"/>
        <transition event="Next" target="Mesh Decimation" applyAction="true" />
    </state>

    <state id="Mesh Decimation">
        <onentry>
            <camitk:onState>
                <camitk:description>Decimate the mesh.</camitk:description>
                <camitk:action>
                    <camitk:name>Decimation</camitk:name>
                    <!-- no parameters: use the default values -->
                    <camitk:inputs>
                         <camitk:component type="MeshComponent" name="exampleMesh"/>
                    </camitk:inputs>
                    <camitk:outputs>
                        <camitk:component type="MeshComponent" name="decimatedMesh"/>
                    </camitk:outputs>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Back" target="Open Mesh Example" applyAction="false">
            <camitk:onTransition>
                <camitk:close>
                    <camitk:component type="MeshComponent" name="exampleMesh"/>
                </camitk:close>
            </camitk:onTransition>
        </transition>
        <transition event="Next" target="Save Mesh" applyAction="true"/>
    </state>

    <state id="Save Mesh">
        <onentry>
            <camitk:onState>
                <camitk:description>Save the decimated mesh</camitk:description>
                <camitk:action>
                    <camitk:name>Save</camitk:name>
                    <camitk:inputs>
                         <camitk:component type="MeshComponent" name="decimatedMesh"  suffix=".vtk"/>
                    </camitk:inputs>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Back" target="Mesh Decimation" applyAction="false">
            <camitk:onTransition>
                <camitk:close>
                    <camitk:component type="MeshComponent" name="decimatedMesh"/>
                </camitk:close>
            </camitk:onTransition>
        </transition>		
        <transition event="Next" target="Force Close" applyAction="true"/>
    </state>

    <state id="Force Close">
        <onentry>
            <camitk:onState>
                <camitk:description>Clicking Next will close all the mesh</camitk:description>
            </camitk:onState>
        </onentry>        
        <transition event="Back" target="Mesh Decimation" applyAction="false">
            <camitk:onTransition>
                <camitk:close>
                    <camitk:component type="MeshComponent" name="decimatedMesh" force="true"/>
                </camitk:close>
            </camitk:onTransition>
        </transition>
        <transition event="Next" target="Bye">
            <camitk:onTransition>
                <camitk:close>
                    <camitk:component type="MeshComponent" name="decimatedMesh" force="true"/>
                    <camitk:component type="MeshComponent" name="exampleMesh"/>
                </camitk:close>
            </camitk:onTransition>
        </transition>
    </state>    

    <state id="Bye" final="true">
        <onentry>
            <camitk:onState>
                <camitk:description>
<![CDATA[
<b><i> Congratulations ! </i></b><br/>
<i>Press <b>Quit</b> to quit the application or <b>Back to the Beginning</b> to
to re-run the application from the beginning.
]]>
                </camitk:description>
            </camitk:onState>
        </onentry>
        <transition event="Back to the Beginning" target="Initialize"/>
    </state>
</scxml>
