34 auto ret = std::make_shared<QtDataModelRegistry>();
36 for (
auto const c : *classMap)
40 QString str = QString::fromStdString(c.first);
42 std::shared_ptr<dyno::Node> node(
dynamic_cast<dyno::Node*
>(obj));
46 QtDataModelRegistry::RegistryItemCreator creator = [str]() {
48 std::shared_ptr<dyno::Node> new_node(
dynamic_cast<dyno::Node*
>(node_obj));
49 auto dat = std::make_unique<QtNodeWidget>(std::move(new_node));
58 this->setRegistry(ret);
83 std::map<dyno::ObjectId, QtNode*> nodeMap;
89 auto addNodeWidget = [&](std::shared_ptr<Node> m) ->
void
91 auto mId = m->objectId();
93 auto type = std::make_unique<QtNodeWidget>(m);
95 auto& node = this->createNode(std::move(type));
99 QPointF posView(m->bx(), m->by());
101 node.nodeGraphicsObject().setPos(posView);
103 this->nodePlaced(node);
106 for (
auto it = scn->begin(); it != scn->end(); it++)
108 addNodeWidget(it.get());
111 auto createNodeConnections = [&](std::shared_ptr<Node> nd) ->
void
113 auto inId = nd->objectId();
115 if (nodeMap.find(inId) != nodeMap.end())
117 auto inBlock = nodeMap[nd->objectId()];
119 auto ports = nd->getImportNodes();
121 for (
int i = 0; i < ports.size(); i++)
126 auto node = ports[i]->getNodes()[0];
129 auto outId = node->objectId();
130 if (nodeMap.find(outId) != nodeMap.end())
132 auto outBlock = nodeMap[node->objectId()];
133 createConnection(*inBlock, i, *outBlock, 0);
141 auto& nodes = ports[i]->getNodes();
143 for (
int j = 0; j < nodes.size(); j++)
145 if (nodes[j] !=
nullptr)
147 auto outId = nodes[j]->objectId();
148 if (nodeMap.find(outId) != nodeMap.end())
150 auto outBlock = nodeMap[outId];
151 createConnection(*inBlock, i, *outBlock, 0);
159 auto fieldInp = nd->getInputFields();
160 for (
int i = 0; i < fieldInp.size(); i++)
162 auto fieldSrc = fieldInp[i]->getSource();
163 if (fieldSrc !=
nullptr) {
164 auto parSrc = fieldSrc->parent();
165 if (parSrc !=
nullptr)
171 if (nodeSrc ==
nullptr)
174 if (moduleSrc !=
nullptr)
178 if (nodeSrc !=
nullptr)
183 uint outFieldIndex = 0;
184 bool fieldFound =
false;
185 for (
auto f : fieldsOut)
195 if (nodeMap[outId]->nodeDataModel()->allowExported()) outFieldIndex++;
197 if (fieldFound && nodeMap.find(outId) != nodeMap.end())
199 auto outBlock = nodeMap[outId];
200 createConnection(*inBlock, i + ports.size(), *outBlock, outFieldIndex);
209 for (
auto it = scn->begin(); it != scn->end(); it++)
211 createNodeConnections(it.get());
270 std::cout << NodeName << std::endl;
273 std::shared_ptr<dyno::Node> new_node(
dynamic_cast<dyno::Node*
>(node_obj));
274 auto dat = std::make_unique<QtNodeWidget>(std::move(new_node));
276 if (dat !=
nullptr) {
278 scn->addNode(dat->getNode());
281 std::cout <<
"nullptr" << std::endl;
284 auto addNodeWidget = [&](std::shared_ptr<Node> m) ->
void
288 auto type = std::make_unique<QtNodeWidget>(m);
290 auto& node = this->createNode(std::move(type));
292 QPointF posView(m->bx(), m->by());
294 node.nodeGraphicsObject().setPos(posView);
296 this->nodePlaced(node);
300 for (
auto it = scn->begin(); it != scn->end(); it++)
303 addNodeWidget(it.get());
308 addNodeWidget(dat->getNode());
360 auto qNodeWdiget = std::make_unique<QtNodeWidget>(node);
361 auto& qNode = createNode(std::move(qNodeWdiget));
364 auto& _nodes = this->nodes();
366 for (
auto const& _node : _nodes)
368 NodeGeometry& geo = _node.second->nodeGeometry();
369 QtNodeGraphicsObject& obj = _node.second->nodeGraphicsObject();
371 float h = geo.height();
373 QPointF pos = obj.pos();
375 y = std::max(y,
float(pos.y() + h));
378 QPointF posView(0.0f, y + 50.0f);
380 qNode.nodeGraphicsObject().setPos(posView);
382 emit nodePlaced(qNode);
407 auto qDataModel =
dynamic_cast<QtNodeWidget*
>(n.nodeDataModel());
408 auto node = qDataModel->
getNode();
409 if (node ==
nullptr) {
413 auto menu =
new QMenu;
414 menu->setStyleSheet(
"QMenu{color:white;border: 1px solid black;} ");
416 auto openAct =
new QAction(
"Open",
this);
418 auto showAllNodesAct =
new QAction(
"Show All Nodes",
this);
419 auto showThisNodeOnlyAct =
new QAction(
"Show This Only",
this);
421 showAllNodesAct->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_V));
422 showThisNodeOnlyAct->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_H));
424 auto delAct =
new QAction(
"Delete",
this);
425 auto helpAct =
new QAction(
"Help",
this);
427 menu->addAction(openAct);
429 menu->addSeparator();
430 menu->addAction(showThisNodeOnlyAct);
431 menu->addAction(showAllNodesAct);
434 auto resetNodeAct =
new QAction(
"Reset This Node",
this);
435 auto activateThisNodeOnlyAct =
new QAction(
"Activate This Only",
this);
436 auto activateAllNodesAct =
new QAction(
"Activate All Nodes",
this);
437 menu->addSeparator();
438 menu->addAction(resetNodeAct);
440 menu->addSeparator();
441 menu->addAction(activateThisNodeOnlyAct);
442 menu->addAction(activateAllNodesAct);
444 menu->addSeparator();
445 auto autoSyncAct =
new QAction(
"Auto-Sync",
this);
446 autoSyncAct->setCheckable(
true);
447 autoSyncAct->setChecked(node->isAutoSync());
449 auto enableDiscendants =
new QAction(
"Enable Descendants' Auto-Sync(s)",
this);
450 auto disableDiscendants =
new QAction(
"Disable Descendants' Auto-Sync(s)",
this);
451 auto enableAutoSync =
new QAction(
"Enable All Auto-Sync(s)",
this);
452 auto disableAutoSync =
new QAction(
"Disable All Auto-Sync(s)",
this);
453 menu->addAction(autoSyncAct);
454 menu->addAction(enableDiscendants);
455 menu->addAction(disableDiscendants);
456 menu->addAction(enableAutoSync);
457 menu->addAction(disableAutoSync);
459 menu->addSeparator();
460 menu->addAction(delAct);
462 menu->addSeparator();
463 menu->addAction(helpAct);
465 connect(openAct, &QAction::triggered,
this, [&]() { nodeDoubleClicked(n); });
468 connect(showAllNodesAct, &QAction::triggered,
this, [&]() {
472 connect(showThisNodeOnlyAct, &QAction::triggered,
this, [&]() {
476 connect(resetNodeAct, &QAction::triggered,
this, [=]() {
480 connect(activateAllNodesAct, &QAction::triggered,
this, [&]() {
484 connect(activateThisNodeOnlyAct, &QAction::triggered,
this, [&]() {
488 connect(autoSyncAct, &QAction::triggered,
this, [=](
bool checked) {
489 node->setAutoSync(checked);
492 connect(enableDiscendants, &QAction::triggered,
this, [&]() {
496 connect(disableDiscendants, &QAction::triggered,
this, [&]() {
500 connect(enableAutoSync, &QAction::triggered,
this, [=]() {
504 connect(disableAutoSync, &QAction::triggered,
this, [=]() {
508 connect(delAct, &QAction::triggered,
this, [&](){ this->removeNode(n); });
509 connect(helpAct, &QAction::triggered,
this, [&]() { this->
showHelper(n); });
511 menu->move(QCursor().pos().x() + 4, QCursor().pos().y() + 4);
642 auto constructDAG = [&](std::shared_ptr<Node> nd) ->
void
645 auto inId = nd->objectId();
647 auto ports = nd->getImportNodes();
652 bool NodeConnection =
false;
653 bool FieldConnection =
false;
654 for (
int i = 0; i < ports.size(); i++)
659 auto node = ports[i]->getNodes()[0];
662 auto outId = node->objectId();
671 auto& nodes = ports[i]->getNodes();
672 for (
int j = 0; j < nodes.size(); j++)
674 if (nodes[j] !=
nullptr)
676 auto outId = nodes[j]->objectId();
689 auto fieldInp = nd->getInputFields();
690 for (
int i = 0; i < fieldInp.size(); i++)
692 auto fieldSrc = fieldInp[i]->getSource();
693 if (fieldSrc !=
nullptr) {
694 auto parSrc = fieldSrc->parent();
695 if (parSrc !=
nullptr)
697 Node* nodeSrc =
dynamic_cast<Node*
>(parSrc);
700 if (nodeSrc ==
nullptr)
703 if (moduleSrc !=
nullptr)
707 if (nodeSrc !=
nullptr)
719 for (
auto it = scn->begin(); it != scn->end(); it++)
721 constructDAG(it.get());
729 auto& _nodes = this->nodes();
730 std::map<dyno::ObjectId, QtNode*> qtNodeMapper;
731 std::map<dyno::ObjectId, Node*> nodeMapper;
732 for (
auto const& _node : _nodes)
734 auto const& qtNode = _node.second;
735 auto model = qtNode->nodeDataModel();
739 if (model !=
nullptr)
741 auto node = nodeData->getNode();
744 qtNodeMapper[node->objectId()] = qtNode.get();
745 nodeMapper[node->objectId()] = node.get();
749 float tempOffsetY = 0.0f;
751 float offsetX = 0.0f;
754 auto& xc = layout.
layer(l);
756 float offsetY = 0.0f;
758 for (
size_t index = 0; index < xc.size(); index++)
761 if (qtNodeMapper.find(
id) != qtNodeMapper.end())
763 QtNode* qtNode = qtNodeMapper[id];
764 NodeGeometry& geo = qtNode->nodeGeometry();
766 float w = geo.width();
767 float h = geo.height();
769 xMax = std::max(xMax, w);
771 Node* node = nodeMapper[id];
775 offsetY += (h +
mDy);
780 offsetX += (xMax +
mDx);
782 tempOffsetY = std::max(tempOffsetY,offsetY);
792 std::set<dyno::ObjectId>::iterator it;
794 float ofstY = tempOffsetY;
796 for (it = otherVertices.begin(); it != otherVertices.end(); it++)
799 if (qtNodeMapper.find(
id) != qtNodeMapper.end())
801 QtNode* qtNode = qtNodeMapper[id];
802 NodeGeometry& geo = qtNode->nodeGeometry();
804 heigth = geo.height();
806 Node* node = nodeMapper[id];
810 ofstX += width +
mDx;
817 qtNodeMapper.clear();