<plugin id="Tuto15Matrix" >

    <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>Tuto15Matrix_AppCfg</id>
        <config>

        <!-- ******************************* Objects declaration ****************************** -->

        <!-- Mesh object associated to the uid 'mesh' -->
        <object uid="mesh"              type="sight::data::Mesh" />
        <!-- Matrix object associated to the uid 'matrix' -->
        <object uid="matrix"            type="sight::data::Matrix4" />
        <!-- Translation matrix object associated to the uid 'translationMatrix' -->
        <object uid="translationMatrix" type="sight::data::Matrix4" />
        <!-- Rotation matrix object associated to the uid 'rotationMatrix' -->
        <object uid="rotationMatrix"    type="sight::data::Matrix4" />
        <object uid="transRotMatrix"    type="sight::data::Matrix4" />
        <object uid="rotTransMatrix"    type="sight::data::Matrix4" />

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

        <service uid="mainFrame" type="sight::module::ui::base::SFrame" >
            <gui>
                <frame>
                    <name>Tuto15Matrix</name>
                    <icon>Tuto15Matrix/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::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+M" />
                    <separator />
                    <menuItem name="Quit" specialAction="QUIT" shortcut="Ctrl+Q" />
                </layout>
            </gui>
            <registry>
                <menuItem sid="openMeshAct" start="true" />
                <menuItem sid="quitAct" start="true" />
            </registry>
        </service>

        <!--
            Default view service:
            The type 'sight::ui::base::LineLayoutManager' represents a layout where the view are aligned
            horizontally or vertically (set orientation value 'horizontal' or 'vertical').
            It is possible to add a 'proportion' attribute for the <view> to defined the proportion
            used by the view compared to the others.
        -->
        <service uid="containerView" type="sight::module::ui::base::SView" >
            <gui>
                <layout type="sight::ui::base::LineLayoutManager" >
                    <orientation value="horizontal" />
                    <view proportion="2" />
                    <view proportion="1" backgroundColor="#36393E" />
                </layout>
            </gui>
            <registry>
                <view sid="genericSceneSrv" start="true" />
                <view sid="editorsView" start="true" />
            </registry>
        </service>

        <service uid="editorsView" type="sight::module::ui::base::SView" >
            <gui>
                <layout type="sight::ui::base::LineLayoutManager" >
                    <orientation value="vertical" />
                    <view proportion="1" />
                    <view proportion="4" />
                </layout>
            </gui>
            <registry>
                <view sid="shhowMeshSrv" start="true" />
                <view sid="matrixView" start="true" />
            </registry>
        </service>

        <service uid="matrixView" type="sight::module::ui::qt::viz::STransformEditor" autoConnect="false" >
            <inout key="matrix" uid="matrix" />
            <translation enabled="true" min="-300" />
            <rotation enabled="true" min="-180" max="180" />
        </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" />

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

        <!--
            Mesh view:
            This scene display two meshes.
        -->
        <service uid="genericSceneSrv" type="sight::viz::scene3d::SRender" >
            <scene>
                <background topColor="#36393E" bottomColor="#36393E" />

                <layer id="default" order="1" />
                <adaptor uid="trackballInteractorAdp" />
                <adaptor uid="mesh1Adp" />
                <adaptor uid="mesh2Adp" />
                <adaptor uid="matrix1Adp" />
                <adaptor uid="matrix2Adp" />
                <adaptor uid="axis1Adp" />
                <adaptor uid="axis2Adp" />
                <adaptor uid="originAxisAdp" />
                <adaptor uid="text1Adp" />
                <adaptor uid="text2Adp" />
            </scene>
        </service>

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

        <!-- Mesh adaptors -->
        <service uid="mesh1Adp" type="sight::module::viz::scene3d::adaptor::SMesh"  autoConnect="true" >
            <in key="mesh" uid="mesh" />
            <config layer="default" transform="transRotMat" />
        </service>

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

        <!--
            Defines transform adaptors:
            This adaptor works on a sight::data::Matrix4 and manages a vtkTransform. When
            the sight::data::Matrix4 is modified, it updates the vtkTransform, and vice
            versa.
        -->
        <service uid="matrix1Adp" type="sight::module::viz::scene3d::adaptor::STransform" autoConnect="true" >
            <inout key="transform" uid="transRotMatrix" />
            <config layer="default" transform="transRotMat" />
        </service>

        <service uid="matrix2Adp" type="sight::module::viz::scene3d::adaptor::STransform" autoConnect="true" >
            <inout key="transform" uid="rotTransMatrix" />
            <config layer="default" transform="rotTransMat" />
        </service>

        <service uid="axis1Adp" type="sight::module::viz::scene3d::adaptor::SAxis" >
            <config layer="default" length="10" transform="transRotMat" label="false" origin="true" originColor="#6997BB" name="Base" />
        </service>

        <service uid="axis2Adp" type="sight::module::viz::scene3d::adaptor::SAxis" >
            <config layer="default" length="10" transform="rotTransMat" label="false" origin="true" originColor="#D25252" />
        </service>

        <service uid="originAxisAdp" type="sight::module::viz::scene3d::adaptor::SAxis" >
            <config layer="default" length="10" label="false" origin="true" originColor="#000000" />
        </service>

        <service uid="text1Adp" type="sight::module::viz::scene3d::adaptor::SText" >
            <text>Translation-Rotation transform</text>
            <config layer="default" color="#FF0000" fontSize="15" hAlign="left" vAlign="bottom" />
        </service>

        <service uid="text2Adp" type="sight::module::viz::scene3d::adaptor::SText" >
            <text>Rotation-Translation transform</text>
            <config layer="default" color="#00FF00" fontSize="15" hAlign="right" vAlign="bottom" />
        </service>


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

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

        <!--
            Defines matrixDecomposerAdp service:
            This service decompose a matrix into a rotation matrix and a translation matrix
        -->
        <service uid="matrixDecomposerAdp" type="sight::module::geometry::base::SDecomposeMatrix" >
            <in key="source" uid="matrix" autoConnect="true" />
            <inout key="translation" uid="translationMatrix" />
            <inout key="rotation" uid="rotationMatrix" />
        </service>

        <!-- to multiply matrices -->
        <service uid="concatenateTranslationAndRotationArv" type="sight::module::geometry::base::SConcatenateMatrices" autoConnect="true" >
            <in group="matrix" >
                <key uid="translationMatrix" />
                <key uid="rotationMatrix" />
            </in>
            <inout key="output" uid="transRotMatrix" />
        </service>

        <!-- to multiply matrices -->
        <service uid="concatenateRotationAndTranslationSrv" type="sight::module::geometry::base::SConcatenateMatrices" autoConnect="true" >
            <in group="matrix" >
                <key uid="rotationMatrix" />
                <key uid="translationMatrix" />
            </in>
            <inout key="output" uid="rotTransMatrix" />
        </service>

        <service uid="shhowMeshSrv" type="sight::module::ui::qt::SParameters" >
             <parameters>
                 <param type="bool" name="Show/Hide Mesh" key="boolParam" defaultValue="true" />
             </parameters>
        </service>

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

        <connect>
            <signal>shhowMeshSrv/boolChanged</signal>
            <slot>mesh1Adp/updateVisibility</slot>
            <slot>mesh2Adp/updateVisibility</slot>
        </connect>

        <connect>
            <signal>trackballInteractorAdp/started</signal>
            <slot>genericSceneSrv/resetCameras</slot>
        </connect>

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

        <start uid="mainFrame" />
        <start uid="matrixDecomposerAdp" />
        <start uid="concatenateTranslationAndRotationArv" />
        <start uid="concatenateRotationAndTranslationSrv" />
        <start uid="mesh1Adp" />
        <start uid="mesh2Adp" />
        <start uid="matrix1Adp" />
        <start uid="matrix2Adp" />
        <start uid="axis1Adp" />
        <start uid="axis2Adp" />
        <start uid="originAxisAdp" />
        <start uid="text1Adp" />
        <start uid="text2Adp" />
        <start uid="trackballInteractorAdp" />

        </config>
    </extension>

</plugin>
