Esempio n. 1
0
  @Override
  public void onBrowserEvent(Event event) {

    if (!this.isEnabled()) {
      event.stopPropagation();
      return;
    }
    switch (DOM.eventGetType(event)) {
      case Event.ONTOUCHSTART:
        {
          onTouchStart(event);
          event.stopPropagation();
          break;
        }
      case Event.ONTOUCHEND:
        {
          onTouchEnd(event);
          event.stopPropagation();
          break;
        }
      case Event.ONTOUCHMOVE:
        {
          onTouchMove(event);
          event.stopPropagation();
          break;
        }
      case Event.ONMOUSEUP:
        {
          Log.debug("touch up");
          // because Event.ONCLICK always came twice on desktop browsers oO
          onClick(event);
          event.stopPropagation();
          break;
        }
      case Event.ONMOUSEDOWN:
        {
          event.stopPropagation();
          break;
        }
      default:
        {
          // Let parent handle event if not one of the above (?)
          try {
            super.onBrowserEvent(event);
          } catch (Throwable t) {
            Log.debug(DOM.eventGetType(event) + "event failed");
          }
        }
    }
  }
Esempio n. 2
0
 /** @return The definition string associated with this toolbar. */
 public String getToolbarString() {
   if (toolbarString == null) {
     Log.warn("Toolbar not initialized");
     return defaultToolbarString;
   }
   return toolbarString;
 }
Esempio n. 3
0
 /**
  * @param app
  * @param type
  * @return short version of Option type string
  */
 public static final String getTypeStringSimple(Localization loc, OptionType type) {
   switch (type) {
     case DEFAULTS:
       return loc.getPlain("Defaults");
     case SPREADSHEET:
       return loc.getPlain("Spreadsheet");
     case EUCLIDIAN:
       return loc.getPlain("DrawingPad");
     case EUCLIDIAN2:
       return loc.getPlain("DrawingPad2");
     case CAS:
       return loc.getPlain("CAS");
     case ADVANCED:
       return loc.getMenu("Advanced");
     case OBJECTS:
       return loc.getMenu("Objects");
       // return objectPanel.getSelectionDescription();
     case LAYOUT:
       return loc.getMenu("Layout");
     case EUCLIDIAN3D:
       return loc.getPlain("GraphicsView3D");
     case EUCLIDIAN_FOR_PLANE:
       return loc.getPlain("ExtraViews");
     case ALGEBRA:
       return loc.getPlain("Algebra");
     default:
       Log.error("missing case in getTypeStringSimple():" + type);
       return null;
   }
 }
