Ocean
X3DNode.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_SCENEDESCRIPTION_SDX_X3D_X3D_NODE_H
9 #define META_OCEAN_SCENEDESCRIPTION_SDX_X3D_X3D_NODE_H
10 
12 
13 #include "ocean/base/Callback.h"
14 
18 
19 #include <map>
20 
21 namespace Ocean
22 {
23 
24 namespace SceneDescription
25 {
26 
27 namespace SDX
28 {
29 
30 namespace X3D
31 {
32 
33 // Forward declaration.
34 class X3DNode;
35 
36 /**
37  * Definition of a smart object reference for abstract X3D nodes.
38  * @see X3DNode, Node.
39  * @ingroup scenedescription
40  */
42 
43 /**
44  * This class implements an abstract x3d node.
45  * @ingroup scenedescriptionsdxx3d
46  */
47 class OCEAN_SCENEDESCRIPTION_SDX_X3D_EXPORT X3DNode : virtual public SDXNode
48 {
49  protected:
50 
51  /**
52  * Definition of a node and field pair.
53  */
54  typedef std::pair<NodeId, std::string> ReceiverPair;
55 
56  /**
57  * Definition of a map mapping field names to field receiver pairs.
58  */
59  typedef std::multimap<std::string, ReceiverPair> FieldConnectionMap;
60 
61  public:
62 
63  /**
64  * Sets or changes a specified field of this node.
65  * @see SDXNode::setField().
66  */
67  bool setField(const std::string& fieldName, const Field& field) override;
68 
69  /**
70  * Adds a field connection for a specified field starting at this node.
71  * @param outputField Name of the output field
72  * @param inputNode Id of the input node
73  * @param inputField Name of the input field
74  * @return True, if the connection has not been added before
75  */
76  bool addConnection(const std::string& outputField, const NodeId inputNode, const std::string& inputField);
77 
78  /**
79  * Tries to translate an alias field name to the original field name.
80  * @see Node::originalFieldName().
81  */
82  std::string originalFieldName(const std::string& fieldName) const override;
83 
84  protected:
85 
86  /**
87  * Creates a new abstract x3d node.
88  * @param environment Node environment
89  */
90  explicit X3DNode(const SDXEnvironment* environment);
91 
92  /**
93  * Registers the fields of this node.
94  * @param specification Node specification receiving the field informations
95  */
96  void registerFields(NodeSpecification& specification);
97 
98  /**
99  * Explicit changing event function for node fields.
100  * All node fields will be informed on field changes by this event function only.<br>
101  * The new field value has to be handles explicitly!<br>
102  * Values fields have a different event function.
103  * @param fieldName Name of the field to be changed
104  * @param field Field holding the new value and timestamp
105  * @return True, if the field value has been accepted
106  * @see onFieldChanged().
107  */
108  virtual bool onFieldChanging(const std::string& fieldName, const Field& field);
109 
110  /**
111  * Informs connected nodes that a field of this node has been changed.
112  * @param fieldName Name of this node field which has been changed
113  * @param field Field of this node which has been changed
114  */
115  void forwardThatFieldHasBeenChanged(const std::string& fieldName, const Field& field);
116 
117  protected:
118 
119  /// Metadata field.
121 
122  /// Map holding all field connections.
124 };
125 
126 }
127 
128 }
129 
130 }
131 
132 }
133 
134 #endif // META_OCEAN_SCENEDESCRIPTION_SDX_X3D_X3D_NODE_H
This class is the base class for all scene description fields.
Definition: Field.h:36
This class implements a node specification object.
Definition: scenedescription/Node.h:77
This class implements an abstract x3d node.
Definition: X3DNode.h:48
std::pair< NodeId, std::string > ReceiverPair
Definition of a node and field pair.
Definition: X3DNode.h:54
std::string originalFieldName(const std::string &fieldName) const override
Tries to translate an alias field name to the original field name.
void registerFields(NodeSpecification &specification)
Registers the fields of this node.
SingleNode metadata_
Metadata field.
Definition: X3DNode.h:120
void forwardThatFieldHasBeenChanged(const std::string &fieldName, const Field &field)
Informs connected nodes that a field of this node has been changed.
bool addConnection(const std::string &outputField, const NodeId inputNode, const std::string &inputField)
Adds a field connection for a specified field starting at this node.
virtual bool onFieldChanging(const std::string &fieldName, const Field &field)
Explicit changing event function for node fields.
bool setField(const std::string &fieldName, const Field &field) override
Sets or changes a specified field of this node.
std::multimap< std::string, ReceiverPair > FieldConnectionMap
Definition of a map mapping field names to field receiver pairs.
Definition: X3DNode.h:59
FieldConnectionMap fieldConnections_
Map holding all field connections.
Definition: X3DNode.h:123
X3DNode(const SDXEnvironment *environment)
Creates a new abstract x3d node.
This class implements a node environment container.
Definition: SDXNode.h:62
This class implements the base class for all SDX scene description nodes.
Definition: SDXNode.h:50
This template class implements a smart object reference which is a specialization of an ObjectRef obj...
Definition: SmartObjectRef.h:90
SmartObjectRef< X3DNode, Node > X3DNodeRef
Definition of a smart object reference for abstract X3D nodes.
Definition: X3DNode.h:34
size_t NodeId
Definition of a object id.
Definition: SceneDescription.h:41
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15