// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example waterpump/waterpump-qml
    \meta tag {qtopcua,quick}
    \ingroup qtopcua-examples
    \title Qt Quick Water Pump
    \examplecategory {Data Processing & I/O}
    \brief Interacting with an OPC UA server to build a QML-based HMI for a
    simple water pump machine.

    \e{Qt Quick Water Pump} example shows how to use Qt OPC UA QML API to interact
    with an OPC UA server to build a QML based HMI for a simple machine.

    \image tankexample.png

    \section1 Building the Server
    Before you can use the Water Pump examples, you need to build the \l
    {https://code.qt.io/cgit/qt/qtopcua.git/tree/examples/opcua/waterpump/simulationserver}
    {simulation server}.
    The simulation server project resides next to the Water Pump examples.
    You can open and build it in QtCreator or from the terminal as usual.

    \section1 The Simulation
    The OPC UA server included in this example runs a simulation of a machine
    containing two tanks, a water pump and a valve. Water can be pumped from the
    first tank into the second tank and then be flushed from the second tank
    by opening the valve. Both operations have a user-configurable setpoint
    which controls how much water is pumped to or flushed from the second tank.

    The following nodes exist on the server:

    \table
        \header
            \li NodeId
            \li Function
        \row
            \li ns=2;s=Machine
            \li The folder containing the method and variable nodes for the machine
        \row
            \li ns=2;s=Machine.State
            \li The state of the machine
        \row
            \li ns=2;s=Machine.Tank1.PercentFilled
            \li The current fill status of the first tank
        \row
            \li ns=2;s=Machine.Tank2.PercentFilled
            \li The current fill status of the second tank
        \row
            \li ns=2;s=Machine.Tank2.TargetPercent
            \li The setpoint for pumping and flushing
        \row
            \li ns=2;s=Machine.Tank2.ValveState
            \li The state of the valve of the second tank
        \row
            \li ns=2;s=Machine.Designation
            \li A human readable designation of the machine for display purposes
        \row
            \li ns=2;s=Machine.Start
            \li Call this method to start the pump
        \row
            \li ns=2;s=Machine.Stop
            \li Call this method to stop the pump
        \row
            \li ns=2;s=Machine.FlushTank2
            \li Call this method to flush tank 2
        \row
            \li ns=2;s=Machine.Reset
            \li Call this method to reset the simulation
    \endtable

    \section1 Implementation

    This example uses QML items to read and write values as well as method calls.
    All operations are asynchronous and handled by QML in the background.

    A QML item represents the machine and its components. This item does not have any
    graphical interface and only provides access to the properties of the machine.
    It has two tanks which are instances of a separate \c Tank component.

    \section2 Properties

    The machine item exposes all properties and subitems as properties.

    \quotefromfile waterpump/waterpump-qml/machine/Machine.qml
    \dots
    \skipto readonly
    \printuntil flushMethod
    \codeline
    \dots

    \section2 Asynchronous Handlers

    The asynchronous parts of the API are handled by QML automatically because
    signals are emitted for every property change by default.

    For example, the button to flush the second tank is enabled
    only if the backend is connected to the server, the machine is idle, and
    the tank level is above the setpoint. On click, the \c flushTank2() method
    is called on the server.

    \quotefromfile waterpump/waterpump-qml/MachineDisplay.qml
    \skipto     Tank2Unit
    \printuntil valveState

    \section1 Usage
    The server is started automatically by the HMI application.
    After connecting to the server by clicking the \uicontrol Connect button,
    drag the slider to set a setpoint, then click \uicontrol Start to start pumping water
    from the first tank to the second tank. After setting a setpoint lower than
    the current value of the second tank, a click on \uicontrol Flush opens the valve.

    If there is no water left, click \uicontrol {Reset simulation} to refill the first tank.

    \sa {Waterpump Example}
*/
