)
set(SOURCES
- Canvas.cxx
Canvas.cxx
CanvasEvent.cxx
CanvasEventListener.cxx
//----------------------------------------------------------------------------
ElementPtr Group::createChild( const std::string& type,
- const std::string& name )
+ const std::string& id )
{
SGPropertyNode* node = _node->addChild(type, 0, false);
- if( !name.empty() )
- node->setStringValue("name", name);
+ if( !id.empty() )
+ node->setStringValue("id", id);
return getChild(node);
}
return child->second;
}
+ //----------------------------------------------------------------------------
+ ElementPtr Group::getElementById(const std::string& id)
+ {
+ std::vector<GroupPtr> groups;
+
+ BOOST_FOREACH( ChildList::value_type child, _children )
+ {
+ const ElementPtr& el = child.second;
+ if( el->getProps()->getStringValue("id") == id )
+ return el;
+
+ GroupPtr group = boost::dynamic_pointer_cast<Group>(el);
+ if( group )
+ groups.push_back(group);
+ }
+
+ BOOST_FOREACH( GroupPtr group, groups )
+ {
+ ElementPtr el = group->getElementById(id);
+ if( el )
+ return el;
+ }
+
+ return ElementPtr();
+ }
+
//----------------------------------------------------------------------------
void Group::update(double dt)
{
virtual ~Group();
ElementPtr createChild( const std::string& type,
- const std::string& name = "" );
+ const std::string& id = "" );
ElementPtr getChild(const SGPropertyNode* node);
+ /**
+ * Get first child with given id (breadth-first search)
+ *
+ * @param id Id (value if property node 'id') of element
+ */
+ ElementPtr getElementById(const std::string& id);
+
virtual void update(double dt);
virtual bool traverse(EventVisitor& visitor);
return Ghost::getPtr( naGhost_ptr(me) );
// Now if it is derived from a ghost (hash with ghost in parent vector)
- // TODO handle recursive parents
else if( naIsHash(me) )
{
naRef na_parents = naHash_cget(me, const_cast<char*>("parents"));
parent != parents.end();
++parent )
{
- if( isBaseOf(naGhost_type(*parent)) )
- return Ghost::getPtr( naGhost_ptr(*parent) );
+ pointer ptr = fromNasal(c, *parent);
+ if( ptr )
+ return ptr;
}
}
obj.set("parents", parents);
VERIFY( Ghost<BasePtr>::fromNasal(c, obj.get_naRef()) == d3 );
+ // Check recursive parents (aka parent-of-parent)
+ std::vector<naRef> parents2;
+ parents2.push_back(obj.get_naRef());
+ Hash derived_obj(c);
+ derived_obj.set("parents", parents2);
+ VERIFY( Ghost<BasePtr>::fromNasal(c, derived_obj.get_naRef()) == d3 );
+
naRef args[] = {
to_nasal(c, std::string("test-arg"))
};