1 /*******************************************************************
2 
3 Part of the Fritzing project - http://fritzing.org
4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de
5 
6 Fritzing 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 Fritzing 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 Fritzing.  If not, see <http://www.gnu.org/licenses/>.
18 
19 ********************************************************************
20 
21 $Revision: 6976 $:
22 $Author: irascibl@gmail.com $:
23 $Date: 2013-04-21 09:50:09 +0200 (So, 21. Apr 2013) $
24 
25 ********************************************************************/
26 
27 #ifndef VIEWLAYER_H
28 #define VIEWLAYER_H
29 
30 #include <QString>
31 #include <QAction>
32 #include <QHash>
33 #include <QMultiHash>
34 #include <QDomElement>
35 
36 struct NamePair {
37     QString xmlName;
38     QString displayName;
39 
40     NamePair(QString xml, QString display);
41 };
42 
43 class ViewLayer : public QObject
44 {
45 	Q_OBJECT
46 
47 public:
48 	enum ViewLayerID {
49 		Icon,
50 		BreadboardBreadboard,
51 		Breadboard,
52 		BreadboardWire,
53 		BreadboardLabel,
54 		BreadboardRatsnest,
55 		BreadboardNote,
56 		BreadboardRuler,
57 		SchematicFrame,
58 		Schematic,
59         SchematicText,
60 		SchematicWire,
61 		SchematicTrace,
62 		SchematicLabel,
63 		SchematicNote,
64 		SchematicRuler,
65 		Board,
66 		GroundPlane0,
67 		Silkscreen0,
68 		Silkscreen0Label,
69 		Copper0,
70 		Copper0Trace,
71 		GroundPlane1,
72 		Copper1,
73 		Copper1Trace,
74 		Silkscreen1,
75 		Silkscreen1Label,
76 		PartImage,
77 		PcbRatsnest,
78 		PcbNote,
79 		PcbRuler,
80 		UnknownLayer,
81 		ViewLayerCount
82 	};
83 
84 	enum ViewLayerPlacement {
85         NewTop,
86         NewBottom,
87 		NewTopAndBottom,
88 		UnknownPlacement
89 	};
90 
91    enum ViewID {
92     	IconView,
93     	BreadboardView,
94     	SchematicView,
95     	PCBView,
96     	AllViews,
97 		UnknownView,
98     	ViewCount
99    	};
100 
101 public:
102 	static const QString HolesColor;
103 	static const QString Copper0Color;
104 	static const QString Copper1Color;
105     static const QString Copper0WireColor;
106     static const QString Copper1WireColor;
107     static const QString Silkscreen1Color;
108 	static const QString Silkscreen0Color;
109 	static const QString BoardColor;
110 
111 protected:
112 	static double zIncrement;
113 	static QHash<ViewLayerID, NamePair *> names;
114 	static QMultiHash<ViewLayerID, ViewLayerID> alternatives;
115 	static QMultiHash<ViewLayerID, ViewLayerID> unconnectables;
116 	static QHash<QString, ViewLayerID> xmlHash;
117 
118 public:
119 	ViewLayer(ViewLayerID, bool visible, double initialZ);
120 	~ViewLayer();
121 
122 	void setAction(QAction *);
123 	QAction* action();
124 	QString & displayName();
125 	bool visible();
126 	void setVisible(bool);
127 	double nextZ();
128 	ViewLayerID viewLayerID();
129 	double incrementZ(double);
130 	ViewLayer * parentLayer();
131 	void setParentLayer(ViewLayer *);
132 	const QList<ViewLayer *> & childLayers();
133 	bool alreadyInLayer(double z);
134 	void resetNextZ(double z);
135 	void setActive(bool);
136 	bool isActive();
137 	bool includeChildLayers();
138 	void setIncludeChildLayers(bool);
139     void setFromBelow(bool);
140     bool fromBelow();
141     void setInitialZFromBelow(double);
142     double getZFromBelow(double currentZ, bool fromBelow);
143 
144 public:
145 	static ViewLayerID viewLayerIDFromXmlString(const QString &);
146 	static const QString & viewLayerNameFromID(ViewLayerID);
147 	static const QString & viewLayerXmlNameFromID(ViewLayerID);
148 	static void initNames();
149 	static double getZIncrement();
150 	static void cleanup();
151 	static QList<ViewLayerID> findAlternativeLayers(ViewLayerID);
152 	static bool canConnect(ViewLayerID, ViewLayerID);
153 	static ViewLayer::ViewLayerPlacement specFromID(ViewLayer::ViewLayerID);
154 	static const QList<ViewLayer::ViewLayerID> & copperLayers(ViewLayer::ViewLayerPlacement);
155 	static const QList<ViewLayer::ViewLayerID> & maskLayers(ViewLayer::ViewLayerPlacement);
156 	static const QList<ViewLayer::ViewLayerID> & silkLayers(ViewLayer::ViewLayerPlacement);
157 	static const QList<ViewLayer::ViewLayerID> & outlineLayers();
158 	static const QList<ViewLayer::ViewLayerID> & drillLayers();
159 	static const QList<ViewLayer::ViewLayerID> & topLayers();
160 	static const QList<ViewLayer::ViewLayerID> & bottomLayers();
161 	static const QList<ViewLayer::ViewLayerID> & silkLayers();
162 	static bool isCopperLayer(ViewLayer::ViewLayerID);
163 	static bool isNonCopperLayer(ViewLayer::ViewLayerID viewLayerID);  // for pcb view layers only
164 
165     static QString & viewIDName(ViewLayer::ViewID);
166 	static QString & viewIDXmlName(ViewLayer::ViewID);
167 	static QString & viewIDNaturalName(ViewLayer::ViewID);
168 	static ViewID idFromXmlName(const QString & name);
169 	static const QList<ViewLayer::ViewLayerID> & layersForView(ViewLayer::ViewID);
170 	static const QList<ViewLayer::ViewLayerID> & layersForViewFromBelow(ViewLayer::ViewID);
171 	static bool viewHasLayer(ViewID, ViewLayer::ViewLayerID);
172 
173     static bool getConnectorSvgIDs(QDomElement & connector, ViewLayer::ViewID, QString & id, QString & terminalID);
174     static QDomElement getConnectorPElement(const QDomElement & connector, ViewLayer::ViewID);
175 
176 protected:
177 	bool m_visible;
178 	ViewLayerID m_viewLayerID;
179 	QAction* m_action;
180 	double m_nextZ;
181 	double m_initialZ;
182 	double m_initialZFromBelow;
183 	QList<ViewLayer *> m_childLayers;
184 	ViewLayer * m_parentLayer;
185 	bool m_active;
186 	bool m_includeChildLayers;
187     bool m_fromBelow;
188 
189     static QHash <ViewID, class NameTriple * > ViewIDNames;
190 
191 };
192 
193 typedef QHash<ViewLayer::ViewLayerID, ViewLayer *> LayerHash;
194 typedef QList<ViewLayer::ViewLayerID> LayerList;
195 
196 Q_DECLARE_METATYPE( ViewLayer* );
197 
198 #endif
199