Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 eqndefined.cpp 00003 ---------------- 00004 begin : Thu Apr 19 2007 00005 copyright : (C) 2007 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 "eqndefined.h" 00018 #include "main.h" 00019 #include "schematic.h" 00020 00021 #include <QFileInfo> 00022 00023 EqnDefined::EqnDefined() 00024 { 00025 Description = QObject::tr("equation defined device"); 00026 00027 Model = "EDD"; 00028 Name = "D"; 00029 00030 // first properties !!! 00031 Props.append(new Property("Type", "explicit", false, 00032 QObject::tr("type of equations")+" [explicit, implicit]")); 00033 Props.append(new Property("Branches", "1", false, 00034 QObject::tr("number of branches"))); 00035 00036 // last properties 00037 Props.append(new Property("I1", "0", true, 00038 QObject::tr("current equation") + " 1")); 00039 Props.append(new Property("Q1", "0", false, 00040 QObject::tr("charge equation") + " 1")); 00041 00042 createSymbol(); 00043 } 00044 00045 // ------------------------------------------------------- 00046 Component* EqnDefined::newOne() 00047 { 00048 EqnDefined* p = new EqnDefined(); 00049 p->Props.at(0)->Value = Props.at(0)->Value; 00050 p->Props.at(1)->Value = Props.at(1)->Value; 00051 p->recreate(0); 00052 return p; 00053 } 00054 00055 // ------------------------------------------------------- 00056 Element* EqnDefined::info(QString& Name, char* &BitmapFile, bool getNewOne) 00057 { 00058 Name = QObject::tr("Equation Defined Device"); 00059 BitmapFile = (char *) "edd"; 00060 00061 if(getNewOne) { 00062 EqnDefined* p = new EqnDefined(); 00063 p->Props.at(0)->Value = "explicit"; 00064 p->Props.at(1)->Value = "1"; 00065 p->recreate(0); 00066 return p; 00067 } 00068 return 0; 00069 } 00070 00071 // ------------------------------------------------------- 00072 QString EqnDefined::netlist() 00073 { 00074 QString s = Model+":"+Name; 00075 QString e = "\n"; 00076 00077 // output all node names 00078 foreach(Port *p1, Ports) 00079 s += " "+p1->Connection->Name; // node names 00080 00081 // output all properties 00082 Property *p2 = Props.at(2); 00083 while(p2) { 00084 s += " "+p2->Name+"=\""+Name+"."+p2->Name+"\""; 00085 e += " Eqn:Eqn"+Name+p2->Name+" "+ 00086 Name+"."+p2->Name+"=\""+p2->Value+"\" Export=\"no\"\n"; 00087 p2 = Props.next(); 00088 } 00089 00090 return s+e; 00091 } 00092 00093 // ------------------------------------------------------- 00094 void EqnDefined::createSymbol() 00095 { 00096 QFont Font(QucsSettings.font); // default application font 00097 // symbol text is smaller (10 pt default) 00098 //Font.setPointSizeF(Font.pointSizeF()/1.2); // symbol text size proportional to default font size 00099 Font.setPointSize(10); // symbol text size fixed at 10 pt 00100 // get the small font size; use the screen-compatible metric 00101 QFontMetrics smallmetrics(Font, 0); 00102 int fHeight = smallmetrics.lineSpacing(); 00103 QString tmp; 00104 int i, PortDistance = 60; 00105 00106 // adjust branch number 00107 int Num = Props.at(1)->Value.toInt(); 00108 if(Num < 1) Num = 1; 00109 else if(Num > 4) { 00110 PortDistance = 40; 00111 if(Num > 8) Num = 8; 00112 } 00113 Props.at(1)->Value = QString::number(Num); 00114 00115 // adjust actual number of properties 00116 int NumProps = (Props.count() - 2) / 2; // current number of properties 00117 if (NumProps < Num) { 00118 for(i = NumProps; i < Num; i++) { 00119 Props.append(new Property("I"+QString::number(i+1), "0", false, 00120 QObject::tr("current equation") + " " +QString::number(i+1))); 00121 Props.append(new Property("Q"+QString::number(i+1), "0", false, 00122 QObject::tr("charge equation") + " " +QString::number(i+1))); 00123 } 00124 } else { 00125 for(i = Num; i < NumProps; i++) { 00126 Props.removeLast(); 00127 Props.removeLast(); 00128 } 00129 } 00130 00131 // adjust property names 00132 Property * p1 = Props.at(2); 00133 for(i = 1; i <= Num; i++) { 00134 p1->Name = "I"+QString::number(i); 00135 p1 = Props.next(); 00136 p1->Name = "Q"+QString::number(i); 00137 p1 = Props.next(); 00138 } 00139 00140 // draw symbol 00141 int h = (PortDistance/2)*((Num-1)) + PortDistance/2; // total component half-height 00142 Lines.append(new Line(-15, -h, 15, -h,QPen(Qt::darkBlue,2))); // top side 00143 Lines.append(new Line( 15, -h, 15, h,QPen(Qt::darkBlue,2))); // right side 00144 Lines.append(new Line(-15, h, 15, h,QPen(Qt::darkBlue,2))); // bottom side 00145 Lines.append(new Line(-15, -h,-15, h,QPen(Qt::darkBlue,2))); // left side 00146 00147 i=0; 00148 int y = PortDistance/2-h, yh; // y is the actual vertical center 00149 while(i<Num) { // for every branch 00150 i++; 00151 // left connection with port 00152 Lines.append(new Line(-30, y,-15, y,QPen(Qt::darkBlue,2))); 00153 Ports.append(new Port(-30, y)); 00154 // small black arrow inside the box 00155 Lines.append(new Line( 7,y-3, 10, y,QPen(Qt::black,1))); 00156 Lines.append(new Line( 7,y+3, 10, y,QPen(Qt::black,1))); 00157 Lines.append(new Line(-10, y, 10, y,QPen(Qt::black,1))); 00158 00159 if (i > 1) { 00160 yh = y-PortDistance/2; // bottom of the branch box 00161 // draw horizontal separation between boxes 00162 Lines.append(new Line(-15, yh, 15, yh, QPen(Qt::darkBlue,2))); 00163 } 00164 // right connection with port 00165 Lines.append(new Line( 15, y, 30, y,QPen(Qt::darkBlue,2))); 00166 Ports.append(new Port( 30, y)); 00167 // add branch number near the right connection port 00168 Texts.append(new Text(25,y-fHeight-2,QString::number(i))); // left-aligned 00169 // move the vertical center down for the next branch 00170 y += PortDistance; 00171 } 00172 00173 x1 = -30; y1 = -h-2; 00174 x2 = 30; y2 = h+2; 00175 // compute component name text position - normal size font 00176 QFontMetrics metrics(QucsSettings.font, 0); // use the screen-compatible metric 00177 tx = x1+4; 00178 ty = y1 - 2*metrics.lineSpacing() - 4; 00179 }