From 1dbaa89f95c9686888144b1a76c276b4307f82eb Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 12 Jul 2019 22:42:30 +0100 Subject: [PATCH] Fix a bug in tool activation/deactivation and another illegal static_cast. Fixes: lp:1836419 * https://bugs.launchpad.net/kicad/+bug/1836419 --- common/tool/tool_event.cpp | 2 +- pcbnew/tools/zone_create_helper.cpp | 43 ++++++++--------------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/common/tool/tool_event.cpp b/common/tool/tool_event.cpp index cd99a049fb..ed7fdf95d0 100644 --- a/common/tool/tool_event.cpp +++ b/common/tool/tool_event.cpp @@ -54,7 +54,7 @@ static const std::string flag2string( int aFlag, const FlagString* aExps ) void TOOL_EVENT::init() { // By default only MESSAGEs and Cancels are passed to multiple recipients - m_passEvent = m_category == TC_MESSAGE || IsCancelInteractive(); + m_passEvent = m_category == TC_MESSAGE || IsCancelInteractive() || IsActivate(); m_hasPosition = ( m_category == TC_MOUSE || m_category == TC_COMMAND ); } diff --git a/pcbnew/tools/zone_create_helper.cpp b/pcbnew/tools/zone_create_helper.cpp index e4947ef40d..550f0d7c3d 100644 --- a/pcbnew/tools/zone_create_helper.cpp +++ b/pcbnew/tools/zone_create_helper.cpp @@ -22,19 +22,14 @@ */ #include - -#include #include #include #include #include -#include #include #include - #include #include - #include ZONE_CREATE_HELPER::ZONE_CREATE_HELPER( DRAWING_TOOL& aTool, PARAMS& aParams ): @@ -133,9 +128,7 @@ void ZONE_CREATE_HELPER::performZoneCutout( ZONE_CONTAINER& aZone, ZONE_CONTAINE newZoneOutline->AddOutline( originalOutline.Outline( i ) ); for (int j = 0; j < originalOutline.HoleCount(i) ; j++ ) - { newZoneOutline->AddHole( originalOutline.CHole(i, j), i ); - } auto newZone = new ZONE_CONTAINER( aZone ); newZone->SetOutline( newZoneOutline ); @@ -160,13 +153,10 @@ void ZONE_CREATE_HELPER::performZoneCutout( ZONE_CONTAINER& aZone, ZONE_CONTAINE void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) { - auto& frame = *m_tool.getEditFrame(); - auto board = m_tool.getModel(); - switch ( m_params.m_mode ) { case ZONE_MODE::CUTOUT: - // For cutouts, subtract from the source + // For cutouts, subtract from the source performZoneCutout( *m_params.m_sourceZone, *aZone ); break; @@ -179,7 +169,7 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) if( !m_params.m_keepout ) { - ZONE_FILLER filler( board ); + ZONE_FILLER filler( m_tool.getModel() ); filler.Fill( { aZone.get() } ); } @@ -192,13 +182,12 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) case ZONE_MODE::GRAPHIC_POLYGON: { BOARD_COMMIT bCommit( &m_tool ); - BOARD_ITEM_CONTAINER* parent = frame.GetModel(); + BOARD_ITEM_CONTAINER* parent = m_tool.m_frame->GetModel(); if( m_tool.getDrawingLayer() != Edge_Cuts ) { - auto poly = m_tool.m_editModules ? - new EDGE_MODULE( (MODULE *) parent ) : - new DRAWSEGMENT(); + auto poly = m_tool.m_editModules ? new EDGE_MODULE( (MODULE *) parent ) + : new DRAWSEGMENT(); poly->SetShape ( S_POLYGON ); poly->SetLayer( m_tool.getDrawingLayer() ); poly->SetPolyShape ( *aZone->Outline() ); @@ -211,9 +200,8 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) for( auto seg = outline->IterateSegments( 0 ); seg; seg++ ) { - auto new_seg = m_tool.m_editModules ? - new EDGE_MODULE( (MODULE *) parent ) : - new DRAWSEGMENT(); + auto new_seg = m_tool.m_editModules ? new EDGE_MODULE( (MODULE *) parent ) + : new DRAWSEGMENT(); new_seg->SetShape( S_SEGMENT ); new_seg->SetLayer( m_tool.getDrawingLayer() ); new_seg->SetStart( wxPoint( seg.Get().A.x, seg.Get().A.y ) ); @@ -233,8 +221,7 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) bool ZONE_CREATE_HELPER::OnFirstPoint( POLYGON_GEOM_MANAGER& aMgr ) { // if we don't have a zone, create one - // the user's choice here can affect things like the colour - // of the preview + // the user's choice here can affect things like the colour of the preview if( !m_zone ) { m_tool.GetManager()->RunAction( PCB_ACTIONS::selectionClear, true ); @@ -255,18 +242,12 @@ bool ZONE_CREATE_HELPER::OnFirstPoint( POLYGON_GEOM_MANAGER& aMgr ) m_parentView.SetVisible( &m_previewItem, true ); - aMgr.SetLeaderMode( m_zone.get()->GetHV45() - ? POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 - : POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT ); + aMgr.SetLeaderMode( m_zone->GetHV45() ? POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 + : POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT ); } } - if( !m_zone ) - { - return false; - } - - return true; + return m_zone != nullptr; } @@ -295,9 +276,7 @@ void ZONE_CREATE_HELPER::OnComplete( const POLYGON_GEOM_MANAGER& aMgr ) auto* outline = m_zone->Outline(); for( int i = 0; i < finalPoints.PointCount(); ++i ) - { outline->Append( finalPoints.CPoint( i ) ); - } outline->Outline( 0 ).SetClosed( true ); outline->RemoveNullSegments();