Pipes use Id instead if Name to identify end-components.
This commit is contained in:
parent
cfe55e430a
commit
0a1966d5f9
@ -11,6 +11,7 @@ namespace SchematicDrawing
|
||||
///
|
||||
/// Schematic drawing parameters
|
||||
///
|
||||
int Id { get; }
|
||||
string Name { get; } /// Unique name
|
||||
string ClassName { get; }
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2020 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2020-2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -31,9 +31,9 @@ namespace SchematicDrawing
|
||||
HasIntersection = false;
|
||||
}
|
||||
|
||||
public Pipe(string pipeStr, Sz sz, Dictionary<string, IDrawingItem> name2Item)
|
||||
public Pipe(string pipeStr, Sz sz, Dictionary<int, IDrawingItem> id2Item)
|
||||
{
|
||||
String2Items(pipeStr, name2Item, out StartItem, out StartNodeId, out EndItem, out EndNodeId);
|
||||
String2Items(pipeStr, id2Item, out StartItem, out StartNodeId, out EndItem, out EndNodeId);
|
||||
Sz = sz;
|
||||
CoordinatesAreValid = false;
|
||||
HasIntersection = false;
|
||||
@ -41,7 +41,7 @@ namespace SchematicDrawing
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (StartItem != null && EndItem != null) ? string.Format("{0}~{1}~{2}~{3}", StartItem.Name, StartNodeId, EndItem.Name, EndNodeId) : string.Empty;
|
||||
return (StartItem != null && EndItem != null) ? string.Format("{0}~{1}~{2}~{3}", StartItem.Id, StartNodeId, EndItem.Id, EndNodeId) : string.Empty;
|
||||
}
|
||||
|
||||
|
||||
@ -85,16 +85,17 @@ namespace SchematicDrawing
|
||||
/// <param name="startItem">Start item</param>
|
||||
/// <param name="endItem">End item</param>
|
||||
/// <returns>true when conversion successful</returns>
|
||||
public static bool String2Items(string pipeStr, Dictionary<string, IDrawingItem> name2Item, out IDrawingItem startItem, out int startNid, out IDrawingItem endItem, out int endNid)
|
||||
public static bool String2Items(string pipeStr, Dictionary<int, IDrawingItem> id2Item, out IDrawingItem startItem, out int startNid, out IDrawingItem endItem, out int endNid)
|
||||
{
|
||||
string[] fields = pipeStr.Split(new char[] { '~' });
|
||||
|
||||
int startId, endId;
|
||||
IDrawingItem start, end;
|
||||
DrawingShape dshapeFrom, dshapeTo;
|
||||
if (fields.Length == 4 && name2Item.TryGetValue(fields[0], out start)
|
||||
if (fields.Length == 4 && int.TryParse(fields[0], out startId) && id2Item.TryGetValue(startId, out start)
|
||||
&& (null != (dshapeFrom = DrawingShape.Shapes[DrawingShape.DrShIx(start.Shape, start.Sz)]))
|
||||
&& int.TryParse(fields[1], out startNid) && (startNid >= 0) && (startNid < dshapeFrom.Nodes.Length)
|
||||
&& name2Item.TryGetValue(fields[2], out end)
|
||||
&& int.TryParse(fields[2], out endId) && id2Item.TryGetValue(endId, out end)
|
||||
&& (null != (dshapeTo = DrawingShape.Shapes[DrawingShape.DrShIx(end.Shape, end.Sz)]))
|
||||
&& int.TryParse(fields[3], out endNid) && (endNid >= 0) && (endNid < dshapeTo.Nodes.Length))
|
||||
{
|
||||
|
||||
@ -131,7 +131,7 @@ namespace SchematicDrawing
|
||||
IList<Pipe> pipesXL;
|
||||
IList<Pipe> allPipes;
|
||||
///
|
||||
public string[] PipesS
|
||||
public string[] PipesS
|
||||
{
|
||||
get {
|
||||
string[] retv = new string[pipesS.Count];
|
||||
@ -144,7 +144,7 @@ namespace SchematicDrawing
|
||||
{
|
||||
foreach (var pStr in value)
|
||||
{
|
||||
pipesS.Add(new Pipe(pStr, Sz.S, Name2Item));
|
||||
pipesS.Add(new Pipe(pStr, Sz.S, Id2Item));
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ namespace SchematicDrawing
|
||||
{
|
||||
foreach (var pStr in value)
|
||||
{
|
||||
pipesM.Add(new Pipe(pStr, Sz.M, Name2Item));
|
||||
pipesM.Add(new Pipe(pStr, Sz.M, Id2Item));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ namespace SchematicDrawing
|
||||
{
|
||||
foreach (var pStr in value)
|
||||
{
|
||||
pipesL.Add(new Pipe(pStr, Sz.L, Name2Item));
|
||||
pipesL.Add(new Pipe(pStr, Sz.L, Id2Item));
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ namespace SchematicDrawing
|
||||
{
|
||||
foreach (var pStr in value)
|
||||
{
|
||||
pipesXL.Add(new Pipe(pStr, Sz.XL, Name2Item));
|
||||
pipesXL.Add(new Pipe(pStr, Sz.XL, Id2Item));
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,6 +283,7 @@ namespace SchematicDrawing
|
||||
/// Dictionary that speeds up drawing edges between nodes
|
||||
/// </summary>
|
||||
public Dictionary<string, IDrawingItem> Name2Item;
|
||||
public Dictionary<int, IDrawingItem> Id2Item;
|
||||
|
||||
|
||||
///
|
||||
@ -343,6 +344,7 @@ namespace SchematicDrawing
|
||||
|
||||
items = new List<IDrawingItem>();
|
||||
Name2Item = new Dictionary<string, IDrawingItem>();
|
||||
Id2Item = new Dictionary<int, IDrawingItem>();
|
||||
SelectedItem = null;
|
||||
|
||||
route = 0x55AA; /// Invalid value to be overwritten in the first write to Route
|
||||
@ -366,6 +368,7 @@ namespace SchematicDrawing
|
||||
{
|
||||
items.Add(item);
|
||||
Name2Item.Add(item.Name, item);
|
||||
Id2Item.Add(item.Id, item);
|
||||
|
||||
if (!EditMode)
|
||||
{
|
||||
@ -397,6 +400,7 @@ namespace SchematicDrawing
|
||||
{
|
||||
items.Clear();
|
||||
Name2Item.Clear();
|
||||
Id2Item.Clear();
|
||||
graph.Clear();
|
||||
Redraw();
|
||||
}
|
||||
@ -580,7 +584,7 @@ namespace SchematicDrawing
|
||||
for (int j = 0; j < allPipes.Count; j++)
|
||||
{
|
||||
Pipe pipe = allPipes[j];
|
||||
DrawPipe(e, pipe, pipe.StartItem.GNodes[pipe.StartNodeId].Dist);
|
||||
DrawPipe(e, pipe, pipe.StartItem != null ? pipe.StartItem.GNodes[pipe.StartNodeId].Dist : int.MaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ namespace TBF.Rig
|
||||
readonly Generic.IComponentCfg cfg;
|
||||
public Generic.IComponentCfg Cfg { get { return cfg; } }
|
||||
|
||||
public int Id { get { return cfg.Id; } }
|
||||
public string Name { get { return cfg.Name; } }
|
||||
public string ClassName { get { return cfg.Factory.ClassName; } }
|
||||
public string ParentName { get { return cfg.ParentName; } }
|
||||
|
||||
@ -12,6 +12,9 @@ namespace TBF.Rig
|
||||
{
|
||||
public class ComponentCfgBase
|
||||
{
|
||||
[XmlIgnore]
|
||||
public int Id { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public string Name
|
||||
{
|
||||
@ -127,6 +130,7 @@ namespace TBF.Rig
|
||||
IComponentCfg config = s.Deserialize(reader) as IComponentCfg;
|
||||
if (config != null)
|
||||
{
|
||||
config.Id = cmpntEntity.Id;
|
||||
config.Name = cmpntEntity.Name;
|
||||
config.ParentName = cmpntEntity.Parent;
|
||||
config.ItemNr = cmpntEntity.ItemNr;
|
||||
|
||||
@ -8,6 +8,8 @@ namespace TBF.Rig.Generic
|
||||
{
|
||||
public interface IComponentCfg
|
||||
{
|
||||
int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unique component # (0 .. nr.of components-1)
|
||||
/// </summary>
|
||||
|
||||
@ -104,9 +104,9 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
var eCfg = cmpCfg as TBF.Rig.Various.Drawing.Pipes.Configuration;
|
||||
switch (eCfg.Sz)
|
||||
{
|
||||
case Sz.S: if (pipesScfg == null) pipesScfg = eCfg; break;
|
||||
case Sz.M: if (pipesMcfg == null) pipesMcfg = eCfg; break;
|
||||
case Sz.L: if (pipesLcfg == null) pipesLcfg = eCfg; break;
|
||||
case Sz.S: if (pipesScfg == null) pipesScfg = eCfg; break;
|
||||
case Sz.M: if (pipesMcfg == null) pipesMcfg = eCfg; break;
|
||||
case Sz.L: if (pipesLcfg == null) pipesLcfg = eCfg; break;
|
||||
case Sz.XL: if (pipesXLcfg == null) pipesXLcfg = eCfg; break;
|
||||
}
|
||||
}
|
||||
@ -236,6 +236,29 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
IComponentFactory factory = selectComponentTypeDlg.SlctdCmpntFactory;
|
||||
IComponentCfg cfg = factory.DefaultConfig();
|
||||
|
||||
/// Find a uniqueue component name with a nummber
|
||||
int i = 1;
|
||||
do
|
||||
{
|
||||
string newName = string.Format("{0}{1}", cfg.Name, i);
|
||||
bool alreadyExists = false;
|
||||
foreach (var ce in cmpntEntities)
|
||||
{
|
||||
if (ce.Name == newName)
|
||||
{
|
||||
alreadyExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!alreadyExists)
|
||||
{
|
||||
cfg.Name = newName;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
while (i < 100);
|
||||
|
||||
IComponentCfgCtrl cfgControl = cfg.GetControl(cmpntEntities);
|
||||
cfgControl.Config = cfg;
|
||||
cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
@ -249,6 +272,8 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
{
|
||||
Config.Entities.Component newComponent = cfgForm.Config.CreateDbEntity();
|
||||
cmpntEntities.Add(newComponent);
|
||||
session.SaveOrUpdate(newComponent);
|
||||
cfgForm.Config.Id = newComponent.Id;
|
||||
|
||||
IDrawingItem item = cfgForm.Config as IDrawingItem;
|
||||
if (item != null)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user