From d94b8b9c0ebc2aed1f207705e95929153783ea29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Tue, 23 Apr 2019 11:46:26 +0200 Subject: [PATCH] router: copy m_maxClearance when cloning/branching PNS::NODEs Fixes: lp:1813328 * https://bugs.launchpad.net/kicad/+bug/1813328 (cherry picked from commit 9e00f48efc2eb70a884a7f0a6620bf519021513b) --- pcbnew/router/CMakeLists.txt | 1 + pcbnew/router/pns_index.cpp | 146 +++++++++++++++++++++++++++++++++++ pcbnew/router/pns_index.h | 117 +--------------------------- pcbnew/router/pns_node.cpp | 1 + 4 files changed, 149 insertions(+), 116 deletions(-) create mode 100644 pcbnew/router/pns_index.cpp diff --git a/pcbnew/router/CMakeLists.txt b/pcbnew/router/CMakeLists.txt index e7ca4422cb..078c4f7a13 100644 --- a/pcbnew/router/CMakeLists.txt +++ b/pcbnew/router/CMakeLists.txt @@ -17,6 +17,7 @@ set( PCBNEW_PNS_SRCS pns_diff_pair_placer.cpp pns_dp_meander_placer.cpp pns_dragger.cpp + pns_index.cpp pns_item.cpp pns_itemset.cpp pns_line.cpp diff --git a/pcbnew/router/pns_index.cpp b/pcbnew/router/pns_index.cpp new file mode 100644 index 0000000000..0457696ede --- /dev/null +++ b/pcbnew/router/pns_index.cpp @@ -0,0 +1,146 @@ +/* + * KiRouter - a push-and-(sometimes-)shove PCB router + * + * Copyright (C) 2013-2014 CERN + * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. + * Author: Tomasz Wlostowski + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "pns_index.h" + +namespace PNS { + +INDEX::INDEX() +{ + memset( m_subIndices, 0, sizeof( m_subIndices ) ); +} + + +INDEX::~INDEX() +{ + Clear(); +} + + +INDEX::ITEM_SHAPE_INDEX* INDEX::getSubindex( const ITEM* aItem ) +{ + int idx_n = -1; + + const LAYER_RANGE l = aItem->Layers(); + + switch( aItem->Kind() ) + { + case ITEM::VIA_T: + idx_n = SI_Multilayer; + break; + + case ITEM::SOLID_T: + { + if( l.IsMultilayer() ) + idx_n = SI_Multilayer; + else if( l.Start() == B_Cu ) // fixme: use kicad layer codes + idx_n = SI_PadsTop; + else if( l.Start() == F_Cu ) + idx_n = SI_PadsBottom; + else + idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight; + } + break; + + case ITEM::SEGMENT_T: + case ITEM::LINE_T: + idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight; + break; + + default: + break; + } + + if( idx_n < 0 || idx_n >= MaxSubIndices ) + { + wxASSERT( idx_n >= 0 ); + wxASSERT( idx_n < MaxSubIndices ); + return nullptr; + } + + if( !m_subIndices[idx_n] ) + m_subIndices[idx_n] = new ITEM_SHAPE_INDEX; + + return m_subIndices[idx_n]; +} + +void INDEX::Add( ITEM* aItem ) +{ + ITEM_SHAPE_INDEX* idx = getSubindex( aItem ); + + if( !idx ) + return; + + idx->Add( aItem ); + m_allItems.insert( aItem ); + int net = aItem->Net(); + + if( net >= 0 ) + { + m_netMap[net].push_back( aItem ); + } +} + +void INDEX::Remove( ITEM* aItem ) +{ + ITEM_SHAPE_INDEX* idx = getSubindex( aItem ); + + if( !idx ) + return; + + idx->Remove( aItem ); + m_allItems.erase( aItem ); + int net = aItem->Net(); + + if( net >= 0 && m_netMap.find( net ) != m_netMap.end() ) + m_netMap[net].remove( aItem ); +} + +void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem ) +{ + Remove( aOldItem ); + Add( aNewItem ); +} + + +void INDEX::Clear() +{ + for( int i = 0; i < MaxSubIndices; ++i ) + { + ITEM_SHAPE_INDEX* idx = m_subIndices[i]; + + if( idx ) + delete idx; + + m_subIndices[i] = NULL; + } +} + + +INDEX::NET_ITEMS_LIST* INDEX::GetItemsForNet( int aNet ) +{ + if( m_netMap.find( aNet ) == m_netMap.end() ) + return NULL; + + return &m_netMap[aNet]; +} + +}; diff --git a/pcbnew/router/pns_index.h b/pcbnew/router/pns_index.h index d6a1efbbc4..83970217fb 100644 --- a/pcbnew/router/pns_index.h +++ b/pcbnew/router/pns_index.h @@ -159,95 +159,6 @@ private: ITEM_SET m_allItems; }; -INDEX::INDEX() -{ - memset( m_subIndices, 0, sizeof( m_subIndices ) ); -} - -INDEX::ITEM_SHAPE_INDEX* INDEX::getSubindex( const ITEM* aItem ) -{ - int idx_n = -1; - - const LAYER_RANGE l = aItem->Layers(); - - switch( aItem->Kind() ) - { - case ITEM::VIA_T: - idx_n = SI_Multilayer; - break; - - case ITEM::SOLID_T: - { - if( l.IsMultilayer() ) - idx_n = SI_Multilayer; - else if( l.Start() == B_Cu ) // fixme: use kicad layer codes - idx_n = SI_PadsTop; - else if( l.Start() == F_Cu ) - idx_n = SI_PadsBottom; - else - idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight; - } - break; - - case ITEM::SEGMENT_T: - case ITEM::LINE_T: - idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight; - break; - - default: - break; - } - - if( idx_n < 0 || idx_n >= MaxSubIndices ) - { - wxASSERT( idx_n >= 0 ); - wxASSERT( idx_n < MaxSubIndices ); - return nullptr; - } - - if( !m_subIndices[idx_n] ) - m_subIndices[idx_n] = new ITEM_SHAPE_INDEX; - - return m_subIndices[idx_n]; -} - -void INDEX::Add( ITEM* aItem ) -{ - ITEM_SHAPE_INDEX* idx = getSubindex( aItem ); - - if( !idx ) - return; - - idx->Add( aItem ); - m_allItems.insert( aItem ); - int net = aItem->Net(); - - if( net >= 0 ) - { - m_netMap[net].push_back( aItem ); - } -} - -void INDEX::Remove( ITEM* aItem ) -{ - ITEM_SHAPE_INDEX* idx = getSubindex( aItem ); - - if( !idx ) - return; - - idx->Remove( aItem ); - m_allItems.erase( aItem ); - int net = aItem->Net(); - - if( net >= 0 && m_netMap.find( net ) != m_netMap.end() ) - m_netMap[net].remove( aItem ); -} - -void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem ) -{ - Remove( aOldItem ); - Add( aNewItem ); -} template int INDEX::querySingle( int index, const SHAPE* aShape, int aMinDistance, Visitor& aVisitor ) @@ -302,32 +213,6 @@ int INDEX::Query( const SHAPE* aShape, int aMinDistance, Visitor& aVisitor ) return total; } -void INDEX::Clear() -{ - for( int i = 0; i < MaxSubIndices; ++i ) - { - ITEM_SHAPE_INDEX* idx = m_subIndices[i]; - - if( idx ) - delete idx; - - m_subIndices[i] = NULL; - } -} - -INDEX::~INDEX() -{ - Clear(); -} - -INDEX::NET_ITEMS_LIST* INDEX::GetItemsForNet( int aNet ) -{ - if( m_netMap.find( aNet ) == m_netMap.end() ) - return NULL; - - return &m_netMap[aNet]; -} - -} +}; #endif diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index 8f3690c735..28ebbe3e1f 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -116,6 +116,7 @@ NODE* NODE::Branch() child->m_parent = this; child->m_ruleResolver = m_ruleResolver; child->m_root = isRoot() ? this : m_root; + child->m_maxClearance = m_maxClearance; // immmediate offspring of the root branch needs not copy anything. // For the rest, deep-copy joints, overridden item map and pointers