convert VB to C#
This commit is contained in:
11
Pilz.Collections/My Project/Application.Designer.cs
generated
Normal file
11
Pilz.Collections/My Project/Application.Designer.cs
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
13
Pilz.Collections/My Project/Application.Designer.vb
generated
13
Pilz.Collections/My Project/Application.Designer.vb
generated
@@ -1,13 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
@@ -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
|
||||
|
||||
<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.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
192
Pilz.Collections/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
192
Pilz.Collections/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
@@ -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<MyComputer> m_ComputerObjectProvider = new ThreadSafeObjectProvider<MyComputer>();
|
||||
/* 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<MyApplication> m_AppObjectProvider = new ThreadSafeObjectProvider<MyApplication>();
|
||||
/* 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<Microsoft.VisualBasic.ApplicationServices.User> m_UserObjectProvider = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.User>();
|
||||
/* 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>(T instance) where T : new()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
else
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
private void Dispose__Instance__<T>(ref T instance)
|
||||
{
|
||||
instance = default;
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public MyWebServices() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private readonly static ThreadSafeObjectProvider<MyWebServices> m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider<MyWebServices>();
|
||||
/* 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<T> 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<T> m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue<T>();
|
||||
/* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
253
Pilz.Collections/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
253
Pilz.Collections/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
@@ -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<XElement> source)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return item.Value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_Value(IEnumerable<XElement> source, string value)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
{
|
||||
item.Value = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static string get_AttributeValue(IEnumerable<XElement> source, XName name)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return Conversions.ToString(item.Attribute(name));
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_AttributeValue(IEnumerable<XElement> 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<XAttribute> 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<XAttribute> attributes, IEnumerable obj)
|
||||
{
|
||||
if (obj is object)
|
||||
{
|
||||
IEnumerable<XElement> elems = obj as IEnumerable<XElement>;
|
||||
if (elems is object)
|
||||
{
|
||||
return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj.Cast<object>().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<XAttribute> m_attributes;
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> 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<XAttribute> 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<XNamespace>();
|
||||
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<XNamespace>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Pilz.Collections/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
14
Pilz.Collections/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
63
Pilz.Collections/My Project/Resources.Designer.vb
generated
63
Pilz.Collections/My Project/Resources.Designer.vb
generated
@@ -1,63 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
'''<summary>
|
||||
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
'''<summary>
|
||||
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
73
Pilz.Collections/My Project/Settings.Designer.vb
generated
73
Pilz.Collections/My Project/Settings.Designer.vb
generated
@@ -1,73 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
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
|
||||
@@ -4,7 +4,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E4B2D294-8479-4014-942D-0B460E453DEA}</ProjectGuid>
|
||||
<ProjectGuid>{569653FF-4821-0FE5-1675-C1386CD2094A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
@@ -14,6 +14,8 @@
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(ProjectDir)**\*.vb</DefaultItemExcludes>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -73,6 +75,7 @@
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
@@ -98,48 +101,51 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SimpleHistory\ObjectValueType.vb" />
|
||||
<Compile Include="SimpleHistory\HistoryPoint.vb" />
|
||||
<Compile Include="SimpleHistory\MemberLists.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<Compile Include="My Project\MyNamespace.Static.1.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.2.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.3.Designer.cs" />
|
||||
<Compile Include="SimpleHistory\ObjectValueType.cs" />
|
||||
<Compile Include="SimpleHistory\HistoryPoint.cs" />
|
||||
<Compile Include="SimpleHistory\MemberLists.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="My Project\Application.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<Compile Include="Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="SimpleHistory\ObjectAction.vb" />
|
||||
<Compile Include="SimpleHistory\ObjectBase.vb" />
|
||||
<Compile Include="SimpleHistory\ObjectState.vb" />
|
||||
<Compile Include="SimpleHistory\SimpleHistory.vb" />
|
||||
<Compile Include="SimpleHistory\ObjectAction.cs" />
|
||||
<Compile Include="SimpleHistory\ObjectBase.cs" />
|
||||
<Compile Include="SimpleHistory\ObjectState.cs" />
|
||||
<Compile Include="SimpleHistory\SimpleHistory.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<EmbeddedResource Include="Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Collections.My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
<LastGenOutput>Application.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Collections.My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
35
Pilz.Collections/Properties/AssemblyInfo.cs
Normal file
35
Pilz.Collections/Properties/AssemblyInfo.cs
Normal file
@@ -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.*")>
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
26
Pilz.Collections/Properties/Settings.Designer.cs
generated
Normal file
26
Pilz.Collections/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Pilz.Collections/Resources.Designer.cs
generated
Normal file
69
Pilz.Collections/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,69 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
/// <summary>
|
||||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
/// <summary>
|
||||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
/// </summary>
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Pilz.Collections/Resources.resx
Normal file
117
Pilz.Collections/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -1,12 +0,0 @@
|
||||
Namespace SimpleHistory
|
||||
|
||||
''' <summary>
|
||||
''' Specify which member types you would include.
|
||||
''' </summary>
|
||||
Public Enum ObjectValueType
|
||||
None = 0
|
||||
Field = 1
|
||||
[Property] = 2
|
||||
End Enum
|
||||
|
||||
End Namespace
|
||||
615
Pilz.Collections/SimpleHistory/HistoryPoint.cs
Normal file
615
Pilz.Collections/SimpleHistory/HistoryPoint.cs
Normal file
@@ -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
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Represent some Object States and Actions.
|
||||
/// </summary>
|
||||
public class HistoryPoint
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Represents the Name of this History Point
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; } = "";
|
||||
/// <summary>
|
||||
/// A List of Object States and Actions.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<ObjectBase> Entries { get; private set; } = new List<ObjectBase>();
|
||||
/// <summary>
|
||||
/// Some data can be refered on this HistoryPoint. Don't know, in some situations this can be helpful.
|
||||
/// </summary>
|
||||
public readonly object Tag = null;
|
||||
|
||||
public bool HasEntries<T>() 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="whiteList">Specify which members to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] obj, MemberWhiteList whiteList)
|
||||
{
|
||||
return FromObject(new[] { obj }, ObjectValueType.None, whiteList, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="blackList">Specify which members to exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] obj, MemberBlackList blackList)
|
||||
{
|
||||
return FromObject(new[] { obj }, ObjectValueType.None, blackList, BindingFlags.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="memberName">The member names to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] obj, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="memberName">The member names to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] obj, ObjectValueType membersToStore, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, membersToStore, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="memberName">The member names to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] obj, BindingFlags flags, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, flags, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="memberName">The member names to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] obj, ObjectValueType membersToStore, BindingFlags flags, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, flags, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="whiteList">Specify which members to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, MemberWhiteList whiteList)
|
||||
{
|
||||
return FromObject(new[] { obj }, ObjectValueType.None, whiteList, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="blackList">Specify which members to exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, MemberBlackList blackList)
|
||||
{
|
||||
return FromObject(new[] { obj }, ObjectValueType.None, blackList, BindingFlags.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="memberName">The member names to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, membersToStore, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="memberName">The member names to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, BindingFlags flags, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, flags, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="memberName">The member names to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, BindingFlags flags, params string[] memberName)
|
||||
{
|
||||
return FromObject(obj, flags, true, memberName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
/// <param name="memberName">The member names to include/exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj)
|
||||
{
|
||||
return FromObject(new[] { obj }, ObjectValueType.None, (object)null, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore)
|
||||
{
|
||||
return FromObject(new[] { obj }, membersToStore, (object)null, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="whiteList">Specify which members to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberWhiteList whiteList)
|
||||
{
|
||||
return FromObject(new[] { obj }, membersToStore, whiteList, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="blackList">Specify which members to exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberBlackList blackList)
|
||||
{
|
||||
return FromObject(new[] { obj }, membersToStore, blackList, BindingFlags.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, BindingFlags flags)
|
||||
{
|
||||
return FromObject(new[] { obj }, ObjectValueType.None, (object)null, flags);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, BindingFlags flags)
|
||||
{
|
||||
return FromObject(new[] { obj }, membersToStore, (object)null, flags);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="whiteList">Specify which members to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberWhiteList whiteList, BindingFlags flags)
|
||||
{
|
||||
return FromObject(new[] { obj }, membersToStore, whiteList, flags);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="blackList">Specify which members to exclude.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object obj, ObjectValueType membersToStore, MemberBlackList blackList, BindingFlags flags)
|
||||
{
|
||||
return FromObject(new[] { obj }, membersToStore, blackList, flags);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs)
|
||||
{
|
||||
return FromObject(objs, ObjectValueType.None, (object)null, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore)
|
||||
{
|
||||
return FromObject(objs, membersToStore, (object)null, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="whiteList">Specify which members to include.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberWhiteList whiteList)
|
||||
{
|
||||
return FromObject(objs, membersToStore, whiteList, BindingFlags.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="blackList">Specify which members to exclude.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberBlackList blackList)
|
||||
{
|
||||
return FromObject(objs, membersToStore, blackList, BindingFlags.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs, BindingFlags flags)
|
||||
{
|
||||
return FromObject(objs, ObjectValueType.None, (object)null, flags);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, BindingFlags flags)
|
||||
{
|
||||
return FromObject(objs, membersToStore, (object)null, flags);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="whiteList">Specify which members to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberWhiteList whiteList, BindingFlags flags)
|
||||
{
|
||||
return FromObject(objs, membersToStore, whiteList, flags);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="blackList">Specify which members to exclude.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
public static HistoryPoint FromObject(object[] objs, ObjectValueType membersToStore, MemberBlackList blackList, BindingFlags flags)
|
||||
{
|
||||
return FromObject(objs, membersToStore, blackList, flags);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an History Point with Object States automaticly from input.
|
||||
/// </summary>
|
||||
/// <param name="objs">The objects that should be included.</param>
|
||||
/// <param name="membersToStore">Specify what member types to include.</param>
|
||||
/// <param name="whiteOrBlackList">Specify which members to include.</param>
|
||||
/// <param name="flags">The Binding Flags that the members should have.</param>
|
||||
/// <returns>A History Point with Object States.</returns>
|
||||
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<string>)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<string>)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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combines some History Points to one.
|
||||
/// </summary>
|
||||
/// <param name="hps">An array of History Points to combine.</param>
|
||||
/// <returns>One History Point that contains all Data of inputted History Points.</returns>
|
||||
public static HistoryPoint Concat(params HistoryPoint[] hps)
|
||||
{
|
||||
return Concat(hps.FirstOrDefault()?.Name, hps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combines some History Points to one.
|
||||
/// </summary>
|
||||
/// <param name="hps">An array of History Points to combine.</param>
|
||||
/// <returns>One History Point that contains all Data of inputted History Points.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,543 +0,0 @@
|
||||
Imports System.Reflection
|
||||
|
||||
Namespace SimpleHistory
|
||||
|
||||
''' <summary>
|
||||
''' Represent some Object States and Actions.
|
||||
''' </summary>
|
||||
Public Class HistoryPoint
|
||||
|
||||
''' <summary>
|
||||
''' Represents the Name of this History Point
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Name As String = ""
|
||||
''' <summary>
|
||||
''' A List of Object States and Actions.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public ReadOnly Property Entries As New List(Of ObjectBase)
|
||||
''' <summary>
|
||||
''' Some data can be refered on this HistoryPoint. Don't know, in some situations this can be helpful.
|
||||
''' </summary>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="whiteList">Specify which members to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object(), whiteList As MemberWhiteList) As HistoryPoint
|
||||
Return FromObject({obj}, ObjectValueType.None, CObj(whiteList), BindingFlags.Default)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="blackList">Specify which members to exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object(), blackList As MemberBlackList) As HistoryPoint
|
||||
Return FromObject({obj}, ObjectValueType.None, CObj(blackList), BindingFlags.Default)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="memberName">The member names to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object(), ParamArray memberName As String()) As HistoryPoint
|
||||
Return FromObject(obj, True, memberName)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="memberName">The member names to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object(), membersToStore As ObjectValueType, ParamArray memberName As String()) As HistoryPoint
|
||||
Return FromObject(obj, membersToStore, True, memberName)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="memberName">The member names to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object(), flags As BindingFlags, ParamArray memberName As String()) As HistoryPoint
|
||||
Return FromObject(obj, flags, True, memberName)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="memberName">The member names to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="whiteList">Specify which members to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, whiteList As MemberWhiteList) As HistoryPoint
|
||||
Return FromObject({obj}, ObjectValueType.None, CObj(whiteList), BindingFlags.Default)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="blackList">Specify which members to exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, blackList As MemberBlackList) As HistoryPoint
|
||||
Return FromObject({obj}, ObjectValueType.None, CObj(blackList), BindingFlags.Default)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, ParamArray memberName As String()) As HistoryPoint
|
||||
Return FromObject(obj, True, memberName)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="memberName">The member names to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, ParamArray memberName As String()) As HistoryPoint
|
||||
Return FromObject(obj, membersToStore, True, memberName)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="memberName">The member names to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, flags As BindingFlags, ParamArray memberName As String()) As HistoryPoint
|
||||
Return FromObject(obj, flags, True, memberName)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="memberName">The member names to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <param name="isWhiteList">If true, the memberName-Array has member names that should be included.</param>
|
||||
''' <param name="memberName">The member names to include/exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object) As HistoryPoint
|
||||
Return FromObject({obj}, ObjectValueType.None, CObj(Nothing), BindingFlags.Default)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType) As HistoryPoint
|
||||
Return FromObject({obj}, membersToStore, CObj(Nothing), BindingFlags.Default)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="whiteList">Specify which members to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="blackList">Specify which members to exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, flags As BindingFlags) As HistoryPoint
|
||||
Return FromObject({obj}, ObjectValueType.None, CObj(Nothing), flags)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(obj As Object, membersToStore As ObjectValueType, flags As BindingFlags) As HistoryPoint
|
||||
Return FromObject({obj}, membersToStore, CObj(Nothing), flags)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="whiteList">Specify which members to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The object that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="blackList">Specify which members to exclude.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(objs As Object()) As HistoryPoint
|
||||
Return FromObject(objs, ObjectValueType.None, CObj(Nothing), BindingFlags.Default)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType) As HistoryPoint
|
||||
Return FromObject(objs, membersToStore, CObj(Nothing), BindingFlags.Default)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="whiteList">Specify which members to include.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="blackList">Specify which members to exclude.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(objs As Object(), flags As BindingFlags) As HistoryPoint
|
||||
Return FromObject(objs, ObjectValueType.None, CObj(Nothing), flags)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
Public Shared Function FromObject(objs As Object(), membersToStore As ObjectValueType, flags As BindingFlags) As HistoryPoint
|
||||
Return FromObject(objs, membersToStore, CObj(Nothing), flags)
|
||||
End Function
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="whiteList">Specify which members to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="blackList">Specify which members to exclude.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates an History Point with Object States automaticly from input.
|
||||
''' </summary>
|
||||
''' <param name="objs">The objects that should be included.</param>
|
||||
''' <param name="membersToStore">Specify what member types to include.</param>
|
||||
''' <param name="whiteOrBlackList">Specify which members to include.</param>
|
||||
''' <param name="flags">The Binding Flags that the members should have.</param>
|
||||
''' <returns>A History Point with Object States.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Combines some History Points to one.
|
||||
''' </summary>
|
||||
''' <param name="hps">An array of History Points to combine.</param>
|
||||
''' <returns>One History Point that contains all Data of inputted History Points.</returns>
|
||||
Public Shared Function Concat(ParamArray hps As HistoryPoint()) As HistoryPoint
|
||||
Return Concat(hps.FirstOrDefault?.Name, hps)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Combines some History Points to one.
|
||||
''' </summary>
|
||||
''' <param name="hps">An array of History Points to combine.</param>
|
||||
''' <returns>One History Point that contains all Data of inputted History Points.</returns>
|
||||
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
|
||||
33
Pilz.Collections/SimpleHistory/MemberLists.cs
Normal file
33
Pilz.Collections/SimpleHistory/MemberLists.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pilz.Collections.SimpleHistory
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// List contianing member names to include.
|
||||
/// </summary>
|
||||
public class MemberWhiteList : List<string>
|
||||
{
|
||||
public MemberWhiteList() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public MemberWhiteList(string[] entries) : base(entries)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List contianing member names to exclude
|
||||
/// </summary>
|
||||
public class MemberBlackList : List<string>
|
||||
{
|
||||
public MemberBlackList() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public MemberBlackList(string[] entries) : base(entries)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
Namespace SimpleHistory
|
||||
|
||||
''' <summary>
|
||||
''' List contianing member names to include.
|
||||
''' </summary>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' List contianing member names to exclude
|
||||
''' </summary>
|
||||
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
|
||||
176
Pilz.Collections/SimpleHistory/ObjectAction.cs
Normal file
176
Pilz.Collections/SimpleHistory/ObjectAction.cs
Normal file
@@ -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<object> ParametersUndo { get; private set; } = new List<object>();
|
||||
public List<object> ParametersRedo { get; private set; } = new List<object>();
|
||||
public MethodInfo MethodUndo { get; set; } = null;
|
||||
public MethodInfo MethodRedo { get; set; } = null;
|
||||
public bool AutogenerateObject { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
public ObjectAction()
|
||||
{
|
||||
}
|
||||
|
||||
private object GetMethodInfo(object obj, string name, BindingFlags flags)
|
||||
{
|
||||
return obj.GetType().GetMethod(name, flags);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
/// <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
public ObjectAction(object obj, string methodNameUndo, string methodNameRedo) : this(obj, methodNameUndo, methodNameRedo, Array.Empty<object>(), Array.Empty<object>(), BindingFlags.Default, BindingFlags.Default)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
/// <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
/// <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
/// <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
public ObjectAction(object obj, string methodNameUndo, string methodNameRedo, object[] paramsUndo, object[] paramsRedo) : this(obj, methodNameUndo, methodNameRedo, paramsUndo, paramsRedo, BindingFlags.Default, BindingFlags.Default)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
/// <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
/// <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
/// <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
/// <param name="methodFlagsUndo">The Binding Flags of Methode on Undo.</param>
|
||||
/// <param name="methodFlagsRedo">The Binding Flags of Methode on Redo.</param>
|
||||
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));
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
/// <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
/// <param name="methodFlagsUndo">The Binding Flags of Methode on Undo.</param>
|
||||
/// <param name="methodFlagsRedo">The Binding Flags of Methode on Redo.</param>
|
||||
public ObjectAction(object obj, string methodNameUndo, string methodNameRedo, BindingFlags methodFlagsUndo, BindingFlags methodFlagsRedo) : this(obj, methodNameUndo, methodNameRedo, Array.Empty<object>(), Array.Empty<object>(), methodFlagsUndo, methodFlagsRedo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodUndo">The MethodInfo of the methode to call on Undo.</param>
|
||||
/// <param name="methodRedo">The MethodInfo of the methode to call on Redo.</param>
|
||||
public ObjectAction(object obj, MethodInfo methodUndo, MethodInfo methodRedo)
|
||||
{
|
||||
Object = obj;
|
||||
MethodUndo = methodUndo;
|
||||
MethodRedo = methodRedo;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodUndo">The MethodInfo of the methode to call on Undo.</param>
|
||||
/// <param name="methodRedo">The MethodInfo of the methode to call on Redo.</param>
|
||||
/// <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
/// <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
public ObjectAction(object obj, MethodInfo methodUndo, MethodInfo methodRedo, object[] paramsUndo, object[] paramsRedo) : this(obj, methodUndo, methodRedo)
|
||||
{
|
||||
ParametersUndo.AddRange(paramsUndo);
|
||||
ParametersRedo.AddRange(paramsRedo);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodUndo">The Delegate of the methode to call on Undo.</param>
|
||||
/// <param name="methodRedo">The Delegate of the methode to call on Redo.</param>
|
||||
public ObjectAction(object obj, Delegate methodUndo, Delegate methodRedo)
|
||||
{
|
||||
Object = obj;
|
||||
MethodUndo = methodUndo.Method;
|
||||
MethodRedo = methodRedo.Method;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodUndo">The Delegate of the methode to call on Undo.</param>
|
||||
/// <param name="methodRedo">The Delegate of the methode to call on Redo.</param>
|
||||
/// <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
/// <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
public ObjectAction(object obj, Delegate methodUndo, Delegate methodRedo, object[] paramsUndo, object[] paramsRedo) : this(obj, methodUndo, methodRedo)
|
||||
{
|
||||
ParametersUndo.AddRange(paramsUndo);
|
||||
ParametersRedo.AddRange(paramsRedo);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new Instance of Object Action.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
/// <param name="methodUndo">The Action of the methode to call on Undo.</param>
|
||||
/// <param name="methodRedo">The Action of the methode to call on Redo.</param>
|
||||
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>());
|
||||
Object = classObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
''' <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
Public Sub New(obj As Object, methodNameUndo As String, methodNameRedo As String)
|
||||
Me.New(obj, methodNameUndo, methodNameRedo, {}, {}, BindingFlags.Default, BindingFlags.Default)
|
||||
End Sub
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
''' <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
''' <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
''' <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
''' <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
''' <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
''' <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
''' <param name="methodFlagsUndo">The Binding Flags of Methode on Undo.</param>
|
||||
''' <param name="methodFlagsRedo">The Binding Flags of Methode on Redo.</param>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodNameUndo">The name of the methode to call on Undo.</param>
|
||||
''' <param name="methodNameRedo">The name of the methode to call on Redo.</param>
|
||||
''' <param name="methodFlagsUndo">The Binding Flags of Methode on Undo.</param>
|
||||
''' <param name="methodFlagsRedo">The Binding Flags of Methode on Redo.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodUndo">The MethodInfo of the methode to call on Undo.</param>
|
||||
''' <param name="methodRedo">The MethodInfo of the methode to call on Redo.</param>
|
||||
Public Sub New(obj As Object, methodUndo As MethodInfo, methodRedo As MethodInfo)
|
||||
[Object] = obj
|
||||
Me.MethodUndo = methodUndo
|
||||
Me.MethodRedo = methodRedo
|
||||
End Sub
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodUndo">The MethodInfo of the methode to call on Undo.</param>
|
||||
''' <param name="methodRedo">The MethodInfo of the methode to call on Redo.</param>
|
||||
''' <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
''' <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodUndo">The Delegate of the methode to call on Undo.</param>
|
||||
''' <param name="methodRedo">The Delegate of the methode to call on Redo.</param>
|
||||
Public Sub New(obj As Object, methodUndo As [Delegate], methodRedo As [Delegate])
|
||||
[Object] = obj
|
||||
Me.MethodUndo = methodUndo.Method
|
||||
Me.MethodRedo = methodRedo.Method
|
||||
End Sub
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodUndo">The Delegate of the methode to call on Undo.</param>
|
||||
''' <param name="methodRedo">The Delegate of the methode to call on Redo.</param>
|
||||
''' <param name="paramsUndo">The parameters for calling the methode on Undo.</param>
|
||||
''' <param name="paramsRedo">The parameters for calling the methode on Redo.</param>
|
||||
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
|
||||
''' <summary>
|
||||
''' Creates a new Instance of Object Action.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Objects that contains the methodes to call.</param>
|
||||
''' <param name="methodUndo">The Action of the methode to call on Undo.</param>
|
||||
''' <param name="methodRedo">The Action of the methode to call on Redo.</param>
|
||||
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
|
||||
10
Pilz.Collections/SimpleHistory/ObjectBase.cs
Normal file
10
Pilz.Collections/SimpleHistory/ObjectBase.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
98
Pilz.Collections/SimpleHistory/ObjectState.cs
Normal file
98
Pilz.Collections/SimpleHistory/ObjectState.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using global::System.Reflection;
|
||||
|
||||
namespace Pilz.Collections.SimpleHistory
|
||||
{
|
||||
public class ObjectState : ObjectBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The Object including the members to patch.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object Object { get; set; } = null;
|
||||
/// <summary>
|
||||
/// The name of the Member to patch.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string MemberName { get; set; } = "";
|
||||
/// <summary>
|
||||
/// The Value that should be patched.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object ValueToPatch { get; set; } = null;
|
||||
/// <summary>
|
||||
/// The member types to include at searching for the member.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ObjectValueType MemberType { get; set; } = ObjectValueType.Field;
|
||||
/// <summary>
|
||||
/// The Binding Flags that are used at searching for the member.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public BindingFlags MemberFlags { get; set; } = BindingFlags.Default;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Instance of ObjectState from input.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Object including the members to patch.</param>
|
||||
/// <param name="valname">The name of the Member to patch.</param>
|
||||
/// <param name="valToPatch">The member types to include at searching for the member.</param>
|
||||
/// <param name="valtype">The Binding Flags that are used at searching for the member.</param>
|
||||
public ObjectState(object obj, string valname, object valToPatch, ObjectValueType valtype)
|
||||
{
|
||||
Object = obj;
|
||||
MemberName = valname;
|
||||
ValueToPatch = valToPatch;
|
||||
MemberType = valtype;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Instance of ObjectState.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
Imports System.Reflection
|
||||
|
||||
Namespace SimpleHistory
|
||||
|
||||
Public Class ObjectState
|
||||
Inherits ObjectBase
|
||||
|
||||
''' <summary>
|
||||
''' The Object including the members to patch.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property [Object] As Object = Nothing
|
||||
''' <summary>
|
||||
''' The name of the Member to patch.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property MemberName As String = ""
|
||||
''' <summary>
|
||||
''' The Value that should be patched.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property ValueToPatch As Object = Nothing
|
||||
''' <summary>
|
||||
''' The member types to include at searching for the member.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property MemberType As ObjectValueType = ObjectValueType.Field
|
||||
''' <summary>
|
||||
''' The Binding Flags that are used at searching for the member.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property MemberFlags As BindingFlags = BindingFlags.Default
|
||||
|
||||
''' <summary>
|
||||
''' Creates a new Instance of ObjectState from input.
|
||||
''' </summary>
|
||||
''' <param name="obj">The Object including the members to patch.</param>
|
||||
''' <param name="valname">The name of the Member to patch.</param>
|
||||
''' <param name="valToPatch">The member types to include at searching for the member.</param>
|
||||
''' <param name="valtype">The Binding Flags that are used at searching for the member.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Creates a new Instance of ObjectState.
|
||||
''' </summary>
|
||||
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
|
||||
14
Pilz.Collections/SimpleHistory/ObjectValueType.cs
Normal file
14
Pilz.Collections/SimpleHistory/ObjectValueType.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
namespace Pilz.Collections.SimpleHistory
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Specify which member types you would include.
|
||||
/// </summary>
|
||||
public enum ObjectValueType
|
||||
{
|
||||
None = 0,
|
||||
Field = 1,
|
||||
Property = 2
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
Namespace SimpleHistory
|
||||
|
||||
''' <summary>
|
||||
''' Specify which member types you would include.
|
||||
''' </summary>
|
||||
Public Enum ObjectValueType
|
||||
None = 0
|
||||
Field = 1
|
||||
[Property] = 2
|
||||
End Enum
|
||||
|
||||
End Namespace
|
||||
104
Pilz.Collections/SimpleHistory/SimpleHistory.cs
Normal file
104
Pilz.Collections/SimpleHistory/SimpleHistory.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
|
||||
namespace Pilz.Collections.SimpleHistory
|
||||
{
|
||||
public class HistoryStack
|
||||
{
|
||||
private Stack<HistoryPoint> stackPast = new Stack<HistoryPoint>();
|
||||
private Stack<HistoryPoint> stackFuture = new Stack<HistoryPoint>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the count of history points.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ChangesCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return Conversions.ToBoolean(stackPast.Count);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the History has past changes.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool HasChanges()
|
||||
{
|
||||
return stackPast.Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Patch Object States and call Undo Actions.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Patch Object States and call Redo Actions.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear the History.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
stackPast.Clear();
|
||||
stackFuture.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Store a History Point.
|
||||
/// </summary>
|
||||
/// <param name="point">The History Point to add to the past changes.</param>
|
||||
/// <param name="newName">The name to set for the History Point.</param>
|
||||
public void Store(HistoryPoint point, string newName)
|
||||
{
|
||||
point.Name = newName;
|
||||
Store(point);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Store a History Point.
|
||||
/// </summary>
|
||||
/// <param name="point">The History Point to add to the past changes.</param>
|
||||
public void Store(HistoryPoint point)
|
||||
{
|
||||
stackPast.Push(point);
|
||||
stackFuture.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
''' <summary>
|
||||
''' Gets the count of history points.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public ReadOnly Property ChangesCount As Boolean
|
||||
Get
|
||||
Return stackPast.Count
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' Checks if the History has past changes.
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Function HasChanges() As Boolean
|
||||
Return stackPast.Count > 0
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Patch Object States and call Undo Actions.
|
||||
''' </summary>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Patch Object States and call Redo Actions.
|
||||
''' </summary>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Clear the History.
|
||||
''' </summary>
|
||||
Public Sub Clear()
|
||||
stackPast.Clear()
|
||||
stackFuture.Clear()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Store a History Point.
|
||||
''' </summary>
|
||||
''' <param name="point">The History Point to add to the past changes.</param>
|
||||
''' <param name="newName">The name to set for the History Point.</param>
|
||||
Public Sub Store(point As HistoryPoint, newName As String)
|
||||
point.Name = newName
|
||||
Store(point)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Store a History Point.
|
||||
''' </summary>
|
||||
''' <param name="point">The History Point to add to the past changes.</param>
|
||||
Public Sub Store(point As HistoryPoint)
|
||||
stackPast.Push(point)
|
||||
stackFuture.Clear()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
113
Pilz.Configuration/AutoSaveConfigurationManager.cs
Normal file
113
Pilz.Configuration/AutoSaveConfigurationManager.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
13
Pilz.Configuration/ConfigurationManager.cs
Normal file
13
Pilz.Configuration/ConfigurationManager.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
namespace Pilz.Configuration
|
||||
{
|
||||
public abstract class ConfigurationManager
|
||||
{
|
||||
public SimpleConfiguration Configuration { get; private set; }
|
||||
|
||||
internal void SetConfiguration(SimpleConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
104
Pilz.Configuration/ConfigurationManagerList.cs
Normal file
104
Pilz.Configuration/ConfigurationManagerList.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using global::Pilz.GeneralEventArgs;
|
||||
|
||||
namespace Pilz.Configuration
|
||||
{
|
||||
public class ConfigurationManagerList : IList<ConfigurationManager>
|
||||
{
|
||||
public event GettingParentManagerEventHandler GettingParentManager;
|
||||
|
||||
public delegate void GettingParentManagerEventHandler(object sender, GetValueEventArgs<SimpleConfiguration> e);
|
||||
|
||||
private readonly List<ConfigurationManager> myList = new List<ConfigurationManager>();
|
||||
|
||||
private object GetParentManager()
|
||||
{
|
||||
var args = new GetValueEventArgs<SimpleConfiguration>();
|
||||
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<ConfigurationManager> GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return myList.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
139
Pilz.Configuration/ConfigurationSerializer.cs
Normal file
139
Pilz.Configuration/ConfigurationSerializer.cs
Normal file
@@ -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<JsonSerializer> e);
|
||||
|
||||
private static JsonSerializer GetJsonSerializer(SimpleConfiguration instance)
|
||||
{
|
||||
var args = new GetValueEventArgs<JsonSerializer>(JsonSerializer.CreateDefault());
|
||||
GettingJsonSerializer?.Invoke(instance, args);
|
||||
return args.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given instance to a string and return it.
|
||||
/// </summary>
|
||||
/// <param name="instance">The configuration instance that should be serialized.</param>
|
||||
/// <returns>The content of the configuration instance as string.</returns>
|
||||
public static string WriteToString(SimpleConfiguration instance)
|
||||
{
|
||||
var tw = new StringWriter();
|
||||
GetJsonSerializer(instance).Serialize(tw, instance);
|
||||
string txt = tw.ToString();
|
||||
tw.Close();
|
||||
return txt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write the given instance to a given stream.
|
||||
/// </summary>
|
||||
/// <param name="instance">The configuration instance that should be serialized.</param>
|
||||
/// <param name="stream">The stream where the content should be written to.</param>
|
||||
public static void WriteToStream(SimpleConfiguration instance, Stream stream)
|
||||
{
|
||||
var sr = new StreamWriter(stream);
|
||||
sr.Write(WriteToString(instance));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given instance to the given filePath as text file.
|
||||
/// </summary>
|
||||
/// <param name="instance">The configuration instance that should be serialized.</param>
|
||||
/// <param name="filePath">The file path where the content should be written to. The file will be created or overwritten.</param>
|
||||
public static void WriteToFile(SimpleConfiguration instance, string filePath)
|
||||
{
|
||||
var fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
|
||||
WriteToStream(instance, fs);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a configuratin from the given string and returns an instance of it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
/// <param name="content">The content of the configuration as string.</param>
|
||||
/// <returns></returns>
|
||||
public static T ReadFromString<T>(string content) where T : SimpleConfiguration
|
||||
{
|
||||
var sr = new StringReader(content);
|
||||
T instance = (T)GetJsonSerializer(null).Deserialize(sr, typeof(T));
|
||||
sr.Close();
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a configuration from the given string and put them to the given instance.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to populate with the configuration.</param>
|
||||
/// <param name="content">The content of the configuration as string.</param>
|
||||
public static void ReadFromString(SimpleConfiguration instance, string content)
|
||||
{
|
||||
var sr = new StringReader(content);
|
||||
GetJsonSerializer(null).Populate(sr, content);
|
||||
sr.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a configuratin from the given string and returns an instance of it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
/// <param name="stream">The stream with the content of the configuration.</param>
|
||||
/// <returns></returns>
|
||||
public static T ReadFromStream<T>(Stream stream) where T : SimpleConfiguration
|
||||
{
|
||||
return ReadFromString<T>(GetContentOfStream(stream));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a configuration from the given string and put them to the given instance.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to populate with the configuration.</param>
|
||||
/// <param name="stream">The stream with the content of the configuration.</param>
|
||||
public static void ReadFromStream(SimpleConfiguration instance, Stream stream)
|
||||
{
|
||||
ReadFromString(instance, GetContentOfStream(stream));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a configuratin from the given string and returns an instance of it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
/// <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
/// <returns></returns>
|
||||
public static T ReadFromFile<T>(string filePath) where T : SimpleConfiguration
|
||||
{
|
||||
return ReadFromString<T>(GetContentOfFile(filePath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a configuration from the given string and put them to the given instance.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to populate with the configuration.</param>
|
||||
/// <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
''' <summary>
|
||||
''' Writes the given instance to a string and return it.
|
||||
''' </summary>
|
||||
''' <param name="instance">The configuration instance that should be serialized.</param>
|
||||
''' <returns>The content of the configuration instance as string.</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Write the given instance to a given stream.
|
||||
''' </summary>
|
||||
''' <param name="instance">The configuration instance that should be serialized.</param>
|
||||
''' <param name="stream">The stream where the content should be written to.</param>
|
||||
Public Sub WriteToStream(instance As SimpleConfiguration, stream As Stream)
|
||||
Dim sr As New StreamWriter(stream)
|
||||
sr.Write(WriteToString(instance))
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Writes the given instance to the given filePath as text file.
|
||||
''' </summary>
|
||||
''' <param name="instance">The configuration instance that should be serialized.</param>
|
||||
''' <param name="filePath">The file path where the content should be written to. The file will be created or overwritten.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Reads a configuratin from the given string and returns an instance of it.
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
''' <param name="content">The content of the configuration as string.</param>
|
||||
''' <returns></returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Read a configuration from the given string and put them to the given instance.
|
||||
''' </summary>
|
||||
''' <param name="instance">The instance to populate with the configuration.</param>
|
||||
''' <param name="content">The content of the configuration as string.</param>
|
||||
Public Sub ReadFromString(instance As SimpleConfiguration, content As String)
|
||||
Dim sr As New StringReader(content)
|
||||
GetJsonSerializer(Nothing).Populate(sr, content)
|
||||
sr.Close()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Reads a configuratin from the given string and returns an instance of it.
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
''' <param name="stream">The stream with the content of the configuration.</param>
|
||||
''' <returns></returns>
|
||||
Public Function ReadFromStream(Of T As SimpleConfiguration)(stream As Stream) As T
|
||||
Return ReadFromString(Of T)(GetContentOfStream(stream))
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Read a configuration from the given string and put them to the given instance.
|
||||
''' </summary>
|
||||
''' <param name="instance">The instance to populate with the configuration.</param>
|
||||
''' <param name="stream">The stream with the content of the configuration.</param>
|
||||
Public Sub ReadFromStream(instance As SimpleConfiguration, stream As Stream)
|
||||
ReadFromString(instance, GetContentOfStream(stream))
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Reads a configuratin from the given string and returns an instance of it.
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
''' <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
''' <returns></returns>
|
||||
Public Function ReadFromFile(Of T As SimpleConfiguration)(filePath As String) As T
|
||||
Return ReadFromString(Of T)(GetContentOfFile(filePath))
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Read a configuration from the given string and put them to the given instance.
|
||||
''' </summary>
|
||||
''' <param name="instance">The instance to populate with the configuration.</param>
|
||||
''' <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
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
|
||||
12
Pilz.Configuration/ISettingsManager.cs
Normal file
12
Pilz.Configuration/ISettingsManager.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
namespace Pilz.Configuration
|
||||
{
|
||||
public interface ISettingsManager
|
||||
{
|
||||
string ConfigFilePath { get; set; }
|
||||
|
||||
void Save();
|
||||
void Load();
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
Public Interface ISettingsManager
|
||||
Property ConfigFilePath As String
|
||||
Sub Save()
|
||||
Sub Load()
|
||||
Sub Reset()
|
||||
End Interface
|
||||
11
Pilz.Configuration/My Project/Application.Designer.cs
generated
Normal file
11
Pilz.Configuration/My Project/Application.Designer.cs
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
@@ -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
|
||||
|
||||
<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.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
192
Pilz.Configuration/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
192
Pilz.Configuration/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
@@ -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<MyComputer> m_ComputerObjectProvider = new ThreadSafeObjectProvider<MyComputer>();
|
||||
/* 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<MyApplication> m_AppObjectProvider = new ThreadSafeObjectProvider<MyApplication>();
|
||||
/* 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<Microsoft.VisualBasic.ApplicationServices.User> m_UserObjectProvider = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.User>();
|
||||
/* 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>(T instance) where T : new()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
else
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
private void Dispose__Instance__<T>(ref T instance)
|
||||
{
|
||||
instance = default;
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public MyWebServices() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private readonly static ThreadSafeObjectProvider<MyWebServices> m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider<MyWebServices>();
|
||||
/* 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<T> 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<T> m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue<T>();
|
||||
/* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
253
Pilz.Configuration/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
253
Pilz.Configuration/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
@@ -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<XElement> source)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return item.Value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_Value(IEnumerable<XElement> source, string value)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
{
|
||||
item.Value = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static string get_AttributeValue(IEnumerable<XElement> source, XName name)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return Conversions.ToString(item.Attribute(name));
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_AttributeValue(IEnumerable<XElement> 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<XAttribute> 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<XAttribute> attributes, IEnumerable obj)
|
||||
{
|
||||
if (obj is object)
|
||||
{
|
||||
IEnumerable<XElement> elems = obj as IEnumerable<XElement>;
|
||||
if (elems is object)
|
||||
{
|
||||
return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj.Cast<object>().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<XAttribute> m_attributes;
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> 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<XAttribute> 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<XNamespace>();
|
||||
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<XNamespace>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Pilz.Configuration/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
14
Pilz.Configuration/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
63
Pilz.Configuration/My Project/Resources.Designer.vb
generated
63
Pilz.Configuration/My Project/Resources.Designer.vb
generated
@@ -1,63 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
'''<summary>
|
||||
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
'''<summary>
|
||||
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
73
Pilz.Configuration/My Project/Settings.Designer.vb
generated
73
Pilz.Configuration/My Project/Settings.Designer.vb
generated
@@ -1,73 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
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
|
||||
@@ -4,7 +4,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A56C6153-C61F-4B10-BE06-35EB0448CFDC}</ProjectGuid>
|
||||
<ProjectGuid>{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Pilz.Configuration</RootNamespace>
|
||||
<AssemblyName>Pilz.Configuration</AssemblyName>
|
||||
@@ -13,6 +13,8 @@
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(ProjectDir)**\*.vb</DefaultItemExcludes>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -45,6 +47,7 @@
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
@@ -66,52 +69,55 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConfigurationManager.vb" />
|
||||
<Compile Include="ConfigurationManagerList.vb" />
|
||||
<Compile Include="ConfigurationSerializer.vb" />
|
||||
<Compile Include="AutoSaveConfigurationManager.vb" />
|
||||
<Compile Include="SimpleConfiguration.vb" />
|
||||
<Compile Include="ISettingsManager.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<Compile Include="My Project\MyNamespace.Static.1.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.2.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.3.Designer.cs" />
|
||||
<Compile Include="ConfigurationManager.cs" />
|
||||
<Compile Include="ConfigurationManagerList.cs" />
|
||||
<Compile Include="ConfigurationSerializer.cs" />
|
||||
<Compile Include="AutoSaveConfigurationManager.cs" />
|
||||
<Compile Include="SimpleConfiguration.cs" />
|
||||
<Compile Include="ISettingsManager.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="My Project\Application.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<Compile Include="Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="SettingsBase.vb" />
|
||||
<Compile Include="SettingsManager.vb" />
|
||||
<Compile Include="SettingsBase.cs" />
|
||||
<Compile Include="SettingsManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<EmbeddedResource Include="Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Configuration.My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
<LastGenOutput>Application.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Configuration.My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pilz\Pilz.vbproj">
|
||||
<Project>{277D2B83-7613-4C49-9CAB-E080195A6E0C}</Project>
|
||||
<ProjectReference Include="..\Pilz\Pilz.csproj">
|
||||
<Project>{9559AAE8-BA4B-03B8-1EF3-2AFE7BCD5AAC}</Project>
|
||||
<Name>Pilz</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
@@ -120,5 +126,5 @@
|
||||
<Version>12.0.3</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
35
Pilz.Configuration/Properties/AssemblyInfo.cs
Normal file
35
Pilz.Configuration/Properties/AssemblyInfo.cs
Normal file
@@ -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.*")>
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
26
Pilz.Configuration/Properties/Settings.Designer.cs
generated
Normal file
26
Pilz.Configuration/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Pilz.Configuration/Resources.Designer.cs
generated
Normal file
69
Pilz.Configuration/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,69 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
/// <summary>
|
||||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
/// <summary>
|
||||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
/// </summary>
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Pilz.Configuration/Resources.resx
Normal file
117
Pilz.Configuration/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
26
Pilz.Configuration/SettingsBase.cs
Normal file
26
Pilz.Configuration/SettingsBase.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
Imports Newtonsoft.Json
|
||||
|
||||
Public MustInherit Class SettingsBase
|
||||
|
||||
Public Sub New()
|
||||
ResetValues()
|
||||
End Sub
|
||||
|
||||
<JsonIgnore>
|
||||
Friend _settingsManager As ISettingsManager
|
||||
<JsonIgnore>
|
||||
Public ReadOnly Property SettingsManager As ISettingsManager
|
||||
Get
|
||||
Return _settingsManager
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public MustOverride Sub ResetValues()
|
||||
|
||||
End Class
|
||||
161
Pilz.Configuration/SettingsManager.cs
Normal file
161
Pilz.Configuration/SettingsManager.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using global::System.IO;
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pilz.Configuration
|
||||
{
|
||||
public sealed class SettingsManager<T> : 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<Type>());
|
||||
if (ctor is object)
|
||||
{
|
||||
defaultInstance = (T)ctor.Invoke(Array.Empty<object>());
|
||||
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<T>();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
112
Pilz.Configuration/SimpleConfiguration.cs
Normal file
112
Pilz.Configuration/SimpleConfiguration.cs
Normal file
@@ -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<SimpleConfiguration> e)
|
||||
{
|
||||
if (ReferenceEquals(sender, Managers))
|
||||
{
|
||||
e.Value = this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes this instance to a string and return it.
|
||||
/// </summary>
|
||||
/// <returns>The content of the configuration instance as string.</returns>
|
||||
public string WriteToString()
|
||||
{
|
||||
return ConfigurationSerializer.WriteToString(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write this instance to a given stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream where the content should be written to.</param>
|
||||
public void WriteToStream(Stream stream)
|
||||
{
|
||||
ConfigurationSerializer.WriteToStream(this, stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes this instance to the given filePath as text file.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The file path where the content should be written to. The file will be created or overwritten.</param>
|
||||
public void WriteToFile(string filePath)
|
||||
{
|
||||
ConfigurationSerializer.WriteToFile(this, filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a configuratin from the given string and returns an instance of it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
/// <param name="content">The content of the configuration as string.</param>
|
||||
/// <returns></returns>
|
||||
public static T ReadFromString<T>(string content) where T : SimpleConfiguration
|
||||
{
|
||||
return ConfigurationSerializer.ReadFromString<T>(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a configuration from the given string and put them to this instance.
|
||||
/// </summary>
|
||||
/// <param name="content">The content of the configuration as string.</param>
|
||||
public void ReadFromString(string content)
|
||||
{
|
||||
ConfigurationSerializer.ReadFromString(this, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a configuratin from the given string and returns an instance of it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
/// <param name="stream">The stream with the content of the configuration.</param>
|
||||
/// <returns></returns>
|
||||
public static T ReadFromStream<T>(Stream stream) where T : SimpleConfiguration
|
||||
{
|
||||
return ConfigurationSerializer.ReadFromStream<T>(stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a configuration from the given string and put them to this instance.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream with the content of the configuration.</param>
|
||||
public void ReadFromStream(Stream stream)
|
||||
{
|
||||
ConfigurationSerializer.ReadFromStream(this, stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a configuratin from the given string and returns an instance of it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
/// <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
/// <returns></returns>
|
||||
public static T ReadFromFile<T>(string filePath) where T : SimpleConfiguration
|
||||
{
|
||||
return ConfigurationSerializer.ReadFromFile<T>(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a configuration from the given string and put them to this instance.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
public void ReadFromFile(string filePath)
|
||||
{
|
||||
ConfigurationSerializer.ReadFromFile(this, filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
Imports System.IO
|
||||
Imports Newtonsoft.Json
|
||||
Imports Pilz.Configuration
|
||||
Imports Pilz.GeneralEventArgs
|
||||
|
||||
Public Class SimpleConfiguration
|
||||
|
||||
<JsonIgnore>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Writes this instance to a string and return it.
|
||||
''' </summary>
|
||||
''' <returns>The content of the configuration instance as string.</returns>
|
||||
Public Function WriteToString() As String
|
||||
Return ConfigurationSerializer.WriteToString(Me)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Write this instance to a given stream.
|
||||
''' </summary>
|
||||
''' <param name="stream">The stream where the content should be written to.</param>
|
||||
Public Sub WriteToStream(stream As Stream)
|
||||
ConfigurationSerializer.WriteToStream(Me, stream)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Writes this instance to the given filePath as text file.
|
||||
''' </summary>
|
||||
''' <param name="filePath">The file path where the content should be written to. The file will be created or overwritten.</param>
|
||||
Public Sub WriteToFile(filePath As String)
|
||||
ConfigurationSerializer.WriteToFile(Me, filePath)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Reads a configuratin from the given string and returns an instance of it.
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
''' <param name="content">The content of the configuration as string.</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ReadFromString(Of T As SimpleConfiguration)(content As String) As T
|
||||
Return ConfigurationSerializer.ReadFromString(Of T)(content)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Read a configuration from the given string and put them to this instance.
|
||||
''' </summary>
|
||||
''' <param name="content">The content of the configuration as string.</param>
|
||||
Public Sub ReadFromString(content As String)
|
||||
ConfigurationSerializer.ReadFromString(Me, content)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Reads a configuratin from the given string and returns an instance of it.
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
''' <param name="stream">The stream with the content of the configuration.</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ReadFromStream(Of T As SimpleConfiguration)(stream As Stream) As T
|
||||
Return ConfigurationSerializer.ReadFromStream(Of T)(stream)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Read a configuration from the given string and put them to this instance.
|
||||
''' </summary>
|
||||
''' <param name="stream">The stream with the content of the configuration.</param>
|
||||
Public Sub ReadFromStream(stream As Stream)
|
||||
ConfigurationSerializer.ReadFromStream(Me, stream)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Reads a configuratin from the given string and returns an instance of it.
|
||||
''' </summary>
|
||||
''' <typeparam name="T">The type of the configuration class to instance.</typeparam>
|
||||
''' <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ReadFromFile(Of T As SimpleConfiguration)(filePath As String) As T
|
||||
Return ConfigurationSerializer.ReadFromFile(Of T)(filePath)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Read a configuration from the given string and put them to this instance.
|
||||
''' </summary>
|
||||
''' <param name="filePath">The path to the file with the content of the configuration.</param>
|
||||
Public Sub ReadFromFile(filePath As String)
|
||||
ConfigurationSerializer.ReadFromFile(Me, filePath)
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
744
Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.cs
Normal file
744
Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/Camera.cs
Normal file
@@ -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<float>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
10
Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.cs
Normal file
10
Pilz.Drawing.Drawing3D.OpenGLRenderer/Camera/CameraMode.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
|
||||
{
|
||||
public enum CameraMode
|
||||
{
|
||||
FLY = 0,
|
||||
ORBIT = 1,
|
||||
LOOK_DIRECTION = 2
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
Namespace CameraN
|
||||
|
||||
Public Enum CameraMode
|
||||
FLY = 0
|
||||
ORBIT = 1
|
||||
LOOK_DIRECTION = 2
|
||||
End Enum
|
||||
|
||||
End Namespace
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
Namespace CameraN
|
||||
|
||||
Public Interface ICameraPoint
|
||||
|
||||
Property Position As Numerics.Vector3
|
||||
Property Rotation As Numerics.Vector3
|
||||
|
||||
End Interface
|
||||
|
||||
End Namespace
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.CameraN
|
||||
{
|
||||
public enum LookDirection
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right,
|
||||
Front,
|
||||
Back
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
Namespace CameraN
|
||||
|
||||
Public Enum LookDirection
|
||||
Top
|
||||
Bottom
|
||||
Left
|
||||
Right
|
||||
Front
|
||||
Back
|
||||
End Enum
|
||||
|
||||
End Namespace
|
||||
@@ -1,120 +0,0 @@
|
||||
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
||||
Partial Class ModelPreview
|
||||
Inherits DevComponents.DotNetBar.OfficeForm
|
||||
|
||||
'Form overrides dispose to clean up the component list.
|
||||
<System.Diagnostics.DebuggerNonUserCode()>
|
||||
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.
|
||||
<System.Diagnostics.DebuggerStepThrough()>
|
||||
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
|
||||
11
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.cs
generated
Normal file
11
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/Application.Designer.cs
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
@@ -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
|
||||
|
||||
<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.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
192
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
192
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
@@ -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<MyComputer> m_ComputerObjectProvider = new ThreadSafeObjectProvider<MyComputer>();
|
||||
/* 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<MyApplication> m_AppObjectProvider = new ThreadSafeObjectProvider<MyApplication>();
|
||||
/* 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<Microsoft.VisualBasic.ApplicationServices.User> m_UserObjectProvider = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.User>();
|
||||
/* 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>(T instance) where T : new()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
else
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
private void Dispose__Instance__<T>(ref T instance)
|
||||
{
|
||||
instance = default;
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public MyWebServices() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private readonly static ThreadSafeObjectProvider<MyWebServices> m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider<MyWebServices>();
|
||||
/* 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<T> 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<T> m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue<T>();
|
||||
/* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
253
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
253
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
@@ -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<XElement> source)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return item.Value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_Value(IEnumerable<XElement> source, string value)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
{
|
||||
item.Value = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static string get_AttributeValue(IEnumerable<XElement> source, XName name)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return Conversions.ToString(item.Attribute(name));
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_AttributeValue(IEnumerable<XElement> 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<XAttribute> 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<XAttribute> attributes, IEnumerable obj)
|
||||
{
|
||||
if (obj is object)
|
||||
{
|
||||
IEnumerable<XElement> elems = obj as IEnumerable<XElement>;
|
||||
if (elems is object)
|
||||
{
|
||||
return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj.Cast<object>().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<XAttribute> m_attributes;
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> 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<XAttribute> 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<XNamespace>();
|
||||
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<XNamespace>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
14
Pilz.Drawing.Drawing3D.OpenGLRenderer/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
'''<summary>
|
||||
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
'''<summary>
|
||||
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
@@ -1,73 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
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
|
||||
@@ -4,7 +4,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}</ProjectGuid>
|
||||
<ProjectGuid>{ECBB8A61-3BE0-0658-02A4-A7806FD3F824}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Pilz.Drawing.Drawing3D.OpenGLFactory</RootNamespace>
|
||||
<AssemblyName>Pilz.Drawing.Drawing3D.OpenGLFactory</AssemblyName>
|
||||
@@ -12,6 +12,8 @@
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(ProjectDir)**\*.vb</DefaultItemExcludes>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -44,6 +46,7 @@
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
@@ -67,62 +70,65 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Camera\Camera.vb" />
|
||||
<Compile Include="Camera\CameraMode.vb" />
|
||||
<Compile Include="Camera\LookDirection.vb" />
|
||||
<Compile Include="Preview\ModelPreview.Designer.vb">
|
||||
<DependentUpon>ModelPreview.vb</DependentUpon>
|
||||
<Compile Include="My Project\MyNamespace.Static.1.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.2.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.3.Designer.cs" />
|
||||
<Compile Include="Camera\Camera.cs" />
|
||||
<Compile Include="Camera\CameraMode.cs" />
|
||||
<Compile Include="Camera\LookDirection.cs" />
|
||||
<Compile Include="Preview\ModelPreview.Designer.cs">
|
||||
<DependentUpon>ModelPreview.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Preview\ModelPreview.vb">
|
||||
<Compile Include="Preview\ModelPreview.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Rendering\BoundingBox.vb" />
|
||||
<Compile Include="Camera\ICameraPoint.vb" />
|
||||
<Compile Include="Rendering\ContentPipe.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<Compile Include="Rendering\BoundingBox.cs" />
|
||||
<Compile Include="Camera\ICameraPoint.cs" />
|
||||
<Compile Include="Rendering\ContentPipe.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="My Project\Application.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<Compile Include="Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Rendering\Renderer.vb" />
|
||||
<Compile Include="Rendering\RenderMode.vb" />
|
||||
<Compile Include="Rendering\Renderer.cs" />
|
||||
<Compile Include="Rendering\RenderMode.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<EmbeddedResource Include="Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Drawing.Drawing3D.OpenGLFactory.My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Preview\ModelPreview.resx">
|
||||
<DependentUpon>ModelPreview.vb</DependentUpon>
|
||||
<DependentUpon>ModelPreview.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
<LastGenOutput>Application.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Drawing.Drawing3D.OpenGLFactory.My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.vbproj">
|
||||
<Project>{ac955819-7910-450c-940c-7c1989483d4b}</Project>
|
||||
<ProjectReference Include="..\Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.csproj">
|
||||
<Project>{1EB1D972-B548-0AFD-1654-B667EBDF09EB}</Project>
|
||||
<Name>Pilz.Simple3DFileParser</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
@@ -137,5 +143,5 @@
|
||||
<Version>4.5.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
52
Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.cs
generated
Normal file
52
Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.Designer.cs
generated
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
Namespace PreviewN
|
||||
|
||||
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
||||
Partial Class ModelPreview
|
||||
Inherits System.Windows.Forms.Form
|
||||
|
||||
'Form overrides dispose to clean up the component list.
|
||||
<System.Diagnostics.DebuggerNonUserCode()>
|
||||
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.
|
||||
<System.Diagnostics.DebuggerStepThrough()>
|
||||
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
|
||||
487
Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.cs
Normal file
487
Pilz.Drawing.Drawing3D.OpenGLRenderer/Preview/ModelPreview.cs
Normal file
@@ -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<Object3D, Renderer> myModels = new Dictionary<Object3D, Renderer>();
|
||||
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<Object3D, Renderer> 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<Object3D>(), 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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.*")>
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
26
Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/Settings.Designer.cs
generated
Normal file
26
Pilz.Drawing.Drawing3D.OpenGLRenderer/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace Pilz.Drawing.Drawing3D.OpenGLFactory.RenderingN
|
||||
{
|
||||
public enum RenderMode : byte
|
||||
{
|
||||
None = 0x0,
|
||||
Fill = 0x1,
|
||||
Outline = 0x2,
|
||||
FillOutline = Fill | Outline
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
485
Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.cs
Normal file
485
Pilz.Drawing.Drawing3D.OpenGLRenderer/Rendering/Renderer.cs
Normal file
@@ -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<Image, int> dicTextureIDs = new global::System.Collections.Generic.Dictionary<global::System.Drawing.Image, global::System.Int32>();
|
||||
private global::System.Collections.Generic.Dictionary<global::System.Drawing.Color, global::System.Int32> dicColorIDs = new global::System.Collections.Generic.Dictionary<global::System.Drawing.Color, global::System.Int32>();
|
||||
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<global::System.Object> SelectedElements { get; private set; }
|
||||
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> VertexBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
|
||||
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Collections.Generic.List<global::System.Int32>> IndicesBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Collections.Generic.List<global::System.Int32>>();
|
||||
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> UVBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
|
||||
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> VertexColorBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
|
||||
private global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32> NormalBuffers { get; set; } = new global::System.Collections.Generic.Dictionary<global::Pilz.S3DFileParser.Mesh, global::System.Int32>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Data of a Vertex in the buffer.
|
||||
/// </summary>
|
||||
/// <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
/// <param name="v">The Vertex to update.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Data of a Normal in the buffer.
|
||||
/// </summary>
|
||||
/// <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
/// <param name="n">The Normal to update.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Data of a Vertex Color in the buffer.
|
||||
/// </summary>
|
||||
/// <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
/// <param name="vc">The Vertex Color to update.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Data of a UV in the buffer.
|
||||
/// </summary>
|
||||
/// <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
/// <param name="uv">The UV to update.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the indicies of a face in the buffer.
|
||||
/// </summary>
|
||||
/// <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
/// <param name="f">The Face to update.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace an Image with a new one.
|
||||
/// </summary>
|
||||
/// <param name="oldImage"></param>
|
||||
/// <param name="newImage"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an Image.
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the Buffers and store the requied Data.
|
||||
/// </summary>
|
||||
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.Int32>();
|
||||
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<global::OpenTK.Vector3>();
|
||||
var uvs = new global::System.Collections.Generic.List<global::OpenTK.Vector2>();
|
||||
var cols = new global::System.Collections.Generic.List<global::OpenTK.Vector4>();
|
||||
var norms = new global::System.Collections.Generic.List<global::OpenTK.Vector3>();
|
||||
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<UInt32>();
|
||||
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<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.VertexBuffers)
|
||||
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
|
||||
this.VertexBuffers.Clear();
|
||||
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.UVBuffers)
|
||||
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
|
||||
this.UVBuffers.Clear();
|
||||
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.VertexColorBuffers)
|
||||
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
|
||||
this.VertexColorBuffers.Clear();
|
||||
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Int32> kvp in this.NormalBuffers)
|
||||
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
|
||||
this.NormalBuffers.Clear();
|
||||
foreach (global::System.Collections.Generic.KeyValuePair<global::Pilz.S3DFileParser.Mesh, global::System.Collections.Generic.List<global::System.Int32>> 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<global::System.Drawing.Image, global::System.Int32> kvp in this.dicTextureIDs)
|
||||
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
|
||||
this.dicTextureIDs.Clear();
|
||||
foreach (global::System.Collections.Generic.KeyValuePair<global::System.Drawing.Color, global::System.Int32> kvp in this.dicColorIDs)
|
||||
global::OpenTK.Graphics.OpenGL.GL.DeleteBuffer(kvp.Value);
|
||||
this.dicColorIDs.Clear();
|
||||
this.HasRendered = false;
|
||||
}
|
||||
|
||||
~Renderer()
|
||||
{
|
||||
// ReleaseBuffers()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
''' <summary>
|
||||
''' Updates the Data of a Vertex in the buffer.
|
||||
''' </summary>
|
||||
''' <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
''' <param name="v">The Vertex to update.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Updates the Data of a Normal in the buffer.
|
||||
''' </summary>
|
||||
''' <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
''' <param name="n">The Normal to update.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Updates the Data of a Vertex Color in the buffer.
|
||||
''' </summary>
|
||||
''' <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
''' <param name="vc">The Vertex Color to update.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Updates the Data of a UV in the buffer.
|
||||
''' </summary>
|
||||
''' <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
''' <param name="uv">The UV to update.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Updates the indicies of a face in the buffer.
|
||||
''' </summary>
|
||||
''' <param name="m">The Mesh where the Vertex is listed.</param>
|
||||
''' <param name="f">The Face to update.</param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Replace an Image with a new one.
|
||||
''' </summary>
|
||||
''' <param name="oldImage"></param>
|
||||
''' <param name="newImage"></param>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Updates an Image.
|
||||
''' </summary>
|
||||
''' <param name="image"></param>
|
||||
Public Sub UpdateTexture(image As Image)
|
||||
If dicTextureIDs.ContainsKey(image) Then
|
||||
ContentPipe.LoadTexture(dicTextureIDs(image))
|
||||
End If
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Creates the Buffers and store the requied Data.
|
||||
''' </summary>
|
||||
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
|
||||
69
Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.Designer.cs
generated
Normal file
69
Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,69 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
/// <summary>
|
||||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
/// <summary>
|
||||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
/// </summary>
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.resx
Normal file
117
Pilz.Drawing.Drawing3D.OpenGLRenderer/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
20
Pilz.Drawing/BitmapExtensions.cs
Normal file
20
Pilz.Drawing/BitmapExtensions.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Runtime.CompilerServices
|
||||
|
||||
Public Module BitmapExtensions
|
||||
|
||||
<Extension>
|
||||
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
|
||||
47
Pilz.Drawing/HelpfulDrawingFunctions.cs
Normal file
47
Pilz.Drawing/HelpfulDrawingFunctions.cs
Normal file
@@ -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<bool>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
11
Pilz.Drawing/My Project/Application.Designer.cs
generated
Normal file
11
Pilz.Drawing/My Project/Application.Designer.cs
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
13
Pilz.Drawing/My Project/Application.Designer.vb
generated
13
Pilz.Drawing/My Project/Application.Designer.vb
generated
@@ -1,13 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user