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

Ac simulation #4076

Draft
wants to merge 45 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c00d04f
Update Bug.md
failiz Feb 5, 2024
0d58769
fixes bug with u simbol. The u symbol should be replaced by a u in ng…
failiz Mar 8, 2023
115ba42
split different options of the spice circuit in sepate lines. Added i…
failiz Mar 12, 2023
600a144
towards transitoty simulations (still work in progress)
failiz Mar 13, 2023
7de4eb7
allow to change properties of the pulse and sinusoidal power supplies
failiz Mar 22, 2023
46bccb8
modified resources.xml to adapt to the new moduleIDs of the new power…
failiz Sep 20, 2023
fc03cb0
added number of cycles as a property to change in pulse power supplies
failiz Sep 20, 2023
be8fac1
fixed bug in loop, removed setElementId to show all the svg elements
failiz Sep 20, 2023
93eedcc
working towards the aligning the oscilloscope signals with the oscill…
failiz Sep 29, 2023
8db3f72
towards multiple oscilloscope in the simulation. Added offset marks t…
failiz Oct 3, 2023
5c2924f
if the negative terminal of a power supply is not connected and there…
failiz Oct 3, 2023
00abb32
handles the 4 channels and adds noise to the signals if the com probe…
failiz Oct 3, 2023
1a4378a
better name for a property
failiz Oct 3, 2023
af0c891
improved oscilloscope in sch view and added axis labels
failiz Oct 4, 2023
a36833f
added axis scale in the oscilloscope for the sch view
failiz Oct 5, 2023
105fd7b
added control of the horizontal simulation to the analysis without lo…
failiz Oct 5, 2023
af0414f
added handling of horizontal positions for multiple oscilloscopes
failiz Oct 6, 2023
433a51a
allow to introduce negative numbers in the properties of parts. This …
failiz Oct 7, 2023
dab2f73
Show the result of the simulation at the end time, not at the startin…
failiz Oct 7, 2023
6e2c3db
In sch view, added the name of the axes to the oscilloscope.
failiz Oct 10, 2023
47ac612
updated position of the labels and axes in the oscilloscope when simu…
failiz Oct 10, 2023
af9e5f6
added properties for the triangular wavegenerator
failiz Oct 10, 2023
b848df3
added some examples for the transitory analysis
failiz Oct 10, 2023
8e1440a
added 555 example
failiz Dec 4, 2023
082736d
Finish wiring of the BB view of the 555 example
failiz Dec 5, 2023
8e7dcd3
added two sketches as examples of the transient simulation
failiz Dec 5, 2023
3ed26cb
fixed oscilloscope text string (too many arguments)
failiz Dec 7, 2023
bfbacda
fixed bug when properties contain capital letters. If so, the propert…
failiz Dec 7, 2023
d258cf5
imprved handling of properties with capital letters
failiz Dec 7, 2023
7684fbd
improved simulation error dialog. Now, there is a scroll area for the…
failiz Dec 7, 2023
a10fdb5
show the right channel in the axis of the oscilloscope (SCH view)
failiz Dec 7, 2023
ef83cec
added properties of the transformer so that users can modifiy its pro…
failiz Dec 7, 2023
3dead91
fixed error when a property does not have symbol: If there is no symb…
failiz Dec 7, 2023
bcf5960
calculate the com voltage at the oscilloscope when there is a wire co…
failiz Dec 8, 2023
cccd30e
First implementation using an animation of the results of the simulat…
failiz Dec 9, 2023
2701e68
now all parts get voltages and currents depending on simulation time
failiz Dec 10, 2023
5d3fc49
Revert elcos
Feb 13, 2024
560f296
Added functionality to set sim frequency and save it to project.
Dec 15, 2023
a70ce54
added the simulation properties to the project properties menu
failiz Feb 18, 2024
4fa9783
added simulator message (sim time) at the top right corner when simul…
failiz Feb 20, 2024
9eb7edb
Added sawtooth generator and modified properties of the triangular si…
failiz Apr 6, 2024
1712697
changed ac poewer supply to sine, added generic pulse power supply an…
failiz Apr 7, 2024
234eb9a
make the transitory simulation not blocking. Results will be shown wh…
failiz Apr 7, 2024
1c56001
added exception for the oscilloscope as it does not have a pcb view
failiz Apr 7, 2024
39b0dad
Load analog code model to have access to current limiting devices for…
failiz May 3, 2024
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
Prev Previous commit
Next Next commit
added simulator message (sim time) at the top right corner when simul…
…ating transitory circuits
  • Loading branch information
failiz committed Feb 20, 2024
commit 4fa9783120c10dc31867aa58e5f075955f0de1b5
33 changes: 26 additions & 7 deletions src/simulation/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Simulator::Simulator(MainWindow *mainWindow) : QObject(mainWindow) {
enable(true);
Copy link
Member

@KjellMorgenstern KjellMorgenstern Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is now save to remove that setting entirely. If there are no objections, I'll to that for 1.0.3

While on it, will it make sense to have a switch between DC and transient analysis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK with removing the enable simulator setting.

m_simulating = false;


}

