Skip to content

Commit

Permalink
Merge branch 'release/v0.11.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbelesky committed Aug 8, 2021
2 parents aa87b88 + eac3e58 commit 4c8246c
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 100 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.11.0] - 2021-08-08
### Added
- Live reporting of progress parsing files (below the component)

### Changed
- Reduced minimum required Rhino 6 version to `6.10` or greater

## [0.10.0] - 2021-07-21
### Added
- A bake-friendly layer name to the `Report` output parameter
Expand Down
2 changes: 1 addition & 1 deletion Caribou.Tests/Models/TestMultipleBoundsParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TestMultipleBoundsParsing : MelbourneCase
private RequestHandler results = new RequestHandler(new List<string>() {
Properties.Resources.MelbourneOSM,
Properties.Resources.SimpleOSM
}, mainFeatures);
}, mainFeatures, OSMGeometryType.Node, reportProgress, "Test");

[TestMethod]
public void ParseBoundsViaXMLReader()
Expand Down
3 changes: 2 additions & 1 deletion Caribou.Tests/Models/TestSingleBoundsParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class TestSingleBoundsParsing : MelbourneCase
{
private Coord expectedMinBounds = new Coord(-37.8164200, 144.9127400);
private Coord expectedMaxBounds = new Coord(-37.2164200, 144.9710600);
private RequestHandler results = new RequestHandler(OSMXMLs, mainFeatures);
private RequestHandler results = new RequestHandler(OSMXMLs, mainFeatures,
OSMGeometryType.Node, reportProgress, "Test");

[TestMethod]
public void ParseBoundsViaXMLReader()
Expand Down
6 changes: 4 additions & 2 deletions Caribou.Tests/Processing/BaseParsingTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Caribou.Tests.Processing
{
using System;
using System.Collections.Generic;
using System.Linq;
using Caribou.Components;
Expand All @@ -9,6 +10,7 @@
public abstract class BaseParsingTest
{
protected static MessagesWrapper messages = new MessagesWrapper();
public static Action<string, double> reportProgress;
protected readonly OSMMetaData craftsData = new OSMMetaData("craft");
protected readonly OSMMetaData amenitiesData = new OSMMetaData("amenity");
protected readonly OSMMetaData buildingsData = new OSMMetaData("building");
Expand All @@ -24,10 +26,10 @@ public abstract class BaseParsingTest
protected readonly OSMMetaData wikiRelatedData = new OSMMetaData("wikipedia");
protected readonly OSMMetaData tramRoutesData = new OSMMetaData("tram", "route_master");
protected readonly OSMMetaData tramStopsData = new OSMMetaData("yes", "tram_stop");

protected static RequestHandler fetchResultsViaXMLReader(List<string> xml, ParseRequest features, OSMGeometryType typeOfFeature)
{
var results = new RequestHandler(xml, features);
var results = new RequestHandler(xml, features, OSMGeometryType.Node, reportProgress, "Test");
ParseViaXMLReader.FindItemsByTag(ref results, typeOfFeature, true);
return results;
}
Expand Down
4 changes: 2 additions & 2 deletions Caribou/Caribou.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<VersionPrefix>0.9.0</VersionPrefix>
<VersionPrefix>0.11.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
<Title>Caribou</Title>
<Description>Description of Caribou</Description>
Expand All @@ -18,7 +18,7 @@
<!--NUGET-->
<ItemGroup>
<PackageReference Include="Eto.Forms" Version="2.5.0" IncludeAssets="compile;build" />
<PackageReference Include="Grasshopper" Version="6.16.19190.7001" IncludeAssets="compile;build" />
<PackageReference Include="Grasshopper" Version="6.10.18308.14011" IncludeAssets="compile;build" />
<PackageReference Include="Hsluv" Version="1.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
Expand Down
22 changes: 2 additions & 20 deletions Caribou/CaribouComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ protected CaribouComponent(string name, string nickname, string description, str
{
}

public virtual string GetSubComponentText()
{
return "v" + GetPluginVersion();
}

// Adds a message under each component while debugging; useful to distinguish between components from published vs development sources
#if DEBUG
public override bool Read(GH_IReader reader)
{
this.Message = GetSubComponentText();
return base.Read(reader);
}

public override void AddedToDocument(GH_Document document)
{
this.Message = GetSubComponentText();
base.AddedToDocument(document);
}
#endif

// Components must implement the method
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "<Pending>")]
protected abstract void CaribouRegisterOutputParams(GH_Component.GH_OutputParamManager pManager);
Expand All @@ -65,6 +45,7 @@ protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager
// Override the main solve instance method. This allows it to be wrapped in a try/catch for error reporting purposes
protected override void SolveInstance(IGH_DataAccess DA)
{
RhinoDoc.ActiveDoc.Views.RedrawEnabled = false;
#if DEBUG
logger.Reset();
#endif
Expand All @@ -74,6 +55,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
#if DEBUG
DA.SetDataList(logger.indexOfDebugOutput, logger.debugLogs);
#endif
RhinoDoc.ActiveDoc.Views.RedrawEnabled = true;
}

// This is provided to all components so it can be passed along to error reporting
Expand Down
2 changes: 1 addition & 1 deletion Caribou/CaribouInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CaribouInfo : GH_AssemblyInfo
public override string AuthorContact => "[email protected]";

// GHB note: if using the provided "About" component this URL is output there
public virtual Uri PluginURL => new Uri("https://github.com/philipbelesky/caribou/");
public virtual Uri PluginURL => new Uri("https://caribou.philipbelesky.com");

// GHB note: if using the provided "About" component this File is output there
public virtual Uri ChangeLogURL => new Uri("https://raw.githubusercontent.com/philipbelesky/Caribou/main/CHANGELOG.md");
Expand Down
26 changes: 19 additions & 7 deletions Caribou/Components/BaseLoadAndParseWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Linq;

/// <summary>
/// Shared logic for doing the 'work' of each parsing component.
Expand All @@ -33,23 +37,34 @@ public BaseLoadAndParseWorker(GH_Component parent)
{
}

// Subclasses must specify their type
protected abstract OSMGeometryType WorkerType();

// Parse the XML to extract component specific results
public void ExtractCoordsForComponentType(Action<string, double> reportProgress)
{
ParseViaXMLReader.FindItemsByTag(ref this.result, this.WorkerType());
}

public override void DoWork(Action<string, double> reportProgress, Action done)
{
logger.Reset();
logger.indexOfDebugOutput = 3;
string typeName = Enum.GetName(typeof(OSMGeometryType), this.WorkerType());

result = new RequestHandler(providedFilePaths, requestedMetaData);
result = new RequestHandler(providedFilePaths, requestedMetaData, this.WorkerType(), reportProgress, Id);
logger.NoteTiming("Setup request handler");
if (this.CancellationToken.IsCancellationRequested)
return;

this.ExtractCoordsForComponentType(); // Parse XML for lat/lon data
logger.NoteTiming("Extract coords from data");
reportProgress(Id, 0.03); // Report something in case there is a long node-collection hang when extracting ways
this.ExtractCoordsForComponentType(reportProgress); // Parse XML for lat/lon data
logger.NoteTiming($"Extract {typeName}s from data");
if (this.CancellationToken.IsCancellationRequested)
return;

this.MakeGeometryForComponentType(); // Translate lat/lon data to Rhino geo
logger.NoteTiming("Translate coords to geometry");
logger.NoteTiming("Convert to geometry");
if (this.CancellationToken.IsCancellationRequested)
return;

Expand All @@ -71,9 +86,6 @@ public override void DoWork(Action<string, double> reportProgress, Action done)
done();
}

// Parse the XML to extract component specific results
public abstract void ExtractCoordsForComponentType();

// Generate type-specific geometry (e.g. way or node)
public abstract void MakeGeometryForComponentType();

Expand Down
10 changes: 4 additions & 6 deletions Caribou/Components/ParseBuildingsWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
public class ParseBuildingsWorker : BaseLoadAndParseWorker
{
private GH_Structure<GH_Surface> buildingOutputs;
private Dictionary<OSMMetaData, List<Surface>> foundBuildings;
private Dictionary<OSMMetaData, List<Surface>> foundBuildings;
protected override OSMGeometryType WorkerType() {
return OSMGeometryType.Building;
}

public ParseBuildingsWorker(GH_Component parent)
: base(parent) // Pass parent component back to base class so state (e.g. remarks) can bubble up
Expand All @@ -24,11 +27,6 @@ public ParseBuildingsWorker(GH_Component parent)

public override WorkerInstance Duplicate() => new ParseBuildingsWorker(this.Parent);

public override void ExtractCoordsForComponentType()
{
ParseViaXMLReader.FindItemsByTag(ref this.result, OSMGeometryType.Building);
}

public override void MakeGeometryForComponentType()
{
// Translate OSM nodes to Rhino Surfaces
Expand Down
9 changes: 4 additions & 5 deletions Caribou/Components/ParseNodesWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class ParseNodesWorker : BaseLoadAndParseWorker
{
private GH_Structure<GH_Point> nodeOutputs;
private Dictionary<OSMMetaData, List<Point3d>> foundNodes;
protected override OSMGeometryType WorkerType()
{
return OSMGeometryType.Node;
}

public ParseNodesWorker(GH_Component parent)
: base(parent) // Pass parent component back to base class so state (e.g. remarks) can bubble up
Expand All @@ -24,11 +28,6 @@ public ParseNodesWorker(GH_Component parent)

public override WorkerInstance Duplicate() => new ParseNodesWorker(this.Parent);

public override void ExtractCoordsForComponentType()
{
ParseViaXMLReader.FindItemsByTag(ref this.result, OSMGeometryType.Node);
}

public override void MakeGeometryForComponentType()
{
// Translate OSM nodes to Rhino points
Expand Down
9 changes: 4 additions & 5 deletions Caribou/Components/ParseWaysWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class ParseWaysWorker : BaseLoadAndParseWorker
{
private GH_Structure<GH_Curve> wayOutputs;
private Dictionary<OSMMetaData, List<PolylineCurve>> foundWays;
protected override OSMGeometryType WorkerType()
{
return OSMGeometryType.Way;
}

public ParseWaysWorker(GH_Component parent)
: base(parent) // Pass parent component back to base class so state (e.g. remarks) can bubble up
Expand All @@ -24,11 +28,6 @@ public ParseWaysWorker(GH_Component parent)

public override WorkerInstance Duplicate() => new ParseWaysWorker(this.Parent);

public override void ExtractCoordsForComponentType()
{
ParseViaXMLReader.FindItemsByTag(ref this.result, OSMGeometryType.Way);
}

public override void MakeGeometryForComponentType()
{
// Translate OSM ways to Rhino polylines
Expand Down
13 changes: 2 additions & 11 deletions Caribou/Forms/ControlStrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,16 @@ public static class ControlStrip
{
public static CheckBox GetHider(Action toggleAction, bool hideObscureFeaturesState)
{
// Note that checkbox labels misaligned on some versions of MacOS Rhino less than current
var showHideMinorFeatures = new CheckBox()
{
Checked = hideObscureFeaturesState,
Text = " Hide SubFeatures with very low counts",
};
showHideMinorFeatures.CheckedChanged += (sender, e) => { toggleAction(); };
return showHideMinorFeatures;
}

/// <summary>Checkbox labels are misaligned on macOS if they have a provided Text.</summary>
public static Label GetHiderLabel(Action toggleAction)
{
var showHideMinorFeaturesLabel = new Label()
{
Text = " Hide SubFeatures with very low counts",
};
showHideMinorFeaturesLabel.MouseDown += (sender, e) => { toggleAction(); };
return showHideMinorFeaturesLabel;
}

public static Button GetSelectAll(int buttonWidth, int buttonHeight, Action selectAll)
{
var allButton = new Button()
Expand Down
7 changes: 0 additions & 7 deletions Caribou/Forms/SpecifyFeaturesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public SpecifyFeaturesForm(TreeGridItemCollection selectionState, bool hideObscu
topButtons.BeginHorizontal();
this.obscureFeaturesCheckbox = ControlStrip.GetHider(ToggleObscureFeatures, this.hideObscureFeatures);
topButtons.Add(obscureFeaturesCheckbox);
topButtons.Add(ControlStrip.GetHiderLabel(ToggleObscureFeatuesManually));
topButtons.Add(null);
topButtons.Add(ControlStrip.GetExpandAll(buttonWidth - 90, buttonHeight, ExpandAll));
topButtons.Add(new Label() { Width = 10 });
Expand Down Expand Up @@ -83,12 +82,6 @@ public SpecifyFeaturesForm(TreeGridItemCollection selectionState, bool hideObscu

private void CollapseAll() => this.SetRollout(false);

private void ToggleObscureFeatuesManually()
{
this.obscureFeaturesCheckbox.Checked = !this.obscureFeaturesCheckbox.Checked.Value;
this.ToggleObscureFeatures();
}

private void ToggleObscureFeatures()
{
this.hideObscureFeatures = this.obscureFeaturesCheckbox.Checked.Value;
Expand Down
15 changes: 13 additions & 2 deletions Caribou/Models/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ public class RequestHandler
public Dictionary<OSMMetaData, List<FoundItem>> FoundData; // The collected items per request
public List<string> FoundItemIds; // Used to track for duplicate ways/nodes across files

public RequestHandler(List<string> providedXMLs, ParseRequest requestedMetaData)
public string WorkerId; // Used for progress reporting
public Action<string, double> ReportProgress;
public List<int> LinesPerFile;

public RequestHandler(List<string> providedXMLs, ParseRequest requestedMetaData, OSMGeometryType requestedType,
Action<string, double> reportProgress, string workerId)
{
this.XmlPaths = providedXMLs;
this.RequestedMetaData = requestedMetaData;

// Setup data holders
this.FoundItemIds = new List<string>();
this.FoundData = new Dictionary<OSMMetaData, List<FoundItem>>();
foreach (OSMMetaData metaData in requestedMetaData.Requests)
{
this.FoundData[metaData] = new List<FoundItem>();
}

this.FoundItemIds = new List<string>();
// Setup reporting infrastructure
this.WorkerId = workerId;
this.ReportProgress = reportProgress;
if (providedXMLs[0].Length < 1000) // Don't calculate line lengths when working with tests (e.g. passed by contents not path)
this.LinesPerFile = ProgressReporting.GetLineLengthsForFiles(providedXMLs, requestedType);
}

public void AddWayIfMatchesRequest(string nodeId, Dictionary<string, string> nodeTags, List<Coord> coords)
Expand Down
Loading

0 comments on commit 4c8246c

Please sign in to comment.