private void RecurseIndexSME(AdminShell.Reference currRef, AdminShell.SubmodelElement sme) { // access if (currRef == null || sme == null) { return; } // add to the currRef currRef.Keys.Add( new AdminShell.Key( sme.GetElementName(), false, AdminShell.Identification.IdShort, sme.idShort)); // index var hk = ComputeHashOnReference(currRef); dict.Add(hk, sme); // recurse var childs = (sme as AdminShell.IEnumerateChildren)?.EnumerateChildren(); if (childs != null) { foreach (var sme2 in childs) { RecurseIndexSME(currRef, sme2?.submodelElement); } } // remove from currRef currRef.Keys.RemoveAt(currRef.Keys.Count - 1); }
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; } } }
// // 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? }