My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
eqndefined.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  eqndefined.cpp
3  ----------------
4  begin : Thu Apr 19 2007
5  copyright : (C) 2007 by Stefan Jahn
6  email : stefan@lkcc.org
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 "eqndefined.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("equation defined device");
30 
31  Model = "EDD";
32  Name = "D";
33 
34  // first properties !!!
35  Props.append(new Property("Type", "explicit", false,
36  QObject::tr("type of equations")+" [explicit, implicit]"));
37  Props.append(new Property("Branches", "1", false,
38  QObject::tr("number of branches")));
39 
40  // last properties
41  Props.append(new Property("I1", "0", true,
42  QObject::tr("current equation") + " 1"));
43  Props.append(new Property("Q1", "0", false,
44  QObject::tr("charge equation") + " 1"));
45 
46  createSymbol();
47 }
48 
49 // -------------------------------------------------------
51 {
52  EqnDefined* p = new EqnDefined();
53  p->Props.at(0)->Value = Props.at(0)->Value;
54  p->Props.at(1)->Value = Props.at(1)->Value;
55  p->recreate(0);
56  return p;
57 }
58 
59 // -------------------------------------------------------
60 Element* EqnDefined::info(QString& Name, char* &BitmapFile, bool getNewOne)
61 {
62  Name = QObject::tr("Equation Defined Device");
63  BitmapFile = (char *) "edd";
64 
65  if(getNewOne) {
66  EqnDefined* p = new EqnDefined();
67  p->Props.at(0)->Value = "explicit";
68  p->Props.at(1)->Value = "1";
69  p->recreate(0);
70  return p;
71  }
72  return 0;
73 }
74 
75 // -------------------------------------------------------
77 {
78  QString s = Model+":"+Name;
79  QString e = "\n";
80 
81  // output all node names
82  for(Port *p1 = Ports.first(); p1 != 0; p1 = Ports.next())
83  s += " "+p1->Connection->Name; // node names
84 
85  // output all properties
86  Property *p2 = Props.at(2);
87  while(p2) {
88  s += " "+p2->Name+"=\""+Name+"."+p2->Name+"\"";
89  e += " Eqn:Eqn"+Name+p2->Name+" "+
90  Name+"."+p2->Name+"=\""+p2->Value+"\" Export=\"no\"\n";
91  p2 = Props.next();
92  }
93 
94  return s+e;
95 }
96 
97 // -------------------------------------------------------
99 {
100  int i, PortDistance = 60;
101 
102  // adjust branch number
103  int Num = Props.at(1)->Value.toInt();
104  if(Num < 1) Num = 1;
105  else if(Num > 4) {
106  PortDistance = 40;
107  if(Num > 8) Num = 8;
108  }
109  Props.at(1)->Value = QString::number(Num);
110 
111  // adjust property number
112  int NumProps = (Props.count() - 2) / 2;
113  if (NumProps < Num) {
114  for(i = NumProps; i < Num; i++) {
115  Props.append(new Property("I"+QString::number(i+1), "0", false,
116  QObject::tr("current equation") + " " +QString::number(i+1)));
117  Props.append(new Property("Q"+QString::number(i+1), "0", false,
118  QObject::tr("charge equation") + " " +QString::number(i+1)));
119  }
120  } else {
121  for(i = Num; i < NumProps; i++) {
122  Props.removeLast();
123  Props.removeLast();
124  }
125  }
126 
127  // adjust property names
128  Property * p1 = Props.at(2);
129  for(i = 1; i <= Num; i++) {
130  p1->Name = "I"+QString::number(i);
131  p1 = Props.next();
132  p1->Name = "Q"+QString::number(i);
133  p1 = Props.next();
134  }
135 
136  // draw symbol
137  int h = (PortDistance/2)*((Num-1)) + PortDistance/2;
138  Lines.append(new Line(-15, -h, 15, -h,QPen(QPen::darkBlue,2)));
139  Lines.append(new Line( 15, -h, 15, h,QPen(QPen::darkBlue,2)));
140  Lines.append(new Line(-15, h, 15, h,QPen(QPen::darkBlue,2)));
141  Lines.append(new Line(-15, -h,-15, h,QPen(QPen::darkBlue,2)));
142 
143 
144  i=0;
145  int y = PortDistance/2-h, yh;
146  while(i<Num) {
147  i++;
148  Lines.append(new Line(-30, y,-15, y,QPen(QPen::darkBlue,2)));
149  Ports.append(new Port(-30, y));
150 
151  Lines.append(new Line( 7,y-3, 10, y,QPen(QPen::black,1)));
152  Lines.append(new Line( 7,y+3, 10, y,QPen(QPen::black,1)));
153  Lines.append(new Line(-10, y, 10, y,QPen(QPen::black,1)));
154 
155  if (i > 1) {
156  yh = y-PortDistance/2;
157  Lines.append(new Line(-15, yh, 15, yh, QPen(QPen::darkBlue,2)));
158  }
159 
160  Lines.append(new Line( 15, y, 30, y,QPen(QPen::darkBlue,2)));
161  Ports.append(new Port( 30, y));
162  Texts.append(new Text( 19,y-14,QString::number(i)));
163  y += PortDistance;
164  }
165 
166  x1 = -30; y1 = -h-2;
167  x2 = 30; y2 = h+2;
168 
169  QFontMetrics metrics(QucsSettings.font); // get size of text
170  tx = x1+4;
171  ty = y1 - 2*metrics.lineSpacing() - 4;
172 }