2017-02-23 08:00:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-01 17:24:31 +00:00
|
|
|
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-02-23 08:00:37 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/wx.h>
|
|
|
|
|
|
|
|
#include <base_units.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <board_commit.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
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 <geometry/geometry_utils.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <microwave/microwave_tool.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <validators.h>
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function gen_arc
|
|
|
|
* generates an arc using arc approximation by lines:
|
|
|
|
* Center aCenter
|
|
|
|
* Angle "angle" (in 0.1 deg)
|
|
|
|
* @param aBuffer = a buffer to store points.
|
|
|
|
* @param aStartPoint = starting point of arc.
|
|
|
|
* @param aCenter = arc centre.
|
|
|
|
* @param a_ArcAngle = arc length in 0.1 degrees.
|
|
|
|
*/
|
|
|
|
static void gen_arc( std::vector <wxPoint>& aBuffer,
|
|
|
|
const wxPoint& aStartPoint,
|
|
|
|
const wxPoint& aCenter,
|
2020-04-01 17:24:31 +00:00
|
|
|
int a_ArcAngle )
|
2017-02-23 08:00:37 +00:00
|
|
|
{
|
2019-05-16 13:46:54 +00:00
|
|
|
auto first_point = aStartPoint - aCenter;
|
|
|
|
auto radius = KiROUND( EuclideanNorm( first_point ) );
|
2020-09-10 23:05:20 +00:00
|
|
|
int seg_count = GetArcToSegmentCount( radius, ARC_HIGH_DEF, a_ArcAngle / 10.0 );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
double increment_angle = (double) a_ArcAngle * M_PI / 1800 / seg_count;
|
|
|
|
|
|
|
|
// Creates nb_seg point to approximate arc by segments:
|
|
|
|
for( int ii = 1; ii <= seg_count; ii++ )
|
|
|
|
{
|
|
|
|
double rot_angle = increment_angle * ii;
|
|
|
|
double fcos = cos( rot_angle );
|
|
|
|
double fsin = sin( rot_angle );
|
|
|
|
wxPoint currpt;
|
|
|
|
|
|
|
|
// Rotate current point:
|
|
|
|
currpt.x = KiROUND( ( first_point.x * fcos + first_point.y * fsin ) );
|
|
|
|
currpt.y = KiROUND( ( first_point.y * fcos - first_point.x * fsin ) );
|
|
|
|
|
|
|
|
auto corner = aCenter + currpt;
|
|
|
|
aBuffer.push_back( corner );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-24 17:02:12 +00:00
|
|
|
enum class INDUCTOR_S_SHAPE_RESULT
|
|
|
|
{
|
|
|
|
OK, /// S-shape constructed
|
|
|
|
TOO_LONG, /// Requested length too long
|
|
|
|
TOO_SHORT, /// Requested length too short
|
|
|
|
NO_REPR, /// Requested length can't be represented
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-23 08:00:37 +00:00
|
|
|
/**
|
|
|
|
* Function BuildCornersList_S_Shape
|
|
|
|
* Create a path like a S-shaped coil
|
|
|
|
* @param aBuffer = a buffer where to store points (ends of segments)
|
|
|
|
* @param aStartPoint = starting point of the path
|
|
|
|
* @param aEndPoint = ending point of the path
|
|
|
|
* @param aLength = full length of the path
|
|
|
|
* @param aWidth = segment width
|
|
|
|
*/
|
2019-01-24 17:02:12 +00:00
|
|
|
static INDUCTOR_S_SHAPE_RESULT BuildCornersList_S_Shape( std::vector<wxPoint>& aBuffer,
|
|
|
|
const wxPoint& aStartPoint, const wxPoint& aEndPoint, int aLength, int aWidth )
|
2017-02-23 08:00:37 +00:00
|
|
|
{
|
|
|
|
/* We must determine:
|
|
|
|
* segm_count = number of segments perpendicular to the direction
|
|
|
|
* segm_len = length of a strand
|
|
|
|
* radius = radius of rounded parts of the coil
|
|
|
|
* stubs_len = length of the 2 stubs( segments parallel to the direction)
|
|
|
|
* connecting the start point to the start point of the S shape
|
|
|
|
* and the ending point to the end point of the S shape
|
|
|
|
* 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
|
2020-04-01 17:24:31 +00:00
|
|
|
* aInductorPattern.m_length = 2 * delta // connections to the coil
|
2017-02-23 08:00:37 +00:00
|
|
|
* + (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
|
|
|
|
*
|
|
|
|
* The constraints are:
|
|
|
|
* segm_count >= 2
|
|
|
|
* radius < m_Size.x
|
|
|
|
* Size.y = (radius * 4) + (2 * stubs_len)
|
|
|
|
* segm_len > radius * 2
|
|
|
|
*
|
|
|
|
* The calculation is conducted in the following way:
|
|
|
|
* first:
|
|
|
|
* segm_count = 2
|
|
|
|
* radius = 4 * Size.x (arbitrarily fixed value)
|
|
|
|
* Then:
|
|
|
|
* Increasing the number of segments to the desired length
|
|
|
|
* (radius decreases if necessary)
|
|
|
|
*/
|
|
|
|
wxPoint size;
|
|
|
|
|
|
|
|
// This scale factor adjusts the arc length to handle
|
|
|
|
// the arc to segment approximation.
|
|
|
|
// because we use SEGM_COUNT_PER_360DEG segment to approximate a circle,
|
|
|
|
// the trace len must be corrected when calculated using arcs
|
|
|
|
// this factor adjust calculations and must be changed if SEGM_COUNT_PER_360DEG is modified
|
|
|
|
// because trace using segment is shorter the corresponding arc
|
|
|
|
// ADJUST_SIZE is the ratio between tline len and the arc len for an arc
|
|
|
|
// of 360/ADJUST_SIZE angle
|
|
|
|
#define ADJUST_SIZE 0.988
|
|
|
|
|
|
|
|
auto pt = aEndPoint - aStartPoint;
|
|
|
|
double angle = -ArcTangente( pt.y, pt.x );
|
|
|
|
int min_len = KiROUND( EuclideanNorm( pt ) );
|
|
|
|
int segm_len = 0; // length of segments
|
|
|
|
int full_len; // full len of shape (sum of length of all segments + arcs)
|
|
|
|
|
|
|
|
|
|
|
|
/* Note: calculations are made for a vertical coil (more easy calculations)
|
|
|
|
* and after points are rotated to their actual position
|
|
|
|
* So the main direction is the Y axis.
|
|
|
|
* the 2 stubs are on the Y axis
|
|
|
|
* the others segments are parallel to the X axis.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Calculate the size of area (for a vertical shape)
|
|
|
|
size.x = min_len / 2;
|
|
|
|
size.y = min_len;
|
|
|
|
|
|
|
|
// Choose a reasonable starting value for the radius of the arcs.
|
|
|
|
int radius = std::min( aWidth * 5, size.x / 4 );
|
|
|
|
|
|
|
|
int segm_count; // number of full len segments
|
|
|
|
// the half size segments (first and last segment) are not counted here
|
|
|
|
int stubs_len = 0; // length of first or last segment (half size of others segments)
|
|
|
|
|
|
|
|
for( segm_count = 0; ; segm_count++ )
|
|
|
|
{
|
|
|
|
stubs_len = ( size.y - ( radius * 2 * (segm_count + 2 ) ) ) / 2;
|
|
|
|
|
|
|
|
if( stubs_len < size.y / 10 ) // Reduce radius.
|
|
|
|
{
|
|
|
|
stubs_len = size.y / 10;
|
|
|
|
radius = ( size.y - (2 * stubs_len) ) / ( 2 * (segm_count + 2) );
|
|
|
|
|
|
|
|
if( radius < aWidth ) // Radius too small.
|
|
|
|
{
|
|
|
|
// Unable to create line: Requested length value is too large for room
|
2019-01-24 17:02:12 +00:00
|
|
|
return INDUCTOR_S_SHAPE_RESULT::TOO_LONG;
|
2017-02-23 08:00:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
segm_len = size.x - ( radius * 2 );
|
|
|
|
full_len = 2 * stubs_len; // Length of coil connections.
|
|
|
|
full_len += segm_len * segm_count; // Length of full length segments.
|
|
|
|
full_len += KiROUND( ( segm_count + 2 ) * M_PI * ADJUST_SIZE * radius ); // Ard arcs len
|
|
|
|
full_len += segm_len - (2 * radius); // Length of first and last segments
|
|
|
|
// (half size segments len = segm_len/2 - radius).
|
|
|
|
|
|
|
|
if( full_len >= aLength )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust len by adjusting segm_len:
|
|
|
|
int delta_size = full_len - aLength;
|
|
|
|
|
|
|
|
// reduce len of the segm_count segments + 2 half size segments (= 1 full size segment)
|
|
|
|
segm_len -= delta_size / (segm_count + 1);
|
|
|
|
|
2019-01-24 17:02:12 +00:00
|
|
|
// at this point, it could still be that the requested length is too
|
|
|
|
// short (because 4 quarter-circles are too long)
|
|
|
|
// to fix this is a relatively complex numerical problem which probably
|
|
|
|
// needs a refactor in this area. For now, just reject these cases:
|
|
|
|
{
|
|
|
|
const int min_total_length = 2 * stubs_len + 2 * M_PI * ADJUST_SIZE * radius;
|
|
|
|
if( min_total_length > aLength )
|
|
|
|
{
|
|
|
|
// we can't express this inductor with 90-deg arcs of this radius
|
|
|
|
return INDUCTOR_S_SHAPE_RESULT::TOO_SHORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( segm_len - 2 * radius < 0 )
|
|
|
|
{
|
|
|
|
// we can't represent this exact requested length with this number
|
|
|
|
// of segments (using the current algorithm). This stems from when
|
|
|
|
// you add a segment, you also add another half-circle, so there's a
|
|
|
|
// little bit of "dead" space.
|
|
|
|
// It's a bit ugly to just reject the input, as it might be possible
|
|
|
|
// to tweak the radius, but, again, that probably needs a refactor.
|
|
|
|
return INDUCTOR_S_SHAPE_RESULT::NO_REPR;
|
|
|
|
}
|
|
|
|
|
2017-02-23 08:00:37 +00:00
|
|
|
// Generate first line (the first stub) and first arc (90 deg arc)
|
|
|
|
pt = aStartPoint;
|
|
|
|
aBuffer.push_back( pt );
|
|
|
|
pt.y += stubs_len;
|
|
|
|
aBuffer.push_back( pt );
|
|
|
|
|
|
|
|
auto centre = pt;
|
|
|
|
centre.x -= radius;
|
|
|
|
gen_arc( aBuffer, pt, centre, -900 );
|
|
|
|
pt = aBuffer.back();
|
|
|
|
|
|
|
|
int half_size_seg_len = segm_len / 2 - radius;
|
|
|
|
|
|
|
|
if( half_size_seg_len )
|
|
|
|
{
|
|
|
|
pt.x -= half_size_seg_len;
|
|
|
|
aBuffer.push_back( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create shape.
|
|
|
|
int ii;
|
|
|
|
int sign = 1;
|
|
|
|
segm_count += 1; // increase segm_count to create the last half_size segment
|
|
|
|
|
|
|
|
for( ii = 0; ii < segm_count; ii++ )
|
|
|
|
{
|
|
|
|
int arc_angle;
|
|
|
|
|
|
|
|
if( ii & 1 ) // odd order arcs are greater than 0
|
|
|
|
sign = -1;
|
|
|
|
else
|
|
|
|
sign = 1;
|
|
|
|
|
|
|
|
arc_angle = 1800 * sign;
|
|
|
|
centre = pt;
|
|
|
|
centre.y += radius;
|
|
|
|
gen_arc( aBuffer, pt, centre, arc_angle );
|
|
|
|
pt = aBuffer.back();
|
|
|
|
pt.x += segm_len * sign;
|
|
|
|
aBuffer.push_back( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
// The last point is false:
|
|
|
|
// it is the end of a full size segment, but must be
|
|
|
|
// the end of the second half_size segment. Change it.
|
|
|
|
sign *= -1;
|
|
|
|
aBuffer.back().x = aStartPoint.x + radius * sign;
|
|
|
|
|
|
|
|
// create last arc
|
|
|
|
pt = aBuffer.back();
|
|
|
|
centre = pt;
|
|
|
|
centre.y += radius;
|
|
|
|
gen_arc( aBuffer, pt, centre, 900 * sign );
|
|
|
|
|
|
|
|
// Rotate point
|
|
|
|
angle += 900;
|
|
|
|
|
|
|
|
for( unsigned jj = 0; jj < aBuffer.size(); jj++ )
|
|
|
|
{
|
2017-08-06 11:31:25 +00:00
|
|
|
RotatePoint( &aBuffer[jj], aStartPoint, angle );
|
2017-02-23 08:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// push last point (end point)
|
|
|
|
aBuffer.push_back( aEndPoint );
|
|
|
|
|
2019-01-24 17:02:12 +00:00
|
|
|
return INDUCTOR_S_SHAPE_RESULT::OK;
|
2017-02-23 08:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
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;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
auto inductorFP = std::unique_ptr<FOOTPRINT>( createMicrowaveInductor( pattern, errorMessage ) );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
// on any error, report if we can
|
2020-11-13 00:43:45 +00:00
|
|
|
if ( !inductorFP || !errorMessage.IsEmpty() )
|
2020-04-01 17:24:31 +00:00
|
|
|
{
|
|
|
|
if ( !errorMessage.IsEmpty() )
|
2020-08-31 13:19:57 +00:00
|
|
|
editFrame.ShowInfoBarError( errorMessage );
|
2020-04-01 17:24:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
// at this point, we can save the footprint
|
2020-11-13 00:43:45 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, inductorFP.get() );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
BOARD_COMMIT commit( this );
|
2020-11-13 00:43:45 +00:00
|
|
|
commit.Add( inductorFP.release() );
|
2020-04-01 17:24:31 +00:00
|
|
|
commit.Push( _("Add microwave inductor" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN& aInductorPattern,
|
|
|
|
wxString& aErrorMessage )
|
2017-02-23 08:00:37 +00:00
|
|
|
{
|
|
|
|
/* Build a microwave inductor footprint.
|
|
|
|
* - Length Mself.lng
|
|
|
|
* - Extremities Mself.m_Start and Mself.m_End
|
|
|
|
* We must determine:
|
|
|
|
* Mself.nbrin = number of segments perpendicular to the direction
|
|
|
|
* (The coil nbrin will demicercles + 1 + 2 1 / 4 circle)
|
|
|
|
* Mself.lbrin = length of a strand
|
|
|
|
* Mself.radius = radius of rounded parts of the coil
|
|
|
|
* Mself.delta = segments extremities connection between him and the coil even
|
|
|
|
*
|
|
|
|
* The equations are
|
|
|
|
* Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin
|
|
|
|
* Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius
|
|
|
|
* Mself.lng = 2 * Mself.delta / / connections to the coil
|
|
|
|
+ (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last
|
|
|
|
+ (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded
|
|
|
|
* Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit
|
|
|
|
*
|
|
|
|
* The constraints are:
|
|
|
|
* Nbrin >= 2
|
|
|
|
* Mself.radius < Mself.m_Size.x
|
|
|
|
* Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord
|
|
|
|
* Mself.lbrin> Mself.radius * 2
|
|
|
|
*
|
|
|
|
* The calculation is conducted in the following way:
|
|
|
|
* Initially:
|
|
|
|
* Nbrin = 2
|
|
|
|
* Radius = 4 * m_Size.x (arbitrarily fixed value)
|
|
|
|
* Then:
|
|
|
|
* Increasing the number of segments to the desired length
|
|
|
|
* (Radius decreases if necessary)
|
|
|
|
*/
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad;
|
2017-02-23 08:00:37 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
|
|
|
|
auto pt = aInductorPattern.m_End - aInductorPattern.m_Start;
|
|
|
|
int min_len = KiROUND( EuclideanNorm( pt ) );
|
2020-11-16 00:04:55 +00:00
|
|
|
aInductorPattern.m_Length = min_len;
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
// Enter the desired length.
|
2020-11-16 00:04:55 +00:00
|
|
|
msg = StringFromValue( editFrame.GetUserUnits(), aInductorPattern.m_Length );
|
2020-04-01 17:24:31 +00:00
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( &editFrame, _( "Length of Trace:" ), wxEmptyString, msg );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2021-02-21 15:01:36 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
2017-02-23 06:23:17 +00:00
|
|
|
return nullptr; // canceled by user
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
msg = dlg.GetValue();
|
2020-11-16 00:04:55 +00:00
|
|
|
aInductorPattern.m_Length = ValueFromString( editFrame.GetUserUnits(), msg );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
// Control values (ii = minimum length)
|
2020-11-16 00:04:55 +00:00
|
|
|
if( aInductorPattern.m_Length < min_len )
|
2017-02-23 08:00:37 +00:00
|
|
|
{
|
|
|
|
aErrorMessage = _( "Requested length < minimum length" );
|
2017-02-23 06:23:17 +00:00
|
|
|
return nullptr;
|
2017-02-23 08:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the elements.
|
|
|
|
std::vector <wxPoint> buffer;
|
2020-04-01 17:24:31 +00:00
|
|
|
const INDUCTOR_S_SHAPE_RESULT res = BuildCornersList_S_Shape( buffer, aInductorPattern.m_Start,
|
2021-02-26 13:49:40 +00:00
|
|
|
aInductorPattern.m_End,
|
|
|
|
aInductorPattern.m_Length,
|
|
|
|
aInductorPattern.m_Width );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2019-01-24 17:02:12 +00:00
|
|
|
switch( res )
|
2017-02-23 08:00:37 +00:00
|
|
|
{
|
2019-01-24 17:02:12 +00:00
|
|
|
case INDUCTOR_S_SHAPE_RESULT::TOO_LONG:
|
2017-02-23 08:00:37 +00:00
|
|
|
aErrorMessage = _( "Requested length too large" );
|
2017-02-23 06:23:17 +00:00
|
|
|
return nullptr;
|
2019-01-24 17:02:12 +00:00
|
|
|
case INDUCTOR_S_SHAPE_RESULT::TOO_SHORT:
|
|
|
|
aErrorMessage = _( "Requested length too small" );
|
|
|
|
return nullptr;
|
|
|
|
case INDUCTOR_S_SHAPE_RESULT::NO_REPR:
|
|
|
|
aErrorMessage = _( "Requested length can't be represented" );
|
|
|
|
return nullptr;
|
|
|
|
case INDUCTOR_S_SHAPE_RESULT::OK:
|
|
|
|
break;
|
2017-02-23 08:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate footprint. the value is also used as footprint name.
|
2017-02-23 06:23:17 +00:00
|
|
|
msg = "L";
|
2020-04-01 17:24:31 +00:00
|
|
|
WX_TEXT_ENTRY_DIALOG cmpdlg( &editFrame, _( "Component Value:" ), wxEmptyString, msg );
|
2020-11-10 21:20:03 +00:00
|
|
|
cmpdlg.SetTextValidator( FOOTPRINT_NAME_VALIDATOR( &msg ) );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2021-02-21 15:01:36 +00:00
|
|
|
if( ( cmpdlg.ShowQuasiModal() != wxID_OK ) || msg.IsEmpty() )
|
2017-02-23 06:23:17 +00:00
|
|
|
return nullptr; // Aborted by user
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = editFrame.CreateNewFootprint( msg );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->SetFPID( LIB_ID( wxEmptyString, wxT( "mw_inductor" ) ) );
|
2020-11-13 02:09:34 +00:00
|
|
|
footprint->SetAttributes( FP_EXCLUDE_FROM_POS_FILES | FP_EXCLUDE_FROM_BOM );
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->ClearFlags();
|
|
|
|
footprint->SetPosition( aInductorPattern.m_End );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
// Generate segments
|
|
|
|
for( unsigned jj = 1; jj < buffer.size(); jj++ )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_SHAPE* seg;
|
2020-11-08 21:29:04 +00:00
|
|
|
seg = new FP_SHAPE( footprint );
|
2020-10-04 23:34:59 +00:00
|
|
|
seg->SetStart( buffer[jj - 1] );
|
|
|
|
seg->SetEnd( buffer[jj] );
|
|
|
|
seg->SetWidth( aInductorPattern.m_Width );
|
2020-11-08 21:29:04 +00:00
|
|
|
seg->SetLayer( footprint->GetLayer() );
|
2020-10-04 23:34:59 +00:00
|
|
|
seg->SetShape( S_SEGMENT );
|
2020-11-08 21:29:04 +00:00
|
|
|
seg->SetStart0( seg->GetStart() - footprint->GetPosition() );
|
|
|
|
seg->SetEnd0( seg->GetEnd() - footprint->GetPosition() );
|
|
|
|
footprint->Add( seg );
|
2017-02-23 08:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Place a pad on each end of coil.
|
2020-11-12 22:30:02 +00:00
|
|
|
pad = new PAD( footprint );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Add( pad );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2017-08-11 09:22:13 +00:00
|
|
|
pad->SetName( "1" );
|
2020-04-01 17:24:31 +00:00
|
|
|
pad->SetPosition( aInductorPattern.m_End );
|
2020-11-08 21:29:04 +00:00
|
|
|
pad->SetPos0( pad->GetPosition() - footprint->GetPosition() );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
pad->SetSize( wxSize( aInductorPattern.m_Width, aInductorPattern.m_Width ) );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
pad->SetLayerSet( LSET( footprint->GetLayer() ) );
|
2017-02-23 08:00:37 +00:00
|
|
|
pad->SetAttribute( PAD_ATTRIB_SMD );
|
|
|
|
pad->SetShape( PAD_SHAPE_CIRCLE );
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* newpad = new PAD( *pad );
|
2020-08-10 13:22:02 +00:00
|
|
|
const_cast<KIID&>( newpad->m_Uuid ) = KIID();
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
footprint->Add( newpad );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
pad = newpad;
|
2017-08-11 09:22:13 +00:00
|
|
|
pad->SetName( "2" );
|
2020-04-01 17:24:31 +00:00
|
|
|
pad->SetPosition( aInductorPattern.m_Start );
|
2020-11-08 21:29:04 +00:00
|
|
|
pad->SetPos0( pad->GetPosition() - footprint->GetPosition() );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
// Modify text positions.
|
2020-04-01 17:24:31 +00:00
|
|
|
wxPoint refPos( ( aInductorPattern.m_Start.x + aInductorPattern.m_End.x ) / 2,
|
|
|
|
( aInductorPattern.m_Start.y + aInductorPattern.m_End.y ) / 2 );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
|
|
|
wxPoint valPos = refPos;
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
refPos.y -= footprint->Reference().GetTextSize().y;
|
|
|
|
footprint->Reference().SetPosition( refPos );
|
|
|
|
valPos.y += footprint->Value().GetTextSize().y;
|
|
|
|
footprint->Value().SetPosition( valPos );
|
2017-02-23 08:00:37 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
return footprint;
|
2017-02-23 08:00:37 +00:00
|
|
|
}
|