diff --git a/CarsonsAddins/Shared/Updaters/PipeEndPrepBCUpdater.cs b/CarsonsAddins/Automation/PipeEndPrep/Models/PipeEndPrepBCUpdater.cs similarity index 100% rename from CarsonsAddins/Shared/Updaters/PipeEndPrepBCUpdater.cs rename to CarsonsAddins/Automation/PipeEndPrep/Models/PipeEndPrepBCUpdater.cs diff --git a/CarsonsAddins/Shared/Updaters/PipeEndPrepUpdater.cs b/CarsonsAddins/Automation/PipeEndPrep/Models/PipeEndPrepUpdater.cs similarity index 100% rename from CarsonsAddins/Shared/Updaters/PipeEndPrepUpdater.cs rename to CarsonsAddins/Automation/PipeEndPrep/Models/PipeEndPrepUpdater.cs diff --git a/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepBCWindow.xaml.cs b/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepBCWindow.xaml.cs index eeab83d..b382805 100644 --- a/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepBCWindow.xaml.cs +++ b/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepBCWindow.xaml.cs @@ -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; diff --git a/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepWindow.xaml.cs b/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepWindow.xaml.cs index c2fe7cf..a004de4 100644 --- a/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepWindow.xaml.cs +++ b/CarsonsAddins/Automation/PipeEndPrep/ViewModels/PipeEndPrepWindow.xaml.cs @@ -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; diff --git a/CarsonsAddins/CarsonsAddins.csproj b/CarsonsAddins/CarsonsAddins.csproj index 28ae44b..bf6368a 100644 --- a/CarsonsAddins/CarsonsAddins.csproj +++ b/CarsonsAddins/CarsonsAddins.csproj @@ -50,6 +50,10 @@ CarsonsAddins + + enable + 8.0 + @@ -60,22 +64,19 @@ true - - False - ..\..\..\..\..\..\Program Files\Autodesk\Revit 2021\AdWindows.dll + + E:\Revit\Product\Revit 2023\AdWindows.dll - - ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + E:\Revit\Product\Revit 2023\AddIns\PnIDModeler\Newtonsoft.Json.dll - - False - ..\..\..\..\..\..\Program Files\Autodesk\Revit 2021\RevitAPI.dll + + E:\Revit\Product\Revit 2023\RevitAPI.dll - - False - ..\..\..\..\..\..\Program Files\Autodesk\Revit 2021\RevitAPIUI.dll + + E:\Revit\Product\Revit 2023\RevitAPIUI.dll @@ -87,11 +88,7 @@ 3.5 - - ..\packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll - True - True - + @@ -103,20 +100,44 @@ - - - - - - - - + + + + + + + + + + + + + + + DimensionSettingsControl.xaml + + + DimensionTypeSelectorControl.xaml + + + FlangeModeSelectorControl.xaml + - - - - - + + + + + + + + ParameterManagerDockablePane.xaml + + + + + + SettingsPluginControl.xaml + @@ -133,37 +154,51 @@ CarsonsAddinsApplication.cs - - + + + GraphicsStylesSelectorControl.xaml + + + + MyApplicationSettingsWindow.xaml + - + - + + + CopyTaskDialog.xaml + + - - - - - - - + + TextBoxWithLabel.xaml + + + ToggleableTextBox.xaml + + + + + + - + + - @@ -176,7 +211,6 @@ - SettingsSingleFileGenerator MySettings.Designer.cs @@ -191,62 +225,65 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer - - + + MSBuild:Compile Designer - - + + MSBuild:Compile Designer - - + + Designer MSBuild:Compile - - MSBuild:Compile + Designer - - MSBuild:Compile - Designer - - MSBuild:Compile + Designer + MSBuild:Compile MSBuild:Compile Designer - + + Designer MSBuild:Compile + + Designer + MSBuild:Compile - + + Designer MSBuild:Compile + + Designer + MSBuild:Compile - + + Designer MSBuild:Compile + + Designer + MSBuild:Compile - MSBuild:Compile Designer + MSBuild:Compile - - - - - - + @@ -257,5 +294,40 @@ + + + + + + 8.0.0 + + + 4.5.1 + + + 4.5.5 + + + 4.5.0 + + + 4.3.1 + + + 6.0.0 + + + 8.0.0 + + + 8.0.4 + + + 4.5.4 + + + 4.5.0 + + \ No newline at end of file diff --git a/CarsonsAddins/CarsonsAddinsApplication.cs b/CarsonsAddins/CarsonsAddinsApplication.cs index cfd33f0..35279db 100644 --- a/CarsonsAddins/CarsonsAddinsApplication.cs +++ b/CarsonsAddins/CarsonsAddinsApplication.cs @@ -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 { @@ -43,8 +47,6 @@ public partial class CarsonsAddinsApplication : IExternalApplication public static string tmplog = string.Empty; private List componentStates = new List(); private readonly List settingsComponents = new List(); - public static CarsonsAddinsApplication instance { get; private set; } - public CarsonsAddinsApplication() { instance = this; } public Result OnStartup(UIControlledApplication app) { ApplicationIds.Init(); @@ -52,46 +54,69 @@ public Result OnStartup(UIControlledApplication app) 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 pulldownButtonDictionary = new Dictionary(); - - 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; @@ -125,9 +150,9 @@ private void RegisterComponentPushButtons(Assembly assembly, RibbonPanel panel, } } - /// - /// Registers all of the classes with a SettingsComponent that contain a DockablePane via reflection. - /// + /// + /// Registers all of the classes with a SettingsComponent that contain a DockablePane via reflection. + /// private void RegisterDockablePanes(object sender, ApplicationInitializedEventArgs e) { UIApplication uiapp = new UIApplication(sender as Autodesk.Revit.ApplicationServices.Application); @@ -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); } } } diff --git a/CarsonsAddins/Shared/Updaters/PipingLCUpdater.cs b/CarsonsAddins/Deprecated/PipingLC/Models/PipingLCUpdater.cs similarity index 100% rename from CarsonsAddins/Shared/Updaters/PipingLCUpdater.cs rename to CarsonsAddins/Deprecated/PipingLC/Models/PipingLCUpdater.cs diff --git a/CarsonsAddins/Deprecated/SimpleFilter/ViewModels/SimpleFilterDockablePane.xaml.cs b/CarsonsAddins/Deprecated/SimpleFilter/ViewModels/SimpleFilterDockablePane.xaml.cs index a046b92..8604a71 100644 --- a/CarsonsAddins/Deprecated/SimpleFilter/ViewModels/SimpleFilterDockablePane.xaml.cs +++ b/CarsonsAddins/Deprecated/SimpleFilter/ViewModels/SimpleFilterDockablePane.xaml.cs @@ -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) diff --git a/CarsonsAddins/Pipeline/Models/DimensionPipeLineCommand.cs b/CarsonsAddins/Dimensioning/DimensionPipeline/DimensionPipeLineCommand.cs similarity index 100% rename from CarsonsAddins/Pipeline/Models/DimensionPipeLineCommand.cs rename to CarsonsAddins/Dimensioning/DimensionPipeline/DimensionPipeLineCommand.cs diff --git a/CarsonsAddins/Pipeline/Models/DimensionPipeline.cs b/CarsonsAddins/Dimensioning/DimensionPipeline/DimensionPipeline.cs similarity index 84% rename from CarsonsAddins/Pipeline/Models/DimensionPipeline.cs rename to CarsonsAddins/Dimensioning/DimensionPipeline/DimensionPipeline.cs index b95f403..4b67d94 100644 --- a/CarsonsAddins/Pipeline/Models/DimensionPipeline.cs +++ b/CarsonsAddins/Dimensioning/DimensionPipeline/DimensionPipeline.cs @@ -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 { @@ -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; @@ -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 ++; + } } } diff --git a/CarsonsAddins/Dimensioning/DimensionPipeline/DimensionReferences.cs b/CarsonsAddins/Dimensioning/DimensionPipeline/DimensionReferences.cs new file mode 100644 index 0000000..e178e5c --- /dev/null +++ b/CarsonsAddins/Dimensioning/DimensionPipeline/DimensionReferences.cs @@ -0,0 +1,288 @@ +using Autodesk.Revit.DB; +using CarsonsAddins.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using static CarsonsAddins.Utils.DimensioningUtils; + +namespace CarsonsAddins.Settings.Dimensioning.Models +{ + class DimensionReferences + { + + public Element[] orderedElements; + public ReferenceNode[] nodes; + private DimensionPreferences dimensionPreferences; + public DimensionReferences(ElementId[] validStyleIds, View activeView, DimensionPreferences dimensionPreferences, Element[] orderedElements) + { + this.orderedElements = orderedElements; + this.dimensionPreferences = dimensionPreferences; + nodes = new ReferenceNode[orderedElements.Length]; + PopulateNodes(validStyleIds, activeView); + } + + private void PopulateNodes(ElementId[] validStyleIds, View activeView) + { + Plane plane = activeView.SketchPlane.GetPlane(); + for (int i = 0; i < orderedElements.Length; i++) + { + CreateReferenceNode(i); + } + if (nodes.Length > 1) + { + SetFirstConnector(); + SetLastConnector(); + + } + else if (nodes[0].isLinear) + { + SetSingleElementConnectors(); + } + PopulateNodeReferences(validStyleIds, activeView); + FillAdjacentNodeReferences(); + SetAdjacentNonLinear(); + MoveEdges(); + SubtractFlanges(); + } + private void SetFirstConnector() + { + if (!nodes[0].isLinear) return; + Connector connector = ConnectionUtils.GetParallelConnector(ConnectionUtils.GetConnectors(orderedElements[0]).Where(con => ConnectionUtils.IsConnectedTo(orderedElements[1], con)).FirstOrDefault()); + nodes[0].firstConnector = connector; + } + private void SetLastConnector() + { + if (!nodes[nodes.Length - 1].isLinear) return; + Connector connector = ConnectionUtils.GetParallelConnector(ConnectionUtils.GetConnectors(orderedElements[nodes.Length - 1]).Where(con => ConnectionUtils.IsConnectedTo(orderedElements[nodes.Length - 2], con)).FirstOrDefault()); + nodes[nodes.Length - 1].lastConnector = connector; + } + private void SetSingleElementConnectors() + { + Connector[] connectors = ConnectionUtils.GetConnectors(orderedElements[0]); + nodes[0].firstConnector = connectors[0]; + nodes[0].lastConnector = connectors[1]; + } + private void CreateReferenceNode(int index) + { + Element element = orderedElements[index]; + Connector firstConnector = null; + if (index > 0) + { + (Connector, Connector) connection = ConnectionUtils.TryGetConnection(orderedElements[index - 1], element); + firstConnector = connection.Item2; + nodes[index - 1].lastConnector = connection.Item1; + } + bool isLinear = ConnectionUtils.IsLinearElement(element); + bool isStart = index == 0; + bool isEnd = index == orderedElements.Length - 1; + bool isNonConnector = IsNonConnector(element); + FlangeDimensionMode mode = dimensionPreferences.GetMode(element); + nodes[index] = new ReferenceNode + { + builtInCategory = (BuiltInCategory)element.Category.Id.IntegerValue, + mode = mode, + origin = GeometryUtils.GetOrigin(element.Location), + isStart = isStart, + isEnd = isEnd, + isLinear = isLinear, + adjacentNonLinear = false, + isNonConnector = isNonConnector, + ignore = isNonConnector, + firstConnector = firstConnector + }; + } + private bool IsNonConnector(Element element) + { + if (element == null) return false; + if (!(element is FamilyInstance familyInstance)) return false; + return (familyInstance.Symbol.FamilyName == "Non-Connector"); + + } + private void MoveEdges() + { + if (nodes[0].isNonConnector || nodes[0].isFlange) + { + int nextIndex = GetAdjacentElementIndex(1, 1, false, false); + if (nextIndex > 0) + { + for (int i = 0; i < nextIndex; i++) nodes[i].ignore = true; + nodes[nextIndex].isStart = true; + } + } + if (nodes[nodes.Length - 1].isNonConnector || nodes[nodes.Length - 1].isFlange) + { + int previousIndex = GetAdjacentElementIndex(nodes.Length - 2, -1, false, false); + if (previousIndex >= 0) + { + for (int i = nodes.Length - 1; i > previousIndex; i--) nodes[i].ignore = true; + nodes[previousIndex].isEnd = true; + } + } + } + + private Reference GetPseudoConnectorReference(ElementId[] validStyleIds, View activeView, Plane plane, Connector connector) + { + return GeometryUtils.GetPseudoReferenceOfConnector(validStyleIds, GeometryUtils.GetGeometryOptions(activeView), plane, connector) ?? + GeometryUtils.GetPseudoReferenceOfConnector(validStyleIds, GeometryUtils.GetGeometryOptions(), plane, connector); + } + + private Reference FindReference(GeometryUtils.XYZWithReference[] xyzReferences, Plane plane, XYZ xyz) + { + Reference reference = xyzReferences.Where(xyzReference => xyz.IsAlmostEqualTo(xyzReference.xyz)).FirstOrDefault().reference; + if (reference != null) return reference; + XYZ projectedXYZ = GeometryUtils.ProjectPointOntoPlane(plane, xyz); + Reference projectedReference = xyzReferences.Where(xyzReference => xyz.IsAlmostEqualTo(GeometryUtils.ProjectPointOntoPlane(plane, xyzReference.xyz))).FirstOrDefault().reference; + return projectedReference; + } + + private void PopulateNodeReferences(ElementId[] validStyleIds, View activeView) + { + Plane plane = activeView.SketchPlane.GetPlane(); + GeometryUtils.XYZWithReference[][] nodeReferencesWithView = Enumerable.Range(0,nodes.Length).Select(i => GeometryUtils.XYZWithReference.StripGeometryObjectsWithReferences(validStyleIds, GeometryUtils.GetGeometryOptions(activeView), orderedElements[i])).ToArray(); + GeometryUtils.XYZWithReference[][] nodeReferencesWithoutView = Enumerable.Range(0, nodes.Length).Select(i => GeometryUtils.XYZWithReference.StripGeometryObjectsWithReferences(validStyleIds, GeometryUtils.GetGeometryOptions(), orderedElements[i])).ToArray(); + for (int i = 0; i < nodes.Length; i++) + { + if (nodes[i].firstConnector != null) + { + XYZ firstConnectorOrigin = nodes[i].firstConnector.Origin; + nodes[i].firstReference = FindReference(nodeReferencesWithView[i], plane, firstConnectorOrigin) ?? FindReference(nodeReferencesWithoutView[i], plane, firstConnectorOrigin); + } + if (!nodes[i].isLinear) + { + XYZ origin = nodes[i].origin; + nodes[i].centerReference = FindReference(nodeReferencesWithView[i], plane, origin) ?? FindReference(nodeReferencesWithoutView[i], plane, origin); + } + if (nodes[i].lastConnector != null) + { + XYZ lastConnectorOrigin = nodes[i].lastConnector.Origin; + nodes[i].lastReference = FindReference(nodeReferencesWithView[i], plane, lastConnectorOrigin) ?? FindReference(nodeReferencesWithoutView[i], plane, lastConnectorOrigin); + } + + } + } + private void FillAdjacentNodeReferences() + { + for (int i = 0; i < nodes.Length - 1; i++) + { + if ((nodes[i].firstReference == null) != (nodes[i + 1].lastReference == null)) + { + Reference reference = nodes[i].lastReference ?? nodes[i + 1].firstReference; + nodes[i].lastReference = reference; + nodes[i + 1].firstReference = reference; + } + + } + } + private void SetAdjacentNonLinear() + { + for (int i = 0; i < nodes.Length; i++) + { + if (nodes[i].isLinear) continue; + nodes[i].adjacentNonLinear = true; + if (i > 0) nodes[i - 1].adjacentNonLinear = true; + if (i < nodes.Length - 1) nodes[i + 1].adjacentNonLinear = true; + } + } + + + public void SubtractFlanges() + { + for (int i = 0; i < nodes.Length; i++) + { + if (nodes[i].isNonConnector) continue; + switch(nodes[i].mode) + { + case (FlangeDimensionMode.None): + break; + case (FlangeDimensionMode.Exact): + IgnoreFlange(i); + break; + case (FlangeDimensionMode.Partial): + PartialFlange(i); + break; + case (FlangeDimensionMode.Negate): + NegateFlange(i); + break; + + } + } + } + private void IgnoreFlange(int index) + { + if (index < 0 || index >= nodes.Length) return; + nodes[index].firstReference = null; + nodes[index].lastReference = null; + } + private void NegateFlange(int index) + { + if (index < 0 || index >= nodes.Length) return; + nodes[index].firstReference = null; + nodes[index].lastReference = null; + RemoveLastReference(index - 1); + RemoveFirstReference(index + 1); + } + private void PartialFlange(int index) + { + if (index < 0 || index >= nodes.Length) return; + else if (nodes[index].isStart || nodes[index].isEnd || NextToNonLinear(index)) IgnoreFlange(index); + else NegateFlange(index); + } + private int GetAdjacentElementIndex(int index, int direction, bool allowNonConnectors, bool allowFlanges) + { + if (direction == 0 || index < 0 || index >= nodes.Length) return -1; + bool passesFlangeFilter = (allowFlanges || (!allowFlanges && !nodes[index].isFlange)); + bool passesNonConnectorFilter = (allowNonConnectors || (!allowNonConnectors && !nodes[index].isNonConnector)); + if (passesFlangeFilter && passesNonConnectorFilter) return index; + return GetAdjacentElementIndex(index + direction, direction, allowNonConnectors, allowFlanges); + } + private bool NextToNonLinear(int index) + { + if (index < 0 || index >= nodes.Length) return false; + int previousIndex = GetAdjacentElementIndex(index - 1, -1, false, true); + int nextIndex = GetAdjacentElementIndex(index + 1, 1, false, true); + if (previousIndex >= 0 && !nodes[previousIndex].isLinear) return true; + if (nextIndex >= 0 && !nodes[nextIndex].isLinear) return true; + return false; + } + + private void RemoveLastReference(int index) + { + if (index < 0 || index >= nodes.Length) return; + if (nodes[index].isNonConnector) RemoveLastReference(index - 1); + nodes[index].lastReference = null; + } + private void RemoveFirstReference(int index) + { + if (index < 0 || index >= nodes.Length) return; + if (nodes[index].isNonConnector) RemoveFirstReference(index + 1); + nodes[index].firstReference = null; + } + public struct ReferenceNode + { + public BuiltInCategory builtInCategory; + public FlangeDimensionMode mode; + public bool isFlange => mode != FlangeDimensionMode.Default; + public XYZ origin; + public bool isStart; + public bool isEnd; + public bool isEdge => isStart || isEnd; + public int referenceCount => ((firstReference != null) ? 1 : 0) + ((lastReference != null) ? 1 : 0) + ((centerReference != null) ? 1 : 0); + public bool isLinear; + public bool adjacentNonLinear; + public bool isNonConnector; + public bool ignore; + public Reference firstReference; + public Reference centerReference; + public Reference lastReference; + public Connector firstConnector; + public Connector lastConnector; + } + } + + +} + diff --git a/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/DimensionSettingsWindow.xaml.cs b/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/DimensionSettingsWindow.xaml.cs deleted file mode 100644 index a890bba..0000000 --- a/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/DimensionSettingsWindow.xaml.cs +++ /dev/null @@ -1,193 +0,0 @@ -using Autodesk.Revit.DB; -using Autodesk.Revit.UI; -using CarsonsAddins.Properties; -using CarsonsAddins.Utils; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Markup; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using static CarsonsAddins.Utils.DimensioningUtils; - -namespace CarsonsAddins -{ - /// - /// Interaction logic for DimensionSettingsWindow.xaml - /// - public partial class DimensionSettingsWindow : Window, ISettingsUIComponent, INotifyPropertyChanged - { - public const string FolderName = "Dimensioning"; - public const bool IsWIP = false; - public event PropertyChangedEventHandler PropertyChanged; - private DimensionType[] dimensionTypes; - private GraphicsStyle[] graphicStyles; - public static DimensionStyles DimensionStylesSettings; - - - public DimensionSettingsWindow() - { - - InitializeComponent(); - } - - public void Init(UIDocument uidoc) - { - DimensionStylesSettings = new DimensionStyles(); - BuiltInCategory[] pipingCategories = new BuiltInCategory[] {BuiltInCategory.OST_PipeCurves, BuiltInCategory.OST_PipeFitting, BuiltInCategory.OST_PipeAccessory, BuiltInCategory.OST_MechanicalEquipment, BuiltInCategory.OST_PipeCurvesCenterLine, BuiltInCategory.OST_PipeFittingCenterLine, BuiltInCategory.OST_CenterLines}; - dimensionTypes = new FilteredElementCollector(uidoc.Document).WhereElementIsElementType().OfClass(typeof(DimensionType)).ToElements().Cast().Where(dt => DimensionStyleType.Linear.Equals(dt.StyleType)).ToArray(); - graphicStyles = new FilteredElementCollector(uidoc.Document).OfClass(typeof(GraphicsStyle)).Cast().Where(gs => pipingCategories.Contains((BuiltInCategory)gs.GraphicsStyleCategory.Id.IntegerValue) || ((gs.GraphicsStyleCategory.Parent != null) && pipingCategories.Contains((BuiltInCategory)gs.GraphicsStyleCategory.Parent.Id.IntegerValue))).ToArray(); - LoadFromDB(); - DimensionTypeSelector.Init(dimensionTypes, ref DimensionStylesSettings); - GraphicsStyleList.Init(graphicStyles, ref DimensionStylesSettings.centerlineStyles); - //DimensionPreviewControl.AddPreviewControlWithCustomView(uidoc.Document); - } - public PushButtonData RegisterButton(Assembly assembly) - { - return new PushButtonData("Dimension Pipeline Settings", "Dimension Pipeline Settings", assembly.Location, typeof(GenericCommands.ShowWindow).FullName) - { - AvailabilityClassName = typeof(Setup.Availablity.Availability_ProjectDocumentsOnly).FullName, - ToolTip = "Settings Window for the Dimension Pipeline Command" - }; - } - private void LoadFromDB() //requires that Load Dimension Types has been called first - { - DimensionStylesSettings = new DimensionStyles(); - - if (dimensionTypes == null || dimensionTypes.Length == 0) return; - if (string.IsNullOrWhiteSpace(MySettings.Default.DimensionStyles_Preferences)) return; - - try - { - DimensionStyleNames dimensionStyleNames = JsonConvert.DeserializeObject(MySettings.Default.DimensionStyles_Preferences); - - - foreach (DimensionType dimensionType in dimensionTypes) - { - if (dimensionType.Name == dimensionStyleNames.primaryDimensionTypeName) DimensionStylesSettings.primaryDimensionType = dimensionType; - if (dimensionType.Name == dimensionStyleNames.secondaryPipeDimensionTypeName) DimensionStylesSettings.secondaryPipeDimensionType = dimensionType; - if (dimensionType.Name == dimensionStyleNames.secondaryAccessoryDimensionTypeName) DimensionStylesSettings.secondaryAccessoryDimensionType = dimensionType; - if (dimensionType.Name == dimensionStyleNames.secondaryFittingDimensionTypeName) DimensionStylesSettings.secondaryFittingDimensionType = dimensionType; - if (dimensionType.Name == dimensionStyleNames.secondaryOtherDimensionTypeName) DimensionStylesSettings.secondaryOtherDimensionType = dimensionType; - if (DimensionStylesSettings.foundAllDimensionTypes) break; - } - if (dimensionStyleNames.centerlineStyleNames != null) - { - - foreach (GraphicsStyle graphicsStyle in graphicStyles) - { - if (dimensionStyleNames.centerlineStyleNames.Contains(graphicsStyle.Name)) DimensionStylesSettings.centerlineStyles.Add(graphicsStyle); - } - }; - - } - catch (Exception ex) - { - TaskDialog.Show("Error Loading Dimension Styles from DB", ex.Message); - } - - - } - - - private void SaveToDB() - { - if (DimensionStylesSettings == null) return; - DimensionStyleNames dimensionStyleNames = DimensionStylesSettings.GetDimensionStyleNames(GraphicsStyleList.SelectedGraphicStyleNames.ToArray()); - try - { - MySettings.Default.DimensionStyles_Preferences = JsonConvert.SerializeObject(dimensionStyleNames); - MySettings.Default.Save(); - } catch (Exception ex) - { - TaskDialog.Show("Error Saving Dimension Settings", ex.Message); - } - - } - - protected override void OnClosing(CancelEventArgs e) - { - Hide(); - SaveToDB(); - e.Cancel = true; - } - - protected void OnNotifyPropertyChanged([CallerMemberName] string memberName = "") - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); - } - } - - - public class DimensionStyles - { - public bool foundAllDimensionTypes => primaryDimensionType != null && secondaryPipeDimensionType != null && secondaryAccessoryDimensionType != null && secondaryFittingDimensionType != null && secondaryOtherDimensionType != null; - public DimensionType primaryDimensionType; - public DimensionType secondaryPipeDimensionType; - public DimensionType secondaryAccessoryDimensionType; - public DimensionType secondaryFittingDimensionType; - public DimensionType secondaryOtherDimensionType; - public List centerlineStyles = new List(); - public DimensionType GetSecondaryDimensionType(BuiltInCategory builtInCategory) - { - switch (builtInCategory) - { - case BuiltInCategory.OST_PipeCurves: return secondaryPipeDimensionType; - case BuiltInCategory.OST_PipeFitting: return secondaryFittingDimensionType; - case BuiltInCategory.OST_PipeAccessory: return secondaryAccessoryDimensionType; - default: return secondaryOtherDimensionType; - } - } - public DimensionStyleNames GetDimensionStyleNames() - { - return new DimensionStyleNames - { - primaryDimensionTypeName = primaryDimensionType?.Name ?? string.Empty, - secondaryPipeDimensionTypeName = secondaryPipeDimensionType?.Name ?? string.Empty, - secondaryAccessoryDimensionTypeName = secondaryAccessoryDimensionType?.Name ?? string.Empty, - secondaryFittingDimensionTypeName = secondaryFittingDimensionType?.Name ?? string.Empty, - secondaryOtherDimensionTypeName = secondaryOtherDimensionType?.Name ?? string.Empty, - centerlineStyleNames = centerlineStyles?.Select(style => style.Name).Distinct().ToArray() - }; - } - public DimensionStyleNames GetDimensionStyleNames(string[] graphicStyleNames) - { - return new DimensionStyleNames - { - primaryDimensionTypeName = primaryDimensionType?.Name ?? string.Empty, - secondaryPipeDimensionTypeName = secondaryPipeDimensionType?.Name ?? string.Empty, - secondaryAccessoryDimensionTypeName = secondaryAccessoryDimensionType?.Name ?? string.Empty, - secondaryFittingDimensionTypeName = secondaryFittingDimensionType?.Name ?? string.Empty, - secondaryOtherDimensionTypeName = secondaryOtherDimensionType?.Name ?? string.Empty, - centerlineStyleNames = graphicStyleNames - }; - } - - } - - public struct DimensionStyleNames - { - public string primaryDimensionTypeName; - public string secondaryPipeDimensionTypeName; - public string secondaryAccessoryDimensionTypeName; - public string secondaryFittingDimensionTypeName; - public string secondaryOtherDimensionTypeName; - public string[] centerlineStyleNames; - } - -} diff --git a/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/DimensionTypeSelectorControl.xaml.cs b/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/DimensionTypeSelectorControl.xaml.cs deleted file mode 100644 index 0a9f30c..0000000 --- a/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/DimensionTypeSelectorControl.xaml.cs +++ /dev/null @@ -1,114 +0,0 @@ -using Autodesk.Revit.DB; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using static CarsonsAddins.Utils.DimensioningUtils; - -namespace CarsonsAddins -{ - /// - /// Interaction logic for DimensionTypeSelectorControl.xaml - /// - public partial class DimensionTypeSelectorControl : UserControl, INotifyPropertyChanged - { - public event PropertyChangedEventHandler PropertyChanged; - - private DimensionStyles dimensionStyles = new DimensionStyles(); - - public DimensionType PrimaryDimensionType - { - get => dimensionStyles.primaryDimensionType; - set - { - if (value == null || value == dimensionStyles.primaryDimensionType) return; - dimensionStyles.primaryDimensionType = value; - OnNotifyPropertyChanged(); - } - } - public DimensionType SecondaryPipeDimensionType - { - get => dimensionStyles.secondaryPipeDimensionType; - set - { - if (value == null || value == dimensionStyles.secondaryPipeDimensionType) return; - dimensionStyles.secondaryPipeDimensionType = value; - OnNotifyPropertyChanged(); - } - } - public DimensionType SecondaryFittingDimensionType - { - get => dimensionStyles.secondaryFittingDimensionType; - set - { - if (value == null || value == dimensionStyles.secondaryFittingDimensionType) return; - dimensionStyles.secondaryFittingDimensionType = value; - OnNotifyPropertyChanged(); - } - } - public DimensionType SecondaryAccessoryDimensionType - { - get => dimensionStyles.secondaryAccessoryDimensionType; - set - { - if (value == null || value == dimensionStyles.secondaryAccessoryDimensionType) return; - dimensionStyles.secondaryAccessoryDimensionType = value; - OnNotifyPropertyChanged(); - } - } - public DimensionType SecondaryOtherDimensionType - { - get => dimensionStyles.secondaryOtherDimensionType; - set - { - if (value == null || value == dimensionStyles.secondaryOtherDimensionType) return; - dimensionStyles.secondaryOtherDimensionType = value; - OnNotifyPropertyChanged(); - } - } - - public ObservableCollection dimensionTypes = new ObservableCollection(); - public ObservableCollection DimensionTypes { get => dimensionTypes; set => dimensionTypes = value; } - - public DimensionTypeSelectorControl() - { - InitializeComponent(); - DataContext = this; - } - - public void Init(DimensionType[] dimensionTypes, ref DimensionStyles currentPreferences) - { - DimensionTypes = new ObservableCollection(dimensionTypes); - dimensionStyles = currentPreferences; - NotifyIntialized(); - } - - private void NotifyIntialized() - { - if (dimensionStyles == null) return; - OnNotifyPropertyChanged(nameof(PrimaryDimensionType)); - OnNotifyPropertyChanged(nameof(SecondaryPipeDimensionType)); - OnNotifyPropertyChanged(nameof(SecondaryFittingDimensionType)); - OnNotifyPropertyChanged(nameof(SecondaryAccessoryDimensionType)); - OnNotifyPropertyChanged(nameof(SecondaryOtherDimensionType)); - } - - protected void OnNotifyPropertyChanged([CallerMemberName] string memberName = "") - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); - } - } -} diff --git a/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/PreviewControlWrapper.xaml.cs b/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/PreviewControlWrapper.xaml.cs deleted file mode 100644 index f2c2323..0000000 --- a/CarsonsAddins/Dimensioning/DimensionSettings/ViewModels/PreviewControlWrapper.xaml.cs +++ /dev/null @@ -1,81 +0,0 @@ -using Autodesk.Revit.DB; -using Autodesk.Revit.UI; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; - - -namespace CarsonsAddins -{ - /// - /// Interaction logic for PreviewControlWrapper.xaml - /// - public partial class PreviewControlWrapper : UserControl - { - public PreviewControl previewControl; - /* - private Document previewDocument; - public Document PreviewDocument - { - get => previewDocument; - set => previewDocument = value; - } - private ElementId viewId = ElementId.InvalidElementId; - public ElementId ViewId - { - get => viewId; - set => viewId = value; - }*/ - - public PreviewControlWrapper() - { - InitializeComponent(); - //AddPreviewControl(previewDocument, ViewId); - } - public void AddPreviewControlWithCustomView(Document doc) - { - if (doc == null) return; - Transaction transaction = new Transaction(doc); - transaction.Start("Create Dimension View"); - try - { - Level level = Level.Create(doc, 0.0); - ElementId floorPlanId = doc.GetDefaultElementTypeId(ElementTypeGroup.ViewTypeFloorPlan); - if (level == null || floorPlanId == ElementId.InvalidElementId) - { - transaction.RollBack(); - return; - } - ViewPlan viewPlan = ViewPlan.Create(doc, floorPlanId, level.Id); - - previewControl = new PreviewControl(doc, viewPlan.Id) - { - IsEnabled = false - }; - - PreviewControlGrid.Children.Add(previewControl); - - - - transaction.Commit(); - } - catch(Exception ex) - { - transaction.RollBack(); - TaskDialog.Show("Error Creating Dimension View", ex.Message); - } - } - public void AddPreviewControl(Document doc, ElementId viewId) - { - if (doc == null || viewId == ElementId.InvalidElementId) return; - previewControl = new PreviewControl(doc, viewId); - PreviewControlGrid.Children.Add(previewControl); - previewControl.IsHitTestVisible = false; - - } - } -} diff --git a/CarsonsAddins/Dimensioning/DimensionSettings/Views/DimensionSettingsWindow.xaml b/CarsonsAddins/Dimensioning/DimensionSettings/Views/DimensionSettingsWindow.xaml deleted file mode 100644 index 4e0f908..0000000 --- a/CarsonsAddins/Dimensioning/DimensionSettings/Views/DimensionSettingsWindow.xaml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/CarsonsAddins/Dimensioning/DimensionSettings/Views/PreviewControlWrapper.xaml b/CarsonsAddins/Dimensioning/DimensionSettings/Views/PreviewControlWrapper.xaml deleted file mode 100644 index b1ba4aa..0000000 --- a/CarsonsAddins/Dimensioning/DimensionSettings/Views/PreviewControlWrapper.xaml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - diff --git a/CarsonsAddins/Deprecated/SimpleFilter/Models/SetDimensionTextEventHandler.cs b/CarsonsAddins/Dimensioning/DimensionText/Models/SetDimensionTextEventHandler.cs similarity index 92% rename from CarsonsAddins/Deprecated/SimpleFilter/Models/SetDimensionTextEventHandler.cs rename to CarsonsAddins/Dimensioning/DimensionText/Models/SetDimensionTextEventHandler.cs index a537faa..9f18119 100644 --- a/CarsonsAddins/Deprecated/SimpleFilter/Models/SetDimensionTextEventHandler.cs +++ b/CarsonsAddins/Dimensioning/DimensionText/Models/SetDimensionTextEventHandler.cs @@ -12,10 +12,10 @@ namespace CarsonsAddins public class SetDimensionsTextEventHandler : IExternalEventHandler { private List<(Dimension, DimensionSegment)> dimensionsAndSegments = new List<(Dimension, DimensionSegment)>(); - - private string above, below, valueOverride, prefix, suffix; +#nullable enable + private string? above, below, valueOverride, prefix, suffix; public void Inject(List<(Dimension, DimensionSegment)> dimensionsAndSegments) => this.dimensionsAndSegments = dimensionsAndSegments; - public void Inject(string above = null, string below = null, string valueOverride = null, string prefix = null, string suffix = null) + public void Inject(string above = "", string below = "", string valueOverride = "", string prefix = "", string suffix = "") { this.above = above; this.below = below; diff --git a/CarsonsAddins/Pipeline/Models/PipingElementReferenceOrderedList.cs b/CarsonsAddins/Pipeline/Models/PipingElementReferenceOrderedList.cs deleted file mode 100644 index 22d1051..0000000 --- a/CarsonsAddins/Pipeline/Models/PipingElementReferenceOrderedList.cs +++ /dev/null @@ -1,182 +0,0 @@ -using Autodesk.Revit.DB; -using CarsonsAddins.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace CarsonsAddins.Pipeline.Models -{ - class PipingElementReferenceOrderedList - { - public enum FlangeDimensionMode { None, Ignore, Partial, Negate } - public Element[] orderedElements; - public ReferenceNode[] nodes; - - public PipingElementReferenceOrderedList(ElementId[] validStyleIds, View activeView, Element[] orderedElements) - { - this.orderedElements = orderedElements; - nodes = new ReferenceNode[orderedElements.Length]; - PopulateNodes(validStyleIds, activeView); - } - - private void PopulateNodes(ElementId[] validStyleIds, View activeView) - { - Plane plane = activeView.SketchPlane.GetPlane(); - nodes[0] = new ReferenceNode - { - builtInCategory = (BuiltInCategory)orderedElements[0].Category.Id.IntegerValue, - mode = GetMode(orderedElements[0]), - origin = GeometryUtils.GetOrigin(orderedElements[0].Location), - isStart = true, - isEnd = false, - adjacentNonLinear = false, - isLinear = ConnectionUtils.IsLinearElement(orderedElements[0]), - centerReference = (!ElementCheckUtils.IsPipeFlange(orderedElements[0])) ? DimensioningUtils.GetEndReference(activeView, validStyleIds, orderedElements[0]) : null - }; - nodes[0].adjacentNonLinear = nodes[0].isLinear; - for (int i = 1; i < orderedElements.Length; i++) - { - CreateReferenceNode(validStyleIds, activeView, plane, i); - } - SetAdjacentNonLinear(); - } - private void CreateReferenceNode(ElementId[] validStyleIds, View activeView, Plane plane, int index) - { - Element element = orderedElements[index]; - - (Connector, Connector) connection = ConnectionUtils.TryGetConnection(orderedElements[index - 1], element); - Reference currentFirstReference = GeometryUtils.GetPseudoReferenceOfConnector(GeometryUtils.GetGeometryOptions(), plane, connection.Item2) - ?? GeometryUtils.GetPseudoReferenceOfConnector(GeometryUtils.GetGeometryOptions(activeView), plane, connection.Item2); - - nodes[index - 1].lastReference = GeometryUtils.GetPseudoReferenceOfConnector(GeometryUtils.GetGeometryOptions(), plane, connection.Item1) - ?? GeometryUtils.GetPseudoReferenceOfConnector(GeometryUtils.GetGeometryOptions(activeView), plane, connection.Item1) ?? currentFirstReference; - bool isLinear = ConnectionUtils.IsLinearElement(element); - bool isEnd = index == orderedElements.Length - 1; - bool isFlange = ElementCheckUtils.IsPipeFlange(element); - nodes[index] = new ReferenceNode - { - builtInCategory = (BuiltInCategory)element.Category.Id.IntegerValue, - mode = GetMode(element), - origin = GeometryUtils.GetOrigin(element.Location), - isStart = false, - isEnd = isEnd, - isLinear = isLinear, - adjacentNonLinear = false, - centerReference = isFlange ? null : (isEnd) ? DimensioningUtils.GetEndReference(activeView, validStyleIds, element) : (!isLinear) ? DimensioningUtils.GetCenterReference(validStyleIds, element) : null, - firstReference = currentFirstReference ?? nodes[index - 1].lastReference, - }; - } - private void SetAdjacentNonLinear() - { - for (int i = 0; i < nodes.Length; i++) - { - if (nodes[i].isLinear) continue; - nodes[i].adjacentNonLinear = true; - if (i > 0) nodes[i - 1].adjacentNonLinear = true; - if (i < nodes.Length - 1) nodes[i + 1].adjacentNonLinear = true; - } - } - - - public void SubtractFlanges() - { - for (int i = 0; i < nodes.Length; i++) - { - if (nodes[i].isNonConnector) continue; - switch(nodes[i].mode) - { - case (FlangeDimensionMode.None): - break; - case (FlangeDimensionMode.Ignore): - IgnoreFlange(i); - break; - case (FlangeDimensionMode.Partial): - PartialFlange(i); - break; - case (FlangeDimensionMode.Negate): - NegateFlange(i); - break; - - } - } - } - private FlangeDimensionMode GetMode(Element element) - { - if (!ElementCheckUtils.IsPipeFlange(element)) return FlangeDimensionMode.None; - - string familyName = (element as FamilyInstance).Symbol.FamilyName; - if (familyName.Contains("FLG")) return FlangeDimensionMode.Ignore; - if (familyName.Contains("MJ") || familyName.Contains("PO")) return FlangeDimensionMode.Negate; - return FlangeDimensionMode.Partial; - } - private void IgnoreFlange(int index) - { - if (index < 0 && index >= nodes.Length) return; - nodes[index].firstReference = null; - nodes[index].lastReference = null; - } - private void NegateFlange(int index) - { - if (index < 0 && index >= nodes.Length) return; - nodes[index].firstReference = null; - nodes[index].lastReference = null; - RemoveLastReference(index - 1); - RemoveFirstReference(index + 1); - } - private void PartialFlange(int index) - { - if (index < 0 && index >= nodes.Length) return; - if (nodes[index].isStart || nodes[index].isEnd || NextToNonLinear(index)) IgnoreFlange(index); - else NegateFlange(index); - } - private bool NextToNonLinear(int index) => IsPreviousNonLinear(index) || IsNextNonLinear(index); - private bool IsNextNonLinear(int index) - { - if (index < 0 || index >= nodes.Length - 1) return false; - if (nodes[index + 1].isNonConnector) return IsNextNonLinear(index + 1); - return !nodes[index + 1].isLinear; - } - private bool IsPreviousNonLinear(int index) - { - if (index < 1 || index > nodes.Length - 1) return false; - if (nodes[index - 1].isNonConnector) return IsNextNonLinear(index - 1); - return !nodes[index - 1].isLinear; - } - private void RemoveLastReference(int index) - { - if (index < 0 && index >= nodes.Length) return; - if (nodes[index].isNonConnector) RemoveLastReference(index - 1); - nodes[index].lastReference = null; - } - private void RemoveFirstReference(int index) - { - if (index < 0 && index >= nodes.Length) return; - if (nodes[index].isNonConnector) RemoveFirstReference(index + 1); - nodes[index].firstReference = null; - } - public struct ReferenceNode - { - //public ElementCheckUtils.PipingCategory pipingCategory; - public BuiltInCategory builtInCategory; - public FlangeDimensionMode mode; - public XYZ origin; - public bool isStart; - public bool isEnd; - public bool isEdge => isStart || isEnd; - public int referenceCount => ((firstReference != null) ? 1 : 0) + ((lastReference != null) ? 1 : 0) + ((centerReference != null) ? 1 : 0); - public bool isLinear; - public bool adjacentNonLinear; - public bool isNonConnector; - public Reference firstReference; - public Reference centerReference; - public Reference lastReference; - - } - } - - -} - diff --git a/CarsonsAddins/Properties/MySettings.Designer.cs b/CarsonsAddins/Properties/MySettings.Designer.cs index 12536b2..9ebe463 100644 --- a/CarsonsAddins/Properties/MySettings.Designer.cs +++ b/CarsonsAddins/Properties/MySettings.Designer.cs @@ -12,7 +12,7 @@ namespace CarsonsAddins.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] internal sealed partial class MySettings : global::System.Configuration.ApplicationSettingsBase { private static MySettings defaultInstance = ((MySettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new MySettings()))); @@ -37,19 +37,7 @@ public string PEP_Preferences { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string LC_Preferences { - get { - return ((string)(this["LC_Preferences"])); - } - set { - this["LC_Preferences"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] + [global::System.Configuration.DefaultSettingValueAttribute(@"{""PipeEndPrepBCWindow"":true,""PipeEndPrepWindow"":false,""DebugSettingsCommand"":false,""DimensionTextWindow"":true,""DimensionPipeLineCommand"":true,""SelectPipeLineCommand"":true,""DebugGeometryCommand"":false,""FilterPipingElementsCommand"":true,""GetTotalPipeLengthCommand"":true,""ParameterManagerDockablePane"":true,""SelectAllElementsOfSystemCommand"":true,""SmartFlipCommand"":true}")] public string ComponentState_Preferences { get { return ((string)(this["ComponentState_Preferences"])); @@ -61,7 +49,42 @@ public string ComponentState_Preferences { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] + [global::System.Configuration.DefaultSettingValueAttribute("{\"primaryDimensionTypeName\":\"C & B\",\"secondaryPipeDimensionTypeName\":\"C & B PIPE " + + "w/dot\",\"secondaryAccessoryDimensionTypeName\":\"C & B FITTING w/dot\",\"secondaryFit" + + "tingDimensionTypeName\":\"C & B FITTING w/dot\",\"secondaryOtherDimensionTypeName\":\"" + + "C & B FITTING w/dot\",\"graphicsStyleNames\":[\"\",\"Pipes\",\"Pipe Fittings" + + "\",\"zLines\"],\"flangeModeItems\":[{\"elementId\":7465461,\"Name\":\"DI FLG DBL\",\"Mode\":2" + + "},{\"elementId\":7151319,\"Name\":\"DI FCA\",\"Mode\":2},{\"elementId\":4634124,\"Name\":\"Co" + + "upling - Generic\",\"Mode\":0},{\"elementId\":7047513,\"Name\":\"DI CMJ LONG SLEEVE C153" + + "\",\"Mode\":4},{\"elementId\":7230174,\"Name\":\"CS WELD GAP MP\",\"Mode\":0},{\"elementId\":" + + "7230980,\"Name\":\"CS WELD GAP\",\"Mode\":0},{\"elementId\":7316050,\"Name\":\"DI FLG DBL f" + + "or fillers\",\"Mode\":2},{\"elementId\":7316874,\"Name\":\"DI FLG DBL MP\",\"Mode\":2},{\"el" + + "ementId\":7317685,\"Name\":\"DI FLG DBL UN LINKED\",\"Mode\":2},{\"elementId\":7320961,\"N" + + "ame\":\"DI FLG SINGLE MP\",\"Mode\":2},{\"elementId\":7322565,\"Name\":\"DI FLG SINGLE\",\"M" + + "ode\":2},{\"elementId\":7303217,\"Name\":\"DI FLG GASKET DO NOT SCHEDULE\",\"Mode\":2},{\"" + + "elementId\":7315853,\"Name\":\"DI FLG GASKET\",\"Mode\":2},{\"elementId\":7319339,\"Name\":" + + "\"DI FLG DBL WITH STUDS\",\"Mode\":2},{\"elementId\":7237273,\"Name\":\"SS WELD GAP\",\"Mod" + + "e\":0},{\"elementId\":7252261,\"Name\":\"SS WELD GAP MP\",\"Mode\":0},{\"elementId\":458413" + + "5,\"Name\":\"Non-Connector\",\"Mode\":0},{\"elementId\":7030191,\"Name\":\"Victaulic-Groove" + + "d Coupling OGS-AGS_Face\",\"Mode\":2},{\"elementId\":7036679,\"Name\":\"DI HP LOK FITTIN" + + "G BELL\",\"Mode\":3},{\"elementId\":7039212,\"Name\":\"DI MJ BELL\",\"Mode\":4},{\"elementId" + + "\":7040062,\"Name\":\"DI PO BELL\",\"Mode\":4},{\"elementId\":7062627,\"Name\":\"Victaulic-A" + + "WWA-Grooved Coupling\",\"Mode\":2},{\"elementId\":7063762,\"Name\":\"DI MJ LONG SLEEVE C" + + "110\",\"Mode\":4},{\"elementId\":7105299,\"Name\":\"DI TRFLEX SLEEVE DOMESTIC\",\"Mode\":3}" + + ",{\"elementId\":7123588,\"Name\":\"DI TRFLEX SLEEVE IMPORT\",\"Mode\":3},{\"elementId\":72" + + "56569,\"Name\":\"DI TR FLEX FITTING BELL MP\",\"Mode\":3},{\"elementId\":7273137,\"Name\":" + + "\"DI HP LOK FITTING BELL MP\",\"Mode\":3},{\"elementId\":7275670,\"Name\":\"DI MJ BELL MP" + + "\",\"Mode\":4},{\"elementId\":7276520,\"Name\":\"DI PO BELL MP WITH FIELD LOK GASKET\",\"M" + + "ode\":2},{\"elementId\":7279034,\"Name\":\"DI PO BELL MP\",\"Mode\":4},{\"elementId\":72844" + + "98,\"Name\":\"Victaulic-AWWA-Coupling Style 31_MP\",\"Mode\":2},{\"elementId\":7286104,\"" + + "Name\":\"DI VIC STYLE 31 CPLG_MP\",\"Mode\":2},{\"elementId\":7289129,\"Name\":\"DI VIC ST" + + "YLE 31 CPLG\",\"Mode\":2},{\"elementId\":7292332,\"Name\":\"DI FLG GASKET w- STUDS\",\"Mod" + + "e\":2},{\"elementId\":7306393,\"Name\":\"FLG PACK w TWO GASKETS & EX LONG STUDS w DBL " + + "NUTS EA\",\"Mode\":2},{\"elementId\":7309215,\"Name\":\"DI HDSS BELL\",\"Mode\":3},{\"elemen" + + "tId\":7311748,\"Name\":\"DI HDSS BELL MP\",\"Mode\":3},{\"elementId\":7314281,\"Name\":\"DI " + + "FLG x VIC FLG STYLE 341\",\"Mode\":2},{\"elementId\":7321771,\"Name\":\"DI FLG SINGLE wo" + + " GASKET\",\"Mode\":2},{\"elementId\":7466331,\"Name\":\"DI TR FLEX FITTING BELL\",\"Mode\":" + + "3}]}")] public string DimensionStyles_Preferences { get { return ((string)(this["DimensionStyles_Preferences"])); diff --git a/CarsonsAddins/Properties/MySettings.settings b/CarsonsAddins/Properties/MySettings.settings index b524813..687ed96 100644 --- a/CarsonsAddins/Properties/MySettings.settings +++ b/CarsonsAddins/Properties/MySettings.settings @@ -5,14 +5,11 @@ - - - - + {"PipeEndPrepBCWindow":true,"PipeEndPrepWindow":false,"DebugSettingsCommand":false,"DimensionTextWindow":true,"DimensionPipeLineCommand":true,"SelectPipeLineCommand":true,"DebugGeometryCommand":false,"FilterPipingElementsCommand":true,"GetTotalPipeLengthCommand":true,"ParameterManagerDockablePane":true,"SelectAllElementsOfSystemCommand":true,"SmartFlipCommand":true} - + {"primaryDimensionTypeName":"C & B","secondaryPipeDimensionTypeName":"C & B PIPE w/dot","secondaryAccessoryDimensionTypeName":"C & B FITTING w/dot","secondaryFittingDimensionTypeName":"C & B FITTING w/dot","secondaryOtherDimensionTypeName":"C & B FITTING w/dot","graphicsStyleNames":["<Centerline>","Pipes","Pipe Fittings","zLines"],"flangeModeItems":[{"elementId":7465461,"Name":"DI FLG DBL","Mode":2},{"elementId":7151319,"Name":"DI FCA","Mode":2},{"elementId":4634124,"Name":"Coupling - Generic","Mode":0},{"elementId":7047513,"Name":"DI CMJ LONG SLEEVE C153","Mode":4},{"elementId":7230174,"Name":"CS WELD GAP MP","Mode":0},{"elementId":7230980,"Name":"CS WELD GAP","Mode":0},{"elementId":7316050,"Name":"DI FLG DBL for fillers","Mode":2},{"elementId":7316874,"Name":"DI FLG DBL MP","Mode":2},{"elementId":7317685,"Name":"DI FLG DBL UN LINKED","Mode":2},{"elementId":7320961,"Name":"DI FLG SINGLE MP","Mode":2},{"elementId":7322565,"Name":"DI FLG SINGLE","Mode":2},{"elementId":7303217,"Name":"DI FLG GASKET DO NOT SCHEDULE","Mode":2},{"elementId":7315853,"Name":"DI FLG GASKET","Mode":2},{"elementId":7319339,"Name":"DI FLG DBL WITH STUDS","Mode":2},{"elementId":7237273,"Name":"SS WELD GAP","Mode":0},{"elementId":7252261,"Name":"SS WELD GAP MP","Mode":0},{"elementId":4584135,"Name":"Non-Connector","Mode":0},{"elementId":7030191,"Name":"Victaulic-Grooved Coupling OGS-AGS_Face","Mode":2},{"elementId":7036679,"Name":"DI HP LOK FITTING BELL","Mode":3},{"elementId":7039212,"Name":"DI MJ BELL","Mode":4},{"elementId":7040062,"Name":"DI PO BELL","Mode":4},{"elementId":7062627,"Name":"Victaulic-AWWA-Grooved Coupling","Mode":2},{"elementId":7063762,"Name":"DI MJ LONG SLEEVE C110","Mode":4},{"elementId":7105299,"Name":"DI TRFLEX SLEEVE DOMESTIC","Mode":3},{"elementId":7123588,"Name":"DI TRFLEX SLEEVE IMPORT","Mode":3},{"elementId":7256569,"Name":"DI TR FLEX FITTING BELL MP","Mode":3},{"elementId":7273137,"Name":"DI HP LOK FITTING BELL MP","Mode":3},{"elementId":7275670,"Name":"DI MJ BELL MP","Mode":4},{"elementId":7276520,"Name":"DI PO BELL MP WITH FIELD LOK GASKET","Mode":2},{"elementId":7279034,"Name":"DI PO BELL MP","Mode":4},{"elementId":7284498,"Name":"Victaulic-AWWA-Coupling Style 31_MP","Mode":2},{"elementId":7286104,"Name":"DI VIC STYLE 31 CPLG_MP","Mode":2},{"elementId":7289129,"Name":"DI VIC STYLE 31 CPLG","Mode":2},{"elementId":7292332,"Name":"DI FLG GASKET w- STUDS","Mode":2},{"elementId":7306393,"Name":"FLG PACK w TWO GASKETS & EX LONG STUDS w DBL NUTS EA","Mode":2},{"elementId":7309215,"Name":"DI HDSS BELL","Mode":3},{"elementId":7311748,"Name":"DI HDSS BELL MP","Mode":3},{"elementId":7314281,"Name":"DI FLG x VIC FLG STYLE 341","Mode":2},{"elementId":7321771,"Name":"DI FLG SINGLE wo GASKET","Mode":2},{"elementId":7466331,"Name":"DI TR FLEX FITTING BELL","Mode":3}]} \ No newline at end of file diff --git a/CarsonsAddins/Setup/ComponentState.cs b/CarsonsAddins/Settings/ComponentStates/Models/ComponentState.cs similarity index 100% rename from CarsonsAddins/Setup/ComponentState.cs rename to CarsonsAddins/Settings/ComponentStates/Models/ComponentState.cs diff --git a/CarsonsAddins/Settings/Models/MyApplicationSettings.cs b/CarsonsAddins/Settings/ComponentStates/Models/ComponentStatePreferences.cs similarity index 97% rename from CarsonsAddins/Settings/Models/MyApplicationSettings.cs rename to CarsonsAddins/Settings/ComponentStates/Models/ComponentStatePreferences.cs index bdf5ea0..5b18db9 100644 --- a/CarsonsAddins/Settings/Models/MyApplicationSettings.cs +++ b/CarsonsAddins/Settings/ComponentStates/Models/ComponentStatePreferences.cs @@ -9,14 +9,14 @@ using System.Text; using System.Threading.Tasks; -namespace CarsonsAddins +namespace CarsonsAddins.Settings.ComponentStates.Models { /// /// Stores the Settings state, either by loading it in from the user's preferences or setting the state to their default values. Manipulates the SettingsState of the Addin. /// - public class MyApplicationSettings + public class ComponentStatePreferences { - public static MyApplicationSettings Instance; + public static ComponentStatePreferences Instance; public ObservableCollection settingsState = new ObservableCollection(); /// @@ -45,7 +45,7 @@ private Dictionary GetNameIsEnabledDictionary() /// /// Saves the current settingsState as a JSON within the user preferences in Revit. /// - public void SaveToDB() + public void Save() { if (settingsState == null || settingsState.Count == 0) return; MySettings.Default.ComponentState_Preferences = JsonConvert.SerializeObject(GetNameIsEnabledDictionary()); diff --git a/CarsonsAddins/Settings/ComponentStates/ViewModels/SettingsPluginViewModel.cs b/CarsonsAddins/Settings/ComponentStates/ViewModels/SettingsPluginViewModel.cs new file mode 100644 index 0000000..ae0be9b --- /dev/null +++ b/CarsonsAddins/Settings/ComponentStates/ViewModels/SettingsPluginViewModel.cs @@ -0,0 +1,18 @@ +using CarsonsAddins.Settings.ComponentStates.Models; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CarsonsAddins.Settings.ComponentStates.ViewModels +{ + public class SettingsPluginViewModel + { + public ObservableCollection componentStates => ComponentStatePreferences.Instance.settingsState; + public void Save() => ComponentStatePreferences.Instance.Save(); + public void LoadFromDB() => ComponentStatePreferences.Instance.LoadFromDB(Assembly.GetExecutingAssembly()); + } +} diff --git a/CarsonsAddins/Settings/Views/MyApplicationSettingsWindow.xaml b/CarsonsAddins/Settings/ComponentStates/Views/SettingsPluginControl.xaml similarity index 85% rename from CarsonsAddins/Settings/Views/MyApplicationSettingsWindow.xaml rename to CarsonsAddins/Settings/ComponentStates/Views/SettingsPluginControl.xaml index fe34dc6..8da1d17 100644 --- a/CarsonsAddins/Settings/Views/MyApplicationSettingsWindow.xaml +++ b/CarsonsAddins/Settings/ComponentStates/Views/SettingsPluginControl.xaml @@ -1,11 +1,11 @@ - + d:Background="White" d:DesignHeight="450" d:DesignWidth="800"> @@ -16,7 +16,6 @@ - @@ -24,6 +23,6 @@