Search in sources :

Example 1 with LoadFailedException

use of com.cburch.logisim.file.LoadFailedException in project logisim-evolution by reds-heig.

the class ProjectActions method doMerge.

public static void doMerge(Component parent, Project baseProject) {
    JFileChooser chooser;
    LogisimFile mergelib;
    Loader loader = null;
    if (baseProject != null) {
        Loader oldLoader = baseProject.getLogisimFile().getLoader();
        chooser = oldLoader.createChooser();
        if (oldLoader.getMainFile() != null) {
            chooser.setSelectedFile(oldLoader.getMainFile());
        }
    } else {
        chooser = JFileChoosers.create();
    }
    chooser.setFileFilter(Loader.LOGISIM_FILTER);
    chooser.setDialogTitle(Strings.get("FileMergeItem"));
    int returnVal = chooser.showOpenDialog(parent);
    if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
    File selected = chooser.getSelectedFile();
    loader = new Loader(baseProject == null ? parent : baseProject.getFrame());
    try {
        mergelib = loader.openLogisimFile(selected);
        if (mergelib == null)
            return;
    } catch (LoadFailedException ex) {
        if (!ex.isShown()) {
            JOptionPane.showMessageDialog(parent, StringUtil.format(Strings.get("fileMergeError"), ex.toString()), Strings.get("FileMergeErrorItem"), JOptionPane.ERROR_MESSAGE);
        }
        return;
    }
    updatecircs(mergelib, baseProject);
    baseProject.doAction(LogisimFileActions.MergeFile(mergelib, baseProject.getLogisimFile()));
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) JFileChooser(javax.swing.JFileChooser) Loader(com.cburch.logisim.file.Loader) LogisimFile(com.cburch.logisim.file.LogisimFile) File(java.io.File) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 2 with LoadFailedException

use of com.cburch.logisim.file.LoadFailedException in project logisim-evolution by reds-heig.

the class ProjectActions method doNew.

public static Project doNew(SplashScreen monitor, boolean isStartupScreen) {
    if (monitor != null)
        monitor.setProgress(SplashScreen.FILE_CREATE);
    Loader loader = new Loader(monitor);
    InputStream templReader = AppPreferences.getTemplate().createStream();
    LogisimFile file = null;
    try {
        file = loader.openLogisimFile(templReader);
    } catch (IOException ex) {
        displayException(monitor, ex);
    } catch (LoadFailedException ex) {
        displayException(monitor, ex);
    } finally {
        try {
            templReader.close();
        } catch (IOException e) {
        }
    }
    if (file == null)
        file = createEmptyFile(loader, null);
    return completeProject(monitor, loader, file, isStartupScreen);
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) InputStream(java.io.InputStream) Loader(com.cburch.logisim.file.Loader) IOException(java.io.IOException) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 3 with LoadFailedException

use of com.cburch.logisim.file.LoadFailedException in project logisim-evolution by reds-heig.

the class Startup method run.

