Exemple #1
0
  public void setMeasurementMode(boolean enabled) {
    measuring = enabled;

    if (enabled) {
      if (choosingPivotPoint) { // disable choose-pivot-point mode
        setChoosePivotPointMode(false);
      }
      // initialize PickCanvas for mouse picking
      if (pickCanvas == null) {
        pickCanvas = new PickCanvas(this, kainBG);
        pickCanvas.setMode(PickCanvas.GEOMETRY);
      }
      if (snapList == null) {
        snapList = new LinkedList<Point3d>();
      }
    } else // clear remaining first point and remove the marker
    if (measurer != null) {
      try {
        Mark currentMark = measurer.getMarks().getLast();
        if (currentMark.isFristPointPlaced()) {
          measurer.removeChild(currentMark);
          currentMark.setFirstPointPlaced(false);
        }
      } catch (NoSuchElementException ex) {
      }
      measurer.getMarker().removeMarkerLine();
    }
  }
Exemple #2
0
  public void setChoosePivotPointMode(boolean enabled) {
    choosingPivotPoint = enabled;

    if (enabled) {
      if (pickCanvas2 == null) {
        pickCanvas2 = new PickCanvas(this, kainBG);
        pickCanvas2.setMode(PickCanvas.GEOMETRY);
      }
    } else { // remove
      if (pivotPointAdjustor != null) {
        kainTG.removeChild(pivotPointAdjustor);
        pivotPointAdjustor = null;
      }
    }
  }
Exemple #3
0
  private MyPickResult getMouseIntersection2(MouseEvent e) {

    MyPickResult myResult = new MyPickResult();
    Point3d closestObjectPos = null;
    Node closestObject = null;

    pickCanvas2.setShapeLocation(e);
    PickResult[] allResults = null;
    try {
      allResults = pickCanvas2.pickAllSorted();
    } catch (AssertionError ex) {
    }
    ;
    if (allResults != null) {
      for (PickResult result : allResults) {
        Shape3D s = (Shape3D) result.getNode(PickResult.SHAPE3D);
        if (s != null) {
          if (closestObjectPos != null) {
            break;
          }
          try {
            PickIntersection intersection = result.getClosestIntersection(cameraPos);
            closestObjectPos = intersection.getPointCoordinatesVW();
            closestObject = s;
          } catch (NullPointerException ex) {
          }
          ;
        }
      }

      myResult.setPoint(closestObjectPos);
      myResult.setNode(closestObject);
    }

    return myResult;
  }
