summaryrefslogtreecommitdiff
path: root/control.cc
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2010-01-13 12:24:24 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2010-01-13 12:24:24 (GMT)
commit7f944e1e25faa8d8c077ba78e4fd489b69270fb5 (patch)
treed9330c7943a585865855e3f3fe3dfdfc400480cd /control.cc
parent367d7b3244c0091f9ca8b5b39a62c5d49886577c (diff)
Clifford Wolf:
Added child() statement git-svn-id: http://svn.clifford.at/openscad/trunk@275 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'control.cc')
-rw-r--r--control.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/control.cc b/control.cc
index c898dfc..19c5255 100644
--- a/control.cc
+++ b/control.cc
@@ -24,6 +24,7 @@
#include "printutils.h"
enum control_type_e {
+ CHILD,
ECHO,
ASSIGN,
FOR,
@@ -81,6 +82,26 @@ void for_eval(AbstractNode *node, int l, const QVector<QString> &call_argnames,
AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation *inst) const
{
+ if (type == CHILD)
+ {
+ int n = 0;
+ if (inst->argvalues.size() > 0) {
+ double v;
+ if (inst->argvalues[0].getnum(v))
+ n = v;
+ }
+ for (int i = Context::ctx_stack.size()-1; i >= 0; i--) {
+ const Context *c = Context::ctx_stack[i];
+ if (c->inst_p) {
+ if (n < c->inst_p->children.size())
+ return c->inst_p->children[n]->evaluate(c->inst_p->ctx);
+ return NULL;
+ }
+ c = c->parent;
+ }
+ return NULL;
+ }
+
AbstractNode *node;
if (type == INT_FOR)
@@ -135,6 +156,7 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation
void register_builtin_control()
{
+ builtin_modules["child"] = new ControlModule(CHILD);
builtin_modules["echo"] = new ControlModule(ECHO);
builtin_modules["assign"] = new ControlModule(ASSIGN);
builtin_modules["for"] = new ControlModule(FOR);
contact: Jan Huwald // Impressum