// 3D model (exampleD.4.wrl) saved using XRML C/so exporter
#include "xrmlP.H"

using namespace xrml;

static MFNode* sceneGraph;
static namedNodeTable* namedNodes;
static protoTable* protos;
static SFNode* master;  // contains enclosing PROTO interface

static SFNode* proto_1_master(void)
{
  interfaceMember* interface[2] = {
    new field("legColor", fieldValue(new SFColor), 0),
    new field("topColor", fieldValue(new SFColor), 0),
  };
  SFNode* node = new SFNode("TwoColorTable", 2, interface);

  SFColor legColor(0.8, 0.4, 0.7);
  node->interface[0]->assign(node, fieldValue(&legColor));
  SFColor topColor(0.6, 0.6, 0.1);
  node->interface[1]->assign(node, fieldValue(&topColor));
  return node;
}

static void proto_1_protodecls(void)
{
}

#include "Material.H"

static SFNode* node_2(void)
{
  static Material* node = 0;
  if (node) return node;

  node = new Material;
  node->interface[1] = node->interface[1]->link(node, master, master->interface[1]);
  return node;
}

#include "Appearance.H"

static SFNode* node_3(void)
{
  static Appearance* node = 0;
  if (node) return node;

  node = new Appearance;
  SFNode* material(node_2());
  node->interface[0]->assign(node, fieldValue(&material));
  return node;
}

#include "Box.H"

static SFNode* node_4(void)
{
  static Box* node = 0;
  if (node) return node;

  node = new Box;
  SFVec3f size(1.2, 0.2, 1.2);
  node->interface[0]->assign(node, fieldValue(&size));
  return node;
}

#include "Shape.H"

static SFNode* node_5(void)
{
  static Shape* node = 0;
  if (node) return node;

  node = new Shape;
  SFNode* appearance(node_3());
  node->interface[0]->assign(node, fieldValue(&appearance));
  SFNode* geometry(node_4());
  node->interface[1]->assign(node, fieldValue(&geometry));
  return node;
}

#include "Transform.H"

static SFNode* node_6(void)
{
  static Transform* node = 0;
  if (node) return node;

  node = new Transform;
  SFNode* the_children[] = { node_5() };
  MFNode children(0); children.set(1, the_children);
  node->interface[3]->assign(node, fieldValue(&children));
  SFVec3f translation(0, 0.6, 0);
  node->interface[7]->assign(node, fieldValue(&translation));
  return node;
}

#include "Material.H"

static SFNode* node_7(void)
{
  static Material* node = 0;
  if (node) return node;

  node = new Material;
  node->interface[1] = node->interface[1]->link(node, master, master->interface[0]);
  return node;
}

#include "Appearance.H"

static SFNode* node_8(void)
{
  static Appearance* node = 0;
  if (node) return node;

  node = new Appearance;
  SFNode* material(node_7());
  node->interface[0]->assign(node, fieldValue(&material));
  return node;
}

#include "Cylinder.H"

static SFNode* node_9(void)
{
  static Cylinder* node = 0;
  if (node) return node;

  node = new Cylinder;
  SFFloat height(1);
  node->interface[1]->assign(node, fieldValue(&height));
  SFFloat radius(0.1);
  node->interface[2]->assign(node, fieldValue(&radius));
  return node;
}

#include "Shape.H"

static SFNode* node_10(void)
{
  static Shape* node = 0;
  if (node) return node;

  node = new Shape;
  SFNode* appearance(node_8());
  node->interface[0]->assign(node, fieldValue(&appearance));
  SFNode* geometry(node_9());
  node->interface[1]->assign(node, fieldValue(&geometry));
  node->nameId = "Leg";
  node->nameIndex = namedNodes->add("Leg", node);
  return node;
}

#include "Transform.H"

static SFNode* node_11(void)
{
  static Transform* node = 0;
  if (node) return node;

  node = new Transform;
  SFNode* the_children[] = { node_10() };
  MFNode children; children.set(1, (SFNode**)the_children);
  node->interface[3]->assign(node, fieldValue(&children));
  SFVec3f translation(-0.5, 0, -0.5);
  node->interface[7]->assign(node, fieldValue(&translation));
  return node;
}

