1 /*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*******************************************************************************
21 * Includes
22 ******************************************************************************/
23 #include "cmdboardnetlineedit.h"
24
25 #include <QtCore>
26
27 /*******************************************************************************
28 * Namespace
29 ******************************************************************************/
30 namespace librepcb {
31 namespace project {
32
33 /*******************************************************************************
34 * Constructors / Destructor
35 ******************************************************************************/
36
CmdBoardNetLineEdit(BI_NetLine & netline)37 CmdBoardNetLineEdit::CmdBoardNetLineEdit(BI_NetLine& netline) noexcept
38 : UndoCommand(tr("Edit trace")),
39 mNetLine(netline),
40 mOldLayer(&netline.getLayer()),
41 mNewLayer(mOldLayer),
42 mOldWidth(netline.getWidth()),
43 mNewWidth(mOldWidth) {
44 }
45
~CmdBoardNetLineEdit()46 CmdBoardNetLineEdit::~CmdBoardNetLineEdit() noexcept {
47 }
48
49 /*******************************************************************************
50 * Setters
51 ******************************************************************************/
52
setLayer(GraphicsLayer & layer)53 void CmdBoardNetLineEdit::setLayer(GraphicsLayer& layer) noexcept {
54 Q_ASSERT(!wasEverExecuted());
55 mNewLayer = &layer;
56 }
57
setWidth(const PositiveLength & width)58 void CmdBoardNetLineEdit::setWidth(const PositiveLength& width) noexcept {
59 Q_ASSERT(!wasEverExecuted());
60 mNewWidth = width;
61 }
62
63 /*******************************************************************************
64 * Inherited from UndoCommand
65 ******************************************************************************/
66
performExecute()67 bool CmdBoardNetLineEdit::performExecute() {
68 performRedo(); // can throw
69
70 return true; // TODO: determine if the via was really modified
71 }
72
performUndo()73 void CmdBoardNetLineEdit::performUndo() {
74 mNetLine.setLayer(*mOldLayer);
75 mNetLine.setWidth(mOldWidth);
76 }
77
performRedo()78 void CmdBoardNetLineEdit::performRedo() {
79 mNetLine.setLayer(*mNewLayer);
80 mNetLine.setWidth(mNewWidth);
81 }
82
83 /*******************************************************************************
84 * End of File
85 ******************************************************************************/
86
87 } // namespace project
88 } // namespace librepcb
89