Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.3.2 #7

Merged
merged 14 commits into from
Jun 14, 2024
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.3.2] / 2024-06-14
### Shapes
- Update Colors using the `System.Windows.Media.Colors` as reference.
- Update `MaterialUtils` and `GraphicsStyleUtils` with default 9 colors.
- Add `ColorExtension` with `ColorEquals`, `Lerp`, `ToColor` and `ToColorWithTransparency`.
- Add `ColorExtension` with `ToHex` for `Color` and `ColorWithTransparency`
- Update `CreateBoxLines` with `graphicsStyleId`
- Add `CreateLines` in `ShapeCreator`
### Tests
- Test all color names in `System.Windows.Media.Colors` with `Colors`.
- Test all 9 colors in `MaterialUtils` and `GraphicsStyleUtils`.
- Test for `ColorExternsion`
- Test `MaterialId` and `GraphicsStyleId`.
- Test `CreateLines` with `closed` and `GraphicsStyleId`.

## [0.3.1] / 2024-01-09 - 2024-04-13
### Features
- Support Revit 2025
Expand Down Expand Up @@ -59,6 +74,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Create Project `ricaun.Revit.DB`

[vNext]: ../../compare/0.1.0...HEAD
[0.3.2]: ../../compare/0.3.1...0.3.2
[0.3.1]: ../../compare/0.3.0...0.3.1
[0.3.0]: ../../compare/0.2.0...0.3.0
[0.2.0]: ../../compare/0.1.0...0.2.0
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
<RevitVersionTests>2024</RevitVersionTests>
<RevitVersionCoreTests>2025</RevitVersionCoreTests>
<RevitForceOpenClose>true</RevitForceOpenClose>
Expand Down
17 changes: 14 additions & 3 deletions ricaun.Revit.DB.Quaternion/ricaun.Revit.DB.Quaternion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@

<!-- RevitVersion -->
<PropertyGroup>
<TargetFrameworks>net46;net8.0-windows</TargetFrameworks>
<TargetFrameworks>net46;net47;net48;net8.0-windows</TargetFrameworks>
</PropertyGroup>
<Choose>
<When Condition="$(TargetFramework.StartsWith('net4'))">
<When Condition="$(TargetFramework.StartsWith('net46'))">
<PropertyGroup>
<RevitVersion>2017</RevitVersion>
</PropertyGroup>
</When>
<When Condition="$(TargetFramework.StartsWith('net47'))">
<PropertyGroup>
<RevitVersion>2019</RevitVersion>
</PropertyGroup>
</When>
<When Condition="$(TargetFramework.StartsWith('net48'))">
<PropertyGroup>
<RevitVersion>2021</RevitVersion>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<RevitVersion>2025</RevitVersion>
Expand Down Expand Up @@ -77,7 +87,8 @@
<PropertyGroup>
<Company>ricaun</Company>
<Authors>Luiz Henrique Cassettari</Authors>
<Description>$(PackageId)</Description>
<Description>Revit API DB library for Quaternion.</Description>
<PackageTags>revit;revitapi;dotnet</PackageTags>
<CopyrightYears>$([System.DateTime]::Now.ToString('yyyy'))</CopyrightYears>
</PropertyGroup>

Expand Down
115 changes: 98 additions & 17 deletions ricaun.Revit.DB.Shape.Tests/Color_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Autodesk.Revit.DB;
using NUnit.Framework;
using ricaun.Revit.DB.Shape.Tests.Utils;
using ricaun.Revit.DB.Shape.Extensions;
using System.Collections.Generic;

