@@ -393,14 +393,36 @@ QtNodes::Node* GraphicContainer::substituteNode(Node *old_node, const QString& n
393
393
394
394
auto & new_node = scene ()->createNodeAtPos ( new_node_ID, new_node_ID, prev_pos);
395
395
396
+ auto bt_old_node = dynamic_cast <BehaviorTreeDataModel*>( old_node->nodeDataModel ());
397
+ auto bt_new_node = dynamic_cast <BehaviorTreeDataModel*>( new_node.nodeDataModel ());
398
+
399
+ if ( bt_old_node && bt_new_node)
400
+ {
401
+ // if the old one contains an edited instance name, use it in new_node
402
+ if ( bt_old_node->instanceName () != bt_old_node->registrationName () &&
403
+ bt_new_node->model ().type != NodeType::SUBTREE )
404
+ {
405
+ bt_new_node->setInstanceName ( bt_old_node->instanceName () );
406
+ }
407
+ // if the old one contains an editedport remapping, use it in new_node
408
+ for (const auto & old_it: bt_old_node->getCurrentPortMapping () )
409
+ {
410
+ auto new_mapping = bt_new_node->getCurrentPortMapping ();
411
+ if ( old_it.second .isEmpty () == false && new_mapping.count ( old_it.first ) )
412
+ {
413
+ bt_new_node->setPortMapping ( old_it.first , old_it.second );
414
+ }
415
+ }
416
+ }
417
+
396
418
QPointF new_pos = prev_pos;
397
419
double new_width = new_node.nodeGeometry ().width ();
398
420
399
421
new_pos.setX ( prev_pos.x () - (new_width - prev_width)*0.5 );
400
422
_scene->setNodePosition (new_node, new_pos);
401
423
402
424
if ( old_node->nodeDataModel ()->nPorts ( PortType::In ) == 1 &&
403
- new_node.nodeDataModel ()->nPorts ( PortType::In ) == 1 )
425
+ new_node.nodeDataModel ()->nPorts ( PortType::In ) == 1 )
404
426
{
405
427
auto conn_in = old_node->nodeState ().connections (PortType::In, 0 );
406
428
for (auto it: conn_in)
@@ -411,7 +433,7 @@ QtNodes::Node* GraphicContainer::substituteNode(Node *old_node, const QString& n
411
433
}
412
434
413
435
if ( old_node->nodeDataModel ()->nPorts ( PortType::Out ) == 1 &&
414
- new_node.nodeDataModel ()->nPorts ( PortType::Out ) == 1 )
436
+ new_node.nodeDataModel ()->nPorts ( PortType::Out ) == 1 )
415
437
{
416
438
auto conn_in = old_node->nodeState ().connections (PortType::Out, 0 );
417
439
for (auto it: conn_in)
@@ -586,7 +608,7 @@ void GraphicContainer::recursiveLoadStep(QPointF& cursor,
586
608
587
609
for (auto & port_it: abs_node->ports_mapping )
588
610
{
589
- bt_node->setParameterValue ( port_it.first , port_it.second );
611
+ bt_node->setPortMapping ( port_it.first , port_it.second );
590
612
}
591
613
bt_node->initWidget ();
592
614
0 commit comments