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 "cmdschematicnetsegmentadd.h"
24
25 #include "../items/si_netsegment.h"
26 #include "../schematic.h"
27
28 #include <QtCore>
29
30 /*******************************************************************************
31 * Namespace
32 ******************************************************************************/
33 namespace librepcb {
34 namespace project {
35
36 /*******************************************************************************
37 * Constructors / Destructor
38 ******************************************************************************/
39
CmdSchematicNetSegmentAdd(SI_NetSegment & segment)40 CmdSchematicNetSegmentAdd::CmdSchematicNetSegmentAdd(
41 SI_NetSegment& segment) noexcept
42 : UndoCommand(tr("Add net segment")),
43 mSchematic(segment.getSchematic()),
44 mNetSignal(segment.getNetSignal()),
45 mNetSegment(&segment) {
46 }
47
CmdSchematicNetSegmentAdd(Schematic & schematic,NetSignal & netsignal)48 CmdSchematicNetSegmentAdd::CmdSchematicNetSegmentAdd(
49 Schematic& schematic, NetSignal& netsignal) noexcept
50 : UndoCommand(tr("Add net segment")),
51 mSchematic(schematic),
52 mNetSignal(netsignal),
53 mNetSegment(nullptr) {
54 }
55
~CmdSchematicNetSegmentAdd()56 CmdSchematicNetSegmentAdd::~CmdSchematicNetSegmentAdd() noexcept {
57 }
58
59 /*******************************************************************************
60 * Inherited from UndoCommand
61 ******************************************************************************/
62
performExecute()63 bool CmdSchematicNetSegmentAdd::performExecute() {
64 if (!mNetSegment) {
65 // create new net segment
66 mNetSegment = new SI_NetSegment(mSchematic, mNetSignal); // can throw
67 }
68
69 performRedo(); // can throw
70
71 return true;
72 }
73
performUndo()74 void CmdSchematicNetSegmentAdd::performUndo() {
75 mSchematic.removeNetSegment(*mNetSegment); // can throw
76 }
77
performRedo()78 void CmdSchematicNetSegmentAdd::performRedo() {
79 mSchematic.addNetSegment(*mNetSegment); // can throw
80 }
81
82 /*******************************************************************************
83 * End of File
84 ******************************************************************************/
85
86 } // namespace project
87 } // namespace librepcb
88