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 "cmdremoveunusednetsignals.h"
24
25 #include <librepcb/project/boards/cmd/cmdboardnetsegmentremove.h>
26 #include <librepcb/project/boards/cmd/cmdboardplaneremove.h>
27 #include <librepcb/project/circuit/circuit.h>
28 #include <librepcb/project/circuit/cmd/cmdnetsignalremove.h>
29 #include <librepcb/project/circuit/netsignal.h>
30
31 #include <QtCore>
32
33 /*******************************************************************************
34 * Namespace
35 ******************************************************************************/
36 namespace librepcb {
37 namespace project {
38 namespace editor {
39
40 /*******************************************************************************
41 * Constructors / Destructor
42 ******************************************************************************/
43
CmdRemoveUnusedNetSignals(Circuit & circuit)44 CmdRemoveUnusedNetSignals::CmdRemoveUnusedNetSignals(Circuit& circuit) noexcept
45 : UndoCommandGroup(tr("Remove Unused Net Signals")), mCircuit(circuit) {
46 }
47
~CmdRemoveUnusedNetSignals()48 CmdRemoveUnusedNetSignals::~CmdRemoveUnusedNetSignals() noexcept {
49 }
50
51 /*******************************************************************************
52 * Inherited from UndoCommand
53 ******************************************************************************/
54
performExecute()55 bool CmdRemoveUnusedNetSignals::performExecute() {
56 foreach (NetSignal* netsignal, mCircuit.getNetSignals()) {
57 bool noComponentSignals = netsignal->getComponentSignals().isEmpty();
58 bool noSchematicNetSegments =
59 netsignal->getSchematicNetSegments().isEmpty();
60 if (noComponentSignals && noSchematicNetSegments) {
61 foreach (BI_NetSegment* netsegment, netsignal->getBoardNetSegments()) {
62 appendChild(new CmdBoardNetSegmentRemove(*netsegment));
63 }
64 foreach (BI_Plane* plane, netsignal->getBoardPlanes()) {
65 appendChild(new CmdBoardPlaneRemove(*plane));
66 }
67 appendChild(new CmdNetSignalRemove(mCircuit, *netsignal));
68 }
69 }
70
71 // execute all child commands
72 return UndoCommandGroup::performExecute(); // can throw
73 }
74
75 /*******************************************************************************
76 * End of File
77 ******************************************************************************/
78
79 } // namespace editor
80 } // namespace project
81 } // namespace librepcb
82