<plugin id="tuto06_filter">
    <requirement id="sight::module::service" />
    <requirement id="sight::module::ui::qt" />

    <extension implements="sight::app::extension::config">
        <id>Tuto06Filter_AppCfg</id>
        <config>
            <!-- ******************************* Objects declaration ****************************** -->

            <!-- This is the source image for the filtering. -->
            <object uid="myImage1" type="sight::data::image" />
            <!-- This is the output image for the filtering. "deferred" defines that the image is not created at the
                 beginning, but will be created by a service. -->
            <object uid="myImage2" type="sight::data::image" deferred="true" />

            <!-- ******************************* UI declaration *********************************** -->

            <!-- Windows & Main Menu -->
            <service uid="mainFrame" type="sight::module::ui::frame">
                <gui>
                    <frame>
                        <name>tuto06_filter</name>
                        <icon>tuto06_filter/tuto.ico</icon>
                        <minSize width="1280" height="720" />
                    </frame>
                    <menubar />
                </gui>
                <registry>
                    <menubar sid="menuBarView" start="true" />
                    <view sid="containerView" start="true" />
                </registry>
            </service>

            <service uid="menuBarView" type="sight::module::ui::menubar">
                <gui>
                    <layout>
                        <menu name="File" />
                        <menu name="filter" />
                    </layout>
                </gui>
                <registry>
                    <menu sid="menuFileView" start="true" />
                    <menu sid="menuFilterView" start="true" />
                </registry>
            </service>

            <!-- Menus -->
            <service uid="menuFileView" type="sight::module::ui::menu">
                <gui>
                    <layout>
                        <menuItem name="Open image" shortcut="Ctrl+O" />
                        <separator />
                        <menuItem name="Quit" specialAction="QUIT" shortcut="Ctrl+Q" />
                    </layout>
                </gui>
                <registry>
                    <menuItem sid="openImageAct" start="true" />
                    <menuItem sid="quitAct" start="true" />
                </registry>
            </service>

            <service uid="menuFilterView" type="sight::module::ui::menu">
                <gui>
                    <layout>
                        <menuItem name="Compute image filter" />
                        <menuItem name="Toggle vertical image flipping" />
                    </layout>
                </gui>
                <registry>
                    <menuItem sid="imageFilterAct" start="true" />
                    <menuItem sid="imageFlipperAct" start="true" />
                </registry>
            </service>

            <service uid="containerView" type="sight::module::ui::view">
                <gui>
                    <layout type="sight::ui::layout::line">
                        <orientation value="horizontal" />
                        <view proportion="1" />
                        <view proportion="1" />
                    </layout>
                </gui>
                <registry>
                    <view sid="image1Srv" start="true" />
                    <!-- As the output image is deferred, the service cannot be started at the beginning. -->
                    <view sid="image2Srv" start="false" />
                </registry>
            </service>

            <!-- ******************************* Actions ****************************************** -->

            <!-- Action to quit the application -->
            <service uid="quitAct" type="sight::module::ui::quit" />

            <!-- Action to open image file: call update on image reader service -->
            <service uid="openImageAct" type="sight::module::ui::action" />

            <!-- Action apply threshold filter: call update on threshold filter service -->
            <service uid="imageFilterAct" type="sight::module::ui::action" />

            <!-- Action apply flip filter: call 'flipAxisY' slot on flip service -->
            <service uid="imageFlipperAct" type="sight::module::ui::action" />

            <!-- ******************************* Services ***************************************** -->

            <!-- Reader of the input image -->
            <service uid="imageReaderSrv" type="sight::module::ui::io::selector">
                <inout key="data" uid="myImage1" />
                <type mode="reader" />
            </service>

            <!--
                Threshold filter:
                Applies a threshold filter. The source image is 'myImage1' and the
                output image is 'myImage2'.
                The two images are declared above.
             -->
            <service uid="imageFilterSrv" type="sight::module::filter::image::threshold">
                <in key="source" uid="myImage1" />
                <out key="target" uid="myImage2" />
                <config>
                    <threshold>50</threshold>
                </config>
            </service>

            <!--
                Flip filter:
                Applies a flip filter. The source image is 'myImage1' and the
                output image is 'myImage2'.
                The two images are declared above.
             -->
            <service uid="imageFlipperSrv" type="sight::module::filter::image::flip">
                <in key="source" uid="myImage1" />
                <out key="target" uid="myImage2" />
            </service>

            <!--
                Renderer of the 1st image:
                This is the source image for the filtering.
            -->
            <service uid="image1Srv" type="sight::module::viz::sample::image">
                <in key="image" uid="myImage1" />
            </service>

            <!--
                Rendered for the 2nd image:
                This is the output image for the filtering.
            -->
            <service uid="image2Srv" type="sight::module::viz::sample::image">
                <in key="image" uid="myImage2" />
            </service>

            <!-- ******************************* Start services ***************************************** -->

            <connect>
                <signal>openImageAct/updated</signal>
                <slot>imageReaderSrv/update</slot>
            </connect>

            <connect>
                <signal>imageFilterAct/updated</signal>
                <slot>imageFilterSrv/update</slot>
            </connect>

            <connect>
                <signal>imageFlipperAct/updated</signal>
                <slot>imageFlipperSrv/flip_axis_y</slot>
            </connect>

            <start uid="mainFrame" />
            <start uid="imageReaderSrv" />
            <start uid="imageFilterSrv" />
            <start uid="imageFlipperSrv" />

            <!-- start the service using a deferred image -->
            <start uid="image2Srv" />
        </config>
    </extension>
</plugin>
