@@ -393,14 +393,36 @@ QtNodes::Node* GraphicContainer::substituteNode(Node *old_node, const QString& n
393393
394394 auto & new_node = scene ()->createNodeAtPos ( new_node_ID, new_node_ID, prev_pos);
395395
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+
396418 QPointF new_pos = prev_pos;
397419 double new_width = new_node.nodeGeometry ().width ();
398420
399421 new_pos.setX ( prev_pos.x () - (new_width - prev_width)*0.5 );
400422 _scene->setNodePosition (new_node, new_pos);
401423
402424 if ( old_node->nodeDataModel ()->nPorts ( PortType::In ) == 1 &&
403- new_node.nodeDataModel ()->nPorts ( PortType::In ) == 1 )
425+ new_node.nodeDataModel ()->nPorts ( PortType::In ) == 1 )
404426 {
405427 auto conn_in = old_node->nodeState ().connections (PortType::In, 0 );
406428 for (auto it: conn_in)
@@ -411,7 +433,7 @@ QtNodes::Node* GraphicContainer::substituteNode(Node *old_node, const QString& n
411433 }
412434
413435 if ( old_node->nodeDataModel ()->nPorts ( PortType::Out ) == 1 &&
414- new_node.nodeDataModel ()->nPorts ( PortType::Out ) == 1 )
436+ new_node.nodeDataModel ()->nPorts ( PortType::Out ) == 1 )
415437 {
416438 auto conn_in = old_node->nodeState ().connections (PortType::Out, 0 );
417439 for (auto it: conn_in)
@@ -586,7 +608,7 @@ void GraphicContainer::recursiveLoadStep(QPointF& cursor,
586608
587609 for (auto & port_it: abs_node->ports_mapping )
588610 {
589- bt_node->setParameterValue ( port_it.first , port_it.second );
611+ bt_node->setPortMapping ( port_it.first , port_it.second );
590612 }
591613 bt_node->initWidget ();
592614
0 commit comments