Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
andor4x4.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  andor4x4
3  ----------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * andor4x4.cpp - device implementations for andor4x4 module
11  *
12  * This is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2, or (at your option)
15  * any later version.
16  *
17  */
18 #include <QtGui>
19 #include "andor4x4.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("4x4 andor verilog device");
27 
28  Props.append (new Property ("TR", "6", false,
29  QObject::tr ("transfer function high scaling factor")));
30  Props.append (new Property ("Delay", "1 ns", false,
31  QObject::tr ("output delay")
32  +" ("+QObject::tr ("s")+")"));
33 
34  createSymbol ();
35  tx = x1 + 19;
36  ty = y2 + 4;
37  Model = "andor4x4";
38  Name = "Y";
39 }
40 
42 {
43  andor4x4 * p = new andor4x4();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * andor4x4::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("4x4 AndOr");
52  BitmapFile = (char *) "andor4x4";
53 
54  if(getNewOne) return new andor4x4();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-30, -60, 30,-60,QPen(Qt::darkBlue,2)));
61  Lines.append(new Line( 30, -60, 30, 140,QPen(Qt::darkBlue,2)));
62  Lines.append(new Line( 30, 140,-30,140,QPen(Qt::darkBlue,2)));
63  Lines.append(new Line(-30, 140,-30,-60,QPen(Qt::darkBlue,2)));
64 
65  Lines.append(new Line(-30, -10, 0,-10,QPen(Qt::darkBlue,2)));
66  Lines.append(new Line(-30, 40, 0, 40,QPen(Qt::darkBlue,2)));
67  Lines.append(new Line(-30, 90, 0, 90,QPen(Qt::darkBlue,2)));
68  Lines.append(new Line( 0, -60, 0,140,QPen(Qt::darkBlue,2)));
69 
70  Lines.append(new Line(-50,-50,-30,-50,QPen(Qt::darkBlue,2))); //A11
71  Lines.append(new Line(-50,-40,-30,-40,QPen(Qt::darkBlue,2))); //A12
72  Lines.append(new Line(-50,-30,-30,-30,QPen(Qt::darkBlue,2))); //A13
73  Lines.append(new Line(-50,-20,-30,-20,QPen(Qt::darkBlue,2))); //A14
74 
75  Lines.append(new Line(-50, 0,-30, 0,QPen(Qt::darkBlue,2))); //A21
76  Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2))); //A22
77  Lines.append(new Line(-50, 20,-30, 20,QPen(Qt::darkBlue,2))); //A23
78  Lines.append(new Line(-50, 30,-30, 30,QPen(Qt::darkBlue,2))); //A24
79 
80  Lines.append(new Line(-50, 50, -30, 50,QPen(Qt::darkBlue,2))); //A31
81  Lines.append(new Line(-50, 60, -30, 60,QPen(Qt::darkBlue,2))); //A32
82  Lines.append(new Line(-50, 70,-30, 70,QPen(Qt::darkBlue,2))); //A33
83  Lines.append(new Line(-50, 80, -30, 80,QPen(Qt::darkBlue,2))); //A34
84 
85  Lines.append(new Line(-50, 100,-30,100,QPen(Qt::darkBlue,2))); //A41
86  Lines.append(new Line(-50, 110,-30,110,QPen(Qt::darkBlue,2))); //A42
87  Lines.append(new Line(-50, 120,-30,120,QPen(Qt::darkBlue,2))); //A43
88  Lines.append(new Line(-50, 130,-30,130,QPen(Qt::darkBlue,2))); //A44
89 
90  Lines.append(new Line( 30, 40, 50, 40,QPen(Qt::darkBlue,2))); //Y
91 
92  Texts.append(new Text( -20, -60, "&", Qt::darkBlue, 12.0));
93  Texts.append(new Text( -20, -10, "&", Qt::darkBlue, 12.0));
94  Texts.append(new Text( -20, 40, "&", Qt::darkBlue, 12.0));
95  Texts.append(new Text( -20, 90, "&", Qt::darkBlue, 12.0));
96 
97  Lines.append(new Line( 7, -45, 17, -40,QPen(Qt::darkBlue,2)));
98  Lines.append(new Line( 7, -35, 17, -40,QPen(Qt::darkBlue,2)));
99  Lines.append(new Line( 7, -30, 17, -35,QPen(Qt::darkBlue,2)));
100  Lines.append(new Line( 22, -30, 22, -45,QPen(Qt::darkBlue,2)));
101 
102  Ports.append(new Port(-50,-50)); // A11
103  Ports.append(new Port(-50,-40)); // A12
104  Ports.append(new Port(-50,-30)); // A13
105  Ports.append(new Port(-50,-20)); // A14
106 
107  Ports.append(new Port(-50, 0)); // A21
108  Ports.append(new Port(-50, 10)); // A22
109  Ports.append(new Port(-50, 20)); // A23
110  Ports.append(new Port(-50, 30)); // A24
111 
112  Ports.append(new Port(-50, 50)); // A31
113  Ports.append(new Port(-50, 60)); // A32
114  Ports.append(new Port(-50, 70)); // A33
115  Ports.append(new Port(-50, 80)); // A34
116 
117  Ports.append(new Port(-50,100)); // A41
118  Ports.append(new Port(-50,110)); // A42
119  Ports.append(new Port(-50,120)); // A43
120  Ports.append(new Port(-50,130)); // A44
121 
122  Ports.append(new Port( 50, 40)); // Y
123 
124  x1 = -50; y1 = -64;
125  x2 = 50; y2 = 144;
126 }
127 
128 QString andor4x4::vhdlCode( int )
129 {
130  QString s="";
131 
132  QString td = Props.at(1)->Value; // delay time
133  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
134  td += ";\n";
135 
136  QString a11 = Ports.at(0)->Connection->Name;
137  QString a12 = Ports.at(1)->Connection->Name;
138  QString a13 = Ports.at(2)->Connection->Name;
139  QString a14 = Ports.at(3)->Connection->Name;
140  QString a21 = Ports.at(4)->Connection->Name;
141  QString a22 = Ports.at(5)->Connection->Name;
142  QString a23 = Ports.at(6)->Connection->Name;
143  QString a24 = Ports.at(7)->Connection->Name;
144  QString a31 = Ports.at(8)->Connection->Name;
145  QString a32 = Ports.at(9)->Connection->Name;
146  QString a33 = Ports.at(10)->Connection->Name;
147  QString a34 = Ports.at(11)->Connection->Name;
148  QString a41 = Ports.at(12)->Connection->Name;
149  QString a42 = Ports.at(13)->Connection->Name;
150  QString a43 = Ports.at(14)->Connection->Name;
151  QString a44 = Ports.at(15)->Connection->Name;
152 
153  QString y = Ports.at(16)->Connection->Name;
154 
155  s = "\n " + Name + ":process (" +
156  a11 + ", " + a12 + ", " + a13 + ", " + a14 + ", " +
157  a21 + ", " + a22 + ", " + a23 + ", " + a24 + ", " +
158  a31 + ", " + a32 + ", " + a33 + ", " + a34 + ", " +
159  a41 + ", " + a42 + ", " + a43 + ", " + a44 + ")\n" +
160  " begin\n " +
161  y + " <= " + "(" + a11 + " and " + a12 + " and " + a13 + " and " + a14 + ") or " +
162  "(" + a21 + " and " + a22 + " and " + a23 + " and " + a24 + ") or\n" +
163  " (" + a31 + " and " + a32 + " and " + a33 + " and " + a34 + ") or " +
164  "(" + a41 + " and " + a42 + " and " + a43 + " and " + a43 + ")" + td +
165  " end process;\n";
166  return s;
167 }
168 
169 QString andor4x4::verilogCode( int )
170 {
171  QString td = Props.at(1)->Value; // delay time
172  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
173 
174  QString a11 = Ports.at(0)->Connection->Name;
175  QString a12 = Ports.at(1)->Connection->Name;
176  QString a13 = Ports.at(2)->Connection->Name;
177  QString a14 = Ports.at(3)->Connection->Name;
178  QString a21 = Ports.at(4)->Connection->Name;
179  QString a22 = Ports.at(5)->Connection->Name;
180  QString a23 = Ports.at(6)->Connection->Name;
181  QString a24 = Ports.at(7)->Connection->Name;
182  QString a31 = Ports.at(8)->Connection->Name;
183  QString a32 = Ports.at(9)->Connection->Name;
184  QString a33 = Ports.at(10)->Connection->Name;
185  QString a34 = Ports.at(11)->Connection->Name;
186  QString a41 = Ports.at(12)->Connection->Name;
187  QString a42 = Ports.at(13)->Connection->Name;
188  QString a43 = Ports.at(14)->Connection->Name;
189  QString a44 = Ports.at(15)->Connection->Name;
190 
191  QString y = Ports.at(16)->Connection->Name;
192 
193  QString l = "";
194 
195  QString v = "net_reg" + Name + y;
196 
197  l = "\n // " + Name + " 4x4 andor\n" +
198  " assign " + y + " = " + v + ";\n" +
199  " reg " + v + " = 0;\n" +
200  " always @ (" + a11 + " or " + a12 + " or " + a13 + " or " + a14 + " or "
201  + a21 + " or " + a22 + " or " + a23 + " or " + a24 + " or "
202  + a31 + " or " + a32 + " or " + a33 + " or " + a34 + " or "
203  + a41 + " or " + a42 + " or " + a43 + " or " + a44 + ")\n " +
204  " " + v + " <=" + td + " (" + a11 + " && " + a12 + " && " + a13 + " && " + a14 +")" + " || " +
205  "(" + a21 + " && " + a22 + " && " + a23 + " && " + a24 +")" + " ||\n" +
206  " (" + a31 + " && " + a32 + " && " + a33 + " && " + a34 +")" + " || " +
207  "(" + a41 + " && " + a42 + " && " + a43 + " && " + a44 +");\n" ;
208  return l;
209 }
210 
Q3PtrList< Line > Lines
Definition: component.h:67
int Type
Definition: element.h:152
int y1
Definition: element.h:153
bool VHDL_Delay(QString &td, const QString &Name)
Definition: main.cpp:493
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
bool Verilog_Delay(QString &td, const QString &Name)
Definition: main.cpp:555
Definitions and declarations for the main application.
int ty
Definition: component.h:78
Q3PtrList< Property > Props
Definition: component.h:72
andor4x4()
Definition: andor4x4.cpp:23
QString vhdlCode(int)
Definition: andor4x4.cpp:128
Definition: element.h:82
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
void createSymbol()
Definition: andor4x4.cpp:58
Q3PtrList< Port > Ports
Definition: component.h:70
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: andor4x4.cpp:41
#define isComponent
Definition: element.h:110
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: andor4x4.cpp:49
int x2
Definition: element.h:153
QString verilogCode(int)
Definition: andor4x4.cpp:169
virtual void recreate(Schematic *)
Definition: component.h:39