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
36/* Puts the text into the given result line.
37*/
38void SetResultInDialog( int line, const char* text );
39
40/* print aValue into the given result line.
41*/
42void SetResultInDialog( int aLineNumber, double aValue, const char* aText );
43
44/* Returns a named property value. */
45double GetPropertyInDialog( enum PRMS_ID aPrmId );
46
47// Returns true if the param aPrmId is selected
48// Has meaning only for params that have a radio button
49bool IsSelectedInDialog( enum PRMS_ID aPrmId );
50
56void SetPropertyBgColorInDialog( enum PRMS_ID aPrmId, const KIGFX::COLOR4D* aCol );
57
58
59/* Constructor creates a transmission line instance. */
61{
63 m_Name = nullptr;
64 Init();
65}
66
67
68/* Destructor destroys a transmission line instance. */
72
73
75{
76 wxColour wxcol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
77 okCol = KIGFX::COLOR4D( wxcol );
78 okCol.r = wxcol.Red() / 255.0;
79 okCol.g = wxcol.Green() / 255.0;
80 okCol.b = wxcol.Blue() / 255.0;
81 int i;
82 // Initialize these variables mainly to avoid warnings from a static analyzer
83 for( i = 0; i < EXTRA_PRMS_COUNT; ++i )
84 {
85 m_parameters[i] = 0;
86 }
87
88 // 1 GHz spec defaults to the canonical FR-4 reporting point for Er and tan delta.
91
92 // Soldermask defaults. SOLDERMASK_PRESENT = 0 keeps the math path bit-identical to
93 // the un-coated baseline. Thickness 20 um, er 3.5, tan d 0.025 match a typical green
94 // LPI; fills-gaps defaults on because standard LPI processes flood the CPW slots.
100}
101
102
103/* Sets a named property to the given value, access through the
104 * application.
105 */
106void TRANSLINE::setProperty( enum PRMS_ID aPrmId, double value )
107{
108 SetPropertyInDialog( aPrmId, value );
109}
110
111
112/*
113 *Returns true if the param aPrmId is selected
114 * Has meaning only for params that have a radio button
115 */
117{
118 return IsSelectedInDialog( aPrmId );
119}
120
121
122/* Puts the text into the given result line.
123*/
124void TRANSLINE::setResult( int line, const char* text )
125{
126 SetResultInDialog( line, text );
127}
128
129
130void TRANSLINE::setResult( int line, double value, const char* text )
131{
132 SetResultInDialog( line, value, text );
133}
134
135
136/* Returns a property value. */
137double TRANSLINE::getProperty( enum PRMS_ID aPrmId )
138{
139 return GetPropertyInDialog( aPrmId );
140}
141
142
148{
149 for( int i = 0; i < DUMMY_PRM; ++i )
150 {
151 m_parameters[i] = getProperty( (PRMS_ID) i );
153 }
154
158}
159
160
167{
168 // Do not check for values that are results of analyzing / synthesizing
169 // Do not check for transline specific incompatibilities ( like " conductor height should be lesser than dielectric height")
170 if( !std::isfinite( m_parameters[EPSILONR_PRM] ) || m_parameters[EPSILONR_PRM] <= 0 )
172
173 if( !std::isfinite( m_parameters[TAND_PRM] ) || m_parameters[TAND_PRM] < 0 )
175
176 if( !std::isfinite( m_parameters[RHO_PRM] ) || m_parameters[RHO_PRM] < 0 )
178
179 if( !std::isfinite( m_parameters[H_PRM] ) || m_parameters[H_PRM] < 0 )
181
182 if( !std::isfinite( m_parameters[TWISTEDPAIR_TWIST_PRM] )
185
186 if( !std::isfinite( m_parameters[STRIPLINE_A_PRM] ) || m_parameters[STRIPLINE_A_PRM] <= 0 )
188
189 // Warn on non-positive or non-finite H_T, and also on the regime where the cover
190 // correction breaks down (air gap below roughly the conductor thickness plus 10 percent
191 // of the substrate height).
192 if( !std::isfinite( m_parameters[H_T_PRM] ) || m_parameters[H_T_PRM] <= 0
193 || ( std::isfinite( m_parameters[H_PRM] ) && m_parameters[H_PRM] > 0
194 && std::isfinite( m_parameters[T_PRM] )
196 {
198 }
199
200 // Wadell Sec. 3.6.3 (off-center stripline) claims +/-2 percent accuracy only when the strip
201 // plane sits inside 0.2 < a/h < 0.8 and the strip-thickness ratio t/h stays below 0.2. Flag
202 // STRIPLINE_A_PRM and T_PRM when we leave that regime so the UI can warn that the offset
203 // correction is extrapolating outside its fit range.
204 if( std::isfinite( m_parameters[STRIPLINE_A_PRM] )
206 && std::isfinite( m_parameters[H_PRM] )
207 && m_parameters[H_PRM] > 0 )
208 {
209 const double aRatio = m_parameters[STRIPLINE_A_PRM] / m_parameters[H_PRM];
210
211 if( aRatio < 0.2 || aRatio > 0.8 )
213 }
214
215 if( std::isfinite( m_parameters[T_PRM] )
216 && m_parameters[T_PRM] > 0
217 && std::isfinite( m_parameters[H_PRM] )
218 && m_parameters[H_PRM] > 0
219 && ( m_parameters[T_PRM] / m_parameters[H_PRM] ) > 0.2 )
220 {
222 }
223
224 // How can we check ROUGH_PRM ?
225
226 if( !std::isfinite( m_parameters[MUR_PRM] ) || m_parameters[MUR_PRM] < 0 )
228
229 if( !std::isfinite( m_parameters[TWISTEDPAIR_EPSILONR_ENV_PRM] )
232
233 if( !std::isfinite( m_parameters[MURC_PRM] ) || m_parameters[MURC_PRM] < 0 )
235
236 if( !std::isfinite( m_parameters[FREQUENCY_PRM] ) || m_parameters[FREQUENCY_PRM] <= 0 )
238}
239
241{
244 calcAnalyze();
245 showAnalyze();
246 show_results();
247}
248
257
258
266{
267 double depth;
268 depth = 1.0
271 return depth;
272}
273
274
287void TRANSLINE::setErrorLevel( PRMS_ID aP, char aErrorLevel )
288{
289 switch( aErrorLevel )
290 {
293 default: SetPropertyBgColorInDialog( aP, &okCol ); break;
294 }
295}
296
297
299{
300 switch( aStatus )
301 {
305 }
306
307 return TRANSLINE_OK;
308}
309
310
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:69
virtual void showSynthesize()
Shows analysis results and checks for errors / warnings.
Definition transline.h:126
bool isSelected(enum PRMS_ID aPrmId)
KIGFX::COLOR4D warnCol
Definition transline.h:136
double getProperty(enum PRMS_ID aPrmId)
void Init()
Definition transline.cpp:74
virtual void calcSynthesize()
Computation for synthesis.
Definition transline.h:116
KIGFX::COLOR4D okCol
Definition transline.h:137
void setResult(int, double, const char *)
double m_parameters[EXTRA_PRMS_COUNT]
Definition transline.h:140
KIGFX::COLOR4D errCol
Definition transline.h:135
virtual void getProperties()
@function getProperties
void checkProperties()
@function checkProperties
void analyze()
virtual void synthesize()
const char * m_Name
Definition transline.h:91
static char convertParameterStatusCode(TRANSLINE_STATUS aStatus)
Converts a TRANSLINE_PARAMETER status to a PCB Calculation status.
void setProperty(enum PRMS_ID aPrmId, double aValue)
void pushSoldermaskParameters(TRANSLINE_CALCULATION_BASE &aCalc, bool aIncludeFillsGaps=false) const
Push the mask-eligible subset of soldermask parameters (PRESENT, THICKNESS, EPSILONR,...
virtual void showAnalyze()
Shows synthesis results and checks for errors / warnings.
Definition transline.h:121
double skin_depth()
@function skin_depth calculate skin depth
virtual void show_results()
Shows results.
Definition transline.h:131
virtual void calcAnalyze()
Computation for analysis.
Definition transline.h:111
void setErrorLevel(PRMS_ID, char)
@function setErrorLevel
TRANSLINE_PARAMETERS TCP
void SetPropertyInDialog(enum PRMS_ID aPrmId, double value)
void SetPropertyBgColorInDialog(enum PRMS_ID aPrmId, const KIGFX::COLOR4D *aCol)
Function SetPropertyBgColorInDialog Set the background color of a parameter.
double GetPropertyInDialog(enum PRMS_ID aPrmId)
void SetResultInDialog(int line, const char *aText)
bool IsSelectedInDialog(enum PRMS_ID aPrmId)
#define M_PI
void SetPropertyInDialog(enum PRMS_ID aPrmId, double value)
void SetPropertyBgColorInDialog(enum PRMS_ID aPrmId, const KIGFX::COLOR4D *aCol)
Function SetPropertyBgColorInDialog Set the background color of a parameter.
double GetPropertyInDialog(enum PRMS_ID aPrmId)
void SetResultInDialog(int line, const char *text)
bool IsSelectedInDialog(enum PRMS_ID aPrmId)
@ 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.