Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

XmEmc.cc

Go to the documentation of this file.
00001 /*
00002   XmEmc.cc
00003 
00004   This is the Motif main window application.
00005 
00006   Modification history:
00007 
00008   29-Sep-2000 JRM Initial version
00009   11-Oct-2000 JRM Changed E-stop to have less colors and if
00010                   pixmap fails to load, use plain text.
00011 */
00012 
00013 #define XMEMC
00014 #include "XmEmc.hh"
00015 #undef XMEMC
00016 
00017 int
00018 main (int argc, char *argv[])
00019 {
00020   Widget mainwindow = NULL;
00021   Widget menubar = NULL;
00022   Widget pane = NULL;
00023   Widget menu = NULL;
00024   Widget widget = NULL;
00025 
00026   XtAppContext app;
00027 
00028   XmString str;
00029 
00030   int i;
00031 
00032   toplevel = XtVaAppInitialize (&app,
00033                                 "XmEmc",
00034                                 NULL,
00035                                 0, &argc, argv, fallbackResources, NULL);
00036 
00037   mainwindow = XtVaCreateManagedWidget ("mainwindow",
00038                                         xmMainWindowWidgetClass, toplevel,
00039                                         XmNdeleteResponse, XmDESTROY,
00040                                         XmNtraversalOn, True, NULL);
00041 
00042   XtAddCallback (mainwindow, XmNdestroyCallback,
00043                  closeMainWindow, (XtPointer) NULL);
00044 
00045   menubar = XmCreateMenuBar (mainwindow, "menubar", NULL, 0);
00046 
00047   /*********************************/
00048   /* Create the File pulldown menu */
00049   /*********************************/
00050 
00051   menu = XmCreatePulldownMenu (menubar, "pulldown", NULL, 0);
00052 
00053   for (i = 0; fileMenu[i].label != NULL; i++)
00054     {
00055       widget = XtVaCreateManagedWidget (fileMenu[i].label,
00056                                         *(fileMenu[i].wClass),
00057                                         menu,
00058                                         XmNmarginWidth, 8,
00059                                         XmNmarginHeight, 8, NULL);
00060 
00061       if (fileMenu[i].mnemonic)
00062         XtVaSetValues (widget, XmNmnemonic, fileMenu[i].mnemonic, NULL);
00063 
00064       if (fileMenu[i].accelerator)
00065         {
00066           str = XmStringCreateLocalized (fileMenu[i].accel_text);
00067           XtVaSetValues (widget,
00068                          XmNaccelerator, fileMenu[i].accelerator,
00069                          XmNacceleratorText, str, NULL);
00070           XmStringFree (str);
00071         }
00072 
00073       if (fileMenu[i].callback)
00074         {
00075           XtAddCallback (widget,
00076                          XmNactivateCallback,
00077                          fileMenu[i].callback, fileMenu[i].callback_data);
00078         }
00079 
00080     }
00081 
00082   str = XmStringCreateLocalized ((char *) FILE_STR);
00083   filemenu = XtVaCreateManagedWidget (FILE_STR,
00084                                       xmCascadeButtonWidgetClass, menubar,
00085                                       XmNsubMenuId, menu,
00086                                       XmNlabelString, str,
00087                                       XmNmnemonic, FILE_MNEMONIC, NULL);
00088   XmStringFree (str);
00089 
00090   /*********************************/
00091   /* Create the Edit pulldown menu */
00092   /*********************************/
00093 
00094   menu = XmCreatePulldownMenu (menubar, "_pulldown", NULL, 0);
00095 
00096   for (i = 0; editMenu[i].label != NULL; i++)
00097     {
00098       widget = XtVaCreateManagedWidget (editMenu[i].label,
00099                                         *(editMenu[i].wClass),
00100                                         menu,
00101                                         XmNmarginWidth, 8,
00102                                         XmNmarginHeight, 8, NULL);
00103 
00104       if (editMenu[i].mnemonic)
00105         XtVaSetValues (widget, XmNmnemonic, editMenu[i].mnemonic, NULL);
00106 
00107       if (editMenu[i].accelerator)
00108         {
00109           str = XmStringCreateLocalized (editMenu[i].accel_text);
00110           XtVaSetValues (widget,
00111                          XmNaccelerator, editMenu[i].accelerator,
00112                          XmNacceleratorText, str, NULL);
00113           XmStringFree (str);
00114         }
00115 
00116       if (editMenu[i].callback)
00117         {
00118           XtAddCallback (widget,
00119                          XmNactivateCallback,
00120                          editMenu[i].callback, editMenu[i].callback_data);
00121         }
00122     }
00123 
00124 
00125   str = XmStringCreateLocalized ((char *) EDIT_STR);
00126   editmenu = XtVaCreateManagedWidget (EDIT_STR,
00127                                       xmCascadeButtonWidgetClass, menubar,
00128                                       XmNsubMenuId, menu,
00129                                       XmNlabelString, str,
00130                                       XmNmnemonic, EDIT_MNEMONIC, NULL);
00131   XmStringFree (str);
00132 
00133 
00134   /*********************************/
00135   /* Create the View pulldown menu */
00136   /*********************************/
00137 
00138   menu = XmCreatePulldownMenu (menubar, "_pulldown", NULL, 0);
00139 
00140   for (i = 0; viewMenu[i].label != NULL; i++)
00141     {
00142       widget = XtVaCreateManagedWidget (viewMenu[i].label,
00143                                         *(viewMenu[i].wClass),
00144                                         menu,
00145                                         XmNmarginWidth, 8,
00146                                         XmNmarginHeight, 8, NULL);
00147 
00148       if (viewMenu[i].mnemonic)
00149         XtVaSetValues (widget, XmNmnemonic, viewMenu[i].mnemonic, NULL);
00150 
00151       if (viewMenu[i].accelerator)
00152         {
00153           str = XmStringCreateLocalized (viewMenu[i].accel_text);
00154           XtVaSetValues (widget,
00155                          XmNaccelerator, viewMenu[i].accelerator,
00156                          XmNacceleratorText, str, NULL);
00157           XmStringFree (str);
00158         }
00159 
00160       if (viewMenu[i].callback)
00161         {
00162           XtAddCallback (widget,
00163                          XmNactivateCallback,
00164                          viewMenu[i].callback, viewMenu[i].callback_data);
00165         }
00166     }
00167 
00168 
00169   str = XmStringCreateLocalized ((char *) VIEW_STR);
00170   viewmenu = XtVaCreateManagedWidget (VIEW_STR,
00171                                       xmCascadeButtonWidgetClass, menubar,
00172                                       XmNsubMenuId, menu,
00173                                       XmNlabelString, str,
00174                                       XmNmnemonic, VIEW_MNEMONIC, NULL);
00175   XmStringFree (str);
00176 
00177   /*********************************/
00178   /* Create the Help pulldown menu */
00179   /*********************************/
00180 
00181   menu = XmCreatePulldownMenu (menubar, "_pulldown", NULL, 0);
00182 
00183   for (i = 0; helpMenu[i].label != NULL; i++)
00184     {
00185       widget = XtVaCreateManagedWidget (helpMenu[i].label,
00186                                         *(helpMenu[i].wClass),
00187                                         menu,
00188                                         XmNmarginWidth, 8,
00189                                         XmNmarginHeight, 8, NULL);
00190 
00191       if (helpMenu[i].mnemonic)
00192         XtVaSetValues (widget, XmNmnemonic, helpMenu[i].mnemonic, NULL);
00193 
00194       if (helpMenu[i].accelerator)
00195         {
00196           str = XmStringCreateLocalized (helpMenu[i].accel_text);
00197           XtVaSetValues (widget,
00198                          XmNaccelerator, helpMenu[i].accelerator,
00199                          XmNacceleratorText, str, NULL);
00200           XmStringFree (str);
00201         }
00202 
00203       if (helpMenu[i].callback)
00204         {
00205           XtAddCallback (widget,
00206                          XmNactivateCallback,
00207                          helpMenu[i].callback, helpMenu[i].callback_data);
00208         }
00209     }
00210 
00211 
00212   str = XmStringCreateLocalized ((char *) HELP_STR);
00213   helpmenu = XtVaCreateManagedWidget (HELP_STR,
00214                                       xmCascadeButtonWidgetClass, menubar,
00215                                       XmNsubMenuId, menu,
00216                                       XmNlabelString, str,
00217                                       XmNmnemonic, HELP_MNEMONIC, NULL);
00218   XmStringFree (str);
00219 
00220   XtVaSetValues (menubar, XmNmenuHelpWidget, helpmenu, NULL);
00221   XtManageChild (menubar);
00222 
00223 
00224   workArea =
00225     XtVaCreateManagedWidget ("workArea", xmFormWidgetClass, mainwindow,
00226                              XmNfractionBase, 40, NULL);
00227 
00228   pane = XtVaCreateWidget ("pane",
00229                            xmPanedWindowWidgetClass, workArea,
00230                            XmNsashWidth, 10,
00231                            XmNtopAttachment, XmATTACH_FORM,
00232                            XmNbottomAttachment, XmATTACH_NONE,
00233                            XmNleftAttachment, XmATTACH_NONE,
00234                            XmNrightAttachment, XmATTACH_FORM,
00235                            XmNsashHeight, 10, XmNtraversalOn, False, NULL);
00236 
00237   buttonform = XtVaCreateWidget ("form",
00238                                  xmFormWidgetClass, pane,
00239                                  XmNfractionBase, 220,
00240                                  XmNtraversalOn, False, NULL);
00241 
00242   int rc = XpmCreatePixmapFromData (XtDisplay (toplevel),
00243                                     DefaultRootWindow (XtDisplay (toplevel)),
00244                                     estop,
00245                                     &pixmap, 0, 0);
00246 
00247   rc +=
00248     XpmCreatePixmapFromData (XtDisplay (toplevel),
00249                              DefaultRootWindow (XtDisplay (toplevel)),
00250                              estop_off, &pixmap_off, 0, 0);
00251 
00252   Dimension width, height;
00253 
00254   if (rc == XpmSuccess)
00255     {
00256 
00257       /* The "estop" button */
00258       estopbutton = XtVaCreateManagedWidget (ESTOP_STR,
00259                                              xmPushButtonWidgetClass,
00260                                              buttonform, XmNtopAttachment,
00261                                              XmATTACH_FORM,
00262                                              XmNbottomAttachment,
00263                                              XmATTACH_NONE, XmNleftAttachment,
00264                                              XmATTACH_NONE,
00265                                              XmNrightAttachment,
00266                                              XmATTACH_FORM, XmNlabelPixmap,
00267                                              pixmap, XmNlabelType, XmPIXMAP,
00268                                              XmNshadowThickness, 4, NULL);
00269       XtVaGetValues (estopbutton, XmNwidth, &width, XmNheight, &height, NULL);
00270     }
00271   else
00272     {
00273       width = 78;
00274       height = 81;
00275       estopbutton = XtVaCreateManagedWidget (ESTOP_STR,
00276                                              xmPushButtonWidgetClass,
00277                                              buttonform, XmNtopAttachment,
00278                                              XmATTACH_FORM,
00279                                              XmNbottomAttachment,
00280                                              XmATTACH_NONE, XmNleftAttachment,
00281                                              XmATTACH_NONE,
00282                                              XmNrightAttachment,
00283                                              XmATTACH_FORM,
00284                                              XmNshadowThickness, 4, XmNwidth,
00285                                              width, XmNheight, height, NULL);
00286     }
00287 
00288   XtAddCallback (estopbutton, XmNarmCallback,
00289                  buttonsCB, (XtPointer) BT_ESTOP);
00290 
00291 
00292   // The "Machine" button
00293   machinebutton = XtVaCreateManagedWidget (MACHINE_STR,
00294                                            xmPushButtonWidgetClass,
00295                                            buttonform, XmNtopAttachment,
00296                                            XmATTACH_WIDGET,
00297                                            XmNbottomAttachment, XmATTACH_NONE,
00298                                            XmNleftAttachment, XmATTACH_NONE,
00299                                            XmNrightAttachment, XmATTACH_FORM,
00300                                            XmNtopWidget, estopbutton,
00301                                            XmNshadowThickness, 4,
00302                                            XmNwidth, width, XmNheight, height,
00303                                            NULL);
00304 
00305   XtAddCallback (machinebutton, XmNarmCallback,
00306                  buttonsCB, (XtPointer) BT_MACHINE);
00307 
00308   // Save the original colors so we can go back to this state. Only need one set for all buttons.
00309   XtVaGetValues (machinebutton, XmNtopShadowColor, &original_tsc,
00310                  XmNbottomShadowColor, &original_bsc,
00311                  XmNarmColor, &original_ac,
00312                  XmNbackground, &original_bg, NULL);
00313 
00314   // The "Abort" button
00315   abortbutton = XtVaCreateManagedWidget (ABORT_STR,
00316                                          xmPushButtonWidgetClass, buttonform,
00317                                          XmNtopAttachment, XmATTACH_WIDGET,
00318                                          XmNbottomAttachment, XmATTACH_NONE,
00319                                          XmNleftAttachment, XmATTACH_NONE,
00320                                          XmNrightAttachment, XmATTACH_FORM,
00321                                          XmNtopWidget, machinebutton,
00322                                          XmNshadowThickness, 4,
00323                                          XmNwidth, width, XmNheight, height,
00324                                          XmNmappedWhenManaged, False, NULL);
00325 
00326   XtAddCallback (abortbutton, XmNarmCallback,
00327                  buttonsCB, (XtPointer) BT_ABORT);
00328 
00329   // The "Mist" button
00330   mistbutton = XtVaCreateManagedWidget (MIST_STR,
00331                                         xmPushButtonWidgetClass, buttonform,
00332                                         XmNtopAttachment, XmATTACH_WIDGET,
00333                                         XmNbottomAttachment, XmATTACH_NONE,
00334                                         XmNleftAttachment, XmATTACH_NONE,
00335                                         XmNrightAttachment, XmATTACH_FORM,
00336                                         XmNtopWidget, machinebutton,
00337                                         XmNsensitive, False,
00338                                         XmNshadowThickness, 4,
00339                                         XmNwidth, width, XmNheight, height,
00340 #ifndef XMEMC_MIST
00341                                         XmNmappedWhenManaged, False,
00342 #endif // XMEMC_MIST
00343                                         NULL);
00344 
00345   XtAddCallback (mistbutton, XmNarmCallback, buttonsCB, (XtPointer) BT_MIST);
00346 
00347   // The "Flood" button
00348   floodbutton = XtVaCreateManagedWidget (FLOOD_STR,
00349                                          xmPushButtonWidgetClass, buttonform,
00350                                          XmNtopAttachment, XmATTACH_WIDGET,
00351                                          XmNbottomAttachment, XmATTACH_NONE,
00352                                          XmNleftAttachment, XmATTACH_NONE,
00353                                          XmNrightAttachment, XmATTACH_FORM,
00354                                          XmNtopWidget, mistbutton,
00355                                          XmNsensitive, False,
00356                                          XmNshadowThickness, 4,
00357                                          XmNwidth, width, XmNheight, height,
00358 #ifndef XMEMC_FLOOD
00359                                          XmNmappedWhenManaged, False,
00360 #endif // XMEMC_FLOOD
00361                                          NULL);
00362 
00363   XtAddCallback (floodbutton, XmNarmCallback,
00364                  buttonsCB, (XtPointer) BT_FLOOD);
00365 
00366 
00367   // The "brake" button
00368   brakebutton = XtVaCreateManagedWidget (BRAKE_STR,
00369                                          xmPushButtonWidgetClass, buttonform,
00370                                          XmNtopAttachment, XmATTACH_WIDGET,
00371                                          XmNbottomAttachment, XmATTACH_NONE,
00372                                          XmNleftAttachment, XmATTACH_NONE,
00373                                          XmNrightAttachment, XmATTACH_FORM,
00374                                          XmNtopWidget, floodbutton,
00375                                          XmNsensitive, False,
00376                                          XmNshadowThickness, 4,
00377                                          XmNwidth, width, XmNheight, height,
00378 #ifndef XMEMC_BRAKE
00379                                          XmNmappedWhenManaged, False,
00380 #endif // XMEMC_BRAKE
00381                                          NULL);
00382 
00383   XtAddCallback (brakebutton, XmNarmCallback,
00384                  buttonsCB, (XtPointer) BT_BRAKE);
00385 
00386   // The "reset" button
00387   resetbutton = XtVaCreateManagedWidget (RESET_STR,
00388                                          xmPushButtonWidgetClass, buttonform,
00389                                          XmNtopAttachment, XmATTACH_WIDGET,
00390                                          XmNbottomAttachment, XmATTACH_NONE,
00391                                          XmNleftAttachment, XmATTACH_NONE,
00392                                          XmNrightAttachment, XmATTACH_FORM,
00393                                          XmNtopWidget, floodbutton,
00394                                          XmNmappedWhenManaged, False,
00395                                          XmNshadowThickness, 4,
00396                                          XmNwidth, width,
00397                                          XmNheight, height, NULL);
00398 
00399   pb = (XmPushButtonWidget) resetbutton;
00400   pb->pushbutton.armed = false;
00401 
00402   XtAddCallback (resetbutton, XmNarmCallback,
00403                  buttonsCB, (XtPointer) BT_RESET);
00404 
00405   /* ---------------------------------------------------------------- */
00406 
00407   XtVaSetValues (buttonform, XmNpaneMaximum, 800, XmNpaneMinimum, 200, NULL);
00408 
00409   XtManageChild (buttonform);
00410 
00411 
00412   XtManageChild (pane);
00413 
00414   Dimension x0 = 3;
00415   Dimension x1 = 30;
00416   Dimension y1 = 20;            // JRM was 5
00417   Dimension y2 = y1 + 5 * EMC_NUM_AXES + 4;
00418   Dimension boxMarginWidth = 5;
00419   Dimension boxMarginHeight = 5;
00420 
00421   jog_widget =
00422     JogControl (x0, x1, y1, y2, boxMarginWidth, boxMarginHeight, workArea,
00423                 EMC_NUM_AXES);
00424 
00425   x0 = 1;
00426   x1 = 22;
00427   y1 = 30;
00428   y2 = 40;
00429   spindle_widget =
00430     SpindleControl (x0, x1, y1, y2, boxMarginWidth, boxMarginHeight,
00431                     workArea);
00432 
00433   createAxes ();
00434   createPosition ();
00435   createRunModes ();
00436   createScrolledText ();
00437 
00438   // Set up in Manual mode
00439   buttonsCB (manualMode, (XtPointer) MANUAL_MODE, (XtPointer) NULL);
00440 
00441   // Start off in the ESTOP condition.
00442   buttonsCB (estopbutton, (XtPointer) BT_ESTOP, (XtPointer) NULL);
00443 
00444   XtRealizeWidget (toplevel);
00445 
00446   XtAppMainLoop (app);
00447 }
00448 
00449 static void
00450 closeMainWindow (Widget mw, XtPointer cd, XtPointer cb)
00451 {
00452   (void) XtDestroyWidget ((Widget) toplevel);
00453   exit (0);
00454 }
00455 
00456 static void
00457 fileMenuCB (Widget mw, XtPointer cd, XtPointer cb)
00458 {
00459   int which = (int) cd;
00460 
00461   switch (which)
00462     {
00463     case FM_QUIT:
00464       // Avoid multiple popup syndrome
00465       if (!quitmenu)
00466         quitPopup (mw, (void *)QUIT_TITLE, cd);
00467       else
00468         RAISE_WIDGET (quitmenu);
00469       break;
00470     case FM_OPEN:
00471       // Avoid multiple popup syndrome
00472       if (!openfile)
00473         fileOpenPopup (mw, (void *)FILE_OPEN_TITLE, cd);
00474       else
00475         RAISE_WIDGET (openfile);
00476       break;
00477     case FM_NEW:
00478       break;
00479     case FM_SAVE_AS:
00480       // Avoid multiple popup syndrome
00481       if (!savefile)
00482         fileOpenPopup (mw, (void *)FILE_SAVE_TITLE, cd);
00483       else
00484         RAISE_WIDGET (savefile);
00485       break;
00486     case FM_SAVE:
00487       break;
00488     case FM_LOGGING:
00489       break;
00490     default:
00491       break;
00492     }
00493 }
00494 
00495 static void
00496 editMenuCB (Widget mw, XtPointer cd, XtPointer cb)
00497 {
00498   int which = (int) cd;
00499 
00500   switch (which)
00501     {
00502     case ED_EDIT:
00503       if (!editedit)
00504         fileOpenPopup (mw, (void *)EDIT_EDIT_TITLE, (XtPointer) cd);
00505       else
00506         RAISE_WIDGET (editedit);
00507       break;
00508     case ED_TOOLS:
00509       break;
00510     case ED_VARIABLES:
00511       break;
00512     case ED_CALIBRATION_0:
00513       break;
00514     case ED_CALIBRATION_1:
00515       break;
00516     case ED_CALIBRATION_2:
00517       break;
00518     default:
00519       break;
00520     }
00521 }
00522 
00523 static void
00524 viewMenuCB (Widget mw, XtPointer cd, XtPointer cb)
00525 {
00526   int which = (int) cd;
00527 
00528   switch (which)
00529     {
00530     case VW_DIAGS_0:
00531       break;
00532     case VW_DIAGS_1:
00533       break;
00534     case VW_DIAGS_2:
00535       break;
00536     default:
00537       break;
00538     }
00539 }
00540 
00541 static void
00542 helpMenuCB (Widget mw, XtPointer cd, XtPointer cb)
00543 {
00544   int which = (int) cd;
00545 
00546   switch (which)
00547     {
00548     case HM_HELP:
00549       break;
00550     case HM_ABOUT:
00551       // Avoid multiple popup syndrome
00552       if (!abouthelp)
00553         aboutPopup (mw, (void *)ABOUT_TEXT, cd);
00554       else
00555         RAISE_WIDGET (abouthelp);
00556       break;
00557     default:
00558       break;
00559     }
00560 }
00561 
00562 // These buttons can be called from anywhere (and hence not
00563 // static (e.g., if the emc receives a hardware e-stop, it
00564 // can call this routine to let the GUI reflect the condition.
00565 // For instance: 
00566 //
00567 // buttonsCB (estopbutton, (XtPointer) BT_ESTOP, (XtPointer) NULL);
00568 //
00569 // would call the estop function.
00570 //
00571 void
00572 buttonsCB (Widget mw, XtPointer cd, XtPointer cb)
00573 {
00574   XmString valueLabel = NULL;
00575   switch ((int) cd)
00576     {
00577     case BT_MACHINE:
00578       TOGGLE (mw);
00579 
00580       if (isMachineOn)
00581         turnMachineOff ();
00582       else
00583         turnMachineOn ();
00584 
00585       // If the machine was off and now its on, do the following:
00586       if (isMachineOn)
00587         {
00588           UNLOCK (brakebutton);
00589           PRESS (brakebutton);
00590           UNLOCK (mistbutton);
00591           UNLOCK (floodbutton);
00592           HIDE_MANUAL ();
00593           HIDE_AUTO ();
00594           HIDE_MDI ();
00595           do_home ();
00596         }
00597       // If the machine was on and now its off, do the following:
00598       else
00599         {
00600           turnMistOff ();
00601           turnFloodOff ();
00602           turnBrakeOn ();
00603           hideSpindle ();
00604           stopSpindle ();
00605           jogDone ();
00606 
00607           switch (runMode)
00608             {
00609             case MANUAL_MODE:
00610               LOCK (brakebutton);
00611               PRESS (brakebutton);
00612               LOCK (mistbutton);
00613               UNPRESS (mistbutton);
00614               LOCK (floodbutton);
00615               UNPRESS (floodbutton);
00616               SHOW_MANUAL ();
00617               break;
00618             case AUTO_MODE:
00619               SHOW_AUTO ();
00620               HIDE (scrolledText);
00621               break;
00622             case MDI_MODE:
00623               SHOW_MDI ();
00624               HIDE (scrolledText);
00625               break;
00626             }
00627         }
00628 
00629       break;
00630 
00631     case BT_ABORT:
00632       wasAborted = True;
00633       isRunning = False;
00634 
00635       turnMachineOff ();
00636       HIDE (abortbutton);
00637       UNLOCK (machinebutton);
00638       UNPRESS (machinebutton);
00639 
00640       // Turn off all other that the AUTO might have turned on
00641       turnMistOff ();
00642       turnFloodOff ();
00643       turnBrakeOn ();
00644       stopSpindle ();
00645       hideSpindle ();
00646 
00647       LOCK (runModes);          // We want to see where it stopped, but not allow to continue
00648       LOCK (scrolledText);
00649       LOCK (pauseButton);
00650       LOCK (stepButton);
00651       valueLabel =
00652         XmStringCreateLtoR ((char *) ABORTED_STR, XmSTRING_DEFAULT_CHARSET);
00653       XtVaSetValues (runButton, XmNlabelString, valueLabel, NULL);
00654       XmStringFree (valueLabel);
00655 
00656       processAbort ();
00657 
00658       break;
00659 
00660     case BT_MIST:
00661       TOGGLE (mw);
00662 
00663       if (isMistOn)
00664         turnMistOff ();
00665       else
00666         turnMistOn ();
00667 
00668       break;
00669     case BT_FLOOD:
00670       TOGGLE (mw);
00671 
00672       if (isFloodOn)
00673         turnFloodOff ();
00674       else
00675         turnFloodOn ();
00676 
00677       break;
00678     case BT_BRAKE:
00679       TOGGLE (mw);
00680 
00681       if (isBrakeOn)
00682         {
00683           turnBrakeOff ();
00684           showSpindle ();
00685         }
00686       else
00687         {
00688           turnBrakeOn ();
00689           stopSpindle ();
00690           hideSpindle ();
00691         }
00692 
00693       break;
00694     case BT_ESTOP:
00695 
00696       do_estop ();
00697 
00698       turnBrakeOn ();
00699       stopSpindle ();
00700       hideSpindle ();
00701 
00702       turnMachineOff ();
00703       turnMistOff ();
00704       turnFloodOff ();
00705 
00706       TOGGLE (mw);
00707 
00708       XtVaSetValues (mw, XmNlabelInsensitivePixmap, pixmap_off, NULL);
00709 
00710       LOCK (mw);
00711 
00712       PRESS (brakebutton);
00713       LOCK (brakebutton);
00714 
00715       UNPRESS (mistbutton);
00716       LOCK (mistbutton);
00717 
00718       UNPRESS (machinebutton);
00719       LOCK (machinebutton);
00720 
00721       UNPRESS (floodbutton);
00722       LOCK (floodbutton);
00723 
00724       jogDone ();
00725 
00726       setSpindleSpeed (INITIAL_SPINDLE_SPEED);
00727       run_finished ();
00728       call_resume ();
00729       unsetLimitOverride ();
00730 
00731       HIDE_MANUAL ();
00732       HIDE_AUTO ();
00733       HIDE_MDI ();
00734       SHOW (resetbutton);
00735 
00736       break;
00737     case BT_RESET:
00738 
00739       HIDE (resetbutton);
00740       TOGGLE (estopbutton);
00741       UNLOCK (estopbutton);
00742 
00743       // Act as if one pressed the Machine button if it's turned on
00744       SHOW (machinebutton);
00745       UNLOCK (machinebutton);
00746       if (isMachineOn)
00747         {
00748           buttonsCB (machinebutton, (XtPointer) BT_MACHINE, (XtPointer) NULL);
00749         }
00750 
00751       break;
00752 
00753     case COORD_RELATIVE:
00754 
00755       if (!isCoordRelative)
00756         setCoordRelative ();
00757       break;
00758 
00759     case COORD_MACHINE:
00760 
00761       if (isCoordRelative)
00762         setCoordMachine ();
00763       break;
00764 
00765     case POSITION_ACTUAL:
00766 
00767       if (!isPosActual)
00768         setPosActual ();
00769       break;
00770 
00771     case POSITION_COMMANDED:
00772 
00773       if (isPosActual)
00774         setPosCommanded ();
00775       break;
00776 
00777     case DO_RUN:
00778       call_run ();
00779       break;
00780 
00781     case PAUSE_RESUME:
00782       if (!isPaused)
00783         call_pause ();
00784       else
00785         call_resume ();
00786       break;
00787 
00788     case STEP:
00789       call_step ();
00790       break;
00791 
00792     case LIMIT_OVERRIDE:
00793       setLimitOverride ();
00794       break;
00795 
00796     case JOG_BUTTON:
00797       showJogPopup ();
00798       break;
00799 
00800     case AUTO_MODE:
00801       if (runMode != AUTO_MODE)
00802         setModeAuto ();
00803       break;
00804 
00805     case MDI_MODE:
00806       if (runMode != MDI_MODE)
00807         setModeMDI ();
00808       break;
00809 
00810     case MANUAL_MODE:
00811       if (runMode != MANUAL_MODE)
00812         setModeManual ();
00813       break;
00814     }
00815 }
00816 static void
00817 quitPopup (Widget push_button, XtPointer text, XtPointer cbs)
00818 {
00819   XmString xm_string;
00820   XmString quit_string;
00821   XmString dont_quit_string;
00822   Arg args[5];
00823 
00824   xm_string =
00825     XmStringCreateLtoR ((char *) QUIT_QUESTION, XmFONTLIST_DEFAULT_TAG);
00826   XtSetArg (args[0], XmNmessageString, xm_string);
00827   quit_string = XmStringCreateLtoR (QUIT_STR, XmFONTLIST_DEFAULT_TAG);
00828   XtSetArg (args[1], XmNokLabelString, quit_string);
00829   dont_quit_string =
00830     XmStringCreateLtoR (DONT_QUIT_STR, XmFONTLIST_DEFAULT_TAG);
00831   XtSetArg (args[2], XmNcancelLabelString, dont_quit_string);
00832 
00833   // Note that Lesstif has overriding default button broken, but Motif works ok.
00834   XtSetArg (args[3], XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON);
00835 
00836   XtSetArg (args[4], XmNtitle, text);
00837 
00838   quitmenu = XmCreateQuestionDialog (push_button, "areYouSure", args, 5);
00839 
00840   XmStringFree (xm_string);
00841   XmStringFree (quit_string);
00842   XmStringFree (dont_quit_string);
00843 
00844   XtUnmanageChild (XmMessageBoxGetChild (quitmenu, XmDIALOG_HELP_BUTTON));
00845 
00846   XtVaSetValues (XmMessageBoxGetChild (quitmenu, XmDIALOG_OK_BUTTON),
00847                  XmNshadowThickness, 4,
00848                  XmNmarginWidth, 12, XmNmarginHeight, 12, NULL);
00849 
00850   XtVaSetValues (XmMessageBoxGetChild (quitmenu, XmDIALOG_CANCEL_BUTTON),
00851                  XmNshadowThickness, 4,
00852                  XmNmarginWidth, 12, XmNmarginHeight, 12, NULL);
00853 
00854   XtAddCallback (quitmenu, (String) XmNokCallback,
00855                  (XtCallbackProc) reallyQuit, (XtPointer) cbs);
00856   XtAddCallback (quitmenu, (String) XmNcancelCallback, (XtCallbackProc) canc,
00857                  (XtPointer) cbs);
00858 
00859   XtManageChild (quitmenu);
00860 
00861   XtPopup (XtParent (quitmenu), XtGrabExclusive);
00862 }
00863 
00864 static void
00865 fileOpenPopup (Widget push_button, XtPointer text, XtPointer cbs)
00866 {
00867   XmString xm_string = NULL;
00868   XmString open_string = NULL;
00869   XmString dont_open_string = NULL;
00870   XmString filter_string = NULL;
00871   XmString filter_title = NULL;
00872   Arg args[6];
00873   int i;
00874 
00875 
00876   xm_string = XmStringCreateSimple ((char *) text);
00877 
00878   i = 0;
00879   XtSetArg (args[i], XmNmessageString, xm_string);
00880   i++;
00881   XtSetArg (args[i], XmNtitle, text);
00882   i++;
00883   // The following controls the width of the File Selection Box
00884   filter_title =
00885     XmStringCreateLtoR (FILTER_TITLE_STR, XmFONTLIST_DEFAULT_TAG);
00886   XtSetArg (args[i], XmNfilterLabelString, filter_title);
00887   i++;
00888   // The following is to make all the buttons taller.
00889   filter_string = XmStringCreateLtoR (FILTER_STR, XmFONTLIST_DEFAULT_TAG);
00890   XtSetArg (args[i], XmNapplyLabelString, filter_string);
00891   i++;
00892 
00893   switch ((int) cbs)
00894     {
00895     case FM_OPEN:
00896       open_string = XmStringCreateSimple (OPEN_STR);
00897       dont_open_string =
00898         XmStringCreateLtoR (DONT_OPEN_STR, XmFONTLIST_DEFAULT_TAG);
00899       XtSetArg (args[i], XmNokLabelString, open_string);
00900       i++;
00901       XtSetArg (args[i], XmNcancelLabelString, dont_open_string);
00902       i++;
00903       openfile =
00904         XmCreateFileSelectionDialog (push_button, "fileOpen", args, i);
00905       XmStringFree (open_string);
00906       XmStringFree (dont_open_string);
00907 
00908       THICKEN_FS_BUTTONS (openfile);
00909       POPUP_FILE_SELECTION_WIDGET (openfile, cbs);
00910       break;
00911     case FM_SAVE_AS:
00912       savefile =
00913         XmCreateFileSelectionDialog (push_button, "fileOpen", args, i);
00914 
00915       THICKEN_FS_BUTTONS (savefile);
00916       POPUP_FILE_SELECTION_WIDGET (savefile, cbs);
00917       break;
00918     case ED_EDIT:
00919       editedit =
00920         XmCreateFileSelectionDialog (push_button, "fileOpen", args, i);
00921 
00922       THICKEN_FS_BUTTONS (editedit);
00923       POPUP_FILE_SELECTION_WIDGET (editedit, cbs);
00924       break;
00925     }
00926 
00927   XmStringFree (filter_string);
00928   XmStringFree (xm_string);
00929 
00930 
00931 }
00932 
00933 static void
00934 reallyQuit (Widget dialog, XtPointer x, XtPointer y)
00935 {
00936   closeMainWindow (dialog, x, y);
00937 }
00938 
00939 static void
00940 canc (Widget dialog, XtPointer cd, XtPointer cb)
00941 {
00942   switch ((int) cd)
00943     {
00944     case FM_QUIT:
00945       (void) XtDestroyWidget (quitmenu);
00946       quitmenu = NULL;
00947       break;
00948     case FM_OPEN:
00949       (void) XtDestroyWidget (openfile);
00950       openfile = NULL;
00951       break;
00952     case FM_SAVE_AS:
00953       (void) XtDestroyWidget (savefile);
00954       savefile = NULL;
00955       break;
00956     case ED_EDIT:
00957       (void) XtDestroyWidget (editedit);
00958       editedit = NULL;
00959       break;
00960     case HM_ABOUT:
00961       (void) XtDestroyWidget (abouthelp);
00962       abouthelp = NULL;
00963       break;
00964     }
00965 }
00966 static void
00967 fileOk (Widget dialog, XtPointer cd, XtPointer cb)
00968 {
00969   char *mySelection = NULL;
00970 
00971 // DO work here.
00972   switch ((int) cd)
00973     {
00974     case FM_OPEN:
00975       mySelection =
00976         XmTextGetString (XmFileSelectionBoxGetChild
00977                          (openfile, XmDIALOG_TEXT));
00978 #ifdef DEBUG
00979       cout << "Openning " << mySelection << endl;
00980 #endif
00981       (void) XtDestroyWidget (openfile);
00982       openfile = NULL;
00983       break;
00984     case FM_SAVE_AS:
00985       mySelection =
00986         XmTextGetString (XmFileSelectionBoxGetChild
00987                          (savefile, XmDIALOG_TEXT));
00988 #ifdef DEBUG
00989       cout << "Saving as" << mySelection << endl;
00990 #endif
00991       (void) XtDestroyWidget (savefile);
00992       savefile = NULL;
00993       break;
00994     case ED_EDIT:
00995       mySelection =
00996         XmTextGetString (XmFileSelectionBoxGetChild
00997                          (editedit, XmDIALOG_TEXT));
00998 #ifdef DEBUG
00999       cout << "Editing" << mySelection << endl;
01000 #endif
01001       (void) XtDestroyWidget (editedit);
01002       editedit = NULL;
01003       break;
01004     default:
01005       break;
01006     }
01007 
01008   if (mySelection)
01009     XtFree (mySelection);
01010 
01011 }
01012 
01013 
01014 static void
01015 aboutPopup (Widget push_button, XtPointer text, XtPointer cbs)
01016 {
01017   XmString xm_string;
01018   XmString about_string;
01019   Arg args[3];
01020 
01021   xm_string = XmStringCreateLtoR ((char *) text, XmFONTLIST_DEFAULT_TAG);
01022   XtSetArg (args[0], XmNmessageString, xm_string);
01023   about_string =
01024     XmStringCreateLtoR ((char *) ABOUT_OK, XmFONTLIST_DEFAULT_TAG);
01025   XtSetArg (args[1], XmNokLabelString, about_string);
01026   XtSetArg (args[2], XmNtitle, ABOUT_TITLE);
01027 
01028   abouthelp = XmCreateInformationDialog (push_button, "about", args, 3);
01029   XmStringFree (xm_string);
01030   XmStringFree (about_string);
01031 
01032   XtUnmanageChild (XmMessageBoxGetChild (abouthelp, XmDIALOG_CANCEL_BUTTON));
01033   XtUnmanageChild (XmMessageBoxGetChild (abouthelp, XmDIALOG_HELP_BUTTON));
01034 
01035   XtVaSetValues (XmMessageBoxGetChild (abouthelp, XmDIALOG_OK_BUTTON),
01036                  XmNshadowThickness, 4, NULL);
01037 
01038   XtAddCallback (abouthelp, (String) XmNokCallback, (XtCallbackProc) canc,
01039                  (XtPointer) cbs);
01040   XtManageChild (abouthelp);
01041 
01042   XtPopup (XtParent (abouthelp), XtGrabExclusive);
01043 }
01044 
01045 void
01046 updateAxes (void)
01047 {
01048   int i = 0;
01049   for (i = 1; i < EMC_NUM_AXES; i++)
01050     {
01051       axisPos[i] = getAxisValue (i);
01052       if (axisWidget[i])        // Just being cautious
01053         LABEL_AXIS_UPDATE (axisWidget[i], axisStr[i], axisPos[i]);
01054     }
01055 }
01056 void
01057 showRunMode (void)
01058 {
01059   if (isMachineOn && runModeForm)
01060     {
01061       XtVaSetValues (runModeForm, XmNmappedWhenManaged, True, NULL);
01062       switch (runMode)
01063         {
01064         case MANUAL_MODE:
01065           SHOW_MANUAL ();
01066           break;
01067         case AUTO_MODE:
01068           SHOW_AUTO ();
01069           break;
01070         case MDI_MODE:
01071           SHOW_MDI ();
01072           break;
01073         }
01074     }
01075   else
01076     hideRunMode ();             // Just to be sure
01077 }
01078 
01079 void
01080 hideRunMode (void)
01081 {
01082   if (axisForm)
01083     {
01084       XtVaSetValues (runModeForm, XmNmappedWhenManaged, False, NULL);
01085       XtVaSetValues (scrolledText, XmNmappedWhenManaged, False, NULL);
01086     }
01087 }
01088 
01089 static void
01090 createAxes (void)
01091 {
01092   if (axisForm != NULL)         // only build one set
01093     return;
01094 
01095   axisForm =
01096     XtVaCreateManagedWidget ("axisForm", xmFormWidgetClass, workArea,
01097                              XmNtopAttachment, XmATTACH_FORM,
01098                              XmNtopOffset, 5,
01099                              XmNbottomAttachment, XmATTACH_NONE,
01100                              XmNleftAttachment, XmATTACH_FORM,
01101                              XmNleftOffset, 5,
01102                              XmNrightAttachment, XmATTACH_NONE,
01103                              XmNmarginWidth, 5,
01104                              XmNmarginWidth, 5, XmNmarginHeight, 5, NULL);
01105   int i = 0;
01106 
01107   LABEL_AXIS (axisWidget[i], axisStr[i], axisPos[i], XmATTACH_FORM, NULL);
01108 
01109 
01110   for (i = 1; i < EMC_NUM_AXES; i++)
01111     {
01112       AXIS_SEPARATOR ();
01113       LABEL_AXIS (axisWidget[i], axisStr[i], axisPos[i], XmATTACH_WIDGET,
01114                   axisWidget[i - 1]);
01115     }
01116 
01117   AXIS_SEPARATOR ();
01118 }
01119 
01120 static void
01121 createPosition (void)
01122 {
01123   posForm =
01124     XtVaCreateManagedWidget ("form", xmFormWidgetClass, workArea,
01125                              XmNtopAttachment, XmATTACH_FORM,
01126                              XmNleftAttachment, XmATTACH_WIDGET,
01127                              XmNleftWidget, axisForm, XmNtopOffset, 5,
01128                              XmNbottomAttachment, XmATTACH_NONE,
01129                              XmNrightAttachment, XmATTACH_NONE,
01130                              XmNleftOffset, 5, XmNtraversalOn, False, NULL);
01131 
01132   XmString valueLabel =
01133     XmStringCreateLtoR ((char *) POSITION_STR, XmSTRING_DEFAULT_CHARSET);
01134 
01135   posLabel =
01136     XtVaCreateManagedWidget ("label", xmLabelWidgetClass, posForm,
01137                              XmNtopAttachment, XmATTACH_FORM,
01138                              XmNtopOffset, 25,
01139                              XmNbottomAttachment, XmATTACH_NONE,
01140                              XmNrightAttachment, XmATTACH_NONE,
01141                              XmNleftAttachment, XmATTACH_FORM,
01142                              XmNleftOffset, 50,
01143                              XmNlabelString, valueLabel, NULL);
01144   XmStringFree (valueLabel);
01145 
01146   Arg args[12];                 // Caution: increment to maximum value of "i" expected
01147   int i;
01148 
01149   i = 0;
01150   XtSetArg (args[i], XmNshadowThickness, 4);
01151   i++;
01152   pulldown = XmCreatePulldownMenu (posForm, "pulldown", args, i);
01153 
01154   actual = XtVaCreateManagedWidget (ACTUAL_STR,
01155                                     xmPushButtonWidgetClass, pulldown,
01156                                     XmNmarginWidth, 12,
01157                                     XmNmarginHeight, 12,
01158                                     XmNshadowThickness, 4, NULL);
01159 
01160 
01161   commanded = XtVaCreateManagedWidget (COMMANDED_STR,
01162                                        xmPushButtonWidgetClass, pulldown,
01163                                        XmNmarginWidth, 12,
01164                                        XmNmarginHeight, 12,
01165                                        XmNshadowThickness, 4, NULL);
01166 
01167 
01168   i = 0;
01169   XtSetArg (args[i], XmNleftAttachment, XmATTACH_FORM);
01170   i++;
01171   XtSetArg (args[i], XmNleftOffset, 25);
01172   i++;
01173   XtSetArg (args[i], XmNtopAttachment, XmATTACH_WIDGET);
01174   i++;
01175   XtSetArg (args[i], XmNtopWidget, posLabel);
01176   i++;
01177   XtSetArg (args[i], XmNtopOffset, 5);
01178   i++;
01179   XtSetArg (args[i], XmNorientation, XmVERTICAL);
01180   i++;
01181   XtSetArg (args[i], XmNsubMenuId, pulldown);
01182   i++;
01183   XtSetArg (args[i], XmNshadowThickness, 4);
01184   i++;
01185 
01186   position = XmCreateOptionMenu (posForm, POSITION_STR, args, i);
01187 
01188   XtManageChild (position);
01189 
01190   XtAddCallback (actual, XmNactivateCallback,
01191                  buttonsCB, (XtPointer) POSITION_ACTUAL);
01192 
01193   XtAddCallback (commanded, XmNactivateCallback,
01194                  buttonsCB, (XtPointer) POSITION_COMMANDED);
01195 
01196 
01197   i = 0;
01198   XtSetArg (args[i], XmNshadowThickness, 4);
01199   i++;
01200   pulldown = XmCreatePulldownMenu (posForm, "pulldown", args, i);
01201 
01202   relative = XtVaCreateManagedWidget (RELATIVE_COORD_STR,
01203                                       xmPushButtonWidgetClass, pulldown,
01204                                       XmNmarginWidth, 12,
01205                                       XmNmarginHeight, 12,
01206                                       XmNshadowThickness, 4, NULL);
01207 
01208   machine = XtVaCreateManagedWidget (MACHINE_COORD_STR,
01209                                      xmPushButtonWidgetClass, pulldown,
01210                                      XmNmarginWidth, 12,
01211                                      XmNmarginHeight, 12,
01212                                      XmNshadowThickness, 4, NULL);
01213 
01214   i = 0;
01215   XtSetArg (args[i], XmNleftAttachment, XmATTACH_FORM);
01216   i++;
01217   XtSetArg (args[i], XmNleftOffset, 25);
01218   i++;
01219   XtSetArg (args[i], XmNtopAttachment, XmATTACH_WIDGET);
01220   i++;
01221   XtSetArg (args[i], XmNtopWidget, position);
01222   i++;
01223   XtSetArg (args[i], XmNtopOffset, 5);
01224   i++;
01225   XtSetArg (args[i], XmNorientation, XmVERTICAL);
01226   i++;
01227   XtSetArg (args[i], XmNsubMenuId, pulldown);
01228   i++;
01229   XtSetArg (args[i], XmNshadowThickness, 4);
01230   i++;
01231 
01232   coordinates = XmCreateOptionMenu (posForm, "pulldown", args, i);
01233 
01234   XtManageChild (coordinates);
01235 
01236   XtAddCallback (relative, XmNactivateCallback,
01237                  buttonsCB, (XtPointer) COORD_RELATIVE);
01238 
01239   XtAddCallback (machine, XmNactivateCallback,
01240                  buttonsCB, (XtPointer) COORD_MACHINE);
01241 }
01242 
01243 static void
01244 createRunModes (void)
01245 {
01246 
01247   runModeForm =
01248     XtVaCreateManagedWidget ("form", xmFormWidgetClass, workArea,
01249                              XmNtopAttachment, XmATTACH_WIDGET,
01250                              XmNtopWidget, posForm, XmNtopOffset, 40,
01251                              XmNbottomAttachment, XmATTACH_NONE,
01252                              XmNrightAttachment, XmATTACH_NONE,
01253                              XmNleftAttachment, XmATTACH_FORM,
01254                              XmNleftOffset, 5,
01255                              XmNtraversalOn, False,
01256                              XmNmappedWhenManaged, False, NULL);
01257 
01258   XmString valueLabel =
01259     XmStringCreateLtoR ((char *) RUN_MODE_STR, XmSTRING_DEFAULT_CHARSET);
01260 
01261   Widget runLabel =
01262     XtVaCreateManagedWidget ("label", xmLabelWidgetClass, runModeForm,
01263                              XmNtopAttachment, XmATTACH_FORM,
01264                              XmNtopOffset, 25,
01265                              XmNbottomAttachment, XmATTACH_NONE,
01266                              XmNrightAttachment, XmATTACH_NONE,
01267                              XmNleftAttachment, XmATTACH_FORM,
01268                              XmNleftOffset, 5,
01269                              XmNlabelString, valueLabel, NULL);
01270   XmStringFree (valueLabel);
01271 
01272   Arg args[12];                 // Caution: increment to maximum value of "i" expected
01273   int i;
01274 
01275   i = 0;
01276   XtSetArg (args[i], XmNshadowThickness, 4);
01277   i++;
01278   pulldown = XmCreatePulldownMenu (runModeForm, "pulldown", args, i);
01279 
01280   autoMode = XtVaCreateManagedWidget (AUTO_STR,
01281                                       xmPushButtonWidgetClass, pulldown,
01282                                       XmNmarginWidth, 12,
01283                                       XmNmarginHeight, 12,
01284                                       XmNshadowThickness, 4, NULL);
01285 
01286 
01287   mdiMode = XtVaCreateManagedWidget (MDI_STR,
01288                                      xmPushButtonWidgetClass, pulldown,
01289                                      XmNmarginWidth, 12,
01290                                      XmNmarginHeight, 12,
01291                                      XmNshadowThickness, 4, NULL);
01292 
01293   manualMode = XtVaCreateManagedWidget (MANUAL_STR,
01294                                         xmPushButtonWidgetClass, pulldown,
01295                                         XmNmarginWidth, 12,
01296                                         XmNmarginHeight, 12,
01297                                         XmNshadowThickness, 4, NULL);
01298 
01299 
01300   i = 0;
01301   XtSetArg (args[i], XmNtopAttachment, XmATTACH_FORM);
01302   i++;
01303   XtSetArg (args[i], XmNleftAttachment, XmATTACH_WIDGET);
01304   i++;
01305   XtSetArg (args[i], XmNleftWidget, runLabel);
01306   i++;
01307   XtSetArg (args[i], XmNleftOffset, 5);
01308   i++;
01309   XtSetArg (args[i], XmNorientation, XmVERTICAL);
01310   i++;
01311   XtSetArg (args[i], XmNsubMenuId, pulldown);
01312   i++;
01313   XtSetArg (args[i], XmNshadowThickness, 4);
01314   i++;
01315   XtSetArg (args[i], XmNbuttonSet, 2);
01316   i++;
01317 
01318   runModes = XmCreateOptionMenu (runModeForm, "optionMenu", args, i);
01319 
01320   XtManageChild (runModes);
01321 
01322   XtAddCallback (autoMode, XmNactivateCallback,
01323                  buttonsCB, (XtPointer) AUTO_MODE);
01324 
01325   XtAddCallback (mdiMode, XmNactivateCallback,
01326                  buttonsCB, (XtPointer) MDI_MODE);
01327 
01328   XtAddCallback (manualMode, XmNactivateCallback,
01329                  buttonsCB, (XtPointer) MANUAL_MODE);
01330 
01331   valueLabel =
01332     XmStringCreateLtoR ((char *) RUN_STR, XmSTRING_DEFAULT_CHARSET);
01333 
01334   runButton =
01335     XtVaCreateManagedWidget ("button", xmPushButtonWidgetClass, runModeForm,
01336                              XmNtopAttachment, XmATTACH_FORM,
01337                              XmNtopOffset, 10,
01338                              XmNbottomAttachment, XmATTACH_NONE,
01339                              XmNrightAttachment, XmATTACH_NONE,
01340                              XmNleftAttachment, XmATTACH_WIDGET,
01341                              XmNleftWidget, runModes,
01342                              XmNleftOffset, 15,
01343                              XmNmarginWidth, 15,
01344                              XmNmarginHeight, 15,
01345                              XmNshadowThickness, 4,
01346                              XmNlabelString, valueLabel, NULL);
01347   XmStringFree (valueLabel);
01348 
01349   XtAddCallback (runButton, XmNarmCallback, buttonsCB, (XtPointer) DO_RUN);
01350 
01351   XmPushButtonWidget pb;
01352   pb = (XmPushButtonWidget) runButton;
01353   pb->pushbutton.armed = false;
01354 
01355   valueLabel =
01356     XmStringCreateLtoR ((char *) PAUSE_STR, XmSTRING_DEFAULT_CHARSET);
01357   pauseButton =
01358     XtVaCreateManagedWidget ("button", xmPushButtonWidgetClass, runModeForm,
01359                              XmNtopAttachment, XmATTACH_FORM, XmNtopOffset,
01360                              10, XmNbottomAttachment, XmATTACH_NONE,
01361                              XmNrightAttachment, XmATTACH_NONE,
01362                              XmNleftAttachment, XmATTACH_WIDGET,
01363                              XmNleftWidget, runButton, XmNleftOffset, 15,
01364                              XmNmarginWidth, 15, XmNmarginHeight, 15,
01365                              XmNshadowThickness, 4, XmNmappedWhenManaged,
01366                              False, XmNlabelString, valueLabel, NULL);
01367   XmStringFree (valueLabel);
01368 
01369   XtAddCallback (pauseButton, XmNactivateCallback,
01370                  buttonsCB, (XtPointer) PAUSE_RESUME);
01371 
01372   valueLabel =
01373     XmStringCreateLtoR ((char *) STEP_STR, XmSTRING_DEFAULT_CHARSET);
01374   stepButton =
01375     XtVaCreateManagedWidget ("button", xmPushButtonWidgetClass, runModeForm,
01376                              XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
01377                              runButton, XmNtopOffset, 10, XmNbottomAttachment,
01378                              XmATTACH_NONE, XmNrightAttachment, XmATTACH_NONE,
01379                              XmNleftAttachment, XmATTACH_WIDGET,
01380                              XmNleftWidget, runModes, XmNleftOffset, 15,
01381                              XmNmarginWidth, 15, XmNmarginHeight, 15,
01382                              XmNshadowThickness, 4, XmNmappedWhenManaged,
01383                              False, XmNlabelString, valueLabel, NULL);
01384   XmStringFree (valueLabel);
01385 
01386   XtAddCallback (stepButton, XmNactivateCallback,
01387                  buttonsCB, (XtPointer) STEP);
01388 
01389   valueLabel =
01390     XmStringCreateLtoR ((char *) LIMIT_OVERRIDE_STR,
01391                         XmSTRING_DEFAULT_CHARSET);
01392   limitOverride =
01393     XtVaCreateManagedWidget ("button", xmPushButtonWidgetClass, runModeForm,
01394                              XmNtopAttachment, XmATTACH_FORM, XmNtopOffset,
01395                              10, XmNbottomAttachment, XmATTACH_NONE,
01396                              XmNrightAttachment, XmATTACH_NONE,
01397                              XmNleftAttachment, XmATTACH_WIDGET,
01398                              XmNleftWidget, runModes, XmNleftOffset, 15,
01399                              XmNmarginWidth, 15, XmNmarginHeight, 15,
01400                              XmNshadowThickness, 4, XmNmappedWhenManaged,
01401                              False, XmNlabelString, valueLabel, NULL);
01402   XmStringFree (valueLabel);
01403 
01404   XtAddCallback (limitOverride, XmNactivateCallback,
01405                  buttonsCB, (XtPointer) LIMIT_OVERRIDE);
01406 
01407   valueLabel =
01408     XmStringCreateLtoR ((char *) JOG_STR, XmSTRING_DEFAULT_CHARSET);
01409   jogButton =
01410     XtVaCreateManagedWidget ("button", xmPushButtonWidgetClass, runModeForm,
01411                              XmNtopAttachment, XmATTACH_FORM, XmNtopOffset,
01412                              10, XmNbottomAttachment, XmATTACH_NONE,
01413                              XmNrightAttachment, XmATTACH_NONE,
01414                              XmNleftAttachment, XmATTACH_WIDGET,
01415                              XmNleftWidget, limitOverride, XmNleftOffset, 15,
01416                              XmNmarginWidth, 15, XmNmarginHeight, 15,
01417                              XmNshadowThickness, 4, XmNmappedWhenManaged,
01418                              False, XmNlabelString, valueLabel, NULL);
01419   XmStringFree (valueLabel);
01420 
01421   XtAddCallback (jogButton, XmNactivateCallback,
01422                  buttonsCB, (XtPointer) JOG_BUTTON);
01423 }
01424 
01425 static void
01426 createScrolledText (void)
01427 {
01428   Arg args[16];                 // Caution, make sure i doesn't exceed this size
01429   int i = 0;
01430 
01431   XtSetArg (args[i], XmNtopAttachment, XmATTACH_WIDGET);
01432   i++;
01433   XtSetArg (args[i], XmNtopWidget, runModes);
01434   i++;
01435   XtSetArg (args[i], XmNtopOffset, 10);
01436   i++;
01437   XtSetArg (args[i], XmNleftAttachment, XmATTACH_FORM);
01438   i++;
01439   XtSetArg (args[i], XmNleftOffset, 5);
01440   i++;
01441   XtSetArg (args[i], XmNrightAttachment, XmATTACH_WIDGET);
01442   i++;
01443   XtSetArg (args[i], XmNrightWidget, buttonform);
01444   i++;
01445   XtSetArg (args[i], XmNrightOffset, 5);
01446   i++;
01447   XtSetArg (args[i], XmNbottomAttachment, XmATTACH_FORM);
01448   i++;
01449   XtSetArg (args[i], XmNbottomOffset, 5);
01450   i++;
01451   XtSetArg (args[i], XmNchildType, XmFRAME_WORKAREA_CHILD);
01452   i++;
01453   XtSetArg (args[i], XmNvisibleItemCount, 6);
01454   i++;
01455 
01456   scrolledText = XmCreateScrolledList (workArea, "scrolled_text", args, i);
01457 
01458   XtManageChild (scrolledText);
01459   XtVaSetValues (scrolledText, XmNmappedWhenManaged, False, NULL);
01460 
01461 }
01462 
01463 static void
01464 restartList ()
01465 {
01466   XmListDeleteAllItems (scrolledText);  // FIXME: Demo purposes only, clean out
01467   // FIXME: Instead, select the first line again, ready to start.
01468   HIDE (scrolledText);
01469 }
01470 
01471 /*************************************************************
01472  * The following are functions so we can insert appropriate  *
01473  * actions to keep the gui in sync with the real world. Only *
01474  * use these to modify these state-information globals.      *
01475  *************************************************************/
01476 
01477 static void
01478 turnMachineOn (void)
01479 {
01480   isMachineOn = true;
01481 #ifdef DEBUG
01482   cout << "Machine On" << endl;
01483 #endif
01484 }
01485 static void
01486 turnMachineOff (void)
01487 {
01488   isMachineOn = false;
01489 #ifdef DEBUG
01490   cout << "Machine Off" << endl;
01491 #endif
01492 }
01493 
01494 static void
01495 do_estop (void)
01496 {
01497 #ifdef DEBUG
01498   cout << endl << "ESTOP PRESSED" << endl << endl;
01499 #endif
01500 }
01501 
01502 static void
01503 turnBrakeOn (void)
01504 {
01505   isBrakeOn = true;
01506 #ifdef DEBUG
01507   cout << "Brake On" << endl;
01508 #endif
01509 }
01510 static void
01511 turnBrakeOff (void)
01512 {
01513   isBrakeOn = false;
01514 #ifdef DEBUG
01515   cout << "Brake Off" << endl;
01516 #endif
01517 }
01518 
01519 static void
01520 turnFloodOn (void)
01521 {
01522   isFloodOn = true;
01523 #ifdef DEBUG
01524   cout << "Flood On" << endl;
01525 #endif
01526 }
01527 
01528 static void
01529 turnFloodOff (void)
01530 {
01531   isFloodOn = false;
01532 #ifdef DEBUG
01533   cout << "Flood Off" << endl;
01534 #endif
01535 }
01536 
01537 static void
01538 turnMistOn (void)
01539 {
01540   isMistOn = true;
01541 #ifdef DEBUG
01542   cout << "Mist On" << endl;
01543 #endif
01544 }
01545 
01546 static void
01547 turnMistOff (void)
01548 {
01549   isMistOn = false;
01550 #ifdef DEBUG
01551   cout << "Mist Off" << endl;
01552 #endif
01553 }
01554 
01555 static void
01556 setCoordRelative (void)
01557 {
01558   isCoordRelative = True;
01559 #ifdef DEBUG
01560   cout << "Coordinates Relative" << endl;
01561 #endif
01562 }
01563 static void
01564 setCoordMachine (void)
01565 {
01566   isCoordRelative = False;
01567 #ifdef DEBUG
01568   cout << "Coordinates Machine" << endl;
01569 #endif
01570 }
01571 static void
01572 setPosActual (void)
01573 {
01574   isPosActual = True;
01575 #ifdef DEBUG
01576   cout << "Position Actual" << endl;
01577 #endif
01578 }
01579 static void
01580 setPosCommanded (void)
01581 {
01582   isPosActual = False;
01583 #ifdef DEBUG
01584   cout << "Position Commanded" << endl;
01585 #endif
01586 }
01587 
01588 static void
01589 call_run (void)
01590 {
01591   isRunning = True;
01592   PRESS (runButton);
01593   LOCK (runButton);
01594   LOCK (runModes);
01595   HIDE (brakebutton);
01596   HIDE (mistbutton);
01597   HIDE (floodbutton);
01598 
01599   UNLOCK (pauseButton);
01600   SHOW (pauseButton);
01601   SHOW (abortbutton);
01602   LOCK (machinebutton);
01603 
01604   if (!isBrakeOn)
01605     {
01606       turnBrakeOn ();
01607       stopSpindle ();
01608       hideSpindle ();
01609     }
01610 
01611   XmString valueLabel =
01612     XmStringCreateLtoR ((char *) RUNNING_STR, XmSTRING_DEFAULT_CHARSET);
01613   XtVaSetValues (runButton, XmNlabelString, valueLabel, NULL);
01614   XmStringFree (valueLabel);
01615 
01616 #ifdef DEBUG
01617   cout << "Called Run" << endl;
01618 #endif
01619 }
01620 
01621 // The following would be called externally to make the run button available again.
01622 void
01623 run_finished (void)
01624 {
01625   if (!isRunning)
01626     return;
01627 
01628   isRunning = False;
01629 
01630   XmString valueLabel = NULL;
01631 
01632   if (runButton)
01633     {
01634       TOGGLE (runButton);
01635       UNLOCK (runButton);
01636     }
01637 
01638   if (runModes)
01639     UNLOCK (runModes);
01640   if (pauseButton)
01641     HIDE (pauseButton);
01642   if (stepButton)
01643     HIDE (stepButton);
01644   if (scrolledText)
01645     restartList ();
01646 
01647   valueLabel =
01648     XmStringCreateLtoR ((char *) RUN_STR, XmSTRING_DEFAULT_CHARSET);
01649   XtVaSetValues (runButton, XmNlabelString, valueLabel, NULL);
01650   XmStringFree (valueLabel);
01651 
01652   SHOW_AUTO ();
01653 
01654 }
01655 
01656 static void
01657 call_pause (void)
01658 {
01659   XmString valueLabel =
01660     XmStringCreateLtoR ((char *) RESUME_STR, XmSTRING_DEFAULT_CHARSET);
01661   XtVaSetValues (pauseButton, XmNlabelString, valueLabel, NULL);
01662   XmStringFree (valueLabel);
01663   valueLabel =
01664     XmStringCreateLtoR ((char *) PAUSED_STR, XmSTRING_DEFAULT_CHARSET);
01665   XtVaSetValues (runButton, XmNlabelString, valueLabel, NULL);
01666   XmStringFree (valueLabel);
01667   isPaused = True;
01668   UNLOCK (stepButton);
01669   SHOW (stepButton);
01670 
01671 #ifdef DEBUG
01672   cout << "We are paused" << endl;
01673 #endif
01674 }
01675 
01676 static void
01677 call_resume (void)
01678 {
01679   if ((!isPaused) || (!pauseButton))
01680     return;
01681   XmString valueLabel =
01682     XmStringCreateLtoR ((char *) PAUSE_STR, XmSTRING_DEFAULT_CHARSET);
01683   XtVaSetValues (pauseButton, XmNlabelString, valueLabel, NULL);
01684   XmStringFree (valueLabel);
01685 
01686   if (isRunning)
01687     valueLabel =
01688       XmStringCreateLtoR ((char *) RUNNING_STR, XmSTRING_DEFAULT_CHARSET);
01689   else
01690     valueLabel =
01691       XmStringCreateLtoR ((char *) RUN_STR, XmSTRING_DEFAULT_CHARSET);
01692 
01693   XtVaSetValues (runButton, XmNlabelString, valueLabel, NULL);
01694   XmStringFree (valueLabel);
01695   isPaused = False;
01696   HIDE (stepButton);
01697 #ifdef DEBUG
01698   cout << "We are resumed" << endl;
01699 #endif
01700 }
01701 
01702 static void
01703 call_step (void)
01704 {
01705 #ifdef DEBUG
01706   cout << "Step" << endl;
01707 #endif
01708 
01709   // For fun put stuff into msg area:
01710   XmString valueLabel =
01711     XmStringCreateLtoR ("G100 -- Move", XmSTRING_DEFAULT_CHARSET);
01712   XmListAddItemUnselected (scrolledText, valueLabel, 0);
01713   XmListSetBottomItem (scrolledText, valueLabel);
01714   XmStringFree (valueLabel);
01715 
01716 }
01717 
01718 static void
01719 setLimitOverride (void)
01720 {
01721   PRESS (limitOverride);
01722   LOCK (limitOverride);
01723   isLimitOverriden = True;
01724 #ifdef DEBUG
01725   cout << "Set limit override" << endl;
01726 #endif
01727 }
01728 
01729 static void
01730 unsetLimitOverride (void)
01731 {
01732   if (!isLimitOverriden)
01733     return;
01734   UNPRESS (limitOverride);
01735   UNLOCK (limitOverride);
01736   isLimitOverriden = False;
01737 #ifdef DEBUG
01738   cout << "Unset limit override" << endl;
01739 #endif
01740 }
01741 
01742 static void
01743 showJogPopup (void)
01744 {
01745 #ifdef DEBUG
01746   cout << "Will popup Jog dialog or push to front if already up" << endl;
01747 #endif
01748 }
01749 static void
01750 setModeAuto (void)
01751 {
01752   runMode = AUTO_MODE;
01753   HIDE_MANUAL ();
01754   HIDE_MDI ();
01755   SHOW_AUTO ();
01756 #ifdef DEBUG
01757   cout << "Mode is Auto" << endl;
01758 #endif
01759 }
01760 
01761 static void
01762 setModeMDI (void)
01763 {
01764   runMode = MDI_MODE;
01765   HIDE_MANUAL ();
01766 
01767   XtVaSetValues (scrolledText, XmNmappedWhenManaged, True, NULL);
01768   XtVaSetValues (runModes, XmNmenuHistory, mdiMode, NULL);
01769 #ifdef DEBUG
01770   cout << "Mode is MDI" << endl;
01771 #endif
01772 }
01773 
01774 static void
01775 setModeManual (void)
01776 {
01777   runMode = MANUAL_MODE;
01778   SHOW_MANUAL ();
01779 #ifdef DEBUG
01780   cout << "Mode is Manual" << endl;
01781 #endif
01782 }
01783 
01784 static void
01785 do_home (void)
01786 {
01787   XtVaSetValues (jog_widget, XmNmappedWhenManaged, True, NULL);
01788 #ifdef DEBUG
01789   cout << "Do Home" << endl;
01790 #endif
01791 }
01792 
01793 static void
01794 processAbort (void)
01795 {
01796   // TODO: put whatever is needed to be done on emc side to clean up
01797 #ifdef DEBUG
01798   cout << "Process aborted" << endl;
01799 #endif
01800 }
01801 
01802 double
01803 getAxisValue (int i)
01804 {
01805   int value = 0;
01806 
01807   // TODO: Call emc interface to obtain current value for i-th axis
01808 
01809   return value;
01810 }
01811 
01812 #ifdef NEED_GET_XM_TEXT
01813 /* Utility to get text from an XmString. May not be needed, but handy */
01814 static char *
01815 getXmText (XmString aXmString)
01816 {
01817   char *text;                   /* Caller must Free ! */
01818   XmStringContext context;
01819   XmStringCharSet charset;
01820   XmStringDirection direction;
01821   Boolean separator;
01822 
01823   if (!XmStringInitContext (&context, aXmString))
01824     {
01825       if (context)
01826         XmStringFreeContext (context);
01827       return NULL;
01828     }
01829   while (XmStringGetNextSegment
01830          (context, &text, &charset, &direction, &separator))
01831     {
01832       if (text != NULL)
01833         break;                  /* Find first non-nil string */
01834     }
01835 
01836   if (context)
01837     XmStringFreeContext (context);
01838   if (charset)
01839     XtFree (charset);
01840 
01841   return text;
01842 }
01843 #endif

Generated on Sun Dec 2 15:27:45 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001