Пример #1
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;
  }
Пример #2
0
  /**
   * for AlgebraView changes in the tree selection and redefine dialog
   *
   * @return changed geo
   */
  public GeoElement changeGeoElementNoExceptionHandling(
      GeoElement geo, ValidExpression newValue, boolean redefineIndependent, boolean storeUndoInfo)
      throws Exception {
    String oldLabel, newLabel;
    GeoElement[] result;

    try {
      oldLabel = geo.getLabel();
      newLabel = newValue.getLabel();

      if (newLabel == null) {
        newLabel = oldLabel;
        newValue.setLabel(newLabel);
      }

      // make sure that points stay points and vectors stay vectors
      if (newValue instanceof ExpressionNode) {
        ExpressionNode n = (ExpressionNode) newValue;
        if (geo.isGeoPoint()) n.setForcePoint();
        else if (geo.isGeoVector()) n.setForceVector();
        else if (geo.isGeoFunction()) n.setForceFunction();
      }

      if (newLabel.equals(oldLabel)) {
        // try to overwrite
        result = processValidExpression(newValue, redefineIndependent);
        if (result != null && storeUndoInfo) app.storeUndoInfo();
        return result[0];
      } else if (cons.isFreeLabel(newLabel)) {
        newValue.setLabel(oldLabel);
        // rename to oldLabel to enable overwriting
        result = processValidExpression(newValue, redefineIndependent);
        result[0].setLabel(newLabel); // now we rename
        if (storeUndoInfo) app.storeUndoInfo();
        return result[0];
      } else {
        String str[] = {"NameUsed", newLabel};
        throw new MyError(app, str);
      }
    } catch (CircularDefinitionException e) {
      Application.debug("CircularDefinition");
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception(app.getError("InvalidInput") + ":\n" + newValue);
    } catch (MyError e) {
      e.printStackTrace();
      throw new Exception(e.getLocalizedMessage());
    } catch (Error e) {
      e.printStackTrace();
      throw new Exception(app.getError("InvalidInput") + ":\n" + newValue);
    }
  }
Пример #3
0
  private GeoElement[] processParametric(Parametric par) throws CircularDefinitionException {

    /*
    ExpressionValue temp = P.evaluate();
          if (!temp.isVectorValue()) {
              String [] str = { "VectorExpected", temp.toString() };
              throw new MyParseError(kernel.getApplication(), str);
          }

          v.resolveVariables();
          temp = v.evaluate();
          if (!(temp instanceof VectorValue)) {
              String [] str = { "VectorExpected", temp.toString() };
              throw new MyParseError(kernel.getApplication(), str);
          } */

    // point and vector are created silently
    boolean oldMacroMode = cons.isSuppressLabelsActive();
    cons.setSuppressLabelCreation(true);

    // get point
    ExpressionNode node = par.getP();
    node.setForcePoint();
    GeoElement[] temp = processExpressionNode(node);
    GeoPoint P = (GeoPoint) temp[0];

    //	get vector
    node = par.getv();
    node.setForceVector();
    temp = processExpressionNode(node);
    GeoVector v = (GeoVector) temp[0];

    // switch back to old mode
    cons.setSuppressLabelCreation(oldMacroMode);

    // Line through P with direction v
    GeoLine line;
    // independent line
    if (P.isConstant() && v.isConstant()) {
      line = new GeoLine(cons);
      line.setCoords(-v.y, v.x, v.y * P.inhomX - v.x * P.inhomY);
    }
    // dependent line
    else {
      line = kernel.Line(par.getLabel(), P, v);
    }
    line.setToParametric(par.getParameter());
    line.updateRepaint();
    GeoElement[] ret = {line};
    return ret;
  }
Пример #4
0
  /**
   * Parses given String str and tries to evaluate it to a GeoPoint. Returns null if something went
   * wrong.
   */
  public GeoPointND evaluateToPoint(String str, boolean showErrors) {
    boolean oldMacroMode = cons.isSuppressLabelsActive();
    cons.setSuppressLabelCreation(true);

    GeoPointND p = null;
    GeoElement[] temp = null;
    ;
    try {
      ValidExpression ve = parser.parseGeoGebraExpression(str);
      if (ve instanceof ExpressionNode) {
        ExpressionNode en = (ExpressionNode) ve;
        en.setForcePoint();
      }

      temp = processValidExpression(ve);
      p = (GeoPointND) temp[0];
    } catch (CircularDefinitionException e) {
      if (showErrors) {
        Application.debug("CircularDefinition");
        app.showError("CircularDefinition");
      }
    } catch (Exception e) {
      if (showErrors) {
        e.printStackTrace();
        app.showError("InvalidInput", str);
      }
    } catch (MyError e) {
      if (showErrors) {
        e.printStackTrace();
        app.showError(e);
      }
    } catch (Error e) {
      if (showErrors) {
        e.printStackTrace();
        app.showError("InvalidInput", str);
      }
    }

    cons.setSuppressLabelCreation(oldMacroMode);
    return p;
  }