Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/rfedd.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                rfedd.cpp
00003                               ----------------
00004     begin                : Sub Feb 17 2008
00005     copyright            : (C) 2008 by Stefan Jahn
00006     email                : stefan@lkcc.org
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 "rfedd.h"
00018 #include "main.h"
00019 #include "schematic.h"
00020 
00021 #include <QFileInfo>
00022 
00023 
00024 RFedd::RFedd()
00025 {
00026   Description = QObject::tr("equation defined RF device");
00027 
00028   Model = "RFEDD";
00029   Name  = "RF";
00030 
00031   // first properties !!!
00032   Props.append(new Property("Type", "Y", false,
00033     QObject::tr("type of parameters")+" [Y, Z, S]"));
00034   Props.append(new Property("Ports", "2", false,
00035     QObject::tr("number of ports")));
00036   Props.append(new Property("duringDC", "open", false,
00037     QObject::tr("representation during DC analysis")+
00038           " [open, short, unspecified, zerofrequency]"));
00039 
00040   // last properties
00041   Props.append(new Property("P11", "0", false,
00042     QObject::tr("parameter equation") + " 11"));
00043   Props.append(new Property("P12", "0", false,
00044     QObject::tr("parameter equation") + " 12"));
00045   Props.append(new Property("P21", "0", false,
00046     QObject::tr("parameter equation") + " 21"));
00047   Props.append(new Property("P22", "0", false,
00048     QObject::tr("parameter equation") + " 22"));
00049 
00050   createSymbol();
00051 }
00052 
00053 // -------------------------------------------------------
00054 Component* RFedd::newOne()
00055 {
00056   RFedd* p = new RFedd();
00057   p->Props.at(0)->Value = Props.at(0)->Value;
00058   p->Props.at(1)->Value = Props.at(1)->Value;
00059   p->recreate(0);
00060   return p;
00061 }
00062 
00063 // -------------------------------------------------------
00064 Element* RFedd::info(QString& Name, char* &BitmapFile, bool getNewOne)
00065 {
00066   Name = QObject::tr("Equation Defined RF Device");
00067   BitmapFile = (char *) "rfedd";
00068 
00069   if(getNewOne) {
00070     RFedd* p = new RFedd();
00071     p->Props.at(0)->Value = "Y";
00072     p->Props.at(1)->Value = "2";
00073     p->recreate(0);
00074     return p;
00075   }
00076   return 0;
00077 }
00078 
00079 // -------------------------------------------------------
00080 QString RFedd::netlist()
00081 {
00082   QString s = Model+":"+Name;
00083   QString e = "\n";
00084   QString n, p;
00085 
00086   // output all node names
00087   foreach(Port *p1, Ports)
00088     s += " "+p1->Connection->Name;   // node names
00089 
00090   // output all properties
00091   Property *p2;
00092   p2 = Props.at(0);
00093   s += " "+p2->Name+"=\""+p2->Value+"\"";
00094   p = p2->Value;
00095   p2 = Props.at(2);
00096   s += " "+p2->Name+"=\""+p2->Value+"\"";
00097   p2 = Props.at(3);
00098   while(p2) {
00099     n = p2->Name.mid(1);
00100     s += " "+p2->Name+"=\""+Name+"."+p+n+"\"";
00101     e += "  Eqn:Eqn"+Name+p2->Name+" "+
00102       Name+"."+p+n+"=\""+p2->Value+"\" Export=\"no\"\n";
00103     p2 = Props.next();
00104   }
00105 
00106   return s+e;
00107 }
00108 
00109 // -------------------------------------------------------
00110 void RFedd::createSymbol()
00111 {
00112   QFont Font(QucsSettings.font); // default application font
00113   // symbol text is smaller (10 pt default)
00114   Font.setPointSize(10); 
00115   // get the small font size; use the screen-compatible metric
00116   QFontMetrics  smallmetrics(Font, 0); 
00117   int fHeight = smallmetrics.lineSpacing();
00118   QString tmp;
00119   int w, i;
00120 
00121   // adjust port number
00122   int No = Props.at(1)->Value.toInt();
00123   if(No < 1) No = 1;
00124   if(No > 8) No = 8;
00125   Props.at(1)->Value = QString::number(No);
00126 
00127   // adjust property number and names
00128   int NumProps = Props.count() - 3; // Type, Ports, duringDC
00129   if (NumProps < No * No) { // number of ports was increased, add properties
00130     for(i = 0; i < NumProps; i++) {
00131       tmp=QString::number((i)/No+1)+QString::number((i)%No+1);
00132       Props.at(i+3)->Name="P"+tmp;
00133       Props.at(i+3)->Description=QObject::tr("parameter equation") + " " +tmp;
00134     }
00135     for(i = NumProps; i < No * No; i++) {
00136       tmp=QString::number((i)/No+1)+QString::number((i)%No+1);
00137       Props.append(new Property("P"+tmp, "0", false,
00138     QObject::tr("parameter equation") + " " +tmp));
00139     }
00140   } else { // number of ports was decreased, remove properties
00141     for(i = No * No; i < NumProps; i++) {
00142       Props.removeLast();
00143     }
00144     for(i = 0; i < No * No; i++) {
00145       tmp=QString::number((i)/No+1)+QString::number((i)%No+1);
00146       Props.at(i+3)->Name="P"+tmp;
00147       Props.at(i+3)->Description=QObject::tr("parameter equation") + " " +tmp;
00148     }
00149   }
00150 
00151   // draw symbol
00152   #define HALFWIDTH  17
00153   int h = 30*((No-1)/2) + 15;
00154   Lines.append(new Line(-HALFWIDTH, -h, HALFWIDTH, -h,QPen(Qt::darkBlue,2)));
00155   Lines.append(new Line( HALFWIDTH, -h, HALFWIDTH,  h,QPen(Qt::darkBlue,2)));
00156   Lines.append(new Line(-HALFWIDTH,  h, HALFWIDTH,  h,QPen(Qt::darkBlue,2)));
00157   Lines.append(new Line(-HALFWIDTH, -h,-HALFWIDTH,  h,QPen(Qt::darkBlue,2)));
00158 
00159   // component text name, centered
00160   tmp = QObject::tr("RF");
00161   w = smallmetrics.width(tmp);
00162   Texts.append(new Text(-w/2, -fHeight/2, tmp)); // text centered in box
00163 
00164   i = 0;
00165   int y = 15-h;
00166   while(i<No) { // add ports lines and numbers
00167     // left side
00168     Lines.append(new Line(-30,  y,-HALFWIDTH,  y,QPen(Qt::darkBlue,2)));
00169     Ports.append(new Port(-30,  y));
00170     tmp = QString::number(i+1);
00171     w = smallmetrics.width(tmp);
00172     Texts.append(new Text(-25-w, y-fHeight-2, tmp)); // text right-aligned
00173     i++;
00174 
00175     if(i == No) break; // if odd number of ports there will be one port less on the right side
00176     // right side
00177     Lines.append(new Line(HALFWIDTH,  y, 30,  y,QPen(Qt::darkBlue,2)));
00178     Ports.append(new Port( 30,  y));
00179     tmp = QString::number(i+1);
00180     Texts.append(new Text(25, y-fHeight-2, tmp)); // text left-aligned
00181     y += 60;
00182     i++;
00183   }
00184 
00185   x1 = -30; y1 = -h-2;
00186   x2 =  30; y2 =  h+2;
00187   // compute component name text position - normal size font
00188   QFontMetrics  metrics(QucsSettings.font, 0);   // use the screen-compatible metric
00189   tx = x1+4;
00190   ty = y1 - metrics.lineSpacing() - 4;
00191 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines