LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gridproperties.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_GRIDPROPERTIES_H
21 #define LIBREPCB_GRIDPROPERTIES_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 #include "units/all_length_units.h"
28 
29 #include <QtCore>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 /*******************************************************************************
37  * Class GridProperties
38  ******************************************************************************/
39 
43 class GridProperties final : public SerializableObject {
44  Q_DECLARE_TR_FUNCTIONS(GridProperties)
45 
46 public:
47  // Types
48  enum class Type_t { Off, Lines, Dots };
49 
50  // Constructors / Destructor
51  GridProperties() noexcept;
52  explicit GridProperties(const SExpression& node);
53  GridProperties(Type_t type, const PositiveLength& interval,
54  const LengthUnit& unit) noexcept;
55  GridProperties(const GridProperties& other) noexcept;
56  ~GridProperties() noexcept;
57 
58  // Getters
59  Type_t getType() const noexcept { return mType; }
60  const PositiveLength& getInterval() const noexcept { return mInterval; }
61  const LengthUnit& getUnit() const noexcept { return mUnit; }
62 
63  // Setters
64  void setType(Type_t type) noexcept { mType = type; }
65  void setInterval(const PositiveLength& interval) noexcept {
66  mInterval = interval;
67  }
68  void setUnit(const LengthUnit& unit) noexcept { mUnit = unit; }
69 
70  // General Methods
71 
73  void serialize(SExpression& root) const override;
74 
75  // Operators
76  GridProperties& operator=(const GridProperties& rhs) noexcept;
77 
78 private: // Data
82 };
83 
84 /*******************************************************************************
85  * Non-Member Functions
86  ******************************************************************************/
87 
88 template <>
90  switch (obj) {
92  return SExpression::createToken("off");
94  return SExpression::createToken("lines");
96  return SExpression::createToken("dots");
97  default:
98  throw LogicError(__FILE__, __LINE__);
99  }
100 }
101 
102 template <>
104  const SExpression& sexpr, bool throwIfEmpty) {
105  QString str = sexpr.getStringOrToken(throwIfEmpty);
106  if (str == "off")
108  else if (str == "lines")
110  else if (str == "dots")
112  else
113  throw RuntimeError(
114  __FILE__, __LINE__,
115  QString(GridProperties::tr("Unknown grid type: \"%1\"")).arg(str));
116 }
117 
118 /*******************************************************************************
119  * End of File
120  ******************************************************************************/
121 
122 } // namespace librepcb
123 
124 #endif // LIBREPCB_GRIDPROPERTIES_H
The LogicError class.
Definition: exceptions.h:182
Type_t
Definition: gridproperties.h:48
PositiveLength mInterval
Definition: gridproperties.h:80
void setInterval(const PositiveLength &interval) noexcept
Definition: gridproperties.h:65
LengthUnit mUnit
Definition: gridproperties.h:81
The GridProperties class.
Definition: gridproperties.h:43
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:79
Type_t mType
Definition: gridproperties.h:79
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:93
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:280
void setUnit(const LengthUnit &unit) noexcept
Definition: gridproperties.h:68
const LengthUnit & getUnit() const noexcept
Definition: gridproperties.h:61
void setType(Type_t type) noexcept
Definition: gridproperties.h:64
The RuntimeError class.
Definition: exceptions.h:219
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: gridproperties.cpp:62
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
Type_t getType() const noexcept
Definition: gridproperties.h:59
GridProperties() noexcept
Definition: gridproperties.cpp:36
GridProperties & operator=(const GridProperties &rhs) noexcept
Definition: gridproperties.cpp:72
const PositiveLength & getInterval() const noexcept
Definition: gridproperties.h:60
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:64
The SExpression class.
Definition: sexpression.h:60