//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Yarn.h" #include "TPUtils.hpp" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // hotfix of undefined of min/max #define min(X,Y) (XY?X:Y) //--------------------------------------------------------------- const int mapW = 100; const int mapH = 100; //--------------------------------------------------------------------------- __fastcall TInfor::TInfor() { Type = 0; SZ = 0; Hair = 0; Count = 5; TPI = 5; Colors = 1; Methods = 0; Method = NULL; for( int i = 0; i < 8; i++ ){ yColor[i].rgbRed = 0; yColor[i].rgbGreen = 0; yColor[i].rgbBlue = 0; yColor[i].rgbReserved = 0; } } //--------------------------------------------------------------------------- __fastcall TInfor::~TInfor() { if (Method) { delete[] Method; Method = NULL; Methods = 0; } } //--------------------------------------------------------------------------- void __fastcall TInfor::Copy(TInfor *yi) { int i; if (Method) { delete[] Method; Method = NULL; Methods = 0; } YarnUnit = yi->YarnUnit; Type = yi->Type; SZ = yi->SZ; Hair = yi->Hair; Count = yi->Count; FTPI = yi->FTPI; FTPM = yi->FTPM; Colors = yi->Colors; for ( i = 0; i < 8; i++ ){ yColor[i] = yi->yColor[i]; } if (yi->Method) { Methods = yi->Methods; if (Methods > 0) { if ((Method = new TYarnMethod[Methods]) == NULL) { #ifdef TPDEBUG SHOWDEBUG; #endif } for (i = 0; i < Methods; i++) { Method[i].Code = i; Method[i].Number = yi->Method[i].Number; } } } } //--------------------------------------------------------------------------- void __fastcall TInfor::SetTPI(int value) { FTPI = value; FTPM = -FTPI * 100 / 2.54; } //--------------------------------------------------------------------------- void __fastcall TInfor::SetTPM(int value) { FTPM = value; FTPI = -FTPM * 2.54 / 100; } //--------------------------------------------------------------------------- int __fastcall TInfor::GetTPI() { return abs(FTPI); } //--------------------------------------------------------------------------- int __fastcall TInfor::GetTPM() { return abs(FTPM); } //--------------------------------------------------------------------------- bool __fastcall TInfor::IsTPIMethod() { return FTPM < 0; } //--------------------------------------------------------------------------- // YarnData //--------------------------------------------------------------------------- __fastcall TYarnData::TYarnData() { Map = NULL; FancyMap = NULL; yInfor = NULL; Colors = 0; FancyThick = 0; FancyOneRepeat = 0; } //--------------------------------------------------------------------------- __fastcall TYarnData::~TYarnData() { int i; if (yInfor) { for (i = 0; i < TYC; i++){ if (yInfor[i].Method){ delete[] yInfor[i].Method; yInfor[i].Method = NULL; yInfor[i].Methods = 0; } } delete[] yInfor; yInfor = NULL; } if (Map) { delete[] Map; Map = NULL; } if (FancyMap) { delete[] FancyMap; FancyMap = NULL; } } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- TPException __fastcall TInfor::SaveToFile(HANDLE fh) { DWORD dwWrite; int i; TPException ec = EC_NONE; if (!WriteFile(fh, &YarnUnit, sizeof(TYarnUnit), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Type, sizeof(unsigned char), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &SZ, sizeof(unsigned char), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Hair, sizeof(unsigned char), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Count, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FTPI, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FTPM, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Colors, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &yColor, sizeof(RGBQUAD)*8, &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Methods, sizeof(int), &dwWrite, NULL)) goto fail; if (Methods>0) { if (!WriteFile(fh, Method, sizeof(TYarnMethod)*Methods, &dwWrite, NULL)) goto fail; } return EC_NONE; fail: if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- bool __fastcall TInfor::LoadFromFile(HANDLE fh, int verNo) { DWORD dwRead; if (!ReadFile(fh, &YarnUnit, sizeof(TYarnUnit), &dwRead, NULL)) return false; if (!ReadFile(fh, &Type, sizeof(unsigned char), &dwRead, NULL)) return false; if (!ReadFile(fh, &SZ, sizeof(unsigned char), &dwRead, NULL)) return false; if (!ReadFile(fh, &Hair, sizeof(unsigned char), &dwRead, NULL)) return false; if (!ReadFile(fh, &Count, sizeof(int), &dwRead, NULL)) return false; if (verNo < 410) { if (!ReadFile(fh, &FTPI, sizeof(int), &dwRead, NULL)) return false; SetTPI(FTPI); } else { if (!ReadFile(fh, &FTPI, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(fh, &FTPM, sizeof(int), &dwRead, NULL)) return false; } if (!ReadFile(fh, &Colors , sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(fh, &yColor, sizeof(RGBQUAD)*8, &dwRead, NULL)) return false; if (!ReadFile(fh, &Methods, sizeof(int), &dwRead, NULL)) return false; if (Methods>0) { if ((Method = new TYarnMethod[Methods]) == NULL) { #ifdef TPDEBUG SHOWDEBUG; #endif } if (!ReadFile(fh, Method, sizeof(TYarnMethod)*Methods, &dwRead, NULL)) return false; } return true; } //--------------------------------------------------------------------------- void __fastcall TYarnData::SetTPI(int value) { FTPI = value; FTPM = -FTPI * 100 / 2.54; } //--------------------------------------------------------------------------- void __fastcall TYarnData::SetTPM(int value) { FTPM = value; FTPI = -FTPM * 2.54 / 100; } //--------------------------------------------------------------------------- int __fastcall TYarnData::GetTPI() { return abs(FTPI); } //--------------------------------------------------------------------------- int __fastcall TYarnData::GetTPM() { return abs(FTPM); } //--------------------------------------------------------------------------- bool __fastcall TYarnData::IsTPIMethod() { return FTPM < 0; } //--------------------------------------------------------------------------- TPException __fastcall TYarnData::LoadFromFile(HANDLE fh) { DWORD dwRead; int s, len; char *ch = NULL; TPException ec = EC_NONE; double Ratio; TTexVersion v; int YarnVerNo; if (!ReadFile(fh, &v, sizeof(TTexVersion), &dwRead, NULL)) goto fail; YarnVerNo = v.Number; VerNo = v.Number; if (YarnVerNo > 411) {ec = EC_HIGHER_VERSION; goto fail;} if (!ReadFile(fh, &Unit, sizeof(TYarnUnit), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &DPI, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Length, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Width, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Thick, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Dyed, sizeof(bool), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &TYC, sizeof(unsigned char), &dwRead, NULL)) goto fail; if (YarnVerNo < 410) { if (!ReadFile(fh, &FTPI, sizeof(int), &dwRead, NULL)) goto fail; SetTPI(FTPI); } else { if (!ReadFile(fh, &FTPI, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &FTPM, sizeof(int), &dwRead, NULL)) goto fail; } if (!ReadFile(fh, &Count, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &SZ, sizeof(unsigned char), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Hair, sizeof(unsigned char), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Fancy, sizeof(unsigned char), &dwRead, NULL)) goto fail; Colors = 0; yInfor = new TInfor[TYC]; for (int i = 0; i < TYC; i++){ if (!yInfor[i].LoadFromFile(fh, YarnVerNo)) goto fail; Colors += yInfor[i].Colors; } if( !ReadFile(fh, &ExactThick, sizeof(double), &dwRead, NULL)) goto fail; if (ExactThick == 0) ExactThick = Thick; if (!ReadFile(fh, &ImageLength, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &ImageHeight, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &RealThick, sizeof(double), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &FancyThick, sizeof(double), &dwRead, NULL)) goto fail; if (YarnVerNo > 410){ if (!ReadFile(fh, &FancyOneRepeat, sizeof(double), &dwRead, NULL)) goto fail; //05.11.11.shin Ãß°¡ } else { FancyOneRepeat = 0; } if (!ReadFile(fh, &FPoint1, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &FPoint2, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Hden, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &Hlen, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &mapsize, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &fancymapsize, sizeof(int), &dwRead, NULL)) goto fail; if ((Map = new Byte[mapsize]) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!ReadFile(fh, Map, mapsize, &dwRead, NULL)) goto fail; if (Fancy == 1) { if ((FancyMap = new Byte[fancymapsize]) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!ReadFile(fh, FancyMap, fancymapsize, &dwRead, NULL)) goto fail; } return EC_NONE; fail: if (Map) { delete[] Map; Map = NULL; } if (FancyMap) { delete[] Map; Map = NULL; } if (ch) HeapFree(GetProcessHeap(), 0, ch); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TYarnData::LoadFromFile(AnsiString fn) { HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; TTexVersion v; Byte bc, *map = NULL, *sp, *dp; char *yp, cnum[4]; short count, colors, number, tot; int i, k, l, m, size, n, cp = 2; double r, Ratio; TTexColor tc; TPException ec = EC_NONE; if (Map) { delete[] Map; Map = NULL; } if (FancyMap) { delete[] FancyMap; FancyMap = NULL; } if (yInfor) { for (i = 0; i < TYC; i++){ if (yInfor[i].Method){ delete[] yInfor[i].Method; yInfor[i].Method = NULL; yInfor[i].Methods = 0; } } delete[] yInfor; yInfor = NULL; } FileName = ExtractFileName(fn); if ((hFile = CreateFile(fn.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = LoadFromFile(hFile)) != EC_NONE) goto fail; CloseHandle(hFile); return EC_NONE; fail: if (map) delete[] map; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TYarnData::SaveToFile(HANDLE fh) { DWORD dwWrite; TPException ec = EC_NONE; TTexVersion v = { 'W', 'Y', 411 }; // weave / yarn 400->410 TPM Ãß°¡, 410->411 FancyOneRepeat Ãß°¡ if (!WriteFile(fh, &v, sizeof(TTexVersion), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Unit, sizeof(TYarnUnit), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &DPI, sizeof(short), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Length, sizeof(short), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Width, sizeof(short), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Thick, sizeof(short), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Dyed, sizeof(bool), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &TYC, sizeof(unsigned char), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FTPI, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FTPM, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Count, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &SZ, sizeof(unsigned char), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Hair, sizeof(unsigned char), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Fancy, sizeof(unsigned char), &dwWrite, NULL)) goto fail; for (int i = 0; i < TYC; i++) if ((ec = yInfor[i].SaveToFile(fh)) != EC_NONE) goto fail; if (Dyed) { ExactThick = Thick; RealThick = (25.4 / DPI) * Thick; } if (!WriteFile(fh, &ExactThick, sizeof(double), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &ImageLength, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &ImageHeight, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &RealThick, sizeof(double), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FancyThick, sizeof(double), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FancyOneRepeat, sizeof(double), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FPoint1, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &FPoint2, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Hden, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &Hlen, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &mapsize, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, &fancymapsize, sizeof(int), &dwWrite, NULL)) goto fail; if (!WriteFile(fh, Map, mapsize, &dwWrite, NULL)) goto fail; if (Fancy == 1) { if(!WriteFile(fh, FancyMap, fancymapsize, &dwWrite, NULL)) goto fail; } return EC_NONE; fail: if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TYarnData::SaveToFile(AnsiString fn) { HANDLE hFile = INVALID_HANDLE_VALUE; //TTexVersion v = { 'P', 'T', 110 }; TPException ec = EC_NONE; if ((hFile = CreateFile(fn.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = SaveToFile(hFile)) != EC_NONE) goto fail; CloseHandle(hFile); return EC_NONE; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- void __fastcall TYarnData::Draw(TCanvas *Canvas, TPoint StartPoint, TSize ViewSize) { Byte *sp, *wp, x, y, bvalue; WORD *dp, value; int r, g, b; int minimum=0; for (int y = 0; y < mapH; y++){ if (Dyed) sp = (Byte *)Map + y* ImageLength* 3; else sp = (Byte *)Map + y * mapW * 3; minimum = min(ImageLength, mapW);//Shin 2006.01.06 for ( int x = 0; x < ViewSize.cx; x++, sp += 3){ if (x>=minimum){//Shin 2006.01.06 Canvas->Pixels[StartPoint.x+x][StartPoint.y+y] = clWhite; } else { if (*sp & 0x800000) { Canvas->Pixels[StartPoint.x+x][StartPoint.y+y] = clWhite; } else { b = *sp; g = *(sp + 1); r = *(sp + 2); Canvas->Pixels[StartPoint.x+x][StartPoint.y+y] = RGB(r, g, b); } } } } } //--------------------------------------------------------------------------- bool __fastcall TYarnData::GetPixelColor(int X, int Y, COLORREF &c) { Byte *wp, r, g, b; WORD *dp; COLORREF value; bool rtn; if (Dyed) { dp = (WORD *) Map+ (Width/2-Thick/2+Y)*Length + X; if (*dp & 0x8000) { rtn = false; } else { value = *dp; b = ((value & 0x1F) << 3) | ((value & 0x1F) >> 2); value >>= 5; g = ((value & 0x1F) << 3) | ((value & 0x1F) >> 2); value >>= 5; r = ((value & 0x1F) << 3) | ((value & 0x1F) >> 2); c = RGB(r, g, b); rtn = true; } } else { wp = (BYTE *)Map+ (Width/2-Thick/2+Y)*Length + X; if (*wp) { if (TYC == 1 && Colors > 1){ c = TColor(RGBToTColor(yInfor[0].yColor[*wp>>3])); } else { c = TColor(RGBToTColor(yInfor[*wp>>3].yColor[0])); } rtn = true; } else { rtn = false; } } return rtn; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TYarnData::SetColor(RGBQUAD sRGB, int i, int j) { int yc, ycs; if (sRGB.rgbBlue == 0xFF && sRGB.rgbGreen == 0xFF && sRGB.rgbRed == 0xFF) { sRGB.rgbBlue = 0xFE; sRGB.rgbGreen = 0xFE; sRGB.rgbRed = 0xFE; } //YarnColor[i][j] = sRGB; yc = TYC; if (yc > 1) { ycs = yInfor[i].Colors; if (ycs > 1) yInfor[i].yColor[j] = sRGB; else yInfor[i].yColor[0] = sRGB; } else { yInfor[0].yColor[j] = sRGB; } } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Extern Functions //--------------------------------------------------------------------------- /* static struct { struct { char *name; double F; // Yarn diameter d = sqrt(N)/F } d[2]; struct { char *name; double F; // Yarn diameter d = 1/(F*sqrt(N)) } i[4]; } Yunit = { { { "Tex", 678.6 }, //ÀϹݻç 1 g/1000 m { "Denier", 2036.0 }, //°ß,Àΰß,È­¼¶»ç 1 g/9000 m }, { { "Cotton", 28.0 }, //¸é»ç 840 yd/1 lb { "Worsted", 22.8 }, //¼Ò¸ð»ç 560 yd/1 lb { "Y.S.W.", 15.4 }, //¹æ¸ð»ç 256 yd/1 lb { "Linen", 16.7 } //¸¶»ç 300 yd/1 lb } }; */ //--------------------------------------------------------------------------- /* double __fastcall Count2Dot(Word dpi, TYarnUnit yu, short count, double ratio) { if (yu.Method==YU_DIRECT) { return (dpi*sqrt((double)count))/(Yunit.d[yu.System].F*ratio); } else { return dpi/(sqrt((double)count)*Yunit.i[yu.System].F*ratio); } } */ //--------------------------------------------------------------------------- static struct { struct { char *name; double F; // Yarn diameter d = sqrt(N)/F } d[2]; struct { char *name; double F; // Yarn diameter d = 1/(F*sqrt(N)) } i[4]; } Yunit = { { { "Tex", 674.33 }, //ÀϹݻç 1 g/1000 m { "Denier", 2023 }, //°ß,Àΰß,È­¼¶»ç 1 g/9000 m }, { { "Cotton", 26.95 }, //¸é»ç 840 yd/1 lb ¿µ±¹½Ä { "Worsted", 21.3 }, //¼Ò¸ð»ç 560 yd/1 lb ¿µ±¹½Ä { "Y.S.W.", 13.5 }, //¹æ¸ð»ç 256 yd/1 lb ¿äÅ©¼Å½Ä { "Linen", 16 } //¸¶»ç 300 yd/1 lb ¿µ±¹½Ä } }; static struct { double U1[5]; double U2[5]; double U3[5]; double U4[5]; double U5[5]; // tex´Â Á¦¿Ü. denier·Î °è»êÈÄ º¯°æ } CountConv = { // 0 : Tex 1 tex = 9 denier { 1, 5315, 7972, 17439, 14882 }, // 1 : denier { 5315, 1, 1.503, 3.281, 2.800 }, // 2 : cotton { 7972, 0.665, 1, 2.188, 1.867 }, // 3 : Worsted { 17439, 0.304, 0.458, 1, 0.854 }, // 4 : Y.S.W { 14882, 0.357, 0.537, 1.171, 1 } // 5 : Linen }; //----------------------------------------------------------------------------- int __fastcall ConvertYarnCount(TYarnUnit DUnit, TYarnUnit SUnit, double count) { int dUnit, sUnit, convcount = 0; double F; bool tex = false; AnsiString str; dUnit = FindUnitIndex(DUnit); sUnit = FindUnitIndex(SUnit); if (sUnit == 0 && dUnit == 1) convcount = count * 9 + 0.5; else if (sUnit == 1 && dUnit == 0) convcount = count / 9 + 0.5; else { if (dUnit != 0) { if (sUnit == 1) F = CountConv.U1[dUnit-1]; else if (sUnit == 2) F = CountConv.U2[dUnit-1]; else if (sUnit == 3) F = CountConv.U3[dUnit-1]; else if (sUnit == 4) F = CountConv.U4[dUnit-1]; else if (sUnit == 5) F = CountConv.U5[dUnit-1]; else { F = CountConv.U1[dUnit-1]; tex = true; } } else { tex = true; if (sUnit == 1) F = CountConv.U1[0]; else if (sUnit == 2) F = CountConv.U2[0]; else if (sUnit == 3) F = CountConv.U3[0]; else if (sUnit == 4) F = CountConv.U4[0]; else if (sUnit == 5) F = CountConv.U5[0]; } if (sUnit == 1 || dUnit == 1 || tex) { convcount = F / count + 0.5; if (tex){ convcount = convcount / 9 + 0.5; } } else { convcount = F * count + 0.5; } } return convcount; } //--------------------------------------------------------------------------- int __fastcall FindUnitIndex(TYarnUnit Unit) { int index; if (Unit.Method == YU_DIRECT) { if(Unit.System == YU_TEX) index = 0; else index = 1; } else { if (Unit.System == YU_COTTON) index = 2; else if (Unit.System == YU_WORSTED) index = 3; else if (Unit.System == YU_Y_S_W) index = 4; else index = 5; } return index; } //--------------------------------------------------------------------------- TYarnUnit __fastcall IndexToUnit(int index) { TYarnUnit Unit; if (index == 0 || index == 1){ Unit.Method = YU_DIRECT; if (index == 0) Unit.System = YU_TEX; else Unit.System = YU_DENIER; } else { Unit.Method = YU_INDIRECT; if (index == 2) Unit.System = YU_COTTON; else if (index == 3) Unit.System = YU_WORSTED; else if (index == 4) Unit.System = YU_Y_S_W; else Unit.System = YU_LINEN; } return Unit; } //--------------------------------------------------------------------------- double __fastcall Count2Dot(Word dpi, TYarnUnit yu, short count) { if (yu.Method==YU_DIRECT) { return (dpi*sqrt((double)count))/(Yunit.d[yu.System].F); } else { return dpi/(sqrt((double)count)*Yunit.i[yu.System].F); } } //--------------------------------------------------------------------------- /* double __fastcall Dot2Count(Word dpi, TYarnUnit yu, short dot, double ratio) { if (yu.Method==YU_DIRECT) { return pow((double)(Yunit.d[yu.System].F*ratio*dot)/dpi, 2.0); } else { return pow((double)dpi/(Yunit.i[yu.System].F*ratio*dot), 2.0); } } */ //---------------------------------------------------------------------------