//--------------------------------------------------------------------- #include #include #include #include #pragma hdrstop #include "MainImage.h" #include "ColorLibrary_F.h" #include "FullView.h" #include "History.h" #include "Main.h" #include "Palette.h" #include "ProtectCard.h" #include "UserColor_F.h" #include "MainMenu_F.h" //--------------------------------------------------------------------- #pragma link "TPImage" #pragma link "TPWeaveImage" #pragma link "TPRuler2D" #pragma resource "*.dfm" TMainImageForm *MainImageForm; int MainImageCount = 0; //--------------------------------------------------------------------- #define IDS_WZOOMIN StringTable[0] #define IDS_WZOOMOUT StringTable[1] #define IDS_WRULER StringTable[2] //--------------------------------------------------------------------- __fastcall TMainImageForm::TMainImageForm(TComponent *Owner) : TForm(Owner) { Number = MainImageCount; MainImageCount++; LineList = new TList; } //--------------------------------------------------------------------- void __fastcall TMainImageForm::FormActivate(TObject *Sender) { if (MainImageForm!=this) { MainMenuForm->ExitForm(); MainImageForm = this; } WorkAreaChange(); ReviewStatusBar(); } //--------------------------------------------------------------------- void __fastcall TMainImageForm::FormClose(TObject *Sender, TCloseAction &Action) { MainImageForm = NULL; Action = caFree; delete LineList; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormCloseQuery(TObject *Sender, bool &CanClose) { AnsiString msg, fn, ext; char *s; ext = ".pil"; /* if (Plan->Weaving) { msg = Format("Save changes to %s!", OPENARRAY (TVarRec,(FileName))); int Btn = MessageDlg(msg, mtWarning, TMsgDlgButtons()<SaveDialog->Execute()) { s = AnsiStrScan(MainForm->SaveDialog->FileName.c_str(), '.'); if (s==NULL) fn = MainForm->SaveDialog->FileName+ext; else fn = MainForm->SaveDialog->FileName; DirName = ExtractFileDir(fn); FileName = ExtractFileName(fn); SaveToFile(DirName, FileName, MainForm->CompressMethod); CanClose = true; } } else { SaveToFile(DirName, FileName, MainForm->CompressMethod); CanClose = true; } } else if (Btn == mrNo) { CanClose = true; } else { CanClose = false; } } else { */ CanClose = true; // } if (CanClose) { if (FileExists(FileName)) { FileHistory->InsertHistory(DirName, ExtractFileName(FileName), 1, iMainImage->Bitmap->BitsPerPixel); } } MainMenuForm->ExitForm(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormCreate(TObject *Sender) { #ifndef LOCK_CRYPKEY #ifndef LOCK_IFC ProtectCard->Check(); #endif #endif int unit; TIniFile *IniFile = new TIniFile(DirectoryItem+"\\Environment.ini"); if (IniFile) { unit = IniFile->ReadInteger("MainImage", "Unit", 0); delete IniFile; } //================================================= StringTable.Create(DirectoryItem, Language, "MainImage"); SetSmallFont(Font); SetSmallFont(TempLabel->Font); sbZoomIn->Hint = IDS_WZOOMIN; sbZoomOut->Hint = IDS_WZOOMOUT; sbGrid->Hint = IDS_COMMON_GRID; sbRuler->Hint = IDS_WRULER; //================================================= if ((WorkArea = new TWorkArea(&(iMainImage->Bitmap)))==NULL) goto fail; if ((Palette = new TPalette)==NULL) goto fail; if ((Plan = new TPlan)==NULL) goto fail; MainImageForm = this; CanvasInfor.DotsPerInch = 160; CanvasInfor.SetExtFileOption(); if (unit == 0) { CurrentUnit = uCm; sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Cm"; } else { CurrentUnit = uInch; sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Inch"; } UnitChange(); ApplyEnvironment(); ZoomChange(1, 1); PaletteForm->InitForm(Palette); ReviewStatusBar(); bChoiceExchange = false; return; fail: ::doDestroy(Plan); ::doDestroy(Palette); ::doDestroy(WorkArea); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormDestroy(TObject *Sender) { MainMenuForm->ExitForm(); ::doDestroy(Plan); ::doDestroy(Palette); ::doDestroy(WorkArea); FullViewForm->InitForm(NULL); MainImageForm = NULL; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormResize(TObject *Sender) { Ruler->Width = ClientWidth-PanelVert->Width-4; Ruler->Height = ClientHeight-PanelHorz->Height-4; if (sbRuler->Down) { Panel->Left = Ruler->Thick; Panel->Width = Ruler->Width-Ruler->Thick; Panel->Height = Ruler->Height-Ruler->Thick; } else { Panel->Left = 0; Panel->Width = Ruler->Width; Panel->Height = Ruler->Height; } PanelHorz->Top = Ruler->Top+Ruler->Height+4; PanelHorz->Width = ClientWidth-PanelVert->Width; PanelVert->Left = Panel->Left+Panel->Width+4; PanelVert->Height = ClientHeight-PanelHorz->Height; sbHorz->Width = PanelHorz->Width-sbHorz->Left-2; sbVert->Height = PanelVert->Height-sbVert->Top-2; iMainImage->SetPosition(); FullViewForm->SetSize(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Active) { DownState = true; if (Shift.Contains(ssCtrl) && Button==mbLeft) { MouseState = 1; iMainImage->Cursor = crHandPoint; ptFirst = Point(X, iMainImage->Bitmap->Height-1-Y); } else { if (MainMenuForm->iMainImageMouseDown(this, Button, Shift, X, Y)) { PaletteForm->iMainImageMouseDown(Sender, Button, Shift, X, Y); if (Button==mbLeft) { FullViewForm->iMainImageMouseDown(Sender, X, Y); } } } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { POINT pt; COLORREF color; if (Active) { CursorPosition.x = X; CursorPosition.y = iMainImage->Bitmap->Height-1-Y; if (MouseState) { ptSecond = Point(X, iMainImage->Bitmap->Height-1-Y); pt.x = ptSecond.x-ptFirst.x; pt.y = ptSecond.y-ptFirst.y; iMainImage->SetPosition(iMainImage->PositionX-pt.x, iMainImage->PositionY-pt.y); ptFirst.x = ptSecond.x-pt.x; ptFirst.y = ptSecond.y-pt.y; } else { if (DownState==false) { if (bChoiceExchange == false) { WORD yarn = Plan->GetYarn(X, CursorPosition.y); if ((yarn & 0x8000) == 0) { if (Plan->Yarn->Choice[(yarn>>11)&3].Color[(yarn>>8)&7]) { if (((yarn>>3)&0x1F) < Plan->Yarn->Choice[(yarn>>11)&3].Data->Colors) { PaletteForm->DIB256Palette->CursorIndex = Plan->Yarn->Choice[(yarn>>11)&3].Color[(yarn>>8)&7][(yarn>>3) & 0x1F]->Index; } } } else { PaletteForm->DIB256Palette->CursorIndex = 1; } } } if (MainMenuForm->iMainImageMouseMove(this, Shift, X, Y)) { FullViewForm->iMainImageMouseMove(Sender, X, Y); PaletteForm->iMainImageMouseMove(Sender, Shift, X, Y); } } } else iMainImage->Cursor = crDefault; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Active) { if (MouseState) { ptSecond = Point(X, iMainImage->Bitmap->Height-1-Y); iMainImage->SetPosition(iMainImage->PositionX-(ptSecond.x-ptFirst.x), iMainImage->PositionY-(ptSecond.y-ptFirst.y)); MouseState = 0; } else { MainMenuForm->iMainImageMouseUp(this, Button, Shift, X, Y); FullViewForm->View(); DownState = false; } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImagePaint(TObject *Sender) { if (MainMenuForm->iMainImagePaint(this)) { PaletteForm->iMainImagePaint(); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImagePositionChange(TObject *Sender) { UpdateImage(); Ruler->StartX = iMainImage->PositionX; Ruler->StartY = iMainImage->PositionY; sbHorz->Position = iMainImage->PositionX; sbVert->Position = sbVert->Max-iMainImage->PositionY; FullViewForm->SetPositionX(iMainImage->PositionX); FullViewForm->SetPositionY(iMainImage->PositionY); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbUnitClick(TObject *Sender) { if (CurrentUnit==uCm) CurrentUnit = uInch; else if (CurrentUnit==uInch) CurrentUnit = uCm; UnitChange(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbHorzScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { iMainImageChange(); iMainImage->PositionX = sbHorz->Position; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbZoomInClick(TObject *Sender) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(2, 1); break; case 2: ZoomChange(1, 1); break; case 4: ZoomChange(1, 2); break; case 8: ZoomChange(1, 4); break; case 16: ZoomChange(1, 8); break; } break; case 2: ZoomChange(4, 1); break; case 4: ZoomChange(8, 1); break; case 8: ZoomChange(16, 1); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbZoomOutClick(TObject *Sender) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(1, 2); break; case 2: ZoomChange(1, 4); break; case 4: ZoomChange(1, 8); break; case 8: ZoomChange(1, 16); break; } break; case 2: ZoomChange(1, 1); break; case 4: ZoomChange(2, 1); break; case 8: ZoomChange(4, 1); break; case 16: ZoomChange(8, 1); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbRulerClick(TObject *Sender) { iMainImageChange(); FormResize(this); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbGridClick(TObject *Sender) { iMainImageChange(); iMainImage->Grid = sbGrid->Down; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbVertScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { iMainImageChange(); iMainImage->PositionY = sbVert->Max-sbVert->Position; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PopupMenu1Popup(TObject *Sender) { GetCursorPos(&ptScreen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ZoomClick(TObject *Sender) { if (Sender==Zoom1161) ZoomChange(1, 16, &ptScreen); else if (Sender==Zoom181) ZoomChange(1, 8, &ptScreen); else if (Sender==Zoom141) ZoomChange(1, 4, &ptScreen); else if (Sender==Zoom121) ZoomChange(1, 2, &ptScreen); else if (Sender==Zoom11) ZoomChange(1, 1, &ptScreen); else if (Sender==Zoom21) ZoomChange(2, 1, &ptScreen); else if (Sender==Zoom41) ZoomChange(4, 1, &ptScreen); else if (Sender==Zoom81) ZoomChange(8, 1, &ptScreen); else if (Sender==Zoom161) ZoomChange(16, 1, &ptScreen); } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetCaption() { AnsiString fn = ExtractFileName(FileName); Caption = (DirName.Length()>0 ? DirName+"\\"+ fn: fn); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::UnitChange() { Ruler->AUnit = CurrentUnit; if (CurrentUnit==uInch) sbUnit->Caption = "Unit : Inch"; else if (CurrentUnit==uCm) sbUnit->Caption = "Unit : Cm"; FullViewForm->UnitChange(); MainMenuForm->UnitChange(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ReviewStatusBar() { MainForm->StatusBar->Panels->Items[StatusBarSize]->Text = "Size : " + CanvasInfor.Name(CurrentUnit, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); MainForm->StatusBar->Panels->Items[StatusBarDPI]->Text = Format("DPI : %d", OPENARRAY(TVarRec, (CanvasInfor.DotsPerInch))); } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::LoadFromFile(AnsiString FileName, TTexpiaBitmap *pBitmap, TPalette *pPalette, TPCanvasInfor &ci) { TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; TPException ec = EC_NONE; if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pBitmap)) != EC_NONE) goto fail; if ((ec = Plan->LoadFromFile(hFile, tpfh)) != EC_NONE) goto fail; UserColorLibForm->ThisFileHasUserColor(pPalette); ci = tpfh.CanvasInfor; CloseHandle(hFile); return EC_NONE; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawOutLine(TCanvas *Canvas) { int w, h, x, A4Width, A4Height; AnsiString str, company = "", date, time; TRegIniFile *Reg = NULL; Reg = new TRegIniFile(""); if (Reg) { Reg->RootKey = HKEY_LOCAL_MACHINE; if (Reg->OpenKey("\\SOFTWARE\\MicroSoft\\Windows", false)) company = Reg->ReadString("CurrentVersion", "RegisteredOrganization", ""); delete Reg; } A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*160/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); A4Height = GetDeviceCaps(Printer()->Handle, VERTRES)*160/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); w = A4Width-1; h = A4Height-1; Canvas->Font->Size = 15; Canvas->Font->Color = clPurple; Canvas->MoveTo(0, 0); Canvas->LineTo(w, 0); Canvas->LineTo(w, 30); Canvas->LineTo(0, 30); Canvas->LineTo(0, 0); str = "PATTERN NAME : " + FileName; Canvas->TextOut(30, 5, str); str = Format("C.P.I : %5.2f W.P.I : %5.2f SPREAD : %d", OPENARRAY(TVarRec, (Plan->Dsim.cpi, Plan->Dsim.wpi, Plan->Dsim.spread))); x = (w - Canvas->TextWidth(str))/2; Canvas->TextOut(x, 5, str); date = DateToStr(Date()); time = TimeToStr(Time()); str = Format("%s %s", OPENARRAY(TVarRec, (date.c_str(), time.c_str()))); x = w - Canvas->TextWidth(str) - 20; Canvas->TextOut(x, 5, str); Canvas->Font->Size = 12; Canvas->Font->Color = clBlack; Canvas->MoveTo(0, 35); Canvas->LineTo(w, 35); Canvas->LineTo(w, h-22); Canvas->LineTo(0, h-22); Canvas->LineTo(0, 35); x = Canvas->TextWidth(company); Canvas->TextOut(w-x-80, h-19, company); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawYarn(TTexpiaBitmap *tp, TCanvas *Canvas, int i, int &xxx, int &yyy, int &Hi) { int colors, wid, chipw, chiph; int k, m, n, p, t, a, b, x, Ind; TPoint sp, chipsp, chipep; TSize sz; RECT Dst, Src, trect; AnsiString str, abcd; TColorData *cd; TYarnArray *ya; TTexpiaBitmap *YarnBit = NULL; TCanvas *cvs = NULL; YarnBit = new TTexpiaBitmap; if (!YarnBit) goto fail; wid = (tp->Width / 6) - 10; chipw = wid / 2; colors = Plan->Yarn->Choice[i].Data->Colors; if (!(YarnBit->Create(wid, (150 + 70*((colors-1)/2)), 16))) goto fail; if (!(cvs = YarnBit->CreateCanvas())) goto fail; if (xxx == 5) Hi = YarnBit->Height; else { if (Hi < YarnBit->Height) Hi = YarnBit->Height; } sp.x = 0; sp.y = 20 + (50 - Plan->Yarn->Choice[i].Data->Width)/2; sz.cy = 50; sz.cx = YarnBit->Width; Src = Rect(0, 0, YarnBit->Width, YarnBit->Height); Dst = Rect(xxx, yyy, xxx+YarnBit->Width, yyy+YarnBit->Height); switch (i) { case 0: abcd = "A: "; break; case 1: abcd = "B: "; break; case 2: abcd = "C: "; break; case 3: abcd = "D: "; break; } Canvas->CopyMode = cmSrcCopy; for (k = 1; k <= 8; k++) { Ind = i*8 + k; cvs->Brush->Color = clWhite; cvs->FillRect(Src); for (t = 0; t < Plan->Yarn->ArrayCount; t++) { for (m = 0; m < Plan->Yarn->Array[t].count; m++) { ya = &Plan->Yarn->Array[t]; if (k + (i * 8) == ya->code[m]) { cvs->Font->Size = 12; str = abcd + Ind; cvs->TextOut(10, 4, str); Plan->Yarn->Choice[i].Data->Draw(cvs, sp, sz, Plan->Yarn->Choice[i].Color[k-1]); cvs->Font->Size = 8; for (p = 0; p < colors; p++) { a = p / 2; b = p % 2; chipsp = Point(2+b*chipw, 70+a*70); chipep = Point((2+chipw-5)+b*chipw, 120+a*70); trect = Rect(2+b*chipw, 120+a*70, (2+chipw-5)+b*chipw, 140+a*70); cd = Plan->Yarn->Choice[i].Color[k-1][p]->GetColor(0); PrintColorChip15(YarnBit, Rect(chipsp.x, chipsp.y, chipep.x, chipep.y), cd->RGB.rgbRed, cd->RGB.rgbGreen, cd->RGB.rgbBlue); cvs->Brush->Color = clWhite; str = GetColorName(cd); x = ((chipw-5) - cvs->TextWidth(str)) / 2; cvs->TextRect(trect, trect.left+x, trect.top+4, str); } Canvas->CopyRect(Dst, cvs, Src); xxx = Dst.right + 10; yyy = Dst.top; if (xxx+YarnBit->Width > tp->Width-1) { xxx = 5; yyy = Dst.top + Hi + 10; Hi = YarnBit->Height; } Dst = Rect(xxx, yyy, xxx + YarnBit->Width, yyy + YarnBit->Height); goto next; } } } next: } YarnBit->DeleteCanvas(cvs); delete YarnBit; return; fail : if (YarnBit) delete YarnBit; if (cvs) YarnBit->DeleteCanvas(cvs); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::FindABCD(int i) { TYarnArray *ya; for (int m = 0; m < Plan->Yarn->ArrayCount; m++) { for (int n = 0; n < Plan->Yarn->Array[m].count; n++) { ya = &Plan->Yarn->Array[m]; if (i == ((ya->code[n] - 1) /8)) return true; } } return false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawColorChip(TTexpiaBitmap *tp, TCanvas *Canvas, int x, int &y) { int sum, cnt, i, j, k, l, m, n, chipcnt, sumcolor; int sy, ey, chipw, chiph, max_x, max_y, mx, my; double ytw, p, yp; int TYarn[6][32]; int TDot[6] = {0, 0, 0, 0, 0, 0}; double YarnDot[32]; double Index[256]; bool stop; AnsiString str; TColorData *cd; TYarnArray *ya; TTextureArrange *ta; ta = Plan->Texture; ya = Plan->Yarn->Array; for (i=0; i<32; i++) { for (j=0; j<6; j++) { TYarn[j][i] = 0; } YarnDot[i]=0; } for (i=0; iCount; i++) { //========== Number of dot in texture sy = 0; cnt = 0; for (j=0; jArray[i].number; j++) { ey = sy; sy = ta->Array[i].Data[j].DY; if (ta->Array[i].Data[j].Pass == PT_EXIST) cnt += (sy-ey); } TDot[i] = cnt; } for (i=0; iCount; i++) { //=============== Number of same yarn for (j = 0; jArray[0].Data[ta->Array[0].number-1].DY; for (i=1; iCount; i++) { if (ya[i].count) { if (max_x < ya[i].count) max_x = ya[i].count; if (max_y < ta->Array[i].Data[ta->Array[i].number-1].DY) max_y = ta->Array[i].Data[ta->Array[i].number-1].DY; } } mx = 0; stop = true; while(stop) { mx += max_x; for (i=0; iCount; i++) { if (ya[i].count) { if (mx % ya[i].count) { break; } else { if (i == (ta->Count-1)) stop = false; } } else { if (i == (ta->Count-1)) stop = false; } } } my = 0; stop = true; while(stop) { my += max_y; for (i=0; iCount; i++) { if (ya[i].count) { if (my % ta->Array[i].Data[ta->Array[i].number-1].DY) { break; } else { if (i == (ta->Count-1)) stop = false; } } else { if (i == (ta->Count-1)) stop = false; } } } for (i=0; iCount; i++) { //=============== Numer of dot per 1 Repeat if(ta->Array[i].Data[ta->Array[i].number-1].DY) TDot[i] = TDot[i]*(my/ta->Array[i].Data[ta->Array[i].number-1].DY); } for (i=0; i<4; i++) { //============= Numer of yarn per 1 Repeat if (Plan->Yarn->Choice[i].Data) { for (j=0; j<8; j++) { if (Plan->Yarn->Choice[i].Color[j]) { for (k=0; kCount; k++) { if (ya[k].count) TYarn[k][i*8 + j] = TYarn[k][i*8 + j]*(mx/ya[k].count); } } } } } sum = 0; for (i=0; i<4; i++) { if (Plan->Yarn->Choice[i].Data) { for (j=0; j<8; j++) { if (Plan->Yarn->Choice[i].Color[j]) { for (k=0; kCount; k++) YarnDot[i*8 + j] += TDot[k]*TYarn[k][i*8 + j]; sum += YarnDot[i*8 + j]; } } } } for (i=0; i<4; i++) { //================== Percentage per yarn if (Plan->Yarn->Choice[i].Data) { for (j=0; j<8; j++) { if (Plan->Yarn->Choice[i].Color[j]) { if (YarnDot[i*8 + j]) YarnDot[i*8 + j] = 100*(YarnDot[i*8 + j]/sum); } } } } for (i=0; i < 256; i++) Index[i] = 0; for (i=0; i < 4; i++) { TYarnData *yd = Plan->Yarn->Choice[i].Data; if (Plan->Yarn->Choice[i].Data) { for (j = 0; j < 8; j++) { if (Plan->Yarn->Choice[i].Color[j]) { //Is it really need? Maybe nextline replaces it if (YarnDot[i*8 + j]) { ytw = 0.0; if (yd->Unit.Method) { //===================== Indirect yarn if (yd->Infor.Detail.TYC > 1) { for (k=0; kInfor.Detail.TYC; k++) { ytw += 1.0 / yd->Infor.Infor[k].Detail.Count; } } else { ytw += 1.0 / yd->Infor.Detail.Count; } ytw = 1.0/ytw; } else { //======================= Direct yarn if (yd->Infor.Detail.TYC > 1) { for (k=0; kInfor.Detail.TYC; k++) { ytw += (double)yd->Infor.Infor[k].Detail.Count; } } else { ytw += (double)yd->Infor.Detail.Count; } } if (yd->Infor.Detail.TYC > 1) { //=============== Yarn Count>1 sumcolor = 0; for (k=0; kInfor.Detail.TYC; k++) { if (yd->Unit.Method) { yp = YarnDot[i*8 + j]*(ytw / yd->Infor.Infor[k].Detail.Count); } else { yp = YarnDot[i*8 + j]*(yd->Infor.Infor[k].Detail.Count / ytw); } if (yd->Infor.Infor[k].Detail.Type) { // if (yd->Infor.Detail.Type) { if (yd->Infor.Infor[k].Methods) { n=0; for (m=0; mInfor.Infor[k].Methods; m++) { //Is it really need? ===>n=100; n += yd->Infor.Infor[k].Method[m].Number; } for (l=0; lInfor.Infor[k].Colors; l++) { p = 0.0; for (m=0; mInfor.Infor[k].Methods; m++) { if (l == yd->Infor.Infor[k].Method[m].Code) { p += (double)yd->Infor.Infor[k].Method[m].Number / n; } } Index[Plan->Yarn->Choice[i].Color[j][sumcolor+l]->Index] += yp*p; } sumcolor += yd->Infor.Infor[k].Colors; } else { p = 1.0/yd->Infor.Infor[k].Colors; for (l=0; lInfor.Infor[k].Colors; l++) { Index[Plan->Yarn->Choice[i].Color[j][sumcolor+l]->Index] += yp*p; } sumcolor += yd->Infor.Infor[k].Colors; } } else { // Index[Plan->Yarn->Choice[i].Color[j][sumcolor+k]->Index] += yp; Index[Plan->Yarn->Choice[i].Color[j][sumcolor]->Index] += yp; sumcolor++; } } } else { if (yd->Unit.Method) { yp = YarnDot[i*8 + j]*(ytw / yd->Infor.Detail.Count); } else { yp = YarnDot[i*8 + j]*(yd->Infor.Detail.Count / ytw); } if (yd->Infor.Detail.Type) { //=========== 1->Melange, 2->Rainbow if (yd->Infor.Methods) { n=0; for (m=0; mInfor.Methods; m++) { // Is it really need? n=100 n += yd->Infor.Method[m].Number; } for (l=0; lInfor.Colors; l++) { p = 0.0; for (m=0; mInfor.Methods; m++) { if (l == yd->Infor.Method[m].Code) { p += (double)yd->Infor.Method[m].Number/n; } } Index[Plan->Yarn->Choice[i].Color[j][l]->Index] += yp*p; } } else { p = 1.0/yd->Infor.Colors; for (l=0; lInfor.Colors; l++) { Index[Plan->Yarn->Choice[i].Color[j][l]->Index] += yp*p; } } } else { //========================= 0->Normal Index[Plan->Yarn->Choice[i].Color[j][0]->Index] += YarnDot[i*8 + j]; } } } } } } } chipw = (tp->Width - 10)/10; chiph = 50; chipcnt = 0; x = 5; Canvas->Font->Size = 10; Canvas->Font->Color = clBlack; Canvas->Pen->Color = clBlack; for (i=0; i < 4; i++) { if (Plan->Yarn->Choice[i].Data) { for (j = 0; j < 8; j++) { if (Plan->Yarn->Choice[i].Color[j]) { cnt = Plan->Yarn->Choice[i].Data->Colors; for (k = 0; k < cnt; k++) { if (Index[Plan->Yarn->Choice[i].Color[j][k]->Index]) { if (chipcnt == 10) { chipcnt = 0; x = 5; y += chiph + 70; } cd = Plan->Yarn->Choice[i].Color[j][k]->GetColor(0); PrintColorChip15(tp, Rect(x+chipcnt*chipw + 5, y, x+(chipcnt+1)*chipw, y+chiph), cd->RGB.rgbRed, cd->RGB.rgbGreen, cd->RGB.rgbBlue); str = GetColorName(cd); Canvas->Brush->Color = clWhite; Canvas->TextOut(x+chipcnt*chipw + 20, y+chiph+5, str); str = Format("%5.2f", OPENARRAY(TVarRec, (Index[Plan->Yarn->Choice[i].Color[j][k]->Index]))); str = str + " %"; Canvas->TextOut(x+chipcnt*chipw + 20, y+chiph+20+5, str); chipcnt ++; Index[Plan->Yarn->Choice[i].Color[j][k]->Index] = 0; } } } } } } y += chiph + 70; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::UseYarnTextOut(TTexpiaBitmap *tp, TCanvas *Canvas, int sy) { int i, j, cnt, sx; //Textout yarn according to texture AnsiString str; cnt = 50; Canvas->Font->Size = 12; for (i=0; iTexture->Count; i++) { sx = 5; str = " [ T "+IntToStr(i+1)+" ] "; Canvas->Font->Color = clBlack; Canvas->TextOut(sx, sy, str); for (j=0; jYarn->Array[i].count; j++) { if ((j+1)%5 == 0) Canvas->Font->Color = clRed; else Canvas->Font->Color = clBlack; if (Plan->Yarn->Array[i].code[j]) { Canvas->TextOut(55+(j%cnt)*25, sy+(j/cnt)*30, Plan->Yarn->Array[i].code[j]); } else { Canvas->TextOut(55+(j%cnt)*25, sy+(j/cnt)*30, "__"); } } sy += ((j-1)/cnt + 1)*30; } Canvas->Font->Color = clBlack; return; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawTexture(TCanvas *Canvas, int i, int sx, int sy, int max, int dot) { int x, y, ex, ey, s, e, j, k; AnsiString str; TPointData *Pd = Plan->Texture->Array; str = Format("[T %d]", OPENARRAY(TVarRec,(i+1))); Canvas->Font->Size = 15; Canvas->Font->Color = clBlue; Canvas->TextOut(sx+20, sy, str); sy = sy + 30; //for Textout ex = sx + PTMAP_COL*dot; ey = sy + PTMAP_ROW*dot; Canvas->Pen->Color = clBlack; Canvas->Rectangle(sx, sy, ex, ey); Canvas->Font->Size = 12; Canvas->Font->Color = clBlack; for (j=0; jMoveTo(ex+2, sy+j*dot); Canvas->LineTo(ex+8, sy+j*dot); Canvas->MoveTo(sx+1, sy+j*dot); Canvas->LineTo(ex-1, sy+j*dot); if (j) Canvas->TextOut(ex+10, sy+j*dot-12, IntToStr((PTMAP_ROW-j)/10)); } else if (j%5 == 0) { Canvas->MoveTo(ex+2, sy+j*dot); Canvas->LineTo(ex+6, sy+j*dot); s = sx+1; while (s < ex-1) { e = s+10; if(e > ex-1) e = ex -1; Canvas->MoveTo(s, sy+j*dot); Canvas->LineTo(e, sy+j*dot); s += 15; } } else { Canvas->MoveTo(ex+2, sy+j*dot); Canvas->LineTo(ex+4, sy+j*dot); } } for (j=0; jMoveTo(sx+j*dot, ey+2); Canvas->LineTo(sx+j*dot, ey+8); Canvas->MoveTo(sx+j*dot, sy+1); Canvas->LineTo(sx+j*dot, ey-1); if (j) Canvas->TextOut(sx+j*dot-8, ey+8, IntToStr((PTMAP_COL-j)/10)); } else if (j%5 == 0) { Canvas->MoveTo(sx+j*dot, ey+2); Canvas->LineTo(sx+j*dot, ey+6); s = sy+1; while (s < ey-1) { e = s+10; if(e > ey-1) e = ey -1; Canvas->MoveTo(sx+j*dot, s); Canvas->LineTo(sx+j*dot, e); s += 15; } } else { Canvas->MoveTo(sx+j*dot, ey+2); Canvas->LineTo(sx+j*dot, ey+4); } } Canvas->Pen->Color = clRed; Canvas->Brush->Color = clBlue; x = Pd[i].sx; y = 0; for (j=0; jDsim.machine == DNB) { Canvas->MoveTo(ex-x*dot+dot/2, ey-y*dot); Canvas->LineTo(ex-x*dot+dot/2, ey-Pd[i].Data[j].DY*dot); Canvas->LineTo(ex-Pd[i].Data[j].DX*dot+dot/2, ey-Pd[i].Data[j].DY*dot); } else { Canvas->MoveTo(ex-x*dot+dot/2, ey-y*dot); Canvas->LineTo(ex-Pd[i].Data[j].DX*dot+dot/2, ey-Pd[i].Data[j].DY*dot); } } else { for(k=y+1; k<=Pd[i].Data[j].DY; k++) { Canvas->FillRect(Rect(ex-x*dot+1, ey-k*dot+1, ex-(x-1)*dot-1, ey-(k-1)*dot-1)); } } x = Pd[i].Data[j].DX; y = Pd[i].Data[j].DY; } Canvas->Pen->Color = clBlack; Canvas->Brush->Color = clWhite; } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::InitForm(TPCanvasInfor &ci) { PALETTEENTRY peEntry[256]; RGBQUAD rgb[256]; if (Palette == NULL || WorkArea == NULL || Plan == NULL) return EC_MEMORY_LACK; Top = 0; Left = 0; if (Palette->LoadFromFile((DirectoryColor+"\\Textile.fcr").c_str())==false) { GetSystemPaletteEntries(Canvas->Handle, 0, 256, peEntry); Palette->SetNormal(0, 0, 0, 0); Palette->SetNormal(1, 255, 255, 255); Palette->SetNormal(2, 0, 0, 0); for (int i=3; i<255; i++) { Palette->SetNormal(i, peEntry[i].peRed, peEntry[i].peGreen, peEntry[i].peBlue); } Palette->SetNormal(255, 255, 255, 255); } if (!ResizePattern(ci)) return EC_MEMORY_LACK; COLORREF c = PaletteForm->DIB256Palette->GetBGCOLORREF(iMainImage->Bitmap->BitsPerPixel); iMainImage->Bitmap->FillRect(Rect(0, 0, CanvasInfor.Width, CanvasInfor.Height), c); iMainImage->Repaint(); FileName = Format("Noname%d.pil", OPENARRAY(TVarRec, (Number+1))); iMainImage->Bitmap->FillRect(Rect(0, 0, CanvasInfor.Width, CanvasInfor.Height), PaletteForm->DIB256Palette->GetBGCOLORREF(iMainImage->Bitmap->BitsPerPixel)); ClientWidth = MainForm->ClientWidth-267; ClientHeight = MainForm->ClientHeight-MainForm->StatusBar->Height -GetSystemMetrics(SM_CYSMCAPTION)-GetSystemMetrics(SM_CYMENU)+3; SetCaption(); iMainImage->SetPosition(0, 0); MainForm->UpdateMenuItems(NULL); return EC_NONE; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::InitFormFile(AnsiString dn, AnsiString fn) { int pw, ph, sw, sh, x, y; RGBQUAD rgb[256]; TTexpiaBitmap *tb = NULL; TPCanvasInfor ci; Byte c[256], *bp; TPException ec = EC_NONE; if (Palette==NULL || WorkArea==NULL || Plan==NULL) return EC_MEMORY_LACK; Top = 0; Left = 0; sw = MainForm->ClientWidth-267; sh = MainForm->ClientHeight-MainForm->StatusBar->Height -GetSystemMetrics(SM_CYSMCAPTION)-GetSystemMetrics(SM_CYMENU)+3; if ((tb = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } tb->CoordinateSystem = csBottomLeft; if ((ec = LoadFromFile(fn, tb, Palette, ci))!=EC_NONE) goto fail; if (!ResizePattern(ci)) { ec = EC_MEMORY_LACK; goto fail; } if (Plan->Piling) { iMainImage->Bitmap->Copy(tb, SRCCOPY); } else { Plan->Simulation(CanvasInfor.Width, CanvasInfor.Height, CanvasInfor.DotsPerInch, RGBToColor15(Palette->ColorData[1]->RGB)); Plan->DrawOutput(iMainImage->Bitmap, RGBToColor15(Palette->ColorData[1]->RGB)); } pw = iMainImage->Bitmap->Width+PanelVert->Width; ph = iMainImage->Bitmap->Height+PanelHorz->Height; if (sbRuler->Down) { pw += Ruler->Thick; ph += Ruler->Thick; } if (pwSetPosition(0, 0); MainForm->UpdateMenuItems(NULL); return EC_NONE; fail: if (tb) delete tb; return ec; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::ResizePattern(TPCanvasInfor &pi) { if (pi.SizeType != cstFree) { pi.Width = pi.GetWidth(); //Á¤Àǰ¡ µÇ¾îÀÖÁö ¾ÊÀ½ pi.Height = pi.GetHeight(); //undefined symbol } CanvasInfor = pi; CanvasInfor.SetExtFileOption(); Ruler->DPI = CanvasInfor.DotsPerInch; if (!iMainImage->Create(CanvasInfor.Width, CanvasInfor.Height)) return false; // Plan->Init(CanvasInfor.Width, CanvasInfor.Height); ReviewStatusBar(); return true; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::EnlargeCanvas(int w, int h) { COLORREF bc = PaletteForm->DIB256Palette->GetBGCOLORREF(iMainImage->Bitmap->BitsPerPixel); WorkArea->ResetRegion(iMainImage); CanvasInfor.SetSize(cstFree, w, h); iMainImage->Bitmap->Resize(w, h, bc); /* Plan->Init(CanvasInfor.Width, CanvasInfor.Height); if (Plan->Finish) { Plan->calc_weave(iMainImage->Bitmap); if (sbFrontBack->Down) { Plan->DrawBack(iMainImage->Bitmap, Palette->ColorData[1]->RGB); } else { Plan->DrawFront(iMainImage->Bitmap, Palette->ColorData[1]->RGB); } } */ ::RepaintImage(); ReviewStatusBar(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ZoomChange(int zi, int zo, POINT *ptScreen) { POINT ptClient; AnsiString sbZoom; if (zi!=iMainImage->ZoomIn || zo!=iMainImage->ZoomOut) { iMainImageChange(); if (ptScreen) { ptClient = iMainImage->ScreenToClient(*ptScreen); ptClient.y = iMainImage->Height - ptClient.y; //LeftTop ÁÂÇ¥°è¿¡ ¸Â°Ô º¯È¯ iMainImage->SetZoom(zi, zo, &ptClient); } else { iMainImage->SetZoom(zi, zo); } Ruler->Zoom = (double)zi/zo; FullViewForm->SetZoom(); } switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: sbZoom = "Zoom : 1"; break; case 2: sbZoom = "Zoom : 1/2"; break; case 4: sbZoom = "Zoom : 1/4"; break; case 8: sbZoom = "Zoom : 1/8"; break; case 16: sbZoom = "Zoom : 1/16"; break; } break; case 2: sbZoom = "Zoom : 2"; break; case 4: sbZoom = "Zoom : 4"; break; case 8: sbZoom = "Zoom : 8"; break; case 16: sbZoom = "Zoom : 16"; break; } MainForm->StatusBar->Panels->Items[StatusBarZoom]->Text = sbZoom; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ZoomChangeIn(POINT ptScreen) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(2, 1, &ptScreen); break; case 2: ZoomChange(1, 1, &ptScreen); break; case 4: ZoomChange(1, 2, &ptScreen); break; case 8: ZoomChange(1, 4, &ptScreen); break; case 16: ZoomChange(1, 8, &ptScreen); break; } break; case 2: ZoomChange(4, 1, &ptScreen); break; case 4: ZoomChange(8, 1, &ptScreen); break; case 8: ZoomChange(16, 1, &ptScreen); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ZoomChangeOut(POINT ptScreen) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(1, 2, &ptScreen); break; case 2: ZoomChange(1, 4, &ptScreen); break; case 4: ZoomChange(1, 8, &ptScreen); break; case 8: ZoomChange(1, 16, &ptScreen); break; } break; case 2: ZoomChange(1, 1, &ptScreen); break; case 4: ZoomChange(2, 1, &ptScreen); break; case 8: ZoomChange(4, 1, &ptScreen); break; case 16: ZoomChange(8, 1, &ptScreen); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageChange() { FullViewForm->iMainImageChange(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::UpdateImage() { TPoint Size; Size.x = Panel->Width*iMainImage->ZoomOut/iMainImage->ZoomIn; Size.y = Panel->Height*iMainImage->ZoomOut/iMainImage->ZoomIn; if (iMainImage->Bitmap->WidthMax = 0; else sbHorz->Max = iMainImage->Bitmap->Width-Size.x; sbHorz->SmallChange = Size.x/4; if (iMainImage->Bitmap->HeightMax = 0; else sbVert->Max = iMainImage->Bitmap->Height-Size.y; sbVert->SmallChange = Size.y/4; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Timer200ms() { if (CurrentUnit==uInch) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%f : %f", OPENARRAY(TVarRec, ((double)CursorPosition.x/CanvasInfor.DotsPerInch, (double)CursorPosition.y/CanvasInfor.DotsPerInch))); } else if (CurrentUnit==uCm) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%f : %f", OPENARRAY(TVarRec, (2.54*CursorPosition.x/CanvasInfor.DotsPerInch, 2.54*CursorPosition.y/CanvasInfor.DotsPerInch))); } if (sbRuler->Down) Ruler->PositionBar(CursorPosition); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Timer1000ms() { if (iMainImage) iMainImage->OutlineBitmapRgn(); } //--------------------------------------------------------------------- TPException __fastcall TMainImageForm::SaveToFile(AnsiString dn, AnsiString fn, TCompressMethod cm) { HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; int ec = EC_NONE, n; TEXPIAFILEHEADER tpfh; TRect src; RGBQUAD rgb[256]; TTexpiaBitmap *tag = NULL; if ((hFile = CreateFile(FullPathName(dn, fn).c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } tpfh.Version = TexVersion('P', 'T', 220); tpfh.CanvasInfor = CanvasInfor; tpfh.BitsPerPixel = iMainImage->Bitmap->BitsPerPixel; tpfh.Compress = cm; src.Left = 0; src.Top = 0; src.Right = iMainImage->Bitmap->Width; src.Bottom = iMainImage->Bitmap->Height; if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } MakeTexpiaTag(tag, iMainImage->Bitmap, src, 0); if (!SaveToTexpiaFile(hFile, Palette, tpfh, tag, iMainImage->Bitmap)) goto fail; delete tag; tag = NULL; if ((ec = Plan->SaveToFile(hFile, tpfh.Compress)) != EC_NONE) goto fail; CloseHandle(hFile); DirName = dn; FileName = fn; SetCaption(); return EC_NONE; fail: if (tag) delete tag; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //---------------------------------------------------------------------------- void __fastcall TMainImageForm::EditCopy() { RGBQUAD rgb[256]; BITMAPHANDLE bh, *pbh; int w, h, i, x, y; HDC dcSrc = NULL, dcDst = NULL, dcMask = NULL; HGLOBAL hMem = NULL; Byte *lpData = NULL; TClipboardInfo cbi; TColorData *cd; Byte *mp, *bp; COLORREF c; bool bClipboard = false; TPException ec = EC_NONE; TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (WorkArea->Mask) { memset(&bh, 0, sizeof(BITMAPHANDLE)); w = WorkArea->Range.right-WorkArea->Range.left; h = WorkArea->Range.bottom-WorkArea->Range.top; // if (L_CreateBitmap(&bh, TYPE_CONV, w, h, iMainImage->Bitmap->BitsPerPixel, ORDER_BGR, NULL, TOP_LEFT)<1) goto next1; if ((dcDst = L_CreateLeadDC(&bh))==NULL) goto next1; if ((dcSrc = iMainImage->Bitmap->CreateDC())==NULL) goto next1; BitBlt(dcDst, 0, 0, w, h, dcSrc, WorkArea->Range.left, WorkArea->Range.top, SRCCOPY); iMainImage->Bitmap->DeleteDC(dcSrc); dcSrc = NULL; if ((dcMask = WorkArea->Mask->CreateDC())==NULL) goto next1; BitBlt(dcDst, 0, 0, w, h, dcMask, 0, 0, SRCAND); WorkArea->Mask->DeleteDC(dcMask); dcMask = NULL; L_DeleteLeadDC(dcDst); dcDst = NULL; if (L_CopyToClipboard(MainForm->Handle, &bh)<1) goto next1; L_FreeBitmap(&bh); goto next2; next1: if (dcDst) { if (dcMask) WorkArea->Mask->DeleteDC(dcMask); if (dcSrc) iMainImage->Bitmap->DeleteDC(dcSrc); L_DeleteLeadDC(dcDst); } L_FreeBitmap(&bh); next2: // if (!OpenClipboard(MainForm->Handle)) { ec = EC_CLIPBOARD_NOT_OPEN; goto fail; } bClipboard = true; if (MainForm->ClipboardFormat) { cbi.Version = 0; cbi.Time = clock(); cbi.Width = w; cbi.Height = h; cbi.Mask = true; cbi.BitsPerPixel = 15; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+sizeof(COLORREF)+ 2*cbi.Width*cbi.Height+WorkArea->Mask->BytesPerLine*cbi.Height))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((lpData = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; goto fail; } memcpy(lpData, &cbi, sizeof(TClipboardInfo)); lpData += sizeof(TClipboardInfo); c = Palette->Color[1]; memcpy(lpData, &c, sizeof(COLORREF)); lpData += sizeof(COLORREF); if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->GetScanLine(WorkArea->Range.top+y)+2*WorkArea->Range.left; memcpy(lpData, bp, 2*cbi.Width); lpData += 2*cbi.Width; } iMainImage->Bitmap->StopScanLine(); if (!WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yMask->GetScanLine(y); for (x=0; xMask->BytesPerLine; x++) { *(lpData+x) = ~*(mp+x); } lpData += WorkArea->Mask->BytesPerLine; } WorkArea->Mask->StopScanLine(); GlobalUnlock(hMem); SetClipboardData(MainForm->ClipboardFormat, hMem); } CloseClipboard(); } else { if ((pbh = iMainImage->Bitmap->Handle)==NULL) { ec = EC_CLIPBOARD_NOT_OPEN; goto fail; } // L_CopyToClipboard(MainForm->Handle, &bh); // if (!OpenClipboard(MainForm->Handle)) { ec = EC_CLIPBOARD_NOT_OPEN; goto fail; } bClipboard = true; if (MainForm->ClipboardFormat) { cbi.Version = 0; cbi.Time = clock(); cbi.Width = iMainImage->Bitmap->Width; cbi.Height = iMainImage->Bitmap->Height; cbi.Mask = false; cbi.BitsPerPixel = 15; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+sizeof(COLORREF)+2*cbi.Width*cbi.Height))) { ec = EC_MEMORY_LACK; goto fail; } if ((lpData = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; goto fail; } memcpy(lpData, &cbi, sizeof(TClipboardInfo)); lpData += sizeof(TClipboardInfo); c = Palette->Color[1]; memcpy(lpData, &c, sizeof(COLORREF)); lpData += sizeof(COLORREF); if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->GetScanLine(y); memcpy(lpData, bp, 2*cbi.Width); lpData += 2*cbi.Width; } iMainImage->Bitmap->StopScanLine(); GlobalUnlock(hMem); GlobalFree(hMem); SetClipboardData(MainForm->ClipboardFormat, hMem); } CloseClipboard(); } Screen->Cursor = cursor; return; fail: if (bClipboard) { if (hMem) { if (lpData) { if (WorkArea->Mask) WorkArea->Mask->StopScanLine(); iMainImage->Bitmap->StopScanLine(); GlobalUnlock(hMem); } GlobalFree(hMem); } CloseClipboard(); } if (WorkArea->Mask) { if (dcDst) { if (dcMask) WorkArea->Mask->DeleteDC(dcMask); if (dcSrc) iMainImage->Bitmap->DeleteDC(dcSrc); L_DeleteLeadDC(dcDst); } L_FreeBitmap(&bh); } Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(ec); } //---------------------------------------------------------------------------- void __fastcall TMainImageForm::WorkAreaChange() { if (WorkArea->Mask) { MainForm->ECopyItem->Enabled = true; } else { MainForm->ECopyItem->Enabled = false; } } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::Simulation() { Plan->Simulation(CanvasInfor.Width, CanvasInfor.Height, CanvasInfor.DotsPerInch, RGBToColor15(Palette->ColorData[1]->RGB)); Plan->DrawOutput(iMainImage->Bitmap, RGBToColor15(Palette->ColorData[1]->RGB)); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::A4NoModePrint(TTexpiaBitmap *tp, int A4Width, int A4Height) { int Width, Height, btw, bth, x, y; TPoint sp; AnsiString str; TCanvas *Canvas = NULL; HDC hDC; if (!tp->Create(A4Width, A4Height, 16)) goto fail; tp->FillRect(Rect(0, 0, tp->Width, tp->Height), clWhite); Width = A4Width-(5+5)-1; Height = A4Height-(30+5+5+5+22)-1; if ((Canvas = tp->CreateCanvas()) == NULL) goto fail; Height = Height - 30; sp.x = 0; btw = Width; if (iMainImage->Bitmap->Width < Width) { btw = iMainImage->Bitmap->Width; } if (iMainImage->Bitmap->Height < Height) { sp.y = 0; bth = iMainImage->Bitmap->Height; } else { sp.y = iMainImage->Bitmap->Height - Height; bth = Height; } if (Plan->Dsim.machine == DNB) { if (Plan->Dsim.edge == 0) str = Format("Pattern [ A ] : %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.ec, Plan->Dsim.ew))); else str = "Pattern [ A ]"; } else if (Plan->Dsim.machine == TRICOT) { if (Plan->Dsim.edge == 0) str = Format("Pile move : %5.2f - %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.move, Plan->Dsim.ec, Plan->Dsim.ew))); else str = Format("Pile move : %5.2f", OPENARRAY(TVarRec, (Plan->Dsim.move))); } DrawOutLine(Canvas); Canvas->MoveTo(0, A4Height-22-30-1); Canvas->LineTo(A4Width, A4Height-22-30-1); hDC = iMainImage->Bitmap->CreateDC(); BitBlt(Canvas->Handle, 5, 40, btw, bth, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); Canvas->Font->Size = 15; Canvas->Font->Color = clBlack; Canvas->TextOut(30, A4Height-(25+22)-1, str); tp->DeleteCanvas(Canvas); return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::A4YesModePrint(TTexpiaBitmap *tp, int A4Width, int A4Height) { int Width, Height; int btw, bth, x, y, nx, tw, th, mbw, mbh, tcnt, gab = 0; TPoint sp; WORD *bp; Byte *mp; RGBQUAD rgb; AnsiString str, Bstr; TCanvas *Canvas = NULL; HDC hDC; if (!(tp->Create(A4Width, A4Height, 16))) goto fail; tp->FillRect(Rect(0, 0, tp->Width, tp->Height), clWhite); if ((Canvas = tp->CreateCanvas()) == NULL) goto fail; Width = A4Width-(5+5)-1; Height = A4Height-(30+5+5+5+22)-1; DrawOutLine(Canvas); Canvas->Font->Size = 15; Canvas->Font->Color = clBlack; if (Plan->Dsim.machine == DNB) { Height = Height/2 - 5 - 30; btw = Width; sp.x = 0; if (iMainImage->Bitmap->Width < btw) btw = iMainImage->Bitmap->Width; if (iMainImage->Bitmap->Height < Height) { sp.y = 0; bth = iMainImage->Bitmap->Height; } else { sp.y = iMainImage->Bitmap->Height - Height; bth = Height; } Canvas->MoveTo(0, 40+Height+5); Canvas->LineTo(A4Width, 40+Height+5); Canvas->MoveTo(0, 40+Height+5+30); Canvas->LineTo(A4Width, 40+Height+5+30); Canvas->MoveTo(0, A4Height-22-30-1); Canvas->LineTo(A4Width, A4Height-22-30-1); if (Plan->Dsim.edge == 0) { str = Format("Pattern [ A ] : %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.ec, Plan->Dsim.ew))); Bstr = Format("PATTERN [ B ] : %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.ec, Plan->Dsim.ew))); } else { str = "PATTERN [ A ]"; Bstr = "PATTERN [ B ]"; } hDC = iMainImage->Bitmap->CreateDC(); BitBlt(Canvas->Handle, 5, 40, btw, bth, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); iMainImage->Bitmap->StartScanLine(); for (y=0; yBitmap->Height-sp.y; y++) { bp = (WORD *)iMainImage->Bitmap->GetScanLine(y+sp.y); mp = (Byte *)tp->StartScanLineN(A4Height-22-30-5-Height-1+y); for (x=0; xStopScanLine(); } iMainImage->Bitmap->StopScanLine(); Canvas->TextOut(30, 30+15+Height+5, str); Canvas->TextOut(30, A4Height-(25+22)-1, Bstr); } else if (Plan->Dsim.machine == TRICOT) { Canvas->MoveTo(0, A4Height-22-30-1); Canvas->LineTo(A4Width, A4Height-22-30-1); tcnt = Plan->Texture->Count; mbw = Plan->ModeBitmap->Width; mbh = Plan->ModeBitmap->Height/tcnt; tw = (Width - 10)/tcnt; th = Height/4; if (mbh < th) th = mbh; else gab = mbh - th; if (mbw < tw) tw = mbw; hDC = Plan->ModeBitmap->CreateDC(); sp.y = 40; for (int i=0; iHandle, sp.x, sp.y, tw-10, th, hDC, 0, gab+i*mbh, SRCCOPY); str = " [ T" + IntToStr(i+1) + " ] "; // tp->Canvas->Brush->Color = clWhite; Canvas->TextOut(sp.x + 20, sp.y + 20, str); } Plan->ModeBitmap->DeleteDC(hDC); Canvas->MoveTo(0, 40 + th + 5); Canvas->LineTo(A4Width, 40 + th + 5); bth = Height - th - 10; btw = Width; sp.x = 0; if (iMainImage->Bitmap->Width < btw) btw = iMainImage->Bitmap->Width; if (iMainImage->Bitmap->Height < bth) { sp.y = 0; bth = iMainImage->Bitmap->Height; } else { sp.y = iMainImage->Bitmap->Height - bth; } if (Plan->Dsim.edge == 0) str = Format("Pile move : %5.2f %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.move, Plan->Dsim.ec, Plan->Dsim.ew))); else str = Format("Pile move : %5.2f", OPENARRAY(TVarRec, (Plan->Dsim.move))); hDC = iMainImage->Bitmap->CreateDC(); BitBlt(Canvas->Handle, 5, 40 + th + 10, btw, bth, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); Canvas->TextOut(30, A4Height - 22 - 26, str); } tp->DeleteCanvas(Canvas); return; fail: if (Canvas) tp->DeleteCanvas(Canvas); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::A4YesPrint(TTexpiaBitmap *tp, int A4Width, int A4Height) { int Width, Height; int YHei, THei, YTxtHei, btw, bth, ycnt, max, tth, tw, th, u_th, tcnt, gab=0; int dot, dotx, doty, sx, sy, lx, ly, i, colors; int k, t, m, y, x, nx; TPoint sp; WORD *bp; Byte *mp; RGBQUAD rgb; AnsiString str, Bstr; TYarnArray *ya; HDC hDC; TCanvas *Canvas; if (!(tp->Create(A4Width, A4Height, 16))) goto fail; tp->FillRect(Rect(0, 0, tp->Width, tp->Height), clWhite); if ((Canvas = tp->CreateCanvas()) == NULL) goto fail; Width = A4Width-(5+5)-1; Height = A4Height-(30+5+5+5+22)-1; btw = Width; bth = Height; DrawOutLine(Canvas); ycnt=0; YHei=0; max = 0; for (i=0; i<4; i++) { if (Plan->Yarn->Choice[i].Data) { colors = Plan->Yarn->Choice[i].Data->Colors; for (k = 1; k <= 8; k++) { for (t = 0; t < Plan->Yarn->ArrayCount; t++) { for (m = 0; m < Plan->Yarn->Array[t].count; m++) { ya = &Plan->Yarn->Array[t]; if (k + (i * 8) == ya->code[m]) { ycnt++; if (max < (150+70*((colors-1)/2))) max = 150+70*((colors-1)/2); if ((ycnt%6) == 0) { YHei += max; max = 0; } goto next; } } } next: } } } if (ycnt%6) YHei += max; YTxtHei = 0; for (i=0; iTexture->Count; i++) { YTxtHei += ((Plan->Yarn->Array[i].count-1)/50 + 1)*30; } if (Plan->Texture->Count<5) THei = Height/3 - 60; else THei = Height/4 - 50; sp.x = 0; bth = Height - (YHei + YTxtHei + THei) - (30+5)-(10+10+20); if (iMainImage->Bitmap->Height < bth) { bth = iMainImage->Bitmap->Height; sp.y = 0; } else { sp.y = iMainImage->Bitmap->Height - bth; } Canvas->Font->Size = 15; Canvas->Font->Color = clBlack; if (Plan->mode) { if (Plan->Dsim.machine == DNB) { btw = Width/2 - 5; if (iMainImage->Bitmap->Width < btw) btw = iMainImage->Bitmap->Width; hDC = iMainImage->Bitmap->CreateDC(); BitBlt(Canvas->Handle, 5, 40, btw, bth, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); Canvas->MoveTo(Width/2+5, 35); Canvas->LineTo(Width/2+5, 35+bth+5); iMainImage->Bitmap->StartScanLine(); for (y=0; yBitmap->Height-sp.y; y++) { bp = (WORD *)iMainImage->Bitmap->GetScanLine(y+sp.y); mp = (Byte *)tp->StartScanLineN(40+y)+3*(Width/2+10); for (x=0; xBitmap->StopScanLine(); if (Plan->Dsim.edge == 0) Bstr = Format("Pattern [ B ] : %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.ec, Plan->Dsim.ew))); else Bstr = "Pattern [ B ]"; Canvas->TextOut(Width/2 + 40, 40+5+bth+5, Bstr); } else if (Plan->Dsim.machine == TRICOT) { tw = Width/4 - 5; btw = Width - tw - 10; if (iMainImage->Bitmap->Width < btw) btw = iMainImage->Bitmap->Width; hDC = iMainImage->Bitmap->CreateDC(); BitBlt(Canvas->Handle, 5, 40, btw, bth, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); Canvas->MoveTo(btw+10, 35); Canvas->LineTo(btw+10, 35+bth+5); tcnt = Plan->Texture->Count; u_th = (Height - (YHei+YTxtHei+THei) - (30+5)-(10+10+20)+10)/tcnt - 10; tth = Plan->ModeBitmap->Height/tcnt; th = u_th; if (Plan->ModeBitmap->Width < tw) tw = Plan->ModeBitmap->Width; if (tth < th) th = tth; else gab = Plan->ModeBitmap->Height - th; hDC = Plan->ModeBitmap->CreateDC(); sp.x = Width - Width/4 + 10; for (i=0; iHandle, sp.x, sp.y, tw, th, hDC, 0, gab+i*tth, SRCCOPY); str = " [ T" + IntToStr(i+1) + " ] "; Canvas->TextOut(sp.x+20, sp.y+20, str); } Plan->ModeBitmap->DeleteDC(hDC); } } else { if (iMainImage->Bitmap->Width < btw) btw = iMainImage->Bitmap->Width; hDC = iMainImage->Bitmap->CreateDC(); BitBlt(Canvas->Handle, 5, 40, btw, bth, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); } Canvas->Pen->Color = clBlack; Canvas->MoveTo(0, 40+bth+5); Canvas->LineTo(A4Width, 40+bth+5); Canvas->MoveTo(0, 40+bth+5+30); Canvas->LineTo(A4Width, 40+bth+5+30); if (Plan->Dsim.machine == DNB) { if (Plan->Dsim.edge == 0) str = Format("Pattern [ A ] : %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.ec, Plan->Dsim.ew))); else str = "Pattern [ A ]"; } else if (Plan->Dsim.machine == TRICOT) { if (Plan->Dsim.edge == 0) str = Format("Pile move : %5.2f %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.move, Plan->Dsim.ec, Plan->Dsim.ew))); else str = Format("Pile move : %5.2f", OPENARRAY(TVarRec, (Plan->Dsim.move))); } Canvas->TextOut(30, 40+5+bth+5, str); x = 5; y = 40 + bth + 5 + 30 + 10; for (i=0; i<4; i++) { if (Plan->Yarn->Choice[i].Data) { if (FindABCD(i)) { DrawYarn(tp, Canvas, i, x, y, 0); } } } y = 40 + 5 + bth + 30 + 10 + YHei + 10; UseYarnTextOut(tp, Canvas, y); y += YTxtHei + 5; Canvas->Pen->Color = clBlack; Canvas->MoveTo(0, y); Canvas->LineTo(tp->Width, y); y += 15; max = Plan->Texture->Count; lx = Width/max; ly = (THei - 30); dotx = (lx - 25)/PTMAP_COL; doty = (ly - 50)/PTMAP_ROW; dot = dotx < doty ? dotx : doty; sx = 5 + (lx-(dot*PTMAP_COL+6))/2; sy = y; for (i=0; iDeleteCanvas(Canvas); return; fail : if (Canvas) tp->DeleteCanvas(Canvas); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::A4Image_YarnPrint(TTexpiaBitmap *tp, int A4Width, int A4Height) { int Width, Height, YHei, btw, bth, ycnt; int i, k, t, m, y, x, max, colors; TPoint sp; bool Mode; AnsiString str; TYarnArray *ya; HDC hDC; TCanvas *Canvas = NULL; if (!(tp->Create(A4Width, A4Height, 16))) goto fail; tp->FillRect(Rect(0, 0, tp->Width, tp->Height), clWhite); if ((Canvas = tp->CreateCanvas()) == NULL) goto fail; Width = A4Width-(5+5)-1; Height = A4Height-(30+5+5+5+22)-1; btw = Width; bth = Height; DrawOutLine(Canvas); ycnt=0; YHei=0; max = 0; for (i=0; i<4; i++) { if (Plan->Yarn->Choice[i].Data) { colors = Plan->Yarn->Choice[i].Data->Colors; for (k = 1; k <= 8; k++) { for (t = 0; t < Plan->Yarn->ArrayCount; t++) { for (m = 0; m < Plan->Yarn->Array[t].count; m++) { ya = &Plan->Yarn->Array[t]; if (k + (i * 8) == ya->code[m]) { ycnt++; if (max < (150+70*((colors-1)/2))) max = 150+70*((colors-1)/2); if ((ycnt%6) == 0) { YHei += max; max = 0; } goto next; } } } next: } } } if (ycnt%6) YHei += max; sp.x = 0; bth = Height - (YHei + 30 + 5 + 10 + 10); if (iMainImage->Bitmap->Width < btw) btw = iMainImage->Bitmap->Width; if (iMainImage->Bitmap->Height < bth) { bth = iMainImage->Bitmap->Height; sp.y = 0; } else { sp.y = iMainImage->Bitmap->Height - bth; } hDC = iMainImage->Bitmap->CreateDC(); BitBlt(Canvas->Handle, 5, 40, btw, bth, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); Canvas->Pen->Color = clBlack; Canvas->MoveTo(0, 40+bth+5); Canvas->LineTo(A4Width, 40+bth+5); Canvas->MoveTo(0, 40+bth+5+30); Canvas->LineTo(A4Width, 40+bth+5+30); if (Plan->Dsim.machine == DNB) { if (Plan->Dsim.edge == 0) str = Format("Pattern [ A ] : %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.ec, Plan->Dsim.ew))); else str = "Pattern [ A ]"; } else if (Plan->Dsim.machine == TRICOT) { if (Plan->Dsim.edge == 0) str = Format("Pile move : %5.2f %d X %d Repeat", OPENARRAY(TVarRec, (Plan->Dsim.move, Plan->Dsim.ec, Plan->Dsim.ew))); else str = Format("Pile move : %5.2f", OPENARRAY(TVarRec, (Plan->Dsim.move))); } Canvas->Font->Size = 15; Canvas->TextOut(30, 40+5+bth+5, str); x = 5; y = 40 + bth + 5 + 30 + 10; for (i=0; i<4; i++) { if (Plan->Yarn->Choice[i].Data) { if (FindABCD(i)) { DrawYarn(tp, Canvas, i, x, y, 0); } } } tp->DeleteCanvas(Canvas); return; fail : if (Canvas) tp->DeleteCanvas(Canvas); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::A4YarnPrint(TTexpiaBitmap *tp, int A4Width, int A4Height) { int i, x, y, sx, sy, Hei, Index; TPoint sp; TYarnData *yd; TYarnInfor *yi; AnsiString str, c, unit; TCanvas *Canvas = NULL; if (!(tp->Create(A4Width, A4Height, 16))) goto fail; tp->FillRect(Rect(0, 0, tp->Width, tp->Height), clWhite); if ((Canvas = tp->CreateCanvas()) == NULL) goto fail; y = 70; DrawOutLine(Canvas); str = "[ Yarn Information ]"; Canvas->Font->Size = 15; Canvas->Font->Color = clBlue; Canvas->TextOut(100, y, str); Canvas->Font->Size = 12; Canvas->Font->Color = clBlack; y += 30; for (i=0; i<4; i++) { if (Plan->Yarn->Choice[i].Data) { if (FindABCD(i)) { switch (i) { case 0: str = "[ A ] "; break; case 1: str = "[ B ] "; break; case 2: str = "[ C ] "; break; case 3: str = "[ D ] "; break; } yd = Plan->Yarn->Choice[i].Data; unit = yd->Unit.Name(); yi = &yd->Infor; if (yi->Detail.SZ) c = " Z "; else c = " S "; str = Format("%s %2d %s, %2d twist yarn, %s twist, %.2f TPI.", OPENARRAY(TVarRec, (str.c_str(), yi->Detail.Count, unit.c_str(), yi->Detail.TYC, c.c_str(), yi->Detail.TPI))); Canvas->TextOut(30, y, str); y += 20; } } } y += 30; x = 5; Hei = 0; for (i=0; i<4; i++) { if (Plan->Yarn->Choice[i].Data) { if (FindABCD(i)) { DrawYarn(tp, Canvas, i, x, y, Hei); } } } if (x != 5) y = y + Hei + 50; str = "[ Used Color Chip ]"; Canvas->Font->Size = 15; Canvas->Font->Color = clBlue; Canvas->TextOut(100, y, str); y += 50; DrawColorChip(tp, Canvas, x, y); y += 50; Canvas->Font->Size = 15; Canvas->Font->Color = clBlue; str = "[ Yarn Arrangement Order ]"; Canvas->TextOut(100, y, str); y += 50; UseYarnTextOut(tp, Canvas, y); tp->DeleteCanvas(Canvas); return; fail : if (Canvas) tp->DeleteCanvas(Canvas); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::A4TexturePrint(TTexpiaBitmap *tp, int A4Width, int A4Height) { int sx, sy, max, dot, x, y, i; TPoint lp, sp; TTextureArrange *ta; TCanvas *Canvas = NULL; if (!(tp->Create(A4Width, A4Height, 16))) goto fail; tp->FillRect(Rect(0, 0, tp->Width, tp->Height), clWhite); if ((Canvas = tp->CreateCanvas()) == NULL) goto fail; DrawOutLine(Canvas); ta = Plan->Texture; max = ta->Count>4 ? 3 : 2; lp.x = (tp->Width-1-max)/max; lp.y = (tp->Height-1-54-max)/max; x = (lp.x-40)/PTMAP_COL; y = (lp.y-65)/PTMAP_ROW; dot = xMoveTo((1+lp.x)*i, 34); Canvas->LineTo((1+lp.x)*i, tp->Height-22); Canvas->MoveTo(1, 33+(1+lp.y)*i); Canvas->LineTo(tp->Width-2, 33+(1+lp.y)*i); } for (i=0; iCount; i++) { sx = sp.x + (i%max)*lp.x; sy = sp.y + (i/max)*lp.y; DrawTexture(Canvas, i, sx, sy, max, dot); } tp->DeleteCanvas(Canvas); return; fail : if (Canvas) tp->DeleteCanvas(Canvas); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FreePrint(TTexpiaBitmap *tp) { int Width, Height; TPoint sp; HDC hDC; TCanvas *ca = NULL; if (WorkArea->Mask) { sp = Point(WorkArea->Range.left, WorkArea->Range.top); Width = WorkArea->Range.right - WorkArea->Range.left; Height = WorkArea->Range.bottom - WorkArea->Range.top; } else { sp = Point(0, 0); Width = iMainImage->Bitmap->Width; Height = iMainImage->Bitmap->Height; } if (!(tp->Create(Width, Height, 16))) goto fail; tp->FillRect(Rect(0, 0, tp->Width, tp->Height), clWhite); if ((ca = tp->CreateCanvas()) == NULL) goto fail; hDC = iMainImage->Bitmap->CreateDC(); BitBlt(ca->Handle, 0, 0, Width, Height, hDC, sp.x, sp.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(hDC); tp->DeleteCanvas(ca); return; fail : if (ca) tp->DeleteCanvas(ca); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ApplyEnvironment() { TIniFile *IniFile = new TIniFile(DirectoryItem+"\\Environment.ini"); if (IniFile) { WorkArea->undoMax = IniFile->ReadInteger("Window", "MaxUndo", 5); delete IniFile; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ChangeColor(int i) { int k, m, n, cnt, num = 0; TYarnChoice *yarnchoice; WORD *yc, bgc; if (PaletteForm->DIB256Palette->ChoiceIndex == 1) { bgc = RGBToColor15(Palette->ColorData[1]->RGB); Plan->ChangeBackGroundColor(iMainImage->Bitmap, bgc); iMainImage->Repaint(); FullViewForm->InitForm(iMainImage); if (FOnReDraw) FOnReDraw(); } else { if (Plan->Yarn->ChoiceCount > 0) { yarnchoice = Plan->Yarn->Choice; for (k = 0; k < Plan->Yarn->ChoiceCount; k++) { if (yarnchoice[k].Data) { num += 8*yarnchoice[k].Data->Colors; } } yc = (WORD *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num*sizeof(WORD)); num = 0; for (k = 0; k < Plan->Yarn->ChoiceCount; k++) { if (yarnchoice[k].Data) { cnt = yarnchoice[k].Data->Colors; for (m = 0; m < 8; m++) { if (yarnchoice[k].Color[m]) { for (n = 0; n < cnt; n++) { if (i == yarnchoice[k].Color[m][n]->Index) { yarnchoice[k].Color[m][n]->SetColor(Palette->ColorData[i], i); yarnchoice[k].Data->Color[n]->SetColor(Palette->ColorData[i]); yc[num] = (k<<11)|(m<<8)|(n<<3); num++; if (FOnYarnColorChange) FOnYarnColorChange(k, m, n, i); } } } } } } Plan->ChangeColor(iMainImage->Bitmap, yc, num); HeapFree(GetProcessHeap(), 0, yc); iMainImage->Repaint(); FullViewForm->InitForm(iMainImage); if (FOnReDraw) FOnReDraw(); } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::RearrangeColor() { int i, k, m, n, cnt, num = 0; WORD *yc, bgc; TYarnChoice *yarnchoice; if (PaletteForm->DIB256Palette->ChoiceIndex == 1) { bgc = RGBToColor15(Palette->ColorData[1]->RGB); Plan->ChangeBackGroundColor(iMainImage->Bitmap, bgc); if (FOnReDraw) FOnReDraw(); } else { if (Plan->Yarn->ChoiceCount > 0) { yarnchoice = Plan->Yarn->Choice; for (k = 0; k < Plan->Yarn->ChoiceCount; k++) { if (yarnchoice[k].Data) { num += 8*yarnchoice[k].Data->Colors; } } yc = (WORD *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num*sizeof(WORD)); num = 0; for (k = 0; k < Plan->Yarn->ChoiceCount; k++) { if (yarnchoice[k].Data) { cnt = yarnchoice[k].Data->Colors; for (m = 0; m < 8; m++) { if (yarnchoice[k].Color[m]) { for (n = 0; n < cnt; n++) { i = yarnchoice[k].Color[m][n]->Index; yarnchoice[k].Color[m][n]->SetColor(Palette->ColorData[i], i); yarnchoice[k].Data->Color[n]->SetColor(Palette->ColorData[i]); yc[num] = (k<<11)|(m<<8)|(n<<3); num++; if (FOnYarnColorChange) FOnYarnColorChange(k, m, n, i); } } } } } Plan->ChangeColor(iMainImage->Bitmap, yc, num); HeapFree(GetProcessHeap(), 0, yc); if (FOnReDraw) FOnReDraw(); } } } //--------------------------------------------------------------------------- // External Function //--------------------------------------------------------------------------- void __fastcall RepaintImage() { if (MainImageForm) { MainImageForm->iMainImage->Repaint(); FullViewForm->InitForm(MainImageForm->iMainImage); } } //--------------------------------------------------------------------- void __fastcall RepaintColor() { RGBQUAD rgb[256]; if (MainImageForm) { MainImageForm->iMainImage->Repaint(); FullViewForm->InitForm(MainImageForm->iMainImage); PaletteForm->InitForm(MainImageForm->Palette); ColorLibraryForm->View(); } } //--------------------------------------------------------------------------- void __fastcall RepaintYarnColor() { if (MainImageForm) { MainImageForm->RearrangeColor(); MainImageForm->iMainImage->Repaint(); FullViewForm->InitForm(MainImageForm->iMainImage); PaletteForm->InitForm(MainImageForm->Palette); ColorLibraryForm->View(); } } //--------------------------------------------------------------------------- int __fastcall TMainImageForm::yarn_gcm(int *cnt) { /* int i, min; if (Ptxtr.pcount<=1) return 1; else { min = 100; for (i=0; i=1; i--) { if (Ptxtr.pcount==2) { if (cnt[0]%i==0 && cnt[1]%i==0) return i; } else if (Ptxtr.pcount==3) { if (cnt[0]%i==0 && cnt[1]%i==0 && cnt[2]%i==0) return i; } else if (Ptxtr.pcount==4) { if (cnt[0]%i==0 && cnt[1]%i==0 && cnt[2]%i==0 && cnt[3]%i==0) return i; } } return 1; } */ } //--------------------------------------------------------------------------- int __fastcall TMainImageForm::yarn_lcm() { int l=0; /* int cnt[MAX_TEXTURE], i, gcm, l; for (i=0; iYarn->Array; ta = Plan->Texture; lcm = yarn_lcm(); memset(ycode[0], 0, (MAX_TEXTURE+1)*33*sizeof(int)); //========================================= //Calculate dot number for (j=0; jCount; j++) { sy = 0; cnt = 0; for (i=0; iArray[j].number; i++) { ey = sy; sy = ta->Array[j].Data[i].DY; if (ta->Array[j].Data[i].Pass == PT_EXIST) { cnt += (sy-ey); } } ycode[j][0] = cnt; } for (i=0; iCount; i++) { for (j=0; jCount; i++) { for (j=1; j<33; j++) { ycode[i][j] = ycode[i][j]*(lcm/ya[i].count)*ycode[i][0]; } } for (j=1; j<33; j++) { for (i=0; iCount; i++) ycode[MAX_TEXTURE][j] += ycode[i][j]; ycode[MAX_TEXTURE][0] += ycode[MAX_TEXTURE][j]; } for (i=0; i<32; i++) color[i] = 0.0; for (i=0; i<4; i++) { TYarnData *yd = Plan->Yarn->Choice[i].Data; for (j = 0; j < 8; j++) { y = i*8 + j + 1; if (ycode[MAX_TEXTURE][y]) { ytw = 0.0; if (yd->Unit.System) { if (yd->Infor.Detail.TYC > 1) { for (k = 0; k < yd->Infor.Detail.TYC; k++) { ytw += 1.0 / yd->Infor.Infor[k].Detail.Count; } } else { ytw += 1.0 / yd->Infor.Detail.Count; } ytw = 1.0/ytw; } else { if (yd->Infor.Detail.TYC > 1) { for (k = 0; k < yd->Infor.Detail.TYC; k++) { ytw += (double)yd->Infor.Infor[k].Detail.Count; } } else { ytw += (double)yd->Infor.Detail.Count; } } } tp = (double)ycode[MAX_TEXTURE][y]/ycode[MAX_TEXTURE][0]; if (yd->Infor.Detail.TYC > 1) { for (k = 0; k < yd->Infor.Detail.TYC; k++) { if (yd->Unit.System) { yp = tp * (ytw / yd->Infor.Infor[k].Detail.Count); } else { yp = tp * (yd->Infor.Infor[k].Detail.Count / ytw); } if (yd->Infor.Detail.Type) { if (yd->Infor.Infor[k].Methods) { for (l = 0; l < yd->Infor.Infor[k].Colors; l++) { n = 0; for (m = 0; m < yd->Infor.Infor[k].Methods; m++) { n += yd->Infor.Infor[k].Method[m].Number; } p = 0.0; for (m = 0; m< yd->Infor.Infor[k].Methods; m++) { if (l == yd->Infor.Infor[k].Method[m].Code) { p += (double)yd->Infor.Infor[k].Method[m].Number / n; } } color[(Plan->Yarn->Choice[i].Color[j][k<<3 + l]->Index - 4)/7] += yp*p; } } else { p = 1.0 / yd->Infor.Infor[k].Colors; for (l = 0; l < yd->Infor.Infor[k].Colors; l++) { color[(Plan->Yarn->Choice[i].Color[j][k<<3 + l]->Index - 2) / 7] += yp*p; } } } else { color[(Plan->Yarn->Choice[i].Color[j][k<<3]->Index - 2) / 7] += yp; } } } else { if (yd->Unit.System) { yp = tp*(ytw/ yd->Infor.Detail.Count); } else { yp = tp*(yd->Infor.Detail.Count/ytw); } if (yd->Infor.Detail.Type & 3) { if (yd->Infor.Methods) { for (l = 0; l < yd->Infor.Colors; l++) { n = 0; for (m = 0; m < yd->Infor.Methods; m++) { n += yd->Infor.Method[m].Number; } p = 0.0; for (m = 0; m < yd->Infor.Methods; m++) { if (l == yd->Infor.Method[m].Code) { p += (double) yd->Infor.Method[m].Number / n; } } color[(Plan->Yarn->Choice[i].Color[j][l]->Index - 2) / 7] += yp*p; } } else { p = 1.0 / yd->Infor.Colors; for (l = 0; l < yd->Infor.Colors; l++) { color[(Plan->Yarn->Choice[i].Color[j][l]->Index - 2) / 7] += yp*p; } } } } } } */ } //------------------------------------------------------------------------------ void __fastcall TMainImageForm::RatioZoom(int r) //by qe { GetCursorPos(&ptScreen); switch (r){ case 116 : ZoomChange(1, 16, &ptScreen); break; case 18 : ZoomChange(1, 8, &ptScreen); break; case 14 : ZoomChange(1, 4, &ptScreen); break; case 12 : ZoomChange(1, 2, &ptScreen); break; case 1 : ZoomChange(1, 1, &ptScreen); break; case 2 : ZoomChange(2, 1, &ptScreen); break; case 4 : ZoomChange(4, 1, &ptScreen); break; case 8 : ZoomChange(8, 1, &ptScreen); break; case 16 : ZoomChange(16, 1, &ptScreen); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormKeyPress(TObject *Sender, char &Key) { int Ratio; if(Key == 65 || Key == 97){ //'a' or 'A' switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: Ratio = 2 ; break; case 2: Ratio = 1; break; case 4: Ratio = 12; break; case 8: Ratio = 14; break; case 16: Ratio = 18; break; } break; case 2: Ratio = 4; break; case 4: Ratio = 8; break; case 8: Ratio = 16; break; } RatioZoom(Ratio); } if(Key == 83 || Key == 115){ // 's' or 'S' switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: Ratio = 12 ; break; case 2: Ratio = 14; break; case 4: Ratio = 18; break; case 8: Ratio = 116; break; } break; case 2: Ratio = 1; break; case 4: Ratio = 2; break; case 8: Ratio = 4; break; case 16 : Ratio = 8; break; } RatioZoom(Ratio); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawLineLocate(POINT First, POINT Second, int NOL) { NumberOfLine=NOL; static RECT oldlines=Rect(0,0,0,0); if(NOL==0) { LineList->Clear(); iMainImage->OnPaintLocate = NULL; InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); } else { iMainImage->OnPaintLocate = PaintLineLocate;/////////////////by jeegeo LineListData *line=new LineListData; static int cnt = 0; if(cnt==0)LineList->Clear(); cnt++; line->First=First; line->Second=Second; LineList->Add(line); if(NOL==cnt) { cnt=0; line=(LineListData *)LineList->Items[0]; int minx,miny,maxx,maxy; minx = iMainImage->BitmapToCanvasX(min( line->First.x, line->Second.x )); maxx = iMainImage->BitmapToCanvasX(max( line->First.x, line->Second.x )); miny = iMainImage->BitmapToCanvasY(min( line->First.y, line->Second.y )); maxy = iMainImage->BitmapToCanvasY(max( line->First.y, line->Second.y )); for(int i=1;iItems[i]; minx = min(minx,iMainImage->BitmapToCanvasX(min(line->First.x,line->Second.x))); maxx = max(maxx,iMainImage->BitmapToCanvasX(max(line->First.x,line->Second.x))); miny = min(miny,iMainImage->BitmapToCanvasY(min(line->First.y,line->Second.y))); maxy = max(maxy,iMainImage->BitmapToCanvasY(max(line->First.y,line->Second.y))); } RECT rc = {minx-1,miny-1,maxx+1,maxy+1}; #if defined(TEXTILE) #if defined(CARPET) InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); InvalidateRect(iMainImage->Parent->Handle,&rc,false); #else #endif #else InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); InvalidateRect(iMainImage->Parent->Handle,&rc,false); #endif oldlines=rc; } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintLineLocate(TObject *Sender, HDC formDC) { // HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; int NOL=NumberOfLine; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); // formDC = iMainImage->Canvas->Handle; POINT pt; POINT First; POINT Second; LineListData *line; for(int i=0;iItems[i]; First=line->First; Second=line->Second; pt.x = iMainImage->BitmapToCanvasX(First.x); pt.y = iMainImage->BitmapToCanvasY(First.y); MoveToEx(formDC, pt.x, pt.y, NULL); pt.x = iMainImage->BitmapToCanvasX(Second.x); pt.y = iMainImage->BitmapToCanvasY(Second.y); LineTo(formDC, pt.x, pt.y); } SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintFreeLineLocate(TObject *Sender, HDC formDC) { // HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; // int NOL=NumberOfLine; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); // formDC = iMainImage->Canvas->Handle; POINT pt; POINT First; POINT Second; LineListData *line; if(LineList->Count>0){ line=(LineListData *)LineList->Items[0]; Second=line->Second; pt.x = iMainImage->BitmapToCanvasX(Second.x); pt.y = iMainImage->BitmapToCanvasY(Second.y); MoveToEx(formDC, pt.x, pt.y, NULL); } for(int i=1;iCount;i++){ line=(LineListData *)LineList->Items[i]; First=line->First; Second=line->Second; pt.x = iMainImage->BitmapToCanvasX(First.x); pt.y = iMainImage->BitmapToCanvasY(First.y); MoveToEx(formDC, pt.x, pt.y, NULL); pt.x = iMainImage->BitmapToCanvasX(Second.x); pt.y = iMainImage->BitmapToCanvasY(Second.y); LineTo(formDC, pt.x, pt.y); } SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawFreeLineLocate(POINT Second, int resetCount) { static RECT oldlines=Rect(0,0,0,0); static POINT First = Second; if(resetCount==0) { First=Second; LineList->Clear(); iMainImage->OnPaintLocate = NULL; InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); } else { iMainImage->OnPaintLocate = PaintFreeLineLocate;/////////////////by jeegeo LineListData *line; if(resetCount==-1||resetCount==-2){ line=new LineListData; line->First=First; line->Second=Second; LineList->Add(line); First=Second; } else { while(LineList->Count>resetCount){ line = (LineListData *)LineList->Last(); LineList->Remove(line); } First= ((LineListData *)LineList->Last())->Second; } line=(LineListData *)LineList->Items[0]; int minx,miny,maxx,maxy; minx = iMainImage->BitmapToCanvasX(min( line->First.x, line->Second.x )); maxx = iMainImage->BitmapToCanvasX(max( line->First.x, line->Second.x )); miny = iMainImage->BitmapToCanvasY(min( line->First.y, line->Second.y )); maxy = iMainImage->BitmapToCanvasY(max( line->First.y, line->Second.y )); for(int i=1;iCount;i++){ line=(LineListData *)LineList->Items[i]; minx = min(minx,iMainImage->BitmapToCanvasX(min(line->First.x,line->Second.x))); maxx = max(maxx,iMainImage->BitmapToCanvasX(max(line->First.x,line->Second.x))); miny = min(miny,iMainImage->BitmapToCanvasY(min(line->First.y,line->Second.y))); maxy = max(maxy,iMainImage->BitmapToCanvasY(max(line->First.y,line->Second.y))); } RECT rc = {minx-1,miny-1,maxx+1,maxy+1}; if(resetCount!=-2){ #if defined(TEXTILE) #if defined(CARPET) InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); InvalidateRect(iMainImage->Parent->Handle,&rc,false); #else #endif #else InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); InvalidateRect(iMainImage->Parent->Handle,&rc,false); #endif } oldlines=rc; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawRectangleLocate(RECT rc,int NOR) { static RECT oldrc=Rect(0,0,0,0); if(NOR==0) { iMainImage->OnPaintLocate = NULL; InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); } else { iMainImage->OnPaintLocate = PaintRectangleLocate;/////////////////by jeegeo FloatingRect.left = iMainImage->BitmapToCanvasX(min(rc.left,rc.right)); FloatingRect.right = iMainImage->BitmapToCanvasX(max(rc.left,rc.right)); FloatingRect.top = iMainImage->BitmapToCanvasY(min(rc.top,rc.bottom)); FloatingRect.bottom = iMainImage->BitmapToCanvasY(max(rc.top,rc.bottom)); #if defined(TEXTILE) #if defined(CARPET) InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); InvalidateRect(iMainImage->Parent->Handle,&FloatingRect,false); #else #endif #else InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); InvalidateRect(iMainImage->Parent->Handle,&FloatingRect,false); #endif oldrc=FloatingRect; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintRectangleLocate(TObject *Sender, HDC formDC) { RECT rc = FloatingRect; // HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); // formDC = iMainImage->Canvas->Handle; Rectangle(formDC, min(rc.left, rc.right)+1, min(rc.top, rc.bottom)+1, max(rc.left, rc.right), max(rc.top, rc.bottom)); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawEllipseLocate(RECT rc,int NOE) { static RECT oldrc=Rect(0,0,0,0); if(NOE==0) { iMainImage->OnPaintLocate = NULL; InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); } else { iMainImage->OnPaintLocate = PaintEllipseLocate;/////////////////by jeegeo FloatingRect.left = iMainImage->BitmapToCanvasX(min(rc.left,rc.right)); FloatingRect.right = iMainImage->BitmapToCanvasX(max(rc.left,rc.right)); FloatingRect.top = iMainImage->BitmapToCanvasY(min(rc.top,rc.bottom)); FloatingRect.bottom = iMainImage->BitmapToCanvasY(max(rc.top,rc.bottom)); #if defined(TEXTILE) #if defined(CARPET) InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); InvalidateRect(iMainImage->Parent->Handle,&FloatingRect,false); #else #endif #else InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); InvalidateRect(iMainImage->Parent->Handle,&FloatingRect,false); #endif oldrc=FloatingRect; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintEllipseLocate(TObject *Sender, HDC formDC) { RECT rc = FloatingRect; // HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); // formDC = iMainImage->Canvas->Handle; Ellipse(formDC, min(rc.left, rc.right)+1, min(rc.top, rc.bottom)+1, max(rc.left, rc.right), max(rc.top, rc.bottom)); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawArcLocate(POINT center2, double LRadius2, double SRadius2, double angleS2, double angleE2, bool isFan2, bool isClosed2, int NOA) { //////isFanÀÌ trueÀ̸é fanÀ̰í falseÀ̸é tubeÀÌ´Ù center=center2; //////tube¿¡¼­´Â SRadius°¡ Æ©ºê ¾çÂÊ ³¡ÀÇ ¼±ºÐÀÇ ±æÀÌÀÌ´Ù LRadius=LRadius2; //////angleS´Â ½ÃÀæ°¢µµÀ̰í SRadius=SRadius2; //////angleE´Â ³¡°¢µµÀÌ´Ù angleS=angleS2; angleE=angleE2; isFan=isFan2; isClosed=isClosed2; RECT rc = Rect(center.x-LRadius-SRadius,center.y-LRadius-SRadius, center.x+LRadius+SRadius,center.y+LRadius+SRadius); static RECT oldrc=Rect(0,0,0,0); if(NOA==0) { iMainImage->OnPaintLocate = NULL; InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); } else { iMainImage->OnPaintLocate = PaintArcLocate;/////////////////by jeegeo FloatingRect.left = iMainImage->BitmapToCanvasX(min(rc.left,rc.right)); FloatingRect.right = iMainImage->BitmapToCanvasX(max(rc.left,rc.right)); FloatingRect.top = iMainImage->BitmapToCanvasY(min(rc.top,rc.bottom)); FloatingRect.bottom = iMainImage->BitmapToCanvasY(max(rc.top,rc.bottom)); #if defined(TEXTILE) #if defined(CARPET) InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); InvalidateRect(iMainImage->Parent->Handle,&FloatingRect,false); #else #endif #else InvalidateRect(iMainImage->Parent->Handle,&oldrc,false); InvalidateRect(iMainImage->Parent->Handle,&FloatingRect,false); #endif oldrc=FloatingRect; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintArcLocate(TObject *Sender, HDC formDC) /////by jeegeo { RECT rc,rr; POINT p,ps,pe; // HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); // formDC = iMainImage->Canvas->Handle; if(isFan){ rc = Rect(center.x - LRadius,center.y - LRadius, center.x + LRadius,center.y + LRadius); rr.left = iMainImage->BitmapToCanvasX(rc.left); rr.top = iMainImage->BitmapToCanvasY(rc.top); rr.right = iMainImage->BitmapToCanvasX(rc.right); rr.bottom = iMainImage->BitmapToCanvasY(rc.bottom); p = Point(center.x+cos(angleS)*LRadius,center.y-sin(angleS)*LRadius); ps.x = iMainImage->BitmapToCanvasX(p.x); ps.y = iMainImage->BitmapToCanvasY(p.y); p = Point(center.x+cos(angleE)*LRadius,center.y-sin(angleE)*LRadius); pe.x = iMainImage->BitmapToCanvasX(p.x); pe.y = iMainImage->BitmapToCanvasY(p.y); Arc(formDC,rr.left,rr.top,rr.right,rr.bottom,ps.x,ps.y,pe.x,pe.y); rc = Rect(center.x - SRadius,center.y - SRadius, center.x + SRadius,center.y + SRadius); rr.left = iMainImage->BitmapToCanvasX(rc.left); rr.top = iMainImage->BitmapToCanvasY(rc.top); rr.right = iMainImage->BitmapToCanvasX(rc.right); rr.bottom = iMainImage->BitmapToCanvasY(rc.bottom); p = Point(center.x+cos(angleS)*SRadius,center.y-sin(angleS)*SRadius); ps.x = iMainImage->BitmapToCanvasX(p.x); ps.y = iMainImage->BitmapToCanvasY(p.y); p = Point(center.x+cos(angleE)*SRadius,center.y-sin(angleE)*SRadius); pe.x = iMainImage->BitmapToCanvasX(p.x); pe.y = iMainImage->BitmapToCanvasY(p.y); Arc(formDC,rr.left,rr.top,rr.right,rr.bottom,ps.x,ps.y,pe.x,pe.y); if(isClosed) { /////////Arc¸¦ ´Ý´Â ¼±ºÐÀ» ±×¸°´Ù p = Point(center.x+cos(angleS)*LRadius,center.y-sin(angleS)*LRadius); p.x = iMainImage->BitmapToCanvasX(p.x); p.y = iMainImage->BitmapToCanvasY(p.y); MoveToEx(formDC,p.x,p.y,NULL); p = Point(center.x+cos(angleS)*SRadius,center.y-sin(angleS)*SRadius); p.x = iMainImage->BitmapToCanvasX(p.x); p.y = iMainImage->BitmapToCanvasY(p.y); LineTo(formDC,p.x,p.y); p = Point(center.x+cos(angleE)*LRadius,center.y-sin(angleE)*LRadius); p.x = iMainImage->BitmapToCanvasX(p.x); p.y = iMainImage->BitmapToCanvasY(p.y); MoveToEx(formDC,p.x,p.y,NULL); p = Point(center.x+cos(angleE)*SRadius,center.y-sin(angleE)*SRadius); p.x = iMainImage->BitmapToCanvasX(p.x); p.y = iMainImage->BitmapToCanvasY(p.y); LineTo(formDC,p.x,p.y); } } else { rc = Rect(center.x - LRadius,center.y - LRadius, center.x + LRadius,center.y + LRadius); rr.left = iMainImage->BitmapToCanvasX(rc.left); rr.top = iMainImage->BitmapToCanvasY(rc.top); rr.right = iMainImage->BitmapToCanvasX(rc.right); rr.bottom = iMainImage->BitmapToCanvasY(rc.bottom); p = Point(center.x+cos(angleS)*LRadius,center.y-sin(angleS)*LRadius); ps.x = iMainImage->BitmapToCanvasX(p.x); ps.y = iMainImage->BitmapToCanvasY(p.y); p = Point(center.x+cos(angleE)*LRadius,center.y-sin(angleE)*LRadius); pe.x = iMainImage->BitmapToCanvasX(p.x); pe.y = iMainImage->BitmapToCanvasY(p.y); Arc(formDC,rr.left,rr.top,rr.right,rr.bottom,ps.x,ps.y,pe.x,pe.y); double midAngle=(angleS+angleE)/2.0; float ratio=(float)iMainImage->ZoomIn/(float)iMainImage->ZoomOut; POINT plus = Point(-SRadius*cos(midAngle)*ratio,SRadius*sin(midAngle)*ratio); rc = Rect(center.x - LRadius,center.y - LRadius, center.x + LRadius,center.y + LRadius); rr.left = iMainImage->BitmapToCanvasX(rc.left); rr.top = iMainImage->BitmapToCanvasY(rc.top); rr.right = iMainImage->BitmapToCanvasX(rc.right); rr.bottom = iMainImage->BitmapToCanvasY(rc.bottom); p = Point(center.x+cos(angleS)*LRadius,center.y-sin(angleS)*LRadius); ps.x = iMainImage->BitmapToCanvasX(p.x); ps.y = iMainImage->BitmapToCanvasY(p.y); p = Point(center.x+cos(angleE)*LRadius,center.y-sin(angleE)*LRadius); pe.x = iMainImage->BitmapToCanvasX(p.x); pe.y = iMainImage->BitmapToCanvasY(p.y); Arc(formDC,rr.left+plus.x,rr.top+plus.y,rr.right+plus.x,rr.bottom+plus.y, ps.x+plus.x,ps.y+plus.y,pe.x+plus.x,pe.y+plus.y); if(isClosed) { /////////Arc¸¦ ´Ý´Â ¼±ºÐÀ» ±×¸°´Ù p = Point(center.x+cos(angleS)*LRadius,center.y-sin(angleS)*LRadius); p.x = iMainImage->BitmapToCanvasX(p.x); p.y = iMainImage->BitmapToCanvasY(p.y); MoveToEx(formDC,p.x,p.y,NULL); LineTo(formDC,p.x+plus.x,p.y+plus.y); p = Point(center.x+cos(angleE)*LRadius,center.y-sin(angleE)*LRadius); p.x = iMainImage->BitmapToCanvasX(p.x); p.y = iMainImage->BitmapToCanvasY(p.y); MoveToEx(formDC,p.x,p.y,NULL); LineTo(formDC,p.x+plus.x,p.y+plus.y); } } SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintCrossLine(TObject *Sender, HDC formDC) { HPEN hOldPen; HBRUSH hOldBrush; int nDrawMode; POINT cp=iMainImage->GetCrossPos(); RGBQUAD rgb; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); #ifdef WEAVE MoveToEx(formDC, cp.x, iMainImage->Parent->Top-30, NULL); LineTo(formDC, cp.x, iMainImage->Parent->Top + iMainImage->Parent->Height); MoveToEx(formDC, iMainImage->Parent->Left-30, cp.y, NULL); LineTo(formDC, iMainImage->Parent->Left + iMainImage->Parent->Width, cp.y); #else MoveToEx(formDC, cp.x, iMainImage->Parent->Top, NULL); LineTo(formDC, cp.x, iMainImage->Parent->Top + iMainImage->Parent->Height); MoveToEx(formDC, iMainImage->Parent->Left, cp.y, NULL); LineTo(formDC, iMainImage->Parent->Left + iMainImage->Parent->Width, cp.y); #endif SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintDirectly(HDC dcDst, int px, int py, int vw, int vh){ if(!isPaintDirectlyClean){ if(!isFirst){ if(iMainImage->OnPaintCursor) iMainImage->OnPaintCursor(iMainImage,dcDst,Pen.x,Pen.y); if(iMainImage->OnPaintCrossLine) iMainImage->OnPaintCrossLine(iMainImage,dcDst); } if(iMainImage->OnPaintZoom) iMainImage->OnPaintZoom(iMainImage, dcDst); if(iMainImage->OnPaintLocate) iMainImage->OnPaintLocate(iMainImage, dcDst); } } //--------------------------------------------------------------------------- int __fastcall TMainImageForm::GetLineListCount(void){ return LineList->Count; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ResetDraw(bool repaint){ iMainImage->OnPaintLocate=NULL; LineList->Clear(); FloatingRect=Rect(0,0,0,0); NumberOfLine=0; center=Point(0,0); SRadius=0;LRadius=0;angleS=0;angleE=0; isClosed=false;isFan=true; if(repaint)iMainImage->Repaint(); } //---------------------------------------------------------------------------