Exemplo n.º 1
0
//-----------------------------------------------------------------------------
bool exporter_c::write_analyzer_file_element( xml_element_ptr parent ) {
  xml_element_ptr top, element;
  xml_attribute_ptr attribute;
  //unsigned column = 1;

  // create the file element as the top (root) of this hierarchy
  top = xml_element_ptr( new xml_element_c() );
  top->set_name( "File" );

  // specify the type
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "type" );
  attribute->set_value( "analyzer" );
  top->append( attribute );

  // specify the file name
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "name" );
  attribute->set_value( _analyzer_file );
  top->append( attribute );

  // add this hierarchy to the parent node
  parent->append( top );

  return true;
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
bool exporter_c::write_trial_file_element( xml_element_ptr parent, trial_ptr ex_trial, std::string delimiter ) {
  xml_element_ptr top, element;
  xml_attribute_ptr attribute;
  unsigned column = 1;

  // create the file element as the top (root) of this hierarchy
  top = xml_element_ptr( new xml_element_c() );
  top->set_name( "File" );

  // specify the type
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "type" );
  attribute->set_value( "trial" );
  top->append( attribute );

  // specify the file name
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "name" );
  attribute->set_value( _trial_file );
  top->append( attribute );

  // specify a delimiter for the flat file
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "delimiter" );
  attribute->set_value( delimiter );
  top->append( attribute );

  // add a time field element as a leaf of top
  add_field_element( top, "time", column );

  // iterate over the models and add each component
  for( unsigned i = 0; i < ex_trial->models.size(); i++ ) {
    model_ptr model = ex_trial->models[i];
    
    element = xml_element_ptr( new xml_element_c() );
    element->set_name( "Model" );
    attribute = xml_attribute_ptr( new xml_attribute_c() );
    attribute->set_name( "id" );
    attribute->set_value( model->id );
    element->append( attribute );
    for( unsigned j = 0; j < model->links.size(); j++ ) {
      link_ptr link = model->links[j];
      write_link_element( element, link, column );
    }
    for( unsigned j = 0; j < model->joints.size(); j++ ) {
      joint_ptr joint = model->joints[j];
      write_joint_element( element, joint, column );
    }
    top->append( element );
  }

  // add this hierarchy to the parent node
  parent->append( top );

  // generate the column map
  _trial_column_map->map_trial_element( top );

  return true;
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------------
bool exporter_c::write_scenario_element( xml_element_ptr parent, scenario_ptr scenario, analyzer_ptr analyzer, trial_ptr trial, solution_ptr solution, std::string delimiter ) {
  xml_c xml;
  xml_element_ptr top, element;
  xml_attribute_ptr attribute;

  assert( analyzer );  // warning supression

  top = xml_element_ptr( new xml_element_c() );
  top->set_name( "Scenario" );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "id" );
  attribute->set_value( scenario->id );
  top->append( attribute );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "package-id" );
  attribute->set_value( scenario->package_id );
  top->append( attribute );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "sample-rate" );
  attribute->set_value( scenario->sample_rate );
  top->append( attribute );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "sample-start-time" );
  attribute->set_value( scenario->sample_start_time );
  top->append( attribute );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "sample-end-time" );
  attribute->set_value( scenario->sample_end_time );
  top->append( attribute );

  element = xml_element_ptr( new xml_element_c() );
  element->set_name( "Description" );
  element->set_value( scenario->description );
  top->append( element );

  for( unsigned i = 0; i < scenario->uris.size(); i++ ) {
    element = xml_element_ptr( new xml_element_c() );
    element->set_name( "URI" );
    element->set_value( scenario->uris[i] );
    top->append( element );
  }

  write_analyzer_file_element( top );
  write_trial_file_element( top, trial, delimiter );
  write_solution_file_element( top, solution, delimiter );

  parent->append( top );

  return true;
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------
bool xml_c::process_tixml_element( void* tixml_element, xml_element_ptr element ) {
  // TODO: robust error checking
 
  TiXmlElement* tixml_e = (TiXmlElement*) tixml_element;
  const char* pkey = tixml_e->Value();
  const char* ptext = tixml_e->GetText();

  element->set_name( pkey );
  if( ptext ) 
    element->set_value( ptext );

  TiXmlAttribute* a = tixml_e->FirstAttribute();
  while( a!= NULL ) {
    std::string name = a->Name();
    std::string value = a->Value();
    
    xml_attribute_ptr attrib = xml_attribute_ptr( new xml_attribute_c() );
    attrib->set_name( a->Name() );
    attrib->set_value( a->Value() );
    element->append( attrib );

    a = a->Next();
  }

  TiXmlElement* tixml_child;

  for( tixml_child = tixml_e->FirstChildElement(); tixml_child != NULL; tixml_child = tixml_child->NextSiblingElement() ) {
    xml_element_ptr child = xml_element_ptr( new xml_element_c() );
    element->append( child );
    process_tixml_element( tixml_child, child );
  }
 

  return true;
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
bool exporter_c::add_field_element( xml_element_ptr parent, std::string name, unsigned& column, unsigned size ) {
  xml_element_ptr element;
  xml_attribute_ptr attribute;

  element = xml_element_ptr( new xml_element_c() );
  element->set_name( "Field" );
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "name" );
  attribute->set_value( name );
  element->append( attribute );
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "size" );
  attribute->set_value( size );
  element->append( attribute );
  add_column_attribute( element, column, size );
  parent->append( element );

  return true;
}
Exemplo n.º 6
0
//-----------------------------------------------------------------------------
bool exporter_c::add_column_attribute( xml_element_ptr element, unsigned& column, unsigned size ) {
#ifdef DEFINE_COLUMNS
  xml_attribute_ptr attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "column" );
  attribute->set_value( column );
  element->append( attribute );
  column += size;