namespace ricaun.Revit.DB.Shape.Tests
{
Expand All @@ -9,27 +11,49 @@ public class Color_Tests
Color black = new Color(0, 0, 0);
Color red = new Color(255, 0, 0);
Color yellow = new Color(255, 255, 0);
Color green = new Color(0, 255, 0);
Color lime = new Color(0, 255, 0);
Color cyan = new Color(0, 255, 255);
Color blue = new Color(0, 0, 255);
Color magenta = new Color(255, 0, 255);
Color white = new Color(255, 255, 255);
Color darkgray = new Color(65, 65, 65);
Color blackgray = new Color(65, 65, 65);
Color gray = new Color(128, 128, 128);

private static Dictionary<string, System.Windows.Media.Color> GetMediaColors()
{
var result = new Dictionary<string, System.Windows.Media.Color>();
foreach (var property in typeof(System.Windows.Media.Colors).GetProperties())
{
if (property.Name == "Transparent") continue;
if (property.GetValue(null) is System.Windows.Media.Color color)
result.Add(property.Name, color);
}
return result;
}

[Test]
public void Colors_Tests()
{
Assert.IsTrue(Colors.Black.ColorEquals(black));
Assert.IsTrue(Colors.Red.ColorEquals(red));
Assert.IsTrue(Colors.Yellow.ColorEquals(yellow));
Assert.IsTrue(Colors.Green.ColorEquals(green));
Assert.IsTrue(Colors.Cyan.ColorEquals(cyan));
Assert.IsTrue(Colors.Blue.ColorEquals(blue));
Assert.IsTrue(Colors.Magenta.ColorEquals(magenta));
Assert.IsTrue(Colors.White.ColorEquals(white));
Assert.IsTrue(Colors.DarkGray.ColorEquals(darkgray));
Assert.IsTrue(Colors.Gray.ColorEquals(gray));
var colorsType = typeof(Colors);
var count = colorsType.GetProperties().Length;
var mediaColors = GetMediaColors();

System.Console.WriteLine($"Colors: {count} \tMedia.Colors: {mediaColors.Count}");

foreach (var color in mediaColors)
{
var name = color.Key;
var expectedColor = new Color(color.Value.R, color.Value.G, color.Value.B);
if (colorsType.GetProperty(name)?.GetValue(null) is Color colorTest)
{
Assert.IsTrue(colorTest.ColorEquals(expectedColor),
$"{name} Color ({colorTest.Red},{colorTest.Green},{colorTest.Blue}) is not equal to ({expectedColor.Red},{expectedColor.Green},{expectedColor.Blue})");
}
else
{
Assert.Fail($"Colors.{name} not found.");
}
}
}

[Test]
Expand All @@ -38,12 +62,12 @@ public void Colors_Index_Tests()
Assert.IsTrue(Colors.Index.Color_0.ColorEquals(black));
Assert.IsTrue(Colors.Index.Color_1.ColorEquals(red));
Assert.IsTrue(Colors.Index.Color_2.ColorEquals(yellow));
Assert.IsTrue(Colors.Index.Color_3.ColorEquals(green));
Assert.IsTrue(Colors.Index.Color_3.ColorEquals(lime));
Assert.IsTrue(Colors.Index.Color_4.ColorEquals(cyan));
Assert.IsTrue(Colors.Index.Color_5.ColorEquals(blue));
Assert.IsTrue(Colors.Index.Color_6.ColorEquals(magenta));
Assert.IsTrue(Colors.Index.Color_7.ColorEquals(white));
Assert.IsTrue(Colors.Index.Color_8.ColorEquals(darkgray));
Assert.IsTrue(Colors.Index.Color_8.ColorEquals(blackgray));
Assert.IsTrue(Colors.Index.Color_9.ColorEquals(gray));
}

Expand All @@ -53,12 +77,12 @@ public void Colors_Index_Get_Tests()
Assert.IsTrue(Colors.Index.Get(0).ColorEquals(black));
Assert.IsTrue(Colors.Index.Get(1).ColorEquals(red));
Assert.IsTrue(Colors.Index.Get(2).ColorEquals(yellow));
Assert.IsTrue(Colors.Index.Get(3).ColorEquals(green));
Assert.IsTrue(Colors.Index.Get(3).ColorEquals(lime));
Assert.IsTrue(Colors.Index.Get(4).ColorEquals(cyan));
Assert.IsTrue(Colors.Index.Get(5).ColorEquals(blue));
Assert.IsTrue(Colors.Index.Get(6).ColorEquals(magenta));
Assert.IsTrue(Colors.Index.Get(7).ColorEquals(white));
Assert.IsTrue(Colors.Index.Get(8).ColorEquals(darkgray));
Assert.IsTrue(Colors.Index.Get(8).ColorEquals(blackgray));
Assert.IsTrue(Colors.Index.Get(9).ColorEquals(gray));
}

Expand All @@ -70,7 +94,64 @@ public void Colors_Index_Get_All_Tests()
Assert.IsNotNull(Colors.Index.Get((byte)i));
}
}
}

[Test]
public void ColorExtension_ColorEquals_Tests()
{
for (int i = 0; i < 256; i++)
{
var color = Colors.Index.Get((byte)i);
Assert.IsTrue(color.ColorEquals(color));

var colorT = color.ToColorWithTransparency();
Assert.IsTrue(colorT.ColorEquals(colorT));
Assert.IsTrue(colorT.ColorEquals(color));
Assert.IsTrue(color.ColorEquals(colorT));

var colorT100 = color.ToColorWithTransparency(100);
Assert.IsFalse(colorT.ColorEquals(colorT100));
Assert.IsFalse(colorT100.ColorEquals(colorT));

var _color = colorT.ToColor();
Assert.IsTrue(color.ColorEquals(_color));
}
}

[Test]
public void ColorExtension_Lerp_Tests()
{
var color = Colors.Black.Lerp(Colors.Gray, 0.5);
var colorExpected = new Color(64, 64, 64);
Assert.IsTrue(color.ColorEquals(colorExpected));
}

[Test]
public void ColorExtension_ToHex_Tests()
{
var tests = new Dictionary<string, Color>()
{
{ "#000000", Colors.Black },
{ "#FF0000", Colors.Red },
{ "#008000", Colors.Green },
{ "#00FF00", Colors.Lime },
{ "#0000FF", Colors.Blue },
{ "#FFFF00", Colors.Yellow },
{ "#00FFFF", Colors.Cyan },
{ "#FF00FF", Colors.Magenta },
{ "#808080", Colors.Gray },
{ "#FFFFFF", Colors.White },
};

foreach (var test in tests)
{
Assert.AreEqual(test.Key, test.Value.ToHex());
}

foreach (var test in tests)
{
Assert.AreEqual(test.Key, test.Value.ToColorWithTransparency().ToHex());
}
}
}

}
45 changes: 21 additions & 24 deletions ricaun.Revit.DB.Shape.Tests/LineColorCreate_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
using NUnit.Framework;
using Autodesk.Revit.DB;
using NUnit.Framework;
using ricaun.Revit.DB.Shape.Tests.Utils;
using ricaun.Revit.DB.Shape.Extensions;
using System.Collections.Generic;

