LibrePCB Developers Documentation
cmdremoveboarditems.h
Go to the documentation of this file.
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 #ifndef LIBREPCB_PROJECT_CMDREMOVEBOARDITEMS_H
21 #define LIBREPCB_PROJECT_CMDREMOVEBOARDITEMS_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 namespace project {
35 
36 class Board;
37 class BI_Device;
38 class BI_NetSegment;
39 class BI_Via;
40 class BI_NetPoint;
41 class BI_NetLine;
42 class BI_NetLineAnchor;
43 class BI_Plane;
44 class BI_Polygon;
45 class BI_StrokeText;
46 class BI_Hole;
47 
48 namespace editor {
49 
50 /*******************************************************************************
51  * Class CmdRemoveBoardItems
52  ******************************************************************************/
53 
57 class CmdRemoveBoardItems final : public UndoCommandGroup {
58 private:
59  // Private Types
60  struct NetSegmentItems {
61  QSet<BI_Via*> vias;
62  QSet<BI_NetPoint*> netpoints;
63  QSet<BI_NetLine*> netlines;
64  };
65  typedef QHash<BI_NetSegment*, NetSegmentItems> NetSegmentItemList;
66 
67 public:
68  // Constructors / Destructor
69  CmdRemoveBoardItems() = delete;
70  CmdRemoveBoardItems(const CmdRemoveBoardItems& other) = delete;
71  explicit CmdRemoveBoardItems(Board& board) noexcept;
72  ~CmdRemoveBoardItems() noexcept;
73 
74  // Set items to remove
75  void removeDeviceInstances(const QSet<BI_Device*>& set) {
76  Q_ASSERT(!wasEverExecuted());
77  mDeviceInstances += set;
78  }
79  void removeNetSegments(const QSet<BI_NetSegment*>& set) {
80  Q_ASSERT(!wasEverExecuted());
81  mNetSegments += set;
82  }
83  void removeVias(const QSet<BI_Via*>& set) {
84  Q_ASSERT(!wasEverExecuted());
85  mVias += set;
86  }
87  void removeNetPoints(const QSet<BI_NetPoint*>& set) {
88  Q_ASSERT(!wasEverExecuted());
89  mNetPoints += set;
90  }
91  void removeNetLines(const QSet<BI_NetLine*>& set) {
92  Q_ASSERT(!wasEverExecuted());
93  mNetLines += set;
94  }
95  void removePlanes(const QSet<BI_Plane*>& set) {
96  Q_ASSERT(!wasEverExecuted());
97  mPlanes += set;
98  }
99  void removePolygons(const QSet<BI_Polygon*>& set) {
100  Q_ASSERT(!wasEverExecuted());
101  mPolygons += set;
102  }
103  void removeStrokeTexts(const QSet<BI_StrokeText*>& set) {
104  Q_ASSERT(!wasEverExecuted());
105  mStrokeTexts += set;
106  }
107  void removeHoles(const QSet<BI_Hole*>& set) {
108  Q_ASSERT(!wasEverExecuted());
109  mHoles += set;
110  }
111 
112  // Operator Overloadings
113  CmdRemoveBoardItems& operator=(const CmdRemoveBoardItems& other) = delete;
114 
115 private: // Methods
117  bool performExecute() override;
118 
119  void splitUpNetSegment(BI_NetSegment& netsegment,
120  const NetSegmentItems& itemsToRemove);
121  void createNewSubNetSegment(BI_NetSegment& netsegment,
122  const NetSegmentItems& items);
123  QVector<NetSegmentItems> getNonCohesiveNetSegmentSubSegments(
124  BI_NetSegment& segment, const NetSegmentItems& removedItems) noexcept;
126  BI_NetLineAnchor& anchor, QSet<BI_NetLineAnchor*>& processedAnchors,
127  QSet<BI_Via*>& vias, QSet<BI_NetPoint*>& netpoints,
128  QSet<BI_NetLine*>& netlines, QSet<BI_Via*>& availableVias,
129  QSet<BI_NetLine*>& availableNetLines) const noexcept;
130 
131 private: // Data
133 
134  // Items to remove
135  QSet<BI_Device*> mDeviceInstances;
136  QSet<BI_NetSegment*> mNetSegments;
137  QSet<BI_Via*> mVias;
138  QSet<BI_NetPoint*> mNetPoints;
139  QSet<BI_NetLine*> mNetLines;
140  QSet<BI_Plane*> mPlanes;
141  QSet<BI_Polygon*> mPolygons;
142  QSet<BI_StrokeText*> mStrokeTexts;
143  QSet<BI_Hole*> mHoles;
144 };
145 
146 /*******************************************************************************
147  * End of File
148  ******************************************************************************/
149 
150 } // namespace editor
151 } // namespace project
152 } // namespace librepcb
153 
154 #endif // LIBREPCB_PROJECT_CMDREMOVEBOARDITEMS_H
QSet< BI_Polygon * > mPolygons
Definition: cmdremoveboarditems.h:141
QSet< BI_NetSegment * > mNetSegments
Definition: cmdremoveboarditems.h:136
QSet< BI_NetLine * > mNetLines
Definition: cmdremoveboarditems.h:139
bool performExecute() override
Execute the command the first time.
Definition: cmdremoveboarditems.cpp:75
QSet< BI_NetPoint * > netpoints
Definition: cmdremoveboarditems.h:62
bool wasEverExecuted() const noexcept
This method shows whether that command was ever executed (execute() called successfully) ...
Definition: undocommand.h:64
void removePolygons(const QSet< BI_Polygon *> &set)
Definition: cmdremoveboarditems.h:99
void removeNetSegments(const QSet< BI_NetSegment *> &set)
Definition: cmdremoveboarditems.h:79
void removeStrokeTexts(const QSet< BI_StrokeText *> &set)
Definition: cmdremoveboarditems.h:103
Definition: airwiresbuilder.cpp:32
Board & mBoard
Definition: cmdremoveboarditems.h:132
QSet< BI_NetLine * > netlines
Definition: cmdremoveboarditems.h:63
void removeNetLines(const QSet< BI_NetLine *> &set)
Definition: cmdremoveboarditems.h:91
void createNewSubNetSegment(BI_NetSegment &netsegment, const NetSegmentItems &items)
Definition: cmdremoveboarditems.cpp:198
QSet< BI_Device * > mDeviceInstances
Definition: cmdremoveboarditems.h:135
The UndoCommandGroup class makes it possible to pack multiple undo commands together (it acts as a pa...
Definition: undocommandgroup.h:43
~CmdRemoveBoardItems() noexcept
Definition: cmdremoveboarditems.cpp:68
QSet< BI_NetPoint * > mNetPoints
Definition: cmdremoveboarditems.h:138
void removeDeviceInstances(const QSet< BI_Device *> &set)
Definition: cmdremoveboarditems.h:75
void removePlanes(const QSet< BI_Plane *> &set)
Definition: cmdremoveboarditems.h:95
The CmdRemoveBoardItems class.
Definition: cmdremoveboarditems.h:57
The BI_NetSegment class.
Definition: bi_netsegment.h:57
CmdRemoveBoardItems & operator=(const CmdRemoveBoardItems &other)=delete
QSet< BI_Hole * > mHoles
Definition: cmdremoveboarditems.h:143
QHash< BI_NetSegment *, NetSegmentItems > NetSegmentItemList
Definition: cmdremoveboarditems.h:65
QSet< BI_StrokeText * > mStrokeTexts
Definition: cmdremoveboarditems.h:142
void removeVias(const QSet< BI_Via *> &set)
Definition: cmdremoveboarditems.h:83
void splitUpNetSegment(BI_NetSegment &netsegment, const NetSegmentItems &itemsToRemove)
Definition: cmdremoveboarditems.cpp:183
QSet< BI_Plane * > mPlanes
Definition: cmdremoveboarditems.h:140
void removeHoles(const QSet< BI_Hole *> &set)
Definition: cmdremoveboarditems.h:107
void removeNetPoints(const QSet< BI_NetPoint *> &set)
Definition: cmdremoveboarditems.h:87
The BI_Device class.
Definition: bi_device.h:62
Definition: bi_netline.h:51
QSet< BI_Via * > vias
Definition: cmdremoveboarditems.h:61
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:83
void findAllConnectedNetPointsAndNetLines(BI_NetLineAnchor &anchor, QSet< BI_NetLineAnchor *> &processedAnchors, QSet< BI_Via *> &vias, QSet< BI_NetPoint *> &netpoints, QSet< BI_NetLine *> &netlines, QSet< BI_Via *> &availableVias, QSet< BI_NetLine *> &availableNetLines) const noexcept
Definition: cmdremoveboarditems.cpp:274
QSet< BI_Via * > mVias
Definition: cmdremoveboarditems.h:137
QVector< NetSegmentItems > getNonCohesiveNetSegmentSubSegments(BI_NetSegment &segment, const NetSegmentItems &removedItems) noexcept
Definition: cmdremoveboarditems.cpp:244