← Back to team overview

kicad-developers team mailing list archive

Re: RC2 blockers?

 

On 03.11.2015 20:13, Javier Serrano wrote:
> On Tue, Nov 3, 2015 at 12:39 AM, Wayne Stambaugh <stambaughw@xxxxxxxxx> wrote:
>> Yes.  The P&S router still has a serious segfault issue.  I've talked to
>> Tom about it and he is working on it.  As soon as the fixes are
>> committed, I will be rolling out rc2.  I'm hoping it will be soon.
> 
> Last time I saw Orson and Tom we were in Australia and they both
> looked like they could really use a few days/weeks of vacation. They
> stayed there and I am back in Geneva. I will talk with them when they
> are back, which is the 9th for Tom and the 17th for Orson.

Hi guys,

Here's an updated version of the patch. Wayne, if you haven't committed
the one I've sent you previously, please take this one. It also fixes
one more issue and removes the pritnfs() reported by Joseph. Sorry it
took so long.

Greetings from AU
Tom


> 
> Cheers,
> 
> Javier
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 

>From 42f067b8b45aef8826cee8bcf6c1957f295a813b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= <tomasz.wlostowski@xxxxxxx>
Date: Tue, 3 Nov 2015 20:21:02 +1000
Subject: [PATCH] Multiple fixes for the P&S router:     - invalidate end item
 after changing layers / ortho mode (fixes a rare segfault)     - fixed hidden
 database corrpution in auto-track-width causing assertion fail in pushVia()
 or segfault in release builds.     - respect grid when snapping to segments  
   - fixed cursor issue when dragging is invoked from the context menu

---
 pcbnew/router/pns_line_placer.cpp    | 11 +++++------
 pcbnew/router/pns_router.cpp         |  6 ++++--
 pcbnew/router/pns_router.h           | 10 ++++------
 pcbnew/router/pns_shove.cpp          |  7 +++++++
 pcbnew/router/pns_sizes_settings.cpp |  4 +++-
 pcbnew/router/pns_tool_base.cpp      | 11 +++++++++++
 pcbnew/router/pns_tool_base.h        |  3 +++
 pcbnew/router/router_tool.cpp        | 15 +++++++++++----
 pcbnew/tools/grid_helper.cpp         | 37 ++++++++++++++++++++++++++++++++++++
 pcbnew/tools/grid_helper.h           |  4 ++++
 10 files changed, 89 insertions(+), 19 deletions(-)

diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp
index bdc2970..5ff7977 100644
--- a/pcbnew/router/pns_line_placer.cpp
+++ b/pcbnew/router/pns_line_placer.cpp
@@ -952,6 +952,7 @@ void PNS_LINE_PLACER::removeLoops( PNS_NODE* aNode, PNS_LINE& aLatest )
     if ( aLatest.CLine().CPoint( 0 ) == aLatest.CLine().CPoint( -1 ) )
         return;
 
+    std::set<PNS_SEGMENT *> toErase;
     aNode->Add( &aLatest, true );
 
     for( int s = 0; s < aLatest.LinkCount(); s++ )
@@ -979,13 +980,16 @@ void PNS_LINE_PLACER::removeLoops( PNS_NODE* aNode, PNS_LINE& aLatest )
 
             if( !( line.ContainsSegment( seg ) ) && line.SegmentCount() )
             {
-                aNode->Remove( &line );
+                BOOST_FOREACH( PNS_SEGMENT *ss, *line.LinkedSegments() )
+                    toErase.insert(ss);
                 removedCount++;
             }
         }
 
         TRACE( 0, "total segs removed: %d/%d\n", removedCount % total );
     }
+    BOOST_FOREACH( PNS_SEGMENT *s, toErase )
+        aNode->Remove (s);
 
     aNode->Remove( &aLatest );
 }
