示例#1
0
 public void Start(
     LogInstance log,
     AdminShellPackageEnv thePackage,
     AdminShell.Submodel theSubmodel,
     AasxPluginDocumentShelf.DocumentShelfOptions theOptions,
     PluginEventStack eventStack)
 {
     this.Log           = log;
     this.thePackage    = thePackage;
     this.theSubmodel   = theSubmodel;
     this.theOptions    = theOptions;
     this.theEventStack = eventStack;
 }
示例#2
0
        /// <summary>
        /// Create a set of minimal options
        /// </summary>
        public static DocumentShelfOptions CreateDefault()
        {
            var opt = new DocumentShelfOptions();

            // use pre-definitions
            var preDefLib = new AasxPredefinedConcepts.DefinitionsVDI2770();
            var preDefs   = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770(preDefLib);

            opt.SemIdDocumentation = preDefs.SM_VDI2770_Documentation?.semanticId?.GetAsExactlyOneKey();
            if (opt.SemIdDocumentation != null)
            {
                opt.AllowSubmodelSemanticIds.Add(opt.SemIdDocumentation);
            }

            opt.SemIdDocument                     = preDefs.CD_VDI2770_Document?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDocumentIdValue              = preDefs.CD_VDI2770_DocumentIdValue?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDocumentClassId              = preDefs.CD_VDI2770_DocumentClassId?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDocumentClassName            = preDefs.CD_VDI2770_DocumentClassName?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDocumentClassificationSystem =
                preDefs.CD_VDI2770_DocumentClassificationSystem?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdOrganizationName         = preDefs.CD_VDI2770_OrganizationName?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdOrganizationOfficialName =
                preDefs.CD_VDI2770_OrganizationOfficialName?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDocumentVersion        = preDefs.CD_VDI2770_DocumentVersion?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdLanguage               = preDefs.CD_VDI2770_Language?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdTitle                  = preDefs.CD_VDI2770_Title?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDate                   = preDefs.CD_VDI2770_Date?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDocumentVersionIdValue =
                preDefs.CD_VDI2770_DocumentVersionIdValue?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDigitalFile = preDefs.CD_VDI2770_DigitalFile?.GetCdReference()?.GetAsExactlyOneKey();

            opt.FormVdi2770 = CreateVdi2770TemplateDesc(opt);

            /* new, Birgit */
            opt.SemIdDocumentId          = preDefs.CD_VDI2770_DocumentId?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdIsPrimaryDocumentId =
                preDefs.CD_VDI2770_IsPrimaryDocumentId?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDocumentVersionId = preDefs.CD_VDI2770_DocumentVersionId?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdSummary           = preDefs.CD_VDI2770_Summary?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdKeywords          = preDefs.CD_VDI2770_Keywords?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdStatusValue       = preDefs.CD_VDI2770_StatusValue?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdRole             = preDefs.CD_VDI2770_Role?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdDomainId         = preDefs.CD_VDI2770_DomainId?.GetCdReference()?.GetAsExactlyOneKey();
            opt.SemIdReferencedObject = preDefs.CD_VDI2770_ReferencedObject?.GetCdReference()?.GetAsExactlyOneKey();

            // for V11, very little
            opt.AllowSubmodelSemanticIds.Add(
                AasxPredefinedConcepts.VDI2770v11.Static.SM_ManufacturerDocumentation.GetSemanticKey());

            return(opt);
        }
        /// <summary>
        /// Create a set of minimal options
        /// </summary>
        public static DocumentShelfOptions CreateDefault()
        {
            var opt = new DocumentShelfOptions();

            //
            //  basic record
            //

            var rec = new DocumentShelfOptionsRecord();

            rec.ForceVersion = DocumentEntity.SubmodelVersion.Default;
            opt.Records.Add(rec);

            // V1.0
            var preDefs = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770(
                new AasxPredefinedConcepts.DefinitionsVDI2770());
            var semIdDocumentation = preDefs.SM_VDI2770_Documentation?.semanticId?.GetAsExactlyOneKey();

            if (semIdDocumentation != null)
            {
                rec.AllowSubmodelSemanticId.Add(semIdDocumentation);
            }

            // V1.1
            rec.AllowSubmodelSemanticId.Add(
                AasxPredefinedConcepts.VDI2770v11.Static.SM_ManufacturerDocumentation.GetSemanticKey());

            //
            // further models for CAD
            //

            rec = new DocumentShelfOptionsRecord()
            {
                UsageInfo = "Some manufacturers use manufacturer documentation to provide models for " +
                            "Computer Aided Design (CAD) and further engineering tools."
            };
            opt.Records.Add(rec);

            rec.AllowSubmodelSemanticId.Add(new AdminShellV20.Key(
                                                AdminShell.Key.Submodel, false, AdminShell.Identification.IRI,
                                                "smart.festo.com/AAS/Submodel/ComputerAidedDesign/1/0"));

            return(opt);
        }
示例#4
0
        /// <summary>
        /// Create a default template description for VDI2770 based on the SemanticIds from the <c>options</c>
        /// </summary>
        /// <param name="opt"></param>
        /// <returns></returns>
        public static FormDescSubmodelElementCollection CreateVdi2770TemplateDesc(DocumentShelfOptions opt)
        {
            if (opt == null)
            {
                return(null);
            }

            var semConfig = DocuShelfSemanticConfig.CreateDefault();

            // DocumentItem

            var descDoc = new FormDescSubmodelElementCollection(
                "Document", FormMultiplicity.ZeroToMany, semConfig.SemIdDocument, "Document{0:00}",
                "Each document item comprises a set of elements describing the information of a VDI 2770 Document " +
                "with directly attached DocumentVersion.");

            // Document

            descDoc.Add(new FormDescProperty(
                            "DocumentId", FormMultiplicity.One, semConfig.SemIdDocumentId, "DocumentId",
                            "The combination of DocumentId and DocumentVersionId shall be unqiue."));

            descDoc.Add(new FormDescProperty(
                            "IsPrimary", FormMultiplicity.One, semConfig.SemIdIsPrimaryDocumentId, "IsPrimary",
                            "True, if primary document id for the document."));

            var descDocClass = new FormDescProperty(
                "ClassId", FormMultiplicity.One, semConfig.SemIdDocumentClassId, "ClassId",
                "VDI2770 ClassId of the document.");

            var cbList = new List <string>();
            var vlList = new List <string>();

            foreach (var dc in (DefinitionsVDI2770.Vdi2770DocClass[])Enum.GetValues(
                         typeof(DefinitionsVDI2770.Vdi2770DocClass)))
            {
                if ((int)dc == 0)
                {
                    continue;
                }
                cbList.Add("" + DefinitionsVDI2770.GetDocClass(dc) + " - " + DefinitionsVDI2770.GetDocClassName(dc));
                vlList.Add("" + DefinitionsVDI2770.GetDocClass(dc));
            }

            descDocClass.comboBoxChoices        = cbList.ToArray();
            descDocClass.valueFromComboBoxIndex = vlList.ToArray();
            descDoc.Add(descDocClass);

            var descDocName = new FormDescProperty(
                "ClassName", FormMultiplicity.One, semConfig.SemIdDocumentClassName, "ClassName",
                "VDI2770 ClassName of the document. This property is automaticall computed based on ClassId.",
                isReadOnly: true);

            descDocName.SlaveOfIdShort = "ClassId";

            descDocName.valueFromMasterValue = new Dictionary <string, string>();
            foreach (var dc in (DefinitionsVDI2770.Vdi2770DocClass[])Enum.GetValues(
                         typeof(DefinitionsVDI2770.Vdi2770DocClass)))
            {
                descDocName.valueFromMasterValue.Add(
                    DefinitionsVDI2770.GetDocClass(dc), DefinitionsVDI2770.GetDocClassName(dc));
            }

            descDoc.Add(descDocName);

            descDoc.Add(
                new FormDescProperty(
                    "ClassificationSystem", FormMultiplicity.One, semConfig.SemIdDocumentClassificationSystem,
                    "ClassificationSystem",
                    "This property is always set to VDI2770:2018", isReadOnly: true, presetValue: "VDI2770:2018"));

            descDoc.Add(new FormDescProperty(
                            "ReferencedObject", FormMultiplicity.One, semConfig.SemIdReferencedObject, "ReferencedObject",
                            "Reference to Asset or Entity, on which the Document is related to."));

            // DocumentVersion

            var descDocVer = new FormDescSubmodelElementCollection(
                "DocumentVersion", FormMultiplicity.OneToMany, semConfig.SemIdDocumentVersion, "DocumentVersion",
                "VDI2770 allows for multiple DocumentVersions for a document to be delivered.");

            descDoc.Add(descDocVer);

            descDocVer.Add(new FormDescProperty(
                               "DocumentVersionId", FormMultiplicity.One, semConfig.SemIdDocumentVersionIdValue, "DocumentVersionId",
                               "The combination of DocumentId and DocumentVersionId shall be unqiue."));

            descDocVer.Add(new FormDescProperty(
                               "Languages", FormMultiplicity.ZeroToMany, semConfig.SemIdLanguage, "Language{0}",
                               "List of languages used in the DocumentVersion. For most cases, " +
                               "at least one language shall be given."));

            descDocVer.Add(new FormDescMultiLangProp(
                               "Title", FormMultiplicity.One, semConfig.SemIdTitle, "Title",
                               "Language dependent title of the document."));

            descDocVer.Add(new FormDescMultiLangProp(
                               "Summary", FormMultiplicity.One, semConfig.SemIdSummary, "Summary",
                               "Language dependent summary of the document."));

            descDocVer.Add(new FormDescMultiLangProp(
                               "Keywords", FormMultiplicity.One, semConfig.SemIdKeywords, "Keywords",
                               "Language dependent keywords of the document."));

            descDocVer.Add(new FormDescFile(
                               "DigitalFile", FormMultiplicity.OneToMany, semConfig.SemIdDigitalFile, "DigitalFile{0:00}",
                               "Digital file, which represents the Document and DocumentVersion. " +
                               "A PDF/A format is required for textual representations."));

            descDocVer.Add(new FormDescProperty(
                               "SetDate", FormMultiplicity.One, semConfig.SemIdDate, "SetDate",
                               "Date when the document was introduced into the AAS or set to the status. Format is YYYY-MM-dd."));

            var descStatus = new FormDescProperty(
                "StatusValue", FormMultiplicity.One, semConfig.SemIdStatusValue, "StatusValue",
                "Each document version represents a point in time in the document life cycle. " +
                "This status value refers to the milestones in the document life cycle. " +
                "The following two statuses should be used for the application of this guideline: " +
                "InReview (under review), Released (released).");

            descDocVer.Add(descStatus);
            descStatus.comboBoxChoices = new[] { "InReview", "Released" };

            var descRole = new FormDescProperty(
                "Role", FormMultiplicity.One, semConfig.SemIdRole, "Role",
                "Define a role for the organisation according to the following selection list.");

            descDocVer.Add(descRole);
            descRole.comboBoxChoices = new[] { "Author", "Customer", "Supplier", "Manufacturer", "Responsible" };

            descDocVer.Add(new FormDescProperty(
                               "OrganizationName", FormMultiplicity.One, semConfig.SemIdOrganizationName, "OrganizationName",
                               "Common name for the organisation."));

            descDocVer.Add(new FormDescProperty(
                               "OrganizationOfficialName", FormMultiplicity.One, semConfig.SemIdOrganizationOfficialName,
                               "OrganizationOfficialName",
                               "Official name for the organisation (which might be longer or include legal information)."));

            return(descDoc);
        }
