//    module: FOpenProject.cpp                                                //
//                                                                            //
//    Form that displays progress and other information when loading model    //
//    and data as specified in associated TProjectG. Loading is done using    //
//    a thread object (ThrOpenProject) which is newed in function OnShow()    //
//                                                                            //                                                                            //
//    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          //
//    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 FOpenProjectH
#define FOpenProjectH

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>

#include "ThrOpenProject.h"      // due to:  ThrOpenProject
#include "projectG.h"            //          TProjectG
#include "cluster.h"             //          TCluster
#include "data.h"                //          TData
#include "tune.h"
#include <AppEvnts.hpp>                //          TTune

// form to display progress etc. when loading a project (model and data); start loading using a ThrOpenProject object
class TFOpenProject : public TForm
   TBitBtn *BtAbort;
   TBitBtn *BtContinue;
   TBitBtn *BtPause;
   TProgressBar *PbOpenProject;
   TShape *ShTestDataStatus;
   TLabel *LaStatusHeader;
   TLabel *LaStatus;
   TLabel *LaFile;
   TTimer *Timer;
   TLabel *LaFileHeader;
   void __fastcall FormShow(TObject *Sender);
   void __fastcall BtPauseClick(TObject *Sender);
   void __fastcall BtContinueClick(TObject *Sender);
   void __fastcall BtAbortClick(TObject *Sender);
   void __fastcall OnTimer(TObject *Sender);


   ThrOpenProject* thread;       // thread object, used to do the work, i.e. load model and data
   TProjectG* prj;               // associated project, specifies model and data filenames
   const char* szModelFile;      // model filename
   const char* szTuningFile;     // tuning results filename
   bool f_Stop;                  // stop flag

   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


   // constructor
   __fastcall TFOpenProject(TComponent* Owner);

   void __fastcall OnFinish(){
      thread->WriteBack(model, data_L, data_T, tuningResults);       // get loaded objects from thread object
      f_IsWithOutput = thread->IsWithOutput();                       // copy flag
      Timer->Enabled = false;                                        // stop progress indication timer
      Close(); };                                                    // close dialog

   // write back loaded objects to main form
   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

   // associate project and model filename
   void Associate(TProjectG*const& _prj, const char*const& _szModelFile, const char*const& _szTuningFile)
         { prj=_prj; szModelFile=_szModelFile; szTuningFile=_szTuningFile;};
extern PACKAGE TFOpenProject *FOpenProject;