Beispiel #1
0
  /**
   * @param app application
   * @return All tools as a toolbar definition string
   */
  public static String getAllTools(AppD app) {
    StringBuilder sb = new StringBuilder();

    sb.append(ToolBar.getAllToolsNoMacros(true, false));

    // macros
    Kernel kernel = app.getKernel();
    int macroNumber = kernel.getMacroNumber();

    // check if at least one macro is shown
    // to avoid strange GUI
    boolean at_least_one_shown = false;
    for (int i = 0; i < macroNumber; i++) {
      Macro macro = kernel.getMacro(i);
      if (macro.isShowInToolBar()) {
        at_least_one_shown = true;
        break;
      }
    }

    if (macroNumber > 0 && at_least_one_shown) {
      sb.append(" || ");
      for (int i = 0; i < macroNumber; i++) {
        Macro macro = kernel.getMacro(i);
        if (macro.isShowInToolBar()) {
          sb.append(i + EuclidianConstants.MACRO_MODE_ID_OFFSET);
          sb.append(" ");
        }
      }
    }

    return sb.toString();
  }
Beispiel #2
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;
  }