Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************************
* Includes
******************************************************************************/
#include "sgi_netpoint.h"
#include "../../../graphics/graphicslayer.h"
#include "../../../graphics/graphicslayerlist.h"
#include "../schematicgraphicsscene.h"
#include <librepcb/core/project/circuit/netsignal.h>
#include <librepcb/core/project/schematic/items/si_netpoint.h>
#include <librepcb/core/project/schematic/items/si_netsegment.h>
#include <librepcb/core/workspace/colorrole.h>
#include <QtCore>
#include <QtWidgets>
/*******************************************************************************
* Namespace
******************************************************************************/
namespace librepcb {
namespace editor {
QRectF SGI_NetPoint::sBoundingRect;
/*******************************************************************************
* Constructors / Destructor
******************************************************************************/
SGI_NetPoint::SGI_NetPoint(
SI_NetPoint& netpoint, const GraphicsLayerList& layers,
std::shared_ptr<const SchematicGraphicsScene::Context> context) noexcept
: QGraphicsItem(),
mNetPoint(netpoint),
mContext(context),
mLayer(layers.get(ColorRole::schematicWires())),
mOnEditedSlot(*this, &SGI_NetPoint::netPointEdited) {
setFlag(QGraphicsItem::ItemIsSelectable, true);
setZValue(SchematicGraphicsScene::ZValue_VisibleNetPoints);
if (sBoundingRect.isNull()) {
qreal radius = Length(600000).toPx();
sBoundingRect = QRectF(-radius, -radius, 2 * radius, 2 * radius);
}
updatePosition();
updateJunction();
mNetPoint.onEdited.attach(mOnEditedSlot);
}
SGI_NetPoint::~SGI_NetPoint() noexcept {
}
/*******************************************************************************
* Inherited from QGraphicsItem
******************************************************************************/
void SGI_NetPoint::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget) {
Q_UNUSED(widget);
if ((!mLayer) || (!mLayer->isVisible())) {
return;
}
const NetSignal* net = &mNetPoint.getNetSegment().getNetSignal();
const bool selected = option->state.testFlag(QStyle::State_Selected);
const GraphicsLayer::State state = mContext->getLayerState(selected, net);
if (mIsVisibleJunction) {
painter->setPen(Qt::NoPen);
painter->setBrush(QBrush(mLayer->getColor(state), Qt::SolidPattern));
painter->drawEllipse(sBoundingRect);
} else if (mIsOpenLineEnd) {
painter->setPen(QPen(mLayer->getColor(state), 0));
painter->setBrush(Qt::NoBrush);
painter->drawLine(sBoundingRect.topLeft() / 2,
sBoundingRect.bottomRight() / 2);
painter->drawLine(sBoundingRect.topRight() / 2,
sBoundingRect.bottomLeft() / 2);
}
}
/*******************************************************************************
* Private Methods
******************************************************************************/
void SGI_NetPoint::netPointEdited(const SI_NetPoint& obj,
SI_NetPoint::Event event) noexcept {
Q_UNUSED(obj);
switch (event) {
case SI_NetPoint::Event::PositionChanged:
updatePosition();
break;
case SI_NetPoint::Event::JunctionChanged:
updateJunction();
break;
case SI_NetPoint::Event::NetSignalNameChanged:
break;
default:
qWarning() << "Unhandled switch-case in SGI_NetPoint::netPointlEdited():"
<< static_cast<int>(event);
break;
}
}
void SGI_NetPoint::updatePosition() noexcept {
setPos(mNetPoint.getPosition().toPxQPointF());
}
void SGI_NetPoint::updateJunction() noexcept {
prepareGeometryChange();
mIsVisibleJunction = mNetPoint.isVisibleJunction();
mIsOpenLineEnd = mNetPoint.isOpen();
setZValue(mIsVisibleJunction
? SchematicGraphicsScene::ZValue_VisibleNetPoints
: SchematicGraphicsScene::ZValue_HiddenNetPoints);
update();
}
/*******************************************************************************
* End of File
******************************************************************************/
} // namespace editor
} // namespace librepcb
59219ad85This file is pinned to the selected release. Download the original to open it in your design tool.