コード例 #1
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");
	}
}
コード例 #2
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);
		}
	}
}
コード例 #3
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();
	
}
コード例 #4
0
ファイル: Paste.cpp プロジェクト: Ahmkel/Flowchart-Creator
void Paste::ReadActionParameters()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();

	list<Statement*> CopiedOrCutStatements = pManager->GetCopiedOrCutStatements();
	if (CopiedOrCutStatements.size() == 0)
	{
		pOut->PrintMessage("Please, Select statement(s) then Copy before Pasting!");
	}
	else
	{
		pOut->PrintMessage("Please Click where you want to paste your statements!");
		pIn->GetPointClicked(P);
		FlagToPaste = true;
	}
}
コード例 #5
0
ファイル: Copy.cpp プロジェクト: Ahmkel/Flowchart-Creator
void Copy::ReadActionParameters()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();
	
	pOut->PrintMessage("Your selected statement(s) are ready to be copied");
	
	//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
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();		
}
コード例 #8
0
ファイル: Delete.cpp プロジェクト: Ahmkel/Flowchart-Creator
void Delete::Execute()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();

	//Get List of selected statements
	list<Statement*> SelectedStatements = pManager->GetSelectedStatements();
	list<Connector*> SelectedConnectors = pManager->GetSelectedConnectors();
	Point TempP;
	//list<Connector*>ConnList = pManager->GetConnList();

	//Print Message and Wait for any click
	pOut->PrintMessage("Delete: Deleting Selected Statements if any, press any key to continue");
	pIn->GetPointClicked(TempP);
	for (list<Connector*>::iterator it = SelectedConnectors.begin(); it != SelectedConnectors.end(); it++)
	{
		pManager->DeleteConnector((*it));
	}


	list<Connector*>ConnList = pManager->GetConnList();

	for (list<Statement*>::iterator it = SelectedStatements.begin(); it != SelectedStatements.end(); it++)
	{
		//Delete Input Connectors
		if ((*it)->GetStatementType() != 0 || ((*it)->GetStatementType() == 0 && ((StartEnd*)(*it))->GetMode() == true))
		{
			list<Connector*> InputConnectors;

			for (list<Connector*>::iterator itConn = ConnList.begin(); itConn != ConnList.end(); itConn++)
			{
				if ((*itConn)->getDstStat() == (*it))
					InputConnectors.push_back((*itConn));
			}
			for (list<Connector*>::iterator itConn = InputConnectors.begin(); itConn != InputConnectors.end(); itConn++)
			{
				/*
				if ((*itConn)->getSrcStat()->GetpConn == (*itConn))
				(*itConn)->getSrcStat()->SetpConn(NULL);
				else if (((Conditional*)(*itConn)->getSrcStat())->GetpConnL() == (*itConn))
				((Conditional*)(*itConn)->getSrcStat())->SetpConnL(NULL);
				*/
				if ((*itConn)->GetBranchType() == 2)
					((Conditional*)(*itConn)->getSrcStat())->SetpConnL(NULL);
				else
					(*itConn)->getSrcStat()->SetpConn(NULL);

				pManager->DeleteConnector((*itConn));
			}
		}

		//Conditional
		if ((*it)->GetStatementType() == 3)
		{
			//Yes
			if (((Conditional*)(*it))->GetpConn() != NULL)
				pManager->DeleteConnector(((Conditional*)(*it))->GetpConn());
			//No
			if (((Conditional*)(*it))->GetpConnL() != NULL)
				pManager->DeleteConnector(((Conditional*)(*it))->GetpConnL());
		}
		else //Not Conditional
		{
			if ((*it)->GetpConn() != NULL)
				pManager->DeleteConnector((*it)->GetpConn());
		}
		pManager->DeleteStatement((*it));
	}

	pOut->PrintMessage("");
	pOut->ClearDrawArea();
	pManager->UpdateInterface();
}
コード例 #9
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);
}
コード例 #10
0
ファイル: Paste.cpp プロジェクト: Ahmkel/Flowchart-Creator
void Paste::Execute()
{
	Input *pIn = pManager->GetInput();
	Output *pOut = pManager->GetOutput();

	ReadActionParameters();

	if (FlagToPaste == true) //Check that the user had already chosen Copy Or Cut to execute Paste action
	{
		//Get the List of Copied or Cut Statements
		list<Statement*> CopiedOrCutStatements = pManager->GetCopiedOrCutStatements();
		
		//If they are Copied
		if (CopiedOrCutStatements.front()->GetCopiedOrCut() == 1) //Copy Action
		{
			Point LeftCornerUp, LeftCornerDown, RightCornerUp, RightCornerDown;
			//Get First Copied statement type to help in calculating dx & dy
			int Type = CopiedOrCutStatements.front()->GetStatementType();
			//Get 4 corners of the point based on its type;
			pManager->GetCorners(P, Type, LeftCornerUp, LeftCornerDown, RightCornerUp, RightCornerDown);
			int dx, dy;

			//Calculate dx and dy due to the first selectes statement
			dx = LeftCornerUp.x - CopiedOrCutStatements.front()->GetLeftCorner().x;
			dy = LeftCornerUp.y - CopiedOrCutStatements.front()->GetLeftCorner().y;

			//Add New Statements to this list
			list<Statement*> NewStatements;

			for (list<Statement*>::iterator it = CopiedOrCutStatements.begin(); it != CopiedOrCutStatements.end(); it++)
			{
				Statement* NewStatement;

				//Get Type of each statement
				Type = (*it)->GetStatementType();
				Point NewStatementPoint = (*it)->GetLeftCorner();

				//This should be the new point for the current statement after copying
				NewStatementPoint.x += dx;
				NewStatementPoint.y += dy;

				//Create New statement of the same type
				//Types:
				// 0 StartEnd
				// 1 SMPLAssignment
				// 2 VARAssignment
				// 3 Conditional
				// 4 Read Write
				switch (Type)
				{
					//No case 0 because we will never have 0 type statements (Start End)
					//"Start and End" are not copied
				case 1:
					NewStatement = new SmplAssign(*((SmplAssign*)(*it)));
					break;
				case 2:
					NewStatement = new VariableAssign(*((VariableAssign*)(*it)));
					break;
				case 3:
					NewStatement = new Conditional(*((Conditional*)(*it)));
					((Conditional*)(NewStatement))->SetpConnL(NULL);
					break;
				case 4:
					NewStatement = new ReadWrite(*((ReadWrite*)(*it)));
					break;
				}

				Statement::IncrementIDCounter();
				NewStatement->SetID(Statement::GetIDCounter());
				NewStatement->SetLeftCorner(NewStatementPoint);
				NewStatement->SetSelected(false);
				NewStatement->SetCopiedOrCut(0);
				NewStatement->UpdatePoints();
				NewStatement->SetpConn(NULL);
				//Dummy variable
				bool tt;
				//Check validity of point
				if (pManager->IsOutOfBounds(NewStatement, tt, tt, tt, tt) || pManager->IsOverlapping(NewStatement))
				{
					//Print Error Message
					pOut->PrintMessage("Unsuitable point for copying. Action terminated! Press any key to continue");
					
					//Remove all new statements
					for (list<Statement*>::iterator it2 = NewStatements.begin(); it2 != NewStatements.end(); it2++)
					{
						delete (*it2);
					}
					NewStatements.clear();

					//Wait for key press
					pIn->GetPointClicked(P);
					pOut->PrintMessage("");
					return;
				}

				//Statement position is okay, add it
				NewStatements.push_back(NewStatement);
			}

			//All statements don't overlap, add them to Statements list
			for (list<Statement*>::iterator it = NewStatements.begin(); it != NewStatements.end(); it++)
			{
				pManager->AddStatement((*it));
			}
			pManager->UpdateCopiedOrCutStatements(0);

		}
		//If they are Cut
		else if (CopiedOrCutStatements.front()->GetCopiedOrCut() == 2) //Cut Action
		{
			//Cutting Statement Only

			Point LeftCornerUp, LeftCornerDown, RightCornerUp, RightCornerDown;
			//Get First Copied statement type to help in calculating dx & dy
			int Type = CopiedOrCutStatements.front()->GetStatementType();
			//Get 4 corners of the point based on its type;
			pManager->GetCorners(P, Type, LeftCornerUp, LeftCornerDown, RightCornerUp, RightCornerDown);
			int dx, dy;
			dx = LeftCornerUp.x - CopiedOrCutStatements.front()->GetLeftCorner().x;
			dy = LeftCornerUp.y - CopiedOrCutStatements.front()->GetLeftCorner().y;

			//Store Old points before cutting
			list<Point> OldPoints;

			for (list<Statement*>::iterator it = CopiedOrCutStatements.begin(); it != CopiedOrCutStatements.end(); it++)
			{
				//Get Type of each statement
				Point NewStatementPoint = (*it)->GetLeftCorner();
				
				//Save Old Point
				OldPoints.push_back(NewStatementPoint);

				//Calculate New Point
				NewStatementPoint.x += dx;
				NewStatementPoint.y += dy;

				//Edit Point
				(*it)->SetLeftCorner(NewStatementPoint);

				//Dummy variable
				bool tt;
				//Check validity of new position of pasted statement
				if (pManager->IsOutOfBounds((*it), tt, tt, tt, tt) || pManager->IsOverlapping((*it)))
				{
					//Print Error Message
					pOut->PrintMessage("Unsuitable point for cutting. Action terminated! Press any key to continue");

					//Return pasted statements to their old positions
					list<Statement*>::iterator it2 = CopiedOrCutStatements.begin();
					for (list<Point>::iterator Pointit = OldPoints.begin(); Pointit != OldPoints.end(); Pointit++)
					{
						(*it2)->SetLeftCorner((*Pointit));
						it2++;
					}
					OldPoints.clear();

					//Wait for key press
					pIn->GetPointClicked(P);
					pOut->PrintMessage("");

					pOut->ClearDrawArea();
					pManager->UpdateInterface();
					return;
				}

				
				(*it)->UpdatePoints();
			}

			for (list<Statement*>::iterator it = CopiedOrCutStatements.begin(); it != CopiedOrCutStatements.end(); it++)
			{
				(*it)->SetCopiedOrCut(0);
			}
			pManager->UpdateCopiedOrCutStatements(0);
		}
		pOut->ClearDrawArea();
		pManager->UpdateInterface();
	}
}
コード例 #11
0
void GenerateCode::Execute()
{
	Output *pOut = pManager->GetOutput();
	Input *pIn = pManager->GetInput();
	Action* pVal = new Validate(pManager);
	string error;

	if (dynamic_cast<Validate*>(pVal)->isValid(error) || error.find("zero") != string::npos)
	{
		ofstream Code;
		Code.open("Code.cpp");

		// Search for Start ID & End ID & Variable Names
		int start_index, end_index;
		set<string> vars;
		set<string>::iterator it;
		for (int i = 0; i < pManager->getStatCount(); ++i)
		{
			string tmp, data;
			tmp = pManager->StatList[i]->CopyData();
			for (int i = 0; i < tmp.size(); i++)
			{
				if (tmp[i] == ' ')
					continue;
				data += tmp[i];
			}
			// Search for Start ID & End ID
			if (dynamic_cast<Start*>(pManager->StatList[i]))
				start_index = i;
			if (dynamic_cast<End*>(pManager->StatList[i]))
				end_index = i;
			// Search for Variable Names
			if (dynamic_cast<Read*>(pManager->StatList[i]))
			{
				char* cData = new char[data.size() + 1];
				strcpy(cData, data.c_str());
				char* var = strtok(cData, ",");
				while (var) {
					vars.insert(var);
					var = strtok(NULL, ",");
				}
				delete[] cData;
			}
			// Search for Variable Names
			if (dynamic_cast<Write*>(pManager->StatList[i]))
			{
				char* cData = new char[data.size() + 1];
				strcpy(cData, data.c_str());
				char* var = strtok(cData, ",");
				while (var) {
					vars.insert(var);
					var = strtok(NULL, ",");
				}
				delete[] cData;
			}
			// Search for Variable Names
			if (dynamic_cast<Assign*>(pManager->StatList[i]))
			{
				string Left = data.substr(0, data.find('='));
				vars.insert(Left);
				string Right = data.substr(data.find('=') + 1);
				string v;
				for (int i = 0; i < Right.size(); i++)
				{
					if ((Right[i] == '+' || Right[i] == '-' || Right[i] == '*' || Right[i] == '/' || Right[i] == '%') && v.size())
					{
						vars.insert(v);
						v.clear();
					}
					else if (isalpha(Right[i]))
						v += Right[i];
				}
				if (v.size())
					vars.insert(v);
			}
			// Search for Variable Names
			if (dynamic_cast<Cond*>(pManager->StatList[i]))
			{
				string cond = dynamic_cast<Cond*>(pManager->StatList[i])->getCond();
				string Left = data.substr(0, data.find(cond));
				string Right = data.substr(data.find(cond) + cond.size());
				string v;
				for (int i = 0; i < Left.size(); i++)
				{
					if ((Left[i] == '+' || Left[i] == '-' || Left[i] == '*' || Left[i] == '/' || Left[i] == '%') && v.size())
					{
						vars.insert(v);
						v.clear();
					}
					else if (isalpha(Left[i]))
						v += Left[i];
				}
				if (v.size())
					vars.insert(v);
				v.clear();
				for (int i = 0; i < Right.size(); i++)
				{
					if ((Right[i] == '+' || Right[i] == '-' || Right[i] == '*' || Right[i] == '/' || Right[i] == '%') && v.size())
					{
						vars.insert(v);
						v.clear();
					}
					else if (isalpha(Right[i]))
						v += Right[i];
				}
				if (v.size())
					vars.insert(v);
			}
		}

		string GeneratedCode;
		int curr_idx, next_idx;
		curr_idx = next_idx = start_index;

		// Generate Start code
		GeneratedCode += pManager->StatList[curr_idx]->GenerateCode(pManager->StatList, pManager->getStatCount(), end_index, curr_idx, next_idx, 0);

		// Generate variables declarations
		if (vars.size())
		{
			GeneratedCode += "\tdouble";
			for (it = vars.begin(); it != vars.end(); ++it)
			{
				GeneratedCode += " " + *it + " = 0";
				if (distance(it, vars.end()) > 1)
					GeneratedCode += ",";
			}
			GeneratedCode += ";\n";
		}

		// Generate code for each statement after Start till End
		while (1)
		{
			curr_idx = next_idx;

			GeneratedCode += pManager->StatList[curr_idx]->GenerateCode(pManager->StatList, pManager->getStatCount(), end_index, curr_idx, next_idx, 1);

			if (curr_idx == end_index)
				break;
		}

		Code << GeneratedCode;

		Code.close();

		pOut->MsgBox("Code generated successfully !", "Info", false);
		pOut->PrintMessage("Code generated successfully !");
	}
	else
		pOut->MsgBox("Sorry. You can only generate code of a valid flowchart. And this is NOT !", "Error", true);
}