2020-04-01 17:24:31 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-01-18 02:40:16 +00:00
|
|
|
* Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-04-01 17:24:31 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <confirm.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/dialog_text_entry.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <microwave/microwave_tool.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprintShape )
|
2020-04-01 17:24:31 +00:00
|
|
|
{
|
2023-04-02 17:02:41 +00:00
|
|
|
int offsetX;
|
|
|
|
int offsetY;
|
2020-11-13 15:15:52 +00:00
|
|
|
PAD* pad;
|
|
|
|
FOOTPRINT* footprint;
|
|
|
|
wxString msg;
|
|
|
|
wxString cmp_name;
|
|
|
|
int pad_count = 2;
|
2022-01-18 02:40:16 +00:00
|
|
|
EDA_ANGLE angle = ANGLE_0;
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
// Ref and value text size (O = use board default value.
|
|
|
|
// will be set to a value depending on the footprint size, if possible
|
|
|
|
int text_size = 0;
|
|
|
|
|
|
|
|
// Enter the size of the gap or stub
|
2022-09-19 09:25:20 +00:00
|
|
|
int gap_size = editFrame->GetDesignSettings().GetCurrentTrackWidth();
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
switch( aFootprintShape )
|
|
|
|
{
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::GAP:
|
|
|
|
msg = _( "Gap Size:" );
|
2022-02-05 13:25:43 +00:00
|
|
|
cmp_name = wxT( "muwave_gap" );
|
2020-04-01 17:24:31 +00:00
|
|
|
text_size = gap_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB:
|
|
|
|
msg = _( "Stub Size:" );
|
2022-02-05 13:25:43 +00:00
|
|
|
cmp_name = wxT( "muwave_stub" );
|
2020-04-01 17:24:31 +00:00
|
|
|
text_size = gap_size;
|
|
|
|
pad_count = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC:
|
|
|
|
msg = _( "Arc Stub Radius Value:" );
|
2022-02-05 13:25:43 +00:00
|
|
|
cmp_name = wxT( "muwave_arcstub" );
|
2020-04-01 17:24:31 +00:00
|
|
|
pad_count = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg = wxT( "???" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
wxString value = editFrame->StringFromValue( gap_size );
|
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( editFrame, msg, _( "Create Microwave Footprint" ), value );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2024-03-10 12:18:27 +00:00
|
|
|
// TODO: why is this QuasiModal?
|
2021-02-21 15:01:36 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr; // cancelled by user
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
value = dlg.GetValue();
|
2022-09-19 09:25:20 +00:00
|
|
|
gap_size = editFrame->ValueFromString( value );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
bool abort = false;
|
|
|
|
|
|
|
|
if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC )
|
|
|
|
{
|
2022-01-18 02:40:16 +00:00
|
|
|
msg = wxT( "0.0" );
|
2022-09-19 09:25:20 +00:00
|
|
|
WX_TEXT_ENTRY_DIALOG angledlg( editFrame, _( "Angle in degrees:" ),
|
2021-08-03 00:11:11 +00:00
|
|
|
_( "Create Microwave Footprint" ), msg );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2024-03-10 12:18:27 +00:00
|
|
|
// TODO: why is this QuasiModal?
|
2021-02-21 15:01:36 +00:00
|
|
|
if( angledlg.ShowQuasiModal() != wxID_OK )
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr; // cancelled by user
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
msg = angledlg.GetValue();
|
|
|
|
|
2022-01-18 02:40:16 +00:00
|
|
|
double fval;
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
if( !msg.ToDouble( &fval ) )
|
|
|
|
{
|
2022-09-19 09:25:20 +00:00
|
|
|
DisplayError( editFrame, _( "Incorrect number, abort" ) );
|
2020-04-01 17:24:31 +00:00
|
|
|
abort = true;
|
|
|
|
}
|
|
|
|
|
2022-01-18 02:40:16 +00:00
|
|
|
angle = EDA_ANGLE( fval, DEGREES_T );
|
|
|
|
|
|
|
|
if( angle < ANGLE_0 )
|
|
|
|
angle = -angle;
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2022-01-18 02:40:16 +00:00
|
|
|
if( angle > ANGLE_180 )
|
|
|
|
angle = ANGLE_180;
|
2020-04-01 17:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( abort )
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2020-11-13 00:43:45 +00:00
|
|
|
footprint = createBaseFootprint( cmp_name, text_size, pad_count );
|
|
|
|
auto it = footprint->Pads().begin();
|
2020-04-01 17:24:31 +00:00
|
|
|
pad = *it;
|
|
|
|
|
|
|
|
switch( aFootprintShape )
|
|
|
|
{
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::GAP: //Gap :
|
2023-04-02 17:02:41 +00:00
|
|
|
offsetX = -( gap_size + pad->GetSize().x ) / 2;
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2023-04-02 17:02:41 +00:00
|
|
|
pad->SetX( pad->GetPosition().x + offsetX );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
pad = *( it + 1 );
|
|
|
|
|
2023-04-02 17:02:41 +00:00
|
|
|
pad->SetX( pad->GetPosition().x + offsetX + gap_size + pad->GetSize().x );
|
2020-04-01 17:24:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB: //Stub :
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( wxT( "1" ) );
|
2023-04-02 17:02:41 +00:00
|
|
|
offsetY = -( gap_size + pad->GetSize().y ) / 2;
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
pad = *( it + 1 );
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( pad->GetSize().x, gap_size ) );
|
2023-04-02 17:02:41 +00:00
|
|
|
pad->SetY( pad->GetPosition().y + offsetY );
|
2020-04-01 17:24:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC: // Arc Stub created by a polygonal approach:
|
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::CUSTOM );
|
2023-06-02 09:10:48 +00:00
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE::RECTANGLE );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2022-01-18 02:40:16 +00:00
|
|
|
int numPoints = ( angle.AsDegrees() / 5.0 ) + 3;
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> polyPoints;
|
2020-04-01 17:24:31 +00:00
|
|
|
polyPoints.reserve( numPoints );
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
polyPoints.emplace_back( VECTOR2I( 0, 0 ) );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2022-01-18 02:40:16 +00:00
|
|
|
EDA_ANGLE theta = -angle / 2;
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
for( int ii = 1; ii < numPoints - 1; ii++ )
|
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I pt( 0, -gap_size );
|
2020-04-01 17:24:31 +00:00
|
|
|
RotatePoint( &pt.x, &pt.y, theta );
|
|
|
|
polyPoints.push_back( pt );
|
|
|
|
|
2022-01-18 02:40:16 +00:00
|
|
|
theta += EDA_ANGLE( 5.0, DEGREES_T );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
if( theta > angle / 2 )
|
|
|
|
theta = angle / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close the polygon:
|
|
|
|
polyPoints.push_back( polyPoints[0] );
|
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
pad->AddPrimitivePoly( polyPoints, 0, true ); // add a polygonal basic shape
|
2020-04-01 17:24:31 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-13 00:43:45 +00:00
|
|
|
// Update the footprint and board
|
2022-09-19 09:25:20 +00:00
|
|
|
editFrame->OnModify();
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2020-11-13 00:43:45 +00:00
|
|
|
return footprint;
|
2020-04-01 17:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* MICROWAVE_TOOL::createBaseFootprint( const wxString& aValue,
|
|
|
|
int aTextSize, int aPadCount )
|
2020-04-01 17:24:31 +00:00
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
|
2024-05-31 09:17:17 +00:00
|
|
|
FOOTPRINT* footprint = editFrame.CreateNewFootprint( aValue, wxEmptyString );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2021-09-24 17:43:38 +00:00
|
|
|
footprint->SetAttributes( FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM );
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
if( aTextSize > 0 )
|
|
|
|
{
|
2023-02-19 03:40:07 +00:00
|
|
|
footprint->Reference().SetTextSize( VECTOR2I( aTextSize, aTextSize ) );
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Reference().SetTextThickness( aTextSize / 5 );
|
2023-02-19 03:40:07 +00:00
|
|
|
footprint->Value().SetTextSize( VECTOR2I( aTextSize, aTextSize ) );
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Value().SetTextThickness( aTextSize / 5 );
|
2020-04-01 17:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create 2 pads used in gaps and stubs. The gap is between these 2 pads
|
|
|
|
// the stub is the pad 2
|
|
|
|
int pad_num = 1;
|
|
|
|
|
|
|
|
while( aPadCount-- )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = new PAD( footprint );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Add( pad, ADD_MODE::INSERT );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
int tw = editFrame.GetDesignSettings().GetCurrentTrackWidth();
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( tw, tw ) );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
pad->SetPosition( footprint->GetPosition() );
|
2023-06-02 09:10:48 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECTANGLE );
|
2021-05-01 14:46:50 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB::SMD );
|
2020-04-01 17:24:31 +00:00
|
|
|
pad->SetLayerSet( F_Cu );
|
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->SetNumber( wxString::Format( wxT( "%d" ), pad_num ) );
|
2020-04-01 17:24:31 +00:00
|
|
|
pad_num++;
|
|
|
|
}
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
return footprint;
|
2020-04-01 17:24:31 +00:00
|
|
|
}
|