| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- using MECF.Framework.UI.Core.DxfScript;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- namespace MECF.Framework.UI.Core.DxfScript
- {
- /// <summary>
- /// 名称:事件类
- /// 用途:BoolConditions/StringConditions 逻辑实现
- /// </summary>
- public partial class GasDxfDocument
- {
- //解析全部事件
- public void ParseConditions()
- {
- foreach (var node in BoolConditions)
- {
- string boolCondition = node.Value;
- if (boolCondition == null || boolCondition.Equals(""))
- {
- continue;
- }
- int id = node.Key;
- GasBaseShape shape = FindShapeById(id);
- if (shape != null)
- {
- shape.BoolCondition = new Script(boolCondition);
- }
- }
- foreach (var node in StringConditions)
- {
- string stringCondition = node.Value;
- if (stringCondition == null || stringCondition.Equals(""))
- {
- continue;
- }
- int id = node.Key;
- GasBaseShape shape = FindShapeById(id);
- if (shape != null)
- {
- shape.StringCondition = new Script(stringCondition);
- }
- }
- foreach (var node in ClickConditions)
- {
- string clickCondition = node.Value;
- if (clickCondition == null || clickCondition.Equals(""))
- {
- continue;
- }
- int id = node.Key;
- GasBaseShape shape = FindShapeById(id);
- if (shape != null)
- {
- shape.ClickCondition = new Script(clickCondition);
- }
- }
- }
- //保存conditions的公共函数
- private void SaveCondition(XmlDocument xmlDoc, XmlElement nodeBoolConditions, XmlElement nodeStringConditions, XmlElement nodeClickConditions, GasBaseShape shape)
- {
- if (shape.Id > 0)
- {
- string boolCondition = null;
- if (BoolConditions.ContainsKey(shape.Id))
- {
- boolCondition = BoolConditions[shape.Id];
- }
- string stringCondition = null;
- if (StringConditions.ContainsKey(shape.Id))
- {
- stringCondition = StringConditions[shape.Id];
- }
- string clickCondition = null;
- if (ClickConditions.ContainsKey(shape.Id))
- {
- clickCondition = ClickConditions[shape.Id];
- }
- if (boolCondition != null && !boolCondition.Equals(""))
- {
- XmlElement nodeBoolCondition = xmlDoc.CreateElement("BoolCondition");
- nodeBoolCondition.SetAttribute("Id", shape.Id.ToString());
- nodeBoolCondition.InnerText = boolCondition;
- nodeBoolConditions.AppendChild(nodeBoolCondition);
- }
- if (stringCondition != null && !stringCondition.Equals(""))
- {
- XmlElement nodeStringCondition = xmlDoc.CreateElement("StringCondition");
- nodeStringCondition.SetAttribute("Id", shape.Id.ToString());
- nodeStringCondition.InnerText = stringCondition;
- nodeStringConditions.AppendChild(nodeStringCondition);
- }
- if (clickCondition != null && !clickCondition.Equals(""))
- {
- XmlElement nodeClickCondition = xmlDoc.CreateElement("ClickCondition");
- nodeClickCondition.SetAttribute("Id", shape.Id.ToString());
- nodeClickCondition.InnerText = clickCondition;
- nodeClickConditions.AppendChild(nodeClickCondition);
- }
- }
- }
- private void LoadCondition(XmlDocument xmlDoc)
- {
- XmlNodeList nodeBoolConditions = xmlDoc.SelectNodes("GasDxfDocument/BoolConditions/BoolCondition");
- foreach (XmlElement nodeBoolCondition in nodeBoolConditions)
- {
- int id = int.Parse(nodeBoolCondition.GetAttribute("Id"));
- if (id > 0)
- {
- string boolCondition = nodeBoolCondition.InnerText;
- if (boolCondition != null && !boolCondition.Equals(""))
- {
- BoolConditions.Add(id, boolCondition);
- }
- GasBaseShape shape = FindShapeById(id);
- if (shape != null)
- {
- shape.BoolCondition = new Script(boolCondition);
- }
- }
- }
- XmlNodeList nodeStringConditions = xmlDoc.SelectNodes("GasDxfDocument/StringConditions/StringCondition");
- foreach (XmlElement nodeStringCondition in nodeStringConditions)
- {
- int id = int.Parse(nodeStringCondition.GetAttribute("Id"));
- if (id > 0)
- {
- string stringCondition = nodeStringCondition.InnerText;
- if (stringCondition != null && !stringCondition.Equals(""))
- {
- StringConditions.Add(id, stringCondition);
- }
- GasBaseShape shape = FindShapeById(id);
- if (shape != null)
- {
- shape.StringCondition = new Script(stringCondition);
- }
- }
- }
- XmlNodeList nodeClickConditions = xmlDoc.SelectNodes("GasDxfDocument/ClickConditions/ClickCondition");
- foreach (XmlElement nodeClickCondition in nodeClickConditions)
- {
- int id = int.Parse(nodeClickCondition.GetAttribute("Id"));
- if (id > 0)
- {
- string clickCondition = nodeClickCondition.InnerText;
- if (clickCondition != null && !clickCondition.Equals(""))
- {
- ClickConditions.Add(id, clickCondition);
- }
- GasBaseShape shape = FindShapeById(id);
- if (shape != null)
- {
- shape.ClickCondition = new Script(clickCondition);
- }
- }
- }
- }
- /// <summary>
- /// 清除所有事件
- /// </summary>
- public void ClearAll()
- {
- ClearDxf();
- if (BoolConditions != null)
- {
- BoolConditions.Clear();
- }
- else
- {
- BoolConditions = new Dictionary<int, string>();
- }
- if (StringConditions != null)
- {
- StringConditions.Clear();
- }
- else
- {
- StringConditions = new Dictionary<int, string>();
- }
- if (ClickConditions != null)
- {
- ClickConditions.Clear();
- }
- else
- {
- ClickConditions = new Dictionary<int, string>();
- }
- InitScriptContent = "";
- InitScriptExpress = null;
- IsGasFileModified = false;
- SelectedShape = null;
- }
- //把boolcondition和stringConditon的文本内容更新到字典中,并且刷新shape的脚本对象
- public void UpdateBoolCondition(GasBaseShape shape, string boolCondition)
- {
- shape.BoolCondition = new Script(boolCondition);
- if (BoolConditions.ContainsKey(shape.Id))
- {
- BoolConditions[shape.Id] = boolCondition;
- }
- else
- {
- BoolConditions.Add(shape.Id, boolCondition);
- }
- }
- public void UpdateStringCondition(GasBaseShape shape, string stringCondition)
- {
- shape.StringCondition = new Script(stringCondition);
- if (StringConditions.ContainsKey(shape.Id))
- {
- StringConditions[shape.Id] = stringCondition;
- }
- else
- {
- StringConditions.Add(shape.Id, stringCondition);
- }
- }
- public void UpdateClickCondition(GasBaseShape shape, string clickCondition)
- {
- shape.ClickCondition = new Script(clickCondition);
- if (ClickConditions.ContainsKey(shape.Id))
- {
- ClickConditions[shape.Id] = clickCondition;
- }
- else
- {
- ClickConditions.Add(shape.Id, clickCondition);
- }
- }
- public void UpdateInitScript(string content)
- {
- InitScriptContent = content;
- InitScriptExpress = new Script(content);
- }
- //根据Id找元件
- public GasBaseShape FindShapeById(int id)
- {
- switch (id / 1000000)
- {
- case (int)GasBaseShape.ShapeType.ACUTE:
- case (int)GasBaseShape.ShapeType.OBTUSE:
- case (int)GasBaseShape.ShapeType.FUNNEL:
- case (int)GasBaseShape.ShapeType.HLINE:
- case (int)GasBaseShape.ShapeType.POLY:
- case (int)GasBaseShape.ShapeType.VLINE:
- //线段
- GasLine line = Lines.Find(x => x.Id == id);
- if (line != null)
- {
- return line;
- }
- else
- {
- GasPolyLine polyLine = PolyLines.Find(x => x.Id == id);
- if (polyLine != null)
- {
- return polyLine;
- }
- else
- {
- GasButton button = Buttons.Find(x => x.Id == id);
- if (button != null)
- {
- return button;
- }
- else
- {
- GasAnalogControl4Jet analog = Analogs.Find(x => x.Id == id);
- if (analog != null)
- {
- return analog;
- }
- else
- {
- return null;
- }
- }
- }
- }
- break;
- case (int)GasBaseShape.ShapeType.CIRCLE:
- //圆
- GasCircle circle = Circles.Find(x => x.Id == id);
- if (circle != null)
- {
- return circle;
- }
- else
- {
- GasAITValve valve = Valves.Find(x => x.Id == id);
- if (valve != null)
- {
- return valve;
- }
- else
- {
- return null;
- }
- }
- break;
- case (int)GasBaseShape.ShapeType.TEXT:
- //文本
- GasText text = Texts.Find(x => x.Id == id);
- if (text != null)
- {
- return text;
- }
- else
- {
- return null;
- }
- break;
- default:
- return null;
- }
- }
- //根据位置找元件
- public GasBaseShape GetShapeByPosition(double x, double y)
- {
- foreach (GasBaseShape shape in Analogs)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- foreach (GasBaseShape shape in Valves)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- foreach (GasBaseShape shape in Buttons)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- foreach (GasBaseShape shape in Texts)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- foreach (GasBaseShape shape in Circles)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- foreach (GasBaseShape shape in Funnels)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- foreach (GasBaseShape shape in Lines)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- foreach (GasBaseShape shape in PolyLines)
- {
- if (shape.Contains(x, y))
- {
- return shape;
- }
- }
- return null;
- }
- }
- }
|