Skip to content

Commit

Permalink
adds calculated info
Browse files Browse the repository at this point in the history
  • Loading branch information
clairekuang committed Oct 15, 2024
1 parent 44e5231 commit efa0f92
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ public Base Convert(object target)

// get general properties
Dictionary<string, object?>? generalProperties = _generalPropertiesExtractor.GetGeneralProperties(entity);
if (generalProperties is not null)
if (generalProperties is not null && generalProperties.Count > 0)
{
properties.Add("Properties", generalProperties);
}

// get part data
Dictionary<string, object?>? partData = _partDataExtractor.GetPartData(entity);
if (partData is not null)
if (partData is not null && partData.Count > 0)
{
properties.Add("Part Data", partData);
}

// get property set data
Dictionary<string, object?>? propertySets = _propertySetExtractor.GetPropertySets(entity);
if (propertySets is not null)
if (propertySets is not null && propertySets.Count > 0)
{
properties.Add("Property Sets", propertySets);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,74 @@ public List<Base> GetCorridorChildren(CDB.Corridor corridor)
convertedAppliedSubassembly["displayValue"] = display;
}

// TODO: get the applied subassembly's calculated stuff
// get the applied subassembly's calculated stuff
AddSubassemblyCalculatedProperties(convertedAppliedSubassembly, appliedSubassembly);

appliedSubassemblies.Add(convertedAppliedSubassembly);
}

convertedAppliedAssembly["@elements"] = appliedSubassemblies;
convertedAppliedAssembly["elements"] = appliedSubassemblies;
appliedAssemblies.Add(convertedAppliedAssembly);
}

convertedRegion["@elements"] = appliedAssemblies;
convertedRegion["elements"] = appliedAssemblies;
regions.Add(convertedRegion);
}

convertedBaseline["@elements"] = regions;
convertedBaseline["elements"] = regions;
baselines.Add(convertedBaseline);
}

return baselines;
}

// Adds the calculated shapes > calculated links > calculated points as dicts to the applied subassembly
private void AddSubassemblyCalculatedProperties(
Base speckleAppliedSubassembly,
CDB.AppliedSubassembly appliedSubassembly
)
{
Dictionary<string, object?> calculatedShapes = new();
int shapeCount = 0;
foreach (CDB.CalculatedShape shape in appliedSubassembly.Shapes)
{
Dictionary<string, object?> calculatedLinks = new();
int linkCount = 0;
foreach (CDB.CalculatedLink link in shape.CalculatedLinks)
{
Dictionary<string, object?> calculatedPoints = new();
int pointCount = 0;
foreach (CDB.CalculatedPoint point in link.CalculatedPoints)
{
calculatedPoints[pointCount.ToString()] = new Dictionary<string, object?>()
{
["xyz"] = point.XYZ.ToArray(),
["corridorCodes"] = point.CorridorCodes.ToList(),
["stationOffsetElevationToBaseline"] = point.StationOffsetElevationToBaseline.ToArray(),
};
pointCount++;
}

calculatedLinks[linkCount.ToString()] = new Dictionary<string, object?>()
{
["corridorCodes"] = link.CorridorCodes.ToList(),
["calculatedPoints"] = calculatedPoints
};

linkCount++;
}

calculatedShapes[shapeCount.ToString()] = new Dictionary<string, object?>()
{
["corridorCodes"] = shape.CorridorCodes.ToList(),
["area"] = shape.Area,
["calculatedLinks"] = calculatedLinks
};
}

speckleAppliedSubassembly["calculatedShapes"] = calculatedShapes;
}

/// <summary>
/// Extracts the solids from a corridor and stores in <see cref="CorridorSolidsCache"/> according to property sets on the solid.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
}
}
}

generalPropertiesDict["Feature Lines"] = featureLinesDict;
if (featureLinesDict.Count > 0)
{
generalPropertiesDict["Feature Lines"] = featureLinesDict;
}

// get surfaces props
Dictionary<string, object?> surfacesDict = new();
Expand All @@ -145,7 +147,10 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
["overhangCorrection"] = surface.OverhangCorrection.ToString()
};
}
generalPropertiesDict["Surfaces"] = surfacesDict;
if (surfacesDict.Count > 0)
{
generalPropertiesDict["Surfaces"] = surfacesDict;
}

return generalPropertiesDict;
}
Expand All @@ -170,7 +175,10 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
};
equationCount++;
}
stationControlDict["Station Equations"] = stationEquationsDict;
if (stationEquationsDict.Count > 0)
{
stationControlDict["Station Equations"] = stationEquationsDict;
}

Dictionary<string, object?> referencePointDict =
new()
Expand All @@ -181,7 +189,10 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
};
stationControlDict["Reference Point"] = referencePointDict;

generalPropertiesDict["Station Control"] = stationControlDict;
if (stationControlDict.Count > 0)
{
generalPropertiesDict["Station Control"] = stationControlDict;
}

// get design criteria props
Dictionary<string, object?> designCriteriaDict = new();
Expand All @@ -199,8 +210,15 @@ CDB.FeatureLineCollection featurelineCollection in offsetFeaturelineCollection.F
speedsCount++;
}
designCriteriaDict["Design Speeds"] = designSpeedsDict;
if (designSpeedsDict.Count > 0)
{
designCriteriaDict["Design Speeds"] = designSpeedsDict;
}

generalPropertiesDict["Design Critera"] = designCriteriaDict;
if (designCriteriaDict.Count > 0)
{
generalPropertiesDict["Design Critera"] = designCriteriaDict;
}

// get offset alignment props
if (alignment.IsOffsetAlignment)
Expand Down

0 comments on commit efa0f92

Please sign in to comment.