//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TextureDesign_F.h" #include "MainImage.h" #include "TextureArrange.h" #include "TextureTable_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPImage" #pragma link "TPTextileImage" #pragma link "TPRuler2D" #pragma link "TPSpin" #pragma resource "*.dfm" TTextureDesignForm *TextureDesignForm; //--------------------------------------------------------------------------- #define IDS_FORMCAPTION StringTable[0] #define IDS_CUT StringTable[1] #define IDS_COORD StringTable[2] //--------------------------------------------------------------------------- __fastcall TTextureDesignForm::TTextureDesignForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FormCreate(TObject *Sender) { TexImage->OnPaintZoom = DrawTexture; TexImage->Bitmap->Create(40, 60, 8); TexImage->Bitmap->FillRect(Rect(0, 0, 40, 60), clWhite); TexImage->Width = 481; TexImage->Height = 721; TexImage->SetZoom(12, 1); TexImage->PaintImageEdit(DrawTexture); brRuler->Zoom = 12; //=========================================================================== StringTable.Create(DirectoryItem, Language, "TextureDesign"); SetSmallFont(Font); SetSmallFont(Label2->Font); SetSmallFont(stKind->Font); Caption = IDS_FORMCAPTION; lbCut->Caption = IDS_CUT; Label1->Caption = IDS_COORD; Label4->Caption = "Current Texture : T" + IntToStr(MainImageForm->Plan->Texture->page+1); spExecute->Caption = IDS_COMMON_RUN; //=========================================================================== TextureGrid->RowHeights[0] = 30;//20; TextureTableForm->OnTextureFileChange = TextureFileChange; if (MainImageForm->Plan->Dsim.machine) stKind->Caption = "TRICORT"; else stKind->Caption = "D.N.B"; if (MainImageForm->Plan->Texture->Count > 0) pspCut->Value = MainImageForm->Plan->Texture->Array[0].cut; CopyPanel->Visible = false; IsCopy = false; bmpW = 40; bmpH = 60; TIniFile *IniFile = new TIniFile(DirectoryItem+"\\TextureDesign.ini"); if (IniFile) { Left = IniFile->ReadInteger("TextureDesign", "FormLeft", (Screen->Width-Width)>>1); Top = IniFile->ReadInteger("TextureDesign", "FormTop", (Screen->Height-Height)>>1); delete IniFile; } else goto fail; return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::FormDestroy(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem+"\\TextureDesign.ini"); if (IniFile) { if (Left<0) Left = 10; if (Top<0) Top = 10; IniFile->WriteInteger("TextureDesign", "FormLeft", Left); IniFile->WriteInteger("TextureDesign", "FormTop", Top); delete IniFile; } else goto fail; MainImageForm->Plan->Texture->bFinish = SetFinish(); return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::stKindClick(TObject *Sender) { if (MainImageForm->Plan->Dsim.machine == TRICOT) { stKind->Caption = "D.N.B"; MainImageForm->Plan->Dsim.machine = DNB; } else { stKind->Caption = "TRICORT"; MainImageForm->Plan->Dsim.machine = TRICOT; } TexImage->Repaint(); TextureGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spNewClick(TObject *Sender) { int i, j; TPointData *tp= MainImageForm->Plan->Texture->Array; for (i = 0; i < 6; i++) { if (tp[i].sx) { for (j = 0; j < tp[i].number; j++) { tp[i].Data[j].DX = 0; tp[i].Data[j].DY = 0; } tp[i].sx = 0; tp[i].number = 0; tp[i].cut = 0; } } MainImageForm->Plan->Texture->Count = 0; TexImage->Repaint(); TextureGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spClearClick(TObject *Sender) { TTextureArrange *ta = MainImageForm->Plan->Texture; for(int i = 1; i <= ta->Array[ta->page].number; i++) { ta->Array[ta->page].Data[i].DX=0; ta->Array[ta->page].Data[i].DY=0; } ta->Array[ta->page].number = 0; ta->Array[ta->page].sx = 0; ta->Array[ta->page].cut = 0; pspCut->Value = 0; TexImage->Repaint(); IsCopy = false; CopyPanel->Visible = false; TextureGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spBackClick(TObject *Sender) { TTextureArrange *ta = MainImageForm->Plan->Texture; if(ta->Array[ta->page].number>0) { ta->Array[ta->page].number--; } else if (ta->Array[ta->page].sx) { ta->Array[ta->page].sx = 0; } MY = 1; TexImage->Repaint(); IsCopy = false; CopyPanel->Visible = false; TextureGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spLShiftClick(TObject *Sender) { int MaxX; TTextureArrange *ta = MainImageForm->Plan->Texture; if(ta->Array[ta->page].number) { MaxX = ta->Array[ta->page].sx; for(int i=0; i < ta->Array[ta->page].number; i++) { if(MaxX < ta->Array[ta->page].Data[i].DX) MaxX = ta->Array[ta->page].Data[i].DX; } if(MaxX < bmpW) { ta->Array[ta->page].sx++; for(int i=0; i < ta->Array[ta->page].number; i++) { ta->Array[ta->page].Data[i].DX++; } } } else if (ta->Array[ta->page].sx) { if (ta->Array[ta->page].sx < bmpW) ta->Array[ta->page].sx++; } MY = 1; TexImage->Repaint(); IsCopy = false; CopyPanel->Visible = false; TextureGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spRShiftClick(TObject *Sender) { int MinX; TTextureArrange *ta = MainImageForm->Plan->Texture; if(ta->Array[ta->page].number) { MinX = ta->Array[ta->page].sx; for(int i = 0; i < ta->Array[ta->page].number; i++) { if(MinX > ta->Array[ta->page].Data[i].DX) MinX = ta->Array[ta->page].Data[i].DX; } if(MinX > 1) { ta->Array[ta->page].sx--; for(int i=0; iArray[ta->page].number; i++) { ta->Array[ta->page].Data[i].DX--; } } } else if (ta->Array[ta->page].sx) { if (ta->Array[ta->page].sx > 1) ta->Array[ta->page].sx--; } MY = 1; TexImage->Repaint(); IsCopy = false; CopyPanel->Visible = false; TextureGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spCopyClick(TObject *Sender) { TTextureArrange *ta = MainImageForm->Plan->Texture; if (IsCopy) { CopyPanel->Visible = false; IsCopy = false; } else { CopyPanel->Visible = true; IsCopy = true; if (ta->Array[ta->page].number && (spSrc->Value != spDst->Value)) spExecute->Enabled = true; else spExecute->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spExecuteClick(TObject *Sender) { int sour, dest, i; TTextureArrange *ta = MainImageForm->Plan->Texture; sour = spSrc->Value-1; dest = spDst->Value-1; if(sour != dest) { if(ta->Array[dest].number > ta->Array[sour].number) { ta->Array[dest].sx =0; for(int k=0; kArray[dest].number; k++) { ta->Array[dest].Data[k].DX = 0; ta->Array[dest].Data[k].DY = 0; } ta->Array[dest].number = 0; } ta->Array[dest].sx = ta->Array[sour].sx; ta->Array[dest].number = ta->Array[sour].number; ta->Array[dest].cut = ta->Array[sour].cut; for(i=0; iArray[sour].number; i++) { ta->Array[dest].Data[i].Pass = ta->Array[sour].Data[i].Pass; ta->Array[dest].Data[i].DX = ta->Array[sour].Data[i].DX; ta->Array[dest].Data[i].DY = ta->Array[sour].Data[i].DY; } pspCut->Value = ta->Array[dest].cut; ta->page = dest; TexImage->Repaint(); if (dest == ta->Count) ta->Count++; } IsCopy = false; CopyPanel->Visible = false; TextureGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spSrcChange(TObject *Sender) { TTextureArrange *ta = MainImageForm->Plan->Texture; ta->page = spSrc->Value - 1; if(ta->Array[ta->page].number == 0) { spExecute->Enabled = false; } else if(spDst->Value == spSrc->Value) { spExecute->Enabled = false; } else { spExecute->Enabled = true; } TexImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spDstChange(TObject *Sender) { int k = spSrc->Value; TTextureArrange *ta = MainImageForm->Plan->Texture; if(ta->Array[k-1].number == 0 || k == spDst->Value || ta->Count + 1 < spDst->Value) { spExecute->Enabled = false; } else { spExecute->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::spOpenClick(TObject *Sender) { TextureTableForm->Visible = true; TextureTableForm->BringToFront(); IsCopy = false; CopyPanel->Visible = false; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::TextureGridClick(TObject *Sender) { TTextureArrange *ta = MainImageForm->Plan->Texture; ta->page = TextureGrid->Row - 1; spSrc->Value = ta->page+1; pspCut->Value = ta->Array[ta->page].cut; MY = 1; Label4->Caption = "Current Texture : T" + IntToStr(TextureGrid->Row); TexImage->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::TextureGridDrawCell(TObject *Sender, int Col, int Row, TRect &Rect, TGridDrawState State) { TTextureArrange *ta; int x, y; TPoint sp; TSize vs = { 120, 120 }; // 75, 120 ta = MainImageForm->Plan->Texture; sp.x = Rect.Left + 20; sp.y = Rect.Top + 2; if (Row == 0) { x = (vs.cx - TextureGrid->Canvas->TextWidth("Preview")) / 2; y = (30 - TextureGrid->Canvas->TextHeight("Preview")) / 2; TextureGrid->Canvas->Font->Color = clBlue; TextureGrid->Canvas->TextOut(x, y, "Preview"); } else { if (ta->Array[Row - 1].sx) { ta->Draw(TextureGrid->Canvas, sp, vs, Row - 1, MainImageForm->Plan->Dsim.machine); } TextureGrid->Canvas->Font->Color = clRed; TextureGrid->Canvas->TextOut(sp.x - 15, sp.y + 5, AnsiString(Row)); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::TexImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { int page, num, first=0; TPointData *tp = MainImageForm->Plan->Texture->Array; page = MainImageForm->Plan->Texture->page; num = MainImageForm->Plan->Texture->Array[page].number; if (page < MainImageForm->Plan->Texture->Count+1) { X = bmpW - X; Y = bmpH - Y; if (tp[page].sx == 0) { // first occur if (Y != 1) { Y--; InputData(X, Y); } tp[page].sx = X; } else { if (num == 0) { // secondary occur if (tp[page].sx != X) Y--; InputData(X, Y); } else if (tp[page].Data[num - 1].Pass == PT_JUMP) { // other // if (num == 1) first = 1; // for tp[page].Data[1].DY = 1 when tp[page].Data[0].DY = 1 // else first = 0; if ((Y+first) > tp[page].Data[num - 1].DY) { InputData(tp[page].Data[num - 1].DX, Y); } } else if (tp[page].Data[num - 1].Pass == PT_EXIST) { if (Y > tp[page].Data[num - 1].DY) { InputData(X, --Y); } } } if (page == MainImageForm->Plan->Texture->Count) MainImageForm->Plan->Texture->Count++; IsCopy = false; CopyPanel->Visible = false; TexImage->Repaint(); TextureGrid->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::TexImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { TPointData *tp; int page, num; tp= MainImageForm->Plan->Texture->Array; CursorPosition.x = X + 1; CursorPosition.y = TexImage->Bitmap->Height - Y - 1; brRuler->PositionBar(CursorPosition); page = MainImageForm->Plan->Texture->page; num = MainImageForm->Plan->Texture->Array[page].number; MY = bmpH - Y; /* if (num) { if(tp[page].Data[num-1].DY < MY) { TexImage->Repaint(); } } else { if (tp[page].sx) TexImage->Repaint(); } */ TexImage->Repaint(); Label3->Caption = Format("( %d , %d )", OPENARRAY(TVarRec, (bmpW-X-1, bmpH-Y-1))); } //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::InputData(int x, int y) { int page, num; TPointData *tp; page = MainImageForm->Plan->Texture->page; num = MainImageForm->Plan->Texture->Array[page].number; tp = MainImageForm->Plan->Texture->Array; if (num == 0) { tp[page].Data[num].Pass = tp[page].sx==x ? PT_EXIST : PT_JUMP; } else { tp[page].Data[num].Pass = tp[page].Data[num - 1].Pass==PT_JUMP ? PT_EXIST : PT_JUMP; } tp[page].Data[num].DX = x; tp[page].Data[num].DY = y; tp[page].number++; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawRectangle(HDC dc, int sx, int sy, int ey) { int page; TPointData *tp; HPEN newpen = NULL, oldpen = NULL; HBRUSH rbrush = NULL, obrush = NULL; tp = MainImageForm->Plan->Texture->Array; page = MainImageForm->Plan->Texture->page; newpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); if (newpen) { oldpen = SelectObject(dc, newpen); if (tp[page].number == 0) { //for red rectangle where sx point rbrush = CreateSolidBrush( RGB(255, 0, 0)); obrush = SelectObject(dc, rbrush); } else { rbrush = SelectObject(dc, GetStockObject(BLACK_BRUSH)); } for(int k = sy; k < ey; k++) { Rectangle(dc, 12*(bmpW - sx) + 2, 12*(bmpH - k) - 9, 12*(bmpW - sx) + 11, 12*(bmpH - k)); } SelectObject(dc, oldpen); DeleteObject(newpen); if (tp[page].number == 0) { SelectObject(dc, obrush); DeleteObject(rbrush); } else { SelectObject(dc, rbrush); } } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawLine(HDC dc, int sx, int sy, int ex, int ey) { int first; HPEN newpen, oldpen; newpen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); if (newpen) { oldpen = SelectObject(dc, newpen); if (ey ==0) first = 1; // for lining from sx to first point if y of first point is 1 else first = 0; MoveToEx(dc, 12 * (bmpW - sx) + 6, 12 * (bmpH - sy) - first, NULL); LineTo(dc, 12 * (bmpW - ex) + 6, 12*(bmpH - ey) - first); SelectObject(dc, oldpen); DeleteObject(newpen); } } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::DrawTexture(TObject *Sender, HDC dc) { TPointData *tp= MainImageForm->Plan->Texture->Array; int page, num; page = MainImageForm->Plan->Texture->page; num = MainImageForm->Plan->Texture->Array[page].number; if (num == 0 && tp[page].sx) { DrawRectangle(dc, tp[page].sx, 0, MY); } else { for (int i = 0; i < num; i++) { if (i == 0) { if (tp[page].Data[i].Pass == PT_EXIST) { DrawRectangle(dc, tp[page].sx, 0, tp[page].Data[i].DY); } else if (tp[page].Data[i].Pass == PT_JUMP) { if (MainImageForm->Plan->Dsim.machine) { DrawLine(dc, tp[page].sx, 0, tp[page].Data[0].DX, tp[page].Data[0].DY); } else { DrawLine(dc, tp[page].sx, 0, tp[page].sx, tp[page].Data[0].DY); DrawLine(dc, tp[page].sx, tp[page].Data[0].DY, tp[page].Data[0].DX, tp[page].Data[0].DY); } } } else { if (tp[page].Data[i].Pass == PT_EXIST) { DrawRectangle(dc, tp[page].Data[i-1].DX, tp[page].Data[i-1].DY, tp[page].Data[i].DY); } else if (tp[page].Data[i].Pass == PT_JUMP) { if (MainImageForm->Plan->Dsim.machine) { DrawLine(dc, tp[page].Data[i-1].DX, tp[page].Data[i-1].DY, tp[page].Data[i].DX, tp[page].Data[i].DY); } else { DrawLine(dc, tp[page].Data[i-1].DX, tp[page].Data[i-1].DY, tp[page].Data[i-1].DX, tp[page].Data[i].DY); DrawLine(dc, tp[page].Data[i-1].DX, tp[page].Data[i].DY, tp[page].Data[i].DX, tp[page].Data[i].DY); } } } } //Draw black color when mouse move if (tp[page].Data[num-1].Pass == PT_JUMP) { DrawRectangle(dc, tp[page].Data[num-1].DX, tp[page].Data[num-1].DY, MY); } } } //--------------------------------------------------------------------------- bool __fastcall TTextureDesignForm::SetFinish() { TTextureArrange *ta = MainImageForm->Plan->Texture; for (int i = 0; i < ta->Count; i++) { if (ta->Array[i].sx == 0) return false; } return true; } //--------------------------------------------------------------------------- // //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::TextureFileChange() { TPointData *tp= MainImageForm->Plan->Texture->Array; int page = MainImageForm->Plan->Texture->page; int x, y; x = tp[0].Data[0].DX; y = tp[0].Data[0].DY; TextureGrid->Repaint(); TexImage->Repaint(); pspCut->Value =tp[page].cut; } //--------------------------------------------------------------------------- void __fastcall TTextureDesignForm::pspCutChange(TObject *Sender) { TPointData *tp= MainImageForm->Plan->Texture->Array; int page = MainImageForm->Plan->Texture->page; if (tp[page].number > 0) { if (pspCut->Text.Length() > 0) { tp[page].cut = pspCut->Value; } } else pspCut->Value = 0; } //---------------------------------------------------------------------------