Skip to content

Commit

Permalink
Вывод результатов
Browse files Browse the repository at this point in the history
  • Loading branch information
AlLevykin committed May 28, 2023
1 parent e21766d commit ae791b5
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 13 deletions.
48 changes: 35 additions & 13 deletions PSRClassLibrary/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
using QuickGraph.Algorithms;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using PSR.Helpers;
using System.Linq;
using static System.Net.Mime.MediaTypeNames;

namespace PSR
{
Expand Down Expand Up @@ -147,33 +145,58 @@ private static bool Route(Module module)
}
graph.AddEdgeRange(mst);

List<Point> errors = new List<Point>();
List<Point> tripls = new List<Point>();
List<Point> sockets = new List<Point>();
List<Point> crosses = new List<Point>();
foreach (Point point in graph.Vertices)
{
int adjacentDegree = graph.AdjacentDegree(point);
switch (adjacentDegree)
{
case 1:
sockets.Add(point);
module.sockets.Add(point);
break;
case 2:
IEnumerable<Edge<Point>> adjacentEdges = graph.AdjacentEdges(point);
List<Edge<Point>> edges = new List<Edge<Point>>(adjacentEdges);
double angle = Geometry.AngleBetween(edges[0], edges[1]);

switch (angle)
{
case 180:
module.tubeLength += edges[0].Source.DistanceTo(edges[0].Target);
module.tubeLength += edges[1].Source.DistanceTo(edges[1].Target);
break;
case 0:
module.tubeLength += edges[0].Source.DistanceTo(edges[0].Target);
module.tubeLength += edges[1].Source.DistanceTo(edges[1].Target);
break;
case 90:
module.angles90.Add(point);
break;
case 45:
module.angles45.Add(point);
break;
case 30:
module.angles30.Add(point);
break;
default:
module.errors.Add(point);
break;
}

break;
case 3:
tripls.Add(point);
module.tripls.Add(point);
break;
case 4:
crosses.Add(point);
module.crosses.Add(point);
break;
default:
errors.Add(point);
module.errors.Add(point);
break;
}
}

module.tubeLength = Math.Round(module.tubeLength / 2);

return true;
}

Expand All @@ -192,13 +215,12 @@ public static bool Build(Module module, Action<string> statusCallback = null)
return false;
}
statusCallback?.Invoke("Трассировка.");
statusCallback?.Invoke("Подбор фиттингов, труб и редукций.");
if (!Route(module))
{
statusCallback?.Invoke("Трассировка завершилась с ошибкой.");
return false;
}
statusCallback?.Invoke("Подбор труб и редукций.");
statusCallback?.Invoke("Подбор фиттингов.");
statusCallback?.Invoke("Расчет системы водоотведения завершен.");

return true;
Expand Down
27 changes: 27 additions & 0 deletions PSRClassLibrary/Helpers/Geometry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using QuickGraph;
using System;
using System.Reflection;
using System.Security.Cryptography;

namespace PSR.Helpers
{
public class Geometry
{
internal static double AngleBetween(IEdge<Point> edge1, IEdge<Point> edge2)
{
Point basePoint = (edge1.Source == edge2.Source) ? edge1.Source : edge1.Target;
Point p1 = (edge1.Source == basePoint) ? edge1.Target : edge1.Source;
Point p2 = (edge2.Source == basePoint) ? edge2.Target : edge2.Source;
return GetAngle(basePoint, p1, p2);
}

public static double GetAngle(Point basePoint, Point p1, Point p2)
{
double m1 = Math.Sqrt(Math.Pow(p1.X - basePoint.X, 2) + Math.Pow(p1.Y - basePoint.Y, 2) + Math.Pow(p1.Z - basePoint.Z, 2));
double m2 = Math.Sqrt(Math.Pow(p2.X - basePoint.X, 2) + Math.Pow(p2.Y - basePoint.Y, 2) + Math.Pow(p2.Z - basePoint.Z, 2));
double sm = (p1.X - basePoint.X) * (p2.X - basePoint.X) + (p1.Y - basePoint.Y) * (p2.Y - basePoint.Y) + (p1.Z - basePoint.Z) * (p2.Z - basePoint.Z);
double cos = sm / (m1 * m2);
return Math.Round(Math.Acos(cos) * 180 / Math.PI);
}
}
}
9 changes: 9 additions & 0 deletions PSRClassLibrary/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@ public class Module
public IList<Wall> Walls = new List<Wall>();
public IList<Entry> Drains = new List<Entry>();
public Entry VentStack { get; set; } = new Entry();
// Результаты
public double tubeLength = 0;
public List<Point> errors = new List<Point>();
public List<Point> tripls = new List<Point>();
public List<Point> angles90 = new List<Point>();
public List<Point> angles30 = new List<Point>();
public List<Point> angles45 = new List<Point>();
public List<Point> sockets = new List<Point>();
public List<Point> crosses = new List<Point>();
}
}
1 change: 1 addition & 0 deletions PSRClassLibrary/PSRClassLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<ItemGroup>
<Compile Include="Builder.cs" />
<Compile Include="Entry.cs" />
<Compile Include="Helpers\Geometry.cs" />
<Compile Include="Module.cs" />
<Compile Include="Point.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
33 changes: 33 additions & 0 deletions PSRNanoCadPlugIn/CadPlugIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ public void BuildPlumbingSystem()

Builder.Build(module, StatusInfoCallback);

dwg.Editor.WriteMessage("Результаты расчета:");

if (module.tubeLength > 0) dwg.Editor.WriteMessage("Общая длина труб:{0}", module.tubeLength);
if (module.sockets.Count > 0)
{
dwg.Editor.WriteMessage("Патрубки:{0}", module.sockets.Count);
foreach(var socket in module.sockets) dwg.Editor.WriteMessage("{0}", socket.ToString());
}
if (module.tripls.Count > 0)
{
dwg.Editor.WriteMessage("Тройники:{0}", module.tripls.Count);
foreach (var tripl in module.tripls) dwg.Editor.WriteMessage("{0}", tripl.ToString());
}
if (module.crosses.Count > 0)
{
dwg.Editor.WriteMessage("Крестовины:{0}", module.crosses.Count);
foreach (var cross in module.crosses) dwg.Editor.WriteMessage("{0}", cross.ToString());
}
if (module.angles30.Count > 0)
{
dwg.Editor.WriteMessage("Отводы 30 градусов:{0}", module.angles30.Count);
foreach (var angle in module.angles30) dwg.Editor.WriteMessage("{0}", angle.ToString());
}
if (module.angles45.Count > 0)
{
dwg.Editor.WriteMessage("Отводы 45 градусов:{0}", module.angles45.Count);
foreach (var angle in module.angles45) dwg.Editor.WriteMessage("{0}", angle.ToString());
}
if (module.angles90.Count > 0)
{
dwg.Editor.WriteMessage("Отводы 90 градусов:{0}", module.angles90.Count);
foreach (var angle in module.angles90) dwg.Editor.WriteMessage("{0}", angle.ToString());
}
}
}
}

0 comments on commit ae791b5

Please sign in to comment.