📄 xemc.cc
字号:
emcCommandBuffer->write(emc_task_plan_run_msg); programStartLineLast = programStartLine; programStartLine = 0; return 0;}static int sendProgramPause(){ EMC_TASK_PLAN_PAUSE emc_task_plan_pause_msg; emc_task_plan_pause_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_task_plan_pause_msg); return 0;}static int sendProgramResume(){ EMC_TASK_PLAN_RESUME emc_task_plan_resume_msg; emc_task_plan_resume_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_task_plan_resume_msg); return 0;}static int sendProgramStep(){ EMC_TASK_PLAN_STEP emc_task_plan_step_msg; // first reopen program if it's not open if (0 == emcStatus->task.file[0]) { // send a request to open last one sendProgramOpen(lastProgramFile); // wait for command to go out if (0 != emcCommandWaitDone(emcCommandSerialNumber)) { printError("error executing command\n"); return -1; } } emc_task_plan_step_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_task_plan_step_msg); programStartLineLast = programStartLine; programStartLine = 0; return 0;}static int sendMdiCmd(char *mdi){ EMC_TASK_PLAN_EXECUTE emc_task_plan_execute_msg; strcpy(emc_task_plan_execute_msg.command, mdi); emc_task_plan_execute_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_task_plan_execute_msg); return 0;}static int sendLoadToolTable(const char *file){ EMC_TOOL_LOAD_TOOL_TABLE emc_tool_load_tool_table_msg; strcpy(emc_tool_load_tool_table_msg.file, file); emc_tool_load_tool_table_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_tool_load_tool_table_msg); return 0;}static int sendAxisSetFerror(int axis, double ferror){ EMC_AXIS_SET_FERROR emc_axis_set_ferror_msg; emc_axis_set_ferror_msg.axis = axis; emc_axis_set_ferror_msg.ferror = ferror; emc_axis_set_ferror_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_axis_set_ferror_msg); return 0;}// paths to awk and xgraph, using to plot logs// fill these in for your system, if these are not in user's path#define AWK_PATH "awk"#define XGRAPH_PATH "xgraph"#define SYSTEM_STRING_LEN 1024// X stuff starts here// flag signifying that window needs to be redrawnstatic int redraw = 1;// global context and widgets, accessed during periodic timerstatic XtAppContext app_context;static Atom killAtom;static Widget topLevel;static Widget topForm;static Widget barMenuForm;static Widget abortCommand;static Widget fileMenu;static Widget viewMenu;static Widget settingsMenu;static Widget helpMenu;static Widget limCommand;static Widget commandMenuForm;static Widget stateMenu;static Widget modeMenu;static Widget mistMenu;static Widget floodMenu;static Widget spindleMenu;static Widget spindleIncLabel, spindleDecLabel;static Widget brakeMenu;static Widget toolTableShell = NULL, toolTableForm, toolTableLabel, toolTableText, toolTableDone, toolTableCancel;static Widget varFileShell = NULL, varFileForm, varFileLabel, varFileText, varFileDone, varFileCancel;static Widget toolNumberForm, toolNumberFormTitle, toolNumberFormName;static Widget toolOffsetForm, toolOffsetFormTitle, toolOffsetFormName;static Widget toolSetOffsetShell, toolSetOffsetForm, toolSetOffsetToolLabel, toolSetOffsetTool, toolSetOffsetLengthLabel, toolSetOffsetLength, toolSetOffsetDiameterLabel, toolSetOffsetDiameter, toolSetOffsetDone, toolSetOffsetCancel;static Widget positionTypeForm, positionTypeFormTitle, positionTypeFormName;static Widget workOffsetForm, workOffsetFormTitle, workOffsetFormName;static Widget posLabel[XEMC_NUM_AXES];static Widget posOffsetShell, posOffsetDialog;static Widget jogSpeedForm, jogSpeedTitleLabel, jogSpeedLabel, jogSpeedIncLabel, jogSpeedDecLabel;static Widget jogSpeedShell, jogSpeedDialog;static Widget jogIncrementForm, jogIncrementTitleLabel, jogIncrementMenu;static Widget jogForm, jogTitleLabel, jogMinusLabel, homeCommand, jogPlusLabel;static Widget feedOverrideForm, feedOverrideTitleLabel, feedOverrideLabel, feedOverrideIncLabel, feedOverrideDecLabel;static Widget feedOverrideShell, feedOverrideDialog;static Widget mdiForm, mdiFormTitle, mdiFormText;static Widget mdiCodesLabel;static Widget programForm, programFormTitle, programFormName, programFormStateTitle, programFormState;static Widget programOpenCommand, programRunCommand, programPauseCommand, programResumeCommand, programStepCommand, programVerifyCommand;static Widget programText;static Widget fileOpenShell, fileOpenDialog, fileOpenDone, fileOpenCancel;static char EDITOR_FILE[256] = ""; // FIXME-- hardcodedstatic Widget fileEditShell, fileEditDialog, fileEditDone, fileEditCancel;static Widget fileEditorShell = NULL, fileEditorForm, fileEditorLabel, fileEditorText, fileEditorDone, fileEditorCancel, fileEditorMark;static Widget fileQuitShell, fileQuitDialog, fileQuitDone, fileQuitCancel;static Widget helpXemcShell = NULL, helpXemcForm, helpXemcLabel, helpXemcText, helpXemcDone;static Widget helpAboutShell, helpAboutDialog, helpAboutDone;static Widget errorShell = 0, errorDialog = 0, errorDone = 0;// Pixel values inited from strings, for hard-coded colorsstatic Pixel pixelWhite;static Pixel pixelBlack;static Pixel pixelRed;static Pixel pixelYellow;static Pixel pixelGreen;// saved background and border colors for position labels,// cleared and restored when highlightingstatic Pixel posLabelBackground[XEMC_NUM_AXES];static Pixel posLabelBorderColor[XEMC_NUM_AXES];static int getColor(Widget w, Pixel *pixel, int foreground){ Arg args; if (foreground) XtSetArg(args, XtNforeground, pixel); else XtSetArg(args, XtNbackground, pixel); XtGetValues(w, &args, 1); return 0;}static int setColor(Widget w, Pixel pixel, int foreground){ if (foreground) XtVaSetValues(w, XtNforeground, pixel, NULL); else XtVaSetValues(w, XtNbackground, pixel, NULL); return 0;}static int stringToPixel(Widget w, String string, Pixel *pixel){ XrmValue from, to; from.addr = string; from.size = strlen(string) + 1; to.addr = (char *) pixel; to.size = sizeof(Pixel); if (False == XtConvertAndStore(w, XtRString, &from, XtRPixel, &to)) return -1; return 0;}static int getBorderColor(Widget w, Pixel *pixel){ Arg args; XtSetArg(args, XtNborderColor, pixel); XtGetValues(w, &args, 1); return 0;}static int setBorderColor(Widget w, Pixel pixel){ XtVaSetValues(w, XtNborderColor, pixel, NULL); return 0;}static int setLabel(Widget w, char *label){ Arg args; int width; XtSetArg(args, XtNwidth, &width); XtGetValues(w, &args, 1); XtVaSetValues(w, XtNlabel, label, NULL); XtVaSetValues(w, XtNwidth, width, NULL); return(0);}static int setProgramText(char *text){ XtVaSetValues(programText, XtNstring, text, NULL); return(0);}// index is diff between top and line to highlight, 0..maxstatic int highlightProgramText(char *text, int index){ int start, end; // position 'start' to first char on index line for (start = 0; ; start++) { if (index <= 0) { break; } if (text[start] == 0 || text[start] == '\n') { index--; } } // position 'end' to last char on index line for (end = start; ; end++) { if (text[end] == 0 || text[end] == '\n') { break; } } XawTextSetSelection(programText, start, end); return(0);}// dialogPopup() is an XtNcallback that expects a// transientShellWidget class as the client_data.// Widget w is not used, but is required if this is to be used// as a callback function. If you call it directly you can put NULL// in for w and call_data.static void dialogPopup(Widget w, XtPointer client_data, XtPointer call_data){ Position x, y; Dimension width, height; // get the coordinates of the middle of topLevel widget XtVaGetValues(topForm, XtNwidth, &width, XtNheight, &height, NULL); // translate coordinates in application top-level window // into coordinates from root window origin XtTranslateCoords(topForm, (Position) 100, (Position) 100, &x, &y); // move popup shell to this position (it's not visible yet) XtVaSetValues((Widget) client_data, XtNx, x, XtNy, y, NULL); XtPopup((Widget) client_data, XtGrabNone);}// command callbacksstatic void limCB(Widget w, XtPointer client_data, XtPointer call_data){ sendOverrideLimits();}static void abortCB(Widget w, XtPointer client_data, XtPointer call_data){ sendAbort();}static void homeCB(Widget w, XtPointer client_data, XtPointer call_data){ sendHome(activeAxis);}// flag to prevent errors from popping up multiple timesstatic int errorIsPopped = 0;static void errorReturnAction(Widget w, XEvent *event, String *params, Cardinal *num_params){ XtPopdown(errorShell); errorIsPopped = 0; destroyErrorShell();}static void errorDoneCB(Widget w, XtPointer client_data, XtPointer call_data){ XtPopdown(errorShell); errorIsPopped = 0; destroyErrorShell();}// createErrorShell() creates the error dialog widget afresh,// so that it gets sized correctly for each different error message.// Otherwise, the widget is sized for the first message, and then// that size is used for all subsequent messages.static int createErrorShell(){ if (NULL != errorShell) { return 0; } errorShell = XtVaCreatePopupShell("errorShell", transientShellWidgetClass, topLevel, NULL); errorDialog = XtVaCreateManagedWidget("errorDialog", dialogWidgetClass, errorShell, NULL); errorDone = XtVaCreateManagedWidget("errorDone", commandWidgetClass, errorDialog, NULL); XtAddCallback(errorDone, XtNcallback, errorDoneCB, errorShell); return 0;}static int destroyErrorShell(){ if (0 != errorDone) { XtDestroyWidget(errorDone); errorDone = 0; } if (0 != errorDialog) { XtDestroyWidget(errorDialog); errorDialog = 0; } if (0 != errorShell) { XtDestroyWidget(errorShell); errorShell = 0; } return 0;}static void popupError(const char *fmt, ...){ va_list ap; char string[256]; // FIXME-- hardcoded value va_start(ap, fmt); vsprintf(string, fmt, ap); va_end(ap); if (errorIsPopped) { // we're popped up already, so just print the error to stdout fprintf(stderr, "error: %s\n", string); return; } destroyErrorShell(); createErrorShell(); XtVaSetValues(errorDialog, XtNlabel, string, NULL); errorIsPopped = 1; dialogPopup(NULL, errorShell, NULL); // trap window kill XSetWMProtocols(XtDisplay(topLevel), XtWindow(errorShell), &killAtom, 1);}// file edit forward declsstatic void fileEditorDoneCB(Widget w, XtPointer client_data, XtPointer call_data);static void fileEditorCancelCB(Widget w, XtPointer client_data, XtPointer call_data);static void fileEditorMarkCB(Widget w, XtPointer client_data, XtPointer call_data);static int createFileEditorShell(int writeable);static int destroyFileEditorShell();static void doFileEditorDone(int get);static void fileEditorDoneCB(Widget w, XtPointer client_data, XtPointer call_data){ doFileEditorDone(1);}static void fileEditorCancelCB(Widget w, XtPointer client_data, XtPointer call_data){ doFileEditorDone(0);}static void fileEditorMarkCB(Widget w, XtPointer client_data, XtPointer call_data){ FILE *fp; XawTextPosition pos; int charcount = 0; int line = 1; char buffer[256]; // FIXME-- hardcoded if (NULL == (fp = fopen(EDITOR_FILE, "r"))) { return; } programStartLine = 0; pos = XawTextGetInsertionPoint(fileEditorText); while (! feof(fp)) { if (NULL == fgets(buffer, 256, fp)) { // hmmm... never found line popupError("Can't mark line-- character position\n%d outside range of file", pos); break; } charcount += strlen(buffer); if (charcount > pos) { // found it sendProgramOpen(EDITOR_FILE); popupError("Marking program to start here:\n%s", buffer); programStartLine = line; break; } line++; } fclose(fp);}static int createFileEditorShell(int writeable){ char label[256]; // FIXME-- hardcoded if (NULL != fileEditorShell) { return 0; } strcpy(label, EDITOR_FILE); if (! writeable) { strcat(label, " (read only)"); } fileEditorShell = XtVaCreatePopupShell("fileEditorShell", topLevelShellWidgetClass, topLevel, XtNallowShellResize, True, NULL); fileEditorForm = XtVaCreateManagedWidget("fileEditorForm", formWidgetClass, fileEditorShell, NULL); fileEditorLabel = XtVaCreateManagedWidget("fileEditorLabel", labelWidgetClass, fileEditorForm, XtNlabel, label, NULL); fileEditorText = XtVaCreateManagedWidget("fileEditorText", asciiTextWidgetClass, fileEditorForm, XtNfromVert, fileEditorLabel, XtNeditType, (writeable ? XawtextEdit : XawtextRead), XtNtype, XawAsciiFile, XtNstring, EDITOR_FILE, XtNscrollVertical, XawtextScrollWhenNeeded, NULL); fileEditorDone = XtVaCreateManagedWidget("fileEditorDone", commandWidgetClass, fileEditorForm, XtNfromVert, fileEditorText, NULL); XtAddCallback(fileEditorDone, XtNcallback, fileEditorDoneCB, fileEditorShell); if (writeable) { XtSetSensitive(fileEditorDone, True); } else { XtSetSensitive(fileEditorDone, False); } fileEditorCancel = XtVaCreateManagedWidget("fileEditorCancel", commandWidgetClass, fileEditorForm, XtNfromVert, fileEditorText, XtNfromHoriz, fileEditorDone, NULL); XtAddCallback(fileEditorCancel, XtNcallback, fileEditorCancelCB, fileEditorShell); fileEditorMark = XtVaCreateManagedWidget("fileEditorMark", commandWidgetClass, fileEditorForm, XtNfromVert, fileEditorText, XtNfromHoriz, fileEditorCancel,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -