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  bool isVisible() const noexcept { return mIsVisible; }
91 
92  // Setters
93  void setOutline(const Path& outline) noexcept;
94  void setLayerName(const GraphicsLayerName& layerName) noexcept;
95  void setNetSignal(NetSignal& netsignal);
96  void setMinWidth(const UnsignedLength& minWidth) noexcept;
97  void setMinClearance(const UnsignedLength& minClearance) noexcept;
98  void setConnectStyle(ConnectStyle style) noexcept;
99  void setPriority(int priority) noexcept;
100  void setKeepOrphans(bool keepOrphans) noexcept;
101  void setVisible(bool visible) noexcept;
102 
103  // General Methods
104  void addToBoard() override;
105  void removeFromBoard() override;
106  void clear() noexcept;
107  void rebuild() noexcept;
108 
110  void serialize(SExpression& root) const override;
111 
112  // Inherited from BI_Base
113  Type_t getType() const noexcept override { return BI_Base::Type_t::Plane; }
114  const Point& getPosition() const noexcept override {
115  static Point p(0, 0);
116  return p;
117  }
118  bool getIsMirrored() const noexcept override { return false; }
119  QPainterPath getGrabAreaScenePx() const noexcept override;
120  void setSelected(bool selected) noexcept override;
121 
122  // Operator Overloadings
123  BI_Plane& operator=(const BI_Plane& rhs) = delete;
124  bool operator<(const BI_Plane& rhs) const noexcept;
125 
126 private slots:
127 
128  void boardAttributesChanged();
129 
130 private: // Methods
131  void init();
132 
133 private: // Data
143  // Length mThermalGapWidth;
144  // Length mThermalSpokeWidth;
145  // style [round square miter] ?
146  QScopedPointer<BGI_Plane> mGraphicsItem;
147  bool mIsVisible; // volatile, not saved to file
148 
149  QVector<Path> mFragments;
150 };
151 
152 /*******************************************************************************
153  * Non-Member Functions
154  ******************************************************************************/
155 
156 } // namespace project
157 
158 template <>
160  const project::BI_Plane::ConnectStyle& obj) {
161  switch (obj) {
163  return SExpression::createToken("none");
164  // case project::BI_Plane::ConnectStyle::Thermal: return
165  // SExpression::createToken("thermal");
167  return SExpression::createToken("solid");
168  default:
169  throw LogicError(__FILE__, __LINE__);
170  }
171 }
172 
173 template <>
175  const SExpression& sexpr, bool throwIfEmpty) {
176  QString str = sexpr.getStringOrToken(throwIfEmpty);
177  if (str == "none") return project::BI_Plane::ConnectStyle::None;
178  // else if (str == "thermal") return
179  // project::BI_Plane::ConnectStyle::Thermal;
180  else if (str == "solid")
182  else
183  throw RuntimeError(
184  __FILE__, __LINE__,
185  QString(project::BI_Plane::tr("Unknown plane connect style: \"%1\""))
186  .arg(str));
187 }
188 
189 /*******************************************************************************
190  * End of File
191  ******************************************************************************/
192 
193 } // namespace librepcb
194 
195 #endif // LIBREPCB_PROJECT_BI_PLANE_H
The LogicError class.
Definition: exceptions.h:182
int mPriority
Definition: bi_plane.h:141
do not connect pads/vias to plane
UnsignedLength mMinWidth
Definition: bi_plane.h:138
bool getIsMirrored() const noexceptoverride
Definition: bi_plane.h:118
~BI_Plane() noexcept
Definition: bi_plane.cpp:121
The BGI_Plane class.
Definition: bgi_plane.h:51
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_plane.cpp:248
Type_t getType() const noexceptoverride
Definition: bi_plane.h:113
bool isVisible() const noexcept
Definition: bi_plane.h:90
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
const Point & getPosition() const noexceptoverride
Definition: bi_plane.h:114
QVector< Path > mFragments
Definition: bi_plane.h:149
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:164
bool isSelectable() const noexceptoverride
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:142
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: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:147
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:137
void setVisible(bool visible) noexcept
Definition: bi_plane.cpp:188
The RuntimeError class.
Definition: exceptions.h:219
void setMinWidth(const UnsignedLength &minWidth) noexcept
Definition: bi_plane.cpp:158
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:136
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:135
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:146
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
void setSelected(bool selected) noexceptoverride
Definition: bi_plane.cpp:256
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:134
void setLayerName(const GraphicsLayerName &layerName) noexcept
Definition: bi_plane.cpp:136
UnsignedLength mMinClearance
Definition: bi_plane.h:139
bool mKeepOrphans
Definition: bi_plane.h:140
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