Beispiel #1
0
  // THIS ADDS A PART TO THE LANE AND UPDATES AGENT INFO
  @Override
  public void msgDoAddPart(GUIPart guipart) {
    state = State.LANE_MOVING;
    parts.add(guipart);
    if (parts.size() >= almostFull && toldAgentItsFull == false) {
      myAgent.msgGuiLaneAlmostFull();
      toldAgentItsFull = true;
    }
    if (parts.size() < almostFull && toldAgentItsFull == true) {
      myAgent.msgGuiLaneNoLongerFull();
      toldAgentItsFull = false;
    }

    MyPart partAdd = new MyPart(guipart);
    partsLane.add(partAdd);
  }
  @Test
  public void testReceiveTwoParts() {
    int scheduleCounter = 0;
    System.out.println("------------------------------\n" + "testReceiveTwoParts():");

    Lane lane = new LaneAgent("Lane1");
    GUILane guiLane = new GUILane(1, 2, 3, new GUINest(1, 2, 3));

    MockFeeder feeder = new MockFeeder("Feeder1");
    MockDiverter diverter = new MockDiverter("Diverter1");
    MockNest nest = new MockNest("Nest1");

    lane.setFeederAgent(feeder);
    lane.setDiverterAgent(diverter);
    lane.setNestAgent(nest);
    lane.setGuiLane(guiLane);
    guiLane.setLaneAgent(lane);

    assertEquals(
        "Mock Feeder should have an empty event log before the Lane's scheduler is called. Instead, the Mock Feeder's event log reads: "
            + feeder.log.toString(),
        0,
        feeder.log.size());
    assertEquals(
        "Mock Diverter should have an empty event log before the Lane's scheduler is called. Instead, the Mock Diverter's event log reads: "
            + diverter.log.toString(),
        0,
        diverter.log.size());
    assertEquals(
        "Mock Nest should have an empty event log before the Lane's scheduler is called. Instead, the Mock Nest's event log reads: "
            + nest.log.toString(),
        0,
        nest.log.size());

    // create a part used for testing
    Part part1 = new Part(PartType.A);

    lane.msgPartReady(part1);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock diverter should have received msgReadyToReceive. Event log: "
            + diverter.log.toString(),
        diverter
            .log
            .getLastLoggedEvent()
            .getMessage()
            .contains("msgReadyToReceive from lane for " + part1.getName()));

    lane.msgHereIsPart(part1);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    assertEquals(
        "Diverter should have only 1 message, should not have received another here. Event log: "
            + diverter.log.toString(),
        1,
        diverter.log.size());

    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    // GUI Lane should move the parts on the lane here

    // create a part used for testing
    Part part2 = new Part(PartType.D);

    lane.msgPartReady(part2);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock diverter should have received msgReadyToReceive. Event log: "
            + diverter.log.toString(),
        diverter
            .log
            .getLastLoggedEvent()
            .getMessage()
            .contains("msgReadyToReceive from lane for " + part2.getName()));

    lane.msgHereIsPart(part2);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    assertEquals(
        "Diverter should have only 2 messages, should not have received another here. Event log: "
            + diverter.log.toString(),
        2,
        diverter.log.size());

    lane.msgGuiDoneMovingPart(part1.guiPart);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock nest should have received msgPartReady. Event log: " + nest.log.toString(),
        nest.log.getLastLoggedEvent().getMessage().contains("msgPartReady"));

    lane.msgReadyToReceive();
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock nest should have received msgHereIsPart. Event log: " + nest.log.toString(),
        nest.log.getLastLoggedEvent().getMessage().contains("msgHereIsPart"));

    System.out.println("END OF TEST");
  }
  public void testLaneFull() {
    // WIP

    int scheduleCounter = 0;
    System.out.println("------------------------------\n" + "testLaneFull():");

    Lane lane = new LaneAgent("Lane1");
    GUILane guiLane = new GUILane(1, 2, 3, new GUINest(1, 2, 3));

    MockFeeder feeder = new MockFeeder("Feeder1");
    MockDiverter diverter = new MockDiverter("Diverter1");
    MockNest nest = new MockNest("Nest1");

    lane.setFeederAgent(feeder);
    lane.setDiverterAgent(diverter);
    lane.setNestAgent(nest);
    lane.setGuiLane(guiLane);
    guiLane.setLaneAgent(lane);

    assertEquals(
        "Mock Feeder should have an empty event log before the Lane's scheduler is called. Instead, the Mock Feeder's event log reads: "
            + feeder.log.toString(),
        0,
        feeder.log.size());
    assertEquals(
        "Mock Diverter should have an empty event log before the Lane's scheduler is called. Instead, the Mock Diverter's event log reads: "
            + diverter.log.toString(),
        0,
        diverter.log.size());
    assertEquals(
        "Mock Nest should have an empty event log before the Lane's scheduler is called. Instead, the Mock Nest's event log reads: "
            + nest.log.toString(),
        0,
        nest.log.size());

    for (int pn = 0; pn < 7; pn++) {
      // create a part used for testing
      Part part1 = new Part(PartType.A);

      lane.msgPartReady(part1);
      System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
      lane.pickAndExecuteAnAction();
      assertTrue(
          "Mock diverter should have received msgReadyToReceive. Event log: "
              + diverter.log.toString(),
          diverter
              .log
              .getLastLoggedEvent()
              .getMessage()
              .contains("msgReadyToReceive from lane for " + part1.type));

      lane.msgHereIsPart(part1);
      System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
      lane.pickAndExecuteAnAction();
    }

    lane.msgGuiLaneAlmostFull();
    System.out.println("SCHEDULER CALLED **");
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock feeder should have received msgHoldOn. Event log: " + feeder.log.toString(),
        feeder.log.getLastLoggedEvent().getMessage().contains("msgHoldOn"));

    // create a part used for testing
    Part part2 = new Part(PartType.B);

    lane.msgPartReady(part2);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    // gui lane should move all its parts

    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    // gui lane should move all its parts

    lane.msgGuiLaneNoLongerFull();
    System.out.println("SCHEDULER CALLED ***");
    lane.pickAndExecuteAnAction();
    assertTrue(
        "Mock diverter should have received msgReadyToReceive. Event log: "
            + diverter.log.toString(),
        diverter
            .log
            .getLastLoggedEvent()
            .getMessage()
            .contains("msgReadyToReceive from lane for " + part2.type));

    lane.msgHereIsPart(part2);
    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();

    System.out.println("SCHEDULER CALLED " + ++scheduleCounter);
    lane.pickAndExecuteAnAction();
    // GUI Lane should move the parts on the lane here

    System.out.println("END OF TEST");
  }
