Package org.contikios.cooja.interfaces

Examples of org.contikios.cooja.interfaces.Position


  }

  Map<Mote, double[]> moveStartPositions = new HashMap<>();

  private void handleMouseDrag(MouseEvent e, boolean stop) {
    Position currPos = transformPixelToPosition(e.getPoint());

    switch (mouseActionState) {
      case DEFAULT_PRESS:
        if (cursorMote == null) {
          mouseActionState = MotesActionState.PANNING;
        }
        else {
          /* If we start moving with on a cursor mote, switch to MOVING */
          mouseActionState = MotesActionState.MOVING;
          // save start position
          for (Mote m : selectedMotes) {
            Position pos = m.getInterfaces().getPosition();
            moveStartPositions.put(m, new double[]{
              pos.getXCoordinate(),
              pos.getYCoordinate(),
              pos.getZCoordinate()});
          }
        }
        break;
      case MOVING:
        canvas.setCursor(MOVE_CURSOR);
View Full Code Here


    else {
      moveStartTime = -1;
    }
    /* Save start positions and set move-start position to clicked mote */
    for (Mote m : selectedMotes) {
      Position pos = m.getInterfaces().getPosition();
      moveStartPositions.put(m, new double[]{
        pos.getXCoordinate(),
        pos.getYCoordinate(),
        pos.getZCoordinate()});
    }
    pressedPos.setCoordinates(
            selectedMote.getInterfaces().getPosition().getXCoordinate(),
            selectedMote.getInterfaces().getPosition().getYCoordinate(),
            selectedMote.getInterfaces().getPosition().getZCoordinate());
View Full Code Here

  private void zoomToFactor(double newZoom) {
    zoomToFactor(newZoom, new Point(canvas.getWidth() / 2, canvas.getHeight() / 2));
  }

  private void zoomToFactor(double newZoom, Point zoomCenter) {
    Position center = transformPixelToPosition(zoomCenter);
    viewportTransform.setToScale(
            newZoom,
            newZoom
    );
    Position newCenter = transformPixelToPosition(zoomCenter);
    viewportTransform.translate(
            newCenter.getXCoordinate() - center.getXCoordinate(),
            newCenter.getYCoordinate() - center.getYCoordinate()
    );
    repaint();
  }
View Full Code Here

   * @return All motes in range
   */
  public Mote[] findMotesInRange(int startX, int startY, int width, int height) {
    List<Mote> motes = new LinkedList<>();
    for (Mote m : simulation.getMotes()) {
      Position pos = m.getInterfaces().getPosition();
      int moteX = transformToPixelX(pos.getXCoordinate());
      int moteY = transformToPixelY(pos.getYCoordinate());
      if (moteX > startX && moteX < startX + width
              && moteY > startY && moteY < startY + height) {
        motes.add(m);
      }
    }
View Full Code Here

            - transformToPositionX(0);
    double paintedMoteHeight = transformToPositionY(MOTE_RADIUS)
            - transformToPositionY(0);

    for (int i = 0; i < simulation.getMotesCount(); i++) {
      Position pos = simulation.getMote(i).getInterfaces().getPosition();

      // Transform to unit circle before checking if mouse hit this mote
      double distanceX = Math.abs(xCoord - pos.getXCoordinate())
              / paintedMoteWidth;
      double distanceY = Math.abs(yCoord - pos.getYCoordinate())
              / paintedMoteHeight;

      if (distanceX * distanceX + distanceY * distanceY <= 1) {
        motes.add(simulation.getMote(i));
      }
View Full Code Here

    /* Paint mote relations */
    if (showMoteToMoteRelations) {
      MoteRelation[] relations = simulation.getCooja().getMoteRelations();
      for (MoteRelation r : relations) {
        Position sourcePos = r.source.getInterfaces().getPosition();
        Position destPos = r.dest.getInterfaces().getPosition();

        Point sourcePoint = transformPositionToPixel(sourcePos);
        Point destPoint = transformPositionToPixel(destPos);

        g.setColor(r.color == null ? Color.black : r.color);
        drawArrow(g, sourcePoint.x, sourcePoint.y, destPoint.x, destPoint.y, MOTE_RADIUS + 1);
      }
    }

    for (Mote mote : allMotes) {

      /* Use the first skin's non-null mote colors */
      Color moteColors[] = null;
      for (VisualizerSkin skin : currentSkins) {
        moteColors = skin.getColorOf(mote);
        if (moteColors != null) {
          break;
        }
      }
      if (moteColors == null) {
        moteColors = DEFAULT_MOTE_COLORS;
      }

      Position motePos = mote.getInterfaces().getPosition();

      Point pixelCoord = transformPositionToPixel(motePos);
      int x = pixelCoord.x;
      int y = pixelCoord.y;

View Full Code Here

    final double BORDER_SCALE_FACTOR = 1.1;
    double smallX, bigX, smallY, bigY, scaleX, scaleY;

    /* Init values */
    {
      Position pos = motes[0].getInterfaces().getPosition();
      smallX = bigX = pos.getXCoordinate();
      smallY = bigY = pos.getYCoordinate();
    }

    /* Extremes */
    for (Mote mote : motes) {
      Position pos = mote.getInterfaces().getPosition();
      smallX = Math.min(smallX, pos.getXCoordinate());
      bigX = Math.max(bigX, pos.getXCoordinate());
      smallY = Math.min(smallY, pos.getYCoordinate());
      bigY = Math.max(bigY, pos.getYCoordinate());
    }

    /* Scale viewport */
    if (smallX == bigX) {
      scaleX = 1;
    }
    else {
      scaleX = (bigX - smallX) / (canvas.getWidth());
    }
    if (smallY == bigY) {
      scaleY = 1;
    }
    else {
      scaleY = (bigY - smallY) / (canvas.getHeight());
    }

    viewportTransform.setToIdentity();
    double newZoom = (1.0 / (BORDER_SCALE_FACTOR * Math.max(scaleX, scaleY)));
    viewportTransform.setToScale(
            newZoom,
            newZoom
    );

    /* Center visible motes */
    final double smallXfinal = smallX, bigXfinal = bigX, smallYfinal = smallY, bigYfinal = bigY;
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        Position viewMid
                = transformPixelToPosition(canvas.getWidth() / 2, canvas.getHeight() / 2);
        double motesMidX = (smallXfinal + bigXfinal) / 2.0;
        double motesMidY = (smallYfinal + bigYfinal) / 2.0;

        viewportTransform.translate(
                viewMid.getXCoordinate() - motesMidX,
                viewMid.getYCoordinate() - motesMidY);
        canvas.repaint();
      }
    });
  }
View Full Code Here

  public Position transformPixelToPosition(Point pixelPos) {
    return transformPixelToPosition(pixelPos.x, pixelPos.y);
  }

  public Position transformPixelToPosition(int x, int y) {
    Position position = new Position(null);
    position.setCoordinates(
            transformToPositionX(x),
            transformToPositionY(y),
            0.0
    );
    return position;
View Full Code Here

      gui.deleteMoteRelationsObserver(moteRelationsObserver);
    }

    simulation.getEventCentral().removeMoteCountListener(newMotesListener);
    for (Mote mote : simulation.getMotes()) {
      Position pos = mote.getInterfaces().getPosition();
      if (pos != null) {
        pos.deleteObserver(posObserver);
      }
    }
  }
View Full Code Here

          g.drawOval(sourcePoint.x - 30, sourcePoint.y - 30, 60, 60);
          continue;
        }
        g.setColor(new Color(TRANSMITTED_COLOR_RGB[0], TRANSMITTED_COLOR_RGB[1], TRANSMITTED_COLOR_RGB[2], colorHistoryIndex));
        for (Radio destRadio : connArrow.getConnection().getDestinations()) {
          Position destPos = destRadio.getPosition();
          Point destPoint = visualizer.transformPositionToPixel(destPos);
          drawArrow(g, sourcePoint.x, sourcePoint.y, destPoint.x, destPoint.y, 8);
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.contikios.cooja.interfaces.Position

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.