Skip to content

Commit 31bc782

Browse files
author
ThomasZecha
committed
CDL main-netlist always wrapped in a subcircuit
-fixed mac build issue -introduced set/reset net-name mapping api to Component class -implemented set/reset net-name mapping in class SubCirPort, Node, Schematic and Wire -implemented CDL PININFO in class CdlNetListWriter -implemented subcircuit wrapping of CDL main netlist in class CdlNetListWriter Signed-off-by: ThomasZecha <zecha@ihp-microelectronics.com>
1 parent a338196 commit 31bc782

File tree

15 files changed

+194
-24
lines changed

15 files changed

+194
-24
lines changed

qucs-s-spar-viewer/smithchartwidget.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,18 @@ SmithChartWidget::SmithChartWidget(QWidget *parent)
167167
// Connect the signals
168168
connect(m_Z0ComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
169169
this, &SmithChartWidget::onZ0Changed);
170+
171+
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
170172
connect(m_ShowAdmittanceChartCheckBox, &QCheckBox::checkStateChanged,
171173
this, &SmithChartWidget::onShowAdmittanceChartChanged);
172174
connect(m_ShowConstantCurvesCheckBox, &QCheckBox::checkStateChanged,
173175
this, &SmithChartWidget::onShowConstantCurvesChanged);
176+
#else
177+
connect(m_ShowAdmittanceChartCheckBox, &QCheckBox::stateChanged,
178+
this, &SmithChartWidget::onShowAdmittanceChartChanged);
179+
connect(m_ShowConstantCurvesCheckBox, &QCheckBox::stateChanged,
180+
this, &SmithChartWidget::onShowConstantCurvesChanged);
181+
#endif
174182

175183
setLayout(mainLayout);
176184
}

qucs/components/component.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "node.h"
3030
#include "misc.h"
3131

32-
#include <QPen>
33-
#include <QString>
3432
#include <QMessageBox>
3533
#include <QPainter>
3634
#include <QDebug>

qucs/components/component.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@
1818
#ifndef COMPONENT_H
1919
#define COMPONENT_H
2020

21+
#include "extsimkernels/spicecompat.h"
22+
#include "element.h"
23+
#include "property.h"
24+
2125
// QObject is needed here to be transitively included
2226
// from component implementations. Some how non-Linux
2327
// builds fail without explicit QObject inclusion
2428
#include <QObject>
25-
#include "extsimkernels/spicecompat.h"
26-
2729
#include <QList>
28-
29-
#include "element.h"
30-
#include "property.h"
31-
30+
#include <QString>
31+
#include <QPen>
32+
#include <QPair>
3233

3334
class Schematic;
34-
class QString;
35-
class QPen;
36-
3735