@@ -1034,17 +1038,12 @@ void PNS_LINE_PLACER::updateLeadingRatLine()
 void PNS_LINE_PLACER::SetOrthoMode( bool aOrthoMode )
 {
     m_orthoMode = aOrthoMode;
-
-    if( !m_idle )
-        Move( m_currentEnd, NULL );
 }
 
 bool PNS_LINE_PLACER::buildInitialLine( const VECTOR2I& aP, PNS_LINE& aHead )
 {
     SHAPE_LINE_CHAIN l;
 
-    printf("H-net %d\n", aHead.Net());
-
     if( m_p_start == aP )
     {
         l.Clear();
diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp
index 8526a64..fd7d911 100644
--- a/pcbnew/router/pns_router.cpp
+++ b/pcbnew/router/pns_router.cpp
@@ -35,6 +35,8 @@
 #include <geometry/shape_rect.h>
 #include <geometry/shape_circle.h>
 
+#include <tools/grid_helper.h>
+
 #include "trace.h"
 #include "pns_node.h"
 #include "pns_line_placer.h"
@@ -572,8 +574,8 @@ const VECTOR2I PNS_ROUTER::SnapToItem( PNS_ITEM* aItem, VECTOR2I aP, bool& aSpli
             anchor = s.B;
         else
         {
-            anchor = s.NearestPoint( aP );
-            aSplitsSegment = true;
+            anchor = m_gridHelper->AlignToSegment ( aP, s );
+            aSplitsSegment = (anchor != s.A && anchor != s.B );
         }
 
         break;
diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h
index 05be228..0541dec 100644
--- a/pcbnew/router/pns_router.h
+++ b/pcbnew/router/pns_router.h
@@ -40,6 +40,7 @@ class BOARD_ITEM;
 class D_PAD;
 class TRACK;
 class VIA;
+class GRID_HELPER;
 class PNS_NODE;
 class PNS_DIFF_PAIR_PLACER;
 class PNS_PLACEMENT_ALGO;
@@ -106,7 +107,6 @@ public:
 
     void StopRouting();
 
-
     int GetClearance( const PNS_ITEM* aA, const PNS_ITEM* aB ) const;
 
     PNS_NODE* GetWorld() const
@@ -216,10 +216,9 @@ public:
 
     PNS_PLACEMENT_ALGO *Placer() { return m_placer; }
 
-    void SetGrid( const VECTOR2I& aOrigin, const VECTOR2I& aSize )
+    void SetGrid( GRID_HELPER *aGridHelper )
     {
-        m_gridOrigin = aOrigin;
-        m_gridSize = aSize;
+        m_gridHelper = aGridHelper;
     }
 
 private:
@@ -284,8 +283,7 @@ private:
     wxString m_toolStatusbarName;
     wxString m_failureReason;
 
-    VECTOR2I m_gridOrigin;
-    VECTOR2I m_gridSize;
+    GRID_HELPER *m_gridHelper;
 };
 
 #endif
diff --git a/pcbnew/router/pns_shove.cpp b/pcbnew/router/pns_shove.cpp
index 9ff66ca..5239376 100644
--- a/pcbnew/router/pns_shove.cpp
+++ b/pcbnew/router/pns_shove.cpp
@@ -1134,6 +1134,13 @@ PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::ShoveLines( const PNS_LINE& aCurrentHead )
         m_newHead = OPT_LINE();
     }
 
+    if (m_newHead && head.EndsWithVia() )
+    {
+        PNS_VIA v = head.Via();
+        v.SetPos( m_newHead->CPoint(-1) );
+        m_newHead->AppendVia(v);
+    }
+
     return st;
 }
 
diff --git a/pcbnew/router/pns_sizes_settings.cpp b/pcbnew/router/pns_sizes_settings.cpp
index 977be6f..dae3ea3 100644
--- a/pcbnew/router/pns_sizes_settings.cpp
+++ b/pcbnew/router/pns_sizes_settings.cpp
@@ -55,7 +55,9 @@ int PNS_SIZES_SETTINGS::inheritTrackWidth( PNS_ITEM* aItem )
 
     int mval = INT_MAX;
 
-    PNS_ITEMSET linkedSegs = jt->Links().ExcludeItem( aItem ).FilterKinds( PNS_ITEM::SEGMENT );
+
+    PNS_ITEMSET linkedSegs = jt->Links();
+    linkedSegs.ExcludeItem( aItem ).FilterKinds( PNS_ITEM::SEGMENT );
 
     BOOST_FOREACH( PNS_ITEM* item, linkedSegs.Items() )
     {
diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp
index 2be6246..2381b81 100644
--- a/pcbnew/router/pns_tool_base.cpp
+++ b/pcbnew/router/pns_tool_base.cpp
@@ -42,6 +42,7 @@
 
 #include <tool/context_menu.h>
 #include <tools/common_actions.h>
+#include <tools/grid_helper.h>
 
 #include <ratsnest_data.h>
 
@@ -75,20 +76,26 @@ PNS_TOOL_BASE::PNS_TOOL_BASE( const std::string& aToolName ) :
     m_frame = NULL;
     m_ctls = NULL;
     m_board = NULL;
+    m_gridHelper = NULL;
 }
 
 
 PNS_TOOL_BASE::~PNS_TOOL_BASE()
 {
     delete m_router;
+    delete m_gridHelper;
 }
 
 
