LibrePCB Developers Documentation
bi_plane.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_BI_PLANE_H
21 #define LIBREPCB_PROJECT_BI_PLANE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "bi_base.h"
27 
31 #include <librepcb/common/uuid.h>
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 namespace project {
40 
41 class Project;
42 class NetSignal;
43 class Board;
44 class BGI_Plane;
45 
46 /*******************************************************************************
47  * Class BI_Plane
48  ******************************************************************************/
49 
53 class BI_Plane final : public BI_Base, public SerializableObject {
54  Q_OBJECT
55 
56 public:
57  // Types
58  enum class ConnectStyle {
59  None,
60  // Thermal, ///< add thermals to connect pads/vias to plane
61  Solid,
62  };
63 
64  // Constructors / Destructor
65  BI_Plane() = delete;
66  BI_Plane(const BI_Plane& other) = delete;
67  BI_Plane(Board& board, const BI_Plane& other);
68  BI_Plane(Board& board, const SExpression& node);
69  BI_Plane(Board& board, const Uuid& uuid, const GraphicsLayerName& layerName,
70  NetSignal& netsignal, const Path& outline);
71  ~BI_Plane() noexcept;
72 
73  // Getters
74  const Uuid& getUuid() const noexcept { return mUuid; }
75  const GraphicsLayerName& getLayerName() const noexcept { return mLayerName; }
76  NetSignal& getNetSignal() const noexcept { return *mNetSignal; }
77  const UnsignedLength& getMinWidth() const noexcept { return mMinWidth; }
78  const UnsignedLength& getMinClearance() const noexcept {
79  return mMinClearance;
80  }
81  bool getKeepOrphans() const noexcept { return mKeepOrphans; }
82  int getPriority() const noexcept { return mPriority; }
83  ConnectStyle getConnectStyle() const noexcept { return mConnectStyle; }
84  // const Length& getThermalGapWidth() const noexcept {return
85  // mThermalGapWidth;} const Length& getThermalSpokeWidth() const noexcept
86  // {return mThermalSpokeWidth;}
87  const Path& getOutline() const noexcept { return mOutline; }
88  const QVector<Path>& getFragments() const noexcept { return mFragments; }
89  BGI_Plane& getGraphicsItem() noexcept { return *mGraphicsItem; }
90  bool isSelectable() const noexcept override;
91  bool isVisible() const noexcept { return mIsVisible; }
92 
93  // Setters
94  void setOutline(const Path& outline) noexcept;
95  void setLayerName(const GraphicsLayerName& layerName) noexcept;
96  void setNetSignal(NetSignal& netsignal);
97  void setMinWidth(const UnsignedLength& minWidth) noexcept;
98  void setMinClearance(const UnsignedLength& minClearance) noexcept;
99  void setConnectStyle(ConnectStyle style) noexcept;
100  void setPriority(int priority) noexcept;
101  void setKeepOrphans(bool keepOrphans) noexcept;
102  void setVisible(bool visible) noexcept;
103 
104  // General Methods
105  void addToBoard() override;
106  void removeFromBoard() override;
107  void clear() noexcept;
108  void rebuild() noexcept;
109 
111  void serialize(SExpression& root) const override;
112 
113  // Inherited from BI_Base
114  Type_t getType() const noexcept override { return BI_Base::Type_t::Plane; }
115  const Point& getPosition() const noexcept override {
116  static Point p(0, 0);
117  return p;
118  }
119  bool getIsMirrored() const noexcept override { return false; }
120  QPainterPath getGrabAreaScenePx() const noexcept override;
121  void setSelected(bool selected) noexcept override;
122 
123  // Operator Overloadings
124  BI_Plane& operator=(const BI_Plane& rhs) = delete;
125  bool operator<(const BI_Plane& rhs) const noexcept;
126 
127 private slots:
128 
129  void boardAttributesChanged();
130 
131 private: // Methods
132  void init();
133 
134 private: // Data
144  // Length mThermalGapWidth;
145  // Length mThermalSpokeWidth;
146  // style [round square miter] ?
147  QScopedPointer<BGI_Plane> mGraphicsItem;
148  bool mIsVisible; // volatile, not saved to file
149 
150  QVector<Path> mFragments;
151 };
152 
153 /*******************************************************************************
154  * Non-Member Functions
155  ******************************************************************************/
156 
157 } // namespace project
158 
159 template <>
161  const project::BI_Plane::ConnectStyle& obj) {
162  switch (obj) {
164  return SExpression::createToken("none");
165  // case project::BI_Plane::ConnectStyle::Thermal: return
166  // SExpression::createToken("thermal");
168  return SExpression::createToken("solid");
169  default:
170  throw LogicError(__FILE__, __LINE__);
171  }
172 }
173 
174 template <>
176  const SExpression& sexpr, bool throwIfEmpty) {
177  QString str = sexpr.getStringOrToken(throwIfEmpty);
178  if (str == "none") return project::BI_Plane::ConnectStyle::None;
179  // else if (str == "thermal") return
180  // project::BI_Plane::ConnectStyle::Thermal;
181  else if (str == "solid")
183  else
184  throw RuntimeError(
185  __FILE__, __LINE__,
186  QString(project::BI_Plane::tr("Unknown plane connect style: \"%1\""))
187  .arg(str));
188 }
189 
190 /*******************************************************************************
191  * End of File
192  ******************************************************************************/
193 
194 } // namespace librepcb
195 
196 #endif // LIBREPCB_PROJECT_BI_PLANE_H
The LogicError class.
Definition: exceptions.h:179
int mPriority
Definition: bi_plane.h:142
do not connect pads/vias to plane
bool operator<(const BI_Plane &rhs) const noexcept
Definition: bi_plane.cpp:265
UnsignedLength mMinWidth
Definition: bi_plane.h:139
~BI_Plane() noexcept
Definition: bi_plane.cpp:121
The BGI_Plane class.
Definition: bgi_plane.h:51
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
Type_t getType() const noexcept override
Definition: bi_plane.h:114
bool isVisible() const noexcept
Definition: bi_plane.h:91
Definition: airwiresbuilder.cpp:32
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
QVector< Path > mFragments
Definition: bi_plane.h:150
void setSelected(bool selected) noexcept override
Definition: bi_plane.cpp:256
Type_t
Definition: bi_base.h:57
const QVector< Path > & getFragments() const noexcept
Definition: bi_plane.h:88
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:76
void setMinClearance(const UnsignedLength &minClearance) noexcept
Definition: bi_plane.cpp:164
bool isSelectable() const noexcept override
Definition: bi_plane.cpp:252
void setNetSignal(NetSignal &netsignal)
Definition: bi_plane.cpp:143
void setPriority(int priority) noexcept
Definition: bi_plane.cpp:176
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
ConnectStyle mConnectStyle
Definition: bi_plane.h:143
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:90
bool getKeepOrphans() const noexcept
Definition: bi_plane.h:81
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:278
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_plane.cpp:230
The BI_Plane class.
Definition: bi_plane.h:53
void boardAttributesChanged()
Definition: bi_plane.cpp:281
void init()
Definition: bi_plane.cpp:111
const UnsignedLength & getMinClearance() const noexcept
Definition: bi_plane.h:78
void setConnectStyle(ConnectStyle style) noexcept
Definition: bi_plane.cpp:170
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
bool mIsVisible
Definition: bi_plane.h:148
void setOutline(const Path &outline) noexcept
Definition: bi_plane.cpp:129
void clear() noexcept
Definition: bi_plane.cpp:218
NetSignal & getNetSignal() const noexcept
Definition: bi_plane.h:76
void rebuild() noexcept
Definition: bi_plane.cpp:223
void addToBoard() override
Definition: bi_plane.cpp:199
Path mOutline
Definition: bi_plane.h:138
void setVisible(bool visible) noexcept
Definition: bi_plane.cpp:188
The RuntimeError class.
Definition: exceptions.h:216
void setMinWidth(const UnsignedLength &minWidth) noexcept
Definition: bi_plane.cpp:158
int getPriority() const noexcept
Definition: bi_plane.h:82
BI_Plane & operator=(const BI_Plane &rhs)=delete
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
QPainterPath getGrabAreaScenePx() const noexcept override
Definition: bi_plane.cpp:248
NetSignal * mNetSignal
Definition: bi_plane.h:137
ConnectStyle getConnectStyle() const noexcept
Definition: bi_plane.h:83
void removeFromBoard() override
Definition: bi_plane.cpp:209
const GraphicsLayerName & getLayerName() const noexcept
Definition: bi_plane.h:75
GraphicsLayerName mLayerName
Definition: bi_plane.h:136
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
const Point & getPosition() const noexcept override
Definition: bi_plane.h:115
const Path & getOutline() const noexcept
Definition: bi_plane.h:87
QScopedPointer< BGI_Plane > mGraphicsItem
Definition: bi_plane.h:147
BGI_Plane & getGraphicsItem() noexcept
Definition: bi_plane.h:89
const Uuid & getUuid() const noexcept
Definition: bi_plane.h:74
const UnsignedLength & getMinWidth() const noexcept
Definition: bi_plane.h:77
The NetSignal class.
Definition: netsignal.h:56
void setKeepOrphans(bool keepOrphans) noexcept
Definition: bi_plane.cpp:182
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:83
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Uuid mUuid
Definition: bi_plane.h:135
void setLayerName(const GraphicsLayerName &layerName) noexcept
Definition: bi_plane.cpp:136
UnsignedLength mMinClearance
Definition: bi_plane.h:140
bool mKeepOrphans
Definition: bi_plane.h:141
The SExpression class.
Definition: sexpression.h:57
ConnectStyle
Definition: bi_plane.h:58
bool getIsMirrored() const noexcept override
Definition: bi_plane.h:119
completely connect pads/vias to plane
librepcb::project::BI_Plane
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:673