Skip to content

Commit

Permalink
Automatic merge of T1.5.1-194-gfbeaf7368 and 14 pull requests
Browse files Browse the repository at this point in the history
- Pull request #706 at 91bcfa2: Extended door functionality
- Pull request #722 at fb9079e: Fix Windows Forms deprecations in ActivityEditor
- Pull request #732 at dc256cd: Improvements for air brakes
- Pull request #735 at b9a0ea3: Added new parameter for battery switch
- Pull request #746 at f5566d7: Website release 1.5.1
- Pull request #753 at ab8fe32: Extends CabControls for user input
- Pull request #760 at 113dd63: Updated EditorConfig with .NET and StyleCop analyzer configuration
- Pull request #761 at f6a3aca: fix: Allow 100% cloud-free skys by making 0% overcast = 0% clouds
- Pull request #763 at 12e250d: build: Remove use of SolutionDir which is not supported everywhere
- Pull request #764 at 5f9a01b: fix: Improve sky dome distortion causing bug #1471416
- Pull request #765 at 083467b: Bug fix for https://bugs.launchpad.net/or/+bug/2002183 OK to proceed sound played wrongly
- Pull request #766 at f143fcc: Control Car additional functionality
- Pull request #767 at 719c737: Refine sunrise and sunset
- Pull request #768 at f2f3e11: OpenRailway Map enhancements
  • Loading branch information
openrails-bot committed Jan 16, 2023
Show file tree
Hide file tree
Showing 13 changed files with 724 additions and 47 deletions.
222 changes: 222 additions & 0 deletions Source/ORTS.Common/InfoApiMap.cs
@@ -0,0 +1,222 @@
// COPYRIGHT 2013 by the Open Rails project.
//
// This file is part of Open Rails.
//
// Open Rails is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Open Rails is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using ORTS.Common;

namespace Orts.Common
{
public class OverlayLayer
{
public string name;
public bool show;
}

public enum TypeOfPointOnApiMap {
track,
named,
rest
}

public class PointOnApiMap
{
public LatLon latLon;
public string color;
public TypeOfPointOnApiMap typeOfPointOnApiMap;
public string name;
}

public class LineOnApiMap
{
public LatLon latLonFrom;
public LatLon latLonTo;
}

public class InfoApiMap
{
public string typeOfLocomotive;
public string baseLayer;
public OverlayLayer[] overlayLayer;

public LinkedList<PointOnApiMap> pointOnApiMapList;
public LinkedList<LineOnApiMap> lineOnApiMapList;

public float latMin;
public float latMax;
public float lonMin;
public float lonMax;

public const string RegistrySection = "ApiMap";
public const string RegistryKeyBaselayer = "baseLayer";
public const string RegistrySectionLayers = "ApiMap\\Layers";

public InfoApiMap(string powerSupplyName, string settingsFilePath, string registryKey)
{
initTypeOfLocomotive(powerSupplyName);
initLayers(settingsFilePath, registryKey);

pointOnApiMapList = new LinkedList<PointOnApiMap>();
lineOnApiMapList = new LinkedList<LineOnApiMap>();

latMax = -999999f;
latMin = +999999f;
lonMax = -999999f;
lonMin = +999999f;
}

private void initTypeOfLocomotive(string powerSupplyName)
{
string powerSupplyNameToLower = powerSupplyName.ToLower();
if (powerSupplyNameToLower.Contains("steam"))
{
typeOfLocomotive = "steam";
}
else
{
if (powerSupplyNameToLower.Contains("diesel"))
{
typeOfLocomotive = "diesel";
}
else
{
typeOfLocomotive = "electric";
}
}
}

private void initLayers(string settingsFilePath, string registryKey)
{
var store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, RegistrySection);
baseLayer = (string)store.GetUserValue(RegistryKeyBaselayer, typeof(string));

overlayLayer = null;
store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, RegistrySectionLayers);
string[] names = store.GetUserNames();
if (names.Length > 0)
{
overlayLayer = new OverlayLayer[names.Length];

int index = 0;
foreach (string name in names)
{
overlayLayer[index] = new OverlayLayer
{
name = name,
show = (bool)store.GetUserValue(name, typeof(bool))
};
index++;
}
}
}

public static void storeLayerSetting(
string settingsFilePath, string registryKey,
string layerAction, string layerName)
{
if (layerAction == "baseLayerChange")
{
var store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, InfoApiMap.RegistrySection);
store.SetUserValue(InfoApiMap.RegistryKeyBaselayer, layerName);
}
else
{
var store = SettingsStore.GetSettingStore(settingsFilePath, registryKey, InfoApiMap.RegistrySectionLayers);
if (layerAction == "overlayAdd")
{
store.SetUserValue(layerName, (bool)true);
}
if (layerAction == "overlayRemove")
{
store.SetUserValue(layerName, (bool)false);
}
}
}

public static LatLon convertToLatLon(int TileX, int TileZ, float X, float Y, float Z)
{
double latitude = 1f;
double longitude = 1f;

WorldLocation mstsLocation = new WorldLocation(TileX, TileZ, X, Y, Z);
new WorldLatLon().ConvertWTC(TileX, TileZ, mstsLocation.Location, ref latitude, ref longitude);
LatLon latLon = new LatLon(MathHelper.ToDegrees((float)latitude), MathHelper.ToDegrees((float)longitude));

return latLon;
}

public void addToPointOnApiMap(
int TileX, int TileZ, float X, float Y, float Z,
string color, TypeOfPointOnApiMap typeOfPointOnApiMap, string name)
{
LatLon latLon = InfoApiMap.convertToLatLon(TileX, TileZ, X, Y, Z);

addToPointOnApiMap(latLon,
color, typeOfPointOnApiMap, name);
}

public void addToPointOnApiMap(
LatLon latLon,
string color, TypeOfPointOnApiMap typeOfPointOnApiMap, string name)
{
PointOnApiMap pointOnApiMap = new PointOnApiMap
{
latLon = latLon,
color = color,
typeOfPointOnApiMap = typeOfPointOnApiMap,
name = name
};

if (pointOnApiMap.typeOfPointOnApiMap == TypeOfPointOnApiMap.named)
{
// named last is the list so that they get displayed on top
pointOnApiMapList.AddLast(pointOnApiMap);
}
else
{
pointOnApiMapList.AddFirst(pointOnApiMap);
}

if (pointOnApiMap.latLon.Lat > latMax)
{
latMax = pointOnApiMap.latLon.Lat;
}
if (pointOnApiMap.latLon.Lat < latMin)
{
latMin = pointOnApiMap.latLon.Lat;
}
if (pointOnApiMap.latLon.Lon > lonMax)
{
lonMax = pointOnApiMap.latLon.Lon;
}
if (pointOnApiMap.latLon.Lon < lonMin)
{
lonMin = pointOnApiMap.latLon.Lon;
}
}

public void addToLineOnApiMap(LatLon latLonFrom, LatLon latLongTo)
{
LineOnApiMap lineOnApiMap = new LineOnApiMap
{
latLonFrom = latLonFrom,
latLonTo = latLongTo
};
lineOnApiMapList.AddLast(lineOnApiMap);
}
}
}
Expand Up @@ -35,7 +35,7 @@
namespace Orts.Common
{
public class WorldLatLon
{
{
int earthRadius = 6370997; // Average radius of the earth, meters
double Epsilon = 0.0000000001; // Error factor (arbitrary)
double[] Lon_Center = new double[12];
Expand Down Expand Up @@ -159,7 +159,7 @@ private int Goode_Inverse(double GX, double GY, ref double Latitude, ref double
switch (region)
{
case 1:
case 3:
case 3:
case 4:
case 5:
case 8:
Expand Down Expand Up @@ -289,20 +289,33 @@ static double Adjust_Lon(double value)
}

/// <summary>
/// Class to store the latitude and longitude values of a point on the map
/// Class to store the latitude and longitude of a position on the webpage map
/// </summary>
public class LatLon
{
private readonly float _lat;
private readonly float _lon;
public float Lat { get; }
public float Lon { get; }

public LatLon(float lat, float lon)
{
this._lat = lat;
this._lon = lon;
Lat = lat;
Lon = lon;
}
}

/// <summary>
/// Class to store the latitude, longitude and direction of a locomotive on the webpage map
/// </summary>
public class LatLonDirection
{
public LatLon LatLon { get; }
public float directionDeg { get; }

public float Lat => _lat;
public float Lon => _lon;
public LatLonDirection(LatLon latLon, float directionDeg)
{
LatLon = latLon;
this.directionDeg = directionDeg;
}
}
}

0 comments on commit 92c7035

Please sign in to comment.