KiCad PCB EDA Suite
Loading...
Searching...
No Matches
transline.cpp
Go to the documentation of this file.
1
2/*
3 * TRANSLINE.cpp - base for a transmission line implementation
4 *
5 * Copyright (C) 2005 Stefan Jahn <[email protected]>
6 * Modified for Kicad: 2018 jean-pierre.charras
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this package. If not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <cmath>
24
25#include <wx/colour.h>
26#include <wx/settings.h>
27
28#include "transline.h"
29#include "units.h"
30
31// Functions to Read/Write parameters in pcb_calculator main frame:
32// They are wrapper to actual functions, so all transline functions do not
33// depend on Graphic User Interface
34void SetPropertyInDialog( enum PRMS_ID aPrmId, double value );
35
39void SetResultInDialog( int line, const char* text );
40
44void SetResultInDialog( int aLineNumber, double aValue, const char* aText );
45
49double GetPropertyInDialog( enum PRMS_ID aPrmId );
50
56bool IsSelectedInDialog( enum PRMS_ID aPrmId );
57
64void SetPropertyBgColorInDialog( enum PRMS_ID aPrmId, const KIGFX::COLOR4D* aCol );
65
66
68{
70 m_Name = nullptr;
71 Init();
72}
73
74
78
79
81{
82 wxColour wxcol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
83 okCol = KIGFX::COLOR4D( wxcol );
84 okCol.r = wxcol.Red() / 255.0;
85 okCol.g = wxcol.Green() / 255.0;
86 okCol.b = wxcol.Blue() / 255.0;
87 int i;
88
89 // Initialize these variables mainly to avoid warnings from a static analyzer
90 for( i = 0; i < EXTRA_PRMS_COUNT; ++i )
91 {
92 m_parameters[i] = 0;
93 }
94
95 // 1 GHz spec defaults to the canonical FR-4 reporting point for Er and tan delta.
98
99 // Soldermask defaults. SOLDERMASK_PRESENT = 0 keeps the math path bit-identical to
100 // the un-coated baseline. Thickness 20 um, er 3.5, tan d 0.025 match a typical green
101 // LPI; fills-gaps defaults on because standard LPI processes flood the CPW slots.
107}
108
109
110void TRANSLINE::setProperty( enum PRMS_ID aPrmId, double value )
111{
112 SetPropertyInDialog( aPrmId, value );
113}
114
115
117{
118 return IsSelectedInDialog( aPrmId );
119}
120
121
122void TRANSLINE::setResult( int aLine, const char* aText )
123{
124 SetResultInDialog( aLine, aText );
125}
126
127
128void TRANSLINE::setResult( int aLine, double aValue, const char* aText )
129{
130 SetResultInDialog( aLine, aValue, aText );
131}
132
133
134double TRANSLINE::getProperty( enum PRMS_ID aPrmId )
135{
136 return GetPropertyInDialog( aPrmId );
137}
138
139
141{
142 for( int i = 0; i < DUMMY_PRM; ++i )
143 {
144 m_parameters[i] = getProperty( (PRMS_ID) i );
146 }
147
151}
152
153
155{
156 // Do not check for values that are results of analyzing / synthesizing
157 // Do not check for transline specific incompatibilities ( like " conductor height should be lesser than
158 // dielectric height")
159 if( !std::isfinite( m_parameters[EPSILONR_PRM] ) || m_parameters[EPSILONR_PRM] <= 0 )
161
162 if( !std::isfinite( m_parameters[TAND_PRM] ) || m_parameters[TAND_PRM] < 0 )
164
165 if( !std::isfinite( m_parameters[RHO_PRM] ) || m_parameters[RHO_PRM] < 0 )
167
168 if( !std::isfinite( m_parameters[H_PRM] ) || m_parameters[H_PRM] < 0 )
170
171 if( !std::isfinite( m_parameters[TWISTEDPAIR_TWIST_PRM] )
174
175 if( !std::isfinite( m_parameters[STRIPLINE_A_PRM] ) || m_parameters[STRIPLINE_A_PRM] <= 0 )
177
178 // Warn on non-positive or non-finite H_T, and also on the regime where the cover
179 // correction breaks down (air gap below roughly the conductor thickness plus 10 percent
180 // of the substrate height).
181 if( !std::isfinite( m_parameters[H_T_PRM] ) || m_parameters[H_T_PRM] <= 0
182 || ( std::isfinite( m_parameters[H_PRM] ) && m_parameters[H_PRM] > 0
183 && std::isfinite( m_parameters[T_PRM] )
185 {
187 }
188
189 // Wadell Sec. 3.6.3 (off-center stripline) claims +/-2 percent accuracy only when the strip
190 // plane sits inside 0.2 < a/h < 0.8 and the strip-thickness ratio t/h stays below 0.2. Flag
191 // STRIPLINE_A_PRM and T_PRM when we leave that regime so the UI can warn that the offset
192 // correction is extrapolating outside its fit range.
193 if( std::isfinite( m_parameters[STRIPLINE_A_PRM] )
195 && std::isfinite( m_parameters[H_PRM] )
196 && m_parameters[H_PRM] > 0 )
197 {
198 const double aRatio = m_parameters[STRIPLINE_A_PRM] / m_parameters[H_PRM];
199
200 if( aRatio < 0.2 || aRatio > 0.8 )
202 }
203
204 if( std::isfinite( m_parameters[T_PRM] )
205 && m_parameters[T_PRM] > 0
206 && std::isfinite( m_parameters[H_PRM] )
207 && m_parameters[H_PRM] > 0
208 && ( m_parameters[T_PRM] / m_parameters[H_PRM] ) > 0.2 )
209 {
211 }
212
213 // How can we check ROUGH_PRM ?
214
215 if( !std::isfinite( m_parameters[MUR_PRM] ) || m_parameters[MUR_PRM] < 0 )
217
218 if( !std::isfinite( m_parameters[TWISTEDPAIR_EPSILONR_ENV_PRM] )
221
222 if( !std::isfinite( m_parameters[MURC_PRM] ) || m_parameters[MURC_PRM] < 0 )
224
225 if( !std::isfinite( m_parameters[FREQUENCY_PRM] ) || m_parameters[FREQUENCY_PRM] <= 0 )
227}
228
229
231{
234 calcAnalyze();
235 showAnalyze();
236 show_results();
237}
238
239
248
249
251{
252 double depth;
253 depth = 1.0
256 return depth;
257}
258
259
260void TRANSLINE::setErrorLevel( PRMS_ID aP, char aErrorLevel )
261{
262 switch( aErrorLevel )
263 {
266 default: SetPropertyBgColorInDialog( aP, &okCol ); break;
267 }
268}
269
270
272{
273 switch( aStatus )
274 {
278 }
279
280 return TRANSLINE_OK;
281}
282
283
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
The base class for all transmission line calculations.
void SetParameter(const TRANSLINE_PARAMETERS aParam, const double aValue)
Sets the given calculation property.
virtual ~TRANSLINE()
Definition transline.cpp:75
virtual void showSynthesize()
Show analysis results and checks for errors / warnings.
Definition transline.h:152
bool isSelected(enum PRMS_ID aPrmId)
Return true if the param aPrmId is selected.
KIGFX::COLOR4D warnCol
Definition transline.h:162
double getProperty(enum PRMS_ID aPrmId)
Return a property value.
void Init()
Definition transline.cpp:80
virtual void calcSynthesize()
Computation for synthesis.
Definition transline.h:142
KIGFX::COLOR4D okCol
Definition transline.h:163
void setResult(int aLine, double aValue, const char *aText)
Put the text into the given result line.
double m_parameters[EXTRA_PRMS_COUNT]
Definition transline.h:166
KIGFX::COLOR4D errCol
Definition transline.h:161
virtual void getProperties()
Get all properties from the UI.
void checkProperties()
Check the input parameters (ie: negative length).
void analyze()
virtual void synthesize()
const char * m_Name
Definition transline.h:91
static char convertParameterStatusCode(TRANSLINE_STATUS aStatus)
Convert a TRANSLINE_STATUS status to a PCB Calculation status.
void setProperty(enum PRMS_ID aPrmId, double aValue)
Set a named property to the given value, access through the application.
void pushSoldermaskParameters(TRANSLINE_CALCULATION_BASE &aCalc, bool aIncludeFillsGaps=false) const
Push the mask-eligible subset of soldermask parameters (PRESENT, THICKNESS, EPSILONR,...
virtual void showAnalyze()
Show synthesis results and checks for errors / warnings.
Definition transline.h:147
double skin_depth()
Calculate skin depth.
virtual void show_results()
Show results.
Definition transline.h:157
virtual void calcAnalyze()
Computation for analysis.
Definition transline.h:137
void setErrorLevel(PRMS_ID, char)
Set an error / warning level for a given parameter.
TRANSLINE_PARAMETERS TCP
void SetPropertyInDialog(enum PRMS_ID aPrmId, double value)
void SetPropertyBgColorInDialog(enum PRMS_ID aPrmId, const KIGFX::COLOR4D *aCol)
Set the background color of a parameter.
double GetPropertyInDialog(enum PRMS_ID aPrmId)
Return a named property value.
void SetResultInDialog(int line, const char *aText)
Puts the text into the given result line.
bool IsSelectedInDialog(enum PRMS_ID aPrmId)
Return true if the param aPrmId is selected.
#define M_PI
void SetPropertyInDialog(enum PRMS_ID aPrmId, double value)
void SetPropertyBgColorInDialog(enum PRMS_ID aPrmId, const KIGFX::COLOR4D *aCol)
Set the background color of a parameter.
double GetPropertyInDialog(enum PRMS_ID aPrmId)
Return a named property value.
void SetResultInDialog(int line, const char *text)
Put the text into the given result line.
bool IsSelectedInDialog(enum PRMS_ID aPrmId)
Return true if the param aPrmId is selected.
@ SOLDERMASK_FILLS_GAPS_PRM
Definition transline.h:81
@ EPSILON_EFF_PRM
Definition transline.h:74
@ SOLDERMASK_PRESENT_PRM
Definition transline.h:77
@ SIGMA_PRM
Definition transline.h:69
@ DIELECTRIC_MODEL_PRM
Definition transline.h:75
@ EPSILONR_SPEC_FREQ_PRM
Definition transline.h:76
@ SKIN_DEPTH_PRM
Definition transline.h:70
@ SOLDERMASK_TAND_PRM
Definition transline.h:80
@ EXTRA_PRMS_COUNT
Definition transline.h:82
@ SOLDERMASK_EPSILONR_PRM
Definition transline.h:79
@ SOLDERMASK_THICKNESS_PRM
Definition transline.h:78
PRMS_ID
Definition transline.h:37
@ TWISTEDPAIR_EPSILONR_ENV_PRM
Definition transline.h:49
@ FREQUENCY_PRM
Definition transline.h:51
@ DUMMY_PRM
Definition transline.h:61
@ RHO_PRM
Definition transline.h:41
@ T_PRM
Definition transline.h:46
@ MURC_PRM
Definition transline.h:50
@ MUR_PRM
Definition transline.h:48
@ STRIPLINE_A_PRM
Definition transline.h:45
@ TAND_PRM
Definition transline.h:40
@ H_T_PRM
Definition transline.h:44
@ TWISTEDPAIR_TWIST_PRM
Definition transline.h:43
@ EPSILONR_PRM
Definition transline.h:39
@ H_PRM
Definition transline.h:42
#define TRANSLINE_OK
Definition transline.h:29
#define TRANSLINE_WARNING
Definition transline.h:30
#define TRANSLINE_ERROR
Definition transline.h:31
TRANSLINE_STATUS
Parameter status values.
TRANSLINE_PARAMETERS
All possible parameters used (as inputs or outputs) by the transmission line calculations.