Saver: Server basics

A Saver is a plug-in server that can write internal nexus objects in a specific file format. Typically the objects are of image and scene types.

Overview

When the modo user selects “Save As…” from the menu, they are presented with a dialog containing a set of formats for the type of object they are saving: image savers for images and scene savers for scenes. Based on the format they choose, a server matching that format will be created to write the object to the file. The internal name of the server is used to reference the format in save commands.

Headers

  • ‘’’io (lx-io.hpp)’’’
    • ‘’CLxImpl_Saver’’

    • ‘’CLxUser_Monitor’’

  • ‘’’value (lx-value.hpp)’’’
    • ‘’CLxUser_Message’’

  • LXsSAV_OUTCLASS – the GUID or alias for the object type that this saver can write (e.g. ‘’LXa_IMAGE’’). Only this type of object will be passed to the saver.

  • LXsSAV_DOSTYPE – the three-character file extension to be used by default (e.g. ‘’JPG’’).

  • LXsSAV_OVERWRITE – set to “1” this indicates that the server needs to get the real, final path for the destination file. If not set the saver may be told to save the file to a temporary location before it’s copied over the real file.

The plug-in server class derives from CLxImpl_Saver, and exports the ILxSaver interface.

Saver::Verify()

The Verify() method is called before saving to allow the server to generate info or warnings. For example there may be data in the source object that can’t be saved in this format. The message can be set to show that, to give users a chance to change formats to avoid losing data.

1
2
3
4
5
6
         LxResult
 sav_Verify (
         ILxUnknownID            source,
         ILxUnknownID            message)     LXx_OVERRIDE
 {
         CLxUser_Message         msg (message);
1
2
         if (source_data_is_ok (source))
                 return LXe_OK;
1
2
3
4
         msg.SetCode (LXe_WARNING);
         msg.SetMsg ("mymessagetable", "myerrormessagekey");
         return LXe_OK;
 }

Saver::Save()

The Save() method does the main work of the server, reading the contents of the source object and writing that data to the destination file.

1
2
3
4
5
6
7
         LxResult
 sav_Save (
         ILxUnknownID            source,
         const char             *filename,
         ILxUnknownID            monitor)     LXx_OVERRIDE
 {
         CLxUser_Monitor         mon (monitor);
1
2
         if (!open_file_write (filename))
                 return LXe_IO_ERROR;
1
         ''< write data to file >''
1
2
3
         close_file ();
         return LXe_OK;
 }

Helper Classes

The CLxSceneSaver class can be used to write scene savers. See scene (lxu-scene.hpp).