Improve/fix Expand connection for graphics.

This commit is contained in:
Alex Shvartzkop 2023-12-04 09:50:29 +03:00
parent e3eab57133
commit 111a8d6ab3
5 changed files with 48 additions and 21 deletions

View File

@ -335,7 +335,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* aTestItem, void* aTestData
// controls for vias, GetLayer() has no meaning, but IsOnLayer() works fine. User
// text in a footprint *is* sensitive to layer visibility but that was already handled.
int accuracy = KiROUND( 5 * m_Guide->OnePixelInIU() );
int accuracy = m_Guide->Accuracy();
if( zone )
{
@ -408,7 +408,7 @@ INSPECT_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* aTestItem, void* aTestData
// controls for vias, GetLayer() has no meaning, but IsOnLayer() works fine. User
// text in a footprint *is* sensitive to layer visibility but that was already handled.
int accuracy = KiROUND( 5 * m_Guide->OnePixelInIU() );
int accuracy = m_Guide->Accuracy();
if( zone )
{

View File

@ -159,6 +159,8 @@ public:
*/
virtual bool IgnoreZoneFills() const = 0;
virtual int Accuracy() const = 0;
virtual double OnePixelInIU() const = 0;
};
@ -332,7 +334,7 @@ public:
GENERAL_COLLECTORS_GUIDE( LSET aVisibleLayerMask, PCB_LAYER_ID aPreferredLayer,
KIGFX::VIEW* aView )
{
VECTOR2I one( 1, 1 );
static const VECTOR2I one( 1, 1 );
m_preferredLayer = aPreferredLayer;
m_visibleLayers = aVisibleLayerMask;
@ -363,7 +365,8 @@ public:
m_ignoreTracks = false;
m_ignoreZoneFills = true;
m_onePixelInIU = abs( aView->ToWorld( one, false ).x );
m_onePixelInIU = abs( aView->ToWorld( one, false ).x );
m_accuracy = KiROUND( 5 * m_onePixelInIU );
}
/**
@ -474,8 +477,10 @@ public:
bool IgnoreZoneFills() const override { return m_ignoreZoneFills; }
void SetIgnoreZoneFills( bool ignore ) { m_ignoreZoneFills = ignore; }
int Accuracy() const override { return m_accuracy; }
void SetAccuracy( int aValue ) { m_accuracy = aValue; }
double OnePixelInIU() const override { return m_onePixelInIU; }
void SetOnePixelInIU( double aValue ) { m_onePixelInIU = aValue; }
private:
// the storage architecture here is not important, since this is only
@ -504,7 +509,8 @@ private:
bool m_ignoreTracks;
bool m_ignoreZoneFills;
double m_onePixelInIU;
double m_onePixelInIU;
int m_accuracy;
};

View File

@ -23,6 +23,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <unordered_set>
#include <trigo.h>
#include <macros.h>
@ -51,6 +53,21 @@
const wxChar* traceBoardOutline = wxT( "KICAD_BOARD_OUTLINE" );
static class SCOPED_FLAGS_CLEANER : public std::unordered_set<EDA_ITEM*>
{
EDA_ITEM_FLAGS m_flagsToClear;
public:
SCOPED_FLAGS_CLEANER( const EDA_ITEM_FLAGS& aFlagsToClear ) : m_flagsToClear( aFlagsToClear ) {}
~SCOPED_FLAGS_CLEANER()
{
for( EDA_ITEM* item : *this )
item->ClearFlags( m_flagsToClear );
}
};
/**
* Local and tunable method of qualifying the proximity of two points.
*
@ -192,6 +209,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aShapeList, SHAPE_POLY_SE
VECTOR2I prevPt;
std::vector<SHAPE_LINE_CHAIN> contours;
SCOPED_FLAGS_CLEANER cleaner( SKIP_STRUCT );
for( PCB_SHAPE* shape : startCandidates )
shape->ClearFlags( SKIP_STRUCT );
@ -200,6 +218,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aShapeList, SHAPE_POLY_SE
{
graphic = (PCB_SHAPE*) *startCandidates.begin();
graphic->SetFlags( SKIP_STRUCT );
cleaner.insert( graphic );
startCandidates.erase( startCandidates.begin() );
contours.emplace_back();
@ -419,6 +438,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aShapeList, SHAPE_POLY_SE
prevGraphic = graphic;
graphic = nextGraphic;
graphic->SetFlags( SKIP_STRUCT );
cleaner.insert( graphic );
startCandidates.erase( graphic );
continue;
}

View File

@ -2298,7 +2298,7 @@ static double polygonArea( SHAPE_POLY_SET& aPolySet )
double FOOTPRINT::GetCoverageArea( const BOARD_ITEM* aItem, const GENERAL_COLLECTOR& aCollector )
{
int textMargin = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
int textMargin = aCollector.GetGuide()->Accuracy();
SHAPE_POLY_SET poly;
if( aItem->Type() == PCB_MARKER_T )
@ -2381,7 +2381,7 @@ double FOOTPRINT::GetCoverageArea( const BOARD_ITEM* aItem, const GENERAL_COLLEC
double FOOTPRINT::CoverageRatio( const GENERAL_COLLECTOR& aCollector ) const
{
int textMargin = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
int textMargin = aCollector.GetGuide()->Accuracy();
SHAPE_POLY_SET footprintRegion( GetBoundingHull() );
SHAPE_POLY_SET coveredRegion;

View File

@ -394,7 +394,7 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
[]( const VECTOR2I& aWhere, GENERAL_COLLECTOR& aCollector,
PCB_SELECTION_TOOL* aTool )
{
int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() );
int accuracy = aCollector.GetGuide()->Accuracy();
std::set<EDA_ITEM*> remove;
for( EDA_ITEM* item : aCollector )
@ -1588,20 +1588,19 @@ void PCB_SELECTION_TOOL::selectAllConnectedShapes( const std::vector<PCB_SHAPE*>
for( PCB_SHAPE* startItem : aStartItems )
toSearch.push( startItem );
GENERAL_COLLECTORS_GUIDE guide = getCollectorsGuide();
GENERAL_COLLECTOR collector;
GENERAL_COLLECTOR collector;
GENERAL_COLLECTORS_GUIDE guide = getCollectorsGuide();
auto searchPoint =
[&]( const VECTOR2I& aWhere )
{
collector.Collect( board(), { PCB_SHAPE_T }, aWhere, guide );
auto searchPoint = [&]( const VECTOR2I& aWhere )
{
collector.Collect( board(), { PCB_SHAPE_T }, aWhere, guide );
for( EDA_ITEM* item : collector )
{
if( isExpandableGraphicShape( item ) )
toSearch.push( static_cast<PCB_SHAPE*>( item ) );
}
};
for( EDA_ITEM* item : collector )
{
if( isExpandableGraphicShape( item ) )
toSearch.push( static_cast<PCB_SHAPE*>( item ) );
}
};
while( !toSearch.empty() )
{
@ -1615,6 +1614,8 @@ void PCB_SELECTION_TOOL::selectAllConnectedShapes( const std::vector<PCB_SHAPE*>
shape->SetFlags( SKIP_STRUCT );
toCleanup.insert( shape );
guide.SetLayerVisibleBits( shape->GetLayerSet() );
searchPoint( shape->GetStart() );
searchPoint( shape->GetEnd() );
}