13#include <QtWidgets/QMenu>
36 : QtFlowScene(registry, parent)
47 auto ret = std::make_shared<QtDataModelRegistry>();
49 for (
auto const c : *classMap)
53 QString str = QString::fromStdString(c.first);
55 std::shared_ptr<dyno::Module> module(
dynamic_cast<dyno::Module*
>(obj));
57 if (module !=
nullptr)
59 QtDataModelRegistry::RegistryItemCreator creator = [str]() {
61 std::shared_ptr<dyno::Module> new_module(
dynamic_cast<dyno::Module*
>(new_obj));
62 auto dat = std::make_unique<QtModuleWidget>(new_module);
66 QString category = QString::fromStdString(module->getModuleType());
71 this->setRegistry(ret);
97 auto allNodes = this->allNodes();
99 for (
auto node : allNodes)
101 auto model =
dynamic_cast<QtModuleWidget*
>(node->nodeDataModel());
102 if (model !=
nullptr)
104 model->enableEditing();
113 auto allNodes = this->allNodes();
115 for (
auto node : allNodes)
117 auto model =
dynamic_cast<QtModuleWidget*
>(node->nodeDataModel());
118 if (model !=
nullptr)
120 model->disableEditing();
134 std::map<dyno::ObjectId, QtNode*> moduleMap;
142 auto addModuleWidget = [&](std::shared_ptr<Module> m) ->
void
144 auto mId = m->objectId();
146 auto type = std::make_unique<QtModuleWidget>(m);
148 auto& node = this->createNode(std::move(type));
150 moduleMap[mId] = &node;
152 QPointF posView(m->bx(), m->by());
154 node.nodeGraphicsObject().setPos(posView);
156 this->nodePlaced(node);
160 mStates = std::make_shared<dyno::States>();
163 for (
auto field : fields)
168 mStates->addOutputField(field);
174 mStates->setBlockCoord(pos.x(), pos.y());
178 for (
auto m : modules)
180 addModuleWidget(m.second);
183 auto createModuleConnections = [&](std::shared_ptr<Module> m) ->
void
185 auto inId = m->objectId();
187 if (moduleMap.find(inId) != moduleMap.end()) {
188 auto inBlock = moduleMap[m->objectId()];
190 auto fieldIn = m->getInputFields();
192 for (
int i = 0; i < fieldIn.size(); i++)
194 auto fieldSrc = fieldIn[i]->getSource();
195 if (fieldSrc !=
nullptr) {
196 auto parSrc = fieldSrc->parent();
197 if (parSrc !=
nullptr)
200 if (nodeSrc ==
nullptr)
208 uint outFieldIndex = 0;
209 bool fieldFound =
false;
210 for (
auto f : fieldsOut)
220 if (fieldFound && moduleMap.find(outId) != moduleMap.end())
222 auto outBlock = moduleMap[outId];
223 createConnection(*inBlock, i, *outBlock, outFieldIndex);
231 for (
auto m : modules)
233 createModuleConnections(m.second);
241 auto m = mw ==
nullptr ? nullptr : mw->
getModule();
245 m->setBlockCoord(newLocation.x(), newLocation.y());
251 auto pipeline =
mNode->resetPipeline();
268 auto pipeline =
mNode->animationPipeline();
280 auto pipeline =
mNode->graphicsPipeline();
299 portMenu.setObjectName(
"PortMenu");
302 auto exportAction = portMenu.addAction(
"Export");
304 connect(exportAction, &QAction::triggered, [&]()
306 auto dataModel =
dynamic_cast<QtModuleWidget*
>(n.nodeDataModel());
308 if (dataModel !=
nullptr)
310 auto m = dataModel->getModule();
313 auto fieldOut = m->getOutputFields();
322 QPoint p(pos.x(), pos.y());
333 if (
mNode !=
nullptr)
346 auto constructDAG = [&](std::shared_ptr<Module> m) ->
void
348 auto outId = m->objectId();
350 auto fieldOut = m->getOutputFields();
351 for (
int i = 0; i < fieldOut.size(); i++)
353 auto& sinks = fieldOut[i]->getSinks();
354 for (
auto sink : sinks)
356 if (sink !=
nullptr) {
357 auto parSrc = sink->parent();
358 if (parSrc !=
nullptr)
362 if (nodeSrc !=
nullptr)
376 for (
auto it = mlists.begin(); it != mlists.end(); it++)
386 auto& _nodes = this->nodes();
387 std::map<dyno::ObjectId, QtNode*> qtNodeMapper;
388 std::map<dyno::ObjectId, Module*> moduleMapper;
389 for (
auto const& _node : _nodes)
391 auto const& qtNode = _node.second;
392 auto model = qtNode->nodeDataModel();
396 if (model !=
nullptr)
398 auto m = nodeData->getModule();
401 qtNodeMapper[m->objectId()] = qtNode.get();
402 moduleMapper[m->objectId()] = m.get();
407 float offsetX = 0.0f;
410 auto& xc = layout.
layer(l);
412 float offsetY = 0.0f;
414 for (
size_t index = 0; index < xc.size(); index++)
417 if (qtNodeMapper.find(
id) != qtNodeMapper.end())
419 QtNode* qtNode = qtNodeMapper[id];
420 NodeGeometry& geo = qtNode->nodeGeometry();
422 float w = geo.width();
423 float h = geo.height();
425 xMax = std::max(xMax, w);
427 Module* node = moduleMapper[id];
431 offsetY += (h +
mDy);
435 offsetX += (xMax +
mDx);
446 qtNodeMapper.clear();
447 moduleMapper.clear();
474 emit this->nodeDeselected();
#define IMPLEMENT_CLASS(name)
std::shared_ptr< dyno::Module > mStates
std::shared_ptr< dyno::Pipeline > mActivePipeline
QtModuleFlowScene(std::shared_ptr< QtDataModelRegistry > registry, QObject *parent=Q_NULLPTR)
void updateModuleGraphView()
void deleteModule(QtNode &n)
std::shared_ptr< dyno::Node > mNode
void moveModule(QtNode &n, const QPointF &newLocation)
void addModule(QtNode &n)
void showModuleFlow(Node *node)
void showGraphicsPipeline()
void promoteOutput(QtNode &n, const PortIndex index, const QPointF &pos)
void showAnimationPipeline()
bool mReorderResetPipeline
bool mReorderGraphicsPipeline
Automatic layout for directed acyclic graph Refer to "Sugiyama Algorithm" by Nikola S....
std::vector< ObjectId > & layer(size_t l)
Graph class represents a directed graph.
void addEdge(ObjectId v, ObjectId w)
Module(std::string name="default")
std::list< std::shared_ptr< Module > > & getModuleList()
std::shared_ptr< AnimationPipeline > animationPipeline()
std::vector< FBase * > & getAllFields()
std::vector< FBase * > & getOutputFields()
void setBlockCoord(float x, float y)
static std::map< std::string, ClassInfo * > * getClassMap()
static Object * createObject(std::string name)
This is an implementation of AdditiveCCD based on peridyno.