Exemple #1
0
  /**
   * This method updates the <code>EditMode</code>'s knowledge of the currently-selected vertices in
   * the <code>MeshApplication</code>.
   */
  @Override
  public void selectionChanged() {
    // We can only modify the selection if it's not being used. Currently,
    // the only other place where the current selection is read when this
    // method executes is in simpleUpdate().
    selectionLock.lock();
    try {
      // Clear all temporary controllers, etc.
      clearSelection();

      // Get the size that the vertex view should have.
      float vertexSize = appState.getVertexSize();
      float scale = appState.getScale();

      // Add each of the currently-selected vertices to the map.
      for (Vertex vertex : appState.getSelectionManager().getSelectedVertices()) {
        int id = vertex.getId();

        // Put the selected vertex in the map.
        selectedVertices.put(id, vertex);

        // Create a temporary clone of the current vertex.
        Vertex clone = (Vertex) vertex.clone();

        // Create a temporary controller for the clone vertex.
        // TODO Set up this material in initMaterials
        VertexController controller =
            new VertexController(clone, updateQueue, createBasicMaterial(null));
        controller.setParentNode(tempSpatials);
        controller.setState(StateType.Temporary);
        controller.setSize(vertexSize);
        controller.setScale(scale);
        vertexControllers.put(clone.getId(), controller);
      }
    } finally {
      selectionLock.unlock();
    }

    return;
  }
Exemple #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ice.client.widgets.mesh.MeshAppStateMode#leftClick(boolean ,
   * float)
   */
  @Override
  public void leftClick(boolean isPressed, float tpf) {
    super.leftClick(isPressed, tpf);

    // Update the mouseDown boolean.
    mouseDown.set(isPressed);

    // We need to differentiate between mouse clicks and mouse drags. Below,
    // we classify them as follows:
    // If your mouse down+up is less than 0.25 seconds, it's a click.
    // If your mouse down+up is greater than 0.25 seconds, then:
    // if the mouse did not move, it is a click
    // if the mouse moved, it is a drag

    if (mouseDown.get()) {
      // Start a timer for the click. The click timer should expire after
      // a quarter of a second. Then it should set the boolean "click" to
      // false.
      clickTimer = new Timer(true);
      clickTimer.schedule(
          new TimerTask() {
            @Override
            public void run() {
              click.set(false);
            }
          },
          clickThreshold);

      // Set the starting location of the mouse drag.
      CollisionResults results = getCollision(grid, appState.getCursorRayFromClick());
      if (results.size() > 0) {
        dragStart = appState.getClosestGridPoint(results.getClosestCollision().getContactPoint());
      }
    }
    // Note: We have to check the clickTimer because it may be possible for
    // the AWTPanel to fire a mouse release event but not a mouse press
    // event.
    else if (clickTimer != null) {
      // Stop the click timer.
      clickTimer.cancel();

      // We need to get the current state of the click and drag booleans.
      // We should also reset them since the mouseUp signals the end of
      // the sequence of mouse events.
      boolean click = this.click.getAndSet(true);
      boolean drag = this.drag.getAndSet(false);

      // The first condition is for clicks. Either the click was fast
      // enough or the mouse did not move.
      if (click || !drag) {
        // Determine whether or not shift and control were pressed.
        boolean addToSelection = shiftPressed.get();
        boolean toggleSelection = controlPressed.get();

        // Get the Vertex for the clicked geometry if possible and add
        // it to the collection of selected vertices.
        CollisionResults results = getCollision(vertexSpatials, appState.getCursorRayFromClick());
        Vertex clickedVertex = null;
        int id = 0;
        if (results.size() > 0) {
          // Get the Vertex ID from the VertexView.
          id = Integer.parseInt(results.getClosestCollision().getGeometry().getName());
          clickedVertex = appState.getMesh().getVertex(id);
        }

        MeshSelectionManager selection = appState.getSelectionManager();
        if (addToSelection) {
          // A shift-click should only add the clicked item to the
          // current selection.
          if (clickedVertex != null) {
            selection.selectVertex(id);
          }
        } else if (toggleSelection) {
          // A control-click should toggle clicked item's selection
          // state.
          if (clickedVertex != null) {
            if (selection.getSelectedVertexIds().contains(id)) {
              selection.deselectVertex(id);
            } else {
              selection.selectVertex(id);
            }
          }
        } else {
          // A standard click should clear the selection and set the
          // clicked item (if any) to the current selection.

          selection.clearSelection();
          if (clickedVertex != null) {
            selection.selectVertex(id);
          }
        }
      }
      // The second condition is for drags. The click was too slow and the
      // mouse moved.
      else {
        // For now, all drag does it drag the currently-selected
        // vertices. We do not draw boxes around things yet, so we do
        // not need to check for shift or control.

        // Update the location for each of the selected vertices.
        for (Vertex v : selectedVertices.values()) {
          VertexController controller = vertexControllers.get(v.getId());
          Vector3f location = controller.getLocation();
          v.setLocation(location.x, location.y, location.z);
        }
      }

      // Reset the click timer.
      clickTimer = null;
    }

    return;
  }