KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20
22#include <footprint.h>
23#include <pad.h>
24#include <confirm.h>
27#include <trigo.h>
28
29
31{
32 int offsetX;
33 int offsetY;
34 PAD* pad;
36 wxString msg;
37 wxString cmp_name;
38 int pad_count = 2;
39 EDA_ANGLE angle = ANGLE_0;
40
42
43 // Ref and value text size (O = use board default value.
44 // will be set to a value depending on the footprint size, if possible
45 int text_size = 0;
46
47 // Enter the size of the gap or stub
48 int gap_size = editFrame->GetDesignSettings().GetCurrentTrackWidth();
49
50 switch( aFootprintShape )
51 {
53 msg = _( "Gap Size:" );
54 cmp_name = wxT( "muwave_gap" );
55 text_size = gap_size;
56 break;
57
59 msg = _( "Stub Size:" );
60 cmp_name = wxT( "muwave_stub" );
61 text_size = gap_size;
62 pad_count = 2;
63 break;
64
66 msg = _( "Arc Stub Radius Value:" );
67 cmp_name = wxT( "muwave_arcstub" );
68 pad_count = 1;
69 break;
70
71 default:
72 msg = wxT( "???" );
73 break;
74 }
75
76 wxString value = editFrame->StringFromValue( gap_size );
77 WX_TEXT_ENTRY_DIALOG dlg( editFrame, msg, _( "Create Microwave Footprint" ), value );
78
79 // TODO: why is this QuasiModal?
80 if( dlg.ShowQuasiModal() != wxID_OK )
81 return nullptr; // canceled by user
82
83 value = dlg.GetValue();
84 gap_size = editFrame->ValueFromString( value );
85
86 bool abort = false;
87
88 if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC )
89 {
90 msg = wxT( "0.0" );
91 WX_TEXT_ENTRY_DIALOG angledlg( editFrame, _( "Angle in degrees:" ),
92 _( "Create Microwave Footprint" ), msg );
93
94 // TODO: why is this QuasiModal?
95 if( angledlg.ShowQuasiModal() != wxID_OK )
96 return nullptr; // canceled by user
97
98 msg = angledlg.GetValue();
99
100 double fval;
101
102 if( !msg.ToDouble( &fval ) )
103 {
104 DisplayError( editFrame, _( "Incorrect number, abort" ) );
105 abort = true;
106 }
107
108 angle = EDA_ANGLE( fval, DEGREES_T );
109
110 if( angle < ANGLE_0 )
111 angle = -angle;
112
113 if( angle > ANGLE_180 )
114 angle = ANGLE_180;
115 }
116
117 if( abort )
118 return nullptr;
119
120 footprint = createBaseFootprint( cmp_name, text_size, pad_count );
121 auto it = footprint->Pads().begin();
122 pad = *it;
123
124 switch( aFootprintShape )
125 {
127 offsetX = -( gap_size + pad->GetSize( PADSTACK::ALL_LAYERS ).x ) / 2;
128
129 pad->SetX( pad->GetPosition().x + offsetX );
130
131 pad = *( it + 1 );
132
133 pad->SetX( pad->GetPosition().x + offsetX + gap_size + pad->GetSize( PADSTACK::ALL_LAYERS ).x );
134 break;
135
137 pad->SetNumber( wxT( "1" ) );
138 offsetY = -( gap_size + pad->GetSize( PADSTACK::ALL_LAYERS ).y ) / 2;
139
140 pad = *( it + 1 );
141 pad->SetSize( PADSTACK::ALL_LAYERS,
142 VECTOR2I( pad->GetSize( PADSTACK::ALL_LAYERS ).x, gap_size ) );
143 pad->SetY( pad->GetPosition().y + offsetY );
144 break;
145
146 case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC: // Arc Stub created by a polygonal approach:
147 {
149 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::RECTANGLE );
150
151 int numPoints = ( angle.AsDegrees() / 5.0 ) + 3;
152 std::vector<VECTOR2I> polyPoints;
153 polyPoints.reserve( numPoints );
154
155 polyPoints.emplace_back( VECTOR2I( 0, 0 ) );
156
157 EDA_ANGLE theta = -angle / 2;
158
159 for( int ii = 1; ii < numPoints - 1; ii++ )
160 {
161 VECTOR2I pt( 0, -gap_size );
162 RotatePoint( &pt.x, &pt.y, theta );
163 polyPoints.push_back( pt );
164
165 theta += EDA_ANGLE( 5.0, DEGREES_T );
166
167 if( theta > angle / 2 )
168 theta = angle / 2;
169 }
170
171 // Close the polygon:
172 polyPoints.push_back( polyPoints[0] );
173
174 pad->AddPrimitivePoly( PADSTACK::ALL_LAYERS, polyPoints, 0, true ); // add a polygonal basic shape
175 break;
176 }
177
178 default:
179 break;
180 }
181
182 // Update the footprint and board
183 editFrame->OnModify();
184
185 return footprint;
186}
187
188
190 int aTextSize, int aPadCount )
191{
193
194 FOOTPRINT* footprint = editFrame.CreateNewFootprint( aValue, wxEmptyString );
195
197
198 if( aTextSize > 0 )
199 {
200 footprint->Reference().SetTextSize( VECTOR2I( aTextSize, aTextSize ) );
201 footprint->Reference().SetTextThickness( aTextSize / 5 );
202 footprint->Value().SetTextSize( VECTOR2I( aTextSize, aTextSize ) );
203 footprint->Value().SetTextThickness( aTextSize / 5 );
204 }
205
206 // Create 2 pads used in gaps and stubs. The gap is between these 2 pads
207 // the stub is the pad 2
208 int pad_num = 1;
209
210 while( aPadCount-- )
211 {
212 PAD* pad = new PAD( footprint );
213
215
216 int tw = editFrame.GetDesignSettings().GetCurrentTrackWidth();
217 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( tw, tw ) );
218
219 pad->SetPosition( footprint->GetPosition() );
221 pad->SetAttribute( PAD_ATTRIB::SMD );
222 pad->SetLayerSet( { F_Cu } );
223
224 pad->SetNumber( wxString::Format( wxT( "%d" ), pad_num ) );
225 pad_num++;
226 }
227
228 return footprint;
229}
double AsDegrees() const
Definition eda_angle.h:116
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.
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:177
Definition pad.h:61
FOOTPRINT * CreateNewFootprint(wxString aFootprintName, const wxString &aLibName)
Create a new footprint at position 0,0.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
The main frame for Pcbnew.
void OnModify() override
Must be called after a board change to set the modified flag.
FOOTPRINT * footprint() const
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
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)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
@ DEGREES_T
Definition eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:415
@ FP_EXCLUDE_FROM_POS_FILES
Definition footprint.h:85
@ FP_EXCLUDE_FROM_BOM
Definition footprint.h:86
@ F_Cu
Definition layer_ids.h:60
MICROWAVE_FOOTPRINT_SHAPE
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:99
@ RECTANGLE
Definition padstack.h:54
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:225
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683