Refactor microwave parts into the microwave tool

This commit is contained in:
Ian McInerney 2020-04-01 18:24:31 +01:00
parent 6730313ab7
commit 4b647ba6b1
11 changed files with 395 additions and 387 deletions

View File

@ -222,7 +222,10 @@ set( PCBNEW_EXPORTERS
)
set( PCBNEW_MICROWAVE_SRCS
microwave/microwave_footprint.cpp
microwave/microwave_inductor.cpp
microwave/microwave_polygon.cpp
microwave/microwave_tool.cpp
)
set( PCBNEW_DRC_SRCS
@ -275,7 +278,6 @@ set( PCBNEW_CLASS_SRCS
load_select_footprint.cpp
menubar_footprint_editor.cpp
menubar_pcb_editor.cpp
microwave.cpp
pad_naming.cpp
pcb_base_edit_frame.cpp
pcb_layer_box_selector.cpp
@ -309,7 +311,6 @@ set( PCBNEW_CLASS_SRCS
tools/edit_tool.cpp
tools/global_edit_tool.cpp
tools/grid_helper.cpp
tools/microwave_tool.cpp
tools/footprint_editor_tools.cpp
tools/pad_tool.cpp
tools/pcb_actions.cpp

View File

@ -0,0 +1,223 @@
/*
* 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
*/
#include <class_module.h>
#include <confirm.h>
#include <dialog_text_entry.h>
#include <microwave/microwave_tool.h>
MODULE* MICROWAVE_TOOL::createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprintShape )
{
int oX;
D_PAD* pad;
MODULE* module;
wxString msg, cmp_name;
int pad_count = 2;
int angle = 0;
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 );
WX_TEXT_ENTRY_DIALOG dlg( &editFrame, msg, _( "Create microwave module" ), value );
if( dlg.ShowModal() != wxID_OK )
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:" ),
_( "Create microwave module" ), msg );
if( angledlg.ShowModal() != wxID_OK )
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;
module = createBaseFootprint( cmp_name, text_size, pad_count );
auto it = module->Pads().begin();
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:
{
pad->SetShape( PAD_SHAPE_CUSTOM );
pad->SetAnchorPadShape( PAD_SHAPE_RECT );
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] );
pad->AddPrimitivePoly( polyPoints, 0 ); // add a polygonal basic shape
}
break;
default:
break;
}
// Update the module and board
module->CalculateBoundingBox();
editFrame.OnModify();
return module;
}
MODULE* MICROWAVE_TOOL::createBaseFootprint( const wxString& aValue,
int aTextSize, int aPadCount )
{
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
MODULE* module = editFrame.CreateNewModule( aValue );
if( aTextSize > 0 )
{
module->Reference().SetTextSize( wxSize( aTextSize, aTextSize ) );
module->Reference().SetThickness( aTextSize/5 );
module->Value().SetTextSize( wxSize( aTextSize, aTextSize ) );
module->Value().SetThickness( aTextSize/5 );
}
// 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-- )
{
D_PAD* pad = new D_PAD( module );
module->Add( pad, ADD_MODE::INSERT );
int tw = editFrame.GetDesignSettings().GetCurrentTrackWidth();
pad->SetSize( wxSize( tw, tw ) );
pad->SetPosition( module->GetPosition() );
pad->SetShape( PAD_SHAPE_RECT );
pad->SetAttribute( PAD_ATTRIB_SMD );
pad->SetLayerSet( F_Cu );
Line.Printf( wxT( "%d" ), pad_num );
pad->SetName( Line );
pad_num++;
}
return module;
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* 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
@ -21,23 +21,22 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "microwave_inductor.h"
#include <wx/wx.h>
#include <base_units.h>
#include <dialog_text_entry.h>
#include <geometry/geometry_utils.h>
#include <pcb_edit_frame.h>
#include <validators.h>
#include <board_commit.h>
#include <class_pad.h>
#include <class_edge_mod.h>
#include <class_module.h>
#include <confirm.h>
#include <dialog_text_entry.h>
#include <geometry/geometry_utils.h>
#include <math/util.h> // for KiROUND
using namespace MWAVE;
#include <microwave/microwave_tool.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <pcb_edit_frame.h>
#include <validators.h>
/**
* Function gen_arc
@ -52,7 +51,7 @@ using namespace MWAVE;
static void gen_arc( std::vector <wxPoint>& aBuffer,
const wxPoint& aStartPoint,
const wxPoint& aCenter,
int a_ArcAngle )
int a_ArcAngle )
{
auto first_point = aStartPoint - aCenter;
auto radius = KiROUND( EuclideanNorm( first_point ) );
@ -109,7 +108,7 @@ static INDUCTOR_S_SHAPE_RESULT BuildCornersList_S_Shape( std::vector<wxPoint>& a
* The equations are (assuming the area size of the entire shape is Size:
* Size.x = 2 * radius + segm_len
* Size.y = (segm_count + 2 ) * 2 * radius + 2 * stubs_len
* inductorPattern.m_length = 2 * delta // connections to the coil
* aInductorPattern.m_length = 2 * delta // connections to the coil
* + (segm_count-2) * segm_len // length of the strands except 1st and last
* + (segm_count) * (PI * radius) // length of rounded
* segm_len + / 2 - radius * 2) // length of 1st and last bit
@ -291,8 +290,42 @@ static INDUCTOR_S_SHAPE_RESULT BuildCornersList_S_Shape( std::vector<wxPoint>& a
}
MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
PCB_EDIT_FRAME* aPcbFrame, wxString& aErrorMessage )
void MICROWAVE_TOOL::createInductorBetween( const VECTOR2I& aStart, const VECTOR2I& aEnd )
{
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
MICROWAVE_INDUCTOR_PATTERN pattern;
pattern.m_Width = board()->GetDesignSettings().GetCurrentTrackWidth();
pattern.m_Start = { aStart.x, aStart.y };
pattern.m_End = { aEnd.x, aEnd.y };
wxString errorMessage;
auto inductorModule = std::unique_ptr<MODULE>( createMicrowaveInductor( pattern,
errorMessage ) );
// on any error, report if we can
if ( !inductorModule || !errorMessage.IsEmpty() )
{
if ( !errorMessage.IsEmpty() )
DisplayError( &editFrame, errorMessage );
}
else
{
// at this point, we can save the module
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, inductorModule.get() );
BOARD_COMMIT commit( this );
commit.Add( inductorModule.release() );
commit.Push( _("Add microwave inductor" ) );
}
}
MODULE* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN& aInductorPattern,
wxString& aErrorMessage )
{
/* Build a microwave inductor footprint.
* - Length Mself.lng
@ -330,22 +363,24 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
D_PAD* pad;
wxString msg;
auto pt = inductorPattern.m_End - inductorPattern.m_Start;
int min_len = KiROUND( EuclideanNorm( pt ) );
inductorPattern.m_length = min_len;
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
auto pt = aInductorPattern.m_End - aInductorPattern.m_Start;
int min_len = KiROUND( EuclideanNorm( pt ) );
aInductorPattern.m_length = min_len;
// Enter the desired length.
msg = StringFromValue( aPcbFrame->GetUserUnits(), inductorPattern.m_length, true );
WX_TEXT_ENTRY_DIALOG dlg( aPcbFrame, _( "Length of Trace:" ), wxEmptyString, msg );
msg = StringFromValue( editFrame.GetUserUnits(), aInductorPattern.m_length, true );
WX_TEXT_ENTRY_DIALOG dlg( &editFrame, _( "Length of Trace:" ), wxEmptyString, msg );
if( dlg.ShowModal() != wxID_OK )
return nullptr; // canceled by user
msg = dlg.GetValue();
inductorPattern.m_length = ValueFromString( aPcbFrame->GetUserUnits(), msg );
aInductorPattern.m_length = ValueFromString( editFrame.GetUserUnits(), msg );
// Control values (ii = minimum length)
if( inductorPattern.m_length < min_len )
if( aInductorPattern.m_length < min_len )
{
aErrorMessage = _( "Requested length < minimum length" );
return nullptr;
@ -353,8 +388,8 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
// Calculate the elements.
std::vector <wxPoint> buffer;
const INDUCTOR_S_SHAPE_RESULT res = BuildCornersList_S_Shape( buffer, inductorPattern.m_Start,
inductorPattern.m_End, inductorPattern.m_length, inductorPattern.m_Width );
const INDUCTOR_S_SHAPE_RESULT res = BuildCornersList_S_Shape( buffer, aInductorPattern.m_Start,
aInductorPattern.m_End, aInductorPattern.m_length, aInductorPattern.m_Width );
switch( res )
{
@ -373,19 +408,18 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
// Generate footprint. the value is also used as footprint name.
msg = "L";
WX_TEXT_ENTRY_DIALOG cmpdlg( aPcbFrame, _( "Component Value:" ), wxEmptyString, msg );
WX_TEXT_ENTRY_DIALOG cmpdlg( &editFrame, _( "Component Value:" ), wxEmptyString, msg );
cmpdlg.SetTextValidator( MODULE_NAME_CHAR_VALIDATOR( &msg ) );
if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() )
return nullptr; // Aborted by user
MODULE* module = aPcbFrame->CreateNewModule( msg );
aPcbFrame->AddModuleToBoard( module );
MODULE* module = editFrame.CreateNewModule( msg );
module->SetFPID( LIB_ID( wxEmptyString, wxT( "mw_inductor" ) ) );
module->SetAttributes( MOD_VIRTUAL | MOD_CMS );
module->ClearFlags();
module->SetPosition( inductorPattern.m_End );
module->SetPosition( aInductorPattern.m_End );
// Generate segments
for( unsigned jj = 1; jj < buffer.size(); jj++ )
@ -394,7 +428,7 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
PtSegm = new EDGE_MODULE( module );
PtSegm->SetStart( buffer[jj - 1] );
PtSegm->SetEnd( buffer[jj] );
PtSegm->SetWidth( inductorPattern.m_Width );
PtSegm->SetWidth( aInductorPattern.m_Width );
PtSegm->SetLayer( module->GetLayer() );
PtSegm->SetShape( S_SEGMENT );
PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() );
@ -408,10 +442,10 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
module->Add( pad );
pad->SetName( "1" );
pad->SetPosition( inductorPattern.m_End );
pad->SetPosition( aInductorPattern.m_End );
pad->SetPos0( pad->GetPosition() - module->GetPosition() );
pad->SetSize( wxSize( inductorPattern.m_Width, inductorPattern.m_Width ) );
pad->SetSize( wxSize( aInductorPattern.m_Width, aInductorPattern.m_Width ) );
pad->SetLayerSet( LSET( module->GetLayer() ) );
pad->SetAttribute( PAD_ATTRIB_SMD );
@ -423,12 +457,12 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
pad = newpad;
pad->SetName( "2" );
pad->SetPosition( inductorPattern.m_Start );
pad->SetPosition( aInductorPattern.m_Start );
pad->SetPos0( pad->GetPosition() - module->GetPosition() );
// Modify text positions.
wxPoint refPos( ( inductorPattern.m_Start.x + inductorPattern.m_End.x ) / 2,
( inductorPattern.m_Start.y + inductorPattern.m_End.y ) / 2 );
wxPoint refPos( ( aInductorPattern.m_Start.x + aInductorPattern.m_End.x ) / 2,
( aInductorPattern.m_Start.y + aInductorPattern.m_End.y ) / 2 );
wxPoint valPos = refPos;

View File

@ -1,55 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 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
*/
#ifndef MICROWAVE_INDUCTOR__H_
#define MICROWAVE_INDUCTOR__H_
#include <wx/wx.h> // for wxPoint
class MODULE;
class PCB_EDIT_FRAME;
namespace MWAVE
{
/**
* Parameters for construction of a microwave inductor
*/
struct INDUCTOR_PATTERN
{
public:
wxPoint m_Start;
wxPoint m_End;
int m_length; // full length trace.
int m_Width; // Trace width.
};
/**
* Creates an S-shaped coil footprint for microwave applications.
*/
MODULE* CreateMicrowaveInductor( INDUCTOR_PATTERN& aPattern,
PCB_EDIT_FRAME* aPcbFrame, wxString& aErrorMessage );
}
#endif // MICROWAVE_INDUCTOR__H_

View File

@ -4,7 +4,7 @@
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2015-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-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
@ -39,7 +39,7 @@
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
#include <microwave/microwave_inductor.h>
#include <microwave/microwave_tool.h>
#include <pcbnew.h>
#include <math/util.h> // for KiROUND
@ -49,193 +49,6 @@ static wxSize ShapeSize;
static int PolyShapeType;
MODULE* PCB_EDIT_FRAME::CreateMuWaveBaseFootprint( const wxString& aValue,
int aTextSize, int aPadCount )
{
MODULE* module = CreateNewModule( aValue );
if( aTextSize > 0 )
{
module->Reference().SetTextSize( wxSize( aTextSize, aTextSize ) );
module->Reference().SetThickness( aTextSize/5 );
module->Value().SetTextSize( wxSize( aTextSize, aTextSize ) );
module->Value().SetThickness( aTextSize/5 );
}
// 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-- )
{
D_PAD* pad = new D_PAD( module );
module->Add( pad, ADD_MODE::INSERT );
int tw = GetDesignSettings().GetCurrentTrackWidth();
pad->SetSize( wxSize( tw, tw ) );
pad->SetPosition( module->GetPosition() );
pad->SetShape( PAD_SHAPE_RECT );
pad->SetAttribute( PAD_ATTRIB_SMD );
pad->SetLayerSet( F_Cu );
Line.Printf( wxT( "%d" ), pad_num );
pad->SetName( Line );
pad_num++;
}
return module;
}
MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type )
{
int oX;
D_PAD* pad;
MODULE* module;
wxString msg, cmp_name;
int pad_count = 2;
int angle = 0;
// 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 = GetDesignSettings().GetCurrentTrackWidth();
switch( shape_type )
{
case 0:
msg = _( "Gap Size:" );
cmp_name = "muwave_gap";
text_size = gap_size;
break;
case 1:
msg = _( "Stub Size:" );
cmp_name = "muwave_stub";
text_size = gap_size;
pad_count = 2;
break;
case 2:
msg = _( "Arc Stub Radius Value:" );
cmp_name = "muwave_arcstub";
pad_count = 1;
break;
default:
msg = wxT( "???" );
break;
}
wxString value = StringFromValue( GetUserUnits(), gap_size );
WX_TEXT_ENTRY_DIALOG dlg( this, msg, _( "Create microwave module" ), value );
if( dlg.ShowModal() != wxID_OK )
return NULL; // cancelled by user
value = dlg.GetValue();
gap_size = ValueFromString( GetUserUnits(), value );
bool abort = false;
if( shape_type == 2 )
{
double fcoeff = 10.0, fval;
msg.Printf( wxT( "%3.1f" ), angle / fcoeff );
WX_TEXT_ENTRY_DIALOG angledlg( this, _( "Angle in degrees:" ),
_( "Create microwave module" ), msg );
if( angledlg.ShowModal() != wxID_OK )
return NULL; // cancelled by user
msg = angledlg.GetValue();
if( !msg.ToDouble( &fval ) )
{
DisplayError( this, _( "Incorrect number, abort" ) );
abort = true;
}
angle = std::abs( KiROUND( fval * fcoeff ) );
if( angle > 1800 )
angle = 1800;
}
if( abort )
return NULL;
module = CreateMuWaveBaseFootprint( cmp_name, text_size, pad_count );
auto it = module->Pads().begin();
pad = *it;
switch( shape_type )
{
case 0: //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 1: //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 2: // Arc Stub created by a polygonal approach:
{
pad->SetShape( PAD_SHAPE_CUSTOM );
pad->SetAnchorPadShape( PAD_SHAPE_RECT );
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] );
pad->AddPrimitivePoly( polyPoints, 0 ); // add a polygonal basic shape
}
break;
default:
break;
}
module->CalculateBoundingBox();
OnModify();
return module;
}
/**************** Polygon Shapes ***********************/
@ -425,7 +238,7 @@ void MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr( wxCommandEvent& event )
}
MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
MODULE* MICROWAVE_TOOL::createPolygonShape()
{
D_PAD* pad1, * pad2;
MODULE* module;
@ -433,7 +246,9 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
int pad_count = 2;
EDGE_MODULE* edge;
MWAVE_POLYGONAL_SHAPE_DLG dlg( this, wxDefaultPosition );
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
MWAVE_POLYGONAL_SHAPE_DLG dlg( &editFrame, wxDefaultPosition );
int ret = dlg.ShowModal();
@ -451,20 +266,20 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
if( ( ShapeSize.x ) == 0 || ( ShapeSize.y == 0 ) )
{
DisplayError( this, _( "Shape has a null size!" ) );
DisplayError( &editFrame, _( "Shape has a null size!" ) );
return NULL;
}
if( PolyEdges.size() == 0 )
{
DisplayError( this, _( "Shape has no points!" ) );
DisplayError( &editFrame, _( "Shape has no points!" ) );
return NULL;
}
cmp_name = wxT( "muwave_polygon" );
// Create a footprint with 2 pads, orientation = 0, pos 0
module = CreateMuWaveBaseFootprint( cmp_name, 0, pad_count );
module = createBaseFootprint( cmp_name, 0, pad_count );
// We try to place the footprint anchor to the middle of the shape len
wxPoint offset;
@ -529,7 +344,8 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
// without extra thickness
edge->SetWidth( 0 );
PolyEdges.clear();
module->CalculateBoundingBox();
OnModify();
editFrame.OnModify();
return module;
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017-2019 Kicad Developers, see change_log.txt for contributors.
* Copyright (C) 2017-2020 Kicad Developers, see change_log.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
@ -21,22 +21,21 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "microwave_tool.h"
#include <gal/graphics_abstraction_layer.h>
#include <class_draw_panel_gal.h>
#include <view/view_controls.h>
#include <view/view.h>
#include <tool/tool_manager.h>
#include <bitmaps.h>
#include <board_commit.h>
#include <class_board_item.h>
#include <class_draw_panel_gal.h>
#include <class_module.h>
#include <confirm.h>
#include <gal/graphics_abstraction_layer.h>
#include <microwave/microwave_tool.h>
#include <preview_items/two_point_geom_manager.h>
#include <preview_items/centreline_rect_item.h>
#include <bitmaps.h>
#include <class_board_item.h>
#include <class_module.h>
#include <microwave/microwave_inductor.h>
#include "pcb_actions.h"
#include "selection_tool.h"
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <tools/selection_tool.h>
#include <view/view_controls.h>
#include <view/view.h>
MICROWAVE_TOOL::MICROWAVE_TOOL() :
@ -56,12 +55,10 @@ void MICROWAVE_TOOL::Reset( RESET_REASON aReason )
int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent )
{
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
struct MICROWAVE_PLACER : public INTERACTIVE_PLACER_BASE
{
MICROWAVE_PLACER( PCB_EDIT_FRAME* aFrame, int aType ) :
m_frame( aFrame ),
MICROWAVE_PLACER( MICROWAVE_TOOL* aTool, MICROWAVE_FOOTPRINT_SHAPE aType ) :
m_tool( aTool ),
m_itemType( aType )
{ };
@ -73,25 +70,25 @@ int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent )
{
switch( m_itemType )
{
case MWAVE_TOOL_SIMPLE_ID::GAP:
return std::unique_ptr<MODULE>( m_frame->Create_MuWaveComponent( 0 ) );
case MWAVE_TOOL_SIMPLE_ID::STUB:
return std::unique_ptr<MODULE>( m_frame->Create_MuWaveComponent( 1 ) );
case MWAVE_TOOL_SIMPLE_ID::STUB_ARC:
return std::unique_ptr<MODULE>( m_frame->Create_MuWaveComponent( 2 ) );
case MWAVE_TOOL_SIMPLE_ID::FUNCTION_SHAPE:
return std::unique_ptr<MODULE>( m_frame->Create_MuWavePolygonShape() );
case MICROWAVE_FOOTPRINT_SHAPE::GAP:
case MICROWAVE_FOOTPRINT_SHAPE::STUB:
case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC:
return std::unique_ptr<MODULE>( m_tool->createFootprint( m_itemType ) );
case MICROWAVE_FOOTPRINT_SHAPE::FUNCTION_SHAPE:
return std::unique_ptr<MODULE>( m_tool->createPolygonShape() );
default:
return std::unique_ptr<MODULE>();
};
}
private:
PCB_EDIT_FRAME* m_frame;
int m_itemType;
MICROWAVE_TOOL* m_tool;
MICROWAVE_FOOTPRINT_SHAPE m_itemType;
};
MICROWAVE_PLACER placer( frame, aEvent.Parameter<intptr_t>() );
MICROWAVE_PLACER placer( this, aEvent.Parameter<MICROWAVE_FOOTPRINT_SHAPE>() );
doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer,
_( "Place microwave feature" ),
@ -101,40 +98,6 @@ int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent )
}
void MICROWAVE_TOOL::createInductorBetween( const VECTOR2I& aStart, const VECTOR2I& aEnd )
{
auto& frame = *getEditFrame<PCB_EDIT_FRAME>();
MWAVE::INDUCTOR_PATTERN pattern;
pattern.m_Width = board()->GetDesignSettings().GetCurrentTrackWidth();
pattern.m_Start = { aStart.x, aStart.y };
pattern.m_End = { aEnd.x, aEnd.y };
wxString errorMessage;
auto inductorModule = std::unique_ptr<MODULE>( CreateMicrowaveInductor( pattern, &frame,
errorMessage ) );
// on any error, report if we can
if ( !inductorModule || !errorMessage.IsEmpty() )
{
if ( !errorMessage.IsEmpty() )
DisplayError( &frame, errorMessage );
}
else
{
// at this point, we can save the module
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, inductorModule.get() );
BOARD_COMMIT commit( this );
commit.Add( inductorModule.release() );
commit.Push( _("Add microwave inductor" ) );
}
}
static const COLOR4D inductorAreaFill( 0.3, 0.3, 0.5, 0.3 );
static const COLOR4D inductorAreaStroke( 0.4, 1.0, 1.0, 1.0 );
static const double inductorAreaStrokeWidth = 1.0;
@ -150,7 +113,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
KIGFX::VIEW& view = *getView();
KIGFX::VIEW_CONTROLS& controls = *getViewControls();
auto& frame = *getEditFrame<PCB_EDIT_FRAME>();
PCB_EDIT_FRAME& frame = *getEditFrame<PCB_EDIT_FRAME>();
std::string tool = aEvent.GetCommandStr().get();
frame.PushTool( tool );
@ -269,6 +232,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
}
void MICROWAVE_TOOL::setTransitions()
{
Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateGap.MakeEvent() );

