コード例 #1
0
void AddSOAssign::ReadActionParameters()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();
		pManager->UnSelect();
	

	while(1)
	{pOut->PrintMessage("Single Operator Assignment Statement: Click to add the statement");
	pIn->GetPointClicked(Position);
	
	Point P[4];
	P[0].x=Position.x-UI.ASSGN_WDTH/2;            P[1].x=Position.x-UI.ASSGN_WDTH/2;             P[2].x=Position.x+UI.ASSGN_WDTH/2;               P[3].x=Position.x+UI.ASSGN_WDTH/2;
	P[0].y=Position.y;     P[1].y=Position.y+UI.ASSGN_HI;                                       P[2].y=P[1].y;        P[3].y=P[0].y;
	if(P[0].x>UI.MnItWdth&&P[0].y>UI.TlBrWdth&&P[1].y<UI.height-UI.StBrWdth)
		if(!pManager->onObject(P[0])&&!pManager->onObject(P[1])&&!pManager->onObject(P[2])&&!pManager->onObject(P[3]))
		break;
	if(pManager->onBars(Position)||pManager->onObject(Position))
	{pOut->ClearStatusBar();	return;}
			
	
	}
	pOut->ClearStatusBar();
	
}
コード例 #2
0
ファイル: Select.cpp プロジェクト: 3bhady/Logic-Simulator
bool Select::MoveDest(Connection * Comp)
{
	//Get a Pointer to the Input / Output Interfaces
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();
	pOut->FlushKeyQueue();
	pOut->ClearStatusBar();
	//Print Action Message
	pOut->PrintMsg("Changing the Destination Pin press Escape to cansel");
	pOut->UpdateBuffer();
	int Cx = 0, Cy = 0;
	GraphicsInfo GInfo;
	GInfo.x1 = Comp->get_GraphicInfo().x1;
	GInfo.y1 = Comp->get_GraphicInfo().y1;
	GInfo.x2 = Comp->get_GraphicInfo().x2;
	GInfo.y2 = Comp->get_GraphicInfo().y2;
	bool check = false;
	do {
		if (pIn->GetKeyPressed() == ESCAPE)
			return false;
		if (pIn->GetPointClicked(Cx, Cy) == LEFT_CLICK && (pManager->GetArr()[Cy][Cx]) != NULL)
		{
			if (pManager->GetArr()[Cy][Cx]->GetInputPinCoordinates(make_pair(Cx, Cy)) != NULL) {
				GInfo.x2 = (pManager->GetArr()[Cy][Cx])->GetInputPinCoordinates(make_pair(Cx, Cy))->first;
				GInfo.y2 = (pManager->GetArr()[Cy][Cx])->GetInputPinCoordinates(make_pair(Cx, Cy))->second;
				break;
			}
			else
			{
				pOut->ClearStatusBar();
				pOut->PrintMsg("You choosed an invalid Component, please choose a Gate or Led  ");
				pOut->UpdateBuffer();
			}
		}
	} while (true);
	if (check) {
		Comp->EraseConnections(pManager);
		pManager->GetArr()[GInfo.y1][GInfo.x1 - 15]->GetOutputPin()->ConnectTo(Comp);
		pManager->GetArr()[GInfo.y2][GInfo.x2]->GetInputPin(make_pair(GInfo.x2, GInfo.y2))->set_connection(Comp);
		if (bfs(GInfo.x1, GInfo.y1, GInfo.x2, GInfo.y2, pManager->GetArr(), Comp->get_path()))
			Comp->set_GraphicInfo(GInfo);
		GInfo.x1 = Comp->get_GraphicInfo().x1;
		GInfo.y1 = Comp->get_GraphicInfo().y1;
		GInfo.x2 = Comp->get_GraphicInfo().x2;
		GInfo.y2 = Comp->get_GraphicInfo().y2;
		pManager->GetArr()[GInfo.y1][GInfo.x1 - 15]->GetOutputPin()->ConnectTo(Comp);
		pManager->GetArr()[GInfo.y2][GInfo.x2]->GetInputPin(make_pair(GInfo.x2, GInfo.y2))->set_connection(Comp);
		return true;
	}
	return false;
}
コード例 #3
0
void AddRead::Execute()
{
	this->ReadActionParameters();

	

	while (1)
	{
		Read *pRead = new Read(Position);

		Output *pOut = pManager->GetOutput();
		pOut->PrintMessage("Enter String: ");

		Input *pIn = pManager->GetInput();
		bool y = pRead->setData((pIn->GetString(pOut)));

		if (y)
		{
			pManager->AddStatement(pRead);
			pOut->ClearStatusBar();
			break;
		}
		else
		{
			pOut->MsgBox("Invalid text !! Click ok to Re-enter data", "Error", true);
		}
	}
}
コード例 #4
0
void AddRead::ReadActionParameters()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();

	pOut->PrintMessage("Read Statement: Click to add the statement");

	while (1)
	{
		pIn->GetPointClicked(Position);

		if (Position.y > UI.TlBrWdth && Position.y < UI.height - UI.StBrWdth)
		{
			//Calculating each corner of the statement block then check if it's inside another statement
			Point C1(Position.x - UI.READ_WDTH / 2, Position.y);
			Point C2(Position.x + UI.READ_WDTH / 2, Position.y);
			Point C3(Position.x - UI.READ_WDTH / 2, Position.y + UI.READ_HI);
			Point C4(Position.x + UI.READ_WDTH / 2, Position.y + UI.READ_HI);

			if (pManager->GetStatement(C1) == NULL && pManager->GetStatement(C2) == NULL && pManager->GetStatement(C3) == NULL && pManager->GetStatement(C4) == NULL)
			{
				pOut->ClearStatusBar();
				break;
			}
			else
				pOut->PrintMessage("Can't add statement near another one !! Click in another valid position");
		}
		else
			pOut->PrintMessage("Invalid area !! Click in another valid position");
	}
}
コード例 #5
0
ファイル: Edit_label.cpp プロジェクト: FatemaKhalid/Logic-sim
void Edit_label::ReadActionParameters() {
	//Get a Pointer to the Input / Output Interfaces
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();

	//Print Action Message
	pOut->PrintMsg("Click on gate or connection you want to edit its label ");

	//Wait for User Input
	pIn->GetPointClicked(Cx, Cy);
	//component_id=pManager->e7sas(Cx, Cy);
	if (Cx % 15 != 0)
		Cx = Cx / 15;

	if (Cy % 15 != 0)
		Cy = Cy / 15;

	pOut->PrintMsg("Write the label");
	label = pIn->GetSrting(pOut);
	if (label.length() > 5)
		label = label.substr(0, 5);

	pManager->Actual_A.push(this);
	while (!pManager->REDO_A.empty())
	{
		pManager->REDO_A.pop();
	}
	//Clear Status Bar
	pOut->ClearStatusBar();

}
コード例 #6
0
void AddSmplAssign::ReadActionParameters()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();
	
	pOut->PrintMessage("Simple Value Assignment Statement: Click to add the statement");

	pIn->GetPointClicked(Position);
	pOut->ClearStatusBar();	
}
コード例 #7
0
/* Reads parameters required for action to execute */
bool AddConnection::ReadActionParameters() {
	Input* pIn = mAppManager->GetInput();
	Output* pOut = mAppManager->GetOutput();
	
	if (!mIsLoaded) {
		mAppManager->SetSelectionOfComponents(false);
		mAppManager->UpdateInterface();

		pOut->PrintMsg("Connection: select the source pin");
		pIn->WaitMouseClick(mGfxInfo.x1, mGfxInfo.y1);
		pOut->ClearStatusBar();
	}

	if (!DetectSourceComponent()) {
		if (!mIsLoaded) pOut->PrintMsg("Invalid source pin. Operation was cancelled");
		return false;
	}
	
	if (!mIsLoaded) {
		pOut->PrintMsg("Connection: select the destination pin");
		pIn->WaitMouseClick(mGfxInfo.x2, mGfxInfo.y2);
		pOut->ClearStatusBar();
	}

	if (!DetectDestinationComponent()) {
		if (!mIsLoaded) pOut->PrintMsg("Invalid destination pin. Operation was cancelled");
		return false;
	}
	
	mPath = pOut->GetConnectionPath(mGfxInfo);

	if (mPath == NULL) {
		if (!mIsLoaded) pOut->PrintMsg("There is no available path. Operation was cancelled");
		return false;
	}

	return true;
}
コード例 #8
0
void AddSwitch::ReadActionParameters()
{
	//Get a Pointer to the Input / Output Interfaces
	Output* pOut = pManager->GetOutput();


	//Print Action Message
	pOut->PrintMsg("Adding a Led Gate; Click to add the gate");

	//Wait for User Input
	pManager->CheckPoint(Cx, Cy);

	//Clear Status Bar
	pOut->ClearStatusBar();
}
コード例 #9
0
void Resize::ReadActionParameters()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();
	
	Stat=pManager->GetSelectedStatement();
	if(Stat==NULL)
		{
			pOut->PrintMessage("no selected Statement");
			return;
		}
	
	while(1)
	{
	pOut->PrintMessage("pleaze enter '+' to zoom in or enter '-' to zoom out");
	type=pIn->GetString(pOut);
	if(type=="+"||type=="-")
		break;
	}
	pOut->ClearStatusBar();		
}
コード例 #10
0
ファイル: AddBuffer.cpp プロジェクト: FatemaKhalid/Logic-sim
void AddBuffer::ReadActionParameters()
{
	//Get a Pointer to the Input / Output Interfaces
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();

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

	//Wait for User Input
	pIn->GetPointClicked(Cx, Cy);

	// calculate the new coordinates "magnet"

	if (Cx % 15 > 7) Cx = Cx / 15 + 1;
	else Cx = Cx / 15;
	//(Cx % 15<= 7)Cx = Cx / 15 - 1;
	if (Cy % 15 > 7) Cy = Cy / 15 + 1;
	else Cy = Cy / 15;
	//if(Cy % 15<= 7)Cy = Cy / 15 - 1;
	Cx *= 15; Cy *= 15;
	while (!pManager->check_matrix(Cx, Cy))
	{
		pOut->PrintMsg("This area is not empty choose another place"); ////hebaaaaa wrbna ystorrrr
		pIn->GetPointClicked(Cx, Cy);
		if (Cx % 15 > 7) Cx = Cx / 15 + 1;
		else Cx = Cx / 15;

		if (Cy % 15 > 7) Cy = Cy / 15 + 1;
		else Cy = Cy / 15;

		Cx *= 15; Cy *= 15;
	}//call fn elahsas
	 
	//Clear Status Bar
	pOut->ClearStatusBar();

}
コード例 #11
0
void AddConnector::Execute()
{
	Output *pOut = pManager->GetOutput();

	if (pManager->getZoomMode())
	{
		pOut->MsgBox("You can't Add Connectors in zoom mode !!", "Error", true);
		return;
	}

	int SelectedCount = pManager->getSelectedCount();
	Statement** SelectedList = pManager->GetAllSelected();

	if (SelectedCount == 2)
	{
		if (SelectedList[0]->hasConn())
			pOut->MsgBox("Invalid! The selected source already has a connector to another one.", "Error", true);
		else if (dynamic_cast<End*>(SelectedList[0]))
			pOut->MsgBox("Invalid! The source can't be the End statement.", "Error", true);
		else if (dynamic_cast<Start*>(SelectedList[1]))
			pOut->MsgBox("Invalid! The destination can't be the Start statement.", "Error", true);
		else 
		{
			Connector *pConnector = new Connector(SelectedList[0], SelectedList[1]);
			pConnector->setStartPoint(SelectedList[0]->getOutlet());
			pConnector->setEndPoint(SelectedList[1]->getInlet());
			SelectedList[0]->setConn(pConnector);
			pManager->AddConn(pConnector);
			SelectedList[1]->SetSelected(false);
			pManager->RemoveSelected(SelectedList[1]);
			SelectedList[0]->SetSelected(false);
			pManager->RemoveSelected(SelectedList[0]);
			pOut->ClearStatusBar();
		}
	}
	else
		pOut->MsgBox("You should select exactly 2 items then click on this action", "Info", false);
}
コード例 #12
0
void EditConnector::Execute()
{
	Output *pOut = pManager->GetOutput();

	if (pManager->ZM)
	{
		pOut->MsgBox("You can't Edit Connectors in zoom mode !!", "Error", true);
		return;
	}

	if (pManager->ConnSelectedCount > 0)
	{
		int toBeEdited = pManager->ConnSelectedCount;

		Action* DeleteConnAct = new Delete(pManager);
		DeleteConnAct->Execute();

		for (int i = 0; i < pManager->StatCount; i++)
		{
			pManager->StatList[i]->SetSelected(false);
		}
		pManager->EmptySelectedList();

		pManager->UpdateInterface();

		pOut->ClearStatusBar();

		for (int i = 0; i < toBeEdited; ++i)
		{
			pManager->UpdateInterface();
			Point SrcP, DstP;
			Statement *SrcS, *DstS;
			while (1)
			{
				pOut->PrintMessage("Select new source for Selected connector " + to_string(i + 1) + ": ");
				pManager->pIn->GetPointClicked(SrcP);
				SrcS = pManager->GetStatement(SrcP);
				if (SrcS)
				{
					SrcS->SetSelected(true);
					pManager->AddSelected(SrcS);
				}
				pManager->UpdateInterface();
				pOut->PrintMessage("Select new destination for Selected connector " + to_string(i + 1) + ": ");
				pManager->pIn->GetPointClicked(DstP);
				DstS = pManager->GetStatement(DstP);
				if (DstS)
				{
					DstS->SetSelected(true);
					pManager->AddSelected(DstS);
				}
				pManager->UpdateInterface();
				if (SrcS && DstS && SrcS != DstS && !SrcS->hasConn() && !dynamic_cast<End*>(SrcS) && !dynamic_cast<Start*>(DstS))
				{
					break;
				}
				else
				{
					if (SrcS)
					{
						SrcS->SetSelected(false);
						pManager->RemoveSelected(SrcS);
					}
					if (DstS)
					{
						DstS->SetSelected(false);
						pManager->RemoveSelected(DstS);
					}
					pManager->EmptySelectedList();
					pManager->UpdateInterface();
					pOut->MsgBox("Invalid source or destination !! Click ok to Re-select", "Error", true);
				}
			}

			Action* AddConnAct = new AddConnector(pManager);
			AddConnAct->Execute();
			delete AddConnAct;
		}

		DeleteConnAct = new Delete(pManager);
		DeleteConnAct->Execute();
		delete DeleteConnAct;

		pOut->PrintMessage("Edited Successfully !");
	}
	else
		pOut->MsgBox("You Should select the connector(s) first then click on the action", "Info", false);
}
コード例 #13
0
void AddCONNECTION::ReadActionParameters()
{
	//Get a Pointer to the Input / Output Interfaces
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();
	GridItem* x, *y;

	pOut->PrintMsg("Connection building : Click on a Gate/Pin to Connect(1)");
	//Print Action Message

	if (pManager->getCompNo() < 2)
	{
		pOut->PrintMsg("No Gates to Connect....Please Add Gate");
		check=true;
		return;
	}
	else check = false;
	bool success = SrcPin && DstPin;
	bool q=true, w=true;
	while (!success)
	{
		q = true, w = true;
		while (q)
		{
			x = pIn->GetPointClicked(x1, y1);
			SrcPin = dynamic_cast<OutputPin*>(x);
			SrcGate = dynamic_cast<Gate*>(x);
			if (!x)
			{
				pOut->PrintMsg("Cannot Connect to Empty Space... Please Try Again");
				continue;
			}
			if (x1 == -1 || y1 == -1)
			{
				pOut->PrintMsg("Cannot Connect Out... Please Try Again");
				return;
			}
			if (dynamic_cast<Button*> (x))
			{
				pOut->PrintMsg("Cannot Connect on a ToolBar Button");
				continue;
			}
			q = false;
		}
	


		pOut->PrintMsg("Connection building : Click on a Gate/Pin to Connect(2)");

		while (w)
		
		{
			y = pIn->GetPointClicked(x2, y2);
			DstPin = dynamic_cast<InputPin*>(y);
			DstGate = dynamic_cast<Gate*>(y);
			if (!x)
			{
				pOut->PrintMsg("Cannot Connect to Empty Space... Please Try Again");
				continue;
			}
			if (x2 == -1 || y2 == -1)
			{
				pOut->PrintMsg("Cannot Connect to Empty Space... Please Try Again");
				return;
			}
			if (dynamic_cast<Button*> (x))
			{
				pOut->PrintMsg("Cannot Connect on a ToolBar Button");
				continue;
			}
			w = false;
			}



		
		if (!(SrcPin || SrcPin || DstPin || DstGate))
		{
			SrcPin = dynamic_cast<OutputPin*>(y);
			DstPin = dynamic_cast<InputPin*>(x);
		}

		if (SrcGate)
		{
			SrcPin = &(SrcGate->GetOutputPin());
		
		}
		if (DstGate)
		{
			DstPin = DstGate->GetFreeInputPins();
			if (!DstPin)
			{
				pOut->PrintMsg("Connection Error... No Free Input Pins");
				continue;
			}
		}
		if (dynamic_cast<OutputPin*>(SrcPin)->getComponent() == dynamic_cast<InputPin*>(DstPin)->getComponent())
		{
			pOut->PrintMsg("Connection Error : Can't Connect gate to itelf....Go to MultiSim :D :D");
			continue;
		}
		if (SrcPin && DstPin)
		{
			x1 = SrcPin->GetPosition().x1;
			y1 = SrcPin->GetPosition().y1;
			x2 = DstPin->GetPosition().x2;
			y2 = DstPin->GetPosition().y2;
			success = true;
		}
		else
		{
			pOut->PrintMsg("Connection Error : Please Try Again.... Click A Gate/Pin to Connect(1)");
		}

	}
	//clear status bar
	pOut->ClearStatusBar();
}
コード例 #14
0
bool AddConnection::ReadActionParameters()
{

	//Get a Pointer to the Input / Output Interfaces
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();
	pOut->FlushKeyQueue();
	pOut->ClearStatusBar();
	//Print Action Message
	
	pOut->PrintMsg("Adding Connection : Click to add the first edge ");
	pOut->UpdateBuffer();
	if ( pManager->GetComponent( UI.u_GfxInfo.x1 , UI.u_GfxInfo.y1 )==NULL)
	do {
		if (pIn->GetKeyPressed() == ESCAPE)
			return false;
		if (pIn->GetPointClicked(Cx, Cy) == LEFT_CLICK&& (pManager->GetArr()[Cy][Cx])!=NULL) {
			if (((pManager->GetArr()[Cy][Cx])->GetOutputPinCoordinates().first != 0
				&& (pManager->GetArr()[Cy][Cx])->GetOutputPinCoordinates().second != 0)) {
				GInfo.x1 = (pManager->GetArr()[Cy][Cx])->GetOutputPinCoordinates().first;
				GInfo.y1 = (pManager->GetArr()[Cy][Cx])->GetOutputPinCoordinates().second;
				break;
			}
			else {
				pOut->ClearStatusBar();
				pOut->PrintMsg("Please choose a vaild Gate or Switch  ");
				pOut->UpdateBuffer();
			}
		}

	} while (true);
	else
	{
		GInfo.x1 = (pManager->GetComponent( UI.u_GfxInfo.x1,UI.u_GfxInfo.y1))->GetOutputPinCoordinates( ).first;
		GInfo.y1 = (pManager->GetComponent(UI.u_GfxInfo.x1,UI.u_GfxInfo.y1))->GetOutputPinCoordinates( ).second;
	}
	pOut->ClearStatusBar();
	pOut->PrintMsg("Adding Connection : Click to add the second edge ");
	pOut->UpdateBuffer();
	do {
		if (pIn->GetKeyPressed() == ESCAPE)
			return false;
		if (pIn->GetPointClicked(Cx, Cy) == LEFT_CLICK && (pManager->GetArr()[Cy][Cx]) != NULL)
		{
			pOut->Magnetize(Cx, Cy);
			if (pManager->GetArr()[Cy][Cx]->GetInputPinCoordinates(make_pair(Cx, Cy)) != NULL) {
			
				GInfo.x2 = (pManager->GetComponent( Cx , Cy ))->GetInputPinCoordinates( make_pair( Cx , Cy ) )->first;
				GInfo.y2 = (pManager->GetComponent( Cx , Cy ))->GetInputPinCoordinates( make_pair( Cx , Cy ) )->second;
				break;
			}
			else
			{
				pOut->ClearStatusBar();
				pOut->PrintMsg("You choosed an invalid Component, please choose a Gate or Led !!");
				pOut->UpdateBuffer();
			}
		}
	} while (true);
	bfs(GInfo.x1, GInfo.y1, GInfo.x2, GInfo.y2, pManager->GetArr(), outx);
	if (outx.check)
		return true;
	else {
		pManager->GetOutput()->ClearStatusBar();
		pManager->GetOutput()->PrintMsg("There is no valid path");
		pManager->GetOutput()->UpdateBuffer();
		return false;
	}
}