Class ExportModel


  • public class ExportModel
    extends java.lang.Object
    Export a model as an image or set of html files.

    The default is to export a .gif file with the same name as the model. See main(String[]) for usage.

    See https://wiki.eecs.berkeley.edu/ptexternal/Main/Main/HTMLExport for detailed instructions about how to create web pages on the Ptolemy website for models.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Christopher Brooks
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (cxh)
    • Constructor Summary

      Constructors 
      Constructor Description
      ExportModel()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void _sleep()
      Sleep the current thread, which is usually not the Swing Event Dispatch Thread.
      void exportModel​(boolean copyJavaScriptFiles, boolean force, java.lang.String formatName, java.lang.String modelFileName, boolean run, boolean openComposites, boolean openResults, java.lang.String outputFileOrDirectory, boolean save, boolean whiteBackground)
      Export an image of a model to a file or directory.
      void exportModel​(boolean copyJavaScriptFiles, boolean force, java.lang.String formatName, java.lang.String modelFileName, boolean run, boolean openComposites, boolean openResults, java.lang.String outputFileOrDirectory, boolean save, long timeOut, boolean whiteBackground)
      Export an image of a model to a file or directory.
      static void main​(java.lang.String[] args)
      Export a model as an image.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExportModel

        public ExportModel()
    • Method Detail

      • exportModel

        public void exportModel​(boolean copyJavaScriptFiles,
                                boolean force,
                                java.lang.String formatName,
                                java.lang.String modelFileName,
                                boolean run,
                                boolean openComposites,
                                boolean openResults,
                                java.lang.String outputFileOrDirectory,
                                boolean save,
                                boolean whiteBackground)
                         throws java.lang.Exception
        Export an image of a model to a file or directory.

        The image is written to a file or directory with the same name as the model. If formatName starts with "HTM" or "htm", then a directory with the same name as the basename of the model is created. If the formatName is "GIF", "gif", "PNG" or "png", then a file with the same basename as the basename of the model is created.

        The time out defaults to 30 seconds.

        Parameters:
        copyJavaScriptFiles - True if the javascript files should be copied. Used only if formatName starts with "htm" or "HTM".
        force - If true, then remove the image file or htm directory to be created in advance before creating the image file or htm directory. This parameter is primarily used to avoid prompting the user with questions about overwriting files after this command is invoked.
        formatName - The file format of the file to be generated. One of "GIF", "gif", "HTM", "htm", "PNG", "png".
        modelFileName - A Ptolemy model in MoML format. The string may start with $CLASSPATH, $HOME or other formats suitable for FileUtilities.nameToFile(String, URI).
        run - True if the model should be run first. If run is true, and if formatName starts with "htm" or "HTM", then the output will include images of any plots.
        openComposites - True if the CompositeEntities should be open. The openComposites parameter only has an effect if formatName starts with "htm" or "HTM".
        openResults - open the resulting image file or web page.
        outputFileOrDirectory - If non-null, then the file or directory in which to generate the file(s).
        save - True if the model should be saved after being run.
        whiteBackground - True if the model background should be set to white.
        Throws:
        java.lang.Exception - Thrown if there is a problem reading the model or exporting the image.
      • exportModel

        public void exportModel​(boolean copyJavaScriptFiles,
                                boolean force,
                                java.lang.String formatName,
                                java.lang.String modelFileName,
                                boolean run,
                                boolean openComposites,
                                boolean openResults,
                                java.lang.String outputFileOrDirectory,
                                boolean save,
                                long timeOut,
                                boolean whiteBackground)
                         throws java.lang.Exception
        Export an image of a model to a file or directory. The image is written to a file or directory with the same name as the model. If formatName starts with "HTM" or "htm", then a directory with the same name as the basename of the model is created. If the formatName is "GIF", "gif", "PNG" or "png", then a file with the same basename as the basename of the model is created.
        Parameters:
        copyJavaScriptFiles - True if the javascript files should be copied. Used only if formatName starts with "htm" or "HTM".
        force - If true, then remove the image file or htm directory to be created in advance before creating the image file or htm directory. This parameter is primarily used to avoid prompting the user with questions about overwriting files after this command is invoked.
        formatName - The file format of the file to be generated. One of "GIF", "gif", "HTM", "htm", "PNG", "png".
        modelFileName - A Ptolemy model in MoML format. The string may start with $CLASSPATH, $HOME or other formats suitable for FileUtilities.nameToFile(String, URI).
        run - True if the model should be run first. If run is true, and if formatName starts with "htm" or "HTM", then the output will include images of any plots.
        openComposites - True if the CompositeEntities should be open. The openComposites parameter only has an effect if formatName starts with "htm" or "HTM".
        openResults - open the resulting image file or web page.
        outputFileOrDirectory - If non-null, then the file or directory in which to generate the file(s).
        save - True if the model should be saved after being run.
        timeOut - Time out in milliseconds. 30000 is a good value.
        whiteBackground - True if the model background should be set to white.
        Throws:
        java.lang.Exception - Thrown if there is a problem reading the model or exporting the image.
      • main

        public static void main​(java.lang.String[] args)
        Export a model as an image.

        Note that the a graphical display must be present, this code displays the model and executes. To use in a headless environment under Linux, install Xvfb.

        Command line arguments are:

        -help|--help|-h
        Print a help message and return.
        -copyJavaScriptFiles
        Copy .js files. Useful only with -web and htm* format.
        -force
        Delete the target file or directory before generating the results.
        -open
        Open the generated file in a browser.
        -openComposites
        Open any composites before exporting the model.
        -run
        Run the model before exporting. This is useful when exporting an html file as plots are also generated.
        -save
        Save the model before closing.
        -web
        Common settings for exporting to the web. Short for: -force -copyJavaScriptFiles -open -openComposites htm.
        -whiteBackground
        Set the background color to white.
        [GIF|gif|HTM*|htm*|PNG|png]
        The file format. If no format is selected, then a gif format file is generated.
        model.xml
        The model to be exported. (Required)
        directoryName
        The directory in which to export the file(s) (Optional)

        Typical usage:

        To save a gif:

           java -classpath $PTII ptolemy.vergil.basic.export.ExportModel model.xml
          

        or, to save the current view of model in HTML format without any plots:

           java -classpath $PTII ptolemy.vergil.basic.export.ExportModel htm model.xml
          

        or, to run the model and save the current view of model in HTML format with any plots:

           java -classpath $PTII ptolemy.vergil.basic.export.ExportModel -run htm model.xml
          

        or, to run the model, open any composites and save the current view of model and the composites HTML format with any plots:

           java -classpath $PTII ptolemy.vergil.basic.export.ExportModel -run -openComposites htm model.xml
          

        Standard setting for exporting to html can be invoked with -web, which is like -copyJavaScriptFiles -open -openComposites htm.

           java -classpath $PTII ptolemy.vergil.basic.export.ExportModel -web model.xml
          

        or, to save a png:

           java -classpath $PTII ptolemy.vergil.basic.export.ExportModel png model.xml
          

        or, to run the model and then save a png:

           java -classpath $PTII ptolemy.vergil.basic.export.ExportModel -run png model.xml
          

        To set the background to white, invoke with -whiteBackground.

        To export an html version in a format suitable for the Ptolemy website, set the "ptolemy.ptII.exportHTML.usePtWebsite" property to true, perhaps by including the following in the command line:

          -Dptolemy.ptII.exportHTML.usePtWebsite=true
          

        For example:

          export JAVAFLAGS=-Dptolemy.ptII.exportHTML.usePtWebsite=true
          $PTII/bin/ptweb $PTII/ptolemy/moml/demo/modulation.xml
          

        To include a link to a sanitizedModelName.jnlp file, set -Dptolemy.ptII.exportHTML.linkToJNLP=true.

        Note that the Ptolemy menus will not appear unless you view the page with a web server that has Server Side Includes (SSI) enabled and has the appropriate scripts. Also, the .html files must be executable.

        Include a link to the a sanitizedModelName.jnlp file, set the "ptolemy.ptII.exportHTML.linkToJNLP" property to true.

        Parameters:
        args - The arguments for the export image operation. The arguments should be in the format: [-help|-h|--help] | [-copyJavaScriptFiles] [-force] [-open] [-openComposites] [-run] [-save] [-timeOut ms] [-web] [-whiteBackground] [GIF|gif|HTM*|htm*|PNG|png] model.xml
        Throws:
        java.lang.IllegalArgumentException - If there is 1 argument, then it names a Ptolemy MoML file and the model is exported as a .gif file. If there are two arguments, then the first argument names a format, current formats are GIF, gif, HTM, htm, PNG and png and the second argument names a Ptolemy MoML file.
      • _sleep

        protected static void _sleep()
        Sleep the current thread, which is usually not the Swing Event Dispatch Thread.