public class ExportModel
extends java.lang.Object
The default is to export a .gif file with the same name as the model.
See main(String[])
for usage.
See http://chess.eecs.berkeley.edu/ptexternal/wiki/Main/HTMLExport for detailed instructions about how to create web pages on the Ptolemy website for models.
Constructor and Description |
---|
ExportModel() |
Modifier and Type | Method and 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.
|
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
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.
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.java.lang.Exception
- Thrown if there is a problem reading the model
or exporting the image.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
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.java.lang.Exception
- Thrown if there is a problem reading the model
or exporting the image.public static void main(java.lang.String[] args)
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:
-force
-copyJavaScriptFiles -open -openComposites htm
.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.
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.xmljava.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.protected static void _sleep()