View File

@ -28,6 +28,30 @@
#include <tool/tool_menu.h>
// This class is inside MICROWAVE_TOOL::addMicrowaveFootprint
class MICROWAVE_PLACER;
// Microwave shapes that are created as board modules when the user requests them.
enum class MICROWAVE_FOOTPRINT_SHAPE
{
GAP,
STUB,
STUB_ARC,
FUNCTION_SHAPE,
};
/**
* Parameters for construction of a microwave inductor
*/
struct MICROWAVE_INDUCTOR_PATTERN
{
public:
wxPoint m_Start;
wxPoint m_End;
int m_length; // full length trace.
int m_Width; // Trace width.
};
/**
* MICROWAVE_TOOL
@ -47,6 +71,8 @@ public:
void setTransitions() override;
private:
// Make the placer class a friend so it can use the create functions
friend MICROWAVE_PLACER;
///> Main interactive tool
int addMicrowaveFootprint( const TOOL_EVENT& aEvent );
@ -56,6 +82,37 @@ private:
///> Draw a microwave inductor interactively
int drawMicrowaveInductor( const TOOL_EVENT& aEvent );
/**
* Creates a module "GAP" or "STUB" used in micro wave designs.
* This module has 2 pads:
* PAD_ATTRIB_SMD, rectangular, H size = V size = current track width.
* the "gap" is isolation created between this 2 pads
*
* @param aComponentShape is the component to create
* @return the new module
*/
MODULE* createFootprint( MICROWAVE_FOOTPRINT_SHAPE aFootprintShape );
MODULE* createPolygonShape();
/**
* Creates an S-shaped coil footprint for microwave applications.
*/
MODULE* createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN& aPattern, wxString& aErrorMessage );
/**
* Create a basic footprint for micro wave applications.
*
* The default pad settings are:
* PAD_ATTRIB_SMD, rectangular, H size = V size = current track width.
*
* @param aValue is the text value
* @param aTextSize is the size of ref and value texts ( <= 0 to use board default values )
* @param aPadCount is number of pads
* @return the new module
*/
MODULE* createBaseFootprint( const wxString& aValue, int aTextSize, int aPadCount );
};

