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

        To use this application, you need to load a mesh.
-->
<plugin id="Tuto09MatrixTransformInGS" >

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

    <extension implements="::sight::service::extension::AppConfig" >
        <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::base::SFrame" >
                <gui>
                    <frame>
                        <name>Tuto09MatrixTransformInGS</name>
                        <icon>Tuto09MatrixTransformInGS/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::base::SMenuBar" >
                <gui>
                    <layout>
                        <menu name="File" />
                    </layout>
                </gui>
                <registry>
                    <menu sid="menuFileView" start="true" />
                </registry>
            </service>

            <service uid="menuFileView" type="sight::module::ui::base::SMenu" >
                <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::base::SView" >
                <gui>
                    <layout type="sight::ui::base::LineLayoutManager" >
                        <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::SRender" >
                <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" />
                </scene>
            </service>

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

            <service uid="mesh0Adp" type="sight::module::viz::scene3d::adaptor::SMesh" autoConnect="true" >
                <inout key="mesh" uid="mesh" />
                <config layer="default" />
            </service>

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

            <service uid="mesh1Adp" type="sight::module::viz::scene3d::adaptor::SMesh" autoConnect="true" >
                <inout key="mesh" uid="mesh" />
                <config layer="default" transform="rotationTransform1" />
            </service>

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

            <service uid="mesh2Adp" type="sight::module::viz::scene3d::adaptor::SMesh" autoConnect="true" >
                <inout key="mesh" uid="mesh" />
                <config layer="default" transform="rotationTransform2" />
            </service>

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

            <service uid="mesh3Adp" type="sight::module::viz::scene3d::adaptor::SMesh" autoConnect="true" >
                <inout key="mesh" uid="mesh" />
                <config layer="default" transform="rotationTransform3" />
            </service>

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

            <service uid="openMeshAct" type="sight::module::ui::base::com::SStarter" >
                <start uid="meshReaderSrv" />
            </service>

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

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

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

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

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

            <service uid="rotation2Srv" type="sight::module::geometry::base::SConcatenateMatrices" >
                <in group="matrix" >
                    <key uid="matrixB" />
                    <key uid="matrixE" autoConnect="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::base::SConcatenateMatrices" >
                <in group="matrix" >
                    <key uid="matrixC" />
                    <key uid="matrixE" autoConnect="true" />
                    <key uid="matrixD" />
                    <key uid="matrixD" />
                    <key uid="matrixD" />
                </in>
                <inout key="output" uid="rotation3" />
            </service>

            <!-- ******************************* 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" />

            <update uid="rotation1Srv" />
            <update uid="rotation2Srv" />
            <update uid="rotation3Srv" />

        </config>
    </extension>
</plugin>
