DAS  3.1.6 - 18/09/2017
ViTES_1.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <malloc.h>
6 #include <math.h>
7 #include <io.h>
8 #include "mgui.h"
9 #include "DAS_Spatram.h"
10 #include "vites_1.h"
11 
12 
19 #define IsEven(a) (!((a)&1))
22 struct vites VITES;
24 
25 
26 
27 const char *hvitesa[] = {{"Autoranging for optimal exposure time"}, //0
28  {"Averaged measurements"}, //1 - O:
29  {"Re-start the execution of the PRG file"}, //2
30  {"Auto calibration with HG Lamp (hg line at 4358A on pix 512)"}, //3
31  {"Performs a DARK Measurement (shutter closed)"}, //4
32  {"Set the exposure time"}, //5 T: S_GEOM
33  {"Set the filter position (0 - 6)"}, //6 T: S_GEOM
34  {"Performs a LIGHT Measurement (shutter opened)"}, //7 T: S_GEOM
35  {"Home for Filter Wheel"}, //8 T: S_GEOM
36  {"Home for Grating"}, //9
37  {"Home for Input Mirror"}, //10
38  {"HG lamp OFF"}, //11
39  {"HG lamp ON"}, //12
40  {"Text after this command is displayed in the Status label"}, //13
41  {"Performs a measurement setting Mirror, Grating, Filter, TExp, Saving mode..."}, //14
42  {"Set Input Mirror position "}, //15
43  {"Display Plot"}, //16
44  {"QJ lamp OFF"}, //17
45  {"QJ lamp ON"}, //18
46  {"NOT Used"}, //19
47  {"Text after this command is a comment"}, //20
48  {"Save the measurement in the predefined file"}, //21
49  {"Stop the program execution for xx millisec"}, //22
50  {"Set the Grating position"}, //23
51  {"Stop the execution of the PRG File"}}; //24
52 
53 /*
54  * Shell creation prototypes
55  */
57 
58 /*
59  * Project Defined Callbacks
60  */
61 void VIKeyCom_CB(MOBJECT p, void *od, void *ad);
62 void MLCursorPositionCB (MOBJECT edit, EDIT_CURS *ec, void *lbl);
63 void MLNewValueCB (MOBJECT edit, char *new_value, void *label);
64 
65 /*****************************************************
66  * This Callback is called by the EDIT
67  * when its cursor position changes.
68  *****************************************************/
69 void
71 {
72  char str[128];
73 
74  sprintf (str, "Pos: %4d X: %3d Y: %3d", ec->pos, ec->pos_x, ec->pos_y);
75  MObjectSetText ((MOBJECT) lbl, str);
76  edc.pos = ec->pos;
77  edc.pos_x = ec->pos_x;
78  edc.pos_y = ec->pos_y;
79 }
80 
81 /*****************************************************
82  * This Callback is called by the EDIT when its
83  * text value has changed.
84  *****************************************************/
85 void
86 MLNewValueCB (MOBJECT edit, char *new_value, void *label)
87 {
88 /*
89  * The EDIT Text has been modified!
90  */
91  if (MObjectGetUserData (edit) == NULL)
92  // MObjectSetText ((MOBJECT) label, "Modified");
93  MObjectSetUserData (edit, (void *) True);
94 }
95 
96 void SelKeywCB(MOBJECT edit, EDIT_CURS *pedc, void *ad)
97 {
98  int d = (int) ad;
99  int er = 0, ls = 0;
100  char buff[128];
101 
102  switch(d)
103  {
104  //AutoRange
105  case 0:
106  sprintf(buff,"%s\n", "AUTORNG");
107  ls = strlen(buff);
108  MSelectObject(edit);
109  MEditChangeText(edit, pedc->pos, ls, buff, ls);
110  pedc->pos += ls;
111  MLCursorPositionCB (edit, pedc, lbl_cur);
112  break;
113  //AVGCCD
114  case 1:
115  break;
116  //Begin
117  case 2 :
118  sprintf(buff,"%s\n", "BEGIN");
119  ls = strlen(buff);
120  MSelectObject(edit);
121  MEditChangeText(edit, pedc->pos, ls, buff, ls);
122  pedc->pos += ls;
123  MLCursorPositionCB (edit, pedc, lbl_cur);
124 
125  break;
126 
127  //CALIBRA
128  case 3 :
129  sprintf(buff,"%s\n", "CALIBRA");
130  ls = strlen(buff);
131  MSelectObject(edit);
132  MEditChangeText(edit, pedc->pos, ls, buff, ls);
133  pedc->pos += ls;
134  MLCursorPositionCB (edit, pedc, lbl_cur);
135  break;
136  //DARKC
137  case 4 :
138  break;
139  //EXPO
140  case 5 :
141  break;
142  //FILTER
143  case 6 :
144  break;
145  //GETCCD
146  case 7 :
147  break;
148  //H_FILTER
149  case 8 :
150  sprintf(buff,"%s\n", "H_FILTER");
151  ls = strlen(buff);
152  MSelectObject(edit);
153  MEditChangeText(edit, pedc->pos, ls, buff, ls);
154  pedc->pos += ls;
155  MLCursorPositionCB (edit, pedc, lbl_cur);
156  break;
157  //H_GRAT
158  case 9 :
159  sprintf(buff,"%s\n", "H_GRAT");
160  ls = strlen(buff);
161  MSelectObject(edit);
162  MEditChangeText(edit, pedc->pos, ls, buff, ls);
163  pedc->pos += ls;
164  MLCursorPositionCB (edit, pedc, lbl_cur);
165  break;
166 
167  //H_MIRROR
168  case 10 :
169  sprintf(buff,"%s\n", "H_MIRROR");
170  ls = strlen(buff);
171  MSelectObject(edit);
172  MEditChangeText(edit, pedc->pos, ls, buff, ls);
173  pedc->pos += ls;
174  MLCursorPositionCB (edit, pedc, lbl_cur);
175  break;
176  //HG_OFF
177  case 11 :
178  sprintf(buff,"%s\n", "HG_OFF");
179  ls = strlen(buff);
180  MSelectObject(edit);
181  MEditChangeText(edit, pedc->pos, ls, buff, ls);
182  pedc->pos += ls;
183  MLCursorPositionCB (edit, pedc, lbl_cur);
184  break;
185  //HG_ON
186  case 12 :
187  sprintf(buff,"%s\n", "HG_ON");
188  ls = strlen(buff);
189  MSelectObject(edit);
190  MEditChangeText(edit, pedc->pos, ls, buff, ls);
191  pedc->pos += ls;
192  MLCursorPositionCB (edit, pedc, lbl_cur);
193  break;
194  //LABEL
195  case 13 :
196  sprintf(buff,"%s\n", "LABEL");
197  ls = strlen(buff);
198  MSelectObject(edit);
199  MEditChangeText(edit, pedc->pos, ls, buff, ls);
200  pedc->pos += ls;
201  MLCursorPositionCB (edit, pedc, lbl_cur);
202  break;
203  //MEASURE
204  case 14 :
205  break;
206  //MIRROR
207  case 15 :
208  break;
209  //PLOT
210  case 16 :
211  sprintf(buff,"%s\n", "PLOT");
212  ls = strlen(buff);
213  MSelectObject(edit);
214  MEditChangeText(edit, pedc->pos, ls, buff, ls);
215  pedc->pos += ls;
216  MLCursorPositionCB (edit, pedc, lbl_cur);
217  break;
218  //QJ_OFF
219  case 17 :
220  sprintf(buff,"%s\n", "QJ_OFF");
221  ls = strlen(buff);
222  MSelectObject(edit);
223  MEditChangeText(edit, pedc->pos, ls, buff, ls);
224  pedc->pos += ls;
225  MLCursorPositionCB (edit, pedc, lbl_cur);
226  break;
227  //QJ_ON
228  case 18 :
229  sprintf(buff,"%s\n", "QJ_ON");
230  ls = strlen(buff);
231  MSelectObject(edit);
232  MEditChangeText(edit, pedc->pos, ls, buff, ls);
233  pedc->pos += ls;
234  MLCursorPositionCB (edit, pedc, lbl_cur);
235  break;
236  //RADIO
237  case 19 :
238  break;
239  //REM
240  case 20 :
241  sprintf(buff,"%s\n", "REM");
242  ls = strlen(buff);
243  MSelectObject(edit);
244  MEditChangeText(edit, pedc->pos, ls, buff, ls);
245  pedc->pos += ls;
246  MLCursorPositionCB (edit, pedc, lbl_cur);
247  break;
248  //SAVE
249  case 21 :
250  sprintf(buff,"%s\n", "SAVE");
251  ls = strlen(buff);
252  MSelectObject(edit);
253  MEditChangeText(edit, pedc->pos, ls, buff, ls);
254  pedc->pos += ls;
255  MLCursorPositionCB (edit, pedc, lbl_cur);
256  break;
257  //WAIT
258  case 22 :
259  break;
260  //WAVELEN
261  case 23 :
262  break;
263  //XEND
264  case 24 :
265  sprintf(buff,"%s\n", "XEND");
266  ls = strlen(buff);
267  MSelectObject(edit);
268  MEditChangeText(edit, pedc->pos, ls, buff, ls);
269  pedc->pos += ls;
270  MLCursorPositionCB (edit, pedc, lbl_cur);
271  break;
272 
273  }
274 
275 
276 
277 
278 }
279 void VIKeyCom_CB(MOBJECT p, void *od, void *ad)
280 {
281  int c = (int) ad;
282  int er = 0, ls = 0;
283 // char buff[128];
284 
285  SelKeywCB(VITES.edit, &edc, (void *)c);
286 
287 }
288 
289 
290 
291 /*
292  * Shell creation functions
293  */
294 
296 {
297  MOBJECT _colform000;
298  MOBJECT _rowform000;
299 // MOBJECT _label000;
300  MOBJECT _tablefrm000;
301 // MOBJECT _label001;
302 // MOBJECT _sedit000;
303  MOBJECT _rowform001;
304  MOBJECT _rowform002;
305  MOBJECT _tablefrm001;
306  MOBJECT _tablefrm002;
307  MOBJECT _label002;
308  MOBJECT _label003;
309  MOBJECT _label004;
310  MOBJECT _label005;
311  MOBJECT _label006;
312  MOBJECT _label007;
313  MOBJECT _label008;
314  MOBJECT _label009;
315  MOBJECT _label010;
316  MOBJECT _label011;
317  MOBJECT _spinedit000;
318  MOBJECT _spinedit001;
319  MOBJECT _spinedit002;
320  MOBJECT _spinedit003;
321  MOBJECT _edit000;
322  MOBJECT _spinedit004;
323  MOBJECT _spinedit005;
324  MOBJECT _spinedit006;
325  MOBJECT _pbutton012;
326  MOBJECT _tablefrm003;
327  MOBJECT _pbutton013;
328  MOBJECT _pbutton014;
329  MOBJECT _pbutton015;
330  MOBJECT lbl;
331 // MOBJECT lbl_cur;
332 
333  int i;
334 // char buff[64];
335 
336 // VITES.epos = 0;
337 // VITES.ex = 0;
338 // VITES.ey = 0;
339 
340  sh_vitesa = MCreateShell("ViTESA-Visual Table Editor for Spectrometer Activity", 0);
342 
343  _colform000 = MCreateColForm(sh_vitesa);
344 
345  _rowform000 = MCreateRowForm(_colform000);
346  MObjectAlign(_rowform000, LEFT_ALIGN, TOP_ALIGN);
347  MObjectSetResize(_rowform000, False, False);
348  MObjectSetBackgroundRGB(_rowform000, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
349 
350  lbl = MCreateLabel(_rowform000, "KeyWords", HELV_SMALL);
354 
355 
356 
357  _tablefrm000 = MCreateTableForm(_rowform000, 4);
358  MObjectSetBackgroundRGB(_tablefrm000, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
359 
360  for(i=0;i<43;i++)
361  {
362  //sprintf(buff,"%s",VITES.keyw[i]);
363  VITES.pbkw[i] = MCreatePButton(_tablefrm000, KeyCode[i], HELV_SMALL);
364  MPButtonSetCallback(VITES.pbkw[i], VIKeyCom_CB, (void *) i);
368  //MObjectSetPopupHelp(VITES.pbkw[i],hvitesa[i] , 200, 5000);
369 
370  }
371  _rowform001 = MCreateRowForm(_colform000);
372  MObjectSetBackgroundRGB(_rowform001, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
373  MObjectSetResize(_rowform001, True, True);
374 
375  lbl = MCreateLabel(_rowform001, "File: NoName.PRG", HELV_SMALL);
380 
381  lbl_cur = MCreateLabel(_rowform001, " ", HELV_SMALL);
386 
387  VITES.edit = MCreateScrolledMLEdit(_rowform001, "", 98, 10, FIXED_SMALL);
393 
394 
395 
396 
397  _rowform002 = MCreateRowForm(sh_vitesa);
398  MFormSetSpacing(_rowform002, 1);
399  MObjectAlign(_rowform002, CENTER_ALIGN, CENTER_ALIGN);
400  MObjectSetResize(_rowform002, False, False);
401  MObjectSetBackgroundRGB(_rowform002, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
403 
404  _tablefrm001 = MCreateTableForm(_rowform002, 2);
405  MFormSetSpacing(_tablefrm001, 1);
406  MObjectSetResize(_tablefrm001, False, False);
407  MObjectSetBackgroundRGB(_tablefrm001, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
409 
410  _tablefrm002 = MCreateTableForm(_tablefrm001, 9);
411  MFormSetSpacing(_tablefrm002, 1);
412  MTableFormShowGrid(_tablefrm002);
413  MObjectSetBackgroundRGB(_tablefrm002, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
415 
416 
417  _label002 = MCreateLabel(_tablefrm002, "KeyWord", HELV_SMALL);
418 
419  _label003 = MCreateLabel(_tablefrm002, "Mirror", HELV_SMALL);
420 
421  _label004 = MCreateLabel(_tablefrm002, "Grating", HELV_SMALL);
422 
423  _label005 = MCreateLabel(_tablefrm002, "Filter", HELV_SMALL);
424 
425  _label006 = MCreateLabel(_tablefrm002, "AutoRange", HELV_SMALL);
426 
427  _label007 = MCreateLabel(_tablefrm002, "Texp(sec)", HELV_SMALL);
428 
429  _label008 = MCreateLabel(_tablefrm002, "MeasType", HELV_SMALL);
430 
431  _label009 = MCreateLabel(_tablefrm002, "Save", HELV_SMALL);
432 
433  _label010 = MCreateLabel(_tablefrm002, "Plot", HELV_SMALL);
434 
435  _label011 = MCreateLabel(_tablefrm002, "MEASURE", FIXED_SMALL);
436 
437  _spinedit000 = MCreateSpinEdit(_tablefrm002, "Zenith", 7, 7, FIXED_SMALL, NULL, NULL);
438  MEditDisableEditing(_spinedit000);
439 
440  _spinedit001 = MCreateSpinEdit(_tablefrm002, "4358", 5, 5, FIXED_SMALL, NULL, NULL);
441  MEditDisableEditing(_spinedit001);
442 
443  _spinedit002 = MCreateSpinEdit(_tablefrm002, "NULL", 4, 4, FIXED_SMALL, NULL, NULL);
444  MEditDisableEditing(_spinedit002);
445 
446  _spinedit003 = MCreateSpinEdit(_tablefrm002, "Yes", 4, 4, FIXED_SMALL, NULL, NULL);
447  MEditDisableEditing(_spinedit003);
448  MEditEnableAutoControlColor(_spinedit003);
449 
450  _edit000 = MCreateEdit(_tablefrm002, "0.5", 6, FIXED_SMALL);
451  MEditSetFilter(_edit000, 772, "");
452 
453  _spinedit004 = MCreateSpinEdit(_tablefrm002, "Light", 5, 5, FIXED_SMALL, NULL, NULL);
454  MObjectSetFGColorFromParent(_spinedit004, False);
455 
456  _spinedit005 = MCreateSpinEdit(_tablefrm002, "Yes", 4, 4, FIXED_SMALL, NULL, NULL);
457  MObjectSetFGColorFromParent(_spinedit005, False);
458 
459  _spinedit006 = MCreateSpinEdit(_tablefrm002, "Yes", 4, 4, FIXED_SMALL, NULL, NULL);
460  MEditDisableEditing(_spinedit006);
461  MEditEnableAutoControlColor(_spinedit006);
462 
463  _pbutton012 = MCreatePButton(_tablefrm001, "Add Command", HELV_SMALL);
466 
467  _tablefrm003 = MCreateTableForm(_rowform002, 3);
468  MObjectSetFGColorFromParent(_tablefrm003, False);
469  MObjectSetBackgroundRGB(_tablefrm003, DPAL.DB_BG[0], DPAL.DB_BG[1], DPAL.DB_BG[2]);
471 
472  _pbutton013 = MCreatePButton(_tablefrm003, "Open...", HELV_SMALL);
475 
476  _pbutton014 = MCreatePButton(_tablefrm003, "Save as...", HELV_SMALL);
479 
480  _pbutton015 = MCreatePButton(_tablefrm003, "Close", HELV_SMALL);
483 
484 
485  return sh_vitesa;
486 }
487 
488 
489 
490 void FlushCR_EOF(FILE *f)
491 {
492  char ch;
493  int er = 0;
494 
495  while ((!er) & (ch != 10))
496  {
497  ch = fgetc(f);
498  er = feof(f);
499  }
500 
501 }
502 
503 
void MEditDisableEditing(MOBJECT edit)
void VIKeyCom_CB(MOBJECT p, void *od, void *ad)
Definition: ViTES_1.c:279
void MObjectSetBackgroundRGB(MOBJECT obj, int r, int g, int b)
MOBJECT lbl
Definition: DFileMan.c:42
short DB_FG_Plbl[3]
Foreground PASSIVE Label Colors.
void MSelectObject(MOBJECT f)
MOBJECT MCreateEdit(MOBJECT parent, const char *text, int len, MTFont font)
MOBJECT lbl_cur
Definition: ViTES_1.c:20
void SelKeywCB(MOBJECT edit, EDIT_CURS *pedc, void *ad)
Definition: ViTES_1.c:96
const char * hvitesa[]
Definition: ViTES_1.c:27
MOBJECT MCreateLabel(MOBJECT parent, const char *text, MTFont font)
void MObjectSetResize(MOBJECT obj, int resize_w, int resize_h)
Cursor Position for the Edit Object.
Definition: Mguidefs.h:1343
int pos_y
Definition: Mguidefs.h:1349
short DB_BG_Albl[3]
Background ACTIVE Label Colors.
#define False
Definition: Mguidefs.h:236
void MObjectAlign(MOBJECT obj, int h_align, int v_align)
const char * KeyCode[]
Definition: DAS_Spat.c:164
MOBJECT MCreateScrolledMLEdit(MOBJECT parent, const char *text, int width, int height, MTFont font)
void MObjectSetText(MOBJECT obj, const char *text)
void * MObjectGetUserData(MOBJECT obj)
static double ch
Definition: SOLPOS.C:120
palette DPAL
Definition: 2DPlot.c:27
MOBJECT MCreateTableForm(MOBJECT parent, int n_cols)
struct vites VITES
Definition: ViTES_1.c:22
void FlushCR_EOF(FILE *f)
Definition: ViTES_1.c:490
void MLNewValueCB(MOBJECT edit, char *new_value, void *label)
Definition: ViTES_1.c:86
MOBJECT MCreatePButton(MOBJECT parent, const char *text, MTFont font)
void MEditSetCursorPosCallback(MOBJECT edit, EDIT_CURS_CB cb, void *data)
#define CENTER_ALIGN
Definition: Mguidefs.h:917
void MObjectSetFGColorFromParent(MOBJECT obj, int true_false)
Definition: vitesdef.h:2
void MEditSetNewValueCallback(MOBJECT edit, OBJ_STRING_CB cb, void *data)
#define HELV_SMALL
Definition: Mguidefs.h:881
#define FIXED_SMALL
Definition: Mguidefs.h:878
MOBJECT pbkw[50]
Command buttons.
Definition: vitesdef.h:3
short DB_FG_Albl[3]
Foreground ACTIVE Label Colors.
MOBJECT MCreateColForm(MOBJECT parent)
MOBJECT sh_vitesa
Definition: ViTES_1.c:21
short DB_BG_Plbl[3]
Background PASSIVE Label Colors.
void MEditChangeText(MOBJECT edit, int off, int len, const char *new_t, int chg_len)
MOBJECT MDCreatesh_vitesa(void)
Definition: ViTES_1.c:295
MOBJECT MCreateShell(const char *title, int flags)
EDIT_CURS edc
Definition: ViTES_1.c:23
short DB_BG[3]
Default Background Color.
Function prototypes.
void MTableFormShowGrid(MOBJECT form)
static double p
Definition: SOLPOS.C:131
void MObjectSetUserData(MOBJECT obj, void *ud)
void MEditSetFilter(MOBJECT edit, int filter, const char *extra_chars)
MOBJECT MCreateSpinEdit(MOBJECT parent, const char *text, int len, int clip_len, MTFont font, OBJ_VALUE_CB cb, void *cd)
void MFormSetSpacing(MOBJECT p, int offset)
void MPButtonSetCallback(MOBJECT button, MGUI_CB cb, void *data)
void MLCursorPositionCB(MOBJECT edit, EDIT_CURS *ec, void *lbl)
Definition: ViTES_1.c:70
void MObjectSetCompositeWidth(MOBJECT obj, int w)
short DB_UnSelFG[3]
Unselected Buttons Colors.
short DB_UnSel[3]
Unselected Buttons Colors.
void * MOBJECT
Definition: Mguidefs.h:192
#define True
Definition: Mguidefs.h:235
#define LEFT_ALIGN
Definition: Mguidefs.h:915
void MObjectSetForegroundRGB(MOBJECT obj, int r, int g, int b)
int pos_x
Definition: Mguidefs.h:1347
MOBJECT MCreateRowForm(MOBJECT parent)
void MEditEnableAutoControlColor(MOBJECT edit)
#define TOP_ALIGN
Definition: Mguidefs.h:918
MOBJECT edit
Definition: vitesdef.h:5
______________________________________________________________________________________
Generated on Mon Sep 18 2017 11:44:10 for DAS - Rel. 3.1.6 - 18/09/2017.