PeriDyno 1.0.0
Loading...
Searching...
No Matches
WSceneDataModel.cpp
Go to the documentation of this file.
1#include "WSceneDataModel.h"
2#include <SceneGraph.h>
3
4
9
10void WNodeDataModel::setScene(std::shared_ptr<dyno::SceneGraph> scene)
11{
12 mScene = scene;
13
14 layoutAboutToBeChanged().emit();
15
16 for (NodeItem* item : mNodeList)
17 delete item;
18 mNodeList.clear();
19
20 if (mScene)
21 {
22 for (auto node = scene->begin(); node != scene->end(); node++)
23 {
24 NodeItem* item = new NodeItem;
25 item->id = mNodeList.size();
26 item->ref = node.get();
27 item->parent = 0;
28 mNodeList.push_back(item);
29 }
30 }
31 layoutChanged().emit();
32}
33
34
35Wt::WModelIndex WNodeDataModel::parent(const Wt::WModelIndex& index) const
36{
37 return Wt::WModelIndex();
38}
39
40Wt::WModelIndex WNodeDataModel::index(int row, int column, const Wt::WModelIndex& parent) const
41{
42 if (parent.isValid())
43 {
44 return Wt::WModelIndex();
45 }
46 return createIndex(row, column, row);
47}
48
49int WNodeDataModel::columnCount(const Wt::WModelIndex& parent) const
50{
51 return 2;
52}
53
54int WNodeDataModel::rowCount(const Wt::WModelIndex& parent) const
55{
56 if (parent.isValid())
57 return 0;
58 return mNodeList.size();
59}
60
61Wt::cpp17::any WNodeDataModel::data(const Wt::WModelIndex& index, Wt::ItemDataRole role) const
62{
63 if (index.isValid())
64 {
65 auto node = mNodeList[index.internalId()]->ref;
66
67 if (role == Wt::ItemDataRole::Display || role == Wt::ItemDataRole::ToolTip)
68 {
69 if (index.column() == 0)
70 {
71 return node->getName();
72 }
73 if (index.column() == 1)
74 {
75 return node->getClassInfo()->getClassName();
76 }
77 }
78 else if (role == Wt::ItemDataRole::Decoration)
79 {
80 if (index.column() == 0)
81 {
82 if (node->getName() == "cube")
83 {
84 return "icons/cube.png";
85 }
86 else if (node->getName() == "Mesh")
87 {
88 return "icons/mesh.png";
89 }
90 return std::string("icons/node.png");
91 }
92 }
93 }
94 return Wt::cpp17::any();
95}
96
97Wt::cpp17::any WNodeDataModel::headerData(int section, Wt::Orientation orientation, Wt::ItemDataRole role) const
98{
99 if (orientation == Wt::Orientation::Horizontal && role == Wt::ItemDataRole::Display) {
100 switch (section) {
101 case 0:
102 return std::string("Node");
103 case 1:
104 return std::string("Type");
105 default:
106 return Wt::cpp17::any();
107 }
108 }
109 else
110 return Wt::cpp17::any();
111}
112
113std::shared_ptr<dyno::Node> WNodeDataModel::getNode(const Wt::WModelIndex& index)
114{
115 return mNodeList[index.internalId()]->ref;
116}
117
118void WModuleDataModel::setNode(std::shared_ptr<dyno::Node> node)
119{
120 mNode = node;
121 layoutAboutToBeChanged().emit();
122 layoutChanged().emit();
123}
124
125int WModuleDataModel::columnCount(const Wt::WModelIndex& parent) const
126{
127 return 2;
128}
129
130int WModuleDataModel::rowCount(const Wt::WModelIndex& parent) const
131{
132 if (mNode != 0)
133 {
134 return mNode->getModuleList().size();
135 }
136 return 0;
137}
138
139Wt::cpp17::any WModuleDataModel::data(const Wt::WModelIndex& index, Wt::ItemDataRole role) const
140{
141 if (mNode != 0 && index.isValid())
142 {
143 auto mod = mNode->getModuleList();
144 auto iter = mod.begin();
145 std::advance(iter, index.row());
146
147 if (role == Wt::ItemDataRole::Display || role == Wt::ItemDataRole::ToolTip)
148 {
149 if (index.column() == 0)
150 {
151 return (*iter)->getName();
152 }
153 if (index.column() == 1)
154 {
155 return (*iter)->getModuleType();
156 }
157 }
158 else if (role == Wt::ItemDataRole::Decoration)
159 {
160 if (index.column() == 0)
161 {
162 return std::string("icons/module.png");
163 }
164 }
165 }
166 return Wt::cpp17::any();
167}
168
169
170Wt::cpp17::any WModuleDataModel::headerData(int section, Wt::Orientation orientation, Wt::ItemDataRole role) const
171{
172 if (orientation == Wt::Orientation::Horizontal && role == Wt::ItemDataRole::Display) {
173 switch (section) {
174 case 0:
175 return std::string("Module");
176 case 1:
177 return std::string("Type");
178 default:
179 return Wt::cpp17::any();
180 }
181 }
182 else
183 return Wt::cpp17::any();
184}
185
186std::shared_ptr<dyno::Module> WModuleDataModel::getModule(const Wt::WModelIndex& index)
187{
188 if (mNode != 0 && index.isValid())
189 {
190 auto mod = mNode->getModuleList();
191 auto iter = mod.begin();
192 std::advance(iter, index.row());
193 return *iter;
194 }
195 return std::shared_ptr<dyno::Module>();
196}
197
198
void setNode(std::shared_ptr< dyno::Node > node)
virtual Wt::cpp17::any headerData(int section, Wt::Orientation orientation=Wt::Orientation::Horizontal, Wt::ItemDataRole role=Wt::ItemDataRole::Display) const
virtual int columnCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
std::shared_ptr< dyno::Module > getModule(const Wt::WModelIndex &index)
std::shared_ptr< dyno::Node > mNode
virtual int rowCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
virtual Wt::cpp17::any data(const Wt::WModelIndex &index, Wt::ItemDataRole role=Wt::ItemDataRole::Display) const
void setScene(std::shared_ptr< dyno::SceneGraph > scene)
virtual Wt::WModelIndex index(int row, int column, const Wt::WModelIndex &parent=Wt::WModelIndex()) const
std::vector< NodeItem * > mNodeList
std::shared_ptr< dyno::SceneGraph > mScene
virtual int rowCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
virtual int columnCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
virtual Wt::WModelIndex parent(const Wt::WModelIndex &index) const
virtual Wt::cpp17::any headerData(int section, Wt::Orientation orientation=Wt::Orientation::Horizontal, Wt::ItemDataRole role=Wt::ItemDataRole::Display) const
std::shared_ptr< dyno::Node > getNode(const Wt::WModelIndex &index)
virtual Wt::cpp17::any data(const Wt::WModelIndex &index, Wt::ItemDataRole role=Wt::ItemDataRole::Display) const
std::shared_ptr< dyno::Node > ref