namespace ricaun.Revit.DB.Shape.Tests
{
public class LineColorCreate_Tests : OneTimeOpenDocumentTransactionTest
{
[Test]
public void CreateLineColorWhite()
public void CreateLineColors()
{
var graphicsStyle = GraphicsStyleUtils.CreateLineColorWhite(document);
Assert.IsNotNull(graphicsStyle);
}
var colors = new Dictionary<Color, GraphicsStyle>() {
{ Colors.White, GraphicsStyleUtils.CreateLineColorWhite(document)},
{ Colors.Red, GraphicsStyleUtils.CreateLineColorRed(document)},
{ Colors.Green, GraphicsStyleUtils.CreateLineColorGreen(document)},
{ Colors.Blue, GraphicsStyleUtils.CreateLineColorBlue(document)},
{ Colors.Yellow, GraphicsStyleUtils.CreateLineColorYellow(document)},
{ Colors.Cyan, GraphicsStyleUtils.CreateLineColorCyan(document)},
{ Colors.Magenta, GraphicsStyleUtils.CreateLineColorMagenta(document)},
{ Colors.Black, GraphicsStyleUtils.CreateLineColorBlack(document)},
{ Colors.Gray, GraphicsStyleUtils.CreateLineColorGray(document)},
};

[Test]
public void CreateLineColorRed()
{
var graphicsStyle = GraphicsStyleUtils.CreateLineColorRed(document);
Assert.IsNotNull(graphicsStyle);
}

[Test]
public void CreateLineColorGreen()
{
var graphicsStyle = GraphicsStyleUtils.CreateLineColorGreen(document);
Assert.IsNotNull(graphicsStyle);
}

[Test]
public void CreateLineColorBlue()
{
var graphicsStyle = GraphicsStyleUtils.CreateLineColorBlue(document);
Assert.IsNotNull(graphicsStyle);
foreach (var color in colors)
{
Assert.IsNotNull(color.Value);
Assert.IsTrue(color.Value.GraphicsStyleCategory.LineColor.ColorEquals(color.Key));
}
}

[Test]
Expand Down
42 changes: 19 additions & 23 deletions ricaun.Revit.DB.Shape.Tests/MaterialCreate_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using Autodesk.Revit.DB;
using NUnit.Framework;
using ricaun.Revit.DB.Shape.Tests.Utils;
using ricaun.Revit.DB.Shape.Extensions;
using System;
using System.Collections.Generic;

namespace ricaun.Revit.DB.Shape.Tests
{
Expand Down Expand Up @@ -66,31 +68,25 @@ public void CreateMaterial_GetColorWithTransparency(int transparency)
}

[Test]
public void CreateMaterialWhite()
public void CreateMaterialColors()
{
var material = MaterialUtils.CreateMaterialWhite(document);
Assert.IsNotNull(material);
}
var colors = new Dictionary<Color, Material>() {
{ Colors.White, MaterialUtils.CreateMaterialWhite(document)},
{ Colors.Red, MaterialUtils.CreateMaterialRed(document)},
{ Colors.Green, MaterialUtils.CreateMaterialGreen(document)},
{ Colors.Blue, MaterialUtils.CreateMaterialBlue(document)},
{ Colors.Yellow, MaterialUtils.CreateMaterialYellow(document)},
{ Colors.Cyan, MaterialUtils.CreateMaterialCyan(document)},
{ Colors.Magenta, MaterialUtils.CreateMaterialMagenta(document)},
{ Colors.Black, MaterialUtils.CreateMaterialBlack(document)},
{ Colors.Gray, MaterialUtils.CreateMaterialGray(document)},
};

[Test]
public void CreateMaterialRed()
{
var material = MaterialUtils.CreateMaterialRed(document);
Assert.IsNotNull(material);
}

[Test]
public void CreateMaterialGreen()
{
var material = MaterialUtils.CreateMaterialGreen(document);
Assert.IsNotNull(material);
}

[Test]
public void CreateMaterialBlue()
{
var material = MaterialUtils.CreateMaterialBlue(document);
Assert.IsNotNull(material);
foreach (var color in colors)
{
Assert.IsNotNull(color.Value);
Assert.IsTrue(color.Value.Color.ColorEquals(color.Key));
}
}

[Test]
Expand Down
15 changes: 15 additions & 0 deletions ricaun.Revit.DB.Shape.Tests/Shape_BoxLine_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Autodesk.Revit.DB;
using NUnit.Framework;
using ricaun.Revit.DB.Shape.Tests.Utils;

namespace ricaun.Revit.DB.Shape.Tests
{
Expand All @@ -15,6 +16,20 @@ public void CreateBoxLines()
Assert.AreEqual(12, lines.Length);
}

[Test]
public void CreateBoxLines_GraphicsStyleId()
{
var scale = 1.0;
var center = XYZ.Zero;

var lines = ShapeCreator.CreateBoxLines(center, scale, ElementIdUtils.GraphicsStyleId);

foreach (var line in lines)
{
Assert.AreEqual(ElementIdUtils.GraphicsStyleId, line.GraphicsStyleId);
}
}

[Test]
public void CreateBoxLines_MinMax()
{
Expand Down
Loading
Loading