コード例 #1
0
void AddConnection::LoadConnection(int SrcID, int DstID)
{
	Component* pSrcComp = NULL;
	Component* pDstComp = NULL;
	for (int i = 0; i < pManager->GetComplistSize(); i++)
		if (pManager->GetComponent(i)->getID() == SrcID)
		{
			pSrcComp = pManager->GetCompList()[i];
			break;
		}
	for (int i = 0; i < pManager->GetComplistSize(); i++)
		if (pManager->GetComponent(i)->getID() == DstID)
		{
			pDstComp = pManager->GetComponent(i);
			break;
		}

	GInfo.x1 = pSrcComp->GetOutputPinCoordinates().first;
	GInfo.y1 = pSrcComp->GetOutputPinCoordinates().second;
	GInfo.x2 = pDstComp->GetInputPinCoordinates(make_pair(pDstComp->get_GraphicInfo().x1 + 5, pDstComp->get_GraphicInfo().y1 + 5))->first;
	GInfo.y2 = pDstComp->GetInputPinCoordinates(make_pair(pDstComp->get_GraphicInfo().x1 + 5, pDstComp->get_GraphicInfo().y1 + 5))->second;
	bfs(GInfo.x1, GInfo.y1, GInfo.x2, GInfo.y2, pManager->GetArr(), outx);
	if (outx.check) {
		Connection *pS = NULL;
		pS = new Connection(GInfo, &outx, pSrcComp->GetOutputPin(), pDstComp->GetInputPin(make_pair(GInfo.x2, GInfo.y2)));
		pSrcComp->GetOutputPin()->ConnectTo(pS);
		pDstComp->GetInputPin(make_pair(GInfo.x2, GInfo.y2))->set_connection(pS);
		pManager->AddComponent(pS);
	}
	else return;

}
コード例 #2
0
ファイル: Select.cpp プロジェクト: 3bhady/Logic-Simulator
bool Select::MoveOutPin(Connection*Comp)
{
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();
	int Cx = Comp->getSourcePin()->getComponent()->GetOutputPinCoordinates().first, Cy = Comp->getSourcePin()->getComponent()->GetOutputPinCoordinates().second;
	bool check = true;
	GraphicsInfo GInfo;
	Component* ChangedComponent = pManager->GetArr()[Cy][Cx - 15];
	for (int i = 0;i < ChangedComponent->GetOutputPin()->GetConnections().size();i++) {
		Comp = ChangedComponent->GetOutputPin()->GetConnections()[i];
		GInfo.x1 = Comp->get_GraphicInfo().x1;
		GInfo.y1 = Comp->get_GraphicInfo().y1;
		GInfo.x2 = Comp->get_GraphicInfo().x2;
		GInfo.y2 = Comp->get_GraphicInfo().y2;
		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;
		}
		else check = false;

		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);
		}
		else break;
	}
	return check;
}