From 782f5929ff8519ee680ea8966b3ce008275d5b47 Mon Sep 17 00:00:00 2001 From: Iwbnwif Yiw Date: Wed, 20 Nov 2024 22:39:28 +0000 Subject: [PATCH] Intermediate commit to address some problems with 'list' and 'value' sweep types --- qucs/components/componentdialog.cpp | 70 +++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/qucs/components/componentdialog.cpp b/qucs/components/componentdialog.cpp index 067ff16ca..240aedea9 100644 --- a/qucs/components/componentdialog.cpp +++ b/qucs/components/componentdialog.cpp @@ -348,7 +348,7 @@ 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", ".NOISE", ".SW", ".SP", ".TR"}).contains(component->Model); - sweepProperties = QStringList({"Sim", "Param", "Type", "Values", "Start", "Stop", "Points"}); + sweepProperties = QStringList({"Sim", "Type", "Param", "Start", "Stop", "Points"}); hasFile = component->Props.count() > 0 && component->Props.at(0)->Name == "File"; paramsHiddenBySim["Export"] = QStringList{"NutmegEq"}; @@ -415,11 +415,12 @@ ComponentDialog::ComponentDialog(Component* schematicComponent, Schematic* schem sweepParamWidget["Points"] = new ParamLineEdit("Points", tr("Number"), intVal, true, sweepPageLayout, this, func); // Setup the widget specialisations for each simulation type. - sweepTypeEnabledParams["lin"] = QStringList{"Sim", "Param", "Type", "Start", "Stop", "Step", "Points"}; - sweepTypeEnabledParams["log"] = QStringList{"Sim", "Param", "Type", "Start", "Stop", "Step", "Points"}; - sweepTypeEnabledParams["list"] = QStringList{"Type", "Values"}; - sweepTypeEnabledParams["value"] = QStringList{"Type", "Values"}; + 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)); @@ -536,6 +537,11 @@ void ComponentDialog::updateSweepWidgets(const QString& type) // Updates all the sweep params on the sweep page according the component value. void ComponentDialog::updateSweepProperty(const QString& property) { + // Cache some pointers for convenience. + ParamWidget* startEdit = sweepParamWidget["Start"]; + ParamWidget* stopEdit = sweepParamWidget["Stop"]; + ParamWidget* pointsEdit = sweepParamWidget["Points"]; + // Type has changed so update the widget presentation. if (property == "Type") updateSweepWidgets(sweepParamWidget["Type"]->value()); @@ -548,7 +554,12 @@ void ComponentDialog::updateSweepProperty(const QString& property) { sweepParamWidget[property->Name]->setValue(property->Value); sweepParamWidget[property->Name]->setCheck(property->display); - } + } + + // Make sure text edits have sensible values. + startEdit->setValue(startEdit->value() == "" ? "1" : startEdit->value()); + stopEdit->setValue(stopEdit->value() == "" ? "100" : stopEdit->value()); + pointsEdit->setValue(pointsEdit->value() == "" ? "100" : pointsEdit->value()); } } @@ -560,14 +571,14 @@ void ComponentDialog::updateSweepProperty(const QString& property) // Specialisations for updating start, stop, step, and points values. else { - double start = str2num(sweepParamWidget["Start"]->value()); - double stop = str2num(sweepParamWidget["Stop"]->value()); + double start = str2num(startEdit->value()); + double stop = str2num(stopEdit->value()); if (sweepParamWidget["Type"]->value() == "log") { if (property == "Start" || property == "Stop" || property == "Points" || property == "All") { - double points = str2num(sweepParamWidget["Points"]->value()); + double points = str2num(pointsEdit->value()); double step = (points - 1.0) / log10(fabs((stop < 1.0 ? 1.0 : stop) / (start < 1.0 ? 1.0 : start))); sweepParamWidget["Step"]->setValue(misc::num2str(step)); } @@ -575,14 +586,14 @@ void ComponentDialog::updateSweepProperty(const QString& property) { double step = str2num(sweepParamWidget["Step"]->value()); double points = log10(fabs((stop < 1.0 ? 1.0 : stop) / (start < 1.0 ? 1.0 : start))) * step + 1.0; - sweepParamWidget["Points"]->setValue(QString::number(round(points), 'g', 16)); + pointsEdit->setValue(QString::number(round(points), 'g', 16)); } } else { if (property == "Start" || property == "Stop" || property == "Points" || property == "All") { - double points = str2num(sweepParamWidget["Points"]->value()); + double points = str2num(pointsEdit->value()); double step = (stop - start) / (points - 1.0); sweepParamWidget["Step"]->setValue(misc::num2str(step)); } @@ -590,7 +601,7 @@ void ComponentDialog::updateSweepProperty(const QString& property) { double step = str2num(sweepParamWidget["Step"]->value()); double points = (stop - start) / step + 1.0; - sweepParamWidget["Points"]->setValue(QString::number(round(points), 'g', 16)); + pointsEdit->setValue(QString::number(round(points), 'g', 16)); } } } @@ -607,6 +618,10 @@ void ComponentDialog::updatePropertyTable(const Component* updateComponent) if (hasSweep && sweepProperties.contains(property->Name)) continue; + /* TODO: ***HACK*** to be fixed */ + if (property->Name == "Symbol" || property->Name == "Values") + continue; + propertyTable->setRowCount(propertyTable->rowCount() + 1); propertyTable->setItem(row, 0, new QTableWidgetItem(property->Name, LabelCell)); propertyTable->item(row, 0)->setFlags(Qt::ItemIsEnabled); @@ -734,15 +749,35 @@ void ComponentDialog::slotApplyButton() else { - // Walk through the Props list and update component. int row = 0; - for (Property* property : component->Props) + + // Update the components sweep properties if it has them. + if (hasSweep) { - if (hasSweep && sweepParamWidget.contains(property->Name)) + // Note: Order is very important here. The component expects parameters in a + // specific order depending on which sweep parameters are valid for the component + // type. + for (auto param : sweepProperties) { - property->Value = sweepParamWidget[property->Name]->value(); - property->display = sweepParamWidget[property->Name]->check(); + /* TODO: ***HACK*** to be fixed */ + QString temp = param; + if (param == "Points" && sweepParamWidget["Type"]->value() == "list") + temp = "Values"; + + if (!(paramsHiddenBySim[param].contains(component->Model))) + { + component->Props.at(row)->Value = sweepParamWidget[temp]->value(); + component->Props.at(row)->display = sweepParamWidget[temp]->check(); + row++; + } } + } + + row = 0; + for (Property* property : component->Props) + { + if (hasSweep && sweepParamWidget.contains(property->Name)) + continue; else { @@ -773,7 +808,6 @@ void ComponentDialog::slotApplyButton() } } } - document->recreateComponent(component); document->viewport()->repaint();