Exemple #4
0
  private MyPickResult getMouseIntersection(MouseEvent e, boolean withSnap) {

    MyPickResult myResult = new MyPickResult();

    Point3d closestObjectPos = null;
    Point3d closestMarkPos = null;
    Node closestObject = null;
    Node closestMark = null;

    // 0: closest object; 1: closest mark
    pickCanvas.setShapeLocation(e);
    PickResult[] allResults = null;
    try {
      allResults = pickCanvas.pickAllSorted();
    } catch (AssertionError ex) {
    }
    if (allResults != null) {
      for (PickResult result : allResults) {
        Shape3D s = (Shape3D) result.getNode(PickResult.SHAPE3D);
        if (s != null) { // only pick a Shape3D object
          if (closestObjectPos != null && closestMarkPos != null) {
            break;
          }
          try {
            PickIntersection intersection = result.getClosestIntersection(cameraPos);
            if (!(s.getParent().getParent().getParent() instanceof Mark)
                && !((s.getParent().getParent().getParent() instanceof Marker))) {
              // markdot/markline/label -> TG -> BG -> Mark/Marker
              try {
                closestObjectPos = intersection.getPointCoordinatesVW();
                closestObject = s;
              } catch (NullPointerException ex) {
              }
            } else if ((s.getParent().getParent().getParent() instanceof Mark)) {
              try {
                closestMarkPos = intersection.getPointCoordinatesVW();
                closestMark = s;
              } catch (NullPointerException ex) {
              }
            }
          } catch (NullPointerException ex) {
          }
        }
      }

      Point3d resultPos = null;
      Node resultNode = null;

      if (closestMark != null) {
        resultPos = closestMarkPos; // priority of result -> mark
        resultNode = closestMark;
      } else if (closestObject != null) {
        resultPos = closestObjectPos;
        resultNode = closestObject;
      }

      if (withSnap) { // snap resultPos to correct position

        // start trying to if cursor are inside object bounding sphere
        if ((closestObjectPos != null && bs.intersect(closestObjectPos))
            || closestMarkPos != null && bs.intersect(closestMarkPos)) {

          Point3d closestObjectPos2 = null;
          Point3d closestMarkPos2 = null;
          Node closestObject2 = null;
          Node closestMark2 = null;

          // initiate snap bounds if hasn't been initiated before
          // "snappable" targets to be considered are the ones inside threshold
          if (cursorBound == null) {
            cursorBound = new BoundingSphere(resultPos, CURSOR_THRESHOLD);
          }
          if (thresholdBound == null) {
            thresholdBound = new BoundingSphere(resultPos, SNAP_THRESHOLD);
          }

          // update the bounds
          // only if the cursor is no longer inside current cursor bounds
          if (!cursorBound.intersect(resultPos)) {
            cursorBound.setCenter(resultPos);
            thresholdBound.setCenter(resultPos);
          }

          // snap to nearest point in the list of snap targets
          double nearestDistance = FARTHEST;
          double distance;
          Point3d nearestTarget = null;

          // snap to vertex. all vertexes listed in snapList
          if (snapList.size() > 0) {
            for (Point3d snapTarget : snapList) {
              if (thresholdBound.intersect(snapTarget)) {
                distance = snapTarget.distance(resultPos);
                if (distance < nearestDistance) {
                  nearestDistance = distance;
                  nearestTarget = snapTarget;
                }

                if (nearestTarget != null) {
                  resultPos.set(nearestTarget); // snap!

                  // pick the snapped node
                  Vector3d camToSnapped = new Vector3d();
                  camToSnapped.x = resultPos.x - cameraPos.x;
                  camToSnapped.y = resultPos.y - cameraPos.y;
                  camToSnapped.z = resultPos.z - cameraPos.z;
                  pickCanvas.setShapeRay(cameraPos, camToSnapped);

                  PickResult[] allResultsSnapped = null;
                  try {
                    allResultsSnapped = pickCanvas.pickAllSorted();
                  } catch (AssertionError ex) {
                  }
                  if (allResultsSnapped != null) {
                    for (PickResult result : allResultsSnapped) {
                      Shape3D s = (Shape3D) result.getNode(PickResult.SHAPE3D);
                      if (s != null) { // only pick a Shape3D object
                        if (closestObjectPos2 != null && closestMarkPos2 != null) {
                          break;
                        }
                        try {
                          PickIntersection intersection = result.getClosestIntersection(cameraPos);
                          if (!(s.getParent().getParent().getParent() instanceof Mark)
                              && !((s.getParent().getParent().getParent() instanceof Marker))) {
                            // markdot/markline/label -> TG -> BG -> Mark/Marker
                            try {
                              closestObjectPos2 = intersection.getPointCoordinatesVW();
                              closestObject2 = s;
                            } catch (NullPointerException ex) {
                            }
                          } else if ((s.getParent().getParent().getParent() instanceof Mark)) {
                            try {
                              closestMarkPos2 = intersection.getPointCoordinatesVW();
                              closestMark2 = s;
                            } catch (NullPointerException ex) {
                            }
                          }
                        } catch (NullPointerException ex) {
                        }
                      }
                    }

                    if (closestMark2 != null) {
                      resultPos = closestMarkPos2; // priority of result -> mark
                      resultNode = closestMark2;
                    } else if (closestObject2 != null) {
                      resultPos = closestObjectPos2;
                      resultNode = closestObject2;
                    }
                  }
                }
              }
            }
          }
        }
      }

      myResult.setPoint(resultPos);
      myResult.setNode(resultNode);
    }
    return myResult;
  }