<plugin id="tuto13_mesh_generator_cpp" library="true">
    <requirement id="sight::module::ui" />
    <requirement id="sight::module::viz::scene3d" />
    <requirement id="sight::module::viz::scene3d_qt" />
    <requirement id="sight::module::ui::qt" />
    <requirement id="sight::module::service" />

    <extension implements="sight::service::extension::factory">
        <type>sight::ui::action</type>
        <service>tuto13_mesh_generator_cpp::mesh_modifier</service>
        <object>sight::data::mesh</object>
    </extension>

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

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

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

            <service uid="mainFrame" type="sight::module::ui::frame">
                <gui>
                    <frame>
                        <name>tuto13_mesh_generator_cpp</name>
                        <icon>tuto13_mesh_generator_cpp/tuto.ico</icon>
                    </frame>
                    <menubar />
                </gui>
                <registry>
                    <menubar sid="menuBarView" start="true" />
                    <view sid="genericSceneSrv" start="true" />
                </registry>
            </service>

            <service uid="progressBarView" type="sight::module::ui::job_bar" />

            <service uid="menuBarView" type="sight::module::ui::menubar">
                <gui>
                    <layout>
                        <menu name="File" />
                        <menu name="Modify" />
                    </layout>
                </gui>
                <registry>
                    <menu sid="menuFileView" start="true" />
                    <menu sid="modifierFileView" start="true" />
                </registry>
            </service>

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

            <service uid="modifierFileView" type="sight::module::ui::menu">
                <gui>
                    <layout>
                        <menuItem name="Shake mesh point" shortcut="Q" />
                        <separator />
                        <menuItem name="Colorize mesh point" shortcut="U" />
                        <menuItem name="Colorize mesh cells" shortcut="I" />
                        <separator />
                        <menuItem name="Compute points normals" shortcut="O" />
                        <menuItem name="Compute cells normals" shortcut="P" />
                        <separator />
                        <menuItem name="Shake points normals" shortcut="L" />
                        <menuItem name="Shake cells normals" shortcut="M" />
                        <separator />
                        <menuItem name="mesh deformation" shortcut="D" />
                    </layout>
                </gui>
                <registry>
                    <menuItem sid="shakeMeshPointAct" start="true" />
                    <menuItem sid="colorizeMeshPointAct" start="true" />
                    <menuItem sid="colorizeMeshCellsAct" start="true" />
                    <menuItem sid="colorizeComputePointsNormalsAct" start="true" />
                    <menuItem sid="colorizeComputeCellsNormalsAct" start="true" />
                    <menuItem sid="shakePointsNormalsAct" start="true" />
                    <menuItem sid="shakeCellsNormalsAct" start="true" />
                    <menuItem sid="meshDeformationAct" start="true" />
                </registry>
            </service>

            <!-- *************************** 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="meshAdp" />
                    </layer>
                </scene>
            </service>

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

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

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

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

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

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

            <service uid="shakeMeshPointAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="ShakeMeshPoint" />
            </service>

            <service uid="colorizeMeshPointAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="ColorizeMeshPoints" />
            </service>

            <service uid="colorizeMeshCellsAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="ColorizeMeshCells" />
            </service>

            <service uid="colorizeComputePointsNormalsAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="ComputePointNormals" />
            </service>

            <service uid="colorizeComputeCellsNormalsAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="ComputeCellNormals" />
            </service>

            <service uid="shakePointsNormalsAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="ShakePointNormals" />
            </service>

            <service uid="shakeCellsNormalsAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="ShakeCellNormals" />
            </service>

            <service uid="meshDeformationAct" type="tuto13_mesh_generator_cpp::mesh_modifier">
                <inout key="mesh" uid="mesh" />
                <config functor="MeshDeformation" />
            </service>

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

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

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

            <!-- ******************************* Connections ***************************************** -->
            <connect>
                <signal>meshReaderSrv/job_created</signal>
                <signal>meshWriterSrv/job_created</signal>
                <slot>progressBarView/show_job</slot>
            </connect>

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

            <connect>
                <signal>saveMeshAct/clicked</signal>
                <slot>meshWriterSrv/update</slot>
            </connect>

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

            <start uid="mainFrame" />
            <start uid="progressBarView" />
            <start uid="trackballInteractorAdp" />
            <start uid="meshAdp" />
            <start uid="meshReaderSrv" />
            <start uid="meshWriterSrv" />
        </config>
    </extension>
</plugin>
