Skip to content

Commit 0956d9e

Browse files
committed
Add list builder node.
1 parent ae33da9 commit 0956d9e

7 files changed

Lines changed: 129 additions & 4 deletions

File tree

Sources/BuiltInNodes/BI_InputUINodes.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ NE::DynamicSerializationInfo IntegerIncrementedNode::serializationInfo (NE::Obje
2424
NE::DynamicSerializationInfo DoubleIncrementedNode::serializationInfo (NE::ObjectId ("{B697B7DE-7AB9-479D-8DBE-8D3CCB6E4F50}"), NE::ObjectVersion (1), DoubleIncrementedNode::CreateSerializableInstance);
2525
NE::DynamicSerializationInfo DoubleDistributedNode::serializationInfo (NE::ObjectId ("{DDD3DF7C-AEA5-4E1E-B48A-2A10EA3FC7EF}"), NE::ObjectVersion (1), DoubleDistributedNode::CreateSerializableInstance);
2626

27+
NE::DynamicSerializationInfo ListBuilderNode::serializationInfo (NE::ObjectId ("{FE9C19DE-4847-458D-8F2D-5D943E7CF8AF}"), NE::ObjectVersion (1), ListBuilderNode::CreateSerializableInstance);
28+
2729
template <typename NodeType>
2830
class MinValueIntegerParameter : public NUIE::SlotDefaultValueNodeParameter<NodeType, NE::IntValue>
2931
{
@@ -737,4 +739,55 @@ NE::Stream::Status DoubleDistributedNode::Write (NE::OutputStream& outputStream)
737739
return outputStream.GetStatus ();
738740
}
739741

742+
ListBuilderNode::ListBuilderNode () :
743+
ListBuilderNode (std::wstring (), NUIE::Point ())
744+
{
745+
746+
}
747+
748+
ListBuilderNode::ListBuilderNode (const std::wstring& name, const NUIE::Point& position) :
749+
BasicUINode (name, position)
750+
{
751+
752+
}
753+
754+
ListBuilderNode::~ListBuilderNode ()
755+
{
756+
757+
}
758+
759+
void ListBuilderNode::Initialize ()
760+
{
761+
RegisterUIInputSlot (NUIE::UIInputSlotPtr (new NUIE::UIInputSlot (NE::SlotId ("in"), NE::Localize (L"Input"), nullptr, NE::OutputSlotConnectionMode::Multiple)));
762+
RegisterUIOutputSlot (NUIE::UIOutputSlotPtr (new NUIE::UIOutputSlot (NE::SlotId ("out"), NE::Localize (L"Output"))));
763+
}
764+
765+
NE::ValueConstPtr ListBuilderNode::Calculate (NE::EvaluationEnv& env) const
766+
{
767+
NE::ValueConstPtr in = EvaluateInputSlot (NE::SlotId ("in"), env);
768+
if (in == nullptr) {
769+
return nullptr;
770+
}
771+
772+
NE::ListValuePtr list (new NE::ListValue ());
773+
NE::FlatEnumerate (in, [&] (const NE::ValueConstPtr& innerVal) {
774+
list->Push (innerVal);
775+
});
776+
return list;
777+
}
778+
779+
NE::Stream::Status ListBuilderNode::Read (NE::InputStream& inputStream)
780+
{
781+
NE::ObjectHeader header (inputStream);
782+
BasicUINode::Read (inputStream);
783+
return inputStream.GetStatus ();
784+
}
785+
786+
NE::Stream::Status ListBuilderNode::Write (NE::OutputStream& outputStream) const
787+
{
788+
NE::ObjectHeader header (outputStream, serializationInfo);
789+
BasicUINode::Write (outputStream);
790+
return outputStream.GetStatus ();
791+
}
792+
740793
}

Sources/BuiltInNodes/BI_InputUINodes.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ class DoubleDistributedNode : public NumericRangeNode
188188
virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override;
189189
};
190190

