// $Source: /usr/local/SimSoft/Sfx3D/src/gsl/modell.h,v $
// $Revision: 1.2 $
// $Author: baum $
// $Date: 2001/11/29 15:18:09 $
//
// Login name of the user who locked the revision
// $Locker:  $
// Tag name used to checkout the file
// $Name:  $
// State assigned to revision
// $State: Exp $
//
//
// $Log: modell.h,v $
// Revision 1.2  2001/11/29 15:18:09  baum
// -Realzeitsteuerung eingebaut
// -Handsteuerung eingebaut
//

#ifndef _MODELL_H
#define _MODELL_H	1

#include "Array.h"
#include "DynArray.h"
#include "Map.h"
#include "Token.h"
#include "Strings.h"

#include "SimTime.h"

#include "Vec3D.h"
#include "XGraph/XGraph.h"

#include "geometry.h"

//LCE
#include "sfx.h"
#include "baustein.h"
//#include "LCE_Interface.h"
//LCE

//#include "XMLHandler.h"

#ifdef _MODELL_CPP
#  undef _impexp
#  define _impexp __declspec(dllexport)
#elif defined BUILD_SFX_DLL
#  undef _impexp
#  define _impexp
#else
#  undef _impexp
#  define _impexp __declspec(dllimport)
#endif

#if defined __GNUC__ || defined __hpux
#  undef _impexp
#  define _impexp
#endif

#ifndef _BAUSTEIN_H
  class typBaustein;
#endif

#ifndef _ROUTE_H
  class typTransportRoute;
#endif

#ifndef _ARBPLAN_H
  class typArbeitsplan;
#endif

#ifndef _TRANSP_H
  class typTransportEinheit;
#endif

#ifndef _PROZESS_H
  class typProzess;
#endif


_impexp extern class SFXModel *MySFXModel;

_impexp extern Array<typBaustein> baustein;

_impexp extern bool Sfx3D_on;
//==================================================================
//		output streaming
//==================================================================

_impexp void dprintf (char* format, ...);
_impexp int MessagerToCout (int, const char* txt);

//==================================================================
//		warning and error handling
//==================================================================

_impexp int sim_error (char *Modul, char *Methode, char *Text,
                       int betr, bool fatal);

_impexp int sim_error (char *Modul, char *Methode, char *Text,
                       char *betr, bool fatal);

//==================================================================
//		Class-Header
//		for class SFXModel
//==================================================================

class _impexp SFXModel {
  public:
    // constructor
    // model-string is path with modelname!!!!
    SFXModel (const Ustring& model, bool plantControl = false, bool realTime = false, bool hla = false);
    SFXModel (const Ustring& model, const Ustring& extension, bool plantControl = false, bool realTime = false, bool hla = false);

    // destructor
    ~SFXModel ();

    void load ();

    bool run  ();
    bool stop ();
    bool isRunning () const;

    const Ustring& ModelName () const;
    const Ustring& ModelExtension () const;
    const Ustring& ModelPath () const;
    Ustring& OutputPath ();/**< Ergaenzt, um Ausgaben in verschiedenen Verzeichnisse umlenken zu koennen. Rudi: 02.08.2002.*/
    void setOutputPath (Ustring path);
    
    TGBLib *TGBLibrary () const;
//	 XMLHandler *ModelXMLHandler () const;
    Space  *ModelSpace () const;

    bool Cycle        () const;
    bool setCycle     (bool cycle);
    bool freezCycle   ();
    bool restoreCycle ();

    bool Trace    () const;
    bool setTrace (bool trace);

    bool Speech    () const;
    bool setSpeech (bool speech);

    bool Debug     () const;
    bool setDebug  (bool debug);
    bool InitDebug () const;
    bool setInitDebug  (bool debug);
    bool PrgDebug  () const;
    bool setPrgDebug (bool debug);

    bool PlantControl () const;
    bool RealTime     () const;
    bool Hla          () const;
    double Release () const;

    void insertPermanent (const typBaustein& bst, const GeoObject& gObj);
    void removePermanent (const typBaustein& bst);
    typBaustein* findPermanent (unsigned nr) const;
    const Map<typBaustein, GeoObject>& Permanents  () const;

    void insertTemporary (const typTransportEinheit& TE, const GeoObject& gObj);
    void removeTemporary (const typTransportEinheit& TE);
    typTransportEinheit* findTemporary (unsigned id) const;
    const Map<typTransportEinheit, GeoObject>& Temporaries () const;

    typTransportRoute *findRoute              (typBaustein* startPerm, typBaustein* destPerm) const;
    typArbeitsplan *findWorkSchedule          (unsigned nr) const;
    typArbeitsplan *findWorkScheduleByArticle (unsigned nr, typBaustein* startBst) const;
    typProzess *findProcess                   (unsigned nr,bool fatal = true) const;

    const DynArray<typArbeitsplan>& WorkSchedules () const;
    const DynArray<typProzess>& Processes () const;
    DynArray <typProzess>    ObjProcesses;


   //LCE
   //LCE_InterfaceKern* zLCE_Kern;
   //LCE

  protected:

  private:
    // declared, but not defined
    SFXModel ();
    SFXModel (const SFXModel&);
    const SFXModel& operator = (const SFXModel&);

    void readTGS ();
    void readTTP ();
    void readTST ();
    void readTBV ();
    void readTAS ();
    void readTFK ();
    void readTLM ();
    void readTPV ();
    void readTZT ();
    void readTMW ();

    SimTime readTime (InputFile& file) const;
    void init ();

    // data-members
    Ustring ObjModelPath;
    Ustring ObjOutputPath; /**< Ergaenzt, um Ausgaben in verschiedenen Verzeichnisse umlenken zu koennen. Rudi: 02.08.2002.*/
    Ustring ObjModelName;
    Ustring ObjModelExtension;

    Space  ObjModelSpace;
    TGBLib *ObjTGB;
//    XMLHandler *ObjXMLHandler;

    Map <typBaustein,   GeoObject> ObjPermanents;
    Map <typTransportEinheit, GeoObject> ObjTemporaries;

    DynArray <typArbeitsplan> ObjWorkSchedules;
    Array <DynArray <typTransportRoute> >  ObjRoutes;

    bool ObjRunning;
    bool ObjCycle;
    bool ObjCycleFreez;
    bool ObjTrace;
    bool ObjDebug;
    bool ObjInitDebug;
    bool ObjPrgDebug;
    bool ObjPlantControl;
    bool ObjRealTime;
    bool ObjHla;
    bool ObjSpeech;
    double ObjRelease;

};

//==================================================================
//		Class-Header
//		for class SFXToken
//==================================================================

class _impexp SFXToken : public Token {
  public:
    // constructor
    SFXToken ();

    // destructor
    virtual ~SFXToken ();

    bool findSentence     (int sNumber, InputFile& file);
    bool findNextSentence (InputFile& file);

  protected:

  private:
    SFXToken (const SFXToken&);
    SFXToken& operator = (const SFXToken&);
};


#endif // !_MODELL_H

