Skip to content

Commit

Permalink
Merge pull request #783 from wawuwo/refactor-sim-components
Browse files Browse the repository at this point in the history
Refactor simulation components
  • Loading branch information
ra3xdh committed Jun 25, 2024
2 parents 4f574bb + 1813ec9 commit c3b599d
Show file tree
Hide file tree
Showing 45 changed files with 256 additions and 413 deletions.
2 changes: 2 additions & 0 deletions qucs/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ circline.cpp
taperedline.cpp
circularloop.cpp
spiralinductor.cpp
simulation.cpp
)

SET(COMPONENTS_HDRS
Expand Down Expand Up @@ -194,6 +195,7 @@ rfedd.h
rfedd2p.h
rlcg.h
rs_flipflop.h
simulation.h
source_ac.h
sp_sim.h
sparamfile.h
Expand Down
21 changes: 1 addition & 20 deletions qucs/components/ac_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* *
***************************************************************************/
#include "ac_sim.h"
#include "main.h"
#include "misc.h"
#include "extsimkernels/spicecompat.h"

Expand All @@ -26,25 +25,7 @@ AC_Sim::AC_Sim()
{
isSimulation = true;
Description = QObject::tr("ac simulation");

QString s = Description;
int a = s.indexOf(" ");
int b = s.lastIndexOf(" ");
if (a != -1 && b != -1) {
if (a > (int) s.length() - b) b = a;
}
if (a < 8 || s.length() - b < 8) b = -1;
if (b != -1) s[b] = '\n';

Texts.append(new Text(0, 0, s.left(b), Qt::darkBlue, QucsSettings.largeFontSize));
if (b != -1)
Texts.append(new Text(0, 0, s.mid(b+1), Qt::darkBlue, QucsSettings.largeFontSize));

x1 = -10; y1 = -9;
x2 = x1+128; y2 = y1+41;

tx = 0;
ty = y2+1;
initSymbol(Description);
Model = ".AC";
SpiceModel = ".AC";
Name = "AC";
Expand Down
4 changes: 2 additions & 2 deletions qucs/components/ac_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef AC_SIM_H
#define AC_SIM_H

#include "component.h"
#include "simulation.h"


class AC_Sim : public Component {
class AC_Sim : public qucs::component::SimulationComponent {
public:
AC_Sim();
~AC_Sim();
Expand Down
77 changes: 3 additions & 74 deletions qucs/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,11 @@ bool Component::getSelected(int x_, int y_) {
return false;
}

void Component::paint(QPainter *p) const {
void Component::paint(QPainter *p) {
p->save();
p->translate(cx, cy);

if (Model.at(0) == '.') { // is simulation component (dc, ac, ...)
drawSimulator(p);
} else { // normal components go here
drawUsual(p);
}
drawSymbol(p);

p->setPen(QPen(Qt::black, 1));
QRect text_br{tx, ty, 0, 0};
Expand Down Expand Up @@ -279,74 +275,7 @@ void Component::paint(QPainter *p) const {
p->restore();
}

void Component::drawSimulator(QPainter* p) const {
const bool correctSimulator = (Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator;
p->save();
if (correctSimulator) {
if ((Model == ".CUSTOMSIM") || (Model == ".DISTO")
|| (Model == ".NOISE") || (Model == ".PZ") ||
(Model == ".SENS") || (Model == ".SENS_AC") ||
(Model == ".FFT"))
p->setPen(QPen(Qt::blue, 2));
else if ((Model == ".XYCESCR") || (Model == ".SENS_XYCE")
|| (Model == ".SENS_TR_XYCE"))
p->setPen(QPen(Qt::darkGreen, 2));
else if (Model == ".FOURIER") p->setPen(QPen(Qt::darkRed, 2));
else p->setPen(QPen(Qt::darkBlue, 2));
} else {
p->setPen(WrongSimulatorPen);
}

QFont title_font{ p->font() };
title_font.setWeight(QFont::DemiBold);
p->setFont(title_font);

QRect all_text_br;
QRect br;
for (Text *t: Texts) {
p->drawText(br.left(), br.bottom(), 0, 0, Qt::TextDontClip, t->s, &br);
all_text_br |= br;
}

// Simulation components look like an isometric box
// or a brick, with a title on its top side, being
// observed from some strange angle, like this:
//
// +-----------+
// | |`.
// | T I T L E | |
// | | |
// +-----------+ |
// `___________`!

// It's drawn below step by step. Remember that
// in painter's coordinate system Y-axis grows downwards

// Top side
QRect plate = all_text_br.marginsAdded(QMargins{5,5,5,5});
p->drawRect(plate);

// Box "depth"
QPoint offset{5, 5};

// Three short edges of the box which define its "depth"
auto topRight_ = plate.topRight() + offset;
p->drawLine(plate.topRight(), topRight_);

auto bottomRight_ = plate.bottomRight() + offset;
p->drawLine(plate.bottomRight(), bottomRight_);

auto bottomLeft_ = plate.bottomLeft() + offset;
p->drawLine(plate.bottomLeft(), bottomLeft_);

// Finally two visble edges of bottom side of the box
p->drawLine(bottomLeft_, bottomRight_);
p->drawLine(bottomRight_, topRight_);

p->restore();
}

void Component::drawUsual(QPainter* p) const {
void Component::drawSymbol(QPainter* p) {
const bool correctSimulator = (Simulator & QucsSettings.DefaultSimulator) == QucsSettings.DefaultSimulator;

auto draw_primitive = [&](qucs::DrawingPrimitive* prim, QPainter* p) {
Expand Down
6 changes: 2 additions & 4 deletions qucs/components/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Component : public Element {
virtual void getExtraVANodes(QStringList& ) {};
QString get_VHDL_Code(int);
QString get_Verilog_Code(int);
void paint(QPainter* painter) const;
void paint(QPainter* painter);
void paintScheme(Schematic*);
void setCenter(int, int, bool relative=false);
void getCenter(int&, int&);
Expand Down Expand Up @@ -127,9 +127,7 @@ class Component : public Element {
Property * getProperty(const QString&);
Schematic* containingSchematic;

private:
void drawSimulator(QPainter* p) const;
void drawUsual(QPainter* p) const;
virtual void drawSymbol(QPainter* p);
};


Expand Down
23 changes: 1 addition & 22 deletions qucs/components/dc_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,15 @@
* *
***************************************************************************/
#include "dc_sim.h"
#include "main.h"


DC_Sim::DC_Sim()
{
isSimulation = true;
Description = QObject::tr("dc simulation");

QString s = Description;
int a = s.indexOf(" ");
int b = s.lastIndexOf(" ");
if (a != -1 && b != -1) {
if (a > (int) s.length() - b) b = a;
}
if (a < 8 || s.length() - b < 8) b = -1;
if (b != -1) s[b] = '\n';

Texts.append(new Text(0, 0, s.left(b), Qt::darkBlue, QucsSettings.largeFontSize));
if (b != -1)
Texts.append(new Text(0, 0, s.mid(b+1), Qt::darkBlue, QucsSettings.largeFontSize));

x1 = -10; y1 = -9;
x2 = x1+128; y2 = y1+41;

tx = 0;
ty = y2+1;
initSymbol(Description);
Model = ".DC";
Name = "DC";
SpiceModel = ".OP";
isSimulation = true;

Props.append(new Property("Temp", "26.85", false,
QObject::tr("simulation temperature in degree Celsius")));
Expand Down
4 changes: 2 additions & 2 deletions qucs/components/dc_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef DC_SIM_H
#define DC_SIM_H

#include "component.h"
#include "simulation.h"


class DC_Sim : public Component {
class DC_Sim : public qucs::component::SimulationComponent {
public:
DC_Sim();
~DC_Sim();
Expand Down
16 changes: 1 addition & 15 deletions qucs/components/digi_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,13 @@
* *
***************************************************************************/
#include "digi_sim.h"
#include "main.h"


Digi_Sim::Digi_Sim()
{
Type = isDigitalComponent;
Description = QObject::tr("digital simulation");

QString s = Description;
int a = s.indexOf(" ");
if (a != -1) s[a] = '\n'; // break line before the word "simulation"

Texts.append(new Text(0, 0, s.left(a), Qt::darkBlue, QucsSettings.largeFontSize));
if (a != -1)
Texts.append(new Text(0, 0, s.mid(a+1), Qt::darkBlue, QucsSettings.largeFontSize));

x1 = -10; y1 = -9;
x2 = x1+120; y2 = y1+59;

tx = 0;
ty = y2+1;
initSymbol(Description);
Model = ".Digi";
Name = "Digi";

Expand Down
4 changes: 2 additions & 2 deletions qucs/components/digi_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef DIGI_SIM_H
#define DIGI_SIM_H

#include "component.h"
#include "simulation.h"


class Digi_Sim : public Component {
class Digi_Sim : public qucs::component::SimulationComponent {
public:
Digi_Sim();
~Digi_Sim();
Expand Down
16 changes: 1 addition & 15 deletions qucs/components/etr_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,13 @@
* *
***************************************************************************/
#include "etr_sim.h"
#include "main.h"


ETR_Sim::ETR_Sim()
{
Description = QObject::tr("externally driven transient simulation");
Simulator = spicecompat::simQucsator;

QString s = Description;
int a = 17;
s[a] = '\n';

Texts.append(new Text(0, 0, s.left(a), Qt::darkBlue, QucsSettings.largeFontSize));
if (a != -1)
Texts.append(new Text(0, 0, s.mid(a+1), Qt::darkBlue, QucsSettings.largeFontSize));

x1 = -10; y1 = -9;
x2 = x1+130; y2 = y1+59;

tx = 0;
ty = y2+1;
initSymbol(Description);
Model = ".ETR";
Name = "ETR";

Expand Down
4 changes: 2 additions & 2 deletions qucs/components/etr_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef ETR_SIM_H
#define ETR_SIM_H

#include "component.h"
#include "simulation.h"


class ETR_Sim : public Component {
class ETR_Sim : public qucs::component::SimulationComponent {
public:
ETR_Sim();
~ETR_Sim();
Expand Down
15 changes: 1 addition & 14 deletions qucs/components/hb_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* *
***************************************************************************/
#include "hb_sim.h"
#include "main.h"
#include "misc.h"
#include "extsimkernels/spicecompat.h"
#include <QRegularExpression>

Expand All @@ -27,18 +25,7 @@ HB_Sim::HB_Sim()
Simulator = spicecompat::simXyce | spicecompat::simQucsator;

QString s = Description;
int a = s.lastIndexOf(" ");
if (a != -1) s[a] = '\n'; // break line before the word "simulation"

Texts.append(new Text(0, 0, s.left(a), Qt::darkBlue, QucsSettings.largeFontSize));
if (a != -1)
Texts.append(new Text(0, 0, s.mid(a+1), Qt::darkBlue, QucsSettings.largeFontSize));

x1 = -10; y1 = -9;
x2 = x1+163; y2 = y1+59;

tx = 0;
ty = y2+1;
initSymbol(Description);
Model = ".HB";
Name = "HB";
SpiceModel = ".HB";
Expand Down
4 changes: 2 additions & 2 deletions qucs/components/hb_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef HB_SIM_H
#define HB_SIM_H

#include "component.h"
#include "simulation.h"


class HB_Sim : public Component {
class HB_Sim : public qucs::component::SimulationComponent {
public:
HB_Sim();
~HB_Sim();
Expand Down
9 changes: 1 addition & 8 deletions qucs/components/opt_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ Optimize_Sim::Optimize_Sim()
{
Description = QObject::tr("Optimization");
Simulator = spicecompat::simQucsator;

Texts.append(new Text(0, 0, Description, Qt::darkBlue, QucsSettings.largeFontSize));

x1 = -10; y1 = -9;
x2 = x1+128; y2 = y1+41;

tx = 0;
ty = y2+1;
initSymbol(Description);
Model = ".Opt";
Name = "Opt";

Expand Down
4 changes: 2 additions & 2 deletions qucs/components/opt_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#ifndef OPT_SIM_H
#define OPT_SIM_H

#include "component.h"
#include "simulation.h"


class Optimize_Sim : public Component {
class Optimize_Sim : public qucs::component::SimulationComponent {
public:
Optimize_Sim();
~Optimize_Sim();
Expand Down
Loading

0 comments on commit c3b599d

Please sign in to comment.