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