// TODO (MIHO, 2020-12-24): check if required private DispLevelColors GetLevelColorsFromResources() { // ReSharper disable CoVariantArrayConversion var res = new DispLevelColors() { MainSection = new AnyUiBrushTuple( AnyUiDisplayContextWpf.GetAnyUiBrush((SolidColorBrush) System.Windows.Application.Current.Resources["DarkestAccentColor"]), AnyUiBrushes.White), SubSection = new AnyUiBrushTuple( AnyUiDisplayContextWpf.GetAnyUiBrush((SolidColorBrush) System.Windows.Application.Current.Resources["LightAccentColor"]), AnyUiBrushes.Black), SubSubSection = new AnyUiBrushTuple( AnyUiDisplayContextWpf.GetAnyUiBrush((SolidColorBrush) System.Windows.Application.Current.Resources["LightAccentColor"]), AnyUiBrushes.Black), HintSeverityHigh = new AnyUiBrushTuple( AnyUiDisplayContextWpf.GetAnyUiBrush((SolidColorBrush) System.Windows.Application.Current.Resources["FocusErrorBrush"]), AnyUiBrushes.White), HintSeverityNotice = new AnyUiBrushTuple( AnyUiDisplayContextWpf.GetAnyUiBrush((SolidColorBrush) System.Windows.Application.Current.Resources["LightAccentColor"]), AnyUiDisplayContextWpf.GetAnyUiBrush((SolidColorBrush) System.Windows.Application.Current.Resources["DarkestAccentColor"])) }; // ReSharper enable CoVariantArrayConversion return(res); }
private void Application_Startup(object sender, StartupEventArgs e) { // allow long term logging (for report box) Log.Singleton.EnableLongTermStore(); // catch unhandled exceptions SetupExceptionHandling(); // Build up of options Log.Singleton.Info("Application startup."); var exePath = System.Reflection.Assembly.GetEntryAssembly()?.Location; Options.ReplaceCurr(InferOptions(exePath, e.Args)); // search for plugins? if (Options.Curr.PluginDir != null) { var searchDir = System.IO.Path.Combine( System.IO.Path.GetDirectoryName(exePath), Options.Curr.PluginDir); Log.Singleton.Info( "Searching for the plugins in the plugin directory: {0}", searchDir); var pluginDllInfos = Plugins.TrySearchPlugins(searchDir); Log.Singleton.Info( $"Found {pluginDllInfos.Count} plugin(s) in the plugin directory: {searchDir}"); Options.Curr.PluginDll.AddRange(pluginDllInfos); } Log.Singleton.Info( $"Loading and activating {Options.Curr.PluginDll.Count} plugin(s)..."); Plugins.LoadedPlugins = LoadAndActivatePlugins(Options.Curr.PluginDll); // at end, write all default options to JSON? if (Options.Curr.WriteDefaultOptionsFN != null) { // info var fullFilename = System.IO.Path.GetFullPath(Options.Curr.WriteDefaultOptionsFN); Log.Singleton.Info($"Writing resulting options to a JSON file: {fullFilename}"); // retrieve Plugins.TryGetDefaultOptionsForPlugins(Options.Curr.PluginDll, Plugins.LoadedPlugins); OptionsInformation.WriteJson(Options.Curr, fullFilename); } // colors if (true) { var resNames = new[] { "LightAccentColor", "DarkAccentColor", "DarkestAccentColor", "FocusErrorBrush" }; for (int i = 0; i < resNames.Length; i++) { var x = this.FindResource(resNames[i]); if (x != null && x is System.Windows.Media.SolidColorBrush && Options.Curr.AccentColors.ContainsKey((OptionsInformation.ColorNames)i)) { this.Resources[resNames[i]] = AnyUiDisplayContextWpf.GetWpfBrush( Options.Curr.GetColor((OptionsInformation.ColorNames)i)); } } resNames = new[] { "FocusErrorColor" }; for (int i = 0; i < resNames.Length; i++) { var x = this.FindResource(resNames[i]); if (x != null && x is System.Windows.Media.Color && Options.Curr.AccentColors.ContainsKey((OptionsInformation.ColorNames)(3 + i))) { this.Resources[resNames[i]] = AnyUiDisplayContextWpf.GetWpfColor( Options.Curr.GetColor((OptionsInformation.ColorNames)(3 + i))); } } } Pref pref = Pref.Read(); // show splash (required for licenses of open source) if (Options.Curr.SplashTime != 0) { var splash = new CustomSplashScreenNew(pref); splash.Show(); } // show main window MainWindow wnd = new MainWindow(pref); wnd.Show(); }
public DisplayRenderHints DisplayOrEditVisualAasxElement( PackageCentral packages, ListOfVisualElementBasic entities, bool editMode, bool hintMode = false, bool showIriMode = false, VisualElementEnvironmentItem.ConceptDescSortOrder?cdSortOrder = null, IFlyoutProvider flyoutProvider = null, IPushApplicationEvent appEventProvider = null, DispEditHighlight.HighlightFieldInfo hightlightField = null) { // // Start // // hint mode disable, when not edit hintMode = hintMode && editMode; // remember objects for UI thread / redrawing this._packages = packages; this._theEntities = entities; _helper.packages = packages; _helper.highlightField = hightlightField; _helper.appEventsProvider = appEventProvider; // primary access var renderHints = new DisplayRenderHints(); if (theMasterPanel == null || entities == null || entities.Count < 1) { renderHints.showDataPanel = false; return(renderHints); } #if MONOUI var stack = ClearDisplayDefautlStack(); #else var stack = new AnyUiStackPanel(); #endif // create display context for WPF _displayContext = new AnyUiDisplayContextWpf(flyoutProvider, packages); _helper.levelColors = DispLevelColors.GetLevelColorsFromOptions(Options.Curr); // modify repository ModifyRepo repo = null; if (editMode) { // some functionality still uses repo != null to detect editMode!! repo = new ModifyRepo(); } _helper.editMode = editMode; _helper.hintMode = hintMode; _helper.repo = repo; _helper.showIriMode = showIriMode; _helper.context = _displayContext; // inform plug that their potential panel might not shown anymore Plugins.AllPluginsInvoke("clear-panel-visual-extension"); // // Test for Blazor // #if __test_blazor if (false) { var lab = new AnyUiLabel(); lab.Content = "Hallo"; lab.Foreground = AnyUiBrushes.DarkBlue; stack.Children.Add(lab); if (editMode) { var tb = new AnyUiTextBox(); tb.Foreground = AnyUiBrushes.Black; tb.Text = "Initial"; stack.Children.Add(tb); repo.RegisterControl(tb, (o) => { Log.Singleton.Info($"Text changed to .. {""+o}"); return(new AnyUiLambdaActionNone()); }); var btn = new AnyUiButton(); btn.Content = "Click me!"; stack.Children.Add(btn); repo.RegisterControl(btn, (o) => { Log.Singleton.Error("Button clicked!"); return(new AnyUiLambdaActionRedrawAllElements(null)); }); } } #endif var inhibitRenderStackToPanel = false; if (entities.ExactlyOne) { // // Dispatch: ONE item // var entity = entities.First(); // maintain parent. If in doubt, set null ListOfVisualElement.SetParentsBasedOnChildHierarchy(entity); // // Dispatch // if (entity is VisualElementEnvironmentItem veei) { _helper.DisplayOrEditAasEntityAasEnv( packages, veei.theEnv, veei, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementAdminShell veaas) { _helper.DisplayOrEditAasEntityAas( packages, veaas.theEnv, veaas.theAas, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementAsset veas) { _helper.DisplayOrEditAasEntityAsset( packages, veas.theEnv, veas.theAsset, editMode, repo, stack, hintMode: hintMode); } else if (entity is VisualElementSubmodelRef vesmref) { // data AdminShell.AdministrationShell aas = null; if (vesmref.Parent is VisualElementAdminShell xpaas) { aas = xpaas.theAas; } // edit _helper.DisplayOrEditAasEntitySubmodelOrRef( packages, vesmref.theEnv, aas, vesmref.theSubmodelRef, vesmref.theSubmodel, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementSubmodel vesm && vesm.theSubmodel != null) { _helper.DisplayOrEditAasEntitySubmodelOrRef( packages, vesm.theEnv, null, null, vesm.theSubmodel, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementSubmodelElement vesme) { _helper.DisplayOrEditAasEntitySubmodelElement( packages, vesme.theEnv, vesme.theContainer, vesme.theWrapper, vesme.theWrapper.submodelElement, editMode, repo, stack, hintMode: hintMode, nestedCds: cdSortOrder.HasValue && cdSortOrder.Value == VisualElementEnvironmentItem.ConceptDescSortOrder.BySme); } else if (entity is VisualElementOperationVariable vepv) { _helper.DisplayOrEditAasEntityOperationVariable( packages, vepv.theEnv, vepv.theContainer, vepv.theOpVar, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementConceptDescription vecd) { _helper.DisplayOrEditAasEntityConceptDescription( packages, vecd.theEnv, null, vecd.theCD, editMode, repo, stack, hintMode: hintMode, preventMove: cdSortOrder.HasValue && cdSortOrder.Value != VisualElementEnvironmentItem.ConceptDescSortOrder.None); } else if (entity is VisualElementView vevw) { if (vevw.Parent != null && vevw.Parent is VisualElementAdminShell xpaas) { _helper.DisplayOrEditAasEntityView( packages, vevw.theEnv, xpaas.theAas, vevw.theView, editMode, stack, hintMode: hintMode); } else { _helper.AddGroup(stack, "View is corrupted!", _helper.levelColors.MainSection); } } else if (entity is VisualElementReference verf) { if (verf.Parent != null && verf.Parent is VisualElementView xpev) { _helper.DisplayOrEditAasEntityViewReference( packages, verf.theEnv, xpev.theView, (AdminShell.ContainedElementRef)verf.theReference, editMode, stack); } else { _helper.AddGroup(stack, "Reference is corrupted!", _helper.levelColors.MainSection); } } else if (entity is VisualElementSupplementalFile vesf) { _helper.DisplayOrEditAasEntitySupplementaryFile(packages, vesf.theFile, editMode, stack); } else if (entity is VisualElementPluginExtension vepe) { // create controls object result = null; try { // replace at top level theMasterPanel.Children.Clear(); if (vepe.thePlugin != null) { result = vepe.thePlugin.InvokeAction( "fill-panel-visual-extension", vepe.thePackage, vepe.theReferable, theMasterPanel); } } catch (Exception ex) { AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex); } // add? if (result == null) { // re-init display! #if MONOUI stack = ClearDisplayDefautlStack(); #else stack = new AnyUiStackPanel(); #endif // helping message _helper.AddGroup( stack, "Entity from Plugin cannot be rendered!", _helper.levelColors.MainSection); } else { // this is natively done; do NOT render Any UI to WPF inhibitRenderStackToPanel = true; } // show no panel nor scroll renderHints.scrollingPanel = false; renderHints.showDataPanel = false; } else { _helper.AddGroup(stack, "Entity is unknown!", _helper.levelColors.MainSection); } }
public DisplayRenderHints DisplayMessage(string message) { // reset _packages = null; _theEntity = null; _displayContext = null; _lastRenderedRootElement = null; // Grid to fill full page var g = new Grid(); g.Background = Brushes.DarkGray; g.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1.0) }); g.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); g.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1.0) }); g.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1.0) }); g.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); g.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1.0) }); // textblock var tb = new TextBlock(); tb.Foreground = Brushes.White; tb.FontSize = 18.0; tb.Text = "" + message; tb.FontWeight = FontWeights.Bold; tb.HorizontalAlignment = HorizontalAlignment.Center; tb.VerticalAlignment = VerticalAlignment.Center; g.Children.Add(tb); Grid.SetRow(tb, 1); Grid.SetColumn(tb, 1); // manually render theMasterPanel.Children.Clear(); theMasterPanel.Children.Add(g); // render hints var rh = new DisplayRenderHints() { scrollingPanel = false, showDataPanel = false }; return(rh); }
public DisplayRenderHints DisplayOrEditVisualAasxElement( PackageCentral packages, ListOfVisualElementBasic entities, bool editMode, bool hintMode = false, bool showIriMode = false, VisualElementEnvironmentItem.ConceptDescSortOrder?cdSortOrder = null, IFlyoutProvider flyoutProvider = null, IPushApplicationEvent appEventProvider = null, DispEditHighlight.HighlightFieldInfo hightlightField = null) { // // Start // // hint mode disable, when not edit hintMode = hintMode && editMode; // remember objects for UI thread / redrawing this._packages = packages; this._theEntities = entities; _helper.packages = packages; _helper.highlightField = hightlightField; _helper.appEventsProvider = appEventProvider; // primary access var renderHints = new DisplayRenderHints(); if (theMasterPanel == null || entities == null || entities.Count < 1) { renderHints.showDataPanel = false; return(renderHints); } #if MONOUI var stack = ClearDisplayDefautlStack(); #else var stack = new AnyUiStackPanel(); #endif // create display context for WPF _displayContext = new AnyUiDisplayContextWpf(flyoutProvider, packages); _helper.levelColors = DispLevelColors.GetLevelColorsFromOptions(Options.Curr); // modify repository ModifyRepo repo = null; if (editMode) { // some functionality still uses repo != null to detect editMode!! repo = new ModifyRepo(); } _helper.editMode = editMode; _helper.hintMode = hintMode; _helper.repo = repo; _helper.showIriMode = showIriMode; _helper.context = _displayContext; // // Test for Blazor // #if __test_blazor if (false) { var lab = new AnyUiLabel(); lab.Content = "Hallo"; lab.Foreground = AnyUiBrushes.DarkBlue; stack.Children.Add(lab); if (editMode) { var tb = new AnyUiTextBox(); tb.Foreground = AnyUiBrushes.Black; tb.Text = "Initial"; stack.Children.Add(tb); repo.RegisterControl(tb, (o) => { Log.Singleton.Info($"Text changed to .. {""+o}"); return(new AnyUiLambdaActionNone()); }); var btn = new AnyUiButton(); btn.Content = "Click me!"; stack.Children.Add(btn); repo.RegisterControl(btn, (o) => { Log.Singleton.Error("Button clicked!"); return(new AnyUiLambdaActionRedrawAllElements(null)); }); } } #endif var inhibitRenderStackToPanel = false; if (entities.ExactlyOne) { // // Dispatch: ONE item // var entity = entities.First(); if (entity is VisualElementEnvironmentItem veei) { _helper.DisplayOrEditAasEntityAasEnv( packages, veei.theEnv, veei, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementAdminShell veaas) { _helper.DisplayOrEditAasEntityAas( packages, veaas.theEnv, veaas.theAas, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementAsset veas) { _helper.DisplayOrEditAasEntityAsset( packages, veas.theEnv, veas.theAsset, editMode, repo, stack, hintMode: hintMode); } else if (entity is VisualElementSubmodelRef vesmref) { AdminShell.AdministrationShell aas = null; if (vesmref.Parent is VisualElementAdminShell xpaas) { aas = xpaas.theAas; } _helper.DisplayOrEditAasEntitySubmodelOrRef( packages, vesmref.theEnv, aas, vesmref.theSubmodelRef, vesmref.theSubmodel, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementSubmodel vesm) { _helper.DisplayOrEditAasEntitySubmodelOrRef( packages, vesm.theEnv, null, null, vesm.theSubmodel, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementSubmodelElement vesme) { _helper.DisplayOrEditAasEntitySubmodelElement( packages, vesme.theEnv, vesme.theContainer, vesme.theWrapper, vesme.theWrapper.submodelElement, editMode, repo, stack, hintMode: hintMode, nestedCds: cdSortOrder.HasValue && cdSortOrder.Value == VisualElementEnvironmentItem.ConceptDescSortOrder.BySme); } else if (entity is VisualElementOperationVariable vepv) { _helper.DisplayOrEditAasEntityOperationVariable( packages, vepv.theEnv, vepv.theContainer, vepv.theOpVar, editMode, stack, hintMode: hintMode); } else if (entity is VisualElementConceptDescription vecd) { _helper.DisplayOrEditAasEntityConceptDescription( packages, vecd.theEnv, null, vecd.theCD, editMode, repo, stack, hintMode: hintMode, preventMove: cdSortOrder.HasValue && cdSortOrder.Value != VisualElementEnvironmentItem.ConceptDescSortOrder.None); } else if (entity is VisualElementView vevw) { if (vevw.Parent != null && vevw.Parent is VisualElementAdminShell xpaas) { _helper.DisplayOrEditAasEntityView( packages, vevw.theEnv, xpaas.theAas, vevw.theView, editMode, stack, hintMode: hintMode); } else { _helper.AddGroup(stack, "View is corrupted!", _helper.levelColors.MainSection); } } else if (entity is VisualElementReference verf) { if (verf.Parent != null && verf.Parent is VisualElementView xpev) { _helper.DisplayOrEditAasEntityViewReference( packages, verf.theEnv, xpev.theView, (AdminShell.ContainedElementRef)verf.theReference, editMode, stack); } else { _helper.AddGroup(stack, "Reference is corrupted!", _helper.levelColors.MainSection); } } else if (entity is VisualElementSupplementalFile vesf) { _helper.DisplayOrEditAasEntitySupplementaryFile(packages, vesf.theFile, editMode, stack); } else if (entity is VisualElementPluginExtension vepe) { // create controls object result = null; try { // replace at top level theMasterPanel.Children.Clear(); if (vepe.thePlugin != null) { result = vepe.thePlugin.InvokeAction( "fill-panel-visual-extension", vepe.thePackage, vepe.theReferable, theMasterPanel); } } catch (Exception ex) { AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex); } // add? if (result == null) { // re-init display! #if MONOUI stack = ClearDisplayDefautlStack(); #else stack = new AnyUiStackPanel(); #endif // helping message _helper.AddGroup( stack, "Entity from Plugin cannot be rendered!", _helper.levelColors.MainSection); } else { // this is natively done; do NOT render Any UI to WPF inhibitRenderStackToPanel = true; } // show no panel nor scroll renderHints.scrollingPanel = false; renderHints.showDataPanel = false; } else { _helper.AddGroup(stack, "Entity is unknown!", _helper.levelColors.MainSection); } } else { // // Dispatch: MULTIPLE items // _helper.DisplayOrEditAasEntityMultipleElements(packages, entities, editMode, stack, cdSortOrder); } // now render master stack #if __export_BLAZOR var fn = @"fileEdit.json"; if (!editMode) { count = 0; var jsonSerializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented }; var json = JsonConvert.SerializeObject(stack, jsonSerializerSettings); System.IO.File.WriteAllText(fn, json); } if (editMode) { if (true && count == 2) { count = 0; JsonSerializerSettings settings = new JsonSerializerSettings { // SerializationBinder = new DisplayNameSerializationBinder( // new[] { typeof(AasxIntegrationBase.AasForms.FormDescListOfElement), // typeof(AasxIntegrationBase.AasForms.FormDescProperty) }), // SerializationBinder = new DisplayNameSerializationBinder( // new[] { typeof(AnyUiStackPanel), typeof(AnyUiUIElement) }), // NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Error, TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented }; //if (stack is AnyUiPanel pan) //{ // for (int i = 0; i < pan.Children.Count; i++) // { // var json = JsonConvert.SerializeObject(pan.Children[i], settings); // System.IO.File.WriteAllText(fn+"."+i, json); // } //} var json = JsonConvert.SerializeObject(stack, settings); System.IO.File.WriteAllText(fn, json); } count++; /* * var writer = new System.Xml.Serialization.XmlSerializer(typeof(AnyUiUIElement)); * var wfile = new System.IO.StreamWriter(@"c:\development\fileEdit.xml"); * writer.Serialize(wfile, stack); * wfile.Close(); */ } #endif #if MONOUI #else // render Any UI to WPF? if (!inhibitRenderStackToPanel) { // rendering theMasterPanel.Children.Clear(); var spwpf = _displayContext.GetOrCreateWpfElement(stack); _helper.ShowLastHighlights(); DockPanel.SetDock(spwpf, Dock.Top); theMasterPanel.Children.Add(spwpf); // register key shortcuts var num = _displayContext.PrepareNameList(stack); if (num > 0) { _displayContext.RegisterKeyShortcut( "aas-elem-move-up", ModifierKeys.Shift | ModifierKeys.Control, Key.Up, "Move current AAS element up by one position."); _displayContext.RegisterKeyShortcut( "aas-elem-move-down", ModifierKeys.Shift | ModifierKeys.Control, Key.Down, "Move current AAS element down by one position."); _displayContext.RegisterKeyShortcut( "aas-elem-move-top", ModifierKeys.Shift | ModifierKeys.Control, Key.Home, "Move current AAS element to the first position of the respective list."); _displayContext.RegisterKeyShortcut( "aas-elem-move-end", ModifierKeys.Shift | ModifierKeys.Control, Key.End, "Move current AAS element to the last position of the respective list."); _displayContext.RegisterKeyShortcut( "aas-elem-delete", ModifierKeys.Shift | ModifierKeys.Control, Key.Delete, "Delete current AAS element in the respective list. Shift key skips dialogue."); _displayContext.RegisterKeyShortcut( "aas-elem-cut", ModifierKeys.Shift | ModifierKeys.Control, Key.X, "Transfers current AAS element into paste buffer and deletes in respective list."); _displayContext.RegisterKeyShortcut( "aas-elem-copy", ModifierKeys.Shift | ModifierKeys.Control, Key.C, "Copies current AAS element into paste buffer for later pasting."); _displayContext.RegisterKeyShortcut( "aas-elem-paste-into", ModifierKeys.Shift | ModifierKeys.Control, Key.V, "Copy existing paste buffer into the child list of the current AAS element."); _displayContext.RegisterKeyShortcut( "aas-elem-paste-above", ModifierKeys.Shift | ModifierKeys.Control, Key.W, "Copy existing paste buffer above the current AAS element in the same list."); _displayContext.RegisterKeyShortcut( "aas-elem-paste-below", ModifierKeys.Shift | ModifierKeys.Control, Key.Y, "Copy existing paste buffer below the current AAS element in the same list."); } } // keep the stack _lastRenderedRootElement = stack; #endif // return render hints return(renderHints); }