2018-11-13 13:30:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-11-13 13:30:56 +00:00
|
|
|
* @author Jon Evans <jon@craftyjon.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bitmaps.h>
|
2022-07-29 19:56:55 +00:00
|
|
|
#include <dialog_shim.h>
|
|
|
|
#include <wx/statline.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/button.h>
|
2022-11-28 20:46:30 +00:00
|
|
|
#include <wx/radiobut.h>
|
2022-12-01 13:22:29 +00:00
|
|
|
#include <widgets/unit_binder.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-07-04 16:09:37 +00:00
|
|
|
#include <board_commit.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2018-11-13 13:30:56 +00:00
|
|
|
#include <collectors.h>
|
|
|
|
#include <confirm.h>
|
2021-07-04 16:09:37 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2022-01-05 02:28:04 +00:00
|
|
|
#include <footprint.h>
|
2021-07-04 16:09:37 +00:00
|
|
|
#include <footprint_edit_frame.h>
|
|
|
|
#include <geometry/shape_compound.h>
|
2018-11-13 13:30:56 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2021-07-04 16:09:37 +00:00
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_track.h>
|
2018-11-13 13:30:56 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/edit_tool.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2021-07-04 16:09:37 +00:00
|
|
|
#include <trigo.h>
|
2022-11-27 18:29:41 +00:00
|
|
|
#include <macros.h>
|
2021-07-04 16:09:37 +00:00
|
|
|
#include <zone.h>
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
#include "convert_tool.h"
|
|
|
|
|
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
class CONVERT_SETTINGS_DIALOG : public DIALOG_SHIM
|
|
|
|
{
|
|
|
|
public:
|
2022-12-01 13:27:59 +00:00
|
|
|
CONVERT_SETTINGS_DIALOG( EDA_DRAW_FRAME* aParent, CONVERT_SETTINGS* aSettings ) :
|
2022-07-29 19:56:55 +00:00
|
|
|
DIALOG_SHIM( aParent, wxID_ANY, _( "Conversion Settings" ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
|
2022-12-01 13:27:59 +00:00
|
|
|
m_settings( aSettings )
|
2022-07-29 19:56:55 +00:00
|
|
|
{
|
|
|
|
wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
SetSizer( mainSizer );
|
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
m_rbMimicLineWidth = new wxRadioButton( this, wxID_ANY, _( "Copy line width of first object" ) );
|
|
|
|
topSizer->Add( m_rbMimicLineWidth, 0, wxLEFT|wxRIGHT, 5 );
|
2022-07-29 19:56:55 +00:00
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
topSizer->AddSpacer( 6 );
|
2022-11-28 20:46:30 +00:00
|
|
|
m_rbCenterline = new wxRadioButton( this, wxID_ANY, _( "Use centerlines" ) );
|
|
|
|
topSizer->Add( m_rbCenterline, 0, wxLEFT|wxRIGHT, 5 );
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
topSizer->AddSpacer( 6 );
|
2022-11-28 20:46:30 +00:00
|
|
|
m_rbEnvelope = new wxRadioButton( this, wxID_ANY, _( "Create bounding hull" ) );
|
|
|
|
topSizer->Add( m_rbEnvelope, 0, wxLEFT|wxRIGHT, 5 );
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
m_gapLabel = new wxStaticText( this, wxID_ANY, _( "Gap:" ) );
|
|
|
|
m_gapCtrl = new wxTextCtrl( this, wxID_ANY );
|
|
|
|
m_gapUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
|
|
|
|
m_gap = new UNIT_BINDER( aParent, m_gapLabel, m_gapCtrl, m_gapUnits );
|
|
|
|
|
|
|
|
m_widthLabel = new wxStaticText( this, wxID_ANY, _( "Line width:" ) );
|
|
|
|
m_widthCtrl = new wxTextCtrl( this, wxID_ANY );
|
|
|
|
m_widthUnits = new wxStaticText( this, wxID_ANY, _( "mm" ) );
|
|
|
|
m_width = new UNIT_BINDER( aParent, m_widthLabel, m_widthCtrl, m_widthUnits );
|
|
|
|
|
|
|
|
wxBoxSizer* hullParamsSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
hullParamsSizer->Add( m_gapLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
|
|
|
|
hullParamsSizer->Add( m_gapCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
|
|
|
|
hullParamsSizer->Add( m_gapUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
|
|
|
|
hullParamsSizer->AddSpacer( 18 );
|
|
|
|
hullParamsSizer->Add( m_widthLabel, 0, wxALIGN_CENTRE_VERTICAL, 5 );
|
|
|
|
hullParamsSizer->Add( m_widthCtrl, 1, wxALIGN_CENTRE_VERTICAL|wxLEFT|wxRIGHT, 3 );
|
|
|
|
hullParamsSizer->Add( m_widthUnits, 0, wxALIGN_CENTRE_VERTICAL, 5 );
|
|
|
|
|
|
|
|
topSizer->AddSpacer( 2 );
|
|
|
|
topSizer->Add( hullParamsSizer, 0, wxLEFT, 26 );
|
|
|
|
|
|
|
|
topSizer->AddSpacer( 15 );
|
2022-11-28 20:46:30 +00:00
|
|
|
m_cbDeleteOriginals = new wxCheckBox( this, wxID_ANY, _( "Delete source objects after conversion" ) );
|
2022-07-29 19:56:55 +00:00
|
|
|
topSizer->Add( m_cbDeleteOriginals, 0, wxALL, 5 );
|
|
|
|
|
|
|
|
wxStaticLine* line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxLI_HORIZONTAL );
|
|
|
|
topSizer->Add( line, 0, wxLEFT|wxRIGHT|wxTOP|wxEXPAND, 5 );
|
|
|
|
|
|
|
|
mainSizer->Add( topSizer, 1, wxALL|wxEXPAND, 10 );
|
|
|
|
|
|
|
|
wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
buttonsSizer->AddStretchSpacer();
|
|
|
|
|
|
|
|
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
|
|
|
|
wxButton* sdbSizerOK = new wxButton( this, wxID_OK );
|
|
|
|
sdbSizer->AddButton( sdbSizerOK );
|
|
|
|
wxButton* sdbSizerCancel = new wxButton( this, wxID_CANCEL );
|
|
|
|
sdbSizer->AddButton( sdbSizerCancel );
|
|
|
|
sdbSizer->Realize();
|
|
|
|
|
|
|
|
buttonsSizer->Add( sdbSizer, 1, 0, 5 );
|
|
|
|
mainSizer->Add( buttonsSizer, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 5 );
|
|
|
|
|
|
|
|
SetupStandardButtons();
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
m_rbMimicLineWidth->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED,
|
|
|
|
wxCommandEventHandler( CONVERT_SETTINGS_DIALOG::onRadioButton ),
|
|
|
|
nullptr, this );
|
|
|
|
m_rbCenterline->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED,
|
|
|
|
wxCommandEventHandler( CONVERT_SETTINGS_DIALOG::onRadioButton ),
|
|
|
|
nullptr, this );
|
|
|
|
m_rbEnvelope->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED,
|
|
|
|
wxCommandEventHandler( CONVERT_SETTINGS_DIALOG::onRadioButton ),
|
|
|
|
nullptr, this );
|
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
finishDialogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
~CONVERT_SETTINGS_DIALOG()
|
2022-12-01 13:22:29 +00:00
|
|
|
{
|
|
|
|
delete m_gap;
|
|
|
|
delete m_width;
|
|
|
|
};
|
2022-07-29 19:56:55 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool TransferDataToWindow() override
|
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
switch( m_settings->m_Strategy )
|
|
|
|
{
|
|
|
|
case COPY_LINEWIDTH: m_rbMimicLineWidth->SetValue( true ); break;
|
|
|
|
case CENTERLINE: m_rbCenterline->SetValue( true ); break;
|
|
|
|
case BOUNDING_HULL: m_rbEnvelope->SetValue( true ); break;
|
|
|
|
}
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
m_gap->Enable( m_rbEnvelope->GetValue() );
|
|
|
|
m_width->Enable( m_rbEnvelope->GetValue() );
|
|
|
|
m_gap->SetValue( m_settings->m_Gap );
|
|
|
|
m_width->SetValue( m_settings->m_LineWidth );
|
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
m_cbDeleteOriginals->SetValue( m_settings->m_DeleteOriginals );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TransferDataFromWindow() override
|
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
if( m_rbEnvelope->GetValue() )
|
|
|
|
m_settings->m_Strategy = BOUNDING_HULL;
|
|
|
|
else if( m_rbCenterline->GetValue() )
|
|
|
|
m_settings->m_Strategy = CENTERLINE;
|
|
|
|
else
|
|
|
|
m_settings->m_Strategy = COPY_LINEWIDTH;
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
m_settings->m_Gap = m_gap->GetValue();
|
|
|
|
m_settings->m_LineWidth = m_width->GetValue();
|
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
m_settings->m_DeleteOriginals = m_cbDeleteOriginals->GetValue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
void onRadioButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_gap->Enable( m_rbEnvelope->GetValue() );
|
|
|
|
m_width->Enable( m_rbEnvelope->GetValue() );
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
private:
|
|
|
|
CONVERT_SETTINGS* m_settings;
|
2022-11-28 20:46:30 +00:00
|
|
|
|
|
|
|
wxRadioButton* m_rbMimicLineWidth;
|
|
|
|
wxRadioButton* m_rbCenterline;
|
|
|
|
wxRadioButton* m_rbEnvelope;
|
2022-12-01 13:22:29 +00:00
|
|
|
wxStaticText* m_gapLabel;
|
|
|
|
wxTextCtrl* m_gapCtrl;
|
|
|
|
wxStaticText* m_gapUnits;
|
|
|
|
UNIT_BINDER* m_gap;
|
|
|
|
wxStaticText* m_widthLabel;
|
|
|
|
wxTextCtrl* m_widthCtrl;
|
|
|
|
wxStaticText* m_widthUnits;
|
|
|
|
UNIT_BINDER* m_width;
|
2022-07-29 19:56:55 +00:00
|
|
|
wxCheckBox* m_cbDeleteOriginals;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
CONVERT_TOOL::CONVERT_TOOL() :
|
2020-11-07 17:35:24 +00:00
|
|
|
TOOL_INTERACTIVE( "pcbnew.Convert" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
m_selectionTool( nullptr ),
|
|
|
|
m_menu( nullptr ),
|
|
|
|
m_frame( nullptr )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2022-12-01 13:27:59 +00:00
|
|
|
m_userSettings.m_Strategy = CENTERLINE;
|
2022-12-01 13:22:29 +00:00
|
|
|
m_userSettings.m_Gap = 0;
|
2022-12-01 13:27:59 +00:00
|
|
|
m_userSettings.m_LineWidth = 0;
|
|
|
|
m_userSettings.m_DeleteOriginals = true;
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
CONVERT_TOOL::~CONVERT_TOOL()
|
|
|
|
{
|
|
|
|
delete m_menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
using S_C = SELECTION_CONDITIONS;
|
|
|
|
using P_S_C = PCB_SELECTION_CONDITIONS;
|
|
|
|
|
|
|
|
|
|
|
|
bool CONVERT_TOOL::Init()
|
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
m_selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2020-08-31 13:19:57 +00:00
|
|
|
m_frame = getEditFrame<PCB_BASE_FRAME>();
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
// Create a context menu and make it available through selection tool
|
|
|
|
m_menu = new CONDITIONAL_MENU( this );
|
2021-03-08 02:59:07 +00:00
|
|
|
m_menu->SetIcon( BITMAPS::convert );
|
2021-07-19 22:45:33 +00:00
|
|
|
m_menu->SetTitle( _( "Create from Selection" ) );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-08-23 10:57:07 +00:00
|
|
|
auto graphicLines = S_C::OnlyTypes( { PCB_SHAPE_LOCATE_SEGMENT_T, PCB_SHAPE_LOCATE_RECT_T,
|
2022-10-31 19:48:23 +00:00
|
|
|
PCB_SHAPE_LOCATE_CIRCLE_T, PCB_SHAPE_LOCATE_ARC_T,
|
|
|
|
PCB_SHAPE_LOCATE_BEZIER_T } )
|
2021-01-06 17:20:54 +00:00
|
|
|
&& P_S_C::SameLayer();
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-08-23 10:57:07 +00:00
|
|
|
auto graphicToTrack = S_C::OnlyTypes( { PCB_SHAPE_LOCATE_SEGMENT_T, PCB_SHAPE_LOCATE_ARC_T } );
|
2021-09-29 01:00:15 +00:00
|
|
|
|
2022-12-01 15:13:45 +00:00
|
|
|
auto anyTracks = S_C::MoreThan( 0 ) && S_C::OnlyTypes( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } )
|
2022-08-20 09:27:35 +00:00
|
|
|
&& P_S_C::SameLayer();
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
auto anyPolys = S_C::OnlyTypes( { PCB_ZONE_T, PCB_SHAPE_LOCATE_POLY_T, PCB_SHAPE_LOCATE_RECT_T } );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-12-01 15:13:45 +00:00
|
|
|
auto canCreateArcs = S_C::Count( 1 )
|
|
|
|
&& S_C::OnlyTypes( { PCB_TRACE_T, PCB_SHAPE_LOCATE_SEGMENT_T } );
|
|
|
|
auto canCreateArray = S_C::MoreThan( 0 );
|
|
|
|
auto canCreatePolyType = graphicLines || anyPolys || anyTracks;
|
|
|
|
auto canCreateLines = anyPolys;
|
2021-09-29 01:00:15 +00:00
|
|
|
auto canCreateTracks = anyPolys || graphicToTrack;
|
2022-12-01 15:13:45 +00:00
|
|
|
auto canCreate = canCreatePolyType
|
|
|
|
|| canCreateLines
|
|
|
|
|| canCreateTracks
|
|
|
|
|| canCreateArcs
|
|
|
|
|| canCreateArray;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-08-09 00:28:47 +00:00
|
|
|
m_menu->AddItem( PCB_ACTIONS::convertToPoly, canCreatePolyType );
|
|
|
|
m_menu->AddItem( PCB_ACTIONS::convertToZone, canCreatePolyType );
|
|
|
|
m_menu->AddItem( PCB_ACTIONS::convertToKeepout, canCreatePolyType );
|
2022-12-01 15:13:45 +00:00
|
|
|
m_menu->AddItem( PCB_ACTIONS::convertToLines, canCreateLines );
|
2022-09-03 18:29:02 +00:00
|
|
|
m_menu->AppendSeparator();
|
2020-10-25 12:25:46 +00:00
|
|
|
|
|
|
|
// Currently the code exists, but tracks are not really existing in footprints
|
|
|
|
// only segments on copper layers
|
|
|
|
if( m_frame->IsType( FRAME_PCB_EDITOR ) )
|
2021-09-29 01:00:15 +00:00
|
|
|
m_menu->AddItem( PCB_ACTIONS::convertToTracks, canCreateTracks );
|
2020-10-25 12:25:46 +00:00
|
|
|
|
2022-12-01 15:13:45 +00:00
|
|
|
m_menu->AddItem( PCB_ACTIONS::convertToArc, canCreateArcs );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-09-07 08:47:44 +00:00
|
|
|
m_menu->AppendSeparator();
|
|
|
|
m_menu->AddItem( PCB_ACTIONS::createArray, canCreateArray );
|
|
|
|
|
2021-01-06 16:39:28 +00:00
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
2022-12-01 15:13:45 +00:00
|
|
|
selToolMenu.AddMenu( m_menu, canCreate, 100 );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-09 00:28:47 +00:00
|
|
|
int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2022-07-29 19:56:55 +00:00
|
|
|
std::vector<SHAPE_POLY_SET> polys;
|
|
|
|
PCB_LAYER_ID destLayer = m_frame->GetActiveLayer();
|
|
|
|
FOOTPRINT* parentFootprint = nullptr;
|
2022-11-28 20:46:30 +00:00
|
|
|
|
2022-07-27 16:15:36 +00:00
|
|
|
PCB_SELECTION& selection = m_selectionTool->RequestSelection(
|
2020-12-16 13:31:32 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2020-11-07 17:35:24 +00:00
|
|
|
} );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
auto getPolys =
|
2022-12-01 13:27:59 +00:00
|
|
|
[&]( CONVERT_SETTINGS cfg )
|
2022-07-29 19:56:55 +00:00
|
|
|
{
|
|
|
|
polys.clear();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
item->ClearTempFlags();
|
|
|
|
|
|
|
|
SHAPE_POLY_SET polySet;
|
2022-11-27 18:29:41 +00:00
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
polySet.Append( makePolysFromClosedGraphics( selection.GetItems(), cfg.m_Strategy ) );
|
2022-11-27 18:29:41 +00:00
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
polySet.Append( makePolysFromChainedSegs( selection.GetItems(), cfg.m_Strategy ) );
|
2022-07-29 19:56:55 +00:00
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
if( cfg.m_Strategy == BOUNDING_HULL )
|
2022-12-01 13:22:29 +00:00
|
|
|
polySet.Append( makePolysFromOpenGraphics( selection.GetItems(), cfg.m_Gap ) );
|
2022-07-29 19:56:55 +00:00
|
|
|
|
|
|
|
if( polySet.IsEmpty() )
|
|
|
|
return false;
|
|
|
|
|
2022-12-12 12:54:00 +00:00
|
|
|
if( cfg.m_Strategy == BOUNDING_HULL )
|
|
|
|
{
|
|
|
|
polySet.ClearArcs();
|
|
|
|
polySet.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
}
|
2022-07-29 19:56:55 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < polySet.OutlineCount(); ++ii )
|
|
|
|
{
|
|
|
|
polys.emplace_back( SHAPE_POLY_SET( polySet.COutline( ii ) ) );
|
|
|
|
|
|
|
|
for( int jj = 0; jj < polySet.HoleCount( ii ); ++jj )
|
|
|
|
polys.back().AddHole( polySet.Hole( ii, jj ) );
|
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
return true;
|
|
|
|
};
|
2021-01-06 17:20:54 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
// Pre-flight getPolys() to see if there's anything to convert.
|
2022-12-01 13:27:59 +00:00
|
|
|
CONVERT_SETTINGS preflightSettings = m_userSettings;
|
|
|
|
preflightSettings.m_Strategy = BOUNDING_HULL;
|
|
|
|
|
|
|
|
if( !getPolys( preflightSettings ) )
|
2018-11-13 13:30:56 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selection.Front() ) )
|
|
|
|
parentFootprint = item->GetParentFootprint();
|
2020-10-02 22:42:32 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
|
|
|
|
PCB_LAYER_ID layer = m_frame->GetActiveLayer();
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::convertToPoly ) )
|
2022-07-27 16:15:36 +00:00
|
|
|
{
|
2022-12-01 13:27:59 +00:00
|
|
|
CONVERT_SETTINGS_DIALOG dlg( m_frame, &m_userSettings );
|
2022-07-27 16:15:36 +00:00
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return 0;
|
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
CONVERT_SETTINGS resolvedSettings = m_userSettings;
|
|
|
|
|
|
|
|
if( resolvedSettings.m_LineWidth == 0 )
|
|
|
|
resolvedSettings.m_LineWidth = bds.m_LineThickness[ bds.GetLayerClass( layer ) ];
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
if( resolvedSettings.m_Strategy == BOUNDING_HULL )
|
|
|
|
{
|
|
|
|
if( resolvedSettings.m_Gap > 0 )
|
|
|
|
resolvedSettings.m_Gap += KiROUND( (double) resolvedSettings.m_LineWidth / 2 );
|
|
|
|
}
|
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
if( !getPolys( resolvedSettings ) )
|
2022-07-29 19:56:55 +00:00
|
|
|
return 0;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
for( const SHAPE_POLY_SET& poly : polys )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* graphic = new PCB_SHAPE( parentFootprint );
|
2022-11-28 20:46:30 +00:00
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
if( resolvedSettings.m_Strategy == COPY_LINEWIDTH )
|
2022-11-28 20:46:30 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM* topLeftItem = nullptr;
|
|
|
|
VECTOR2I pos;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
if( BOARD_ITEM* candidate = dynamic_cast<BOARD_ITEM*>( item ) )
|
|
|
|
{
|
|
|
|
if( candidate->HasLineStroke() )
|
|
|
|
{
|
|
|
|
pos = candidate->GetPosition();
|
|
|
|
|
|
|
|
if( !topLeftItem
|
|
|
|
|| ( pos.x < topLeftItem->GetPosition().x )
|
|
|
|
|| ( topLeftItem->GetPosition().x == pos.x
|
|
|
|
&& pos.y < topLeftItem->GetPosition().y ) )
|
|
|
|
{
|
|
|
|
topLeftItem = candidate;
|
2022-12-01 13:27:59 +00:00
|
|
|
resolvedSettings.m_LineWidth = topLeftItem->GetStroke().GetWidth();
|
2022-11-28 20:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
graphic->SetShape( SHAPE_T::POLY );
|
2022-12-01 13:27:59 +00:00
|
|
|
graphic->SetStroke( STROKE_PARAMS( resolvedSettings.m_LineWidth, PLOT_DASH_TYPE::SOLID,
|
|
|
|
COLOR4D::UNSPECIFIED ) );
|
2018-11-13 13:30:56 +00:00
|
|
|
graphic->SetLayer( destLayer );
|
|
|
|
graphic->SetPolyShape( poly );
|
|
|
|
|
|
|
|
commit.Add( graphic );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Creating zone or keepout
|
|
|
|
PCB_BASE_EDIT_FRAME* frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
BOARD_ITEM_CONTAINER* parent = frame->GetModel();
|
|
|
|
ZONE_SETTINGS zoneInfo = frame->GetZoneSettings();
|
|
|
|
|
2021-06-20 19:13:18 +00:00
|
|
|
bool nonCopper = IsNonCopperLayer( destLayer );
|
|
|
|
zoneInfo.m_Layers.reset().set( destLayer );
|
2021-12-09 23:20:30 +00:00
|
|
|
zoneInfo.m_Name.Empty();
|
2021-06-20 19:13:18 +00:00
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
int ret;
|
|
|
|
|
2022-11-30 14:27:40 +00:00
|
|
|
// No copy-line-width option for zones/keepouts
|
2022-12-01 13:27:59 +00:00
|
|
|
if( m_userSettings.m_Strategy == COPY_LINEWIDTH )
|
|
|
|
m_userSettings.m_Strategy = CENTERLINE;
|
2022-11-30 14:27:40 +00:00
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::convertToKeepout ) )
|
2021-12-09 23:20:30 +00:00
|
|
|
{
|
|
|
|
zoneInfo.SetIsRuleArea( true );
|
2022-12-01 13:27:59 +00:00
|
|
|
ret = InvokeRuleAreaEditor( frame, &zoneInfo, &m_userSettings );
|
2021-12-09 23:20:30 +00:00
|
|
|
}
|
2021-06-20 19:13:18 +00:00
|
|
|
else if( nonCopper )
|
2021-12-09 23:20:30 +00:00
|
|
|
{
|
|
|
|
zoneInfo.SetIsRuleArea( false );
|
2022-12-01 13:27:59 +00:00
|
|
|
ret = InvokeNonCopperZonesEditor( frame, &zoneInfo, &m_userSettings );
|
2021-12-09 23:20:30 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
else
|
2021-12-09 23:20:30 +00:00
|
|
|
{
|
|
|
|
zoneInfo.SetIsRuleArea( false );
|
2022-12-01 13:27:59 +00:00
|
|
|
ret = InvokeCopperZonesEditor( frame, &zoneInfo, &m_userSettings );
|
2021-12-09 23:20:30 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
if( ret == wxID_CANCEL )
|
|
|
|
return 0;
|
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
if( !getPolys( m_userSettings ) )
|
2022-07-29 19:56:55 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
for( const SHAPE_POLY_SET& poly : polys )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
ZONE* zone = new ZONE( parent );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
*zone->Outline() = poly;
|
|
|
|
zone->HatchBorder();
|
|
|
|
|
|
|
|
zoneInfo.ExportSetting( *zone );
|
|
|
|
|
|
|
|
commit.Add( zone );
|
|
|
|
}
|
2022-07-29 19:56:55 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-12-01 13:27:59 +00:00
|
|
|
if( m_userSettings.m_DeleteOriginals )
|
2022-07-29 19:56:55 +00:00
|
|
|
{
|
2022-11-11 17:52:36 +00:00
|
|
|
PCB_SELECTION selectionCopy = selection;
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selectionCopy )
|
2022-07-29 19:56:55 +00:00
|
|
|
{
|
|
|
|
if( item->GetFlags() & SKIP_STRUCT )
|
|
|
|
commit.Remove( item );
|
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 19:56:55 +00:00
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::convertToPoly ) )
|
|
|
|
commit.Push( _( "Convert shapes to polygon" ) );
|
|
|
|
else
|
|
|
|
commit.Push( _( "Convert shapes to zone" ) );
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
SHAPE_POLY_SET CONVERT_TOOL::makePolysFromChainedSegs( const std::deque<EDA_ITEM*>& aItems,
|
|
|
|
CONVERT_STRATEGY aStrategy )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2021-08-13 00:17:04 +00:00
|
|
|
// TODO: This code has a somewhat-similar purpose to ConvertOutlineToPolygon but is slightly
|
|
|
|
// different, so this remains a separate algorithm. It might be nice to analyze the dfiferences
|
|
|
|
// in requirements and refactor this.
|
2021-12-09 02:04:23 +00:00
|
|
|
|
2022-11-30 13:25:28 +00:00
|
|
|
// Using a large epsilon here to allow for sloppy drawing can cause the algorithm to miss very
|
|
|
|
// short segments in a converted bezier. So use an epsilon only large enough to cover for
|
|
|
|
// rouding errors in the conversion.
|
|
|
|
int chainingEpsilon = 100; // max dist from one endPt to next startPt in IU
|
2021-08-13 00:17:04 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
|
|
|
|
SHAPE_POLY_SET poly;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
// Stores pairs of (anchor, item) where anchor == 0 -> SEG.A, anchor == 1 -> SEG.B
|
|
|
|
std::map<VECTOR2I, std::vector<std::pair<int, EDA_ITEM*>>> connections;
|
2018-11-13 13:30:56 +00:00
|
|
|
std::deque<EDA_ITEM*> toCheck;
|
|
|
|
|
2021-08-13 00:17:04 +00:00
|
|
|
auto closeEnough =
|
2022-11-28 20:46:30 +00:00
|
|
|
[]( VECTOR2I aLeft, VECTOR2I aRight, int aLimit )
|
2021-08-13 00:17:04 +00:00
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
return ( aLeft - aRight ).SquaredEuclideanNorm() <= SEG::Square( aLimit );
|
2021-08-13 00:17:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto findInsertionPoint =
|
|
|
|
[&]( VECTOR2I aPoint ) -> VECTOR2I
|
|
|
|
{
|
2021-12-09 02:04:23 +00:00
|
|
|
if( connections.count( aPoint ) )
|
|
|
|
return aPoint;
|
|
|
|
|
2021-08-13 00:17:04 +00:00
|
|
|
for( const auto& candidatePair : connections )
|
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
if( closeEnough( aPoint, candidatePair.first, chainingEpsilon ) )
|
2021-08-13 00:17:04 +00:00
|
|
|
return candidatePair.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aPoint;
|
|
|
|
};
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
for( EDA_ITEM* item : aItems )
|
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
if( std::optional<SEG> seg = getStartEndPoints( item ) )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
|
|
|
toCheck.push_back( item );
|
2021-08-13 00:17:04 +00:00
|
|
|
connections[findInsertionPoint( seg->A )].emplace_back( std::make_pair( 0, item ) );
|
|
|
|
connections[findInsertionPoint( seg->B )].emplace_back( std::make_pair( 1, item ) );
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while( !toCheck.empty() )
|
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
std::vector<BOARD_ITEM*> insertedItems;
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
EDA_ITEM* candidate = toCheck.front();
|
|
|
|
toCheck.pop_front();
|
|
|
|
|
2022-07-27 16:15:36 +00:00
|
|
|
if( candidate->GetFlags() & SKIP_STRUCT )
|
2018-11-13 13:30:56 +00:00
|
|
|
continue;
|
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
SHAPE_LINE_CHAIN outline;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
auto insert =
|
|
|
|
[&]( EDA_ITEM* aItem, VECTOR2I aAnchor, bool aDirection )
|
|
|
|
{
|
2021-10-10 15:25:19 +00:00
|
|
|
if( aItem->Type() == PCB_ARC_T
|
2023-03-30 11:49:23 +00:00
|
|
|
|| ( aItem->Type() == PCB_SHAPE_T
|
2021-10-10 15:25:19 +00:00
|
|
|
&& static_cast<PCB_SHAPE*>( aItem )->GetShape() == SHAPE_T::ARC ) )
|
2021-07-04 16:09:37 +00:00
|
|
|
{
|
|
|
|
SHAPE_ARC arc;
|
|
|
|
|
|
|
|
if( aItem->Type() == PCB_ARC_T )
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
PCB_ARC* pcb_arc = static_cast<PCB_ARC*>( aItem );
|
|
|
|
arc = *static_cast<SHAPE_ARC*>( pcb_arc->GetEffectiveShape().get() );
|
2021-07-04 16:09:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
PCB_SHAPE* pcb_shape = static_cast<PCB_SHAPE*>( aItem );
|
|
|
|
arc = SHAPE_ARC( pcb_shape->GetStart(), pcb_shape->GetArcMid(),
|
|
|
|
pcb_shape->GetEnd(), pcb_shape->GetWidth() );
|
2021-07-04 16:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aDirection )
|
|
|
|
outline.Append( aAnchor == arc.GetP0() ? arc : arc.Reversed() );
|
|
|
|
else
|
|
|
|
outline.Insert( 0, aAnchor == arc.GetP0() ? arc : arc.Reversed() );
|
2022-11-28 20:46:30 +00:00
|
|
|
|
|
|
|
insertedItems.push_back( static_cast<BOARD_ITEM*>( aItem ) );
|
2021-07-04 16:09:37 +00:00
|
|
|
}
|
2022-10-31 19:48:23 +00:00
|
|
|
else if( aItem->IsType( { PCB_SHAPE_LOCATE_BEZIER_T } ) )
|
|
|
|
{
|
|
|
|
PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( aItem );
|
|
|
|
|
|
|
|
if( aAnchor == graphic->GetStart() )
|
|
|
|
{
|
|
|
|
for( auto it = graphic->GetBezierPoints().begin();
|
|
|
|
it != graphic->GetBezierPoints().end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( aDirection )
|
|
|
|
outline.Append( *it );
|
|
|
|
else
|
|
|
|
outline.Insert( 0, *it );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( auto it = graphic->GetBezierPoints().rbegin();
|
|
|
|
it != graphic->GetBezierPoints().rend();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
if( aDirection )
|
|
|
|
outline.Append( *it );
|
|
|
|
else
|
|
|
|
outline.Insert( 0, *it );
|
|
|
|
}
|
|
|
|
}
|
2022-11-28 20:46:30 +00:00
|
|
|
|
|
|
|
insertedItems.push_back( static_cast<BOARD_ITEM*>( aItem ) );
|
2022-10-31 19:48:23 +00:00
|
|
|
}
|
2022-11-28 20:46:30 +00:00
|
|
|
else if( std::optional<SEG> nextSeg = getStartEndPoints( aItem ) )
|
2021-07-04 16:09:37 +00:00
|
|
|
{
|
|
|
|
VECTOR2I& point = ( aAnchor == nextSeg->A ) ? nextSeg->B : nextSeg->A;
|
|
|
|
|
|
|
|
if( aDirection )
|
|
|
|
outline.Append( point );
|
|
|
|
else
|
|
|
|
outline.Insert( 0, point );
|
2022-11-28 20:46:30 +00:00
|
|
|
|
|
|
|
insertedItems.push_back( static_cast<BOARD_ITEM*>( aItem ) );
|
2021-07-04 16:09:37 +00:00
|
|
|
}
|
|
|
|
};
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
// aDirection == true for walking "right" and appending to the end of points
|
|
|
|
// false for walking "left" and prepending to the beginning
|
2021-07-04 16:09:37 +00:00
|
|
|
std::function<void( EDA_ITEM*, VECTOR2I, bool )> process =
|
|
|
|
[&]( EDA_ITEM* aItem, VECTOR2I aAnchor, bool aDirection )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2022-07-27 16:15:36 +00:00
|
|
|
if( aItem->GetFlags() & SKIP_STRUCT )
|
2018-11-13 13:30:56 +00:00
|
|
|
return;
|
|
|
|
|
2022-07-27 16:15:36 +00:00
|
|
|
aItem->SetFlags( SKIP_STRUCT );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
insert( aItem, aAnchor, aDirection );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
std::optional<SEG> anchors = getStartEndPoints( aItem );
|
2021-07-04 16:09:37 +00:00
|
|
|
wxASSERT( anchors );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
VECTOR2I nextAnchor = ( aAnchor == anchors->A ) ? anchors->B : anchors->A;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
for( std::pair<int, EDA_ITEM*> pair : connections[nextAnchor] )
|
|
|
|
{
|
|
|
|
if( pair.second == aItem )
|
|
|
|
continue;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
process( pair.second, nextAnchor, aDirection );
|
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
};
|
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
std::optional<SEG> anchors = getStartEndPoints( candidate );
|
2021-07-04 16:09:37 +00:00
|
|
|
wxASSERT( anchors );
|
|
|
|
|
|
|
|
// Start with the first object and walk "right"
|
2021-07-04 16:22:52 +00:00
|
|
|
// Note if the first object is an arc, we don't need to insert its first point here, the
|
|
|
|
// whole arc will be inserted at anchor B inside process()
|
2021-10-10 15:25:19 +00:00
|
|
|
if( !( candidate->Type() == PCB_ARC_T
|
2023-03-30 11:49:23 +00:00
|
|
|
|| ( candidate->Type() == PCB_SHAPE_T
|
2021-10-10 15:25:19 +00:00
|
|
|
&& static_cast<PCB_SHAPE*>( candidate )->GetShape() == SHAPE_T::ARC ) ) )
|
2021-07-04 16:22:52 +00:00
|
|
|
{
|
|
|
|
insert( candidate, anchors->A, true );
|
|
|
|
}
|
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
process( candidate, anchors->B, true );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
// check for any candidates on the "left"
|
|
|
|
EDA_ITEM* left = nullptr;
|
|
|
|
|
2021-07-04 16:09:37 +00:00
|
|
|
for( std::pair<int, EDA_ITEM*> possibleLeft : connections[anchors->A] )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2021-07-04 16:09:37 +00:00
|
|
|
if( possibleLeft.second != candidate )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2021-07-04 16:09:37 +00:00
|
|
|
left = possibleLeft.second;
|
2018-11-13 13:30:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( left )
|
2021-07-04 16:09:37 +00:00
|
|
|
process( left, anchors->A, false );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
if( outline.PointCount() < 3
|
|
|
|
|| !closeEnough( outline.GetPoint( 0 ), outline.GetPoint( -1 ), chainingEpsilon ) )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : insertedItems )
|
|
|
|
item->ClearFlags( SKIP_STRUCT );
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
continue;
|
2022-11-28 20:46:30 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
outline.SetClosed( true );
|
|
|
|
|
|
|
|
poly.AddOutline( outline );
|
2022-11-28 20:46:30 +00:00
|
|
|
|
|
|
|
if( aStrategy == BOUNDING_HULL )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : insertedItems )
|
|
|
|
{
|
|
|
|
item->TransformShapeToPolygon( poly, UNDEFINED_LAYER, 0, bds.m_MaxError,
|
|
|
|
ERROR_INSIDE, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
insertedItems.clear();
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return poly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
SHAPE_POLY_SET CONVERT_TOOL::makePolysFromOpenGraphics( const std::deque<EDA_ITEM*>& aItems,
|
|
|
|
int aGap )
|
2022-11-27 18:29:41 +00:00
|
|
|
{
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
|
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : aItems )
|
|
|
|
{
|
|
|
|
if( item->GetFlags() & SKIP_STRUCT )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_SHAPE_T:
|
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
|
2022-11-27 18:29:41 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
if( shape->IsClosed() )
|
2022-11-27 18:29:41 +00:00
|
|
|
continue;
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
shape->TransformShapeToPolygon( poly, UNDEFINED_LAYER, aGap, bds.m_MaxError,
|
2022-12-01 13:27:59 +00:00
|
|
|
ERROR_INSIDE, false );
|
2022-11-28 20:46:30 +00:00
|
|
|
shape->SetFlags( SKIP_STRUCT );
|
|
|
|
|
2022-11-27 18:29:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-12-01 12:04:39 +00:00
|
|
|
case PCB_TRACE_T:
|
|
|
|
case PCB_ARC_T:
|
|
|
|
case PCB_VIA_T:
|
|
|
|
{
|
|
|
|
PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
|
|
|
|
|
2022-12-01 13:22:29 +00:00
|
|
|
track->TransformShapeToPolygon( poly, UNDEFINED_LAYER, aGap, bds.m_MaxError,
|
2022-12-01 13:27:59 +00:00
|
|
|
ERROR_INSIDE, false );
|
2022-12-01 12:04:39 +00:00
|
|
|
track->SetFlags( SKIP_STRUCT );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-27 18:29:41 +00:00
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return poly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SHAPE_POLY_SET CONVERT_TOOL::makePolysFromClosedGraphics( const std::deque<EDA_ITEM*>& aItems,
|
2022-11-28 20:46:30 +00:00
|
|
|
CONVERT_STRATEGY aStrategy )
|
2021-01-06 17:20:54 +00:00
|
|
|
{
|
2022-07-27 16:15:36 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
|
|
|
|
SHAPE_POLY_SET poly;
|
2021-01-06 17:20:54 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : aItems )
|
|
|
|
{
|
2022-07-27 16:15:36 +00:00
|
|
|
if( item->GetFlags() & SKIP_STRUCT )
|
2021-01-06 17:20:54 +00:00
|
|
|
continue;
|
|
|
|
|
2021-08-09 00:28:47 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_SHAPE_T:
|
2022-07-27 16:15:36 +00:00
|
|
|
{
|
2022-11-28 20:46:30 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
|
|
|
|
FILL_T wasFilled = shape->GetFillMode();
|
2022-07-29 19:56:55 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
if( !shape->IsClosed() )
|
2022-11-27 18:29:41 +00:00
|
|
|
continue;
|
2021-08-09 00:28:47 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
shape->SetFilled( true );
|
|
|
|
shape->TransformShapeToPolygon( poly, UNDEFINED_LAYER, 0, bds.m_MaxError, ERROR_INSIDE,
|
|
|
|
aStrategy == COPY_LINEWIDTH || aStrategy == CENTERLINE );
|
|
|
|
shape->SetFillMode( wasFilled );
|
|
|
|
shape->SetFlags( SKIP_STRUCT );
|
|
|
|
|
2021-08-09 00:28:47 +00:00
|
|
|
break;
|
2022-07-27 16:15:36 +00:00
|
|
|
}
|
2021-08-09 00:28:47 +00:00
|
|
|
|
|
|
|
case PCB_ZONE_T:
|
|
|
|
poly.Append( *static_cast<ZONE*>( item )->Outline() );
|
2022-07-29 19:56:55 +00:00
|
|
|
item->SetFlags( SKIP_STRUCT );
|
2021-08-09 00:28:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return poly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CONVERT_TOOL::CreateLines( const TOOL_EVENT& aEvent )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
2020-12-16 13:31:32 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2020-11-07 17:35:24 +00:00
|
|
|
for( int i = aCollector.GetCount() - 1; i >= 0; --i )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2020-11-07 17:35:24 +00:00
|
|
|
BOARD_ITEM* item = aCollector[i];
|
|
|
|
|
|
|
|
switch( item->Type() )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2020-11-07 17:35:24 +00:00
|
|
|
case PCB_SHAPE_T:
|
|
|
|
switch( static_cast<PCB_SHAPE*>( item )->GetShape() )
|
|
|
|
{
|
2021-09-29 01:00:15 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
|
|
|
case SHAPE_T::ARC:
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
|
|
|
case SHAPE_T::RECT:
|
2020-11-07 17:35:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2020-09-08 12:41:22 +00:00
|
|
|
break;
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
default:
|
|
|
|
aCollector.Remove( item );
|
|
|
|
}
|
|
|
|
}
|
2021-01-09 00:46:18 +00:00
|
|
|
} );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
auto getPolySet =
|
|
|
|
[]( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET set;
|
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
|
|
|
set = *static_cast<ZONE*>( aItem )->Outline();
|
2018-11-13 13:30:56 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2020-09-08 12:41:22 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( aItem );
|
2020-09-08 12:41:22 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
if( graphic->GetShape() == SHAPE_T::POLY )
|
2020-09-08 12:41:22 +00:00
|
|
|
{
|
|
|
|
set = graphic->GetPolyShape();
|
|
|
|
}
|
2021-07-21 18:31:25 +00:00
|
|
|
else if( graphic->GetShape() == SHAPE_T::RECT )
|
2020-09-08 12:41:22 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN outline;
|
|
|
|
VECTOR2I start( graphic->GetStart() );
|
|
|
|
VECTOR2I end( graphic->GetEnd() );
|
|
|
|
|
|
|
|
outline.Append( start );
|
|
|
|
outline.Append( VECTOR2I( end.x, start.y ) );
|
|
|
|
outline.Append( end );
|
|
|
|
outline.Append( VECTOR2I( start.x, end.y ) );
|
|
|
|
outline.SetClosed( true );
|
|
|
|
|
|
|
|
set.AddOutline( outline );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-05 13:25:43 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unhandled graphic shape type in PolyToLines - getPolySet" ) );
|
2020-09-08 12:41:22 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
break;
|
2020-09-08 12:41:22 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
default:
|
2022-02-05 13:25:43 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unhandled type in PolyToLines - getPolySet" ) );
|
2018-11-13 13:30:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return set;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto getSegList =
|
|
|
|
[]( SHAPE_POLY_SET& aPoly )
|
|
|
|
{
|
|
|
|
std::vector<SEG> segs;
|
|
|
|
|
|
|
|
// Our input should be valid polys, so OK to assert here
|
|
|
|
wxASSERT( aPoly.VertexCount() >= 2 );
|
|
|
|
|
|
|
|
for( int i = 1; i < aPoly.VertexCount(); i++ )
|
|
|
|
segs.emplace_back( SEG( aPoly.CVertex( i - 1 ), aPoly.CVertex( i ) ) );
|
|
|
|
|
|
|
|
segs.emplace_back( SEG( aPoly.CVertex( aPoly.VertexCount() - 1 ),
|
|
|
|
aPoly.CVertex( 0 ) ) );
|
|
|
|
|
|
|
|
return segs;
|
|
|
|
};
|
|
|
|
|
2021-07-10 11:04:50 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2021-09-29 01:00:15 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2021-08-08 19:12:23 +00:00
|
|
|
FOOTPRINT_EDIT_FRAME* fpEditor = dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame );
|
|
|
|
FOOTPRINT* footprint = nullptr;
|
|
|
|
PCB_LAYER_ID targetLayer = m_frame->GetActiveLayer();
|
2021-09-29 01:00:15 +00:00
|
|
|
BOARD_ITEM_CONTAINER* parent = frame->GetModel();
|
2020-10-25 12:25:46 +00:00
|
|
|
|
|
|
|
if( fpEditor )
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint = fpEditor->GetBoard()->GetFirstFootprint();
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-09-29 01:00:15 +00:00
|
|
|
auto handleGraphicSeg =
|
|
|
|
[&]( EDA_ITEM* aItem )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( aItem->Type() != PCB_SHAPE_T )
|
2021-09-29 01:00:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( aItem );
|
|
|
|
|
|
|
|
if( graphic->GetShape() == SHAPE_T::SEGMENT )
|
|
|
|
{
|
|
|
|
PCB_TRACK* track = new PCB_TRACK( parent );
|
|
|
|
|
|
|
|
track->SetLayer( targetLayer );
|
|
|
|
track->SetStart( graphic->GetStart() );
|
|
|
|
track->SetEnd( graphic->GetEnd() );
|
2022-03-02 18:45:53 +00:00
|
|
|
track->SetWidth( graphic->GetWidth() );
|
2021-09-29 01:00:15 +00:00
|
|
|
commit.Add( track );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( graphic->GetShape() == SHAPE_T::ARC )
|
|
|
|
{
|
|
|
|
PCB_ARC* arc = new PCB_ARC( parent );
|
|
|
|
|
|
|
|
arc->SetLayer( targetLayer );
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStart( graphic->GetStart() );
|
|
|
|
arc->SetEnd( graphic->GetEnd() );
|
2021-09-29 01:00:15 +00:00
|
|
|
arc->SetMid( graphic->GetArcMid() );
|
2022-03-02 18:45:53 +00:00
|
|
|
arc->SetWidth( graphic->GetWidth() );
|
2021-09-29 01:00:15 +00:00
|
|
|
commit.Add( arc );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2022-03-02 18:15:41 +00:00
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::convertToTracks ) )
|
|
|
|
{
|
|
|
|
if( !IsCopperLayer( targetLayer ) )
|
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
targetLayer = frame->SelectOneLayer( F_Cu, LSET::AllNonCuMask() );
|
2022-03-02 18:15:41 +00:00
|
|
|
|
2022-07-29 21:02:35 +00:00
|
|
|
if( targetLayer == UNDEFINED_LAYER ) // User canceled
|
2022-03-02 18:15:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
2021-09-29 01:00:15 +00:00
|
|
|
if( handleGraphicSeg( item ) )
|
|
|
|
continue;
|
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
SHAPE_POLY_SET polySet = getPolySet( item );
|
|
|
|
std::vector<SEG> segs = getSegList( polySet );
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::convertToLines ) )
|
|
|
|
{
|
|
|
|
for( SEG& seg : segs )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* graphic = new PCB_SHAPE( footprint, SHAPE_T::SEGMENT );
|
2020-10-25 12:25:46 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
graphic->SetLayer( targetLayer );
|
|
|
|
graphic->SetStart( VECTOR2I( seg.A ) );
|
|
|
|
graphic->SetEnd( VECTOR2I( seg.B ) );
|
|
|
|
commit.Add( graphic );
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-25 12:25:46 +00:00
|
|
|
// I am really unsure converting a polygon to "tracks" (i.e. segments on
|
|
|
|
// copper layers) make sense for footprints, but anyway this code exists
|
|
|
|
if( fpEditor )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2020-10-25 12:25:46 +00:00
|
|
|
// Creating segments on copper layer
|
|
|
|
for( SEG& seg : segs )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* graphic = new PCB_SHAPE( footprint, SHAPE_T::SEGMENT );
|
2021-08-08 19:12:23 +00:00
|
|
|
graphic->SetLayer( targetLayer );
|
2022-01-01 06:04:08 +00:00
|
|
|
graphic->SetStart( VECTOR2I( seg.A ) );
|
|
|
|
graphic->SetEnd( VECTOR2I( seg.B ) );
|
2020-10-25 12:25:46 +00:00
|
|
|
commit.Add( graphic );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Creating tracks
|
|
|
|
for( SEG& seg : segs )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* track = new PCB_TRACK( parent );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-08-08 19:12:23 +00:00
|
|
|
track->SetLayer( targetLayer );
|
2022-01-01 06:04:08 +00:00
|
|
|
track->SetStart( VECTOR2I( seg.A ) );
|
|
|
|
track->SetEnd( VECTOR2I( seg.B ) );
|
2020-10-25 12:25:46 +00:00
|
|
|
commit.Add( track );
|
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( _( "Convert polygons to lines" ) );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CONVERT_TOOL::SegmentToArc( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
auto& selection = m_selectionTool->RequestSelection(
|
2020-12-16 13:31:32 +00:00
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
|
|
|
for( int i = aCollector.GetCount() - 1; i >= 0; --i )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = aCollector[i];
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( !( item->Type() == PCB_SHAPE_T ||
|
2023-03-30 11:49:23 +00:00
|
|
|
item->Type() == PCB_TRACE_T ) )
|
2020-11-07 17:35:24 +00:00
|
|
|
{
|
2018-11-13 13:30:56 +00:00
|
|
|
aCollector.Remove( item );
|
2020-11-07 17:35:24 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
2021-01-09 00:46:18 +00:00
|
|
|
} );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
EDA_ITEM* source = selection.Front();
|
2020-08-29 16:12:40 +00:00
|
|
|
VECTOR2I start, end, mid;
|
|
|
|
|
|
|
|
// Offset the midpoint along the normal a little bit so that it's more obviously an arc
|
|
|
|
const double offsetRatio = 0.1;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
if( std::optional<SEG> seg = getStartEndPoints( source ) )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2020-08-29 16:12:40 +00:00
|
|
|
start = seg->A;
|
|
|
|
end = seg->B;
|
|
|
|
|
|
|
|
VECTOR2I normal = ( seg->B - seg->A ).Perpendicular().Resize( offsetRatio * seg->Length() );
|
|
|
|
mid = seg->Center() + normal;
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
else
|
2021-03-13 17:06:15 +00:00
|
|
|
{
|
2018-11-13 13:30:56 +00:00
|
|
|
return -1;
|
2021-03-13 17:06:15 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
PCB_BASE_EDIT_FRAME* frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
BOARD_ITEM_CONTAINER* parent = frame->GetModel();
|
|
|
|
|
|
|
|
BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( source );
|
2020-09-20 01:20:41 +00:00
|
|
|
|
|
|
|
// Don't continue processing if we don't actually have a board item
|
|
|
|
if( !boardItem )
|
|
|
|
return 0;
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
PCB_LAYER_ID layer = boardItem->GetLayer();
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( source->Type() == PCB_SHAPE_T )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* line = static_cast<PCB_SHAPE*>( source );
|
2021-07-17 19:56:18 +00:00
|
|
|
PCB_SHAPE* arc = new PCB_SHAPE( parent, SHAPE_T::ARC );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
VECTOR2I center = CalcArcCenter( start, mid, end );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
arc->SetFilled( false );
|
2018-11-13 13:30:56 +00:00
|
|
|
arc->SetLayer( layer );
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStroke( line->GetStroke() );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
arc->SetCenter( VECTOR2I( center ) );
|
|
|
|
arc->SetStart( VECTOR2I( start ) );
|
|
|
|
arc->SetEnd( VECTOR2I( end ) );
|
2020-08-29 16:12:40 +00:00
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
commit.Add( arc );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxASSERT( source->Type() == PCB_TRACE_T );
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* line = static_cast<PCB_TRACK*>( source );
|
|
|
|
PCB_ARC* arc = new PCB_ARC( parent );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
arc->SetLayer( layer );
|
|
|
|
arc->SetWidth( line->GetWidth() );
|
2022-01-01 06:04:08 +00:00
|
|
|
arc->SetStart( VECTOR2I( start ) );
|
|
|
|
arc->SetMid( VECTOR2I( mid ) );
|
|
|
|
arc->SetEnd( VECTOR2I( end ) );
|
2018-11-13 13:30:56 +00:00
|
|
|
|
|
|
|
commit.Add( arc );
|
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( _( "Create arc from line segment" ) );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-28 20:46:30 +00:00
|
|
|
std::optional<SEG> CONVERT_TOOL::getStartEndPoints( EDA_ITEM* aItem )
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2018-11-13 13:30:56 +00:00
|
|
|
{
|
2021-07-17 19:56:18 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
|
2021-03-13 17:06:15 +00:00
|
|
|
|
2022-07-27 16:15:36 +00:00
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::SEGMENT:
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
case SHAPE_T::POLY:
|
2022-10-31 19:48:23 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2022-07-27 16:15:36 +00:00
|
|
|
if( shape->GetStart() == shape->GetEnd() )
|
2022-08-25 22:50:47 +00:00
|
|
|
return std::nullopt;
|
2022-07-27 16:15:36 +00:00
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
return std::make_optional<SEG>( VECTOR2I( shape->GetStart() ),
|
|
|
|
VECTOR2I( shape->GetEnd() ) );
|
2022-07-27 16:15:36 +00:00
|
|
|
|
|
|
|
default:
|
2022-08-25 22:50:47 +00:00
|
|
|
return std::nullopt;
|
2022-07-27 16:15:36 +00:00
|
|
|
}
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* line = static_cast<PCB_TRACK*>( aItem );
|
2022-08-25 22:50:47 +00:00
|
|
|
return std::make_optional<SEG>( VECTOR2I( line->GetStart() ), VECTOR2I( line->GetEnd() ) );
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_ARC_T:
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_ARC* arc = static_cast<PCB_ARC*>( aItem );
|
2022-08-25 22:50:47 +00:00
|
|
|
return std::make_optional<SEG>( VECTOR2I( arc->GetStart() ), VECTOR2I( arc->GetEnd() ) );
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2022-08-25 22:50:47 +00:00
|
|
|
return std::nullopt;
|
2018-11-13 13:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CONVERT_TOOL::setTransitions()
|
|
|
|
{
|
2021-08-09 00:28:47 +00:00
|
|
|
Go( &CONVERT_TOOL::CreatePolys, PCB_ACTIONS::convertToPoly.MakeEvent() );
|
|
|
|
Go( &CONVERT_TOOL::CreatePolys, PCB_ACTIONS::convertToZone.MakeEvent() );
|
|
|
|
Go( &CONVERT_TOOL::CreatePolys, PCB_ACTIONS::convertToKeepout.MakeEvent() );
|
|
|
|
Go( &CONVERT_TOOL::CreateLines, PCB_ACTIONS::convertToLines.MakeEvent() );
|
|
|
|
Go( &CONVERT_TOOL::CreateLines, PCB_ACTIONS::convertToTracks.MakeEvent() );
|
2018-11-13 13:30:56 +00:00
|
|
|
Go( &CONVERT_TOOL::SegmentToArc, PCB_ACTIONS::convertToArc.MakeEvent() );
|
|
|
|
}
|