• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • GUI - CDP Widgets
  • CDPBaseLamp

CDPBaseLamp Class

The Lamp is a display widget that shows a lamp in configurable colors. More...

Header: #include <CDPBaseWidgets/CDPBaseLamp.h>
Inherits: CDPBasePictureSequence
  • List of all members, including inherited members

Public Types

enum LampType { Custom, Sunken, Ring }
typedef MapLampSvg

Properties

  • svgType : LampType
  • 2 properties inherited from CDPBasePictureSequence
  • 18 properties inherited from CDPBasePicture
  • 6 properties inherited from CDPBaseWidget

Public Functions

CDPBaseLamp(QWidget *parent = 0)
virtual ~CDPBaseLamp()
LampType lampType()
void setLampType(LampType type)
virtual void setSvgFile(QString svg)
  • 3 public functions inherited from CDPBasePictureSequence
  • 34 public functions inherited from CDPBasePicture
  • 17 public functions inherited from CDPBaseCom
  • 8 public functions inherited from CDPBaseWidget
  • 3 public functions inherited from RoutingContainerBase
  • 4 public functions inherited from CDPBaseControlVisible

Additional Inherited Members

  • 2 public slots inherited from CDPBasePictureSequence
  • 15 public slots inherited from CDPBasePicture
  • 10 public slots inherited from CDPBaseWidget
  • 2 signals inherited from CDPBasePicture
  • 1 signal inherited from CDPBaseWidget
  • 2 static public members inherited from CDPBaseCom
  • 3 static public members inherited from RoutingContainerBase
  • 2 protected functions inherited from CDPBasePictureSequence
  • 14 protected functions inherited from CDPBasePicture
  • 4 protected functions inherited from CDPBaseCom
  • 1 protected function inherited from CDPBaseControlVisible
  • 1 protected slot inherited from CDPBasePicture

Detailed Description

The Lamp is a display widget that shows a lamp in configurable colors.

Use the cdpStyleRouting property to set the color from the control logic. Connect (route) cdpStyleRouting to the control system variable/property (signal, parameter, alarm etc). Be aware that floating point numbers will get converted to integer in the widget. The values that set the different colors are shown in the below table.

ThemesvgTypecolor 0color 1color 2color 3color 4color 5
AllRinggraygreenyellowbrownredblue
cdp_light, cdp_dark, flat_light, flat_darkSunken, Custom*graygreenyellowbrownredblue
flat_gray_light, flat_graySunken, Custom*grayblueredorangeyellowgreen

* Custom can be changed by the user, but is the same as Sunken by default.

The property widgetStyle can be used to set the lamp to a fixed color. This is useful when testing the user interface without connecting it to the control system, or the use case described below in the example using the stacked widget. Note that using cdpStyleRouting will override what you set in widgetStyle.

The example in Intro 4: Using Messages and States demonstrates how the lamp can be used to create traffic lights.

Lamp variations

Some of the themes come with optional variations of the lamp image. The property svgType has a dropdown list where alternative lamp images can be selected.

svgTypeflat_light, flat_darkflat_gray_light, flat_graycdp_light, cdp_dark
Sunken, Custom*Round (flat)SquareRound (sunken)
RingRound (flat)Round (flat)Round (edge)

* Custom can be changed by the user, but is the same as Sunken by default.

Some themes can also have different color ordering (as shown in the color table). Hence, we will always have to verify that the lamps show the colors we want if changing themes in a project.

Connecting the Lamp to Control System Logic

The cdpStyleRouting property is used to connect and control the lamp color from the control logic.

Example: Connecting the Lamp to a Control System Signal

Create a GUI application and add a lamp. Add a component to the application containing an output signal named MyStyleSignal. To make the signal control the lamp color, we configure cdpStyleRouting in the lamp as shown in the below table. For the flat_gray_light theme, toggling the MystyleSignal between 0 and 1 will change the lamp color between gray and blue. The colors can be verified in Design mode using widgetStyle.

PropertyValue
cdpStyleRoutingApplication.Component.MyStyleSignal.Value

Example: How to Map Colors to Different Values

In the previous example, toggling the MyStyleSignal between 0 and 1 changed the lamp color between gray and blue. The blue color is fine for showing if something is on or off, but what if we wanted to display an alarm? In that case we might want the lamp to be red when the control signal is 1.

Option 1 - Using Stacked Widget in the User Interface

Add a Stacked Widget in the GUI and place lamps with different colors on different indexes/pages. Use the page routing property (cdpPageRouting) to control which lamp to show. To show grey color when the value is 0 and red when the value us 1:

  • Add a stacked widget to the GUI
  • Add a lamp in the first page (page 0) and set the lamp property widgetStyle to 0 (gray in the flat_gray theme)
  • Add a lamp in the second page (page 1) and set the lamp property widgetStyle to 2 (red)
  • Connect the control signal to the stacked widget property cdpPageRouting

The stacked widget will now show the grey lamp on page 0 when the signal value is 0, and page 1 with the red lamp when the value is 1.

Option 2 - Using the Evaluate Operator in the Control Logic

Instead of adding additional elements in GUI, we can transform the value in the control system before it is received by the lamp. One option is to add an Automation::Evaluate operator next to the component that has the MyStyleSignal and configure the Expression property as shown below.

PropertyValue
ExpressionInput?2:0 (means If Input is True, then Out = 2 else Out = 0)

All that remains now is to connect MyStyleSignal to the Evaluate Input and Evaluate Out to the lamp widget property cdpStyleRouting.

The lamp will now be gray when MyStyleSignal is 0 and red when the value is 1 (assuming flat_gray theme).

Option 3 - Create a Custom SVG

A third option is to make a custom SVG file as described in Creating Custom Lamps. In short, you want to copy the SVG file that styles the lamp, change the colors and configure svgFile with the new file path.

Creating Custom Lamps

The lamp widget is created for convenience as lamps are often used in automation systems user interfaces. It is actually a Picture Sequence Widget configured with a sequence of lamp images in different colors. The integer provided in widgetStyle or cdpStyleRouting selects which image in the sequence to show.

Use the Picture Sequence Widget to create your own lamps. The SVG structure is described in the Detailed Description of the class.

Consider using the lamp widget SVG as a starting point and follow the steps in How to Extend an Existing Theme.

Member Type Documentation

enum CDPBaseLamp::LampType

This enum type specifies how to style the widget:

ConstantValueDescription
CDPBaseLamp::Custom0Style the widget using a custom svg file
CDPBaseLamp::Sunken1Style the widget using a sunken looking lamp.
CDPBaseLamp::Ring2Style the widget using a beveled looking lamp.

typedef CDPBaseLamp::MapLampSvg

Property Documentation

svgType : LampType

This property holds the lamp type that sets an svg file to show on the widget.

Access functions:

LampType lampType()
void setLampType(LampType type)

See also CDPBasePictureSequence and svgFile.

Member Function Documentation

CDPBaseLamp::CDPBaseLamp(QWidget *parent = 0)

Default constructs an instance of CDPBaseLamp.

[virtual] CDPBaseLamp::~CDPBaseLamp()

Destroys the instance of CDPBaseLamp. The destructor is virtual.

[virtual] void CDPBaseLamp::setSvgFile(QString svg)

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2024 CDP Technologies. Privacy and cookie policy.

Return to top