3836
class Component : public Element {
3937
public:
@@ -84,6 +82,9 @@ class Component : public Element {
8482
virtual void setSchematic (Schematic* p) { containingSchematic = p; }
8583
virtual Schematic* getSchematic () {return containingSchematic; }
8684

85+
virtual void setNetNameMapping(QList<QPair<QString, QString>>& pinInfo) { Q_UNUSED(pinInfo) }
86+
virtual void resetNetNameMapping() {}
87+
8788
QList<qucs::Line *> Lines;
8889
QList<qucs::Polyline *> Polylines;
8990
QList<struct qucs::Arc *> Arcs;

qucs/components/subcirport.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "subcirport.h"
1818
#include "node.h"
1919

20+
#include <utility>
2021

2122
SubCirPort::SubCirPort()
2223
{
@@ -112,6 +113,27 @@ QString SubCirPort::spice_netlist(spicecompat::SpiceDialect dialect /* = spiceco
112113
return QString();
113114
}
114115

116+
void SubCirPort::setNetNameMapping(QList<QPair<QString, QString>>& pinInfo)
117+
{
118+
Q_ASSERT(!Ports.isEmpty());
119+
Q_ASSERT(Props.size() >= 2);
120+
121+
Ports.first()->Connection->setNetNameMapping(Name);
122+
123+
const QString type(Props.at(1)->Value);
124+
pinInfo.append(
125+
std::make_pair(
126+
Name,
127+
(type == "analog" ? "I" : type == "in" ? "I" : type == "out" ? "O" : "B")));
128+
}
129+
130+
void SubCirPort::resetNetNameMapping()
131+
{
132+
Q_ASSERT(!Ports.isEmpty());
133+
134+
Ports.first()->Connection->resetNetNameMapping();
135+
}
136+
115137
// -------------------------------------------------------
116138
QString SubCirPort::vhdlCode(int)
117139
{

qucs/components/subcirport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class SubCirPort : public MultiViewComponent {
3131
protected:
3232
QString netlist();
3333
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
34+
virtual void setNetNameMapping(QList<QPair<QString, QString>>& pinInfo);
35+
virtual void resetNetNameMapping();
3436
QString vhdlCode(int);
3537
QString verilogCode(int);
3638
void createSymbol();

qucs/extsimkernels/CdlNetlistWriter.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@
3636
CdlNetlistWriter::CdlNetlistWriter(
3737
QTextStream& netlistStream,
3838
Schematic* schematic,
39-
bool resolveSpicePrefix) :
39+
bool resolveSpicePrefix,
40+
const QString& subCircuitName) :
4041
a_netlistStream(netlistStream),
4142
a_schematic(schematic),
4243
a_resolveSpicePrefix(resolveSpicePrefix),
4344
a_netListString(),
4445
a_netListStringStream(&a_netListString, QIODeviceBase::WriteOnly),
45-
a_effectiveNetlistStream(resolveSpicePrefix ? a_netListStringStream : a_netlistStream)
46+
a_effectiveNetlistStream(resolveSpicePrefix ? a_netListStringStream : a_netlistStream),
47+
a_pinInfo(),
48+
a_subCircuitName(subCircuitName)
4649
{
4750
if (a_resolveSpicePrefix)
4851
{
@@ -66,7 +69,7 @@ bool CdlNetlistWriter::write()
6669

6770
startNetlist();
6871

69-
a_effectiveNetlistStream << ".END\n";
72+
a_effectiveNetlistStream << ".ENDS\n" << ".END\n";
7073

7174
if (a_resolveSpicePrefix)
7275
{
@@ -76,6 +79,8 @@ bool CdlNetlistWriter::write()
7679
a_netlistStream << a_netListString;
7780
}
7881

82+
a_schematic->resetNetNameMapping();
83+
7984
return true;
8085
}
8186

@@ -163,6 +168,8 @@ int CdlNetlistWriter::prepareNetlist()
163168
return -10;
164169
}
165170

171+
a_schematic->setNetNameMapping(a_pinInfo);
172+
166173
return numPorts;
167174
}
168175

@@ -171,7 +178,7 @@ void CdlNetlistWriter::startNetlist()
171178
QString s;
172179

173180
// Parameters, Initial conditions, Options
174-
for (Component *pc : a_schematic->a_DocComps)
181+
for (Component *pc: a_schematic->a_DocComps)
175182
{
176183
if (pc->isEquation)
177184
{
@@ -180,17 +187,37 @@ void CdlNetlistWriter::startNetlist()
180187
}
181188
}
182189

190+
// always wrap the main netlist in a subcircuit
191+
a_effectiveNetlistStream << ".SUBCKT " << a_subCircuitName;
192+
for (auto pinInfo: a_pinInfo)
193+
{
194+
a_effectiveNetlistStream << " " << pinInfo.first;
195+
}
196+
a_effectiveNetlistStream << "\n";
197+
183198
// global net 0 is always ground
184-
a_effectiveNetlistStream << ".GLOBAL 0:G\n";
199+
a_effectiveNetlistStream << "*.GLOBAL 0:G\n";
200+
201+
if (!a_pinInfo.isEmpty())
202+
{
203+
a_effectiveNetlistStream << "*.PININFO";
204+
205+
for (auto pinInfo: a_pinInfo)
206+
{
207+
a_effectiveNetlistStream << " " << pinInfo.first << ":" << pinInfo.second;
208+
}
209+
210+
a_effectiveNetlistStream << "\n";
211+
}
185212

186213
// Components
187-
for (Component *pc : a_schematic->a_DocComps)
214+
for (Component *pc: a_schematic->a_DocComps)
188215
{
189216
if (a_schematic->getIsAnalog() && !pc->isSimulation && !pc->isEquation)
190217
{
191218
s = pc->getSpiceNetlist(spicecompat::CDL);
192219

193-
a_effectiveNetlistStream << s;
220+
a_effectiveNetlistStream << (s == "\n" ? "" : s);
194221
}
195222
}
196223

qucs/extsimkernels/CdlNetlistWriter.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@
2424
#include <QMap>
2525
#include <QStringList>
2626
#include <QTextStream>
27+
#include <QList>
28+
#include <QPair>
29+
#include <QString>
2730

2831
class Schematic;
2932

3033
class CdlNetlistWriter
3134
{
3235
public:
33-
CdlNetlistWriter(QTextStream& netlistStream, Schematic* schematic, bool resolveSpicePrefix);
36+
CdlNetlistWriter(
37+
QTextStream& netlistStream,
38+
Schematic* schematic,
39+
bool resolveSpicePrefix,
40+
const QString& subCircuitName);
3441
~CdlNetlistWriter() {};
3542

3643
bool write();
@@ -47,6 +54,8 @@ class CdlNetlistWriter
4754
QString a_netListString;
4855
QTextStream a_netListStringStream;
4956
QTextStream& a_effectiveNetlistStream;
57+
QList<QPair<QString, QString>> a_pinInfo;
58+
const QString a_subCircuitName;
5059
};
5160

5261
#endif // CDL_NETLIST_WRITER_H

qucs/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,22 @@ int doCdlNetlist(
479479
QScopedPointer<QString> netlistString;
480480
QScopedPointer<QFile> cdlFile;
481481

482+
QString subCircuitName;
483+
482484
if (netlist2Console)
483485
{
486+
subCircuitName = "console";
487+
484488
netlistString.reset(new QString());
485489
netlistStream.reset(new QTextStream(netlistString.get()));
486490
}
487491
else
488492
{
493+
// The main-netlist wrapping subcircuit gets the name from the netlist storage
494+
// file name excluding the potential file suffix
495+
subCircuitName = netlistFileName.split(QDir::separator()).last();
496+
subCircuitName = subCircuitName.left(subCircuitName.lastIndexOf("."));
497+
489498
cdlFile.reset(new QFile(netlistFileName));
490499

491500
if (cdlFile->open(QFile::WriteOnly))
@@ -508,7 +517,7 @@ int doCdlNetlist(
508517
}
509518
}
510519

511-
CdlNetlistWriter cdlWriter(*netlistStream, schematic.get(), resolveSpicePrefix);
520+
CdlNetlistWriter cdlWriter(*netlistStream, schematic.get(), resolveSpicePrefix, subCircuitName);
512521
if (!cdlWriter.write())
513522
{
514523
QMessageBox::critical(

qucs/node.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Node::Node(int x, int y) :
2828
a_components(),
2929
a_dtype(""),
3030
a_state(0),
31-
a_name()
31+
a_name(),
32+
a_mappedName()
3233
{
3334
Type = isNode;
3435
cx = x;
@@ -120,3 +121,29 @@ Node* Node::merge(Node* donor)
120121

121122
return donor;
122123
}
124+
125+
void Node::setNetNameMapping(const QString& netName)
126+
{
127+
if (!a_mappedName.has_value() || a_mappedName.value() != netName)
128+
{
129+
a_mappedName = netName;
130+
131+
std::for_each(
132+
a_wires.begin(),
133+
a_wires.end(),
134+
[netName](Wire* &wire) { wire->setNetNameMapping(netName); });
135+
}
136+
}
137+
138+
void Node::resetNetNameMapping()
139+
{
140+
if (a_mappedName.has_value())
141+
{
142+
a_mappedName.reset();
143+
144+
std::for_each(
145+
a_wires.begin(),
146+
a_wires.end(),
147+
[](Wire* &wire) { wire->resetNetNameMapping(); });
148+
}
149+
}

qucs/node.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "conductor.h"
2222
#include <list>
23+
#include <optional>
2324

2425
#include <QDebug>
2526

@@ -73,12 +74,15 @@ class Node : public Conductor {
7374

7475
inline void setName(const QString& name) { a_name = name; }
7576
inline void addName(const QString& name) { a_name += name; }
76-
inline QString getName() const { return a_name; }
77+
inline QString getName() const { return a_mappedName.has_value() ? a_mappedName.value() : a_name; }
7778
inline void setDType(const QString& dtype) { a_dtype = dtype; }
7879
inline QString getDType() const { return a_dtype; }
7980
inline void setState(int state) { a_state = state; }
8081
inline int getState() const { return a_state; }
8182

83+
void setNetNameMapping(const QString& netName);
84+
void resetNetNameMapping();
85+
8286
private:
8387
// Nodes usually have quite a few connections. In ideal case, when all wire
8488
// placement optimizations work properly, there can be at most four connections
@@ -94,6 +98,7 @@ class Node : public Conductor {
9498
QString a_dtype; // type of node (used by digital files)
9599
int a_state; // remember some things during some operations
96100
QString a_name; // node name used by creation of netlist
101+
std::optional<QString> a_mappedName;
97102
};
98103

99104
#endif

0 commit comments

Comments
 (0)