Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
componentdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  componentdialog.cpp
3  -------------------
4  begin : Tue Sep 9 2003
5  copyright : (C) 2003, 2004 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include <QtGui>
18 #include "componentdialog.h"
19 #include "main.h"
20 #include "qucs.h"
21 //Added by qt3to4:
22 #include <Q3Button>
23 #include <QLabel>
24 #include <Q3GridLayout>
25 #include <Q3VBoxLayout>
26 #include "schematic.h"
27 
28 #include <Q3HBox>
29 #include <Q3VBox>
30 #include <QLayout>
31 #include <Q3HGroupBox>
32 #include <QValidator>
33 #include <QTabWidget>
34 #include <QFileDialog>
35 
36 #include <math.h>
37 
38 
40  : QDialog(d, 0, TRUE, Qt::WDestructiveClose)
41 {
42  resize(400, 250);
43  setCaption(tr("Edit Component Properties"));
44  Comp = c;
45  Doc = d;
46  QString s;
47 
48  all = new Q3VBoxLayout(this); // to provide neccessary size
49  Q3GridLayout *gp1;
50  QWidget *myParent = this;
51  ValInteger = new QIntValidator(1, 1000000, this);
52 
53  Expr.setPattern("[^\"=]*"); // valid expression for property 'edit'
54  Validator = new QRegExpValidator(Expr, this);
55  Expr.setPattern("[^\"]*"); // valid expression for property 'edit'
56  Validator2 = new QRegExpValidator(Expr, this);
57  Expr.setPattern("[\\w_]+"); // valid expression for property 'NameEdit'
58  ValRestrict = new QRegExpValidator(Expr, this);
59 
60  checkSim = 0; editSim = 0; comboType = 0; checkParam = 0;
61  editStart = 0; editStop = 0; editNumber = 0;
62 
63  Property *pp = 0; // last property not to put in ListView
64  // ...........................................................
65  // if simulation component
66  if((Comp->Model[0] == '.') &&
67  (Comp->Model != ".DC") && (Comp->Model != ".HB") &&
68  (Comp->Model != ".Digi") && (Comp->Model != ".ETR")) {
69  QTabWidget *t = new QTabWidget(this);
70  all->addWidget(t);
71 
72  QWidget *Tab1 = new QWidget(t);
73  t->addTab(Tab1, tr("Sweep"));
74  Q3GridLayout *gp = new Q3GridLayout(Tab1, 9,3,5,5);
75 
76  gp->addMultiCellWidget(new QLabel(Comp->Description, Tab1), 0,0,0,1);
77 
78  int row=1;
79  editParam = new QLineEdit(Tab1);
80  editParam->setValidator(ValRestrict);
81  connect(editParam, SIGNAL(returnPressed()), SLOT(slotParamEntered()));
82  checkParam = new QCheckBox(tr("display in schematic"), Tab1);
83  if(Comp->Model == ".SW") { // parameter sweep
84  textSim = new QLabel(tr("Simulation:"), Tab1);
85  gp->addWidget(textSim, row,0);
86  editSim = new QComboBox(Tab1);
87  editSim->setEditable(true);
88  connect(editSim, SIGNAL(activated(int)), SLOT(slotSimEntered(int)));
89  gp->addWidget(editSim, row,1);
90  checkSim = new QCheckBox(tr("display in schematic"), Tab1);
91  gp->addWidget(checkSim, row++,2);
92  }
93  else {
94  editParam->setReadOnly(true);
95  checkParam->setDisabled(true);
96  if(Comp->Model == ".TR") // transient simulation ?
97  editParam->setText("time");
98  else {
99  if(Comp->Model == ".AC") // AC simulation ?
100  editParam->setText("acfrequency");
101  else
102  editParam->setText("frequency");
103  }
104  }
105 
106  gp->addWidget(new QLabel(tr("Sweep Parameter:"), Tab1), row,0);
107  gp->addWidget(editParam, row,1);
108  gp->addWidget(checkParam, row++,2);
109 
110  textType = new QLabel(tr("Type:"), Tab1);
111  gp->addWidget(textType, row,0);
112  comboType = new QComboBox(Tab1);
113  comboType->insertItem(tr("linear"));
114  comboType->insertItem(tr("logarithmic"));
115  comboType->insertItem(tr("list"));
116  comboType->insertItem(tr("constant"));
117  gp->addWidget(comboType, row,1);
118  connect(comboType, SIGNAL(activated(int)), SLOT(slotSimTypeChange(int)));
119  checkType = new QCheckBox(tr("display in schematic"), Tab1);
120  gp->addWidget(checkType, row++,2);
121 
122  textValues = new QLabel(tr("Values:"), Tab1);
123  gp->addWidget(textValues, row,0);
124  editValues = new QLineEdit(Tab1);
125  editValues->setValidator(Validator);
126  connect(editValues, SIGNAL(returnPressed()), SLOT(slotValuesEntered()));
127  gp->addWidget(editValues, row,1);
128  checkValues = new QCheckBox(tr("display in schematic"), Tab1);
129  gp->addWidget(checkValues, row++,2);
130 
131  textStart = new QLabel(tr("Start:"), Tab1);
132  gp->addWidget(textStart, row,0);
133  editStart = new QLineEdit(Tab1);
134  editStart->setValidator(Validator);
135  connect(editStart, SIGNAL(returnPressed()), SLOT(slotStartEntered()));
136  gp->addWidget(editStart, row,1);
137  checkStart = new QCheckBox(tr("display in schematic"), Tab1);
138  gp->addWidget(checkStart, row++,2);
139 
140  textStop = new QLabel(tr("Stop:"), Tab1);
141  gp->addWidget(textStop, row,0);
142  editStop = new QLineEdit(Tab1);
143  editStop->setValidator(Validator);
144  connect(editStop, SIGNAL(returnPressed()), SLOT(slotStopEntered()));
145  gp->addWidget(editStop, row,1);
146  checkStop = new QCheckBox(tr("display in schematic"), Tab1);
147  gp->addWidget(checkStop, row++,2);
148 
149  textStep = new QLabel(tr("Step:"), Tab1);
150  gp->addWidget(textStep, row,0);
151  editStep = new QLineEdit(Tab1);
152  editStep->setValidator(Validator);
153  connect(editStep, SIGNAL(returnPressed()), SLOT(slotStepEntered()));
154  gp->addWidget(editStep, row++,1);
155 
156  textNumber = new QLabel(tr("Number:"), Tab1);
157  gp->addWidget(textNumber, row,0);
158  editNumber = new QLineEdit(Tab1);
159  editNumber->setValidator(ValInteger);
160  connect(editNumber, SIGNAL(returnPressed()), SLOT(slotNumberEntered()));
161  gp->addWidget(editNumber, row,1);
162  checkNumber = new QCheckBox(tr("display in schematic"), Tab1);
163  gp->addWidget(checkNumber, row++,2);
164 
165 
166  if(Comp->Model == ".SW") { // parameter sweep
167  Component *pc;
168  for(pc=Doc->Components->first(); pc!=0; pc=Doc->Components->next())
169  if(pc != Comp)
170  if(pc->Model[0] == '.')
171  editSim->insertItem(pc->Name);
172  editSim->setCurrentText(Comp->Props.first()->Value);
173 
174  checkSim->setChecked(Comp->Props.current()->display);
175  s = Comp->Props.next()->Value;
176  checkType->setChecked(Comp->Props.current()->display);
177  editParam->setText(Comp->Props.next()->Value);
178  checkParam->setChecked(Comp->Props.current()->display);
179  }
180  else {
181  s = Comp->Props.first()->Value;
182  checkType->setChecked(Comp->Props.current()->display);
183  }
184  pp = Comp->Props.next();
185  editStart->setText(pp->Value);
186  checkStart->setChecked(pp->display);
187  pp = Comp->Props.next();
188  editStop->setText(pp->Value);
189  checkStop->setChecked(pp->display);
190  pp = Comp->Props.next(); // remember last property for ListView
191  editNumber->setText(pp->Value);
192  checkNumber->setChecked(pp->display);
193 
194  int tNum = 0;
195  if(s[0] == 'l') {
196  if(s[1] == 'i') {
197  if(s[2] != 'n')
198  tNum = 2;
199  }
200  else tNum = 1;
201  }
202  else tNum = 3;
203  comboType->setCurrentItem(tNum);
204 
205  slotSimTypeChange(tNum); // not automatically ?!?
206  if(tNum > 1) {
207  editValues->setText(
208  editNumber->text().mid(1, editNumber->text().length()-2));
209  checkValues->setChecked(Comp->Props.current()->display);
210  editNumber->setText("2");
211  }
213 
214 /* connect(editValues, SIGNAL(textChanged(const QString&)),
215  SLOT(slotTextChanged(const QString&)));*/
216  connect(editStart, SIGNAL(textChanged(const QString&)),
217  SLOT(slotNumberChanged(const QString&)));
218  connect(editStop, SIGNAL(textChanged(const QString&)),
219  SLOT(slotNumberChanged(const QString&)));
220  connect(editStep, SIGNAL(textChanged(const QString&)),
221  SLOT(slotStepChanged(const QString&)));
222  connect(editNumber, SIGNAL(textChanged(const QString&)),
223  SLOT(slotNumberChanged(const QString&)));
224 
225 /* if(checkSim)
226  connect(checkSim, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int)));
227  connect(checkType, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int)));
228  connect(checkParam, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int)));
229  connect(checkStart, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int)));
230  connect(checkStop, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int)));
231  connect(checkNumber, SIGNAL(stateChanged(int)), SLOT(slotSetChanged(int)));*/
232 
233 
234  QWidget *Tab2 = new QWidget(t);
235  t->addTab(Tab2, tr("Properties"));
236  gp1 = new Q3GridLayout(Tab2, 9,2,5,5);
237  myParent = Tab2;
238  }
239  else { // no simulation component
240  gp1 = new Q3GridLayout(0, 9,2,5,5);
241  all->addLayout(gp1);
242  }
243 
244 
245  // ...........................................................
246  gp1->addMultiCellWidget(new QLabel(Comp->Description, myParent), 0,0,0,1);
247 
248  Q3HBox *h5 = new Q3HBox(myParent);
249  h5->setSpacing(5);
250  gp1->addWidget(h5, 1,0);
251  new QLabel(tr("Name:"), h5);
252  CompNameEdit = new QLineEdit(h5);
253  CompNameEdit->setValidator(ValRestrict);
254  connect(CompNameEdit, SIGNAL(returnPressed()), SLOT(slotButtOK()));
255 
256  showName = new QCheckBox(tr("display in schematic"), myParent);
257  gp1->addWidget(showName, 1,1);
258 
259  Q3HGroupBox *PropertyBox = new Q3HGroupBox(tr("Properties"), myParent);
260  gp1->addMultiCellWidget(PropertyBox, 2,2,0,1);
261 
262  prop = new Q3ListView(PropertyBox);
263  prop->setMinimumSize(200, 150);
264  prop->addColumn(tr("Name"));
265  prop->addColumn(tr("Value"));
266  prop->addColumn(tr("display"));
267  prop->addColumn(tr("Description"));
268  prop->setSorting(-1); // no sorting
269 
270  Q3VBox *v1 = new Q3VBox(PropertyBox);
271  v1->setSpacing(3);
272 
273  Name = new QLabel(v1);
274 
275  Description = new QLabel(v1);
276 
277  // hide, because it only replaces 'Description' in some cases
278  NameEdit = new QLineEdit(v1);
279  NameEdit->setShown(false);
280  NameEdit->setValidator(ValRestrict);
281  connect(NameEdit, SIGNAL(returnPressed()), SLOT(slotApplyPropName()));
282 
283  edit = new QLineEdit(v1);
284  edit->setMinimumWidth(150);
285  edit->setValidator(Validator2);
286  connect(edit, SIGNAL(returnPressed()), SLOT(slotApplyProperty()));
287 
288  // hide, because it only replaces 'edit' in some cases
289  ComboEdit = new QComboBox(false, v1);
290  ComboEdit->setShown(false);
291  connect(ComboEdit, SIGNAL(activated(const QString&)),
292  SLOT(slotApplyChange(const QString&)));
293 
294  Q3HBox *h3 = new Q3HBox(v1);
295  h3->setStretchFactor(new QWidget(h3),5); // stretchable placeholder
296  EditButt = new QPushButton(tr("Edit"),h3);
297  EditButt->setEnabled(false);
298  EditButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
299  connect(EditButt, SIGNAL(clicked()), SLOT(slotEditFile()));
300  BrowseButt = new QPushButton(tr("Browse"),h3);
301  BrowseButt->setEnabled(false);
302  BrowseButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
303  connect(BrowseButt, SIGNAL(clicked()), SLOT(slotBrowseFile()));
304 
305  disp = new QCheckBox(tr("display in schematic"), v1);
306  connect(disp, SIGNAL(stateChanged(int)), SLOT(slotApplyState(int)));
307 
308  v1->setStretchFactor(new QWidget(v1),5); // stretchable placeholder
309 
310  Q3HBox *h4 = new Q3HBox(v1);
311  h4->setSpacing(5);
312  ButtAdd = new QPushButton(tr("Add"),h4);
313  ButtAdd->setEnabled(false);
314  ButtRem = new QPushButton(tr("Remove"),h4);
315  ButtRem->setEnabled(false);
316  connect(ButtAdd, SIGNAL(clicked()), SLOT(slotButtAdd()));
317  connect(ButtRem, SIGNAL(clicked()), SLOT(slotButtRem()));
318 
319  // ...........................................................
320  Q3HBox *h2 = new Q3HBox(this);
321  h2->setSpacing(5);
322  all->addWidget(h2);
323  connect(new QPushButton(tr("OK"),h2), SIGNAL(clicked()),
324  SLOT(slotButtOK()));
325  connect(new QPushButton(tr("Apply"),h2), SIGNAL(clicked()),
326  SLOT(slotApplyInput()));
327  connect(new QPushButton(tr("Cancel"),h2), SIGNAL(clicked()),
328  SLOT(slotButtCancel()));
329 
330  // ------------------------------------------------------------
331  CompNameEdit->setText(Comp->Name);
332  showName->setChecked(Comp->showName);
333  changed = false;
334 
336  int tmp = Comp->tx+tx_Dist - Comp->x1;
337  if((tmp > 0) || (tmp < -6)) tx_Dist = 0; // remember the text position
338  tmp = Comp->ty+ty_Dist - Comp->y1;
339  if((tmp > 0) || (tmp < -6)) ty_Dist = 0;
340 
341  // insert all properties into the ListBox
342  for(Property *p = Comp->Props.last(); p != 0; p = Comp->Props.prev()) {
343  if(p == pp) break; // do not insert if already on first tab
344  if(p->display) s = tr("yes");
345  else s = tr("no");
346  new Q3ListViewItem(prop, p->Name, p->Value, s, p->Description);
347  }
348 
349  if(prop->childCount() > 0) {
350  prop->setCurrentItem(prop->firstChild());
351  slotSelectProperty(prop->firstChild());
352  }
353 
354  connect(prop, SIGNAL(clicked(Q3ListViewItem*)),
355  SLOT(slotSelectProperty(Q3ListViewItem*)));
356 }
357 
359 {
360  delete all;
361  delete Validator;
362  delete Validator2;
363  delete ValRestrict;
364  delete ValInteger;
365 }
366 
367 // -------------------------------------------------------------------------
368 // Is called if a property is selected. It transfers the values to the right
369 // side for editing.
370 void ComponentDialog::slotSelectProperty(Q3ListViewItem *item)
371 {
372  if(item == 0) return;
373  item->setSelected(true); // if called from elsewhere, this was not yet done
374 
375  if(item->text(2) == tr("yes")) disp->setChecked(true);
376  else disp->setChecked(false);
377 
378  if(item->text(0) == "File") {
379  EditButt->setEnabled(true);
380  BrowseButt->setEnabled(true);
381  }
382  else {
383  EditButt->setEnabled(false);
384  BrowseButt->setEnabled(false);
385  }
386 
387  QString PropDesc = item->text(3);
388  if(PropDesc.isEmpty()) {
389  // show two line edit fields (name and value)
390  ButtAdd->setEnabled(true);
391  ButtRem->setEnabled(true);
392 
393  Name->setText("");
394  NameEdit->setText(item->text(0));
395  edit->setText(item->text(1));
396 
397  edit->setShown(true);
398  NameEdit->setShown(true);
399  Description->setShown(false);
400  ComboEdit->setShown(false);
401 
402  NameEdit->setFocus(); // edit QLineEdit
403  }
404  else { // show standard line edit (description and value)
405  ButtAdd->setEnabled(false);
406  ButtRem->setEnabled(false);
407 
408  Name->setText(item->text(0));
409  edit->setText(item->text(1));
410 
411  NameEdit->setShown(false);
412  NameEdit->setText(item->text(0)); // perhaps used for adding properties
413  Description->setShown(true);
414 
415  // handle special combobox items
416  QStringList List;
417  int b = PropDesc.find('[');
418  int e = PropDesc.findRev(']');
419  if (e-b > 2) {
420  QString str = PropDesc.mid(b+1, e-b-1);
421  str.replace( QRegExp("[^a-zA-Z0-9_,]"), "" );
422  List = List.split(',',str);
423  }
424 
425  QFontMetrics metrics(QucsSettings.font); // get size of text
426  while(metrics.width(PropDesc) > 270) { // if description too long, cut it
427  if (PropDesc.findRev(' ') != -1)
428  PropDesc = PropDesc.left(PropDesc.findRev(' ', -1)) + "....";
429  else
430  PropDesc = PropDesc.left(PropDesc.length()-5) + "....";
431  }
432  Description->setText(PropDesc);
433 
434  if(List.count() >= 1) { // ComboBox with value list or line edit ?
435  ComboEdit->clear();
436  ComboEdit->insertStringList(List);
437 
438  for(int i=ComboEdit->count()-1; i>=0; i--)
439  if(item->text(1) == ComboEdit->text(i)) {
440  ComboEdit->setCurrentItem(i);
441  break;
442  }
443  edit->setShown(false);
444  ComboEdit->setShown(true);
445  }
446  else {
447  edit->setShown(true);
448  ComboEdit->setShown(false);
449  }
450  edit->setFocus(); // edit QLineEdit
451 // edit->deselect(); // doesn't work ?!?
452  }
453 }
454 
455 // -------------------------------------------------------------------------
457 {
458  edit->setText(Text);
459  prop->currentItem()->setText(1, Text); // apply edit line
460 
461  ComboEdit->setFocus();
462  Q3ListViewItem *item = prop->currentItem()->itemBelow();
463  if(item == 0) return;
464 
465  prop->setSelected(item, true);
466  slotSelectProperty(item); // switch to the next property
467 }
468 
469 // -------------------------------------------------------------------------
470 // Is called if the "RETURN"-button is pressed in the "edit" Widget.
472 {
473  Q3ListViewItem *item = prop->currentItem();
474  if(!item) return;
475 
476  if(ComboEdit->isShown()) // take text from ComboBox ?
477  edit->setText(ComboEdit->currentText());
478 
479  if(item->text(1) != edit->text())
480  item->setText(1, edit->text()); // apply edit line
481 
482  if(NameEdit->isShown()) // also apply property name ?
483  if(item->text(0) != NameEdit->text()) {
484 // if(NameEdit->text() == "Export")
485 // item->setText(0, "Export_"); // name must not be "Export" !!!
486 // else
487  item->setText(0, NameEdit->text()); // apply property name
488  }
489 
490  item = item->itemBelow();
491  if(!item) {
492  slotButtOK(); // close dialog, if it was the last property
493  return;
494  }
495 
496  prop->setSelected(item, true);
497  prop->ensureItemVisible(item);
498  slotSelectProperty(item); // switch to the next property
499 }
500 
501 // -------------------------------------------------------------------------
502 // Is called if the "RETURN"-button is pressed in the "NameEdit" Widget.
504 {
505  Q3ListViewItem *item = prop->currentItem();
506  if(item->text(0) != NameEdit->text()) {
507 // if(NameEdit->text() == "Export") {
508 // item->setText(0, "Export_"); // name must not be "Export" !!!
509 // NameEdit->setText("Export_");
510 // }
511 // else
512  item->setText(0, NameEdit->text()); // apply property name
513  }
514  edit->setFocus(); // cursor into "edit" widget
515 }
516 
517 // -------------------------------------------------------------------------
518 // Is called if the checkbox is pressed (changed).
520 {
521  Q3ListViewItem *item = prop->currentItem();
522  if(item == 0) return;
523 
524  QString ButtonState;
525  if(State) ButtonState = tr("yes");
526  else ButtonState = tr("no");
527 
528  if(item->text(2) != ButtonState) {
529  item->setText(2, ButtonState);
530  }
531 }
532 
533 // -------------------------------------------------------------------------
534 // Is called if the "OK"-button is pressed.
536 {
537  slotApplyInput();
538  slotButtCancel();
539 }
540 
541 // -------------------------------------------------------------------------
542 // Is called if the "Cancel"-button is pressed.
544 {
545  if(changed) done(1); // changed could have been done before
546  else done(0); // (by "Apply"-button)
547 }
548 
549 //-----------------------------------------------------------------
550 // To get really all close events (even <Escape> key).
552 {
553  slotButtCancel();
554 }
555 
556 // -------------------------------------------------------------------------
557 // Is called, if the "Apply"-button is pressed.
559 {
560  if(Comp->showName != showName->isChecked()) {
561  Comp->showName = showName->isChecked();
562  changed = true;
563  }
564 
565  QString tmp;
566  Component *pc;
567  if(CompNameEdit->text().isEmpty()) CompNameEdit->setText(Comp->Name);
568  else
569  if(CompNameEdit->text() != Comp->Name) {
570  for(pc = Doc->Components->first(); pc!=0; pc = Doc->Components->next())
571  if(pc->Name == CompNameEdit->text())
572  break; // found component with the same name ?
573  if(pc) CompNameEdit->setText(Comp->Name);
574  else {
575  Comp->Name = CompNameEdit->text();
576  changed = true;
577  }
578  }
579 
580  bool display;
581  Property *pp = Comp->Props.first();
582  // apply all the new property values
583  if(editSim) {
584  display = checkSim->isChecked();
585  if(pp->display != display) {
586  pp->display = display;
587  changed = true;
588  }
589  if(pp->Value != editSim->currentText()) {
590  pp->Value = editSim->currentText();
591  changed = true;
592  }
593  pp = Comp->Props.next();
594  }
595  if(comboType) {
596  display = checkType->isChecked();
597  if(pp->display != display) {
598  pp->display = display;
599  changed = true;
600  }
601  switch(comboType->currentItem()) {
602  case 1: tmp = "log"; break;
603  case 2: tmp = "list"; break;
604  case 3: tmp = "const"; break;
605  default: tmp = "lin"; break;
606  }
607  if(pp->Value != tmp) {
608  pp->Value = tmp;
609  changed = true;
610  }
611  pp = Comp->Props.next();
612  }
613  if(checkParam) if(checkParam->isEnabled()) {
614  display = checkParam->isChecked();
615  if(pp->display != display) {
616  pp->display = display;
617  changed = true;
618  }
619  if(pp->Value != editParam->text()) {
620  pp->Value = editParam->text();
621  changed = true;
622  }
623  pp = Comp->Props.next();
624  }
625  if(editStart) {
626  if(comboType->currentItem() < 2) {
627  display = checkStart->isChecked();
628  if(pp->display != display) {
629  pp->display = display;
630  changed = true;
631  }
632  pp->Name = "Start";
633  if(pp->Value != editStart->text()) {
634  pp->Value = editStart->text();
635  changed = true;
636  }
637  pp = Comp->Props.next();
638 
639  display = checkStop->isChecked();
640  if(pp->display != display) {
641  pp->display = display;
642  changed = true;
643  }
644  pp->Name = "Stop";
645  if(pp->Value != editStop->text()) {
646  pp->Value = editStop->text();
647  changed = true;
648  }
649  pp = Comp->Props.next();
650 
651  display = checkNumber->isChecked();
652  if(pp->display != display) {
653  pp->display = display;
654  changed = true;
655  }
656  if((pp->Value != editNumber->text()) || (pp->Name != "Points")) {
657  pp->Value = editNumber->text();
658  pp->Name = "Points";
659  changed = true;
660  }
661  pp = Comp->Props.next();
662  }
663  else {
664  // If a value list is used, the properties "Start" and "Stop" are not
665  // used. -> Call them "Symbol" to omit them in the netlist.
666  pp->Name = "Symbol";
667  pp->display = false;
668  pp = Comp->Props.next();
669  pp->Name = "Symbol";
670  pp->display = false;
671  pp = Comp->Props.next();
672 
673  display = checkValues->isChecked();
674  if(pp->display != display) {
675  pp->display = display;
676  changed = true;
677  }
678  tmp = "["+editValues->text()+"]";
679  if((pp->Value != tmp) || (pp->Name != "Values")) {
680  pp->Value = tmp;
681  pp->Name = "Values";
682  changed = true;
683  }
684  pp = Comp->Props.next();
685  }
686  }
687 
688 
689  Q3ListViewItem *item = prop->firstChild();
690  if(item != 0) {
691 
692  item = prop->currentItem();
693  if(item->text(1) != edit->text())
694  item->setText(1, edit->text()); // apply edit line
695  if(NameEdit->isShown()) // also apply property name ?
696  if(item->text(0) != NameEdit->text())
697  item->setText(0, NameEdit->text()); // apply property name
698 
699 
700  // apply all the new property values in the ListView
701  for(item = prop->firstChild(); item != 0; item = item->itemBelow()) {
702  display = (item->text(2) == tr("yes"));
703  if(pp) {
704  if(pp->display != display) {
705  pp->display = display;
706  changed = true;
707  }
708  if(pp->Value != item->text(1)) {
709  pp->Value = item->text(1);
710  changed = true;
711  }
712  if(pp->Name != item->text(0)) {
713  pp->Name = item->text(0); // override if previous one was removed
714  changed = true;
715  }
716  pp->Description = item->text(3);
717  }
718  else { // if less properties than in ListView -> create new
719  Comp->Props.append(new
720  Property(item->text(0), item->text(1), display, item->text(3)));
721  changed = true;
722  }
723  pp = Comp->Props.next();
724  }
725  if(pp) { // if more properties than in ListView -> delete the rest
726  pp = Comp->Props.prev();
727  Comp->Props.last();
728  while(pp != Comp->Props.current())
729  Comp->Props.remove();
730  changed = true;
731  }
732  }
733 
734  if(changed) {
735  int dx, dy;
736  Comp->textSize(dx, dy);
737  if(tx_Dist != 0) {
738  Comp->tx += tx_Dist-dx;
739  tx_Dist = dx;
740  }
741  if(ty_Dist != 0) {
742  Comp->ty += ty_Dist-dy;
743  ty_Dist = dy;
744  }
745 
747  Doc->viewport()->repaint();
748  }
749 }
750 
751 // -------------------------------------------------------------------------
753 {
754  QString s = QFileDialog::getOpenFileName (
755  this,
756  tr("Select a file"),
757  QucsSettings.QucsWorkDir.path(),
758  tr("All Files")+" (*.*);;"
759  + tr("Touchstone files") + " (*.s?p);;"
760  + tr("CSV files") + " (*.csv);;"
761  + tr("SPICE files") + " (*.cir *.spi);;"
762  + tr("VHDL files") + " (*.vhdl *.vhd);;"
763  + tr("Verilog files")+" (*.v)" );
764 
765  if(!s.isEmpty()) {
766  // snip path if file in current directory
767  QFileInfo file(s);
768  if(QucsSettings.QucsWorkDir.exists(file.fileName()) &&
769  QucsSettings.QucsWorkDir.absPath() == file.dirPath(true)) s = file.fileName();
770  edit->setText(s);
771  }
772  prop->currentItem()->setText(1, s);
773 }
774 
775 // -------------------------------------------------------------------------
777 {
778  Doc->App->editFile(QucsSettings.QucsWorkDir.filePath(edit->text()));
779 }
780 
781 // -------------------------------------------------------------------------
782 // Is called if the add button is pressed. This is only possible for some
783 // properties.
785 {
786  Q3ListViewItem *item;
787  // Search if property with this name already exist.
788  for(item = prop->firstChild(); item != 0; item = item->itemBelow())
789  if(item->text(0) == NameEdit->text()) {
790  prop->setSelected(item, true);
791  slotSelectProperty(item);
792  return;
793  }
794 
795  item = prop->selectedItem();
796  if(item == 0) item = prop->lastItem();
797 
798  QString s = tr("no");
799  if(disp->isChecked()) s = tr("yes");
800 
801  prop->setSelected(new Q3ListViewItem(prop, item,
802  NameEdit->text(), edit->text(), s), true);
803 }
804 
805 // -------------------------------------------------------------------------
806 // Is called if the remove button is pressed. This is only possible for
807 // some properties.
809 {
810  if(prop->childCount() < 3) return; // the last property cannot be removed
811  Q3ListViewItem *item = prop->selectedItem();
812  if(item == 0) return;
813 
814  Q3ListViewItem *next_item = item->itemBelow();
815  if(next_item == 0) next_item = item->itemAbove();
816  prop->takeItem(item); // remove from ListView
817  delete item; // delete item
818 
819  slotSelectProperty(next_item);
820 }
821 
822 // -------------------------------------------------------------------------
824 {
825  if(Type < 2) { // new type is "linear" or "logarithmic"
826  if(!editNumber->isEnabled()) { // was the other mode before ?
827  // this text change, did not emit the textChange signal !??!
828  editStart->setText(
829  editValues->text().section(';', 0, 0).stripWhiteSpace());
830  editStop->setText(
831  editValues->text().section(';', -1, -1).stripWhiteSpace());
832  editNumber->setText("2");
834 
835  checkStart->setChecked(true);
836  checkStop->setChecked(true);
837  }
838  textValues->setDisabled(true);
839  editValues->setDisabled(true);
840  checkValues->setDisabled(true);
841  textStart->setDisabled(false);
842  editStart->setDisabled(false);
843  checkStart->setDisabled(false);
844  textStop->setDisabled(false);
845  editStop->setDisabled(false);
846  checkStop->setDisabled(false);
847  textStep->setDisabled(false);
848  editStep->setDisabled(false);
849  textNumber->setDisabled(false);
850  editNumber->setDisabled(false);
851  checkNumber->setDisabled(false);
852  if(Type == 1) // logarithmic ?
853  textStep->setText(tr("Points per decade:"));
854  else
855  textStep->setText(tr("Step:"));
856  }
857  else { // new type is "list" or "constant"
858  if(!editValues->isEnabled()) { // was the other mode before ?
859  editValues->setText(editStart->text() + "; " + editStop->text());
860  checkValues->setChecked(true);
861  }
862 
863  textValues->setDisabled(false);
864  editValues->setDisabled(false);
865  checkValues->setDisabled(false);
866  textStart->setDisabled(true);
867  editStart->setDisabled(true);
868  checkStart->setDisabled(true);
869  textStop->setDisabled(true);
870  editStop->setDisabled(true);
871  checkStop->setDisabled(true);
872  textStep->setDisabled(true);
873  editStep->setDisabled(true);
874  textNumber->setDisabled(true);
875  editNumber->setDisabled(true);
876  checkNumber->setDisabled(true);
877  textStep->setText(tr("Step:"));
878  }
879 }
880 
881 // -------------------------------------------------------------------------
882 // Is called when "Start", "Stop" or "Number" is edited.
884 {
885  QString Unit, tmp;
886  double x, y, Factor;
887  if(comboType->currentItem() == 1) { // logarithmic ?
888  str2num(editStop->text(), x, Unit, Factor);
889  x *= Factor;
890  str2num(editStart->text(), y, Unit, Factor);
891  y *= Factor;
892  if(y == 0.0) y = x / 10.0;
893  if(x == 0.0) x = y * 10.0;
894  if(y == 0.0) { y = 1.0; x = 10.0; }
895  x = editNumber->text().toDouble() / log10(fabs(x / y));
896  Unit = QString::number(x);
897  }
898  else {
899  str2num(editStop->text(), x, Unit, Factor);
900  x *= Factor;
901  str2num(editStart->text(), y, Unit, Factor);
902  y *= Factor;
903  x = (x - y) / (editNumber->text().toDouble() - 1.0);
904 
905  QString step = num2str(x);
906 
907  str2num(step, x, Unit, Factor);
908  if(Factor == 1.0)
909  Unit = "";
910 
911  Unit = QString::number(x) + " " + Unit;
912  }
913 
914  editStep->blockSignals(true); // do not calculate step again
915  editStep->setText(Unit);
916  editStep->blockSignals(false);
917 }
918 
919 // -------------------------------------------------------------------------
920 void ComponentDialog::slotStepChanged(const QString& Step)
921 {
922  QString Unit;
923  double x, y, Factor;
924  if(comboType->currentItem() == 1) { // logarithmic ?
925  str2num(editStop->text(), x, Unit, Factor);
926  x *= Factor;
927  str2num(editStart->text(), y, Unit, Factor);
928  y *= Factor;
929 
930  x /= y;
931  str2num(Step, y, Unit, Factor);
932  y *= Factor;
933 
934  x = log10(fabs(x)) * y;
935  }
936  else {
937  str2num(editStop->text(), x, Unit, Factor);
938  x *= Factor;
939  str2num(editStart->text(), y, Unit, Factor);
940  y *= Factor;
941 
942  x -= y;
943  str2num(Step, y, Unit, Factor);
944  y *= Factor;
945 
946  x /= y;
947  }
948 
949  editNumber->blockSignals(true); // do not calculate number again
950  editNumber->setText(QString::number(floor(x + 1.0)));
951  editNumber->blockSignals(false);
952 }
953 
954 // -------------------------------------------------------------------------
955 // Is called if return is pressed in LineEdit "Parameter".
957 {
958  if(editValues->isEnabled())
959  editValues->setFocus();
960  else
961  editStart->setFocus();
962 }
963 
964 // -------------------------------------------------------------------------
965 // Is called if return is pressed in LineEdit "Simulation".
967 {
968  editParam->setFocus();
969 }
970 
971 // -------------------------------------------------------------------------
972 // Is called if return is pressed in LineEdit "Values".
974 {
975  slotButtOK();
976 }
977 
978 // -------------------------------------------------------------------------
979 // Is called if return is pressed in LineEdit "Start".
981 {
982  editStop->setFocus();
983 }
984 
985 // -------------------------------------------------------------------------
986 // Is called if return is pressed in LineEdit "Stop".
988 {
989  editStep->setFocus();
990 }
991 
992 // -------------------------------------------------------------------------
993 // Is called if return is pressed in LineEdit "Step".
995 {
996  editNumber->setFocus();
997 }
998 
999 // -------------------------------------------------------------------------
1000 // Is called if return is pressed in LineEdit "Number".
1002 {
1003  slotButtOK();
1004 }
QCheckBox * disp
Q3ListView * prop
QLineEdit * editValues
void slotSimTypeChange(int)
QLineEdit * editStart
QDir QucsWorkDir
Definition: main.h:65
QComboBox * editSim
void str2num(const QString &s_, double &Number, QString &Unit, double &Factor)
Definition: main.cpp:328
QCheckBox * checkStop
QLineEdit * NameEdit
int y1
Definition: element.h:153
void slotNumberChanged(const QString &)
QCheckBox * checkSim
QFont font
Definition: main.h:46
tQucsSettings QucsSettings
Definition: main.cpp:52
QPushButton * ButtAdd
int tx
Definition: component.h:78
QValidator * ValRestrict
int x1
Definition: element.h:153
QLineEdit * editParam
QCheckBox * checkNumber
int textSize(int &, int &)
Definition: component.cpp:86
Schematic * Doc
QCheckBox * checkStart
QValidator * Validator2
void slotStepChanged(const QString &)
bool display
Definition: element.h:99
Definitions and declarations for the main application.
int ty
Definition: component.h:78
QString Value
Definition: element.h:97
ComponentDialog(Component *, Schematic *)
QLineEdit * editStep
QComboBox * ComboEdit
Component * Comp
QLabel * Description
Q3PtrList< Component > * Components
Definition: schematic.h:123
QIntValidator * ValInteger
Q3PtrList< Property > Props
Definition: component.h:72
QCheckBox * checkType
QString num2str(double Num)
Definition: main.cpp:384
QLineEdit * editNumber
QucsApp * App
Definition: qucsdoc.h:59
Definition: element.h:82
void slotApplyChange(const QString &Text)
bool showName
Definition: component.h:79
QPushButton * EditButt
QValidator * Validator
QString Name
Definition: element.h:97
QString Name
Definition: component.h:80
QPushButton * ButtRem
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
QCheckBox * showName
QComboBox * comboType
void editFile(const QString &)
QLineEdit * edit
Q3VBoxLayout * all
QCheckBox * checkParam
void slotSelectProperty(Q3ListViewItem *item)
QString Description
Definition: element.h:100
void recreateComponent(Component *)
void slotSimEntered(int)
QLineEdit * editStop
QLineEdit * CompNameEdit
QPushButton * BrowseButt
QCheckBox * checkValues
void slotApplyState(int State)