Example #1
0
  public void popupActionPopupReleaseFinished() {
    if (actionStatus == ActionStatus.passGlass) {
      for (MyGlass g : glasses) {
        if (g.status == GlassStatus.WaitingForPass) {

          print("popup" + myIndex + "popup released the glass");
          glasses.remove(g);
          animationStatus = AnimationStatus.Nothing;
          actionStatus = ActionStatus.Nothing;
          nextCF.msgHereIsGlass(g.glass);
          return;
        }
      }
    } else if (actionStatus == ActionStatus.getGlassFromMachine) {
      for (MyGlass g : glasses) {
        if (g.status == GlassStatus.Ready) {
          print("popup" + myIndex + "popup released the glass");
          glasses.remove(g);
          animationStatus = AnimationStatus.Nothing;
          actionStatus = ActionStatus.Nothing;
          robots.get(g.robotIndex).status = RobotStatus.Empty;
          print("" + myIndex + "machine " + g.getRobotIndex() + " is set to empty!~~~~~");
          nextCF.msgHereIsGlass(g.glass);
          conveyor.msgPopupAvailable();
          return;
        }
      }
    }
  }
Example #2
0
 public void passGlass(MyGlass g) {
   Integer[] popupArgs = new Integer[1];
   popupArgs[0] = myIndex;
   Integer[] conveyorArgs = new Integer[1];
   conveyorArgs[0] = conveyor.getMyIndex();
   nextFamilyAvailable = false;
   transducer.fireEvent(TChannel.POPUP, TEvent.POPUP_DO_MOVE_DOWN, popupArgs);
   animationStatus = AnimationStatus.PopupMovingDown;
   //		try {
   //			animationSem.acquire();
   //		} catch (InterruptedException e) {
   //			e.printStackTrace();
   //		} // released by POPUP_GUI_MOVED_DOWN
   //
   //		transducer.fireEvent(TChannel.CONVEYOR,TEvent.CONVEYOR_DO_START,conveyorArgs);
   //		try {
   //			animationSem.acquire();
   //		} catch (InterruptedException e) {
   //			e.printStackTrace();
   //		} // released by POPUP_GUI_LOAD_FINISHED
   //		transducer.fireEvent(TChannel.POPUP,TEvent.POPUP_RELEASE_GLASS,popupArgs);
   //		try {
   //			animationSem.acquire();
   //		} catch (InterruptedException e) {
   //			e.printStackTrace();
   //		} // released by POPUP_GUI_RELEASE_FINISHED
   //		nextCF.msgHereIsGlass(g.glass);
   //		glasses.remove(g);
   stateChanged();
   // move down, take the glass and pass it to the next family when the family is ready
 }
Example #3
0
 public void fixRobot(int i) {
   for (MyGlass g : glasses) {
     if (g.robotIndex == i && g.status == GlassStatus.Handling) {
       glasses.remove(g);
       robots.get(i).status = RobotStatus.Empty;
       conveyor.msgPopupAvailable();
       stateChanged();
       break;
     }
   }
 }
Example #4
0
  public void popupActionPopupMovedDown() {

    if (actionStatus == ActionStatus.deliverGlass || actionStatus == ActionStatus.passGlass) {
      Integer[] conveyorArgs = new Integer[1];
      conveyorArgs[0] = conveyor.getMyIndex();
      transducer.fireEvent(TChannel.CONVEYOR, TEvent.CONVEYOR_DO_START, conveyorArgs);
      animationStatus = AnimationStatus.StartingConveyor;
      stateChanged();
    } else if (actionStatus == ActionStatus.getGlassFromMachine) {
      Integer[] popupArgs = new Integer[1];
      popupArgs[0] = myIndex;
      transducer.fireEvent(TChannel.POPUP, TEvent.POPUP_RELEASE_GLASS, popupArgs);
      animationStatus = AnimationStatus.PopupReleasingGlass;
      stateChanged();
    }
  }