示例#5
0
        private void ButtonTabPanels_Click(object sender, RoutedEventArgs e)
        {
            if (sender == ButtonCreateDoc)
            {
                // show the edit panel
                OuterTabControl.SelectedItem = TabPanelEdit;
                ButtonAddUpdateDoc.Content   = "Add";

                //// TODO (MIHO, 2020-09-29): if the V1.1 template works and is adopted, the old
                //// V1.0 shall be removed completely (over complicated) */
                //// make a template description for the content (remeber it)
                var desc = theOptions.FormVdi2770;
                if (desc == null)
                {
                    desc = DocumentShelfOptions.CreateVdi2770TemplateDesc(theOptions);
                }

                // latest version (from resources)
                if (this.CheckBoxLatestVersion.IsChecked == true)
                {
                    desc = DocumentShelfOptions.CreateVdi2770v11TemplateDesc();
                }

                this.currentFormDescription = desc;
                formInUpdateMode            = false;
                updateSourceElements        = null;

                // take over existing data
                this.currentFormInst = new FormInstanceSubmodelElementCollection(null, currentFormDescription);
                this.currentFormInst.PresetInstancesBasedOnSource(updateSourceElements);
                this.currentFormInst.outerEventStack = theEventStack;

                // bring it to the panel
                var elementsCntl = new FormListOfDifferentControl();
                elementsCntl.ShowHeader  = false;
                elementsCntl.DataContext = this.currentFormInst;
                ScrollViewerForm.Content = elementsCntl;
            }

            if (sender == ButtonAddUpdateDoc)
            {
                // add
                if (this.currentFormInst != null && this.currentFormDescription != null &&
                    thePackage != null &&
                    theOptions != null && theOptions.SemIdDocument != null &&
                    theSubmodel != null)
                {
                    // on this level of the hierarchy, shall a new SMEC be created or shall
                    // the existing source of elements be used?
                    AdminShell.SubmodelElementWrapperCollection currentElements = null;
                    if (formInUpdateMode && updateSourceElements != null)
                    {
                        currentElements = updateSourceElements;
                    }
                    else
                    {
                        currentElements = new AdminShell.SubmodelElementWrapperCollection();
                    }

                    // create a sequence of SMEs
                    try
                    {
                        this.currentFormInst.AddOrUpdateDifferentElementsToCollection(
                            currentElements, thePackage, addFilesToPackage: true);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "when adding Document");
                    }

                    // the InstSubmodel, which started the process, should have a "fresh" SMEC available
                    // make it unique in the Documentens Submodel
                    var newSmc = this.currentFormInst?.sme as AdminShell.SubmodelElementCollection;

                    // if not update, put them into the Document's Submodel
                    if (!formInUpdateMode && currentElements != null && newSmc != null)
                    {
                        // make newSmc unique in the cotext of the Submodel
                        FormInstanceHelper.MakeIdShortUnique(theSubmodel.submodelElements, newSmc);

                        // add the elements
                        newSmc.value = currentElements;

                        // add the whole SMC
                        theSubmodel.Add(newSmc);
                    }

#if __may_be_not__
                    // save directly to ensure consistency
                    try
                    {
                        if (thePackage.Filename != null)
                        {
                            thePackage.SaveAs(thePackage.Filename);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (theLogger != null)
                        {
                            theLogger.Log(
                                $"Saving package {thePackage.Filename} failed for adding Document " +
                                $"and gave: {ex.Message}");
                        }
                    }
#endif
                }
                else
                {
                    Log.Error("Preconditions for adding Document not met.");
                }

                // change back
                OuterTabControl.SelectedItem = TabPanelList;

                // re-display
                ParseSubmodelToListItems(
                    this.theSubmodel, this.theOptions, theViewModel.TheSelectedDocClass,
                    theViewModel.TheSelectedLanguage, theViewModel.TheSelectedListType);

                // re-display also in Explorer
                var evt = new AasxPluginResultEventRedrawAllElements();
                if (theEventStack != null)
                {
                    theEventStack.PushEvent(evt);
                }
            }

            if (sender == ButtonCancel)
            {
                OuterTabControl.SelectedItem = TabPanelList;
            }

            if (sender == ButtonFixCDs)
            {
                // check if CDs are present
                var theDefs = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770(
                    new AasxPredefinedConcepts.DefinitionsVDI2770());
                var theCds = theDefs.GetAllReferables().Where(
                    (rf) => { return(rf is AdminShell.ConceptDescription); }).ToList();

                // v11
                if (CheckBoxLatestVersion.IsChecked == true)
                {
                    theCds = AasxPredefinedConcepts.VDI2770v11.Static.GetAllReferables().Where(
                        (rf) => { return(rf is AdminShell.ConceptDescription); }).ToList();
                }

                if (theCds.Count < 1)
                {
                    Log.Error(
                        "Not able to find appropriate ConceptDescriptions in pre-definitions. " +
                        "Aborting.");
                    return;
                }

                // check for Environment
                var env = this.thePackage?.AasEnv;
                if (env == null)
                {
                    Log.Error(
                        "Not able to access AAS environment for set of Submodel's ConceptDescriptions. Aborting.");
                    return;
                }

                // be safe?
                if (MessageBoxResult.Yes != MessageBox.Show(
                        "Add missing ConceptDescriptions to the AAS?", "Question",
                        MessageBoxButton.YesNo, MessageBoxImage.Warning))
                {
                    return;
                }

                // ok, check
                int nr = 0;
                foreach (var x in theCds)
                {
                    var cd = x as AdminShell.ConceptDescription;
                    if (cd == null || cd.identification == null)
                    {
                        continue;
                    }
                    var cdFound = env.FindConceptDescription(cd.identification);
                    if (cdFound != null)
                    {
                        continue;
                    }
                    // ok, add
                    var newCd = new AdminShell.ConceptDescription(cd);
                    env.ConceptDescriptions.Add(newCd);
                    nr++;
                }

                // ok
                Log.Info("In total, {0} ConceptDescriptions were added to the AAS environment.", nr);
            }

            if (sender == ButtonCreateEntity)
            {
                // show the edit panel
                OuterTabControl.SelectedItem = TabPanelEntity;
            }

            if (sender == ButtonCancelEntity)
            {
                OuterTabControl.SelectedItem = TabPanelList;
            }

            if (sender == ButtonAddEntity &&
                this.theSubmodel != null &&
                TextBoxEntityIdShort.Text.Trim().HasContent())
            {
                // add entity
                this.theSubmodel.SmeForWrite.CreateSMEForCD <AdminShell.Entity>(
                    AasxPredefinedConcepts.VDI2770v11.Static.CD_DocumentedEntity,
                    idShort: "" + TextBoxEntityIdShort.Text.Trim(),
                    addSme: true);

                // switch back
                OuterTabControl.SelectedItem = TabPanelList;

                // re-display also in Explorer
                var evt = new AasxPluginResultEventRedrawAllElements();
                if (theEventStack != null)
                {
                    theEventStack.PushEvent(evt);
                }
            }
        }
