Compare commits

..

No commits in common. "bc304b325e93e608c8f737a009f170bdb432952d" and "be67b5ef031b09cc1174835059c2078e136b1e5b" have entirely different histories.

4 changed files with 34 additions and 75 deletions

View File

@ -336,7 +336,7 @@ QList<std::shared_ptr<LogicalNode>> SequenceNode::getForwards() const
QString SequenceNode::typeName() const QString SequenceNode::typeName() const
{ {
return u8"顺序"; return u8"顺序节点";
} }
LogicalResult SequenceNode::execute() { LogicalResult SequenceNode::execute() {
@ -412,11 +412,8 @@ void LogicalNode::insert(std::shared_ptr<LogicalNode> node, int index /*= -1*/)
if (it->getID() == node->getID()) if (it->getID() == node->getID())
return; return;
if(node->parent().lock())
node->parent().lock()->remove(node);
_child_list.insert(index, node);
node->_set_parent_node(this->shared_from_this()); node->_set_parent_node(this->shared_from_this());
_child_list.insert(index, node);
} }
void LogicalNode::remove(std::shared_ptr<LogicalNode> node) void LogicalNode::remove(std::shared_ptr<LogicalNode> node)
@ -484,7 +481,7 @@ void SelectorNode::reset()
QString SelectorNode::typeName() const QString SelectorNode::typeName() const
{ {
return u8"选择"; return u8"选择节点";
} }
LogicalResult SelectorNode::execute() LogicalResult SelectorNode::execute()
@ -526,7 +523,7 @@ void ParallelNode::reset()
QString ParallelNode::typeName() const QString ParallelNode::typeName() const
{ {
return u8"并行"; return u8"并行节点";
} }
LogicalResult ParallelNode::execute() LogicalResult ParallelNode::execute()
@ -582,7 +579,7 @@ void CompareNode::reset() {
QString CompareNode::typeName() const QString CompareNode::typeName() const
{ {
return QString(u8"%1<%2>").arg(u8"比较", delegateName()); return QString(u8"%1<%2>").arg(u8"比较节点", delegateName());
} }
LogicalResult CompareNode::execute() LogicalResult CompareNode::execute()
@ -767,7 +764,7 @@ QList<std::shared_ptr<LogicalNode>> ExecuteNode::getForwards() const
QString ExecuteNode::typeName() const QString ExecuteNode::typeName() const
{ {
return QString(u8"执行<%1>").arg(delegateName()); return QString(u8"执行节点<%1>").arg(delegateName());
} }
QHash<QString, std::shared_ptr<TopicData>> ExecuteNode::inputList() const QHash<QString, std::shared_ptr<TopicData>> ExecuteNode::inputList() const

View File

@ -465,7 +465,7 @@ enum class IO_TYPE {
class COMPONENTBASIC_EXPORT BehaviorMapNode : public LogicalNode { class COMPONENTBASIC_EXPORT BehaviorMapNode : public LogicalNode {
private: private:
std::shared_ptr<MapKernal> _bind_kernal; std::shared_ptr<MapKernal> _bind_kernal;
QString _map_name = u8"行为树"; QString _map_name = u8"行为树节点";
/// <summary> /// <summary>
/// 華芞曹講桶 /// 華芞曹講桶

View File

@ -1,14 +1,8 @@
#include "BehaviorEditor.h" #include "BehaviorEditor.h"
NodePresent::NodePresent(BehaviorsPresent* pwidget, QVector<double>& columns_set, std::shared_ptr<LogicalNode> bind) NodePresent::NodePresent(BehaviorsPresent* pwidget, double& width_bind, std::shared_ptr<LogicalNode> bind)
: _widget_p(pwidget), _columns_width_seqs(columns_set), _node_bind(bind) { : _widget_p(pwidget), _node_bind(bind), _column_width(width_bind) {
this->setAcceptDrops(true); this->setAcceptDrops(true);
this->setCacheMode(QGraphicsItem::NoCache);
}
std::shared_ptr<LogicalNode> NodePresent::logicalBind() const
{
return _node_bind;
} }
QRectF NodePresent::contentMeasure() const QRectF NodePresent::contentMeasure() const
@ -114,12 +108,11 @@ void NodePresent::dropEvent(QGraphicsSceneDragDropEvent* e)
new_type = this->_node_bind->bindMap()->getKernal()->getNode(kind_string); new_type = this->_node_bind->bindMap()->getKernal()->getNode(kind_string);
else else
new_type = std::dynamic_pointer_cast<BehaviorMapNode>(this->_node_bind)->getKernal()->getNode(kind_string); new_type = std::dynamic_pointer_cast<BehaviorMapNode>(this->_node_bind)->getKernal()->getNode(kind_string);
auto new_node = std::dynamic_pointer_cast<LogicalNode>(new_type->newDefault()); auto new_node = std::dynamic_pointer_cast<LogicalNode>(new_type->newDefault());
new_node->setID(++_widget_p->_node_id_max); new_node->setID(++_widget_p->_node_id_max);
auto this_node = this->_node_bind; auto this_node = this->_node_bind;
auto appoint_index = 0; auto appoint_index = 0;
if (parent_node) if (parent_node)
appoint_index = parent_node->children().indexOf(this_node); appoint_index = parent_node->children().indexOf(this_node);
@ -142,22 +135,16 @@ void NodePresent::dropEvent(QGraphicsSceneDragDropEvent* e)
break; break;
} }
this->_drop_target = AcceptType::NONE;
_widget_p->relayout(); _widget_p->relayout();
this->_drop_target = AcceptType::NONE;
this->update(); this->update();
} }
QRectF NodePresent::boundingRect() const QRectF NodePresent::boundingRect() const
{ {
auto rect = contentMeasure(); auto rect = contentMeasure();
auto depth = this->_node_bind->depth(); rect.setWidth(std::max(_column_width, rect.width()));
if(_columns_width_seqs.size() <= depth) _column_width = rect.width();
_columns_width_seqs.resize(depth + 1);
auto width_col = _columns_width_seqs[depth];
rect.setWidth(std::max(width_col, rect.width()));
_columns_width_seqs[depth] = rect.width();
return rect + QMargins(0, 0, 30, 30); return rect + QMargins(0, 0, 30, 30);
} }
@ -167,7 +154,7 @@ void NodePresent::paint(QPainter* painter, const QStyleOptionGraphicsItem* optio
{ {
painter->save(); painter->save();
//painter->drawRect(boundingRect()); painter->drawRect(boundingRect());
painter->fillRect(option->rect - QMargins(padding, padding, padding, padding), Qt::gray); painter->fillRect(option->rect - QMargins(padding, padding, padding, padding), Qt::gray);
auto outline = this->boundingRect(); auto outline = this->boundingRect();
@ -210,7 +197,6 @@ BehaviorsPresent::BehaviorsPresent(QWidget* parent /*= nullptr*/)
this->setScene(&_bind_scene); this->setScene(&_bind_scene);
this->setAcceptDrops(true); this->setAcceptDrops(true);
this->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
auto font = this->font(); auto font = this->font();
font.setPixelSize(20); font.setPixelSize(20);
@ -237,6 +223,7 @@ NodePresent* BehaviorsPresent::presentAllocate(std::shared_ptr<LogicalNode> ins)
for (auto idx = _column_aligns.size(); idx < ins->depth() + 1; ++idx) for (auto idx = _column_aligns.size(); idx < ins->depth() + 1; ++idx)
_column_aligns.append(0); _column_aligns.append(0);
auto& current_width = _column_aligns[ins->depth()];
QList<NodePresent*> _children_set; QList<NodePresent*> _children_set;
switch (ins->nodeKind()) { switch (ins->nodeKind()) {
case NodeKind::MAPNODE: case NodeKind::MAPNODE:
@ -253,13 +240,13 @@ NodePresent* BehaviorsPresent::presentAllocate(std::shared_ptr<LogicalNode> ins)
default: default:
if (_present_peers.contains(ins)) { if (_present_peers.contains(ins)) {
for (auto child : _children_set) { for (auto child : _children_set) {
_branch_list << new BranchPresent(_present_peers, child); _branch_list << new BranchPresent(_present_peers[ins], current_width, child);
this->_bind_scene.addItem(_branch_list.last()); this->_bind_scene.addItem(_branch_list.last());
} }
return nullptr; return nullptr;
} }
_present_peers[ins] = new NodePresent(this, _column_aligns, ins); _present_peers[ins] = new NodePresent(this, current_width, ins);
this->_bind_scene.addItem(_present_peers[ins]); this->_bind_scene.addItem(_present_peers[ins]);
return _present_peers[ins]; return _present_peers[ins];
@ -304,8 +291,8 @@ void BehaviorsPresent::relayout()
// µ÷Õû·Ö֧ͼÐÎλÖà // µ÷Õû·Ö֧ͼÐÎλÖÃ
for (auto ins : this->_branch_list) { for (auto ins : this->_branch_list) {
auto rect_s = ins->startOutline(); auto rect_s = ins->startNodeOutline();
auto rect_e = ins->endOutline(); auto rect_e = ins->endNodeOutline();
qDebug() << __FILE__ << __LINE__ << rect_s << rect_e; qDebug() << __FILE__ << __LINE__ << rect_s << rect_e;
@ -318,8 +305,6 @@ void BehaviorsPresent::relayout()
ins->setPos(left_val, top_val); ins->setPos(left_val, top_val);
ins->resetArrow(start_pos, end_pos); ins->resetArrow(start_pos, end_pos);
} }
this->update();
} }
QSizeF BehaviorsPresent::outlineMeasure(std::shared_ptr<LogicalNode> ins, QHash<std::shared_ptr<LogicalNode>, std::pair<QSizeF, QSizeF>>& _outline_occupy) QSizeF BehaviorsPresent::outlineMeasure(std::shared_ptr<LogicalNode> ins, QHash<std::shared_ptr<LogicalNode>, std::pair<QSizeF, QSizeF>>& _outline_occupy)
@ -396,6 +381,7 @@ uint qHash(const std::shared_ptr<LogicalNode> data, uint seed) noexcept
#include <QMenuBar> #include <QMenuBar>
#include <QMenu> #include <QMenu>
#include <QFileDialog> #include <QFileDialog>
#include <QDebug>
void BehaviorEditor::open_behavior_map() void BehaviorEditor::open_behavior_map()
{ {
@ -434,15 +420,11 @@ BehaviorEditor::BehaviorEditor(QWidget* parent /*= nullptr*/)
auto split_h = new QSplitter(Qt::Horizontal, this); auto split_h = new QSplitter(Qt::Horizontal, this);
split_v->addWidget(split_h); split_v->addWidget(split_h);
split_v->addWidget(_logs_present); split_v->addWidget(_logs_present);
split_v->setStretchFactor(0, 1);
split_v->setStretchFactor(1, 0);
split_h->addWidget(_logical_present); split_h->addWidget(_logical_present);
split_h->addWidget(_type_view); split_h->addWidget(_type_view);
split_h->setStretchFactor(0, 1);
split_h->setStretchFactor(1, 0);
_type_view->setModel(_type_model); _type_view->setModel(_type_model);
nodeTypesViewInit(_type_model); nodeTypesViewInit(_type_model);
} }
@ -500,17 +482,12 @@ void NodeTypesView::startDrag(Qt::DropActions supported)
} }
} }
BranchPresent::BranchPresent(const QHash<std::shared_ptr<LogicalNode>, NodePresent*>& present_set, NodePresent* head_anchor) BranchPresent::BranchPresent(NodePresent* a, double& a_width, NodePresent* b)
:_present_set_bind(present_set), _head_node(head_anchor) { :_start_node(a), _start_node_width(a_width), _end_node(b) {
} }
QRectF BranchPresent::startOutline() const QRectF BranchPresent::startNodeOutline() const
{ {
auto parent_node = _head_node->logicalBind()->parent().lock();
if (!parent_node)
return QRectF();
auto _start_node = _present_set_bind[parent_node];
auto _start_pos = _start_node->pos(); auto _start_pos = _start_node->pos();
auto _s_rect = _start_node->boundingRect(); auto _s_rect = _start_node->boundingRect();
_s_rect.moveTopLeft(_start_pos); _s_rect.moveTopLeft(_start_pos);
@ -518,13 +495,8 @@ QRectF BranchPresent::startOutline() const
return _s_rect; return _s_rect;
} }
QRectF BranchPresent::endOutline() const QRectF BranchPresent::endNodeOutline() const
{ {
auto parent_node = _head_node->logicalBind()->parent().lock();
if (!parent_node)
return QRectF();
auto _end_node = this->_head_node;
auto _end_pos = _end_node->pos(); auto _end_pos = _end_node->pos();
auto _e_rect = _end_node->boundingRect(); auto _e_rect = _end_node->boundingRect();
_e_rect.moveTopLeft(_end_pos); _e_rect.moveTopLeft(_end_pos);
@ -580,9 +552,5 @@ void BranchPresent::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt
//painter->drawLine(pt1, pt2); //painter->drawLine(pt1, pt2);
//painter->drawLine(pt1, vtarget); //painter->drawLine(pt1, vtarget);
//p.setColor(Qt::green);
//painter->setPen(p);
//painter->drawRect(option->rect);
painter->restore(); painter->restore();
} }

