diff --git a/MES_Wind/frmMain.cs b/MES_Wind/frmMain.cs index 6dfa09ad2f836503ec6979d93d2889291dff1073..67bafe8bf35531f275d124e9bced2157c6de2abf 100644 --- a/MES_Wind/frmMain.cs +++ b/MES_Wind/frmMain.cs @@ -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>(); diff --git a/WindStressPRM/Objects/ClimateCell.cs b/WindStressPRM/Objects/ClimateCell.cs index 0a8bcec048e2bb59cc72eba1bc4b7bd7649c16c9..66d93f6ea5b99dcf270e0b298f366b0f1a54c612 100644 --- a/WindStressPRM/Objects/ClimateCell.cs +++ b/WindStressPRM/Objects/ClimateCell.cs @@ -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; } } } diff --git a/WindStressPRM/Objects/PowerStation.cs b/WindStressPRM/Objects/PowerStation.cs index 0d6e8b8222dd268b8c87d1bcd0e84deff0c36f03..1f96a56524772d89b075deccccb41778f533ff82 100644 --- a/WindStressPRM/Objects/PowerStation.cs +++ b/WindStressPRM/Objects/PowerStation.cs @@ -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 diff --git a/WindStressPRM/Objects/Powerline.cs b/WindStressPRM/Objects/Powerline.cs index 9fd1ee9999fc5e8f5ec654ab69e4893a99b1b9ba..f6f60165be2dce09ddee6fb96129d39c3b87aef8 100644 --- a/WindStressPRM/Objects/Powerline.cs +++ b/WindStressPRM/Objects/Powerline.cs @@ -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"); + } } } } diff --git a/WindStressPRM/Objects/PrognosticCell.cs b/WindStressPRM/Objects/PrognosticCell.cs index e2e5b0acce4d8eff997de5c90ed31c66c5a70a12..4a9154380b3e6a40901576ffc9c7f99d59c2a688 100644 --- a/WindStressPRM/Objects/PrognosticCell.cs +++ b/WindStressPRM/Objects/PrognosticCell.cs @@ -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"); + } } } } diff --git a/WindStressPRM/Utils/CellSize.cs b/WindStressPRM/Utils/CellSize.cs index 4bb470b25a16315cf3c1adbc86d4d9b43cbc403d..f0e5f19cb1d7131e06c24d5221946a51995b7df4 100644 --- a/WindStressPRM/Utils/CellSize.cs +++ b/WindStressPRM/Utils/CellSize.cs @@ -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"); + } } } } diff --git a/WindStressPRM/Utils/Coordinate.cs b/WindStressPRM/Utils/Coordinate.cs index 6e2f0c89129bf586b2261bb344308705c7dc375b..0e0de4183e37410c0cbbd1089b39e8db370546ff 100644 --- a/WindStressPRM/Utils/Coordinate.cs +++ b/WindStressPRM/Utils/Coordinate.cs @@ -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"); + } } } } diff --git a/WindStressPRM/Utils/Matrix.cs b/WindStressPRM/Utils/Matrix.cs index a4677bccd57e1402a5b0f16f9cbc15c0697dfcc8..51f81f64afd78429be5c92ce5a32d8405ed4da27 100644 --- a/WindStressPRM/Utils/Matrix.cs +++ b/WindStressPRM/Utils/Matrix.cs @@ -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>