⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ace.c

📁 This is a CNCPro source file. It is include the G-Code interpreter source.
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <windows.h>
#include <stdio.h>
#include <dir.h>
#include <math.h>
#include "ace.h"
#include "converter.h"

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK CodeWndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL PopFileOpenDlg (HWND, PSTR, PSTR, OPENFILENAME *) ;
BOOL PopFileSaveDlg (HWND, PSTR, PSTR, OPENFILENAME *) ;
BOOL CALLBACK LayerDlgProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK PriorityDlgProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK ConvertDlgProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK LicenseDlgProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK EndDlgProc (HWND, UINT, WPARAM, LPARAM) ;
int DelPriority (int, int);
int NewPriority (int);
int ReadLayer (char *);
void GetDir(char, char *);
void SaveDir(char, char *);
int check_key(char *, char *);
HWND hWindow;
HINSTANCE hInst;
char szAppName[]="ACEconverter";
int demo=FALSE;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
     {
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASSEX   wndclass ;
     hInst=hInstance;

     wndclass.cbSize        = sizeof (wndclass) ;
     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = DLGWINDOWEXTRA ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     wndclass.hIconSm       = LoadIcon (hInstance, szAppName) ;

     RegisterClassEx (&wndclass) ;

     hWindow = hwnd = CreateDialog (hInstance, szAppName, 0, NULL) ;
     EnableWindow(GetDlgItem(hwnd,IDD_CONVERT), FALSE);
     ShowWindow (hwnd, iCmdShow) ;

     while (GetMessage (&msg, NULL, 0, 0))
          {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
          }
     return msg.wParam ;
     }

