Esempio n. 1
0
  private GeoElement[] processBoolean(ExpressionNode n, ExpressionValue evaluate) {
    GeoElement[] ret = new GeoElement[1];
    String label = n.getLabel();

    boolean isIndependent = n.isConstant();

    if (isIndependent) {
      ret[0] = kernel.Boolean(label, ((BooleanValue) evaluate).getBoolean());
    } else ret[0] = kernel.DependentBoolean(label, n);
    return ret;
  }
Esempio n. 2
0
  private GeoElement[] processText(ExpressionNode n, ExpressionValue evaluate) {
    GeoElement[] ret = new GeoElement[1];
    String label = n.getLabel();

    boolean isIndependent = n.isConstant();

    if (isIndependent) {
      MyStringBuffer eval = ((TextValue) evaluate).getText();
      ret[0] = kernel.Text(label, eval.toValueString());
    } else ret[0] = kernel.DependentText(label, n);
    return ret;
  }
Esempio n. 3
0
  private GeoElement[] processPointVector(ExpressionNode n, ExpressionValue evaluate) {
    String label = n.getLabel();

    GeoVec2D p = (GeoVec2D) ((VectorValue) evaluate).getVector();

    boolean polar = p.getMode() == Kernel.COORD_POLAR;

    // we want z = 3 + i to give a (complex) GeoPoint not a GeoVector
    boolean complex = p.getMode() == Kernel.COORD_COMPLEX;

    GeoVec3D[] ret = new GeoVec3D[1];
    boolean isIndependent = n.isConstant();

    // make point if complex parts are present, e.g. 3 + i
    if (complex) {
      n.setForcePoint();
    }
    // make vector, if label begins with lowercase character
    else if (label != null) {
      if (!(n.isForcedPoint() || n.isForcedVector())) { // may be set by MyXMLHandler
        if (Character.isLowerCase(label.charAt(0))) n.setForceVector();
        else n.setForcePoint();
      }
    }
    boolean isVector = n.isVectorValue();

    if (isIndependent) {
      // get coords
      double x = p.getX();
      double y = p.getY();
      if (isVector) ret[0] = kernel.Vector(label, x, y);
      else ret[0] = kernel.Point(label, x, y, complex);
    } else {
      if (isVector) ret[0] = kernel.DependentVector(label, n);
      else ret[0] = kernel.DependentPoint(label, n, complex);
    }
    if (polar) {
      ret[0].setMode(Kernel.COORD_POLAR);
      ret[0].updateRepaint();
    } else if (complex) {
      ret[0].setMode(Kernel.COORD_COMPLEX);
      ret[0].updateRepaint();
    }
    return ret;
  }
Esempio n. 4
0
  private GeoElement[] processList(ExpressionNode n, MyList evalList) {
    String label = n.getLabel();

    GeoElement[] ret = new GeoElement[1];

    // no operations or no variables are present, e.g.
    // { a, b, 7 } or  { 2, 3, 5 } + {1, 2, 4}
    if (!n.hasOperations() || n.isConstant()) {

      // PROCESS list items to generate a list of geoElements
      ArrayList<GeoElement> geoElements = new ArrayList<GeoElement>();
      boolean isIndependent = true;

      // make sure we don't create any labels for the list elements
      boolean oldMacroMode = cons.isSuppressLabelsActive();
      cons.setSuppressLabelCreation(true);

      int size = evalList.size();
      for (int i = 0; i < size; i++) {
        ExpressionNode en = (ExpressionNode) evalList.getListElement(i);
        // we only take one resulting object
        GeoElement[] results = processExpressionNode(en);
        GeoElement geo = results[0];

        // add to list
        geoElements.add(geo);
        if (geo.isLabelSet() || !geo.isIndependent()) isIndependent = false;
      }
      cons.setSuppressLabelCreation(oldMacroMode);

      // Create GeoList object
      ret[0] = kernel.List(label, geoElements, isIndependent);
    }

    // operations and variables are present
    // e.g. {3, 2, 1} + {a, b, 2}
    else {
      ret[0] = kernel.ListExpression(label, n);
    }

    return ret;
  }
