//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Main_F.h" #include "YarnList_F.h" #include "YarnCompositionData.h" #include "Design.h" #include "Palette.h" #include "YarnTable_F.h" //gabriel #include "Yarn.h" //gabriel #include "YarnDesign_F.h" //gabriel: to get images from YarnDesign #include "define.h" //gabriel: to use YARNIMAGEHEIGHT( =100) #include "YarnArrange_F.h"//gabriel: for image color change //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzEdit" #pragma link "RzButton" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_YARNLIST StringTable[0] #define IDS_DENIER StringTable[1] #define IDS_FILAMENT StringTable[2] #define IDS_COLOR StringTable[3] #define IDS_MATERIAL StringTable[4] #define IDS_KIND StringTable[5] #define IDS_ADD StringTable[6] #define IDS_DELETE StringTable[7] #define IDS_CONTRACTION StringTable[8] #define IDS_REFLECTION StringTable[9] #define IDS_TRANSPARENT StringTable[10] #define IDS_YARN_NAME StringTable[11] #define IDS_YARN_CODE StringTable[12] #define IDS_YARN_COST StringTable[13] #define IDS_COST_HINT StringTable[14] #define IDS_YARN_MAKER StringTable[15] #define IDS_YARN_TIME StringTable[16] #define IDS_SAVE StringTable[17] #define IDS_LOAD StringTable[18] #define IDS_SELECT_YARN StringTable[19] #define IDS_DIRECT_INPUT StringTable[20] #define IDS_LOADYAN StringTable[21] //--------------------------------------------------------------------------- TYarnListForm *YarnListForm; //--------------------------------------------------------------------------- __fastcall TYarnListForm::TYarnListForm(TComponent* Owner) : TForm(Owner) { YarnListStringGrid->DoubleBuffered = true; } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::YarnListStringGridClick(TObject *Sender) { edInput->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::YarnListStringGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { TexLayer *texlayer = (TexLayer *)Main->texlayer; AnsiString str; YarnListStringGrid->Canvas->Font->Size=10; switch(ACol){ case 0: { if(ARow==0){ str=""; } else { str=AnsiString((char)('A'+ARow-1)); YarnListStringGrid->Canvas->Font->Color = clWhite; } break; } case 1: { if(ARow==0){ str = IDS_YARN_NAME; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=((Yarn *)(texlayer->YarnList->Items[ARow-1]))->name; } } break; } case 2: { if(ARow==0){ str = IDS_YARN_CODE; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=((Yarn *)(texlayer->YarnList->Items[ARow-1]))->code; } } break; } case 3: { if(ARow==0){ str = IDS_YARN_MAKER; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=((Yarn *)(texlayer->YarnList->Items[ARow-1]))->lot; } } break; } case 4: { if(ARow==0){ str = IDS_DENIER; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=MyFloatToStr(((Yarn *)(texlayer->YarnList->Items[ARow-1]))->denier,2); } } break; } case 5: { if(ARow==0){ str = IDS_FILAMENT; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=IntToStr(((Yarn *)(texlayer->YarnList->Items[ARow-1]))->filament); } } break; } case 6: { if(ARow==0){ str = IDS_COLOR; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; TColor c=DEFAULT_YARN_COLOR; if(ARow-1YarnList->Count){ Yarn *yarn = (Yarn *)texlayer->YarnList->Items[ARow-1]; c=yarn->color; YarnListStringGrid->Canvas->Brush->Color=clGray; YarnListStringGrid->Canvas->FillRect(Rect); YarnListStringGrid->Canvas->Brush->Color=c; YarnListStringGrid->Canvas->FillRect(TRect(Rect.left+2,Rect.top+2,Rect.right-2,Rect.bottom-2)); RGBQUAD rgb = TColorToRGB(c); str=IntToStr(255-rgb.rgbRed)+"-"+IntToStr(255-rgb.rgbGreen)+"-"+IntToStr(255-rgb.rgbBlue); YarnListStringGrid->Canvas->Font->Color=clBlack; YarnListStringGrid->Canvas->Font->Size=10; YarnListStringGrid->Canvas->TextOut(Rect.Left+5, Rect.Top+5, str); str=""; } } break; } case 7: { if(ARow==0){ str = IDS_CONTRACTION; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; // edInput->Text = str; //ÀåÁø¸¸: %ºÙ¿©¾ß µÇ´Ï±î µû·Î if(ARow-1YarnList->Count){ double v=((Yarn *)(texlayer->YarnList->Items[ARow-1]))->contraction; v+=1; if(v<0.01)v=0.01; // edInput->Text = MyFloatToStr(100.0/v,2); //ÀåÁø¸¸: %ºÙ¿©¾ß µÇ´Ï±î µû·Î str=MyFloatToStr(100.0/v,2)+"%"; } } break; } case 8: { if(ARow==0){ str = IDS_REFLECTION; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=MyFloatToStr(((Yarn *)(texlayer->YarnList->Items[ARow-1]))->reflection,2); } } break; } case 9: { if(ARow==0){ str = IDS_TRANSPARENT; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=MyFloatToStr(((Yarn *)(texlayer->YarnList->Items[ARow-1]))->transparency,2); } } break; } case 10: { if(ARow==0){ str = IDS_MATERIAL; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ Yarn *yarn = (Yarn *)texlayer->YarnList->Items[ARow-1]; YARNMATERIAL ym=yarn->ym; switch(ym){ case ymPO: { str="P"; break; } case ymNY: { str="N"; break; } case ymNONE: { str="-"; break; } case ymSPANDEX: { str="SPANDEX"; break; } case ymCOTTON: { str="COTTON"; break; } case ymDirectInput: { str=yarn->ymDirect; //ÀåÁø¸¸: ½Ç Á¾·ù Á÷Á¢ÀÔ·ÂÀ» À§ÇØ break; } } } } break; } case 11: { if(ARow==0){ str = IDS_KIND; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ Yarn *yarn = (Yarn *)texlayer->YarnList->Items[ARow-1]; YARNPROPERTY yp=yarn->yp; switch(yp){ case ypNONE: { str="-"; break; } case ypSD: { str="SD"; break; } case ypFD: { str="FD"; break; } case ypCD: { str="CD"; break; } case ypSPK: { str="SPK"; break; } case ypBRT: { str="BRT"; break; } case ypPDD: { str="PDD"; break; } case ypSDY: { str="SDY"; break; } case ypAMT: { str="AMT"; break; } case ypDirectInput://ÀåÁø¸¸: ½Ç Á¾·ù Á÷Á¢ÀÔ·ÂÀ» À§ÇØ { str=yarn->ypDirect; break; } } } } break; } case 12: { if(ARow==0){ str = IDS_YARN_COST; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ char buf[256]; Extended value=((Yarn *)(texlayer->YarnList->Items[ARow-1]))->cost; memset(buf,0,256); FloatToText(buf, &value, fvExtended, ffNumber, 10, 2); str=buf; } } break; } case 13: { if(ARow==0){ str = IDS_YARN_TIME; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ str=((Yarn *)(texlayer->YarnList->Items[ARow-1]))->detail; } } break; } case 14: //gabriel { if(ARow==0){ str = "Preview"; YarnListStringGrid->Canvas->Font->Color = clWhite; } else { str=""; if(ARow-1YarnList->Count){ Yarn *tyarn = ((Yarn *)(texlayer->YarnList->Items[ARow-1])); if (tyarn->lpimage){ RECT rect = {0,0,tyarn->size_of_image/YARNIMAGEHEIGHT/3,YARNIMAGEHEIGHT}; TTexpiaBitmap *tYarnImage; tYarnImage = new TTexpiaBitmap; tYarnImage->Create(tyarn->size_of_image/YARNIMAGEHEIGHT/3,YARNIMAGEHEIGHT,24); tYarnImage->LoadFromMemory((BYTE*)tyarn->lpimage, tyarn->size_of_image/YARNIMAGEHEIGHT, rect); HDC tDC = tYarnImage->CreateDC(); TPoint sp1; sp1.x = 2; sp1.y = 2; StretchBlt(YarnListStringGrid->Canvas->Handle,Rect.Left,Rect.Top,80,25, tDC,0,0,tYarnImage->Width, tYarnImage->Height,SRCCOPY); tYarnImage->DeleteDC(tDC); delete tYarnImage; break; } } } break; } default: break; } if(ACol == 1) edInput->Text = str; //ÀåÁø¸¸: ±ä À̸§ ©¸®´Â Çö»ó ÇØ°á else edInput->Text = ""; if(YarnListStringGrid->Cells[ACol][ARow]!="")YarnListStringGrid->Cells[ACol][ARow]=""; int x = ((Rect.right-Rect.left) - YarnListStringGrid->Canvas->TextWidth(str)) / 2; int y = ((Rect.bottom-Rect.top) - YarnListStringGrid->Canvas->TextHeight(str)) / 2; YarnListStringGrid->Canvas->TextOut(Rect.Left + x, Rect.Top + y, str); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::YarnListStringGridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { int ACol,ARow; YarnListStringGrid->MouseToCell(X, Y, ACol, ARow); col=ACol; row=ARow; //YarnListStringGrid->Col=ACol<1 ? 1 : ACol; //YarnListStringGrid->Row=ARow<1 ? 1 : ARow; TexLayer *texlayer = (TexLayer *)Main->texlayer; switch(ACol){ case 6: { if(!Shift.Contains(ssLeft))break; TColor c; PaletteForm->Visible=true; PaletteForm->InitForm(PaletteForm->Palette);//visible »óÅ¿¡¼­ ÃʱâÈ­ÇØ¾ß ½ºÅ©·Ñ¹Ù°¡ ¿òÁ÷¿©Áø´Ù PaletteForm->Visible=false; if(ARow-1==texlayer->YarnList->Count){ if(PaletteForm->ShowModal()==mrOk){ c=PaletteForm->DIB256Palette->FGColor; Yarn *yarn = new Yarn; yarn->color=c; texlayer->YarnList->Add(yarn); } } else if(ARow!=0&&ARow-1YarnList->Count){ Yarn *yarn = (Yarn *)texlayer->YarnList->Items[ARow-1]; if (yarn->exist_image) {//gabriel: Image color change if (YarnArrangeForm) delete YarnArrangeForm; YarnArrangeForm = new TYarnArrangeForm(this, yarn->lpimage, yarn->size_of_image); if(YarnArrangeForm->ShowModal()==mrOk){ //bitmap copy from YarnArrangeForm RECT rect = {0,0,yarn->size_of_image/YARNIMAGEHEIGHT/3,YARNIMAGEHEIGHT}; YarnArrangeForm->copiedbitmap->SaveToMemory((BYTE*)yarn->lpimage, yarn->size_of_image/YARNIMAGEHEIGHT, rect); yarn->color=YarnArrangeForm->GetAvgTColor(); } delete YarnArrangeForm; YarnArrangeForm = NULL; } else { RGBQUAD rgb = TColorToRGB(yarn->color); PaletteForm->DIB256Palette->SetNormal(1,rgb.rgbRed,rgb.rgbGreen,rgb.rgbBlue) ; // 1 ¹ÙÅÁ»ö if(PaletteForm->ShowModal()==mrOk){ yarn->color=PaletteForm->DIB256Palette->FGColor; } } } //YarnListStringGrid->Col=1; break; } case 10: { if(!row)break;//gabriel: Don't insert 0th row YarnListStringGrid->Row = row; YarnListStringGrid->Col = col; if(!Shift.Contains(ssLeft))break; if(ARow-1==texlayer->YarnList->Count){ Yarn *yarn = new Yarn; texlayer->YarnList->Add(yarn); } else if(ARow!=0&&ARow-1YarnList->Count){ if(!Shift.Contains(ssLeft))break; Yarn *yarn=(Yarn *)texlayer->YarnList->Items[ARow-1]; switch(yarn->ym){ case ymNONE: { yarn->ym=ymPO; break; } case ymPO: { yarn->ym=ymNY; break; } case ymNY: { yarn->ym=ymSPANDEX; break; } case ymSPANDEX: { yarn->ym=ymCOTTON; break; } case ymCOTTON: { yarn->ym=ymNONE; break; } } } //YarnListStringGrid->Col=1; break; } case 11: { if(!row)break;//gabriel: Don't insert 0th row YarnListStringGrid->Row = row; YarnListStringGrid->Col = col; if(!Shift.Contains(ssLeft))break; if(ARow-1==texlayer->YarnList->Count){ Yarn *yarn = new Yarn; texlayer->YarnList->Add(yarn); } else if(ARow!=0&&ARow-1YarnList->Count){ if(!Shift.Contains(ssLeft))break; Yarn *yarn=(Yarn *)texlayer->YarnList->Items[ARow-1]; switch(yarn->yp){ case ypNONE: { yarn->yp=ypSD; break; } case ypSD: { yarn->yp=ypFD; break; } case ypFD: { yarn->yp=ypCD; break; } case ypCD: { yarn->yp=ypSPK; break; } case ypSPK: { yarn->yp=ypBRT; break; } case ypBRT: { yarn->yp=ypPDD; break; } case ypPDD: { yarn->yp=ypSDY; break; } case ypSDY: { yarn->yp=ypAMT; break; } case ypAMT: { yarn->yp=ypNONE; break; } } } //YarnListStringGrid->Col=1; break; } default: break; } if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::YarnListStringGridMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int ACol,ARow; YarnListStringGrid->MouseToCell(X, Y, ACol, ARow); if(ACol==12){ YarnListStringGrid->Hint=IDS_COST_HINT; } else { YarnListStringGrid->Hint=""; } if(ACol==11){ YarnListStringGrid->PopupMenu=PopupMenuStringGridOpticalProperty; } else if(ACol==10) { YarnListStringGrid->PopupMenu=PopupMenuStringGridMaterial; } else { YarnListStringGrid->PopupMenu=PopupMenuStringGrid; } } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::FormCreate(TObject *Sender) { SetFont(); StringTable.Create(BaseDir, Language, "YarnList"); Caption=IDS_YARNLIST; pmAdd->Caption=IDS_ADD; pmDelete->Caption=IDS_DELETE; pmSave->Caption=IDS_SAVE; pmLoad->Caption=IDS_LOAD; pmLoadyan->Caption=IDS_LOADYAN; YarnListStringGrid->ColCount = 15; YarnListStringGrid->RowCount = 20; YarnListStringGrid->DefaultRowHeight = 25; YarnListStringGrid->ColWidths[0] = 38; YarnListStringGrid->ColWidths[1] = 120; YarnListStringGrid->ColWidths[2] = 70; YarnListStringGrid->ColWidths[3] = 60; YarnListStringGrid->ColWidths[4] = 60; YarnListStringGrid->ColWidths[5] = 65; YarnListStringGrid->ColWidths[6] = 100; YarnListStringGrid->ColWidths[7] = 90; YarnListStringGrid->ColWidths[8] = 90; YarnListStringGrid->ColWidths[9] = 95; YarnListStringGrid->ColWidths[10] = 65; YarnListStringGrid->ColWidths[11] = 60; YarnListStringGrid->ColWidths[12] = 70; YarnListStringGrid->ColWidths[13] = 95; YarnListStringGrid->ColWidths[14] = 80;//gabriel } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::SetFont(){ SetSmallFont(Font); //SetSmallFont(lbCourse->Font); //SetSmallFont(lbThread->Font); //SetSmallFont(lbLayer->Font); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmAddClick(TObject *Sender) { int i; TexLayer *texlayer = (TexLayer *)Main->texlayer; Yarn *yarn = new Yarn; if(row-1<0||row-1>texlayer->YarnList->Count){ texlayer->YarnList->Add(yarn); } else { texlayer->YarnList->Insert(row-1,yarn); } if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmDeleteClick(TObject *Sender) { int i; for(int j2=YarnListStringGrid->Selection.Bottom;j2>=YarnListStringGrid->Selection.Top;j2--){ TexLayer *texlayer = (TexLayer *)Main->texlayer; if(j2-1/*row-1*/<0||j2-1/*row-1*/>=texlayer->YarnList->Count){ return; } else if (j2-1 == 0) break; Yarn *yarn = (Yarn *)texlayer->YarnList->Items[j2-1/*row-1*/]; delete yarn; texlayer->YarnList->Delete(j2-1/*row-1*/); for(int i=0;iTexList->Count;i++){ Tex *tex=(Tex *)texlayer->TexList->Items[i]; for(int j=0;jWales->Count;j++){ WaleState *ws=(WaleState *)tex->Wales->Items[j]; if(ws->yarnIndex>=texlayer->YarnList->Count)ws->yarnIndex=0; } } } if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::SetMaterial(YARNMATERIAL ym) { TexLayer *texlayer = (TexLayer *)Main->texlayer; if(YarnListStringGrid->Row-1<0||YarnListStringGrid->Row-1>texlayer->YarnList->Count){ return; } if(YarnListStringGrid->Row-1==Main->texlayer->YarnList->Count){ Yarn *yarn = new Yarn; yarn->ym=ym; Main->texlayer->YarnList->Insert(YarnListStringGrid->Row-1,yarn); } else { Yarn *yarn = (Yarn *)Main->texlayer->YarnList->Items[YarnListStringGrid->Row-1]; yarn->ym=ym; } if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmymNONEClick(TObject *Sender) { SetMaterial(ymNONE); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmymPOClick(TObject *Sender) { SetMaterial(ymPO); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmymNYClick(TObject *Sender) { SetMaterial(ymNY); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmymSPANDEXClick(TObject *Sender) { SetMaterial(ymSPANDEX); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmymCOTTONClick(TObject *Sender) { SetMaterial(ymCOTTON); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmymDirectInputClick(TObject *Sender)//ÀåÁø¸¸ { SetMaterial(ymDirectInput); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::SetProperty(YARNPROPERTY yp) { TexLayer *texlayer = (TexLayer *)Main->texlayer; if(YarnListStringGrid->Row-1<0||YarnListStringGrid->Row-1>texlayer->YarnList->Count){ return; } if(YarnListStringGrid->Row-1==Main->texlayer->YarnList->Count){ Yarn *yarn = new Yarn; yarn->yp=yp; Main->texlayer->YarnList->Insert(YarnListStringGrid->Row-1,yarn); } else { Yarn *yarn = (Yarn *)Main->texlayer->YarnList->Items[YarnListStringGrid->Row-1]; yarn->yp=yp; } if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypNONEClick(TObject *Sender) { SetProperty(ypNONE); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypSDClick(TObject *Sender) { SetProperty(ypSD); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypFDClick(TObject *Sender) { SetProperty(ypFD); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypCDClick(TObject *Sender) { SetProperty(ypCD); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypSPKClick(TObject *Sender) { SetProperty(ypSPK); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypBRTClick(TObject *Sender) { SetProperty(ypBRT); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypPDDClick(TObject *Sender) { SetProperty(ypPDD); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypSDYClick(TObject *Sender) { SetProperty(ypSDY); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypAMTClick(TObject *Sender) { SetProperty(ypAMT); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmypDirectInputClick(TObject *Sender) { SetProperty(ypDirectInput); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::edInputKeyPress(TObject *Sender, char &Key) { AnsiString inputData; if(edInput->Focused()) fgEdit=2; if(fgEdit==1) inputData = edYarnList->Text; else inputData = edInput->Text; TexLayer *texlayer = (TexLayer *)Main->texlayer; switch(YarnListStringGrid->Col){ case 0: break; case 1: //# name ¼öÁ¤ { if(Key==VK_RETURN){ //2007.01.11. diekun ½Ç À̸§À» ´Ù½Ã Áö¿ï ¼öµµ ÀÖµµ·Ï ±×³É ¸®ÅÏÇÏ´Â °ÍÀ» ¸·¾Ò´Ù. //if(edInput->Text=="")return; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ strcpy(((Yarn *)texlayer->YarnList->Items[j-1])->name,inputData.c_str()); } else { Yarn *yarn = new Yarn; strcpy(yarn->name,inputData.c_str()); texlayer->YarnList->Add(yarn); bAdd = true; } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 2: { if(Key==VK_RETURN){ if(inputData=="")return; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ strcpy(((Yarn *)texlayer->YarnList->Items[j-1])->code,inputData.c_str()); } else { Yarn *yarn = new Yarn; strcpy(yarn->code,inputData.c_str()); texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 3: { if(Key==VK_RETURN){ if(inputData=="")return; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ strcpy(((Yarn *)texlayer->YarnList->Items[j-1])->lot,inputData.c_str()); } else { Yarn *yarn = new Yarn; strcpy(yarn->lot,inputData.c_str()); texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 4: { if(Key==VK_RETURN){ if(inputData=="")return; double d; d=StrToFloat(inputData); if(d<0)d=0; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->denier=d; } else { Yarn *yarn = new Yarn; yarn->denier=d; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 5: { if(Key==VK_RETURN){ if(inputData=="")return; int i; i=StrToInt(inputData); if(i<1)i=1; //if(i>255)i=255; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->filament=i; } else { Yarn *yarn = new Yarn; yarn->filament=i; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 7: { if(Key==VK_RETURN){ if(inputData=="")return; double v; v=StrToFloat(inputData); if(v<100)v=100; v/=100.0; v=1.0/v; v-=1; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->contraction=v; } else { Yarn *yarn = new Yarn; yarn->contraction=v; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 8: { if(Key==VK_RETURN){ if(inputData=="")return; double v; v=StrToFloat(inputData); if(v<0)v=0; if(v>1)v=1; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->reflection=v; } else { Yarn *yarn = new Yarn; yarn->reflection=v; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 9: { if(Key==VK_RETURN){ if(inputData=="")return; double v; v=StrToFloat(inputData); if(v<0)v=0; if(v>1)v=1; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->transparency=v; } else { Yarn *yarn = new Yarn; yarn->transparency=v; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 10: { if(Key==VK_RETURN){ if(inputData=="")return; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->ym=ymDirectInput; ((Yarn *)texlayer->YarnList->Items[j-1])->ymDirect=inputData; } else { Yarn *yarn = new Yarn; yarn->ym = ymDirectInput; yarn->ymDirect=inputData; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 11: { if(Key==VK_RETURN){ if(inputData=="")return; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->yp=ypDirectInput; ((Yarn *)texlayer->YarnList->Items[j-1])->ypDirect=inputData; } else { Yarn *yarn = new Yarn; yarn->yp = ypDirectInput; yarn->ypDirect=inputData; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 12: { if(Key==VK_RETURN){ if(inputData=="")return; double v; v=StrToFloat(inputData); if(v<0)v=0; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ ((Yarn *)texlayer->YarnList->Items[j-1])->cost=v; } else { Yarn *yarn = new Yarn; yarn->cost=v; texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } case 13: { if(Key==VK_RETURN){ if(inputData=="")return; for(int j=YarnListStringGrid->Selection.Top;j<=YarnListStringGrid->Selection.Bottom;j++){ if(j-1YarnList->Count){//Row´Â 1ºÎÅÍ ½ÃÀÛ strcpy(((Yarn *)texlayer->YarnList->Items[j-1])->detail,inputData.c_str()); } else { Yarn *yarn = new Yarn; strcpy(yarn->detail,inputData.c_str()); texlayer->YarnList->Add(yarn); } } edInput->Text=""; YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); YarnListStringGrid->Row++; } break; } default: break; } TRect rect = YarnListStringGrid->CellRect(YarnListStringGrid->Col, YarnListStringGrid->Row); edYarnList->Left = rect.left + YarnListStringGrid->Left; edYarnList->Top = rect.top + YarnListStringGrid->Top; edYarnList->Width = rect.Width(); edYarnList->Height = rect.Height(); if(fgEdit == 1){ edYarnList->Visible = true; edYarnList->SetFocus(); } if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::edInputKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { switch(Key){ case VK_LEFT: { if(YarnListStringGrid->Col>YarnListStringGrid->FixedCols) YarnListStringGrid->Col--; break; } case VK_RIGHT: { if(YarnListStringGrid->ColColCount-1) YarnListStringGrid->Col++; break; } case VK_UP: { if(YarnListStringGrid->Row>YarnListStringGrid->FixedRows) YarnListStringGrid->Row--; break; } case VK_DOWN: { if(YarnListStringGrid->RowRowCount-1) YarnListStringGrid->Row++; break; } } } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::FormPaint(TObject *Sender) { YarnListStringGrid->RowCount = Main->texlayer->YarnList->Count>20 ? Main->texlayer->YarnList->Count+10 : 30; YarnListStringGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::OpenDialogSelectionChange(TObject *Sender) { AnsiString str; HANDLE hFile = INVALID_HANDLE_VALUE; hFile = CreateFile(OpenDialog->FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL); if(hFile==NULL||hFile==INVALID_HANDLE_VALUE) return; Yarn *yarn = new Yarn; yarn->ReadFromFile(hFile); str+="NAME:"+AnsiString(yarn->name)+" "; str+="CODE:"+AnsiString(yarn->code)+" "; str+="MAKER:"+AnsiString(yarn->lot)+" "; YarnCompositionData_F->AddYMToStr(str,yarn->ym,yarn->ymDirect); str+=IntToStr((int)yarn->denier); str+="/"; str+=IntToStr(yarn->filament); str+=" "; YarnCompositionData_F->AddYPToStr(str,yarn->yp,yarn->ypDirect); lbSpec->Caption=str; CloseHandle(hFile); delete yarn; } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmLoadyanClick(TObject *Sender) { if (!YarnTableForm || YarnTableForm->Visible==false) YarnListForm->sbYarnTableClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmLoadClick(TObject *Sender) { HANDLE hFile = INVALID_HANDLE_VALUE; OpenDialog->InitialDir=BaseDir + "\\yarn"; OpenDialog->DefaultExt="yn"; OpenDialog->Filter="Yarn Files(*.yn)|*.yn"; if(OpenDialog->Execute()){ hFile = CreateFile(OpenDialog->FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL); TexLayer *texlayer = (TexLayer *)Main->texlayer; Yarn *yarn = NULL; if(row-1<0||row>texlayer->YarnList->Count){ yarn = new Yarn; texlayer->YarnList->Add(yarn); } else { yarn = (Yarn *)texlayer->YarnList->Items[row-1]; } yarn->ReadFromFile(hFile); CloseHandle(hFile); if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); } } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::pmSaveClick(TObject *Sender) { TexLayer *texlayer = (TexLayer *)Main->texlayer; if(row-1<0||row>texlayer->YarnList->Count){ ShowMessage(IDS_SELECT_YARN); return; } HANDLE hFile = INVALID_HANDLE_VALUE; SaveDialog->InitialDir=BaseDir + "\\yarn"; SaveDialog->DefaultExt="yn"; SaveDialog->Filter="Yarn Files(*.yn)|*.yn"; if(SaveDialog->Execute()){ hFile = CreateFile(SaveDialog->FileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); Yarn *yarn = NULL; yarn = (Yarn *)texlayer->YarnList->Items[row-1]; yarn->SaveToFile(hFile); CloseHandle(hFile); } } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::FormActivate(TObject *Sender) { pmypDirectInput->Caption = IDS_DIRECT_INPUT; pmymDirectInput->Caption = IDS_DIRECT_INPUT; } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::sbYarnTableClick(TObject *Sender) { //gabriel //Parent¸¦ MainÀ¸·Î ó¸®Çؼ­ ´Ù¸¥ Æû ¾Æ·¡¿¡ Ç¥½ÃµÇ´Â ¹®Á¦°¡ ¹ß»ýÇÑ´Ù. //À̹®Á¦¸¦ ó¸®Çϱ⠿ìÇØ¼­ YarnTableFormµµ ¿ª½Ã Auto Createed FormÀ¸·Î º¯°æÇß°í //ÀÌ ºÎºÐÀ» ÁÖ¼®À¸·Î ó¸®Çß´Ù. - by maxleo21c (06.11.08) /* if (YarnTableForm == NULL) { if ((YarnTableForm = new TYarnTableForm(this))==NULL) return;// throw EC_FORM_NOT_CREATE; } */ YarnTableForm->OnYarnChange = YarnChange; // YarnTableForm->Parent = Main; YarnTableForm->Panel1->Height = 40; //9_30 if(YarnTableForm->Visible==true){ YarnTableForm->Hide(); } else { YarnTableForm->Show(); } } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::YarnChange(AnsiString fn)//gabriel {//YarnTable yarn(TEXWEAVE YARN) --> to Tricot Yarn type AnsiString fullPathName = FullPathName(YarnTableForm->DirectoryListBox->Directory, fn); //Get bitmap Main->mYarnMaker->Checked = false; Main->mYarnMakerClick(NULL); YarnDesignForm->Visible = false; YarnDesignForm->use_ImageRepaint_bitmapcopy = true; YarnDesignForm->FileRead_public(fullPathName); YarnDesignForm->use_ImageRepaint_bitmapcopy = false; HDC dc_yarn = YarnDesignForm->original_yarn_image->CreateDC(); // Copy to TexpiaBitmap TTexpiaBitmap *tYarnImage; tYarnImage = new TTexpiaBitmap; int YarnImageWidth = YarnDesignForm->original_yarn_image->Width; tYarnImage->Create(YarnImageWidth,YARNIMAGEHEIGHT,24); HDC tDC = tYarnImage->CreateDC(); BitBlt(tDC, 0,0,YarnDesignForm->original_yarn_image->Width, YarnDesignForm->original_yarn_image->Height, dc_yarn,0,0,SRCCOPY); tYarnImage->DeleteDC(tDC); YarnDesignForm->original_yarn_image->DeleteDC(dc_yarn); Main->mYarnMaker->Checked = true; Main->mYarnMakerClick(this);//dummy pointer - not changed //~Get bitmap TYarnData *YarnFromYTable = new TYarnData; YarnFromYTable->LoadFromFile(fullPathName); //add data to Yarn List TexLayer *texlayer = (TexLayer *)Main->texlayer; Yarn *yarn = NULL; if(row-1<0||row>texlayer->YarnList->Count){ yarn = new Yarn; texlayer->YarnList->Add(yarn); } else {//change in the middle yarn = (Yarn *)texlayer->YarnList->Items[row-1]; } //yarn data converting ... yarn->cost = 0; yarn->contraction = 0; yarn->reflection = 0.3; yarn->transparency = 0.3; if (YarnFromYTable->Unit.Method == YU_DIRECT) yarn->ym = ymPO; else yarn->ym = ymCOTTON; if (YarnFromYTable->Dyed) yarn->ym = ymNONE; //½ºÄµ»çÀÏ °æ¿ì yarn->yp = ypNONE; yarn->filament = 20; if (YarnFromYTable->TYC == 1 && !YarnFromYTable->Hair && !YarnFromYTable->Fancy && !YarnFromYTable->Dyed && YarnFromYTable->yInfor->Type==0) yarn->is_simple = true;//Çì¾î,ÆÒ½Ã¾ø´Â ´Ü»ç. ½ºÄµ»ç, ·¹Àκ¸¿ì, ¸á¶õÁö´Â Á¦¿Ü //calculate Denier from YarnData->realthick yarn->denier = (YarnFromYTable->Dyed)? 1.38*3.14*900000/(2+3*log(20)) *pow(YarnFromYTable->RealThick/2*0.1,2):YarnFromYTable->Count; yarn->RealThick = YarnFromYTable->RealThick; yarn->DPI = YarnFromYTable->DPI; yarn->YarnUnit.Copy(YarnFromYTable->Unit); strcpy(yarn->name,fn.c_str());//copy c-style strings strcpy(yarn->code,""); strcpy(yarn->lot,""); strcpy(yarn->detail,""); yarn->exist_image = true; yarn->size_of_image = 3*YarnImageWidth*YARNIMAGEHEIGHT; if(yarn->lpimage) VirtualUnlock(yarn->lpimage,yarn->size_of_image); if(yarn->lpimage) VirtualFree(yarn->lpimage,yarn->size_of_image,MEM_DECOMMIT); yarn->lpimage = VirtualAlloc(NULL,yarn->size_of_image,MEM_COMMIT,PAGE_READWRITE); if(yarn->lpimage) VirtualLock(yarn->lpimage,yarn->size_of_image); // Copy from TexpiaBitmap to yarn image RECT rect = {0,0,YarnImageWidth,YARNIMAGEHEIGHT}; tYarnImage->SaveToMemory((BYTE*)yarn->lpimage, yarn->size_of_image/YARNIMAGEHEIGHT, rect); yarn->color = TYarnArrangeForm::GetAvgTColor_fromImage(yarn->lpimage, yarn->size_of_image); delete tYarnImage; if(YarnCompositionData_F&&YarnCompositionData_F->Visible)YarnCompositionData_F->Repaint(); YarnListStringGrid->Repaint(); DesignForm->DrawChart(false); } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::YarnListStringGridDblClick(TObject *Sender) { if((col==1||col==2||col==3||col==4||col==5||col==7||col==8||col==9||col==12||col==13) && row!=0){ fgEdit=1; TRect a = YarnListStringGrid->CellRect(col, row); edYarnList->Left = a.left + YarnListStringGrid->Left; edYarnList->Top = a.top + YarnListStringGrid->Top; edYarnList->Width = a.Width(); edYarnList->Height = a.Height(); edYarnList->Text = ""; edYarnList->Visible = true; edYarnList->SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TYarnListForm::edYarnListExit(TObject *Sender) { edYarnList->Visible = false; } //---------------------------------------------------------------------------