struct layer_obj *layer, *temp_lay ;
struct priority_obj *priority, *temp_pri ;
struct convert_obj convertop ;
int iLayerCount, iPrioCount;
char szDxfFile[_MAX_PATH], szToFileName[_MAX_PATH];

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     static char szTitleName[_MAX_FNAME + _MAX_EXT] ;
     static char szDrive[MAXDRIVE], szDir[MAXDIR], szName[MAXFILE], szExt[MAXEXT] ;
     static char szDXFFilter[]="DXF Files (*.DXF)\0*.dxf\0" ;
     static char szTXTFilter[]="TXT Files (*.TXT)\0*.txt\0" ;
     static char szString[50], status[100], szFileName[_MAX_PATH];
     static char szAcePath[_MAX_PATH], szHelp[_MAX_PATH], szDirectory[_MAX_PATH] ;
     static int i, iID;
     static HINSTANCE hInstance ;
     static OPENFILENAME ofn ;

     switch (iMsg)
          {
          case WM_CREATE :
               GetDir('1',szAcePath);
               sprintf(szHelp,"%s\\index.html",szAcePath);
               hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
               ofn.lStructSize       = sizeof (OPENFILENAME) ;
               ofn.hwndOwner         = hwnd ;
               ofn.hInstance         = NULL ;
               ofn.lpstrCustomFilter = NULL ;
               ofn.nMaxCustFilter    = 0 ;
               ofn.nFilterIndex      = 0 ;
               ofn.lpstrFile         = NULL ;          // Set in Open and Close functions
               ofn.nMaxFile          = _MAX_PATH ;
               ofn.lpstrFileTitle    = NULL ;          // Set in Open and Close functions
               ofn.nMaxFileTitle     = _MAX_FNAME + _MAX_EXT ;
               ofn.lpstrTitle        = NULL ;
               ofn.Flags             = 0 ;             // Set in Open and Close functions
               ofn.nFileOffset       = 0 ;
               ofn.nFileExtension    = 0 ;
               ofn.lCustData         = 0L ;
               ofn.lpfnHook          = NULL ;
               ofn.lpTemplateName    = NULL ;
               ofn.lpstrInitialDir = NULL;
               //set default value for i and j converting option
               convertop.ijrel=TRUE;
               return 0 ;
          case WM_COMMAND :
               switch (LOWORD(wParam))
                    {
                    case IDD_OPEN :
                         GetDir('2',szDirectory);
                         ofn.lpstrInitialDir = szDirectory;
                         ofn.lpstrFilter = szDXFFilter ;
                         ofn.lpstrDefExt = "dxf" ;
                         if (PopFileOpenDlg (hwnd, szFileName, szTitleName, &ofn))
                           {GetCurrentDirectory(_MAX_PATH,szDirectory);
                            SaveDir('2',szDirectory);
                            EnableWindow(GetDlgItem(hwnd,IDD_CONVERT), TRUE);
                            SetWindowText (GetDlgItem(hwnd, IDD_FILE), ofn.lpstrFileTitle) ;
                            sprintf(status,"");
                            SetWindowText(GetDlgItem(hwnd, IDD_STATUS),status);
                            while(iPrioCount>0) iPrioCount=DelPriority (iPrioCount, iPrioCount) ;
                            if(iLayerCount>0) free(layer);
                            iLayerCount=ReadLayer (ofn.lpstrFile) ;
                            SendMessage(GetDlgItem(hwnd, IDD_PRIORITY), LB_RESETCONTENT, 0, 0);
                            SendMessage(GetDlgItem(hwnd, IDD_LAYER), LB_RESETCONTENT, 0, 0);
                            if(iLayerCount>0)
                              {iPrioCount=NewPriority (iPrioCount) ;
                               SendMessage(GetDlgItem(hwnd, IDD_PRIORITY), LB_ADDSTRING, 0, (LPARAM) "1");
                               SendMessage(GetDlgItem(hwnd, IDD_PRIORITY), LB_SETCURSEL, (WPARAM) 0, 0);
                               for(i=0;i<iLayerCount;i++)
                                 {sprintf(szString,"%s...%d",layer[i].name,layer[i].priority);
                                  SendMessage(GetDlgItem(hwnd, IDD_LAYER), LB_ADDSTRING, 0, (LPARAM) szString);
                                 }
                               SendMessage(GetDlgItem(hwnd, IDD_LAYER), LB_SETCURSEL, (WPARAM) 0, 0);
                              }
                           }
                         break ;
                    case IDD_CONVERT :
                         sprintf(szDxfFile,"%s",ofn.lpstrFile);
                         GetDir('3',szDirectory);
                         fnsplit (ofn.lpstrFile, szDrive, szDir, szName, szExt) ;
                         sprintf(ofn.lpstrFile,"%s\\%s.txt",szDirectory,szName);
                         sprintf(ofn.lpstrFileTitle,"%s.txt",szName);
                         ofn.lpstrInitialDir = szDirectory;
                         ofn.lpstrFilter = szTXTFilter ;
                         ofn.lpstrDefExt = "txt" ;
                         DialogBox (hInstance, "ConvertBox", hwnd, ConvertDlgProc) ;
                         if (PopFileSaveDlg (hwnd, szFileName, szTitleName, &ofn))
                           {GetCurrentDirectory(_MAX_PATH,szDirectory);
                            SaveDir('3',szDirectory);
                            sprintf(szToFileName,"%s",szFileName);
                            EnableWindow(GetDlgItem(hwnd,IDD_CONVERT), FALSE);
                            EnableWindow(GetDlgItem(hwnd,IDD_OPEN), FALSE);
                            EnableWindow(GetDlgItem(hwnd,IDD_LAYER), FALSE);
                            EnableWindow(GetDlgItem(hwnd,IDD_PRIORITY), FALSE);
                            CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) convert,	NULL,	0,	&iID);
                           }
                         fnmerge (ofn.lpstrFile, szDrive, szDir, szName, szExt) ;
                         fnmerge (ofn.lpstrFileTitle, NULL, NULL, szName, szExt) ;
                         break ;
                    case IDD_HELP :
                         ShellExecute(hwnd, "open", szHelp, NULL, NULL, SW_SHOWDEFAULT);
                         break ;
                    case IDD_LAYER :
                         if(HIWORD (wParam)==LBN_DBLCLK)
                           {DialogBox (hInstance, "LayerBox", hwnd, LayerDlgProc) ;
                            i=SendMessage(GetDlgItem(hwnd, IDD_LAYER), LB_GETCURSEL, 0, 0);
                            SendMessage(GetDlgItem(hwnd, IDD_LAYER), LB_DELETESTRING, (WPARAM) i, 0);
                            sprintf(szString,"%s...%d",layer[i].name,layer[i].priority);
                            SendMessage(GetDlgItem(hwnd, IDD_LAYER), LB_INSERTSTRING, (WPARAM) i, (LPARAM) szString);
                            SendMessage(GetDlgItem(hwnd, IDD_LAYER), LB_SETCURSEL, (WPARAM) i, 0);
                            for(i=0;i<iLayerCount;i++)
                               if(layer[i].priority==iPrioCount+1)
                                 {iPrioCount=NewPriority(iPrioCount);
                                  sprintf(szString,"%d",iPrioCount);
                                  SendMessage(GetDlgItem(hwnd, IDD_PRIORITY), LB_ADDSTRING, 0, (LPARAM) szString);
                                 }
                           }
                         break ;
                    case IDD_PRIORITY :
                         if(HIWORD (wParam)==LBN_DBLCLK) DialogBox (hInstance, "PriorityBox", hwnd, PriorityDlgProc) ;
                         break ;
                    }
               return 0 ;
          case WM_DESTROY :
               if(demo==TRUE) DialogBox (hInstance, "EndBox", hwnd, EndDlgProc) ;
               PostQuitMessage (0) ;
               return 0 ;
          }
     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
     }

