//--------------------------------------------------------------------------- #include #pragma hdrstop #include "LogData.h" #include "StatusProgress.h" #include "Data3D2.h" #include "Undo.h" #include #include "define.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- static String __fastcall TempN3DFilename() { String filename; Char tp[MAX_PATH+1], fn[MAX_PATH+1]; GetTempPath(MAX_PATH, tp); if (tp[_tcslen(tp)-1]=='\\') tp[_tcslen(tp)-1] = 0; while (1) { _stprintf(fn, L"%s\\N3D%05X.TMP", tp, rand() & 0xFFFFF); if (!FileExists(fn)) break; } filename = filename.sprintf(fn); return filename; } //--------------------------------------------------------------------------- __fastcall HermiteCurves::HermiteCurves(LPVOID ptr, int CurveCnt){ cnt = CurveCnt; curves = (HermiteCurve *)ptr; } //--------------------------------------------------------------------------- __fastcall HermiteCurves::~HermiteCurves(){ curves = NULL; } //--------------------------------------------------------------------------- void __fastcall HermiteCurves::set_constant(){ if(cnt<2){ //cnt >= 1 HermiteCurve *hc1 = curves; hc1->r1 = hc1->p4-hc1->p1; hc1->r4 = hc1->p4-hc1->p1; } else { for(int i=0;ip4-hc1->p1)/hc1->step; double tan2 = (double)(hc2->p4-hc2->p1)/hc2->step; hc1->r1 = (5*tan1/4-tan2/4)*hc1->step; hc1->r4 = (tan1+tan2)/2*hc1->step; } else if(i==cnt-1){ HermiteCurve *hc1 = curves+i-1; HermiteCurve *hc2 = curves+i; double tan1 = (double)(hc1->p4-hc1->p1)/hc1->step; double tan2 = (double)(hc2->p4-hc2->p1)/hc2->step; hc2->r1 = (tan1+tan2)/2*hc2->step; hc2->r4 = (5*tan2/4-tan1/4)*hc2->step; } else { HermiteCurve *hc1 = curves+i-1; HermiteCurve *hc2 = curves+i; HermiteCurve *hc3 = curves+i+1; double tan1 = (double)(hc1->p4-hc1->p1)/hc1->step; double tan2 = (double)(hc2->p4-hc2->p1)/hc2->step; double tan3 = (double)(hc3->p4-hc3->p1)/hc3->step; hc2->r1 = (tan1+tan2)/2*hc2->step; hc2->r4 = (tan2+tan3)/2*hc2->step; } } } for(int i=0;iset_constant(); } } //--------------------------------------------------------------------------- double __fastcall HermiteCurves::get_value(int CurveIndex, double t){ HermiteCurve *hc = curves+CurveIndex; return hc->get_value(t); } //--------------------------------------------------------------------------- __fastcall Vector::Vector(){ // pts = NULL; // dim = 0; pts[0]=0; pts[1]=0; pts[2]=0; dim = 0; } //--------------------------------------------------------------------------- __fastcall Vector::~Vector(){ // if(pts) delete [] pts; } //--------------------------------------------------------------------------- void __fastcall Vector::init(int d){ // if(pts) delete [] pts; // pts = new double[d]; dim = d; } //--------------------------------------------------------------------------- void __fastcall Vector::init3(double x, double y, double z){ init(3); set(0,x); set(1,y); set(2,z); } //--------------------------------------------------------------------------- double __fastcall Vector::get(int n){ if(dim<=n) return 0; return *(pts+n); } //--------------------------------------------------------------------------- void __fastcall Vector::set(int n, double x){ if(dim<=n) return; *(pts+n) = x; } //--------------------------------------------------------------------------- double __fastcall Vector::length(){ if(dim==0) return 0; double r=0, r1; for(int i=0;iz = 0;//pipez; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TData3D2::Normal(){ if(FxUnitCount<2||FyUnitCount<2) return; BEGIN_LOG("Data3D2"); N3D_POINT *pts2=NULL; pts2 = (N3D_POINT *)VirtualAlloc(NULL,sizeof(N3D_POINT)*(FxUnitCount)*(FyUnitCount),MEM_COMMIT,PAGE_READWRITE); if(pts2) VirtualLock(pts2,sizeof(N3D_POINT)*(FxUnitCount)*(FyUnitCount)); for(int i=0;ix-p2b->x)*(p2a->x-p2b->x)+(p2a->y-p2b->y)*(p2a->y-p2b->y) );//Àüü±æÀÌ } for(int j=0;jx-p2b->x)*(p2a->x-p2b->x)+(p2a->y-p2b->y)*(p2a->y-p2b->y) ); if(length2>=length*(j+1)/(yUnitCount-1)) { double a=length2-length*(j+1)/(yUnitCount-1); double b=sqrt( (p2a->x-p2b->x)*(p2a->x-p2b->x)+(p2a->y-p2b->y)*(p2a->y-p2b->y) );// a < b always N3D_POINT *pk1 = (pts+(xUnitCount)*(j+1)+i); if(b==0){ pk1->x = p2b->x; pk1->y = p2b->y; } else { pk1->x = p2b->x*(b-a)/b+p2a->x*a/b; pk1->y = p2b->y*(b-a)/b+p2a->y*a/b; } break; } } } } for(int j=0;jx-p2b->x)*(p2a->x-p2b->x)+(p2a->y-p2b->y)*(p2a->y-p2b->y) );//Àüü±æÀÌ } for(int i=0;ix-p2b->x)*(p2a->x-p2b->x)+(p2a->y-p2b->y)*(p2a->y-p2b->y) ); if(length2>=length*(i+1)/(xUnitCount-1)) { double a=length2-length*(i+1)/(xUnitCount-1); double b=sqrt( (p2a->x-p2b->x)*(p2a->x-p2b->x)+(p2a->y-p2b->y)*(p2a->y-p2b->y) );// a < b always N3D_POINT *pk1 = (pts+(xUnitCount)*j+i+1); if(b==0){ pk1->x = p2b->x; pk1->y = p2b->y; } else { pk1->x = p2b->x*(b-a)/b+p2a->x*a/b; pk1->y = p2b->y*(b-a)/b+p2a->y*a/b; } break; } } } } GenerateSurface(); if(pts2) VirtualUnlock(pts2,sizeof(N3D_POINT)*(FxUnitCount)*(FyUnitCount)); if(pts2) VirtualFree(pts2,sizeof(N3D_POINT)*(FxUnitCount)*(FyUnitCount),MEM_DECOMMIT); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TData3D2::Invert(int mode){ BEGIN_LOG("Data3D2"); if(mode==1){ N3D_POINT *p0 = P(0,0); double minx=p0->x,maxx=p0->x,meanx; for(int i=0;ix,minx); maxx=max(p->x,maxx); } } meanx=(minx+maxx)/2.0; for(int j=0;jx=meanx-(p->x-meanx); } } for(int j=0;jx = (x1*(xUnitCount-1-i)+x2*i)/(double)(xUnitCount-1); p->y = (y1*(xUnitCount-1-i)+y2*i)/(double)(xUnitCount-1); if((i==0&&j==0)||(i==0&&j==yUnitCount-1) ||(i==xUnitCount-1&&j==0)||(i==xUnitCount-1&&j==yUnitCount-1)) { p->visible = true; } else { p->visible = false; } p->fixed = false; } } ResetZ(); END_LOG; } //--------------------------------------------------------------------------- N3D_POINT * __fastcall TData3D2::P(int x, int y){ if(xUnitCount<=x||x<0) return NULL; if(yUnitCount<=y||y<0) return NULL; return (pts+(xUnitCount)*y+x); } //--------------------------------------------------------------------------- bool * __fastcall TData3D2::P_sel(int x, int y){ if(xUnitCount<=x||x<0) return NULL; if(yUnitCount<=y||y<0) return NULL; return (temp_pts+(xUnitCount)*y+x); } //--------------------------------------------------------------------------- void __fastcall TData3D2::PaintData3D2Grid(TObject *Sender, HDC dc, TColor c1, TColor c2){ // ´Ü¼øÈ÷ È­¸é¿¡ ±×¸°´Ù if(pts==NULL) return; BEGIN_LOG("Data3D2"); HPEN hPenF = NULL; HPEN hOldPenF = NULL; //int nDrawMode; //nDrawMode = GetROP2(dc); //SetROP2(dc, R2_NOT); TPLayerImage *iMainImage = (TPLayerImage *)Sender; int i,j; bool exist; N3D_POINT *p=NULL,*p1=NULL,*p2=NULL; N3D_POINT *cursor=NULL; hPenF = CreatePen(psSolid, 1, c2); for(i=0;ivisible){ exist = true; break; } } if(exist) { if(i==CursorPoint.x){ hOldPenF = (HPEN)SelectObject(dc, hPenF); for(j=0;jBitmapToCanvasX(p1->x), iMainImage->BitmapToCanvasY(p1->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p2->x), iMainImage->BitmapToCanvasY(p2->y)); } SelectObject(dc, hOldPenF); hOldPenF = NULL; } else { for(j=0;jBitmapToCanvasX(p1->x), iMainImage->BitmapToCanvasY(p1->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p2->x), iMainImage->BitmapToCanvasY(p2->y)); } } } } for(i=0;ivisible){ exist = true; break; } } if(exist) { if(i==CursorPoint.y){ hOldPenF = (HPEN)SelectObject(dc, hPenF); for(j=0;jBitmapToCanvasX(p1->x), iMainImage->BitmapToCanvasY(p1->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p2->x), iMainImage->BitmapToCanvasY(p2->y)); } SelectObject(dc, hOldPenF); hOldPenF = NULL; } else { for(j=0;jBitmapToCanvasX(p1->x), iMainImage->BitmapToCanvasY(p1->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p2->x), iMainImage->BitmapToCanvasY(p2->y)); } } } } cursor = P(CursorPoint.x,CursorPoint.y); if(cursor&&cursor->visible){ hOldPenF = (HPEN)SelectObject(dc, hPenF); RECT rr; rr.left=iMainImage->BitmapToCanvasX(cursor->x)-5; rr.top=iMainImage->BitmapToCanvasY(cursor->y)-5; rr.right=iMainImage->BitmapToCanvasX(cursor->x)+5; rr.bottom=iMainImage->BitmapToCanvasY(cursor->y)+5; Arc(dc,rr.left,rr.top,rr.right,rr.bottom,rr.left,rr.top,rr.left,rr.top); SelectObject(dc, hOldPenF); hOldPenF = NULL; } DeleteObject(hPenF); hPenF = NULL; //SetROP2(dc, nDrawMode); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TData3D2::Rendering(TUnionBitmap *dst, TUnionBitmap *src, // convert by celberus PatternGroup *pg, TTexpiaBitmap *colormasksrc, TUnionBitmap *masksrc){ if(pts==NULL) return; if(xUnitCount<2||yUnitCount<2) return; /* Byte *brts=NULL; brts = (Byte *)VirtualAlloc(NULL,sizeof(Byte)*(xUnitCount)*(yUnitCount),MEM_COMMIT,PAGE_READWRITE); if(brts) VirtualLock(brts,sizeof(Byte)*(xUnitCount)*(yUnitCount)); //¸í¾ÏÀ» Á¤ÇÑ´Ù Vector stand, light; stand.init3(0,0,1); light.init3(10,-20,30); // ±¤¿øÀÇ ¹æÇâÀ¸·Î ÀÓÀÇ·Î Á¤ÇÑ´Ù light.normal(); double lightangle = light.dot(stand); // lightangleÀº 0º¸´Ù Å©°Ô ¼³°èÇÑ´Ù//0.5ÀÌ»óÀ» ±ÇÀåÇÔ double increasefactor = 1.0+(1.0-lightangle)/lightangle; for(int i=0;ix-p11->x,p12->y-p11->y,p12->z-p11->z); v2.init3(p21->x-p11->x,p21->y-p11->y,p21->z-p11->z); v3.init(3); v3.cross(v2,v1); if(v3.length()<=0){ *(brts+j*xUnitCount+i) = 127; } else { v3.normal(); double angle = light.dot(v3); // -1 <= angle <= 1 if(angle<=0){ *(brts+j*xUnitCount+i) = 0; } else { double brt = angle*increasefactor; if(brt<=0) brt = 0; if(brt>1) brt = 1; *(brts+j*xUnitCount+i) = (Byte)(brt*255); } } } } // Á¶°¢Á¶°¢ ½Ã¹Ä·¹À̼ÇÇÑ´Ù int progpos=StatusProgress->Position; for(int i=0;iPosition=progpos+i*100/(xUnitCount-1); for(int j=0;jx,p11->y); sm.pos[1] = Point(p21->x,p21->y); sm.pos[2] = Point(p22->x,p22->y); sm.pos[3] = Point(p12->x,p12->y); sm.brt[0] = *(brts+j*xUnitCount+i); if(i==xUnitCount-2){ if(j==yUnitCount-2){ sm.brt[1] = *(brts+j*xUnitCount+i); sm.brt[2] = *(brts+j*xUnitCount+i); sm.brt[3] = *(brts+j*xUnitCount+i); } else { sm.brt[1] = *(brts+j*xUnitCount+i); sm.brt[2] = *(brts+(j+1)*xUnitCount+i); sm.brt[3] = *(brts+(j+1)*xUnitCount+i); } } else { if(j==yUnitCount-2){ sm.brt[1] = *(brts+j*xUnitCount+i+1); sm.brt[2] = *(brts+j*xUnitCount+i+1); sm.brt[3] = *(brts+j*xUnitCount+i); } else { sm.brt[1] = *(brts+j*xUnitCount+i+1); sm.brt[2] = *(brts+(j+1)*xUnitCount+i+1); sm.brt[3] = *(brts+(j+1)*xUnitCount+i); } } sm.glx = xUnitDot*100/XRatio; sm.gly = yUnitDot*100/YRatio; sm.dst = dst; sm.src = src; if(pg){ sm.patternsrc = pg->Pattern; } else { sm.patternsrc = NULL; } sm.colormasksrc = colormasksrc; sm.masksrc = masksrc; sm.set_constant(); RGBQUAD bgrgb; TColor bgcolor; if(pg&&pg->Palette&&pg->Pattern){ if(pg->Pattern->BitsPerPixel==24){ bgcolor = pg->Palette->Color[1]; bgrgb = TColorToRGB(bgcolor); } } rendering_piece(sm, i, j, (pg&&pg->Palette&&pg->Pattern) ? pg->transparentPattern : false, bgrgb); } } StatusProgress->Position=progpos+100; if(brts) VirtualUnlock(brts,sizeof(Byte)*(xUnitCount)*(yUnitCount)); if(brts) VirtualFree(brts,sizeof(Byte)*(xUnitCount)*(yUnitCount),MEM_DECOMMIT); */ ////////////////////////////////////////////////////////////////////////////// BEGIN_LOG("Data3D2"); int *brts=NULL; brts = (int *)VirtualAlloc(NULL,sizeof(int)*(xUnitCount)*(yUnitCount),MEM_COMMIT,PAGE_READWRITE); if(brts) VirtualLock(brts,sizeof(int)*(xUnitCount)*(yUnitCount)); //¸í¾ÏÀ» Á¤ÇÑ´Ù double brt; for(int i=0;iz>31) brt = 31; else if(p->z<-32) brt = -32; else brt = p->z; brt+=32; *(brts+j*xUnitCount+i) = (int)(brt*8.0); } } // Á¶°¢Á¶°¢ ½Ã¹Ä·¹À̼ÇÇÑ´Ù int progpos=StatusProgress->Position; for(int i=0;iPosition=progpos+i*100/(xUnitCount-1); for(int j=0;jx,p11->y); sm.pos[1] = Point(p21->x,p21->y); sm.pos[2] = Point(p22->x,p22->y); sm.pos[3] = Point(p12->x,p12->y); sm.brt[0] = *(brts+j*xUnitCount+i); sm.brt[1] = *(brts+j*xUnitCount+i+1); sm.brt[2] = *(brts+(j+1)*xUnitCount+i+1); sm.brt[3] = *(brts+(j+1)*xUnitCount+i); sm.glx = xUnitDot*100/XRatio; sm.gly = yUnitDot*100/YRatio; sm.dst = dst; sm.src = src; if(pg){ sm.patternsrc = pg->Pattern; } else { sm.patternsrc = NULL; } sm.colormasksrc = colormasksrc; sm.masksrc = masksrc; sm.set_constant(); RGBQUAD bgrgb; TColor bgcolor; if(pg&&pg->Palette&&pg->Pattern){ if(pg->Pattern->BitsPerPixel==24){ bgcolor = pg->Palette->Color[1]; bgrgb = TColorToRGB(bgcolor); } } rendering_piece(sm, i, j, (pg&&pg->Palette&&pg->Pattern) ? pg->transparentPattern : false, bgrgb); } } StatusProgress->Position=progpos+100; if(brts) VirtualUnlock(brts,sizeof(int)*(xUnitCount)*(yUnitCount)); if(brts) VirtualFree(brts,sizeof(int)*(xUnitCount)*(yUnitCount),MEM_DECOMMIT); ////////////////////////////////////////////////////////////////////////////// END_LOG; return; } //--------------------------------------------------------------------------- #define cut255(x) (x>255) ? 255 : ( (x<0)? 0 : x ) //--------------------------------------------------------------------------- void __fastcall TData3D2::rendering_piece(sSimData2 &sm, int i, int j, bool transparentPattern, RGBQUAD bgrgb){ BEGIN_LOG("Data3D2"); Byte *DP = 0,*MP = 0, *PP = 0, *CMP = 0,*SP = 0; RGBQUAD rgb[256]; int dstw = sm.dst->Width; int dsth = sm.dst->Height; int w = 0; int h = 0; if(sm.patternsrc){ w=sm.patternsrc->Width; h=sm.patternsrc->Height; sm.patternsrc->GetColors(0, 256, rgb); } RGBQUAD mappingrgb = TColorToRGB(mappingcolor); TPlaneVertex pv; pv.Create(sm.pos[0], sm.pos[1], sm.pos[2], sm.pos[3]); if (sm.sqr[0]>0.0 && sm.sqr[1]>0.0 && sm.sqr[2]>0.0 && sm.sqr[3]>0.0) { for (int y = pv.start.y; y <= pv.end.y; y++) { if( y<0 || y>=dsth ) continue; DP = sm.dst->GetScanLine(y); MP = sm.masksrc->GetScanLine(y); SP = sm.src->GetScanLine(y); CMP = sm.colormasksrc->GetScanLine(y); for (int x = pv.start.x; x <= pv.end.x; x++) { int nx, ny, px, py; int bright; int x1, px1; x1 = 3 * x; if( x<0 || x>=dstw ) continue; if(mappingrgb.rgbBlue!=CMP[x1]||mappingrgb.rgbGreen!=CMP[x1+1]||mappingrgb.rgbRed!=CMP[x1+2]) continue; if ((MP[x >> 3] & (0x80 >> (x & 7))) == 0) { if (pv.Check(x, y)) { double r0=sqrt((sm.pos[0].x-x)*(sm.pos[0].x-x)+(sm.pos[0].y-y)*(sm.pos[0].y-y)); double r1=sqrt((sm.pos[1].x-x)*(sm.pos[1].x-x)+(sm.pos[1].y-y)*(sm.pos[1].y-y)); double r2=sqrt((sm.pos[2].x-x)*(sm.pos[2].x-x)+(sm.pos[2].y-y)*(sm.pos[2].y-y)); double r3=sqrt((sm.pos[3].x-x)*(sm.pos[3].x-x)+(sm.pos[3].y-y)*(sm.pos[3].y-y)); double r=r0+r1+r2+r3; if(r<=0) { bright = sm.brt[0]; } else { bright = (double)(r2*sm.brt[0]+r3*sm.brt[1]+r0*sm.brt[2]+r1*sm.brt[3])/r; } if(bright>2*255)bright=2*255; if(bright<0)bright=0; if(sm.patternsrc==NULL){ DP[x1] = cut255(mappingrgb.rgbBlue*bright/255); DP[x1+1] = cut255(mappingrgb.rgbGreen*bright/255); DP[x1+2] = cut255(mappingrgb.rgbRed*bright/255); } else { sm.find_point(x, y, nx, ny); if(P(FixPointOfGrid.x,FixPointOfGrid.y)){ // Á¦´ë·ÎµÈ µ¥ÀÌŸÀΰ¡? py = (int)( (j-FixPointOfGrid.y) * sm.gly + ny + FixPointOfPattern.y + ((int)(yUnitCount * sm.gly / h)) * h + h ) % h; // À½¼öÀÏ °¡´É¼º ¶§¹®¿¡ ´õÇØÁÜ px = (int)( (i-FixPointOfGrid.x) * sm.glx + nx + FixPointOfPattern.x + ((int)(xUnitCount * sm.glx / w)) * w + w ) % w; // À½¼öÀÏ °¡´É¼º ¶§¹®¿¡ ´õÇØÁÜ } else { py = (int)(j * sm.gly + ny + FixPointOfPattern.y) % h; //px, py´Â ¸Þ¸ð¸®¸¦ ¹þ¾î³ªÁö ¾Ê´Â´Ù px = (int)(i * sm.glx + nx + FixPointOfPattern.x) % w; } PP = sm.patternsrc->GetScanLine(py); if(sm.patternsrc->BitsPerPixel==8){ if(PP[px]==1&&transparentPattern){ //DP[x1] = SP[x1]; //cut255(mappingrgb.rgbBlue*bright/255); //DP[x1+1] = SP[x1+1];//cut255(mappingrgb.rgbGreen*bright/255); //DP[x1+2] = SP[x1+2];//cut255(mappingrgb.rgbRed*bright/255); } else { DP[x1] = cut255(rgb[PP[px]].rgbBlue*bright/255); DP[x1+1] = cut255(rgb[PP[px]].rgbGreen*bright/255); DP[x1+2] = cut255(rgb[PP[px]].rgbRed*bright/255); } } else { px1 = 3 * px; if(transparentPattern){ if(bgrgb.rgbBlue==PP[px1]&&bgrgb.rgbGreen==PP[px1+1]&&bgrgb.rgbRed==PP[px1+2]) { //DP[x1] = SP[x1]; //cut255(mappingrgb.rgbBlue*bright/255); //DP[x1+1] = SP[x1+1];//cut255(mappingrgb.rgbGreen*bright/255); //DP[x1+2] = SP[x1+2];//cut255(mappingrgb.rgbRed*bright/255); } else { DP[x1] = cut255(PP[px1]*bright/255); DP[x1+1] = cut255(PP[px1+1]*bright/255); DP[x1+2] = cut255(PP[px1+2]*bright/255); } } else { DP[x1] = cut255(PP[px1]*bright/255); DP[x1+1] = cut255(PP[px1+1]*bright/255); DP[x1+2] = cut255(PP[px1+2]*bright/255); } } } } } } sm.dst->PutScanLine(y); } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TData3D2::update_point_data(void){ if(pts==NULL) return; if(xUnitCount<2||yUnitCount<2) return; BEGIN_LOG("Data3D2"); if(Version<7){ Byte *brts=NULL; brts = (Byte *)VirtualAlloc(NULL,sizeof(Byte)*(xUnitCount)*(yUnitCount),MEM_COMMIT,PAGE_READWRITE); if(brts) VirtualLock(brts,sizeof(Byte)*(xUnitCount)*(yUnitCount)); Vector stand, light; stand.init3(0,0,1); light.init3(10,-20,30); light.normal(); double lightangle = light.dot(stand); double increasefactor = 1.0+(1.0-lightangle)/lightangle; for(int i=0;ix-p11->x,p12->y-p11->y,p12->z-p11->z); v2.init3(p21->x-p11->x,p21->y-p11->y,p21->z-p11->z); v3.init(3); v3.cross(v2,v1); if(v3.length()<=0){ *(brts+j*xUnitCount+i) = 127; } else { v3.normal(); double angle = light.dot(v3); // -1 <= angle <= 1 if(angle<=0){ *(brts+j*xUnitCount+i) = 0; } else { double brt = angle*increasefactor; if(brt<=0) brt = 0; if(brt>1) brt = 1; *(brts+j*xUnitCount+i) = (Byte)(brt*255); } } } } for(int i=0;iz=(*(brts+j*xUnitCount+i))/8.0-32; } } if(brts) VirtualUnlock(brts,sizeof(Byte)*(xUnitCount)*(yUnitCount)); if(brts) VirtualFree(brts,sizeof(Byte)*(xUnitCount)*(yUnitCount),MEM_DECOMMIT); } END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TData3D2::SaveToFile(HANDLE fh){ BEGIN_LOG("Data3D2"); DWORD dwWrite; if(!WriteFile(fh, &Version, sizeof(int), &dwWrite, NULL)) { return false; } if(Version>=1){ if(!WriteFile(fh, &XRatio, sizeof(int), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &YRatio, sizeof(int), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &FixPointOfPattern, sizeof(POINT), &dwWrite, NULL)) { return false; } if(Version>=3) if(!WriteFile(fh, &FixPointOfGrid, sizeof(POINT), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &mappingcolor, sizeof(TColor), &dwWrite, NULL)) { return false; } if(Version>=5) if(!WriteFile(fh, &IndexOfPatternGroup, sizeof(int), &dwWrite, NULL)) { return false; } SavePointToFile(fh); } END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall TData3D2::SavePointToFile(HANDLE fh){ BEGIN_LOG("Data3D2"); DWORD dwWrite; if(Version>=1){ if(!WriteFile(fh, &xUnitCount, sizeof(int), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &yUnitCount, sizeof(int), &dwWrite, NULL)) { return false; } for(int i=0;ix), sizeof(double), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &(p->y), sizeof(double), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &(p->z), sizeof(double), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &(p->visible), sizeof(bool), &dwWrite, NULL)) { return false; } if(!WriteFile(fh, &(p->fixed), sizeof(bool), &dwWrite, NULL)) { return false; } } } } END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall TData3D2::ReadFromFile(HANDLE fh){ BEGIN_LOG("Data3D2"); DWORD dwRead; if(!ReadFile(fh, &Version, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(Version>=1){ if(!ReadFile(fh, &XRatio, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &YRatio, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(Version==4||Version==5) { if(!SetFilePointer(fh, sizeof(bool), NULL , FILE_CURRENT)) { END_LOG; return false; }//Solid ¸¸µé¾ú´Ù°¡ version 6¿¡¼­ Á¦°Å } if(!ReadFile(fh, &FixPointOfPattern, sizeof(POINT), &dwRead, NULL)) { END_LOG; return false; } if(Version>=3) if(!ReadFile(fh, &FixPointOfGrid, sizeof(POINT), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &mappingcolor, sizeof(TColor), &dwRead, NULL)) { END_LOG; return false; } if(Version>=5) if(!ReadFile(fh, &IndexOfPatternGroup, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } ReadPointFromFile(fh); update_point_data(); if(Version<5){ int w,h; if(!ReadFile(fh, &w, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &h, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } TTexpiaBitmap *Pattern = new TTexpiaBitmap; Pattern->Create(w, h, 24); // Version 5¹Ì¸¸¿¡¼­´Â 24ºñƮ¥¸® ÆÐÅÏÀÌ ÀÖ¾úÁö¸¸ ÇöÀç´Â ¾²Áö ¾Ê´Â´Ù Pattern->LoadFromTexpiaFile(fh, cmZLib); delete Pattern; } } Version = TDATA3D2_FILE_VERSION; END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall TData3D2::ReadPointFromFile(HANDLE fh){ BEGIN_LOG("Data3D2"); DWORD dwRead; if(Version>=1){ if(!ReadFile(fh, &xUnitCount, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &yUnitCount, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } SetxyUnitCount(xUnitCount, yUnitCount); if(Version>=2){ for(int i=0;i=8){ if(!ReadFile(fh, &(p->x), sizeof(double), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &(p->y), sizeof(double), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &(p->z), sizeof(double), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &(p->visible), sizeof(bool), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &(p->fixed), sizeof(bool), &dwRead, NULL)) { END_LOG; return false; } } else { if(!ReadFile(fh, p, 32/*sizeof(N3D_POINT)*/, &dwRead, NULL)) { END_LOG; return false; } } } } } else { for(int i=0;ix = p.x; np->y = p.y; np->z = 0; if((i==0&&j==0)||(i==0&&j==yUnitCount-1) ||(i==xUnitCount-1&&j==0)||(i==xUnitCount-1&&j==yUnitCount-1)) { np->visible = true; } else { np->visible = false; } np->fixed = false; } } } } END_LOG; return true; } //--------------------------------------------------------------------------- void __fastcall TData3D2::Copy(TData3D2 *src){ BEGIN_LOG("Data3D2"); String TempName = TempN3DFilename(); // È­ÀÏ¿¡ ÀúÀåÇϰí Àд ¹æ¹ýÀ¸·Î º¹»çÇÏ¸é ¼Óµµ°¡ ´À¸®°í Æí¹ýÀûÀ̶ó´Â ´ÜÁ¡ÀÌ ÀÖÁö¸¸ // È­ÀÏ ¹öÀüÀÌ ¿Ã¶ó°¡¼­ º¯°æÇؾßÇÒ °ÍÀÌ ÀÖÀ» ¶§ ÀÌÇÔ¼ö¸¦ °íÄ¡´Â ¹ø°Å·Î¿òÀÌ ¾ø´Ù // ´ÜÁö SaveToFile¿Í ReadFromFile¸¦ º¯°æÇϱ⸸ ÇÏ¸é ±×¸¸ HANDLE hFile = INVALID_HANDLE_VALUE; if ((hFile = CreateFile(TempName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { END_LOG; return; } src->SaveToFile(hFile); CloseHandle(hFile); if ((hFile = CreateFile(TempName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { END_LOG; return; } ReadFromFile(hFile); CloseHandle(hFile); DeleteFile(TempName.c_str()); END_LOG; } //--------------------------------------------------------------------------- POINT __fastcall TData3D2::FindNearestPoint(int X, int Y, bool checkvisible){ if(pts==NULL) return Point(-1,-1); BEGIN_LOG("Data3D2"); POINT p; N3D_POINT *p2=NULL; double minr = -1; double r; for(int i=0;ix)*(X-p2->x)+(Y-p2->y)*(Y-p2->y)); if(minr==-1){ minr = r; p = Point(i,j); } else { if(checkvisible){ if(p2->visible){ if(minr>r){ minr = r; p = Point(i,j); } } } else { if(minr>r){ minr = r; p = Point(i,j); } } } } } END_LOG; return p; } //--------------------------------------------------------------------------- POINT __fastcall TData3D2::FindNearestPointZ(int X, int Y, bool checkvisible){ if(pts==NULL) return Point(-1,-1); BEGIN_LOG("Data3D2"); POINT p; N3D_POINT *p2=NULL; double minr = -1; double r; for(int j=0;jx-p1->x,p2->y-p1->y,0); v2.init3(v1.get(1),-v1.get(0),0); v2.normal(); for(int i=0;ix-p1->x,p3->y-p1->y,0); double shift = v2.dot(v3);//p3 °¡ base line¿¡¼­ ¿Ã¶ó°£ °Å¸® double x = p3->x+v2.get(0)*(p3->z-shift); double y = p3->y+v2.get(1)*(p3->z-shift); r = sqrt((X-x)*(X-x)+(Y-y)*(Y-y)); if(minr==-1){ minr = r; p = Point(i,j); } else { if(checkvisible){ if(p3->visible){ if(minr>r){ minr = r; p = Point(i,j); } } } else { if(minr>r){ minr = r; p = Point(i,j); } } } } } END_LOG; return p; } //--------------------------------------------------------------------------- void __fastcall TData3D2::GenerateSurface(){ if(pts==NULL) return; BEGIN_LOG("Data3D2"); static bool processing = false; if(processing) { END_LOG; return; } // Áߺ¹½ÇÇà±ÝÁö processing = true; n3d_index *nis = NULL; // º¸ÀÌ´Â Á¡À» ¼¾´Ù int cntx=0,cnty=0; for(int j=0;jvisible){ cnty++; } } for(int i=0;ivisible){ cntx++; } } if(cntx<2||cnty<2) { processing = false; END_LOG; return; } // º¸ÀÌ´Â Á¡ÀÇ À妽º¿¡ ´ëÇÑ ÀÚ·á°ø°£ ÇÒ´Þ nis = (n3d_index *)VirtualAlloc(NULL,sizeof(n3d_index)*(cntx)*(cnty),MEM_COMMIT,PAGE_READWRITE); if(nis) VirtualLock(nis,sizeof(n3d_index)*(cntx)*(cnty)); // À妽º ÃʱâÈ­ int niscnt=0; for(int j=0;jvisible){ for(int i=0;ivisible){ (nis+niscnt)->ix = i; (nis+niscnt)->iy = j; niscnt++; } } } } // ÇÊ¿äÇÑ Ä¿ºêµéÀÇ °ø°£ ÇÒ´ç // temporary curves int mcnt = max(cntx,cnty); LPVOID lpcx1 = NULL; LPVOID lpcy1 = NULL; LPVOID lpcz1 = NULL; LPVOID lpcx2 = NULL; LPVOID lpcy2 = NULL; LPVOID lpcz2 = NULL; lpcx1 = VirtualAlloc(NULL,sizeof(HermiteCurve)*mcnt,MEM_COMMIT,PAGE_READWRITE); if(lpcx1) VirtualLock(lpcx1,sizeof(HermiteCurve)*mcnt); lpcy1 = VirtualAlloc(NULL,sizeof(HermiteCurve)*mcnt,MEM_COMMIT,PAGE_READWRITE); if(lpcy1) VirtualLock(lpcy1,sizeof(HermiteCurve)*mcnt); lpcz1 = VirtualAlloc(NULL,sizeof(HermiteCurve)*mcnt,MEM_COMMIT,PAGE_READWRITE); if(lpcz1) VirtualLock(lpcz1,sizeof(HermiteCurve)*mcnt); lpcx2 = VirtualAlloc(NULL,sizeof(HermiteCurve)*mcnt,MEM_COMMIT,PAGE_READWRITE); if(lpcx2) VirtualLock(lpcx2,sizeof(HermiteCurve)*mcnt); lpcy2 = VirtualAlloc(NULL,sizeof(HermiteCurve)*mcnt,MEM_COMMIT,PAGE_READWRITE); if(lpcy2) VirtualLock(lpcy2,sizeof(HermiteCurve)*mcnt); lpcz2 = VirtualAlloc(NULL,sizeof(HermiteCurve)*mcnt,MEM_COMMIT,PAGE_READWRITE); if(lpcz2) VirtualLock(lpcz2,sizeof(HermiteCurve)*mcnt); // º¸ÀÌ´Â Á¡À» Hermite Curves ·Î ³ªÅ¸³½´Ù ( °¡·Î ¹æÇâ Ä¿ºê ) for(int j=0;jix,ip1->iy); N3D_POINT *p2 = P(ip2->ix,ip2->iy); HermiteCurve *hcx = cx.curves+i; HermiteCurve *hcy = cy.curves+i; HermiteCurve *hcz = cz.curves+i; hcx->step = ip2->ix-ip1->ix; hcy->step = ip2->ix-ip1->ix; hcz->step = ip2->ix-ip1->ix; hcx->p1 = p1->x; hcx->p4 = p2->x; hcy->p1 = p1->y; hcy->p4 = p2->y; hcz->p1 = p1->z; hcz->p4 = p2->z; } cx.set_constant(); cy.set_constant(); cz.set_constant(); for(int i=0;iix+1;i2ix;i2++){ N3D_POINT *p = P(i2,ip1->iy); p->x = cx.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); p->y = cy.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); p->z = cz.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); } } } // º¸ÀÌ´Â Á¡À» Hermite Curves ·Î ³ªÅ¸³½´Ù ( ¼¼·Î ¹æÇâ Ä¿ºê ) for(int i=0;iix,ip1->iy); N3D_POINT *p2 = P(ip2->ix,ip2->iy); HermiteCurve *hcx = cx.curves+j; HermiteCurve *hcy = cy.curves+j; HermiteCurve *hcz = cz.curves+j; hcx->step = ip2->iy-ip1->iy; hcy->step = ip2->iy-ip1->iy; hcz->step = ip2->iy-ip1->iy; hcx->p1 = p1->x; hcx->p4 = p2->x; hcy->p1 = p1->y; hcy->p4 = p2->y; hcz->p1 = p1->z; hcz->p4 = p2->z; } cx.set_constant(); cy.set_constant(); cz.set_constant(); for(int j=0;jiy+1;j2iy;j2++){ N3D_POINT *p = P(ip1->ix,j2); p->x = cx.get_value(j,((double)(j2-ip1->iy))/(ip2->iy-ip1->iy)); p->y = cy.get_value(j,((double)(j2-ip1->iy))/(ip2->iy-ip1->iy)); p->z = cz.get_value(j,((double)(j2-ip1->iy))/(ip2->iy-ip1->iy)); } } } // ¼¼·Î ¹æÇâÀÇ ¼Óµµ¸¦ °ªÀ¸·Î °¡Áö´Â ¼¼·Î ¹æÇâ Ä¿ºêµé »ý¼º HermiteCurves **vCurvex = NULL; HermiteCurves **vCurvey = NULL; HermiteCurves **vCurvez = NULL; vCurvex = (HermiteCurves **)VirtualAlloc(NULL,sizeof(HermiteCurves *)*(xUnitCount),MEM_COMMIT,PAGE_READWRITE); if(vCurvex) VirtualLock(vCurvex,sizeof(HermiteCurves *)*(xUnitCount)); vCurvey = (HermiteCurves **)VirtualAlloc(NULL,sizeof(HermiteCurves *)*(xUnitCount),MEM_COMMIT,PAGE_READWRITE); if(vCurvey) VirtualLock(vCurvey,sizeof(HermiteCurves *)*(xUnitCount)); vCurvez = (HermiteCurves **)VirtualAlloc(NULL,sizeof(HermiteCurves *)*(xUnitCount),MEM_COMMIT,PAGE_READWRITE); if(vCurvez) VirtualLock(vCurvez,sizeof(HermiteCurves *)*(xUnitCount)); LPVOID curvedatax = NULL; LPVOID curvedatay = NULL; LPVOID curvedataz = NULL; int hcsize = sizeof(HermiteCurve)*(cnty-1); curvedatax = (HermiteCurves *)VirtualAlloc(NULL,hcsize*xUnitCount,MEM_COMMIT,PAGE_READWRITE); if(curvedatax) VirtualLock(curvedatax,hcsize*xUnitCount); curvedatay = (HermiteCurves *)VirtualAlloc(NULL,hcsize*xUnitCount,MEM_COMMIT,PAGE_READWRITE); if(curvedatay) VirtualLock(curvedatay,hcsize*xUnitCount); curvedataz = (HermiteCurves *)VirtualAlloc(NULL,hcsize*xUnitCount,MEM_COMMIT,PAGE_READWRITE); if(curvedataz) VirtualLock(curvedataz,hcsize*xUnitCount); for(int i=0;iix,ip1->iy); N3D_POINT *p2 = P(ip2->ix,ip2->iy); HermiteCurve *hcx = cx.curves+j; HermiteCurve *hcy = cy.curves+j; HermiteCurve *hcz = cz.curves+j; hcx->step = ip2->iy-ip1->iy; hcy->step = ip2->iy-ip1->iy; hcz->step = ip2->iy-ip1->iy; hcx->p1 = p1->x; hcx->p4 = p2->x; hcy->p1 = p1->y; hcy->p4 = p2->y; hcz->p1 = p1->z; hcz->p4 = p2->z; } cx.set_constant(); cy.set_constant(); cz.set_constant(); for(int j=0;jix]->curves+j; HermiteCurve *hcy = vCurvey[ip1->ix]->curves+j; HermiteCurve *hcz = vCurvez[ip1->ix]->curves+j; hcx->r1 = (cx.curves+j)->r1; hcx->r4 = (cx.curves+j)->r4; hcy->r1 = (cy.curves+j)->r1; hcy->r4 = (cy.curves+j)->r4; hcz->r1 = (cz.curves+j)->r1; hcz->r4 = (cz.curves+j)->r4; } } // ¼Óµµ º¤Å͸¦ ¿Ï¼ºÇÑ´Ù (¼Óµµ º¤ÅÍ´Â °¡·Î ¹æÇâÀ» ÃÎÃÎÇÑ °ÍÀ¸·Î Á¤Çß´Ù) for(int j=0;jstep = ip2->ix-ip1->ix; hcy1->step = ip2->ix-ip1->ix; hcz1->step = ip2->ix-ip1->ix; hcx1->p1 = (vCurvex[ip1->ix]->curves+j)->r1; hcx1->p4 = (vCurvex[ip2->ix]->curves+j)->r1; hcy1->p1 = (vCurvey[ip1->ix]->curves+j)->r1; hcy1->p4 = (vCurvey[ip2->ix]->curves+j)->r1; hcz1->p1 = (vCurvez[ip1->ix]->curves+j)->r1; hcz1->p4 = (vCurvez[ip2->ix]->curves+j)->r1; } cx1.set_constant(); cy1.set_constant(); cz1.set_constant(); for(int i=0;iix+1;i2ix;i2++){ (vCurvex[i2]->curves+j)->r1 = cx1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvey[i2]->curves+j)->r1 = cy1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvez[i2]->curves+j)->r1 = cz1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); } } } else if(j==cnty-1) { HermiteCurves cx1(lpcx1,cntx-1); HermiteCurves cy1(lpcy1,cntx-1); HermiteCurves cz1(lpcz1,cntx-1); for(int i=0;istep = ip2->ix-ip1->ix; hcy1->step = ip2->ix-ip1->ix; hcz1->step = ip2->ix-ip1->ix; hcx1->p1 = (vCurvex[ip1->ix]->curves+j-1)->r4; hcx1->p4 = (vCurvex[ip2->ix]->curves+j-1)->r4; hcy1->p1 = (vCurvey[ip1->ix]->curves+j-1)->r4; hcy1->p4 = (vCurvey[ip2->ix]->curves+j-1)->r4; hcz1->p1 = (vCurvez[ip1->ix]->curves+j-1)->r4; hcz1->p4 = (vCurvez[ip2->ix]->curves+j-1)->r4; } cx1.set_constant(); cy1.set_constant(); cz1.set_constant(); for(int i=0;iix+1;i2ix;i2++){ (vCurvex[i2]->curves+j-1)->r4 = cx1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvey[i2]->curves+j-1)->r4 = cy1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvez[i2]->curves+j-1)->r4 = cz1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); } } } else { HermiteCurves cx1(lpcx1,cntx-1); HermiteCurves cy1(lpcy1,cntx-1); HermiteCurves cz1(lpcz1,cntx-1); HermiteCurves cx2(lpcx2,cntx-1); HermiteCurves cy2(lpcy2,cntx-1); HermiteCurves cz2(lpcz2,cntx-1); for(int i=0;istep = ip2->ix-ip1->ix; hcy1->step = ip2->ix-ip1->ix; hcz1->step = ip2->ix-ip1->ix; hcx2->step = ip2->ix-ip1->ix; hcy2->step = ip2->ix-ip1->ix; hcz2->step = ip2->ix-ip1->ix; hcx1->p1 = (vCurvex[ip1->ix]->curves+j-1)->r4; hcx1->p4 = (vCurvex[ip2->ix]->curves+j-1)->r4; hcy1->p1 = (vCurvey[ip1->ix]->curves+j-1)->r4; hcy1->p4 = (vCurvey[ip2->ix]->curves+j-1)->r4; hcz1->p1 = (vCurvez[ip1->ix]->curves+j-1)->r4; hcz1->p4 = (vCurvez[ip2->ix]->curves+j-1)->r4; hcx2->p1 = (vCurvex[ip1->ix]->curves+j)->r1; hcx2->p4 = (vCurvex[ip2->ix]->curves+j)->r1; hcy2->p1 = (vCurvey[ip1->ix]->curves+j)->r1; hcy2->p4 = (vCurvey[ip2->ix]->curves+j)->r1; hcz2->p1 = (vCurvez[ip1->ix]->curves+j)->r1; hcz2->p4 = (vCurvez[ip2->ix]->curves+j)->r1; } cx1.set_constant(); cy1.set_constant(); cz1.set_constant(); cx2.set_constant(); cy2.set_constant(); cz2.set_constant(); for(int i=0;iix+1;i2ix;i2++){ (vCurvex[i2]->curves+j-1)->r4 = cx1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvex[i2]->curves+j)->r1 = cx2.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvey[i2]->curves+j-1)->r4 = cy1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvey[i2]->curves+j)->r1 = cy2.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvez[i2]->curves+j-1)->r4 = cz1.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); (vCurvez[i2]->curves+j)->r1 = cz2.get_value(i,((double)(i2-ip1->ix))/(ip2->ix-ip1->ix)); } } } } // ¼Óµµ º¤Å͵éÀ» ¸ð¾Æ¼­ ÃÎÃÎÇÑ Hermite Surface¸¦ ¸¸µç´Ù for(int i2=0;i2iy); N3D_POINT *p2 = P(i2,ip2->iy); HermiteCurve *hcx = vCurvex[i2]->curves+j; HermiteCurve *hcy = vCurvey[i2]->curves+j; HermiteCurve *hcz = vCurvez[i2]->curves+j; hcx->step = ip2->iy-ip1->iy; hcy->step = ip2->iy-ip1->iy; hcz->step = ip2->iy-ip1->iy; hcx->p1 = p1->x; hcx->p4 = p2->x; hcy->p1 = p1->y; hcy->p4 = p2->y; hcz->p1 = p1->z; hcz->p4 = p2->z; hcx->set_constant(); hcy->set_constant(); hcz->set_constant(); for(int j2=ip1->iy+1;j2iy;j2++){ N3D_POINT *p = P(i2,j2); p->x = hcx->get_value(((double)(j2-ip1->iy))/(ip2->iy-ip1->iy)); p->y = hcy->get_value(((double)(j2-ip1->iy))/(ip2->iy-ip1->iy)); p->z = hcz->get_value(((double)(j2-ip1->iy))/(ip2->iy-ip1->iy)); } } } for(int i=0;iAdd(new TData3D2); Display=new TUnionBitmap; // convert by celberus ColorMask=new TTexpiaBitmap; Mask=new TUnionBitmap; // convert by celberus Display->Create(1,1,24); ColorMask->Create(1,1,24); Mask->Create(1,1,1); Width = 1; Height = 1; RECT r; SetRect(&r, 0, 0, Width, Height); Display->FillRect(r, 0x00FFFFFF); ColorMask->FillRect(r, 0x00FFFFFF); Mask->FillRect(r, clWhite); Activated = true; PActivated = true; temp_angle1=0; temp_angle2=0; } //--------------------------------------------------------------------------- __fastcall T3CP::~T3CP(){ if(FileExists(TempName)) DeleteFile(TempName); if(ListOfData3D2){ while(ListOfData3D2->Count > 0){ TData3D2 *data3d2 = (TData3D2 *)ListOfData3D2->Last(); delete data3d2; ListOfData3D2->Remove(data3d2); } delete ListOfData3D2; ListOfData3D2 = NULL; } if(ListOfPatternGroup){ while(ListOfPatternGroup->Count > 0){ PatternGroup *pg = (PatternGroup *)ListOfPatternGroup->Last(); delete pg; ListOfPatternGroup->Remove(pg); } delete ListOfPatternGroup; ListOfPatternGroup = NULL; } if(ColorMask) {delete ColorMask;ColorMask=NULL;} if(Mask) {delete Mask;Mask=NULL;} if(Display) {delete Display;Display=NULL;} } //--------------------------------------------------------------------------- void __fastcall T3CP::Create(int w, int h){// ´ç¿¬È÷ full color // 24 bits BEGIN_LOG("Data3D2"); if(Width!=w||Height!=h) { Display->Resize(w,h,0x00FFFFFF); ColorMask->Resize(w,h,0x00FFFFFF); //white Mask->Resize(w,h,clWhite); Mask->FillRect(Rect(0, 0, w, h), clWhite); // Åõ¸íÇÏ°Ô ¾ÈµÇ¼­.. by celberus Width = w; Height = h; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall T3CP::SetGridPenState(TGridPenState gps){ // ¿©±â¼­ ±×¸®µå ÆæÀÌ ¹Ù²ð°æ¿ì º¯¼öµéÀ» ¸®¼ÂÇÑ´Ù GridPenStep = 0; FGridPenState = gps; } //--------------------------------------------------------------------------- void __fastcall T3CP::SetIndexOfData3D2(int index){ GridPenStep = 0; FIndexOfData3D2 = index; } //--------------------------------------------------------------------------- void __fastcall T3CP::Paint3CPGrid(TObject *Sender, HDC dc, TColor c1, TColor c2){ BEGIN_LOG("Data3D2"); TPLayerImage *iMainImage = (TPLayerImage *)Sender; if(ListOfData3D2&&ListOfData3D2->Count){ TData3D2 *data3d2 = (TData3D2 *)ListOfData3D2->Items[IndexOfData3D2]; //int nDrawMode; //nDrawMode = GetROP2(dc); //SetROP2(dc, R2_NOT); HPEN hPen = NULL; HPEN hOldPen = NULL; hPen = CreatePen(psSolid, 1, c1); hOldPen = (HPEN)SelectObject(dc, hPen); switch(GridPenState){ case FIX_POINT: { HPEN hPenF = NULL; HPEN hOldPenF = NULL; hPenF = CreatePen(psSolid, 1, c2); hOldPenF = (HPEN)SelectObject(dc, hPenF); N3D_POINT *p=data3d2->P(data3d2->FixPointOfGrid.x,data3d2->FixPointOfGrid.y); if(p){ MoveToEx(dc, iMainImage->BitmapToCanvasX(p->x), iMainImage->BitmapToCanvasY(p->y)+5, NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p->x), iMainImage->BitmapToCanvasY(p->y)-5); MoveToEx(dc, iMainImage->BitmapToCanvasX(p->x-5), iMainImage->BitmapToCanvasY(p->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p->x+5), iMainImage->BitmapToCanvasY(p->y)); } SelectObject(dc, hOldPenF); hOldPenF = NULL; DeleteObject(hPenF); hPenF = NULL; //break; } case NO_MOVE: // ±×¸®µå º¸±â checkedµµ º¸À̱â case MULTI_MOVE: { data3d2->PaintData3D2Grid(Sender, dc, c1, c2); break; } case INIT_PEN: { if(GridPenStep==1){ N3D_POINT *p11=data3d2->P(0,0); N3D_POINT *p12=data3d2->P(0,1); MoveToEx(dc, iMainImage->BitmapToCanvasX(p11->x), iMainImage->BitmapToCanvasY(p11->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p12->x), iMainImage->BitmapToCanvasY(p12->y)); } else if(GridPenStep==2){ N3D_POINT *p11=data3d2->P(0,0); N3D_POINT *p12=data3d2->P(0,1); N3D_POINT *p22=data3d2->P(1,1); MoveToEx(dc, iMainImage->BitmapToCanvasX(p11->x), iMainImage->BitmapToCanvasY(p11->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p12->x), iMainImage->BitmapToCanvasY(p12->y)); MoveToEx(dc, iMainImage->BitmapToCanvasX(p22->x), iMainImage->BitmapToCanvasY(p22->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p12->x), iMainImage->BitmapToCanvasY(p12->y)); } else if(GridPenStep==3){ N3D_POINT *p11=data3d2->P(0,0); N3D_POINT *p12=data3d2->P(0,1); N3D_POINT *p21=data3d2->P(1,0); N3D_POINT *p22=data3d2->P(1,1); MoveToEx(dc, iMainImage->BitmapToCanvasX(p11->x), iMainImage->BitmapToCanvasY(p11->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p12->x), iMainImage->BitmapToCanvasY(p12->y)); LineTo(dc, iMainImage->BitmapToCanvasX(p22->x), iMainImage->BitmapToCanvasY(p22->y)); LineTo(dc, iMainImage->BitmapToCanvasX(p21->x), iMainImage->BitmapToCanvasY(p21->y)); LineTo(dc, iMainImage->BitmapToCanvasX(p11->x), iMainImage->BitmapToCanvasY(p11->y)); } break; } case BRIGHT_MOVE: { HPEN hPenF = NULL; HPEN hOldPenF = NULL; for(int j=0;jyUnitCount;j++){ if(j==data3d2->CursorPoint.y){ hPenF = CreatePen(psSolid, 1, c2); hOldPenF = (HPEN)SelectObject(dc, hPenF); N3D_POINT *p1=data3d2->P(0,j); N3D_POINT *p2=data3d2->P(data3d2->xUnitCount-1,j); if(!p1->visible) { SelectObject(dc, hOldPenF); hOldPenF = NULL; DeleteObject(hPenF); hPenF = NULL; continue; } Vector v1,v2; v1.init3(p2->x-p1->x,p2->y-p1->y,0); v2.init3(v1.get(1),-v1.get(0),0); v2.normal(); MoveToEx(dc, iMainImage->BitmapToCanvasX(p1->x), iMainImage->BitmapToCanvasY(p1->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p2->x), iMainImage->BitmapToCanvasY(p2->y)); MoveToEx(dc, iMainImage->BitmapToCanvasX(p1->x+v2.get(0)*p1->z), iMainImage->BitmapToCanvasY(p1->y+v2.get(1)*p1->z), NULL); for(int i=0;ixUnitCount;i++){ N3D_POINT *p=data3d2->P(i,j); Vector v3; v3.init3(p->x-p1->x,p->y-p1->y,0); double shift = v2.dot(v3);//p °¡ base line¿¡¼­ ¿Ã¶ó°£ °Å¸® LineTo(dc, iMainImage->BitmapToCanvasX(p->x+v2.get(0)*(p->z-shift)), iMainImage->BitmapToCanvasY(p->y+v2.get(1)*(p->z-shift))); } for(int i=0;ixUnitCount;i++){ N3D_POINT *p=data3d2->P(i,j); if(p->visible){ Vector v3; v3.init3(p->x-p1->x,p->y-p1->y,0); double shift = v2.dot(v3);//p °¡ base line¿¡¼­ ¿Ã¶ó°£ °Å¸® MoveToEx(dc, iMainImage->BitmapToCanvasX(p->x+v2.get(0)*(p->z-shift)), iMainImage->BitmapToCanvasY(p->y+v2.get(1)*(p->z-shift)), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p->x+v2.get(0)*(-shift)), iMainImage->BitmapToCanvasY(p->y+v2.get(1)*(-shift))); } } N3D_POINT *cursor = data3d2->P(data3d2->CursorPoint.x,data3d2->CursorPoint.y); if(cursor&&cursor->visible){ RECT rr; Vector v3; v3.init3(cursor->x-p1->x,cursor->y-p1->y,0); double shift = v2.dot(v3);//cursor °¡ base line¿¡¼­ ¿Ã¶ó°£ °Å¸® int x = cursor->x+v2.get(0)*(cursor->z-shift); int y = cursor->y+v2.get(1)*(cursor->z-shift); rr.left=iMainImage->BitmapToCanvasX(x)-5; rr.top=iMainImage->BitmapToCanvasY(y)-5; rr.right=iMainImage->BitmapToCanvasX(x)+5; rr.bottom=iMainImage->BitmapToCanvasY(y)+5; Arc(dc,rr.left,rr.top,rr.right,rr.bottom,rr.left,rr.top,rr.left,rr.top); } SelectObject(dc, hOldPenF); hOldPenF = NULL; DeleteObject(hPenF); hPenF = NULL; } else { N3D_POINT *p1=data3d2->P(0,j); N3D_POINT *p2=data3d2->P(data3d2->xUnitCount-1,j); if(!p1->visible) continue; Vector v1,v2; v1.init3(p2->x-p1->x,p2->y-p1->y,0); v2.init3(v1.get(1),-v1.get(0),0); v2.normal(); MoveToEx(dc, iMainImage->BitmapToCanvasX(p1->x), iMainImage->BitmapToCanvasY(p1->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p2->x), iMainImage->BitmapToCanvasY(p2->y)); MoveToEx(dc, iMainImage->BitmapToCanvasX(p1->x+v2.get(0)*p1->z), iMainImage->BitmapToCanvasY(p1->y+v2.get(1)*p1->z), NULL); for(int i=0;ixUnitCount;i++){ N3D_POINT *p=data3d2->P(i,j); Vector v3; v3.init3(p->x-p1->x,p->y-p1->y,0); double shift = v2.dot(v3);//p °¡ base line¿¡¼­ ¿Ã¶ó°£ °Å¸® LineTo(dc, iMainImage->BitmapToCanvasX(p->x+v2.get(0)*(p->z-shift)), iMainImage->BitmapToCanvasY(p->y+v2.get(1)*(p->z-shift))); } for(int i=0;ixUnitCount;i++){ N3D_POINT *p=data3d2->P(i,j); if(p->visible){ Vector v3; v3.init3(p->x-p1->x,p->y-p1->y,0); double shift = v2.dot(v3);//p °¡ base line¿¡¼­ ¿Ã¶ó°£ °Å¸® MoveToEx(dc, iMainImage->BitmapToCanvasX(p->x+v2.get(0)*(p->z-shift)), iMainImage->BitmapToCanvasY(p->y+v2.get(1)*(p->z-shift)), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(p->x+v2.get(0)*(-shift)), iMainImage->BitmapToCanvasY(p->y+v2.get(1)*(-shift))); } } } } break; } case MOVE_GRID: { data3d2->PaintData3D2Grid(Sender, dc, c1, c2); //HPEN hPenF = NULL; HPEN hOldPenF = NULL; //hPenF = CreatePen(psSolid, 1, c2); //hOldPenF = SelectObject(dc, hPenF); for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *p=data3d2->P(i,j); if(p&&p->visible&&(*pts_sel)){ int nDrawMode; nDrawMode = GetROP2(dc); SetROP2(dc, R2_NOT); RECT rr; rr.left=iMainImage->BitmapToCanvasX(p->x)-5; rr.top=iMainImage->BitmapToCanvasY(p->y)-5; rr.right=iMainImage->BitmapToCanvasX(p->x)+5; rr.bottom=iMainImage->BitmapToCanvasY(p->y)+5; Ellipse(dc, rr.left, rr.top, rr.right, rr.bottom); SetROP2(dc, nDrawMode); } } } for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *p=data3d2->P(i,j); if(p&&p->visible&&(*pts_sel)){ int nDrawMode; nDrawMode = GetROP2(dc); SetROP2(dc, R2_NOT); RECT rr; rr.left=iMainImage->BitmapToCanvasX(p->x+temp_pt2.x)-5; rr.top=iMainImage->BitmapToCanvasY(p->y+temp_pt2.y)-5; rr.right=iMainImage->BitmapToCanvasX(p->x+temp_pt2.x)+5; rr.bottom=iMainImage->BitmapToCanvasY(p->y+temp_pt2.y)+5; Ellipse(dc, rr.left, rr.top, rr.right, rr.bottom); SetROP2(dc, nDrawMode); } } } //SelectObject(dc, hOldPenF); hOldPenF = NULL; //DeleteObject(hPenF); hPenF = NULL; break; } case ROTATE_GRID: { data3d2->PaintData3D2Grid(Sender, dc, c1, c2); //HPEN hPenF = NULL; HPEN hOldPenF = NULL; //hPenF = CreatePen(psSolid, 1, c2); //hOldPenF = SelectObject(dc, hPenF); for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *p=data3d2->P(i,j); if(p&&p->visible&&(*pts_sel)){ int nDrawMode; nDrawMode = GetROP2(dc); SetROP2(dc, R2_NOT); RECT rr; rr.left=iMainImage->BitmapToCanvasX(p->x)-5; rr.top=iMainImage->BitmapToCanvasY(p->y)-5; rr.right=iMainImage->BitmapToCanvasX(p->x)+5; rr.bottom=iMainImage->BitmapToCanvasY(p->y)+5; Ellipse(dc, rr.left, rr.top, rr.right, rr.bottom); SetROP2(dc, nDrawMode); } } } double cos_t=cos(temp_angle2-temp_angle1),sin_t=sin(temp_angle2-temp_angle1); double tempx,tempy; for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *np = data3d2->P(i,j); if(np&&np->visible&&(*pts_sel)){ int nDrawMode; nDrawMode = GetROP2(dc); SetROP2(dc, R2_NOT); tempx= cos_t * (np->x-temp_pt1.x) - sin_t * (np->y-temp_pt1.y); tempy= sin_t * (np->x-temp_pt1.x) + cos_t * (np->y-temp_pt1.y); RECT rr; rr.left=iMainImage->BitmapToCanvasX(tempx+temp_pt1.x)-5; rr.top=iMainImage->BitmapToCanvasY(tempy+temp_pt1.y)-5; rr.right=iMainImage->BitmapToCanvasX(tempx+temp_pt1.x)+5; rr.bottom=iMainImage->BitmapToCanvasY(tempy+temp_pt1.y)+5; Ellipse(dc, rr.left, rr.top, rr.right, rr.bottom); SetROP2(dc, nDrawMode); } } } //SelectObject(dc, hOldPenF); hOldPenF = NULL; //DeleteObject(hPenF); hPenF = NULL; break; } case SELECT_GRID: { data3d2->PaintData3D2Grid(Sender, dc, c1, c2); HPEN hPenF = NULL; HPEN hOldPenF = NULL; hPenF = CreatePen(psSolid, 1, c2); hOldPenF = (HPEN)SelectObject(dc, hPenF); for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *p=data3d2->P(i,j); if(p&&p->visible&&(*pts_sel)){ int nDrawMode; nDrawMode = GetROP2(dc); SetROP2(dc, R2_NOT); RECT rr; rr.left=iMainImage->BitmapToCanvasX(p->x)-5; rr.top=iMainImage->BitmapToCanvasY(p->y)-5; rr.right=iMainImage->BitmapToCanvasX(p->x)+5; rr.bottom=iMainImage->BitmapToCanvasY(p->y)+5; Ellipse(dc, rr.left, rr.top, rr.right, rr.bottom); SetROP2(dc, nDrawMode); } } } SelectObject(dc, hOldPenF); hOldPenF = NULL; DeleteObject(hPenF); hPenF = NULL; if(GridPenStep==6){ int nDrawMode; nDrawMode = GetROP2(dc); SetROP2(dc, R2_NOT); N3D_POINT *np1 = data3d2->P(temp_pt1.x,temp_pt1.y); N3D_POINT *np2 = data3d2->P(temp_pt2.x,temp_pt1.y); N3D_POINT *np3 = data3d2->P(temp_pt2.x,temp_pt2.y); N3D_POINT *np4 = data3d2->P(temp_pt1.x,temp_pt2.y); MoveToEx(dc, iMainImage->BitmapToCanvasX(np1->x), iMainImage->BitmapToCanvasY(np1->y), NULL); LineTo(dc, iMainImage->BitmapToCanvasX(np2->x), iMainImage->BitmapToCanvasY(np2->y)); LineTo(dc, iMainImage->BitmapToCanvasX(np3->x), iMainImage->BitmapToCanvasY(np3->y)); LineTo(dc, iMainImage->BitmapToCanvasX(np4->x), iMainImage->BitmapToCanvasY(np4->y)); LineTo(dc, iMainImage->BitmapToCanvasX(np1->x), iMainImage->BitmapToCanvasY(np1->y)); SetROP2(dc, nDrawMode); } break; } } SelectObject(dc, hOldPen); hOldPen = NULL; DeleteObject(hPen); hPen = NULL; //SetROP2(dc, nDrawMode); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall T3CP::MouseMove(TPLayerImage *iMainImage, TShiftState Shift, int X, int Y){ if(ListOfData3D2&&ListOfData3D2->Count){ TData3D2 *data3d2 = ((TData3D2 *)ListOfData3D2->Items[IndexOfData3D2%ListOfData3D2->Count]); switch(GridPenState){ case NO_MOVE: { break; } case INIT_PEN: { if(GridPenStep==0){ } else if(GridPenStep==1){ N3D_POINT *p = data3d2->P(0,1); p->x = X; p->y = Y; } else if(GridPenStep==2){ N3D_POINT *p = data3d2->P(1,1); p->x = X; p->y = Y; } else if(GridPenStep==3){ N3D_POINT *p = data3d2->P(1,0); p->x = X; p->y = Y; } break; } case NORMAL_MOVE: { break; } case MULTI_MOVE: { if(GridPenStep==0){ if(Shift.Contains(ssAlt)){ POINT p = data3d2->FindNearestPoint(X,Y,false); N3D_POINT *np = data3d2->P(p.x,p.y); if(np==NULL) break; //if(np->visible){ data3d2->CursorPoint = Point(p.x,p.y); //} } else { POINT p = data3d2->FindNearestPoint(X,Y,true); N3D_POINT *np = data3d2->P(p.x,p.y); if(np==NULL) break; if(np->visible){ data3d2->CursorPoint = Point(p.x,p.y); } } } else if(GridPenStep==1){ N3D_POINT *p = data3d2->P(data3d2->CursorPoint.x,data3d2->CursorPoint.y); if(p->visible){ p->x = X; p->y = Y; data3d2->GenerateSurface(); } } break; } case BRIGHT_MOVE: { if(GridPenStep==0){ POINT p = data3d2->FindNearestPointZ(X,Y,true); N3D_POINT *np = data3d2->P(p.x,p.y); if(np==NULL) break; if(np->visible){ data3d2->CursorPoint = Point(p.x,p.y); GridPenStep=4; } } else if(GridPenStep==4){ POINT p = data3d2->FindNearestPointZ(X,Y,true); N3D_POINT *np = data3d2->P(p.x,p.y); if(np==NULL) break; if(np->visible){ data3d2->CursorPoint = Point(p.x,p.y); } } else if(GridPenStep==5){ N3D_POINT *p=data3d2->P(data3d2->CursorPoint.x,data3d2->CursorPoint.y); N3D_POINT *p1=data3d2->P(0,data3d2->CursorPoint.y); N3D_POINT *p2=data3d2->P(data3d2->xUnitCount-1,data3d2->CursorPoint.y); Vector v1,v2,v3,v4; v1.init3(p2->x-p1->x,p2->y-p1->y,0); v2.init3(v1.get(1),-v1.get(0),0); if(v2.length()<=0){ p->z=0; } else { v2.normal(); v4.init3(X-p1->x,Y-p1->y,0); p->z = v4.dot(v2); } data3d2->GenerateSurface(); } break; } case SPECIAL_WAVE: { break; } case SELECT_GRID: { if(GridPenStep==6){ temp_pt2 = data3d2->FindNearestPoint(X,Y,true); if(temp_pt1.x>=data3d2->xUnitCount) temp_pt1.x=data3d2->xUnitCount-1; if(temp_pt1.x<0) temp_pt1.x=0; if(temp_pt1.y>=data3d2->yUnitCount) temp_pt1.y=data3d2->yUnitCount-1; if(temp_pt1.y<0) temp_pt1.y=0; if(temp_pt2.x>=data3d2->xUnitCount) temp_pt2.x=data3d2->xUnitCount-1; if(temp_pt2.x<0) temp_pt2.x=0; if(temp_pt2.y>=data3d2->yUnitCount) temp_pt2.y=data3d2->yUnitCount-1; if(temp_pt2.y<0) temp_pt2.y=0; N3D_POINT *np1 = data3d2->P(temp_pt1.x,temp_pt1.y); N3D_POINT *np2 = data3d2->P(temp_pt2.x,temp_pt2.y); /* static RECT range_oldrc=Rect(0,0,0,0); RECT range_rc = { iMainImage->BitmapToCanvasX(min(np1->x,np2->x))-1, iMainImage->BitmapToCanvasY(min(np1->y,np1->y))-1, iMainImage->BitmapToCanvasX(max(np1->x,np2->x))+1, iMainImage->BitmapToCanvasY(max(np1->y,np2->y))+1}; InvalidateRect(iMainImage->Parent->Handle,&range_oldrc,false); InvalidateRect(iMainImage->Parent->Handle,&range_rc,false); range_oldrc=range_rc;*/ } break; } case MOVE_GRID: { bool check=false; temp_pt1 = Point(0,0); for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); if(*pts_sel){ temp_pt1 = Point(i,j); check = true; break; } } if(check) break; } N3D_POINT *np = data3d2->P(temp_pt1.x,temp_pt1.y); temp_pt2=Point(X-np->x,Y-np->y);//offset break; } case ROTATE_GRID: { N3D_POINT *np1 = data3d2->P(0,0); N3D_POINT *np2 = data3d2->P(data3d2->xUnitCount-1,data3d2->yUnitCount-1); if(np1==NULL||np2==NULL) break; temp_pt1 = Point(np1->x/2+np2->x/2,np1->y/2+np2->y/2); if(temp_pt1.x-X==0){ temp_angle2=0; } else { temp_angle2 = ArcTan2(Y-temp_pt1.y, X-temp_pt1.x); } break; } default: break; } /* static RECT oldrc=Rect(0,0,0,0); double minx,miny,maxx,maxy; N3D_POINT *p0=data3d2->P(0,0); minx=maxx=p0->x; miny=maxy=p0->y; for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *p=data3d2->P(i,j); minx = min(minx,p->x); maxx = max(maxx,p->x); miny = min(miny,p->y); maxy = max(maxy,p->y); } } RECT rc = { iMainImage->BitmapToCanvasX(minx)-5, iMainImage->BitmapToCanvasY(miny)-5, iMainImage->BitmapToCanvasX(maxx)+5, iMainImage->BitmapToCanvasY(maxy)+5}; RECT urc = { min(rc.left,oldrc.left), min(rc.top,oldrc.top), max(rc.right,oldrc.right), max(rc.bottom,oldrc.bottom)}; InvalidateRect(iMainImage->Parent->Handle,&urc,false); oldrc=rc; */ } } //--------------------------------------------------------------------------- void __fastcall T3CP::MouseDown(TPLayerImage *iMainImage, TMouseButton Button, TShiftState Shift, int X, int Y){ if(ListOfData3D2&&ListOfData3D2->Count){ TData3D2 *data3d2 = ((TData3D2 *)ListOfData3D2->Items[IndexOfData3D2%ListOfData3D2->Count]); switch(GridPenState){ case NO_MOVE: { break; } case INIT_PEN: { if(GridPenStep==0){ GridPenStep++; data3d2->SetxyUnitCount(2, 2); N3D_POINT *p = data3d2->P(0,0); p->x = X; p->y = Y; p = data3d2->P(1,0); p->x = X; p->y = Y; p = data3d2->P(0,1); p->x = X; p->y = Y; p = data3d2->P(1,1); p->x = X; p->y = Y; } else if(GridPenStep==1){ GridPenStep++; N3D_POINT *p = data3d2->P(0,1); p->x = X; p->y = Y; p = data3d2->P(1,1); p->x = X; p->y = Y; } else if(GridPenStep==2){ GridPenStep++; N3D_POINT *p = data3d2->P(1,1); p->x = X; p->y = Y; p = data3d2->P(1,0); p->x = X; p->y = Y; } else if(GridPenStep==3){ GridPenStep=0; N3D_POINT *np11 = data3d2->P(0,0), *np12 = data3d2->P(0,1), *np22 = data3d2->P(1,1); POINT p11 = Point(np11->x,np11->y), p12 = Point(np12->x,np12->y), p21 = Point(X,Y), p22 = Point(np22->x,np22->y); int lenx = sqrt((p11.x-p21.x)*(p11.x-p21.x)+(p11.y-p21.y)*(p11.y-p21.y)) +sqrt((p12.x-p22.x)*(p12.x-p22.x)+(p12.y-p22.y)*(p12.y-p22.y)); int leny = sqrt((p11.x-p12.x)*(p11.x-p12.x)+(p11.y-p12.y)*(p11.y-p12.y)) +sqrt((p21.x-p22.x)*(p21.x-p22.x)+(p21.y-p22.y)*(p21.y-p22.y)); data3d2->SetxyUnitCount(lenx/2/data3d2->xUnitDot, leny/2/data3d2->yUnitDot); data3d2->InitGrid(p11, p12, p21, p22); GridPenState=MULTI_MOVE; } break; } case NORMAL_MOVE: { break; } case MULTI_MOVE: { if(GridPenStep==0){ if(Shift.Contains(ssAlt)){ POINT p = data3d2->FindNearestPoint(X,Y,false); N3D_POINT *np = data3d2->P(p.x,p.y); if(p.x==0&&p.y==0||p.x==0&&p.y==data3d2->yUnitCount-1|| p.x==data3d2->xUnitCount-1&&p.y==0|| p.x==data3d2->xUnitCount-1&&p.y==data3d2->yUnitCount-1) break; if(np==NULL) break; if(np->visible){ if(p.x!=0&&p.x!=data3d2->xUnitCount-1){ for(int j=0;jyUnitCount;j++){ N3D_POINT *np1 = data3d2->P(p.x,j); np1->visible = false; } } if(p.y!=0&&p.y!=data3d2->yUnitCount-1){ for(int i=0;ixUnitCount;i++){ N3D_POINT *np1 = data3d2->P(i,p.y); np1->visible = false; } } } else { for(int j=0;jyUnitCount;j++){ bool exist = false; for(int i=0;ixUnitCount;i++){ N3D_POINT *np1 = data3d2->P(i,j); if(np1->visible) { exist = true; break; } } if(exist) { N3D_POINT *np2 = data3d2->P(p.x,j); np2->visible = true; } } for(int i=0;ixUnitCount;i++){ bool exist = false; for(int j=0;jyUnitCount;j++){ N3D_POINT *np1 = data3d2->P(i,j); if(np1->visible) { exist = true; break; } } if(exist) { N3D_POINT *np2 = data3d2->P(i,p.y); np2->visible = true; } } } } else { POINT p = data3d2->FindNearestPoint(X,Y,true); N3D_POINT *np = data3d2->P(p.x,p.y); if(np==NULL) break; if(np->visible){ data3d2->CursorPoint = Point(p.x,p.y); GridPenStep=1; } } } break; } case SPECIAL_WAVE: { break; } case BRIGHT_MOVE: { if(GridPenStep==0||GridPenStep==4){ POINT p = data3d2->FindNearestPointZ(X,Y,true); N3D_POINT *np = data3d2->P(p.x,p.y); if(np==NULL) break; if(np->visible){ data3d2->CursorPoint = Point(p.x,p.y); GridPenStep=5; } } break; } case FIX_POINT: { POINT p = data3d2->FindNearestPoint(X,Y,false); data3d2->FixPointOfGrid = p; break; } case SELECT_GRID: { if(GridPenStep==0){ temp_pt2 = temp_pt1 = data3d2->FindNearestPoint(X,Y,true); GridPenStep=6; } else if(GridPenStep==6){ temp_pt2 = data3d2->FindNearestPoint(X,Y,true); if(temp_pt1.x>=data3d2->xUnitCount) temp_pt1.x=data3d2->xUnitCount-1; if(temp_pt1.x<0) temp_pt1.x=0; if(temp_pt1.y>=data3d2->yUnitCount) temp_pt1.y=data3d2->yUnitCount-1; if(temp_pt1.y<0) temp_pt1.y=0; if(temp_pt2.x>=data3d2->xUnitCount) temp_pt2.x=data3d2->xUnitCount-1; if(temp_pt2.x<0) temp_pt2.x=0; if(temp_pt2.y>=data3d2->yUnitCount) temp_pt2.y=data3d2->yUnitCount-1; if(temp_pt2.y<0) temp_pt2.y=0; if(Param1==0){ for(int j=min(temp_pt1.y,temp_pt2.y);j<=max(temp_pt2.y,temp_pt1.y);j++){ for(int i=min(temp_pt1.x,temp_pt2.x);i<=max(temp_pt2.x,temp_pt1.x);i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *np = data3d2->P(i,j); if(np&&np->visible) *pts_sel = true; } } } else { for(int j=min(temp_pt1.y,temp_pt2.y);j<=max(temp_pt2.y,temp_pt1.y);j++){ for(int i=min(temp_pt1.x,temp_pt2.x);i<=max(temp_pt2.x,temp_pt1.x);i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *np = data3d2->P(i,j); if(np&&np->visible) *pts_sel = false; } } } GridPenStep=0; } break; } case MOVE_GRID: { bool check=false; temp_pt1 = Point(0,0); for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); if(*pts_sel){ temp_pt1 = Point(i,j); check = true; break; } } if(check) break; } N3D_POINT *np = data3d2->P(temp_pt1.x,temp_pt1.y); temp_pt2=Point(X-np->x,Y-np->y);//offset for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *np = data3d2->P(i,j); if(np&&np->visible&&(*pts_sel)){ np->x+=temp_pt2.x; np->y+=temp_pt2.y; } } } data3d2->GenerateSurface(); temp_pt2 = Point(0,0); iMainImage->Repaint(); break; } case ROTATE_GRID: { N3D_POINT *np1 = data3d2->P(0,0); N3D_POINT *np2 = data3d2->P(data3d2->xUnitCount-1,data3d2->yUnitCount-1); if(np1==NULL||np2==NULL) break; temp_pt1 = Point(np1->x/2+np2->x/2,np1->y/2+np2->y/2); if(temp_pt1.x-X==0){ temp_angle2=0; } else { temp_angle2 = ArcTan2(Y-temp_pt1.y, X-temp_pt1.x); } double cos_t=cos(temp_angle2-temp_angle1),sin_t=sin(temp_angle2-temp_angle1); double tempx,tempy; for(int j=0;jyUnitCount;j++){ for(int i=0;ixUnitCount;i++){ bool *pts_sel = data3d2->P_sel(i,j); N3D_POINT *np = data3d2->P(i,j); if(np&&np->visible&&(*pts_sel)){ tempx= cos_t * (np->x-temp_pt1.x) - sin_t * (np->y-temp_pt1.y); tempy= sin_t * (np->x-temp_pt1.x) + cos_t * (np->y-temp_pt1.y); np->x=tempx+temp_pt1.x; np->y=tempy+temp_pt1.y; } } } data3d2->GenerateSurface(); temp_angle1=temp_angle2; iMainImage->Repaint(); break; } default: break; } } } //--------------------------------------------------------------------------- void __fastcall T3CP::MouseUp(TPLayerImage *iMainImage, TMouseButton Button, TShiftState Shift, int X, int Y){ if(ListOfData3D2&&ListOfData3D2->Count){ TData3D2 *data3d2 = ((TData3D2 *)ListOfData3D2->Items[IndexOfData3D2%ListOfData3D2->Count]); switch(GridPenState){ case NO_MOVE: { break; } case INIT_PEN: { break; } case NORMAL_MOVE: case MULTI_MOVE: { if(GridPenStep==1){ data3d2->GenerateSurface(); GridPenStep=0; } break; } case BRIGHT_MOVE: { if(GridPenStep==5){ GridPenStep=4; } break; } case SPECIAL_WAVE: { break; } default: break; } } } //--------------------------------------------------------------------------- bool __fastcall T3CP::SaveToFile(HANDLE fh, TEXPIAFILEHEADER &tpfh){ BEGIN_LOG("Data3D2"); DWORD dwWrite; TCompressMethod cm = tpfh.Compress; int nlength = Name.Length(); int CountOfPattern; if(ListOfPatternGroup) CountOfPattern=ListOfPatternGroup->Count; else CountOfPattern=0; if(!WriteFile(fh, &Version, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(Version>=1){ if(!WriteFile(fh, &Skip, sizeof(bool), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &Density, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &nlength, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, Name.c_str(), sizeof(Char)*(nlength+1), &dwWrite, NULL)) { END_LOG; return false; } if (!ColorMask->SaveToTexpiaFile(fh, cm)) { END_LOG; return false; } if (!Mask->SaveToTexpiaFile(fh, cm)) { END_LOG; return false; } if (!Display->SaveToTexpiaFile(fh, cm)) { END_LOG; return false; } SaveData3D2File(fh,tpfh); } if(Version>=2){ if(!WriteFile(fh, &CountOfPattern, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(ListOfPatternGroup){ for(int i=0;iItems[i]; pg->SaveToFile(fh); } } } END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall T3CP::ReadFromFile(HANDLE fh, TEXPIAFILEHEADER &tpfh){ BEGIN_LOG("Data3D2"); DWORD dwRead; TCompressMethod cm = tpfh.Compress; int nlength; LPVOID buf = NULL; int CountOfPattern; TTexpiaBitmap *temp; // 090527 upper version if (tpfh.Version.Texpia == 'P' && tpfh.Version.Method == 'T' && tpfh.Version.Number > TextileFileVersion) { return false; /*ec = EC_FILE_NOT_OPEN_NEWERVERSION; goto fail;*/ } Create(tpfh.CanvasInfor.Width, tpfh.CanvasInfor.Height); if(!ReadFile(fh, &Version, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(Version>=1){ if(!ReadFile(fh, &Skip, sizeof(bool), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &Density, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &nlength, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if (tpfh.Version.Number <= 301) { //<= 301 ÀÌÀü ¹öÀü buf = VirtualAlloc(NULL, sizeof(char)*(nlength+1),MEM_COMMIT,PAGE_READWRITE); if(buf) VirtualLock(buf, sizeof(char)*(nlength+1)); if(!ReadFile(fh, buf, sizeof(char)*(nlength+1), &dwRead, NULL)) { END_LOG; return false; } Name = String((char *)buf); if(buf) VirtualUnlock(buf, sizeof(char)*(nlength+1)); if(buf) VirtualFree(buf, sizeof(char)*(nlength+1),MEM_DECOMMIT); } else { // >= 302 buf = VirtualAlloc(NULL, sizeof(Char)*(nlength+1),MEM_COMMIT,PAGE_READWRITE); if(buf) VirtualLock(buf, sizeof(Char)*(nlength+1)); if(!ReadFile(fh, buf, sizeof(Char)*(nlength+1), &dwRead, NULL)) { END_LOG; return false; } Name = String((Char *)buf); if(buf) VirtualUnlock(buf, sizeof(Char)*(nlength+1)); if(buf) VirtualFree(buf, sizeof(Char)*(nlength+1),MEM_DECOMMIT); } if (!ColorMask->LoadFromTexpiaFile(fh, cm)) { END_LOG; return false; } if (tpfh.Version.Number < 300) { temp = new TTexpiaBitmap; temp->Create(Mask->Width, Mask->Height, Mask->BitsPerPixel); if (!temp->LoadFromTexpiaFile(fh, cm)) { END_LOG; return false; } if (!Mask->Copy(temp, SRCCOPY)) { END_LOG; return false; } temp->Destroy(); temp->Create(Display->Width, Display->Height, Display->BitsPerPixel); if (!temp->LoadFromTexpiaFile(fh, cm)) { END_LOG; return false; } if (!Display->Copy(temp, SRCCOPY)) { END_LOG; return false; } delete temp; } else { if (!Mask->LoadFromTexpiaFile(fh, cm)) { END_LOG; return false; } if (!Display->LoadFromTexpiaFile(fh, cm)) { END_LOG; return false; } } ReadData3D2File(fh,tpfh); } if(Version>=2){ if(ListOfPatternGroup){ while(ListOfPatternGroup->Count > 0){ PatternGroup *pg = (PatternGroup *)ListOfPatternGroup->Last(); delete pg; ListOfPatternGroup->Remove(pg); } } if(!ReadFile(fh, &CountOfPattern, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(ListOfPatternGroup){ for(int i=0;iReadFromFile(fh); ListOfPatternGroup->Add(pg); } } } Version = T3CP_FILE_VERSION; END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall T3CP::SaveData3D2File(HANDLE fh, TEXPIAFILEHEADER &tpfh){ BEGIN_LOG("Data3D2"); DWORD dwWrite; int CountOfData3D2 = ListOfData3D2->Count; if(!WriteFile(fh, &CountOfData3D2, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(ListOfData3D2){ for(int i=0;iItems[i]; data3d2->SaveToFile(fh); } } END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall T3CP::ReadData3D2File(HANDLE fh, TEXPIAFILEHEADER &tpfh){ BEGIN_LOG("Data3D2"); DWORD dwRead; int CountOfData3D2; if(ListOfData3D2){ while(ListOfData3D2->Count > 0){ TData3D2 *data3d2 = (TData3D2 *)ListOfData3D2->Last(); delete data3d2; ListOfData3D2->Remove(data3d2); } } if(!ReadFile(fh, &CountOfData3D2, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(ListOfData3D2){ for(int i=0;iReadFromFile(fh); ListOfData3D2->Add(data3d2); } if(IndexOfData3D2>=ListOfData3D2->Count) IndexOfData3D2=ListOfData3D2->Count-1; } END_LOG; return true; } //--------------------------------------------------------------------------- void __fastcall T3CP::Rendering(TUnionBitmap *dst, bool mergeOnly){ // convert by celberus BEGIN_LOG("Data3D2"); if(mergeOnly){ if (!Display->StartScanLine()) { END_LOG; return; } if (!Mask->StartScanLine()) { END_LOG; return; } Merge(dst, Display, Mask, Density); Display->StopScanLine(); Mask->StopScanLine(); StatusProgress->Position+=100; } else { Display->Copy(ColorMask, SRCCOPY); if (!Display->StartScanLine()) { END_LOG; return; } if (!ColorMask->StartScanLine()) { END_LOG; return; } if (!Mask->StartScanLine()) { END_LOG; return; } StatusProgress->Position+=40; if(ListOfData3D2){ for(int i=0;iCount;i++){ TData3D2 *data3d2 = ((TData3D2 *)ListOfData3D2->Items[i]); if(data3d2->xUnitCount<2||data3d2->yUnitCount<2) { StatusProgress->Position+=100; continue; } PatternGroup *pg = NULL; if(ListOfPatternGroup->Count>data3d2->IndexOfPatternGroup&&data3d2->IndexOfPatternGroup>=0){ pg = (PatternGroup *)ListOfPatternGroup->Items[data3d2->IndexOfPatternGroup]; if(pg->Pattern){ if (!pg->Pattern->StartScanLine()) { END_LOG; return; } data3d2->Rendering(Display, dst, pg, ColorMask, Mask); pg->Pattern->StopScanLine(); } else { data3d2->Rendering(Display, dst, NULL, ColorMask, Mask); } } else { data3d2->Rendering(Display, dst, NULL, ColorMask, Mask); } } } Merge(dst, Display, Mask, Density); Display->StopScanLine(); ColorMask->StopScanLine(); Mask->StopScanLine(); StatusProgress->Position+=60; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall T3CP::Merge(TUnionBitmap *dst, TUnionBitmap *src, TUnionBitmap *mask, int density){ // convert by celberus BEGIN_LOG("Data3D2"); Byte *DP = 0, *SP = 0, *MP = 0; if(density>100) density=100; if(density<0) density=0; for(int y=0;yHeight;y++){ DP = dst->GetScanLine(y); SP = src->GetScanLine(y); MP = mask->GetScanLine(y); for(int x=0;xWidth;x++){ int x1 = 3 * x; if ((MP[x >> 3] & (0x80 >> (x & 7))) == 0) { DP[x1] = (DP[x1]*(100-density)+SP[x1]*density)/100; DP[x1+1] = (DP[x1+1]*(100-density)+SP[x1+1]*density)/100; DP[x1+2] = (DP[x1+2]*(100-density)+SP[x1+2]*density)/100; } } dst->PutScanLine(y); } END_LOG; return; } //--------------------------------------------------------------------------- bool __fastcall T3CP::SeekType(int &step, TN3DMemberType &mt, LPVOID &ptr){ mt = TYPE_NONE; ptr = NULL; return false; // °ªÀ» ¸øÃ£À¸¸é false// ãÀ¸¸é true } //--------------------------------------------------------------------------- void __fastcall T3CP::Activate(){ if(Activated) return; /* DWORD dwRead; TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; if ((hFile = CreateFile(TempName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) return; if(!ReadFile(hFile, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) return; ReadFromFile(hFile, tpfh); CloseHandle(hFile); */ // need-conversion ÀÓ½ÃÆÄÀÏ »ç¿ë¿©ºÎ //ActivatePattern(); Activated = true; } //--------------------------------------------------------------------------- void __fastcall T3CP::Deactivate(){ /* if(!Activated) return; DWORD dwWrite; TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; if ((hFile = CreateFile(TempName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) return; tpfh.Compress = cmNone; tpfh.CanvasInfor.Width = Width; tpfh.CanvasInfor.Height = Height; if(!WriteFile(hFile, &tpfh, sizeof(TEXPIAFILEHEADER), &dwWrite, NULL)) return; SaveToFile(hFile, tpfh); Create(1,1); /*if(ListOfData3D2){ while(ListOfData3D2->Count > 0){ TData3D2 *data3d2 = (TData3D2 *)ListOfData3D2->Last(); delete data3d2; ListOfData3D2->Remove(data3d2); } }*//* CloseHandle(hFile); //DeactivatePattern();*/ // need-conversion ÀÓ½ÃÆÄÀÏ »ç¿ë¿©ºÎ Activated = false; } //--------------------------------------------------------------------------- void __fastcall T3CP::ActivatePattern(){ if(PActivated) return; BEGIN_LOG("Data3D2"); DWORD dwRead; HANDLE hFile = INVALID_HANDLE_VALUE; if ((hFile = CreateFile(TempName2.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { END_LOG; return; } int CountOfPattern; if(!ReadFile(hFile, &CountOfPattern, sizeof(int), &dwRead, NULL)) { END_LOG; return; } if(ListOfPatternGroup){ while(ListOfPatternGroup->Count > 0){ PatternGroup *pg = (PatternGroup *)ListOfPatternGroup->Last(); delete pg; ListOfPatternGroup->Remove(pg); } } for(int i=0;iReadFromFile(hFile); ListOfPatternGroup->Add(pg); } CloseHandle(hFile); PActivated = true; END_LOG; } //--------------------------------------------------------------------------- void __fastcall T3CP::DeactivatePattern(){ if(!PActivated) return; BEGIN_LOG("Data3D2"); DWORD dwWrite; HANDLE hFile = INVALID_HANDLE_VALUE; if ((hFile = CreateFile(TempName2.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { END_LOG; return; } int CountOfPattern = ListOfPatternGroup->Count; if(!WriteFile(hFile, &CountOfPattern, sizeof(int), &dwWrite, NULL)) { END_LOG; return; } for(int i=0;iItems[i]; pg->SaveToFile(hFile); } if(ListOfPatternGroup){ while(ListOfPatternGroup->Count > 0){ PatternGroup *pg = (PatternGroup *)ListOfPatternGroup->Last(); delete pg; ListOfPatternGroup->Remove(pg); } } CloseHandle(hFile); PActivated = false; END_LOG; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- __fastcall TN3D::TN3D(TPLayerImage *image){ Version = TN3D_FILE_VERSION; TempName = TempN3DFilename(); iMainImage = image; if(image->uBitmap->Width==0||image->uBitmap->Height==0){ if (image->uBitmap->BitsPerPixel == 0) image->uBitmap->Create(1, 1, 24); //image->ResizeLayer(1, 1, 0x00FFFFFF); } Width = image->uBitmap->Width; Height = image->uBitmap->Height; RECT r; SetRect(&r, 0, 0, Width, Height); iMainImage->uBitmap->FillRect(r, 0x00FFFFFF); iMainImage->AddLayer("display", Width, Height, 24, 0x00FFFFFF); iMainImage->AddLayer("colormask", Width, Height, 24, 0x00FFFFFF); iMainImage->Index = 0; // Undo->SetLayerOrder(); ListOf3CP = new TList; T3CP *t3cp = new T3CP; t3cp->Create(Width, Height); ListOf3CP->Add(t3cp); FAMI = 0; GridColor = clYellow; GridFocusColor = clAqua; NotPaintN3DGrid = false; } //--------------------------------------------------------------------------- __fastcall TN3D::~TN3D(){ if(FileExists(TempName)) DeleteFile(TempName); if(ListOf3CP){ while(ListOf3CP->Count > 0){ T3CP *t3cp = (T3CP *)ListOf3CP->Last(); delete t3cp; ListOf3CP->Remove(t3cp); } delete ListOf3CP; ListOf3CP = NULL; } } //--------------------------------------------------------------------------- void __fastcall TN3D::Resize(int w, int h, bool stretch){ if(iMainImage->uBitmap->Width!=w||iMainImage->uBitmap->Height!=h){ if(stretch){ iMainImage->ResizeStretchLayer(w, h); } else { iMainImage->ResizeLayer(w, h, 0x00FFFFFF); } } if(Width!=w||Height!=h) { if(stretch){ if(ListOf3CP){ for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; bool active = t3cp->Activated; t3cp->Activate(); t3cp->Display->ResizeStretch(w, h); t3cp->ColorMask->ResizeStretch(w, h); t3cp->Mask->ResizeStretch(w, h); t3cp->Width = w; t3cp->Height = h; if(!active) t3cp->Deactivate(); } } } else { if(ListOf3CP){ for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; bool active = t3cp->Activated; t3cp->Activate(); t3cp->Display->Resize(w,h,0x00FFFFFF); t3cp->ColorMask->Resize(w,h,0x00FFFFFF); t3cp->Mask->Resize(w,h,clWhite); t3cp->Width = w; t3cp->Height = h; if(!active) t3cp->Deactivate(); } } } Width = w, Height = h; } } //--------------------------------------------------------------------------- TPException __fastcall TN3D::LoadFromFile(HANDLE fh, TPalette *pPalette, TEXPIAFILEHEADER &tpfh){ BEGIN_LOG("Data3D2"); WORD BitCount; TPException ec = EC_NONE; DWORD dwRead; int CountOf3CP; ///////////////////////////////// Start of Standard Tag Format if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) goto fail; // 090527 upper version if (tpfh.Version.Texpia == 'P' && tpfh.Version.Method == 'T' && tpfh.Version.Number > TextileFileVersion) { ec = EC_FILE_NOT_OPEN_NEWERVERSION; goto fail; } WORD useColor; if (!ReadFile(fh, &useColor, sizeof(Word), &dwRead, NULL)) goto fail; pPalette->UseColor = useColor; if (tpfh.Version.Number <= 301){ pPalette->LoadFromFileHandle(fh, 1); } else { pPalette->LoadFromFileHandle(fh, 2); } if (!ReadFile(fh, &BitCount, sizeof(WORD), &dwRead, NULL)) goto fail; if (SetFilePointer(fh, BitCount==8 ? 8000 : 24000, NULL, FILE_CURRENT)== 0xFFFFFFFF) goto fail; ///////////////////////////////// End of Standard Tag Format if(!ReadFile(fh, &Version, sizeof(int), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if(Version>=3){ if(!ReadFile(fh, &GridColor, sizeof(TColor), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } } if(Version>=4){ if(!ReadFile(fh, &GridFocusColor, sizeof(TColor), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } } Resize(tpfh.CanvasInfor.Width, tpfh.CanvasInfor.Height, false); iMainImage->LoadFromLayerFile(fh, tpfh.Version.Number); if(Version>=1){ if(ListOf3CP){ while(ListOf3CP->Count > 0){ T3CP *t3cp = (T3CP *)ListOf3CP->Last(); delete t3cp; ListOf3CP->Remove(t3cp); } } if(!ReadFile(fh, &CountOf3CP, sizeof(int), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if(ListOf3CP){ for(int i=0;iReadFromFile(fh, tpfh); t3cp->Deactivate(); ListOf3CP->Add(t3cp); } } } Version = TN3D_FILE_VERSION; iMainImage->Index = 2; // Undo->SetLayerOrder(); if(CountOf3CP){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[0]; t3cp->Activate(); iMainImage->uBitmap->Copy(t3cp->ColorMask, SRCCOPY); iMainImage->LayerMask->Copy(t3cp->Mask, SRCCOPY); } iMainImage->StartLayerVisibleChange(1, false); // visible ÃʱâÈ­ iMainImage->StartLayerVisibleChange(2, false); iMainImage->EndOfLayerVisibleChange(0, true); // ÃʱâÈ­Çϸ鼭 ·¹¾î¾î üÀÎÁö //0¹øÀ¸·Î ¼¼ÆÃ // Undo->SetLayerOrder(); iMainImage->Repaint(); END_LOG; return EC_NONE; fail: if (fh!=INVALID_HANDLE_VALUE) CloseHandle(fh); END_LOG; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TN3D::SaveToFile(HANDLE fh, TPalette *pPalette, TEXPIAFILEHEADER &tpfh){ BEGIN_LOG("Data3D2"); TUnionBitmap *ub = NULL; LPVOID ptr=NULL; TN3DMemberType mt; SeekType(FAMI, mt, ptr); switch(mt){ case TYPE_BAREBODY: case TYPE_DISPLAY: case TYPE_T3CP_LIST: { break; } case TYPE_T3CP: { iMainImage->Index = 2; // Undo->SetLayerOrder(); ((T3CP *)ptr)->Activate(); // ((T3CP *)ptr)->ColorMask->Copy(iMainImage->uBitmap, SRCCOPY); iMainImage->uBitmap->CopyToTexpia(((T3CP *)ptr)->ColorMask, 0, 0, ((T3CP *)ptr)->ColorMask->Width, ((T3CP *)ptr)->ColorMask-> Height, 0, 0, SRCCOPY); // convert by celberus ((T3CP *)ptr)->Mask->Copy(iMainImage->LayerMask, SRCCOPY); break; } default: break; } DWORD dwWrite; TPException ec = EC_NONE; TRect src; src.Left = 0; src.Top = 0; src.Right = Width; src.Bottom = Height; TTexpiaBitmap *tag = NULL; TTexpiaBitmap *tb = NULL; HDC dcTmp=NULL; WORD bpp; int CountOf3CP; if(ListOf3CP) CountOf3CP=ListOf3CP->Count; else CountOf3CP=0; ///////////////////////////////// Start of Standard Tag Format if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } //if ((tb = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } //tb->Create(Width,Height,24); //if ((dcTmp = tb->CreateDC()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } //iMainImage->FullViewPaint(dcTmp, 1, 1); //tb->DeleteDC(dcTmp); dcTmp = NULL; //iMainImage->Index = 1; //MakeTexpiaTag(tag, tb, src, 0); ub = iMainImage->Composition(); MakeTexpiaTag(tag, ub, src, 0); delete ub; if (!WriteFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwWrite, NULL)) { END_LOG; return false; } WORD useColor; if (!WriteFile(fh, &useColor, sizeof(WORD), &dwWrite, NULL)) { END_LOG; return false; } pPalette->UseColor = useColor; pPalette->SaveToFileHandle(fh, 2); bpp = tag->BitsPerPixel; if (!WriteFile(fh, &bpp, sizeof(WORD), &dwWrite, NULL)) { END_LOG; return false; } if (!tag->SaveToTexpiaFile(fh, cmNone)) { END_LOG; return false; } delete tag; //delete tb; ///////////////////////////////// End of Standard Tag Format if(!WriteFile(fh, &Version, sizeof(int), &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } if(Version>=3){ if(!WriteFile(fh, &GridColor, sizeof(TColor), &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } } if(Version>=4){ if(!WriteFile(fh, &GridFocusColor, sizeof(TColor), &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } } iMainImage->SaveToLayerFile(fh, tpfh.Version.Number); if(Version>=1){ if(!WriteFile(fh, &CountOf3CP, sizeof(int), &dwWrite, NULL)) { ec = EC_FILE_NOT_WRITE; SAVE_EXCEPTION(ec); goto fail; } if(ListOf3CP){ for(int i=0;iItems[i]; bool active = t3cp->Activated; t3cp->Activate(); t3cp->SaveToFile(fh, tpfh); if(!active) t3cp->Deactivate(); } } } END_LOG; return EC_NONE; fail: if(tag) delete tag; if(tb) delete tb; if (fh!=INVALID_HANDLE_VALUE) CloseHandle(fh); END_LOG; return ec; } //--------------------------------------------------------------------------- void __fastcall TN3D::PaintN3DGrid(TObject *Sender, HDC dc){ if(NotPaintN3DGrid) return; BEGIN_LOG("Data3D2"); TN3DMemberType mt; LPVOID ptr=NULL; SeekType(FAMI, mt, ptr); if(mt==TYPE_T3CP){ T3CP *t3cp = (T3CP *)ptr; t3cp->Paint3CPGrid(Sender, dc, GridColor, GridFocusColor); } END_LOG; } //--------------------------------------------------------------------------- int __fastcall TN3D::GetAMI(){ return FAMI; } //--------------------------------------------------------------------------- void __fastcall TN3D::SetAMI(int i){ BEGIN_LOG("Data3D2"); LPVOID ptr=NULL; TN3DMemberType mt; SeekType(FAMI, mt, ptr); switch(mt){ case TYPE_BAREBODY: case TYPE_DISPLAY: case TYPE_T3CP_LIST: { break; } case TYPE_T3CP: { iMainImage->Index = 2; // Undo->SetLayerOrder(); ((T3CP *)ptr)->Activate(); // ((T3CP *)ptr)->ColorMask->Copy(iMainImage->uBitmap, SRCCOPY); iMainImage->uBitmap->CopyToTexpia(((T3CP *)ptr)->ColorMask, 0, 0, ((T3CP *)ptr)->ColorMask->Width, ((T3CP *)ptr)->ColorMask-> Height, 0, 0, SRCCOPY); // convert by celberus ((T3CP *)ptr)->Mask->Copy(iMainImage->LayerMask, SRCCOPY); break; } default: break; } if(SeekType(i, mt, ptr)){ FAMI = i; } else { FAMI = 0; mt = TYPE_BAREBODY; } switch(mt){ // TYPE_BAREBODY¿Í TYPE_DISPLAY´Â Á¤ÇØÁø °ªÀ¸·Î visibleÀ» ¹Ù²Ù°í // TYPE_T3CPÀº ´Ù¸¥ °÷¿¡¼­ ¶§¿¡µû¶ó visibleÀ» ¹Ù²Û´Ù case TYPE_BAREBODY: { iMainImage->StartLayerVisibleChange(2, false); iMainImage->StartLayerVisibleChange(1, false); iMainImage->EndOfLayerVisibleChange(0, true); // Undo->SetLayerOrder(); for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; t3cp->Deactivate(); } break; } case TYPE_DISPLAY: { iMainImage->StartLayerVisibleChange(0, true); iMainImage->StartLayerVisibleChange(2, false); iMainImage->EndOfLayerVisibleChange(1, true); // Undo->SetLayerOrder(); for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; t3cp->Deactivate(); } break; } case TYPE_T3CP_LIST: { for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; t3cp->Deactivate(); } break; } case TYPE_T3CP:// ¿©±â¼­´Â visible change°¡ ¾ø´Ù { for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; if(t3cp!=(T3CP *)ptr) t3cp->Deactivate(); else t3cp->Activate(); } iMainImage->Index = 2; // Undo->SetLayerOrder(); iMainImage->uBitmap->Copy(((T3CP *)ptr)->ColorMask, SRCCOPY); iMainImage->LayerMask->Copy(((T3CP *)ptr)->Mask, SRCCOPY); break; } default: break; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TN3D::MouseMove(TShiftState Shift, int X, int Y){ TN3DMemberType mt; LPVOID ptr=NULL; SeekType(FAMI, mt, ptr); if(mt==TYPE_T3CP){ ((T3CP *)ptr)->MouseMove(iMainImage, Shift, X, Y); } } //--------------------------------------------------------------------------- void __fastcall TN3D::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y){ TN3DMemberType mt; LPVOID ptr=NULL; SeekType(FAMI, mt, ptr); if(mt==TYPE_T3CP){ ((T3CP *)ptr)->MouseDown(iMainImage, Button, Shift, X, Y); } } //--------------------------------------------------------------------------- void __fastcall TN3D::MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y){ TN3DMemberType mt; LPVOID ptr=NULL; SeekType(FAMI, mt, ptr); if(mt==TYPE_T3CP){ ((T3CP *)ptr)->MouseUp(iMainImage, Button, Shift, X, Y); } } //--------------------------------------------------------------------------- void __fastcall TN3D::Rendering(){ BEGIN_LOG("Data3D2"); int cnt=0; bool renderingAll = true; TN3DMemberType mt; LPVOID ptr=NULL; SeekType(FAMI, mt, ptr); if(mt==TYPE_T3CP){ renderingAll = false; } TUnionBitmap *barebody = NULL; // convert by celberus RECT r = Rect(0,0,Width,Height); int ami = FAMI; barebody = new TUnionBitmap; // convert by celberus barebody->Create(Width, Height, 24); AMI = 0; barebody->Copy(iMainImage->uBitmap, SRCCOPY); // iMainImage->uBitmap->CopyToTexpia(barebody, 0, 0, // barebody->Width, barebody-> Height, 0, 0, SRCCOPY); // convert by celberus AMI = 1; iMainImage->uBitmap->Copy(barebody, SRCCOPY); iMainImage->LayerMask->FillRect(r, 0); if (!iMainImage->uBitmap->StartScanLine()) goto fail; for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; cnt+=t3cp->ListOfData3D2->Count; } StatusProgress->Maximum = (ListOf3CP->Count+cnt)*100; for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; if( renderingAll==true || t3cp==(T3CP *)ptr ) { t3cp->Display->Copy(barebody, SRCCOPY); } if(!t3cp->Skip) { bool active = t3cp->Activated; t3cp->Activate(); t3cp->Rendering(iMainImage->uBitmap, ( renderingAll==false && t3cp!=(T3CP *)ptr ) ); // convert by celberus if(!active) t3cp->Deactivate(); } } StatusProgress->End(); iMainImage->uBitmap->StopScanLine(); delete barebody; END_LOG; //AMI = ami; return; fail: //AMI = ami; END_LOG; return; } //--------------------------------------------------------------------------- void __fastcall TN3D::ChangePen(TGridPenState gps, int param1){ TN3DMemberType mt; LPVOID ptr=NULL; SeekType(FAMI, mt, ptr); if(mt==TYPE_T3CP){ ((T3CP *)ptr)->GridPenState = gps; ((T3CP *)ptr)->Param1 = param1; } } //--------------------------------------------------------------------------- bool __fastcall TN3D::SeekType(int step, TN3DMemberType &mt, LPVOID &ptr){ BEGIN_LOG("Data3D2"); if(step--==0){ mt = TYPE_BAREBODY; ptr = NULL; END_LOG; return true; } else if(step--==0){ mt = TYPE_DISPLAY; ptr = NULL; END_LOG; return true; } else if(step--==0){ mt = TYPE_T3CP_LIST; ptr = ListOf3CP; END_LOG; return true; } else { if(ListOf3CP->Count){ for(int i=0;iCount;i++){ T3CP *t3cp = (T3CP *)ListOf3CP->Items[i]; if(step--==0){ mt = TYPE_T3CP; ptr = t3cp; END_LOG; return true; } if(t3cp->SeekType(step, mt, ptr)){ END_LOG; return true; } } } } mt = TYPE_NONE; ptr = NULL; END_LOG; return false; // °ªÀ» ¸øÃ£À¸¸é false // Á¦´ë·Î ãÀ¸¸é true } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- __fastcall undodata::undodata(String d){ dir=d; udata = CreateFile( (dir+"//temp.und").c_str() , GENERIC_WRITE|GENERIC_READ , 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rdata = CreateFile( (dir+"//temp.rnd").c_str() , GENERIC_WRITE|GENERIC_READ , 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); uindex = new TList; rindex = new TList; oldt3cp=NULL; } //--------------------------------------------------------------------------- __fastcall undodata::~undodata(){ CloseHandle(udata); CloseHandle(rdata); DeleteFile((dir+"//temp.und").c_str()); DeleteFile((dir+"//temp.rnd").c_str()); while(uindex->Count){ delete (DWORD *)uindex->Last(); uindex->Remove(uindex->Last()); } while(rindex->Count){ delete (DWORD *)rindex->Last(); rindex->Remove(rindex->Last()); } delete uindex; uindex=NULL; delete rindex; rindex=NULL; } //--------------------------------------------------------------------------- void __fastcall undodata::reset(){ BEGIN_LOG("Data3D2"); CloseHandle(udata); CloseHandle(rdata); udata = CreateFile( (dir+"//temp.und").c_str() , GENERIC_WRITE|GENERIC_READ , 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rdata = CreateFile( (dir+"//temp.rnd").c_str() , GENERIC_WRITE|GENERIC_READ , 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); while(uindex->Count){ delete (DWORD *)uindex->Last(); uindex->Remove(uindex->Last()); } while(rindex->Count){ delete (DWORD *)rindex->Last(); rindex->Remove(rindex->Last()); } END_LOG; } //--------------------------------------------------------------------------- bool __fastcall undodata::canundo(T3CP *t3cp){ return (t3cp==oldt3cp)&&(uindex->Count!=0); } //--------------------------------------------------------------------------- bool __fastcall undodata::canredo(T3CP *t3cp){ return (t3cp==oldt3cp)&&(rindex->Count!=0); } //--------------------------------------------------------------------------- void __fastcall undodata::do_(T3CP *t3cp){ //do_´Â actionÀü¿¡ ½ÇÇàÇÑ´Ù BEGIN_LOG("Data3D2"); if(t3cp!=oldt3cp){ reset(); oldt3cp=t3cp; } TEXPIAFILEHEADER tpfh; tpfh.Compress = cmNone; DWORD *p = new DWORD; *p = GetFileSize (udata, NULL); uindex->Add(p); t3cp->SaveData3D2File(udata,tpfh); CloseHandle(rdata); rdata = CreateFile( (dir+"//temp.rnd").c_str() , GENERIC_WRITE|GENERIC_READ , 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); while(rindex->Count){ delete (DWORD *)rindex->Last(); rindex->Remove(rindex->Last()); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall undodata::undo(T3CP *t3cp){ BEGIN_LOG("Data3D2"); TEXPIAFILEHEADER tpfh; tpfh.Compress = cmNone; if(canundo(t3cp)){ DWORD *pr = new DWORD; *pr = GetFileSize (rdata, NULL); rindex->Add(pr); t3cp->SaveData3D2File(rdata,tpfh); DWORD *p = (DWORD *)uindex->Last(); SetFilePointer (udata, *p, NULL, FILE_BEGIN); t3cp->ReadData3D2File(udata,tpfh); uindex->Remove(uindex->Last()); SetFilePointer (udata, *p, NULL, FILE_BEGIN); SetEndOfFile(udata); delete p; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall undodata::redo(T3CP *t3cp){ BEGIN_LOG("Data3D2"); TEXPIAFILEHEADER tpfh; tpfh.Compress = cmNone; if(canredo(t3cp)){ DWORD *pu = new DWORD; *pu = GetFileSize (udata, NULL); uindex->Add(pu); t3cp->SaveData3D2File(udata,tpfh); DWORD *p = (DWORD *)rindex->Last(); SetFilePointer (rdata, *p, NULL, FILE_BEGIN); t3cp->ReadData3D2File(rdata,tpfh); rindex->Remove(rindex->Last()); SetFilePointer (rdata, *p, NULL, FILE_BEGIN); SetEndOfFile(rdata); delete p; } END_LOG; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- __fastcall PatternGroup::PatternGroup() { Version = PATTERN_FILE_VERSION; XRatio = 100; YRatio = 100; Pattern = NULL;//new TTexpiaBitmap; Palette = NULL; pal_exist = false; transparentPattern = false; mappingcolor = clWhite; } //--------------------------------------------------------------------------- __fastcall PatternGroup::~PatternGroup(){ if(Palette) delete Palette; if(Pattern) delete Pattern; } //--------------------------------------------------------------------------- bool __fastcall PatternGroup::SaveToFile(HANDLE fh){ BEGIN_LOG("Data3D2"); DWORD dwWrite; if(!WriteFile(fh, &Version, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(Version>=1){ if(!WriteFile(fh, &XRatio, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &YRatio, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &mappingcolor, sizeof(TColor), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &pal_exist, sizeof(bool), &dwWrite, NULL)) { END_LOG; return false; } if(pal_exist){ Palette->SaveToFileHandle(fh, 2); } if(!WriteFile(fh, &transparentPattern, sizeof(bool), &dwWrite, NULL)) { END_LOG; return false; } if(Pattern){ int w = Pattern->Width, h = Pattern->Height, bpp = Pattern->BitsPerPixel; if(!WriteFile(fh, &w, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &h, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &bpp, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } Pattern->SaveToTexpiaFile(fh, cmZLib); } else { int w = 0, h = 0, bpp = 0; if(!WriteFile(fh, &w, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &h, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } if(!WriteFile(fh, &bpp, sizeof(int), &dwWrite, NULL)) { END_LOG; return false; } } } END_LOG; return true; } //--------------------------------------------------------------------------- bool __fastcall PatternGroup::ReadFromFile(HANDLE fh){ BEGIN_LOG("Data3D2"); DWORD dwRead; if(!ReadFile(fh, &Version, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(Version>=1){ if(!ReadFile(fh, &XRatio, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &YRatio, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &mappingcolor, sizeof(TColor), &dwRead, NULL)) { END_LOG; return false; } if(Version==2) { if(!SetFilePointer(fh, sizeof(bool), NULL , FILE_CURRENT)) { END_LOG; return false; }//Solid ¸¸µé¾ú´Ù°¡ version 3¿¡¼­ Á¦°Å } if(Version>=4) { if(!ReadFile(fh, &pal_exist, sizeof(bool), &dwRead, NULL)) { END_LOG; return false; } if(pal_exist){ Palette = new TPalette; if(Version <= 6){ Palette->LoadFromFileHandle(fh, 1); } else { Palette->LoadFromFileHandle(fh, 2); } } } if(Version>=5) { if(!ReadFile(fh, &transparentPattern, sizeof(bool), &dwRead, NULL)) { END_LOG; return false; } } int w,h,bpp=24; if(!ReadFile(fh, &w, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(!ReadFile(fh, &h, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(Version>=6) if(!ReadFile(fh, &bpp, sizeof(int), &dwRead, NULL)) { END_LOG; return false; } if(w!=0&&h!=0){ if(Pattern==NULL) Pattern = new TTexpiaBitmap; if(bpp==8){ RGBQUAD rgb[256]; if(Palette) Palette->ToRGBQUAD(rgb, 256); Pattern->Create(w, h, bpp, rgb); } else { Pattern->Create(w, h, bpp); } Pattern->LoadFromTexpiaFile(fh, cmZLib); } } Version = PATTERN_FILE_VERSION; END_LOG; return true; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //---------------------------------------------------------------------------