//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Simulation_F.h" #include "Main_F.h" #include "treatment.h" #include "YarnCompositionData.h" #include "Palette.h" #include "Viewer.h" #include "GuideBar.h" #include "ProtectCard.h" #include "SimulationAdvSet_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_SIMULATION StringTable[0] #define IDS_SIMULATION_SETTING_MENU StringTable[1] #define IDS_ZOOM StringTable[2] #define IDS_WHOLE_VIEWER StringTable[3] #define IDS_COPY StringTable[4] #define IDS_CPC StringTable[5] #define IDS_WIDTH StringTable[6] #define IDS_FUZZ StringTable[7] #define IDS_BACK StringTable[8] #define IDS_REPEATV StringTable[9] #define IDS_REPEATH StringTable[10] #define IDS_BGCOLOR StringTable[11] #define IDS_INITIALIZING StringTable[12] #define IDS_OPTIMIZING StringTable[13] #define IDS_SIMULATING StringTable[14] #define IDS_TREATING StringTable[15] #define IDS_SAVE StringTable[16] #define IDS_SPANDEX_EFFECT StringTable[17] #define IDS_ADVANCED StringTable[18] //--------------------------------------------------------------------------- TSimulationForm *SimulationForm; //--------------------------------------------------------------------------- __fastcall TSimulationForm::TSimulationForm(TComponent* Owner) : TForm(Owner) { StringTable.Create(BaseDir, Language, "Simulation"); Caption=IDS_SIMULATION; gbSimulation->Caption=IDS_SIMULATION_SETTING_MENU; sbSimulation->Hint=IDS_SIMULATION; lbSimulationW->Caption=IDS_WIDTH; lbCPC->Caption=IDS_CPC; lbFuzz->Caption=IDS_FUZZ; lbBack->Caption=IDS_BACK; lbBGColor->Caption=IDS_BGCOLOR; pmsmZoom->Caption=IDS_ZOOM; pmsmViewer->Caption=IDS_WHOLE_VIEWER; pmsmToClipBoard->Caption=IDS_COPY; pmsmSave->Caption=IDS_SAVE; sbAdvanced->Caption=IDS_ADVANCED; } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::sbSimulationClick(TObject *Sender) { if(image) { MakeImage(); ShowImage(); } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::FormCreate(TObject *Sender) { image = new TTexpiaBitmap; SetFont(); ShowSimulationData(); SavePictureDialog->InitialDir=BaseDir+"\\bmp"; SavePictureDialog->DefaultExt = "bmp"; SavePictureDialog->FileName = "Noname1"; SavePictureDialog->Filter="Bitmaps (*.bmp)|*.bmp|JPEG Image File (*.jpg)|*.jpg"; } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::UpdateMenu(){ //¸Þ´º¿Í ÆË¾÷¸Å´º¸¦ ¾÷µ¥ÀÌÆ®ÇÑ´Ù pmsmx1->Checked=false; pmsmx1_2->Checked=false; pmsmx1_5->Checked=false; pmsmx2->Checked=false; pmsmx4->Checked=false; pmsmx8->Checked=false; pmsmx16->Checked=false; switch(sd.zoom){ case 1: { if(sd.sub_zoom==0){ pmsmx1->Checked=true; } else if(sd.sub_zoom==2){ pmsmx1_2->Checked=true; } else { pmsmx1_5->Checked=true; } break; } case 2: { pmsmx2->Checked=true; break; } case 4: { pmsmx4->Checked=true; break; } case 8: { pmsmx8->Checked=true; break; } case 16: { pmsmx16->Checked=true; break; } default: break; } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::edSWidthKeyPress(TObject *Sender, char &Key) { if(Key==VK_RETURN){ SetSimulationData(); //DrawChart(); if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); sbSimulationClick(NULL); edSCPC->SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::edSCPCKeyPress(TObject *Sender, char &Key) { if(Key==VK_RETURN){ SetSimulationData(); //DrawChart(); if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); sbSimulationClick(NULL); } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmx1Click(TObject *Sender) { sd.zoom=1; sd.sub_zoom=0; SetSimulationData(); UpdateMenu(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmx1_2Click(TObject *Sender) { sd.zoom=1; sd.sub_zoom=2; SetSimulationData(); UpdateMenu(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmx1_5Click(TObject *Sender) { sd.zoom=1; sd.sub_zoom=5; SetSimulationData(); UpdateMenu(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmx2Click(TObject *Sender) { sd.zoom=2; sd.sub_zoom=0; SetSimulationData(); UpdateMenu(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmx4Click(TObject *Sender) { sd.zoom=4; sd.sub_zoom=0; SetSimulationData(); UpdateMenu(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmx8Click(TObject *Sender) { sd.zoom=8; sd.sub_zoom=0; SetSimulationData(); UpdateMenu(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmx16Click(TObject *Sender) { sd.zoom=16; sd.sub_zoom=0; SetSimulationData(); UpdateMenu(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::edFuzzKeyPress(TObject *Sender, char &Key) { if(Key==VK_RETURN){ int i=StrToInt(edFuzz->Text); if(i<0)i=0; if(i>99)i=99; edFuzz->Text=IntToStr(i); SetSimulationData(); sbSimulationClick(NULL); } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::spBGColorMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(!Shift.Contains(ssLeft))return; TColor c; PaletteForm->Visible=true; PaletteForm->InitForm(PaletteForm->Palette);//visible »óÅ¿¡¼­ ÃʱâÈ­ÇØ¾ß ½ºÅ©·Ñ¹Ù°¡ ¿òÁ÷¿©Áø´Ù PaletteForm->Visible=false; if(PaletteForm->ShowModal()==mrOk){ spBGColor->Brush->Color=PaletteForm->DIB256Palette->FGColor; SetSimulationData(); sbSimulationClick(NULL); } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::SaveImage(HANDLE hFile, int main_ver, TCompressMethod cm) { DWORD dwWrite; try{ bool existImage=true; if(main_ver>=1){ WriteFile(hFile, &existImage, sizeof(bool), &dwWrite, NULL); WriteFile(hFile, &(image->Width), sizeof(int), &dwWrite, NULL); WriteFile(hFile, &(image->Height), sizeof(int), &dwWrite, NULL); if(main_ver>=4){ WriteFile(hFile, &cm, sizeof(TCompressMethod), &dwWrite, NULL); image->SaveToTexpiaFile(hFile, cm); } else if(main_ver>=3){ image->SaveToTexpiaFile(hFile, cmNone); } } } catch(...){ bool existImage=false; if(main_ver>=1){ WriteFile(hFile, &existImage, sizeof(bool), &dwWrite, NULL); } return; } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::LoadImage(HANDLE hFile, int main_ver){ #ifdef LOCK_HASP if(ProtectCard==NULL){ ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } else { ProtectCard->Read(); ProtectCard->Check(); if (ProtectCard->isHacking) { ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } } #endif #ifdef LOCK_IFC if(ProtectCard==NULL){ ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } else if(!ProtectCard->CheckPassword()) { ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } #endif DWORD dwRead; bool existImage; int w,h; if(main_ver>=1){ ReadFile(hFile, &existImage, sizeof(bool), &dwRead, NULL); if(existImage){ ReadFile(hFile, &w, sizeof(int), &dwRead, NULL); ReadFile(hFile, &h, sizeof(int), &dwRead, NULL); image->Create(w,h, 24); if(main_ver>=4){ TCompressMethod cm = cmNone; ReadFile(hFile, &cm, sizeof(TCompressMethod), &dwRead, NULL); image->LoadFromTexpiaFile(hFile, cm); } else if(main_ver>=3){ image->LoadFromTexpiaFile(hFile, cmNone); } else { image->LoadFromTexpiaFile(hFile, cmZLib); } } } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::cbBackMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { SetSimulationData(); sbSimulationClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmViewerClick(TObject *Sender) { if(image->Height==0||image->Width==0)return; if(image->Width>1280*1.5||image->Height>1024*1.5) { ShowMessage(IDS_MESSAGE_TOO_LARGE_BITMAP_ZOOM_REPEAT); return; } Viewer_F->Width = image->Width+6; Viewer_F->Height = image->Height+25; Viewer_F->Image->Width = image->Width; Viewer_F->Image->Height = image->Height; Viewer_F->Image->Picture->Bitmap->Width = image->Width; Viewer_F->Image->Picture->Bitmap->Height = image->Height; HDC hDC = Viewer_F->Image->Canvas->Handle; HDC dcSrc = image->CreateDC(); BitBlt(hDC,0,0,Viewer_F->Width,Viewer_F->Height,dcSrc,0,0,SRCCOPY); image->DeleteDC(dcSrc); Viewer_F->Show(); Viewer_F->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmToClipBoardClick(TObject *Sender) { BITMAPHANDLE bh; HDC dcSrc = NULL, dcDst = NULL; memset(&bh, 0, sizeof(BITMAPHANDLE)); L_CreateBitmap(&bh, TYPE_CONV, image->Width, image->Height, 24, ORDER_BGR, NULL, TOP_LEFT); dcDst = L_CreateLeadDC(&bh); dcSrc = image->CreateDC(); BitBlt(dcDst, 0, 0, image->Width, image->Height, dcSrc, 0, 0, SRCCOPY); image->DeleteDC(dcSrc); L_DeleteLeadDC(dcDst); dcDst = NULL; L_CopyToClipboard(Handle, &bh); L_FreeBitmap(&bh); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::FormResize(TObject *Sender) { OnChangeSize(); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::OnChangeSize(){ int h=ClientHeight; int w=ClientWidth; Shape3->Left=w-gbSimulation->Width-2; Shape3->Top=2; sbSimulation->Left=Shape3->Left+2; sbSimulation->Top=Shape3->Top+2; gbSimulation->Top=Shape3->Height+4; gbSimulation->Left=w-gbSimulation->Width-2; SimulationScrollBox->Left=2; SimulationScrollBox->Top=2; SimulationScrollBox->Height=h-SimulationScrollBox->Top-6-HorzScrollBar->Height; SimulationScrollBox->Width=w-gbSimulation->Width-8-VertScrollBar->Width; HorzScrollBar->Width=SimulationScrollBox->Width; VertScrollBar->Height=SimulationScrollBox->Height; HorzScrollBar->Top=SimulationScrollBox->Top+SimulationScrollBox->Height+2; VertScrollBar->Left=SimulationScrollBox->Left+SimulationScrollBox->Width+2; VertScrollBar->Top=SimulationScrollBox->Top; HorzScrollBar->Left=SimulationScrollBox->Left; ShowImage(); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::SimulationPopupMenuPopup(TObject *Sender) { UpdateMenu(); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::SetFont(){ SetSmallFont(Font); SetSmallFont(sbSimulation->Font); SetSmallFont(gbSimulation->Font); SetSmallFont(lbSimulationW->Font); SetSmallFont(lbCPC->Font); SetSmallFont(lbFuzz->Font); SetSmallFont(lbBack->Font); SetSmallFont(lbBGColor->Font); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::MakeImage(){ #ifdef LOCK_HASP if(ProtectCard==NULL){ ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } else { ProtectCard->Read(); ProtectCard->Check(); if (ProtectCard->isHacking) { ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } } #endif #ifdef LOCK_IFC if(ProtectCard==NULL){ ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } else if(!ProtectCard->CheckPassword()) { ShowMessage(IDS_MESSAGE_INTERFACE); Application->Terminate(); return; } #endif Main->UpdateForms();//½Ã¹Ä·¹ÀÌ¼Ç ÇÏ´Â µ¿¾È À̹ÌÁö ±úÁü º¹¿ø SetSimulationData(); TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; int width = Main->texlayer->complete_needle; int height = Main->maindata.course; int tm_width = (int)(sd.RDistX*(double)width)*sd.rW; int tm_height = (int)(sd.RDistY*(double)height)*sd.rH; try { image->Create(tm_width, tm_height, 24); } catch(...){ ShowMessage(IDS_MESSAGE_TOO_LARGE_BITMAP_ZOOM_REPEAT); return; } TexLayer *texlayer = Main->texlayer; Tricot *tricot = new Tricot(width, height, ((int)(sd.RDistX*(double)width))/(double)width, ((int)(sd.RDistY*(double)height))/(double)height); //(½ÇÁ¦ ºñÆ®¸ÊÀÇ Æø) = (int)(sd.RDistX*(double)width) //(ÇÑ Ä­ÀÇ °£°Ý) = (½ÇÁ¦ ºñÆ®¸ÊÀÇ Æø)/(double)width = ((int)(sd.RDistX*(double)width))/(double)width Yarnmap *yarnmap = new Yarnmap(sd.RDistX*(double)width, sd.RDistY*(double)height, (double)sd.zoom+sd.sub_zoom/10.0, sd.back, sd.fuzz, sd.c); ProgressPercentage *percent = new ProgressPercentage(this, ""); //texlayer->MakeYarnImage(); percent->Reset(IDS_INITIALIZING); tricot->InitTricot(texlayer, percent); Treatment_F->PreTreat(tricot);//OptimizeÇϱâÀü¿¡ pileÀ» ÀÏÀ¸Å°´Â ´Ù¸®¸¦ NO_LEG·Î.. percent->Reset(IDS_OPTIMIZING); tricot->Optimize(sd.optimization, sd.span_effect, percent); yarnmap->MappingTricot(tricot);//MappingOctopus¸¦ ÀÛµ¿½ÃŲ´Ù percent->Reset(IDS_SIMULATING); yarnmap->Draw(image,percent);//ºñÆ®¸Ê¿¡ ±×¸°´Ù percent->Reset(IDS_SPANDEX_EFFECT); yarnmap->SpandexEffect(image, sd.span_effect, sd.span_power, sd.span_invert, percent);//½ºÆÇ È¿°ú¸¦ ¸í¾ÏÀ» ÀÌ¿ëÇÏ¿© ³ÖÀ»°Í.. percent->Reset(IDS_TREATING); Treatment_F->FinalTreat(image,sd.RDistX*(double)width,sd.RDistY*(double)height,percent);//¸ðµç󸮰¡ ³¡³ª°í Èİ¡°ø ÆûÀÇ µ¥ÀÌŸ¸¦ °¡Áö°í Èİ¡°øÀ» ½ÃÇà delete percent; delete yarnmap; delete tricot; Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::ShowImage(){ if(image){ try{ SImage->Top=0; SImage->Left=0; SImage->Picture->Bitmap->Width = min(image->Width,SimulationScrollBox->Width); SImage->Picture->Bitmap->Height = min(image->Height,SimulationScrollBox->Height); if(image->Width>SimulationScrollBox->Width){ HorzScrollBar->Max=image->Width-SimulationScrollBox->Width; } else { HorzScrollBar->Max=0; } if(image->Height>SimulationScrollBox->Height){ VertScrollBar->Max=image->Height-SimulationScrollBox->Height; } else { VertScrollBar->Max=0; } } catch(...){ ShowMessage(IDS_MESSAGE_TOO_LARGE_BITMAP_ZOOM_REPEAT); return; } HDC hDC = image->CreateDC(); BitBlt(SImage->Canvas->Handle,0,0,SImage->Width,SImage->Height, hDC,HorzScrollBar->Position,VertScrollBar->Position, SRCCOPY); image->DeleteDC(hDC); SImage->Repaint(); } else { SImage->Picture->Bitmap->Width=0; SImage->Picture->Bitmap->Height=0; SImage->Width=0; SImage->Height=0; SImage->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::SetSimulationData(){ if(edSWidth->Text=="")edSWidth->Text="0"; if(edSCPC->Text=="")edSCPC->Text="0"; if(StrToFloat(edSWidth->Text)<1)edSWidth->Text="1"; if(StrToFloat(edSCPC->Text)<5)edSCPC->Text="5"; if(StrToFloat(edSCPC->Text)>100)edSCPC->Text="100"; sd.width = StrToFloat(edSWidth->Text); sd.gauge=Main->maindata.width*Main->maindata.gauge/sd.width; sd.cpc = StrToFloat(edSCPC->Text); sd.fuzz = StrToInt(edFuzz->Text); sd.back = cbBack->Checked; sd.c = spBGColor->Brush->Color; int width = Main->texlayer->complete_needle; int height = Main->maindata.course; //sd.zoom sd.RDistX = 2.54*(double)DOT_PER_CM/(double)sd.gauge*(double)(sd.zoom+sd.sub_zoom/10.0);// DOT_PER_CM //¼¾Æ¼¹ÌÅÍ´ç µµÆ® sd.RDistY = (double)DOT_PER_CM/sd.cpc*(double)(sd.zoom+sd.sub_zoom/10.0); sd.rW = SimulationScrollBox->Width/(sd.RDistX*(double)width)+1; sd.rH = SimulationScrollBox->Height/(sd.RDistY*(double)height)+1; } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::ShowSimulationData(){ SimulationForm->edSWidth->Text=MyFloatToStr(sd.width,2); SimulationForm->edSCPC->Text=MyFloatToStr(sd.cpc,2); SimulationForm->cbBack->Checked=sd.back; SimulationForm->edFuzz->Text=IntToStr(sd.fuzz); SimulationForm->spBGColor->Brush->Color=sd.c; } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::New(){ if(image)image->Destroy(); SImage->Picture->Bitmap->Width=0; SImage->Picture->Bitmap->Height=0; SImage->Width=0; SImage->Height=0; SImage->Repaint(); sd.reset(); ShowSimulationData(); SimulationAdvSetForm->SetData(); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::FormDestroy(TObject *Sender) { if(image) { delete image; image = NULL; } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::VertScrollBarChange(TObject *Sender) { ShowImage(); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::HorzScrollBarChange(TObject *Sender) { ShowImage(); } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::pmsmSaveClick(TObject *Sender) { if (SavePictureDialog->Execute()) { if(SavePictureDialog->FilterIndex==1){ image->SaveToFile(SavePictureDialog->FileName, FILE_BMP); } else if(SavePictureDialog->FilterIndex==2){ image->SaveToFile(SavePictureDialog->FileName, FILE_JFIF, 2);//2´Â ¹«¼Õ½Ç } } } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::sbAdvancedClick(TObject *Sender) { if(SimulationAdvSetForm->Visible)SimulationAdvSetForm->Visible=false; else SimulationAdvSetForm->Visible=true; } //--------------------------------------------------------------------------- void __fastcall TSimulationForm::FormShow(TObject *Sender) { static bool first=true; if(first){ POINT p=Main->ClientToScreen(Point(0,0)); Top=p.y+(Main->ClientHeight-6)/2+4; Height=(Main->ClientHeight-6)/2; Left=p.x+2; Width=(Main->ClientWidth-209-6)/2; } first=false; } //---------------------------------------------------------------------------