mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-22 08:34:12 +02:00
ab159404a3
The conductor table keyed on Terminal::uuid(), which comes from the catalog .elmt definition and is empty for every element authored before that field existed. A conductor was dropped unless *both* its terminals had one, so the tables this slice adds were empty on almost every project in existence: examples corpus conductor rows in the database industrial.qet 0 of 671 affuteuse_250h.qet 0 of 263 tremie_vibrante.qet 0 of 77 741.qet 0 of 67 Across the 23 example projects, 16 of the 20 that contain conductors have zero terminal uuids -- 2366 of 3002 conductors -- and overall coverage is 7.3%. Meanwhile --export-cables, already on master, lists all 671 conductors of industrial.qet from the document. A feature that only works on newly authored elements is not one users can rely on. Terminal::stableUuid() returns the terminal's own uuid when it has one and otherwise derives one from its local position and orientation inside its element. That is not an invented scheme: it is what the project format already does. TerminalData::fromXml() says so where it parses the field -- "if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach to identify terminals" -- and the legacy approach is the terminal's position. m_pos is read from the definition and is not touched by moving the element on a folio, so the identity survives loads, saves and folio moves. Derived values are UUID v5 in a fixed namespace, so they are reproducible without being stored, and cannot collide with the v4 uuids the element editor generates. Every project in the corpus now has exactly as many conductor rows as the document has conductors -- 20 of 20 measured, 0 mismatches. (schema_indus.qet is excluded: it blocks on a modal dialog at zero CPU under any CLI flag, the pre-existing hang PR #661 addresses.) Two things this deliberately does not key on: - The terminal name. It is not stable: QET rewrites a terminal named "_" as unnamed, which would have silently changed the identity of 1421 of industrial.qet's 1790 terminals on their first resave. Measured across the corpus, dropping it costs nothing -- geometry alone yields exactly the same three collisions -- and it means renaming a terminal no longer changes what it is. - Uniqueness in the face of a definition that declares two terminals at the same point and orientation. Three cases exist in the whole corpus. They merge to a single terminal row, which is harmless: two terminals identical in position and orientation are indistinguishable in every observable respect, and every conductor on either still resolves to the right element and terminal name. Both affected projects (industrial, perceuse) return their full conductor count. The only conductor still skipped is one whose terminal has no parent element, which has no identity to key on at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
166 lines
4.8 KiB
C++
166 lines
4.8 KiB
C++
/*
|
|
Copyright 2006-2026 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 TERMINAL_H
|
|
#define TERMINAL_H
|
|
#include "../qet.h"
|
|
#include "../properties/terminaldata.h"
|
|
|
|
#include <QtWidgets>
|
|
#include <QtXml>
|
|
class Conductor;
|
|
class Diagram;
|
|
class Element;
|
|
|
|
|
|
/**
|
|
@brief The Terminal class
|
|
This class represents a terminal of an electrical element, i.e. a possible
|
|
plug point for conductors.
|
|
This class handles all mouse events for connecting conductors
|
|
*/
|
|
class Terminal : public QGraphicsObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
signals:
|
|
void conductorWasAdded(Conductor *conductor);
|
|
void conductorWasRemoved(Conductor *conductor);
|
|
|
|
// constructors, destructor
|
|
public:
|
|
Terminal(TerminalData* data, Element *e = nullptr);
|
|
~Terminal() override;
|
|
|
|
private:
|
|
Terminal(const Terminal &);
|
|
|
|
// methods
|
|
public:
|
|
/**
|
|
@brief type
|
|
Enable the use of qgraphicsitem_cast to safely
|
|
cast a QGraphicsItem into a Terminal
|
|
@return the QGraphicsItem type
|
|
*/
|
|
int type() const override { return Type; }
|
|
|
|
void paint(
|
|
QPainter *painter,
|
|
const QStyleOptionGraphicsItem *,
|
|
QWidget *) override;
|
|
void drawHelpLine (bool draw = true);
|
|
QLineF HelpLine () const;
|
|
QRectF boundingRect () const override;
|
|
|
|
// methods to manage conductors attached to the terminal
|
|
Terminal* alignedWithTerminal () const;
|
|
bool addConductor (Conductor *conductor);
|
|
void removeConductor (Conductor *conductor);
|
|
int conductorsCount () const;
|
|
Diagram *diagram () const;
|
|
Element *parentElement () const;
|
|
QUuid uuid () const;
|
|
QUuid stableUuid () const;
|
|
QString name () const;
|
|
QString baseName () const;
|
|
TerminalData::Type terminalType() const;
|
|
bool useMasterLabel() const { return d->m_use_master_label; }
|
|
void setUseMasterLabel(bool use);
|
|
int masterLabelIndex() const { return d->m_master_label_index; }
|
|
void setMasterLabelIndex(int index);
|
|
|
|
QList<Conductor *> conductors() const;
|
|
Qet::Orientation orientation() const;
|
|
QPointF dockConductor() const;
|
|
void updateConductor();
|
|
bool isLinkedTo(Terminal *);
|
|
bool canBeLinkedTo(Terminal *);
|
|
|
|
// methods related to XML import/export
|
|
static bool valideXml(QDomElement &);
|
|
bool fromXml (QDomElement &);
|
|
QDomElement toXml (QDomDocument &) const;
|
|
|
|
protected:
|
|
// methods related to events management
|
|
void hoverEnterEvent (QGraphicsSceneHoverEvent *) override;
|
|
void hoverMoveEvent (QGraphicsSceneHoverEvent *) override;
|
|
void hoverLeaveEvent (QGraphicsSceneHoverEvent *) override;
|
|
void mousePressEvent (QGraphicsSceneMouseEvent *) override;
|
|
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
|
|
|
|
// attributes
|
|
public:
|
|
enum { Type = UserType + 1002 };
|
|
|
|
static const qreal terminalSize;
|
|
static const qreal Z;
|
|
// Various static colors used for hover effects
|
|
/// default color
|
|
static QColor neutralColor;
|
|
/// color for legal actions
|
|
static QColor allowedColor;
|
|
/// color for allowed but fuzzy or not recommended actions
|
|
static QColor warningColor;
|
|
/// color for forbidden actions
|
|
static QColor forbiddenColor;
|
|
|
|
private:
|
|
bool m_draw_help_line{false};
|
|
QGraphicsLineItem *m_help_line{nullptr};
|
|
QGraphicsLineItem *m_help_line_a{nullptr};
|
|
|
|
|
|
TerminalData* d;
|
|
|
|
/// Parent electrical element
|
|
Element *parent_element_{nullptr};
|
|
public:
|
|
/// docking point for parent element
|
|
QPointF dock_elmt_;
|
|
private:
|
|
/// List of conductors attached to the terminal
|
|
QList<Conductor *> m_conductors_list;
|
|
QRectF m_br;
|
|
/// Last terminal seen through an attached conductor
|
|
Terminal *m_previous_terminal = nullptr;
|
|
/// Whether the mouse pointer is hovering the terminal
|
|
bool m_hovered = false;
|
|
/// Color used for the hover effect
|
|
QColor m_hovered_color = Terminal::neutralColor;
|
|
|
|
private:
|
|
void init();
|
|
void init(QPointF pf, Qet::Orientation o);
|
|
};
|
|
|
|
/**
|
|
@brief Terminal::conductorsCount
|
|
@return the number of conductors attached to the terminal.
|
|
*/
|
|
inline int Terminal::conductorsCount() const
|
|
{
|
|
return(m_conductors_list.size());
|
|
}
|
|
|
|
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
|
|
const bool all_diagram = true);
|
|
|
|
#endif
|