Skip to content
Snippets Groups Projects
Commit 0b292827 authored by Антон Кудряшов's avatar Антон Кудряшов
Browse files

fixed check values methods

parent f7f8af98
Branches
No related tags found
No related merge requests found
......@@ -210,17 +210,16 @@ namespace MES_Wind
List<WindStressPRM.Powerline> powerlinesToPRM = new List<WindStressPRM.Powerline>();
foreach (IFeature feature in pwlineSet.Features)
{
WindStressPRM.Powerline dummyline = new WindStressPRM.Powerline();
DataRow featureData = feature.DataRow;
dummyline.Identifier = feature.Fid;
dummyline.Year = int.Parse(featureData["Year"].ToString());
dummyline.Height = double.Parse(featureData["HeightOffs"].ToString());
dummyline.Voltage = int.Parse(featureData["Voltage"].ToString());
dummyline.PointFromID = int.Parse(featureData["PointFrom"].ToString());
dummyline.PointToID = int.Parse(featureData["PointTo"].ToString());
int Identifier = feature.Fid;
int Year = int.Parse(featureData["Year"].ToString());
double Height = double.Parse(featureData["HeightOffs"].ToString());
int Voltage = int.Parse(featureData["Voltage"].ToString());
int PointFromID = int.Parse(featureData["PointFrom"].ToString());
int PointToID = int.Parse(featureData["PointTo"].ToString());
LineString featureline = feature.BasicGeometry as LineString;
dummyline.Coordinates = DotspLinestringToPrm(featureline);
powerlinesToPRM.Add(dummyline);
WindStressPRM.Powerline powerline = new WindStressPRM.Powerline(DotspLinestringToPrm(featureline), Identifier, Year, Height, Voltage, PointToID, PointFromID);
powerlinesToPRM.Add(powerline);
}
//create PRM_station list to pass to PRM_wind from loaded point layer
List<WindStressPRM.PowerStation> powerpointsToPRM = new List<WindStressPRM.PowerStation>();
......
......@@ -46,16 +46,13 @@ namespace WindStressPRM
this.Wind10 = w10;
this.Wind15 = w15;
this.Wind25 = w25;
if (!(this.CheckValue()))
{
throw new System.ArgumentException("Climate wind value is not correct");
}
this.CheckValue();
}
/// <summary>
/// Провекра валидности полей класса
/// </summary>
/// <returns></returns>
public bool CheckValue()
private void CheckValue()
{
double w5 = Wind5;
double w10 = Wind10;
......@@ -94,7 +91,6 @@ namespace WindStressPRM
{
throw new System.ArgumentOutOfRangeException("w25", w25, "Expected 0=<w25<70");
}
return true;
}
}
}
......@@ -99,15 +99,16 @@ namespace WindStressPRM
this.IsON = false;
CheckValue();
}
public bool CheckValue()
private void CheckValue()
{
if (Identifier < 0) {
if (Identifier < 0)
{
throw new System.ArgumentOutOfRangeException("Identifier", Identifier, "Identifer expected to be more than 0");
}
if (Voltage < 0 || Voltage > 1500) {
if (Voltage < 0 || Voltage > 1500)
{
throw new System.ArgumentOutOfRangeException("Voltage", Voltage, "Voltage expected to be in range (0,1500)");
}
return true;
}
/// <summary>
/// Gets attached lines list
......
......@@ -56,11 +56,6 @@ namespace WindStressPRM
/// получает (true) или нет (false) линия питание
/// </summary>
public bool IsON { get; set; }
public Powerline()
{
//default constructor body
}
/// <summary>
/// designated constructor
/// </summary>
......@@ -82,31 +77,38 @@ namespace WindStressPRM
this.IsON = false;
this.PointFromID = fromID;
this.PointToID = toID;
if (!(this.CheckValue()))
{
throw new System.ArgumentException("Powerline object wasn't initialized correctly");
}
this.CheckValue();
}
/// <summary>
/// проверка валидности полей
/// </summary>
/// <returns></returns>
public bool CheckValue()
private void CheckValue()
{
bool checker =
Identifier >= 0;
if (!checker) { throw new System.ArgumentOutOfRangeException("Identifier", Identifier, "Expected >0"); }
checker = checker && Year > 1900 && Year < 2050;
if (!checker) { throw new System.ArgumentOutOfRangeException("Year", Year, "Expected 1900<Year<2050"); }
checker = checker && Height > 0 && Height < 50;
if (!checker) { throw new System.ArgumentOutOfRangeException("Height", Height, "Expected 0<Height<50"); }
checker = checker && Voltage > 0 && Voltage < 1500;
if (!checker) { throw new System.ArgumentOutOfRangeException("Voltage", Voltage, "Expected 0<Voltage<1500"); }
checker = checker && PointFromID >= 0;
if (!checker) { throw new System.ArgumentOutOfRangeException("PointFromID", PointFromID, "Expected >0"); }
checker = checker && PointToID >= 0;
if (!checker) { throw new System.ArgumentOutOfRangeException("PointToID", PointToID, "Expected >0"); }
return checker;
if (Identifier < 0)
{
throw new System.ArgumentOutOfRangeException("Identifier", Identifier, "Expected >0");
}
if (Year > 2050 || Year < 1900)
{
throw new System.ArgumentOutOfRangeException("Year", Year, "Expected 1900<=Year<=2050");
}
if (Height <= 0 || Height > 50)
{
throw new System.ArgumentOutOfRangeException("Height", Height, "Expected 0<Height<=50");
}
if (Voltage <= 0 || Voltage > 1500)
{
throw new System.ArgumentOutOfRangeException("Voltage", Voltage, "Expected 0<Voltage<=1500");
}
if (PointFromID < 0)
{
throw new System.ArgumentOutOfRangeException("PointFromID", PointFromID, "Expected >0");
}
if (PointToID < 0)
{
throw new System.ArgumentOutOfRangeException("PointToID", PointToID, "Expected >0");
}
}
}
}
......@@ -31,30 +31,31 @@ namespace WindStressPRM
{
this.VelocityX = vX;
this.VelocityY = vY;
if (!(this.CheckValue()))
{
throw new System.ArgumentException("Prognostic wind velocities are incorrect");
}
this.CheckValue();
}
/// <summary>
/// Проверка полей на валидность
/// </summary>
/// <returns></returns>
public bool CheckValue()
private void CheckValue()
{
bool res1 = Double.IsNaN(VelocityX);
bool res2 = Double.IsNaN(VelocityY);
if (res1 != res2)
{
return false;
throw new System.ArgumentException("Prognostic wind velocities are incorrect: one projection is Nan, and other has value.");
}
// пустые данные
if (res1 == res2 == true)
{
return true;
return;
}
///Скорость ветра на высоте 10м от поверхности на Земле не может превышать 70м/c
return Math.Abs(Math.Pow(VelocityX, 2) + Math.Pow(VelocityY, 2)) <= 4900;
double module = Math.Sqrt(Math.Abs(Math.Pow(VelocityX, 2) + Math.Pow(VelocityY, 2)));
if (module > 70)
{
throw new System.ArgumentOutOfRangeException("Module of wind speed", module, "Expected 0<Module<=70");
}
}
}
}
......@@ -28,18 +28,22 @@ namespace WindStressPRM
{
this.Width = width;
this.Height = height;
if (!(this.CheckValue()))
{
throw new System.ArgumentException("Cell width or height values are incorrect!");
}
this.CheckValue();
}
/// <summary>
/// Проверка валидности полей
/// </summary>
/// <returns></returns>
public bool CheckValue()
private void CheckValue()
{
return Width > 0 && Height > 0;
if (Width <= 0 || Double.IsNaN(Width))
{
throw new System.ArgumentOutOfRangeException("Cellsize.width is incorrect", Width, "Expected 0<Width");
}
if (Height <= 0 || Double.IsNaN(Height))
{
throw new System.ArgumentOutOfRangeException("Cellsize.height is incorrect", Height, "Expected 0<Height");
}
}
}
}
......@@ -29,18 +29,22 @@ namespace WindStressPRM
{
this.X = X;
this.Y = Y;
if (!(this.CheckValue()))
{
throw new System.ArgumentException("Passed coordinates are not valid!");
}
this.CheckValue();
}
/// <summary>
/// Проверка на валидность значений
/// </summary>
/// <returns></returns>
public bool CheckValue()
private void CheckValue()
{
return !Double.IsNaN(X) && !Double.IsInfinity(X) && !Double.IsNaN(Y) && !Double.IsInfinity(Y);
if (Double.IsNaN(X) || Double.IsInfinity(X))
{
throw new System.ArgumentOutOfRangeException("Coordinate.X is incorrect", X, "Expected X!=Nan, X!=INF");
}
if (Double.IsNaN(Y) || Double.IsInfinity(Y))
{
throw new System.ArgumentOutOfRangeException("Coordinate.Y is incorrect", Y, "Expected Y!=Nan, Y!=INF");
}
}
}
}
......@@ -18,7 +18,8 @@ namespace WindStressPRM
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public Coordinate CellToProjection(Index index) {
public Coordinate CellToProjection(Index index)
{
return new Coordinate(Origin.X + index.Row*Size.Width, Origin.Y - index.Col*Size.Height);
}
/// <summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment