
266 Chapter 10: Creating a File Writer
Creating a New File Writer iTool Developer’s Guide
Note
Any property registered with a call to the RegisterProperty method must be listed as
a keyword to the SetProperty method either of the visualization class or one of its
superclasses.
Note
A file writer need not register any properties at all, if the write operation is simple.
Many of the standard iTool image file writer work without registering any
properties.
See “IDLitWriter::SetProperty” (IDL Reference Guide) for additional details.
Example SetProperty Method
PRO ExampleWriter::SetProperty, _REF_EXTRA = _extra
IF (N_ELEMENTS(_extra) GT 0) THEN $
self->IDLitWriter::SetProperty, _EXTRA = _extra
END
Discussion
The SetProperty method first defines the keywords it will accept. There must be a
keyword for each property of the visualization type. Since the file writer we are
creating has no properties of its own, there are no keywords explicitly defined. Note
the use of the keyword inheritance mechanism to allow us to set properties from the
ExampleWriter class’ superclasses without knowing the names of the properties.
Using the N_ELEMENTS function, we check to see whether any properties were
specified via the keyword inheritance mechanism. If any keywords were specified,
we call the superclass’ SetProperty method, passing in all of the keywords stored in
the
_extra structure.
Creating a SetData Method
The file writer SetData method does the work of the file writer, extracting data from
the selected iTool data object and writing the data to a file using some method. If the
process is successful, the SetData method must return 1 for success.
In our example, we write the selected data to a Portable Pixmap (PPM) file. As a
result, we do some additional checking to ensure that the data that the user has
selected can be displayed as an image.
See “IDLitWriter::SetData” (IDL Reference Guide) for additional details.