Esempio n. 4
0
  @BeforeClass
  public static void setupCas() {
    app = new AppD(new CommandLineArguments(new String[] {"--giac"}), new JFrame(), false);
    // Set language to something else than English to test automatic translation.
    app.setLanguage(Locale.GERMANY);
    // app.fillCasCommandDict();

    kernel = app.getKernel();
    cas = kernel.getGeoGebraCAS();
    logger = new CASTestLogger();
    // Setting the general timeout to 13 seconds. Feel free to change this.
    kernel.getApplication().getSettings().getCasSettings().setTimeoutMilliseconds(13000);

    try {
      Log.debug("CAS: loading testcases");
      String json = readFileAsString("../web/war/__giac.js");
      Log.debug("CAS: parsing testcases");
      Log.debug("CAS: testcases parsed");
      JSONArray testsJSON = new JSONArray(json.substring("var __giac = ".length()));
      Assert.assertNotSame(0, testsJSON.length());
      int i = 1;
      while (i < testsJSON.length()) {

        JSONObject test = testsJSON.getJSONObject(i);
        i++;
        String cat = "general";
        if (test.has("cat")) {
          cat = test.getString("cat");
        }
        if (!testcases.containsKey(cat)) {
          /*System.out.println("@Test");
          System.out.println("public void test"+cat+"(){");
          System.out.println("	testCat(\""+cat+"\");");
          System.out.println("}\n");*/

          testcases.put(cat, new HashMap<String, String>());
        }
        if (test.has("round")) {
          testcases.get(cat).put(test.getString("cmd"), test.getString("round"));
        } else {
          testcases.get(cat).put(test.getString("cmd"), test.getString("result"));
        }
      }
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }
Esempio n. 5
0
  /**
   * **************************************************** Constructs AppW for applets
   *
   * @param undoActive if true you can undo by CTRL+Z and redo by CTRL+Y
   * @param ae article element
   * @param gf frame
   * @param dimension 3 for 3d, 2 otherwise
   * @param laf look and feel
   */
  public AppWapplet(
      ArticleElement ae,
      GeoGebraFrameBoth gf,
      final boolean undoActive,
      int dimension,
      GLookAndFeel laf) {
    super(ae, dimension, laf, null);
    this.frame = gf;
    setAppletHeight(frame.getComputedHeight());
    setAppletWidth(frame.getComputedWidth());

    this.useFullGui =
        !isApplet()
            || ae.getDataParamShowAlgebraInput(false)
            || ae.getDataParamShowToolBar(false)
            || ae.getDataParamShowMenuBar(false)
            || ae.getDataParamEnableRightClick();

    Log.info(
        "GeoGebra "
            + GeoGebraConstants.VERSION_STRING
            + " "
            + GeoGebraConstants.BUILD_DATE
            + " "
            + Window.Navigator.getUserAgent());
    initCommonObjects();
    initing = true;

    this.euclidianViewPanel = new EuclidianDockPanelW(this, allowStylebar());
    // (EuclidianDockPanelW)getGuiManager().getLayout().getDockManager().getPanel(App.VIEW_EUCLIDIAN);
    this.canvas = this.euclidianViewPanel.getCanvas();
    canvas.setWidth("1px");
    canvas.setHeight("1px");
    canvas.setCoordinateSpaceHeight(1);
    canvas.setCoordinateSpaceWidth(1);
    initCoreObjects(undoActive, this);
    afterCoreObjectsInited();
    resetFonts();
    Browser.removeDefaultContextMenu(this.getArticleElement());
    if (ae.getDataParamApp() && !this.getLAF().isSmart()) {
      RootPanel.getBodyElement().addClassName("application");
    }
    if (this.showMenuBar()) {
      // opening file -> this was inited before
      if (getLoginOperation() == null) {
        initSignInEventFlow(new LoginOperationW(this), ae.isEnableUsageStats());
      }
    } else {
      if (Browser.runningLocal() && ae.isEnableUsageStats()) {
        new GeoGebraTubeAPIWSimple(has(Feature.TUBE_BETA)).checkAvailable(null);
      }
    }
  }
Esempio n. 6
0
  /**
   * Pass a popup action event up to the button invoker. If the first button click triggered our
   * popup (the click was in the triangle region), then we must pass action events from the popup to
   * the invoker
   */
  public void handlePopupActionEvent() {
    if (popupHandler != null) {
      popupHandler.fireActionPerformed(this);
    } else {
      Log.debug("PopupMenubutton has null popupHandler");
    }

    updateGUI();
    if (!keepVisible) {
      myPopup.hide();
    }
  }
Esempio n. 7
0
  /**
   * cam set alert, this updates the hand in/out status
   *
   * @param id hand id
   * @param type alert type
   */
  void setAlert(int id, AlertType type) {

    // App.debug("alert hand #" + id + " : " + type);

    if (handOut != OutOfField.NO) { // no hand for now
      if (type == AlertType.ALERT_HAND_INSIDE_BORDERS) {
        Log.debug("hand #" + id + " inside borders");
        handId = id;
        handOut = OutOfField.NO;
        resetAllValues = true;
      } else if (handId == id) {
        switch (type) {
          case ALERT_HAND_OUT_OF_BOTTOM_BORDER:
            handOut = OutOfField.BOTTOM;
            break;
          case ALERT_HAND_OUT_OF_TOP_BORDER:
            handOut = OutOfField.TOP;
            break;
          case ALERT_HAND_OUT_OF_LEFT_BORDER:
            handOut = OutOfField.LEFT;
            break;
          case ALERT_HAND_OUT_OF_RIGHT_BORDER:
            handOut = OutOfField.RIGHT;
            break;
          case ALERT_HAND_TOO_CLOSE:
            handOut = OutOfField.NEAR;
            break;
          case ALERT_HAND_TOO_FAR:
            handOut = OutOfField.FAR;
            break;
        }
      }
    } else if (handId == id) { // new alert from tracked hand
      if (type == AlertType.ALERT_HAND_OUT_OF_BORDERS) {
        Log.debug("hand #" + id + " out of borders");
        handOut = OutOfField.YES;
      }
    }
  }
Esempio n. 8
0
 @Override
 public void compute() {
   if (!kernel.getGeoGebraCAS().getCurrentCAS().isLoaded()) {
     inputFingerprint = null;
     return;
   }
   String inputFingerprintPrev = inputFingerprint;
   setInputOutput();
   if (inputFingerprintPrev == null || !inputFingerprintPrev.equals(inputFingerprint)) {
     Log.trace(inputFingerprintPrev + " -> " + inputFingerprint);
     initialCompute();
   }
 }
Esempio n. 9
0
  private void applyFontStyle(ArrayList<GeoElement> geos) {

    int fontStyle = 0;
    if (btnBold.isSelected()) fontStyle += 1;
    if (btnItalic.isSelected()) fontStyle += 2;
    for (int i = 0; i < geos.size(); i++) {
      GeoElement geo = geos.get(i);
      Log.debug(((GeoCasCell) geo).getGeoText());
      if (geo instanceof GeoCasCell
          && ((GeoCasCell) geo).getGeoText().getFontStyle() != fontStyle) {
        ((GeoCasCell) geo).getGeoText().setFontStyle(fontStyle);
        geo.updateRepaint();
        needUndo = true;
      }
    }
  }
Esempio n. 10
0
  /** write current renderer's image to current export file */
  public void writeExportImage() {

    if (exportFile == null) {
      Log.debug("exportFile not set");
      return;
    }

    try {
      BufferedImage img = ((RendererD) getRenderer()).getExportImage();
      MyImageIO.write(img, "png", exportDPI, exportFile);
      if (exportToClipboard) {
        GraphicExportDialog.sendToClipboard(exportFile);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 11
0
 public void setText(String s, boolean shallfocus) {
   String slatex = historyMap.get(s);
   if (slatex == null) {
     slatex = s;
   }
   Log.debug("HIST READ" + slatex + "," + s);
   if (slatex != null) {
     slatex =
         slatex
             .replace("\\$", "\\dollar ")
             .replace("$", "\\dollar ")
             .replace("(", "\\left(")
             .replace(")", "\\right)")
             .replace("\\left\\left(", "\\left(")
             .replace("\\right\\right)", "\\right)");
   }
   MathQuillHelper.updateEditingMathQuillGGB(component.getLaTeXElement(), slatex, shallfocus);
 }
Esempio n. 12
0
 @Override
 public void syncAppletPanelSize(int widthDiff, int heightDiff, int evno) {
   Log.debug(widthDiff + "x" + heightDiff);
   if (evno == 1 && getEuclidianView1().isShowing()) {
     // this should follow the resizing of the EuclidianView
     if (getSplitLayoutPanel() != null)
       getSplitLayoutPanel()
           .setPixelSize(
               getSplitLayoutPanel().getOffsetWidth() + widthDiff,
               getSplitLayoutPanel().getOffsetHeight() + heightDiff);
   } else if (evno == 2
       && hasEuclidianView2(1)
       && getEuclidianView2(1).isShowing()) { // or the EuclidianView 2
     if (getSplitLayoutPanel() != null)
       getSplitLayoutPanel()
           .setPixelSize(
               getSplitLayoutPanel().getOffsetWidth() + widthDiff,
               getSplitLayoutPanel().getOffsetHeight() + heightDiff);
   }
 }
Esempio n. 13
0
  /*
   * Take a list of commands and return all possible syntaxes for these
   * commands
   */
  private List<String> getSyntaxes(List<String> commands) {
    if (commands == null) {
      return null;
    }
    ArrayList<String> syntaxes = new ArrayList<String>();
    for (String cmd : commands) {

      String cmdInt = app.getInternalCommand(cmd);
      Localization loc = app.getLocalization();
      String syntaxString;
      if (component.isForCAS()) {
        syntaxString = app.getLocalization().getCommandSyntaxCAS(cmdInt);
      } else {
        syntaxString =
            app.getExam() == null
                ? loc.getCommandSyntax(cmdInt)
                : app.getExam().getSyntax(cmdInt, loc, app.getSettings());
      }
      if (syntaxString != null) {
        if (syntaxString.endsWith(
            component.isForCAS() ? Localization.syntaxCAS : Localization.syntaxStr)) {

          // command not found, check for macros
          Macro macro = component.isForCAS() ? null : app.getKernel().getMacro(cmd);
          if (macro != null) {
            syntaxes.add(macro.toString());
          } else {
            // syntaxes.add(cmdInt + "[]");
            Log.debug("Can't find syntax for: " + cmd);
          }

          continue;
        }
        for (String syntax : syntaxString.split("\\n")) {
          syntaxes.add(syntax);
        }
      }
    }
    return syntaxes;
  }
Esempio n. 14
0
 @Override
 public void onChange(ChangeEvent event) {
   Log.debug("onchange");
   onSliderInput();
 }
Esempio n. 15
0
 @Override
 public void exportPaintPre(GGraphics2D g2d, double scale, boolean transparency) {
   Log.error("exportPaintPre unimplemented");
 }
Esempio n. 16
0
  /**
   * Create a "Socket" for realsense camera
   *
   * @throws Exception when fails
   */
  public Socket() throws Input3DException {

    if (SESSION == null) {
      createSession();
    }

    if (SESSION == null) {
      throw new Input3DException(Input3DExceptionType.INSTALL, "RealSense: no session created");
    }

    if (SENSE_MANAGER != null) {
      throw new Input3DException(Input3DExceptionType.ALREADY_USED, "RealSense: already in use");
    }

    SENSE_MANAGER = SESSION.CreateSenseManager();
    if (SENSE_MANAGER == null) {
      throw new Input3DException(
          Input3DExceptionType.RUN, "RealSense: Failed to create a SenseManager instance");
    }

    CAPTURE_MANAGER = SENSE_MANAGER.QueryCaptureManager();
    CAPTURE_MANAGER.FilterByDeviceInfo("RealSense", null, 0);

    sts = SENSE_MANAGER.EnableHand(null);
    if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) < 0) {
      throw new Input3DException(
          Input3DExceptionType.RUN, "RealSense: Failed to enable HandAnalysis");
    }

    dataSampler = new DataAverage(SAMPLES);

    sts = SENSE_MANAGER.Init();
    if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) >= 0) {
      PXCMHandModule handModule = SENSE_MANAGER.QueryHand();
      PXCMHandConfiguration handConfig = handModule.CreateActiveConfiguration();

      handConfig.EnableAllAlerts();

      AlertHandler alertHandler =
          new AlertHandler() {

            @Override
            public void OnFiredAlert(intel.rssdk.PXCMHandData.AlertData data) {
              setAlert(data.handId, data.label);
            }
          };
      handConfig.SubscribeAlert(alertHandler);

      handConfig.ApplyChanges();
      handConfig.Update();

      handData = handModule.CreateOutput();
      hand = new PXCMHandData.IHand();

      handOut = OutOfField.YES;
      connected = true;
    }

    if (!connected) {
      throw new Input3DException(Input3DExceptionType.RUN, "RealSense: not connected");
    }

    Log.debug("RealSense: connected");
  }
