mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-05 02:24:13 +02:00
20e134f2bd
Discussion #1158: a real terminal takes one or two wires (four with double ferrules), a folio report is a virtual point that carries one, but QElectroTech lets any number of wires be connected anywhere. Project properties > General gets a "Conducteurs par borne" group: - the most wires a terminal may take (0, the default, is no limit); - "one wire per folio report". When set, a new wire that would go past the limit is refused: the terminal shows red while dragging, as for any refused link, and a tooltip says why on release. Auto-connect on placing, moving or multi-pasting a symbol skips full terminals, and qet.addConductor() refuses with its own message. Wires already drawn, opening, pasting and undo are never refused. Settings > General gets a master switch, on by default, that turns every rule of this feature off in every project; the project group is greyed with a note while it is off. The rules live in wiringrules.cpp. The project setting is saved as <wiring_rules .../> only when a rule is on, so a project that never used it saves exactly as before; an older version drops it, which means "off". tst_wiringrules covers the rules, the save round trip and, through the real binary, that a wire past the limit is refused unless the master switch is off (checked to fail with the limit check removed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015FPuYPS4T7QuEwjNu22rXD
69 lines
2.3 KiB
C++
69 lines
2.3 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/>.
|
|
*/
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#ifndef WIRINGRULES_H
|
|
#define WIRINGRULES_H
|
|
|
|
class QDomElement;
|
|
|
|
/**
|
|
@brief The WiringRules namespace
|
|
How many wires a terminal may take (discussion #1158). A real terminal
|
|
takes one or two wires, sometimes four with double ferrules; a folio
|
|
report is a virtual point that should carry one. When a project sets a
|
|
limit, a new wire that would go past it is refused. Wires already in
|
|
the drawing are never touched.
|
|
|
|
Every rule is off unless the project turns it on, and the application
|
|
has a master switch (masterEnabled()) that turns all of them off in
|
|
every project at once. Kept free of any QGraphicsItem so the rules can
|
|
be tested on their own.
|
|
*/
|
|
namespace WiringRules
|
|
{
|
|
///The QSettings key of the master switch
|
|
constexpr const char *settings_key = "diagrameditor/wiring_rules_enabled";
|
|
|
|
///The rules a project chose. The default is "no rule".
|
|
struct Settings
|
|
{
|
|
///Most wires a terminal may take, 0 for no limit
|
|
int max_wires = 0;
|
|
///A folio report takes one wire only
|
|
bool one_wire_per_report = false;
|
|
|
|
bool isDefault() const { return *this == Settings(); }
|
|
bool operator==(const Settings &other) const {
|
|
return max_wires == other.max_wires
|
|
&& one_wire_per_report == other.one_wire_per_report;
|
|
}
|
|
bool operator!=(const Settings &other) const { return !(*this == other); }
|
|
};
|
|
|
|
bool masterEnabled();
|
|
void setMasterEnabled(bool enabled);
|
|
|
|
Settings fromXml(const QDomElement &project_root);
|
|
void toXml(const Settings &settings, QDomElement &project_root);
|
|
|
|
int limit(const Settings &settings, bool master_enabled, bool is_report);
|
|
bool hasRoom(int limit, int wires);
|
|
}
|
|
|
|
#endif // WIRINGRULES_H
|