//----------------------------------------------------------------------------//
//    module ThrOpenProject.h                                                 //
//                                                                            //
//    Thread function: Loads model, tuning results and data as specifed in    //
//    given TProjectG object. Calls back to given c-style function when       //
//    finished.                                                               //
//                                                                            //                                                                            //
//    copyright (c) 2003 by Lars Haendel                                      //
//    home: www.newty.de                                                      //
//                                                                            //
//    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 as version 2 of the License.               //
//                                                                            //
//    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.               //
//                                                                            //
//----------------------------------------------------------------------------//



#ifndef ThrOpenProjectH
#define ThrOpenProjectH

#include <Classes.hpp>



#include "projectG.h"               // due to:  TProjectG
#include "cluster.h"                //          TCluster
#include "data.h"                   //          TData
#include "tune.h"                   //          TTune


//----------------------------------------------------------------------------------------------------------------------
// load model, tuning results and data as specified by given project (TProjectG)
class ThrOpenProject : public TThread
{
private:

   char szText[1024];            // error message
   const char* szFilename;       // pointer to filename


   const bool* f_Stop;           // stop flag
   TProjectG* prj;               // project
   const char* szModelFile;      // model filename
   const char* szTuningFile;     // tuning results filename
   void (*FinishFunc)();         // callback function called in OnFinish()

   // objects to load
   TCluster* model;              // model
   TData*    data_L;             // learn data
   TData*    data_T;             // test data
   TTune*    tuningResults;      // tuning results

   bool f_IsWithOutput;          // flag: test data is with output

protected:
   void __fastcall Execute();

   void __fastcall OnFinish(TObject*){ (*FinishFunc)(); };     // called when loading is finished
   void __fastcall MessageBox();                               // display error message box
   void __fastcall Clear();                                    // release data and model again (in case of an error)


public:

   // constructor: _FinishFunc is a c-style function pointer used for a callback when the thread finishes.
   // Take a look at the "function pointer tutorials" at http://www.newty.de for an introduction to function pointers!
   __fastcall ThrOpenProject(bool CreateSuspended, void (*_FinishFunc)(), TProjectG*const& _prj,
                 const char*const& _szModelFile, const char*const& _szTuningFile, const bool*const& _f_Stop=NULL);


   float Progress();             // return current progress
   const char* Status();         // return status text
   const char* Filename();       // return actually processed filename

   void WriteBack(TCluster*& _model, TData*& _data_L, TData*& _data_T, TTune*& _tuningResults)
                  { _model=model; _data_L=data_L; _data_T=data_T; _tuningResults=tuningResults; };

   const bool& IsWithOutput() const { return f_IsWithOutput; }; // return true is data is with output
};
#endif