SonyWWS / ATF

Authoring Tools Framework (ATF) is a set of C#/.NET components for making tools on Windows. ATF has been in continuous development in Sony Computer Entertainment's (SCE) Worldwide Studios central tools group since early 2005. ATF has been used by most SCE first party studios to make many custom tools such as Naughty Dog’s level editor and shader editor for The Last of Us, Guerrilla Games’ sequence editor for Killzone games (including the Killzone: Shadow Fall PS4 launch title), an animation blending tool at Santa Monica Studio, a level editor at Bend Studio, a visual state machine editor for Quantic Dream, sound editing tools, and many others.
Apache License 2.0
1.89k stars 262 forks source link

Multiple Circuit Editor Instances. #11

Closed RomainBL closed 10 years ago

RomainBL commented 10 years ago

Hello,

Thanks for sharing your great work.

I would like to use multiple instance of the circuit editor and each of these instances will edit a different file extension but using the same schema (I know it’s a bit weird). The circuit editor will be a generic nodal editor.

The first approach was to simply instantiate multiple CircuitEditor but quickly I realized the use of a lot of static in the code (Command, Schema, EditorInfo...). I started to convert or move these static variables. I think I nearly succeed. The last problem where I struggle is the possibility to have one file extension per circuit editor instance. Also, I found other static variable which I don’t know if I need to change it (like Direct2D variable s_gfx.)

The second approach was to duplicate the circuit editor project, but I don’t want to go that way.

Do you have a better solution in mind ? or any advices ?

Ron2 commented 10 years ago

Hello, I'm glad to hear that you're diving into ATF and we hope it proves useful to you!

The editors in general, like CircuitEditor, are designed to be instantiated once per application session, and they work with the current editing context (which is usually a document). The IDocumentClient interface specifies the kinds of document file extensions that your app knows about. In most cases, the editor deals with just one kind of document, and so it's convenient for the editor to implement IDocumentClient. But in your case, the circuit editor should not implement IDocumentClient, and you should implement it separately, multiple times, once for each file extension, and export each IDocumentClient so that the IDocumentRegistry can find it. We happen to do this in the CodeEditor sample app:

            // create a document client for each file type
            m_txtDocumentClient = new DocumentClient(this, ".txt");
            m_csDocumentClient = new DocumentClient(this, ".cs");
            m_luaDocumentClient = new DocumentClient(this, ".lua");
            m_nutDocumentClient = new DocumentClient(this, ".nut");
            m_pyDocumentClient = new DocumentClient(this, ".py");
            m_xmlDocumentClient = new DocumentClient(this, ".xml");
            m_daeDocumentClient = new DocumentClient(this, ".dae");
            m_cgDocumentClient = new DocumentClient(this, ".cg");

...
        [Export(typeof(IDocumentClient))]
        private DocumentClient m_txtDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_csDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_luaDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_nutDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_pyDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_xmlDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_daeDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_cgDocumentClient;

I chatted with a coworker here, Shen, and he says that Santa Monica Studios had to do something very similar to what you're doing, where the circuit editor would open and save two kinds of circuit documents that used the same schema, but with two different file extensions. One file extension is for a "master" circuit document and another is for sub-circuits that are referenced by the master one.

--Ron

Ron2 commented 10 years ago

I should have mentioned that you can also make a single IDocumentClient handle multiple extensions. There's a constructor of DocumentClientInfo() that can accept an array of string extensions. We do this in the ModelViewer and SimpleDomEditor sample apps.

            string[] exts = { ".atgi", ".dae" };
            m_info = new DocumentClientInfo("3D Model", exts, null, null, false);

I think you would use a single IDocumentClient that supports multiple extensions if you want the user to be able to convert one file type into another, in the Save As menu. Ctrl+N will probably behave differently, too, to ask the user what type of file they want to create. When opening a file, all the possible extensions are listed in a drop-down list.

You would use multiple IDocumentClients to have a 'New' sub-menu in the File menu that lets the user choose which type of new document to create in the menu. When saving or save-as, the user won't be able to change the file type.

RomainBL commented 10 years ago

Thanks for your answer.

What we finally did is for each circuit editor instance we have a specific Editor Class which derived from the main Editor Class. The member EditorInfo is now a non-static variable initialized in the constructor.

[ImportingConstructor]
public Editor(
        ...
    string extension)
        {
           EditorInfo = new DocumentClientInfo(CircuitDocument.GetDocumentType(extension), extension, null, null);
        ...
      }

The static initialization of the File Extension in the Schema loader have been removed

//            Schema.circuitDocumentType.Type.SetTag(Editor.EditorInfo);

Now we can have multiple Circuit Editor Instance, each of them manages a specific file extension but all the instances have the same schema.

Ron2 commented 10 years ago

Sounds good! Glad you found a good solution. All of the code in the sample apps is intended to be copied and modified by our clients, so that's perfectly normal that you had to modify that Editor class.