Пример #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
bool Select::MoveConnection(Connection*Comp)
{
	Output* pOut = pManager->GetOutput();
	Input* pIn = pManager->GetInput();
	int Cx = Comp->getDestPin()->getComponent()->GetInputPinCoordinates(Comp->getDestPin())->first, Cy = Comp->getDestPin()->getComponent()->GetInputPinCoordinates(Comp->getDestPin())->second;
	bool check = true;
	GraphicsInfo GInfo;
	Component* ChangedComponent = pManager->GetArr()[Cy][Cx];
	Comp = ChangedComponent->GetInputPin(make_pair(Cx, Cy))->get_connection();
	GInfo.x1 = Comp->get_GraphicInfo().x1;
	GInfo.y1 = Comp->get_GraphicInfo().y1;
	GInfo.x2 = Comp->get_GraphicInfo().x2;
	GInfo.y2 = Comp->get_GraphicInfo().y2;

	GInfo.x2 = (pManager->GetArr()[Cy][Cx])->GetInputPinCoordinates(make_pair(Cx, Cy))->first;
	GInfo.y2 = (pManager->GetArr()[Cy][Cx])->GetInputPinCoordinates(make_pair(Cx, Cy))->second;
	Cx = Comp->getSourcePin()->getComponent()->GetOutputPinCoordinates().first, Cy = Comp->getSourcePin()->getComponent()->GetOutputPinCoordinates().second;

	GInfo.x1 = (pManager->GetArr()[Cy][Cx])->GetOutputPinCoordinates().first;
	GInfo.y1 = (pManager->GetArr()[Cy][Cx])->GetOutputPinCoordinates().second;

	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 return false;
	}
	return check;
}