Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rfedd.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  rfedd.cpp
3  ----------------
4  begin : Sub Feb 17 2008
5  copyright : (C) 2008 by Stefan Jahn
6  email : stefan@lkcc.org
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 "rfedd.h"
19 #include "main.h"
20 #include "schematic.h"
21 
22 #include <QFileInfo>
23 
24 
25 
27 {
28  Description = QObject::tr("equation defined RF device");
29 
30  Model = "RFEDD";
31  Name = "RF";
32 
33  // first properties !!!
34  Props.append(new Property("Type", "Y", false,
35  QObject::tr("type of parameters")+" [Y, Z, S]"));
36  Props.append(new Property("Ports", "2", false,
37  QObject::tr("number of ports")));
38  Props.append(new Property("duringDC", "open", false,
39  QObject::tr("representation during DC analysis")+
40  " [open, short, unspecified, zerofrequency]"));
41 
42  // last properties
43  Props.append(new Property("P11", "0", false,
44  QObject::tr("parameter equation") + " 11"));
45  Props.append(new Property("P12", "0", false,
46  QObject::tr("parameter equation") + " 12"));
47  Props.append(new Property("P21", "0", false,
48  QObject::tr("parameter equation") + " 21"));
49  Props.append(new Property("P22", "0", false,
50  QObject::tr("parameter equation") + " 22"));
51 
52  createSymbol();
53 }
54 
55 // -------------------------------------------------------
57 {
58  RFedd* p = new RFedd();
59  p->Props.at(0)->Value = Props.at(0)->Value;
60  p->Props.at(1)->Value = Props.at(1)->Value;
61  p->recreate(0);
62  return p;
63 }
64 
65 // -------------------------------------------------------
66 Element* RFedd::info(QString& Name, char* &BitmapFile, bool getNewOne)
67 {
68  Name = QObject::tr("Equation Defined RF Device");
69  BitmapFile = (char *) "rfedd";
70 
71  if(getNewOne) {
72  RFedd* p = new RFedd();
73  p->Props.at(0)->Value = "Y";
74  p->Props.at(1)->Value = "2";
75  p->recreate(0);
76  return p;
77  }
78  return 0;
79 }
80 
81 // -------------------------------------------------------
82 QString RFedd::netlist()
83 {
84  QString s = Model+":"+Name;
85  QString e = "\n";
86  QString n, p;
87 
88  // output all node names
89  for(Port *p1 = Ports.first(); p1 != 0; p1 = Ports.next())
90  s += " "+p1->Connection->Name; // node names
91 
92  // output all properties
93  Property *p2;
94  p2 = Props.at(0);
95  s += " "+p2->Name+"=\""+p2->Value+"\"";
96  p = p2->Value;
97  p2 = Props.at(2);
98  s += " "+p2->Name+"=\""+p2->Value+"\"";
99  p2 = Props.at(3);
100  while(p2) {
101  n = p2->Name.mid(1);
102  s += " "+p2->Name+"=\""+Name+"."+p+n+"\"";
103  e += " Eqn:Eqn"+Name+p2->Name+" "+
104  Name+"."+p+n+"=\""+p2->Value+"\" Export=\"no\"\n";
105  p2 = Props.next();
106  }
107 
108  return s+e;
109 }
110 
111 // -------------------------------------------------------
113 {
114  QFontMetrics metrics(QucsSettings.font); // get size of text
115  int fHeight = metrics.lineSpacing();
116  int w, i;
117  QString tmp;
118 
119  // adjust port number
120  int No = Props.at(1)->Value.toInt();
121  if(No < 1) No = 1;
122  if(No > 8) No = 8;
123  Props.at(1)->Value = QString::number(No);
124 
125  // adjust property number and names
126  int NumProps = Props.count() - 3;
127  if (NumProps < No * No) {
128  for(i = 0; i < NumProps; i++) {
129  tmp=QString::number((i)/No+1)+QString::number((i)%No+1);
130  Props.at(i+3)->Name="P"+tmp;
131  Props.at(i+3)->Description=QObject::tr("parameter equation") + " " +tmp;
132  }
133  for(i = NumProps; i < No * No; i++) {
134  tmp=QString::number((i)/No+1)+QString::number((i)%No+1);
135  Props.append(new Property("P"+tmp, "0", false,
136  QObject::tr("parameter equation") + " " +tmp));
137  }
138  } else {
139  for(i = No * No; i < NumProps; i++) {
140  Props.removeLast();
141  }
142  for(i = 0; i < No * No; i++) {
143  tmp=QString::number((i)/No+1)+QString::number((i)%No+1);
144  Props.at(i+3)->Name="P"+tmp;
145  Props.at(i+3)->Description=QObject::tr("parameter equation") + " " +tmp;
146  }
147  }
148 
149  // draw symbol
150  #define HALFWIDTH 17
151  int h = 30*((No-1)/2) + 15;
152  Lines.append(new Line(-HALFWIDTH, -h, HALFWIDTH, -h,QPen(Qt::darkBlue,2)));
153  Lines.append(new Line( HALFWIDTH, -h, HALFWIDTH, h,QPen(Qt::darkBlue,2)));
154  Lines.append(new Line(-HALFWIDTH, h, HALFWIDTH, h,QPen(Qt::darkBlue,2)));
155  Lines.append(new Line(-HALFWIDTH, -h,-HALFWIDTH, h,QPen(Qt::darkBlue,2)));
156 
157  i = fHeight/2;
158  tmp = QObject::tr("RF");
159  w = metrics.width(tmp);
160  Texts.append(new Text(w/-2, -i, tmp));
161 
162  i = 0;
163  int y = 15-h;
164  while(i<No) {
165  Lines.append(new Line(-30, y,-HALFWIDTH, y,QPen(Qt::darkBlue,2)));
166  Ports.append(new Port(-30, y));
167  tmp = QString::number(i+1);
168  w = metrics.width(tmp);
169  Texts.append(new Text(-20-w, y-fHeight-2, tmp));
170  i++;
171 
172  if(i == No) break;
173  Lines.append(new Line(HALFWIDTH, y, 30, y,QPen(Qt::darkBlue,2)));
174  Ports.append(new Port( 30, y));
175  tmp = QString::number(i+1);
176  Texts.append(new Text( 20, y-fHeight-2, tmp));
177  y += 60;
178  i++;
179  }
180 
181  x1 = -30; y1 = -h-2;
182  x2 = 30; y2 = h+2;
183 
184  tx = x1+4;
185  ty = y1 - fHeight - 4;
186 }
Q3PtrList< Line > Lines
Definition: component.h:67
QString netlist()
Definition: rfedd.cpp:82
int y1
Definition: element.h:153
QFont font
Definition: main.h:46
tQucsSettings QucsSettings
Definition: main.cpp:52
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
Definitions and declarations for the main application.
int ty
Definition: component.h:78
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: rfedd.cpp:66
Q3PtrList< Property > Props
Definition: component.h:72
Component * newOne()
Definition: rfedd.cpp:56
RFedd()
Definition: rfedd.cpp:26
#define HALFWIDTH
Definition: element.h:82
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
void recreate(Schematic *)
Definition: component.cpp:1250
Q3PtrList< Port > Ports
Definition: component.h:70
QString Name
Definition: component.h:80
Q3PtrList< Text > Texts
Definition: component.h:71
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
Definition: rfedd.h:24
int x2
Definition: element.h:153
void createSymbol()
Definition: rfedd.cpp:112