Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
switch.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  switch.cpp
3  ------------
4  begin : Sat Feb 25 2006
5  copyright : (C) 2006 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
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 "switch.h"
19 #include "node.h"
20 #include "schematic.h"
21 
22 
24 {
25  Description = QObject::tr("switch (time controlled)");
26 
27  Props.append(new Property("init", "off", false,
28  QObject::tr("initial state")+" [on, off]"));
29  Props.append(new Property("time", "1 ms", false,
30  QObject::tr("time when state changes (semicolon separated list possible, even numbered lists are repeated)")));
31  Props.append(new Property("Ron", "0", false,
32  QObject::tr("resistance of \"on\" state in ohms")));
33  Props.append(new Property("Roff", "1e12", false,
34  QObject::tr("resistance of \"off\" state in ohms")));
35  Props.append(new Property("Temp", "26.85", false,
36  QObject::tr("simulation temperature in degree Celsius")));
37  Props.append(new Property("MaxDuration", "1e-6", false,
38  QObject::tr("Max possible switch transition time (transition time 1/100 smallest value in 'time', or this number)")));
39 
40  createSymbol();
41  tx = x1+4;
42  ty = y2+4;
43  Model = "Switch";
44  Name = "S";
45 }
46 
47 // -------------------------------------------------------
49 {
50  Switch *p = new Switch();
51  p->Props.getFirst()->Value = Props.getFirst()->Value;
52  p->recreate(0);
53  return p;
54 }
55 
56 // -------------------------------------------------------
57 Element* Switch::info(QString& Name, char* &BitmapFile, bool getNewOne)
58 {
59  Name = QObject::tr("Switch");
60  BitmapFile = (char *) "switch";
61 
62  if(getNewOne) return new Switch();
63  return 0;
64 }
65 
66 // -------------------------------------------------------
67 QString Switch::netlist()
68 {
69  QString s = Model+":"+Name;
70 
71  // output all node names
72  s += " "+Ports.first()->Connection->Name;
73  s += " "+Ports.next()->Connection->Name;
74 
75  // output all properties
76  Property *p2 = Props.first();
77  s += " "+p2->Name+"=\""+p2->Value+"\"";
78  p2 = Props.next();
79  s += " "+p2->Name+"=\"["+p2->Value+"]\"";
80  for(p2 = Props.next(); p2 != 0; p2 = Props.next())
81  s += " "+p2->Name+"=\""+p2->Value+"\"";
82 
83  return s + '\n';
84 }
85 
86 // -------------------------------------------------------
88 {
89  if(Props.getFirst()->Value != "on") {
90  Lines.append(new Line(-15, 0, 15,-15,QPen(Qt::darkBlue,2)));
91  y1 = -17;
92  }
93  else {
94  Lines.append(new Line(-15, 0, 16,-5,QPen(Qt::darkBlue,2)));
95  y1 = -7;
96  }
97 
98  Lines.append(new Line(-30, 0,-15, 0,QPen(Qt::darkBlue,2)));
99  Lines.append(new Line( 17, 0, 30, 0,QPen(Qt::darkBlue,2)));
100  Arcs.append(new Arc( 12, -3, 5, 5, 0, 16*360,QPen(Qt::darkBlue,2)));
101  Ellips.append(new Area(-18, -3, 6, 6, QPen(Qt::darkBlue,2),
102  QBrush(Qt::darkBlue, Qt::SolidPattern)));
103 
104  Ports.append(new Port(-30, 0));
105  Ports.append(new Port( 30, 0));
106 
107  x1 = -30;
108  x2 = 30; y2 = 7;
109 }
Q3PtrList< Line > Lines
Definition: component.h:67
Component * newOne()
Definition: switch.cpp:48
Definition: element.h:55
int y1
Definition: element.h:153
Q3PtrList< struct Arc > Arcs
Definition: component.h:68
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
int ty
Definition: component.h:78
QString Value
Definition: element.h:97
Definition: switch.h:24
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: switch.cpp:57
Q3PtrList< Property > Props
Definition: component.h:72
Definition: element.h:63
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
QString Model
Definition: component.h:80
void createSymbol()
Definition: switch.cpp:87
QString Description
Definition: component.h:81
QString netlist()
Definition: switch.cpp:67
Q3PtrList< Area > Ellips
Definition: component.h:69
int x2
Definition: element.h:153
Switch()
Definition: switch.cpp:23