コード例 #1
0
ファイル: CommBaseManager.java プロジェクト: NTNU-MCS/neptus
  /**
   * Shutdown. Stops the {@link #openNode} and {@link #messageProcessor} and clears the messages
   * queue. Calls the stopMsgProcessing on the vehicle comms. Then sends a {@link #MANAGER_STOP}
   * event.
   *
   * <p style="color='GREEN'">This one needs to be called if you override it.
   *
   * @return
   */
  @Override
  public synchronized boolean stop() {
    boolean ret;
    try {
      if (!started) return true; // do nothing
      NeptusLog.pub().debug("Stopping comms");
      if (timerThread != null) {
        timerThread.interrupt();
        timerThread = null;
      }

      stopManagerComms();

      if (messageProcessor != null) {
        messageProcessor.stopProcessing();
        messageProcessor = null;
        msgQueue.clear();
        infoQueue.clear();
      }

      for (SystemCommBaseInfo<M, Mi, I> vic : commInfo.values()) {
        vic.stopMsgProcessing();
      }

      sendManagerStatusChanged(MANAGER_STOP, "");
      started = false;
      ret = true;
    } catch (Exception e) {
      GuiUtils.errorMessage(ConfigFetch.getSuperParentFrame(), e);
      NeptusLog.pub().error("CommBase Manager init error!", e);
      ret = false;
    }
    super.stop();
    return ret;
  }
コード例 #2
0
 private void printErrors(String[] errors) {
   String errorsString = "<html>" + I18n.text("The following errors were found") + ":<br>";
   int i = 1;
   for (String error : errors) {
     errorsString = errorsString + "<br> &nbsp;" + (i++) + ") " + error;
   }
   errorsString = errorsString + "</html>";
   GuiUtils.errorMessage(
       new JFrame(I18n.text("Error")), I18n.text("Invalid properties"), errorsString);
 }
コード例 #3
0
  private void solve() {

    if (pe == null) {
      GuiUtils.errorMessage(getConsole(), "Coverage Plan Solver", "The polygon is not valid");
      return;
    }

    double north, east, south, west;
    double[] bounds = pe.getBounds3d();

    south = bounds[PathElement.SOUTH_COORD];
    west = bounds[PathElement.WEST_COORD];
    north = bounds[PathElement.NORTH_COORD];
    east = bounds[PathElement.EAST_COORD];

    CoverageCell[][] cells =
        new CoverageCell[(int) ((north - south) / grid) + 1][(int) ((east - west) / grid) + 1];

    for (int i = 0; i < cells.length; i++)
      for (int j = 0; j < cells[i].length; j++) {
        cells[i][j] = new CoverageCell();
        cells[i][j].i = i;
        cells[i][j].j = j;
      }

    int i = 0, j = 0;
    int desiredCells = 0;
    for (double n = south + grid / 2; n < north; n += grid) {
      j = 0;
      for (double e = west + grid / 2; e < east; e += grid) {
        LocationType lt = new LocationType(pe.getCenterLocation());
        lt.translatePosition(n, e, 0);
        CoverageCell cell = cells[i][j];
        cell.realWorldLoc = lt.getNewAbsoluteLatLonDepth();
        if (pe.containsPoint(lt, null)) {
          cell.desired = true;
          desiredCells++;
        }
        cells[i][j] = cell;
        j++;
      }
      i++;
    }

    CoverageCell initialCell = null;
    i = 0;
    for (j = 0; j < cells[0].length - 1 && initialCell == null; j++)
      for (i = 0; i < cells.length && initialCell == null; i++)
        if (cells[i][j].desired) initialCell = cells[i][j];

    if (initialCell == null) {
      GuiUtils.errorMessage("Polygon coverage", "Polygon area is invalid");
      return;
    }

    CoverageCell current = initialCell;
    desiredCells--;

    int dir = -1;

    while (desiredCells > 0) {
      current.visited = true;
      current.active = false;
      if (dir == 1) {
        if (current.i < cells.length - 1
            && cells[current.i + 1][current.j].desired == true
            && cells[current.i + 1][current.j].visited == false) {
          current.next = cells[current.i + 1][current.j];
          cells[current.i + 1][current.j].previous = current;
          current = current.next;
          current.active = true;
        } else {
          dir = -1;
          if (current.j == cells[0].length - 1) break;

          while (!cells[current.i][current.j + 1].desired && i > 0 && current.previous != null) {
            current.active = false;
            current = current.previous;
          }

          if (i == 0) break;

          current.next = cells[current.i][current.j + 1];
          cells[current.i][current.j + 1].previous = current;
          current = current.next;
          current.active = true;
        }
      } else {
        if (current.i > 0
            && cells[current.i - 1][current.j].desired == true
            && cells[current.i - 1][current.j].visited == false) {
          current.next = cells[current.i - 1][current.j];
          cells[current.i - 1][current.j].previous = current;
          current = current.next;
          current.active = true;
        } else {
          dir = 1;
          if (current.j == cells[0].length - 1) break;

          while (current.previous != null
              && !cells[current.i][current.j + 1].desired
              && i < cells.length) {
            current.active = false;
            current = current.previous;
          }

          if (i == cells.length) break;

          current.next = cells[current.i][current.j + 1];
          cells[current.i][current.j + 1].previous = current;
          current = current.next;
          current.active = true;
        }
      }
      desiredCells--;
    }
    generatePlans(cells, initialCell);
  }
コード例 #4
0
  void generatePlans(CoverageCell[][] mat, CoverageCell first) {

    Vector<String> selectedVehicles = new Vector<String>();
    Vector<SystemsList> tmp = getConsole().getSubPanelsOfClass(SystemsList.class);

    selectedVehicles.addAll(tmp.get(0).getSelectedSystems(true));
    Object planid;

    if (selectedVehicles.size() > 1)
      planid = JOptionPane.showInputDialog(getConsole(), "Enter desired plan prefix");
    else planid = JOptionPane.showInputDialog(getConsole(), "Enter desired plan name");

    MissionType mission = getConsole().getMission();

    if (mission == null) {
      GuiUtils.errorMessage(getConsole(), "Coverage Plan Solver", "No mission has been set");
      return;
    }

    if (selectedVehicles.size() <= 1) {
      CoverageCell current = first, next = current.next;
      PlanCreator creator = new PlanCreator(mission);
      creator.setLocation(first.realWorldLoc);
      // creator.addManeuver("Goto");
      while (next != null) {
        if (next.j != current.j) {
          CoverageCell pivot = current;
          while (pivot.previous != null && pivot.previous.i == current.i) pivot = pivot.previous;
          creator.setLocation(pivot.realWorldLoc);
          creator.addManeuver("Goto");
          creator.setLocation(next.realWorldLoc);
          creator.addManeuver("Goto");
        }
        current = next;
        next = current.next;
      }

      PlanType plan = creator.getPlan();
      plan.setId(planid.toString());
      plan.setVehicle(getConsole().getMainSystem());
      mission.addPlan(plan);
      mission.save(false);
      getConsole().updateMissionListeners();
    } else {
      double distance = 0;
      CoverageCell current = first, next = current.next;
      distance += current.realWorldLoc.getDistanceInMeters(next.realWorldLoc);
      while (next != null) {
        if (next.j != current.j) {
          CoverageCell pivot = current;
          while (pivot.previous != null && pivot.previous.i == current.i) pivot = pivot.previous;
        }
        distance += current.realWorldLoc.getDistanceInMeters(next.realWorldLoc);
        current = next;
        next = current.next;
      }

      double distEach = distance / selectedVehicles.size();

      current = first;
      next = current.next;
      PlanCreator creator = new PlanCreator(mission);
      creator.setLocation(current.realWorldLoc);
      distance = 0;
      int curIndex = 0;
      while (next != null) {

        if (next.j != current.j) {
          CoverageCell pivot = current;
          while (pivot.previous != null && pivot.previous.i == current.i) pivot = pivot.previous;
          creator.setLocation(pivot.realWorldLoc);
          creator.addManeuver("Goto");

          distance += current.realWorldLoc.getDistanceInMeters(next.realWorldLoc);

          if (distance < distEach) {
            creator.setLocation(next.realWorldLoc);
            creator.addManeuver("Goto");
          }
        } else distance += current.realWorldLoc.getDistanceInMeters(next.realWorldLoc);

        if (distance > distEach) {
          creator.setLocation(current.realWorldLoc);
          creator.addManeuver("Goto");
          PlanType plan = creator.getPlan();
          plan.setVehicle(selectedVehicles.get(curIndex));
          plan.setId(planid + "_" + selectedVehicles.get(curIndex++));

          mission.addPlan(plan);
          creator = new PlanCreator(mission);
          creator.setLocation(current.realWorldLoc);
          creator.addManeuver("Goto");
          distance = 0;
        }
        current = next;
        next = current.next;
      }
      PlanType plan = creator.getPlan();
      plan.setVehicle(selectedVehicles.get(curIndex));
      plan.setId(planid + "_" + selectedVehicles.get(curIndex++));

      mission.addPlan(plan);

      mission.save(false);
      getConsole().updateMissionListeners();
    }
  }
