示例#1
0
void Group::loadFromFile(QString const& filePath)
{
   QFileInfo info(filePath);
   QString name(info.completeBaseName());
   setText(name);

   setFlags(Qt::ItemIsSelectable |  Qt::ItemIsEnabled);

   Parser::ParseFile parser(filePath);
   parser.start();
   parser.wait();

   QStringList errors(parser.errors());
   if (!errors.isEmpty()) {
      QMsgBox::warning(0, "IQmol", errors.join("\n"));
   }

   IQmol::Data::Bank& bank(parser.data());
   Factory& factory(Factory::instance()); 
   List data(factory.toLayers(bank));
   List::iterator iter;

   for (iter = data.begin(); iter != data.end(); ++iter) {
       addAtoms((*iter)->findLayers<Atom>(Children));
       addBonds((*iter)->findLayers<Bond>(Children));
  }
}
void TensegrityModel::addBondGroups(tgStructure& structure, const Yam& bond_groups, tgBuildSpec& spec) {
    if (!bond_groups) return;

    // go through first level keys
    for (YAML::const_iterator firstLvl = bond_groups.begin(); firstLvl != bond_groups.end(); ++firstLvl) {
        std::string bonds;
        std::string tags;
        bool bondsSet = false;
        bool tagsSet = false;

        std::string firstLvlKey = firstLvl->first.as<std::string>();
        Yam firstLvlContent = firstLvl->second;
        // bonds must use the '/' notation
        if (firstLvlKey.find("/") == std::string::npos) {  // firstLvlKey is a tag
            tags = firstLvlKey;
            tagsSet = true;
        }
        else { // firstLvlKey is a bond
            bonds = firstLvlKey;
            bondsSet = true;
        }

        // go through second level keys
        for (YAML::const_iterator secondLvl = firstLvlContent.begin(); secondLvl != firstLvlContent.end(); ++secondLvl) {
            std::string secondLvlKey = secondLvl->first.as<std::string>();
            Yam secondLvlContent = secondLvl->second;
            if (secondLvlKey.find("/") == std::string::npos) { // secondLvlKey is a tag
                // a bond must be nested inside a tag or vice versa
                if (tagsSet) throw std::invalid_argument("Invalid nesting of tags: "+ secondLvlKey);
                tags = secondLvlKey;
            }
            else { // secondLvlKey is a bond
                if (bondsSet) throw std::invalid_argument("Invalid nesting of bonds: " + secondLvlKey);
                bonds = secondLvlKey;
            }
            addBonds(structure, bonds, tags, secondLvlContent, spec);
        }
    }
}