Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #21 from thelsing/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
thelsing authored Mar 11, 2021
2 parents 9deb814 + 7eb0d54 commit 6f5bab6
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Reflection;
Expand All @@ -28,10 +29,17 @@ public override object ConvertTo(ITypeDescriptorContext context, System.Globaliz
FieldInfo fi = value.GetType().GetField(value.ToString());
if (fi != null)
{
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
var result = ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();
//TODO: lookup ressource for localisation
return result;
var attributes = (DisplayAttribute[])fi.GetCustomAttributes(typeof(DisplayAttribute), false);
if (attributes.Length == 0)
return "";

var type = attributes[0].ResourceType;
var name = attributes[0].Name;
if(type == null)
return name;

var propertyInfo = type.GetProperty(name, BindingFlags.Public | BindingFlags.Static);
return propertyInfo.GetValue(null);
}
}

Expand Down
37 changes: 37 additions & 0 deletions Converter/ObjectVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using CreateKnxProd.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace CreateKnxProd.Converter
{
public class ObjectVisibilityConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(Visibility))
return null;


if (value == null)
return Visibility.Collapsed;

return Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
3 changes: 2 additions & 1 deletion CreateKnxProd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Converter\EnableTBoolTypeConverter.cs" />
<Compile Include="Converter\EnumDescriptionTypeConverter.cs" />
<Compile Include="Converter\EnumDescriptionTypeConverter - Copy.cs" />
<Compile Include="Converter\ObjectVisibilityConverter.cs" />
<Compile Include="Extensions\Extensions.cs" />
<Compile Include="Model\ComObjectRefRef_t.cs" />
<Compile Include="Model\ComObjectRef_t.cs" />
Expand Down
53 changes: 29 additions & 24 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Title="{lex:Loc WindowTitle}" Height="450" Width="800">
<Window.Resources>
<lc:EnableTBoolTypeConverter x:Key="EnableBoolConverter"/>
<lc:ObjectVisibilityConverter x:Key="ObjectVisibilityConverter"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -103,38 +104,42 @@
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<DataTemplate DataType="{x:Type model:ParameterType_TTypeText}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{lex:Loc CharacterCount}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding SizeInByte, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>

