1
/*******************************************************************
3
Part of the Fritzing project - http://fritzing.org
4
Copyright (c) 2007-2012 Fachhochschule Potsdam - http://fh-potsdam.de
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.
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.
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/>.
19
********************************************************************
22
$Author: cohen@irascible.com $:
23
$Date: 2012-06-28 00:18:10 +0200 (Thu, 28 Jun 2012) $
25
********************************************************************/
35
#include <QGraphicsItem>
37
#include <QProgressDialog>
38
#include <QUndoCommand>
40
#include "autorouter.h"
41
#include "../viewgeometry.h"
42
#include "../viewlayer.h"
44
class Autorouter1 : public Autorouter
49
Autorouter1(class PCBSketchWidget *);
54
bool drawTrace(class ConnectorItem * from, class ConnectorItem * to, const QPolygonF & boundingPoly, QList<class Wire *> & wires);
55
bool drawTrace(QPointF fromPos, QPointF toPos, class ConnectorItem * from, class ConnectorItem * to, QList<class Wire *> & wires, const QPolygonF & boundingPoly, int level, QPointF endPos, bool recurse, bool & shortcut);
56
bool tryLeftAndRight(QPointF fromPos, QPointF toPos, class ConnectorItem * from, class ConnectorItem * to, QPointF right, QPointF left, QList<class Wire *> & wires, const QPolygonF & boundingPoly, int level, QPointF endPos, bool & shortcut);
57
bool tryOne(QPointF fromPos, QPointF toPos, class ConnectorItem * from, class ConnectorItem * to, QPointF midPos, QList<class Wire *> & wires, const QPolygonF & boundingPoly, int level, QPointF endPos, bool & shortcut);
58
bool tryWithWires(QPointF fromPos, QPointF toPos, class ConnectorItem * from, class ConnectorItem * to, QList<class Wire *> & wires, class ConnectorItem * end, QList<class Wire *> & chainedWires, const QPolygonF & boundingPoly, int level, QPointF endPos, bool & shortcut);
59
bool tryWithWire(QPointF fromPos, QPointF toPos, class ConnectorItem * from, class ConnectorItem * to, QList<class Wire *> & wires, QPointF midpoint, QList<class Wire *> & chainedWires, const QPolygonF & boundingPoly, int level, QPointF endPos, bool & shortcut);
60
bool prePoly(QGraphicsItem * nearestObstacle, QPointF fromPos, QPointF toPos, QPointF & leftPoint, QPointF & rightPoint, bool adjust);
62
class JumperItem * drawJumperItem(struct JumperItemStruct *);
63
void restoreOriginalState(QUndoCommand * parentCommand);
64
void addToUndo(Wire * wire, QUndoCommand * parentCommand);
65
void addToUndo(QUndoCommand * parentCommand, QList<struct JumperItemStruct *> &);
66
void reduceWires(QList<Wire *> & wires, ConnectorItem * from, ConnectorItem * to, const QPolygonF & boundingPoly);
67
Wire * reduceWiresAux(QList<Wire *> & wires, ConnectorItem * from, ConnectorItem * to, QPointF fromPos, QPointF toPos, const QPolygonF & boundingPoly);
68
bool clean90(ConnectorItem * from, ConnectorItem * to, QList<Wire *> & oldWires);
69
bool clean90(QPointF fromPos, QPointF toPos, QList<Wire *> & newWires, int level);
70
QPointF calcPrimePoint(ConnectorItem *);
71
void findNearestIntersection(QLineF & l1, QPointF & fromPos, const QPolygonF & boundingPoly, bool & inBounds, QPointF & nearestBoundsIntersection, qreal & nearestBoundsIntersectionDistance);
72
bool hitsObstacle(class ItemBase * traceWire, ItemBase * ignore);
73
bool drawThree(QPointF fromPos, QPointF toPos, QPointF d1, QPointF d2, QList<Wire *> & newWires, int level, bool recurse);
74
bool drawTwo(QPointF fromPos, QPointF toPos, QPointF d1, QList<Wire *> & newWires, int level, bool recurse);
75
void clearLastDrawTraces();
76
void reduceColinearWires(QList<Wire *> &);
77
bool sameY(const QPointF & fromPos0, const QPointF & fromPos1, const QPointF & toPos0, const QPointF & toPos1);
78
bool sameX(const QPointF & fromPos0, const QPointF & fromPos1, const QPointF & toPos0, const QPointF & toPos1);
79
bool findSpaceFor(ConnectorItem * & from, class JumperItem *, struct JumperItemStruct *, QPointF & candidate);
80
void dijkstraNets(QHash<ConnectorItem *, int> & indexer, QVector<int> & netCounters, QList<struct Edge *> & edges);
81
void dijkstra(QList<class ConnectorItem *> & vertices, QHash<class ConnectorItem *, int> & indexer, QVector< QVector<double> > & adjacency, ViewGeometry::WireFlags skipFlags);
82
void addSubedge(Wire * wire, QList<ConnectorItem *> & toConnectorItems, QList<struct Subedge *> & subedges);
83
bool traceSubedge(Subedge* subedge, QList<Wire *> & wires, ItemBase * partForBounds, const QPolygonF & boundingPoly, QGraphicsLineItem *);
84
ItemBase * getPartForBounds(struct Edge *);
85
void fixupJumperItems(QList<struct JumperItemStruct *> &);
86
void runEdges(QList<Edge *> & edges, QGraphicsLineItem * lineItem,
87
QList<struct JumperItemStruct *> & jumperItemStructs,
88
QVector<int> & netCounters, struct RoutingStatus &);
89
void clearEdges(QList<Edge *> & edges);
90
void doCancel(QUndoCommand * parentCommand);
91
bool alreadyJumper(QList<struct JumperItemStruct *> & jumperItemStructs, ConnectorItem * from, ConnectorItem * to);
92
bool hasCollisions(JumperItem *, ViewLayer::ViewLayerID, QGraphicsItem *, ConnectorItem * from);
93
void updateProgress(int num, int denom);
96
static void calcDistance(QGraphicsItem * & nearestObstacle, double & nearestObstacleDistance, QPointF fromPos, QGraphicsItem * item);
97
static double calcDistance(QPointF fromPos, QGraphicsItem *);
98
static double distanceToLine(QPointF fromPos, QPointF p1, QPointF p2);
99
static void clearTraces(PCBSketchWidget * sketchWidget, bool deleteAll, QUndoCommand * parentCommand);
100
static void addUndoConnections(PCBSketchWidget * sketchWidget, bool connect, QList<Wire *> & wires, QUndoCommand * parentCommand);
103
QList< QLine * > m_lastDrawTraces;
104
QList<class ConnectorItem *> * m_drawingNet;
106
QGraphicsItem * m_nearestObstacle;
107
QList<Wire *> m_cleanWires;
108
ViewLayer::ViewLayerSpec m_viewLayerSpec;