BOOL PopFileOpenDlg (HWND hwnd, PSTR pstrFileName, PSTR pstrTitleName, OPENFILENAME *ofn)
     {
     ofn->hwndOwner         = hwnd ;
     ofn->lpstrFile         = pstrFileName ;
     ofn->lpstrFileTitle    = pstrTitleName ;
     ofn->Flags             = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;

     return GetOpenFileName (ofn) ;
     }

BOOL PopFileSaveDlg (HWND hwnd, PSTR pstrFileName, PSTR pstrTitleName, OPENFILENAME *ofn)
     {
     ofn->hwndOwner         = hwnd ;
     ofn->lpstrFile         = pstrFileName ;
     ofn->lpstrFileTitle    = pstrTitleName ;
     ofn->Flags             = OFN_OVERWRITEPROMPT ;

     return GetSaveFileName (ofn) ;
     }

BOOL CALLBACK LayerDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     static int iLayer, iArc, iTemp, iPrioCount, i;
     static char szString[30], *endptr;
     static float fTemp;

     switch (iMsg)
          {
          case WM_INITDIALOG :
               iLayer=SendMessage(GetDlgItem(hWindow, IDD_LAYER), LB_GETCURSEL, 0, 0);
               SetWindowText(GetDlgItem(hDlg, IDD_LAYERDISP),layer[iLayer].name);
               if(layer[iLayer].status==FALSE) SendMessage(GetDlgItem(hDlg, IDD_LAYEROFF), BM_SETCHECK, 1, 0);
               CheckRadioButton(hDlg, IDD_EITHERARC, IDD_CWARC, (iArc=layer[iLayer].arc));
               sprintf(szString,"%f",layer[iLayer].zoffset);
               SetWindowText(GetDlgItem(hDlg, IDD_ZOFFSET),szString);
               sprintf(szString,"%f",layer[iLayer].depth);
               SetWindowText(GetDlgItem(hDlg, IDD_DEPTH),szString);
               SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_ADDSTRING, 0, (LPARAM) "W");
               SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_ADDSTRING, 0, (LPARAM) "Z");
               SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_ADDSTRING, 0, (LPARAM) "A");
               SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_ADDSTRING, 0, (LPARAM) "C");
               sprintf(szString,"%c",layer[iLayer].zchar);
               SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_SETCURSEL,
                           SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_FINDSTRINGEXACT, 0, (LPARAM) szString),0);
               iPrioCount=SendMessage(GetDlgItem(hWindow, IDD_PRIORITY), LB_GETCOUNT, 0, 0);
               for(i=0;i<=iPrioCount;i++)
                 {sprintf(szString,"%d",i+1);
                  SendMessage(GetDlgItem(hDlg, IDD_PRIOR), CB_ADDSTRING, 0, (LPARAM) szString);
                 }
               sprintf(szString,"%d",layer[iLayer].priority);
               SendMessage(GetDlgItem(hDlg, IDD_PRIOR), CB_SETCURSEL,
                           SendMessage(GetDlgItem(hDlg, IDD_PRIOR), CB_FINDSTRINGEXACT, 0, (LPARAM) szString),0); 
               return FALSE ;

          case WM_COMMAND :
               switch (LOWORD (wParam))
                    {
		              case IDD_OK :
                         layer[iLayer].status=1-SendMessage(GetDlgItem(hDlg, IDD_LAYEROFF), BM_GETCHECK, 0, 0);
                         layer[iLayer].arc=iArc;
                         GetWindowText(GetDlgItem(hDlg, IDD_ZOFFSET), szString, 30);
                         endptr=NULL;
                         fTemp=(float) strtod(szString, &endptr);
                         if(*endptr==NULL) layer[iLayer].zoffset=fTemp;
                         GetWindowText(GetDlgItem(hDlg, IDD_DEPTH), szString, 30);
                         endptr=NULL;
                         fTemp=(float) fabs(strtod(szString, &endptr));
                         if(*endptr==NULL) layer[iLayer].depth=fTemp;
                         SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_GETLBTEXT,
                                     SendMessage(GetDlgItem(hDlg, IDD_ZCHAR), CB_GETCURSEL, 0, 0), (LPARAM) szString);
                         layer[iLayer].zchar=szString[0];
                         SendMessage(GetDlgItem(hDlg, IDD_PRIOR), CB_GETLBTEXT,
                                     SendMessage(GetDlgItem(hDlg, IDD_PRIOR), CB_GETCURSEL, 0, 0), (LPARAM) szString);
                         endptr=NULL;
                         iTemp=(int) strtol(szString, &endptr, 10);
                         if(*endptr==NULL) layer[iLayer].priority=iTemp;
		              case IDD_CANCEL :
                         EndDialog (hDlg, 0) ;
                         return TRUE;
                    case IDD_EITHERARC :
                    case IDD_CCWARC :
                    case IDD_CWARC :
                         iArc=LOWORD (wParam);
                         CheckRadioButton(hDlg,IDD_EITHERARC,IDD_CWARC,LOWORD (wParam));
                         return TRUE;
                    }
               break ;
          }
     return FALSE ;
     }

