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

Fix on 'Annotation Leaders' #1038

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/RhinoInside.Revit.GH/Components/Annotations/Leaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,31 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
leaderElement.HasLeader = hasLeader;
}

if (!(hasLeader is false))
if (leaderElement.HasLeader is true || hasLeader is true)
{
if (Params.GetDataList(DA, "End Locations", out IList<Point3d?> endPositions))
{
StartTransaction(annotation.Document);

if (annotation.Value is Autodesk.Revit.DB.TextNote note)
{
var location = annotation.Location;
note.RemoveLeaders();

var location = annotation.Location;
foreach (var point in endPositions)
{
if (!point.HasValue) continue;
location.ClosestParameter(point.Value, out var u, out var v);

if (note.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ARC_LEADER_PARAM).AsBoolean())
{
if (u < 0.0)
note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_ARC_L);
else
note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_ARC_R);
if (u < 0.0) note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_ARC_L);
else note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_ARC_R);
}
else
{
if (u < 0.0)
note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_STRAIGHT_L);
else
note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_STRAIGHT_R);
if (u < 0.0) note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_STRAIGHT_L);
else note.AddLeader(Autodesk.Revit.DB.TextNoteLeaderTypes.TNLT_STRAIGHT_R);
}
}
}
Expand All @@ -217,8 +214,10 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
}
}

Params.TrySetData(DA, "Leader", () => leaderElement.HasLeader);
// Regenerate is necessary here to obtain correct elbow positions.
annotation.Document.Regenerate();
}
Params.TrySetData(DA, "Leader", () => leaderElement.HasLeader);

if (Params.GetDataList(DA, "Text Locations", out IList<Point3d?> textPositions))
{
Expand All @@ -234,8 +233,6 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
}
}

// Regenerate is necessary here to obtain correct elbow positions.
annotation.Document.Regenerate();
var leaders = leaderElement.Leaders;

Params.TrySetDataList
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Components/Input/PickElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected override void BeforeSolveInstance()
}
else
{
foreach (var element in Elements.OfType<Types.IGH_ReferenceData>())
foreach (var element in Elements.OfType<IGH_ReferencedData>())
element.LoadReferencedData();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ public override void ClearData()

foreach (var goo in PersistentData)
{
if (goo is RhinoInside.Revit.GH.Types.IGH_ReferenceData id) id.UnloadReferencedData();
if (goo is IGH_ReferencedData id) id.UnloadReferencedData();
else if (goo is IGH_GeometricGoo geo) geo.ClearCaches();
}

Expand Down Expand Up @@ -1203,7 +1203,7 @@ protected virtual void LoadVolatileData()
{
var goo = branch[i];

if (goo is RhinoInside.Revit.GH.Types.IGH_ReferenceData id && id.IsReferencedData && !id.IsReferencedDataLoaded && !id.LoadReferencedData())
if (goo is IGH_ReferencedData id && id.IsReferencedData && !id.IsReferencedDataLoaded && !id.LoadReferencedData())
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"A referenced {goo.TypeName} could not be found.");
}
Expand Down
14 changes: 8 additions & 6 deletions src/RhinoInside.Revit.GH/Parameters/PersistentParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
using Grasshopper.Kernel.Types;
using OS = System.Environment;

namespace RhinoInside.Revit.GH.Types
#if !RHINO_8
namespace Grasshopper.Kernel.Types
{
/// <summary>
/// Implement this interface into your Goo type if you are referencing external resources.
/// </summary>
/// <remarks>
/// <see cref="Parameters.PersistentParam{T}"/> uses it to load-unload external resources.
/// </remarks>
interface IGH_ReferenceData
interface IGH_ReferencedData
{
bool IsReferencedData { get; }
bool IsReferencedDataLoaded { get; }
bool LoadReferencedData();
void UnloadReferencedData();
}
}
#endif

namespace RhinoInside.Revit.GH.Parameters
{
Expand Down Expand Up @@ -179,7 +181,7 @@ public override void ClearData()
if (PersistentData.IsEmpty)
return;

foreach (var reference in PersistentData.OfType<Types.IGH_ReferenceData>())
foreach (var reference in PersistentData.OfType<IGH_ReferencedData>())
reference.UnloadReferencedData();
}

Expand All @@ -197,7 +199,7 @@ protected virtual void ReloadVolatileData()
{
for (int i = 0; i < branch.Count; i++)
{
if (branch[i] is Types.IGH_ReferenceData reference)
if (branch[i] is IGH_ReferencedData reference)
{
if (reference.IsReferencedData && !reference.LoadReferencedData())
{
Expand Down Expand Up @@ -263,7 +265,7 @@ protected T PersistentValue

value = (T) value?.Duplicate();

if (value is Types.IGH_ReferenceData data)
if (value is IGH_ReferencedData data)
data.LoadReferencedData();

return value?.IsValid is true ? value : default;
Expand Down Expand Up @@ -361,7 +363,7 @@ protected override bool Prompt_ManageCollection(GH_Structure<T> values)
if (item.IsValid)
continue;

if (item is Types.IGH_ReferenceData reference)
if (item is IGH_ReferencedData reference)
{
if (reference.IsReferencedData)
reference.LoadReferencedData();
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Types/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface IGH_Document : IGH_Goo, IEquatable<IGH_Document>

[Kernel.Attributes.Name("Document"), AssemblyPriority]
[DebuggerDisplay("{this.ToString()}: id {Id}")]
public class Document : IGH_Document, IGH_ReferenceData, IGH_ItemDescription, ICloneable
public class Document : IGH_Document, IGH_ReferencedData, IGH_ItemDescription, ICloneable
{
#region System.Object
public bool Equals(IGH_Document other)
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Types/DocumentObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public interface IGH_ReferenceObject : IGH_DocumentObject
public abstract class ReferenceObject : DocumentObject,
IEquatable<ReferenceObject>,
IGH_ReferenceObject,
IGH_ReferenceData,
IGH_ReferencedData,
IGH_QuickCast
{
#region System.Object
Expand Down