<plugin id="tuto11_picker">
    <requirement id="sight::module::ui" />
    <requirement id="sight::module::viz::scene3d" />
    <requirement id="sight::module::ui::qt" />
    <requirement id="sight::module::service" />

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

            <object uid="mesh" type="sight::data::mesh" />
            <object uid="image" type="sight::data::image" />
            <object uid="snapshot" type="sight::data::image" />
            <object uid="tf" type="sight::data::transfer_function" />

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

            <service uid="mainFrame" type="sight::module::ui::frame">
                <gui>
                    <frame>
                        <name>tuto11_picker</name>
                        <icon>tuto11_picker/tuto.ico</icon>
                        <minSize width="800" height="600" />
                    </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" />
                    </layout>
                </gui>
                <registry>
                    <menu sid="menuFileView" start="true" />
                </registry>
            </service>

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

            <service uid="containerView" type="sight::module::ui::view">
                <gui>
                    <layout type="sight::ui::layout::line">
                        <orientation value="vertical" />
                        <view proportion="0" backgroundColor="#3E4453" />
                        <view proportion="1" />
                    </layout>
                </gui>
                <registry>
                    <view sid="pointEditorSrv" start="true" />
                    <view sid="sceneView" start="true" />
                </registry>
            </service>

            <service uid="sceneView" type="sight::module::ui::view">
                <gui>
                    <layout type="sight::ui::layout::line">
                        <orientation value="vertical" />
                        <view proportion="1" />
                        <view proportion="0" minHeight="30" backgroundColor="#3E4453" />
                    </layout>
                </gui>
                <registry>
                    <view sid="genericSceneSrv" start="true" />
                    <view sid="editorsView" start="true" />
                </registry>
            </service>

            <service uid="editorsView" type="sight::module::ui::view">
                <gui>
                    <layout type="sight::ui::layout::line">
                        <orientation value="horizontal" />
                        <view proportion="0" minWidth="50" />
                        <view proportion="1" />
                        <view proportion="0" minWidth="30" />
                    </layout>
                </gui>
                <registry>
                    <view sid="showNegatoSrv" start="true" />
                    <view sid="sliderIndexEditorSrv" start="true" />
                    <view sid="snapshotSrv" start="true" />
                </registry>
            </service>

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

            <service uid="openImageAct" type="sight::module::ui::action" />
            <service uid="openMeshAct" type="sight::module::ui::action" />

            <service uid="quitAct" type="sight::module::ui::quit" />

            <!-- *************************** Begin generic scene *************************** -->

            <service uid="genericSceneSrv" type="sight::viz::scene3d::render">
                <scene>
                    <background topColor="#36393E" bottomColor="#36393E" />

                    <layer id="default" order="1">
                        <adaptor uid="trackballInteractorAdp" />
                        <adaptor uid="pickerInteractorAdp" />
                        <adaptor uid="meshAdp" />
                        <adaptor uid="negatoAdp" />
                        <adaptor uid="snapshotAdp" />
                    </layer>
                </scene>
            </service>

            <service uid="trackballInteractorAdp" type="sight::module::viz::scene3d::adaptor::trackball_camera">
                <config priority="0" />
            </service>

            <service uid="pickerInteractorAdp" type="sight::module::viz::scene3d::adaptor::voxel_picker">
                <in key="image" uid="image" />
                <config mode="3D" priority="1" />
            </service>

            <service uid="meshAdp" type="sight::module::viz::scene3d::adaptor::mesh" auto_connect="true">
                <in key="mesh" uid="mesh" />
            </service>

            <service uid="negatoAdp" type="sight::module::viz::scene3d::adaptor::negato3d" auto_connect="true">
                <in key="image" uid="image" />
                <inout key="tf" uid="tf" />
                <config sliceIndex="axial" interactive="true" />
            </service>

            <service uid="snapshotAdp" type="sight::module::viz::scene3d::adaptor::fragments_info">
                <inout key="image" uid="snapshot" />
            </service>

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

            <service uid="snapshotSrv" type="sight::module::ui::qt::com::signal_button">
                <config>
                    <checkable>false</checkable>
                    <icon>sight::module::ui::icons/frame.svg</icon>
                </config>
            </service>

            <service uid="showNegatoSrv" type="sight::module::ui::qt::com::signal_button">
                <config>
                    <checkable>true</checkable>
                    <icon>sight::module::ui::icons/cross.svg</icon>
                    <icon2>sight::module::ui::icons/layers.svg</icon2>
                    <iconWidth>40</iconWidth>
                    <iconHeight>16</iconHeight>
                    <checked>true</checked>
                </config>
            </service>

            <service uid="pointEditorSrv" type="sight::module::ui::qt::viz::point_editor" />

            <service uid="meshReaderSrv" type="sight::module::ui::io::selector">
                <inout key="data" uid="mesh" />
                <type mode="reader" />
            </service>

            <service uid="imageReaderSrv" type="sight::module::ui::io::selector">
                <inout key="data" uid="image" />
                <type mode="reader" />
            </service>

            <service uid="sliderIndexEditorSrv" type="sight::module::ui::qt::image::slice_index_position_editor" auto_connect="true">
                <inout key="image" uid="image" />
                <config orientation="axial" label="index" display_axis_selector="false" display_step_buttons="false" />
            </service>

            <!-- Write the snapshot image -->
            <service uid="imageWriterSrv" type="sight::module::io::bitmap::writer">
                <in key="data" uid="snapshot" />
                <dialog policy="always" />
                <backends enable="all" mode="best" />
            </service>

            <!-- ******************************* Connections ***************************************** -->

            <connect>
                <signal>snapshotSrv/clicked</signal>
                <slot>imageWriterSrv/update</slot>
            </connect>

            <connect>
                <signal>showNegatoSrv/toggled</signal>
                <slot>negatoAdp/update_visibility</slot>
            </connect>

            <connect>
                <signal>pickerInteractorAdp/picked</signal>
                <slot>pointEditorSrv/get_interaction</slot>
            </connect>

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

            <connect>
                <signal>openMeshAct/clicked</signal>
                <slot>meshReaderSrv/update</slot>
            </connect>

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

            <start uid="mainFrame" />
            <start uid="imageWriterSrv" />
            <start uid="trackballInteractorAdp" />
            <start uid="pickerInteractorAdp" />
            <start uid="meshAdp" />
            <start uid="negatoAdp" />
            <start uid="snapshotAdp" />
            <start uid="imageReaderSrv" />
            <start uid="meshReaderSrv" />
        </config>
    </extension>
</plugin>
