Qucs-GUI  0.0.18
 All Data Structures 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 #include <QtGui>
18 #include "eqndefined.h"
19 #include "main.h"
20 #include "schematic.h"
21 
22 #include <QFileInfo>
23 
24 
26 {
27  Description = QObject::tr("equation defined device");
28 
29  Model = "EDD";
30  Name = "D";
31 
32  // first properties !!!
33  Props.append(new Property("Type", "explicit", false,
34  QObject::tr("type of equations")+" [explicit, implicit]"));
35  Props.append(new Property("Branches", "1", false,
36  QObject::tr("number of branches")));
37 
38  // last properties
39  Props.append(new Property("I1", "0", true,
40  QObject::tr("current equation") + " 1"));
41  Props.append(new Property("Q1", "0", false,
42  QObject::tr("charge equation") + " 1"));
43 
44  createSymbol();
45 }
46 
47 // -------------------------------------------------------
49 {
50  EqnDefined* p = new EqnDefined();
51  p->Props.at(0)->Value = Props.at(0)->Value;
52  p->Props.at(1)->Value = Props.at(1)->Value;
53  p->recreate(0);
54  return p;
55 }
56 
57 // -------------------------------------------------------
58 Element* EqnDefined::info(QString& Name, char* &BitmapFile, bool getNewOne)
59 {
60  Name = QObject::tr("Equation Defined Device");
61  BitmapFile = (char *) "edd";
62 
63  if(getNewOne) {
64  EqnDefined* p = new EqnDefined();
65  p->Props.at(0)->Value = "explicit";
66  p->Props.at(1)->Value = "1";
67  p->recreate(0);
68  return p;
69  }
70  return 0;
71 }
72 
73 // -------------------------------------------------------
75 {
76  QString s = Model+":"+Name;
77  QString e = "\n";
78 
79  // output all node names
80  for(Port *p1 = Ports.first(); p1 != 0; p1 = Ports.next())
81  s += " "+p1->Connection->Name; // node names
82 
83  // output all properties
84  Property *p2 = Props.at(2);
85  while(p2) {
86  s += " "+p2->Name+"=\""+Name+"."+p2->Name+"\"";
87  e += " Eqn:Eqn"+Name+p2->Name+" "+
88  Name+"."+p2->Name+"=\""+p2->Value+"\" Export=\"no\"\n";
89  p2 = Props.next();
90  }
91 
92  return s+e;
93 }
94 
95 // -------------------------------------------------------
97 {
98  int i, PortDistance = 60;
99 
100  // adjust branch number
101  int Num = Props.at(1)->Value.toInt();
102  if(Num < 1) Num = 1;
103  else if(Num > 4) {
104  PortDistance = 40;
105  if(Num > 8) Num = 8;
106  }
107  Props.at(1)->Value = QString::number(Num);
108 
109  // adjust property number
110  int NumProps = (Props.count() - 2) / 2;
111  if (NumProps < Num) {
112  for(i = NumProps; i < Num; i++) {
113  Props.append(new Property("I"+QString::number(i+1), "0", false,
114  QObject::tr("current equation") + " " +QString::number(i+1)));
115  Props.append(new Property("Q"+QString::number(i+1), "0", false,
116  QObject::tr("charge equation") + " " +QString::number(i+1)));
117  }
118  } else {
119  for(i = Num; i < NumProps; i++) {
120  Props.removeLast();
121  Props.removeLast();
122  }
123  }
124 
125  // adjust property names
126  Property * p1 = Props.at(2);
127  for(i = 1; i <= Num; i++) {
128  p1->Name = "I"+QString::number(i);
129  p1 = Props.next();
130  p1->Name = "Q"+QString::number(i);
131  p1 = Props.next();
132  }
133 
134  // draw symbol
135  int h = (PortDistance/2)*((Num-1)) + PortDistance/2;
136  Lines.append(new Line(-15, -h, 15, -h,QPen(Qt::darkBlue,2)));
137  Lines.append(new Line( 15, -h, 15, h,QPen(Qt::darkBlue,2)));
138  Lines.append(new Line(-15, h, 15, h,QPen(Qt::darkBlue,2)));
139  Lines.append(new Line(-15, -h,-15, h,QPen(Qt::darkBlue,2)));
140 
141 
142  i=0;
143  int y = PortDistance/2-h, yh;
144  while(i<Num) {
145  i++;
146  Lines.append(new Line(-30, y,-15, y,QPen(Qt::darkBlue,2)));
147  Ports.append(new Port(-30, y));
148 
149  Lines.append(new Line( 7,y-3, 10, y,QPen(Qt::black,1)));
150  Lines.append(new Line( 7,y+3, 10, y,QPen(Qt::black,1)));
151  Lines.append(new Line(-10, y, 10, y,QPen(Qt::black,1)));
152 
153  if (i > 1) {
154  yh = y-PortDistance/2;
155  Lines.append(new Line(-15, yh, 15, yh, QPen(Qt::darkBlue,2)));
156  }
157 
158  Lines.append(new Line( 15, y, 30, y,QPen(Qt::darkBlue,2)));
159  Ports.append(new Port( 30, y));
160  Texts.append(new Text( 19,y-14,QString::number(i)));
161  y += PortDistance;
162  }
163 
164  x1 = -30; y1 = -h-2;
165  x2 = 30; y2 = h+2;
166 
167  QFontMetrics metrics(QucsSettings.font); // get size of text
168  tx = x1+4;
169  ty = y1 - 2*metrics.lineSpacing() - 4;
170 }
Q3PtrList< Line > Lines
Definition: component.h:67
QString netlist()
Definition: eqndefined.cpp:74
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: eqndefined.cpp:58
int y1
Definition: element.h:153
QFont font
Definition: main.h:46
tQucsSettings QucsSettings
Definition: main.cpp:52
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
void createSymbol()
Definition: eqndefined.cpp:96
Definitions and declarations for the main application.
int ty
Definition: component.h:78
Q3PtrList< Property > Props
Definition: component.h:72
Definition: element.h:82
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
void recreate(Schematic *)
Definition: component.cpp:1250
Q3PtrList< Port > Ports
Definition: component.h:70
QString Name
Definition: element.h:97
QString Name
Definition: component.h:80
Q3PtrList< Text > Texts
Definition: component.h:71
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
Component * newOne()
Definition: eqndefined.cpp:48
int x2
Definition: element.h:153