Simulator::~Simulator() {
Expand Down Expand Up @@ -149,7 +150,9 @@ void Simulator::stopSimulation() {
m_showResultsTimer->stop();
m_simulating = false;
removeSimItems();
emit simulationStartedOrStopped(m_simulating);
emit simulationStartedOrStopped(m_simulating);
m_breadboardGraphicsView->setSimulatorMessage("");
m_schematicGraphicsView->setSimulatorMessage("");
}

/**
Expand Down Expand Up @@ -370,19 +373,35 @@ void Simulator::simulate() {
netList.clear();


//The spice simulation has finished, iterate over each part being simulated and update it (if it is necessary).
currSimStep = 1;
m_showResultsTimer->start();

//The spice simulation has finished, iterate over each part being simulated and update it (if it is necessary).
removeSimItems();
updateParts(itemBases, 0);

//If this a transitory simulation, set the timer for the animation
if (m_simEndTime > 0) {
m_currSimStep = 1;
m_showResultsTimer->start();
}

}

void Simulator::showSimulationResults() {
if (currSimStep < m_simNumberOfSteps) {
if (m_currSimStep < m_simNumberOfSteps) {
removeSimItems();
updateParts(itemBases, currSimStep);
currSimStep++;
updateParts(itemBases, m_currSimStep);

double simTime = m_simStartTime + m_currSimStep * m_simStepTime;

QString simMessage = QString::number(simTime, 'f', 3) + " s";

m_breadboardGraphicsView->setSimulatorMessage(simMessage);
m_schematicGraphicsView->setSimulatorMessage(simMessage);




m_currSimStep++;
} else {
m_showResultsTimer->stop();
}
Expand Down
3 changes: 2 additions & 1 deletion src/simulation/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public slots:

QList<QString>* m_instanceTitleSim;
QTimer *m_simTimer, *m_showResultsTimer;
int currSimStep;
int m_currSimStep;

static constexpr int SimDelay = 200;
static constexpr double HarmfulNegativeVoltage = -0.5;

Expand Down
28 changes: 28 additions & 0 deletions src/sketch/sketchwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7657,9 +7657,37 @@ void SketchWidget::drawBackground( QPainter * painter, const QRectF & rect )
painter->restore();
}
}
}

void SketchWidget::drawForeground ( QPainter * painter, const QRectF & rect ) {
if(!m_simMessage.isEmpty()) {
//Set the font size based on the zoom
QFont font = painter->font();
qreal baseFontSize = 18; // Base font size at zoom level 1
font.setPointSizeF(baseFontSize);
painter->setFont(font);

int margin = 0; // Margin from the top and right edges
QFontMetrics metrics = painter->fontMetrics();
int textWidth = metrics.horizontalAdvance(m_simMessage);

// 2. Get the View's Top-Right Corner in View Coordinates
QPointF viewTopRight = this->viewport()->rect().topRight();
QPointF viewTexPos = viewTopRight - QPointF(textWidth, -1*metrics.ascent()); // Adjust for the width of the text item

//save current transformations, remove them temporaly, draw the text in the view and restore the transformations
painter->save();
painter->resetTransform();
painter->drawText(viewTexPos.x(), viewTexPos.y(), m_simMessage);
painter->restore();
}
}

void SketchWidget::setSimulatorMessage(QString message) {
m_simMessage = message;
if (isVisible()) {
update();
}
}

/*
Expand Down
3 changes: 3 additions & 0 deletions src/sketch/sketchwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class SketchWidget : public InfoGraphicsView
double retrieveZoom();
void initGrid();
virtual double defaultGridSizeInches();
void setSimulatorMessage(QString);
void clearPasteOffset();
virtual ViewLayer::ViewLayerPlacement defaultViewLayerPlacement(ModelPart *);
void collectAllNets(
Expand Down Expand Up @@ -433,6 +434,7 @@ class SketchWidget : public InfoGraphicsView
virtual const QString & hoverEnterPartConnectorMessage(QGraphicsSceneHoverEvent * event, ConnectorItem * item);
void partLabelChangedAux(ItemBase * pitem,const QString & oldText, const QString &newText);
void drawBackground( QPainter * painter, const QRectF & rect );
void drawForeground( QPainter * painter, const QRectF & rect );
void handleConnect(QDomElement & connect, ModelPart *, const QString & fromConnectorID, ViewLayer::ViewLayerID, QStringList & alreadyConnected,
QHash<long, ItemBase *> & newItems, QUndoCommand * parentCommand, bool seekOutsideConnections);
void setUpSwapReconnect(SwapThing &, ItemBase * itemBase, long newID, bool master);
Expand Down Expand Up @@ -755,6 +757,7 @@ public Q_SLOTS:
bool m_everZoomed = false;
double m_ratsnestOpacity = 0.0;
double m_ratsnestWidth = 0.0;
QString m_simMessage = "";

public:
static ViewLayer::ViewLayerID defaultConnectorLayer(ViewLayer::ViewID viewId);
Expand Down