/*************************************************************************
 *    CompuCell - A software framework for multimodel simulations of     *
 * biocomplexity problems Copyright (C) 2003 University of Notre Dame,   *
 *                             Indiana                                   *
 *                                                                       *
 * This program is free software; IF YOU AGREE TO CITE USE OF CompuCell  *
 *  IN ALL RELATED RESEARCH PUBLICATIONS according to the terms of the   *
 *  CompuCell GNU General Public License RIDER 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., 675 Mass Ave, Cambridge, MA 02139, USA.        *
 *************************************************************************/

#include "MitosisPluginVelocity.h"

#include <CompuCell3D/Simulator.h>
#include <CompuCell3D/Field3D/Field3D.h>
#include <CompuCell3D/Potts3D/Potts3D.h>
#include <CompuCell3D/Potts3D/Cell.h>
#include <CompuCell3D/Automaton/Automaton.h>


#include <CompuCell3D/Potts3D/Cell.h>

#include <XMLCereal/XMLPullParser.h>
#include <XMLCereal/XMLSerializer.h>

#include <BasicUtils/BasicString.h>
#include <BasicUtils/BasicException.h>

#include <CompuCell3D/plugins/CellVelocity/CellVelocityPlugin.h>
#include <CompuCell3D/plugins/CellVelocity/CellVelocityData.h>



using namespace CompuCell3D;

#include <iostream>
using namespace std;
MitosisPluginVelocity::MitosisPluginVelocity():MitosisPlugin() {}

MitosisPluginVelocity::~MitosisPluginVelocity()
{}

 void MitosisPluginVelocity::init(Simulator *simulator){
    MitosisPlugin::init(simulator);
    CellVelocityPlugin * cellVelocityPlugin=(CellVelocityPlugin*)(Simulator::pluginManager.get("CellVelocity"));
    cellVelocityDataAccessorPtr = cellVelocityPlugin->getCellVelocityDataAccessorPtr();

 }

// 
// void MitosisPluginVelocity::field3DChange(const Point3D &pt, CellG *newCell,CellG *oldCell){
//    MitosisPlugin::field3DChange(pt,newCell,oldCell);
// }
// 
// void MitosisPluginVelocity::step(){
//    MitosisPlugin::step();
// }
// 
// 
// void MitosisPluginVelocity::turnOn(){
//    MitosisPlugin::turnOn();
// }
// void MitosisPluginVelocity::turnOff(){
//    MitosisPlugin::turnOff();
// }
// 
//
//bool MitosisPluginVelocity::doMitosis(){///actually make mitosis - returns true if mitosis was done , false otherwise
//   MitosisPlugin::doMitosis();
//}

void MitosisPluginVelocity::updateAttributes(){


   ///copying type and target volume of the parent cell to the new cell
   childCell->type = parentCell->type;
   childCell->targetVolume = parentCell->targetVolume;
   
   ///put COM of child cell into its CellVelocityData attribute. It has to be done before calling produceVelocityHistoryFromSource() fcn
   
   cellVelocityDataAccessorPtr -> get(childCell->extraAttribPtr) ->
   push_front( childCell->xCM/(float)childCell->volume , childCell->yCM/(float)childCell->volume , childCell->zCM/(float)childCell->volume );
   
   cellVelocityDataAccessorPtr -> get(childCell->extraAttribPtr) ->
   produceVelocityHistoryFromSource(cellVelocityDataAccessorPtr -> get(parentCell->extraAttribPtr));

//    cerr<<"ChildCell"<<endl;
//    cerr<<*cellVelocityDataAccessorPtr -> get(childCell->extraAttribPtr) -> cellCOMPtr;
//    cerr<<"ParentCell"<<endl;
//    cerr<<*cellVelocityDataAccessorPtr -> get(parentCell->extraAttribPtr) -> cellCOMPtr;

   cellVelocityDataAccessorPtr -> get(childCell->extraAttribPtr) ->enoughData =
   cellVelocityDataAccessorPtr -> get(parentCell->extraAttribPtr) ->enoughData;

   cellVelocityDataAccessorPtr -> get(childCell->extraAttribPtr) -> numberOfSamples =
   cellVelocityDataAccessorPtr -> get(parentCell->extraAttribPtr) -> numberOfSamples ;

      
//   childCell->type = parentCell->type;
//   childCell->targetVolume = initialTargetVolume;
//   parentCell->targetVolume = initialTargetVolume;
//   childCell->targetSurface = initialTargetSurface;
//   parentCell->targetSurface = initialTargetSurface;


/*   cerr<<"childCell->targetVolume ="<<childCell->targetVolume<<" parentCell->targetVolume ="<<parentCell->targetVolume<<endl;
   cerr<<"initialTargetVolume="<<initialTargetVolume<<endl;*/
}

// void MitosisPluginVelocity::readXML(XMLPullParser &in) {
//    MitosisPlugin::readXML(in);
// }
// 
// void MitosisPluginVelocity::writeXML(XMLSerializer &out) {
//    MitosisPlugin::writeXML(out);
// }
// 

















