SchematicDrawing : Intersections of pipes drawn as a bow having darker color.
This commit is contained in:
@@ -9,6 +9,8 @@ namespace SchematicDrawing
|
|||||||
{
|
{
|
||||||
public class Graph
|
public class Graph
|
||||||
{
|
{
|
||||||
|
public bool Completed;
|
||||||
|
|
||||||
IList<GNode> nodes;
|
IList<GNode> nodes;
|
||||||
GNode startNode;
|
GNode startNode;
|
||||||
int secondaryStartNodesCount;
|
int secondaryStartNodesCount;
|
||||||
@@ -22,6 +24,7 @@ namespace SchematicDrawing
|
|||||||
startNode = null;
|
startNode = null;
|
||||||
secondaryStartNodesCount = 0;
|
secondaryStartNodesCount = 0;
|
||||||
minHeap = new MinHeap();
|
minHeap = new MinHeap();
|
||||||
|
Completed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
@@ -29,6 +32,7 @@ namespace SchematicDrawing
|
|||||||
nodes.Clear();
|
nodes.Clear();
|
||||||
startNode = null;
|
startNode = null;
|
||||||
secondaryStartNodesCount = 0;
|
secondaryStartNodesCount = 0;
|
||||||
|
Completed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ namespace SchematicDrawing
|
|||||||
public int EndNodeId;
|
public int EndNodeId;
|
||||||
public Sz Sz;
|
public Sz Sz;
|
||||||
|
|
||||||
|
public bool CoordinatesAreValid;
|
||||||
|
public int x1, y1, x2, y2;
|
||||||
|
public bool HasIntersection;
|
||||||
|
public float P;
|
||||||
|
|
||||||
|
|
||||||
public Pipe(IDrawingItem startItem, int startNodeId, IDrawingItem endItem, int endNodeId, Sz sz)
|
public Pipe(IDrawingItem startItem, int startNodeId, IDrawingItem endItem, int endNodeId, Sz sz)
|
||||||
{
|
{
|
||||||
@@ -22,12 +27,16 @@ namespace SchematicDrawing
|
|||||||
EndItem = endItem;
|
EndItem = endItem;
|
||||||
EndNodeId = endNodeId;
|
EndNodeId = endNodeId;
|
||||||
Sz = sz;
|
Sz = sz;
|
||||||
|
CoordinatesAreValid = false;
|
||||||
|
HasIntersection = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pipe(string pipeStr, Sz sz, Dictionary<string, IDrawingItem> name2Item)
|
public Pipe(string pipeStr, Sz sz, Dictionary<string, IDrawingItem> name2Item)
|
||||||
{
|
{
|
||||||
String2Items(pipeStr, name2Item, out StartItem, out StartNodeId, out EndItem, out EndNodeId);
|
String2Items(pipeStr, name2Item, out StartItem, out StartNodeId, out EndItem, out EndNodeId);
|
||||||
Sz = sz;
|
Sz = sz;
|
||||||
|
CoordinatesAreValid = false;
|
||||||
|
HasIntersection = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@@ -44,7 +53,7 @@ namespace SchematicDrawing
|
|||||||
/// <param name="x2">End point X</param>
|
/// <param name="x2">End point X</param>
|
||||||
/// <param name="y2">End point Y</param>
|
/// <param name="y2">End point Y</param>
|
||||||
/// <returns>true when calculation successful</returns>
|
/// <returns>true when calculation successful</returns>
|
||||||
public bool GetCoordinates(out int x1, out int y1, out int x2, out int y2)
|
public bool GetCoordinates()
|
||||||
{
|
{
|
||||||
DrawingShape startDShape = DrawingShape.GetDrawingShape(StartItem);
|
DrawingShape startDShape = DrawingShape.GetDrawingShape(StartItem);
|
||||||
DrawingShape endDShape = DrawingShape.GetDrawingShape(EndItem);
|
DrawingShape endDShape = DrawingShape.GetDrawingShape(EndItem);
|
||||||
@@ -58,17 +67,16 @@ namespace SchematicDrawing
|
|||||||
y1 = StartItem.Y + startNode.Y * Const.GridSize;
|
y1 = StartItem.Y + startNode.Y * Const.GridSize;
|
||||||
x2 = EndItem.X + endNode.X * Const.GridSize;
|
x2 = EndItem.X + endNode.X * Const.GridSize;
|
||||||
y2 = EndItem.Y + endNode.Y * Const.GridSize;
|
y2 = EndItem.Y + endNode.Y * Const.GridSize;
|
||||||
|
CoordinatesAreValid = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x1 = y1 = x2 = y2 = 0;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts pipe string to start and end items
|
/// Converts pipe string to start and end items
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -101,5 +109,37 @@ namespace SchematicDrawing
|
|||||||
endNid = 0;
|
endNid = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true when two pipes have an intersection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pipe2">Second pipe</param>
|
||||||
|
/// <returns>true when ipes intersect</returns>
|
||||||
|
public bool CalculateIntersectionWith(Pipe pipe2)
|
||||||
|
{
|
||||||
|
if (!this.CoordinatesAreValid) GetCoordinates();
|
||||||
|
if (!pipe2.CoordinatesAreValid) pipe2.GetCoordinates();
|
||||||
|
|
||||||
|
int D = (x2 - x1) * (pipe2.y2 - pipe2.y1) - (y2 - y1) * (pipe2.x2 - pipe2.x1);
|
||||||
|
float Dp = Convert.ToSingle((pipe2.x1 - x1) * (pipe2.y2 - pipe2.y1) - (pipe2.y1 - y1) * (pipe2.x2 - pipe2.x1));
|
||||||
|
float Dq = Convert.ToSingle((x2 - x1) * (pipe2.y1 - y1) - (y2 - y1) * (pipe2.x1 - x1));
|
||||||
|
|
||||||
|
if (D == 0)
|
||||||
|
{
|
||||||
|
return false; /// Parallel pipes -> no intersection
|
||||||
|
}
|
||||||
|
|
||||||
|
float Df = Convert.ToSingle(D);
|
||||||
|
float p = Dp / Df;
|
||||||
|
float q = -Dq / Df;
|
||||||
|
if (p > 0.01 && p < 0.99 && q > 0.01 && q < 0.99)
|
||||||
|
{
|
||||||
|
this.HasIntersection = true;
|
||||||
|
this.P = p;
|
||||||
|
return true; /// Pipes intersect, pipes touching by their ends are not considered
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; /// Pipes do not intersect
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,18 @@ namespace SchematicDrawing
|
|||||||
private bool supressRedraws;
|
private bool supressRedraws;
|
||||||
public bool SupressRedraws
|
public bool SupressRedraws
|
||||||
{
|
{
|
||||||
set { if (supressRedraws != value) { supressRedraws = value; Redraw(); } }
|
set
|
||||||
|
{
|
||||||
|
if (supressRedraws != value)
|
||||||
|
{
|
||||||
|
supressRedraws = value;
|
||||||
|
if (!supressRedraws)
|
||||||
|
{
|
||||||
|
JoinPipeListsEtc();
|
||||||
|
Redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
get { return supressRedraws; }
|
get { return supressRedraws; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,12 +100,16 @@ namespace SchematicDrawing
|
|||||||
Pen[] pensDry;
|
Pen[] pensDry;
|
||||||
Pen[] pensWater;
|
Pen[] pensWater;
|
||||||
Pen[] pensVacuum;
|
Pen[] pensVacuum;
|
||||||
|
Pen[] pensDryBackgr;
|
||||||
|
Pen[] pensWaterBackgr;
|
||||||
|
Pen[] pensVacuumBackgr;
|
||||||
Pen[] pensHighlighted;
|
Pen[] pensHighlighted;
|
||||||
|
|
||||||
IList<Pipe> pipesS;
|
IList<Pipe> pipesS;
|
||||||
IList<Pipe> pipesM;
|
IList<Pipe> pipesM;
|
||||||
IList<Pipe> pipesL;
|
IList<Pipe> pipesL;
|
||||||
IList<Pipe> pipesXL;
|
IList<Pipe> pipesXL;
|
||||||
|
IList<Pipe> allPipes;
|
||||||
///
|
///
|
||||||
public string[] PipesS
|
public string[] PipesS
|
||||||
{
|
{
|
||||||
@@ -107,24 +122,20 @@ namespace SchematicDrawing
|
|||||||
pipesS.Clear();
|
pipesS.Clear();
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
foreach (var p in value)
|
foreach (var pStr in value)
|
||||||
{
|
{
|
||||||
Pipe pi = new Pipe(p, Sz.S, Name2Item);
|
pipesS.Add(new Pipe(pStr, Sz.S, Name2Item));
|
||||||
pipesS.Add(pi);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!EditMode && pi.StartItem != null && pi.StartItem.GNodes.Count > pi.StartNodeId &&
|
if (!supressRedraws)
|
||||||
pi.EndItem != null && pi.EndItem.GNodes.Count > pi.EndNodeId)
|
|
||||||
{
|
{
|
||||||
int x1, y1, x2, y2;
|
JoinPipeListsEtc();
|
||||||
int dist = pi.GetCoordinates(out x1, out y1, out x2, out y2) ? (int)Math.Round(Math.Sqrt((double)((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)))) : 1;
|
|
||||||
graph.AddEdge(pi.StartItem.GNodes[pi.StartNodeId], pi.EndItem.GNodes[pi.EndNodeId], dist);
|
|
||||||
graph.AddEdge(pi.EndItem.GNodes[pi.EndNodeId], pi.StartItem.GNodes[pi.StartNodeId], dist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Redraw();
|
Redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
///
|
||||||
public string[] PipesM
|
public string[] PipesM
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -138,24 +149,20 @@ namespace SchematicDrawing
|
|||||||
pipesM.Clear();
|
pipesM.Clear();
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
foreach (var p in value)
|
foreach (var pStr in value)
|
||||||
{
|
{
|
||||||
Pipe pi = new Pipe(p, Sz.M, Name2Item);
|
pipesM.Add(new Pipe(pStr, Sz.M, Name2Item));
|
||||||
pipesM.Add(pi);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!EditMode && pi.StartItem != null && pi.StartItem.GNodes.Count > pi.StartNodeId &&
|
if (!supressRedraws)
|
||||||
pi.EndItem != null && pi.EndItem.GNodes.Count > pi.EndNodeId)
|
|
||||||
{
|
{
|
||||||
int x1, y1, x2, y2;
|
JoinPipeListsEtc();
|
||||||
int dist = pi.GetCoordinates(out x1, out y1, out x2, out y2) ? (int)Math.Round(Math.Sqrt((double)((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)))) : 1;
|
|
||||||
graph.AddEdge(pi.StartItem.GNodes[pi.StartNodeId], pi.EndItem.GNodes[pi.EndNodeId], dist);
|
|
||||||
graph.AddEdge(pi.EndItem.GNodes[pi.EndNodeId], pi.StartItem.GNodes[pi.StartNodeId], dist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Redraw();
|
Redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
///
|
||||||
public string[] PipesL
|
public string[] PipesL
|
||||||
{
|
{
|
||||||
get {
|
get {
|
||||||
@@ -167,24 +174,20 @@ namespace SchematicDrawing
|
|||||||
pipesL.Clear();
|
pipesL.Clear();
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
foreach (var p in value)
|
foreach (var pStr in value)
|
||||||
{
|
{
|
||||||
Pipe pi = new Pipe(p, Sz.L, Name2Item);
|
pipesL.Add(new Pipe(pStr, Sz.L, Name2Item));
|
||||||
pipesL.Add(pi);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!EditMode && pi.StartItem != null && pi.StartItem.GNodes.Count > pi.StartNodeId &&
|
if (!supressRedraws)
|
||||||
pi.EndItem != null && pi.EndItem.GNodes.Count > pi.EndNodeId)
|
|
||||||
{
|
{
|
||||||
int x1, y1, x2, y2;
|
JoinPipeListsEtc();
|
||||||
int dist = pi.GetCoordinates(out x1, out y1, out x2, out y2) ? (int)Math.Round(Math.Sqrt((double)((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)))) : 1;
|
|
||||||
graph.AddEdge(pi.StartItem.GNodes[pi.StartNodeId], pi.EndItem.GNodes[pi.EndNodeId], dist);
|
|
||||||
graph.AddEdge(pi.EndItem.GNodes[pi.EndNodeId], pi.StartItem.GNodes[pi.StartNodeId], dist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Redraw();
|
Redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
///
|
||||||
public string[] PipesXL
|
public string[] PipesXL
|
||||||
{
|
{
|
||||||
get {
|
get {
|
||||||
@@ -196,24 +199,60 @@ namespace SchematicDrawing
|
|||||||
pipesXL.Clear();
|
pipesXL.Clear();
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
foreach (var p in value)
|
foreach (var pStr in value)
|
||||||
{
|
{
|
||||||
Pipe pi = new Pipe(p, Sz.XL, Name2Item);
|
pipesXL.Add(new Pipe(pStr, Sz.XL, Name2Item));
|
||||||
pipesXL.Add(pi);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!EditMode && pi.StartItem != null && pi.StartItem.GNodes.Count > pi.StartNodeId &&
|
if (!supressRedraws)
|
||||||
pi.EndItem != null && pi.EndItem.GNodes.Count > pi.EndNodeId)
|
|
||||||
{
|
{
|
||||||
int x1, y1, x2, y2;
|
JoinPipeListsEtc();
|
||||||
int dist = pi.GetCoordinates(out x1, out y1, out x2, out y2) ? (int)Math.Round(Math.Sqrt((double)((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)))) : 1;
|
|
||||||
graph.AddEdge(pi.StartItem.GNodes[pi.StartNodeId], pi.EndItem.GNodes[pi.EndNodeId], dist);
|
|
||||||
graph.AddEdge(pi.EndItem.GNodes[pi.EndNodeId], pi.StartItem.GNodes[pi.StartNodeId], dist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Redraw();
|
Redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 1. Join 4 pipe lists.
|
||||||
|
/// 2. Add graph edges in case EditMode is off.
|
||||||
|
/// 3. Determine intersections of pipes in case EditMode is off.
|
||||||
|
/// </summary>
|
||||||
|
void JoinPipeListsEtc()
|
||||||
|
{
|
||||||
|
allPipes.Clear();
|
||||||
|
foreach (var p in pipesS) allPipes.Add(p);
|
||||||
|
foreach (var p in pipesM) allPipes.Add(p);
|
||||||
|
foreach (var p in pipesL) allPipes.Add(p);
|
||||||
|
foreach (var p in pipesXL) allPipes.Add(p);
|
||||||
|
|
||||||
|
if ((allPipes.Count > 0) && !EditMode && !graph.Completed)
|
||||||
|
{
|
||||||
|
/// Do the following just once in non edit mode
|
||||||
|
|
||||||
|
for (int i = 0; i < allPipes.Count; i++)
|
||||||
|
{
|
||||||
|
Pipe p = allPipes[i];
|
||||||
|
if (p.StartItem != null && p.StartItem.GNodes.Count > p.StartNodeId &&
|
||||||
|
p.EndItem != null && p.EndItem.GNodes.Count > p.EndNodeId)
|
||||||
|
{
|
||||||
|
int dist = p.GetCoordinates() ? (int)Math.Round(Math.Sqrt((double)((p.x2 - p.x1) * (p.x2 - p.x1) + (p.y2 - p.y1) * (p.y2 - p.y1)))) : 1;
|
||||||
|
graph.AddEdge(p.StartItem.GNodes[p.StartNodeId], p.EndItem.GNodes[p.EndNodeId], dist);
|
||||||
|
graph.AddEdge(p.EndItem.GNodes[p.EndNodeId], p.StartItem.GNodes[p.StartNodeId], dist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < allPipes.Count; i++)
|
||||||
|
{
|
||||||
|
for (int j = i + 1; j < allPipes.Count; j++)
|
||||||
|
{
|
||||||
|
if (allPipes[i].CalculateIntersectionWith(allPipes[j])) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
graph.Completed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Support for adding new pipes
|
/// Support for adding new pipes
|
||||||
IDrawingItem startItem;
|
IDrawingItem startItem;
|
||||||
@@ -246,6 +285,9 @@ namespace SchematicDrawing
|
|||||||
Brush brushDry;
|
Brush brushDry;
|
||||||
Brush brushWater;
|
Brush brushWater;
|
||||||
Brush brushVacuum;
|
Brush brushVacuum;
|
||||||
|
Brush brushDryBackgr;
|
||||||
|
Brush brushWaterBackgr;
|
||||||
|
Brush brushVacuumBackgr;
|
||||||
Brush brushHihglighted;
|
Brush brushHihglighted;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -271,6 +313,7 @@ namespace SchematicDrawing
|
|||||||
|
|
||||||
public SchematicDrawingCtrl()
|
public SchematicDrawingCtrl()
|
||||||
{
|
{
|
||||||
|
SupressRedraws = true;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
this.AutoScaleMode = AutoScaleMode.None;
|
this.AutoScaleMode = AutoScaleMode.None;
|
||||||
@@ -285,6 +328,7 @@ namespace SchematicDrawing
|
|||||||
pipesM = new List<Pipe>();
|
pipesM = new List<Pipe>();
|
||||||
pipesL = new List<Pipe>();
|
pipesL = new List<Pipe>();
|
||||||
pipesXL = new List<Pipe>();
|
pipesXL = new List<Pipe>();
|
||||||
|
allPipes = new List<Pipe>();
|
||||||
|
|
||||||
graph = new Graph();
|
graph = new Graph();
|
||||||
|
|
||||||
@@ -401,11 +445,17 @@ namespace SchematicDrawing
|
|||||||
brushDry = new SolidBrush(Color.FromArgb(255, 127, 127, 127));
|
brushDry = new SolidBrush(Color.FromArgb(255, 127, 127, 127));
|
||||||
brushWater = new SolidBrush(Color.FromArgb(255, 0, 162, 232));
|
brushWater = new SolidBrush(Color.FromArgb(255, 0, 162, 232));
|
||||||
brushVacuum = new SolidBrush(Color.FromArgb(255, 64, 255, 64));
|
brushVacuum = new SolidBrush(Color.FromArgb(255, 64, 255, 64));
|
||||||
|
brushDryBackgr = new SolidBrush(Color.FromArgb(255, 80, 80, 80));
|
||||||
|
brushWaterBackgr = new SolidBrush(Color.FromArgb(255, 0, 108, 154));
|
||||||
|
brushVacuumBackgr = new SolidBrush(Color.FromArgb(255, 48, 196, 48));
|
||||||
brushHihglighted = new SolidBrush(Color.FromArgb(255, 255, 0, 0));
|
brushHihglighted = new SolidBrush(Color.FromArgb(255, 255, 0, 0));
|
||||||
///
|
///
|
||||||
pensDry = new Pen[(int)Sz.XL + 1];
|
pensDry = new Pen[(int)Sz.XL + 1];
|
||||||
pensWater = new Pen[(int)Sz.XL + 1];
|
pensWater = new Pen[(int)Sz.XL + 1];
|
||||||
pensVacuum = new Pen[(int)Sz.XL + 1];
|
pensVacuum = new Pen[(int)Sz.XL + 1];
|
||||||
|
pensDryBackgr = new Pen[(int)Sz.XL + 1];
|
||||||
|
pensWaterBackgr = new Pen[(int)Sz.XL + 1];
|
||||||
|
pensVacuumBackgr = new Pen[(int)Sz.XL + 1];
|
||||||
pensHighlighted = new Pen[(int)Sz.XL + 1];
|
pensHighlighted = new Pen[(int)Sz.XL + 1];
|
||||||
///
|
///
|
||||||
for (Sz sz = Sz.S; sz <= Sz.XL; sz++)
|
for (Sz sz = Sz.S; sz <= Sz.XL; sz++)
|
||||||
@@ -413,6 +463,9 @@ namespace SchematicDrawing
|
|||||||
pensDry[(int)sz] = new Pen(brushDry);
|
pensDry[(int)sz] = new Pen(brushDry);
|
||||||
pensWater[(int)sz] = new Pen(brushWater);
|
pensWater[(int)sz] = new Pen(brushWater);
|
||||||
pensVacuum[(int)sz] = new Pen(brushVacuum);
|
pensVacuum[(int)sz] = new Pen(brushVacuum);
|
||||||
|
pensDryBackgr[(int)sz] = new Pen(brushDryBackgr);
|
||||||
|
pensWaterBackgr[(int)sz] = new Pen(brushWaterBackgr);
|
||||||
|
pensVacuumBackgr[(int)sz] = new Pen(brushVacuumBackgr);
|
||||||
pensHighlighted[(int)sz] = new Pen(brushHihglighted);
|
pensHighlighted[(int)sz] = new Pen(brushHihglighted);
|
||||||
float width;
|
float width;
|
||||||
switch (sz)
|
switch (sz)
|
||||||
@@ -429,6 +482,12 @@ namespace SchematicDrawing
|
|||||||
pensWater[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
pensWater[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
||||||
pensVacuum[(int)sz].Width = width;
|
pensVacuum[(int)sz].Width = width;
|
||||||
pensVacuum[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
pensVacuum[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
||||||
|
pensDryBackgr[(int)sz].Width = width;
|
||||||
|
pensDryBackgr[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
||||||
|
pensWaterBackgr[(int)sz].Width = width;
|
||||||
|
pensWaterBackgr[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
||||||
|
pensVacuumBackgr[(int)sz].Width = width;
|
||||||
|
pensVacuumBackgr[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
||||||
pensHighlighted[(int)sz].Width = width;
|
pensHighlighted[(int)sz].Width = width;
|
||||||
pensHighlighted[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
pensHighlighted[(int)sz].LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;
|
||||||
}
|
}
|
||||||
@@ -456,8 +515,8 @@ namespace SchematicDrawing
|
|||||||
void SchematicDrawingCtrl_Paint(object sender, PaintEventArgs e)
|
void SchematicDrawingCtrl_Paint(object sender, PaintEventArgs e)
|
||||||
{
|
{
|
||||||
/// Profiling
|
/// Profiling
|
||||||
//stopwatch.Reset();
|
stopwatch.Reset();
|
||||||
//stopwatch.Start();
|
stopwatch.Start();
|
||||||
|
|
||||||
e.Graphics.Clear(Color.White);
|
e.Graphics.Clear(Color.White);
|
||||||
|
|
||||||
@@ -483,19 +542,22 @@ namespace SchematicDrawing
|
|||||||
///
|
///
|
||||||
if (EditMode)
|
if (EditMode)
|
||||||
{
|
{
|
||||||
/// Draw pipes without water
|
/// Draw an empty pipe. Coordinates are always recalculated
|
||||||
foreach (var pipe in pipesS) DrawPipe(e, pipe, int.MaxValue);
|
for (int j = 0; j < allPipes.Count; j++)
|
||||||
foreach (var pipe in pipesM) DrawPipe(e, pipe, int.MaxValue);
|
{
|
||||||
foreach (var pipe in pipesL) DrawPipe(e, pipe, int.MaxValue);
|
Pipe pipe = allPipes[j];
|
||||||
foreach (var pipe in pipesXL) DrawPipe(e, pipe, int.MaxValue);
|
pipe.CoordinatesAreValid = false;
|
||||||
|
DrawPipe(e, pipe, int.MaxValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/// Draw pipes with a color determined by Dijkstra shortest path algorithm
|
/// Draw pipes with a color determined by Dijkstra shortest path algorithm
|
||||||
foreach (var pipe in pipesS) DrawPipe(e, pipe, pipe.StartItem.GNodes[pipe.StartNodeId].Dist);
|
for (int j = 0; j < allPipes.Count; j++)
|
||||||
foreach (var pipe in pipesM) DrawPipe(e, pipe, pipe.StartItem.GNodes[pipe.StartNodeId].Dist);
|
{
|
||||||
foreach (var pipe in pipesL) DrawPipe(e, pipe, pipe.StartItem.GNodes[pipe.StartNodeId].Dist);
|
Pipe pipe = allPipes[j];
|
||||||
foreach (var pipe in pipesXL) DrawPipe(e, pipe, pipe.StartItem.GNodes[pipe.StartNodeId].Dist);
|
DrawPipe(e, pipe, pipe.StartItem.GNodes[pipe.StartNodeId].Dist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -504,7 +566,7 @@ namespace SchematicDrawing
|
|||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
DrawingShape dshape = DrawingShape.GetDrawingShape(item);
|
DrawingShape dshape = DrawingShape.GetDrawingShape(item);
|
||||||
if (dshape != null && dshape.Shape != Shape.Junction && dshape.HasImg && (!Utils.IsHidden(item) || EditMode))
|
if (dshape != null && dshape.Shape != Shape.Junction && dshape.HasImg && (!Utils.IsHidden(item) || (EditMode && item == selectedItem)))
|
||||||
{
|
{
|
||||||
Rectangle rect = DrawItem(e, item, dshape);
|
Rectangle rect = DrawItem(e, item, dshape);
|
||||||
ItemElementRectangles.Add(new ItemElementRect(item, Element.Body, rect));
|
ItemElementRectangles.Add(new ItemElementRect(item, Element.Body, rect));
|
||||||
@@ -656,43 +718,89 @@ namespace SchematicDrawing
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Profiling
|
/// Profiling
|
||||||
//stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
//if (firstTime)
|
if (firstTime)
|
||||||
//{
|
{
|
||||||
// firstTime = false;
|
firstTime = false;
|
||||||
//}
|
}
|
||||||
//else if (totalTimes < long.MaxValue)
|
else if (totalTimes < long.MaxValue)
|
||||||
//{
|
{
|
||||||
// totalMs += stopwatch.ElapsedMilliseconds;
|
totalMs += stopwatch.ElapsedMilliseconds;
|
||||||
// totalTicks += stopwatch.ElapsedTicks;
|
totalTicks += stopwatch.ElapsedTicks;
|
||||||
// totalTimes++;
|
totalTimes++;
|
||||||
// Console.WriteLine("Average Paint duration is {0} ms = {1} ticks", totalMs / totalTimes, totalTicks / totalTimes);
|
Console.WriteLine("Average Paint duration is {0} ms = {1} ticks", totalMs / totalTimes, totalTicks / totalTimes);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Profiling
|
/// Profiling
|
||||||
//Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
//bool firstTime = true;
|
bool firstTime = true;
|
||||||
//long totalMs = 0;
|
long totalMs = 0;
|
||||||
//long totalTicks = 0;
|
long totalTicks = 0;
|
||||||
//long totalTimes = 0;
|
long totalTimes = 0;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draw a pipe.
|
/// Draw a pipe.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="e">PaintEventArgs</param>
|
/// <param name="e">PaintEventArgs</param>
|
||||||
/// <param name="pipe">Pipe object</param>
|
/// <param name="p">Pipe object</param>
|
||||||
/// <param name="distance">Distance from source of water for coloring</param>
|
/// <param name="distance">Distance from source of water for coloring</param>
|
||||||
/// <param name="highlighted">true = highlighted (edit mode)</param>
|
/// <param name="highlighted">true = highlighted (edit mode)</param>
|
||||||
void DrawPipe(PaintEventArgs e, Pipe pipe, int distance, bool highlighted = false)
|
void DrawPipe(PaintEventArgs e, Pipe p, int distance, bool highlighted = false)
|
||||||
{
|
{
|
||||||
int x1, y1, x2, y2;
|
if (!p.CoordinatesAreValid) p.GetCoordinates();
|
||||||
if (pipe.GetCoordinates(out x1, out y1, out x2, out y2) && (pipe.Sz >= Sz.S) && (pipe.Sz <= Sz.XL))
|
|
||||||
|
int eIx = Math.Max((int)Sz.S, Math.Min((int)Sz.XL, (int)p.Sz));
|
||||||
|
Pen pen = (distance == int.MaxValue) ? pensDry[eIx] : (distance < Const.Vacuum) ? pensWater[eIx] : pensVacuum[eIx];
|
||||||
|
|
||||||
|
if (highlighted)
|
||||||
{
|
{
|
||||||
int eIx = (int)pipe.Sz;
|
e.Graphics.DrawLine(pensHighlighted[eIx], p.x1, p.y1, p.x2, p.y2);
|
||||||
Pen pen = highlighted ? pensHighlighted[eIx] : ((distance == int.MaxValue) ? pensDry[eIx] : (distance < Const.Vacuum) ? pensWater[eIx] : pensVacuum[eIx]);
|
}
|
||||||
e.Graphics.DrawLine(pen, x1, y1, x2, y2);
|
else if (!p.HasIntersection)
|
||||||
|
{
|
||||||
|
e.Graphics.DrawLine(pen, p.x1, p.y1, p.x2, p.y2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Pen pen2 = (distance == int.MaxValue) ? pensDryBackgr[eIx] : (distance < Const.Vacuum) ? pensWaterBackgr[eIx] : pensVacuumBackgr[eIx];
|
||||||
|
|
||||||
|
float len = (float)Math.Sqrt(Convert.ToSingle((p.x2 - p.x1) * (p.x2 - p.x1) + (p.y2 - p.y1) * (p.y2 - p.y1)));
|
||||||
|
float PP = 1.0f - p.P;
|
||||||
|
if (p.P * len < 20 && PP * len < 20)
|
||||||
|
{
|
||||||
|
/// Draw a straght line with darker color
|
||||||
|
e.Graphics.DrawLine(pen2, p.x1, p.y1, p.x2, p.y2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/// Draw a line having normal color with a bow having darker color
|
||||||
|
|
||||||
|
float vx = 17.0f * (p.x2 - p.x1) / len; /// Fixed size vector in the direction of the line
|
||||||
|
float vy = 17.0f * (p.y2 - p.y1) / len;
|
||||||
|
|
||||||
|
float xm = p.x1 * PP + p.x2 * p.P; /// Intersection point
|
||||||
|
float ym = p.y1 * PP + p.y2 * p.P;
|
||||||
|
int x3 = Convert.ToInt32(Math.Round(xm - vx)); /// Points around the intersection point
|
||||||
|
int y3 = Convert.ToInt32(Math.Round(ym - vy));
|
||||||
|
int x4 = Convert.ToInt32(Math.Round(xm - 2 * vy / 3));
|
||||||
|
int y4 = Convert.ToInt32(Math.Round(ym + 2 * vx / 3));
|
||||||
|
int x5 = Convert.ToInt32(Math.Round(xm + vx));
|
||||||
|
int y5 = Convert.ToInt32(Math.Round(ym + vy));
|
||||||
|
|
||||||
|
/// Joints between straight parts of the line and the bow
|
||||||
|
DrawingShape dsh = DrawingShape.GetDrawingShape(Shape.Junction, p.Sz);
|
||||||
|
Image image = (distance == int.MaxValue) ? dsh.ImgRightOpenDry : (distance < Const.Vacuum) ? dsh.ImgRight : dsh.ImgRightVacuum;
|
||||||
|
e.Graphics.DrawImage(image, x3 - dsh.Wid / 2, y3 - dsh.Hgh / 2);
|
||||||
|
e.Graphics.DrawImage(image, x5 - dsh.Wid / 2, y5 - dsh.Hgh / 2);
|
||||||
|
|
||||||
|
e.Graphics.DrawLine(pen2, x3, y3, x4, y4); /// Bow
|
||||||
|
e.Graphics.DrawLine(pen2, x4, y4, x5, y5);
|
||||||
|
|
||||||
|
e.Graphics.DrawLine(pen, p.x1, p.y1, x3, y3); /// Straight parts of the line
|
||||||
|
e.Graphics.DrawLine(pen, x5, y5, p.x2, p.y2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -936,15 +1044,14 @@ namespace SchematicDrawing
|
|||||||
/// <returns>Squared distance</returns>
|
/// <returns>Squared distance</returns>
|
||||||
float SquaredDistanceFromLine(int x, int y, Pipe pipe)
|
float SquaredDistanceFromLine(int x, int y, Pipe pipe)
|
||||||
{
|
{
|
||||||
int xx1, yy1, xx2, yy2;
|
if (!pipe.GetCoordinates() || (pipe.x1 == pipe.x2 && pipe.y1 == pipe.y2))
|
||||||
if (!pipe.GetCoordinates(out xx1, out yy1, out xx2, out yy2) || (xx1 == xx2 && yy1 == yy2))
|
|
||||||
{
|
{
|
||||||
return float.MaxValue;
|
return float.MaxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 X = new Vector2(Convert.ToSingle(x), Convert.ToSingle(y));
|
Vector2 X = new Vector2(Convert.ToSingle(x), Convert.ToSingle(y));
|
||||||
Vector2 X1 = new Vector2(Convert.ToSingle(xx1), Convert.ToSingle(yy1));
|
Vector2 X1 = new Vector2(Convert.ToSingle(pipe.x1), Convert.ToSingle(pipe.y1));
|
||||||
Vector2 X2 = new Vector2(Convert.ToSingle(xx2), Convert.ToSingle(yy2));
|
Vector2 X2 = new Vector2(Convert.ToSingle(pipe.x2), Convert.ToSingle(pipe.y2));
|
||||||
Vector2 vX = X - X1; /// |X1 X|
|
Vector2 vX = X - X1; /// |X1 X|
|
||||||
Vector2 v12 = X2 - X1; /// |X1 X2|
|
Vector2 v12 = X2 - X1; /// |X1 X2|
|
||||||
|
|
||||||
|
|||||||
@@ -644,12 +644,12 @@ namespace TBF.UI.Bench.EditSchDrawing
|
|||||||
|
|
||||||
void DeleteSelectedPipe()
|
void DeleteSelectedPipe()
|
||||||
{
|
{
|
||||||
Pipe edge = drawingCtrl.GetTempPipe();
|
Pipe pipe = drawingCtrl.GetTempPipe();
|
||||||
if (edge != null)
|
if (pipe != null)
|
||||||
{
|
{
|
||||||
/// Delete selected pipe
|
/// Delete selected pipe
|
||||||
TBF.BenchControl.Various.Drawing.Pipes.Configuration pipesCfg = null;
|
TBF.BenchControl.Various.Drawing.Pipes.Configuration pipesCfg = null;
|
||||||
switch (edge.Sz)
|
switch (pipe.Sz)
|
||||||
{
|
{
|
||||||
case Sz.S: pipesCfg = pipesScfg; break;
|
case Sz.S: pipesCfg = pipesScfg; break;
|
||||||
case Sz.M: pipesCfg = pipesMcfg; break;
|
case Sz.M: pipesCfg = pipesMcfg; break;
|
||||||
@@ -664,7 +664,7 @@ namespace TBF.UI.Bench.EditSchDrawing
|
|||||||
int ix = -1;
|
int ix = -1;
|
||||||
for (int i = 0; i < oriEdges.Length; i++)
|
for (int i = 0; i < oriEdges.Length; i++)
|
||||||
{
|
{
|
||||||
if (oriEdges[i] == edge.ToString())
|
if (oriEdges[i] == pipe.ToString())
|
||||||
{
|
{
|
||||||
ix = i;
|
ix = i;
|
||||||
break;
|
break;
|
||||||
@@ -683,7 +683,7 @@ namespace TBF.UI.Bench.EditSchDrawing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (edge.Sz)
|
switch (pipe.Sz)
|
||||||
{
|
{
|
||||||
case Sz.S: drawingCtrl.PipesS = pipesCfg.Pipes; break;
|
case Sz.S: drawingCtrl.PipesS = pipesCfg.Pipes; break;
|
||||||
case Sz.M: drawingCtrl.PipesM = pipesCfg.Pipes; break;
|
case Sz.M: drawingCtrl.PipesM = pipesCfg.Pipes; break;
|
||||||
|
|||||||
Reference in New Issue
Block a user