2011-08-05 19:53:42 +00:00
|
|
|
/****************************************************************************
|
|
|
|
** From Qucs Attenuator Synthesis
|
|
|
|
** attenuator_classes.cpp
|
|
|
|
**
|
|
|
|
** since 2006/6/14
|
|
|
|
**
|
|
|
|
*****************************************************************************/
|
2012-09-21 17:02:54 +00:00
|
|
|
#include <cmath>
|
2011-08-05 19:53:42 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <attenuator_classes.h>
|
2019-09-29 15:25:56 +00:00
|
|
|
#include <i18n_utility.h>
|
2011-08-05 19:53:42 +00:00
|
|
|
|
|
|
|
// Bitmaps:
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <att_pi.xpm>
|
|
|
|
#include <att_tee.xpm>
|
|
|
|
#include <att_bridge.xpm>
|
|
|
|
#include <att_splitter.xpm>
|
2016-01-16 14:27:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Html texts showing the formulas
|
2019-10-01 15:03:00 +00:00
|
|
|
wxString pi_formula =
|
2016-01-16 14:27:42 +00:00
|
|
|
#include <pi_formula.h>
|
|
|
|
|
2019-10-01 15:03:00 +00:00
|
|
|
|
|
|
|
wxString tee_formula =
|
2016-01-16 14:27:42 +00:00
|
|
|
#include <tee_formula.h>
|
2019-10-01 15:03:00 +00:00
|
|
|
|
2016-01-16 14:27:42 +00:00
|
|
|
|
2019-09-29 15:25:56 +00:00
|
|
|
wxString bridget_tee_formula =
|
2016-01-16 14:27:42 +00:00
|
|
|
#include <bridget_tee_formula.h>
|
|
|
|
|
2019-10-01 15:03:00 +00:00
|
|
|
|
|
|
|
wxString splitter_formula =
|
2016-01-16 14:27:42 +00:00
|
|
|
#include <splitter_formula.h>
|
2019-10-01 15:03:00 +00:00
|
|
|
|
2016-01-16 14:27:42 +00:00
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ATTENUATOR::ATTENUATOR( ATTENUATORS_TYPE aTopology )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_base");
|
|
|
|
m_Error = false;
|
|
|
|
m_Topology = aTopology;
|
|
|
|
m_ResultCount = 3; // If 3 values must be calculated
|
|
|
|
m_Zin = 50; // Ohms
|
|
|
|
m_Zin_Enable = true;
|
|
|
|
m_Zout = 50; // Ohms
|
|
|
|
m_Attenuation = 6.0; // dB
|
|
|
|
m_Attenuation_Enable = true;
|
|
|
|
m_MinimumATT = 0.0; // dB
|
|
|
|
m_SchBitMap = NULL;
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = NULL;
|
2015-03-04 09:26:00 +00:00
|
|
|
|
|
|
|
// Initialize these variables mainly to avoid warnings from a static analyzer
|
|
|
|
m_R1 = 0.0;
|
|
|
|
m_R2 = 0.0;
|
|
|
|
m_R3 = 0.0;
|
|
|
|
Lmin = L = A = 0.0; // internal variable for temporary use
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR::~ATTENUATOR()
|
|
|
|
{
|
|
|
|
delete m_SchBitMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define KEYWORD_ATTENUATOR_ATT wxT( "Attenuation" )
|
|
|
|
#define KEYWORD_ATTENUATOR_ZIN wxT( "Zin" )
|
|
|
|
#define KEYWORD_ATTENUATOR_ZOUT wxT( "Zout" )
|
|
|
|
#define KEYWORD_ATTENUATORS wxT( "Attenuators/" )
|
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
void ATTENUATOR::ReadConfig( wxConfigBase* aConfig )
|
2011-08-05 19:53:42 +00:00
|
|
|
{
|
|
|
|
aConfig->SetPath( KEYWORD_ATTENUATORS + m_Name );
|
|
|
|
if( m_Attenuation_Enable )
|
|
|
|
aConfig->Read( KEYWORD_ATTENUATOR_ATT, &m_Attenuation, 6.0 );
|
|
|
|
aConfig->Read( KEYWORD_ATTENUATOR_ZIN, &m_Zin, 50.0 );
|
|
|
|
aConfig->Read( KEYWORD_ATTENUATOR_ZOUT, &m_Zout, 50.0 );
|
|
|
|
aConfig->SetPath( wxT( "../.." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
void ATTENUATOR::WriteConfig( wxConfigBase* aConfig )
|
2011-08-05 19:53:42 +00:00
|
|
|
{
|
|
|
|
aConfig->SetPath( KEYWORD_ATTENUATORS + m_Name );
|
|
|
|
aConfig->Write( KEYWORD_ATTENUATOR_ATT, m_Attenuation );
|
|
|
|
aConfig->Write( KEYWORD_ATTENUATOR_ZIN, m_Zin );
|
|
|
|
aConfig->Write( KEYWORD_ATTENUATOR_ZOUT, m_Zout );
|
|
|
|
aConfig->SetPath( wxT( "../.." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_PI::ATTENUATOR_PI() : ATTENUATOR( PI_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_pi");
|
|
|
|
m_SchBitMap = new wxBitmap( att_pi_xpm );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &pi_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_PI::Calculate()
|
|
|
|
{
|
|
|
|
if( !ATTENUATOR::Calculate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_R2 = ( (L - 1) / 2 ) * sqrt( m_Zin * m_Zout / L );
|
|
|
|
m_R1 = 1 / ( ( (A / m_Zin) ) - (1 / m_R2) );
|
|
|
|
m_R3 = 1 / ( ( (A / m_Zout) ) - (1 / m_R2) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_TEE::ATTENUATOR_TEE() : ATTENUATOR( TEE_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_tee");
|
|
|
|
m_SchBitMap = new wxBitmap( att_tee_xpm );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &tee_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_TEE::Calculate()
|
|
|
|
{
|
|
|
|
if( !ATTENUATOR::Calculate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_R2 = ( 2 * sqrt( L * m_Zin * m_Zout ) ) / (L - 1);
|
|
|
|
m_R1 = m_Zin * A - m_R2;
|
|
|
|
m_R3 = m_Zout * A - m_R2;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_BRIDGE::ATTENUATOR_BRIDGE() : ATTENUATOR( BRIDGE_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_bridge");
|
|
|
|
m_Zin_Enable = false;
|
|
|
|
m_ResultCount = 2;
|
|
|
|
m_SchBitMap = new wxBitmap( att_bridge_xpm );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &bridget_tee_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_BRIDGE::Calculate()
|
|
|
|
{
|
|
|
|
m_Zin = m_Zout;
|
|
|
|
if( !ATTENUATOR::Calculate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
L = pow( 10, m_Attenuation / 20 );
|
|
|
|
m_R1 = m_Zin * (L - 1);
|
|
|
|
m_R2 = m_Zin / (L - 1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ATTENUATOR_SPLITTER::ATTENUATOR_SPLITTER() : ATTENUATOR( SPLITTER_TYPE )
|
|
|
|
{
|
|
|
|
m_Name = wxT("att_splitter");
|
|
|
|
m_Attenuation_Enable = false;
|
|
|
|
m_Attenuation = 6.0;
|
|
|
|
m_MinimumATT = 6.0;
|
|
|
|
m_Zin_Enable = false;
|
|
|
|
m_SchBitMap = new wxBitmap( att_splitter_xpm );
|
2016-01-16 14:27:42 +00:00
|
|
|
m_FormulaName = &splitter_formula;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR_SPLITTER::Calculate()
|
|
|
|
{
|
|
|
|
m_Attenuation = 6.0;
|
|
|
|
m_Zin = m_Zout;
|
|
|
|
m_R1 = m_R2 = m_R3 = m_Zout / 3.0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ATTENUATOR::Calculate()
|
|
|
|
{
|
|
|
|
L = pow( 10, m_Attenuation / 10 );
|
|
|
|
|
|
|
|
A = (L + 1) / (L - 1);
|
|
|
|
|
|
|
|
if( m_Zin > m_Zout )
|
|
|
|
{
|
|
|
|
Lmin = (2 * m_Zin / m_Zout) - 1 + 2 *
|
|
|
|
sqrt( m_Zin / m_Zout * (m_Zin / m_Zout - 1) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Lmin = (2 * m_Zout / m_Zin) - 1 + 2 *
|
|
|
|
sqrt( m_Zout / m_Zin * (m_Zout / m_Zin - 1) );
|
|
|
|
}
|
|
|
|
m_MinimumATT = 10 * log10( Lmin );
|
|
|
|
|
|
|
|
if( m_MinimumATT > m_Attenuation )
|
|
|
|
{
|
|
|
|
m_Error = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Error = false;
|
|
|
|
return true;
|
|
|
|
}
|