+
 void PNS_TOOL_BASE::Reset( RESET_REASON aReason )
 {
     if( m_router )
         delete m_router;
 
+    if (m_gridHelper)
+        delete m_gridHelper;
+
     m_frame = getEditFrame<PCB_EDIT_FRAME>();
     m_ctls = getViewControls();
     m_board = getModel<BOARD>();
@@ -100,6 +107,10 @@ void PNS_TOOL_BASE::Reset( RESET_REASON aReason )
     m_router->SyncWorld();
     m_router->LoadSettings( m_savedSettings );
     m_router->UpdateSizes( m_savedSizes );
+
+    m_gridHelper = new GRID_HELPER ( m_frame );
+    m_router->SetGrid ( m_gridHelper );
+
     m_needsSync = false;
 
     if( getView() )
diff --git a/pcbnew/router/pns_tool_base.h b/pcbnew/router/pns_tool_base.h
index 11e7b9b..20bed42 100644
--- a/pcbnew/router/pns_tool_base.h
+++ b/pcbnew/router/pns_tool_base.h
@@ -32,6 +32,7 @@
 #include "pns_router.h"
 
 class PNS_TUNE_STATUS_POPUP;
+class GRID_HELPER;
 
 class APIEXPORT PNS_TOOL_BASE : public TOOL_INTERACTIVE
 {
@@ -73,6 +74,8 @@ protected:
     PCB_EDIT_FRAME* m_frame;
     KIGFX::VIEW_CONTROLS* m_ctls;
     BOARD* m_board;
+    GRID_HELPER* m_gridHelper;
+
 
 };
 
diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp
index bd59a08..4b610a3 100644
--- a/pcbnew/router/router_tool.cpp
+++ b/pcbnew/router/router_tool.cpp
@@ -46,6 +46,8 @@
 #include <tool/tool_settings.h>
 #include <tools/common_actions.h>
 #include <tools/size_menu.h>
+#include <tools/selection_tool.h>
+#include <tools/edit_tool.h>
 
 #include <ratsnest_data.h>
 
@@ -551,8 +553,8 @@ void ROUTER_TOOL::performRouting()
             break;
         else if( evt->IsMotion() )
         {
-            updateEndItem( *evt );
             m_router->SetOrthoMode( evt->Modifier( MD_CTRL ) );
+            updateEndItem( *evt );
             m_router->Move( m_endSnapPoint, m_endItem );
         }
         else if( evt->IsClick( BUT_LEFT ) )
@@ -568,6 +570,7 @@ void ROUTER_TOOL::performRouting()
 
             // Synchronize the indicated layer
             m_frame->SetActiveLayer( ToLAYER_ID( m_router->GetCurrentLayer() ) );
+            updateEndItem( *evt );
             m_router->Move( m_endSnapPoint, m_endItem );
             m_startItem = NULL;
         }
@@ -586,12 +589,13 @@ void ROUTER_TOOL::performRouting()
         else if( evt->IsAction( &ACT_SwitchPosture ) )
         {
             m_router->FlipPosture();
+            updateEndItem( *evt );
             m_router->Move( m_endSnapPoint, m_endItem );        // refresh
         }
         else if( evt->IsAction( &COMMON_ACTIONS::layerChanged ) )
         {
-            updateEndItem( *evt );
             m_router->SwitchLayer( m_frame->GetActiveLayer() );
+            updateEndItem( *evt );
             m_router->Move( m_endSnapPoint, m_endItem );        // refresh
         }
         else if( evt->IsAction( &ACT_EndTrack ) )
@@ -733,12 +737,15 @@ void ROUTER_TOOL::performDragging()
     if( m_startItem && m_startItem->Net() >= 0 )
         highlightNet( true, m_startItem->Net() );
 
-    ctls->ForceCursorPosition( false );
     ctls->SetAutoPan( true );
 
     while( OPT_TOOL_EVENT evt = Wait() )
     {
-        if( evt->IsCancel() || evt->IsActivate() )
+        ctls->ForceCursorPosition( false );
+
+        VECTOR2I p0 = ctls->GetCursorPosition();
+
+       if( evt->IsCancel() || evt->IsActivate() )
             break;
         else if( evt->IsMotion() )
         {
diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp
index 56efa40..d7093bc 100644
--- a/pcbnew/tools/grid_helper.cpp
+++ b/pcbnew/tools/grid_helper.cpp
@@ -112,6 +112,43 @@ VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
 }
 
 
+VECTOR2I GRID_HELPER::AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg )
+{
+    OPT_VECTOR2I pts[6];
+
+    VECTOR2I origin ( GetOrigin() );
+    VECTOR2I grid ( GetGrid() );
+
+    const VECTOR2D gridOffset( GetOrigin() );
+    const VECTOR2D gridSize( GetGrid() );
+
+    VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
+                      KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
+
+    pts[0] = aSeg.A;
+    pts[1] = aSeg.B;
+    pts[2] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I(1, 0 ) ) );
+    pts[3] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I(0, 1 ) ) );
+
+    int min_d = std::numeric_limits<int>::max();
+
+    for(int i = 0; i < 4; i++)
+    {
+        if ( pts[i] && aSeg.Contains( *pts[i] ) )
+        {
+            int d = (*pts[i] - aPoint).EuclideanNorm();
+
+            if( d < min_d )
+            {
+                min_d = d;
+                nearest = *pts[i];
+            }
+        }
+    }
+
+    return nearest;
+}
+
 VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, BOARD_ITEM* aItem )
 {
     clearAnchors();
diff --git a/pcbnew/tools/grid_helper.h b/pcbnew/tools/grid_helper.h
index f239b11..6401b69 100644
--- a/pcbnew/tools/grid_helper.h
+++ b/pcbnew/tools/grid_helper.h
@@ -32,6 +32,8 @@
 
 #include <layers_id_colors_and_visibility.h>
 
+#include <geometry/seg.h>
+
 class PCB_BASE_FRAME;
 
 class GRID_HELPER {
@@ -50,6 +52,8 @@ public:
 
     VECTOR2I Align( const VECTOR2I& aPoint ) const;
 
+    VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
+
     VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem );
     VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
 
-- 
1.9.1


Follow ups

References