public void run() {
    if (isTty) {
        try {
            TtyInterface.run(this);
            return;
        } catch (Exception t) {
            t.printStackTrace();
            System.exit(-1);
            return;
        }
    }
    // I loaded a large file.)
    if (showSplash) {
        try {
            monitor = new SplashScreen();
            monitor.setVisible(true);
        } catch (Exception t) {
            monitor = null;
            showSplash = false;
        }
    }
    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.COMPONENT_EVENT_MASK | AWTEvent.CONTAINER_EVENT_MASK);
    // taken is shown separately in the progress bar.
    if (showSplash) {
        monitor.setProgress(SplashScreen.LIBRARIES);
    }
    Loader templLoader = new Loader(monitor);
    int count = templLoader.getBuiltin().getLibrary("Base").getTools().size() + templLoader.getBuiltin().getLibrary("Gates").getTools().size();
    if (count < 0) {
        // this will never happen, but the optimizer doesn't know that...
        // OK
        logger.error("FATAL ERROR - no components");
        System.exit(-1);
    }
    // load in template
    loadTemplate(templLoader, templFile, templEmpty);
    // interface initialization
    if (showSplash) {
        monitor.setProgress(SplashScreen.GUI_INIT);
    }
    WindowManagers.initialize();
    if (MacCompatibility.isSwingUsingScreenMenuBar()) {
        MacCompatibility.setFramelessJMenuBar(new LogisimMenuBar(null, null));
    } else {
        new LogisimMenuBar(null, null);
    // most of the time occupied here will be in loading menus, which
    // will occur eventually anyway; we might as well do it when the
    // monitor says we are
    }
    // if user has double-clicked a file to open, we'll
    // use that as the file to open now.
    initialized = true;
    // load file
    if (filesToOpen.isEmpty()) {
        Project proj = ProjectActions.doNew(monitor);
        proj.setStartupScreen(true);
        if (showSplash) {
            monitor.close();
        }
    } else {
        int numOpened = 0;
        boolean first = true;
        for (File fileToOpen : filesToOpen) {
            try {
                if (testVector != null) {
                    Project proj = ProjectActions.doOpenNoWindow(monitor, fileToOpen);
                    proj.doTestVector(testVector, circuitToTest);
                } else {
                    ProjectActions.doOpen(monitor, fileToOpen, substitutions);
                }
                numOpened++;
            } catch (LoadFailedException ex) {
                logger.error("{} : {}", fileToOpen.getName(), ex.getMessage());
            }
            if (first) {
                first = false;
                if (showSplash) {
                    monitor.close();
                }
                monitor = null;
            }
        }
        if (numOpened == 0)
            System.exit(-1);
    }
    for (File fileToPrint : filesToPrint) {
        doPrintFile(fileToPrint);
    }
    if (exitAfterStartup) {
        System.exit(0);
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Loader(com.cburch.logisim.file.Loader) LogisimMenuBar(com.cburch.logisim.gui.menu.LogisimMenuBar) File(java.io.File) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) LoadFailedException(com.cburch.logisim.file.LoadFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Print(com.cburch.logisim.gui.main.Print) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 4 with LoadFailedException

use of com.cburch.logisim.file.LoadFailedException in project logisim-evolution by reds-heig.

the class TtyInterface method run.

public static void run(Startup args) {
    File fileToOpen = args.getFilesToOpen().get(0);
    Loader loader = new Loader(null);
    LogisimFile file;
    try {
        file = loader.openLogisimFile(fileToOpen, args.getSubstitutions());
    } catch (LoadFailedException e) {
        logger.error("{}", Strings.get("ttyLoadError", fileToOpen.getName()));
        System.exit(-1);
        return;
    }
    int format = args.getTtyFormat();
    if ((format & FORMAT_STATISTICS) != 0) {
        format &= ~FORMAT_STATISTICS;
        displayStatistics(file);
    }
    if (format == 0) {
        // no simulation remaining to perform, so just exit
        System.exit(0);
    }
    Project proj = new Project(file);
    Circuit circuit = file.getMainCircuit();
    Map<Instance, String> pinNames = Analyze.getPinLabels(circuit);
    ArrayList<Instance> outputPins = new ArrayList<Instance>();
    Instance haltPin = null;
    for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
        Instance pin = entry.getKey();
        String pinName = entry.getValue();
        if (!Pin.FACTORY.isInputPin(pin)) {
            outputPins.add(pin);
            if (pinName.equals("halt")) {
                haltPin = pin;
            }
        }
    }
    CircuitState circState = new CircuitState(proj, circuit);
    // we have to do our initial propagation before the simulation starts -
    // it's necessary to populate the circuit with substates.
    circState.getPropagator().propagate();
    if (args.getLoadFile() != null) {
        try {
            boolean loaded = loadRam(circState, args.getLoadFile());
            if (!loaded) {
                logger.error("{}", Strings.get("loadNoRamError"));
                System.exit(-1);
            }
        } catch (IOException e) {
            logger.error("{}: {}", Strings.get("loadIoError"), e.toString());
            System.exit(-1);
        }
    }
    int ttyFormat = args.getTtyFormat();
    int simCode = runSimulation(circState, outputPins, haltPin, ttyFormat);
    System.exit(simCode);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Loader(com.cburch.logisim.file.Loader) Circuit(com.cburch.logisim.circuit.Circuit) IOException(java.io.IOException) Project(com.cburch.logisim.proj.Project) LogisimFile(com.cburch.logisim.file.LogisimFile) LogisimFile(com.cburch.logisim.file.LogisimFile) File(java.io.File) Map(java.util.Map) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 5 with LoadFailedException

use of com.cburch.logisim.file.LoadFailedException in project logisim-evolution by reds-heig.

the class ProjectActions method doOpen.

public static Project doOpen(Component parent, Project baseProject, File f) {
    Project proj = Projects.findProjectFor(f);
    Loader loader = null;
    if (proj != null) {
        proj.getFrame().toFront();
        loader = proj.getLogisimFile().getLoader();
        if (proj.isFileDirty()) {
            String message = StringUtil.format(Strings.get("openAlreadyMessage"), proj.getLogisimFile().getName());
            String[] options = { Strings.get("openAlreadyLoseChangesOption"), Strings.get("openAlreadyNewWindowOption"), Strings.get("openAlreadyCancelOption") };
            int result = JOptionPane.showOptionDialog(proj.getFrame(), message, Strings.get("openAlreadyTitle"), 0, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
            if (result == 0) {
                // keep proj as is, so that load happens into the window
                ;
            } else if (result == 1) {
                // we'll create a new project
                proj = null;
            } else {
                return proj;
            }
        }
    }
    if (proj == null && baseProject != null && baseProject.isStartupScreen()) {
        proj = baseProject;
        proj.setStartupScreen(false);
        loader = baseProject.getLogisimFile().getLoader();
    } else {
        loader = new Loader(baseProject == null ? parent : baseProject.getFrame());
    }
    try {
        LogisimFile lib = loader.openLogisimFile(f);
        AppPreferences.updateRecentFile(f);
        if (lib == null)
            return null;
        LibraryTools.RemovePresentLibraries(lib, new HashMap<String, Library>(), true);
        if (proj == null) {
            proj = new Project(lib);
            updatecircs(lib, proj);
        } else {
            updatecircs(lib, proj);
            proj.setLogisimFile(lib);
        }
    } catch (LoadFailedException ex) {
        if (!ex.isShown()) {
            JOptionPane.showMessageDialog(parent, StringUtil.format(Strings.get("fileOpenError"), ex.toString()), Strings.get("fileOpenErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        return null;
    }
    Frame frame = proj.getFrame();
    if (frame == null) {
        frame = createFrame(baseProject, proj);
    }
    frame.setVisible(true);
    frame.toFront();
    frame.getCanvas().requestFocus();
    proj.getLogisimFile().getLoader().setParent(frame);
    return proj;
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) Frame(com.cburch.logisim.gui.main.Frame) Loader(com.cburch.logisim.file.Loader) LoadedLibrary(com.cburch.logisim.file.LoadedLibrary) Library(com.cburch.logisim.tools.Library) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Aggregations

LoadFailedException (com.cburch.logisim.file.LoadFailedException)6 Loader (com.cburch.logisim.file.Loader)6 LogisimFile (com.cburch.logisim.file.LogisimFile)5 IOException (java.io.IOException)4 File (java.io.File)3 Project (com.cburch.logisim.proj.Project)2 InputStream (java.io.InputStream)2 Circuit (com.cburch.logisim.circuit.Circuit)1 CircuitState (com.cburch.logisim.circuit.CircuitState)1 LoadedLibrary (com.cburch.logisim.file.LoadedLibrary)1 Frame (com.cburch.logisim.gui.main.Frame)1 Print (com.cburch.logisim.gui.main.Print)1 LogisimMenuBar (com.cburch.logisim.gui.menu.LogisimMenuBar)1 Instance (com.cburch.logisim.instance.Instance)1 Library (com.cburch.logisim.tools.Library)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1