public override List <ConvertOfferBase> CheckForOffers(AdminShell.Referable currentReferable) { // collectResults var res = new List <ConvertOfferBase>(); // use pre-definitions var defs = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770( new AasxPredefinedConcepts.DefinitionsVDI2770()); var sm = currentReferable as AdminShell.Submodel; if (sm != null && true == sm.GetSemanticKey()?.Matches(defs.SM_VDI2770_Documentation.GetSemanticKey())) { res.Add(new ConvertOfferDocumentationSg2ToHsu(this, $"Convert Submodel '{"" + sm.idShort}' for Documentation SG2 to HSU")); } // MIHO, 2020-07-31: temporary have code to allow conversion of Festo MCAD / ECAD models as well //// if (sm != null && true == sm.GetSemanticKey()?.Matches("Submodel", false, "IRI", //// "http://smart.festo.com/AAS/Submodel/ComputerAidedDesign/1/0", AdminShell.Key.MatchMode.Relaxed)) //// res.Add(new ConvertOfferDocumentationSg2ToHsu(this, //// $"Convert Submodel '{"" + sm.idShort}' for Documentation SG2 to HSU")); return(res); }
/// <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); }
public override List <ConvertOfferBase> CheckForOffers(AdminShell.Referable currentReferable) { // collectResults var res = new List <ConvertOfferBase>(); // use pre-definitions var defs = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770( new AasxPredefinedConcepts.DefinitionsVDI2770()); var sm = currentReferable as AdminShell.Submodel; if (sm != null && true == sm.GetSemanticKey()?.Matches(defs.SM_VDI2770_Documentation.GetSemanticKey())) { res.Add(new ConvertOfferDocumentationSg2ToV11(this, $"Convert Submodel '{"" + sm.idShort}' for Documentation SG2 (V1.0) to V1.1")); } return(res); }
/// <summary> /// Create a set of minimal options /// </summary> public static DocuShelfSemanticConfig CreateDefault() { var opt = new DocuShelfSemanticConfig(); // use pre-definitions var preDefLib = new AasxPredefinedConcepts.DefinitionsVDI2770(); var preDefs = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770(preDefLib); opt.SemIdDocumentation = preDefs.SM_VDI2770_Documentation?.semanticId?.GetAsExactlyOneKey(); 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(); /* 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(); return(opt); }
public override bool ExecuteOffer(AdminShellPackageEnv package, AdminShell.Referable currentReferable, ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs) { // access var offer = offerBase as ConvertOfferDocumentationSg2ToV11; if (package == null || package.AasEnv == null || currentReferable == null || offer == null) { return(false); } // use pre-definitions var defsSg2 = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770( new AasxPredefinedConcepts.DefinitionsVDI2770()); var defsV11 = AasxPredefinedConcepts.VDI2770v11.Static; // access Submodel (again) var sm = currentReferable as AdminShell.Submodel; if (sm == null || sm.submodelElements == null || true != sm.GetSemanticKey()?.Matches(defsSg2.SM_VDI2770_Documentation.GetSemanticKey())) { /* disable line above to allow more models, such as MCAD/ECAD */ return(false); } // convert in place: detach old SMEs, change semanticId var smcOldSg2 = sm.submodelElements; sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection(); sm.semanticId = new AdminShell.SemanticId(defsV11.SM_ManufacturerDocumentation.GetSemanticKey()); // delete (old) CDs if (deleteOldCDs) { smcOldSg2.RecurseOnSubmodelElements(null, null, (state, parents, current) => { var sme = current; if (sme != null && sme.semanticId != null) { var cd = package.AasEnv.FindConceptDescription(sme.semanticId); if (cd != null) { if (package.AasEnv.ConceptDescriptions.Contains(cd)) { package.AasEnv.ConceptDescriptions.Remove(cd); } } } }); } // add (all) new CDs? if (addNewCDs) { foreach (var rf in defsV11.GetAllReferables()) { if (rf is AdminShell.ConceptDescription) { package.AasEnv.ConceptDescriptions.AddIfNew(new AdminShell.ConceptDescription( rf as AdminShell.ConceptDescription)); } } } // ok, go thru the old == SG2 records foreach (var smcDoc in smcOldSg2.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( defsSg2.CD_VDI2770_Document.GetSingleKey())) { // access if (smcDoc == null || smcDoc.value == null) { continue; } // look immediately for DocumentVersion, as only with this there is a valid List item foreach (var smcVer in smcDoc.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( defsSg2.CD_VDI2770_DocumentVersion.GetSingleKey())) { // access if (smcVer == null || smcVer.value == null) { continue; } // make new V11 Document // Document Item using (var smcV11Doc = AdminShell.SubmodelElementCollection.CreateNew("" + smcDoc.idShort, smcDoc.category, AdminShell.Key.GetFromRef(defsV11.CD_Document.GetCdReference()))) { // Document itself smcV11Doc.description = smcDoc.description; sm.submodelElements.Add(smcV11Doc); // Domain? var s1 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DomainId.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value; var s2 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentId.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value; if (s1 != null || s2 != null) { var smcV11Dom = smcV11Doc.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>( defsV11.CD_DocumentIdDomain, addSme: true); smcV11Dom.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_DocumentDomainId, addSme: true)?.Set("string", "" + s1); smcV11Dom.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_DocumentId, addSme: true)?.Set("string", "" + s2); } // Classification (3 properties) s1 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentClassificationSystem.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value; s2 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentClassId.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value; var s3 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentClassName.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value; if (s2 != null || s3 != null) { var smcV11Cls = smcV11Doc.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>( defsV11.CD_DocumentClassification, addSme: true); smcV11Cls.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_DocumentClassificationSystem, addSme: true)?.Set("string", "" + s1); smcV11Cls.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_DocumentClassId, addSme: true)?.Set("string", "" + s2); smcV11Cls.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_DocumentClassName, addSme: true)?.Set("string", "" + s3); } // Document Version var smcV11Ver = smcV11Doc.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>( defsV11.CD_DocumentVersion, addSme: true); foreach (var o in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_Language.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)) { smcV11Ver.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_Language, addSme: true)?.Set("string", "" + o); } smcV11Ver.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_DocumentVersionIdValue, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentVersionIdValue.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value); var mlp1 = smcVer.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>( defsSg2.CD_VDI2770_Title.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed); if (mlp1 != null) { smcV11Ver.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>( defsV11.CD_Title, addSme: true).value = mlp1.value; } mlp1 = smcVer.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>( defsSg2.CD_VDI2770_Summary.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed); if (mlp1 != null) { smcV11Ver.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>( defsV11.CD_Summary, addSme: true).value = mlp1.value; } mlp1 = smcVer.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>( defsSg2.CD_VDI2770_Keywords.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed); if (mlp1 != null) { smcV11Ver.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>( defsV11.CD_KeyWords, addSme: true).value = mlp1.value; } smcV11Ver.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_Date, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_Date.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value); smcV11Ver.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_LifeCycleStatusValue, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_StatusValue.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value); smcV11Ver.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_Role, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_Role.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value); smcV11Ver.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_OrganizationName, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_OrganizationName.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value); smcV11Ver.value.CreateSMEForCD <AdminShell.Property>( defsV11.CD_OrganizationOfficialName, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_OrganizationOfficialName.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)?.value); foreach (var o in smcVer.value.FindAllSemanticIdAs <AdminShell.File>( defsSg2.CD_VDI2770_DigitalFile.GetSingleKey(), AdminShellV20.Key.MatchMode.Relaxed)) { smcV11Ver.value.CreateSMEForCD <AdminShell.File>( defsV11.CD_DigitalFile, addSme: true)?.Set(o.mimeType, o.value); } } } } // obviously well return(true); }
public override bool ExecuteOffer( AdminShellPackageEnv package, AdminShell.Referable currentReferable, ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs) { // access var offer = offerBase as ConvertOfferDocumentationHsuToSg2; if (package == null || package.AasEnv == null || currentReferable == null || offer == null) { return(false); } // use pre-definitions var defsHsu = new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate.SetOfDocumentation( new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate()); var defsSg2 = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770( new AasxPredefinedConcepts.DefinitionsVDI2770()); // access Submodel (again) var sm = currentReferable as AdminShell.Submodel; if (sm == null || sm.submodelElements == null || true != sm.GetSemanticKey()?.Matches(defsHsu.SM_Document.GetSemanticKey())) { return(false); } // convert in place: detach old SMEs, change semanticId var smcOldHsu = sm.submodelElements; sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection(); sm.semanticId = new AdminShell.SemanticId(defsSg2.SM_VDI2770_Documentation.GetSemanticKey()); // delete (old) CDs if (deleteOldCDs) { smcOldHsu.RecurseOnSubmodelElements(null, null, (state, parents, current) => { var sme = current; if (sme != null && sme.semanticId != null) { var cd = package.AasEnv.FindConceptDescription(sme.semanticId); if (cd != null) { if (package.AasEnv.ConceptDescriptions.Contains(cd)) { package.AasEnv.ConceptDescriptions.Remove(cd); } } } }); } // add (all) new CDs? if (addNewCDs) { foreach (var rf in defsSg2.GetAllReferables()) { if (rf is AdminShell.ConceptDescription) { package.AasEnv.ConceptDescriptions.AddIfNew( new AdminShell.ConceptDescription(rf as AdminShell.ConceptDescription)); } } } // ok, go thru the old == HSU records foreach (var smcSource in smcOldHsu.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( defsHsu.CD_DocumentationItem.GetSingleKey(), AdminShell.Key.MatchMode.Relaxed)) { // access if (smcSource == null || smcSource.value == null) { continue; } // make new SG2 Document + DocumentItem // Document Item using (var smcDoc = AdminShell.SubmodelElementCollection.CreateNew("" + smcSource.idShort, smcSource.category, AdminShell.Key.GetFromRef(defsSg2.CD_VDI2770_Document.GetReference()))) using (var smcDocVersion = AdminShell.SubmodelElementCollection.CreateNew("DocumentVersion", smcSource.category, AdminShell.Key.GetFromRef(defsSg2.CD_VDI2770_DocumentVersion.GetReference()))) { // Document itself smcDoc.description = smcSource.description; // classification var clid = smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_DocumentClassification_ClassId.GetSingleKey())?.value; var clname = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_VDI2770_ClassName.GetSingleKey())?.value; var clsys = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_VDI2770_ClassificationSystem.GetSingleKey())?.value; #if future_structure // as described in the VDI 2770 Submodel template document if (clid.HasContent()) { using (var smcClass = AdminShell.SubmodelElementCollection.CreateNew("DocumentClassification", smcSource.category, AdminShell.Key.GetFromRef(defsSg2.CD_XXX.GetReference()))) { smcDoc.Add(smcClass); smcClass.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassId, addSme: true)?.Set("string", "" + clid); smcClass.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassName, addSme: true)?.Set("string", "" + clname); smcClass.value.CreateSMEForCD <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentClassificationSystem, addSme: true)? .Set("string", "" + clsys); } } #else // current state of code smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassId, addSme: true)?.Set("string", "" + clid); smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassName, addSme: true)?.Set("string", "" + clname); smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassificationSystem, addSme: true)?.Set("string", "" + clsys); #endif // items .. smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentId, addSme: true)?. Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_DocumentId.GetSingleKey())?.value); var idt = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_VDI2770_IdType.GetSingleKey())?.IsTrue(); smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_IsPrimaryDocumentId, addSme: true)?.Set("boolean", (idt.Trim().ToLower() == "primary") ? "True" : "False"); smcDoc.value.CreateSMEForCD <AdminShell.ReferenceElement>(defsSg2.CD_VDI2770_ReferencedObject, addSme: true)?. Set(new AdminShell.Reference()); // DocumentVersion // languages var lcs = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_DocumentVersion_LanguageCode.GetSingleKey())?.value; var lcsa = lcs.Trim().Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); //ReSharper disable ConditionIsAlwaysTrueOrFalse if (lcsa != null && lcsa.Length > 0) { int i = 0; foreach (var lc in lcsa) { var lcc = "" + lc; if (lcc.IndexOf('-') > 0) { lcc = lc.Substring(0, lcc.IndexOf('-')); } smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_Language, idShort: $"Language{(i++):00}", addSme: true)?. Set("string", "" + lcc); } } //ReSharper enable ConditionIsAlwaysTrueOrFalse smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentVersionId, addSme: true)?. Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_DocumentVersionId.GetSingleKey())?.value); var cdSrc = new[] { defsHsu.CD_VDI2770_Title, defsHsu.CD_VDI2770_Summary, defsHsu.CD_VDI2770_Keywords }; var cdDst = new[] { defsSg2.CD_VDI2770_Title, defsSg2.CD_VDI2770_Summary, defsSg2.CD_VDI2770_Keywords }; for (int i = 0; i < 3; i++) { var target = smcDocVersion.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>(cdDst[i], addSme: true); if (target == null) { continue; } var asProp = smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( cdSrc[i].GetSingleKey()); if (asProp != null) { target.Set("en?", "" + asProp.value); } var asMLP = smcSource.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>( cdSrc[i].GetSingleKey()); if (asMLP != null) { target.value = asMLP.value; } } smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_Date, addSme: true)?. Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_VDI2770_SetDate.GetSingleKey())?.value); smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_Role, addSme: true)?. Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_VDI2770_Role.GetSingleKey())?.value); smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_OrganizationName, addSme: true)?.Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_VDI2770_OrganisationName.GetSingleKey())?.value); smcDocVersion.value.CreateSMEForCD <AdminShell.Property>( defsSg2.CD_VDI2770_OrganizationOfficialName, addSme: true)?.Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>( defsHsu.CD_VDI2770_OrganisationOfficialName.GetSingleKey())?.value); // 1 file? var fl = smcSource.value.FindFirstSemanticIdAs <AdminShell.File>(defsHsu.CD_File.GetSingleKey()); smcDocVersion.value.CreateSMEForCD <AdminShell.File>(defsSg2.CD_VDI2770_DigitalFile, addSme: true)?. Set("" + fl?.mimeType, "" + fl?.value); // finally, add smcDoc.Add(smcDocVersion); sm.submodelElements.Add(smcDoc); } } // obviously well return(true); }
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); } } }
public override bool ExecuteOffer(AdminShellPackageEnv package, AdminShell.Referable currentReferable, ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs) { // access var offer = offerBase as ConvertOfferDocumentationSg2ToHsu; if (package == null || package.AasEnv == null || currentReferable == null || offer == null) { return(false); } // use pre-definitions var defsSg2 = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770( new AasxPredefinedConcepts.DefinitionsVDI2770()); var defsHsu = new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate.SetOfDocumentation( new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate()); // access Submodel (again) var sm = currentReferable as AdminShell.Submodel; if (sm == null || sm.submodelElements == null || true != sm.GetSemanticKey()?.Matches(defsSg2.SM_VDI2770_Documentation.GetSemanticKey())) { /* disable line above to allow more models, such as MCAD/ECAD */ return(false); } // convert in place: detach old SMEs, change semanticId var smcOldSg2 = sm.submodelElements; sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection(); sm.semanticId = new AdminShell.SemanticId(defsHsu.SM_Document.GetSemanticKey()); // delete (old) CDs if (deleteOldCDs) { sm.RecurseOnSubmodelElements(null, (state, parents, current) => { var sme = current; if (sme != null && sme.semanticId != null) { var cd = package.AasEnv.FindConceptDescription(sme.semanticId); if (cd != null) { if (package.AasEnv.ConceptDescriptions.Contains(cd)) { package.AasEnv.ConceptDescriptions.Remove(cd); } } } // recurse return(true); }); } // add (all) new CDs? if (addNewCDs) { foreach (var rf in defsHsu.GetAllReferables()) { if (rf is AdminShell.ConceptDescription) { package.AasEnv.ConceptDescriptions.AddIfNew(new AdminShell.ConceptDescription( rf as AdminShell.ConceptDescription)); } } } // ok, go thru the old == SG2 records foreach (var smcDoc in smcOldSg2.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( defsSg2.CD_VDI2770_Document.GetSingleKey())) { // access if (smcDoc == null || smcDoc.value == null) { continue; } // look immediately for DocumentVersion, as only with this there is a valid List item foreach (var smcVer in smcDoc.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( defsSg2.CD_VDI2770_DocumentVersion.GetSingleKey())) { // access if (smcVer == null || smcVer.value == null) { continue; } // make new HSU Document // ReSharper disable once ConvertToUsingDeclaration // Document Item using (var smcHsuDoc = AdminShell.SubmodelElementCollection.CreateNew("" + smcDoc.idShort, smcDoc.category, AdminShell.Key.GetFromRef(defsHsu.CD_DocumentationItem.GetCdReference()))) { // Document itself smcHsuDoc.description = smcDoc.description; sm.submodelElements.Add(smcHsuDoc); // items .. smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentType, addSme: true)?. Set("string", "Single"); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_DomainId, addSme: true)?.Set("string", ""); var b = true == smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_IsPrimaryDocumentId.GetSingleKey())?.IsTrue(); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_IdType, addSme: true)?. Set("string", b ? "Primary" : "Secondary"); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentId, addSme: true)?. Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentDomainId, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Role, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_Role.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_OrganisationId, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_OrganisationName, addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_OrganizationName.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>( defsHsu.CD_VDI2770_OrganisationOfficialName, addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_OrganizationOfficialName.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Description, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentPartId, addSme: true)?. Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentClassification_ClassId, addSme: true)?.Set("string", "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentClassId.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_ClassName, addSme: true)?.Set("string", "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentClassName.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_ClassificationSystem, addSme: true)?.Set("string", "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentClassificationSystem.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentVersionId, addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_DocumentVersionId.GetSingleKey())?.value); var lcs = ""; foreach (var lcp in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_Language.GetSingleKey())) { lcs += "" + lcp?.value + ","; } smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentVersion_LanguageCode, addSme: true)?.Set("string", lcs.TrimEnd(',')); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Title, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticId( defsSg2.CD_VDI2770_Title.GetSingleKey(), new[] { typeof(AdminShell.Property), typeof(AdminShell.MultiLanguageProperty) })?.submodelElement?.ValueAsText()); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Summary, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticId( defsSg2.CD_VDI2770_Summary.GetSingleKey(), new[] { typeof(AdminShell.Property), typeof(AdminShell.MultiLanguageProperty) })?.submodelElement?.ValueAsText()); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Keywords, addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticId( defsSg2.CD_VDI2770_Keywords.GetSingleKey(), new[] { typeof(AdminShell.Property), typeof(AdminShell.MultiLanguageProperty) })?.submodelElement?.ValueAsText()); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_StatusValue, addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_StatusValue.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_SetDate, addSme: true)?. Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( defsSg2.CD_VDI2770_Date.GetSingleKey())?.value); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Purpose, addSme: true)?. Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_BasedOnProcedure, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Comments, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_ReferencedObject_Type, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>( defsHsu.CD_VDI2770_ReferencedObject_RefType, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>( defsHsu.CD_VDI2770_ReferencedObject_ObjectId, addSme: true)?.Set("string", ""); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_FileId, addSme: true)?. Set("string", ""); var fl = smcVer.value.FindFirstSemanticIdAs <AdminShell.File>( defsSg2.CD_VDI2770_DigitalFile.GetSingleKey()); if (fl != null) { smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_FileName, addSme: true)?.Set("string", System.IO.Path.GetFileName("" + fl.value)); smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_FileFormat, addSme: true)?.Set("string", "" + fl.mimeType); smcHsuDoc.value.CreateSMEForCD <AdminShell.File>(defsHsu.CD_File, addSme: true)?. Set("" + fl.mimeType, "" + fl.value); } } } } // obviously well return(true); }