Esempio n. 5
0
  private GeoElement[] processNumber(ExpressionNode n, ExpressionValue evaluate) {
    GeoElement[] ret = new GeoElement[1];
    String label = n.getLabel();
    boolean isIndependent = n.isConstant();
    MyDouble eval = ((NumberValue) evaluate).getNumber();
    boolean isAngle = eval.isAngle();
    double value = eval.getDouble();

    if (isIndependent) {
      if (isAngle) ret[0] = new GeoAngle(cons, label, value);
      else ret[0] = new GeoNumeric(cons, label, value);
    } else {
      ret[0] = kernel.DependentNumber(label, n, isAngle);
    }

    if (n.isForcedFunction()) {
      ret[0] = ((GeoFunctionable) (ret[0])).getGeoFunction();
    }

    return ret;
  }
Esempio n. 6
0
  public GeoElement[] processExpressionNode(ExpressionNode n) throws MyError {
    // command is leaf: process command
    if (n.isLeaf()) {
      ExpressionValue leaf = n.getLeft();
      if (leaf instanceof Command) {
        Command c = (Command) leaf;
        c.setLabels(n.getLabels());
        return cmdDispatcher.processCommand(c, true);
      } else if (leaf instanceof Equation) {
        Equation eqn = (Equation) leaf;
        eqn.setLabels(n.getLabels());
        return processEquation(eqn);
      } else if (leaf instanceof Function) {
        Function fun = (Function) leaf;
        fun.setLabels(n.getLabels());
        return processFunction(n, fun);
      } else if (leaf instanceof FunctionNVar) {
        FunctionNVar fun = (FunctionNVar) leaf;
        fun.setLabels(n.getLabels());
        return processFunctionNVar(n, fun);
      }
    }

    // ELSE:  resolve variables and evaluate expressionnode
    n.resolveVariables();
    eval = n.evaluate();
    boolean dollarLabelFound = false;

    ExpressionNode myNode = n;
    if (myNode.isLeaf()) myNode = myNode.getLeftTree();
    // leaf (no new label specified): just return the existing GeoElement
    if (eval.isGeoElement()
        && n.getLabel() == null
        && !(n.operation.equals(Operation.ELEMENT_OF))) {
      // take care of spreadsheet $ names: don't loose the wrapper ExpressionNode here
      // check if we have a Variable
      switch (myNode.getOperation()) {
        case $VAR_COL:
        case $VAR_ROW:
        case $VAR_ROW_COL:
          // don't do anything here: we need to keep the wrapper ExpressionNode
          // and must not return the GeoElement here
          dollarLabelFound = true;
          break;

        default:
          // return the GeoElement
          GeoElement[] ret = {(GeoElement) eval};
          return ret;
      }
    }

    if (eval.isBooleanValue()) return processBoolean(n, eval);
    else if (eval.isNumberValue()) return processNumber(n, eval);
    else if (eval.isVectorValue()) return processPointVector(n, eval);
    else if (eval.isVector3DValue()) return processPointVector3D(n, eval);
    else if (eval.isTextValue()) return processText(n, eval);
    else if (eval instanceof MyList) {
      return processList(n, (MyList) eval);
    } else if (eval instanceof Function) {
      return processFunction(n, (Function) eval);
    } else if (eval instanceof FunctionNVar) {

      return processFunctionNVar(n, (FunctionNVar) eval);
    }
    // we have to process list in case list=matrix1(1), but not when list=list2
    else if (eval instanceof GeoList && myNode.hasOperations()) {
      Application.debug("should work");
      return processList(n, ((GeoList) eval).getMyList());
    } else if (eval.isGeoElement()) {

      // e.g. B1 = A1 where A1 is a GeoElement and B1 does not exist yet
      // create a copy of A1
      if (n.getLabel() != null || dollarLabelFound) {
        return processGeoCopy(n.getLabel(), n);
      }
    }

    // REMOVED due to issue 131: http://code.google.com/p/geogebra/issues/detail?id=131
    //		// expressions like 2 a (where a:x + y = 1)
    //		// A1=b doesn't work for these objects
    //		else if (eval instanceof GeoLine) {
    //			if (((GeoLine)eval).getParentAlgorithm() instanceof AlgoDependentLine) {
    //				GeoElement[] ret = {(GeoElement) eval };
    //				return ret;
    //			}
    //
    //		}

    // if we get here, nothing worked
    Application.debug("Unhandled ExpressionNode: " + eval + ", " + eval.getClass());
    return null;
  }