#endif
  return true;
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
bool exporter_c::write_joint_element( xml_element_ptr parent, joint_ptr joint, unsigned& column, bool write_controls ) {
  xml_element_ptr top, element;
  xml_attribute_ptr attribute;

  top = xml_element_ptr( new xml_element_c() );
  top->set_name( "Joint" );
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "id" );
  attribute->set_value( joint->id );
  top->append( attribute );
 
  add_field_element( top, "position", column, joint->state.size_q() );
  add_field_element( top, "velocity", column, joint->state.size_dq() );
  if( write_controls && joint->control.size() )
    add_field_element( top, "control", column, joint->control.size() );

  parent->append( top );

  return true;
}
Exemplo n.º 8
0
//-----------------------------------------------------------------------------
bool exporter_c::write_link_element( xml_element_ptr parent, link_ptr link, unsigned& column ) {
  xml_element_ptr top, element;
  xml_attribute_ptr attribute;

  top = xml_element_ptr( new xml_element_c() );
  top->set_name( "Link" );
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "id" );
  attribute->set_value( link->id );
  top->append( attribute );
 
  add_field_element( top, "position", column, 3 );

  add_field_element( top, "rotation", column, 4 );

  add_field_element( top, "linear-velocity", column, 3 );

  add_field_element( top, "angular-velocity", column, 3 );

  parent->append( top );

  return true;
}
Exemplo n.º 9
0
//-----------------------------------------------------------------------------
bool exporter_c::write_analyzer_element( xml_element_ptr parent, analyzer_ptr analyzer ) {
  xml_c xml;
  xml_element_ptr top, element;
  xml_attribute_ptr attribute;

  // Note: really only should have to specify the filename for scenario 
  // generation.  The rest of the record needs to be exported in a separate 
  // framework as the server needs to validate the pathing and the typing
  // and it requires a compilation step on the server anyway.

  top = xml_element_ptr( new xml_element_c() );
  top->set_name( "Analyzer" );

  // specify the scenario
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "id" );
  attribute->set_value( analyzer->scenario_id );
  top->append( attribute );

  // specify the type
  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "type" );
  if( analyzer->type == Reveal::Core::analyzer_c::PLUGIN ) 
    attribute->set_value( "plugin" );
  else 
    attribute->set_value( "script" );
  top->append( attribute );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "source-path" );
  attribute->set_value( analyzer->source_path );
  top->append( attribute );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "build-path" );
  attribute->set_value( analyzer->build_path );
  top->append( attribute );

  attribute = xml_attribute_ptr( new xml_attribute_c() );
  attribute->set_name( "build-target" );
  attribute->set_value( analyzer->build_target );
  top->append( attribute );

  // iterate over any keys and write them as a new element
  for( unsigned i = 0; i < analyzer->keys.size(); i++ ) {
    element = xml_element_ptr( new xml_element_c() );
    element->set_name( "Datum" );

    // write out any keys
    attribute = xml_attribute_ptr( new xml_attribute_c() );
    attribute->set_name( "key" );
    attribute->set_value( analyzer->keys[i] );
    element->append( attribute );

    if( analyzer->keys.size() == analyzer->labels.size() ) {
      // if there are the same number of keys and labels, write out labels too
  
      attribute = xml_attribute_ptr( new xml_attribute_c() );
      attribute->set_name( "label" );
      attribute->set_value( analyzer->labels[i] );
      element->append( attribute );
    }
    top->append( element );
  }
    
  parent->append( top );

  return true;

}