コード例 #5
0
ファイル: Viewer3D.java プロジェクト: CptColonlSandrs/neptus
  @SuppressWarnings("unchecked")
  public void openFile(File fx) {
    saveFile = null;
    File file;
    if (fx == null) file = showOpenImageDialog();
    else file = fx;
    if (file != null) {
      if ("3ds".equalsIgnoreCase(FileUtil.getFileExtension(file))) {
        if (lobj != null) render.removeObj3D(lobj);
        Inspector3DS loader = new Inspector3DS(file.getAbsolutePath()); // constructor
        loader.parseIt(); // process the file
        TransformGroup theModel1 = loader.getModel(); // get the
        // resulting 3D
        NeptusLog.waste().info("Point to view window " + Util3D.getModelDim(theModel1));
        lobj = new Obj3D();
        lobj.setModel3D(theModel1);
        // lobj.setRoll(Math.PI/2);
        render.addObj3D(lobj);

        update3dFilesOpened(file);
      } else if ("wrl".equalsIgnoreCase(FileUtil.getFileExtension(file))) {

        /*
         * try {
         *
         * if (lobj != null) render.removeObj3D(lobj);
         *
         * String filename = file.getAbsolutePath(); VrmlLoader loader =
         * new VrmlLoader();
         *
         * BufferedReader in = null; in = new BufferedReader(new
         * InputStreamReader(new FileInputStream(filename), "UTF8"));
         *
         * URL url = FileUtil.pathToURL(file.getParent()+"/");
         * loader.setBaseUrl(url);
         *
         * Scene scene = loader.load(in); BranchGroup branch =
         * scene.getSceneGroup();
         *
         * TransformGroup ret = new TransformGroup(); Enumeration<Group>
         * enume = branch.getAllChildren(); while
         * (enume.hasMoreElements()) { Group next = enume.nextElement();
         * branch.removeChild(next); ret.addChild(next); }
         * lobj.setModel3D(ret); //lobj.setRoll(Math.PI / 2);
         * render.addObj3D(lobj);
         *
         *
         * } catch (Throwable e) { e.printStackTrace();
         * GuiUtils.errorMessage(this, "Load",
         * "Error Loading WRL File");
         *
         * }
         */

        // --------------------------------------------------------
        if (lobj != null) render.removeObj3D(lobj);

        Loader myFileLoader = null; // holds the file loader
        Scene myVRMLScene = null; // holds the loaded scene
        BranchGroup myVRMLModel = null; // BG of the VRML scene
        try {
          // create an instance of the Loader
          myFileLoader = new org.web3d.j3d.loaders.VRML97Loader();

          myFileLoader.setBasePath(file.getParent());
          myFileLoader.setFlags(
              myFileLoader.getFlags() | org.web3d.j3d.loaders.VRML97Loader.LOAD_BEHAVIOR_NODES);
          // Load the scene from your VRML97 file
          myVRMLScene = myFileLoader.load(file.getAbsolutePath());

          // Obtain the root BranchGroup for the Scene
          myVRMLModel = myVRMLScene.getSceneGroup();
          lobj = new Obj3D();
          TransformGroup scene = new TransformGroup();
          Enumeration<Node> enume = myVRMLModel.getAllChildren();
          while (enume.hasMoreElements()) {
            Node next = enume.nextElement();
            myVRMLModel.removeChild(next);
            scene.addChild(next);
          }
          lobj.setModel3D(scene);
          // lobj.setRoll(Math.PI / 2);
          render.addObj3D(lobj);

          /*
           * VrmlLoader f = new VrmlLoader(); Scene s = null;
           * BranchGroup myVRMLModel = null; //BG of the VRML scene
           * try { //f.setFlags(VrmlLoader.LOAD_ALL); s =
           * f.load(file.getAbsolutePath()); // Obtain the root
           * BranchGroup for the Scene myVRMLModel =
           * s.getSceneGroup(); lobj = new Obj3D(); TransformGroup
           * scene = new TransformGroup(); Enumeration<Group> enume =
           * myVRMLModel.getAllChildren(); while
           * (enume.hasMoreElements()) { Group next =
           * enume.nextElement(); myVRMLModel.removeChild(next);
           * scene.addChild(next); } lobj.setModel3D(scene);
           * //lobj.setRoll(Math.PI / 2); render.addObj3D(lobj); }
           * catch (FileNotFoundException e) { e.printStackTrace();
           * GuiUtils.errorMessage(this, "Load",
           * "Error Loading WRL File"); }
           */

          update3dFilesOpened(file);

          System.err.println("fez o load----------");
        } catch (Exception e) {
          // in case there was a problem, print the stack out
          e.printStackTrace();
          // we still need a model, even if we can't load the right
          // one, I use a color cube just in case
          GuiUtils.errorMessage(this, "Load", "Error Loading WRL File");
        }

      } else if ("x3d".equalsIgnoreCase(FileUtil.getFileExtension(file))
          || "x3dv".equalsIgnoreCase(FileUtil.getFileExtension(file))) {

        if (lobj != null) render.removeObj3D(lobj);

        Loader myFileLoader = null; // holds the file loader
        Scene myVRMLScene = null; // holds the loaded scene
        BranchGroup myVRMLModel = null; // BG of the VRML scene
        try {
          // create an instance of the Loader
          myFileLoader = new org.web3d.j3d.loaders.X3DLoader();
          myFileLoader.setBasePath(file.getParent());

          // myFileLoader.setFlags(org.web3d.j3d.loaders.X3DLoader.LOAD_ALL);
          // Load the scene from your VRML97 file
          myVRMLScene = myFileLoader.load(file.getAbsolutePath());

          // Obtain the root BranchGroup for the Scene
          myVRMLModel = myVRMLScene.getSceneGroup();
          lobj = new Obj3D();
          TransformGroup scene = new TransformGroup();
          Enumeration<Group> enume = myVRMLModel.getAllChildren();
          while (enume.hasMoreElements()) {
            Group next = enume.nextElement();
            myVRMLModel.removeChild(next);
            scene.addChild(next);
          }
          lobj.setModel3D(scene);
          // lobj.setRoll(Math.PI / 2);
          render.addObj3D(lobj);

          update3dFilesOpened(file);

          System.err.println("fez o load----------");
        } catch (Exception e) {
          // in case there was a problem, print the stack out
          e.printStackTrace();
          // we still need a model, even if we can't load the right
          // one, I use a color cube just in case
          GuiUtils.errorMessage(this, "Load", "Error Loading x3D File");
        }

      } else if ("j3d".equalsIgnoreCase(FileUtil.getFileExtension(file))) {

        if (lobj != null) render.removeObj3D(lobj);

        BranchGroup bg = null;

        try {
          SceneGraphFileReader filer = new SceneGraphFileReader(file);
          bg = (filer.readAllBranchGraphs())[0];
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        if (bg == null) {
          NeptusLog.pub().error("Error loading vehicle model\n" + this);
        }
        TransformGroup scene = new TransformGroup();

        Enumeration<Group> enume = bg.getAllChildren();
        while (enume.hasMoreElements()) {
          Group next = enume.nextElement();
          bg.removeChild(next);
          scene.addChild(next);
        }
        lobj = new Obj3D();
        lobj.setModel3D(scene);
        // lobj.setRoll(Math.PI / 2);
        render.addObj3D(lobj);

        update3dFilesOpened(file);
      } else GuiUtils.errorMessage(this, "Load", "Invalid file type.");
    }
  }