/* massXpert - the true massist's program.

   Copyright(C) 2006,2007 Filippo Rusconi

   http://www.massxpert.org/massXpert

   This file is part of the massXpert project.

   The massxpert project is the successor to the "GNU polyxmass"
   project that is an official GNU project package(see
   www.gnu.org). The massXpert project is not endorsed by the GNU
   project, although it is released ---in its entirety--- under the
   GNU General Public License. A huge part of the code in massXpert
   is actually a C++ rewrite of code in GNU polyxmass. As such
   massXpert was started at the Centre National de la Recherche
   Scientifique(FRANCE), that granted me the formal authorization to
   publish it under this Free Software License.

   This software is free software; you can redistribute it and/or
   modify it under the terms of the GNU  General Public
   License version 3, as published by the Free Software Foundation.
   

   This software is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this software; if not, write to the

   Free Software Foundation, Inc.,

   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/


/////////////////////// Local includes
#include "cleaveOptions.hpp"


namespace massXpert
{

  CleaveOptions::CleaveOptions(PolChemDef *polChemDef, 
				QString name, 
				QString pattern,
				int partials, 
				bool sequenceEmbedded)
    : CleaveSpec(polChemDef, name, pattern), m_partials(partials),
      m_sequenceEmbedded(sequenceEmbedded)
  {
    // Have to be 1 and not 0, otherwise the setting functions ensuring
    // that m_startIonizeLevel>=m_endIonizeLevel will bug.
    m_startIonizeLevel = 1;
    m_endIonizeLevel = 1;
  }


  CleaveOptions::CleaveOptions(const CleaveSpec &cleavespec,
				int partials, 
				bool sequenceEmbedded)
    : CleaveSpec(cleavespec), m_partials(partials),
      m_sequenceEmbedded(sequenceEmbedded)
  {
    // Have to be 1 and not 0, otherwise the setting functions ensuring
    // that m_startIonizeLevel>=m_endIonizeLevel will bug.
    m_startIonizeLevel = 1;
    m_endIonizeLevel = 1;
  }

 
  CleaveOptions::CleaveOptions(const CleaveOptions &other)
    : CleaveSpec(other), 
      m_partials(other.m_partials),
      m_startIonizeLevel(other.m_startIonizeLevel),
      m_endIonizeLevel(other.m_endIonizeLevel),
      m_sequenceEmbedded(other.m_sequenceEmbedded)
  {
  }



  CleaveOptions::~CleaveOptions()
  {
  }


  void 
  CleaveOptions::clone(CleaveOptions *other) const
  {
    Q_ASSERT(other);
  
    CleaveSpec::clone(other);

    other->m_partials = m_partials;
    other->m_startIonizeLevel = m_startIonizeLevel;
    other->m_endIonizeLevel = m_endIonizeLevel;
    other->m_sequenceEmbedded = m_sequenceEmbedded;
  }


  void 
  CleaveOptions::mold(const CleaveOptions &other)
  {
    if (&other == this)
      return;

    CleaveSpec::mold(other);
  
    m_partials = other.m_partials;
    m_startIonizeLevel = other.m_startIonizeLevel;
    m_endIonizeLevel = other.m_endIonizeLevel;
    m_sequenceEmbedded = other.m_sequenceEmbedded;
  }


  void 
  CleaveOptions::setPartials(int value)
  {
    Q_ASSERT(value >= 0);
  
    m_partials = value;
  }

  int 
  CleaveOptions::partials() const
  {
    return m_partials;
  }


  void 
  CleaveOptions::setStartIonizeLevel(int value)
  {
    int local =(value < 0 ) ? abs(value) : value;
  
    if (local <= m_endIonizeLevel)
      {
	m_startIonizeLevel = local;
      }
    else
      {
	m_startIonizeLevel = m_endIonizeLevel; 
	m_endIonizeLevel = local;
      }
  }


  int 
  CleaveOptions::startIonizeLevel() const
  {
    return m_startIonizeLevel;
  }


  void 
  CleaveOptions::setEndIonizeLevel(int value)
  {
    int local =(value < 0) ? abs(value) : value;
  
    if (local > m_startIonizeLevel)
      {
	m_endIonizeLevel = local;
      }
    else
      {
	m_startIonizeLevel = m_endIonizeLevel; 
	m_endIonizeLevel = local;
      }
  }


  int 
  CleaveOptions::endIonizeLevel() const
  {
    return m_endIonizeLevel;
  }


  void  
  CleaveOptions::setIonizeLevels(int value1, int value2)
  {
    if (abs(value1) <= abs(value2))
      {
	m_startIonizeLevel = abs(value1);
	m_endIonizeLevel = abs(value2);
      }
    else
      {
	m_startIonizeLevel = abs(value2);
	m_endIonizeLevel = abs(value1);
      }
  }
  

  void 
  CleaveOptions::setSequenceEmbedded(bool value)
  {
    m_sequenceEmbedded = value;
  }

  
  bool 
  CleaveOptions::isSequenceEmbedded() const
  {
    return m_sequenceEmbedded;
  }

} // namespace massXpert
