Changeset 12:35b3eecd8d06 in finroc_plugins_composite_ports


Ignore:
Timestamp:
14.04.2020 11:54:57 (18 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Message:

Adds parameter to ConnectUnconnectedMatchingInterfaces convenience function

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • auto_connect.cpp

    r11 r12  
    9595} 
    9696 
     97bool ConnectUnconnectedMatchingInterface(core::tFrameworkElement& source_parent, core::tPortGroup& destination_component_interface, core::tAbstractPort& destination_port, bool connect_derived_interfaces, bool connect_to_nested_source_interfaces) 
     98{ 
     99  std::vector<core::tAbstractPort*> unconnected_source_interface_ports; 
     100  for (auto source_port = source_parent.ChildPortsBegin(); source_port != source_parent.ChildPortsEnd(); ++source_port) 
     101  { 
     102    bool already_connected = false; 
     103    for (auto connector = source_port->OutgoingConnectionsBegin(); connector != source_port->OutgoingConnectionsEnd(); ++connector) 
     104    { 
     105      auto aggregator = core::tEdgeAggregator::GetAggregator(connector->Destination()); 
     106      if (aggregator == &destination_component_interface) 
     107      { 
     108        already_connected = true; 
     109        break; 
     110      } 
     111    } 
     112 
     113    if (!already_connected) 
     114    { 
     115      if (source_port->IsReady() && source_port->GetDataType().GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE && (source_port->GetDataType() == destination_port.GetDataType() || (connect_derived_interfaces && rrlib::rtti::conversion::tStaticCastOperation::IsImplicitlyConvertibleTo(source_port->GetDataType(), destination_port.GetDataType())))) 
     116      { 
     117        source_port->ConnectTo(destination_port); 
     118        return true; 
     119      } 
     120      else if (connect_to_nested_source_interfaces) 
     121      { 
     122        unconnected_source_interface_ports.push_back(&*source_port); 
     123      } 
     124    } 
     125  } 
     126 
     127  // still not connected 
     128  assert(destination_port.CountIncomingConnections() == 0); 
     129  for (auto & source_port : unconnected_source_interface_ports) 
     130  { 
     131    if (ConnectUnconnectedMatchingInterface(*source_port, destination_component_interface, destination_port, connect_derived_interfaces, connect_to_nested_source_interfaces)) 
     132    { 
     133      return true; 
     134    } 
     135  } 
     136  return false; 
     137} 
     138 
    97139} 
    98140 
     
    138180} 
    139181 
    140 void ConnectUnconnectedMatchingInterfaces(core::tPortGroup& source_component_interface, core::tPortGroup& destination_component_interface, bool connect_derived_interfaces) 
     182void ConnectUnconnectedMatchingInterfaces(core::tPortGroup& source_component_interface, core::tPortGroup& destination_component_interface, bool connect_derived_interfaces, bool connect_to_nested_source_interfaces) 
    141183{ 
    142184  for (auto destination_port = destination_component_interface.ChildPortsBegin(); destination_port != destination_component_interface.ChildPortsEnd(); ++destination_port) 
     
    144186    if (destination_port->IsReady() && destination_port->GetDataType().GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE && destination_port->CountIncomingConnections() == 0) 
    145187    { 
    146       for (auto source_port = source_component_interface.ChildPortsBegin(); source_port != source_component_interface.ChildPortsEnd(); ++source_port) 
    147       { 
    148         if (source_port->IsReady() && source_port->GetDataType().GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE && (source_port->GetDataType() == destination_port->GetDataType() || (connect_derived_interfaces && rrlib::rtti::conversion::tStaticCastOperation::IsImplicitlyConvertibleTo(source_port->GetDataType(), destination_port->GetDataType())))) 
    149         { 
    150           bool already_connected = false; 
    151           for (auto connector = source_port->OutgoingConnectionsBegin(); connector != source_port->OutgoingConnectionsEnd(); ++connector) 
    152           { 
    153             auto aggregator = core::tEdgeAggregator::GetAggregator(connector->Destination()); 
    154             if (aggregator == &destination_component_interface) 
    155             { 
    156               already_connected = true; 
    157               break; 
    158             } 
    159           } 
    160           if (!already_connected) 
    161           { 
    162             source_port->ConnectTo(*destination_port); 
    163           } 
    164         } 
    165       } 
     188      ConnectUnconnectedMatchingInterface(source_component_interface, destination_component_interface, *destination_port, connect_derived_interfaces, connect_to_nested_source_interfaces); 
    166189    } 
    167190  } 
  • auto_connect.h

    r11 r12  
    9292 * \param destination_component_interface Component interface with incoming data flow 
    9393 * \param connect_derived_interfaces Whether to connect sub- and superclass port composite interfaces 
     94 * \param connect_to_nested_source_interfaces Whether to connect unconnected destination interfaces to nested source interfaces also 
    9495 */ 
    95 void ConnectUnconnectedMatchingInterfaces(core::tPortGroup& source_component_interface, core::tPortGroup& destination_component_interface, bool connect_derived_interfaces = false); 
     96void ConnectUnconnectedMatchingInterfaces(core::tPortGroup& source_component_interface, core::tPortGroup& destination_component_interface, bool connect_derived_interfaces = false, bool connect_to_nested_source_interfaces = false); 
    9697 
    9798//---------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.