LIBRARY.C

Go to the documentation of this file.
00001 /* file LIBRARY.C  library of helper functions */
00002 
00003 #define MODULE_LIBS 1
00004 
00005 #include "animate.h"
00006 #include "spin_dll.h"
00007 
00008 typedef struct tagNUMENTRY {
00009   long low,high,val;
00010   char *title;
00011   char *message;
00012 } NUMENTRY;
00013 
00014 
00015 static long local_grid_size=UNIT;
00016 
00017 static BOOL CALLBACK NumEntryDlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ){
00018  NUMENTRY *dp;
00019  BOOL err;
00020  int i;
00021  switch( msg ) {
00022    case WM_PAINT:
00023      PaintDialogBackground(hwnd,ghinst_main);
00024      break;
00025    case WM_INITDIALOG:{
00026        dp=(NUMENTRY *)lparam;
00027        SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)dp->title);
00028        SendDlgItemMessage(hwnd,DLG_NUMENTRY_TEXT,WM_SETTEXT,0,
00029                           (LPARAM)dp->message);
00030        SetDlgItemInt(hwnd,DLG_NUMENTRY_EDIT,dp->val,FALSE);
00031        SendDlgItemMessage(hwnd,DLG_NUMENTRY_SPIN,SPNM_SETRANGE,0,
00032                           MAKELPARAM(dp->low,dp->high));
00033        SendDlgItemMessage(hwnd,DLG_NUMENTRY_SPIN,SPNM_SETCRNTVALUE,
00034                           (WPARAM)dp->val,0);
00035        SendDlgItemMessage(hwnd,DLG_NUMENTRY_SPIN,SPNM_SETEDITCTRL,0,
00036                           (LPARAM)GetDlgItem(hwnd,DLG_NUMENTRY_EDIT));
00037        SetWindowLong(hwnd,GWL_USERDATA,lparam);
00038        CentreDialogOnCursor(hwnd);
00039      }
00040      return (TRUE);
00041    case WM_COMMAND:
00042       dp=(NUMENTRY *)GetWindowLong(hwnd,GWL_USERDATA);
00043       switch(LOWORD(wparam)){
00044         case DLG_NUMENTRY_SPIN:
00045           switch(HIWORD(wparam)){
00046             case SPNN_VALUECHANGE:
00047             break;
00048             default: break;
00049           }
00050           break;
00051         case IDCANCEL:
00052         case DLG_NUMENTRY_CANCEL:
00053           EndDialog(hwnd, -1);
00054           return(TRUE);
00055         case IDOK:
00056         case DLG_NUMENTRY_OK:
00057           i=GetDlgItemInt(hwnd,DLG_NUMENTRY_EDIT,&err,FALSE);
00058           if(!err)goto CANCELX;
00059           if(i > dp->high)i=dp->high; if(i < dp->low)i=dp->low;
00060           EndDialog(hwnd,i);
00061           return(TRUE);
00062           CANCELX:
00063           EndDialog(hwnd, -1);
00064           return TRUE;
00065         default:
00066           break;
00067       }
00068       break;
00069     default: break;
00070  }
00071  return(FALSE);
00072 }
00073 
00074 short RequestNumEntry(long val, long minval, long maxval,
00075                       char *title, char *message){
00076  int i;
00077  NUMENTRY Numentry;
00078  Numentry.low=minval;
00079  Numentry.high=maxval;
00080  Numentry.val=val;
00081  Numentry.title=title;
00082  Numentry.message=message;
00083  EnableToolPannels(ALL_PANNELS,FALSE);
00084  i=DialogBoxParam(ghinst_main,MAKEINTRESOURCE(DLG_NUMENTRY),ghwnd_main,
00085             (DLGPROC)NumEntryDlgProc,(LPARAM)&Numentry);
00086  EnableToolPannels(ALL_PANNELS,TRUE);
00087  return (short)i;
00088 }
00089 
00090 typedef struct tagSTRINGDLGLIST {
00091   int  len;
00092   char *title;
00093   char *string;
00094 } STRINGDLGLIST;
00095 
00096 static BOOL CALLBACK StringDlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ){
00097  HWND hctl;
00098  STRINGDLGLIST *dp;
00099  switch( msg ) {
00100    case WM_PAINT:
00101      PaintDialogBackground(hwnd,ghinst_main);
00102      break;
00103    case WM_INITDIALOG:{
00104        dp=(STRINGDLGLIST *)lparam;
00105        hctl=GetDlgItem(hwnd,DLG_STRING_EDIT);
00106        SendMessage(hctl,WM_SETTEXT,0,(LPARAM)dp->string);
00107        SendMessage(hctl,EM_LIMITTEXT,(WPARAM)dp->len,0);
00108        SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)dp->title);
00109        SetWindowLong(hwnd,GWL_USERDATA,lparam);
00110        CentreDialogOnCursor(hwnd);
00111      }
00112      return (TRUE);
00113    case WM_COMMAND:
00114       switch(LOWORD(wparam)){
00115         case IDOK:
00116         case IDCANCEL:
00117         case DLG_STRING_OK:
00118           dp=(STRINGDLGLIST *)GetWindowLong(hwnd,GWL_USERDATA);
00119           hctl=GetDlgItem(hwnd,DLG_STRING_EDIT);
00120           SendMessage(hctl,WM_GETTEXT,(WPARAM)dp->len,(LPARAM)dp->string);
00121           EndDialog(hwnd,TRUE);
00122           return(TRUE);
00123         default:
00124           break;
00125       }
00126       break;
00127     default: break;
00128  }
00129  return(FALSE);
00130 }
00131 
00132 int RequestCharString(int len, char *string, char *title){
00133  STRINGDLGLIST StringDlgList;
00134  StringDlgList.len=len;
00135  StringDlgList.string=string;
00136  StringDlgList.title=title;
00137  EnableToolPannels(ALL_PANNELS,FALSE);
00138  DialogBoxParam(ghinst_main,MAKEINTRESOURCE(DLG_STRING),ghwnd_main,
00139             (DLGPROC)StringDlgProc,(LPARAM)&StringDlgList);
00140  EnableToolPannels(ALL_PANNELS,TRUE);
00141  return 1;
00142 }
00143 
00144 void EnableToolPannels(int what_one,BOOL status){
00145   if(what_one & MAIN_WINDOW   )EnableWindow(ghwnd_main,status);
00146   if(what_one & TOOL_PANNEL   )EnableTools(status);
00147   if(what_one & COORD_PANNEL  )EnableWindow(ghwndCoord1,status);
00148   if(what_one & KEYS_WINDOW && ghwndTimeline != NULL)
00149                                EnableWindow(ghwndTimeline,status);
00150 }
00151 
00152 typedef struct tagSELECTDLGLIST {
00153   int n;
00154   char *title;
00155   char **list;
00156 } SELECTDLGLIST;
00157 
00158 BOOL CALLBACK ItemSelectDlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ){
00159  int i;
00160  SELECTDLGLIST *dp;
00161  HWND hctl;
00162  switch( msg ) {
00163    case WM_PAINT:
00164      PaintDialogBackground(hwnd,ghinst_main);
00165      break;
00166    case WM_INITDIALOG:{
00167        dp=(SELECTDLGLIST *)lparam;
00168        hctl=GetDlgItem(hwnd,DLG_CHOOSE_LIST);
00169        for(i=0;i<dp->n;i++)SendMessage(hctl,LB_ADDSTRING,0,(LPARAM)dp->list[i]);
00170        SendMessage(hctl,LB_SETCURSEL,0,0);
00171        SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)dp->title);
00172        CentreDialogOnCursor(hwnd);
00173      }
00174      return (TRUE);
00175    case WM_COMMAND:
00176       switch(LOWORD(wparam)){
00177         case DLG_CHOOSE_LIST:
00178           switch(HIWORD(wparam)){
00179             case LBN_DBLCLK:
00180             SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(DLG_CHOOSE_OK,0),0);
00181               break;
00182             default:
00183               break;
00184           }
00185           break;
00186         case IDCANCEL:
00187         case DLG_CHOOSE_CANCEL:
00188           EndDialog(hwnd, -1);
00189           return (TRUE);
00190         case IDOK:
00191         case DLG_CHOOSE_OK:
00192           hctl=GetDlgItem(hwnd,DLG_CHOOSE_LIST);
00193           i=SendMessage(hctl,LB_GETCURSEL,0,0);
00194           EndDialog(hwnd,i);
00195           return(TRUE);
00196         default:
00197           break;
00198       }
00199       break;
00200  }
00201  return(FALSE);
00202 }
00203 
00204 int SelectScrolledItemList(int n, char **list, char *title,
00205                            BOOL wide, HWND parent){
00206  int i;
00207  HWND hwnd;
00208  SELECTDLGLIST SelectDlgList;
00209  SelectDlgList.n=n;
00210  SelectDlgList.list=list;
00211  SelectDlgList.title=title;
00212  if(!wide)i=DialogBoxParam(ghinst_main,MAKEINTRESOURCE(DLG_CHOOSE),parent,
00213             (DLGPROC)ItemSelectDlgProc,(LPARAM)&SelectDlgList);
00214  else i=DialogBoxParam(ghinst_main,MAKEINTRESOURCE(DLG_CHOOSE_WIDE),parent,
00215             (DLGPROC)ItemSelectDlgProc,(LPARAM)&SelectDlgList);
00216  return i;
00217 }
00218 
00219 static int SelectItemListID;
00220 
00221 #if 0
00222 // these methods are not used now
00223 static LRESULT CALLBACK SelectItemListWndProc(HWND hwnd, UINT msg,
00224                                     WPARAM wparam, LPARAM lparam ){
00225  switch( msg ){
00226    case WM_COMMAND:
00227      SelectItemListID=LOWORD(wparam);
00228    break;
00229    default:
00230    return( DefWindowProc( hwnd, msg, wparam, lparam ) );
00231  }
00232  return( 0L );
00233 }
00234 
00235 int SelectItemList(int n, char **list, char *title){
00236  WNDCLASS wc;
00237  BOOL     rc;
00238  HWND     hwnd;
00239  HMENU    hmenu;
00240  POINT    p;
00241  int i;
00242  SelectItemListID = -1;
00243  wc.lpszClassName = "OFX:TEMPCLASS";
00244  wc.style = CS_HREDRAW | CS_VREDRAW;
00245  wc.lpfnWndProc = (WNDPROC)SelectItemListWndProc;
00246  wc.cbClsExtra = 0;
00247  wc.cbWndExtra = 0;
00248  wc.hInstance = ghinst_main;
00249  wc.hIcon = NULL;
00250  wc.hCursor = NULL;
00251  wc.hbrBackground = NULL;
00252  wc.lpszMenuName = NULL;
00253  rc = RegisterClass( &wc );
00254  if(!rc)return -1;
00255  hwnd = CreateWindow(
00256      wc.lpszClassName,"  ",
00257      0,
00258      0,0,0,0,NULL,NULL,ghinst_main,NULL);
00259  if(hwnd != NULL){
00260    if((hmenu=CreatePopupMenu()) != NULL){
00261      for(i=0;i<n;i++)AppendMenu(hmenu,MF_ENABLED,(UINT)i,(LPCTSTR)list[i]);
00262      GetCursorPos(&p);
00263      SendPrgmText(title);
00264      MessageBeep(MB_ICONQUESTION);
00265      TrackPopupMenu(hmenu,TPM_CENTERALIGN | TPM_LEFTBUTTON,(int)p.x,(int)p.y,0,hwnd,NULL);
00266    }
00267    {MSG msg;  /* allow WM_COMMAND message to be processed */
00268     while(PeekMessage(&msg,hwnd,0,0,PM_REMOVE)){
00269       TranslateMessage(&msg);
00270       DispatchMessage(&msg);
00271     }
00272    }
00273    DestroyMenu(hmenu);
00274    DestroyWindow(hwnd);
00275  }
00276  UnregisterClass(wc.lpszClassName,wc.hInstance);
00277  return SelectItemListID;
00278 }
00279 
00280 static BOOL CALLBACK EnumSelectItemsProc(HWND hwnd, LPARAM lparam){
00281  char m[8];
00282  SendMessage(hwnd,WM_GETTEXT,8,(LPARAM)&m);
00283  if(m[0] > '`' && m[0] < '{')m[0] -= 32;
00284  if(lparam > '`' && lparam < '{')lparam -= 32;
00285  if((LPARAM)m[0] == lparam){
00286    SendMessage(GetParent(hwnd),WM_COMMAND,
00287                MAKELONG(0,BN_CLICKED),(LPARAM)hwnd);
00288    return FALSE;
00289  }
00290  return TRUE;
00291 }
00292 
00293 static LRESULT CALLBACK SelectItemsWndProc(HWND hwnd, UINT msg, WPARAM wparam,
00294                                     LPARAM lparam ){
00295  switch( msg ){
00296    case WM_KEYDOWN:
00297      switch(wparam){
00298        case VK_ESCAPE:
00299        SelectItemListID = -1;
00300        PostQuitMessage(0);
00301      }
00302      return( DefWindowProc( hwnd, msg, wparam, lparam ) );
00303    case WM_CHAR:  /* check first character of button names */
00304      EnumChildWindows(hwnd,EnumSelectItemsProc,(LPARAM)wparam);
00305      return( DefWindowProc( hwnd, msg, wparam, lparam ) );
00306    case WM_COMMAND:
00307      if(HIWORD(wparam) == BN_CLICKED){
00308        SelectItemListID=GetWindowLong((HWND)lparam,GWL_ID);
00309        PostQuitMessage(0);
00310      }
00311      break;
00312    default:
00313    return( DefWindowProc( hwnd, msg, wparam, lparam ) );
00314  }
00315  return( 0L );
00316 }
00317 
00318 int SelectItems(int n, char **list, char *title, int where){
00319  WNDCLASS   wc;
00320  BOOL       rc;
00321  HWND       hwnd,*hwndlist,*original;
00322  TEXTMETRIC tm;
00323  HDC        hdc;
00324  POINT      p;
00325  MSG        msg;
00326  int i,j,x,y,dx,dy,bsx,bsy;
00327  original=GetActiveWindow();
00328  wc.lpszClassName = "OFX:TEMPCLASS";
00329  wc.style = CS_SAVEBITS;
00330  wc.lpfnWndProc = (WNDPROC)SelectItemsWndProc;
00331  wc.cbClsExtra = 0;
00332  wc.cbWndExtra = 0;
00333  wc.hInstance = ghinst_main;
00334  wc.hIcon = NULL;
00335  wc.hCursor = NULL;
00336  wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND+1);
00337  wc.lpszMenuName = NULL;
00338  rc = RegisterClass( &wc );
00339  if(!rc)return -1;
00340  SelectItemListID = -1;
00341  hdc=GetDC(ghwnd_main);
00342  GetTextMetrics(hdc,&tm);
00343  ReleaseDC(ghwnd_main,hdc);
00344  bsx=strlen(title)+2;
00345  for(i=0;i<n;i++)if(strlen(list[i]) > bsx)bsx=strlen(list[i]);
00346  bsx += 2; bsx *= tm.tmAveCharWidth;
00347  bsy = tm.tmHeight+8;
00348  dx=bsx+20; dy=(bsy+8)*(n+1)-10;
00349  GetCursorPos(&p);
00350  x=max(p.x-dx/2,0); x=min(x,Xres-dx);
00351  y=max(p.y-dy/2,0); y=min(y,Yres-dy);
00352  hwnd = CreateWindow(
00353      wc.lpszClassName,title,
00354      WS_POPUP | WS_CLIPSIBLINGS | WS_CAPTION,
00355      x,y,dx,dy,ghwnd_main,NULL,ghinst_main,NULL);
00356  if(hwnd != NULL){
00357    if((hwndlist = (HWND *)X__Malloc(n*sizeof(HWND))) != NULL){
00358      y=5;
00359      for(i=0;i<n;i++){
00360        if((hwndlist[i] = CreateWindow("BUTTON","Stop",
00361           WS_CHILD | BS_DEFPUSHBUTTON | WS_VISIBLE | WS_TABSTOP,
00362           10,y,
00363           bsx,bsy,hwnd,(HMENU)i,ghinst_main,NULL)) == NULL){
00364          for(j=0;j<i;i++)DestroyWindow(hwndlist[i]);
00365          goto BREAK_LOOP;
00366        }
00367        y += (bsy+8);
00368      }
00369      ShowWindow(hwnd,SW_SHOWNA);
00370      SetActiveWindow(hwnd);
00371      for(i=0;i<n;i++){
00372        SendMessage(hwndlist[i],WM_SETTEXT,0,(LPARAM)(list[i]));
00373        ShowWindow(hwndlist[i],SW_SHOWNA);
00374      }
00375      EnableToolPannels(ALL_PANNELS,FALSE);
00376      SetFocus(hwnd);
00377      while (GetMessage(&msg,NULL,0,0)){
00378        TranslateMessage(&msg);
00379        DispatchMessage(&msg);
00380      }
00381      EnableToolPannels(ALL_PANNELS,TRUE);
00382      for(i=0;i<n;i++)DestroyWindow(hwndlist[i]);
00383    }
00384    BREAK_LOOP:
00385    X__Free(hwndlist);
00386    DestroyWindow(hwnd);
00387  }
00388  UnregisterClass(wc.lpszClassName,wc.hInstance);
00389  if(original != NULL)SetActiveWindow(original);
00390  return SelectItemListID;
00391 }
00392 #endif
00393 
00394 void  ActivateAllMenus(HWND hwnd, UINT fuFlags){
00395  static WORD enable_state[256];  /* must be >= number of menu commands */
00396  int id,i,j,k,n,m,o,c=0;
00397  HMENU hmenu,hsubmenu,hsubsubmenu;
00398  hmenu=GetMenu(hwnd);
00399  n=GetMenuItemCount(hmenu);
00400  if(n < 1)return;
00401  for(i=0;i<n;i++){
00402   if((hsubmenu=GetSubMenu(hmenu,i)) == NULL){
00403     if((id=GetMenuItemID(hmenu,i)) < 0xffffffff){
00404       if(fuFlags == MF_GRAYED){
00405         enable_state[c] = GetMenuState(hmenu,id,MF_BYCOMMAND);
00406         EnableMenuItem(hmenu,id,fuFlags);
00407       }
00408       else EnableMenuItem(hmenu,id,enable_state[c]);
00409       c++;
00410     }
00411   }
00412   else{
00413     m=GetMenuItemCount(hsubmenu);
00414     for(j=0;j<m;j++){
00415       if((hsubsubmenu=GetSubMenu(hsubmenu,j)) == NULL){
00416         if((id=GetMenuItemID(hsubmenu,j)) < 0xffffffff){
00417           if(fuFlags == MF_GRAYED){
00418             enable_state[c] = GetMenuState(hsubmenu,id,MF_BYCOMMAND);
00419             EnableMenuItem(hsubmenu,id,fuFlags);
00420           }
00421           else EnableMenuItem(hsubmenu,id,enable_state[c]);
00422           c++;
00423         }
00424       }
00425       else{
00426         o=GetMenuItemCount(hsubsubmenu);
00427         for(k=0;k<o;k++){
00428           if((id=GetMenuItemID(hsubsubmenu,k)) < 0xffffffff){
00429             if(fuFlags == MF_GRAYED){
00430               enable_state[c] = GetMenuState(hsubsubmenu,id,MF_BYCOMMAND);
00431               EnableMenuItem(hsubsubmenu,id,fuFlags);
00432             }
00433             else EnableMenuItem(hsubsubmenu,id,enable_state[c]);
00434             c++;
00435           }
00436         }
00437       }
00438     }
00439   }
00440  }
00441 }
00442 
00443 PSTR FileInPath(PSTR pstrPath){
00444  PSTR pstr;
00445  pstr = pstrPath + strlen(pstrPath);
00446  while (pstr > pstrPath) {
00447      pstr = (AnsiPrev(pstrPath, pstr));
00448      if (*pstr == '\\' || *pstr == ':' || *pstr == '/') {
00449          pstr = (AnsiNext(pstr));
00450          break;
00451      }
00452  }
00453  return pstr;
00454 }
00455 
00456 #define ATOL 0.5
00457 
00458 void GetWorldCoords0(int W, long *x, long *y, long *z,
00459                      int hpos, int vpos);
00460 void GetWindowCoords0(int W, long x, long y, long z,
00461                      int *hpos, int *vpos);
00462 void GetWorldCoords1(int W, long *x, long *y, long *z,
00463                     int hpos, int vpos);
00464 void GetWindowCoords1(int W, long x, long y, long z,
00465                      int *hpos, int *vpos);
00466 
00467 void GetWorldCoords0(int W, long *x, long *y, long *z,
00468                     int hpos, int vpos){
00469   if(W == TRITOP){
00470     *x=(long)((double)(hpos-WindowCentreX[0])*WindowPixelSize)+TVcentreX;
00471     *y=(long)((double)(WindowCentreY[0]-vpos)*WindowPixelSize)+TVcentreY;
00472     *z=NpointerZ;
00473   }
00474   else if(W == TRIFRONT){
00475     *x=(long)((double)(hpos-WindowCentreX[1])*WindowPixelSize)+TVcentreX;
00476     *y=NpointerY;
00477     *z=(long)((double)(WindowCentreY[1]-vpos)*WindowPixelSize)+TVcentreZ;
00478   }
00479   else if(W == TRIRIGHT){
00480     *x=NpointerX;
00481     *y=(long)((double)(hpos-WindowCentreX[2])*WindowPixelSize)+TVcentreY;
00482     *z=(long)((double)(WindowCentreY[2]-vpos)*WindowPixelSize)+TVcentreZ;
00483   }
00484 }
00485 
00486 void GetWindowCoords0(int W, long x, long y, long z, int *hpos, int *vpos){
00487   if(W == TRITOP){
00488    *hpos=(int)((double)WindowCentreX[0]+(double)(x-TVcentreX)/WindowPixelSize+ATOL);
00489    *vpos=(int)((double)WindowCentreY[0]-(double)(y-TVcentreY)/WindowPixelSize+ATOL);
00490   }
00491   else if(W == TRIFRONT){
00492    *hpos=(int)((double)WindowCentreX[1]+(double)(x-TVcentreX)/WindowPixelSize+ATOL);
00493    *vpos=(int)((double)WindowCentreY[1]-(double)(z-TVcentreZ)/WindowPixelSize+ATOL);
00494   }
00495   else if(W == TRIRIGHT){
00496    *hpos=(int)((double)WindowCentreX[2]+(double)(y-TVcentreY)/WindowPixelSize+ATOL);
00497    *vpos=(int)((double)WindowCentreY[2]-(double)(z-TVcentreZ)/WindowPixelSize+ATOL);
00498   }
00499 }
00500 
00501 void GetWorldCoords1(int W, long *x, long *y, long *z,
00502                     int hpos, int vpos){
00503   if(W == TRITOP){
00504     *x=(long)((double)(WindowCentreX[0]-hpos)*WindowPixelSize)+TVcentreX;
00505     *y=(long)((double)(vpos-WindowCentreY[0])*WindowPixelSize)+TVcentreY;
00506     *z=NpointerZ;
00507   }
00508   else if(W == TRIFRONT){
00509     *x=(long)((double)(WindowCentreX[1]-hpos)*WindowPixelSize)+TVcentreX;
00510     *y=NpointerY;
00511     *z=(long)((double)(WindowCentreY[1]-vpos)*WindowPixelSize)+TVcentreZ;
00512   }
00513   else if(W == TRIRIGHT){
00514     *x=NpointerX;
00515     *y=(long)((double)(WindowCentreX[2]-hpos)*WindowPixelSize)+TVcentreY;
00516     *z=(long)((double)(WindowCentreY[2]-vpos)*WindowPixelSize)+TVcentreZ;
00517   }
00518 }
00519 
00520 void GetWindowCoords1(int W, long x, long y, long z,
00521                      int *hpos, int *vpos){
00522  double wdx,wdy;
00523   if(W == TRITOP){
00524    *hpos=(int)((double)WindowCentreX[0]-(double)(x-TVcentreX)/WindowPixelSize+ATOL);
00525    *vpos=(int)((double)WindowCentreY[0]+(double)(y-TVcentreY)/WindowPixelSize+ATOL);
00526   }
00527   else if(W == TRIFRONT){
00528    *hpos=(int)((double)WindowCentreX[1]-(double)(x-TVcentreX)/WindowPixelSize+ATOL);
00529    *vpos=(int)((double)WindowCentreY[1]-(double)(z-TVcentreZ)/WindowPixelSize+ATOL);
00530   }
00531   else if(W == TRIRIGHT){
00532    *hpos=(int)((double)WindowCentreX[2]-(double)(y-TVcentreY)/WindowPixelSize+ATOL);
00533    *vpos=(int)((double)WindowCentreY[2]-(double)(z-TVcentreZ)/WindowPixelSize+ATOL);
00534   }
00535 }
00536 
00537 void SetUpWindowBoxView(int view){
00538  if(view == 0){
00539    GetWorldCoords  = GetWorldCoords0;
00540    GetWindowCoords = GetWindowCoords0;
00541    WindowBox_view=0;
00542  }
00543  else if(view == 1){
00544    WindowBox_view=1;
00545    GetWorldCoords  = GetWorldCoords1;
00546    GetWindowCoords = GetWindowCoords1;
00547  }
00548 }
00549 
00550 void GetTriview(BOOL reset){
00551  double scale;
00552  if(reset){
00553    TVsizeX=TVsizeY=TVsizeZ=UNIT2*4;
00554    TVcentreX=TVcentreY=TVcentreZ=0;
00555  }
00556  if(View == TRIVIEW){
00557    scale=(double)WindowSizeX[1]/(double)WindowSizeY[1];
00558    TVsizeX=(long)((double)TVsizeZ*scale);
00559    scale=(double)WindowSizeX[2]/(double)WindowSizeY[1];
00560    TVsizeY=(long)((double)TVsizeZ*scale);
00561    scale=(double)WindowSizeY[0]/(double)WindowSizeX[1];
00562    TVsizeY=max(TVsizeY,(long)((double)TVsizeX*scale));
00563  }
00564  else{
00565    scale=(double)WindowSizeX[ActiveView]/(double)WindowSizeY[ActiveView];
00566    if     (ActiveView == TRITOP){
00567      TVsizeX=(long)((double)TVsizeZ*scale);
00568    }
00569    else if(ActiveView == TRIFRONT){
00570      TVsizeY=TVsizeX=(long)((double)TVsizeZ*scale);
00571    }
00572    else if(ActiveView == TRIRIGHT){
00573      TVsizeY=TVsizeX=(long)((double)TVsizeZ*scale);
00574    }
00575  }
00576  TVpointX=(TVcentreX-TVsizeX/2);
00577  TVpointY=(TVcentreY-TVsizeY/2);
00578  TVpointZ=(TVcentreZ-TVsizeZ/2);
00579  WindowPixelSize=(double)TVsizeZ/(double)WindowSizeY[1];
00580 }
00581 
00582 void Draw3dCursor(void){
00583  int i;
00584  HDC hdc;
00585  int ifd,ild;
00586  if(View == TRIVIEW){ifd=0;ild=3;}
00587  else               {ifd=ActiveView; ild=ifd+1;}
00588  for(i=ifd;i<ild;i++){
00589    hdc=GetDC(ghwnd_triview[i]);
00590 //SelectPalette(hdc,ghpaletteScreen,FALSE);
00591 //RealizePalette (hdc);
00592    DrawOne3dCursor(hdc,i);
00593    ReleaseDC(ghwnd_triview[i],hdc);
00594  }
00595 }
00596 
00597 void DrawOne3dCursor(HDC hdc, int i){
00598  int sho,svo,oldROP;
00599  HPEN holdpen;
00600  GetWindowCoords(i,NpointerX,NpointerY,NpointerZ,&sho,&svo);
00601  oldROP=SetROP2(hdc,R2_XORPEN);
00602  holdpen=SelectObject(hdc,ghCursorPen);
00603  if(CursorToggle == 0){
00604    MoveToEx(hdc,sho-10,svo,NULL); LineTo(hdc,sho-3,svo);
00605    MoveToEx(hdc,sho+3,svo,NULL);  LineTo(hdc,sho+10,svo);
00606    MoveToEx(hdc,sho,svo-10,NULL); LineTo(hdc,sho,svo-3);
00607    MoveToEx(hdc,sho,svo+3,NULL);  LineTo(hdc,sho,svo+10);
00608  }
00609  else{
00610    MoveToEx(hdc,0,svo,NULL); LineTo(hdc,WindowSizeX[i],svo);
00611    MoveToEx(hdc,sho,0,NULL); LineTo(hdc,sho,WindowSizeY[i]);
00612  }
00613  SelectObject(hdc,holdpen);
00614  SetROP2(hdc,oldROP);
00615 }
00616 
00617 void Move3dCursor(int stor, int xw, int yw){
00618  int i;
00619  HDC hdc;
00620  HWND hwnd;
00621  static int xws=0,yws=0;
00622  long x,y,z,g2;
00623  int ifd,ild,dx,dy,dxa,dya;
00624  if(stor){
00625    xws=xw; yws=yw;
00626  }
00627  else if((GetKeyState(VK_SHIFT) & 0x8000)){
00628 //         (tool == GRABBER || tool == NODETOOL)){
00629    dx=xw-xws; dy=yw-yws;  dxa=abs(dx); dya=abs(dy);
00630    if(dxa == 0)dxa=1;
00631    if(dya == 0)dya=1;
00632    if     (dya < dxa/2)yw=yws;
00633    else if(dxa < dya/2)xw=xws;
00634    else if(dya < dxa)yw=yws+(int)((double)dxa*(double)dy/(double)dya);
00635    else if(dxa < dya)xw=xws+(int)((double)dya*(double)dx/(double)dxa);
00636  }
00637  if(View == TRIVIEW){ifd=0;ild=3;}
00638  else               {ifd=ActiveView; ild=ifd+1;}
00639  for(i=ifd;i<ild;i++){
00640    hwnd=ghwnd_triview[i];
00641    hdc=GetDC(hwnd);
00642 //   SelectPalette(hdc,ghpaletteScreen,FALSE);
00643 //   RealizePalette (hdc);
00644    DrawOne3dCursor(hdc,i);
00645    ReleaseDC(hwnd,hdc);
00646  }
00647  GetWorldCoords(ActiveView,&x,&y,&z,xw,yw);
00648  if(grid_on){
00649 //   g2=grid_size/2;
00650 //   x = lrulerx+((x+(x >= 0  ? g2 : -g2)-lrulerx)/grid_size)*grid_size;
00651 //   y = lrulery+((y+(y >= 0  ? g2 : -g2)-lrulery)/grid_size)*grid_size;
00652 //   z = lrulerz+((z+(z >= 0  ? g2 : -g2)-lrulerz)/grid_size)*grid_size;
00653    g2=local_grid_size/2;
00654    x = lrulerx+((x+(x >= 0  ? g2 : -g2)-lrulerx)/local_grid_size)*local_grid_size;
00655    y = lrulery+((y+(y >= 0  ? g2 : -g2)-lrulery)/local_grid_size)*local_grid_size;
00656    z = lrulerz+((z+(z >= 0  ? g2 : -g2)-lrulerz)/local_grid_size)*local_grid_size;
00657  }
00658  NpointerX=x; NpointerY=y; NpointerZ=z;
00659  for(i=ifd;i<ild;i++){
00660    hwnd=ghwnd_triview[i];
00661    hdc=GetDC(hwnd);
00662 //   SelectPalette(hdc,ghpaletteScreen,FALSE);
00663 //   RealizePalette (hdc);
00664    DrawOne3dCursor(hdc,i);
00665    ReleaseDC(hwnd,hdc);
00666  }
00667  if(coords_visible)UpdateRuler(0);
00668 }
00669 
00670 #define ARROW_ICON_SIZE 12
00671 
00672 static HBITMAP hbmArrow[6]={NULL,NULL,NULL,NULL,NULL,NULL};
00673 static int ArrowOK,ArrowID[6]={IDBM_ARROW_Zp,IDBM_ARROW_Zm,
00674                                IDBM_ARROW_Xp,IDBM_ARROW_Xm,
00675                                IDBM_ARROW_Yp,IDBM_ARROW_Ym};
00676 
00677 void LoadArrowIcons(void){
00678  int i;
00679 #if 0
00680  unsigned char camera[64]={
00681   0x00,0x03,0xc0,0x00,
00682   0x00,0x03,0xc0,0x00,
00683   0x00,0x0f,0xf8,0x78,
00684   0x00,0x0f,0xf8,0x48,
00685   0x0f,0xfc,0x1f,0xf8,
00686   0x1f,0xf8,0x0f,0xfc,
00687   0x19,0xf0,0x07,0xdc,
00688   0x19,0xf0,0x07,0xdc,
00689   0x19,0xf0,0x07,0xdc,
00690   0x19,0xf0,0x07,0xdc,
00691   0x19,0xf0,0x07,0xdc,
00692   0x19,0xf8,0x0f,0xdc,
00693   0x1f,0xfc,0x1f,0xfc,
00694   0x0f,0xff,0xff,0xf8,
00695   0x00,0x03,0xe0,0x00,
00696   0x00,0x00,0x00,0x00
00697  };
00698  unsigned char light[32] = {
00699   0x00,0x00,  0x01,0x80,
00700   0x03,0xc0,  0x02,0x40,
00701   0x02,0x40,  0x02,0x40,
00702   0x02,0x40,  0x02,0x40,
00703   0x04,0x20,  0x08,0x10,
00704   0x10,0x08,  0x10,0x08,
00705   0x10,0x08,  0x08,0x10,
00706   0x04,0x20,  0x03,0xc0
00707  };
00708 #endif
00709  ArrowOK=1;
00710 // Camera and Light use loaded bitmaps. (1 bit bitmaps !!!!)
00711 // ghCameraBitmap=CreateBitmap(32,16,1,1,camera);
00712 // ghLightBitmap=CreateBitmap(16,16,1,1,light);
00713  ghCameraBitmap=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_I_CAMERA));
00714  ghLightBitmap=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_I_LIGHT));
00715  for(i=0;i<6;i++){
00716    if((hbmArrow[i]=LoadBitmap(ghinst_main,
00717       MAKEINTRESOURCE(ArrowID[i]))) == NULL)ArrowOK=0;
00718  }
00719  if(!Preferences.buttons){
00720    if((hbmName[0]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_Th))) == NULL)ArrowOK=0;
00721    if((hbmName[1]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_Rh))) == NULL)ArrowOK=0;
00722    if((hbmName[2]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_Sh))) == NULL)ArrowOK=0;
00723    if((hbmName[4]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_Fh))) == NULL)ArrowOK=0;
00724  }
00725  else{
00726    if((hbmName[0]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_T))) == NULL)ArrowOK=0;
00727    if((hbmName[1]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_R))) == NULL)ArrowOK=0;
00728    if((hbmName[2]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_S))) == NULL)ArrowOK=0;
00729    if((hbmName[4]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_F))) == NULL)ArrowOK=0;
00730  }
00731  if((hbmName[5]=LoadBitmap(ghinst_main,MAKEINTRESOURCE(IDBM_WIN_C))) == NULL)ArrowOK=0;
00732 }
00733 
00734 void DrawArrowIcons(HDC hDC, int id){
00735  int i,ic,x,y;
00736  HDC hMemDC;
00737  HBITMAP hbmOld;
00738  HBRUSH holdBrush;
00739  static int arrow_table[2][3][4]={
00740   {{3,2,4,5} ,     /* top   */
00741    {3,2,0,1} ,     /* rear  */
00742    {5,4,0,1} } ,   /* right */
00743   {{2,3,5,4} ,
00744    {2,3,0,1} ,
00745    {4,5,0,1} }
00746  };
00747  if(!ArrowOK)return;
00748  hMemDC = CreateCompatibleDC(hDC);
00749  for(i=0;i<4;i++){
00750    ic=arrow_table[WindowBox_view][id][i];
00751    if(i == 0)hbmOld = SelectObject(hMemDC,hbmArrow[ic]);
00752    else      SelectObject(hMemDC,hbmArrow[ic]);
00753    if     (i == 0){x=0; y=WindowSizeY[id]/2-ARROW_ICON_SIZE/2;}
00754    else if(i == 1){x=WindowSizeX[id]-ARROW_ICON_SIZE-1;
00755                    y=WindowSizeY[id]/2-ARROW_ICON_SIZE/2;}
00756    else if(i == 2){x=WindowSizeX[id]/2-ARROW_ICON_SIZE/2; y=0;}
00757    else if(i == 3){x=WindowSizeX[id]/2-ARROW_ICON_SIZE/2;
00758                    y=WindowSizeY[id]-ARROW_ICON_SIZE-1;}
00759    BitBlt(hDC,x,y,ARROW_ICON_SIZE,ARROW_ICON_SIZE,hMemDC,0,0,SRCPAINT);
00760  }
00761  SelectObject(hMemDC,hbmName[id]);
00762 
00763 // x=WindowSizeX[id]-WINDOW_ID_XSIZE-1;
00764 // y=WindowSizeY[id]-WINDOW_ID_YSIZE-1;
00765  x=0;
00766  y=0;
00767 
00768  if(!Preferences.buttons)
00769       BitBlt(hDC,x,y,WINDOW_ID_XSIZE,WINDOW_ID_YSIZE,hMemDC,0,0,SRCPAINT);
00770  else BitBlt(hDC,x,y,WINDOW_ID_XSIZE,WINDOW_ID_YSIZE,hMemDC,0,0,SRCCOPY);
00771  if(View == ONEVIEW){
00772 
00773 //   x=1;
00774 //   y=WindowSizeY[id]-WINDOW_ID_YSIZE-1;
00775 
00776    x=WindowSizeX[id]-2*WINDOW_ID_XSIZE-1;
00777    y=0;
00778 
00779    holdBrush=SelectObject(hDC,GetStockObject(LTGRAY_BRUSH));
00780    for(i=0;i<3;i++)if(i != id){
00781      SelectObject(hMemDC,hbmName[i]);
00782      if(!Preferences.buttons){
00783        BitBlt(hDC,x,y,WINDOW_ID_XSIZE,WINDOW_ID_YSIZE,hMemDC,0,0,0x00220326); /*  DSna */
00784        BitBlt(hDC,x,y,WINDOW_ID_XSIZE,WINDOW_ID_YSIZE,hMemDC,0,0,0x00ea02e9); /* DPSao */
00785      }
00786      else BitBlt(hDC,x,y,WINDOW_ID_XSIZE,WINDOW_ID_YSIZE,hMemDC,0,0,SRCCOPY);
00787      x+=WINDOW_ID_XSIZE;
00788    }
00789    SelectObject(hDC,holdBrush);
00790  }
00791  SelectObject(hMemDC, hbmOld);
00792  DeleteDC(hMemDC);
00793 }
00794 
00795 int CheckWindowIcon(int xi, int yi){
00796 #if 0
00797  int i,x,y;
00798  if(xi > WindowSizeX[ActiveView]-WINDOW_ID_XSIZE &&
00799     xi < WindowSizeX[ActiveView] &&
00800     yi > WindowSizeY[ActiveView]-WINDOW_ID_YSIZE &&
00801     yi < WindowSizeY[ActiveView])return 4;
00802  if(View == ONEVIEW){
00803    if(xi > 1 && xi < WINDOW_ID_XSIZE &&
00804       yi > WindowSizeY[ActiveView]-WINDOW_ID_YSIZE &&
00805       yi < WindowSizeY[ActiveView])return 5;
00806    if(xi > 1+WINDOW_ID_XSIZE && xi < 2*WINDOW_ID_XSIZE &&
00807       yi > WindowSizeY[ActiveView]-WINDOW_ID_YSIZE &&
00808       yi < WindowSizeY[ActiveView])return 6;
00809  }
00810 #endif
00811  if(xi >=0 &&
00812     xi < WINDOW_ID_XSIZE &&
00813     yi >=0 &&
00814     yi < WINDOW_ID_YSIZE)return 4;
00815  if(View == ONEVIEW){
00816    if(xi > WindowSizeX[ActiveView]-2*WINDOW_ID_XSIZE &&
00817       xi < WindowSizeX[ActiveView]-WINDOW_ID_XSIZE &&
00818       yi > 0 &&
00819       yi < WINDOW_ID_YSIZE)return 5;
00820    if(xi > WindowSizeX[ActiveView]-WINDOW_ID_XSIZE &&
00821       xi < WindowSizeX[ActiveView] &&
00822       yi > 0 &&
00823       yi < WINDOW_ID_YSIZE)return 6;
00824  }
00825  return -1;
00826 }
00827 
00828 void InvertWindowIcon(int i, HWND hwnd){
00829  HDC hdc;
00830  RECT rc;
00831  if     (i == 0){rc.left=0;
00832                  rc.top=WindowSizeY[ActiveView]/2-ARROW_ICON_SIZE/2;}
00833  else if(i == 1){rc.left=WindowSizeX[ActiveView]-ARROW_ICON_SIZE-1;
00834                  rc.top=WindowSizeY[ActiveView]/2-ARROW_ICON_SIZE/2;}
00835  else if(i == 2){rc.left=WindowSizeX[ActiveView]/2-ARROW_ICON_SIZE/2;
00836                  rc.top=0;}
00837  else if(i == 3){rc.left=WindowSizeX[ActiveView]/2-ARROW_ICON_SIZE/2;
00838                  rc.top=WindowSizeY[ActiveView]-ARROW_ICON_SIZE-1;}
00839  if(i > 3){
00840 #if 0
00841    rc.top = WindowSizeY[ActiveView]-WINDOW_ID_YSIZE;
00842    if     (i == 4)rc.left=WindowSizeX[ActiveView]-WINDOW_ID_XSIZE;
00843    else if(i == 5)rc.left=1;
00844    else if(i == 6)rc.left=1+WINDOW_ID_XSIZE;
00845 #endif
00846    rc.top = 0;
00847    if     (i == 4)rc.left=0;
00848    else if(i == 5)rc.left=WindowSizeX[ActiveView]-2*WINDOW_ID_XSIZE;
00849    else if(i == 6)rc.left=WindowSizeX[ActiveView]-WINDOW_ID_XSIZE;
00850    rc.right=rc.left+WINDOW_ID_XSIZE;
00851    rc.bottom=rc.top+WINDOW_ID_YSIZE;
00852  }
00853  else{  /* other corner for arrows */
00854    rc.right=rc.left+ARROW_ICON_SIZE;
00855    rc.bottom=rc.top+ARROW_ICON_SIZE;
00856  }
00857  hdc=GetDC(hwnd);
00858  InvertRect(hdc,&rc);
00859  ReleaseDC(hwnd,hdc);
00860  return;
00861 }
00862 
00863 int CheckViewWindowIcon(int xi, int yi){
00864  int i,x,y;
00865 // if(xi > WindowViewXsize-WINDOW_ID_VSIZE && xi < WindowViewXsize &&
00866 //    yi > WindowViewYsize-WINDOW_ID_YSIZE && yi < WindowViewYsize)return 1;
00867 
00868  if(xi > 0 && xi < WINDOW_ID_VSIZE &&
00869     yi > 0 && yi < WINDOW_ID_YSIZE)return 1;
00870 
00871  return -1;
00872 }
00873 
00874 void InvertViewWindowIcon(int i, HWND hwnd){
00875  HDC hdc;
00876  RECT rc;
00877  if(i == 1){
00878 //   rc.top=WindowViewYsize-WINDOW_ID_YSIZE;
00879 //   rc.left=WindowViewXsize-WINDOW_ID_VSIZE;
00880 
00881    rc.top=0;
00882    rc.left=0;
00883 
00884    rc.right=rc.left+WINDOW_ID_VSIZE;
00885    rc.bottom=rc.top+WINDOW_ID_YSIZE;
00886  }
00887  hdc=GetDC(hwnd);
00888  InvertRect(hdc,&rc);
00889  ReleaseDC(hwnd,hdc);
00890  return;
00891 }
00892 
00893 void DeleteArrowIcons(void){
00894  int i;
00895  for(i=0;i<6;i++){
00896    if(hbmArrow != NULL)DeleteObject(hbmArrow[i]);
00897    hbmArrow[i]=NULL;
00898  }
00899  if(hbmName[0] != NULL)DeleteObject(hbmName[0]); hbmName[0]=NULL;
00900  if(hbmName[1] != NULL)DeleteObject(hbmName[1]); hbmName[1]=NULL;
00901  if(hbmName[2] != NULL)DeleteObject(hbmName[2]); hbmName[2]=NULL;
00902  if(hbmName[4] != NULL)DeleteObject(hbmName[4]); hbmName[4]=NULL;
00903 }
00904 
00905 void SwapViewBitmaps(void){
00906  HBITMAP hbmTemp;
00907  hbmTemp=hbmName[1];
00908  hbmName[1]=hbmName[4];
00909  hbmName[4]=hbmTemp;
00910 }
00911 
00912 static BOOL CALLBACK ThreeRealsDlgProc(HWND hwnd, UINT msg,
00913                                     WPARAM wparam, LPARAM lparam){
00914  char tempstr[128];
00915  struct np {char *title,*name1,*name2,*name3; double cal1,cal2,cal3;} *dp;
00916  switch( msg ) {
00917    case WM_PAINT:
00918      PaintDialogBackground(hwnd,ghinst_main);
00919      break;
00920    case WM_INITDIALOG:{
00921        RECT rcDlg;
00922        POINT p;
00923        dp=(struct np *)lparam;
00924        SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)dp->title);
00925        SendDlgItemMessage(hwnd,DLG_3REALS_NAME1,WM_SETTEXT,0,(LPARAM)dp->name1);
00926        SendDlgItemMessage(hwnd,DLG_3REALS_NAME2,WM_SETTEXT,0,(LPARAM)dp->name2);
00927        SendDlgItemMessage(hwnd,DLG_3REALS_NAME3,WM_SETTEXT,0,(LPARAM)dp->name3);
00928        sprintf(tempstr,"%.4lf",dp->cal1);
00929        SendDlgItemMessage(hwnd,DLG_3REALS_CAL1,WM_SETTEXT,0,(LPARAM)tempstr);
00930        SendDlgItemMessage(hwnd,DLG_3REALS_CAL1,EM_LIMITTEXT,(WPARAM)12,0);
00931        sprintf(tempstr,"%.4lf",dp->cal2);
00932        SendDlgItemMessage(hwnd,DLG_3REALS_CAL2,WM_SETTEXT,0,(LPARAM)tempstr);
00933        SendDlgItemMessage(hwnd,DLG_3REALS_CAL2,EM_LIMITTEXT,(WPARAM)12,0);
00934        sprintf(tempstr,"%.4lf",dp->cal3);
00935        SendDlgItemMessage(hwnd,DLG_3REALS_CAL3,WM_SETTEXT,0,(LPARAM)tempstr);
00936        SendDlgItemMessage(hwnd,DLG_3REALS_CAL3,EM_LIMITTEXT,(WPARAM)12,0);
00937        SetWindowLong(hwnd,GWL_USERDATA,lparam);
00938        GetCursorPos(&p);
00939        GetWindowRect(hwnd,&rcDlg);
00940        OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
00941        OffsetRect(&rcDlg,p.x-rcDlg.right/2,p.y-rcDlg.bottom/2);
00942        if(rcDlg.left < 0)OffsetRect(&rcDlg,-rcDlg.left,0);
00943        if(rcDlg.top  < 0)OffsetRect(&rcDlg,0,-rcDlg.top);
00944        if(rcDlg.right  > Xres)OffsetRect(&rcDlg,Xres-rcDlg.right,0);
00945        if(rcDlg.bottom > Yres)OffsetRect(&rcDlg,Yres-rcDlg.bottom,0);
00946        SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
00947      }
00948      return (TRUE);
00949    case WM_COMMAND:
00950       switch(LOWORD(wparam)){
00951         case IDCANCEL:
00952         case DLG_3REALS_CANCEL:
00953           EndDialog(hwnd, FAIL);
00954           return(TRUE);
00955         case IDOK:
00956         case DLG_3REALS_OK:
00957           dp=(struct np *)GetWindowLong(hwnd,GWL_USERDATA);
00958           if(GetDlgItemText(hwnd,DLG_3REALS_CAL1,tempstr,10) == 0)goto CANCELX;
00959           dp->cal1=atof(tempstr);
00960           if(GetDlgItemText(hwnd,DLG_3REALS_CAL2,tempstr,10) == 0)goto CANCELX;
00961           dp->cal2=atof(tempstr);
00962           if(GetDlgItemText(hwnd,DLG_3REALS_CAL3,tempstr,10) == 0)goto CANCELX;
00963           dp->cal3=atof(tempstr);
00964           EndDialog(hwnd,OK);
00965           return(TRUE);
00966           CANCELX:
00967           EndDialog(hwnd,FAIL);
00968           return(TRUE);
00969         default:
00970           break;
00971       }
00972       break;
00973     default: break;
00974  }
00975  return(FALSE);
00976 }
00977 
00978 int Read3Reals(char *title, double *r1, double *r2, double *r3, int list){
00979  int rv;
00980  char ttt[24];
00981  char lists0[]="                        ";
00982  char lists1[]="                        ";
00983  char lists2[]="                        ";
00984  char lists3[]="                        ";
00985  char lists4[]="                        ";
00986  char lists5[]="                        ";
00987  struct np {char *title,*name1,*name2,*name3; double cal1,cal2,cal3;} d,*dp;
00988  LoadString(ghinst_main,IDX_MISC_LEFT_RIGHT,ttt,24);
00989  strcpy(lists0,ttt);
00990  LoadString(ghinst_main,IDX_MISC_BACK_FRONT,ttt,24);
00991  strcpy(lists1,ttt);
00992  LoadString(ghinst_main,IDX_MISC_UP_DOWN,ttt,24);
00993  strcpy(lists2,ttt);
00994  LoadString(ghinst_main,IDX_MISC_DIRECTION,ttt,24);
00995  strcpy(lists3,ttt);
00996  LoadString(ghinst_main,IDX_MISC_ELEVATION,ttt,24);
00997  strcpy(lists4,ttt);
00998  LoadString(ghinst_main,IDX_MISC_BANK,ttt,24);
00999  strcpy(lists5,ttt);
01000  d.title=title;
01001  if(list == 0){
01002    d.name1=lists0;
01003    d.name2=lists1;
01004    d.name3=lists2;
01005  }
01006  else{
01007    d.name1=lists3;
01008    d.name2=lists4;
01009    d.name3=lists5;
01010  }
01011  d.cal1 = *r1;
01012  d.cal2 = *r2;
01013  d.cal3 = *r3;
01014  EnableToolPannels(ALL_PANNELS,FALSE);
01015  if(DialogBoxParam(ghinst_main,MAKEINTRESOURCE(DLG_3REALS),ghwnd_main,
01016             (DLGPROC)ThreeRealsDlgProc,(LPARAM)&d) == OK){
01017    *r1 = d.cal1;
01018    *r2 = d.cal2;
01019    *r3 = d.cal3;
01020    rv=OK;
01021  }
01022  else rv=FAIL;
01023  EnableToolPannels(ALL_PANNELS,TRUE);
01024  return rv;
01025 }
01026 
01027 static char *ColorSelectDlgString;
01028 
01029 static BOOL CALLBACK ColorSelectDlgProc(HWND hwnd, UINT msg, WPARAM wparam,
01030                                         LPARAM lparam){
01031  switch( msg ) {
01032    case WM_INITDIALOG:
01033      SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)ColorSelectDlgString);
01034      return TRUE;
01035    default:
01036      break;
01037  }
01038  return FALSE;
01039 }
01040 
01041 void SetColour(unsigned char colour[], char *Title, HWND parent){
01042  CHOOSECOLOR cc;
01043  static COLORREF CustColours[16]={
01044    RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
01045    RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
01046    RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
01047    RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
01048  cc.lStructSize=sizeof(CHOOSECOLOR);
01049  cc.hwndOwner=parent;
01050  cc.rgbResult=RGB(colour[0],colour[1],colour[2]);
01051  cc.lpCustColors=(LPDWORD)CustColours;
01052  cc.Flags=CC_FULLOPEN | CC_RGBINIT | CC_ENABLEHOOK;
01053  cc.lCustData=(DWORD)0;
01054  ColorSelectDlgString=Title;
01055  cc.lpfnHook=(LPCCHOOKPROC)ColorSelectDlgProc;
01056  EnableToolPannels(ALL_PANNELS,FALSE);
01057  if(ChooseColor(&cc)){
01058    colour[0]=GetRValue(cc.rgbResult);
01059    colour[1]=GetGValue(cc.rgbResult);
01060    colour[2]=GetBValue(cc.rgbResult);
01061  }
01062  EnableToolPannels(ALL_PANNELS,TRUE);
01063 }
01064 
01065 void SetSfxColour(unsigned char colour[], long ID, HWND parent){
01066  char szTitle[256];
01067  LoadString(ghinst_main,ID,szTitle,255);
01068  SetColour(colour,szTitle,parent);
01069 }
01070 
01071 void scal(double t[4][4], double sx, double sy, double sz){
01072  long i,j;
01073  for(i=0;i<4;i++) for(j=0;j<4;j++) t[i][j]=0.0;
01074  t[0][0]=sx; t[1][1]=sy; t[2][2]=sz; t[3][3]=1;
01075  return;
01076 }
01077 
01078 void rotz(double tr[4][4], double ang){
01079  short i,j;
01080  for(i=0;i<4;i++)
01081  for(j=0;j<4;j++)
01082  {
01083   tr[i][j]=0.0;
01084   if(i == j)tr[i][j]=1.0;
01085  }
01086   tr[0][0]= cos(ang);
01087   tr[0][1]=-sin(ang);
01088   tr[1][0]= sin(ang);
01089   tr[1][1]= cos(ang);
01090   return;
01091 }
01092 
01093 void roty(double tr[4][4], double ang){
01094  short i,j;
01095  for(i=0;i<4;i++)
01096  for(j=0;j<4;j++)
01097  {
01098   tr[i][j]=0.0;
01099   if(i == j)tr[i][j]=1.0;
01100  }
01101   tr[0][0]= cos(ang);
01102   tr[0][2]=-sin(ang);
01103   tr[2][0]= sin(ang);
01104   tr[2][2]= cos(ang);
01105   return;
01106 }
01107 
01108 void rotx(double tr[4][4], double ang){
01109  long i,j;
01110  for(i=0;i<4;i++)
01111  for(j=0;j<4;j++)
01112  {
01113   tr[i][j]=0.0;
01114   if(i == j)tr[i][j]=1.0;
01115  }
01116   tr[1][1]= cos(ang);
01117   tr[1][2]=-sin(ang);
01118   tr[2][1]= sin(ang);
01119   tr[2][2]= cos(ang);
01120   return;
01121 }
01122 
01123 void tram(double t[4][4], double dx, double dy, double dz){
01124  short i,j;
01125  for(i=0;i<4;i++)
01126  for(j=0;j<4;j++)
01127  {
01128   t[i][j]=0.0;
01129   if(i == j)t[i][j]=1.0;
01130  }
01131  t[0][3]=dx;
01132  t[1][3]=dy;
01133  t[2][3]=dz;
01134  t[3][3]=1;
01135  return;
01136 }
01137 
01138 void m4by4(double t1[4][4], double t2[4][4], double tr[4][4]){
01139  short n=4,i,j,k;
01140  for(i=0;i<4;i++)
01141  for(j=0;j<4;j++)
01142  {
01143   tr[i][j]=0.0;
01144   for(k=0;k<4;k++)tr[i][j]=tr[i][j]+t1[i][k]*t2[k][j];
01145  }
01146  return;
01147 }
01148 
01149 void m4by1(double t4[4][4], double x, double y, double z,
01150            double *xx, double *yy, double *zz){
01151  *xx=t4[0][0]*x+t4[0][1]*y+t4[0][2]*z+t4[0][3];
01152  *yy=t4[1][0]*x+t4[1][1]*y+t4[1][2]*z+t4[1][3];
01153  *zz=t4[2][0]*x+t4[2][1]*y+t4[2][2]*z+t4[2][3];
01154  return;
01155 }
01156 
01157 void c4to4(double tin[4][4], double tout[4][4]){
01158  short i,j;
01159  for(i=0;i<4;i++)
01160  for(j=0;j<4;j++)
01161  tout[i][j]=tin[i][j];
01162 }
01163 
01164 void null_transform(double t[4][4]){
01165  short i,j;
01166  for(i=0;i<4;i++)
01167  for(j=0;j<4;j++)
01168  if(i == j)t[i][j]=1.0;
01169  else      t[i][j]=0.0;
01170 }
01171 
01172 void arbitrary_rotate(double angle, point p1, point p2, double t[4][4]){
01173   double dx,dy,dz,phi,theta,dxy;
01174   double t1[4][4],t2[4][4],t3[4][4];
01175   angle *= PI/180.0;
01176   dx=p2[0]-p1[0]; dy=p2[1]-p1[1]; dz=p2[2]-p1[2];
01177   dxy=dx*dx+dy*dy;
01178   tram(t1, -p1[0], -p1[1], -p1[2]);
01179   if(dxy < 1.0){ /* vertical so just rotate about z  and return */
01180     rotz(t2, angle);
01181     m4by4(t2,t1,t3);
01182     tram(t1,p1[0],p1[1],p1[2]);
01183     m4by4(t1,t3,t);
01184     return;
01185   }
01186   dxy=sqrt(dxy);
01187   if     (dx == 0.0 && dy > 0.0)phi =  PI2;
01188   else if(dx == 0.0 && dy < 0.0)phi = -PI2;
01189   else phi = atan2(dy,dx);
01190   theta = atan2(dz,dxy);
01191   rotz(t2, -phi);
01192   m4by4(t2,t1,t3);
01193   roty(t2, -theta);
01194   m4by4(t2,t3,t1);
01195   rotx(t2, angle);
01196   m4by4(t2,t1,t3);
01197   roty(t2,theta);
01198   m4by4(t2,t3,t1);
01199   rotz(t2,phi);
01200   m4by4(t2,t1,t3);
01201   tram(t1,p1[0],p1[1],p1[2]);
01202   m4by4(t1,t3,t);
01203 }
01204 
01205 void L_cross(point p1, point p2, point p3, point p4){
01206  double v1[3],v2[3],r[3];
01207  v1[0]=(double)(p2[0]-p1[0]);
01208  v1[1]=(double)(p2[1]-p1[1]);
01209  v1[2]=(double)(p2[2]-p1[2]);
01210  v2[0]=(double)(p3[0]-p1[0]);
01211  v2[1]=(double)(p3[1]-p1[1]);
01212  v2[2]=(double)(p3[2]-p1[2]);
01213  r[0] = (v1[1]*v2[2]) - (v2[1]*v1[2]);
01214  r[1] = (v1[2]*v2[0]) - (v1[0]*v2[2]);
01215  r[2] = (v1[0]*v2[1]) - (v2[0]*v1[1]);
01216  p4[0] = p1[0] + (long)(r[0]/UNIT);
01217  p4[1] = p1[1] + (long)(r[1]/UNIT);
01218  p4[2] = p1[2] + (long)(r[2]/UNIT);
01219 }
01220 
01221 void PaintDialogBackground(HWND hDlg, HINSTANCE hInst){
01222  int x;
01223  int y;
01224  HDC hDC;
01225  HPALETTE hpalT;
01226  HBRUSH hOldBrush;
01227  RECT rc1,rc2;
01228  HDC hMemDC;
01229  HBITMAP hBmBackground,hbmOld;
01230  BITMAP  bm;
01231  PAINTSTRUCT ps;
01232  hDC = BeginPaint(hDlg,&ps);
01233  hBmBackground=LoadBitmap(hInst,MAKEINTRESOURCE(IDBM_BACKGROUND));
01234  if(hBmBackground != NULL){
01235    GetObject(hBmBackground,sizeof(BITMAP),&bm);
01236    hMemDC = CreateCompatibleDC(hDC);
01237    hbmOld = SelectObject(hMemDC,hBmBackground);
01238    GetClientRect(hDlg,&rc2);
01239    for(x=0;x<(rc2.right/bm.bmWidth)+1;x++)
01240    for(y=0;y<(rc2.bottom/bm.bmHeight)+1;y++)
01241      BitBlt(hDC,
01242           x*bm.bmWidth,y*bm.bmHeight,
01243           bm.bmWidth,
01244           bm.bmHeight,
01245           hMemDC,
01246           0,0,
01247           SRCCOPY);
01248    SelectObject(hMemDC,hbmOld);
01249    DeleteDC(hMemDC);
01250    DeleteObject(hBmBackground);
01251  }
01252  EndPaint(hDlg,&ps);
01253 }
01254 
01255 static BOOL CALLBACK CoordinateDlgProc(HWND hwnd, UINT msg,
01256                                     WPARAM wparam, LPARAM lparam){
01257  char tempstr[128];
01258  struct np {char *name; double cal;} *dp;
01259  switch( msg ) {
01260    case WM_INITDIALOG:{
01261        RECT rcDlg;
01262        POINT p;
01263        dp=(struct np *)lparam;
01264        SendDlgItemMessage(hwnd,DLG_COORD_NAME,WM_SETTEXT,0,(LPARAM)dp->name);
01265        SendDlgItemMessage(hwnd,DLG_COORD_NAME,EM_LIMITTEXT,(WPARAM)6,0);
01266        sprintf(tempstr,"%.4lf",dp->cal);
01267        SendDlgItemMessage(hwnd,DLG_COORD_CAL,WM_SETTEXT,0,(LPARAM)tempstr);
01268        SendDlgItemMessage(hwnd,DLG_COORD_CAL,EM_LIMITTEXT,(WPARAM)12,0);
01269        SetWindowLong(hwnd,GWL_USERDATA,lparam);
01270        GetCursorPos(&p);
01271        GetWindowRect(hwnd,&rcDlg);
01272        OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
01273        OffsetRect(&rcDlg,p.x-rcDlg.right/2,p.y-rcDlg.bottom/2);
01274        if(rcDlg.left < 0)OffsetRect(&rcDlg,-rcDlg.left,0);
01275        if(rcDlg.top  < 0)OffsetRect(&rcDlg,0,-rcDlg.top);
01276        if(rcDlg.right  > Xres)OffsetRect(&rcDlg,Xres-rcDlg.right,0);
01277        if(rcDlg.bottom > Yres)OffsetRect(&rcDlg,Yres-rcDlg.bottom,0);
01278        SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
01279      }
01280      return (TRUE);
01281    case WM_PAINT:
01282      PaintDialogBackground(hwnd,ghinst_main);
01283      break;
01284    case WM_COMMAND:
01285       switch(LOWORD(wparam)){
01286         case IDCANCEL:
01287         case DLG_COORD_CANCEL:
01288           EndDialog(hwnd, FAIL);
01289           return(TRUE);
01290         case IDOK:
01291         case DLG_COORD_OK:
01292           dp=(struct np *)GetWindowLong(hwnd,GWL_USERDATA);
01293           if(GetDlgItemText(hwnd,DLG_COORD_NAME,dp->name,7) == 0)goto CANCELX;
01294           if(GetDlgItemText(hwnd,DLG_COORD_CAL,tempstr,10) == 0)goto CANCELX;
01295           dp->cal=atof(tempstr);
01296           EndDialog(hwnd,OK);
01297           return(TRUE);
01298           CANCELX:
01299           EndDialog(hwnd, FAIL);
01300           return(TRUE);
01301         default:
01302           break;
01303       }
01304       break;
01305     default: break;
01306  }
01307  return(FALSE);
01308 }
01309 
01310 void UpdateRuler(short m){
01311  double dx,dy,dz;
01312  char tempstr[32];
01313  if(m == 1){ /* cancel */
01314    rulerx=NpointerX; rulery=NpointerY; rulerz=NpointerZ;
01315  }
01316  if(m == 2){ /* set origin*/
01317    if(SendPrgmQuery(IDQ_SET_COORD_ORIGIN,1) != IDYES)return;
01318    EDIT_ACTION=YES;
01319    lrulerx=NpointerX; lrulery=NpointerY; lrulerz=NpointerZ;
01320  }
01321  if(m == 3){ /* set ruler */
01322    char name[10];
01323    struct np {char *name; double cal;} d;
01324    dx = (double)(NpointerX-lrulerx);
01325    dy = (double)(NpointerY-lrulery);
01326    dz = (double)(NpointerZ-lrulerz);
01327    if(dx < (double)MINUNIT || dy < (double)MINUNIT || dz < (double)MINUNIT){
01328      double dd;
01329      EDIT_ACTION=YES;
01330      if(ruler_name[0] == 0)strcpy(name,"<cms>");
01331      else                  strcpy(name,ruler_name);
01332      dd=sqrt(dx*dx+dy*dy+dz*dz);
01333      d.name=name; d.cal=dd/ruler;
01334      EnableToolPannels(ALL_PANNELS,FALSE);
01335      if(DialogBoxParam(ghinst_main,MAKEINTRESOURCE(DLG_COORD),ghwnd_main,
01336                 (DLGPROC)CoordinateDlgProc,(LPARAM)&d) == OK){
01337        strcpy(ruler_name,d.name);
01338        LoadString(ghinst_main,IDX_MISC_COORDS,tempstr,32);
01339        strcat(tempstr,ruler_name);
01340        SendMessage(ghwndCoord1,WM_SETTEXT,0,(LPARAM)tempstr);
01341        ruler = dd;
01342        if(d.cal > 0.0)ruler /= d.cal;
01343      }
01344      EnableToolPannels(ALL_PANNELS,TRUE);
01345    }
01346    else SendPrgmQuery(IDQ_COORD_BAD_RANGE,0);
01347  }
01348  SendMessage(ghwndCoord1,WM_COMMAND,IDC_COORD_UPDATE,0);
01349 }
01350 
01351 static BOOL CALLBACK GridSizeDlgProc(HWND hwnd, UINT msg,
01352                                      WPARAM wparam, LPARAM lparam){
01353  double d;
01354  char size[16];
01355  switch( msg ) {
01356    case WM_INITDIALOG:{
01357        RECT rcDlg;
01358        POINT p;
01359        SetWindowLong(hwnd,GWL_USERDATA,lparam);
01360        GetCursorPos(&p);
01361        GetWindowRect(hwnd,&rcDlg);
01362        OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
01363        OffsetRect(&rcDlg,p.x-rcDlg.right/2,p.y-rcDlg.bottom/2);
01364        if(rcDlg.left < 0)OffsetRect(&rcDlg,-rcDlg.left,0);
01365        if(rcDlg.top  < 0)OffsetRect(&rcDlg,0,-rcDlg.top);
01366        if(rcDlg.right  > Xres)OffsetRect(&rcDlg,Xres-rcDlg.right,0);
01367        if(rcDlg.bottom > Yres)OffsetRect(&rcDlg,Yres-rcDlg.bottom,0);
01368        SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
01369        if(draw_grid_on)SendDlgItemMessage(hwnd,DLG_GRIDSIZE_ON ,BM_SETCHECK,1,0);
01370        else            SendDlgItemMessage(hwnd,DLG_GRIDSIZE_OFF,BM_SETCHECK,1,0);
01371        sprintf(size,"%.4lf",((double)grid_size)/ruler);
01372        SendDlgItemMessage(hwnd,DLG_GRIDSIZE_EDIT,WM_SETTEXT,0,
01373                           (LPARAM)(LPSTR)size);
01374        SendDlgItemMessage(hwnd,DLG_GRIDSIZE_EDIT,EM_LIMITTEXT,12,0);
01375      }
01376      SetFocus(GetDlgItem(hwnd,DLG_GRIDSIZE_OK)); return(FALSE);
01377      return (TRUE);  /* must be used unless SetFocus */
01378    case WM_PAINT:
01379      PaintDialogBackground(hwnd,ghinst_main);
01380      break;
01381    case WM_COMMAND:
01382       switch(LOWORD(wparam)){
01383         case IDCANCEL:
01384         case DLG_GRIDSIZE_CANCEL:
01385           EndDialog(hwnd, FAIL);
01386           return(TRUE);
01387         case IDOK:
01388         case DLG_GRIDSIZE_OK:
01389           if(SendDlgItemMessage(hwnd,DLG_GRIDSIZE_ON,BM_GETCHECK,0,0))
01390                draw_grid_on=1;
01391           else draw_grid_on=0;
01392           if(GetDlgItemText(hwnd,DLG_GRIDSIZE_EDIT,size,12)){
01393             if((d=atof(size)) > 0.0)grid_size=(long)(d*ruler);
01394           }
01395           EndDialog(hwnd,OK);
01396           return(TRUE);
01397         default:
01398           break;
01399       }
01400       break;
01401     default: break;
01402  }
01403  return(FALSE);
01404 }
01405 
01406 void SetUpGrid(void){
01407  EnableToolPannels(ALL_PANNELS,FALSE);
01408  DialogBox(ghinst_main,MAKEINTRESOURCE(DLG_GRIDSIZE),ghwnd_main,
01409             (DLGPROC)GridSizeDlgProc);
01410  EnableToolPannels(ALL_PANNELS,TRUE);
01411  return;
01412 }
01413 
01414 #if 0
01415 void DrawGrid(HDC hdc[]){
01416  int ifd,ild;
01417  int ng,ngx,ngy,ngz,ng1,ng2,j,k,xx[50],yy[50],d;
01418  long i,x,y,z,x1,y1,z1,g2;
01419  HPEN hOldPen[3];
01420  BOOL bSmall=FALSE;
01421 // LOGPEN lopn;
01422 // GetObject(ghSelectedPen,sizeof(LOGPEN),&lopn);
01423  if(View == TRIVIEW){ifd=0;ild=3;}
01424  else               {ifd=ActiveView; ild=ifd+1;}
01425  g2=grid_size/2;
01426  x=TVpointX; y=TVpointY; z=TVpointZ;
01427  x1 = lrulerx+((x+(x >= 0  ? g2 : -g2)-lrulerx)/grid_size)*grid_size;
01428  y1 = lrulery+((y+(y >= 0  ? g2 : -g2)-lrulery)/grid_size)*grid_size;
01429  z1 = lrulerz+((z+(z >= 0  ? g2 : -g2)-lrulerz)/grid_size)*grid_size;
01430  if(x1 <= TVpointX)x1 += grid_size;
01431  if(y1 <= TVpointY)y1 += grid_size;
01432  if(z1 <= TVpointZ)z1 += grid_size;
01433  ngx=(short)(TVsizeX/grid_size);
01434  ngy=(short)(TVsizeY/grid_size);
01435  ngz=(short)(TVsizeZ/grid_size);
01436  ng = max(ngx,ngy);   ng=max(ngz,ng); ng++;
01437  if((View == TRIVIEW && ng > 25)  || ng > 50 || ng == 0)return;
01438  if((View == TRIVIEW && ng > 10)  || ng > 20)bSmall=TRUE;
01439  for(i=ifd;i<ild;i++){
01440    hOldPen[i]=SelectObject(hdc[i],GetStockObject(BLACK_PEN));
01441    ng1 = ng2 = -1; x=x1; y=y1; z=z1;
01442    for(j=0;j<ng;j++){
01443      GetWindowCoords(i,x,y,z,&xx[j],&yy[j]);
01444      x += grid_size; y += grid_size; z += grid_size;
01445      if(WindowBox_view == 0){
01446        if(xx[j] >= WindowSizeX[i] && ng1 < 0)ng1=j;
01447        if(yy[j] <= 0               && ng2 < 0)ng2=j;
01448      }
01449      else{
01450        if(xx[j] <= 0 && ng1 < 0)ng1=j;
01451        if(i==TRITOP){if(yy[j] >= WindowSizeY[i] && ng2 < 0)ng2=j;}
01452        else         {if(yy[j] <= 0              && ng2 < 0)ng2=j;}
01453      }
01454    }
01455    if(ng1 < 0)ng1=ng; if(ng2 < 0)ng2=ng;
01456    if(ng1 > 0 && ng2 > 0)for(j=0;j<ng2;j++)for(k=0;k<ng1;k++){
01457 //     X__SetPixel(hdc[i],xx[k],yy[j],lopn.lopnColor);
01458      if(bSmall){
01459        MoveToEx(hdc[i],xx[k],yy[j],NULL); LineTo(hdc[i],xx[k]+1,yy[j]);
01460      }
01461      else{
01462        MoveToEx(hdc[i],xx[k]-2,yy[j],NULL); LineTo(hdc[i],xx[k]+3,yy[j]);
01463        MoveToEx(hdc[i],xx[k],yy[j]-2,NULL); LineTo(hdc[i],xx[k],yy[j]+3);
01464      }
01465    }
01466    SelectObject(hdc[i],hOldPen[i]);
01467  }
01468  return;
01469 }
01470 #endif
01471 
01472 void DrawGrid(HDC hdc[]){
01473  int ifd,ild;
01474  COLORREF OldColour;
01475  HPEN hPen1,hPen2,hPen3,hOldPen,hTempPen;
01476  BOOL flagx[50],flagy[50];
01477  int ng,ngx,ngy,ngz,ng1,ng2,j,k,xx[50],yy[50],d;
01478  long i,x,y,z,x1,y1,z1,g2,nx,ny,nz,iter;
01479  if(View == TRIVIEW){ifd=0;ild=3;}
01480  else               {ifd=ActiveView; ild=ifd+1;}
01481  local_grid_size=grid_size/10;
01482  iter=0;
01483  TRYAGAIN:
01484  g2=local_grid_size/2;
01485  x=TVpointX; y=TVpointY; z=TVpointZ;
01486  x1 = lrulerx+((x+(x >= 0  ? g2 : -g2)-lrulerx)/local_grid_size)*local_grid_size;
01487  y1 = lrulery+((y+(y >= 0  ? g2 : -g2)-lrulery)/local_grid_size)*local_grid_size;
01488  z1 = lrulerz+((z+(z >= 0  ? g2 : -g2)-lrulerz)/local_grid_size)*local_grid_size;
01489  if(x1 <= TVpointX)x1 += local_grid_size;
01490  if(y1 <= TVpointY)y1 += local_grid_size;
01491  if(z1 <= TVpointZ)z1 += local_grid_size;
01492  ngx=(short)(TVsizeX/local_grid_size);
01493  ngy=(short)(TVsizeY/local_grid_size);
01494  ngz=(short)(TVsizeZ/local_grid_size);
01495  ng = max(ngx,ngy);   ng=max(ngz,ng); ng++;
01496  if(ng == 0)return;
01497  if(ng > 30){
01498    local_grid_size *= 10;
01499    if(iter++ > 100)return;
01500    goto TRYAGAIN;
01501  }
01502  for(i=ifd;i<ild;i++){
01503    ng1 = ng2 = -1; x=x1; y=y1; z=z1;
01504    for(j=0;j<ng;j++){
01505      nx = labs(x-lrulerx)/local_grid_size;
01506      ny = labs(y-lrulery)/local_grid_size;
01507      nz = labs(z-lrulerz)/local_grid_size;
01508      flagx[j]=flagy[j]=FALSE;
01509      if(i == TRIRIGHT){
01510        nx=ny;
01511        ny=nz;
01512      }
01513      else if(i == TRIFRONT){
01514        ny=nz;
01515      }
01516      if(nx%10 == 0)flagx[j]=TRUE;
01517      if(ny%10 == 0)flagy[j]=TRUE;
01518      GetWindowCoords(i,x,y,z,&xx[j],&yy[j]);
01519      x += local_grid_size; y += local_grid_size; z += local_grid_size;
01520      if(WindowBox_view == 0){
01521        if(xx[j] >= WindowSizeX[i] && ng1 < 0)ng1=j;
01522        if(yy[j] <= 0              && ng2 < 0)ng2=j;
01523      }
01524      else{
01525        if(xx[j] <= 0 && ng1 < 0)ng1=j;
01526        if(i==TRITOP){if(yy[j] >= WindowSizeY[i] && ng2 < 0)ng2=j;}
01527        else         {if(yy[j] <= 0              && ng2 < 0)ng2=j;}
01528      }
01529    }
01530    if(ng1 < 0)ng1=ng; if(ng2 < 0)ng2=ng;
01531    if(iter == 0)hPen1=CreatePen(PS_DOT,0,gGridColourRef1);
01532    else         hPen1=CreatePen(PS_SOLID,0,gGridColourRef1);
01533    hPen2=CreatePen(PS_SOLID,0,gGridColourRef2);
01534    hPen3=CreatePen(PS_SOLID,0,RGB(255,255,255));
01535    OldColour=SetBkColor(hdc[i],gScreenColourRef);
01536    hOldPen=SelectObject(hdc[i],hPen1);
01537    x= -1; y = -1;
01538    if(lrulerx > TVpointX || lrulerx < TVpointX+TVsizeX ||
01539       lrulery > TVpointY || lrulery < TVpointY+TVsizeY ||
01540       lrulerz > TVpointZ || lrulerz < TVpointZ+TVsizeZ){
01541      GetWindowCoords(i,lrulerx,lrulery,lrulerz,(int *)(&x),(int *)&y);
01542    }
01543    if(ng1 > 0 && ng2 > 0){
01544      for(j=0;j<ng2;j++){
01545        if(yy[j] == y)continue;
01546        if(flagy[j])hTempPen=SelectObject(hdc[i],hPen2);
01547        MoveToEx(hdc[i],0,yy[j],NULL); LineTo(hdc[i],WindowSizeX[i]+1,yy[j]);
01548        if(flagy[j])SelectObject(hdc[i],hTempPen);
01549      }
01550      for(k=0;k<ng1;k++){
01551        if(xx[k] == x)continue;
01552        if(flagx[k])hTempPen=SelectObject(hdc[i],hPen2);
01553        MoveToEx(hdc[i],xx[k],0,NULL); LineTo(hdc[i],xx[k],WindowSizeY[i]+1);
01554        if(flagx[k])SelectObject(hdc[i],hTempPen);
01555      }
01556    }
01557    SetBkColor(hdc[i],OldColour);
01558    SelectObject(hdc[i],hPen3);
01559    if(y >= 0 && y <= WindowSizeY[i]){
01560      MoveToEx(hdc[i],0,y,NULL); LineTo(hdc[i],WindowSizeX[i]+1,y);
01561    }
01562    if(x >= 0 && x <= WindowSizeX[i]){
01563      MoveToEx(hdc[i],x,0,NULL); LineTo(hdc[i],x,WindowSizeY[i]+1);
01564    }
01565    SelectObject(hdc[i],hOldPen);
01566    DeleteObject(hPen1);
01567    DeleteObject(hPen2);
01568    DeleteObject(hPen3);
01569  }
01570  return;
01571 }

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