-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAddNORgate2.cpp
More file actions
90 lines (71 loc) · 1.76 KB
/
Copy pathAddNORgate2.cpp
File metadata and controls
90 lines (71 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "AddNORgate2.h"
#include "ApplicationManager.h"
#include "NOR2.h"
AddNORgate2::AddNORgate2(ApplicationManager* pApp) :Action(pApp)
{
loaded = false;
}
AddNORgate2::AddNORgate2(ApplicationManager *pApp ,bool l ,int cx ,int cy) : Action(pApp)
{
loaded = l;
Cx = cx; Cy = cy;
}
AddNORgate2::~AddNORgate2(void)
{
}
void AddNORgate2::ReadActionParameters()
{
//Get a Pointer to the Input / Output Interfaces
Output* pOut = pManager->GetOutput();
Input* pIn = pManager->GetInput();
if (loaded == false)
{
//Print Action Message
pOut->PrintMsg("2-Input NOR Gate: Click to add the gate");
//Wait for User Input
pIn->GetPointClicked(Cx, Cy);
//Clear Status Bar
pOut->ClearStatusBar();
}
}
bool AddNORgate2::Execute()
{
//Get Center point of the Gate
ReadActionParameters();
Output *pOut = pManager->GetOutput();
//Calculate the rectangle Corners
int Len = UI.NOR2_Width;
int Wdth = UI.NOR2_Height;
GraphicsInfo GInfo; //Gfx info to be used to construct the gate
GInfo.x1 = Cx - Len / 2;
GInfo.x2 = Cx + Len / 2;
GInfo.y1 = Cy - Wdth / 2;
GInfo.y2 = Cy + Wdth / 2;
if (pManager->CanDraw(Cx ,Cy))
{
NOR2 *pA = new NOR2(GInfo ,NOR2_FANOUT);
pManager->AddComponent(GInfo ,pA);
}
else
pOut->PrintMsg("invalid location please tryagain ");
return true;
}
void AddNORgate2::Undo()
{
Output *pOut = pManager->GetOutput();
pManager->SelectComponent(Cx ,Cy);
pManager->DeleteComp();
}
void AddNORgate2::Redo()
{
Output *pOut = pManager->GetOutput();
int Len = UI.AND2_Width;
int Wdth = UI.AND2_Height;
GraphicsInfo GInfo; //Gfx info to be used to construct the gate
GInfo.x1 = Cx - Len / 2;
GInfo.x2 = Cx + Len / 2;
GInfo.y1 = Cy - Wdth / 2;
GInfo.y2 = Cy + Wdth / 2;
NOR2 *pA = new NOR2(GInfo ,AND2_FANOUT);
pManager->AddComponent(GInfo ,pA);
}