2020-04-01 17:24:31 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.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
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
int oX;
|
|
|
|
PAD* pad;
|
|
|
|
FOOTPRINT* footprint;
|
|
|
|
wxString msg;
|
|
|
|
wxString cmp_name;
|
|
|
|
int pad_count = 2;
|
|
|
|
int angle = 0;
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
int gap_size = editFrame.GetDesignSettings().GetCurrentTrackWidth();
|
|
|
|
|
|
|
|
switch( aFootprintShape )
|
|
|
|
{
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::GAP:
|
|
|
|
msg = _( "Gap Size:" );
|
|
|
|
cmp_name = "muwave_gap";
|
|
|
|
text_size = gap_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB:
|
|
|
|
msg = _( "Stub Size:" );
|
|
|
|
cmp_name = "muwave_stub";
|
|
|
|
text_size = gap_size;
|
|
|
|
pad_count = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC:
|
|
|
|
msg = _( "Arc Stub Radius Value:" );
|
|
|
|
cmp_name = "muwave_arcstub";
|
|
|
|
pad_count = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg = wxT( "???" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString value = StringFromValue( editFrame.GetUserUnits(), gap_size );
|
2020-11-13 00:43:45 +00:00
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( &editFrame, msg, _( "Create microwave footprint" ), value );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2021-02-21 15:01:36 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
2020-04-01 17:24:31 +00:00
|
|
|
return NULL; // cancelled by user
|
|
|
|
|
|
|
|
value = dlg.GetValue();
|
|
|
|
gap_size = ValueFromString( editFrame.GetUserUnits(), value );
|
|
|
|
|
|
|
|
bool abort = false;
|
|
|
|
|
|
|
|
if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC )
|
|
|
|
{
|
|
|
|
double fcoeff = 10.0, fval;
|
|
|
|
msg.Printf( wxT( "%3.1f" ), angle / fcoeff );
|
|
|
|
WX_TEXT_ENTRY_DIALOG angledlg( &editFrame, _( "Angle in degrees:" ),
|
2020-11-13 00:43:45 +00:00
|
|
|
_( "Create microwave footprint" ), msg );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2021-02-21 15:01:36 +00:00
|
|
|
if( angledlg.ShowQuasiModal() != wxID_OK )
|
2020-04-01 17:24:31 +00:00
|
|
|
return NULL; // cancelled by user
|
|
|
|
|
|
|
|
msg = angledlg.GetValue();
|
|
|
|
|
|
|
|
if( !msg.ToDouble( &fval ) )
|
|
|
|
{
|
|
|
|
DisplayError( &editFrame, _( "Incorrect number, abort" ) );
|
|
|
|
abort = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
angle = std::abs( KiROUND( fval * fcoeff ) );
|
|
|
|
|
|
|
|
if( angle > 1800 )
|
|
|
|
angle = 1800;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( abort )
|
|
|
|
return NULL;
|
|
|
|
|
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 :
|
|
|
|
oX = -( gap_size + pad->GetSize().x ) / 2;
|
|
|
|
pad->SetX0( oX );
|
|
|
|
|
|
|
|
pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
|
|
|
|
|
|
|
|
pad = *( it + 1 );
|
|
|
|
|
|
|
|
pad->SetX0( oX + gap_size + pad->GetSize().x );
|
|
|
|
pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB: //Stub :
|
|
|
|
pad->SetName( wxT( "1" ) );
|
|
|
|
pad = *( it + 1 );
|
|
|
|
pad->SetY0( -( gap_size + pad->GetSize().y ) / 2 );
|
|
|
|
pad->SetSize( wxSize( pad->GetSize().x, gap_size ) );
|
|
|
|
pad->SetY( pad->GetPos0().y + pad->GetPosition().y );
|
|
|
|
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 );
|
|
|
|
pad->SetAnchorPadShape( PAD_SHAPE::RECT );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
int numPoints = (angle / 50) + 3; // Note: angles are in 0.1 degrees
|
|
|
|
std::vector<wxPoint> polyPoints;
|
|
|
|
polyPoints.reserve( numPoints );
|
|
|
|
|
|
|
|
polyPoints.emplace_back( wxPoint( 0, 0 ) );
|
|
|
|
|
|
|
|
int theta = -angle / 2;
|
|
|
|
|
|
|
|
for( int ii = 1; ii < numPoints - 1; ii++ )
|
|
|
|
{
|
|
|
|
wxPoint pt( 0, -gap_size );
|
|
|
|
RotatePoint( &pt.x, &pt.y, theta );
|
|
|
|
polyPoints.push_back( pt );
|
|
|
|
|
|
|
|
theta += 50;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-13 00:43:45 +00:00
|
|
|
// Update the footprint and board
|
2020-04-01 17:24:31 +00:00
|
|
|
editFrame.OnModify();
|
|
|
|
|
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>();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = editFrame.CreateNewFootprint( aValue );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
if( aTextSize > 0 )
|
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Reference().SetTextSize( wxSize( aTextSize, aTextSize ) );
|
|
|
|
footprint->Reference().SetTextThickness( aTextSize / 5 );
|
|
|
|
footprint->Value().SetTextSize( wxSize( aTextSize, aTextSize ) );
|
|
|
|
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
|
|
|
|
wxString Line;
|
|
|
|
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();
|
|
|
|
pad->SetSize( wxSize( tw, tw ) );
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
pad->SetPosition( footprint->GetPosition() );
|
2021-05-01 12:22:35 +00:00
|
|
|
pad->SetShape( PAD_SHAPE::RECT );
|
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 );
|
|
|
|
|
|
|
|
Line.Printf( wxT( "%d" ), pad_num );
|
|
|
|
pad->SetName( Line );
|
|
|
|
pad_num++;
|
|
|
|
}
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
return footprint;
|
2020-04-01 17:24:31 +00:00
|
|
|
}
|