LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  bool isSelectable() const noexcept override;
90 
91  // Setters
92  void setOutline(const Path& outline) noexcept;
93  void setLayerName(const GraphicsLayerName& layerName) noexcept;
94  void setNetSignal(NetSignal& netsignal);
95  void setMinWidth(const UnsignedLength& minWidth) noexcept;
96  void setMinClearance(const UnsignedLength& minClearance) noexcept;
97  void setConnectStyle(ConnectStyle style) noexcept;
98  void setPriority(int priority) noexcept;
99  void setKeepOrphans(bool keepOrphans) noexcept;
100 
101  // General Methods
102  void addToBoard() override;
103  void removeFromBoard() override;
104  void clear() noexcept;
105  void rebuild() noexcept;
106 
108  void serialize(SExpression& root) const override;
109 
110  // Inherited from BI_Base
111  Type_t getType() const noexcept override { return BI_Base::Type_t::Plane; }
112  const Point& getPosition() const noexcept override {
113  static Point p(0, 0);
114  return p;
115  }
116  bool getIsMirrored() const noexcept override { return false; }
117  QPainterPath getGrabAreaScenePx() const noexcept override;
118  void setSelected(bool selected) noexcept override;
119 
120  // Operator Overloadings
121  BI_Plane& operator=(const BI_Plane& rhs) = delete;
122  bool operator<(const BI_Plane& rhs) const noexcept;
123 
124 private slots:
125 
126  void boardAttributesChanged();
127 
128 private: // Methods
129  void init();
130 
131 private: // Data
141  // Length mThermalGapWidth;
142  // Length mThermalSpokeWidth;
143  // style [round square miter] ?
144  QScopedPointer<BGI_Plane> mGraphicsItem;
145 
146  QVector<Path> mFragments;
147 };
148 
149 /*******************************************************************************
150  * Non-Member Functions
151  ******************************************************************************/
152 
153 } // namespace project
154 
155 template <>
157  const project::BI_Plane::ConnectStyle& obj) {
158  switch (obj) {
160  return SExpression::createToken("none");
161  // case project::BI_Plane::ConnectStyle::Thermal: return
162  // SExpression::createToken("thermal");
164  return SExpression::createToken("solid");
165  default:
166  throw LogicError(__FILE__, __LINE__);
167  }
168 }
169 
170 template <>
172  const SExpression& sexpr, bool throwIfEmpty) {
173  QString str = sexpr.getStringOrToken(throwIfEmpty);
174  if (str == "none") return project::BI_Plane::ConnectStyle::None;
175  // else if (str == "thermal") return
176  // project::BI_Plane::ConnectStyle::Thermal;
177  else if (str == "solid")
179  else
180  throw RuntimeError(
181  __FILE__, __LINE__,
182  QString(project::BI_Plane::tr("Unknown plane connect style: \"%1\""))
183  .arg(str));
184 }
185 
186 /*******************************************************************************
187  * End of File
188  ******************************************************************************/
189 
190 } // namespace librepcb
191 
192 #endif // LIBREPCB_PROJECT_BI_PLANE_H
The LogicError class.
Definition: exceptions.h:182
int mPriority
Definition: bi_plane.h:139
do not connect pads/vias to plane
UnsignedLength mMinWidth
Definition: bi_plane.h:136
bool getIsMirrored() const noexceptoverride
Definition: bi_plane.h:116
~BI_Plane() noexcept
Definition: bi_plane.cpp:118
The BGI_Plane class.
Definition: bgi_plane.h:51
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_plane.cpp:238
Type_t getType() const noexceptoverride
Definition: bi_plane.h:111
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
const Point & getPosition() const noexceptoverride
Definition: bi_plane.h:112
QVector< Path > mFragments
Definition: bi_plane.h:146
Type_t
Definition: bi_base.h:57
const QVector< Path > & getFragments() const noexcept
Definition: bi_plane.h:88
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:76
void setMinClearance(const UnsignedLength &minClearance) noexcept
Definition: bi_plane.cpp:161
bool isSelectable() const noexceptoverride
Definition: bi_plane.cpp:242
void setNetSignal(NetSignal &netsignal)
Definition: bi_plane.cpp:140
void setPriority(int priority) noexcept
Definition: bi_plane.cpp:173
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:140
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:280
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_plane.cpp:220
The BI_Plane class.
Definition: bi_plane.h:53
void boardAttributesChanged()
Definition: bi_plane.cpp:271
void init()
Definition: bi_plane.cpp:108
const UnsignedLength & getMinClearance() const noexcept
Definition: bi_plane.h:78
void setConnectStyle(ConnectStyle style) noexcept
Definition: bi_plane.cpp:167
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void setOutline(const Path &outline) noexcept
Definition: bi_plane.cpp:126
void clear() noexcept
Definition: bi_plane.cpp:208
NetSignal & getNetSignal() const noexcept
Definition: bi_plane.h:76
void rebuild() noexcept
Definition: bi_plane.cpp:213
void addToBoard() override
Definition: bi_plane.cpp:189
Path mOutline
Definition: bi_plane.h:135
The RuntimeError class.
Definition: exceptions.h:219
void setMinWidth(const UnsignedLength &minWidth) noexcept
Definition: bi_plane.cpp:155
int getPriority() const noexcept
Definition: bi_plane.h:82
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
NetSignal * mNetSignal
Definition: bi_plane.h:134
ConnectStyle getConnectStyle() const noexcept
Definition: bi_plane.h:83
void removeFromBoard() override
Definition: bi_plane.cpp:199
const GraphicsLayerName & getLayerName() const noexcept
Definition: bi_plane.h:75
GraphicsLayerName mLayerName
Definition: bi_plane.h:133
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
const Path & getOutline() const noexcept
Definition: bi_plane.h:87
QScopedPointer< BGI_Plane > mGraphicsItem
Definition: bi_plane.h:144
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:179
void setSelected(bool selected) noexceptoverride
Definition: bi_plane.cpp:246
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:82
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Uuid mUuid
Definition: bi_plane.h:132
void setLayerName(const GraphicsLayerName &layerName) noexcept
Definition: bi_plane.cpp:133
UnsignedLength mMinClearance
Definition: bi_plane.h:137
bool mKeepOrphans
Definition: bi_plane.h:138
The SExpression class.
Definition: sexpression.h:57
ConnectStyle
Definition: bi_plane.h:58
completely connect pads/vias to plane
librepcb::project::BI_Plane
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:659