void CCircuitView::OnLButtonDown(UINT nFlags, CPoint point) { CLogicSimulatorDoc *pDoc = (CLogicSimulatorDoc *)GetDocument(); CClientDC dc(this); Gdiplus::Graphics graphics(dc); Gdiplus::Pen P(Gdiplus::Color(0, 0, 0), 2); dec_x = Rounding(point.x); dec_y = Rounding(point.y); CPoint cur_pos(dec_x, dec_y); BOOL check = FALSE; //¼±ÀÌµç ·ÎÁ÷ÀÌµç »ý¼º¿Ï·á //¼±À» ¼±ÅÃÇßÀ» °æ¿ì´Â LINE , ±âº»°ªÀº OBJECT·Î ÇÔ. object = OBJECT; //¼± ¿ÀºêÁ§Æ®¿¡¼ ¼±ÀÌ ºÐ±â µÉ °æ¿ì // + ¸Þ´º¿¡¼ ¼±ÅÃÀÌ ¾È‰çÀ» °æ¿ì ¶óÀÎ ¸ðµå ÁøÀÔ ////////ºÐ±â °Ë»ç////// int ln = (int)pDoc->currBox->lines.size(); for (int i = 0; i < ln; i++) { if (pDoc->currBox->lines.at(i)->Is_match_IineCoord(point) && !(pDoc->isSelected) && !(pDoc->clickMode)) { LineObject* curline = pDoc->currBox->lines.at(i); if (curline->line[0] != cur_pos && curline->line[1] != cur_pos) object = LINE; object = LINE; break; } } //³í¸® ¿ÀºêÁ§Æ®µé Áß¿¡¼ ¼± ºÐ±â °¡´É°Ë»ç for (int i = 0; i < pDoc->currBox->logicInfo.size() && object == OBJECT; i++) { int in = pDoc->currBox->logicInfo.at(i)->inputNum; int on = pDoc->currBox->logicInfo.at(i)->outputNum; CPoint pos; for (int j = 0; j < on; j++) { pos = pDoc->currBox->logicInfo.at(i)->outputCoord[j].first; if (dec_x == pos.x && dec_y == pos.y && !(pDoc->isSelected) && !(pDoc->clickMode)) { object = LINE; break; } } for (int j = 0; j < in; j++) { pos = pDoc->currBox->logicInfo.at(i)->inputCoord[j].first; if (dec_x == pos.x && dec_y == pos.y && !(pDoc->isSelected) && !(pDoc->clickMode)) { object = LINE; break; } } } ////////////³í¸® ¿ÀºêÁ§Æ® »ý¼º///////////////// if (object == OBJECT) { //¸Þ´º¿¡¼ ¼±ÅÃÇÏ°í Çʵ忡¼ ÁöÁ¤ ¿Ï·áµÉ ¶§ LogicObject* temp; temp = NULL; if (pDoc->isSelected) { pDoc->locked = TRUE; if (pDoc->objectType == GATE_TYPE) { Gate *Gtemp; Gtemp = NULL; switch (pDoc->objectName) { case AND_GATE: Gtemp = new andGate(dec_x, dec_y); break; case OR_GATE: Gtemp = new orGate(dec_x, dec_y); break; case NAND_GATE: Gtemp = new nandGate(dec_x, dec_y); break; case NOR_GATE: Gtemp = new norGate(dec_x, dec_y); break; case XOR_GATE: Gtemp = new xorGate(dec_x, dec_y); break; case NOT_GATE: Gtemp = new notGate(dec_x, dec_y); break; } temp = Gtemp; // delete ¿ëÀ¸·Î ÇÊ¿äÇÔ. if (Gtemp != NULL) { Gtemp->set_Coord_From_outC(dec_x, dec_y); pDoc->currBox->logicInfo.push_back(Gtemp); pDoc->CheckPoint(); } } else if (pDoc->objectType == WIRING_TYPE) { Pin *Ptemp = NULL; Clock *Ctemp = NULL; Out *Otemp = NULL; Sevenseg *Stemp = NULL; temp = NULL; switch (pDoc->objectName) { case PIN: Ptemp = new Pin(dec_x, dec_y); temp = Ptemp; //¶óÀ̺귯¸® »óÀÚ¿¡ ´ëÇÑ ÀÔ·Â À§Ä¡¸¦ ã¾ÆÁØ´Ù. break; case CLOCK: Ctemp = new Clock(dec_x, dec_y); temp = Ctemp; break; case OUTPIN: Otemp = new Out(dec_x, dec_y); temp = Otemp; break; case SEG7: Stemp = new Sevenseg(dec_x, dec_y); temp = Stemp; } if (temp != NULL) { temp->set_outputCoord(dec_x, dec_y); temp->set_Coord_From_outC(dec_x, dec_y); //Ãâ·ÂÇÉÀº Ãâ·Â ¼±ÀÌ ¾ø´Ù. //7 segµµ ¸¶Âù°¡ÁöÀÓ. pDoc->currBox->logicInfo.push_back(temp); pDoc->CheckPoint(); } } else if (pDoc->objectType == FLIPFLOP_TYPE) { FlipFlop *Ftemp = NULL; switch (pDoc->objectName) { case D_FF: Ftemp = new DFlipFlop(dec_x, dec_y); break; case JK_FF: Ftemp = new JKFlipFlop(dec_x, dec_y); break; case T_FF: Ftemp = new TFlipFlop(dec_x, dec_y); break; } if (Ftemp != NULL) { Ftemp->set_Coord_From_outC(dec_x, dec_y); pDoc->currBox->logicInfo.push_back(Ftemp); pDoc->CheckPoint(); } } else if (pDoc->objectType == LIB) { Box *Btemp = NULL; if (pDoc->objectName == MAIN_LIB) Btemp = new Box(dec_x, dec_y, &(pDoc->logicBox[0])); else Btemp = new Box(dec_x, dec_y, &(pDoc->logicBox[1])); Btemp->set_Coord_From_outC(dec_x, dec_y); pDoc->currBox->logicInfo.push_back(Btemp); pDoc->CheckPoint(); } delete pDoc->currBox->temp; pDoc->currBox->temp = NULL; pDoc->isSelected = false; } ////Ŭ¸¯ ¸ðµå/////////////////////////////// //Ŭ¸¯ ¸ðµåÀÎ °æ¿ì //Pin °ú Clock ÀÇ output µ¥ÀÌÅ͸¦ ¹Ù²Ü»Ó gate ´Â ¿µÇâÀÌ ¾ø´Ù.. if (pDoc->clickMode) { POINT temp_top, temp_bottom; for (int i = 0; i < pDoc->currBox->logicInfo.size(); i++) { LogicObject* tempLogic = pDoc->currBox->logicInfo.at(i); if (pDoc->currBox->IsInput(tempLogic)) { temp_top = tempLogic->get_top(); temp_bottom = tempLogic->get_bottm(); CRect rect(temp_top.x, temp_top.y, temp_bottom.x, temp_bottom.y); if (PtInRect(rect, point) && (tempLogic->objectName == PIN || tempLogic->objectName == CLOCK)) tempLogic->toggleOutput(); } } } else { //Ŭ¸¯ ¸ðµå »óÅ¿¡¼¸¸ °´Ã¼ ¼±Åà °¡´É if (!(pDoc->isSelected)) { pDoc->currBox->currObject.clear(); POINT temp_top, temp_bottom; BOOL checkFocus = FALSE; for (int i = 0; i < pDoc->currBox->logicInfo.size(); i++) { pDoc->currBox->logicInfo.at(i)->isSelected = FALSE; temp_top = pDoc->currBox->logicInfo.at(i)->get_top(); temp_bottom = pDoc->currBox->logicInfo.at(i)->get_bottm(); CRect rect(temp_top.x, temp_top.y, temp_bottom.x, temp_bottom.y); //¸¶¿ì½º°¡ °´Ã¼¾È¿¡ ÀÖÀ¸¸é ¼±ÅÃÇÔ. if (PtInRect(rect, point)) { checkFocus = TRUE; pDoc->currBox->isOnFocus = TRUE; pDoc->currBox->logicInfo.at(i)->isSelected = TRUE; prevT.x = dec_x; prevT.y = dec_y; pDoc->currBox->currObject.push_back(pDoc->currBox->logicInfo.at(i)); } } //ÇöÀç ¼±ÅÃµÈ ·ÎÁ÷ ¿ÀºêÁ§Æ®ÀÇ »óŸ¦ º¸¿©ÁØ´Ù. if (pDoc->currBox->isOnFocus) { if (pDoc->currBox->currObject.size() == 1) { CPropertyView *PVCtrl = (CPropertyView *)((CMainFrame*)AfxGetMainWnd())->m_wndSplitterSub.GetPane(1, 0); PVCtrl->InitializePropGrid(pDoc->currBox->currObject.at(0)); } else { //´Ù¼ö ¼±Åà } } for (int i = 0; i < pDoc->currBox->lines.size(); i++) { pDoc->currBox->lines.at(i)->isSelected = FALSE; if (pDoc->currBox->lines.at(i)->Is_match_CLICK(point)) { pDoc->currBox->lines.at(i)->isSelected = TRUE; pDoc->currBox->isOnFocus = TRUE; checkFocus = TRUE; sdis.x = dec_x - pDoc->currBox->lines.at(i)->line[0].x; sdis.y = dec_y - pDoc->currBox->lines.at(i)->line[0].y; edis.x = dec_x - pDoc->currBox->lines.at(i)->line[1].x; edis.y = dec_y - pDoc->currBox->lines.at(i)->line[1].y; } } //¸¶¿ì½º ³»¿¡ °´Ã¼°¡ Çϳª¶óµµ ¾øÀ¸¸é ¼±Åà Ãë¼ÒµÊ. if (!checkFocus) pDoc->currBox->isOnFocus = FALSE; } } } /////////¼± »ý¼º///////////////////////////// else if (object != OBJECT && !(pDoc->isSelected)) { //µ¿±×¶õ Ç¥½Ã Áö¿ì±â if (pDoc->currBox->CanBeDivided) { pDoc->currBox->CanBeDivided = FALSE; } LineObject* temp_line[2]; //¼± µÎ°³ »ý¼º temp_line[0] = new LineObject(dec_x, dec_y); temp_line[1] = new LineObject(dec_x, dec_y); cur_line = (int)pDoc->currBox->lines.size() + 1; pDoc->currBox->lines.push_back(temp_line[0]); pDoc->currBox->lines.push_back(temp_line[1]); } pDoc->currBox->CheckCircuit(); Invalidate(); CView::OnLButtonDown(nFlags, point); }
void CCircuitView::OnEditPaste() { if (PASTED || CUTED) { CLogicSimulatorDoc *pDoc = (CLogicSimulatorDoc *)GetDocument(); for (int i = 0; i < pDoc->currBox->store.name.size(); i++) { LogicObject* temp; int dec_x = pDoc->currBox->store.dec.x, dec_y = pDoc->currBox->store.dec.y; if (pDoc->currBox->store.type.at(i) == GATE_TYPE) { Gate *Gtemp; Gtemp = NULL; switch (pDoc->currBox->store.name.at(i)) { case AND_GATE: Gtemp = new andGate(dec_x, dec_y); break; case OR_GATE: Gtemp = new orGate(dec_x, dec_y); break; case NAND_GATE: Gtemp = new nandGate(dec_x, dec_y); break; case NOR_GATE: Gtemp = new norGate(dec_x, dec_y); break; case XOR_GATE: Gtemp = new xorGate(dec_x, dec_y); break; case NOT_GATE: Gtemp = new notGate(dec_x, dec_y); break; } temp = Gtemp; // delete ¿ëÀ¸·Î ÇÊ¿äÇÔ. if (Gtemp != NULL) { Gtemp->set_Coord_From_outC(dec_x, dec_y); } } else if (pDoc->currBox->store.type.at(i) == WIRING_TYPE) { Pin *Ptemp = NULL; Clock *Ctemp = NULL; Out *Otemp = NULL; Sevenseg *Stemp = NULL; temp = NULL; switch (pDoc->currBox->store.name.at(i)) { case PIN: Ptemp = new Pin(dec_x, dec_y); temp = Ptemp; //¶óÀ̺귯¸® »óÀÚ¿¡ ´ëÇÑ ÀÔ·Â À§Ä¡¸¦ ã¾ÆÁØ´Ù. break; case CLOCK: Ctemp = new Clock(dec_x, dec_y); temp = Ctemp; break; case OUTPIN: Otemp = new Out(dec_x, dec_y); temp = Otemp; break; case SEG7: Stemp = new Sevenseg(dec_x, dec_y); temp = Stemp; } if (temp != NULL) { temp->set_outputCoord(dec_x, dec_y); temp->set_Coord_From_outC(dec_x, dec_y); //Ãâ·ÂÇÉÀº Ãâ·Â ¼±ÀÌ ¾ø´Ù. //7 segµµ ¸¶Âù°¡ÁöÀÓ. } } else if (pDoc->currBox->store.type.at(i) == FLIPFLOP_TYPE) { FlipFlop *Ftemp = NULL; switch (pDoc->currBox->store.name.at(i)) { case D_FF: Ftemp = new DFlipFlop(dec_x, dec_y); break; case JK_FF: Ftemp = new JKFlipFlop(dec_x, dec_y); break; case T_FF: Ftemp = new TFlipFlop(dec_x, dec_y); break; } if (Ftemp != NULL) { Ftemp->set_Coord_From_outC(dec_x, dec_y); temp = Ftemp; } } else if (pDoc->currBox->store.type.at(i) == LIB) { Box *Btemp = NULL; if (pDoc->currBox->store.name.at(i) == MAIN_LIB); //Btemp = new Box(dec_x, dec_y, &(pDoc->logicBox[0])); else Btemp = new Box(dec_x, dec_y, &(pDoc->logicBox[1])); Btemp->set_Coord_From_outC(dec_x, dec_y); temp = Btemp; } temp->facing = pDoc->currBox->store.facing; temp->set_Coord_ByFacing(temp->facing); pDoc->currBox->logicInfo.push_back(temp); temp = NULL; } pDoc->CheckPoint(); Invalidate(); CUTED = FALSE; } }