Skip to content

Commit

Permalink
Merge pull request #1093 from iwbnwif/new_comp_dialog
Browse files Browse the repository at this point in the history
Update the 'values' field of simulation sweep in component dialog
  • Loading branch information
ra3xdh authored Nov 25, 2024
2 parents 5d47d79 + 38d37c3 commit 8378690
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions qucs/components/componentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ ComponentDialog::ComponentDialog(Component* schematicComponent, Schematic* schem
component = schematicComponent;
document = schematic;

qDebug() << component->Model;
// qDebug() << component->Model;

restoreGeometry(_settings::Get().item<QByteArray>("ComponentDialog/geometry"));
setWindowTitle(tr("Edit Component Properties") + " - " + component->Description.toUpper());
Expand All @@ -350,9 +350,14 @@ ComponentDialog::ComponentDialog(Component* schematicComponent, Schematic* schem
// Try to work out what kind of component this is.
isEquation = QStringList({"Eqn", "NutmegEq", "SpicePar", "SpGlobPar"}).contains(component->Model);
hasSweep = QStringList({".AC", ".DISTO", ".NOISE", ".SW", ".SP", ".TR"}).contains(component->Model);
sweepProperties = QStringList({"Sim", "Type", "Param", "Start", "Stop", "Points"});
hasFile = component->Props.count() > 0 && component->Props.at(0)->Name == "File";

sweepProperties = QStringList({"Sim", "Type", "Param", "Start", "Stop", "Points"});

// TODO: Consider creating a sweepParams hash which contains the valid sweep parameters
// for a given simulation type. Then only create the valid widgets fo
// sweepParams[".AC"] = QStringList({"Type", "Start", "Stop", "Points"});

paramsHiddenBySim["Export"] = QStringList{"NutmegEq"};
paramsHiddenBySim["Sim"] = QStringList{".AC", ".DISTO", ".SP", ".NOISE", ".TR", "Eqn", "SpicePar", "SpGlobPar"};
paramsHiddenBySim["Param"] = QStringList{".AC", ".DISTO", ".SP", ".NOISE", ".TR"};
Expand Down Expand Up @@ -420,13 +425,11 @@ ComponentDialog::ComponentDialog(Component* schematicComponent, Schematic* schem
sweepTypeEnabledParams["lin"] = QStringList{"Sim", "Type", "Param", "Start", "Stop", "Step", "Points"};
sweepTypeEnabledParams["log"] = QStringList{"Sim", "Type", "Param", "Start", "Stop", "Step", "Points"};
sweepTypeEnabledParams["list"] = QStringList{"Sim", "Type", "Param", "Values"};
sweepTypeEnabledParams["value"] = QStringList{"Sim", "Type", "Param", "Values"};
sweepTypeSpecialLabels[qMakePair(QString("log"),QString("Step"))] = {"Points per decade"};
// sweepTypeSpecialLabels[qMakePair(QString("list"),QString("Points"))] = {"Values"};

// Setup the widgets as per the stored type.
sweepParamWidget["Sim"]->setOptions(getSimulationList(false));
sweepParamWidget["Type"]->setOptions({"lin", "log", "list", "value"});
sweepParamWidget["Type"]->setOptions({"lin", "log", "list"});
updateSweepProperty("All");

// Create the properties page and add it to the tab widget.
Expand Down Expand Up @@ -552,8 +555,10 @@ void ComponentDialog::updateSweepProperty(const QString& property)
{
for (auto property : component->Props)
{
// qDebug() << "Property name " << property->Name;
if (sweepParamWidget.contains(property->Name))
{
// qDebug() << "Is a sweep param";
sweepParamWidget[property->Name]->setValue(property->Value);
sweepParamWidget[property->Name]->setCheck(property->display);
}
Expand All @@ -565,9 +570,16 @@ void ComponentDialog::updateSweepProperty(const QString& property)
}
}

if (property == "Values")
// Update start and stop values if there is a valid values list.
if (property == "Values" || sweepParamWidget["Type"]->value() == "list")
{
// Do nothing.
QStringList values = sweepParamWidget["Values"]->value().remove('[').remove(']').split(';');
// qDebug() << "values " << values;
if (values.size() > 1)
{
sweepParamWidget["Start"]->setValue(values.first());
sweepParamWidget["Stop"]->setValue(values.last());
}
}

// Specialisations for updating start, stop, step, and points values.
Expand Down Expand Up @@ -604,7 +616,9 @@ void ComponentDialog::updateSweepProperty(const QString& property)
double step = str2num(sweepParamWidget["Step"]->value());
double points = (stop - start) / step + 1.0;
pointsEdit->setValue(QString::number(round(points), 'g', 16));
}
}

sweepParamWidget["Values"]->setValue("[" + startEdit->value() + ";" + stopEdit->value() + "]");
}
}
}
Expand Down Expand Up @@ -778,9 +792,14 @@ void ComponentDialog::slotApplyButton()
row = 0;
for (Property* property : component->Props)
{
// Ignore sweep parameters here.
if (hasSweep && sweepParamWidget.contains(property->Name))
continue;

/* TODO: ***HACK*** to be fixed */
if (property->Name == "Symbol")
continue;

else
{
QTableWidgetItem* item = propertyTable->item(row, 1);
Expand All @@ -805,6 +824,7 @@ void ComponentDialog::slotApplyButton()
else
property->Value = propertyTable->item(row, 1)->text();

// qDebug() << "Writing property " << property->Name << " " << property->Value;
property->display = (propertyTable->item(row, 2)->checkState() == Qt::Checked);
row++;
}
Expand Down

0 comments on commit 8378690

Please sign in to comment.