<!--
        This tutorial explains how to perform matrix transformation using the generic scene.

        To use this application, you need to load a mesh.
-->
<plugin id="tuto09_matrix_transform_in_gs">
    <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>Tuto09MatrixTransformInGS_AppCfg</id>
        <config>
            <!-- ******************************* Objects declaration ****************************** -->

            <object uid="matrixA" type="sight::data::matrix4">
                <matrix>
                    <![CDATA[
                        1 0 0 2
                        0 1 0 0
                        0 0 1 0
                        0 0 0 1
                    ]]>
                </matrix>
            </object>

            <object uid="matrixB" type="sight::data::matrix4">
                <matrix>
                    <![CDATA[
                        1 0 0 4
                        0 1 0 0
                        0 0 1 0
                        0 0 0 1
                    ]]>
                </matrix>
            </object>

            <object uid="matrixC" type="sight::data::matrix4">
                <matrix>
                    <![CDATA[
                        1 0 0 0
                        0 1 0 0
                        0 0 1 2
                        0 0 0 1
                    ]]>
                </matrix>
            </object>

            <object uid="matrixD" type="sight::data::matrix4">
                <matrix>
                    <![CDATA[
                        0.75 0        0        0
                        0        0.75 0        0
                        0        0        0.75 0
                        0        0        0    1
                    ]]>
                </matrix>
            </object>

            <object uid="matrixE" type="sight::data::matrix4" />

            <object uid="rotation1" type="sight::data::matrix4" />

            <object uid="rotation2" type="sight::data::matrix4" />

            <object uid="rotation3" type="sight::data::matrix4" />

            <object uid="mesh" type="sight::data::mesh" />

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

            <service uid="mainFrame" type="sight::module::ui::frame">
                <gui>
                    <frame>
                        <name>tuto09_matrix_transform_in_gs</name>
                        <icon>tuto09_matrix_transform_in_gs/tuto.ico</icon>
                        <minSize width="800" height="600" />
                    </frame>
                    <menubar />
                </gui>
                <registry>
                    <menubar sid="menuBarView" start="true" />
                    <view sid="mainView" 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 mesh" shortcut="Ctrl+O" />
                        <separator />
                        <menuItem name="Quit" shortcut="Ctrl+Q" specialAction="QUIT" />
                    </layout>
                </gui>
                <registry>
                    <menuItem sid="openMeshAct" start="true" />
                    <menuItem sid="quitAct" start="true" />
                </registry>
            </service>

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

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

            <!--
                Generic scene:
                This scene shows four times the same mesh but with a different matrix. It manages multiples transformation matrices.
            -->
            <service uid="genericSceneSrv" type="sight::viz::scene3d::render">
                <scene>
                    <background topColor="#36393E" bottomColor="#36393E" />

                    <layer id="default" order="1">
                        <adaptor uid="trackballInteractorAdp" />
                        <adaptor uid="mesh0Adp" />
                        <adaptor uid="transform1Adp" />
                        <adaptor uid="mesh1Adp" />
                        <adaptor uid="transform2Adp" />
                        <adaptor uid="mesh2Adp" />
                        <adaptor uid="transform3Adp" />
                        <adaptor uid="mesh3Adp" />
                    </layer>
                </scene>
            </service>

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

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

            <service uid="transform1Adp" type="sight::module::viz::scene3d::adaptor::transform" auto_connect="true">
                <inout key="transform" uid="rotation1" />
                <config transform="rotationTransform1" />
            </service>

            <service uid="mesh1Adp" type="sight::module::viz::scene3d::adaptor::mesh" auto_connect="true">
                <in key="mesh" uid="mesh" />
                <config transform="rotationTransform1" />
            </service>

            <service uid="transform2Adp" type="sight::module::viz::scene3d::adaptor::transform" auto_connect="true">
                <inout key="transform" uid="rotation2" />
                <config transform="rotationTransform2" />
            </service>

            <service uid="mesh2Adp" type="sight::module::viz::scene3d::adaptor::mesh" auto_connect="true">
                <in key="mesh" uid="mesh" />
                <config transform="rotationTransform2" />
            </service>

            <service uid="transform3Adp" type="sight::module::viz::scene3d::adaptor::transform" auto_connect="true">
                <inout key="transform" uid="rotation3" />
                <config transform="rotationTransform3" />
            </service>

            <service uid="mesh3Adp" type="sight::module::viz::scene3d::adaptor::mesh" auto_connect="true">
                <in key="mesh" uid="mesh" />
                <config transform="rotationTransform3" />
            </service>

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

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

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

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

            <service uid="matrixEditorSrv" type="sight::module::ui::qt::viz::transform_editor">
                <inout key="matrix" uid="matrixE" />
                <translation enabled="false" />
                <rotation enabled="y" min="0" max="360" />
            </service>

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

            <service uid="rotation1Srv" type="sight::module::geometry::concatenate_matrices">
                <in group="matrix">
                    <key uid="matrixE" auto_connect="true" />
                    <key uid="matrixA" />
                    <key uid="matrixD" />
                </in>
                <inout key="output" uid="rotation1" />
            </service>

            <service uid="rotation2Srv" type="sight::module::geometry::concatenate_matrices">
                <in group="matrix">
                    <key uid="matrixB" />
                    <key uid="matrixE" auto_connect="true" />
                    <key uid="matrixE" />
                    <key uid="matrixE" />
                    <key uid="matrixD" />
                    <key uid="matrixD" />
                </in>
                <inout key="output" uid="rotation2" />
            </service>

            <service uid="rotation3Srv" type="sight::module::geometry::concatenate_matrices">
                <in group="matrix">
                    <key uid="matrixC" />
                    <key uid="matrixE" auto_connect="true" />
                    <key uid="matrixD" />
                    <key uid="matrixD" />
                    <key uid="matrixD" />
                </in>
                <inout key="output" uid="rotation3" />
            </service>

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

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

            <start uid="mainFrame" />
            <start uid="rotation1Srv" />
            <start uid="rotation2Srv" />
            <start uid="rotation3Srv" />
            <start uid="trackballInteractorAdp" />
            <start uid="mesh0Adp" />
            <start uid="transform1Adp" />
            <start uid="mesh1Adp" />
            <start uid="transform2Adp" />
            <start uid="mesh2Adp" />
            <start uid="transform3Adp" />
            <start uid="mesh3Adp" />
            <start uid="meshReaderSrv" />

            <update uid="rotation1Srv" />
            <update uid="rotation2Srv" />
            <update uid="rotation3Srv" />
        </config>
    </extension>
</plugin>
