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 NetPoints forming a straight line
- Add default nullptr when searching for items at location
- Add myself to AUTHORS.md
  • Loading branch information
5n8ke committed Aug 5, 2020
1 parent 99feb39 commit 7ed178a
Show file tree
Hide file tree
Showing 11 changed files with 462 additions and 19 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))
29 changes: 15 additions & 14 deletions libs/librepcb/project/boards/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,21 @@ class Board final : public QObject,
}
bool isEmpty() const noexcept;
QList<BI_Base*> getItemsAtScenePos(const Point& pos) const noexcept;
QList<BI_Via*> getViasAtScenePos(const Point& pos,
const NetSignal* netsignal) const noexcept;
QList<BI_NetPoint*> getNetPointsAtScenePos(const Point& pos,
const GraphicsLayer* layer,
const NetSignal* netsignal) const
noexcept;
QList<BI_NetLine*> getNetLinesAtScenePos(const Point& pos,
const GraphicsLayer* layer,
const NetSignal* netsignal) const
noexcept;
QList<BI_FootprintPad*> getPadsAtScenePos(const Point& pos,
const GraphicsLayer* layer,
const NetSignal* netsignal) const
noexcept;
QList<BI_Via*> getViasAtScenePos(const Point& pos,
const NetSignal* netsignal = nullptr)
const noexcept;
QList<BI_NetPoint*> getNetPointsAtScenePos(const Point& pos,
const GraphicsLayer* layer = nullptr,
const NetSignal* netsignal = nullptr)
const noexcept;
QList<BI_NetLine*> getNetLinesAtScenePos(const Point& pos,
const GraphicsLayer* layer = nullptr,
const NetSignal* netsignal = nullptr)
const noexcept;
QList<BI_FootprintPad*> getPadsAtScenePos(const Point& pos,
const GraphicsLayer* layer = nullptr,
const NetSignal* netsignal = nullptr)
const noexcept;
QList<BI_Base*> getAllItems() const noexcept;

// Setters: General
Expand Down
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 @@ -142,11 +142,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
5 changes: 5 additions & 0 deletions libs/librepcb/projecteditor/boardeditor/boardeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ BoardEditor::BoardEditor(ProjectEditor& projectEditor, Project& project)
mUi->actionToolAddText);
mToolsActionGroup->addAction(BES_FSM::State::State_AddHole,
mUi->actionToolAddHole);
mToolsActionGroup->addAction(BES_FSM::State::State_Simplify,
mUi->actionToolSimplify);
mToolsActionGroup->setCurrentAction(mFsm->getCurrentState());
connect(mFsm, &BES_FSM::stateChanged, mToolsActionGroup.data(),
&ExclusiveActionGroup::setCurrentAction);
Expand Down Expand Up @@ -812,6 +814,9 @@ void BoardEditor::toolActionGroupChangeTriggered(
case BES_FSM::State::State_AddHole:
mFsm->processEvent(new BEE_Base(BEE_Base::StartAddHole), true);
break;
case BES_FSM::State::State_Simplify:
mFsm->processEvent(new BEE_Base(BEE_Base::StartSimplify), true);
break;
default:
Q_ASSERT(false);
qCritical() << "Unknown tool triggered!";
Expand Down
14 changes: 14 additions & 0 deletions libs/librepcb/projecteditor/boardeditor/boardeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<addaction name="actionToolSelect"/>
<addaction name="actionToolAddVia"/>
<addaction name="actionToolDrawTrace"/>
<addaction name="actionToolSimplify"/>
<addaction name="actionToolDrawPolygon"/>
<addaction name="actionToolAddText"/>
<addaction name="actionToolAddHole"/>
Expand Down Expand Up @@ -272,6 +273,7 @@
<addaction name="actionToolSelect"/>
<addaction name="actionToolAddVia"/>
<addaction name="actionToolDrawTrace"/>
<addaction name="actionToolSimplify"/>
<addaction name="actionToolDrawPolygon"/>
<addaction name="actionToolAddText"/>
<addaction name="actionToolAddHole"/>
Expand Down Expand Up @@ -926,6 +928,18 @@
<string notr="true">Ctrl+A</string>
</property>
</action>
<action name="actionToolSimplify">
<property name="icon">
<iconset>
<normaloff>:/img/actions/ruler.png</normaloff>:/img/actions/ruler.png</iconset>
</property>
<property name="text">
<string>Simplify</string>
</property>
<property name="toolTip">
<string>Simplify traces</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
7 changes: 7 additions & 0 deletions libs/librepcb/projecteditor/boardeditor/fsm/bes_fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "bes_drawpolygon.h"
#include "bes_drawtrace.h"
#include "bes_select.h"
#include "bes_simplify.h"
#include "boardeditorevent.h"
#include "ui_boardeditor.h"

Expand Down Expand Up @@ -80,6 +81,9 @@ BES_FSM::BES_FSM(BoardEditor& editor, Ui::BoardEditor& editorUi,
mSubStates.insert(
State_AddHole,
new BES_AddHole(mEditor, mEditorUi, mEditorGraphicsView, mUndoStack));
mSubStates.insert(
State_Simplify,
new BES_Simplify(mEditor, mEditorUi, mEditorGraphicsView, mUndoStack));

// go to state "Select"
if (mSubStates[State_Select]->entry(nullptr)) {
Expand Down Expand Up @@ -190,6 +194,9 @@ BES_FSM::State BES_FSM::processEventFromChild(BEE_Base* event) noexcept {
case BEE_Base::StartAddDevice:
event->setAccepted(true);
return State_AddDevice;
case BEE_Base::StartSimplify:
event->setAccepted(true);
return State_Simplify;
case BEE_Base::GraphicsViewEvent: {
QEvent* e = BEE_RedirectedQEvent::getQEventFromBEE(event);
Q_ASSERT(e);
Expand Down
1 change: 1 addition & 0 deletions libs/librepcb/projecteditor/boardeditor/fsm/bes_fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class BES_FSM final : public BES_Base {
State_AddVia, ///< ::librepcb::project::editor::BES_AddVia
State_AddDevice, ///< ::librepcb::project::editor::BES_AddDevice
State_DrawPlane, ///< ::librepcb::project::editor::BES_DrawPlane
State_Simplify, ///< ::librepcb::project::editor::BES_Simplify
};

// Constructors / Destructor
Expand Down

0 comments on commit 7ed178a

Please sign in to comment.