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

#define _GTSMLOG_CPP

/*** Windows headers ***/
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
//#include <winnt.h>
#endif /*WIN32*/

#ifdef __GNUC__
#include <unistd.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "XGraph/Select.h"
#include "XGraph/Parent.h"
#include "XGraph/GeoObj.h"
#include "XGraph/Space.h"

#include <tcl.h>
#include <tk.h>

#include "gtsglob.h"
#include "gtsgraf.h"
#include "gtsini.h"
#include "gtstgb.h"
#include "gtsb00.h"
#include "gtsb01.h"
#include "gtsb02.h"
#include "gtsb03.h"
#include "gtsb04.h"
#include "gtsb05.h"
#include "gtsb06.h"
#include "gtsb07.h"
#include "gtsb08.h"
#include "gtsb12.h"
#include "gtsb16.h"
#include "gtsb17.h"
#include "gtsb18.h"
#include "gtsb19.h"
#include "gtsb23.h"
#include "gtsb24.h"
#include "gtsb25.h"
#include "gtsb26.h"
#include "gtsb28.h"
#include "gtsb29.h"
#include "gtsb30.h"
#include "gtsb31.h"
#include "gtsb32.h"
#include "gtsb33.h"
#include "gtsb34.h"
#include "gtsb35.h"
#include "gtsb36.h"
#include "gtsb37.h"
#include "gtsb38.h"
#include "gtsb39.h"
#include "gtstfk.h"
#include "gtstas.h"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BstPoolVerwaltung (const char *argv2, const char *argv3, const char *argv4, const char *argv5)
{
  typBaustein* zbst;
  if (!strcmp("SELECTBST", argv2))
  {
    if (GTSSpace->MySelection()->SelectedObjects ().Count() == 1)
    {
      zbst = GTSMAP.findKey (*(GTSSpace->MySelection()->SelectedObjects ().First()));
      if (zbst)
        if ((zbst->i_BstTyp() == tRegalverwalter)  ||
            (zbst->i_BstTyp() == tNcPoolverwalter) ||
            (zbst->i_BstTyp() == tFtsLadepool)     ||
            (zbst->i_BstTyp() == tFtsVerwalter))
        sprintf (DlgBuffer, "%d\t%d", zbst->i_BstNr(), zbst->i_BstTyp());
    }
    return;
  }

  zbst = BausteinListe->Suche(ArgInt(argv5));
  if (zbst == NULL)
  {
    Meld.Ausgabe (9, ArgInt(argv5));
    return;
  }
  if (!strcmp("BSTNR", argv2))
  {
    if ((zbst->i_BstTyp() == tRegalverwalter)   ||
        (zbst->i_BstTyp() == tNcPoolverwalter)  ||
        (zbst->i_BstTyp() == tFtsLadepool)      ||
        (zbst->i_BstTyp() == tFtsVerwalter))
    {
      sprintf (DlgBuffer, "%d", zbst->i_BstTyp());
    }
    else
    {
      Meld.Ausgabe (84, zbst->i_BstNr());
      return;
    }
  }
  if (!strcmp("PV_POOLBAUSTEINE", argv2))
    sprintf (DlgBuffer, (char*)BausteinListe->getPoolBausteine(zbst).str());
  else if (!strcmp("PV_POOLLISTE", argv2))
    sprintf (DlgBuffer, (char*)zbst->getPoolListe().str());
  else if (!strcmp("PV_BETREUTEBAUSTEINE", argv2))
    sprintf (DlgBuffer, (char*)BausteinListe->getBetreuteBausteine(zbst).str());
  else if (!strcmp("PV_BETREUTELISTE", argv2))
    sprintf (DlgBuffer, (char*)zbst->getBetreuteListe().str());
  else if (!strcmp("PV_AENDEREPOOLBST", argv2))
  {
    Ustring tmp(argv3);
    zbst->setPoolListe(ArgInt(argv4), tmp);
  }
  else if (!strcmp("PV_AENDEREBETREUTEBST", argv2))
  {
    Ustring tmp(argv3);
    zbst->setBetreuteListe(ArgInt(argv4), tmp);
  }
}  // ENDE BstPoolVerwaltung

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BstParameter (const char *argv2, const char *argv3, const char * /*argv4*/, const char *argv5)
{
  typBaustein* zbst;
  if (!strcmp("SELECTBST", argv2))
  {
    if (GTSSpace->MySelection()->SelectedObjects ().Count() == 1)
    {
      zbst = GTSMAP.findKey (*(GTSSpace->MySelection()->SelectedObjects ().First()));
      if (zbst)
        sprintf (DlgBuffer, "%d\t%d", zbst->i_BstNr(), zbst->i_BstTyp());
    }
    return;
  }

  // Baustein wird ueber die Nummer gesucht
  zbst = BausteinListe->Suche(ArgInt(argv5));
  if (zbst == NULL)
  {
    Meld.Ausgabe (9, ArgInt(argv5));
    return;
  }
  if (!strcmp("BSTNR", argv2)) sprintf (DlgBuffer, "%d", zbst->i_BstTyp());
  else if (!strcmp("GETTTPWERTE", argv2))
    sprintf (DlgBuffer, (char*)zbst->getBTPWerte().str());
  else if (!strcmp("SETTTPWERTE", argv2)) zbst->setBTPWerte(Ustring(argv3));
  else if (!strcmp("GETTSTWERTE", argv2))
    sprintf (DlgBuffer, (char*)zbst->getBSPWerte().str());
  else if (!strcmp("SETTSTWERTE", argv2)) zbst->setBSPWerte(Ustring(argv3));
  else if (!strcmp("GETTMWWERTE", argv2))
    sprintf (DlgBuffer, (char*)zbst->getTMWWerte().str());
  else if (!strcmp("SETTMWWERTE", argv2)) zbst->setTMWWerte(Ustring(argv3));
  else if (!strcmp("GETVBRWERTE", argv2))
    sprintf (DlgBuffer, (char*)zbst->getVBRWerte().str());
  else if (!strcmp("SETVBRWERTE", argv2)) zbst->setVBRWerte(Ustring(argv3));
  else if (!strcmp("GETALGWERTE", argv2))
    sprintf (DlgBuffer, (char*)zbst->getALGWerte().str());
  else if (!strcmp("SETALGWERTE", argv2)) zbst->setALGWerte(Ustring(argv3));
}  // ENDE BstParameter

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InfoFahrkurs ()
{
  GTSCB.setToInfoRouting ();
  Meld.setSpeicher (116);
  Meld.StatusZeile (116, true);
}  //  InfoFahrkurs

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ErzeugeFahrkurs ()
{
  GTSCB.setToNewRouting ();
  Meld.setSpeicher (118);
  Meld.StatusZeile (118, true);
}  //  ErzeugeFahrkurs

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LoescheFahrkurs ()
{
  GTSCB.setToDeleteRouting();
  Meld.setSpeicher (121);
  Meld.StatusZeile (121, true);
}  //  LoescheFahrkurs

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InfoVerkettung ()
{
  GTSCB.setToInfoCombining ();
  Meld.deleteSpeicher();
  Meld.StatusZeile (111, true);
}  //  InfoVerkettung

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ErzeugeVerkettung ()
{
  GTSCB.setToNewCombining ();
  Meld.setSpeicher (112);
  Meld.StatusZeile (112, true);
}  //  LoescheVerkettung

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LoescheVerkettung ()
{
  GTSCB.setToDeleteCombining ();
  Meld.setSpeicher (114);
  Meld.StatusZeile (114, true);
}  //  LoescheVerkettung

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LogikPruefen ()
{
  bool ok = ArbeitsplanListe->pruefeArbeitsPlaene();
  if (ok) Meld.Ausgabe (222);
  else
  Meld.Ausgabe (228);
}  //  LogikPruefen

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int DlgLogik (ClientData /*clientData*/,
                     Tcl_Interp *interp, int argc, const char *argv[] )
{
  GTSInterpreter = interp;
  if (testprog) {
    Write("DlgLogik: Anfang >%s<", argv[1]);
    for (int i = 2; i <= argc; i++) Write(" >%s< ", argv[i]);
  }
  sprintf(DlgBuffer, "%s", "");


  if ( !strcmp("POOLVERWALTUNG", argv[1]) )
             BstPoolVerwaltung (argv[2], argv[3], argv[4], argv[5]);
  else if ( !strcmp("BSTPARAMETER", argv[1]) )
             BstParameter (argv[2], argv[3], argv[4], argv[5]);
  else if ( !strcmp("TFKINFO", argv[1]))      InfoFahrkurs();
  else if ( !strcmp("TFKLOESCHEN",  argv[1])) LoescheFahrkurs();
  else if ( !strcmp("TFKERZEUGEN",  argv[1])) ErzeugeFahrkurs();
  else if (!strcmp ("TBVERZEUGEN",  argv[1])) ErzeugeVerkettung();
  else if (!strcmp ("TBVLOESCHEN",  argv[1])) LoescheVerkettung();
  else if (!strcmp ("TBVINFO",      argv[1])) InfoVerkettung();
  else if (!strcmp ("LOGIKPRUEFEN", argv[1])) LogikPruefen ();
  else if (!strcmp ("TFKAUTOMATISCHERZEUGEN", argv[1]))
           {
             ArbeitsplanListe->erzeugeAlleFahrkurse();
             Meld.Ausgabe (230);
           }
  else
  {
    sprintf (DlgBuffer, "DlgLogik: Unbekannte Methode \"%.32s\"\n " , argv[1]);
    Tcl_SetResult( interp, DlgBuffer, TCL_STATIC );
    return TCL_ERROR;
  }

  if (testprog) Write("  -> Ende: DlgBuffer >%s<\n", DlgBuffer);
  Tcl_SetResult(interp, DlgBuffer, TCL_STATIC);
  return TCL_OK;
} //  ENDE DlgLogik

