Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/sparamfile.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                sparamfile.cpp
00003                               ----------------
00004     begin                : Sat Aug 23 2003
00005     copyright            : (C) 2003 by Michael Margraf
00006     email                : michael.margraf@alumni.tu-berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include "sparamfile.h"
00018 #include "main.h"
00019 #include "schematic.h"
00020 #include "misc.h"
00021 
00022 #include <QFileInfo>
00023 
00024 
00025 SParamFile::SParamFile()
00026 {
00027   Description = QObject::tr("S parameter file");
00028 
00029   Model = "SPfile";
00030   Name  = "X";
00031 
00032   // must be the first property !!!
00033   Props.append(new Property("File", "test.s1p", true,
00034     QObject::tr("name of the s parameter file")));
00035   Props.append(new Property("Data", "rectangular", false,
00036     QObject::tr("data type")+" [rectangular, polar]"));
00037   Props.append(new Property("Interpolator", "linear", false,
00038     QObject::tr("interpolation type")+" [linear, cubic]"));
00039   Props.append(new Property("duringDC", "open", false,
00040     QObject::tr("representation during DC analysis")+
00041           " [open, short, shortall, unspecified]"));
00042 
00043   // must be the last property !!!
00044   Props.append(new Property("Ports", "1", false,
00045     QObject::tr("number of ports")));
00046 
00047   createSymbol();
00048 }
00049 
00050 // -------------------------------------------------------
00051 Component* SParamFile::newOne()
00052 {
00053   SParamFile* p = new SParamFile();
00054   p->Props.getLast()->Value = Props.getLast()->Value;
00055   p->recreate(0);
00056   return p;
00057 }
00058 
00059 // -------------------------------------------------------
00060 Element* SParamFile::info(QString& Name, char* &BitmapFile, bool getNewOne)
00061 {
00062   Name = QObject::tr("n-port S parameter file");
00063   BitmapFile = (char *) "spfile3";
00064 
00065   if(getNewOne) {
00066     SParamFile* p = new SParamFile();
00067     p->Props.getFirst()->Value = "test.s3p";
00068     p->Props.getLast()->Value = "3";
00069     p->recreate(0);
00070     return p;
00071   }
00072   return 0;
00073 }
00074 
00075 // -------------------------------------------------------
00076 Element* SParamFile::info1(QString& Name, char* &BitmapFile, bool getNewOne)
00077 {
00078   Name = QObject::tr("1-port S parameter file");
00079   BitmapFile = (char *) "spfile1";
00080 
00081   if(getNewOne)  return new SParamFile();
00082   return 0;
00083 }
00084 
00085 // -------------------------------------------------------
00086 Element* SParamFile::info2(QString& Name, char* &BitmapFile, bool getNewOne)
00087 {
00088   Name = QObject::tr("2-port S parameter file");
00089   BitmapFile = (char *) "spfile2";
00090 
00091   if(getNewOne) {
00092     SParamFile* p = new SParamFile();
00093     p->Props.getFirst()->Value = "test.s2p";
00094     p->Props.getLast()->Value = "2";
00095     p->recreate(0);
00096     return p;
00097   }
00098   return 0;
00099 }
00100 
00101 // -------------------------------------------------------
00102 QString SParamFile::getSubcircuitFile()
00103 {
00104   // construct full filename
00105   QString FileName = Props.getFirst()->Value;
00106   return misc::properAbsFileName(FileName);
00107 }
00108 
00109 // -------------------------------------------------------
00110 QString SParamFile::netlist()
00111 {
00112   QString s = Model+":"+Name;
00113 
00114   // output all node names
00115   foreach(Port *p1, Ports)
00116     s += " "+p1->Connection->Name;   // node names
00117 
00118   // output all properties
00119   Property *p2 = Props.first();
00120   s += " "+p2->Name+"=\"{"+getSubcircuitFile()+"}\"";
00121 
00122   // data type
00123   p2 = Props.next();
00124   s += " "+p2->Name+"=\""+p2->Value+"\"";
00125 
00126   // interpolator type
00127   p2 = Props.next();
00128   s += " "+p2->Name+"=\""+p2->Value+"\"";
00129 
00130   // DC property
00131   p2 = Props.next();
00132   s += " "+p2->Name+"=\""+p2->Value+"\"\n";
00133 
00134   return s;
00135 }
00136 
00137 // -------------------------------------------------------
00138 void SParamFile::createSymbol()
00139 {
00140   QFont Font(QucsSettings.font); // default application font
00141   // symbol text is smaller (10 pt default)
00142   Font.setPointSize(10 ); 
00143   // get the small font size; use the screen-compatible metric
00144   QFontMetrics  smallmetrics(Font, 0);
00145   int fHeight = smallmetrics.lineSpacing();
00146   QString stmp;
00147 
00148   int w, PortDistance = 60;
00149   int Num = Props.getLast()->Value.toInt();
00150 
00151   // adjust number of ports
00152   if(Num < 1) Num = 1;
00153   else if(Num > 8) {
00154     PortDistance = 20;
00155     if(Num > 40) Num = 40;
00156   }
00157   Props.getLast()->Value = QString::number(Num);
00158 
00159   // draw symbol outline
00160   int h = (PortDistance/2)*((Num-1)/2) + 15;
00161   Lines.append(new Line(-15, -h, 15, -h,QPen(Qt::darkBlue,2)));
00162   Lines.append(new Line( 15, -h, 15,  h,QPen(Qt::darkBlue,2)));
00163   Lines.append(new Line(-15,  h, 15,  h,QPen(Qt::darkBlue,2)));
00164   Lines.append(new Line(-15, -h,-15,  h,QPen(Qt::darkBlue,2)));
00165   stmp = QObject::tr("file"); 
00166   w = smallmetrics.width(stmp); // compute text size to center it 
00167   Texts.append(new Text(-w/2, -fHeight/2, stmp));
00168 
00169   int i=0, y = 15-h;
00170   while(i<Num) { // add ports lines and numbers
00171     i++;
00172     Lines.append(new Line(-30, y,-15, y,QPen(Qt::darkBlue,2)));
00173     Ports.append(new Port(-30, y));
00174     stmp = QString::number(i);
00175     w = smallmetrics.width(stmp);
00176     Texts.append(new Text(-25-w, y-fHeight-2, stmp)); // text right-aligned
00177 
00178     if(i == Num) break; // if odd number of ports there will be one port less on the right side
00179     i++;
00180     Lines.append(new Line( 15, y, 30, y,QPen(Qt::darkBlue,2)));
00181     Ports.append(new Port( 30, y));
00182     stmp = QString::number(i);
00183     Texts.append(new Text(25, y-fHeight-2, stmp)); // text left-aligned
00184     y += PortDistance;
00185   }
00186 
00187   Lines.append(new Line( 0, h, 0,h+15,QPen(Qt::darkBlue,2)));
00188   Texts.append(new Text( 4, h,"Ref"));
00189   Ports.append(new Port( 0,h+15));    // 'Ref' port
00190 
00191   x1 = -30; y1 = -h-2;
00192   x2 =  30; y2 =  h+15;
00193   // compute component name text position - normal size font
00194   QFontMetrics  metrics(QucsSettings.font, 0);   // use the screen-compatible metric
00195   tx = x1+4;
00196   ty = y1 - 2*metrics.lineSpacing() - 4;
00197 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines