23#ifndef __PNS_OPTIMIZER_H
24#define __PNS_OPTIMIZER_H
26#include <unordered_map>
29#include <geometry/shape_index_list.h>
30#include <geometry/shape_line_chain.h>
57 m_lengthCost( aB.m_lengthCost ),
58 m_cornerCost( aB.m_cornerCost )
63 static int CornerCost(
const SEG& aA,
const SEG& aB );
65 static int CornerCost(
const LINE& aLine );
67 void Add(
const LINE& aLine );
68 void Remove(
const LINE& aLine );
69 void Replace(
const LINE& aOldLine,
const LINE& aNewLine );
71 bool IsBetter(
const COST_ESTIMATOR& aOther,
double aLengthTolerance,
72 double aCornerTollerace )
const;
74 double GetLengthCost()
const {
return m_lengthCost; }
75 double GetCornerCost()
const {
return m_cornerCost; }
103 KEEP_TOPOLOGY = 0x10,
104 PRESERVE_VERTEX = 0x20,
105 RESTRICT_VERTEX_RANGE = 0x40,
107 RESTRICT_AREA = 0x100,
116 static bool Optimize(
LINE* aLine,
int aEffortLevel,
NODE* aWorld,
119 bool Optimize(
LINE* aLine,
LINE* aResult =
nullptr,
LINE* aRoot =
nullptr );
123 void SetWorld(
NODE* aNode ) { m_world = aNode; }
124 void CacheRemove( ITEM* aItem );
125 void ClearCache(
bool aStaticOnly =
false );
127 void SetCollisionMask(
int aMask )
129 m_collisionKindMask = aMask;
132 void SetEffortLevel(
int aEffort )
134 m_effortLevel = aEffort;
137 void SetPreserveVertex(
const VECTOR2I& aV )
139 m_preservedVertex = aV;
140 m_effortLevel |= OPTIMIZER::PRESERVE_VERTEX;
143 void SetRestrictVertexRange(
int aStart,
int aEnd )
145 m_restrictedVertexRange.first = aStart;
146 m_restrictedVertexRange.second = aEnd;
147 m_effortLevel |= OPTIMIZER::RESTRICT_VERTEX_RANGE;
150 void SetRestrictArea(
const BOX2I& aArea,
bool aStrict =
true )
152 m_restrictArea = aArea;
153 m_restrictAreaIsStrict = aStrict;
156 void ClearConstraints();
157 void AddConstraint ( OPT_CONSTRAINT *aConstraint );
160 static const int MaxCachedItems = 256;
162 typedef std::vector<SHAPE_LINE_CHAIN> BREAKOUT_LIST;
164 struct CACHE_VISITOR;
172 bool mergeObtuse( LINE* aLine );
173 bool mergeFull( LINE* aLine );
174 bool mergeColinear( LINE* aLine );
175 bool runSmartPads( LINE* aLine );
177 bool fanoutCleanup( LINE * aLine );
178 bool mergeDpSegments( DIFF_PAIR *aPair );
179 bool mergeDpStep( DIFF_PAIR *aPair,
bool aTryP,
int step );
181 bool checkColliding( ITEM* aItem,
bool aUpdateCache =
true );
184 void cacheAdd( ITEM* aItem,
bool aIsStatic );
185 void removeCachedSegments( LINE* aLine,
int aStartVertex = 0,
int aEndVertex = -1 );
187 bool checkConstraints(
int aVertex1,
int aVertex2, LINE* aOriginLine,
191 BREAKOUT_LIST circleBreakouts(
int aWidth,
const SHAPE* aShape,
bool aPermitDiagonal )
const;
192 BREAKOUT_LIST rectBreakouts(
int aWidth,
const SHAPE* aShape,
bool aPermitDiagonal )
const;
193 BREAKOUT_LIST customBreakouts(
int aWidth,
const ITEM* aItem,
bool aPermitDiagonal )
const;
194 BREAKOUT_LIST computeBreakouts(
int aWidth,
const ITEM* aItem,
bool aPermitDiagonal )
const;
196 int smartPadsSingle( LINE* aLine, ITEM* aPad,
bool aEnd,
int aEndVertex );
198 ITEM* findPadOrVia(
int aLayer,
int aNet,
const VECTOR2I& aP )
const;
202 std::vector<OPT_CONSTRAINT*> m_constraints;
203 std::unordered_map<ITEM*, CACHED_ITEM> m_cacheTags;
206 int m_collisionKindMask;
210 std::pair<int, int> m_restrictedVertexRange;
211 BOX2I m_restrictArea;
212 bool m_restrictAreaIsStrict;
229 virtual bool Check(
int aVertex1,
int aVertex2,
const LINE* aOriginLine,
233 int GetPriority()
const {
return m_priority; }
234 void SetPriority(
int aPriority ) { m_priority = aPriority; }
246 m_entryDirectionMask( aEntryDirectionMask ),
247 m_exitDirectionMask( aExitDirectionMask )
254 virtual bool Check (
int aVertex1,
int aVertex2,
const LINE* aOriginLine,
259 int m_entryDirectionMask;
260 int m_exitDirectionMask;
268 m_allowedArea ( aAllowedArea ),
269 m_allowedAreaStrict ( aAllowedAreaStrict )
273 bool Check(
int aVertex1,
int aVertex2,
const LINE* aOriginLine,
279 bool m_allowedAreaStrict;
291 bool Check(
int aVertex1,
int aVertex2,
const LINE* aOriginLine,
306 bool Check(
int aVertex1,
int aVertex2,
const LINE* aOriginLine,
324 virtual bool Check(
int aVertex1,
int aVertex2,
const LINE* aOriginLine,
339 m_minCorners( aMinCorners ),
340 m_maxCorners( aMaxCorners ),
341 m_angleMask( aAngleMask )
345 virtual bool Check(
int aVertex1,
int aVertex2,
const LINE* aOriginLine,
Definition pns_optimizer.h:242
Definition pns_optimizer.h:264
Definition pns_optimizer.h:334
Calculate the cost of a given line, taking corner angles and total length into account.
Definition pns_optimizer.h:49
Basic class for a differential pair.
Definition pns_diff_pair.h:235
Definition pns_optimizer.h:284
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:61
Keep the router "world" - i.e.
Definition pns_node.h:148
Perform various optimizations of the lines being routed, attempting to make the lines shorter and les...
Definition pns_optimizer.h:95
~OPTIMIZER()
A quick shortcut to optimize a line without creating and setting up an optimizer.
Definition pns_optimizer.cpp:121
OptimizationEffort
Definition pns_optimizer.h:98
@ LIMIT_CORNER_COUNT
Do not attempt to optimize if the resulting line's corner count is outside the predefined range.
Definition pns_optimizer.h:108
@ SMART_PADS
Reroute pad exits.
Definition pns_optimizer.h:100
@ FANOUT_CLEANUP
Simplify pad-pad and pad-via connections if possible.
Definition pns_optimizer.h:102
@ MERGE_SEGMENTS
Reduce corner cost iteratively.
Definition pns_optimizer.h:99
@ MERGE_COLINEAR
Merge co-linear segments.
Definition pns_optimizer.h:106
@ MERGE_OBTUSE
Reduce corner cost by merging obtuse segments.
Definition pns_optimizer.h:101
Definition pns_optimizer.h:217
Definition pns_optimizer.h:298
Definition pns_optimizer.h:315
Definition shape_index_list.h:43
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Definition shape_line_chain.h:81
An abstract shape on 2D plane.
Definition shape.h:117