View File

@ -73,7 +73,7 @@
#include <tools/pcb_inspection_tool.h>
#include <tools/placement_tool.h>
#include <tools/pad_tool.h>
#include <tools/microwave_tool.h>
#include <microwave/microwave_tool.h>
#include <tools/position_relative_tool.h>
#include <tools/zone_filler_tool.h>
#include <tools/pcb_actions.h>

View File

@ -925,28 +925,6 @@ public:
*/
void SendCrossProbeNetName( const wxString& aNetName );
/**
* Function CreateMuWaveBaseFootprint
* create a basic footprint for micro wave applications.
* @param aValue = the text value
* @param aTextSize = the size of ref and value texts ( <= 0 to use board default values )
* @param aPadCount = number of pads
* Pads settings are:
* PAD_ATTRIB_SMD, rectangular, H size = V size = current track width.
*/
MODULE* CreateMuWaveBaseFootprint( const wxString& aValue, int aTextSize, int aPadCount );
/**
* Create_MuWaveComponent
* creates a module "GAP" or "STUB" used in micro wave designs.
* This module has 2 pads:
* PAD_ATTRIB_SMD, rectangular, H size = V size = current track width.
* the "gap" is isolation created between this 2 pads
*/
MODULE* Create_MuWaveComponent( int shape_type );
MODULE* Create_MuWavePolygonShape();
void ShowChangedLanguage() override;
/**

View File

@ -27,6 +27,7 @@
#include <pcbnew_id.h>
#include <bitmaps.h>
#include <layers_id_colors_and_visibility.h>
#include <microwave/microwave_tool.h>
#include <tool/tool_manager.h>
#include <router/pns_router.h>
@ -407,22 +408,22 @@ TOOL_ACTION PCB_ACTIONS::cleanupTracksAndVias( "pcbnew.GlobalEdit.cleanupTracksA
TOOL_ACTION PCB_ACTIONS::microwaveCreateGap( "pcbnew.MicrowaveTool.createGap",
AS_GLOBAL, 0, "",
_( "Add Microwave Gap" ), _( "Create gap of specified length for microwave applications" ),
mw_add_gap_xpm, AF_ACTIVATE, (void*) MWAVE_TOOL_SIMPLE_ID::GAP );
mw_add_gap_xpm, AF_ACTIVATE, (void*) MICROWAVE_FOOTPRINT_SHAPE::GAP );
TOOL_ACTION PCB_ACTIONS::microwaveCreateStub( "pcbnew.MicrowaveTool.createStub",
AS_GLOBAL, 0, "",
_( "Add Microwave Stub" ), _( "Create stub of specified length for microwave applications" ),
mw_add_stub_xpm, AF_ACTIVATE, (void*) MWAVE_TOOL_SIMPLE_ID::STUB );
mw_add_stub_xpm, AF_ACTIVATE, (void*) MICROWAVE_FOOTPRINT_SHAPE::STUB );
TOOL_ACTION PCB_ACTIONS::microwaveCreateStubArc( "pcbnew.MicrowaveTool.createStubArc",
AS_GLOBAL, 0, "",
_( "Add Microwave Arc Stub" ), _( "Create stub (arc) of specified size for microwave applications" ),
mw_add_stub_arc_xpm, AF_ACTIVATE, (void*) MWAVE_TOOL_SIMPLE_ID::STUB_ARC );
mw_add_stub_arc_xpm, AF_ACTIVATE, (void*) MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC );
TOOL_ACTION PCB_ACTIONS::microwaveCreateFunctionShape( "pcbnew.MicrowaveTool.createFunctionShape",
AS_GLOBAL, 0, "",
_( "Add Microwave Polygonal Shape" ), _( "Create a microwave polygonal shape from a list of vertices" ),
mw_add_gap_xpm, AF_ACTIVATE, (void*) MWAVE_TOOL_SIMPLE_ID::FUNCTION_SHAPE );
mw_add_gap_xpm, AF_ACTIVATE, (void*) MICROWAVE_FOOTPRINT_SHAPE::FUNCTION_SHAPE );
TOOL_ACTION PCB_ACTIONS::microwaveCreateLine( "pcbnew.MicrowaveTool.createLine",
AS_GLOBAL, 0, "",

View File

@ -33,17 +33,6 @@
class TOOL_EVENT;
class TOOL_MANAGER;
// Type of microwave items that are "simple" - just get placed on the board directly,
// without a graphical interactive setup stage
enum MWAVE_TOOL_SIMPLE_ID
{
GAP,
STUB,
STUB_ARC,
FUNCTION_SHAPE,
};
enum class ZONE_MODE
{
ADD, ///< Add a new zone/keepout with fresh settings