public static ShelfControl FillWithWpfControls( LogInstance log, object opackage, object osm, AasxPluginDocumentShelf.DocumentShelfOptions options, PluginEventStack eventStack, object masterDockPanel) { // access var package = opackage as AdminShellPackageEnv; var sm = osm as AdminShell.Submodel; var master = masterDockPanel as DockPanel; if (package == null || sm == null || master == null) { return(null); } // the Submodel elements need to have parents sm.SetAllParents(); // create TOP control var shelfCntl = new ShelfControl(); shelfCntl.Start(log, package, sm, options, eventStack); master.Children.Add(shelfCntl); // return shelf return(shelfCntl); }
public void InitPlugin(string[] args) { // start .. Log.Info("InitPlugin() called with args = {0}", (args == null) ? "" : string.Join(", ", args)); // .. with built-in options options = AasxPluginDocumentShelf.DocumentShelfOptions.CreateDefault(); // try load defaults options from assy directory try { var newOpt = AasxPluginOptionsBase.LoadDefaultOptionsFromAssemblyDir < AasxPluginDocumentShelf.DocumentShelfOptions>( this.GetPluginName(), Assembly.GetExecutingAssembly()); if (newOpt != null) { this.options = newOpt; } } catch (Exception ex) { Log.Error(ex, "Exception when reading default options {1}"); } }
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; }
// // Default // public static ListOfDocumentEntity ParseSubmodelForV10( AdminShellPackageEnv thePackage, AdminShell.Submodel subModel, AasxPluginDocumentShelf.DocumentShelfOptions options, string defaultLang, int selectedDocClass, AasxLanguageHelper.LangEnum selectedLanguage) { // set a new list var its = new ListOfDocumentEntity(); // look for Documents if (subModel?.submodelElements != null) { foreach (var smcDoc in subModel.submodelElements.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( _semConfig.SemIdDocument, AdminShellV20.Key.MatchMode.Relaxed)) { // 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>( _semConfig.SemIdDocumentVersion, AdminShellV20.Key.MatchMode.Relaxed)) { // access if (smcVer == null || smcVer.value == null) { continue; } // // try to lookup info in smcDoc and smcVer // // take the 1st title var title = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(_semConfig.SemIdTitle, AdminShellV20.Key.MatchMode.Relaxed)?.value; // could be also a multi-language title foreach (var mlp in smcVer.value.FindAllSemanticIdAs <AdminShell.MultiLanguageProperty>( _semConfig.SemIdTitle, AdminShellV20.Key.MatchMode.Relaxed)) { if (mlp.value != null) { title = mlp.value.GetDefaultStr(defaultLang); } } // have multiple opportunities for orga var orga = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( _semConfig.SemIdOrganizationOfficialName, AdminShellV20.Key.MatchMode.Relaxed)?.value; if (orga.Trim().Length < 1) { orga = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( _semConfig.SemIdOrganizationName, AdminShellV20.Key.MatchMode.Relaxed)?.value; } // class infos var classId = "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( _semConfig.SemIdDocumentClassId, AdminShellV20.Key.MatchMode.Relaxed)?.value; // collect country codes var countryCodesStr = new List <string>(); var countryCodesEnum = new List <AasxLanguageHelper.LangEnum>(); foreach (var cclp in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(_semConfig.SemIdLanguage, AdminShellV20.Key.MatchMode.Relaxed)) { // language code var candidate = "" + cclp.value; if (candidate.Length < 1) { continue; } // convert to country codes and add var le = AasxLanguageHelper.FindLangEnumFromLangCode(candidate); if (le != AasxLanguageHelper.LangEnum.Any) { countryCodesEnum.Add(le); countryCodesStr.Add(AasxLanguageHelper.GetCountryCodeFromEnum(le)); } } // evaluate, if in selection var okDocClass = selectedDocClass < 1 || classId.Trim().Length < 1 || classId.Trim() .StartsWith( DefinitionsVDI2770.GetDocClass( (DefinitionsVDI2770.Vdi2770DocClass)selectedDocClass)); var okLanguage = selectedLanguage == AasxLanguageHelper.LangEnum.Any || // make only exception, if no language not all (not only the preferred // of LanguageSelectionToISO639String) are in the property countryCodesStr.Count < 1 || countryCodesEnum.Contains(selectedLanguage); if (!okDocClass || !okLanguage) { continue; } // further info var further = ""; foreach (var fi in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>( _semConfig.SemIdDocumentVersionIdValue)) { further += "\u00b7 version: " + fi.value; } foreach (var fi in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(_semConfig.SemIdDate, AdminShellV20.Key.MatchMode.Relaxed)) { further += "\u00b7 date: " + fi.value; } if (further.Length > 0) { further = further.Substring(2); } // construct entity var ent = new DocumentEntity(title, orga, further, countryCodesStr.ToArray()); ent.ReferableHash = String.Format( "{0:X14} {1:X14}", thePackage.GetHashCode(), smcDoc.GetHashCode()); // for updating data, set the source elements of this document entity ent.SourceElementsDocument = smcDoc.value; ent.SourceElementsDocumentVersion = smcVer.value; // filename var fl = smcVer.value.FindFirstSemanticIdAs <AdminShell.File>( _semConfig.SemIdDigitalFile, AdminShellV20.Key.MatchMode.Relaxed); ent.DigitalFile = new DocumentEntity.FileInfo(fl); // add ent.SmVersion = DocumentEntity.SubmodelVersion.Default; its.Add(ent); } } } // ok return(its); }
private void ParseSubmodelToListItems( AdminShell.Submodel subModel, AasxPluginDocumentShelf.DocumentShelfOptions options, int selectedDocClass, AasxLanguageHelper.LangEnum selectedLanguage, ViewModel.ListType selectedListType) { try { // influence list view rendering, as well if (selectedListType == ViewModel.ListType.Bars) { ScrollMainContent.ItemTemplate = (DataTemplate)ScrollMainContent.Resources["ItemTemplateForBar"]; ScrollMainContent.ItemsPanel = (ItemsPanelTemplate)ScrollMainContent.Resources["ItemsPanelForBar"]; } if (selectedListType == ViewModel.ListType.Grid) { ScrollMainContent.ItemTemplate = (DataTemplate)ScrollMainContent.Resources["ItemTemplateForGrid"]; ScrollMainContent.ItemsPanel = (ItemsPanelTemplate)ScrollMainContent.Resources["ItemsPanelForGrid"]; } // clean table ScrollMainContent.ItemsSource = null; // access if (subModel == null || options == null) { return; } // make sure for the right Submodel var found = false; if (options.AllowSubmodelSemanticIds != null) { foreach (var x in options.AllowSubmodelSemanticIds) { if (subModel.semanticId != null && subModel.semanticId.Matches(x)) { found = true; break; } } } if (!found) { return; } // right now: hardcoded check for mdoel version var modelVersion = DocumentEntity.SubmodelVersion.Default; var defs11 = AasxPredefinedConcepts.VDI2770v11.Static; if (subModel.semanticId.Matches(defs11?.SM_ManufacturerDocumentation?.GetSemanticKey())) { modelVersion = DocumentEntity.SubmodelVersion.V11; } // what defaultLanguage string defaultLang = null; if (theViewModel != null && theViewModel.TheSelectedLanguage > AasxLanguageHelper.LangEnum.Any) { defaultLang = AasxLanguageHelper.LangEnumToISO639String[(int)theViewModel.TheSelectedLanguage]; } // make new list box items var its = new List <DocumentEntity>(); if (modelVersion != DocumentEntity.SubmodelVersion.V11) { its = ListOfDocumentEntity.ParseSubmodelForV10( thePackage, subModel, options, defaultLang, selectedDocClass, selectedLanguage); } else { its = ListOfDocumentEntity.ParseSubmodelForV11( thePackage, subModel, defs11, defaultLang, selectedDocClass, selectedLanguage); } // post process foreach (var ent in its) { // make viewbox to host __later__ created image! var vb = new Viewbox(); vb.Stretch = Stretch.Uniform; ent.ImgContainer = vb; // can already put a generated image into the viewbox? if (referableHashToCachedBitmap != null && referableHashToCachedBitmap.ContainsKey(ent.ReferableHash)) { var img = new Image(); img.Source = referableHashToCachedBitmap[ent.ReferableHash]; ent.ImgContainer.Child = img; } else { // trigger generation of image // check if already in list DocumentEntity foundDe = null; foreach (var de in theDocEntitiesToPreview) { if (ent.ReferableHash == de.ReferableHash) { foundDe = de; } } lock (theDocEntitiesToPreview) { if (foundDe != null) { theDocEntitiesToPreview.Remove(foundDe); } theDocEntitiesToPreview.Add(ent); } } // attach events and add ent.DoubleClick += DocumentEntity_DoubleClick; ent.MenuClick += DocumentEntity_MenuClick; } // finally set ScrollMainContent.ItemsSource = its; } catch (Exception ex) { Log.Error(ex, "Exception when parse/ display Submodel"); } }
public AasxPluginResultBase ActivateAction(string action, params object[] args) { // for speed reasons, have the most often used at top! if (action == "call-check-visual-extension") { // arguments if (args.Length < 1) { return(null); } // looking only for Submodels var sm = args[0] as AdminShell.Submodel; if (sm == null) { return(null); } // check for a record in options, that matches Submodel var found = false; if (this.options.AllowSubmodelSemanticIds != null) { foreach (var x in this.options.AllowSubmodelSemanticIds) { if (sm.semanticId != null && sm.semanticId.Matches(x)) { found = true; break; } } } if (!found) { return(null); } // success prepare record var cve = new AasxPluginResultVisualExtension("DOC", "Document Shelf"); // ok return(cve); } // rest follows if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string) { var newOpt = Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginDocumentShelf.DocumentShelfOptions>( (args[0] as string)); if (newOpt != null) { this.options = newOpt; } } if (action == "get-json-options") { var json = Newtonsoft.Json.JsonConvert.SerializeObject( this.options, Newtonsoft.Json.Formatting.Indented); return(new AasxPluginResultBaseObject("OK", json)); } if (action == "get-licenses") { var lic = new AasxPluginResultLicense(); lic.shortLicense = "The CountryFlag library (NuGet) is licensed under the MIT license (MIT)."; lic.isStandardLicense = true; lic.longLicense = AasxPluginHelper.LoadLicenseTxtFromAssemblyDir( "LICENSE.txt", Assembly.GetExecutingAssembly()); return(lic); } if (action == "get-events" && this.eventStack != null) { // try access return(this.eventStack.PopEvent()); } if (action == "event-return" && args != null && args.Length >= 1 && args[0] is AasxPluginEventReturnBase && this.shelfControl != null) { this.shelfControl.HandleEventReturn(args[0] as AasxPluginEventReturnBase); } if (action == "get-check-visual-extension") { var cve = new AasxPluginResultBaseObject(); cve.strType = "True"; cve.obj = true; return(cve); } if (action == "fill-panel-visual-extension") { // arguments if (args == null || args.Length < 3) { return(null); } // call this.shelfControl = AasxPluginDocumentShelf.ShelfControl.FillWithWpfControls( Log, args[0], args[1], this.options, this.eventStack, args[2]); // give object back var res = new AasxPluginResultBaseObject(); res.obj = this.shelfControl; return(res); } if (action == "get-list-new-submodel") { // prepare list var list = new List <string>(); list.Add("Document (recommended version)"); list.Add("Document (development version V1.1)"); // make result var res = new AasxPluginResultBaseObject(); res.obj = list; return(res); } if (action == "generate-submodel" && args != null && args.Length >= 1 && args[0] is string) { // get arguments var smName = args[0] as string; if (smName == null) { return(null); } // generate (by hand) var sm = new AdminShell.Submodel(); if (smName.Contains("V1.1")) { sm.semanticId = new AdminShell.SemanticId( AasxPredefinedConcepts.VDI2770v11.Static.SM_ManufacturerDocumentation.GetSemanticKey()); sm.idShort = "ManufacturerDocumentation"; } else { sm.semanticId = new AdminShell.SemanticId(options.SemIdDocumentation); sm.idShort = "Documentation"; } // make result var res = new AasxPluginResultBaseObject(); res.strType = "OK"; res.obj = sm; return(res); } // default return(null); }
private void ParseSubmodelToListItems( AdminShell.Submodel subModel, AasxPluginDocumentShelf.DocumentShelfOptions options, int selectedDocClass, ViewModel.LanguageSelection selectedLanguage, ViewModel.ListType selectedListType) { try { // influence list view rendering, as well if (selectedListType == ViewModel.ListType.Bars) { ScrollMainContent.ItemTemplate = (DataTemplate)ScrollMainContent.Resources["ItemTemplateForBar"]; ScrollMainContent.ItemsPanel = (ItemsPanelTemplate)ScrollMainContent.Resources["ItemsPanelForBar"]; } if (selectedListType == ViewModel.ListType.Grid) { ScrollMainContent.ItemTemplate = (DataTemplate)ScrollMainContent.Resources["ItemTemplateForGrid"]; ScrollMainContent.ItemsPanel = (ItemsPanelTemplate)ScrollMainContent.Resources["ItemsPanelForGrid"]; } // clean table ScrollMainContent.ItemsSource = null; // access if (subModel == null || options == null) { return; } // make sure for the right Submodel var found = false; if (options.AllowSubmodelSemanticIds != null) { foreach (var x in options.AllowSubmodelSemanticIds) { if (subModel.semanticId != null && subModel.semanticId.Matches(x)) { found = true; break; } } } if (!found) { return; } // what defaultLanguage string defaultLang = null; if (theViewModel != null && theViewModel.TheSelectedLanguage > ViewModel.LanguageSelection.All) { defaultLang = ViewModel.LanguageSelectionToISO639String[(int)theViewModel.TheSelectedLanguage]; } // set a new list var its = new List <DocumentEntity>(); // look for Documents if (subModel?.submodelElements != null) { foreach (var smcDoc in subModel.submodelElements.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>( options?.SemIdDocument)) { // 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>( options?.SemIdDocumentVersion)) { // access if (smcVer == null || smcVer.value == null) { continue; } // // try to lookup info in smcDoc and smcVer // // take the 1st title var title = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(options?.SemIdTitle)?.value; // could be also a multi-language title foreach (var mlp in smcVer.value.FindAllSemanticIdAs <AdminShell.MultiLanguageProperty>( options?.SemIdTitle)) { if (mlp.value != null) { title = mlp.value.GetDefaultStr(defaultLang); } } // have multiple opportunities for orga var orga = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( options?.SemIdOrganizationOfficialName)?.value; if (orga.Trim().Length < 1) { orga = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>( options?.SemIdOrganizationName)?.value; } // class infos var classId = "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>( options?.SemIdDocumentClassId)?.value; // collect country codes var countryCodesStr = new List <string>(); var countryCodesEnum = new List <ViewModel.LanguageSelection>(); foreach (var cclp in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(options?.SemIdLanguage)) { // language code var candidate = ("" + cclp.value).Trim().ToUpper(); if (candidate.Length < 1) { continue; } // convert to country codes foreach (var ev in (ViewModel.LanguageSelection[])Enum.GetValues(typeof(ViewModel.LanguageSelection))) { if (candidate == ViewModel.LanguageSelectionToISO639String[(int)ev]?.ToUpper()) { candidate = ViewModel.LanguageSelectionToISO3166String[(int)ev]?.ToUpper(); countryCodesEnum.Add(ev); } } // add countryCodesStr.Add(candidate); } // evaluate, if in selection var okDocClass = (selectedDocClass < 1 || classId == null || classId.Trim().Length < 1 || classId.Trim() .StartsWith( DefinitionsVDI2770.GetDocClass( (DefinitionsVDI2770.Vdi2770DocClass)selectedDocClass))); var okLanguage = (selectedLanguage == ViewModel.LanguageSelection.All || countryCodesEnum == null || // make only exception, if no language not all (not only the preferred // of LanguageSelectionToISO639String) are in the property countryCodesStr.Count < 1 || countryCodesEnum.Contains(selectedLanguage)); if (!okDocClass || !okLanguage) { continue; } // further info var further = ""; foreach (var fi in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>( options?.SemIdDocumentVersionIdValue)) { further += "\u00b7 version: " + fi.value; } foreach (var fi in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(options?.SemIdDate)) { further += "\u00b7 date: " + fi.value; } if (further.Length > 0) { further = further.Substring(2); } // construct entity var ent = new DocumentEntity(title, orga, further, countryCodesStr.ToArray()); ent.ReferableHash = String.Format( "{0:X14} {1:X14}", thePackage.GetHashCode(), smcDoc.GetHashCode()); // for updating data, set the source elements of this document entity ent.SourceElementsDocument = smcDoc.value; ent.SourceElementsDocumentVersion = smcVer.value; // filename var fn = smcVer.value.FindFirstSemanticIdAs <AdminShell.File>( options?.SemIdDigitalFile)?.value; ent.DigitalFile = fn; // make viewbox to host __later__ created image! var vb = new Viewbox(); vb.Stretch = Stretch.Uniform; ent.ImgContainer = vb; // can already put a generated image into the viewbox? if (referableHashToCachedBitmap != null && referableHashToCachedBitmap.ContainsKey(ent.ReferableHash)) { var img = new Image(); img.Source = referableHashToCachedBitmap[ent.ReferableHash]; ent.ImgContainer.Child = img; } else { // trigger generation of image // check if already in list DocumentEntity foundDe = null; foreach (var de in theDocEntitiesToPreview) { if (ent.ReferableHash == de.ReferableHash) { foundDe = de; } } lock (theDocEntitiesToPreview) { if (foundDe != null) { theDocEntitiesToPreview.Remove(foundDe); } theDocEntitiesToPreview.Add(ent); } } // attach events and add ent.DoubleClick += DocumentEntity_DoubleClick; ent.MenuClick += DocumentEntity_MenuClick; its.Add(ent); } } } // make new list box items ScrollMainContent.ItemsSource = its; } catch (Exception ex) { Log.Error(ex, "Exception when parse/ display Submodel"); } }
private void ParseSubmodelToListItems( AdminShell.Submodel subModel, AasxPluginDocumentShelf.DocumentShelfOptions options, int selectedDocClass, AasxLanguageHelper.LangEnum selectedLanguage, ViewModel.ListType selectedListType) { try { // influence list view rendering, as well if (selectedListType == ViewModel.ListType.Bars) { ScrollMainContent.ItemTemplate = (DataTemplate)ScrollMainContent.Resources["ItemTemplateForBar"]; ScrollMainContent.ItemsPanel = (ItemsPanelTemplate)ScrollMainContent.Resources["ItemsPanelForBar"]; } if (selectedListType == ViewModel.ListType.Grid) { ScrollMainContent.ItemTemplate = (DataTemplate)ScrollMainContent.Resources["ItemTemplateForGrid"]; ScrollMainContent.ItemsPanel = (ItemsPanelTemplate)ScrollMainContent.Resources["ItemsPanelForGrid"]; } // clean table ScrollMainContent.ItemsSource = null; // access if (subModel?.semanticId == null || options == null) { return; } // make sure for the right Submodel DocumentShelfOptionsRecord foundRec = null; foreach (var rec in options.LookupAllIndexKey <DocumentShelfOptionsRecord>( subModel?.semanticId?.GetAsExactlyOneKey())) { foundRec = rec; } if (foundRec == null) { return; } // right now: hardcoded check for mdoel version var modelVersion = DocumentEntity.SubmodelVersion.Default; var defs11 = AasxPredefinedConcepts.VDI2770v11.Static; if (subModel.semanticId.Matches(defs11?.SM_ManufacturerDocumentation?.GetSemanticKey())) { modelVersion = DocumentEntity.SubmodelVersion.V11; } if (foundRec.ForceVersion == DocumentEntity.SubmodelVersion.V10) { modelVersion = DocumentEntity.SubmodelVersion.V10; } if (foundRec.ForceVersion == DocumentEntity.SubmodelVersion.V11) { modelVersion = DocumentEntity.SubmodelVersion.V11; } // set checkbox this.CheckBoxLatestVersion.IsChecked = modelVersion == DocumentEntity.SubmodelVersion.V11; // set usage info var useinf = foundRec.UsageInfo; TextBlockUsageInfo.Text = useinf; PanelUsageInfo.Visibility = useinf.HasContent() ? Visibility.Visible : Visibility.Collapsed; // what defaultLanguage string defaultLang = null; if (theViewModel != null && theViewModel.TheSelectedLanguage > AasxLanguageHelper.LangEnum.Any) { defaultLang = AasxLanguageHelper.LangEnumToISO639String[(int)theViewModel.TheSelectedLanguage]; } // make new list box items var its = new List <DocumentEntity>(); if (modelVersion != DocumentEntity.SubmodelVersion.V11) { its = ListOfDocumentEntity.ParseSubmodelForV10( thePackage, subModel, options, defaultLang, selectedDocClass, selectedLanguage); } else { its = ListOfDocumentEntity.ParseSubmodelForV11( thePackage, subModel, defs11, defaultLang, selectedDocClass, selectedLanguage); } // post process foreach (var ent in its) { // make viewbox to host __later__ created image! var vb = new Viewbox(); vb.Stretch = Stretch.Uniform; ent.ImgContainer = vb; // if a preview file exists, try load directly, but not interfere // we delayed load logic, as these images might get more detailed if (ent.PreviewFile?.Path?.HasContent() == true) { var inputFn = ent.PreviewFile.Path; // from package? if (CheckIfPackageFile(inputFn)) { inputFn = thePackage.MakePackageFileAvailableAsTempFile(ent.PreviewFile.Path); } ent.LoadImageFromPath(inputFn); } // delayed load logic // can already put a generated image into the viewbox? if (referableHashToCachedBitmap != null && referableHashToCachedBitmap.ContainsKey(ent.ReferableHash)) { var img = new Image(); img.Source = referableHashToCachedBitmap[ent.ReferableHash]; ent.ImgContainer.Child = img; } else { // trigger generation of image // check if already in list DocumentEntity foundDe = null; foreach (var de in theDocEntitiesToPreview) { if (ent.ReferableHash == de.ReferableHash) { foundDe = de; } } lock (theDocEntitiesToPreview) { if (foundDe != null) { theDocEntitiesToPreview.Remove(foundDe); } theDocEntitiesToPreview.Add(ent); } } // attach events and add ent.DoubleClick += DocumentEntity_DoubleClick; ent.MenuClick += DocumentEntity_MenuClick; ent.DragStart += DocumentEntity_DragStart; } // finally set ScrollMainContent.ItemsSource = its; } catch (Exception ex) { Log.Error(ex, "Exception when parse/ display Submodel"); } }