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