AuboStudio SDK  0.6.3
tree_node.h
浏览该文件的文档.
1#ifndef AUBO_SCOPE_TREE_NODE_H
2#define AUBO_SCOPE_TREE_NODE_H
3
4#include <vector>
5#include <functional>
7
8namespace arcs {
9namespace aubo_scope {
11
12/**
13 * \chinese
14 * 树节点
15 * 此接口表示程序树中的一个节点,可用于构建以 AuboCap 程序节点为根的子树。
16 *
17 * 使用 {@link ProgramModel#getRootTreeNode(ProgramNodeContribution)} 获取子树
18 * 的根节点后,即可添加子节点。每次调用 {@link TreeNode#addChild(ProgramNode)}
19 * 都会返回一个新的 {@link TreeNode},该节点又可以作为另一个子树的根节点。
20 * \endchinese
21 * \english
22 * TreeNode
23 * This interface represents a node in the program tree that can be used to
24 * construct a sub-tree rooted in a AuboCap program node.
25 *
26 * Using the {@link ProgramModel#getRootTreeNode(ProgramNodeContribution)} to
27 * obtain a root for the sub-tree, it is possible to add children. For each call
28 * to {@link TreeNode#addChild(ProgramNode)}, a new {@link TreeNode} is
29 * returned, that can, in turn, act as a root for yet another sub-tree.
30 * \endenglish
31 */
33{
34public:
37 virtual ~TreeNode();
38
39 /**
40 * \chinese
41 * 向子树添加一个子程序节点。
42 *
43 * @param program_node 使用 ProgramNodeFactory 构建的 ProgramNode
44 * @return 返回一个 TreeNode,可用于向新添加的子节点添加子节点。
45 * @throws TreeStructureException 如果不允许在此位置插入 ProgramNode
46 * @throws IllegalStateException 如果在 UndoableChanges 范围外从基于 Qt 的
47 * AuboCap 调用
48 * \endchinese
49 * \english
50 * Add a child program node to the sub-tree.
51 *
52 * @param program_node the {@link ProgramNode} constructed using the {@link
53 * ProgramNodeFactory}
54 * @return Returns a TreeNode that can be used to add children to the newly
55 * added child.
56 * @throws TreeStructureException If it is not allowed to insert the {@link
57 * ProgramNode} at this position a
58 * {@link TreeStructureException} will be thrown.
59 * @throws IllegalStateException if called from a Qt-based AuboCap
60 * outside of an {@link UndoableChanges} scope (see also {@link
61 * UndoRedoManager}).
62 * \endenglish
63 */
64 TreeNodePtr addChild(ProgramNodePtr program_node);
65
66 /**
67 * \chinese
68 * 在子树中,在现有选中子节点之前插入一个子程序节点。将选中子节点及其后的节点
69 * 移到新添加子节点之后的位置。
70 *
71 * @param existingChildNode 此 TreeNode 的现有 TreeNode 子节点
72 * @param program_node 使用 ProgramNodeFactory 构建的 ProgramNode
73 * @return 返回一个 TreeNode,可用于向新添加的子节点添加子节点。
74 * @throws TreeStructureException 如果不允许在此位置插入或选中子节点不是
75 * 此 TreeNode 的子节点
76 * @throws IllegalStateException 如果在 UndoableChanges 范围外调用
77 * \endchinese
78 * \english
79 * Inserts a child program node in the sub-tree directly before the existing
80 * selected child node. Shifts the selected child node and any subsequent
81 * nodes to positions after the newly added child.
82 *
83 * @param existingChildNode existing TreeNode child of this TreeNode.
84 * @param program_node the {@link ProgramNode} constructed using the {@link
85 * ProgramNodeFactory}.
86 * @return Returns a TreeNode that can be used to add children to the newly
87 * added child.
88 * @throws TreeStructureException If it is not allowed to insert the {@link
89 * ProgramNode} at this position or if the selected child node is not a
90 * child of this TreeNode a {@link TreeStructureException} will be thrown.
91 * @throws IllegalStateException if called from a Qt-based AuboCap
92 * outside of an {@link UndoableChanges} scope (see also {@link
93 * UndoRedoManager}).
94 * \endenglish
95 */
96 TreeNodePtr insertChildBefore(TreeNodePtr existingChildNode,
97 ProgramNodePtr program_node);
98
99 /**
100 * \chinese
101 * 在子树中,在现有选中子节点之后插入一个子程序节点。将后续节点移到新添加
102 * 子节点之后的位置。
103 *
104 * @param existingChildNode 此 TreeNode 的现有 TreeNode 子节点
105 * @param program_node 使用 ProgramNodeFactory 构建的 ProgramNode
106 * @return 返回一个 TreeNode,可用于向新添加的子节点添加子节点。
107 * @throws TreeStructureException 如果不允许在此位置插入或选中子节点不是
108 * 此 TreeNode 的子节点
109 * @throws IllegalStateException 如果在 UndoableChanges 范围外调用
110 * \endchinese
111 * \english
112 * Inserts a child program node under in the sub-tree directly after the
113 * existing selected child node. Shifts any subsequent nodes to positions
114 * after the newly added child.
115 *
116 * @param existingChildNode existing TreeNode child of this TreeNode.
117 * @param program_node the {@link ProgramNode} constructed using the {@link
118 * ProgramNodeFactory}.
119 * @return Returns a TreeNode that can be used to add children to the newly
120 * added child.
121 * @throws TreeStructureException If it is not allowed to insert the {@link
122 * ProgramNode} at this position or if the selected child node is not a
123 * child of this TreeNode a {@link TreeStructureException} will be thrown.
124 * @throws IllegalStateException if called from a Qt-based AuboCap
125 * outside of an {@link UndoableChanges} scope (see also {@link
126 * UndoRedoManager}).
127 * \endenglish
128 */
129 TreeNodePtr insertChildAfter(TreeNodePtr existingChildNode,
130 ProgramNodePtr program_node);
131
132 /**
133 * \chinese
134 * 剪切子树中的一个子程序节点。
135 *
136 * @param child 此 TreeNode 的现有 TreeNode 子节点
137 * @return 返回被剪切掉的 TreeNode
138 * @throws TreeStructureException 如果不允许剪切此 ProgramNode 或子节点不是
139 * 此 TreeNode 的子节点
140 * @throws IllegalStateException 如果在 UndoableChanges 范围外调用
141 * \endchinese
142 * \english
143 * Cut a child program node under in the sub-tree directly after the
144 * existing selected child node. Shifts any subsequent nodes to positions
145 * after the newly added child.
146 *
147 * @param child existing TreeNode child of this TreeNode.
148 * @return Returns the TreeNode that has been cut off.
149 * @throws TreeStructureException If it is not allowed to cut the {@link
150 * ProgramNode} or if the selected child node is not a child of this
151 * TreeNode a {@link TreeStructureException} will be thrown.
152 * @throws IllegalStateException if called from a Qt-based AuboCap
153 * outside of an {@link UndoableChanges} scope (see also {@link
154 * UndoRedoManager}).
155 * \endenglish
156 */
157 TreeNodePtr cutChildNode(TreeNodePtr child);
158
159 /**
160 * \chinese
161 * 从子树中移除子节点。注意:移除最后一个子节点将触发插入一个
162 * {@literal <empty>} 子节点。
163 *
164 * @param program_node 要移除的 TreeNode 子节点
165 * @return 成功移除返回 <code>true</code>,否则返回 <code>false</code>
166 * @throws TreeStructureException 如果移除子节点会使树处于非法状态
167 * @throws IllegalStateException 如果在 UndoableChanges 范围外调用
168 * \endchinese
169 * \english
170 * Removes a child node from the sub-tree. Be aware that removing the last
171 * child will trigger the insertion of an
172 * {@literal <empty>} child node.
173 *
174 * @param program_node The TreeNode child to be removed.
175 * @return Returns <code>true</code> if removed successfully.
176 * <code>false</code> otherwise.
177 * @throws TreeStructureException If the removed child would leave the tree
178 * in an illegal state a
179 * {@link TreeStructureException} will be thrown.
180 * @throws IllegalStateException if called from a Qt-based AuboCap
181 * outside of an {@link UndoableChanges} scope (see also {@link
182 * UndoRedoManager}).
183 * \endenglish
184 */
185 bool removeChild(TreeNodePtr program_node);
186
187 /**
188 * \chinese
189 * @return TreeNode 对象列表,表示此 TreeNode 的所有子节点(包括以编程方式
190 * 添加的和终端用户插入的)
191 * \endchinese
192 * \english
193 * @return a list of <code>TreeNode</code> objects that represents all the
194 * children of this <code>TreeNode</code> (both programmatically added as
195 * well as inserted by the end user).
196 * \endenglish
197 */
198 std::vector<TreeNodePtr> getChildren();
199
200 std::vector<TreeNodePtr> getChildrenNotSuppressed();
201
202 /**
203 * \chinese
204 * @return 节点的父 TreeNode
205 * \endchinese
206 * \english
207 * @return Parent treenode of the node
208 * \endenglish
209 */
210 TreeNodePtr getParent();
211
212 /**
213 * \chinese
214 * @return 返回子树中此位置的 ProgramNode。可以是内置 AuboScope 程序节点
215 * 或 AuboCap 程序节点。
216 * \endchinese
217 * \english
218 * @return Returns the {@link ProgramNode} at this position in the sub-tree.
219 * Can either be a built-in AuboScope program node (provided by AUBO
220 * Robots) or a AuboCap program node.
221 * \endenglish
222 */
223 ProgramNodePtr getProgramNode();
225
226 /**
227 * \chinese
228 * 节点是否在程序树中;不在程序树中的节点可能已被剪切或删除。
229 *
230 * @return <code>true</code> 节点在程序树中,
231 * <code>false</code> 节点不在程序树中(可能已被剪切或删除)
232 * \endchinese
233 * \english
234 * Whether the node is in the program tree; nodes not in the program tree
235 * may have been cut or deleted.
236 *
237 * @return Returns <code>true</code> The node is in the program tree.
238 * <code>false</code> The node is not in the program tree; such nodes may
239 * have been cut or deleted.
240 * \endenglish
241 */
243
244 /**
245 * \chinese
246 * <p>获取此 TreeNode 下子树中子程序节点(ProgramNode 实例)对应的 TreeNode
247 * 实例。</p>
248 * 此方法可用于在遍历父节点子树时,获取遇到子程序节点下的子树访问权限。
249 *
250 * @param program_node 需要获取对应 TreeNode 表示的程序节点,不能为
251 * <code>null</code>
252 * @return 指定程序节点的 TreeNode 实例
253 * @throws ProgramNodeNotInSubTreeException 当程序节点不在子树中时
254 * \endchinese
255 * \english
256 * <p>
257 * Gets a corresponding {@link TreeNode} instance for a child program node
258 * (a {@link ProgramNode} instance) in the sub-tree under this {@link
259 * TreeNode}.
260 * </p>
261 * This method can for instance be used to gain access to the sub-tree under
262 * a child program node encountered when iterating the sub-tree of the
263 * parent node using the {@link ProgramNodeVisitor} (or any derived sub
264 * class thereof).
265 *
266 * @param program_node program node to get a corresponding {@link TreeNode}
267 * representation for, not <code>null</code>. Can either be a built-in
268 * AuboScope program node (provided by AUBO Robots) or a AuboCap
269 * program node.
270 * @return the <code>TreeNode</code> instance for the specified program
271 * node.
272 * @throws ProgramNodeNotInSubTreeException when the program node cannot be
273 * found because it is not in the sub-tree.
274 * \endenglish
275 */
276 TreeNodePtr locateDescendantTreeNode(ProgramNodePtr program_node);
277
278 /**
279 * \chinese
280 * 配置子节点是否可被终端用户重新排列、删除或将其他节点插入到子节点序列中。
281 *
282 * @param isChildSequenceLocked 如果为 <code>true</code>,则此
283 * TreeNode 下的直接子节点将被锁定
284 * \endchinese
285 * \english
286 * Configures whether or not child nodes can be rearranged, deleted or have
287 * other nodes inserted into the child sequence by the end user.
288 *
289 * @param isChildSequenceLocked If <code>true</code> then the immediate
290 * children under this <code>TreeNode</code> will be locked.
291 * \endenglish
292 */
293 void setChildSequenceLocked(bool isChildSequenceLocked);
294
295 /**
296 * \chinese
297 * <p>此方法以深度优先方式遍历此树节点下的整个子树(对应于程序树中的自顶向下方式)。</p>
298 * <p>使用节点访问器进行回调,回调的重载取决于遇到的节点类型。</p>
299 * <p>所有 visit 方法都具有程序节点、兄弟索引和深度作为参数,以便在需要时过滤节点。</p>
300 *
301 * @param nodeVisitor 回调实例
302 * @return 0 表示正常退出,非零表示异常或错误导致提前退出
303 * \endchinese
304 * \english
305 * <p>
306 * This method traverses the entire sub-tree under this tree node in a
307 * depth-first fashion (this corresponds to a top-down approach in the
308 * program tree).
309 * </p>
310 * <p>
311 * A node visitor is used for callbacks to the visit-overloads you choose to
312 * override. The overload called depends on the node type encountered.
313 * Override the overloads for the node types you are concerned with. All
314 * visit-methods have the program node, sibling index and depth as arguments
315 * to help filter nodes if needed.
316 * </p>
317 * <p>
318 * The node visitor can be either a {@link ProgramNodeVisitor}
319 * implementation with optional overrides or a
320 * {@link ProgramNodeInterfaceVisitor} implementation. In the latter
321 * case, the
322 * {@link ProgramNodeInterfaceVisitor#visitAs(Object, int, int)}
323 * method must be implemented.
324 * </p>
325 * <p>
326 * The {@link ProgramNodeInterfaceVisitor} can be used when targeting
327 * AuboCap program nodes implementing the (generic) type parameter specified
328 * in {@link ProgramNodeInterfaceVisitor} (see also
329 * {@link ProgramNode#getAs(Class)}).
330 * </p>
331 * Note that this method is sometimes called <code>accept()</code> in the
332 * Visitor software design pattern.
333 *
334 * @param nodeVisitor the instance callbacks are made to.
335 * @return 0 for normal exit.
336 * non-zero for exception or error causing premature exit.
337 * \endenglish
338 */
339 int traverse(std::function<int(ProgramNodePtr, int, int)> nodeVisitor);
340
341private:
342 friend class DataSwitch;
344 void *d_{ nullptr };
345};
346
347} // namespace aubo_scope
348} // namespace arcs
349#endif // AUBO_SCOPE_TREE_NODE_H
#define ARCS_ABI_EXPORT
#define ARCS_CLASS_FORWARD(C)
Macro that forward declares a class and defines the respective smartpointers through ARCS_DECLARE_PTR...
\chinese 树节点 此接口表示程序树中的一个节点,可用于构建以 AuboCap 程序节点为根的子树。
std::vector< TreeNodePtr > getChildren()
\chinese
TreeNodePtr getParent()
\chinese
int traverse(std::function< int(ProgramNodePtr, int, int)> nodeVisitor)
\chinese
TreeNodePtr addChild(ProgramNodePtr program_node)
\chinese 向子树添加一个子程序节点。
TreeNodePtr insertChildBefore(TreeNodePtr existingChildNode, ProgramNodePtr program_node)
\chinese 在子树中,在现有选中子节点之前插入一个子程序节点。将选中子节点及其后的节点 移到新添加子节点之后的位置。
bool isInProgramTree()
\chinese 节点是否在程序树中;不在程序树中的节点可能已被剪切或删除。
void setChildSequenceLocked(bool isChildSequenceLocked)
\chinese 配置子节点是否可被终端用户重新排列、删除或将其他节点插入到子节点序列中。
TreeNodePtr insertChildAfter(TreeNodePtr existingChildNode, ProgramNodePtr program_node)
\chinese 在子树中,在现有选中子节点之后插入一个子程序节点。将后续节点移到新添加 子节点之后的位置。
ProgramNodePtr getProgramNode()
\chinese
TreeNodePtr locateDescendantTreeNode(ProgramNodePtr program_node)
\chinese
std::vector< TreeNodePtr > getChildrenNotSuppressed()
bool removeChild(TreeNodePtr program_node)
\chinese 从子树中移除子节点。注意:移除最后一个子节点将触发插入一个 <empty> 子节点。
TreeNodePtr cutChildNode(TreeNodePtr child)
\chinese 剪切子树中的一个子程序节点。