#pragma once

/* $Header: https://oberon.oapd.inaf.it/shins/trunk/tan/basda-mocca/src/interface/Basda/Qt/Wheel/BasdaMoccaWheelServiceWidgetUnit.h 3436 2020-09-04 10:04:29Z depa $
*/


#include <Nice/Qt/BridgeItem.h>
#include <Nice/Map/Point.h>
#include <Basda/Mocca/Constant.h>
#include <Basda/Mocca/WheelServiceWorkerInterface.h>
#include <QtDesigner/QDesignerExportWidget>

namespace Ui
{
    class BasdaMoccaWheelServiceWidgetUnitUI;
}
;

/**
 * @brief This class is the implementation of the GUI BasdaMoccaWheelServiceWidgetUnit
 */
class QDESIGNER_WIDGET_EXPORT BasdaMoccaWheelServiceWidgetUnit : public QWidget, public Nice::BridgeItem
{
    private:
        Q_OBJECT

        /**
         * @brief Connect the Qt Designer Property propertyNode with the methods
         *        getPropertyNode and setPropertyNode.
         */
        Q_PROPERTY(QString PropertyNode READ getPropertyNode WRITE setPropertyNode)

        /**
         * @brief Connect the Qt Designer Property AutoSynch with the methods
         *        getSynchStatus and setSynchStatus.
         */
        Q_PROPERTY(bool AutoSynch READ getSynchStatus WRITE setSynchStatus)

        void updateDoubleSpinBoxRel();

        void updateDoubleSpinBoxAbs();

        void updateNamedPositionLabels();

        Ui::BasdaMoccaWheelServiceWidgetUnitUI* m_wheelView;

        /**
         * @brief member for the command interface
         */
        Basda::MoccaWheelServiceWorkerInterfacePtr m_cmd;

        /**
         * @brief member for the current used named position.
         */
        int m_namedPos;

        std::string m_unit;

        std::map<std::string, int> m_unitPrec;

        /**
         * @brief member to store the named reletive position
         */
        std::vector<Nice::Int> m_namedPosRel;

        /**
         * @brief member to store the named absolute position
         */
        std::vector<Nice::Int> m_namedPosAbs;

        Nice::SeqBitSet m_namedRef;

        Nice::Mutex m_mutex;

        std::string m_namedPositionNotDefined;

    public:
        //------------------------------------------------------------
        /**
         * @brief Consturtor
         * @param parent the parent widget
         * @param _connect ??
         */
        BasdaMoccaWheelServiceWidgetUnit(QWidget * parent = 0, bool _connect=false );

        //------------------------------------------------------------
        /**
         * @brief Initiate the attributes. The command attributes like the named
         *        position and the different units are added.
         *
         * One drop down button will be filled with the labels of the named
         * position. A second drop down button will be filled with the labels of
         * the units.
         */
        virtual void initAttributes();

        /**
         * @brief This method can be used to connect different properties with
         *        method, which will be executed every time when a property changed.
         */
        virtual void initSlots();

    public slots:
        void slotNice_setNamedPositionAbs(std::vector<Nice::Int> _p);

        void slotNice_setNamedPositionRel(std::vector<Nice::Int> _p);

    protected slots:
        /**
         * @brief This method will be called whenever the sign button of the
         *        relative position X is pressed.
         */
        virtual void slotQt_signRelXChanged();

        /**
         * @brief This method will be called whenever the sign button of the
         *        absolute position X is pressed.
         */
        virtual void slotQt_signAbsXChanged();

        /**
         * @brief This method will be called whenever the named position will
         *        change in the GUI
         */
        virtual void slotQt_valueNamedPositionChanged(int);

        /**
         * @brief This is the implementation of the stop button.
         */
        virtual void slotQt_stop();

        /**
         * @brief This is the implementation of the abort button.
         */
        virtual void slotQt_abort();

        /**
         * @brief This is the implementation of the move relative button.
         */
        virtual void slotQt_moveRelativeX();

        /**
         * @brief This is the implementation of the move absolute button.
         */
        virtual void slotQt_moveAbsoluteX();

        /**
         * @brief This is the implementation of the move home button.
         */
        virtual void slotQt_moveToHomeX();

        virtual void slotQt_moveToNamedPositionX();

        virtual void slotQt_scanAllReferenceSwitches();

        /**
         * @brief This method will be called whenever the unit will change in
         *        the GUI.
         */
        virtual void slotQt_valueUnitChanged(QString);
};

