//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "YarnArrange_F.h" #include "MainImage.h" #include "Palette.h" #include "YarnAccount_F.h" #include "YarnTable_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "PColorGrid" #pragma link "PHLS" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IM_YARNS 0 #define IM_LENGTH 1 #define IDS_YARNARRANGE StringTable[0] #define IDS_YARNDYE StringTable[1] #define IDS_TABLEVIEW StringTable[2] #define IDS_WARP StringTable[3] #define IDS_WEFT StringTable[4] #define IDS_YARNS StringTable[5] #define IDS_ACCOUNT StringTable[6] #define IDS_INSERT StringTable[7] #define IDS_DENSITY StringTable[8] #define IDS_ASWARP StringTable[9] #define IDS_TOTAL StringTable[10] #define IDS_CODE StringTable[11] #define IDS_NEW StringTable[12] #define IDS_MESSAGE StringTable[13] #define IDS_CHANGE StringTable[14] #define IDS_MESSAGE_CHANGE StringTable[15] TYarnArrangeForm *YarnArrangeForm; //--------------------------------------------------------------------------- __fastcall TYarnArrangeForm::TYarnArrangeForm(TComponent* Owner) : TForm(Owner) { //===================================================== StringTable.Create(DirectoryItem, Language, "YarnArrange"); SetSmallFont(Font); SetSmallFont(StaticText1->Font); SetSmallFont(StaticText2->Font); SetSmallFont(rbYarns->Font); SetSmallFont(rbLength->Font); Caption = IDS_YARNARRANGE; StaticText1->Caption = IDS_YARNDYE; sbDyeNew->Caption = IDS_NEW; sbDyeDelete->Caption = IDS_COMMON_DELETE; sbDyeChange->Caption = IDS_CHANGE; sbTableView->Caption = IDS_TABLEVIEW; StaticText2->Caption = IDS_YARNARRANGE; sbWarp->Caption = IDS_WARP; sbWeft->Caption = IDS_WEFT; rbYarns->Caption = IDS_YARNS; rbLength->Caption = IDS_COMMON_LENGTH; sbAccount->Caption = IDS_ACCOUNT; sbArrayNew->Caption = IDS_NEW; sbArrayInsert->Caption = IDS_INSERT; sbArrayDelete->Caption = IDS_COMMON_DELETE; sbArrayDensity->Caption = IDS_DENSITY; sbSameWarp->Caption = IDS_ASWARP; StatusBar->Panels->Items[0]->Text = IDS_TOTAL; //===================================================== } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::FormCreate(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Main.ini"); int m; if (IniFile) { Left = IniFile->ReadInteger("YanrArrangeForm", "FormLeft", 2); Top = IniFile->ReadInteger("YanrArrangeForm", "FormTop", 489); Width = IniFile->ReadInteger("YanrArrangeForm", "FormWidth", 965); Height = IniFile->ReadInteger("YanrArrangeForm", "FormHeight", 422); m = IniFile->ReadInteger("YarnArray", "InputMode", 0); delete IniFile; } MainImageForm->OnYarnColorChange = YarnColorChange; YarnTableForm->OnYarnChange = YarnChange; YarnTableForm->OnCloseForm = CloseTableForm; YarnAccountForm->OnCloseForm = CloseAccountForm; PalIndex = 2; insert = -1; if (m) { InputMode = IM_LENGTH; rbLength->Checked = true; } else { InputMode = IM_YARNS; rbYarns->Checked = true; } if (MainImageForm->Plan->Yarn->bSuckerDown) sbSucker->Down = true; WORW = -1; memset(cmap, NULL, sizeof(WORD *) * 8); MainImageForm->Plan->Yarn->bFinish[0] = false; MainImageForm->Plan->Yarn->bFinish[1] = false; for(int i=0; i<8; i++) { if (MainImageForm->Plan->Yarn->Choice[i].Data) ScrollEnable(i); } InitDyePanel(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::InitDyePanel() { TPColorGrid *colorgrid; TPanel *panel; TYarnData *yd; int cnt; for (int i = 0; i < 8; i++) { yd = MainImageForm->Plan->Yarn->Choice[i].Data; if (yd) { InitChoiceButton(1); if (yd->Dyed) { panel = (TPanel *) FindComponent("Panel" + AnsiString(i+1) + "16"); panel->BringToFront(); InitSetHLS(i); TPHLS *hls = (TPHLS *) FindComponent("PHLS" + AnsiString(i+1)); hls->Color = (TColor) MainImageForm->Plan->Yarn->Choice[i].DyeColor; colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(i*8+1)); colorgrid->IsFill = true; } else { cnt = yd->Colors; for (int j = 0; j < 8; j++) { colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(i*8+j+1)); colorgrid->ColorCount = cnt; if (MainImageForm->Plan->Yarn->Choice[i].Color[j]) { colorgrid->IsFill = true; for (int k = 0; k < cnt; k++) { colorgrid->ReDrawCell(k, (MainImageForm->Plan->Yarn->Choice[i].Color[j][k]->GetColor(0))->Color); } } } } } } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::FormDestroy(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Main.ini"); if (IniFile) { if (Left<0) Left = 10; if (Top<0) Top = 10; IniFile->WriteInteger("YanrArrangeForm", "FormLeft", Left); IniFile->WriteInteger("YanrArrangeForm", "FormTop", Top); IniFile->WriteInteger("YanrArrangeForm", "FormWidth", Width); IniFile->WriteInteger("YanrArrangeForm", "FormHeight", Height); //IniFile->WriteInteger("YarnArray", "FormLeft", Left); //IniFile->WriteInteger("YarnArray", "FormTop", Top); IniFile->WriteInteger("YarnArray", "InputMode", InputMode); delete IniFile; } for (int i = 0; i < 8; i++) { if (cmap[i]) delete[] cmap[i]; } MainImageForm->OnYarnColorChange = NULL; MainImageForm->Plan->Yarn->bFinish[WEFT] = SetFinish(WEFT); MainImageForm->Plan->Yarn->bFinish[WARP] = SetFinish(WARP); } //--------------------------------------------------------------------------- bool __fastcall TYarnArrangeForm::SetFinish(int i) { TYarnArray *ya; TPColorGrid *colorgrid; int check, temp; if (MainImageForm->Plan->Yarn->Array[i]->Count) { for (int k = 0; k < MainImageForm->Plan->Yarn->Array[i]->Count; k++) { ya = (TYarnArray *) MainImageForm->Plan->Yarn->Array[i]->Items[k]; if (ya->code == 0) return false; else { check = (ya->code-1) / 8; if (MainImageForm->Plan->Yarn->Choice[check].Data == NULL) return false; temp = ya->code; colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(temp)); if (!colorgrid->IsFill) return false; } if (ya->length == 0) return false; if (ya->yarns == 0) return false; } return true; } else return false; } //--------------------------------------------------------------------------- //// Choice Published Method //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::sbAccountClick(TObject *Sender) { if (sbAccount->Down) YarnAccountForm->Visible = true; else YarnAccountForm->Visible = false; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::DyeGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { TYarnData *yd = MainImageForm->Plan->Yarn->Choice[ACol].Data; if (yd) { int x, y; TPoint sp; TSize vs = { 100, 76 }; sp.x = Rect.Left+2; sp.y = Rect.Top+2+((vs.cy-yd->Width)>>1); yd->Draw(DyeGrid->Canvas, sp, vs); TRect TextRect = TRect(Rect.Left, Rect.Top + (vs.cy + 4), Rect.Right, Rect.Bottom); x = ((vs.cx + 4) - DyeGrid->Canvas->TextWidth(yd->FileName)) / 2; DyeGrid->Canvas->TextRect(TextRect, TextRect.Left + x, TextRect.Top+5, yd->FileName); } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::sbDyeNewClick(TObject *Sender) { TPColorGrid *colorgrid; int i; MainImageForm->Plan->Yarn->ClearAllChoiceData(); Panel116->SendToBack(); Panel216->SendToBack(); Panel316->SendToBack(); Panel416->SendToBack(); Panel516->SendToBack(); Panel616->SendToBack(); Panel716->SendToBack(); Panel816->SendToBack(); for (i = 0; i < 8; i++) { if (cmap[i]) { delete[] cmap[i]; cmap[i] = NULL; } } for (i = 1; i <= 64; i++) { colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(i)); colorgrid->ColorCount = 0; colorgrid->IsFill = false; } InitChoiceButton(0); DyeGrid->Repaint(); int precnt = MainImageForm->Plan->Yarn->Array[WEFT]->Count; MainImageForm->Plan->Yarn->ClearArray(WEFT); RearrangeGrid(precnt, WEFT); precnt = MainImageForm->Plan->Yarn->Array[WARP]->Count; MainImageForm->Plan->Yarn->ClearArray(WARP); RearrangeGrid(precnt, WARP); InitArrayButton(0); ChangeTotalSize(); ArrayGrid->Repaint(); if (YarnAccountForm->Visible) YarnAccountForm->RearrangeData(); if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::sbTableViewClick(TObject *Sender) { YarnTableForm->Visible = sbTableView->Down; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::DyeGridClick(TObject *Sender) { int i = DyeGrid->Col; int k, m, n, precnt; TPColorGrid *colorgrid; TPanel *panel; TYarnArray *ya; if (sbDyeDelete->Down) { if (MainImageForm->Plan->Yarn->Choice[i].Data) { if (MainImageForm->Plan->Yarn->Choice[i].Data->Dyed) { //½ºÄµ¹ÞÀº ½ÇÀ϶§ true panel = (TPanel *) FindComponent("Panel" + AnsiString(i+1) + "16"); panel->SendToBack(); if (cmap[i]) { delete[] cmap[i]; cmap[i] = NULL; } } MainImageForm->Plan->Yarn->RemoveChoiceData(i); //ÀúÀåµÇ¾îÀÖ´Â µ¥ÀÌŸ»èÁ¦ for (int j = 1; j <= 8; j++) { //¼±ÅÃµÈ ¿­ÀÇ ÇàÀ» ¸ðµÎ Áö¿ò k = i*8 + j; //i¿­ÀÇ jÇàÀ» ³ªÅ¸³»´Â Àμö // colorgrid clear colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(k)); colorgrid->ColorCount = 0; colorgrid->IsFill = false; } if (WORW == WEFT) { precnt = MainImageForm->Plan->Yarn->Array[WARP]->Count; DeleteArrayData(precnt, i, WARP); RearrangeGrid(precnt, WARP); precnt = MainImageForm->Plan->Yarn->Array[WEFT]->Count; DeleteArrayData(precnt, i, WEFT); RearrangeGrid(precnt, WEFT); } else { precnt = MainImageForm->Plan->Yarn->Array[WEFT]->Count; DeleteArrayData(precnt, i, WEFT); RearrangeGrid(precnt, WEFT); precnt = MainImageForm->Plan->Yarn->Array[WARP]->Count; DeleteArrayData(precnt, i, WARP); RearrangeGrid(precnt, WARP); } if (!MainImageForm->Plan->Yarn->ChoiceCount) InitChoiceButton(0); DyeGrid->Repaint(); if (WORW >= 0) { if (!MainImageForm->Plan->Yarn->Array[WORW]->Count) InitArrayButton(0); } ChangeTotalSize(); ArrayGrid->Repaint(); if (YarnAccountForm->Visible) YarnAccountForm->RearrangeData(); MainImageForm->DrawWarpBar(); MainImageForm->DrawWeftBar(); } sbDyeDelete->Down = false; } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ScrollBarScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { TScrollBar *sb = (TScrollBar *) Sender; TPColorGrid *colorgrid; int index = sb->Tag; for (int i = 1; i <= 8; i++) { colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(i+index*8)); colorgrid->Pos = ScrollPos; } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ColorGridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TPColorGrid *colorgrid = (TPColorGrid *) Sender; TColorData *cd = NULL; int i, j, index; i = (colorgrid->Tag-1) / 8; // 0, 1, 2, 3 j = (colorgrid->Tag-1) % 8; // 0 - 7 if (colorgrid->IsFill) { if (Button== mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { index = colorgrid->GetColorIndex(X, Y); if (index >= 0) { PaletteForm->DIB256Palette->ChoiceIndex = MainImageForm->Plan->Yarn->Choice[i].Color[j][index]->Index; } return; } else if (Button == mbLeft) { if (sbDyeDelete->Down) { MainImageForm->Plan->Yarn->RemoveColor(i, j); colorgrid->DrawNullSquare(); colorgrid->IsFill = false; sbDyeDelete->Down = false; } else { index = colorgrid->GetColorIndex(X, Y); if (index >= 0) { ChangeChoiceColor(i, j, index); cd = (TColorData *) MainImageForm->Plan->Yarn->Choice[i].Color[j][index]->GetColor(0); colorgrid->ReDrawCell(index, cd->Color); } } } } else { if (MainImageForm->Plan->Yarn->Choice[i].Data) { MainImageForm->Plan->Yarn->AddColor(i, j); AddChoiceColor(i, j); DrawColorGrid(colorgrid->Tag-1); colorgrid->IsFill = true; } } if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); DyeGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ColorGridMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { TPColorGrid *colorgrid = (TPColorGrid *) Sender; int i, j, index; i = (colorgrid->Tag-1) / 8; // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 j = (colorgrid->Tag-1) % 8; // 0 - 7 if (colorgrid->IsFill) { index = colorgrid->GetColorIndex(X, Y); if (index>=0) { PaletteForm->DIB256Palette->CursorIndex = MainImageForm->Plan->Yarn->Choice[i].Color[j][index]->Index; } } } //--------------------------------------------------------------------------- //// Array Published Method //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ArrayGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { AnsiString str; int x, y, wid, temp; TSize size; TYarnArray *yarnarray; size.cx = Rect.Right-Rect.Left; size.cy = Rect.Bottom-Rect.Top; if (ACol == 0) { if (ARow == 0) str = "No."; else str = ARow; } else { if (ARow == 0) { switch (ACol) { case 1: str = IDS_CODE; break; case 2: str = IDS_COMMON_METHOD; break; case 3: str = IDS_COMMON_LENGTH; break; case 4: str = IDS_YARNS; break; case 5: str = IDS_DENSITY; break; case 6: str = IDS_COMMON_REPEAT; break; case 7: str = "Sucker"; break; // qe test } } else { if (WORW < 0) return; if (!MainImageForm->Plan->Yarn->Array[WORW]->Count) return; if (ARow > MainImageForm->Plan->Yarn->Array[WORW]->Count) return; if (ARow == insert) return; yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[ARow-1]; switch (ACol) { case 1: temp = (int) yarnarray->code; str = temp; break; case 2: switch (yarnarray->method) { case 0: str = "Normal"; break; case 1: str = "Reverse"; break; case 2: str = "Center"; break; } break; case 3: if (MainImageForm->CurrentUnit == uCm) str = Format("%.2f", OPENARRAY(TVarRec, (yarnarray->length*2.54))); else str = Format("%.2f", OPENARRAY(TVarRec, (yarnarray->length))); break; case 4: str = AnsiString(yarnarray->yarns); break; case 5: if (MainImageForm->CurrentUnit == uCm) str = Format("%.2f", OPENARRAY(TVarRec, (yarnarray->density / 2.54))); else str = Format("%.2f", OPENARRAY(TVarRec, (yarnarray->density))); break; case 6: str = AnsiString(yarnarray->repeat); break; case 7: if (yarnarray->sucker) str = "Yes"; else str = "No"; break; } } } x = (size.cx-ArrayGrid->Canvas->TextWidth(str)) / 2; if (x<0) x = 0; y = (size.cy-ArrayGrid->Canvas->TextHeight(str)) / 2; if (y<0) y = 0; ArrayGrid->Canvas->TextRect(Rect, Rect.Left+x, Rect.Top+y, str); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ArrayGridClick(TObject *Sender) { TYarnArray *yarnarray, *preya; int i, k; if (MainImageForm->Plan->Yarn->ChoiceCount == 0) return; if (WORW >= 0) { if (ArrayGrid->Row) { if (sbArrayInsert->Down || sbArrayDelete->Down) { if ((ArrayGrid->Row-1)Plan->Yarn->Array[WORW]->Count) { if (sbArrayInsert->Down) { MainImageForm->Plan->Yarn->InsertArray(ArrayGrid->Row-1, WORW); insert = ArrayGrid->Row; ///////// for (i=MainImageForm->Plan->Yarn->Array[WORW]->Count; i>ArrayGrid->Row; i--) { ArrayGrid->Cells[1][i] = ArrayGrid->Cells[1][i-1]; ArrayGrid->Cells[3][i] = ArrayGrid->Cells[3][i-1]; ArrayGrid->Cells[4][i] = ArrayGrid->Cells[4][i-1]; ArrayGrid->Cells[5][i] = ArrayGrid->Cells[5][i-1]; ArrayGrid->Cells[6][i] = ArrayGrid->Cells[6][i-1]; } ArrayGrid->Cells[1][ArrayGrid->Row] = ""; ArrayGrid->Cells[3][ArrayGrid->Row] = ""; ArrayGrid->Cells[4][ArrayGrid->Row] = ""; ArrayGrid->Cells[5][ArrayGrid->Row] = ""; ArrayGrid->Cells[6][ArrayGrid->Row] = ""; } else if (sbArrayDelete->Down) { MainImageForm->Plan->Yarn->RemoveArray(ArrayGrid->Row-1, WORW); if (insert == ArrayGrid->Row) insert = -1; for (i=ArrayGrid->Row; i<=MainImageForm->Plan->Yarn->Array[WORW]->Count; i++) { ArrayGrid->Cells[1][i] = ArrayGrid->Cells[1][i+1]; ArrayGrid->Cells[3][i] = ArrayGrid->Cells[3][i+1]; ArrayGrid->Cells[4][i] = ArrayGrid->Cells[4][i+1]; ArrayGrid->Cells[5][i] = ArrayGrid->Cells[5][i+1]; ArrayGrid->Cells[6][i] = ArrayGrid->Cells[6][i+1]; } i = MainImageForm->Plan->Yarn->Array[WORW]->Count+1; ArrayGrid->Cells[1][i] = ""; ArrayGrid->Cells[3][i] = ""; ArrayGrid->Cells[4][i] = ""; ArrayGrid->Cells[5][i] = ""; ArrayGrid->Cells[6][i] = ""; } ChangeTotalSize(); } ArrayGrid->EditorMode = false; sbArrayInsert->Down = false; sbArrayDelete->Down = false; if (MainImageForm->Plan->Yarn->Array[WORW]->Count == 0) InitArrayButton(0); } else if (ArrayGrid->Col) { if (WORW < 0) return; switch (ArrayGrid->Col) { case 1: if ((ArrayGrid->Row-1)<=MainImageForm->Plan->Yarn->Array[WORW]->Count) ArrayGrid->EditorMode = true; break; case 2: if ((ArrayGrid->Row-1)Plan->Yarn->Array[WORW]->Count) { yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[ArrayGrid->Row-1]; if ((ArrayGrid->Row - 2) < 0) { if (yarnarray->method == 0) yarnarray->method = 1; else yarnarray->method = 0; } else { preya = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[ArrayGrid->Row-2]; switch (preya->method) { case 0: if (yarnarray->method == 0) yarnarray->method = 1; else if (yarnarray->method == 1) yarnarray->method = 2; else if (yarnarray->method == 2) yarnarray->method = 0; break; case 1: if (yarnarray->method == 0) yarnarray->method = 1; else if (yarnarray->method == 1) yarnarray->method = 2; else if (yarnarray->method == 2) yarnarray->method = 0; break; case 2: if (yarnarray->method == 0) yarnarray->method = 1; else if (yarnarray->method == 1) yarnarray->method = 0; break; } } ChangeTotalSize(); } break; case 3: if ((ArrayGrid->Row-1)Plan->Yarn->Array[WORW]->Count) { yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[ArrayGrid->Row-1]; if (yarnarray->length) { ArrayGrid->EditorMode = true; } else { if (InputMode == IM_LENGTH) ArrayGrid->EditorMode = true; else ArrayGrid->EditorMode = false; } } break; case 4: if ((ArrayGrid->Row-1)Plan->Yarn->Array[WORW]->Count) { yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[ArrayGrid->Row-1]; if (yarnarray->yarns) { ArrayGrid->EditorMode = true; } else { if (InputMode == IM_YARNS) ArrayGrid->EditorMode = true; else ArrayGrid->EditorMode = false; } } break; case 5: case 6: if ((ArrayGrid->Row-1)Plan->Yarn->Array[WORW]->Count) ArrayGrid->EditorMode = true; break; case 7: if ((ArrayGrid->Row-1)Plan->Yarn->Array[WORW]->Count) { yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[ArrayGrid->Row-1]; yarnarray->sucker = !yarnarray->sucker; } break; default: ArrayGrid->EditorMode = false; } } } } ArrayGrid->Repaint(); if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); if (YarnAccountForm->Visible) YarnAccountForm->RearrangeData(); } //--------------------------------------------------------------------------- bool __fastcall TYarnArrangeForm::ProperInput(AnsiString str, int col) { if (str == "" ) return false; int k; TPColorGrid *colorgrid; try { if (col == 1) { k = StrToInt(str); if (k >0 && k < 81 ) { colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(k)); if (colorgrid->IsFill) return true; } else return false; } return false; } catch (EConvertError *error) { return false; } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::YPICalculate(int col, int row) { TYarnArray *ya = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[row-1]; switch (col) { case 3: ya->yarns = ya->density * ya->length + 0.5; if(ya->length == 0) ya->length = ya->yarns / ya->density; break; case 4: if (ya->density){ ya->length = (double) ya->yarns / ya->density; } else { ya->length = 0; } break; case 5: if (InputMode == IM_YARNS) if (ya->density){ ya->length = (double) ya->yarns / ya->density; } else { ya->length = 0; } else ya->yarns = ya->density * ya->length + 0.5; break; } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ArrayGridKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { TYarnArray *yarnarray; AnsiString str; TStringGrid *grid = (TStringGrid *) Sender; bool IsChange; if (WORW < 0) return; if(grid->EditorMode){ //by qe ...¹æÇâŰ·Î Æ÷Ä¿½ºÀ̵¿À§ÇØ ¸¸µç ÄÚµå, case by case·Î ÇÏ¿´À½ if(Key == 39){ //right arrow key Key = 0; switch(grid->Col){ case 1: if(InputMode == IM_YARNS) if(ArrayGrid->Cells[grid->Col+3][grid->Row] != "") grid->Col = 4; if(InputMode == IM_LENGTH) if(ArrayGrid->Cells[grid->Col+2][grid->Row] != "") grid->Col = 3; break; case 3: grid->Col = 5; break; case 4: grid->Col = 5; break; case 5: grid->Col = 6; break; case 6: grid->Row = grid->Row+1; grid->Col = 1; break; } RearrangeGrid(0, WORW); } if(Key == 37){ //left arrow key Key = 0; switch(grid->Col){ case 1: if(grid->Row != 1){ grid->Row = grid->Row - 1; grid->Col = 6; } break; case 3: grid->Col = 1; break; case 4: grid->Col = 1; break; case 5: if(InputMode == IM_YARNS) grid->Col = 4; if(InputMode == IM_LENGTH) grid->Col = 3; break; case 6: grid->Col = 5; break; } RearrangeGrid(0, WORW); } } if (Key==VK_RETURN) { if (grid->EditorMode) { str = ArrayGrid->Cells[grid->Col][grid->Row]; if ((grid->Row-1) == MainImageForm->Plan->Yarn->Array[WORW]->Count) { if (grid->Col == 1) { if (ProperInput(str, 1)) { MainImageForm->Plan->Yarn->AddArray(StrToInt(str), WORW); if (InputMode == IM_YARNS) grid->Col = 4; else grid->Col = 3; InitArrayButton(1); } else { ArrayGrid->Cells[grid->Col][grid->Row] = ""; } } } else if ((grid->Row-1) < MainImageForm->Plan->Yarn->Array[WORW]->Count){ yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[grid->Row-1]; if (grid->Col == 1) { if (ProperInput(str, 1)) { IsChange = false; if(yarnarray->code != StrToInt(str)){ yarnarray->code = StrToInt(str); IsChange = true; } if(IsChange){ yarnarray->density = MainImageForm->Plan->Yarn->Choice[(yarnarray->code - 1) / 8].ypi; } YPICalculate(5, grid->Row); } if (insert>=0) insert = -1; if (InputMode == IM_YARNS) grid->Col = 4; else grid->Col = 3; } else if (grid->Col == 3) { if (MainImageForm->CurrentUnit == uCm) yarnarray->length = StrToFloat(str) / 2.54; else yarnarray->length = StrToFloat(str); YPICalculate(3, grid->Row); //grid->Col = 1; ------------------by qe //grid->Row = grid->Row+1; grid->Col = 5; } else if (grid->Col == 4) { yarnarray->yarns = StrToInt(str); YPICalculate(4, grid->Row); //grid->Col = 1; -----------------by qe //grid->Row = grid->Row+1; grid->Col = 5; } else if (grid->Col == 5) { if (StrToFloat(str) == 0.0) return; if (sbArrayDensity->Down) { if (MainImageForm->CurrentUnit == uCm) AllDensity(StrToFloat(str) * 2.54); else AllDensity(StrToFloat(str)); grid->Col = 1; grid->Row = MainImageForm->Plan->Yarn->Array[WORW]->Count+1; } else { if (MainImageForm->CurrentUnit == uCm) yarnarray->density = StrToFloat(str) * 2.54; else yarnarray->density = StrToFloat(str); YPICalculate(5, grid->Row); //grid->Col = 1; -----------------------by qe //grid->Row = grid->Row+1; grid->Col=6; } } else if (grid->Col == 6) { yarnarray->repeat = StrToInt(str); grid->Col = 1; grid->Row = grid->Row+1; } } grid->EditorMode = false; ArrayGrid->Repaint(); RearrangeGrid(0, WORW); ChangeTotalSize(); // if (WORW == 0) MainImageForm->DrawWarpBar(); // by kjs ask to me. // else if (WORW == 1) MainImageForm->DrawWeftBar(); if (YarnAccountForm->Visible) YarnAccountForm->RearrangeData(); } } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::AllDensity(double d) { TYarnArray *yarnarray; if (WORW >= 0) { int cnt = MainImageForm->Plan->Yarn->Array[WORW]->Count; for (int i = 0; i < cnt; i++) { yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[i]; yarnarray->density = d; YPICalculate(5, i+1); ArrayGrid->Cells[5][i+1] = d; } } sbArrayDensity->Down = false; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ArrayGridSelectCell(TObject *Sender, int ACol, int ARow, bool &CanSelect) { if ((WORW >= 0) && (MainImageForm->Plan->Yarn->ChoiceCount > 0)) { if (CanSelect) { if (ARow) { switch (ACol) { case 0: case 2: case 7: ArrayGrid->Options>>goEditing; break; case 1: case 3: case 4: case 5: case 6: ArrayGrid->Options<Options>>goEditing; } } else ArrayGrid->Options>>goEditing; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::sbArrayNewClick(TObject *Sender) { int precnt = MainImageForm->Plan->Yarn->Array[WORW]->Count; MainImageForm->Plan->Yarn->ClearArray(WORW); RearrangeGrid(precnt, WORW); InitArrayButton(0); ChangeTotalSize(); ArrayGrid->Repaint(); if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); if (YarnAccountForm->Visible) YarnAccountForm->RearrangeData(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::rbClick(TObject *Sender) { TRadioButton *rb = (TRadioButton *) Sender; InputMode = rb->Tag; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::sbWORWClick(TObject *Sender) { int precnt; bool can; if (WORW >= 0) precnt = MainImageForm->Plan->Yarn->Array[WORW]->Count; else precnt = 0; if (sbWarp->Down) { WORW = WARP; sbSucker->Visible = true; sbSucker->BringToFront(); ReCountCol(WARP); if (MainImageForm->Plan->Yarn->Array[WARP]->Count) InitArrayButton(1); else InitArrayButton(0); ArrayGrid->Col = 1; ArrayGrid->Row = MainImageForm->Plan->Yarn->Array[WARP]->Count+1; } else if (sbWeft->Down) { WORW = WEFT; ReCountCol(WEFT); sbSameWarp->Visible = true; sbSameWarp->BringToFront(); if (MainImageForm->Plan->Yarn->Array[WEFT]->Count) InitArrayButton(1); else InitArrayButton(0); ArrayGrid->Col = 1; ArrayGrid->Row = MainImageForm->Plan->Yarn->Array[WEFT]->Count+1; } else { WORW = -1; sbSameWarp->Visible = false; sbSucker->Visible = false; } RearrangeGrid(precnt, WORW); ChangeTotalSize(); ArrayGrid->Repaint(); if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::sbSameWarpClick(TObject *Sender) { int precnt = MainImageForm->Plan->Yarn->Array[WEFT]->Count; MainImageForm->Plan->Yarn->CopyFromWarpToWeft(); RearrangeGrid(precnt, WORW); ChangeTotalSize(); ArrayGrid->Repaint(); ArrayGrid->Row = MainImageForm->Plan->Yarn->Array[WARP]->Count+1; if (MainImageForm->Plan->Yarn->Array[WEFT]->Count) InitArrayButton(1); else InitArrayButton(0); if (YarnAccountForm->Visible) YarnAccountForm->RearrangeData(); if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); } //--------------------------------------------------------------------------- //// Private Method //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::InitChoiceButton(int i) { sbDyeDelete->Down = false; sbDyeChange->Down = false; //by qe sbDyeChange->Enabled = i; //by qe sbDyeNew->Enabled = i; sbDyeDelete->Enabled = i; // sbDyeOyc->Enabled = i; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::AddChoiceColor(int i, int j, int *pIndex) { TColorData *cd; int cnt = MainImageForm->Plan->Yarn->Choice[i].Data->Colors; if (cnt > 0) { if (pIndex) { for (int k = 0; k < cnt; k++) { cd = MainImageForm->Palette->ColorData[pIndex[k]]; MainImageForm->Plan->Yarn->Choice[i].Color[j][k]->SetColor(cd, pIndex[k]); MainImageForm->Plan->Yarn->Choice[i].Data->Color[k]->SetColor(cd); } } else { for (int k = 0; k < cnt; k++) { cd = MainImageForm->Palette->ColorData[PalIndex]; MainImageForm->Plan->Yarn->Choice[i].Color[j][k]->SetColor(cd, PalIndex); MainImageForm->Plan->Yarn->Choice[i].Data->Color[k]->SetColor(cd); if (MainImageForm->Palette->UseColor < PalIndex) { MainImageForm->Palette->UseColor = PalIndex; PaletteForm->FGColor->Text1 = PalIndex - 1; } PalIndex++; if (PalIndex > 251) PalIndex = 2; } } } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ChangeChoiceColor(int i, int j, int k) { int ind = PaletteForm->DIB256Palette->ChoiceIndex; if (ind == 1) { ShowMessage(IDS_MESSAGE); PaletteForm->DIB256Palette->ChoiceIndex = 2; ind = 2; } TColorData *src = MainImageForm->Palette->ColorData[ind]; MainImageForm->Plan->Yarn->Choice[i].Color[j][k]->SetColor(src, ind); for (int n = 0; n < MainImageForm->Plan->Yarn->Choice[i].Data->Colors; n++) { src = (TColorData *) MainImageForm->Plan->Yarn->Choice[i].Color[j][n]->GetColor(0); MainImageForm->Plan->Yarn->Choice[i].Data->Color[n]->SetColor(src); } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::DrawColorGrid(int i) { TPColorGrid *colorgrid = (TPColorGrid *) FindComponent("ColorGrid"+ AnsiString(i+1)); TColorData *cd; int k = i / 8; if (colorgrid->ColorCount > 0) { for (int j = 0; j < colorgrid->ColorCount; j++) { cd = (TColorData *) MainImageForm->Plan->Yarn->Choice[k].Color[i%8][j]->GetColor(0); colorgrid->ReDrawCell(j, cd->Color); } } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ScrollEnable(int i) { TScrollBar *sb = (TScrollBar *) FindComponent("ScrollBar" + AnsiString(i+1)); int cnt = MainImageForm->Plan->Yarn->Choice[i].Data->Colors; if (cnt < 6) sb->Enabled = false; else { sb->Enabled = true; sb->Max = cnt - 5; } } //--------------------------------------------------------------------------- int __fastcall TYarnArrangeForm::FindChoiceIndex() { for (int i = 0; i < 8; i++) { if (!MainImageForm->Plan->Yarn->Choice[i].Data) return i; } return -1; } //--------------------------------------------------------------------------- //// Array Private Method //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::InitArrayButton(int i) { sbArrayInsert->Down = false; sbArrayDelete->Down = false; sbArrayDensity->Down = false; sbArrayNew->Enabled = i; sbArrayInsert->Enabled = i; sbArrayDelete->Enabled = i; sbArrayDensity->Enabled = i; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ChangeTotalSize() { AnsiString len, yar; TYarnArray *ya; int i, j, ctr, totyar; double totlen; if (WORW >= 0) { int cnt = MainImageForm->Plan->Yarn->Array[WORW]->Count; if (cnt) { i = 0; totlen = 0; totyar = 0; ctr = -1; while (iPlan->Yarn->Array[WORW]->Count) { ya = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[i]; totlen = totlen + ya->length*ya->repeat; totyar = totyar + ya->yarns*ya->repeat; if (ya->method == 2) { j = i-1; while (j > ctr) { ya = (TYarnArray *) MainImageForm->Plan->Yarn->Array[WORW]->Items[j]; if (ya->method==1) { totlen = totlen + ya->length*ya->repeat; totyar = totyar + ya->yarns*ya->repeat; } j = j-1; } ctr = i; } i = i+1; } if (MainImageForm->CurrentUnit == uCm) totlen *= 2.54; len = Format("%.2f", OPENARRAY(TVarRec, (totlen))); yar = Format("%d", OPENARRAY(TVarRec, (totyar))); } else { len = "0.00"; yar = "0.00"; } StatusBar->Panels->Items[1]->Text = AnsiString(IDS_COMMON_LENGTH)+ " -> " + len; StatusBar->Panels->Items[2]->Text = AnsiString(IDS_YARNS) + " -> " + yar; } else { StatusBar->Panels->Items[1]->Text = ""; StatusBar->Panels->Items[2]->Text = ""; } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::DeleteArrayData(int cnt, int i, int ww, bool ex) { TYarnArray *yarnarray; int st = 0, k = 0; if (ex) { st = i * 8 + 1; while (k < cnt) { yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[ww]->Items[k]; if (yarnarray->code == st) { k++; continue; } if (i == ((yarnarray->code - 1) / 8)) { MainImageForm->Plan->Yarn->RemoveArray(k, ww); cnt--; } else k++; } } else { while (k < cnt) { yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[ww]->Items[k]; if (i == ((yarnarray->code - 1) / 8)) { MainImageForm->Plan->Yarn->RemoveArray(k, ww); cnt--; } else k++; } } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::RearrangeGrid(int precnt, int ww) { TYarnArray *ya; int cnt, i, m, temp; if (WORW >= 0) { cnt = MainImageForm->Plan->Yarn->Array[ww]->Count; if (cnt > precnt) m = cnt; else m = precnt; for (i = 0; i < m; i++) { if (i < cnt) { ya = (TYarnArray *) MainImageForm->Plan->Yarn->Array[ww]->Items[i]; temp = (int) ya->code; ArrayGrid->Cells[1][i+1] = temp; ArrayGrid->Cells[4][i+1] = AnsiString(ya->yarns); ArrayGrid->Cells[6][i+1] = AnsiString(ya->repeat); if (MainImageForm->CurrentUnit == uCm) { ArrayGrid->Cells[3][i+1] = Format("%.2f", OPENARRAY(TVarRec, (ya->length * 2.54))); ArrayGrid->Cells[5][i+1] = Format("%.2f", OPENARRAY(TVarRec, (ya->density / 2.54))); } else { ArrayGrid->Cells[3][i+1] = Format("%.2f", OPENARRAY(TVarRec, (ya->length))); ArrayGrid->Cells[5][i+1] = Format("%.2f", OPENARRAY(TVarRec, (ya->density))); } } else { ArrayGrid->Cells[1][i+1] = ""; ArrayGrid->Cells[3][i+1] = ""; ArrayGrid->Cells[4][i+1] = ""; ArrayGrid->Cells[5][i+1] = ""; ArrayGrid->Cells[6][i+1] = ""; } } } else { for (i = 0; i < precnt; i++) { ArrayGrid->Cells[1][i+1] = ""; ArrayGrid->Cells[3][i+1] = ""; ArrayGrid->Cells[4][i+1] = ""; ArrayGrid->Cells[5][i+1] = ""; ArrayGrid->Cells[6][i+1] = ""; } } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::CloseTableForm() { sbTableView->Down = false; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::CloseAccountForm() { sbAccount->Down = false; } //--------------------------------------------------------------------------- //// Public Method //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::YarnChange(AnsiString fn) { int i = FindChoiceIndex(); if (i >= 0) { AcceptData(fn, i); } else { MainImageForm->Plan->Yarn->ChoiceCount = 8; //qe Sysutils::Beep(); ShowMessage(IDS_MESSAGE_DATAFULL); } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::AcceptData(AnsiString fn, int i) { TPColorGrid *colorgrid; TPanel *panel; MainImageForm->Plan->Yarn->AddChoiceData(fn, i, MainImageForm->CanvasInfor.DotsPerInch); AddChoiceColor(i, 0); for (int j = 1; j <= 8; j++) { colorgrid = (TPColorGrid *) FindComponent("ColorGrid"+ AnsiString(i*8+j)); colorgrid->ColorCount = MainImageForm->Plan->Yarn->Choice[i].Data->Colors; } ScrollEnable(i); RangeChange(i); DrawColorGrid(i*8); colorgrid = (TPColorGrid *) FindComponent("ColorGrid"+ AnsiString(i*8+1)); colorgrid->IsFill = true; InitChoiceButton(1); if (MainImageForm->Plan->Yarn->Choice[i].Data->Dyed) { panel = (TPanel *) FindComponent("Panel" + AnsiString(i+1) + "16"); panel->BringToFront(); InitSetHLS(i); } DyeGrid->Repaint(); if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::DyeGridDragDrop(TObject *Sender, TObject *Source, int X, int Y) { int si, ti, i, cnt, precnt; TPColorGrid *cg; TPanel *panel; TStringGrid *sg = (TStringGrid *) Source; AnsiString fn, dn; si = sg->Col + (sg->Row * sg->ColCount); if (si >= YarnTableForm->FileListBox->Items->Count) return; YarnTableForm->FileListBox->ItemIndex = si; fn = ExtractFileName(YarnTableForm->FileListBox->FileName); dn = ExtractFileDir(YarnTableForm->FileListBox->FileName); chdir(dn.c_str()); ti = (DyeGrid->MouseCoord(X, Y)).X; if (ti < 0) return; if (MainImageForm->Plan->Yarn->Choice[ti].Data) { if (MainImageForm->Plan->Yarn->Choice[ti].Data->Dyed) { MainImageForm->Plan->Yarn->RemoveChoiceData(ti); if (cmap[ti]) { delete[] cmap[ti]; cmap[ti] = NULL; } AcceptData(fn, ti); if (MainImageForm->Plan->Yarn->Choice[ti].Data->Dyed == false) { panel = (TPanel *) FindComponent("Panel" + AnsiString(ti+1) + "16"); panel->SendToBack(); } } else { MainImageForm->Plan->Yarn->RemoveChoiceData(ti); cnt = 0; for (i = 0; i < 8; i++) { cg = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(ti*8+i+1)); if (cg->IsFill) cnt++; cg->ColorCount = 0; cg->IsFill = false; } MainImageForm->Plan->Yarn->ChangeChoiceData(fn, ti, MainImageForm->CanvasInfor.DotsPerInch); if (MainImageForm->Plan->Yarn->Choice[ti].Data->Dyed) { cg = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(ti*8+1)); cg->IsFill = true; panel = (TPanel *) FindComponent("Panel" + AnsiString(ti+1) + "16"); panel->BringToFront(); InitSetHLS(ti); if (WORW == WARP) { precnt = MainImageForm->Plan->Yarn->Array[WEFT]->Count; DeleteArrayData(precnt, ti, WEFT, true); RearrangeGrid(precnt, WEFT); precnt = MainImageForm->Plan->Yarn->Array[WARP]->Count; DeleteArrayData(precnt, ti, WARP, true); RearrangeGrid(precnt, WARP); } else { precnt = MainImageForm->Plan->Yarn->Array[WARP]->Count; DeleteArrayData(precnt, ti, WARP, true); RearrangeGrid(precnt, WARP); precnt = MainImageForm->Plan->Yarn->Array[WEFT]->Count; DeleteArrayData(precnt, ti, WEFT, true); RearrangeGrid(precnt, WEFT); } ArrayGrid->Repaint(); if (WORW >= 0) { if (MainImageForm->Plan->Yarn->Array[WORW]->Count) InitArrayButton(1); else InitArrayButton(0); } } else { for (i = 0; i < 8; i++) { cg = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(ti*8+i+1)); cg->ColorCount = MainImageForm->Plan->Yarn->Choice[ti].Data->Colors; if (i < cnt) { MainImageForm->Plan->Yarn->AddColor(ti, i); AddChoiceColor(ti, i); DrawColorGrid(cg->Tag-1); cg->IsFill = true; } } ScrollEnable(ti); } DyeGrid->Repaint(); if (WORW == 0) MainImageForm->DrawWarpBar(); else if (WORW == 1) MainImageForm->DrawWeftBar(); } MainImageForm->bChoiceExchange = true; } else { YarnChange(fn); } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::UnitChange() { ArrayGrid->Repaint(); RearrangeGrid(0, WORW); ChangeTotalSize(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::InitSetHLS(int i) { TYarnData *yd = MainImageForm->Plan->Yarn->Choice[i].Data; WORD *DP, *CP; RGBQUAD temp; int cnt = 0; int r = 0, g = 0, b = 0; if (cmap[i]) { delete cmap[i]; cmap[i] = NULL; } if ((cmap[i] = new WORD[yd->Width * yd->Length]) == NULL) { #ifdef TPDEBUG SHOWDEBUG; #endif } for (int y = 0; y < yd->Width; y++) { DP = (WORD *) yd->Map + (y * yd->Length); CP = (WORD *) cmap[i] + (y * yd->Length); for (int x = 0; x < yd->Length; x++, DP++, CP++) { *CP = *DP; if (!(*DP & 0x8000)) { temp = Color15ToRGB(*DP); r += temp.rgbRed; g += temp.rgbGreen; b += temp.rgbBlue; cnt++; } } } Basic[i].rgbRed = r / cnt; Basic[i].rgbGreen = g / cnt; Basic[i].rgbBlue = b / cnt; TPHLS *hls = (TPHLS *) FindComponent("PHLS" + AnsiString(i+1)); hls->Color = (TColor)RGB(Basic[i].rgbRed, Basic[i].rgbGreen, Basic[i].rgbBlue); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::PHLSColorChange(TObject *Sender) { Byte r, g, b; short rc, gc, bc, rr, gg, bb; TPHLS *hls = (TPHLS *) Sender; int i = hls->Tag; TYarnData *yd = MainImageForm->Plan->Yarn->Choice[i].Data; WORD *DP, *CP; RGBQUAD temp; TColor2RGB(hls->Color, r, g, b); rc = Basic[i].rgbRed - r; gc = Basic[i].rgbGreen - g; bc = Basic[i].rgbBlue - b; for (int y = 0; y < yd->Width; y++) { DP = (WORD *) yd->Map + (y * yd->Length); CP = (WORD *) cmap[i] + (y * yd->Length); for (int x = 0; x < yd->Length; x++, DP++, CP++) { if (!(*CP & 0x8000)) { temp = Color15ToRGB(*CP); rr = temp.rgbRed - rc; gg = temp.rgbGreen - gc; bb = temp.rgbBlue - bc; if (rr < 0) temp.rgbRed = 0; else if (rr > 255) temp.rgbRed = 255; else temp.rgbRed = rr; if (gg < 0) temp.rgbGreen = 0; else if (gg > 255) temp.rgbGreen = 255; else temp.rgbGreen = gg; if (bb < 0) temp.rgbBlue = 0; else if (bb > 255) temp.rgbBlue = 255; else temp.rgbBlue = bb; *DP = RGBToColor15(temp); } } } MainImageForm->Plan->Yarn->Choice[i].DyeColor = hls->Color; DyeGrid->Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::DyeGridDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept) { if (Source == YarnTableForm->YarnTableGrid) Accept = true; else Accept = false; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::YarnColorChange(int k, int m, int n, int i) { TPColorGrid *colorgrid = NULL; int index = k*8 + (m+1); TColorData *cd = MainImageForm->Palette->ColorData[i]; colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(index)); colorgrid->ReDrawCell(n, cd->Color); DyeGrid->Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::DyeChange(AnsiString fn) //added by qe ½Çchange À§ÇØ 2000.10.21 { TPColorGrid *colorgrid; TPanel *panel; TYarnArray *yarnarray; TStringGrid *grid; int i = DyeGrid->Col; int j,k; int *pIndex[8]; if(fn == NULL){ ShowMessage(IDS_MESSAGE_CHANGE); } if((fn != NULL) && (MainImageForm->Plan->Yarn->Choice[i].Data)){ MainImageForm->bChoiceExchange = true; int PastColors = MainImageForm->Plan->Yarn->Choice[i].Data->Colors; //¹Ù²Ù±â ÀüÀÇ ½ÇÀÇ Å¸ÀÔÀ» ¾Ë¾Æº»´Ù. bool PastIsFill[8] = {false}; //»öä¿öÁ® ÀÖ´Â Çà ±â¾ï if(MainImageForm->Plan->Yarn->Choice[i].Data->Dyed){ panel = (TPanel *) FindComponent("Panel" + AnsiString(i+1) + "16"); panel->SendToBack(); if (cmap[i]) { delete[] cmap[i]; cmap[i] = NULL; } } if(!MainImageForm->Plan->Yarn->Choice[i].Data->Dyed){ //½ºÄµ¹ÞÁö ¾ÊÀº ½Ç·Î ¹Ù²Ù´Â °æ¿ì for (j = 0; j < 8; j++) { colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(i*8+j+1)); if (colorgrid->IsFill) { PastIsFill[j] = true; pIndex[j] = new int[colorgrid->ColorCount]; for (k = 0; k < colorgrid->ColorCount; k++) { pIndex[j][k] = MainImageForm->Plan->Yarn->Choice[i].Color[j][k]->Index; } } else pIndex[j] = NULL; colorgrid->ColorCount = 0; colorgrid->IsFill = false; } MainImageForm->Plan->Yarn->RemoveChoiceData(i); MainImageForm->Plan->Yarn->ChangeChoiceData(fn, i, MainImageForm->CanvasInfor.DotsPerInch); for (j = 0; j < 8; j++) { colorgrid = (TPColorGrid *) FindComponent("ColorGrid" + AnsiString(i*8+j+1)); colorgrid->ColorCount = MainImageForm->Plan->Yarn->Choice[i].Data->Colors; if (PastIsFill[j]) { //»ö±òÀÌ Ã¤¿öÁ® ÀÖ´ø Çุ ä¿î´Ù. MainImageForm->Plan->Yarn->AddColor(i, j); if (PastColors == MainImageForm->Plan->Yarn->Choice[i].Data->Colors) AddChoiceColor(i, j, pIndex[j]); else AddChoiceColor(i, j); DrawColorGrid(colorgrid->Tag-1); colorgrid->IsFill = true; } if (pIndex[j]) delete[] pIndex[j]; } ScrollEnable(i); } else { //½ºÄµ ¹ÞÀº ½Ç·Î ¹Ù²Ù´Â °æ¿ì MainImageForm->Plan->Yarn->RemoveChoiceData(i); MainImageForm->Plan->Yarn->AddChoiceData(fn, i, MainImageForm->CanvasInfor.DotsPerInch); panel = (TPanel *) FindComponent("Panel" + AnsiString(i+1) + "16"); panel->BringToFront(); InitSetHLS(i); } RangeChange(i); if(WORW >= 0){ //°æ»ç,À§»ç ½Ç¹è¿­ÀÇ ¹Ðµµ¿¡ µû¸¥ ±æÀÌ,½Ç °³¼ö ¼¼ÆÃÇØÁÜ for(j=0; j< MainImageForm->Plan->Yarn->Array[0]->Count; j++){ //°æ»ç yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[0]->Items[j]; if((i*8 < yarnarray->code) && (yarnarray->code < (i+1)*8+1)){ yarnarray->density = MainImageForm->Plan->Yarn->Choice[i].ypi; if (InputMode == IM_YARNS){ if (yarnarray->density){ yarnarray->length = (double) yarnarray->yarns / yarnarray->density; } else { yarnarray->length = 0; } }else { yarnarray->yarns = yarnarray->density * yarnarray->length + 0.5; } } } for(j=0; j< MainImageForm->Plan->Yarn->Array[1]->Count; j++){ //À§»ç yarnarray = (TYarnArray *) MainImageForm->Plan->Yarn->Array[1]->Items[j]; if((i*8 < yarnarray->code) && (yarnarray->code < (i+1)*8+1)){ yarnarray->density = MainImageForm->Plan->Yarn->Choice[i].ypi; if (InputMode == IM_YARNS){ if (yarnarray->density){ yarnarray->length = (double) yarnarray->yarns / yarnarray->density; } else { yarnarray->length = 0; } }else { yarnarray->yarns = yarnarray->density * yarnarray->length + 0.5; } } } ArrayGrid->Repaint(); } DyeGrid->Repaint(); MainImageForm->DrawWarpBar(); MainImageForm->DrawWeftBar(); //if (WORW == 0) MainImageForm->DrawWarpBar(); //else if (WORW == 1) MainImageForm->DrawWeftBar(); } sbDyeChange->Down = false; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ScrollBarXScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { Panel1->Left = - ScrollBarX->Position; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::RangeChange(int i) { int Pos = Panel1->Left + i*106; if(Pos < 0) { Panel1->Left = -i*106; ScrollBarX->Position = i*106; } if(Pos > 424) { Panel1->Left = -(i-4)*106; ScrollBarX->Position = (i-4)*106; } } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::sbSuckerClick(TObject *Sender) { ReCountCol(WARP); MainImageForm->Plan->Yarn->bSuckerDown = sbSucker->Down; } //--------------------------------------------------------------------------- void __fastcall TYarnArrangeForm::ReCountCol(int i) { if (i == 0 && sbSucker->Down) { ArrayGrid->ColCount = 8; ArrayGrid->ColWidths[0] = 39; ArrayGrid->ColWidths[1] = 39; ArrayGrid->ColWidths[2] = 50; ArrayGrid->ColWidths[3] = 50; ArrayGrid->ColWidths[4] = 50; ArrayGrid->ColWidths[5] = 50; ArrayGrid->ColWidths[6] = 50; ArrayGrid->ColWidths[7] = 50; } else { ArrayGrid->ColCount = 7; ArrayGrid->DefaultColWidth = 54; } } //----------------------------------------------------------------------------