Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature CDL netlist export #1165

Merged
merged 11 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qucs/components/ac_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void AC_Sim::recreate(Schematic*)
}
}

QString AC_Sim::spice_netlist(bool isXyce)
QString AC_Sim::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
QString s = SpiceModel + " ";
QString unit;
Expand All @@ -100,7 +100,7 @@ QString AC_Sim::spice_netlist(bool isXyce)
QString fstart = spicecompat::normalize_value(Props.at(1)->Value); // Start freq.
QString fstop = spicecompat::normalize_value(Props.at(2)->Value); // Stop freq.
s += QStringLiteral("%1 %2 \n").arg(fstart).arg(fstop);
if (!isXyce) s.remove(0,1);
if (dialect != spicecompat::SPICEXyce) s.remove(0,1);
return s.toLower();

}
2 changes: 1 addition & 1 deletion qucs/components/ac_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AC_Sim : public qucs::component::SimulationComponent {
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
void recreate(Schematic*);
QString spice_netlist(bool isXyce=false);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
};

#endif
4 changes: 3 additions & 1 deletion qucs/components/ampere_ac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ Element* Ampere_ac::info(QString& Name, char* &BitmapFile, bool getNewOne)
}


QString Ampere_ac::spice_netlist(bool)
QString Ampere_ac::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
Q_UNUSED(dialect);

QString s = spicecompat::check_refdes(Name,SpiceModel);

QString plus = spicecompat::normalize_node_name(Ports.at(1)->Connection->Name);
Expand Down
2 changes: 1 addition & 1 deletion qucs/components/ampere_ac.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Ampere_ac : public Component {
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
protected:
QString spice_netlist(bool isXyce = false);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
};

#endif
12 changes: 10 additions & 2 deletions qucs/components/ampere_dc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Ampere_dc::Ampere_dc()
SpiceModel = "I";

Props.append(new Property("I", "1 mA", true,
QObject::tr("current in Ampere")));
QObject::tr("current in Ampere")));

rotate(); // fix historical flaw
}
Expand All @@ -56,8 +56,10 @@ Ampere_dc::~Ampere_dc()
{
}

QString Ampere_dc::spice_netlist(bool)
QString Ampere_dc::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
Q_UNUSED(dialect);

QString s = spicecompat::check_refdes(Name,SpiceModel);

QString plus = Ports.at(1)->Connection->Name;
Expand All @@ -68,6 +70,12 @@ QString Ampere_dc::spice_netlist(bool)
.arg(spicecompat::normalize_value(Props.at(0)->Value));
return s;
}

QString Ampere_dc::cdl_netlist()
{
return spice_netlist(spicecompat::CDL);
}

Component* Ampere_dc::newOne()
{
return new Ampere_dc();
Expand Down
3 changes: 2 additions & 1 deletion qucs/components/ampere_dc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Ampere_dc : public Component {
~Ampere_dc();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString spice_netlist(bool isXyce = false);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
virtual QString cdl_netlist();
};

#endif
5 changes: 3 additions & 2 deletions qucs/components/biast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ Element* BiasT::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}

QString BiasT::spice_netlist(bool isXyce)
QString BiasT::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
Q_UNUSED(isXyce);
Q_UNUSED(dialect);

QString s;
QString L = spicecompat::normalize_value(getProperty("L")->Value);
QString C = spicecompat::normalize_value(getProperty("C")->Value);
Expand Down
2 changes: 1 addition & 1 deletion qucs/components/biast.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BiasT : public Component {
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
protected:
QString spice_netlist(bool isXyce);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
};

#endif
23 changes: 17 additions & 6 deletions qucs/components/bjt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Component* BJT::newOne()
return p;
}

QString BJT::spice_netlist(bool)
QString BJT::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
QString s = spicecompat::check_refdes(Name,SpiceModel);
QList<int> pin_seq;
Expand All @@ -60,17 +60,28 @@ QString BJT::spice_netlist(bool)

QString par_str = form_spice_param_list(spice_incompat,spice_tr);

