Skip to content

Commit

Permalink
Removed stuff no longer used
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Oct 20, 2014
1 parent c62b774 commit b297be0
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 87 deletions.
1 change: 1 addition & 0 deletions Gu.Units.Generator.Tests/Gu.Units.Generator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<AssemblyName>Gu.Units.Generator.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Gu.Units.Generator/Descriptors/Quantity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public string Interface
{
siUnit.PropertyChanged += (sender, eventArgs) =>
{
if (eventArgs.PropertyName == NameOf.Property(() => siUnit.QuantityName))
if (eventArgs.PropertyName == NameOf.Property(() => siUnit.QuantityName, true))
{
OnPropertyChanged();
}
Expand Down Expand Up @@ -130,7 +130,7 @@ public IEnumerable<OperatorOverload> OperatorOverloads
{
return Enumerable.Empty<OperatorOverload>();
}
return Settings.Quantities.Where(x => x != this)
return Settings.Quantities.Where(x => x.ClassName != ClassName)
.Where(result => OperatorOverload.CanCreate(Settings, this, result))
.Select(result => new OperatorOverload(this, result, Settings));
}
Expand Down
22 changes: 21 additions & 1 deletion Gu.Units.Generator/Descriptors/UnitParts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
Expand All @@ -16,6 +17,7 @@
[TypeConverter(typeof(UnitPartsConverter))]
public class UnitParts : ParentCollection<IUnit, UnitAndPower>, INotifyPropertyChanged
{
private static BaseUnitOrderComparer _baseUnitOrderComparer = new BaseUnitOrderComparer();
public UnitParts(IUnit baseUnit, IEnumerable<UnitAndPower> parts)
: base(baseUnit, (up, u) => up.Parent = u, parts)
{
Expand Down Expand Up @@ -220,7 +222,7 @@ private string CreateExpression(IEnumerable<UnitAndPower> ups)
}
var sb = new StringBuilder();
UnitAndPower previous = null;
foreach (var unitAndPower in ups)
foreach (var unitAndPower in ups.OrderBy(x => x, _baseUnitOrderComparer).ToArray())
{
if (previous != null)
{
Expand All @@ -245,6 +247,9 @@ private string CreateExpression(IEnumerable<UnitAndPower> ups)
case 3:
sb.Append("³");
break;
case 4:
sb.Append("");
break;
default:
sb.Append("^")
.Append(Math.Abs(unitAndPower.Power));
Expand All @@ -254,5 +259,20 @@ private string CreateExpression(IEnumerable<UnitAndPower> ups)
}
return sb.ToString();
}

public class BaseUnitOrderComparer : IComparer<UnitAndPower>
{
private readonly string[] _order = { "kg", "m", "s", "A", "cd", "mol" };
public int Compare(UnitAndPower x, UnitAndPower y)
{
var indexOfX = Array.IndexOf(_order, x.Unit.Symbol);
var indexOfY = Array.IndexOf(_order, y.Unit.Symbol);
if (indexOfX < 0 && indexOfY < 0)
{
return String.Compare(x.Unit.Symbol, y.Unit.Symbol, StringComparison.Ordinal);
}
return indexOfX.CompareTo(indexOfY);
}
}
}
}
36 changes: 36 additions & 0 deletions Gu.Units.Generator/GeneratorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,42 @@
</UnitAndPower>
</Parts>
</DerivedUnit>
<DerivedUnit>
<ClassName>Henrys</ClassName>
<Symbol>H</Symbol>
<QuantityName>Inductance</QuantityName>
<Conversions />
<Parts>
<UnitAndPower>
<UnitName>Volts</UnitName>
<Power>1</Power>
</UnitAndPower>
<UnitAndPower>
<UnitName>Seconds</UnitName>
<Power>1</Power>
</UnitAndPower>
<UnitAndPower>
<UnitName>Amperes</UnitName>
<Power>-1</Power>
</UnitAndPower>
</Parts>
</DerivedUnit>
<DerivedUnit>
<ClassName>Farads</ClassName>
<Symbol>F</Symbol>
<QuantityName>Capacitance</QuantityName>
<Conversions />
<Parts>
<UnitAndPower>
<UnitName>Coulombs</UnitName>
<Power>1</Power>
</UnitAndPower>
<UnitAndPower>
<UnitName>Volts</UnitName>
<Power>-1</Power>
</UnitAndPower>
</Parts>
</DerivedUnit>
</DerivedUnits>
<SiUnits>
<SiUnit>
Expand Down
6 changes: 3 additions & 3 deletions Gu.Units.Generator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<DataGridTextColumn Binding="{Binding QuantityName}" Header="Quantity" />
<DataGridTextColumn Binding="{Binding ClassName}" Header="Unit" />
<DataGridTextColumn Binding="{Binding Symbol}" Header="Symbol" />
<DataGridTextColumn Binding="{Binding Quantity.Interface}" Header="Interface" />
<!--<DataGridTextColumn Binding="{Binding Quantity.Interface}" Header="Interface" />-->
</DataGrid.Columns>
</DataGrid>
</GroupBox>
Expand All @@ -64,9 +64,9 @@
<DataGridTextColumn Binding="{Binding Parts.BaseUnitExpression}"
Header="In base units"
IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Quantity.Interface}"
<!--<DataGridTextColumn Binding="{Binding Quantity.Interface}"
Header="Interface"
IsReadOnly="True" />
IsReadOnly="True" />-->

