private DefaultCancellableMonitorable createCancelMonitor() {
   DefaultCancellableMonitorable monitor = new DefaultCancellableMonitorable();
   monitor.setInitialStep(0);
   monitor.setDeterminatedProcess(true);
   int clipSteps = 0;
   try {
     if (onlyClipLayerSelection) {
       FBitSet selection = overlayLayer.getRecordset().getSelection();
       clipSteps = selection.cardinality();
     } else {
       clipSteps = overlayLayer.getSource().getShapeCount();
     }
     int firstSteps = 0;
     if (onlyFirstLayerSelection) {
       FBitSet selection = firstLayer.getRecordset().getSelection();
       firstSteps = selection.cardinality();
     } else {
       firstSteps = firstLayer.getSource().getShapeCount();
     }
     int totalSteps = clipSteps + firstSteps;
     monitor.setFinalStep(totalSteps);
   } catch (ReadDriverException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return monitor;
 }
  /*
   * (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 #3
0
  private void storeOriginalSelection() throws ReadDriverException {
    FBitSet bs = layer.getSelectionSupport().getSelection();
    ReadableVectorial source = layer.getSource();

    source.start();

    for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
      IFeature feature = source.getFeature(i);
      pksSelected.add(feature.getID());
    }

    source.stop();
  }
Example #4
0
  private void doRestoreSelection() throws ReadDriverException {
    ReadableVectorial source = layer.getSource();
    Collection<String> pks = new ArrayList<String>(pksSelected);
    source.start();
    FBitSet selection = layer.getSelectionSupport().getSelection();
    selection.clear();
    for (int i = 0; i < source.getShapeCount(); i++) {
      IFeature feat = source.getFeature(i);
      String id = feat.getID();
      if (pks.contains(id)) {
        pks.remove(id);
        selection.set(i);
        if (pks.isEmpty()) {
          break;
        }
      }
    }

    source.stop();
  }
  /*
   * (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");
    }
  }
Example #6
0
  /**
   * Evaluate the expression.
   *
   * @throws ReadDriverException
   * @throws BSFException
   */
  public boolean evalExpression(String expression) throws ReadDriverException, BSFException {
    long rowCount = sds.getRowCount();
    byte[] expressionBytes;
    String encoding = System.getProperty("file.encoding");
    try {
      expressionBytes = expression.getBytes(encoding);
      expression = new String(expressionBytes, "ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
    expression = expression.replaceAll("\\[", "field(\"").replaceAll("\\]", "\")");

    interpreter.declareBean("ee", this, EvalExpression.class);
    interpreter.exec(
        ExpressionFieldExtension.JYTHON,
        null,
        -1,
        -1,
        "def expression():\n" + "  return " + expression + "");
    if (rowCount > 0) {
      try {
        interpreter.exec(
            ExpressionFieldExtension.JYTHON,
            null,
            -1,
            -1,
            "def isCorrect():\n" + "    ee.isCorrectValue(expression())\n");
        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "isCorrect()");
      } catch (BSFException ee) {
        String message = ee.getMessage();
        if (message.length() > 200) {
          message = message.substring(0, 200);
        }
        int option =
            JOptionPane.showConfirmDialog(
                (Component) PluginServices.getMainFrame(),
                PluginServices.getText(this, "error_expression")
                    + "\n"
                    + message
                    + "\n"
                    + PluginServices.getText(this, "continue?"));
        if (option != JOptionPane.OK_OPTION) {
          return false;
        }
      }
    }
    ies.startComplexRow();

    ArrayList exceptions = new ArrayList();
    interpreter.declareBean("exceptions", exceptions, ArrayList.class);
    FBitSet selection = sds.getSelection();
    if (selection.cardinality() > 0) {
      interpreter.declareBean("selection", selection, FBitSet.class);
      interpreter.exec(
          ExpressionFieldExtension.JYTHON,
          null,
          -1,
          -1,
          "def p():\n"
              + "  i=selection.nextSetBit(0)\n"
              + "  while i >=0:\n"
              + "    indexRow.set(i)\n"
              + "    obj=expression()\n"
              + "    ee.setValue(obj,i)\n"
              + "    ee.saveEdits(i)\n"
              + "    i=selection.nextSetBit(i+1)\n");
    } else {
      interpreter.exec(
          ExpressionFieldExtension.JYTHON,
          null,
          -1,
          -1,
          "def p():\n"
              + "  for i in xrange("
              + rowCount
              + "):\n"
              + "    indexRow.set(i)\n"
              +
              //						"    print i , expression() , repr (expression())\n" +
              "    ee.setValue(expression(),i)\n"
              + "    ee.saveEdits(i)\n");
    }
    try {
      interpreter.eval(ExpressionFieldExtension.JYTHON, null, -1, -1, "p()");
    } catch (BSFException ee) {

      JOptionPane.showMessageDialog(
          (Component) PluginServices.getMainFrame(),
          PluginServices.getText(this, "evaluate_expression_with_errors")
              + " "
              + (rowCount - indexRow.get())
              + "\n"
              + ee.getMessage());
    }

    ies.endComplexRow(PluginServices.getText(this, "expression"));

    return true;
  }