Mini projet en langage C et Qt5 pour la manipulation des abaques de Smith
Mini projet langage C et Qt5 pour la manipulation des abaques de Smith
Cet article propose en détaille un mini projet langage C et Qt5 pour la manipulation des abaques de Smith.
Cette abaque permet de construire votre circuit électronique en ajoutant/enlevant des composants (condensateurs, bobine, ligne de transmission, stub) et de récupérer l'impédance résultante finale, ou le coefficient de réflexion.
Vous pourrez télécharger le fichier au format zip il contient le code sources complet avec les fichiers media.
Compilation sur windows :
- Cd Build
- Qmake ../QSmithTool.pro
- make (ou mingw32-make sur win)
Extrait du code:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
//QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
qDebug() << "Starting application...";
QApplication app(argc, argv);
MainWindow w;
w.setWindowTitle(_SOFT_NAME);
w.setGeometry(QRect(200, 50, 1100, 600)); // (300, 50, 1200, 700));
w.setMinimumSize(500, 350);
w.setWindowIcon(QIcon(QString(":/myResources/Resources/appIco.ico")));
w.show();
return app.exec();
}
… …. …
#include "circuit.h"
Circuit::Circuit(double _frequencyGHz)
{
// Only used to add new component with suited default value
m_defaultFrequencyGHz = _frequencyGHz;
m_componentsList.clear();
// Pixmap vector initialization
for (int i=0 ; i<NB_COMP_TYPE-1 ; i++)
pixmapComponents[i] = new QPixmap();
pixmapSuppComp = new QPixmap();
pixmapDotAndPoint = new QPixmap();
// Pixmap components generation
generatePixmapsComponents(64,64);
qDebug() << "Comp pixmaps loaded : OK";
}
void Circuit::addComponent(Component comp, bool componentPreview)
{
int last=-1;
// preview : comp added at the end
if (componentPreview==true)
{
m_componentsList.append(comp);
m_componentsList.last().setPreviewState(componentPreview);
qDebug() << "Component preview added :" << m_componentsList.last().getName();
}
else // not preview, added after the last not preview comp
{
if (m_componentsList.size()==0)
last=-1;
else
{
// find last not preview comp
for (int i=0 ; i<m_componentsList.size() ; i++)
{
if (m_componentsList[i].getPreviewState()==false)
last=i;
}
}
m_componentsList.insert(last+1, comp);
m_componentsList[last+1].setPreviewState(componentPreview);
qDebug() << "Component added :" << m_componentsList[last+1].getName();
}
}
void Circuit::addComponent(ComponentType _compType, CompParametersList _parameters, bool _componentPreview)
{
Component comp(_compType, _parameters);
addComponent(comp, _componentPreview);
}
void Circuit::addDefaultComponent(ComponentType type, bool componentPreview)
{
switch (type)
{
case CAPA_S:
addNewCAPA_S(componentPreview); break;
case SELF_S:
addNewSELF_S(componentPreview); break;
case RESIST_S:
addNewRESIST_S(componentPreview); break;
case LINE_S:
addNewLINE_S(componentPreview); break;
case CAPA_P:
addNewCAPA_P(componentPreview); break;
case SELF_P:
addNewSELF_P(componentPreview); break;
case RESIST_P:
addNewRESIST_P(componentPreview); break;
case LINE_OPEN:
addNewLINE_OPEN(componentPreview); break;
case LINE_SHORT:
addNewLINE_SHORT(componentPreview); break;
case NOT_DEF:
break;
}
}
// CAPA_S, SELF_S, RESIST_S, LINE_S, CAPA_P, SELF_P, RESIST_P, LINE_OPEN, LINE_SHORT, NOT_DEF };
void Circuit::insertCAPA_S(int numCompBefore) {
m_componentsList.insert(numCompBefore, Component(CAPA_S, 400.0/m_defaultFrequencyGHz));
}
void Circuit::insertSELF_S(int numCompBefore) {
m_componentsList.insert(numCompBefore, Component(SELF_S, 0.08/m_defaultFrequencyGHz));
}
void Circuit::insertRESIST_S(int numCompBefore) {
m_componentsList.insert(numCompBefore, Component(RESIST_S, 0.3));
}
void Circuit::insertLINE_S(int numCompBefore)
{
CompParametersList paramList;
paramList.append(24.0/m_defaultFrequencyGHz); // 24mm mechanical length by default at 1GHz
paramList.append(1.0); // 50ohm normalized
paramList.append(1.0); // Er
m_componentsList.insert(numCompBefore, Component(LINE_S, paramList));
}
void Circuit::insertCAPA_P(int numCompBefore) {
m_componentsList.insert(numCompBefore, Component(CAPA_P, 400.0/m_defaultFrequencyGHz));
}
void Circuit::insertSELF_P(int numCompBefore) {
m_componentsList.insert(numCompBefore, Component(SELF_P, 0.06/m_defaultFrequencyGHz));
}
void Circuit::insertRESIST_P(int numCompBefore) {
m_componentsList.insert(numCompBefore, Component(RESIST_P, 0.2));
}
void Circuit::insertLINE_OPEN(int numCompBefore) {
CompParametersList paramList;
paramList.append(60.0/m_defaultFrequencyGHz); // 24mm mechanical length by default at 1GHz
paramList.append(1.0); // 50ohm normalized
paramList.append(1.0); // Er
m_componentsList.insert(numCompBefore, Component(LINE_OPEN, paramList));
}
void Circuit::insertLINE_SHORT(int numCompBefore) {
CompParametersList paramList;
paramList.append(20.0/m_defaultFrequencyGHz); // 24mm mechanical length by default at 1GHz
paramList.append(1.0); // 50ohm normalized
paramList.append(1.0); // Er
m_componentsList.insert(numCompBefore, Component(LINE_SHORT, paramList));
}
void Circuit::removeComponent(int numComp)
{
if (m_componentsList.size() >= numComp)
m_componentsList.remove(numComp);
}
void Circuit::removeLastComponent()
{
int compToDelete=-1;
if (!m_componentsList.isEmpty())
{
// find last not preview comp
for (int i=0 ; i<m_componentsList.size() ; i++)
{
if (m_componentsList[i].getPreviewState()==false)
compToDelete=i;
}
}
if (compToDelete!=-1)
m_componentsList.remove(compToDelete);
}
void Circuit::replaceComponent(int numComp, Component comp)
{
m_componentsList.replace(numComp, comp);
}
void Circuit::setPreviewComponent(ComponentType type)
{
removePreviewComponent();
if (type!=NOT_DEF)
{
addDefaultComponent(type, true);
}
}
void Circuit::removePreviewComponent()
{
if (!m_componentsList.isEmpty())
{
for (int i=0 ; i<m_componentsList.size() ; i++)
{
if (m_componentsList.last().getPreviewState()==true)
m_componentsList.removeLast();
}}}
ComponentType Circuit::getPreviewComponentType()
{
if (!m_componentsList.isEmpty())
{
if (m_componentsList.last().getPreviewState() == true)
return m_componentsList.last().getType();
}
return NOT_DEF;
}
void Circuit::clearAll()
{
m_componentsList.clear();
}
void Circuit::addNewCAPA_S(bool componentPreview) {
addComponent(Component(CAPA_S, 400.0/m_defaultFrequencyGHz), componentPreview); // normalized value (400 = 8pF with 50ohm at 1GHz)
}
void Circuit::addNewSELF_S(bool componentPreview) {
addComponent(Component(SELF_S, 0.08/m_defaultFrequencyGHz), componentPreview); // normalized value
}
void Circuit::addNewRESIST_S(bool componentPreview) {
addComponent(Component(RESIST_S, 0.3), componentPreview); // normalized value (0.3 = 15.0 with 50ohm)
}
void Circuit::addNewCAPA_P(bool componentPreview) {
if (getSize()==1) // if first component (to reach 50ohm with 3 components...)
addComponent(Component(CAPA_P, 250.0/m_defaultFrequencyGHz), componentPreview); // normalized value (400 = 8pF with 50ohm at 2GHz)
else if (getSize()==3)
addComponent(Component(CAPA_P, 100.0/m_defaultFrequencyGHz), componentPreview); // normalized value (400 = 8pF with 50ohm at 2GHz)
else
addComponent(Component(CAPA_P, 400.0/m_defaultFrequencyGHz), componentPreview); // normalized value (400 = 8pF with 50ohm at 2GHz)
}
void Circuit::addNewSELF_P(bool componentPreview) {
addComponent(Component(SELF_P, 0.06/m_defaultFrequencyGHz), componentPreview); // normalized value
}
void Circuit::addNewRESIST_P(bool componentPreview) {
addComponent(Component(RESIST_P, 0.2), componentPreview); // normalized value (0.2 = 10.0 with 50ohm)
}
void Circuit::addNewLINE_S(bool componentPreview)
{
CompParametersList paramList;
if (getSize()==2)
paramList.append(30.0/m_defaultFrequencyGHz);
else
paramList.append(24.0/m_defaultFrequencyGHz); // 24mm mechanical length by default at 1GHz
paramList.append(1.0); // 50ohm normalized
paramList.append(1.0); // Er
paramList.append(0.0); // alpha att.
addComponent(Component(LINE_S, paramList), componentPreview);
}