//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TextureTable_F.h" #include "MainImage.h" #include "TextureDesign_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_PART StringTable[0] #define IDS_MAKEFOLDER StringTable[1] #define IDS_CURRENTDIR StringTable[2] TTextureTableForm *TextureTableForm; //--------------------------------------------------------------------------- __fastcall TTextureTableForm::TTextureTableForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::FormCreate(TObject *Sender) { AnsiString IniDirName; //=========================================================================== StringTable.Create(DirectoryItem, Language, "TextureTable"); SetSmallFont(Font); SetSmallFont(Label1->Font); sbRead->Caption = IDS_COMMON_READ; sbPart->Caption = IDS_PART; sbSave->Caption = IDS_COMMON_SAVE; sbSaveAs->Caption = IDS_COMMON_SAVEAS; sbDelete->Caption = IDS_COMMON_DELETE; sbMakeFolder->Caption = IDS_MAKEFOLDER; sbExit->Caption = IDS_COMMON_EXIT; Label1->Caption = IDS_CURRENTDIR; //=========================================================================== if(MainImageForm->Plan->Dsim.machine) IniDirName = DirectoryTexture + "\\Tricot"; else IniDirName = DirectoryTexture + "\\Dnb"; TIniFile *IniFile = new TIniFile(DirectoryItem+"\\TextureTable.ini"); if (IniFile) { Left = IniFile->ReadInteger("TextureTable", "FormLeft", (Screen->Width-Width)>>1); Top = IniFile->ReadInteger("TextureTable", "FormTop", (Screen->Height-Height)>>1); Width = IniFile->ReadInteger("TextureTable", "FormWidth", Width); Height = IniFile->ReadInteger("TextureTable", "FormHeight", Height); delete IniFile; } else goto fail; DirectoryListBox->Directory = IniDirName; DirectoryListBox->ItemIndex = 0; Table = new TList; if (!Table) goto fail; Item = 0; return; fail : if (IniFile) delete IniFile; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::FormDestroy(TObject *Sender) { while (Table->Count) { TTextureArrange *ta = (TTextureArrange *) Table->Last(); Table->Remove(ta); delete ta; } delete Table; TIniFile *IniFile = new TIniFile(DirectoryItem+"\\TextureTable.ini"); if (IniFile) { if (Left<0) Left = 10; if (Top<0) Top = 10; IniFile->WriteInteger("TextureTable", "FormLeft", Left); IniFile->WriteInteger("TextureTable", "FormTop", Top); IniFile->WriteInteger("TextureTable", "FormWidth", Width); IniFile->WriteInteger("TextureTable", "FormHeight", Height); delete IniFile; } else goto fail; return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::FormResize(TObject *Sender) { TextureTableGrid->ColCount = (TextureTableGrid->Width-4) / 90; TextureTableGrid->RowCount = (FileListBox->Items->Count-1) / TextureTableGrid->ColCount+1; int w = (Panel1->Width - 10) / 7; sbRead->Width = w; sbPart->Left = sbRead->Left + w; sbPart->Width = w; sbSave->Left = sbPart->Left + w; sbSave->Width = w; sbSaveAs->Left = sbSave->Left + w; sbSaveAs->Width = w; sbDelete->Left = sbSaveAs->Left + w; sbDelete->Width = w; sbMakeFolder->Left = sbDelete->Left + w; sbMakeFolder->Width = w; sbExit->Left = sbMakeFolder->Left + w; sbExit->Width = w; } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::TextureTableGridDrawCell(TObject *Sender, int Col, int Row, TRect &rect, TGridDrawState State) { TTextureArrange *ta; int x, y; TPoint sp; AnsiString str; TSize vs = { 80, 120 }; // 75, 120 int n = Row*TextureTableGrid->ColCount+Col; if (nItems->Count) { ta = (TTextureArrange *)Table->Items[n]; sp.x = rect.Left + 5; sp.y = rect.Top + 2; ta->Draw(TextureTableGrid->Canvas, sp, vs, ta->page, MainImageForm->Plan->Dsim.machine); str = AnsiString(ta->page+1); TextureTableGrid->Canvas->TextOut(sp.x + 5, sp.y + 5, str); TRect TextRect = Rect(rect.Left, rect.Top + (vs.cy + 4), rect.Right, rect.Bottom); x = (90 - TextureTableGrid->Canvas->TextWidth(ta->FileName)) / 2; TextureTableGrid->Canvas->TextRect(TextRect, TextRect.Left + x, TextRect.Top+5 , ta->FileName); } } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::FileListBoxChange(TObject *Sender) { TTextureArrange *ta = NULL; int cnt = FileListBox->Items->Count; if (Table) { while (Table->Count) { ta = (TTextureArrange *) Table->Last(); Table->Remove(ta); delete ta; ta = NULL; } for (int i=0; i < cnt; i++) { if ((ta = new TTextureArrange) == NULL) goto fail; if (ta->LoadFromFile(FileListBox->Items->Strings[i]) == EC_NONE) { Table->Add(ta); } else { delete ta; } ta = NULL; } if (cnt >= TextureTableGrid->ColCount*TextureTableGrid->RowCount) TextureTableGrid->RowCount = (cnt / 3) + 1; TextureTableGrid->Repaint(); } return; fail : if (ta) delete ta; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::TextureTableGridDblClick(TObject *Sender) { TTextureArrange *ta; int Index = TextureTableGrid->Col + (TextureTableGrid->Row * TextureTableGrid->ColCount); if (Index < Table->Count) { ta = (TTextureArrange *) Table->Items[Index]; // Item 0: Read 1: Part Read 2: OverWrite 4: Delete if (Item == 0) { MainImageForm->Plan->Texture->Copy(ta); TextureDesignForm->spClear->Enabled = true; } else if (Item == 1) { MainImageForm->Plan->Texture->PartCopy(ta); TextureDesignForm->spClear->Enabled = true; } else if (Item == 2) { ta->Copy(MainImageForm->Plan->Texture); ta->SaveToFile(ta->FileName); } else if (Item == 4) { if (MessageDlg(IDS_MESSAGE_DELETETEXTURE, mtWarning, TMsgDlgButtons()<FileName); Table->Remove(ta); delete ta; } } FileListBox->Update(); TextureTableGrid->Repaint(); if (FOnTextureFileChange) FOnTextureFileChange(); } Item = 0; sbRead->Down = true; } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::sbFunctionClick(TObject *Sender) { TSpeedButton *sp = (TSpeedButton *)Sender; Item = sp->Tag; } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::sbSaveAsClick(TObject *Sender) { TTextureArrange *ta; AnsiString fn = "Noname.ptx"; if (InputQuery(IDS_COMMON_SAVEAS, IDS_COMMON_INPUTNAME, fn)) { fn = FileNameExt(fn); if (!FileExists(fn)) { ta = new TTextureArrange; if (!ta) goto fail; ta->Copy(MainImageForm->Plan->Texture); ta->SaveToFile(fn); Table->Add(ta); Item = 0; sbRead->Down = true; FileListBox->Update(); TextureTableGrid->Repaint(); if (FOnTextureFileChange) FOnTextureFileChange(); } else { EXCEPTION_MESSAGE_OK(EC_FILE_EXIST_ALREADY); sbSaveAsClick(Sender); } } return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- AnsiString __fastcall TTextureTableForm::FileNameExt(AnsiString fn) { char *s = AnsiStrScan(fn.c_str(), '.'); if (s==NULL) return fn + ".ptx"; else return fn; } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::sbMakeFolderClick(TObject *Sender) { AnsiString dir = ""; if (InputQuery(IDS_COMMON_MAKEFOLDER, IDS_COMMON_INPUTNAME, dir)) { CreateDirectory(dir.c_str(), NULL); DirectoryListBox->Update(); } } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::TextureTableGridMouseDown( TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TTextureArrange *ta; TGridCoord gc; if (Button == mbRight) { gc = TextureTableGrid->MouseCoord(X, Y); int Index = gc.X + (gc.Y * TextureTableGrid->ColCount); if (Index < Table->Count) { ta = (TTextureArrange *) Table->Items[Index]; ta->page++; if (ta->page == ta->Count) ta->page = 0; TextureTableGrid->Repaint(); } } } //--------------------------------------------------------------------------- void __fastcall TTextureTableForm::sbExitClick(TObject *Sender) { Visible = false; } //---------------------------------------------------------------------------