Skip to content

Commit

Permalink
Uploading the project
Browse files Browse the repository at this point in the history
  • Loading branch information
MUSTAFA-Hamzawy committed Jul 26, 2022
1 parent 77c4d65 commit 1202b74
Show file tree
Hide file tree
Showing 279 changed files with 26,421 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Actions/Action.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _ACTION_H
#define _ACTION_H

class ApplicationManager; //forward class declaration


//Base class for all possible actions (abstract class)
class Action
{
protected:
ApplicationManager *pManager; //Actions needs AppMngr to do their job
public:
Action(ApplicationManager *pApp) { pManager = pApp; } //constructor

//Reads parameters required for action to execute
virtual void ReadActionParameters()=0;

//Execute action (code depends on action type)
virtual void Execute()=0;

//To undo this action (code depends on action type)
virtual void Undo()=0;

//To redo this action (code depends on action type)
virtual void Redo()=0;

};

#endif
87 changes: 87 additions & 0 deletions Actions/ActionLabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "../Actions/ActionLabel.h"
#include "..\ApplicationManager.h"

ActionLabel::ActionLabel(ApplicationManager* pApp) :Action(pApp)
{
test = true;
comp = NULL;
}

ActionLabel::~ActionLabel(void)
{

}

void ActionLabel::ReadActionParameters()
{
//Get a Pointer to the Input / Output Interfaces
Output* pOut = pManager->GetOutput();
Input* pIn = pManager->GetInput();

//Print Action Message
pOut->PrintMsg("click on the item that you want to label (if wire click on its srcPin or DstPin)");

//Wait for User Input
pIn->GetPointClicked(Cx, Cy);
int i;
if (pManager->isExist(Cx, Cy, i))
{
comp = pManager->getComponent(i);
if (comp->isLabeld())
{
pOut->PrintMsg("This component has already been labeled (we suggest to click on edit from tool bar)");
test = false;
}
}
else
{
pOut->PrintMsg("Failed, It is not a component. try again accurately");
test = false;
}
}

void ActionLabel::Execute()
{
//Get Center point of the Gate
ReadActionParameters();

if (test)
{
Output* pOut = pManager->GetOutput();
Input* pIn = pManager->GetInput();
GraphicsInfo gfx;
Gate* g;
Connection* c;
if (comp)
{
g = dynamic_cast<Gate*>(comp);
c = dynamic_cast<Connection*>(comp);
string InputText = "empty";
if (g)
{
gfx = comp->getGxfInfo();
InputText = pIn->GetSrting(pOut, "Write Here : ", gfx.x1, gfx.y1 - (0.5 * UI.AND2_Height + 5));
}
else if (c)
{
gfx = comp->getGxfInfo();
InputText = pIn->GetSrting(pOut, "Write Here : ", ((gfx.x1 + gfx.x2) / 2.0), gfx.y1 - (0.5 * UI.AND2_Height + 2));
}
comp->setLabel(InputText);
}
}
else
{
return;
}



}

void ActionLabel::Undo()
{}

void ActionLabel::Redo()
{}

28 changes: 28 additions & 0 deletions Actions/ActionLabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef _ACTIONLABEL_H
#define _ACTIONLABEL_H

#include "action.h"
#include "../Components/Component.h"
class ActionLabel : public Action
{

private:
int Cx, Cy; //Two corners of the start and end of wire
bool test; // to validate that ReadActionParameters has no problem
Component* comp;
public:
ActionLabel(ApplicationManager* pApp);
virtual ~ActionLabel(void);

//Reads parameters required for action to execute
virtual void ReadActionParameters();
//Execute action (code depends on action type)
virtual void Execute();

virtual void Undo();
virtual void Redo();


};

#endif
67 changes: 67 additions & 0 deletions Actions/AddANDgate2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "AddANDgate2.h"
#include "..\ApplicationManager.h"

AddANDgate2::AddANDgate2(ApplicationManager* pApp, ActionType actType, Data* pLoadedData):Action(pApp)
{
test = true;
}

AddANDgate2::~AddANDgate2(void)
{

}

void AddANDgate2::ReadActionParameters()
{
//Get a Pointer to the Input / Output Interfaces
Output* pOut = pManager->GetOutput();
Input* pIn = pManager->GetInput();

//Print Action Message
pOut->PrintMsg("2-Input AND Gate: Click to add the gate");

int i;
pIn->GetPointClicked(Cx, Cy);
if (pOut->isValidArea(Cy) && !(pManager->isExist(Cx, Cy, i)))
{
test = true;
}
else
{
pOut->PrintMsg("Invalid position to draw, try again");
test = false;
}
}

