From 14ce7a0ad7c5ff24ef9b0764252f918a0de941d3 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Sun, 18 Oct 2020 22:58:48 +0200 Subject: [PATCH] router: implement area constraint in optimizer --- pcbnew/router/pns_optimizer.cpp | 18 ++++++++---- pcbnew/router/pns_optimizer.h | 51 ++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/pcbnew/router/pns_optimizer.cpp b/pcbnew/router/pns_optimizer.cpp index 290c98dc6f..bac8c25e36 100644 --- a/pcbnew/router/pns_optimizer.cpp +++ b/pcbnew/router/pns_optimizer.cpp @@ -237,8 +237,7 @@ bool PRESERVE_VERTEX_CONSTRAINT::Check( int aVertex1, int aVertex2, const LINE* for( int i = aVertex1; i < aVertex2; i++ ) { - SEG::ecoord dist = aCurrentPath.CSegment(i).SquaredDistance( m_v ); - + int dist = aCurrentPath.CSegment(i).Distance( m_v ); if ( dist <= 1 ) { cv = true; @@ -254,7 +253,9 @@ bool PRESERVE_VERTEX_CONSTRAINT::Check( int aVertex1, int aVertex2, const LINE* SEG::ecoord dist = aReplacement.CSegment(i).SquaredDistance( m_v ); if ( dist <= 1 ) + { return true; + } } return false; @@ -306,9 +307,9 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP ) result = 1 - result; else { - double d = static_cast( ip.x - aP.x ) * + double d = static_cast( ip.x - aP.x ) * static_cast( ipNext.y - aP.y ) - - static_cast( ipNext.x - aP.x ) * + static_cast( ipNext.x - aP.x ) * static_cast( ip.y - aP.y ); if( !d ) @@ -592,7 +593,7 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult ) auto c = new PRESERVE_VERTEX_CONSTRAINT( m_world, m_preservedVertex ); AddConstraint( c ); } - + if( m_effortLevel & RESTRICT_VERTEX_RANGE ) { auto c = new RESTRICT_VERTEX_RANGE_CONSTRAINT( m_world, m_restrictedVertexRange.first, @@ -600,6 +601,13 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult ) AddConstraint( c ); } + if ( m_effortLevel & RESTRICT_AREA ) + { + auto c = new AREA_CONSTRAINT( m_world, m_restrictArea ); + AddConstraint( c ); + } + + if( m_effortLevel & KEEP_TOPOLOGY ) { auto c = new KEEP_TOPOLOGY_CONSTRAINT( m_world ); diff --git a/pcbnew/router/pns_optimizer.h b/pcbnew/router/pns_optimizer.h index 689cf89c29..111221af0d 100644 --- a/pcbnew/router/pns_optimizer.h +++ b/pcbnew/router/pns_optimizer.h @@ -100,10 +100,11 @@ public: SMART_PADS = 0x02, ///< Reroute pad exits MERGE_OBTUSE = 0x04, ///< Reduce corner cost by merging obtuse segments FANOUT_CLEANUP = 0x08, ///< Simplify pad-pad and pad-via connections if possible - KEEP_TOPOLOGY = 0x10, - PRESERVE_VERTEX = 0x20, + KEEP_TOPOLOGY = 0x10, + PRESERVE_VERTEX = 0x20, RESTRICT_VERTEX_RANGE = 0x40, - MERGE_COLINEAR = 0x80 ///< Merge co-linear segments + MERGE_COLINEAR = 0x80, ///< Merge co-linear segments + RESTRICT_AREA = 0x100 }; OPTIMIZER( NODE* aWorld ); @@ -194,17 +195,19 @@ private: ITEM* findPadOrVia( int aLayer, int aNet, const VECTOR2I& aP ) const; private: - SHAPE_INDEX_LIST m_cache; + SHAPE_INDEX_LIST m_cache; std::vector m_constraints; std::unordered_map m_cacheTags; - NODE* m_world; - int m_collisionKindMask; - int m_effortLevel; + NODE* m_world; + int m_collisionKindMask; + int m_effortLevel; + bool m_keepPostures; - VECTOR2I m_preservedVertex; + + VECTOR2I m_preservedVertex; std::pair m_restrictedVertexRange; - BOX2I m_restrictArea; + BOX2I m_restrictArea; }; @@ -213,9 +216,9 @@ class OPT_CONSTRAINT public: OPT_CONSTRAINT( NODE* aWorld ) : m_world( aWorld ) - { - m_priority = 0; - }; + { + m_priority = 0; + }; virtual ~OPT_CONSTRAINT() { @@ -230,9 +233,28 @@ public: protected: NODE* m_world; - int m_priority; + int m_priority; }; +class ANGLE_CONSTRAINT_45: public OPT_CONSTRAINT +{ +public: + ANGLE_CONSTRAINT_45( NODE* aWorld, int aEntryDirectionMask = -1, int aExitDirectionMask = -1 ) : + OPT_CONSTRAINT( aWorld ), + m_entryDirectionMask( aEntryDirectionMask ), + m_exitDirectionMask( aExitDirectionMask ) + { + + } + + virtual ~ANGLE_CONSTRAINT_45() {}; + + virtual bool Check ( int aVertex1, int aVertex2, LINE* aOriginLine, const SHAPE_LINE_CHAIN& aCurrentPath, const SHAPE_LINE_CHAIN& aReplacement ) override; + +private: + int m_entryDirectionMask; + int m_exitDirectionMask; +}; class AREA_CONSTRAINT : public OPT_CONSTRAINT { @@ -249,6 +271,7 @@ public: private: BOX2I m_allowedArea; + }; @@ -279,6 +302,7 @@ public: const SHAPE_LINE_CHAIN& aCurrentPath, const SHAPE_LINE_CHAIN& aReplacement ) override; private: + VECTOR2I m_v; }; @@ -297,6 +321,7 @@ public: const SHAPE_LINE_CHAIN& aCurrentPath, const SHAPE_LINE_CHAIN& aReplacement ) override; private: + int m_start; int m_end; };