Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
andor4x3.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  andor4x3
3  ----------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * andor4x3.cpp - device implementations for andor4x3 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 "andor4x3.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("4x3 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 = "andor4x3";
38  Name = "Y";
39 }
40 
42 {
43  andor4x3 * p = new andor4x3();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * andor4x3::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("4x3 AndOr");
52  BitmapFile = (char *) "andor4x3";
53 
54  if(getNewOne) return new andor4x3();
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, 100,QPen(Qt::darkBlue,2)));
62  Lines.append(new Line( 30, 100,-30,100,QPen(Qt::darkBlue,2)));
63  Lines.append(new Line(-30, 100,-30,-60,QPen(Qt::darkBlue,2)));
64 
65  Lines.append(new Line(-30, -20, 0,-20,QPen(Qt::darkBlue,2)));
66  Lines.append(new Line(-30, 20, 0, 20,QPen(Qt::darkBlue,2)));
67  Lines.append(new Line(-30, 60, 0, 60,QPen(Qt::darkBlue,2)));
68  Lines.append(new Line( 0, -60, 0,100,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 
74  Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2))); //A21
75  Lines.append(new Line(-50, 0,-30, 0,QPen(Qt::darkBlue,2))); //A22
76  Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2))); //A23
77 
78  Lines.append(new Line(-50, 30, -30, 30,QPen(Qt::darkBlue,2))); //A31
79  Lines.append(new Line(-50, 40, -30, 40,QPen(Qt::darkBlue,2))); //A32
80  Lines.append(new Line(-50, 50,-30, 50,QPen(Qt::darkBlue,2))); //A33
81 
82  Lines.append(new Line(-50, 70, -30, 70,QPen(Qt::darkBlue,2))); //A41
83  Lines.append(new Line(-50, 80, -30, 80,QPen(Qt::darkBlue,2))); //A42
84  Lines.append(new Line(-50, 90,-30, 90,QPen(Qt::darkBlue,2))); //A43
85 
86  Lines.append(new Line( 30, 20, 50, 20,QPen(Qt::darkBlue,2))); //Y
87 
88  Texts.append(new Text( -20, -60, "&", Qt::darkBlue, 12.0));
89  Texts.append(new Text( -20, -20, "&", Qt::darkBlue, 12.0));
90  Texts.append(new Text( -20, 20, "&", Qt::darkBlue, 12.0));
91  Texts.append(new Text( -20, 60, "&", Qt::darkBlue, 12.0));
92 
93  Lines.append(new Line( 7, -45, 17, -40,QPen(Qt::darkBlue,2)));
94  Lines.append(new Line( 7, -35, 17, -40,QPen(Qt::darkBlue,2)));
95  Lines.append(new Line( 7, -30, 17, -35,QPen(Qt::darkBlue,2)));
96  Lines.append(new Line( 22, -30, 22, -45,QPen(Qt::darkBlue,2)));
97 
98  Ports.append(new Port(-50,-50)); // A11
99  Ports.append(new Port(-50,-40)); // A12
100  Ports.append(new Port(-50,-30)); // A13
101 
102  Ports.append(new Port(-50,-10)); // A21
103  Ports.append(new Port(-50, 0)); // A22
104  Ports.append(new Port(-50, 10)); // A23
105 
106  Ports.append(new Port(-50, 30)); // A31
107  Ports.append(new Port(-50, 40)); // A32
108  Ports.append(new Port(-50, 50)); // A33
109 
110  Ports.append(new Port(-50, 70)); // A41
111  Ports.append(new Port(-50, 80)); // A42
112  Ports.append(new Port(-50, 90)); // A43
113 
114  Ports.append(new Port( 50, 20)); // Y
115 
116  x1 = -50; y1 = -64;
117  x2 = 50; y2 = 104;
118 
119 }
120 
121 QString andor4x3::vhdlCode( int )
122 {
123  QString s="";
124 
125  QString td = Props.at(1)->Value; // delay time
126  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
127  td += ";\n";
128 
129  QString a11 = Ports.at(0)->Connection->Name;
130  QString a12 = Ports.at(1)->Connection->Name;
131  QString a13 = Ports.at(2)->Connection->Name;
132  QString a21 = Ports.at(3)->Connection->Name;
133  QString a22 = Ports.at(4)->Connection->Name;
134  QString a23 = Ports.at(5)->Connection->Name;
135  QString a31 = Ports.at(6)->Connection->Name;
136  QString a32 = Ports.at(7)->Connection->Name;
137  QString a33 = Ports.at(8)->Connection->Name;
138  QString a41 = Ports.at(9)->Connection->Name;
139  QString a42 = Ports.at(10)->Connection->Name;
140  QString a43 = Ports.at(11)->Connection->Name;
141  QString y = Ports.at(12)->Connection->Name;
142 
143  s = "\n " + Name + ":process (" +
144  a11 + ", " + a12 + ", " + a13 + ", " +
145  a21 + ", " + a22 + ", " + a23 + ", " +
146  a31 + ", " + a32 + ", " + a33 + ", " +
147  a41 + ", " + a42 + ", " + a43 +")\n" +
148  " begin\n " +
149  y + " <= " + "(" + a11 + " and " + a12 + " and " + a13 + ") or " +
150  "(" + a21 + " and " + a22 + " and " + a23 + ") or\n" +
151  " (" + a31 + " and " + a32 + " and " + a33 + ") or " +
152  "(" + a41 + " and " + a42 + " and " + a43 + ")" + td +
153  " end process;\n";
154  return s;
155 }
156 
157 QString andor4x3::verilogCode( int )
158 {
159  QString td = Props.at(1)->Value; // delay time
160  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
161 
162  QString l = "";
163 
164  QString a11 = Ports.at(0)->Connection->Name;
165  QString a12 = Ports.at(1)->Connection->Name;
166  QString a13 = Ports.at(2)->Connection->Name;
167  QString a21 = Ports.at(3)->Connection->Name;
168  QString a22 = Ports.at(4)->Connection->Name;
169  QString a23 = Ports.at(5)->Connection->Name;
170  QString a31 = Ports.at(6)->Connection->Name;
171  QString a32 = Ports.at(7)->Connection->Name;
172  QString a33 = Ports.at(8)->Connection->Name;
173  QString a41 = Ports.at(9)->Connection->Name;
174  QString a42 = Ports.at(10)->Connection->Name;
175  QString a43 = Ports.at(11)->Connection->Name;
176  QString y = Ports.at(12)->Connection->Name;
177 
178  QString v = "net_reg" + Name + y;
179 
180  l = "\n // " + Name + " 4x3 andor\n" +
181  " assign " + y + " = " + v + ";\n" +
182  " reg " + v + " = 0;\n" +
183  " always @ (" + a11 + " or " + a12 + " or " + a13 + " or "
184  + a21 + " or " + a22 + " or " + a23 + " or "
185  + a31 + " or " + a32 + " or " + a33 + " or "
186  + a41 + " or " + a42 + " or " + a43 + ")\n " +
187  " " + v + " <=" + td + " (" + a11 + " && " + a12 + " && " + a13 +")" + " || " +
188  "(" + a21 + " && " + a22 + " && " + a23 +")" + " ||\n" +
189  " (" + a31 + " && " + a32 + " && " + a33 +")" + " || " +
190  "(" + a41 + " && " + a42 + " && " + a43 +");\n " ;
191 
192  return l;
193 }
194 
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
QString verilogCode(int)
Definition: andor4x3.cpp:157
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
QString vhdlCode(int)
Definition: andor4x3.cpp:121
Q3PtrList< Property > Props
Definition: component.h:72
andor4x3()
Definition: andor4x3.cpp:23
Definition: element.h:82
void createSymbol()
Definition: andor4x3.cpp:58
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
Component * newOne()
Definition: andor4x3.cpp:41
Q3PtrList< Port > Ports
Definition: component.h:70
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: andor4x3.cpp:49
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
#define isComponent
Definition: element.h:110
int x2
Definition: element.h:153
virtual void recreate(Schematic *)
Definition: component.h:39