/***************************************************************************
 *   Copyright (C) 2005 by Tavarez Arnaud Bakoula                          *
 *   tbakoula@yahoo.fr                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program 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 program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "conversion.h"
#include "site.h"
#include "tick.h"
#include "siterow.h"
#include "tickrow.h"
#include "combinaison.h"
#include "notification.h"

#include <iostream>
using std::cout;

/*!
 *  \fn combinaisonToSiterow
 *  Affects to each site of the specified SiteRow \a siterow the attribute
 *  of the corresponding piece contained in the Combinaison \a cmb.
 */
bool combinaisonToSiterow( Combinaison* cmb, SiteRow* siterow )
{
    if ( !cmb || !siterow )
      return false;

    uint dim = cmb->getDim();
    if ( dim != siterow->getDim() )
      return false;

    for ( uint i = 0; i<dim; i++ )
    {
      Site* site = (Site*) siterow->getCellAt( i );
      site->setColor( (*cmb)[i].getColor() );
    }
    return true;
}

bool siterowToCombinaison( SiteRow* siterow, Combinaison* cmb )
{
    if ( !siterow || !cmb )
      return false;

    uint dim = siterow->getDim();
    if ( dim != cmb->getDim() )
      return false;

    for ( uint i = 0; i<dim; i++ )
    {
      Site* site = (Site*) siterow->getCellAt( i );
      (*cmb)[i].setColor( site->getColor() );
    }
    return true;
}

/*!
 *  \fn notificationToTickrow
 *  Affects to each tick of the specified TickRow \a tickrow the attribute
 *  of the corresponding mark contained in the Notification \a ntf.
 */
bool notificationToTickrow( Notification* ntf, TickRow* tickrow )
{
    if ( !ntf || !tickrow )
      return false;

    uint dim = ntf->getDim();
    if ( dim != tickrow->getDim() )
      return false;

    for ( uint i = 0; i<dim; i++ )
    {
      Tick* tick = (Tick*) tickrow->getCellAt( i );
      tick->setState( (*ntf)[i].getState() );
    }
    return true;
}

bool tickrowToNotification( TickRow* tickrow, Notification* ntf )
{
    if ( !tickrow || !ntf )
      return false;

    uint dim = tickrow->getDim();
    if ( dim != ntf->getDim() )
      return false;

    for ( uint i = 0; i<dim; i++ )
    {
      Tick* tick = (Tick*) tickrow->getCellAt( i );
      (*ntf)[i].setState( tick->getState() );
    }
    return true;
}
