Esempio n. 1
0
/**
 * Proceeds with the next step in the simulation.
 * Reads the inputs from the inputs field and sends them to the machine.
 */
void Simulator::next()
{
  QString in, out;
  int numin, numout;
  GState* next_state;
  Convert conv;
  IOInfo* ioinfo;
  IOInfoBin iobin(IO_MealyIn);
  IOInfoASCII ioascii(IO_MealyIn);
  Error err;

  numin = machine->getNumInputs();
  numout = machine->getNumOutputs();

  in = simdlg->getInputs();
//  bin = new char[numin+1];
  if (simdlg->isIBinChecked())
  {
    
    if (Transition::conditionValid(Binary, in, FALSE))
    {
      if (!simdlg->isClockOn())
        err.info(tr("Input is not in binary format."));
      else
        //simdlg->setInputs("");
	simdlg->clearInput();
      return;
    }
    iobin = conv.binStrToX10(numin, in, IO_MealyIn);
    ioinfo = &iobin;
  }
  else if (simdlg->isIHexChecked())
  {
    QString intmp=in;
    intmp = intmp.replace(QRegExp("[0-9a-fA-F\\s]"), "");
    if (!intmp.isEmpty())
    {
      if (!simdlg->isClockOn())
        err.info(tr("Input is not in hexadecimal format."));
      else
        //simdlg->setInputs("");
	simdlg->clearInput();
      return;
    }
    iobin = conv.hexStrToX10(numin, in, IO_MealyIn);
    ioinfo = &iobin;
  }
  else  // ASCII
  {
    ioascii.setInfo(in); 
    ioinfo = &ioascii;
    if (!ioascii.isSingle())
    {
      if (!ioascii.getInfo().isEmpty() && !simdlg->isClockOn())
        err.info(tr("The input is not a single character.")); //
      else
        //simdlg->setInputs("");
	simdlg->clearInput();
      return;
    }
  }

//  IOInfoBin ioinfo(bin, numin);

  next_state = next(ioinfo, out);

  if (next_state)
  {
    simdlg->setOutputs(out);
    setCurrentState(next_state);
    main->repaintViewport();

  }
  if (simdlg->isClockOn() && simdlg->isIASCIIChecked())
  {
    simdlg->resetBits();
    simdlg->clearInput();
  }
  else
    simdlg->selectFirst();
//  delete [] bin;
}