View File

@ -17,19 +17,14 @@ class BehaviorsPresent;
class NodePresent : public QGraphicsItem { class NodePresent : public QGraphicsItem {
private: private:
BehaviorsPresent* const _widget_p; BehaviorsPresent* const _widget_p;
QVector<double> &_columns_width_seqs; double& _column_width;
std::shared_ptr<LogicalNode> _node_bind;
AcceptType _drop_target = AcceptType::NONE; AcceptType _drop_target = AcceptType::NONE;
public: public:
std::shared_ptr<LogicalNode> _node_bind;
static const double padding; static const double padding;
NodePresent(BehaviorsPresent* pwidget, QVector<double> &columns_set, std::shared_ptr<LogicalNode> bind); NodePresent(BehaviorsPresent* pwidget, double& width_bind, std::shared_ptr<LogicalNode> bind);
/// <summary>
/// °ó¶¨µÄÂß¼­½Úµã
/// </summary>
/// <returns></returns>
std::shared_ptr<LogicalNode> logicalBind() const;
QRectF contentMeasure() const; QRectF contentMeasure() const;
AcceptType testAccept(const QPointF& local_pos, const QString& kind_str) const; AcceptType testAccept(const QPointF& local_pos, const QString& kind_str) const;
@ -43,7 +38,6 @@ protected:
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent* event); virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent* event); virtual void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
virtual void dropEvent(QGraphicsSceneDragDropEvent* event); virtual void dropEvent(QGraphicsSceneDragDropEvent* event);
}; };
/// <summary> /// <summary>
@ -51,16 +45,17 @@ protected:
/// </summary> /// </summary>
class BranchPresent : public QGraphicsItem { class BranchPresent : public QGraphicsItem {
private: private:
const QHash<std::shared_ptr<LogicalNode>, NodePresent*> &_present_set_bind; NodePresent* const _start_node;
NodePresent* const _head_node; double& _start_node_width;
NodePresent* const _end_node;
QPointF _arrow_start, _arrow_end; QPointF _arrow_start, _arrow_end;
public: public:
BranchPresent(const QHash<std::shared_ptr<LogicalNode>, NodePresent*> &present_set, NodePresent* head_anchor); BranchPresent(NodePresent* a, double& a_width, NodePresent* b);
QRectF startOutline() const; QRectF startNodeOutline() const;
QRectF endOutline() const; QRectF endNodeOutline() const;
void resetArrow(const QPointF& start, const QPointF& end); void resetArrow(const QPointF& start, const QPointF& end);
// ͨ¹ý QGraphicsItem ¼Ì³Ð // ͨ¹ý QGraphicsItem ¼Ì³Ð
@ -130,7 +125,6 @@ public:
/// <returns>×óϽÇ</returns> /// <returns>×óϽÇ</returns>
QPointF nodeRelayout(QHash<std::shared_ptr<LogicalNode>, std::pair<QSizeF, QSizeF>>& _outline_occupy, QPointF nodeRelayout(QHash<std::shared_ptr<LogicalNode>, std::pair<QSizeF, QSizeF>>& _outline_occupy,
std::shared_ptr<LogicalNode> ins, const QPointF& origin_offset); std::shared_ptr<LogicalNode> ins, const QPointF& origin_offset);
}; };