//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Tex.h" #include "common.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall Tex::Tex(){ Curve = new TList; Wales = new TList; Courses = new TList; Raise = new TList; Force = new TList; Visible = true; Repeat = false; leftShift=0; WaleState *ws = new WaleState; Wales->Add(ws);//¾ðÁ¦³ª 1°³ ÀÌ»ó old_iotc=0; lpThreading=NULL; } //--------------------------------------------------------------------------- __fastcall Tex::~Tex(){ if(lpThreading) VirtualUnlock(lpThreading,old_iotc*sizeof(Threading)); if(lpThreading) VirtualFree(lpThreading,old_iotc*sizeof(Threading),MEM_DECOMMIT); if(Curve){ /* while(Curve->Count){ delete (KO *)Curve->Last(); Curve->Remove(Curve->Last()); } delete Curve; */ KO *itemKO = NULL; for (int i = 0; i < Curve->Count; i++) { itemKO = (KO *)Curve->Items[i]; delete itemKO; } Curve->Clear(); delete Curve; } if(Wales){ /* while(Wales->Count){ delete (WaleState *)Wales->Last(); Wales->Remove(Wales->Last()); } delete Wales; */ WaleState *itemWaleState = NULL; for (int i = 0; i < Wales->Count; i++) { itemWaleState = (WaleState *)Wales->Items[i]; delete itemWaleState; } Wales->Clear(); delete Wales; } if(Courses){ /* while(Courses->Count){ delete (CourseState2 *)Courses->Last(); Courses->Remove(Courses->Last()); } delete Courses; */ CourseState2 *itemCourseState2 = NULL; for (int i = 0; i < Courses->Count; i++) { itemCourseState2 = (CourseState2 *)Courses->Items[i]; delete itemCourseState2; } Courses->Clear(); delete Courses; } if(Raise){ /* while(Raise->Count){ delete (bool *)Raise->Last(); Raise->Remove(Raise->Last()); } delete Raise; */ bool *itembool = NULL; for (int i = 0; i < Raise->Count; i++) { itembool = (bool *)Raise->Items[i]; delete itembool; } Raise->Clear(); delete Raise; } if(Force){ /* while(Force->Count){ delete (bool *)Force->Last(); Force->Remove(Force->Last()); } delete Force; */ bool *itembool = NULL; for (int i = 0; i < Force->Count; i++) { itembool = (bool *)Force->Items[i]; delete itembool; } Force->Clear(); delete Force; } } //--------------------------------------------------------------------------- void __fastcall Tex::SetHeight(int h){ Height = h; if(Curve->Count>h){ while(Curve->Count>h){ delete (KO *)Curve->Last(); Curve->Remove(Curve->Last()); } } else { while(Curve->CountCount%2){ KO *ko = new KO; ko->in = 1; ko->via = 0; ko->out = 1; Curve->Add(ko); } else { KO *ko = new KO; ko->in = 2; ko->via = 3; ko->out = 2; Curve->Add(ko); } } } if(Courses->Count>h){ while(Courses->Count>h){ delete (CourseState2 *)Courses->Last(); Courses->Remove(Courses->Last()); } } else { while(Courses->CountAdd(cs); } } if(Raise->Count>h){ while(Raise->Count>h){ delete (bool *)Raise->Last(); Raise->Remove(Raise->Last()); } } else { while(Raise->CountAdd(ol); } } if(Force->Count>h){ while(Force->Count>h){ delete (bool *)Force->Last(); Force->Remove(Force->Last()); } } else { while(Force->CountAdd(ol); } } } //--------------------------------------------------------------------------- int __fastcall Tex::GetHeight(){ return Curve->Count; } //--------------------------------------------------------------------------- bool __fastcall Tex::Draw(HDC hDC, TList *YarnList, RECT r, int DistX, int DistY, POINT delta, int diff){ bool black_y = false; if(!Curve)return false; if(Curve->Count==0)return false; Correction(); KO *ko; int w = (r.right-r.left)/DistX; int h = (r.bottom-r.top)/DistY; if(Wales->Count<0) { return false; } SetThreading(); if(lpThreading==NULL) return false; for(int j = -w-leftShift; j <= w-leftShift; j++ ){ if(!Repeat&&j!=0) continue; Yarn *yarn = NULL; if(Repeat) { yarn = GetYarn(YarnList, j, false); } else { yarn = GetYarn(YarnList, j, true); } if(yarn==NULL) continue; if(yarn->color==clBlack){ black_y = true; continue; } HPEN hOldPen,hPen; HBRUSH hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hPen = CreatePen(PS_SOLID,1,yarn->color); hOldPen = SelectObject(hDC, hPen); int chartbottom = //min = 0 (diff)/DistY -1; if(chartbottom<0) chartbottom=0; int charttop = //max = r.bottom/DistY (r.bottom-r.top)/DistY+1; if(charttop>r.bottom/DistY) charttop= r.bottom/DistY; Reset_StartingPoint = true; for(int i=chartbottom;iItems[i%Curve->Count]); DrawKo(hDC, ko , r, j+leftShift, i, DistX, DistY, delta);//leftShift Á·Π½¬ÇÁÆ® } SelectObject(hDC, hOldPen); SelectObject(hDC, hOldBrush); DeleteObject(hPen); } return black_y; } //--------------------------------------------------------------------------- //¹Ù·ÎÀ§ draw¿Í °°Àº ±¸¹®ÀÌÁö¸¸ °ËÀº»ö ½ÇÀ» Ãâ·ÂÇϱâ À§Çؼ­ µû·Î Á¸ÀçÇÑ´Ù //°ËÀº»öÀ» ±×³É °°ÀÌ ±×¸®¸é ¸¶½ºÅ©¿¡ ¹¯¾î³ªÁö ¾Ê±â ¶§¹®ÀÌ´Ù void __fastcall Tex::DrawBlack(HDC hDC, TList *YarnList, RECT r, int DistX, int DistY, POINT delta, int diff){ if(!Curve)return; if(Curve->Count==0)return; Correction(); KO *ko; int w = (r.right-r.left)/DistX; int h = (r.bottom-r.top)/DistY; if(Wales->Count<0) { return; } SetThreading(); if(lpThreading==NULL) return; for(int j = -w-leftShift; j <= w-leftShift; j++ ){ if(!Repeat&&j!=0) continue; Yarn *yarn = NULL; if(Repeat) { yarn = GetYarn(YarnList, j, false); } else { yarn = GetYarn(YarnList, j, true); } if(yarn==NULL) continue; if(yarn->color != clBlack) continue; HPEN hOldPen,hPen; HBRUSH hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hPen = CreatePen(PS_SOLID,1,clWhite); hOldPen = SelectObject(hDC, hPen); int chartbottom = //min = 0 (diff)/DistY -1; if(chartbottom<0) chartbottom=0; int charttop = //max = r.bottom/DistY (r.bottom-r.top)/DistY+1; if(charttop>r.bottom/DistY) charttop= r.bottom/DistY; Reset_StartingPoint = true; for(int i=chartbottom;iItems[i%Curve->Count]); DrawKo(hDC, ko , r, j+leftShift, i, DistX, DistY, delta);//leftShift Á·Π½¬ÇÁÆ® } SelectObject(hDC, hOldPen); SelectObject(hDC, hOldBrush); DeleteObject(hPen); } } //--------------------------------------------------------------------------- void __fastcall Tex::MouseMove(TShiftState Shift, int X , int Y){ } //--------------------------------------------------------------------------- void __fastcall Tex::MouseDown(TShiftState Shift, int X , int Y, bool Complex){ if(Y>=Curve->Count)return; KO *ko = (KO *)(Curve->Items[Y]); int x = X -leftShift; if(Complex){ if(Shift.Contains(ssCtrl)){ ko->in = x; } else if(Shift.Contains(ssAlt)){ ko->via = x; } else { ko->out = x; } } else { if(!Shift.Contains(ssCtrl)){ if(ko->in>ko->via){ ko->in = x; ko->via = x+1; } else if(ko->invia){ ko->in = x + 1; ko->via = x; } else { ko->in = x; ko->via = x+1; ko->out = x; } } else { if(ko->in>ko->via){ if(ko->via>x) ko->out = ko->via; else if(ko->viaout = ko->via+1; else { if(ko->out>ko->via) ko->out = ko->via; else ko->out = ko->via+1; } } else if(ko->invia){ if(ko->via-1>x) ko->out = ko->via-1; else if(ko->via-1out = ko->via; else { if(ko->outvia) ko->out = ko->via; else ko->out = ko->via-1; } } } } Correction(); } //--------------------------------------------------------------------------- void __fastcall Tex::DrawKo(HDC hDC, KO *ko , RECT r, int x, int y, int DistX, int DistY, POINT delta){ r.right--; // r.bottom--; // correction int inx, outx; int minx,maxx; double midx; minx = min(ko->in,min(ko->via,ko->out)); maxx = max(ko->in,max(ko->via,ko->out)); midx = (double)(minx + maxx)/2.0; double R = DistX/4.0; int inMode; /* 0 == bottom, 1 == top, 2 == vert. */ bool cw; if(ko->invia) cw = false; /* µ¹¾Æ°¡´Â ¹æÇâÀ» Á¤ÇÏ´Â°Ô °¡Àå ¿ì¼±ÀÌ´Ù */ else cw = true; /* cw == clock-wise */ if(cw) { outx = ko->via; inx = ko->in - 1; } else { outx = ko->via-1; inx = ko->in; } static int oldvia = ko->in; if(y==0) oldvia = ko->in; if(midx>ko->in) { if(oldvia>ko->in) inMode = 0; else inMode = 1; } else { if(oldviain) inMode = 0; else inMode = 1; } oldvia = ko->via; static int oldout = ko->in; if(y==0) oldout = ko->in; if(oldout==ko->in) inMode=2; oldout = ko->out; if(Reset_StartingPoint)//gabriel 0Æ÷ÀÎÆ® ¿¡·¯ ¾ø¾Ú MoveToEx(hDC, r.right - (ko->in + x)*DistX , r.bottom - r.top - y*DistY - 0.5*DistY + R, NULL ); if(minx!=maxx){ if(y==0) { DrawKoInVert(hDC, r, x + inx, y, DistX, DistY, cw, delta); } else { if(inMode==1)DrawKoInTop(hDC, r, x + inx, y, DistX, DistY, cw, delta); else if(inMode==0)DrawKoInBottom(hDC, r, x + inx, y, DistX, DistY, cw, delta); else if(inMode==2)DrawKoInVert(hDC, r, x + inx, y, DistX, DistY, cw, delta); } } if(minx==maxx){ if(y>0)LineTo(hDC, r.right - (ko->in + x)*DistX , r.bottom - r.top - y*DistY - 0.5*DistY + R ); else MoveToEx(hDC, r.right - (ko->in + x)*DistX , r.bottom - r.top - y*DistY - 0.5*DistY + R, NULL ); LineTo(hDC, r.right - (ko->in + x)*DistX , r.bottom - r.top - y*DistY - 0.5*DistY - R ); } else if(minx+1via==ko->out) { DrawKoOutOpen(hDC, r, x + outx, y, DistX, DistY, cw, delta); } else { KO *ko2 = (KO *)(Curve->Items[(y+1)%(Curve->Count)]); if(ko->out!=ko2->in)DrawKoOutClosed(hDC, r, x + outx, y, DistX, DistY, cw, delta); else DrawKoOutClosedVert(hDC, r, x + outx, y, DistX, DistY, cw, delta); } } } //--------------------------------------------------------------------------- void __fastcall Tex::DrawKoInTop(HDC hDC, RECT r, int x, int y, int DistX, int DistY, bool cw, POINT delta){ POINT p; POINT c; c.x = r.right - x*DistX - 0.5*DistX; c.y = r.bottom - r.top - y*DistY - 0.5*DistY; c.x+=delta.x?1:0; c.y+=delta.y?1:0; double R = DistX/4.0; if(cw==true) { p.x = c.x - R; p.y = c.y - R*0.4; } else { p.x = c.x + R; p.y = c.y - R*0.4; } if(y>0 && !Reset_StartingPoint) {//gabriel LineTo(hDC, p.x, p.y ); } else { MoveToEx(hDC, p.x , p.y ,NULL); Reset_StartingPoint = false; } if(cw==true) { LineTo(hDC, c.x - R/1.414 , c.y - R/1.414); Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x , c.y - R, c.x - R/1.414 , c.y - R/1.414); MoveToEx(hDC, c.x , c.y - R,NULL); } else { LineTo(hDC, c.x + R/1.414 , c.y - R/1.414); Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x + R/1.414 , c.y - R/1.414, c.x , c.y - R); MoveToEx(hDC, c.x , c.y - R,NULL); } } //--------------------------------------------------------------------------- void __fastcall Tex::DrawKoInBottom(HDC hDC, RECT r, int x, int y, int DistX, int DistY, bool cw, POINT delta){ POINT p; POINT c; c.x = r.right - x*DistX - 0.5*DistX; c.y = r.bottom - r.top - y*DistY - 0.5*DistY; c.x+=delta.x?1:0; c.y+=delta.y?1:0; double R = DistX/4.0; if(cw==true) { p.x = c.x - R*0.4; p.y = c.y + R; } else { p.x = c.x + R*0.4; p.y = c.y + R; } if(y>0 && !Reset_StartingPoint) {//gabriel LineTo(hDC, p.x, p.y ); } else { MoveToEx(hDC, p.x , p.y ,NULL); Reset_StartingPoint = false; } if(cw==true) { LineTo(hDC, c.x - R/1.414 , c.y + R/1.414); Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x , c.y - R, c.x - R/1.414 , c.y + R/1.414); MoveToEx(hDC, c.x , c.y - R,NULL); } else { LineTo(hDC, c.x + R/1.414 , c.y + R/1.414); Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x + R/1.414 , c.y + R/1.414, c.x , c.y - R); MoveToEx(hDC, c.x , c.y - R,NULL); } } //--------------------------------------------------------------------------- void __fastcall Tex::DrawKoInVert(HDC hDC, RECT r, int x, int y, int DistX, int DistY, bool cw, POINT delta){ POINT p; POINT c; c.x = r.right - x*DistX - 0.5*DistX; c.y = r.bottom - r.top - y*DistY - 0.5*DistY; c.x+=delta.x?1:0; c.y+=delta.y?1:0; double R = DistX/4.0; if(cw==true) { p.x = c.x - R/**0.4*/; p.y = c.y /*+ R*/; } else { p.x = c.x + R/**0.4*/; p.y = c.y /*+ R*/; } if(y>0 && !Reset_StartingPoint) {//gabriel LineTo(hDC, p.x, p.y ); } else { MoveToEx(hDC, p.x , p.y ,NULL); Reset_StartingPoint = false; } if(cw==true) { //LineTo(hDC, c.x - R/1.414 , c.y + R/1.414); Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x , c.y - R, c.x - R/*/1.414*/ , c.y /*+ R/1.414*/); MoveToEx(hDC, c.x , c.y - R,NULL); } else { //LineTo(hDC, c.x + R/1.414 , c.y + R/1.414); Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x + R/*/1.414 */, c.y /*+ R/1.414*/, c.x , c.y - R); MoveToEx(hDC, c.x , c.y - R,NULL); } } //--------------------------------------------------------------------------- void __fastcall Tex::DrawKoOutOpen(HDC hDC, RECT r, int x, int y, int DistX, int DistY, bool cw, POINT delta){ POINT c; c.x = r.right - x*DistX - 0.5*DistX; c.y = r.bottom - r.top - y*DistY - 0.5*DistY; c.x+=delta.x?1:0; c.y+=delta.y?1:0; double R = DistX/4.0; if(cw==true) { Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x + R/*/1.414*/ , c.y /*+ R/1.414*/, c.x , c.y - R); MoveToEx(hDC, c.x + R/*/1.414*/ , c.y /*+ R/1.414*/ ,NULL); //LineTo(hDC, c.x + R , c.y + R*0.4); } else { Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x , c.y - R, c.x - R/*/1.414*/ , c.y /*+ R/1.414*/); MoveToEx(hDC, c.x - R/*/1.414*/ , c.y /*+ R/1.414*/ ,NULL); //LineTo(hDC, c.x - R , c.y + R*0.4); } } //--------------------------------------------------------------------------- void __fastcall Tex::DrawKoOutClosedVert(HDC hDC, RECT r, int x, int y, int DistX, int DistY, bool cw, POINT delta){ POINT c; c.x = r.right - x*DistX - 0.5*DistX; c.y = r.bottom - r.top - y*DistY - 0.5*DistY; c.x+=delta.x?1:0; c.y+=delta.y?1:0; double R = DistX/4.0; if(cw==true) { Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x - R/*/1.414*/ , c.y /*+ R/1.414*/, c.x , c.y - R); MoveToEx(hDC, c.x - R/*/1.414*/ , c.y /*+ R/1.414*/ ,NULL); //LineTo(hDC, c.x - R , c.y + R*0.4); } else { Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x , c.y - R, c.x + R/*/1.414*/ , c.y /*+ R/1.414*/); MoveToEx(hDC, c.x + R/*/1.414*/ , c.y /*+ R/1.414*/ ,NULL); //LineTo(hDC, c.x + R , c.y + R*0.4); } } //--------------------------------------------------------------------------- void __fastcall Tex::DrawKoOutClosed(HDC hDC, RECT r, int x, int y, int DistX, int DistY, bool cw, POINT delta){ POINT c; c.x = r.right - x*DistX - 0.5*DistX; c.y = r.bottom - r.top - y*DistY - 0.5*DistY; c.x+=delta.x?1:0; c.y+=delta.y?1:0; double R = DistX/4.0; if(cw==true) { Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x - R/1.414 , c.y + R/1.414, c.x , c.y - R); MoveToEx(hDC, c.x - R/1.414 , c.y + R/1.414 ,NULL); LineTo(hDC, c.x - R , c.y + R*0.4); } else { Arc(hDC, c.x - R , c.y - R, c.x + R , c.y + R, c.x , c.y - R, c.x + R/1.414 , c.y + R/1.414); MoveToEx(hDC, c.x + R/1.414 , c.y + R/1.414 ,NULL); LineTo(hDC, c.x + R , c.y + R*0.4); } } //--------------------------------------------------------------------------- void __fastcall Tex::Correction(void){ KO *ko1,*ko2; for(int i=0;iCount;i++){ ko1 = (KO *)Curve->Items[i]; ko2 = (KO *)Curve->Items[(i+1)%Curve->Count]; if(ko1->via>ko1->in){ if(ko1->via<=ko2->in) ko1->out = ko1->via; else ko1->out = ko1->via-1; } else if(ko1->viain){ if(ko1->via>=ko2->in) ko1->out = ko1->via; else ko1->out = ko1->via+1; } else { ko1->out = ko1->in; } } } //--------------------------------------------------------------------------- bool __fastcall Tex::ReadFromFile(HANDLE hFile, int main_ver){ DWORD dwRead; int curveCnt,waleCnt,courseCnt,overlapCnt,forceCnt; int Width,Height,leftShift; bool Visible=false; try{ if(Curve){ while(Curve->Count){ delete (KO *)Curve->Last(); Curve->Remove(Curve->Last()); } //delete Curve; } if(Wales){ while(Wales->Count){ delete (WaleState *)Wales->Last(); Wales->Remove(Wales->Last()); } //delete Wales; } if(Courses){ while(Courses->Count){ delete (CourseState2 *)Courses->Last(); Courses->Remove(Courses->Last()); } //delete Courses; } if(Raise){ while(Raise->Count){ delete (bool *)Raise->Last(); Raise->Remove(Raise->Last()); } //delete Raise; } if(Force){ while(Force->Count){ delete (bool *)Force->Last(); Force->Remove(Force->Last()); } //delete Force; } if(main_ver>=100){ int ver; ReadFile(hFile, &ver, sizeof(int), &dwRead, NULL); ReadFile(hFile, &Width, sizeof(int), &dwRead, NULL); ReadFile(hFile, &Height, sizeof(int), &dwRead, NULL); ReadFile(hFile, &leftShift, sizeof(int), &dwRead, NULL); ReadFile(hFile, &Visible, sizeof(bool), &dwRead, NULL); this->Width=Width; this->Height=Height; this->leftShift=leftShift; this->Visible=Visible; ReadFile(hFile, &curveCnt, sizeof(int), &dwRead, NULL); for(int i=0;iAdd(ko); } ReadFile(hFile, &waleCnt, sizeof(int), &dwRead, NULL); for(int i=0;iReadFromFile(hFile); Wales->Add(ws); } ReadFile(hFile, &courseCnt, sizeof(int), &dwRead, NULL); if(ver>=4){ for(int i=0;iReadFromFile(hFile); Courses->Add(cs2); } } else { for(int i=0;iemit=cs->emit; cs2->emit_ref=0; delete cs; Courses->Add(cs2); } } if(ver>=2){ ReadFile(hFile, &overlapCnt, sizeof(int), &dwRead, NULL); for(int i=0;iAdd(ol); } } if(ver>=3){ ReadFile(hFile, &forceCnt, sizeof(int), &dwRead, NULL); for(int i=0;iAdd(ol); } } } else if(main_ver>=1){ ReadFile(hFile, &Width, sizeof(int), &dwRead, NULL); ReadFile(hFile, &Height, sizeof(int), &dwRead, NULL); ReadFile(hFile, &leftShift, sizeof(int), &dwRead, NULL); ReadFile(hFile, &Visible, sizeof(bool), &dwRead, NULL); this->Width=Width; this->Height=Height; this->leftShift=leftShift; this->Visible=Visible; ReadFile(hFile, &curveCnt, sizeof(int), &dwRead, NULL); for(int i=0;iAdd(ko); } ReadFile(hFile, &waleCnt, sizeof(int), &dwRead, NULL); for(int i=0;iReadFromFile(hFile, main_ver);//ÀÏ´Ü Àаí TexLayer¿¡¼­ WaleState·Î º¯È¯ÇÑ´Ù Wales->Add(ws); } ReadFile(hFile, &courseCnt, sizeof(int), &dwRead, NULL); for(int i=0;iemit=cs->emit; cs2->emit_ref=0; delete cs; Courses->Add(cs2); } } } catch(...){ ShowMessage(IDS_MESSAGE_LOAD_FAIL); return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall Tex::SaveToFile(HANDLE hFile){ DWORD dwWrite; try{ int ver=4; WriteFile(hFile, &ver, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &Width, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &Height, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &leftShift, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &Visible, sizeof(bool), &dwWrite, NULL); WriteFile(hFile, &(Curve->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ WriteFile(hFile, Curve->Items[i], sizeof(KO), &dwWrite, NULL); } WriteFile(hFile, &(Wales->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ ((WaleState *)Wales->Items[i])->SaveToFile(hFile); } WriteFile(hFile, &(Courses->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ ((CourseState2 *)Courses->Items[i])->SaveToFile(hFile); } WriteFile(hFile, &(Raise->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ WriteFile(hFile, Raise->Items[i], sizeof(bool), &dwWrite, NULL); } WriteFile(hFile, &(Force->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ WriteFile(hFile, Force->Items[i], sizeof(bool), &dwWrite, NULL); } }catch(...){ ShowMessage(IDS_MESSAGE_SAVE_FAIL); return false; } return true; } //--------------------------------------------------------------------------- double __fastcall Tex::DefaultLength(int i, double Denier, int Multi, double CPC, int WPI, int length_method){ double p=10.0/CPC; double w=25.4/WPI; double d=0; KO *ko2 = (KO *)Curve->Items[(i+1)%Curve->Count]; KO *ko = (KO *)Curve->Items[i]; int n = fabs((ko2->in+ko2->via)-(ko->in+ko->via))/2.0+0.1; if(ko->in==ko->via) { if(n==0) { return 1000/100/CPC; } else { double len = 0.3 + sqrt( (n-1)*(n-1)*GetB2(WPI, CPC) + 1 ); return len*1000/100/CPC; } } switch(length_method){ case 0: { d=0.01371*sqrt(Denier); break; } case 1: { d=0.019*sqrt(12*Multi-3)/3.0; break; } case 2: { d=0.0114*sqrt(Denier); break; } default: { d=0.01371*sqrt(Denier); break; } } return sqrt(p*p+n*n*w*w)+2.05*sqrt(p*p+4.0*d*d)+7.28*d; } //--------------------------------------------------------------------------- double __fastcall Tex::DefaultLengthPer480Course(double Denier, int Multi, double CPC, int WPI, int length_method){ if(Curve->Count==0)return 0; double l=0; for(int i=0;iCount;i++){ l+=DefaultLength(i,Denier,Multi,CPC,WPI,length_method); } l/=Curve->Count; return l*480.0; } //--------------------------------------------------------------------------- double __fastcall Tex::LengthPer480Course(){ if(Courses->Count==0)return 0; double meanEmit=0; CourseState2 *cs; for(int h=0;hCount;h++){ cs = (CourseState2 *)Courses->Items[h]; meanEmit+=cs->emit; } meanEmit/=Courses->Count; return meanEmit; } //--------------------------------------------------------------------------- double __fastcall Tex::mPerYard(double Denier, int Multi, double CPC, int WPI, int length_method){ if(Courses->Count==0){ return DefaultLengthPer480Course(Denier, Multi, CPC, WPI, length_method)/480.0*CPC*91.44/1000.0; } else { return LengthPer480Course()/480.0*CPC*91.44/1000.0; } } //--------------------------------------------------------------------------- double __fastcall Tex::gPerYard(double Denier, int Multi, double CPC, int WPI, int length_method, int total/*ÃѺ»¼ö*/){ return mPerYard(Denier, Multi, CPC, WPI, length_method)*(double)total*Denier/9000.0; } //--------------------------------------------------------------------------- void __fastcall Tex::SetThreading(){ if(lpThreading) VirtualUnlock(lpThreading,old_iotc*sizeof(Threading)); if(lpThreading) VirtualFree(lpThreading,old_iotc*sizeof(Threading),MEM_DECOMMIT); lpThreading=NULL; old_iotc=0; for(int i=0;iCount;i++){ old_iotc+=((WaleState *)Wales->Items[i])->cnt; } lpThreading = (Threading *)VirtualAlloc(NULL,old_iotc*sizeof(Threading),MEM_COMMIT,PAGE_READWRITE); if(lpThreading) VirtualLock(lpThreading,old_iotc*sizeof(Threading)); int k=0; for(int i=0;iCount;i++){ WaleState *ws = (WaleState *)Wales->Items[i]; for(int j=0;jcnt;j++){ (lpThreading+k)->yarnIndex=ws->yarnIndex; (lpThreading+k)->in=ws->in; (lpThreading+k)->isTransParent=ws->isTransParent; k++; } } } //--------------------------------------------------------------------------- Yarn * __fastcall Tex::GetYarn(TList *YarnList, int i, bool ignore_io){ int l=i; while(l<0){l+=old_iotc;} l%=old_iotc; if(ignore_io==true){ if(i==0) { return (Yarn *)YarnList->Items[(lpThreading)->yarnIndex]; } else { return NULL; } } else { if((lpThreading+l)->in){ return (Yarn *)YarnList->Items[(lpThreading+l)->yarnIndex]; } else { return NULL; } } } //--------------------------------------------------------------------------- bool __fastcall Tex::GetTransParent(int i){ int l=i; while(l<0){l+=old_iotc;} l%=old_iotc; if((lpThreading+l)->in){ return (lpThreading+l)->isTransParent; } else { return true; } } //--------------------------------------------------------------------------- double __fastcall Tex::GetB2(int gauge, double cpc2){ int cpc=cpc2*10.0; double table[33][33]={ /* *///0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 /*0 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*1 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*2 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*3 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*4 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*5 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*6 */ {0.00, 0.00, 0.00, 1.61, 0.00, 0.00, 6.45, 0.00,11.49, 0.00,17.89, 0.00,25.81, 0.00,35.16, 0.00,45.83, 0.00,58.06, 0.00,71.74, 0.00,86.68, 0.00,103.23,0.00,121.22,0.00,140.42,0.00,161.29,0.00,183.51}, /*7 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*8 */ {0.00, 0.00, 0.00, 0.90, 0.00, 0.00, 3.65, 0.00, 6.45, 0.00,10.11, 0.00,14.51, 0.00,19.80, 0.00,25.81, 0.00,32.72, 0.00,40.32, 0.00,48.86, 0.00,58.06, 0.00,68.23, 0.00,79.03, 0.00,90.82, 0.00,103.22}, /*9 */ {0.00, 0.00, 0.00, 0.72, 0.00, 0.00, 2.86, 0.00, 5.12, 0.00, 7.95, 0.00,11.49, 0.00,15.60, 0.00,20.43, 0.00,25.81, 0.00,31.81, 0.00,38.56, 0.00,45.83, 0.00,53.88, 0.00,62.41, 0.00,71.74, 0.00,81.49}, /*10 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*11 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*12 */ {0.00, 0.00, 0.00, 0.41, 0.00, 0.00, 1.61, 0.00, 2.89, 0.00, 4.49, 0.00, 6.45, 0.00, 8.76, 0.00,11.49, 0.00,14.52, 0.00,17.89, 0.00,21.72, 0.00,25.81, 0.00,30.25, 0.00,35.16, 0.00,40.32, 0.00,45.87}, /*13 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*14 */ {0.00, 0.00, 0.00, 0.29, 0.00, 0.00, 1.19, 0.00, 2.10, 0.00, 3.28, 0.00, 4.75, 0.00, 6.45, 0.00, 8.48, 0.00,10.69, 0.00,13.18, 0.00,15.92, 0.00,18.92, 0.00,22.28, 0.00,25.81, 0.00,29.59, 0.00,33.70}, /*15 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*16 */ {0.00, 0.00, 0.00, 0.23, 0.00, 0.00, 0.90, 0.00, 1.61, 0.00, 2.53, 0.00, 3.65, 0.00, 4.93, 0.00, 6.45, 0.00, 8.18, 0.00,10.11, 0.00,12.18, 0.00,14.52, 0.00,17.06, 0.00,19.80, 0.00,22.66, 0.00,25.80}, /*17 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*18 */ {0.00, 0.00, 0.00, 0.18, 0.00, 0.00, 0.72, 0.00, 1.28, 0.00, 1.99, 0.00, 2.86, 0.00, 3.92, 0.00, 5.12, 0.00, 6.45, 0.00, 7.95, 0.00, 9.61, 0.00,11.49, 0.00,13.47, 0.00,15.60, 0.00,17.89, 0.00,20.38}, /*19 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*20 */ {0.00, 0.00, 0.00, 0.14, 0.00, 0.00, 0.58, 0.00, 1.04, 0.00, 1.61, 0.00, 2.31, 0.00, 3.17, 0.00, 4.12, 0.00, 5.24, 0.00, 6.45, 0.00, 7.78, 0.00, 9.30, 0.00,10.89, 0.00,12.67, 0.00,14.52, 0.00,16.51}, /*21 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*22 */ {0.00, 0.00, 0.00, 0.12, 0.00, 0.00, 0.48, 0.00, 0.85, 0.00, 1.32, 0.00, 1.93, 0.00, 2.62, 0.00, 3.42, 0.00, 4.33, 0.00, 5.34, 0.00, 6.45, 0.00, 7.67, 0.00, 9.00, 0.00,10.43, 0.00,11.97, 0.00,13.64}, /*23 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*24 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*25 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*26 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*27 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*28 */ {0.00, 0.00, 0.00, 0.07, 0.00, 0.00, 0.29, 0.00, 0.53, 0.00, 0.83, 0.00, 1.19, 0.00, 1.61, 0.00, 2.10, 0.00, 2.66, 0.00, 3.28, 0.00, 4.00, 0.00, 4.75, 0.00, 5.57, 0.00, 6.45, 0.00, 7.40, 0.00, 8.42}, /*29 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*30 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*31 */ {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, /*32 */ {0.00, 0.00, 0.00, 0.06, 0.00, 0.00, 0.23, 0.00, 0.41, 0.00, 0.62, 0.00, 0.90, 0.00, 1.23, 0.00, 1.61, 0.00, 2.04, 0.00, 2.53, 0.00, 3.06, 0.00, 3.65, 0.00, 4.24, 0.00, 4.93, 0.00, 5.66, 0.00, 6.45} }; //cpc ºÒ±ÔÄ¢ ºÎºÐ ä¿ì±â for(int i=6;i<=32;i++){ table[i][4]=(2*table[i][3]+table[i][6])/3; } for(int j=5;j<=31;j+=2){ for(int i=6;i<=32;i++){ table[i][j]=(table[i][j-1]+table[i][j+1])/2; } } //gauge ºÒ±ÔÄ¢ ºÎºÐ ä¿ì±â for(int i=3;i<=32;i++){ table[7][i]=(table[6][i]+table[8][i])/2; } for(int i=3;i<=32;i++){ table[10][i]=(2*table[9][i]+table[12][i])/3; } for(int i=3;i<=32;i++){ table[24][i]=(2*table[22][i]+table[28][i])/3; } for(int i=3;i<=32;i++){ table[26][i]=(table[22][i]+2*table[28][i])/3; } for(int i=3;i<=32;i++){ table[30][i]=(table[28][i]+table[32][i])/2; } for(int j=11;j<=31;j+=2){ for(int i=3;i<=32;i++){ table[j][i]=(table[j-1][i]+table[j+1][i])/2; } } if(gauge<6)gauge=6; if(gauge>32)gauge=32; if(cpc<30)cpc=30; if(cpc>320)cpc=320; if(cpc%10){ return table[gauge][cpc/10]; } else { return ((10-cpc%10)*table[gauge][cpc/10]+(cpc%10)*table[gauge][cpc/10+1])/10.0; } } //---------------------------------------------------------------------------