/*
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see .
*/
#ifndef TERMINALSTRIP_H
#define TERMINALSTRIP_H
#include
#include
#include
#include "terminalstripdata.h"
#include "../properties/elementdata.h"
class Element;
class RealTerminal;
class QETProject;
class PhysicalTerminal;
class TerminalStripIndex;
class TerminalElement;
/**
* @brief The RealTerminalData struct
* Conveniant struct to quickly get some values
* of a RealTerminal
*/
struct RealTerminalData
{
int level_ = -1;
QString label_,
Xref_,
cable_,
cable_wire_,
conductor_;
QUuid element_uuid,
real_terminal_uuid,
bridge_uuid;
ElementData::TerminalType type_;
ElementData::TerminalFunction function_;
bool led_ = false,
is_element = false,
is_bridged = false;
QPointer element_;
};
/**
* @brief The PhysicalTerminalData struct
* Conveniant struct to quickly get some values
* of a PhysicalTerminal
*/
struct PhysicalTerminalData
{
QVector real_terminals_vector;
int pos_ = -1;
QUuid uuid_;
};
//Code to use PhysicalTerminalData as key for QHash
inline bool operator == (const PhysicalTerminalData &phy_1, const PhysicalTerminalData &phy_2) {
return phy_1.uuid_ == phy_2.uuid_;
}
inline uint qHash(const PhysicalTerminalData &key, uint seed) {
return qHash(key.uuid_, seed);
}
struct TerminalStripBridge
{
QVector> real_terminals;
QColor color_ = Qt::gray;
QUuid uuid_ = QUuid::createUuid();
};
/**
* @brief The TerminalStrip class
* This class hold all the datas and configurations
* of a terminal strip (but the not the visual aspect).
* A terminal strip have some informations (name comment etc...)
* and is composed by one or several PhysicalTerminal.
*/
class TerminalStrip : public QObject
{
friend class TerminalStripModel;
Q_OBJECT
public:
signals:
void orderChanged(); //Emitted when the order of the physical terminal is changed
void bridgeChanged();
public:
TerminalStrip(QETProject *project);
TerminalStrip(const QString &installation,
const QString &location,
const QString &name,
QETProject *project);
void setInstallation(const QString &installation);
QString installation() const {return m_data.m_installation;}
void setLocation(const QString &location);
QString location() const {return m_data.m_location;}
void setName(const QString &name);
QString name() const {return m_data.m_name;}
void setComment(const QString &comment);
QString comment() const {return m_data.m_comment;}
void setDescription(const QString &description);
QString description() const {return m_data.m_description;}
QUuid uuid() const {return m_data.m_uuid;}
TerminalStripData data() const;
void setData(const TerminalStripData &data);
bool addTerminal (Element *terminal);
bool removeTerminal (Element *terminal);
int physicalTerminalCount() const;
PhysicalTerminalData physicalTerminalData(int index) const;
PhysicalTerminalData physicalTerminalData (const RealTerminalData &real_data) const;
QVector physicalTerminalData() const;
bool setOrderTo(const QVector &sorted_vector);
bool groupTerminals(const PhysicalTerminalData &receiver_terminal, const QVector &added_terminals);
void unGroupTerminals(const QVector &terminals_to_ungroup);
bool setLevel(const RealTerminalData &real_terminal_data, int level);
bool isBridgeable(const QVector &real_terminals_uuid) const;
bool setBridge(const QVector &real_terminals_uuid);
bool setBridge(const QUuid &bridge_uuid, const QVector &real_terminals_uuid);
void unBridge(const QVector &real_terminals_uuid);
QSharedPointer bridgeFor(const QUuid &real_terminal_uuid) const;
QVector> terminalElement() const;
static QString xmlTagName() {return QStringLiteral("terminal_strip");}
QDomElement toXml(QDomDocument &parent_document);
bool fromXml(QDomElement &xml_element);
private:
QSharedPointer realTerminal(Element *terminal);
QSharedPointer physicalTerminal(QSharedPointer terminal) const;
RealTerminalData realTerminalData(const QSharedPointer real_terminal) const;
QSharedPointer physicalTerminalForUuid (const QUuid &uuid) const;
QSharedPointer realTerminalForUuid(const QUuid &uuid) const;
QSharedPointer isBridged(const QSharedPointer real_terminal) const;
QSharedPointer bridgeFor (const QVector> &terminal_vector) const;
QSharedPointer bridgeForUuid (const QUuid &bridge_uuid);
private:
TerminalStripData m_data;
QPointer m_project;
QVector> m_terminal_elements_vector;
QVector> m_real_terminals;
QVector> m_physical_terminals;
QVector> m_bridge;
};
#endif // TERMINALSTRIP_H