</DataGrid.Columns>
</DataGrid>
Expand Down
2 changes: 1 addition & 1 deletion Gu.Units.Generator/WpfStuff/UnitPartsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class UnitPartsConverter : TypeConverter
{
private static readonly string[] Superscripts = { "¹", "²", "³" };
private static readonly string[] Superscripts = { "¹", "²", "³", "" };

public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
Expand Down
37 changes: 0 additions & 37 deletions Gu.Units.Tests/ArithmeticsTests.cs

This file was deleted.

10 changes: 0 additions & 10 deletions Gu.Units.Tests/ConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,5 @@ public void Roundtrip(IUnit unit)
Assert.AreEqual(value, d);
}
}

[TestCase(0)]
[TestCase(100)]
public void RoundtripDummy(double value)
{
var dummyUnit = new DummyUnit();
var si = UnitConverter.ConvertFrom(value, dummyUnit);
var d = UnitConverter.ConvertTo(si, dummyUnit);
Assert.AreEqual(value, d);
}
}
}
1 change: 0 additions & 1 deletion Gu.Units.Tests/Gu.Units.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ArithmeticsTests.cs" />
<Compile Include="ConverterTests.cs" />
<Compile Include="Helpers\DummyUnit.cs" />
<Compile Include="ParserTests.cs" />
Expand Down
12 changes: 12 additions & 0 deletions Gu.Units/Area.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public Area(double value, AreaUnit unit)
SquareMetres = unit.ToSiUnit(value);
}

/// <summary>
/// The unit expressed in SI base units
/// http://en.wikipedia.org/wiki/SI_derived_unit
/// </summary>
public string BaseUnits
{
get
{
return "m^2";
}
}

/// <summary>
/// The quantity in SquareMetres
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions Gu.Units/Gu.Units.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@
<Compile Include="TorqueUnit.generated.cs">
<DependentUpon>UnitGenerator.txt4</DependentUpon>
</Compile>
<Compile Include="Utils\Arithmetics.cs" />
<Compile Include="Utils\UnitConverter.cs" />
<Compile Include="Utils\Parser.cs" />
<Compile Include="Utils\XmlExt.cs" />
<Compile Include="Voltage.generated.cs">
Expand Down
13 changes: 0 additions & 13 deletions Gu.Units/Utils/Arithmetics.cs

This file was deleted.

17 changes: 0 additions & 17 deletions Gu.Units/Utils/UnitConverter.cs

This file was deleted.

0 comments on commit b297be0

Please sign in to comment.