//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "Stripe_F.h" #include "FileManager_F.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #include "FullView.h" #include "Main.h" #include "MainMenu.h" #include "Define.h" #include "UserColor_F.h" #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Rulers" #pragma link "RzCmboBx" #pragma link "TNumEdit" #pragma link "TPImage" #pragma link "TPTextileImage" #pragma link "RzButton" #pragma link "RzGrids" #pragma link "RzLabel" #pragma link "RzPanel" #pragma link "RzTrkBar" #pragma link "RzBckgnd" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_STRIPEMAKER StringTable[0] #define IDS_AMENDMENT StringTable[1] #define IDS_NEW StringTable[2] #define IDS_ADDSTRIPE StringTable[3] #define IDS_DELETESTRIPE StringTable[4] #define IDS_PREVIEW StringTable[5] #define IDS_SPREADVIEW StringTable[6] #define IDS_PART StringTable[7] #define IDS_BRINGTOIMAGE StringTable[8] #define IDS_TOP StringTable[9] #define IDS_BOTTOM StringTable[10] #define IDS_ONEREPEAT StringTable[11] #define IDS_THICKNESS StringTable[12] #define IDS_RATIO StringTable[13] #define IDS_OVERLENWID StringTable[14] #define IDS_SUPER StringTable[15] #define IDS_WARPLENGTH StringTable[16] #define IDS_WEFTLENGTH StringTable[17] #define IDS_WARP StringTable[18] #define IDS_WEFT StringTable[19] #define IDS_SAME StringTable[20] #define IDS_DELETEWARP StringTable[21] #define IDS_DELETEWEFT StringTable[22] #define IDS_GAUZEMODE StringTable[23] #define IDS_MIXTUREMODE StringTable[24] #define IDS_PALETTEERROR StringTable[25] #define IDS_MSG_00 StringTable[26] #define IDS_INSERTSTATE StringTable[27] //--------------------------------------------------------------------------- #define CM_PER_INCH 2.54 TStripeForm *StripeForm; //--------------------------------------------------------------------------- __fastcall TStripeForm::TStripeForm(TComponent* Owner) : TForm(Owner) { BEGIN_LOG(""); hWnd = ((TWinControl *)Owner)->Handle; //=========================================================== // Font ¼³Á¤ ////////////////////////////////////////////////////// StringTable.Create(DirectoryBin, Language, "Stripe"); SetSmallFont(Font); SetSmallFont(sttxtRatio->Font); SetSmallFont(sttxtWarpLength->Font); SetSmallFont(sttxtWeftLength->Font); rzgrdWarp->Canvas->Font = rzgrdWarp->Font; rzgrdWeft->Canvas->Font = rzgrdWeft->Font; ////////////////////////////////////////////////////// // Text ¼³Á¤ ////////////////////////////////////////////////////// Caption = IDS_STRIPEMAKER; rzgrbxAmendment->Caption = IDS_AMENDMENT; spbtnAdd->Hint = IDS_ADDSTRIPE; spbtnDelete->Hint = IDS_DELETESTRIPE; spbtnMakeSame->Hint = IDS_SAME; spbtnDeleteWarp->Hint = IDS_DELETEWARP; spbtnDeleteWeft->Hint = IDS_DELETEWEFT; spbtnDeleteAll->Hint = IDS_NEW; rzbbtnSpreadView->Caption = IDS_SPREADVIEW; rzlblSize->Caption = IDS_COMMON_SIZE; rzcbobxSize->Items->Strings[0] = IDS_PART; rzcbobxSize->Items->Strings[1] = IDS_COMMON_WHOLE; rzcbobxSize->Text = IDS_PART; rzbbtnOneRepeat->Caption = IDS_ONEREPEAT; rzbbtnWhole->Caption = IDS_COMMON_WHOLE; rzlblThickness->Caption = IDS_THICKNESS; rzlblAngle->Caption = IDS_COMMON_ANGLE;// + "(Deg.)"; rzlblThickUnit->Caption = "Cm"; rzlblRatio->Caption = IDS_RATIO; rzlblWarpLength->Caption = IDS_WARPLENGTH; rzlblWeftLength->Caption = IDS_WEFTLENGTH; rzbbtnRun->Caption = IDS_COMMON_RUN; spbtnExit->Hint = IDS_COMMON_EXIT; spbtnFile->Hint = IDS_COMMON_FILE; rzcbobxMethod->Items->Strings[0] = IDS_GAUZEMODE; rzcbobxMethod->Items->Strings[1] = IDS_MIXTUREMODE; rzcbobxMethod->ItemIndex = 0; ////////////////////////////////////////////////////// END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::FormClose(TObject *Sender, TCloseAction &Action) { BEGIN_LOG(""); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::FormResize(TObject *Sender) { BEGIN_LOG(""); rzgrdWarp->Width = rzpnlStringGrid->Width / 2; teximgStripePositionChange(NULL); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::InitForm() { BEGIN_LOG(""); UnitItem = MainImageForm->CurrentUnit; rulerWeft->AUnit = UnitItem; rulerWarp->AUnit = UnitItem; ImageBpp = MainImageForm->iMainImage->uBitmap->BitsPerPixel; // ImageBpp °ªÀº Full ÀÌ³Ä 256 ÀÌ³Ä ±¸ºÐ. óÀ½¿¡ ÃʱâÈ­. DPI = MainImageForm->CanvasInfor.DotsPerInch; rulerWeft->DPI = DPI; rulerWarp->DPI = DPI; OrgUseColor = PaletteForm->DIB256Palette->UseColor; SelColorIdx = &(PaletteForm->DIB256Palette->ChoiceIndex); SelColorRGB = &(PaletteForm->DIB256Palette->Palette->ColorData[*SelColorIdx]->RGB); rzgrdWarp->RowCount = 150; rzgrdWeft->RowCount = 150; Left = 4; Top = 30; Visible = true; IsRun = false; OverlapMode = O_GAUZE; rztbrOverlap->Visible = false; nedOverlap->Visible = false; rzcbobxSize->ItemIndex = V_ORGVIEW; IsInsertComplete[S_WARP] = true; IsInsertComplete[S_WEFT] = true; ThickValue = DPI; for(int i = 0; i < 2; i++) { StripeDataList[i] = new TList; StripePartBitmap[i] = new TTexpiaBitmap; } StripeBitmap = new TTexpiaBitmap; ReadSTPIni(); rzgrdWarp->Repaint(); rzgrdWeft->Repaint(); PaintStripeImage(); UpdateTextValue(); UpdateComponentEnabled(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ExitForm() { BEGIN_LOG(""); WriteSTPIni(); for (int gridIdx = 0; gridIdx < 2; gridIdx++) { if (StripeDataList[gridIdx]) { for (int idx = 0; idx < StripeDataList[gridIdx]->Count; idx++) { TStripeData *stripeData = (TStripeData *)StripeDataList[gridIdx]->Items[idx]; delete stripeData; } StripeDataList[gridIdx]->Clear(); } delete StripeDataList[gridIdx]; StripeDataList[gridIdx] = NULL; if (StripePartBitmap[gridIdx]) { delete StripePartBitmap[gridIdx]; StripePartBitmap[gridIdx] = NULL; } delete StripeBitmap; StripeBitmap = NULL; } MainImageForm->iMainImage->SubVisible = false; MainImageForm->iMainImage->SubEnabled = false; Visible = false; if (ImageBpp == 8 && !IsRun) PaletteForm->DIB256Palette->UseColor = OrgUseColor; END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::IsNumber(String str, int col) { if (str == "") return false; else if (str == ".") return false; if (col == C_LENGTH_COL) // Length Column { float num = 0.0; if (TryStrToFloat(str, num)) return true; else return false; } else if (col == C_REPEAT_COL) // Repeat Column { int num = 0; if (TryStrToInt(str, num)) return true; else return false; } else return false; } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::CheckGrid(TRzStringGrid *grid) { BEGIN_LOG(""); // ÀԷ°ªÀÌ 0º¸´Ù Å©¸é return true // ÀԷ°ªÀÌ 0º¸´Ù ÀÛÀ¸¸é return false // ÀԷ°ªÀÌ 0ÀÏ °æ¿ì °Ë»ç // StringGrid¿¡ ÀÔ·ÂµÈ °ªÀÌ À¯È¿ÇÑÁö üũ - by monkman (2009.10.08) // Stripe Áß Àû¾îµµ ÇÑ ¶óÀÎÀº Length * Repeat ÀÌ 0ÀÌ µÇÁö ¾Êµµ·Ï Çϸç // ¸ðµç Strip´Â RepeatÀÌ 0ÀÌ µÇÁö ¾Ê°Ô ÀԷ¹޴´٠TList *stripeDataList = StripeDataList[grid->Tag]; if (stripeDataList) { float gridData = 0.0; if (grid->Row > stripeDataList->Count) { END_LOG; return true; } if(TryStrToFloat(grid->Cells[grid->Col][grid->Row], gridData)) { if (gridData > 0) { END_LOG; return true; } else if (gridData < 0) { END_LOG; return false; } } float totalLength = 0.0; for (int dataIdx = 0; dataIdx < stripeDataList->Count && dataIdx < grid->RowCount; dataIdx++) { if (dataIdx == grid->Row - 1) continue; TStripeData *stripeData = (TStripeData *)stripeDataList->Items[dataIdx]; totalLength += (stripeData->LengthDot * stripeData->Repetition); } // ¸ðµç µ¥ÀÌÅ͵éÀ» Á¶»ç ÇÑ °á°ú Length * RepeatÀÇ ÇÕÀÌ 0 ÀÌÇÏÀÏ ¶§ ÇöÀç ¼±ÅÃµÈ µ¥ÀÌŸ¸¦ ¼öÁ¤ if (totalLength <= 0) { if (grid->Col != C_REPEAT_COL) { switch (UnitItem) { case uDot: grid->Cells[C_LENGTH_COL][grid->Row] = DPI / CM_PER_INCH + 0.5; break; case uInch: grid->Cells[C_LENGTH_COL][grid->Row] = 1 / CM_PER_INCH; break; case uCm: grid->Cells[C_LENGTH_COL][grid->Row] = 1.0; break; } } if (grid->Col != C_LENGTH_COL) { grid->Cells[C_REPEAT_COL][grid->Row] = 1; } } } END_LOG; return true; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::InputData(TRzStringGrid *grid) { BEGIN_LOG(""); TList *stripeDataList = StripeDataList[grid->Tag]; if (grid->Row > stripeDataList->Count) { END_LOG; return; } if (IsNumber(grid->Cells[grid->Col][grid->Row], grid->Col)) { if (CheckGrid(grid) == false) { END_LOG; return; } // StringStringGrid¿¡ ÀÔ·ÂµÈ °ªÀÌ À¯È¿ÇÑÁö üũ - by monkman (2009.10.08) float gridData = 0.0; if(TryStrToFloat(grid->Cells[grid->Col][grid->Row], gridData)) { TStripeData *stripeData = (TStripeData *) stripeDataList->Items[grid->Row - 1]; if (grid->Col == C_LENGTH_COL) { switch (UnitItem) { case uDot: stripeData->LengthDot = gridData; stripeData->LengthInch = gridData / DPI; stripeData->LengthCm = gridData * CM_PER_INCH / DPI; break; case uInch: stripeData->LengthDot = gridData * DPI + 0.5; stripeData->LengthInch = gridData; stripeData->LengthCm = gridData * CM_PER_INCH; break; case uCm: stripeData->LengthDot = gridData * DPI / CM_PER_INCH + 0.5; stripeData->LengthInch = gridData / CM_PER_INCH; stripeData->LengthCm = gridData; break; } } else if (grid->Col == C_REPEAT_COL) { stripeData->Repetition = (int)gridData; } } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::InitData(EStripeType option) { BEGIN_LOG(""); //option = 0: °æ»ç »èÁ¦, 1: À§»ç »èÁ¦, 2: Àüü »èÁ¦ for (int gridIdx = 0; gridIdx < 2; gridIdx++) { if (option == 0 && gridIdx > 0) break; else if(option == 1 && gridIdx == 0) continue; for (int i = 0; i < StripeDataList[gridIdx]->Count; i++) { TStripeData *stripeData = (TStripeData *)StripeDataList[gridIdx]->Items[i]; delete stripeData; } StripeDataList[gridIdx]->Clear(); IsInsertComplete[gridIdx] = true; } if (option == S_ALL && ImageBpp == 8) PaletteForm->DIB256Palette->UseColor = OrgUseColor; END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::CheckRange() { BEGIN_LOG(""); float angle = 0; if (TryStrToFloat(rzcbobxAngle->Text, angle) == false) { angle = 0.0; rzcbobxAngle->Text = "0"; } angle *= M_PI / 180; int width = abs(long(StripeBitmap->Width * cos(angle))) + abs(long(StripeBitmap->Height * sin(angle))); int height = abs(long(StripeBitmap->Width * sin(angle))) + abs(long(StripeBitmap->Height * cos(angle))); if (width > MainImageForm->iMainImage->uBitmap->Width || height > MainImageForm->iMainImage->uBitmap->Height) { END_LOG; return false; } else { END_LOG; return true; } } //--------------------------------------------------------------------------- String __fastcall TStripeForm::STPOnFileName(String fileName, TGraphicFileFormat ExtIndex) { BEGIN_LOG(""); String fileExtension = L".stp"; if(LowerCase(ExtractFileExt(fileName)) == fileExtension) { END_LOG; return fileName; } else { END_LOG; return fileName + fileExtension; } } //--------------------------------------------------------------------------- TPException __fastcall TStripeForm::STPOnSave(String DirName, String FileName, TGraphicFileFormat ExtIndex, TCompressMethod cm) { BEGIN_LOG(""); if (IsInsertComplete[S_WARP] == false || IsInsertComplete[S_WEFT] == false) { MessageDlg(IDS_MESSAGE_INSERTCOLOR,mtConfirmation, TMsgDlgButtons()<CanvasInfor; tpfh.BitsPerPixel = ImageBpp; tpfh.Compress = cm; // tag bitmap ÃʱâÈ­ RGBQUAD rgb[256]; PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); if ((tagBitmap = new TTexpiaBitmap) == NULL) throw EC_MEMORY_LACK; if (tagBitmap->Create(80, 100, ImageBpp, rgb) == false) throw EC_MEMORY_LACK; if ((tagCanvas = tagBitmap->CreateCanvas()) == NULL) throw EC_RESOURCE_LACK; if (ImageBpp == 8) tagCanvas->Brush->Color = clWhite; else tagCanvas->Brush->Color = RGB2TColor(255, 255, 255); tagCanvas->FillRect(Rect(0, 0, 80, 100)); // tag bitmap º¹»ç if (StripeBitmap->Width > 0 && StripeBitmap->Height > 0) { if ((srcDC = StripeBitmap->CreateDC()) == NULL) throw EC_RESOURCE_LACK; SetStretchBltMode(tagCanvas->Handle, COLORONCOLOR); StretchBlt(tagCanvas->Handle, 0, 0, 80, 100, srcDC, 0, 0, StripeBitmap->Width, StripeBitmap->Height, SRCCOPY); StripeBitmap->DeleteDC(srcDC); srcDC = NULL; tagBitmap->DeleteCanvas(tagCanvas); tagCanvas = NULL; } else { BitBlt(tagCanvas->Handle, 0, 0, 80, 100, NULL, 0, 0, WHITENESS); } // tag bitmap ÀúÀå if (SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tagBitmap, (TUnionBitmap *)NULL) == false) throw EC_FILE_NOT_WRITE; // Union°úÀÇ Ambiguity Á¦°Å 2003-03-17 by celberus delete tagBitmap; tagBitmap = NULL; // TextileVersion 302 ºÎÅÍ Stripe VersionÀ» º°µµ·Î ÀúÀå int stripeVersion = 100; if (WriteFile(hFile, &stripeVersion, sizeof(int), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; // Stripe Data ÀúÀå for (int gridIdx = 0; gridIdx < 2; gridIdx++) { short dataCnt = StripeDataList[gridIdx]->Count; if (WriteFile(hFile, &dataCnt, sizeof(short), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; for (int dataIdx = 0; dataIdx < dataCnt; dataIdx++) { TStripeData *stripeData = (TStripeData *)StripeDataList[gridIdx]->Items[dataIdx]; if (ImageBpp == 8) { if (WriteFile(hFile, &stripeData->ColorIdx, sizeof(Byte), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; } else // stp ÆÄÀÏ¿¡ RGBQUAD Çü Ãß°¡ by tmddn85 { if (WriteFile(hFile, &stripeData->ColorRGB.rgbBlue, sizeof(BYTE), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; if (WriteFile(hFile, &stripeData->ColorRGB.rgbGreen, sizeof(BYTE), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; if (WriteFile(hFile, &stripeData->ColorRGB.rgbRed, sizeof(BYTE), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; } if (WriteFile(hFile, &stripeData->Method, sizeof(EMethodItem), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; if (stripeData->LengthDot < 0) stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; if (stripeData->Repetition < 0) stripeData->Repetition = 1; if (WriteFile(hFile, &stripeData->Repetition, sizeof(short), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; if (WriteFile(hFile, &stripeData->LengthDot, sizeof(short), &dwWrite, NULL) == false) throw EC_FILE_NOT_WRITE; } } CloseHandle(hFile); END_LOG; return EC_NONE; } catch (TPException ec) { if (srcDC) StripeBitmap->DeleteDC(srcDC); if (tagBitmap) { if (tagCanvas) tagBitmap->DeleteCanvas(tagCanvas); delete tagBitmap; } if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); DeleteFile(FullPathName(DirName, FileName).c_str()); SAVE_EXCEPTION(ec); END_LOG; return ec; } } //--------------------------------------------------------------------------- TPException __fastcall TStripeForm::STPOnRead(TFMReadParameter rp, bool changeFileFormat) { BEGIN_LOG(""); TEXPIAFILEHEADER tpfh; TPalette *tempPalette = NULL; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; int stripeVersion = 0; try { if ((hFile = CreateFile(FullPathName(rp.DirName, rp.FileName).c_str(),GENERIC_READ, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) throw EC_FILE_NOT_OPEN; if ((tempPalette = new TPalette) == NULL) throw EC_MEMORY_LACK; TPException ec = LoadFromTexpiaFile(hFile, tempPalette, tpfh, (TUnionBitmap*)NULL, FindExtension(ExtractFileExt(rp.FileName))); if (ec == EC_FILE_NOT_OPEN_NEWERVERSION) { throw ec; } else if (ec != EC_NONE) { throw EC_MEMORY_LACK; } UserColorLibForm->ThisFileHasUserColor(tempPalette); if (ImageBpp == 8) // 256 Color { if (tpfh.BitsPerPixel != 8) // Full Color ¸ðµå stp ¿­Áö ¸øÇÏ°Ô Çϱâ À§ÇØ by david { Application->MessageBox(IDS_MSG_00.c_str(), L"Warning", MB_OK); // "Full Color ¸ðµå ÆÄÀÏÀº ¿­ ¼ö ¾ø½À´Ï´Ù !" CloseHandle(hFile); END_LOG; return EC_NONE; } int useColorCnt = PaletteForm->DIB256Palette->Palette->UseColor; int colorMapTable[252]; for (int i = 0; i < 252; i++) colorMapTable[i] = -1; // Stripe Version Àбâ if (tpfh.Version.Texpia == 'P' && tpfh.Version.Method == 'T' && tpfh.Version.Number >= 302) { if (ReadFile(hFile, &stripeVersion, sizeof(int), &dwRead, NULL) == false) throw EC_FILE_NOT_WRITE; } else { stripeVersion = 0; } InitData(S_ALL);//by bomchun ¼öÁ¤ for (int gridIdx = 0; gridIdx < 2; gridIdx++) { short dataCnt = 0; if (ReadFile(hFile, &dataCnt, sizeof(short), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; // if ((useColorCnt + dataCnt) > 251) throw EC_COLOR_OVERFLOW; for (int dataIdx = 0; dataIdx < dataCnt; dataIdx++) { TStripeData *stripeData = new TStripeData; if (ReadFile(hFile, &stripeData->ColorIdx, sizeof(Byte), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (ReadFile(hFile, &stripeData->Method, sizeof(EMethodItem), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (ReadFile(hFile, &stripeData->Repetition, sizeof(short), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (ReadFile(hFile, &stripeData->LengthDot, sizeof(short), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (stripeData->LengthDot < 0) stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; if (stripeData->Repetition < 0) stripeData->Repetition = 1; stripeData->LengthInch = (float)stripeData->LengthDot / DPI; stripeData->LengthCm = (float)stripeData->LengthDot * CM_PER_INCH / DPI; /////////////////// if (gridIdx == S_WARP && (tpfh.Version.Texpia != 'P' || tpfh.Version.Method != 'T')) //by bomchun Å×½ºÆ® { if (SetFilePointer(hFile, 2, NULL, FILE_CURRENT) == 0xFFFFFFFF) throw EC_FILE_NOT_READ; } /////////////////// stripeData->Valid = true; // useColorCnt++; // PaletteForm->DIB256Palette->Palette->ColorData[useColorCnt]->Copy(tempPalette->ColorData[stripeData->ColorIdx]); // stripeData->ColorIdx = useColorCnt; if (colorMapTable[stripeData->ColorIdx] < 0) { if (useColorCnt > 250) throw EC_COLOR_OVERFLOW; useColorCnt++; PaletteForm->DIB256Palette->Palette->ColorData[useColorCnt]->Copy(tempPalette->ColorData[stripeData->ColorIdx]); colorMapTable[stripeData->ColorIdx] = useColorCnt; } StripeDataList[gridIdx]->Add(stripeData); } if (gridIdx == S_WARP) { if (stripeVersion < 100) { short temp = 10000; if (ReadFile(hFile, &temp, sizeof(short), &dwRead, NULL) == false || temp != 10000) break; } } } for (int gridIdx = 0; gridIdx < 2; gridIdx++) { for (int dataIdx = 0; dataIdx < StripeDataList[gridIdx]->Count; dataIdx++) { TStripeData *stripeData = static_cast(StripeDataList[gridIdx]->Items[dataIdx]); stripeData->ColorIdx = colorMapTable[stripeData->ColorIdx]; } } //NewUseColor = useColorCnt; PaletteForm->DIB256Palette->Palette->UseColor = useColorCnt; PaletteForm->DIB256Palette->Palette->ColorCount = useColorCnt + 1; } else // Full Color { // Stripe Version Àбâ if (tpfh.Version.Texpia == 'P' && tpfh.Version.Method == 'T' && tpfh.Version.Number >= 302) { if (ReadFile(hFile, &stripeVersion, sizeof(int), &dwRead, NULL) == false) throw EC_FILE_NOT_WRITE; } else { stripeVersion = 0; } InitData(S_ALL);//by bomchun ¼öÁ¤ for (int gridIdx = 0; gridIdx < 2; gridIdx++) { short dataCnt = 0; if (ReadFile(hFile, &dataCnt, sizeof(short), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; for (int dataIdx = 0; dataIdx < dataCnt; dataIdx++) { TStripeData *stripeData = new TStripeData; if (tpfh.BitsPerPixel == 8) //256ÆÄÀÏÀ» ¿­ °æ¿ì by david { if (ReadFile(hFile, &stripeData->ColorIdx, sizeof(Byte), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; stripeData->ColorRGB = tempPalette->ColorData[stripeData->ColorIdx]->RGB; } else // full color fileÀ» ¿­ °æ¿ì { if (ReadFile(hFile, &stripeData->ColorRGB.rgbBlue, sizeof(BYTE), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (ReadFile(hFile, &stripeData->ColorRGB.rgbGreen, sizeof(BYTE), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (ReadFile(hFile, &stripeData->ColorRGB.rgbRed, sizeof(BYTE), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; } if (ReadFile(hFile, &stripeData->Method, sizeof(EMethodItem), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (ReadFile(hFile, &stripeData->Repetition, sizeof(short), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (ReadFile(hFile, &stripeData->LengthDot, sizeof(short), &dwRead, NULL) == false) throw EC_FILE_NOT_READ; if (stripeData->LengthDot < 0) stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; if (stripeData->Repetition < 0) stripeData->Repetition = 1; stripeData->LengthInch = (float)stripeData->LengthDot / DPI; stripeData->LengthCm = (float)stripeData->LengthDot * CM_PER_INCH / DPI; /////////////////// if (gridIdx == S_WARP && (tpfh.Version.Texpia != 'P' || tpfh.Version.Method != 'T')) //by bomchun Å×½ºÆ® { if (SetFilePointer(hFile, 2, NULL, FILE_CURRENT) == 0xFFFFFFFF) throw EC_FILE_NOT_READ; } /////////////////// stripeData->Valid = true; StripeDataList[gridIdx]->Add(stripeData); } if (gridIdx == S_WARP) { if (stripeVersion < 100) { short temp = 10000; if (ReadFile(hFile, &temp, sizeof(short), &dwRead, NULL) == false || temp != 10000) break; } } } } delete tempPalette; CloseHandle(hFile); Visible = true; rzgrdWarp->Repaint(); rzgrdWeft->Repaint(); PaintStripeImage(); UpdateTextValue(); UpdateComponentEnabled(); RepaintColor(); END_LOG; return EC_NONE; } catch (TPException ec) { if (tempPalette) delete tempPalette; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); SAVE_EXCEPTION(ec); END_LOG; return ec; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::WriteSTPIni() { BEGIN_LOG(""); TIniFile *stpIni = NULL; if (ImageBpp == 8) stpIni = new TIniFile(AppDataItem + "\\Stripe.ini"); else stpIni = new TIniFile(AppDataItem + "\\StripeFull.ini"); if (stpIni) { String stripeType; for (int gridIdx = 0; gridIdx < 2; gridIdx++) { TList *dataList = StripeDataList[gridIdx]; if (gridIdx == S_WARP) stripeType = "Warp"; else stripeType = "Weft"; int count = stpIni->ReadInteger("Information", stripeType + " Count", 0); if (dataList->Count < count) { for (int i = dataList->Count; i < count; i++) stpIni->EraseSection(stripeType + IntToStr(i)); } stpIni->WriteInteger("Information", stripeType + " Count", dataList->Count); for (int i = 0; i < dataList->Count; i++) { TStripeData *stripeData = (TStripeData *)dataList->Items[i]; if (stripeData->Valid) { String section = stripeType + IntToStr(i); if (ImageBpp == 8) { stpIni->WriteInteger(section, "Color Index", stripeData->ColorIdx); } else { stpIni->WriteInteger(section, "Color Blue", stripeData->ColorRGB.rgbBlue); stpIni->WriteInteger(section, "Color Green", stripeData->ColorRGB.rgbGreen); stpIni->WriteInteger(section, "Color Red", stripeData->ColorRGB.rgbRed); } stpIni->WriteInteger(section, "Method", (int)stripeData->Method); if (stripeData->LengthDot < 0) stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; if (stripeData->Repetition < 0) stripeData->Repetition = 1; stpIni->WriteInteger(section, "Length", stripeData->LengthDot); stpIni->WriteInteger(section, "Repetition", stripeData->Repetition); } } } stpIni->WriteString("Information", "Angle", rzcbobxAngle->Text); // stpIni->WriteBool("Information", "One Repeat", rzbbtnOneRepeat->Down); delete stpIni; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ReadSTPIni() { BEGIN_LOG(""); TIniFile *stpIni = NULL; if (ImageBpp == 8) stpIni = new TIniFile(AppDataItem + "\\Stripe.ini"); else stpIni = new TIniFile(AppDataItem + "\\StripeFull.ini"); if (stpIni) { String stripeType; for (int gridIdx = 0; gridIdx < 2; gridIdx++) { TList *dataList = StripeDataList[gridIdx]; if (gridIdx == S_WARP) stripeType = "Warp"; else stripeType = "Weft"; int count = stpIni->ReadInteger("Information", stripeType + " Count", 0); for (int i = 0; i < count; i++) { String section = stripeType + IntToStr(i); if (ImageBpp == 8) { int colorIndex = stpIni->ReadInteger(section, "Color Index", 0); //stripeData->ColorIdx = stpIni->ReadInteger(section, "Color Index", 0); //if (PaletteForm->DIB256Palette->UseColor < stripeData->ColorIdx) PaletteForm->DIB256Palette->UseColor = stripeData->ColorIdx; if (PaletteForm->DIB256Palette->ColorCount > colorIndex){ TStripeData *stripeData = new TStripeData; stripeData->ColorIdx = colorIndex; stripeData->Method = (EMethodItem)stpIni->ReadInteger(section, "Method", 0); stripeData->LengthDot = stpIni->ReadInteger(section, "Length", DPI / CM_PER_INCH + 0.5); stripeData->Repetition = stpIni->ReadInteger(section, "Repetition", 1); if (stripeData->LengthDot < 0) stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; if (stripeData->Repetition < 0) stripeData->Repetition = 1; stripeData->LengthInch = (float)stripeData->LengthDot / DPI; stripeData->LengthCm = (float)stripeData->LengthDot * CM_PER_INCH / DPI; stripeData->Valid = true; dataList->Add(stripeData); if (colorIndex > PaletteForm->DIB256Palette->UseColor) PaletteForm->DIB256Palette->UseColor = colorIndex; } } else { TStripeData *stripeData = new TStripeData; stripeData->ColorRGB.rgbBlue = stpIni->ReadInteger(section, "Color Blue", 0); stripeData->ColorRGB.rgbGreen = stpIni->ReadInteger(section, "Color Green", 0); stripeData->ColorRGB.rgbRed = stpIni->ReadInteger(section, "Color Red", 0); stripeData->Method = (EMethodItem)stpIni->ReadInteger(section, "Method", 0); stripeData->LengthDot = stpIni->ReadInteger(section, "Length", DPI / CM_PER_INCH + 0.5); stripeData->Repetition = stpIni->ReadInteger(section, "Repetition", 1); if (stripeData->LengthDot < 0) stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; if (stripeData->Repetition < 0) stripeData->Repetition = 1; stripeData->LengthInch = (float)stripeData->LengthDot / DPI; stripeData->LengthCm = (float)stripeData->LengthDot * CM_PER_INCH / DPI; stripeData->Valid = true; dataList->Add(stripeData); } } } rzcbobxAngle->Text = stpIni->ReadString("Information", "Angle", "0"); // if (stpIni->ReadBool("Information", "One Repeat", true)) // rzbbtnOneRepeat->Down = true; // else // rzbbtnWhole->Down = true; delete stpIni; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ChangeUnit(TUnit newUnit) { BEGIN_LOG(""); if (IsInsertComplete[S_WARP] == false || IsInsertComplete[S_WEFT] == false) { MessageDlg(IDS_MESSAGE_INSERTCOLOR, mtConfirmation, TMsgDlgButtons() << mbOK, 0); } else { if (newUnit != UnitItem) { UnitItem = newUnit; rulerWeft->AUnit = UnitItem; rulerWarp->AUnit = UnitItem; rzgrdWarp->Options >> goEditing; rzgrdWeft->Options >> goEditing; rzgrdWarp->Repaint(); rzgrdWeft->Repaint(); UpdateTextValue(); } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::FGChange(int colorIdx) { BEGIN_LOG(""); SelColorRGB = &(PaletteForm->DIB256Palette->Palette->ColorData[*SelColorIdx]->RGB); // ¼Óµµ°¡ ´À·Á¼­ ÀÏ´Ü ÁÖ¼® ó¸® /*/ Palette¿¡¼­ »öÀ» ¹Ù²Ù¸é Stripe¿¡µµ ¹Ù·Î Àû¿ëµÇµµ·Ï ÇÔ if (ImageBpp == 8) { for (int gridIdx = 0; gridIdx < 2; gridIdx++) { if (StripeDataList[gridIdx]) { for (int dataIdx = 0; dataIdx < StripeDataList[gridIdx]->Count; dataIdx++) { TStripeData *stripeData = (TStripeData *)StripeDataList[gridIdx]->Items[dataIdx]; if (stripeData->ColorIdx == colorIdx) { rzgrdWarp->Repaint(); rzgrdWeft->Repaint(); PaintStripeImage(); return; } } } } } */ END_LOG; } //--------------------------------------------------------------------------- int __fastcall TStripeForm::GetWidth(EStripeType stripeType) { if (stripeType > S_WEFT) return 0; BEGIN_LOG(""); TList *dataList = StripeDataList[stripeType]; int width = 0; int idx = 0; int centerIdx = -1; while (idx < dataList->Count) { TStripeData *stripeData = (TStripeData *)dataList->Items[idx]; if (stripeData->Valid) { width += (stripeData->LengthDot * stripeData->Repetition); if (stripeData->Method == M_CENTER) { int searchIdx = idx - 1; while (searchIdx > centerIdx) { stripeData = (TStripeData *)dataList->Items[searchIdx]; if (stripeData->Valid) { if (stripeData->Method == M_REVERSE) width += (stripeData->LengthDot * stripeData->Repetition); } searchIdx--; } centerIdx = idx; } } idx++; } END_LOG; return width; } //--------------------------------------------------------------------------- int __fastcall TStripeForm::GetHeight(EStripeType stripeType) { if (stripeType > S_WEFT) return 0; BEGIN_LOG(""); int height = 0; if (stripeType == S_WARP) height = GetWidth(S_WEFT); else if (stripeType == S_WEFT) height = GetWidth(S_WARP); if (height == 0) height = ThickValue; END_LOG; return height; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::DrawStripeItem(EStripeType stripeType, Byte *bitmap, int stIdx, int endIdx, int repeatCnt) { if (stripeType > S_WEFT) return; BEGIN_LOG(""); TList *dataList = StripeDataList[stripeType]; int &length = StripeLength[stripeType]; int pos = length * 3; int inc = 1; if (stIdx > endIdx) inc = -1; for (int repeatIdx = 0; repeatIdx < repeatCnt; repeatIdx++) { for (int stripeIdx = stIdx; stripeIdx != endIdx + inc; stripeIdx += inc) { TStripeData *stripeData = (TStripeData *)dataList->Items[stripeIdx]; if (stripeData->Valid == false) continue; if (ImageBpp == 8) // 256 Color { for (int x = length; x < length + stripeData->LengthDot; x++) *(bitmap + x) = stripeData->ColorIdx; } else if (ImageBpp == 24) // Full Color { for (int x = pos; x < pos + 3 * stripeData->LengthDot; x += 3) { *(bitmap + x) = stripeData->ColorRGB.rgbBlue; *(bitmap + x + 1) = stripeData->ColorRGB.rgbGreen; *(bitmap + x + 2) = stripeData->ColorRGB.rgbRed; } pos += (3 * stripeData->LengthDot); } length += stripeData->LengthDot; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::MakeStripePartBitmap(EStripeType stripeType) { if (stripeType > S_WEFT) return; BEGIN_LOG(""); TList *dataList = StripeDataList[stripeType]; TTexpiaBitmap *stripePartBitmap = StripePartBitmap[stripeType]; StripeLength[stripeType] = 0; if (dataList->Count > 0) { int width = GetWidth(stripeType); int height = GetHeight(stripeType); RGBQUAD rgb[256]; PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); try { if (stripePartBitmap->Create(width, height, ImageBpp, rgb) == NULL) throw EC_MEMORY_LACK; } catch(TPException ec) { stripePartBitmap->Destroy(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } if (ImageBpp == 8) { rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; stripePartBitmap->PutColors(0, 256, rgb); } RECT rect = Rect(0, 0, width, height); //by jeegeo if (ImageBpp == 8) stripePartBitmap->FillRect(rect, PALETTEINDEX(255)); else if (ImageBpp == 24) stripePartBitmap->FillRect(rect, RGB2TColor(255,255,255)); // 256À̶û Full À϶§ °¢ÀÚ ¹ÙÅÁ»ö ÁÖ±â try { if (stripePartBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; } catch(TPException ec) { stripePartBitmap->StopScanLine(); stripePartBitmap->Destroy(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } Byte *byteLine = (Byte *)stripePartBitmap->GetScanLine(0); int idx = 0; int centerIdx = -1; while (idx < dataList->Count) { TStripeData *stripeData = (TStripeData *)dataList->Items[idx]; if (stripeData->Valid == false) { idx++; continue; } int repeat = stripeData->Repetition; int stIdx, endIdx, searchIdx; if (stripeData->Method == M_CENTER) // dataÀÇ Method°¡ CENTERÀÎ °æ¿ì { DrawStripeItem(stripeType, byteLine, idx, idx, repeat); searchIdx = idx - 1; while (searchIdx > centerIdx) { stripeData = (TStripeData *)dataList->Items[searchIdx]; if (stripeData->Valid == false) { searchIdx--; continue; } stIdx = searchIdx; endIdx = searchIdx; // dataÀÇ Method°¡ REVERSEÀÎ °æ¿ì CENTER¸¦ Áß½ÉÀ¸·Î ¹Ýº¹Çؼ­ ±×·ÁÁöµµ·Ï ÇÔ. if (stripeData->Method == M_REVERSE) { repeat = stripeData->Repetition; int tempIdx = searchIdx - 1; while (tempIdx > centerIdx) { stripeData = (TStripeData *)dataList->Items[tempIdx]; if (stripeData->Valid == false) { tempIdx--; continue; } if (stripeData->Repetition == repeat && stripeData->Method == M_REVERSE) { endIdx = tempIdx; tempIdx--; } else { endIdx = tempIdx + 1; break; } } DrawStripeItem(stripeType, byteLine, stIdx, endIdx, repeat); } searchIdx = endIdx - 1; } centerIdx = idx; idx++; } else // data ÀÇ Method°¡ CENTERÀÌ ¾Æ´Ñ °æ¿ì { stIdx = idx; endIdx = idx; searchIdx = idx + 1; while (searchIdx < dataList->Count) { stripeData = (TStripeData *)dataList->Items[searchIdx]; if (stripeData->Valid == false) { searchIdx++; continue; } if (stripeData->Repetition == repeat && stripeData->Method != M_CENTER) { endIdx = searchIdx; searchIdx++; } else { endIdx = searchIdx - 1; break; } } idx = endIdx + 1; DrawStripeItem(stripeType, byteLine, stIdx, endIdx, repeat); } } for (int y = 0; y < height; y++) { stripePartBitmap->PutScanLine(y); } stripePartBitmap->StopScanLine(); // À§»ç ½ºÆ®¶óÀÌÇÁÀÇ °æ¿ì °æ»ç¿Í ¶È°°ÀÌ ½ºÆ®¶óÀÌÇÁ¸¦ ¸¸µç ÈÄ 90µµ ȸÀüÀ» ½ÃÄѼ­ À§»ç ÇüÅ·Π¸¸µç´Ù. if (stripeType == S_WEFT) stripePartBitmap->Rotate(9000, true, 0); } END_LOG; } //--------------------------------------------------------------------------- Byte __fastcall TStripeForm::MixColor(Byte base, Byte cover, Byte colorTable[256][256]) { BEGIN_LOG(""); if (ImageBpp == 8) // 256 Color Mode { if (base && cover) { if (base == cover) { END_LOG; return base; } else { Byte useColor = PaletteForm->DIB256Palette->UseColor; if (useColor >= 251) { END_LOG; return 0xFF; } RGBQUAD *baseRGB = &(PaletteForm->DIB256Palette->Palette->ColorData[base]->RGB); RGBQUAD *coverRGB = &(PaletteForm->DIB256Palette->Palette->ColorData[cover]->RGB); // µÎ »öÀ» ºñÀ²¿¡ µû¶ó ¼¯À½ int mixRatio = rztbrOverlap->Position * 63 / 100; RGBQUAD mixedRGB; mixedRGB.rgbBlue = (baseRGB->rgbBlue * (63 - mixRatio) + coverRGB->rgbBlue * mixRatio) / 63; mixedRGB.rgbGreen = (baseRGB->rgbGreen * (63 - mixRatio) + coverRGB->rgbGreen * mixRatio) / 63; mixedRGB.rgbRed = (baseRGB->rgbRed * (63 - mixRatio) + coverRGB->rgbRed * mixRatio) / 63; // µÎ »öÀ» ¼¯¾î ¸¸µç »öÀÌ ÆÈ·¹Æ®¿¡ Á¸ÀçÇÏ´ÂÁö Á¶»ç RGBQUAD rgb[256]; PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); for (int idx = 2; idx <= useColor; idx++) { RGBQUAD *tempRGB = &rgb[idx]; if (tempRGB->rgbBlue == mixedRGB.rgbBlue && tempRGB->rgbGreen == mixedRGB.rgbGreen && tempRGB->rgbRed == mixedRGB.rgbRed) { colorTable[base][cover] = idx; END_LOG; return idx; } } int point = useColor + 1; PaletteForm->DIB256Palette->UseColor = point; RGBQUAD *pointRGB = &(PaletteForm->DIB256Palette->Palette->ColorData[point]->RGB); *pointRGB = mixedRGB; colorTable[base][cover] = point; if (NewUseColor < point) NewUseColor = point; END_LOG; return point; } } else { if (base) { END_LOG; return base; } else { END_LOG; return cover; } } } else // Full Color Mode { if (base == cover) { END_LOG; return base; } else { int mixRatio = rztbrOverlap->Position * 63 / 100; Byte mixedColor = (base * (63 - mixRatio) + cover * mixRatio) / 63; colorTable[base][cover] = mixedColor; END_LOG; return mixedColor; } } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::MakePattern() { if (StripeDataList[S_WARP]->Count == 0 || StripeDataList[S_WEFT]->Count == 0) return; BEGIN_LOG(""); RGBQUAD rgb[256]; TTexpiaBitmap *dstBitmap = StripeBitmap; TTexpiaBitmap *srcBitmap = StripePartBitmap[S_WARP]; // StripeBitmap¿¡ °æ»ç ½ºÆ®¶óÀÌÇÁÀÎ StripePartBimtap[S_WARP]¸¦ copy if (ImageBpp == 8) // 256 Color { PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); dstBitmap->Create(srcBitmap->Width, srcBitmap->Height, ImageBpp, rgb); } else // Full Color { dstBitmap->Create(srcBitmap->Width, srcBitmap->Height, ImageBpp); } dstBitmap->Copy(srcBitmap, SRCCOPY); // À§»ç ½ºÆ®¶óÀÌÇÁ¸¦ srcBitmapÀ¸·Î ¼³Á¤ srcBitmap = StripePartBitmap[S_WEFT]; try { if (dstBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; if (srcBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; } catch(TPException ec) { dstBitmap->StopScanLine(); srcBitmap->StopScanLine(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } COLORREF color; RGBQUAD mixedRGB; Byte colorTable[256][256]; Byte fullColorTable[3][256][256]; Byte savedUseColor = PaletteForm->DIB256Palette->UseColor; NewUseColor = PaletteForm->DIB256Palette->UseColor; if (ImageBpp == 8) memset(colorTable, 0, 256 * 256); else memset(fullColorTable, 0, 3 * 256 * 256); for (int y = 0; y < dstBitmap->Height; y++) { Byte *src = srcBitmap->GetScanLine(y); Byte *dst = dstBitmap->GetScanLine(y); for (int x = 0; x < dstBitmap->Width; x++) { if (ImageBpp == 8) // 256 Color { if (*src > 1) // srcÀÇ Color Index°¡ 2ÀÌ»óÀÏ ¶§ (À¯È¿ÇÑ Color¸¦ °¡Áú ¶§) { if (*dst > 1) // dstÀÇ Color Index°¡ 2ÀÌ»óÀÏ ¶§ (À¯È¿ÇÑ Color¸¦ °¡Áú ¶§) { switch(OverlapMode) { case O_GAUZE: if ((x + y) & 1) *dst = *src; break; case O_MIXTURE: if (colorTable[*dst][*src] == 0) color = MixColor(*dst, *src, colorTable); else color = colorTable[*dst][*src]; if (color == 0xFF) { dstBitmap->StopScanLine(); srcBitmap->StopScanLine(); Application->MessageBox(IDS_PALETTEERROR.c_str(), L"Warning", MB_OK); //OverlapLabelClick(NULL); // ¸Á»çÇüÀ¸·Î ¼³Á¤ÇÔ rzcbobxMethod->ItemIndex = O_GAUZE; END_LOG; return; } else *dst = color; break; } } else *dst = *src; // dst°¡ À¯È¿ÇÑ Color°¡ ¾Æ´Ï¸é src¸¦ ¹«Á¶°Ç copy } src++; dst++; } else // Full Color { switch(OverlapMode) { case O_GAUZE: if ((x + y) & 1) CopyPixel24(dst, src); break; case O_MIXTURE: if (fullColorTable[0][*dst][*src] == 0) mixedRGB.rgbBlue = MixColor(*dst, *src, fullColorTable[0]); else mixedRGB.rgbBlue = fullColorTable[0][*dst][*src]; if (fullColorTable[1][*(dst + 1)][*(src + 1)] == 0) mixedRGB.rgbGreen = MixColor(*(dst + 1), *(src + 1), fullColorTable[1]); else mixedRGB.rgbGreen = fullColorTable[1][*(dst + 1)][*(src + 1)]; if (fullColorTable[2][*(dst + 2)][*(src + 2)] == 0) mixedRGB.rgbRed = MixColor(*(dst + 2), *(src + 2), fullColorTable[2]); else mixedRGB.rgbRed = fullColorTable[2][*(dst + 2)][*(src + 2)]; *dst = mixedRGB.rgbBlue; *(dst + 1) = mixedRGB.rgbGreen; *(dst + 2) = mixedRGB.rgbRed; break; } src += 3; dst += 3; } } dstBitmap->PutScanLine(y); } dstBitmap->StopScanLine(); srcBitmap->StopScanLine(); if (ImageBpp == 8) { PaletteForm->DIB256Palette->Repaint(); PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); dstBitmap->PutColors(0, 256, rgb); StripePartBitmap[S_WARP]->PutColors(0, 256, rgb); StripePartBitmap[S_WEFT]->PutColors(0, 256, rgb); if (OverlapMode == O_MIXTURE) PaletteForm->DIB256Palette->UseColor = savedUseColor; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ViewStripeImage(EViewMode viewMode) { BEGIN_LOG(""); int ratio; switch (viewMode) { case V_ORGVIEW: ratio = 100; break; case V_FULLVIEW: if (StripeBitmap->Width > 0 && StripeBitmap->Height > 0) ratio = min(teximgStripe->Width * 100 / StripeBitmap->Width, teximgStripe->Height * 100 / StripeBitmap->Height); else ratio = 100; break; } sttxtRatio->Caption = Format("%d %%", OPENARRAY(TVarRec, (ratio))); HDC srcDC, dstDC; try { RGBQUAD rgb[256]; if (ImageBpp == 8) { PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; } if (StripeBitmap->Width > 0 && StripeBitmap->Height > 0) { int width, height; if (viewMode == V_ORGVIEW) { width = StripeBitmap->Width; height = StripeBitmap->Height; } else { width = teximgStripe->Width; height = teximgStripe->Height; } if (teximgStripe->Bitmap->Create(width, height, ImageBpp, rgb) == NULL) throw EC_MEMORY_LACK; TRect rect = Rect(0, 0, width, height); if (ImageBpp == 8) teximgStripe->Bitmap->FillRect(rect, PALETTEINDEX(255)); else teximgStripe->Bitmap->FillRect(rect, RGB2TColor(255, 255, 255)); if ((srcDC = StripeBitmap->CreateDC()) == NULL) throw EC_MEMORY_LACK; if ((dstDC = teximgStripe->Bitmap->CreateDC()) == NULL) throw EC_MEMORY_LACK; SetStretchBltMode(dstDC,COLORONCOLOR); StretchBlt(dstDC, 0, 0, StripeBitmap->Width * ratio / 100, StripeBitmap->Height * ratio / 100, srcDC , 0, 0, StripeBitmap->Width, StripeBitmap->Height, SRCCOPY); StripeBitmap->DeleteDC(srcDC); teximgStripe->Bitmap->DeleteDC(dstDC); } else { if (teximgStripe->Bitmap->Create(teximgStripe->Width, teximgStripe->Height, ImageBpp, rgb) == NULL) throw EC_MEMORY_LACK; RECT rect = Rect(0, 0, teximgStripe->Width, teximgStripe->Height); if (ImageBpp == 8) teximgStripe->Bitmap->FillRect(rect, PALETTEINDEX(255)); else teximgStripe->Bitmap->FillRect(rect, RGB2TColor(255, 255, 255)); } } catch(TPException ec) { if (srcDC) StripeBitmap->DeleteDC(srcDC); if (dstDC) teximgStripe->Bitmap->DeleteDC(dstDC); teximgStripe->Bitmap->Destroy(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::SpreadView() { if (StripeBitmap->Width <= 0 || StripeBitmap->Height <= 0) return; BEGIN_LOG(""); int horiRepeatCnt = teximgStripe->Width / StripeBitmap->Width; int vertRepeatCnt = teximgStripe->Height / StripeBitmap->Height; // int horiRemainder = teximgStripe->Width % StripeBitmap->Width; // int vertRemainder = teximgStripe->Height % StripeBitmap->Height; if (horiRepeatCnt == 0) { horiRepeatCnt = 1; // horiRemainder = 0; } if (vertRepeatCnt == 0) { vertRepeatCnt = 1; // vertRemainder = 0; } HDC srcDC, dstDC; try { int width = (StripeBitmap->Width > teximgStripe->Width ? StripeBitmap->Width : teximgStripe->Width); int height = (StripeBitmap->Height > teximgStripe->Height ? StripeBitmap->Height : teximgStripe->Height); TRect rect = Rect(0, 0, width, height); RGBQUAD rgb[256]; if (ImageBpp == 8) { PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; } if (teximgStripe->Bitmap->Create(width, height, ImageBpp, rgb) == NULL) throw EC_MEMORY_LACK; if (ImageBpp == 8) teximgStripe->Bitmap->FillRect(rect, PALETTEINDEX(255)); else teximgStripe->Bitmap->FillRect(rect, RGB2TColor(255, 255, 255)); if ((srcDC = StripeBitmap->CreateDC()) == NULL) throw EC_MEMORY_LACK; if ((dstDC = teximgStripe->Bitmap->CreateDC()) == NULL) throw EC_MEMORY_LACK; }catch(TPException ec) { if (srcDC) StripeBitmap->DeleteDC(srcDC); if (dstDC) teximgStripe->Bitmap->DeleteDC(dstDC); teximgStripe->Bitmap->Destroy(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } TRect dstRect; for (int y = 0; y < vertRepeatCnt + 1; y++) { for (int x = 0; x < horiRepeatCnt + 1; x++) { if (y < vertRepeatCnt && x < horiRepeatCnt) dstRect = Rect(StripeBitmap->Width * x, StripeBitmap->Height * y, StripeBitmap->Width * (x + 1), StripeBitmap->Height * (y + 1)); else if (y < vertRepeatCnt && x == horiRepeatCnt) dstRect = Rect(StripeBitmap->Width * x, StripeBitmap->Height * y, teximgStripe->Width, StripeBitmap->Height * (y + 1)); else if (y == vertRepeatCnt && x < horiRepeatCnt) dstRect = Rect(StripeBitmap->Width * x, StripeBitmap->Height * y, StripeBitmap->Width * (x + 1), teximgStripe->Height); else if(y == vertRepeatCnt && x == horiRepeatCnt) dstRect = Rect(StripeBitmap->Width * x, StripeBitmap->Height * y, teximgStripe->Width, teximgStripe->Height); BitBlt(dstDC, dstRect.Left, dstRect.Top, dstRect.Width(), dstRect.Height(), srcDC, 0, 0, SRCCOPY); } } StripeBitmap->DeleteDC(srcDC); teximgStripe->Bitmap->DeleteDC(dstDC); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::PaintStripeImage(bool bDataUpdated) { BEGIN_LOG(""); NewUseColor = PaletteForm->DIB256Palette->UseColor; if (bDataUpdated) { MakeStripePartBitmap(S_WARP); MakeStripePartBitmap(S_WEFT); } RGBQUAD rgb[256]; PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); if (StripeDataList[S_WARP]->Count > 0 && StripeDataList[S_WEFT]->Count > 0) MakePattern(); else if (StripeDataList[S_WARP]->Count > 0) { StripeBitmap->Create(StripePartBitmap[S_WARP]->Width, StripePartBitmap[S_WARP]->Height, ImageBpp, rgb); StripeBitmap->Copy(StripePartBitmap[S_WARP], SRCCOPY); } else if (StripeDataList[S_WEFT]->Count > 0) { StripeBitmap->Create(StripePartBitmap[S_WEFT]->Width, StripePartBitmap[S_WEFT]->Height, ImageBpp, rgb); StripeBitmap->Copy(StripePartBitmap[S_WEFT], SRCCOPY); } else StripeBitmap->Destroy(); if (StripeBitmap->Width >= teximgStripe->Width && StripeBitmap->Height >= teximgStripe->Height) rzbbtnSpreadView->Enabled = false; else rzbbtnSpreadView->Enabled = true; if (StripeBitmap->Width >= teximgStripe->Width || StripeBitmap->Height >= teximgStripe->Height) rzcbobxSize->Enabled = true; else rzcbobxSize->Enabled = false; if (rzcbobxSize->Enabled) ViewStripeImage(EViewMode(rzcbobxSize->ItemIndex)); else if (rzbbtnSpreadView->Enabled && rzbbtnSpreadView->Down) SpreadView(); else ViewStripeImage(V_ORGVIEW); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::UpdateTextValue() { BEGIN_LOG(""); String unitName = MainImageForm->UnitName(UnitItem); float warpLength, weftLength, thick, defaultThick; switch (UnitItem) { case uDot: warpLength = (float)StripeLength[S_WARP]; weftLength = (float)StripeLength[S_WEFT]; thick = (float)ThickValue; defaultThick = DPI; sttxtWarpLength->Caption = Format("%.0f %s", OPENARRAY (TVarRec, (warpLength, unitName))); sttxtWeftLength->Caption = Format("%.0f %s", OPENARRAY (TVarRec, (weftLength, unitName))); break; case uInch: warpLength = (float)StripeLength[S_WARP] / DPI; weftLength = (float)StripeLength[S_WEFT] / DPI; thick = (float)ThickValue / DPI; defaultThick = 1; sttxtWarpLength->Caption = Format("%.2f %s", OPENARRAY (TVarRec, (warpLength, unitName))); sttxtWeftLength->Caption = Format("%.2f %s", OPENARRAY (TVarRec, (weftLength, unitName))); break; case uCm: warpLength = (float)StripeLength[S_WARP] * CM_PER_INCH / DPI; weftLength = (float)StripeLength[S_WEFT] * CM_PER_INCH / DPI; thick = (float)ThickValue * CM_PER_INCH / DPI; defaultThick = CM_PER_INCH; sttxtWarpLength->Caption = Format("%.2f %s", OPENARRAY (TVarRec, (warpLength, unitName))); sttxtWeftLength->Caption = Format("%.2f %s", OPENARRAY (TVarRec, (weftLength, unitName))); break; } rzlblThickUnit->Caption = unitName; if (thick > 0) nedThick->Value = thick; else nedThick->Value = defaultThick; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::UpdateComponentEnabled() { BEGIN_LOG(""); if (StripeDataList[S_WARP] == NULL || StripeDataList[S_WEFT] == NULL) { END_LOG; return; } if (StripeDataList[S_WARP]->Count > 0 && StripeDataList[S_WEFT]->Count > 0) { rzcbobxMethod->Enabled = true; if (OverlapMode == O_GAUZE) { rztbrOverlap->Visible = false; nedOverlap->Visible = false; } else { rztbrOverlap->Visible = true; nedOverlap->Visible = true; } spbtnAdd->Enabled = true; spbtnDelete->Enabled = true; nedThick->Enabled = false; rzlblThickness->Enabled = false; rzlblThickUnit->Enabled = false; } else { rzcbobxMethod->Enabled = false; rztbrOverlap->Visible = false; nedOverlap->Visible = false; if (StripeDataList[S_WARP]->Count > 0 || StripeDataList[S_WEFT]->Count > 0) { spbtnAdd->Enabled = true; spbtnDelete->Enabled = true; } else { spbtnAdd->Enabled = false; spbtnDelete->Enabled = false; } nedThick->Enabled = true; rzlblThickness->Enabled = true; rzlblThickUnit->Enabled = true; } teximgStripePositionChange(NULL); END_LOG; } //--------------------------------------------------------------------------- COLORREF __fastcall TStripeForm::GetSrcColor(int dstX, int dstY, Extended theta) { BEGIN_LOG(""); //ThetaȸÀüº¯È¯ÀÇ matrix = (cos -sin)(x') = (x) // (sin cos)(y') (y) //Áö±Ý parameterÀÇ x,y´Â ÀÌ¹Ì È¸ÀüÀÌ µÈ »óÅÂÀÇ x,y·Î¼­ ±× ÀÚ¸®¿¡ //¾î¶² »öÀÇ Çȼ¿ÀÌ µé¾î°¡¾ß ÇÏ´ÂÁö°¡ ÀÌ ÇÔ¼ö¿¡¼­ ÇÒ ÀÏ //µû¶ó¼­ ¿ªº¯È¯ matrix = ( cos sin)(x) = (x') // (-sin cos)(y) (y') //À» ÅëÇÏ¿© x',y'ÀÇ À§Ä¡¸¦ ¾Ë¾Æ³»¾ß ÇÑ´Ù. Extended xPrime = dstX * cos(theta) + dstY * sin(theta); Extended yPrime = dstY * cos(theta) - dstX * sin(theta); int srcX = (int)(xPrime + 0.5) % StripeBitmap->Width; int srcY = (int)(yPrime + 0.5) % StripeBitmap->Height; if (srcX < 0) srcX += StripeBitmap->Width; if (srcY < 0) srcY += StripeBitmap->Height; byte *stripeBitmapLine; COLORREF color; if (ImageBpp == 8) { stripeBitmapLine = StripeBitmap->GetScanLine(srcY); color = stripeBitmapLine[srcX]; } else { stripeBitmapLine = StripeBitmap->GetScanLine(srcY) + 3 * srcX; GetPixel24(stripeBitmapLine, color); } END_LOG; return color; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::RunWholeImage() { if (StripeBitmap->Width <= 0 || StripeBitmap->Height <= 0) return; BEGIN_LOG(""); TPItemImage *mainImage = MainImageForm->iMainImage; Extended theta = StrToInt(rzcbobxAngle->Text); theta = DegToRad(theta); theta = 2 * M_PI - theta; int bytePerPixel; if (ImageBpp == 8) bytePerPixel = 1; else bytePerPixel = 3; try { if (mainImage->uBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; if (StripeBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; if (mainImage->LayerMask) { if (mainImage->LayerMask->StartScanLine() == false) throw EC_MEMORY_LACK;} } catch(TPException ec) { mainImage->uBitmap->StopScanLine(); StripeBitmap->StopScanLine(); if (mainImage->LayerMask) mainImage->LayerMask->StopScanLine(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } Byte *uBitmapLine, *layerMaskLine; for (int y = 0; y < mainImage->uBitmap->Height; y++) { uBitmapLine = mainImage->uBitmap->GetScanLine(y); if (mainImage->LayerMask) layerMaskLine = mainImage->LayerMask->GetScanLine(y); for (int x = 0; x < mainImage->uBitmap->Width; x++, uBitmapLine += bytePerPixel) { if (ImageBpp == 8) { if (PaletteForm->DIB256Palette->Palette->ColorData[*uBitmapLine]->Protect == 0 // »öº¸È£ »óŰ¡ ¾Æ´Ï¸é º¸¿©Áöµµ·Ï - by monkman (2009.10.08) || (PaletteForm->DIB256Palette->Palette->ColorData[*uBitmapLine]->Protect != 0 && MainImageForm->bProtect == false)) { *uBitmapLine = GetSrcColor(x, y, theta); if (mainImage->LayerMask) *(layerMaskLine + x) = 0; } } else { COLORREF color = GetSrcColor(x, y, theta); SetPixel24(uBitmapLine, color); if (mainImage->LayerMask) { *(layerMaskLine + (x >> 3)) &= ~(0x80 >> (x & 7)); } } } mainImage->uBitmap->PutScanLine(y); if (mainImage->LayerMask) mainImage->LayerMask->PutScanLine(y); } mainImage->uBitmap->StopScanLine(); StripeBitmap->StopScanLine(); if (mainImage->LayerMask) mainImage->LayerMask->StopScanLine(); RepaintColor(); END_LOG; } //--------------------------------------------------------------------------- COLORREF __fastcall TStripeForm::SearchFillColor() { BEGIN_LOG(""); COLORREF color; Byte rgb[3][256]; memset(rgb, 0, 256 * 3); try { if (StripeBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; } catch (TPException ec) { StripeBitmap->StopScanLine(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return 0; } for (int y = 0; y < StripeBitmap->Height; y++) { Byte *stripeBimtapLine = StripeBitmap->GetScanLine(y); for (int x = 0; x < StripeBitmap->Width; x++, stripeBimtapLine += 3) { GetPixel24(stripeBimtapLine, color); Byte r = color & 0xFF; Byte g = (color >> 8) & 0xFF; Byte b = (color >> 16) & 0xFf; rgb[0][r] = 1; rgb[0][g] = 1; rgb[0][b] = 1; } } StripeBitmap->StopScanLine(); for (int i = 0; i < 3; i++) { for(int j = 0; j < 256; j++) if (rgb[i][j] == 0) { END_LOG; return 0x00000000 | (j << (i * 8)); } } END_LOG; return 0; } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::RunOneRepeatImage() { if (StripeBitmap->Width <= 0 || StripeBitmap->Height <= 0) return false; BEGIN_LOG(""); TPItemImage *mainImage = MainImageForm->iMainImage; RGBQUAD rgb[256]; PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); int angle = 0; if (TryStrToInt(rzcbobxAngle->Text, angle) == false) { angle = 0; rzcbobxAngle->Text = "0"; } angle *= 100; try { if (ImageBpp == 8) { if (StripeBitmap->Rotate(angle, true, 0) == false) throw EC_MEMORY_LACK; if (mainImage->SubBitmap->Create(StripeBitmap->Width, StripeBitmap->Height, ImageBpp, rgb) == false) throw EC_MEMORY_LACK; if (mainImage->SubMask->Create(StripeBitmap->Width, StripeBitmap->Height, ImageBpp, rgb) == false) throw EC_MEMORY_LACK; if (StripeBitmap->StartScanLine() == false) throw EC_MEMORY_LACK;; if (mainImage->SubMask->StartScanLine() == false) throw EC_MEMORY_LACK; for (int y = 0; y < StripeBitmap->Height; y++) { Byte *stripeBitmapLine = StripeBitmap->GetScanLine(y); Byte *subMaskLine = mainImage->SubMask->GetScanLine(y); for (int x = 0; x < StripeBitmap->Width; x++) { if (stripeBitmapLine[x]) subMaskLine[x] = 0; else subMaskLine[x] = 0xFF; } mainImage->SubMask->PutScanLine(y); } StripeBitmap->StopScanLine(); mainImage->SubMask->StopScanLine(); } else { COLORREF fillColor = SearchFillColor(); if (StripeBitmap->Rotate(angle, true, fillColor) == false) throw EC_MEMORY_LACK; if (mainImage->SubBitmap->Create(StripeBitmap->Width, StripeBitmap->Height, ImageBpp) == false) throw EC_MEMORY_LACK; if (mainImage->SubMask->Create(mainImage->SubBitmap->Width, mainImage->SubBitmap->Height, 1) == false) throw EC_MEMORY_LACK; StripeBitmap->StartScanLine(); mainImage->SubMask->StartScanLine(); for (int y = 0; y < StripeBitmap->Height; y++) { Byte *stripeBitmapLine = StripeBitmap->GetScanLine(y); Byte *subMaskLine = mainImage->SubMask->GetScanLine(y); *subMaskLine = 0; Byte mm = 0x80; for (int x = 0; x < StripeBitmap->Width; x++, stripeBitmapLine += 3) { COLORREF color; GetPixel24(stripeBitmapLine, color); if (color == fillColor) *subMaskLine |= mm; if (mm == 1) { subMaskLine++; *subMaskLine = 0; mm = 0x80; } else { mm >>= 1; } } mainImage->SubMask->PutScanLine(y); } StripeBitmap->StopScanLine(); mainImage->SubMask->StopScanLine(); } END_LOG; return true; } catch(TPException ec) { StripeBitmap->StopScanLine(); mainImage->SubMask->StopScanLine(); mainImage->SubMask->Destroy(); mainImage->SubBitmap->Destroy(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; return false; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::SetSubBitmap() { BEGIN_LOG(""); TPItemImage *mainImage = MainImageForm->iMainImage; RECT subRange = mainImage->SubRange; try { if (mainImage->uBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; if (mainImage->SubBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; if (mainImage->SubMask->StartScanLine() == false) throw EC_MEMORY_LACK; if (StripeBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; } catch (TPException ec) { mainImage->uBitmap->StopScanLine(); mainImage->SubBitmap->StopScanLine(); mainImage->SubMask->StopScanLine(); StripeBitmap->StopScanLine(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } int bytePerPixel; if (ImageBpp == 8) bytePerPixel = 1; else bytePerPixel = 3; for (int y = 0; y < mainImage->SubBitmap->Height; y++) { Byte *uBitmapLine = mainImage->uBitmap->GetScanLine(subRange.top + y) + subRange.left * bytePerPixel; Byte *subBitmapLine = mainImage->SubBitmap->GetScanLine(y); Byte *subMaskLine = mainImage->SubMask->GetScanLine(y); Byte *stripeBitmapLine = StripeBitmap->GetScanLine(y); if (ImageBpp == 8) { for (int x = 0; x < mainImage->SubBitmap->Width; x++, uBitmapLine += bytePerPixel, subBitmapLine += bytePerPixel, stripeBitmapLine += bytePerPixel, subMaskLine++) { if (*subMaskLine == 0xFF || (PaletteForm->DIB256Palette->Palette->ColorData[*uBitmapLine]->Protect != 0 && MainImageForm->bProtect)) *subBitmapLine = *uBitmapLine; else *subBitmapLine = *stripeBitmapLine; } } else { Byte mm = 0x80; for (int x = 0; x < mainImage->SubBitmap->Width; x++, uBitmapLine += bytePerPixel, subBitmapLine += bytePerPixel, stripeBitmapLine += bytePerPixel) { if (*subMaskLine & mm) { CopyPixel24(subBitmapLine, uBitmapLine); } else { CopyPixel24(subBitmapLine, stripeBitmapLine); } if (mm == 1) { subMaskLine++; mm = 0x80; } else { mm >>= 1; } } } mainImage->SubBitmap->PutScanLine(y); } mainImage->uBitmap->StopScanLine(); mainImage->SubBitmap->StopScanLine(); mainImage->SubMask->StopScanLine(); StripeBitmap->StopScanLine(); mainImage->SubVisible = true; static RECT paintedRect = subRange; RECT repaintRect; repaintRect.left = paintedRect.left < subRange.left ? paintedRect.left : subRange.left; repaintRect.top = paintedRect.top < subRange.top ? paintedRect.top : subRange.top; repaintRect.right = paintedRect.right > subRange.right ? paintedRect.right : subRange.right; repaintRect.bottom = paintedRect.bottom > subRange.bottom ? paintedRect.bottom : subRange.bottom; paintedRect = subRange; mainImage->RectPaint(repaintRect); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::LoadToMainImage() { BEGIN_LOG(""); TPItemImage *mainImage = MainImageForm->iMainImage; RECT undoRect, workAreaRect; undoRect = Rect(mainImage->SubRange.left, mainImage->SubRange.top, mainImage->SubRange.left + mainImage->SubBitmap->Width, mainImage->SubRange.top + mainImage->SubBitmap->Height); workAreaRect = undoRect; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) undoRect = MainImageForm->AutoRep_UndoRect(undoRect); //2001.6.19 by lhskys autorepeat bool undoSw = false; try { if ((undoSw = MainImageForm->UndoSave(UK_ALL, undoRect)) == false) throw EC_MEMORY_LACK; if (mainImage->uBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; if (mainImage->SubBitmap->StartScanLine() == false) throw EC_MEMORY_LACK; } catch(TPException ec) { if (undoSw) MainImageForm->Undo->RemoveLast(); mainImage->uBitmap->StopScanLine(); mainImage->SubBitmap->StopScanLine(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } int bytePerPixel; if (ImageBpp == 8) bytePerPixel = 1; else bytePerPixel = 3; for (int y = 0; y < mainImage->SubBitmap->Height; y++) { Byte *uBitmapLine = mainImage->uBitmap->GetScanLine(workAreaRect.top + y) + workAreaRect.left * bytePerPixel; Byte *subBitmapLine = mainImage->SubBitmap->GetScanLine(y); for (int x = 0; x < mainImage->SubBitmap->Width; x++, uBitmapLine += bytePerPixel, subBitmapLine += bytePerPixel) { if (ImageBpp == 8) *uBitmapLine = *subBitmapLine; else CopyPixel24(uBitmapLine, subBitmapLine); } mainImage->uBitmap->PutScanLine(workAreaRect.top + y); } mainImage->uBitmap->StopScanLine(); mainImage->SubBitmap->StopScanLine(); if (mainImage->LayerMask) mainImage->LayerMask->CopyToRect(workAreaRect.left, workAreaRect.top, mainImage->SubMask, SRCAND); MainImageForm->WorkArea->SetRectangle(workAreaRect); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) MainImageForm->RedrawingRepeat(false, false); //2001.6.19 by lhskys autorepeat MainImageForm->WorkAreaChange(); PaletteForm->DIB256Palette->ChoiceIndex = 2; MainImageForm->Palette->UseColor = PaletteForm->DIB256Palette->UseColor; mainImage->SubVisible = false; mainImage->SubEnabled = false; RepaintColor(); IsRunOneRepeatModeOn = false; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::iMainImageMouseDown(int X, int Y) { BEGIN_LOG(""); if (IsRunOneRepeatModeOn) { MainImageForm->SubBitmapPosition(X, Y, false); LoadToMainImage(); if (ImageBpp == 8 && PaletteForm->DIB256Palette->UseColor < NewUseColor) PaletteForm->DIB256Palette->UseColor = NewUseColor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::iMainImageMouseMove(int X, int Y) { BEGIN_LOG(""); if (IsRunOneRepeatModeOn) { MainImageForm->SubBitmapPosition(X, Y, false); if (rzbbtnOneRepeat->Down) { MainImageForm->iMainImage->Cursor = crHandPoint; SetSubBitmap(); } } else { if(!MainImageForm->iMainImage->Cross) MainImageForm->iMainImage->Cursor = crPen; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ChangeZoom(int ratio) { BEGIN_LOG(""); int zoomIn, zoomOut; zoomIn = ratio / 100; zoomOut = ratio % 100; if (zoomIn != teximgStripe->ZoomIn || zoomOut != teximgStripe->ZoomOut) { POINT pt = Point(teximgStripe->PositionX, teximgStripe->PositionY); teximgStripe->SetZoom(zoomIn, zoomOut, &pt); rulerWeft->Zoom = (double)zoomIn / zoomOut; rulerWarp->Zoom = (double)zoomIn / zoomOut; } END_LOG; } //--------------------------------------------------------------------------- // Component Event //////////////////////////////////////////////////////////////////////////////// void __fastcall TStripeForm::StringGridDlbClick(TObject *Sender) { BEGIN_LOG(""); TRzStringGrid *grid = dynamic_cast(Sender); TList *stripeDataList = StripeDataList[grid->Tag]; if (grid->Row > 0 && grid->Row <= stripeDataList->Count) { if (grid->Col == C_LENGTH_COL || grid->Col == C_REPEAT_COL) { TGridRect gridRect; gridRect.Left = grid->Col; gridRect.Right = grid->Col; gridRect.Top = grid->Row; gridRect.Bottom = grid->Row; grid->Selection = gridRect; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { BEGIN_LOG(""); TRzStringGrid *grid = dynamic_cast(Sender); TList *stripeDataList = StripeDataList[grid->Tag]; if (stripeDataList == NULL) { END_LOG; return; } String str = ""; int posX = 0, posY = 0; if (ARow==0) { switch (ACol) { case C_FIXED_COL: if (grid->Tag == 0) str = IDS_WARP; else str = IDS_WEFT; break; case C_COLOR_COL: str = "Color"; break; case C_METHOD_COL: str = "Method"; break; case C_LENGTH_COL: str = "Length"; break; case C_REPEAT_COL: str = "Repeat"; break; } posX = (Rect.Right - Rect.Left - grid->Canvas->TextWidth(str)) / 2; posY = (Rect.Bottom - Rect.Top - grid->Canvas->TextHeight(str)) / 2; if (posX < 0) posX = 0; if (posY < 0) posY = 0; TColor oldColor = grid->Canvas->Brush->Color; grid->Canvas->Brush->Color = clBtnFace; grid->Canvas->TextRect(Rect, Rect.Left + posX, Rect.Top + posY, str); grid->Canvas->Brush->Color = oldColor; }else { if (ACol == C_FIXED_COL) //index { str = Format(" %d", OPENARRAY (TVarRec, (ARow))); posX = (Rect.Right - Rect.Left - grid->Canvas->TextWidth(str)) / 2; posY = (Rect.Bottom - Rect.Top - grid->Canvas->TextHeight(str)) / 2; if(posX < 0) posX = 0; if (posY < 0) posY = 0; TColor oldColor = grid->Canvas->Brush->Color; grid->Canvas->Brush->Color = clBtnFace; grid->Canvas->TextRect(Rect, Rect.Left + posX, Rect.Top + posY, str); grid->Canvas->Brush->Color = oldColor; }else { int stripeDataCnt = stripeDataList->Count; if (ARow > stripeDataCnt) { grid->Canvas->FillRect(TRect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom)); END_LOG; return; } TStripeData *stripeData = (TStripeData *) stripeDataList->Items[ARow - 1]; if (stripeData->Valid == false) { grid->Canvas->FillRect(TRect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom)); END_LOG; return; } switch (ACol) { case C_COLOR_COL: // Color { TColor orgColor = grid->Canvas->Brush->Color; if (ImageBpp == 8) { TColorData *colorData = PaletteForm->DIB256Palette->Palette->ColorData[stripeData->ColorIdx]; grid->Canvas->Brush->Color = RGB2TColor(colorData->RGB.rgbRed, colorData->RGB.rgbGreen, colorData->RGB.rgbBlue); } else grid->Canvas->Brush->Color = RGB2TColor(stripeData->ColorRGB.rgbRed, stripeData->ColorRGB.rgbGreen, stripeData->ColorRGB.rgbBlue); //grid->Canvas->FillRect(Classes::Rect(Rect.Left + 2, Rect.Top + 2, Rect.Right - 2, Rect.Bottom - 2)); grid->Canvas->FillRect(Classes::Rect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom)); grid->Canvas->Brush->Color = orgColor; break; } case C_METHOD_COL: // Method { switch (stripeData->Method) { case M_NORMAL: str = "Normal"; break; case M_REVERSE: str = "Reverse"; break; case M_CENTER: str = "Center"; break; } posX = (Rect.Right - Rect.Left - grid->Canvas->TextWidth(str)) / 2; posY = (Rect.Bottom - Rect.Top - grid->Canvas->TextHeight(str)) / 2; if (posX < 0) posX = 0; if (posY < 0) posY = 0; grid->Canvas->TextRect(Rect, Rect.Left + posX, Rect.Top + posY, str); break; } case C_LENGTH_COL: // Length { switch (UnitItem) { case uDot: str = Format("%d", OPENARRAY (TVarRec, (stripeData->LengthDot))); break; case uInch: str = Format("%.2f", OPENARRAY (TVarRec, (stripeData->LengthInch))); break; case uCm: str = Format("%.2f", OPENARRAY (TVarRec, (stripeData->LengthCm))); break; } posX = 2;//(Rect.Right - Rect.Left - grid->Canvas->TextWidth(str)) / 2; posY = 2;//(Rect.Bottom - Rect.Top - grid->Canvas->TextHeight(str)) / 2; if (posX < 0) posX = 0; if (posY < 0) posY = 0; grid->Canvas->TextRect(Rect, Rect.Left + posX, Rect.Top + posY, str); break; } case C_REPEAT_COL: // Repeat { str = Format("%d", OPENARRAY (TVarRec, (stripeData->Repetition))); posX = 2;//(Rect.Right - Rect.Left - grid->Canvas->TextWidth(str)) / 2; posY = 2;//(Rect.Bottom - Rect.Top - grid->Canvas->TextHeight(str)) / 2; if (posX < 0) posX = 0; if (posY < 0) posY = 0; grid->Canvas->TextRect(Rect, Rect.Left + posX, Rect.Top + posY, str); break; } } } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { BEGIN_LOG(""); TRzStringGrid *grid = dynamic_cast(Sender); if (Key == VK_RETURN) { grid->Options >> goEditing; if (grid->Col == C_LENGTH_COL || grid->Col == C_REPEAT_COL) { if (grid->Row > 0) { InputData(grid); grid->Repaint(); grid->Row = grid->Row + 1; } } PaintStripeImage(); UpdateTextValue(); UpdateComponentEnabled(); } else if ( !(Key == VK_LEFT || Key == VK_UP || Key == VK_RIGHT || Key == VK_DOWN || Key == VK_HOME || Key == VK_END) && !((48 <= Key && Key <= 57) || Key == 190) && // ¼ýÀÚ 0 ~ 9 ¶Ç´Â . ÀÎÁö °Ë»ç !((VK_NUMPAD0 <= Key && Key <= VK_NUMPAD9) || Key == VK_DECIMAL) && // ŰÆÐµå ¼ýÀÚ 0 ~ 9 ¶Ç´Â . ÀÎÁö °Ë»ç !(Key == VK_BACK || Key == VK_DELETE) // BackSpace ¶Ç´Â Delete ÀÎÁö °Ë»ç ) { grid->Options >> goEditing; grid->Repaint(); // grid->DefaultDrawing = false; g_FocusControl->SetFocus(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); TRzStringGrid *grid = dynamic_cast(Sender); grid->Options >> goEditing; int colIdx; int rowIdx; grid->MouseToCell(X, Y, colIdx, rowIdx); if (Button == mbMiddle) { grid->Col = colIdx; } if (Button == mbLeft && (colIdx != grid->Col || rowIdx != grid->Row)) { END_LOG; return; } TList *stripeDataList = StripeDataList[grid->Tag]; TStripeData *stripeData = NULL; if (spbtnAdd->Down) // ÁÙ¹«´Ì »ðÀÔ ¹öưÀÌ ´­·¯Á® ÀÖ´Â °æ¿ì { if (grid->Row <= stripeDataList->Count) { stripeData = new TStripeData; stripeDataList->Insert(grid->Row - 1, stripeData); stripeData->Valid = false; IsInsertComplete[grid->Tag] = false; spbtnAdd->Down = false; } else { spbtnAdd->Down = false; END_LOG; return; } } else if (spbtnDelete->Down) // ÁÙ¹«´Ì »èÁ¦ ¹öưÀÌ ´­·¯Á® ÀÖ´Â °æ¿ì { if (grid->Row <= stripeDataList->Count) { stripeData = (TStripeData *)stripeDataList->Items[grid->Row - 1]; stripeDataList->Remove(stripeData); delete stripeData; spbtnDelete->Down = false; } else { spbtnDelete->Down = false; END_LOG; return; } } else { if (grid->Col == C_COLOR_COL) // Color { if (Button == mbMiddle) // »ö ¼±Åà { // middle buttonÀ¸·Î ´©¸¥ °æ¿ì grid->Row´Â updateµÇÁö ¾ÊÀ¸¹Ç·Î rowIdx »ç¿ë if (rowIdx > 0 && rowIdx <= stripeDataList->Count) { stripeData = (TStripeData *)stripeDataList->Items[rowIdx - 1]; if (ImageBpp == 8) { PaletteForm->DIB256Palette->ChoiceIndex = stripeData->ColorIdx; PaletteForm->DIB256Palette->Repaint(); } else { PaletteForm->DIB256Palette->Palette->ColorData[*SelColorIdx]->RGB.rgbBlue = stripeData->ColorRGB.rgbBlue; PaletteForm->DIB256Palette->Palette->ColorData[*SelColorIdx]->RGB.rgbGreen = stripeData->ColorRGB.rgbGreen; PaletteForm->DIB256Palette->Palette->ColorData[*SelColorIdx]->RGB.rgbRed = stripeData->ColorRGB.rgbRed; PaletteForm->DIB256Palette->Repaint(); } } END_LOG; return; } else // »ö º¯°æ ¶Ç´Â Ãß°¡ { if (grid->Row <= stripeDataList->Count) // »ö º¯°æ { stripeData = (TStripeData *)stripeDataList->Items[grid->Row - 1]; if (stripeData->Valid == false) // Áß°£¿¡ data¸¦ »ðÀÔÇÏ°í °ªÀ» ÀÔ·ÂÇÏÁö ¾ÊÀº °æ¿ì { stripeData->Method = M_NORMAL; stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; // 1 Cm stripeData->LengthInch = 1.0 / CM_PER_INCH; // 1 Cm stripeData->LengthCm = 1.0; // 1 Cm stripeData->Repetition = 1; stripeData->Valid = true; IsInsertComplete[grid->Tag] = true; } } else // »ö Ãß°¡ { stripeData = new TStripeData; stripeData->Method = M_NORMAL; stripeData->LengthDot = DPI / CM_PER_INCH + 0.5; // 1 Cm stripeData->LengthInch = 1.0 / CM_PER_INCH; // 1 Cm stripeData->LengthCm = 1.0; // 1 Cm stripeData->Repetition = 1; stripeData->Valid = true; stripeDataList->Add(stripeData); } if (ImageBpp == 8) stripeData->ColorIdx = *SelColorIdx; else { stripeData->ColorRGB.rgbBlue = SelColorRGB->rgbBlue; stripeData->ColorRGB.rgbGreen = SelColorRGB->rgbGreen; stripeData->ColorRGB.rgbRed = SelColorRGB->rgbRed; } } } else if (grid->Col == C_METHOD_COL) // Method { if (grid->Row <= stripeDataList->Count) { int upperMethod = M_NORMAL; if (grid->Row > 1) //error ¹æÁö { stripeData = (TStripeData *)stripeDataList->Items[grid->Row - 2]; // ¹Ù·Î À§ dataÀÇ Method upperMethod = stripeData->Method; } stripeData = (TStripeData *)stripeDataList->Items[grid->Row - 1]; stripeData->Method = (EMethodItem)(stripeData->Method + 1); if (upperMethod == M_REVERSE) // ¹Ù·Î À§ dataÀÇ Method°¡ ReverseÀÎ °æ¿ì { if (stripeData->Method > M_CENTER) stripeData->Method = M_REVERSE; } else { if (stripeData->Method > M_REVERSE) stripeData->Method = M_NORMAL; } } } else if (grid->Col == C_LENGTH_COL || grid->Col == C_REPEAT_COL) // Length or Repeat { if (grid->Row > 0 && grid->Row <= stripeDataList->Count) { TStripeData *stripeData = (TStripeData *)stripeDataList->Items[grid->Row - 1]; if (stripeData->Valid == true) { grid->EditorMode = true; grid->Options << goEditing; } } END_LOG; return; } else { END_LOG; return; } } grid->Repaint(); PaintStripeImage(); UpdateTextValue(); UpdateComponentEnabled(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridSelect(TObject *Sender, int ACol, int ARow, bool &CanSelect) { BEGIN_LOG(""); TRzStringGrid *grid = dynamic_cast(Sender); grid->Options >> goEditing; TList *stripeDataList = StripeDataList[grid->Tag]; if (ARow > 0 && ARow <= stripeDataList->Count) { switch (ACol) { case C_LENGTH_COL: case C_REPEAT_COL: { TStripeData *stripeData = (TStripeData *)stripeDataList->Items[ARow - 1]; if (stripeData->Valid == true) { String str; if (ACol == C_LENGTH_COL) { switch (UnitItem) { case uDot: str = Format("%d", OPENARRAY (TVarRec, (stripeData->LengthDot))); break; case uInch: str = Format("%.2f", OPENARRAY (TVarRec, (stripeData->LengthInch))); break; case uCm: str = Format("%.2f", OPENARRAY (TVarRec, (stripeData->LengthCm))); break; } } else str = Format("%d", OPENARRAY (TVarRec, (stripeData->Repetition))); grid->Cells[ACol][ARow] = str; grid->EditorMode = true; grid->Options << goEditing; } break; } } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::DeleteStripeClick(TObject *Sender) { BEGIN_LOG(""); TSpeedButton *btn = dynamic_cast(Sender); InitData((EStripeType)btn->Tag); if (btn->Tag == 0 || btn->Tag == 2) rzgrdWarp->Repaint(); if (btn->Tag == 1 || btn->Tag == 2) rzgrdWeft->Repaint(); PaintStripeImage(); UpdateTextValue(); UpdateComponentEnabled(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::rztbrOverlapChange(TObject *Sender) { BEGIN_LOG(""); nedOverlap->Value = rztbrOverlap->Position; PaintStripeImage(false); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::nedOverlapChange(TObject *Sender) { rztbrOverlap->Position = nedOverlap->Value; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::nedOverlapMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { nedOverlap->SetFocus(); nedOverlap->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::nedThickChange(TObject *Sender) { float value = nedThick->Value; switch (UnitItem) { case uDot: ThickValue = value; break; case uInch: ThickValue = value * DPI; break; case uCm: ThickValue = value * DPI / CM_PER_INCH; break; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::nedThickKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { BEGIN_LOG(""); if (Key == VK_RETURN) { PaintStripeImage(); UpdateTextValue(); UpdateComponentEnabled(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::nedThickClick(TObject *Sender) { nedThick->SetFocus(); nedThick->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::rzcbobxAngleDblClick(TObject *Sender) { rzcbobxAngle->SetFocus(); rzcbobxAngle->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::rzcbobxAngleChange(TObject *Sender) { int degVal = 0; if (TryStrToInt(rzcbobxAngle->Text, degVal)) { if (degVal < 0) rzcbobxAngle->Text = "0"; if (degVal > 360) rzcbobxAngle->Text = "360"; } else { rzcbobxAngle->Text = "0"; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::rzbbtnSpreadViewClick(TObject *Sender) { BEGIN_LOG(""); if (IsInsertComplete[S_WARP] == false || IsInsertComplete[S_WEFT] == false) MessageDlg(IDS_MESSAGE_INSERTCOLOR,mtConfirmation, TMsgDlgButtons()<Down) SpreadView(); else if (rzcbobxSize->Enabled) ViewStripeImage((EViewMode)rzcbobxSize->ItemIndex); else ViewStripeImage(V_ORGVIEW); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::rzcbobxSizeChange(TObject *Sender) { BEGIN_LOG(""); ViewStripeImage(EViewMode(rzcbobxSize->ItemIndex)); teximgStripe->PositionX = 0; teximgStripe->PositionY = 0; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::rzbbtnRunClick(TObject *Sender) { BEGIN_LOG(""); if (IsInsertComplete[S_WARP] == false || IsInsertComplete[S_WEFT] == false) { MessageDlg(IDS_MESSAGE_INSERTCOLOR, mtConfirmation, TMsgDlgButtons() << mbOK, 0); END_LOG; return; } else if (CheckRange() == false) { ShowMessage(IDS_OVERLENWID); END_LOG; return; } Visible = false; IsRun = true; MainImageForm->WorkAreaReset(); MainForm->UpdateMenuItems(NULL); if (rzbbtnOneRepeat->Down) { MainImageForm->iMainImage->SubEnabled = true; IsRunOneRepeatModeOn = RunOneRepeatImage(); MainImageForm->Center.x = MainImageForm->iMainImage->SubBitmap->Width / 2; MainImageForm->Center.y = MainImageForm->iMainImage->SubBitmap->Height / 2; } else { RECT undoRect = Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height); bool undoSw = false; try { if ((undoSw = MainImageForm->UndoSave(UK_ALL, undoRect)) == false) throw EC_MEMORY_LACK; } catch(TPException ec) { if (undoSw) MainImageForm->Undo->RemoveLast(); SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; return; } MainImageForm->iMainImage->SubEnabled = false; RunWholeImage(); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) MainImageForm->RedrawingRepeat(false, true); if (ImageBpp == 8) PaletteForm->DIB256Palette->UseColor = NewUseColor; } if (rzbbtnWhole->Down) PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::teximgStripePositionChange(TObject *Sender) { BEGIN_LOG(""); TPoint size = Point(teximgStripe->Width * teximgStripe->ZoomOut / teximgStripe->ZoomIn, teximgStripe->Height * teximgStripe->ZoomOut / teximgStripe->ZoomIn); if (teximgStripe->Bitmap->Width > size.x) { scrlbrWeft->Enabled = true; scrlbrWeft->Max = teximgStripe->Bitmap->Width - size.x; scrlbrWeft->SmallChange = scrlbrWeft->Max / 10; scrlbrWeft->LargeChange = scrlbrWeft->Max / 5; rulerWeft->Start = teximgStripe->PositionX; } else { scrlbrWeft->Position = 0; scrlbrWeft->Enabled = false; rulerWeft->Start = 0; } if (teximgStripe->Bitmap->Height > size.y) { scrlbrWarp->Enabled = true; scrlbrWarp->Max = teximgStripe->Bitmap->Height - size.y; scrlbrWarp->SmallChange = scrlbrWarp->Max / 10; scrlbrWarp->LargeChange = scrlbrWarp->Max / 5; rulerWarp->Start = teximgStripe->PositionY; } else { scrlbrWarp->Position = 0; scrlbrWarp->Enabled = false; rulerWarp->Start = 0; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::scrlbrWeftScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { teximgStripe->PositionX = scrlbrWeft->Position; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::scrlbrWarpScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { teximgStripe->PositionY = scrlbrWarp->Position; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ExecuteHotKey(String command) { BEGIN_LOG(""); int ratio = 0; if (command == "ZoomIn") { switch (teximgStripe->ZoomIn) { case 1: switch (teximgStripe->ZoomOut) // ÇöÀçÀÇ È®´ë, Ãà¼ÒµÈ ºñÀ²Àº ¾Ë¾Æ³»¾î { // ºñÀ²¿¡ µû¶ó ratio¶ó´Â º¯¼ö¿¡ Àû´çÇÑ °ªÀ» case 1: ratio = 302; break; // ÀԷ½Ã۰í, ±×°ÍÀº parameter·Î ÇÏ´Â ÇÔ¼ö(RatioZoom) case 2: ratio = 203; break; // ¸¦ È£ÃâÇÑ´Ù. case 3: ratio = 102; break; case 4: ratio = 103; break; // ¼öÁ¤ By GreenFish (Áܴܰè È®Àå) case 6: ratio = 104; break; case 8: ratio = 106; break; case 12: ratio = 108; break; case 16: ratio = 112; break; } break; case 2: switch (teximgStripe->ZoomOut) { case 1: ratio = 301; break; case 3: ratio = 101; break; } break; case 3: switch (teximgStripe->ZoomOut) { case 1: ratio = 401; break; case 2: ratio = 201; break; } break; case 4: ratio = 601; break; case 6: ratio = 801; break; case 8: ratio = 1201; break; case 12: ratio = 1601; break; default: { END_LOG; return; } } ChangeZoom(ratio); } else if (command == "ZoomOut") { switch (teximgStripe->ZoomIn) { case 1: switch (teximgStripe->ZoomOut) { case 1: ratio = 203; break; case 2: ratio = 103; break; case 3: ratio = 104; break; case 4: ratio = 106; break; case 6: ratio = 108; break; case 8: ratio = 112; break; case 12: ratio = 116; break; default: { END_LOG; return; } } break; case 2: switch (teximgStripe->ZoomOut) { case 1: ratio = 302; break; case 3: ratio = 102; break; } break; case 3: switch (teximgStripe->ZoomOut) { case 1: ratio = 201; break; case 2: ratio = 101; break; } break; case 4: ratio = 301; break; case 6: ratio = 401; break; case 8: ratio = 601; break; case 12: ratio = 801; break; case 16: ratio = 1201; break; default: { END_LOG; return; } } ChangeZoom(ratio); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::spbtnAddClick(TObject *Sender) { BEGIN_LOG(""); if (IsInsertComplete[S_WARP] == false || IsInsertComplete[S_WEFT] == false) { spbtnAdd->Down = false; MessageDlg(IDS_MESSAGE_INSERTCOLOR, mtConfirmation, TMsgDlgButtons() << mbOK, 0); } else { if(StripeDataList[S_WARP]->Count >= 150 && StripeDataList[S_WEFT]->Count >= 150) { spbtnAdd->Down = false; ShowMessage(IDS_MESSAGE_NOTADDSTRIPE); } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::spbtnDeleteClick(TObject *Sender) { BEGIN_LOG(""); if (IsInsertComplete[S_WARP] == false || IsInsertComplete[S_WEFT] == false) { spbtnDelete->Down = false; Application->MessageBox(IDS_INSERTSTATE.c_str(), L"Wanring", MB_OK); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::spbtnMakeSameClick(TObject *Sender) { BEGIN_LOG(""); EStripeType srcIdx, dstIdx; TStripeData *srcStripeData; TStripeData *dstStripeData; TRzStringGrid *dstGrid; if (StripeDataList[S_WARP]->Count > 0) { srcIdx = S_WARP; dstIdx = S_WEFT; dstGrid = rzgrdWeft; } else if(StripeDataList[S_WEFT]->Count > 0) { srcIdx = S_WEFT; dstIdx = S_WARP; dstGrid = rzgrdWarp; } else { END_LOG; return; } for (int i = 0; i < StripeDataList[dstIdx]->Count; i++) { dstStripeData = (TStripeData *)StripeDataList[dstIdx]->Items[i]; delete dstStripeData; } StripeDataList[dstIdx]->Clear(); IsInsertComplete[dstIdx] = IsInsertComplete[srcIdx]; for (int i = 0; i < StripeDataList[srcIdx]->Count; i++) { srcStripeData = (TStripeData *)StripeDataList[srcIdx]->Items[i]; dstStripeData = new TStripeData; dstStripeData->ColorIdx = srcStripeData->ColorIdx; dstStripeData->ColorRGB = srcStripeData->ColorRGB; dstStripeData->Method = srcStripeData->Method; dstStripeData->LengthDot = srcStripeData->LengthDot; dstStripeData->LengthInch = srcStripeData->LengthInch; dstStripeData->LengthCm = srcStripeData->LengthCm; dstStripeData->Repetition = srcStripeData->Repetition; dstStripeData->Valid = srcStripeData->Valid; StripeDataList[dstIdx]->Add(dstStripeData); } dstGrid->Repaint(); PaintStripeImage(); UpdateTextValue(); UpdateComponentEnabled(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::rzcbobxMethodChange(TObject *Sender) { BEGIN_LOG(""); switch (rzcbobxMethod->ItemIndex) { case 0: OverlapMode = O_GAUZE; //OverlapLabel->Caption = IDS_GAUZEMODE; rztbrOverlap->Visible = false; nedOverlap->Visible = false; break; case 1: OverlapMode = O_MIXTURE; //OverlapLabel->Caption = IDS_MIXTUREMODE; rztbrOverlap->Visible = true; nedOverlap->Visible = true; break; } PaintStripeImage(false); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::spbtnFileClick(TObject *Sender) { BEGIN_LOG(""); try { if ((FileManagerForm = new TFileManagerForm(NULL)) == NULL) throw EC_MEMORY_LACK; } catch(TPException ec) { SAVE_EXCEPTION(ec); EXCEPTION_MESSAGE_OK(ec); END_LOG; return; } FileManagerForm->rztbRead->Down = true; FileManagerForm->rztbReadClick(this); FileManagerForm->Extension = 2; //Stripe¸¦ fileManager¿¡°Ô ¾Ë¸². FileManagerForm->FilterComboBox->Filter = "Texpro Stripe File (*.stp)|*.stp"; FileManagerForm->OnRead = STPOnRead; FileManagerForm->OnFileName = STPOnFileName; FileManagerForm->OnSave = STPOnSave; FileManagerForm->ShowModal(); delete FileManagerForm; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::spbtnExitClick(TObject *Sender) { BEGIN_LOG(""); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //---------------------------------------------------------------------------