Skip to content

Atom Tools Framework Document System

Guthrie Adams edited this page Jun 1, 2023 · 1 revision

Document System

https://github.com/o3de/o3de/tree/development/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Document

Most of the tool specific code is intended to be contained in document, view, and other UI classes. • A document is a class with an interface to create, load, save, adapt, and manipulate a specific type of data. • A view is usually UI tied to a document for visualizing and interacting with its content.

This is a common MVC or document/view design pattern that decouples object data from how it is presented. The separation allows for documents and views to change independently.

Different views can be created for the same document type. For example, a single document could represent a hierarchical scene. The application could implement multiple views for a scene document, like a 3D viewport to render the scene, a tree view to display the hierarchy, a table to display details about assets and object types referenced in the scene. A more traditional example would be a document containing a table of values and different table, graph, and chart views to visualize the table data.

The document system class manages registration, creation, destruction, and high level request routing for document types and instances. Event buses allow interaction with the system through code and script.

For simple cases, generic document classes can be used to adapt and register any reflected, serializable data types without additional code.

https://github.com/o3de/o3de/blob/development/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Document/AtomToolsAnyDocument.h

To implement a custom document class: • Create a new document class derived from the base document class. • Override functions to load, save, undo, redo, etc. • Create a custom bus with functions needed to access or mutate document data and add it to the behavior context for your document type. • Register the document type with the document system.

Here is the base document class. https://github.com/o3de/o3de/blob/development/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Document/AtomToolsDocument.h

Here is an example document class from the Material Editor. It requires a custom document class because the editable data is assembled from multiple source files with data structures that are not directly editable.

https://github.com/o3de/o3de/blob/development/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocument.h

The Material Editor document is registered with the application here.

https://github.com/o3de/o3de/blob/development/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp#L73-L83

Material Canvas registers multiple generic and complex document types.

https://github.com/o3de/o3de/blob/development/Gems/Atom/Tools/MaterialCanvas/Code/Source/MaterialCanvasApplication.cpp#L282-L350

Extended application and main window base classes are provided with the document system. These add menus, a tab bar, an inspector, and other support for managing multiple documents, types, and views. At this time, most cases only have one central view per document. Other windows can monitor document related notifications as well as display and interact with documents via buses.