summaryrefslogtreecommitdiff
path: root/src/builtin.cc
blob: bdd2d3b8053aee83cb77a831ff305e4dc77f8af2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "builtin.h"
#include "function.h"
#include "module.h"
#include "expression.h"
#include <boost/foreach.hpp>

Builtins *Builtins::instance(bool erase)
{
	static Builtins *s_builtins = new Builtins;
	if (erase) {
		delete s_builtins;
		s_builtins = NULL;
	}
	return s_builtins;
}

void Builtins::init(const char *name, class AbstractModule *module)
{
	Builtins::instance()->rootmodule.modules[name] = module;
}

void Builtins::init(const char *name, class AbstractFunction *function)
{
	Builtins::instance()->rootmodule.functions[name] = function;
}

extern void register_builtin_functions();
extern void register_builtin_csgops();
extern void register_builtin_transform();
extern void register_builtin_color();
extern void register_builtin_primitives();
extern void register_builtin_surface();
extern void register_builtin_control();
extern void register_builtin_render();
extern void register_builtin_import();
extern void register_builtin_projection();
extern void register_builtin_cgaladv();
extern void register_builtin_dxf_linear_extrude();
extern void register_builtin_dxf_rotate_extrude();
extern void initialize_builtin_dxf_dim();

/*!
	Registers all builtin functions.
	Call once for the whole app.
*/
void Builtins::initialize()
{
	register_builtin_functions();
	initialize_builtin_dxf_dim();

	init("group", new AbstractModule());

	register_builtin_csgops();
	register_builtin_transform();
	register_builtin_color();
	register_builtin_primitives();
	register_builtin_surface();
	register_builtin_control();
	register_builtin_render();
	register_builtin_import();
	register_builtin_projection();
	register_builtin_cgaladv();
	register_builtin_dxf_linear_extrude();
	register_builtin_dxf_rotate_extrude();

	this->deprecations["dxf_linear_extrude"] = "linear_extrude";
	this->deprecations["dxf_rotate_extrude"] = "rotate_extrude";
	this->deprecations["import_stl"] = "import";
	this->deprecations["import_dxf"] = "import";
	this->deprecations["import_off"] = "import";
}

std::string Builtins::isDeprecated(const std::string &name)
{
	if (this->deprecations.find(name) != this->deprecations.end()) {
		return this->deprecations[name];
	}
	return std::string();
}

Builtins::Builtins()
{
	this->rootmodule.assignments_var.push_back("$fn");
	this->rootmodule.assignments["$fn"] = new Expression(Value(0.0));
	this->rootmodule.assignments_var.push_back("$fs");
	this->rootmodule.assignments["$fs"] = new Expression(Value(2.0));
	this->rootmodule.assignments_var.push_back("$fa");
	this->rootmodule.assignments["$fa"] = new Expression(Value(12.0));
	this->rootmodule.assignments_var.push_back("$t");
	this->rootmodule.assignments["$t"] = new Expression(Value(0.0));

	Value::VectorType zero3;
	zero3.push_back(Value(0.0));
	zero3.push_back(Value(0.0));
	zero3.push_back(Value(0.0));
	Value zero3val(zero3);
	this->rootmodule.assignments_var.push_back("$vpt");
	this->rootmodule.assignments["$vpt"] = new Expression(zero3val);
	this->rootmodule.assignments_var.push_back("$vpr");
	this->rootmodule.assignments["$vpr"] = new Expression(zero3val);
}

Builtins::~Builtins()
{
}
contact: Jan Huwald // Impressum