Skip to content

Commit bd55f24

Browse files
MozgovoyOlegМозговой Олег Владимирович
andauthored
Feature idle trail (#72)
* add idle trails * optimize replay log row selection with keeping transition order Co-authored-by: Мозговой Олег Владимирович <mozgovoy@nkbvs.ttn.ru>
1 parent 9f81708 commit bd55f24

File tree

6 files changed

+90
-8
lines changed

6 files changed

+90
-8
lines changed

bt_editor/mainwindow.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,22 +1461,54 @@ bool MainWindow::SavedState::operator ==(const MainWindow::SavedState &other) co
14611461
return true;
14621462
}
14631463

1464+
void MainWindow::resetTreeStyle(AbsBehaviorTree &tree){
1465+
//printf("resetTreeStyle\n");
1466+
QtNodes::NodeStyle node_style;
1467+
QtNodes::ConnectionStyle conn_style;
1468+
1469+
for(auto abs_node: tree.nodes()){
1470+
auto gui_node = abs_node.graphic_node;
1471+
1472+
gui_node->nodeDataModel()->setNodeStyle( node_style );
1473+
gui_node->nodeGraphicsObject().update();
1474+
1475+
const auto& conn_in = gui_node->nodeState().connections(PortType::In, 0 );
1476+
if(conn_in.size() == 1)
1477+
{
1478+
auto conn = conn_in.begin()->second;
1479+
conn->setStyle( conn_style );
1480+
conn->connectionGraphicsObject().update();
1481+
}
1482+
}
1483+
}
1484+
14641485
void MainWindow::onChangeNodesStatus(const QString& bt_name,
14651486
const std::vector<std::pair<int, NodeStatus> > &node_status)
14661487
{
14671488
auto tree = BuildTreeFromScene( getTabByName(bt_name)->scene() );
14681489

1490+
std::vector<NodeStatus> vec_last_status(tree.nodesCount());
1491+
1492+
// printf("---\n");
1493+
14691494
for (auto& it: node_status)
14701495
{
14711496
const int index = it.first;
14721497
const NodeStatus status = it.second;
14731498
auto& abs_node = tree.nodes().at(index);
14741499

1500+
// printf("%3d: %d, %s\n", index, (int)it.second, abs_node.instance_name.toStdString().c_str());
1501+
1502+
if(index == 1 && it.second == NodeStatus::RUNNING)
1503+
resetTreeStyle(tree);
1504+
14751505
auto gui_node = abs_node.graphic_node;
1476-
auto style = getStyleFromStatus( status );
1506+
auto style = getStyleFromStatus( status, vec_last_status[index] );
14771507
gui_node->nodeDataModel()->setNodeStyle( style.first );
14781508
gui_node->nodeGraphicsObject().update();
14791509

1510+
vec_last_status[index] = status;
1511+
14801512
const auto& conn_in = gui_node->nodeState().connections(PortType::In, 0 );
14811513
if(conn_in.size() == 1)
14821514
{

bt_editor/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class MainWindow : public QMainWindow
5757

5858
const NodeModels &registeredModels() const;
5959

60+
void resetTreeStyle(AbsBehaviorTree &tree);
61+
6062
public slots:
6163

6264
void onAutoArrange();

bt_editor/sidepanel_replay.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ void SidepanelReplay::loadLog(const QByteArray &content)
214214
_transitions.clear();
215215
_transitions.reserve( (content.size() - 4 - bt_header_size) / 12 );
216216

217+
int idle_counter = _loaded_tree.nodes().size();
218+
const int total_nodes = _loaded_tree.nodes().size();
219+
int nearest_restart_transition_index = 0;
220+
217221
for (size_t offset = 4+bt_header_size; offset < content.size(); offset += 12)
218222
{
219223
Transition transition;
@@ -225,6 +229,21 @@ void SidepanelReplay::loadLog(const QByteArray &content)
225229
transition.index = uid_to_index.at(uid);
226230
transition.prev_status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+10] ));
227231
transition.status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+11] ));
232+
transition.is_tree_restart = false;
233+
234+
if(transition.index == 1 &&
235+
(transition.status == NodeStatus::RUNNING || transition.status == NodeStatus::IDLE) &&
236+
idle_counter >= total_nodes - 1){
237+
transition.is_tree_restart = true;
238+
nearest_restart_transition_index = _transitions.size();
239+
}
240+
241+
if(transition.prev_status != NodeStatus::IDLE && transition.status == NodeStatus::IDLE)
242+
idle_counter++;
243+
else if(transition.prev_status == NodeStatus::IDLE && transition.status != NodeStatus::IDLE)
244+
idle_counter--;
245+
246+
transition.nearest_restart_transition_index = nearest_restart_transition_index;
228247

