From 24b6f99f6505eb3df822c4dd81fff2f60a46cd0a Mon Sep 17 00:00:00 2001 From: afaina Date: Mon, 12 Jul 2021 00:34:12 +0200 Subject: [PATCH] resize a stripboard following the current layout, fixes #3090 #2998 and #3084. The slow performance is still present but the extended area is not shortcircuited. --- src/items/perfboard.cpp | 15 +++++++++++---- src/items/perfboard.h | 1 + src/items/stripboard.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/items/stripboard.h | 3 +++ src/sketch/sketchwidget.cpp | 4 ++-- 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/items/perfboard.cpp b/src/items/perfboard.cpp index 8cfadddc8..8f96b6efd 100644 --- a/src/items/perfboard.cpp +++ b/src/items/perfboard.cpp @@ -40,9 +40,9 @@ along with Fritzing. If not, see . static const int ConnectorIDJump = 1000; static const int MaxXDimension = 199; -static const int MinXDimension = 5; +static const int MinXDimension = 3; static const int MaxYDimension = 199; -static const int MinYDimension = 5; +static const int MinYDimension = 3; static const int WarningSize = 2000; static const QString OneHole("M%1,%2a%3,%3 0 1 %5 %4,0 %3,%3 0 1 %5 -%4,0z\n"); @@ -279,7 +279,7 @@ bool Perfboard::canEditPart() { return false; } -void Perfboard::changeBoardSize() +bool Perfboard::boardSizeWarning() { if (!m_gotWarning) { int x = m_xEdit->text().toInt(); @@ -303,10 +303,17 @@ void Perfboard::changeBoardSize() getXY(x, y, m_size); m_xEdit->setText(QString::number(x)); m_yEdit->setText(QString::number(y)); - return; + return true; } } } + return false; +} + +void Perfboard::changeBoardSize() +{ + if (boardSizeWarning()) + return; QString newSize = QString("%1.%2").arg(m_xEdit->text()).arg(m_yEdit->text()); m_propsMap.insert("size", newSize); diff --git a/src/items/perfboard.h b/src/items/perfboard.h index 174fa180d..9f78f37c1 100644 --- a/src/items/perfboard.h +++ b/src/items/perfboard.h @@ -66,6 +66,7 @@ protected slots: protected: static bool getXY(int & x, int & y, const QString & s); + bool boardSizeWarning(); protected: static bool m_gotWarning; diff --git a/src/items/stripboard.cpp b/src/items/stripboard.cpp index 250e326d7..205b4b6ce 100644 --- a/src/items/stripboard.cpp +++ b/src/items/stripboard.cpp @@ -858,3 +858,39 @@ QStringList Stripboard::collectValues(const QString & family, const QString & pr return values; } + +void Stripboard::changeBoardSize() +{ + if (boardSizeWarning()) + return; + + QString newSize = QString("%1.%2").arg(m_xEdit->text(), m_yEdit->text()); + m_propsMap.insert("size", newSize); + + //We have to create the "buses" (strip segments that are broken) for the strip board. + //We do not modify the previous buses. If we extend the board, we just break the strips based on + //the layout (vertical or horizontal strips). These buses properties are pased to the swap mechanism, + //which creates a new part and sets the new properties (the buses). + QString buses = prop("buses"); + QString newBuses; + bool vertical = m_layout.compare(VerticalString) == 0; + QString hv = vertical ? "h" : "v"; + int offsetX = vertical ? 1 : 0; + int offsetY = vertical ? 0 : 1; + + for (int i = 0; i < m_xEdit->text().toInt() - offsetX; i++) { + for (int j = 0; j < m_yEdit->text().toInt() - offsetY; j++) { + if (i < (m_x - offsetX) && j < (m_y - offsetY)) + continue; //Do not modify previous strips + QString newBus = QString("%1.%2%3 ").arg(i).arg(j).arg(hv); + newBuses += newBus; + } + } + + m_propsMap.insert("buses", buses + newBuses); + + InfoGraphicsView * infoGraphicsView = InfoGraphicsView::getInfoGraphicsView(this); + if (infoGraphicsView) { + infoGraphicsView->swap(family(), "size", m_propsMap, this); + } +} diff --git a/src/items/stripboard.h b/src/items/stripboard.h index ea79ba67d..676ebea76 100644 --- a/src/items/stripboard.h +++ b/src/items/stripboard.h @@ -88,6 +88,9 @@ class Stripboard : public Perfboard void swapEntry(const QString & text); QStringList collectValues(const QString & family, const QString & prop, QString & value); +protected slots: + void changeBoardSize(); + protected: void nextBus(QList & soFar); QString getRowLabel(); diff --git a/src/sketch/sketchwidget.cpp b/src/sketch/sketchwidget.cpp index af7ac430a..e4526630d 100644 --- a/src/sketch/sketchwidget.cpp +++ b/src/sketch/sketchwidget.cpp @@ -5356,14 +5356,14 @@ void SketchWidget::prepDeleteOtherProps(ItemBase * itemBase, long id, const QStr QString buses = itemBase->prop("buses"); QString newBuses = propsMap.value("buses"); if (newBuses.isEmpty()) newBuses = buses; - if (!buses.isEmpty()) { + if (!newBuses.isEmpty()) { new SetPropCommand(this, id, "buses", buses, newBuses, true, parentCommand); } QString layout = itemBase->prop("layout"); QString newLayout = propsMap.value("layout"); if (newLayout.isEmpty()) newLayout = layout; - if (!layout.isEmpty()) { + if (!newLayout.isEmpty()) { new SetPropCommand(this, id, "layout", layout, newLayout, true, parentCommand); } }