</DataTemplate>
<DataTemplate DataType="{x:Type model:ParameterType_TTypeFloat}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{lex:Loc Minimum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding minInclusive, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="{lex:Loc Maximum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding maxInclusive, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>

</DataTemplate>
<DataTemplate DataType="{x:Type model:ParameterType_TTypeNumber}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{lex:Loc Minimum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding minInclusive, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="{lex:Loc Maximum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding maxInclusive, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>

</DataTemplate>
<DataTemplate DataType="{x:Type model:ParameterType_TTypeRestriction}">
<DataGrid ItemsSource="{Binding Enumeration}" Margin="5" AutoGenerateColumns="False"
dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True">
<DataGrid.Columns>
<DataGridTextColumn Header="{lex:Loc Value}" Binding="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Header="{lex:Loc Text}" Binding="{Binding Text, UpdateSourceTrigger=PropertyChanged}" Width="200"/>
</DataGrid.Columns>
</DataGrid>

</DataTemplate>
</StackPanel.Resources>
<ContentPresenter Content="{Binding Item}"/>
<!--<ContentPresenter Content="{Binding Item}">-->
<StackPanel Orientation="Horizontal" Visibility="{Binding TypeText, Converter={StaticResource ObjectVisibilityConverter}}">
<TextBlock Text="{lex:Loc CharacterCount}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding TypeText.SizeInByte, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding TypeFloat, Converter={StaticResource ObjectVisibilityConverter}}">
<TextBlock Text="{lex:Loc Minimum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding TypeFloat.MinInclusive, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="{lex:Loc Maximum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding TypeFloat.MaxInclusive, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding TypeNumber, Converter={StaticResource ObjectVisibilityConverter}}">
<TextBlock Text="{lex:Loc Minimum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding TypeNumber.MinInclusive, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="{lex:Loc Maximum}" Margin="5"/>
<TextBox Width="50" Margin="5" Text="{Binding TypeNumber.MaxInclusive, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
<DataGrid ItemsSource="{Binding TypeRestriction.Enumeration}" Margin="5" AutoGenerateColumns="False"
dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" Visibility="{Binding TypeRestriction, Converter={StaticResource ObjectVisibilityConverter}}">
<DataGrid.Columns>
<DataGridTextColumn Header="{lex:Loc Value}" Binding="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Header="{lex:Loc Text}" Binding="{Binding Text, UpdateSourceTrigger=PropertyChanged}" Width="200"/>
</DataGrid.Columns>
</DataGrid>
</StackPanel>

</DataTemplate>
Expand Down
6 changes: 3 additions & 3 deletions MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,15 @@ private void CorrectIds()
_codeSegment.Id = string.Format("{0}_RS-{1:00}-{2:00000}", _applicationProgram.Id, _codeSegment.LoadStateMachine,
_codeSegment.Offset);

_hardware.Id = string.Format("{0}_H-{1}-{2}", _manufacturerData.RefId, _hardware.SerialNumber,
_hardware.Id = string.Format("{0}_H-{1}-{2}", _manufacturerData.RefId, _hardware.SerialNumber.Replace("-", ".2D"),
_hardware.VersionNumber);
_product.Id = string.Format("{0}_P-{1}", _hardware.Id, _product.OrderNumber);
_product.Id = string.Format("{0}_P-{1}", _hardware.Id, _product.OrderNumber.Replace("-", ".2D"));
_hardware2Program.Id = string.Format("{0}_HP-{1:X04}-{2:X02}-0000", _hardware.Id,
_applicationProgram.ApplicationNumber, _applicationProgram.ApplicationVersion);

_catalogSection.Id = string.Format("{0}_CS-{1}", _manufacturerData.RefId, _catalogSection.Number);

_catalogItem.Id = string.Format("{0}_CI-{1}-{2}", _hardware2Program.Id, _product.OrderNumber, _catalogItem.Number);
_catalogItem.Id = string.Format("{0}_CI-{1}-{2}", _hardware2Program.Id, _product.OrderNumber.Replace("-", ".2D"), _catalogItem.Number);
_catalogItem.ProductRefId = _product.Id;
_catalogItem.Hardware2ProgramRefId = _hardware2Program.Id;

Expand Down
8 changes: 5 additions & 3 deletions Model/ParameterTypeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -13,12 +14,13 @@ namespace CreateKnxProd.Model
public enum ParameterTypeType
{
[Description("Number")]
[Display(Name = "Parametertype_Integer", ResourceType = typeof(Ressources))]
Number,
[Description("Fließkommazahl")]
[Display(Name = "Parametertype_Float", ResourceType = typeof(Ressources))]
Float,
[Description("Aufzählung")]
[Display(Name = "Parametertype_Enumeration", ResourceType = typeof(Ressources))]
Restriction,
[Description("Text")]
[Display(Name = "Parametertype_Text", ResourceType = typeof(Ressources))]
Text
}

Expand Down
38 changes: 37 additions & 1 deletion Properties/Ressources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Properties/Ressources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,16 @@
<data name="ReplacedVersion" xml:space="preserve">
<value>Ersetzt Versionen</value>
</data>
<data name="Parametertype_Enumeration" xml:space="preserve">
<value>Aufzählung</value>
</data>
<data name="Parametertype_Float" xml:space="preserve">
<value>Fließkommazahl</value>
</data>
<data name="Parametertype_Integer" xml:space="preserve">
<value>Ganze Zahl</value>
</data>
<data name="Parametertype_Text" xml:space="preserve">
<value>Text</value>
</data>
</root>
15 changes: 15 additions & 0 deletions Properties/Ressources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,19 @@
<data name="MaxSecurityIndividualAddressEntries" xml:space="preserve">
<value>Max SecurityIndividualAddress Entries</value>
</data>
<data name="Parametertype_Enumeration" xml:space="preserve">
<value>Enumeration</value>
</data>
<data name="RF" xml:space="preserve">
<value>RF</value>
</data>
<data name="Parametertype_Float" xml:space="preserve">
<value>Float</value>
</data>
<data name="Parametertype_Integer" xml:space="preserve">
<value>Integer</value>
</data>
<data name="Parametertype_Text" xml:space="preserve">
<value>Text</value>
</data>
</root>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ C:\Program Files (x86)\ETS5\CV\4.0.1997.50261
You can also change UICulture and Culture from 'de' to 'en' there.

If ETS doesn't import the generated file, try removing underscores from product name, hardware name etc. Maybe version numbers have to be at least 10 too.

A knx-stack for multiple platforms can be found [here](https://github.com/thelsing/knx).
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ steps:

- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
rootFolderOrFile: 'bin/$(buildConfiguration)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/CreateKnxProd.zip'
Expand Down

0 comments on commit 6f5bab6

Please sign in to comment.