Skip to content

Commit

Permalink
Merge pull request #8 from Carson-McCombs/Temporary-Dev
Browse files Browse the repository at this point in the history
Temporary dev
  • Loading branch information
Carson-McCombs authored Jul 25, 2024
2 parents d8d4ba8 + e672d24 commit 49963dd
Show file tree
Hide file tree
Showing 69 changed files with 2,211 additions and 1,275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Autodesk.Revit.UI;
using CarsonsAddins.Properties;
using CarsonsAddins.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public PipeEndPrepPreferences(string pipeTypeId, string pipeTypeName)
this.pipeTypeId = pipeTypeId;
this.pipeTypeName = pipeTypeName;
}
[JsonConstructor]
[System.Text.Json.Serialization.JsonConstructor]
public PipeEndPrepPreferences(string pipeTypeId, string pipeTypeName, string bellEndPrep, string spigotEndPrep)
{
this.pipeTypeId = pipeTypeId;
Expand Down
206 changes: 139 additions & 67 deletions CarsonsAddins/CarsonsAddins.csproj

Large diffs are not rendered by default.

91 changes: 58 additions & 33 deletions CarsonsAddins/CarsonsAddinsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
using Newtonsoft.Json;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using CarsonsAddins.GenericCommands;
using CarsonsAddins.Settings.ComponentStates.Models;
using CarsonsAddins.Settings.Main.Views;
using CarsonsAddins.Settings.Dimensioning.Models;

namespace CarsonsAddins
{
Expand All @@ -43,55 +47,76 @@ public partial class CarsonsAddinsApplication : IExternalApplication
public static string tmplog = string.Empty;
private List<ComponentState> componentStates = new List<ComponentState>();
private readonly List<ISettingsComponent> settingsComponents = new List<ISettingsComponent>();
public static CarsonsAddinsApplication instance { get; private set; }
public CarsonsAddinsApplication() { instance = this; }
public Result OnStartup(UIControlledApplication app)
{
ApplicationIds.Init();
app.CreateRibbonTab("Carsons Addins");
RibbonPanel panel = app.CreateRibbonPanel("Carsons Addins", "Tools");
Assembly assembly = Assembly.GetExecutingAssembly();

MyApplicationSettings.Instance = new MyApplicationSettings();

ComponentStatePreferences.Instance = new ComponentStatePreferences();

// Always loads in the Application Settings Window
panel.AddItem(MyApplicationSettingsWindow.RegisterButton(assembly));

// Then loads in ComponentStates based on the user's saved preference on which Component should be enabled at launch ( or loads in whichever is not a work in progress component by default )
componentStates = MyApplicationSettings.Instance.InitComponentStates(assembly);
componentStates = ComponentStatePreferences.Instance.InitComponentStates(assembly);
Dictionary<string, PulldownButton> pulldownButtonDictionary = new Dictionary<string, PulldownButton>();

PulldownButtonData automationPullDownButtonData = new PulldownButtonData("AutomationPullDownButton", "Automation")
if (componentStates.Any(component => component.FolderName == "Automation" && component.IsEnabled))
{
PulldownButtonData automationPullDownButtonData = new PulldownButtonData("AutomationPullDownButton", "Automation")
{
ToolTip = "All tools for automating tasks.",
Image = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.automation_icon_32.png"),
LargeImage = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.automation_icon_32.png")
};
PulldownButton automationPullDownButton = panel.AddItem(automationPullDownButtonData) as PulldownButton;
pulldownButtonDictionary.Add("Automation", automationPullDownButton);
}
if (componentStates.Any(component => component.FolderName == "Dimensioning" && component.IsEnabled))
{
ToolTip = "All tools with their own dedicated window or dockable pane.",
Image = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.automation_icon_32.png"),
LargeImage = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.automation_icon_32.png")
};
PulldownButton automationPullDownButton = panel.AddItem(automationPullDownButtonData) as PulldownButton;
pulldownButtonDictionary.Add("Automation", automationPullDownButton);
// Includes all components with UI, such as Windows and DockablePanes
PulldownButtonData dimensioningPulldownButtonData = new PulldownButtonData("UIComponentsPullDownButton", "Dimensioning")
PulldownButtonData dimensioningPulldownButtonData = new PulldownButtonData("UIComponentsPullDownButton", "Dimensioning")
{
ToolTip = "All tools for creating or manipulating dimensions.",
Image = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.dimension_icon_32.png"),
LargeImage = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.dimension_icon_32.png")
};
PulldownButton dimensioningPulldownButton = panel.AddItem(dimensioningPulldownButtonData) as PulldownButton;
pulldownButtonDictionary.Add("Dimensioning", dimensioningPulldownButton);
}
if (componentStates.Any(component => component.FolderName == "Debug" && component.IsEnabled))
{
ToolTip = "All tools with their own dedicated window or dockable pane.",
Image = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.dimension_icon_32.png"),
LargeImage = Utils.MediaUtils.GetImage(assembly, "CarsonsAddins.Resources.dimension_icon_32.png")
};
PulldownButton dimensioningPulldownButton = panel.AddItem(dimensioningPulldownButtonData) as PulldownButton;
pulldownButtonDictionary.Add("Dimensioning", dimensioningPulldownButton);
// Includes all components without UI
PulldownButtonData miscComponentsPulldownButtonData = new PulldownButtonData("MiscComponentsPullDownButton", "Misc")
PulldownButtonData debugPulldownButtonData = new PulldownButtonData("DebugPullDownButton", "Debug")
{
ToolTip = "All tools for development purposes.",
};
PulldownButton debugPulldownButton = panel.AddItem(debugPulldownButtonData) as PulldownButton;
pulldownButtonDictionary.Add("Debug", debugPulldownButton);
}
if (componentStates.Any(component => component.FolderName == "Misc" && component.IsEnabled))
{
ToolTip = "All tools without their own dedicated window or dockable pane.",

};
PulldownButton miscComponentsPulldownButton = panel.AddItem(miscComponentsPulldownButtonData) as PulldownButton;
pulldownButtonDictionary.Add("Misc", miscComponentsPulldownButton);
PulldownButtonData miscComponentsPulldownButtonData = new PulldownButtonData("MiscComponentsPullDownButton", "Misc")
{
ToolTip = "All tools without their own dedicated window or dockable pane.",

};
PulldownButton miscComponentsPulldownButton = panel.AddItem(miscComponentsPulldownButtonData) as PulldownButton;
pulldownButtonDictionary.Add("Misc", miscComponentsPulldownButton);
}
RegisterComponentPushButtons(assembly, panel, pulldownButtonDictionary);
app.ControlledApplication.ApplicationInitialized += RegisterDockablePanes;
app.ViewActivated += CheckIfFocusingOnNewDocument;
return Result.Succeeded;
}


