Esempio n. 1
0
 public Build(String path) throws IOException {
   hasMainWindow = false;
   if (path == null) {
     mainFilename = null;
     name = "Untitled";
     folder = new File("~");
     BuildElement code = new BuildCode(null, null);
     openedElement = code;
     code.setModified(true);
     elements.add(code);
   } else {
     File mainFile = new File(path);
     mainFilename = mainFile.getName();
     String suffix = "";
     int lastIdx = mainFilename.lastIndexOf('.');
     if (lastIdx > 0) {
       suffix = mainFilename.substring(lastIdx + 1);
       name = mainFilename.substring(0, lastIdx);
     } else {
       name = mainFilename;
     }
     String parentPath = new File(path).getParent();
     if (parentPath == null) {
       parentPath = ".";
     }
     folder = new File(parentPath);
     if ("stl".equalsIgnoreCase(suffix)
         || "obj".equalsIgnoreCase(suffix)
         || "dae".equalsIgnoreCase(suffix)) {
       modelFile = mainFile;
     }
     loadCode();
     loadModel();
     if (("gcode".equalsIgnoreCase(suffix) || "ngc".equalsIgnoreCase(suffix))
         && getCode() != null) {
       openedElement = getCode();
     } else {
       openedElement = getModel();
     }
   }
 }
Esempio n. 2
0
  /**
   * path is location of the main .gcode file, because this is also simplest to use when opening the
   * file from the finder/explorer.
   */
  public Build(MainWindow editor, String path) throws IOException {
    hasMainWindow = true;
    this.editor = editor;
    if (path == null) {
      mainFilename = null;
      name = "Untitled";
      folder = new File("~");
      BuildElement code = new BuildCode(null, null);
      openedElement = code;
      code.setModified(true);
      elements.add(code);
    } else {

      File mainFile = new File(path);
      mainFilename = mainFile.getName();
      String suffix = "";
      int lastIdx = mainFilename.lastIndexOf('.');
      if (lastIdx > 0) {
        suffix = mainFilename.substring(lastIdx + 1);
        name = mainFilename.substring(0, lastIdx);
      } else {
        name = mainFilename;
      }

      // protect against loading files that may have caused a crash last time
      File crashCheck = new File(name + ".crash");
      if (crashCheck.exists()) {
        crashCheck.delete();
        int op =
            JOptionPane.showConfirmDialog(
                null,
                "It looks as though ReplicatorG may have crashed\n"
                    + "last time it tried to load this file.\nRe-loading the same file could cause another crash,\n"
                    + "would you like to load this file anyway?",
                "Remnants of a crash detected!",
                JOptionPane.OK_OPTION,
                JOptionPane.WARNING_MESSAGE);
        if (op != 0) return;
      }
      crashCheck.createNewFile();

      String parentPath = new File(path).getParent();
      if (parentPath == null) {
        parentPath = ".";
      }
      folder = new File(parentPath);
      if ("stl".equalsIgnoreCase(suffix)
          || "obj".equalsIgnoreCase(suffix)
          || "dae".equalsIgnoreCase(suffix)) {
        modelFile = mainFile;
      }
      loadCode();
      loadModel();
      if (("gcode".equalsIgnoreCase(suffix) || "ngc".equalsIgnoreCase(suffix))
          && getCode() != null) {
        openedElement = getCode();
      } else {
        openedElement = getModel();
      }

      crashCheck.delete();
    }
  }