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

Sketch Grids #127

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions Grids/SketchGrids/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

bin/
obj/
*.glb
output.json
input.json
.vs/
server/
test/Generated/
21 changes: 21 additions & 0 deletions Grids/SketchGrids/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


# Sketch Grids

Generate grids automatically from conceptual masses or sketch grid lines.

|Input Name|Type|Description|
|---|---|---|
|Offset Distance From Conceptual Mass|number|The default grid offset from the conceptual mass.|
|Add Skeleton Grids|boolean|Add grids along conceptual mass skeletons.|


<br>

|Output Name|Type|Description|
|---|---|---|


<br>

## Additional Information
62 changes: 62 additions & 0 deletions Grids/SketchGrids/SketchGrids.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SketchGrids", "src\SketchGrids.csproj", "{EAA286E4-3EE3-4017-945A-18189AE2FDDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SketchGrids.Dependencies", "dependencies\SketchGrids.Dependencies.csproj", "{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SketchGrids.Tests", "test\SketchGrids.Tests.csproj", "{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Debug|x64.ActiveCfg = Debug|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Debug|x64.Build.0 = Debug|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Debug|x86.ActiveCfg = Debug|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Debug|x86.Build.0 = Debug|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Release|Any CPU.Build.0 = Release|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Release|x64.ActiveCfg = Release|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Release|x64.Build.0 = Release|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Release|x86.ActiveCfg = Release|Any CPU
{EAA286E4-3EE3-4017-945A-18189AE2FDDC}.Release|x86.Build.0 = Release|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Debug|x64.ActiveCfg = Debug|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Debug|x64.Build.0 = Debug|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Debug|x86.ActiveCfg = Debug|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Debug|x86.Build.0 = Debug|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Release|Any CPU.Build.0 = Release|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Release|x64.ActiveCfg = Release|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Release|x64.Build.0 = Release|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Release|x86.ActiveCfg = Release|Any CPU
{C3DC1E0D-A438-4CC9-9DBB-61B81DD1929F}.Release|x86.Build.0 = Release|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Debug|x64.ActiveCfg = Debug|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Debug|x64.Build.0 = Debug|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Debug|x86.ActiveCfg = Debug|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Debug|x86.Build.0 = Debug|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Release|Any CPU.Build.0 = Release|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Release|x64.ActiveCfg = Release|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Release|x64.Build.0 = Release|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Release|x86.ActiveCfg = Release|Any CPU
{6B5FECA2-A2AB-4D74-B89A-A37E33408D91}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
69 changes: 69 additions & 0 deletions Grids/SketchGrids/dependencies/ConceptualMass.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//----------------------
// <auto-generated>
// Generated using the NJsonSchema v10.1.21.0 (Newtonsoft.Json v13.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------
using Elements;
using Elements.GeoJSON;
using Elements.Geometry;
using Elements.Geometry.Solids;
using Elements.Spatial;
using Elements.Validators;
using Elements.Serialization.JSON;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using Line = Elements.Geometry.Line;
using Polygon = Elements.Geometry.Polygon;

namespace Elements
{
#pragma warning disable // Disable all warnings

/// <summary>Represents an early stage building massing volume. Its boundary typically represents the nominal edge of slab, and may be articulated further by subsequent functions.</summary>
[JsonConverter(typeof(Elements.Serialization.JSON.JsonInheritanceConverter), "discriminator")]
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")]
public partial class ConceptualMass : Envelope
{
[JsonConstructor]
public ConceptualMass(IList<Line> @skeleton, string @primaryUseCategory, System.Guid? @building, IList<System.Guid> @levelIds, Transform @localCoordinateSystem, Profile @profile, double @elevation, double @height, Vector3 @direction, double @rotation, IList<double> @floorToFloorHeights, Transform @transform, Material @material, Representation @representation, bool @isElementDefinition, System.Guid @id, string @name)
: base(profile, elevation, height, direction, rotation, floorToFloorHeights, transform, material, representation, isElementDefinition, id, name)
{
this.Skeleton = @skeleton;
this.PrimaryUseCategory = @primaryUseCategory;
this.Building = @building;
this.LevelIds = @levelIds;
this.LocalCoordinateSystem = @localCoordinateSystem;
}


// Empty constructor
public ConceptualMass()
: base()
{
}

/// <summary>A collection of lines which indicate a "centerline" of the mass.</summary>
[JsonProperty("Skeleton", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public IList<Line> Skeleton { get; set; }

/// <summary>The primary programmatic use for this mass, e.g. Residential, Office, Parking, Retail. Some levels or spaces within the mass may have other uses.</summary>
[JsonProperty("Primary Use Category", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string PrimaryUseCategory { get; set; }

/// <summary>The building this mass belongs to, if any.</summary>
[JsonProperty("Building", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Guid? Building { get; set; }

/// <summary>The ids of the levels this conceptual mass contains</summary>
[JsonProperty("Level Ids", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public IList<System.Guid> LevelIds { get; set; }

/// <summary>A transform representing the local coordinate system for this mass</summary>
[JsonProperty("Local Coordinate System", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public Transform LocalCoordinateSystem { get; set; }


}
}
74 changes: 74 additions & 0 deletions Grids/SketchGrids/dependencies/Envelope.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//----------------------
// <auto-generated>
// Generated using the NJsonSchema v10.1.21.0 (Newtonsoft.Json v13.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------
using Elements;
using Elements.GeoJSON;
using Elements.Geometry;
using Elements.Geometry.Solids;
using Elements.Spatial;
using Elements.Validators;
using Elements.Serialization.JSON;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using Line = Elements.Geometry.Line;
using Polygon = Elements.Geometry.Polygon;

namespace Elements
{
#pragma warning disable // Disable all warnings

/// <summary>Represents one part of a building enclosure.</summary>
[JsonConverter(typeof(Elements.Serialization.JSON.JsonInheritanceConverter), "discriminator")]
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")]
public partial class Envelope : GeometricElement
{
[JsonConstructor]
public Envelope(Profile @profile, double @elevation, double @height, Vector3 @direction, double @rotation, IList<double> @floorToFloorHeights, Transform @transform = null, Material @material = null, Representation @representation = null, bool @isElementDefinition = false, System.Guid @id = default, string @name = null)
: base(transform, material, representation, isElementDefinition, id, name)
{
this.Profile = @profile;
this.Elevation = @elevation;
this.Height = @height;
this.Direction = @direction;
this.Rotation = @rotation;
this.FloorToFloorHeights = @floorToFloorHeights;
}


// Empty constructor
public Envelope()
: base()
{
}

/// <summary>The profile to extrude.</summary>
[JsonProperty("Profile", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public Profile Profile { get; set; }

/// <summary>The elevation of the envelope.</summary>
[JsonProperty("Elevation", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double Elevation { get; set; }

/// <summary>The height of the envelope.</summary>
[JsonProperty("Height", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double Height { get; set; }

/// <summary>The direction in which to extrude.</summary>
[JsonProperty("Direction", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public Vector3 Direction { get; set; }

/// <summary>The rotation of the envelope, in degrees.</summary>
[JsonProperty("Rotation", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double Rotation { get; set; }

/// <summary>An optional list of floor-to-floor heights for this envelope. If provided, levels can be generated from these floor-to-floor heights.</summary>
[JsonProperty("Floor To Floor Heights", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public IList<double> FloorToFloorHeights { get; set; }


}
}
153 changes: 153 additions & 0 deletions Grids/SketchGrids/dependencies/GridLinesOverride.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using Elements;
using System.Collections.Generic;
using System;
using System.Linq;

namespace SketchGrids
{
/// <summary>
/// Override metadata for GridLinesOverride
/// </summary>
public partial class GridLinesOverride : IOverride
{
public static string Name = "Grid Lines";
public static string Dependency = null;
public static string Context = "[*discriminator=Elements.GridLine]";
public static string Paradigm = "Edit";

/// <summary>
/// Get the override name for this override.
/// </summary>
public string GetName() {
return Name;
}

public object GetIdentity() {

return Identity;
}

}
public static class GridLinesOverrideExtensions
{
/// <summary>
/// Apply Grid Lines edit overrides to a collection of existing elements
/// </summary>
/// <param name="overrideData">The Grid Lines Overrides to apply</param>
/// <param name="existingElements">A collection of existing elements to which to apply the overrides.</param>
/// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param>
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param>
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam>
/// <returns>A collection of elements, including unmodified and modified elements from the supplied collection.</returns>
public static List<T> Apply<T>(
this IList<GridLinesOverride> overrideData,
IEnumerable<T> existingElements,
Func<T, GridLinesIdentity, bool> identityMatch,
Func<T, GridLinesOverride, T> modifyElement) where T : Element
{
var resultElements = new List<T>(existingElements);
if (overrideData != null)
{
foreach (var overrideValue in overrideData)
{
// Assuming there will only be one match per identity, find the first element that matches.
var matchingElement = existingElements.FirstOrDefault(e => identityMatch(e, overrideValue.Identity));
// if we found a match,
if (matchingElement != null)
{
// remove the old matching element
resultElements.Remove(matchingElement);
// apply the modification function to it
var modifiedElement = modifyElement(matchingElement, overrideValue);
// set the identity
Identity.AddOverrideIdentity(modifiedElement, overrideValue);
//and re-add it to the collection
resultElements.Add(modifiedElement);
}
}
}
return resultElements;
}

/// <summary>
/// Apply Grid Lines edit overrides to a collection of existing elements
/// </summary>
/// <param name="existingElements">A collection of existing elements to which to apply the overrides.</param>
/// <param name="overrideData">The Grid Lines Overrides to apply — typically `input.Overrides.GridLines`</param>
/// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param>
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param>
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam>
/// <returns>A collection of elements, including unmodified and modified elements from the supplied collection.</returns>
public static void ApplyOverrides<T>(
this List<T> existingElements,
IList<GridLinesOverride> overrideData,
Func<T, GridLinesIdentity, bool> identityMatch,
Func<T, GridLinesOverride, T> modifyElement
) where T : Element
{
var updatedElements = overrideData.Apply(existingElements, identityMatch, modifyElement);
existingElements.Clear();
existingElements.AddRange(updatedElements);
}

/// <summary>
/// Create elements from add/removeoverrides, and apply any edits.
/// </summary>
/// <param name="edits">The collection of edit overrides (Overrides.GridLines)</param>
/// <param name="additions">The collection of add overrides (Overrides.Additions.GridLines)</param>
/// <param name="removals">The collection of remove overrides (Overrides.Removals.GridLines)</param> /// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param>
/// <param name="createElement">A function to create a new element, returning the created element.</param>
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param>
/// <param name="existingElements">An optional collection of existing elements to which to apply any edit overrides, or remove if remove overrides are found.</param>
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam>
/// <returns>A collection of elements, including new, unmodified, and modified elements from the supplied collection.</returns>
public static List<T> CreateElements<T>(
this IList<GridLinesOverride> edits,
IList<GridLinesOverrideAddition> additions,
IList<GridLinesOverrideRemoval> removals, Func<GridLinesOverrideAddition, T> createElement,
Func<T, GridLinesIdentity, bool> identityMatch,
Func<T, GridLinesOverride, T> modifyElement,
IEnumerable<T> existingElements = null
) where T : Element
{
List<T> resultElements = existingElements == null ? new List<T>() : new List<T>(existingElements);
if (removals != null)
{
foreach (var removedElement in removals)
{
var elementToRemove = resultElements.FirstOrDefault(e => identityMatch(e, removedElement.Identity));
if (elementToRemove != null)
{
resultElements.Remove(elementToRemove);
}
}
} if (additions != null)
{
foreach (var addedElement in additions)
{
var elementToAdd = createElement(addedElement);
resultElements.Add(elementToAdd);
Identity.AddOverrideIdentity(elementToAdd, addedElement);
}
}
if (edits != null)
{
foreach (var editedElement in edits)
{
var elementToEdit = resultElements.FirstOrDefault(e => identityMatch(e, editedElement.Identity));
if (elementToEdit != null)
{
resultElements.Remove(elementToEdit);
var newElement = modifyElement(elementToEdit, editedElement);
resultElements.Add(newElement);
Identity.AddOverrideIdentity(newElement, editedElement);
}
}
}
return resultElements;
}

}


}
Loading
Loading