2021-12-01 21:27:04 +01:00
|
|
|
|
/*
|
2021-03-16 19:59:45 +01:00
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef TERMINALSTRIP_H
|
|
|
|
|
#define TERMINALSTRIP_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QPointer>
|
2021-12-01 21:27:04 +01:00
|
|
|
|
#include <QColor>
|
|
|
|
|
|
2021-04-02 20:51:55 +02:00
|
|
|
|
#include "terminalstripdata.h"
|
2021-06-07 19:26:41 +02:00
|
|
|
|
#include "../properties/elementdata.h"
|
2021-03-16 19:59:45 +01:00
|
|
|
|
|
|
|
|
|
class Element;
|
|
|
|
|
class RealTerminal;
|
|
|
|
|
class QETProject;
|
|
|
|
|
class PhysicalTerminal;
|
2021-04-29 20:31:53 +02:00
|
|
|
|
class TerminalStripIndex;
|
2021-05-03 22:25:43 +02:00
|
|
|
|
class TerminalElement;
|
|
|
|
|
|
2021-06-07 19:26:41 +02:00
|
|
|
|
|
2021-12-01 21:27:04 +01:00
|
|
|
|
/**
|
|
|
|
|
* @brief The RealTerminalData struct
|
|
|
|
|
* Conveniant struct to quickly get some values
|
|
|
|
|
* of a RealTerminal
|
2021-12-11 21:25:40 +01:00
|
|
|
|
* A RealTerminalData with level_ = -1
|
|
|
|
|
* is considered as a null data
|
2021-12-01 21:27:04 +01:00
|
|
|
|
*/
|
2021-06-07 19:26:41 +02:00
|
|
|
|
struct RealTerminalData
|
|
|
|
|
{
|
2021-10-04 21:26:51 +02:00
|
|
|
|
int level_ = -1;
|
2021-06-07 19:26:41 +02:00
|
|
|
|
|
|
|
|
|
QString label_,
|
|
|
|
|
Xref_,
|
|
|
|
|
cable_,
|
|
|
|
|
cable_wire_,
|
|
|
|
|
conductor_;
|
|
|
|
|
|
2021-10-09 11:58:10 +02:00
|
|
|
|
QUuid element_uuid,
|
2021-12-01 21:27:04 +01:00
|
|
|
|
real_terminal_uuid,
|
|
|
|
|
bridge_uuid;
|
2021-09-12 12:49:12 +02:00
|
|
|
|
|
2021-06-07 19:26:41 +02:00
|
|
|
|
ElementData::TerminalType type_;
|
2021-07-17 13:44:44 +02:00
|
|
|
|
ElementData::TerminalFunction function_;
|
2021-06-07 19:26:41 +02:00
|
|
|
|
|
|
|
|
|
bool led_ = false,
|
2021-12-01 21:27:04 +01:00
|
|
|
|
is_element = false,
|
|
|
|
|
is_bridged = false;
|
2021-08-23 20:44:53 +02:00
|
|
|
|
|
2021-09-20 18:34:48 +02:00
|
|
|
|
QPointer<Element> element_;
|
2021-08-23 20:44:53 +02:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-01 21:27:04 +01:00
|
|
|
|
/**
|
|
|
|
|
* @brief The PhysicalTerminalData struct
|
|
|
|
|
* Conveniant struct to quickly get some values
|
|
|
|
|
* of a PhysicalTerminal
|
|
|
|
|
*/
|
2021-08-23 20:44:53 +02:00
|
|
|
|
struct PhysicalTerminalData
|
|
|
|
|
{
|
|
|
|
|
QVector<RealTerminalData> real_terminals_vector;
|
|
|
|
|
int pos_ = -1;
|
2021-10-09 11:58:10 +02:00
|
|
|
|
QUuid uuid_;
|
2021-06-07 19:26:41 +02:00
|
|
|
|
};
|
|
|
|
|
|
2021-10-09 14:45:54 +02:00
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 21:27:04 +01:00
|
|
|
|
struct TerminalStripBridge
|
|
|
|
|
{
|
|
|
|
|
QVector<QSharedPointer<RealTerminal>> real_terminals;
|
2021-12-11 21:25:40 +01:00
|
|
|
|
QColor color_ = Qt::darkGray;
|
2021-12-01 21:27:04 +01:00
|
|
|
|
QUuid uuid_ = QUuid::createUuid();
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-03 22:25:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* @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...)
|
2021-12-01 21:27:04 +01:00
|
|
|
|
* and is composed by one or several PhysicalTerminal.
|
2021-05-03 22:25:43 +02:00
|
|
|
|
*/
|
2021-03-16 19:59:45 +01:00
|
|
|
|
class TerminalStrip : public QObject
|
|
|
|
|
{
|
2021-06-07 19:26:41 +02:00
|
|
|
|
friend class TerminalStripModel;
|
|
|
|
|
|
2021-10-09 11:58:10 +02:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2021-09-22 23:02:33 +02:00
|
|
|
|
public:
|
2021-12-11 21:25:40 +01:00
|
|
|
|
static QVector<QColor> bridgeColor() {return QVector<QColor>{Qt::red, Qt::blue, Qt::white, Qt::darkGray, Qt::black};}
|
|
|
|
|
|
2021-09-22 23:02:33 +02:00
|
|
|
|
signals:
|
|
|
|
|
void orderChanged(); //Emitted when the order of the physical terminal is changed
|
2021-12-01 21:27:04 +01:00
|
|
|
|
void bridgeChanged();
|
2021-09-22 23:02:33 +02:00
|
|
|
|
|
2021-03-16 19:59:45 +01:00
|
|
|
|
public:
|
2021-05-02 22:58:20 +02:00
|
|
|
|
TerminalStrip(QETProject *project);
|
2021-03-16 19:59:45 +01:00
|
|
|
|
|
|
|
|
|
TerminalStrip(const QString &installation,
|
2021-04-02 20:51:55 +02:00
|
|
|
|
const QString &location,
|
|
|
|
|
const QString &name,
|
|
|
|
|
QETProject *project);
|
2021-03-16 19:59:45 +01:00
|
|
|
|
|
|
|
|
|
void setInstallation(const QString &installation);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
QString installation() const {return m_data.m_installation;}
|
2021-03-16 19:59:45 +01:00
|
|
|
|
void setLocation(const QString &location);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
QString location() const {return m_data.m_location;}
|
2021-03-16 19:59:45 +01:00
|
|
|
|
void setName(const QString &name);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
QString name() const {return m_data.m_name;}
|
2021-04-04 19:39:21 +02:00
|
|
|
|
void setComment(const QString &comment);
|
|
|
|
|
QString comment() const {return m_data.m_comment;}
|
2021-04-03 15:48:07 +02:00
|
|
|
|
void setDescription(const QString &description);
|
|
|
|
|
QString description() const {return m_data.m_description;}
|
2021-04-09 14:16:22 +02:00
|
|
|
|
QUuid uuid() const {return m_data.m_uuid;}
|
2021-03-16 19:59:45 +01:00
|
|
|
|
|
2021-05-05 22:34:11 +02:00
|
|
|
|
TerminalStripData data() const;
|
|
|
|
|
void setData(const TerminalStripData &data);
|
|
|
|
|
|
2021-04-29 20:31:53 +02:00
|
|
|
|
bool addTerminal (Element *terminal);
|
|
|
|
|
bool removeTerminal (Element *terminal);
|
|
|
|
|
|
|
|
|
|
int physicalTerminalCount() const;
|
2021-09-22 23:02:33 +02:00
|
|
|
|
PhysicalTerminalData physicalTerminalData(int index) const;
|
2021-10-09 11:58:10 +02:00
|
|
|
|
PhysicalTerminalData physicalTerminalData (const RealTerminalData &real_data) const;
|
2021-09-22 23:02:33 +02:00
|
|
|
|
QVector<PhysicalTerminalData> physicalTerminalData() const;
|
2021-10-12 19:25:35 +02:00
|
|
|
|
bool setOrderTo(const QVector<PhysicalTerminalData> &sorted_vector);
|
2021-10-09 11:58:10 +02:00
|
|
|
|
bool groupTerminals(const PhysicalTerminalData &receiver_terminal, const QVector<RealTerminalData> &added_terminals);
|
2021-10-04 21:26:51 +02:00
|
|
|
|
void unGroupTerminals(const QVector<RealTerminalData> &terminals_to_ungroup);
|
2021-10-12 19:25:35 +02:00
|
|
|
|
bool setLevel(const RealTerminalData &real_terminal_data, int level);
|
2021-12-01 21:27:04 +01:00
|
|
|
|
bool isBridgeable(const QVector<QUuid> &real_terminals_uuid) const;
|
|
|
|
|
bool setBridge(const QVector<QUuid> &real_terminals_uuid);
|
|
|
|
|
bool setBridge(const QUuid &bridge_uuid, const QVector<QUuid> &real_terminals_uuid);
|
|
|
|
|
void unBridge(const QVector<QUuid> &real_terminals_uuid);
|
2021-12-11 21:25:40 +01:00
|
|
|
|
const QSharedPointer<TerminalStripBridge> bridgeFor(const QUuid &real_terminal_uuid) const;
|
|
|
|
|
|
|
|
|
|
RealTerminalData previousTerminalInLevel(const QUuid &real_terminal_uuid) const;
|
|
|
|
|
RealTerminalData nextTerminalInLevel(const QUuid &real_terminal_uuid) const;
|
|
|
|
|
RealTerminalData previousRealTerminal(const QUuid &real_terminal_uuid) const;
|
|
|
|
|
RealTerminalData nextRealTerminal(const QUuid &real_terminal_uuid) const;
|
2021-03-16 19:59:45 +01:00
|
|
|
|
|
2021-04-30 19:15:10 +02:00
|
|
|
|
QVector<QPointer<Element>> terminalElement() const;
|
|
|
|
|
|
2021-05-01 20:04:40 +02:00
|
|
|
|
static QString xmlTagName() {return QStringLiteral("terminal_strip");}
|
|
|
|
|
QDomElement toXml(QDomDocument &parent_document);
|
2021-05-02 22:58:20 +02:00
|
|
|
|
bool fromXml(QDomElement &xml_element);
|
2021-05-01 20:04:40 +02:00
|
|
|
|
|
2021-03-16 19:59:45 +01:00
|
|
|
|
private:
|
|
|
|
|
QSharedPointer<RealTerminal> realTerminal(Element *terminal);
|
2021-09-22 23:02:33 +02:00
|
|
|
|
QSharedPointer<PhysicalTerminal> physicalTerminal(QSharedPointer<RealTerminal> terminal) const;
|
2021-12-01 21:27:04 +01:00
|
|
|
|
RealTerminalData realTerminalData(const QSharedPointer<RealTerminal> real_terminal) const;
|
2021-10-09 11:58:10 +02:00
|
|
|
|
QSharedPointer<PhysicalTerminal> physicalTerminalForUuid (const QUuid &uuid) const;
|
|
|
|
|
QSharedPointer<RealTerminal> realTerminalForUuid(const QUuid &uuid) const;
|
2021-12-01 21:27:04 +01:00
|
|
|
|
QSharedPointer<TerminalStripBridge> isBridged(const QSharedPointer<RealTerminal> real_terminal) const;
|
|
|
|
|
QSharedPointer<TerminalStripBridge> bridgeFor (const QVector<QSharedPointer<RealTerminal>> &terminal_vector) const;
|
|
|
|
|
QSharedPointer<TerminalStripBridge> bridgeForUuid (const QUuid &bridge_uuid);
|
2021-12-11 21:25:40 +01:00
|
|
|
|
void rebuildRealVector();
|
2021-03-16 19:59:45 +01:00
|
|
|
|
|
|
|
|
|
private:
|
2021-04-02 20:51:55 +02:00
|
|
|
|
TerminalStripData m_data;
|
2021-03-16 19:59:45 +01:00
|
|
|
|
QPointer<QETProject> m_project;
|
|
|
|
|
QVector<QPointer<Element>> m_terminal_elements_vector;
|
|
|
|
|
QVector<QSharedPointer<RealTerminal>> m_real_terminals;
|
|
|
|
|
QVector<QSharedPointer<PhysicalTerminal>> m_physical_terminals;
|
2021-12-01 21:27:04 +01:00
|
|
|
|
QVector<QSharedPointer<TerminalStripBridge>> m_bridge;
|
2021-03-16 19:59:45 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // TERMINALSTRIP_H
|