00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #include <archon/x3d/server/field_type.H>
00027 #include <archon/x3d/server/field.H>
00028 #include <archon/x3d/server/scene.H>
00029
00030 namespace Archon
00031 {
00032 namespace X3D
00033 {
00034 const NodeType *BoundedObject::type = 0;
00035
00036 const NodeType *GroupingNode::type = 0;
00037 const NodeSequenceFieldBase *GroupingNode::childrenField = 0;
00038
00039 const NodeType *Group::type = 0;
00040 const NodeType *Switch::type = 0;
00041 const NodeType *Transform::type = 0;
00042
00043
00050 void initializeGroupComponent()
00051 {
00052 vector<const FieldBase *> fields;
00053
00054
00055
00056
00057 fields.push_back(newPrivateField("bboxCenter", SFVec3f::type,
00058 &BoundedObject::bboxCenter));
00059 fields.push_back(newPrivateField("bboxSize", SFVec3f::type,
00060 &BoundedObject::bboxSize));
00061 BoundedObject::type =
00062 NodeType::newAbstract("BoundedObject", false, &fields);
00063 fields.clear();
00064
00065
00066
00067
00068 fields.push_back(newEventIn("addChildren",
00069 &GroupingNode::addChildren,
00070 &GroupingNode::childrenStamp));
00071 fields.push_back(newEventIn("removeChildren",
00072 &GroupingNode::removeChildren,
00073 &GroupingNode::childrenStamp));
00074 GroupingNode::childrenField =
00075 newExposedField("children",
00076 &GroupingNode::children,
00077 &GroupingNode::childrenChanged,
00078 &GroupingNode::childrenStamp);
00079 fields.push_back(GroupingNode::childrenField);
00080 GroupingNode::type =
00081 NodeType::newAbstract("GroupingNode", false,
00082 &fields, ChildNode::type);
00083 fields.clear();
00084
00085
00086
00087
00088 Group::type =
00089 NodeType::newConcrete("Group", "children", Group::instantiate,
00090 0, GroupingNode::type, BoundedObject::type);
00091
00092
00093
00094
00095 fields.push_back(newExposedField("whichChoice", SFInt32::type,
00096 &Switch::whichChoice,
00097 &Switch::whichChoiceChanged,
00098 &Switch::whichChoiceStamp));
00099 Switch::type =
00100 NodeType::newConcrete("Switch", "children", Switch::instantiate,
00101 &fields, GroupingNode::type, BoundedObject::type);
00102 fields.clear();
00103
00104
00105
00106
00107 fields.push_back(newExposedField("center", SFVec3f::type,
00108 &Transform::center,
00109 &Transform::centerChanged,
00110 &Transform::centerStamp));
00111 fields.push_back(newExposedField("rotation", SFRotation::type,
00112 &Transform::rotation,
00113 &Transform::rotationChanged,
00114 &Transform::rotationStamp));
00115 fields.push_back(newExposedField("scale", SFVec3f::type,
00116 &Transform::scale,
00117 &Transform::scaleChanged,
00118 &Transform::scaleStamp));
00119 fields.push_back(newExposedField("scaleOrientation", SFRotation::type,
00120 &Transform::scaleOrientation,
00121 &Transform::scaleOrientationChanged,
00122 &Transform::scaleOrientationStamp));
00123 fields.push_back(newExposedField("translation", SFVec3f::type,
00124 &Transform::translation,
00125 &Transform::translationChanged,
00126 &Transform::translationStamp));
00127 Transform::type =
00128 NodeType::newConcrete("Transform", "children", Transform::instantiate,
00129 &fields, GroupingNode::type, BoundedObject::type);
00130 fields.clear();
00131 }
00132
00133 bool GroupingNode::addChildren(const vector<Ref<ChildNode> > &c, const Time &t)
00134 {
00135 for(unsigned i=0; i<c.size(); ++i)
00136 if(find(children.begin(), children.end(), c[i]) == children.end())
00137 children.push_back(c[i]);
00138 childrenStamp = t;
00139 Event event(childrenField->get(this), t);
00140 childrenChanged.cascadeEvent(&event);
00141 return true;
00142 }
00143
00144 bool GroupingNode::removeChildren(const vector<Ref<ChildNode> > &c, const Time &t)
00145 {
00146 for(unsigned i=0; i<c.size(); ++i)
00147 children.erase(std::remove(children.begin(), children.end(),
00148 c[i]), children.end());
00149 childrenStamp = t;
00150 Event event(childrenField->get(this), t);
00151 childrenChanged.cascadeEvent(&event);
00152 return true;
00153 }
00154 }
00155 }