My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qucsattenuator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Qucs Attenuator Synthesis
3 ** qucsattenuator.cpp
4 **
5 **
6 **
7 **
8 **
9 **
10 **
11 *****************************************************************************/
12 
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16 
17 #include "attenuatorfunc.h"
18 #include "qucsattenuator.h"
19 #include "helpdialog.h"
20 
21 #include <qvgroupbox.h>
22 #include <qvbox.h>
23 #include <qmenubar.h>
24 #include <qpopupmenu.h>
25 #include <qmessagebox.h>
26 #include <qlayout.h>
27 #include <qlabel.h>
28 #include <qpushbutton.h>
29 #include <qlineedit.h>
30 #include <qcombobox.h>
31 #include <qvalidator.h>
32 #include <qtimer.h>
33 #include <qclipboard.h>
34 #include <qapplication.h>
35 #include <qimage.h>
36 
38 {
39  setIcon(QPixmap(QucsSettings.BitmapDir + "big.qucs.xpm"));
40  setCaption("Qucs Attenuator " PACKAGE_VERSION);
41 
42  QPopupMenu *fileMenu = new QPopupMenu();
43  fileMenu->insertItem(tr("E&xit"), this, SLOT(slotQuit()), CTRL+Key_Q);
44 
45  QPopupMenu *helpMenu = new QPopupMenu();
46  helpMenu->insertItem(tr("Help..."), this, SLOT(slotHelpIntro()), Key_F1);
47  helpMenu->insertSeparator();
48  helpMenu->insertItem(
49  tr("&About QucsAttenuator..."), this, SLOT(slotHelpAbout()), 0);
50  helpMenu->insertItem(tr("About Qt..."), this, SLOT(slotHelpAboutQt()), 0);
51 
52  QMenuBar *bar = new QMenuBar(this);
53  bar->insertItem(tr("&File"), fileMenu);
54  bar->insertSeparator ();
55  bar->insertItem(tr("&Help"), helpMenu);
56 
57  QVBoxLayout * v2 = new QVBoxLayout (this);
58  QVBox * vm = new QVBox (this);
59  vm->setSpacing(0);
60  v2->setSpacing(2);
61 
62  QWidget *Space = new QWidget(this); // reserve space for menubar
63  Space->setFixedSize(5, bar->height());
64  v2->addWidget(Space);
65 
66  QHBox * h1 = new QHBox (this);
67  v2->addWidget(h1);
68  h1->setSpacing(2);
69  h1->setMargin(5);
70  QVBox * v1 = new QVBox (h1);
71  v1->setSpacing(2);
72 
73  QGroupBox * TopoGroup = new QGroupBox (tr("Topology"), v1);
74  QGridLayout * tbox = new QGridLayout(TopoGroup, 3,1,5,5);
75 
76  QWidget *Space2 = new QWidget(TopoGroup);
77  Space2->setFixedSize(8, 8);
78  tbox->addMultiCellWidget(Space2,0,0,0,0);
79 
80  ComboTopology = new QComboBox(TopoGroup);//=================Topology Combobox
81  ComboTopology->insertItem("Pi");
82  ComboTopology->insertItem("Tee");
83  ComboTopology->insertItem("Bridged Tee");
84  connect(ComboTopology, SIGNAL(activated(int)), SLOT(slotTopologyChanged()));
85  tbox->addWidget(ComboTopology, 1,0);
86 
87  pixTopology = new QLabel(TopoGroup);//====================Pixmap for Topology
88  pixTopology->setPixmap(QPixmap (QImage (QucsSettings.BitmapDir + "att_pi.png")));
89  tbox->addMultiCellWidget(pixTopology,2,2,0,0);
90 
91  QVBox * vb = new QVBox (h1);
92  vb->setSpacing(2);
93 
94  QGroupBox * InputGroup = new QGroupBox (tr("Input"), vb);
95  QGridLayout * ibox = new QGridLayout(InputGroup, 5,3,5,5);
96  ibox->addMultiCellWidget(Space2,0,0,0,2);
97 
98  IntVal = new QIntValidator(this);
99  DoubleVal = new QDoubleValidator(this);
100 
101  LabelAtten = new QLabel(tr("Attenuation:"), InputGroup);
102  ibox ->addWidget(LabelAtten, 1,0);
103  lineEdit_Attvalue = new QLineEdit(tr("1"), InputGroup);
104  lineEdit_Attvalue->setValidator(DoubleVal);
105  ibox->addWidget(lineEdit_Attvalue, 1,1);
106  QLabel *Label1 = new QLabel(tr("dB"), InputGroup);
107  ibox->addWidget(Label1, 1,2);
108 
109  LabelImp1 = new QLabel(tr("Zin:"), InputGroup);
110  ibox->addWidget(LabelImp1, 2,0);
111  lineEdit_Zin = new QLineEdit(tr("50"), InputGroup);
112  lineEdit_Zin->setValidator(DoubleVal);
113  connect(lineEdit_Zin, SIGNAL(textChanged(const QString&)), this,
114  SLOT(slotSetText_Zin(const QString&)) );
115 
116  ibox->addWidget(lineEdit_Zin, 2,1);
117  QLabel *Label2 = new QLabel(tr("Ohm"), InputGroup);
118  ibox->addWidget(Label2, 2,2);
119 
120  LabelImp2 = new QLabel(tr("Zout:"), InputGroup);
121  ibox->addWidget(LabelImp2, 3,0);
122  lineEdit_Zout = new QLineEdit(tr("50"), InputGroup);
123  lineEdit_Zout->setValidator(DoubleVal);
124  connect(lineEdit_Zout, SIGNAL(textChanged(const QString&)), this,
125  SLOT(slotSetText_Zout(const QString&)) );
126  ibox->addWidget(lineEdit_Zout, 3,1);
127  QLabel *Label3 = new QLabel(tr("Ohm"), InputGroup);
128  ibox->addWidget(Label3, 3,2);
129 
130  Calculate = new QPushButton(tr("Calculate and put into Clipboard"), vb);
131  connect(Calculate, SIGNAL(clicked()), SLOT(slotCalculate()));
132 
133  QGroupBox * OutputGroup = new QGroupBox (tr("Output"), vb);
134  QGridLayout * obox = new QGridLayout(OutputGroup, 5,3,5,5);
135  obox->addMultiCellWidget(Space2,0,0,0,2);
136 
137  LabelR1 = new QLabel(tr("R1:"), OutputGroup);
138  obox->addWidget(LabelR1, 1,0);
139  lineEdit_R1 = new QLineEdit(tr("--"), OutputGroup);
140  obox->addWidget(lineEdit_R1, 1,1);
141  QLabel *Label4 = new QLabel(tr("Ohm"), OutputGroup);
142  obox->addWidget(Label4, 1,2);
143 
144  LabelR2 = new QLabel(tr("R2:"), OutputGroup);
145  obox->addWidget(LabelR2, 2,0);
146  lineEdit_R2 = new QLineEdit(tr("--"), OutputGroup);
147  obox->addWidget(lineEdit_R2, 2,1);
148  QLabel *Label5 = new QLabel(tr("Ohm"), OutputGroup);
149  obox->addWidget(Label5, 2,2);
150 
151  LabelR3 = new QLabel(tr("R3:"), OutputGroup);
152  obox->addWidget(LabelR3, 3,0);
153  lineEdit_R3 = new QLineEdit(tr("--"), OutputGroup);
154  obox->addWidget(lineEdit_R3, 3,1);
155  LabelR3_Ohm = new QLabel(tr("Ohm"), OutputGroup);
156  obox->addWidget(LabelR3_Ohm, 3,2);
157 
158  LabelResult = new QLabel(tr("Result:"), this);
159  v2->addWidget(LabelResult);
160  LabelResult->setAlignment(Qt::AlignHCenter);
161 
162  QWidget *Space1 = new QWidget(this); // reserve space for menubar
163  Space1->setFixedSize(5,5);
164  v2->addWidget(Space1);
165 }
166 
168 {
169  delete IntVal;
170  delete DoubleVal;
171 }
172 
173 void QucsAttenuator::slotHelpIntro()
174 {
175  HelpDialog *d = new HelpDialog(this);
176  d->show();
177 }
178 
179 void QucsAttenuator::slotHelpAboutQt()
180 {
181  QMessageBox::aboutQt(this, tr("About Qt"));
182 }
183 
184 void QucsAttenuator::slotHelpAbout()
185 {
186  QMessageBox::about(this, tr("About..."),
187  "QucsAttenuator Version " PACKAGE_VERSION+
188  tr("\nAttenuator synthesis program\n")+
189  tr("Copyright (C) 2006 by")+" Toyoyuki Ishikawa"
190  "\n"+
191  tr("Copyright (C) 2006 by")+" Stefan Jahn"
192  "\n"
193  "\nThis is free software; see the source for copying conditions."
194  "\nThere is NO warranty; not even for MERCHANTABILITY or "
195  "\nFITNESS FOR A PARTICULAR PURPOSE.\n\n");
196 }
197 
198 void QucsAttenuator::slotQuit()
199 {
200  int tmp;
201  tmp = x();
202  tmp = y();
203  tmp = width();
204  tmp = height();
205 
206  accept();
207  close();
208 }
209 
210 void QucsAttenuator::slotSetText_Zin( const QString &text )
211 {
212  if(ComboTopology->currentItem() == BRIDGE_TYPE) {
213  lineEdit_Zout->blockSignals( TRUE );
214  lineEdit_Zout->setText( text );
215  lineEdit_Zout->blockSignals( FALSE );
216  }
217 }
218 
219 void QucsAttenuator::slotSetText_Zout( const QString &text )
220 {
221  if(ComboTopology->currentItem() == BRIDGE_TYPE) {
222  lineEdit_Zin->blockSignals( TRUE );
223  lineEdit_Zin->setText( text );
224  lineEdit_Zin->blockSignals( FALSE );
225  }
226 }
227 
228 void QucsAttenuator::slotTopologyChanged()
229 {
230  switch(ComboTopology->currentItem())
231  {
232  case PI_TYPE:
233  pixTopology->setPixmap(QPixmap(QImage(QucsSettings.BitmapDir + "att_pi.png")));
234  LabelR2->setText("R2:");
235  LabelR3->show();
236  lineEdit_R3->show();
237  LabelR3_Ohm->show();
238  break;
239  case TEE_TYPE:
240  pixTopology->setPixmap(QPixmap(QImage(QucsSettings.BitmapDir + "att_tee.png")));
241  LabelR2->setText("R2:");
242  LabelR3->show();
243  lineEdit_R3->show();
244  LabelR3_Ohm->show();
245  break;
246  case BRIDGE_TYPE:
247  pixTopology->setPixmap(QPixmap(QImage(QucsSettings.BitmapDir + "att_bridge.png")));
248  LabelR2->setText("R4:");
249  LabelR3->hide();
250  lineEdit_R3->hide();
251  LabelR3_Ohm->hide();
252  lineEdit_Zout->setText( lineEdit_Zin->text() );
253  break;
254  }
255  adjustSize();
256 }
257 
258 void QucsAttenuator::slotCalculate()
259 {
260  QUCS_Att qatt;
261  int result;
262  QString * s = NULL;
263  struct tagATT Values;
264 
265 
266  Values.Topology = ComboTopology->currentItem();
267  Values.Attenuation = lineEdit_Attvalue->text().toDouble();
268  Values.Zin = lineEdit_Zin->text().toDouble();
269  Values.Zout = lineEdit_Zout->text().toDouble();
270  result = qatt.Calc(&Values);
271 
272  if(result != -1)
273  {
274  LabelResult->setText(tr("Result:")+" "+tr("Success!"));
275  lineEdit_R1->setText(QString::number(Values.R1, 'f', 1));
276  lineEdit_R2->setText(QString::number(Values.R2, 'f', 1));
277  lineEdit_R3->setText(QString::number(Values.R3, 'f', 1));
278 
279  s = qatt.createSchematic(&Values);
280  if(!s) return;
281 
282  QClipboard *cb = QApplication::clipboard();
283  cb->setText(*s);
284  delete s;
285  }
286  else
287  {
288  LabelResult->setText(tr("Error: Set Attenuation more than %1 dB").arg(QString::number(Values.MinimumATT, 'f', 3)));
289  lineEdit_R1->setText("--");
290  lineEdit_R2->setText("--");
291  lineEdit_R3->setText("--");
292  }
293 
294 }