DXFOUT.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 2007 OpenFX Development Team
00004 -- */
00005 
00006 /* File DXFOUT.C DLL to create a DXF from EVI structure */
00007 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <math.h>
00011 #include <setjmp.h>
00012 #include <windows.h>
00013 
00014 #include "struct.h"
00015 #include "dstruct.h"
00016 
00017 #define MAXUNIT    4194304L
00018 #define DESELECTED 0
00019 #define SELECTED   1
00020 #define INEDITOR   3
00021 
00022 #if __X__MIPS__
00023 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00024 #endif
00025 
00026 static HWND      hParent;
00027 static HINSTANCE hThisInstance;
00028 
00029 #if __WATCOMC__
00030 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00031 #else
00032 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00033 #endif
00034   switch (dwReason) {
00035     case DLL_PROCESS_ATTACH: {
00036 #if __X__MIPS__
00037       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00038 #endif
00039 //      MessageBox (GetFocus(),"Attaching","Debug",MB_OK);
00040       hThisInstance=hDLL;
00041       break;
00042     }
00043     case DLL_PROCESS_DETACH:
00044 #if __X__MIPS__
00045       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00046 #endif
00047 //      MessageBox (GetFocus(),"Detaching","Debug",MB_OK);
00048       break;
00049   }
00050   return TRUE;
00051 }
00052 
00053 #if __SC__
00054 #pragma startaddress(DllMain)
00055 #endif
00056 
00057 long _Export
00058  (HWND parent_window, char *filename,X__STRUCTURE *lpevi){
00059  char layer[8]={"MODEL"},cl[16];
00060  FILE *dxfp;
00061  vertex *Vp,*V0,*V1,*V2;
00062  face   *Fp;
00063  skel   *sp;
00064  long   vp,fp;
00065  long i,nf,colour=7;
00066  long xmax = -MAXUNIT, ymax = -MAXUNIT, zmax = -MAXUNIT,
00067       xmin =  MAXUNIT, ymin =  MAXUNIT, zmin =  MAXUNIT;
00068  long lrulerx,lrulery,lrulerz;
00069  double ruler;
00070  lpEVI=lpevi;
00071  if(filename == NULL)return 0;
00072  if(NvertSelect == 0 || Nface == 0){
00073    MessageBox(parent_window,"Too few vertices or faces selected","DXF Write",MB_OK);
00074    return 0;
00075  }
00076  lrulerx= (*(lpEVI->orulerx));
00077  lrulery= (*(lpEVI->orulery));
00078  lrulerz= (*(lpEVI->orulerz));
00079  ruler  = (*(lpEVI->ruler));
00080  if((dxfp=fopen(filename,"w")) != NULL){
00081    vp=0; while(vp < Nvert){
00082      Vp=(MainVp+vp);
00083      if(Vp->status == SELECTED){
00084        if(Vp->xyz[0] > xmax)xmax=Vp->xyz[0];
00085        if(Vp->xyz[1] > ymax)ymax=Vp->xyz[1];
00086        if(Vp->xyz[2] > zmax)zmax=Vp->xyz[2];
00087        if(Vp->xyz[0] < xmin)xmin=Vp->xyz[0];
00088        if(Vp->xyz[1] < ymin)ymin=Vp->xyz[1];
00089        if(Vp->xyz[2] < zmin)zmin=Vp->xyz[2];
00090      }
00091      vp++;
00092    }
00093    fprintf(dxfp,"0\nSECTION\n2\nHEADER\n9\n$ACADVER\n1\nAC1008\n9\n");
00094    fprintf(dxfp,"$UCSORG\n10\n0.0\n20\n0.0\n30\n0.0\n9\n$UCSXDIR\n");
00095    fprintf(dxfp,"10\n1.0\n20\n0.0\n30\n0.0\n9\n$TILEMODE\n70\n1\n9\n");
00096    fprintf(dxfp,"$UCSYDIR\n10\n0.0\n20\n1.0\n30\n0.0\n");
00097    fprintf(dxfp,"9\n$EXTMIN\n10\n%lf\n20\n%lf\n30\n%lf\n",
00098      (double)(xmin-lrulerx)/ruler,
00099      (double)(ymin-lrulery)/ruler,
00100      (double)(zmin-lrulerz)/ruler);
00101    fprintf(dxfp,"9\n$EXTMAX\n10\n%lf\n20\n%lf\n30\n%lf\n",
00102      (double)(xmax-lrulerx)/ruler,
00103      (double)(ymax-lrulery)/ruler,
00104      (double)(zmax-lrulerz)/ruler);
00105    fprintf(dxfp,"0\nENDSEC\n0\nSECTION\n2\nTABLES\n0\nTABLE\n2\nLTYPE\n");
00106    fprintf(dxfp,"70\n1\n0\nLTYPE\n2\nCONTINUOUS\n70\n64\n3\nSolid line\n");
00107    fprintf(dxfp,"72\n65\n73\n0\n40\n0.0\n0\nENDTAB\n0\nTABLE\n2\nLAYER\n");
00108    fprintf(dxfp,"70\n1\n0\nLAYER\n2\n%s\n70\n0\n62\n7\n6\nCONTINUOUS\n",layer);
00109    if((sp=MainSp) != NULL) while(sp != NULL){
00110      fprintf(dxfp,"0\nLAYER\n2\n%s\n70\n0\n62\n%ld\n6\nCONTINUOUS\n",
00111              sp->name,colour);
00112      sp=sp->last;
00113    }
00114    fprintf(dxfp,"0\nENDTAB\n0\nTABLE\n2\nSTYLE\n70\n1\n0\n");
00115    fprintf(dxfp,"STYLE\n2\nSTANDARD\n70\n0\n40\n0.0\n41\n1.0\n50\n0.0\n");
00116    fprintf(dxfp,"71\n0\n42\n0.2\n3\ntxt\n4\n  \n0\nENDTAB\n0\nTABLE\n");
00117    fprintf(dxfp,"2\nUCS\n70\n0\n0\nENDTAB\n0\nENDSEC\n");
00118    fprintf(dxfp,"0\nSECTION\n2\nENTITIES\n");
00119    sp=MainSp; for(;;){ /* sp will be null for vertices not on any node */
00120      if(sp != NULL)strcpy(cl,sp->name);
00121      else          strcpy(cl,layer);
00122      vp=0; while(vp < Nvert){
00123        Vp=(MainVp+vp);
00124        if(Vp->status == SELECTED && Vp->sp == sp)Vp->status=INEDITOR;
00125        vp++;
00126      }
00127      nf=0; fp=0; while(fp < Nface){
00128        Fp=(MainFp+fp);
00129        V0=(MainVp+Fp->V[0]); V1=(MainVp+Fp->V[1]); V2=(MainVp+Fp->V[2]);
00130        if(V0->status == INEDITOR && V1->status == INEDITOR &&
00131           V2->status == INEDITOR)nf++;
00132        fp++;
00133      }
00134      if(nf > 0){ /* only write if there are any faces */
00135        fprintf(dxfp,"0\nPOLYLINE\n8\n%s\n",cl);
00136        fprintf(dxfp,"66\n1\n70\n64\n71\n%ld\n72\n%ld\n",NvertSelect,nf);
00137        i=1; vp=0; while(vp < Nvert){
00138          Vp=(MainVp+vp);
00139          if(Vp->status == INEDITOR){
00140            fprintf(dxfp,"0\nVERTEX\n8\n%s\n10\n%lf\n20\n%lf\n30\n%lf\n",cl,
00141               (double)(Vp->xyz[0]-lrulerx)/ruler,
00142               (double)(Vp->xyz[1]-lrulery)/ruler,
00143               (double)(Vp->xyz[2]-lrulerz)/ruler);
00144            fprintf(dxfp,"70\n192\n");
00145            Vp->id = i++;
00146          }
00147          else Vp->id = -1;
00148          vp++;
00149        }
00150        fp=0; while(fp < Nface){
00151          Fp=(MainFp+fp);
00152          V0=(MainVp+Fp->V[0]); V1=(MainVp+Fp->V[1]); V2=(MainVp+Fp->V[2]);
00153          if(V0->status == INEDITOR && V1->status == INEDITOR &&
00154             V2->status == INEDITOR){
00155            fprintf(dxfp,"0\nVERTEX\n8\n%s\n10\n0\n20\n0\n30\n0\n70\n128\n",
00156                    cl);
00157            fprintf(dxfp,"71\n%d\n72\n%d\n73\n%d\n",(short)(V0->id),
00158                    (short)(V1->id),(short)(V2->id));
00159          }
00160          fp++;
00161        }
00162        fprintf(dxfp,"0\nSEQEND\n");
00163      }
00164      vp=0; while(vp < Nvert){ /* reset status */
00165        Vp=(MainVp+vp);
00166        if(Vp->status == INEDITOR)Vp->status=SELECTED;
00167        vp++;
00168      }
00169      if(sp == NULL)break;
00170      sp=sp->last;
00171    }  /* end of for(;;) */
00172    fprintf(dxfp,"8\n%s\n0\nENDSEC\n0\nEOF\n",layer);
00173    fclose(dxfp);
00174  }
00175  else{
00176    MessageBox(parent_window,"File open Error","DXF Write",MB_OK);
00177  }
00178  return 1;
00179 }

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