Skip to content

Commit

Permalink
Merge pull request #781 from ra3xdh/679_improve_symdialog
Browse files Browse the repository at this point in the history
Improve SpiceLibComp dialog
  • Loading branch information
ra3xdh committed Jun 23, 2024
2 parents 1c83de6 + 278a5bb commit 6d2c931
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 20 deletions.
22 changes: 22 additions & 0 deletions library/symbols/opamp6t.sym
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Qucs Schematic 24.2.1>
<Symbol>
<Line -20 -50 0 100 #000080 2 1>
<Line -20 50 70 -50 #000080 2 1>
<Line -40 -20 20 0 #000080 2 1>
<Line -40 20 20 0 #000080 2 1>
<Line -15 20 10 0 #000000 2 1>
<Line -10 -25 0 10 #ff0000 0 1>
<Line -15 -20 10 0 #ff0000 0 1>
<.PortSym -40 20 2 0 >
<.PortSym -40 -20 1 0 >
<.PortSym 10 50 4 0 >
<.PortSym 10 -50 3 0 >
<.PortSym 70 0 5 180 >
<Line 50 0 20 0 #000080 2 1>
<Line -20 -50 70 50 #000080 2 1>
<Line 10 30 0 20 #000080 2 1>
<Line 10 -30 0 -20 #000080 2 1>
<.ID 30 -66 OP>
<.PortSym 40 50 6 0 6>
<Line 40 8 0 42 #000080 2 1>
</Symbol>
71 changes: 54 additions & 17 deletions qucs/extsimkernels/spicelibcompdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{
Doc = sch;
symbolPinsCount = 0;
isChanged = false;
libError = false;

QString file = comp->Props.at(0)->Value;
if (!file.isEmpty()) {
Expand Down Expand Up @@ -50,11 +51,13 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{
cbxSelectSubcir = new QComboBox;
connect(cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotFillPinsTable()));

cbxSymPattern = new QComboBox;
listSymPattern = new QListWidget;
QStringList lst_patterns;
misc::getSymbolPatternsList(lst_patterns);
cbxSymPattern->addItems(lst_patterns);
connect(cbxSymPattern,SIGNAL(currentIndexChanged(int)),this,SLOT(slotSetSymbol()));
listSymPattern->addItems(lst_patterns);
listSymPattern->setCurrentRow(0);
listSymPattern->setSelectionMode(QAbstractItemView::SingleSelection);
connect(listSymPattern,SIGNAL(currentRowChanged(int)),this,SLOT(slotSetSymbol()));

rbAutoSymbol = new QRadioButton(tr("Automatic symbol"));
rbSymFromTemplate = new QRadioButton(tr("Symbol from template"));
Expand Down Expand Up @@ -93,6 +96,7 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{
symbol = new SymbolWidget;
symbol->disableDragNDrop();
symbol->enableShowPinNumbers();
symbol->setPaintText("");

tbwPinsTable = new QTableWidget;
tbwPinsTable->setColumnCount(2);
Expand Down Expand Up @@ -133,10 +137,10 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{
gl1->addWidget(rbAutoSymbol,0,0);
gl1->addWidget(rbSymFromTemplate,1,0);
gl1->addWidget(rbUserSym,2,0);
gl1->addWidget(cbxSymPattern,1,1);
gl1->addWidget(edtSymFile,2,1);
gl1->addWidget(btnOpenSym,2,2);
gl1->addWidget(symbol,0,3,3,2);
gl1->addWidget(listSymPattern,0,5,3,2);
top->addLayout(gl1);

QHBoxLayout *l3 = new QHBoxLayout;
Expand Down Expand Up @@ -167,7 +171,9 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{
slotFillSubcirComboBox();

cbxSelectSubcir->setCurrentText(device);
cbxSymPattern->setCurrentText(sym);
auto items = listSymPattern->findItems(sym,Qt::MatchExactly);
if (!items.isEmpty()) listSymPattern->setCurrentItem(items.at(0));
//listSymPattern->setCurrentText(sym);

if (!pin_list.isEmpty()) {
QStringList pins = pin_list.split(";");
Expand All @@ -179,14 +185,17 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{
}
}

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(cbxSymPattern,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged()));
connect(listSymPattern,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged()));
connect(cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged()));

}
Expand All @@ -195,8 +204,23 @@ void SpiceLibCompDialog::slotFillSubcirComboBox()
{
QString libfile = edtLibPath->text();
if (!QFile::exists(libfile)) return;
if (!parseLibFile(libfile)) {
QMessageBox::critical(this,tr("Error"),tr("SPICE library parse error"));
int r = parseLibFile(libfile);
libError = false;
if (r != noError) {
libError = true;
QString msg;
switch (r) {
case failedOpenFile:
msg = tr("Failed open file: ") + libfile;
break;
case noSUBCKT:
msg = tr("SPICE library parse error.\n"
"No SUBCKT directive found in library ") + libfile;
break;
default:
msg = tr("SPICE library parse error");
}
QMessageBox::critical(this,tr("Error"),msg);
return;
}

Expand Down Expand Up @@ -227,12 +251,13 @@ void SpiceLibCompDialog::slotFillPinsTable()
edtSPICE->setPlainText(subcirSPICE[subcir_name]);
}

bool SpiceLibCompDialog::parseLibFile(const QString &filename)
int SpiceLibCompDialog::parseLibFile(const QString &filename)
{
if (!QFileInfo::exists(filename)) return false;
QFile f(filename);
if (!f.open(QIODevice::ReadOnly)) {
return false;
QMessageBox::critical(this,tr("Error"),tr("Failed to open file: ") + filename);
return failedOpenFile;
}

subcirPins.clear();
Expand Down Expand Up @@ -274,35 +299,36 @@ bool SpiceLibCompDialog::parseLibFile(const QString &filename)

f.close();
if (subcirPins.isEmpty()) {
return false;
return noSUBCKT;
}
return true;
return noError;

}

void SpiceLibCompDialog::slotSetSymbol()
{
if (rbAutoSymbol->isChecked()) {
tbwPinsTable->setEnabled(false);
cbxSymPattern->setEnabled(false);
listSymPattern->setEnabled(false);
edtSymFile->setEnabled(false);
btnOpenSym->setEnabled(false);
QString s1 = "";
QString s2 = "SpLib";
symbol->setSymbol(s1, s1, s2);
symbol->setWarning(tr("No symbol loaded"));
symbolPinsCount = 0;
} else if (rbSymFromTemplate->isChecked()) {
tbwPinsTable->setEnabled(true);
cbxSymPattern->setEnabled(true);
listSymPattern->setEnabled(true);
edtSymFile->setEnabled(false);
btnOpenSym->setEnabled(false);
QString dir_name = QucsSettings.BinDir + "/../share/" QUCS_NAME "/symbols/";
QString file = dir_name + cbxSymPattern->currentText() + ".sym";
QString file = dir_name + listSymPattern->currentItem()->text() + ".sym";
symbol->loadSymFile(file);
symbolPinsCount = symbol->getPortsNumber();
} else if (rbUserSym->isChecked()) {
tbwPinsTable->setEnabled(true);
cbxSymPattern->setEnabled(false);
listSymPattern->setEnabled(false);
edtSymFile->setEnabled(true);
btnOpenSym->setEnabled(true);
symbol->loadSymFile(edtSymFile->text());
Expand Down Expand Up @@ -426,7 +452,7 @@ bool SpiceLibCompDialog::setCompProps()
if (rbAutoSymbol->isChecked()) {
pp->Value = "auto";
} else if (rbSymFromTemplate->isChecked()) {
pp->Value = cbxSymPattern->currentText();
pp->Value = listSymPattern->currentItem()->text();
} else if (rbUserSym->isChecked()) {
pp->Value = sympath;
}
Expand All @@ -444,6 +470,11 @@ bool SpiceLibCompDialog::setCompProps()
void SpiceLibCompDialog::slotBtnApply()
{
if (isChanged) {
if (libError) {
QMessageBox::critical(this,tr("Error"),
tr("There were library file parse error! Cannot apply changes."));
return;
}
if (setCompProps()) {
isChanged = false;
btnApply->setEnabled(false);
Expand All @@ -454,6 +485,12 @@ void SpiceLibCompDialog::slotBtnApply()
void SpiceLibCompDialog::slotBtnOK()
{
if (isChanged) {
if (libError) {
QMessageBox::critical(this,tr("Error"),
tr("There were library file parse error! Cannot apply changes."));
reject();
return;
}
if (setCompProps()) accept();
} else {
accept();
Expand Down
9 changes: 7 additions & 2 deletions qucs/extsimkernels/spicelibcompdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SpiceLibCompDialog : public QDialog {
private:
int symbolPinsCount;
bool isChanged;
bool libError;

QString lastSymbolDir;
QString lastLibDir;

Expand All @@ -30,15 +32,18 @@ class SpiceLibCompDialog : public QDialog {

QPushButton *btnOpenLib, *btnOK, *btnApply, *btnCancel, *btnOpenSym;
QTableWidget *tbwPinsTable;
QComboBox *cbxSelectSubcir, *cbxSymPattern;
QComboBox *cbxSelectSubcir;
QListWidget *listSymPattern;

QRadioButton *rbSymFromTemplate, *rbAutoSymbol, *rbUserSym;
QCheckBox *chbShowLib, *chbShowModel, *chbShowParams;

QMap<QString,QStringList> subcirPins;
QMap<QString,QString> subcirSPICE;

bool parseLibFile(const QString &filename);
enum SPICEparseError { noError=0, failedOpenFile = -1, noSUBCKT = -2 };

int parseLibFile(const QString &filename);
bool setCompProps();

private slots:
Expand Down
2 changes: 1 addition & 1 deletion qucs/spicecomponents/spicelibcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Component* SpiceLibComp::newOne()
// -------------------------------------------------------
Element* SpiceLibComp::info(QString& Name, char* &BitmapFile, bool getNewOne)
{
Name = QObject::tr("SpiceLibComp");
Name = QObject::tr("SPICE library device");
BitmapFile = (char *) "spicelibcomp";

if(getNewOne) {
Expand Down
7 changes: 7 additions & 0 deletions qucs/symbolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,10 @@ bool SymbolWidget::getBrush(const QString& s, QBrush& Brush, int i)

return true;
}

void SymbolWidget::setPaintText(const QString &txt)
{
PaintText = txt;
QFontMetrics metrics(QucsSettings.font, 0); // use the the screen-compatible metric
TextWidth = metrics.size(0,PaintText).width() + 4; // get size of text
}
2 changes: 2 additions & 0 deletions qucs/symbolwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class SymbolWidget : public QWidget {
void disableShowPinNumbers() { showPinNumbers = false; }
bool showPinNumbersEnabled() { return showPinNumbers; }
int getPortsNumber() { return portsNumber; }
void setPaintText(const QString &txt);
void setWarning(const QString &warn) { Warning = warn; }
// component properties
int Text_x, Text_y;
QString Prefix, LibraryPath, ComponentName;
Expand Down

0 comments on commit 6d2c931

Please sign in to comment.