229248
_transitions.push_back(transition);
230249
}
@@ -307,12 +326,10 @@ void SidepanelReplay::onRowChanged(int current_row)
307326
node_status.push_back( { index, NodeStatus::IDLE} );
308327
}
309328

310-
// THIS CAN BE OPTIMIZED, but it is so fast that I don't even care... for the time being.
311-
for (int t = 0; t <= current_row; t++)
329+
for (int t = _transitions[current_row].nearest_restart_transition_index; t <= current_row; t++)
312330
{
313331
auto& trans = _transitions[t];
314-
node_status[ trans.index ].second = trans.status;
315-
//qDebug() << trans.index << " : " << tr(toStr(trans.status));
332+
node_status.push_back( { trans.index, trans.status} );
316333
}
317334

318335
emit changeNodeStyle( bt_name, node_status );

bt_editor/sidepanel_replay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ private slots:
6969
double timestamp;
7070
NodeStatus prev_status;
7171
NodeStatus status;
72+
bool is_tree_restart;
73+
int nearest_restart_transition_index;
7274
};
7375
std::vector<Transition> _transitions;
7476
std::vector< std::pair<double,int>> _timepoint;

bt_editor/utils.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,25 +456,54 @@ BuildTreeFromFlatbuffers(const Serialization::BehaviorTree *fb_behavior_tree)
456456
}
457457

458458
std::pair<QtNodes::NodeStyle, QtNodes::ConnectionStyle>
459-
getStyleFromStatus(NodeStatus status)
459+
getStyleFromStatus(NodeStatus status, NodeStatus prev_status)
460460
{
461461
QtNodes::NodeStyle node_style;
462462
QtNodes::ConnectionStyle conn_style;
463463

464+
float penWidth = 3.0;
465+
464466
conn_style.HoveredColor = Qt::transparent;
465467

468+
//printf("status=%d, old=%d\n", status, prev_status);
469+
466470
if( status == NodeStatus::IDLE )
467471
{
472+
if(prev_status != NodeStatus::IDLE){
473+
node_style.PenWidth *= penWidth;
474+
node_style.HoveredPenWidth = node_style.PenWidth;
475+
476+
if( prev_status == NodeStatus::SUCCESS )
477+
{
478+
node_style.NormalBoundaryColor =
479+
node_style.ShadowColor = QColor(100, 150, 100);
480+
conn_style.NormalColor = node_style.NormalBoundaryColor;
481+
}
482+
else if( prev_status == NodeStatus::RUNNING )
483+
{
484+
node_style.NormalBoundaryColor =
485+
node_style.ShadowColor = QColor(150, 130, 40);
486+
conn_style.NormalColor = node_style.NormalBoundaryColor;
487+
}
488+
else if( prev_status == NodeStatus::FAILURE )
489+
{
490+
node_style.NormalBoundaryColor =
491+
node_style.ShadowColor = QColor(150, 80, 80);
492+
conn_style.NormalColor = node_style.NormalBoundaryColor;
493+
}
494+
}
495+
468496
return {node_style, conn_style};
469497
}
470498

471-
node_style.PenWidth *= 3.0;
499+
node_style.PenWidth *= penWidth;
472500
node_style.HoveredPenWidth = node_style.PenWidth;
473501

474502
if( status == NodeStatus::SUCCESS )
475503
{
476504
node_style.NormalBoundaryColor =
477505
node_style.ShadowColor = QColor(51, 200, 51);
506+
node_style.ShadowColor = QColor(51, 250, 51);
478507
conn_style.NormalColor = node_style.NormalBoundaryColor;
479508
}
480509
else if( status == NodeStatus::RUNNING )

bt_editor/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ AbsBehaviorTree BuildTreeFromXML(const QDomElement &bt_root, const NodeModels &m
2727
void NodeReorder(QtNodes::FlowScene &scene, AbsBehaviorTree &abstract_tree );
2828

2929
std::pair<QtNodes::NodeStyle, QtNodes::ConnectionStyle>
30-
getStyleFromStatus(NodeStatus status);
30+
getStyleFromStatus(NodeStatus status, NodeStatus prev_status);
3131

3232
QtNodes::Node* GetParentNode(QtNodes::Node* node);
3333

0 commit comments

Comments
 (0)