Skip to content

Commit a951f2f

Browse files
authored
Merge pull request #1453 from mcneel/kike/1.36
Kike/1.36
2 parents 744991d + 117ac90 commit a951f2f

File tree

31 files changed

+838
-388
lines changed

31 files changed

+838
-388
lines changed

docs/pages/_en/1.0/reference/release-notes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ group: Deployment & Configs
1111
### WIP
1212

1313
### RC
14-
14+
- Added 'Add Revit Link' component.
15+
- Added 'Link IFC File' component.
16+
- Added 'Link CAD File' component.
17+
- Added 'Query CAD Models' component.
1518

1619
{% endcapture %}
1720

src/RhinoInside.Revit.External/DB/Extensions/FilteredElementCollector.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ public static FilteredElementCollector WhereParameterEqualsTo(this FilteredEleme
286286
return collector.WherePasses(filter);
287287
}
288288

289+
public static FilteredElementCollector WhereParameterEqualsTo(this FilteredElementCollector collector, BuiltInParameter paramId, double value, double tolerance = Numerical.Constant.DefaultTolerance)
290+
{
291+
using (var provider = new ParameterValueProvider(new ElementId(paramId)))
292+
using (var evaluator = new FilterNumericEquals())
293+
using (var rule = new FilterDoubleRule(provider, evaluator, value, tolerance))
294+
using (var filter = new ElementParameterFilter(rule))
295+
return collector.WherePasses(filter);
296+
}
297+
289298
public static FilteredElementCollector WhereParameterEqualsTo(this FilteredElementCollector collector, BuiltInParameter paramId, string value)
290299
{
291300
if (value is null) return collector;

src/RhinoInside.Revit.External/DB/Extensions/GeometryObject.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,17 +666,16 @@ public int GetHashCode(GeometryObject value)
666666

667667
public static class GeometryObjectExtension
668668
{
669-
internal static bool IsValid(this GeometryObject geometry) => geometry?.IsValidObject() ?? false;
670-
671-
internal static bool IsValidObject(this GeometryObject geometry)
669+
internal static bool IsEmpty(this GeometryObject geometry)
672670
{
673-
#if REVIT_2021
674-
try { return geometry.Id >= 0; }
675-
#else
676-
// TODO : Test this, type by type, and use a faster fail check.
677-
try { return geometry.TryGetLocation(out var _, out var _, out var _);}
678-
#endif
679-
catch { return false; }
671+
switch (geometry)
672+
{
673+
case PolyLine pline: return pline.NumberOfCoordinates == 0;
674+
case Mesh mesh: return mesh.NumTriangles == 0;
675+
case Solid solid: return solid.Faces.IsEmpty;
676+
}
677+
678+
return false;
680679
}
681680

682681
public static bool AlmostEquals<G>(this G left, G right)

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,25 @@ internal static bool TryGetHermiteSpline(this Curve curve, out IList<Point3d> po
777777
/// <param name="angleToleranceRadians">Tolerance to use when checking for kinks, in radians.</param>
778778
/// <returns>true if the curve has kinks within tolerance and results into a PolyCurve.</returns>
779779
public static bool TryGetPolyCurve(this Curve curve, out PolyCurve polyCurve, double angleToleranceRadians)
780+
{
781+
if (GetSubCurves(curve, angleToleranceRadians) is Curve[] segments)
782+
{
783+
polyCurve = new PolyCurve();
784+
foreach (var segment in segments)
785+
polyCurve.AppendSegment(segment);
786+
787+
return true;
788+
}
789+
790+
polyCurve = default;
791+
return false;
792+
}
793+
794+
#if !RHINO_8
795+
public static Curve[] GetSubCurves(this Curve curve) => GetSubCurves(curve).ToArray();
796+
#endif
797+
798+
private static Curve[] GetSubCurves(Curve curve, double angleToleranceRadians = Math.PI / 180.0)
780799
{
781800
var kinks = default(List<double>);
782801

@@ -792,16 +811,9 @@ public static bool TryGetPolyCurve(this Curve curve, out PolyCurve polyCurve, do
792811
}
793812

794813
if (kinks is object && kinks.Count > (curve.IsClosed ? 1 : 0) && curve.Split(kinks) is Curve[] segments)
795-
{
796-
polyCurve = new PolyCurve();
797-
foreach (var segment in segments)
798-
polyCurve.AppendSegment(segment);
814+
return curve.Split(kinks);
799815

800-
return true;
801-
}
802-
803-
polyCurve = default;
804-
return false;
816+
return null;
805817
}
806818

807819
static bool TryEvaluateCurvature

src/RhinoInside.Revit.External/Extensions/System.IO.cs

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,63 @@
33

44
namespace System.IO
55
{
6-
#pragma warning disable CA1060 // Move pinvokes to native methods class
76
static class PathExtension
87
{
8+
internal static readonly StringComparer Comparer = new PathComparer();
9+
10+
private class PathComparer : StringComparer
11+
{
12+
private static readonly StringComparer StringComparer = OrdinalIgnoreCase;
13+
14+
public PathComparer() { }
15+
16+
private static string Normalize(string path) => Path.GetFullPath(path);
17+
18+
internal static string Canonicalize(string path) => new FileInfo(path).FullName;
19+
20+
public override int Compare(string x, string y)
21+
{
22+
var comparison = StringComparer.Compare(x, y);
23+
if (comparison == 0) return 0;
24+
25+
try
26+
{
27+
if (StringComparer.Compare(Normalize(x), Normalize(y)) == 0) return 0;
28+
return StringComparer.Compare(Canonicalize(x), Canonicalize(y));
29+
}
30+
catch { return comparison; }
31+
}
32+
33+
public override bool Equals(string x, string y)
34+
{
35+
if (StringComparer.Equals(x, y)) return true;
36+
try
37+
{
38+
if (StringComparer.Equals(Normalize(x), Normalize(y))) return true;
39+
return StringComparer.Equals(Canonicalize(x), Canonicalize(y));
40+
}
41+
catch { return false; }
42+
}
43+
44+
public override int GetHashCode(string obj)
45+
{
46+
try { return obj is null ? 0 : StringComparer.GetHashCode(Canonicalize(obj)); }
47+
catch { return int.MinValue; }
48+
}
49+
}
50+
51+
public static bool TryGetFullyQualifiedPath(ref string path)
52+
{
53+
if (string.IsNullOrWhiteSpace(path)) return false;
54+
if (!IsFullyQualifiedPath(path)) return false;
55+
try
56+
{
57+
path = PathComparer.Canonicalize(path);
58+
return true;
59+
}
60+
catch { return false; }
61+
}
62+
963
public static bool IsFullyQualifiedPath(this string path)
1064
{
1165
if (path == null) return false;
@@ -29,17 +83,20 @@ public static bool IsFullyQualifiedPath(this string path)
2983
#endif
3084
}
3185

32-
[DllImport("SHLWAPI", CharSet = CharSet.Unicode)]
33-
static extern bool PathCompactPathExW([Out] Text.StringBuilder pszOut, string szPath, int cchMax, int dwFlags);
3486
internal static string TripleDotPath(this string path, int maxLength)
3587
{
3688
if (path is null) return null;
3789
var builder = new Text.StringBuilder(maxLength + 1);
38-
PathCompactPathExW(builder, path, maxLength, 0);
90+
SafeNativeMethods.PathCompactPathExW(builder, path, maxLength, 0);
3991
return builder.ToString();
4092
}
93+
94+
static class SafeNativeMethods
95+
{
96+
[DllImport("SHLWAPI", CharSet = CharSet.Unicode)]
97+
public static extern bool PathCompactPathExW([Out] Text.StringBuilder pszOut, string szPath, int cchMax, int dwFlags);
98+
}
4199
}
42-
#pragma warning restore CA1060 // Move pinvokes to native methods class
43100

44101
internal static class DirectoryInfoExtension
45102
{

src/RhinoInside.Revit.GH/Components/Documents/DocumentSave.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class DocumentSave : ZuiComponent
1818
public DocumentSave() : base
1919
(
2020
name: "Save Document",
21-
nickname: "Save",
21+
nickname: "D-Save",
2222
description: "Saves a document to a given file path",
2323
category: "Revit",
2424
subCategory: "Document"
@@ -104,7 +104,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
104104
if (filePath.Last() == Path.DirectorySeparatorChar)
105105
filePath = Path.Combine(filePath, doc.Title);
106106

107-
if (filePath.IsFullyQualifiedPath())
107+
if (PathExtension.TryGetFullyQualifiedPath(ref filePath))
108108
{
109109
if (!Path.HasExtension(filePath))
110110
{

src/RhinoInside.Revit.GH/Components/Element/HostObject/ElementHost.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,8 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
4848
return;
4949
}
5050

51-
var hostId = default(ARDB.ElementId);
52-
53-
if (element.Value is ARDB.Structure.Rebar rebar) hostId = rebar.GetHostId();
54-
else if (element.Value is ARDB.Structure.RebarInSystem rebarInSystem) hostId = rebarInSystem.GetHostId();
55-
else if (element.Value is ARDB.Structure.RebarContainer rebarContainer) hostId = rebarContainer.GetHostId();
56-
else if (element.Value is ARDB.Structure.AreaReinforcement areaReinforcement) hostId = areaReinforcement.GetHostId();
57-
else if (element.Value is ARDB.Structure.PathReinforcement pathReinforcement) hostId = pathReinforcement.GetHostId();
58-
else if (element.Value is ARDB.Structure.FabricSheet fabricSheet) hostId = fabricSheet.HostId;
59-
else if (element.Value is ARDB.FabricationPart fabricationPart)
60-
{
61-
using (var hostedInfo = fabricationPart.GetHostedInfo())
62-
hostId = hostedInfo.HostId;
63-
}
64-
else hostId = element.Value.get_Parameter(ARDB.BuiltInParameter.HOST_ID_PARAM)?.AsElementId();
65-
6651
// Default to Level if hostId is null
67-
DA.SetData("Host", element.GetElement<Types.GraphicalElement>(hostId ?? element.LevelId));
52+
DA.SetData("Host", element.GetElement<Types.GraphicalElement>(element.Level));
6853
}
6954
}
7055
}

src/RhinoInside.Revit.GH/Components/Family/New.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static string GetDefaultTemplatePath(ARDB.Document doc, ARDB.ElementId categoryI
650650

651651
static bool FindTemplatePath(ARDB.Document doc, ref string templatePath, out bool pathWasRelative)
652652
{
653-
pathWasRelative = !templatePath.IsFullyQualifiedPath();
653+
pathWasRelative = !PathExtension.TryGetFullyQualifiedPath(ref templatePath);
654654

655655
// Validate input
656656
foreach (var invalid in Path.GetInvalidPathChars())

src/RhinoInside.Revit.GH/Components/Family/Save.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
126126
if (!Path.HasExtension(filePath))
127127
filePath += ".rfa";
128128

129-
if (!filePath.IsFullyQualifiedPath())
129+
if (!PathExtension.TryGetFullyQualifiedPath(ref filePath))
130130
{
131131
filePath = Path.Combine(Types.Document.FromValue(family.Document).SwapFolder.Directory.FullName, "Families", filePath);
132132
Directory.CreateDirectory(Path.GetDirectoryName(filePath));

src/RhinoInside.Revit.GH/Components/Import/IFCImportOptions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
namespace RhinoInside.Revit.GH.Components.Insert
77
{
88
[ComponentVersion(introduced: "1.36")]
9-
public class IFCImportOptions : ZuiComponent
9+
public class IFCReadOptions : ZuiComponent
1010
{
1111
public override Guid ComponentGuid => new Guid("A8F3E5C1-9D4B-4E2A-B8F1-3C5D6E7F8A9B");
1212
public override GH_Exposure Exposure => GH_Exposure.secondary;
1313
protected override string IconTag => string.Empty;
1414

15-
public IFCImportOptions() : base
15+
public IFCReadOptions() : base
1616
(
17-
name: "IFC Import Options",
18-
nickname: "IFCOpt",
19-
description: "Configure options for IFC file import or link operations",
17+
name: "IFC Read Options",
18+
nickname: "IFC-Read",
19+
description: "Configure options to read IFC files.",
2020
category: "Revit",
2121
subCategory: "Insert"
2222
)
@@ -128,7 +128,7 @@ public IFCImportOptions() : base
128128
NickName = "AC",
129129
Description = "Autocorrect off-axis lines enabled",
130130
Access = GH_ParamAccess.item
131-
}
131+
}, ParamRelevance.Secondary
132132
)
133133
};
134134

@@ -162,10 +162,10 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
162162

163163
if (options != null)
164164
{
165-
DA.SetData("Intent", (int)options.Intent);
166-
DA.SetData("Action", (int)options.Action);
167-
DA.SetData("Auto Join", options.AutoJoin);
168-
DA.SetData("Autocorrect Off Axis Lines", options.AutocorrectOffAxisLines);
165+
Params.TrySetData(DA, "Intent", () => (int)options.Intent);
166+
Params.TrySetData(DA, "Action", () => (int)options.Action);
167+
Params.TrySetData(DA, "Auto Join", () => options.AutoJoin);
168+
Params.TrySetData(DA, "Autocorrect Off Axis Lines", () => options.AutocorrectOffAxisLines);
169169
}
170170
}
171171
}

0 commit comments

Comments
 (0)