private void CheckIfFocusingOnNewDocument(object sender, ViewActivatedEventArgs e)
{
if (e.CurrentActiveView?.Document == null || e.CurrentActiveView?.Document == e.PreviousActiveView?.Document) return;

DimensionPreferences.Instance = DimensionPreferences.CreateFromPreferences(e.CurrentActiveView.Document);
}

public Result OnShutdown(UIControlledApplication app)
{
return Result.Succeeded;
Expand Down Expand Up @@ -125,9 +150,9 @@ private void RegisterComponentPushButtons(Assembly assembly, RibbonPanel panel,
}
}

/// <summary>
/// Registers all of the classes with a SettingsComponent that contain a DockablePane via reflection.
/// </summary>
/// <summary>
/// Registers all of the classes with a SettingsComponent that contain a DockablePane via reflection.
/// </summary>
private void RegisterDockablePanes(object sender, ApplicationInitializedEventArgs e)
{
UIApplication uiapp = new UIApplication(sender as Autodesk.Revit.ApplicationServices.Application);
Expand All @@ -136,9 +161,9 @@ private void RegisterDockablePanes(object sender, ApplicationInitializedEventArg
if (!(component is IDockablePaneProvider)) continue;
if (component is ISettingsUIComponent uiComponent)
{
Type registerCommandType = typeof( GenericCommands.RegisterDockablePane<>).MakeGenericType(uiComponent.GetType());
Type registerCommandType = typeof( RegisterDockablePane<>).MakeGenericType(uiComponent.GetType());
var registerCommand = Activator.CreateInstance(registerCommandType);
if (registerCommand is GenericCommands.IExecuteWithUIApplication command) command.Execute(uiapp);
if (registerCommand is IExecuteWithUIApplication command) command.Execute(uiapp);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void CheckNoneButtonPress(object sender, RoutedEventArgs e)
SetAllCategoriesToSelectionState(false);
foreach (CategorySelectionItem item in categorySelectionItems) b += item.ToString() + '\n';

TaskDialog.Show("Comparing Check None Action", "BEFORE: \n " + a + "\n\nAFTER: \n" + b);
TaskDialog.Show("Comparing Check Default Action", "BEFORE: \n " + a + "\n\nAFTER: \n" + b);
}

private void ApplySelectionButtonPress(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Autodesk.Revit.UI;
using System.Runtime.ExceptionServices;
using System.Windows.Controls;
using CarsonsAddins.Settings.Dimensioning.Models;

namespace CarsonsAddins.Pipeline.Models
{
Expand Down Expand Up @@ -60,8 +61,8 @@ public static void CreateDimensions(Document doc, Element[] elements, Element se
View activeView = doc.ActiveView;
Plane plane = GeometryUtils.GetOrCreatePlane(doc);

DimensionStyles dimensionStyles = DimensionSettingsWindow.DimensionStylesSettings ?? new DimensionStyles();
ElementId[] validStyleIds = dimensionStyles.centerlineStyles.Select(style => style.Id).ToArray();
DimensionPreferences dimensionPreferences = DimensionPreferences.Instance ?? new DimensionPreferences();
ElementId[] validStyleIds = dimensionPreferences.linesStyles.Select(style => style.Id).ToArray();
ElementId defaultDimensionTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.LinearDimensionType);
DimensionType defaultDimensionType = (defaultDimensionTypeId != ElementId.InvalidElementId) ? doc.GetElement(defaultDimensionTypeId) as DimensionType : default;

Expand Down Expand Up @@ -90,49 +91,78 @@ public static void CreateDimensions(Document doc, Element[] elements, Element se

//Calculates the secondary dimension line by creating a line parallel to the primary dimension line but offset a distance based on the dimension type settings
//( right now it only checks the pipe dimension type settings, but it should choose the type with the largest text and text offset )
Line secondaryDimensionLine = CreateSecondaryDimensionLine(doc.ActiveView, dimensionStyles.secondaryPipeDimensionType ?? defaultDimensionType, projectedElementLine, primaryDimensionLine);
Line secondaryDimensionLine = CreateSecondaryDimensionLine(doc.ActiveView, dimensionPreferences.secondaryPipeDimensionType ?? defaultDimensionType, projectedElementLine, primaryDimensionLine);

//Creates a reference array for the primary dimension based on its end point references.
ReferenceArray primaryReferenceArray = new ReferenceArray();
//ReferenceArray secondaryReferenceArray = new ReferenceArray();
PipingElementReferenceOrderedList referenceSets = new PipingElementReferenceOrderedList(validStyleIds, doc.ActiveView, elements);
referenceSets.SubtractFlanges();
DimensionReferences referenceSets = new DimensionReferences(validStyleIds, doc.ActiveView, dimensionPreferences, elements);
ReferenceArray secondaryReferenceArray = new ReferenceArray();
bool matchesPrimary = true;
for (int i = 0; i < referenceSets.nodes.Length; i++)
{
if (referenceSets.nodes[i].isNonConnector) continue;
PipingElementReferenceOrderedList.ReferenceNode node = referenceSets.nodes[i];
DimensionReferences.ReferenceNode node = referenceSets.nodes[i];
if (node.ignore) continue;


AddReferences(ref primaryReferenceArray, ref secondaryReferenceArray, node, secondaryDimension);
if (node.firstReference != null || node.lastReference != null) matchesPrimary = false;
bool splitDimension = (i == referenceSets.nodes.Length - 1) || (node.mode == PipingElementReferenceOrderedList.FlangeDimensionMode.Ignore || (node.mode == PipingElementReferenceOrderedList.FlangeDimensionMode.Partial && (node.isEdge || node.adjacentNonLinear)));
if (splitDimension && secondaryReferenceArray.Size > 1)
matchesPrimary = AddReferences(ref primaryReferenceArray, ref secondaryReferenceArray, node, secondaryDimension, matchesPrimary);
bool splitDimension = node.isEnd || node.mode == FlangeDimensionMode.Exact || (node.mode == FlangeDimensionMode.Partial && (node.isEdge || node.adjacentNonLinear));
if (splitDimension)
{

BuiltInCategory builtInCategory = (node.referenceCount == secondaryReferenceArray.Size) ? node.builtInCategory : BuiltInCategory.OST_PipeCurves;
if (!matchesPrimary) doc.Create.NewDimension(activeView, secondaryDimensionLine, secondaryReferenceArray, dimensionStyles.GetSecondaryDimensionType(builtInCategory) ?? defaultDimensionType);
secondaryReferenceArray.Clear();
matchesPrimary = true;
if (!matchesPrimary)
{
if (secondaryReferenceArray.Size > 1) doc.Create.NewDimension(activeView, secondaryDimensionLine, secondaryReferenceArray, dimensionPreferences.GetSecondaryDimensionType(builtInCategory) ?? defaultDimensionType);
secondaryReferenceArray.Clear();
matchesPrimary = true;
}
else if (node.centerReference != null)
{
secondaryReferenceArray.Clear();
matchesPrimary = true;
}
}

}
doc.Create.NewDimension(activeView, primaryDimensionLine, primaryReferenceArray, dimensionStyles.primaryDimensionType ?? defaultDimensionType);
doc.Create.NewDimension(activeView, primaryDimensionLine, primaryReferenceArray, dimensionPreferences.primaryDimensionType ?? defaultDimensionType);
}
private static void AddReferences(ref ReferenceArray primaryReferenceArray, ref ReferenceArray secondaryReferenceArray, PipingElementReferenceOrderedList.ReferenceNode node, bool secondaryDimension)
{
if (node.isStart && node.centerReference == null && node.lastReference != null) primaryReferenceArray.Append(node.lastReference);
if (node.centerReference != null) primaryReferenceArray.Append(node.centerReference);
if (node.isEnd && node.centerReference == null && node.firstReference != null) primaryReferenceArray.Append(node.firstReference);
private static bool AddReferences(ref ReferenceArray primaryReferenceArray, ref ReferenceArray secondaryReferenceArray, DimensionReferences.ReferenceNode node, bool secondaryDimension, bool matchesPrimary)
{
int addedFirst = 0;
int addedCenter = 0;
int addedLast = 0;
if (node.isEdge)
{
if (node.isLinear)
{
if (node.isEnd) AddReferenceIfNotNull(ref primaryReferenceArray, node.lastReference, ref addedLast);
else if (node.isStart) AddReferenceIfNotNull(ref primaryReferenceArray, node.firstReference, ref addedFirst);
}
else if (node.centerReference == null)
{
if (node.isStart) AddReferenceIfNotNull(ref primaryReferenceArray, node.lastReference, ref addedLast);
else if (node.isEnd) AddReferenceIfNotNull(ref primaryReferenceArray, node.firstReference, ref addedFirst);
}
}
AddReferenceIfNotNull(ref primaryReferenceArray, node.centerReference, ref addedCenter);


if (secondaryDimension)
{
if (node.firstReference != null) secondaryReferenceArray.Append(node.firstReference);
if (node.centerReference != null) secondaryReferenceArray.Append(node.centerReference);
if (node.lastReference != null) secondaryReferenceArray.Append(node.lastReference);
AddReferenceIfNotNull(ref secondaryReferenceArray, node.firstReference, ref addedFirst);
AddReferenceIfNotNull(ref secondaryReferenceArray, node.centerReference, ref addedCenter);
AddReferenceIfNotNull(ref secondaryReferenceArray, node.lastReference, ref addedLast);
}
return !(!matchesPrimary || node.mode == FlangeDimensionMode.Exact || addedFirst > 0 || addedLast > 0);

}
private static void AddReferenceIfNotNull(ref ReferenceArray referenceArray, Reference reference, ref int counter)
{
if (referenceArray == null || reference == null) return;
referenceArray.Append(reference);
counter ++;
}
}

}
Expand Down
Loading

0 comments on commit 49963dd

Please sign in to comment.