00001 #ifndef __SPINDLE__H__
00002 #define __SPINDLE__H__
00003
00004 #include <unistd.h>
00005
00006 #include <Xm/Xm.h>
00007 #include <Xm/Frame.h>
00008 #include <Xm/Form.h>
00009 #include <Xm/PushB.h>
00010 #include <Xm/PushBP.h>
00011 #include <Xm/Separator.h>
00012 #include <X11/xpm.h>
00013
00014 #include <stdio.h>
00015
00016 #ifdef DEBUG
00017 #include <iostream.h>
00018 #endif
00019
00020 #ifndef INITIAL_SPINDLE_SPEED
00021 #define INITIAL_SPINDLE_SPEED (3000.00)
00022 #endif
00023
00024 #ifdef SPINDLE
00025 #include "GuiStrings.hh"
00026 #include "r_arrow.xpm"
00027 #include "r_arrow_in.xpm"
00028 #include "l_arrow.xpm"
00029 #include "l_arrow_in.xpm"
00030 #include "right_arrows.xpm"
00031 #include "right_arrows_in.xpm"
00032 #include "left_arrows.xpm"
00033 #include "left_arrows_in.xpm"
00034
00035
00036
00037 #ifndef FAST_CHANGE
00038 #define FAST_CHANGE (10.00)
00039 #endif
00040
00041 #ifndef SLOW_CHANGE
00042 #define SLOW_CHANGE (.01)
00043 #endif
00044
00045 static double theSpeed = INITIAL_SPINDLE_SPEED;
00046
00047 static Widget arrowFrame = NULL;
00048 static Widget arrowForm = NULL;
00049 static Widget arrowB1 = { NULL };
00050 static Widget arrowB2 = { NULL };
00051 static Widget label = { NULL };
00052 static Widget arrowB3 = { NULL };
00053 static Widget arrowB4 = { NULL };
00054 static Widget spindleButton = NULL;
00055 static Widget separator = NULL;
00056 static Widget forwardButton = NULL;
00057 static Widget reverseButton = NULL;
00058
00059 static bool wasForward = true;
00060 static bool isSpindleOn = false;
00061
00062 static Pixmap r_pixmap;
00063 static Pixmap r_pixmap_in;
00064 static Pixmap l_pixmap;
00065 static Pixmap l_pixmap_in;
00066
00067 static Pixmap rr_pixmap;
00068 static Pixmap rr_pixmap_in;
00069 static Pixmap ll_pixmap;
00070 static Pixmap ll_pixmap_in;
00071
00072 static Pixel original_tsc;
00073 static Pixel original_bsc;
00074 static Pixel original_ac;
00075 static Pixel original_bg;
00076
00077 static void buttonCB (Widget mw, XtPointer cd, XtPointer cb);
00078 static void unbuttonCB (Widget mw, XtPointer cd, XtPointer cb);
00079 static void change_spindle (int type);
00080 static void stop_changing_spindle (int type);
00081 static double get_speed (void);
00082 static void checkSpindleReversal (void);
00083 static void turnSpindleOn (void);
00084 static void turnSpindleOff (void);
00085
00086 enum
00087 {
00088 ARROW_LEFT_FAST,
00089 ARROW_LEFT,
00090 ARROW_RIGHT,
00091 ARROW_RIGHT_FAST,
00092 SPINDLE_FORWARD,
00093 SPINDLE_REVERSE,
00094 SPINDLE_ON_OFF,
00095 };
00096
00097
00098
00099 #define CREATE_PIXMAP(xpm_name, pixmap_name) \
00100 do { \
00101 XpmCreatePixmapFromData (XtDisplay (arrowFrame), \
00102 DefaultRootWindow (XtDisplay (arrowFrame)), \
00103 xpm_name, &pixmap_name, 0, 0); \
00104 } while (0)
00105
00106 #define SPINDLE_AXIS(arrow_widget, left_attach_type, left_attach_widget, \
00107 left_offset, arrow_pixmap, arrow_type) \
00108 do { \
00109 arrow_widget = \
00110 XtVaCreateManagedWidget ("arrowB", xmPushButtonWidgetClass, arrowForm, \
00111 XmNtopAttachment, XmATTACH_WIDGET, \
00112 XmNtopWidget, separator, XmNtopOffset, 5, \
00113 XmNbottomAttachment, XmATTACH_NONE, \
00114 XmNleftAttachment, left_attach_type, \
00115 XmNleftWidget, left_attach_widget, \
00116 XmNleftOffset, left_offset, \
00117 XmNrightAttachment, XmATTACH_NONE, \
00118 XmNwidth, 50, XmNheight, 50, \
00119 XmNlabelPixmap, arrow_pixmap, XmNlabelType, \
00120 XmPIXMAP, XmNmarginWidth, 0, XmNmarginHeight, \
00121 0, XmNshadowThickness, 0, NULL); \
00122 XtAddCallback (arrow_widget, XmNarmCallback, buttonCB, \
00123 (XtPointer) arrow_type); \
00124 XtAddCallback (arrow_widget, XmNdisarmCallback, unbuttonCB, \
00125 (XtPointer) arrow_type); \
00126 } while (0)
00127
00128 #define LABEL_SPEED(speed) \
00129 do { \
00130 XmStringCharSet cs = (char *) XmSTRING_DEFAULT_CHARSET; \
00131 XFontStruct *newfont = NULL; \
00132 XmFontList fontlist = NULL; \
00133 if ((newfont = XLoadQueryFont (XtDisplay (arrowFrame), \
00134 "-adobe-courier-bold-r-normal--48-*-*-*-*-*-*-1")) \
00135 == NULL) \
00136 { \
00137 newfont = XLoadQueryFont (XtDisplay (arrowFrame), "fixed"); \
00138 } \
00139 fontlist = XmFontListCreate (newfont, cs); \
00140 char speedChar[12]; \
00141 sprintf (speedChar, "%7.2f", speed); \
00142 XmString speedLabel = \
00143 XmStringCreateLtoR ((char *) speedChar, XmSTRING_DEFAULT_CHARSET); \
00144 label = \
00145 XtVaCreateManagedWidget ("label", xmLabelWidgetClass, arrowForm, \
00146 XmNtopAttachment, XmATTACH_WIDGET, \
00147 XmNtopWidget, separator, XmNtopOffset, 5, \
00148 XmNbottomAttachment, XmATTACH_NONE, \
00149 XmNrightAttachment, XmATTACH_WIDGET, \
00150 XmNrightWidget, arrowB3, \
00151 XmNleftAttachment, XmATTACH_NONE, \
00152 XmNwidth, 225, \
00153 XmNheight, 50, \
00154 XmNfontList, fontlist, \
00155 XmNlabelString, speedLabel, NULL); \
00156 XmFontListFree (fontlist); \
00157 XUnloadFont (XtDisplay (arrowFrame), newfont->fid); \
00158 \
00159 XmStringFree (speedLabel); \
00160 } while (0)
00161
00162 #define LABEL_SPEED_UPDATE(speed) \
00163 do { \
00164 char speedChar[12]; \
00165 if (label) \
00166 { \
00167 sprintf (speedChar, "%7.2f", speed); \
00168 XmString speedLabel = \
00169 XmStringCreateLtoR ((char *) speedChar, XmSTRING_DEFAULT_CHARSET); \
00170 XtVaSetValues (label, \
00171 XmNlabelString, speedLabel, NULL); \
00172 XmStringFree (speedLabel); \
00173 } \
00174 } while (0)
00175
00176 #define SEPARATOR() \
00177 do { \
00178 separator = \
00179 XtVaCreateManagedWidget ("separator", xmSeparatorWidgetClass, arrowForm, \
00180 XmNtopAttachment, XmATTACH_WIDGET, \
00181 XmNtopWidget, forwardButton, \
00182 XmNtopOffset, 5, \
00183 XmNbottomAttachment, XmATTACH_NONE, \
00184 XmNleftAttachment, XmATTACH_FORM, \
00185 XmNrightAttachment, XmATTACH_FORM, \
00186 XmNmarginWidth, 5, XmNmarginHeight, 5, NULL); \
00187 } while (0)
00188
00189 #define LOCK(button) \
00190 do \
00191 { \
00192 XtVaSetValues(button, XmNsensitive, False, NULL); \
00193 } while (0)
00194
00195 #define UNLOCK(button) \
00196 do \
00197 { \
00198 XtVaSetValues(button, XmNsensitive, True, NULL); \
00199 } while (0)
00200
00201
00202 #define TOGGLE(button) \
00203 do \
00204 { \
00205 Pixel tsc; \
00206 Pixel bsc; \
00207 Pixel ac; \
00208 Pixel bg; \
00209 XmPushButtonWidget pb; \
00210 XtVaGetValues(button, XmNtopShadowColor, &tsc, \
00211 XmNbottomShadowColor, &bsc, \
00212 XmNarmColor, &ac, \
00213 XmNbackground, &bg, \
00214 NULL); \
00215 XtVaSetValues(button, XmNtopShadowColor, bsc, \
00216 XmNbottomShadowColor, tsc, \
00217 XmNarmColor, bg, \
00218 XmNbackground, ac, \
00219 NULL); \
00220 pb = (XmPushButtonWidget) button ; \
00221 pb->pushbutton.armed = false; \
00222 } while (0)
00223
00224 #define UNPRESS(button) \
00225 do \
00226 { \
00227 XtVaSetValues(button, XmNbottomShadowColor, original_bsc, \
00228 XmNtopShadowColor, original_tsc, \
00229 XmNarmColor, original_ac, \
00230 XmNbackground, original_bg, \
00231 NULL); \
00232 } while (0)
00233
00234 #define PRESS(button) \
00235 do \
00236 { \
00237 UNPRESS(button); \
00238 TOGGLE(button); \
00239 } while (0)
00240
00241 #endif // SPINDLE
00242
00243
00244
00245 extern void updateSpindleSpeed ();
00246
00247 extern void setSpindleSpeed (double);
00248
00249 extern void showSpindle (void);
00250
00251 extern void hideSpindle (void);
00252
00253 extern void changeDirection (void);
00254
00255 extern void stopSpindle (void);
00256
00257 extern Widget
00258 SpindleControl (Dimension x0, Dimension x1, Dimension y1, Dimension y2,
00259 Dimension boxMarginWidth, Dimension boxMarginHeight,
00260 Widget parent);
00261
00262 #endif // __SPINDLE__H__