if (getProperty("UseGlobTemp")->Value == "yes") {
s += QStringLiteral(" QMOD_%1 AREA=%2\n").arg(Name).arg(getProperty("Area")->Value);
const bool isDialectCDL(dialect == spicecompat::CDL);

if (getProperty("UseGlobTemp")->Value == "yes" || isDialectCDL) {
s += QStringLiteral(" QMOD_%1 %2=%3\n").arg(Name).arg(isDialectCDL ? "$EA" : "AREA").arg(getProperty("Area")->Value);
} else {
s += QStringLiteral(" QMOD_%1 AREA=%2 TEMP=%3\n").arg(Name).arg(getProperty("Area")->Value)
.arg(getProperty("Temp")->Value);
s += QStringLiteral(" QMOD_%1 AREA=%2 TEMP=%3\n").arg(Name).arg(getProperty("Area")->Value)
.arg(getProperty("Temp")->Value);
}

if (!isDialectCDL)
{
s += QStringLiteral(".MODEL QMOD_%1 %2 (%3)\n").arg(Name).arg(getProperty("Type")->Value).arg(par_str);
}
s += QStringLiteral(".MODEL QMOD_%1 %2 (%3)\n").arg(Name).arg(getProperty("Type")->Value).arg(par_str);

return s;
}

QString BJT::cdl_netlist()
{
return spice_netlist(spicecompat::CDL);
}

// -------------------------------------------------------
Element* BJT::info(QString& Name, char* &BitmapFile, bool getNewOne)
{
Expand Down
3 changes: 2 additions & 1 deletion qucs/components/bjt.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class BJT : public Basic_BJT {
protected:
void createSymbol();
QString netlist();
QString spice_netlist(bool isXyce = false);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
virtual QString cdl_netlist();
};

#endif
22 changes: 16 additions & 6 deletions qucs/components/bjtsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void BJTsub::createSymbol()
x2 = 30; y2 = 30;
}

QString BJTsub::spice_netlist(bool)
QString BJTsub::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
QString s = spicecompat::check_refdes(Name,SpiceModel);
QList<int> pin_seq;
Expand All @@ -219,14 +219,24 @@ QString BJTsub::spice_netlist(bool)

QString par_str = form_spice_param_list(spice_incompat,spice_tr);

if (getProperty("UseGlobTemp")->Value == "yes") {
s += QStringLiteral(" QMOD_%1 AREA=%2\n").arg(Name).arg(getProperty("Area")->Value);
const bool isDialectCDL(dialect == spicecompat::CDL);

if (getProperty("UseGlobTemp")->Value == "yes" || isDialectCDL) {
s += QStringLiteral(" QMOD_%1 %2=%3\n").arg(Name).arg(isDialectCDL ? "$EA" : "AREA").arg(getProperty("Area")->Value);
} else {
s += QStringLiteral(" QMOD_%1 AREA=%2 TEMP=%3\n").arg(Name).arg(getProperty("Area")->Value)
.arg(getProperty("Temp")->Value);
s += QStringLiteral(" QMOD_%1 AREA=%2 TEMP=%3\n").arg(Name).arg(getProperty("Area")->Value)
.arg(getProperty("Temp")->Value);
}

s += QStringLiteral(".MODEL QMOD_%1 %2 (%3)\n").arg(Name).arg(getProperty("Type")->Value).arg(par_str);
if (!isDialectCDL)
{
s += QStringLiteral(".MODEL QMOD_%1 %2 (%3)\n").arg(Name).arg(getProperty("Type")->Value).arg(par_str);
}

return s;
}

QString BJTsub::cdl_netlist()
{
return spice_netlist(spicecompat::CDL);
}
3 changes: 2 additions & 1 deletion qucs/components/bjtsub.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class BJTsub : public Basic_BJT {
static Element* info_pnp(QString&, char* &, bool getNewOne=false);

protected:
QString spice_netlist(bool isXyce);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
virtual QString cdl_netlist();
void createSymbol();
};

Expand Down
21 changes: 13 additions & 8 deletions qucs/components/capacitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Capacitor::Capacitor()
Description = QObject::tr("capacitor");

Props.append(new Property("C", "1 nF", true,
QObject::tr("capacitance in Farad")));
QObject::tr("capacitance in Farad")));
Props.append(new Property("V", "", false,
QObject::tr("initial voltage for transient simulation")));
QObject::tr("initial voltage for transient simulation")));
Props.append(new Property("Symbol", "neutral", false,
QObject::tr("schematic symbol")+" [neutral, polar]"));
QObject::tr("schematic symbol")+" [neutral, polar]"));

createSymbol();
tx = x1+4;
Expand All @@ -53,7 +53,7 @@ Element* Capacitor::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}

QString Capacitor::spice_netlist(bool)
QString Capacitor::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
QString s = spicecompat::check_refdes(Name,SpiceModel);

