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