Skip to content

Commit

Permalink
resize a stripboard following the current layout, fixes #3090 #2998 and
Browse files Browse the repository at this point in the history
#3084. The slow performance is still present but the extended area is not shortcircuited.
  • Loading branch information
failiz authored and KjellMorgenstern committed Sep 22, 2021
1 parent 17d6db9 commit 24b6f99
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/items/perfboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.

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");
Expand Down Expand Up @@ -279,7 +279,7 @@ bool Perfboard::canEditPart() {
return false;
}

void Perfboard::changeBoardSize()
bool Perfboard::boardSizeWarning()
{
if (!m_gotWarning) {
int x = m_xEdit->text().toInt();
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/items/perfboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected slots:

protected:
static bool getXY(int & x, int & y, const QString & s);
bool boardSizeWarning();

protected:
static bool m_gotWarning;
Expand Down
36 changes: 36 additions & 0 deletions src/items/stripboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions src/items/stripboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectorItem *> & soFar);
QString getRowLabel();
Expand Down
4 changes: 2 additions & 2 deletions src/sketch/sketchwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 24b6f99

Please sign in to comment.