#include "Transform.H"

static SFNode* node_12(void)
{
  static Transform* node = 0;
  if (node) return node;

  node = new Transform;
  SFNode* the_children[] = { node_10() };
  MFNode children; children.set(1, (SFNode**)the_children);
  node->interface[3]->assign(node, fieldValue(&children));
  SFVec3f translation(0.5, 0, -0.5);
  node->interface[7]->assign(node, fieldValue(&translation));
  return node;
}

#include "Transform.H"

static SFNode* node_13(void)
{
  static Transform* node = 0;
  if (node) return node;

  node = new Transform;
  SFNode* the_children[] = { node_10() };
  MFNode children; children.set(1, (SFNode**)the_children);
  node->interface[3]->assign(node, fieldValue(&children));
  SFVec3f translation(-0.5, 0, 0.5);
  node->interface[7]->assign(node, fieldValue(&translation));
  return node;
}

#include "Transform.H"

static SFNode* node_14(void)
{
  static Transform* node = 0;
  if (node) return node;

  node = new Transform;
  SFNode* the_children[] = { node_10() };
  MFNode children; children.set(1, (SFNode**)the_children);
  node->interface[3]->assign(node, fieldValue(&children));
  SFVec3f translation(0.5, 0, 0.5);
  node->interface[7]->assign(node, fieldValue(&translation));
  return node;
}

#include "Transform.H"

static SFNode* node_15(void)
{
  static Transform* node = 0;
  if (node) return node;

  node = new Transform;
  SFNode* the_children[] = { node_6(), node_11(), node_12(), node_13(), node_14() };
  MFNode children; children.set(5, (SFNode**)the_children);
  node->interface[3]->assign(node, fieldValue(&children));
  return node;
}

static void proto_1_scenegraph(void)
{
  SFNode* the_nodes[] = { node_15() };
  sceneGraph->append(1, the_nodes);
}

static void proto_1_routes(void)
{
}

static Proto* proto_1(void)
{
  static Proto* proto = 0;
  if (proto) return proto;

  SFNode* prev_master = master; master = proto_1_master();
  MFNode* prev_sg = sceneGraph; sceneGraph = new MFNode;
  namedNodeTable* prev_nn = namedNodes; namedNodes = new namedNodeTable;
  protoTable* prev_protos = protos; protos = new protoTable;
  
  proto_1_protodecls();
  proto_1_scenegraph();
  proto_1_routes();
  proto = new Proto(master, sceneGraph, *namedNodes, *protos);
  
  master = prev_master;
  sceneGraph = prev_sg;
  namedNodes = prev_nn;
  protos = prev_protos;
  protos->add("TwoColorTable", proto);
  return proto;
}

static void protodecls(void)
{
  proto_1();
}

static SFNode* node_16(void)
{
  static SFNode* node = 0;
  if (node) return node;

  node = proto_1()->instantiate();
  SFColor legColor(1, 0, 0);
  node->interface[0]->assign(node, fieldValue(&legColor));
  SFColor topColor(0, 1, 0);
  node->interface[1]->assign(node, fieldValue(&topColor));
  return node;
}

#include "NavigationInfo.H"

static SFNode* node_17(void)
{
  static NavigationInfo* node = 0;
  if (node) return node;

  node = new NavigationInfo;
  char* the_type[] = { "EXAMINE" };
  MFString type; type.set(1, (SFString*)the_type);
  node->interface[4]->assign(node, fieldValue(&type));
  return node;
}

static void scenegraph(void)
{
  SFNode* the_nodes[] = { node_16(), node_17() };
  sceneGraph->append(2, the_nodes);
}

static void routes(void)
{
}

void import(class world* world)
{
  sceneGraph = world->sceneGraph;
  namedNodes = &world->namedNodes;
  protos = &world->protos;
  master = (SFNode*)0;

  protodecls();
  scenegraph();
  routes();
}

