Example #1
0
  public boolean execute(PlugInContext context) throws Exception {
    if (context.getLayerViewPanel() == null) return false;
    this.networkMgr = NetworkModuleUtilWorkbench.getNetworkManager(context);
    configProperties = new CalcRutaConfigFileReaderWriter();
    if (configProperties.getRedesNames() == null) {
      context
          .getLayerViewPanel()
          .getContext()
          .warnUser(
              I18N.get("calcruta", "routeengine.calcularruta.errormessage.emptyconfiguration"));
      return false;
    }
    this.context = context;
    nodesInfo = new HashMap<Integer, VirtualNodeInfo>();
    configuatorNetworks = new HashMap<String, Network>();

    nodesFeatureCol = AddNewLayerPlugIn.createBlankFeatureCollection();
    nodesFeatureCol.getFeatureSchema().addAttribute("nodeId", AttributeType.INTEGER);

    if (context.getLayerManager().getLayer("Puntos para TSP") != null) {
      context.getLayerManager().remove(sourcePointLayer);
    }

    sourcePointLayer = context.addLayer("Puntos TSP", "Puntos para TSP", nodesFeatureCol);

    //		LabelStyle labelStyle = new LabelStyle();
    //		labelStyle.setAttribute("nodeId");
    //		labelStyle.setColor(Color.black);
    //		labelStyle.setScaling(false);
    //		labelStyle.setEnabled(true);
    //		sourcePointLayer.addStyle(labelStyle);

    if (networkMgr == null) {
      context.getLayerViewPanel().getContext().warnUser("Error en el NetworkManager.");
      return false;
    }

    if (networkMgr.getNetworks().isEmpty()) {
      context
          .getLayerViewPanel()
          .getContext()
          .warnUser("No hay redes cargadas en el NetworkManager");
      return false;
    }

    if (configProperties.getRedesNames().length <= 0) {
      context
          .getLayerViewPanel()
          .getContext()
          .warnUser("Error en la configuracion. Inicie el configurador de rutas");
    }

    String redes[] = configProperties.getRedesNames();
    for (int i = 0; i < redes.length; i++) {
      configuatorNetworks.put(
          redes[i], ((LocalGISNetworkManager) networkMgr).getAllNetworks().get(redes[i]));
    }
    for (int m = 0; m < configuatorNetworks.values().size(); m++) {
      if (configuatorNetworks.values().toArray()[m] == null) {
        context
            .getLayerViewPanel()
            .getContext()
            .warnUser("Error en la configuracion. Inicie el configurador de rutas");
        return false;
      }
    }

    ToolboxDialog toolbox = new ToolboxDialog(context.getWorkbenchContext());
    //		toolbox.add();
    //
    //		RouteEngineDrawPointTool.createCursor(IconLoader.icon("bandera.gif").getImage());
    context
        .getLayerViewPanel()
        .setCurrentCursorTool(RouteEngineTSPDrawPointTool.create(toolbox.getContext()));

    return false;
  }
  /**
   * @param context
   * @throws IOException
   */
  private void saveTrafficRegulationInformation(PlugInContext context, TaskMonitor monitor)
      throws IOException {

    String netName = "";
    if (getSelectedLayer().getSystemId().startsWith("Arcos-")) {
      String[] a = getSelectedLayer().getSystemId().split("-");
      netName = a[1];
      System.out.println(a.length);
      for (int i = 2; i < a.length; i++) {
        netName = netName + "-" + a[i];
      }
    } else {
      netName = getSelectedLayer().getSystemId();
    }

    ArrayList<GeopistaFeature> listaFeatures = this.getSelectedsArrayListStreetFeature();
    ArrayList<Integer> listaEdgeIds = this.getSelectedsArrayListEdgesIds();

    for (int i = 0; i < listaFeatures.size(); i++) {

      monitor.report("Modificando Direccion tramo " + i + " de " + listaEdgeIds.size());

      Edge selectedEdge = searchEdgeByIdAndNetworkName(context, netName, listaEdgeIds.get(i));

      if (selectedEdge instanceof LocalGISStreetDynamicEdge) {
        // Se actualiza el StreetEdge
        ((LocalGISStreetDynamicEdge) selectedEdge).setTrafficRegulation(getTrafficRegualtion());

        RouteArrowLineStyle line =
            new RouteArrowLineStyle.BiDirect(
                (Viewport) context.getLayerViewPanel().getViewport(),
                (Graphics2D) ((LayerViewPanel) context.getLayerViewPanel()).getGraphics());
        if (this.getSelectedLayer().getStyle(RouteArrowLineStyle.class) != null) {
          getSelectedLayer().removeStyle(getSelectedLayer().getStyle(RouteArrowLineStyle.class));
        }
        getSelectedLayer().addStyle(line);

        GeopistaFeature feat = listaFeatures.get(i);

        if (feat != null) {
          // se actualiza el valor de la feature
          feat.setAttribute(
              I18N.get(
                  "regulacionTrafico",
                  "routeengine.trafficregulation.trafficregulationattributename"),
              getTrafficRegualtion().toString());
          //					this.paintBidirectTrafiicRegulation(getTrafficRegualtion());

          if (feat.getSchema().hasAttribute("pintadaRegulacionTrafico")
              && feat.getAttribute("pintadaRegulacionTrafico") != null
              && feat.getAttribute("pintadaRegulacionTrafico") instanceof Integer) {
            try {
              feat.setAttribute("pintadaRegulacionTrafico", 1);
            } catch (Exception e) {
            }
          }
        }

        context.getLayerViewPanel().repaint();
      }
      NetworkManager nManager = NetworkModuleUtilWorkbench.getNetworkManager(context);
      Network actualNetwork = nManager.getNetwork(netName);

      // intentamos insercion en la base de datos de la velocidad de la v�a
      Category categoryLayer = context.getLayerManager().getCategory(getSelectedLayer());
      if (!categoryLayer.getName().equals("")) {
        if (actualNetwork.getGraph() instanceof DynamicGraph
            && ((DynamicGraph) actualNetwork.getGraph()).getMemoryManager()
                instanceof SpatialAllInMemoryExternalSourceMemoryManager) {
          RouteConnectionFactory routeConnection = new GeopistaRouteConnectionFactoryImpl();
          LocalGISNetworkDAO lnDAO = new LocalGISNetworkDAO();
          Connection connection = null;
          try {
            connection = routeConnection.getConnection();
            lnDAO.updateStreetData(netName, (LocalGISStreetDynamicEdge) selectedEdge, connection);
          } catch (SQLException e) {
            e.printStackTrace();
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            ConnectionUtilities.closeConnection(connection);
          }
        }
      }
    }
  }