LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
graphicslayer.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_GRAPHICSLAYER_H
21 #define LIBREPCB_GRAPHICSLAYER_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "graphicslayername.h"
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 #include <memory>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 class IF_GraphicsLayerObserver;
39 
40 /*******************************************************************************
41  * Class GraphicsLayer
42  ******************************************************************************/
43 
54 class GraphicsLayer : public QObject {
55  Q_OBJECT
56 
57 public:
58  // clang-format off
59 
60  // schematic layers
61  //static constexpr const char* sSchematicBackground = "sch_background"; ///< Primary: background | Secondary: grid
62  //static constexpr const char* sSchematicSelection = "sch_selection"; ///< Primary: outline | Secondary: area
63  static constexpr const char* sSchematicReferences = "sch_references";
64  static constexpr const char* sSchematicSheetFrames = "sch_scheet_frames";
65  static constexpr const char* sSchematicNetLines = "sch_net_lines";
66  static constexpr const char* sSchematicNetLabels = "sch_net_labels";
67  static constexpr const char* sSchematicNetLabelAnchors= "sch_net_label_anchors";
68  static constexpr const char* sSchematicDocumentation = "sch_documentation";
69  static constexpr const char* sSchematicComments = "sch_comments";
70  static constexpr const char* sSchematicGuide = "sch_guide";
71 
72  // symbol layers
73  static constexpr const char* sSymbolOutlines = "sym_outlines";
74  static constexpr const char* sSymbolGrabAreas = "sym_grab_areas";
75  static constexpr const char* sSymbolHiddenGrabAreas = "sym_hidden_grab_areas";
76  static constexpr const char* sSymbolNames = "sym_names";
77  static constexpr const char* sSymbolValues = "sym_values";
78  static constexpr const char* sSymbolPinCirclesOpt = "sym_pin_circles_opt";
79  static constexpr const char* sSymbolPinCirclesReq = "sym_pin_circles_req";
80  static constexpr const char* sSymbolPinNames = "sym_pin_names";
81  static constexpr const char* sSymbolPinNumbers = "sym_pin_numbers";
82 
83  // asymmetric board layers
84  //static constexpr const char* sBoardBackground = "brd_background"; ///< Primary: background | Secondary: grid
85  //static constexpr const char* sBoardSelection = "brd_selection"; ///< Primary: outline | Secondary: area
86  //static constexpr const char* sBoardReferences = "brd_references"; ///< origin crosses of footprints, holes, ...
87  static constexpr const char* sBoardSheetFrames = "brd_sheet_frames";
88  static constexpr const char* sBoardOutlines = "brd_outlines";
89  static constexpr const char* sBoardMillingPth = "brd_milling_pth";
90  static constexpr const char* sBoardDrillsNpth = "brd_drills_npth";
91  static constexpr const char* sBoardPadsTht = "brd_pads_tht";
92  static constexpr const char* sBoardViasTht = "brd_vias_tht";
93  static constexpr const char* sBoardAirWires = "brd_airwires";
94  static constexpr const char* sBoardMeasures = "brd_measures";
95  static constexpr const char* sBoardAlignment = "brd_alignment";
96  static constexpr const char* sBoardDocumentation = "brd_documentation";
97  static constexpr const char* sBoardComments = "brd_comments";
98  static constexpr const char* sBoardGuide = "brd_guide";
99 
100  // symmetric board layers
101  static constexpr const char* sTopPlacement = "top_placement";
102  static constexpr const char* sBotPlacement = "bot_placement";
103  static constexpr const char* sTopDocumentation = "top_documentation";
104  static constexpr const char* sBotDocumentation = "bot_documentation";
105  static constexpr const char* sTopGrabAreas = "top_grab_areas";
106  static constexpr const char* sBotGrabAreas = "bot_grab_areas";
107  static constexpr const char* sTopHiddenGrabAreas = "top_hidden_grab_areas";
108  static constexpr const char* sBotHiddenGrabAreas = "bot_hidden_grab_areas";
109  static constexpr const char* sTopReferences = "top_references";
110  static constexpr const char* sBotReferences = "bot_references";
111  static constexpr const char* sTopNames = "top_names";
112  static constexpr const char* sBotNames = "bot_names";
113  static constexpr const char* sTopValues = "top_values";
114  static constexpr const char* sBotValues = "bot_values";
115  static constexpr const char* sTopCourtyard = "top_courtyard";
116  static constexpr const char* sBotCourtyard = "bot_courtyard";
117  static constexpr const char* sTopStopMask = "top_stop_mask";
118  static constexpr const char* sBotStopMask = "bot_stop_mask";
119  static constexpr const char* sTopSolderPaste = "top_solder_paste";
120  static constexpr const char* sBotSolderPaste = "bot_solder_paste";
121  static constexpr const char* sTopFinish = "top_finish";
122  static constexpr const char* sBotFinish = "bot_finish";
123  static constexpr const char* sTopGlue = "top_glue";
124  static constexpr const char* sBotGlue = "bot_glue";
125 
126  // copper layers
127  static constexpr const char* sTopCopper = "top_cu";
128  //static constexpr const char* sInnerCopper# = "in#_cu";
129  static constexpr const char* sBotCopper = "bot_cu";
130 
131 #ifdef QT_DEBUG
132  // debug layers
133  static constexpr const char* sDebugGraphicsItemsBoundingRects = "dbg_GraphicsItemsBoundingRects";
134  static constexpr const char* sDebugGraphicsItemsTextsBoundingRects = "dbg_GraphicsItemsTextsBoundingRects";
135  static constexpr const char* sDebugSymbolPinNetSignalNames = "dbg_SymbolPinNetSignalNames";
136  static constexpr const char* sDebugNetLinesNetSignalNames = "dbg_NetLinesNetSignalNames";
137  static constexpr const char* sDebugInvisibleNetPoints = "dbg_InvisibleNetPoints";
138  static constexpr const char* sDebugComponentSymbolsCounts = "dbg_ComponentSymbolsCounts";
139 #endif
140 
141  // clang-format on
142 
143  // Constructors / Destructor
144  GraphicsLayer() = delete;
145  GraphicsLayer(const GraphicsLayer& other) noexcept;
146  explicit GraphicsLayer(const QString& name) noexcept;
147  virtual ~GraphicsLayer() noexcept;
148 
149  // Getters
150  const QString& getName() const noexcept { return mName; }
151  const QString& getNameTr() const noexcept { return mNameTr; }
152  const QColor& getColor(bool highlighted = false) const noexcept {
153  return highlighted ? mColorHighlighted : mColor;
154  }
155  bool getVisible() const noexcept { return mIsVisible; }
156  bool isEnabled() const noexcept { return mIsEnabled; }
157  bool isVisible() const noexcept { return mIsEnabled && mIsVisible; }
158  bool isTopLayer() const noexcept { return isTopLayer(mName); }
159  bool isBottomLayer() const noexcept { return isBottomLayer(mName); }
160  bool isInnerLayer() const noexcept { return isInnerLayer(mName); }
161  bool isCopperLayer() const noexcept { return isCopperLayer(mName); }
162  int getInnerLayerNumber() const noexcept {
163  return getInnerLayerNumber(mName);
164  }
165  QString getMirroredLayerName() const noexcept {
166  return getMirroredLayerName(mName);
167  }
168  QString getGrabAreaLayerName() const noexcept {
169  return getGrabAreaLayerName(mName);
170  }
171 
172  // Setters
173  void setColor(const QColor& color) noexcept;
174  void setColorHighlighted(const QColor& color) noexcept;
175  void setVisible(bool visible) noexcept;
176  void setEnabled(bool enable) noexcept;
177 
178  // General Methods
179  void registerObserver(IF_GraphicsLayerObserver& object) const noexcept;
180  void unregisterObserver(IF_GraphicsLayerObserver& object) const noexcept;
181 
182  // Operator Overloadings
183  GraphicsLayer& operator=(const GraphicsLayer& rhs) = delete;
184 
185  // Static Methods
186  static int getInnerLayerCount() noexcept {
187  return 62;
188  } // some random number... ;)
189  static bool isTopLayer(const QString& name) noexcept;
190  static bool isBottomLayer(const QString& name) noexcept;
191  static bool isInnerLayer(const QString& name) noexcept;
192  static bool isCopperLayer(const QString& name) noexcept;
193  static QString getInnerLayerName(int number) noexcept;
194  static int getInnerLayerNumber(const QString& name) noexcept;
195  static QString getMirroredLayerName(const QString& name) noexcept;
196  static QString getGrabAreaLayerName(const QString& outlineLayerName) noexcept;
197  static const QStringList& getSchematicGeometryElementLayerNames() noexcept;
198  static const QStringList& getBoardGeometryElementLayerNames() noexcept;
199  static void getDefaultValues(const QString& name, QString& nameTr,
200  QColor& color, QColor& colorHl,
201  bool& visible) noexcept;
202 
203 signals:
204  void attributesChanged();
205 
206 protected: // Data
207  QString mName;
208  QString mNameTr;
209  QColor mColor;
211  bool mIsVisible;
213  bool mIsEnabled;
214  mutable QSet<IF_GraphicsLayerObserver*>
216 };
217 
218 /*******************************************************************************
219  * Interface IF_GraphicsLayerObserver
220  ******************************************************************************/
221 
228 public:
230 
231  virtual void layerColorChanged(const GraphicsLayer& layer,
232  const QColor& newColor) noexcept = 0;
233  virtual void layerHighlightColorChanged(const GraphicsLayer& layer,
234  const QColor& newColor) noexcept = 0;
235  virtual void layerVisibleChanged(const GraphicsLayer& layer,
236  bool newVisible) noexcept = 0;
237  virtual void layerEnabledChanged(const GraphicsLayer& layer,
238  bool newEnabled) noexcept = 0;
239  virtual void layerDestroyed(const GraphicsLayer& layer) noexcept = 0;
240 };
241 
242 /*******************************************************************************
243  * Interface IF_GraphicsLayerProvider
244  ******************************************************************************/
245 
251 public:
253 
254  virtual GraphicsLayer* getLayer(const QString& name) const noexcept = 0;
255  virtual QList<GraphicsLayer*> getAllLayers() const noexcept = 0;
256 
257  GraphicsLayer* getGrabAreaLayer(const QString outlineLayerName) const
258  noexcept {
259  return getLayer(GraphicsLayer::getGrabAreaLayerName(outlineLayerName));
260  }
261 
262  QList<GraphicsLayer*> getSchematicGeometryElementLayers() const noexcept {
264  }
265 
266  QList<GraphicsLayer*> getBoardGeometryElementLayers() const noexcept {
268  }
269 
270  QList<GraphicsLayer*> getLayers(const QStringList& layerNames) const
271  noexcept {
272  QList<GraphicsLayer*> layers;
273  foreach (const QString& name, layerNames) {
274  GraphicsLayer* layer = getLayer(name);
275  if (layer) layers.append(layer);
276  }
277  return layers;
278  }
279 };
280 
281 /*******************************************************************************
282  * End of File
283  ******************************************************************************/
284 
285 } // namespace librepcb
286 
287 #endif // LIBREPCB_GRAPHICSLAYER_H
static constexpr const char * sTopDocumentation
like placement layers, but not for silk screen
Definition: graphicslayer.h:103
static constexpr const char * sSymbolPinCirclesReq
red circle of unconnected pins
Definition: graphicslayer.h:79
int getInnerLayerNumber() const noexcept
Definition: graphicslayer.h:162
static constexpr const char * sBotFinish
areas of special surface treatments
Definition: graphicslayer.h:122
static constexpr const char * sTopNames
text, may be used for silk screen
Definition: graphicslayer.h:111
virtual ~GraphicsLayer() noexcept
Definition: graphicslayer.cpp:52
QString getGrabAreaLayerName() const noexcept
Definition: graphicslayer.h:168
static constexpr const char * sTopCourtyard
area required to mount devices
Definition: graphicslayer.h:115
QList< GraphicsLayer * > getSchematicGeometryElementLayers() const noexcept
Definition: graphicslayer.h:262
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
bool isVisible() const noexcept
Definition: graphicslayer.h:157
static constexpr const char * sBoardComments
for personal comments, e.g. text
Definition: graphicslayer.h:97
static constexpr const char * sBotValues
text, may be used for silk screen
Definition: graphicslayer.h:114
const QString & getNameTr() const noexcept
Definition: graphicslayer.h:151
static constexpr const char * sSymbolValues
text {{VALUE}}
Definition: graphicslayer.h:77
QString mName
Unique name which is used for serialization.
Definition: graphicslayer.h:207
bool isInnerLayer() const noexcept
Definition: graphicslayer.h:160
void setVisible(bool visible) noexcept
Definition: graphicslayer.cpp:83
static constexpr const char * sBotPlacement
placement information (e.g. outline) of devices
Definition: graphicslayer.h:102
static constexpr const char * sBotReferences
origin crosses of devices
Definition: graphicslayer.h:110
The IF_GraphicsLayerOblayerHighlightColorChangedserver class defines an interface for classes which c...
Definition: graphicslayer.h:227
static constexpr const char * sSchematicNetLines
librepcb::project::SI_NetLine
Definition: graphicslayer.h:65
static constexpr const char * sBoardViasTht
plated through hole vias
Definition: graphicslayer.h:92
GraphicsLayer & operator=(const GraphicsLayer &rhs)=delete
static constexpr const char * sSymbolPinCirclesOpt
green circle of unconnected pins
Definition: graphicslayer.h:78
static constexpr const char * sBotDocumentation
like placement layers, but not for silk screen
Definition: graphicslayer.h:104
void unregisterObserver(IF_GraphicsLayerObserver &object) const noexcept
Definition: graphicslayer.cpp:112
static constexpr const char * sBoardMillingPth
plated through hole milling
Definition: graphicslayer.h:89
bool isBottomLayer() const noexcept
Definition: graphicslayer.h:159
bool getVisible() const noexcept
Definition: graphicslayer.h:155
static constexpr const char * sBotSolderPaste
areas over smt pads
Definition: graphicslayer.h:120
static constexpr const char * sTopStopMask
areas over smt pads
Definition: graphicslayer.h:117
void registerObserver(IF_GraphicsLayerObserver &object) const noexcept
Definition: graphicslayer.cpp:107
static constexpr const char * sBoardAirWires
air wires (unconnected)
Definition: graphicslayer.h:93
const QColor & getColor(bool highlighted=false) const noexcept
Definition: graphicslayer.h:152
static constexpr const char * sSchematicGuide
e.g. for boxes around circuits
Definition: graphicslayer.h:70
bool mIsEnabled
Visibility/availability of the layer itself.
Definition: graphicslayer.h:213
static constexpr const char * sTopGrabAreas
area where devices can be dragged
Definition: graphicslayer.h:105
bool isEnabled() const noexcept
Definition: graphicslayer.h:156
QList< GraphicsLayer * > getLayers(const QStringList &layerNames) const noexcept
Definition: graphicslayer.h:270
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
QColor mColor
Color of graphics items on that layer.
Definition: graphicslayer.h:209
QList< GraphicsLayer * > getBoardGeometryElementLayers() const noexcept
Definition: graphicslayer.h:266
static constexpr const char * sBoardAlignment
alignment helpers in devices
Definition: graphicslayer.h:95
static constexpr const char * sSchematicComments
for personal comments, e.g. text
Definition: graphicslayer.h:69
static constexpr const char * sTopSolderPaste
areas over smt pads
Definition: graphicslayer.h:119
static constexpr const char * sBotGlue
adhesive for fixing devices
Definition: graphicslayer.h:124
QString mNameTr
Layer name (translated into the user's language)
Definition: graphicslayer.h:208
static constexpr const char * sBoardMeasures
measurements documentation
Definition: graphicslayer.h:94
static constexpr const char * sSchematicNetLabels
librepcb::project::SI_NetLabel
Definition: graphicslayer.h:66
static constexpr const char * sTopFinish
areas of special surface treatments
Definition: graphicslayer.h:121
static constexpr const char * sTopReferences
origin crosses of devices
Definition: graphicslayer.h:109
bool isCopperLayer() const noexcept
Definition: graphicslayer.h:161
void setColorHighlighted(const QColor &color) noexcept
Definition: graphicslayer.cpp:73
static constexpr const char * sSymbolOutlines
dark red lines of symbols
Definition: graphicslayer.h:73
static const QStringList & getSchematicGeometryElementLayerNames() noexcept
Definition: graphicslayer.cpp:174
static constexpr const char * sSymbolPinNames
name of the connected component signal
Definition: graphicslayer.h:80
static constexpr const char * sBotGrabAreas
area where devices can be dragged
Definition: graphicslayer.h:106
static constexpr const char * sTopPlacement
placement information (e.g. outline) of devices
Definition: graphicslayer.h:101
void setEnabled(bool enable) noexcept
Definition: graphicslayer.cpp:93
QSet< IF_GraphicsLayerObserver * > mObservers
A list of all observer objects.
Definition: graphicslayer.h:215
static constexpr const char * sSymbolHiddenGrabAreas
hidden grab areas of symbols
Definition: graphicslayer.h:75
static constexpr const char * sBoardGuide
e.g. for boxes around circuits
Definition: graphicslayer.h:98
static constexpr const char * sTopGlue
adhesive for fixing devices
Definition: graphicslayer.h:123
static int getInnerLayerCount() noexcept
Definition: graphicslayer.h:186
bool mIsVisible
Visibility of graphics items on that layer.
Definition: graphicslayer.h:212
QColor mColorHighlighted
Definition: graphicslayer.h:210
static void getDefaultValues(const QString &name, QString &nameTr, QColor &color, QColor &colorHl, bool &visible) noexcept
Definition: graphicslayer.cpp:203
static constexpr const char * sBoardOutlines
incl. non-plated through hole milling
Definition: graphicslayer.h:88
void setColor(const QColor &color) noexcept
Definition: graphicslayer.cpp:63
const QString & getName() const noexcept
Definition: graphicslayer.h:150
static constexpr const char * sBotHiddenGrabAreas
hidden area where devices can be dragged
Definition: graphicslayer.h:108
static constexpr const char * sSchematicNetLabelAnchors
anchor line of librepcb::project::SI_NetLabel
Definition: graphicslayer.h:67
static constexpr const char * sSchematicSheetFrames
e.g. A4 sheet frame + text boxes
Definition: graphicslayer.h:64
static constexpr const char * sSchematicDocumentation
for documentation purposes, e.g. text
Definition: graphicslayer.h:68
static constexpr const char * sSymbolNames
text {{NAME}}
Definition: graphicslayer.h:76
static constexpr const char * sBoardDocumentation
for documentation purposes, e.g. text
Definition: graphicslayer.h:96
static QString getInnerLayerName(int number) noexcept
Definition: graphicslayer.cpp:137
bool isTopLayer() const noexcept
Definition: graphicslayer.h:158
static constexpr const char * sBotNames
text, may be used for silk screen
Definition: graphicslayer.h:112
static constexpr const char * sBotCopper
Definition: graphicslayer.h:129
static constexpr const char * sSymbolPinNumbers
number of the connected footprint pad
Definition: graphicslayer.h:81
virtual ~IF_GraphicsLayerObserver()
Definition: graphicslayer.h:229
virtual ~IF_GraphicsLayerProvider()
Definition: graphicslayer.h:252
static constexpr const char * sBoardPadsTht
plated through hole pads
Definition: graphicslayer.h:91
static const QStringList & getBoardGeometryElementLayerNames() noexcept
Definition: graphicslayer.cpp:183
static constexpr const char * sTopHiddenGrabAreas
hidden area where devices can be dragged
Definition: graphicslayer.h:107
static constexpr const char * sSchematicReferences
origin crosses of symbols, texts, ...
Definition: graphicslayer.h:63
static constexpr const char * sTopCopper
Definition: graphicslayer.h:127
static constexpr const char * sTopValues
text, may be used for silk screen
Definition: graphicslayer.h:113
static constexpr const char * sSymbolGrabAreas
optional yellow area of symbols
Definition: graphicslayer.h:74
static constexpr const char * sBotStopMask
areas over smt pads
Definition: graphicslayer.h:118
QString getMirroredLayerName() const noexcept
Definition: graphicslayer.h:165
static constexpr const char * sBoardSheetFrames
e.g. A4 sheet frame + text boxes
Definition: graphicslayer.h:87
static constexpr const char * sBotCourtyard
area required to mount devices
Definition: graphicslayer.h:116
static constexpr const char * sBoardDrillsNpth
non-plated through hole drills
Definition: graphicslayer.h:90