void SGI_NetLabel::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(widget); bool deviceIsPrinter = (dynamic_cast<QPrinter*>(painter->device()) != 0); const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); SchematicLayer* layer = getSchematicLayer(SchematicLayer::OriginCrosses); Q_ASSERT(layer); if ((layer->isVisible()) && (lod > 2) && (!deviceIsPrinter)) { // draw origin cross painter->setPen(QPen(layer->getColor(mNetLabel.isSelected()), 0)); painter->drawLines(sOriginCrossLines); } layer = getSchematicLayer(SchematicLayer::NetLabels); Q_ASSERT(layer); if ((layer->isVisible()) && ((deviceIsPrinter) || (lod > 1))) { // draw text painter->setPen(QPen(layer->getColor(mNetLabel.isSelected()), 0)); painter->setFont(mFont); if (mRotate180) { painter->save(); painter->rotate(180); painter->drawStaticText(mTextOrigin, mStaticText); painter->restore(); } else painter->drawStaticText(mTextOrigin, mStaticText); } else { // draw filled rect painter->setPen(Qt::NoPen); painter->setBrush(QBrush(layer->getColor(mNetLabel.isSelected()), Qt::Dense5Pattern)); painter->drawRect(mBoundingRect); } #ifdef QT_DEBUG layer = getSchematicLayer(SchematicLayer::LayerID::DEBUG_GraphicsItemsBoundingRect); Q_ASSERT(layer); if (layer->isVisible()) { // draw bounding rect painter->setPen(QPen(layer->getColor(mNetLabel.isSelected()), 0)); painter->setBrush(Qt::NoBrush); painter->drawRect(mBoundingRect); } layer = getSchematicLayer(SchematicLayer::LayerID::DEBUG_GraphicsItemsTextsBoundingRect); Q_ASSERT(layer); if (layer->isVisible()) { // draw text bounding rect painter->setPen(QPen(layer->getColor(mNetLabel.isSelected()), 0)); painter->setBrush(Qt::NoBrush); painter->drawRect(QRectF(mTextOrigin, mStaticText.size())); } #endif }
SGI_NetLine::SGI_NetLine(SI_NetLine& netline) noexcept : SGI_Base(), mNetLine(netline), mLayer(nullptr) { setZValue(Schematic::ZValue_NetLines); mLayer = getSchematicLayer(SchematicLayer::Nets); Q_ASSERT(mLayer); updateCacheAndRepaint(); }
void SGI_NetLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); bool highlight = mNetLine.isSelected() || mNetLine.getNetSignal().isHighlighted(); // draw line if (mLayer->isVisible()) { QPen pen(mLayer->getColor(highlight), mNetLine.getWidth().toPx(), Qt::SolidLine, Qt::RoundCap); painter->setPen(pen); painter->drawLine(mLineF); } #ifdef QT_DEBUG SchematicLayer* layer = getSchematicLayer(SchematicLayer::LayerID::DEBUG_NetLinesNetSignalNames); Q_ASSERT(layer); if (layer->isVisible()) { // draw net signal name QFont font; font.setStyleStrategy(QFont::StyleStrategy(QFont::OpenGLCompatible | QFont::PreferQuality)); font.setStyleHint(QFont::TypeWriter); font.setFamily("Monospace"); font.setPixelSize(3); painter->setFont(font); painter->setPen(QPen(layer->getColor(highlight), 0)); painter->drawText(mLineF.pointAt((qreal)0.5), mNetLine.getNetSignal().getName()); } layer = getSchematicLayer(SchematicLayer::LayerID::DEBUG_GraphicsItemsBoundingRect); Q_ASSERT(layer); if (layer->isVisible()) { // draw bounding rect painter->setPen(QPen(layer->getColor(highlight), 0)); painter->setBrush(Qt::NoBrush); painter->drawRect(mBoundingRect); } #endif }
void SGI_Symbol::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(widget); const SchematicLayer* layer = 0; const bool selected = mSymbol.isSelected(); const bool deviceIsPrinter = (dynamic_cast<QPrinter*>(painter->device()) != 0); const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); // draw all polygons for (int i = 0; i < mLibSymbol.getPolygonCount(); i++) { const Polygon* polygon = mLibSymbol.getPolygon(i); Q_ASSERT(polygon); if (!polygon) continue; // set colors layer = getSchematicLayer(polygon->getLayerId()); if (layer) {if (!layer->isVisible()) layer = nullptr;} if (layer) painter->setPen(QPen(layer->getColor(selected), polygon->getWidth().toPx(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); else painter->setPen(Qt::NoPen); if (polygon->isFilled()) layer = getSchematicLayer(polygon->getLayerId()); else if (polygon->isGrabArea()) layer = getSchematicLayer(SchematicLayer::LayerID::SymbolGrabAreas); else layer = nullptr; if (layer) {if (!layer->isVisible()) layer = nullptr;} painter->setBrush(layer ? QBrush(layer->getColor(selected), Qt::SolidPattern) : Qt::NoBrush); // draw polygon painter->drawPath(polygon->toQPainterPathPx()); } // draw all ellipses for (int i = 0; i < mLibSymbol.getEllipseCount(); i++) { const Ellipse* ellipse = mLibSymbol.getEllipse(i); Q_ASSERT(ellipse); if (!ellipse) continue; // set colors layer = getSchematicLayer(ellipse->getLayerId()); if (layer) {if (!layer->isVisible()) layer = nullptr;} if (layer) painter->setPen(QPen(layer->getColor(selected), ellipse->getLineWidth().toPx(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); else painter->setPen(Qt::NoPen); if (ellipse->isFilled()) layer = getSchematicLayer(ellipse->getLayerId()); else if (ellipse->isGrabArea()) layer = getSchematicLayer(SchematicLayer::LayerID::SymbolGrabAreas); else layer = nullptr; if (layer) {if (!layer->isVisible()) layer = nullptr;} painter->setBrush(layer ? QBrush(layer->getColor(selected), Qt::SolidPattern) : Qt::NoBrush); // draw ellipse painter->drawEllipse(ellipse->getCenter().toPxQPointF(), ellipse->getRadiusX().toPx(), ellipse->getRadiusY().toPx()); // TODO: rotation } // draw all texts for (int i = 0; i < mLibSymbol.getTextCount(); i++) { const Text* text = mLibSymbol.getText(i); Q_ASSERT(text); if (!text) continue; // get layer layer = getSchematicLayer(text->getLayerId()); if (!layer) continue; if (!layer->isVisible()) continue; // get cached text properties const CachedTextProperties_t& props = mCachedTextProperties.value(text); mFont.setPixelSize(props.fontPixelSize); // draw text or rect painter->save(); painter->translate(text->getPosition().toPxQPointF()); painter->rotate(-text->getRotation().toDeg()); painter->translate(-text->getPosition().toPxQPointF()); painter->scale(props.scaleFactor, props.scaleFactor); if (props.rotate180) painter->rotate(180); if ((deviceIsPrinter) || (lod * text->getHeight().toPx() > 8)) { // draw text painter->setPen(QPen(layer->getColor(selected), 0)); painter->setFont(mFont); painter->drawText(props.textRect, props.flags, props.text); } else { // fill rect painter->fillRect(props.textRect, QBrush(layer->getColor(selected), Qt::Dense5Pattern)); } #ifdef QT_DEBUG layer = getSchematicLayer(SchematicLayer::LayerID::DEBUG_GraphicsItemsTextsBoundingRect); Q_ASSERT(layer); if (layer->isVisible()) { // draw text bounding rect painter->setPen(QPen(layer->getColor(selected), 0)); painter->setBrush(Qt::NoBrush); painter->drawRect(props.textRect); } #endif painter->restore(); } // draw origin cross if (!deviceIsPrinter) { layer = getSchematicLayer(SchematicLayer::OriginCrosses); Q_ASSERT(layer); if (layer->isVisible()) { qreal width = Length(700000).toPx(); painter->setPen(QPen(layer->getColor(selected), 0)); painter->drawLine(-2*width, 0, 2*width, 0); painter->drawLine(0, -2*width, 0, 2*width); } } #ifdef QT_DEBUG layer = getSchematicLayer(SchematicLayer::LayerID::DEBUG_ComponentSymbolsCount); Q_ASSERT(layer); if (layer->isVisible()) { // show symbols count of the component int count = mSymbol.getComponentInstance().getPlacedSymbolsCount(); int maxCount = mSymbol.getComponentInstance().getSymbolVariant().getItemCount(); mFont.setPixelSize(Length(1000000).toPx()); painter->setFont(mFont); painter->setPen(QPen(layer->getColor(selected), 0, Qt::SolidLine, Qt::RoundCap)); painter->drawText(QRectF(), Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine | Qt::TextDontClip, QString("[%1/%2]").arg(count).arg(maxCount)); } layer = getSchematicLayer(SchematicLayer::LayerID::DEBUG_GraphicsItemsBoundingRect); Q_ASSERT(layer); if (layer->isVisible()) { // draw bounding rect painter->setPen(QPen(layer->getColor(selected), 0)); painter->setBrush(Qt::NoBrush); painter->drawRect(mBoundingRect); } #endif }