Search in sources :

Example 6 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class Main method clearRootModel.

public void clearRootModel() {
    myWorkspace.cancelRenderRequests();
    myModelName = null;
    myModelFile = null;
    RootModel rootModel = getRootModel();
    if (rootModel != null) {
        rootModel.detach(this);
        rootModel.removeComponentChangeListener(this);
        // just for completeness
        rootModel.setMainViewer(null);
        // 
        rootModel.removeController(myPullController);
        rootModel.dispose();
    }
    mySelectionManager.clearSelections();
    myUndoManager.clearCommands();
    myWorkspace.removeDisposables();
    ArtisynthPath.setWorkingDir(null);
    // myWorkspace.clearOutputProbes();
    if (myViewerManager != null) {
        myViewerManager.clearRenderables();
    }
    getWorkspace().setRootModel(null);
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Example 7 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class MenuBarHandler method createHelpMenu.

private void createHelpMenu(JMenu menu) {
    RootModel rootModel = myMain.getRootModel();
    addMenuItem(menu, "About ArtiSynth");
    addMenuItem(menu, "Keybindings");
    if (rootModel.getAbout() != null && rootModel.getAbout().length() > 0) {
        addMenuItem(menu, "About the current model");
    }
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Example 8 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class MenuBarHandler method doAddControlPanel.

/**
 * add a control panel to the model
 */
private void doAddControlPanel() {
    RootModel root = myMain.getRootModel();
    int number = root.getControlPanels().nextComponentNumber();
    ControlPanel panel = new ControlPanel("panel " + number, "LiveUpdate Close");
    GuiUtils.locateVertically(panel.getFrame(), myMain.getFrame(), GuiUtils.CENTER);
    GuiUtils.locateHorizontally(panel.getFrame(), myMain.getFrame(), GuiUtils.RIGHT);
    root.addControlPanel(panel);
}
Also used : RootModel(artisynth.core.workspace.RootModel) ControlPanel(artisynth.core.gui.ControlPanel)

Example 9 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class TestCommands method testSaveAndLoad.

public String testSaveAndLoad(String baseFileName, String fmtStr, double tsim, double hsim) {
    RootModel rootModel = myMain.getRootModel();
    if (rootModel == null) {
        return ("No root model loaded");
    }
    try {
        System.out.println("TESTING saveAndLoad for " + rootModel.getName() + " ...");
        String saveFileName = baseFileName + ".art";
        String checkFileName = baseFileName + ".chk";
        String stateFile0Name = rootModel.getName() + "_testdata0.txt";
        String stateFile1Name = rootModel.getName() + "_testdata1.txt";
        File saveFile = new File(saveFileName);
        File checkFile = new File(checkFileName);
        System.out.println("saving model to " + saveFileName + " ...");
        myMain.saveModelFile(saveFile, fmtStr);
        if (tsim > 0) {
            MechModel mech = findMechModel(rootModel);
            if (mech != null) {
                System.out.println("running model for " + tsim + " seconds ...");
                mech.setPrintState("%g", hsim);
                mech.openPrintStateFile(stateFile0Name);
                myMain.play(tsim);
                myMain.waitForStop();
            }
        }
        System.out.println("loading model from " + saveFileName + " ...");
        myMain.loadModelFile(saveFile);
        rootModel = myMain.getRootModel();
        System.out.println("saving model from " + checkFileName + " ...");
        myMain.saveModelFile(checkFile, fmtStr);
        System.out.println("comparing files " + saveFileName + " and " + checkFileName + " ...");
        String compareError = compareFiles(saveFileName, checkFileName, true);
        if (compareError != null) {
            System.out.println("FAILED");
            return compareError;
        } else {
            saveFile.delete();
            checkFile.delete();
        }
        if (tsim > 0) {
            MechModel mech = findMechModel(rootModel);
            if (mech != null) {
                System.out.println("running restored model for " + tsim + " seconds ...");
                mech.setPrintState("%g", hsim);
                mech.openPrintStateFile(stateFile1Name);
                myMain.play(tsim);
                myMain.waitForStop();
                CompareStateFiles comparator = new CompareStateFiles();
                System.out.println("comparing run state files " + stateFile0Name + " and " + stateFile1Name + " ...");
                if (!comparator.compareFiles(stateFile0Name, stateFile1Name, -1)) {
                    StringWriter sw = new StringWriter();
                    comparator.printMaxErrors(new PrintWriter(sw));
                    System.out.println("FAILED");
                    return sw.toString();
                } else {
                    File stateFile0 = new File(stateFile0Name);
                    File stateFile1 = new File(stateFile1Name);
                    stateFile0.delete();
                    stateFile1.delete();
                }
            }
        }
        System.out.println("OK");
    } catch (Exception e) {
        e.printStackTrace();
        return "IO Exception";
    }
    return null;
}
Also used : RootModel(artisynth.core.workspace.RootModel)

Example 10 with RootModel

use of artisynth.core.workspace.RootModel in project artisynth_core by artisynth.

the class ViewerManager method buildRenderList.

RenderList buildRenderList() {
    RenderList list = new RenderList();
    list.addIfVisibleAll(myRenderables);
    RootModel root = Main.getMain().getRootModel();
    if (root != null) {
        // modified by Ian: add RootModel to the render list,
        // note that prerender is called by addIfVisible()
        // root.prerender (list);
        list.addIfVisible(root);
    }
    return list;
}
Also used : RootModel(artisynth.core.workspace.RootModel) RenderList(maspack.render.RenderList)

Aggregations

RootModel (artisynth.core.workspace.RootModel)44 ModelComponent (artisynth.core.modelbase.ModelComponent)10 InternalErrorException (maspack.util.InternalErrorException)7 IOException (java.io.IOException)6 WayPoint (artisynth.core.probes.WayPoint)4 FileNotFoundException (java.io.FileNotFoundException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Probe (artisynth.core.probes.Probe)3 WayPointProbe (artisynth.core.probes.WayPointProbe)3 File (java.io.File)3 Property (maspack.properties.Property)3 ControlPanel (artisynth.core.gui.ControlPanel)2 CompositeComponent (artisynth.core.modelbase.CompositeComponent)2 TracingProbe (artisynth.core.probes.TracingProbe)2 Point (java.awt.Point)2 JFileChooser (javax.swing.JFileChooser)2 JMenuItem (javax.swing.JMenuItem)2 JSeparator (javax.swing.JSeparator)2 CompositeProperty (maspack.properties.CompositeProperty)2 ArgParser (argparser.ArgParser)1