mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-19 20:44:16 +02:00
34557928d1
Add two realistic drawing styles for the terminal strip plan, besides
the existing schematic one:
- Realistic (push-in) and Realistic (screw): the strip seen from above,
at scale (real width of each terminal), like a cabinet mounting
drawing: end stops, group marker carrier with the strip name, one row
of wire entries per level, bridge channels with red bridges, marker
tags with the terminal number, type symbol (fuse, LED, diode,
sectional, ground...), green/yellow PE and terminal color.
The style is chosen for each plan in the "Add terminal strip plan"
dialog and saved with the item (attribute draw_style of
terminal_strip_item). Items saved before keep the schematic style.
Several plans of the same strip can use different styles.
The values used by the realistic styles are in the layout (scale in
px/mm, terminal length in mm, end stops, group marker) and can be set
in the layout editor, whose style combo box only changes the preview.
Separator plates: a new "Separator plate after" check box column in
the terminal strip editor, stored in the terminal element informations
(key terminal_separator). Drawn as a plate at scale in the realistic
styles and as a thick line in the schematic style.
New files: realisticterminalstripdrawer.{h,cpp} (realistic drawing) and
terminalstripdrawerhelpers.h (helpers shared with the schematic drawer).
397 lines
9.3 KiB
C++
397 lines
9.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/>.
|
|
*/
|
|
#include "realterminal.h"
|
|
#include "terminalstrip.h"
|
|
#include "../qetgraphicsitem/terminalelement.h"
|
|
#include "physicalterminal.h"
|
|
#include "terminalcolor.h"
|
|
#include "../qetgraphicsitem/conductor.h"
|
|
|
|
/**
|
|
* @brief RealTerminal
|
|
* @param parent_strip : parent terminal strip
|
|
* @param terminal : terminal element (if any) in a folio
|
|
*/
|
|
RealTerminal::RealTerminal(Element *terminal) :
|
|
m_element(terminal)
|
|
{}
|
|
|
|
RealTerminal::~RealTerminal()
|
|
{
|
|
if (m_physical_terminal) {
|
|
m_physical_terminal->removeTerminal(sharedRef());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::sharedRef
|
|
* @return a QSharedPointer of this
|
|
*/
|
|
QSharedPointer<RealTerminal> RealTerminal::sharedRef()
|
|
{
|
|
QSharedPointer<RealTerminal> this_shared(this->weakRef());
|
|
if (this_shared.isNull())
|
|
{
|
|
this_shared = QSharedPointer<RealTerminal>(this);
|
|
m_this_weak = this_shared.toWeakRef();
|
|
}
|
|
|
|
return this_shared;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::sharedRef
|
|
* @return a shared reference of this, not that because
|
|
* this method is const, the shared reference can be null if not already
|
|
* used in another part of the code.
|
|
*/
|
|
QSharedPointer<RealTerminal> RealTerminal::sharedRef() const {
|
|
return QSharedPointer<RealTerminal>(m_this_weak);
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::weakRef
|
|
* @return a QWeakPointer of this, weak pointer can be bull
|
|
*/
|
|
QWeakPointer<RealTerminal> RealTerminal::weakRef() {
|
|
return m_this_weak;
|
|
}
|
|
|
|
/**
|
|
* @brief toXml
|
|
* @param parent_document
|
|
* @return this real terminal to xml
|
|
*/
|
|
QDomElement RealTerminal::toXml(QDomDocument &parent_document) const
|
|
{
|
|
auto root_elmt = parent_document.createElement(this->xmlTagName());
|
|
if (m_element)
|
|
root_elmt.setAttribute(QStringLiteral("element_uuid"), m_element->uuid().toString());
|
|
|
|
return root_elmt;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::setPhysicalTerminal
|
|
* Set the parent physical terminal of this real terminal
|
|
* @param phy_t
|
|
*/
|
|
void RealTerminal::setPhysicalTerminal(const QSharedPointer<PhysicalTerminal> &phy_t) {
|
|
m_physical_terminal = phy_t;
|
|
}
|
|
|
|
/**
|
|
* @brief parentStrip
|
|
* @return parent terminal strip or nullptr
|
|
*/
|
|
TerminalStrip *RealTerminal::parentStrip() const noexcept {
|
|
if (m_physical_terminal) {
|
|
return m_physical_terminal->terminalStrip();
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::physicalTerminal
|
|
* @return The parent physical terminal of this terminal.
|
|
* The returned QSharedPointer can be null
|
|
*/
|
|
QSharedPointer<PhysicalTerminal> RealTerminal::physicalTerminal() const noexcept{
|
|
return m_physical_terminal;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::level
|
|
* @return
|
|
*/
|
|
int RealTerminal::level() const
|
|
{
|
|
if (m_physical_terminal &&
|
|
sharedRef()) {
|
|
return m_physical_terminal->levelOf(sharedRef());
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* @brief label
|
|
* @return the label of this real terminal
|
|
*/
|
|
QString RealTerminal::label() const {
|
|
if (!m_element.isNull()) {
|
|
return m_element->actualLabel();
|
|
} else {
|
|
return QLatin1String();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::Xref
|
|
* @return Convenient method to get the XRef
|
|
* formatted to string
|
|
*/
|
|
QString RealTerminal::Xref() const
|
|
{
|
|
if (!m_element.isNull()) {
|
|
return autonum::AssignVariables::genericXref(m_element.data());
|
|
} else {
|
|
return QString();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::cable
|
|
* @return The name of the cable (hose) connected to this terminal.
|
|
* The value is stored in the informations of the element.
|
|
*/
|
|
QString RealTerminal::cable() const {
|
|
if (m_element) {
|
|
return m_element->elementData().m_informations.value(cableInfoKey()).toString();
|
|
}
|
|
return QString();
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::cableWire
|
|
* @return The color / number of the wire of the cable, connected to this terminal.
|
|
*/
|
|
QString RealTerminal::cableWire() const {
|
|
if (m_element) {
|
|
return m_element->elementData().m_informations.value(cableWireInfoKey()).toString();
|
|
}
|
|
return QString();
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::isShield
|
|
* @return true if this terminal is the shield of the cable
|
|
* and not one of its wires.
|
|
*/
|
|
bool RealTerminal::isShield() const {
|
|
if (m_element) {
|
|
return QET::infoFlagIsTrue(
|
|
m_element->elementData().m_informations.value(shieldInfoKey()).toString());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::color
|
|
* @return The color set by the user for this terminal, drawn in the
|
|
* terminal strip. An invalid color mean that the user did not set a color.
|
|
* The value is stored in the informations of the element.
|
|
* @sa stripeColor
|
|
*/
|
|
QColor RealTerminal::color() const
|
|
{
|
|
QColor main_, stripe_;
|
|
if (m_element) {
|
|
TerminalColor::parse(m_element->elementData().m_informations.value(colorInfoKey()).toString(),
|
|
&main_, &stripe_);
|
|
}
|
|
return main_;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::stripeColor
|
|
* @return The second color of a two-tone color (green/yellow for example)
|
|
* or an invalid color if the color of this terminal is plain or not set.
|
|
*/
|
|
QColor RealTerminal::stripeColor() const
|
|
{
|
|
QColor main_, stripe_;
|
|
if (m_element) {
|
|
TerminalColor::parse(m_element->elementData().m_informations.value(colorInfoKey()).toString(),
|
|
&main_, &stripe_);
|
|
}
|
|
return stripe_;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::section
|
|
* @return The section in mm2 set by the user for this terminal
|
|
* or 0 if no section was set.
|
|
* The value is stored in the informations of the element,
|
|
* with the dot as decimal separator, whatever the locale.
|
|
*/
|
|
qreal RealTerminal::section() const
|
|
{
|
|
if (m_element)
|
|
{
|
|
bool ok_ = false;
|
|
const auto section_ = m_element->elementData().m_informations.value(sectionInfoKey()).toString().toDouble(&ok_);
|
|
if (ok_ && section_ > 0) {
|
|
return section_;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::widthMm
|
|
* @return The width in mm of this terminal (the width of the terminal
|
|
* sold by the manufacturer), set by the user, or 0 if no width was set.
|
|
* The value is stored in the informations of the element,
|
|
* with the dot as decimal separator, whatever the locale.
|
|
*/
|
|
qreal RealTerminal::widthMm() const
|
|
{
|
|
if (m_element)
|
|
{
|
|
bool ok_ = false;
|
|
const auto width_ = m_element->elementData().m_informations.value(widthInfoKey()).toString().toDouble(&ok_);
|
|
if (ok_ && width_ > 0) {
|
|
return width_;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::hasSeparatorAfter
|
|
* @return true if a separator plate (partition plate) is mounted
|
|
* after this terminal, between this terminal and the next one of the strip.
|
|
* Used to separate groups of terminals (voltages, functions...).
|
|
*/
|
|
bool RealTerminal::hasSeparatorAfter() const {
|
|
if (m_element) {
|
|
return QET::infoFlagIsTrue(
|
|
m_element->elementData().m_informations.value(separatorInfoKey()).toString());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::conductor
|
|
* @return
|
|
*/
|
|
QString RealTerminal::conductor() const {
|
|
if (m_element)
|
|
{
|
|
const auto conductors_{m_element->conductors()};
|
|
if (conductors_.size()) {
|
|
return conductors_.first()->properties().text;
|
|
}
|
|
}
|
|
return QString();
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::type
|
|
* @return
|
|
*/
|
|
ElementData::TerminalType RealTerminal::type() const {
|
|
if (m_element) {
|
|
return m_element->elementData().terminalType();
|
|
} else {
|
|
return ElementData::TTGeneric;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::function
|
|
* @return
|
|
*/
|
|
ElementData::TerminalFunction RealTerminal::function() const {
|
|
if (m_element) {
|
|
return m_element->elementData().terminalFunction();
|
|
} else {
|
|
return ElementData::TFGeneric;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::isLed
|
|
* @return
|
|
*/
|
|
bool RealTerminal::isLed() const {
|
|
if (m_element) {
|
|
return m_element->elementData().terminalLed();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief isElement
|
|
* @return true if this real terminal is linked to a terminal element
|
|
*/
|
|
bool RealTerminal::isElement() const {
|
|
return m_element.isNull() ? false : true;
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::isBridged
|
|
* @return true if is bridged.
|
|
* @sa TerminalStrip::isBridged
|
|
*/
|
|
bool RealTerminal::isBridged() const
|
|
{
|
|
if (parentStrip()) {
|
|
return !parentStrip()->isBridged(m_this_weak.toStrongRef()).isNull();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::bridge
|
|
* @return
|
|
*/
|
|
QSharedPointer<TerminalStripBridge> RealTerminal::bridge() const
|
|
{
|
|
if (parentStrip()) {
|
|
return parentStrip()->isBridged(m_this_weak.toStrongRef());
|
|
} else {
|
|
return QSharedPointer<TerminalStripBridge>();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief element
|
|
* @return the element linked to this real terminal
|
|
* or nullptr if not linked to an Element.
|
|
*/
|
|
Element *RealTerminal::element() const {
|
|
return m_element.data();
|
|
}
|
|
|
|
/**
|
|
* @brief elementUuid
|
|
* @return if this real terminal is an element
|
|
* in a folio, return the uuid of the element
|
|
* else return a null uuid.
|
|
*/
|
|
QUuid RealTerminal::elementUuid() const {
|
|
if (!m_element.isNull()) {
|
|
return m_element->uuid();
|
|
} else {
|
|
return QUuid();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief RealTerminal::RealTerminal::xmlTagName
|
|
* @return
|
|
*/
|
|
QString RealTerminal::RealTerminal::xmlTagName() {
|
|
return QStringLiteral("real_terminal");
|
|
}
|