Esempio n. 17
0
  /** Heavy computation of the proof. */
  public final void initialCompute() {

    // Create and initialize the prover
    Prover p = UtilFactory.getPrototype().newProver();
    ProverSettings proverSettings = ProverSettings.get();
    if ("OpenGeoProver".equalsIgnoreCase(proverSettings.proverEngine)) {
      if ("Wu".equalsIgnoreCase(proverSettings.proverMethod))
        p.setProverEngine(ProverEngine.OPENGEOPROVER_WU);
      else if ("Area".equalsIgnoreCase(proverSettings.proverMethod))
        p.setProverEngine(ProverEngine.OPENGEOPROVER_AREA);
    } else if ("Botana".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.BOTANAS_PROVER);
    else if ("Recio".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.RECIOS_PROVER);
    else if ("PureSymbolic".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.PURE_SYMBOLIC_PROVER);
    else if ("Auto".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.AUTO);
    p.setTimeout(proverSettings.proverTimeout);
    p.setConstruction(cons);
    p.setStatement(root);
    // Compute extra NDG's:
    p.setReturnExtraNDGs(true);

    // Adding benchmarking:
    double startTime = cons.getApplication().getMillisecondTime();
    p.compute(); // the computation of the proof
    int elapsedTime = (int) (cons.getApplication().getMillisecondTime() - startTime);
    /*
     * Don't remove this. It is needed for automated testing. (String match
     * is assumed.)
     */
    Log.debug("Benchmarking: " + elapsedTime + " ms");

    ProofResult proofresult = p.getProofResult();
    ExtendedBoolean result = p.getYesNoAnswer();

    Log.debug("STATEMENT IS " + proofresult + " (yes/no: " + result + ")");

    if (proofresult == ProofResult.PROCESSING) {
      list.setUndefined();
      return;
    }

    list.setDefined(true);
    list.clear();

    if (!ExtendedBoolean.UNKNOWN.equals(result)) {
      Boolean unreadable = null;

      if (proofresult == ProofResult.TRUE_NDG_UNREADABLE) {
        unreadable = true;
      }
      if (proofresult == ProofResult.TRUE) {
        unreadable = false;
      }

      GeoBoolean answer = new GeoBoolean(cons);
      answer.setValue(result.boolVal());
      list.add(answer);
      if (result.boolVal()) {
        HashSet<NDGCondition> ndgresult = p.getNDGConditions();
        GeoList ndgConditionsList = new GeoList(cons);
        ndgConditionsList.clear();
        ndgConditionsList.setDrawAsComboBox(true);
        Iterator<NDGCondition> it = ndgresult.iterator();
        TreeSet<GeoText> sortedSet = new TreeSet<GeoText>(GeoText.getComparator());

        // Collecting the set of NDG conditions.
        // The OGP data collector may left some unreadable conditions
        // so we make sure if the condition is readable.
        while (!unreadable && it.hasNext()) {
          GeoText ndgConditionText = new GeoText(cons);
          NDGCondition ndgc = it.next();
          // Do not print unnecessary conditions:
          if (ndgc.getReadability() > 0) {
            ndgc.rewrite(cons);
            String s = null;

            if (relTool) {
              String cond = ndgc.getCondition();
              if ("AreParallel".equals(cond)) {
                // non-parallism in 2D means intersecting
                // FIXME: this is not true for 3D
                s =
                    RelationNumerical.intersectString(
                        ndgc.getGeos()[0], ndgc.getGeos()[1], true, getLoc());
              } else if ("AreCollinear".equals(cond)) {
                s =
                    RelationNumerical.triangleNonDegenerateString(
                        (GeoPoint) ndgc.getGeos()[0],
                        (GeoPoint) ndgc.getGeos()[1],
                        (GeoPoint) ndgc.getGeos()[2],
                        getLoc());
              } else if ("AreEqual".equals(cond)) {
                s =
                    RelationNumerical.equalityString(
                        ndgc.getGeos()[0], ndgc.getGeos()[1], false, getLoc());
              } else if ("ArePerpendicular".equals(cond)) {
                s =
                    RelationNumerical.perpendicularString(
                        (GeoLine) ndgc.getGeos()[0], (GeoLine) ndgc.getGeos()[1], false, getLoc());
              } else if ("AreCongruent".equals(cond)) {
                s =
                    RelationNumerical.congruentSegmentString(
                        ndgc.getGeos()[0], ndgc.getGeos()[1], false, getLoc());
              }
            }
            if (s == null || !relTool) {
              GeoElement[] geos = ndgc.getGeos();
              if (geos == null) { // formula with quantities
                s = ndgc.getCondition();
              } else {
                s = getLoc().getCommand(ndgc.getCondition());
                s += "[";
                for (int i = 0; i < ndgc.getGeos().length; ++i) {
                  if (i > 0) {
                    s += ',';
                  }
                  /*
                   * There can be a case when the underlying
                   * prover sends such objects which cannot be
                   * understood by GeoGebra. In this case we
                   * use the "Objects" word. In this case we
                   * normally return ProveResult.UNKNOWN to
                   * not confuse the student, but for sure, we
                   * still do the check here as well.
                   */
                  GeoElement geo = ndgc.getGeos()[i];
                  if (geo != null) s += ndgc.getGeos()[i].getLabelSimple();
                  else s += "...";
                }
                s += "]";
                if (relTool) {
                  s = getLoc().getPlain("not") + " " + s;
                }
              }
            }

            ndgConditionText.setTextString(s);
            ndgConditionText.setLabelVisible(false);
            ndgConditionText.setEuclidianVisible(false);
            sortedSet.add(ndgConditionText);
          }
          // For alphabetically ordering, we need a sorted set here:
        }
        // Copy the sorted list into the output:
        Iterator<GeoText> it2 = sortedSet.iterator();
        while (it2.hasNext()) {
          ndgConditionsList.add(it2.next());
        }

        if (unreadable) {
          GeoText ndgConditionText = new GeoText(cons);
          String cond = "...";
          ndgConditionText.setTextString(cond);
          ndgConditionText.setLabelVisible(false);
          ndgConditionText.setEuclidianVisible(false);
          sortedSet.add(ndgConditionText);
          ndgConditionsList.add(ndgConditionText);
        }

        // Put this list to the final output (if non-empty):
        if (ndgConditionsList.size() > 0) list.add(ndgConditionsList);
      }
    }

    /*
     * Don't remove this. It is needed for testing the web platform. (String
     * match is assumed.)
     */
    Log.debug("OUTPUT for ProveDetails: " + list);
  }