.. _part-settings-tutorial:

############################################
UnstructGrid: Apply Part Settings to a Model
############################################

.. image:: ../images/tut_partsettings.png
    :height: 300
    :align: center

Various part settings can be applied to the different parts in the model to improve
the visual representation of the data. Part settings are, for instance, visibility, 
highlighting, draw style, colors and result visibility.

Each part has its own settings.

This tutorial shows how to apply some part settings to parts in the model.

The demo file (contact.vtfx) contains a geometry with four parts. This tutorial shows 
how to set the following settings on these parts:

-   Part 1: Set invisible
-   Part 2: Set color to blue
-   Part 3: Set draw style surface mesh
-   Part 4: Set opacity

Load the file and setup the model specification to show the result. For a more thorough 
explanation on creating a data source from a file interface and setup the model specification,
see the Load VTFx tutorial:
:ref:`simple-load-vtf-tutorial`

.. note::
    This tutorial expect the application to have a correctly configured :class:`cee::vis::View`
    in place. See demo applications on how to set up a :class:`cee::vis::View` in your application.

**Load model**

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 46-48,50-56,58


Create the model and a VTFx file interface data source. Open the file and set the created data
source in the model.

Set the first state as current in the model specification.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 61-63

**Part settings**

Get the part ids for the four parts in this model. Part info is available in the data sources
metadata directory. We know this model only has one geometry and four parts.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 74-78

Set the first part invisible

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 81

Give the second part the color blue

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 84

Use surface mesh draw style at the third part

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 87

Set the fourth part transparent

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 90

**Set up the created model**

The model is ready to use and can be added to the view. Exactly where the view exists
depends on the platform and solution. These examples uses Qt and the view is set up 
in a :class:`cee::qt::ViewerWidget`.

.. literalinclude:: ../../../../EnvisionDesktop/Tutorials/PartSettings.cpp
    :language: cpp
    :lines: 93,95,97

**See the complete source code here:**

:ref:`part-settings-example`