Beispiel #4
0
  /** THIS IS THE IMPORTANT PART-- DRAWS ALL THE STATES OF LANE AND UPDATES ITS PARTS */
  @Override
  public void draw(Graphics g) {
    if (state == State.FULL) {}

    if (state == State.PARTIALLYFILLED) {
      g.drawImage(imageL.getImage(), xPos, yPos, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth, yPos, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth * 2, yPos, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth * 3, yPos, width, height, null);
      g.drawImage(imageR.getImage(), xPos + stdWidth * 4, yPos, width, height, null);
      for (int i = 0; i < laneLines.length; i++) {
        Graphics2D g2 = (Graphics2D) g;
        //				g2.setColor(Color.BLACK);
        g2.setColor(new Color(20, 124, 185));
        g2.draw(laneLines[i]);
      }
    }
    if (state == State.EMPTY) {
      g.drawImage(imageL.getImage(), xPos, yPos, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth, yPos, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth * 2, yPos, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth * 3, yPos, width, height, null);
      g.drawImage(imageR.getImage(), xPos + stdWidth * 4, yPos, width, height, null);
      for (int i = 0; i < laneLines.length; i++) {
        Graphics2D g2 = (Graphics2D) g;
        //				g2.setColor(Color.BLACK);
        g2.setColor(new Color(20, 124, 185));
        g2.draw(laneLines[i]);
      }
    }
    if (state == State.LANE_MOVING) {
      g.drawImage(imageL.getImage(), xPos, yPos + shakeY, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth, yPos + shakeY, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth * 2, yPos + shakeY, width, height, null);
      g.drawImage(imageM.getImage(), xPos + stdWidth * 3, yPos + shakeY, width, height, null);
      g.drawImage(imageR.getImage(), xPos + stdWidth * 4, yPos + shakeY, width, height, null);
      for (int i = 0; i < laneLines.length; i++) {
        Graphics2D g2 = (Graphics2D) g;
        //				g2.setColor(Color.BLACK);
        g2.setColor(new Color(20, 124, 185));
        g2.draw(laneLines[i]);
      }
      boolean movedLaneLines = false;
      // boolean shakeLane = false;
      for (int i = 0; i < parts.size(); i++) {
        int placeX = endX + i * 18;
        if (parts.get(i).getX() > placeX) {
          if (parts.get(i).getX() - speed > placeX) parts.get(i).moveX(-speed);
          else {
            // parts.get(i).moveX(placeX - parts.get(i).getX());
            parts.get(i).moveX(-1);
          }

          if (!movedLaneLines) {
            for (int k = 0; k < laneLines.length; k++) {
              Double x = laneLines[k].getX();
              if (x > xPos) {
                x--;
              } else {
                x = (double) xPos + 250;
              }
              laneLines[k].setFrame(x, yPos + 8, 1, height - 16);
            }
            movedLaneLines = true;
          }
          /*if(!shakeLane)
          {
          	shakeCounter++;
          	if(shakeCounter==10)
          	{
          		shakeY=-1;
          	}
          	if(shakeCounter==12)
          	{
          		shakeY=0;
          	}
          	if(shakeCounter>=14)
          	{
          		shakeY=1;
          		shakeCounter = 0;
          	}
          	shakeLane = true;
          }*/

        }

        if (parts.get(i).getY() > endY) {
          //					if (parts.get(i).getY() + speed > endY)
          //						parts.get(i).moveY(speed);
          //					else
          //					{
          // parts.get(i).moveX(endY - parts.get(i).getY());
          parts.get(i).moveX(1);
          // }
        }
        if (parts.get(i).getY() < endY) {
          //					if (parts.get(i).getY() - speed < endY)
          //						parts.get(i).moveY(-speed);
          //					else
          //					{
          // parts.get(i).moveY(endY + parts.get(i).getY());
          parts.get(i).moveY(-1);
          // }
        }
        if (parts.get(i).getX() == endX && parts.get(i).getY() == endY) {
          // state = State.PARTIALLYFILLED;
          // THIS WILL CHANGE BASED ON AGENT INTERACTIONS

          if (nest.getState() != NestState.ADDING_PART
              && nest.getState() != NestState.FULL
              && nest.fullState == false) {
            if (partsLane.get(i).toldAgentItsDone == false) {
              myAgent.msgGuiDoneMovingPart(parts.get(i));
              partsLane.get(i).toldAgentItsDone = true;
            }
            nest.givePart(parts.get(i), this);

            parts.remove(i);
            partsLane.remove(i);
          }
        }
      }
    }
  }