-
Notifications
You must be signed in to change notification settings - Fork 2
/
Select.cpp
105 lines (87 loc) · 2.25 KB
/
Select.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Select.h"
#include"ApplicationManager.h"
#include"Defs.H"
#include"Components/Component.h"
#include"..\Components\Switch.h"
//constructor
Select::Select(ApplicationManager* pApp, Component*& ComponentPassed, GraphicsInfo& r_GfxInfo, MODE r_mode) :Action(pApp), CompSelected(ComponentPassed)
{
this->r_GInfo = r_GfxInfo;
m_mode = r_mode;
}
//destructor
Select::~Select(void)
{
}
//Reads parameters required for action to execute
void Select::ReadActionParameters()
{
//Get a Pointer to the Input / Output Interfaces
Output* pOut = pManager->GetOutput();
Input* pIn = pManager->GetInput();
//Print Action Message
if(m_mode == DESIGN)
pOut->PrintMsg("Click on the component you want to select");
else
pOut->PrintMsg("Click on a switch to change state");
//Wait for User Input
pIn->GetPointClicked(x, y);
//Clear Status Bar
pOut->ClearStatusBar();
//check if the click is inside area of any componenet
CompSelected = pManager->getComponent(x, y, m_GfxInfo);
}
//Execute action (code depends on action type)
void Select::Execute()
{
//Get the location of the click
ReadActionParameters();
//make IsSelected true if initilay false
//make IsSelected false if initilay true
Output* pOut = pManager->GetOutput();
if (CompSelected)
{
if (m_mode == DESIGN)
{
if (CompSelected->getIsSelected())
{
pOut->PrintMsg("Component is Unselected");
CompSelected->setIsSelected(false);
CompSelected = NULL;
}
else
{
pOut->PrintMsg("Component is Selected");
pManager->UnselectOtherComponents(CompSelected);
CompSelected->setIsSelected(true);
}
}
else if (m_mode == SIMULATION)
{
Component* Selected_switch = CompSelected;
if (dynamic_cast<Switch*>(Selected_switch))
{
if ( ((Switch*)Selected_switch)->GetOutPinStatus() == LOW )
{
pOut->PrintMsg("Switch set to High");
((Switch*)Selected_switch)->Setswitch(HIGH);
}
else
{
pOut->PrintMsg("Switch set to Low");
((Switch*)Selected_switch)->Setswitch(LOW);
}
}
else
{
pOut->PrintMsg("You can NOT select a component in simulation mode");
}
}
}
}
//To undo this action (code depends on action type)
void Select::Undo()
{}
//To redo this action (code depends on action type)
void Select::Redo()
{}