Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/rfedd2p.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                rfedd2p.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 "rfedd2p.h"
00018 #include "main.h"
00019 #include "schematic.h"
00020 
00021 #include <QFileInfo>
00022 
00023 
00024 
00025 RFedd2P::RFedd2P()
00026 {
00027   Description = QObject::tr("equation defined 2-port RF device");
00028 
00029   Model = "RFEDD2P";
00030   Name  = "RF";
00031 
00032   // first properties !!!
00033   Props.append(new Property("Type", "Y", false,
00034     QObject::tr("type of parameters")+" [Y, Z, S, H, G, A, T]"));
00035   Props.append(new Property("duringDC", "open", false,
00036     QObject::tr("representation during DC analysis")+
00037           " [open, short, unspecified, zerofrequency]"));
00038 
00039   // last properties
00040   Props.append(new Property("P11", "0", false,
00041     QObject::tr("parameter equation") + " 11"));
00042   Props.append(new Property("P12", "0", false,
00043     QObject::tr("parameter equation") + " 12"));
00044   Props.append(new Property("P21", "0", false,
00045     QObject::tr("parameter equation") + " 21"));
00046   Props.append(new Property("P22", "0", false,
00047     QObject::tr("parameter equation") + " 22"));
00048 
00049   createSymbol();
00050 }
00051 
00052 // -------------------------------------------------------
00053 Component* RFedd2P::newOne()
00054 {
00055   RFedd2P* p = new RFedd2P();
00056   p->Props.at(0)->Value = Props.at(0)->Value;
00057   p->recreate(0);
00058   return p;
00059 }
00060 
00061 // -------------------------------------------------------
00062 Element* RFedd2P::info(QString& Name, char* &BitmapFile, bool getNewOne)
00063 {
00064   Name = QObject::tr("Equation Defined 2-port RF Device");
00065   BitmapFile = (char *) "rfedd";
00066 
00067   if(getNewOne) {
00068     RFedd2P* p = new RFedd2P();
00069     p->Props.at(0)->Value = "Y";
00070     p->recreate(0);
00071     return p;
00072   }
00073   return 0;
00074 }
00075 
00076 // -------------------------------------------------------
00077 QString RFedd2P::netlist()
00078 {
00079   QString s = "RFEDD:"+Name;
00080   QString e = "\n";
00081   QString n, p;
00082 
00083   // output all node names
00084   foreach(Port *p1, Ports)
00085     s += " "+p1->Connection->Name;   // node names
00086 
00087   // output all properties
00088   Property *p2;
00089   p2 = Props.at(0);
00090   s += " "+p2->Name+"=\""+p2->Value+"\"";
00091   p = p2->Value;
00092   p2 = Props.at(1);
00093   s += " "+p2->Name+"=\""+p2->Value+"\"";
00094   p2 = Props.at(2);
00095   while(p2) {
00096     n = p2->Name.mid(1);
00097     s += " "+p2->Name+"=\""+Name+"."+p+n+"\"";
00098     e += "  Eqn:Eqn"+Name+p2->Name+" "+
00099       Name+"."+p+n+"=\""+p2->Value+"\" Export=\"no\"\n";
00100     p2 = Props.next();
00101   }
00102 
00103   return s+e;
00104 }
00105 
00106 // -------------------------------------------------------
00107 void RFedd2P::createSymbol()
00108 {
00109   QFont Font(QucsSettings.font); // default application font
00110   // symbol text is smaller (10 pt default)
00111   Font.setPointSize(10); 
00112   // get the small font size; use the screen-compatible metric
00113   QFontMetrics  smallmetrics(Font, 0); 
00114   int fHeight = smallmetrics.lineSpacing();
00115   QString tmp;
00116   int w, i;
00117 
00118   // draw symbol
00119   #define HALFWIDTH  17
00120   int h = 15;
00121   Lines.append(new Line(-HALFWIDTH, -h, HALFWIDTH, -h,QPen(Qt::darkBlue,2)));
00122   Lines.append(new Line( HALFWIDTH, -h, HALFWIDTH,  h,QPen(Qt::darkBlue,2)));
00123   Lines.append(new Line(-HALFWIDTH,  h, HALFWIDTH,  h,QPen(Qt::darkBlue,2)));
00124   Lines.append(new Line(-HALFWIDTH, -h,-HALFWIDTH,  h,QPen(Qt::darkBlue,2)));
00125 
00126   // component text name
00127   tmp = Props.at(0)->Value;
00128   w = smallmetrics.width(tmp);
00129   Texts.append(new Text(-w/2, -fHeight/2, tmp)); // text centered in the box
00130 
00131   // add port numbers text
00132   i = 0;
00133   int y = 15-h;
00134   Lines.append(new Line(-30,  y,-HALFWIDTH,  y,QPen(Qt::darkBlue,2)));
00135   Ports.append(new Port(-30,  y));
00136   tmp = QString::number(i+1);
00137   w = smallmetrics.width(tmp);
00138   Texts.append(new Text(-25-w, y-fHeight-2, tmp)); // text right-aligned
00139   i++;
00140 
00141   Lines.append(new Line(HALFWIDTH,  y, 30,  y,QPen(Qt::darkBlue,2)));
00142   Ports.append(new Port( 30,  y));
00143   tmp = QString::number(i+1);
00144   Texts.append(new Text(25, y-fHeight-2, tmp)); // text left-aligned
00145   y += 60;
00146   i++;
00147 
00148   x1 = -30; y1 = -h-2;
00149   x2 =  30; y2 =  h+2;
00150   // compute component name text position - normal size font
00151   QFontMetrics  metrics(QucsSettings.font, 0);   // use the screen-compatible metric
00152   tx = x1+4;
00153   ty = y1 - metrics.lineSpacing() - 4;
00154 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines