Skip to content

Commit

Permalink
feat(civil3d): CNX-8013 add alignment properties design speed (#3116)
Browse files Browse the repository at this point in the history
* adds design speeds and other warn fixes

* sets design speeds on receive

* refactors design speeds on alignments
  • Loading branch information
clairekuang authored Dec 19, 2023
1 parent 7b9592e commit 3834ca0
Showing 1 changed file with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private bool GetCivilDocument(ApplicationObject appObj, out CivilDocument doc)
}

// stations
public Station StationToSpeckle(CivilDB.Station station, double? designSpeed)
public Station StationToSpeckle(CivilDB.Station station)
{
var speckleStation = new Station
{
Expand All @@ -55,11 +55,6 @@ public Station StationToSpeckle(CivilDB.Station station, double? designSpeed)
number = station.RawStation,
units = ModelUnits
};

if (designSpeed is not null)
{
speckleStation["designSpeed"] = designSpeed.Value;
}

return speckleStation;
}
Expand Down Expand Up @@ -156,19 +151,20 @@ public CivilAlignment AlignmentToSpeckle(CivilDB.Alignment alignment)

AddNameAndDescriptionProperty(alignment.Name, alignment.Description, speckleAlignment);

// get alignment stations and design speeds
List<Station> stations = new();
Dictionary<double,double> designSpeeds =new();
foreach (DesignSpeed designSpeed in alignment.DesignSpeeds)
// get design speeds
var designSpeeds = DesignSpeedsToSpeckle(alignment.DesignSpeeds);
if (designSpeeds.Count > 0)
{
designSpeeds.Add(designSpeed.Station, designSpeed.Value);
speckleAlignment["@designSpeeds"] = designSpeeds;
}

// get alignment stations and design speeds
List<Station> stations = new();
foreach (CivilDB.Station station in alignment.GetStationSet(StationTypes.All))
{
double? speed = designSpeeds.ContainsKey(station.RawStation) ? designSpeeds[station.RawStation] : null;
stations.Add(StationToSpeckle(station, speed));
stations.Add(StationToSpeckle(station));
}
if (stations.Any())
if (stations.Count > 0)
{
speckleAlignment["@stations"] = stations;
}
Expand All @@ -189,6 +185,28 @@ public CivilAlignment AlignmentToSpeckle(CivilDB.Alignment alignment)

return speckleAlignment;
}

private List<Base> DesignSpeedsToSpeckle(DesignSpeedCollection designSpeeds)
{
List<Base> speckleDesignSpeeds = new();

foreach (DesignSpeed designSpeed in designSpeeds)
{
Base speckleDesignSpeed = new();
speckleDesignSpeed["number"] = designSpeed.SpeedNumber;
speckleDesignSpeed["station"] = designSpeed.Station;
speckleDesignSpeed["value"] = designSpeed.Value;
if (!string.IsNullOrEmpty(designSpeed.Comment))
{
speckleDesignSpeed["comment"] = designSpeed.Comment;
}

speckleDesignSpeeds.Add(speckleDesignSpeed);
}

return speckleDesignSpeeds;
}

public ApplicationObject AlignmentToNative(Alignment alignment)
{
var appObj = new ApplicationObject(alignment.id, alignment.speckle_type) { applicationId = alignment.applicationId };
Expand Down Expand Up @@ -331,13 +349,13 @@ public ApplicationObject AlignmentToNative(Alignment alignment)
existingAlignment.ReferencePointStation = alignment.startStation;

// set design speeds if any
if (civilAlignment["@stations"] is List<object> stations)
if (civilAlignment["@designSpeeds"] is List<object> speeds)
{
foreach (Station station in stations.Cast<Station>())
foreach (object speed in speeds)
{
if (station["designSpeed"] is double designSpeed)
if (speed is Base speedBase && speedBase["station"] is double station && speedBase["value"] is double value)
{
existingAlignment.DesignSpeeds.Add(station.number, designSpeed);
existingAlignment.DesignSpeeds.Add(station, value);
}
}
}
Expand Down

0 comments on commit 3834ca0

Please sign in to comment.