Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pad3bit.cpp
Go to the documentation of this file.
1 /*
2  * pad3bit.cpp - device implementations for pad3bit module
3  *
4  * This is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  */
10 #include <stdlib.h>
11 #include <QtGui>
12 #include "pad3bit.h"
13 #include "node.h"
14 #include "main.h"
15 
17 {
18  Type = isComponent; // Analogue and digital component.
19  Description = QObject::tr ("3bit pattern generator verilog device");
20 
21  Props.append (new Property ("Number", "0", false,
22  QObject::tr ("pad output value")));
23 
24  createSymbol ();
25  tx = x1 + 4;
26  ty = y2 + 4;
27  Model = "pad3bit";
28  Name = "Y";
29 }
30 
32 {
33  pad3bit * p = new pad3bit();
34  p->Props.getFirst()->Value = Props.getFirst()->Value;
35  p->recreate(0);
36  return p;
37 }
38 
39 Element * pad3bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
40 {
41  Name = QObject::tr("3Bit Pattern");
42  BitmapFile = (char *) "pad3bit";
43 
44  if(getNewOne) return new pad3bit();
45  return 0;
46 }
47 
49 {
50  Lines.append(new Line(-60, -50, 30,-50,QPen(Qt::darkGreen,2)));
51  Lines.append(new Line( 30, -50, 30, 30,QPen(Qt::darkGreen,2)));
52  Lines.append(new Line( 30, 30,-60, 30,QPen(Qt::darkGreen,2)));
53  Lines.append(new Line(-60, 30,-60,-50,QPen(Qt::darkGreen,2)));
54 
55  Lines.append(new Line( 40,-30, 30,-30,QPen(Qt::darkGreen,2))); // A
56  Lines.append(new Line( 40,-10, 30,-10,QPen(Qt::darkGreen,2))); // B
57  Lines.append(new Line( 40, 10, 30, 10,QPen(Qt::darkGreen,2))); // C
58 
59  Texts.append(new Text(-58,-33, " 0 1 2 3", Qt::darkGreen, 12.0));
60  Texts.append(new Text(-58, -8, " 4 5 6 7", Qt::darkGreen, 12.0));
61 
62  Ports.append(new Port(40, 10)); // C
63  Ports.append(new Port(40,-10)); // B
64  Ports.append(new Port(40,-30)); // A
65 
66  x1 = -64; y1 = -54;
67  x2 = 40; y2 = 34;
68 }
69 
70 QString pad3bit::vhdlCode( int )
71 {
72  QString v = Props.at(0)->Value;
73  QString s1, s2, s3, s ="";
74 
75  QString A = Ports.at(0)->Connection->Name;
76  QString B = Ports.at(1)->Connection->Name;
77  QString C = Ports.at(2)->Connection->Name;
78 
79  s1 = "\n "+Name+":process\n"+
80  " variable n_" + Name + " : integer := " + v + ";\n" +
81  " begin\n";
82  s2 = " case n_" + Name + " is\n" +
83  " when 0 => "+A+" <= '0'; "+B+" <= '0'; "+C+" <= '0';\n"+
84  " when 1 => "+A+" <= '0'; "+B+" <= '0'; "+C+" <= '1';\n"+
85  " when 2 => "+A+" <= '0'; "+B+" <= '1'; "+C+" <= '0';\n"+
86  " when 3 => "+A+" <= '0'; "+B+" <= '1'; "+C+" <= '1';\n"+
87  " when 4 => "+A+" <= '1'; "+B+" <= '0'; "+C+" <= '0';\n"+
88  " when 5 => "+A+" <= '1'; "+B+" <= '0'; "+C+" <= '1';\n"+
89  " when 6 => "+A+" <= '1'; "+B+" <= '1'; "+C+" <= '0';\n"+
90  " when 7 => "+A+" <= '1'; "+B+" <= '1'; "+C+" <= '1';\n"+
91  " when others => null;\n" +
92  " end case;\n";
93  s3 = " end process;\n";
94  s = s1+s2+s3;
95  return s;
96 }
97 
98 QString pad3bit::verilogCode( int )
99 {
100  QString v = Props.at(0)->Value;
101 
102  QString l = "";
103  QString l1, l2, l3;
104 
105  QString A = Ports.at(0)->Connection->Name;
106  QString B = Ports.at(1)->Connection->Name;
107  QString C = Ports.at(2)->Connection->Name;
108 
109  QString AR = "A_reg" + Name + A;
110  QString BR = "Y_reg" + Name + B;
111  QString CR = "Y_reg" + Name + C;
112 
113  l1 = "\n // "+Name+" 3bit pattern generator\n"+
114  " assign "+A+" = "+AR+";\n"+
115  " reg "+AR+" = 0;\n"+
116  " assign "+B+" = "+BR+";\n"+
117  " reg "+BR+" = 0;\n"+
118  " assign "+C+" = "+CR+";\n"+
119  " reg "+CR+" = 0;\n"+
120  " initial\n" ;
121  l2 = " begin\n"
122  " case ("+v+")\n"+
123  " 0 : begin "+AR+" = 0; "+BR+" = 0; "+CR+" = 0; end\n"+
124  " 1 : begin "+AR+" = 0; "+BR+" = 0; "+CR+" = 1; end\n"+
125  " 2 : begin "+AR+" = 0; "+BR+" = 1; "+CR+" = 0; end\n"+
126  " 3 : begin "+AR+" = 0; "+BR+" = 1; "+CR+" = 1; end\n"+
127  " 4 : begin "+AR+" = 1; "+BR+" = 0; "+CR+" = 0; end\n"+
128  " 5 : begin "+AR+" = 1; "+BR+" = 0; "+CR+" = 1; end\n"+
129  " 6 : begin "+AR+" = 1; "+BR+" = 1; "+CR+" = 0; end\n"+
130  " 7 : begin "+AR+" = 1; "+BR+" = 1; "+CR+" = 1; end\n"+
131  " endcase\n";
132  l3 = " end\n";
133  l = l1+l2+l3;
134  return l;
135 }
Q3PtrList< Line > Lines
Definition: component.h:67
int Type
Definition: element.h:152
int y1
Definition: element.h:153
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: pad3bit.cpp:39
int x1
Definition: element.h:153
Component * newOne()
Definition: pad3bit.cpp:31
QString verilogCode(int)
Definition: pad3bit.cpp:98
Definitions and declarations for the main application.
int ty
Definition: component.h:78
Q3PtrList< Property > Props
Definition: component.h:72
pad3bit()
Definition: pad3bit.cpp:16
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 vhdlCode(int)
Definition: pad3bit.cpp:70
void createSymbol()
Definition: pad3bit.cpp:48
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