コード例 #1
0
        public static List <VisualElementGeneric> GenerateVisualElementsFromShellEnv(
            TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShellPackageEnv package = null,
            bool editMode = false, int expandMode = 0)
        {
            // clear tree
            var res = new List <VisualElementGeneric>();

            // valid?
            if (env == null)
            {
                return(res);
            }

            // need some attach points
            VisualElementEnvironmentItem tiPackage = null, tiEnv = null, tiShells = null, tiAssets = null, tiCDs = null;

            // tracking references of Submodels
            var referencedSubmodels = new List <AdminShell.Submodel>();

            // interested plug-ins
            var pluginsToCheck = new List <Plugins.PluginInstance>();

            if (Plugins.LoadedPlugins != null)
            {
                foreach (var lpi in Plugins.LoadedPlugins.Values)
                {
                    // ReSharper disable EmptyGeneralCatchClause
                    try
                    {
                        var x =
                            lpi.InvokeAction(
                                "get-check-visual-extension") as AasxIntegrationBase.AasxPluginResultBaseObject;
                        if (x != null && (bool)x.obj)
                        {
                            pluginsToCheck.Add(lpi);
                        }
                    }
                    catch { }
                    // ReSharper enable EmptyGeneralCatchClause
                }
            }

            // many operytions -> make it bulletproof
            try
            {
                if (editMode)
                {
                    // package
                    tiPackage = new VisualElementEnvironmentItem(
                        null /* Parent */, cache, package, env, VisualElementEnvironmentItem.ItemType.Package);
                    tiPackage.SetIsExpandedIfNotTouched(true);
                    res.Add(tiPackage);

                    // env
                    tiEnv = new VisualElementEnvironmentItem(
                        tiPackage, cache, package, env, VisualElementEnvironmentItem.ItemType.Env);
                    tiEnv.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiPackage.Members.Add(tiEnv);

                    // shells
                    tiShells = new VisualElementEnvironmentItem(
                        tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.Shells);
                    tiShells.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiEnv.Members.Add(tiShells);

                    // assets
                    tiAssets = new VisualElementEnvironmentItem(
                        tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.Assets);
                    tiAssets.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiEnv.Members.Add(tiAssets);

                    // concept descriptions
                    tiCDs = new VisualElementEnvironmentItem(
                        tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.ConceptDescriptions);
                    tiCDs.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiEnv.Members.Add(tiCDs);
                }

                // over all Admin shells
                foreach (var aas in env.AdministrationShells)
                {
                    // item
                    var tiAas = new VisualElementAdminShell(null, cache, package, env, aas);
                    tiAas.SetIsExpandedIfNotTouched(expandMode > 0);

                    // add item
                    if (editMode)
                    {
                        tiAas.Parent = tiShells;
                        tiShells.Members.Add(tiAas);
                    }
                    else
                    {
                        res.Add(tiAas);
                    }

                    // have submodels?
                    if (aas.submodelRefs != null)
                    {
                        foreach (var smr in aas.submodelRefs)
                        {
                            var sm = env.FindSubmodel(smr);
                            if (sm == null)
                            {
                                Log.Error("Cannot find some submodel!");
                            }
                            else
                            {
                                referencedSubmodels.Add(sm);
                            }

                            // item (even if sm is null)
                            var tiSm = new VisualElementSubmodelRef(tiAas, cache, env, smr, sm);
                            tiSm.SetIsExpandedIfNotTouched(expandMode > 1);

                            // check for visual extensions
                            foreach (var lpi in pluginsToCheck)
                            {
                                // ReSharper disable EmptyGeneralCatchClause
                                try
                                {
                                    var ext = lpi.InvokeAction(
                                        "call-check-visual-extension", sm)
                                              as AasxIntegrationBase.AasxPluginResultVisualExtension;
                                    if (ext != null)
                                    {
                                        var tiExt = new VisualElementPluginExtension(
                                            tiSm, cache, package, sm, lpi, ext);
                                        tiSm.Members.Add(tiExt);
                                    }
                                }
                                catch { }
                                // ReSharper enable EmptyGeneralCatchClause
                            }

                            // recursively into the submodel elements
                            if (sm != null)
                            {
                                if (sm.submodelElements != null)
                                {
                                    foreach (var sme in sm.submodelElements)
                                    {
                                        GenerateVisualElementsFromShellEnvAddElements(cache, env, tiSm, sm, sme);
                                    }
                                }
                            }

                            // add
                            tiAas.Members.Add(tiSm);
                        }
                    }

                    // have views?
                    if (aas.views != null && aas.views.views != null)
                    {
                        foreach (var vw in aas.views.views)
                        {
                            // item
                            var tiVw = new VisualElementView(tiAas, cache, env, vw);
                            tiVw.SetIsExpandedIfNotTouched(expandMode > 1);
                            // recursion -> submodel elements
                            if (vw.containedElements != null && vw.containedElements.reference != null)
                            {
                                foreach (var ce in vw.containedElements.reference)
                                {
                                    var tiRf = new VisualElementReference(tiVw, cache, env, ce);
                                    tiVw.Members.Add(tiRf);
                                }
                            }
                            // add
                            tiAas.Members.Add(tiVw);
                        }
                    }
                }

                // if edit mode, then display further ..
                if (editMode)
                {
                    // over all assets
                    foreach (var asset in env.Assets)
                    {
                        // item
                        var tiAsset = new VisualElementAsset(tiAssets, cache, env, asset);
                        tiAssets.Members.Add(tiAsset);
                    }

                    // over all concept descriptions
                    foreach (var cd in env.ConceptDescriptions)
                    {
                        // item
                        var tiCD = new VisualElementConceptDescription(tiCDs, cache, env, cd);
                        tiCDs.Members.Add(tiCD);
                    }

                    // alternative code deleted
                    {
                        // head
                        var tiAllSubmodels = new VisualElementEnvironmentItem(
                            tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.AllSubmodels);
                        tiAllSubmodels.SetIsExpandedIfNotTouched(expandMode > 0);
                        tiEnv.Members.Add(tiAllSubmodels);

                        // show all Submodels
                        foreach (var sm in env.Submodels)
                        {
                            var tiSm = new VisualElementSubmodel(tiAllSubmodels, cache, env, sm);
                            tiSm.SetIsExpandedIfNotTouched(expandMode > 1);
                            tiAllSubmodels.Members.Add(tiSm);
                        }
                    }
                }

                // package as well?
                if (editMode && package != null && tiPackage != null)
                {
                    // file folder
                    var tiFiles = new VisualElementEnvironmentItem(
                        tiPackage, cache, package, env, VisualElementEnvironmentItem.ItemType.SupplFiles);
                    tiFiles.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiPackage.Members.Add(tiFiles);

                    // single files
                    var files = package.GetListOfSupplementaryFiles();
                    foreach (var fi in files)
                    {
                        tiFiles.Members.Add(new VisualElementSupplementalFile(tiFiles, cache, package, fi));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Generating tree of visual elements");
            }

            // end
            return(res);
        }
コード例 #2
0
ファイル: VisualAasxElements.cs プロジェクト: i-Asset/basyx
        public static List <VisualElementGeneric> GenerateVisualElementsFromShellEnv(TreeViewLineCache cache, AdminShell.AdministrationShellEnv env, AdminShell.PackageEnv package = null, bool editMode = false, int expandMode = 0)
        {
            // clear tree
            var res = new List <VisualElementGeneric>();

            // valid?
            if (env == null)
            {
                return(res);
            }

            // need some attach points
            VisualElementEnvironmentItem tiPackage = null, tiEnv = null, tiShells = null, tiAssets = null, tiCDs = null;

            // many operytions -> make it bulletproof
            try
            {
                if (editMode)
                {
                    // package
                    tiPackage = new VisualElementEnvironmentItem(null /* Parent */, cache, package, env, VisualElementEnvironmentItem.ItemType.Package);
                    tiPackage.SetIsExpandedIfNotTouched(true);
                    res.Add(tiPackage);

                    // env
                    tiEnv = new VisualElementEnvironmentItem(tiPackage, cache, package, env, VisualElementEnvironmentItem.ItemType.Env);
                    tiEnv.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiPackage.Members.Add(tiEnv);

                    // shells
                    tiShells = new VisualElementEnvironmentItem(tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.Shells);
                    tiShells.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiEnv.Members.Add(tiShells);

                    // assets
                    tiAssets = new VisualElementEnvironmentItem(tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.Assets);
                    tiAssets.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiEnv.Members.Add(tiAssets);

                    // concept descriptions
                    tiCDs = new VisualElementEnvironmentItem(tiEnv, cache, package, env, VisualElementEnvironmentItem.ItemType.ConceptDescriptions);
                    tiCDs.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiEnv.Members.Add(tiCDs);
                }

                // over all Admin shells
                foreach (var aas in env.AdministrationShells)
                {
                    // item
                    var tiAas = new VisualElementAdminShell(null, cache, env, aas);
                    tiAas.SetIsExpandedIfNotTouched(expandMode > 0);

                    // add item
                    if (editMode)
                    {
                        tiAas.Parent = tiShells;
                        tiShells.Members.Add(tiAas);
                    }
                    else
                    {
                        res.Add(tiAas);
                    }

                    // have submodels?
                    if (aas.submodelRefs != null)
                    {
                        foreach (var smr in aas.submodelRefs)
                        {
                            var sm = env.FindSubmodel(smr);
                            if (sm == null)
                            {
                                Log.Error("Cannot find some submodel!");
                                continue;
                            }
                            // item
                            var tiSm = new VisualElementSubmodelRef(tiAas, cache, env, smr, sm);
                            tiSm.SetIsExpandedIfNotTouched(expandMode > 1);
                            // recursively into the submodel elements
                            if (sm.submodelElements != null)
                            {
                                foreach (var sme in sm.submodelElements)
                                {
                                    GenerateVisualElementsFromShellEnvAddElements(cache, env, tiSm, sm, sme);
                                }
                            }
                            // add
                            tiAas.Members.Add(tiSm);
                        }
                    }

                    // have views?
                    if (aas.views != null && aas.views.views != null)
                    {
                        foreach (var vw in aas.views.views)
                        {
                            // item
                            var tiVw = new VisualElementView(tiAas, cache, env, vw);
                            tiVw.SetIsExpandedIfNotTouched(expandMode > 1);
                            // recursion -> submodel elements
                            if (vw.containedElements != null && vw.containedElements.reference != null)
                            {
                                foreach (var ce in vw.containedElements.reference)
                                {
                                    var tiRf = new VisualElementReference(tiVw, cache, env, ce);
                                    tiVw.Members.Add(tiRf);
                                }
                            }
                            // add
                            tiAas.Members.Add(tiVw);
                        }
                    }
                }

                // if edit mode, then display further ..
                if (editMode)
                {
                    // over all assets
                    foreach (var asset in env.Assets)
                    {
                        // item
                        var tiAsset = new VisualElementAsset(tiAssets, cache, env, asset);
                        tiAssets.Members.Add(tiAsset);
                    }

                    // over all concept descriptions
                    foreach (var cd in env.ConceptDescriptions)
                    {
                        // item
                        var tiCD = new VisualElementConceptDescription(tiCDs, cache, env, cd);
                        tiCDs.Members.Add(tiCD);
                    }
                }

                // package as well?
                if (editMode && package != null && tiPackage != null)
                {
                    // file folder
                    var tiFiles = new VisualElementEnvironmentItem(tiPackage, cache, package, env, VisualElementEnvironmentItem.ItemType.SupplFiles);
                    tiFiles.SetIsExpandedIfNotTouched(expandMode > 0);
                    tiPackage.Members.Add(tiFiles);

                    // single files
                    var files = package.GetListOfSupplementaryFiles();
                    foreach (var fi in files)
                    {
                        tiFiles.Members.Add(new VisualElementSupplementalFile(tiFiles, cache, package, fi));
                    }
                }
            } catch (Exception ex)
            {
                Log.Error(ex, "Generating tree of visual elements");
            }

            // end
            return(res);
        }