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 (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 offsetX;
37 int offsetY;
38 PAD* pad;
40 wxString msg;
41 wxString cmp_name;
42 int pad_count = 2;
43 EDA_ANGLE angle = ANGLE_0;
44
45 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
46
47 // Ref and value text size (O = use board default value.
48 // will be set to a value depending on the footprint size, if possible
49 int text_size = 0;
50
51 // Enter the size of the gap or stub
52 int gap_size = editFrame->GetDesignSettings().GetCurrentTrackWidth();
53
54 switch( aFootprintShape )
55 {
56 case MICROWAVE_FOOTPRINT_SHAPE::GAP:
57 msg = _( "Gap Size:" );
58 cmp_name = wxT( "muwave_gap" );
59 text_size = gap_size;
60 break;
61
62 case MICROWAVE_FOOTPRINT_SHAPE::STUB:
63 msg = _( "Stub Size:" );
64 cmp_name = wxT( "muwave_stub" );
65 text_size = gap_size;
66 pad_count = 2;
67 break;
68
69 case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC:
70 msg = _( "Arc Stub Radius Value:" );
71 cmp_name = wxT( "muwave_arcstub" );
72 pad_count = 1;
73 break;
74
75 default:
76 msg = wxT( "???" );
77 break;
78 }
79
80 wxString value = editFrame->StringFromValue( gap_size );
81 WX_TEXT_ENTRY_DIALOG dlg( editFrame, msg, _( "Create Microwave Footprint" ), value );
82
83 // TODO: why is this QuasiModal?
84 if( dlg.ShowQuasiModal() != wxID_OK )
85 return nullptr; // cancelled by user
86
87 value = dlg.GetValue();
88 gap_size = editFrame->ValueFromString( value );
89
90 bool abort = false;
91
92 if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC )
93 {
94 msg = wxT( "0.0" );
95 WX_TEXT_ENTRY_DIALOG angledlg( editFrame, _( "Angle in degrees:" ),
96 _( "Create Microwave Footprint" ), msg );
97
98 // TODO: why is this QuasiModal?
99 if( angledlg.ShowQuasiModal() != wxID_OK )
100 return nullptr; // cancelled by user
101
102 msg = angledlg.GetValue();
103
104 double fval;
105
106 if( !msg.ToDouble( &fval ) )
107 {
108 DisplayError( editFrame, _( "Incorrect number, abort" ) );
109 abort = true;
110 }
111
112 angle = EDA_ANGLE( fval, DEGREES_T );
113
114 if( angle < ANGLE_0 )
115 angle = -angle;
116
117 if( angle > ANGLE_180 )
118 angle = ANGLE_180;
119 }
120
121 if( abort )
122 return nullptr;
123
124 footprint = createBaseFootprint( cmp_name, text_size, pad_count );
125 auto it = footprint->Pads().begin();
126 pad = *it;
127
128 switch( aFootprintShape )
129 {
130 case MICROWAVE_FOOTPRINT_SHAPE::GAP: //Gap :
131 offsetX = -( gap_size + pad->GetSize( PADSTACK::ALL_LAYERS ).x ) / 2;
132
133 pad->SetX( pad->GetPosition().x + offsetX );
134
135 pad = *( it + 1 );
136
137 pad->SetX( pad->GetPosition().x + offsetX + gap_size + pad->GetSize( PADSTACK::ALL_LAYERS ).x );
138 break;
139
140 case MICROWAVE_FOOTPRINT_SHAPE::STUB: //Stub :
141 pad->SetNumber( wxT( "1" ) );
142 offsetY = -( gap_size + pad->GetSize( PADSTACK::ALL_LAYERS ).y ) / 2;
143
144 pad = *( it + 1 );
145 pad->SetSize( PADSTACK::ALL_LAYERS,
146 VECTOR2I( pad->GetSize( PADSTACK::ALL_LAYERS ).x, gap_size ) );
147 pad->SetY( pad->GetPosition().y + offsetY );
148 break;
149
150 case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC: // Arc Stub created by a polygonal approach:
151 {
152 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CUSTOM );
153 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::RECTANGLE );
154
155 int numPoints = ( angle.AsDegrees() / 5.0 ) + 3;
156 std::vector<VECTOR2I> polyPoints;
157 polyPoints.reserve( numPoints );
158
159 polyPoints.emplace_back( VECTOR2I( 0, 0 ) );
160
161 EDA_ANGLE theta = -angle / 2;
162
163 for( int ii = 1; ii < numPoints - 1; ii++ )
164 {
165 VECTOR2I pt( 0, -gap_size );
166 RotatePoint( &pt.x, &pt.y, theta );
167 polyPoints.push_back( pt );
168
169 theta += EDA_ANGLE( 5.0, DEGREES_T );
170
171 if( theta > angle / 2 )
172 theta = angle / 2;
173 }
174
175 // Close the polygon:
176 polyPoints.push_back( polyPoints[0] );
177
178 pad->AddPrimitivePoly( PADSTACK::ALL_LAYERS, polyPoints, 0, true ); // add a polygonal basic shape
179 break;
180 }
181
182 default:
183 break;
184 }
185
186 // Update the footprint and board
187 editFrame->OnModify();
188
189 return footprint;
190}
191
192
194 int aTextSize, int aPadCount )
195{
196 PCB_EDIT_FRAME& editFrame = *getEditFrame<PCB_EDIT_FRAME>();
197
198 FOOTPRINT* footprint = editFrame.CreateNewFootprint( aValue, wxEmptyString );
199
201
202 if( aTextSize > 0 )
203 {
204 footprint->Reference().SetTextSize( VECTOR2I( aTextSize, aTextSize ) );
205 footprint->Reference().SetTextThickness( aTextSize / 5 );
206 footprint->Value().SetTextSize( VECTOR2I( aTextSize, aTextSize ) );
207 footprint->Value().SetTextThickness( aTextSize / 5 );
208 }
209
210 // Create 2 pads used in gaps and stubs. The gap is between these 2 pads
211 // the stub is the pad 2
212 int pad_num = 1;
213
214 while( aPadCount-- )
215 {
216 PAD* pad = new PAD( footprint );
217
218 footprint->Add( pad, ADD_MODE::INSERT );
219
220 int tw = editFrame.GetDesignSettings().GetCurrentTrackWidth();
221 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( tw, tw ) );
222
223 pad->SetPosition( footprint->GetPosition() );
224 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::RECTANGLE );
225 pad->SetAttribute( PAD_ATTRIB::SMD );
226 pad->SetLayerSet( { F_Cu } );
227
228 pad->SetNumber( wxString::Format( wxT( "%d" ), pad_num ) );
229 pad_num++;
230 }
231
232 return footprint;
233}
int ShowQuasiModal()
double AsDegrees() const
Definition: eda_angle.h:113
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:419
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:196
void SetAttributes(int aAttributes)
Definition: footprint.h:291
PCB_FIELD & Value()
read/write accessors:
Definition: footprint.h:638
std::deque< PAD * > & Pads()
Definition: footprint.h:206
PCB_FIELD & Reference()
Definition: footprint.h:639
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:982
VECTOR2I GetPosition() const override
Definition: footprint.h:224
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:144
Definition: pad.h:54
FOOTPRINT * CreateNewFootprint(wxString aFootprintName, const wxString &aLibName)
Creates a new footprint, at position 0,0.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns 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
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, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_180
Definition: eda_angle.h:405
@ FP_EXCLUDE_FROM_POS_FILES
Definition: footprint.h:77
@ FP_EXCLUDE_FROM_BOM
Definition: footprint.h:78
@ F_Cu
Definition: layer_ids.h:64
MICROWAVE_FOOTPRINT_SHAPE
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:229
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691