Пример #1
0
   /**
   * Remove a Link.
   */
   void LinkMaster::removeLink(int id)
   {
      Link* linkPtr = &link(id);
      int  atom0Id;
      int  atom1Id;

      if (!link(id).isActive()) {
        UTIL_THROW("Attempt to remove a nonactive link");
      }
      atom0Id = linkPtr->atom0().id();
      atom1Id = linkPtr->atom1().id();
      // Remove link from atom0 and atom1 link sets
      if (!atomLinkSets_[atom0Id].isElement(*linkPtr)) {
        UTIL_THROW("Link is not in atomLinkSets of atom0");
      }
      if (!atomLinkSets_[atom1Id].isElement(*linkPtr)) {
        UTIL_THROW("Link is not in atomLinkSets of atom1");
      }
      atomLinkSets_[atom0Id].remove(*linkPtr);
      atomLinkSets_[atom1Id].remove(*linkPtr);

      // Notify observers of removal of this Link.
      // Notify before clearing Link so atomPtrs and typeId are available.
      LinkRemoveEvent event(linkPtr);
      Notifier<LinkRemoveEvent>::notifyObservers(event);

      // Clear the link: nullify atomPtrs, set typeId = -1, isActive = false
      linkPtr->clear();

      // Return link to reservoir 
      linkSet_.remove(*linkPtr);
      reservoir_.push(*linkPtr);

   }
Пример #2
0
bool parseLink(Link &link, TiXmlElement* config)
{

  link.clear();

  const char *name_char = config->Attribute("name");
  if (!name_char)
  {
    logError("No name given for the link.");
    return false;
  }
  link.name = std::string(name_char);

  // Inertial (optional)
  TiXmlElement *i = config->FirstChildElement("inertial");
  if (i)
  {
    resetPtr(link.inertial,new Inertial());
    if (!parseInertial(*link.inertial, i))
    {
      logError("Could not parse inertial element for Link [%s]", link.name.c_str());
      return false;
    }
  }

  // Multiple Visuals (optional)
  for (TiXmlElement* vis_xml = config->FirstChildElement("visual"); vis_xml; vis_xml = vis_xml->NextSiblingElement("visual"))
  {

    VisualPtr vis;
    resetPtr(vis,new Visual());
    if (parseVisual(*vis, vis_xml))
    {
      link.visual_array.push_back(vis);
    }
    else
    {
      resetPtr(vis);
      logError("Could not parse visual element for Link [%s]", link.name.c_str());
      return false;
    }
  }

  // Visual (optional)
  // Assign the first visual to the .visual ptr, if it exists
  if (!link.visual_array.empty())
    link.visual = link.visual_array[0];

  // Multiple Collisions (optional)
  for (TiXmlElement* col_xml = config->FirstChildElement("collision"); col_xml; col_xml = col_xml->NextSiblingElement("collision"))
  {
    CollisionPtr col;
    resetPtr(col,new Collision());
    if (parseCollision(*col, col_xml))
    {
      link.collision_array.push_back(col);
    }
    else
    {
      resetPtr(col);
      logError("Could not parse collision element for Link [%s]",  link.name.c_str());
      return false;
    }
  }

  // Collision (optional)
  // Assign the first collision to the .collision ptr, if it exists
  if (!link.collision_array.empty())
    link.collision = link.collision_array[0];
}