00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 static void DeleteAllPath(void){
00027 if(Np > 0 && pathlist != NULL){
00028 int i,n;
00029 PATHPOINT *pp;
00030 for(i=0;i<Np;i++){
00031 if((n=pathlist[i].n) > 0 && (pp=pathlist[i].pts) != NULL){
00032 X__Free(pp);
00033 }
00034 }
00035 X__Free(pathlist);
00036 Np=0; pathlist=NULL;
00037 Lp= -1; Lpp= -1;
00038 }
00039 }
00040
00041 static void DeleteOnePath(int id){
00042 int i,n;
00043 PATHPOINT *pp;
00044 if(Np < 2){
00045 DeleteAllPath();
00046 return;
00047 }
00048 if((n=pathlist[id].n) > 0 && (pp=pathlist[id].pts) != NULL){
00049 X__Free(pp);
00050 }
00051 if(Lp < Np-1){
00052 for(i=Lp;i<Np-1;i++){
00053 memcpy((pathlist + i),(pathlist + i+1),sizeof(PTH));
00054 }
00055 }
00056 Np--;
00057 pathlist=(PTH *)X__Realloc(pathlist,sizeof(PTH)*Np);
00058 if(pathlist == NULL){
00059 Np=0; MessageBeep(MB_OK);
00060 }
00061 Lp= -1; Lpp= -1;
00062 return;
00063 }
00064
00065 static void DeletePathVertex(void){
00066 int i;
00067 PTH *pth;
00068 PATHPOINT *temp;
00069 pth=(pathlist + Lp);
00070 if(pth->n == 1){
00071 DeleteOnePath(Lp);
00072 return;
00073 }
00074 if(Lpp == 0 || Lpp == pth->n - 1)pth->closed=0;
00075 if(Lpp < pth->n - 1){
00076 for(i=Lpp;i<pth->n - 1;i++){
00077 memcpy((pth->pts + i),(pth->pts + i+1),sizeof(PATHPOINT));
00078 }
00079 }
00080 (pth->n)--;
00081 pth->pts=(PATHPOINT *)X__Realloc(pth->pts,sizeof(PATHPOINT)*pth->n);
00082 if(pth->pts == NULL){
00083 pth->n=0; MessageBeep(MB_OK);
00084 }
00085 Lp= -1; Lpp= -1;
00086 }
00087
00088 static int CreatePath(void){
00089 PTH *temp;
00090 if(pathlist == NULL){
00091 if((pathlist=(PTH *)X__Malloc(sizeof(PTH))) == NULL)return -1;
00092 }
00093 else{
00094 if((temp=(PTH *)X__Realloc(pathlist,sizeof(PTH)*(Np+1))) == NULL)
00095 return Np-1;
00096 pathlist=temp;
00097 }
00098 pathlist[Np].pts=NULL;
00099 pathlist[Np].n=0;
00100 pathlist[Np].closed=0;
00101 Np++;
00102 return Np-1;
00103 }
00104
00105 static int CreatePathPoint(int pa,int x, int y){
00106 PATHPOINT *temp;
00107 if(pa < 0)return -1;
00108 if(pathlist[pa].pts == NULL){
00109 if((pathlist[pa].pts=(PATHPOINT *)X__Malloc(sizeof(PATHPOINT))) == NULL)
00110 return -1;
00111 }
00112 else{
00113 if((temp=(PATHPOINT *)X__Realloc(pathlist[pa].pts,
00114 sizeof(PATHPOINT)*(pathlist[pa].n+1))) == NULL)return pathlist[pa].n;
00115 pathlist[pa].pts=temp;
00116 }
00117 pathlist[pa].pts[pathlist[pa].n].p.x=x;
00118 pathlist[pa].pts[pathlist[pa].n].p.y=y;
00119 pathlist[pa].pts[pathlist[pa].n].type=0;
00120 pathlist[pa].pts[pathlist[pa].n].hand=0;
00121 pathlist[pa].pts[pathlist[pa].n].bent=0;
00122 pathlist[pa].n++;
00123 return pathlist[pa].n - 1;
00124 }
00125
00126 static void GetXtraPoints(int w, PATHPOINT *pp, PATHPOINT *pp1,
00127 long *xr, long *yr){
00128 double x0,x1,x2,x3,b,c,cc,bb;
00129 if(w == 1){
00130 x0=(double)(pp->p.x); x1=(double)(pp->p1.x);
00131 x2=(double)(pp1->p2.x); x3=(double)(pp1->p.x);
00132 }
00133 else{
00134 x0=(double)(pp->p.x); x1=(double)(pp->p2.x);
00135 x2=(double)(pp1->p1.x); x3=(double)(pp1->p.x);
00136 }
00137 c=3.0*(x1-x0);
00138 b=3.0*(x2-2.0*x1+x0);
00139 bb=b/4.0;
00140 cc=c*0.5; x1=x0+cc/3.0;
00141 *xr = (long)(bb/3.0+2.0*x1-x0);
00142 if(w == 1){
00143 x0=(double)(pp->p.y); x1=(double)(pp->p1.y);
00144 x2=(double)(pp1->p2.y); x3=(double)(pp1->p.y);
00145 }
00146 else{
00147 x0=(double)(pp->p.y); x1=(double)(pp->p2.y);
00148 x2=(double)(pp1->p1.y); x3=(double)(pp1->p.y);
00149 }
00150 c=3.0*(x1-x0);
00151 b=3.0*(x2-2.0*x1+x0);
00152 bb=b/4.0;
00153 cc=c*0.5; x1=x0+cc/3.0;
00154 *yr = (long)(bb/3.0+2.0*x1-x0);
00155 }
00156
00157 static void InsertVertex(void){
00158 BOOL bInsert;
00159 int i,bCurve=0;
00160 PTH *pth;
00161 PATHPOINT *pp,*pp1;
00162 long x,y,x1,y1,x2,y2;
00163 pth=(pathlist + Lp);
00164 if(Lpp < pth->n - 1)bInsert=TRUE; else bInsert=FALSE;
00165 if(CreatePathPoint(Lp,0,0) < 0)return;
00166 pth=(pathlist + Lp);
00167 if(bInsert){
00168 pp1=(pth->pts + Lpp+1); pp=(pth->pts + Lpp);
00169 if(pp1->type == 1 || pp->type == 1){
00170 GetBezierPoint(0.5,pp,pp1,&x,&y);
00171 if(pp->type == 0){
00172 int dx,dy;
00173 dx=pp1->p2.x - pp->p.x;
00174 dy=pp1->p2.y - pp->p.y;
00175 pp->p1.x=(double)pp->p.x + 0.05*dx;
00176 pp->p1.y=(double)pp->p.y + 0.05*dy;
00177 }
00178 if(pp1->type == 0){
00179 int dx,dy;
00180 dx=pp->p1.x - pp1->p.x;
00181 dy=pp->p1.y - pp1->p.y;
00182 pp1->p2.x=(double)pp1->p.x + 0.05*dx;
00183 pp1->p2.y=(double)pp1->p.y + 0.05*dy;
00184 }
00185 GetXtraPoints(1,pp,pp1,&x1,&y1);
00186 GetXtraPoints(2,pp1,pp,&x2,&y2);
00187 pp1->p2.x = pp1->p.x + (pp1->p2.x - pp1->p.x)/2;
00188 pp1->p2.y = pp1->p.y + (pp1->p2.y - pp1->p.y)/2;
00189 pp->p1.x = pp->p.x + (pp->p1.x - pp->p.x)/2;
00190 pp->p1.y = pp->p.y + (pp->p1.y - pp->p.y)/2;
00191 bCurve=1;
00192 }
00193 else{
00194 x=(pp1->p.x + pp->p.x)/2;
00195 y=(pp1->p.y + pp->p.y)/2;
00196 }
00197 for(i=pth->n - 1;i > Lpp; i--){
00198 memcpy((pth->pts + i),(pth->pts + i-1),sizeof(PATHPOINT));
00199 }
00200 }
00201 else{
00202 pp1=(pth->pts); pp=(pth->pts + Lpp);
00203 if(pp1->type == 1 || pp->type == 1){
00204 GetBezierPoint(0.5,pp,pp1,&x,&y);
00205 if(pp->type == 0){
00206 int dx,dy;
00207 dx=pp1->p2.x - pp->p.x;
00208 dy=pp1->p2.y - pp->p.y;
00209 pp->p1.x=(double)pp->p.x + 0.05*dx;
00210 pp->p1.y=(double)pp->p.y + 0.05*dy;
00211 }
00212 if(pp1->type == 0){
00213 int dx,dy;
00214 dx=pp->p1.x - pp1->p.x;
00215 dy=pp->p1.y - pp1->p.y;
00216 pp1->p2.x=(double)pp1->p.x + 0.05*dx;
00217 pp1->p2.y=(double)pp1->p.y + 0.05*dy;
00218 }
00219 GetXtraPoints(1,pp,pp1,&x1,&y1);
00220 GetXtraPoints(2,pp1,pp,&x2,&y2);
00221 pp1->p2.x = pp1->p.x + (pp1->p2.x - pp1->p.x)/2;
00222 pp1->p2.y = pp1->p.y + (pp1->p2.y - pp1->p.y)/2;
00223 pp->p1.x = pp->p.x + (pp->p1.x - pp->p.x)/2;
00224 pp->p1.y = pp->p.y + (pp->p1.y - pp->p.y)/2;
00225 bCurve=1;
00226 }
00227 else {
00228 x=(pp1->p.x + pp->p.x)/2;
00229 y=(pp1->p.y + pp->p.y)/2;
00230 }
00231 }
00232 ((pth->pts)+Lpp+1)->p.x=x;
00233 ((pth->pts)+Lpp+1)->p.y=y;
00234 ((pth->pts)+Lpp+1)->type=bCurve;
00235 if(bCurve){
00236 ((pth->pts)+Lpp+1)->p2.x=x1;
00237 ((pth->pts)+Lpp+1)->p2.y=y1;
00238 ((pth->pts)+Lpp+1)->p1.x=x2;
00239 ((pth->pts)+Lpp+1)->p1.y=y2;
00240 }
00241 ((pth->pts)+Lpp+1)->hand=0;
00242 ((pth->pts)+Lpp+1)->bent=0;
00243 }
00244
00245 static double Cubic(double t, double x0, double x1, double x2, double x3){
00246 double a,b,c;
00247 c=3.0*(x1-x0);
00248 b=3.0*(x2-2.0*x1+x0);
00249 a=3.0*(x1-x2)+x3-x0;
00250 return x0+t*(t*(t*a+b)+c);
00251 }
00252
00253 static void DrawBezierCurve(HDC hDC, PATHPOINT *pl, PATHPOINT *p){
00254 double t,dt,x,y,x0,x1,x2,x3,y0,y1,y2,y3,dx,dy;
00255 x0=pl->p.x; y0=pl->p.y;
00256 if(pl->type == 0){
00257 dx=p->p2.x - pl->p.x;
00258 dy=p->p2.y - pl->p.y;
00259 x1=(double)pl->p.x + 0.05*dx;
00260 y1=(double)pl->p.y + 0.05*dy;
00261 }
00262 else{x1=pl->p1.x; y1=pl->p1.y;}
00263 if(p->type == 0){
00264 dx=p->p.x - pl->p1.x;
00265 dy=p->p.y - pl->p1.y;
00266 x2=(double)p->p.x - 0.05*dx;
00267 y2=(double)p->p.y - 0.05*dy;
00268 }
00269 else{x2=p->p2.x; y2=p->p2.y;}
00270 x3=p->p.x; y3=p->p.y;
00271 dt=0.05;
00272 MoveToEx(hDC,(int)x0-WoffX,(int)y0-WoffY,NULL);
00273 for(t=dt;t<1.0+dt;t+=dt){
00274 x=Cubic(t,x0,x1,x2,x3);
00275 y=Cubic(t,y0,y1,y2,y3);
00276 LineTo(hDC,(int)x-WoffX,(int)y-WoffY);
00277 }
00278 }
00279
00280 static void GetBezierPoint(double t, PATHPOINT *pl, PATHPOINT *p,
00281 long *xp, long *yp){
00282 double x,y,x0,x1,x2,x3,y0,y1,y2,y3,dx,dy;
00283 x0=pl->p.x; y0=pl->p.y;
00284 if(pl->type == 0){
00285 dx=p->p2.x - pl->p.x;
00286 dy=p->p2.y - pl->p.y;
00287 x1=(double)pl->p.x + 0.05*dx;
00288 y1=(double)pl->p.y + 0.05*dy;
00289 }
00290 else{x1=pl->p1.x; y1=pl->p1.y;}
00291 if(p->type == 0){
00292 dx=p->p.x - pl->p1.x;
00293 dy=p->p.y - pl->p1.y;
00294 x2=(double)p->p.x - 0.05*dx;
00295 y2=(double)p->p.y - 0.05*dy;
00296 }
00297 else{x2=p->p2.x; y2=p->p2.y;}
00298 x3=p->p.x; y3=p->p.y;
00299 *xp=(long)Cubic(t,x0,x1,x2,x3);
00300 *yp=(long)Cubic(t,y0,y1,y2,y3);
00301 }
00302
00303 static void DrawFromPathPoint(BOOL closed, int p,int pp, POINT *pt,
00304 HWND hwnd, HDC hdc){
00305 HPEN hOldPen;
00306 HBRUSH hOldBrush;
00307 int oldROP;
00308 HDC hDClocal;
00309 PATHPOINT *ppt,Pp,*lpPp;
00310 if(p < 0 || pp < 0)return;
00311 ppt=(pathlist[p].pts + pp);
00312 if(hdc == NULL)hDClocal=GetDC(hwnd);
00313 else hDClocal=hdc;
00314 hOldPen=SelectObject(hDClocal,GetStockObject(WHITE_PEN));
00315 hOldBrush=SelectObject(hDClocal,GetStockObject(WHITE_BRUSH));
00316 oldROP=SetROP2(hDClocal,R2_XORPEN);
00317 if(ppt->type == 1 || (closed && pathlist[p].pts->type == 1)){
00318 lpPp=&Pp;
00319 if(closed){
00320 lpPp->type=pathlist[p].pts->type;
00321 lpPp->p1.x=pathlist[p].pts->p1.x;
00322 lpPp->p1.y=pathlist[p].pts->p1.y;
00323 lpPp->p2.x=pathlist[p].pts->p2.x;
00324 lpPp->p2.y=pathlist[p].pts->p2.y;
00325 lpPp->p.x=pathlist[p].pts->p.x;
00326 lpPp->p.y=pathlist[p].pts->p.y;
00327 }
00328 else{
00329 lpPp->type=0;
00330 lpPp->p.x=pt->x; lpPp->p.y=pt->y;
00331 }
00332 DrawBezierCurve(hDClocal,ppt,lpPp);
00333 }
00334 else{
00335 MoveToEx(hDClocal,ppt->p.x-WoffX,ppt->p.y-WoffY,NULL);
00336 if(closed)LineTo(hDClocal,pathlist[p].pts->p.x-WoffX,
00337 pathlist[p].pts->p.y-WoffY);
00338 else LineTo(hDClocal,pt->x-WoffX,pt->y-WoffY);
00339 }
00340 if(!closed)Rectangle(hDClocal,pt->x-2-WoffX,pt->y-2-WoffY,
00341 pt->x+3-WoffX,pt->y+3-WoffY);
00342 SetROP2(hDClocal,oldROP);
00343 SelectObject(hDClocal,hOldPen);
00344 SelectObject(hDClocal,hOldBrush);
00345 if(hdc == NULL)ReleaseDC(hwnd,hDClocal);
00346 }
00347
00348 static void DrawPathPoint(int p, int pp, HWND hwnd, HDC hdc){
00349 HPEN hOldPen;
00350 HBRUSH hOldBrush;
00351 int oldROP;
00352 HDC hDClocal;
00353 PATHPOINT *ppt,*ppt1;
00354 int x1,y1,x2,y2,n;
00355 if(p < 0 || pp < 0)return;
00356 n=pathlist[p].n;
00357 if(pp > n)return;
00358 if(pp == n){
00359 if(pathlist[p].closed == 0)return;
00360 pp=0;
00361 }
00362 ppt=(pathlist[p].pts + pp);
00363 x2=ppt->p.x; y2=ppt->p.y;
00364 if(pp > 0){
00365 ppt1=(ppt-1);
00366 x1=ppt1->p.x; y1=ppt1->p.y;
00367 }
00368 else{
00369 if(pathlist[p].closed){
00370 ppt1=(ppt+(n-1));
00371 x1=ppt1->p.x; y1=ppt1->p.y;
00372 }
00373 else{
00374 ppt1=NULL;
00375 x1=x2; y1=y2;
00376 }
00377 }
00378 if(hdc == NULL)hDClocal=GetDC(hwnd);
00379 else hDClocal=hdc;
00380 hOldPen=SelectObject(hDClocal,GetStockObject(WHITE_PEN));
00381 hOldBrush=SelectObject(hDClocal,GetStockObject(BLACK_BRUSH));
00382 oldROP=SetROP2(hDClocal,R2_XORPEN);
00383 if(ppt1 != NULL && (ppt->type == 1 || ppt1->type == 1))
00384 DrawBezierCurve(hDClocal,ppt1,ppt);
00385 else{
00386 MoveToEx(hDClocal,x1-WoffX,y1-WoffY,NULL);
00387 LineTo(hDClocal,x2-WoffX,y2-WoffY);
00388 }
00389 Rectangle(hDClocal,x2-2-WoffX,y2-2-WoffY,
00390 x2+3-WoffX,y2+3-WoffY);
00391 if(ppt->hand == 1 && ppt->type == 1){
00392 int n;
00393 if(pp < pathlist[p].n - 1 || pathlist[p].closed || tracetool == 1){
00394 MoveToEx(hDClocal,ppt->p1.x-WoffX,ppt->p1.y-WoffY,NULL);
00395 Rectangle(hDClocal,ppt->p1.x-1-WoffX,ppt->p1.y-1-WoffY,
00396 ppt->p1.x+2-WoffX,ppt->p1.y+2-WoffY);
00397 LineTo(hDClocal,x2-WoffX,y2-WoffY);
00398 }
00399 if(pp > 0 || pathlist[p].closed){
00400 MoveToEx(hDClocal,x2-WoffX,y2-WoffY,NULL);
00401 LineTo(hDClocal,ppt->p2.x-WoffX,ppt->p2.y-WoffY);
00402 Rectangle(hDClocal,ppt->p2.x-1-WoffX,ppt->p2.y-1-WoffY,
00403 ppt->p2.x+2-WoffX,ppt->p2.y+2-WoffY);
00404 }
00405 }
00406 SetROP2(hDClocal,oldROP);
00407 SelectObject(hDClocal,hOldPen);
00408 SelectObject(hDClocal,hOldBrush);
00409 if(hdc == NULL)ReleaseDC(hwnd,hDClocal);
00410 }
00411
00412 static void MoveWholePath(int x, int y, HWND hWnd){
00413 PATHPOINT *pp;
00414 int j,n,dx,dy;
00415 if(Lp < 0 || Lpp < 0)return;
00416 pp=((pathlist + Lp)->pts + Lpp);
00417 n=(pathlist + Lp)->n;
00418 dx = x - pp->p.x; dy = y - pp->p.y;
00419 for(j=0;j<n;j++)DrawPathPoint(Lp,j,hWnd,NULL);
00420 pp=(pathlist + Lp)->pts;
00421 for(j=0;j<n;j++){
00422 pp->p.x += dx; pp->p1.x += dx; pp->p2.x += dx;
00423 pp->p.y += dy; pp->p1.y += dy; pp->p2.y += dy;
00424 pp++;
00425 }
00426 for(j=0;j<n;j++)DrawPathPoint(Lp,j,hWnd,NULL);
00427 }
00428
00429 static void BuildBezierCurve(PATHPOINT *pl, PATHPOINT *p,
00430 long Scale, BOOL fv){
00431 int flag=0;
00432 long i,n;
00433 double t,dt,dts,x,y,x0,x1,x2,x3,y0,y1,y2,y3,dx,dy;
00434 x0=pl->p.x; y0=pl->p.y;
00435 if(pl->type == 0){
00436 dx=p->p2.x - pl->p.x;
00437 dy=p->p2.y - pl->p.y;
00438 x1=(double)pl->p.x + 0.05*dx;
00439 y1=(double)pl->p.y + 0.05*dy;
00440 flag=1;
00441 }
00442 else{x1=pl->p1.x; y1=pl->p1.y;}
00443 if(p->type == 0){
00444 dx=p->p.x - pl->p1.x;
00445 dy=p->p.y - pl->p1.y;
00446 x2=(double)p->p.x - 0.05*dx;
00447 y2=(double)p->p.y - 0.05*dy;
00448 flag=2;
00449 }
00450 else{x2=p->p2.x; y2=p->p2.y;}
00451 x3=p->p.x; y3=p->p.y;
00452 n=10;
00453 dt=1.0/(double)n;
00454 if(flag == 1){
00455 dts=2*dt;
00456 dt=(1.0-dts)/(double)(n-1);
00457 }
00458 else if(flag == 2){
00459 dt=(1.0-2.0*dt)/(double)(n-1);
00460 dts=dt;
00461 }
00462 else dts=dt;
00463 if(fv)n--;
00464 UpdateVertexHeap(Nvert+n);
00465 UpdateEdgeHeap(Nedge+n);
00466 for(i=0,t=dts;i<n;i++,t+=dt){
00467 if(!fv && i == n-1)t=1.0;
00468 x=Cubic(t,x0,x1,x2,x3);
00469 y=Cubic(t,y0,y1,y2,y3);
00470 CreateVertex();
00471 (MainVp+Nvert-1)->xyz[0]=(x-PAGESIZE/2)*Scale;
00472 (MainVp+Nvert-1)->xyz[1]=NpointerY;
00473 (MainVp+Nvert-1)->xyz[2]=(PAGESIZE/2-y)*Scale;
00474 CreateEdge(Nvert-1,Nvert-2);
00475 }
00476 }
00477
00478 static void BuildFromTrace(HWND hWnd){
00479 RECT rc;
00480 PATHPOINT *ppt,*ppt1;
00481 int x1,y1,x2,y2;
00482 int i,j,n;
00483 PATHPOINT *pp;
00484 long Scale,first_vertex;
00485 if(Np == 0 || pathlist == NULL)return;
00486 GetClientRect(hWnd,&rc);
00487 Scale=100;
00488 for(i=0;i<Np;i++){
00489 pp=pathlist[i].pts;
00490 if(pp != NULL){
00491 ppt=(pathlist[i].pts);
00492 n=pathlist[i].n;
00493 x1=ppt->p.x; y1=ppt->p.y;
00494 UpdateVertexHeap(Nvert+1);
00495 CreateVertex();
00496 first_vertex=Nvert-1;
00497 (MainVp+Nvert-1)->xyz[0]=(x1-PAGESIZE/2)*Scale;
00498 (MainVp+Nvert-1)->xyz[1]=NpointerY;
00499 (MainVp+Nvert-1)->xyz[2]=(PAGESIZE/2-y1)*Scale;
00500 if(n > 1)for(j=1;j<n;j++){
00501 ppt=(pathlist[i].pts + j);
00502 x2=ppt->p.x; y2=ppt->p.y;
00503 ppt1=(ppt-1);
00504 if(ppt->type == 1 || ppt1->type == 1)
00505 BuildBezierCurve(ppt1,ppt,Scale,FALSE);
00506 else{
00507 UpdateVertexHeap(Nvert+1);
00508 CreateVertex();
00509 (MainVp+Nvert-1)->xyz[0]=(x2-PAGESIZE/2)*Scale;
00510 (MainVp+Nvert-1)->xyz[1]=NpointerY;
00511 (MainVp+Nvert-1)->xyz[2]=(PAGESIZE/2-y2)*Scale;
00512 UpdateEdgeHeap(Nedge+1);
00513 CreateEdge(Nvert-1,Nvert-2);
00514 }
00515 }
00516 if(pathlist[i].closed){
00517 ppt=pathlist[i].pts; ppt1=(ppt + n-1);
00518 if(ppt->type == 1 || ppt1->type == 1)
00519 BuildBezierCurve(ppt1,ppt,Scale,TRUE);
00520 UpdateEdgeHeap(Nedge+1);
00521 CreateEdge(Nvert-1,first_vertex);
00522 }
00523 }
00524 }
00525 }
00526
00527 static void WritePaths(void){
00528 FILE *fp;
00529 PTH *p;
00530 PATHPOINT *pp;
00531 char signon[]="EBPH";
00532 int i,j;
00533 if((fp=fopen(gszFile,"wb")) == NULL){
00534 MessageBox(GetFocus(),"Failed to open file","Bezier Module",MB_OK);
00535 return;
00536 }
00537 fwrite(signon,1,4,fp);
00538 fwrite(&Np,sizeof(int),1,fp);
00539 p=pathlist;
00540 for(i=0;i<Np;i++){
00541 fwrite(&(p->n),sizeof(int),1,fp);
00542 fwrite(&(p->closed),sizeof(int),1,fp);
00543 pp=p->pts;
00544 if(p->n > 0)for(j=0;j<p->n;j++){
00545 fwrite(&(pp->type),sizeof(int),1,fp);
00546 fwrite(&(pp->bent),sizeof(int),1,fp);
00547 fwrite(&(pp->p),sizeof(POINT),1,fp);
00548 fwrite(&(pp->p1),sizeof(POINT),1,fp);
00549 fwrite(&(pp->p2),sizeof(POINT),1,fp);
00550 pp++;
00551 }
00552 p++;
00553 }
00554 fclose(fp);
00555 }
00556
00557 static void ReadPaths(void){
00558 FILE *fp;
00559 POINT p,p1,p2;
00560 PATHPOINT *pp;
00561 char signon[5];
00562 int Np1,n,closed,type,bent;
00563 int i,j,k;
00564 if((fp=fopen(gszFile,"rb")) == NULL){
00565 MessageBox(GetFocus(),"Failed to open file","Bezier Module",MB_OK);
00566 return;
00567 }
00568 DeleteAllPath();
00569 fread(signon,1,4,fp); signon[4]=0;
00570 fread(&Np1,sizeof(int),1,fp);
00571
00572
00573 if(Np1 > 0)for(i=0;i<Np1;i++){
00574
00575
00576 fread(&n,sizeof(int),1,fp);
00577
00578
00579 fread(&closed,sizeof(int),1,fp);
00580
00581
00582 if(CreatePath() < 0)goto XERR;
00583 pathlist[Np-1].closed=closed;
00584 if(n > 0)for(j=0;j<n;j++){
00585 fread(&type,sizeof(int),1,fp);
00586 fread(&bent,sizeof(int),1,fp);
00587 fread(&p,sizeof(POINT),1,fp);
00588 fread(&p1,sizeof(POINT),1,fp);
00589 fread(&p2,sizeof(POINT),1,fp);
00590 if((k=CreatePathPoint(Np-1,(int)p.x,(int)p.y)) < 0)goto XERR;
00591 pp=((pathlist + Np-1)->pts + k);
00592 pp->type=type; pp->bent=bent;
00593 pp->p1.x=p1.x; pp->p1.y=p1.y;
00594 pp->p2.x=p2.x; pp->p2.y=p2.y;
00595 }
00596 }
00597 fclose(fp);
00598 return;
00599 XERR:
00600 MessageBox(GetFocus(),"Memory error","Bezier Module",MB_OK);
00601 DeleteAllPath();
00602 fclose(fp);
00603 return;
00604 }