From 06ac172c276fa22ec6ecc9c4ea8374dc79443548 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 15 Sep 2018 09:51:35 -0700 Subject: [PATCH] pcbnew: Add corners in polygons Allow corner adding to polygons in both module editor and board editor. The board editor was already allowed but only through special types. The module editor is now sychronized to the same process and both recognize standard context menus Fixes: lp:1782966 * https://bugs.launchpad.net/kicad/+bug/1782966 --- pcbnew/tools/point_editor.cpp | 45 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index a7fe7722a4..4fccadd49e 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -657,9 +657,18 @@ void POINT_EDITOR::updatePoints() case S_POLYGON: { const auto& points = segment->BuildPolyPointsList(); - for( unsigned i = 0; i < points.size(); i++ ) + + if( m_editPoints->PointsSize() != (unsigned) points.size() ) { - m_editPoints->Point( i ).SetPosition( points[i] ); + getView()->Remove( m_editPoints.get() ); + m_editedPoint = nullptr; + m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() ); + getView()->Add( m_editPoints.get() ); + } + else + { + for( unsigned i = 0; i < points.size(); i++ ) + m_editPoints->Point( i ).SetPosition( points[i] ); } break; } @@ -826,7 +835,8 @@ bool POINT_EDITOR::addCornerCondition( const SELECTION& aSelection ) // Works only for zones and line segments return item->Type() == PCB_ZONE_AREA_T || ( ( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) && - static_cast( item )->GetShape() == S_SEGMENT ); + ( static_cast( item )->GetShape() == S_SEGMENT || + static_cast( item )->GetShape() == S_POLYGON ) ); } @@ -887,17 +897,23 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition(); BOARD_COMMIT commit( frame ); - if( item->Type() == PCB_ZONE_AREA_T ) + bool moduleEdge = item->Type() == PCB_MODULE_EDGE_T; + + if( item->Type() == PCB_ZONE_AREA_T || + ( moduleEdge && static_cast( item )->GetShape() == S_POLYGON ) ) { - ZONE_CONTAINER* zone = static_cast( item ); - SHAPE_POLY_SET* zoneOutline = zone->Outline(); - - commit.Modify( zone ); - unsigned int nearestIdx = 0; unsigned int nextNearestIdx = 0; unsigned int nearestDist = INT_MAX; unsigned int firstPointInContour = 0; + SHAPE_POLY_SET* zoneOutline; + + if( moduleEdge ) + zoneOutline = &( static_cast( item )->GetPolyShape() ); + else + zoneOutline = static_cast( item )->Outline(); + + commit.Modify( item ); // Search the best outline segment to add a new corner // and therefore break this segment into two segments @@ -944,15 +960,18 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) // Add corner between nearestIdx and nextNearestIdx: zoneOutline->InsertVertex( nextNearestIdx, nearestPoint ); - zone->Hatch(); + + // In board editor, we re-hatch the zone item + if( !moduleEdge ) + static_cast( item )->Hatch(); + commit.Push( _( "Add a zone corner" ) ); } - else if( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) + else if( item->Type() == PCB_LINE_T || + ( moduleEdge && static_cast( item )->GetShape() == S_SEGMENT ) ) { - bool moduleEdge = item->Type() == PCB_MODULE_EDGE_T; - DRAWSEGMENT* segment = static_cast( item ); if( segment->GetShape() == S_SEGMENT )