Example #1
0
OpenRAVE::BaseXMLReader::ProcessElement kdata_parser::startElement(const std::string& name, const OpenRAVE::AttributesList& atts)
{
   if (name == "spheres")
   {
      if (this->inside_spheres) RAVELOG_ERROR("you can't have <spheres> inside <spheres>!\n");
      this->inside_spheres = true;
      return PE_Support;
   }
   if (name == "sphere")
   {
      struct sphere * s;
      struct sphereelem * e;
      if (!this->inside_spheres) { RAVELOG_ERROR("you can't have <sphere> not inside <spheres>!\n"); return PE_Pass; }
      s = (struct sphere *) malloc(sizeof(struct sphere));
      for(OpenRAVE::AttributesList::const_iterator itatt = atts.begin(); itatt != atts.end(); ++itatt)
      {
         if (itatt->first=="link")
            strcpy(s->linkname, itatt->second.c_str());
         else if (itatt->first=="radius")
            s->radius = strtod(itatt->second.c_str(), 0);
         else if (itatt->first=="pos")
            sscanf(itatt->second.c_str(), "%lf %lf %lf", &s->pos[0], &s->pos[1], &s->pos[2]);
         else
            RAVELOG_ERROR("unknown attribute %s=%s!\n",itatt->first.c_str(),itatt->second.c_str());
      }
      /* insert at head of kdata list */
      e = (struct sphereelem *) malloc(sizeof(struct sphereelem));
      e->s = s;
      e->next = this->d->sphereelems;
      this->d->sphereelems = e;
      return PE_Support;
   }
   return PE_Pass;
}
OpenRAVE::BaseXMLReader::ProcessElement 
kdata_parser::startElement(const std::string& name, 
                           const OpenRAVE::AttributesList& atts)
{

   if (name == "ignorables"){
      if (this->inside_spheres) {
          RAVELOG_ERROR("you can't have <ignorables> inside <spheres>!\n");
      }
      if (this->inside_ignorables) {
          RAVELOG_ERROR("you can't have <ignorables> inside <ignorables>!\n");
      }

      this->inside_ignorables = true;
      return PE_Support;
   }

   else if (name == "ignore"){
      if (!this->inside_ignorables) {
          RAVELOG_ERROR("you can't have <ignore> "
                        "not inside <ignorables>!\n");
          return PE_Pass;
      }
      if (this->inside_spheres) {
          RAVELOG_ERROR("you can't have <ignore> "
                        "inside <spheres>!\n");
          return PE_Pass;
      }
      
      //increase the size of the vector,
      //    add an ignorable pair to the end.
      d->ignorables.resize( d->ignorables.size() + 1 );

      //iterate through the arguments, and assign things to the to
      for(OpenRAVE::AttributesList::const_iterator itatt = atts.begin();
          itatt != atts.end();
          ++itatt)
      {
         if (itatt->first=="link1"){
            d->ignorables.back().first = itatt->second;
         }else if (itatt->first=="link2"){
            d->ignorables.back().second = itatt->second;
         }else{
            RAVELOG_ERROR("unknown attribute %s=%s!\n",
                            itatt->first.c_str(),itatt->second.c_str());
         }
      }

      return PE_Support;
   }


   else if (name == "spheres")
   {
      if (this->inside_spheres) {
          RAVELOG_ERROR("you can't have <spheres> inside <spheres>!\n");
      }
      if (this->inside_ignorables) {
          RAVELOG_ERROR("you can't have <spheres> inside <ignorables>!\n");
      }

      this->inside_spheres = true;
      return PE_Support;
   }
   else if (name == "sphere")
   {

      if (!this->inside_spheres) {
          RAVELOG_ERROR("you can't have <sphere> not inside <spheres>!\n");
          return PE_Pass;
      }
      if (this->inside_ignorables) {
          RAVELOG_ERROR("you can't have <sphere> inside <ignorables>!\n");
          return PE_Pass;
      }
      
      //increase the size of the vector, add a sphere to the end.
      d->spheres.resize( d->spheres.size() + 1 );
      Sphere & current_sphere = d->spheres.back();

      //iterate through the arguments, and assign things to the to
      for(OpenRAVE::AttributesList::const_iterator itatt = atts.begin();
          itatt != atts.end();
          ++itatt)
      {
         if (itatt->first=="link"){
            current_sphere.linkname = itatt->second;
         }else if (itatt->first=="radius"){
            current_sphere.radius = strtod(itatt->second.c_str(), 0);
         }else if (itatt->first=="pos"){
            double pose[3];
            sscanf(itatt->second.c_str(), "%lf %lf %lf",    
                   &pose[0], &pose[1], &pose[2] );
            current_sphere.position = OpenRAVE::Vector( pose );
         }else if (itatt->first =="inactive"){
             if ( itatt->second =="true" ){
                current_sphere.inactive = true;
             }
         }else{
            RAVELOG_ERROR("unknown attribute %s=%s!\n",
                            itatt->first.c_str(),itatt->second.c_str());
         }
      }

      return PE_Support;
   }

   return PE_Pass;
}