00001
00002
00003
00004
00005
00006
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include <math.h>
00010 #include <windows.h>
00011
00012 #include "struct.h"
00013 #include "dstruct.h"
00014
00015 #include "sections.h"
00016
00017 #define DESELECTED 0
00018 #define SELECTED 1
00019
00020 static HWND hParent;
00021 static HINSTANCE hThisInstance;
00022 static BOOL i_full=TRUE;
00023 static double scale_v=1.0;
00024
00025 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00026 HWND parent, HINSTANCE hInst);
00027
00028 #if __WATCOMC__
00029 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00030 #else
00031 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00032 #endif
00033 switch (dwReason) {
00034 case DLL_PROCESS_ATTACH: {
00035 hThisInstance=hDLL;
00036 if(hDLL == NULL)MessageBox ( GetFocus()," NULL instance",NULL, MB_OK);
00037 break;
00038 }
00039 case DLL_PROCESS_DETACH:
00040 break;
00041 }
00042 return TRUE;
00043 }
00044
00045 BOOL _Xmodeler
00046 (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00047 char localfile[256];
00048 lpEVI=lpevi;
00049 localfile[0]='\0';
00050 hParent=parent_window;
00051 if(!LocalSelectFileName(localfile,
00052 "Data Files (*.DAT)|*.dat",
00053 parent_window,hThisInstance))return FALSE;
00054 else{
00055 HCURSOR hSave;
00056 FILE *fp;
00057 vertex *Vp;
00058 edge *Ep;
00059 long i,j,nsections,npoints,id;
00060 double x,y,z,scale=32768.0/327.0*scale_v;
00061 hSave=SetCursor(LoadCursor(NULL,IDC_WAIT));
00062 if((fp = fopen(localfile,"r")) != NULL){
00063 fscanf(fp,"%ld %ld",&nsections,&npoints);
00064
00065 if(nsections > 0 && npoints > 0){
00066 for(j=0;j<nsections;j++){
00067 if(!UpdateVertexHeap(Nvert+npoints))goto XXIT;
00068 if(!UpdateEdgeHeap(Nedge+npoints))goto XXIT;
00069 for(i=0;i<npoints;i++){
00070 fscanf(fp,"%lf %lf %lf",&x,&y,&z);
00071 CreateVertex();
00072 Vp=(MainVp+Nvert-1);
00073 Vp->xyz[0]=(long)(x*scale);
00074 Vp->xyz[1]=(long)(y*scale);
00075 Vp->xyz[2]=(long)(z*scale);
00076 if(i > 0)CreateEdge(Nvert-1,Nvert-2);
00077 else id=Nvert-1;
00078 if(i == (npoints-1))CreateEdge(Nvert-1,id);
00079 }
00080
00081 if(i_full && j > 0){
00082 if(!UpdateEdgeHeap(Nedge+2*npoints))goto XXIT;
00083 if(!UpdateFaceHeap(Nface+2*npoints))goto XXIT;
00084 for(i=0;i<npoints;i++){
00085 CreateEdge(Nvert-npoints+i,Nvert-npoints-npoints+i);
00086 if(i > 0){
00087 CreateEdge(Nvert-npoints+i,Nvert-npoints-npoints+i-1);
00088 CreateFace(Nvert-npoints+i,
00089 Nvert-npoints-npoints+i-1,
00090 Nvert-npoints-npoints+i);
00091 CreateFace(Nvert-npoints+i,
00092 Nvert-npoints+i-1,
00093 Nvert-npoints-npoints+i-1);
00094 }
00095 else{
00096 CreateEdge(Nvert-npoints,Nvert-npoints-1);
00097 CreateFace(Nvert-npoints,
00098 Nvert-npoints-1,
00099 Nvert-npoints-npoints);
00100 CreateFace(Nvert-npoints,
00101 Nvert-1,
00102 Nvert-npoints-1);
00103 }
00104 }
00105 }
00106 }
00107 XXIT:;
00108 }
00109 fclose(fp);
00110 }
00111 else MessageBox(NULL,"No FILE",NULL,MB_OK);
00112 SetCursor(hSave);
00113 }
00114 return TRUE;
00115 }
00116
00117 static unsigned CALLBACK NameHookProc(HWND hwnd,UINT msg,
00118 WPARAM wparam,LPARAM lparam){
00119 char str[32];
00120 BOOL err;
00121 LPOFNOTIFY lp;
00122 switch( msg ) {
00123 case WM_INITDIALOG:
00124 if(i_full)SendDlgItemMessage(hwnd,DLG_SECTIONS_FACET,BM_SETCHECK,1,0);
00125 sprintf(str,"%.2lf",scale_v);
00126 SetDlgItemText(hwnd,DLG_SECTIONS_SCALE,str);
00127 return FALSE;
00128 case WM_COMMAND:
00129 switch(LOWORD(wparam)){
00130 case IDOK:{
00131 lp=NULL;
00132 goto JUMPHERE;
00133 }
00134 break;
00135 default: break;
00136 }
00137 break;
00138 case WM_NOTIFY:{
00139 lp=(LPOFNOTIFY)lparam;
00140 if(lp->hdr.code == CDN_FILEOK){
00141 JUMPHERE:
00142 if(SendDlgItemMessage(hwnd,DLG_SECTIONS_FACET,BM_GETCHECK,0,0))
00143 i_full=TRUE; else i_full=FALSE;
00144 GetDlgItemText(hwnd,DLG_SECTIONS_SCALE,str,31);
00145 scale_v=atof(str);
00146 if(scale_v < 0.00001)scale_v=0.00001;
00147 }
00148 }
00149 break;
00150 default: break;
00151 }
00152 return FALSE;
00153 }
00154
00155 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00156 HWND parent, HINSTANCE hInst){
00157 int i;
00158 OPENFILENAME ofn;
00159 char szFilter[128],title[256];
00160 DWORD version;
00161 strcpy(szFilter,szfilter);
00162 i=0; while(szFilter[i] != '\0'){
00163 if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00164 }
00165 memset(&ofn,0,sizeof(OPENFILENAME));
00166 ofn.lStructSize=sizeof(OPENFILENAME);
00167 ofn.hwndOwner=parent;
00168 ofn.lpstrFilter=szFilter;
00169 ofn.nFilterIndex=0;
00170 ofn.lpstrFile=szfile;
00171 ofn.nMaxFile=255;
00172 ofn.lpstrFileTitle=NULL;
00173 ofn.nMaxFileTitle=0;
00174 ofn.lpstrInitialDir=NULL;
00175 LoadString(hThisInstance,IDX_STRING2,title,255);
00176 ofn.lpstrTitle=title;
00177 ofn.hInstance=hInst;
00178 ofn.lpfnHook=NameHookProc;
00179 version=GetVersion();
00180 ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00181 OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON;
00182
00183 ofn.lpTemplateName=MAKEINTRESOURCE(DLG_SECTIONS);
00184 ofn.Flags |= OFN_EXPLORER;
00185
00186
00187
00188
00189
00190
00191 return GetOpenFileName(&ofn);
00192 }