Schematic Connection (metaclass)

A standalone SchematicConnection server can be declared as a metaclass.

Basics

The most simple example adds the connection point to all items of a given type, and allows all other items to connect to it through a named graph. Optional arguments on the metaclass configuration methods allow the graph to be reversed, and the connection point to support multiple or ordered connections.

1
2
3
4
5
6
7
8
9
static CLxMeta_SchematicConnection<CLxSchematicConnection>       schm_meta ("mySchematicConnectionServerName");

        void
initialize ()
{
        schm_meta.set_graph (GRAPH_NAME);
        schm_meta.set_itemtype (ITEMTYPE_NAME);
        ...
}

Since probably not every item should be able to connect it’s common to subclass and override the allow() method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class MySchematicConnection : public CLxSchematicConnection
{
    public:
                bool
        allow (
                CLxUser_Item            &from,
                CLxUser_Item            &to)         LXx_OVERRIDE
        {
                ...
        }
};

static CLxMeta_SchematicConnection<MySchematicConnection>        schm_meta ("mySchematicConnectionServerName");

Dynamic Items

If an item type is set (or if one is inferred from a Package metaclass) then there will be a connection on every item of the given type. If a different behavior is desired – such as allowing the connection on items of disparate types, or allowing the connection on a subset of items of the same type based on tags or packages – then the metaclass can be set to dynamic:

1
        schm_meta.set_dynamic ();

When this is set the test_item() method of the overridden CLxSchematicConnection class must call set_single() or set_multiple() for item that should have connection points. If neither method is called then the item will not have that connection.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
                void
        test_item (
                CLxUser_Item            &item)      LXx_OVERRIDE
        {
                if (item-can-have-connection)
                {
                        if (item-supports-multiple-inputs)
                                set_single ();
                        else
                                set_multiple ();
                }
        }

The schematic viewport caches the state of items for performance, so adding or removing a connection from a specific item requires that the cached state be invalidated. That can be done with the invalidate() method on the metaclass.

1
        schm_meta.invalidate ();

Manual Linkages

Schematic can also manage relationships other than graphs. This is done by setting the metaclass to manual mode (which is the default if no graph is specified). This requires three more methods of the base class be overridden by the connection. The first gets the list of items attached to this item. The other two make the changes when links are added or removed.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
                void
        get_list (
                CLxUser_Item            &item)          LXx_OVERRIDE
        {
                for (i = 0; i < item-count; i++)
                        add_item (item-list[i]);
        }

                void
        connect (
                CLxUser_Item            &from,
                CLxUser_Item            &to,
                int                      toIndex)       LXx_OVERRIDE
        {
                ...
        }

                void
        disconnect (
                CLxUser_Item            &from,
                CLxUser_Item            &to)            LXx_OVERRIDE
        {
                ...
        }