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: 6979 $:
22 $Author: irascibl@gmail.com $:
23 $Date: 2013-04-21 23:20:35 +0200 (So, 21. Apr 2013) $
24 
25 ********************************************************************/
26 
27 #ifndef PCBSKETCHWIDGET_H
28 #define PCBSKETCHWIDGET_H
29 
30 #include "sketchwidget.h"
31 #include "../dialogs/quotedialog.h"
32 #include <QVector>
33 #include <QNetworkReply>
34 #include <QDialog>
35 
36 ///////////////////////////////////////////////
37 
38 class PCBSketchWidget : public SketchWidget
39 {
40 	Q_OBJECT
41 
42 public:
43     PCBSketchWidget(ViewLayer::ViewID, QWidget *parent=0);
44 
45 	void addViewLayers();
46 	bool canDeleteItem(QGraphicsItem * item, int count);
47 	bool canCopyItem(QGraphicsItem * item, int count);
48 	void createTrace(Wire *, bool useLastWireColor);
49 	void excludeFromAutoroute(bool exclude);
50 	void selectAllExcludedTraces();
51 	void selectAllIncludedTraces();
52 	bool hasAnyNets();
53 	void forwardRoutingStatus(const RoutingStatus &);
54 	void addDefaultParts();
55 	void showEvent(QShowEvent * event);
56 	void initWire(Wire *, int penWidth);
57 	virtual bool autorouteTypePCB();
58 	virtual double getKeepout();
59     void setKeepout(double mils);
60     void resetKeepout();
61 	virtual const QString & traceColor(ConnectorItem *);
62 	const QString & traceColor(ViewLayer::ViewLayerPlacement);
63 	virtual void ensureTraceLayersVisible();
64 	virtual void ensureTraceLayerVisible();
65 	bool canChainMultiple();
66 	void setNewPartVisible(ItemBase *);
67 	void setClipEnds(class ClipableWire *, bool);
68 	void showGroundTraces(QList<ConnectorItem *> & seeds, bool show);
69     virtual double getLabelFontSizeTiny();
70 	virtual double getLabelFontSizeSmall();
71 	virtual double getLabelFontSizeMedium();
72 	virtual double getLabelFontSizeLarge();
73 	ViewLayer::ViewLayerID getWireViewLayerID(const ViewGeometry & viewGeometry, ViewLayer::ViewLayerPlacement);
74 	QList<ItemBase *> findBoard();
75     ItemBase * findSelectedBoard(int & boardCount);
76     ItemBase * findBoardBeneath(ItemBase *);
77 
78 	void setBoardLayers(int, bool redraw);
79     void swapLayers(ItemBase * itemBase, int newLayers, QUndoCommand * parentCommand);
80 	void loadFromModelParts(QList<ModelPart *> & modelParts, BaseCommand::CrossViewType, QUndoCommand * parentCommand,
81 							bool offsetPaste, const QRectF * boundingRect, bool seekOutsideConnections, QList<long> & newIDs);
82 	virtual bool isInLayers(ConnectorItem *, ViewLayer::ViewLayerPlacement);
83 	bool routeBothSides();
84 	bool sameElectricalLayer2(ViewLayer::ViewLayerID, ViewLayer::ViewLayerID);
85 	void changeTraceLayer(ItemBase *, bool force, QUndoCommand * parentCommand);
86 	void changeLayer(long id, double z, ViewLayer::ViewLayerID viewLayerID);
87 	bool acceptsTrace(const ViewGeometry & viewGeometry);
88 	ItemBase * placePartDroppedInOtherView(ModelPart *, ViewLayer::ViewLayerPlacement, const ViewGeometry & viewGeometry, long id, SketchWidget * dropOrigin);
89 	void autorouterSettings();
90 	void getViaSize(double & ringThickness, double & holeSize);
91     void deleteItem(ItemBase *, bool deleteModelPart, bool doEmit, bool later);
92 	double getTraceWidth();
93 	virtual double getAutorouterTraceWidth();
94 	void getBendpointWidths(class Wire *, double w, double & w1, double & w2, bool & negativeOffsetRect);
95 	double getSmallerTraceWidth(double minDim);
96 	bool groundFill(bool fillGroundTraces, ViewLayer::ViewLayerID, QUndoCommand * parentCommand);
97 	void setGroundFillSeeds();
98 	void clearGroundFillSeeds();
99 	QString generateCopperFillUnit(ItemBase * itemBase, QPointF whereToStart);
100 	double getWireStrokeWidth(Wire *, double wireWidth);
101 	ItemBase * addCopperLogoItem(ViewLayer::ViewLayerPlacement viewLayerPlacement);
102 	QString characterizeGroundFill(ViewLayer::ViewLayerID);
103 	ViewGeometry::WireFlag getTraceFlag();
104 	void hideCopperLogoItems(QList<ItemBase *> &);
105 	void restoreCopperLogoItems(QList<ItemBase *> &);
106 	void hideHoles(QList<ItemBase *> &);
107     QString makePasteMask(const QString & svgMask, ItemBase * board, double dpi, const LayerList & maskLayerIDs);
108 	int selectAllItemType(ModelPart::ItemType, const QString & typeName);
109 	bool isBoardLayerChange(ItemBase * itemBase, const QString & newModuleID, int & newLayers);
110 	void convertToVia(ConnectorItem * lastHoverEnterConnectorItem);
111 	void convertToBendpoint();
112     int checkLoadedTraces();
113 	bool hasCustomBoardShape();
114     virtual QSizeF jumperItemSize();
115     virtual LayerList routingLayers(ViewLayer::ViewLayerPlacement);
116     virtual bool attachedToTopLayer(ConnectorItem *);
117     virtual bool attachedToBottomLayer(ConnectorItem *);
118     QHash<QString, QString> getAutorouterSettings();
119     void setAutorouterSettings(QHash<QString, QString> &);
120 	void getDefaultViaSize(QString & ringThickness, QString & holeSize);
121     void hidePartSilkscreen();
122     void fabQuote();
123     QDialog * quoteDialog(QWidget * parent);
124     void setGroundFillKeepout();
125     void setViewFromBelow(bool);
126     bool dropOnBottom();
127     ViewLayer::ViewLayerPlacement defaultViewLayerPlacement(ModelPart *);
128 
129 public slots:
130 	void resizeBoard(double w, double h, bool doEmit);
131 	void showLabelFirstTime(long itemID, bool show, bool doEmit);
132 	void changeBoardLayers(int layers, bool doEmit);
133 	ItemBase * resizeBoard(long id, double w, double h);
134 
135 
136 public:
137 	enum CleanType {
138 		noClean,
139 		ninetyClean
140 	};
141 
142 	CleanType cleanType();
143 
144 protected:
145 	void setWireVisible(Wire * wire);
146 	// void checkAutorouted();
147 	ViewLayer::ViewLayerID multiLayerGetViewLayerID(ModelPart * modelPart, ViewLayer::ViewID, ViewLayer::ViewLayerPlacement, LayerList &);
148 	bool canChainWire(Wire *);
149 	bool canDragWire(Wire * wire);
150 	const QString & hoverEnterPartConnectorMessage(QGraphicsSceneHoverEvent * event, ConnectorItem * item);
151 	//bool modifyNewWireConnections(Wire * dragWire, ConnectorItem * fromOnWire, ConnectorItem * from, ConnectorItem * to, QUndoCommand * parentCommand);
152 	ViewLayer::ViewLayerID getDragWireViewLayerID(ConnectorItem *);
153 	bool canDropModelPart(ModelPart * modelPart);
154 	bool canCreateWire(Wire * dragWire, ConnectorItem * from, ConnectorItem * to);
155 	bool bothEndsConnected(Wire * wire, ViewGeometry::WireFlags, ConnectorItem * oneEnd, QList<Wire *> & wires, QList<ConnectorItem *> & partConnectorItems);
156 	void setUpColor(ConnectorItem * fromConnectorItem, ConnectorItem * toConnectorItem, Wire * wire, QUndoCommand * parentCommand);
157 	ConnectorItem * findNearestPartConnectorItem(ConnectorItem * fromConnectorItem);
158 	bool bothEndsConnectedAux(Wire * wire, ViewGeometry::WireFlags flag, ConnectorItem * oneEnd, QList<Wire *> & wires, QList<ConnectorItem *> & partConnectorItems, QList<Wire *> & visited);
159 	void getLabelFont(QFont &, QColor &, ItemBase *);
160 	double defaultGridSizeInches();
161 	ViewLayer::ViewLayerID getLabelViewLayerID(ItemBase *);
162 	ViewLayer::ViewLayerPlacement wireViewLayerPlacement(ConnectorItem *);
163 	bool resizingJumperItemPress(ItemBase *);
164 	bool resizingJumperItemRelease();
165 	void resizeJumperItem();
166 	void dealWithDefaultParts();
167 	bool connectorItemHasSpec(ConnectorItem * connectorItem, ViewLayer::ViewLayerPlacement spec);
168 	ViewLayer::ViewLayerPlacement createWireViewLayerPlacement(ConnectorItem * from, ConnectorItem * to);
169 	Wire * createTempWireForDragging(Wire * fromWire, ModelPart * wireModel, ConnectorItem * connectorItem, ViewGeometry & viewGeometry, ViewLayer::ViewLayerPlacement);
170 	void prereleaseTempWireForDragging(Wire*);
171 	void rotatePartLabels(double degrees, QTransform &, QPointF center, QUndoCommand * parentCommand);
172 	bool hasNeighbor(ConnectorItem * connectorItem, ViewLayer::ViewLayerID viewLayerID, const QRectF & r);
173 	void setGroundFillSeeds(const QString & intro);
174 	bool collectGroundFillSeeds(QList<ConnectorItem *> & seeds, bool includePotential);
175 	void shiftHoles();
176 	void selectAllXTraces(bool autoroutable, const QString & cmdText, bool forPCB);
177 	bool canAlignToCenter(ItemBase *);
178     void selectAllWires(ViewGeometry::WireFlag flag);
179     QString checkDroppedModuleID(const QString & moduleID);
180     bool canConnect(Wire * from, ItemBase * to);
181 	void collectThroughHole(QList<ConnectorItem *> & th, QList<ConnectorItem *> & pads, const LayerList &);
182 	ViewLayer::ViewLayerPlacement getViewLayerPlacement(ModelPart *, QDomElement & instance, QDomElement & view, ViewGeometry &);
183     void requestQuote(bool byUser);
184     double calcBoardArea(int & boardCount);
185     PaletteItem* addPartItem(ModelPart * modelPart, ViewLayer::ViewLayerPlacement, PaletteItem * paletteItem, bool doConnectors, bool & ok, ViewLayer::ViewID, bool temporary);
186     void requestQuoteSoon();
187     double getKeepoutMils();
188     bool updateOK(ConnectorItem *, ConnectorItem *);
189 
190 signals:
191 	void subSwapSignal(SketchWidget *, ItemBase *, const QString & newModuleID, ViewLayer::ViewLayerPlacement, long & newID, QUndoCommand * parentCommand);
192 	void boardDeletedSignal();
193 	void groundFillSignal();
194 	void copperFillSignal();
195 
196 protected:
197 	static void calcDistances(Wire * wire, QList<ConnectorItem *> & ends);
198 	static void clearDistances();
199 	static int calcDistance(Wire * wire, ConnectorItem * end, int distance, QList<Wire *> & distanceWires, bool & fromConnector0);
200 	static int calcDistanceAux(ConnectorItem * from, ConnectorItem * to, int distance, QList<Wire *> & distanceWires);
201 
202 protected slots:
203 	void alignJumperItem(class JumperItem *, QPointF &);
204     void wireSplitSlot(class Wire*, QPointF newPos, QPointF oldPos, const QLineF & oldLine);
205 	void postImageSlot(class GroundPlaneGenerator *, QImage * copperImage, QImage * boardImage, QGraphicsItem * board, QList<QRectF> *);
206     void gotFabQuote(QNetworkReply *);
207     void requestQuoteNow();
208     void getDroppedItemViewLayerPlacement(ModelPart * modelPart, ViewLayer::ViewLayerPlacement &);
209 
210 
211 protected:
212 	CleanType m_cleanType;
213 	QPointF m_jumperDragOffset;
214 	QPointer<class JumperItem> m_resizingJumperItem;
215 	QList<ConnectorItem *> * m_groundFillSeeds;
216     QHash<QString, QString> m_autorouterSettings;
217     QPointer<class QuoteDialog> m_quoteDialog;
218     QPointer<class QuoteDialog> m_rolloverQuoteDialog;
219     QTimer m_requestQuoteTimer;
220 
221 protected:
222 	static QSizeF m_jumperItemSize;
223 	static const char * FakeTraceProperty;
224 };
225 
226 
227 #endif
228