Skip to content

Commit

Permalink
Add a checkbox to allow enabling / disabling of equation variables ex…
Browse files Browse the repository at this point in the history
…port.
  • Loading branch information
iwbnwif committed Nov 13, 2024
1 parent a19e460 commit 61222d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
40 changes: 30 additions & 10 deletions qucs/components/componentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
3. DONE: Add special property names - i.e., for log sweeps (per decade instead of step)
4. DONE: Update components from SPICE file.
5. DONE: Implement highlighting.
6. Have "Export" as a check box, or option list for equations.
6. DONE: Have "Export" as a check box, or option list for Qucsator equations.
7. DONE: .INCLUDE components have multiple files
8. Should 'Lib' parameters also be able to open a file?
9. Check for memory leaks.
Expand Down Expand Up @@ -93,7 +93,7 @@ class CompoundWidget : public QWidget
}
~CompoundWidget()
{
qDebug() << "CompoundWidget dtor called";
// qDebug() << "CompoundWidget dtor called";
delete mButton;
delete mEdit;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ class ParamCombo : public QComboBox, public ParamWidget
{
public:
ParamCombo(const QString& param, const QString& label, bool displayCheck, QGridLayout* layout, ComponentDialog* dialog,
void (ComponentDialog::* func)(const QString&, const QString&))
void (ComponentDialog::* func)(const QString&, const QString&) = nullptr)
: ParamWidget(param, label, displayCheck, layout)
{
layout->addWidget(this, layout->rowCount() - 1, 1);
Expand Down Expand Up @@ -330,7 +330,7 @@ ComponentDialog::ComponentDialog(Component* schematicComponent, Schematic* schem
restoreGeometry(_settings::Get().item<QByteArray>("ComponentDialog/geometry"));
setWindowTitle(tr("Edit Component Properties") + " - " + component->Description.toUpper());

qDebug() << "Component name is: " << component->Model << " " << component->Name;
// qDebug() << "Component name is: " << component->Model << " " << component->Name;

// Setup dialog layout.
QVBoxLayout* mainLayout = new QVBoxLayout(this);
Expand All @@ -356,17 +356,19 @@ ComponentDialog::ComponentDialog(Component* schematicComponent, Schematic* schem
sweepProperties = QStringList({"Sim", "Param", "Type", "Values", "Start", "Stop", "Points"});
hasFile = component->Props.count() > 0 && component->Props.at(0)->Name == "File";

paramsHiddenBySim["Export"] = QStringList{"NutmegEq"};
paramsHiddenBySim["Sim"] = QStringList{".AC", ".SP", ".TR", "Eqn", "SpicePar", "SpGlobPar"};
paramsHiddenBySim["Param"] = QStringList{".AC", ".SP", ".TR"};

// Setup the dialog according to the component kind.
if (isEquation)
{
// Create the equation editor.
QGroupBox *editorGroup = new QGroupBox(tr("Equation Editor"));
QGroupBox* editorGroup = new QGroupBox(tr("Equation Editor"));
static_cast<QVBoxLayout*>(layout())->addWidget(editorGroup, 2);
QVBoxLayout *editorLayout = new QVBoxLayout(editorGroup);
QVBoxLayout* editorLayout = new QVBoxLayout(editorGroup);

// Ngspice equations can be referenced to a simulation.
if (!paramsHiddenBySim["Sim"].contains(component->Model))
{
eqnSimCombo = new QComboBox();
Expand All @@ -380,6 +382,16 @@ ComponentDialog::ComponentDialog(Component* schematicComponent, Schematic* schem
new EqnHighlighter("ngspice", eqnEditor->document());
editorLayout->addWidget(eqnEditor, 2);

// Qucsator equations can choose whether to export values.
if (!paramsHiddenBySim["Export"].contains(component->Model))
{
QHBoxLayout* exportLayout = new QHBoxLayout;
eqnExportCheck = new QCheckBox(tr("Put result in dataset"), this);
exportLayout->addWidget(eqnExportCheck);
exportLayout->addStretch();
editorLayout->addLayout(exportLayout);
}

updateEqnEditor();
}

Expand Down Expand Up @@ -505,8 +517,6 @@ 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, const QString& value)
{
qDebug() << "updateSweepProperty " << property << " = " << value;

// Type has changed so update the widget presentation.
if (property == "Type")
updateSweepWidgets(sweepParamWidget["Type"]->value());
Expand Down Expand Up @@ -575,6 +585,7 @@ void ComponentDialog::updatePropertyTable()
int row = 0;
for (Property* property : component->Props)
{
// qDebug() << "Adding / updating property " << property->Name << " " << property->Value << " " << (property->display ? "Show" : "Hide");
// Check this is a sweep property (as there not added to property table).
if (hasSweep && sweepProperties.contains(property->Name))
continue;
Expand Down Expand Up @@ -637,12 +648,18 @@ void ComponentDialog::updateEqnEditor()

for (auto property : component->Props)
{
// qDebug() << "Adding / updating eqn property " << property->Name << " " << property->Value << " "
// << property->Description << " " << (property->display ? "Show" : "Hide");
if (eqnSimCombo && property->Name == "Simulation")
eqnSimCombo->setCurrentText(property->Value);

else if (eqnExportCheck && property->Name == "Export")
eqnExportCheck->setCheckState(property->Value == "yes" ? Qt::Checked : Qt::Unchecked);

else
eqnList.append(property->Name + " = " + property->Value + "\n");
}

eqnEditor->setPlainText(eqnList);
}

Expand All @@ -667,6 +684,9 @@ void ComponentDialog::writeEquation()
if (parts.count() == 2)
component->Props.append(new Property(parts[0].trimmed(), parts[1].trimmed(), true));
}

if (eqnExportCheck)
component->Props.append(new Property("Export", eqnExportCheck->checkState() == Qt::Checked ? "yes" : "no", false));
}

// -------------------------------------------------------------------------
Expand Down Expand Up @@ -847,7 +867,7 @@ void ComponentDialog::simpleEditEqn(QLineEdit* lineEdit)
SimpleEqnDialog::SimpleEqnDialog(QString& string, QWidget* parent)
: QDialog(parent), mText(string)
{
qDebug() << "Showing an equation editor.... " << string;
// qDebug() << "Showing an equation editor.... " << string;
setMinimumSize(300, 300);

// Setup dialog layout.
Expand Down
3 changes: 2 additions & 1 deletion qucs/components/componentdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class QGridLayout;

class ParamWidget;
class ParamLineEdit;
class CompoundWidget;
class ParamCombo;

class ComponentDialog : public QDialog
{
Expand All @@ -69,6 +69,7 @@ private slots:
QTableWidget* propertyTable;
QTextEdit* eqnEditor;
QComboBox* eqnSimCombo = nullptr;
QCheckBox* eqnExportCheck = nullptr;

Component* component;
Schematic* document;
Expand Down

0 comments on commit 61222d1

Please sign in to comment.