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; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include <cmath>
26
27#include <wx/colour.h>
28#include <wx/settings.h>
29
30#include "transline.h"
31#include "units.h"
32
33// Functions to Read/Write parameters in pcb_calculator main frame:
34// They are wrapper to actual functions, so all transline functions do not
35// depend on Graphic User Interface
36void SetPropertyInDialog( enum PRMS_ID aPrmId, double value );
37
38/* Puts the text into the given result line.
39*/
40void SetResultInDialog( int line, const char* text );
41
42/* print aValue into the given result line.
43*/
44void SetResultInDialog( int aLineNumber, double aValue, const char* aText );
45
46/* Returns a named property value. */
47double GetPropertyInDialog( enum PRMS_ID aPrmId );
48
49// Returns true if the param aPrmId is selected
50// Has meaning only for params that have a radio button
51bool IsSelectedInDialog( enum PRMS_ID aPrmId );
52
58void SetPropertyBgColorInDialog( enum PRMS_ID aPrmId, const KIGFX::COLOR4D* aCol );
59
60
61/* Constructor creates a transmission line instance. */
63{
65 m_Name = nullptr;
66 Init();
67}
68
69
70/* Destructor destroys a transmission line instance. */
74
75
77{
78 wxColour wxcol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
79 okCol = KIGFX::COLOR4D( wxcol );
80 okCol.r = wxcol.Red() / 255.0;
81 okCol.g = wxcol.Green() / 255.0;
82 okCol.b = wxcol.Blue() / 255.0;
83 int i;
84 // Initialize these variables mainly to avoid warnings from a static analyzer
85 for( i = 0; i < EXTRA_PRMS_COUNT; ++i )
86 {
87 m_parameters[i] = 0;
88 }
89
90 // 1 GHz spec defaults to the canonical FR-4 reporting point for Er and tan delta.
93
94 // Soldermask defaults. SOLDERMASK_PRESENT = 0 keeps the math path bit-identical to
95 // the un-coated baseline. Thickness 20 um, er 3.5, tan d 0.025 match a typical green
96 // LPI; fills-gaps defaults on because standard LPI processes flood the CPW slots.
102}
103
104
105/* Sets a named property to the given value, access through the
106 * application.
107 */
108void TRANSLINE::setProperty( enum PRMS_ID aPrmId, double value )
109{
110 SetPropertyInDialog( aPrmId, value );
111}
112
113
114/*
115 *Returns true if the param aPrmId is selected
116 * Has meaning only for params that have a radio button
117 */
119{
120 return IsSelectedInDialog( aPrmId );
121}
122
123
124/* Puts the text into the given result line.
125*/
126void TRANSLINE::setResult( int line, const char* text )
127{
128 SetResultInDialog( line, text );
129}
130
131
132void TRANSLINE::setResult( int line, double value, const char* text )
133{
134 SetResultInDialog( line, value, text );
135}
136
137
138/* Returns a property value. */
139double TRANSLINE::getProperty( enum PRMS_ID aPrmId )
140{
141 return GetPropertyInDialog( aPrmId );
142}
143
144
150{
151 for( int i = 0; i < DUMMY_PRM; ++i )
152 {
153 m_parameters[i] = getProperty( (PRMS_ID) i );
155 }
156
160}
161
162
169{
170 // Do not check for values that are results of analyzing / synthesizing
171 // Do not check for transline specific incompatibilities ( like " conductor height should be lesser than dielectric height")
172 if( !std::isfinite( m_parameters[EPSILONR_PRM] ) || m_parameters[EPSILONR_PRM] <= 0 )
174
175 if( !std::isfinite( m_parameters[TAND_PRM] ) || m_parameters[TAND_PRM] < 0 )
177
178 if( !std::isfinite( m_parameters[RHO_PRM] ) || m_parameters[RHO_PRM] < 0 )
180
181 if( !std::isfinite( m_parameters[H_PRM] ) || m_parameters[H_PRM] < 0 )
183
184 if( !std::isfinite( m_parameters[TWISTEDPAIR_TWIST_PRM] )
187
188 if( !std::isfinite( m_parameters[STRIPLINE_A_PRM] ) || m_parameters[STRIPLINE_A_PRM] <= 0 )
190
191 // Warn on non-positive or non-finite H_T, and also on the regime where the cover
192 // correction breaks down (air gap below roughly the conductor thickness plus 10 percent
193 // of the substrate height).
194 if( !std::isfinite( m_parameters[H_T_PRM] ) || m_parameters[H_T_PRM] <= 0
195 || ( std::isfinite( m_parameters[H_PRM] ) && m_parameters[H_PRM] > 0
196 && std::isfinite( m_parameters[T_PRM] )
198 {
200 }
201
202 // Wadell Sec. 3.6.3 (off-center stripline) claims +/-2 percent accuracy only when the strip
203 // plane sits inside 0.2 < a/h < 0.8 and the strip-thickness ratio t/h stays below 0.2. Flag
204 // STRIPLINE_A_PRM and T_PRM when we leave that regime so the UI can warn that the offset
205 // correction is extrapolating outside its fit range.
206 if( std::isfinite( m_parameters[STRIPLINE_A_PRM] )
208 && std::isfinite( m_parameters[H_PRM] )
209 && m_parameters[H_PRM] > 0 )
210 {
211 const double aRatio = m_parameters[STRIPLINE_A_PRM] / m_parameters[H_PRM];
212
213 if( aRatio < 0.2 || aRatio > 0.8 )
215 }
216
217 if( std::isfinite( m_parameters[T_PRM] )
218 && m_parameters[T_PRM] > 0
219 && std::isfinite( m_parameters[H_PRM] )
220 && m_parameters[H_PRM] > 0
221 && ( m_parameters[T_PRM] / m_parameters[H_PRM] ) > 0.2 )
222 {
224 }
225
226 // How can we check ROUGH_PRM ?
227
228 if( !std::isfinite( m_parameters[MUR_PRM] ) || m_parameters[MUR_PRM] < 0 )
230
231 if( !std::isfinite( m_parameters[TWISTEDPAIR_EPSILONR_ENV_PRM] )
234
235 if( !std::isfinite( m_parameters[MURC_PRM] ) || m_parameters[MURC_PRM] < 0 )
237
238 if( !std::isfinite( m_parameters[FREQUENCY_PRM] ) || m_parameters[FREQUENCY_PRM] <= 0 )
240}
241
243{
246 calcAnalyze();
247 showAnalyze();
248 show_results();
249}
250
259
260
268{
269 double depth;
270 depth = 1.0
273 return depth;
274}
275
276
289void TRANSLINE::setErrorLevel( PRMS_ID aP, char aErrorLevel )
290{
291 switch( aErrorLevel )
292 {
295 default: SetPropertyBgColorInDialog( aP, &okCol ); break;
296 }
297}
298
299
301{
302 switch( aStatus )
303 {
307 }
308
309 return TRANSLINE_OK;
310}
311
312
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
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:71
virtual void showSynthesize()
Shows analysis results and checks for errors / warnings.
Definition transline.h:128
bool isSelected(enum PRMS_ID aPrmId)
KIGFX::COLOR4D warnCol
Definition transline.h:138
double getProperty(enum PRMS_ID aPrmId)
void Init()
Definition transline.cpp:76
virtual void calcSynthesize()
Computation for synthesis.
Definition transline.h:118
KIGFX::COLOR4D okCol
Definition transline.h:139
void setResult(int, double, const char *)
double m_parameters[EXTRA_PRMS_COUNT]
Definition transline.h:142
KIGFX::COLOR4D errCol
Definition transline.h:137
virtual void getProperties()
@function getProperties
void checkProperties()
@function checkProperties
void analyze()
virtual void synthesize()
const char * m_Name
Definition transline.h:93
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:123
double skin_depth()
@function skin_depth calculate skin depth
virtual void show_results()
Shows results.
Definition transline.h:133
virtual void calcAnalyze()
Computation for analysis.
Definition transline.h:113
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:83
@ EPSILON_EFF_PRM
Definition transline.h:76
@ SOLDERMASK_PRESENT_PRM
Definition transline.h:79
@ SIGMA_PRM
Definition transline.h:71
@ DIELECTRIC_MODEL_PRM
Definition transline.h:77
@ EPSILONR_SPEC_FREQ_PRM
Definition transline.h:78
@ SKIN_DEPTH_PRM
Definition transline.h:72
@ SOLDERMASK_TAND_PRM
Definition transline.h:82
@ EXTRA_PRMS_COUNT
Definition transline.h:84
@ SOLDERMASK_EPSILONR_PRM
Definition transline.h:81
@ SOLDERMASK_THICKNESS_PRM
Definition transline.h:80
PRMS_ID
Definition transline.h:39
@ TWISTEDPAIR_EPSILONR_ENV_PRM
Definition transline.h:51
@ FREQUENCY_PRM
Definition transline.h:53
@ DUMMY_PRM
Definition transline.h:63
@ RHO_PRM
Definition transline.h:43
@ T_PRM
Definition transline.h:48
@ MURC_PRM
Definition transline.h:52
@ MUR_PRM
Definition transline.h:50
@ STRIPLINE_A_PRM
Definition transline.h:47
@ TAND_PRM
Definition transline.h:42
@ H_T_PRM
Definition transline.h:46
@ TWISTEDPAIR_TWIST_PRM
Definition transline.h:45
@ EPSILONR_PRM
Definition transline.h:41
@ H_PRM
Definition transline.h:44
#define TRANSLINE_OK
Definition transline.h:31
#define TRANSLINE_WARNING
Definition transline.h:32
#define TRANSLINE_ERROR
Definition transline.h:33
TRANSLINE_STATUS
Parameter status values.
TRANSLINE_PARAMETERS
All possible parameters used (as inputs or outputs) by the transmission line calculations.