28#include <unordered_set>
29#include <unordered_map>
30#include <core/minoptmax.h>
32#include <geometry/shape_line_chain.h>
33#include <geometry/shape_index.h>
37#include "pns_itemset.h"
55enum class CONSTRAINT_TYPE
63 CT_HOLE_CLEARANCE = 7,
64 CT_EDGE_CLEARANCE = 8,
70 CONSTRAINT_TYPE m_Type;
83 virtual int Clearance(
const ITEM* aA,
const ITEM* aB ) = 0;
84 virtual int HoleClearance(
const ITEM* aA,
const ITEM* aB ) = 0;
85 virtual int HoleToHoleClearance(
const ITEM* aA,
const ITEM* aB ) = 0;
87 virtual int DpCoupledNet(
int aNet ) = 0;
88 virtual int DpNetPolarity(
int aNet ) = 0;
89 virtual bool DpNetPair(
const ITEM* aItem,
int& aNetP,
int& aNetN ) = 0;
91 virtual bool IsDiffPair(
const ITEM* aA,
const ITEM* aB ) = 0;
93 virtual bool QueryConstraint( CONSTRAINT_TYPE aType,
const PNS::ITEM* aItemA,
97 virtual wxString NetName(
int aNet ) = 0;
99 virtual void ClearCacheForItem(
const ITEM* aItem ) {}
124 void SetWorld(
const NODE* aNode,
const NODE* aOverride =
nullptr );
126 virtual bool operator()(
ITEM* aCandidate ) = 0;
129 bool visit(
ITEM* aCandidate );
150 typedef std::optional<OBSTACLE> OPT_OBSTACLE;
151 typedef std::vector<ITEM*> ITEM_VECTOR;
152 typedef std::vector<OBSTACLE> OBSTACLES;
158 int GetClearance(
const ITEM* aA,
const ITEM* aB )
const;
159 int GetHoleClearance(
const ITEM* aA,
const ITEM* aB )
const;
165 return m_maxClearance;
171 m_maxClearance = aClearance;
177 m_ruleResolver = aFunc;
182 return m_ruleResolver;
188 return m_joints.size();
206 int QueryColliding(
const ITEM* aItem, OBSTACLES& aObstacles,
int aKindMask = ITEM::ANY_T,
207 int aLimitCount = -1,
bool aDifferentNetsOnly =
true );
209 int QueryJoints(
const BOX2I& aBox, std::vector<JOINT*>& aJoints,
210 LAYER_RANGE aLayerMask = LAYER_RANGE::All(),
int aKindMask = ITEM::ANY_T );
220 OPT_OBSTACLE
NearestObstacle(
const LINE* aLine,
int aKindMask = ITEM::ANY_T,
221 const std::set<ITEM*>* aRestrictedSet =
nullptr );
231 OPT_OBSTACLE
CheckColliding(
const ITEM* aItem,
int aKindMask = ITEM::ANY_T );
242 OPT_OBSTACLE
CheckColliding(
const ITEM_SET& aSet,
int aKindMask = ITEM::ANY_T );
260 bool Add( std::unique_ptr< SEGMENT > aSegment,
bool aAllowRedundant =
false );
261 void Add( std::unique_ptr< SOLID > aSolid );
262 void Add( std::unique_ptr< VIA > aVia );
263 bool Add( std::unique_ptr< ARC > aArc,
bool aAllowRedundant =
false );
265 void Add( LINE& aLine,
bool aAllowRedundant =
false );
271 void Remove( SOLID* aSolid );
273 void Remove( SEGMENT* aSegment );
274 void Remove( ITEM* aItem );
281 void Remove( LINE& aLine );
289 void Replace( ITEM* aOldItem, std::unique_ptr< ITEM > aNewItem );
290 void Replace( LINE& aOldLine, LINE& aNewLine );
313 const LINE
AssembleLine( LINKED_ITEM* aSeg,
int* aOriginSegmentIndex =
nullptr,
314 bool aStopAtLockedJoints =
false,
315 bool aFollowLockedSegments =
false );
318 void Dump(
bool aLong =
false );
336 void Commit( NODE* aNode );
345 void LockJoint(
const VECTOR2I& aPos,
const ITEM* aItem,
bool aLock );
354 return FindJoint( aPos, aItem->Layers().Start(), aItem->Net() );
366 void AllItemsInNet(
int aNet, std::set<ITEM*>& aItems,
int aKindMask = -1 );
368 void ClearRanks(
int aMarkerMask = MK_HEAD | MK_VIOLATION | MK_HOLE );
370 void RemoveByMarker(
int aMarker );
374 bool HasChildren()
const
376 return !m_children.empty();
385 bool Overrides(
ITEM* aItem )
const
387 return m_override.find( aItem ) != m_override.end();
390 void FixupVirtualVias();
393 void Add( std::unique_ptr< ITEM > aItem,
bool aAllowRedundant =
false );
396 NODE(
const NODE& aB );
397 NODE& operator=(
const NODE& aB );
403 void linkJoint(
const VECTOR2I& aPos,
const LAYER_RANGE& aLayers,
int aNet, ITEM* aWhere );
406 void unlinkJoint(
const VECTOR2I& aPos,
const LAYER_RANGE& aLayers,
int aNet, ITEM* aWhere );
409 void addSolid( SOLID* aSeg );
410 void addSegment( SEGMENT* aSeg );
411 void addVia( VIA* aVia );
412 void addArc( ARC* aVia );
414 void removeSolidIndex( SOLID* aSeg );
415 void removeSegmentIndex( SEGMENT* aSeg );
416 void removeViaIndex( VIA* aVia );
417 void removeArcIndex( ARC* aVia );
419 void doRemove( ITEM* aItem );
421 void releaseChildren();
422 void releaseGarbage();
423 void rebuildJoint( JOINT* aJoint, ITEM* aItem );
427 return m_parent ==
nullptr;
432 SEGMENT* findRedundantSegment( SEGMENT* aSeg );
435 ARC* findRedundantArc( ARC* aSeg );
438 void followLine( LINKED_ITEM* aCurrent,
bool aScanDirection,
int& aPos,
int aLimit,
439 VECTOR2I* aCorners, LINKED_ITEM** aSegments,
bool* aArcReversed,
440 bool& aGuardHit,
bool aStopAtLockedJoints,
bool aFollowLockedSegments );
443 struct DEFAULT_OBSTACLE_VISITOR;
444 typedef std::unordered_multimap<JOINT::HASH_TAG, JOINT, JOINT::JOINT_TAG_HASH> JOINT_MAP;
445 typedef JOINT_MAP::value_type TagJointPair;
452 std::set<NODE*> m_children;
454 std::unordered_set<ITEM*> m_override;
458 RULE_RESOLVER* m_ruleResolver;
463 std::unordered_set<ITEM*> m_garbageItems;
Represent a contiguous set of PCB layers.
Definition pns_layerset.h:32
Definition minoptmax.h:31
Base class for PNS router board items.
Definition pns_item.h:57
A 2D point on a given set of layers and belonging to a certain net, that links together a number of b...
Definition pns_joint.h:43
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
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition pns_node.cpp:138
int FindLinesBetweenJoints(const JOINT &aA, const JOINT &aB, std::vector< LINE > &aLines)
Find the joints corresponding to the ends of line aLine.
Definition pns_node.cpp:1037
NODE * GetParent() const
Check if this branch contains an updated version of the m_item from the root branch.
Definition pns_node.h:379
void Replace(ITEM *aOldItem, std::unique_ptr< ITEM > aNewItem)
Replace an item with another one.
Definition pns_node.cpp:803
int GetMaxClearance() const
Set the worst-case clearance between any pair of items.
Definition pns_node.h:163
void SetMaxClearance(int aClearance)
Assign a clearance resolution function object.
Definition pns_node.h:169
void GetUpdatedItems(ITEM_VECTOR &aRemoved, ITEM_VECTOR &aAdded)
Return the list of items removed and added in this branch with respect to the root branch.
Definition pns_node.cpp:1345
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Check if the item collides with anything else in the world, and if found, returns the obstacle.
Definition pns_node.cpp:451
int QueryColliding(const ITEM *aItem, OBSTACLES &aObstacles, int aKindMask=ITEM::ANY_T, int aLimitCount=-1, bool aDifferentNetsOnly=true)
Find items colliding (closer than clearance) with the item aItem.
Definition pns_node.cpp:267
JOINT * FindJoint(const VECTOR2I &aPos, const ITEM *aItem)
Search for a joint at a given position, linked to given item.
Definition pns_node.h:352
void FindLineEnds(const LINE &aLine, JOINT &aA, JOINT &aB)
Destroy all child nodes. Applicable only to the root node.
Definition pns_node.cpp:1030
RULE_RESOLVER * GetRuleResolver() const
Return the number of joints.
Definition pns_node.h:180
int GetHoleToHoleClearance(const ITEM *aA, const ITEM *aB) const
Return the pre-set worst case clearance between any pair of items.
Definition pns_node.cpp:126
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Add an item to the current node.
Definition pns_node.cpp:639
int JointCount() const
Return the number of nodes in the inheritance chain (wrs to the root node).
Definition pns_node.h:186
OPT_OBSTACLE NearestObstacle(const LINE *aLine, int aKindMask=ITEM::ANY_T, const std::set< ITEM * > *aRestrictedSet=nullptr)
Follow the line in search of an obstacle that is nearest to the starting to the line's starting point...
Definition pns_node.cpp:297
JOINT * FindJoint(const VECTOR2I &aPos, int aLayer, int aNet)
Search for a joint at a given position, layer and belonging to given net.
Definition pns_node.cpp:1142
void Remove(ARC *aArc)
Remove an item from this branch.
Definition pns_node.cpp:838
void Commit(NODE *aNode)
Apply the changes from a given branch (aNode) to the root branch.
Definition pns_node.cpp:1392
~NODE()
Return the expected clearance between items a and b.
Definition pns_node.cpp:69
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=nullptr, bool aStopAtLockedJoints=false, bool aFollowLockedSegments=false)
Follow the joint map to assemble a line connecting two non-trivial joints starting from segment aSeg.
Definition pns_node.cpp:948
const ITEM_SET HitTest(const VECTOR2I &aPoint) const
Find all items that contain the point aPoint.
Definition pns_node.cpp:518
Definition pns_node.h:116
const NODE * m_node
node we are searching in (either root or a branch)
Definition pns_node.h:134
const ITEM * m_item
the item we are looking for collisions with
Definition pns_node.h:132
const NODE * m_override
node that overrides root entries
Definition pns_node.h:135
Definition pns_horizon_iface.hpp:29
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
Definition wx_compat.h:13
Hold an object colliding with another object, along with some useful data about the collision.
Definition pns_node.h:106
int m_distFirst
... and the distance thereof
Definition pns_node.h:112
VECTOR2I m_ipFirst
First intersection between m_head and m_hull.
Definition pns_node.h:111
ITEM * m_item
Item found to be colliding with m_head.
Definition pns_node.h:109
const ITEM * m_head
Item we search collisions with.
Definition pns_node.h:107
SHAPE_LINE_CHAIN m_hull
Hull of the colliding m_item.
Definition pns_node.h:110