Setting Colors of Products and Parts

The color of a part or a product can be changed while playing a simulation. You can set the color and the opacity via a color lookup table or by setting RGB and opacity values (0 to 255). The object to color must be a part or a product belonging to a resource.

This task shows you how to:


Before you begin: The System and Device Designer workbench should be opened.

Set Color in SFC+

You can insert a Set Color action in a SFC+ graph.

  1. Open a resource that has sub-products in the Live Simulation environment (see a typical example below).



  2. To open the SFC+ Editor, do one of the following:

    • Expand the content of the Main block and double-click Behavior.
    • Right-click the Main block and select Behavior Editor.
    • Select Behavior Editor in the Main window toolbar.

    A 2D immersive window is opened to edit the block behavior. A toolbox at the right side of the window contains the SFC+ Editor commands.

    Note: In our example, the resource logic is undefined, so the editor is empty.

  3. Select Set Color in the Activities toolbox.

  4. If the 2D immersive window is in front of the 3D object, click in the 3D view.

    The SFC+ Editor window becomes transparent.

  5. Select the part to position.

    The selected part is highlighted and a bubble attached to it appears.

    Tip: Select another part if you want to change the target.

  6. Click the bubble to confirm the selection of the product.



    The Color Properties dialog box appears.

  7. To select the color, you can do one of the following:

    • Select Color.




      • Click the palette or set the R,G,B values. Then, click outside the palette window to validate your choice.
      • Click Basic Colors and select a color.
    • Select RGB: You have to enter the value of the Red, Green and Blue colors (type: int32, range: 0...255). You can also enter the name of a signal or a port.



      Note: If you have entered port or signal names not yet defined in the block, you must check As Port or As Signal in the Declaration frame. The ports or signals are automatically created with the activity.

    • Select Restore Color: the color is the color of the product or the part.



    For our example, select Restore Color.

  8. In the Action frame, you can fill Condition with a boolean expression. Then, the action Set Color is triggered only if the condition is true.

    Note: If you select Sustain, the Set color activity is applied at each step the step is active. This is useful if the color is set by ports and signals and their value changes.

  9. Click OK. Then, click in the SFC+ Editor to position a new step.

    A first step of the SFC+ graph is created. The action contains a square displaying the selected color followed by the name of the product (or the part) being the target of the activity.

  10. Create a new Set color action in the SFC+:

    1. Select Set Color in the Activities toolbox.
    2. Select the part Green Lens.1 in the 3D view.
    3. Click the bubble to confirm the selection of the product.
    4. Select a color.

    5. Click OK and click in the SFC+ Editor to position a new step.



  11. Select Add Transition in the Tools toolbar, click the initial step and then, the second step.



  12. Double-click the transition to change the condition.



  13. Click OK.



    The transition appears in red because the signal Power is undefined.

  14. Select the Main block and select Edit Properties in its contextual menu.

    The Block Properties dialog box appears.

  15. Click Add port and change the name of the new port to Power.



  16. Click OK.

    The transition is no more in red.

  17. Repeat the step 11. and 12. to create a transition between the step S1 and S0. Set the transition condition to Power=false.



  18. Close the SFC+ Editor.

  19. To test the behavior of the activity in simulation:

    1. Select the Main block and click Play in the compass.

      The block is compiled and the simulation is initialized. The Simulation toolbar and the Signals Monitoring window appear.

    2. Click Next in the control bar of the compass.

      As the first action is to restore the original color, the led does not change.

    3. Expand the Ports node of the Signals Monitoring window and force the value of Power to true.



    4. Press Enter.
    5. Click Next in the control bar of the compass.

      The led is highlighted by the color change.

    6. Repeat the step c. and force the value of Power to false.
    7. Click Next. The initial color of the led is restored.
    8. Click the Play of the compass to close the simulation.

Set Color in Dataflow

You can insert a Set Color block in a Dataflow graph. In Dataflow, the color lookup table is not available. You must set directly the R, G, B and opacity values.

  1. Open a resource that has sub-products in the Live Simulation environment. The Main block must be a Dataflow block (see a typical example below).



  2. Double-click the Main block.

    A 2D immersive window is opened to edit the block behavior. The Block Editor commands are available in the toolbox at the right side of the window.

    Note: In our example, the resource logic is undefined, so the editor is empty.

  3. Select Set Color in the Activities toolbar.

  4. If the 2D immersive window is in front of the 3D object, click in the 3D view.

    The SFC+ Editor window becomes transparent.

  5. Select the part to position.

    The selected part is highlighted and a bubble attached to it appears.

    Tip: Select another part if you want to change the target.

  6. Click the bubble to confirm the selection of the product.

  7. Click the 2D editor to position the activity instance.

    An instance of the color activity is created.

    The Color output type is {Red:int32;Green:int32;Blue:int32;Opacity:int32}.

    Tip: This type is available as predefined type named Color as soon as the activity Set color is used.

  8. Select Color object > Map to new Port in the contextual menu of the port Color.



  9. Double-click the Green Lens.1_Color port to change its name to Color_IN.

  10. Close the Block Editor window.

  11. To test the behavior of the activity in simulation:

    1. Select the Main block thumbnail and click Play in the compass.

      The block is compiled and the simulation is initialized. The Simulation toolbar and the Signals Monitoring window appear.

    2. Expand the Ports node of the Signals Monitoring window and force all the values of Color_IN.



      Warning: The color change request is taken into account only if all the ports (Red, Green, Blue and Opacity) are emitted. Do not forget to force the status of a signal if its value does not change.

    3. Click Next in the control bar of the compass.

      The led is highlighted by the color change.

    4. Force the values of Red, Green and Blue to -1. As the Opacity is not changed, just force its status.



    5. Click Next. The initial color of the led is restored.
    6. Click the Play of the compass to close the simulation.