Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sparamfile.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  sparamfile.cpp
3  ----------------
4  begin : Sat Aug 23 2003
5  copyright : (C) 2003 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 "sparamfile.h"
19 #include "main.h"
20 #include "schematic.h"
21 
22 #include <QFileInfo>
23 
24 
25 
27 {
28  Description = QObject::tr("S parameter file");
29 
30  Model = "SPfile";
31  Name = "X";
32 
33  // must be the first property !!!
34  Props.append(new Property("File", "test.s1p", true,
35  QObject::tr("name of the s parameter file")));
36  Props.append(new Property("Data", "rectangular", false,
37  QObject::tr("data type")+" [rectangular, polar]"));
38  Props.append(new Property("Interpolator", "linear", false,
39  QObject::tr("interpolation type")+" [linear, cubic]"));
40  Props.append(new Property("duringDC", "open", false,
41  QObject::tr("representation during DC analysis")+
42  " [open, short, shortall, unspecified]"));
43 
44  // must be the last property !!!
45  Props.append(new Property("Ports", "1", false,
46  QObject::tr("number of ports")));
47 
48  createSymbol();
49 }
50 
51 // -------------------------------------------------------
53 {
54  SParamFile* p = new SParamFile();
55  p->Props.getLast()->Value = Props.getLast()->Value;
56  p->recreate(0);
57  return p;
58 }
59 
60 // -------------------------------------------------------
61 Element* SParamFile::info(QString& Name, char* &BitmapFile, bool getNewOne)
62 {
63  Name = QObject::tr("n-port S parameter file");
64  BitmapFile = (char *) "spfile3";
65 
66  if(getNewOne) {
67  SParamFile* p = new SParamFile();
68  p->Props.getFirst()->Value = "test.s3p";
69  p->Props.getLast()->Value = "3";
70  p->recreate(0);
71  return p;
72  }
73  return 0;
74 }
75 
76 // -------------------------------------------------------
77 Element* SParamFile::info1(QString& Name, char* &BitmapFile, bool getNewOne)
78 {
79  Name = QObject::tr("1-port S parameter file");
80  BitmapFile = (char *) "spfile1";
81 
82  if(getNewOne) return new SParamFile();
83  return 0;
84 }
85 
86 // -------------------------------------------------------
87 Element* SParamFile::info2(QString& Name, char* &BitmapFile, bool getNewOne)
88 {
89  Name = QObject::tr("2-port S parameter file");
90  BitmapFile = (char *) "spfile2";
91 
92  if(getNewOne) {
93  SParamFile* p = new SParamFile();
94  p->Props.getFirst()->Value = "test.s2p";
95  p->Props.getLast()->Value = "2";
96  p->recreate(0);
97  return p;
98  }
99  return 0;
100 }
101 
102 // -------------------------------------------------------
104 {
105  // construct full filename
106  QString FileName = Props.getFirst()->Value;
107  return properAbsFileName(FileName);
108 }
109 
110 // -------------------------------------------------------
112 {
113  QString s = Model+":"+Name;
114 
115  // output all node names
116  for(Port *p1 = Ports.first(); p1 != 0; p1 = Ports.next())
117  s += " "+p1->Connection->Name; // node names
118 
119  // output all properties
120  Property *p2 = Props.first();
121  s += " "+p2->Name+"=\"{"+getSubcircuitFile()+"}\"";
122 
123  // data type
124  p2 = Props.next();
125  s += " "+p2->Name+"=\""+p2->Value+"\"";
126 
127  // interpolator type
128  p2 = Props.next();
129  s += " "+p2->Name+"=\""+p2->Value+"\"";
130 
131  // DC property
132  p2 = Props.next();
133  s += " "+p2->Name+"=\""+p2->Value+"\"\n";
134 
135  return s;
136 }
137 
138 // -------------------------------------------------------
140 {
141  int PortDistance = 60;
142  int Num = Props.getLast()->Value.toInt();
143  if(Num < 1) Num = 1;
144  else if(Num > 8) {
145  PortDistance = 20;
146  if(Num > 40) Num = 40;
147  }
148  Props.getLast()->Value = QString::number(Num);
149 
150  int h = (PortDistance/2)*((Num-1)/2) + 15;
151  Lines.append(new Line(-15, -h, 15, -h,QPen(Qt::darkBlue,2)));
152  Lines.append(new Line( 15, -h, 15, h,QPen(Qt::darkBlue,2)));
153  Lines.append(new Line(-15, h, 15, h,QPen(Qt::darkBlue,2)));
154  Lines.append(new Line(-15, -h,-15, h,QPen(Qt::darkBlue,2)));
155  Texts.append(new Text( -9, -6,QObject::tr("file")));
156 
157 
158  int i=0, y = 15-h;
159  while(i<Num) {
160  i++;
161  Lines.append(new Line(-30, y,-15, y,QPen(Qt::darkBlue,2)));
162  Ports.append(new Port(-30, y));
163  Texts.append(new Text(-25,y-14,QString::number(i)));
164 
165  if(i == Num) break;
166  i++;
167  Lines.append(new Line( 15, y, 30, y,QPen(Qt::darkBlue,2)));
168  Ports.append(new Port( 30, y));
169  Texts.append(new Text( 19,y-14,QString::number(i)));
170  y += PortDistance;
171  }
172 
173  Lines.append(new Line( 0, h, 0,h+15,QPen(Qt::darkBlue,2)));
174  Texts.append(new Text( 4, h,"Ref"));
175  Ports.append(new Port( 0,h+15)); // 'Ref' port
176 
177  x1 = -30; y1 = -h-2;
178  x2 = 30; y2 = h+15;
179 
180  QFontMetrics metrics(QucsSettings.font); // get size of text
181  tx = x1+4;
182  ty = y1 - 2*metrics.lineSpacing() - 4;
183 }
Q3PtrList< Line > Lines
Definition: component.h:67
int y1
Definition: element.h:153
QFont font
Definition: main.h:46
tQucsSettings QucsSettings
Definition: main.cpp:52
QString netlist()
Definition: sparamfile.cpp:111
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
void createSymbol()
Definition: sparamfile.cpp:139
Definitions and declarations for the main application.
int ty
Definition: component.h:78
QString properAbsFileName(const QString &Name)
Definition: main.cpp:452
Q3PtrList< Property > Props
Definition: component.h:72
static Element * info2(QString &, char *&, bool getNewOne=false)
Definition: sparamfile.cpp:87
Definition: element.h:82
QString getSubcircuitFile()
Definition: sparamfile.cpp:103
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
Component * newOne()
Definition: sparamfile.cpp:52
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: sparamfile.cpp:61
int x2
Definition: element.h:153
static Element * info1(QString &, char *&, bool getNewOne=false)
Definition: sparamfile.cpp:77