/* Executes action */ bool Paste::Execute() { if (!ReadActionParameters()) { return false; } mAct = new AddGate(mAppManager, mComp->GetAddActionType()); mAct->Execute(); return true; }
void AddSwitch::Execute() { //Get Center point of the Gate ReadActionParameters(); GraphicsInfo GInfo(Cx, Cy); //Gfx info to be used to construct the Buffer SWITCH *pA = new SWITCH(GInfo); pManager->AddComponent(pA); pA->Draw(pManager->GetOutput()); }
void Select::Execute() { ReadActionParameters(); if(!pManager->getSim()) pManager->getTemp()->SetState(!pManager->getTemp()->GetState()); SWITCH* x = dynamic_cast<SWITCH*>(pManager->getTemp()); if (x && pManager->getSim()) { x->turnONOFF(!x->getONOFF()); } }
void Cut::Execute() { ReadActionParameters(); for (std::set<Component*>::iterator i = Components.begin(); i != Components.end(); i++) { if (dynamic_cast<Connection*>(*i) == NULL) { pManager->PushIntoClipboard(*i); } } pManager->RemoveComponents(std::vector<Component*>(Components.begin(), Components.end())); }
void AddConnection::Execute() { Connection *pS = NULL; //Get Center point of the Connection if (!ReadActionParameters()) return; pS = new Connection(GInfo, &outx, (pManager->GetComponent( GInfo.x1 - 15 , GInfo.y1 ))->GetOutputPin(), (pManager->GetComponent( GInfo.x2 , GInfo.y2 ))->GetInputPin(make_pair(GInfo.x2, GInfo.y2))); //pManager->GetArr()[GInfo.y1][GInfo.x1 - 15]->GetOutputPin()->ConnectTo(pS); pManager->GetComponent(GInfo.x1 - 15, GInfo.y1 )->GetOutputPin( )->ConnectTo( pS ); //pManager->GetArr()[GInfo.y2][GInfo.x2]->GetInputPin(make_pair(GInfo.x2, GInfo.y2))->set_connection(pS); pManager->GetComponent( GInfo.x2,GInfo.y2)->GetInputPin( make_pair( GInfo.x2 , GInfo.y2 ) )->set_connection( pS ); pManager->AddComponent(pS); }
void AddCONNECTION::Execute() { //Get Connection Source and destination points ReadActionParameters(); if (check) return; GraphicsInfo GInfo(x1,y1,x2,y2); Connection *pA = new Connection(GInfo, dynamic_cast<OutputPin*>(SrcPin), dynamic_cast<InputPin*>(DstPin)); pManager->AddComponent(pA); pA->Draw(pManager->GetOutput()); }
void Paste::Execute() { ReadActionParameters(); auto temp=pManager->getClipboard(); GraphicsInfo Gfx(this->x, y); GraphicsInfo tmp3 = ((Gate*)temp[0])->GetPosition(); for (size_t i = 0; i < temp.size(); i++) { if (IsInDesign(GraphicsInfo(Gfx - tmp3 + ((Gate*)temp[i])->GetPosition()))) { temp[i]->SetPosition(GraphicsInfo(Gfx - tmp3 + ((Gate*)temp[i])->GetPosition())); } pManager->AddComponent(temp[i]); } }
/* Executes action */ bool AddConnection::Execute() { if (!ReadActionParameters()) { return false; } mConnection = new Connection(mAppManager->GetOutput(), mGfxInfo, *mPath); mConnection->SetSourcePin(mSrcPin); mConnection->SetDestinationPin(mDstPin, mDstPinIndex); mConnection->SetLabel(mLabel); mAppManager->AddComponent(mConnection); delete mPath; return true; }
void AddBuffer::Execute() { //Get Center point of the Gate ReadActionParameters(); //Calculate the rectangle Corners int Len = UI.Buffer_Width; int Wdth = UI.Buffer_Height; GraphicsInfo GInfo; //Gfx info to be used to construct the AND2 gate GInfo.x1 = Cx - Len / 2; GInfo.x2 = Cx + Len / 2; GInfo.y1 = Cy - Wdth / 2; GInfo.y2 = Cy + Wdth / 2; Buffer *pA = new Buffer(GInfo, AND2_FANOUT); pA->updateMatrix(GInfo, pA->getid(), pA->gettype()); pManager->AddComponent(pA); }
void AddNOTgate::Execute(ApplicationManager *pManager) { //Get Center point of the Gate ReadActionParameters(pManager); if(Cx > 95 && Cy > 105 && Cy < 620 && Cx < 960) { GraphicsInfo GInfo; GInfo.IMG= new image("images\\NOT.jpg"); GInfo.IMGsel= new image("images\\NOTsel.jpg"); int Len = GInfo.IMG->GetWidth(), Wdth = GInfo.IMG->GetHeight(); GInfo.x1 = Cx - Len/2; GInfo.x2 = Cx + Len/2; GInfo.y1 = Cy - Wdth/2; GInfo.y2 = Cy + Wdth/2; Comp = new Not(GInfo, Not_FANOUT); pManager->AddComponent(Comp); } }
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(); } }
/* Destructor */ Paste::~Paste() { if (ReadActionParameters()) { delete mAct; } }
void XORToolBar::Execute() { ReadActionParameters(); pManager->DrawToolBar(TOOLBARS::ADDXORBAR); }