示例#6
0
        private void DocumentEntity_MenuClick(DocumentEntity e, string menuItemHeader, object tag)
        {
            // first check
            if (e == null || menuItemHeader == null)
            {
                return;
            }

            // what to do?
            if (tag == null && menuItemHeader == "Edit" && e.SourceElementsDocument != null &&
                e.SourceElementsDocumentVersion != null)
            {
                // show the edit panel
                OuterTabControl.SelectedItem = TabPanelEdit;
                ButtonAddUpdateDoc.Content   = "Update";

                // make a template description for the content (remeber it)
                formInUpdateMode     = true;
                updateSourceElements = e.SourceElementsDocument;

                var desc = theOptions.FormVdi2770;
                if (desc == null)
                {
                    desc = DocumentShelfOptions.CreateVdi2770TemplateDesc(theOptions);
                }

                // latest version (from resources)
                if (e.SmVersion == DocumentEntity.SubmodelVersion.V11)
                {
                    desc = DocumentShelfOptions.CreateVdi2770v11TemplateDesc();
                }

                this.currentFormDescription = desc;

                // take over existing data
                this.currentFormInst = new FormInstanceSubmodelElementCollection(null, currentFormDescription);
                this.currentFormInst.PresetInstancesBasedOnSource(updateSourceElements);
                this.currentFormInst.outerEventStack = theEventStack;

                // bring it to the panel
                var elementsCntl = new FormListOfDifferentControl();
                elementsCntl.ShowHeader  = false;
                elementsCntl.DataContext = this.currentFormInst;
                ScrollViewerForm.Content = elementsCntl;

#if not_yet
                this.currentTemplateDescription = new AasTemplateDescListOfElement(desc);
                this.currentTemplateDescription.ClearDynamicData();
                this.currentTemplateDescription.PresetInstancesBasedOnSource(updateSourceElements);

                // bring it to the panel
                var elementsCntl = new AasTemplateListOfElementControl();
                elementsCntl.DataContext = this.currentTemplateDescription;
                ScrollViewerForm.Content = elementsCntl;
#endif
                // OK
                return;
            }

            if (tag == null && menuItemHeader == "Delete" && e.SourceElementsDocument != null &&
                e.SourceElementsDocumentVersion != null && theSubmodel?.submodelElements != null && theOptions != null)
            {
                // the source elements need to match a Document
                foreach (var smcDoc in
                         theSubmodel.submodelElements.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                             theOptions?.SemIdDocument))
                {
                    if (smcDoc?.value == e.SourceElementsDocument)
                    {
                        // identify as well the DocumentVersion
                        // (convert to List() because of Count() below)
                        var allVers =
                            e.SourceElementsDocument.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                                theOptions?.SemIdDocumentVersion).ToList();
                        foreach (var smcVer in allVers)
                        {
                            if (smcVer?.value == e.SourceElementsDocumentVersion)
                            {
                                // access
                                if (smcVer == null || smcVer.value == null || smcDoc == null || smcDoc.value == null)
                                {
                                    continue;
                                }

                                // ask back .. the old-fashioned way!
                                if (MessageBoxResult.Yes != MessageBox.Show(
                                        "Delete Document?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning))
                                {
                                    return;
                                }

                                // confirmed! -> delete
                                if (allVers.Count < 2)
                                {
                                    // remove the whole document!
                                    theSubmodel.submodelElements.Remove(smcDoc);
                                }
                                else
                                {
                                    // remove only the document version
                                    e.SourceElementsDocument.Remove(smcVer);
                                }

                                // switch back to docs
                                // change back
                                OuterTabControl.SelectedItem = TabPanelList;

                                // re-display
                                ParseSubmodelToListItems(
                                    this.theSubmodel, this.theOptions, theViewModel.TheSelectedDocClass,
                                    theViewModel.TheSelectedLanguage, theViewModel.TheSelectedListType);

                                // re-display also in Explorer
                                var evt = new AasxPluginResultEventRedrawAllElements();
                                if (theEventStack != null)
                                {
                                    theEventStack.PushEvent(evt);
                                }

                                // OK
                                return;
                            }
                        }

                        // ReSharper enable PossibleMultipleEnumeration
                    }
                }
            }

            // check for a document reference
            if (tag != null && tag is Tuple <DocumentEntity.DocRelationType, AdminShell.Reference> reltup &&
                reltup.Item2 != null && reltup.Item2.Count > 0)
            {
                var evt = new AasxPluginResultEventNavigateToReference();
                evt.targetReference = new AdminShell.Reference(reltup.Item2);
                this.theEventStack.PushEvent(evt);
            }
        }
        private void ButtonTabPanels_Click(object sender, RoutedEventArgs e)
        {
            if (sender == ButtonCreateDoc)
            {
                // show the edit panel
                OuterTabControl.SelectedItem = TabPanelEdit;
                ButtonAddUpdateDoc.Content   = "Add";

                // make a template description for the content (remeber it)
                var desc = theOptions.FormVdi2770;
                if (desc == null)
                {
                    desc = DocumentShelfOptions.CreateVdi2770TemplateDesc(theOptions);
                }

                this.currentFormDescription = desc;
                formInUpdateMode            = false;
                updateSourceElements        = null;

                // take over existing data
                this.currentFormInst = new FormInstanceSubmodelElementCollection(null, currentFormDescription);
                this.currentFormInst.PresetInstancesBasedOnSource(updateSourceElements);

                // bring it to the panel
                var elementsCntl = new FormListOfDifferentControl();
                elementsCntl.ShowHeader  = false;
                elementsCntl.DataContext = this.currentFormInst;
                ScrollViewerForm.Content = elementsCntl;
            }

            if (sender == ButtonAddUpdateDoc)
            {
                // add
                if (this.currentFormInst != null && this.currentFormDescription != null &&
                    thePackage != null &&
                    theOptions != null && theOptions.SemIdDocument != null &&
                    theSubmodel != null)
                {
                    // on this level of the hierarchy, shall a new SMEC be created or shall
                    // the existing source of elements be used?
                    AdminShell.SubmodelElementWrapperCollection currentElements = null;
                    if (formInUpdateMode && updateSourceElements != null)
                    {
                        currentElements = updateSourceElements;
                    }
                    else
                    {
                        currentElements = new AdminShell.SubmodelElementWrapperCollection();
                    }

                    // create a sequence of SMEs
                    try
                    {
                        this.currentFormInst.AddOrUpdateDifferentElementsToCollection(
                            currentElements, thePackage, addFilesToPackage: true);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "when adding Document");
                    }

                    // the InstSubmodel, which started the process, should have a "fresh" SMEC available
                    // make it unique in the Documentens Submodel
                    var newSmc = this.currentFormInst?.sme as AdminShell.SubmodelElementCollection;

                    // if not update, put them into the Document's Submodel
                    if (!formInUpdateMode && currentElements != null && newSmc != null)
                    {
                        // make newSmc unique in the cotext of the Submodel
                        FormInstanceHelper.MakeIdShortUnique(theSubmodel.submodelElements, newSmc);

                        // add the elements
                        newSmc.value = currentElements;

                        // add the whole SMC
                        theSubmodel.Add(newSmc);
                    }

#if __may_be_not__
                    // save directly to ensure consistency
                    try
                    {
                        if (thePackage.Filename != null)
                        {
                            thePackage.SaveAs(thePackage.Filename);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (theLogger != null)
                        {
                            theLogger.Log(
                                $"Saving package {thePackage.Filename} failed for adding Document " +
                                $"and gave: {ex.Message}");
                        }
                    }
#endif
                }
                else
                {
                    Log.Error("Preconditions for adding Document not met.");
                }

                // change back
                OuterTabControl.SelectedItem = TabPanelList;

                // re-display
                ParseSubmodelToListItems(
                    this.theSubmodel, this.theOptions, theViewModel.TheSelectedDocClass,
                    theViewModel.TheSelectedLanguage, theViewModel.TheSelectedListType);

                // re-display also in Explorer
                var evt = new AasxPluginResultEventRedrawAllElements();
                if (theEventStack != null)
                {
                    theEventStack.PushEvent(evt);
                }
            }

            if (sender == ButtonCancel)
            {
                OuterTabControl.SelectedItem = TabPanelList;
            }
        }