/*
   * (non-Javadoc)
   *
   * @see
   * com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#polylineFinished
   * (com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
   */
  public void polylineFinished(MeasureEvent event) throws BehaviorException {
    try {
      GeneralPathX gp = event.getGP();
      IGeometry geom = ShapeFactory.createPolyline2D(gp);
      FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();

      for (int i = 0; i < actives.length; i++) {
        if (actives[i] instanceof FLyrVect) {
          FLyrVect lyrVect = (FLyrVect) actives[i];
          FBitSet oldBitSet = lyrVect.getSource().getRecordset().getSelection();
          FBitSet newBitSet = lyrVect.queryByShape(geom, DefaultStrategy.INTERSECTS);
          if (event.getEvent().isControlDown()) newBitSet.xor(oldBitSet);
          lyrVect.getRecordset().setSelection(newBitSet);
        }
      }
    } catch (com.vividsolutions.jts.geom.TopologyException topEx) {
      NotificationManager.showMessageError(
          PluginServices.getText(
              null, "Failed_selecting_geometries_by_polyline_topology_exception_explanation"),
          topEx);
    } catch (Exception ex) {
      NotificationManager.showMessageError(
          PluginServices.getText(null, "Failed_selecting_geometries"), ex);
    }
  }
Example #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.gvsig.fmap.tools.Listeners.PointListener#point(org.gvsig.fmap.tools
   * .Events.PointEvent) The PointEvent method bring you a point in pixel
   * coordinates. You need to transform it to world coordinates. The class to
   * do conversions is ViewPort, obtained thru the MapContext of mapCtrl.
   */
  public void point(PointEvent event) throws BehaviorException {
    com.iver.cit.gvsig.fmap.ViewPort vp = mapCtrl.getViewPort();
    Point2D pReal = vp.toMapPoint(event.getPoint());

    SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
    while (it.hasNext()) {
      FLayer aux = it.next();
      if (!aux.isActive()) continue;
      Network net = (Network) aux.getProperty("network");

      if (net != null) {

        double realTol = vp.toMapDistance(pixelTolerance);
        Point2D pReal2 =
            vp.toMapPoint(
                (int) event.getPoint().getX() + pixelTolerance,
                (int) event.getPoint().getY() + pixelTolerance);

        // if ((vp.getProjection() != null) &&
        // !(vp.getProjection().isProjected())) {
        // realTol = vp.distanceWorld(pReal, pReal2);
        // }

        GvFlag flag;
        try {
          if (mode == TO_ARC) flag = net.addFlag(pReal.getX(), pReal.getY(), realTol);
          else flag = net.addFlagToNode(pReal.getX(), pReal.getY(), realTol);
          if (flag == null) {
            JOptionPane.showMessageDialog(
                null, PluginServices.getText(this, "point_not_on_the_network"));
            return;
          }
          NetworkUtils.addGraphicFlag(mapCtrl, flag);
          mapCtrl.drawGraphics();
          PluginServices.getMainFrame().enableControls();
        } catch (GraphException e) {
          e.printStackTrace();
          NotificationManager.addError(e);
        }
      }
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com
   * .iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
   */
  public void rectangle(RectangleEvent event) throws BehaviorException {
    try {
      // mapCtrl.getMapContext().selectByRect(event.getWorldCoordRect());
      Rectangle2D rect = event.getWorldCoordRect();
      FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
      for (int i = 0; i < actives.length; i++) {
        if (actives[i] instanceof FLyrVect) {
          FLyrVect lyrVect = (FLyrVect) actives[i];
          FBitSet oldBitSet = lyrVect.getSource().getRecordset().getSelection();
          FBitSet newBitSet = lyrVect.queryByRect(rect);
          if (event.getEvent().isControlDown()) newBitSet.xor(oldBitSet);
          lyrVect.getRecordset().setSelection(newBitSet);
        }
      }

    } catch (ReadDriverException e) {
      throw new BehaviorException("No se pudo hacer la selección");
    } catch (VisitorException e) {
      throw new BehaviorException("No se pudo hacer la selección");
    }
  }