VRMLX.C

Go to the documentation of this file.
00001 /* File VRMLX.C DLL   ||   */
00002 
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include <math.h>
00006 #include <setjmp.h>
00007 #include <windows.h>
00008 #if __HELP_WS__
00009 #include "..\help_ws\include\htmlhelp.h"
00010 #endif
00011 
00012 #include "astruct.h"
00013 #include "dstruct.h"
00014 
00015 #include "vrmlX.h"
00016 
00017 #if __X__MIPS__
00018 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00019 #endif
00020 
00021 static HWND      hParent;
00022 static HINSTANCE hThisInstance;
00023 
00024 #define DOS386
00025 #define _X__FAR
00026 #define PI  3.1415926
00027 
00028 #ifndef min
00029 #define min(a,b)  ( ((a) < (b)) ? (a) : (b) )
00030 #endif
00031 #ifndef max
00032 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00033 #endif
00034 
00035 /* definition of flags and identifiers*/
00036 
00037 static long indent=0;
00038 static long digits=3,interpolate=3;
00039 static BOOL bIndent=TRUE,bPrefix=FALSE;
00040 static BOOL bViewpoints=TRUE,bInterpolate=FALSE;
00041 static char map_path[256]="../objects/";
00042 static char globalfile[256]="";
00043 static char back_image[256]="";
00044 static char front_image[256]="";
00045 static char left_image[256]="";
00046 static char right_image[256]="";
00047 static char top_image[256]="";
00048 static char bottom_image[256]="";
00049 
00050 static BOOL WriteDataToRegistry(char *keyname){
00051  HKEY hkey;
00052  DWORD result;
00053  DWORD dw;
00054  if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,keyname,0,NULL,
00055                    REG_OPTION_NON_VOLATILE,
00056                    KEY_ALL_ACCESS,NULL,&hkey,&result) != ERROR_SUCCESS)
00057    return FALSE;
00058  RegSetValueEx(hkey,"object_prefix",0,REG_SZ,(LPBYTE)map_path,strlen(map_path)+1);
00059  RegSetValueEx(hkey,"anim_file",0,REG_SZ,(LPBYTE)globalfile,strlen(globalfile)+1);
00060  dw=(DWORD)bPrefix;
00061  RegSetValueEx(hkey,"use_object_prefix",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00062  dw=(DWORD)digits;
00063  RegSetValueEx(hkey,"digits",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00064  dw=(DWORD)bIndent;
00065  RegSetValueEx(hkey,"indent",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00066 
00067  dw=(DWORD)bViewpoints;
00068  RegSetValueEx(hkey,"viewpoints",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00069  dw=(DWORD)bInterpolate;
00070  RegSetValueEx(hkey,"interpolate",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00071  dw=(DWORD)interpolate;
00072  RegSetValueEx(hkey,"interpolate_value",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00073  RegSetValueEx(hkey,"back_image",0,REG_SZ,(LPBYTE)back_image,strlen(back_image)+1);
00074  RegSetValueEx(hkey,"front_image",0,REG_SZ,(LPBYTE)front_image,strlen(front_image)+1);
00075  RegSetValueEx(hkey,"left_image",0,REG_SZ,(LPBYTE)left_image,strlen(left_image)+1);
00076  RegSetValueEx(hkey,"right_image",0,REG_SZ,(LPBYTE)right_image,strlen(right_image)+1);
00077  RegSetValueEx(hkey,"top_image",0,REG_SZ,(LPBYTE)top_image,strlen(top_image)+1);
00078  RegSetValueEx(hkey,"bottom_image",0,REG_SZ,(LPBYTE)bottom_image,strlen(bottom_image)+1);
00079 
00080  RegCloseKey(hkey);
00081  return TRUE;
00082 }
00083 
00084 static BOOL ReadDataFromRegistry(char *keyname){
00085  HKEY hkey;
00086  DWORD result;
00087  DWORD len,type,dw;
00088  char  str[256];
00089  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyname,0,KEY_ALL_ACCESS,&hkey)
00090    != ERROR_SUCCESS)return FALSE;
00091  len=256;
00092  if(RegQueryValueEx(hkey,"object_prefix",NULL,&type,(LPBYTE)str,&len)
00093     == ERROR_SUCCESS)strcpy(map_path,str);
00094  len=256;
00095  if(RegQueryValueEx(hkey,"anim_file",NULL,&type,(LPBYTE)str,&len)
00096     == ERROR_SUCCESS)strcpy(globalfile,str);
00097  len=sizeof(DWORD);
00098  if(RegQueryValueEx(hkey,"use_object_prefix",NULL,&type,(LPBYTE)(&dw),&len)
00099     == ERROR_SUCCESS)bPrefix=(BOOL)dw;
00100  len=sizeof(DWORD);
00101  if(RegQueryValueEx(hkey,"indent",NULL,&type,(LPBYTE)(&dw),&len)
00102     == ERROR_SUCCESS)bIndent=(BOOL)dw;
00103  len=sizeof(DWORD);
00104  if(RegQueryValueEx(hkey,"digits",NULL,&type,(LPBYTE)(&dw),&len)
00105     == ERROR_SUCCESS)digits=(long)dw;
00106 
00107  len=sizeof(DWORD);
00108  if(RegQueryValueEx(hkey,"viewpoints",NULL,&type,(LPBYTE)(&dw),&len)
00109     == ERROR_SUCCESS)bViewpoints=(BOOL)dw;
00110  len=sizeof(DWORD);
00111  if(RegQueryValueEx(hkey,"interpolate",NULL,&type,(LPBYTE)(&dw),&len)
00112     == ERROR_SUCCESS)bInterpolate=(BOOL)dw;
00113  len=sizeof(DWORD);
00114  if(RegQueryValueEx(hkey,"interpolate_value",NULL,&type,(LPBYTE)(&dw),&len)
00115     == ERROR_SUCCESS)interpolate=(long)dw;
00116  len=256;
00117  if(RegQueryValueEx(hkey,"back_image",NULL,&type,(LPBYTE)str,&len)
00118     == ERROR_SUCCESS)strcpy(back_image,str);
00119  len=256;
00120  if(RegQueryValueEx(hkey,"front_image",NULL,&type,(LPBYTE)str,&len)
00121     == ERROR_SUCCESS)strcpy(front_image,str);
00122  len=256;
00123  if(RegQueryValueEx(hkey,"left_image",NULL,&type,(LPBYTE)str,&len)
00124     == ERROR_SUCCESS)strcpy(left_image,str);
00125  len=256;
00126  if(RegQueryValueEx(hkey,"right_image",NULL,&type,(LPBYTE)str,&len)
00127     == ERROR_SUCCESS)strcpy(right_image,str);
00128  len=256;
00129  if(RegQueryValueEx(hkey,"top_image",NULL,&type,(LPBYTE)str,&len)
00130     == ERROR_SUCCESS)strcpy(top_image,str);
00131  len=256;
00132  if(RegQueryValueEx(hkey,"bottom_image",NULL,&type,(LPBYTE)str,&len)
00133     == ERROR_SUCCESS)strcpy(bottom_image,str);
00134  RegCloseKey(hkey);
00135  return TRUE;
00136 }
00137 static char *FileOnly(char *file){
00138  char *t;
00139  t=strrchr(file,'\\');
00140  if(t == NULL)return file;
00141  return (t+1);
00142 }
00143 
00144 static void ReplaceExt(char *str){
00145  char *t;
00146  t=strrchr(str,'.');
00147  if(t == NULL)return;
00148  strcpy((t+1),"wrl");
00149  return;
00150 }
00151 
00152 static void DeleteExt(char *str){
00153  char *t;
00154  t=strchr(str,'.');
00155  if(t == NULL)return;
00156  *t='\0';
00157  t=strchr(str,' ');
00158  if(t == NULL)return;
00159  *t='\0';
00160  return;
00161 }
00162 
00163 static void Id(FILE *f){
00164  int i;
00165  if(!bIndent)return;
00166  if(indent > 0)for(i=0;i<indent;i++)fprintf(f,"  ");
00167 }
00168 
00169 typedef double quaternion[4];
00170 
00171 void EulerToQuaternion(double p, double t, double a, quaternion q){
00172   a *= 0.5; t *= 0.5; p *= 0.5;
00173   q[0]=cos(a)*cos(t)*cos(p)+sin(a)*sin(t)*sin(p);
00174   q[1]=sin(a)*cos(t)*cos(p)-cos(a)*sin(t)*sin(p);
00175   q[2]=cos(a)*sin(t)*cos(p)+sin(a)*cos(t)*sin(p);
00176   q[3]=cos(a)*cos(t)*sin(p)-sin(a)*sin(t)*cos(p);
00177 }
00178 
00179 void TransformOrientation(double phi, double theta, double alpha,
00180                           double *ux, double *uy, double *uz,
00181                           double *ua){
00182  double w;
00183  quaternion q;
00184  *ux = 0.0; *uy = 0.0; *uz= 1.0; *ua = 0.0;
00185  EulerToQuaternion(phi*PI/180.0,theta*PI/180.0,alpha*PI/180.0,q);
00186  if(fabs(q[0] - 1.0) < 1.e-5)return;
00187  *ua = 2.0*acos(q[0]);
00188  w=1.0/sqrt(1.0-q[0]*q[0]);
00189  *ux = q[1]*w;
00190  *uy = q[2]*w;
00191  *uz = q[3]*w;
00192  return;
00193 }
00194 
00195 void CreateVRMLfile(FILE *dxfp){
00196  char format2[64],format3[64],format4[64],tempstr[256],tempstr1[256];
00197  position *Pp;
00198  node     *Np;
00199  object   *Op;
00200  sky      *Sp;
00201  long i,k,ccf;
00202  point p,tp;
00203  short im,refl;
00204  double phi,theta,alpha,mratio,sx,sy,sz,ima,gamb,oamb,m2ratio,frac;
00205  unsigned char sr,sg,sb,zr,zg,zb,gr,gg,gb;
00206  double ux,uy,uz,ua;
00207  char filename[255];
00208  BOOL bSky=FALSE,bGround=FALSE;
00209  sprintf(format3,"%%.%ldf %%.%ldf %%.%ldf",digits,digits,digits);
00210  sprintf(format4,"%%.%ldf %%.%ldf %%.%ldf %%.%ldf",digits,digits,digits,digits);
00211  sprintf(format2,"%%.%ldf %%.%ldf",digits,digits);
00212  // write-group
00213  Id(dxfp); fprintf(dxfp,"DEF SFX-ANIM Group {\n");  indent++;
00214  Id(dxfp); fprintf(dxfp,"children [\n"); indent++;
00215  // Viewpoints
00216  if(bViewpoints){
00217  Np=FirstNp; while(Np!=NULL){
00218    if(Np->type == CAMERA && Np == SelectedCamera){
00219      if((Op=Np->fobj) != NULL && (Pp=Np->fpos) != NULL)while(Pp != NULL){
00220        ccf=CurrentFrame;
00221        CurrentFrame=Pp->lastframe;
00222        GetTransform(0,Pp->lastframe,1.0,
00223                     Np,Op,p,tp,&phi,&theta,&alpha,
00224                     &sx,&sy,&sz,&im,&ima);
00225        CurrentFrame=ccf;
00226        Id(dxfp); fprintf(dxfp,"DEF %s Viewpoint {\n",
00227                          Np->actorname /*,Pp->lastframe */);
00228        indent++;
00229        Id(dxfp); fprintf(dxfp,"fieldOfView 0.78\n");
00230        Id(dxfp); fprintf(dxfp,"description \"%s Key-%ld\"\n",Np->actorname,Pp->lastframe);
00231        Id(dxfp); fprintf(dxfp,"position ");
00232        Id(dxfp); fprintf(dxfp,format3,
00233                               (double)p[0]/(double)UNIT,
00234                               (double)p[2]/(double)UNIT,
00235                              -(double)p[1]/(double)UNIT);
00236        Id(dxfp); fprintf(dxfp,"\n");
00237        Id(dxfp); fprintf(dxfp,"# phi=%lf theta=%lf alpha=%lf\n",phi,theta,alpha);
00238        Id(dxfp); fprintf(dxfp,"orientation ");
00239        // theta is bank alpha is pitch phi is turn ????
00240        TransformOrientation(phi,-theta,alpha,&ux,&uy,&uz,&ua);
00241        Id(dxfp); fprintf(dxfp,format4,ux,uz,-uy,ua);
00242        Id(dxfp); fprintf(dxfp,"\n");
00243        indent--;
00244        Id(dxfp); fprintf(dxfp,"}\n");
00245        Pp=Pp->next;
00246      }
00247      break;
00248    }
00249    Np=Np->next;
00250  }
00251  }
00252  // TimeSensors
00253  if(bInterpolate){
00254    Np=FirstNp; while(Np!=NULL){
00255      if(Np->type == CAMERA && Np == SelectedCamera)break;
00256      Np=Np->next;
00257    }
00258    frac=1.0/(double)interpolate;
00259    Id(dxfp);
00260      fprintf(dxfp,"DEF TIMER-%s TimeSensor { loop FALSE cycleInterval %.3lf}\n",
00261    Np->actorname,frac);
00262 
00263    Id(dxfp); fprintf(dxfp,
00264      "DEF POS-TWEEN-%s PositionInterpolator{\n",Np->actorname); indent++;
00265    Id(dxfp); fprintf(dxfp,"key ["); indent++;
00266    for(i=1,k=1;i<=Nframes;i+=interpolate,k++){
00267      fprintf(dxfp,"%.3lf",(double)(i)/(double)(Nframes));
00268      if(k%10 == 0){
00269        fprintf(dxfp,",\n");
00270        Id(dxfp);
00271      }
00272      else fprintf(dxfp,", ");
00273    }
00274    indent--;
00275    fprintf(dxfp,"\n");
00276    Id(dxfp); fprintf(dxfp,"]\n"); // end key
00277    Id(dxfp); fprintf(dxfp,"keyValue ["); indent++;
00278    ccf=CurrentFrame;
00279    for(CurrentFrame=1,k=1;CurrentFrame<=Nframes;CurrentFrame+=interpolate,k++){
00280      Np=FirstNp; while(Np!=NULL){
00281        if(Np->type == CAMERA && Np == SelectedCamera){
00282          GetTransform(0,CurrentFrame,1.0,
00283                       Np,Op,p,tp,&phi,&theta,&alpha,
00284                       &sx,&sy,&sz,&im,&ima);
00285          fprintf(dxfp,format3,
00286                               (double)p[0]/(double)UNIT,
00287                               (double)p[2]/(double)UNIT,
00288                              -(double)p[1]/(double)UNIT);
00289          if(k%4 == 0){
00290            fprintf(dxfp,",\n");
00291            Id(dxfp);
00292          }
00293          else fprintf(dxfp,", ");
00294          break;
00295        }
00296        Np=Np->next;
00297      }
00298    }
00299    indent--;
00300    fprintf(dxfp,"\n");
00301    Id(dxfp); fprintf(dxfp,"]\n"); // end keyValue
00302    indent--;
00303    Id(dxfp); fprintf(dxfp,"}\n");  // position interpolator
00304    CurrentFrame=ccf;
00305 
00306    Id(dxfp); fprintf(dxfp,
00307      "DEF ROT-TWEEN-%s OrientationInterpolator{\n",Np->actorname); indent++;
00308    Id(dxfp); fprintf(dxfp,"key ["); indent++;
00309    for(i=1,k=1;i<=Nframes;i+=interpolate,k++){
00310      fprintf(dxfp,"%.3lf",(double)(i)/(double)(Nframes));
00311      if(k%10 == 0){
00312        fprintf(dxfp,",\n");
00313        Id(dxfp);
00314      }
00315      else fprintf(dxfp,", ");
00316    }
00317    indent--;
00318    fprintf(dxfp,"\n");
00319    Id(dxfp); fprintf(dxfp,"]\n"); // end key
00320    Id(dxfp); fprintf(dxfp,"keyValue ["); indent++;
00321    ccf=CurrentFrame;
00322    for(CurrentFrame=1,k=1;CurrentFrame<=Nframes;CurrentFrame+=interpolate,k++){
00323      Np=FirstNp; while(Np!=NULL){
00324        if(Np->type == CAMERA && Np == SelectedCamera){
00325          GetTransform(0,CurrentFrame,1.0,
00326                       Np,Op,p,tp,&phi,&theta,&alpha,
00327                       &sx,&sy,&sz,&im,&ima);
00328          TransformOrientation(phi,-theta,alpha,&ux,&uy,&uz,&ua);
00329          fprintf(dxfp,format4,ux,uz,-uy,ua);
00330          if(k%3 == 0){
00331            fprintf(dxfp,",\n");
00332            Id(dxfp);
00333          }
00334          else fprintf(dxfp,", ");
00335          break;
00336        }
00337        Np=Np->next;
00338      }
00339    }
00340    indent--;
00341    fprintf(dxfp,"\n");
00342    Id(dxfp); fprintf(dxfp,"]\n"); // end keyValue
00343    indent--;
00344    Id(dxfp); fprintf(dxfp,"}\n");  // orientation interpolator
00345    CurrentFrame=ccf;
00346 
00347 // Put route statement here
00348 
00349  }
00350  // Models
00351  Np=FirstNp; while(Np!=NULL){
00352    if(Np->type == SKY){
00353      if((Sp=Np->fsky) != NULL)while(Sp != NULL){
00354        if(CurrentFrame >= Sp->firstframe && CurrentFrame <= Sp->lastframe){
00355          sr=Sp->colour[0];
00356          sg=Sp->colour[1];
00357          sb=Sp->colour[2];
00358          zr=Sp->zcolour[0];
00359          zg=Sp->zcolour[1];
00360          zb=Sp->zcolour[2];
00361          bSky=TRUE;
00362          break;
00363        }
00364        Sp=Sp->next;
00365      }
00366    }
00367    else{
00368      if((Op=Np->fobj) != NULL)while(Op != NULL){
00369        if(CurrentFrame >= Op->firstframe && CurrentFrame <= Op->lastframe){
00370          if(Op->type == LIGHT){
00371            sr=Op->colour[0]; sg=Op->colour[1]; sb=Op->colour[2];
00372            GetTransform(0,CurrentFrame,1.0,
00373                         Np,Op,p,tp,&phi,&theta,&alpha,
00374                         &sx,&sy,&sz,&im,&ima);
00375            if(Op->lighttype >= SPOTLIGHT){
00376            ;}
00377          }
00378          else if(Op->type == GROUND){
00379            gr=Op->colour[0];  gg=Op->colour[1];  gb=Op->colour[2];
00380            refl = Op->grefl;
00381            bGround=TRUE;
00382          }
00383          else if(Op->type == NORMAL || Op->type == ANIMOBJ){
00384            strcpy(tempstr,FileOnly(Op->name));
00385            ReplaceExt(tempstr);
00386            strcpy(tempstr1,FileOnly(Op->name));
00387            DeleteExt(tempstr1);
00388            GetTransform(0,CurrentFrame,1.0,
00389                         Np,Op,p,tp,&phi,&theta,&alpha,
00390                         &sx,&sy,&sz,&im,&ima);
00391            Id(dxfp); fprintf(dxfp,"DEF SFX-%s Transform {\n",tempstr1);
00392            indent++;
00393            Id(dxfp); fprintf(dxfp,"translation ");
00394            Id(dxfp); fprintf(dxfp,format3,
00395                               (double)p[0]/(double)UNIT,
00396                               (double)p[2]/(double)UNIT,
00397                              -(double)p[1]/(double)UNIT);
00398            Id(dxfp); fprintf(dxfp,"\n");
00399            //Id(dxfp); fprintf(dxfp,"# phi=%lf theta=%lf alpha=%lf\n",phi,theta,alpha);
00400            Id(dxfp); fprintf(dxfp,"rotation ");
00401            TransformOrientation(phi,-theta,alpha,&ux,&uy,&uz,&ua);
00402            Id(dxfp); fprintf(dxfp,format4,ux,uz,-uy,ua);
00403            Id(dxfp); fprintf(dxfp,"\n");
00404            Id(dxfp); fprintf(dxfp,"scale ");
00405            Id(dxfp); fprintf(dxfp,format3,sx,sz,sy);
00406            Id(dxfp); fprintf(dxfp,"\n");
00407            Id(dxfp); fprintf(dxfp,"children [\n"); indent++;
00408            Id(dxfp); fprintf(dxfp,"Inline {");
00409            if(bPrefix)fprintf(dxfp,"url \"%s",map_path);
00410            else       fprintf(dxfp,"url \"");
00411            fprintf(dxfp,"%s\"}\n",tempstr);
00412            indent--;
00413            Id(dxfp); fprintf(dxfp,"]\n");
00414            indent--;
00415            Id(dxfp); fprintf(dxfp,"}\n");
00416          }
00417          break;
00418        }
00419        Op=Op->next;
00420      }
00421    }
00422    Np=Np->next;
00423  }
00424  if(1 || bGround || bSky){
00425    Id(dxfp); fprintf(dxfp,"DEF BACKGROUND Background {\n");
00426    indent++;
00427    if(bSky){
00428      Id(dxfp); fprintf(dxfp,"skyAngle 1.57\n");
00429      Id(dxfp); fprintf(dxfp,"skyColor [");
00430      fprintf(dxfp,format3,(double)sr/255.0,(double)sg/255.0,(double)sb/255.0);
00431      fprintf(dxfp,", ");
00432      fprintf(dxfp,format3,(double)zr/255.0,(double)zg/255.0,(double)zb/255.0);
00433      fprintf(dxfp,"]\n");
00434    }
00435    if(bGround){
00436      Id(dxfp); fprintf(dxfp,"groundAngle 1.57\n");
00437      Id(dxfp); fprintf(dxfp,"groundColor [");
00438      fprintf(dxfp,format3,(double)gr/255.0,(double)gg/255.0,(double)gb/255.0);
00439      fprintf(dxfp,", ");
00440      fprintf(dxfp,format3,(double)gr/255.0,(double)gg/255.0,(double)gb/255.0);
00441      fprintf(dxfp,"]\n");
00442    }
00443    if(back_image[0] != '\0')  {Id(dxfp); fprintf(dxfp,"backUrl   [\"%s\"] \n",back_image);  }
00444    if(front_image[0] != '\0') {Id(dxfp); fprintf(dxfp,"frontUrl  [\"%s\"] \n",front_image); }
00445    if(left_image[0] != '\0')  {Id(dxfp); fprintf(dxfp,"leftUrl   [\"%s\"] \n",left_image);  }
00446    if(right_image[0] != '\0') {Id(dxfp); fprintf(dxfp,"rightUrl  [\"%s\"] \n",right_image); }
00447    if(top_image[0] != '\0')   {Id(dxfp); fprintf(dxfp,"topUrl    [\"%s\"] \n",top_image);   }
00448    if(bottom_image[0] != '\0'){Id(dxfp); fprintf(dxfp,"bottomUrl [\"%s\"] \n",bottom_image);}
00449    indent--;
00450    Id(dxfp); fprintf(dxfp,"}\n"); // Background
00451  }
00452  indent--;
00453  Id(dxfp); fprintf(dxfp,"]\n"); // children
00454  indent--;
00455  Id(dxfp); fprintf(dxfp,"}\n"); // group
00456  return;
00457 }
00458 
00459 #if __WATCOMC__
00460 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00461 #else
00462 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00463 #endif
00464   switch (dwReason) {
00465     case DLL_PROCESS_ATTACH: {
00466 #if __X__MIPS__
00467       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00468 #endif
00469       hThisInstance=hDLL;
00470       break;
00471     }
00472     case DLL_PROCESS_DETACH:
00473 #if __X__MIPS__
00474       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00475 #endif
00476       break;
00477   }
00478   return TRUE;
00479 }
00480 
00481 static PSTR FileInPath(PSTR pstrPath){
00482  PSTR pstr;
00483  pstr = pstrPath + strlen(pstrPath);
00484  while (pstr > pstrPath) {
00485      pstr = (AnsiPrev(pstrPath, pstr));
00486      if (*pstr == '\\' || *pstr == ':' || *pstr == '/') {
00487          pstr = (AnsiNext(pstr));
00488          break;
00489      }
00490  }
00491  return pstr;
00492 }
00493 
00494 static unsigned CALLBACK NameHookProc(HWND hwnd,UINT msg,
00495                               WPARAM wparam,LPARAM lparam){
00496  BOOL err;
00497  switch( msg ) {
00498    case WM_INITDIALOG:
00499      if(bPrefix)SendDlgItemMessage(hwnd,DLG_VRML_USEPREFIX,BM_SETCHECK,1,0);
00500      if(bIndent)SendDlgItemMessage(hwnd,DLG_VRML_INDENTATION,BM_SETCHECK,1,0);
00501      if(bViewpoints)SendDlgItemMessage(hwnd,DLG_VRML_KEYFRAME,BM_SETCHECK,1,0);
00502      if(bInterpolate)SendDlgItemMessage(hwnd,DLG_VRML_KEYINTER,BM_SETCHECK,1,0);
00503      SetDlgItemInt(hwnd,DLG_VRML_DIGITS,digits,FALSE);
00504      SetDlgItemInt(hwnd,DLG_VRML_KEYINTERVAL,interpolate,FALSE);
00505      SetDlgItemText(hwnd,DLG_VRML_PREFIX,map_path);
00506      SetDlgItemText(hwnd,DLG_VRML_IMAGE_TOP,top_image);
00507      SetDlgItemText(hwnd,DLG_VRML_IMAGE_BOTTOM,bottom_image);
00508      SetDlgItemText(hwnd,DLG_VRML_IMAGE_LEFT,left_image);
00509      SetDlgItemText(hwnd,DLG_VRML_IMAGE_RIGHT,right_image);
00510      SetDlgItemText(hwnd,DLG_VRML_IMAGE_FRONT,front_image);
00511      SetDlgItemText(hwnd,DLG_VRML_IMAGE_BACK,back_image);
00512 //     SetWindowPos(GetParent(hwnd),HWND_TOP,50,5,0,0,SWP_NOSIZE);
00513 //     CentreDlgOnS(GetParent(hwnd));
00514      return FALSE;
00515    case WM_COMMAND:
00516      switch(LOWORD(wparam)){
00517        case IDOK:{
00518           goto JUMPHERE;
00519          }
00520          break;
00521        case  DLG_VRML_HELP:{
00522             char lname[256],res_str1[256],res_str2[256];
00523             GetModuleFileName(hThisInstance,lname,225);
00524             *FileInPath(lname) = '\0';
00525             strcat(lname,"help\\");
00526             strcpy(res_str1,lname);
00527 #if !__HELP_WS__
00528             strcat(res_str1,"ani_help.chm");
00529             ShellExecute(hwnd,NULL,res_str1,
00530                          NULL,lname,SW_SHOW);
00531 #else
00532             {
00533              HH_WINTYPE hhwin;
00534              memset(&hhwin,0,sizeof(HH_WINTYPE));
00535              hhwin.cbStruct=sizeof(HH_WINTYPE);
00536              hhwin.nShowState=SW_SHOW;
00537              hhwin.pszType="MyHelp";
00538              LoadString(hThisInstance,IDX_VRML_STRING2,lname,255);
00539              hhwin.pszCaption=lname;
00540              hhwin.fsValidMembers = HHWIN_PARAM_SHOWSTATE |
00541                                     HHWIN_PARAM_PROPERTIES|
00542                                     HHWIN_PARAM_CUR_TAB|
00543                                     HHWIN_PARAM_EXPANSION|
00544                                     HHWIN_PARAM_RECT;
00545              hhwin.rcWindowPos.top=0;
00546              hhwin.rcWindowPos.left=0;
00547              hhwin.rcWindowPos.right=500;
00548              hhwin.rcWindowPos.bottom=500;
00549              hhwin.nShowState=SW_SHOW;
00550              strcat(res_str1,"ani_help.chm");
00551              hhwin.fNotExpanded = TRUE;
00552              hhwin.fsWinProperties = HHWIN_PROP_TRI_PANE|HHWIN_PROP_TAB_SEARCH;
00553              hhwin.curNavType=HHWIN_NAVTYPE_TOC;
00554              strcpy(res_str2,res_str1);
00555              strcat(res_str2,"::toc.hhc");
00556              hhwin.pszToc=res_str2;
00557              strcat(res_str1,"::/vrml_exporter.htm");
00558              HtmlHelp(hwnd,NULL,HH_SET_WIN_TYPE,(DWORD)&hhwin);
00559              HtmlHelp(hwnd,">MyHelp",HH_DISPLAY_TOPIC,(DWORD)res_str1);
00560            }
00561 #endif
00562          }
00563          break;
00564        default: break;
00565      }
00566      break;
00567    case WM_NOTIFY:{
00568        LPOFNOTIFY lp=(LPOFNOTIFY)lparam;
00569        if(lp->hdr.code == CDN_FILEOK){
00570          JUMPHERE:
00571          if(SendDlgItemMessage(hwnd,DLG_VRML_USEPREFIX,BM_GETCHECK,0,0))
00572               bPrefix=TRUE;
00573          else bPrefix=FALSE;
00574          if(SendDlgItemMessage(hwnd,DLG_VRML_INDENTATION,BM_GETCHECK,0,0))
00575               bIndent=TRUE;
00576          else bIndent=FALSE;
00577          if(SendDlgItemMessage(hwnd,DLG_VRML_KEYFRAME,BM_GETCHECK,0,0))
00578               bViewpoints=TRUE;
00579          else bViewpoints=FALSE;
00580          if(SendDlgItemMessage(hwnd,DLG_VRML_KEYINTER,BM_GETCHECK,0,0))
00581               bInterpolate=TRUE;
00582          else bInterpolate=FALSE;
00583          digits=GetDlgItemInt(hwnd,DLG_VRML_DIGITS,&err,FALSE);
00584          if(digits < 0)digits=0;
00585          interpolate=GetDlgItemInt(hwnd,DLG_VRML_KEYINTERVAL,&err,FALSE);
00586          if(digits < 1)digits=1;
00587          GetDlgItemText(hwnd,DLG_VRML_PREFIX,map_path,255);
00588          GetDlgItemText(hwnd,DLG_VRML_IMAGE_BACK,back_image,255);
00589          GetDlgItemText(hwnd,DLG_VRML_IMAGE_FRONT,front_image,255);
00590          GetDlgItemText(hwnd,DLG_VRML_IMAGE_LEFT,left_image,255);
00591          GetDlgItemText(hwnd,DLG_VRML_IMAGE_RIGHT,right_image,255);
00592          GetDlgItemText(hwnd,DLG_VRML_IMAGE_TOP,top_image,255);
00593          GetDlgItemText(hwnd,DLG_VRML_IMAGE_BOTTOM,bottom_image,255);
00594        }
00595      }
00596      break;
00597    default: break;
00598  }
00599  return FALSE;
00600 }
00601 
00602 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00603                            HWND parent, HINSTANCE hInst){
00604  int i;
00605  OPENFILENAME ofn;
00606  char szFilter[80],title[256];
00607  DWORD version;
00608  version=GetVersion();
00609  strcpy(szFilter,szfilter);
00610  i=0; while(szFilter[i] != '\0'){
00611    if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00612  }
00613  memset(&ofn,0,sizeof(OPENFILENAME));
00614  ofn.lStructSize=sizeof(OPENFILENAME);
00615  ofn.hwndOwner=parent;
00616  ofn.lpstrFilter=szFilter;
00617  ofn.nFilterIndex=0;
00618  ofn.lpstrFile=szfile;
00619  ofn.nMaxFile=255;
00620  ofn.lpstrFileTitle=NULL;
00621  ofn.nMaxFileTitle=0;
00622  ofn.lpstrInitialDir=NULL;
00623  LoadString(hThisInstance,IDX_VRML_STRING1,title,255);
00624  ofn.lpstrTitle=title;
00625  ofn.hInstance=hInst;
00626  ofn.lpfnHook=(LPOFNHOOKPROC)NameHookProc;
00627  ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00628            OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON;
00629 //version=3;
00630  if(LOBYTE(LOWORD(version)) >= 4){
00631    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_VRML);
00632    ofn.Flags |= OFN_EXPLORER;
00633  }
00634  else{
00635    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_OLDVRML);
00636  }
00637 
00638  return GetOpenFileName(&ofn);
00639 }
00640 
00641 long _Export(HWND parent_window, char *filename, ANI_STRUCTURE *lpevi){
00642  char localfile[256];
00643  FILE *dxfp;
00644  lpEVI=lpevi;
00645  ReadDataFromRegistry("SOFTWARE\\OPENFX\\VRML");
00646  strcpy(localfile,globalfile);
00647  if(!LocalSelectFileName(localfile,
00648                          "VRML files (*.WRL)|*.wrl",
00649                           parent_window,hThisInstance))return 1;
00650  strcpy(globalfile,localfile);
00651  WriteDataToRegistry("SOFTWARE\\OPENFX\\VRML");
00652  AppendFileExtension(localfile,".wrl");
00653  if((dxfp=fopen(localfile,"w")) != NULL){
00654    fprintf(dxfp,"#VRML V2.0 utf8\n\n# Animation Script Produced by OpenFX Version 2.0\n\n");
00655    CreateVRMLfile(dxfp);
00656    fclose(dxfp);
00657  }
00658  else{
00659    MessageBox(parent_window,"File open Error",NULL,MB_OK);
00660  }
00661  return 1;
00662 }
00663 

Generated on Sun Apr 27 14:20:10 2014 for OpenFX by  doxygen 1.5.6