Azure / opendigitaltwins-dtdl

Digital Twins Definition Language
Creative Commons Attribution 4.0 International
466 stars 160 forks source link

Use of component #98

Closed Andrej-Kalocanj-Mohaci closed 3 years ago

Andrej-Kalocanj-Mohaci commented 3 years ago

Greetings,

If we have a model of an phone with a component of Camera model with some properties { "@id": "dtmi:com:example:Phone;2", "@type": "Interface", "displayName": "Phone", "contents": [ { "@type": "Component", "name": "frontCamera", "schema": "dtmi:com:example:Camera;3" } ], "@context": "dtmi:dtdl:context;2" }

how do we "connect" that in a .xlsx of ADT Explorer? When a twin is created from an Phone model, that twin contains Camera in metadata, but it is empty, how do we fill does fields for that camera, do we create a twin from Camera and connect it in some way like with relationships?

Thanks for the answer. Kind regards

cschormann commented 3 years ago

Components do not need to (and can't) be instantiated separately - they are included in the hosting twin "by value". That is, if you instantiate a twin with a component, the component is not an independent twin with an ID connected via relationships, but just data that is included in the hosting twin. The easiest way to think of components is a sub-folder of properties within a twin.

When you instantiate a twin with components in adt-explorer, the component properties are empty, but you can edit them in the property inspector (in the latest build) and patch them (use the save icon in the upper right corner of the property inspector).

You can definitively upload twin definition files with component properties using JSON files, but I am not sure if that works for XLS files. JSON twin files that you can import into adt-explorer look like this: { "digitalTwinsFileInfo": { "fileVersion": "1.0.0" }, "digitalTwinsGraph": { "digitalTwins": [ ], "relationships": [ ] }, "digitalTwinsModels": [ ] }

If you already have uploaded models, the model section can be empty, but it must be present. Same for the relationships section. Here is an example that creates a single twin that hosts two copies of the same component and initializes their properties. This example also contains the models: `{ "digitalTwinsFileInfo": { "fileVersion": "1.0.0" }, "digitalTwinsGraph": { "digitalTwins": [ { "$dtId": "NewTwinWithComponent", "c1": { "testCompProp": "Some property value", "$metadata": { } }, "c2": { "testCompProp": "My property value", "$metadata": { } }, "$metadata": { "$model": "dtmi:example:ModelWithComponents;1" } } ], "relationships": [

    ]
},
"digitalTwinsModels": [
    {
        "@context": [
            "dtmi:dtdl:context;2"
        ],
        "@id": "dtmi:example:TestComponent;1",
        "@type": "Interface",
        "displayName": "TestComponent",
        "contents": [
            {
                "@type": "Property",
                "name": "testCompProp",
                "schema": "string"
            }
        ]
    },
    {
        "@context": [
            "dtmi:dtdl:context;2"
        ],
        "@id": "dtmi:example:ModelWithComponents;1",
        "@type": "Interface",
        "displayName": "Model with Components",
        "contents": [
            {
                "@type": "Component",
                "name": "c1",
                "schema": "dtmi:example:TestComponent;1"
            },
            {
                "@type": "Component",
                "name": "c2",
                "schema": "dtmi:example:TestComponent;1"
            },
            {
                "@type": "Property",
                "name": "testObject",
                "schema": {
                    "@type": "Object",
                    "fields": [
                        {
                            "name": "objFieldTest1",
                            "schema": "double"
                        },
                        {
                            "name": "objFieldTest2",
                            "schema": "double"
                        }
                    ]
                }
            }
        ]
    }
]

}`