From a25d091b6ca7670e7772e80a5716b85e1e3d41b4 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 2 Oct 2020 18:42:32 -0400 Subject: [PATCH] Add Convert Shapes tool to footprint editor --- pcbnew/class_zone.cpp | 21 +++++++---- pcbnew/footprint_edit_frame.cpp | 2 ++ pcbnew/tools/convert_tool.cpp | 43 +++++++++++++++++------ pcbnew/tools/convert_tool.h | 1 + pcbnew/tools/pcb_selection_conditions.cpp | 2 +- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index a10261c5ca..041c9518fe 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -642,15 +642,19 @@ void ZONE_CONTAINER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetActiveLayer() ) ) layer = pcbframe->GetActiveLayer(); #endif - auto layer_it = m_FilledPolysList.find( layer ); - if( layer_it == m_FilledPolysList.end() ) - layer_it = m_FilledPolysList.begin(); - - if( layer_it != m_FilledPolysList.end() ) + if( !GetIsRuleArea() ) { - msg.Printf( wxT( "%d" ), layer_it->second.TotalVertices() ); - aList.emplace_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg, BLUE ) ); + auto layer_it = m_FilledPolysList.find( layer ); + + if( layer_it == m_FilledPolysList.end() ) + layer_it = m_FilledPolysList.begin(); + + if( layer_it != m_FilledPolysList.end() ) + { + msg.Printf( wxT( "%d" ), layer_it->second.TotalVertices() ); + aList.emplace_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg, BLUE ) ); + } } } @@ -1313,6 +1317,9 @@ double MODULE_ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const if( !aView ) return 0; + if( !aView->IsLayerVisible( LAYER_ZONES ) ) + return HIDE; + bool flipped = GetParent() && GetParent()->GetLayer() == B_Cu; // Handle Render tab switches diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 93656641b3..498529be74 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -20,6 +20,7 @@ * with this program. If not, see . */ +#include "tools/convert_tool.h" #include "tools/drawing_tool.h" #include "tools/edit_tool.h" #include "tools/footprint_editor_tools.h" @@ -861,6 +862,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new PCBNEW_PICKER_TOOL ); m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL ); m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS ); + m_toolManager->RegisterTool( new CONVERT_TOOL ); m_toolManager->GetTool()->SetEditModules( true ); m_toolManager->GetTool()->SetEditModules( true ); diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index 31541f60c7..abc8661a13 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ bool CONVERT_TOOL::Init() m_menu->SetTitle( _( "Convert..." ) ); static KICAD_T convertableTracks[] = { PCB_TRACE_T, PCB_ARC_T, EOT }; + static KICAD_T convertableZones[] = { PCB_ZONE_AREA_T, PCB_MODULE_ZONE_AREA_T, EOT }; auto graphicLines = P_S_C::OnlyGraphicShapeTypes( { S_SEGMENT, S_RECT } ) && P_S_C::SameLayer(); @@ -76,16 +78,19 @@ bool CONVERT_TOOL::Init() auto anyLines = graphicLines || trackLines; - auto anyPolys = ( S_C::OnlyType( PCB_ZONE_AREA_T ) || + auto anyPolys = ( S_C::OnlyTypes( convertableZones ) || P_S_C::OnlyGraphicShapeTypes( { S_POLYGON, S_RECT } ) ); - auto lineToArc = P_S_C::OnlyGraphicShapeTypes( { S_SEGMENT } ) || - S_C::OnlyType( PCB_TRACE_T ); + auto lineToArc = S_C::Count( 1 ) && ( P_S_C::OnlyGraphicShapeTypes( { S_SEGMENT } ) || + S_C::OnlyType( PCB_TRACE_T ) ); auto showConvert = anyPolys || anyLines || lineToArc; m_menu->AddItem( PCB_ACTIONS::convertToPoly, anyLines ); - m_menu->AddItem( PCB_ACTIONS::convertToZone, anyLines ); + + if( m_frame->IsType( FRAME_PCB_EDITOR ) ) + m_menu->AddItem( PCB_ACTIONS::convertToZone, anyLines ); + m_menu->AddItem( PCB_ACTIONS::convertToKeepout, anyLines ); m_menu->AddItem( PCB_ACTIONS::convertToLines, anyPolys ); m_menu->AddItem( PCB_ACTIONS::convertToTracks, anyPolys ); @@ -94,7 +99,7 @@ bool CONVERT_TOOL::Init() for( std::shared_ptr& subMenu : m_selectionTool->GetToolMenu().GetSubMenus() ) { if( dynamic_cast( subMenu.get() ) ) - static_cast( subMenu.get() )->AddMenu( m_menu, showConvert ); + static_cast( subMenu.get() )->AddMenu( m_menu, SELECTION_CONDITIONS::ShowAlways ); } return true; @@ -103,6 +108,8 @@ bool CONVERT_TOOL::Init() int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) { + MODULE* mod = nullptr; + auto& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool ) { @@ -116,11 +123,12 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) switch( item->Type() ) { case PCB_LINE_T: + case PCB_MODULE_EDGE_T: switch( static_cast( item )->GetShape() ) { case S_SEGMENT: case S_RECT: - //case S_ARC: // Not yet + // case S_ARC: // Not yet break; default: @@ -154,6 +162,11 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) if( polySet.IsEmpty() ) return 0; + bool isFootprint = m_frame->IsType( FRAME_FOOTPRINT_EDITOR ); + + if( EDGE_MODULE* edge_mod = dynamic_cast( selection.Front() ) ) + mod = edge_mod->GetParentModule(); + BOARD_COMMIT commit( m_frame ); // For now, we convert each outline in the returned shape to its own polygon @@ -166,7 +179,7 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) { for( const SHAPE_POLY_SET& poly : polys ) { - DRAWSEGMENT* graphic = new DRAWSEGMENT; + DRAWSEGMENT* graphic = isFootprint ? new EDGE_MODULE( mod ) : new DRAWSEGMENT; graphic->SetShape( S_POLYGON ); graphic->SetLayer( destLayer ); @@ -196,7 +209,8 @@ int CONVERT_TOOL::LinesToPoly( const TOOL_EVENT& aEvent ) for( const SHAPE_POLY_SET& poly : polys ) { - ZONE_CONTAINER* zone = new ZONE_CONTAINER( parent ); + ZONE_CONTAINER* zone = isFootprint ? new MODULE_ZONE_CONTAINER( parent ) + : new ZONE_CONTAINER( parent ); *zone->Outline() = poly; zone->HatchBorder(); @@ -313,7 +327,7 @@ SHAPE_POLY_SET CONVERT_TOOL::makePolysFromRects( const std::deque& aI for( EDA_ITEM* item : aItems ) { - if( item->Type() != PCB_LINE_T ) + if( item->Type() != PCB_LINE_T && item->Type() != PCB_MODULE_EDGE_T ) continue; DRAWSEGMENT* graphic = static_cast( item ); @@ -353,6 +367,7 @@ int CONVERT_TOOL::PolyToLines( const TOOL_EVENT& aEvent ) switch( item->Type() ) { case PCB_LINE_T: + case PCB_MODULE_EDGE_T: switch( static_cast( item )->GetShape() ) { case S_POLYGON: @@ -368,6 +383,7 @@ int CONVERT_TOOL::PolyToLines( const TOOL_EVENT& aEvent ) break; case PCB_ZONE_AREA_T: + case PCB_MODULE_ZONE_AREA_T: break; default: @@ -387,10 +403,12 @@ int CONVERT_TOOL::PolyToLines( const TOOL_EVENT& aEvent ) switch( aItem->Type() ) { case PCB_ZONE_AREA_T: + case PCB_MODULE_ZONE_AREA_T: set = *static_cast( aItem )->Outline(); break; case PCB_LINE_T: + case PCB_MODULE_EDGE_T: { DRAWSEGMENT* graphic = static_cast( aItem ); @@ -506,7 +524,9 @@ int CONVERT_TOOL::SegmentToArc( const TOOL_EVENT& aEvent ) { BOARD_ITEM* item = aCollector[i]; - if( !( item->Type() == PCB_LINE_T || item->Type() == PCB_TRACE_T ) ) + if( !( item->Type() == PCB_LINE_T || + item->Type() == PCB_TRACE_T || + item->Type() == PCB_MODULE_EDGE_T ) ) aCollector.Remove( item ); } } ); @@ -541,7 +561,7 @@ int CONVERT_TOOL::SegmentToArc( const TOOL_EVENT& aEvent ) BOARD_COMMIT commit( m_frame ); - if( source->Type() == PCB_LINE_T ) + if( source->Type() == PCB_LINE_T || source->Type() == PCB_MODULE_EDGE_T ) { DRAWSEGMENT* line = static_cast( source ); DRAWSEGMENT* arc = new DRAWSEGMENT( parent ); @@ -585,6 +605,7 @@ OPT CONVERT_TOOL::getStartEndPoints( EDA_ITEM* aItem ) switch( aItem->Type() ) { case PCB_LINE_T: + case PCB_MODULE_EDGE_T: { DRAWSEGMENT* line = static_cast( aItem ); return boost::make_optional( { VECTOR2I( line->GetStart() ), diff --git a/pcbnew/tools/convert_tool.h b/pcbnew/tools/convert_tool.h index f744935312..c22434ccc0 100644 --- a/pcbnew/tools/convert_tool.h +++ b/pcbnew/tools/convert_tool.h @@ -25,6 +25,7 @@ #ifndef CONVERT_TOOL_H_ #define CONVERT_TOOL_H_ +#include #include class CONDITIONAL_MENU; diff --git a/pcbnew/tools/pcb_selection_conditions.cpp b/pcbnew/tools/pcb_selection_conditions.cpp index 99c202bd0c..c533f64260 100644 --- a/pcbnew/tools/pcb_selection_conditions.cpp +++ b/pcbnew/tools/pcb_selection_conditions.cpp @@ -144,7 +144,7 @@ bool PCB_SELECTION_CONDITIONS::onlyGraphicShapeTypesFunc( const SELECTION& aSele for( const EDA_ITEM* item : aSelection ) { - if( item->Type() != PCB_LINE_T ) + if( item->Type() != PCB_LINE_T && item->Type() != PCB_MODULE_EDGE_T ) return false; STROKE_T shape = static_cast( item )->GetShape();