GCC Code Coverage Report
Directory: emc/rs274ngc/ Exec Total Coverage
File: emc/rs274ngc/interpmodule.cc Lines: 159 694 22.9 %
Date: 2016-10-27 Branches: 143 366 39.1 %

Line Exec Source
1
/*    This is a component of LinuxCNC
2
 *    Copyright 2011, 2012, 2013 Michael Haberler <git@mah.priv.at>,
3
 *    Sebastian Kuzminsky <seb@highlab.com>
4
 *
5
 *    This program is free software; you can redistribute it and/or modify
6
 *    it under the terms of the GNU General Public License as published by
7
 *    the Free Software Foundation; either version 2 of the License, or
8
 *    (at your option) any later version.
9
 *
10
 *    This program is distributed in the hope that it will be useful,
11
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *    GNU General Public License for more details.
14
 *
15
 *    You should have received a copy of the GNU General Public License
16
 *    along with this program; if not, write to the Free Software
17
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
// Interpreter internals - Python bindings
20
// Michael Haberler 7/2011
21
//
22
23
#include <boost/python/class.hpp>
24
#include <boost/python/def.hpp>
25
#include <boost/python/exception_translator.hpp>
26
#include <boost/python/module.hpp>
27
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
28
#include <map>
29
30
namespace bp = boost::python;
31
extern int _task;  // zero in gcodemodule, 1 in milltask
32
33
#include <stdio.h>
34
#include <string.h>
35
#include <assert.h>
36
37
#include "rs274ngc.hh"
38
#include "interp_return.hh"
39
#include "interp_internal.hh"
40
#include "rs274ngc_interp.hh"
41
#include "units.h"
42
#include "array1.hh"
43
44
extern void export_Internals();
45
extern void export_Arrays();
46
extern void export_Block();
47
extern void export_EmcTypes();
48
#include "paramclass.hh"
49
50
namespace pp = pyplusplus::containers::static_sized;
51
#include "interp_array_types.hh"
52
53
#define IS_STRING(x) (PyObject_IsInstance(x.ptr(), (PyObject*)&PyString_Type))
54
#define IS_INT(x) (PyObject_IsInstance(x.ptr(), (PyObject*)&PyInt_Type))
55
56
static  active_g_codes_array active_g_codes_wrapper ( Interp & inst) {
57
    return active_g_codes_array(inst._setup.active_g_codes);
58
}
59
static  active_m_codes_array active_m_codes_wrapper ( Interp & inst) {
60
    return active_m_codes_array(inst._setup.active_m_codes);
61
}
62
63
static  active_settings_array active_settings_wrapper ( Interp & inst) {
64
    return active_settings_array(inst._setup.active_settings);
65
}
66
67
static  blocks_array blocks_wrapper ( Interp & inst) {
68
    return blocks_array(inst._setup.blocks);
69
}
70
71
static  parameters_array parameters_wrapper ( Interp & inst) {
72
    return parameters_array(inst._setup.parameters);
73
}
74
75
static  tool_table_array tool_table_wrapper ( Interp & inst) {
76
    return tool_table_array(inst._setup.tool_table);
77
}
78
79
static  sub_context_array sub_context_wrapper ( Interp & inst) {
80
    return sub_context_array(inst._setup.sub_context);
81
}
82
83
84
#pragma GCC diagnostic ignored "-Wformat-security"
85
static void setErrorMsg(Interp &interp, const char *s)
86
{
87
    setup *settings  = &interp._setup;
88
89
    if ((s == NULL) || (strlen(s) == 0))
90
	s = "###";
91
    interp.setError (s);
92
    settings->stack_index = 0;
93
    strncpy(settings->stack[settings->stack_index],
94
	    "Python", STACK_ENTRY_LEN);
95
    settings->stack[settings->stack_index][STACK_ENTRY_LEN-1] = 0;
96
    settings->stack_index++;
97
    settings->stack[settings->stack_index][0] = 0;
98
}
99
100
#pragma GCC diagnostic warning "-Wformat-security"
101
102
static bp::object errorStack(Interp &interp)
103
{
104
    setup *settings  = &interp._setup;
105
    bp::list msgs;
106
107
    for (int i = 0; i < settings->stack_index; i++)
108
	msgs.append(bp::object( (const char *) settings->stack[i]));
109
    return msgs;
110
}
111
112
static bp::object wrap_find_tool_pocket(Interp &interp, int toolno)
113
{
114
    int status, pocket;
115
    setup *settings  =  &interp._setup;
116
117
    status = interp.find_tool_pocket(settings, toolno, &pocket);
118
    return bp::make_tuple(status, pocket);
119
}
120
121
122
// FIXME not sure if this is really needed
123
3
static  ParamClass param_wrapper ( Interp & inst) {
124
3
    return ParamClass(inst);
125
}
126
127
static int get_task(Interp &i) { return _task; };
128
static const char *get_filename(Interp &i) { return i._setup.filename; };
129
static const char *get_linetext(Interp &i) { return i._setup.linetext; };
130
131
// those are exposed here because they look useful for regression testing
132
8
static bool __equal(double a, double b) { return fabs(a - b) < TOLERANCE_EQUAL; }
133
// see interp_convert.cc
134
static bool is_near_int(double value) {
135
    int i = (int)(value + .5);
136
    return fabs(i - value) < .0001;
137
}
138
static int nearest_int(double value) { return (int)(value + .5); }
139
140
int (Interp::*execute_1)(const char *command) = &Interp::execute;
141
int (Interp::*execute_2)(const char *command, int line_number) = &Interp::execute;
142
143
// lifted from http://stackoverflow.com/questions/2261858/boostpython-export-custom-exception
144
145
146
class InterpreterException : public std::exception {
147
private:
148
    std::string error_message;
149
    int line_number;
150
    std::string line_text;
151
public:
152
    InterpreterException(std::string error_message, int line_number, std::string line_text)  {
153
	this->error_message = error_message;
154
	this->line_number = line_number;
155
	this->line_text = line_text;
156
    }
157
    const char *what() const throw() { return this->error_message.c_str();  }
158
159
    ~InterpreterException() throw()  {}
160
    std::string get_error_message()  { return this->error_message;  }
161
    int get_line_number()    { return this->line_number;  }
162
    std::string get_line_text()      { return this->line_text; }
163
};
164
165
static PyObject *InterpreterExceptionType = NULL;
166
167
void translateInterpreterException(InterpreterException const &e)
168
{
169
  assert(InterpreterExceptionType != NULL);
170
  bp::object pythonExceptionInstance(e);
171
  PyErr_SetObject(InterpreterExceptionType, pythonExceptionInstance.ptr());
172
}
173
174
static int throw_exceptions = 1;
175
176
static int wrap_interp_execute_1(Interp &interp, const char *command)
177
{
178
    setup &_setup = interp._setup;
179
    block saved_block = _setup.blocks[0];
180
    int saved_call_state = _setup.call_state;
181
182
    // Temporarily set the call state to CS_NORMAL
183
    _setup.call_state = CS_NORMAL;
184
    int status = interp.execute(command);
185
    _setup.call_state = saved_call_state;
186
    _setup.blocks[0] = saved_block;
187
188
    // printf("ie1: tc=%d if=%d pf=%d\n", _setup.toolchange_flag,_setup.input_flag,_setup.probe_flag);
189
190
    if ((status > INTERP_MIN_ERROR) && throw_exceptions) {
191
	throw InterpreterException(interp.getSavedError(),
192
				   _setup.blocks[0].line_number, // not sure
193
				   _setup.linetext);
194
    }
195
    return status;
196
}
197
198
static int wrap_interp_execute_2(Interp &interp, const char *command, int lineno)
199
{
200
    setup &_setup = interp._setup;
201
    block saved_block = _setup.blocks[0];
202
203
    // use the remap stack to save/restore the current block
204
    CHP(interp.enter_remap());
205
    int status = interp.execute(command, lineno);
206
    CHP(interp.leave_remap());
207
    _setup.blocks[0] = saved_block;
208
209
    //printf("ie2: tc=%d if=%d pf=%d\n", _setup.toolchange_flag,_setup.input_flag,_setup.probe_flag);
210
    if ((status > INTERP_MIN_ERROR) && throw_exceptions) {
211
	throw InterpreterException(interp.getSavedError(),
212
				   lineno, // not sure
213
				   _setup.linetext);
214
    }
215
    return status;
216
}
217
218
// this might not be a good idea - it destroys the block which has a 'o<ngcbody> call' parsed in it
219
static int wrap_interp_read(Interp &interp, const char *command)
220
{
221
    setup &_setup = interp._setup;
222
    block saved_block = _setup.blocks[0];
223
224
    int status = interp.read(command);
225
    if ((status > INTERP_MIN_ERROR) && throw_exceptions) {
226
	throw InterpreterException(interp.getSavedError(),
227
				   _setup.blocks[0].line_number, // not sure
228
				   _setup.linetext);
229
    }
230
    return status;
231
}
232
233
// static inline remap_map wrap_remaps(Interp &interp)  {
234
//     return interp._setup.remaps;
235
// }
236
237
// what a barren desert
238
static inline EmcPose get_tool_offset (Interp &interp)  {
239
    return interp._setup.tool_offset;
240
}
241
static inline void set_tool_offset(Interp &interp, EmcPose value)  {
242
    interp._setup.tool_offset = value;
243
}
244
static inline bool get_arc_not_allowed (Interp &interp)  {
245
    return interp._setup.arc_not_allowed;
246
}
247
static inline void set_arc_not_allowed(Interp &interp, bool value)  {
248
    interp._setup.arc_not_allowed = value;
249
}
250
static inline bool get_cutter_comp_firstmove (Interp &interp)  {
251
    return interp._setup.cutter_comp_firstmove;
252
}
253
static inline void set_cutter_comp_firstmove(Interp &interp, bool value)  {
254
    interp._setup.cutter_comp_firstmove = value;
255
}
256
static inline bool get_feed_override (Interp &interp)  {
257
    return interp._setup.feed_override;
258
}
259
static inline void set_feed_override(Interp &interp, bool value)  {
260
    interp._setup.feed_override = value;
261
}
262
static inline bool get_input_digital (Interp &interp)  {
263
    return interp._setup.input_digital;
264
}
265
static inline void set_input_digital(Interp &interp, bool value)  {
266
    interp._setup.input_digital = value;
267
}
268
static inline bool get_input_flag (Interp &interp)  {
269
    return interp._setup.input_flag;
270
}
271
static inline void set_input_flag(Interp &interp, bool value)  {
272
    interp._setup.input_flag = value;
273
}
274
static inline bool get_mdi_interrupt (Interp &interp)  {
275
    return interp._setup.mdi_interrupt;
276
}
277
static inline void set_mdi_interrupt(Interp &interp, bool value)  {
278
    interp._setup.mdi_interrupt = value;
279
}
280
static inline bool get_mist (Interp &interp)  {
281
    return interp._setup.mist;
282
}
283
static inline void set_mist(Interp &interp, bool value)  {
284
    interp._setup.mist = value;
285
}
286
static inline bool get_percent_flag (Interp &interp)  {
287
    return interp._setup.percent_flag;
288
}
289
static inline void set_percent_flag(Interp &interp, bool value)  {
290
    interp._setup.percent_flag = value;
291
}
292
static inline bool get_probe_flag (Interp &interp)  {
293
    return interp._setup.probe_flag;
294
}
295
static inline void set_probe_flag(Interp &interp, bool value)  {
296
    interp._setup.probe_flag = value;
297
}
298
static inline bool get_speed_override (Interp &interp)  {
299
    return interp._setup.speed_override;
300
}
301
static inline void set_speed_override(Interp &interp, bool value)  {
302
    interp._setup.speed_override = value;
303
}
304
static inline bool get_toolchange_flag (Interp &interp)  {
305
    return interp._setup.toolchange_flag;
306
}
307
static inline void set_toolchange_flag(Interp &interp, bool value)  {
308
    interp._setup.toolchange_flag = value;
309
}
310
static inline double get_u_current (Interp &interp)  {
311
    return interp._setup.u_current;
312
}
313
static inline void set_u_current(Interp &interp, double value)  {
314
    interp._setup.u_current = value;
315
}
316
static inline double get_AA_axis_offset (Interp &interp)  {
317
    return interp._setup.AA_axis_offset;
318
}
319
static inline void set_AA_axis_offset(Interp &interp, double value)  {
320
    interp._setup.AA_axis_offset = value;
321
}
322
static inline double get_AA_current (Interp &interp)  {
323
    return interp._setup.AA_current;
324
}
325
static inline void set_AA_current(Interp &interp, double value)  {
326
    interp._setup.AA_current = value;
327
}
328
static inline double get_AA_origin_offset (Interp &interp)  {
329
    return interp._setup.AA_origin_offset;
330
}
331
static inline void set_AA_origin_offset(Interp &interp, double value)  {
332
    interp._setup.AA_origin_offset = value;
333
}
334
static inline double get_BB_axis_offset (Interp &interp)  {
335
    return interp._setup.BB_axis_offset;
336
}
337
static inline void set_BB_axis_offset(Interp &interp, double value)  {
338
    interp._setup.BB_axis_offset = value;
339
}
340
static inline double get_BB_current (Interp &interp)  {
341
    return interp._setup.BB_current;
342
}
343
static inline void set_BB_current(Interp &interp, double value)  {
344
    interp._setup.BB_current = value;
345
}
346
static inline double get_BB_origin_offset (Interp &interp)  {
347
    return interp._setup.BB_origin_offset;
348
}
349
static inline void set_BB_origin_offset(Interp &interp, double value)  {
350
    interp._setup.BB_origin_offset = value;
351
}
352
static inline double get_CC_axis_offset (Interp &interp)  {
353
    return interp._setup.CC_axis_offset;
354
}
355
static inline void set_CC_axis_offset(Interp &interp, double value)  {
356
    interp._setup.CC_axis_offset = value;
357
}
358
static inline double get_CC_current (Interp &interp)  {
359
    return interp._setup.CC_current;
360
}
361
static inline void set_CC_current(Interp &interp, double value)  {
362
    interp._setup.CC_current = value;
363
}
364
static inline double get_CC_origin_offset (Interp &interp)  {
365
    return interp._setup.CC_origin_offset;
366
}
367
static inline void set_CC_origin_offset(Interp &interp, double value)  {
368
    interp._setup.CC_origin_offset = value;
369
}
370
static inline double get_axis_offset_x (Interp &interp)  {
371
    return interp._setup.axis_offset_x;
372
}
373
static inline void set_axis_offset_x(Interp &interp, double value)  {
374
    interp._setup.axis_offset_x = value;
375
}
376
static inline double get_axis_offset_y (Interp &interp)  {
377
    return interp._setup.axis_offset_y;
378
}
379
static inline void set_axis_offset_y(Interp &interp, double value)  {
380
    interp._setup.axis_offset_y = value;
381
}
382
static inline double get_axis_offset_z (Interp &interp)  {
383
    return interp._setup.axis_offset_z;
384
}
385
static inline void set_axis_offset_z(Interp &interp, double value)  {
386
    interp._setup.axis_offset_z = value;
387
}
388
static inline double get_current_x (Interp &interp)  {
389
    return interp._setup.current_x;
390
}
391
static inline void set_current_x(Interp &interp, double value)  {
392
    interp._setup.current_x = value;
393
}
394
static inline double get_current_y (Interp &interp)  {
395
    return interp._setup.current_y;
396
}
397
static inline void set_current_y(Interp &interp, double value)  {
398
    interp._setup.current_y = value;
399
}
400
static inline double get_current_z (Interp &interp)  {
401
    return interp._setup.current_z;
402
}
403
static inline void set_current_z(Interp &interp, double value)  {
404
    interp._setup.current_z = value;
405
}
406
static inline double get_cutter_comp_radius (Interp &interp)  {
407
    return interp._setup.cutter_comp_radius;
408
}
409
static inline void set_cutter_comp_radius(Interp &interp, double value)  {
410
    interp._setup.cutter_comp_radius = value;
411
}
412
static inline double get_cycle_cc (Interp &interp)  {
413
    return interp._setup.cycle_cc;
414
}
415
static inline void set_cycle_cc(Interp &interp, double value)  {
416
    interp._setup.cycle_cc = value;
417
}
418
static inline double get_cycle_i (Interp &interp)  {
419
    return interp._setup.cycle_i;
420
}
421
static inline void set_cycle_i(Interp &interp, double value)  {
422
    interp._setup.cycle_i = value;
423
}
424
static inline double get_cycle_il (Interp &interp)  {
425
    return interp._setup.cycle_il;
426
}
427
static inline void set_cycle_il(Interp &interp, double value)  {
428
    interp._setup.cycle_il = value;
429
}
430
static inline double get_cycle_j (Interp &interp)  {
431
    return interp._setup.cycle_j;
432
}
433
static inline void set_cycle_j(Interp &interp, double value)  {
434
    interp._setup.cycle_j = value;
435
}
436
static inline double get_cycle_k (Interp &interp)  {
437
    return interp._setup.cycle_k;
438
}
439
static inline void set_cycle_k(Interp &interp, double value)  {
440
    interp._setup.cycle_k = value;
441
}
442
static inline double get_cycle_p (Interp &interp)  {
443
    return interp._setup.cycle_p;
444
}
445
static inline void set_cycle_p(Interp &interp, double value)  {
446
    interp._setup.cycle_p = value;
447
}
448
static inline double get_cycle_q (Interp &interp)  {
449
    return interp._setup.cycle_q;
450
}
451
static inline void set_cycle_q(Interp &interp, double value)  {
452
    interp._setup.cycle_q = value;
453
}
454
static inline double get_cycle_r (Interp &interp)  {
455
    return interp._setup.cycle_r;
456
}
457
static inline void set_cycle_r(Interp &interp, double value)  {
458
    interp._setup.cycle_r = value;
459
}
460
static inline double get_feed_rate (Interp &interp)  {
461
    return interp._setup.feed_rate;
462
}
463
static inline void set_feed_rate(Interp &interp, double value)  {
464
    interp._setup.feed_rate = value;
465
}
466
static inline double get_origin_offset_x (Interp &interp)  {
467
    return interp._setup.origin_offset_x;
468
}
469
static inline void set_origin_offset_x(Interp &interp, double value)  {
470
    interp._setup.origin_offset_x = value;
471
}
472
static inline double get_origin_offset_y (Interp &interp)  {
473
    return interp._setup.origin_offset_y;
474
}
475
static inline void set_origin_offset_y(Interp &interp, double value)  {
476
    interp._setup.origin_offset_y = value;
477
}
478
static inline double get_origin_offset_z (Interp &interp)  {
479
    return interp._setup.origin_offset_z;
480
}
481
static inline void set_origin_offset_z(Interp &interp, double value)  {
482
    interp._setup.origin_offset_z = value;
483
}
484
static inline double get_program_x (Interp &interp)  {
485
    return interp._setup.program_x;
486
}
487
static inline void set_program_x(Interp &interp, double value)  {
488
    interp._setup.program_x = value;
489
}
490
static inline double get_program_y (Interp &interp)  {
491
    return interp._setup.program_y;
492
}
493
static inline void set_program_y(Interp &interp, double value)  {
494
    interp._setup.program_y = value;
495
}
496
static inline double get_program_z (Interp &interp)  {
497
    return interp._setup.program_z;
498
}
499
static inline void set_program_z(Interp &interp, double value)  {
500
    interp._setup.program_z = value;
501
}
502
8
static inline double get_return_value (Interp &interp)  {
503
8
    return interp._setup.return_value;
504
}
505
static inline void set_return_value(Interp &interp, double value)  {
506
    interp._setup.return_value = value;
507
}
508
static inline double get_rotation_xy (Interp &interp)  {
509
    return interp._setup.rotation_xy;
510
}
511
static inline void set_rotation_xy(Interp &interp, double value)  {
512
    interp._setup.rotation_xy = value;
513
}
514
static inline double get_speed (Interp &interp)  {
515
    return interp._setup.speed;
516
}
517
static inline void set_speed(Interp &interp, double value)  {
518
    interp._setup.speed = value;
519
}
520
static inline double get_traverse_rate (Interp &interp)  {
521
    return interp._setup.traverse_rate;
522
}
523
static inline void set_traverse_rate(Interp &interp, double value)  {
524
    interp._setup.traverse_rate = value;
525
}
526
static inline double get_u_axis_offset (Interp &interp)  {
527
    return interp._setup.u_axis_offset;
528
}
529
static inline void set_u_axis_offset(Interp &interp, double value)  {
530
    interp._setup.u_axis_offset = value;
531
}
532
static inline double get_u_origin_offset (Interp &interp)  {
533
    return interp._setup.u_origin_offset;
534
}
535
static inline void set_u_origin_offset(Interp &interp, double value)  {
536
    interp._setup.u_origin_offset = value;
537
}
538
static inline double get_v_axis_offset (Interp &interp)  {
539
    return interp._setup.v_axis_offset;
540
}
541
static inline void set_v_axis_offset(Interp &interp, double value)  {
542
    interp._setup.v_axis_offset = value;
543
}
544
static inline double get_v_current(Interp &interp)  {
545
    return interp._setup.v_current;
546
}
547
static inline void set_v_current(Interp &interp, double value)  {
548
    interp._setup.v_current = value;
549
}
550
static inline double get_v_origin_offset (Interp &interp)  {
551
    return interp._setup.v_origin_offset;
552
}
553
static inline void set_v_origin_offset(Interp &interp, double value)  {
554
    interp._setup.v_origin_offset = value;
555
}
556
static inline double get_w_axis_offset (Interp &interp)  {
557
    return interp._setup.w_axis_offset;
558
}
559
static inline void set_w_axis_offset(Interp &interp, double value)  {
560
    interp._setup.w_axis_offset = value;
561
}
562
static inline double get_w_current (Interp &interp)  {
563
    return interp._setup.w_current;
564
}
565
static inline void set_w_current(Interp &interp, double value)  {
566
    interp._setup.w_current = value;
567
}
568
static inline double get_w_origin_offset (Interp &interp)  {
569
    return interp._setup.w_origin_offset;
570
}
571
static inline void set_w_origin_offset(Interp &interp, double value)  {
572
    interp._setup.w_origin_offset = value;
573
}
574
static inline int get_a_axis_wrapped (Interp &interp)  {
575
    return interp._setup.a_axis_wrapped;
576
}
577
static inline void set_a_axis_wrapped(Interp &interp, int value)  {
578
    interp._setup.a_axis_wrapped = value;
579
}
580
static inline int get_a_indexer (Interp &interp)  {
581
    return interp._setup.a_indexer_jnum;
582
}
583
static inline void set_a_indexer(Interp &interp, int value)  {
584
    interp._setup.a_indexer_jnum = value;
585
}
586
static inline int get_b_axis_wrapped (Interp &interp)  {
587
    return interp._setup.b_axis_wrapped;
588
}
589
static inline void set_b_axis_wrapped(Interp &interp, int value)  {
590
    interp._setup.b_axis_wrapped = value;
591
}
592
static inline int get_b_indexer (Interp &interp)  {
593
    return interp._setup.b_indexer_jnum;
594
}
595
static inline void set_b_indexer(Interp &interp, int value)  {
596
    interp._setup.b_indexer_jnum = value;
597
}
598
static inline int get_c_axis_wrapped (Interp &interp)  {
599
    return interp._setup.c_axis_wrapped;
600
}
601
static inline void set_c_axis_wrapped(Interp &interp, int value)  {
602
    interp._setup.c_axis_wrapped = value;
603
}
604
static inline int get_c_indexer (Interp &interp)  {
605
    return interp._setup.c_indexer_jnum;
606
}
607
static inline void set_c_indexer(Interp &interp, int value)  {
608
    interp._setup.c_indexer_jnum = value;
609
}
610
static inline int get_call_level (Interp &interp)  {
611
    return interp._setup.call_level;
612
}
613
static inline void set_call_level(Interp &interp, int value)  {
614
    interp._setup.call_level = value;
615
}
616
static inline int get_current_pocket (Interp &interp)  {
617
    return interp._setup.current_pocket;
618
}
619
static inline void set_current_pocket(Interp &interp, int value)  {
620
    interp._setup.current_pocket = value;
621
}
622
static inline int get_cutter_comp_orientation (Interp &interp)  {
623
    return interp._setup.cutter_comp_orientation;
624
}
625
static inline void set_cutter_comp_orientation(Interp &interp, int value)  {
626
    interp._setup.cutter_comp_orientation = value;
627
}
628
static inline int get_cutter_comp_side (Interp &interp)  {
629
    return interp._setup.cutter_comp_side;
630
}
631
static inline void set_cutter_comp_side(Interp &interp, int value)  {
632
    interp._setup.cutter_comp_side = value;
633
}
634
static inline int get_cycle_il_flag (Interp &interp)  {
635
    return interp._setup.cycle_il_flag;
636
}
637
static inline void set_cycle_il_flag(Interp &interp, int value)  {
638
    interp._setup.cycle_il_flag = value;
639
}
640
static inline int get_cycle_l (Interp &interp)  {
641
    return interp._setup.cycle_l;
642
}
643
static inline void set_cycle_l(Interp &interp, int value)  {
644
    interp._setup.cycle_l = value;
645
}
646
static inline int get_debugmask (Interp &interp)  {
647
    return interp._setup.debugmask;
648
}
649
static inline void set_debugmask(Interp &interp, int value)  {
650
    interp._setup.debugmask = value;
651
}
652
static inline int get_distance_mode (Interp &interp)  {
653
    return interp._setup.distance_mode;
654
}
655
static inline void set_distance_mode(Interp &interp, DISTANCE_MODE value)  {
656
    interp._setup.distance_mode = value;
657
}
658
static inline int get_feed_mode (Interp &interp)  {
659
    return interp._setup.feed_mode;
660
}
661
static inline void set_feed_mode(Interp &interp, int value)  {
662
    interp._setup.feed_mode = value;
663
}
664
static inline int get_ijk_distance_mode (Interp &interp)  {
665
    return interp._setup.ijk_distance_mode;
666
}
667
static inline void set_ijk_distance_mode(Interp &interp, DISTANCE_MODE value)  {
668
    interp._setup.ijk_distance_mode = value;
669
}
670
static inline int get_input_index (Interp &interp)  {
671
    return interp._setup.input_index;
672
}
673
static inline void set_input_index(Interp &interp, int value)  {
674
    interp._setup.input_index = value;
675
}
676
static inline int get_length_units (Interp &interp)  {
677
    return interp._setup.length_units;
678
}
679
static inline void set_length_units(Interp &interp, int value)  {
680
    interp._setup.length_units = value;
681
}
682
static inline int get_loggingLevel (Interp &interp)  {
683
    return interp._setup.loggingLevel;
684
}
685
static inline void set_loggingLevel(Interp &interp, int value)  {
686
    interp._setup.loggingLevel = value;
687
}
688
static inline int get_motion_mode (Interp &interp)  {
689
    return interp._setup.motion_mode;
690
}
691
static inline void set_motion_mode(Interp &interp, int value)  {
692
    interp._setup.motion_mode = value;
693
}
694
static inline int get_origin_index (Interp &interp)  {
695
    return interp._setup.origin_index;
696
}
697
static inline void set_origin_index(Interp &interp, int value)  {
698
    interp._setup.origin_index = value;
699
}
700
static inline int get_plane (Interp &interp)  {
701
    return interp._setup.plane;
702
}
703
static inline void set_plane(Interp &interp, int value)  {
704
    interp._setup.plane = value;
705
}
706
static inline int get_pockets_max (Interp &interp)  {
707
    return interp._setup.pockets_max;
708
}
709
static inline void set_pockets_max(Interp &interp, int value)  {
710
    interp._setup.pockets_max = value;
711
}
712
static inline int get_random_toolchanger (Interp &interp)  {
713
    return interp._setup.random_toolchanger;
714
}
715
static inline void set_random_toolchanger(Interp &interp, int value)  {
716
    interp._setup.random_toolchanger = value;
717
}
718
static inline int get_remap_level (Interp &interp)  {
719
    return interp._setup.remap_level;
720
}
721
static inline void set_remap_level(Interp &interp, int value)  {
722
    interp._setup.remap_level = value;
723
}
724
static inline int get_retract_mode (Interp &interp)  {
725
    return interp._setup.retract_mode;
726
}
727
static inline void set_retract_mode(Interp &interp, RETRACT_MODE value)  {
728
    interp._setup.retract_mode = value;
729
}
730
static inline int get_selected_pocket (Interp &interp)  {
731
    return interp._setup.selected_pocket;
732
}
733
static inline void set_selected_pocket(Interp &interp, int value)  {
734
    interp._setup.selected_pocket = value;
735
}
736
static inline int get_selected_tool (Interp &interp)  {
737
    return interp._setup.selected_tool;
738
}
739
static inline void set_selected_tool(Interp &interp, int value)  {
740
    interp._setup.selected_tool = value;
741
}
742
static inline int get_sequence_number (Interp &interp)  {
743
    return interp._setup.sequence_number;
744
}
745
static inline void set_sequence_number(Interp &interp, int value)  {
746
    interp._setup.sequence_number = value;
747
}
748
static inline int get_speed_feed_mode (Interp &interp)  {
749
    return interp._setup.speed_feed_mode;
750
}
751
static inline void set_speed_feed_mode(Interp &interp, int value)  {
752
    interp._setup.speed_feed_mode = value;
753
}
754
static inline int get_spindle_mode (Interp &interp)  {
755
    return interp._setup.spindle_mode;
756
}
757
static inline void set_spindle_mode(Interp &interp, SPINDLE_MODE value)  {
758
    interp._setup.spindle_mode = value;
759
}
760
static inline int get_spindle_turning (Interp &interp)  {
761
    return interp._setup.spindle_turning;
762
}
763
static inline void set_spindle_turning(Interp &interp, int value)  {
764
    interp._setup.spindle_turning = value;
765
}
766
static inline int get_stack_index (Interp &interp)  {
767
    return interp._setup.stack_index;
768
}
769
static inline void set_stack_index(Interp &interp, int value)  {
770
    interp._setup.stack_index = value;
771
}
772
8
static inline int get_value_returned (Interp &interp)  {
773
8
    return interp._setup.value_returned;
774
}
775
static inline void set_value_returned(Interp &interp, int value)  {
776
    interp._setup.value_returned = value;
777
}
778
static inline int get_current_tool(Interp &interp)  {
779
    return interp._setup.tool_table[0].toolno;
780
}
781
static inline void set_current_tool(Interp &interp, int value)  {
782
    interp._setup.tool_table[0].toolno = value;
783
}
784
785
786
136
BOOST_PYTHON_MODULE(interpreter) {
787
    using namespace boost::python;
788
    using namespace boost;
789
790
136
    scope().attr("__doc__") =
791
        "Interpreter introspection\n"
792
68
        ;
793
204
    scope().attr("throw_exceptions") = throw_exceptions;
794
795
204
    scope().attr("INTERP_OK") = INTERP_OK;
796
204
    scope().attr("INTERP_EXIT") = INTERP_EXIT;
797
204
    scope().attr("INTERP_EXECUTE_FINISH") = INTERP_EXECUTE_FINISH;
798
204
    scope().attr("INTERP_ENDFILE") = INTERP_ENDFILE;
799
204
    scope().attr("INTERP_FILE_NOT_OPEN") = INTERP_FILE_NOT_OPEN;
800
204
    scope().attr("INTERP_ERROR") = INTERP_ERROR;
801
204
    scope().attr("INTERP_MIN_ERROR") = INTERP_MIN_ERROR;
802
204
    scope().attr("TOLERANCE_EQUAL") = TOLERANCE_EQUAL;
803
804
204
    scope().attr("MODE_ABSOLUTE") = (int) MODE_ABSOLUTE;
805
204
    scope().attr("MODE_INCREMENTAL") = (int) MODE_INCREMENTAL;
806
204
    scope().attr("R_PLANE") =  (int) R_PLANE;
807
204
    scope().attr("OLD_Z") =  (int) OLD_Z;
808
809
204
    scope().attr("UNITS_PER_MINUTE") =  (int) UNITS_PER_MINUTE;
810
204
    scope().attr("INVERSE_TIME") =  (int) INVERSE_TIME;
811
204
    scope().attr("UNITS_PER_REVOLUTION") =  (int) UNITS_PER_REVOLUTION;
812
813
204
    scope().attr("RIGHT") = RIGHT;
814
204
    scope().attr("LEFT") = LEFT;
815
204
    scope().attr("CONSTANT_RPM") =  (int) CONSTANT_RPM;
816
204
    scope().attr("CONSTANT_SURFACE") =  (int) CONSTANT_SURFACE;
817
818
68
    def("equal", &__equal);  // EMC's perception of equality of doubles
819
68
    def("is_near_int", &is_near_int);  // EMC's perception of closeness to an int
820
68
    def("nearest_int", &nearest_int);
821
822
68
    export_EmcTypes();
823
68
    export_ParamClass();
824
68
    export_Internals();
825
68
    export_Block();
826
68
    class_<InterpreterException>InterpreterExceptionClass("InterpreterException",							bp::init<std::string, int, std::string>());
827
    InterpreterExceptionClass
828
68
	.add_property("error_message", &InterpreterException::get_error_message)
829
136
	.add_property("line_number", &InterpreterException::get_line_number)
830
68
	.add_property("line_text", &InterpreterException::get_line_text)
831
136
	;
832
833
68
    InterpreterExceptionType = InterpreterExceptionClass.ptr();
834
835
    bp::register_exception_translator<InterpreterException>
836
68
	(&translateInterpreterException);
837
838
    class_< Interp, noncopyable >("Interp",no_init)
839
840
136
	.def("find_tool_pocket", &wrap_find_tool_pocket)
841
68
	.def("load_tool_table", &Interp::load_tool_table)
842
136
	.def("set_tool_parameters", &Interp::set_tool_parameters)
843
844
845
136
	.def("set_errormsg", &setErrorMsg)
846
68
	.def("get_errormsg", &Interp::getSavedError)
847
136
	.def("stack", &errorStack)
848
68
	.def("synch", &Interp::synch)
849
850
	// those will raise exceptions on return value < INTERP_MIN_ERROR  if throw_exceptions is set.
851
136
	.def("execute", &wrap_interp_execute_1)
852
68
	.def("execute",  &wrap_interp_execute_2)
853
68
	.def("read", &wrap_interp_read)
854
855
	// until I know better
856
	//.def_readwrite("remaps",  &wrap_remaps)
857
858
68
	.add_property("task", &get_task) // R/O
859
68
	.add_property("filename", &get_filename) // R/O
860
68
	.add_property("linetext", &get_linetext) // R/O
861
68
	.add_property("tool_offset", &get_tool_offset, &set_tool_offset)
862
68
	.add_property("arc_not_allowed", &get_arc_not_allowed, &set_arc_not_allowed)
863
	.add_property("cutter_comp_firstmove",
864
		      &get_cutter_comp_firstmove,
865
68
		      &set_cutter_comp_firstmove)
866
68
	.add_property("feed_override", &get_feed_override, &set_feed_override)
867
68
	.add_property("input_digital", &get_input_digital, &set_input_digital)
868
68
	.add_property("input_flag", &get_input_flag, &set_input_flag)
869
68
	.add_property("mdi_interrupt", &get_mdi_interrupt, &set_mdi_interrupt)
870
68
	.add_property("mist", &get_mist, &set_mist)
871
68
	.add_property("percent_flag", &get_percent_flag, &set_percent_flag)
872
68
	.add_property("probe_flag", &get_probe_flag, &set_probe_flag)
873
68
	.add_property("speed_override", &get_speed_override, &set_speed_override)
874
68
	.add_property("toolchange_flag", &get_toolchange_flag, &set_toolchange_flag)
875
68
	.add_property("u_current", &get_u_current, &set_u_current)
876
68
	.add_property("AA_axis_offset", &get_AA_axis_offset, &set_AA_axis_offset)
877
68
	.add_property("AA_current", &get_AA_current, &set_AA_current)
878
68
	.add_property("AA_origin_offset", &get_AA_origin_offset, &set_AA_origin_offset)
879
68
	.add_property("BB_axis_offset", &get_BB_axis_offset, &set_BB_axis_offset)
880
68
	.add_property("BB_current", &get_BB_current, &set_BB_current)
881
68
	.add_property("BB_origin_offset", &get_BB_origin_offset, &set_BB_origin_offset)
882
68
	.add_property("CC_axis_offset", &get_CC_axis_offset, &set_CC_axis_offset)
883
68
	.add_property("CC_current", &get_CC_current, &set_CC_current)
884
68
	.add_property("CC_origin_offset", &get_CC_origin_offset, &set_CC_origin_offset)
885
68
	.add_property("axis_offset_x", &get_axis_offset_x, &set_axis_offset_x)
886
68
	.add_property("axis_offset_y", &get_axis_offset_y, &set_axis_offset_y)
887
68
	.add_property("axis_offset_z", &get_axis_offset_z, &set_axis_offset_z)
888
68
	.add_property("current_x", &get_current_x, &set_current_x)
889
68
	.add_property("current_y", &get_current_y, &set_current_y)
890
68
	.add_property("current_z", &get_current_z, &set_current_z)
891
68
	.add_property("cutter_comp_radius", &get_cutter_comp_radius, &set_cutter_comp_radius)
892
68
	.add_property("cycle_cc", &get_cycle_cc, &set_cycle_cc)
893
68
	.add_property("cycle_i", &get_cycle_i, &set_cycle_i)
894
68
	.add_property("cycle_il", &get_cycle_il, &set_cycle_il)
895
68
	.add_property("cycle_j", &get_cycle_j, &set_cycle_j)
896
68
	.add_property("cycle_k", &get_cycle_k, &set_cycle_k)
897
68
	.add_property("cycle_p", &get_cycle_p, &set_cycle_p)
898
68
	.add_property("cycle_q", &get_cycle_q, &set_cycle_q)
899
68
	.add_property("cycle_r", &get_cycle_r, &set_cycle_r)
900
68
	.add_property("feed_rate", &get_feed_rate, &set_feed_rate)
901
68
	.add_property("origin_offset_x", &get_origin_offset_x, &set_origin_offset_x)
902
68
	.add_property("origin_offset_y", &get_origin_offset_y, &set_origin_offset_y)
903
68
	.add_property("origin_offset_z", &get_origin_offset_z, &set_origin_offset_z)
904
68
	.add_property("program_x", &get_program_x, &set_program_x)
905
68
	.add_property("program_y", &get_program_y, &set_program_y)
906
68
	.add_property("program_z", &get_program_z, &set_program_z)
907
68
	.add_property("return_value", &get_return_value, &set_return_value)
908
68
	.add_property("rotation_xy", &get_rotation_xy, &set_rotation_xy)
909
68
	.add_property("speed", &get_speed, &set_speed)
910
68
	.add_property("traverse_rate", &get_traverse_rate, &set_traverse_rate)
911
68
	.add_property("u_axis_offset", &get_u_axis_offset, &set_u_axis_offset)
912
68
	.add_property("u_origin_offset", &get_u_origin_offset, &set_u_origin_offset)
913
68
	.add_property("v_axis_offset", &get_v_axis_offset, &set_v_axis_offset)
914
68
	.add_property("v_current", &get_v_current, &set_v_current)
915
68
	.add_property("v_origin_offset", &get_v_origin_offset, &set_v_origin_offset)
916
68
	.add_property("w_axis_offset", &get_w_axis_offset, &set_w_axis_offset)
917
68
	.add_property("w_current", &get_w_current, &set_w_current)
918
68
	.add_property("w_origin_offset", &get_w_origin_offset, &set_w_origin_offset)
919
68
	.add_property("a_axis_wrapped", &get_a_axis_wrapped, &set_a_axis_wrapped)
920
68
	.add_property("a_indexer_jnum", &get_a_indexer, &set_a_indexer)
921
68
	.add_property("b_axis_wrapped", &get_b_axis_wrapped, &set_b_axis_wrapped)
922
68
	.add_property("b_indexer_jnum", &get_b_indexer, &set_b_indexer)
923
68
	.add_property("c_axis_wrapped", &get_c_axis_wrapped, &set_c_axis_wrapped)
924
68
	.add_property("c_indexer_jnum", &get_c_indexer, &set_c_indexer)
925
68
	.add_property("call_level", &get_call_level, &set_call_level)
926
68
	.add_property("current_pocket", &get_current_pocket, &set_current_pocket)
927
	.add_property("cutter_comp_orientation",
928
68
		      &get_cutter_comp_orientation, &set_cutter_comp_orientation)
929
68
	.add_property("cutter_comp_side", &get_cutter_comp_side, &set_cutter_comp_side)
930
68
	.add_property("cycle_il_flag", &get_cycle_il_flag, &set_cycle_il_flag)
931
68
	.add_property("cycle_l", &get_cycle_l, &set_cycle_l)
932
68
	.add_property("debugmask", &get_debugmask, &set_debugmask)
933
68
	.add_property("distance_mode", &get_distance_mode, &set_distance_mode)
934
68
	.add_property("feed_mode", &get_feed_mode, &set_feed_mode)
935
68
	.add_property("ijk_distance_mode", &get_ijk_distance_mode, &set_ijk_distance_mode)
936
68
	.add_property("input_index", &get_input_index, &set_input_index)
937
68
	.add_property("length_units", &get_length_units, &set_length_units)
938
68
	.add_property("loggingLevel", &get_loggingLevel, &set_loggingLevel)
939
68
	.add_property("motion_mode", &get_motion_mode, &set_motion_mode)
940
68
	.add_property("origin_index", &get_origin_index, &set_origin_index)
941
68
	.add_property("plane", &get_plane, &set_plane)
942
68
	.add_property("pockets_max", &get_pockets_max, &set_pockets_max)
943
68
	.add_property("random_toolchanger", &get_random_toolchanger, &set_random_toolchanger)
944
68
	.add_property("remap_level", &get_remap_level, &set_remap_level)
945
68
	.add_property("retract_mode", &get_retract_mode, &set_retract_mode)
946
68
	.add_property("selected_pocket", &get_selected_pocket, &set_selected_pocket)
947
68
	.add_property("selected_tool", &get_selected_tool, &set_selected_tool)
948
68
	.add_property("sequence_number", &get_sequence_number, &set_sequence_number)
949
68
	.add_property("speed_feed_mode", &get_speed_feed_mode, &set_speed_feed_mode)
950
68
	.add_property("spindle_mode", &get_spindle_mode, &set_spindle_mode)
951
68
	.add_property("spindle_turning", &get_spindle_turning, &set_spindle_turning)
952
68
	.add_property("stack_index", &get_stack_index, &set_stack_index)
953
68
	.add_property("value_returned", &get_value_returned, &set_value_returned)
954
955
68
	.add_property("current_tool", &get_current_tool, &set_current_tool)
956
957
	.add_property( "params",
958
		       bp::make_function( &param_wrapper,
959
204
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
960
961
962
	// _setup arrays
963
	.add_property( "active_g_codes",
964
		       bp::make_function( active_g_codes_w(&active_g_codes_wrapper),
965
204
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
966
	.add_property( "active_m_codes",
967
		       bp::make_function( active_m_codes_w(&active_m_codes_wrapper),
968
204
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
969
	.add_property( "active_settings",
970
		       bp::make_function( active_settings_w(&active_settings_wrapper),
971
204
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
972
	.add_property( "blocks",
973
		       bp::make_function( blocks_w(&blocks_wrapper),
974
204
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
975
	.add_property( "parameters",
976
		       bp::make_function( parameters_w(&parameters_wrapper),
977
204
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
978
	.add_property( "tool_table",
979
		       bp::make_function( tool_table_w(&tool_table_wrapper),
980
204
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
981
	.add_property( "sub_context",
982
		       bp::make_function( sub_context_w(&sub_context_wrapper),
983
136
					  bp::with_custodian_and_ward_postcall< 0, 1 >()))
984
68
	;
985
986
68
    export_Arrays();
987
413
}