void AddANDgate2::Execute()
{
//Get Center point of the Gate
ReadActionParameters();

if (test)
{
//Calculate the rectangle Corners
int Len = UI.AND2_Width;
int Wdth = UI.AND2_Height;

GraphicsInfo GInfo; //Gfx info to be used to construct the AND2 gate

GInfo.x1 = Cx - Len / 2;
GInfo.x2 = Cx + Len / 2;
GInfo.y1 = Cy - Wdth / 2;
GInfo.y2 = Cy + Wdth / 2;
AND2* pA = new AND2(GInfo, AND2_FANOUT);
pManager->AddComponent(pA);
}
else
{
return;
}
}

void AddANDgate2::Undo()
{}

void AddANDgate2::Redo()
{}

29 changes: 29 additions & 0 deletions Actions/AddANDgate2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _ADD_AND_GATE_H
#define _ADD_AND_GATE_H

#include "action.h"
#include "..\Components\AND2.h"

class AddANDgate2 : public Action
{
private:
//Parameters for rectangular area to be occupied by the gate
int Cx, Cy; //Center point of the gate
int x1, y1, x2, y2; //Two corners of the rectangluar area
bool test;
public:
AddANDgate2(ApplicationManager* pAppMan, ActionType actType, Data* pLoadedData = NULL);
virtual ~AddANDgate2(void);

//Reads parameters required for action to execute
virtual void ReadActionParameters();
//Execute action (code depends on action type)
virtual void Execute();

virtual void Undo();
virtual void Redo();


};

#endif
68 changes: 68 additions & 0 deletions Actions/AddANDgate3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "AddANDgate3.h"
#include "..\ApplicationManager.h"

AddANDgate3::AddANDgate3(ApplicationManager* pApp, ActionType actType, Data* pLoadedData) :Action(pApp)
{
test = true;
}

AddANDgate3::~AddANDgate3(void)
{

}

void AddANDgate3::ReadActionParameters()
{
//Get a Pointer to the Input / Output Interfaces
Output* pOut = pManager->GetOutput();
Input* pIn = pManager->GetInput();

//Print Action Message
pOut->PrintMsg("3-Input AND Gate: Click to add the gate");

int i;
pIn->GetPointClicked(Cx, Cy);
if (pOut->isValidArea(Cy) && !(pManager->isExist(Cx, Cy, i)))
{
test = true;
}
else
{
pOut->PrintMsg("Invalid position to draw, try again");
test = false;
}

}

void AddANDgate3::Execute()
{
//Get Center point of the Gate
ReadActionParameters();

if (test)
{
//Calculate the rectangle Corners
int Len = UI.AND3_Width;
int Wdth = UI.AND3_Height;

GraphicsInfo GInfo; //Gfx info to be used to construct the AND2 gate

GInfo.x1 = Cx - Len / 2;
GInfo.x2 = Cx + Len / 2;
GInfo.y1 = Cy - Wdth / 2;
GInfo.y2 = Cy + Wdth / 2;
AND3* pA = new AND3(GInfo, AND2_FANOUT);
pManager->AddComponent(pA);
}
else
{
return;;
}
}

void AddANDgate3::Undo()
{}

void AddANDgate3::Redo()
{}

29 changes: 29 additions & 0 deletions Actions/AddANDgate3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _ADD_AND3_GATE_H
#define _ADD_AND3_GATE_H

#include "Action.h"
#include "..\Components\AND3.h"

class AddANDgate3 : public Action
{
private:
//Parameters for rectangular area to be occupied by the gate
int Cx, Cy; //Center point of the gate
int x1, y1, x2, y2; //Two corners of the rectangluar area
bool test;
public:
AddANDgate3(ApplicationManager* pAppMan, ActionType actType, Data* pLoadedData = NULL);
virtual ~AddANDgate3(void);

//Reads parameters required for action to execute
virtual void ReadActionParameters();
//Execute action (code depends on action type)
virtual void Execute();

virtual void Undo();
virtual void Redo();


};

#endif#pragma once
Loading

0 comments on commit 1202b74

Please sign in to comment.