diff --git a/qucs/extsimkernels/customsimdialog.cpp b/qucs/extsimkernels/customsimdialog.cpp index 664d6ecfe..b3b22904e 100644 --- a/qucs/extsimkernels/customsimdialog.cpp +++ b/qucs/extsimkernels/customsimdialog.cpp @@ -29,7 +29,7 @@ /*! * \brief CustomSimDialog::CustomSimDialog class constructor * \param pc[in] Component that need to be edit. - * \param sch[in] Schematic on which a_component presents. + * \param sch[in] Schematic on which component presents. */ CustomSimDialog::CustomSimDialog(SpiceCustomSim *pc, Schematic *sch) : QDialog(sch), @@ -119,7 +119,7 @@ void CustomSimDialog::slotChanged() a_isChanged = true; } /*! - * \brief CustomSimDialog::slotApply Apply changes of a_component properties. + * \brief CustomSimDialog::slotApply Apply changes of component properties. */ void CustomSimDialog::slotApply() { diff --git a/qucs/extsimkernels/spicelibcompdialog.cpp b/qucs/extsimkernels/spicelibcompdialog.cpp index 9552ec15d..e8e02820b 100644 --- a/qucs/extsimkernels/spicelibcompdialog.cpp +++ b/qucs/extsimkernels/spicelibcompdialog.cpp @@ -11,56 +11,74 @@ #include "spicelibcompdialog.h" -SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{sch} +SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : + QDialog(sch), + a_symbolPinsCount(0), + a_isChanged(false), + a_libError(false), + a_prev_row(-1), + a_prev_col(-1), + a_lastSymbolDir(), + a_lastLibDir(), + a_comp(pc), + a_Doc(sch), + a_symbol(new SymbolWidget), + a_edtLibPath(new QLineEdit), + a_edtParams(new QLineEdit), + a_edtSymFile(new QLineEdit), + a_edtSPICE(new QPlainTextEdit), + a_btnOpenLib(new QPushButton(tr("Open"))), + a_btnOK(new QPushButton(tr("OK"))), + a_btnApply(new QPushButton(tr("Apply"))), + a_btnCancel(new QPushButton(tr("Cancel"))), + a_btnOpenSym(new QPushButton(tr("Open"))), + a_tbwPinsTable(new QTableWidget), + a_cbxSelectSubcir(new QComboBox), + a_listSymPattern(new QListWidget), + a_rbSymFromTemplate(new QRadioButton(tr("Symbol from template"))), + a_rbAutoSymbol(new QRadioButton(tr("Automatic symbol"))), + a_rbUserSym(new QRadioButton(tr("Symbol from file"))), + a_chbShowLib(new QCheckBox(tr("Show"))), + a_chbShowModel(new QCheckBox(tr("Show"))), + a_chbShowParams(new QCheckBox(tr("Show"))), + a_subcirPins(), + a_subcirSPICE() { - comp = pc; - Doc = sch; - symbolPinsCount = 0; - isChanged = false; - libError = false; - prev_col = -1; - prev_row = -1; - - QString file = comp->Props.at(0)->Value; + QString file = a_comp->Props.at(0)->Value; if (!file.isEmpty()) { - file = misc::properAbsFileName(file, Doc); + file = misc::properAbsFileName(file, a_Doc); QFileInfo inf(file); - lastLibDir = inf.absoluteDir().path(); + a_lastLibDir = inf.absoluteDir().path(); } else { - QFileInfo inf = Doc->getFileInfo(); + QFileInfo inf = a_Doc->getFileInfo(); if (inf.absoluteFilePath().isEmpty()) { // untitled document - lastLibDir = QucsSettings.QucsWorkDir.absolutePath(); + a_lastLibDir = QucsSettings.QucsWorkDir.absolutePath(); } else { // saved schematic - lastLibDir = inf.absoluteDir().path(); + a_lastLibDir = inf.absoluteDir().path(); } } - bool show_lib = comp->Props.at(0)->display; - QString device = comp->Props.at(1)->Value; - bool show_model = comp->Props.at(1)->display; - QString sym = comp->Props.at(2)->Value; - QString par = comp->Props.at(3)->Value; - bool show_par = comp->Props.at(3)->display; - QString pin_list = comp->Props.at(4)->Value; + bool show_lib = a_comp->Props.at(0)->display; + QString device = a_comp->Props.at(1)->Value; + bool show_model = a_comp->Props.at(1)->display; + QString sym = a_comp->Props.at(2)->Value; + QString par = a_comp->Props.at(3)->Value; + bool show_par = a_comp->Props.at(3)->display; + QString pin_list = a_comp->Props.at(4)->Value; QLabel *lblLibfile = new QLabel("SPICE library:"); - edtLibPath = new QLineEdit; - edtLibPath->setText(file); - connect(edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotFillSubcirComboBox())); - btnOpenLib = new QPushButton(tr("Open")); - connect(btnOpenLib,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenLib())); + a_edtLibPath->setText(file); + connect(a_edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotFillSubcirComboBox())); + connect(a_btnOpenLib,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenLib())); QLabel *lbl_par = new QLabel("Component parameters"); - edtParams = new QLineEdit; - edtParams->setText(par); + a_edtParams->setText(par); QLabel *lblDevice = new QLabel("Subcircuit:"); - cbxSelectSubcir = new QComboBox; - connect(cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotFillPinsTable())); + connect(a_cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotFillPinsTable())); - listSymPattern = new QListWidget; QStringList lst_patterns; misc::getSymbolPatternsList(lst_patterns); - listSymPattern->addItems(lst_patterns); + a_listSymPattern->addItems(lst_patterns); if (lst_patterns.isEmpty()) { QString dir_name = QucsSettings.BinDir + "/../share/" QUCS_NAME "/symbols/"; QString msg = tr("No symbol files found at the following path:\n"); @@ -68,114 +86,100 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{ msg += tr("\nCheck you installation!\n"); QMessageBox::warning(this,tr("Warning"),msg); } - listSymPattern->setCurrentRow(0); - listSymPattern->setSelectionMode(QAbstractItemView::SingleSelection); - connect(listSymPattern,SIGNAL(currentRowChanged(int)),this,SLOT(slotSetSymbol())); + a_listSymPattern->setCurrentRow(0); + a_listSymPattern->setSelectionMode(QAbstractItemView::SingleSelection); + connect(a_listSymPattern,SIGNAL(currentRowChanged(int)),this,SLOT(slotSetSymbol())); - rbAutoSymbol = new QRadioButton(tr("Automatic symbol")); - rbSymFromTemplate = new QRadioButton(tr("Symbol from template")); if (lst_patterns.isEmpty()) { - rbSymFromTemplate->setEnabled(false); + a_rbSymFromTemplate->setEnabled(false); } - rbUserSym = new QRadioButton(tr("Symbol from file")); - btnOpenSym = new QPushButton(tr("Open")); - edtSymFile = new QLineEdit(); - connect(btnOpenSym,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenSym())); - - chbShowLib = new QCheckBox(tr("Show")); - chbShowLib->setChecked(show_lib); - chbShowModel = new QCheckBox(tr("Show")); - chbShowModel->setChecked(show_model); - chbShowParams = new QCheckBox(tr("Show")); - chbShowParams->setChecked(show_par); - connect(chbShowLib,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); - connect(chbShowModel,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); - connect(chbShowParams,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); - - if (QFileInfo::exists(misc::properAbsFileName(sym, Doc))) { - edtSymFile->setText(misc::properAbsFileName(sym, Doc)); - rbUserSym->setChecked(true); - QFileInfo inf(misc::properAbsFileName(sym, Doc)); - lastSymbolDir = inf.absoluteDir().path(); + connect(a_btnOpenSym,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenSym())); + + a_chbShowLib->setChecked(show_lib); + a_chbShowModel->setChecked(show_model); + a_chbShowParams->setChecked(show_par); + connect(a_chbShowLib,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); + connect(a_chbShowModel,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); + connect(a_chbShowParams,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); + + if (QFileInfo::exists(misc::properAbsFileName(sym, a_Doc))) { + a_edtSymFile->setText(misc::properAbsFileName(sym, a_Doc)); + a_rbUserSym->setChecked(true); + QFileInfo inf(misc::properAbsFileName(sym, a_Doc)); + a_lastSymbolDir = inf.absoluteDir().path(); } else { - QFileInfo inf = Doc->getFileInfo(); - lastSymbolDir = inf.absoluteDir().path(); + QFileInfo inf = a_Doc->getFileInfo(); + a_lastSymbolDir = inf.absoluteDir().path(); if (sym == "auto") { - rbAutoSymbol->setChecked(true); + a_rbAutoSymbol->setChecked(true); } else { - rbSymFromTemplate->setChecked(true); + a_rbSymFromTemplate->setChecked(true); } } - symbol = new SymbolWidget; - symbol->disableDragNDrop(); - symbol->enableShowPinNumbers(); - symbol->setPaintText(""); + a_symbol->disableDragNDrop(); + a_symbol->enableShowPinNumbers(); + a_symbol->setPaintText(""); - tbwPinsTable = new QTableWidget; - tbwPinsTable->setColumnCount(2); - tbwPinsTable->setRowCount(100); + a_tbwPinsTable->setColumnCount(2); + a_tbwPinsTable->setRowCount(100); QStringList lbl_cols; lbl_cols<<"Subcircuit pin"<<"Symbol pin"; - tbwPinsTable->setHorizontalHeaderLabels(lbl_cols); - tbwPinsTable->setMinimumWidth(2.2*tbwPinsTable->columnWidth(0)); - tbwPinsTable->setMinimumHeight(5*tbwPinsTable->rowHeight(0)); - connect(tbwPinsTable,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(slotTableCellDoubleClick())); - - edtSPICE = new QPlainTextEdit; - edtSPICE->setReadOnly(true); - edtSPICE->setMinimumSize(tbwPinsTable->minimumSize()); - - btnOK = new QPushButton(tr("OK")); - connect(btnOK,SIGNAL(clicked(bool)),this,SLOT(slotBtnOK())); - btnApply = new QPushButton(tr("Apply")); - connect(btnApply,SIGNAL(clicked(bool)),this,SLOT(slotBtnApply())); - btnCancel = new QPushButton(tr("Cancel")); - connect(btnCancel,SIGNAL(clicked(bool)),this,SLOT(slotBtnCancel())); + a_tbwPinsTable->setHorizontalHeaderLabels(lbl_cols); + a_tbwPinsTable->setMinimumWidth(2.2*a_tbwPinsTable->columnWidth(0)); + a_tbwPinsTable->setMinimumHeight(5*a_tbwPinsTable->rowHeight(0)); + connect(a_tbwPinsTable,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(slotTableCellDoubleClick())); + + a_edtSPICE->setReadOnly(true); + a_edtSPICE->setMinimumSize(a_tbwPinsTable->minimumSize()); + + connect(a_btnOK,SIGNAL(clicked(bool)),this,SLOT(slotBtnOK())); + connect(a_btnApply,SIGNAL(clicked(bool)),this,SLOT(slotBtnApply())); + connect(a_btnCancel,SIGNAL(clicked(bool)),this,SLOT(slotBtnCancel())); QVBoxLayout *top = new QVBoxLayout; QHBoxLayout *l2 = new QHBoxLayout; l2->addWidget(lblLibfile); - l2->addWidget(edtLibPath,4); - l2->addWidget(btnOpenLib,1); - l2->addWidget(chbShowLib); + l2->addWidget(a_edtLibPath,4); + l2->addWidget(a_btnOpenLib,1); + l2->addWidget(a_chbShowLib); top->addLayout(l2); QHBoxLayout *l7 = new QHBoxLayout; l7->addWidget(lbl_par); - l7->addWidget(edtParams); - l7->addWidget(chbShowParams); + l7->addWidget(a_edtParams); + l7->addWidget(a_chbShowParams); top->addLayout(l7); QGridLayout *gl1 = new QGridLayout; - gl1->addWidget(rbAutoSymbol,0,0); - gl1->addWidget(rbSymFromTemplate,1,0); - gl1->addWidget(rbUserSym,2,0); - gl1->addWidget(edtSymFile,2,1); - gl1->addWidget(btnOpenSym,2,2); - gl1->addWidget(symbol,0,3,3,2); - gl1->addWidget(listSymPattern,0,5,3,2); + gl1->addWidget(a_rbAutoSymbol,0,0); + gl1->addWidget(a_rbSymFromTemplate,1,0); + gl1->addWidget(a_rbUserSym,2,0); + gl1->addWidget(a_edtSymFile,2,1); + gl1->addWidget(a_btnOpenSym,2,2); + gl1->addWidget(a_symbol,0,3,3,2); + gl1->addWidget(a_listSymPattern,0,5,3,2); top->addLayout(gl1); QHBoxLayout *l3 = new QHBoxLayout; - l3->addWidget(tbwPinsTable); + l3->addWidget(a_tbwPinsTable); QGroupBox *gpb1 = new QGroupBox(tr("SPICE model")); QVBoxLayout *l8 = new QVBoxLayout; QHBoxLayout *l5 = new QHBoxLayout; l5->addWidget(lblDevice); - l5->addWidget(cbxSelectSubcir); - l5->addWidget(chbShowModel); + l5->addWidget(a_cbxSelectSubcir); + l5->addWidget(a_chbShowModel); l8->addLayout(l5); - l8->addWidget(edtSPICE); + l8->addWidget(a_edtSPICE); gpb1->setLayout(l8); l3->addWidget(gpb1); top->addLayout(l3,3); QHBoxLayout *l4 = new QHBoxLayout; - l4->addWidget(btnOK); - l4->addWidget(btnApply); - l4->addWidget(btnCancel); + l4->addWidget(a_btnOK); + l4->addWidget(a_btnApply); + l4->addWidget(a_btnCancel); l4->addStretch(); top->addLayout(l4); @@ -184,46 +188,46 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{ this->setWindowTitle(tr("Edit SPICE library device")); slotFillSubcirComboBox(); - cbxSelectSubcir->setCurrentText(device); - auto items = listSymPattern->findItems(sym,Qt::MatchExactly); - if (!items.isEmpty()) listSymPattern->setCurrentItem(items.at(0)); - //listSymPattern->setCurrentText(sym); + a_cbxSelectSubcir->setCurrentText(device); + auto items = a_listSymPattern->findItems(sym,Qt::MatchExactly); + if (!items.isEmpty()) a_listSymPattern->setCurrentItem(items.at(0)); + //a_listSymPattern->setCurrentText(sym); if (!pin_list.isEmpty()) { QStringList pins = pin_list.split(";"); for(int i = 0; i < pins.count(); i++) { - QTableWidgetItem *itm = tbwPinsTable->item(i,1); + QTableWidgetItem *itm = a_tbwPinsTable->item(i,1); if (itm != nullptr) { itm->setText(pins.at(i)); } } } - listSymPattern->setMinimumWidth(0.75*tbwPinsTable->minimumWidth()); - symbol->setMinimumWidth(0.75*tbwPinsTable->minimumWidth()); - - btnApply->setEnabled(false); - connect(rbAutoSymbol,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); - connect(rbSymFromTemplate,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); - connect(rbUserSym,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); - connect(edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); - connect(edtParams,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); - connect(tbwPinsTable,SIGNAL(cellChanged(int,int)),this,SLOT(slotChanged())); - connect(listSymPattern,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); - connect(cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); - connect(edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotSetSymbol())); - connect(edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); + a_listSymPattern->setMinimumWidth(0.75*a_tbwPinsTable->minimumWidth()); + a_symbol->setMinimumWidth(0.75*a_tbwPinsTable->minimumWidth()); + + a_btnApply->setEnabled(false); + connect(a_rbAutoSymbol,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); + connect(a_rbSymFromTemplate,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); + connect(a_rbUserSym,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); + connect(a_edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); + connect(a_edtParams,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); + connect(a_tbwPinsTable,SIGNAL(cellChanged(int,int)),this,SLOT(slotChanged())); + connect(a_listSymPattern,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); + connect(a_cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); + connect(a_edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotSetSymbol())); + connect(a_edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); } void SpiceLibCompDialog::slotFillSubcirComboBox() { - QString libfile = edtLibPath->text(); + QString libfile = a_edtLibPath->text(); if (!QFile::exists(libfile)) return; int r = parseLibFile(libfile); - libError = false; + a_libError = false; if (r != noError) { - libError = true; + a_libError = true; QString msg; switch (r) { case failedOpenFile: @@ -240,31 +244,31 @@ void SpiceLibCompDialog::slotFillSubcirComboBox() return; } - cbxSelectSubcir->blockSignals(true); - cbxSelectSubcir->clear(); - for(const auto &key: subcirPins.keys()) { - cbxSelectSubcir->addItem(key); + a_cbxSelectSubcir->blockSignals(true); + a_cbxSelectSubcir->clear(); + for(const auto &key: a_subcirPins.keys()) { + a_cbxSelectSubcir->addItem(key); } - cbxSelectSubcir->blockSignals(false); + a_cbxSelectSubcir->blockSignals(false); slotFillPinsTable(); } void SpiceLibCompDialog::slotFillPinsTable() { - QString subcir_name = cbxSelectSubcir->currentText(); - if (subcirPins.find(subcir_name) == subcirPins.end()) return; - QStringList pins = subcirPins[subcir_name]; - tbwPinsTable->clearContents(); - tbwPinsTable->setRowCount(pins.count()); + QString subcir_name = a_cbxSelectSubcir->currentText(); + if (a_subcirPins.find(subcir_name) == a_subcirPins.end()) return; + QStringList pins = a_subcirPins[subcir_name]; + a_tbwPinsTable->clearContents(); + a_tbwPinsTable->setRowCount(pins.count()); for (int i = 0; i < pins.count(); i++) { QTableWidgetItem *itm1 = new QTableWidgetItem(pins.at(i)); - tbwPinsTable->setItem(i,0,itm1); + a_tbwPinsTable->setItem(i,0,itm1); QTableWidgetItem *itm2 = new QTableWidgetItem("NC"); - tbwPinsTable->setItem(i,1,itm2); + a_tbwPinsTable->setItem(i,1,itm2); } - edtSPICE->clear(); - edtSPICE->setPlainText(subcirSPICE[subcir_name]); + a_edtSPICE->clear(); + a_edtSPICE->setPlainText(a_subcirSPICE[subcir_name]); } int SpiceLibCompDialog::parseLibFile(const QString &filename) @@ -276,8 +280,8 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) return failedOpenFile; } - subcirPins.clear(); - subcirSPICE.clear(); + a_subcirPins.clear(); + a_subcirSPICE.clear(); QTextStream ts(&f); bool subcir_start = false; @@ -300,7 +304,7 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) if (line.startsWith("+")) { line.remove(0,1); QStringList pins = line.split(QRegularExpression("[ \\t]"),Qt::SkipEmptyParts); - subcirPins[last_subcir].append(pins); + a_subcirPins[last_subcir].append(pins); } else { // end of header header_start = false; @@ -325,19 +329,19 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) pin_names.append(s1); } } - subcirPins[subname] = pin_names; + a_subcirPins[subname] = pin_names; } if (subcir_start) { subcir_body += line + "\n"; } if (line.startsWith(".ENDS")) { subcir_start = false; - subcirSPICE[subname] = subcir_body; + a_subcirSPICE[subname] = subcir_body; } } f.close(); - if (subcirPins.isEmpty()) { + if (a_subcirPins.isEmpty()) { return noSUBCKT; } return noError; @@ -347,40 +351,40 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) void SpiceLibCompDialog::slotSetSymbol() { int result = -1; - if (rbAutoSymbol->isChecked()) { - tbwPinsTable->setEnabled(false); - listSymPattern->setEnabled(false); - edtSymFile->setEnabled(false); - btnOpenSym->setEnabled(false); + if (a_rbAutoSymbol->isChecked()) { + a_tbwPinsTable->setEnabled(false); + a_listSymPattern->setEnabled(false); + a_edtSymFile->setEnabled(false); + a_btnOpenSym->setEnabled(false); QString s1 = ""; QString s2 = "SpLib"; - symbol->setSymbol(s1, s1, s2); + a_symbol->setSymbol(s1, s1, s2); result = 0; - symbol->setWarning(tr("No symbol loaded")); - symbolPinsCount = 0; - } else if (rbSymFromTemplate->isChecked()) { - if (listSymPattern->currentItem() == nullptr) { + a_symbol->setWarning(tr("No symbol loaded")); + a_symbolPinsCount = 0; + } else if (a_rbSymFromTemplate->isChecked()) { + if (a_listSymPattern->currentItem() == nullptr) { return; // empty list } - tbwPinsTable->setEnabled(true); - listSymPattern->setEnabled(true); - edtSymFile->setEnabled(false); - btnOpenSym->setEnabled(false); + a_tbwPinsTable->setEnabled(true); + a_listSymPattern->setEnabled(true); + a_edtSymFile->setEnabled(false); + a_btnOpenSym->setEnabled(false); QString dir_name = QucsSettings.BinDir + "/../share/" QUCS_NAME "/symbols/"; - QString file = dir_name + listSymPattern->currentItem()->text() + ".sym"; - result = symbol->loadSymFile(file); - symbolPinsCount = symbol->getPortsNumber(); - } else if (rbUserSym->isChecked()) { - tbwPinsTable->setEnabled(true); - listSymPattern->setEnabled(false); - edtSymFile->setEnabled(true); - btnOpenSym->setEnabled(true); - if (edtSymFile->text().isEmpty()) { - symbolPinsCount = 0; + QString file = dir_name + a_listSymPattern->currentItem()->text() + ".sym"; + result = a_symbol->loadSymFile(file); + a_symbolPinsCount = a_symbol->getPortsNumber(); + } else if (a_rbUserSym->isChecked()) { + a_tbwPinsTable->setEnabled(true); + a_listSymPattern->setEnabled(false); + a_edtSymFile->setEnabled(true); + a_btnOpenSym->setEnabled(true); + if (a_edtSymFile->text().isEmpty()) { + a_symbolPinsCount = 0; return; } - result = symbol->loadSymFile(edtSymFile->text()); - symbolPinsCount = symbol->getPortsNumber(); + result = a_symbol->loadSymFile(a_edtSymFile->text()); + a_symbolPinsCount = a_symbol->getPortsNumber(); } if (result < 0) { @@ -388,33 +392,33 @@ void SpiceLibCompDialog::slotSetSymbol() return; } - for (int i = 0; i < tbwPinsTable->rowCount(); i++) { + for (int i = 0; i < a_tbwPinsTable->rowCount(); i++) { QTableWidgetItem *itm = new QTableWidgetItem("NC"); - tbwPinsTable->setItem(i,1,itm); + a_tbwPinsTable->setItem(i,1,itm); } - isChanged = true; - btnApply->setEnabled(true); + a_isChanged = true; + a_btnApply->setEnabled(true); } void SpiceLibCompDialog::slotTableCellDoubleClick() { - int r = tbwPinsTable->currentRow(); - int c = tbwPinsTable->currentColumn(); + int r = a_tbwPinsTable->currentRow(); + int c = a_tbwPinsTable->currentColumn(); if (c == 0) return; // do not edit the first column - if (prev_col >= 0 && prev_row >= 0) { // remove combo box from previous cell + if (a_prev_col >= 0 && a_prev_row >= 0) { // remove combo box from previous cell QTableWidgetItem *itm = new QTableWidgetItem("NC"); - tbwPinsTable->removeCellWidget(prev_row, prev_col); - tbwPinsTable->setItem(prev_row, prev_col, itm); + a_tbwPinsTable->removeCellWidget(a_prev_row, a_prev_col); + a_tbwPinsTable->setItem(a_prev_row, a_prev_col, itm); } QComboBox *cbxSelectPin = new QComboBox; cbxSelectPin->addItem("NC"); - for (int i = 1; i <= symbolPinsCount; i++) { + for (int i = 1; i <= a_symbolPinsCount; i++) { bool pinAssigned = false; - for(int j = 0; j < tbwPinsTable->rowCount(); j++) { + for(int j = 0; j < a_tbwPinsTable->rowCount(); j++) { if (j == r) continue; - auto itm = tbwPinsTable->item(j,1); + auto itm = a_tbwPinsTable->item(j,1); if (itm == nullptr) continue; QString s = itm->text(); if (s.isEmpty()) continue; @@ -428,49 +432,49 @@ void SpiceLibCompDialog::slotTableCellDoubleClick() cbxSelectPin->addItem(QString::number(i)); } } - tbwPinsTable->item(r,c)->setText(""); - tbwPinsTable->setCellWidget(r,c,cbxSelectPin); + a_tbwPinsTable->item(r,c)->setText(""); + a_tbwPinsTable->setCellWidget(r,c,cbxSelectPin); connect(cbxSelectPin,SIGNAL(activated(int)),this,SLOT(slotSelectPin())); - prev_col = c; // remebmebr cell with combo box - prev_row = r; + a_prev_col = c; // remebmebr cell with combo box + a_prev_row = r; } void SpiceLibCompDialog::slotSelectPin() { QComboBox *cbxSelectPin = qobject_cast(sender()); QString pin = cbxSelectPin->currentText(); - int r = tbwPinsTable->currentRow(); - int c = tbwPinsTable->currentColumn(); + int r = a_tbwPinsTable->currentRow(); + int c = a_tbwPinsTable->currentColumn(); QTableWidgetItem *itm = new QTableWidgetItem(pin); - tbwPinsTable->removeCellWidget(r,c); - tbwPinsTable->setItem(r,c,itm); + a_tbwPinsTable->removeCellWidget(r,c); + a_tbwPinsTable->setItem(r,c,itm); - prev_col = -1; // clear cell index with combo box - prev_row = -1; + a_prev_col = -1; // clear cell index with combo box + a_prev_row = -1; } void SpiceLibCompDialog::slotBtnOpenLib() { QString s = QFileDialog::getOpenFileName(this, tr("Open SPICE library"), - lastLibDir, + a_lastLibDir, tr("SPICE files (*.cir +.ckt *.sp *.lib)")); if (!s.isEmpty()) { QFileInfo inf(s); - lastLibDir = inf.absoluteDir().path(); - edtLibPath->setText(s); + a_lastLibDir = inf.absoluteDir().path(); + a_edtLibPath->setText(s); } } void SpiceLibCompDialog::slotBtnOpenSym() { QString s = QFileDialog::getOpenFileName(this, tr("Open symbol file"), - lastSymbolDir, + a_lastSymbolDir, tr("Schematic symbol (*.sym)")); if (!s.isEmpty()) { QFileInfo inf(s); - lastSymbolDir = inf.absoluteDir().path(); - edtSymFile->setText(s); + a_lastSymbolDir = inf.absoluteDir().path(); + a_edtSymFile->setText(s); } } @@ -478,11 +482,11 @@ bool SpiceLibCompDialog::setCompProps() { QStringList pins; QString pin_string; - if (rbAutoSymbol->isChecked()) { + if (a_rbAutoSymbol->isChecked()) { pin_string = ""; } else { - for (int i = 0; i < tbwPinsTable->rowCount(); i++) { - QTableWidgetItem *itm = tbwPinsTable->item(i,1); + for (int i = 0; i < a_tbwPinsTable->rowCount(); i++) { + QTableWidgetItem *itm = a_tbwPinsTable->item(i,1); if (itm == nullptr) continue; QString s = itm->text(); if (s == "NC") { @@ -494,15 +498,15 @@ bool SpiceLibCompDialog::setCompProps() pin_string = pins.join(";"); } - if (rbUserSym->isChecked() && - !QFileInfo::exists(edtSymFile->text())) { + if (a_rbUserSym->isChecked() && + !QFileInfo::exists(a_edtSymFile->text())) { QMessageBox::warning(this,tr("Warning"),tr("Set a valid symbol file name")); return false; } - QString sch_dir = Doc->getFileInfo().absoluteDir().path(); - QString libpath = edtLibPath->text(); - QString sympath = edtSymFile->text(); + QString sch_dir = a_Doc->getFileInfo().absoluteDir().path(); + QString libpath = a_edtLibPath->text(); + QString sympath = a_edtSymFile->text(); if (libpath.startsWith(sch_dir)) { libpath = QDir(sch_dir).relativeFilePath(libpath); } @@ -510,50 +514,50 @@ bool SpiceLibCompDialog::setCompProps() sympath = QDir(sch_dir).relativeFilePath(sympath); } - auto pp = comp->Props.begin(); + auto pp = a_comp->Props.begin(); (*pp)->Value = libpath; - (*pp)->display = chbShowLib->isChecked(); + (*pp)->display = a_chbShowLib->isChecked(); pp++; - (*pp)->Value = cbxSelectSubcir->currentText(); - (*pp)->display = chbShowModel->isChecked(); + (*pp)->Value = a_cbxSelectSubcir->currentText(); + (*pp)->display = a_chbShowModel->isChecked(); pp++; - if (rbAutoSymbol->isChecked()) { + if (a_rbAutoSymbol->isChecked()) { (*pp)->Value = "auto"; - } else if (rbSymFromTemplate->isChecked()) { - (*pp)->Value = listSymPattern->currentItem()->text(); - } else if (rbUserSym->isChecked()) { + } else if (a_rbSymFromTemplate->isChecked()) { + (*pp)->Value = a_listSymPattern->currentItem()->text(); + } else if (a_rbUserSym->isChecked()) { (*pp)->Value = sympath; } pp++; - (*pp)->Value = edtParams->text(); - (*pp)->display = chbShowParams->isChecked(); + (*pp)->Value = a_edtParams->text(); + (*pp)->display = a_chbShowParams->isChecked(); pp++; (*pp)->Value = QString(pin_string); - Doc->recreateComponent(comp); - Doc->viewport()->repaint(); - Doc->setChanged(true,true); + a_Doc->recreateComponent(a_comp); + a_Doc->viewport()->repaint(); + a_Doc->setChanged(true,true); return true; } void SpiceLibCompDialog::slotBtnApply() { - if (isChanged) { - if (libError) { + if (a_isChanged) { + if (a_libError) { QMessageBox::critical(this,tr("Error"), tr("There were library file parse error! Cannot apply changes.")); return; } if (setCompProps()) { - isChanged = false; - btnApply->setEnabled(false); + a_isChanged = false; + a_btnApply->setEnabled(false); } } } void SpiceLibCompDialog::slotBtnOK() { - if (isChanged) { - if (libError) { + if (a_isChanged) { + if (a_libError) { QMessageBox::critical(this,tr("Error"), tr("There were library file parse error! Cannot apply changes.")); reject(); @@ -572,6 +576,6 @@ void SpiceLibCompDialog::slotBtnCancel() void SpiceLibCompDialog::slotChanged() { - isChanged = true; - btnApply->setEnabled(true); + a_isChanged = true; + a_btnApply->setEnabled(true); } diff --git a/qucs/extsimkernels/spicelibcompdialog.h b/qucs/extsimkernels/spicelibcompdialog.h index ef7cc7db9..7da4a07b3 100644 --- a/qucs/extsimkernels/spicelibcompdialog.h +++ b/qucs/extsimkernels/spicelibcompdialog.h @@ -16,32 +16,43 @@ class SpiceLibCompDialog : public QDialog { Q_OBJECT private: - int symbolPinsCount; - bool isChanged; - bool libError; - - int prev_row, prev_col; - - QString lastSymbolDir; - QString lastLibDir; - - Component *comp; - Schematic *Doc; - - SymbolWidget *symbol; - QLineEdit *edtLibPath, *edtParams, *edtSymFile; - QPlainTextEdit *edtSPICE; - - QPushButton *btnOpenLib, *btnOK, *btnApply, *btnCancel, *btnOpenSym; - QTableWidget *tbwPinsTable; - QComboBox *cbxSelectSubcir; - QListWidget *listSymPattern; - - QRadioButton *rbSymFromTemplate, *rbAutoSymbol, *rbUserSym; - QCheckBox *chbShowLib, *chbShowModel, *chbShowParams; - - QMap subcirPins; - QMap subcirSPICE; + int a_symbolPinsCount; + bool a_isChanged; + bool a_libError; + + int a_prev_row; + int a_prev_col; + + QString a_lastSymbolDir; + QString a_lastLibDir; + + Component* a_comp; + Schematic* a_Doc; + + SymbolWidget *a_symbol; + QLineEdit* a_edtLibPath; + QLineEdit* a_edtParams; + QLineEdit* a_edtSymFile; + QPlainTextEdit* a_edtSPICE; + + QPushButton* a_btnOpenLib; + QPushButton* a_btnOK; + QPushButton* a_btnApply; + QPushButton* a_btnCancel; + QPushButton* a_btnOpenSym; + QTableWidget* a_tbwPinsTable; + QComboBox* a_cbxSelectSubcir; + QListWidget* a_listSymPattern; + + QRadioButton* a_rbSymFromTemplate; + QRadioButton* a_rbAutoSymbol; + QRadioButton* a_rbUserSym; + QCheckBox* a_chbShowLib; + QCheckBox* a_chbShowModel; + QCheckBox* a_chbShowParams; + + QMap a_subcirPins; + QMap a_subcirSPICE; enum SPICEparseError { noError=0, failedOpenFile = -1, noSUBCKT = -2 };