Compare commits

..

No commits in common. "5a917f3ff46cdf55cf7ce89060f6e9104c0ba174" and "6769ada4b6eaee6d78610d15d110087ceb470ae5" have entirely different histories.

5 changed files with 44 additions and 80 deletions

View File

@ -98,7 +98,7 @@ std::shared_ptr<MessageLoader> MapKernal::messageLoader() const
void MapKernal::registData(std::shared_ptr<TopicData> init) void MapKernal::registData(std::shared_ptr<TopicData> init)
{ {
if (_variable_types.contains(init->topicString())) if (_variable_types.contains(init->topicString()))
throw new UniException(QString(u8"重复注册类型数据{%1}").arg(init->topicString())); throw new UniException(QString("重复注册类型数据{%1}").arg(init->topicString()));
_variable_types[init->topicString()] = init; _variable_types[init->topicString()] = init;
} }
@ -132,14 +132,6 @@ NodeKind LogicalNode::nodeKind() const
return _node_type; return _node_type;
} }
int LogicalNode::depth() const
{
auto node_temp = this->parent().lock();
if (!node_temp) return 0;
return this->parent().lock()->depth() + 1;
}
std::shared_ptr<LogicalNode> LogicalNode::bindMap() const std::shared_ptr<LogicalNode> LogicalNode::bindMap() const
{ {
auto node_temp = this->parent().lock(); auto node_temp = this->parent().lock();
@ -163,7 +155,7 @@ int LogicalNode::getID() const
QString LogicalNode::rtName() const QString LogicalNode::rtName() const
{ {
return QString(u8"%1(%2)").arg(this->typeName()).arg(getID()); return QString("%1(%2)").arg(this->typeName()).arg(getID());
} }
std::weak_ptr<LogicalNode> LogicalNode::parent() const std::weak_ptr<LogicalNode> LogicalNode::parent() const
@ -179,7 +171,7 @@ void BehaviorMapNode::setVariable(const QString& key, IO_TYPE t, std::shared_ptr
{ {
if (_variables.contains(key)) if (_variables.contains(key))
if (_variables[key].second->topicString() != ins->topicString()) if (_variables[key].second->topicString() != ins->topicString())
throw new UniException(u8"不同数据类型数据绑定同一个名称!"); throw new UniException("不同数据类型数据绑定同一个名称!");
_variables[key] = std::make_pair(t, ins); _variables[key] = std::make_pair(t, ins);
} }
@ -241,7 +233,7 @@ QHash<QString, std::shared_ptr<TopicData>> BehaviorMapNode::inputList() const
{ {
QHash<QString, std::shared_ptr<TopicData>> list; QHash<QString, std::shared_ptr<TopicData>> list;
for (auto key : this->_variables.keys()) { for (auto key : this->_variables.keys()) {
if (this->_variables[key].first == IO_TYPE::INPUT && key.contains(u8"::")) if (this->_variables[key].first == IO_TYPE::INPUT && key.contains("::"))
list[key] = _variables[key].second; list[key] = _variables[key].second;
} }
@ -252,7 +244,7 @@ QHash<QString, std::shared_ptr<TopicData>> BehaviorMapNode::outputList() const
{ {
QHash<QString, std::shared_ptr<TopicData>> list; QHash<QString, std::shared_ptr<TopicData>> list;
for (auto key : this->_variables.keys()) { for (auto key : this->_variables.keys()) {
if (this->_variables[key].first == IO_TYPE::OUTPUT && key.contains(u8"::")) if (this->_variables[key].first == IO_TYPE::OUTPUT && key.contains("::"))
list[key] = _variables[key].second; list[key] = _variables[key].second;
} }
@ -283,7 +275,7 @@ QList<std::shared_ptr<LogicalNode>> SequenceNode::getForwards() const
QString SequenceNode::typeName() const QString SequenceNode::typeName() const
{ {
return u8"顺序节点"; return "顺序节点";
} }
LogicalResult SequenceNode::execute() { LogicalResult SequenceNode::execute() {
@ -317,7 +309,7 @@ void SequenceNode::recoveryFrom(const QJsonObject& obj)
QStringList state_items; QStringList state_items;
STRLIST_PEAK(state_items); STRLIST_PEAK(state_items);
for (auto kv : state_items) { for (auto kv : state_items) {
auto kv_pair = kv.split(u8":"); auto kv_pair = kv.split(":");
_state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt(); _state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt();
} }
} }
@ -326,7 +318,7 @@ void SequenceNode::saveTo(QJsonObject& obj) const
{ {
QStringList state_items; QStringList state_items;
for (auto inv : _state_map.keys()) { for (auto inv : _state_map.keys()) {
state_items << QString(u8"%1:%2").arg(inv).arg((int)_state_map[inv]); state_items << QString("%1:%2").arg(inv).arg((int)_state_map[inv]);
} }
STRLIST_SAVE(state_items); STRLIST_SAVE(state_items);
@ -406,7 +398,7 @@ void SelectorNode::recoveryFrom(const QJsonObject& obj)
QStringList state_items; QStringList state_items;
STRLIST_PEAK(state_items); STRLIST_PEAK(state_items);
for (auto kv : state_items) { for (auto kv : state_items) {
auto kv_pair = kv.split(u8":"); auto kv_pair = kv.split(":");
_state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt(); _state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt();
} }
} }
@ -415,7 +407,7 @@ void SelectorNode::saveTo(QJsonObject& obj) const
{ {
QStringList state_items; QStringList state_items;
for (auto inv : _state_map.keys()) { for (auto inv : _state_map.keys()) {
state_items << QString(u8"%1:%2").arg(inv).arg((int)_state_map[inv]); state_items << QString("%1:%2").arg(inv).arg((int)_state_map[inv]);
} }
STRLIST_SAVE(state_items); STRLIST_SAVE(state_items);
@ -428,7 +420,7 @@ void SelectorNode::reset()
QString SelectorNode::typeName() const QString SelectorNode::typeName() const
{ {
return u8"选择节点"; return "选择节点";
} }
LogicalResult SelectorNode::execute() LogicalResult SelectorNode::execute()
@ -470,7 +462,7 @@ void ParallelNode::reset()
QString ParallelNode::typeName() const QString ParallelNode::typeName() const
{ {
return u8"并行节点"; return "并行节点";
} }
LogicalResult ParallelNode::execute() LogicalResult ParallelNode::execute()
@ -506,7 +498,7 @@ void ParallelNode::recoveryFrom(const QJsonObject& obj)
QStringList state_items; QStringList state_items;
STRLIST_PEAK(state_items); STRLIST_PEAK(state_items);
for (auto kv : state_items) { for (auto kv : state_items) {
auto kv_pair = kv.split(u8":"); auto kv_pair = kv.split(":");
_state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt(); _state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt();
} }
} }
@ -515,7 +507,7 @@ void ParallelNode::saveTo(QJsonObject& obj) const
{ {
QStringList state_items; QStringList state_items;
for (auto inv : _state_map.keys()) { for (auto inv : _state_map.keys()) {
state_items << QString(u8"%1:%2").arg(inv).arg((int)_state_map[inv]); state_items << QString("%1:%2").arg(inv).arg((int)_state_map[inv]);
} }
STRLIST_SAVE(state_items); STRLIST_SAVE(state_items);
@ -526,14 +518,14 @@ void CompareNode::reset() {
QString CompareNode::typeName() const QString CompareNode::typeName() const
{ {
return QString(u8"%1<%2>").arg(u8"比较节点", delegateName()); return QString("%1<%2>").arg("比较节点", delegateName());
} }
LogicalResult CompareNode::execute() LogicalResult CompareNode::execute()
{ {
if (this->_bind_delegate) { if (this->_bind_delegate) {
auto vl = _data_map[u8"左值"]; auto vl = _data_map["左值"];
auto vb = _data_map[u8"右值"]; auto vb = _data_map["右值"];
if (this->_bind_delegate->compare(vl, vb)) if (this->_bind_delegate->compare(vl, vb))
return LogicalResult::SUCCESS; return LogicalResult::SUCCESS;
} }
@ -564,15 +556,15 @@ std::shared_ptr<Serializable> CompareNode::newDefault() const
CompareNode::CompareNode() CompareNode::CompareNode()
: LogicalNode(NodeKind::COMPARENODE) { : LogicalNode(NodeKind::COMPARENODE) {
_data_map[u8"左值"] = std::make_shared<GeneralData>(); _data_map["左值"] = std::make_shared<GeneralData>();
_data_map[u8"右值"] = std::make_shared<GeneralData>(); _data_map["右值"] = std::make_shared<GeneralData>();
} }
QString CompareNode::delegateName() const QString CompareNode::delegateName() const
{ {
if (_bind_delegate) if (_bind_delegate)
return _bind_delegate->name(); return _bind_delegate->name();
return u8""; return "";
} }
void CompareNode::bindDelegate(std::shared_ptr<CompareKernel> ins) void CompareNode::bindDelegate(std::shared_ptr<CompareKernel> ins)
@ -592,27 +584,27 @@ QHash<QString, std::shared_ptr<TopicData>> CompareNode::outputList() const
void CompareNode::recoveryFrom(const QJsonObject& obj) void CompareNode::recoveryFrom(const QJsonObject& obj)
{ {
auto vala = obj[u8"ValL"]; auto vala = obj["ValL"];
auto valb = obj[u8"ValR"]; auto valb = obj["ValR"];
_data_map[u8"左值"]->recoveryFrom(vala.toObject()); _data_map["左值"]->recoveryFrom(vala.toObject());
_data_map[u8"右值"]->recoveryFrom(valb.toObject()); _data_map["右值"]->recoveryFrom(valb.toObject());
} }
void CompareNode::saveTo(QJsonObject& obj) const void CompareNode::saveTo(QJsonObject& obj) const
{ {
QJsonObject vala, valb; QJsonObject vala, valb;
_data_map[u8"左值"]->saveTo(vala); _data_map["左值"]->saveTo(vala);
_data_map[u8"右值"]->saveTo(valb); _data_map["右值"]->saveTo(valb);
obj[u8"ValL"] = vala; obj["ValL"] = vala;
obj[u8"ValR"] = valb; obj["ValR"] = valb;
} }
#include <QJsonDocument> #include <QJsonDocument>
QString GeneralData::topicString() const QString GeneralData::topicString() const
{ {
return u8"GeneralData"; return "GeneralData";
} }
std::shared_ptr<Serializable> GeneralData::newDefault() const std::shared_ptr<Serializable> GeneralData::newDefault() const

View File

@ -249,11 +249,6 @@ public:
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
NodeKind nodeKind() const; NodeKind nodeKind() const;
/// <summary>
/// 节点深度
/// </summary>
/// <returns></returns>
int depth() const;
/// <summary> /// <summary>
/// 获取包含树图节点 /// 获取包含树图节点

View File

@ -1,42 +1,31 @@
#include "BehaviorEditor.h" #include "BehaviorEditor.h"
NodePresent::NodePresent(QWidget* pwidget, double& width_bind, std::shared_ptr<LogicalNode> bind) NodePresent::NodePresent(std::shared_ptr<LogicalNode> bind)
: _widget_p(pwidget), _node_bind(bind), _column_width(width_bind) { :_node_bind(bind) {
} }
QRectF NodePresent::contentMeasure() const QRectF NodePresent::contentMeasure() const
{ {
auto metrics = this->_widget_p->fontMetrics(); return QRectF(0, 0, 200, 40);
return metrics.boundingRect(this->_node_bind->rtName());
} }
QRectF NodePresent::boundingRect() const QRectF NodePresent::boundingRect() const
{ {
auto rect = contentMeasure(); return contentMeasure() + QMargins(0, 0, 20, 20);
rect.setWidth(std::max(_column_width, rect.width()));
_column_width = rect.width();
return rect + QMargins(0, 0, 30, 30);
} }
#include <QStyleOptionGraphicsItem>
void NodePresent::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) void NodePresent::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{ {
painter->drawRect(boundingRect()); //painter->drawRect(boundingRect());
painter->fillRect(option->rect - QMargins(8,8,8,8), Qt::gray); painter->translate(QPointF(10, 10));
painter->translate(QPointF(15, 15));
auto rect = contentMeasure(); auto rect = contentMeasure();
painter->drawText(rect, 0, this->_node_bind->rtName()); painter->fillRect(rect, Qt::red);
} }
BehaviorsPresent::BehaviorsPresent(QWidget* parent /*= nullptr*/) BehaviorsPresent::BehaviorsPresent(QWidget* parent /*= nullptr*/)
: QGraphicsView(parent) { : QGraphicsView(parent) {
this->setScene(&_bind_scene); this->setScene(&_bind_scene);
auto font = this->font();
font.setPixelSize(20);
this->setFont(font);
} }
void BehaviorsPresent::setRoot(std::shared_ptr<BehaviorMapNode> root) void BehaviorsPresent::setRoot(std::shared_ptr<BehaviorMapNode> root)
@ -45,7 +34,7 @@ void BehaviorsPresent::setRoot(std::shared_ptr<BehaviorMapNode> root)
_present_peers.clear(); _present_peers.clear();
this->_bind_maproot = root; this->_bind_maproot = root;
relayout(); contentRelayout();
} }
void BehaviorsPresent::presentAllocate(std::shared_ptr<LogicalNode> ins) void BehaviorsPresent::presentAllocate(std::shared_ptr<LogicalNode> ins)
@ -65,12 +54,8 @@ void BehaviorsPresent::presentAllocate(std::shared_ptr<LogicalNode> ins)
default: default:
if (_present_peers.contains(ins)) if (_present_peers.contains(ins))
return; return;
for(auto idx=_column_aligns.size(); idx < ins->depth() + 1; ++idx) _present_peers[ins] = new NodePresent(ins);
_column_aligns.append(0);
auto &current_width = _column_aligns[ins->depth()];
_present_peers[ins] = new NodePresent(this, current_width, ins);
this->_bind_scene.addItem(_present_peers[ins]); this->_bind_scene.addItem(_present_peers[ins]);
break; break;
} }
@ -91,12 +76,11 @@ void BehaviorsPresent::presentRelease(std::shared_ptr<LogicalNode> ins)
default: default:
if (this->_present_peers.contains(ins)) if (this->_present_peers.contains(ins))
delete this->_present_peers[ins]; delete this->_present_peers[ins];
this->_present_peers.remove(ins);
break; break;
} }
} }
void BehaviorsPresent::relayout() void BehaviorsPresent::contentRelayout()
{ {
if (!_bind_maproot) if (!_bind_maproot)
return; return;

View File

@ -4,19 +4,12 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QGraphicsView> #include <QGraphicsView>
uint qHash(const std::shared_ptr<LogicalNode> data, uint seed) noexcept;
/// <summary>
/// 节点显示代理
/// </summary>
class NodePresent : public QGraphicsItem { class NodePresent : public QGraphicsItem {
private: private:
QWidget *const _widget_p;
std::shared_ptr<LogicalNode> _node_bind; std::shared_ptr<LogicalNode> _node_bind;
double &_column_width;
public: public:
NodePresent(QWidget *pwidget, double &width_bind, std::shared_ptr<LogicalNode> bind); NodePresent(std::shared_ptr<LogicalNode> bind);
QRectF contentMeasure() const; QRectF contentMeasure() const;
@ -26,6 +19,7 @@ public:
}; };
uint qHash(const std::shared_ptr<LogicalNode> data, uint seed) noexcept;
/// <summary> /// <summary>
/// 行为树编辑展示 /// 行为树编辑展示
/// </summary> /// </summary>
@ -35,7 +29,6 @@ private:
QGraphicsScene _bind_scene; QGraphicsScene _bind_scene;
const double _space_h = 120; const double _space_h = 120;
QVector<double> _column_aligns;
QHash<std::shared_ptr<LogicalNode>, NodePresent*> _present_peers; QHash<std::shared_ptr<LogicalNode>, NodePresent*> _present_peers;
/// <summary> /// <summary>
@ -67,7 +60,7 @@ public:
/// <summary> /// <summary>
/// 内容重新布局 /// 内容重新布局
/// </summary> /// </summary>
void relayout(); void contentRelayout();
/// <summary> /// <summary>
/// 尺寸测量 /// 尺寸测量
/// </summary> /// </summary>

View File

@ -39,7 +39,7 @@ int main(int argc, char *argv[])
item->setID(10000); item->setID(10000);
parallel->insert(item); parallel->insert(item);
item = std::make_shared<CompareNode>(); item = std::make_shared<CompareNode>();
item->setID(100010000); item->setID(10001);
parallel->insert(item); parallel->insert(item);
w.setRoot(root); w.setRoot(root);