HWND prehwnd, posthwnd;
char *szTemp1, *szTemp2;
BOOL CALLBACK PriorityDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     static int iPriority;
     static char szString[30], *endptr;
     static float fTemp;
     static WNDCLASSEX wndclass ;

     switch (iMsg)
          {
          case WM_INITDIALOG :
               iPriority=SendMessage(GetDlgItem(hWindow, IDD_PRIORITY), LB_GETCURSEL, 0, 0);
               sprintf(szString,"%d",iPriority+1);
               SetWindowText(GetDlgItem(hDlg, IDD_PRIODISP),szString);
               if(priority[iPriority].optimize==TRUE) SendMessage(GetDlgItem(hDlg, IDD_OPTIMIZE), BM_SETCHECK, 1, 0);
               sprintf(szString,"%f",priority[iPriority].release);
               SetWindowText(GetDlgItem(hDlg, IDD_RELEASE),szString);
               sprintf(szString,"%f",priority[iPriority].close);
               SetWindowText(GetDlgItem(hDlg, IDD_CLOSE),szString);
               wndclass.cbSize        = sizeof (wndclass) ;
               wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
               wndclass.lpfnWndProc   = CodeWndProc ;
               wndclass.cbClsExtra    = 0 ;
               wndclass.cbWndExtra    = 0 ;
               wndclass.hInstance     = NULL ;
               wndclass.hIcon         = LoadIcon (hInst, szAppName) ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -