Allow graphic polygons/keepouts to be closed automatically

ADDED: Auto close option for graphic polygons/keepouts/cutouts
ADDED: Delete last point option for graphic polygons/keepouts/cutouts

Fixes https://gitlab.com/kicad/code/kicad/issues/2350
This commit is contained in:
Ian McInerney 2020-04-24 18:34:05 +01:00
parent 3f9b3e505e
commit f649204c04
3 changed files with 21 additions and 13 deletions

View File

@ -79,19 +79,27 @@ DRAWING_TOOL::~DRAWING_TOOL()
bool DRAWING_TOOL::Init() bool DRAWING_TOOL::Init()
{ {
auto activeToolFunctor = [ this ] ( const SELECTION& aSel ) { auto activeToolFunctor = [ this ] ( const SELECTION& aSel )
{
return m_mode != MODE::NONE; return m_mode != MODE::NONE;
}; };
// some interactive drawing tools can undo the last point // some interactive drawing tools can undo the last point
auto canUndoPoint = [ this ] ( const SELECTION& aSel ) { auto canUndoPoint = [ this ] ( const SELECTION& aSel )
return m_mode == MODE::ARC || m_mode == MODE::ZONE; {
return ( m_mode == MODE::ARC
|| m_mode == MODE::ZONE
|| m_mode == MODE::KEEPOUT
|| m_mode == MODE::GRAPHIC_POLYGON );
}; };
// functor for zone-only actions // functor for tools that can automatically close the outline
auto zoneActiveFunctor = [this ] ( const SELECTION& aSel ) { auto canCloseOutline = [ this ] ( const SELECTION& aSel )
return m_mode == MODE::ZONE; {
}; return ( m_mode == MODE::ZONE
|| m_mode == MODE::KEEPOUT
|| m_mode == MODE::GRAPHIC_POLYGON );
};
auto& ctxMenu = m_menu.GetMenu(); auto& ctxMenu = m_menu.GetMenu();
@ -100,7 +108,7 @@ bool DRAWING_TOOL::Init()
ctxMenu.AddSeparator( 1 ); ctxMenu.AddSeparator( 1 );
// tool-specific actions // tool-specific actions
ctxMenu.AddItem( PCB_ACTIONS::closeZoneOutline, zoneActiveFunctor, 200 ); ctxMenu.AddItem( PCB_ACTIONS::closeOutline, canCloseOutline, 200 );
ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 ); ctxMenu.AddItem( PCB_ACTIONS::deleteLastPoint, canUndoPoint, 200 );
ctxMenu.AddSeparator( 500 ); ctxMenu.AddSeparator( 500 );
@ -1506,11 +1514,11 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
// events that lock in nodes // events that lock in nodes
else if( evt->IsClick( BUT_LEFT ) else if( evt->IsClick( BUT_LEFT )
|| evt->IsDblClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
|| evt->IsAction( &PCB_ACTIONS::closeZoneOutline ) ) || evt->IsAction( &PCB_ACTIONS::closeOutline ) )
{ {
// Check if it is double click / closing line (so we have to finish the zone) // Check if it is double click / closing line (so we have to finish the zone)
const bool endPolygon = evt->IsDblClick( BUT_LEFT ) const bool endPolygon = evt->IsDblClick( BUT_LEFT )
|| evt->IsAction( &PCB_ACTIONS::closeZoneOutline ) || evt->IsAction( &PCB_ACTIONS::closeOutline )
|| polyGeomMgr.NewPointClosesOutline( cursorPos ); || polyGeomMgr.NewPointClosesOutline( cursorPos );
if( endPolygon ) if( endPolygon )

View File

@ -158,9 +158,9 @@ TOOL_ACTION PCB_ACTIONS::deleteLastPoint( "pcbnew.InteractiveDrawing.deleteLastP
_( "Delete Last Point" ), _( "Delete the last point added to the current item" ), _( "Delete Last Point" ), _( "Delete the last point added to the current item" ),
undo_xpm ); undo_xpm );
TOOL_ACTION PCB_ACTIONS::closeZoneOutline( "pcbnew.InteractiveDrawing.closeZoneOutline", TOOL_ACTION PCB_ACTIONS::closeOutline( "pcbnew.InteractiveDrawing.closeOutline",
AS_CONTEXT, 0, "", AS_CONTEXT, 0, "",
_( "Close Zone Outline" ), _( "Close the outline of a zone in progress" ), _( "Close Outline" ), _( "Close the in progress outline" ),
checked_ok_xpm ); checked_ok_xpm );

View File

@ -150,7 +150,7 @@ public:
static TOOL_ACTION placeImportedGraphics; static TOOL_ACTION placeImportedGraphics;
static TOOL_ACTION setAnchor; static TOOL_ACTION setAnchor;
static TOOL_ACTION deleteLastPoint; static TOOL_ACTION deleteLastPoint;
static TOOL_ACTION closeZoneOutline; static TOOL_ACTION closeOutline;
/// Increase width of currently drawn line /// Increase width of currently drawn line
static TOOL_ACTION incWidth; static TOOL_ACTION incWidth;