Logo Search packages:      
Sourcecode: massxpert version File versions

bool massXpert::PolChemDef::writeXmlFile (  ) 

Write the polymer chemistry definition to file.

Returns:
true if successful, false otherwise.

Definition at line 1307 of file polChemDef.cpp.

References formatXmlDtd(), massXpert::IonizeRule::formatXmlIonizeRuleElement(), massXpert::Formula::formula(), m_atomList, m_cleaveSpecList, m_codeLength, m_crossLinkerList, m_filePath, m_fragSpecList, m_ionizeRule, m_leftCap, m_modifList, m_monomerList, m_name, m_rightCap, and massXpert::IonizeRule::setLevel().

  {
    QString *string = 0;
    QString indent("  ");
    QString lead;

    int offset = 0;
    int iter = 0;
  
    // We are asked to send an xml description of the polymer chemistry
    // definition.

    QFile file(m_filePath);
  
    if (!file.open(QIODevice::WriteOnly))
      {
      qDebug() << __FILE__ << __LINE__
              << "Failed to open file" << m_filePath
              << "for writing.";
      
      return false;
      }

    QTextStream stream(&file);
    stream.setCodec("UTF-8");
  
    // The DTD
    string =   formatXmlDtd();
    stream << *string;
    delete string;


    // Open the <polchemdefinition> element.
    stream << QString("<polchemdefinition version=\"%1\">\n")
      .arg(POL_CHEM_DEF_FILE_FORMAT_VERSION);

    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }
  
    // Open the <atomdefdata> element.
    stream << QString("%1<atomdefdata>\n")
      .arg(lead);

    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }
  
    // All the atoms in the List.
    for (iter = 0; iter < m_atomList.size(); ++iter)
      {
      string = m_atomList.at(iter)->formatXmlAtomElement(2);
      stream << *string;
      delete string;
      }
  
    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    // Close the <atomdefdata> element.
    stream << QString("%1</atomdefdata>\n")
      .arg(lead);
  
    // Open the <polchemdefdata> element.
    stream << QString("%1<polchemdefdata>\n")
      .arg(lead);

    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1<name>%2</name>\n")
      .arg(lead).arg(m_name);
  
    stream << QString("%1<leftcap>%2</leftcap>\n")
      .arg(lead).arg(m_leftCap.formula());
  
    stream << QString("%1<rightcap>%2</rightcap>\n")
      .arg(lead).arg(m_rightCap.formula());
  
    stream << QString("%1<codelen>%2</codelen>\n")
      .arg(lead).arg(m_codeLength);
  
    // Before writing the ionization rule, set the level to 1. This
    // member datum is set to 0 in the constructor.
    m_ionizeRule.setLevel(1);
    string = m_ionizeRule.formatXmlIonizeRuleElement(offset);
    stream << *string;
    delete string;
  
    stream << QString("%1<monomers>\n")
      .arg(lead);

    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    for (iter = 0 ; iter < m_monomerList.size(); ++iter)
      {
      QString *newString =
        m_monomerList.at(iter)->formatXmlMnmElement(offset);

      stream << *newString;

      delete newString;
      }

    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1</monomers>\n")
      .arg(lead);
  

    stream << QString("%1<modifs>\n")
      .arg(lead);

    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    for (iter = 0 ; iter < m_modifList.size(); ++iter)
      {
      QString *newString = m_modifList.at(iter)->formatXmlMdfElement(offset);

      stream << *newString;

      delete newString;
      }

    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1</modifs>\n")
      .arg(lead);
  

    stream << QString("%1<crosslinkers>\n")
      .arg(lead);

    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    for (iter = 0 ; iter < m_crossLinkerList.size(); ++iter)
      {
      QString *newString = 
        m_crossLinkerList.at(iter)->formatXmlClkElement(offset);

      stream << *newString;

      delete newString;
      }

    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1</crosslinkers>\n")
      .arg(lead);


    stream << QString("%1<cleavespecs>\n")
      .arg(lead);

    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    for (int iter = 0 ; iter < m_cleaveSpecList.size(); ++iter)
      {
      QString *newString = 
        m_cleaveSpecList.at(iter)->formatXmlClsElement(offset);

      stream << *newString;

      delete newString;
      }

    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1</cleavespecs>\n")
      .arg(lead);
    

    stream << QString("%1<fragspecs>\n")
      .arg(lead);


    // Prepare the lead.
    ++offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    for (int iter = 0 ; iter < m_fragSpecList.size(); ++iter)
      {
      QString *newString = 
        m_fragSpecList.at(iter)->formatXmlFgsElement(offset);

      stream << *newString;

      delete newString;
      }

    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1</fragspecs>\n")
      .arg(lead);
  
    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1</polchemdefdata>\n")
      .arg(lead);
  
    // Prepare the lead.
    --offset;  
    lead.clear();
    iter = 0;
    while(iter < offset)
      {
      lead += indent;
      ++iter;
      }

    stream << QString("%1</polchemdefinition>\n")
      .arg(lead);
  
    file.close();

    return true;
  }


Generated by  Doxygen 1.6.0   Back to index