<plugin id="Tuto06Filter" >

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

    <extension implements="::sight::service::extension::AppConfig" >
        <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" src="deferred" />

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

            <!-- Windows & Main Menu -->
            <service uid="mainFrame" type="sight::module::ui::base::SFrame" >
                <gui>
                    <frame>
                        <name>Tuto06Filter</name>
                        <icon>Tuto06Filter/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::base::SMenuBar" >
                <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::base::SMenu" >
                <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::base::SMenu" >
                <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::base::SView" >
                <gui>
                    <layout type="sight::ui::base::LineLayoutManager" >
                        <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::base::SQuit" />

            <!-- Action to open image file: call update on image reader service -->
            <service uid="openImageAct" type="sight::module::ui::base::com::SSlotCaller" >
                <slots>
                    <slot>imageReaderSrv/update</slot>
                </slots>
            </service>

            <!-- Action apply threshold filter: call update on threshold filter service -->
            <service uid="imageFilterAct" type="sight::module::ui::base::com::SSlotCaller" >
                <slots>
                    <slot>imageFilterSrv/update</slot>
                </slots>
            </service>

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

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

            <!-- Reader of the input image -->
            <service uid="imageReaderSrv" type="sight::module::ui::base::io::SSelector" >
                <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::SThreshold" >
                <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::SFlip" >
                <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::SImage" >
                <in key="image" uid="myImage1" autoConnect="true" />
            </service>

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

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

            <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>
