diff --git a/Pilz.Collections/My Project/Application.Designer.cs b/Pilz.Collections/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Collections/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Collections/My Project/Application.Designer.vb b/Pilz.Collections/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Collections/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Collections/My Project/AssemblyInfo.vb b/Pilz.Collections/My Project/AssemblyInfo.vb deleted file mode 100644 index 16e3ed2..0000000 --- a/Pilz.Collections/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Collections/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Collections/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..a4b7309 --- /dev/null +++ b/Pilz.Collections/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Collections.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Collections/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Collections/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..bf76689 --- /dev/null +++ b/Pilz.Collections/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Collections.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Collections/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Collections/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Collections/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Collections/My Project/Resources.Designer.vb b/Pilz.Collections/My Project/Resources.Designer.vb deleted file mode 100644 index efc949e..0000000 --- a/Pilz.Collections/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Collections.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Collections/My Project/Settings.Designer.vb b/Pilz.Collections/My Project/Settings.Designer.vb deleted file mode 100644 index 69fe663..0000000 --- a/Pilz.Collections/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Collections.My.MySettings - Get - Return Global.Pilz.Collections.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Collections/Pilz.Collections.vbproj b/Pilz.Collections/Pilz.Collections.csproj similarity index 76% rename from Pilz.Collections/Pilz.Collections.vbproj rename to Pilz.Collections/Pilz.Collections.csproj index 1d39f65..5c24b81 100644 --- a/Pilz.Collections/Pilz.Collections.vbproj +++ b/Pilz.Collections/Pilz.Collections.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {E4B2D294-8479-4014-942D-0B460E453DEA} + {569653FF-4821-0FE5-1675-C1386CD2094A} Library @@ -14,6 +14,8 @@ Windows v4.7.2 + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest AnyCPU @@ -73,6 +75,7 @@ MinimumRecommendedRules.ruleset + @@ -98,48 +101,51 @@ - - - - - + + + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - - - + + + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Collections.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Collections.My + Settings.Designer.cs - + \ No newline at end of file diff --git a/Pilz.Collections/Properties/AssemblyInfo.cs b/Pilz.Collections/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9ae74e3 --- /dev/null +++ b/Pilz.Collections/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("SimpleHistory")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("Dr. Schneider Kunststoffwerke GmbH")] +[assembly: AssemblyProduct("SimpleHistory")] +[assembly: AssemblyCopyright("Copyright © Pascal Schedel 2018")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("7dd4cf70-efc1-4386-a169-39ec65e4aef3")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Collections/Properties/Settings.Designer.cs b/Pilz.Collections/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3b191f9 --- /dev/null +++ b/Pilz.Collections/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Collections.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Collections/My Project/Settings.settings b/Pilz.Collections/Properties/Settings.settings similarity index 100% rename from Pilz.Collections/My Project/Settings.settings rename to Pilz.Collections/Properties/Settings.settings diff --git a/Pilz.Collections/Resources.Designer.cs b/Pilz.Collections/Resources.Designer.cs new file mode 100644 index 0000000..6951a7d --- /dev/null +++ b/Pilz.Collections/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Collections.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Collections.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Collections/Resources.resx b/Pilz.Collections/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Collections/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/Enums.vb b/Pilz.Collections/SimpleHistory/Enums.vb deleted file mode 100644 index 8438552..0000000 --- a/Pilz.Collections/SimpleHistory/Enums.vb +++ /dev/null @@ -1,12 +0,0 @@ -Namespace SimpleHistory - - ''' - ''' Specify which member types you would include. - ''' - Public Enum ObjectValueType - None = 0 - Field = 1 - [Property] = 2 - End Enum - -End Namespace \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/HistoryPoint.cs b/Pilz.Collections/SimpleHistory/HistoryPoint.cs new file mode 100644 index 0000000..44778f0 --- /dev/null +++ b/Pilz.Collections/SimpleHistory/HistoryPoint.cs @@ -0,0 +1,615 @@ +using System.Collections.Generic; +using System.Data; +using System.Linq; +using global::System.Reflection; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Collections.SimpleHistory +{ + + /// + /// Represent some Object States and Actions. + /// + public class HistoryPoint + { + + /// + /// Represents the Name of this History Point + /// + /// + public string Name { get; set; } = ""; + /// + /// A List of Object States and Actions. + /// + /// + public List Entries { get; private set; } = new List(); + /// + /// Some data can be refered on this HistoryPoint. Don't know, in some situations this can be helpful. + /// + public readonly object Tag = null; + + public bool HasEntries() where T : ObjectBase + { + return Entries.Where(n => n is T).Count() > 0; + } + + internal void Undo() + { + foreach (ObjectBase s in Entries.OrderBy(n => n.UndoPriority)) + { + if (s is ObjectState) + { + ((ObjectState)s).Patch(); + } + else if (s is ObjectAction) + { + ((ObjectAction)s).Undo(); + } + } + } + + internal void Redo() + { + foreach (ObjectBase s in Entries.OrderBy(n => n.RedoPriority)) + { + if (s is ObjectState) + { + ((ObjectState)s).Patch(); + } + else if (s is ObjectAction) + { + ((ObjectAction)s).Redo(); + } + } + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify which members to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, MemberWhiteList whiteList) + { + return FromObject(new[] { obj }, ObjectValueType.None, whiteList, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify which members to exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, MemberBlackList blackList) + { + return FromObject(new[] { obj }, ObjectValueType.None, blackList, BindingFlags.Default); + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// The member names to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, params string[] memberName) + { + return FromObject(obj, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberWhiteList(memberName), BindingFlags.Default); + } + else + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberBlackList(memberName), BindingFlags.Default); + } + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// The member names to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, ObjectValueType membersToStore, params string[] memberName) + { + return FromObject(obj, membersToStore, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, ObjectValueType membersToStore, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, membersToStore, new MemberWhiteList(memberName), BindingFlags.Default); + } + else + { + return FromObject(new[] { obj }, membersToStore, new MemberBlackList(memberName), BindingFlags.Default); + } + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// The Binding Flags that the members should have. + /// The member names to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, BindingFlags flags, params string[] memberName) + { + return FromObject(obj, flags, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// The Binding Flags that the members should have. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, BindingFlags flags, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberWhiteList(memberName), flags); + } + else + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberBlackList(memberName), flags); + } + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// The Binding Flags that the members should have. + /// The member names to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, ObjectValueType membersToStore, BindingFlags flags, params string[] memberName) + { + return FromObject(obj, flags, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// The Binding Flags that the members should have. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] obj, ObjectValueType membersToStore, BindingFlags flags, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, membersToStore, new MemberWhiteList(memberName), flags); + } + else + { + return FromObject(new[] { obj }, membersToStore, new MemberBlackList(memberName), flags); + } + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify which members to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, MemberWhiteList whiteList) + { + return FromObject(new[] { obj }, ObjectValueType.None, whiteList, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify which members to exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, MemberBlackList blackList) + { + return FromObject(new[] { obj }, ObjectValueType.None, blackList, BindingFlags.Default); + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, params string[] memberName) + { + return FromObject(obj, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberWhiteList(memberName), BindingFlags.Default); + } + else + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberBlackList(memberName), BindingFlags.Default); + } + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// The member names to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, params string[] memberName) + { + return FromObject(obj, membersToStore, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, membersToStore, new MemberWhiteList(memberName), BindingFlags.Default); + } + else + { + return FromObject(new[] { obj }, membersToStore, new MemberBlackList(memberName), BindingFlags.Default); + } + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// The Binding Flags that the members should have. + /// The member names to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, BindingFlags flags, params string[] memberName) + { + return FromObject(obj, flags, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// The Binding Flags that the members should have. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, BindingFlags flags, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberWhiteList(memberName), flags); + } + else + { + return FromObject(new[] { obj }, ObjectValueType.None, new MemberBlackList(memberName), flags); + } + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// The Binding Flags that the members should have. + /// The member names to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, BindingFlags flags, params string[] memberName) + { + return FromObject(obj, flags, true, memberName); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// The Binding Flags that the members should have. + /// If true, the memberName-Array has member names that should be included. + /// The member names to include/exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, BindingFlags flags, bool isWhiteList, params string[] memberName) + { + if (isWhiteList) + { + return FromObject(new[] { obj }, membersToStore, new MemberWhiteList(memberName), flags); + } + else + { + return FromObject(new[] { obj }, membersToStore, new MemberBlackList(memberName), flags); + } + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj) + { + return FromObject(new[] { obj }, ObjectValueType.None, (object)null, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore) + { + return FromObject(new[] { obj }, membersToStore, (object)null, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// Specify which members to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberWhiteList whiteList) + { + return FromObject(new[] { obj }, membersToStore, whiteList, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// Specify which members to exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberBlackList blackList) + { + return FromObject(new[] { obj }, membersToStore, blackList, BindingFlags.Default); + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, BindingFlags flags) + { + return FromObject(new[] { obj }, ObjectValueType.None, (object)null, flags); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, BindingFlags flags) + { + return FromObject(new[] { obj }, membersToStore, (object)null, flags); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// Specify which members to include. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberWhiteList whiteList, BindingFlags flags) + { + return FromObject(new[] { obj }, membersToStore, whiteList, flags); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The object that should be included. + /// Specify what member types to include. + /// Specify which members to exclude. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberBlackList blackList, BindingFlags flags) + { + return FromObject(new[] { obj }, membersToStore, blackList, flags); + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs) + { + return FromObject(objs, ObjectValueType.None, (object)null, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore) + { + return FromObject(objs, membersToStore, (object)null, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// Specify which members to include. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberWhiteList whiteList) + { + return FromObject(objs, membersToStore, whiteList, BindingFlags.Default); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// Specify which members to exclude. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberBlackList blackList) + { + return FromObject(objs, membersToStore, blackList, BindingFlags.Default); + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs, BindingFlags flags) + { + return FromObject(objs, ObjectValueType.None, (object)null, flags); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, BindingFlags flags) + { + return FromObject(objs, membersToStore, (object)null, flags); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// Specify which members to include. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberWhiteList whiteList, BindingFlags flags) + { + return FromObject(objs, membersToStore, whiteList, flags); + } + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// Specify which members to exclude. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberBlackList blackList, BindingFlags flags) + { + return FromObject(objs, membersToStore, blackList, flags); + } + + /// + /// Creates an History Point with Object States automaticly from input. + /// + /// The objects that should be included. + /// Specify what member types to include. + /// Specify which members to include. + /// The Binding Flags that the members should have. + /// A History Point with Object States. + private static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, object whiteOrBlackList, BindingFlags flags) + { + var hp = new HistoryPoint(); + if (whiteOrBlackList is null) + whiteOrBlackList = new MemberBlackList(); + bool isWhiteList = whiteOrBlackList is MemberWhiteList; + if (flags == BindingFlags.Default) + { + flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + } + + if (membersToStore == ObjectValueType.None) + { + membersToStore = ObjectValueType.Field | ObjectValueType.Property; + } + + foreach (object obj in objs) + { + if ((membersToStore & ObjectValueType.Field) == ObjectValueType.Field) + { + foreach (FieldInfo fi in obj.GetType().GetFields(flags)) + { + bool contains = Conversions.ToBoolean(((List)whiteOrBlackList).Contains(fi.Name)); + if (isWhiteList ? contains : !contains) + { + var os = new ObjectState(); + os.Object = obj; + os.MemberName = fi.Name; + os.MemberType = ObjectValueType.Field; + os.MemberFlags = flags; + os.ValueToPatch = fi.GetValue(obj); + hp.Entries.Add(os); + } + } + } + + if ((membersToStore & ObjectValueType.Property) == ObjectValueType.Property) + { + foreach (PropertyInfo pi in obj.GetType().GetProperties(flags)) + { + bool contains = Conversions.ToBoolean(((List)whiteOrBlackList).Contains(pi.Name)); + if (isWhiteList ? contains : !contains) + { + var os = new ObjectState(); + os.Object = obj; + os.MemberName = pi.Name; + os.MemberType = ObjectValueType.Property; + os.MemberFlags = flags; + os.ValueToPatch = pi.GetValue(obj); + hp.Entries.Add(os); + } + } + } + } + + return hp; + } + + /// + /// Combines some History Points to one. + /// + /// An array of History Points to combine. + /// One History Point that contains all Data of inputted History Points. + public static HistoryPoint Concat(params HistoryPoint[] hps) + { + return Concat(hps.FirstOrDefault()?.Name, hps); + } + + /// + /// Combines some History Points to one. + /// + /// An array of History Points to combine. + /// One History Point that contains all Data of inputted History Points. + public static HistoryPoint Concat(string newName, params HistoryPoint[] hps) + { + var hp = new HistoryPoint(); + foreach (HistoryPoint _hp in hps) + hp.Entries.AddRange(_hp.Entries); + return hp; + } + } +} \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/HistoryPoint.vb b/Pilz.Collections/SimpleHistory/HistoryPoint.vb deleted file mode 100644 index a023780..0000000 --- a/Pilz.Collections/SimpleHistory/HistoryPoint.vb +++ /dev/null @@ -1,543 +0,0 @@ -Imports System.Reflection - -Namespace SimpleHistory - - ''' - ''' Represent some Object States and Actions. - ''' - Public Class HistoryPoint - - ''' - ''' Represents the Name of this History Point - ''' - ''' - Public Property Name As String = "" - ''' - ''' A List of Object States and Actions. - ''' - ''' - Public ReadOnly Property Entries As New List(Of ObjectBase) - ''' - ''' Some data can be refered on this HistoryPoint. Don't know, in some situations this can be helpful. - ''' - Public ReadOnly Tag As Object = Nothing - - Public Function HasEntries(Of T As ObjectBase)() As Boolean - Return Entries.Where(Function(n) TypeOf n Is T).Count > 0 - End Function - - Friend Sub Undo() - For Each s As ObjectBase In Entries.OrderBy(Function(n) n.UndoPriority) - If TypeOf s Is ObjectState Then - CType(s, ObjectState).Patch() - ElseIf TypeOf s Is ObjectAction Then - CType(s, ObjectAction).Undo() - End If - Next - End Sub - - Friend Sub Redo() - For Each s As ObjectBase In Entries.OrderBy(Function(n) n.RedoPriority) - If TypeOf s Is ObjectState Then - CType(s, ObjectState).Patch() - ElseIf TypeOf s Is ObjectAction Then - CType(s, ObjectAction).Redo() - End If - Next - End Sub - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify which members to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), whiteList As MemberWhiteList) As HistoryPoint - Return FromObject({obj}, ObjectValueType.None, CObj(whiteList), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify which members to exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), blackList As MemberBlackList) As HistoryPoint - Return FromObject({obj}, ObjectValueType.None, CObj(blackList), BindingFlags.Default) - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' The member names to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberWhiteList(memberName)), BindingFlags.Default) - Else - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberBlackList(memberName)), BindingFlags.Default) - End If - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' The member names to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), membersToStore As ObjectValueType, ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, membersToStore, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), membersToStore As ObjectValueType, isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, membersToStore, CObj(New MemberWhiteList(memberName)), BindingFlags.Default) - Else - Return FromObject({obj}, membersToStore, CObj(New MemberBlackList(memberName)), BindingFlags.Default) - End If - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' The Binding Flags that the members should have. - ''' The member names to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), flags As BindingFlags, ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, flags, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' The Binding Flags that the members should have. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), flags As BindingFlags, isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberWhiteList(memberName)), flags) - Else - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberBlackList(memberName)), flags) - End If - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' The Binding Flags that the members should have. - ''' The member names to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), membersToStore As ObjectValueType, flags As BindingFlags, ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, flags, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' The Binding Flags that the members should have. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object(), membersToStore As ObjectValueType, flags As BindingFlags, isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, membersToStore, CObj(New MemberWhiteList(memberName)), flags) - Else - Return FromObject({obj}, membersToStore, CObj(New MemberBlackList(memberName)), flags) - End If - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify which members to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, whiteList As MemberWhiteList) As HistoryPoint - Return FromObject({obj}, ObjectValueType.None, CObj(whiteList), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify which members to exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, blackList As MemberBlackList) As HistoryPoint - Return FromObject({obj}, ObjectValueType.None, CObj(blackList), BindingFlags.Default) - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberWhiteList(memberName)), BindingFlags.Default) - Else - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberBlackList(memberName)), BindingFlags.Default) - End If - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' The member names to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, membersToStore, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, membersToStore, CObj(New MemberWhiteList(memberName)), BindingFlags.Default) - Else - Return FromObject({obj}, membersToStore, CObj(New MemberBlackList(memberName)), BindingFlags.Default) - End If - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' The Binding Flags that the members should have. - ''' The member names to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, flags As BindingFlags, ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, flags, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' The Binding Flags that the members should have. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, flags As BindingFlags, isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberWhiteList(memberName)), flags) - Else - Return FromObject({obj}, ObjectValueType.None, CObj(New MemberBlackList(memberName)), flags) - End If - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' The Binding Flags that the members should have. - ''' The member names to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, flags As BindingFlags, ParamArray memberName As String()) As HistoryPoint - Return FromObject(obj, flags, True, memberName) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' The Binding Flags that the members should have. - ''' If true, the memberName-Array has member names that should be included. - ''' The member names to include/exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, flags As BindingFlags, isWhiteList As Boolean, ParamArray memberName As String()) As HistoryPoint - If isWhiteList Then - Return FromObject({obj}, membersToStore, CObj(New MemberWhiteList(memberName)), flags) - Else - Return FromObject({obj}, membersToStore, CObj(New MemberBlackList(memberName)), flags) - End If - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object) As HistoryPoint - Return FromObject({obj}, ObjectValueType.None, CObj(Nothing), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType) As HistoryPoint - Return FromObject({obj}, membersToStore, CObj(Nothing), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' Specify which members to include. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, whiteList As MemberWhiteList) As HistoryPoint - Return FromObject({obj}, membersToStore, CObj(whiteList), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' Specify which members to exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, blackList As MemberBlackList) As HistoryPoint - Return FromObject({obj}, membersToStore, CObj(blackList), BindingFlags.Default) - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, flags As BindingFlags) As HistoryPoint - Return FromObject({obj}, ObjectValueType.None, CObj(Nothing), flags) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, flags As BindingFlags) As HistoryPoint - Return FromObject({obj}, membersToStore, CObj(Nothing), flags) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' Specify which members to include. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, whiteList As MemberWhiteList, flags As BindingFlags) As HistoryPoint - Return FromObject({obj}, membersToStore, CObj(whiteList), flags) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The object that should be included. - ''' Specify what member types to include. - ''' Specify which members to exclude. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, blackList As MemberBlackList, flags As BindingFlags) As HistoryPoint - Return FromObject({obj}, membersToStore, CObj(blackList), flags) - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object()) As HistoryPoint - Return FromObject(objs, ObjectValueType.None, CObj(Nothing), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType) As HistoryPoint - Return FromObject(objs, membersToStore, CObj(Nothing), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' Specify which members to include. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType, whiteList As MemberWhiteList) As HistoryPoint - Return FromObject(objs, membersToStore, CObj(whiteList), BindingFlags.Default) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' Specify which members to exclude. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType, blackList As MemberBlackList) As HistoryPoint - Return FromObject(objs, membersToStore, CObj(blackList), BindingFlags.Default) - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object(), flags As BindingFlags) As HistoryPoint - Return FromObject(objs, ObjectValueType.None, CObj(Nothing), flags) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType, flags As BindingFlags) As HistoryPoint - Return FromObject(objs, membersToStore, CObj(Nothing), flags) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' Specify which members to include. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType, whiteList As MemberWhiteList, flags As BindingFlags) As HistoryPoint - Return FromObject(objs, membersToStore, CObj(whiteList), flags) - End Function - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' Specify which members to exclude. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType, blackList As MemberBlackList, flags As BindingFlags) As HistoryPoint - Return FromObject(objs, membersToStore, CObj(blackList), flags) - End Function - - ''' - ''' Creates an History Point with Object States automaticly from input. - ''' - ''' The objects that should be included. - ''' Specify what member types to include. - ''' Specify which members to include. - ''' The Binding Flags that the members should have. - ''' A History Point with Object States. - Private Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType, whiteOrBlackList As Object, flags As BindingFlags) As HistoryPoint - Dim hp As New HistoryPoint - - If whiteOrBlackList Is Nothing Then whiteOrBlackList = New MemberBlackList - Dim isWhiteList As Boolean = TypeOf whiteOrBlackList Is MemberWhiteList - - If flags = BindingFlags.Default Then - flags = BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic - End If - If membersToStore = ObjectValueType.None Then - membersToStore = ObjectValueType.Field Or ObjectValueType.Property - End If - - For Each obj As Object In objs - If (membersToStore And ObjectValueType.Field) = ObjectValueType.Field Then - - For Each fi As FieldInfo In obj.GetType.GetFields(flags) - - Dim contains As Boolean = whiteOrBlackList.Contains(fi.Name) - If If(isWhiteList, contains, Not contains) Then - - Dim os As New ObjectState - os.Object = obj - os.MemberName = fi.Name - os.MemberType = ObjectValueType.Field - os.MemberFlags = flags - os.ValueToPatch = fi.GetValue(obj) - hp.Entries.Add(os) - - End If - - Next - - End If - - If (membersToStore And ObjectValueType.Property) = ObjectValueType.Property Then - - For Each pi As PropertyInfo In obj.GetType.GetProperties(flags) - - Dim contains As Boolean = whiteOrBlackList.Contains(pi.Name) - If If(isWhiteList, contains, Not contains) Then - - Dim os As New ObjectState - os.Object = obj - os.MemberName = pi.Name - os.MemberType = ObjectValueType.Property - os.MemberFlags = flags - os.ValueToPatch = pi.GetValue(obj) - hp.Entries.Add(os) - - End If - - Next - - End If - Next - - Return hp - End Function - - ''' - ''' Combines some History Points to one. - ''' - ''' An array of History Points to combine. - ''' One History Point that contains all Data of inputted History Points. - Public Shared Function Concat(ParamArray hps As HistoryPoint()) As HistoryPoint - Return Concat(hps.FirstOrDefault?.Name, hps) - End Function - - ''' - ''' Combines some History Points to one. - ''' - ''' An array of History Points to combine. - ''' One History Point that contains all Data of inputted History Points. - Public Shared Function Concat(newName As String, ParamArray hps As HistoryPoint()) As HistoryPoint - Dim hp As New HistoryPoint - - For Each _hp As HistoryPoint In hps - hp.Entries.AddRange(_hp.Entries) - Next - - Return hp - End Function - - End Class - -End Namespace diff --git a/Pilz.Collections/SimpleHistory/MemberLists.cs b/Pilz.Collections/SimpleHistory/MemberLists.cs new file mode 100644 index 0000000..633279a --- /dev/null +++ b/Pilz.Collections/SimpleHistory/MemberLists.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; + +namespace Pilz.Collections.SimpleHistory +{ + + /// + /// List contianing member names to include. + /// + public class MemberWhiteList : List + { + public MemberWhiteList() : base() + { + } + + public MemberWhiteList(string[] entries) : base(entries) + { + } + } + + /// + /// List contianing member names to exclude + /// + public class MemberBlackList : List + { + public MemberBlackList() : base() + { + } + + public MemberBlackList(string[] entries) : base(entries) + { + } + } +} \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/MemberLists.vb b/Pilz.Collections/SimpleHistory/MemberLists.vb deleted file mode 100644 index 05fdf82..0000000 --- a/Pilz.Collections/SimpleHistory/MemberLists.vb +++ /dev/null @@ -1,33 +0,0 @@ -Namespace SimpleHistory - - ''' - ''' List contianing member names to include. - ''' - Public Class MemberWhiteList - Inherits List(Of String) - - Public Sub New() - MyBase.New - End Sub - - Public Sub New(entries As String()) - MyBase.New(entries) - End Sub - End Class - - ''' - ''' List contianing member names to exclude - ''' - Public Class MemberBlackList - Inherits List(Of String) - - Public Sub New() - MyBase.New - End Sub - - Public Sub New(entries As String()) - MyBase.New(entries) - End Sub - End Class - -End Namespace \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectAction.cs b/Pilz.Collections/SimpleHistory/ObjectAction.cs new file mode 100644 index 0000000..e749d36 --- /dev/null +++ b/Pilz.Collections/SimpleHistory/ObjectAction.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using global::System.Reflection; + +namespace Pilz.Collections.SimpleHistory +{ + public class ObjectAction : ObjectBase + { + public object Object { get; set; } = null; + public List ParametersUndo { get; private set; } = new List(); + public List ParametersRedo { get; private set; } = new List(); + public MethodInfo MethodUndo { get; set; } = null; + public MethodInfo MethodRedo { get; set; } = null; + public bool AutogenerateObject { get; set; } = true; + + /// + /// Creates a new Instance of Object Action. + /// + public ObjectAction() + { + } + + private object GetMethodInfo(object obj, string name, BindingFlags flags) + { + return obj.GetType().GetMethod(name, flags); + } + + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The name of the methode to call on Undo. + /// The name of the methode to call on Redo. + public ObjectAction(object obj, string methodNameUndo, string methodNameRedo) : this(obj, methodNameUndo, methodNameRedo, Array.Empty(), Array.Empty(), BindingFlags.Default, BindingFlags.Default) + { + } + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The name of the methode to call on Undo. + /// The name of the methode to call on Redo. + /// The parameters for calling the methode on Undo. + /// The parameters for calling the methode on Redo. + public ObjectAction(object obj, string methodNameUndo, string methodNameRedo, object[] paramsUndo, object[] paramsRedo) : this(obj, methodNameUndo, methodNameRedo, paramsUndo, paramsRedo, BindingFlags.Default, BindingFlags.Default) + { + } + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The name of the methode to call on Undo. + /// The name of the methode to call on Redo. + /// The parameters for calling the methode on Undo. + /// The parameters for calling the methode on Redo. + /// The Binding Flags of Methode on Undo. + /// The Binding Flags of Methode on Redo. + public ObjectAction(object obj, string methodNameUndo, string methodNameRedo, object[] paramsUndo, object[] paramsRedo, BindingFlags methodFlagsUndo, BindingFlags methodFlagsRedo) + { + Object = obj; + ParametersUndo.AddRange(paramsUndo); + ParametersRedo.AddRange(paramsRedo); + MethodUndo = (MethodInfo)GetMethodInfo(obj, methodNameUndo, GetFlags(methodFlagsUndo)); + MethodRedo = (MethodInfo)GetMethodInfo(obj, methodNameRedo, GetFlags(methodFlagsRedo)); + } + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The name of the methode to call on Undo. + /// The name of the methode to call on Redo. + /// The Binding Flags of Methode on Undo. + /// The Binding Flags of Methode on Redo. + public ObjectAction(object obj, string methodNameUndo, string methodNameRedo, BindingFlags methodFlagsUndo, BindingFlags methodFlagsRedo) : this(obj, methodNameUndo, methodNameRedo, Array.Empty(), Array.Empty(), methodFlagsUndo, methodFlagsRedo) + { + } + + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The MethodInfo of the methode to call on Undo. + /// The MethodInfo of the methode to call on Redo. + public ObjectAction(object obj, MethodInfo methodUndo, MethodInfo methodRedo) + { + Object = obj; + MethodUndo = methodUndo; + MethodRedo = methodRedo; + } + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The MethodInfo of the methode to call on Undo. + /// The MethodInfo of the methode to call on Redo. + /// The parameters for calling the methode on Undo. + /// The parameters for calling the methode on Redo. + public ObjectAction(object obj, MethodInfo methodUndo, MethodInfo methodRedo, object[] paramsUndo, object[] paramsRedo) : this(obj, methodUndo, methodRedo) + { + ParametersUndo.AddRange(paramsUndo); + ParametersRedo.AddRange(paramsRedo); + } + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The Delegate of the methode to call on Undo. + /// The Delegate of the methode to call on Redo. + public ObjectAction(object obj, Delegate methodUndo, Delegate methodRedo) + { + Object = obj; + MethodUndo = methodUndo.Method; + MethodRedo = methodRedo.Method; + } + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The Delegate of the methode to call on Undo. + /// The Delegate of the methode to call on Redo. + /// The parameters for calling the methode on Undo. + /// The parameters for calling the methode on Redo. + public ObjectAction(object obj, Delegate methodUndo, Delegate methodRedo, object[] paramsUndo, object[] paramsRedo) : this(obj, methodUndo, methodRedo) + { + ParametersUndo.AddRange(paramsUndo); + ParametersRedo.AddRange(paramsRedo); + } + /// + /// Creates a new Instance of Object Action. + /// + /// The Objects that contains the methodes to call. + /// The Action of the methode to call on Undo. + /// The Action of the methode to call on Redo. + public ObjectAction(object obj, Action methodUndo, Action methodRedo) + { + Object = obj; + MethodUndo = methodUndo.Method; + MethodRedo = methodRedo.Method; + } + + private BindingFlags GetFlags(BindingFlags flags) + { + if (flags == BindingFlags.Default) + { + flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + } + + return flags; + } + + internal void Undo() + { + CheckIfObjIsNothing(MethodUndo); + MethodUndo?.Invoke(Object, ParametersUndo.ToArray()); + } + + internal void Redo() + { + CheckIfObjIsNothing(MethodRedo); + MethodRedo?.Invoke(Object, ParametersRedo.ToArray()); + } + + private void CheckIfObjIsNothing(MethodInfo mi) + { + if (mi is object && !mi.IsStatic && AutogenerateObject) + { + if ((Object is null || Object.GetType() != mi.ReflectedType) && !mi.IsStatic) + { + var constructor = mi.ReflectedType.GetConstructor(Type.EmptyTypes); + var classObject = constructor.Invoke(Array.Empty()); + Object = classObject; + } + } + } + } +} \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectAction.vb b/Pilz.Collections/SimpleHistory/ObjectAction.vb deleted file mode 100644 index 7861237..0000000 --- a/Pilz.Collections/SimpleHistory/ObjectAction.vb +++ /dev/null @@ -1,165 +0,0 @@ -Imports System.Reflection -Imports System.Runtime.InteropServices - -Namespace SimpleHistory - - Public Class ObjectAction - Inherits ObjectBase - - Public Property [Object] As Object = Nothing - Public ReadOnly Property ParametersUndo As New List(Of Object) - Public ReadOnly Property ParametersRedo As New List(Of Object) - Public Property MethodUndo As MethodInfo = Nothing - Public Property MethodRedo As MethodInfo = Nothing - Public Property AutogenerateObject As Boolean = True - - ''' - ''' Creates a new Instance of Object Action. - ''' - Public Sub New() - End Sub - - Private Function GetMethodInfo(obj As Object, name As String, flags As BindingFlags) - Return obj.GetType.GetMethod(name, flags) - End Function - - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The name of the methode to call on Undo. - ''' The name of the methode to call on Redo. - Public Sub New(obj As Object, methodNameUndo As String, methodNameRedo As String) - Me.New(obj, methodNameUndo, methodNameRedo, {}, {}, BindingFlags.Default, BindingFlags.Default) - End Sub - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The name of the methode to call on Undo. - ''' The name of the methode to call on Redo. - ''' The parameters for calling the methode on Undo. - ''' The parameters for calling the methode on Redo. - Public Sub New(obj As Object, methodNameUndo As String, methodNameRedo As String, paramsUndo As Object(), paramsRedo As Object()) - Me.New(obj, methodNameUndo, methodNameRedo, paramsUndo, paramsRedo, BindingFlags.Default, BindingFlags.Default) - End Sub - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The name of the methode to call on Undo. - ''' The name of the methode to call on Redo. - ''' The parameters for calling the methode on Undo. - ''' The parameters for calling the methode on Redo. - ''' The Binding Flags of Methode on Undo. - ''' The Binding Flags of Methode on Redo. - Public Sub New(obj As Object, methodNameUndo As String, methodNameRedo As String, paramsUndo As Object(), paramsRedo As Object(), methodFlagsUndo As BindingFlags, methodFlagsRedo As BindingFlags) - [Object] = obj - ParametersUndo.AddRange(paramsUndo) - ParametersRedo.AddRange(paramsRedo) - MethodUndo = GetMethodInfo(obj, methodNameUndo, GetFlags(methodFlagsUndo)) - MethodRedo = GetMethodInfo(obj, methodNameRedo, GetFlags(methodFlagsRedo)) - End Sub - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The name of the methode to call on Undo. - ''' The name of the methode to call on Redo. - ''' The Binding Flags of Methode on Undo. - ''' The Binding Flags of Methode on Redo. - Public Sub New(obj As Object, methodNameUndo As String, methodNameRedo As String, methodFlagsUndo As BindingFlags, methodFlagsRedo As BindingFlags) - Me.New(obj, methodNameUndo, methodNameRedo, {}, {}, methodFlagsUndo, methodFlagsRedo) - End Sub - - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The MethodInfo of the methode to call on Undo. - ''' The MethodInfo of the methode to call on Redo. - Public Sub New(obj As Object, methodUndo As MethodInfo, methodRedo As MethodInfo) - [Object] = obj - Me.MethodUndo = methodUndo - Me.MethodRedo = methodRedo - End Sub - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The MethodInfo of the methode to call on Undo. - ''' The MethodInfo of the methode to call on Redo. - ''' The parameters for calling the methode on Undo. - ''' The parameters for calling the methode on Redo. - Public Sub New(obj As Object, methodUndo As MethodInfo, methodRedo As MethodInfo, paramsUndo As Object(), paramsRedo As Object()) - Me.New(obj, methodUndo, methodRedo) - ParametersUndo.AddRange(paramsUndo) - ParametersRedo.AddRange(paramsRedo) - End Sub - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The Delegate of the methode to call on Undo. - ''' The Delegate of the methode to call on Redo. - Public Sub New(obj As Object, methodUndo As [Delegate], methodRedo As [Delegate]) - [Object] = obj - Me.MethodUndo = methodUndo.Method - Me.MethodRedo = methodRedo.Method - End Sub - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The Delegate of the methode to call on Undo. - ''' The Delegate of the methode to call on Redo. - ''' The parameters for calling the methode on Undo. - ''' The parameters for calling the methode on Redo. - Public Sub New(obj As Object, methodUndo As [Delegate], methodRedo As [Delegate], paramsUndo As Object(), paramsRedo As Object()) - Me.New(obj, methodUndo, methodRedo) - ParametersUndo.AddRange(paramsUndo) - ParametersRedo.AddRange(paramsRedo) - End Sub - ''' - ''' Creates a new Instance of Object Action. - ''' - ''' The Objects that contains the methodes to call. - ''' The Action of the methode to call on Undo. - ''' The Action of the methode to call on Redo. - Public Sub New(obj As Object, methodUndo As Action, methodRedo As Action) - [Object] = obj - Me.MethodUndo = methodUndo.Method - Me.MethodRedo = methodRedo.Method - End Sub - - Private Function GetFlags(flags As BindingFlags) As BindingFlags - If flags = BindingFlags.Default Then - flags = BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic - End If - Return flags - End Function - - Friend Sub Undo() - CheckIfObjIsNothing(MethodUndo) - MethodUndo?.Invoke([Object], ParametersUndo.ToArray) - End Sub - - Friend Sub Redo() - CheckIfObjIsNothing(MethodRedo) - MethodRedo?.Invoke([Object], ParametersRedo.ToArray) - End Sub - - Private Sub CheckIfObjIsNothing(mi As MethodInfo) - If mi IsNot Nothing AndAlso Not mi.IsStatic AndAlso AutogenerateObject Then - If (Me.Object Is Nothing OrElse Me.Object.GetType <> mi.ReflectedType) AndAlso Not mi.IsStatic Then - Dim constructor As ConstructorInfo = mi.ReflectedType.GetConstructor(Type.EmptyTypes) - Dim classObject As Object = constructor.Invoke({}) - Me.Object = classObject - End If - End If - End Sub - - End Class - - -End Namespace \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectBase.cs b/Pilz.Collections/SimpleHistory/ObjectBase.cs new file mode 100644 index 0000000..8a60e54 --- /dev/null +++ b/Pilz.Collections/SimpleHistory/ObjectBase.cs @@ -0,0 +1,10 @@ + +namespace Pilz.Collections.SimpleHistory +{ + public class ObjectBase + { + public static int DefaultPriorityValue { get; set; } = 1000; + public int UndoPriority { get; set; } = DefaultPriorityValue; + public int RedoPriority { get; set; } = DefaultPriorityValue; + } +} \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectBase.vb b/Pilz.Collections/SimpleHistory/ObjectBase.vb deleted file mode 100644 index 76a201e..0000000 --- a/Pilz.Collections/SimpleHistory/ObjectBase.vb +++ /dev/null @@ -1,13 +0,0 @@ -Namespace SimpleHistory - - Public Class ObjectBase - - Public Shared Property DefaultPriorityValue As Integer = 1000 - - Public Property UndoPriority As Integer = DefaultPriorityValue - Public Property RedoPriority As Integer = DefaultPriorityValue - - End Class - - -End Namespace \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectState.cs b/Pilz.Collections/SimpleHistory/ObjectState.cs new file mode 100644 index 0000000..9eaa3c9 --- /dev/null +++ b/Pilz.Collections/SimpleHistory/ObjectState.cs @@ -0,0 +1,98 @@ +using System; +using global::System.Reflection; + +namespace Pilz.Collections.SimpleHistory +{ + public class ObjectState : ObjectBase + { + + /// + /// The Object including the members to patch. + /// + /// + public object Object { get; set; } = null; + /// + /// The name of the Member to patch. + /// + /// + public string MemberName { get; set; } = ""; + /// + /// The Value that should be patched. + /// + /// + public object ValueToPatch { get; set; } = null; + /// + /// The member types to include at searching for the member. + /// + /// + public ObjectValueType MemberType { get; set; } = ObjectValueType.Field; + /// + /// The Binding Flags that are used at searching for the member. + /// + /// + public BindingFlags MemberFlags { get; set; } = BindingFlags.Default; + + /// + /// Creates a new Instance of ObjectState from input. + /// + /// The Object including the members to patch. + /// The name of the Member to patch. + /// The member types to include at searching for the member. + /// The Binding Flags that are used at searching for the member. + public ObjectState(object obj, string valname, object valToPatch, ObjectValueType valtype) + { + Object = obj; + MemberName = valname; + ValueToPatch = valToPatch; + MemberType = valtype; + } + + /// + /// Creates a new Instance of ObjectState. + /// + public ObjectState() + { + } + + internal void Patch() + { + var t = Object.GetType(); + switch (MemberType) + { + case ObjectValueType.Field: + { + var f = t.GetField(MemberName, MemberFlags); + object temp = null; + if (f is object) + { + temp = f.GetValue(Object); + f.SetValue(Object, ValueToPatch); + ValueToPatch = temp; + } + + break; + } + + case ObjectValueType.Property: + { + var p = t.GetProperty(MemberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); + object temp = null; + if (p is object) + { + temp = p.GetValue(Object); + p.SetValue(Object, ValueToPatch); + ValueToPatch = temp; + } + + break; + } + + default: + { + throw new Exception("ValueType is invalid!"); + break; + } + } + } + } +} \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectState.vb b/Pilz.Collections/SimpleHistory/ObjectState.vb deleted file mode 100644 index 9678686..0000000 --- a/Pilz.Collections/SimpleHistory/ObjectState.vb +++ /dev/null @@ -1,84 +0,0 @@ -Imports System.Reflection - -Namespace SimpleHistory - - Public Class ObjectState - Inherits ObjectBase - - ''' - ''' The Object including the members to patch. - ''' - ''' - Public Property [Object] As Object = Nothing - ''' - ''' The name of the Member to patch. - ''' - ''' - Public Property MemberName As String = "" - ''' - ''' The Value that should be patched. - ''' - ''' - Public Property ValueToPatch As Object = Nothing - ''' - ''' The member types to include at searching for the member. - ''' - ''' - Public Property MemberType As ObjectValueType = ObjectValueType.Field - ''' - ''' The Binding Flags that are used at searching for the member. - ''' - ''' - Public Property MemberFlags As BindingFlags = BindingFlags.Default - - ''' - ''' Creates a new Instance of ObjectState from input. - ''' - ''' The Object including the members to patch. - ''' The name of the Member to patch. - ''' The member types to include at searching for the member. - ''' The Binding Flags that are used at searching for the member. - Public Sub New(obj As Object, valname As String, valToPatch As Object, valtype As ObjectValueType) - [Object] = obj - MemberName = valname - ValueToPatch = valToPatch - MemberType = valtype - End Sub - - ''' - ''' Creates a new Instance of ObjectState. - ''' - Public Sub New() - End Sub - - Friend Sub Patch() - Dim t As Type = [Object].GetType - Select Case MemberType - Case ObjectValueType.Field - Dim f As FieldInfo = t.GetField(MemberName, MemberFlags) - Dim temp As Object = Nothing - - If f IsNot Nothing Then - temp = f.GetValue([Object]) - f.SetValue([Object], ValueToPatch) - ValueToPatch = temp - End If - - Case ObjectValueType.Property - Dim p As PropertyInfo = t.GetProperty(MemberName, BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Static) - Dim temp As Object = Nothing - - If p IsNot Nothing Then - temp = p.GetValue([Object]) - p.SetValue([Object], ValueToPatch) - ValueToPatch = temp - End If - - Case Else - Throw New Exception("ValueType is invalid!") - End Select - End Sub - - End Class - -End Namespace \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectValueType.cs b/Pilz.Collections/SimpleHistory/ObjectValueType.cs new file mode 100644 index 0000000..57c0386 --- /dev/null +++ b/Pilz.Collections/SimpleHistory/ObjectValueType.cs @@ -0,0 +1,14 @@ + +namespace Pilz.Collections.SimpleHistory +{ + + /// + /// Specify which member types you would include. + /// + public enum ObjectValueType + { + None = 0, + Field = 1, + Property = 2 + } +} \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/ObjectValueType.vb b/Pilz.Collections/SimpleHistory/ObjectValueType.vb deleted file mode 100644 index 8438552..0000000 --- a/Pilz.Collections/SimpleHistory/ObjectValueType.vb +++ /dev/null @@ -1,12 +0,0 @@ -Namespace SimpleHistory - - ''' - ''' Specify which member types you would include. - ''' - Public Enum ObjectValueType - None = 0 - Field = 1 - [Property] = 2 - End Enum - -End Namespace \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/SimpleHistory.cs b/Pilz.Collections/SimpleHistory/SimpleHistory.cs new file mode 100644 index 0000000..3a76dbe --- /dev/null +++ b/Pilz.Collections/SimpleHistory/SimpleHistory.cs @@ -0,0 +1,104 @@ +using System.Collections.Generic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Collections.SimpleHistory +{ + public class HistoryStack + { + private Stack stackPast = new Stack(); + private Stack stackFuture = new Stack(); + + /// + /// Gets the count of history points. + /// + /// + public bool ChangesCount + { + get + { + return Conversions.ToBoolean(stackPast.Count); + } + } + + /// + /// Checks if the History has past changes. + /// + /// + public bool HasChanges() + { + return stackPast.Count > 0; + } + + /// + /// Patch Object States and call Undo Actions. + /// + public HistoryPoint Undo() + { + HistoryPoint ret; + if (stackPast.Count > 0) + { + var hp = stackPast.Pop(); + hp.Undo(); + stackFuture.Push(hp); + ret = hp; + } + else + { + ret = null; + } + + return ret; + } + + /// + /// Patch Object States and call Redo Actions. + /// + public HistoryPoint Redo() + { + HistoryPoint ret; + if (stackFuture.Count > 0) + { + var hp = stackFuture.Pop(); + hp.Redo(); + stackPast.Push(hp); + ret = hp; + } + else + { + ret = null; + } + + return ret; + } + + /// + /// Clear the History. + /// + public void Clear() + { + stackPast.Clear(); + stackFuture.Clear(); + } + + /// + /// Store a History Point. + /// + /// The History Point to add to the past changes. + /// The name to set for the History Point. + public void Store(HistoryPoint point, string newName) + { + point.Name = newName; + Store(point); + } + + /// + /// Store a History Point. + /// + /// The History Point to add to the past changes. + public void Store(HistoryPoint point) + { + stackPast.Push(point); + stackFuture.Clear(); + } + } +} \ No newline at end of file diff --git a/Pilz.Collections/SimpleHistory/SimpleHistory.vb b/Pilz.Collections/SimpleHistory/SimpleHistory.vb deleted file mode 100644 index a4d7d88..0000000 --- a/Pilz.Collections/SimpleHistory/SimpleHistory.vb +++ /dev/null @@ -1,93 +0,0 @@ -Imports System.Reflection - -Namespace SimpleHistory - - Public Class HistoryStack - - Private stackPast As New Stack(Of HistoryPoint) - Private stackFuture As New Stack(Of HistoryPoint) - - ''' - ''' Gets the count of history points. - ''' - ''' - Public ReadOnly Property ChangesCount As Boolean - Get - Return stackPast.Count - End Get - End Property - - ''' - ''' Checks if the History has past changes. - ''' - ''' - Public Function HasChanges() As Boolean - Return stackPast.Count > 0 - End Function - - ''' - ''' Patch Object States and call Undo Actions. - ''' - Public Function Undo() As HistoryPoint - Dim ret As HistoryPoint - - If stackPast.Count > 0 Then - Dim hp As HistoryPoint = stackPast.Pop - hp.Undo() - stackFuture.Push(hp) - ret = hp - Else - ret = Nothing - End If - - Return ret - End Function - - ''' - ''' Patch Object States and call Redo Actions. - ''' - Public Function Redo() As HistoryPoint - Dim ret As HistoryPoint - - If stackFuture.Count > 0 Then - Dim hp As HistoryPoint = stackFuture.Pop - hp.Redo() - stackPast.Push(hp) - ret = hp - Else - ret = Nothing - End If - - Return ret - End Function - - ''' - ''' Clear the History. - ''' - Public Sub Clear() - stackPast.Clear() - stackFuture.Clear() - End Sub - - ''' - ''' Store a History Point. - ''' - ''' The History Point to add to the past changes. - ''' The name to set for the History Point. - Public Sub Store(point As HistoryPoint, newName As String) - point.Name = newName - Store(point) - End Sub - - ''' - ''' Store a History Point. - ''' - ''' The History Point to add to the past changes. - Public Sub Store(point As HistoryPoint) - stackPast.Push(point) - stackFuture.Clear() - End Sub - - End Class - -End Namespace diff --git a/Pilz.Configuration/AutoSaveConfigurationManager.cs b/Pilz.Configuration/AutoSaveConfigurationManager.cs new file mode 100644 index 0000000..325a1ac --- /dev/null +++ b/Pilz.Configuration/AutoSaveConfigurationManager.cs @@ -0,0 +1,113 @@ +using System; + +namespace Pilz.Configuration +{ + public class AutoSaveConfigurationManager : ConfigurationManager + { + private bool addedHandler = false; + private bool enableAutoSave = false; + private string _ConfigFilePath = string.Empty; + private bool _AutoLoadConfigOnAccess = false; + + public string ConfigFilePath + { + get + { + return _ConfigFilePath; + } + + set + { + _ConfigFilePath = value; + if (AutoLoadConfigOnAccess) + Load(); + } + } + + public bool AutoLoadConfigOnAccess + { + get + { + return _AutoLoadConfigOnAccess; + } + + set + { + _AutoLoadConfigOnAccess = value; + if (value) + Load(); + } + } + + public bool AutoSaveConfigOnExit + { + get + { + return enableAutoSave; + } + + set + { + if (enableAutoSave != value) + { + enableAutoSave = value; + switch (enableAutoSave) + { + case true: + { + AddAutoSaveHandler(); + break; + } + + case false: + { + RemoveAutoSaveHandler(); + break; + } + } + } + } + } + + private void AddAutoSaveHandler() + { + if (!addedHandler) + { + System.Windows.Forms.Application.ApplicationExit += AutoSaveSettingsOnExit; + addedHandler = true; + } + } + + private void RemoveAutoSaveHandler() + { + System.Windows.Forms.Application.ApplicationExit -= AutoSaveSettingsOnExit; + addedHandler = false; + } + + private void AutoSaveSettingsOnExit(object sender, EventArgs e) + { + Save(); + } + + private void Save() + { + if (!string.IsNullOrEmpty(ConfigFilePath) && Configuration is object) + { + Configuration.WriteToFile(ConfigFilePath); + } + } + + private void Load() + { + if (!string.IsNullOrEmpty(ConfigFilePath)) + { + Configuration.ReadFromFile(ConfigFilePath); + } + } + + ~AutoSaveConfigurationManager() + { + RemoveAutoSaveHandler(); + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/AutoSaveConfigurationManager.vb b/Pilz.Configuration/AutoSaveConfigurationManager.vb deleted file mode 100644 index bb32d11..0000000 --- a/Pilz.Configuration/AutoSaveConfigurationManager.vb +++ /dev/null @@ -1,78 +0,0 @@ -Public Class AutoSaveConfigurationManager - Inherits ConfigurationManager - - Private addedHandler As Boolean = False - Private enableAutoSave As Boolean = False - Private _ConfigFilePath As String = String.Empty - Private _AutoLoadConfigOnAccess As Boolean = False - - Public Property ConfigFilePath As String - Get - Return _ConfigFilePath - End Get - Set - _ConfigFilePath = Value - If AutoLoadConfigOnAccess Then Load() - End Set - End Property - - Public Property AutoLoadConfigOnAccess As Boolean - Get - Return _AutoLoadConfigOnAccess - End Get - Set - _AutoLoadConfigOnAccess = Value - If Value Then Load() - End Set - End Property - - Public Property AutoSaveConfigOnExit As Boolean - Get - Return enableAutoSave - End Get - Set - If enableAutoSave <> Value Then - enableAutoSave = Value - Select Case enableAutoSave - Case True - AddAutoSaveHandler() - Case False - RemoveAutoSaveHandler() - End Select - End If - End Set - End Property - - Private Sub AddAutoSaveHandler() - If Not addedHandler Then - AddHandler Windows.Forms.Application.ApplicationExit, AddressOf AutoSaveSettingsOnExit - addedHandler = True - End If - End Sub - - Private Sub RemoveAutoSaveHandler() - RemoveHandler Windows.Forms.Application.ApplicationExit, AddressOf AutoSaveSettingsOnExit - addedHandler = False - End Sub - - Private Sub AutoSaveSettingsOnExit(sender As Object, e As EventArgs) - Save() - End Sub - - Private Sub Save() - If Not String.IsNullOrEmpty(ConfigFilePath) AndAlso Configuration IsNot Nothing Then - Configuration.WriteToFile(ConfigFilePath) - End If - End Sub - - Private Sub Load() - If Not String.IsNullOrEmpty(ConfigFilePath) Then - Configuration.ReadFromFile(ConfigFilePath) - End If - End Sub - - Protected Overrides Sub Finalize() - RemoveAutoSaveHandler() - End Sub - -End Class diff --git a/Pilz.Configuration/ConfigurationManager.cs b/Pilz.Configuration/ConfigurationManager.cs new file mode 100644 index 0000000..2e0da2b --- /dev/null +++ b/Pilz.Configuration/ConfigurationManager.cs @@ -0,0 +1,13 @@ + +namespace Pilz.Configuration +{ + public abstract class ConfigurationManager + { + public SimpleConfiguration Configuration { get; private set; } + + internal void SetConfiguration(SimpleConfiguration configuration) + { + Configuration = configuration; + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/ConfigurationManager.vb b/Pilz.Configuration/ConfigurationManager.vb deleted file mode 100644 index 772ece6..0000000 --- a/Pilz.Configuration/ConfigurationManager.vb +++ /dev/null @@ -1,9 +0,0 @@ -Public MustInherit Class ConfigurationManager - - Public ReadOnly Property Configuration As SimpleConfiguration - - Friend Sub SetConfiguration(configuration As SimpleConfiguration) - _Configuration = configuration - End Sub - -End Class diff --git a/Pilz.Configuration/ConfigurationManagerList.cs b/Pilz.Configuration/ConfigurationManagerList.cs new file mode 100644 index 0000000..abb88d3 --- /dev/null +++ b/Pilz.Configuration/ConfigurationManagerList.cs @@ -0,0 +1,104 @@ +using System.Collections; +using System.Collections.Generic; +using global::Pilz.GeneralEventArgs; + +namespace Pilz.Configuration +{ + public class ConfigurationManagerList : IList + { + public event GettingParentManagerEventHandler GettingParentManager; + + public delegate void GettingParentManagerEventHandler(object sender, GetValueEventArgs e); + + private readonly List myList = new List(); + + private object GetParentManager() + { + var args = new GetValueEventArgs(); + GettingParentManager?.Invoke(this, args); + return args.Value; + } + + public ConfigurationManager this[int index] + { + get + { + return myList[index]; + } + + set + { + myList[index] = value; + } + } + + public int Count + { + get + { + return myList.Count; + } + } + + public bool IsReadOnly + { + get + { + return false; + } + } + + public void Insert(int index, ConfigurationManager item) + { + myList.Insert(index, item); + item.SetConfiguration((SimpleConfiguration)GetParentManager()); + } + + public void RemoveAt(int index) + { + } + + public void Add(ConfigurationManager item) + { + item.SetConfiguration((SimpleConfiguration)GetParentManager()); + } + + public void Clear() + { + foreach (ConfigurationManager item in myList) + item.SetConfiguration(null); + myList.Clear(); + } + + public void CopyTo(ConfigurationManager[] array, int arrayIndex) + { + myList.CopyTo(array, arrayIndex); + } + + public int IndexOf(ConfigurationManager item) + { + return myList.IndexOf(item); + } + + public bool Contains(ConfigurationManager item) + { + return myList.Contains(item); + } + + public bool Remove(ConfigurationManager item) + { + item.SetConfiguration(null); + return myList.Remove(item); + } + + public IEnumerator GetEnumerator() + { + return GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return myList.GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/ConfigurationManagerList.vb b/Pilz.Configuration/ConfigurationManagerList.vb deleted file mode 100644 index c084885..0000000 --- a/Pilz.Configuration/ConfigurationManagerList.vb +++ /dev/null @@ -1,83 +0,0 @@ -Imports Pilz.Configuration -Imports Pilz.GeneralEventArgs - -Public Class ConfigurationManagerList - Implements IList(Of ConfigurationManager) - - Public Event GettingParentManager(sender As Object, e As GetValueEventArgs(Of SimpleConfiguration)) - - Private ReadOnly myList As New List(Of ConfigurationManager) - - Private Function GetParentManager() - Dim args As New GetValueEventArgs(Of SimpleConfiguration) - RaiseEvent GettingParentManager(Me, args) - Return args.Value - End Function - - Default Public Property Item(index As Integer) As ConfigurationManager Implements IList(Of ConfigurationManager).Item - Get - Return myList(index) - End Get - Set(value As ConfigurationManager) - myList(index) = value - End Set - End Property - - Public ReadOnly Property Count As Integer Implements ICollection(Of ConfigurationManager).Count - Get - Return myList.Count - End Get - End Property - - Public ReadOnly Property IsReadOnly As Boolean Implements ICollection(Of ConfigurationManager).IsReadOnly - Get - Return False - End Get - End Property - - Public Sub Insert(index As Integer, item As ConfigurationManager) Implements IList(Of ConfigurationManager).Insert - myList.Insert(index, item) - item.SetConfiguration(GetParentManager) - End Sub - - Public Sub RemoveAt(index As Integer) Implements IList(Of ConfigurationManager).RemoveAt - - End Sub - - Public Sub Add(item As ConfigurationManager) Implements ICollection(Of ConfigurationManager).Add - item.SetConfiguration(GetParentManager) - End Sub - - Public Sub Clear() Implements ICollection(Of ConfigurationManager).Clear - For Each item As ConfigurationManager In myList - item.SetConfiguration(Nothing) - Next - myList.Clear() - End Sub - - Public Sub CopyTo(array() As ConfigurationManager, arrayIndex As Integer) Implements ICollection(Of ConfigurationManager).CopyTo - myList.CopyTo(array, arrayIndex) - End Sub - - Public Function IndexOf(item As ConfigurationManager) As Integer Implements IList(Of ConfigurationManager).IndexOf - Return myList.IndexOf(item) - End Function - - Public Function Contains(item As ConfigurationManager) As Boolean Implements ICollection(Of ConfigurationManager).Contains - Return myList.Contains(item) - End Function - - Public Function Remove(item As ConfigurationManager) As Boolean Implements ICollection(Of ConfigurationManager).Remove - item.SetConfiguration(Nothing) - Return myList.Remove(item) - End Function - - Public Function GetEnumerator() As IEnumerator(Of ConfigurationManager) Implements IEnumerable(Of ConfigurationManager).GetEnumerator - Return IEnumerable_GetEnumerator() - End Function - - Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator - Return myList.GetEnumerator - End Function - -End Class diff --git a/Pilz.Configuration/ConfigurationSerializer.cs b/Pilz.Configuration/ConfigurationSerializer.cs new file mode 100644 index 0000000..aa64390 --- /dev/null +++ b/Pilz.Configuration/ConfigurationSerializer.cs @@ -0,0 +1,139 @@ +using global::System.IO; +using global::Newtonsoft.Json; +using global::Pilz.GeneralEventArgs; + +namespace Pilz.Configuration +{ + public static class ConfigurationSerializer + { + public static event GettingJsonSerializerEventHandler GettingJsonSerializer; + + public delegate void GettingJsonSerializerEventHandler(object instance, GetValueEventArgs e); + + private static JsonSerializer GetJsonSerializer(SimpleConfiguration instance) + { + var args = new GetValueEventArgs(JsonSerializer.CreateDefault()); + GettingJsonSerializer?.Invoke(instance, args); + return args.Value; + } + + /// + /// Writes the given instance to a string and return it. + /// + /// The configuration instance that should be serialized. + /// The content of the configuration instance as string. + public static string WriteToString(SimpleConfiguration instance) + { + var tw = new StringWriter(); + GetJsonSerializer(instance).Serialize(tw, instance); + string txt = tw.ToString(); + tw.Close(); + return txt; + } + + /// + /// Write the given instance to a given stream. + /// + /// The configuration instance that should be serialized. + /// The stream where the content should be written to. + public static void WriteToStream(SimpleConfiguration instance, Stream stream) + { + var sr = new StreamWriter(stream); + sr.Write(WriteToString(instance)); + } + + /// + /// Writes the given instance to the given filePath as text file. + /// + /// The configuration instance that should be serialized. + /// The file path where the content should be written to. The file will be created or overwritten. + public static void WriteToFile(SimpleConfiguration instance, string filePath) + { + var fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite); + WriteToStream(instance, fs); + fs.Close(); + } + + /// + /// Reads a configuratin from the given string and returns an instance of it. + /// + /// The type of the configuration class to instance. + /// The content of the configuration as string. + /// + public static T ReadFromString(string content) where T : SimpleConfiguration + { + var sr = new StringReader(content); + T instance = (T)GetJsonSerializer(null).Deserialize(sr, typeof(T)); + sr.Close(); + return instance; + } + + /// + /// Read a configuration from the given string and put them to the given instance. + /// + /// The instance to populate with the configuration. + /// The content of the configuration as string. + public static void ReadFromString(SimpleConfiguration instance, string content) + { + var sr = new StringReader(content); + GetJsonSerializer(null).Populate(sr, content); + sr.Close(); + } + + /// + /// Reads a configuratin from the given string and returns an instance of it. + /// + /// The type of the configuration class to instance. + /// The stream with the content of the configuration. + /// + public static T ReadFromStream(Stream stream) where T : SimpleConfiguration + { + return ReadFromString(GetContentOfStream(stream)); + } + + /// + /// Read a configuration from the given string and put them to the given instance. + /// + /// The instance to populate with the configuration. + /// The stream with the content of the configuration. + public static void ReadFromStream(SimpleConfiguration instance, Stream stream) + { + ReadFromString(instance, GetContentOfStream(stream)); + } + + /// + /// Reads a configuratin from the given string and returns an instance of it. + /// + /// The type of the configuration class to instance. + /// The path to the file with the content of the configuration. + /// + public static T ReadFromFile(string filePath) where T : SimpleConfiguration + { + return ReadFromString(GetContentOfFile(filePath)); + } + + /// + /// Read a configuration from the given string and put them to the given instance. + /// + /// The instance to populate with the configuration. + /// The path to the file with the content of the configuration. + public static void ReadFromFile(SimpleConfiguration instance, string filePath) + { + ReadFromString(instance, GetContentOfFile(filePath)); + } + + private static string GetContentOfStream(Stream stream) + { + var sr = new StreamReader(stream); + return sr.ReadToEnd(); + } + + private static string GetContentOfFile(string filePath) + { + var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); + string content = GetContentOfStream(fs); + fs.Close(); + return content; + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/ConfigurationSerializer.vb b/Pilz.Configuration/ConfigurationSerializer.vb deleted file mode 100644 index 6eb860f..0000000 --- a/Pilz.Configuration/ConfigurationSerializer.vb +++ /dev/null @@ -1,123 +0,0 @@ -Imports System.IO -Imports Newtonsoft.Json -Imports Pilz.GeneralEventArgs - -Public Module ConfigurationSerializer - - Public Event GettingJsonSerializer(instance As Object, e As GetValueEventArgs(Of JsonSerializer)) - - Private Function GetJsonSerializer(instance As SimpleConfiguration) As JsonSerializer - Dim args As New GetValueEventArgs(Of JsonSerializer)(JsonSerializer.CreateDefault) - RaiseEvent GettingJsonSerializer(instance, args) - Return args.Value - End Function - - ''' - ''' Writes the given instance to a string and return it. - ''' - ''' The configuration instance that should be serialized. - ''' The content of the configuration instance as string. - Public Function WriteToString(instance As SimpleConfiguration) As String - Dim tw As New StringWriter - GetJsonSerializer(instance).Serialize(tw, instance) - Dim txt = tw.ToString - tw.Close() - Return txt - End Function - - ''' - ''' Write the given instance to a given stream. - ''' - ''' The configuration instance that should be serialized. - ''' The stream where the content should be written to. - Public Sub WriteToStream(instance As SimpleConfiguration, stream As Stream) - Dim sr As New StreamWriter(stream) - sr.Write(WriteToString(instance)) - End Sub - - ''' - ''' Writes the given instance to the given filePath as text file. - ''' - ''' The configuration instance that should be serialized. - ''' The file path where the content should be written to. The file will be created or overwritten. - Public Sub WriteToFile(instance As SimpleConfiguration, filePath As String) - Dim fs As New FileStream(filePath, FileMode.Create, FileAccess.ReadWrite) - WriteToStream(instance, fs) - fs.Close() - End Sub - - ''' - ''' Reads a configuratin from the given string and returns an instance of it. - ''' - ''' The type of the configuration class to instance. - ''' The content of the configuration as string. - ''' - Public Function ReadFromString(Of T As SimpleConfiguration)(content As String) As T - Dim sr As New StringReader(content) - Dim instance As T = GetJsonSerializer(Nothing).Deserialize(sr, GetType(T)) - sr.Close() - Return instance - End Function - - ''' - ''' Read a configuration from the given string and put them to the given instance. - ''' - ''' The instance to populate with the configuration. - ''' The content of the configuration as string. - Public Sub ReadFromString(instance As SimpleConfiguration, content As String) - Dim sr As New StringReader(content) - GetJsonSerializer(Nothing).Populate(sr, content) - sr.Close() - End Sub - - ''' - ''' Reads a configuratin from the given string and returns an instance of it. - ''' - ''' The type of the configuration class to instance. - ''' The stream with the content of the configuration. - ''' - Public Function ReadFromStream(Of T As SimpleConfiguration)(stream As Stream) As T - Return ReadFromString(Of T)(GetContentOfStream(stream)) - End Function - - ''' - ''' Read a configuration from the given string and put them to the given instance. - ''' - ''' The instance to populate with the configuration. - ''' The stream with the content of the configuration. - Public Sub ReadFromStream(instance As SimpleConfiguration, stream As Stream) - ReadFromString(instance, GetContentOfStream(stream)) - End Sub - - ''' - ''' Reads a configuratin from the given string and returns an instance of it. - ''' - ''' The type of the configuration class to instance. - ''' The path to the file with the content of the configuration. - ''' - Public Function ReadFromFile(Of T As SimpleConfiguration)(filePath As String) As T - Return ReadFromString(Of T)(GetContentOfFile(filePath)) - End Function - - ''' - ''' Read a configuration from the given string and put them to the given instance. - ''' - ''' The instance to populate with the configuration. - ''' The path to the file with the content of the configuration. - Public Sub ReadFromFile(instance As SimpleConfiguration, filePath As String) - ReadFromString(instance, GetContentOfFile(filePath)) - End Sub - - Private Function GetContentOfStream(stream As Stream) As String - Dim sr As New StreamReader(stream) - Return sr.ReadToEnd - End Function - - Private Function GetContentOfFile(filePath As String) As String - Dim fs As New FileStream(filePath, FileMode.Open, FileAccess.Read) - Dim content = GetContentOfStream(fs) - fs.Close() - Return content - End Function - -End Module diff --git a/Pilz.Configuration/ISettingsManager.cs b/Pilz.Configuration/ISettingsManager.cs new file mode 100644 index 0000000..4f2d6cc --- /dev/null +++ b/Pilz.Configuration/ISettingsManager.cs @@ -0,0 +1,12 @@ + +namespace Pilz.Configuration +{ + public interface ISettingsManager + { + string ConfigFilePath { get; set; } + + void Save(); + void Load(); + void Reset(); + } +} \ No newline at end of file diff --git a/Pilz.Configuration/ISettingsManager.vb b/Pilz.Configuration/ISettingsManager.vb deleted file mode 100644 index 7be6f54..0000000 --- a/Pilz.Configuration/ISettingsManager.vb +++ /dev/null @@ -1,6 +0,0 @@ -Public Interface ISettingsManager - Property ConfigFilePath As String - Sub Save() - Sub Load() - Sub Reset() -End Interface \ No newline at end of file diff --git a/Pilz.Configuration/My Project/Application.Designer.cs b/Pilz.Configuration/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Configuration/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Configuration/My Project/Application.Designer.vb b/Pilz.Configuration/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Configuration/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Configuration/My Project/AssemblyInfo.vb b/Pilz.Configuration/My Project/AssemblyInfo.vb deleted file mode 100644 index d92aa5f..0000000 --- a/Pilz.Configuration/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Configuration/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Configuration/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..6807c42 --- /dev/null +++ b/Pilz.Configuration/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Configuration.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Configuration/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Configuration/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..9cf024a --- /dev/null +++ b/Pilz.Configuration/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Configuration.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Configuration/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Configuration/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Configuration/My Project/Resources.Designer.vb b/Pilz.Configuration/My Project/Resources.Designer.vb deleted file mode 100644 index e1545bd..0000000 --- a/Pilz.Configuration/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Configuration.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Configuration/My Project/Settings.Designer.vb b/Pilz.Configuration/My Project/Settings.Designer.vb deleted file mode 100644 index 190e071..0000000 --- a/Pilz.Configuration/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Configuration.My.MySettings - Get - Return Global.Pilz.Configuration.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Configuration/Pilz.Configuration.vbproj b/Pilz.Configuration/Pilz.Configuration.csproj similarity index 68% rename from Pilz.Configuration/Pilz.Configuration.vbproj rename to Pilz.Configuration/Pilz.Configuration.csproj index b71c249..766ddff 100644 --- a/Pilz.Configuration/Pilz.Configuration.vbproj +++ b/Pilz.Configuration/Pilz.Configuration.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC} + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C} Library Pilz.Configuration Pilz.Configuration @@ -13,6 +13,8 @@ v4.7.2 true + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -45,6 +47,7 @@ On + @@ -66,52 +69,55 @@ - - - - - - - - + + + + + + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Configuration.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Configuration.My + Settings.Designer.cs - - {277D2B83-7613-4C49-9CAB-E080195A6E0C} + + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC} Pilz @@ -120,5 +126,5 @@ 12.0.3 - + \ No newline at end of file diff --git a/Pilz.Configuration/Properties/AssemblyInfo.cs b/Pilz.Configuration/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5fb1f58 --- /dev/null +++ b/Pilz.Configuration/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("Pilz.Configuration")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("DRSN")] +[assembly: AssemblyProduct("Pilz.Configuration")] +[assembly: AssemblyCopyright("Copyright © DRSN 2019")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("3980caa6-d118-4166-8f0d-e91c9dc07e3c")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Configuration/Properties/Settings.Designer.cs b/Pilz.Configuration/Properties/Settings.Designer.cs new file mode 100644 index 0000000..8463906 --- /dev/null +++ b/Pilz.Configuration/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Configuration.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Configuration/My Project/Settings.settings b/Pilz.Configuration/Properties/Settings.settings similarity index 100% rename from Pilz.Configuration/My Project/Settings.settings rename to Pilz.Configuration/Properties/Settings.settings diff --git a/Pilz.Configuration/Resources.Designer.cs b/Pilz.Configuration/Resources.Designer.cs new file mode 100644 index 0000000..a730667 --- /dev/null +++ b/Pilz.Configuration/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Configuration.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Configuration.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/Resources.resx b/Pilz.Configuration/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Configuration/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.Configuration/SettingsBase.cs b/Pilz.Configuration/SettingsBase.cs new file mode 100644 index 0000000..7140e65 --- /dev/null +++ b/Pilz.Configuration/SettingsBase.cs @@ -0,0 +1,26 @@ +using global::Newtonsoft.Json; + +namespace Pilz.Configuration +{ + public abstract class SettingsBase + { + public SettingsBase() + { + ResetValues(); + } + + [JsonIgnore] + internal ISettingsManager _settingsManager; + + [JsonIgnore] + public ISettingsManager SettingsManager + { + get + { + return _settingsManager; + } + } + + public abstract void ResetValues(); + } +} \ No newline at end of file diff --git a/Pilz.Configuration/SettingsBase.vb b/Pilz.Configuration/SettingsBase.vb deleted file mode 100644 index 2f2ee29..0000000 --- a/Pilz.Configuration/SettingsBase.vb +++ /dev/null @@ -1,20 +0,0 @@ -Imports Newtonsoft.Json - -Public MustInherit Class SettingsBase - - Public Sub New() - ResetValues() - End Sub - - - Friend _settingsManager As ISettingsManager - - Public ReadOnly Property SettingsManager As ISettingsManager - Get - Return _settingsManager - End Get - End Property - - Public MustOverride Sub ResetValues() - -End Class diff --git a/Pilz.Configuration/SettingsManager.cs b/Pilz.Configuration/SettingsManager.cs new file mode 100644 index 0000000..8a40bc6 --- /dev/null +++ b/Pilz.Configuration/SettingsManager.cs @@ -0,0 +1,161 @@ +using System; +using global::System.IO; +using global::Newtonsoft.Json.Linq; + +namespace Pilz.Configuration +{ + public sealed class SettingsManager : ISettingsManager where T : SettingsBase + { + public event EventHandler AutoSavingSettings; + public event EventHandler SavingSettings; + public event EventHandler SavedSettings; + + private T defaultInstance = null; + private bool enableAutoSave = false; + private bool addedHandler = false; + + public string ConfigFilePath { get; set; } + + public bool AutoSaveOnExit + { + get + { + return enableAutoSave; + } + + set + { + if (enableAutoSave != value) + { + enableAutoSave = value; + switch (enableAutoSave) + { + case true: + { + if (!addedHandler) + { + AddAutoSaveHandler(); + } + + break; + } + + case false: + { + if (addedHandler) + { + RemoveAutoSaveHandler(); + } + + break; + } + } + } + } + } + + private void AddAutoSaveHandler() + { + System.Windows.Forms.Application.ApplicationExit += AutoSaveSettingsOnExit; + addedHandler = true; + } + + private void RemoveAutoSaveHandler() + { + System.Windows.Forms.Application.ApplicationExit -= AutoSaveSettingsOnExit; + addedHandler = false; + } + + public T Instance + { + get + { + if (defaultInstance is null) + { + Load(); + } + + return defaultInstance; + } + } + + public SettingsManager() + { + ConfigFilePath = ""; + AutoSaveOnExit = false; + } + + public SettingsManager(string fileName, bool autoSaveOnExit) + { + ConfigFilePath = fileName; + AutoSaveOnExit = autoSaveOnExit; + } + + private void AutoSaveSettingsOnExit(object sender, EventArgs e) + { + AutoSavingSettings?.Invoke(this, new EventArgs()); + Save(); + } + + public void Save() + { + if (!string.IsNullOrEmpty(ConfigFilePath) && defaultInstance is object) + { + SavePrivate(); + } + } + + public void Load() + { + if (!string.IsNullOrEmpty(ConfigFilePath) && File.Exists(ConfigFilePath)) + { + LoadPrivate(); + } + else + { + CreateNewInstance(); + } + + if (defaultInstance is object) + { + defaultInstance._settingsManager = this; + } + } + + public void Reset() + { + Instance.ResetValues(); + } + + private void CreateNewInstance() + { + var ctor = typeof(T).GetConstructor(Array.Empty()); + if (ctor is object) + { + defaultInstance = (T)ctor.Invoke(Array.Empty()); + defaultInstance.ResetValues(); + } + else + { + throw new Exception("The base type has no constructor with no parameters."); + } + } + + private void LoadPrivate() + { + defaultInstance = JObject.Parse(File.ReadAllText(ConfigFilePath)).ToObject(); + } + + private void SavePrivate() + { + SavingSettings?.Invoke(this, new EventArgs()); + var obj = JObject.FromObject(defaultInstance); + if (obj is object) + { + File.WriteAllText(ConfigFilePath, obj.ToString()); + } + + SavedSettings?.Invoke(this, new EventArgs()); + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/SettingsManager.vb b/Pilz.Configuration/SettingsManager.vb deleted file mode 100644 index 7639ab7..0000000 --- a/Pilz.Configuration/SettingsManager.vb +++ /dev/null @@ -1,119 +0,0 @@ -Imports System.IO -Imports System.Reflection -Imports Newtonsoft.Json.Linq - -Public NotInheritable Class SettingsManager(Of T As SettingsBase) - Implements ISettingsManager - - Public Event AutoSavingSettings As EventHandler - Public Event SavingSettings As EventHandler - Public Event SavedSettings As EventHandler - - Private defaultInstance As T = Nothing - Private enableAutoSave As Boolean = False - Private addedHandler As Boolean = False - - Public Property ConfigFilePath As String Implements ISettingsManager.ConfigFilePath - - Public Property AutoSaveOnExit As Boolean - Get - Return enableAutoSave - End Get - Set - If enableAutoSave <> Value Then - enableAutoSave = Value - Select Case enableAutoSave - Case True - If Not addedHandler Then - AddAutoSaveHandler() - End If - Case False - If addedHandler Then - RemoveAutoSaveHandler() - End If - End Select - End If - End Set - End Property - - Private Sub AddAutoSaveHandler() - AddHandler Windows.Forms.Application.ApplicationExit, AddressOf AutoSaveSettingsOnExit - addedHandler = True - End Sub - Private Sub RemoveAutoSaveHandler() - RemoveHandler Windows.Forms.Application.ApplicationExit, AddressOf AutoSaveSettingsOnExit - addedHandler = False - End Sub - - Public ReadOnly Property Instance As T - Get - If defaultInstance Is Nothing Then - Load() - End If - Return defaultInstance - End Get - End Property - - Public Sub New() - ConfigFilePath = "" - AutoSaveOnExit = False - End Sub - Public Sub New(fileName As String, autoSaveOnExit As Boolean) - ConfigFilePath = fileName - Me.AutoSaveOnExit = autoSaveOnExit - End Sub - - Private Sub AutoSaveSettingsOnExit(sender As Object, e As EventArgs) - RaiseEvent AutoSavingSettings(Me, New EventArgs) - Save() - End Sub - - Public Sub Save() Implements ISettingsManager.Save - If Not String.IsNullOrEmpty(ConfigFilePath) AndAlso defaultInstance IsNot Nothing Then - SavePrivate() - End If - End Sub - - Public Sub Load() Implements ISettingsManager.Load - If Not String.IsNullOrEmpty(ConfigFilePath) AndAlso File.Exists(ConfigFilePath) Then - LoadPrivate() - Else - CreateNewInstance() - End If - - If defaultInstance IsNot Nothing Then - defaultInstance._settingsManager = Me - End If - End Sub - - Public Sub Reset() Implements ISettingsManager.Reset - Instance.ResetValues() - End Sub - - Private Sub CreateNewInstance() - Dim ctor As ConstructorInfo = GetType(T).GetConstructor({}) - If ctor IsNot Nothing Then - defaultInstance = ctor.Invoke({}) - - defaultInstance.ResetValues() - Else - Throw New Exception("The base type has no constructor with no parameters.") - End If - End Sub - - Private Sub LoadPrivate() - defaultInstance = JObject.Parse(File.ReadAllText(ConfigFilePath)).ToObject(Of T) - End Sub - - Private Sub SavePrivate() - RaiseEvent SavingSettings(Me, New EventArgs) - - Dim obj As JObject = JObject.FromObject(defaultInstance) - If obj IsNot Nothing Then - File.WriteAllText(ConfigFilePath, obj.ToString) - End If - - RaiseEvent SavedSettings(Me, New EventArgs) - End Sub - -End Class diff --git a/Pilz.Configuration/SimpleConfiguration.cs b/Pilz.Configuration/SimpleConfiguration.cs new file mode 100644 index 0000000..84f6b31 --- /dev/null +++ b/Pilz.Configuration/SimpleConfiguration.cs @@ -0,0 +1,112 @@ +using global::System.IO; +using global::Newtonsoft.Json; +using global::Pilz.GeneralEventArgs; + +namespace Pilz.Configuration +{ + public class SimpleConfiguration + { + [JsonIgnore] + public readonly ConfigurationManagerList Managers = new ConfigurationManagerList(); + + public SimpleConfiguration() + { + Managers.GettingParentManager += Managers_GettingParentManager; + } + + private void Managers_GettingParentManager(object sender, GetValueEventArgs e) + { + if (ReferenceEquals(sender, Managers)) + { + e.Value = this; + } + } + + /// + /// Writes this instance to a string and return it. + /// + /// The content of the configuration instance as string. + public string WriteToString() + { + return ConfigurationSerializer.WriteToString(this); + } + + /// + /// Write this instance to a given stream. + /// + /// The stream where the content should be written to. + public void WriteToStream(Stream stream) + { + ConfigurationSerializer.WriteToStream(this, stream); + } + + /// + /// Writes this instance to the given filePath as text file. + /// + /// The file path where the content should be written to. The file will be created or overwritten. + public void WriteToFile(string filePath) + { + ConfigurationSerializer.WriteToFile(this, filePath); + } + + /// + /// Reads a configuratin from the given string and returns an instance of it. + /// + /// The type of the configuration class to instance. + /// The content of the configuration as string. + /// + public static T ReadFromString(string content) where T : SimpleConfiguration + { + return ConfigurationSerializer.ReadFromString(content); + } + + /// + /// Read a configuration from the given string and put them to this instance. + /// + /// The content of the configuration as string. + public void ReadFromString(string content) + { + ConfigurationSerializer.ReadFromString(this, content); + } + + /// + /// Reads a configuratin from the given string and returns an instance of it. + /// + /// The type of the configuration class to instance. + /// The stream with the content of the configuration. + /// + public static T ReadFromStream(Stream stream) where T : SimpleConfiguration + { + return ConfigurationSerializer.ReadFromStream(stream); + } + + /// + /// Read a configuration from the given string and put them to this instance. + /// + /// The stream with the content of the configuration. + public void ReadFromStream(Stream stream) + { + ConfigurationSerializer.ReadFromStream(this, stream); + } + + /// + /// Reads a configuratin from the given string and returns an instance of it. + /// + /// The type of the configuration class to instance. + /// The path to the file with the content of the configuration. + /// + public static T ReadFromFile(string filePath) where T : SimpleConfiguration + { + return ConfigurationSerializer.ReadFromFile(filePath); + } + + /// + /// Read a configuration from the given string and put them to this instance. + /// + /// The path to the file with the content of the configuration. + public void ReadFromFile(string filePath) + { + ConfigurationSerializer.ReadFromFile(this, filePath); + } + } +} \ No newline at end of file diff --git a/Pilz.Configuration/SimpleConfiguration.vb b/Pilz.Configuration/SimpleConfiguration.vb deleted file mode 100644 index 2dd432f..0000000 --- a/Pilz.Configuration/SimpleConfiguration.vb +++ /dev/null @@ -1,99 +0,0 @@ -Imports System.IO -Imports Newtonsoft.Json -Imports Pilz.Configuration -Imports Pilz.GeneralEventArgs - -Public Class SimpleConfiguration - - - Public ReadOnly Managers As New ConfigurationManagerList - - Public Sub New() - AddHandler Managers.GettingParentManager, AddressOf Managers_GettingParentManager - End Sub - - Private Sub Managers_GettingParentManager(sender As Object, e As GetValueEventArgs(Of SimpleConfiguration)) - If sender Is Managers Then - e.Value = Me - End If - End Sub - - ''' - ''' Writes this instance to a string and return it. - ''' - ''' The content of the configuration instance as string. - Public Function WriteToString() As String - Return ConfigurationSerializer.WriteToString(Me) - End Function - - ''' - ''' Write this instance to a given stream. - ''' - ''' The stream where the content should be written to. - Public Sub WriteToStream(stream As Stream) - ConfigurationSerializer.WriteToStream(Me, stream) - End Sub - - ''' - ''' Writes this instance to the given filePath as text file. - ''' - ''' The file path where the content should be written to. The file will be created or overwritten. - Public Sub WriteToFile(filePath As String) - ConfigurationSerializer.WriteToFile(Me, filePath) - End Sub - - ''' - ''' Reads a configuratin from the given string and returns an instance of it. - ''' - ''' The type of the configuration class to instance. - ''' The content of the configuration as string. - ''' - Public Shared Function ReadFromString(Of T As SimpleConfiguration)(content As String) As T - Return ConfigurationSerializer.ReadFromString(Of T)(content) - End Function - - ''' - ''' Read a configuration from the given string and put them to this instance. - ''' - ''' The content of the configuration as string. - Public Sub ReadFromString(content As String) - ConfigurationSerializer.ReadFromString(Me, content) - End Sub - - ''' - ''' Reads a configuratin from the given string and returns an instance of it. - ''' - ''' The type of the configuration class to instance. - ''' The stream with the content of the configuration. - ''' - Public Shared Function ReadFromStream(Of T As SimpleConfiguration)(stream As Stream) As T - Return ConfigurationSerializer.ReadFromStream(Of T)(stream) - End Function - - ''' - ''' Read a configuration from the given string and put them to this instance. - ''' - ''' The stream with the content of the configuration. - Public Sub ReadFromStream(stream As Stream) - ConfigurationSerializer.ReadFromStream(Me, stream) - End Sub - - ''' - ''' Reads a configuratin from the given string and returns an instance of it. - ''' - ''' The type of the configuration class to instance. - ''' The path to the file with the content of the configuration. - ''' - Public Shared Function ReadFromFile(Of T As SimpleConfiguration)(filePath As String) As T - Return ConfigurationSerializer.ReadFromFile(Of T)(filePath) - End Function - - ''' - ''' Read a configuration from the given string and put them to this instance. - ''' - ''' The path to the file with the content of the configuration. - Public Sub ReadFromFile(filePath As String) - ConfigurationSerializer.ReadFromFile(Me, filePath) - End Sub - -End Class diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.cs new file mode 100644 index 0000000..22aa79c --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.cs @@ -0,0 +1,744 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using global::System.Windows.Forms; +using global::OpenTK; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN +{ + public class Camera + { + public event NeedSelectedObjectEventHandler NeedSelectedObject; + + public delegate void NeedSelectedObjectEventHandler(object sender, NeedSelectedObjectEventArgs e); + + public event PerspectiveChangedEventHandler PerspectiveChanged; + + public delegate void PerspectiveChangedEventHandler(object sender, EventArgs e); + + // P R I V A T E F I E L D S + + private readonly float TAU = (float)(Math.PI * 2d); + private CameraMode myCamMode = CameraMode.FLY; + private Vector3 pos = new Vector3(-5000.0f, 3000.0f, 4000.0f); + private Vector3 myLookat = new Vector3(0f, 0f, 0f); + private Vector3 myFarPoint = new Vector3(0f, 0f, 0f); + private Vector3 myNearPoint = new Vector3(0f, 0f, 0f); + private int lastMouseX = -1; + private int lastMouseY = -1; + private float CamAngleX = 0f; + private float CamAngleY = (float)-(Math.PI / 2d); + private bool resetMouse = true; + private float orbitDistance = 500.0f; + private float orbitTheta = 0.0f; + private float orbitPhi = 0.0f; + private LookDirection currentLookDirection; + private Vector3[] lookPositions = new Vector3[] { new Vector3(0f, 12500f, 0f), new Vector3(0f, -12500, 0f), new Vector3(-12500, 0f, 0f), new Vector3(12500f, 0f, 0f), new Vector3(0f, 0f, 12500f), new Vector3(0f, 0f, -12500) }; + + // A U T O M A T I C P R O P E R T I E S + + public float CamSpeedMultiplier { get; set; } = 1f; + + // P R O P E R T I E S + + public CameraMode CamMode + { + get + { + return myCamMode; + } + } + + public float Yaw + { + get + { + return CamAngleX; + } + } + + public float Pitch + { + get + { + return CamAngleY; + } + } + + public float Yaw_Degrees + { + get + { + return CamAngleX * (180.0f / 3.14159274f); + } + } + + public float Pitch_Degrees + { + get + { + return CamAngleY * (180.0f / 3.14159274f); + } + } + + public Vector3 Position + { + get + { + return pos; + } + + set + { + pos = value; + } + } + + public Vector3 LookAt + { + get + { + return myLookat; + } + + set + { + myLookat = value; + } + } + + public Vector3 NearPoint + { + get + { + return myNearPoint; + } + + set + { + myNearPoint = value; + } + } + + public Vector3 FarPoint + { + get + { + return myFarPoint; + } + + set + { + myFarPoint = value; + } + } + + // C O N S T R U C T O R + + public Camera() + { + SetRotationFromLookAt(); + } + + // F E A T U R E S + + private float Clampf(float value, float min, float max) + { + return value > max ? max : value < min ? min : value; + } + + private void OrientateCam(float ang, float ang2) + { + float CamLX = (float)Math.Sin(ang) * (float)Math.Sin(-ang2); + float CamLY = (float)Math.Cos(ang2); + float CamLZ = (float)-Math.Cos(ang) * (float)Math.Sin(-ang2); + myLookat.X = pos.X + -CamLX * 100.0f; + myLookat.Y = pos.Y + -CamLY * 100.0f; + myLookat.Z = pos.Z + -CamLZ * 100.0f; + } + + private void OffsetCam(int xAmt, int yAmt, int zAmt) + { + double pitch_Renamed = CamAngleY - Math.PI / 2d; + float CamLX = (float)Math.Sin(CamAngleX) * (float)Math.Cos(-pitch_Renamed); + float CamLY = (float)Math.Sin(pitch_Renamed); + float CamLZ = (float)-Math.Cos(CamAngleX) * (float)Math.Cos(-pitch_Renamed); + pos.X = pos.X + xAmt * CamLX * CamSpeedMultiplier; + pos.Y = pos.Y + yAmt * CamLY * CamSpeedMultiplier; + pos.Z = pos.Z + zAmt * CamLZ * CamSpeedMultiplier; + } + + public void Move(float y, ref Matrix4 camMtx) + { + OffsetCam(0, (int)y, 0); + OrientateCam(CamAngleX, CamAngleY); + UpdateMatrix(ref camMtx); + } + + public void Move(float x, float z, ref Matrix4 camMtx) + { + UpdateCameraOffsetDirectly((int)x, (int)z, ref camMtx); + OrientateCam(CamAngleX, CamAngleY); + UpdateMatrix(ref camMtx); + } + + public void SetRotationFromLookAt() + { + float x_diff = myLookat.X - pos.X; + float y_diff = myLookat.Y - pos.Y; + float z_diff = myLookat.Z - pos.Z; + float dist = (float)Math.Sqrt(x_diff * x_diff + y_diff * y_diff + z_diff * z_diff); + if (z_diff == 0f) + { + z_diff = 0.001f; + } + + float nxz_ratio = -x_diff / z_diff; + if (z_diff < 0f) + { + CamAngleX = (float)(Math.Atan(nxz_ratio) + Math.PI); + } + else + { + CamAngleX = (float)Math.Atan(nxz_ratio); + } + + CamAngleY = -3.1459f - ((float)Math.Asin(y_diff / dist) - 1.57f); + } + + public void ResetOrbitToSelectedObject() + { + var objs = GetSelectedObject(); + if (objs?.Length > 0 == true) + { + orbitTheta = -(CalculateCenterYRotationOfObjects(objs) * ((float)Math.PI / 180.0f)); + orbitPhi = -0.3f; + orbitDistance = 1200.0f; + } + } + + public void UpdateOrbitCamera(ref Matrix4 cameraMatrix) + { + if (myCamMode == CameraMode.ORBIT) + { + var objs = GetSelectedObject(); + if (objs?.Length > 0 == true) + { + var centerPos = CalculateCenterPositionOfObjects(objs); + pos.X = centerPos.X + (float)(Math.Cos(orbitPhi) * -Math.Sin(orbitTheta) * orbitDistance); + pos.Y = centerPos.Y + (float)(-Math.Sin(orbitPhi) * orbitDistance); + pos.Z = centerPos.Z + (float)(Math.Cos(orbitPhi) * Math.Cos(orbitTheta) * orbitDistance); + myLookat.X = centerPos.X; + myLookat.Y = centerPos.Y; + myLookat.Z = centerPos.Z; + UpdateMatrix(ref cameraMatrix); + SetRotationFromLookAt(); + } + } + } + + public bool IsOrbitCamera() + { + return myCamMode == CameraMode.ORBIT; + } + + public void SetCameraMode(CameraMode mode, ref Matrix4 cameraMatrix) + { + myCamMode = mode; + if (IsOrbitCamera()) + { + ResetOrbitToSelectedObject(); + UpdateOrbitCamera(ref cameraMatrix); + } + } + + public void SetCameraMode_LookDirection(LookDirection dir, ref Matrix4 cameraMatrix) + { + myCamMode = CameraMode.LOOK_DIRECTION; + currentLookDirection = dir; + switch (currentLookDirection) + { + case LookDirection.Top: + { + pos = lookPositions[(int)LookDirection.Top]; + myLookat = new Vector3(pos.X, -25000, pos.Z - 1f); + UpdateMatrix(ref cameraMatrix); + SetRotationFromLookAt(); + break; + } + + case LookDirection.Bottom: + { + pos = lookPositions[(int)LookDirection.Bottom]; + myLookat = new Vector3(pos.X, 25000f, pos.Z + 1f); + UpdateMatrix(ref cameraMatrix); + SetRotationFromLookAt(); + break; + } + + case LookDirection.Left: + { + pos = lookPositions[(int)LookDirection.Left]; + myLookat = new Vector3(25000f, pos.Y, pos.Z); + UpdateMatrix(ref cameraMatrix); + SetRotationFromLookAt(); + break; + } + + case LookDirection.Right: + { + pos = lookPositions[(int)LookDirection.Right]; + myLookat = new Vector3(-25000, pos.Y, pos.Z); + UpdateMatrix(ref cameraMatrix); + SetRotationFromLookAt(); + break; + } + + case LookDirection.Front: + { + pos = lookPositions[(int)LookDirection.Front]; + myLookat = new Vector3(pos.X, pos.Y, -25000); + UpdateMatrix(ref cameraMatrix); + SetRotationFromLookAt(); + break; + } + + case LookDirection.Back: + { + pos = lookPositions[(int)LookDirection.Back]; + myLookat = new Vector3(pos.X, pos.Y, 25000f); + UpdateMatrix(ref cameraMatrix); + SetRotationFromLookAt(); + break; + } + } + } + + public void UpdateCameraMatrixWithMouse(int mouseX, int mouseY, ref Matrix4 cameraMatrix) + { + if (myCamMode == CameraMode.ORBIT && GetSelectedObject() is object) + { + UpdateCameraMatrixWithMouse_ORBIT(mouseX, mouseY, ref cameraMatrix); + } + else if (myCamMode == CameraMode.LOOK_DIRECTION) + { + UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, ref cameraMatrix); + } + else + { + UpdateCameraMatrixWithMouse_FLY(mouseX, mouseY, ref cameraMatrix); + } + } + + public void UpdateCameraOffsetWithMouse(Vector3 orgPos, int mouseX, int mouseY, int w, int h, ref Matrix4 cameraMatrix) + { + if (myCamMode == CameraMode.ORBIT && GetSelectedObject() is object) + { + UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, ref cameraMatrix); + } + else if (myCamMode == CameraMode.LOOK_DIRECTION) + { + UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, ref cameraMatrix); + } + else + { + UpdateCameraOffsetWithMouse_FLY(orgPos, mouseX, mouseY, w, h, ref cameraMatrix); + } + } + + public void UpdateCameraMatrixWithScrollWheel(int amt, ref Matrix4 cameraMatrix) + { + if (myCamMode == CameraMode.ORBIT && GetSelectedObject() is object) + { + UpdateCameraMatrixWithScrollWheel_ORBIT(amt, ref cameraMatrix); + } + else if (myCamMode == CameraMode.LOOK_DIRECTION) + { + UpdateCameraMatrixWithScrollWheel_LOOK(amt, ref cameraMatrix); + } + else + { + UpdateCameraMatrixWithScrollWheel_FLY(amt, ref cameraMatrix); + } + } + + private void UpdateCameraMatrixWithScrollWheel_FLY(int amt, ref Matrix4 cameraMatrix) + { + OffsetCam(amt, amt, amt); + OrientateCam(CamAngleX, CamAngleY); + UpdateMatrix(ref cameraMatrix); + } + + public void RaisePerspectiveChanged() + { + PerspectiveChanged?.Invoke(this, new EventArgs()); + } + + public void UpdateMatrix(ref Matrix4 cameraMatrix) + { + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z, 0f, 1f, 0f); + RaisePerspectiveChanged(); + } + + private void UpdateCameraMatrixWithScrollWheel_LOOK(int amt, ref Matrix4 cameraMatrix) + { + OffsetCam(amt, amt, amt); + OrientateCam(CamAngleX, CamAngleY); + switch (currentLookDirection) + { + case LookDirection.Top: + { + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z - 1f, 0f, 1f, 0f); + RaisePerspectiveChanged(); + break; + } + + case LookDirection.Bottom: + { + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z + 1f, 0f, 1f, 0f); + RaisePerspectiveChanged(); + break; + } + + default: + { + UpdateMatrix(ref cameraMatrix); + break; + } + } + } + + private void UpdateCameraMatrixWithMouse_LOOK(Vector3 orgPos, int mouseX, int mouseY, ref Matrix4 cameraMatrix) + { + if (resetMouse) + { + lastMouseX = mouseX; + lastMouseY = mouseY; + resetMouse = false; + } + + int MousePosX = mouseX - lastMouseX; + int MousePosY = mouseY - lastMouseY; + double pitch_Renamed = CamAngleY - Math.PI / 2d; + double yaw_Renamed = CamAngleX - Math.PI / 2d; + float CamLX = (float)Math.Sin(yaw_Renamed); + float CamLY = (float)Math.Cos(pitch_Renamed); + float CamLZ = (float)-Math.Cos(yaw_Renamed); + float m = 8.0f; + switch (currentLookDirection) + { + case LookDirection.Top: + { + pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m - MousePosY * CamSpeedMultiplier * CamLZ * m; + pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m - MousePosY * CamSpeedMultiplier * CamLX * m; + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y - 1000f, pos.Z - 1f, 0f, 1f, 0f); + lookPositions[(int)currentLookDirection] = pos; + break; + } + + case LookDirection.Bottom: + { + pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m + MousePosY * CamSpeedMultiplier * CamLZ * m; + pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m + MousePosY * CamSpeedMultiplier * CamLX * m; + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y + 1000f, pos.Z + 1f, 0f, 1f, 0f); + lookPositions[(int)currentLookDirection] = pos; + break; + } + + case LookDirection.Left: + { + pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m; + pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m; + pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m; + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X + 12500f, pos.Y, pos.Z, 0f, 1f, 0f); + lookPositions[(int)currentLookDirection] = pos; + break; + } + + case LookDirection.Right: + { + pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m; + pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m; + pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m; + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X - 12500f, pos.Y, pos.Z, 0f, 1f, 0f); + lookPositions[(int)currentLookDirection] = pos; + break; + } + + case LookDirection.Front: + { + pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m; + pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m; + pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m; + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z - 12500f, 0f, 1f, 0f); + lookPositions[(int)currentLookDirection] = pos; + break; + } + + case LookDirection.Back: + { + pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * m; + pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * m; + pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * m; + cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z + 12500f, 0f, 1f, 0f); + lookPositions[(int)currentLookDirection] = pos; + break; + } + } + + RaisePerspectiveChanged(); + lastMouseX = mouseX; + lastMouseY = mouseY; + // Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY); + // setRotationFromLookAt(); + } + + private void UpdateCameraMatrixWithMouse_FLY(int mouseX, int mouseY, ref Matrix4 cameraMatrix) + { + if (resetMouse) + { + lastMouseX = mouseX; + lastMouseY = mouseY; + resetMouse = false; + } + + int MousePosX = mouseX - lastMouseX; + int MousePosY = mouseY - lastMouseY; + CamAngleX = CamAngleX + 0.01f * MousePosX; + // This next part isn't neccessary, but it keeps the Yaw rotation value within [0, 2*pi] which makes debugging simpler. + if (CamAngleX > TAU) + { + CamAngleX -= TAU; + } + else if (CamAngleX < 0f) + { + CamAngleX += TAU; + } + + // Lock pitch rotation within the bounds of [-3.1399.0, -0.0001], otherwise the LookAt function will snap to the + // opposite side and reverse mouse looking controls. + CamAngleY = Clampf(CamAngleY + 0.01f * MousePosY, -3.1399f, -0.0001f); + lastMouseX = mouseX; + lastMouseY = mouseY; + OrientateCam(CamAngleX, CamAngleY); + UpdateMatrix(ref cameraMatrix); + // Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY); + // setRotationFromLookAt(); + } + + private void UpdateCameraOffsetWithMouse_FLY(Vector3 orgPos, int mouseX, int mouseY, int w, int h, ref Matrix4 cameraMatrix) + { + if (resetMouse) + { + lastMouseX = mouseX; + lastMouseY = mouseY; + resetMouse = false; + } + + int MousePosX = -mouseX + lastMouseX; + int MousePosY = -mouseY + lastMouseY; + double pitch_Renamed = CamAngleY - Math.PI / 2d; + double yaw_Renamed = CamAngleX - Math.PI / 2d; + float CamLX = (float)Math.Sin(yaw_Renamed); + float CamLZ = (float)-Math.Cos(yaw_Renamed); + pos.X = orgPos.X - MousePosX * CamSpeedMultiplier * CamLX * 6.0f; + pos.Y = orgPos.Y - MousePosY * CamSpeedMultiplier * -1.0f * 6.0f; + pos.Z = orgPos.Z - MousePosX * CamSpeedMultiplier * CamLZ * 6.0f; + OrientateCam(CamAngleX, CamAngleY); + UpdateMatrix(ref cameraMatrix); + } + + public void UpdateCameraOffsetDirectly(int horz_amount, int vert_amount, ref Matrix4 cameraMatrix) + { + if (myCamMode == CameraMode.ORBIT) + { + UpdateCameraOffsetDirectly_ORBIT((int)(horz_amount / 5d), (int)(vert_amount / 5d), ref cameraMatrix); + } + else + { + // Console.WriteLine(MousePosX+","+ MousePosY); + double pitch_Renamed = CamAngleY - Math.PI / 2d; + double yaw_Renamed = CamAngleX - Math.PI / 2d; + float CamLX = (float)Math.Sin(yaw_Renamed); + // float CamLY = (float)Math.Cos(pitch); + float CamLZ = (float)-Math.Cos(yaw_Renamed); + pos.X += horz_amount * CamSpeedMultiplier * CamLX; + pos.Y += vert_amount * CamSpeedMultiplier * -1.0f; + pos.Z += horz_amount * CamSpeedMultiplier * CamLZ; + OrientateCam(CamAngleX, CamAngleY); + UpdateMatrix(ref cameraMatrix); + } + } + + private void UpdateCameraOffsetDirectly_ORBIT(int moveSpeedX, int moveSpeedY, ref Matrix4 cameraMatrix) + { + int MousePosX = moveSpeedX; + int MousePosY = moveSpeedY; + orbitTheta += MousePosX * 0.01f * CamSpeedMultiplier; + orbitPhi -= MousePosY * 0.01f * CamSpeedMultiplier; + orbitPhi = Clampf(orbitPhi, -1.57f, 1.57f); + UpdateOrbitCamera(ref cameraMatrix); + } + + private void UpdateCameraMatrixWithMouse_ORBIT(int mouseX, int mouseY, ref Matrix4 cameraMatrix) + { + UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, ref cameraMatrix); + } + + private void UpdateCameraOffsetWithMouse_ORBIT(int mouseX, int mouseY, ref Matrix4 cameraMatrix) + { + if (resetMouse) + { + lastMouseX = mouseX; + lastMouseY = mouseY; + resetMouse = false; + } + + int MousePosX = -mouseX + lastMouseX; + int MousePosY = -mouseY + lastMouseY; + orbitTheta += MousePosX * 0.01f * CamSpeedMultiplier; + orbitPhi -= MousePosY * 0.01f * CamSpeedMultiplier; + orbitPhi = Clampf(orbitPhi, -1.57f, 1.57f); + UpdateOrbitCamera(ref cameraMatrix); + lastMouseX = mouseX; + lastMouseY = mouseY; + } + + private void UpdateCameraMatrixWithScrollWheel_ORBIT(int amt, ref Matrix4 cameraMatrix) + { + orbitDistance -= amt; + if (orbitDistance < 300.0f) + { + orbitDistance = 300.0f; + } + + UpdateOrbitCamera(ref cameraMatrix); + } + + public void ResetMouseStuff() + { + resetMouse = true; + } + + private System.Numerics.Vector3 CalculateCenterPositionOfObjects(ICameraPoint[] objs) + { + if (objs.Length <= 1) + { + var obj = objs.FirstOrDefault(); + if (obj is null) + { + return System.Numerics.Vector3.Zero; + } + else + { + return new System.Numerics.Vector3(obj.Position.X, obj.Position.Y, obj.Position.Z); + } + } + + float? maxX = default; + float? maxY = default; + float? maxZ = default; + float? minX = default; + float? minY = default; + float? minZ = default; + foreach (ICameraPoint obj in objs) + { + var pos = obj.Position; + if (maxX is null || pos.X > maxX) + maxX = pos.X; + if (maxY is null || pos.Y > maxY) + maxY = pos.Y; + if (maxZ is null || pos.Z > maxZ) + maxZ = pos.Z; + if (minX is null || pos.X < minX) + minX = pos.X; + if (minY is null || pos.Y < minY) + minY = pos.Y; + if (minZ is null || pos.Z < minZ) + minZ = pos.Z; + } + + if (maxX is null) + maxX = 0; + if (maxY is null) + maxY = 0; + if (maxZ is null) + maxZ = 0; + if (minX is null) + minX = 0; + if (minY is null) + minY = 0; + if (minZ is null) + minZ = 0; + var upper = new System.Numerics.Vector3((float)maxX, (float)maxY, (float)maxZ); + var lower = new System.Numerics.Vector3((float)minX, (float)minY, (float)minZ); + var middle = (upper + lower) / 2f; + return middle; + } + + private float CalculateCenterYRotationOfObjects(ICameraPoint[] objs) + { + if (objs.Length <= 1) + { + var obj = objs.FirstOrDefault(); + if (obj is null) + { + return 0f; + } + else + { + return obj.Rotation.Y; + } + } + + var yRot = new List(); + foreach (ICameraPoint obj in objs) + yRot.Add(obj.Rotation.Y); + return yRot.Average(); + } + + private ICameraPoint[] GetSelectedObject() + { + var e = new NeedSelectedObjectEventArgs(); + NeedSelectedObject?.Invoke(this, e); + var stopw = new Stopwatch(); + stopw.Start(); + while (!e.HasObjectSetted && stopw.ElapsedMilliseconds <= 1000L) + Application.DoEvents(); + stopw.Stop(); + return e.Points; + } + + // C A P S E L T C L A S S E S + + public class NeedSelectedObjectEventArgs : EventArgs + { + private bool _HasObjectSetted = false; + + public bool HasObjectSetted + { + get + { + return _HasObjectSetted; + } + } + + private ICameraPoint[] _Points = null; + + public ICameraPoint[] Points + { + get + { + return _Points; + } + + set + { + _Points = value; + _HasObjectSetted = true; + } + } + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.vb deleted file mode 100644 index e0e25e7..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.vb +++ /dev/null @@ -1,580 +0,0 @@ -Imports System.Windows.Forms -Imports OpenTK - -Namespace CameraN - - Public Class Camera - - Public Event NeedSelectedObject(sender As Object, e As NeedSelectedObjectEventArgs) - Public Event PerspectiveChanged(sender As Object, e As EventArgs) - - 'P R I V A T E F I E L D S - - Private ReadOnly TAU As Single = Math.PI * 2 - Private myCamMode As CameraMode = CameraMode.FLY - Private pos As New Vector3(-5000.0F, 3000.0F, 4000.0F) - Private myLookat As New Vector3(0F, 0F, 0F) - Private myFarPoint As New Vector3(0F, 0F, 0F) - Private myNearPoint As New Vector3(0F, 0F, 0F) - Private lastMouseX As Integer = -1, lastMouseY As Integer = -1 - Private CamAngleX As Single = 0F, CamAngleY As Single = -(Math.PI / 2) - Private resetMouse As Boolean = True - - Private orbitDistance As Single = 500.0F - Private orbitTheta As Single = 0.0F, orbitPhi As Single = 0.0F - - Private currentLookDirection As LookDirection - Private lookPositions() As Vector3 = { - New Vector3(0, 12500, 0), - New Vector3(0, -12500, 0), - New Vector3(-12500, 0, 0), - New Vector3(12500, 0, 0), - New Vector3(0, 0, 12500), - New Vector3(0, 0, -12500) - } - - 'A U T O M A T I C P R O P E R T I E S - - Public Property CamSpeedMultiplier As Single = 1 - - 'P R O P E R T I E S - - Public ReadOnly Property CamMode As CameraMode - Get - Return myCamMode - End Get - End Property - - Public ReadOnly Property Yaw As Single - Get - Return CamAngleX - End Get - End Property - - Public ReadOnly Property Pitch As Single - Get - Return CamAngleY - End Get - End Property - - Public ReadOnly Property Yaw_Degrees As Single - Get - Return CamAngleX * (180.0F / 3.14159274F) - End Get - End Property - - Public ReadOnly Property Pitch_Degrees As Single - Get - Return CamAngleY * (180.0F / 3.14159274F) - End Get - End Property - - Public Property Position As Vector3 - Get - Return pos - End Get - Set(value As Vector3) - pos = value - End Set - End Property - - Public Property LookAt As Vector3 - Get - Return myLookat - End Get - Set(value As Vector3) - myLookat = value - End Set - End Property - - Public Property NearPoint As Vector3 - Get - Return myNearPoint - End Get - Set(value As Vector3) - myNearPoint = value - End Set - End Property - - Public Property FarPoint As Vector3 - Get - Return myFarPoint - End Get - Set(value As Vector3) - myFarPoint = value - End Set - End Property - - 'C O N S T R U C T O R - - Public Sub New() - SetRotationFromLookAt() - End Sub - - 'F E A T U R E S - - Private Function Clampf(value As Single, min As Single, max As Single) As Single - Return If(value > max, max, If(value < min, min, value)) - End Function - - Private Sub OrientateCam(ang As Single, ang2 As Single) - Dim CamLX As Single = CSng(Math.Sin(ang)) * CSng(Math.Sin(-ang2)) - Dim CamLY As Single = CSng(Math.Cos(ang2)) - Dim CamLZ As Single = CSng(-Math.Cos(ang)) * CSng(Math.Sin(-ang2)) - - myLookat.X = pos.X + (-CamLX) * 100.0F - myLookat.Y = pos.Y + (-CamLY) * 100.0F - myLookat.Z = pos.Z + (-CamLZ) * 100.0F - End Sub - - Private Sub OffsetCam(xAmt As Integer, yAmt As Integer, zAmt As Integer) - Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2) - Dim CamLX As Single = CSng(Math.Sin(CamAngleX)) * CSng(Math.Cos(-pitch_Renamed)) - Dim CamLY As Single = CSng(Math.Sin(pitch_Renamed)) - Dim CamLZ As Single = CSng(-Math.Cos(CamAngleX)) * CSng(Math.Cos(-pitch_Renamed)) - pos.X = pos.X + xAmt * (CamLX) * CamSpeedMultiplier - pos.Y = pos.Y + yAmt * (CamLY) * CamSpeedMultiplier - pos.Z = pos.Z + zAmt * (CamLZ) * CamSpeedMultiplier - End Sub - - Public Sub Move(y As Single, ByRef camMtx As Matrix4) - OffsetCam(0, y, 0) - OrientateCam(CamAngleX, CamAngleY) - UpdateMatrix(camMtx) - End Sub - - Public Sub Move(x As Single, z As Single, ByRef camMtx As Matrix4) - UpdateCameraOffsetDirectly(x, z, camMtx) - OrientateCam(CamAngleX, CamAngleY) - UpdateMatrix(camMtx) - End Sub - - Public Sub SetRotationFromLookAt() - Dim x_diff As Single = myLookat.X - pos.X - Dim y_diff As Single = myLookat.Y - pos.Y - Dim z_diff As Single = myLookat.Z - pos.Z - Dim dist As Single = CSng(Math.Sqrt(x_diff * x_diff + y_diff * y_diff + z_diff * z_diff)) - If z_diff = 0 Then - z_diff = 0.001F - End If - Dim nxz_ratio As Single = -x_diff / z_diff - If z_diff < 0 Then - CamAngleX = CSng(Math.Atan(nxz_ratio) + Math.PI) - Else - CamAngleX = CSng(Math.Atan(nxz_ratio)) - End If - CamAngleY = -3.1459F - (CSng(Math.Asin(y_diff / dist)) - 1.57F) - End Sub - - Public Sub ResetOrbitToSelectedObject() - Dim objs As ICameraPoint() = GetSelectedObject() - If objs?.Length > 0 Then - orbitTheta = -(CalculateCenterYRotationOfObjects(objs) * (CSng(Math.PI) / 180.0F)) - orbitPhi = -0.3F - orbitDistance = 1200.0F - End If - End Sub - - Public Sub UpdateOrbitCamera(ByRef cameraMatrix As Matrix4) - If myCamMode = CameraMode.ORBIT Then - Dim objs As ICameraPoint() = GetSelectedObject() - If objs?.Length > 0 Then - Dim centerPos As Numerics.Vector3 = CalculateCenterPositionOfObjects(objs) - pos.X = centerPos.X + CSng(Math.Cos(orbitPhi) * -Math.Sin(orbitTheta) * orbitDistance) - pos.Y = centerPos.Y + CSng(-Math.Sin(orbitPhi) * orbitDistance) - pos.Z = centerPos.Z + CSng(Math.Cos(orbitPhi) * Math.Cos(orbitTheta) * orbitDistance) - myLookat.X = centerPos.X - myLookat.Y = centerPos.Y - myLookat.Z = centerPos.Z - UpdateMatrix(cameraMatrix) - SetRotationFromLookAt() - End If - End If - End Sub - - Public Function IsOrbitCamera() As Boolean - Return myCamMode = CameraMode.ORBIT - End Function - - Public Sub SetCameraMode(mode As CameraMode, ByRef cameraMatrix As Matrix4) - myCamMode = mode - If IsOrbitCamera() Then - ResetOrbitToSelectedObject() - UpdateOrbitCamera(cameraMatrix) - End If - End Sub - - Public Sub SetCameraMode_LookDirection(dir As LookDirection, ByRef cameraMatrix As Matrix4) - myCamMode = CameraMode.LOOK_DIRECTION - currentLookDirection = dir - Select Case currentLookDirection - Case LookDirection.Top - pos = lookPositions(CInt(LookDirection.Top)) - myLookat = New Vector3(pos.X, -25000, pos.Z - 1) - UpdateMatrix(cameraMatrix) - SetRotationFromLookAt() - Case LookDirection.Bottom - pos = lookPositions(CInt(LookDirection.Bottom)) - myLookat = New Vector3(pos.X, 25000, pos.Z + 1) - UpdateMatrix(cameraMatrix) - SetRotationFromLookAt() - Case LookDirection.Left - pos = lookPositions(CInt(LookDirection.Left)) - myLookat = New Vector3(25000, pos.Y, pos.Z) - UpdateMatrix(cameraMatrix) - SetRotationFromLookAt() - Case LookDirection.Right - pos = lookPositions(CInt(LookDirection.Right)) - myLookat = New Vector3(-25000, pos.Y, pos.Z) - UpdateMatrix(cameraMatrix) - SetRotationFromLookAt() - Case LookDirection.Front - pos = lookPositions(CInt(LookDirection.Front)) - myLookat = New Vector3(pos.X, pos.Y, -25000) - UpdateMatrix(cameraMatrix) - SetRotationFromLookAt() - Case LookDirection.Back - pos = lookPositions(CInt(LookDirection.Back)) - myLookat = New Vector3(pos.X, pos.Y, 25000) - UpdateMatrix(cameraMatrix) - SetRotationFromLookAt() - End Select - End Sub - - Public Sub UpdateCameraMatrixWithMouse(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4) - If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then - UpdateCameraMatrixWithMouse_ORBIT(mouseX, mouseY, cameraMatrix) - ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then - UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, cameraMatrix) - Else - UpdateCameraMatrixWithMouse_FLY(mouseX, mouseY, cameraMatrix) - End If - End Sub - - Public Sub UpdateCameraOffsetWithMouse(orgPos As Vector3, mouseX As Integer, mouseY As Integer, w As Integer, h As Integer, ByRef cameraMatrix As Matrix4) - If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then - UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, cameraMatrix) - ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then - UpdateCameraMatrixWithMouse_LOOK(pos, mouseX, mouseY, cameraMatrix) - Else - UpdateCameraOffsetWithMouse_FLY(orgPos, mouseX, mouseY, w, h, cameraMatrix) - End If - End Sub - - Public Sub UpdateCameraMatrixWithScrollWheel(amt As Integer, ByRef cameraMatrix As Matrix4) - If myCamMode = CameraMode.ORBIT AndAlso GetSelectedObject() IsNot Nothing Then - UpdateCameraMatrixWithScrollWheel_ORBIT(amt, cameraMatrix) - ElseIf myCamMode = CameraMode.LOOK_DIRECTION Then - UpdateCameraMatrixWithScrollWheel_LOOK(amt, cameraMatrix) - Else - UpdateCameraMatrixWithScrollWheel_FLY(amt, cameraMatrix) - End If - End Sub - - Private Sub UpdateCameraMatrixWithScrollWheel_FLY(amt As Integer, ByRef cameraMatrix As Matrix4) - OffsetCam(amt, amt, amt) - OrientateCam(CamAngleX, CamAngleY) - UpdateMatrix(cameraMatrix) - End Sub - - Public Sub RaisePerspectiveChanged() - RaiseEvent PerspectiveChanged(Me, New EventArgs) - End Sub - - Public Sub UpdateMatrix(ByRef cameraMatrix As Matrix4) - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z, 0, 1, 0) - RaisePerspectiveChanged() - End Sub - - Private Sub UpdateCameraMatrixWithScrollWheel_LOOK(amt As Integer, ByRef cameraMatrix As Matrix4) - OffsetCam(amt, amt, amt) - OrientateCam(CamAngleX, CamAngleY) - Select Case currentLookDirection - Case LookDirection.Top - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z - 1, 0, 1, 0) - RaisePerspectiveChanged() - Case LookDirection.Bottom - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, myLookat.X, myLookat.Y, myLookat.Z + 1, 0, 1, 0) - RaisePerspectiveChanged() - Case Else - UpdateMatrix(cameraMatrix) - End Select - End Sub - - Private Sub UpdateCameraMatrixWithMouse_LOOK(orgPos As Vector3, mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4) - If resetMouse Then - lastMouseX = mouseX - lastMouseY = mouseY - resetMouse = False - End If - Dim MousePosX As Integer = mouseX - lastMouseX - Dim MousePosY As Integer = mouseY - lastMouseY - - Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2) - Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2) - Dim CamLX As Single = CSng(Math.Sin(yaw_Renamed)) - Dim CamLY As Single = CSng(Math.Cos(pitch_Renamed)) - Dim CamLZ As Single = CSng(-Math.Cos(yaw_Renamed)) - - Dim m As Single = 8.0F - - Select Case currentLookDirection - Case LookDirection.Top - pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) - ((MousePosY * CamSpeedMultiplier) * (CamLZ) * m) - pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) - ((MousePosY * CamSpeedMultiplier) * (CamLX) * m) - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y - 1000, pos.Z - 1, 0, 1, 0) - lookPositions(CInt(currentLookDirection)) = pos - Case LookDirection.Bottom - pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) + ((MousePosY * CamSpeedMultiplier) * (CamLZ) * m) - pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) + ((MousePosY * CamSpeedMultiplier) * (CamLX) * m) - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y + 1000, pos.Z + 1, 0, 1, 0) - lookPositions(CInt(currentLookDirection)) = pos - Case LookDirection.Left - pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) - pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m) - pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X + 12500, pos.Y, pos.Z, 0, 1, 0) - lookPositions(CInt(currentLookDirection)) = pos - Case LookDirection.Right - pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) - pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m) - pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X - 12500, pos.Y, pos.Z, 0, 1, 0) - lookPositions(CInt(currentLookDirection)) = pos - Case LookDirection.Front - pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) - pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m) - pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z - 12500, 0, 1, 0) - lookPositions(CInt(currentLookDirection)) = pos - Case LookDirection.Back - pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * m) - pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * m) - pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * m) - cameraMatrix = Matrix4.LookAt(pos.X, pos.Y, pos.Z, pos.X, pos.Y, pos.Z + 12500, 0, 1, 0) - lookPositions(CInt(currentLookDirection)) = pos - End Select - - RaisePerspectiveChanged() - - lastMouseX = mouseX - lastMouseY = mouseY - 'Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY); - 'setRotationFromLookAt(); - End Sub - - Private Sub UpdateCameraMatrixWithMouse_FLY(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4) - If resetMouse Then - lastMouseX = mouseX - lastMouseY = mouseY - resetMouse = False - End If - Dim MousePosX As Integer = mouseX - lastMouseX - Dim MousePosY As Integer = mouseY - lastMouseY - CamAngleX = CamAngleX + (0.01F * MousePosX) - ' This next part isn't neccessary, but it keeps the Yaw rotation value within [0, 2*pi] which makes debugging simpler. - If CamAngleX > TAU Then - CamAngleX -= TAU - ElseIf CamAngleX < 0 Then - CamAngleX += TAU - End If - - ' Lock pitch rotation within the bounds of [-3.1399.0, -0.0001], otherwise the LookAt function will snap to the - ' opposite side and reverse mouse looking controls. - CamAngleY = Clampf((CamAngleY + (0.01F * MousePosY)), -3.1399F, -0.0001F) - - lastMouseX = mouseX - lastMouseY = mouseY - OrientateCam(CamAngleX, CamAngleY) - UpdateMatrix(cameraMatrix) - 'Console.WriteLine("CamAngleX = " + CamAngleX + ", CamAngleY = " + CamAngleY); - 'setRotationFromLookAt(); - End Sub - - Private Sub UpdateCameraOffsetWithMouse_FLY(orgPos As Vector3, mouseX As Integer, mouseY As Integer, w As Integer, h As Integer, ByRef cameraMatrix As Matrix4) - If resetMouse Then - lastMouseX = mouseX - lastMouseY = mouseY - resetMouse = False - End If - Dim MousePosX As Integer = (-mouseX) + lastMouseX - Dim MousePosY As Integer = (-mouseY) + lastMouseY - Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2) - Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2) - Dim CamLX As Single = Math.Sin(yaw_Renamed) - Dim CamLZ As Single = -Math.Cos(yaw_Renamed) - pos.X = orgPos.X - ((MousePosX * CamSpeedMultiplier) * (CamLX) * 6.0F) - pos.Y = orgPos.Y - ((MousePosY * CamSpeedMultiplier) * (-1.0F) * 6.0F) - pos.Z = orgPos.Z - ((MousePosX * CamSpeedMultiplier) * (CamLZ) * 6.0F) - - OrientateCam(CamAngleX, CamAngleY) - UpdateMatrix(cameraMatrix) - End Sub - - Public Sub UpdateCameraOffsetDirectly(horz_amount As Integer, vert_amount As Integer, ByRef cameraMatrix As Matrix4) - If myCamMode = CameraMode.ORBIT Then - UpdateCameraOffsetDirectly_ORBIT(horz_amount / 5, vert_amount / 5, cameraMatrix) - Else - 'Console.WriteLine(MousePosX+","+ MousePosY); - Dim pitch_Renamed As Double = CamAngleY - (Math.PI / 2) - Dim yaw_Renamed As Double = CamAngleX - (Math.PI / 2) - Dim CamLX As Single = CSng(Math.Sin(yaw_Renamed)) - ' float CamLY = (float)Math.Cos(pitch); - Dim CamLZ As Single = CSng(-Math.Cos(yaw_Renamed)) - pos.X += ((horz_amount * CamSpeedMultiplier) * (CamLX)) - pos.Y += ((vert_amount * CamSpeedMultiplier) * (-1.0F)) - pos.Z += ((horz_amount * CamSpeedMultiplier) * (CamLZ)) - - OrientateCam(CamAngleX, CamAngleY) - UpdateMatrix(cameraMatrix) - End If - End Sub - - Private Sub UpdateCameraOffsetDirectly_ORBIT(moveSpeedX As Integer, moveSpeedY As Integer, ByRef cameraMatrix As Matrix4) - Dim MousePosX As Integer = moveSpeedX - Dim MousePosY As Integer = moveSpeedY - orbitTheta += MousePosX * 0.01F * CamSpeedMultiplier - orbitPhi -= MousePosY * 0.01F * CamSpeedMultiplier - orbitPhi = Clampf(orbitPhi, -1.57F, 1.57F) - UpdateOrbitCamera(cameraMatrix) - End Sub - - Private Sub UpdateCameraMatrixWithMouse_ORBIT(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4) - UpdateCameraOffsetWithMouse_ORBIT(mouseX, mouseY, cameraMatrix) - End Sub - - Private Sub UpdateCameraOffsetWithMouse_ORBIT(mouseX As Integer, mouseY As Integer, ByRef cameraMatrix As Matrix4) - If resetMouse Then - lastMouseX = mouseX - lastMouseY = mouseY - resetMouse = False - End If - Dim MousePosX As Integer = (-mouseX) + lastMouseX - Dim MousePosY As Integer = (-mouseY) + lastMouseY - orbitTheta += MousePosX * 0.01F * CamSpeedMultiplier - orbitPhi -= MousePosY * 0.01F * CamSpeedMultiplier - orbitPhi = Clampf(orbitPhi, -1.57F, 1.57F) - UpdateOrbitCamera(cameraMatrix) - lastMouseX = mouseX - lastMouseY = mouseY - End Sub - - Private Sub UpdateCameraMatrixWithScrollWheel_ORBIT(amt As Integer, ByRef cameraMatrix As Matrix4) - orbitDistance -= amt - If orbitDistance < 300.0F Then - orbitDistance = 300.0F - End If - UpdateOrbitCamera(cameraMatrix) - End Sub - - Public Sub ResetMouseStuff() - resetMouse = True - End Sub - - Private Function CalculateCenterPositionOfObjects(objs As ICameraPoint()) As Numerics.Vector3 - If objs.Length <= 1 Then - Dim obj As ICameraPoint = objs.FirstOrDefault - If obj Is Nothing Then - Return Numerics.Vector3.Zero - Else - Return New Numerics.Vector3(obj.Position.X, - obj.Position.Y, - obj.Position.Z) - End If - End If - - Dim maxX As Single? = Nothing - Dim maxY As Single? = Nothing - Dim maxZ As Single? = Nothing - Dim minX As Single? = Nothing - Dim minY As Single? = Nothing - Dim minZ As Single? = Nothing - - For Each obj As ICameraPoint In objs - Dim pos As Numerics.Vector3 = obj.Position - If maxX Is Nothing OrElse pos.X > maxX Then maxX = pos.X - If maxY Is Nothing OrElse pos.Y > maxY Then maxY = pos.Y - If maxZ Is Nothing OrElse pos.Z > maxZ Then maxZ = pos.Z - If minX Is Nothing OrElse pos.X < minX Then minX = pos.X - If minY Is Nothing OrElse pos.Y < minY Then minY = pos.Y - If minZ Is Nothing OrElse pos.Z < minZ Then minZ = pos.Z - Next - - If maxX Is Nothing Then maxX = 0 - If maxY Is Nothing Then maxY = 0 - If maxZ Is Nothing Then maxZ = 0 - If minX Is Nothing Then minX = 0 - If minY Is Nothing Then minY = 0 - If minZ Is Nothing Then minZ = 0 - - Dim upper As New Numerics.Vector3(maxX, maxY, maxZ) - Dim lower As New Numerics.Vector3(minX, minY, minZ) - - Dim middle As Numerics.Vector3 = (upper + lower) / 2 - - Return middle - End Function - - Private Function CalculateCenterYRotationOfObjects(objs As ICameraPoint()) As Single - If objs.Length <= 1 Then - Dim obj As ICameraPoint = objs.FirstOrDefault - If obj Is Nothing Then - Return 0 - Else - Return obj.Rotation.Y - End If - End If - - Dim yRot As New List(Of Single) - - For Each obj As ICameraPoint In objs - yRot.Add(obj.Rotation.Y) - Next - - Return yRot.Average - End Function - - Private Function GetSelectedObject() As ICameraPoint() - Dim e As New NeedSelectedObjectEventArgs - RaiseEvent NeedSelectedObject(Me, e) - - Dim stopw As New Stopwatch - stopw.Start() - - Do Until e.HasObjectSetted OrElse stopw.ElapsedMilliseconds > 1000 - Application.DoEvents() - Loop - - stopw.Stop() - - Return e.Points - End Function - - 'C A P S E L T C L A S S E S - - Public Class NeedSelectedObjectEventArgs - Inherits EventArgs - - Private _HasObjectSetted As Boolean = False - Public ReadOnly Property HasObjectSetted As Boolean - Get - Return _HasObjectSetted - End Get - End Property - - Private _Points As ICameraPoint() = Nothing - Public Property Points As ICameraPoint() - Get - Return _Points - End Get - Set(value As ICameraPoint()) - _Points = value - _HasObjectSetted = True - End Set - End Property - - End Class - - End Class - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.cs new file mode 100644 index 0000000..6a9beb9 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.cs @@ -0,0 +1,10 @@ + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN +{ + public enum CameraMode + { + FLY = 0, + ORBIT = 1, + LOOK_DIRECTION = 2 + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.vb deleted file mode 100644 index 57564c6..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.vb +++ /dev/null @@ -1,9 +0,0 @@ -Namespace CameraN - - Public Enum CameraMode - FLY = 0 - ORBIT = 1 - LOOK_DIRECTION = 2 - End Enum - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/ICameraPoint.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/ICameraPoint.cs new file mode 100644 index 0000000..a1ecddf --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/ICameraPoint.cs @@ -0,0 +1,9 @@ + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN +{ + public interface ICameraPoint + { + System.Numerics.Vector3 Position { get; set; } + System.Numerics.Vector3 Rotation { get; set; } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/ICameraPoint.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/ICameraPoint.vb deleted file mode 100644 index 5fb91d1..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/ICameraPoint.vb +++ /dev/null @@ -1,10 +0,0 @@ -Namespace CameraN - - Public Interface ICameraPoint - - Property Position As Numerics.Vector3 - Property Rotation As Numerics.Vector3 - - End Interface - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/LookDirection.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/LookDirection.cs new file mode 100644 index 0000000..1e7ac03 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/LookDirection.cs @@ -0,0 +1,13 @@ + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN +{ + public enum LookDirection + { + Top, + Bottom, + Left, + Right, + Front, + Back + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/LookDirection.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/LookDirection.vb deleted file mode 100644 index 38853ac..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/LookDirection.vb +++ /dev/null @@ -1,12 +0,0 @@ -Namespace CameraN - - Public Enum LookDirection - Top - Bottom - Left - Right - Front - Back - End Enum - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/ModelPreview.Designer.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/ModelPreview.Designer.vb deleted file mode 100644 index 2e53c09..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/ModelPreview.Designer.vb +++ /dev/null @@ -1,120 +0,0 @@ - -Partial Class ModelPreview - Inherits DevComponents.DotNetBar.OfficeForm - - 'Form overrides dispose to clean up the component list. - - Protected Overrides Sub Dispose(ByVal disposing As Boolean) - Try - If disposing AndAlso components IsNot Nothing Then - components.Dispose() - End If - Finally - MyBase.Dispose(disposing) - End Try - End Sub - - 'Required by the Windows Form Designer - Private components As System.ComponentModel.IContainer - - 'NOTE: The following procedure is required by the Windows Form Designer - 'It can be modified using the Windows Form Designer. - 'Do not modify it using the code editor. - - Private Sub InitializeComponent() - Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ModelPreview)) - Me.PanelEx1 = New DevComponents.DotNetBar.PanelEx() - Me.PanelEx2 = New DevComponents.DotNetBar.PanelEx() - Me.DoubleInput1 = New DevComponents.Editors.DoubleInput() - Me.LabelX1 = New DevComponents.DotNetBar.LabelX() - Me.PanelEx2.SuspendLayout() - CType(Me.DoubleInput1, System.ComponentModel.ISupportInitialize).BeginInit() - Me.SuspendLayout() - ' - 'PanelEx1 - ' - Me.PanelEx1.CanvasColor = System.Drawing.Color.Empty - Me.PanelEx1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled - Me.PanelEx1.DisabledBackColor = System.Drawing.Color.Empty - Me.PanelEx1.Dock = System.Windows.Forms.DockStyle.Fill - Me.PanelEx1.Location = New System.Drawing.Point(0, 47) - Me.PanelEx1.Name = "PanelEx1" - Me.PanelEx1.Size = New System.Drawing.Size(880, 491) - Me.PanelEx1.Style.Alignment = System.Drawing.StringAlignment.Center - Me.PanelEx1.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder - Me.PanelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText - Me.PanelEx1.Style.GradientAngle = 90 - Me.PanelEx1.TabIndex = 0 - ' - 'PanelEx2 - ' - Me.PanelEx2.CanvasColor = System.Drawing.Color.Empty - Me.PanelEx2.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled - Me.PanelEx2.Controls.Add(Me.DoubleInput1) - Me.PanelEx2.Controls.Add(Me.LabelX1) - Me.PanelEx2.DisabledBackColor = System.Drawing.Color.Empty - Me.PanelEx2.Dock = System.Windows.Forms.DockStyle.Top - Me.PanelEx2.Location = New System.Drawing.Point(0, 0) - Me.PanelEx2.Name = "PanelEx2" - Me.PanelEx2.Size = New System.Drawing.Size(880, 47) - Me.PanelEx2.Style.Alignment = System.Drawing.StringAlignment.Center - Me.PanelEx2.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder - Me.PanelEx2.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText - Me.PanelEx2.Style.GradientAngle = 90 - Me.PanelEx2.TabIndex = 7 - Me.PanelEx2.Visible = False - ' - 'DoubleInput1 - ' - ' - ' - ' - Me.DoubleInput1.BackgroundStyle.Class = "DateTimeInputBackground" - Me.DoubleInput1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square - Me.DoubleInput1.ButtonFreeText.Shortcut = DevComponents.DotNetBar.eShortcut.F2 - Me.DoubleInput1.Increment = 1.0R - Me.DoubleInput1.Location = New System.Drawing.Point(62, 13) - Me.DoubleInput1.Name = "DoubleInput1" - Me.DoubleInput1.ShowUpDown = True - Me.DoubleInput1.Size = New System.Drawing.Size(80, 20) - Me.DoubleInput1.TabIndex = 0 - ' - 'LabelX1 - ' - ' - ' - ' - Me.LabelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square - Me.LabelX1.Location = New System.Drawing.Point(12, 12) - Me.LabelX1.Name = "LabelX1" - Me.LabelX1.Size = New System.Drawing.Size(44, 23) - Me.LabelX1.TabIndex = 1 - Me.LabelX1.Text = "Scaling:" - ' - 'ModelPreview - ' - Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) - Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(880, 538) - Me.Controls.Add(Me.PanelEx1) - Me.Controls.Add(Me.PanelEx2) - Me.DoubleBuffered = True - Me.EnableGlass = False - Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) - Me.KeyPreview = True - Me.Name = "ModelPreview" - Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen - Me.Text = "ModelPreview" - Me.TopLeftCornerSize = 0 - Me.TopRightCornerSize = 0 - Me.PanelEx2.ResumeLayout(False) - CType(Me.DoubleInput1, System.ComponentModel.ISupportInitialize).EndInit() - Me.ResumeLayout(False) - - End Sub - - Friend WithEvents PanelEx1 As DevComponents.DotNetBar.PanelEx - Friend WithEvents PanelEx2 As DevComponents.DotNetBar.PanelEx - Friend WithEvents DoubleInput1 As DevComponents.Editors.DoubleInput - Friend WithEvents LabelX1 As DevComponents.DotNetBar.LabelX -End Class diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/AssemblyInfo.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/AssemblyInfo.vb deleted file mode 100644 index 05b61da..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..536bf22 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..91d3de2 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Resources.Designer.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Resources.Designer.vb deleted file mode 100644 index 300e380..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Drawing.Drawing3D.OpenGLFactory.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Settings.Designer.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Settings.Designer.vb deleted file mode 100644 index 7ef730a..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Drawing.Drawing3D.OpenGLFactory.My.MySettings - Get - Return Global.Pilz.Drawing.Drawing3D.OpenGLFactory.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Pilz.Drawing.Drawing3D.OpenGLFactory.vbproj b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Pilz.Drawing.Drawing3D.OpenGLFactory.csproj similarity index 69% rename from Pilz.Drawing.Drawing3D.OpenGLRenderer/Pilz.Drawing.Drawing3D.OpenGLFactory.vbproj rename to Pilz.Drawing.Drawing3D.OpenGLRenderer/Pilz.Drawing.Drawing3D.OpenGLFactory.csproj index 849e34a..387c6ac 100644 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Pilz.Drawing.Drawing3D.OpenGLFactory.vbproj +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Pilz.Drawing.Drawing3D.OpenGLFactory.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84} + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824} Library Pilz.Drawing.Drawing3D.OpenGLFactory Pilz.Drawing.Drawing3D.OpenGLFactory @@ -12,6 +12,8 @@ Windows v4.7.2 + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -44,6 +46,7 @@ On + @@ -67,62 +70,65 @@ - - - - - ModelPreview.vb + + + + + + + + ModelPreview.cs - + Form - - - - - + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Drawing.Drawing3D.OpenGLFactory.My.Resources Designer - ModelPreview.vb + ModelPreview.cs MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Drawing.Drawing3D.OpenGLFactory.My + Settings.Designer.cs - - {ac955819-7910-450c-940c-7c1989483d4b} + + {1EB1D972-B548-0AFD-1654-B667EBDF09EB} Pilz.Simple3DFileParser @@ -137,5 +143,5 @@ 4.5.0 - + \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.cs new file mode 100644 index 0000000..92dd952 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.cs @@ -0,0 +1,52 @@ +using System; +using System.Diagnostics; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.PreviewN +{ + [Microsoft.VisualBasic.CompilerServices.DesignerGenerated()] + public partial class ModelPreview : System.Windows.Forms.Form + { + + // Form overrides dispose to clean up the component list. + [DebuggerNonUserCode()] + protected override void Dispose(bool disposing) + { + try + { + if (disposing && components is object) + { + components.Dispose(); + } + } + finally + { + base.Dispose(disposing); + } + } + + // Required by the Windows Form Designer + private System.ComponentModel.IContainer components; + + // NOTE: The following procedure is required by the Windows Form Designer + // It can be modified using the Windows Form Designer. + // Do not modify it using the code editor. + [DebuggerStepThrough()] + private void InitializeComponent() + { + var resources = new System.ComponentModel.ComponentResourceManager(typeof(ModelPreview)); + SuspendLayout(); + // + // ModelPreview + // + ClientSize = new System.Drawing.Size(880, 538); + DoubleBuffered = true; + Name = "ModelPreview"; + Text = "ModelPreview"; + Shown += new EventHandler(HandlesOnShown); + Activated += new EventHandler(HandlesOnActivated); + Deactivate += new EventHandler(HandlesOnDeactivate); + Disposed += new EventHandler(ModelPreview_FormDisposed); + ResumeLayout(false); + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.vb deleted file mode 100644 index 0ee6e5e..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.vb +++ /dev/null @@ -1,42 +0,0 @@ -Namespace PreviewN - - - Partial Class ModelPreview - Inherits System.Windows.Forms.Form - - 'Form overrides dispose to clean up the component list. - - Protected Overrides Sub Dispose(ByVal disposing As Boolean) - Try - If disposing AndAlso components IsNot Nothing Then - components.Dispose() - End If - Finally - MyBase.Dispose(disposing) - End Try - End Sub - - 'Required by the Windows Form Designer - Private components As System.ComponentModel.IContainer - - 'NOTE: The following procedure is required by the Windows Form Designer - 'It can be modified using the Windows Form Designer. - 'Do not modify it using the code editor. - - Private Sub InitializeComponent() - Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ModelPreview)) - Me.SuspendLayout() - ' - 'ModelPreview - ' - Me.ClientSize = New System.Drawing.Size(880, 538) - Me.DoubleBuffered = True - Me.Name = "ModelPreview" - Me.Text = "ModelPreview" - Me.ResumeLayout(False) - - End Sub - - End Class - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.cs new file mode 100644 index 0000000..5c6c62d --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.cs @@ -0,0 +1,487 @@ +using System; +using System.Collections.Generic; +using global::System.Drawing; +using Color = System.Drawing.Color; +using Point = System.Drawing.Point; +using System.Linq; +using System.Runtime.CompilerServices; +using global::System.Windows.Forms; +using global::OpenTK; +using global::OpenTK.Graphics.OpenGL; +using Key = OpenTK.Input.Key; +using Keyboard = OpenTK.Input.Keyboard; +using global::Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN; +using global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN; +using global::Pilz.S3DFileParser; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.PreviewN +{ + public partial class ModelPreview + { + public ModelPreview(Object3D[] objs, float scale) + { + MyCamera = new Camera(); + RenderTimer = new System.Timers.Timer(25d) { AutoReset = true }; + SuspendLayout(); + InitializeComponent(); + DoubleBuffered = true; + + // glControl1 + glControl1 = new GLControl(); + glControl1.BackColor = Color.Black; + glControl1.Location = new Point(0, 0); + glControl1.MinimumSize = new Size(600, 120); + glControl1.Name = "glControl1"; + glControl1.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom; + glControl1.Location = new Point(0, 0); + glControl1.Size = ClientSize; + glControl1.TabIndex = 0; + glControl1.TabStop = false; + glControl1.VSync = false; + Controls.Add(glControl1); + ResumeLayout(false); + + // RenderTimer.SynchronizingObject = Nothing + Scaling = scale; + + // Toolkit.Init() + + glControl1.CreateControl(); + glControl1.MouseWheel += glControl1_Wheel; + ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, (float)(glControl1.Width / (double)glControl1.Height), 100.0f, 100000.0f); + glControl1.Enabled = false; + MyCamera.SetCameraMode(CameraMode.FLY, ref camMtx); + MyCamera.UpdateMatrix(ref camMtx); + ResumeLayout(); + foreach (Object3D obj in objs) + AddModel(obj); + } + + private GLControl _glControl1; + + private GLControl glControl1 + { + [MethodImpl(MethodImplOptions.Synchronized)] + get + { + return _glControl1; + } + + [MethodImpl(MethodImplOptions.Synchronized)] + set + { + if (_glControl1 != null) + { + _glControl1.Load -= glControl1_Load; + _glControl1.Paint -= HandlesOnPaint; + _glControl1.Resize -= glControl1_Resize; + _glControl1.MouseDown -= glControl1_MouseDown; + _glControl1.MouseLeave -= glControl1_MouseLeave; + _glControl1.MouseUp -= glControl1_MouseLeave; + _glControl1.MouseMove -= glControl1_MouseMove; + } + + _glControl1 = value; + if (_glControl1 != null) + { + _glControl1.Load += glControl1_Load; + _glControl1.Paint += HandlesOnPaint; + _glControl1.Resize += glControl1_Resize; + _glControl1.MouseDown += glControl1_MouseDown; + _glControl1.MouseLeave += glControl1_MouseLeave; + _glControl1.MouseUp += glControl1_MouseLeave; + _glControl1.MouseMove += glControl1_MouseMove; + } + } + } + + private Camera _MyCamera; + + private Camera MyCamera + { + [MethodImpl(MethodImplOptions.Synchronized)] + get + { + return _MyCamera; + } + + [MethodImpl(MethodImplOptions.Synchronized)] + set + { + if (_MyCamera != null) + { + _MyCamera.NeedSelectedObject -= Camera_NeedSelectedObject; + _MyCamera.PerspectiveChanged -= MyCamera_PerspectiveChanged; + } + + _MyCamera = value; + if (_MyCamera != null) + { + _MyCamera.NeedSelectedObject += Camera_NeedSelectedObject; + _MyCamera.PerspectiveChanged += MyCamera_PerspectiveChanged; + } + } + } + + private Matrix4 ProjMatrix = default; + private float FOV = 1.048f; + private Matrix4 camMtx = Matrix4.Identity; + private Vector3 savedCamPos = new Vector3(); + private bool _isMouseDown = false; + private bool isDeactivated = false; + private readonly Dictionary myModels = new Dictionary(); + private System.Timers.Timer _RenderTimer; + + private System.Timers.Timer RenderTimer + { + [MethodImpl(MethodImplOptions.Synchronized)] + get + { + return _RenderTimer; + } + + [MethodImpl(MethodImplOptions.Synchronized)] + set + { + if (_RenderTimer != null) + { + _RenderTimer.Elapsed -= RenderTimer_Elapsed; + } + + _RenderTimer = value; + if (_RenderTimer != null) + { + _RenderTimer.Elapsed += RenderTimer_Elapsed; + } + } + } + + private bool _EnableCameraControlling = false; + + public float Scaling { get; set; } = 500.0f; + public Color ClearColor { get; set; } = Color.CornflowerBlue; + + public bool EnableCameraControlling + { + get + { + return _EnableCameraControlling; + } + + set + { + _EnableCameraControlling = value; + if (value) + { + if (!RenderTimer.Enabled) + { + RenderTimer.Start(); + } + } + else if (RenderTimer.Enabled) + { + RenderTimer.Stop(); + } + } + } + + public double RenderInterval + { + get + { + return RenderTimer.Interval; + } + + set + { + RenderTimer.Interval = value; + } + } + + public Camera Camera + { + get + { + return MyCamera; + } + } + + public Matrix4 CameraMatrix + { + get + { + return camMtx; + } + } + + public IReadOnlyDictionary Models + { + get + { + return myModels; + } + } + + public Control GLControl + { + get + { + return glControl1; + } + } + + private bool IsStrgPressed + { + get + { + var state = Keyboard.GetState(); + return state[Key.ControlLeft] || state[Key.ControlRight]; + } + } + + private bool IsShiftPressed + { + get + { + var state = Keyboard.GetState(); + return state[Key.ShiftLeft] || state[Key.ShiftRight]; + } + } + + public bool IsMouseDown + { + get + { + return _isMouseDown; + } + + set + { + _isMouseDown = value; + glControl1.Refresh(); + } + } + + public ModelPreview() : this(Array.Empty(), 1.0f) + { + } + + public ModelPreview(Object3D obj) : this(obj, 1.0f) + { + } + + public ModelPreview(Object3D obj, float scale) : this(new[] { obj }, scale) + { + } + + public void UpdateOrbitCamera() + { + if (Camera.IsOrbitCamera()) + { + Camera.UpdateOrbitCamera(ref camMtx); + } + } + + public void UpdateView() + { + if (glControl1.Enabled) + { + glControl1.Invoke(new Action(() => glControl1.Invalidate())); + } + } + + public Renderer AddModel(Object3D obj) + { + var rndr = new Renderer(obj); + AddModel(rndr); + return rndr; + } + + public void AddModel(Renderer rndr) + { + myModels.Add(rndr.Model, rndr); + } + + public void HandlesOnShown(object sender, EventArgs e) + { + glControl1.Enabled = true; + RenderModels(); + glControl1.Invalidate(); + } + + public void RenderModels() + { + foreach (Renderer rndr in myModels.Values) + RenderModel(rndr); + } + + public void RenderModel(Renderer rndr) + { + if (myModels.Values.Contains(rndr)) + { + rndr.ModelScaling = Scaling; + rndr.RenderModel(); + } + } + + private void glControl1_Load(object sender, EventArgs e) + { + GL.Enable(EnableCap.Blend); + GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + GL.Enable(EnableCap.DepthTest); + GL.DepthFunc(DepthFunction.Lequal); + GL.Enable(EnableCap.Texture2D); + GL.Enable(EnableCap.AlphaTest); + GL.AlphaFunc(AlphaFunction.Gequal, 0.5f); + GL.Enable(EnableCap.CullFace); + } + + public void HandlesOnActivated(object sender, EventArgs e) + { + if (isDeactivated) + { + isDeactivated = false; + } + } + + public void HandlesOnDeactivate(object sender, EventArgs e) + { + isDeactivated = true; + } + + private void RenderTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + if (!isDeactivated) + { + MoveCameraViaWASDQE(); + } + } + + public void HandlesOnPaint(object sender, PaintEventArgs e) + { + GL.ClearColor(ClearColor); + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + GL.MatrixMode(MatrixMode.Projection); + GL.LoadMatrix(ref ProjMatrix); + GL.MatrixMode(MatrixMode.Modelview); + GL.LoadMatrix(ref camMtx); + foreach (Renderer rndr in myModels.Values) + { + if (rndr.HasRendered) + { + rndr.DrawModel(RenderMode.FillOutline); + } + } + + glControl1.SwapBuffers(); + } + + private void glControl1_Resize(object sender, EventArgs e) + { + glControl1.Context.Update(glControl1.WindowInfo); + GL.Viewport(0, 0, glControl1.Width, glControl1.Height); + ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, (float)(glControl1.Width / (double)glControl1.Height), 100.0f, 100000.0f); + glControl1.Invalidate(); + } + + private void glControl1_Wheel(object sender, MouseEventArgs e) + { + MyCamera.ResetMouseStuff(); + MyCamera.UpdateCameraMatrixWithScrollWheel((int)Math.Truncate(e.Delta * (IsShiftPressed ? 3.5f : 1.5f)), ref camMtx); + savedCamPos = MyCamera.Position; + glControl1.Invalidate(); + } + + private void glControl1_MouseDown(object sender, MouseEventArgs e) + { + IsMouseDown = true; + savedCamPos = MyCamera.Position; + } + + private void glControl1_MouseLeave(object sender, EventArgs e) + { + MyCamera.ResetMouseStuff(); + IsMouseDown = false; + } + + private void glControl1_MouseMove(object sender, MouseEventArgs e) + { + if (IsMouseDown && e.Button == MouseButtons.Left) + { + if (IsShiftPressed) + { + MyCamera.UpdateCameraOffsetWithMouse(savedCamPos, e.X, e.Y, glControl1.Width, glControl1.Height, ref camMtx); + } + else + { + MyCamera.UpdateCameraMatrixWithMouse(e.X, e.Y, ref camMtx); + } + + glControl1.Invalidate(); + } + } + + public void MoveCameraViaWASDQE() + { + int moveSpeed = Convert.ToInt32(Math.Round((IsShiftPressed ? 60 : 30) * MyCamera.CamSpeedMultiplier, 0)); + bool allowCamMove = !(IsMouseDown && IsShiftPressed); + if (allowCamMove) + { + var state = Keyboard.GetState(); + if (state[Key.W]) + { + // camera.Move(moveSpeed, moveSpeed, camMtx) + MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, ref camMtx); + savedCamPos = MyCamera.Position; + } + + if (state[Key.S]) + { + // camera.Move(-moveSpeed, -moveSpeed, camMtx) + MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, ref camMtx); + savedCamPos = MyCamera.Position; + } + + if (state[Key.A]) + { + // camera.Move(-moveSpeed, 0, camMtx) + MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, ref camMtx); + } + + if (state[Key.D]) + { + // camera.Move(moveSpeed, 0, camMtx) + MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, ref camMtx); + } + + if (state[Key.E]) + { + // camera.Move(0, -moveSpeed, camMtx) + MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, ref camMtx); + } + + if (state[Key.Q]) + { + // camera.Move(0, moveSpeed, camMtx) + MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, ref camMtx); + } + } + } + + private void Camera_NeedSelectedObject(object sender, Camera.NeedSelectedObjectEventArgs e) + { + e.Points = null; + } + + private void MyCamera_PerspectiveChanged(object sender, EventArgs e) + { + UpdateView(); + } + + private void ModelPreview_FormDisposed(object sender, EventArgs e) + { + foreach (Renderer rndr in myModels.Values) + rndr.ReleaseBuffers(); + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb deleted file mode 100644 index a973f11..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.vb +++ /dev/null @@ -1,336 +0,0 @@ -Imports System.Drawing -Imports System.Windows.Forms -Imports Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN -Imports Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN -Imports OpenTK -Imports OpenTK.Graphics.OpenGL -Imports Pilz.S3DFileParser -Imports Point = System.Drawing.Point -Imports KeyboardState = OpenTK.Input.KeyboardState -Imports Keyboard = OpenTK.Input.Keyboard -Imports Key = OpenTK.Input.Key -Imports Color = System.Drawing.Color - -Namespace PreviewN - - Public Class ModelPreview - - Private WithEvents glControl1 As GLControl - Private WithEvents MyCamera As New Camera - Private ProjMatrix As Matrix4 = Nothing - Private FOV As Single = 1.048F - Private camMtx As Matrix4 = Matrix4.Identity - Private savedCamPos As New Vector3 - Private _isMouseDown As Boolean = False - Private isDeactivated As Boolean = False - Private ReadOnly myModels As New Dictionary(Of Object3D, Renderer) - Private WithEvents RenderTimer As New Timers.Timer(25) With {.AutoReset = True} - Private _EnableCameraControlling As Boolean = False - - Public Property Scaling As Single = 500.0F - Public Property ClearColor As Color = Color.CornflowerBlue - - Public Property EnableCameraControlling As Boolean - Get - Return _EnableCameraControlling - End Get - Set - _EnableCameraControlling = Value - If Value Then - If Not RenderTimer.Enabled Then - RenderTimer.Start() - End If - ElseIf RenderTimer.Enabled Then - RenderTimer.Stop() - End If - End Set - End Property - - Public Property RenderInterval As Double - Get - Return RenderTimer.Interval - End Get - Set - RenderTimer.Interval = Value - End Set - End Property - - Public ReadOnly Property Camera As Camera - Get - Return MyCamera - End Get - End Property - - Public ReadOnly Property CameraMatrix As Matrix4 - Get - Return camMtx - End Get - End Property - - Public ReadOnly Property Models As IReadOnlyDictionary(Of Object3D, Renderer) - Get - Return myModels - End Get - End Property - - Public ReadOnly Property GLControl As Control - Get - Return glControl1 - End Get - End Property - - Private ReadOnly Property IsStrgPressed As Boolean - Get - Dim state As KeyboardState = Keyboard.GetState() - Return state(Key.ControlLeft) OrElse state(Key.ControlRight) - End Get - End Property - - Private ReadOnly Property IsShiftPressed As Boolean - Get - Dim state As KeyboardState = Keyboard.GetState() - Return state(Key.ShiftLeft) OrElse state(Key.ShiftRight) - End Get - End Property - - Public Property IsMouseDown As Boolean - Get - Return _isMouseDown - End Get - Set(value As Boolean) - _isMouseDown = value - glControl1.Refresh() - End Set - End Property - - Public Sub New() - Me.New({}, 1.0F) - End Sub - - Public Sub New(obj As Object3D) - Me.New(obj, 1.0F) - End Sub - - Public Sub New(obj As Object3D, scale As Single) - Me.New({obj}, scale) - End Sub - - Public Sub New(objs As Object3D(), scale As Single) - Me.SuspendLayout() - - InitializeComponent() - DoubleBuffered = True - - 'glControl1 - Me.glControl1 = New GLControl - Me.glControl1.BackColor = Color.Black - Me.glControl1.Location = New Point(0, 0) - Me.glControl1.MinimumSize = New Size(600, 120) - Me.glControl1.Name = "glControl1" - Me.glControl1.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Bottom - Me.glControl1.Location = New Point(0, 0) - Me.glControl1.Size = Me.ClientSize - Me.glControl1.TabIndex = 0 - Me.glControl1.TabStop = False - Me.glControl1.VSync = False - Me.Controls.Add(Me.glControl1) - Me.ResumeLayout(False) - - 'RenderTimer.SynchronizingObject = Nothing - Scaling = scale - - 'Toolkit.Init() - - glControl1.CreateControl() - AddHandler glControl1.MouseWheel, AddressOf glControl1_Wheel - ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControl1.Width / glControl1.Height, 100.0F, 100000.0F) - glControl1.Enabled = False - - MyCamera.SetCameraMode(CameraMode.FLY, camMtx) - MyCamera.UpdateMatrix(camMtx) - - Me.ResumeLayout() - - For Each obj As Object3D In objs - AddModel(obj) - Next - End Sub - - Public Sub UpdateOrbitCamera() - If Camera.IsOrbitCamera Then - Camera.UpdateOrbitCamera(camMtx) - End If - End Sub - - Public Sub UpdateView() - If glControl1.Enabled Then - glControl1.Invoke(Sub() glControl1.Invalidate()) - End If - End Sub - - Public Function AddModel(obj As Object3D) As Renderer - Dim rndr As New Renderer(obj) - AddModel(rndr) - Return rndr - End Function - - Public Sub AddModel(rndr As Renderer) - myModels.Add(rndr.Model, rndr) - End Sub - - Public Sub HandlesOnShown(sender As Object, e As EventArgs) Handles MyBase.Shown - glControl1.Enabled = True - RenderModels() - glControl1.Invalidate() - End Sub - - Public Sub RenderModels() - For Each rndr As Renderer In myModels.Values - RenderModel(rndr) - Next - End Sub - - Public Sub RenderModel(rndr As Renderer) - If myModels.Values.Contains(rndr) Then - rndr.ModelScaling = Scaling - rndr.RenderModel() - End If - End Sub - - Private Sub glControl1_Load(sender As Object, e As EventArgs) Handles glControl1.Load - GL.Enable(EnableCap.Blend) - GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha) - - GL.Enable(EnableCap.DepthTest) - GL.DepthFunc(DepthFunction.Lequal) - - GL.Enable(EnableCap.Texture2D) - GL.Enable(EnableCap.AlphaTest) - GL.AlphaFunc(AlphaFunction.Gequal, 0.5F) - - GL.Enable(EnableCap.CullFace) - End Sub - - Public Sub HandlesOnActivated(sender As Object, e As EventArgs) Handles Me.Activated - If isDeactivated Then - isDeactivated = False - End If - End Sub - - Public Sub HandlesOnDeactivate(sender As Object, e As EventArgs) Handles Me.Deactivate - isDeactivated = True - End Sub - - Private Sub RenderTimer_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) Handles RenderTimer.Elapsed - If Not isDeactivated Then - MoveCameraViaWASDQE() - End If - End Sub - - Public Sub HandlesOnPaint(sender As Object, e As PaintEventArgs) Handles glControl1.Paint - GL.ClearColor(ClearColor) - - GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit) - - GL.MatrixMode(MatrixMode.Projection) - GL.LoadMatrix(ProjMatrix) - GL.MatrixMode(MatrixMode.Modelview) - GL.LoadMatrix(camMtx) - - For Each rndr As Renderer In myModels.Values - If rndr.HasRendered Then - rndr.DrawModel(RenderMode.FillOutline) - End If - Next - - glControl1.SwapBuffers() - End Sub - - Private Sub glControl1_Resize(sender As Object, e As EventArgs) Handles glControl1.Resize - glControl1.Context.Update(glControl1.WindowInfo) - GL.Viewport(0, 0, glControl1.Width, glControl1.Height) - ProjMatrix = Matrix4.CreatePerspectiveFieldOfView(FOV, glControl1.Width / glControl1.Height, 100.0F, 100000.0F) - glControl1.Invalidate() - End Sub - - Private Sub glControl1_Wheel(sender As Object, e As MouseEventArgs) - MyCamera.ResetMouseStuff() - MyCamera.UpdateCameraMatrixWithScrollWheel(CInt(Math.Truncate(e.Delta * (If(IsShiftPressed, 3.5F, 1.5F)))), camMtx) - savedCamPos = MyCamera.Position - glControl1.Invalidate() - End Sub - - Private Sub glControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles glControl1.MouseDown - IsMouseDown = True - savedCamPos = MyCamera.Position - End Sub - - Private Sub glControl1_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles glControl1.MouseLeave, glControl1.MouseUp - MyCamera.ResetMouseStuff() - IsMouseDown = False - End Sub - - Private Sub glControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles glControl1.MouseMove - If IsMouseDown AndAlso e.Button = MouseButtons.Left Then - If IsShiftPressed Then - MyCamera.UpdateCameraOffsetWithMouse(savedCamPos, e.X, e.Y, glControl1.Width, glControl1.Height, camMtx) - Else - MyCamera.UpdateCameraMatrixWithMouse(e.X, e.Y, camMtx) - End If - glControl1.Invalidate() - End If - End Sub - - Public Sub MoveCameraViaWASDQE() - Dim moveSpeed As Integer = Convert.ToInt32(Math.Round((If(IsShiftPressed, 60, 30)) * (MyCamera.CamSpeedMultiplier), 0)) - Dim allowCamMove As Boolean = Not (IsMouseDown AndAlso IsShiftPressed) - - If allowCamMove Then - Dim state As KeyboardState = Keyboard.GetState - - If state(Key.W) Then - 'camera.Move(moveSpeed, moveSpeed, camMtx) - MyCamera.UpdateCameraMatrixWithScrollWheel(moveSpeed, camMtx) - savedCamPos = MyCamera.Position - End If - If state(Key.S) Then - 'camera.Move(-moveSpeed, -moveSpeed, camMtx) - MyCamera.UpdateCameraMatrixWithScrollWheel(-moveSpeed, camMtx) - savedCamPos = MyCamera.Position - End If - If state(Key.A) Then - 'camera.Move(-moveSpeed, 0, camMtx) - MyCamera.UpdateCameraOffsetDirectly(-moveSpeed, 0, camMtx) - End If - If state(Key.D) Then - 'camera.Move(moveSpeed, 0, camMtx) - MyCamera.UpdateCameraOffsetDirectly(moveSpeed, 0, camMtx) - End If - If state(Key.E) Then - 'camera.Move(0, -moveSpeed, camMtx) - MyCamera.UpdateCameraOffsetDirectly(0, -moveSpeed, camMtx) - End If - If state(Key.Q) Then - 'camera.Move(0, moveSpeed, camMtx) - MyCamera.UpdateCameraOffsetDirectly(0, moveSpeed, camMtx) - End If - End If - End Sub - - Private Sub Camera_NeedSelectedObject(sender As Object, e As Camera.NeedSelectedObjectEventArgs) Handles MyCamera.NeedSelectedObject - e.Points = Nothing - End Sub - - Private Sub MyCamera_PerspectiveChanged(sender As Object, e As EventArgs) Handles MyCamera.PerspectiveChanged - UpdateView() - End Sub - - Private Sub ModelPreview_FormDisposed(sender As Object, e As EventArgs) Handles Me.Disposed - For Each rndr As Renderer In myModels.Values - rndr.ReleaseBuffers() - Next - End Sub - - End Class - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/AssemblyInfo.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c7f5a59 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("OpenGLRenderer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("Pilzinsel64")] +[assembly: AssemblyProduct("OpenGLRenderer")] +[assembly: AssemblyCopyright("Copyright © Pilzinsel64 2018")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("03d57392-1aac-468d-b5c9-30d927e685b5")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/Settings.Designer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/Settings.Designer.cs new file mode 100644 index 0000000..4d8a9f8 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Settings.settings b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/Settings.settings similarity index 100% rename from Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Settings.settings rename to Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/Settings.settings diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/BoundingBox.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/BoundingBox.cs new file mode 100644 index 0000000..2d376c9 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/BoundingBox.cs @@ -0,0 +1,92 @@ +using global::System.Drawing; +using global::OpenTK.Graphics.OpenGL; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN +{ + public class BoundingBox + { + public static void DrawSolid(System.Numerics.Vector3 scale, System.Numerics.Quaternion rot, System.Numerics.Vector3 pos, Color color, System.Numerics.Vector3 upper, System.Numerics.Vector3 lower) + { + GL.Disable(EnableCap.Blend); + GL.Disable(EnableCap.Texture2D); + GL.Disable(EnableCap.AlphaTest); + GL.PushMatrix(); + GL.Translate(pos.X, pos.Y, pos.Z); + GL.Rotate(rot.X, 1f, 0f, 0f); + GL.Rotate(rot.Y, 0f, 1f, 0f); + GL.Rotate(rot.Z, 0f, 0f, 1f); + GL.Scale(scale.X, scale.Y, scale.Z); + GL.Begin(PrimitiveType.Quads); + GL.Color4(color); + GL.Vertex3(upper.X, upper.Y, lower.Z); // Top-right of top face + GL.Vertex3(lower.X, upper.Y, lower.Z); // Top-left of top face + GL.Vertex3(lower.X, upper.Y, upper.Z); // Bottom-left of top face + GL.Vertex3(upper.X, upper.Y, upper.Z); // Bottom-right of top face + GL.Vertex3(upper.X, lower.Y, lower.Z); // Top-right of bottom face + GL.Vertex3(lower.X, lower.Y, lower.Z); // Top-left of bottom face + GL.Vertex3(lower.X, lower.Y, upper.Z); // Bottom-left of bottom face + GL.Vertex3(upper.X, lower.Y, upper.Z); // Bottom-right of bottom face + GL.Vertex3(upper.X, upper.Y, upper.Z); // Top-Right of front face + GL.Vertex3(lower.X, upper.Y, upper.Z); // Top-left of front face + GL.Vertex3(lower.X, lower.Y, upper.Z); // Bottom-left of front face + GL.Vertex3(upper.X, lower.Y, upper.Z); // Bottom-right of front face + GL.Vertex3(upper.X, lower.Y, lower.Z); // Bottom-Left of back face + GL.Vertex3(lower.X, lower.Y, lower.Z); // Bottom-Right of back face + GL.Vertex3(lower.X, upper.Y, lower.Z); // Top-Right of back face + GL.Vertex3(upper.X, upper.Y, lower.Z); // Top-Left of back face + GL.Vertex3(lower.X, upper.Y, upper.Z); // Top-Right of left face + GL.Vertex3(lower.X, upper.Y, lower.Z); // Top-Left of left face + GL.Vertex3(lower.X, lower.Y, lower.Z); // Bottom-Left of left face + GL.Vertex3(lower.X, lower.Y, upper.Z); // Bottom-Right of left face + GL.Vertex3(upper.X, upper.Y, upper.Z); // Top-Right of left face + GL.Vertex3(upper.X, upper.Y, lower.Z); // Top-Left of left face + GL.Vertex3(upper.X, lower.Y, lower.Z); // Bottom-Left of left face + GL.Vertex3(upper.X, lower.Y, upper.Z); // Bottom-Right of left face + GL.Color4(Color.White); + GL.End(); + GL.PopMatrix(); + GL.Enable(EnableCap.Blend); + GL.Enable(EnableCap.Texture2D); + GL.Enable(EnableCap.AlphaTest); + } + + public static void Draw(System.Numerics.Vector3 scale, System.Numerics.Quaternion rot, System.Numerics.Vector3 pos, Color color, System.Numerics.Vector3 upper, System.Numerics.Vector3 lower) + { + GL.Disable(EnableCap.Blend); + GL.Disable(EnableCap.Texture2D); + GL.Disable(EnableCap.AlphaTest); + GL.PushMatrix(); + GL.Translate(pos.X, pos.Y, pos.Z); + GL.Rotate(rot.X, 1f, 0f, 0f); + GL.Rotate(rot.Y, 0f, 1f, 0f); + GL.Rotate(rot.Z, 0f, 0f, 1f); + GL.Scale(scale.X, scale.Y, scale.Z); + GL.Begin(PrimitiveType.LineLoop); + GL.Color4(color); + GL.Vertex3(upper.X, upper.Y, lower.Z); // 1 + GL.Vertex3(lower.X, upper.Y, lower.Z); // 2 + GL.Vertex3(lower.X, upper.Y, upper.Z); // 3 + GL.Vertex3(upper.X, upper.Y, lower.Z); // 1 + GL.Vertex3(upper.X, upper.Y, upper.Z); // 4 + GL.Vertex3(lower.X, upper.Y, upper.Z); // 3 + GL.Vertex3(lower.X, lower.Y, upper.Z); // 7 + GL.Vertex3(lower.X, lower.Y, lower.Z); // 6 + GL.Vertex3(upper.X, lower.Y, lower.Z); // 5 + GL.Vertex3(lower.X, lower.Y, upper.Z); // 7 + GL.Vertex3(upper.X, lower.Y, upper.Z); // 8 + GL.Vertex3(upper.X, lower.Y, lower.Z); // 5 + GL.Vertex3(lower.X, upper.Y, lower.Z); // 2 + GL.Vertex3(lower.X, lower.Y, lower.Z); // 6 + GL.Vertex3(lower.X, upper.Y, upper.Z); // 3 + GL.Vertex3(upper.X, lower.Y, upper.Z); // 8 + GL.Vertex3(upper.X, upper.Y, upper.Z); // 4 + GL.Vertex3(upper.X, lower.Y, lower.Z); // 5 + GL.Color4(Color.White); + GL.End(); + GL.PopMatrix(); + GL.Enable(EnableCap.Blend); + GL.Enable(EnableCap.Texture2D); + GL.Enable(EnableCap.AlphaTest); + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/BoundingBox.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/BoundingBox.vb deleted file mode 100644 index edbd8d4..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/BoundingBox.vb +++ /dev/null @@ -1,105 +0,0 @@ -Imports System.Drawing -Imports OpenTK -Imports OpenTK.Graphics.OpenGL - -Namespace RenderingN - - Public Class BoundingBox - - Public Shared Sub DrawSolid(scale As System.Numerics.Vector3, rot As System.Numerics.Quaternion, pos As System.Numerics.Vector3, color As Color, upper As System.Numerics.Vector3, lower As System.Numerics.Vector3) - GL.Disable(EnableCap.Blend) - GL.Disable(EnableCap.Texture2D) - GL.Disable(EnableCap.AlphaTest) - GL.PushMatrix() - GL.Translate(pos.X, pos.Y, pos.Z) - GL.Rotate(rot.X, 1, 0, 0) - GL.Rotate(rot.Y, 0, 1, 0) - GL.Rotate(rot.Z, 0, 0, 1) - GL.Scale(scale.X, scale.Y, scale.Z) - - GL.Begin(PrimitiveType.Quads) - GL.Color4(color) - - GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-right of top face - GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-left of top face - GL.Vertex3(lower.X, upper.Y, upper.Z) ' Bottom-left of top face - GL.Vertex3(upper.X, upper.Y, upper.Z) ' Bottom-right of top face - - GL.Vertex3(upper.X, lower.Y, lower.Z) ' Top-right of bottom face - GL.Vertex3(lower.X, lower.Y, lower.Z) ' Top-left of bottom face - GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-left of bottom face - GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-right of bottom face - - GL.Vertex3(upper.X, upper.Y, upper.Z) ' Top-Right of front face - GL.Vertex3(lower.X, upper.Y, upper.Z) ' Top-left of front face - GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-left of front face - GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-right of front face - - GL.Vertex3(upper.X, lower.Y, lower.Z) ' Bottom-Left of back face - GL.Vertex3(lower.X, lower.Y, lower.Z) ' Bottom-Right of back face - GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-Right of back face - GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-Left of back face - - GL.Vertex3(lower.X, upper.Y, upper.Z) ' Top-Right of left face - GL.Vertex3(lower.X, upper.Y, lower.Z) ' Top-Left of left face - GL.Vertex3(lower.X, lower.Y, lower.Z) ' Bottom-Left of left face - GL.Vertex3(lower.X, lower.Y, upper.Z) ' Bottom-Right of left face - - GL.Vertex3(upper.X, upper.Y, upper.Z) ' Top-Right of left face - GL.Vertex3(upper.X, upper.Y, lower.Z) ' Top-Left of left face - GL.Vertex3(upper.X, lower.Y, lower.Z) ' Bottom-Left of left face - GL.Vertex3(upper.X, lower.Y, upper.Z) ' Bottom-Right of left face - - GL.Color4(Color.White) - GL.End() - GL.PopMatrix() - GL.Enable(EnableCap.Blend) - GL.Enable(EnableCap.Texture2D) - GL.Enable(EnableCap.AlphaTest) - End Sub - - Public Shared Sub Draw(scale As Numerics.Vector3, rot As Numerics.Quaternion, pos As Numerics.Vector3, color As Color, upper As Numerics.Vector3, lower As Numerics.Vector3) - GL.Disable(EnableCap.Blend) - GL.Disable(EnableCap.Texture2D) - GL.Disable(EnableCap.AlphaTest) - GL.PushMatrix() - GL.Translate(pos.X, pos.Y, pos.Z) - GL.Rotate(rot.X, 1, 0, 0) - GL.Rotate(rot.Y, 0, 1, 0) - GL.Rotate(rot.Z, 0, 0, 1) - GL.Scale(scale.X, scale.Y, scale.Z) - - GL.Begin(PrimitiveType.LineLoop) - GL.Color4(color) - - GL.Vertex3(upper.X, upper.Y, lower.Z) ' 1 - GL.Vertex3(lower.X, upper.Y, lower.Z) ' 2 - GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3 - GL.Vertex3(upper.X, upper.Y, lower.Z) ' 1 - GL.Vertex3(upper.X, upper.Y, upper.Z) ' 4 - GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3 - - GL.Vertex3(lower.X, lower.Y, upper.Z) ' 7 - GL.Vertex3(lower.X, lower.Y, lower.Z) ' 6 - GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5 - GL.Vertex3(lower.X, lower.Y, upper.Z) ' 7 - GL.Vertex3(upper.X, lower.Y, upper.Z) ' 8 - GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5 - - GL.Vertex3(lower.X, upper.Y, lower.Z) ' 2 - GL.Vertex3(lower.X, lower.Y, lower.Z) ' 6 - GL.Vertex3(lower.X, upper.Y, upper.Z) ' 3 - GL.Vertex3(upper.X, lower.Y, upper.Z) ' 8 - GL.Vertex3(upper.X, upper.Y, upper.Z) ' 4 - GL.Vertex3(upper.X, lower.Y, lower.Z) ' 5 - - GL.Color4(Color.White) - GL.End() - GL.PopMatrix() - GL.Enable(EnableCap.Blend) - GL.Enable(EnableCap.Texture2D) - GL.Enable(EnableCap.AlphaTest) - End Sub - End Class - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/ContentPipe.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/ContentPipe.cs new file mode 100644 index 0000000..045a0a5 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/ContentPipe.cs @@ -0,0 +1,34 @@ +using global::System; +using global::System.Drawing; +using Bitmap = System.Drawing.Bitmap; +using global::System.Drawing.Imaging; +using global::OpenTK.Graphics.OpenGL; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN +{ + public class ContentPipe + { + public static int LoadTexture(string filepath) + { + var bitmap = new Bitmap(filepath); + return LoadTexture(bitmap); + } + + public static int LoadTexture(Bitmap bitmap) + { + int id = GL.GenTexture(); + LoadTexture(bitmap, id); + return id; + } + + public static void LoadTexture(Bitmap bitmap, int id) + { + var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + GL.BindTexture(TextureTarget.Texture2D, id); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); + bitmap.UnlockBits(bmpData); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)Math.Truncate((decimal)TextureMinFilter.Linear)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)Math.Truncate((decimal)TextureMagFilter.Linear)); + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/ContentPipe.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/ContentPipe.vb deleted file mode 100644 index fa197ef..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/ContentPipe.vb +++ /dev/null @@ -1,34 +0,0 @@ -Imports System -Imports OpenTK -Imports OpenTK.Graphics.OpenGL -Imports System.Drawing -Imports System.Drawing.Imaging -Imports Bitmap = System.Drawing.Bitmap - -Namespace RenderingN - - Public Class ContentPipe - - Public Shared Function LoadTexture(filepath As String) As Integer - Dim bitmap As New Bitmap(filepath) - Return LoadTexture(bitmap) - End Function - - Public Shared Function LoadTexture(bitmap As Bitmap) As Integer - Dim id As Integer = GL.GenTexture() - LoadTexture(bitmap, id) - Return id - End Function - - Public Shared Sub LoadTexture(bitmap As Bitmap, id As Integer) - Dim bmpData As BitmapData = bitmap.LockBits(New Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppArgb) - GL.BindTexture(TextureTarget.Texture2D, id) - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0) - bitmap.UnlockBits(bmpData) - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, CInt(Math.Truncate(TextureMinFilter.Linear))) - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, CInt(Math.Truncate(TextureMagFilter.Linear))) - End Sub - - End Class - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/RenderMode.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/RenderMode.cs new file mode 100644 index 0000000..85d04a4 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/RenderMode.cs @@ -0,0 +1,11 @@ + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN +{ + public enum RenderMode : byte + { + None = 0x0, + Fill = 0x1, + Outline = 0x2, + FillOutline = Fill | Outline + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/RenderMode.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/RenderMode.vb deleted file mode 100644 index 0205862..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/RenderMode.vb +++ /dev/null @@ -1,10 +0,0 @@ -Namespace RenderingN - - Public Enum RenderMode As Byte - None = &H0 - Fill = &H1 - Outline = &H2 - FillOutline = Fill Or Outline - End Enum - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.cs new file mode 100644 index 0000000..1fd4f73 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.cs @@ -0,0 +1,485 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using global::System.Drawing; +using Bitmap = global::System.Drawing.Bitmap; +using Color = global::System.Drawing.Color; +using Image = global::System.Drawing.Image; +using System.Linq; +using global::System.Threading; +using System.Threading.Tasks; +using global::System.Windows.Forms; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; +using global::OpenTK; +using global::OpenTK.Graphics.OpenGL; +using global::Pilz.S3DFileParser; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN +{ + public class Renderer + { + private global::Pilz.S3DFileParser.Object3D obj3d; + private Dictionary dicTextureIDs = new global::System.Collections.Generic.Dictionary(); + private global::System.Collections.Generic.Dictionary dicColorIDs = new global::System.Collections.Generic.Dictionary(); + private global::System.Drawing.Bitmap emptyTexture = null; + private global::System.Drawing.Bitmap lineTexture = null; + private global::System.Drawing.Bitmap selectedLineTexture = null; + + public float ModelScaling { get; set; } = 1.0f; + public bool HasRendered { get; private set; } = false; + public global::System.Collections.Generic.List SelectedElements { get; private set; } + private global::System.Collections.Generic.Dictionary VertexBuffers { get; set; } = new global::System.Collections.Generic.Dictionary(); + private global::System.Collections.Generic.Dictionary> IndicesBuffers { get; set; } = new global::System.Collections.Generic.Dictionary>(); + private global::System.Collections.Generic.Dictionary UVBuffers { get; set; } = new global::System.Collections.Generic.Dictionary(); + private global::System.Collections.Generic.Dictionary VertexColorBuffers { get; set; } = new global::System.Collections.Generic.Dictionary(); + private global::System.Collections.Generic.Dictionary NormalBuffers { get; set; } = new global::System.Collections.Generic.Dictionary(); + + public global::Pilz.S3DFileParser.Object3D Model + { + get + { + return this.obj3d; + } + } + + public Renderer(global::Pilz.S3DFileParser.Object3D obj3d) + { + this.obj3d = obj3d.ToOneMesh(); + + // Set Texture used for faces without texture + this.emptyTexture = (global::System.Drawing.Bitmap)this.ColorToTexture(global::System.Drawing.Color.LightGray); + + // Set Texture used for lines + this.lineTexture = (global::System.Drawing.Bitmap)this.ColorToTexture(global::System.Drawing.Color.Black); + + // Set Texture used for lines of selected faces + this.selectedLineTexture = (global::System.Drawing.Bitmap)this.ColorToTexture(global::System.Drawing.Color.Orange); + } + + private global::System.Drawing.Image ColorToTexture(global::System.Drawing.Color color) + { + var tex = new global::System.Drawing.Bitmap(1, 1); + tex.SetPixel(0, 0, color); + return tex; + } + + /// + /// Updates the Data of a Vertex in the buffer. + /// + /// The Mesh where the Vertex is listed. + /// The Vertex to update. + public void UpdateVertexData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.Vertex v) + { + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexBuffers[m]); + var argdata = new global::OpenTK.Vector3((global::System.Single)v.X, (global::System.Single)v.Y, (global::System.Single)v.Z); + global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.Vertices.IndexOf(v)) * (global::OpenTK.Vector3.SizeInBytes)), global::OpenTK.Vector3.SizeInBytes, ref argdata); + } + + /// + /// Updates the Data of a Normal in the buffer. + /// + /// The Mesh where the Vertex is listed. + /// The Normal to update. + public void UpdateNormalData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.Normal n) + { + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.NormalBuffers[m]); + var argdata = new global::OpenTK.Vector3(n.X, n.Y, n.Z); + global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.Normals.IndexOf(n)) * (global::OpenTK.Vector3.SizeInBytes)), global::OpenTK.Vector3.SizeInBytes, ref argdata); + } + + /// + /// Updates the Data of a Vertex Color in the buffer. + /// + /// The Mesh where the Vertex is listed. + /// The Vertex Color to update. + public void UpdateVertexColorData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.VertexColor vc) + { + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexColorBuffers[m]); + var argdata = new global::OpenTK.Vector4(vc.R, vc.G, vc.B, vc.A); + global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.VertexColors.IndexOf(vc)) * (global::OpenTK.Vector4.SizeInBytes)), global::OpenTK.Vector4.SizeInBytes, ref argdata); + } + + /// + /// Updates the Data of a UV in the buffer. + /// + /// The Mesh where the Vertex is listed. + /// The UV to update. + public void UpdateUVData(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.UV uv) + { + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.UVBuffers[m]); + var argdata = new global::OpenTK.Vector2(uv.U, uv.V); + global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((m.UVs.IndexOf(uv)) * (global::OpenTK.Vector2.SizeInBytes)), global::OpenTK.Vector2.SizeInBytes, ref argdata); + } + + /// + /// Updates the indicies of a face in the buffer. + /// + /// The Mesh where the Vertex is listed. + /// The Face to update. + public void UpdateFaceIndicies(global::Pilz.S3DFileParser.Mesh m, global::Pilz.S3DFileParser.Face f) + { + global::System.Int32 faceIndex = m.Faces.IndexOf(f); + global::System.Byte uintlen = (global::System.Byte)global::Microsoft.VisualBasic.Strings.Len(new uint()); + var indicies = new global::OpenTK.Vector3((global::System.Single)m.Vertices.IndexOf(f.Points[0].Vertex), (global::System.Single)m.Vertices.IndexOf(f.Points[1].Vertex), (global::System.Single)m.Vertices.IndexOf(f.Points[2].Vertex)); + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.IndicesBuffers[m][faceIndex]); + global::OpenTK.Graphics.OpenGL.GL.BufferSubData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::System.Int32)(uintlen) * (faceIndex)), (global::System.Int32)uintlen, ref indicies); + } + + /// + /// Replace an Image with a new one. + /// + /// + /// + public void UpdateTexture(global::System.Drawing.Image oldImage, global::System.Drawing.Image newImage) + { + if (this.dicTextureIDs.ContainsKey(oldImage)) + { + global::System.Int32 id = this.dicTextureIDs[oldImage]; + this.dicTextureIDs.Remove(oldImage); + this.dicTextureIDs.Add(newImage, id); + global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((global::System.Drawing.Bitmap)newImage, id); + } + } + + /// + /// Updates an Image. + /// + /// + public void UpdateTexture(global::System.Drawing.Image image) + { + if (this.dicTextureIDs.ContainsKey(image)) + { + global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((this.dicTextureIDs[image]).ToString()); + } + } + + /// + /// Creates the Buffers and store the requied Data. + /// + public void RenderModel() + { + this.ReleaseBuffers(); + foreach (global::Pilz.S3DFileParser.Mesh mesh in this.obj3d.Meshes) + { + var nibo = new global::System.Collections.Generic.List(); + global::System.Boolean enablecols = ((mesh.VertexColors.Count) > (0)); + global::System.Boolean enablenorms = (((!(enablecols))) && ((mesh.Normals.Count) > (0))); + var verts = new global::System.Collections.Generic.List(); + var uvs = new global::System.Collections.Generic.List(); + var cols = new global::System.Collections.Generic.List(); + var norms = new global::System.Collections.Generic.List(); + global::System.UInt64 curvi = 0UL; + this.IndicesBuffers.Add(mesh, nibo); + for (global::System.Int32 i = 0, loopTo = (mesh.Faces.Count) - (1); i <= loopTo; i++) + { + { + var currentFace = mesh.Faces[i]; + var indices = new List(); + foreach (S3DFileParser.Point p in currentFace.Points) + { + indices.Add((global::System.UInt32)curvi); + curvi = (global::System.UInt64)(curvi + 1m); + if (p.Vertex is object) + { + verts.Add(new Vector3((Single)p.Vertex.X, (Single)p.Vertex.Y, (Single)p.Vertex.Z)); + } + else + { + verts.Add(new Vector3(0f, 0f, 0f)); + } + + if (p.UV is object) + { + uvs.Add(new Vector2(p.UV.U, p.UV.V)); + } + else + { + uvs.Add(new Vector2(0f, 0f)); + } + + if (((enablecols) && p.VertexColor is object)) + { + cols.Add(new Vector4(p.VertexColor.R, p.VertexColor.G, p.VertexColor.B, p.VertexColor.A)); + } + else + { + cols.Add(new Vector4(1f, 1f, 1f, 1f)); + } + + if (((enablenorms) && p.Normal is object)) + { + norms.Add(new global::OpenTK.Vector3(p.Normal.X, p.Normal.Y, p.Normal.Z)); + } + else + { + norms.Add(new global::OpenTK.Vector3(1f, 1f, 1f)); + } + } + + nibo.Add(GL.GenBuffer()); + GL.BindBuffer(BufferTarget.ElementArrayBuffer, nibo[i]); + GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)((Strings.Len(new uint())) * (indices.Count)), indices.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw); + if (currentFace.Material?.Image is object) + { + if (!(this.dicTextureIDs.ContainsKey(currentFace.Material.Image))) + { + this.dicTextureIDs.Add(currentFace.Material.Image, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((global::System.Drawing.Bitmap)currentFace.Material.Image)); + } + } + else if (currentFace.Material?.Color is object) + { + if (!(this.dicColorIDs.ContainsKey((global::System.Drawing.Color)currentFace.Material.Color))) + { + this.dicColorIDs.Add((global::System.Drawing.Color)currentFace.Material.Color, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture((global::System.Drawing.Bitmap)this.ColorToTexture((global::System.Drawing.Color)currentFace.Material.Color))); + } + } + else if (!(this.dicTextureIDs.ContainsKey(this.emptyTexture))) + { + this.dicTextureIDs.Add(this.emptyTexture, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture(this.emptyTexture)); + } + } + } + + global::System.Int32 nvbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer(); + this.VertexBuffers.Add(mesh, nvbo); + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, nvbo); + global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector3.SizeInBytes) * (verts.Count)), verts.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw); + global::System.Int32 ntbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer(); + this.UVBuffers.Add(mesh, ntbo); + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, ntbo); + global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector2.SizeInBytes) * (uvs.Count)), uvs.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw); + if (enablecols) + { + global::System.Int32 ncbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer(); + this.VertexColorBuffers.Add(mesh, ncbo); + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, ncbo); + global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector4.SizeInBytes) * (cols.Count)), cols.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw); + } + + if (enablenorms) + { + global::System.Int32 nnbo = global::OpenTK.Graphics.OpenGL.GL.GenBuffer(); + this.NormalBuffers.Add(mesh, nnbo); + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, nnbo); + global::OpenTK.Graphics.OpenGL.GL.BufferData(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, (global::System.IntPtr)((global::OpenTK.Vector3.SizeInBytes) * (norms.Count)), norms.ToArray(), global::OpenTK.Graphics.OpenGL.BufferUsageHint.StaticDraw); + } + } + + if (!(this.dicTextureIDs.ContainsKey(this.lineTexture))) + { + this.dicTextureIDs.Add(this.lineTexture, global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.ContentPipe.LoadTexture(this.lineTexture)); + } + + this.HasRendered = true; + } + + public void DrawModel(global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode mode) + { + this.DrawModel(mode, global::OpenTK.Vector3.Zero, global::OpenTK.Quaternion.Identity, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling)); + } + + public void DrawModel(global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode mode, global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot) + { + this.DrawModel(mode, pos, rot, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling)); + } + + public void DrawModel(global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode mode, global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot, global::OpenTK.Vector3 scale) + { + if ((mode == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.None)) + return; + if (!(this.HasRendered)) + return; + global::OpenTK.Graphics.OpenGL.GL.PushMatrix(); + global::OpenTK.Graphics.OpenGL.GL.Translate(pos.X, pos.Y, pos.Z); + global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.X, 1f, 0f, 0f); + global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Y, 0f, 1f, 0f); + global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Z, 0f, 0f, 1f); + global::OpenTK.Graphics.OpenGL.GL.Scale(scale); // GL.Scale(scale.X, scale.Y, scale.Z) + global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray); + global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.TextureCoordArray); + foreach (global::Pilz.S3DFileParser.Mesh mesh in this.obj3d.Meshes) + { + if (this.VertexColorBuffers.ContainsKey(mesh)) + { + global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.ColorArray); + } + else if (this.NormalBuffers.ContainsKey(mesh)) + { + global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.NormalArray); + } + + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexBuffers[mesh]); + global::OpenTK.Graphics.OpenGL.GL.VertexPointer(3, global::OpenTK.Graphics.OpenGL.VertexPointerType.Float, 0, global::System.IntPtr.Zero); + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.UVBuffers[mesh]); + global::OpenTK.Graphics.OpenGL.GL.TexCoordPointer(2, global::OpenTK.Graphics.OpenGL.TexCoordPointerType.Float, 0, global::System.IntPtr.Zero); + if (this.VertexColorBuffers.ContainsKey(mesh)) + { + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexColorBuffers[mesh]); + global::OpenTK.Graphics.OpenGL.GL.ColorPointer(4, global::OpenTK.Graphics.OpenGL.ColorPointerType.Float, 0, global::System.IntPtr.Zero); + } + else if (this.NormalBuffers.ContainsKey(mesh)) + { + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.NormalBuffers[mesh]); + global::OpenTK.Graphics.OpenGL.GL.NormalPointer(global::OpenTK.Graphics.OpenGL.NormalPointerType.Float, 0, global::System.IntPtr.Zero); + } + + for (global::System.Int32 i = 0, loopTo = (mesh.Faces.Count) - (1); i <= loopTo; i++) + { + var l = mesh.Faces[i]; + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ElementArrayBuffer, this.IndicesBuffers[mesh][i]); + global::System.Boolean isEmptyTexture = l.Material?.Image is null; + global::System.Boolean isEmptyColor = l.Material?.Color is null; + void setMaterialTextureOrColor() + { + global::System.Int32 texID; + if (!(isEmptyTexture)) + { + texID = this.dicTextureIDs[l.Material.Image]; + } + else if (!(isEmptyColor)) + { + texID = this.dicColorIDs[(global::System.Drawing.Color)l.Material.Color]; + } + else + { + texID = this.dicTextureIDs[this.emptyTexture]; + } + + global::OpenTK.Graphics.OpenGL.GL.BindTexture(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, texID); + }; + if ((((mode & global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill)) == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill)) + { + setMaterialTextureOrColor(); + if (!(isEmptyTexture)) + { + global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapT, l.Material.Wrap.X); + global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapS, l.Material.Wrap.Y); + } + + global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill); + global::OpenTK.Graphics.OpenGL.GL.DrawElements(global::OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, l.Points.Count, global::OpenTK.Graphics.OpenGL.DrawElementsType.UnsignedInt, global::System.IntPtr.Zero); + } + + if ((((mode & global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Outline)) == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Outline)) + { + if ((((mode & global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill)) == global::Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN.RenderMode.Fill)) + { + global::OpenTK.Graphics.OpenGL.GL.BindTexture(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, this.dicTextureIDs[this.lineTexture]); + } + else + { + setMaterialTextureOrColor(); + if (!(isEmptyTexture)) + { + global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapT, l.Material.Wrap.X); + global::OpenTK.Graphics.OpenGL.GL.TexParameter(global::OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, global::OpenTK.Graphics.OpenGL.TextureParameterName.TextureWrapS, l.Material.Wrap.Y); + } + } + + global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Line); + global::OpenTK.Graphics.OpenGL.GL.DrawElements(global::OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, l.Points.Count, global::OpenTK.Graphics.OpenGL.DrawElementsType.UnsignedInt, global::System.IntPtr.Zero); + } + } + + global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill); // Reset for RenderEngineOld + if (this.VertexColorBuffers.ContainsKey(mesh)) + { + global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.ColorArray); + } + else if (this.NormalBuffers.ContainsKey(mesh)) + { + global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.NormalArray); + } + } + + global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray); + global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.TextureCoordArray); + global::OpenTK.Graphics.OpenGL.GL.PopMatrix(); + } + + public void DrawFacePicking() + { + this.DrawFacePicking(global::OpenTK.Vector3.Zero, global::OpenTK.Quaternion.Identity, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling)); + } + + public void DrawFacePicking(global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot) + { + this.DrawFacePicking(pos, rot, new global::OpenTK.Vector3(this.ModelScaling, this.ModelScaling, this.ModelScaling)); + } + + public void DrawFacePicking(global::OpenTK.Vector3 pos, global::OpenTK.Quaternion rot, global::OpenTK.Vector3 scale) + { + if (!(this.HasRendered)) + return; + global::OpenTK.Graphics.OpenGL.GL.PushMatrix(); + global::OpenTK.Graphics.OpenGL.GL.Translate(pos.X, pos.Y, pos.Z); + global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.X, 1f, 0f, 0f); + global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Y, 0f, 1f, 0f); + global::OpenTK.Graphics.OpenGL.GL.Rotate(rot.Z, 0f, 0f, 1f); + global::OpenTK.Graphics.OpenGL.GL.Scale(scale); + global::OpenTK.Graphics.OpenGL.GL.EnableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray); + for (global::System.Int32 iMesh = 0, loopTo = (this.obj3d.Meshes.Count) - (1); iMesh <= loopTo; iMesh++) + { + var mesh = this.obj3d.Meshes[iMesh]; + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, this.VertexBuffers[mesh]); + global::OpenTK.Graphics.OpenGL.GL.VertexPointer(3, global::OpenTK.Graphics.OpenGL.VertexPointerType.Float, 0, global::System.IntPtr.Zero); + for (global::System.Int32 iFace = 0, loopTo1 = (mesh.Faces.Count) - (1); iFace <= loopTo1; iFace++) + { + var l = mesh.Faces[iFace]; + global::OpenTK.Graphics.OpenGL.GL.BindBuffer(global::OpenTK.Graphics.OpenGL.BufferTarget.ElementArrayBuffer, this.IndicesBuffers[mesh][iFace]); + global::System.Int32 colorCode = (((0x20000000) + ((((iMesh) << (16))))) + (iFace)); + global::OpenTK.Graphics.OpenGL.GL.Color4(global::System.Drawing.Color.FromArgb(colorCode)); // Color: "2f ff xx xx" -> where 'f' = mesh index and where 'x' is face index + global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill); + global::OpenTK.Graphics.OpenGL.GL.DrawElements(global::OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, l.Points.Count, global::OpenTK.Graphics.OpenGL.DrawElementsType.UnsignedInt, global::System.IntPtr.Zero); + } + + global::OpenTK.Graphics.OpenGL.GL.PolygonMode(global::OpenTK.Graphics.OpenGL.MaterialFace.FrontAndBack, global::OpenTK.Graphics.OpenGL.PolygonMode.Fill); + } + + global::OpenTK.Graphics.OpenGL.GL.DisableClientState(global::OpenTK.Graphics.OpenGL.ArrayCap.VertexArray); + global::OpenTK.Graphics.OpenGL.GL.PopMatrix(); + } + + public void ReleaseBuffers() + { + if (!(this.HasRendered)) + return; + foreach (global::System.Collections.Generic.KeyValuePair kvp in this.VertexBuffers) + global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value); + this.VertexBuffers.Clear(); + foreach (global::System.Collections.Generic.KeyValuePair kvp in this.UVBuffers) + global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value); + this.UVBuffers.Clear(); + foreach (global::System.Collections.Generic.KeyValuePair kvp in this.VertexColorBuffers) + global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value); + this.VertexColorBuffers.Clear(); + foreach (global::System.Collections.Generic.KeyValuePair kvp in this.NormalBuffers) + global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value); + this.NormalBuffers.Clear(); + foreach (global::System.Collections.Generic.KeyValuePair> kvp in this.IndicesBuffers) + { + foreach (global::System.Int32 i in kvp.Value) + global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(i); + kvp.Value.Clear(); + } + + this.IndicesBuffers.Clear(); + foreach (global::System.Collections.Generic.KeyValuePair kvp in this.dicTextureIDs) + global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value); + this.dicTextureIDs.Clear(); + foreach (global::System.Collections.Generic.KeyValuePair kvp in this.dicColorIDs) + global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value); + this.dicColorIDs.Clear(); + this.HasRendered = false; + } + + ~Renderer() + { + // ReleaseBuffers() + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.vb b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.vb deleted file mode 100644 index 6e071c6..0000000 --- a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.vb +++ /dev/null @@ -1,471 +0,0 @@ -Imports System.Drawing -Imports System.Threading -Imports System.Windows.Forms -Imports OpenTK -Imports OpenTK.Graphics.OpenGL -Imports Pilz.S3DFileParser -Imports Bitmap = System.Drawing.Bitmap -Imports Color = System.Drawing.Color -Imports Image = System.Drawing.Image - -Namespace RenderingN - - Public Class Renderer - - Private obj3d As Object3D - Private dicTextureIDs As New Dictionary(Of Image, Integer) - Private dicColorIDs As New Dictionary(Of Color, Integer) - Private emptyTexture As Bitmap = Nothing - Private lineTexture As Bitmap = Nothing - Private selectedLineTexture As Bitmap = Nothing - Public Property ModelScaling As Single = 1.0F - Public ReadOnly Property HasRendered As Boolean = False - Public ReadOnly Property SelectedElements As List(Of Object) - - Private ReadOnly Property VertexBuffers As New Dictionary(Of Mesh, Integer) - Private ReadOnly Property IndicesBuffers As New Dictionary(Of Mesh, List(Of Integer)) - Private ReadOnly Property UVBuffers As New Dictionary(Of Mesh, Integer) - Private ReadOnly Property VertexColorBuffers As New Dictionary(Of Mesh, Integer) - Private ReadOnly Property NormalBuffers As New Dictionary(Of Mesh, Integer) - - Public ReadOnly Property Model As Object3D - Get - Return obj3d - End Get - End Property - - Public Sub New(obj3d As Object3D) - Me.obj3d = obj3d.ToOneMesh - - 'Set Texture used for faces without texture - emptyTexture = ColorToTexture(Color.LightGray) - - 'Set Texture used for lines - lineTexture = ColorToTexture(Color.Black) - - 'Set Texture used for lines of selected faces - selectedLineTexture = ColorToTexture(Color.Orange) - End Sub - - Private Function ColorToTexture(color As Color) As Image - Dim tex As New Bitmap(1, 1) - tex.SetPixel(0, 0, color) - Return tex - End Function - - ''' - ''' Updates the Data of a Vertex in the buffer. - ''' - ''' The Mesh where the Vertex is listed. - ''' The Vertex to update. - Public Sub UpdateVertexData(m As Mesh, v As Vertex) - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(m)) - GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.Vertices.IndexOf(v) * Vector3.SizeInBytes, IntPtr), Vector3.SizeInBytes, New Vector3(v.X, v.Y, v.Z)) - End Sub - - ''' - ''' Updates the Data of a Normal in the buffer. - ''' - ''' The Mesh where the Vertex is listed. - ''' The Normal to update. - Public Sub UpdateNormalData(m As Mesh, n As Normal) - GL.BindBuffer(BufferTarget.ArrayBuffer, NormalBuffers(m)) - GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.Normals.IndexOf(n) * Vector3.SizeInBytes, IntPtr), Vector3.SizeInBytes, New Vector3(n.X, n.Y, n.Z)) - End Sub - - ''' - ''' Updates the Data of a Vertex Color in the buffer. - ''' - ''' The Mesh where the Vertex is listed. - ''' The Vertex Color to update. - Public Sub UpdateVertexColorData(m As Mesh, vc As VertexColor) - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColorBuffers(m)) - GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.VertexColors.IndexOf(vc) * Vector4.SizeInBytes, IntPtr), Vector4.SizeInBytes, New Vector4(vc.R, vc.G, vc.B, vc.A)) - End Sub - - ''' - ''' Updates the Data of a UV in the buffer. - ''' - ''' The Mesh where the Vertex is listed. - ''' The UV to update. - Public Sub UpdateUVData(m As Mesh, uv As UV) - GL.BindBuffer(BufferTarget.ArrayBuffer, UVBuffers(m)) - GL.BufferSubData(BufferTarget.ArrayBuffer, CType(m.UVs.IndexOf(uv) * Vector2.SizeInBytes, IntPtr), Vector2.SizeInBytes, New Vector2(uv.U, uv.V)) - End Sub - - ''' - ''' Updates the indicies of a face in the buffer. - ''' - ''' The Mesh where the Vertex is listed. - ''' The Face to update. - Public Sub UpdateFaceIndicies(m As Mesh, f As Face) - Dim faceIndex As Integer = m.Faces.IndexOf(f) - Dim uintlen As Byte = Len(New UInteger) - Dim indicies As New Vector3(m.Vertices.IndexOf(f.Points(0).Vertex), - m.Vertices.IndexOf(f.Points(1).Vertex), - m.Vertices.IndexOf(f.Points(2).Vertex)) - - GL.BindBuffer(BufferTarget.ArrayBuffer, IndicesBuffers(m)(faceIndex)) - GL.BufferSubData(BufferTarget.ArrayBuffer, CType(uintlen * faceIndex, IntPtr), uintlen, indicies) - End Sub - - ''' - ''' Replace an Image with a new one. - ''' - ''' - ''' - Public Sub UpdateTexture(oldImage As Image, newImage As Image) - If dicTextureIDs.ContainsKey(oldImage) Then - Dim id As Integer = dicTextureIDs(oldImage) - dicTextureIDs.Remove(oldImage) - dicTextureIDs.Add(newImage, id) - ContentPipe.LoadTexture(newImage, id) - End If - End Sub - - ''' - ''' Updates an Image. - ''' - ''' - Public Sub UpdateTexture(image As Image) - If dicTextureIDs.ContainsKey(image) Then - ContentPipe.LoadTexture(dicTextureIDs(image)) - End If - End Sub - - ''' - ''' Creates the Buffers and store the requied Data. - ''' - Public Sub RenderModel() - ReleaseBuffers() - - For Each mesh As Mesh In obj3d.Meshes - - Dim nibo As New List(Of Integer) - Dim enablecols As Boolean = mesh.VertexColors.Count > 0 - Dim enablenorms As Boolean = (Not enablecols) AndAlso mesh.Normals.Count > 0 - Dim verts As New List(Of Vector3) - Dim uvs As New List(Of Vector2) - Dim cols As New List(Of Vector4) - Dim norms As New List(Of Vector3) - Dim curvi As ULong = 0 - IndicesBuffers.Add(mesh, nibo) - - For i As Integer = 0 To mesh.Faces.Count - 1 - With mesh.Faces(i) - Dim indices As New List(Of UInteger) - For Each p As S3DFileParser.Point In .Points - indices.Add(curvi) - curvi += 1 - - If p.Vertex IsNot Nothing Then - verts.Add(New Vector3(p.Vertex.X, p.Vertex.Y, p.Vertex.Z)) - Else - verts.Add(New Vector3(0, 0, 0)) - End If - - If p.UV IsNot Nothing Then - uvs.Add(New Vector2(p.UV.U, p.UV.V)) - Else - uvs.Add(New Vector2(0, 0)) - End If - - If enablecols AndAlso p.VertexColor IsNot Nothing Then - cols.Add(New Vector4(p.VertexColor.R, p.VertexColor.G, p.VertexColor.B, p.VertexColor.A)) - Else - cols.Add(New Vector4(1, 1, 1, 1)) - End If - - If enablenorms AndAlso p.Normal IsNot Nothing Then - norms.Add(New Vector3(p.Normal.X, p.Normal.Y, p.Normal.Z)) - Else - norms.Add(New Vector3(1, 1, 1)) - End If - Next - - nibo.Add(GL.GenBuffer) - GL.BindBuffer(BufferTarget.ElementArrayBuffer, nibo(i)) - GL.BufferData( - BufferTarget.ElementArrayBuffer, - CType(Len(New UInteger) * indices.Count, IntPtr), - indices.ToArray, - BufferUsageHint.StaticDraw) - - If .Material?.Image IsNot Nothing Then - If Not dicTextureIDs.ContainsKey(.Material.Image) Then - dicTextureIDs.Add(.Material.Image, ContentPipe.LoadTexture(.Material.Image)) - End If - ElseIf .Material?.Color IsNot Nothing Then - If Not dicColorIDs.ContainsKey(.Material.Color) Then - dicColorIDs.Add(.Material.Color, ContentPipe.LoadTexture(ColorToTexture(.Material.Color))) - End If - Else - If Not dicTextureIDs.ContainsKey(emptyTexture) Then - dicTextureIDs.Add(emptyTexture, ContentPipe.LoadTexture(emptyTexture)) - End If - End If - End With - Next - - Dim nvbo As Integer = GL.GenBuffer - VertexBuffers.Add(mesh, nvbo) - GL.BindBuffer(BufferTarget.ArrayBuffer, nvbo) - GL.BufferData( - BufferTarget.ArrayBuffer, - CType(Vector3.SizeInBytes * verts.Count, IntPtr), - verts.ToArray, - BufferUsageHint.StaticDraw - ) - - Dim ntbo As Integer = GL.GenBuffer - UVBuffers.Add(mesh, ntbo) - GL.BindBuffer(BufferTarget.ArrayBuffer, ntbo) - GL.BufferData( - BufferTarget.ArrayBuffer, - CType(Vector2.SizeInBytes * uvs.Count, IntPtr), - uvs.ToArray, - BufferUsageHint.StaticDraw - ) - - If enablecols Then - Dim ncbo As Integer = GL.GenBuffer - VertexColorBuffers.Add(mesh, ncbo) - GL.BindBuffer(BufferTarget.ArrayBuffer, ncbo) - GL.BufferData( - BufferTarget.ArrayBuffer, - CType(Vector4.SizeInBytes * cols.Count, IntPtr), - cols.ToArray, - BufferUsageHint.StaticDraw - ) - End If - - If enablenorms Then - Dim nnbo As Integer = GL.GenBuffer - NormalBuffers.Add(mesh, nnbo) - GL.BindBuffer(BufferTarget.ArrayBuffer, nnbo) - GL.BufferData( - BufferTarget.ArrayBuffer, - CType(Vector3.SizeInBytes * norms.Count, IntPtr), - norms.ToArray, - BufferUsageHint.StaticDraw - ) - End If - - Next - - If Not dicTextureIDs.ContainsKey(lineTexture) Then - dicTextureIDs.Add(lineTexture, ContentPipe.LoadTexture(lineTexture)) - End If - - _HasRendered = True - End Sub - - Public Sub DrawModel(mode As RenderMode) - DrawModel(mode, Vector3.Zero, Quaternion.Identity, New Vector3(ModelScaling, ModelScaling, ModelScaling)) - End Sub - - Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion) - DrawModel(mode, pos, rot, New Vector3(ModelScaling, ModelScaling, ModelScaling)) - End Sub - - Public Sub DrawModel(mode As RenderMode, pos As Vector3, rot As Quaternion, scale As Vector3) - If mode = RenderMode.None Then Return - If Not _HasRendered Then Return - - GL.PushMatrix() - GL.Translate(pos.X, pos.Y, pos.Z) - GL.Rotate(rot.X, 1, 0, 0) - GL.Rotate(rot.Y, 0, 1, 0) - GL.Rotate(rot.Z, 0, 0, 1) - GL.Scale(scale) 'GL.Scale(scale.X, scale.Y, scale.Z) - GL.EnableClientState(ArrayCap.VertexArray) - GL.EnableClientState(ArrayCap.TextureCoordArray) - - For Each mesh As Mesh In obj3d.Meshes - - If VertexColorBuffers.ContainsKey(mesh) Then - GL.EnableClientState(ArrayCap.ColorArray) - ElseIf NormalBuffers.ContainsKey(mesh) Then - GL.EnableClientState(ArrayCap.NormalArray) - End If - - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(mesh)) - GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero) - - GL.BindBuffer(BufferTarget.ArrayBuffer, UVBuffers(mesh)) - GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero) - - If VertexColorBuffers.ContainsKey(mesh) Then - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColorBuffers(mesh)) - GL.ColorPointer(4, ColorPointerType.Float, 0, IntPtr.Zero) - ElseIf NormalBuffers.ContainsKey(mesh) Then - GL.BindBuffer(BufferTarget.ArrayBuffer, NormalBuffers(mesh)) - GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero) - End If - - For i As Integer = 0 To mesh.Faces.Count - 1 - Dim l As Face = mesh.Faces(i) - - GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesBuffers(mesh)(i)) - - Dim isEmptyTexture As Boolean = l.Material?.Image Is Nothing - Dim isEmptyColor As Boolean = l.Material?.Color Is Nothing - - Dim setMaterialTextureOrColor = - Sub() - Dim texID As Integer - If Not isEmptyTexture Then - texID = dicTextureIDs(l.Material.Image) - ElseIf Not isEmptyColor Then - texID = dicColorIDs(l.Material.Color) - Else - texID = dicTextureIDs(emptyTexture) - End If - GL.BindTexture(TextureTarget.Texture2D, texID) - End Sub - - If (mode And RenderMode.Fill) = RenderMode.Fill Then - setMaterialTextureOrColor() - - If Not isEmptyTexture Then - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, l.Material.Wrap.X) - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, l.Material.Wrap.Y) - End If - - GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill) - - GL.DrawElements(PrimitiveType.Triangles, l.Points.Count, - DrawElementsType.UnsignedInt, IntPtr.Zero) - - End If - - If (mode And RenderMode.Outline) = RenderMode.Outline Then - - If (mode And RenderMode.Fill) = RenderMode.Fill Then - GL.BindTexture(TextureTarget.Texture2D, dicTextureIDs(lineTexture)) - Else - setMaterialTextureOrColor() - - If Not isEmptyTexture Then - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, l.Material.Wrap.X) - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, l.Material.Wrap.Y) - End If - End If - - GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line) - - GL.DrawElements(PrimitiveType.Triangles, l.Points.Count, - DrawElementsType.UnsignedInt, IntPtr.Zero) - - End If - Next - - GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill) 'Reset for RenderEngineOld - - If VertexColorBuffers.ContainsKey(mesh) Then - GL.DisableClientState(ArrayCap.ColorArray) - ElseIf NormalBuffers.ContainsKey(mesh) Then - GL.DisableClientState(ArrayCap.NormalArray) - End If - Next - - GL.DisableClientState(ArrayCap.VertexArray) - GL.DisableClientState(ArrayCap.TextureCoordArray) - GL.PopMatrix() - End Sub - - Public Sub DrawFacePicking() - DrawFacePicking(Vector3.Zero, Quaternion.Identity, New Vector3(ModelScaling, ModelScaling, ModelScaling)) - End Sub - Public Sub DrawFacePicking(pos As Vector3, rot As Quaternion) - DrawFacePicking(pos, rot, New Vector3(ModelScaling, ModelScaling, ModelScaling)) - End Sub - Public Sub DrawFacePicking(pos As Vector3, rot As Quaternion, scale As Vector3) - If Not _HasRendered Then Return - - GL.PushMatrix() - GL.Translate(pos.X, pos.Y, pos.Z) - GL.Rotate(rot.X, 1, 0, 0) - GL.Rotate(rot.Y, 0, 1, 0) - GL.Rotate(rot.Z, 0, 0, 1) - GL.Scale(scale) - GL.EnableClientState(ArrayCap.VertexArray) - - For iMesh As Integer = 0 To obj3d.Meshes.Count - 1 - Dim mesh As Mesh = obj3d.Meshes(iMesh) - - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffers(mesh)) - GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero) - - For iFace As Integer = 0 To mesh.Faces.Count - 1 - Dim l As Face = mesh.Faces(iFace) - - GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesBuffers(mesh)(iFace)) - - Dim colorCode As Integer = &H20000000 + (iMesh << 16) + iFace - GL.Color4(Color.FromArgb(colorCode)) 'Color: "2f ff xx xx" -> where 'f' = mesh index and where 'x' is face index - - GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill) - - GL.DrawElements(PrimitiveType.Triangles, l.Points.Count, - DrawElementsType.UnsignedInt, IntPtr.Zero) - Next - - GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill) - Next - - GL.DisableClientState(ArrayCap.VertexArray) - GL.PopMatrix() - End Sub - - Public Sub ReleaseBuffers() - If Not HasRendered Then Return - - For Each kvp As KeyValuePair(Of Mesh, Integer) In VertexBuffers - GL.DeleteBuffer(kvp.Value) - Next - VertexBuffers.Clear() - - For Each kvp As KeyValuePair(Of Mesh, Integer) In UVBuffers - GL.DeleteBuffer(kvp.Value) - Next - UVBuffers.Clear() - - For Each kvp As KeyValuePair(Of Mesh, Integer) In VertexColorBuffers - GL.DeleteBuffer(kvp.Value) - Next - VertexColorBuffers.Clear() - - For Each kvp As KeyValuePair(Of Mesh, Integer) In NormalBuffers - GL.DeleteBuffer(kvp.Value) - Next - NormalBuffers.Clear() - - For Each kvp As KeyValuePair(Of Mesh, List(Of Integer)) In IndicesBuffers - For Each i As Integer In kvp.Value - GL.DeleteBuffer(i) - Next - kvp.Value.Clear() - Next - IndicesBuffers.Clear() - - For Each kvp As KeyValuePair(Of Image, Integer) In dicTextureIDs - GL.DeleteBuffer(kvp.Value) - Next - dicTextureIDs.Clear() - - For Each kvp As KeyValuePair(Of Color, Integer) In dicColorIDs - GL.DeleteBuffer(kvp.Value) - Next - dicColorIDs.Clear() - - _HasRendered = False - End Sub - - Protected Overrides Sub Finalize() - 'ReleaseBuffers() - End Sub - - End Class - -End Namespace diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.Designer.cs b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.Designer.cs new file mode 100644 index 0000000..d71de19 --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Drawing.Drawing3D.OpenGLFactory.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Drawing.Drawing3D.OpenGLFactory.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.resx b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.Drawing/BitmapExtensions.cs b/Pilz.Drawing/BitmapExtensions.cs new file mode 100644 index 0000000..115d75e --- /dev/null +++ b/Pilz.Drawing/BitmapExtensions.cs @@ -0,0 +1,20 @@ +using global::System.Drawing; + +namespace Pilz.Drawing +{ + public static class BitmapExtensions + { + public static void InvertColors(this Bitmap bmp) + { + for (int y = 0, loopTo = bmp.Height - 1; y <= loopTo; y++) + { + for (int x = 0, loopTo1 = bmp.Width - 1; x <= loopTo1; x++) + { + var inv = bmp.GetPixel(x, y); + inv = Color.FromArgb(inv.A, byte.MaxValue - inv.R, byte.MaxValue - inv.G, byte.MaxValue - inv.B); + bmp.SetPixel(x, y, inv); + } + } + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing/BitmapExtensions.vb b/Pilz.Drawing/BitmapExtensions.vb deleted file mode 100644 index afe580f..0000000 --- a/Pilz.Drawing/BitmapExtensions.vb +++ /dev/null @@ -1,20 +0,0 @@ -Imports System.Drawing -Imports System.Runtime.CompilerServices - -Public Module BitmapExtensions - - - Public Sub InvertColors(bmp As Bitmap) - For y As Integer = 0 To bmp.Height - 1 - For x As Integer = 0 To bmp.Width - 1 - Dim inv As Color = bmp.GetPixel(x, y) - inv = Color.FromArgb(inv.A, - Byte.MaxValue - inv.R, - Byte.MaxValue - inv.G, - Byte.MaxValue - inv.B) - bmp.SetPixel(x, y, inv) - Next - Next - End Sub - -End Module diff --git a/Pilz.Drawing/HelpfulDrawingFunctions.cs b/Pilz.Drawing/HelpfulDrawingFunctions.cs new file mode 100644 index 0000000..5485512 --- /dev/null +++ b/Pilz.Drawing/HelpfulDrawingFunctions.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Data; +using global::System.Drawing; +using System.Linq; + +namespace Pilz.Drawing +{ + public static class HelpfulDrawingFunctions + { + public static bool IsPointInRectangle(PointF p, RectangleF rect) + { + var bList = new List(); + bList.Add(p.X > rect.Left); + bList.Add(p.X < rect.Right); + bList.Add(p.Y > rect.Top); + bList.Add(p.Y < rect.Bottom); + return !bList.Contains(false); + } + + public static bool OverlapsTwoRectangles(RectangleF a, RectangleF b) + { + return a.IntersectsWith(b); // RectangleF.Intersect(a, b) <> RectangleF.Empty + } + + public static bool RectangleContainsRectangle(RectangleF parent, RectangleF child) + { + return parent.Contains(child); + // Return _ + // IsPointInRectangle(New PointF(child.Top, child.Left), parent) AndAlso + // IsPointInRectangle(New PointF(child.Top, child.Right), parent) AndAlso + // IsPointInRectangle(New PointF(child.Bottom, child.Left), parent) AndAlso + // IsPointInRectangle(New PointF(child.Bottom, child.Right), parent) + } + + public static RectangleF GetRectangle(PointF p1, PointF p2) + { + var rect = new RectangleF(); + bool startIsEnd = p1.X > p2.X && p1.Y > p2.Y; + var xValues = new int[] { (int)p1.X, (int)p2.X }; + var yValues = new int[] { (int)p1.Y, (int)p2.Y }; + rect.Location = new PointF(xValues.OrderBy(n => n).First(), yValues.OrderBy(n => n).First()); + rect.Size = new SizeF(xValues.OrderByDescending(n => n).First(), yValues.OrderByDescending(n => n).First()); + rect.Size = new SizeF(rect.Size.Width - rect.Location.X, rect.Size.Height - rect.Location.Y); + return rect; + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing/HelpfulDrawingFunctions.vb b/Pilz.Drawing/HelpfulDrawingFunctions.vb deleted file mode 100644 index 5fb2c28..0000000 --- a/Pilz.Drawing/HelpfulDrawingFunctions.vb +++ /dev/null @@ -1,50 +0,0 @@ -Imports System.Drawing -Imports System.Drawing.Drawing2D - -Public Module HelpfulDrawingFunctions - - Public Function IsPointInRectangle(p As PointF, rect As RectangleF) As Boolean - Dim bList As New List(Of Boolean) - - bList.Add(p.X > rect.Left) - bList.Add(p.X < rect.Right) - bList.Add(p.Y > rect.Top) - bList.Add(p.Y < rect.Bottom) - - Return Not bList.Contains(False) - End Function - - Public Function OverlapsTwoRectangles(a As RectangleF, b As RectangleF) As Boolean - Return a.IntersectsWith(b) 'RectangleF.Intersect(a, b) <> RectangleF.Empty - End Function - - Public Function RectangleContainsRectangle(parent As RectangleF, child As RectangleF) As Boolean - Return parent.Contains(child) - 'Return _ - ' IsPointInRectangle(New PointF(child.Top, child.Left), parent) AndAlso - ' IsPointInRectangle(New PointF(child.Top, child.Right), parent) AndAlso - ' IsPointInRectangle(New PointF(child.Bottom, child.Left), parent) AndAlso - ' IsPointInRectangle(New PointF(child.Bottom, child.Right), parent) - End Function - - Public Function GetRectangle(p1 As PointF, p2 As PointF) As RectangleF - Dim rect As New RectangleF - Dim startIsEnd As Boolean = p1.X > p2.X AndAlso p1.Y > p2.Y - - Dim xValues() As Integer = {p1.X, p2.X} - Dim yValues() As Integer = {p1.Y, p2.Y} - - rect.Location = New PointF(xValues.OrderBy(Function(n) n).First, - yValues.OrderBy(Function(n) n).First) - - rect.Size = New SizeF(xValues.OrderByDescending(Function(n) n).First, - yValues.OrderByDescending(Function(n) n).First) - - rect.Size = New SizeF(rect.Size.Width - rect.Location.X, - rect.Size.Height - rect.Location.Y) - - Return rect - End Function - -End Module - diff --git a/Pilz.Drawing/My Project/Application.Designer.cs b/Pilz.Drawing/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Drawing/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Drawing/My Project/Application.Designer.vb b/Pilz.Drawing/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Drawing/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Drawing/My Project/AssemblyInfo.vb b/Pilz.Drawing/My Project/AssemblyInfo.vb deleted file mode 100644 index c0a2a4b..0000000 --- a/Pilz.Drawing/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Drawing/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Drawing/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..0c7d4df --- /dev/null +++ b/Pilz.Drawing/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Drawing.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Drawing/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Drawing/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..86a1912 --- /dev/null +++ b/Pilz.Drawing/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Drawing.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Drawing/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Drawing/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Drawing/My Project/Resources.Designer.vb b/Pilz.Drawing/My Project/Resources.Designer.vb deleted file mode 100644 index e6ce8ce..0000000 --- a/Pilz.Drawing/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Drawing.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Drawing/My Project/Settings.Designer.vb b/Pilz.Drawing/My Project/Settings.Designer.vb deleted file mode 100644 index 3a2242f..0000000 --- a/Pilz.Drawing/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Drawing.My.MySettings - Get - Return Global.Pilz.Drawing.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Drawing/Pilz.Drawing.vbproj b/Pilz.Drawing/Pilz.Drawing.csproj similarity index 72% rename from Pilz.Drawing/Pilz.Drawing.vbproj rename to Pilz.Drawing/Pilz.Drawing.csproj index fb06738..5b32065 100644 --- a/Pilz.Drawing/Pilz.Drawing.vbproj +++ b/Pilz.Drawing/Pilz.Drawing.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6} + {A82F006D-E811-06F9-37B9-6A73EC0BCC56} Library Pilz.Drawing Pilz.Drawing @@ -13,6 +13,8 @@ v4.7.2 true + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -45,6 +47,7 @@ On + @@ -66,43 +69,46 @@ - - - + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Drawing.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Drawing.My + Settings.Designer.cs - + \ No newline at end of file diff --git a/Pilz.Drawing/PointD.cs b/Pilz.Drawing/PointD.cs new file mode 100644 index 0000000..20eaed4 --- /dev/null +++ b/Pilz.Drawing/PointD.cs @@ -0,0 +1,39 @@ + +namespace Pilz.Drawing +{ + public class PointD + { + public double X { get; set; } + public double Y { get; set; } + + public PointD() + { + X = 0d; + Y = 0d; + } + + public PointD(double x, double y) + { + X = x; + Y = y; + } + + public static PointD Empty + { + get + { + return new PointD(); + } + } + + public static bool operator ==(PointD val1, PointD val2) + { + return val1.X == val2.X && val1.Y == val2.Y; + } + + public static bool operator !=(PointD val1, PointD val2) + { + return val1.X != val2.X || val1.Y != val2.Y; + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing/PointD.vb b/Pilz.Drawing/PointD.vb deleted file mode 100644 index f37d80f..0000000 --- a/Pilz.Drawing/PointD.vb +++ /dev/null @@ -1,31 +0,0 @@ -Public Class PointD - - Public Property X As Double - Public Property Y As Double - - Public Sub New() - X = 0 - Y = 0 - End Sub - - Public Sub New(x As Double, y As Double) - Me.X = x - Me.Y = y - End Sub - - Public Shared ReadOnly Property Empty As PointD - Get - Return New PointD - End Get - End Property - - Public Shared Operator =(val1 As PointD, val2 As PointD) As Boolean - Return val1.X = val2.X AndAlso val1.Y = val2.Y - End Operator - - Public Shared Operator <>(val1 As PointD, val2 As PointD) As Boolean - Return val1.X <> val2.X OrElse val1.Y <> val2.Y - End Operator - - -End Class diff --git a/Pilz.Drawing/Properties/AssemblyInfo.cs b/Pilz.Drawing/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8a4322b --- /dev/null +++ b/Pilz.Drawing/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("Pilz.Drawing")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("DRSN")] +[assembly: AssemblyProduct("Pilz.Drawing")] +[assembly: AssemblyCopyright("Copyright © DRSN 2019")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("42ba224c-e5dc-4b15-96f8-98b94825a820")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Drawing/Properties/Settings.Designer.cs b/Pilz.Drawing/Properties/Settings.Designer.cs new file mode 100644 index 0000000..7bd1bcf --- /dev/null +++ b/Pilz.Drawing/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Drawing.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Drawing/My Project/Settings.settings b/Pilz.Drawing/Properties/Settings.settings similarity index 100% rename from Pilz.Drawing/My Project/Settings.settings rename to Pilz.Drawing/Properties/Settings.settings diff --git a/Pilz.Drawing/Resources.Designer.cs b/Pilz.Drawing/Resources.Designer.cs new file mode 100644 index 0000000..f84fd22 --- /dev/null +++ b/Pilz.Drawing/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Drawing.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Drawing.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Drawing/Resources.resx b/Pilz.Drawing/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Drawing/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.IO/ManagedPipes/ManagedPipeClient.cs b/Pilz.IO/ManagedPipes/ManagedPipeClient.cs index 4264079..ae52d01 100644 --- a/Pilz.IO/ManagedPipes/ManagedPipeClient.cs +++ b/Pilz.IO/ManagedPipes/ManagedPipeClient.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using global::System.IO.Pipes; using System.Threading.Tasks; -using global::Pilz.Threading; +using Pilz.Threading; namespace Pilz.IO { diff --git a/Pilz.IO/Pilz.IO.csproj b/Pilz.IO/Pilz.IO.csproj index 19becee..8d445db 100644 --- a/Pilz.IO/Pilz.IO.csproj +++ b/Pilz.IO/Pilz.IO.csproj @@ -135,16 +135,16 @@ Settings.Designer.cs - - - {d9c8655e-4f1c-4348-a51c-ab00fd9a14bb} - Pilz.Threading - - 12.0.3 + + + {6bece435-8344-0cb9-2744-617e9f0d201b} + Pilz.Threading + + \ No newline at end of file diff --git a/Pilz.Networking/ConnectionManagerBase.cs b/Pilz.Networking/ConnectionManagerBase.cs new file mode 100644 index 0000000..0f04c5d --- /dev/null +++ b/Pilz.Networking/ConnectionManagerBase.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.Data; +using global::System.IO; +using System.Linq; +using global::System.Net; +using global::Newtonsoft.Json.Linq; + +namespace Pilz.Networking +{ + public abstract class ConnectionManagerBase + { + private const int HEADER_LENGTH = 12; + private bool listening = false; + private readonly Dictionary> dicData = new Dictionary>(); + + public int Port { get; private set; } + public bool UseAssemblyQualifiedName { get; set; } = false; + + public event RetriveDataEventHandler RetriveData; + + public delegate void RetriveDataEventHandler(ConnectionManagerBase manager, string senderIP, string cmd, object content); + + public bool IsListening + { + get + { + return listening; + } + + protected set + { + listening = value; + } + } + + public ConnectionManagerBase(int port) + { + Port = port; + } + + ~ConnectionManagerBase() + { + Stop(); + } + + public abstract void Start(); + public abstract void Stop(); + protected abstract void SendData(IPEndPoint endPoint, byte[] data); + protected abstract int GetBufferSize(); + + public virtual void Send(string empfängerIP, string cmd) + { + Send(empfängerIP, cmd, string.Empty); + } + + public virtual void Send(string empfängerIP, string cmd, string info) + { + Send(empfängerIP, cmd, info); + } + + private void RaiseRetriveData(string senderIP, string cmd, object content) + { + RetriveData?.Invoke(this, senderIP, cmd, content); + } + + protected void ProcessRetrivedData(string senderIP, byte[] buf) + { + int readInteger(int index) => buf[index] << 24 | buf[index + 1] << 16 | buf[index + 2] << 8 | buf[index + 3]; + int dataID = readInteger(0); + int packageID = readInteger(4); + int packageCount = readInteger(8); + bool resolveData = true; + + // Remember data + var data = buf.Skip(HEADER_LENGTH).ToArray(); + Dictionary dicMyData; + if (dicData.ContainsKey(dataID)) + { + dicMyData = dicData[dataID]; + if (dicMyData.ContainsKey(packageID)) + { + dicMyData[packageID] = data; + } + else + { + dicMyData.Add(packageID, data); + } + } + else + { + dicMyData = new Dictionary() { { packageID, data } }; + dicData.Add(dataID, dicMyData); + } + + if (dicMyData.Count < packageCount) + { + resolveData = false; + } + + // Resolve Data + if (resolveData) + { + if (dicMyData is null) + { + dicMyData = dicData[dataID]; + } + + var myData = new List(); + foreach (var kvp in dicMyData.OrderBy(n => n.Key)) + myData.AddRange(kvp.Value); + dicMyData.Remove(dataID); + object content = null; + string cmd = string.Empty; + try + { + var res = DecodeFromBytes(myData.ToArray()); + cmd = res.cmd; + content = res.content; + } + catch (Exception ex) + { + } + + RaiseRetriveData(senderIP, cmd, content); + } + } + + private Random send_Rnd = new Random(); + public void Send(string empfängerIP, string cmd, object content) + { + var ep = new IPEndPoint(NetworkFeatures.GetIPFromHost(empfängerIP).MapToIPv4(), Port); + var finalBuffer = new List(); + int maxBufferSize = GetBufferSize(); + int maxDataSize = maxBufferSize - HEADER_LENGTH; + var data = EncodeToBytes(cmd, content, UseAssemblyQualifiedName); + int dataID = send_Rnd.Next(); + + // Some methods for later user + void send() => SendData(ep, finalBuffer.ToArray()); + void addInteger(int value) => finalBuffer.AddRange(new byte[] { (byte)((value >> 24) & 0xFF), (byte)((value >> 16) & 0xFF), (byte)((value >> 8) & 0xFF), (byte)(value & 0xFF) }); + void addHeader(int packageID, int packagesCount) + { + addInteger(dataID); // Data ID + addInteger(packageID); // Package ID + addInteger(packagesCount); // Packages Count + }; + + // Send data (this if statement and else content might be useless) + if (data.Length > maxDataSize) + { + int curIndex = 0; + int curID = 0; + int packagesCount = (int)Math.Ceiling(data.Length / (double)maxDataSize); + while (curIndex < data.Length) + { + finalBuffer.Clear(); + addHeader(curID, packagesCount); + for (int i = 1, loopTo = maxDataSize; i <= loopTo; i++) + { + if (curIndex < data.Length) + { + finalBuffer.Add(data[curIndex]); + curIndex += 1; + } + } + + send(); + curID += 1; + } + } + else + { + addHeader(0, 1); + finalBuffer.AddRange(data); + send(); + } + } + + private static byte[] EncodeToBytes(string cmd, object content, bool useAssemblyQualifiedName) + { + var ms = new MemoryStream(); + var bw = new BinaryWriter(ms); + var obj = new JObject(); + + // Write header + obj["Cmd"] = cmd; + obj["ContentType"] = useAssemblyQualifiedName ? content?.GetType()?.AssemblyQualifiedName : content?.GetType()?.ToString(); + + // Content + obj["Content"] = JToken.FromObject(content); + + // Write Json to MemoryStream + bw.Write(System.Text.Encoding.Default.GetBytes(obj.ToString())); + + // Get Buffer Bytes + var buf = ms.ToArray(); + ms.Close(); + return buf; + } + + private static (string cmd, object content) DecodeFromBytes(byte[] buf) + { + string contentstring = System.Text.Encoding.Default.GetString(buf); + object content = null; + var contentobj = JObject.Parse(contentstring); + string cmd = (string)contentobj["Cmd"]; + string contenttypestring = (string)contentobj["ContentType"]; + var contentlinq = contentobj["Content"]; + if (!string.IsNullOrEmpty(contenttypestring)) + { + var contenttype = Type.GetType(contenttypestring); + content = contentlinq.ToObject(contenttype); + } + + return (cmd, content); + } + } +} \ No newline at end of file diff --git a/Pilz.Networking/ConnectionManagerBase.vb b/Pilz.Networking/ConnectionManagerBase.vb deleted file mode 100644 index 1f1dc1d..0000000 --- a/Pilz.Networking/ConnectionManagerBase.vb +++ /dev/null @@ -1,192 +0,0 @@ -Imports System.IO -Imports System.Net -Imports Newtonsoft.Json.Linq - -Public MustInherit Class ConnectionManagerBase - - Private Const HEADER_LENGTH As Integer = 12 - - Private listening As Boolean = False - Private ReadOnly dicData As New Dictionary(Of Integer, Dictionary(Of Integer, Byte())) - - Public ReadOnly Property Port As Integer - Public Property UseAssemblyQualifiedName As Boolean = False - - Public Event RetriveData(manager As ConnectionManagerBase, senderIP As String, cmd As String, content As Object) - - Public Property IsListening As Boolean - Get - Return listening - End Get - Protected Set(value As Boolean) - listening = value - End Set - End Property - - Public Sub New(port As Integer) - Me.Port = port - End Sub - - Protected Overrides Sub Finalize() - [Stop]() - End Sub - - Public MustOverride Sub Start() - Public MustOverride Sub [Stop]() - Protected MustOverride Sub SendData(endPoint As IPEndPoint, data As Byte()) - Protected MustOverride Function GetBufferSize() As Integer - - Public Overridable Sub Send(empfängerIP As String, cmd As String) - Send(empfängerIP, cmd, String.Empty) - End Sub - - Public Overridable Sub Send(empfängerIP As String, cmd As String, info As String) - Send(empfängerIP, cmd, CObj(info)) - End Sub - - Private Sub RaiseRetriveData(senderIP As String, cmd As String, content As Object) - RaiseEvent RetriveData(Me, senderIP, cmd, content) - End Sub - - Protected Sub ProcessRetrivedData(senderIP As String, buf As Byte()) - Dim readInteger = - Function(index As Integer) As Integer - Return (CInt(buf(index)) << 24) Or (CInt(buf(index + 1)) << 16) Or (CInt(buf(index + 2)) << 8) Or buf(index + 3) - End Function - - Dim dataID As Integer = readInteger(0) - Dim packageID As Integer = readInteger(4) - Dim packageCount As Integer = readInteger(8) - Dim resolveData As Boolean = True - - 'Remember data - Dim data As Byte() = buf.Skip(HEADER_LENGTH).ToArray - Dim dicMyData As Dictionary(Of Integer, Byte()) - - If dicData.ContainsKey(dataID) Then - dicMyData = dicData(dataID) - If dicMyData.ContainsKey(packageID) Then - dicMyData(packageID) = data - Else - dicMyData.Add(packageID, data) - End If - Else - dicMyData = New Dictionary(Of Integer, Byte()) From {{packageID, data}} - dicData.Add(dataID, dicMyData) - End If - - If dicMyData.Count < packageCount Then - resolveData = False - End If - - 'Resolve Data - If resolveData Then - If dicMyData Is Nothing Then - dicMyData = dicData(dataID) - End If - Dim myData As New List(Of Byte) - For Each kvp In dicMyData.OrderBy(Function(n) n.Key) - myData.AddRange(kvp.Value) - Next - dicMyData.Remove(dataID) - - Dim content As Object = Nothing - Dim cmd As String = String.Empty - Try - Dim res = DecodeFromBytes(myData.ToArray) - cmd = res.cmd - content = res.content - Catch ex As Exception - End Try - - RaiseRetriveData(senderIP, cmd, content) - End If - End Sub - - Public Sub Send(empfängerIP As String, cmd As String, content As Object) - Static rnd As New Random - Dim ep As New IPEndPoint(GetIPFromHost(empfängerIP).MapToIPv4, Port) - Dim finalBuffer As New List(Of Byte) - Dim maxBufferSize As Integer = GetBufferSize() - Dim maxDataSize As Integer = maxBufferSize - HEADER_LENGTH - Dim data As Byte() = EncodeToBytes(cmd, content, UseAssemblyQualifiedName) - Dim dataID As Integer = rnd.Next - - 'Some methods for later user - Dim send = Sub() SendData(ep, finalBuffer.ToArray) - Dim addInteger = - Sub(value As Integer) - finalBuffer.AddRange({(value >> 24) And &HFF, (value >> 16) And &HFF, (value >> 8) And &HFF, value And &HFF}) - End Sub - Dim addHeader = - Sub(packageID As Integer, packagesCount As Integer) - addInteger(dataID) 'Data ID - addInteger(packageID) 'Package ID - addInteger(packagesCount) 'Packages Count - End Sub - - 'Send data (this if statement and else content might be useless) - If data.Length > maxDataSize Then - Dim curIndex As Integer = 0 - Dim curID As Integer = 0 - Dim packagesCount As Integer = Math.Ceiling(data.Length / maxDataSize) - - Do While curIndex < data.Length - finalBuffer.Clear() - addHeader(curID, packagesCount) - For i As Integer = 1 To maxDataSize - If curIndex < data.Length Then - finalBuffer.Add(data(curIndex)) - curIndex += 1 - End If - Next - send() - curID += 1 - Loop - Else - addHeader(0, 1) - finalBuffer.AddRange(data) - send() - End If - End Sub - - Private Shared Function EncodeToBytes(cmd As String, content As Object, useAssemblyQualifiedName As Boolean) As Byte() - Dim ms As New MemoryStream() - Dim bw As New BinaryWriter(ms) - Dim obj As New JObject - - 'Write header - obj("Cmd") = cmd - obj("ContentType") = If(useAssemblyQualifiedName, content?.GetType?.AssemblyQualifiedName, content?.GetType?.ToString) - - 'Content - obj("Content") = JToken.FromObject(content) - - 'Write Json to MemoryStream - bw.Write(Text.Encoding.Default.GetBytes(obj.ToString)) - - 'Get Buffer Bytes - Dim buf As Byte() = ms.ToArray - ms.Close() - - Return buf - End Function - - Private Shared Function DecodeFromBytes(buf As Byte()) As (cmd As String, content As Object) - Dim contentstring As String = Text.Encoding.Default.GetString(buf) - Dim content As Object = Nothing - Dim contentobj As JObject = JObject.Parse(contentstring) - - Dim cmd As String = contentobj("Cmd") - Dim contenttypestring As String = contentobj("ContentType") - Dim contentlinq As JToken = contentobj("Content") - - If Not String.IsNullOrEmpty(contenttypestring) Then - Dim contenttype As Type = Type.GetType(contenttypestring) - content = contentlinq.ToObject(contenttype) - End If - - Return (cmd, content) - End Function - -End Class diff --git a/Pilz.Networking/My Project/Application.Designer.cs b/Pilz.Networking/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Networking/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Networking/My Project/Application.Designer.vb b/Pilz.Networking/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Networking/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Networking/My Project/AssemblyInfo.vb b/Pilz.Networking/My Project/AssemblyInfo.vb deleted file mode 100644 index c81f2f8..0000000 --- a/Pilz.Networking/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Networking/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Networking/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..65bbf63 --- /dev/null +++ b/Pilz.Networking/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Networking.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Networking/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Networking/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..4775149 --- /dev/null +++ b/Pilz.Networking/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Networking.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Networking/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Networking/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Networking/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Networking/My Project/Resources.Designer.vb b/Pilz.Networking/My Project/Resources.Designer.vb deleted file mode 100644 index 3fceebd..0000000 --- a/Pilz.Networking/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Networking.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Networking/My Project/Settings.Designer.vb b/Pilz.Networking/My Project/Settings.Designer.vb deleted file mode 100644 index 5906e16..0000000 --- a/Pilz.Networking/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Networking.My.MySettings - Get - Return Global.Pilz.Networking.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Networking/NetworkFeatures.cs b/Pilz.Networking/NetworkFeatures.cs new file mode 100644 index 0000000..fb088d1 --- /dev/null +++ b/Pilz.Networking/NetworkFeatures.cs @@ -0,0 +1,62 @@ +using System.Linq; +using global::System.Net; +using global::System.Net.NetworkInformation; +using global::System.Net.Sockets; + +namespace Pilz.Networking +{ + public static class NetworkFeatures + { + public static IPAddress GetIPFromHost(string hostName) + { + return Dns.GetHostAddresses(hostName).FirstOrDefault(n => n.AddressFamily == AddressFamily.InterNetwork); + } + + public static object GetHostFromIP(string ip) + { + return Dns.GetHostEntry(ip)?.HostName; + } + + public static UnicastIPAddressInformation GetLocalIPInformations() + { + UnicastIPAddressInformation addr = null; + foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) + { + if (addr is null && adapter.OperationalStatus == OperationalStatus.Up && adapter.NetworkInterfaceType != NetworkInterfaceType.Tunnel && adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback) + { + foreach (UnicastIPAddressInformation uni in adapter.GetIPProperties().UnicastAddresses) + { + if (addr is null && uni.Address.AddressFamily == AddressFamily.InterNetwork) + { + addr = uni; + } + } + } + } + + return addr; + } + + public static IPAddress GetLocalIPAddress() + { + return GetLocalIPInformations()?.Address; + } + + public static IPAddress GetLocalIPv4Mask() + { + return GetLocalIPInformations()?.IPv4Mask; + } + + public static IPAddress GetLocalBoradcastIP(UnicastIPAddressInformation ipInfo) + { + IPAddress ip = null; + var myIPBytes = ipInfo.Address.GetAddressBytes(); + var subnetBytes = ipInfo.IPv4Mask.GetAddressBytes(); + var broadcastBytes = new byte[myIPBytes.Length]; + for (int i = 0, loopTo = subnetBytes.Length - 1; i <= loopTo; i++) + broadcastBytes[i] = (byte)(myIPBytes[i] | ~subnetBytes[i]); + ip = new IPAddress(broadcastBytes); + return ip; + } + } +} \ No newline at end of file diff --git a/Pilz.Networking/NetworkFeatures.vb b/Pilz.Networking/NetworkFeatures.vb deleted file mode 100644 index 3c2f5df..0000000 --- a/Pilz.Networking/NetworkFeatures.vb +++ /dev/null @@ -1,54 +0,0 @@ -Imports System.Net -Imports System.Net.NetworkInformation -Imports System.Net.Sockets - -Public Module NetworkFeatures - - Public Function GetIPFromHost(hostName As String) As IPAddress - Return Dns.GetHostAddresses(hostName).FirstOrDefault(Function(n) n.AddressFamily = AddressFamily.InterNetwork) - End Function - - Public Function GetHostFromIP(ip As String) - Return Dns.GetHostEntry(ip)?.HostName - End Function - - Public Function GetLocalIPInformations() As UnicastIPAddressInformation - Dim addr As UnicastIPAddressInformation = Nothing - - For Each adapter As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces - If addr Is Nothing AndAlso adapter.OperationalStatus = OperationalStatus.Up AndAlso adapter.NetworkInterfaceType <> NetworkInterfaceType.Tunnel AndAlso adapter.NetworkInterfaceType <> NetworkInterfaceType.Loopback Then - For Each uni As UnicastIPAddressInformation In adapter.GetIPProperties.UnicastAddresses - If addr Is Nothing AndAlso uni.Address.AddressFamily = AddressFamily.InterNetwork Then - addr = uni - End If - Next - End If - Next - - Return addr - End Function - - Public Function GetLocalIPAddress() As IPAddress - Return GetLocalIPInformations()?.Address - End Function - - Public Function GetLocalIPv4Mask() As IPAddress - Return GetLocalIPInformations()?.IPv4Mask - End Function - - Public Function GetLocalBoradcastIP(ipInfo As UnicastIPAddressInformation) As IPAddress - Dim ip As IPAddress = Nothing - Dim myIPBytes As Byte() = ipInfo.Address.GetAddressBytes - Dim subnetBytes As Byte() = ipInfo.IPv4Mask.GetAddressBytes - Dim broadcastBytes As Byte() = New Byte(myIPBytes.Length - 1) {} - - For i As Integer = 0 To subnetBytes.Length - 1 - broadcastBytes(i) = myIPBytes(i) Or Not subnetBytes(i) - Next - - ip = New IPAddress(broadcastBytes) - - Return ip - End Function - -End Module diff --git a/Pilz.Networking/Pilz.Networking.vbproj b/Pilz.Networking/Pilz.Networking.csproj similarity index 72% rename from Pilz.Networking/Pilz.Networking.vbproj rename to Pilz.Networking/Pilz.Networking.csproj index c08a7cc..788e937 100644 --- a/Pilz.Networking/Pilz.Networking.vbproj +++ b/Pilz.Networking/Pilz.Networking.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {4584B121-09C6-40AC-849B-7E410125EF66} + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6} Library Pilz.Networking Pilz.Networking @@ -13,6 +13,8 @@ v4.7.2 true + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -45,6 +47,7 @@ On + @@ -65,43 +68,46 @@ - - - + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - - + + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Networking.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Networking.My + Settings.Designer.cs @@ -109,5 +115,5 @@ 12.0.3 - + \ No newline at end of file diff --git a/Pilz.Networking/Properties/AssemblyInfo.cs b/Pilz.Networking/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..16907a6 --- /dev/null +++ b/Pilz.Networking/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("Pilz.Networking")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("DRSN")] +[assembly: AssemblyProduct("Pilz.Networking")] +[assembly: AssemblyCopyright("Copyright © DRSN 2019")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("467b9a06-75bf-4894-b88d-397eeb2bb0cc")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Networking/Properties/Settings.Designer.cs b/Pilz.Networking/Properties/Settings.Designer.cs new file mode 100644 index 0000000..1384b03 --- /dev/null +++ b/Pilz.Networking/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Networking.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Networking/My Project/Settings.settings b/Pilz.Networking/Properties/Settings.settings similarity index 100% rename from Pilz.Networking/My Project/Settings.settings rename to Pilz.Networking/Properties/Settings.settings diff --git a/Pilz.Networking/Resources.Designer.cs b/Pilz.Networking/Resources.Designer.cs new file mode 100644 index 0000000..47a9666 --- /dev/null +++ b/Pilz.Networking/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Networking.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Networking.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Networking/Resources.resx b/Pilz.Networking/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Networking/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.Networking/TCPManager.cs b/Pilz.Networking/TCPManager.cs new file mode 100644 index 0000000..0c86914 --- /dev/null +++ b/Pilz.Networking/TCPManager.cs @@ -0,0 +1,74 @@ +using global::System.Net; +using global::System.Net.Sockets; +using System.Threading.Tasks; + +namespace Pilz.Networking +{ + public class TCPManager : ConnectionManagerBase + { + private readonly TcpListener listener; + + public int BufferSize { get; set; } = 10240; + + public TCPManager(int port) : base(port) + { + listener = new TcpListener(IPAddress.Any, port); + } + + public override void Start() + { + if (!IsListening) + { + listener.Start(); + IsListening = true; + Task.Run(CheckRetriveData); + } + } + + public override void Stop() + { + if (IsListening) + { + IsListening = false; + listener.Stop(); + } + } + + protected override int GetBufferSize() + { + return BufferSize; + } + + private void CheckRetriveData() + { + while (IsListening) + { + if (listener.Pending()) + { + var tcp = listener.AcceptTcpClient(); + string ip = ((IPEndPoint)tcp.Client.RemoteEndPoint).Address.ToString(); + var Stream = tcp.GetStream(); + var buf = new byte[BufferSize]; + tcp.ReceiveBufferSize = BufferSize; + Stream.Read(buf, 0, buf.Length); + tcp.Close(); + ProcessRetrivedData(ip, buf); + } + } + } + + protected override void SendData(IPEndPoint ep, byte[] buf) + { + var tcp = new TcpClient(); + tcp.SendBufferSize = BufferSize; + tcp.Connect(ep); + var stream = tcp.GetStream(); + + // Send Data + stream.Write(buf, 0, buf.Length); + stream.Flush(); + tcp.Client.Shutdown(SocketShutdown.Both); + tcp.Close(); + } + } +} \ No newline at end of file diff --git a/Pilz.Networking/TCPManager.vb b/Pilz.Networking/TCPManager.vb deleted file mode 100644 index 801dcf9..0000000 --- a/Pilz.Networking/TCPManager.vb +++ /dev/null @@ -1,71 +0,0 @@ -Imports System.IO -Imports System.Net -Imports System.Net.NetworkInformation -Imports System.Net.Sockets -Imports Newtonsoft.Json.Linq - -Public Class TCPManager - Inherits ConnectionManagerBase - - Private ReadOnly listener As TcpListener - Public Property BufferSize As Integer = 10240 - - Public Sub New(port As Integer) - MyBase.New(port) - listener = New TcpListener(IPAddress.Any, port) - End Sub - - Public Overrides Sub Start() - If Not IsListening Then - listener.Start() - IsListening = True - Task.Run(AddressOf CheckRetriveData) - End If - End Sub - - Public Overrides Sub [Stop]() - If IsListening Then - IsListening = False - listener.Stop() - End If - End Sub - - Protected Overrides Function GetBufferSize() As Integer - Return BufferSize - End Function - - Private Sub CheckRetriveData() - Do While IsListening - If listener.Pending Then - Dim tcp As TcpClient = listener.AcceptTcpClient() - Dim ip As String = CType(tcp.Client.RemoteEndPoint, IPEndPoint).Address.ToString - Dim Stream As NetworkStream = tcp.GetStream - Dim buf As Byte() = New Byte(BufferSize - 1) {} - - tcp.ReceiveBufferSize = BufferSize - Stream.Read(buf, 0, buf.Length) - - tcp.Close() - - ProcessRetrivedData(ip, buf) - End If - Loop - End Sub - - Protected Overrides Sub SendData(ep As IPEndPoint, buf As Byte()) - Dim tcp As New TcpClient - - tcp.SendBufferSize = BufferSize - tcp.Connect(ep) - - Dim stream As NetworkStream = tcp.GetStream() - - 'Send Data - stream.Write(buf, 0, buf.Length) - stream.Flush() - - tcp.Client.Shutdown(SocketShutdown.Both) - tcp.Close() - End Sub - -End Class diff --git a/Pilz.Networking/UDPManager.cs b/Pilz.Networking/UDPManager.cs new file mode 100644 index 0000000..184191a --- /dev/null +++ b/Pilz.Networking/UDPManager.cs @@ -0,0 +1,83 @@ +using System; +using global::System.Net; +using global::System.Net.Sockets; +using global::System.Threading; +using System.Threading.Tasks; + +namespace Pilz.Networking +{ + public class UDPManager : ConnectionManagerBase + { + public UDPManager(int port) : base(port) + { + cancelToken = cancelTokenSource.Token; + client = new UdpClient(port); + } + + private readonly UdpClient client; + private Task listenTask = null; + private readonly CancellationTokenSource cancelTokenSource = new CancellationTokenSource(); + private readonly CancellationToken cancelToken; + + public int MaxBufferSize { get; private set; } = 8192; + + ~UDPManager() + { + client.Client.Shutdown(SocketShutdown.Both); + client.Close(); + } + + public override void Start() + { + if (!IsListening) + { + StartInternal(); + } + } + + private void StartInternal() + { + IsListening = true; + listenTask = Task.Run(() => { try { RetriveAnyData(cancelToken); } catch (Exception ex) { IsListening = false; } }); + } + + public override void Stop() + { + if (IsListening) + { + IsListening = false; + cancelTokenSource.Cancel(); + listenTask.Wait(); + } + } + + protected override int GetBufferSize() + { + return MaxBufferSize; + } + + private void RetriveAnyData(CancellationToken ct) + { + void doExit() => ct.ThrowIfCancellationRequested(); + var receiveTask = client.ReceiveAsync(); + + // Wait for the data and cancel if requested + receiveTask.Wait(ct); + var buf = receiveTask.Result.Buffer; + string ip = receiveTask.Result.RemoteEndPoint.Address.ToString(); + doExit(); + ProcessRetrivedData(ip, buf); + doExit(); + StartInternal(); + } + + protected override void SendData(IPEndPoint ep, byte[] buf) + { + var udp = new UdpClient(); + udp.Connect(ep); + udp.Send(buf, buf.Length); + udp.Client.Shutdown(SocketShutdown.Both); + udp.Close(); + } + } +} \ No newline at end of file diff --git a/Pilz.Networking/UDPManager.vb b/Pilz.Networking/UDPManager.vb deleted file mode 100644 index 99dba2e..0000000 --- a/Pilz.Networking/UDPManager.vb +++ /dev/null @@ -1,85 +0,0 @@ -Imports System.IO -Imports System.Net -Imports System.Net.NetworkInformation -Imports System.Net.Sockets -Imports System.Threading -Imports Newtonsoft.Json.Linq - -Public Class UDPManager - Inherits ConnectionManagerBase - - Private ReadOnly client As UdpClient - Private listenTask As Task = Nothing - Private ReadOnly cancelTokenSource As New CancellationTokenSource - Private ReadOnly cancelToken As CancellationToken = cancelTokenSource.Token - Public ReadOnly Property MaxBufferSize As Integer = 8192 - - Public Sub New(port As Integer) - MyBase.New(port) - client = New UdpClient(port) - End Sub - - Protected Overrides Sub Finalize() - MyBase.Finalize() - client.Client.Shutdown(SocketShutdown.Both) - client.Close() - End Sub - - Public Overrides Sub Start() - If Not IsListening Then - StartInternal() - End If - End Sub - - Private Sub StartInternal() - IsListening = True - listenTask = Task.Run( - Sub() - Try - RetriveAnyData(cancelToken) - Catch ex As Exception - IsListening = False - End Try - End Sub) - End Sub - - Public Overrides Sub [Stop]() - If IsListening Then - IsListening = False - cancelTokenSource.Cancel() - listenTask.Wait() - End If - End Sub - - Protected Overrides Function GetBufferSize() As Integer - Return MaxBufferSize - End Function - - Private Sub RetriveAnyData(ct As CancellationToken) - Dim doExit = Sub() ct.ThrowIfCancellationRequested() - Dim receiveTask As Task(Of UdpReceiveResult) = client.ReceiveAsync() - - 'Wait for the data and cancel if requested - receiveTask.Wait(ct) - - Dim buf As Byte() = receiveTask.Result.Buffer - Dim ip As String = receiveTask.Result.RemoteEndPoint.Address.ToString - - doExit() - - ProcessRetrivedData(ip, buf) - - doExit() - - StartInternal() - End Sub - - Protected Overrides Sub SendData(ep As IPEndPoint, buf As Byte()) - Dim udp As New UdpClient - udp.Connect(ep) - udp.Send(buf, buf.Length) - udp.Client.Shutdown(SocketShutdown.Both) - udp.Close() - End Sub - -End Class diff --git a/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.cs b/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.cs new file mode 100644 index 0000000..3f41c2a --- /dev/null +++ b/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.cs @@ -0,0 +1,19 @@ +using System; + +namespace Pilz.Reflection.PluginSystem.Attributes +{ + public class PluginFunctionAttribute : Attribute + { + public string FunctionCode { get; private set; } + public object[] Params { get; private set; } + + /// + /// The function code for this PluginFunction. + /// The parameters for this PluginFunction. + public PluginFunctionAttribute(string funcCode, params object[] @params) + { + FunctionCode = funcCode; + Params = @params; + } + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.vb b/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.vb deleted file mode 100644 index e3b1c1e..0000000 --- a/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.vb +++ /dev/null @@ -1,19 +0,0 @@ -Namespace Attributes - - Public Class PluginFunctionAttribute - Inherits Attribute - - Public ReadOnly Property FunctionCode As String - Public ReadOnly Property Params As Object() - - ''' - ''' The function code for this PluginFunction. - ''' The parameters for this PluginFunction. - Public Sub New(funcCode As String, ParamArray params As Object()) - Me.FunctionCode = funcCode - Me.Params = params - End Sub - - End Class - -End Namespace diff --git a/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.cs b/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.cs new file mode 100644 index 0000000..ce7eda6 --- /dev/null +++ b/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.cs @@ -0,0 +1,8 @@ +using System; + +namespace Pilz.Reflection.PluginSystem.Attributes +{ + public class LoadMethodAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.vb b/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.vb deleted file mode 100644 index d898afc..0000000 --- a/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.vb +++ /dev/null @@ -1,7 +0,0 @@ -Namespace Attributes - - Public Class LoadMethodAttribute - Inherits Attribute - End Class - -End Namespace diff --git a/Pilz.Reflection.PluginSystem/My Project/Application.Designer.cs b/Pilz.Reflection.PluginSystem/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Reflection.PluginSystem/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Reflection.PluginSystem/My Project/Application.Designer.vb b/Pilz.Reflection.PluginSystem/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Reflection.PluginSystem/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Reflection.PluginSystem/My Project/AssemblyInfo.vb b/Pilz.Reflection.PluginSystem/My Project/AssemblyInfo.vb deleted file mode 100644 index 6cc80cf..0000000 --- a/Pilz.Reflection.PluginSystem/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..6da7aee --- /dev/null +++ b/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Reflection.PluginSystem.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..f991845 --- /dev/null +++ b/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Reflection.PluginSystem.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Reflection.PluginSystem/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/My Project/Resources.Designer.vb b/Pilz.Reflection.PluginSystem/My Project/Resources.Designer.vb deleted file mode 100644 index 931e75d..0000000 --- a/Pilz.Reflection.PluginSystem/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Reflection.PluginSystem.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Reflection.PluginSystem/My Project/Settings.Designer.vb b/Pilz.Reflection.PluginSystem/My Project/Settings.Designer.vb deleted file mode 100644 index b9afff4..0000000 --- a/Pilz.Reflection.PluginSystem/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Reflection.PluginSystem.My.MySettings - Get - Return Global.Pilz.Reflection.PluginSystem.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.vbproj b/Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.csproj similarity index 69% rename from Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.vbproj rename to Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.csproj index 0ea782c..c47197d 100644 --- a/Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.vbproj +++ b/Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7} + {45B3D51B-80FB-005A-3932-69D15BEF9F17} Library Pilz.Reflection.PluginSystem Pilz.Reflection.PluginSystem @@ -13,6 +13,8 @@ v4.7.2 true + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -45,6 +47,7 @@ On + @@ -65,46 +68,49 @@ - - - - - + + + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - - + + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Reflection.PluginSystem.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Reflection.PluginSystem.My + Settings.Designer.cs - + \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/Plugin.cs b/Pilz.Reflection.PluginSystem/Plugin.cs new file mode 100644 index 0000000..646ef0a --- /dev/null +++ b/Pilz.Reflection.PluginSystem/Plugin.cs @@ -0,0 +1,152 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using global::System.Reflection; +using global::Pilz.Reflection.PluginSystem.Attributes; + +namespace Pilz.Reflection.PluginSystem +{ + public class Plugin + { + + /// + /// A collection of Methods that contains PluginFunctions that will be called automatically when loading the Plugin, as long as the property AutoCallMainFunctions is set to True. + /// + /// + public IReadOnlyList MainFunctions { get; private set; } + /// + /// A collection of Methods with a FunctionCode (excluding all PluginFunctions from MainFunctions). + /// + /// + public IReadOnlyList PluginFunctions { get; private set; } + /// + /// Gets the assembly that contains the PluginFunctions of this Plugin + /// + /// + public Assembly Assembly { get; private set; } + /// + /// Gets the main module that contains the PluginFunctions of this Plugin + /// + /// + public Type MainModule { get; private set; } + + /// + /// Load a new Plugin and its PluginFunctions. + /// + /// + /// If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. + /// The name of the type where to search for Methods when loading a new Plugin. + public Plugin(string filePath, bool autoCallMainFunction, string entryTypeName) + { + Assembly = Assembly.LoadFile(filePath); + MainModule = Assembly.GetType(entryTypeName); + if (MainModule is null) + { + throw new PluginLoadException("Plugin Modul not found!"); + } + + // Define the attribute types to observe + var entryMethodType = typeof(LoadMethodAttribute); + var implementMethodType = typeof(PluginFunctionAttribute); + + // Create the lists + var mainMethods = new List(); + var implementMethods = new List(); + + // Search for PluginFunctions + foreach (MethodInfo mi in MainModule.GetMethods()) + { + bool found = false; + + // Check if the method has one of the defined attributes + foreach (Attribute attr in Attribute.GetCustomAttributes(mi)) + { + if (!found) + { + var t = attr.GetType(); + switch (t) + { + case var @case when @case == entryMethodType: + { + mainMethods.Add(new PluginFunction(mi, this)); + break; + } + + case var case1 when case1 == implementMethodType: + { + { + var withBlock = (PluginFunctionAttribute)attr; + implementMethods.Add(new PluginFunction(mi, this, withBlock.Params, withBlock.FunctionCode)); + } + + break; + } + } + + found = true; + } + } + } + + // Set the collections + MainFunctions = mainMethods; + PluginFunctions = implementMethods; + + // Call all PluginFunctions in MainFunctions + if (autoCallMainFunction) + { + foreach (PluginFunction func in mainMethods) + { + var @params = func.Method.GetParameters(); + if (@params.Length == 1) + { + string startupExe = Assembly.GetEntryAssembly().Location; + var args = new[] { startupExe, filePath }; + func.Invoke(new[] { args }); + } + else if (!@params.Any()) + { + func.Invoke(); + } + } + } + } + + /// + /// Get all PluginFunctions that have one of the given function codes. + /// + /// + /// + public IEnumerable GetFunctions(params string[] funcCodes) + { + var funcs = new List(); + foreach (PluginFunction func in PluginFunctions) + { + if (funcCodes.Contains(func.FunctionCode)) + { + funcs.Add(func); + } + } + + return funcs; + } + + /// + /// Get the first PluginFunction that have the one of the given function codes. + /// + /// + public PluginFunction GetFunction(params string[] funcCodes) + { + PluginFunction f = null; + foreach (PluginFunction func in PluginFunctions) + { + if (f is null && funcCodes.Contains(func.FunctionCode)) + { + f = func; + } + } + + return f; + } + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/Plugin.vb b/Pilz.Reflection.PluginSystem/Plugin.vb deleted file mode 100644 index 0498da7..0000000 --- a/Pilz.Reflection.PluginSystem/Plugin.vb +++ /dev/null @@ -1,127 +0,0 @@ -Imports System.IO -Imports System.Reflection -Imports Pilz.Reflection.PluginSystem.Attributes - -Public Class Plugin - - ''' - ''' A collection of Methods that contains PluginFunctions that will be called automatically when loading the Plugin, as long as the property AutoCallMainFunctions is set to True. - ''' - ''' - Public ReadOnly Property MainFunctions As IReadOnlyList(Of PluginFunction) - ''' - ''' A collection of Methods with a FunctionCode (excluding all PluginFunctions from MainFunctions). - ''' - ''' - Public ReadOnly Property PluginFunctions As IReadOnlyList(Of PluginFunction) - ''' - ''' Gets the assembly that contains the PluginFunctions of this Plugin - ''' - ''' - Public ReadOnly Property Assembly As Assembly - ''' - ''' Gets the main module that contains the PluginFunctions of this Plugin - ''' - ''' - Public ReadOnly Property MainModule As Type - - ''' - ''' Load a new Plugin and its PluginFunctions. - ''' - ''' - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' The name of the type where to search for Methods when loading a new Plugin. - Public Sub New(filePath As String, autoCallMainFunction As Boolean, entryTypeName As String) - Assembly = Assembly.LoadFile(filePath) - MainModule = Assembly.GetType(entryTypeName) - - If MainModule Is Nothing Then - Throw New PluginLoadException("Plugin Modul not found!") - End If - - 'Define the attribute types to observe - Dim entryMethodType As Type = GetType(LoadMethodAttribute) - Dim implementMethodType As Type = GetType(PluginFunctionAttribute) - - 'Create the lists - Dim mainMethods As New List(Of PluginFunction) - Dim implementMethods As New List(Of PluginFunction) - - 'Search for PluginFunctions - For Each mi As MethodInfo In MainModule.GetMethods - Dim found As Boolean = False - - 'Check if the method has one of the defined attributes - For Each attr As Attribute In Attribute.GetCustomAttributes(mi) - If Not found Then - Dim t As Type = attr.GetType - - Select Case t - Case entryMethodType - mainMethods.Add(New PluginFunction(mi, Me)) - - Case implementMethodType - With CType(attr, PluginFunctionAttribute) - implementMethods.Add(New PluginFunction(mi, Me, .Params, .FunctionCode)) - End With - - End Select - - found = True - End If - Next - Next - - 'Set the collections - Me.MainFunctions = mainMethods - Me.PluginFunctions = implementMethods - - 'Call all PluginFunctions in MainFunctions - If autoCallMainFunction Then - For Each func As PluginFunction In mainMethods - Dim params As ParameterInfo() = func.Method.GetParameters - If params.Length = 1 Then - Dim startupExe As String = Assembly.GetEntryAssembly.Location - Dim args As String() = {startupExe, filePath} - func.Invoke({args}) - ElseIf Not params.Any Then - func.Invoke() - End If - Next - End If - End Sub - - ''' - ''' Get all PluginFunctions that have one of the given function codes. - ''' - ''' - ''' - Public Function GetFunctions(ParamArray funcCodes As String()) As IEnumerable(Of PluginFunction) - Dim funcs As New List(Of PluginFunction) - - For Each func As PluginFunction In PluginFunctions - If funcCodes.Contains(func.FunctionCode) Then - funcs.Add(func) - End If - Next - - Return funcs - End Function - - ''' - ''' Get the first PluginFunction that have the one of the given function codes. - ''' - ''' - Public Function GetFunction(ParamArray funcCodes As String()) As PluginFunction - Dim f As PluginFunction = Nothing - - For Each func As PluginFunction In PluginFunctions - If f Is Nothing AndAlso funcCodes.Contains(func.FunctionCode) Then - f = func - End If - Next - - Return f - End Function - -End Class diff --git a/Pilz.Reflection.PluginSystem/PluginFunction.cs b/Pilz.Reflection.PluginSystem/PluginFunction.cs new file mode 100644 index 0000000..b7540cb --- /dev/null +++ b/Pilz.Reflection.PluginSystem/PluginFunction.cs @@ -0,0 +1,80 @@ +using global::System.Reflection; + +namespace Pilz.Reflection.PluginSystem +{ + public class PluginFunction + { + + /// + /// Gets the method to invoke when invoking this PluginFunction. + /// + /// + public MethodInfo Method { get; private set; } + + /// + /// Gets the refered Plugin for this PluginFunction, if it has one. + /// + /// + public Plugin Plugin { get; private set; } + + /// + /// Gets the Parameters that was given by the attribute. + /// + /// + public object[] Params { get; private set; } + + /// + /// Gets the function code for this PluginFunction. + /// + /// + public string FunctionCode { get; private set; } + + /// + /// Creates a new instance of a PluginFunction. + /// + /// The Method to invoke when invoking this PluginFunction. + /// The Plugin that is the Parent of this PluginFunction. This value can be NULL. + public PluginFunction(MethodInfo method, Plugin plugin) + { + Method = method; + Plugin = plugin; + } + + /// + /// Creates a new instance of a PluginFunction. + /// + /// The Method to invoke when invoking this PluginFunction.. + /// The Plugin that is the Parent of this PluginFunction. This value can be NULL. + /// The Parameters that was given by the attribute. + /// The function code for this PluginFunction. + public PluginFunction(MethodInfo method, Plugin plugin, object[] @params, string funcCode) : this(method, plugin) + { + Params = @params; + FunctionCode = funcCode; + } + + /// + /// Invokes the Method of the PluginFunction. + /// + public void Invoke() + { + Method.Invoke(null, null); + } + + /// + /// Invokes the Method of the PluginFunction. + /// + public void Invoke(params object[] @params) + { + Method.Invoke(null, @params); + } + + /// + /// Invokes the Method of the PluginFunction and returns the return value. + /// + public object InvokeGet(params object[] @params) + { + return Method.Invoke(null, @params); + } + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/PluginFunction.vb b/Pilz.Reflection.PluginSystem/PluginFunction.vb deleted file mode 100644 index 28c0b3f..0000000 --- a/Pilz.Reflection.PluginSystem/PluginFunction.vb +++ /dev/null @@ -1,73 +0,0 @@ -Imports System.Reflection - -Public Class PluginFunction - - ''' - ''' Gets the method to invoke when invoking this PluginFunction. - ''' - ''' - Public ReadOnly Property Method As MethodInfo - - ''' - ''' Gets the refered Plugin for this PluginFunction, if it has one. - ''' - ''' - Public ReadOnly Property Plugin As Plugin - - ''' - ''' Gets the Parameters that was given by the attribute. - ''' - ''' - Public ReadOnly Property Params As Object() - - ''' - ''' Gets the function code for this PluginFunction. - ''' - ''' - Public ReadOnly Property FunctionCode As String - - ''' - ''' Creates a new instance of a PluginFunction. - ''' - ''' The Method to invoke when invoking this PluginFunction. - ''' The Plugin that is the Parent of this PluginFunction. This value can be NULL. - Public Sub New(method As MethodInfo, plugin As Plugin) - Me.Method = method - Me.Plugin = plugin - End Sub - - ''' - ''' Creates a new instance of a PluginFunction. - ''' - ''' The Method to invoke when invoking this PluginFunction.. - ''' The Plugin that is the Parent of this PluginFunction. This value can be NULL. - ''' The Parameters that was given by the attribute. - ''' The function code for this PluginFunction. - Public Sub New(method As MethodInfo, plugin As Plugin, params As Object(), funcCode As String) - Me.New(method, plugin) - Me.Params = params - Me.FunctionCode = funcCode - End Sub - - ''' - ''' Invokes the Method of the PluginFunction. - ''' - Public Sub Invoke() - Method.Invoke(Nothing, Nothing) - End Sub - - ''' - ''' Invokes the Method of the PluginFunction. - ''' - Public Sub Invoke(ParamArray params As Object()) - Method.Invoke(Nothing, params) - End Sub - - ''' - ''' Invokes the Method of the PluginFunction and returns the return value. - ''' - Public Function InvokeGet(ParamArray params As Object()) As Object - Return Method.Invoke(Nothing, params) - End Function - -End Class diff --git a/Pilz.Reflection.PluginSystem/PluginLoadException.cs b/Pilz.Reflection.PluginSystem/PluginLoadException.cs new file mode 100644 index 0000000..2d2c09a --- /dev/null +++ b/Pilz.Reflection.PluginSystem/PluginLoadException.cs @@ -0,0 +1,15 @@ +using System; + +namespace Pilz.Reflection.PluginSystem +{ + public class PluginLoadException : Exception + { + public PluginLoadException() : base() + { + } + + public PluginLoadException(string message) : base(message) + { + } + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/PluginLoadException.vb b/Pilz.Reflection.PluginSystem/PluginLoadException.vb deleted file mode 100644 index fef7f10..0000000 --- a/Pilz.Reflection.PluginSystem/PluginLoadException.vb +++ /dev/null @@ -1,11 +0,0 @@ -Public Class PluginLoadException - Inherits Exception - - Public Sub New() - MyBase.New - End Sub - - Public Sub New(message As String) - MyBase.New(message) - End Sub -End Class diff --git a/Pilz.Reflection.PluginSystem/PluginManager.cs b/Pilz.Reflection.PluginSystem/PluginManager.cs new file mode 100644 index 0000000..bdf5178 --- /dev/null +++ b/Pilz.Reflection.PluginSystem/PluginManager.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using global::System.IO; + +namespace Pilz.Reflection.PluginSystem +{ + public class PluginManager + { + + /// + /// The name of the type where to search for Methods when loading a new Plugin. + /// + /// + public string EntryTypeName { get; set; } = "Plugin"; + + /// + /// If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. + /// + /// + public bool AutoCallMainFunctions { get; set; } = true; + + /// + /// A collection of all loaded Plugins. + /// + /// + public Dictionary Plugins { get; private set; } = new Dictionary(); + + /// + /// Loads Plugins that can be found at the given path and adds them to the Plugins-List. + /// + /// The path where to search for Plugins to load. + public IEnumerable LoadPlugins(string pluginPath) + { + return LoadPlugins(pluginPath, true); + } + + /// + /// Loads Plugins that can be found at the given path and adds them to the Plugins-List. + /// + /// The path where to search for Plugins to load. + /// If true, the Plugins will be added to Plugins-List after loading. + public IEnumerable LoadPlugins(string pluginPath, bool addToList) + { + return LoadPlugins(pluginPath, addToList, AutoCallMainFunctions, EntryTypeName); + } + + /// + /// Loads Plugins that can be found at the given path and adds them to the Plugins-List. + /// + /// The path where to search for Plugins to load. + /// If true, the Plugins will be added to Plugins-List after loading. + /// If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. + /// The name of the type where to search for Methods when loading a new Plugin. + public IEnumerable LoadPlugins(string pluginPath, bool addToList, bool autoCallMainFunction, string entryTypeName) + { + var loaded = new List(); + foreach (string f in Directory.GetFiles(pluginPath, "*.dll", SearchOption.AllDirectories)) + { + var p = LoadPlugin(f, addToList); + if (p is object) + { + loaded.Add(p); + } + } + + return loaded; + } + + /// + /// Loads a Plugin and adds it to the Plugins-List. + /// + /// The path to the plugin to load. + /// If true, the Plugin will be added to Plugins-List after loading. + public Plugin LoadPlugin(string filePath, bool addToList) + { + return LoadPlugin(filePath, addToList, AutoCallMainFunctions, EntryTypeName); + } + + /// + /// Loads a Plugin and adds it to the Plugins-List. + /// + /// The path to the plugin to load. + /// If true, the Plugin will be added to Plugins-List after loading. + /// If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. + /// The name of the type where to search for Methods when loading a new Plugin. + public Plugin LoadPlugin(string filePath, bool addToList, bool autoCallMainFunction, string entryTypeName) + { + try + { + var plugin = new Plugin(filePath, autoCallMainFunction, entryTypeName); + if (addToList) + Plugins.Add(filePath, plugin); + return plugin; + } + catch (Exception ex) + { + return null; + } + } + + /// + /// Loads a Plugin and adds it to the Plugins-List. + /// + /// The path to the plugin to load. + public Plugin LoadPlugin(string filePath) + { + return LoadPlugin(filePath, true); + } + + /// + /// Get all PluginFunctions that have one of the given function codes. + /// + /// + /// + public IEnumerable GetFunctions(params string[] funcCodes) + { + var list = new List(); + foreach (var kvp in Plugins) + list.AddRange(kvp.Value.GetFunctions(funcCodes)); + return list; + } + + /// + /// Get the first PluginFunction that have the one of the given function codes. + /// + /// + public PluginFunction GetFunction(params string[] funcCodes) + { + PluginFunction f = null; + foreach (var kvp in Plugins) + { + if (f is null) + { + foreach (PluginFunction func in kvp.Value.GetFunctions(funcCodes)) + { + if (f is null) + { + f = func; + } + } + } + } + + return f; + } + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/PluginManager.vb b/Pilz.Reflection.PluginSystem/PluginManager.vb deleted file mode 100644 index c7acaa8..0000000 --- a/Pilz.Reflection.PluginSystem/PluginManager.vb +++ /dev/null @@ -1,129 +0,0 @@ -Imports System.IO - -Public Class PluginManager - - ''' - ''' The name of the type where to search for Methods when loading a new Plugin. - ''' - ''' - Public Property EntryTypeName As String = "Plugin" - - ''' - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' - ''' - Public Property AutoCallMainFunctions As Boolean = True - - ''' - ''' A collection of all loaded Plugins. - ''' - ''' - Public ReadOnly Property Plugins As New Dictionary(Of String, Plugin) - - ''' - ''' Loads Plugins that can be found at the given path and adds them to the Plugins-List. - ''' - ''' The path where to search for Plugins to load. - Public Function LoadPlugins(pluginPath As String) As IEnumerable(Of Plugin) - Return LoadPlugins(pluginPath, True) - End Function - - ''' - ''' Loads Plugins that can be found at the given path and adds them to the Plugins-List. - ''' - ''' The path where to search for Plugins to load. - ''' If true, the Plugins will be added to Plugins-List after loading. - Public Function LoadPlugins(pluginPath As String, addToList As Boolean) As IEnumerable(Of Plugin) - Return LoadPlugins(pluginPath, addToList, AutoCallMainFunctions, EntryTypeName) - End Function - - ''' - ''' Loads Plugins that can be found at the given path and adds them to the Plugins-List. - ''' - ''' The path where to search for Plugins to load. - ''' If true, the Plugins will be added to Plugins-List after loading. - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' The name of the type where to search for Methods when loading a new Plugin. - Public Function LoadPlugins(pluginPath As String, addToList As Boolean, autoCallMainFunction As Boolean, entryTypeName As String) As IEnumerable(Of Plugin) - Dim loaded As New List(Of Plugin) - - For Each f As String In Directory.GetFiles(pluginPath, "*.dll", SearchOption.AllDirectories) - Dim p As Plugin = LoadPlugin(f, addToList) - If p IsNot Nothing Then - loaded.Add(p) - End If - Next - - Return loaded - End Function - - ''' - ''' Loads a Plugin and adds it to the Plugins-List. - ''' - ''' The path to the plugin to load. - ''' If true, the Plugin will be added to Plugins-List after loading. - Public Function LoadPlugin(filePath As String, addToList As Boolean) As Plugin - Return LoadPlugin(filePath, addToList, AutoCallMainFunctions, EntryTypeName) - End Function - - ''' - ''' Loads a Plugin and adds it to the Plugins-List. - ''' - ''' The path to the plugin to load. - ''' If true, the Plugin will be added to Plugins-List after loading. - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' The name of the type where to search for Methods when loading a new Plugin. - Public Function LoadPlugin(filePath As String, addToList As Boolean, autoCallMainFunction As Boolean, entryTypeName As String) As Plugin - Try - Dim plugin As New Plugin(filePath, autoCallMainFunction, entryTypeName) - If addToList Then Plugins.Add(filePath, plugin) - Return plugin - Catch ex As Exception - Return Nothing - End Try - End Function - - ''' - ''' Loads a Plugin and adds it to the Plugins-List. - ''' - ''' The path to the plugin to load. - Public Function LoadPlugin(filePath As String) As Plugin - Return LoadPlugin(filePath, True) - End Function - - ''' - ''' Get all PluginFunctions that have one of the given function codes. - ''' - ''' - ''' - Public Function GetFunctions(ParamArray funcCodes As String()) As IEnumerable(Of PluginFunction) - Dim list As New List(Of PluginFunction) - - For Each kvp In Plugins - list.AddRange(kvp.Value.GetFunctions(funcCodes)) - Next - - Return list - End Function - - ''' - ''' Get the first PluginFunction that have the one of the given function codes. - ''' - ''' - Public Function GetFunction(ParamArray funcCodes As String()) As PluginFunction - Dim f As PluginFunction = Nothing - - For Each kvp In Plugins - If f Is Nothing Then - For Each func As PluginFunction In kvp.Value.GetFunctions(funcCodes) - If f Is Nothing Then - f = func - End If - Next - End If - Next - - Return f - End Function - -End Class diff --git a/Pilz.Reflection.PluginSystem/Properties/AssemblyInfo.cs b/Pilz.Reflection.PluginSystem/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cef2aef --- /dev/null +++ b/Pilz.Reflection.PluginSystem/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("Pilz.Reflection.PluginSystem")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("Pascal Schedel")] +[assembly: AssemblyProduct("Pilz.Reflection.PluginSystem")] +[assembly: AssemblyCopyright("Copyright © Pascal Schedel 2019")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("71d06604-a99f-4aa7-9dec-a2fe0d6b63d3")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Reflection.PluginSystem/Properties/Settings.Designer.cs b/Pilz.Reflection.PluginSystem/Properties/Settings.Designer.cs new file mode 100644 index 0000000..46de10d --- /dev/null +++ b/Pilz.Reflection.PluginSystem/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Reflection.PluginSystem.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Reflection.PluginSystem/My Project/Settings.settings b/Pilz.Reflection.PluginSystem/Properties/Settings.settings similarity index 100% rename from Pilz.Reflection.PluginSystem/My Project/Settings.settings rename to Pilz.Reflection.PluginSystem/Properties/Settings.settings diff --git a/Pilz.Reflection.PluginSystem/Resources.Designer.cs b/Pilz.Reflection.PluginSystem/Resources.Designer.cs new file mode 100644 index 0000000..62f5e60 --- /dev/null +++ b/Pilz.Reflection.PluginSystem/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Reflection.PluginSystem.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Reflection.PluginSystem.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/Resources.resx b/Pilz.Reflection.PluginSystem/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Reflection.PluginSystem/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/FileParser/Aspose3DLoader.cs b/Pilz.Simple3DFileParser/FileParser/Aspose3DLoader.cs new file mode 100644 index 0000000..7de15b7 --- /dev/null +++ b/Pilz.Simple3DFileParser/FileParser/Aspose3DLoader.cs @@ -0,0 +1,273 @@ +using System.Collections.Generic; +using System.Drawing; +using global::System.Globalization; +using global::System.IO; +using global::System.Threading; +using global::Aspose.ThreeD; +using global::Aspose.ThreeD.Entities; +using global::Aspose.ThreeD.Shading; +using global::Aspose.ThreeD.Utilities; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.S3DFileParser.Aspose3DModule +{ + public class Aspose3DLoader + { + private static bool hasActivatedMemoryPatching = false; + + private static void ActivateMemoryPatching() + { + if (!hasActivatedMemoryPatching) + { + LicenseHelper.AsposeModifyInMemory.ActivateMemoryPatching(); + hasActivatedMemoryPatching = true; + } + } + + public static Object3D FromFile(string fileName, bool LoadMaterials, UpAxis UpAxis) + { + ActivateMemoryPatching(); + + // Create new Model + var obj3d = new Object3D(); + + // Create new temporary CultureInfo + var curThread = Thread.CurrentThread; + var curCultInfo = curThread.CurrentCulture; + var newCultInfo = new CultureInfo(curCultInfo.Name); + newCultInfo.NumberFormat.NumberDecimalSeparator = "."; + newCultInfo.NumberFormat.PercentDecimalSeparator = "."; + newCultInfo.NumberFormat.CurrencyDecimalSeparator = "."; + newCultInfo.NumberFormat.NumberGroupSeparator = ","; + newCultInfo.NumberFormat.PercentGroupSeparator = ","; + newCultInfo.NumberFormat.CurrencyGroupSeparator = ","; + curThread.CurrentCulture = newCultInfo; + + // Load Model from file + var scene = new Scene(fileName); + + // Reset Cultur-Info + curThread.CurrentCulture = curCultInfo; + + // Triangulate the Model + PolygonModifier.Triangulate(scene); + + // Create Dictionary for Materials + var dicMaterials = new Dictionary(); + + // Create List of all avaiable Map-States + var MapNames = new[] { Aspose.ThreeD.Shading.Material.MapDiffuse, Aspose.ThreeD.Shading.Material.MapAmbient, Aspose.ThreeD.Shading.Material.MapSpecular, Aspose.ThreeD.Shading.Material.MapEmissive, Aspose.ThreeD.Shading.Material.MapNormal }; + var ColorNames = new[] { "DiffuseColor", "AmbientColor", "SpecularColor", "EmissiveColor" }; + foreach (Node node in scene.RootNode.ChildNodes) + { + + // Add new Materials, if not added + foreach (Aspose.ThreeD.Shading.Material mat in node.Materials) + { + if (!dicMaterials.ContainsKey(mat)) + { + + // Create new Material + var newMat = new Material(); + + // Get TextureBase + TextureBase texBase = null; + byte curmnindex = 0; + while (texBase is null && curmnindex < MapNames.Length) + { + texBase = mat.GetTexture(MapNames[curmnindex]); + curmnindex = (byte)(curmnindex + 1); + } + + if (texBase is object) + { + if (LoadMaterials) + { + // Get Texture Image + string imgFile = Conversions.ToString(texBase.GetPropertyValue("FileName")); + imgFile = imgFile.Replace("/", @"\"); + + // Load and set Image + if (!string.IsNullOrEmpty(imgFile)) + { + var fs = new FileStream(imgFile, FileMode.Open, FileAccess.Read); + newMat.Image = Image.FromStream(fs); + fs.Close(); + } + } + } + + // Get Texture Color + Vector3? texcol = default; + byte curcnindex = 0; + while (texcol is null && curcnindex < ColorNames.Length) + { + texcol = (Vector3?)mat.GetPropertyValue(ColorNames[curcnindex]); + curcnindex = (byte)(curcnindex + 1); + } + + if (texcol is object) + { + newMat.Color = Color.FromArgb((int)texcol?.x, (int)texcol?.y, (int)texcol?.z); + } + + // Add Material to Object3D + obj3d.Materials.Add(mat.Name, newMat); + + // Add Dictionary-Entry + dicMaterials.Add(mat, newMat); + } + } + + // Get Aspose-Mesh + var curMesh = node.GetEntity(); + if (curMesh is object) + { + + // Create new Mesh + var newMesh = new Mesh(); + + // Create Vertices + foreach (Vector4 vert in curMesh.ControlPoints) + { + // Create new Vertex + var newVert = new Vertex(); + + // Set Vertex Data + newVert.X = vert.x; + newVert.Y = vert.y; + newVert.Z = vert.z; + + // Add new Vertex + newMesh.Vertices.Add(newVert); + } + + // Create Normals + VertexElementNormal veNormals = (VertexElementNormal)curMesh.GetElement(VertexElementType.Normal); + if (veNormals is object) + { + foreach (Vector4 n in veNormals.Data) + { + // Create new Normal + var newNormal = new Normal(); + + // Set Normal Data + newNormal.X = (float)n.x; + newNormal.Y = (float)n.y; + newNormal.Z = (float)n.z; + + // Add new Normal + newMesh.Normals.Add(newNormal); + } + } + + // Create Normals + VertexElementUV veUVs = (VertexElementUV)curMesh.GetElement(VertexElementType.UV); + if (veUVs is object) + { + foreach (Vector4 uv in veUVs.Data) + { + // Create new UV + var newUV = new UV(); + + // Set UV Data + newUV.U = (float)uv.x; + newUV.V = (float)uv.y; + + // Add new UV + newMesh.UVs.Add(newUV); + } + } + + // Create Normals + VertexElementVertexColor veVertexColor = (VertexElementVertexColor)curMesh.GetElement(VertexElementType.VertexColor); + if (veVertexColor is object) + { + foreach (Vector4 n in veVertexColor.Data) + { + // Create new Normal + var newVC = new VertexColor(); + + // Set Normal Data + newVC.R = (float)n.x; + newVC.G = (float)n.y; + newVC.B = (float)n.z; + newVC.A = (float)n.w; + + // Add new Normal + newMesh.VertexColors.Add(newVC); + } + } + + // Get Material-Indicies + VertexElementMaterial veMaterials = (VertexElementMaterial)curMesh.GetElement(VertexElementType.Material); + + // Definde Index for VertexElement.Indicies + int veIndex = 0; + + // Build Polygones + for (int iPoly = 0, loopTo = curMesh.Polygons.Count - 1; iPoly <= loopTo; iPoly++) + { + // Get current Polygon + var poly = curMesh.Polygons[iPoly]; + + // Create new Face + var f = new Face(); + + // Set Texture, if avaiable + if (veMaterials is object) + { + f.Material = dicMaterials[node.Materials[veMaterials.Indices[iPoly]]]; + } + else if (node.Material is object) + { + f.Material = dicMaterials[node.Material]; + } + + foreach (int index in poly) + { + // Create new Point + var p = new Point(); + + // Set Vertex + p.Vertex = newMesh.Vertices[index]; + + // Set Normal + if (veNormals is object) + { + p.Normal = newMesh.Normals[veNormals.Indices[veIndex]]; + } + + // Set UV + if (veUVs is object) + { + p.UV = newMesh.UVs[veUVs.Indices[veIndex]]; + } + + // Set Vertex Color + if (veVertexColor is object) + { + p.VertexColor = newMesh.VertexColors[veVertexColor.Indices[veIndex]]; + } + + // Add new Point + f.Points.Add(p); + + // Increment VertexElementIndicies-Index + veIndex += 1; + } + + // Add new Face + newMesh.Faces.Add(f); + } + + // Add new Mesh + obj3d.Meshes.Add(newMesh); + } + } + + // Return the new Object3D + return obj3d; + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/FileParser/Aspose3DLoader.vb b/Pilz.Simple3DFileParser/FileParser/Aspose3DLoader.vb deleted file mode 100644 index 67806f0..0000000 --- a/Pilz.Simple3DFileParser/FileParser/Aspose3DLoader.vb +++ /dev/null @@ -1,250 +0,0 @@ -Imports System.Globalization -Imports System.IO -Imports System.Threading -Imports Aspose.ThreeD -Imports Aspose.ThreeD.Entities -Imports Aspose.ThreeD.Formats -Imports Aspose.ThreeD.Shading -Imports Aspose.ThreeD.Utilities - -Namespace Aspose3DModule - - Public Class Aspose3DLoader - - Private Shared hasActivatedMemoryPatching As Boolean = False - - Private Shared Sub ActivateMemoryPatching() - If Not hasActivatedMemoryPatching Then - LicenseHelper.AsposeModifyInMemory.ActivateMemoryPatching() - hasActivatedMemoryPatching = True - End If - End Sub - - Public Shared Function FromFile(fileName As String, LoadMaterials As Boolean, UpAxis As UpAxis) As Object3D - ActivateMemoryPatching() - - 'Create new Model - Dim obj3d As New Object3D - - 'Create new temporary CultureInfo - Dim curThread As Thread = Thread.CurrentThread - Dim curCultInfo As CultureInfo = curThread.CurrentCulture - Dim newCultInfo As New CultureInfo(curCultInfo.Name) - newCultInfo.NumberFormat.NumberDecimalSeparator = "." - newCultInfo.NumberFormat.PercentDecimalSeparator = "." - newCultInfo.NumberFormat.CurrencyDecimalSeparator = "." - newCultInfo.NumberFormat.NumberGroupSeparator = "," - newCultInfo.NumberFormat.PercentGroupSeparator = "," - newCultInfo.NumberFormat.CurrencyGroupSeparator = "," - curThread.CurrentCulture = newCultInfo - - 'Load Model from file - Dim scene As New Scene(fileName) - - 'Reset Cultur-Info - curThread.CurrentCulture = curCultInfo - - 'Triangulate the Model - PolygonModifier.Triangulate(scene) - - 'Create Dictionary for Materials - Dim dicMaterials As New Dictionary(Of Aspose.ThreeD.Shading.Material, Material) - - 'Create List of all avaiable Map-States - Dim MapNames As String() = {Aspose.ThreeD.Shading.Material.MapDiffuse, Aspose.ThreeD.Shading.Material.MapAmbient, Aspose.ThreeD.Shading.Material.MapSpecular, Aspose.ThreeD.Shading.Material.MapEmissive, Aspose.ThreeD.Shading.Material.MapNormal} - Dim ColorNames As String() = {"DiffuseColor", "AmbientColor", "SpecularColor", "EmissiveColor"} - - For Each node As Node In scene.RootNode.ChildNodes - - 'Add new Materials, if not added - For Each mat As Aspose.ThreeD.Shading.Material In node.Materials - If Not dicMaterials.ContainsKey(mat) Then - - 'Create new Material - Dim newMat As New Material - - 'Get TextureBase - Dim texBase As TextureBase = Nothing - Dim curmnindex As Byte = 0 - Do While texBase Is Nothing AndAlso curmnindex < MapNames.Length - texBase = mat.GetTexture(MapNames(curmnindex)) - curmnindex += 1 - Loop - - If texBase IsNot Nothing Then - If LoadMaterials Then - 'Get Texture Image - Dim imgFile As String = texBase.GetPropertyValue("FileName") - imgFile = imgFile.Replace("/", "\") - - 'Load and set Image - If imgFile <> "" Then - Dim fs As New FileStream(imgFile, FileMode.Open, FileAccess.Read) - newMat.Image = Image.FromStream(fs) - fs.Close() - End If - End If - End If - - 'Get Texture Color - Dim texcol As Vector3? = Nothing - Dim curcnindex As Byte = 0 - Do While texcol Is Nothing AndAlso curcnindex < ColorNames.Length - texcol = mat.GetPropertyValue(ColorNames(curcnindex)) - curcnindex += 1 - Loop - - If texcol IsNot Nothing Then - newMat.Color = Color.FromArgb(texcol?.x, texcol?.y, texcol?.z) - End If - - 'Add Material to Object3D - obj3d.Materials.Add(mat.Name, newMat) - - 'Add Dictionary-Entry - dicMaterials.Add(mat, newMat) - - End If - Next - - 'Get Aspose-Mesh - Dim curMesh As Entities.Mesh = node.GetEntity(Of Entities.Mesh) - - If curMesh IsNot Nothing Then - - 'Create new Mesh - Dim newMesh As New Mesh - - 'Create Vertices - For Each vert As Vector4 In curMesh.ControlPoints - 'Create new Vertex - Dim newVert As New Vertex - - 'Set Vertex Data - newVert.X = vert.x - newVert.Y = vert.y - newVert.Z = vert.z - - 'Add new Vertex - newMesh.Vertices.Add(newVert) - Next - - 'Create Normals - Dim veNormals As VertexElementNormal = curMesh.GetElement(VertexElementType.Normal) - If veNormals IsNot Nothing Then - For Each n As Vector4 In veNormals.Data - 'Create new Normal - Dim newNormal As New Normal - - 'Set Normal Data - newNormal.X = n.x - newNormal.Y = n.y - newNormal.Z = n.z - - 'Add new Normal - newMesh.Normals.Add(newNormal) - Next - End If - - 'Create Normals - Dim veUVs As VertexElementUV = curMesh.GetElement(VertexElementType.UV) - If veUVs IsNot Nothing Then - For Each uv As Vector4 In veUVs.Data - 'Create new UV - Dim newUV As New UV - - 'Set UV Data - newUV.U = uv.x - newUV.V = uv.y - - 'Add new UV - newMesh.UVs.Add(newUV) - Next - End If - - 'Create Normals - Dim veVertexColor As VertexElementVertexColor = curMesh.GetElement(VertexElementType.VertexColor) - If veVertexColor IsNot Nothing Then - For Each n As Vector4 In veVertexColor.Data - 'Create new Normal - Dim newVC As New VertexColor - - 'Set Normal Data - newVC.R = n.x - newVC.G = n.y - newVC.B = n.z - newVC.A = n.w - - 'Add new Normal - newMesh.VertexColors.Add(newVC) - Next - End If - - 'Get Material-Indicies - Dim veMaterials As VertexElementMaterial = curMesh.GetElement(VertexElementType.Material) - - 'Definde Index for VertexElement.Indicies - Dim veIndex As Integer = 0 - - 'Build Polygones - For iPoly = 0 To curMesh.Polygons.Count - 1 - 'Get current Polygon - Dim poly As Integer() = curMesh.Polygons(iPoly) - - 'Create new Face - Dim f As New Face - - 'Set Texture, if avaiable - If veMaterials IsNot Nothing Then - f.Material = dicMaterials(node.Materials(veMaterials.Indices(iPoly))) - ElseIf node.Material IsNot Nothing Then - f.Material = dicMaterials(node.Material) - End If - - For Each index As Integer In poly - 'Create new Point - Dim p As New Point - - 'Set Vertex - p.Vertex = newMesh.Vertices(index) - - 'Set Normal - If veNormals IsNot Nothing Then - p.Normal = newMesh.Normals(veNormals.Indices(veIndex)) - End If - - 'Set UV - If veUVs IsNot Nothing Then - p.UV = newMesh.UVs(veUVs.Indices(veIndex)) - End If - - 'Set Vertex Color - If veVertexColor IsNot Nothing Then - p.VertexColor = newMesh.VertexColors(veVertexColor.Indices(veIndex)) - End If - - 'Add new Point - f.Points.Add(p) - - 'Increment VertexElementIndicies-Index - veIndex += 1 - Next - - 'Add new Face - newMesh.Faces.Add(f) - Next - - 'Add new Mesh - obj3d.Meshes.Add(newMesh) - - End If - - Next - - 'Return the new Object3D - Return obj3d - End Function - - End Class - -End Namespace diff --git a/Pilz.Simple3DFileParser/FileParser/AssimpLoader.cs b/Pilz.Simple3DFileParser/FileParser/AssimpLoader.cs new file mode 100644 index 0000000..e4fd709 --- /dev/null +++ b/Pilz.Simple3DFileParser/FileParser/AssimpLoader.cs @@ -0,0 +1,540 @@ +using System.Collections.Generic; +using System.Drawing; +using global::System.IO; +using System.Linq; +using global::Assimp; +using global::Assimp.Unmanaged; + +namespace Pilz.S3DFileParser.AssimpModule +{ + internal class ConversionContext + { + public Scene DaeMdl { get; set; } + public UpAxis UpAxis { get; set; } + public Mesh NewMesh { get; set; } = new Mesh(); + public Object3D NewObj { get; set; } = new Object3D(); + public Dictionary ChannelIndicies { get; set; } = new Dictionary(); + + public ConversionContext(Scene daeMdlP, UpAxis upAxis) + { + DaeMdl = daeMdlP; + UpAxis = upAxis; + NewObj.Meshes.Add(NewMesh); + } + } + + internal class ParsingContext + { + public ConversionContext ConversionContext { get; private set; } + public Dictionary DicVertices { get; set; } = new Dictionary(); + public Dictionary DicNormals { get; set; } = new Dictionary(); + public Dictionary DicUVs { get; set; } = new Dictionary(); + public Dictionary DicVertexColors { get; set; } = new Dictionary(); + + public ParsingContext(ConversionContext ctx) + { + ConversionContext = ctx; + } + } + + public class AssimpLoader + { + public static event LoadingAssimpLibsEventHandler LoadingAssimpLibs; + + public delegate void LoadingAssimpLibsEventHandler(); + + public static event LoadedAssimpLibsEventHandler LoadedAssimpLibs; + + public delegate void LoadedAssimpLibsEventHandler(); + + public static string PathToAssimpLib32 { get; set; } = "Assimp32.dll"; + public static string PathToAssimpLib64 { get; set; } = "Assimp64.dll"; + + internal static void LoadAssimpLibs() + { + if (!AssimpLibrary.Instance.IsLibraryLoaded) + { + LoadingAssimpLibs?.Invoke(); + AssimpLibrary.Instance.LoadLibrary(PathToAssimpLib32, PathToAssimpLib64); + LoadedAssimpLibs?.Invoke(); + } + } + + private static void ComputeNewObj(ConversionContext cc) + { + var identity = Matrix4x4.Identity; + ComputeNode(cc.DaeMdl.RootNode, identity, new ParsingContext(cc)); + } + + private static void ComputeNode(Node node, Matrix4x4 trafo, ParsingContext pc) + { + var newObj = pc.ConversionContext.NewObj; + var newMesh = pc.ConversionContext.NewMesh; + var daeMdl = pc.ConversionContext.DaeMdl; + var channelIndicies = pc.ConversionContext.ChannelIndicies; + var UpAxis = pc.ConversionContext.UpAxis; + var dicVertices = pc.DicVertices; + var dicNormals = pc.DicNormals; + var dicUVs = pc.DicUVs; + var dicVertexColors = pc.DicVertexColors; + trafo = trafo * node.Transform; + if (node.HasMeshes) + { + foreach (var meshIndex in node.MeshIndices) + { + var m = daeMdl.Meshes[meshIndex]; + Material curMat; + if (m.MaterialIndex > -1 && newObj.Materials.Count > m.MaterialIndex) + { + curMat = newObj.Materials.ElementAt(m.MaterialIndex).Value; + } + else + { + curMat = null; + } + + foreach (Vector3D untransformedN in m.Normals) + { + var n = trafo * untransformedN; + if (!dicNormals.ContainsKey(n)) + { + var newNormal = new Normal(); + switch (UpAxis) + { + case UpAxis.Y: + { + newNormal.X = n.X; + newNormal.Y = n.Y; + newNormal.Z = n.Z; + break; + } + + case UpAxis.Z: + { + newNormal.X = n.Y; + newNormal.Y = n.Z; + newNormal.Z = n.X; + break; + } + } + + newMesh.Normals.Add(newNormal); + dicNormals.Add(n, newNormal); + } + } + + foreach (Vector3D untranformedV in m.Vertices) + { + var v = trafo * untranformedV; + if (!dicVertices.ContainsKey(v)) + { + var newVert = new Vertex(); + switch (UpAxis) + { + case UpAxis.Y: + { + newVert.X = v.X; + newVert.Y = v.Y; + newVert.Z = v.Z; + break; + } + + case UpAxis.Z: + { + newVert.X = v.Y; + newVert.Y = v.Z; + newVert.Z = v.X; + break; + } + } + + newMesh.Vertices.Add(newVert); + dicVertices.Add(v, newVert); + } + } + + foreach (List uvList in m.TextureCoordinateChannels) + { + foreach (Vector3D uv in uvList) + { + if (!dicUVs.ContainsKey(uv)) + { + var newUV = new UV(); + newUV.U = uv.X; + newUV.V = uv.Y; + newMesh.UVs.Add(newUV); + dicUVs.Add(uv, newUV); + } + } + } + + foreach (List vcList in m.VertexColorChannels) + { + foreach (Color4D vc in vcList) + { + if (!dicVertexColors.ContainsKey(vc)) + { + var newVC = new VertexColor(); + newVC.R = vc.R; + newVC.G = vc.G; + newVC.B = vc.B; + newVC.A = vc.A; + newMesh.VertexColors.Add(newVC); + dicVertexColors.Add(vc, newVC); + } + } + } + + foreach (Assimp.Face f in m.Faces) + { + if (f.HasIndices) + { + var newFace = new Face() { Material = curMat }; + foreach (int index in f.Indices) + { + if (index > -1) + { + var newPoint = new Point(); + if (m.HasVertices) + { + var v = trafo * m.Vertices[index]; + newPoint.Vertex = dicVertices[v]; + } + + if (m.HasNormals) + { + var n = trafo * m.Normals[index]; + newPoint.Normal = dicNormals[n]; + } + + if (curMat is object && channelIndicies.ContainsKey(curMat)) + { + int tkey = channelIndicies[curMat]; + if (m.HasTextureCoords(tkey)) + { + newPoint.UV = dicUVs[m.TextureCoordinateChannels[tkey][index]]; + } + + if (m.HasVertexColors(tkey)) + { + newPoint.VertexColor = dicVertexColors[m.VertexColorChannels[tkey][index]]; + } + } + + newFace.Points.Add(newPoint); + } + } + + if (newFace.Points.Count == 3) + { + newMesh.Faces.Add(newFace); + } + } + } + } + } + + foreach (var n in node.Children) + ComputeNode(n, trafo, pc); + } + + public static Object3D FromFile(string fileName, bool LoadMaterials, UpAxis UpAxis) + { + var LoadedImages = new Dictionary(); + var ac = new AssimpContext(); + var cc = new ConversionContext(ac.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessSteps.Triangulate), UpAxis); + var newObj = cc.NewObj; + var daeMdl = cc.DaeMdl; + var channelIndicies = cc.ChannelIndicies; + foreach (EmbeddedTexture et in daeMdl.Textures) + { + if (et.HasCompressedData) + { + var newMat = new Material(); + var ms = new MemoryStream(et.CompressedData); + newMat.Image = Image.FromStream(ms); + ms.Close(); + newObj.Materials.Add("tex_" + daeMdl.Textures.IndexOf(et), newMat); + } + } + + foreach (Assimp.Material mat in daeMdl.Materials) + { + var newMat = new Material(); + TextureSlot? texSlot = default; + Color4D? col4d = default; + newMat.Opacity = mat.Opacity; + switch (true) + { + case object _ when mat.HasTextureNormal: + { + texSlot = mat.TextureNormal; + break; + } + + case object _ when mat.HasTextureDiffuse: + { + texSlot = mat.TextureDiffuse; + break; + } + + case object _ when mat.HasTextureAmbient: + { + texSlot = mat.TextureAmbient; + break; + } + + case object _ when mat.HasTextureSpecular: + { + texSlot = mat.TextureSpecular; + break; + } + } + + switch (true) + { + case object _ when mat.HasColorDiffuse: + { + col4d = mat.ColorDiffuse; + break; + } + + case object _ when mat.HasColorAmbient: + { + col4d = mat.ColorAmbient; + break; + } + + case object _ when mat.HasColorSpecular: + { + col4d = mat.ColorSpecular; + break; + } + } + + if (texSlot is object) + { + string filePath = texSlot.Value.FilePath; + if (LoadMaterials) + { + if (!string.IsNullOrEmpty(filePath)) + { + string combiPath = Path.Combine(Path.GetDirectoryName(fileName), filePath); + if (File.Exists(combiPath)) + { + newMat.Image = LoadImage(combiPath, LoadedImages); + } + else if (File.Exists(filePath)) + { + newMat.Image = LoadImage(filePath, LoadedImages); + } + } + else if (texSlot.Value.TextureIndex > -1 && daeMdl.Textures.Count > texSlot.Value.TextureIndex) + { + var et = daeMdl.Textures[texSlot.Value.TextureIndex]; + if (et.HasCompressedData) + { + var ms = new MemoryStream(et.CompressedData); + newMat.Image = Image.FromStream(ms); + ms.Close(); + } + } + } + + channelIndicies.Add(newMat, texSlot.Value.UVIndex); + } + + if (col4d is object) + { + newMat.Color = Color.FromArgb((int)(col4d.Value.R * 255f), (int)(col4d.Value.G * 255f), (int)(col4d.Value.B * 255f)); + } + + newObj.Materials.Add(mat.Name, newMat); + } + + ComputeNewObj(cc); + return newObj; + } + + public static void ToFile(string fileName, Object3D obj) + { + var mdl = new Scene(); + var dicMatIndex = new Dictionary(); + string texDir = ""; + if (obj.Materials.Count > 0) + { + texDir = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)); + if (!Directory.Exists(texDir)) + { + Directory.CreateDirectory(texDir); + } + } + + foreach (KeyValuePair kvp in obj.Materials) + { + var mat = new Assimp.Material(); + mat.Name = !string.IsNullOrEmpty(kvp.Key) ? kvp.Key : "_" + mdl.Materials.Count; + mat.Opacity = mat.Opacity; + var texslot = new TextureSlot(); + texslot.TextureIndex = mdl.Textures.Count; + texslot.TextureType = TextureType.Diffuse; + texslot.UVIndex = 0; + var ms = new MemoryStream(); + kvp.Value.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); + // Dim tex As New EmbeddedTexture("png", ms.GetBuffer) + ms.Close(); + if (kvp.Value.Image is object) + { + texslot.FilePath = Path.Combine(texDir, mat.Name + ".png"); + File.WriteAllBytes(texslot.FilePath, ms.GetBuffer()); + } + + // mdl.Textures.Add(tex) + mat.AddMaterialTexture(ref texslot); + mdl.Materials.Add(mat); + if (kvp.Value.Color is object) + { + { + var withBlock = kvp.Value.Color.Value; + mat.ColorDiffuse = new Color4D((float)(withBlock.R / 255d), (float)(withBlock.G / 255d), (float)(withBlock.B / 255d), 1f); + } + } + + dicMatIndex.Add(kvp.Value, mdl.Materials.Count - 1); + } + + var dicTexMesh = new Dictionary(); + var dicMeshDicVertIndex = new Dictionary>(); + var dicCounter = new Dictionary(); + foreach (Mesh mesh in obj.Meshes) + { + foreach (Face f in mesh.Faces) + { + Assimp.Mesh m; + if (dicTexMesh.ContainsKey(f.Material)) + { + m = dicTexMesh[f.Material]; + } + else + { + m = new Assimp.Mesh("Mesh_" + (mdl.MeshCount + 1)); + m.PrimitiveType = PrimitiveType.Triangle; + if (dicMatIndex.ContainsKey(f.Material)) + { + m.MaterialIndex = dicMatIndex[f.Material]; + } + + mdl.Meshes.Add(m); + dicTexMesh.Add(f.Material, m); + dicMeshDicVertIndex.Add(m, new Dictionary()); + dicCounter.Add(m, 0); + } + + var newFace = new Assimp.Face(); + foreach (Point p in f.Points) + { + newFace.Indices.Add(dicCounter[m]); + if (p.Vertex is object) + { + var vert = new Vector3D(); + vert.X = (float)p.Vertex.X; + vert.Y = (float)p.Vertex.Y; + vert.Z = (float)p.Vertex.Z; + m.Vertices.Add(vert); + } + else + { + m.Vertices.Add(new Vector3D(0f, 0f, 0f)); + } + + if (p.Normal is object) + { + var norm = new Vector3D(); + norm.X = p.Normal.X; + norm.Y = p.Normal.Y; + norm.Z = p.Normal.Z; + m.Normals.Add(norm); + } + else + { + m.Normals.Add(new Vector3D(0f, 0f, 0f)); + } + + // If p.UV IsNot Nothing Then + // Dim uv As New Vector3D + // uv.X = p.UV.U + // uv.Y = p.UV.V + // m.TextureCoordinateChannels(0).Add(uv) + // Else + // m.TextureCoordinateChannels(0).Add(New Vector3D(0, 0, 0)) + // End If + + // If p.VertexColor IsNot Nothing Then + // Dim vc As New Color4D + // vc.R = p.VertexColor.R + // vc.G = p.VertexColor.G + // vc.B = p.VertexColor.B + // vc.A = p.VertexColor.A + // m.VertexColorChannels(0).Add(vc) + // Else + // m.VertexColorChannels(0).Add(New Color4D(0, 0, 0, 0)) + // End If + + dicCounter[m] += 1; + } + + m.Faces.Add(newFace); + } + } + + // Add Root Node + mdl.RootNode = new Node(Path.GetFileName(fileName)); + + // Add Mesh Indicies + for (int i = 0, loopTo = mdl.MeshCount - 1; i <= loopTo; i++) + mdl.RootNode.MeshIndices.Add(i); + var ac = new AssimpContext(); + string formatID = ""; + string myExt = Path.GetExtension(fileName).ToLower().Substring(1); + foreach (ExportFormatDescription efd in ac.GetSupportedExportFormats()) + { + if ((myExt ?? "") == (efd.FileExtension ?? "")) + { + formatID = efd.FormatId; + break; + } + } + + ac.ExportFile(mdl, fileName, formatID); + } + + private static Image LoadImage(string fileName, Dictionary loadedImages) + { + if (File.Exists(fileName)) + { + if (loadedImages.ContainsKey(fileName)) + { + return loadedImages[fileName]; + } + else + { + var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); + var img = Image.FromStream(fs); + fs.Close(); + foreach (var kvp in loadedImages) + { + if (((Bitmap)img).IsTheSameAs((Bitmap)kvp.Value)) + { + return kvp.Value; + } + } + + loadedImages.Add(fileName, img); + return img; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/FileParser/AssimpLoader.vb b/Pilz.Simple3DFileParser/FileParser/AssimpLoader.vb deleted file mode 100644 index 2571ba2..0000000 --- a/Pilz.Simple3DFileParser/FileParser/AssimpLoader.vb +++ /dev/null @@ -1,453 +0,0 @@ -Imports System.IO -Imports Assimp -Imports Assimp.Unmanaged - -Namespace AssimpModule - - Friend Class ConversionContext - - Public Property DaeMdl As Scene - Public Property UpAxis As UpAxis - Public Property NewMesh As New Mesh - Public Property NewObj As New Object3D - Public Property ChannelIndicies As New Dictionary(Of Material, Integer) - - Public Sub New(daeMdlP As Scene, upAxis As UpAxis) - DaeMdl = daeMdlP - Me.UpAxis = upAxis - - NewObj.Meshes.Add(NewMesh) - End Sub - - End Class - - Friend Class ParsingContext - - Public ReadOnly Property ConversionContext As ConversionContext - Public Property DicVertices As New Dictionary(Of Vector3D, Vertex) - Public Property DicNormals As New Dictionary(Of Vector3D, Normal) - Public Property DicUVs As New Dictionary(Of Vector3D, UV) - Public Property DicVertexColors As New Dictionary(Of Color4D, VertexColor) - - Public Sub New(ctx As ConversionContext) - ConversionContext = ctx - End Sub - - End Class - - Public Class AssimpLoader - - Public Shared Event LoadingAssimpLibs() - Public Shared Event LoadedAssimpLibs() - - Public Shared Property PathToAssimpLib32 As String = "Assimp32.dll" - Public Shared Property PathToAssimpLib64 As String = "Assimp64.dll" - - Friend Shared Sub LoadAssimpLibs() - If Not AssimpLibrary.Instance.IsLibraryLoaded Then - RaiseEvent LoadingAssimpLibs() - AssimpLibrary.Instance.LoadLibrary(PathToAssimpLib32, PathToAssimpLib64) - RaiseEvent LoadedAssimpLibs() - End If - End Sub - - Private Shared Sub ComputeNewObj(cc As ConversionContext) - Dim identity As Matrix4x4 = Matrix4x4.Identity - ComputeNode(cc.DaeMdl.RootNode, identity, New ParsingContext(cc)) - End Sub - - Private Shared Sub ComputeNode(node As Node, trafo As Matrix4x4, pc As ParsingContext) - Dim newObj = pc.ConversionContext.NewObj - Dim newMesh = pc.ConversionContext.NewMesh - Dim daeMdl = pc.ConversionContext.DaeMdl - Dim channelIndicies = pc.ConversionContext.ChannelIndicies - Dim UpAxis = pc.ConversionContext.UpAxis - Dim dicVertices = pc.DicVertices - Dim dicNormals = pc.DicNormals - Dim dicUVs = pc.DicUVs - Dim dicVertexColors = pc.DicVertexColors - - trafo = trafo * node.Transform - - If node.HasMeshes Then - For Each meshIndex In node.MeshIndices - Dim m As Assimp.Mesh = daeMdl.Meshes(meshIndex) - - Dim curMat As Material - If m.MaterialIndex > -1 AndAlso newObj.Materials.Count > m.MaterialIndex Then - curMat = newObj.Materials.ElementAt(m.MaterialIndex).Value - Else - curMat = Nothing - End If - - For Each untransformedN As Vector3D In m.Normals - Dim n = trafo * untransformedN - If Not dicNormals.ContainsKey(n) Then - Dim newNormal As New Normal - - Select Case UpAxis - Case UpAxis.Y - newNormal.X = n.X - newNormal.Y = n.Y - newNormal.Z = n.Z - Case UpAxis.Z - newNormal.X = n.Y - newNormal.Y = n.Z - newNormal.Z = n.X - End Select - - newMesh.Normals.Add(newNormal) - dicNormals.Add(n, newNormal) - End If - Next - - For Each untranformedV As Vector3D In m.Vertices - Dim v = trafo * untranformedV - If Not dicVertices.ContainsKey(v) Then - Dim newVert As New Vertex - - Select Case UpAxis - Case UpAxis.Y - newVert.X = v.X - newVert.Y = v.Y - newVert.Z = v.Z - Case UpAxis.Z - newVert.X = v.Y - newVert.Y = v.Z - newVert.Z = v.X - End Select - - newMesh.Vertices.Add(newVert) - dicVertices.Add(v, newVert) - End If - Next - - For Each uvList As List(Of Vector3D) In m.TextureCoordinateChannels - For Each uv As Vector3D In uvList - If Not dicUVs.ContainsKey(uv) Then - Dim newUV As New UV - - newUV.U = uv.X - newUV.V = uv.Y - - newMesh.UVs.Add(newUV) - dicUVs.Add(uv, newUV) - End If - Next - Next - - For Each vcList As List(Of Color4D) In m.VertexColorChannels - For Each vc As Color4D In vcList - If Not dicVertexColors.ContainsKey(vc) Then - Dim newVC As New VertexColor - - newVC.R = vc.R - newVC.G = vc.G - newVC.B = vc.B - newVC.A = vc.A - - newMesh.VertexColors.Add(newVC) - dicVertexColors.Add(vc, newVC) - End If - Next - Next - - For Each f As Assimp.Face In m.Faces - If f.HasIndices Then - Dim newFace As New Face With {.Material = curMat} - - For Each index As Integer In f.Indices - If index > -1 Then - Dim newPoint As New Point - - If m.HasVertices Then - Dim v = trafo * m.Vertices(index) - newPoint.Vertex = dicVertices(v) - End If - - If m.HasNormals Then - Dim n = trafo * m.Normals(index) - newPoint.Normal = dicNormals(n) - End If - - If curMat IsNot Nothing AndAlso channelIndicies.ContainsKey(curMat) Then - Dim tkey As Integer = channelIndicies(curMat) - - If m.HasTextureCoords(tkey) Then - newPoint.UV = dicUVs(m.TextureCoordinateChannels(tkey)(index)) - End If - - If m.HasVertexColors(tkey) Then - newPoint.VertexColor = dicVertexColors(m.VertexColorChannels(tkey)(index)) - End If - End If - - newFace.Points.Add(newPoint) - End If - Next - - If newFace.Points.Count = 3 Then - newMesh.Faces.Add(newFace) - End If - End If - Next - Next - End If - - For Each n In node.Children - ComputeNode(n, trafo, pc) - Next - End Sub - - Public Shared Function FromFile(fileName As String, LoadMaterials As Boolean, UpAxis As UpAxis) As Object3D - Dim LoadedImages As New Dictionary(Of String, Image) - Dim ac As New AssimpContext - - Dim cc As New ConversionContext(ac.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality Or PostProcessSteps.Triangulate), UpAxis) - - Dim newObj = cc.NewObj - Dim daeMdl = cc.DaeMdl - Dim channelIndicies = cc.ChannelIndicies - - For Each et As EmbeddedTexture In daeMdl.Textures - If et.HasCompressedData Then - Dim newMat As New Material - - Dim ms As New MemoryStream(et.CompressedData) - newMat.Image = Image.FromStream(ms) - ms.Close() - - newObj.Materials.Add("tex_" & daeMdl.Textures.IndexOf(et), newMat) - End If - Next - - For Each mat As Assimp.Material In daeMdl.Materials - Dim newMat As New Material - Dim texSlot As TextureSlot? = Nothing - Dim col4d As Color4D? = Nothing - - newMat.Opacity = mat.Opacity - - Select Case True - Case mat.HasTextureNormal - texSlot = mat.TextureNormal - Case mat.HasTextureDiffuse - texSlot = mat.TextureDiffuse - Case mat.HasTextureAmbient - texSlot = mat.TextureAmbient - Case mat.HasTextureSpecular - texSlot = mat.TextureSpecular - End Select - - Select Case True - Case mat.HasColorDiffuse - col4d = mat.ColorDiffuse - Case mat.HasColorAmbient - col4d = mat.ColorAmbient - Case mat.HasColorSpecular - col4d = mat.ColorSpecular - End Select - - If texSlot IsNot Nothing Then - Dim filePath As String = texSlot.Value.FilePath - - If LoadMaterials Then - If filePath <> "" Then - Dim combiPath As String = Path.Combine(Path.GetDirectoryName(fileName), filePath) - If File.Exists(combiPath) Then - newMat.Image = LoadImage(combiPath, LoadedImages) - ElseIf File.Exists(filePath) Then - newMat.Image = LoadImage(filePath, LoadedImages) - End If - ElseIf texSlot.Value.TextureIndex > -1 AndAlso daeMdl.Textures.Count > texSlot.Value.TextureIndex Then - Dim et As EmbeddedTexture = daeMdl.Textures(texSlot.Value.TextureIndex) - If et.HasCompressedData Then - Dim ms As New MemoryStream(et.CompressedData) - newMat.Image = Image.FromStream(ms) - ms.Close() - End If - End If - End If - - channelIndicies.Add(newMat, texSlot.Value.UVIndex) - End If - - If col4d IsNot Nothing Then - newMat.Color = Color.FromArgb(col4d.Value.R * 255, col4d.Value.G * 255, col4d.Value.B * 255) - End If - - newObj.Materials.Add(mat.Name, newMat) - Next - - ComputeNewObj(cc) - - Return newObj - End Function - - Public Shared Sub ToFile(fileName As String, obj As Object3D) - Dim mdl As New Scene - Dim dicMatIndex As New Dictionary(Of Material, Integer) - - Dim texDir As String = "" - If obj.Materials.Count > 0 Then - texDir = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)) - If Not Directory.Exists(texDir) Then - Directory.CreateDirectory(texDir) - End If - End If - - For Each kvp As KeyValuePair(Of String, Material) In obj.Materials - Dim mat As New Assimp.Material - - mat.Name = If(kvp.Key <> "", kvp.Key, "_" & mdl.Materials.Count) - mat.Opacity = mat.Opacity - - Dim texslot As New TextureSlot - texslot.TextureIndex = mdl.Textures.Count - texslot.TextureType = TextureType.Diffuse - texslot.UVIndex = 0 - - Dim ms As New MemoryStream - kvp.Value.Image.Save(ms, Imaging.ImageFormat.Png) - 'Dim tex As New EmbeddedTexture("png", ms.GetBuffer) - ms.Close() - - If kvp.Value.Image IsNot Nothing Then - texslot.FilePath = Path.Combine(texDir, mat.Name & ".png") - File.WriteAllBytes(texslot.FilePath, ms.GetBuffer) - End If - - 'mdl.Textures.Add(tex) - mat.AddMaterialTexture(texslot) - mdl.Materials.Add(mat) - - If kvp.Value.Color IsNot Nothing Then - With kvp.Value.Color.Value - mat.ColorDiffuse = New Color4D(.R / 255, .G / 255, .B / 255, 1) - End With - End If - - dicMatIndex.Add(kvp.Value, mdl.Materials.Count - 1) - Next - - Dim dicTexMesh As New Dictionary(Of Material, Assimp.Mesh) - Dim dicMeshDicVertIndex As New Dictionary(Of Assimp.Mesh, Dictionary(Of Vertex, Integer)) - Dim dicCounter As New Dictionary(Of Assimp.Mesh, Integer) - - For Each mesh As Mesh In obj.Meshes - For Each f As Face In mesh.Faces - Dim m As Assimp.Mesh - - If dicTexMesh.ContainsKey(f.Material) Then - m = dicTexMesh(f.Material) - Else - m = New Assimp.Mesh("Mesh_" & mdl.MeshCount + 1) - m.PrimitiveType = PrimitiveType.Triangle - If dicMatIndex.ContainsKey(f.Material) Then - m.MaterialIndex = dicMatIndex(f.Material) - End If - mdl.Meshes.Add(m) - dicTexMesh.Add(f.Material, m) - dicMeshDicVertIndex.Add(m, New Dictionary(Of Vertex, Integer)) - dicCounter.Add(m, 0) - End If - - Dim newFace As New Assimp.Face - - For Each p As Point In f.Points - newFace.Indices.Add(dicCounter(m)) - - If p.Vertex IsNot Nothing Then - Dim vert As New Vector3D - vert.X = p.Vertex.X - vert.Y = p.Vertex.Y - vert.Z = p.Vertex.Z - m.Vertices.Add(vert) - Else - m.Vertices.Add(New Vector3D(0, 0, 0)) - End If - - If p.Normal IsNot Nothing Then - Dim norm As New Vector3D - norm.X = p.Normal.X - norm.Y = p.Normal.Y - norm.Z = p.Normal.Z - m.Normals.Add(norm) - Else - m.Normals.Add(New Vector3D(0, 0, 0)) - End If - - 'If p.UV IsNot Nothing Then - ' Dim uv As New Vector3D - ' uv.X = p.UV.U - ' uv.Y = p.UV.V - ' m.TextureCoordinateChannels(0).Add(uv) - 'Else - ' m.TextureCoordinateChannels(0).Add(New Vector3D(0, 0, 0)) - 'End If - - 'If p.VertexColor IsNot Nothing Then - ' Dim vc As New Color4D - ' vc.R = p.VertexColor.R - ' vc.G = p.VertexColor.G - ' vc.B = p.VertexColor.B - ' vc.A = p.VertexColor.A - ' m.VertexColorChannels(0).Add(vc) - 'Else - ' m.VertexColorChannels(0).Add(New Color4D(0, 0, 0, 0)) - 'End If - - dicCounter(m) += 1 - Next - - m.Faces.Add(newFace) - Next - Next - - 'Add Root Node - mdl.RootNode = New Node(Path.GetFileName(fileName)) - - 'Add Mesh Indicies - For i As Integer = 0 To mdl.MeshCount - 1 - mdl.RootNode.MeshIndices.Add(i) - Next - - Dim ac As New AssimpContext - - Dim formatID As String = "" - Dim myExt As String = Path.GetExtension(fileName).ToLower.Substring(1) - For Each efd As ExportFormatDescription In ac.GetSupportedExportFormats - If myExt = efd.FileExtension Then - formatID = efd.FormatId - Exit For - End If - Next - - ac.ExportFile(mdl, fileName, formatID) - End Sub - - Private Shared Function LoadImage(fileName As String, loadedImages As Dictionary(Of String, Image)) As Image - If File.Exists(fileName) Then - If loadedImages.ContainsKey(fileName) Then - Return loadedImages(fileName) - Else - Dim fs As New FileStream(fileName, FileMode.Open, FileAccess.Read) - Dim img As Image = Image.FromStream(fs) - fs.Close() - - For Each kvp In loadedImages - If IsTheSameAs(img, kvp.Value) Then - Return kvp.Value - End If - Next - - loadedImages.Add(fileName, img) - Return img - End If - End If - Return Nothing - End Function - - End Class - -End Namespace diff --git a/Pilz.Simple3DFileParser/FileParser/Obj.cs b/Pilz.Simple3DFileParser/FileParser/Obj.cs new file mode 100644 index 0000000..6d6171a --- /dev/null +++ b/Pilz.Simple3DFileParser/FileParser/Obj.cs @@ -0,0 +1,476 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using global::System.Globalization; +using global::System.IO; +using System.Linq; +using global::System.Threading; +using Microsoft.VisualBasic.CompilerServices; +using global::Pilz.S3DFileParser.Exceptions; + +namespace Pilz.S3DFileParser.ObjModule +{ + public class ObjFile + { + public static Object3D FromFile(string FileName, bool LoadMaterials, UpAxis UpAxis) + { + var curThread = Thread.CurrentThread; + var curCultInfo = curThread.CurrentCulture; + var newCultInfo = new CultureInfo(curCultInfo.Name); + newCultInfo.NumberFormat.NumberDecimalSeparator = "."; + newCultInfo.NumberFormat.PercentDecimalSeparator = "."; + newCultInfo.NumberFormat.CurrencyDecimalSeparator = "."; + newCultInfo.NumberFormat.NumberGroupSeparator = ","; + newCultInfo.NumberFormat.PercentGroupSeparator = ","; + newCultInfo.NumberFormat.CurrencyGroupSeparator = ","; + curThread.CurrentCulture = newCultInfo; + var newObj = new Object3D(); + var newMesh = new Mesh(); + string curObjPath = Path.GetDirectoryName(FileName); + var mtllibs = new Dictionary(); + MaterialLib curMaterialLib = null; + Material curMaterial = null; + var srObj = new StreamReader(FileName, System.Text.Encoding.ASCII); + string line = ""; + while (!srObj.EndOfStream) + { + line = srObj.ReadLine().Trim(); + if (!string.IsNullOrEmpty(line)) + { + switch (true) + { + case object _ when line.StartsWith("mtllib "): + { + string name = line.Substring(7); + if (!mtllibs.ContainsKey(name)) + { + string mtlfile = Path.Combine(curObjPath, name); + if (!File.Exists(mtlfile)) + throw new MaterialException("Material Library not found!"); + var newmtl = new MaterialLib(); + newmtl.FromFile(mtlfile, LoadMaterials); + mtllibs.Add(name, newmtl); + curMaterialLib = newmtl; + foreach (KeyValuePair kvp in curMaterialLib.Materials) + { + if (!newObj.Materials.ContainsKey(kvp.Key)) + newObj.Materials.Add(kvp.Key, kvp.Value); + } + } + else + { + curMaterialLib = mtllibs[name]; + } + + break; + } + + case object _ when line.StartsWith("usemtl "): + { + curMaterial = curMaterialLib.Materials[line.Substring(7)]; + break; + } + + case object _ when line.StartsWith("v "): + { + if (line.Contains("nan")) + line = line.Replace("nan", "0"); + var splitXYZ = line.Substring(2).Split(' '); + double tX = Convert.ToDouble(splitXYZ[0]); + double tY = Convert.ToDouble(splitXYZ[1]); + double tZ = Convert.ToDouble(splitXYZ[2]); + var v = new Vertex(); + switch (UpAxis) + { + case UpAxis.Y: + { + v.X = tX; + v.Y = tY; + v.Z = tZ; + break; + } + + case UpAxis.Z: + { + v.X = tY; + v.Y = tZ; + v.Z = tX; + break; + } + } + + newMesh.Vertices.Add(v); + break; + } + + case object _ when line.StartsWith("vt "): + { + var uvstr = line.Substring(3).Split(' '); + var uv = new UV() + { + U = Convert.ToSingle(uvstr[0]), + V = Convert.ToSingle(uvstr[1]) + }; + newMesh.UVs.Add(uv); + break; + } + + case object _ when line.StartsWith("vn "): + { + var splitXYZ = line.Substring(3).Split(' '); + float tX = Convert.ToSingle(splitXYZ[0]); + float tY = Convert.ToSingle(splitXYZ[1]); + float tZ = Convert.ToSingle(splitXYZ[2]); + var n = new Normal(); + switch (UpAxis) + { + case UpAxis.Y: + { + n.X = tX; + n.Y = tY; + n.Z = tZ; + break; + } + + case UpAxis.Z: + { + n.X = tZ; + n.Y = tY; + n.Z = tX; + break; + } + } + + newMesh.Normals.Add(n); + break; + } + + case object _ when line.StartsWith("vc "): + { + var splitRGB = line.Substring(3).Split(' '); + float tX = Convert.ToSingle(splitRGB[0]); + float tY = Convert.ToSingle(splitRGB[1]); + float tZ = Convert.ToSingle(splitRGB[2]); + var vc = new VertexColor(); + switch (UpAxis) + { + case UpAxis.Y: + { + vc.R = tX; + vc.G = tY; + vc.B = tZ; + break; + } + + case UpAxis.Z: + { + vc.R = tY; + vc.G = tZ; + vc.B = tX; + break; + } + } + + newMesh.VertexColors.Add(vc); + break; + } + + case object _ when line.StartsWith("f "): + { + var tri = new Face() { Material = curMaterial }; + foreach (string xyz1 in line.Substring(2).Split(' ')) + { + var xyz = xyz1.Trim(); + if (string.IsNullOrEmpty(xyz)) + continue; + string[] splitsub = null; + var p = new Point(); + switch (true) + { + case object _ when xyz.Contains("/"): + { + splitsub = xyz.Split('/'); + break; + } + + case object _ when xyz.Contains(@"\"): + { + splitsub = xyz.Split('\\'); + break; + } + + default: + { + splitsub = new string[] { 0.ToString(), 0.ToString(), 0.ToString() }; + break; + } + } + + string v1 = splitsub[0]; + string v2 = splitsub[1]; + string v3 = splitsub[2]; + if (!string.IsNullOrEmpty(v1)) + { + p.Vertex = newMesh.Vertices[Convert.ToInt32(v1) - 1]; + } + + if (!string.IsNullOrEmpty(v2)) + { + p.UV = newMesh.UVs[Convert.ToInt32(v2) - 1]; + } + else + { + var newUV = new UV() { U = 0f, V = 0f }; + p.UV = newUV; + newMesh.UVs.Add(newUV); + } + + if (!string.IsNullOrEmpty(v3)) + { + p.Normal = newMesh.Normals[Convert.ToInt32(v3) - 1]; + } + + if (splitsub.Count() > 3) + { + string v4 = splitsub[3]; + if (!string.IsNullOrEmpty(v4)) + p.VertexColor = newMesh.VertexColors[Convert.ToInt32(v4) - 1]; + } + + tri.Points.Add(p); + } + + newMesh.Faces.Add(tri); + break; + } + } + } + } + + newObj.Meshes.Add(newMesh); + curThread.CurrentCulture = curCultInfo; + srObj.Close(); + return newObj; + } + + public static void ToFile(string FileName, Object3D obj) + { + var fs = new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite); + var sw = new StreamWriter(fs, System.Text.Encoding.ASCII); + if (obj.Materials.Count > 0) + { + string mtlName = Path.GetFileNameWithoutExtension(FileName) + ".mtl"; + string mtlFile = Path.Combine(Path.GetDirectoryName(FileName), mtlName); + sw.WriteLine($"mtllib {mtlName}"); + MaterialLib.ToFile(mtlFile, obj); + } + + int curVertCount = 1; + int curUVCount = 1; + int curNormCount = 1; + int curVertColCount = 1; + foreach (Mesh m in obj.Meshes) + { + foreach (Vertex vert in m.Vertices) + sw.WriteLine($"v {vert.X.ToString().Replace(",", ".")} {vert.Y.ToString().Replace(",", ".")} {vert.Z.ToString().Replace(",", ".")}"); + foreach (UV uv in m.UVs) + sw.WriteLine($"vt {uv.U.ToString().Replace(",", ".")} {uv.V.ToString().Replace(",", ".")}"); + foreach (Normal norm in m.Normals) + sw.WriteLine($"vn {norm.X.ToString().Replace(",", ".")} {norm.Y.ToString().Replace(",", ".")} {norm.Z.ToString().Replace(",", ".")}"); + foreach (VertexColor vertcol in m.VertexColors) + sw.WriteLine($"vc {vertcol.R.ToString().Replace(",", ".")} {vertcol.G.ToString().Replace(",", ".")} {vertcol.B.ToString().Replace(",", ".")}"); + Material curMtl = null; + foreach (Face f in m.Faces) + { + if (!ReferenceEquals(curMtl, f.Material)) + { + curMtl = f.Material; + sw.WriteLine($"usemtl _{GetIndexOfMaterialInList(obj, curMtl)}"); + } + + sw.Write("f"); + foreach (Point p in f.Points) + { + sw.Write(" "); + sw.Write(curVertCount + m.Vertices.IndexOf(p.Vertex)); + sw.Write("/"); + if (p.UV is object) + sw.Write(curUVCount + m.UVs.IndexOf(p.UV)); + sw.Write("/"); + if (p.Normal is object) + sw.Write(curNormCount + m.Normals.IndexOf(p.Normal)); + if (m.VertexColors.Count > 0) + { + sw.Write("/"); + if (p.VertexColor is object) + sw.Write(curVertColCount + m.VertexColors.IndexOf(p.VertexColor)); + } + } + + sw.WriteLine(); + } + + curVertCount += m.Vertices.Count; + curUVCount += m.UVs.Count; + curNormCount += m.Normals.Count; + curVertColCount += m.VertexColors.Count; + } + + sw.Flush(); + fs.Close(); + } + + public static int GetIndexOfMaterialInList(Object3D obj, Material matToFind) + { + for (int Index = 0, loopTo = obj.Materials.Count - 1; Index <= loopTo; Index++) + { + if (obj.Materials.ElementAt(Index).Value.Equals(matToFind)) + { + return Index; + } + } + + return -1; + } + } + + public class MaterialLib + { + public Dictionary Materials { get; private set; } = new Dictionary(); + + private readonly Dictionary LoadedImages = new Dictionary(); + + public void FromFile(string fileName, bool LoadMaterials) + { + LoadedImages.Clear(); + string curMatLibPath = Path.GetDirectoryName(fileName); + Material curMat = null; + string curName = ""; + var srMtl = new StreamReader(fileName, System.Text.Encoding.ASCII); + string line = ""; + while (!srMtl.EndOfStream) + { + line = srMtl.ReadLine(); + switch (true) + { + case object _ when line.StartsWith("newmtl "): + { + curMat = new Material(); + curName = line.Substring(7); + Materials.Add(curName, curMat); + break; + } + + case object _ when line.ToLower().StartsWith("kd "): + { + var splitColor = line.Substring(3).Split(' '); + var col = Color.FromArgb((int)Convert.ToSingle(Math.Round(255d * Conversions.ToDouble(splitColor[0]))), (int)Convert.ToSingle(Math.Round(255d * Conversions.ToDouble(splitColor[1]))), (int)Convert.ToSingle(Math.Round(255d * Conversions.ToDouble(splitColor[2])))); + curMat.Color = col; + break; + } + + case object _ when line.ToLower().StartsWith("d "): + { + curMat.Opacity = Convert.ToSingle(line.Substring(2)); + break; + } + + case object _ when line.ToLower().StartsWith("tr "): + { + curMat.Opacity = 1f - Convert.ToSingle(line.Substring(2)); + break; + } + + case object _ when line.ToLower().StartsWith("map_kd "): + { + if (LoadMaterials) + { + string mtlpath = line.Substring(7); + string combipath = Path.Combine(curMatLibPath, line.Substring(7)); + string imgfile; + if (File.Exists(combipath)) + { + imgfile = combipath; + } + else if (File.Exists(line.Substring(7))) + { + imgfile = mtlpath; + } + else + { + imgfile = ""; + } + + if (!string.IsNullOrEmpty(imgfile)) + { + if (LoadedImages.ContainsKey(imgfile)) + { + curMat.Image = LoadedImages[imgfile]; + } + else + { + var fs = new FileStream(imgfile, FileMode.Open, FileAccess.Read); + curMat.Image = Image.FromStream(fs); + fs.Close(); + bool imgExists = false; + foreach (var kvp in LoadedImages) + { + if (!imgExists && ((Bitmap)kvp.Value).IsTheSameAs((Bitmap)curMat.Image)) + { + curMat.Image = kvp.Value; + imgExists = true; + } + } + + if (!imgExists) + { + LoadedImages.Add(imgfile, curMat.Image); + } + } + } + } + + break; + } + } + } + + srMtl.Close(); + } + + public static void ToFile(string fileName, Object3D obj) + { + var fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite); + var sw = new StreamWriter(fs, System.Text.Encoding.ASCII); + string imgDirName = Path.GetFileNameWithoutExtension(fileName); + string imgDirFull = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)); + foreach (KeyValuePair kvp in obj.Materials) + { + var mat = kvp.Value; + string name = "_" + ObjFile.GetIndexOfMaterialInList(obj, mat); + sw.WriteLine($"newmtl {name}"); + if (mat.Color is object) + { + sw.WriteLine($"kd {(mat.Color.Value.R / 255d).ToString().Replace(",", ".")} {(mat.Color.Value.G / 255d).ToString().Replace(",", ".")} {(mat.Color.Value.B / 255d).ToString().Replace(",", ".")}"); + } + + if (mat.Opacity is object) + { + sw.WriteLine($"d {mat.Opacity.Value.ToString().Replace(",", ".")}"); + } + + if (mat.Image is object) + { + string imgFile = name + ".png"; + if (!Directory.Exists(imgDirFull)) + Directory.CreateDirectory(imgDirFull); + mat.Image.Save(Path.Combine(imgDirFull, imgFile), System.Drawing.Imaging.ImageFormat.Png); + sw.WriteLine($"map_kd {Path.Combine(imgDirName, imgFile)}"); + } + } + + sw.Flush(); + fs.Close(); + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/FileParser/Obj.vb b/Pilz.Simple3DFileParser/FileParser/Obj.vb deleted file mode 100644 index 7b9de0e..0000000 --- a/Pilz.Simple3DFileParser/FileParser/Obj.vb +++ /dev/null @@ -1,391 +0,0 @@ -Imports System.Globalization -Imports System.IO -Imports System.Threading -Imports Pilz.S3DFileParser.Exceptions - -Namespace ObjModule - - Public Class ObjFile - - Public Shared Function FromFile(FileName As String, LoadMaterials As Boolean, UpAxis As UpAxis) As Object3D - Dim curThread As Thread = Thread.CurrentThread - Dim curCultInfo As CultureInfo = curThread.CurrentCulture - Dim newCultInfo As New CultureInfo(curCultInfo.Name) - newCultInfo.NumberFormat.NumberDecimalSeparator = "." - newCultInfo.NumberFormat.PercentDecimalSeparator = "." - newCultInfo.NumberFormat.CurrencyDecimalSeparator = "." - newCultInfo.NumberFormat.NumberGroupSeparator = "," - newCultInfo.NumberFormat.PercentGroupSeparator = "," - newCultInfo.NumberFormat.CurrencyGroupSeparator = "," - curThread.CurrentCulture = newCultInfo - - Dim newObj As New Object3D - Dim newMesh As New Mesh - Dim curObjPath As String = Path.GetDirectoryName(FileName) - - Dim mtllibs As New Dictionary(Of String, MaterialLib) - - Dim curMaterialLib As MaterialLib = Nothing - Dim curMaterial As Material = Nothing - - Dim srObj As New StreamReader(FileName, Text.Encoding.ASCII) - Dim line As String = "" - - Do Until srObj.EndOfStream - line = srObj.ReadLine.Trim - - If line <> "" Then - - Select Case True - Case line.StartsWith("mtllib ") - Dim name As String = line.Substring(7) - - If Not mtllibs.ContainsKey(name) Then - Dim mtlfile As String = Path.Combine(curObjPath, name) - If Not File.Exists(mtlfile) Then Throw New MaterialException("Material Library not found!") - - Dim newmtl As New MaterialLib - newmtl.FromFile(mtlfile, LoadMaterials) - mtllibs.Add(name, newmtl) - curMaterialLib = newmtl - - For Each kvp As KeyValuePair(Of String, Material) In curMaterialLib.Materials - If Not newObj.Materials.ContainsKey(kvp.Key) Then newObj.Materials.Add(kvp.Key, kvp.Value) - Next - Else - curMaterialLib = mtllibs(name) - End If - - Case line.StartsWith("usemtl ") - curMaterial = curMaterialLib.Materials(line.Substring(7)) - - Case line.StartsWith("v ") - If line.Contains("nan") Then line = line.Replace("nan", "0") - Dim splitXYZ() As String = line.Substring(2).Split(" "c) - - Dim tX As Double = Convert.ToDouble(splitXYZ(0)) - Dim tY As Double = Convert.ToDouble(splitXYZ(1)) - Dim tZ As Double = Convert.ToDouble(splitXYZ(2)) - - Dim v As New Vertex - Select Case UpAxis - Case UpAxis.Y - v.X = tX - v.Y = tY - v.Z = tZ - Case UpAxis.Z - v.X = tY - v.Y = tZ - v.Z = tX - End Select - newMesh.Vertices.Add(v) - - Case line.StartsWith("vt ") - Dim uvstr() As String = line.Substring(3).Split(" "c) - Dim uv As New UV With { - .U = Convert.ToSingle(uvstr(0)), - .V = Convert.ToSingle(uvstr(1))} - newMesh.UVs.Add(uv) - - Case line.StartsWith("vn ") - Dim splitXYZ() As String = line.Substring(3).Split(" "c) - - Dim tX As Single = Convert.ToSingle(splitXYZ(0)) - Dim tY As Single = Convert.ToSingle(splitXYZ(1)) - Dim tZ As Single = Convert.ToSingle(splitXYZ(2)) - - Dim n As New Normal - Select Case UpAxis - Case UpAxis.Y - n.X = tX - n.Y = tY - n.Z = tZ - Case UpAxis.Z - n.X = tZ - n.Y = tY - n.Z = tX - End Select - newMesh.Normals.Add(n) - - Case line.StartsWith("vc ") - Dim splitRGB() As String = line.Substring(3).Split(" "c) - - Dim tX As Single = Convert.ToSingle(splitRGB(0)) - Dim tY As Single = Convert.ToSingle(splitRGB(1)) - Dim tZ As Single = Convert.ToSingle(splitRGB(2)) - - Dim vc As New VertexColor - Select Case UpAxis - Case UpAxis.Y - vc.R = tX - vc.G = tY - vc.B = tZ - Case UpAxis.Z - vc.R = tY - vc.G = tZ - vc.B = tX - End Select - newMesh.VertexColors.Add(vc) - - Case line.StartsWith("f ") - Dim tri As New Face With {.Material = curMaterial} - - For Each xyz As String In line.Substring(2).Split(" "c) - xyz = xyz.Trim - If xyz = "" Then Continue For - - Dim splitsub() As String = Nothing - Dim p As New Point - - Select Case True - Case xyz.Contains("/") - splitsub = xyz.Split("/"c) - Case xyz.Contains("\") - splitsub = xyz.Split("\"c) - Case Else - splitsub = {0, 0, 0} - End Select - - Dim v1 As String = splitsub(0) - Dim v2 As String = splitsub(1) - Dim v3 As String = splitsub(2) - - If v1 <> "" Then - p.Vertex = newMesh.Vertices(Convert.ToInt32(v1) - 1) - End If - - If v2 <> "" Then - p.UV = newMesh.UVs(Convert.ToInt32(v2) - 1) - Else - Dim newUV As New UV With {.U = 0, .V = 0} - p.UV = newUV - newMesh.UVs.Add(newUV) - End If - - If v3 <> "" Then - p.Normal = newMesh.Normals(Convert.ToInt32(v3) - 1) - End If - - If splitsub.Count > 3 Then - Dim v4 As String = splitsub(3) - If v4 <> "" Then p.VertexColor = newMesh.VertexColors(Convert.ToInt32(v4) - 1) - End If - - tri.Points.Add(p) - Next - - newMesh.Faces.Add(tri) - - End Select - - End If - - Loop - newObj.Meshes.Add(newMesh) - - curThread.CurrentCulture = curCultInfo - - srObj.Close() - Return newObj - End Function - - Public Shared Sub ToFile(FileName As String, obj As Object3D) - Dim fs As New FileStream(FileName, FileMode.Create, FileAccess.ReadWrite) - Dim sw As New StreamWriter(fs, Text.Encoding.ASCII) - - If obj.Materials.Count > 0 Then - Dim mtlName As String = Path.GetFileNameWithoutExtension(FileName) & ".mtl" - Dim mtlFile As String = Path.Combine(Path.GetDirectoryName(FileName), mtlName) - sw.WriteLine($"mtllib {mtlName}") - MaterialLib.ToFile(mtlFile, obj) - End If - - Dim curVertCount As Integer = 1 - Dim curUVCount As Integer = 1 - Dim curNormCount As Integer = 1 - Dim curVertColCount As Integer = 1 - - For Each m As Mesh In obj.Meshes - - For Each vert As Vertex In m.Vertices - sw.WriteLine($"v {vert.X.ToString.Replace(",", ".")} {vert.Y.ToString.Replace(",", ".")} {vert.Z.ToString.Replace(",", ".")}") - Next - - For Each uv As UV In m.UVs - sw.WriteLine($"vt {uv.U.ToString.Replace(",", ".")} {uv.V.ToString.Replace(",", ".")}") - Next - - For Each norm As Normal In m.Normals - sw.WriteLine($"vn {norm.X.ToString.Replace(",", ".")} {norm.Y.ToString.Replace(",", ".")} {norm.Z.ToString.Replace(",", ".")}") - Next - - For Each vertcol As VertexColor In m.VertexColors - sw.WriteLine($"vc {vertcol.R.ToString.Replace(",", ".")} {vertcol.G.ToString.Replace(",", ".")} {vertcol.B.ToString.Replace(",", ".")}") - Next - - Dim curMtl As Material = Nothing - - For Each f As Face In m.Faces - If curMtl IsNot f.Material Then - curMtl = f.Material - sw.WriteLine($"usemtl _{GetIndexOfMaterialInList(obj, curMtl)}") - End If - - sw.Write("f") - - For Each p As Point In f.Points - sw.Write(" ") - sw.Write(curVertCount + m.Vertices.IndexOf(p.Vertex)) - - sw.Write("/") - If p.UV IsNot Nothing Then sw.Write(curUVCount + m.UVs.IndexOf(p.UV)) - - sw.Write("/") - If p.Normal IsNot Nothing Then sw.Write(curNormCount + m.Normals.IndexOf(p.Normal)) - - If m.VertexColors.Count > 0 Then - sw.Write("/") - If p.VertexColor IsNot Nothing Then sw.Write(curVertColCount + m.VertexColors.IndexOf(p.VertexColor)) - End If - Next - - sw.WriteLine() - Next - - curVertCount += m.Vertices.Count - curUVCount += m.UVs.Count - curNormCount += m.Normals.Count - curVertColCount += m.VertexColors.Count - Next - - sw.Flush() - fs.Close() - End Sub - - Public Shared Function GetIndexOfMaterialInList(obj As Object3D, matToFind As Material) As Integer - For Index As Integer = 0 To obj.Materials.Count - 1 - If obj.Materials.ElementAt(Index).Value.Equals(matToFind) Then - Return Index - End If - Next - Return -1 - End Function - - End Class - - Public Class MaterialLib - - Public ReadOnly Property Materials As New Dictionary(Of String, Material) - Private ReadOnly LoadedImages As New Dictionary(Of String, Image) - - Public Sub FromFile(fileName As String, LoadMaterials As Boolean) - LoadedImages.Clear() - - Dim curMatLibPath As String = Path.GetDirectoryName(fileName) - - Dim curMat As Material = Nothing - Dim curName As String = "" - - Dim srMtl As New StreamReader(fileName, Text.Encoding.ASCII) - Dim line As String = "" - - Do Until srMtl.EndOfStream - line = srMtl.ReadLine - - Select Case True - Case line.StartsWith("newmtl ") - curMat = New Material - curName = line.Substring(7) - Materials.Add(curName, curMat) - - Case line.ToLower.StartsWith("kd ") - Dim splitColor() As String = line.Substring(3).Split(" "c) - Dim col As Color = Color.FromArgb( - Convert.ToSingle(Math.Round(255 * splitColor(0))), - Convert.ToSingle(Math.Round(255 * splitColor(1))), - Convert.ToSingle(Math.Round(255 * splitColor(2)))) - curMat.Color = col - - Case line.ToLower.StartsWith("d ") - curMat.Opacity = Convert.ToSingle(line.Substring(2)) - - Case line.ToLower.StartsWith("tr ") - curMat.Opacity = 1 - Convert.ToSingle(line.Substring(2)) - - Case line.ToLower.StartsWith("map_kd ") - If LoadMaterials Then - Dim mtlpath As String = line.Substring(7) - Dim combipath As String = Path.Combine(curMatLibPath, line.Substring(7)) - Dim imgfile As String - - If File.Exists(combipath) Then - imgfile = combipath - ElseIf File.Exists(line.Substring(7)) Then - imgfile = mtlpath - Else - imgfile = "" - End If - - If imgfile <> "" Then - If LoadedImages.ContainsKey(imgfile) Then - curMat.Image = LoadedImages(imgfile) - Else - Dim fs As New FileStream(imgfile, FileMode.Open, FileAccess.Read) - curMat.Image = Image.FromStream(fs) - fs.Close() - Dim imgExists As Boolean = False - For Each kvp In LoadedImages - If Not imgExists AndAlso IsTheSameAs(kvp.Value, curMat.Image) Then - curMat.Image = kvp.Value - imgExists = True - End If - Next - If Not imgExists Then - LoadedImages.Add(imgfile, curMat.Image) - End If - End If - End If - End If - - End Select - Loop - - srMtl.Close() - End Sub - - Public Shared Sub ToFile(fileName As String, obj As Object3D) - Dim fs As New FileStream(fileName, FileMode.Create, FileAccess.ReadWrite) - Dim sw As New StreamWriter(fs, Text.Encoding.ASCII) - Dim imgDirName As String = Path.GetFileNameWithoutExtension(fileName) - Dim imgDirFull As String = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)) - - For Each kvp As KeyValuePair(Of String, Material) In obj.Materials - Dim mat As Material = kvp.Value - Dim name As String = "_" & ObjFile.GetIndexOfMaterialInList(obj, mat) - sw.WriteLine($"newmtl {name}") - - If mat.Color IsNot Nothing Then - sw.WriteLine($"kd {(mat.Color.Value.R / 255).ToString.Replace(",", ".")} {(mat.Color.Value.G / 255).ToString.Replace(",", ".")} {(mat.Color.Value.B / 255).ToString.Replace(",", ".")}") - End If - - If mat.Opacity IsNot Nothing Then - sw.WriteLine($"d {mat.Opacity.Value.ToString.Replace(",", ".")}") - End If - - If mat.Image IsNot Nothing Then - Dim imgFile As String = name & ".png" - - If Not Directory.Exists(imgDirFull) Then Directory.CreateDirectory(imgDirFull) - mat.Image.Save(Path.Combine(imgDirFull, imgFile), Imaging.ImageFormat.Png) - - sw.WriteLine($"map_kd {Path.Combine(imgDirName, imgFile)}") - End If - Next - - sw.Flush() - fs.Close() - End Sub - - End Class - -End Namespace \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Face.cs b/Pilz.Simple3DFileParser/Model/Face.cs new file mode 100644 index 0000000..09fd85e --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Face.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Pilz.S3DFileParser +{ + public class Face + { + public List Points { get; private set; } = new List(); + public Material Material { get; set; } = null; + public object Tag { get; set; } = null; + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Face.vb b/Pilz.Simple3DFileParser/Model/Face.vb deleted file mode 100644 index 09497ce..0000000 --- a/Pilz.Simple3DFileParser/Model/Face.vb +++ /dev/null @@ -1,5 +0,0 @@ -Public Class Face - Public ReadOnly Property Points As New List(Of Point) - Public Property Material As Material = Nothing - Public Property Tag As Object = Nothing -End Class diff --git a/Pilz.Simple3DFileParser/Model/Interfaces.cs b/Pilz.Simple3DFileParser/Model/Interfaces.cs new file mode 100644 index 0000000..6f037f2 --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Interfaces.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; + +namespace Pilz.S3DFileParser +{ + public interface IToObject3D + { + Object3D ToObject3D(); + Task ToObject3DAsync(); + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Interfaces.vb b/Pilz.Simple3DFileParser/Model/Interfaces.vb deleted file mode 100644 index 05bac76..0000000 --- a/Pilz.Simple3DFileParser/Model/Interfaces.vb +++ /dev/null @@ -1,6 +0,0 @@ -Public Interface IToObject3D - - Function ToObject3D() As Object3D - Function ToObject3DAsync() As Task(Of Object3D) - -End Interface diff --git a/Pilz.Simple3DFileParser/Model/Material.cs b/Pilz.Simple3DFileParser/Model/Material.cs new file mode 100644 index 0000000..f12aa71 --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Material.cs @@ -0,0 +1,35 @@ +using System; +using System.Drawing; +using global::System.Numerics; + +namespace Pilz.S3DFileParser +{ + public class Material : IComparable + { + public Image Image { get; set; } = null; + public Color? Color { get; set; } = default; + public float? Opacity { get; set; } = default; + public Vector2 Wrap { get; set; } = new Vector2(10497f, 10497f); + public Vector2 Scale { get; set; } = new Vector2(1.0f, 1.0f); + public object Tag { get; set; } = null; + + public int CompareTo(object obj) + { + if (obj is object) + { + if (ReferenceEquals(obj, this)) + { + return 0; + } + else + { + return -1; + } + } + else + { + return 1; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Material.vb b/Pilz.Simple3DFileParser/Model/Material.vb deleted file mode 100644 index 1b755b6..0000000 --- a/Pilz.Simple3DFileParser/Model/Material.vb +++ /dev/null @@ -1,25 +0,0 @@ -Imports System.Numerics - -Public Class Material - Implements IComparable - - Public Property Image As Image = Nothing - Public Property Color As Color? = Nothing - Public Property Opacity As Single? = Nothing - Public Property Wrap As New Vector2(10497, 10497) - Public Property Scale As New Vector2(1.0F, 1.0F) - Public Property Tag As Object = Nothing - - Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo - If obj IsNot Nothing Then - If obj Is Me Then - Return 0 - Else - Return -1 - End If - Else - Return 1 - End If - End Function - -End Class diff --git a/Pilz.Simple3DFileParser/Model/Mesh.cs b/Pilz.Simple3DFileParser/Model/Mesh.cs new file mode 100644 index 0000000..87c9721 --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Mesh.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using global::System.Numerics; + +namespace Pilz.S3DFileParser +{ + public class Mesh + { + public List Vertices { get; private set; } = new List(); + public List Normals { get; private set; } = new List(); + public List UVs { get; private set; } = new List(); + public List VertexColors { get; private set; } = new List(); + public List Faces { get; private set; } = new List(); + + public void CenterModel() + { + CenterModel(new[] { this }); + } + + public static void CenterModel(IEnumerable meshes) + { + int avgX = 0; + int avgY = 0; + int avgZ = 0; + long vertsCount = 0L; + foreach (Mesh m in meshes) + { + foreach (Vertex v in m.Vertices) + { + avgX = (int)(avgX + v.X); + avgY = (int)(avgY + v.Y); + avgZ = (int)(avgZ + v.Z); + } + + vertsCount += m.Vertices.Count; + } + + var avg = new Vector3(avgX, avgY, avgZ); + avg /= new Vector3(vertsCount); + foreach (Mesh m in meshes) + { + foreach (Vertex v in m.Vertices) + { + v.X -= avg.X; + v.Y -= avg.Y; + v.Z -= avg.Z; + } + } + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Mesh.vb b/Pilz.Simple3DFileParser/Model/Mesh.vb deleted file mode 100644 index 392c850..0000000 --- a/Pilz.Simple3DFileParser/Model/Mesh.vb +++ /dev/null @@ -1,42 +0,0 @@ -Imports System.Numerics - -Public Class Mesh - - Public ReadOnly Property Vertices As New List(Of Vertex) - Public ReadOnly Property Normals As New List(Of Normal) - Public ReadOnly Property UVs As New List(Of UV) - Public ReadOnly Property VertexColors As New List(Of VertexColor) - Public ReadOnly Property Faces As New List(Of Face) - - Public Sub CenterModel() - CenterModel({Me}) - End Sub - - Public Shared Sub CenterModel(meshes As IEnumerable(Of Mesh)) - Dim avgX As Integer = 0 - Dim avgY As Integer = 0 - Dim avgZ As Integer = 0 - Dim vertsCount As Long = 0 - - For Each m As Mesh In meshes - For Each v As Vertex In m.Vertices - avgX += v.X - avgY += v.Y - avgZ += v.Z - Next - vertsCount += m.Vertices.Count - Next - - Dim avg As New Vector3(avgX, avgY, avgZ) - avg /= New Vector3(vertsCount) - - For Each m As Mesh In meshes - For Each v As Vertex In m.Vertices - v.X -= avg.X - v.Y -= avg.Y - v.Z -= avg.Z - Next - Next - End Sub - -End Class diff --git a/Pilz.Simple3DFileParser/Model/ModelBoundaries.cs b/Pilz.Simple3DFileParser/Model/ModelBoundaries.cs new file mode 100644 index 0000000..bcffcbe --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/ModelBoundaries.cs @@ -0,0 +1,16 @@ +using global::System.Numerics; + +namespace Pilz.S3DFileParser +{ + public class ModelBoundaries + { + public readonly Vector3 Upper; + public readonly Vector3 Lower; + + public ModelBoundaries(Vector3 upper, Vector3 lower) + { + Upper = upper; + Lower = lower; + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/ModelBoundaries.vb b/Pilz.Simple3DFileParser/Model/ModelBoundaries.vb deleted file mode 100644 index ea4495d..0000000 --- a/Pilz.Simple3DFileParser/Model/ModelBoundaries.vb +++ /dev/null @@ -1,11 +0,0 @@ -Imports System.Numerics - -Public Class ModelBoundaries - Public ReadOnly Upper As Vector3 - Public ReadOnly Lower As Vector3 - - Public Sub New(upper As Vector3, lower As Vector3) - Me.Upper = upper - Me.Lower = lower - End Sub -End Class diff --git a/Pilz.Simple3DFileParser/Model/Normal.cs b/Pilz.Simple3DFileParser/Model/Normal.cs new file mode 100644 index 0000000..de6a011 --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Normal.cs @@ -0,0 +1,10 @@ + +namespace Pilz.S3DFileParser +{ + public class Normal + { + public float X { get; set; } = 0f; + public float Y { get; set; } = 0f; + public float Z { get; set; } = 0f; + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Normal.vb b/Pilz.Simple3DFileParser/Model/Normal.vb deleted file mode 100644 index e855cb2..0000000 --- a/Pilz.Simple3DFileParser/Model/Normal.vb +++ /dev/null @@ -1,5 +0,0 @@ -Public Class Normal - Public Property X As Single = 0 - Public Property Y As Single = 0 - Public Property Z As Single = 0 -End Class diff --git a/Pilz.Simple3DFileParser/Model/Object3D.cs b/Pilz.Simple3DFileParser/Model/Object3D.cs new file mode 100644 index 0000000..e8a1ad0 --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Object3D.cs @@ -0,0 +1,217 @@ +using System.Collections.Generic; +using global::System.Numerics; + +namespace Pilz.S3DFileParser +{ + public class Object3D + { + public List Meshes { get; private set; } = new List(); + public Dictionary Materials { get; private set; } = new Dictionary(); + public Shading Shading { get; set; } = new Shading(); + + public void ScaleModel(float factor) + { + foreach (Mesh m in Meshes) + { + foreach (Vertex v in m.Vertices) + { + v.X *= factor; + v.Y *= factor; + v.Z *= factor; + } + } + } + + public void OffsetModel(Vector3 off) + { + foreach (Mesh m in Meshes) + { + foreach (Vertex v in m.Vertices) + { + v.X += off.X; + v.Y += off.Y; + v.Z += off.Z; + } + } + } + + public ModelBoundaries GetBoundaries() + { + float? maxX = default; + float? maxY = default; + float? maxZ = default; + float? minX = default; + float? minY = default; + float? minZ = default; + foreach (Mesh m in Meshes) + { + foreach (Vertex vert in m.Vertices) + { + if (maxX is null || vert.X > maxX) + maxX = (float?)vert.X; + if (maxY is null || vert.Y > maxY) + maxY = (float?)vert.Y; + if (maxZ is null || vert.Z > maxZ) + maxZ = (float?)vert.Z; + if (minX is null || vert.X < minX) + minX = (float?)vert.X; + if (minY is null || vert.Y < minY) + minY = (float?)vert.Y; + if (minZ is null || vert.Z < minZ) + minZ = (float?)vert.Z; + } + } + + if (maxX is null) + maxX = 0; + if (maxY is null) + maxY = 0; + if (maxZ is null) + maxZ = 0; + if (minX is null) + minX = 0; + if (minY is null) + minY = 0; + if (minZ is null) + minZ = 0; + return new ModelBoundaries(new Vector3((float)maxX, (float)maxY, (float)maxZ), new Vector3((float)minX, (float)minY, (float)minZ)); + } + + public void SetNullVertices() + { + var newVert = new Vertex() { X = 0d, Y = 0d, Z = 0d }; + int nullCounter; + foreach (Mesh m in Meshes) + { + nullCounter = 0; + foreach (Face f in m.Faces) + { + foreach (Point p in f.Points) + { + if (p.Vertex is null) + { + p.Vertex = newVert; + nullCounter += 1; + } + } + } + + if (nullCounter > 0) + { + m.Vertices.Add(newVert); + } + } + } + + public void SetNullUVs() + { + var newUV = new UV() { U = 0f, V = 0f }; + int nullCounter; + foreach (Mesh m in Meshes) + { + nullCounter = 0; + foreach (Face f in m.Faces) + { + foreach (Point p in f.Points) + { + if (p.UV is null) + { + p.UV = newUV; + nullCounter += 1; + } + } + } + + if (nullCounter > 0) + { + m.UVs.Add(newUV); + } + } + } + + public void SetNullNormals() + { + var newNormal = new Normal() { X = 0f, Y = 0f, Z = 1f }; + int nullCounter; + foreach (Mesh m in Meshes) + { + nullCounter = 0; + foreach (Face f in m.Faces) + { + foreach (Point p in f.Points) + { + if (p.Normal is null) + { + p.Normal = newNormal; + nullCounter += 1; + } + } + } + + if (nullCounter > 0) + { + m.Normals.Add(newNormal); + } + } + } + + public void RemoveUnusedMaterials() + { + // Dim usedMats As New List(Of Material) + // Dim unusedMats As New List(Of String) + + // For Each f As Face In Faces + // If Not usedMats.Contains(f.Material) Then + // usedMats.Add(f.Material) + // End If + // Next + + // For Each kvp As KeyValuePair(Of String, Material) In Materials + // If Not usedMats.Contains(kvp.Value) Then + // unusedMats.Add(kvp.Key) + // End If + // Next + + // For Each k As String In unusedMats + // Materials.Remove(k) + // Next + } + + public Object3D ToOneMesh() + { + var newObject3D = new Object3D(); + var newMesh = new Mesh(); + foreach (KeyValuePair mat in Materials) + newObject3D.Materials.Add(mat.Key, mat.Value); + foreach (Mesh m in Meshes) + { + foreach (Vertex v in m.Vertices) + newMesh.Vertices.Add(v); + foreach (VertexColor vc in m.VertexColors) + newMesh.VertexColors.Add(vc); + foreach (Normal n in m.Normals) + newMesh.Normals.Add(n); + foreach (UV uv in m.UVs) + newMesh.UVs.Add(uv); + foreach (Face f in m.Faces) + newMesh.Faces.Add(f); + } + + newObject3D.Meshes.Add(newMesh); + return newObject3D; + } + + public void CenterModel() + { + Mesh.CenterModel(Meshes); + } + + public static void CenterModel(IEnumerable objs) + { + var meshes = new List(); + foreach (Object3D obj in objs) + meshes.AddRange(obj.Meshes); + Mesh.CenterModel(meshes); + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Object3D.vb b/Pilz.Simple3DFileParser/Model/Object3D.vb deleted file mode 100644 index 7e36721..0000000 --- a/Pilz.Simple3DFileParser/Model/Object3D.vb +++ /dev/null @@ -1,195 +0,0 @@ -Imports System.IO -Imports System.Numerics - -Public Class Object3D - - Public ReadOnly Property Meshes As New List(Of Mesh) - Public ReadOnly Property Materials As New Dictionary(Of String, Material) - Public Property Shading As New Shading - - Public Sub ScaleModel(factor As Single) - For Each m As Mesh In Meshes - For Each v As Vertex In m.Vertices - v.X *= factor - v.Y *= factor - v.Z *= factor - Next - Next - End Sub - - Public Sub OffsetModel(off As Vector3) - For Each m As Mesh In Meshes - For Each v As Vertex In m.Vertices - v.X += off.X - v.Y += off.Y - v.Z += off.Z - Next - Next - End Sub - - Public Function GetBoundaries() As ModelBoundaries - Dim maxX As Single? = Nothing - Dim maxY As Single? = Nothing - Dim maxZ As Single? = Nothing - Dim minX As Single? = Nothing - Dim minY As Single? = Nothing - Dim minZ As Single? = Nothing - - For Each m As Mesh In Meshes - For Each vert As Vertex In m.Vertices - If maxX Is Nothing OrElse vert.X > maxX Then maxX = vert.X - If maxY Is Nothing OrElse vert.Y > maxY Then maxY = vert.Y - If maxZ Is Nothing OrElse vert.Z > maxZ Then maxZ = vert.Z - If minX Is Nothing OrElse vert.X < minX Then minX = vert.X - If minY Is Nothing OrElse vert.Y < minY Then minY = vert.Y - If minZ Is Nothing OrElse vert.Z < minZ Then minZ = vert.Z - Next - Next - - If maxX Is Nothing Then maxX = 0 - If maxY Is Nothing Then maxY = 0 - If maxZ Is Nothing Then maxZ = 0 - If minX Is Nothing Then minX = 0 - If minY Is Nothing Then minY = 0 - If minZ Is Nothing Then minZ = 0 - - Return New ModelBoundaries(New Vector3(maxX, maxY, maxZ), - New Vector3(minX, minY, minZ)) - End Function - - Public Sub SetNullVertices() - Dim newVert As New Vertex With {.X = 0, .Y = 0, .Z = 0} - Dim nullCounter As Integer - - For Each m As Mesh In Meshes - nullCounter = 0 - - For Each f As Face In m.Faces - For Each p As Point In f.Points - If p.Vertex Is Nothing Then - p.Vertex = newVert - nullCounter += 1 - End If - Next - Next - - If nullCounter > 0 Then - m.Vertices.Add(newVert) - End If - Next - End Sub - - Public Sub SetNullUVs() - Dim newUV As New UV With {.U = 0, .V = 0} - Dim nullCounter As Integer - - For Each m As Mesh In Meshes - nullCounter = 0 - - For Each f As Face In m.Faces - For Each p As Point In f.Points - If p.UV Is Nothing Then - p.UV = newUV - nullCounter += 1 - End If - Next - Next - - If nullCounter > 0 Then - m.UVs.Add(newUV) - End If - Next - End Sub - - Public Sub SetNullNormals() - Dim newNormal As New Normal With {.X = 0, .Y = 0, .Z = 1} - Dim nullCounter As Integer - - For Each m As Mesh In Meshes - nullCounter = 0 - - For Each f As Face In m.Faces - For Each p As Point In f.Points - If p.Normal Is Nothing Then - p.Normal = newNormal - nullCounter += 1 - End If - Next - Next - - If nullCounter > 0 Then - m.Normals.Add(newNormal) - End If - Next - End Sub - - Public Sub RemoveUnusedMaterials() - 'Dim usedMats As New List(Of Material) - 'Dim unusedMats As New List(Of String) - - 'For Each f As Face In Faces - ' If Not usedMats.Contains(f.Material) Then - ' usedMats.Add(f.Material) - ' End If - 'Next - - 'For Each kvp As KeyValuePair(Of String, Material) In Materials - ' If Not usedMats.Contains(kvp.Value) Then - ' unusedMats.Add(kvp.Key) - ' End If - 'Next - - 'For Each k As String In unusedMats - ' Materials.Remove(k) - 'Next - End Sub - - Public Function ToOneMesh() As Object3D - Dim newObject3D As New Object3D - Dim newMesh As New Mesh - - For Each mat As KeyValuePair(Of String, Material) In Materials - newObject3D.Materials.Add(mat.Key, mat.Value) - Next - - For Each m As Mesh In Meshes - For Each v As Vertex In m.Vertices - newMesh.Vertices.Add(v) - Next - - For Each vc As VertexColor In m.VertexColors - newMesh.VertexColors.Add(vc) - Next - - For Each n As Normal In m.Normals - newMesh.Normals.Add(n) - Next - - For Each uv As UV In m.UVs - newMesh.UVs.Add(uv) - Next - - For Each f As Face In m.Faces - newMesh.Faces.Add(f) - Next - Next - - newObject3D.Meshes.Add(newMesh) - Return newObject3D - End Function - - Public Sub CenterModel() - Mesh.CenterModel(Meshes) - End Sub - - Public Shared Sub CenterModel(objs As IEnumerable(Of Object3D)) - Dim meshes As New List(Of Mesh) - - For Each obj As Object3D In objs - meshes.AddRange(obj.Meshes) - Next - - Mesh.CenterModel(meshes) - End Sub - -End Class diff --git a/Pilz.Simple3DFileParser/Model/Point.cs b/Pilz.Simple3DFileParser/Model/Point.cs new file mode 100644 index 0000000..731fb6c --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Point.cs @@ -0,0 +1,11 @@ + +namespace Pilz.S3DFileParser +{ + public class Point + { + public Vertex Vertex { get; set; } = null; + public UV UV { get; set; } = null; + public VertexColor VertexColor { get; set; } = null; + public Normal Normal { get; set; } = null; + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Point.vb b/Pilz.Simple3DFileParser/Model/Point.vb deleted file mode 100644 index 2760f7f..0000000 --- a/Pilz.Simple3DFileParser/Model/Point.vb +++ /dev/null @@ -1,6 +0,0 @@ -Public Class Point - Public Property Vertex As Vertex = Nothing - Public Property UV As UV = Nothing - Public Property VertexColor As VertexColor = Nothing - Public Property Normal As Normal = Nothing -End Class diff --git a/Pilz.Simple3DFileParser/Model/Shading.cs b/Pilz.Simple3DFileParser/Model/Shading.cs new file mode 100644 index 0000000..0e7d465 --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Shading.cs @@ -0,0 +1,12 @@ +using System; +using System.Drawing; + +namespace Pilz.S3DFileParser +{ + public class Shading + { + public Color AmbientColor { get; set; } = Color.FromArgb(Convert.ToInt32(0xFFFFFFFF)); + public Color DiffuseColor { get; set; } = Color.FromArgb(Convert.ToInt32(0xFF7F7F7F)); + public Vertex DiffusePosition { get; set; } = null; + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Shading.vb b/Pilz.Simple3DFileParser/Model/Shading.vb deleted file mode 100644 index b69447b..0000000 --- a/Pilz.Simple3DFileParser/Model/Shading.vb +++ /dev/null @@ -1,5 +0,0 @@ -Public Class Shading - Public Property AmbientColor As Color = Color.FromArgb(&HFFFFFFFF) - Public Property DiffuseColor As Color = Color.FromArgb(&HFF7F7F7F) - Public Property DiffusePosition As Vertex = Nothing -End Class diff --git a/Pilz.Simple3DFileParser/Model/UV.cs b/Pilz.Simple3DFileParser/Model/UV.cs new file mode 100644 index 0000000..105e70a --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/UV.cs @@ -0,0 +1,9 @@ + +namespace Pilz.S3DFileParser +{ + public class UV + { + public float U { get; set; } = 0f; + public float V { get; set; } = 0f; + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/UV.vb b/Pilz.Simple3DFileParser/Model/UV.vb deleted file mode 100644 index 74de128..0000000 --- a/Pilz.Simple3DFileParser/Model/UV.vb +++ /dev/null @@ -1,4 +0,0 @@ -Public Class UV - Public Property U As Single = 0 - Public Property V As Single = 0 -End Class diff --git a/Pilz.Simple3DFileParser/Model/UpAxis.cs b/Pilz.Simple3DFileParser/Model/UpAxis.cs new file mode 100644 index 0000000..4cb340f --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/UpAxis.cs @@ -0,0 +1,9 @@ + +namespace Pilz.S3DFileParser +{ + public enum UpAxis + { + Y, + Z + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/UpAxis.vb b/Pilz.Simple3DFileParser/Model/UpAxis.vb deleted file mode 100644 index 1e309de..0000000 --- a/Pilz.Simple3DFileParser/Model/UpAxis.vb +++ /dev/null @@ -1,4 +0,0 @@ -Public Enum UpAxis - Y - Z -End Enum diff --git a/Pilz.Simple3DFileParser/Model/Vertex.cs b/Pilz.Simple3DFileParser/Model/Vertex.cs new file mode 100644 index 0000000..10a9cb9 --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/Vertex.cs @@ -0,0 +1,10 @@ + +namespace Pilz.S3DFileParser +{ + public class Vertex + { + public double X { get; set; } = 0d; + public double Y { get; set; } = 0d; + public double Z { get; set; } = 0d; + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/Vertex.vb b/Pilz.Simple3DFileParser/Model/Vertex.vb deleted file mode 100644 index d1b4d1e..0000000 --- a/Pilz.Simple3DFileParser/Model/Vertex.vb +++ /dev/null @@ -1,5 +0,0 @@ -Public Class Vertex - Public Property X As Double = 0 - Public Property Y As Double = 0 - Public Property Z As Double = 0 -End Class diff --git a/Pilz.Simple3DFileParser/Model/VertexColor.cs b/Pilz.Simple3DFileParser/Model/VertexColor.cs new file mode 100644 index 0000000..e4d06bf --- /dev/null +++ b/Pilz.Simple3DFileParser/Model/VertexColor.cs @@ -0,0 +1,11 @@ + +namespace Pilz.S3DFileParser +{ + public class VertexColor + { + public float R { get; set; } = 1f; + public float G { get; set; } = 1f; + public float B { get; set; } = 1f; + public float A { get; set; } = 1f; + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Model/VertexColor.vb b/Pilz.Simple3DFileParser/Model/VertexColor.vb deleted file mode 100644 index 0d41404..0000000 --- a/Pilz.Simple3DFileParser/Model/VertexColor.vb +++ /dev/null @@ -1,6 +0,0 @@ -Public Class VertexColor - Public Property R As Single = 1 - Public Property G As Single = 1 - Public Property B As Single = 1 - Public Property A As Single = 1 -End Class diff --git a/Pilz.Simple3DFileParser/My Project/Application.Designer.cs b/Pilz.Simple3DFileParser/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Simple3DFileParser/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Simple3DFileParser/My Project/Application.Designer.vb b/Pilz.Simple3DFileParser/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Simple3DFileParser/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Simple3DFileParser/My Project/AssemblyInfo.cs b/Pilz.Simple3DFileParser/My Project/AssemblyInfo.cs new file mode 100644 index 0000000..37dc55c --- /dev/null +++ b/Pilz.Simple3DFileParser/My Project/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("SimpleFileParser")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("Pilzinsel64")] +[assembly: AssemblyProduct("SM64 ROM Manager")] +[assembly: AssemblyCopyright("Copyright © Pilzinsel64 2018")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("21610485-a96f-4808-bf2e-bbf06c65eba1")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Simple3DFileParser/My Project/AssemblyInfo.vb b/Pilz.Simple3DFileParser/My Project/AssemblyInfo.vb deleted file mode 100644 index d6dd9e2..0000000 --- a/Pilz.Simple3DFileParser/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..3d06c02 --- /dev/null +++ b/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.S3DFileParser.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..4c3bc6b --- /dev/null +++ b/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.S3DFileParser.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Simple3DFileParser/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/My Project/Resources.Designer.vb b/Pilz.Simple3DFileParser/My Project/Resources.Designer.vb deleted file mode 100644 index 0832c08..0000000 --- a/Pilz.Simple3DFileParser/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.S3DFileParser.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Simple3DFileParser/My Project/Settings.Designer.vb b/Pilz.Simple3DFileParser/My Project/Settings.Designer.vb deleted file mode 100644 index 60c5980..0000000 --- a/Pilz.Simple3DFileParser/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.S3DFileParser.My.MySettings - Get - Return Global.Pilz.S3DFileParser.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Simple3DFileParser/Other/Exceptions.cs b/Pilz.Simple3DFileParser/Other/Exceptions.cs new file mode 100644 index 0000000..bc50d92 --- /dev/null +++ b/Pilz.Simple3DFileParser/Other/Exceptions.cs @@ -0,0 +1,15 @@ +using System; + +namespace Pilz.S3DFileParser.Exceptions +{ + public class MaterialException : Exception + { + public MaterialException() : base() + { + } + + public MaterialException(string message) : base(message) + { + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Other/Exceptions.vb b/Pilz.Simple3DFileParser/Other/Exceptions.vb deleted file mode 100644 index df3a620..0000000 --- a/Pilz.Simple3DFileParser/Other/Exceptions.vb +++ /dev/null @@ -1,14 +0,0 @@ -Namespace Exceptions - - Public Class MaterialException - Inherits Exception - - Public Sub New() - MyBase.New - End Sub - Public Sub New(message As String) - MyBase.New(message) - End Sub - End Class - -End Namespace diff --git a/Pilz.Simple3DFileParser/Other/Extensions.cs b/Pilz.Simple3DFileParser/Other/Extensions.cs new file mode 100644 index 0000000..9f266b1 --- /dev/null +++ b/Pilz.Simple3DFileParser/Other/Extensions.cs @@ -0,0 +1,30 @@ +using System.Drawing; + +namespace Pilz.S3DFileParser +{ + internal static class Extensions + { + public static object GetPropertyValue(this object @base, string propertyName) + { + return @base?.GetType().GetProperty(propertyName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static)?.GetValue(@base); + } + + public static bool IsTheSameAs(this Bitmap @base, Bitmap image) + { + if (@base.Size != image.Size) + return false; + for (int y = 0, loopTo = @base.Height - 1; y <= loopTo; y++) + { + for (int x = 0, loopTo1 = @base.Width - 1; x <= loopTo1; x++) + { + var p1 = @base.GetPixel(x, y); + var p2 = image.GetPixel(x, y); + if (p1 != p2) + return false; + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Other/Extensions.vb b/Pilz.Simple3DFileParser/Other/Extensions.vb deleted file mode 100644 index 59da39b..0000000 --- a/Pilz.Simple3DFileParser/Other/Extensions.vb +++ /dev/null @@ -1,26 +0,0 @@ -Imports System.IO -Imports System.Runtime.CompilerServices - -Friend Module Extensions - - - Public Function GetPropertyValue(base As Object, propertyName As String) As Object - Return base?.GetType.GetProperty(propertyName, Reflection.BindingFlags.Public Or Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.Static)?.GetValue(base) - End Function - - - Public Function IsTheSameAs(base As Bitmap, image As Bitmap) As Boolean - If base.Size <> image.Size Then Return False - - For y As Integer = 0 To base.Height - 1 - For x As Integer = 0 To base.Width - 1 - Dim p1 As Color = base.GetPixel(x, y) - Dim p2 As Color = image.GetPixel(x, y) - If p1 <> p2 Then Return False - Next - Next - - Return True - End Function - -End Module diff --git a/Pilz.Simple3DFileParser/Other/LoaderModule.cs b/Pilz.Simple3DFileParser/Other/LoaderModule.cs new file mode 100644 index 0000000..b856c49 --- /dev/null +++ b/Pilz.Simple3DFileParser/Other/LoaderModule.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using global::Assimp.Unmanaged; + +namespace Pilz.S3DFileParser +{ + public class File3DLoaderModule + { + public delegate Object3D LoaderAction(string fileName, LoaderOptions options); + + public delegate void ExporterAction(Object3D obj, string fileName); + + private static File3DLoaderModule[] _LoaderModules = null; + private static File3DLoaderModule[] _ExporterModules = null; + private readonly Delegate method = null; + + public string Name { get; private set; } + public IReadOnlyDictionary SupportedFormats { get; private set; } + + public File3DLoaderModule(string name, LoaderAction method, IReadOnlyDictionary supportedFormats) + { + Name = name; + this.method = method; + SupportedFormats = supportedFormats; + } + + public File3DLoaderModule(string name, ExporterAction method, IReadOnlyDictionary supportedFormats) + { + Name = name; + this.method = method; + SupportedFormats = supportedFormats; + } + + public Task InvokeAsync(Object3D obj, string fileName) + { + return Task.Run(() => Invoke(obj, fileName)); + } + + public void Invoke(Object3D obj, string fileName) + { + method.Method.Invoke(null, new object[] { obj, fileName }); + } + + public Task InvokeAsync(string fileName, LoaderOptions options) + { + return Task.Run(() => Invoke(fileName, options)); + } + + public Object3D Invoke(string fileName, LoaderOptions options) + { + return (Object3D)method.Method.Invoke(null, new object[] { fileName, options }); + } + + public static File3DLoaderModule[] LoaderModules + { + get + { + if (_LoaderModules is null) + { + _LoaderModules = GetLoaderModules(); + } + + return _LoaderModules; + } + } + + public static File3DLoaderModule[] ExporterModules + { + get + { + if (_ExporterModules is null) + { + _ExporterModules = GetExporterModules(); + } + + return _ExporterModules; + } + } + + private static File3DLoaderModule[] GetLoaderModules() + { + var list = new List(); + list.Add(new File3DLoaderModule("Simple File Parser", LoadViaSimpleFileParser, new Dictionary() { { "obj", "OBJ" } })); + AssimpModule.AssimpLoader.LoadAssimpLibs(); + var exts = new Dictionary(); + foreach (Assimp.ExportFormatDescription fd in AssimpLibrary.Instance.GetExportFormatDescriptions()) + { + if (!exts.ContainsKey(fd.FileExtension)) + { + exts.Add(fd.FileExtension, fd.FormatId + " - " + fd.Description); + } + } + + exts.Add("blend", "Blender"); + list.Add(new File3DLoaderModule("Assimp", LoadViaAssimp, exts)); + list.Add(new File3DLoaderModule("Aspose.3D", LoadViaAspose3D, new Dictionary() { { "obj", "OBJ" }, { "dae", "DAE" }, { "fbx", "FBX" }, { "stl", "STL" }, { "3ds", "3DS" }, { "3d", "3D" }, { "gltf", "glTF" }, { "drc", "DRC" }, { "rvm", "RVM" }, { "pdf", "PDF" }, { "x", "X" }, { "jt", "JT" }, { "dfx", "DFX" }, { "ply", "PLY" }, { "3mf", "3MF" }, { "ase", "ASE" } })); + return list.ToArray(); + } + + private static File3DLoaderModule[] GetExporterModules() + { + var list = new List(); + list.Add(new File3DLoaderModule("Simple File Parser", ExportViaSimpleFileParser, new Dictionary() { { "obj", "OBJ" } })); + AssimpModule.AssimpLoader.LoadAssimpLibs(); + var exts = new Dictionary(); + foreach (Assimp.ExportFormatDescription fd in AssimpLibrary.Instance.GetExportFormatDescriptions()) + { + if (!exts.ContainsKey(fd.FileExtension)) + exts.Add(fd.FileExtension, fd.FormatId + " - " + fd.Description); + } + + list.Add(new File3DLoaderModule("Assimp", ExportViaAssimp, exts)); + return list.ToArray(); + } + + private static Object3D LoadViaSimpleFileParser(string fileName, LoaderOptions options) + { + return ObjModule.ObjFile.FromFile(fileName, options.LoadMaterials, options.UpAxis); + } + + private static Object3D LoadViaAssimp(string fileName, LoaderOptions options) + { + AssimpModule.AssimpLoader.LoadAssimpLibs(); + return AssimpModule.AssimpLoader.FromFile(fileName, options.LoadMaterials, options.UpAxis); + } + + private static Object3D LoadViaAspose3D(string fileName, LoaderOptions options) + { + return Aspose3DModule.Aspose3DLoader.FromFile(fileName, options.LoadMaterials, options.UpAxis); + } + + private static void ExportViaSimpleFileParser(Object3D o, string fileName) + { + ObjModule.ObjFile.ToFile(fileName, o); + } + + private static void ExportViaAssimp(Object3D o, string fileName) + { + AssimpModule.AssimpLoader.LoadAssimpLibs(); + AssimpModule.AssimpLoader.ToFile(fileName, o); + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Other/LoaderModule.vb b/Pilz.Simple3DFileParser/Other/LoaderModule.vb deleted file mode 100644 index 620657f..0000000 --- a/Pilz.Simple3DFileParser/Other/LoaderModule.vb +++ /dev/null @@ -1,147 +0,0 @@ -Imports System.Reflection -Imports Assimp.Unmanaged - -Public Class File3DLoaderModule - - Public Delegate Function LoaderAction(fileName As String, options As LoaderOptions) As Object3D - Public Delegate Sub ExporterAction(obj As Object3D, fileName As String) - - Private Shared _LoaderModules As File3DLoaderModule() = Nothing - Private Shared _ExporterModules As File3DLoaderModule() = Nothing - - Private ReadOnly method As [Delegate] = Nothing - Public ReadOnly Property Name As String - Public ReadOnly Property SupportedFormats As IReadOnlyDictionary(Of String, String) - - Public Sub New(name As String, method As LoaderAction, supportedFormats As IReadOnlyDictionary(Of String, String)) - Me.Name = name - Me.method = method - Me.SupportedFormats = supportedFormats - End Sub - - Public Sub New(name As String, method As ExporterAction, supportedFormats As IReadOnlyDictionary(Of String, String)) - Me.Name = name - Me.method = method - Me.SupportedFormats = supportedFormats - End Sub - - Public Function InvokeAsync(obj As Object3D, fileName As String) As Task - Return Task.Run(Sub() Invoke(obj, fileName)) - End Function - - Public Sub Invoke(obj As Object3D, fileName As String) - method.Method.Invoke(Nothing, {obj, fileName}) - End Sub - - Public Function InvokeAsync(fileName As String, options As LoaderOptions) As Task(Of Object3D) - Return Task.Run(Function() Invoke(fileName, options)) - End Function - - Public Function Invoke(fileName As String, options As LoaderOptions) As Object3D - Return method.Method.Invoke(Nothing, {fileName, options}) - End Function - - Public Shared ReadOnly Property LoaderModules As File3DLoaderModule() - Get - If _LoaderModules Is Nothing Then - _LoaderModules = GetLoaderModules() - End If - Return _LoaderModules - End Get - End Property - - Public Shared ReadOnly Property ExporterModules As File3DLoaderModule() - Get - If _ExporterModules Is Nothing Then - _ExporterModules = GetExporterModules() - End If - Return _ExporterModules - End Get - End Property - - Private Shared Function GetLoaderModules() As File3DLoaderModule() - Dim list As New List(Of File3DLoaderModule) - - list.Add(New File3DLoaderModule("Simple File Parser", - AddressOf LoadViaSimpleFileParser, - New Dictionary(Of String, String) From {{"obj", "OBJ"}})) - - AssimpModule.AssimpLoader.LoadAssimpLibs() - Dim exts As New Dictionary(Of String, String) - For Each fd As Assimp.ExportFormatDescription In AssimpLibrary.Instance.GetExportFormatDescriptions - If Not exts.ContainsKey(fd.FileExtension) Then - exts.Add(fd.FileExtension, fd.FormatId & " - " & fd.Description) - End If - Next - exts.Add("blend", "Blender") - - list.Add(New File3DLoaderModule("Assimp", - AddressOf LoadViaAssimp, - exts)) - - list.Add(New File3DLoaderModule("Aspose.3D", - AddressOf LoadViaAspose3D, - New Dictionary(Of String, String) From { - {"obj", "OBJ"}, - {"dae", "DAE"}, - {"fbx", "FBX"}, - {"stl", "STL"}, - {"3ds", "3DS"}, - {"3d", "3D"}, - {"gltf", "glTF"}, - {"drc", "DRC"}, - {"rvm", "RVM"}, - {"pdf", "PDF"}, - {"x", "X"}, - {"jt", "JT"}, - {"dfx", "DFX"}, - {"ply", "PLY"}, - {"3mf", "3MF"}, - {"ase", "ASE"}})) - - Return list.ToArray - End Function - - Private Shared Function GetExporterModules() As File3DLoaderModule() - Dim list As New List(Of File3DLoaderModule) - - list.Add(New File3DLoaderModule("Simple File Parser", - AddressOf ExportViaSimpleFileParser, - New Dictionary(Of String, String) From {{"obj", "OBJ"}})) - - AssimpModule.AssimpLoader.LoadAssimpLibs() - Dim exts As New Dictionary(Of String, String) - For Each fd As Assimp.ExportFormatDescription In AssimpLibrary.Instance.GetExportFormatDescriptions - If Not exts.ContainsKey(fd.FileExtension) Then exts.Add(fd.FileExtension, fd.FormatId & " - " & fd.Description) - Next - - list.Add(New File3DLoaderModule("Assimp", - AddressOf ExportViaAssimp, - exts)) - - Return list.ToArray - End Function - - Private Shared Function LoadViaSimpleFileParser(fileName As String, options As LoaderOptions) As Object3D - Return ObjModule.ObjFile.FromFile(fileName, options.LoadMaterials, options.UpAxis) - End Function - - Private Shared Function LoadViaAssimp(fileName As String, options As LoaderOptions) As Object3D - AssimpModule.AssimpLoader.LoadAssimpLibs() - Return AssimpModule.AssimpLoader.FromFile(fileName, options.LoadMaterials, options.UpAxis) - End Function - - Private Shared Function LoadViaAspose3D(fileName As String, options As LoaderOptions) As Object3D - Return Aspose3DModule.Aspose3DLoader.FromFile(fileName, options.LoadMaterials, options.UpAxis) - End Function - - Private Shared Sub ExportViaSimpleFileParser(o As Object3D, fileName As String) - ObjModule.ObjFile.ToFile(fileName, o) - End Sub - - Private Shared Sub ExportViaAssimp(o As Object3D, fileName As String) - AssimpModule.AssimpLoader.LoadAssimpLibs() - AssimpModule.AssimpLoader.ToFile(fileName, o) - End Sub - -End Class diff --git a/Pilz.Simple3DFileParser/Other/LoaderOptions.cs b/Pilz.Simple3DFileParser/Other/LoaderOptions.cs new file mode 100644 index 0000000..95b922e --- /dev/null +++ b/Pilz.Simple3DFileParser/Other/LoaderOptions.cs @@ -0,0 +1,19 @@ + +namespace Pilz.S3DFileParser +{ + public class LoaderOptions + { + public bool LoadMaterials { get; set; } = false; + public UpAxis UpAxis { get; set; } = UpAxis.Y; + + public LoaderOptions() + { + } + + public LoaderOptions(bool loadMaterials, UpAxis upAxis) + { + LoadMaterials = loadMaterials; + UpAxis = upAxis; + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Other/LoaderOptions.vb b/Pilz.Simple3DFileParser/Other/LoaderOptions.vb deleted file mode 100644 index a41d785..0000000 --- a/Pilz.Simple3DFileParser/Other/LoaderOptions.vb +++ /dev/null @@ -1,14 +0,0 @@ -Public Class LoaderOptions - - Public Property LoadMaterials As Boolean = False - Public Property UpAxis As UpAxis = False - - Public Sub New() - End Sub - - Public Sub New(loadMaterials As Boolean, upAxis As UpAxis) - Me.LoadMaterials = loadMaterials - Me.UpAxis = upAxis - End Sub - -End Class diff --git a/Pilz.Simple3DFileParser/Pilz.Simple3DFileParser.vbproj b/Pilz.Simple3DFileParser/Pilz.Simple3DFileParser.csproj similarity index 68% rename from Pilz.Simple3DFileParser/Pilz.Simple3DFileParser.vbproj rename to Pilz.Simple3DFileParser/Pilz.Simple3DFileParser.csproj index ac93bf0..fc1b8cb 100644 --- a/Pilz.Simple3DFileParser/Pilz.Simple3DFileParser.vbproj +++ b/Pilz.Simple3DFileParser/Pilz.Simple3DFileParser.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {AC955819-7910-450C-940C-7C1989483D4B} + {1EB1D972-B548-0AFD-1654-B667EBDF09EB} Library @@ -16,6 +16,8 @@ + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest AnyCPU @@ -50,6 +52,7 @@ On + ..\Shared Libs\AssimpNet.dll @@ -82,59 +85,62 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.S3DFileParser.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.S3DFileParser.My + Settings.Designer.cs @@ -152,5 +158,5 @@ 4.5.0 - + \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Properties/Settings.Designer.cs b/Pilz.Simple3DFileParser/Properties/Settings.Designer.cs new file mode 100644 index 0000000..f148421 --- /dev/null +++ b/Pilz.Simple3DFileParser/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.S3DFileParser.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Simple3DFileParser/My Project/Settings.settings b/Pilz.Simple3DFileParser/Properties/Settings.settings similarity index 100% rename from Pilz.Simple3DFileParser/My Project/Settings.settings rename to Pilz.Simple3DFileParser/Properties/Settings.settings diff --git a/Pilz.Simple3DFileParser/Resources.Designer.cs b/Pilz.Simple3DFileParser/Resources.Designer.cs new file mode 100644 index 0000000..9f332a9 --- /dev/null +++ b/Pilz.Simple3DFileParser/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.S3DFileParser.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.S3DFileParser.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Simple3DFileParser/Resources.resx b/Pilz.Simple3DFileParser/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Simple3DFileParser/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.Threading/CrossThreadsInvokeing.cs b/Pilz.Threading/CrossThreadsInvokeing.cs new file mode 100644 index 0000000..0914b81 --- /dev/null +++ b/Pilz.Threading/CrossThreadsInvokeing.cs @@ -0,0 +1,78 @@ +// IDE-Voreinstellungen: +// Option Explicit On +// Option Strict On + +// "My Project"-Einstellungen: +// Imports Microsoft.VisualBasic.ControlChars +// Imports System.Windows.Forms +// Imports System + +using System; +using global::System.Windows.Forms; + +namespace Pilz.Threading +{ + + /// +/// Stellt Methoden bereit, mit denen ein beliebiger Methoden-Aufruf mit bis zu 3 Argumenten +/// in einen Nebenthread verlegt werden kann, bzw. aus einem Nebenthread in den Hauptthread +/// + public class CrossThreadsInvokeing + { + public static void RunAsync(Action Action, T1 Arg1, T2 Arg2, T3 Arg3) + { + Action.BeginInvoke(Arg1, Arg2, Arg3, Action.EndInvoke, null); + } + + public static void RunAsync(Action Action, T1 Arg1, T2 Arg2) + { + Action.BeginInvoke(Arg1, Arg2, Action.EndInvoke, null); + } + + public static void RunAsync(Action Action, T1 Arg1) + { + Action.BeginInvoke(Arg1, Action.EndInvoke, null); + } + + public static void RunAsync(Action Action) + { + Action.BeginInvoke(Action.EndInvoke, null); + } + + private static bool GuiCrossInvoke(Delegate Action, params object[] Args) + { + var frms = Application.OpenForms; + if (frms.Count > 0 && frms[0].InvokeRequired) + { + frms[0].BeginInvoke(Action, Args); + return true; + } + + return false; + } + + public static void RunGui(Action Action, T1 Arg1, T2 Arg2, T3 Arg3) + { + if (!GuiCrossInvoke(Action, Arg1, Arg2, Arg3)) + Action(Arg1, Arg2, Arg3); + } + + public static void RunGui(Action Action, T1 Arg1, T2 Arg2) + { + if (!GuiCrossInvoke(Action, Arg1, Arg2)) + Action(Arg1, Arg2); + } + + public static void RunGui(Action Action, T1 Arg1) + { + if (!GuiCrossInvoke(Action, (object)Arg1)) + Action(Arg1); + } + + public static void RunGui(Action Action) + { + if (!GuiCrossInvoke(Action)) + Action(); + } + } +} \ No newline at end of file diff --git a/Pilz.Threading/CrossThreadsInvokeing.vb b/Pilz.Threading/CrossThreadsInvokeing.vb deleted file mode 100644 index a43f643..0000000 --- a/Pilz.Threading/CrossThreadsInvokeing.vb +++ /dev/null @@ -1,61 +0,0 @@ -'IDE-Voreinstellungen: -'Option Explicit On -'Option Strict On - -'"My Project"-Einstellungen: -'Imports Microsoft.VisualBasic.ControlChars -'Imports System.Windows.Forms -'Imports System - -Imports System.Windows.Forms - -''' -''' Stellt Methoden bereit, mit denen ein beliebiger Methoden-Aufruf mit bis zu 3 Argumenten -''' in einen Nebenthread verlegt werden kann, bzw. aus einem Nebenthread in den Hauptthread -''' -Public Class CrossThreadsInvokeing - - Public Shared Sub RunAsync(Of T1, T2, T3)(ByVal Action As Action(Of T1, T2, T3), ByVal Arg1 As T1, ByVal Arg2 As T2, ByVal Arg3 As T3) - Action.BeginInvoke(Arg1, Arg2, Arg3, AddressOf Action.EndInvoke, Nothing) - End Sub - - Public Shared Sub RunAsync(Of T1, T2)(ByVal Action As Action(Of T1, T2), ByVal Arg1 As T1, ByVal Arg2 As T2) - Action.BeginInvoke(Arg1, Arg2, AddressOf Action.EndInvoke, Nothing) - End Sub - - Public Shared Sub RunAsync(Of T1)(ByVal Action As Action(Of T1), ByVal Arg1 As T1) - Action.BeginInvoke(Arg1, AddressOf Action.EndInvoke, Nothing) - End Sub - - Public Shared Sub RunAsync(ByVal Action As Action) - Action.BeginInvoke(AddressOf Action.EndInvoke, Nothing) - End Sub - - Private Shared Function GuiCrossInvoke(ByVal Action As [Delegate], ByVal ParamArray Args() As Object) As Boolean - Dim frms As FormCollection = Application.OpenForms - - If frms.Count > 0 AndAlso frms(0).InvokeRequired Then - frms(0).BeginInvoke(Action, Args) - Return True - End If - - Return False - End Function - - Public Shared Sub RunGui(Of T1, T2, T3)(ByVal Action As Action(Of T1, T2, T3), ByVal Arg1 As T1, ByVal Arg2 As T2, ByVal Arg3 As T3) - If Not GuiCrossInvoke(Action, Arg1, Arg2, Arg3) Then Action(Arg1, Arg2, Arg3) - End Sub - - Public Shared Sub RunGui(Of T1, T2)(ByVal Action As Action(Of T1, T2), ByVal Arg1 As T1, ByVal Arg2 As T2) - If Not GuiCrossInvoke(Action, Arg1, Arg2) Then Action(Arg1, Arg2) - End Sub - - Public Shared Sub RunGui(Of T1)(ByVal Action As Action(Of T1), ByVal Arg1 As T1) - If Not GuiCrossInvoke(Action, Arg1) Then Action(Arg1) - End Sub - - Public Shared Sub RunGui(ByVal Action As Action) - If Not GuiCrossInvoke(Action) Then Action() - End Sub - -End Class diff --git a/Pilz.Threading/My Project/Application.Designer.cs b/Pilz.Threading/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Threading/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Threading/My Project/Application.Designer.vb b/Pilz.Threading/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Threading/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Threading/My Project/AssemblyInfo.vb b/Pilz.Threading/My Project/AssemblyInfo.vb deleted file mode 100644 index 4418d63..0000000 --- a/Pilz.Threading/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Threading/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Threading/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..ec67ff7 --- /dev/null +++ b/Pilz.Threading/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Threading.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Threading/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Threading/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..e2305e3 --- /dev/null +++ b/Pilz.Threading/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Threading.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Threading/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Threading/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Threading/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Threading/My Project/Resources.Designer.vb b/Pilz.Threading/My Project/Resources.Designer.vb deleted file mode 100644 index cd77810..0000000 --- a/Pilz.Threading/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Threading.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Threading/My Project/Settings.Designer.vb b/Pilz.Threading/My Project/Settings.Designer.vb deleted file mode 100644 index 6a2281a..0000000 --- a/Pilz.Threading/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Threading.My.MySettings - Get - Return Global.Pilz.Threading.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Threading/Pilz.Threading.vbproj b/Pilz.Threading/Pilz.Threading.csproj similarity index 78% rename from Pilz.Threading/Pilz.Threading.vbproj rename to Pilz.Threading/Pilz.Threading.csproj index 6d1863c..96c6af7 100644 --- a/Pilz.Threading/Pilz.Threading.vbproj +++ b/Pilz.Threading/Pilz.Threading.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB} + {6BECE435-8344-0CB9-2744-617E9F0D201B} Library Pilz.Threading Pilz.Threading @@ -13,6 +13,8 @@ v4.7.2 true + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -67,6 +69,7 @@ MinimumRecommendedRules.ruleset + @@ -88,41 +91,44 @@ - - - + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Threading.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Threading.My + Settings.Designer.cs - + \ No newline at end of file diff --git a/Pilz.Threading/Properties/AssemblyInfo.cs b/Pilz.Threading/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..21b1897 --- /dev/null +++ b/Pilz.Threading/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("CrossThreads")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("DRSN")] +[assembly: AssemblyProduct("CrossThreads")] +[assembly: AssemblyCopyright("Copyright © DRSN 2018")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("ff2262d0-23fc-4536-b691-e99a23942f73")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Threading/Properties/Settings.Designer.cs b/Pilz.Threading/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3165636 --- /dev/null +++ b/Pilz.Threading/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Threading.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Threading/My Project/Settings.settings b/Pilz.Threading/Properties/Settings.settings similarity index 100% rename from Pilz.Threading/My Project/Settings.settings rename to Pilz.Threading/Properties/Settings.settings diff --git a/Pilz.Threading/Resources.Designer.cs b/Pilz.Threading/Resources.Designer.cs new file mode 100644 index 0000000..041c923 --- /dev/null +++ b/Pilz.Threading/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Threading.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Threading.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Threading/Resources.resx b/Pilz.Threading/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Threading/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.UI/My Project/Application.Designer.cs b/Pilz.UI/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.UI/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.UI/My Project/Application.Designer.vb b/Pilz.UI/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.UI/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.UI/My Project/AssemblyInfo.vb b/Pilz.UI/My Project/AssemblyInfo.vb deleted file mode 100644 index 31f117b..0000000 --- a/Pilz.UI/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.UI/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.UI/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..720dbe5 --- /dev/null +++ b/Pilz.UI/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.UI.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.UI/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.UI/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..f8e799c --- /dev/null +++ b/Pilz.UI/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.UI.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.UI/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.UI/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.UI/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.UI/My Project/Resources.Designer.vb b/Pilz.UI/My Project/Resources.Designer.vb deleted file mode 100644 index b6cfcb8..0000000 --- a/Pilz.UI/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.UI.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.UI/My Project/Settings.Designer.vb b/Pilz.UI/My Project/Settings.Designer.vb deleted file mode 100644 index d282691..0000000 --- a/Pilz.UI/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.UI.My.MySettings - Get - Return Global.Pilz.UI.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.UI/PaintingControl/DefaultDrawMethodes.cs b/Pilz.UI/PaintingControl/DefaultDrawMethodes.cs new file mode 100644 index 0000000..2facec4 --- /dev/null +++ b/Pilz.UI/PaintingControl/DefaultDrawMethodes.cs @@ -0,0 +1,263 @@ +using System; +using global::System.Drawing; +using global::System.Drawing.Drawing2D; +using global::System.Windows.Forms; +using global::Pilz.Drawing; + +namespace Pilz.UI +{ + + /// +/// Contains static methods that are used for the standart PaintingObject Types. +/// + public class DefaultDrawMethodes + { + public static void DrawText(PaintingObjectPaintEventArgs e) + { + var obj = e.PaintingObject; + var b = new SolidBrush(obj.TextColor); + var p = new PointF(); + var rect = new Rectangle((int)e.X, (int)e.Y, (int)obj.Width, (int)obj.Height); + var f = StringFormat.GenericDefault; + f.Alignment = obj.HorizontalTextAlignment; + f.LineAlignment = obj.VerticalTextAlignment; + float zoomFactor; + if (obj.Parent is null) + { + zoomFactor = 1.0f; + } + else + { + zoomFactor = obj.Parent.ZoomFactor.Width; + } + + e.Graphics.DrawString(obj.Text, new Font(obj.TextFont.FontFamily, obj.TextFont.Size * zoomFactor, obj.TextFont.Style), b, rect, f); + } + + private static object drawPicture_NewSyncObject = new object(); + public static void DrawPicture(PaintingObjectPaintEventArgs e) + { + var obj = e.PaintingObject; + Image objImg; + Size objImgSize; + RectangleF result; + Bitmap image; + SizeF zoomf; + bool hasNoParent = e.PaintingObject.Parent is null; + object syncObj; + if (hasNoParent) + { + zoomf = new SizeF(1f, 1f); + syncObj = drawPicture_NewSyncObject; + } + else + { + zoomf = e.PaintingObject.Parent.ZoomFactor; + syncObj = e.PaintingObject.Parent; + } + + lock (syncObj) + { + if (obj?.Image is null) + return; + objImg = obj.Image; + objImgSize = objImg.Size; + } + + image = (Bitmap)obj.BufferedImage; + result = CalculateImageResolution(obj, objImgSize, zoomf); + if (obj.ImageProperties.Rotate == 90 || obj.ImageProperties.Rotate == 270) + { + result = CalculateImageResolution(obj, new SizeF(objImgSize.Height, objImgSize.Width), zoomf); + } + + if (image is null) + { + bool needRescaleImageBecauseRot = false; + image = DrawToNewImage((Bitmap)objImg, result.Size); + switch (obj.ImageProperties.Rotate) + { + case 90: + { + image.RotateFlip(RotateFlipType.Rotate90FlipNone); + needRescaleImageBecauseRot = true; + break; + } + + case 180: + { + image.RotateFlip(RotateFlipType.Rotate180FlipNone); + break; + } + + case 270: + { + image.RotateFlip(RotateFlipType.Rotate270FlipNone); + needRescaleImageBecauseRot = true; + break; + } + } + + if (obj.ImageProperties.FlipX) + { + image.RotateFlip(RotateFlipType.RotateNoneFlipX); + } + + if (obj.ImageProperties.FlipY) + { + image.RotateFlip(RotateFlipType.RotateNoneFlipY); + } + + if (needRescaleImageBecauseRot) + { + result = CalculateImageResolution(obj, new SizeF(objImgSize.Height, objImgSize.Width), zoomf); + image = DrawToNewImage(image, result.Size); + } + + obj.BufferedImage = image; + } + + if (image is object) + { + lock (syncObj) + e.Graphics.DrawImageUnscaled(image, new Rectangle(new Point((int)(obj.Location.X + result.Location.X - e.Offset.X), (int)(obj.Location.Y + result.Location.Y - e.Offset.Y)), result.Size.ToSize())); + } + } + + private static Bitmap DrawToNewImage(Bitmap image, SizeF newSize) + { + var bmp = new Bitmap((int)(newSize.Width < 0f ? newSize.Width * -1 : newSize.Width), (int)(newSize.Height < 0f ? newSize.Height * -1 : newSize.Height)); + var gimage = Graphics.FromImage(bmp); + gimage.SmoothingMode = SmoothingMode.HighQuality; + gimage.PixelOffsetMode = PixelOffsetMode.HighQuality; + gimage.PageUnit = GraphicsUnit.Pixel; + gimage.InterpolationMode = InterpolationMode.HighQualityBicubic; + gimage.DrawImage(image, new RectangleF(PointF.Empty, newSize)); + gimage.Dispose(); + return bmp; + } + + public static void DrawLine(PaintingObjectPaintEventArgs e) + { + var obj = e.PaintingObject; + var p2 = new Pen(obj.OutlineColor, obj.OutlineThicknes) { DashStyle = obj.OutlineDashStyle }; + p2.Alignment = PenAlignment.Center; + var no = new PointF(e.X, e.Y); + e.Graphics.DrawLine(p2, no, no + obj.Size); + } + + private static RectangleF CalculateImageResolution(PaintingObject obj, SizeF imageSize, SizeF zoom) + { + var result = new RectangleF(); + var objrect = new RectangleF(obj.Location, obj.Size); + var size = new SizeF(imageSize.Width * zoom.Width, imageSize.Height * zoom.Height); + var clientRectangle = objrect; + float val = clientRectangle.Width / size.Width; + clientRectangle = objrect; + float num = Math.Min(val, clientRectangle.Height / size.Height); + result.Width = (int)Math.Truncate(size.Width * num); + result.Height = (int)Math.Truncate(size.Height * num); + clientRectangle = objrect; + result.X = (long)(clientRectangle.Width - result.Width) / 2L; + clientRectangle = objrect; + result.Y = (long)(clientRectangle.Height - result.Height) / 2L; + return result; + } + + public static void DrawTriangle(PaintingObjectPaintEventArgs e) + { + var obj = e.PaintingObject; + var p1 = new Point((int)(obj.Size.Width / 2f + e.X), (int)e.Y); + var p2 = new Point((int)e.X, (int)(e.Y + obj.Size.Height)); + var p3 = new Point((int)(e.X + obj.Size.Width), (int)(e.Y + obj.Size.Height)); + if (obj.EnableFill) + { + var b = new SolidBrush(obj.FillColor); + e.Graphics.FillPolygon(b, new[] { p1, p2, p3 }); + } + + if (obj.EnableOutline) + { + float lw = obj.OutlineThicknes; + var p = new Pen(obj.OutlineColor, obj.OutlineThicknes) { DashStyle = obj.OutlineDashStyle, Alignment = PenAlignment.Inset }; + e.Graphics.DrawPolygon(p, new[] { p1, p2, p3 }); + } + } + + public static void DrawRectangle(PaintingObjectPaintEventArgs e) + { + var obj = e.PaintingObject; + float hol = obj.OutlineThicknes / 2f; + if (obj.EnableFill) + { + var b = new SolidBrush(obj.FillColor); + var rect = obj.EnableOutline ? new Rectangle((int)(e.X + hol), (int)(e.Y + hol), (int)(obj.Size.Width - hol * 2f), (int)(obj.Size.Height - hol * 2f)) : new Rectangle((int)e.X, (int)e.Y, (int)obj.Size.Width, (int)obj.Size.Height); + e.Graphics.FillRectangle(b, rect); + } + + if (obj.EnableOutline) + { + var p = new Pen(obj.OutlineColor, obj.OutlineThicknes) { DashStyle = obj.OutlineDashStyle, Alignment = PenAlignment.Inset }; + var rect = new Rectangle((int)e.X, (int)e.Y, (int)obj.Size.Width, (int)obj.Size.Height); + e.Graphics.DrawRectangle(p, rect); + } + } + + public static void DrawEllipse(PaintingObjectPaintEventArgs e) + { + var obj = e.PaintingObject; + if (obj.EnableFill) + { + var b = new SolidBrush(obj.FillColor); + var rect = new Rectangle((int)e.X, (int)e.Y, (int)obj.Size.Width, (int)obj.Size.Height); + e.Graphics.FillEllipse(b, rect); + } + + if (obj.EnableOutline) + { + var p = new Pen(obj.OutlineColor, obj.OutlineThicknes) { DashStyle = obj.OutlineDashStyle, Alignment = PenAlignment.Inset }; + var rect = new Rectangle((int)e.X, (int)e.Y, (int)obj.Size.Width, (int)obj.Size.Height); + e.Graphics.DrawEllipse(p, rect); + } + } + + public static void DrawSelection(PaintingObjectPaintEventArgs e) + { + var obj = e.PaintingObject; + float lw = 2.5f; + float hlw = lw / 2f; + float hlwphol = hlw; // + hol + float hlwpholm2 = hlwphol * 2f; + var p = new Pen(Color.CornflowerBlue, lw) { DashStyle = obj.SelectionDashStyle, Alignment = PenAlignment.Outset }; + var rect = new Rectangle((int)(e.X - hlwphol), (int)(e.Y - hlwphol), (int)(obj.Size.Width + hlwpholm2), (int)(obj.Size.Height + hlwpholm2)); + e.Graphics.DrawRectangle(p, rect); + } + + public static void DrawGrid(PaintEventArgs e, PaintingControl pc, PointF offset) + { + var p = new Pen(pc.GridColor, 0.5f); + int curX = (int)(pc.GridChunkSize.Width * pc.ZoomFactor.Width - offset.X); + while (curX < pc.Width) + { + e.Graphics.DrawLine(p, curX, -offset.Y, curX, pc.Height); + curX = (int)(curX + pc.GridChunkSize.Width * pc.ZoomFactor.Width); + } + + int curY = (int)(pc.GridChunkSize.Height * pc.ZoomFactor.Height - offset.Y); + while (curY < pc.Height) + { + e.Graphics.DrawLine(p, -offset.X, curY, pc.Width, curY); + curY = (int)(curY + pc.GridChunkSize.Height * pc.ZoomFactor.Height); + } + } + + public static void DrawAreaSelection(PaintEventArgs e, PaintingControl pc, PointF startMousePos, PointF lastMousePos) + { + var rectToDraw = HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos); + var p = new Pen(pc.AreaSelectionColor); + p.DashStyle = startMousePos.X >= lastMousePos.X ? DashStyle.DashDot : DashStyle.Solid; + p.Width = 3f; + e.Graphics.DrawRectangle(p, rectToDraw.X, rectToDraw.Y, rectToDraw.Width, rectToDraw.Height); + } + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb b/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb deleted file mode 100644 index b802cb7..0000000 --- a/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb +++ /dev/null @@ -1,233 +0,0 @@ -Imports System.Drawing -Imports System.Drawing.Drawing2D -Imports System.Windows.Forms -Imports Pilz.Drawing - -''' -''' Contains static methods that are used for the standart PaintingObject Types. -''' -Public Class DefaultDrawMethodes - - Public Shared Sub DrawText(e As PaintingObjectPaintEventArgs) - Dim obj As PaintingObject = e.PaintingObject - Dim b As New SolidBrush(obj.TextColor) - Dim p As New PointF - Dim rect As New Rectangle(e.X, e.Y, obj.Width, obj.Height) - - Dim f As StringFormat = StringFormat.GenericDefault - f.Alignment = obj.HorizontalTextAlignment - f.LineAlignment = obj.VerticalTextAlignment - - Dim zoomFactor As Single - If obj.Parent Is Nothing Then - zoomFactor = 1.0! - Else - zoomFactor = obj.Parent.ZoomFactor.Width - End If - - e.Graphics.DrawString(obj.Text, New Font(obj.TextFont.FontFamily, obj.TextFont.Size * zoomFactor, obj.TextFont.Style), b, rect, f) - End Sub - - Public Shared Sub DrawPicture(e As PaintingObjectPaintEventArgs) - Dim obj As PaintingObject = e.PaintingObject - Dim objImg As Image - Dim objImgSize As Size - Dim result As RectangleF - Dim image As Bitmap - Dim zoomf As SizeF - Dim hasNoParent As Boolean = e.PaintingObject.Parent Is Nothing - Dim syncObj As Object - - If hasNoParent Then - zoomf = New SizeF(1, 1) - Static newSyncObj As New Object - syncObj = newSyncObj - Else - zoomf = e.PaintingObject.Parent.ZoomFactor - syncObj = e.PaintingObject.Parent - End If - - SyncLock syncObj - If obj?.Image Is Nothing Then Return - objImg = obj.Image - objImgSize = objImg.Size - End SyncLock - - image = obj.BufferedImage - result = CalculateImageResolution(obj, objImgSize, zoomf) - - If obj.ImageProperties.Rotate = 90 OrElse obj.ImageProperties.Rotate = 270 Then - result = CalculateImageResolution(obj, New SizeF(objImgSize.Height, objImgSize.Width), zoomf) - End If - - If image Is Nothing Then - Dim needRescaleImageBecauseRot As Boolean = False - - image = DrawToNewImage(objImg, result.Size) - - Select Case obj.ImageProperties.Rotate - Case 90 - image.RotateFlip(RotateFlipType.Rotate90FlipNone) - needRescaleImageBecauseRot = True - Case 180 - image.RotateFlip(RotateFlipType.Rotate180FlipNone) - Case 270 - image.RotateFlip(RotateFlipType.Rotate270FlipNone) - needRescaleImageBecauseRot = True - End Select - If obj.ImageProperties.FlipX Then - image.RotateFlip(RotateFlipType.RotateNoneFlipX) - End If - If obj.ImageProperties.FlipY Then - image.RotateFlip(RotateFlipType.RotateNoneFlipY) - End If - - If needRescaleImageBecauseRot Then - result = CalculateImageResolution(obj, New SizeF(objImgSize.Height, objImgSize.Width), zoomf) - image = DrawToNewImage(image, result.Size) - End If - - obj.BufferedImage = image - End If - - If image IsNot Nothing Then - SyncLock syncObj - e.Graphics.DrawImageUnscaled(image, New Rectangle(New Point(obj.Location.X + result.Location.X - e.Offset.X, obj.Location.Y + result.Location.Y - e.Offset.Y), result.Size.ToSize)) - End SyncLock - End If - End Sub - - Private Shared Function DrawToNewImage(image As Bitmap, newSize As SizeF) As Bitmap - Dim bmp As New Bitmap(CInt(If(newSize.Width < 0, newSize.Width * -1, newSize.Width)), - CInt(If(newSize.Height < 0, newSize.Height * -1, newSize.Height))) - Dim gimage As Graphics = Graphics.FromImage(bmp) - gimage.SmoothingMode = SmoothingMode.HighQuality - gimage.PixelOffsetMode = PixelOffsetMode.HighQuality - gimage.PageUnit = GraphicsUnit.Pixel - gimage.InterpolationMode = InterpolationMode.HighQualityBicubic - gimage.DrawImage(image, New RectangleF(PointF.Empty, newSize)) - gimage.Dispose() - Return bmp - End Function - - Public Shared Sub DrawLine(e As PaintingObjectPaintEventArgs) - Dim obj As PaintingObject = e.PaintingObject - Dim p2 As New Pen(obj.OutlineColor, obj.OutlineThicknes) With {.DashStyle = obj.OutlineDashStyle} - p2.Alignment = PenAlignment.Center - Dim no As PointF = New PointF(e.X, e.Y) - e.Graphics.DrawLine(p2, no, no + obj.Size) - End Sub - - Private Shared Function CalculateImageResolution(obj As PaintingObject, imageSize As SizeF, zoom As SizeF) As RectangleF - Dim result As New RectangleF - Dim objrect As New RectangleF(obj.Location, obj.Size) - Dim size As SizeF = New SizeF(imageSize.Width * zoom.Width, imageSize.Height * zoom.Height) - Dim clientRectangle As RectangleF = objrect - Dim val As Single = clientRectangle.Width / size.Width - - clientRectangle = objrect - Dim num As Single = Math.Min(val, clientRectangle.Height / size.Height) - - result.Width = CInt(Math.Truncate(size.Width * num)) - result.Height = CInt(Math.Truncate(size.Height * num)) - - clientRectangle = objrect - result.X = (clientRectangle.Width - result.Width) \ 2 - - clientRectangle = objrect - result.Y = (clientRectangle.Height - result.Height) \ 2 - - Return result - End Function - - Public Shared Sub DrawTriangle(e As PaintingObjectPaintEventArgs) - Dim obj As PaintingObject = e.PaintingObject - - Dim p1 As New Point(obj.Size.Width / 2 + e.X, e.Y) - Dim p2 As New Point(e.X, e.Y + obj.Size.Height) - Dim p3 As New Point(e.X + obj.Size.Width, e.Y + obj.Size.Height) - - If obj.EnableFill Then - Dim b As New SolidBrush(obj.FillColor) - e.Graphics.FillPolygon(b, {p1, p2, p3}) - End If - - If obj.EnableOutline Then - Dim lw As Single = obj.OutlineThicknes - Dim p As New Pen(obj.OutlineColor, obj.OutlineThicknes) With {.DashStyle = obj.OutlineDashStyle, .Alignment = PenAlignment.Inset} - e.Graphics.DrawPolygon(p, {p1, p2, p3}) - End If - End Sub - - Public Shared Sub DrawRectangle(e As PaintingObjectPaintEventArgs) - Dim obj As PaintingObject = e.PaintingObject - Dim hol As Single = obj.OutlineThicknes / 2 - - If obj.EnableFill Then - Dim b As New SolidBrush(obj.FillColor) - Dim rect As Rectangle = If(obj.EnableOutline, - New Rectangle(e.X + hol, e.Y + hol, obj.Size.Width - hol * 2, obj.Size.Height - hol * 2), - New Rectangle(e.X, e.Y, obj.Size.Width, obj.Size.Height)) - e.Graphics.FillRectangle(b, rect) - End If - - If obj.EnableOutline Then - Dim p As New Pen(obj.OutlineColor, obj.OutlineThicknes) With {.DashStyle = obj.OutlineDashStyle, .Alignment = PenAlignment.Inset} - Dim rect As New Rectangle(e.X, e.Y, obj.Size.Width, obj.Size.Height) - e.Graphics.DrawRectangle(p, rect) - End If - End Sub - - Public Shared Sub DrawEllipse(e As PaintingObjectPaintEventArgs) - Dim obj As PaintingObject = e.PaintingObject - - If obj.EnableFill Then - Dim b As New SolidBrush(obj.FillColor) - Dim rect As Rectangle = New Rectangle(e.X, e.Y, obj.Size.Width, obj.Size.Height) - e.Graphics.FillEllipse(b, rect) - End If - - If obj.EnableOutline Then - Dim p As New Pen(obj.OutlineColor, obj.OutlineThicknes) With {.DashStyle = obj.OutlineDashStyle, .Alignment = PenAlignment.Inset} - Dim rect As New Rectangle(e.X, e.Y, obj.Size.Width, obj.Size.Height) - e.Graphics.DrawEllipse(p, rect) - End If - End Sub - - Public Shared Sub DrawSelection(e As PaintingObjectPaintEventArgs) - Dim obj As PaintingObject = e.PaintingObject - Dim lw As Single = 2.5! - Dim hlw As Single = lw / 2 - Dim hlwphol As Single = hlw '+ hol - Dim hlwpholm2 As Single = hlwphol * 2 - - Dim p As New Pen(Color.CornflowerBlue, lw) With {.DashStyle = obj.SelectionDashStyle, .Alignment = PenAlignment.Outset} - Dim rect As New Rectangle(e.X - hlwphol, e.Y - hlwphol, obj.Size.Width + hlwpholm2, obj.Size.Height + hlwpholm2) - e.Graphics.DrawRectangle(p, rect) - End Sub - - Public Shared Sub DrawGrid(e As PaintEventArgs, pc As PaintingControl, offset As PointF) - Dim p As New Pen(pc.GridColor, 0.5) - - Dim curX As Integer = pc.GridChunkSize.Width * pc.ZoomFactor.Width - offset.X - Do While curX < pc.Width - e.Graphics.DrawLine(p, curX, -offset.Y, curX, pc.Height) - curX += (pc.GridChunkSize.Width * pc.ZoomFactor.Width) - Loop - - Dim curY As Integer = pc.GridChunkSize.Height * pc.ZoomFactor.Height - offset.Y - Do While curY < pc.Height - e.Graphics.DrawLine(p, -offset.X, curY, pc.Width, curY) - curY += (pc.GridChunkSize.Height * pc.ZoomFactor.Height) - Loop - End Sub - - Public Shared Sub DrawAreaSelection(e As PaintEventArgs, pc As PaintingControl, startMousePos As PointF, lastMousePos As PointF) - Dim rectToDraw As RectangleF = HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos) - Dim p As New Pen(pc.AreaSelectionColor) - p.DashStyle = If(startMousePos.X >= lastMousePos.X, DashStyle.DashDot, DashStyle.Solid) - p.Width = 3 - e.Graphics.DrawRectangle(p, rectToDraw.X, rectToDraw.Y, rectToDraw.Width, rectToDraw.Height) - End Sub - -End Class diff --git a/Pilz.UI/PaintingControl/EventArgs/PaintingObjectEventArgs.cs b/Pilz.UI/PaintingControl/EventArgs/PaintingObjectEventArgs.cs new file mode 100644 index 0000000..4715c70 --- /dev/null +++ b/Pilz.UI/PaintingControl/EventArgs/PaintingObjectEventArgs.cs @@ -0,0 +1,14 @@ +using System; + +namespace Pilz.UI +{ + public class PaintingObjectEventArgs : EventArgs + { + public PaintingObject[] PaintingObjects { get; private set; } = null; + + internal PaintingObjectEventArgs(PaintingObject[] paintingObjects) + { + PaintingObjects = paintingObjects; + } + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/EventArgs/PaintingObjectEventArgs.vb b/Pilz.UI/PaintingControl/EventArgs/PaintingObjectEventArgs.vb deleted file mode 100644 index ef5c14b..0000000 --- a/Pilz.UI/PaintingControl/EventArgs/PaintingObjectEventArgs.vb +++ /dev/null @@ -1,16 +0,0 @@ -Imports System.Drawing -Imports System.IO -Imports System.Windows.Forms -Imports Newtonsoft.Json -Imports Newtonsoft.Json.Linq - -Public Class PaintingObjectEventArgs - Inherits EventArgs - - Public ReadOnly Property PaintingObjects As PaintingObject() = Nothing - - Friend Sub New(paintingObjects As PaintingObject()) - _PaintingObjects = paintingObjects - End Sub - -End Class diff --git a/Pilz.UI/PaintingControl/EventArgs/PaintingObjectPaintEventArgs.cs b/Pilz.UI/PaintingControl/EventArgs/PaintingObjectPaintEventArgs.cs new file mode 100644 index 0000000..dcbb3a0 --- /dev/null +++ b/Pilz.UI/PaintingControl/EventArgs/PaintingObjectPaintEventArgs.cs @@ -0,0 +1,86 @@ +using System; +using global::System.Drawing; + +namespace Pilz.UI +{ + public class PaintingObjectPaintEventArgs : EventArgs + { + + /// + /// The Painting Object to draw. + /// + /// + public PaintingObject PaintingObject { get; private set; } + + /// + /// The current offset of the page on the screen. + /// + /// + public PointF Offset { get; private set; } + + /// + /// The Grpahics from the parent PaintingControl. + /// + /// + public Graphics Graphics { get; private set; } + + /// + /// The position of the PaintingObject on Screen. + /// + /// + public PointF Location + { + get + { + return new PointF(X, Y); + } + } + + /// + /// The X position of the PaintingObject on Screen. + /// + /// + public float X + { + get + { + return PaintingObject.X - Offset.X; + } + } + + /// + /// The Y position of the PaintingObject on Screen. + /// + /// + public float Y + { + get + { + return PaintingObject.Y - Offset.Y; + } + } + + /// + /// The rectangle of the PaintingObject on Screen. + /// + /// + public RectangleF Rectangle + { + get + { + return new RectangleF(X, Y, PaintingObject.Width, PaintingObject.Height); + } + } + + internal PaintingObjectPaintEventArgs(PaintingObject obj, Graphics g) : this(obj, g, obj.Parent.Offset) + { + } + + internal PaintingObjectPaintEventArgs(PaintingObject obj, Graphics g, PointF offset) + { + PaintingObject = obj; + Offset = offset; + Graphics = g; + } + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/EventArgs/PaintingObjectPaintEventArgs.vb b/Pilz.UI/PaintingControl/EventArgs/PaintingObjectPaintEventArgs.vb deleted file mode 100644 index aaca912..0000000 --- a/Pilz.UI/PaintingControl/EventArgs/PaintingObjectPaintEventArgs.vb +++ /dev/null @@ -1,78 +0,0 @@ -Imports System.Drawing -Imports System.IO -Imports System.Windows.Forms -Imports Newtonsoft.Json -Imports Newtonsoft.Json.Linq - -Public Class PaintingObjectPaintEventArgs - Inherits EventArgs - - ''' - ''' The Painting Object to draw. - ''' - ''' - Public ReadOnly Property PaintingObject As PaintingObject - - ''' - ''' The current offset of the page on the screen. - ''' - ''' - Public ReadOnly Property Offset As PointF - - ''' - ''' The Grpahics from the parent PaintingControl. - ''' - ''' - Public ReadOnly Property Graphics As Graphics - - ''' - ''' The position of the PaintingObject on Screen. - ''' - ''' - Public ReadOnly Property Location As PointF - Get - Return New PointF(X, Y) - End Get - End Property - - ''' - ''' The X position of the PaintingObject on Screen. - ''' - ''' - Public ReadOnly Property X As Single - Get - Return PaintingObject.X - Offset.X - End Get - End Property - - ''' - ''' The Y position of the PaintingObject on Screen. - ''' - ''' - Public ReadOnly Property Y As Single - Get - Return PaintingObject.Y - Offset.Y - End Get - End Property - - ''' - ''' The rectangle of the PaintingObject on Screen. - ''' - ''' - Public ReadOnly Property Rectangle As RectangleF - Get - Return New RectangleF(X, Y, PaintingObject.Width, PaintingObject.Height) - End Get - End Property - - Friend Sub New(obj As PaintingObject, g As Graphics) - Me.New(obj, g, obj.Parent.Offset) - End Sub - - Friend Sub New(obj As PaintingObject, g As Graphics, offset As PointF) - PaintingObject = obj - Me.Offset = offset - Graphics = g - End Sub - -End Class diff --git a/Pilz.UI/PaintingControl/IPaintingObjectContainer.cs b/Pilz.UI/PaintingControl/IPaintingObjectContainer.cs new file mode 100644 index 0000000..03b9994 --- /dev/null +++ b/Pilz.UI/PaintingControl/IPaintingObjectContainer.cs @@ -0,0 +1,7 @@ + +namespace Pilz.UI +{ + public interface IPaintingObjectContainer + { + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/IPaintingObjectContainer.vb b/Pilz.UI/PaintingControl/IPaintingObjectContainer.vb deleted file mode 100644 index 6909c7d..0000000 --- a/Pilz.UI/PaintingControl/IPaintingObjectContainer.vb +++ /dev/null @@ -1,5 +0,0 @@ -Imports System.Drawing - -Public Interface IPaintingObjectContainer - -End Interface diff --git a/Pilz.UI/PaintingControl/ImageProperties.cs b/Pilz.UI/PaintingControl/ImageProperties.cs new file mode 100644 index 0000000..083ff8d --- /dev/null +++ b/Pilz.UI/PaintingControl/ImageProperties.cs @@ -0,0 +1,10 @@ + +namespace Pilz.UI +{ + public class PaintingObjectImageProperties + { + public bool FlipY { get; set; } = false; + public bool FlipX { get; set; } = false; + public ushort Rotate { get; set; } = 0; + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/ImageProperties.vb b/Pilz.UI/PaintingControl/ImageProperties.vb deleted file mode 100644 index b572234..0000000 --- a/Pilz.UI/PaintingControl/ImageProperties.vb +++ /dev/null @@ -1,5 +0,0 @@ -Public Class PaintingObjectImageProperties - Public Property FlipY As Boolean = False - Public Property FlipX As Boolean = False - Public Property Rotate As UShort = 0 -End Class diff --git a/Pilz.UI/PaintingControl/PaintingControl.cs b/Pilz.UI/PaintingControl/PaintingControl.cs new file mode 100644 index 0000000..e994c58 --- /dev/null +++ b/Pilz.UI/PaintingControl/PaintingControl.cs @@ -0,0 +1,833 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using global::System.ComponentModel; +using System.Data; +using global::System.Drawing; +using global::System.Drawing.Drawing2D; +using System.Linq; +using global::System.Windows.Forms; +using Microsoft.VisualBasic.CompilerServices; +using global::Pilz.Drawing; + +namespace Pilz.UI +{ + public class PaintingControl : UserControl, IPaintingObjectContainer + { + public PaintingControl() + { + PaintingObjects = new PaintingObjectList(this); + this.KeyDown += CheckKeyDown; + this.KeyUp += CheckKeyDown; + this.MouseClick += CheckMouseClick; + this.MouseDown += CheckMouseDown; + this.MouseUp += CheckMouseUp; + this.MouseMove += CheckMouseMove; + this.PaintingObjectAdded += PaintingControl_PaintingObjectAdded; + this.PaintingObjectRemoved += PaintingControl_PaintingObjectAdded; + this.MouseWheel += CheckMouseWheel; + // SetStyle(ControlStyles.Opaque, True) 'For real transparency + DoubleBuffered = true; + } + + private PaintingObject curObjMouseDown = null; + private Color bgColor = Color.White; + private Point startMousePos = default; + private Point lastMousePos = default; + private int lastHashCode = 0; + private Point calcOffset_MouseOnTab = Point.Empty; + private bool calcOffset_IsActive = false; + private PointF calcOffset_LastOffset = PointF.Empty; + + private new Color ForeColor { get; set; } + private new Font Font { get; set; } + private new string Text { get; set; } + public PointF Offset { get; set; } = PointF.Empty; + public PaintingObjectList PaintingObjects { get; private set; } + // Public Property EnableRealTransparency As Boolean = False + public bool VisibleForMouseEvents { get; set; } = true; + public bool AutoAreaSelection { get; set; } = true; + public bool AutoSingleSelection { get; set; } = true; + public bool AutoMultiselection { get; set; } = true; + public bool AutoRemoveSelection { get; set; } = true; + public DashStyle AreaSelectionDashStyle { get; set; } = DashStyle.DashDot; + public Color AreaSelectionColor { get; set; } = Color.CornflowerBlue; + public bool AutoMoveObjects { get; set; } = true; + + private bool _IsAreaSelecting = false; + + public bool IsMovingObjects { get; private set; } = false; + public bool GridEnabled { get; set; } = true; + public bool GridVisible { get; set; } = false; + public Size GridChunkSize { get; set; } = new Size(20, 20); + public Color GridColor { get; set; } = Color.LightGray; + public DelegateDrawPaintingControlGridMethode DrawGridMethode { get; set; } = DefaultDrawMethodes.DrawGrid; + public DelegateDrawPaintingControlAreaSelectionMethode DrawAreaSelectionMethode { get; set; } = DefaultDrawMethodes.DrawAreaSelection; + + private SizeF _ZoomFactor = new SizeF(1f, 1f); + private int _stopDrawing = -1; + private Image bufferedImg = null; + private bool pressedShift = false; + private bool pressedControl = false; + private bool pressedAlt = false; + + // Friend WithEvents HScrollBarAdv1 As DevComponents.DotNetBar.ScrollBar.HScrollBarAdv + // Friend WithEvents VScrollBarAdv1 As DevComponents.DotNetBar.VScrollBarAdv + + private Dictionary savedPos = new Dictionary(); + + public event SelectionChangedEventHandler SelectionChanged; + + public delegate void SelectionChangedEventHandler(object sender, PaintingObjectEventArgs e); + + public event PaintingObjectAddedEventHandler PaintingObjectAdded; + + public delegate void PaintingObjectAddedEventHandler(object sender, PaintingObjectEventArgs e); + + public event PaintingObjectRemovedEventHandler PaintingObjectRemoved; + + public delegate void PaintingObjectRemovedEventHandler(object sender, PaintingObjectEventArgs e); + + public event AfterScrollingDoneEventHandler AfterScrollingDone; + + public delegate void AfterScrollingDoneEventHandler(object sender, EventArgs e); + + public event ZoomFactorChangedEventHandler ZoomFactorChanged; + + public delegate void ZoomFactorChangedEventHandler(object sender, EventArgs e); + + public PaintingObject[] SelectedObjects + { + get + { + var objs = new List(); + foreach (PaintingObject obj in PaintingObjects) + { + if (obj.Selected) + { + objs.Add(obj); + } + } + + return objs.ToArray(); + } + } + + public bool IsLayoutSuspended + { + get + { + return Conversions.ToBoolean(Operators.ConditionalCompareObjectNotEqual(GetType().GetField("layoutSuspendCount", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this), 0, false)); + } + } + + public bool StopDrawing + { + get + { + return _stopDrawing > -1; + } + } + + public override Color BackColor + { + get + { + return bgColor; + } + + set + { + bgColor = value; + base.BackColor = value; + // If value <> Color.Transparent Then + // MyBase.BackColor = value + // End If + } + } + + public bool IsAreaSelecting + { + get + { + return _IsAreaSelecting && startMousePos != lastMousePos; + } + } + + public SizeF ZoomFactor + { + get + { + return _ZoomFactor; + } + + set + { + if (_ZoomFactor != value) + { + _ZoomFactor = value; + ResetAllBufferedImages(); + ZoomFactorChanged?.Invoke(this, new EventArgs()); + } + } + } + + private void ResetAllBufferedImages() + { + foreach (PaintingObject ob in PaintingObjects) + ob.ResetImageBuffer(); + Refresh(); + } + + private void CheckKeyDown(object sender, KeyEventArgs e) + { + pressedShift = e.Shift; + pressedControl = e.Control; + pressedAlt = e.Alt; + } + + internal RectangleF AreaSelectionRectangle + { + get + { + return HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos); + } + } + + private void CheckMouseClick(object sender, MouseEventArgs e) + { + foreach (PaintingObject obj in GetObjects(new Point((int)(e.X + Offset.X), (int)(e.Y + Offset.Y)))) + { + if (!obj.MouseTransparency) + { + obj.RaiseMouseClick(GetMouseEventArgs(e, obj)); + } + } + } + + private void CheckMouseDown(object sender, MouseEventArgs e) + { + lastMousePos = new Point((int)(e.X + Offset.X), (int)(e.Y + Offset.Y)); + curObjMouseDown = GetObjects(lastMousePos).Where(n => !n.MouseTransparency).LastOrDefault(); + curObjMouseDown?.RaiseMouseDown(GetMouseEventArgs(e, curObjMouseDown)); + if (curObjMouseDown is null || !curObjMouseDown.Selected || pressedControl) + { + bool hasMovedObjects = false; + if (IsMovingObjects) + { + foreach (PaintingObject obj in GetSelectedObjects()) + { + if (HelpfulDrawingFunctions.IsPointInRectangle(lastMousePos, obj.Rectangle)) + { + hasMovedObjects = true; + break; + } + } + } + + if (!hasMovedObjects && !_IsAreaSelecting) + { + var selChanged = new List(); + if (AutoRemoveSelection && !pressedControl) + { + foreach (PaintingObject obj in PaintingObjects) + { + if (obj.Selected) + { + obj.SelectedDirect = false; + if (!selChanged.Contains(obj)) + { + selChanged.Add(obj); + } + } + } + } + + if (AutoSingleSelection && curObjMouseDown is object) + { + var objtosel = curObjMouseDown; + if (objtosel.EnableSelection) + { + objtosel.SelectedDirect = !objtosel.Selected; + if (!selChanged.Contains(objtosel)) + { + selChanged.Add(objtosel); + } + else + { + selChanged.Remove(objtosel); + } + } + } + + SelectionChanged?.Invoke(this, new PaintingObjectEventArgs(selChanged.ToArray())); + } + } + + if (pressedControl) + { + calcOffset_MouseOnTab = new Point(e.X, e.Y); + calcOffset_LastOffset = Offset; + calcOffset_IsActive = true; + Cursor = Cursors.Arrow; + } + else + { + switch (e.Button) + { + case MouseButtons.Left: + { + savedPos.Clear(); + if (AutoMoveObjects) + { + SaveObjectPositions(e, GetSelectedObjects()); + } + + if (savedPos.Count > 0) + { + IsMovingObjects = true; + } + else if (AutoAreaSelection) + { + startMousePos = new Point((int)(e.X + Offset.X), (int)(e.Y + Offset.Y)); + lastMousePos = startMousePos; // New Point(e.X - Offset.X, e.Y - Offset.Y) + _IsAreaSelecting = true; + } + + break; + } + } + } + } + + public void RaiseSelectionChanged() + { + SelectionChanged?.Invoke(this, new PaintingObjectEventArgs(SelectedObjects)); + } + + private void CheckMouseUp(object sender, MouseEventArgs e) + { + if (_IsAreaSelecting) + { + _IsAreaSelecting = false; + } + + if (IsMovingObjects) + { + IsMovingObjects = false; + foreach (PaintingObject obj in GetSelectedObjects()) + obj.RaiseMoved(new EventArgs()); + AutoArrangeToGrid(); + } + + if (curObjMouseDown is object) + { + if (!curObjMouseDown.MouseTransparency) + { + curObjMouseDown.RaiseMouseUp(GetMouseEventArgs(e, curObjMouseDown)); + } + + curObjMouseDown = null; + } + + if (calcOffset_IsActive) + { + calcOffset_IsActive = false; + Cursor = Cursors.Default; + CalcNewOffset(e.Location); + AfterScrollingDone?.Invoke(this, new EventArgs()); + } + } + + private void CheckMouseMove(object sender, MouseEventArgs e) + { + if (_IsAreaSelecting || IsMovingObjects) + { + lastMousePos = new Point((int)(e.X + Offset.X), (int)(e.Y + Offset.Y)); + } + + if (_IsAreaSelecting) + { + SelectControlsInArea(); + } + + if (IsMovingObjects) + { + UpdateObjectPositions(e); + } + + foreach (PaintingObject obj in GetObjects(new Point((int)(e.X + Offset.X), (int)(e.Y + Offset.Y)))) + { + if (!obj.MouseTransparency) + { + obj.RaiseMouseMove(GetMouseEventArgs(e, obj)); + } + } + + var topObj = GetObject(new Point((int)(e.X + Offset.X), (int)(e.Y + Offset.Y)), true); + if (topObj is object) + { + Cursor = topObj.Cursor; + } + else if (calcOffset_IsActive) + { + Cursor = Cursors.Arrow; + } + else + { + Cursor = Cursors.Default; + } + + if (calcOffset_IsActive) + { + if (pressedControl) + { + CalcNewOffset(e.Location); + } + else + { + calcOffset_IsActive = false; + } + } + + Refresh(); + } + + private void CalcNewOffset(Point newMousePos) + { + Offset = new PointF(calcOffset_LastOffset.X - (newMousePos.X - calcOffset_MouseOnTab.X), calcOffset_LastOffset.Y - (newMousePos.Y - calcOffset_MouseOnTab.Y)); + if (Offset.X < 0f) + { + Offset = new PointF(0f, Offset.Y); + } + + if (Offset.Y < 0f) + { + Offset = new PointF(Offset.X, 0f); + } + } + + private PaintingObject[] GetSelectedObjects() + { + var objs = new List(); + foreach (PaintingObject obj in PaintingObjects) + { + if (obj.Selected) + objs.Add(obj); + } + + return objs.ToArray(); + } + + private void SaveObjectPositions(MouseEventArgs e, IList objs) + { + foreach (PaintingObject obj in objs) + { + if (!savedPos.ContainsKey(obj)) + { + savedPos.Add(obj, new PointF(e.X - obj.Location.X + Offset.X, e.Y - obj.Location.Y + Offset.Y)); + SaveObjectPositions(e, obj.PinnedObjects); + } + } + } + + private void UpdateObjectPositions(MouseEventArgs e) + { + UpdateObjectPositions(e, GetSelectedObjects()); + } + + private void UpdateObjectPositions(MouseEventArgs e, IList objs, List movedObjs = null) + { + if (IsResizingObjs(objs)) + return; + if (movedObjs is null) + movedObjs = new List(); + SuspendDrawing(); + foreach (PaintingObject obj in objs) + { + var sp = savedPos[obj]; + if (!movedObjs.Contains(obj)) + { + if (UpdateObjectPosition(e, obj, sp)) + { + movedObjs.Add(obj); + } + } + + if (obj.PinnedObjects.Count > 0) + { + UpdateObjectPositions(e, obj.PinnedObjects, movedObjs); + movedObjs.AddRange(obj.PinnedObjects.ToArray()); + } + } + + ResumeDrawing(false); + } + + private bool UpdateObjectPosition(MouseEventArgs e, PaintingObject obj, PointF sp) + { + bool moved = false; + var cancel = new CancelEventArgs(false); + obj.RaiseMovingBeforePositionUpdated(cancel); + if (!cancel.Cancel) + { + obj.Location = new Point((int)(e.X - sp.X + Offset.X), (int)(e.Y - sp.Y + Offset.Y)); + obj.RaiseMoving(new EventArgs()); + moved = true; + } + + return moved; + } + + private bool IsResizingObjs(IList objs) + { + foreach (PaintingObject obj in objs) + { + if (obj.IsResizing) + return true; + } + + return false; + } + + private MouseEventArgs GetMouseEventArgs(MouseEventArgs e, PaintingObject obj) + { + return new MouseEventArgs(e.Button, e.Clicks, (int)(e.X - obj.X + Offset.X), (int)(e.Y - obj.Y + Offset.Y), e.Delta); + } + + public PaintingObject GetObject(PointF p, bool UseExtRect = false) + { + PaintingObject val = null; + for (int i = PaintingObjects.Count - 1; i >= 0; i -= 1) + { + var obj = PaintingObjects[i]; + if (val is null) + { + if (UseExtRect) + { + if (HelpfulDrawingFunctions.IsPointInRectangle(p, obj.RectangleExtended)) + { + val = obj; + } + } + else if (HelpfulDrawingFunctions.IsPointInRectangle(p, obj.Rectangle)) + { + val = obj; + } + } + } + + return val; + } + + public PaintingObject[] GetObjects(Point p) + { + var objs = new List(); + foreach (PaintingObject obj in PaintingObjects) + { + if (HelpfulDrawingFunctions.IsPointInRectangle(p, obj.RectangleExtended)) + { + objs.Add(obj); + } + } + + return objs.ToArray(); + } + + public PaintingObject[] GetObjects(Point startPoint, Point endPoint) + { + return GetObjects(new Rectangle(startPoint, (Size)(endPoint - (Size)startPoint))); + } + + public PaintingObject[] GetObjects(Rectangle rect) + { + var objs = new List(); + foreach (PaintingObject obj in PaintingObjects) + { + var objRect = obj.Rectangle; + if (HelpfulDrawingFunctions.IsPointInRectangle(objRect.Location, rect) || HelpfulDrawingFunctions.IsPointInRectangle(objRect.Location + objRect.Size, rect) || HelpfulDrawingFunctions.IsPointInRectangle(new PointF(objRect.Left, objRect.Bottom), rect) || HelpfulDrawingFunctions.IsPointInRectangle(new PointF(objRect.Right, objRect.Top), rect)) + { + objs.Add(obj); + } + } + + return objs.ToArray(); + } + + protected override CreateParams CreateParams + { + get + { + var cp = base.CreateParams; + + // If EnableRealTransparency Then + // cp.ExStyle = cp.ExStyle Or &H20 'WS_EX_TRANSPARENT + // End If + + return cp; + } + } + + /// + /// Sorg dafür, dass Events durch dieses Control durchdringen zum Parnet-Control. + /// + /// + protected override void WndProc(ref Message m) + { + const int WM_NCHITTEST = 0x84; + const int HTTRANSPARENT = -1; + if (!VisibleForMouseEvents && m.Msg == WM_NCHITTEST) + { + m.Result = (IntPtr)HTTRANSPARENT; + } + else + { + base.WndProc(ref m); + } + } + + protected override void OnPaintBackground(PaintEventArgs e) + { + // Stop Drawing directly to the parent + SuspendLayout(); + + // Draw Background + // If Not EnableRealTransparency Then + base.OnPaintBackground(e); + // End If + } + + protected override void OnPaint(PaintEventArgs e) + { + // Draw PaintingObjects stuff + if (StopDrawing) + { + e.Graphics.DrawImage(bufferedImg, Point.Empty); + } + else + { + { + var withBlock = e.Graphics; + withBlock.SmoothingMode = SmoothingMode.HighQuality; + withBlock.PixelOffsetMode = PixelOffsetMode.HighQuality; + withBlock.PageUnit = GraphicsUnit.Pixel; + withBlock.InterpolationMode = InterpolationMode.HighQualityBicubic; + } + + if (GridVisible) + { + DrawGridMethode?.Invoke(e, this, Offset); + } + + var baserect = new RectangleF(Offset, Size); + foreach (PaintingObject obj in PaintingObjects) + { + if (obj.Visible && HelpfulDrawingFunctions.OverlapsTwoRectangles(obj.Rectangle, baserect)) + { + obj.Draw(e, Offset); + } + } + + if (_IsAreaSelecting) + { + DrawAreaSelectionMethode?.Invoke(e, this, new PointF(startMousePos.X - Offset.X, startMousePos.Y - Offset.Y), new PointF(lastMousePos.X - Offset.X, lastMousePos.Y - Offset.Y)); + } + } + + // Do default Drawing Methode + base.OnPaint(e); + + // Start Drawing directly to the Form + ResumeLayout(false); + } + + public new Graphics CreateGraphics() + { + return base.CreateGraphics(); + } + + public void PaintFullView(Graphics g) + { + foreach (PaintingObject obj in PaintingObjects) + { + if (obj.Visible) + { + obj.Draw(g, PointF.Empty); + } + } + } + + private SizeF CalcTextSize(PaintingObject obj) + { + return CalcTextSize(obj, Parent.CreateGraphics()); + } + + private SizeF CalcTextSize(PaintingObject obj, Graphics g) + { + return g.MeasureString(obj.Text, obj.TextFont, (int)obj.Width); + } + + private void SelectControlsInArea() + { + var rect = HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos); + foreach (PaintingObject obj in PaintingObjects) + obj.Selected = startMousePos.X >= lastMousePos.X ? HelpfulDrawingFunctions.OverlapsTwoRectangles(obj.Rectangle, rect) : HelpfulDrawingFunctions.RectangleContainsRectangle(rect, obj.Rectangle); + } + + public void ArrangeToGrid(PaintingObject obj, bool snapPinnedObjects) + { + if (snapPinnedObjects || !IsPinnedObject(obj)) + { + var zoomedGridChunkSize = new SizeF(GridChunkSize.Width * ZoomFactor.Width, GridChunkSize.Height * ZoomFactor.Height); + int modTop = (int)(obj.Y % zoomedGridChunkSize.Height); + int modLeft = (int)(obj.X % zoomedGridChunkSize.Width); + int halfHeight = (int)(zoomedGridChunkSize.Height / 2f); + int halfWidth = (int)(zoomedGridChunkSize.Width / 2f); + void zoomLocation(PaintingObject obj2) + { + if (modTop > halfHeight) + { + obj2.Y += zoomedGridChunkSize.Height - modTop; + } + else + { + obj2.Y -= modTop; + } + + if (modLeft > halfWidth) + { + obj2.X += zoomedGridChunkSize.Width - modLeft; + } + else + { + obj2.X -= modLeft; + } + }; + zoomLocation(obj); + foreach (PaintingObject pinned in obj.PinnedObjects) + zoomLocation(pinned); + int modH = (int)(obj.Height % zoomedGridChunkSize.Height); + int modW = (int)(obj.Width % zoomedGridChunkSize.Width); + void zoomSize(PaintingObject obj2) { if (obj2.EnableResize && !obj2.HardcodedSize) { if (modH > halfHeight) { obj2.Height += zoomedGridChunkSize.Height - modH; } else { obj2.Height -= modH; } if (modW > halfWidth) { obj2.Width += zoomedGridChunkSize.Width - modW; } else { obj2.Width -= modW; } } }; + zoomSize(obj); + foreach (PaintingObject pinned in obj.PinnedObjects) + zoomSize(pinned); + } + } + + public bool IsPinnedObject(PaintingObject o) + { + foreach (PaintingObject obj in PaintingObjects) + { + if (obj.PinnedObjects.Contains(o)) + { + return true; + } + } + + return false; + } + + public void AutoArrangeToGrid() + { + if (GridEnabled) + { + foreach (PaintingObject obj in GetSelectedObjects()) + { + if (obj.AutoAlignToGrid) + { + ArrangeToGrid(obj, false); + } + } + + if (!StopDrawing) + Refresh(); + } + } + + public SizeF GetFullSize() + { + return GetFullSize(PaintingObjects); + } + + public static SizeF GetFullSize(IEnumerable objects) + { + float curX = 0f; + float curY = 0f; + foreach (PaintingObject po in objects) + { + float myX = po.X + po.Width; + if (curX < myX) + { + curX = myX; + } + + float myY = po.Y + po.Height; + if (curY < myY) + { + curY = myY; + } + } + + return new SizeF(curX + 20f, curY + 20f); + } + + internal void RaisePaintingObjectAdded(PaintingObjectEventArgs args) + { + PaintingObjectAdded?.Invoke(this, args); + } + + internal void RaisePaintingObjectRemoved(PaintingObjectEventArgs args) + { + PaintingObjectRemoved?.Invoke(this, args); + } + + private void PaintingControl_PaintingObjectAdded(object sender, PaintingObjectEventArgs e) + { + // CalculateScrollValues() + } + + private void CheckMouseWheel(object sender, MouseEventArgs e) + { + if (pressedControl) + { + float val = (float)(e.Delta / 120d / 10d); + ZoomFactor = new SizeF((float)Math.Max(ZoomFactor.Width + val, 0.25d), (float)Math.Max(ZoomFactor.Height + val, 0.25d)); + Refresh(); + } + } + + public void SuspendDrawing() + { + if (_stopDrawing < 0) + { + // bufferedImg = New Bitmap(Width, Height) + // DrawToBitmap(bufferedImg, New Rectangle(0, 0, bufferedImg.Width, bufferedImg.Height)) + Utils.DrawingControl.SuspendDrawing(this); + } + + _stopDrawing += 1; + } + + public void ResumeDrawing() + { + ResumeDrawing(true); + } + + public void ResumeDrawing(bool executeRefresh) + { + if (_stopDrawing >= 0) + { + _stopDrawing -= 1; + } + + if (_stopDrawing == -1) + { + // bufferedImg.Dispose() + // bufferedImg = Nothing + // If executeRefresh Then Refresh() + Utils.DrawingControl.ResumeDrawing(this, executeRefresh); + } + } + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/PaintingControl.vb b/Pilz.UI/PaintingControl/PaintingControl.vb deleted file mode 100644 index 745e3a0..0000000 --- a/Pilz.UI/PaintingControl/PaintingControl.vb +++ /dev/null @@ -1,680 +0,0 @@ -Imports System.ComponentModel -Imports System.Drawing -Imports System.Drawing.Drawing2D -Imports System.Runtime.CompilerServices -Imports System.Windows.Forms -Imports Pilz.Drawing - -Public Class PaintingControl - Inherits UserControl - Implements IPaintingObjectContainer - - Private curObjMouseDown As PaintingObject = Nothing - Private bgColor As Color = Color.White - Private startMousePos As Point = Nothing - Private lastMousePos As Point = Nothing - Private lastHashCode As Integer = 0 - Private calcOffset_MouseOnTab As Point = Point.Empty - Private calcOffset_IsActive As Boolean = False - Private calcOffset_LastOffset As PointF = PointF.Empty - - Private Overloads Property ForeColor As Color - Private Overloads Property Font As Font - Private Overloads Property Text As String - - Public Property Offset As PointF = PointF.Empty - Public ReadOnly Property PaintingObjects As New PaintingObjectList(Me) - 'Public Property EnableRealTransparency As Boolean = False - Public Property VisibleForMouseEvents As Boolean = True - Public Property AutoAreaSelection As Boolean = True - Public Property AutoSingleSelection As Boolean = True - Public Property AutoMultiselection As Boolean = True - Public Property AutoRemoveSelection As Boolean = True - Public Property AreaSelectionDashStyle As DashStyle = DashStyle.DashDot - Public Property AreaSelectionColor As Color = Color.CornflowerBlue - Public Property AutoMoveObjects As Boolean = True - Private _IsAreaSelecting As Boolean = False - Public ReadOnly Property IsMovingObjects As Boolean = False - Public Property GridEnabled As Boolean = True - Public Property GridVisible As Boolean = False - Public Property GridChunkSize As New Size(20, 20) - Public Property GridColor As Color = Color.LightGray - Public Property DrawGridMethode As DelegateDrawPaintingControlGridMethode = AddressOf DefaultDrawMethodes.DrawGrid - Public Property DrawAreaSelectionMethode As DelegateDrawPaintingControlAreaSelectionMethode = AddressOf DefaultDrawMethodes.DrawAreaSelection - Private _ZoomFactor As New SizeF(1, 1) - - Private _stopDrawing As Integer = -1 - Private bufferedImg As Image = Nothing - - Private pressedShift As Boolean = False - Private pressedControl As Boolean = False - Private pressedAlt As Boolean = False - - 'Friend WithEvents HScrollBarAdv1 As DevComponents.DotNetBar.ScrollBar.HScrollBarAdv - 'Friend WithEvents VScrollBarAdv1 As DevComponents.DotNetBar.VScrollBarAdv - - Private savedPos As New Dictionary(Of PaintingObject, PointF) - - Public Event SelectionChanged(sender As Object, e As PaintingObjectEventArgs) - Public Event PaintingObjectAdded(sender As Object, e As PaintingObjectEventArgs) - Public Event PaintingObjectRemoved(sender As Object, e As PaintingObjectEventArgs) - Public Event AfterScrollingDone(sender As Object, e As EventArgs) - Public Event ZoomFactorChanged(sender As Object, e As EventArgs) - - Public ReadOnly Property SelectedObjects As PaintingObject() - Get - Dim objs As New List(Of PaintingObject) - - For Each obj As PaintingObject In PaintingObjects - If obj.Selected Then - objs.Add(obj) - End If - Next - - Return objs.ToArray - End Get - End Property - - Public ReadOnly Property IsLayoutSuspended As Boolean - Get - Return Me.GetType.GetField("layoutSuspendCount", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(Me) <> 0 - End Get - End Property - - Public ReadOnly Property StopDrawing As Boolean - Get - Return _stopDrawing > -1 - End Get - End Property - - Public Overrides Property BackColor As Color - Get - Return bgColor - End Get - Set(value As Color) - bgColor = value - MyBase.BackColor = value - 'If value <> Color.Transparent Then - ' MyBase.BackColor = value - 'End If - End Set - End Property - Public ReadOnly Property IsAreaSelecting As Boolean - Get - Return _IsAreaSelecting AndAlso startMousePos <> lastMousePos - End Get - End Property - Public Property ZoomFactor As SizeF - Get - Return _ZoomFactor - End Get - Set - If _ZoomFactor <> Value Then - _ZoomFactor = Value - ResetAllBufferedImages() - RaiseEvent ZoomFactorChanged(Me, New EventArgs) - End If - End Set - End Property - - Public Sub New() - 'SetStyle(ControlStyles.Opaque, True) 'For real transparency - DoubleBuffered = True - End Sub - - Private Sub ResetAllBufferedImages() - For Each ob As PaintingObject In PaintingObjects - ob.ResetImageBuffer() - Next - Refresh() - End Sub - - Private Sub CheckKeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown, Me.KeyUp - pressedShift = e.Shift - pressedControl = e.Control - pressedAlt = e.Alt - End Sub - - Friend ReadOnly Property AreaSelectionRectangle As RectangleF - Get - Return HelpfulDrawingFunctions.GetRectangle(startMousePos, lastMousePos) - End Get - End Property - - Private Sub CheckMouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick - For Each obj As PaintingObject In GetObjects(New Point(e.X + Offset.X, e.Y + Offset.Y)) - If Not obj.MouseTransparency Then - obj.RaiseMouseClick(GetMouseEventArgs(e, obj)) - End If - Next - End Sub - - Private Sub CheckMouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown - lastMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y) - - curObjMouseDown = GetObjects(lastMousePos).Where(Function(n) Not n.MouseTransparency).LastOrDefault - curObjMouseDown?.RaiseMouseDown(GetMouseEventArgs(e, curObjMouseDown)) - - If curObjMouseDown Is Nothing OrElse Not curObjMouseDown.Selected OrElse pressedControl Then - Dim hasMovedObjects As Boolean = False - If _IsMovingObjects Then - For Each obj As PaintingObject In GetSelectedObjects() - If HelpfulDrawingFunctions.IsPointInRectangle(lastMousePos, obj.Rectangle) Then - hasMovedObjects = True - Exit For - End If - Next - End If - - If (Not hasMovedObjects) AndAlso (Not _IsAreaSelecting) Then - Dim selChanged As New List(Of PaintingObject) - - If AutoRemoveSelection AndAlso Not pressedControl Then - For Each obj As PaintingObject In PaintingObjects - If obj.Selected Then - obj.SelectedDirect = False - If Not selChanged.Contains(obj) Then - selChanged.Add(obj) - End If - End If - Next - End If - - If AutoSingleSelection AndAlso curObjMouseDown IsNot Nothing Then - Dim objtosel As PaintingObject = curObjMouseDown - If objtosel.EnableSelection Then - objtosel.SelectedDirect = Not objtosel.Selected - If Not selChanged.Contains(objtosel) Then - selChanged.Add(objtosel) - Else - selChanged.Remove(objtosel) - End If - End If - End If - - RaiseEvent SelectionChanged(Me, New PaintingObjectEventArgs(selChanged.ToArray)) - End If - End If - - If pressedControl Then - - calcOffset_MouseOnTab = New Point(e.X, e.Y) - calcOffset_LastOffset = Offset - calcOffset_IsActive = True - Cursor = Cursors.Arrow - - Else - - Select Case e.Button - Case MouseButtons.Left - savedPos.Clear() - If AutoMoveObjects Then - SaveObjectPositions(e, GetSelectedObjects) - End If - If savedPos.Count > 0 Then - _IsMovingObjects = True - ElseIf AutoAreaSelection Then - startMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y) - lastMousePos = startMousePos 'New Point(e.X - Offset.X, e.Y - Offset.Y) - _IsAreaSelecting = True - End If - End Select - - End If - End Sub - Public Sub RaiseSelectionChanged() - RaiseEvent SelectionChanged(Me, New PaintingObjectEventArgs(SelectedObjects)) - End Sub - Private Sub CheckMouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp - If _IsAreaSelecting Then - _IsAreaSelecting = False - End If - - If _IsMovingObjects Then - _IsMovingObjects = False - For Each obj As PaintingObject In GetSelectedObjects() - obj.RaiseMoved(New EventArgs) - Next - AutoArrangeToGrid() - End If - - If curObjMouseDown IsNot Nothing Then - If Not curObjMouseDown.MouseTransparency Then - curObjMouseDown.RaiseMouseUp(GetMouseEventArgs(e, curObjMouseDown)) - End If - curObjMouseDown = Nothing - End If - - If calcOffset_IsActive Then - calcOffset_IsActive = False - Cursor = Cursors.Default - CalcNewOffset(e.Location) - RaiseEvent AfterScrollingDone(Me, New EventArgs) - End If - End Sub - Private Sub CheckMouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove - If _IsAreaSelecting OrElse _IsMovingObjects Then - lastMousePos = New Point(e.X + Offset.X, e.Y + Offset.Y) - End If - - If _IsAreaSelecting Then - SelectControlsInArea() - End If - - If _IsMovingObjects Then - UpdateObjectPositions(e) - End If - - For Each obj As PaintingObject In GetObjects(New Point(e.X + Offset.X, e.Y + Offset.Y)) - If Not obj.MouseTransparency Then - obj.RaiseMouseMove(GetMouseEventArgs(e, obj)) - End If - Next - - Dim topObj As PaintingObject = GetObject(New Point(e.X + Offset.X, e.Y + Offset.Y), True) - If topObj IsNot Nothing Then - Cursor = topObj.Cursor - ElseIf calcOffset_IsActive Then - Cursor = Cursors.Arrow - Else - Cursor = Cursors.Default - End If - - If calcOffset_IsActive Then - If pressedControl Then - CalcNewOffset(e.Location) - Else - calcOffset_IsActive = False - End If - End If - - Refresh() - End Sub - - Private Sub CalcNewOffset(newMousePos As Point) - Offset = New PointF(calcOffset_LastOffset.X - (newMousePos.X - calcOffset_MouseOnTab.X), - calcOffset_LastOffset.Y - (newMousePos.Y - calcOffset_MouseOnTab.Y)) - If Offset.X < 0 Then - Offset = New PointF(0, Offset.Y) - End If - If Offset.Y < 0 Then - Offset = New PointF(Offset.X, 0) - End If - End Sub - - Private Function GetSelectedObjects() As PaintingObject() - Dim objs As New List(Of PaintingObject) - - For Each obj As PaintingObject In PaintingObjects - If obj.Selected Then objs.Add(obj) - Next - - Return objs.ToArray - End Function - - Private Sub SaveObjectPositions(e As MouseEventArgs, objs As IList) - For Each obj As PaintingObject In objs - If Not savedPos.ContainsKey(obj) Then - savedPos.Add(obj, New PointF(e.X - obj.Location.X + Offset.X, e.Y - obj.Location.Y + Offset.Y)) - SaveObjectPositions(e, obj.PinnedObjects) - End If - Next - End Sub - - Private Sub UpdateObjectPositions(e As MouseEventArgs) - UpdateObjectPositions(e, GetSelectedObjects) - End Sub - - Private Sub UpdateObjectPositions(e As MouseEventArgs, objs As IList(Of PaintingObject), Optional movedObjs As List(Of PaintingObject) = Nothing) - If IsResizingObjs(objs) Then Return - If movedObjs Is Nothing Then movedObjs = New List(Of PaintingObject) - - SuspendDrawing() - - For Each obj As PaintingObject In objs - Dim sp As PointF = savedPos(obj) - - If Not movedObjs.Contains(obj) Then - If UpdateObjectPosition(e, obj, sp) Then - movedObjs.Add(obj) - End If - End If - - If obj.PinnedObjects.Count > 0 Then - UpdateObjectPositions(e, obj.PinnedObjects, movedObjs) - movedObjs.AddRange(obj.PinnedObjects.ToArray) - End If - Next - - ResumeDrawing(False) - End Sub - - Private Function UpdateObjectPosition(e As MouseEventArgs, obj As PaintingObject, sp As PointF) As Boolean - Dim moved As Boolean = False - Dim cancel As New CancelEventArgs(False) - obj.RaiseMovingBeforePositionUpdated(cancel) - - If Not cancel.Cancel Then - obj.Location = New Point(e.X - sp.X + Offset.X, - e.Y - sp.Y + Offset.Y) - obj.RaiseMoving(New EventArgs) - moved = True - End If - - Return moved - End Function - - Private Function IsResizingObjs(objs As IList(Of PaintingObject)) As Boolean - For Each obj As PaintingObject In objs - If obj.IsResizing Then Return True - Next - Return False - End Function - - Private Function GetMouseEventArgs(e As MouseEventArgs, obj As PaintingObject) As MouseEventArgs - Return New MouseEventArgs(e.Button, e.Clicks, e.X - obj.X + Offset.X, e.Y - obj.Y + Offset.Y, e.Delta) - End Function - - Public Function GetObject(p As PointF, Optional UseExtRect As Boolean = False) As PaintingObject - Dim val As PaintingObject = Nothing - - For i As Integer = PaintingObjects.Count - 1 To 0 Step -1 - Dim obj As PaintingObject = PaintingObjects(i) - - If val Is Nothing Then - If UseExtRect Then - If HelpfulDrawingFunctions.IsPointInRectangle(p, obj.RectangleExtended) Then - val = obj - End If - Else - If HelpfulDrawingFunctions.IsPointInRectangle(p, obj.Rectangle) Then - val = obj - End If - End If - End If - Next - - Return val - End Function - - Public Function GetObjects(p As Point) As PaintingObject() - Dim objs As New List(Of PaintingObject) - - For Each obj As PaintingObject In PaintingObjects - If HelpfulDrawingFunctions.IsPointInRectangle(p, obj.RectangleExtended) Then - objs.Add(obj) - End If - Next - - Return objs.ToArray - End Function - - Public Function GetObjects(startPoint As Point, endPoint As Point) As PaintingObject() - Return GetObjects(New Rectangle(startPoint, CType(endPoint - startPoint, Size))) - End Function - - Public Function GetObjects(rect As Rectangle) As PaintingObject() - Dim objs As New List(Of PaintingObject) - - For Each obj As PaintingObject In PaintingObjects - Dim objRect As RectangleF = obj.Rectangle - If HelpfulDrawingFunctions.IsPointInRectangle(objRect.Location, rect) OrElse - HelpfulDrawingFunctions.IsPointInRectangle(objRect.Location + objRect.Size, rect) OrElse - HelpfulDrawingFunctions.IsPointInRectangle(New PointF(objRect.Left, objRect.Bottom), rect) OrElse - HelpfulDrawingFunctions.IsPointInRectangle(New PointF(objRect.Right, objRect.Top), rect) Then - objs.Add(obj) - End If - Next - - Return objs.ToArray - End Function - - Protected Overrides ReadOnly Property CreateParams As CreateParams - Get - Dim cp = MyBase.CreateParams - - 'If EnableRealTransparency Then - ' cp.ExStyle = cp.ExStyle Or &H20 'WS_EX_TRANSPARENT - 'End If - - Return cp - End Get - End Property - - ''' - ''' Sorg dafür, dass Events durch dieses Control durchdringen zum Parnet-Control. - ''' - ''' - Protected Overrides Sub WndProc(ByRef m As Message) - Const WM_NCHITTEST As Integer = &H84 - Const HTTRANSPARENT As Integer = -1 - - If Not VisibleForMouseEvents AndAlso m.Msg = WM_NCHITTEST Then - m.Result = CType(HTTRANSPARENT, IntPtr) - Else - MyBase.WndProc(m) - End If - End Sub - - Protected Overrides Sub OnPaintBackground(e As PaintEventArgs) - 'Stop Drawing directly to the parent - Me.SuspendLayout() - - 'Draw Background - 'If Not EnableRealTransparency Then - MyBase.OnPaintBackground(e) - 'End If - End Sub - - Protected Overrides Sub OnPaint(e As PaintEventArgs) - 'Draw PaintingObjects stuff - If StopDrawing Then - e.Graphics.DrawImage(bufferedImg, Point.Empty) - Else - With e.Graphics - .SmoothingMode = SmoothingMode.HighQuality - .PixelOffsetMode = PixelOffsetMode.HighQuality - .PageUnit = GraphicsUnit.Pixel - .InterpolationMode = InterpolationMode.HighQualityBicubic - End With - - If GridVisible Then - DrawGridMethode?.Invoke(e, Me, Offset) - End If - - Dim baserect As RectangleF = New RectangleF(Offset, Size) - - For Each obj As PaintingObject In PaintingObjects - If obj.Visible AndAlso HelpfulDrawingFunctions.OverlapsTwoRectangles(obj.Rectangle, baserect) Then - obj.Draw(e, Offset) - End If - Next - - If _IsAreaSelecting Then - DrawAreaSelectionMethode?.Invoke(e, Me, New PointF(startMousePos.X - Offset.X, startMousePos.Y - Offset.Y), New PointF(lastMousePos.X - Offset.X, lastMousePos.Y - Offset.Y)) - End If - End If - - 'Do default Drawing Methode - MyBase.OnPaint(e) - - 'Start Drawing directly to the Form - ResumeLayout(False) - End Sub - - Public Overloads Function CreateGraphics() As Graphics - Return MyBase.CreateGraphics - End Function - - Public Sub PaintFullView(g As Graphics) - For Each obj As PaintingObject In PaintingObjects - If obj.Visible Then - obj.Draw(g, PointF.Empty) - End If - Next - End Sub - - Private Function CalcTextSize(obj As PaintingObject) As SizeF - Return CalcTextSize(obj, Parent.CreateGraphics) - End Function - - Private Function CalcTextSize(obj As PaintingObject, g As Graphics) As SizeF - Return g.MeasureString(obj.Text, obj.TextFont, obj.Width) - End Function - - Private Sub SelectControlsInArea() - Dim rect As RectangleF = GetRectangle(startMousePos, lastMousePos) - For Each obj As PaintingObject In PaintingObjects - obj.Selected = If(startMousePos.X >= lastMousePos.X, - OverlapsTwoRectangles(obj.Rectangle, rect), - RectangleContainsRectangle(rect, obj.Rectangle)) - Next - End Sub - - Public Sub ArrangeToGrid(obj As PaintingObject, snapPinnedObjects As Boolean) - If snapPinnedObjects OrElse Not IsPinnedObject(obj) Then - Dim zoomedGridChunkSize As New SizeF(GridChunkSize.Width * ZoomFactor.Width, Me.GridChunkSize.Height * ZoomFactor.Height) - - Dim modTop As Integer = obj.Y Mod zoomedGridChunkSize.Height - Dim modLeft As Integer = obj.X Mod zoomedGridChunkSize.Width - - Dim halfHeight As Integer = zoomedGridChunkSize.Height / 2 - Dim halfWidth As Integer = zoomedGridChunkSize.Width / 2 - - Dim zoomLocation = - Sub(obj2 As PaintingObject) - If modTop > halfHeight Then - obj2.Y += (zoomedGridChunkSize.Height - modTop) - Else - obj2.Y -= modTop - End If - - If modLeft > halfWidth Then - obj2.X += (zoomedGridChunkSize.Width - modLeft) - Else - obj2.X -= modLeft - End If - End Sub - - zoomLocation(obj) - - For Each pinned As PaintingObject In obj.PinnedObjects - zoomLocation(pinned) - Next - - Dim modH As Integer = obj.Height Mod zoomedGridChunkSize.Height - Dim modW As Integer = obj.Width Mod zoomedGridChunkSize.Width - - Dim zoomSize = - Sub(obj2 As PaintingObject) - If obj2.EnableResize AndAlso Not obj2.HardcodedSize Then - If modH > halfHeight Then - obj2.Height += (zoomedGridChunkSize.Height - modH) - Else - obj2.Height -= modH - End If - - If modW > halfWidth Then - obj2.Width += (zoomedGridChunkSize.Width - modW) - Else - obj2.Width -= modW - End If - End If - End Sub - - zoomSize(obj) - - For Each pinned As PaintingObject In obj.PinnedObjects - zoomSize(pinned) - Next - End If - End Sub - - Public Function IsPinnedObject(o As PaintingObject) As Boolean - For Each obj As PaintingObject In PaintingObjects - If obj.PinnedObjects.Contains(o) Then - Return True - End If - Next - Return False - End Function - - Public Sub AutoArrangeToGrid() - If GridEnabled Then - For Each obj As PaintingObject In GetSelectedObjects() - If obj.AutoAlignToGrid Then - ArrangeToGrid(obj, False) - End If - Next - If Not StopDrawing Then Refresh() - End If - End Sub - - Public Function GetFullSize() As SizeF - Return GetFullSize(PaintingObjects) - End Function - - Public Shared Function GetFullSize(objects As IEnumerable(Of PaintingObject)) As SizeF - Dim curX As Single = 0 - Dim curY As Single = 0 - - For Each po As PaintingObject In objects - Dim myX As Single = po.X + po.Width - If curX < myX Then - curX = myX - End If - Dim myY As Single = po.Y + po.Height - If curY < myY Then - curY = myY - End If - Next - - Return New SizeF(curX + 20, curY + 20) - End Function - - Friend Sub RaisePaintingObjectAdded(args As PaintingObjectEventArgs) - RaiseEvent PaintingObjectAdded(Me, args) - End Sub - Friend Sub RaisePaintingObjectRemoved(args As PaintingObjectEventArgs) - RaiseEvent PaintingObjectRemoved(Me, args) - End Sub - - Private Sub PaintingControl_PaintingObjectAdded(sender As Object, e As PaintingObjectEventArgs) Handles Me.PaintingObjectAdded, Me.PaintingObjectRemoved - 'CalculateScrollValues() - End Sub - - Private Sub CheckMouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel - If pressedControl Then - Dim val As Single = e.Delta / 120 / 10 - ZoomFactor = New SizeF(Math.Max(ZoomFactor.Width + val, 0.25), Math.Max(ZoomFactor.Height + val, 0.25)) - Refresh() - End If - End Sub - - Public Sub SuspendDrawing() - If _stopDrawing < 0 Then - 'bufferedImg = New Bitmap(Width, Height) - 'DrawToBitmap(bufferedImg, New Rectangle(0, 0, bufferedImg.Width, bufferedImg.Height)) - Utils.SuspendDrawing(Me) - End If - _stopDrawing += 1 - End Sub - - Public Sub ResumeDrawing() - ResumeDrawing(True) - End Sub - - Public Sub ResumeDrawing(executeRefresh As Boolean) - If _stopDrawing >= 0 Then - _stopDrawing -= 1 - End If - - If _stopDrawing = -1 Then - 'bufferedImg.Dispose() - 'bufferedImg = Nothing - 'If executeRefresh Then Refresh() - Utils.ResumeDrawing(Me, executeRefresh) - End If - End Sub - -End Class diff --git a/Pilz.UI/PaintingControl/PaintingControlDelegates.cs b/Pilz.UI/PaintingControl/PaintingControlDelegates.cs new file mode 100644 index 0000000..0af3864 --- /dev/null +++ b/Pilz.UI/PaintingControl/PaintingControlDelegates.cs @@ -0,0 +1,11 @@ +using global::System.Drawing; +using global::System.Windows.Forms; + +namespace Pilz.UI +{ + public delegate void DelegateDrawPaintingObjectMethode(PaintingObjectPaintEventArgs e); + + public delegate void DelegateDrawPaintingControlGridMethode(PaintEventArgs e, PaintingControl pc, PointF offset); + + public delegate void DelegateDrawPaintingControlAreaSelectionMethode(PaintEventArgs e, PaintingControl pc, PointF startMousePos, PointF lastMousePos); +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/PaintingControlDelegates.vb b/Pilz.UI/PaintingControl/PaintingControlDelegates.vb deleted file mode 100644 index 6516ca2..0000000 --- a/Pilz.UI/PaintingControl/PaintingControlDelegates.vb +++ /dev/null @@ -1,6 +0,0 @@ -Imports System.Drawing -Imports System.Windows.Forms - -Public Delegate Sub DelegateDrawPaintingObjectMethode(e As PaintingObjectPaintEventArgs) -Public Delegate Sub DelegateDrawPaintingControlGridMethode(e As PaintEventArgs, pc As PaintingControl, offset As PointF) -Public Delegate Sub DelegateDrawPaintingControlAreaSelectionMethode(e As PaintEventArgs, pc As PaintingControl, startMousePos As PointF, lastMousePos As PointF) diff --git a/Pilz.UI/PaintingControl/PaintingObject.cs b/Pilz.UI/PaintingControl/PaintingObject.cs new file mode 100644 index 0000000..ed4fca6 --- /dev/null +++ b/Pilz.UI/PaintingControl/PaintingObject.cs @@ -0,0 +1,873 @@ +using System; +using System.Collections.Generic; +using global::System.ComponentModel; +using global::System.Drawing; +using global::System.Drawing.Drawing2D; +using System.Linq; +using global::System.Reflection; +using global::System.Windows.Forms; +using global::Newtonsoft.Json; + +namespace Pilz.UI +{ + [Serializable] + public class PaintingObject : ICloneable, IPaintingObjectContainer + { + private PaintingObjectResizing resizeEngine = null; + private bool _Selected = false; + private PaintingControl _Parent = null; + + public Color FillColor { get; set; } = Color.Blue; + public Color OutlineColor { get; set; } = Color.DarkBlue; + public float OutlineThicknes { get; set; } = 1f; + public DashStyle OutlineDashStyle { get; set; } = DashStyle.Solid; + + private string _Text = ""; + + public TextPosition TextPosition { get; set; } = TextPosition.FullCenter; + public StringAlignment VerticalTextAlignment { get; set; } = StringAlignment.Center; + public StringAlignment HorizontalTextAlignment { get; set; } = StringAlignment.Center; + public Font TextFont { get; set; } = new Font(FontFamily.GenericSansSerif, 8.25f); + public Color TextColor { get; set; } = Color.Black; + + private PointF _Location = new PointF(50f, 50f); + private SizeF _Size = new SizeF(50f, 80f); + + public bool EnableFill { get; set; } = true; + public bool EnableOutline { get; set; } = true; + public Color SelectionColor { get; set; } = Color.CornflowerBlue; + public DashStyle SelectionDashStyle { get; set; } = DashStyle.Dot; + + private bool _EnableSelection = true; + + public Image Image { get; set; } = null; + [JsonIgnore] + public Image BufferedImage { get; set; } = null; + public ImageSizeMode ImageSizeMode { get; set; } + public PaintingObjectImageProperties ImageProperties { get; set; } = new PaintingObjectImageProperties(); + public string Tag { get; set; } = null; + public string Name { get; set; } = ""; + public List PinnedObjects { get; private set; } = new List(); + public List DrawMethodes { get; private set; } = new List(); + public DelegateDrawPaintingObjectMethode DrawSelectionMethode { get; private set; } = DefaultDrawMethodes.DrawSelection; + public Cursor Cursor { get; set; } = Cursors.Default; + public bool HardcodedSize { get; set; } = false; + + private bool _Visible = true; + private bool _AutoAlignToGrid = false; + + public bool MouseTransparency { get; set; } = false; + public PaintingObjectLayering Layering { get; private set; } + public PaintingObjectList PaintingObjects { get; private set; } + public ulong ErrorsAtDrawing { get; private set; } = 0UL; + + public event MouseClickEventHandler MouseClick; + + public delegate void MouseClickEventHandler(PaintingObject sender, MouseEventArgs e); + + public event MouseDownEventHandler MouseDown; + + public delegate void MouseDownEventHandler(PaintingObject sender, MouseEventArgs e); + + public event MouseUpEventHandler MouseUp; + + public delegate void MouseUpEventHandler(PaintingObject sender, MouseEventArgs e); + + public event MouseMoveEventHandler MouseMove; + + public delegate void MouseMoveEventHandler(PaintingObject sender, MouseEventArgs e); + + public event SelectedChangedEventHandler SelectedChanged; + + public delegate void SelectedChangedEventHandler(PaintingObject sender, EventArgs e); + + public event PaintEventHandler Paint; + + public delegate void PaintEventHandler(PaintingObject sender, PaintEventArgs e); + + public event ParentChangedEventHandler ParentChanged; + + public delegate void ParentChangedEventHandler(PaintingObject sender, EventArgs e); + + public event VisibleChangedEventHandler VisibleChanged; + + public delegate void VisibleChangedEventHandler(PaintingObject sender, EventArgs e); + + public event MovedEventHandler Moved; + + public delegate void MovedEventHandler(PaintingObject sender, EventArgs e); + + public event MovingEventHandler Moving; + + public delegate void MovingEventHandler(PaintingObject sender, EventArgs e); + + public event MovingBeforePositionUpdatedEventHandler MovingBeforePositionUpdated; + + public delegate void MovingBeforePositionUpdatedEventHandler(PaintingObject sender, CancelEventArgs e); + + public PaintingObject() + { + Layering = new PaintingObjectLayering(this); + PaintingObjects = new PaintingObjectList(_Parent) { EnableRaisingEvents = false }; + } + + public PaintingObject(PaintingObjectType type) : this() + { + Type = type; + } + + public PaintingObject(PaintingObjectType type, DelegateDrawPaintingObjectMethode[] drawMethodes) : this(type) + { + DrawMethodes.AddRange(drawMethodes); + } + + internal void RaiseMouseClick(MouseEventArgs e) + { + MouseClick?.Invoke(this, e); + } + + internal void RaiseMouseDown(MouseEventArgs e) + { + MouseDown?.Invoke(this, e); + } + + internal void RaiseMouseUp(MouseEventArgs e) + { + MouseUp?.Invoke(this, e); + } + + internal void RaiseMouseMove(MouseEventArgs e) + { + MouseMove?.Invoke(this, e); + } + + private void RaisePaint(PaintEventArgs e) + { + Paint?.Invoke(this, e); + } + + internal void RaiseMoved(EventArgs e) + { + Moved?.Invoke(this, e); + } + + internal void RaiseMoving(EventArgs e) + { + Moving?.Invoke(this, e); + } + + internal void RaiseMovingBeforePositionUpdated(EventArgs e) + { + MovingBeforePositionUpdated?.Invoke(this, (CancelEventArgs)e); + } + + public PaintingObjectType Type + { + get + { + var tt = PaintingObjectType.Custom; + foreach (DelegateDrawPaintingObjectMethode d in DrawMethodes) + { + if (ReferenceEquals(d.Method.DeclaringType, typeof(DefaultDrawMethodes))) + { + switch (d.Method.Name ?? "") + { + case "DrawPicture": + { + tt = tt | PaintingObjectType.Picture; + break; + } + + case "DrawText": + { + tt = tt | PaintingObjectType.Text; + break; + } + + case "DrawRectangle": + { + tt = tt | PaintingObjectType.Rectangle; + break; + } + + case "DrawEllipse": + { + tt = tt | PaintingObjectType.Elipse; + break; + } + + case "DrawTriangle": + { + tt = tt | PaintingObjectType.Triangle; + break; + } + + case "DrawLine": + { + tt = tt | PaintingObjectType.Line; + break; + } + } + } + } + + return tt; + } + + set + { + DrawMethodes.Clear(); + if ((value & PaintingObjectType.Picture) == PaintingObjectType.Picture) + { + DrawMethodes.Add(DefaultDrawMethodes.DrawPicture); + } + + if ((value & PaintingObjectType.Rectangle) == PaintingObjectType.Rectangle) + { + DrawMethodes.Add(DefaultDrawMethodes.DrawRectangle); + } + + if ((value & PaintingObjectType.Elipse) == PaintingObjectType.Elipse) + { + DrawMethodes.Add(DefaultDrawMethodes.DrawEllipse); + } + + if ((value & PaintingObjectType.Triangle) == PaintingObjectType.Triangle) + { + DrawMethodes.Add(DefaultDrawMethodes.DrawTriangle); + } + + if ((value & PaintingObjectType.Line) == PaintingObjectType.Line) + { + DrawMethodes.Add(DefaultDrawMethodes.DrawLine); + } + + if ((value & PaintingObjectType.Text) == PaintingObjectType.Text) + { + DrawMethodes.Add(DefaultDrawMethodes.DrawText); + } + } + } + + [JsonIgnore] + public PointF Location + { + get + { + if (Parent is object) + { + return new PointF(_Location.X * Parent.ZoomFactor.Width, _Location.Y * Parent.ZoomFactor.Height); + } + else + { + return _Location; + } + } + + set + { + if (Parent is object) + { + _Location = new PointF(value.X / Parent.ZoomFactor.Width, value.Y / Parent.ZoomFactor.Height); + } + else + { + _Location = value; + } + } + } + + [JsonIgnore] + public SizeF Size + { + get + { + if (Parent is object) + { + return new SizeF(_Size.Width * Parent.ZoomFactor.Width, _Size.Height * Parent.ZoomFactor.Height); + } + else + { + return _Size; + } + } + + set + { + if (Parent is object) + { + _Size = new SizeF(value.Width / Parent.ZoomFactor.Width, value.Height / Parent.ZoomFactor.Height); + } + else + { + _Size = value; + } + + ResetImageBuffer(); + } + } + + [JsonIgnore] + public SizeF SizeDirect + { + get + { + return _Size; + } + + set + { + _Size = value; + ResetImageBuffer(); + } + } + + [JsonIgnore] + public bool AutoAlignToGrid + { + get + { + return _AutoAlignToGrid; + } + + set + { + _AutoAlignToGrid = value; + if (value) + ArrangeToGrid(); + } + } + + [JsonIgnore] + public bool IsResizing + { + get + { + if (resizeEngine is null) + { + return false; + } + else + { + return resizeEngine?.IsResizing == true; + } + } + } + + [JsonIgnore] + public PaintingControl Parent + { + get + { + return _Parent; + } + + set + { + bool re = !ReferenceEquals(value, _Parent); + _Parent = value; + if (re) + ParentChanged?.Invoke(this, new EventArgs()); + } + } + + [JsonIgnore] + public bool Visible + { + get + { + return _Visible; + } + + set + { + if (value != _Visible) + { + _Visible = value; + if (!value && !_EnableSelection) + EnableResize = false; + VisibleChanged?.Invoke(this, new EventArgs()); + } + } + } + + public bool Selected + { + get + { + return _Selected; + } + + set + { + SetSelection(value, true); + } + } + + [JsonIgnore] + public bool SelectedDirect + { + get + { + return Selected; + } + + set + { + SetSelection(value, false); + } + } + + private void SetSelection(bool value, bool raiseEventOnParent) + { + if (EnableSelection) + { + if (_Selected != value) + { + _Selected = value; + SelectedChanged?.Invoke(this, new EventArgs()); + if (raiseEventOnParent) + { + Parent.RaiseSelectionChanged(); + } + } + } + else + { + _Selected = false; + } + } + + [JsonIgnore] + public float Width + { + get + { + return Size.Width; + } + + set + { + Size = new SizeF(value, Size.Height); + } + } + + [JsonIgnore] + public float Height + { + get + { + return Size.Height; + } + + set + { + Size = new SizeF(Size.Width, value); + } + } + + [JsonIgnore] + public float X + { + get + { + return Location.X; + } + + set + { + Location = new PointF(value, Location.Y); + } + } + + [JsonIgnore] + public float Y + { + get + { + return Location.Y; + } + + set + { + Location = new PointF(Location.X, value); + } + } + + [JsonIgnore] + public string Text + { + get + { + return _Text; + } + + set + { + _Text = value; + } + } + + public RectangleF Rectangle + { + get + { + return new RectangleF(Location, Size); + } + + set + { + Location = value.Location; + Size = value.Size; + } + } + + [JsonIgnore] + public bool EnableSelection + { + get + { + return _EnableSelection; + } + + set + { + _EnableSelection = value; + if (!value && !_Visible) + EnableResize = false; + if (!value) + Selected = false; + } + } + + [JsonIgnore] + public Rectangle RectangleExtended + { + get + { + return new Rectangle((int)(X - 12f), (int)(Y - 12f), (int)(Width + 12f + 12f), (int)(Height + 12f + 12f)); + } + + set + { + X = value.X + 12; + Y = value.Y + 12; + Width = value.Width - 12 - 12; + Height = value.Height - 12 - 12; + } + } + + public void FitSizeToText() + { + if (Parent is null) + { + throw new Exception("You have to put that PaintingObject to a PaintingControl before."); + } + + var g = Parent.CreateGraphics(); + var newSize = g.MeasureString(Text, TextFont); + SizeDirect = newSize + new SizeF(1f, 0f); + } + + public void SetBounds(int x, int y, int width, int height) + { + Location = new Point(x, y); + Size = new Size(width, height); + } + + [JsonIgnore] + public int Left + { + get + { + return (int)X; + } + + set + { + X = value; + } + } + + [JsonIgnore] + public int Top + { + get + { + return (int)Y; + } + + set + { + Y = value; + } + } + + [JsonIgnore] + public int Right + { + get + { + return (int)(X + Width); + } + + set + { + X = value - Width; + } + } + + [JsonIgnore] + public int Bottom + { + get + { + return (int)(Y + Height); + } + + set + { + Y = value - Height; + } + } + + public bool EnableResize + { + get + { + if (resizeEngine is null) + { + return false; + } + else + { + return resizeEngine.Enabled; + } + } + + set + { + if (resizeEngine is null && value) + { + resizeEngine = new PaintingObjectResizing(this); + } + else if (resizeEngine is object) + { + resizeEngine.Enabled = value; + } + } + } + + public void Remove() + { + Parent?.PaintingObjects.Remove(this); + } + + public void AutoArrangeToGrid() + { + if (((bool)Parent?.GridEnabled && AutoAlignToGrid) == true) + { + ArrangeToGrid(); + } + } + + public void ArrangeToGrid() + { + if (Parent is object) + { + Parent.ArrangeToGrid(this, true); + if (!Parent.StopDrawing) + Parent.Refresh(); + } + } + + public void Draw(PaintEventArgs e) + { + Draw(e, PointF.Empty); + } + + public void Draw(PaintEventArgs e, PointF offset) + { + Draw(e.Graphics, offset); + if (Visible) + { + RaisePaint(e); + } + } + + public void Draw(Graphics g, PointF offset) + { + if (Visible) + { + var poevargs = new PaintingObjectPaintEventArgs(this, g, offset); + foreach (DelegateDrawPaintingObjectMethode dm in DrawMethodes) + { + try + { + dm?.Invoke(poevargs); + } + catch (Exception ex) + { + ErrorsAtDrawing = (ulong)(ErrorsAtDrawing + 1m); + } + } + + if (Selected && DrawSelectionMethode is object) + { + DrawSelectionMethode?.Invoke(poevargs); + } + } + } + + public object Clone() + { + return Clone(true); + } + + public object Clone(bool includePinnedObject) + { + var obj = new PaintingObject(); + var metype = GetType(); + var blackField = new[] { nameof(PinnedObjects), nameof(resizeEngine), nameof(_Parent), nameof(BufferedImage), nameof(ImageProperties) }; + void copyFields(object source, object dest, string[] blackFields, Type t) + { + var fields = new List(t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.Instance)); + foreach (FieldInfo field in fields) + { + if (!blackFields.Contains(field.Name)) + { + field.SetValue(dest, field.GetValue(source)); + } + } + }; + copyFields(this, obj, blackField, metype); + copyFields(ImageProperties, obj.ImageProperties, Array.Empty(), ImageProperties.GetType()); + if (includePinnedObject) + { + obj.PinnedObjects.AddRange(PinnedObjects); + } + + obj.EnableResize = EnableResize; + return obj; + } + + [Obsolete("Use Layering.BringToTop() instead!")] + public void BringToFront() + { + Layering.BringToTop(); + } + + [Obsolete("Use Layering.SendToBack() instead!")] + public void SendToBack() + { + Layering.SendToBack(); + } + + public void ResetImageBuffer() + { + BufferedImage = null; + } + } + + public class PaintingObjectList : List + { + internal PaintingControl MyParent { get; private set; } + internal bool EnableRaisingEvents { get; set; } = true; + public PaintingObjectListLayering Layering { get; private set; } + + public PaintingObjectList() : this(null) + { + } + + public PaintingObjectList(PaintingControl parent) + { + Layering = new PaintingObjectListLayering(this); + MyParent = parent; + } + + public new void Add(PaintingObject item) + { + item.Parent = MyParent; + base.Add(item); + item.AutoArrangeToGrid(); + if (EnableRaisingEvents) + { + MyParent?.RaisePaintingObjectAdded(new PaintingObjectEventArgs(new[] { item })); + } + } + + public void AddRange(PaintingObject[] items) + { + foreach (PaintingObject item in items) + item.Parent = MyParent; + base.AddRange(items); + foreach (PaintingObject item in items) + item.AutoArrangeToGrid(); + if (EnableRaisingEvents) + { + MyParent?.RaisePaintingObjectAdded(new PaintingObjectEventArgs(items)); + } + } + + public new void Insert(int index, PaintingObject item) + { + item.Parent = MyParent; + base.Insert(index, item); + MyParent?.AutoArrangeToGrid(); + if (EnableRaisingEvents) + { + MyParent?.RaisePaintingObjectAdded(new PaintingObjectEventArgs(new[] { item })); + } + } + + public new void Remove(PaintingObject item) + { + item.Parent = null; + base.Remove(item); + if (EnableRaisingEvents) + { + MyParent?.RaisePaintingObjectRemoved(new PaintingObjectEventArgs(new[] { item })); + } + } + + public new void RemoveAt(int index) + { + this[index].Parent = null; + var item = this[index]; + base.RemoveAt(index); + if (EnableRaisingEvents) + { + MyParent?.RaisePaintingObjectRemoved(new PaintingObjectEventArgs(new[] { item })); + } + } + } + + public enum PaintingObjectType + { + Custom = 0, + Text = 1, + Picture = 2, + Line = 4, + Triangle = 8, + Rectangle = 16, + Elipse = 32 + } + + public enum ImageSizeMode + { + Fit, + Zoom, + Original + } + + public enum TextPosition + { + HLeft = 0x1, + HRight = 0x2, + HCenter = 0x4, + VUp = 0x10, + VDown = 0x20, + VCenter = 0x40, + FullCenter = HCenter | VCenter + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/PaintingObject.vb b/Pilz.UI/PaintingControl/PaintingObject.vb deleted file mode 100644 index c46c134..0000000 --- a/Pilz.UI/PaintingControl/PaintingObject.vb +++ /dev/null @@ -1,617 +0,0 @@ -Imports System.ComponentModel -Imports System.Drawing -Imports System.Drawing.Drawing2D -Imports System.Reflection -Imports System.Runtime.CompilerServices -Imports System.Runtime.InteropServices -Imports System.Runtime.Serialization -Imports System.Windows.Forms -Imports Newtonsoft.Json - - Public Class PaintingObject - Implements ICloneable, IPaintingObjectContainer - - Private resizeEngine As PaintingObjectResizing = Nothing - Private _Selected As Boolean = False - - Private _Parent As PaintingControl = Nothing - Public Property FillColor As Color = Color.Blue - Public Property OutlineColor As Color = Color.DarkBlue - Public Property OutlineThicknes As Single = 1 - Public Property OutlineDashStyle As DashStyle = DashStyle.Solid - Private _Text As String = "" - Public Property TextPosition As TextPosition = TextPosition.FullCenter - Public Property VerticalTextAlignment As StringAlignment = StringAlignment.Center - Public Property HorizontalTextAlignment As StringAlignment = StringAlignment.Center - Public Property TextFont As New Font(FontFamily.GenericSansSerif, 8.25) - Public Property TextColor As Color = Color.Black - Private _Location As New PointF(50, 50) - Private _Size As New SizeF(50, 80) - Public Property EnableFill As Boolean = True - Public Property EnableOutline As Boolean = True - Public Property SelectionColor As Color = Color.CornflowerBlue - Public Property SelectionDashStyle As DashStyle = DashStyle.Dot - Private _EnableSelection As Boolean = True - Public Property Image As Image = Nothing - Public Property BufferedImage As Image = Nothing - Public Property ImageSizeMode As ImageSizeMode - Public Property ImageProperties As New PaintingObjectImageProperties - Public Property Tag As String = Nothing - Public Property Name As String = "" - Public ReadOnly Property PinnedObjects As New List(Of PaintingObject) - Public ReadOnly Property DrawMethodes As New List(Of DelegateDrawPaintingObjectMethode) - Public ReadOnly Property DrawSelectionMethode As DelegateDrawPaintingObjectMethode = AddressOf DefaultDrawMethodes.DrawSelection - Public Property Cursor As Cursor = Cursors.Default - Public Property HardcodedSize As Boolean = False - Private _Visible As Boolean = True - Private _AutoAlignToGrid As Boolean = False - Public Property MouseTransparency As Boolean = False - Public ReadOnly Property Layering As New PaintingObjectLayering(Me) - Public ReadOnly Property PaintingObjects As New PaintingObjectList(_Parent) With {.EnableRaisingEvents = False} - Public ReadOnly Property ErrorsAtDrawing As ULong = 0 - - Public Event MouseClick(sender As PaintingObject, e As MouseEventArgs) - Public Event MouseDown(sender As PaintingObject, e As MouseEventArgs) - Public Event MouseUp(sender As PaintingObject, e As MouseEventArgs) - Public Event MouseMove(sender As PaintingObject, e As MouseEventArgs) - Public Event SelectedChanged(sender As PaintingObject, e As EventArgs) - Public Event Paint(sender As PaintingObject, e As PaintEventArgs) - Public Event ParentChanged(sender As PaintingObject, e As EventArgs) - Public Event VisibleChanged(sender As PaintingObject, e As EventArgs) - Public Event Moved(sender As PaintingObject, e As EventArgs) - Public Event Moving(sender As PaintingObject, e As EventArgs) - Public Event MovingBeforePositionUpdated(sender As PaintingObject, e As CancelEventArgs) - - Public Sub New() - End Sub - - Public Sub New(type As PaintingObjectType) - Me.Type = type - End Sub - - Public Sub New(type As PaintingObjectType, drawMethodes As DelegateDrawPaintingObjectMethode()) - Me.New(type) - Me.DrawMethodes.AddRange(drawMethodes) - End Sub - - Friend Sub RaiseMouseClick(e As MouseEventArgs) - RaiseEvent MouseClick(Me, e) - End Sub - Friend Sub RaiseMouseDown(e As MouseEventArgs) - RaiseEvent MouseDown(Me, e) - End Sub - Friend Sub RaiseMouseUp(e As MouseEventArgs) - RaiseEvent MouseUp(Me, e) - End Sub - Friend Sub RaiseMouseMove(e As MouseEventArgs) - RaiseEvent MouseMove(Me, e) - End Sub - Private Sub RaisePaint(e As PaintEventArgs) - RaiseEvent Paint(Me, e) - End Sub - Friend Sub RaiseMoved(e As EventArgs) - RaiseEvent Moved(Me, e) - End Sub - Friend Sub RaiseMoving(e As EventArgs) - RaiseEvent Moving(Me, e) - End Sub - Friend Sub RaiseMovingBeforePositionUpdated(e As EventArgs) - RaiseEvent MovingBeforePositionUpdated(Me, e) - End Sub - - Public Property Type As PaintingObjectType - Get - Dim tt As PaintingObjectType = PaintingObjectType.Custom - - For Each d As DelegateDrawPaintingObjectMethode In DrawMethodes - If d.Method.DeclaringType Is GetType(DefaultDrawMethodes) Then - Select Case d.Method.Name - Case "DrawPicture" - tt = tt Or PaintingObjectType.Picture - Case "DrawText" - tt = tt Or PaintingObjectType.Text - Case "DrawRectangle" - tt = tt Or PaintingObjectType.Rectangle - Case "DrawEllipse" - tt = tt Or PaintingObjectType.Elipse - Case "DrawTriangle" - tt = tt Or PaintingObjectType.Triangle - Case "DrawLine" - tt = tt Or PaintingObjectType.Line - End Select - End If - Next - - Return tt - End Get - Set(value As PaintingObjectType) - DrawMethodes.Clear() - - If (value And PaintingObjectType.Picture) = PaintingObjectType.Picture Then - DrawMethodes.Add(AddressOf DefaultDrawMethodes.DrawPicture) - End If - - If (value And PaintingObjectType.Rectangle) = PaintingObjectType.Rectangle Then - DrawMethodes.Add(AddressOf DefaultDrawMethodes.DrawRectangle) - End If - - If (value And PaintingObjectType.Elipse) = PaintingObjectType.Elipse Then - DrawMethodes.Add(AddressOf DefaultDrawMethodes.DrawEllipse) - End If - - If (value And PaintingObjectType.Triangle) = PaintingObjectType.Triangle Then - DrawMethodes.Add(AddressOf DefaultDrawMethodes.DrawTriangle) - End If - - If (value And PaintingObjectType.Line) = PaintingObjectType.Line Then - DrawMethodes.Add(AddressOf DefaultDrawMethodes.DrawLine) - End If - - If (value And PaintingObjectType.Text) = PaintingObjectType.Text Then - DrawMethodes.Add(AddressOf DefaultDrawMethodes.DrawText) - End If - End Set - End Property - - Public Property Location As PointF - Get - If Parent IsNot Nothing Then - Return New PointF(_Location.X * Parent.ZoomFactor.Width, - _Location.Y * Parent.ZoomFactor.Height) - Else - Return _Location - End If - End Get - Set(value As PointF) - If Parent IsNot Nothing Then - _Location = New PointF(value.X / Parent.ZoomFactor.Width, - value.Y / Parent.ZoomFactor.Height) - Else - _Location = value - End If - End Set - End Property - - Public Property Size As SizeF - Get - If Parent IsNot Nothing Then - Return New SizeF(_Size.Width * Parent.ZoomFactor.Width, - _Size.Height * Parent.ZoomFactor.Height) - Else - Return _Size - End If - End Get - Set(value As SizeF) - If Parent IsNot Nothing Then - _Size = New SizeF(value.Width / Parent.ZoomFactor.Width, - value.Height / Parent.ZoomFactor.Height) - Else - _Size = value - End If - ResetImageBuffer() - End Set - End Property - - Public Property SizeDirect As SizeF - Get - Return _Size - End Get - Set(value As SizeF) - _Size = value - ResetImageBuffer() - End Set - End Property - - Public Property AutoAlignToGrid As Boolean - Get - Return _AutoAlignToGrid - End Get - Set(value As Boolean) - _AutoAlignToGrid = value - If value Then ArrangeToGrid() - End Set - End Property - - Public ReadOnly Property IsResizing As Boolean - Get - If resizeEngine Is Nothing Then - Return False - Else - Return resizeEngine?.IsResizing - End If - End Get - End Property - - Public Property Parent As PaintingControl - Get - Return _Parent - End Get - Set(value As PaintingControl) - Dim re As Boolean = value IsNot _Parent - _Parent = value - If re Then RaiseEvent ParentChanged(Me, New EventArgs) - End Set - End Property - - Public Property Visible As Boolean - Get - Return _Visible - End Get - Set(value As Boolean) - If value <> _Visible Then - _Visible = value - If Not value AndAlso Not _EnableSelection Then EnableResize = False - RaiseEvent VisibleChanged(Me, New EventArgs) - End If - End Set - End Property - - Public Property Selected As Boolean - Get - Return _Selected - End Get - Set(value As Boolean) - SetSelection(value, True) - End Set - End Property - - Public Property SelectedDirect As Boolean - Get - Return Selected - End Get - Set(value As Boolean) - SetSelection(value, False) - End Set - End Property - - Private Sub SetSelection(value As Boolean, raiseEventOnParent As Boolean) - If EnableSelection Then - If _Selected <> value Then - _Selected = value - RaiseEvent SelectedChanged(Me, New EventArgs) - If raiseEventOnParent Then - Parent.RaiseSelectionChanged() - End If - End If - Else - _Selected = False - End If - End Sub - - Public Property Width As Single - Get - Return Size.Width - End Get - Set(value As Single) - Size = New SizeF(value, Size.Height) - End Set - End Property - Public Property Height As Single - Get - Return Size.Height - End Get - Set(value As Single) - Size = New SizeF(Size.Width, value) - End Set - End Property - - Public Property X As Single - Get - Return Location.X - End Get - Set(value As Single) - Location = New PointF(value, Location.Y) - End Set - End Property - Public Property Y As Single - Get - Return Location.Y - End Get - Set(value As Single) - Location = New PointF(Location.X, value) - End Set - End Property - - Public Property Text As String - Get - Return _Text - End Get - Set(value As String) - _Text = value - End Set - End Property - - Public Property Rectangle As RectangleF - Get - Return New RectangleF(Location, Size) - End Get - Set(value As RectangleF) - Location = value.Location - Size = value.Size - End Set - End Property - - Public Property EnableSelection As Boolean - Get - Return _EnableSelection - End Get - Set(value As Boolean) - _EnableSelection = value - If Not value AndAlso Not _Visible Then EnableResize = False - If Not value Then Selected = False - End Set - End Property - - Public Property RectangleExtended As Rectangle - Get - Return New Rectangle(X - 12, - Y - 12, - Width + 12 + 12, - Height + 12 + 12) - End Get - Set(value As Rectangle) - X = value.X + 12 - Y = value.Y + 12 - Width = value.Width - 12 - 12 - Height = value.Height - 12 - 12 - End Set - End Property - - Public Sub FitSizeToText() - If Parent Is Nothing Then - Throw New Exception("You have to put that PaintingObject to a PaintingControl before.") - End If - - Dim g As Graphics = Parent.CreateGraphics() - Dim newSize As SizeF = g.MeasureString(Text, TextFont) - SizeDirect = newSize + New SizeF(1, 0) - End Sub - - Public Sub SetBounds(x As Integer, y As Integer, width As Integer, height As Integer) - Location = New Point(x, y) - Size = New Size(width, height) - End Sub - - Public Property Left As Integer - Get - Return X - End Get - Set(value As Integer) - X = value - End Set - End Property - - Public Property Top() As Integer - Get - Return Y - End Get - Set(value As Integer) - Y = value - End Set - End Property - - Public Property Right As Integer - Get - Return X + Width - End Get - Set(value As Integer) - X = value - Width - End Set - End Property - - Public Property Bottom() As Integer - Get - Return Y + Height - End Get - Set(value As Integer) - Y = value - Height - End Set - End Property - - Public Property EnableResize As Boolean - Get - If resizeEngine Is Nothing Then - Return False - Else - Return resizeEngine.Enabled - End If - End Get - Set(value As Boolean) - If resizeEngine Is Nothing AndAlso value Then - resizeEngine = New PaintingObjectResizing(Me) - ElseIf resizeEngine IsNot Nothing Then - resizeEngine.Enabled = value - End If - End Set - End Property - - Public Sub Remove() - Parent?.PaintingObjects.Remove(Me) - End Sub - - Public Sub AutoArrangeToGrid() - If Parent?.GridEnabled AndAlso AutoAlignToGrid Then - ArrangeToGrid() - End If - End Sub - - Public Sub ArrangeToGrid() - If Parent IsNot Nothing Then - Parent.ArrangeToGrid(Me, True) - If Not Parent.StopDrawing Then Parent.Refresh() - End If - End Sub - - Public Sub Draw(e As PaintEventArgs) - Draw(e, PointF.Empty) - End Sub - - Public Sub Draw(e As PaintEventArgs, offset As PointF) - Draw(e.Graphics, offset) - - If Visible Then - RaisePaint(e) - End If - End Sub - - Public Sub Draw(g As Graphics, offset As PointF) - If Visible Then - Dim poevargs As New PaintingObjectPaintEventArgs(Me, g, offset) - - For Each dm As DelegateDrawPaintingObjectMethode In DrawMethodes - Try - dm?.Invoke(poevargs) - Catch ex As Exception - _ErrorsAtDrawing += 1 - End Try - Next - - If Selected AndAlso DrawSelectionMethode IsNot Nothing Then - DrawSelectionMethode?.Invoke(poevargs) - End If - End If - End Sub - - Public Function Clone() As Object Implements ICloneable.Clone - Return Clone(True) - End Function - - Public Function Clone(includePinnedObject As Boolean) As Object - Dim obj As New PaintingObject - Dim metype As Type = Me.GetType - Dim blackField As String() = { - NameOf(_PinnedObjects), - NameOf(resizeEngine), - NameOf(_Parent), - NameOf(BufferedImage), - NameOf(_ImageProperties) - } - - Dim copyFields = - Sub(source As Object, dest As Object, blackFields As String(), t As Type) - Dim fields As New List(Of FieldInfo)(t.GetFields(BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.IgnoreCase Or BindingFlags.Instance)) - For Each field As FieldInfo In fields - If Not blackFields.Contains(field.Name) Then - field.SetValue(dest, field.GetValue(source)) - End If - Next - End Sub - - copyFields(Me, obj, blackField, metype) - copyFields(ImageProperties, obj.ImageProperties, {}, ImageProperties.GetType) - - If includePinnedObject Then - obj.PinnedObjects.AddRange(PinnedObjects) - End If - - obj.EnableResize = EnableResize - - Return obj - End Function - - - Public Sub BringToFront() - Layering.BringToTop() - End Sub - - - Public Sub SendToBack() - Layering.SendToBack() - End Sub - - Public Sub ResetImageBuffer() - BufferedImage = Nothing - End Sub - -End Class - -Public Class PaintingObjectList - Inherits List(Of PaintingObject) - - Friend ReadOnly Property MyParent As PaintingControl - Friend Property EnableRaisingEvents As Boolean = True - Public ReadOnly Property Layering As New PaintingObjectListLayering(Me) - - Public Sub New() - Me.New(Nothing) - End Sub - - Public Sub New(parent As PaintingControl) - MyParent = parent - End Sub - - Public Overloads Sub Add(item As PaintingObject) - item.Parent = MyParent - MyBase.Add(item) - item.AutoArrangeToGrid() - If EnableRaisingEvents Then - MyParent?.RaisePaintingObjectAdded(New PaintingObjectEventArgs({item})) - End If - End Sub - - Public Overloads Sub AddRange(items As PaintingObject()) - For Each item As PaintingObject In items - item.Parent = MyParent - Next - MyBase.AddRange(items) - For Each item As PaintingObject In items - item.AutoArrangeToGrid() - Next - If EnableRaisingEvents Then - MyParent?.RaisePaintingObjectAdded(New PaintingObjectEventArgs(items)) - End If - End Sub - - Public Overloads Sub Insert(index As Integer, item As PaintingObject) - item.Parent = MyParent - MyBase.Insert(index, item) - MyParent?.AutoArrangeToGrid() - If EnableRaisingEvents Then - MyParent?.RaisePaintingObjectAdded(New PaintingObjectEventArgs({item})) - End If - End Sub - - Public Overloads Sub Remove(item As PaintingObject) - item.Parent = Nothing - MyBase.Remove(item) - If EnableRaisingEvents Then - MyParent?.RaisePaintingObjectRemoved(New PaintingObjectEventArgs({item})) - End If - End Sub - - Public Overloads Sub RemoveAt(index As Integer) - Me(index).Parent = Nothing - Dim item As PaintingObject = Me(index) - MyBase.RemoveAt(index) - If EnableRaisingEvents Then - MyParent?.RaisePaintingObjectRemoved(New PaintingObjectEventArgs({item})) - End If - End Sub - -End Class - -Public Enum PaintingObjectType - Custom = 0 - Text = 1 - Picture = 2 - Line = 4 - Triangle = 8 - Rectangle = 16 - Elipse = 32 -End Enum - -Public Enum ImageSizeMode - Fit - Zoom - Original -End Enum - -Public Enum TextPosition - HLeft = &H1 - HRight = &H2 - HCenter = &H4 - VUp = &H10 - VDown = &H20 - VCenter = &H40 - FullCenter = HCenter Or VCenter -End Enum diff --git a/Pilz.UI/PaintingControl/PaintingObjectLayering.cs b/Pilz.UI/PaintingControl/PaintingObjectLayering.cs new file mode 100644 index 0000000..5900e76 --- /dev/null +++ b/Pilz.UI/PaintingControl/PaintingObjectLayering.cs @@ -0,0 +1,100 @@ + +namespace Pilz.UI +{ + public class PaintingObjectLayering + { + public PaintingObject PaintingObject { get; private set; } + + /// + /// Get the current object list from the painting object. + /// + /// Returns the current object list from the painting object. + public PaintingObjectList ObjectList + { + get + { + return PaintingObject.Parent.PaintingObjects; + } + } + + /// + /// Create a new instance of object layer managing. + /// + /// + public PaintingObjectLayering(PaintingObject obj) + { + PaintingObject = obj; + } + + /// + /// Moves the object by the given number of indicies. + /// + /// The number how many objects it should be moved. + public void MoveObject(int count) + { + int oldIndex = ObjectList.IndexOf(PaintingObject); + int newIndex = oldIndex + count; + MoveObjectTo(newIndex); + } + + /// + /// Moves the object to the new index. + /// + /// + public void MoveObjectTo(int newIndex) + { + var list = ObjectList; + + // Check & make index valid + if (newIndex >= ObjectList.Count) + { + newIndex = ObjectList.Count - 1; + } + else if (newIndex < 0) + { + newIndex = 0; + } + + // Remove object + list.Remove(PaintingObject); + + // Insert object at new index + list.Insert(newIndex, PaintingObject); + + // Order all objects again + list.Layering.OrderAll(); + } + + /// + /// Moves the object to the front. + /// + public void BringToTop() + { + MoveObjectTo(ObjectList.Count - 1); + } + + /// + /// Moves the object to the back. + /// + public void SendToBack() + { + MoveObjectTo(0); + } + + /// + /// Moves the object fordward by one + /// + public void OneToTop() + { + MoveObject(+1); + } + + /// + /// Moves the object backward by one + /// + public void OneToBack() + { + MoveObject(-1); + } + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/PaintingObjectLayering.vb b/Pilz.UI/PaintingControl/PaintingObjectLayering.vb deleted file mode 100644 index f56e4ac..0000000 --- a/Pilz.UI/PaintingControl/PaintingObjectLayering.vb +++ /dev/null @@ -1,85 +0,0 @@ -Public Class PaintingObjectLayering - - Public ReadOnly Property PaintingObject As PaintingObject - - ''' - ''' Get the current object list from the painting object. - ''' - ''' Returns the current object list from the painting object. - Public ReadOnly Property ObjectList As PaintingObjectList - Get - Return PaintingObject.Parent.PaintingObjects - End Get - End Property - - ''' - ''' Create a new instance of object layer managing. - ''' - ''' - Public Sub New(obj As PaintingObject) - PaintingObject = obj - End Sub - - ''' - ''' Moves the object by the given number of indicies. - ''' - ''' The number how many objects it should be moved. - Public Sub MoveObject(count As Integer) - Dim oldIndex As Integer = ObjectList.IndexOf(PaintingObject) - Dim newIndex As Integer = oldIndex + count - MoveObjectTo(newIndex) - End Sub - - ''' - ''' Moves the object to the new index. - ''' - ''' - Public Sub MoveObjectTo(newIndex As Integer) - Dim list As PaintingObjectList = ObjectList - - 'Check & make index valid - If newIndex >= ObjectList.Count Then - newIndex = ObjectList.Count - 1 - ElseIf newIndex < 0 Then - newIndex = 0 - End If - - 'Remove object - list.Remove(PaintingObject) - - 'Insert object at new index - list.Insert(newIndex, PaintingObject) - - 'Order all objects again - list.Layering.OrderAll() - End Sub - - ''' - ''' Moves the object to the front. - ''' - Public Sub BringToTop() - MoveObjectTo(ObjectList.Count - 1) - End Sub - - ''' - ''' Moves the object to the back. - ''' - Public Sub SendToBack() - MoveObjectTo(0) - End Sub - - ''' - ''' Moves the object fordward by one - ''' - Public Sub OneToTop() - MoveObject(+1) - End Sub - - ''' - ''' Moves the object backward by one - ''' - Public Sub OneToBack() - MoveObject(-1) - End Sub - -End Class diff --git a/Pilz.UI/PaintingControl/PaintingObjectListLayering.cs b/Pilz.UI/PaintingControl/PaintingObjectListLayering.cs new file mode 100644 index 0000000..a1120d3 --- /dev/null +++ b/Pilz.UI/PaintingControl/PaintingObjectListLayering.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace Pilz.UI +{ + public class PaintingObjectListLayering + { + public PaintingObjectList ObjectList { get; private set; } + public Dictionary> Conditions { get; private set; } = new Dictionary>(); + + /// + /// Get the order function will checkout the conditions. + /// + /// Returns true, if conditions are aviable, otherwise false. + public bool EnableConditions + { + get + { + return Conditions.Any(); + } + } + + /// + /// Create a new instance of object list layer managing. + /// + /// + public PaintingObjectListLayering(PaintingObjectList list) + { + ObjectList = list; + } + + /// + /// Order all objects using the conditions. If no conditions are setted, this method will do nothing. + /// + public void OrderAll() + { + if (EnableConditions) + { + OrderAllPrivate(); + } + } + + private void OrderAllPrivate() + { + var list = ObjectList; + var listOld = list.ToList(); + var toRemove = new List(); + + // Disable raising events + ObjectList.EnableRaisingEvents = false; + + // Clear list + list.Clear(); + + // Add ordered + foreach (var kvp in Conditions.OrderBy(n => n.Key)) + { + var func = kvp.Value; + foreach (PaintingObject obj in listOld) + { + if (func(obj)) + { + // Add to list + list.Add(obj); + + // Add to remove + toRemove.Add(obj); + } + } + + // Remove remembered objects + foreach (PaintingObject obj in toRemove) + listOld.Remove(obj); + toRemove.Clear(); + } + + // Enable raising events + ObjectList.EnableRaisingEvents = true; + + // Refresh + ObjectList.MyParent?.Refresh(); + } + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/PaintingObjectListLayering.vb b/Pilz.UI/PaintingControl/PaintingObjectListLayering.vb deleted file mode 100644 index 64100ec..0000000 --- a/Pilz.UI/PaintingControl/PaintingObjectListLayering.vb +++ /dev/null @@ -1,73 +0,0 @@ -Public Class PaintingObjectListLayering - - - Public ReadOnly Property ObjectList As PaintingObjectList - Public ReadOnly Property Conditions As New Dictionary(Of Integer, Func(Of PaintingObject, Boolean)) - - ''' - ''' Get the order function will checkout the conditions. - ''' - ''' Returns true, if conditions are aviable, otherwise false. - Public ReadOnly Property EnableConditions As Boolean - Get - Return Conditions.Any - End Get - End Property - - ''' - ''' Create a new instance of object list layer managing. - ''' - ''' - Public Sub New(list As PaintingObjectList) - ObjectList = list - End Sub - - ''' - ''' Order all objects using the conditions. If no conditions are setted, this method will do nothing. - ''' - Public Sub OrderAll() - If EnableConditions Then - OrderAllPrivate() - End If - End Sub - - Private Sub OrderAllPrivate() - Dim list As PaintingObjectList = ObjectList - Dim listOld As List(Of PaintingObject) = list.ToList - Dim toRemove As New List(Of PaintingObject) - - 'Disable raising events - ObjectList.EnableRaisingEvents = False - - 'Clear list - list.Clear() - - 'Add ordered - For Each kvp In Conditions.OrderBy(Function(n) n.Key) - Dim func = kvp.Value - - For Each obj As PaintingObject In listOld - If func(obj) Then - 'Add to list - list.Add(obj) - - 'Add to remove - toRemove.Add(obj) - End If - Next - - 'Remove remembered objects - For Each obj As PaintingObject In toRemove - listOld.Remove(obj) - Next - toRemove.Clear() - Next - - 'Enable raising events - ObjectList.EnableRaisingEvents = True - - 'Refresh - ObjectList.MyParent?.Refresh() - End Sub - -End Class diff --git a/Pilz.UI/PaintingControl/PaintingObjectResizing.cs b/Pilz.UI/PaintingControl/PaintingObjectResizing.cs new file mode 100644 index 0000000..1f69bd9 --- /dev/null +++ b/Pilz.UI/PaintingControl/PaintingObjectResizing.cs @@ -0,0 +1,335 @@ +using System; +using global::System.Drawing; +using System.Runtime.CompilerServices; +using global::System.Windows.Forms; +using global::Pilz.Drawing; + +namespace Pilz.UI +{ + [Serializable] + internal class PaintingObjectResizing + { + public PaintingObjectResizing() + { + mObjParent = null; + mObjControl = null; + } + + public PaintingObjectResizing(PaintingObject obj) + { + mObjParent = null; + mObjControl = null; + mObj = obj; + mObjControl = mObj.Parent; + } + + private PaintingObject _mObj; + + private PaintingObject mObj + { + [MethodImpl(MethodImplOptions.Synchronized)] + get + { + return _mObj; + } + + [MethodImpl(MethodImplOptions.Synchronized)] + set + { + if (_mObj != null) + { + _mObj.MouseDown -= mControl_MouseDown; + _mObj.MouseUp -= mControl_MouseUp; + _mObj.Paint -= mControl_Paint; + _mObj.SelectedChanged -= mControl_MouseLeave; + _mObj.ParentChanged -= mObj_ParentChanged; + } + + _mObj = value; + if (_mObj != null) + { + _mObj.MouseDown += mControl_MouseDown; + _mObj.MouseUp += mControl_MouseUp; + _mObj.Paint += mControl_Paint; + _mObj.SelectedChanged += mControl_MouseLeave; + _mObj.ParentChanged += mObj_ParentChanged; + } + } + } + + private Control mObjParent; + private Control _mObjControl; + + private Control mObjControl + { + [MethodImpl(MethodImplOptions.Synchronized)] + get + { + return _mObjControl; + } + + [MethodImpl(MethodImplOptions.Synchronized)] + set + { + if (_mObjControl != null) + { + _mObjControl.MouseMove -= mControl_MouseMove; + _mObjControl.ParentChanged -= mObjParent_ParentChanged; + } + + _mObjControl = value; + if (_mObjControl != null) + { + _mObjControl.MouseMove += mControl_MouseMove; + _mObjControl.ParentChanged += mObjParent_ParentChanged; + } + } + } + + private bool mMouseDown = false; + private EdgeEnum mEdge = EdgeEnum.None; + private int mWidth = 4; + private int qWidth = 4 * 4; + private Rectangle rect = new Rectangle(); + + public bool Enabled { get; set; } = true; + public SizeF MinimumSize { get; set; } = new SizeF(15f, 15f); + + [Serializable] + private enum EdgeEnum + { + None, + Right, + Left, + Top, + Bottom, + TopLeft, + TopRight, + BottomLeft, + BottomRight + } + + public bool IsResizing + { + get + { + return mMouseDown && mEdge != EdgeEnum.None; + } + } + + public static PaintingObjectResizing ApplyToControl(PaintingObject obj) + { + return new PaintingObjectResizing(obj); + } + + private void mControl_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + mMouseDown = true; + } + } + + private void mControl_MouseUp(object sender, MouseEventArgs e) + { + mMouseDown = false; + if (mObj.Selected) + { + mObj.AutoArrangeToGrid(); + } + } + + private void KeepInRange(ref SizeF size) + { + if (size.Height < MinimumSize.Height || size.Width < MinimumSize.Width) + { + size = new SizeF(Math.Max(size.Width, MinimumSize.Width), Math.Max(size.Height, MinimumSize.Height)); + } + } + + private void mControl_MouseMove(object sender, MouseEventArgs e) + { + if (mMouseDown && mEdge != EdgeEnum.None) + { + int eX = (int)(e.X + mObj.Parent.Offset.X); + int eY = (int)(e.Y + mObj.Parent.Offset.Y); + switch (mEdge) + { + case EdgeEnum.TopLeft: + { + mObj.SetBounds(eX, eY, (int)(mObj.Width + (mObj.Left - eX)), (int)(mObj.Height + (mObj.Top - eY))); + break; + } + + case EdgeEnum.TopRight: + { + mObj.SetBounds(mObj.Left, eY, eX - mObj.Left, (int)(mObj.Height + (mObj.Top - eY))); + break; + } + + case EdgeEnum.BottomRight: + { + mObj.SetBounds(mObj.Left, mObj.Top, eX - mObj.Left, eY - mObj.Top); + break; + } + + case EdgeEnum.BottomLeft: + { + mObj.SetBounds(eX, mObj.Top, (int)(mObj.Width + (mObj.Left - eX)), eY - mObj.Top); + break; + } + + case EdgeEnum.Left: + { + mObj.SetBounds(eX, mObj.Top, (int)(mObj.Width + (mObj.Left - eX)), (int)mObj.Height); + break; + } + + case EdgeEnum.Right: + { + mObj.SetBounds(mObj.Left, mObj.Top, eX - mObj.Left, (int)mObj.Height); + break; + } + + case EdgeEnum.Top: + { + mObj.SetBounds(mObj.Left, eY, (int)mObj.Width, (int)(mObj.Height + (mObj.Top - eY))); + break; + } + + case EdgeEnum.Bottom: + { + mObj.SetBounds(mObj.Left, mObj.Top, (int)mObj.Width, eY - mObj.Top); + break; + } + } + + var argsize = mObj.Size; + KeepInRange(ref argsize); + mObj.Size = argsize; + } + else if (!mMouseDown) + { + int eXo = e.X; + int eYo = e.Y; + int realX = (int)(eXo + mObj.Parent.Offset.X); + int realY = (int)(eYo + mObj.Parent.Offset.Y); + int eXwo = (int)(eXo - mObj.X); + int eYwo = (int)(eYo - mObj.Y); + int eX = (int)(eXwo + mObj.Parent.Offset.X); + int eY = (int)(eYwo + mObj.Parent.Offset.Y); + var eLocation = new Point(eX, eY); + RectangleF extRect = mObj.RectangleExtended; + var oldRect = mObj.Rectangle; + var newRect = new RectangleF(); + newRect.X = extRect.X - oldRect.X; + newRect.Y = extRect.Y - oldRect.Y; + newRect.Width = (extRect.Width - oldRect.Width) / 2f; + newRect.Height = (extRect.Height - oldRect.Height) / 2f; + bool setToNone = false; + bool isOnTop = ReferenceEquals(mObj.Parent.GetObject(new PointF(realX, realY), true), mObj); + if (Enabled && isOnTop) + { + switch (true) + { + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle((int)newRect.X, (int)newRect.Y, (int)newRect.Width, (int)newRect.Height)): + { + mObj.Cursor = Cursors.SizeNWSE; + mEdge = EdgeEnum.TopLeft; + break; + } + + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle((int)mObj.Width, (int)newRect.Y, (int)newRect.Width, (int)newRect.Height)): + { + mObj.Cursor = Cursors.SizeNESW; + mEdge = EdgeEnum.TopRight; + break; + } + + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle((int)mObj.Width, (int)mObj.Height, (int)newRect.Width, (int)newRect.Height)): + { + mObj.Cursor = Cursors.SizeNWSE; + mEdge = EdgeEnum.BottomRight; + break; + } + + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle((int)newRect.X, (int)mObj.Height, (int)newRect.Width, (int)newRect.Height)): + { + mObj.Cursor = Cursors.SizeNESW; + mEdge = EdgeEnum.BottomLeft; + break; + } + + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle((int)-newRect.Width, 0, (int)newRect.Width, (int)mObj.Height)): + { + mObj.Cursor = Cursors.SizeWE; + mEdge = EdgeEnum.Left; + break; + } + + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle((int)mObj.Width, 0, (int)newRect.Width, (int)mObj.Height)): + { + mObj.Cursor = Cursors.SizeWE; + mEdge = EdgeEnum.Right; + break; + } + + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle(0, (int)-newRect.Height, (int)mObj.Width, (int)newRect.Height)): + { + mObj.Cursor = Cursors.SizeNS; + mEdge = EdgeEnum.Top; + break; + } + + case object _ when HelpfulDrawingFunctions.IsPointInRectangle(eLocation, new Rectangle(0, (int)mObj.Height, (int)mObj.Width, (int)newRect.Height)): + { + mObj.Cursor = Cursors.SizeNS; + mEdge = EdgeEnum.Bottom; + break; + } + + default: + { + setToNone = true; + break; + } + } + } + else + { + setToNone = true; + } + + if (setToNone) + { + mObj.Cursor = Cursors.Default; + mEdge = EdgeEnum.None; + } + } + } + + private void mControl_Paint(PaintingObject sender, PaintEventArgs e) + { + // e.Graphics.FillRectangle(brush, rect) + } + + private void mControl_MouseLeave(PaintingObject sender, EventArgs e) + { + if (!sender.Selected) + { + mEdge = EdgeEnum.None; + } + } + + private void mObjParent_ParentChanged(object sender, EventArgs e) + { + mObjParent = mObjControl.Parent; + } + + private void mObj_ParentChanged(PaintingObject sender, EventArgs e) + { + mObjControl = mObj.Parent; + mObjParent = mObjControl?.Parent; + } + } +} \ No newline at end of file diff --git a/Pilz.UI/PaintingControl/PaintingObjectResizing.vb b/Pilz.UI/PaintingControl/PaintingObjectResizing.vb deleted file mode 100644 index 9edbea5..0000000 --- a/Pilz.UI/PaintingControl/PaintingObjectResizing.vb +++ /dev/null @@ -1,177 +0,0 @@ -Imports System.Drawing -Imports System.Windows.Forms -Imports Newtonsoft.Json -Imports Pilz.Drawing - - Friend Class PaintingObjectResizing - - Private WithEvents mObj As PaintingObject - Private WithEvents mObjParent As Control = Nothing - Private WithEvents mObjControl As Control = Nothing - Private mMouseDown As Boolean = False - Private mEdge As EdgeEnum = EdgeEnum.None - Private mWidth As Integer = 4 - Private qWidth As Integer = 4 * 4 - Private rect As New Rectangle - - Public Property Enabled As Boolean = True - Public Property MinimumSize As New SizeF(15, 15) - - Private Enum EdgeEnum - None - Right - Left - Top - Bottom - TopLeft - TopRight - BottomLeft - BottomRight - End Enum - - Public ReadOnly Property IsResizing As Boolean - Get - Return mMouseDown AndAlso mEdge <> EdgeEnum.None - End Get - End Property - - Public Sub New(obj As PaintingObject) - mObj = obj - mObjControl = mObj.Parent - End Sub - - Shared Function ApplyToControl(obj As PaintingObject) As PaintingObjectResizing - Return New PaintingObjectResizing(obj) - End Function - - Private Sub mControl_MouseDown(sender As Object, e As MouseEventArgs) Handles mObj.MouseDown - If e.Button = System.Windows.Forms.MouseButtons.Left Then - mMouseDown = True - End If - End Sub - - Private Sub mControl_MouseUp(sender As Object, e As MouseEventArgs) Handles mObj.MouseUp - mMouseDown = False - - If mObj.Selected Then - mObj.AutoArrangeToGrid() - End If - End Sub - - Private Sub KeepInRange(ByRef size As SizeF) - If size.Height < MinimumSize.Height OrElse size.Width < MinimumSize.Width Then - size = New SizeF(Math.Max(size.Width, MinimumSize.Width), - Math.Max(size.Height, MinimumSize.Height)) - End If - End Sub - - Private Sub mControl_MouseMove(sender As Object, e As MouseEventArgs) Handles mObjControl.MouseMove - If mMouseDown AndAlso mEdge <> EdgeEnum.None Then - - Dim eX As Integer = e.X + mObj.Parent.Offset.X - Dim eY As Integer = e.Y + mObj.Parent.Offset.Y - - Select Case mEdge - Case EdgeEnum.TopLeft - mObj.SetBounds(eX, eY, mObj.Width + (mObj.Left - eX), mObj.Height + (mObj.Top - eY)) - Case EdgeEnum.TopRight - mObj.SetBounds(mObj.Left, eY, eX - mObj.Left, mObj.Height + (mObj.Top - eY)) - Case EdgeEnum.BottomRight - mObj.SetBounds(mObj.Left, mObj.Top, eX - mObj.Left, eY - mObj.Top) - Case EdgeEnum.BottomLeft - mObj.SetBounds(eX, mObj.Top, mObj.Width + (mObj.Left - eX), eY - mObj.Top) - Case EdgeEnum.Left - mObj.SetBounds(eX, mObj.Top, mObj.Width + (mObj.Left - eX), mObj.Height) - Case EdgeEnum.Right - mObj.SetBounds(mObj.Left, mObj.Top, eX - mObj.Left, mObj.Height) - Case EdgeEnum.Top - mObj.SetBounds(mObj.Left, eY, mObj.Width, mObj.Height + (mObj.Top - eY)) - Case EdgeEnum.Bottom - mObj.SetBounds(mObj.Left, mObj.Top, mObj.Width, eY - mObj.Top) - End Select - - KeepInRange(mObj.Size) - - ElseIf Not mMouseDown Then - - Dim eXo As Integer = e.X - Dim eYo As Integer = e.Y - Dim realX As Integer = eXo + mObj.Parent.Offset.X - Dim realY As Integer = eYo + mObj.Parent.Offset.Y - Dim eXwo As Integer = eXo - mObj.X - Dim eYwo As Integer = eYo - mObj.Y - Dim eX As Integer = eXwo + mObj.Parent.Offset.X - Dim eY As Integer = eYwo + mObj.Parent.Offset.Y - Dim eLocation As New Point(eX, eY) - Dim extRect As RectangleF = mObj.RectangleExtended - Dim oldRect As RectangleF = mObj.Rectangle - - Dim newRect As New RectangleF - newRect.X = extRect.X - oldRect.X - newRect.Y = extRect.Y - oldRect.Y - newRect.Width = (extRect.Width - oldRect.Width) / 2 - newRect.Height = (extRect.Height - oldRect.Height) / 2 - - Dim setToNone As Boolean = False - Dim isOnTop As Boolean = mObj.Parent.GetObject(New PointF(realX, realY), True) Is mObj - - If Enabled AndAlso isOnTop Then - Select Case True - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(newRect.X, newRect.Y, newRect.Width, newRect.Height)) - mObj.Cursor = Cursors.SizeNWSE - mEdge = EdgeEnum.TopLeft - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(mObj.Width, newRect.Y, newRect.Width, newRect.Height)) - mObj.Cursor = Cursors.SizeNESW - mEdge = EdgeEnum.TopRight - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(mObj.Width, mObj.Height, newRect.Width, newRect.Height)) - mObj.Cursor = Cursors.SizeNWSE - mEdge = EdgeEnum.BottomRight - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(newRect.X, mObj.Height, newRect.Width, newRect.Height)) - mObj.Cursor = Cursors.SizeNESW - mEdge = EdgeEnum.BottomLeft - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(-newRect.Width, 0, newRect.Width, mObj.Height)) - mObj.Cursor = Cursors.SizeWE - mEdge = EdgeEnum.Left - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(mObj.Width, 0, newRect.Width, mObj.Height)) - mObj.Cursor = Cursors.SizeWE - mEdge = EdgeEnum.Right - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(0, -newRect.Height, mObj.Width, newRect.Height)) - mObj.Cursor = Cursors.SizeNS - mEdge = EdgeEnum.Top - Case HelpfulDrawingFunctions.IsPointInRectangle(eLocation, New Rectangle(0, mObj.Height, mObj.Width, newRect.Height)) - mObj.Cursor = Cursors.SizeNS - mEdge = EdgeEnum.Bottom - Case Else - setToNone = True - End Select - Else - setToNone = True - End If - - If setToNone Then - mObj.Cursor = Cursors.Default - mEdge = EdgeEnum.None - End If - End If - End Sub - - Private Sub mControl_Paint(sender As PaintingObject, e As PaintEventArgs) Handles mObj.Paint - 'e.Graphics.FillRectangle(brush, rect) - End Sub - - Private Sub mControl_MouseLeave(ByVal sender As PaintingObject, ByVal e As EventArgs) Handles mObj.SelectedChanged - If Not sender.Selected Then - mEdge = EdgeEnum.None - End If - End Sub - - Private Sub mObjParent_ParentChanged(sender As Object, e As EventArgs) Handles mObjControl.ParentChanged - mObjParent = mObjControl.Parent - End Sub - - Private Sub mObj_ParentChanged(sender As PaintingObject, e As EventArgs) Handles mObj.ParentChanged - mObjControl = mObj.Parent - mObjParent = mObjControl?.Parent - End Sub - -End Class diff --git a/Pilz.UI/Pilz.UI.vbproj b/Pilz.UI/Pilz.UI.csproj similarity index 71% rename from Pilz.UI/Pilz.UI.vbproj rename to Pilz.UI/Pilz.UI.csproj index ca09a5e..41c8f78 100644 --- a/Pilz.UI/Pilz.UI.vbproj +++ b/Pilz.UI/Pilz.UI.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {827C60BF-4D92-4D39-92F0-4285923266A1} + {3058E1D4-81CA-02C8-10A8-88FBF0A55201} Library Pilz.UI Pilz.UI @@ -12,6 +12,8 @@ Windows v4.7.2 + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -67,6 +69,7 @@ MinimumRecommendedRules.ruleset + @@ -89,62 +92,65 @@ - - - - - - - - - + + + + + + + + + + + + UserControl - - + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - - - + + + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.UI.My.Resources Designer - PaintingControl.vb + PaintingControl.cs MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.UI.My + Settings.Designer.cs - - {1a0b8106-2449-4908-b5e1-a00d8e9cf8f6} + + {A82F006D-E811-06F9-37B9-6A73EC0BCC56} Pilz.Drawing @@ -153,5 +159,5 @@ 12.0.3 - + \ No newline at end of file diff --git a/Pilz.UI/Properties/AssemblyInfo.cs b/Pilz.UI/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c2b5043 --- /dev/null +++ b/Pilz.UI/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("PaintingControls")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("Dr. Schneider Kunststoffwerke GmbH")] +[assembly: AssemblyProduct("PaintingControls")] +[assembly: AssemblyCopyright("Copyright © Pascal Schedel 2018")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("35e33313-ac05-4192-9cc7-c60016d65657")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.UI/Properties/Settings.Designer.cs b/Pilz.UI/Properties/Settings.Designer.cs new file mode 100644 index 0000000..41d30c8 --- /dev/null +++ b/Pilz.UI/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.UI.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.UI/My Project/Settings.settings b/Pilz.UI/Properties/Settings.settings similarity index 100% rename from Pilz.UI/My Project/Settings.settings rename to Pilz.UI/Properties/Settings.settings diff --git a/Pilz.UI/Resources.Designer.cs b/Pilz.UI/Resources.Designer.cs new file mode 100644 index 0000000..33e0b7b --- /dev/null +++ b/Pilz.UI/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.UI.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.UI.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.UI/Resources.resx b/Pilz.UI/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.UI/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.UI/Utilities/DrawingControl.cs b/Pilz.UI/Utilities/DrawingControl.cs new file mode 100644 index 0000000..2a01916 --- /dev/null +++ b/Pilz.UI/Utilities/DrawingControl.cs @@ -0,0 +1,26 @@ +using global::System.Windows.Forms; + +namespace Pilz.UI.Utils +{ + public static class DrawingControl + { + private const int WM_SETREDRAW = 11; + + public static void SuspendDrawing(this Control control) + { + User32Bridge.SendMessage(control.Handle, WM_SETREDRAW, false, 0); + } + + public static void ResumeDrawing(this Control control) + { + control.ResumeDrawing(true); + } + + public static void ResumeDrawing(this Control control, bool redraw) + { + User32Bridge.SendMessage(control.Handle, WM_SETREDRAW, true, 0); + if (redraw) + control.Refresh(); + } + } +} \ No newline at end of file diff --git a/Pilz.UI/Utilities/DrawingControl.vb b/Pilz.UI/Utilities/DrawingControl.vb deleted file mode 100644 index 02b44a8..0000000 --- a/Pilz.UI/Utilities/DrawingControl.vb +++ /dev/null @@ -1,28 +0,0 @@ -Imports System.Runtime.CompilerServices -Imports System.Windows.Forms - -Namespace Utils - - Public Module DrawingControl - - Private Const WM_SETREDRAW = 11 - - - Public Sub SuspendDrawing(control As Control) - SendMessage(control.Handle, WM_SETREDRAW, False, 0) - End Sub - - - Public Sub ResumeDrawing(control As Control) - ResumeDrawing(control, True) - End Sub - - - Public Sub ResumeDrawing(control As Control, redraw As Boolean) - SendMessage(control.Handle, WM_SETREDRAW, True, 0) - If redraw Then control.Refresh() - End Sub - - End Module - -End Namespace diff --git a/Pilz.UI/Utilities/User32Bridge.cs b/Pilz.UI/Utilities/User32Bridge.cs new file mode 100644 index 0000000..d59f89b --- /dev/null +++ b/Pilz.UI/Utilities/User32Bridge.cs @@ -0,0 +1,11 @@ +using System; +using System.Runtime.InteropServices; + +namespace Pilz.UI +{ + public static class User32Bridge + { + [DllImport("user32.dll", CharSet = CharSet.Auto)] + internal static extern int SendMessage(IntPtr hWnd, int Msg, bool wParam, int lParam); + } +} \ No newline at end of file diff --git a/Pilz.UI/Utilities/User32Bridge.vb b/Pilz.UI/Utilities/User32Bridge.vb deleted file mode 100644 index be8d6b6..0000000 --- a/Pilz.UI/Utilities/User32Bridge.vb +++ /dev/null @@ -1,5 +0,0 @@ -Public Module User32Bridge - - Friend Declare Auto Function SendMessage Lib "user32.dll" (hWnd As IntPtr, Msg As Integer, wParam As Boolean, lParam As Integer) As Integer - -End Module diff --git a/Pilz.Win32/Internals/IconExtractor.cs b/Pilz.Win32/Internals/IconExtractor.cs new file mode 100644 index 0000000..442a9ef --- /dev/null +++ b/Pilz.Win32/Internals/IconExtractor.cs @@ -0,0 +1,33 @@ +using System; +using global::System.Drawing; +using global::System.Runtime.InteropServices; +using global::Pilz.Win32.Native; + +namespace Pilz.Win32.Internals +{ + public class IconExtractor + { + + /// + /// Extrahiert das Icon aus einer Datei oder aus einem Ordner. + /// + /// Hier übergeben Sie den Pfad der Datei von dem das Icon extrahiert werden soll. + /// Bei übergabe von true wird ein kleines und bei false ein großes Icon zurück gegeben. + public static Icon ExtractIcon(string FilePath, bool Small) + { + Icon icon; + var shinfo = new SHFILEINFO(); + LibShell32.SHGetFileInfo(FilePath, 0U, ref shinfo, (uint)Math.Truncate((decimal)Marshal.SizeOf(shinfo)), SHFILEINFO.SHGFI_ICON | (Small ? SHFILEINFO.SHGFI_SMALLICON : SHFILEINFO.SHGFI_LARGEICON)); + try + { + icon = Icon.FromHandle(shinfo.hIcon); + } + catch (Exception ex) + { + icon = null; + } + + return icon; + } + } +} \ No newline at end of file diff --git a/Pilz.Win32/Internals/IconExtractor.vb b/Pilz.Win32/Internals/IconExtractor.vb deleted file mode 100644 index d6487b9..0000000 --- a/Pilz.Win32/Internals/IconExtractor.vb +++ /dev/null @@ -1,31 +0,0 @@ -Imports System.Drawing -Imports System.Runtime.InteropServices -Imports Pilz.Win32.Native - -Namespace Internals - - Public Class IconExtractor - - ''' - ''' Extrahiert das Icon aus einer Datei oder aus einem Ordner. - ''' - ''' Hier übergeben Sie den Pfad der Datei von dem das Icon extrahiert werden soll. - ''' Bei übergabe von true wird ein kleines und bei false ein großes Icon zurück gegeben. - Public Shared Function ExtractIcon(FilePath As String, Small As Boolean) As Icon - Dim icon As Icon - Dim shinfo As New SHFILEINFO - - LibShell32.SHGetFileInfo(FilePath, 0, shinfo, Math.Truncate(Marshal.SizeOf(shinfo)), SHFILEINFO.SHGFI_ICON Or If(Small, SHFILEINFO.SHGFI_SMALLICON, SHFILEINFO.SHGFI_LARGEICON)) - - Try - icon = Icon.FromHandle(shinfo.hIcon) - Catch ex As Exception - icon = Nothing - End Try - - Return icon - End Function - - End Class - -End Namespace diff --git a/Pilz.Win32/Mapped/NativeFileInfo.cs b/Pilz.Win32/Mapped/NativeFileInfo.cs new file mode 100644 index 0000000..d8ca55e --- /dev/null +++ b/Pilz.Win32/Mapped/NativeFileInfo.cs @@ -0,0 +1,21 @@ +using global::System.Drawing; +using global::Pilz.Win32.Native; + +namespace Pilz.Win32.Mapped +{ + public class NativeFileInfo + { + public Icon Icon { get; private set; } + public int SystemIconIndex { get; private set; } + public string Displayname { get; private set; } + public string Typename { get; private set; } + + public NativeFileInfo(SHFILEINFO info) + { + Icon = Icon.FromHandle(info.hIcon); + SystemIconIndex = (int)info.iIcon; + Displayname = info.szDisplayName; + Typename = info.szTypeName; + } + } +} \ No newline at end of file diff --git a/Pilz.Win32/Mapped/NativeFileInfo.vb b/Pilz.Win32/Mapped/NativeFileInfo.vb deleted file mode 100644 index 83b2c5c..0000000 --- a/Pilz.Win32/Mapped/NativeFileInfo.vb +++ /dev/null @@ -1,22 +0,0 @@ -Imports System.Drawing -Imports Pilz.Win32.Native - -Namespace Mapped - - Public Class NativeFileInfo - - Public ReadOnly Property Icon As Icon - Public ReadOnly Property SystemIconIndex As Integer - Public ReadOnly Property Displayname As String - Public ReadOnly Property Typename As String - - Public Sub New(info As SHFILEINFO) - Icon = Icon.FromHandle(info.hIcon) - SystemIconIndex = info.iIcon - Displayname = info.szDisplayName - Typename = info.szTypeName - End Sub - - End Class - -End Namespace diff --git a/Pilz.Win32/My Project/Application.Designer.cs b/Pilz.Win32/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz.Win32/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz.Win32/My Project/Application.Designer.vb b/Pilz.Win32/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz.Win32/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz.Win32/My Project/AssemblyInfo.vb b/Pilz.Win32/My Project/AssemblyInfo.vb deleted file mode 100644 index 7215404..0000000 --- a/Pilz.Win32/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz.Win32/My Project/MyNamespace.Static.1.Designer.cs b/Pilz.Win32/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..41147d8 --- /dev/null +++ b/Pilz.Win32/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.Win32.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz.Win32/My Project/MyNamespace.Static.2.Designer.cs b/Pilz.Win32/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..d367869 --- /dev/null +++ b/Pilz.Win32/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.Win32.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz.Win32/My Project/MyNamespace.Static.3.Designer.cs b/Pilz.Win32/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz.Win32/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz.Win32/My Project/Resources.Designer.vb b/Pilz.Win32/My Project/Resources.Designer.vb deleted file mode 100644 index 75efaf8..0000000 --- a/Pilz.Win32/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Win32.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz.Win32/My Project/Settings.Designer.vb b/Pilz.Win32/My Project/Settings.Designer.vb deleted file mode 100644 index 0cc5b4a..0000000 --- a/Pilz.Win32/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.Win32.My.MySettings - Get - Return Global.Pilz.Win32.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz.Win32/Native/LibShell32.cs b/Pilz.Win32/Native/LibShell32.cs new file mode 100644 index 0000000..edbe6f0 --- /dev/null +++ b/Pilz.Win32/Native/LibShell32.cs @@ -0,0 +1,11 @@ +using System; +using System.Runtime.InteropServices; + +namespace Pilz.Win32.Native +{ + public class LibShell32 + { + [DllImport("shell32.dll")] + public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags); + } +} \ No newline at end of file diff --git a/Pilz.Win32/Native/LibShell32.vb b/Pilz.Win32/Native/LibShell32.vb deleted file mode 100644 index 7ce4246..0000000 --- a/Pilz.Win32/Native/LibShell32.vb +++ /dev/null @@ -1,9 +0,0 @@ -Namespace Native - - Public Class LibShell32 - - Public Declare Function SHGetFileInfo Lib "shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As UInteger, ByRef psfi As SHFILEINFO, ByVal cbSizeFileInfo As UInteger, ByVal uFlags As UInteger) As IntPtr - - End Class - -End Namespace diff --git a/Pilz.Win32/Native/SHFILEINFO.cs b/Pilz.Win32/Native/SHFILEINFO.cs new file mode 100644 index 0000000..c467542 --- /dev/null +++ b/Pilz.Win32/Native/SHFILEINFO.cs @@ -0,0 +1,20 @@ +using System; +using global::System.Runtime.InteropServices; + +namespace Pilz.Win32.Native +{ + [StructLayout(LayoutKind.Sequential)] + public struct SHFILEINFO + { + public const uint SHGFI_ICON = 0x100U; + public const uint SHGFI_LARGEICON = 0x0U; + public const uint SHGFI_SMALLICON = 0x1U; + public IntPtr hIcon; + public IntPtr iIcon; + public uint dwAttributes; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + public string szDisplayName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] + public string szTypeName; + } +} \ No newline at end of file diff --git a/Pilz.Win32/Native/SHFILEINFO.vb b/Pilz.Win32/Native/SHFILEINFO.vb deleted file mode 100644 index 2cd55f8..0000000 --- a/Pilz.Win32/Native/SHFILEINFO.vb +++ /dev/null @@ -1,21 +0,0 @@ -Imports System.Runtime.InteropServices - -Namespace Native - - - - Public Structure SHFILEINFO - Public Const SHGFI_ICON As UInteger = &H100 - Public Const SHGFI_LARGEICON As UInteger = &H0 - Public Const SHGFI_SMALLICON As UInteger = &H1 - - Public hIcon As IntPtr - Public iIcon As IntPtr - Public dwAttributes As UInteger - - Public szDisplayName As String - - Public szTypeName As String - End Structure - -End Namespace diff --git a/Pilz.Win32/Pilz.Win32.vbproj b/Pilz.Win32/Pilz.Win32.csproj similarity index 71% rename from Pilz.Win32/Pilz.Win32.vbproj rename to Pilz.Win32/Pilz.Win32.csproj index f47325c..ababe8f 100644 --- a/Pilz.Win32/Pilz.Win32.vbproj +++ b/Pilz.Win32/Pilz.Win32.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497} + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037} Library Pilz.Win32 Pilz.Win32 @@ -13,6 +13,8 @@ v4.7.2 true + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -45,6 +47,7 @@ On + @@ -66,45 +69,48 @@ - - - - + + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.Win32.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.Win32.My + Settings.Designer.cs - + \ No newline at end of file diff --git a/Pilz.Win32/Properties/AssemblyInfo.cs b/Pilz.Win32/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c85a547 --- /dev/null +++ b/Pilz.Win32/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("Pilz.Win32")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("DRSN")] +[assembly: AssemblyProduct("Pilz.Win32")] +[assembly: AssemblyCopyright("Copyright © DRSN 2019")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("30989d46-fe34-48f5-9d28-4da98548e5d7")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz.Win32/Properties/Settings.Designer.cs b/Pilz.Win32/Properties/Settings.Designer.cs new file mode 100644 index 0000000..ba4ed8d --- /dev/null +++ b/Pilz.Win32/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.Win32.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz.Win32/My Project/Settings.settings b/Pilz.Win32/Properties/Settings.settings similarity index 100% rename from Pilz.Win32/My Project/Settings.settings rename to Pilz.Win32/Properties/Settings.settings diff --git a/Pilz.Win32/Resources.Designer.cs b/Pilz.Win32/Resources.Designer.cs new file mode 100644 index 0000000..233c6c4 --- /dev/null +++ b/Pilz.Win32/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.Win32.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Win32.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz.Win32/Resources.resx b/Pilz.Win32/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz.Win32/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz.sln b/Pilz.sln index 0500f97..1886ca4 100644 --- a/Pilz.sln +++ b/Pilz.sln @@ -3,31 +3,31 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28307.329 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz", "Pilz\Pilz.vbproj", "{277D2B83-7613-4C49-9CAB-E080195A6E0C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz", "Pilz\Pilz.csproj", "{9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Drawing", "Pilz.Drawing\Pilz.Drawing.vbproj", "{1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Drawing", "Pilz.Drawing\Pilz.Drawing.csproj", "{A82F006D-E811-06F9-37B9-6A73EC0BCC56}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.UI", "Pilz.UI\Pilz.UI.vbproj", "{827C60BF-4D92-4D39-92F0-4285923266A1}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.UI", "Pilz.UI\Pilz.UI.csproj", "{3058E1D4-81CA-02C8-10A8-88FBF0A55201}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Collections", "Pilz.Collections\Pilz.Collections.vbproj", "{E4B2D294-8479-4014-942D-0B460E453DEA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Collections", "Pilz.Collections\Pilz.Collections.csproj", "{569653FF-4821-0FE5-1675-C1386CD2094A}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Threading", "Pilz.Threading\Pilz.Threading.vbproj", "{D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Threading", "Pilz.Threading\Pilz.Threading.csproj", "{6BECE435-8344-0CB9-2744-617E9F0D201B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.IO", "Pilz.IO\Pilz.IO.csproj", "{877D980E-4F61-0E53-0E8B-5C50B7D1440C}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Win32", "Pilz.Win32\Pilz.Win32.vbproj", "{0BE0428D-AC97-4812-ADFC-6D7D00AEE497}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Win32", "Pilz.Win32\Pilz.Win32.csproj", "{B9C4C3E6-60CF-07E3-2FA4-A7036239D037}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Configuration", "Pilz.Configuration\Pilz.Configuration.vbproj", "{A56C6153-C61F-4B10-BE06-35EB0448CFDC}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Configuration", "Pilz.Configuration\Pilz.Configuration.csproj", "{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Reflection.PluginSystem", "Pilz.Reflection.PluginSystem\Pilz.Reflection.PluginSystem.vbproj", "{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Reflection.PluginSystem", "Pilz.Reflection.PluginSystem\Pilz.Reflection.PluginSystem.csproj", "{45B3D51B-80FB-005A-3932-69D15BEF9F17}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Drawing.Drawing3D.OpenGLFactory", "Pilz.Drawing.Drawing3D.OpenGLRenderer\Pilz.Drawing.Drawing3D.OpenGLFactory.vbproj", "{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Drawing.Drawing3D.OpenGLFactory", "Pilz.Drawing.Drawing3D.OpenGLRenderer\Pilz.Drawing.Drawing3D.OpenGLFactory.csproj", "{ECBB8A61-3BE0-0658-02A4-A7806FD3F824}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Simple3DFileParser", "Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.vbproj", "{AC955819-7910-450C-940C-7C1989483D4B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Simple3DFileParser", "Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.csproj", "{1EB1D972-B548-0AFD-1654-B667EBDF09EB}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.LicenseHelper", "Pilz.LicenseHelper\Pilz.LicenseHelper.csproj", "{67593FF7-C1D1-4529-98C4-61CBD0615F08}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Networking", "Pilz.Networking\Pilz.Networking.vbproj", "{4584B121-09C6-40AC-849B-7E410125EF66}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Networking", "Pilz.Networking\Pilz.Networking.csproj", "{F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Cryptography", "Pilz.Cryptography\Pilz.Cryptography.csproj", "{3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}" EndProject @@ -39,46 +39,46 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Debug|x86.ActiveCfg = Debug|Any CPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Debug|x86.Build.0 = Debug|Any CPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Release|Any CPU.Build.0 = Release|Any CPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Release|x86.ActiveCfg = Release|Any CPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C}.Release|x86.Build.0 = Release|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Debug|x86.ActiveCfg = Debug|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Debug|x86.Build.0 = Debug|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Release|Any CPU.Build.0 = Release|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Release|x86.ActiveCfg = Release|Any CPU - {1A0B8106-2449-4908-B5E1-A00D8E9CF8F6}.Release|x86.Build.0 = Release|Any CPU - {827C60BF-4D92-4D39-92F0-4285923266A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {827C60BF-4D92-4D39-92F0-4285923266A1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {827C60BF-4D92-4D39-92F0-4285923266A1}.Debug|x86.ActiveCfg = Debug|x86 - {827C60BF-4D92-4D39-92F0-4285923266A1}.Debug|x86.Build.0 = Debug|x86 - {827C60BF-4D92-4D39-92F0-4285923266A1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {827C60BF-4D92-4D39-92F0-4285923266A1}.Release|Any CPU.Build.0 = Release|Any CPU - {827C60BF-4D92-4D39-92F0-4285923266A1}.Release|x86.ActiveCfg = Release|x86 - {827C60BF-4D92-4D39-92F0-4285923266A1}.Release|x86.Build.0 = Release|x86 - {E4B2D294-8479-4014-942D-0B460E453DEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E4B2D294-8479-4014-942D-0B460E453DEA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E4B2D294-8479-4014-942D-0B460E453DEA}.Debug|x86.ActiveCfg = Debug|x86 - {E4B2D294-8479-4014-942D-0B460E453DEA}.Debug|x86.Build.0 = Debug|x86 - {E4B2D294-8479-4014-942D-0B460E453DEA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E4B2D294-8479-4014-942D-0B460E453DEA}.Release|Any CPU.Build.0 = Release|Any CPU - {E4B2D294-8479-4014-942D-0B460E453DEA}.Release|x86.ActiveCfg = Release|x86 - {E4B2D294-8479-4014-942D-0B460E453DEA}.Release|x86.Build.0 = Release|x86 - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Debug|x86.ActiveCfg = Debug|x86 - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Debug|x86.Build.0 = Debug|x86 - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Release|Any CPU.Build.0 = Release|Any CPU - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Release|x86.ActiveCfg = Release|x86 - {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Release|x86.Build.0 = Release|x86 + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Debug|x86.ActiveCfg = Debug|Any CPU + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Debug|x86.Build.0 = Debug|Any CPU + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Release|Any CPU.Build.0 = Release|Any CPU + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Release|x86.ActiveCfg = Release|Any CPU + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}.Release|x86.Build.0 = Release|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Debug|x86.ActiveCfg = Debug|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Debug|x86.Build.0 = Debug|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Release|Any CPU.Build.0 = Release|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Release|x86.ActiveCfg = Release|Any CPU + {A82F006D-E811-06F9-37B9-6A73EC0BCC56}.Release|x86.Build.0 = Release|Any CPU + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Debug|x86.ActiveCfg = Debug|x86 + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Debug|x86.Build.0 = Debug|x86 + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Release|Any CPU.Build.0 = Release|Any CPU + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Release|x86.ActiveCfg = Release|x86 + {3058E1D4-81CA-02C8-10A8-88FBF0A55201}.Release|x86.Build.0 = Release|x86 + {569653FF-4821-0FE5-1675-C1386CD2094A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {569653FF-4821-0FE5-1675-C1386CD2094A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {569653FF-4821-0FE5-1675-C1386CD2094A}.Debug|x86.ActiveCfg = Debug|x86 + {569653FF-4821-0FE5-1675-C1386CD2094A}.Debug|x86.Build.0 = Debug|x86 + {569653FF-4821-0FE5-1675-C1386CD2094A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {569653FF-4821-0FE5-1675-C1386CD2094A}.Release|Any CPU.Build.0 = Release|Any CPU + {569653FF-4821-0FE5-1675-C1386CD2094A}.Release|x86.ActiveCfg = Release|x86 + {569653FF-4821-0FE5-1675-C1386CD2094A}.Release|x86.Build.0 = Release|x86 + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Debug|x86.ActiveCfg = Debug|x86 + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Debug|x86.Build.0 = Debug|x86 + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Release|Any CPU.Build.0 = Release|Any CPU + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Release|x86.ActiveCfg = Release|x86 + {6BECE435-8344-0CB9-2744-617E9F0D201B}.Release|x86.Build.0 = Release|x86 {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Debug|Any CPU.Build.0 = Debug|Any CPU {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Debug|x86.ActiveCfg = Debug|x86 @@ -87,46 +87,46 @@ Global {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Release|Any CPU.Build.0 = Release|Any CPU {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Release|x86.ActiveCfg = Release|x86 {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Release|x86.Build.0 = Release|x86 - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Debug|x86.ActiveCfg = Debug|Any CPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Debug|x86.Build.0 = Debug|Any CPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Release|Any CPU.Build.0 = Release|Any CPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Release|x86.ActiveCfg = Release|Any CPU - {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Release|x86.Build.0 = Release|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Debug|x86.ActiveCfg = Debug|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Debug|x86.Build.0 = Debug|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Release|Any CPU.Build.0 = Release|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Release|x86.ActiveCfg = Release|Any CPU - {A56C6153-C61F-4B10-BE06-35EB0448CFDC}.Release|x86.Build.0 = Release|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|x86.ActiveCfg = Debug|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|x86.Build.0 = Debug|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|Any CPU.Build.0 = Release|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|x86.ActiveCfg = Release|Any CPU - {F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|x86.Build.0 = Release|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|x86.ActiveCfg = Debug|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|x86.Build.0 = Debug|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Release|Any CPU.Build.0 = Release|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Release|x86.ActiveCfg = Release|Any CPU - {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Release|x86.Build.0 = Release|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Debug|x86.ActiveCfg = Debug|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Debug|x86.Build.0 = Debug|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Release|Any CPU.Build.0 = Release|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Release|x86.ActiveCfg = Release|Any CPU - {AC955819-7910-450C-940C-7C1989483D4B}.Release|x86.Build.0 = Release|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Debug|x86.ActiveCfg = Debug|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Debug|x86.Build.0 = Debug|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Release|Any CPU.Build.0 = Release|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Release|x86.ActiveCfg = Release|Any CPU + {B9C4C3E6-60CF-07E3-2FA4-A7036239D037}.Release|x86.Build.0 = Release|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Debug|x86.ActiveCfg = Debug|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Debug|x86.Build.0 = Debug|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|Any CPU.Build.0 = Release|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|x86.ActiveCfg = Release|Any CPU + {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|x86.Build.0 = Release|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Debug|x86.ActiveCfg = Debug|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Debug|x86.Build.0 = Debug|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Release|Any CPU.Build.0 = Release|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Release|x86.ActiveCfg = Release|Any CPU + {45B3D51B-80FB-005A-3932-69D15BEF9F17}.Release|x86.Build.0 = Release|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Debug|x86.ActiveCfg = Debug|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Debug|x86.Build.0 = Debug|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Release|Any CPU.Build.0 = Release|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Release|x86.ActiveCfg = Release|Any CPU + {ECBB8A61-3BE0-0658-02A4-A7806FD3F824}.Release|x86.Build.0 = Release|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Debug|x86.ActiveCfg = Debug|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Debug|x86.Build.0 = Debug|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Release|Any CPU.Build.0 = Release|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Release|x86.ActiveCfg = Release|Any CPU + {1EB1D972-B548-0AFD-1654-B667EBDF09EB}.Release|x86.Build.0 = Release|Any CPU {67593FF7-C1D1-4529-98C4-61CBD0615F08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {67593FF7-C1D1-4529-98C4-61CBD0615F08}.Debug|Any CPU.Build.0 = Debug|Any CPU {67593FF7-C1D1-4529-98C4-61CBD0615F08}.Debug|x86.ActiveCfg = Debug|Any CPU @@ -135,14 +135,14 @@ Global {67593FF7-C1D1-4529-98C4-61CBD0615F08}.Release|Any CPU.Build.0 = Release|Any CPU {67593FF7-C1D1-4529-98C4-61CBD0615F08}.Release|x86.ActiveCfg = Release|Any CPU {67593FF7-C1D1-4529-98C4-61CBD0615F08}.Release|x86.Build.0 = Release|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Debug|x86.ActiveCfg = Debug|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Debug|x86.Build.0 = Debug|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Release|Any CPU.Build.0 = Release|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Release|x86.ActiveCfg = Release|Any CPU - {4584B121-09C6-40AC-849B-7E410125EF66}.Release|x86.Build.0 = Release|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Debug|x86.ActiveCfg = Debug|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Debug|x86.Build.0 = Debug|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Release|Any CPU.Build.0 = Release|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Release|x86.ActiveCfg = Release|Any CPU + {F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}.Release|x86.Build.0 = Release|Any CPU {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Debug|Any CPU.Build.0 = Debug|Any CPU {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Debug|x86.ActiveCfg = Debug|Any CPU diff --git a/Pilz.sln.bak b/Pilz.sln.bak index d0c9d60..0500f97 100644 --- a/Pilz.sln.bak +++ b/Pilz.sln.bak @@ -13,9 +13,7 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Collections", "Pilz.Co EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Threading", "Pilz.Threading\Pilz.Threading.vbproj", "{D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.IO", "Pilz.IO\Pilz.IO.vbproj", "{35591965-8339-41A2-8CD3-962ED54670AC}" -EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Cryptography", "Pilz.Cryptography\Pilz.Cryptography.vbproj", "{DF980F5D-820C-4CD3-A865-C40791BF7CE4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.IO", "Pilz.IO\Pilz.IO.csproj", "{877D980E-4F61-0E53-0E8B-5C50B7D1440C}" EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Win32", "Pilz.Win32\Pilz.Win32.vbproj", "{0BE0428D-AC97-4812-ADFC-6D7D00AEE497}" EndProject @@ -31,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.LicenseHelper", "Pilz. EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Pilz.Networking", "Pilz.Networking\Pilz.Networking.vbproj", "{4584B121-09C6-40AC-849B-7E410125EF66}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Cryptography", "Pilz.Cryptography\Pilz.Cryptography.csproj", "{3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,22 +79,14 @@ Global {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Release|Any CPU.Build.0 = Release|Any CPU {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Release|x86.ActiveCfg = Release|x86 {D9C8655E-4F1C-4348-A51C-AB00FD9A14BB}.Release|x86.Build.0 = Release|x86 - {35591965-8339-41A2-8CD3-962ED54670AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {35591965-8339-41A2-8CD3-962ED54670AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {35591965-8339-41A2-8CD3-962ED54670AC}.Debug|x86.ActiveCfg = Debug|x86 - {35591965-8339-41A2-8CD3-962ED54670AC}.Debug|x86.Build.0 = Debug|x86 - {35591965-8339-41A2-8CD3-962ED54670AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {35591965-8339-41A2-8CD3-962ED54670AC}.Release|Any CPU.Build.0 = Release|Any CPU - {35591965-8339-41A2-8CD3-962ED54670AC}.Release|x86.ActiveCfg = Release|x86 - {35591965-8339-41A2-8CD3-962ED54670AC}.Release|x86.Build.0 = Release|x86 - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Debug|x86.ActiveCfg = Debug|Any CPU - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Debug|x86.Build.0 = Debug|Any CPU - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Release|Any CPU.Build.0 = Release|Any CPU - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Release|x86.ActiveCfg = Release|Any CPU - {DF980F5D-820C-4CD3-A865-C40791BF7CE4}.Release|x86.Build.0 = Release|Any CPU + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Debug|x86.ActiveCfg = Debug|x86 + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Debug|x86.Build.0 = Debug|x86 + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Release|Any CPU.Build.0 = Release|Any CPU + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Release|x86.ActiveCfg = Release|x86 + {877D980E-4F61-0E53-0E8B-5C50B7D1440C}.Release|x86.Build.0 = Release|x86 {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Debug|Any CPU.Build.0 = Debug|Any CPU {0BE0428D-AC97-4812-ADFC-6D7D00AEE497}.Debug|x86.ActiveCfg = Debug|Any CPU @@ -151,6 +143,14 @@ Global {4584B121-09C6-40AC-849B-7E410125EF66}.Release|Any CPU.Build.0 = Release|Any CPU {4584B121-09C6-40AC-849B-7E410125EF66}.Release|x86.ActiveCfg = Release|Any CPU {4584B121-09C6-40AC-849B-7E410125EF66}.Release|x86.Build.0 = Release|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Debug|x86.ActiveCfg = Debug|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Debug|x86.Build.0 = Debug|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Release|Any CPU.Build.0 = Release|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Release|x86.ActiveCfg = Release|Any CPU + {3F5988E6-439E-4A9D-B2C6-47EFFB161AC6}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Pilz/GeneralEventArgs/GetValueEventArgs.cs b/Pilz/GeneralEventArgs/GetValueEventArgs.cs new file mode 100644 index 0000000..8c9caf1 --- /dev/null +++ b/Pilz/GeneralEventArgs/GetValueEventArgs.cs @@ -0,0 +1,17 @@ +using System; + +namespace Pilz.GeneralEventArgs +{ + public class GetValueEventArgs : EventArgs + { + public T Value { get; set; } + + public GetValueEventArgs() : base() + { + } + + public GetValueEventArgs(T value) : base() + { + } + } +} \ No newline at end of file diff --git a/Pilz/GeneralEventArgs/GetValueEventArgs.vb b/Pilz/GeneralEventArgs/GetValueEventArgs.vb deleted file mode 100644 index 397e2ed..0000000 --- a/Pilz/GeneralEventArgs/GetValueEventArgs.vb +++ /dev/null @@ -1,18 +0,0 @@ -Namespace GeneralEventArgs - - Public Class GetValueEventArgs(Of T) - Inherits EventArgs - - Public Property Value As T - - Public Sub New() - MyBase.New - End Sub - - Public Sub New(value As T) - MyBase.New - End Sub - - End Class - -End Namespace diff --git a/Pilz/HelpfulFunctions.cs b/Pilz/HelpfulFunctions.cs new file mode 100644 index 0000000..352b6ad --- /dev/null +++ b/Pilz/HelpfulFunctions.cs @@ -0,0 +1,17 @@ +using System.Diagnostics; +using global::System.Windows.Forms; + +namespace Pilz +{ + public static class HelpfulFunctions + { + public static void Sleep(int milliseconds) + { + var stopw = new Stopwatch(); + stopw.Start(); + while (stopw.ElapsedMilliseconds < milliseconds) + Application.DoEvents(); + stopw.Stop(); + } + } +} \ No newline at end of file diff --git a/Pilz/HelpfulFunctions.vb b/Pilz/HelpfulFunctions.vb deleted file mode 100644 index 1418dd3..0000000 --- a/Pilz/HelpfulFunctions.vb +++ /dev/null @@ -1,17 +0,0 @@ -Imports System.Windows.Forms - -Public Module HelpfulFunctions - - Public Sub Sleep(milliseconds As Integer) - Dim stopw As New Stopwatch - - stopw.Start() - - Do While stopw.ElapsedMilliseconds < milliseconds - Application.DoEvents() - Loop - - stopw.Stop() - End Sub - -End Module diff --git a/Pilz/My Project/Application.Designer.cs b/Pilz/My Project/Application.Designer.cs new file mode 100644 index 0000000..2be760e --- /dev/null +++ b/Pilz/My Project/Application.Designer.cs @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + + diff --git a/Pilz/My Project/Application.Designer.vb b/Pilz/My Project/Application.Designer.vb deleted file mode 100644 index 8ab460b..0000000 --- a/Pilz/My Project/Application.Designer.vb +++ /dev/null @@ -1,13 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - diff --git a/Pilz/My Project/AssemblyInfo.vb b/Pilz/My Project/AssemblyInfo.vb deleted file mode 100644 index 900251e..0000000 --- a/Pilz/My Project/AssemblyInfo.vb +++ /dev/null @@ -1,35 +0,0 @@ -Imports System -Imports System.Reflection -Imports System.Runtime.InteropServices - -' Allgemeine Informationen über eine Assembly werden über die folgenden -' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -' die einer Assembly zugeordnet sind. - -' Werte der Assemblyattribute überprüfen - - - - - - - - - - -'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. - - -' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -' -' Hauptversion -' Nebenversion -' Buildnummer -' Revision -' -' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -' übernehmen, indem Sie "*" eingeben: -' - - - diff --git a/Pilz/My Project/MyNamespace.Static.1.Designer.cs b/Pilz/My Project/MyNamespace.Static.1.Designer.cs new file mode 100644 index 0000000..1c30a3d --- /dev/null +++ b/Pilz/My Project/MyNamespace.Static.1.Designer.cs @@ -0,0 +1,192 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Diagnostics; +using Microsoft.VisualBasic; + +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ +/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */ +/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ +/* TODO ERROR: Skipped IfDirectiveTrivia */ +namespace Pilz.My +{ + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */ + internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer + { + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyComputer() : base() + { + } + } + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [HideModuleName()] + [System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")] + internal static class MyProject + { + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Computer")] + internal static MyComputer Computer + { + [DebuggerHidden()] + get + { + return m_ComputerObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_ComputerObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.Application")] + internal static MyApplication Application + { + [DebuggerHidden()] + get + { + return m_AppObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_AppObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.User")] + internal static Microsoft.VisualBasic.ApplicationServices.User User + { + [DebuggerHidden()] + get + { + return m_UserObjectProvider.GetInstance; + } + } + + private readonly static ThreadSafeObjectProvider m_UserObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [System.ComponentModel.Design.HelpKeyword("My.WebServices")] + internal static MyWebServices WebServices + { + [DebuggerHidden()] + get + { + return m_MyWebServicesObjectProvider.GetInstance; + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")] + internal sealed class MyWebServices + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override bool Equals(object o) + { + return base.Equals(o); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override int GetHashCode() + { + return base.GetHashCode(); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + internal new Type GetType() + { + return typeof(MyWebServices); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [DebuggerHidden()] + public override string ToString() + { + return base.ToString(); + } + + [DebuggerHidden()] + private static T Create__Instance__(T instance) where T : new() + { + if (instance == null) + { + return new T(); + } + else + { + return instance; + } + } + + [DebuggerHidden()] + private void Dispose__Instance__(ref T instance) + { + instance = default; + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public MyWebServices() : base() + { + } + } + + private readonly static ThreadSafeObjectProvider m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider(); + /* TODO ERROR: Skipped EndIfDirectiveTrivia */ + /* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.InteropServices.ComVisible(false)] + internal sealed class ThreadSafeObjectProvider where T : new() + { + internal T GetInstance + { + /* TODO ERROR: Skipped IfDirectiveTrivia */ + [DebuggerHidden()] + get + { + var Value = m_Context.Value; + if (Value == null) + { + Value = new T(); + m_Context.Value = Value; + } + + return Value; + } + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + + [DebuggerHidden()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public ThreadSafeObjectProvider() : base() + { + } + + /* TODO ERROR: Skipped IfDirectiveTrivia */ + private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue(); + /* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */ + } + } +} +/* TODO ERROR: Skipped EndIfDirectiveTrivia */ diff --git a/Pilz/My Project/MyNamespace.Static.2.Designer.cs b/Pilz/My Project/MyNamespace.Static.2.Designer.cs new file mode 100644 index 0000000..d99db07 --- /dev/null +++ b/Pilz/My Project/MyNamespace.Static.2.Designer.cs @@ -0,0 +1,253 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +// See Compiler::LoadXmlSolutionExtension +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualBasic; +using Microsoft.VisualBasic.CompilerServices; + +namespace Pilz.My +{ + [Embedded()] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal sealed class InternalXmlHelper + { + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private InternalXmlHelper() + { + } + + public static string get_Value(IEnumerable source) + { + foreach (XElement item in source) + return item.Value; + return null; + } + + public static void set_Value(IEnumerable source, string value) + { + foreach (XElement item in source) + { + item.Value = value; + break; + } + } + + public static string get_AttributeValue(IEnumerable source, XName name) + { + foreach (XElement item in source) + return Conversions.ToString(item.Attribute(name)); + return null; + } + + public static void set_AttributeValue(IEnumerable source, XName name, string value) + { + foreach (XElement item in source) + { + item.SetAttributeValue(name, value); + break; + } + } + + public static string get_AttributeValue(XElement source, XName name) + { + return Conversions.ToString(source.Attribute(name)); + } + + public static void set_AttributeValue(XElement source, XName name, string value) + { + source.SetAttributeValue(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateAttribute(XName name, object value) + { + if (value is null) + { + return null; + } + + return new XAttribute(name, value); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns) + { + var a = new XAttribute(name, ns.NamespaceName); + a.AddAnnotation(ns); + return a; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, object obj) + { + if (obj is object) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem); + } + else + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems); + } + } + } + + return obj; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, IEnumerable obj) + { + if (obj is object) + { + IEnumerable elems = obj as IEnumerable; + if (elems is object) + { + return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement); + } + else + { + return obj.Cast().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject); + } + } + + return obj; + } + + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + private sealed class RemoveNamespaceAttributesClosure + { + private readonly string[] m_inScopePrefixes; + private readonly XNamespace[] m_inScopeNs; + private readonly List m_attributes; + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes) + { + m_inScopePrefixes = inScopePrefixes; + m_inScopeNs = inScopeNs; + m_attributes = attributes; + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal XElement ProcessXElement(XElement elem) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + internal object ProcessObject(object obj) + { + XElement elem = obj as XElement; + if (elem is object) + { + return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem); + } + else + { + return obj; + } + } + } + + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List attributes, XElement e) + { + if (e is object) + { + var a = e.FirstAttribute; + while (a is object) + { + var nextA = a.NextAttribute; + if (a.IsNamespaceDeclaration) + { + var ns = a.Annotation(); + string prefix = a.Name.LocalName; + if (ns is object) + { + if (inScopePrefixes is object && inScopeNs is object) + { + int lastIndex = inScopePrefixes.Length - 1; + for (int i = 0, loopTo = lastIndex; i <= loopTo; i++) + { + string currentInScopePrefix = inScopePrefixes[i]; + var currentInScopeNs = inScopeNs[i]; + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + + if (a is object) + { + // Prefix is not in scope + // Now check whether it's going to be in scope because it is in the attributes list + + if (attributes is object) + { + int lastIndex = attributes.Count - 1; + for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++) + { + var currentA = attributes[i]; + string currentInScopePrefix = currentA.Name.LocalName; + var currentInScopeNs = currentA.Annotation(); + if (currentInScopeNs is object) + { + if (prefix.Equals(currentInScopePrefix)) + { + if (ns == currentInScopeNs) + { + // prefix and namespace match. Remove the unneeded ns attribute + a.Remove(); + } + + // prefix is in scope but refers to something else. Leave the ns attribute. + a = null; + break; + } + } + } + } + + if (a is object) + { + // Prefix is definitely not in scope + a.Remove(); + // namespace is not defined either. Add this attributes list + attributes.Add(a); + } + } + } + } + + a = nextA; + } + } + + return e; + } + } +} \ No newline at end of file diff --git a/Pilz/My Project/MyNamespace.Static.3.Designer.cs b/Pilz/My Project/MyNamespace.Static.3.Designer.cs new file mode 100644 index 0000000..b2b5044 --- /dev/null +++ b/Pilz/My Project/MyNamespace.Static.3.Designer.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.VisualBasic +{ + [Embedded()] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)] + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + [System.Runtime.CompilerServices.CompilerGenerated()] + internal sealed class Embedded : Attribute + { + } +} \ No newline at end of file diff --git a/Pilz/My Project/Resources.Designer.vb b/Pilz/My Project/Resources.Designer.vb deleted file mode 100644 index 748156b..0000000 --- a/Pilz/My Project/Resources.Designer.vb +++ /dev/null @@ -1,63 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' - ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace diff --git a/Pilz/My Project/Settings.Designer.vb b/Pilz/My Project/Settings.Designer.vb deleted file mode 100644 index 4ea8662..0000000 --- a/Pilz/My Project/Settings.Designer.vb +++ /dev/null @@ -1,73 +0,0 @@ -'------------------------------------------------------------------------------ -' -' Dieser Code wurde von einem Tool generiert. -' Laufzeitversion:4.0.30319.42000 -' -' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -' der Code erneut generiert wird. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "Automatische My.Settings-Speicherfunktion" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.Pilz.My.MySettings - Get - Return Global.Pilz.My.MySettings.Default - End Get - End Property - End Module -End Namespace diff --git a/Pilz/Pilz.vbproj b/Pilz/Pilz.csproj similarity index 71% rename from Pilz/Pilz.vbproj rename to Pilz/Pilz.csproj index a45f138..b07bc99 100644 --- a/Pilz/Pilz.vbproj +++ b/Pilz/Pilz.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {277D2B83-7613-4C49-9CAB-E080195A6E0C} + {9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC} Library Pilz Pilz @@ -13,6 +13,8 @@ v4.7.2 true + $(DefaultItemExcludes);$(ProjectDir)**\*.vb + latest true @@ -45,6 +47,7 @@ On + @@ -66,44 +69,47 @@ - - - - + + + + + + + True Application.myapp - + True True Resources.resx - + True Settings.settings True - - + + - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources + + ResXFileCodeGenerator + Resources.Designer.cs + Pilz.My.Resources Designer MyApplicationCodeGenerator - Application.Designer.vb + Application.Designer.cs - + SettingsSingleFileGenerator - My - Settings.Designer.vb + Pilz.My + Settings.Designer.cs - + \ No newline at end of file diff --git a/Pilz/Properties/AssemblyInfo.cs b/Pilz/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8b2bce4 --- /dev/null +++ b/Pilz/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using global::System; +using global::System.Reflection; +using global::System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. + +// Werte der Assemblyattribute überprüfen + +[assembly: AssemblyTitle("Pilz")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("DRSN")] +[assembly: AssemblyProduct("Pilz")] +[assembly: AssemblyCopyright("Copyright © DRSN 2019")] +[assembly: AssemblyTrademark("")] +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird. +[assembly: Guid("c670b282-ffff-446d-b35e-585b4d802996")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + diff --git a/Pilz/Properties/Settings.Designer.cs b/Pilz/Properties/Settings.Designer.cs new file mode 100644 index 0000000..9b39ce8 --- /dev/null +++ b/Pilz/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Pilz.My { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Pilz/My Project/Settings.settings b/Pilz/Properties/Settings.settings similarity index 100% rename from Pilz/My Project/Settings.settings rename to Pilz/Properties/Settings.settings diff --git a/Pilz/Resources.Designer.cs b/Pilz/Resources.Designer.cs new file mode 100644 index 0000000..28ebb8b --- /dev/null +++ b/Pilz/Resources.Designer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +// ------------------------------------------------------------------------------ + +using System.Diagnostics; +using Microsoft.VisualBasic; + +namespace Pilz.My.Resources +{ + + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + [System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [DebuggerNonUserCode()] + [System.Runtime.CompilerServices.CompilerGenerated()] + [HideModuleName()] + internal static class Resources + { + private static System.Resources.ResourceManager resourceMan; + private static System.Globalization.CultureInfo resourceCulture; + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + var temp = new System.Resources.ResourceManager("Pilz.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + + set + { + resourceCulture = value; + } + } + } +} \ No newline at end of file diff --git a/Pilz/Resources.resx b/Pilz/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Pilz/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pilz/Runtime/OSType.cs b/Pilz/Runtime/OSType.cs new file mode 100644 index 0000000..2e21b0a --- /dev/null +++ b/Pilz/Runtime/OSType.cs @@ -0,0 +1,10 @@ + +namespace Pilz.Runtime +{ + public enum OSType + { + Windows, + Linux, + OSX + } +} \ No newline at end of file diff --git a/Pilz/Runtime/OSType.vb b/Pilz/Runtime/OSType.vb deleted file mode 100644 index caf344b..0000000 --- a/Pilz/Runtime/OSType.vb +++ /dev/null @@ -1,9 +0,0 @@ -Namespace Runtime - - Public Enum OSType - Windows - Linux - OSX - End Enum - -End Namespace diff --git a/Pilz/Runtime/RuntimeInformationsEx.cs b/Pilz/Runtime/RuntimeInformationsEx.cs new file mode 100644 index 0000000..2baead2 --- /dev/null +++ b/Pilz/Runtime/RuntimeInformationsEx.cs @@ -0,0 +1,32 @@ +using global::System.Runtime.InteropServices; + +namespace Pilz.Runtime +{ + public static class RuntimeInformationsEx + { + private static OSType? oSType = null; + public static OSType OSType + { + get + { + if (oSType is null) + { + switch (true) + { + case object _ when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): + oSType = OSType.Windows; + break; + case object _ when RuntimeInformation.IsOSPlatform(OSPlatform.Linux): + oSType = OSType.Linux; + break; + case object _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX): + oSType = OSType.OSX; + break; + } + } + + return (OSType)OSType; + } + } + } +} \ No newline at end of file diff --git a/Pilz/Runtime/RuntimeInformationsEx.vb b/Pilz/Runtime/RuntimeInformationsEx.vb deleted file mode 100644 index a52bb99..0000000 --- a/Pilz/Runtime/RuntimeInformationsEx.vb +++ /dev/null @@ -1,28 +0,0 @@ -Imports System.Runtime.InteropServices - -Namespace Runtime - - Public Module RuntimeInformationsEx - - Public ReadOnly Property OSType As OSType - Get - Static t As OSType? = Nothing - - If t Is Nothing Then - Select Case True - Case RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - t = OSType.Windows - Case RuntimeInformation.IsOSPlatform(OSPlatform.Linux) - t = OSType.Linux - Case RuntimeInformation.IsOSPlatform(OSPlatform.OSX) - t = OSType.OSX - End Select - End If - - Return t - End Get - End Property - - End Module - -End Namespace