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; }
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; } }