Example #5
0
  public void deliverGlass(MyGlass g) {
    System.out.println("deliver the glass is called:" + myIndex + " " + g.getRobotIndex());
    g.status = GlassStatus.Delivering;
    Integer[] popupArgs = new Integer[1];
    popupArgs[0] = myIndex;
    Integer[] conveyorArgs = new Integer[1];
    conveyorArgs[0] = conveyor.getMyIndex();
    Integer[] robotArgs = new Integer[1];
    robotArgs[0] = g.robotIndex;
    // move down, take glass, take it to the next available machine
    transducer.fireEvent(TChannel.POPUP, TEvent.POPUP_DO_MOVE_DOWN, popupArgs);
    animationStatus = AnimationStatus.PopupMovingDown;
    //		try {
    //			animationSem.acquire();
    //		} catch (InterruptedException e) {
    //			e.printStackTrace();
    //		} // released by POPUP_GUI_MOVED_DOWN
    //		print("popup"+myIndex+" moved down the pop up");
    //		transducer.fireEvent(TChannel.CONVEYOR,TEvent.CONVEYOR_DO_START,conveyorArgs);
    //		try {
    //			animationSem.acquire();
    //		} catch (InterruptedException e) {
    //			e.printStackTrace();
    //		} // released by POPUP_GUI_LOAD_FINISHED
    //		print("popup"+myIndex+"popup finished loading");
    //		transducer.fireEvent(TChannel.POPUP,TEvent.POPUP_DO_MOVE_UP,popupArgs);

    //		print("popup"+myIndex+"popup moved up");
    //		transducer.fireEvent(myChannel, TEvent.WORKSTATION_DO_LOAD_GLASS,robotArgs);
    //		try {
    //			animationSem.acquire();
    //		} catch (InterruptedException e) {
    //			e.printStackTrace();
    //		} // released by WORKSTATION_LOAD_FINISHED
    //		//TODO
    //		print("workStation"+robotArgs[0]+"load glass finished");
    //		transducer.fireEvent(myChannel, TEvent.WORKSTATION_DO_ACTION,robotArgs);

    // robots.get(g.robotIndex).robot.msgHereIsGlass(g.glass);

    stateChanged();
  }
