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