191+
class ListBuilderNode : public BasicUINode
192+
{
193+
DYNAMIC_SERIALIZABLE (ListBuilderNode);
194+
195+
public:
196+
ListBuilderNode ();
197+
ListBuilderNode (const std::wstring& name, const NUIE::Point& position);
198+
virtual ~ListBuilderNode ();
199+
200+
virtual void Initialize () override;
201+
virtual NE::ValueConstPtr Calculate (NE::EvaluationEnv& env) const override;
202+
203+
virtual NE::Stream::Status Read (NE::InputStream& inputStream) override;
204+
virtual NE::Stream::Status Write (NE::OutputStream& outputStream) const override;
205+
};
206+
191207
}
192208

193209
#endif

Sources/BuiltInNodes/BI_ViewerUINodes.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ void MultiLineViewerNode::UpdateNodeDrawingImage (NUIE::NodeUIDrawingEnvironment
112112
if (HasCalculatedValue ()) {
113113
NE::ValueConstPtr nodeValue = GetCalculatedValue ();
114114
if (nodeValue != nullptr) {
115-
NE::IListValueConstPtr listValue = NE::CreateListValue (nodeValue);
116-
nodeTexts.clear ();
117-
listValue->Enumerate ([&] (const NE::ValueConstPtr& value) {
118-
nodeTexts.push_back (value->ToString (env.GetStringSettings ()));
115+
NE::FlatEnumerate (nodeValue, [&] (const NE::ValueConstPtr& value) {
116+
if (value != nullptr) {
117+
nodeTexts.push_back (value->ToString (env.GetStringSettings ()));
118+
} else {
119+
nodeTexts.push_back (NE::Localize (L"<empty>"));
120+
}
119121
});
120122
}
121123
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "SimpleTest.hpp"
2+
#include "NUIE_NodeUIManager.hpp"
3+
#include "BI_InputUINodes.hpp"
4+
5+
using namespace NE;
6+
using namespace NUIE;
7+
using namespace BI;
8+
9+
namespace InputNodesTest
10+
{
11+
12+
TEST (TestListBuilderNode)
13+
{
14+
NodeUIManager uiManager;
15+
16+
UINodePtr intNode = uiManager.AddNode (UINodePtr (new IntegerUpDownNode (L"Value1", Point (0, 0), 1, 1)), EmptyEvaluationEnv);
17+
UINodePtr intIncNode = uiManager.AddNode (UINodePtr (new IntegerIncrementedNode (L"Value2", Point (0, 0))), EmptyEvaluationEnv);
18+
UINodePtr listBuilder = uiManager.AddNode (UINodePtr (new ListBuilderNode (L"List Builder", Point (0, 0))), EmptyEvaluationEnv);
19+
20+
{
21+
ValueConstPtr val = listBuilder->Evaluate (EmptyEvaluationEnv);
22+
ASSERT (val == nullptr);
23+
}
24+
25+
uiManager.ConnectOutputSlotToInputSlot (intNode->GetUIOutputSlot (SlotId ("out")), listBuilder->GetUIInputSlot (SlotId ("in")));
26+
{
27+
ValueConstPtr val = listBuilder->Evaluate (EmptyEvaluationEnv);
28+
ASSERT (val != nullptr);
29+
ASSERT (IsComplexType<IntValue> (val));
30+
ASSERT (Value::IsType<ListValue> (val));
31+
ASSERT (Value::Cast<ListValue> (val)->GetSize () == 1);
32+
}
33+
34+
uiManager.ConnectOutputSlotToInputSlot (intIncNode->GetUIOutputSlot (SlotId ("out")), listBuilder->GetUIInputSlot (SlotId ("in")));
35+
{
36+
ValueConstPtr val = listBuilder->Evaluate (EmptyEvaluationEnv);
37+
ASSERT (val != nullptr);
38+
ASSERT (IsComplexType<IntValue> (val));
39+
ASSERT (Value::IsType<ListValue> (val));
40+
ASSERT (Value::Cast<ListValue> (val)->GetSize () == 11);
41+
}
42+
}
43+
44+
}

Sources/WindowsEmbeddingDemo/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class MyNodeUIEnvironment : public NUIE::NodeUIEnvironment
5050
nodeTree.AddItem (L"Input Nodes", L"Number Distribution", [&] (const NUIE::Point& position) {
5151
return NUIE::UINodePtr (new BI::DoubleDistributedNode (L"Number Distribution", position));
5252
});
53+
nodeTree.AddItem (L"Input Nodes", L"List Builder", [&] (const NUIE::Point& position) {
54+
return NUIE::UINodePtr (new BI::ListBuilderNode (L"List Builder", position));
55+
});
5356
nodeTree.AddItem (L"Arithmetic Nodes", L"Addition", [&] (const NUIE::Point& position) {
5457
return NUIE::UINodePtr (new BI::AdditionNode (L"Addition", position));
5558
});

Sources/WindowsEmbeddingDemo2/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ LRESULT CALLBACK ApplicationWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPAR
6464
nodeTree.AddItem (L"Input Nodes", L"Number Distribution", [&] (const NUIE::Point& position) {
6565
return NUIE::UINodePtr (new BI::DoubleDistributedNode (L"Number Distribution", position));
6666
});
67+
nodeTree.AddItem (L"Input Nodes", L"List Builder", [&] (const NUIE::Point& position) {
68+
return NUIE::UINodePtr (new BI::ListBuilderNode (L"List Builder", position));
69+
});
6770
nodeTree.AddItem (L"Arithmetic Nodes", L"Addition", [&] (const NUIE::Point& position) {
6871
return NUIE::UINodePtr (new BI::AdditionNode (L"Addition", position));
6972
});

Sources/wxWidgetsTestApp/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class MyCreateNodeCommand : public BI::CreateNodeCommand
5858
IntegerIncrement,
5959
NumberIncrement,
6060
NumberDistribution,
61+
ListBuilder,
6162
Addition,
6263
Subtraction,
6364
Multiplication,
@@ -92,6 +93,8 @@ class MyCreateNodeCommand : public BI::CreateNodeCommand
9293
return NUIE::UINodePtr (new BI::DoubleIncrementedNode (L"Number Increment", modelPosition));
9394
case NodeType::NumberDistribution:
9495
return NUIE::UINodePtr (new BI::DoubleDistributedNode (L"Number Distribution", modelPosition));
96+
case NodeType::ListBuilder:
97+
return NUIE::UINodePtr (new BI::ListBuilderNode (L"List Builder", modelPosition));
9598
case NodeType::Addition:
9699
return NUIE::UINodePtr (new BI::AdditionNode (L"Addition", modelPosition));
97100
case NodeType::Subtraction:
@@ -141,6 +144,7 @@ class MyNodeEditorEventHandlers : public WXAS::NodeEditorEventHandlers
141144
inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (MyCreateNodeCommand::NodeType::IntegerIncrement, uiManager, uiEnvironment, L"Integer Increment", position)));
142145
inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (MyCreateNodeCommand::NodeType::NumberIncrement, uiManager, uiEnvironment, L"Number Increment", position)));
143146
inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (MyCreateNodeCommand::NodeType::NumberDistribution, uiManager, uiEnvironment, L"Number Distribution", position)));
147+
inputCommandGroup->AddChildCommand (NUIE::MenuCommandPtr (new MyCreateNodeCommand (MyCreateNodeCommand::NodeType::ListBuilder, uiManager, uiEnvironment, L"List Builder", position)));
144148
createCommandGroup->AddChildCommand (inputCommandGroup);
145149

146150
NUIE::GroupMenuCommandPtr arithmeticCommandGroup (new NUIE::GroupMenuCommand (L"Arithmetic Nodes"));

0 commit comments

Comments
 (0)