GCC Code Coverage Report
Directory: emc/rs274ngc/ Exec Total Coverage
File: emc/rs274ngc/pyemctypes.cc Lines: 27 57 47.4 %
Date: 2016-10-27 Branches: 16 48 33.3 %

Line Exec Source
1
/*    This is a component of LinuxCNC
2
 *    Copyright 2013 Michael Haberler <git@mah.priv.at>
3
 *
4
 *    This program is free software; you can redistribute it and/or modify
5
 *    it under the terms of the GNU General Public License as published by
6
 *    the Free Software Foundation; either version 2 of the License, or
7
 *    (at your option) any later version.
8
 *
9
 *    This program is distributed in the hope that it will be useful,
10
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *    GNU General Public License for more details.
13
 *
14
 *    You should have received a copy of the GNU General Public License
15
 *    along with this program; if not, write to the Free Software
16
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
18
// Interpreter internals - Python bindings
19
// Michael Haberler 7/2011
20
//
21
22
#include <boost/python/class.hpp>
23
#include <boost/python/tuple.hpp>
24
namespace bp = boost::python;
25
26
#include "rs274ngc.hh"
27
28
static bp::object pmcartesian_str( PmCartesian &c) {
29
    return  bp::object("PmCartesian(x=%.4f y=%.4f z=%.4f)" %
30
		       bp::make_tuple(c.x,c.y,c.z));
31
}
32
33
static bp::object emcpose_2_obj ( EmcPose &p) {
34
    return  bp::object("x=%.4f y=%.4f z=%.4f a=%.4f b=%.4f c=%.4f u=%.4f v=%.4f w=%.4f" %
35
		       bp::make_tuple(p.tran.x,p.tran.y,p.tran.z,
36
				      p.a,p.b,p.c,p.u,p.v,p.w));
37
}
38
static bp::object emcpose_str( EmcPose &p) {
39
    return  bp::object("EmcPose(" + emcpose_2_obj(p) + ")");
40
}
41
42
static void  set_x(EmcPose &p, double value) { p.tran.x = value; }
43
static void  set_y(EmcPose &p, double value) { p.tran.y = value; }
44
static void  set_z(EmcPose &p, double value) { p.tran.z = value; }
45
static double get_x(EmcPose &p) { return p.tran.x; }
46
static double get_y(EmcPose &p) { return p.tran.y; }
47
static double get_z(EmcPose &p) { return p.tran.z; }
48
49
static bp::object tool_str( CANON_TOOL_TABLE &t) {
50
    return  bp::object("Tool(T%d D%.4f I%.4f J%.4f Q%d offset: " %
51
		       bp::make_tuple(t.toolno,  t.diameter,
52
				      t.frontangle,t.backangle, t.orientation) +
53
		       emcpose_2_obj(t.offset) + ")");
54
}
55
56
static void tool_zero( CANON_TOOL_TABLE &t) {
57
    t.toolno = -1;
58
    ZERO_EMC_POSE(t.offset);
59
    t.diameter = 0.0;
60
    t.frontangle = 0.0;
61
    t.backangle = 0.0;
62
    t.orientation = 0;
63
}
64
static void carte_zero( PmCartesian &c) {
65
    c.x = 0.0;
66
    c.y = 0.0;
67
    c.z = 0.0;
68
}
69
70
static void pose_zero( EmcPose &p) { ZERO_EMC_POSE(p); }
71
72
73
68
void export_EmcTypes()
74
{
75
    using namespace boost::python;
76
    using namespace boost;
77
78
    // PmCartesian and EmcPose make sense to be instantiable
79
    // within Python, since some canon calls take these as parameter
80
    class_<PmCartesian, noncopyable>("PmCartesian","EMC cartesian postition")
81
136
	.def_readwrite("x",&PmCartesian::x)
82
68
	.def_readwrite("y",&PmCartesian::y)
83
68
	.def_readwrite("z",&PmCartesian::z)
84
68
	.def("__str__", &pmcartesian_str)
85
	.def("zero", &carte_zero)
86
68
	;
87
88
    class_<EmcPose>("EmcPose","EMC pose")
89
136
	.def_readwrite("tran",&EmcPose::tran)
90
68
	.add_property("x", &get_x, &set_x)
91
68
	.add_property("y", &get_y, &set_y)
92
68
	.add_property("z", &get_z, &set_z)
93
68
	.def_readwrite("a",&EmcPose::a)
94
68
	.def_readwrite("b",&EmcPose::b)
95
68
	.def_readwrite("c",&EmcPose::c)
96
68
	.def_readwrite("u",&EmcPose::u)
97
68
	.def_readwrite("v",&EmcPose::v)
98
68
	.def_readwrite("w",&EmcPose::w)
99
68
	.def("__str__", &emcpose_str)
100
	.def("zero", &pose_zero)
101
68
	;
102
103
    // leave CANON_TOOL_TABLE copyable/assignable because assignment is
104
    // used a lot when fiddling with tooltable entries
105
    class_<CANON_TOOL_TABLE >("CANON_TOOL_TABLE","Tool description" ,no_init)
106
136
	.def_readwrite("toolno", &CANON_TOOL_TABLE::toolno)
107
68
	.def_readwrite("offset", &CANON_TOOL_TABLE::offset)
108
68
	.def_readwrite("diameter", &CANON_TOOL_TABLE::diameter)
109
68
	.def_readwrite("frontangle", &CANON_TOOL_TABLE::frontangle)
110
68
	.def_readwrite("backangle", &CANON_TOOL_TABLE::backangle)
111
68
	.def_readwrite("orientation", &CANON_TOOL_TABLE::orientation)
112
68
	.def("__str__", &tool_str)
113
	.def("zero", &tool_zero)
114
68
	;
115
413
}