Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sweepdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  sweepdialog.cpp
3  -----------------
4  begin : Sat Aug 13 2005
5  copyright : (C) 2005 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 "sweepdialog.h"
19 #include "schematic.h"
20 #include "qucs.h"
21 
22 #include <QGridLayout>
23 #include "main.h"
24 #include "../diagrams/graph.h"
25 
26 #include <QLabel>
27 #include <QLineEdit>
28 #include <QValidator>
29 #include <QPushButton>
30 
31 // SpinBoxes are used to show the calculated bias points at the given set of sweep points
32 mySpinBox::mySpinBox(int Min, int Max, int Step, double *Val, QWidget *Parent)
33  : QSpinBox(Parent)
34 {
35  setMinimum(Min);
36  setMaximum(Max);
37  setSingleStep(Step);
38  Values = Val;
39  ValueSize = Max;
40  //editor()->
41  // setReadOnly(true);
42 }
43 
44 
45 #include <iostream>
46 using namespace std;
47 QString mySpinBox::textFromValue(int Val)
48 {
49  cout<<"Values + Val"<<*(Values+Val)<<endl;
50  return QString::number(*(Values+Val));
51 }
52 
53 QValidator::State mySpinBox::validate ( QString & text, int & pos ) const
54 {
55  if(pos>ValueSize)return QValidator::Invalid;
56  if(QString::number(*(Values+pos))==text)
57  return QValidator::Acceptable;
58  else return QValidator::Invalid;
59 }
60 
61 
63  : QDialog(Doc_)//, 0, TRUE, Qt::WDestructiveClose)
64 {
65  Doc = Doc_;
66 
68  // if simulation has no sweeps, terminate dialog before showing it
69  if(pGraph->cPointsX.count() == 0) {
70  reject();
71  return;
72  }
73  if(pGraph->cPointsX.count() <= 1)
74  if(pGraph->cPointsX.getFirst()->count <= 1) {
75  reject();
76  return;
77  }
78 
79 
80  setWindowTitle(tr("Bias Points"));
81 
82  int i = 0;
83  // ...........................................................
84  QGridLayout *all = new QGridLayout(this);//, pGraph->cPointsX.count()+2,2,3,3);
85  all->setMargin(5);
86  all->setSpacing(5);
87  all->setColStretch(1,5);
88 
89  DataX *pD;
90  mySpinBox *Box;
91 
92  for(pD = pGraph->cPointsX.first(); pD!=0; pD = pGraph->cPointsX.next()) {
93  all->addWidget(new QLabel(pD->Var, this), i,0);
94  //cout<<"count: "<<pD->count-1<<", points: "<<*pD->Points<<endl;
95  //works only for linear:
96  /*double Min = pD->Points[0];
97  double Max = pD->Points[pD->count-1];
98  double Step = (Max-Min)/(pD->count);
99  cout<<"Min: "<<Min<<", Max: "<<Max<<", Step: "<<Step<<endl;
100  Box = new mySpinBox(Min, Max, Step, pD->Points, this);*/
101  Box = new mySpinBox(0, pD->count-1, 1, pD->Points, this);
102  Box->setValue(0);
103  all->addWidget(Box, i++,1);
104  connect(Box, SIGNAL(valueChanged(int)), SLOT(slotNewValue(int)));
105  BoxList.append(Box);
106  }
107 
108  // ...........................................................
109  all->setRowStretch(i,5);
110  QPushButton *ButtClose = new QPushButton(tr("Close"), this);
111  all->addMultiCellWidget(ButtClose, i+1,i+1, 0,1);
112  connect(ButtClose, SIGNAL(clicked()), SLOT(accept()));
113  show();
114 }
115 
117 {
118  delete pGraph;
119 
120  for(double *p = ValueList.first(); p!=0; p = ValueList.next())
121  delete p;
122 }
123 
124 // ---------------------------------------------------------------
126 {
127  DataX *pD = pGraph->cPointsX.first();
128  int Factor = 1, Index = 0;
129  for(mySpinBox *pb = BoxList.first(); pb!=0; pb = BoxList.next()) {
130  Index += pb->value() * Factor;
131  Factor *= pD->count;
132  }
133  Index *= 2; // because of complex values
134 
135  double *p = ValueList.first();
136  for(Node *pn = NodeList.first(); pn!=0; pn = NodeList.next()) {
137  pn->Name = num2str(*(p+Index));
138  if(pn->x1 & 0x10)
139  pn->Name += "A";
140  else
141  pn->Name += "V";
142  p = ValueList.next();
143  }
144 
145  Doc->viewport()->update();
146 }
147 
148 // ---------------------------------------------------
150 {
151  // When this function is entered, a simulation was performed.
152  // Thus, the node names are still in "node->Name".
153 
154  bool hasNoComp;
155  Graph *pg = new Graph("");
156  Diagram *Diag = new Diagram();
157  QFileInfo Info(Doc->DocName);
158  QString DataSet = Info.dirPath() + QDir::separator() + Doc->DataSet;
159 
160  Node *pn;
161  Element *pe;
162  // create DC voltage for all nodes
163  for(pn = Doc->Nodes->first(); pn != 0; pn = Doc->Nodes->next()) {
164  if(pn->Name.isEmpty()) continue;
165 
166  pn->x1 = 0;
167  if(pn->Connections.count() < 2) {
168  pn->Name = ""; // no text at open nodes
169  continue;
170  }
171  else {
172  hasNoComp = true;
173  for(pe = pn->Connections.first(); pe!=0; pe = pn->Connections.next())
174  if(pe->Type == isWire) {
175  if( ((Wire*)pe)->isHorizontal() ) pn->x1 |= 2;
176  }
177  else {
178  if( ((Component*)pe)->Model == "GND" ) {
179  hasNoComp = true; // no text at ground symbol
180  break;
181  }
182 
183  if(pn->cx < pe->cx) pn->x1 |= 1; // to the right is no room
184  hasNoComp = false;
185  }
186  if(hasNoComp) { // text only were a component is connected
187  pn->Name = "";
188  continue;
189  }
190  }
191 
192  pg->Var = pn->Name + ".V";
193  if(Diag->loadVarData(DataSet, pg)) {
194  pn->Name = num2str(*(pg->cPointsY)) + "V";
195  NodeList.append(pn); // remember node ...
196  ValueList.append(pg->cPointsY); // ... and all of its values
197  pg->cPointsY = 0; // do not delete it next time !
198  }
199  else
200  pn->Name = "0V";
201 
202 
203  for(pe = pn->Connections.first(); pe!=0; pe = pn->Connections.next())
204  if(pe->Type == isWire) {
205  if( ((Wire*)pe)->Port1 != pn ) // no text at next node
206  ((Wire*)pe)->Port1->Name = "";
207  else ((Wire*)pe)->Port2->Name = "";
208  }
209  }
210 
211 
212  // create DC current through each probe
213  Component *pc;
214  for(pc = Doc->Components->first(); pc != 0; pc = Doc->Components->next())
215  if(pc->Model == "IProbe") {
216  pn = pc->Ports.first()->Connection;
217  if(!pn->Name.isEmpty()) // preserve node voltage ?
218  pn = pc->Ports.next()->Connection;
219 
220  pn->x1 = 0x10; // mark current
221  pg->Var = pc->Name + ".I";
222  if(Diag->loadVarData(DataSet, pg)) {
223  pn->Name = num2str(*(pg->cPointsY)) + "A";
224  NodeList.append(pn); // remember node ...
225  ValueList.append(pg->cPointsY); // ... and all of its values
226  pg->cPointsY = 0; // do not delete it next time !
227  }
228  else
229  pn->Name = "0A";
230 
231  for(pe = pn->Connections.first(); pe!=0; pe = pn->Connections.next())
232  if(pe->Type == isWire) {
233  if( ((Wire*)pe)->isHorizontal() ) pn->x1 |= 2;
234  }
235  else {
236  if(pn->cx < pe->cx) pn->x1 |= 1; // to the right is no room
237  }
238  }
239 
240 
241  Doc->showBias = 1;
242  delete Diag;
243  return pg;
244 }
void slotNewValue(int)
mySpinBox(int, int, int, double *, QWidget *)
Definition: sweepdialog.cpp:32
Graph * setBiasPoints()
Q3PtrList< Node > NodeList
Definition: sweepdialog.h:68
int Type
Definition: element.h:152
Definition: node.h:30
Definition: wire.h:31
int count
Definition: graph.h:53
Definition: graph.h:57
int showBias
Definition: qucsdoc.h:63
QGridLayout * all
Definition: sweepdialog.h:63
int x1
Definition: element.h:153
QString Var
Definition: graph.h:50
QString textFromValue(int)
Definition: sweepdialog.cpp:47
Definition: graph.h:47
Graph * pGraph
Definition: sweepdialog.h:66
QString Var
Definition: graph.h:75
Definitions and declarations for the main application.
Schematic * Doc
Definition: sweepdialog.h:67
int cx
Definition: element.h:153
Q3PtrList< Component > * Components
Definition: schematic.h:123
QString num2str(double Num)
Definition: main.cpp:384
Q3PtrList< Element > Connections
Definition: node.h:39
Q3PtrList< Node > * Nodes
Definition: schematic.h:120
int loadVarData(const QString &, Graph *)
Definition: diagram.cpp:828
Q3PtrList< double > ValueList
Definition: sweepdialog.h:69
Superclass of all schematic drawing elements.
Definition: element.h:142
Q3PtrList< Port > Ports
Definition: component.h:70
QString DataSet
Definition: qucsdoc.h:52
SweepDialog(Schematic *)
Definition: sweepdialog.cpp:62
QString Name
Definition: component.h:80
QString Model
Definition: component.h:80
QString Name
Definition: node.h:40
QString DocName
Definition: qucsdoc.h:51
int ValueSize
Definition: sweepdialog.h:46
Q3PtrList< mySpinBox > BoxList
Definition: sweepdialog.h:64
double * Points
Definition: graph.h:52
Q3PtrList< DataX > cPointsX
Definition: graph.h:71
#define isWire
Definition: element.h:118
double * Values
Definition: sweepdialog.h:45
double * cPointsY
Definition: graph.h:72
QValidator::State validate(QString &text, int &pos) const
Definition: sweepdialog.cpp:53