Ejemplo n.º 1
0
  /**
   * @param c Command to be executed
   * @param labelOutput specifies if output GeoElements of this command should get labels
   * @throws MyError in case command execution fails
   * @return Geos created by the command
   */
  public final GeoElement[] processCommand(Command c, boolean labelOutput) throws MyError {

    if (cmdTable == null) {
      initCmdTable();
    }

    // cmdName
    String cmdName = c.getName();
    CommandProcessor cmdProc;
    //
    //        // remove CAS variable prefix from command name if present
    //        cmdName = cmdName.replace(ExpressionNode.GGBCAS_VARIABLE_PREFIX, "");

    // MACRO: is there a macro with this command name?
    MacroInterface macro = kernel.getMacro(cmdName);
    if (macro != null) {
      c.setMacro(macro);
      cmdProc = macroProc;
    }
    // STANDARD CASE
    else {
      // get CommandProcessor object for command name from command table
      cmdProc = cmdTable.get(cmdName);

      if (cmdProc == null) {
        cmdProc = commandTableSwitch(cmdName);
        if (cmdProc != null) {
          cmdTable.put(cmdName, cmdProc);
        }
      }

      if (cmdProc == null && internalCmdTable != null) {
        // try internal command
        cmdProc = internalCmdTable.get(cmdName);
      }
    }

    if (cmdProc == null)
      throw new MyError(app, app.getError("UnknownCommand") + " : " + app.getCommand(c.getName()));

    // switch on macro mode to avoid labeling of output if desired
    boolean oldMacroMode = cons.isSuppressLabelsActive();
    if (!labelOutput) cons.setSuppressLabelCreation(true);

    GeoElement[] ret = null;
    try {
      ret = cmdProc.process(c);
    } catch (MyError e) {
      throw e;
    } catch (Exception e) {
      cons.setSuppressLabelCreation(oldMacroMode);
      e.printStackTrace();
      throw new MyError(app, app.getError("CAS.GeneralErrorMessage"));
    } finally {
      cons.setSuppressLabelCreation(oldMacroMode);
    }

    // remember macro command used:
    // this is needed when a single tool A[] is exported to find
    // all other tools that are needed for A[]
    if (macro != null) cons.addUsedMacro(macro);

    return ret;
  }