Skip to content

Commit

Permalink
Make InsertNode menu sorted, add customed BuiltinNodeModels
Browse files Browse the repository at this point in the history
  • Loading branch information
Aoi-hosizora committed May 25, 2021
1 parent 1f3e5f2 commit e86d967
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions bt_editor/bt_editor_base.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "bt_editor_base.h"
#include <behaviortree_cpp_v3/decorators/subtree_node.h>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include "XML_utilities.hpp"

void AbsBehaviorTree::clear()
{
Expand Down Expand Up @@ -208,6 +211,28 @@ const NodeModels &BuiltinNodeModels()
groot_model = bt_model;
out.insert( { QString::fromStdString(model_name), std::move(groot_model) });
}

QString fileName = "custommed.xml";
if (QFileInfo::exists(fileName)) {
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QString xml_text;
QTextStream in(&file);
while (!in.atEnd()) {
xml_text += in.readLine();
}

QDomDocument document;
if (document.setContent(xml_text)) {
for (const auto &it : ReadTreeNodesModel(document.documentElement())) {
const auto &model_name = it.first;
if (model_name == "SubTree" || model_name == "SubTreePlus") {
continue;
}
out.insert({model_name, std::move(it.second)});
}
}
}
return out;
}();

Expand Down
7 changes: 5 additions & 2 deletions bt_editor/graphic_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void GraphicContainer::createMorphSubMenu(QtNodes::Node &node, QMenu* nodeMenu)
}
else
{
std::vector<QString> v;;
std::vector<QString> v;
v.insert(v.end(), names_in_category.begin(), names_in_category.end());
std::sort(v.begin(), v.end());
for(auto& name: v)
Expand Down Expand Up @@ -597,7 +597,10 @@ void GraphicContainer::onConnectionContextMenu(QtNodes::Connection &connection,
submenu->setEnabled(false);
}
else{
for(auto& name: model_names)
std::vector<QString> v;
v.insert(v.end(), model_names.begin(), model_names.end());
std::sort(v.begin(), v.end());
for(auto& name: v)
{
auto action = new QAction(name, submenu);
submenu->addAction(action);
Expand Down

0 comments on commit e86d967

Please sign in to comment.