/* $Id: LOG.CPP 2.4 1995/07/20 11:24:33 leon Exp $
 *
 *      GISEL - G-CODE ISEL CNC driver
 *
 *      Copyright (c) 1994 LECAD
 *      All Rights Reserved.
 *
 */

#include <string.h>             // for strlen etc


#define Uses_TWindow

#define Uses_TTerminal

#define Uses_MsgBox             // for messageBox()

#include <tvision/tv.h>


#include "log.h"


#include <string.h>


/**
 ** Returns pointer to error message string. /reply/ 
 ** is character reply from controller 
 **/
char *TLogWindow::getErrMsg(int reply)
{
  char *unknown = "Unknown response ('x') from the controller";
  switch(char(reply))
    {
      case '0': return "Command completed successfuly.";
      case '2': return "ERROR #2: Emegrency stop or limit switch encountered.";
      case '3': return "ERROR #3: Illegal number of axes.";
      case '4': return "ERROR #4: Axis not defined.";
      case '5': return "ERROR #4: Syntax error.";
      case '6': return "ERROR #4: Illegal parameters.";
      case '8': return "ERROR #4: Illegal branch.";
      case 'c': return "ERROR #c: Loop error.";
      case 'D': return "ERROR #D: Illegal speed specified.";
      case 'G': return "ERROR #G: No data for execution in memory.";
      case 'z': return "ERROR #z: Internal SW error";
      case '\r': return "ERROR #(CR): Unexpected end of command.";
    }
  unknown[19] = char(reply);
  return unknown;
}

/**
 ** Inserts error message into log window
 **/
void TLogWindow::insertErrMsg(int reply)
{
  char *p = getErrMsg(reply);
  terminal->do_sputn("\n", 1);
  terminal->do_sputn(p, strlen(p));
}



/**
 ** Log terminal window
 **/
class LogTerminal : public TTerminal 
{
public:
  LogTerminal(const TRect& bounds, TScrollBar *aHScrollBar, 
              TScrollBar *aVScrollBar, ushort aBufSize) :
    TTerminal(bounds, aHScrollBar, aVScrollBar, aBufSize)
  {
//    messageBox(mfInformation | mfOKButton, "DElta = %d",  delta.y);

  }
};





/**
 ** Log Window constructor
 **/
TLogWindow::TLogWindow( const TRect& bounds, const char *aTitle,
              short aNumber, TLogWindow **log) :
    TWindow( bounds, aTitle, aNumber ),
    TWindowInit( initFrame )
{
    instance = log;
    TRect r( getExtent() );
    r.grow(-1, -1);
    options |= ofTileable;
    terminal = new TTerminal( r,
                         NULL, // standardScrollBar(sbHorizontal | sbHandleKeyboard),

                         standardScrollBar(sbVertical | sbHandleKeyboard),
                         32768U);
    if( terminal != 0 )
        insert(terminal);
}


/**
 ** Log window destructor
 **/
TLogWindow::~TLogWindow()
{
  *instance = NULL;
}



/**
 ** Inserts character string /s/ into the Log window
 **/
void TLogWindow::insertLine(const char *s)
{
  terminal->do_sputn(s, strlen(s));
}
                      
/**
 ** Inserts max /count/ characters from string /s/ into the Log window
 **/
void TLogWindow::insertChars(const char *s, int count)
{
  terminal->do_sputn(s, count);
}




syntax highlighted by Code2HTML, v. 0.9.1