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;
  }
Example #2
0
  private static void addSourceToRoute(Point p, boolean b) {
    // TODO Auto-generated method stub
    String[] redes = configProperties.getRedesNames();
    GeometryFactory fact = new GeometryFactory();
    try {
      if (redes != null) {

        NetworkManager networkMgr = NetworkModuleUtilWorkbench.getNetworkManager(context);

        CoordinateSystem coordSys = context.getLayerManager().getCoordinateSystem();
        if (coordSys != null) {
          p.setSRID(coordSys.getEPSGCode());
        }
        CoordinateReferenceSystem crs = CRS.decode("EPSG:" + coordSys.getEPSGCode());
        org.opengis.geometry.primitive.Point primitivePoint =
            GeographicNodeUtil.createISOPoint(p, crs);

        ExternalInfoRouteLN externalInfoRouteLN = new ExternalInfoRouteLN();
        ArrayList<VirtualNodeInfo> virtualNodesInfo = new ArrayList<VirtualNodeInfo>();
        for (int i = 0; i < redes.length; i++) {

          configuatorNetworks.put(
              redes[i], ((LocalGISNetworkManager) networkMgr).getAllNetworks().get(redes[i]));
          VirtualNodeInfo nodeInfo = null;
          try {
            nodeInfo =
                externalInfoRouteLN.getVirtualNodeInfo(
                    new GeopistaRouteConnectionFactoryImpl(),
                    primitivePoint,
                    networkMgr,
                    redes[i],
                    100);
          } catch (Exception e) {
            e.printStackTrace();
          }
          if (nodeInfo != null) {
            virtualNodesInfo.add(nodeInfo);
          }
        }
        if (virtualNodesInfo.size() == 0) return;
        Iterator<VirtualNodeInfo> it = virtualNodesInfo.iterator();
        double lastDistante = -1;
        VirtualNodeInfo selectedNodeInfo = null;
        while (it.hasNext()) {
          VirtualNodeInfo vNodeinfo = it.next();
          if (lastDistante == -1 || lastDistante > vNodeinfo.getDistance()) {
            selectedNodeInfo = vNodeinfo;
            lastDistante = vNodeinfo.getDistance();
          }
        }

        //
        //	((LocalGISNetworkManager)networkMgr).addNewVirtualNode(networkMgr.getNetwork(selectedNodeInfo.getNetworkName()).getGraph()
        //						, selectedNodeInfo.getEdge()
        //						, selectedNodeInfo.getRatio()
        //						, this);
        nodesInfo.put(selectedNodeInfo.hashCode(), selectedNodeInfo);
        //
        Coordinate coord = selectedNodeInfo.getLinestringVtoB().getCoordinateN(0);
        Point geom_nodes = fact.createPoint(coord);
        Feature feature = new BasicFeature(nodesFeatureCol.getFeatureSchema());
        feature.setGeometry(geom_nodes);
        //				feature.setAttribute("nodeId", new Integer(node.getID()));
        feature.setAttribute("nodeId", selectedNodeInfo.hashCode());
        sourcePointLayer.getFeatureCollectionWrapper().add(feature);

      } else {

      }
    } catch (NoSuchAuthorityCodeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (FactoryException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }