Exemplo n.º 1
0
        //
        // HasSemantic
        //

        public void DisplayOrEditEntitySemanticId(AnyUiStackPanel stack,
                                                  AdminShell.SemanticId semanticId,
                                                  Action <AdminShell.SemanticId> setOutput,
                                                  string statement           = null,
                                                  bool checkForCD            = false,
                                                  string addExistingEntities = null,
                                                  CopyPasteBuffer cpb        = null)
        {
            // access
            if (stack == null)
            {
                return;
            }

            // members
            this.AddGroup(stack, "Semantic ID:", levelColors.SubSection);

            // hint
            this.AddHintBubble(
                stack, hintMode,
                new[] {
                new HintCheck(
                    () => { return(semanticId == null || semanticId.IsEmpty); },
                    "Check if you want to add a semantic reference. " + statement,
                    severityLevel: HintCheck.Severity.Notice,
                    breakIfTrue: true),
                new HintCheck(
                    () => { return(checkForCD &&
                                   semanticId[0].type != AdminShell.Key.ConceptDescription); },
                    "The semanticId usually refers to a ConceptDescription " +
                    "within the respective repository.",
                    severityLevel: HintCheck.Severity.Notice)
            });

            // add from Copy Buffer
            var bufferKeys = CopyPasteBuffer.PreparePresetsForListKeys(cpb);

            // add the keys
            if (this.SafeguardAccess(
                    stack, repo, semanticId, "semanticId:", "Create data element!",
                    v =>
            {
                setOutput?.Invoke(new AdminShell.SemanticId());
                return(new AnyUiLambdaActionRedrawEntity());
            }))
            {
                this.AddKeyListKeys(
                    stack, "semanticId", semanticId.Keys, repo,
                    packages, PackageCentral.PackageCentral.Selector.MainAux,
                    addExistingEntities: addExistingEntities, addFromPool: true,
                    addEclassIrdi: true,
                    addPresetNames: bufferKeys.Item1,
                    addPresetKeyLists: bufferKeys.Item2,
                    jumpLambda: (kl) =>
                {
                    return(new AnyUiLambdaActionNavigateTo(AdminShell.Reference.CreateNew(kl)));
                });
            }
        }
Exemplo n.º 2
0
            public static Tuple <string[], AdminShell.KeyList[]> PreparePresetsForListKeys(
                CopyPasteBuffer cpb, string label = "Paste")
            {
                // add from Copy Buffer
                AdminShell.KeyList bufferKey = null;
                if (cpb != null && cpb.Valid && cpb.Items != null && cpb.Items.Count == 1)
                {
                    if (cpb.Items[0] is CopyPasteItemIdentifiable cpbi && cpbi.entity?.identification != null)
                    {
                        bufferKey = AdminShell.KeyList.CreateNew(
                            new AdminShell.Key("" + cpbi.entity.GetElementName(), false,
                                               cpbi.entity.identification.idType, cpbi.entity.identification.id));
                    }

                    if (cpb.Items[0] is CopyPasteItemSubmodel cpbsm && cpbsm.sm?.GetSemanticKey() != null)
                    {
                        bufferKey = AdminShell.KeyList.CreateNew(cpbsm.sm.GetSemanticKey());
                    }

                    if (cpb.Items[0] is CopyPasteItemSME cpbsme && cpbsme.sme != null &&
                        cpbsme.env.Submodels != null)
                    {
                        // index parents for ALL Submodels -> parent for our SME shall be set by this ..
                        foreach (var sm in cpbsme.env?.Submodels)
                        {
                            sm?.SetAllParents();
                        }

                        // collect buffer list
                        bufferKey = new AdminShell.KeyList();
                        cpbsme.sme.CollectReferencesByParent(bufferKey);
                    }
                }

                // result
                return(new Tuple <string[], AdminShell.KeyList[]>(
                           (bufferKey == null) ? null : new[] { label },
                           (bufferKey == null) ? null : new[] { bufferKey }
                           ));
            }
Exemplo n.º 3
0
        public void DispSmeCutCopyPasteHelper(
            AnyUiPanel stack,
            ModifyRepo repo,
            AdminShell.AdministrationShellEnv env,
            AdminShell.Referable parentContainer,
            CopyPasteBuffer cpbInternal,
            AdminShell.SubmodelElementWrapper wrapper,
            AdminShell.SubmodelElement sme,
            string label = "Buffer:")
        {
            // access
            if (parentContainer == null || cpbInternal == null || sme == null)
            {
                return;
            }

            // use an action
            this.AddAction(
                stack, label,
                new[] { "Cut", "Copy", "Paste above", "Paste below", "Paste into" }, repo,
                actionTags: new[] { "aas-elem-cut", "aas-elem-copy", "aas-elem-paste-above",
                                    "aas-elem-paste-below", "aas-elem-paste-into" },
                action: (buttonNdx) =>
            {
                if (buttonNdx == 0 || buttonNdx == 1)
                {
                    // store info
                    cpbInternal.Clear();
                    cpbInternal.Valid     = true;
                    cpbInternal.Duplicate = buttonNdx == 1;
                    AdminShell.EnumerationPlacmentBase placement = null;
                    if (parentContainer is AdminShell.IEnumerateChildren enc)
                    {
                        placement = enc.GetChildrenPlacement(sme);
                    }
                    cpbInternal.Items = new ListOfCopyPasteItem(
                        new CopyPasteItemSME(env, parentContainer, wrapper, sme, placement));
                    cpbInternal.CopyToClipboard(context, cpbInternal.Watermark);

                    // special case?

                    // user feedback
                    Log.Singleton.Info(
                        StoredPrint.Color.Blue,
                        "Stored SubmodelElement '{0}'({1}) to internal buffer.{2}", "" + sme.idShort,
                        "" + sme?.GetElementName(),
                        cpbInternal.Duplicate
                                ? " Paste will duplicate."
                                : " Paste will cut at original position.");
                }

                if (buttonNdx == 2 || buttonNdx == 3 || buttonNdx == 4)
                {
                    // which buffer?
                    var cbdata = context?.ClipboardGet();
                    var cpb    = cpbInternal.CheckIfUseExternalCopyPasteBuffer(cbdata);

                    // content?
                    if (!cpb.ContentAvailable)
                    {
                        this.context?.MessageBoxFlyoutShow(
                            "No sufficient infomation in internal paste buffer or external clipboard.",
                            "Copy & Paste",
                            AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Error);
                        return(new AnyUiLambdaActionNone());
                    }

                    // uniform?
                    if (!cpb.Items.AllOfElementType <CopyPasteItemSME>())
                    {
                        this.context?.MessageBoxFlyoutShow(
                            "No (valid) information for SubmodelElements in copy/paste buffer.",
                            "Copy & Paste",
                            AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Information);
                        return(new AnyUiLambdaActionNone());
                    }

                    // user feedback
                    Log.Singleton.Info($"Pasting {cpb.Items.Count} SubmodelElements from paste buffer");

                    // loop over items
                    object nextBusObj = null;
                    foreach (var it in cpb.Items)
                    {
                        // access
                        var item = it as CopyPasteItemSME;
                        if (item?.sme == null || item.wrapper == null ||
                            (!cpb.Duplicate && item?.parentContainer == null))
                        {
                            Log.Singleton.Error("When pasting SME, an element was invalid.");
                            continue;
                        }

                        // apply info
                        var smw2   = new AdminShell.SubmodelElementWrapper(item.sme, shallowCopy: false);
                        nextBusObj = smw2.submodelElement;

                        // insertation depends on parent container
                        if (buttonNdx == 2)
                        {
                            if (parentContainer is AdminShell.Submodel pcsm && wrapper != null)
                            {
                                this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                    pcsm.submodelElements, smw2, wrapper);
                            }

                            if (parentContainer is AdminShell.SubmodelElementCollection pcsmc &&
                                wrapper != null)
                            {
                                this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                    pcsmc.value, smw2, wrapper);
                            }

                            if (parentContainer is AdminShell.Entity pcent &&
                                wrapper != null)
                            {
                                this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                    pcent.statements, smw2, wrapper);
                            }

                            if (parentContainer is AdminShell.AnnotatedRelationshipElement pcarel &&
                                wrapper != null)
                            {
                                this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                    pcarel.annotations, smw2, wrapper);
                            }

                            // TODO (Michael Hoffmeister, 2020-08-01): Operation complete?
                            if (parentContainer is AdminShell.Operation pcop && wrapper?.submodelElement != null)
                            {
                                var place = pcop.GetChildrenPlacement(wrapper.submodelElement) as
                                            AdminShell.Operation.EnumerationPlacmentOperationVariable;
                                if (place?.OperationVariable != null)
                                {
                                    var op   = new AdminShell.OperationVariable();
                                    op.value = smw2;
                                    this.AddElementInListBefore <AdminShell.OperationVariable>(
                                        pcop[place.Direction], op, place.OperationVariable);
                                    nextBusObj = op;
                                }
                            }
                        }
Exemplo n.º 4
0
            public static CopyPasteBuffer FromClipboardString(string cps)
            {
                // access
                if (cps == null)
                {
                    return(null);
                }
                cps = cps.Trim();
                if (cps.Length < 1)
                {
                    return(null);
                }

                // quite likely to crash
                try
                {
                    // be very straight for allowed formats
                    var isSingleObject = cps.StartsWith("{");
                    var isArrayObject  = cps.StartsWith("[");

                    // try simple way
                    if (isSingleObject)
                    {
                        // TODO (MIHO, 2021-06-22): think of converting Referable to IAasElement
                        var obj = AdminShellSerializationHelper.DeserializeFromJSON <AdminShell.Referable>(cps);

                        // try fake a copy paste item (order matters!)
                        var cpi = CopyPasteItemBase.FactoryConvertFrom(obj);
                        if (cpi != null)
                        {
                            return new CopyPasteBuffer()
                                   {
                                       Valid          = true,
                                       ExternalSource = true,
                                       Duplicate      = true,
                                       Items          = new ListOfCopyPasteItem(cpi)
                                   }
                        }
                        ;
                    }
                    else
                    if (isArrayObject)
                    {
                        // make array of object
                        var objarr = AdminShellSerializationHelper
                                     .DeserializePureObjectFromJSON <List <AdminShell.Referable> >(cps);
                        if (objarr != null)
                        {
                            // overall structure
                            var cpb = new CopyPasteBuffer()
                            {
                                Valid          = true,
                                ExternalSource = true,
                                Duplicate      = true,
                                Items          = new ListOfCopyPasteItem()
                            };

                            // single items
                            foreach (var obj in objarr)
                            {
                                var cpi = CopyPasteItemBase.FactoryConvertFrom(obj);
                                if (cpi != null)
                                {
                                    cpb.Items.Add(cpi);
                                }
                            }

                            // be picky with validity
                            if (cpb.Items.Count > 0)
                            {
                                return(cpb);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Singleton.Error(ex, "when trying to decode clipboad text");
                }

                // ups
                return(null);
            }
Exemplo n.º 5
0
        public void DispMultiElementCutCopyPasteHelper(
            AnyUiPanel stack,
            ModifyRepo repo,
            AdminShell.AdministrationShellEnv env,
            AdminShell.IAasElement parentContainer,
            CopyPasteBuffer cpb,
            ListOfVisualElementBasic entities,
            string label = "Buffer:")
        {
            // access
            if (parentContainer == null || cpb == null || entities == null)
            {
                return;
            }

            // use an action
            this.AddAction(
                stack, label,
                new[] { "Cut", "Copy" }, repo,
                actionTags: new[] { "aas-multi-elem-cut", "aas-multi-elem-copy" },
                action: (buttonNdx) =>
            {
                if (buttonNdx == 0 || buttonNdx == 1)
                {
                    // store info
                    cpb.Clear();
                    cpb.Valid     = true;
                    cpb.Duplicate = buttonNdx == 1;

                    cpb.Items = new ListOfCopyPasteItem();
                    foreach (var el in entities)
                    {
                        if (el is VisualElementSubmodelElement vesme &&
                            parentContainer is AdminShell.Referable pcref)
                        {
                            var sme = vesme.theWrapper?.submodelElement;
                            AdminShell.EnumerationPlacmentBase placement = null;
                            if (parentContainer is AdminShell.IEnumerateChildren enc)
                            {
                                placement = enc.GetChildrenPlacement(sme);
                            }
                            cpb.Items.Add(new CopyPasteItemSME(env, pcref,
                                                               vesme.theWrapper, sme, placement));
                        }

                        if (el is VisualElementSubmodelRef vesmr)
                        {
                            cpb.Items.Add(new CopyPasteItemSubmodel(parentContainer, vesmr.theSubmodelRef,
                                                                    vesmr.theSubmodelRef, vesmr.theSubmodel));
                        }

                        if (el is VisualElementSubmodel vesm)
                        {
                            cpb.Items.Add(new CopyPasteItemSubmodel(parentContainer, vesm.theSubmodel,
                                                                    null, vesm.theSubmodel));
                        }

                        if (el is VisualElementOperationVariable veopv &&
                            parentContainer is AdminShell.Referable pcref2)
                        {
                            if (veopv.theOpVar?.value != null)
                            {
                                cpb.Items.Add(new CopyPasteItemSME(env, pcref2,
                                                                   veopv.theOpVar.value, veopv.theOpVar.value?.submodelElement));
                            }
                        }

                        if (el is VisualElementConceptDescription vecd)
                        {
                            cpb.Items.Add(new CopyPasteItemIdentifiable(parentContainer, vecd.theCD));
                        }

                        if (el is VisualElementAsset veass)
                        {
                            cpb.Items.Add(new CopyPasteItemIdentifiable(parentContainer, veass.theAsset));
                        }

                        if (el is VisualElementAdminShell veaas)
                        {
                            cpb.Items.Add(new CopyPasteItemIdentifiable(parentContainer, veaas.theAas));
                        }
                    }
        //
        // Helper functions
        //

        public void DispSmeCutCopyPasteHelper(
            Panel stack, ModifyRepo repo,
            AdminShell.AdministrationShellEnv env,
            AdminShell.Referable parentContainer,
            CopyPasteBuffer cpb,
            AdminShell.SubmodelElementWrapper wrapper,
            AdminShell.SubmodelElement sme,
            string label = "Buffer:")
        {
            // access
            if (parentContainer == null || cpb == null || sme == null)
            {
                return;
            }

            // use an action
            this.AddAction(
                stack, label,
                new[] { "Cut", "Copy", "Paste above", "Paste below", "Paste into" }, repo,
                (buttonNdx) =>
            {
                if (buttonNdx == 0 || buttonNdx == 1)
                {
                    // store info
                    cpb.valid     = true;
                    cpb.duplicate = buttonNdx == 1;
                    cpb.item      = new CopyPasteItemSME(env, parentContainer, wrapper, sme);

                    // user feedback
                    AasxPackageExplorer.Log.Singleton.Info(
                        StoredPrint.Color.Blue,
                        "Stored SubmodelElement '{0}'({1}) to internal buffer.{2}", "" + sme.idShort,
                        "" + sme?.GetElementName(),
                        cpb.duplicate
                                ? " Paste will duplicate."
                                : " Paste will cut at original position.");
                }

                if (buttonNdx == 2 || buttonNdx == 3 || buttonNdx == 4)
                {
                    // present
                    var item = cpb?.item as CopyPasteItemSME;
                    if (!cpb.valid || item?.sme == null || item?.wrapper == null ||
                        item?.parentContainer == null)
                    {
                        if (this.flyoutProvider != null)
                        {
                            this.flyoutProvider.MessageBoxFlyoutShow(
                                "No (valid) information for SubmodelElements in copy/paste buffer.",
                                "Copy & Paste",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        return(new ModifyRepo.LambdaActionNone());
                    }

                    // user feedback
                    AasxPackageExplorer.Log.Singleton.Info(
                        "Pasting buffer with SubmodelElement '{0}'({1}) to internal buffer.",
                        "" + item.sme.idShort, "" + item.sme.GetElementName());

                    // apply info
                    var smw2 = new AdminShell.SubmodelElementWrapper(item.sme, shallowCopy: false);

                    // insertation depends on parent container
                    if (buttonNdx == 2)
                    {
                        if (parentContainer is AdminShell.Submodel pcsm && wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcsm.submodelElements, smw2, wrapper);
                        }

                        if (parentContainer is AdminShell.SubmodelElementCollection pcsmc &&
                            wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcsmc.value, smw2, wrapper);
                        }

                        if (parentContainer is AdminShell.Entity pcent &&
                            wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcent.statements, smw2, wrapper);
                        }

                        if (parentContainer is AdminShell.AnnotatedRelationshipElement pcarel &&
                            wrapper != null)
                        {
                            this.AddElementInListBefore <AdminShell.SubmodelElementWrapper>(
                                pcarel.annotations, smw2, wrapper);
                        }

                        // TODO (Michael Hoffmeister, 2020-08-01): Operation mssing here?
                    }