Changeset 140:367aefee6ddf in finroc_plugins_runtime_construction


Ignore:
Timestamp:
17.05.2020 07:59:43 (3 weeks ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Message:

Makes XML structure files support extension in finroc_plugins_parameters: config entries can now also be set for whole port interfaces and composite ports

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tFinstructable.cpp

    r134 r140  
    318318      constructor_params = &(*child_node); 
    319319      ++child_node; 
    320       p_name = child_node->Name(); 
     320      p_name = child_node == node.ChildrenEnd() ? std::string() : child_node->Name(); 
    321321    } 
    322322    if (p_name == "parameters") 
     
    381381} 
    382382 
    383 void tFinstructable::LoadParameter(const rrlib::xml::tNode& node, core::tAbstractPort& parameter_port) 
    384 { 
    385   parameters::internal::tParameterInfo* pi = parameter_port.GetAnnotation<parameters::internal::tParameterInfo>(); 
     383void tFinstructable::LoadParameter(const rrlib::xml::tNode& node, core::tFrameworkElement& parameter_element) 
     384{ 
     385  parameters::internal::tParameterInfo* pi = parameter_element.GetAnnotation<parameters::internal::tParameterInfo>(); 
    386386  bool outermost_group = GetFrameworkElement()->GetParent() == &(core::tRuntimeEnvironment::GetInstance()); 
    387387  if (!pi) 
    388388  { 
    389     FINROC_LOG_PRINT(WARNING, "Port is not a parameter: '", parameter_port, "'. Parameter entry is not loaded."); 
     389    FINROC_LOG_PRINT(WARNING, "Element is not parameter-related: '", parameter_element, "'. Parameter entry is not loaded."); 
    390390  } 
    391391  else 
     
    394394    bool high_precendence = include_instance == nullptr; 
    395395    auto origin = include_instance ? include_instance->origin : nullptr; 
    396     if (outermost_group && node.HasAttribute("cmdline") && (!IsResponsibleForConfigFileConnections(parameter_port))) 
     396    if (outermost_group && parameter_element.IsPort() && node.HasAttribute("cmdline") && (!IsResponsibleForConfigFileConnections(parameter_element))) 
    397397    { 
    398398      pi->SetCommandLineOption(node.GetStringAttribute("cmdline"), high_precendence, origin); 
     
    408408    catch (const std::exception& e) 
    409409    { 
    410       FINROC_LOG_PRINT(WARNING, "Unable to load parameter value for '", parameter_port, "'. ", e); 
     410      FINROC_LOG_PRINT(WARNING, "Unable to load parameter config for '", parameter_element, "'. ", e); 
    411411    } 
    412412  } 
     
    788788      { 
    789789        ProcessParameterLinksNode(*it, *corresponding_element); 
     790 
     791        if (it->HasAttribute("config")) 
     792        { 
     793          core::tFrameworkElement* parameters_interface = corresponding_element->GetChild("Parameters"); 
     794          if (parameters_interface) 
     795          { 
     796            LoadParameter(*it, *parameters_interface); 
     797          } 
     798        } 
    790799      } 
    791800      else 
     
    805814      if (parameter_element && parameter_element->IsPort()) 
    806815      { 
    807         LoadParameter(*it, static_cast<core::tAbstractPort&>(*parameter_element)); 
     816        LoadParameter(*it, *parameter_element); 
    808817      } 
    809818      else 
     
    820829  std::vector<core::tFrameworkElement*> child_elements; 
    821830  std::vector<core::tAbstractPort*> parameter_ports; 
     831  core::tFrameworkElement* parameters_interface = nullptr; 
    822832  for (auto it = element.ChildrenBegin(); it != element.ChildrenEnd(); ++it) 
    823833  { 
    824834    if (it->IsReady()) 
    825835    { 
    826       if (it->GetFlag(tFlag::INTERFACE) && it->GetName() == "Parameters") 
     836      if ((!it->IsPort()) && it->GetFlag(tFlag::INTERFACE) && it->GetFlag(tFlag::PARAMETER_INTERFACE)) 
    827837      { 
    828838        for (auto parameter_it = it->ChildrenBegin(); parameter_it != it->ChildrenEnd(); ++parameter_it) 
     
    833843          } 
    834844        } 
     845        parameters_interface = &*it; 
    835846      } 
    836847      else if (it->IsPort() && it->GetAnnotation<parameters::internal::tParameterInfo>()) 
     
    877888        info->Serialize(parameter_node, true, outermost_group, nullptr); 
    878889      } 
     890      result = true; 
     891    } 
     892  } 
     893 
     894  // Save possible config entry for parameters interface 
     895  if (parameters_interface) 
     896  { 
     897    parameters::internal::tParameterInfo* info = parameters_interface->GetAnnotation<parameters::internal::tParameterInfo>(); 
     898    bool is_responsible_for_parameter_links = IsResponsibleForConfigFileConnections(*parameters_interface); 
     899    if (info && HasNonDefaultFinstructInfo(*info) && is_responsible_for_parameter_links) 
     900    { 
     901      info->Serialize(node, true, false, nullptr); 
    879902      result = true; 
    880903    } 
     
    894917  } 
    895918  return result; 
    896  
    897   /*for (auto it = GetFrameworkElement()->SubElementsBegin(); it != GetFrameworkElement()->SubElementsEnd(); ++it) 
    898   { 
    899     if ((!it->IsPort()) || (!it->IsReady())) 
    900     { 
    901       continue; 
    902     } 
    903  
    904     core::tAbstractPort& port = static_cast<core::tAbstractPort&>(*it); 
    905     bool outermost_group = GetFrameworkElement()->GetParent() == &(core::tRuntimeEnvironment::GetInstance()); 
    906     parameters::internal::tParameterInfo* info = port.GetAnnotation<parameters::internal::tParameterInfo>(); 
    907  
    908     if (info && info->HasNonDefaultFinstructInfo() && (IsResponsibleForConfigFileConnections(port) || (outermost_group && info->GetCommandLineOption().length()))) 
    909     { 
    910       bool parameter_interface = port.GetParent()->GetFlag(tFlag::INTERFACE) || port.GetParent()->GetName() == "Parameters"; // TODO: remove the latter as soon as 
    911       core::tFrameworkElement* target_hierarchy_element = (parameter_interface && port.GetParent()->GetParent()) ? port.GetParent()->GetParent() : port.GetParent(); 
    912  
    913       // Possibly move up hierarchy in XML 
    914       while (!(target_hierarchy_element == current_hierarchy_element || target_hierarchy_element->IsChildOf(*current_hierarchy_element))) 
    915       { 
    916         current_hierarchy_element = current_hierarchy_element->GetParent(); 
    917         current_parameter_links_node = &current_parameter_links_node->Parent(); 
    918       } 
    919       // Possibly create hierarchy in XML 
    920       std::vector<core::tFrameworkElement*> elements_to_add; 
    921       core::tFrameworkElement* element_to_add = target_hierarchy_element; 
    922       while (element_to_add != current_hierarchy_element) 
    923       { 
    924         elements_to_add.push_back(element_to_add); 
    925         element_to_add = element_to_add->GetParent(); 
    926       } 
    927       for (auto it = elements_to_add.rbegin(); it != elements_to_add.rend(); ++it) 
    928       { 
    929         current_parameter_links_node = &current_parameter_links_node->AddChildNode("element"); 
    930         current_parameter_links_node->SetAttribute("name", (*it)->GetName()); 
    931       } 
    932       current_hierarchy_element = target_hierarchy_element; 
    933  
    934       // Save Parameter 
    935       rrlib::xml::tNode& parameter_node = current_parameter_links_node->AddChildNode("parameter"); 
    936       parameter_node.SetAttribute("name", port.GetName()); 
    937  
    938       if (!IsResponsibleForConfigFileConnections(port)) 
    939       { 
    940         parameter_node.SetAttribute("cmdline", info->GetCommandLineOption()); 
    941       } 
    942       else 
    943       { 
    944         info->Serialize(parameter_node, true, outermost_group); 
    945       } 
    946     } 
    947   } 
    948   */ 
    949919} 
    950920 
  • tFinstructable.h

    r134 r140  
    243243   * \param parameter_port Abstract Port that should be a parameter 
    244244   */ 
    245   void LoadParameter(const rrlib::xml::tNode& node, core::tAbstractPort& parameter_port); 
     245  void LoadParameter(const rrlib::xml::tNode& node, core::tFrameworkElement& parameter_element); 
    246246 
    247247  virtual void OnInitialization() override; 
Note: See TracChangeset for help on using the changeset viewer.