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