Example #6
0
  public void eventFired(TChannel channel, TEvent event, Object[] args) {

    if (channel == TChannel.POPUP) {

      if (args[0] == myIndex) {
        if (event == TEvent.POPUP_GUI_MOVED_DOWN) {
          if (!popupJam) {
            if (animationStatus == AnimationStatus.PopupMovingDown) {
              if (actionStatus != ActionStatus.Nothing) {
                animationStatus = AnimationStatus.PopupMovedDown;
                print("POPUP_GUI_MOVED_DOWN is finished");
                stateChanged();
              } else {
                System.err.println(
                    "POPUP_GUI_MOVED_DOWN is released" + animationStatus + " " + actionStatus);
              }
            }
          } else {
            System.err.println("got message when jamming " + event);
          }

        } else if (event == TEvent.POPUP_GUI_LOAD_FINISHED) {
          if (!popupJam) {
            if (animationStatus == AnimationStatus.StartingConveyor
                && (actionStatus != ActionStatus.Nothing)) {
              animationStatus = AnimationStatus.PopUpGuiLoadFinished;
              print("POPUP_GUI_LOAD_FINISHED is released");
              stateChanged();
            } else if (animationStatus == AnimationStatus.WorkStationReleasingGlass
                && actionStatus == ActionStatus.getGlassFromMachine) {
              animationStatus = AnimationStatus.PopUpGuiLoadFinished;
              print("POPUP_GUI_LOAD_FINISHED is released");
              stateChanged();
            } else {
              System.err.println(
                  "POPUP_GUI_LOAD_FINISHED is released" + animationStatus + " " + actionStatus);
            }

          } else {
            System.err.println("got error when jamming " + event);
          }

        } else if (event == TEvent.POPUP_GUI_MOVED_UP) {
          if (!popupJam) {
            if (animationStatus == AnimationStatus.PopUpMovingUp
                && actionStatus == ActionStatus.deliverGlass) {
              animationStatus = AnimationStatus.PopUpMovedUp;
              stateChanged();
              print("POPUP_GUI_MOVED_UP is released" + animationStatus + " " + actionStatus);
            } else if (animationStatus == AnimationStatus.PopUpMovingUp
                && actionStatus == ActionStatus.getGlassFromMachine) {
              animationStatus = AnimationStatus.PopUpMovedUp;
              stateChanged();
              print("POPUP_GUI_MOVED_UP is released");
            } else {
              System.err.println(
                  "POPUP_GUI_MOVED_UP is released" + animationStatus + " " + actionStatus);
            }

          } else {
            System.err.println("got message when jamming " + event);
          }

        } else if (event == TEvent.POPUP_GUI_RELEASE_FINISHED) {
          if (!popupJam) {
            if (animationStatus == AnimationStatus.PopupReleasingGlass) {
              if (actionStatus == ActionStatus.getGlassFromMachine
                  || actionStatus == ActionStatus.passGlass) {
                animationStatus = AnimationStatus.PopupReleaseFinished;
                stateChanged();
                print("POPUP_GUI_RELEASE_FINISHED is released");
              } else {
                System.err.println(
                    "POPUP_GUI_RELEASE_FINISHED is released"
                        + animationStatus
                        + " "
                        + actionStatus);
              }
            } else {
              System.err.println(
                  "POPUP_GUI_RELEASE_FINISHED is released" + animationStatus + " " + actionStatus);
            }
          } else {
            System.err.println("got message when jamming " + event);
          }
        } else if (event == TEvent.POPUP_JAM) {
          if (!popupJam) {
            cp.tracePanel.print(
                "Popup is jammed: Channel: " + myChannel + " conveyor is stopped.\n", this);
            popupJam = true;
            conveyor.msgIamJammed();
          }
        } else if (event == TEvent.POPUP_UNJAM) {
          if (popupJam) {
            cp.tracePanel.print(
                "Popup 's jamming issue is fixed: Channel: "
                    + myChannel
                    + " conveyor is resumed.\n",
                this);
            popupJam = false;
            conveyor.msgIamUnJammed();
          }
        }
      }
    } else if (channel == myChannel) {
      if (event == TEvent.WORKSTATION_LOAD_FINISHED) {
        if (!popupJam) {
          if (actionStatus == ActionStatus.deliverGlass
              && animationStatus == AnimationStatus.WorkStationLoadingGlass) {
            animationStatus = AnimationStatus.WorkStationLoadFinished;
            print("WORKSTATION_LOAD_FINISHED is released");
            stateChanged();
          } else {
            System.err.println(
                "WORKSTATION_LOAD_FINISHED is released" + animationStatus + " " + actionStatus);
          }
        } else {
          System.err.println("got message when jamming " + event);
        }

      } else if (event
          == TEvent
              .WORKSTATION_GUI_ACTION_FINISHED) { // we do not have machine agent so we use this
                                                  // eventFired
        Integer tempIndex = (Integer) args[0];
        int intIndex = tempIndex.intValue();
        robots.get(intIndex).startTime = 0;
        msgGlassReady(tempIndex);
      } else if (event == TEvent.ROMOVE_GLASS_OFFLINE) {

        int tempIndex = ((Integer) (args[0])).intValue();
        robots.get(tempIndex).status = RobotStatus.Fixing;
        stateChanged();
      } else if (event == TEvent.WORKSTATION_FIXED) {
        int tempIndex = ((Integer) (args[0])).intValue();
        cp.getTracePanel()
            .print(
                "Workstation is fixed : machine channel: "
                    + myChannel
                    + " index: "
                    + tempIndex
                    + "\n",
                this);
        robots.get(tempIndex).status = RobotStatus.Fixing;
        stateChanged();
      } else if (event == TEvent.WORKSTATION_OFFLINE_CHANGE_SPEED) {
        if (channel == myChannel) {
          int speedup = ((Integer) (args[0])).intValue();
          speedDown = 10 / speedup;
        }

      } else if (event == TEvent.WORKSTATION_DISABLE_OFFLINE) {
        int machineIndex = ((Integer) (args[0])).intValue();
        robots.get(machineIndex).status = RobotStatus.Working;
        stateChanged();

      } else if (event == TEvent.WORKSTATION_ENABLE_OFFLINE) {
        int machineIndex = ((Integer) (args[0])).intValue();
        robots.get(machineIndex).status = RobotStatus.Empty;
        stateChanged();
      }
    }
  }