Skip to content

Commit 350a1b1

Browse files
authored
Merge pull request #1445 from mcneel/kike/1.36
Kike/1.36
2 parents f732298 + f4604d7 commit 350a1b1

File tree

4 files changed

+88
-30
lines changed

4 files changed

+88
-30
lines changed

src/RhinoInside.Revit.External/Extensions/RhinoCommon.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,11 +1527,19 @@ public static bool Scale(this RhinoViewport viewport, double scaleFactor)
15271527
return true;
15281528
}
15291529
}
1530+
}
15301531

1532+
namespace Rhino.Render
1533+
{
15311534
static class RenderMaterialExtension
15321535
{
15331536
#if !RHINO_8
1534-
public static DocObjects.Material ToMaterial(this Render.RenderMaterial material, Render.RenderTexture.TextureGeneration generation)
1537+
public static RenderMaterial Find(this RenderMaterialTable table, Guid id)
1538+
{
1539+
return table.FirstOrDefault(x => x.Id == id);
1540+
}
1541+
1542+
public static DocObjects.Material ToMaterial(this RenderMaterial material, RenderTexture.TextureGeneration generation)
15351543
{
15361544
return material.SimulatedMaterial(generation);
15371545
}

src/RhinoInside.Revit.GH/Extensions/System.Collections.Generic.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,54 @@ public static IEnumerable<int> IndexOf<T>(this IEnumerable<T> values, T value, i
5454
if (index > 0)
5555
values = values.Skip(index);
5656

57+
var comparer = EqualityComparer<T>.Default;
5758
foreach (var item in values)
5859
{
59-
if (item.Equals(value))
60+
if (comparer.Equals(item, value))
6061
yield return index;
6162

6263
index++;
6364
}
6465
}
6566

67+
public static IEnumerable<T> TakeButLast<T>(this IEnumerable<T> source, out T last) where T : class
68+
{
69+
if (source == null) throw new ArgumentNullException(nameof(source));
70+
71+
last = default;
72+
using var e = source.GetEnumerator();
73+
if (!e.MoveNext()) Array.Empty<T>();
74+
75+
var count = (source as IList)?.Count - 1 ?? 0;
76+
var queue = new Queue<T>(count);
77+
last = e.Current;
78+
while (e.MoveNext())
79+
{
80+
queue.Enqueue(last);
81+
last = e.Current;
82+
}
83+
return queue;
84+
}
85+
86+
public static IEnumerable<T> TakeButLast<T>(this IEnumerable<T> source, out T? last) where T : struct
87+
{
88+
if (source == null) throw new ArgumentNullException(nameof(source));
89+
90+
last = default;
91+
using var e = source.GetEnumerator();
92+
if (!e.MoveNext()) Array.Empty<T>();
93+
94+
var count = (source as IList)?.Count - 1 ?? 0;
95+
var queue = new Queue<T>(count);
96+
last = e.Current;
97+
while (e.MoveNext())
98+
{
99+
queue.Enqueue(last.Value);
100+
last = e.Current;
101+
}
102+
return queue;
103+
}
104+
66105
public static IEnumerable<TResult> ZipOrLast<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
67106
{
68107
if (first is null) throw new ArgumentNullException(nameof(first));

src/RhinoInside.Revit.GH/Types/Enums.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public CategoryType(ARDB.CategoryType value) : base(value) { }
8383
public override bool IsEmpty => Value == ARDB.CategoryType.Invalid;
8484
public static new IReadOnlyDictionary<int, string> NamedValues { get; } = new Dictionary<int, string>
8585
{
86-
{ (int) ARDB.CategoryType.Model, "Model" },
87-
{ (int) ARDB.CategoryType.Annotation, "Annotation" },
88-
{ (int) ARDB.CategoryType.Internal, "Internal" },
89-
{ (int) ARDB.CategoryType.AnalyticalModel, "Analytical" },
86+
{ (int) ARDB.CategoryType.Model, "Model" },
87+
{ (int) ARDB.CategoryType.Annotation, "Annotation" },
88+
{ (int) ARDB.CategoryType.Internal, "Internal" },
89+
{ (int) ARDB.CategoryType.AnalyticalModel, "Analytical Model" },
9090
};
9191
}
9292

src/RhinoInside.Revit.GH/Types/ObjectStyles/LinePatternElement.cs

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,40 +110,19 @@ out Guid guid
110110

111111
if (Id == ARDB.LinePatternElement.GetSolidPatternId())
112112
{
113-
idMap.Add(Id, guid = new Guid("{3999bed5-78ee-4d73-a059-032224c6fd55}"));
113+
idMap.Add(Id, guid = new Guid("{3999BED5-78EE-4D73-A059-032224C6FD55}"));
114114
return true;
115115
}
116116
else if (Value is ARDB.LinePatternElement linePattern)
117117
{
118118
// 2. Check if already exist
119119
var index = doc.Linetypes.Find(linePattern.Name);
120-
var linetype = index < 0 ?
121-
new Linetype() { Name = linePattern.Name } :
122-
doc.Linetypes[index];
120+
var linetype = index < 0 ? null : doc.Linetypes[index];
123121

124122
// 3. Update if necessary
125123
if (index < 0 || overwrite)
126124
{
127-
using (var pattern = linePattern.GetLinePattern())
128-
{
129-
linetype.SetSegments
130-
(
131-
pattern.GetSegments().Select
132-
(
133-
x =>
134-
{
135-
switch (x.Type)
136-
{
137-
case ARDB.LinePatternSegmentType.Dash: return UnitScale.Convert(+x.Length, UnitScale.Internal, UnitScale.Millimeters);
138-
case ARDB.LinePatternSegmentType.Space: return UnitScale.Convert(-x.Length, UnitScale.Internal, UnitScale.Millimeters);
139-
case ARDB.LinePatternSegmentType.Dot: return 0.0;
140-
default: throw new ArgumentOutOfRangeException();
141-
}
142-
}
143-
)
144-
);
145-
}
146-
125+
linetype = ToLinetype(linetype);
147126
if (index < 0) { index = doc.Linetypes.Add(linetype); linetype = doc.Linetypes[index]; }
148127
else if (overwrite) doc.Linetypes.Modify(linetype, index, true);
149128
}
@@ -195,6 +174,38 @@ internal ModelContent ToModelContent(IDictionary<ARDB.ElementId, ModelContent> i
195174
return null;
196175
}
197176
#endif
177+
178+
internal Linetype ToLinetype(Linetype linetype = null)
179+
{
180+
if (Value is ARDB.LinePatternElement linePattern)
181+
{
182+
linetype ??= new Linetype() { Name = linePattern.Name };
183+
184+
using (var pattern = linePattern.GetLinePattern())
185+
{
186+
linetype.SetSegments
187+
(
188+
pattern.GetSegments().Select
189+
(
190+
x =>
191+
{
192+
switch (x.Type)
193+
{
194+
case ARDB.LinePatternSegmentType.Dash: return UnitScale.Convert(+x.Length, UnitScale.Internal, UnitScale.Millimeters);
195+
case ARDB.LinePatternSegmentType.Space: return UnitScale.Convert(-x.Length, UnitScale.Internal, UnitScale.Millimeters);
196+
case ARDB.LinePatternSegmentType.Dot: return 0.0;
197+
default: throw new ArgumentOutOfRangeException();
198+
}
199+
}
200+
)
201+
);
202+
}
203+
204+
return linetype;
205+
}
206+
207+
return null;
208+
}
198209
#endregion
199210

200211
#region Properties

0 commit comments

Comments
 (0)