#include "Residue_impl.h"

#include "Array_of_ref.h"
#include "Model.h"
#include "Atom_kit.h"
#include "Joint.h"

namespace MM
{

/*Text const & Residue_impl::
name () const
{
    return name_;//fix with classification
}//*/
/*
Array_of <Atom> & Residue::atom()
{
    FIX;
    static Array_of_ref <Atom> dummy;
    return dummy;
}//*/

Residue_impl::
//Residue_impl (Model & model)
Residue_impl ()
:
    //model_ (model),
    local_id_   ("-"),    //fix to ""
    name_       ("-"),
    short_alias_("-"),
    alias_      ("-")
{
}

void Residue_impl::
add_atom (Atom & ref)
{
/*    Residue & old_res = ref.kit().in_residue ();

    if (&old_res == (Residue*)this)
        return;//*/

    atom_group_.push_back (ref);
    ref.kit().set_residue (*this);
}

void Residue_impl::
remove_dead_atoms ()
{
    atom_group_.stable_remove_deads ();

/*    int i;
    Array_of_ref <Atom> tmp_atom;

    for (i=0;  i<group_.size ();  ++i)
        if (group_[i].kit().is_alive())
            tmp_atom.push_back (group_[i]);

    group_.clear();

    for (i=0;  i<tmp_atom.size();  ++i)
        group_.push_back (tmp_atom[i]); //*/
}

void Residue_impl::
add_joint (Joint &joint)
{
    joint_group_.push_back (joint);
    joint.set_residue (*this);
}
/*
bool Residue_impl::
has_left_joint () const
{
    switch (joint_group_.size())
    {
    case 0:
        return false;
    case 1:
            return (&joint_group_[0].stub_atom().kit().in_residue().
                            joint(0).stub_atom().kit().in_residue()
                            != (Residue*)this);
    default:
        return true;
    }
}

bool Residue_impl::
has_right_joint () const
{
    switch (joint_group_.size())
    {
    case 0:
        return false;
    case 1:
            return (&joint_group_[0].stub_atom().kit().in_residue().
                            joint(0).stub_atom().kit().in_residue()
                            == (Residue*)this);
    default:
        return true;
    }
}//*/

Joint & Residue_impl::
left_joint () 
{
    //REQUIRE ("", has_left_joint());
    return joint_group_[0];
}

Joint & Residue_impl::
right_joint () 
{
    //REQUIRE ("", has_right_joint());

    if (joint_group_.size() == 1)
        return joint_group_[0];
    return joint_group_[1];
}

void Residue_impl::
remove_dead_joints ()
{
    joint_group_.stable_remove_deads();
}

}//MM






