2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-01-28 10:00:48 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-12-17 13:12:18 +00:00
|
|
|
* Copyright (C) 2015-2016 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-01-28 19:08:38 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-10 15:55:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2021-08-03 00:11:11 +00:00
|
|
|
#include <widgets/unit_binder.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2021-07-21 21:37:49 +00:00
|
|
|
#include <dialog_shim.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <filter_reader.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/dialog_text_entry.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <microwave/microwave_tool.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2021-06-04 00:26:58 +00:00
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/dialog.h>
|
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/radiobox.h>
|
|
|
|
#include <wx/sizer.h>
|
2021-08-03 00:11:11 +00:00
|
|
|
#include <wx/statbox.h>
|
2021-06-04 00:26:58 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
static std::vector< wxRealPoint > g_PolyEdges;
|
|
|
|
static double g_ShapeScaleX, g_ShapeScaleY;
|
|
|
|
static wxSize g_ShapeSize;
|
|
|
|
static int g_PolyShapeType;
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
enum id_mw_cmd {
|
2007-10-07 03:08:24 +00:00
|
|
|
ID_READ_SHAPE_FILE = 1000
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
class MWAVE_POLYGONAL_SHAPE_DLG : public DIALOG_SHIM
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
public:
|
2015-01-28 10:00:48 +00:00
|
|
|
MWAVE_POLYGONAL_SHAPE_DLG( PCB_EDIT_FRAME* parent, const wxPoint& pos );
|
2021-08-03 00:11:11 +00:00
|
|
|
|
|
|
|
~MWAVE_POLYGONAL_SHAPE_DLG()
|
|
|
|
{
|
|
|
|
delete m_sizeX;
|
|
|
|
delete m_sizeY;
|
|
|
|
};
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
private:
|
2009-11-18 12:52:19 +00:00
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-19 23:56:05 +00:00
|
|
|
* Read a description shape file.
|
|
|
|
*
|
2011-11-10 15:55:05 +00:00
|
|
|
* File format is
|
|
|
|
* Unit=MM
|
|
|
|
* XScale=271.501
|
|
|
|
* YScale=1.00133
|
|
|
|
*
|
|
|
|
* $COORD
|
|
|
|
* 0 0.6112600148417837
|
|
|
|
* 0.001851851851851852 0.6104800531118608
|
|
|
|
* ....
|
|
|
|
* $ENDCOORD
|
|
|
|
*
|
|
|
|
* Each line is the X Y coord (normalized units from 0 to 1)
|
|
|
|
*/
|
2009-11-18 12:52:19 +00:00
|
|
|
void ReadDataShapeDescr( wxCommandEvent& event );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
PCB_EDIT_FRAME* m_frame;
|
|
|
|
wxRadioBox* m_shapeOptionCtrl;
|
|
|
|
UNIT_BINDER* m_sizeX;
|
|
|
|
UNIT_BINDER* m_sizeY;
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-01-28 19:08:38 +00:00
|
|
|
BEGIN_EVENT_TABLE( MWAVE_POLYGONAL_SHAPE_DLG, DIALOG_SHIM )
|
2015-01-28 10:00:48 +00:00
|
|
|
EVT_BUTTON( wxID_CANCEL, MWAVE_POLYGONAL_SHAPE_DLG::OnCancelClick )
|
|
|
|
EVT_BUTTON( ID_READ_SHAPE_FILE, MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr )
|
2009-11-18 12:52:19 +00:00
|
|
|
END_EVENT_TABLE()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
MWAVE_POLYGONAL_SHAPE_DLG::MWAVE_POLYGONAL_SHAPE_DLG( PCB_EDIT_FRAME* parent,
|
2011-03-01 19:26:17 +00:00
|
|
|
const wxPoint& framepos ) :
|
2021-08-03 00:11:11 +00:00
|
|
|
DIALOG_SHIM( parent, -1, _( "Complex Shape" ), framepos, wxDefaultSize,
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
|
|
|
|
m_sizeX(),
|
|
|
|
m_sizeY()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2021-08-03 00:11:11 +00:00
|
|
|
m_frame = parent;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
g_PolyEdges.clear();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
wxBoxSizer* mainBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
SetSizer( mainBoxSizer );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
// Controls
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
wxBoxSizer* topBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
mainBoxSizer->Add( topBoxSizer, 1, wxGROW | wxALL, 5 );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2019-07-01 23:48:05 +00:00
|
|
|
wxString shapelist[] = { _( "Normal" ), _( "Symmetrical" ), _( "Mirrored" ) };
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
m_shapeOptionCtrl = new wxRadioBox( this, -1, _( "Shape" ),
|
2009-11-18 12:52:19 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, 3,
|
|
|
|
shapelist, 1,
|
2007-08-08 03:50:44 +00:00
|
|
|
wxRA_SPECIFY_COLS );
|
2021-08-03 00:11:11 +00:00
|
|
|
topBoxSizer->Add( m_shapeOptionCtrl, 1, wxGROW | wxALL, 5 );
|
|
|
|
|
|
|
|
auto sizeSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _( "Size" ) ),
|
|
|
|
wxVERTICAL );
|
|
|
|
wxBoxSizer* xSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
wxBoxSizer* ySizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
|
|
|
topBoxSizer->Add( sizeSizer, 1, wxGROW | wxALL, 5 );
|
|
|
|
sizeSizer->Add( xSizer, 0, 0, 5 );
|
|
|
|
sizeSizer->Add( ySizer, 0, 0, 5 );
|
|
|
|
|
|
|
|
wxStaticText* xLabel = new wxStaticText( this, -1, _( "X:" ) );
|
|
|
|
wxTextCtrl* xCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString );
|
|
|
|
wxStaticText* xUnits = new wxStaticText( this, -1, _( "units" ) );
|
|
|
|
|
|
|
|
xSizer->Add( xLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
xSizer->Add( xCtrl, 1, wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
xSizer->Add( xUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
m_sizeX = new UNIT_BINDER( m_frame, xLabel, xCtrl, xUnits );
|
|
|
|
|
|
|
|
wxStaticText* yLabel = new wxStaticText( this, -1, _( "Y:" ) );
|
|
|
|
wxTextCtrl* yCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString );
|
|
|
|
wxStaticText* yUnits = new wxStaticText( this, -1, _( "units" ) );
|
|
|
|
|
|
|
|
ySizer->Add( yLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
ySizer->Add( yCtrl, 1, wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
ySizer->Add( yUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
m_sizeY = new UNIT_BINDER( m_frame, yLabel, yCtrl, yUnits );
|
|
|
|
|
|
|
|
// Buttons
|
|
|
|
|
|
|
|
wxBoxSizer* buttonsBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
mainBoxSizer->Add( buttonsBoxSizer, 0, wxALL, 5 );
|
|
|
|
|
|
|
|
wxButton* btn = new wxButton( this, ID_READ_SHAPE_FILE, _( "Read Shape Description File..." ) );
|
|
|
|
buttonsBoxSizer->Add( btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10 );
|
|
|
|
buttonsBoxSizer->AddStretchSpacer();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
|
|
|
|
buttonsBoxSizer->Add( sdbSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
wxButton* sdbSizerOK = new wxButton( this, wxID_OK );
|
|
|
|
sdbSizer->AddButton( sdbSizerOK );
|
|
|
|
wxButton* sdbSizerCancel = new wxButton( this, wxID_CANCEL );
|
|
|
|
sdbSizer->AddButton( sdbSizerCancel );
|
|
|
|
sdbSizer->Realize();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
void MWAVE_POLYGONAL_SHAPE_DLG::OnCancelClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2021-08-03 00:11:11 +00:00
|
|
|
g_PolyEdges.clear();
|
2021-07-21 21:37:49 +00:00
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
bool MWAVE_POLYGONAL_SHAPE_DLG::TransferDataFromWindow()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2021-07-21 21:37:49 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
g_ShapeSize.x = m_sizeX->GetValue();
|
|
|
|
g_ShapeSize.y = m_sizeY->GetValue();
|
|
|
|
g_PolyShapeType = m_shapeOptionCtrl->GetSelection();
|
2021-07-21 21:37:49 +00:00
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2021-08-03 00:11:11 +00:00
|
|
|
static wxString s_lastpath; // To remember the last open path during a session
|
2020-11-25 00:08:09 +00:00
|
|
|
wxString fullFileName;
|
2019-01-06 04:23:13 +00:00
|
|
|
wxString mask = wxFileSelectorDefaultWildcardStr;
|
2015-01-28 10:00:48 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
fullFileName = wxFileSelector( _( "Shape Description File" ), s_lastpath,
|
2021-07-28 17:25:40 +00:00
|
|
|
fullFileName, wxEmptyString, mask, wxFD_OPEN, this );
|
2020-11-25 00:08:09 +00:00
|
|
|
|
|
|
|
if( fullFileName.IsEmpty() )
|
2007-08-08 03:50:44 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-25 00:08:09 +00:00
|
|
|
wxFileName fn( fullFileName );
|
2021-08-03 00:11:11 +00:00
|
|
|
s_lastpath = fn.GetPath();
|
|
|
|
g_PolyEdges.clear();
|
2015-01-28 10:00:48 +00:00
|
|
|
|
2020-11-25 00:08:09 +00:00
|
|
|
FILE* File = wxFopen( fullFileName, wxT( "rt" ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( File == nullptr )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "File not found" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-17 00:45:14 +00:00
|
|
|
double unitconv = pcbIUScale.IU_PER_MM;
|
2021-08-03 00:11:11 +00:00
|
|
|
g_ShapeScaleX = g_ShapeScaleY = 1.0;
|
2011-01-14 17:43:30 +00:00
|
|
|
|
2020-11-25 00:08:09 +00:00
|
|
|
FILE_LINE_READER fileReader( File, fullFileName );
|
2011-01-14 17:43:30 +00:00
|
|
|
FILTER_READER reader( fileReader );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
LOCALE_IO toggle;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2015-01-28 10:00:48 +00:00
|
|
|
char* Line = reader.Line();
|
|
|
|
char* param1 = strtok( Line, " =\n\r" );
|
2021-07-19 23:56:05 +00:00
|
|
|
char* param2 = strtok( nullptr, " \t\n\r" );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( param1, "Unit", 4 ) == 0 )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( param2, "inch", 4 ) == 0 )
|
2022-09-16 23:25:07 +00:00
|
|
|
unitconv = pcbIUScale.IU_PER_MILS*1000;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( param2, "mm", 2 ) == 0 )
|
2022-09-17 00:45:14 +00:00
|
|
|
unitconv = pcbIUScale.IU_PER_MM;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( param1, "$ENDCOORD", 8 ) == 0 )
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( param1, "$COORD", 6 ) == 0 )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-08 03:50:44 +00:00
|
|
|
param1 = strtok( Line, " \t\n\r" );
|
2021-07-19 23:56:05 +00:00
|
|
|
param2 = strtok( nullptr, " \t\n\r" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( param1, "$ENDCOORD", 8 ) == 0 )
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
wxRealPoint coord( atof( param1 ), atof( param2 ) );
|
2021-08-03 00:11:11 +00:00
|
|
|
g_PolyEdges.push_back( coord );
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( Line, "XScale", 6 ) == 0 )
|
2021-08-03 00:11:11 +00:00
|
|
|
g_ShapeScaleX = atof( param2 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2016-08-16 08:27:09 +00:00
|
|
|
if( strncasecmp( Line, "YScale", 6 ) == 0 )
|
2021-08-03 00:11:11 +00:00
|
|
|
g_ShapeScaleY = atof( param2 );
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
g_ShapeScaleX *= unitconv;
|
|
|
|
g_ShapeScaleY *= unitconv;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
m_sizeX->SetValue( (int) g_ShapeScaleX );
|
|
|
|
m_sizeY->SetValue( (int) g_ShapeScaleY );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* MICROWAVE_TOOL::createPolygonShape()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
PAD* pad1;
|
|
|
|
PAD* pad2;
|
|
|
|
FOOTPRINT* footprint;
|
|
|
|
wxString cmp_name;
|
|
|
|
int pad_count = 2;
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* shape;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
|
|
|
|
MWAVE_POLYGONAL_SHAPE_DLG dlg( &editFrame, wxDefaultPosition );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
int ret = dlg.ShowModal();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
if( ret != wxID_OK )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2021-08-03 00:11:11 +00:00
|
|
|
g_PolyEdges.clear();
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
if( g_PolyShapeType == 2 ) // mirrored
|
|
|
|
g_ShapeScaleY = -g_ShapeScaleY;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
g_ShapeSize.x = KiROUND( g_ShapeScaleX );
|
|
|
|
g_ShapeSize.y = KiROUND( g_ShapeScaleY );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
if(( g_ShapeSize.x ) == 0 || ( g_ShapeSize.y == 0 ) )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2021-02-23 12:45:37 +00:00
|
|
|
editFrame.ShowInfoBarError( _( "Shape has a null size." ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
if( g_PolyEdges.size() == 0 )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2021-02-23 12:45:37 +00:00
|
|
|
editFrame.ShowInfoBarError( _( "Shape has no points." ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
cmp_name = wxT( "muwave_polygon" );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
// Create a footprint with 2 pads, orientation = 0, pos 0
|
2020-11-13 00:43:45 +00:00
|
|
|
footprint = createBaseFootprint( cmp_name, 0, pad_count );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
// We try to place the footprint anchor to the middle of the shape len
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I offset;
|
2021-08-03 00:11:11 +00:00
|
|
|
offset.x = -g_ShapeSize.x / 2;
|
2015-01-28 10:00:48 +00:00
|
|
|
|
2020-11-13 00:43:45 +00:00
|
|
|
auto it = footprint->Pads().begin();
|
2019-06-01 23:23:36 +00:00
|
|
|
|
|
|
|
pad1 = *it;
|
2023-04-02 17:02:41 +00:00
|
|
|
pad1->SetX( offset.x );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
pad2 = *( ++it );
|
2023-04-02 17:02:41 +00:00
|
|
|
pad2->SetX( offset.x + g_ShapeSize.x );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
// Add a polygonal edge (corners will be added later) on copper layer
|
2023-03-30 11:49:23 +00:00
|
|
|
shape = new PCB_SHAPE( footprint, SHAPE_T::POLY );
|
2020-11-14 01:16:02 +00:00
|
|
|
shape->SetFilled( true );
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetLayer( F_Cu );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2020-11-13 00:43:45 +00:00
|
|
|
footprint->Add( shape, ADD_MODE::INSERT );
|
2015-01-28 10:00:48 +00:00
|
|
|
|
|
|
|
// Get the corner buffer of the polygonal edge
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> polyPoints;
|
2021-08-03 00:11:11 +00:00
|
|
|
polyPoints.reserve( g_PolyEdges.size() + 2 );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
// Init start point coord:
|
2023-02-19 03:40:07 +00:00
|
|
|
polyPoints.emplace_back( VECTOR2I( offset.x, 0 ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I last_coordinate;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
for( wxRealPoint& pt: g_PolyEdges ) // Copy points
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2021-08-03 00:11:11 +00:00
|
|
|
last_coordinate.x = KiROUND( pt.x * g_ShapeScaleX );
|
|
|
|
last_coordinate.y = -KiROUND( pt.y * g_ShapeScaleY );
|
2015-01-28 10:00:48 +00:00
|
|
|
last_coordinate += offset;
|
2011-08-08 23:50:55 +00:00
|
|
|
polyPoints.push_back( last_coordinate );
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
// finish the polygonal shape
|
|
|
|
if( last_coordinate.y != 0 )
|
2023-02-19 03:40:07 +00:00
|
|
|
polyPoints.emplace_back( VECTOR2I( last_coordinate.x, 0 ) );
|
2015-01-28 10:00:48 +00:00
|
|
|
|
2021-08-03 00:11:11 +00:00
|
|
|
switch( g_PolyShapeType )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2015-01-28 10:00:48 +00:00
|
|
|
case 0: // shape from file
|
|
|
|
case 2: // shape from file, mirrored (the mirror is already done)
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
|
|
|
|
2015-01-28 10:00:48 +00:00
|
|
|
case 1: // Symmetric shape: add the symmetric (mirrored) shape
|
2019-07-01 23:48:05 +00:00
|
|
|
for( int ndx = (int) polyPoints.size() - 1; ndx >= 0; --ndx )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pt = polyPoints[ndx];
|
2008-12-29 18:02:54 +00:00
|
|
|
pt.y = -pt.y; // mirror about X axis
|
2011-08-08 23:50:55 +00:00
|
|
|
polyPoints.push_back( pt );
|
2008-12-29 18:02:54 +00:00
|
|
|
}
|
2021-07-21 21:37:49 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->SetPolyPoints( polyPoints );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-12-11 11:54:17 +00:00
|
|
|
// Set the polygon outline thickness to 0, only the polygonal shape is filled
|
2021-07-19 23:56:05 +00:00
|
|
|
// without extra thickness.
|
2021-07-17 19:56:18 +00:00
|
|
|
shape->SetStroke( STROKE_PARAMS( 0, PLOT_DASH_TYPE::SOLID ) );
|
2021-08-03 00:11:11 +00:00
|
|
|
g_PolyEdges.clear();
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
editFrame.OnModify();
|
2020-11-13 00:43:45 +00:00
|
|
|
return footprint;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|