Skip to content

Commit

Permalink
Intermediate commit to address some problems with 'list' and 'value' …
Browse files Browse the repository at this point in the history
…sweep types
  • Loading branch information
iwbnwif committed Nov 20, 2024
1 parent 03261ed commit 782f592
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 additions & 18 deletions qucs/components/componentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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());
Expand All @@ -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());
}
}

Expand All @@ -560,37 +571,37 @@ 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));
}
else if (property == "Step")
{
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));
}
else if (property == "Step")
{
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));
}
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -773,7 +808,6 @@ void ComponentDialog::slotApplyButton()
}
}
}

document->recreateComponent(component);
document->viewport()->repaint();

Expand Down

0 comments on commit 782f592

Please sign in to comment.