示例#1
0
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    Project proj = menubar.getProject();
    if (src == newi) {
      ProjectActions.doNew(proj);
    } else if (src == merge) {
      ProjectActions.doMerge(proj == null ? null : proj.getFrame().getCanvas(), proj);
    } else if (src == open) {
      ProjectActions.doOpen(proj == null ? null : proj.getFrame().getCanvas(), proj);
    } else if (src == close) {
      int result = 0;
      Frame frame = proj.getFrame();
      if (proj.isFileDirty()) {
        /* Must use hardcoded strings here, because the string management is rotten */
        String message =
            "What should happen to your unsaved changes to " + proj.getLogisimFile().getName();
        String[] options = {"Save", "Discard", "Cancel"};
        result =
            JOptionPane.showOptionDialog(
                JOptionPane.getFrameForComponent(this),
                message,
                "Confirm Close",
                0,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]);

        if (result == 0) {
          ProjectActions.doSave(proj);
        }
      }

      /* If "cancel" pressed do nothing, otherwise dispose the window, opening one if this was the last opened window */
      if (result != 2) {
        // Get the list of open projects
        List<Project> pl = Projects.getOpenProjects();
        if (pl.size() == 1) {
          // Since we have a single window open, before closing the
          // current
          // project open a new empty one
          ProjectActions.doNew(proj);
        }

        // Close the current project
        frame.dispose();
        OptionsFrame f = proj.getOptionsFrame(false);
        if (f != null) f.dispose();
      }
    } else if (src == save) {
      ProjectActions.doSave(proj);
    } else if (src == saveAs) {
      ProjectActions.doSaveAs(proj);
    } else if (src == prefs) {
      PreferencesFrame.showPreferences();
    } else if (src == quit) {
      ProjectActions.doQuit();
    }
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  private void GetSizeInformationDialog(BoardDialog parent) {
    int NrOfDevicePins = IOComponentTypes.GetNrOfFPGAPins(MyType);
    int min = 1;
    int max = 1;
    String text = "null";

    switch (MyType) {
      case DIPSwitch:
        min = DipSwitch.MIN_SWITCH;
        max = DipSwitch.MAX_SWITCH;
        text = "switch";
        break;
      case PortIO:
        min = PortIO.MIN_IO;
        max = PortIO.MAX_IO;
        text = "pins";
        break;
      default:
        break;
    }

    final JDialog selWindow = new JDialog(parent.GetPanel(), MyType + " number of " + text);
    ActionListener actionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("next")) {
              MyType.setNbSwitch(
                  Integer.valueOf(
                      ((JComboBox) (selWindow.getContentPane().getComponents()[1]))
                          .getSelectedItem()
                          .toString()));
              // setNrOfPins(Integer.valueOf(((JComboBox)(selWindow.getContentPane().getComponents()[1])).getSelectedItem().toString()));
              selWindow.dispose();
            }
            selWindow.setVisible(false);
          }
        };

    JComboBox size = new JComboBox<>();
    for (int i = min; i <= max; i++) {
      size.addItem(i);
    }
    size.setSelectedItem(NrOfDevicePins);
    GridBagLayout dialogLayout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    selWindow.setLayout(dialogLayout);
    c.fill = GridBagConstraints.HORIZONTAL;

    JLabel sizeText = new JLabel("Specify number of " + text + ": ");
    c.gridx = 0;
    c.gridy = 0;
    selWindow.add(sizeText, c);

    c.gridx = 1;
    selWindow.add(size, c);

    JButton nextButton = new JButton("Next");
    nextButton.setActionCommand("next");
    nextButton.addActionListener(actionListener);
    c.gridy++;
    selWindow.add(nextButton, c);
    selWindow.pack();
    selWindow.setLocation(Projects.getCenteredLoc(selWindow.getWidth(), selWindow.getHeight()));
    // PointerInfo mouseloc = MouseInfo.getPointerInfo();
    // Point mlocation = mouseloc.getLocation();
    // selWindow.setLocation(mlocation.x, mlocation.y);
    selWindow.setModal(true);
    selWindow.setResizable(false);
    selWindow.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    selWindow.setAlwaysOnTop(true);
    selWindow.setVisible(true);
  }
  private void GetSimpleInformationDialog(BoardDialog parent) {
    int NrOfDevicePins = IOComponentTypes.GetNrOfFPGAPins(MyType);
    final JDialog selWindow = new JDialog(parent.GetPanel(), MyType + " properties");
    JComboBox<String> DriveInput = new JComboBox<>(DriveStrength.Behavior_strings);
    JComboBox<String> PullInput = new JComboBox<>(PullBehaviors.Behavior_strings);
    JComboBox<String> ActiveInput = new JComboBox<>(PinActivity.Behavior_strings);
    ActionListener actionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("cancel")) {
              MyType = IOComponentTypes.Unknown;
              abort = true;
            }
            selWindow.setVisible(false);
          }
        };
    GridBagLayout dialogLayout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    selWindow.setLayout(dialogLayout);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridy = -1;
    ArrayList<JTextField> LocInputs = new ArrayList<JTextField>();
    ArrayList<String> PinLabels;
    switch (MyType) {
      case SevenSegment:
        PinLabels = SevenSegment.GetLabels();
        break;
      case RGBLED:
        PinLabels = RGBLed.GetLabels();
        break;
      case DIPSwitch:
        PinLabels = DipSwitch.GetLabels(NrOfDevicePins);
        break;
      case PortIO:
        PinLabels = PortIO.GetLabels(NrOfDevicePins);
        break;
      case LocalBus:
        PinLabels = ReptarLocalBus.GetLabels();
        break;
      default:
        PinLabels = new ArrayList<String>();
        if (NrOfDevicePins == 1) {
          PinLabels.add("FPGA pin");
        } else {
          for (int i = 0; i < NrOfDevicePins; i++) {
            PinLabels.add("pin " + i);
          }
        }
    }
    int offset = 0;
    int oldY = c.gridy;
    int maxY = -1;
    for (int i = 0; i < NrOfDevicePins; i++) {
      if (i % 32 == 0) {
        offset = (i / 32) * 2;
        c.gridy = oldY;
      }
      JLabel LocText = new JLabel("Specify " + PinLabels.get(i) + " location:");
      c.gridx = 0 + offset;
      c.gridy++;
      selWindow.add(LocText, c);
      JTextField txt = new JTextField(6);
      LocInputs.add(txt);
      c.gridx = 1 + offset;
      selWindow.add(LocInputs.get(i), c);
      maxY = c.gridy > maxY ? c.gridy : maxY;
    }
    c.gridy = maxY;

    JLabel StandardText = new JLabel("Specify FPGA pin standard:");
    c.gridy++;
    c.gridx = 0;
    selWindow.add(StandardText, c);
    JComboBox<String> StandardInput = new JComboBox<>(IoStandards.Behavior_strings);
    StandardInput.setSelectedIndex(parent.GetDefaultStandard());
    c.gridx = 1;
    selWindow.add(StandardInput, c);

    if (IOComponentTypes.OutputComponentSet.contains(MyType)) {
      JLabel DriveText = new JLabel("Specify FPGA pin drive strength:");
      c.gridy++;
      c.gridx = 0;
      selWindow.add(DriveText, c);
      DriveInput.setSelectedIndex(parent.GetDefaultDriveStrength());
      c.gridx = 1;
      selWindow.add(DriveInput, c);
    }

    if (IOComponentTypes.InputComponentSet.contains(MyType)) {
      JLabel PullText = new JLabel("Specify FPGA pin pull behavior:");
      c.gridy++;
      c.gridx = 0;
      selWindow.add(PullText, c);
      PullInput.setSelectedIndex(parent.GetDefaultPullSelection());
      c.gridx = 1;
      selWindow.add(PullInput, c);
    }

    if (!IOComponentTypes.InOutComponentSet.contains(MyType)) {
      JLabel ActiveText = new JLabel("Specify " + MyType + " activity:");
      c.gridy++;
      c.gridx = 0;
      selWindow.add(ActiveText, c);
      ActiveInput.setSelectedIndex(parent.GetDefaultActivity());
      c.gridx = 1;
      selWindow.add(ActiveInput, c);
    }

    JButton OkayButton = new JButton("Done and Store");
    OkayButton.setActionCommand("done");
    OkayButton.addActionListener(actionListener);
    c.gridx = 0;
    c.gridy++;
    selWindow.add(OkayButton, c);

    JButton CancelButton = new JButton("Cancel");
    CancelButton.setActionCommand("cancel");
    CancelButton.addActionListener(actionListener);
    c.gridx = 1;
    selWindow.add(CancelButton, c);
    selWindow.pack();
    selWindow.setLocation(Projects.getCenteredLoc(selWindow.getWidth(), selWindow.getHeight()));
    // PointerInfo mouseloc = MouseInfo.getPointerInfo();
    // Point mlocation = mouseloc.getLocation();
    // selWindow.setLocation(mlocation.x, mlocation.y);
    selWindow.setModal(true);
    selWindow.setResizable(false);
    selWindow.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    selWindow.setAlwaysOnTop(true);
    abort = false;
    while (!abort) {
      selWindow.setVisible(true);
      if (!abort) {
        boolean correct = true;
        for (int i = 0; i < NrOfDevicePins; i++) {
          if (LocInputs.get(i).getText().isEmpty()) {
            correct = false;
            showDialogNotification(
                selWindow,
                "Error",
                "<html>You have to specify a location for " + PinLabels.get(i) + "!</html>");
            continue;
          }
        }
        if (correct) {
          parent.SetDefaultStandard(StandardInput.getSelectedIndex());
          NrOfPins = NrOfDevicePins;
          for (int i = 0; i < NrOfDevicePins; i++) {
            MyPinLocations.put(i, LocInputs.get(i).getText());
          }
          MyIOStandard = IoStandards.getId(StandardInput.getSelectedItem().toString());
          if (IOComponentTypes.OutputComponentSet.contains(MyType)) {
            parent.SetDefaultDriveStrength(DriveInput.getSelectedIndex());
            MyDriveStrength = DriveStrength.getId(DriveInput.getSelectedItem().toString());
          }
          if (IOComponentTypes.InputComponentSet.contains(MyType)) {
            parent.SetDefaultPullSelection(PullInput.getSelectedIndex());
            MyPullBehavior = PullBehaviors.getId(PullInput.getSelectedItem().toString());
          }
          if (!IOComponentTypes.InOutComponentSet.contains(MyType)) {
            parent.SetDefaultActivity(ActiveInput.getSelectedIndex());
            MyActivityLevel = PinActivity.getId(ActiveInput.getSelectedItem().toString());
          }
          abort = true;
        }
      }
    }
    selWindow.dispose();
  }
  public static boolean Download(
      Settings MySettings,
      String scriptPath,
      String ProjectPath,
      String SandboxPath,
      FPGAReport MyReporter) {
    VendorSoftware alteraVendor = Settings.vendors.get(FPGAClass.VendorAltera);
    boolean SofFileExists =
        new File(SandboxPath + ToplevelHDLGeneratorFactory.FPGAToplevelName + ".sof").exists();
    GridBagConstraints gbc = new GridBagConstraints();
    JFrame panel = new JFrame("Altera Downloading");
    panel.setResizable(false);
    panel.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    GridBagLayout thisLayout = new GridBagLayout();
    panel.setLayout(thisLayout);
    // PointerInfo mouseloc = MouseInfo.getPointerInfo();
    // Point mlocation = mouseloc.getLocation();
    // panel.setLocation(mlocation.x, mlocation.y);
    JLabel LocText =
        new JLabel("Generating FPGA files and performing download; this may take a while");
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(LocText, gbc);
    JProgressBar progres = new JProgressBar(0, 5);
    progres.setValue(1);
    progres.setStringPainted(true);
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(progres, gbc);
    panel.pack();
    panel.setLocation(Projects.getCenteredLoc(panel.getWidth(), panel.getHeight() * 4));
    panel.setVisible(true);
    Rectangle labelRect = LocText.getBounds();
    labelRect.x = 0;
    labelRect.y = 0;
    LocText.paintImmediately(labelRect);
    List<String> command = new ArrayList<String>();
    if (!SofFileExists) {
      try {
        LocText.setText("Creating Project");
        labelRect = LocText.getBounds();
        labelRect.x = 0;
        labelRect.y = 0;
        LocText.paintImmediately(labelRect);
        command.add(alteraVendor.getBinaryPath(0));
        command.add("-t");
        command.add(scriptPath.replace(ProjectPath, ".." + File.separator) + "AlteraDownload.tcl");
        ProcessBuilder Altera1 = new ProcessBuilder(command);
        Altera1.directory(new File(SandboxPath));
        final Process CreateProject = Altera1.start();
        InputStream is = CreateProject.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        MyReporter.ClsScr();
        while ((line = br.readLine()) != null) {
          MyReporter.print(line);
        }
        CreateProject.waitFor();
        if (CreateProject.exitValue() != 0) {
          MyReporter.AddFatalError("Failed to Create a Quartus Project, cannot download");
          panel.dispose();
          return false;
        }
      } catch (IOException e) {
        MyReporter.AddFatalError("Internal Error during Altera download");
        panel.dispose();
        return false;
      } catch (InterruptedException e) {
        MyReporter.AddFatalError("Internal Error during Altera download");
        panel.dispose();
        return false;
      }
    }
    progres.setValue(2);
    Rectangle ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    command.clear();
    if (!SofFileExists) {
      try {
        LocText.setText("Optimize Project");
        labelRect = LocText.getBounds();
        labelRect.x = 0;
        labelRect.y = 0;
        LocText.paintImmediately(labelRect);
        command.add(alteraVendor.getBinaryPath(2));
        command.add(ToplevelHDLGeneratorFactory.FPGAToplevelName);
        command.add("--optimize=area");
        ProcessBuilder Altera1 = new ProcessBuilder(command);
        Altera1.directory(new File(SandboxPath));
        final Process CreateProject = Altera1.start();
        InputStream is = CreateProject.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        MyReporter.ClsScr();
        while ((line = br.readLine()) != null) {
          MyReporter.print(line);
        }
        CreateProject.waitFor();
        if (CreateProject.exitValue() != 0) {
          MyReporter.AddFatalError("Failed to optimize (AREA) Project, cannot download");
          panel.dispose();
          return false;
        }
      } catch (IOException e) {
        MyReporter.AddFatalError("Internal Error during Altera download");
        panel.dispose();
        return false;
      } catch (InterruptedException e) {
        MyReporter.AddFatalError("Internal Error during Altera download");
        panel.dispose();
        return false;
      }
    }
    LocText.setText("Synthesizing and creating configuration file (this may take a while)");
    labelRect = LocText.getBounds();
    labelRect.x = 0;
    labelRect.y = 0;
    LocText.paintImmediately(labelRect);
    progres.setValue(3);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    if (!SofFileExists) {
      try {
        command.clear();
        command.add(alteraVendor.getBinaryPath(0));
        command.add("--flow");
        command.add("compile");
        command.add(ToplevelHDLGeneratorFactory.FPGAToplevelName);
        ProcessBuilder Altera1 = new ProcessBuilder(command);
        Altera1.directory(new File(SandboxPath));
        final Process CreateProject = Altera1.start();
        InputStream is = CreateProject.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        MyReporter.ClsScr();
        while ((line = br.readLine()) != null) {
          MyReporter.print(line);
        }
        CreateProject.waitFor();
        if (CreateProject.exitValue() != 0) {
          MyReporter.AddFatalError(
              "Failed to synthesize design and to create the configuration files, cannot download");
          panel.dispose();
          return false;
        }
      } catch (IOException e) {
        MyReporter.AddFatalError("Internal Error during Altera download");
        panel.dispose();
        return false;
      } catch (InterruptedException e) {
        MyReporter.AddFatalError("Internal Error during Altera download");
        panel.dispose();
        return false;
      }
    }
    LocText.setText("Downloading");
    Object[] options = {"Yes, download", "No, abort"};
    if (JOptionPane.showOptionDialog(
            progres,
            "Verify that your board is connected and you are ready to download.",
            "Ready to download ?",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING_MESSAGE,
            null,
            options,
            options[0])
        != JOptionPane.YES_OPTION) {
      MyReporter.AddWarning("Download aborted.");
      panel.dispose();
      return false;
    }

    labelRect = LocText.getBounds();
    labelRect.x = 0;
    labelRect.y = 0;
    LocText.paintImmediately(labelRect);
    progres.setValue(4);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    try {
      command.clear();
      command.add(alteraVendor.getBinaryPath(1));
      command.add("-c");
      command.add("usb-blaster");
      command.add("-m");
      command.add("jtag");
      command.add("-o");
      // if there is no .sof generated, try with the .pof
      if (new File(SandboxPath + ToplevelHDLGeneratorFactory.FPGAToplevelName + ".sof").exists()) {
        command.add("P;" + ToplevelHDLGeneratorFactory.FPGAToplevelName + ".sof");
      } else {
        command.add("P;" + ToplevelHDLGeneratorFactory.FPGAToplevelName + ".pof");
      }
      MyReporter.AddInfo(command.toString());
      ProcessBuilder Altera1 = new ProcessBuilder(command);
      Altera1.directory(new File(SandboxPath));
      final Process CreateProject = Altera1.start();
      InputStream is = CreateProject.getInputStream();
      InputStreamReader isr = new InputStreamReader(is);
      BufferedReader br = new BufferedReader(isr);
      String line;
      MyReporter.ClsScr();
      while ((line = br.readLine()) != null) {
        MyReporter.print(line);
      }
      CreateProject.waitFor();
      if (CreateProject.exitValue() != 0) {
        MyReporter.AddFatalError("Failed to Download design; did you connect the board?");
        panel.dispose();
        return false;
      }
    } catch (IOException e) {
      MyReporter.AddFatalError("Internal Error during Altera download");
      panel.dispose();
      return false;
    } catch (InterruptedException e) {
      MyReporter.AddFatalError("Internal Error during Altera download");
      panel.dispose();
      return false;
    }

    panel.dispose();
    return true;
  }