25 #include <QTextStream>
27 #include <QDataStream>
29 #include <QTreeWidgetItem>
31 #include <QMessageBox>
32 #include <QPushButton>
33 #include <QScrollArea>
34 #include <QButtonGroup>
35 #include <QVBoxLayout>
36 #include <QHBoxLayout>
37 #include <QStackedWidget>
51 setWindowTitle(tr(
"Create Library"));
53 Expr.setPattern(
"[\\w_]+");
59 all =
new QVBoxLayout(
this);
69 QWidget *selectSubckt =
new QWidget();
72 QVBoxLayout *selectSubcktLayout =
new QVBoxLayout();
73 selectSubckt->setLayout(selectSubcktLayout);
76 QHBoxLayout *h1 =
new QHBoxLayout();
77 selectSubcktLayout->addLayout(h1);
78 theLabel =
new QLabel(tr(
"Library Name:"));
85 Group =
new QGroupBox(tr(
"Choose subcircuits:"));
86 selectSubcktLayout->addWidget(
Group);
88 QScrollArea *scrollArea =
new QScrollArea(
Group);
89 scrollArea->setWidgetResizable(
true);
91 QWidget *scrollWidget =
new QWidget();
93 QVBoxLayout *checkBoxLayout =
new QVBoxLayout();
94 scrollWidget->setLayout(checkBoxLayout);
95 scrollArea->setWidget(scrollWidget);
97 QVBoxLayout *areaLayout =
new QVBoxLayout();
98 areaLayout->addWidget(scrollArea);
99 Group->setLayout(areaLayout);
102 QHBoxLayout *hCheck =
new QHBoxLayout();
103 selectSubcktLayout->addLayout(hCheck);
104 checkDescr =
new QCheckBox(tr(
"Add subcircuit description"));
107 hCheck->addStretch();
111 QGridLayout *gridButts =
new QGridLayout();
112 selectSubcktLayout->addLayout(gridButts);
122 connect(
ButtCancel, SIGNAL(clicked()), SLOT(reject()));
131 QWidget *subcktDescr =
new QWidget();
134 QVBoxLayout *subcktDescrLayout =
new QVBoxLayout();
135 subcktDescr->setLayout(subcktDescrLayout);
137 QHBoxLayout *hbox =
new QHBoxLayout();
138 subcktDescrLayout->addLayout(hbox);
139 QLabel *libName =
new QLabel(tr(
"Enter description for:"));
140 hbox->addWidget(libName);
145 QGroupBox *descrBox =
new QGroupBox(tr(
"Description:"));
146 subcktDescrLayout->addWidget(descrBox);
149 textDescr->setWordWrapMode(QTextOption::NoWrap);
151 QVBoxLayout *vGroup =
new QVBoxLayout;
153 descrBox->setLayout(vGroup);
156 gridButts =
new QGridLayout();
157 subcktDescrLayout->addLayout(gridButts);
158 prevButt =
new QPushButton(tr(
"Previous"));
159 gridButts->addWidget(
prevButt, 0, 0);
162 nextButt =
new QPushButton(tr(
"Next >>"));
164 gridButts->addWidget(
nextButt, 0, 1);
169 connect(
ButtCancel, SIGNAL(clicked()), SLOT(reject()));
178 QWidget *msg =
new QWidget();
181 QVBoxLayout *msgLayout =
new QVBoxLayout();
182 msg->setLayout(msgLayout);
184 QHBoxLayout *hbox1 =
new QHBoxLayout();
185 msgLayout->addLayout(hbox1);
186 QLabel *finalLabel =
new QLabel(tr(
"Library Name:"));
187 hbox1->addWidget(finalLabel);
191 QGroupBox *msgBox =
new QGroupBox(tr(
"Message:"));
192 msgLayout->addWidget(msgBox);
194 ErrText->setTextFormat(Qt::PlainText);
195 ErrText->setWordWrapMode(QTextOption::NoWrap);
197 QVBoxLayout *vbox1 =
new QVBoxLayout();
199 msgBox->setLayout(vbox1);
201 QHBoxLayout *hbox2 =
new QHBoxLayout();
203 QPushButton *close =
new QPushButton(tr(
"Close"));
204 hbox2->addWidget(close);
205 connect(close, SIGNAL(clicked()), SLOT(reject()));
206 msgLayout->addLayout(hbox2);
211 for(
int i=0; i < SchematicList->childCount(); i++){
212 p = SchematicList->child(i);
215 if(!p->text(1).isEmpty()){
216 QCheckBox *subCheck =
new QCheckBox(p->text(0));
217 checkBoxLayout->addWidget(subCheck);
224 QLabel *noProj =
new QLabel(tr(
"No projects!"));
225 checkBoxLayout->addWidget(noProj);
240 QMessageBox::critical(
this, tr(
"Error"), tr(
"Please insert a library name!"));
246 QListIterator<QCheckBox *> i(
BoxList);
257 QMessageBox::critical(
this, tr(
"Error"), tr(
"Please choose at least one subcircuit!"));
262 if(!
LibDir.cd(
"user_lib")) {
263 if(!
LibDir.mkdir(
"user_lib")) {
264 QMessageBox::warning(
this, tr(
"Warning"),
265 tr(
"Cannot create user library directory !"));
273 QMessageBox::critical(
this, tr(
"Error"), tr(
"A system library with this name already exists!"));
279 QMessageBox::critical(
this, tr(
"Error"), tr(
"A library with this name already exists!"));
306 int i = tmp.find(
"TOP LEVEL MARK");
308 i = tmp.find(
'\n',i) + 1;
311 Stream <<
" <" << sec <<
">";
313 Stream <<
" </" << sec <<
">\n";
321 if(!ifile.open(QIODevice::ReadOnly)) {
322 ErrText->insert(QObject::tr(
"ERROR: Cannot open file \"%1\".\n").
327 QByteArray FileContent = ifile.readAll();
329 if(ifile.name().right(4) ==
".lst")
330 LibDir.remove(ifile.name());
332 if(!LibDirSub.cd(
NameEdit->text())) {
333 if(!LibDirSub.mkdir(
NameEdit->text())) {
335 QObject::tr(
"ERROR: Cannot create user library subdirectory !\n"));
341 ofn = Info.fileName();
344 ofile.setName(LibDirSub.absFilePath(ofn));
345 if(!ofile.open(QIODevice::WriteOnly)) {
347 QObject::tr(
"ERROR: Cannot create file \"%1\".\n").arg(ofn));
351 QDataStream ds(&ofile);
352 ds.writeRawBytes(FileContent.data(), FileContent.size());
362 if (state == Qt::Unchecked){
416 ErrText->insert(tr(
"Saving library..."));
418 if(!
LibFile.open(QIODevice::WriteOnly)) {
419 ErrText->append(tr(
"Error: Cannot create library!"));
424 Stream <<
"<Qucs Library " PACKAGE_VERSION
" \""
427 bool Success =
true, ret;
430 QTextStream ts(&tmp, QIODevice::WriteOnly);
433 ErrText->insert(
"\n=================\n");
435 QString description =
"";
439 Stream <<
"<Component " +
SelectedNames[i].section(
'.',0,0) +
">\n"
440 <<
" <Description>\n"
442 <<
"\n </Description>\n";
448 ErrText->append(tr(
"Error: Cannot load subcircuit \"%1\".").
460 ErrText->insert(tr(
"Creating Qucs netlist.\n"));
466 SubMap::Iterator it =
FileList.begin();
468 QString f = it.data().File;
470 if(it.data().Type ==
"SCH") {
474 else if(it.data().Type ==
"CIR") {
478 if (!ifn.isEmpty()) error +=
intoFile(ifn, ofn, IFiles);
482 if(!IFiles.isEmpty()) {
483 Stream <<
" <ModelIncludes \"" << IFiles.join(
"\" \"") <<
"\">\n";
485 Success = error > 0 ?
false :
true;
498 ErrText->insert(tr(
"Creating Verilog netlist.\n"));
504 SubMap::Iterator it =
FileList.begin();
506 QString f = it.data().File;
508 if(it.data().Type ==
"SCH") {
512 else if(it.data().Type ==
"VER") {
516 if (!ifn.isEmpty()) error +=
intoFile(ifn, ofn, IFiles);
520 if(!IFiles.isEmpty()) {
521 Stream <<
" <VerilogModelIncludes \""
522 << IFiles.join(
"\" \"") <<
"\">\n";
524 Success = error > 0 ?
false :
true;
535 ErrText->insert(tr(
"Creating VHDL netlist.\n"));
541 SubMap::Iterator it =
FileList.begin();
543 QString f = it.data().File;
545 if(it.data().Type ==
"SCH") {
549 else if(it.data().Type ==
"VHD") {
553 if (!ifn.isEmpty()) error +=
intoFile(ifn, ofn, IFiles);
557 if(!IFiles.isEmpty()) {
558 Stream <<
" <VHDLModelIncludes \""
559 << IFiles.join(
"\" \"") <<
"\">\n";
561 Success = error > 0 ?
false :
true;
567 Stream <<
" <Symbol>\n";
571 Stream <<
" <" << pp->
save() <<
">\n";
573 Stream <<
" </Symbol>\n"
574 <<
"</Component>\n\n";
585 ErrText->append(tr(
"Error creating library."));
589 ErrText->append(tr(
"Successfully created library."));
596 QListIterator<QCheckBox *> i(
BoxList);
607 QListIterator<QCheckBox *> i(
BoxList);
610 p->setChecked(
false);
QStringList SelectedNames
tQucsSettings QucsSettings
QPushButton * ButtSelectNone
QMap< QString, SubFile > SubMap
int intoFile(QString &, QString &, QStringList &)
bool createSubcircuitSymbol()
Definitions and declarations for the main application.
QStackedWidget * stackedWidgets
QPushButton * ButtSelectAll
QPushButton * ButtCreateNext
QRegExpValidator * Validator
void slotCheckDescrChanged(int)
bool createLibNetlist(QTextStream *, QTextEdit *, int)
Q3PtrList< Painting > SymbolPaints
LibraryDialog(QucsApp *, QTreeWidgetItem *)
QList< QCheckBox * > BoxList
void intoStream(QTextStream &, QString &, const char *)
void slotUpdateDescription()