KiCad PCB EDA Suite
microwave_footprint.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
26#include <footprint.h>
27#include <pad.h>
28#include <confirm.h>
31#include <trigo.h>
32
33
35{
36 int oX;
37 PAD* pad;
39 wxString msg;
40 wxString cmp_name;
41 int pad_count = 2;
43
44 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
45
46 // Ref and value text size (O = use board default value.
47 // will be set to a value depending on the footprint size, if possible
48 int text_size = 0;
49
50 // Enter the size of the gap or stub
51 int gap_size = editFrame->GetDesignSettings().GetCurrentTrackWidth();
52
53 switch( aFootprintShape )
54 {
56 msg = _( "Gap Size:" );
57 cmp_name = wxT( "muwave_gap" );
58 text_size = gap_size;
59 break;
60
62 msg = _( "Stub Size:" );
63 cmp_name = wxT( "muwave_stub" );
64 text_size = gap_size;
65 pad_count = 2;
66 break;
67
69 msg = _( "Arc Stub Radius Value:" );
70 cmp_name = wxT( "muwave_arcstub" );
71 pad_count = 1;
72 break;
73
74 default:
75 msg = wxT( "???" );
76 break;
77 }
78
79 wxString value = editFrame->StringFromValue( gap_size );
80 WX_TEXT_ENTRY_DIALOG dlg( editFrame, msg, _( "Create Microwave Footprint" ), value );
81
82 if( dlg.ShowQuasiModal() != wxID_OK )
83 return nullptr; // cancelled by user
84
85 value = dlg.GetValue();
86 gap_size = editFrame->ValueFromString( value );
87
88 bool abort = false;
89
90 if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC )
91 {
92 msg = wxT( "0.0" );
93 WX_TEXT_ENTRY_DIALOG angledlg( editFrame, _( "Angle in degrees:" ),
94 _( "Create Microwave Footprint" ), msg );
95
96 if( angledlg.ShowQuasiModal() != wxID_OK )
97 return nullptr; // cancelled by user
98
99 msg = angledlg.GetValue();
100
101 double fval;
102
103 if( !msg.ToDouble( &fval ) )
104 {
105 DisplayError( editFrame, _( "Incorrect number, abort" ) );
106 abort = true;
107 }
108
109 angle = EDA_ANGLE( fval, DEGREES_T );
110
111 if( angle < ANGLE_0 )
112 angle = -angle;
113
114 if( angle > ANGLE_180 )
116 }
117
118 if( abort )
119 return nullptr;
120
121 footprint = createBaseFootprint( cmp_name, text_size, pad_count );
122 auto it = footprint->Pads().begin();
123 pad = *it;
124
125 switch( aFootprintShape )
126 {
128 oX = -( gap_size + pad->GetSize().x ) / 2;
129 pad->SetX0( oX );
130
131 pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
132
133 pad = *( it + 1 );
134
135 pad->SetX0( oX + gap_size + pad->GetSize().x );
136 pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
137 break;
138
140 pad->SetNumber( wxT( "1" ) );
141 pad = *( it + 1 );
142 pad->SetY0( -( gap_size + pad->GetSize().y ) / 2 );
143 pad->SetSize( wxSize( pad->GetSize().x, gap_size ) );
144 pad->SetY( pad->GetPos0().y + pad->GetPosition().y );
145 break;
146
147 case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC: // Arc Stub created by a polygonal approach:
148 {
149 pad->SetShape( PAD_SHAPE::CUSTOM );
150 pad->SetAnchorPadShape( PAD_SHAPE::RECT );
151
152 int numPoints = ( angle.AsDegrees() / 5.0 ) + 3;
153 std::vector<VECTOR2I> polyPoints;
154 polyPoints.reserve( numPoints );
155
156 polyPoints.emplace_back( wxPoint( 0, 0 ) );
157
158 EDA_ANGLE theta = -angle / 2;
159
160 for( int ii = 1; ii < numPoints - 1; ii++ )
161 {
162 wxPoint pt( 0, -gap_size );
163 RotatePoint( &pt.x, &pt.y, theta );
164 polyPoints.push_back( pt );
165
166 theta += EDA_ANGLE( 5.0, DEGREES_T );
167
168 if( theta > angle / 2 )
169 theta = angle / 2;
170 }
171
172 // Close the polygon:
173 polyPoints.push_back( polyPoints[0] );
174
175 pad->AddPrimitivePoly( polyPoints, 0, true ); // add a polygonal basic shape
176 break;
177 }
178
179 default:
180 break;
181 }
182
183 // Update the footprint and board
184 editFrame->OnModify();
185
186 return footprint;
187}
188
189
191 int aTextSize, int aPadCount )
192{
193 PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
194
195 FOOTPRINT* footprint = editFrame.CreateNewFootprint( aValue, true );
196
198
199 if( aTextSize > 0 )
200 {
201 footprint->Reference().SetTextSize( wxSize( aTextSize, aTextSize ) );
202 footprint->Reference().SetTextThickness( aTextSize / 5 );
203 footprint->Value().SetTextSize( wxSize( aTextSize, aTextSize ) );
204 footprint->Value().SetTextThickness( aTextSize / 5 );
205 }
206
207 // Create 2 pads used in gaps and stubs. The gap is between these 2 pads
208 // the stub is the pad 2
209 int pad_num = 1;
210
211 while( aPadCount-- )
212 {
213 PAD* pad = new PAD( footprint );
214
216
217 int tw = editFrame.GetDesignSettings().GetCurrentTrackWidth();
218 pad->SetSize( wxSize( tw, tw ) );
219
220 pad->SetPosition( footprint->GetPosition() );
221 pad->SetShape( PAD_SHAPE::RECT );
222 pad->SetAttribute( PAD_ATTRIB::SMD );
223 pad->SetLayerSet( F_Cu );
224
225 pad->SetNumber( wxString::Format( wxT( "%d" ), pad_num ) );
226 pad_num++;
227 }
228
229 return footprint;
230}
int ShowQuasiModal()
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:185
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:347
void SetAttributes(int aAttributes)
Definition: footprint.h:246
PADS & Pads()
Definition: footprint.h:174
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:555
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:549
VECTOR2I GetPosition() const override
Definition: footprint.h:192
FP_TEXT & Reference()
Definition: footprint.h:556
FOOTPRINT * createFootprint(MICROWAVE_FOOTPRINT_SHAPE aFootprintShape)
Create a footprint "GAP" or "STUB" used in micro wave designs.
FOOTPRINT * createBaseFootprint(const wxString &aValue, int aTextSize, int aPadCount)
Create a basic footprint for micro wave applications.
Definition: pad.h:58
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
FOOTPRINT * CreateNewFootprint(const wxString &aFootprintName, bool aQuiet=false)
Creates a new footprint, at position 0,0.
The main frame for Pcbnew.
void OnModify() override
Must be called after a board change to set the modified flag.
FOOTPRINT * footprint() const
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aValue in internal units into a united string.
long long int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aTextValue in aUnits to internal units used by the frame.
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
This file is part of the common library.
#define _(s)
static constexpr EDA_ANGLE & ANGLE_180
Definition: eda_angle.h:416
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:412
@ FP_EXCLUDE_FROM_POS_FILES
Definition: footprint.h:69
@ FP_EXCLUDE_FROM_BOM
Definition: footprint.h:70
@ F_Cu
Definition: layer_ids.h:64
MICROWAVE_FOOTPRINT_SHAPE
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
@ SMD
Smd pad, appears on the solder paste layer (default)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183