Expand All @@ -64,24 +64,29 @@ QString Capacitor::spice_netlist(bool)
s += " "+spicecompat::normalize_value(Props.at(0)->Value) + " ";
QString val = Props.at(1)->Value; // add inial voltage if presents
val = val.remove(' ').toUpper();
if (!val.isEmpty()) {
if (!val.isEmpty() && dialect != spicecompat::CDL) {
s += " IC=" + val;
}

return s+'\n';
}

QString Capacitor::cdl_netlist()
{
return spice_netlist(spicecompat::CDL);
}

QString Capacitor::va_code()
{
QString val = vacompat::normalize_value(Props.at(0)->Value);
QString plus = Ports.at(0)->Connection->Name;
QString minus = Ports.at(1)->Connection->Name;
QString minus = Ports.at(1)->Connection->Name;
QString s = "";
QString Vpm = vacompat::normalize_voltage(plus,minus);
if (Vpm.startsWith("(-")) Vpm.remove(1,1); // Make capacitor unipolar, remove starting minus
QString Ipm = vacompat::normalize_current(plus,minus,true);
QString Ipm = vacompat::normalize_current(plus,minus,true);
s += QStringLiteral("%1 <+ ddt( %2 * %3 );\n").arg(Ipm).arg(Vpm).arg(val);

return s;
}

Expand Down
3 changes: 2 additions & 1 deletion qucs/components/capacitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Capacitor : public MultiViewComponent {

protected:
void createSymbol();
QString spice_netlist(bool isXyce = false);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
virtual QString cdl_netlist();
QString va_code();
};

Expand Down
6 changes: 4 additions & 2 deletions qucs/components/capq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ Element* CapQ::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}

QString CapQ::spice_netlist(bool isXyce)
QString CapQ::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
Q_UNUSED(isXyce);
Q_UNUSED(dialect);

QString s;
QString pin1 = Ports.at(0)->Connection->Name;
pin1 = spicecompat::normalize_node_name(pin1);
Expand Down Expand Up @@ -124,3 +125,4 @@ QString CapQ::spice_netlist(bool isXyce)

return s;
}

2 changes: 1 addition & 1 deletion qucs/components/capq.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CapQ : public Component {
static Element* info(QString&, char* &, bool getNewOne=false);

protected:
QString spice_netlist(bool isXyce);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
};

#endif
20 changes: 11 additions & 9 deletions qucs/components/cccs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,29 @@ Element* CCCS::info(QString& Name, char* &BitmapFile, bool getNewOne)
}

QString CCCS::va_code()
{
QString Gain = vacompat::normalize_value(Props.at(0)->Value);
QString P1 = Ports.at(0)->Connection->Name;
{

QString Gain = vacompat::normalize_value(Props.at(0)->Value);
QString P1 = Ports.at(0)->Connection->Name;
QString P4 = Ports.at(1)->Connection->Name;
QString P3 = Ports.at(2)->Connection->Name;
QString P2 = Ports.at(3)->Connection->Name;
QString s = "";

QString Vpm = vacompat::normalize_voltage(P1,P2);
QString Ipm = vacompat::normalize_current(P1,P2,true);
QString Ipm = vacompat::normalize_current(P1,P2,true);
s += QStringLiteral(" %1 <+ %2 * 1e3;\n").arg(Ipm).arg(Vpm);
QString Vpm2 = vacompat::normalize_voltage(P4,P3);
QString Ipm2 = vacompat::normalize_current(P4,P3,true);
QString Ipm2 = vacompat::normalize_current(P4,P3,true);
s += QStringLiteral("%1 <+ %2 * 1e-9;\n").arg(Ipm2).arg(Vpm2);
s += QStringLiteral("%1 <+ %2 * 1e3 * %3 ;\n").arg(Ipm2).arg(Vpm).arg(Gain);

return s;
}
QString CCCS::spice_netlist(bool)
QString CCCS::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
Q_UNUSED(dialect);

QString s = spicecompat::check_refdes(Name,SpiceModel); // spice CCCS consists two sources: output source
// and zero value controlling source
QString val = spicecompat::normalize_value(Props.at(0)->Value);
Expand Down
2 changes: 1 addition & 1 deletion qucs/components/cccs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CCCS : public Component {
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
protected:
QString spice_netlist(bool isXyce = false);
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
QString va_code();
};

Expand Down
Loading
Loading