Skip to content

Commit

Permalink
Implementation of "simplify" command
Browse files Browse the repository at this point in the history
- New Tool class created and added to GUI
  - Remove duplicate NetLines with the same start and end points
  - Merge NetPoints at the same location
  - Connect Vias with the NetPoints and NetLines at the same location
  - Connect NetPoints with NetLines at the same location
  - Plan out other simplifications
  - Simplify NetLines forming a straight line
- new CmdBoardCombineAnchors undo command group, that combines anchors of the same NetSegment. Based on combineAnchors in BoardEditorState_DrawTrace
- Add default nullptr when searching for items at location
- Add myself to AUTHORS.md
  • Loading branch information
5n8ke committed Sep 4, 2020
1 parent 0046d47 commit e5d9a62
Show file tree
Hide file tree
Showing 14 changed files with 714 additions and 100 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ yourself by creating a pull request (see [CONTRIBUTING.md](CONTRIBUTING.md)).
- [@chrisgwerder](https://github.com/chrisgwerder)
- [@0xB767B](https://github.com/0xB767B)
- Josua Schmid ([@schmijos](https://github.com/schmijos))
- Lucas Keune ([@5n8ke](https://github.com/5n8ke))
16 changes: 11 additions & 5 deletions libs/librepcb/project/boards/items/bi_netpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,17 @@ void BI_NetPoint::removeFromBoard() {
}

void BI_NetPoint::registerNetLine(BI_NetLine& netline) {
if ((!isAddedToBoard()) || (mRegisteredNetLines.contains(&netline)) ||
(&netline.getNetSegment() != &mNetSegment) ||
((mRegisteredNetLines.count() > 0) &&
(&netline.getLayer() != getLayerOfLines()))) {
throw LogicError(__FILE__, __LINE__);
if (!isAddedToBoard()) {
throw LogicError(__FILE__, __LINE__, "NetPoint is not added to the board.");
} else if (mRegisteredNetLines.contains(&netline)) {
throw LogicError(__FILE__, __LINE__,
"NetLine already registered to NetPoint.");
} else if (&netline.getNetSegment() != &mNetSegment) {
throw LogicError(__FILE__, __LINE__,
"NetLine is part of a different NetSegment.");
} else if ((mRegisteredNetLines.count() > 0) &&
(&netline.getLayer() != getLayerOfLines())) {
throw LogicError(__FILE__, __LINE__, "NetLine is on a different layer.");
}
mRegisteredNetLines.insert(&netline);
netline.updateLine();
Expand Down
12 changes: 8 additions & 4 deletions libs/librepcb/project/boards/items/bi_netsegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,15 @@ void BI_NetSegment::removeElements(const QList<BI_Via*>& vias,
const QList<BI_NetPoint*>& netpoints,
const QList<BI_NetLine*>& netlines) {
if (!isAddedToBoard()) {
throw LogicError(__FILE__, __LINE__);
throw LogicError(__FILE__, __LINE__,
"Element to be removed not added to board.");
}

ScopeGuardList sgl(netpoints.count() + netlines.count());
foreach (BI_NetLine* netline, netlines) {
if (!mNetLines.contains(netline)) {
throw LogicError(__FILE__, __LINE__);
throw LogicError(__FILE__, __LINE__,
"Netline to be removed not part of the netsegment.");
}
// remove from board
netline->removeFromBoard(); // can throw
Expand All @@ -417,7 +419,8 @@ void BI_NetSegment::removeElements(const QList<BI_Via*>& vias,
}
foreach (BI_NetPoint* netpoint, netpoints) {
if (!mNetPoints.contains(netpoint)) {
throw LogicError(__FILE__, __LINE__);
throw LogicError(__FILE__, __LINE__,
"Netpoint to be removed not part of the netsegment.");
}
// remove from board
netpoint->removeFromBoard(); // can throw
Expand All @@ -429,7 +432,8 @@ void BI_NetSegment::removeElements(const QList<BI_Via*>& vias,
}
foreach (BI_Via* via, vias) {
if (!mVias.contains(via)) {
throw LogicError(__FILE__, __LINE__);
throw LogicError(__FILE__, __LINE__,
"Via to be removed not part of the netsegment.");
}
// remove from board
via->removeFromBoard(); // can throw
Expand Down
5 changes: 5 additions & 0 deletions libs/librepcb/projecteditor/boardeditor/boardeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ BoardEditor::BoardEditor(ProjectEditor& projectEditor, Project& project)
mUi->actionToolAddText);
mToolsActionGroup->addAction(BoardEditorFsm::State::ADD_HOLE,
mUi->actionToolAddHole);
mToolsActionGroup->addAction(BoardEditorFsm::State::SIMPLIFY,
mUi->actionToolSimplify);
mToolsActionGroup->setCurrentAction(mFsm->getCurrentState());
connect(mFsm.data(), &BoardEditorFsm::stateChanged, mToolsActionGroup.data(),
&ExclusiveActionGroup::setCurrentAction);
Expand Down Expand Up @@ -874,6 +876,9 @@ void BoardEditor::toolActionGroupChangeTriggered(
case BoardEditorFsm::State::ADD_HOLE:
mFsm->processAddHole();
break;
case BoardEditorFsm::State::SIMPLIFY:
mFsm->processSimplify();
break;
default:
Q_ASSERT(false);
qCritical() << "Unknown tool triggered!";
Expand Down

0 comments on commit e5d9a62

Please sign in to comment.