//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TexLayer.h" #include "common.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall TexLayer::TexLayer(){ TexList = new TList; YarnList=new TList; YarnUseList = new TList; Complex = false; repeatRegionState = false; staticState=false; complete_needle=12; Yarn *yarn = new Yarn; YarnList->Add(yarn);//yarnÀº ±âº»ÀûÀ¸·Î 1°³ ÀÌ»ó ¸®½ºÆ®¿¡ ¿Ã¶óÀÖ´Ù } //--------------------------------------------------------------------------- __fastcall TexLayer::~TexLayer(){ if(TexList){ while(TexList->Count){ delete (Tex *)TexList->Last(); TexList->Remove(TexList->Last()); } delete TexList; } if(YarnList){ while(YarnList->Count){ delete (Yarn *)YarnList->Last(); YarnList->Remove(YarnList->Last()); } delete YarnList; } if(YarnUseList){ while(YarnUseList->Count){ delete (YarnUse *)YarnUseList->Last(); YarnUseList->Remove(YarnUseList->Last()); } delete YarnUseList; } } //--------------------------------------------------------------------------- void __fastcall TexLayer::SetHeight(int Height){ for(int i=0;iCount;i++){ ((Tex *)(TexList->Items[i]))->SetHeight(Height); } } //--------------------------------------------------------------------------- int __fastcall TexLayer::GetHeight(){ return ((Tex *)(TexList->Items[0]))->GetHeight(); } //--------------------------------------------------------------------------- void __fastcall TexLayer::AddLayer(){ Tex *tex=new Tex; TexList->Add(tex); } //--------------------------------------------------------------------------- void __fastcall TexLayer::DeleteLayer(int num){ if(num>=TexList->Count)return; delete (Tex *)TexList->Items[num]; TexList->Delete(num); } //--------------------------------------------------------------------------- int __fastcall TexLayer::GetLayerCount(){ return TexList->Count; } //--------------------------------------------------------------------------- void __fastcall TexLayer::SetVisibleLayer(int l, bool v){ if(l>=TexList->Count)return; ((Tex *)(TexList->Items[l]))->Visible=v; } //--------------------------------------------------------------------------- void __fastcall TexLayer::Draw(HDC hDC, RECT r, int DistX, int DistY, bool OneCurve){ int i; if(TexList->Count==0)return; int w = (r.right-r.left)/DistX; int h = (r.bottom-r.top)/DistY; int shift; if(Complex) shift = 0.5*DistX; else shift = 0 ; if(repeatRegionState){ RECT rR; rR.left = min(repeatRegion.left,repeatRegion.right); rR.right = max(repeatRegion.left,repeatRegion.right); rR.top = min(repeatRegion.top,repeatRegion.bottom); rR.bottom = max(repeatRegion.top,repeatRegion.bottom); HPEN hOldPen,hPen = CreatePen(PS_SOLID,1,clGreen); HBRUSH hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hOldPen = SelectObject(hDC, hPen); Rectangle(hDC, r.right-(rR.right+1)*DistX-1 + shift, r.bottom-DistY*(rR.bottom+1)-1, r.right - (rR.left)*DistX + shift, r.bottom - DistY*(rR.top)); SelectObject(hDC, hOldPen); SelectObject(hDC, hOldBrush); DeleteObject(hPen); staticState=false; } else { if(Focus.x>=0&&Focus.x<=w&&Focus.y>=0&&Focus.y<=h){ if(OneCurve){ HPEN hOldPen,hPen = CreatePen(PS_SOLID,1,clGreen); HBRUSH hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hOldPen = SelectObject(hDC, hPen); Rectangle(hDC, r.right-(Focus.x+1)*DistX-1 + shift, r.bottom-DistY*(Focus.y+1)-1, r.right - (Focus.x)*DistX + shift, r.bottom - DistY*(Focus.y)); SelectObject(hDC, hOldPen); SelectObject(hDC, hOldBrush); DeleteObject(hPen); staticState=false; } else { staticState=true; } } } Draw2(hDC,r,DistX,DistY,OneCurve); } //--------------------------------------------------------------------------- void __fastcall TexLayer::Draw2(HDC hDC, RECT r, int DistX, int DistY, bool OneCurve){ int i; if(TexList->Count==0)return; int w = (r.right-r.left)/DistX; int h = (r.bottom-r.top)/DistY; int shift; if(Complex) shift = 0.5*DistX; else shift = 0 ; if(OneCurve){ for(i=0;iCount;i++){ if(((Tex *)(TexList->Items[i]))->Visible==true){ ((Tex *)(TexList->Items[i]))->Draw(hDC, YarnList, r, DistX, DistY, OneCurve, Point(i&1,i&2)); } } } else { int width = complete_needle; int maxrun=0; int minrun=0; for(int j2=0;j2Count;j2++){ Tex *tex = ((Tex *)TexList->Items[j2]); for(int i2=0;i2Curve->Count;i2++) { KO *ko = (KO *)tex->Curve->Items[i2]; maxrun = max(ko->in,max(ko->via,max(ko->out,maxrun))); minrun = min(ko->in,min(ko->via,min(ko->out,minrun))); } } RECT r2=Rect(0,0,(width+(maxrun-minrun))*DistX,r.bottom/*GetHeight()*DistY*/); for(i=0;iCount;i++){ if(((Tex *)(TexList->Items[i]))->Visible==true){ ((Tex *)(TexList->Items[i]))->Draw(hDC, YarnList, r2, DistX, DistY, OneCurve, Point(i&1,i&2)); } } RECT r3=Rect(0,0,width*DistX,r.bottom/*GetHeight()*DistY*/); TTexpiaBitmap *bm = new TTexpiaBitmap; bm->Create(r3.right,r3.bottom,24); HDC dc=bm->CreateDC(); BitBlt(dc,0,0,r3.right,r3.bottom,hDC,r2.right-r3.right,0,SRCCOPY); //r2.bottom==r.bottom for(int l=0;l<=r.right/r3.right;l++){ BitBlt(hDC, r.right-(l+1)*r3.right,0, r3.right,r3.bottom, dc, 0,0, SRCCOPY); } bm->DeleteDC(dc); delete bm; } } //--------------------------------------------------------------------------- bool __fastcall TexLayer::LayerMouseMove(TShiftState Shift, RECT r, int X , int Y, int DistX, int DistY, int LayerNum){ Tex *tex = ((Tex *)(TexList->Items[LayerNum])); if(tex->Visible==false) return true; POINT p = FindCell(r, X, Y, DistX, DistY); tex->MouseMove(Shift, p.x , p.y); if(Shift.Contains(ssShift)){ repeatRegion.right=p.x; repeatRegion.bottom=p.y; } else { repeatRegionState=false; } if(Focus.x == p.x && Focus.y == p.y) { return true; } else { Focus = p; return false; } } //--------------------------------------------------------------------------- void __fastcall TexLayer::LayerMouseDown(TShiftState Shift, RECT r, int X , int Y, int DistX, int DistY, int LayerNum){ Tex *tex = ((Tex *)(TexList->Items[LayerNum])); if(tex->Visible==false)return; POINT p = FindCell(r, X, Y, DistX, DistY); if(Shift.Contains(ssShift)){ repeatRegionState=true; repeatRegion.left=p.x; repeatRegion.top=p.y; repeatRegion.right=p.x; repeatRegion.bottom=p.y; } else { tex->MouseDown(Shift, p.x, p.y, Complex); repeatRegionState=false; } } //--------------------------------------------------------------------------- bool __fastcall TexLayer::LayerMouseUp(TShiftState Shift, RECT r, int X , int Y, int DistX, int DistY, int LayerNum){ //repeatRegionState=false; return true; } //--------------------------------------------------------------------------- POINT __fastcall TexLayer::FindCell(RECT r, int X , int Y, int DistX, int DistY){ int shift; if(Complex) shift = 0.5*DistX; else shift = 0 ; int x = (r.right-X + shift)/DistX; int y = (r.bottom-Y)/DistY; return Point(x,y); } //--------------------------------------------------------------------------- POINT __fastcall TexLayer::FindCell2(RECT r, int X , int Y, int DistX, int DistY){ int shift = 0.5*DistX; int x = (r.right-X + shift)/DistX; int y = (r.bottom-Y)/DistY; return Point(x,y); } //--------------------------------------------------------------------------- bool __fastcall TexLayer::ReadFromFile(HANDLE hFile, int main_ver){ DWORD dwRead; int cnt,yCnt; try{ if(main_ver>=1){ if(TexList){ while(TexList->Count){ delete (Tex *)TexList->Last(); TexList->Remove(TexList->Last()); } //delete TexList; } if(YarnList){ while(YarnList->Count){ delete (Yarn *)YarnList->Last(); YarnList->Remove(YarnList->Last()); } //delete YarnList; } if(YarnUseList){ while(YarnUseList->Count){ delete (YarnUse *)YarnUseList->Last(); YarnUseList->Remove(YarnUseList->Last()); } //delete YarnUseList; } if(main_ver>=100){ int ver; ReadFile(hFile, &ver, sizeof(int), &dwRead, NULL); if(ver>=1){ ReadFile(hFile, &complete_needle, sizeof(int), &dwRead, NULL); ReadFile(hFile, &cnt, sizeof(int), &dwRead, NULL); for(int i=0;iReadFromFile(hFile); YarnList->Add(yarn); } ReadFile(hFile, &cnt, sizeof(int), &dwRead, NULL); for(int i=0;iReadFromFile(hFile); YarnUseList->Add(yu); } ReadFile(hFile, &cnt, sizeof(int), &dwRead, NULL); for(int i=0;iItems[i])->ReadFromFile(hFile, main_ver); } } } else { ReadFile(hFile, &cnt, sizeof(int), &dwRead, NULL); ReadFile(hFile, &yCnt, sizeof(int), &dwRead, NULL); for(int i=0;iyarnIndex=i; yu->layer_num=ys.Bar; yarn->ym=ys.ym; yarn->yp=ys.yp; yarn->denier=ys.denier; yarn->filament=ys.filament; yarn->color=ys.c; yu->mmPerRACK=ys.meanLengthPer480COS; yu->MPY=ys.MPerY; yu->GPY=ys.GPerY; yu->total_use=ys.total; yu->percent=ys.percent; YarnList->Add(yarn);//¿¹ÀüÈ­ÀÏÀ» ºÒ·¯¿À´Ùº¸¸é ½ÇÁ¦·Î ¾²ÀÌÁö ¾ÊÀº ½ÇÀÌ ³ª¿À´Â ¹ö±×°¡ ÀÖÀ¸³ª ¹«½ÃÇØµµ µÊ YarnUseList->Add(yu); } for(int i=0;iItems[i]; tex->ReadFromFile(hFile, main_ver); for(int j=0;jWales->Count;j++){ OldWaleState2 *ws = (OldWaleState2 *)tex->Wales->Items[j]; if(ws->cnt<1) { delete ws; tex->Wales->Remove(ws); j--; continue; } WaleState *ws2 = new WaleState; ws2->cnt=ws->cnt; ws2->in=ws->in; ws2->isTransParent=ws->isTransParent; ws2->yarnIndex=0; bool match=false; for(int k=0;kCount;k++){ Yarn *yarn = (Yarn *)YarnList->Items[k]; if(yarn->color==ws->c&& yarn->denier==ws->Denier&& yarn->filament==ws->multi&& //yarn->contraction==ws->contraction&& yarn->ym==ws->YarnMaterial()&& yarn->yp==ws->YarnProperty()){ ws2->yarnIndex=k; match=true; break; } } if(match==false){ Yarn *yarn=new Yarn; yarn->color=ws->c; yarn->denier=ws->Denier; yarn->filament=ws->multi; //yarn->contraction=ws->contraction; yarn->ym=ws->YarnMaterial(); yarn->yp=ws->YarnProperty(); ws2->yarnIndex=YarnList->Count; YarnList->Add(yarn); } delete ws; tex->Wales->Remove(ws); tex->Wales->Insert(j,ws2); } if(tex->Wales->Count==0){ tex->Wales->Add(new WaleState); } } if(YarnList->Count==0){ YarnList->Add(new Yarn); } int a[4] = {0,0,0,0}; for(int j2=0;j2Count;j2++){ Tex *tex = ((Tex *)TexList->Items[j2]); for(int i2=0;i2Wales->Count;i2++) a[j2]+= ((WaleState *)(tex->Wales->Items[i2]))->cnt; } complete_needle = GetLCN(a[0],a[1],a[2],a[3]); } } }catch(...){ ShowMessage(IDS_MESSAGE_LOAD_FAIL); return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TexLayer::SaveToFile(HANDLE hFile){ DWORD dwWrite; try{ int ver=1; WriteFile(hFile, &ver, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &complete_needle, sizeof(int), &dwWrite, NULL); WriteFile(hFile, &(YarnList->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ ((Yarn *)YarnList->Items[i])->SaveToFile(hFile); } WriteFile(hFile, &(YarnUseList->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ ((YarnUse *)YarnUseList->Items[i])->SaveToFile(hFile); } WriteFile(hFile, &(TexList->Count), sizeof(int), &dwWrite, NULL); for(int i=0;iCount;i++){ ((Tex *)TexList->Items[i])->SaveToFile(hFile); } } catch(...){ ShowMessage(IDS_MESSAGE_SAVE_FAIL); return false; } return true; } //--------------------------------------------------------------------------- void __fastcall TexLayer::setFocus(int fX , int fY){ Focus.x = fX; Focus.y = fY; } //--------------------------------------------------------------------------- void __fastcall TexLayer::repeatUpperRegion(int LayerNum){ Tex *tex = ((Tex *)TexList->Items[LayerNum]); if(repeatRegionState){ RECT rR; rR.left = max(repeatRegion.left,repeatRegion.right); rR.right = min(repeatRegion.left,repeatRegion.right); rR.top = max(repeatRegion.top,repeatRegion.bottom); rR.bottom = min(repeatRegion.top,repeatRegion.bottom); if(rR.top>=tex->Curve->Count) return; int cnt = rR.top - rR.bottom + 1; for(int i=rR.top+1;iCurve->Count;i++){ KO *ko = (KO *)tex->Curve->Items[i]; KO *ko2 = (KO *)tex->Curve->Items[(i-rR.bottom)%cnt+rR.bottom]; *ko = *ko2; } } } //--------------------------------------------------------------------------- void __fastcall TexLayer::leftShiftRegion(int shift, int LayerNum){ Tex *tex = ((Tex *)TexList->Items[LayerNum]); if(repeatRegionState){ RECT rR; rR.left = max(repeatRegion.left,repeatRegion.right); rR.right = min(repeatRegion.left,repeatRegion.right); rR.top = max(repeatRegion.top,repeatRegion.bottom); rR.bottom = min(repeatRegion.top,repeatRegion.bottom); if(rR.top>=tex->Curve->Count) return; int cnt = rR.top - rR.bottom + 1; for(int i=rR.bottom;iCurve->Items[i]; ko->in = ko->in + shift; ko->via = ko->via + shift; ko->out = ko->out + shift; } } else { for(int i=0;iCurve->Count;i++){ KO *ko = (KO *)tex->Curve->Items[i]; ko->in = ko->in + shift; ko->via = ko->via + shift; ko->out = ko->out + shift; } } } //--------------------------------------------------------------------------- void __fastcall TexLayer::invertRegion(int LayerNum){ Tex *tex = ((Tex *)TexList->Items[LayerNum]); if(repeatRegionState){ RECT rR; rR.left = max(repeatRegion.left,repeatRegion.right); rR.right = min(repeatRegion.left,repeatRegion.right); rR.top = max(repeatRegion.top,repeatRegion.bottom); rR.bottom = min(repeatRegion.top,repeatRegion.bottom); if(rR.top>=tex->Curve->Count) return; int cnt = rR.top - rR.bottom + 1; int maxx=0; for(int i=rR.bottom;iCurve->Items[i]; maxx = max(ko->via,max(ko->out,max(maxx,ko->in))); } for(int i=rR.bottom;iCurve->Items[i]; ko->in = maxx - ko->in; ko->via = maxx - ko->via; ko->out = maxx - ko->out; } } else { int maxx=0; for(int i=0;iCurve->Count;i++){ KO *ko = (KO *)tex->Curve->Items[i]; maxx = max(ko->via,max(ko->out,max(maxx,ko->in))); } for(int i=0;iCurve->Count;i++){ KO *ko = (KO *)tex->Curve->Items[i]; ko->in = maxx - ko->in; ko->via = maxx - ko->via; ko->out = maxx - ko->out; } } } //--------------------------------------------------------------------------- void __fastcall TexLayer::MakeYarnImage(){ for(int i=0;iCount;i++){ Yarn *yarn=(Yarn *)YarnList->Items[i]; //yarn } } //---------------------------------------------------------------------------