#include "ScreenshotData.h"
#include "GraphicsBase.h"
#include <iostream>

using namespace std;

ScreenshotData::ScreenshotData(){
   graphicsPtr=0;
   inventoryFilePtr=0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ScreenshotData::~ScreenshotData(){
   if(graphicsPtr)
      delete graphicsPtr;
   graphicsPtr=0;

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ScreenshotData::setCoreName(const std::string  & _name )
{
   coreName=_name;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ScreenshotData::setScreenshotIdName(const QString & scrName){
   screenshotIdName = scrName;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ScreenshotData::activate(const QString & _simulationRootDir){
   simulationRootDir=_simulationRootDir;
   thisDirectoryName=QString(simulationRootDir+QDir::separator()+coreName);


   bool dirOK=dir.mkdir(thisDirectoryName);
      if(!dirOK){
         cerr<<"could not create directory: "<<thisDirectoryName<<endl;
         cerr<<"Make sure that directory with this name is removed"<<endl;
         exit(0);
      }
   fullInventoryFileName = QString(thisDirectoryName+QDir::separator()+coreName+".grl");
   
   inventoryFilePtr=new ofstream();
   inventoryFilePtr->open(fullInventoryFileName.ascii());

   graphicsPtr->setUnivGraphSetPtr(&univGraphSet);
   
   //cerr<<"&univGraphSet="<<&univGraphSet<<endl;
   //cerr<<"graphicsPtr="<<graphicsPtr<<endl;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ScreenshotData::outputScreenshot(unsigned int screenshotCounter){
    QImage image;
    ofstream &out = *inventoryFilePtr;
    QString screenshotName(coreName+"."+QString().setNum(screenshotCounter)+".png");
    QString screenshotFullName(thisDirectoryName+QDir::separator()+screenshotName);
    //draws scene (cell field concentration etc. depending on the initialization)
    //(graphicsPtr->*(graphicsPtr->getCurrentPainitgFcnPtr()))();
    
    graphicsPtr->drawCurrentScene();
    
    cerr<<"GOT HERE"<<endl;
    cerr<<"fcn address="<<graphicsPtr->getCurrentPainitgFcnPtr()<<endl;
    cerr<<"graphicsPtr="<<graphicsPtr<<endl;
    graphicsPtr->produceImage(image);
    image.save(QString(screenshotFullName),"PNG");
    //adding entry to file list
    out<<screenshotName<<endl;
    

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




















