Example #1
0
int DynOptionswx::SetOptions(OpenBabel::OBConversion& Conv, OpenBabel::OBConversion::Option_type opttyp)
{
  //Now sets options directly in OBConversion
  int count=0;
  OMapType::iterator itr;
  for (itr = OptionMap.begin(); itr != OptionMap.end(); ++itr)
  {
    if(itr->first.empty()) continue; //just a caption or a line

    wxString oname = itr->first;
    wxString txt;

    wxCheckBox* pChk = dynamic_cast<wxCheckBox*> (itr->second);
    if(pChk)
    {
      if(!pChk->IsChecked())
      {
        // if a checkbox is not checked, ignore the subsidiary editboxes also
        while(!(++itr)->first.empty()&& itr->first[0]==_T(' '));
        --itr;
        continue;
      }
    }
    else
    {
      wxRadioButton* pRadio = dynamic_cast<wxRadioButton*> (itr->second);
      if(pRadio)
      {
        if(pRadio->GetValue())
          continue;
      }
      else
      {
        wxTextCtrl* pText = dynamic_cast<wxTextCtrl*> (itr->second);
        if(pText)
        {
          txt = pText->GetValue();
          if(txt.IsEmpty()) continue;
          oname = itr->first;
        }
      }
    }

    //Get the contents of subsequent editboxes
    OMapType::iterator itr2 = itr;
    while(++itr2!= OptionMap.end())
    {
      if((itr2->first).empty() || itr2->first[0]!=_T(' ')) //subsequent editboxes have the name preceded by a space
        break;
      txt = txt + _T(' ') + static_cast<wxTextCtrl*>(itr2->second)->GetValue();
      ++itr;
    }
    txt.Trim(true); txt.Trim(false);
    Conv.AddOption(oname.mb_str(), opttyp, txt.mb_str());
    ++count;

  }
  return count;
}
void ReadFileThread::run()
{
  // Check that the file can be read from disk
  if (!MoleculeFile::canOpen(m_moleculeFile->m_fileName, QFile::ReadOnly | QFile::Text)) {
    // Cannot read the file
    m_moleculeFile->m_error.append(QObject::tr("File %1 cannot be opened for reading.")
                                   .arg(m_moleculeFile->m_fileName));
    return;
  }

  // Construct the OpenBabel objects, set the file type
  OpenBabel::OBConversion conv;
  OpenBabel::OBFormat *inFormat;
  if (!m_moleculeFile->m_fileType.isEmpty() &&
      !conv.SetInFormat(m_moleculeFile->m_fileType.toAscii().data())) {
    // Input format not supported
    m_moleculeFile->m_error.append(
          QObject::tr("File type '%1' is not supported for reading.")
          .arg(m_moleculeFile->m_fileType));
    return;
  }
  else {
    inFormat = conv.FormatFromExt(m_moleculeFile->m_fileName.toAscii().data());
    if (!inFormat || !conv.SetInFormat(inFormat)) {
      // Input format not supported
      m_moleculeFile->m_error
          .append(QObject::tr("File type for file '%1' is not supported for reading.")
                  .arg(m_moleculeFile->m_fileName));
      return;
    }
  }

  // set any options
  if (!m_moleculeFile->m_fileOptions.isEmpty()) {
    foreach(const QString &option, m_moleculeFile
            ->m_fileOptions.split('\n', QString::SkipEmptyParts)) {
      conv.AddOption(option.toAscii().data(), OBConversion::INOPTIONS);
    }
  }