kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #29341
[PATCH] More aggressive sheet-selection
Hello everyone!
I made a small change to the "select hierarchical sheet" function. I
would love if someone tried this and gave some feedback.
Before the function only selected segments belonging to a netlist unique
to that hierarchical sheet. Now it will use the "select logical
connection" to every segment connected to module from the subsheet as
well. presonally I think it is more useful now, but I want confirmation
if possible :)
- Kristoffer
>From d0f376bd274d83a091b10e373a7cca483996d5cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= <kristoffer.odmark90@xxxxxxxxx>
Date: Wed, 3 May 2017 15:21:24 +0200
Subject: [PATCH] Modified the selectAllItemOnSheet to select logical
connections that are launched from the sheet-local modules
---
pcbnew/class_board.cpp | 16 ++++++++++++++++
pcbnew/class_board.h | 10 ++++++++++
pcbnew/class_track.h | 11 +++++++++++
pcbnew/tools/selection_tool.cpp | 14 +++++++++++++-
4 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp
index 29f6c3314..02dcfdc24 100644
--- a/pcbnew/class_board.cpp
+++ b/pcbnew/class_board.cpp
@@ -32,6 +32,7 @@
#include <limits.h>
#include <algorithm>
+#include <iterator>
#include <fctsys.h>
#include <common.h>
@@ -1579,6 +1580,21 @@ VIA* BOARD::GetViaByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer) con
}
return NULL;
+
+}
+
+std::list<TRACK*> BOARD::GetTracksByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer ) const
+{
+ std::list<TRACK*> tracks;
+ for( TRACK *track = GetFirstTrack( m_Track); track; track = GetFirstTrack( track->Next() ) )
+ {
+ if( ((track->GetStart() == aPosition) || track->GetEnd() == aPosition ) &&
+ (track->GetState( BUSY | IS_DELETED ) == 0) &&
+ ((aLayer == UNDEFINED_LAYER) || (track->IsOnLayer( aLayer ))))
+
+ tracks.push_back(track);
+ }
+ return tracks;
}
diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h
index ea54cd1a8..8fda0542c 100644
--- a/pcbnew/class_board.h
+++ b/pcbnew/class_board.h
@@ -1193,6 +1193,16 @@ public:
VIA* GetViaByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer = PCB_LAYER_ID( -1 ) ) const;
/**
+ * Function GetTracksByPosition
+ * finds the list of tracks that starts or ends at \a aPosition on \a aLayer.
+ *
+ * @param aPosition The wxPoint to check start agains against.
+ * @param aLayer The layer to search. Use -1 (<PCB_LAYER_ID>::UNDEFINED_LAYER) for a don't care.
+ * @return std::list<TRACK*> A list of TRACK* items that can be zero if no track is found.
+ */
+ std::list<TRACK*> GetTracksByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer = PCB_LAYER_ID( -1 ) ) const;
+
+ /**
* Function GetPad
* finds a pad \a aPosition on \a aLayer.
*
diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h
index a9e3e887d..5fa3d317e 100644
--- a/pcbnew/class_track.h
+++ b/pcbnew/class_track.h
@@ -505,5 +505,16 @@ inline VIA* GetFirstVia( TRACK* aTrk, const TRACK* aStopPoint = NULL )
else
return NULL;
}
+inline TRACK* GetFirstTrack( TRACK* aTrk, const TRACK* aStopPoint = NULL )
+{
+ while( aTrk && (aTrk != aStopPoint) && (aTrk->Type() != PCB_TRACE_T) )
+ aTrk = aTrk->Next();
+
+ // It could stop because of the stop point, not on a via
+ if( aTrk && (aTrk->Type() == PCB_TRACE_T) )
+ return static_cast<TRACK*>( aTrk );
+ else
+ return NULL;
+}
#endif // CLASS_TRACK_H
diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp
index 494fb1cf1..291307662 100644
--- a/pcbnew/tools/selection_tool.cpp
+++ b/pcbnew/tools/selection_tool.cpp
@@ -801,6 +801,7 @@ void SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetpath )
//Generate a list of all pads, and of all nets they belong to.
std::list<int> netcodeList;
+ std::list<BOARD_CONNECTED_ITEM*> padList;
for( MODULE* mmod : modList )
{
for( D_PAD* pad = mmod->Pads().GetFirst(); pad; pad = pad->Next() )
@@ -808,14 +809,25 @@ void SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetpath )
if( pad->IsConnected() )
{
netcodeList.push_back( pad->GetNetCode() );
+ padList.push_back( pad );
}
}
}
-
// remove all duplicates
netcodeList.sort();
netcodeList.unique();
+ // auto select trivial connections segments which are launched from the pads
+ std::list<TRACK*> launchTracks;
+ for(auto pad : padList)
+ {
+ launchTracks = board()->GetTracksByPosition( pad->GetPosition() );
+ for (auto track : launchTracks)
+ {
+ selectAllItemsConnectedToTrack( *track );
+ }
+ }
+
// now we need to find all modules that are connected to each of these nets
// then we need to determine if these modules are in the list of modules
// belonging to this sheet ( modList )
--
2.12.2
Follow ups