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 if( dlg.ShowQuasiModal() != wxID_OK )
84 return nullptr; // cancelled by user
85
86 value = dlg.GetValue();
87 gap_size = editFrame->ValueFromString( value );
88
89 bool abort = false;
90
91 if( aFootprintShape == MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC )
92 {
93 msg = wxT( "0.0" );
94 WX_TEXT_ENTRY_DIALOG angledlg( editFrame, _( "Angle in degrees:" ),
95 _( "Create Microwave Footprint" ), msg );
96
97 if( angledlg.ShowQuasiModal() != wxID_OK )
98 return nullptr; // cancelled by user
99
100 msg = angledlg.GetValue();
101
102 double fval;
103
104 if( !msg.ToDouble( &fval ) )
105 {
106 DisplayError( editFrame, _( "Incorrect number, abort" ) );
107 abort = true;
108 }
109
110 angle = EDA_ANGLE( fval, DEGREES_T );
111
112 if( angle < ANGLE_0 )
113 angle = -angle;
114
115 if( angle > ANGLE_180 )
116 angle = ANGLE_180;
117 }
118
119 if( abort )
120 return nullptr;
121
122 footprint = createBaseFootprint( cmp_name, text_size, pad_count );
123 auto it = footprint->Pads().begin();
124 pad = *it;
125
126 switch( aFootprintShape )
127 {
128 case MICROWAVE_FOOTPRINT_SHAPE::GAP: //Gap :
129 offsetX = -( gap_size + pad->GetSize().x ) / 2;
130
131 pad->SetX( pad->GetPosition().x + offsetX );
132
133 pad = *( it + 1 );
134
135 pad->SetX( pad->GetPosition().x + offsetX + gap_size + pad->GetSize().x );
136 break;
137
138 case MICROWAVE_FOOTPRINT_SHAPE::STUB: //Stub :
139 pad->SetNumber( wxT( "1" ) );
140 offsetY = -( gap_size + pad->GetSize().y ) / 2;
141
142 pad = *( it + 1 );
143 pad->SetSize( VECTOR2I( pad->GetSize().x, gap_size ) );
144 pad->SetY( pad->GetPosition().y + offsetY );
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( VECTOR2I( 0, 0 ) );
157
158 EDA_ANGLE theta = -angle / 2;
159
160 for( int ii = 1; ii < numPoints - 1; ii++ )
161 {
162 VECTOR2I 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( VECTOR2I( aTextSize, aTextSize ) );
202 footprint->Reference().SetTextThickness( aTextSize / 5 );
203 footprint->Value().SetTextSize( VECTOR2I( 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
215 footprint->Add( pad, ADD_MODE::INSERT );
216
217 int tw = editFrame.GetDesignSettings().GetCurrentTrackWidth();
218 pad->SetSize( VECTOR2I( 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()
double AsDegrees() const
Definition: eda_angle.h:149
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:197
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:359
PCB_TEXT & Value()
read/write accessors:
Definition: footprint.h:569
void SetAttributes(int aAttributes)
Definition: footprint.h:253
PADS & Pads()
Definition: footprint.h:172
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:568
PCB_TEXT & Reference()
Definition: footprint.h:570
VECTOR2I GetPosition() const override
Definition: footprint.h:190
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:59
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.
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:283
This file is part of the common library.
#define _(s)
static constexpr EDA_ANGLE & ANGLE_180
Definition: eda_angle.h:433
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:429
@ FP_EXCLUDE_FROM_POS_FILES
Definition: footprint.h:71
@ FP_EXCLUDE_FROM_BOM
Definition: footprint.h:72
@ F_Cu
Definition: layer_ids.h:64
MICROWAVE_FOOTPRINT_SHAPE
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588