| | |
| | | |
| | | namespace Hydro.WinfrmUI |
| | | { |
| | | public partial class ViewBrowser : UserControl |
| | | public partial class ViewBrowserBAK : UserControl |
| | | { |
| | | public static bool LockSelect = false; |
| | | public static bool ApplyFilter = false; |
| | | #region 一、全局 |
| | | |
| | | #region 一、全局 |
| | | |
| | | #region 初始化 |
| | | |
| | | private bool _showToolBar = true; |
| | | [DisplayName("显示工具栏")] |
| | | |
| | | [DisplayName("显示工具栏")] |
| | | public bool showToolBar |
| | | { |
| | | get |
| | | { |
| | | return _showToolBar;// this.panel1==null?true:Visible; |
| | | return _showToolBar;// this.panel1==null?true:Visible; |
| | | } |
| | | set |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public ViewBrowser() |
| | | { |
| | | |
| | | this.showToolBar = false; |
| | | InitializeComponent(); |
| | | |
| | |
| | | |
| | | SetStyle(ControlStyles.SupportsTransparentBackColor, true); |
| | | BackColor = Color.Transparent; |
| | | |
| | | } |
| | | |
| | | private void MapViewer_Load(object sender, EventArgs e) |
| | | { |
| | | this.panel1.Visible = _showToolBar; |
| | | |
| | | |
| | | cb_Node_Colour.Items.Clear(); |
| | | cb_Link_Colour.Items.Clear(); |
| | |
| | | i++; |
| | | } |
| | | |
| | | |
| | | cb_Node_Colour.SelectedIndex = 0; |
| | | |
| | | cb_Link_Colour.SelectedIndex = 0; |
| | | |
| | | map.Init(TC, new DrawDelegate[] { Draw, Draw, DrawH }, new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel }); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #endregion 初始化 |
| | | |
| | | #region 对外开放,全局控制方法 |
| | | |
| | | public bool LoadData(bool isDelCache = false) |
| | | { |
| | | |
| | | if (_Template == null) return false; |
| | | if (isDelCache || _Template.network == null) |
| | | { |
| | |
| | | if (param == null) |
| | | param = new dict<string, dynamic>(); |
| | | _Template.network.LoadRepeaters(_Template.MaxLevel, param, _ViewModel, !_IsEditMode); |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | if (param == null) |
| | | param = new dict<string, dynamic>(); |
| | | _Template.network.LoadRepeaters(_Template.MaxLevel, param, _ViewModel, !_IsEditMode); |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | param = new dict<string, dynamic>(); |
| | | _Template.network.LoadRepeaters(_Template.MaxLevel, param, null, !_IsEditMode); |
| | | } |
| | | |
| | | } |
| | | //if (GlobalObject.PropertyForm != null) |
| | | //{ |
| | |
| | | // //_Template.network.MapObjects.AddUndoRedoSupport(GlobalObject.PropertyForm.propertyGrid); |
| | | //} |
| | | |
| | | |
| | | SetStartEndPoint(_Template.Node1, _Template.Node2); |
| | | |
| | | ResumeLayout(false); |
| | | return true; |
| | | } |
| | | |
| | | private Dictionary<TemplateType, bool> _ViewModel = null; |
| | | |
| | | Dictionary<TemplateType, bool> _ViewModel = null; |
| | | public void Clear() |
| | | { |
| | | _Template = null; |
| | |
| | | RotationF = 90; |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | public void SetData(Template template, dict<string, dynamic> param = null, Dictionary<TemplateType, bool> viewMode = null) |
| | | { |
| | | this.param = param; |
| | |
| | | this._ViewModel = viewMode; |
| | | |
| | | if (!LoadData()) return; |
| | | |
| | | |
| | | if (!reLoad) |
| | | { |
| | |
| | | { |
| | | OnChangeViewRotation.Invoke(Rotation, RotationF); |
| | | } |
| | | |
| | | } |
| | | |
| | | public Action<PointF> OnChangeViewCenter = null;//改变视图中心的委托 |
| | | public Action<double> OnChangeViewZoom = null;// |
| | | public Action<double, double> OnChangeViewRotation = null;// |
| | |
| | | Rotation = 0; |
| | | RotationF = 90; |
| | | |
| | | |
| | | if (_Nodes.Count > 0) |
| | | { |
| | | p.X /= _Nodes.Count; |
| | |
| | | } |
| | | |
| | | public void SetMapInvalidate() |
| | | { |
| | | { |
| | | _needPaintAll = true; |
| | | PMin_Show = ScreenToMap(new PointF(0, this.map.Height)); |
| | | PMax_Show = ScreenToMap(new PointF(this.map.Width, 0)); |
| | | _timerDraw = true; |
| | | _timerDraw = true; |
| | | } |
| | | |
| | | public void SetStartEndPoint(String node1, string node2) |
| | |
| | | _EndPoint = node2; |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | public void Set3DView(bool is3Dview, double 俯视角度) |
| | | |
| | | { |
| | |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | |
| | | |
| | | public void SetRotation(double d) |
| | | { |
| | | this.Rotation = d; |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #endregion 对外开放,全局控制方法 |
| | | |
| | | #region 重绘函数 |
| | | |
| | | bool _needPaintAll |
| | | private bool _needPaintAll |
| | | { |
| | | get |
| | | { |
| | |
| | | __needpaintall = value; |
| | | } |
| | | } |
| | | |
| | | //protected override void OnPaint(PaintEventArgs e) |
| | | //{ |
| | | // base.OnPaint(e); |
| | |
| | | // int heightOfBar = showToolBar ? 24 : 0; |
| | | // if (!showToolBar) heightOfBar = 0; |
| | | |
| | | |
| | | |
| | | // if (e.ClipRectangle != new Rectangle(this.Left, heightOfBar, this.map.Width, this.map.Height - heightOfBar - statusStrip1.Height)) return; |
| | | |
| | | |
| | | // _needPaintAll = false; |
| | | // if (buffer == null || buffer.Width != Width || buffer.Height != Height) |
| | |
| | | // //BookMark :绘制地图事件 |
| | | // Draw(bufferG, _Template); |
| | | |
| | | |
| | | |
| | | // if (_newTemplate?.network != null) Draw(bufferG, _newTemplate); |
| | | |
| | | // var r = 2f / zoom; |
| | | // if (_isDragging && DragStartPos!=new PointF(0,0) && mousePosition!=new PointF(0,0)) |
| | | // { |
| | | // label_center.Text = $"S:{DragStartPos.X}:{DragStartPos.Y} E:{mousePosition.X}:{mousePosition.Y}"; |
| | | // label_center.Text = $"S:{DragStartPos.X}:{DragStartPos.Y} E:{mousePosition.X}:{mousePosition.Y}"; |
| | | // var _lastMousePosition = DragStartPos; |
| | | // // 绘制矩形 |
| | | // var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y)); |
| | |
| | | // } |
| | | // if (_isSettingBackGroundPictur) |
| | | // { |
| | | |
| | | // var _lastMousePosition = DragStartPos; |
| | | // // 绘制矩形 |
| | | // var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y)); |
| | |
| | | |
| | | //} |
| | | |
| | | PointF[] getCurclePoints(int num) |
| | | private PointF[] getCurclePoints(int num) |
| | | { |
| | | PointF[] points = new PointF[num + 1]; |
| | | float angle = 0; |
| | |
| | | points[num] = points[0]; |
| | | return points; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | private void timer_draw_Tick(object sender, EventArgs e) |
| | | { |
| | |
| | | |
| | | // 当控件尺寸改变时,触发重绘 |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #endregion 重绘函数 |
| | | |
| | | #region 鼠标事件 |
| | | |
| | | void mapMouseDown(MouseEventArgs e) |
| | | private void mapMouseDown(MouseEventArgs e) |
| | | { |
| | | base.OnMouseDown(e); |
| | | |
| | |
| | | mousePosition = _MousePosition = ScreenToMap(new PointF(e.X, e.Y)); |
| | | if (e.Button == MouseButtons.Left && _isInsertingObject) |
| | | { |
| | | |
| | | } |
| | | else |
| | | if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.XButton2) |
| | | { |
| | | |
| | | if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Shift)//按下框选放大 |
| | | { |
| | | DragStartPos = ScreenToMap(new PointF(e.X, e.Y)); |
| | | _isDragging = true; |
| | | } |
| | | |
| | | else |
| | | { |
| | | |
| | | _lastCursor = this.Cursor; |
| | | this.Cursor = Cursors.SizeAll; |
| | | MapCenter0 = MapCenter; |
| | |
| | | } |
| | | else if (e.Button == MouseButtons.Left && _mouseState == MouseState.无) |
| | | { |
| | | |
| | | |
| | | if (ModifierKeys == Keys.Shift) |
| | | { |
| | | var point = ScreenToMap(new PointF(e.X, e.Y)); |
| | |
| | | List<NodeViewModel> nodes = selectedNodes; |
| | | foreach (NodeViewModel node in nodes) |
| | | { |
| | | |
| | | |
| | | PointF mapPos = WorldPointToMapPoint(node); |
| | | PointF currentPoint = MapToScreen(mapPos); |
| | | if (Get_dist(new PointF(e.X, e.Y), currentPoint) < 15f) |
| | | { |
| | | |
| | | |
| | | _NewNet.Nodes.AddRange(selectedNodes); |
| | | _NewNet.Links.AddRange(selectedLinks); |
| | | _isMovingObject = true; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | if (!_isMovingObject)//拖拽选择 |
| | | { |
| | | DragStartPos = ScreenToMap(new PointF(e.X, e.Y)); |
| | | _isDragging = true; |
| | | } |
| | | |
| | | } |
| | | |
| | | else if (e.Button == MouseButtons.Left && _mouseState == MouseState.设置底图范围) |
| | | { |
| | | _mouseState = MouseState.无; |
| | |
| | | mapOption0 = mapOption.Copy(); |
| | | _isRotating = true; |
| | | } |
| | | |
| | | } |
| | | |
| | | private bool IsPointInPolygon(PointF point, List<PointF> polygon) |
| | | { |
| | | int count = polygon.Count; |
| | |
| | | //if (_OperaNode == null) _OperaNode=_NewNet.Nodes[0]; |
| | | } |
| | | |
| | | bool controlDown = false; |
| | | PointF _MousePosition = new PointF(0, 0); |
| | | void mapMouseMove(MouseEventArgs e) |
| | | private bool controlDown = false; |
| | | private PointF _MousePosition = new PointF(0, 0); |
| | | |
| | | private void mapMouseMove(MouseEventArgs e) |
| | | { |
| | | //base.OnMouseMove(e); |
| | | bool needInvalidate = false; |
| | |
| | | |
| | | needInvalidate = true; |
| | | } |
| | | |
| | | |
| | | else if (_isPainting) |
| | | { |
| | | needInvalidate = true; |
| | | |
| | | |
| | | } |
| | | else if (_isPanning) |
| | | { |
| | | var vector = GetRotateVector(new PointF(e.X, e.Y), new PointF(_lastMouseX, _lastMouseY)); |
| | | MapCenter = new PointF(MapCenter.X - vector.X / Zoom.X, MapCenter.Y - vector.Y / Zoom.Y); |
| | | |
| | | |
| | | if (OnChangeViewCenter != null) |
| | | { |
| | |
| | | } |
| | | |
| | | needInvalidate = true; |
| | | |
| | | } |
| | | else if (_isDragging || _isDrawingPolygon || _isSettingBackGroundPictur) |
| | | { |
| | | mousePosition = _MousePosition; |
| | | // 绘制选择框 |
| | | // 绘制选择框 |
| | | // Rectangle selectionRect = new Rectangle( |
| | | // Math.Min((int)DragStartPos.X, (int)MP.X), |
| | | // Math.Min((int)DragStartPos.Y, (int)MP.Y), |
| | |
| | | // Math.Abs((int)DragStartPos.Y - (int)MP.Y)); |
| | | //DrawSelectionRect(selectionRect); |
| | | needInvalidate = true; |
| | | |
| | | } |
| | | else if (_isRotating) |
| | | { |
| | |
| | | if (RotationF > 90) RotationF = 90; |
| | | if (RotationF < 0) RotationF = 0; |
| | | needInvalidate = true; |
| | | |
| | | } |
| | | else |
| | | |
| | |
| | | |
| | | //GlobalObject.PropertyForm.propertyGrid.Refresh(); |
| | | needInvalidate = true; |
| | | |
| | | |
| | | } |
| | | //else |
| | | /*判断是否触碰到对象*/ |
| | |
| | | obj.Hovered = true; |
| | | hoveredObjs.Add(obj); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | if (needInvalidate) this.SetMapInvalidate(); |
| | | if (OnChangeMonseClickPostion != null) |
| | |
| | | _lastMouseX = e.X; |
| | | _lastMouseY = e.Y; |
| | | } |
| | | |
| | | public Action<int, int, PointF> OnChangeMonseClickPostion = null; |
| | | |
| | | bool RectangContain(RectangleF r, PointF p) |
| | | private bool RectangContain(RectangleF r, PointF p) |
| | | { |
| | | var x = p.X; var y = p.Y; |
| | | |
| | | |
| | | if (r.X <= x && x < r.X + r.Width && r.Y <= y) |
| | | { |
| | |
| | | /// <summary> |
| | | /// 用于绘制管线 |
| | | /// </summary> |
| | | NodeViewModel _select_junction1 = null; |
| | | NodeViewModel _select_junction2 = null; |
| | | DateTime _lastMouseUp = DateTime.Now; |
| | | int doubleClick_Delay = 500;//毫秒 |
| | | bool recordView = false; |
| | | void mapMouseUp(MouseEventArgs e) |
| | | private NodeViewModel _select_junction1 = null; |
| | | |
| | | private NodeViewModel _select_junction2 = null; |
| | | private DateTime _lastMouseUp = DateTime.Now; |
| | | private int doubleClick_Delay = 500;//毫秒 |
| | | private bool recordView = false; |
| | | |
| | | private void mapMouseUp(MouseEventArgs e) |
| | | { |
| | | //BookMark :鼠标抬起事件 |
| | | base.OnMouseUp(e); |
| | |
| | | _isDragging = false; |
| | | |
| | | this.Cursor = _lastCursor; |
| | | |
| | | |
| | | var _lastMousePosition = DragStartPos; |
| | | |
| | |
| | | NodeViewModel minNode = null; |
| | | foreach (NodeViewModel node in nodes) |
| | | { |
| | | |
| | | |
| | | PointF mapPos = WorldPointToMapPoint(node); |
| | | PointF currentPoint = MapToScreen(mapPos); |
| | | float currentDist = 0; |
| | |
| | | |
| | | if (ModifierKeys != Keys.Alt && minNode != null) |
| | | { |
| | | |
| | | var p1 = (PointF3D)_undoOldValue; |
| | | var p2 = minNode.Position3D; |
| | | var dd = _newTemplate.OffSet; |
| | | dx = p2.X - p1.X; |
| | | dy = p2.Y - p1.Y; |
| | | dz = p2.Z - p1.Z; |
| | | |
| | | |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | dx = dd.X; //p2.X - p1.X; |
| | | dy = dd.Y;// p2.Y - p1.Y; |
| | | dz = dd.Z;// p2.Z - p1.Z; |
| | | |
| | | } |
| | | |
| | | |
| | | net.Nodes.ForEach(n => { ((NodeViewModel)n).Position3D = new PointF3D(n.X + dx, n.Y + dy, n.Elev + dz); }); |
| | | |
| | |
| | | n.Selected = true; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | SetMapInvalidate(); |
| | | // 结束绘制多边形 |
| | |
| | | NodeViewModel minNode = null; |
| | | foreach (NodeViewModel node in nodes) |
| | | { |
| | | |
| | | |
| | | PointF mapPos = WorldPointToMapPoint(node); |
| | | PointF currentPoint = MapToScreen(mapPos); |
| | | float currentDist = 0; |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (ModifierKeys != Keys.Alt && minNode != null) |
| | | { |
| | |
| | | n = _Network.AddJunction(p, z); |
| | | MapObjectExtensions.AddCommand(_Network, "Add", null, new List<IBaseViewModel>() { n }); |
| | | break; |
| | | |
| | | case MouseState.新建水表: |
| | | getPointAndHeight(e, out p, out z); |
| | | n = _Network.AddMeter(p); |
| | | MapObjectExtensions.AddCommand(_Network, "Add", null, new List<IBaseViewModel>() { n }); |
| | | break; |
| | | |
| | | case MouseState.新建水库: |
| | | getPointAndHeight(e, out p, out z); |
| | | n = _Network.AddReservoir(p); |
| | | MapObjectExtensions.AddCommand(_Network, "Add", null, new List<IBaseViewModel>() { n }); |
| | | break; |
| | | |
| | | case MouseState.新建水池: |
| | | getPointAndHeight(e, out p, out z); |
| | | n = _Network.AddTank(p); |
| | | MapObjectExtensions.AddCommand(_Network, "Add", null, new List<IBaseViewModel>() { n }); |
| | | break; |
| | | |
| | | case MouseState.新增管线: |
| | | case MouseState.新增立管: |
| | | case MouseState.新建水泵: |
| | |
| | | getPointAndHeight(e, out p, out z); |
| | | Set_junction1(e); |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | getPointAndHeight(e, _select_junction1, out p, out z); |
| | | var l = AddLink(new PointF(e.X, e.Y), isdoubleClick, p, z); |
| | | if (l.Count > 0) MapObjectExtensions.AddCommand(_Network, "Add", null, l); |
| | | |
| | | } |
| | | |
| | | } |
| | | break; |
| | | } |
| | |
| | | if (isJunction) _OperaNode = (NodeViewModel)obj; |
| | | mousePosition = new PointF(0, 0); |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | var selectedObjs = new List<IBaseViewModel>(); |
| | | for (int i = 0; i < _Nodes.Count; i++) |
| | | { |
| | | |
| | | var node = _Nodes[i] as NodeViewModel; |
| | | if (!node.Visible) continue; |
| | | PointF p = WorldPointToMapPoint(node); |
| | |
| | | if (RectangContain(rectangle0, p)) |
| | | { |
| | | selectedObjs.Add(node); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | if /*叠加框选*/(isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.Control) |
| | | { |
| | | |
| | | _isDragging = false; |
| | | Cursor = Cursors.Default; |
| | | |
| | |
| | | var rectangle0 = new RectangleF(start, size); |
| | | for (int i = 0; i < _Nodes.Count; i++) |
| | | { |
| | | |
| | | var node = _Nodes[i] as NodeViewModel; |
| | | if (!node.Visible) continue; |
| | | PointF p = WorldPointToMapPoint(node); |
| | |
| | | node.Selected = true; |
| | | selectedObjs.Add(node); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | // GlobalObject.PropertyForm.SetObjs(selectedObjs); |
| | | _OperaNode = null; |
| | | |
| | | |
| | | SetMapInvalidate(); |
| | | mousePosition = new PointF(0, 0); |
| | | |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | SetMapInvalidate(); |
| | | } |
| | | return; |
| | | |
| | | |
| | | } |
| | | |
| | | if (/*叠加点选*/!isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.Control) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void getPointAndHeight(MouseEventArgs e, out PointF p, out float z) |
| | | { |
| | | z = 0; |
| | | if (RotationF != 0) |
| | | { |
| | | p = MapPointToWorldPoint(ScreenToMap(new PointF(e.X, e.Y), z)); |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | p = new PointF(m.X, 0); |
| | | } |
| | | } |
| | | |
| | | private void getPointAndHeight(MouseEventArgs e, NodeViewModel j, out PointF p, out float z) |
| | | { |
| | | z = j.Elev; |
| | | if (RotationF != 0) |
| | | { |
| | | p = MapPointToWorldPoint(ScreenToMap(new PointF(e.X, e.Y), j.Elev), j.Elev); |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | p = new PointF(j.X, j.Y); |
| | | } |
| | | } |
| | | IBaseViewModel GetObj_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) |
| | | |
| | | private IBaseViewModel GetObj_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) |
| | | { |
| | | float minDist = float.MaxValue; |
| | | |
| | |
| | | return obj; |
| | | } |
| | | |
| | | List<IBaseViewModel> GetObjs_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) |
| | | private List<IBaseViewModel> GetObjs_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) |
| | | { |
| | | float minDist = float.MaxValue; |
| | | |
| | |
| | | //float dist = Get_dist(clickedPoint, currentPoint); |
| | | if (dist < minDist && dist <= DistLimit) |
| | | { |
| | | |
| | | |
| | | objs.Add(link); |
| | | } |
| | | } |
| | |
| | | /// 鼠标滚轮事件 |
| | | /// </summary> |
| | | /// <param name="e"></param> |
| | | void mapMouseWheel(MouseEventArgs e) |
| | | private void mapMouseWheel(MouseEventArgs e) |
| | | { |
| | | base.OnMouseWheel(e); |
| | | mapOption0 = mapOption.Copy(); |
| | |
| | | |
| | | private int _lastMouseX; |
| | | private int _lastMouseY; |
| | | #endregion |
| | | |
| | | #endregion 鼠标事件 |
| | | |
| | | #endregion 一、全局 |
| | | |
| | | #region 二、工具栏 |
| | | |
| | | |
| | | #region 视角工具 |
| | | |
| | | // 显示点属性 |
| | | private void ShowProperties(IBaseViewModel obj) |
| | | { |
| | |
| | | { |
| | | // GlobalObject.PropertyForm.SetObj(MapCenter); |
| | | } |
| | | double 俯视角度_bak = 45; |
| | | |
| | | private double 俯视角度_bak = 45; |
| | | |
| | | private void tool视角_ButtonClick(object sender, EventArgs e) |
| | | { |
| | | mapOption0 = mapOption.Copy(); |
| | |
| | | { |
| | | 俯视角度_bak = RotationF; |
| | | RotationF = 90; |
| | | |
| | | } |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | SetMapInvalidate(); |
| | |
| | | RotationF = jiaodu; |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | public void 重置视角ToolStripMenuItem_Click(object sender, EventArgs e) |
| | |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 正视图ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | mapOption0 = mapOption.Copy(); |
| | |
| | | |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 俯视图ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | mapOption0 = mapOption.Copy(); |
| | |
| | | |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 默认视角ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | |
| | | mapOption0 = mapOption.Copy(); |
| | | |
| | | InitCenter(); |
| | |
| | | |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 设为隐藏ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | selectedObjs.ForEach(v => |
| | |
| | | MapObjectExtensions.AddCommand(v, "Visible", v.Visible, false); |
| | | v.Visible = false; |
| | | } |
| | | |
| | | }); |
| | | |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 设置长度ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | //double length = 0; |
| | |
| | | //{ |
| | | // if (double.TryParse(input.ShowDialog(), out length)) |
| | | // { |
| | | |
| | | // var count1 = _Links.FindAll(ll => ll.Node1 == l.StartNode.ID || ll.Node2 == l.StartNode.ID).Count; |
| | | // var count2 = _Links.FindAll(ll => ll.Node1 == l.EndNode.ID || ll.Node2 == l.EndNode.ID).Count; |
| | | // if (count1 > 1 && count2 <= 1) |
| | |
| | | |
| | | //} |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //this.SetMapInvalidate(); |
| | | } |
| | | void MovePointbyLength(NodeViewModel node1, NodeViewModel node2, float Length) |
| | | { |
| | | |
| | | private void MovePointbyLength(NodeViewModel node1, NodeViewModel node2, float Length) |
| | | { |
| | | float distance = Vector3.Distance(new Vector3(node1.X, node1.Y, node1.Elev), new Vector3(node2.X, node2.Y, node2.Elev)); |
| | | |
| | | if (distance > 0) |
| | |
| | | //Console.WriteLine("移动后点 B 的坐标为 ({0}, {1}, {2})", x2, y2, z2); |
| | | } |
| | | } |
| | | |
| | | private void 全部显示ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Nodes.Select(n => (NodeViewModel)n).ToList().ForEach(v => |
| | |
| | | }); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | #endregion |
| | | |
| | | #endregion 视角工具 |
| | | |
| | | #region 文件工具 |
| | | |
| | | public void OpenFile(string filePath) |
| | | { |
| | | _Template = new Template(); |
| | | _Template.network = new MapViewNetWork(); |
| | | |
| | | |
| | | |
| | | |
| | | // 读取文件内容 |
| | | _Network.BuildFromInp(filePath); |
| | | _Template.filePath = filePath; |
| | | //_filePath = filePath; |
| | | SetData(_Template); |
| | | |
| | | } |
| | | |
| | | private void tool打开_ButtonClick(object sender, EventArgs e) |
| | | { |
| | | |
| | | // 创建打开文件对话框 |
| | | OpenFileDialog openFileDialog = new OpenFileDialog(); |
| | | openFileDialog.Filter = "INP Files (*.inp)|*.inp|All Files (*.*)|*.*"; |
| | |
| | | { |
| | | _Template = new Template(); |
| | | _Template.network = new MapViewNetWork(); |
| | | |
| | | |
| | | //_Template.network.use_old = false; |
| | | // 获取选中文件的文件路径 |
| | |
| | | //private void 旧版打开ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | //{ |
| | | // // 创建打开文件对话框 |
| | | |
| | | |
| | | |
| | | // _Template = new Template(); |
| | | // _Template.network = new MapViewNetWork(); |
| | |
| | | if (message.show("提醒", "浏览模式无法保存,是否恢复为编辑模式")) |
| | | { |
| | | _IsEditMode = true; |
| | | |
| | | } |
| | | else |
| | | return; |
| | |
| | | |
| | | private void toolStripButton_save_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void 另存ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | private void 导出形状ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #endregion 文件工具 |
| | | |
| | | #region 绘图工具 |
| | | |
| | |
| | | _mouseState = MouseState.新增节点; |
| | | Cursor = Cursors.Cross; |
| | | } |
| | | |
| | | public void NewLink() |
| | | { |
| | | _mouseState = MouseState.新增管线; |
| | | Cursor = Cursors.Cross; |
| | | } |
| | | |
| | | public void NewVerticalLink() |
| | | { |
| | | _mouseState = MouseState.新增立管; |
| | | Cursor = Cursors.Cross; |
| | | } |
| | | |
| | | public void ResetOperateStatus() |
| | | { |
| | | _mouseState = MouseState.无; |
| | | Cursor = Cursors.Cross; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | private List<IBaseViewModel> AddLink(PointF e, bool isdoubleClick, PointF p, float z) |
| | | { |
| | |
| | | _select_junction1 = null; |
| | | _select_junction2 = null; |
| | | _isPainting = false; |
| | | |
| | | |
| | | } |
| | | return l; |
| | | } |
| | |
| | | _isPainting = true; |
| | | } |
| | | } |
| | | |
| | | public void NewWaterMeter() |
| | | { |
| | | _mouseState = MouseState.新建水表; |
| | |
| | | _mouseState = MouseState.新建水泵; |
| | | Cursor = Cursors.Cross; |
| | | } |
| | | |
| | | public void NewValve() |
| | | { |
| | | _mouseState = MouseState.新建阀门; |
| | | Cursor = Cursors.Cross; |
| | | } |
| | | |
| | | public void NewRepeater() |
| | | { |
| | | _mouseState = MouseState.新建重复器; |
| | | Cursor = Cursors.Cross; |
| | | } |
| | | |
| | | public void toolStripButton_添加水表_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | public void toolStripButton_添加阀门_Click(object sender, EventArgs e) |
| | | { |
| | | { |
| | | } |
| | | |
| | | public void toolStripButton_添加水泵_Click(object sender, EventArgs e) |
| | | { |
| | | { |
| | | } |
| | | |
| | | public void toolStripButton_添加水库_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | public void toolStripButton_添加水池_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | public void toolStripButton_重复器_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | bool Buzylock = false; |
| | | private bool Buzylock = false; |
| | | |
| | | private void MapViewer_KeyDown(object sender, KeyEventArgs e) |
| | | { |
| | | |
| | | if (e.KeyCode == Keys.Escape) |
| | | { |
| | | Cursor = _lastCursor; |
| | |
| | | _Links.ForEach(o => ((LinkViewModel)o).Selected = false); |
| | | selectedObjs.Clear(); |
| | | SetMapInvalidate(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | if (e.KeyCode == Keys.Delete) |
| | | { |
| | |
| | | if (e.KeyCode == Keys.D1 && e.Modifiers == Keys.Control) |
| | | { |
| | | 南北对齐ToolStripMenuItem_Click(1, new EventArgs()); |
| | | |
| | | } |
| | | if (e.KeyCode == Keys.Oemtilde && e.Modifiers == Keys.Control) |
| | | { |
| | |
| | | 自动对齐ToolStripMenuItem_Click(1, new EventArgs()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | private void MapViewer_KeyPress(object sender, KeyPressEventArgs e) |
| | | { |
| | |
| | | e.Handled = true; |
| | | } |
| | | } |
| | | |
| | | private void MapViewer_PreKeyPress(object sender, PreviewKeyDownEventArgs e) |
| | | { |
| | | if (e.Control && e.KeyCode == Keys.Z) |
| | |
| | | ctrlPressed = true; |
| | | // 防止默认操作 |
| | | e.IsInputKey = true; |
| | | |
| | | } |
| | | if (e.Control && e.KeyCode == Keys.Y) |
| | | { |
| | | ctrlPressed = true; |
| | | // 防止默认操作 |
| | | e.IsInputKey = true; |
| | | |
| | | } |
| | | if (e.Control && e.KeyCode == Keys.R) |
| | | { |
| | | ctrlPressed = true; |
| | | // 防止默认操作 |
| | | e.IsInputKey = true; |
| | | |
| | | } |
| | | } |
| | | |
| | | public void setCenter(IBaseViewModel obj) |
| | | { |
| | | PointF position; |
| | |
| | | MapCenter.Y - vector.Y / Zoom.Y); |
| | | } |
| | | |
| | | bool ctrlPressed = false; |
| | | #endregion |
| | | private bool ctrlPressed = false; |
| | | |
| | | #endregion 绘图工具 |
| | | |
| | | #region 右键菜单 |
| | | |
| | | |
| | | private void 转换ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | } |
| | | junc.ID = ID; |
| | | break; |
| | | |
| | | case "基本节点": |
| | | |
| | | junc = _Network.AddJunction(obj.Position, obj.Elev); |
| | |
| | | } |
| | | junc.ID = ID; |
| | | break; |
| | | |
| | | case "水库": |
| | | junc = _Network.AddReservoir(obj.Position); |
| | | i = 0; |
| | |
| | | } |
| | | junc.ID = ID; |
| | | break; |
| | | |
| | | case "水池": |
| | | junc = _Network.AddTank(obj.Position); |
| | | i = 0; |
| | |
| | | junc.Elev = obj.Elev; |
| | | junc.Demand = obj.Demand; |
| | | |
| | | |
| | | junc.Selected = true; |
| | | foreach (var p in _Links) |
| | | { |
| | | if (p.StartNode == obj) |
| | | { |
| | | p.StartNode = junc; |
| | | |
| | | } |
| | | else if (p.EndNode == obj) |
| | | { |
| | |
| | | //MapObjectExtensions.AddCommand(obj, "Add", null, new List<MapObject>() { n }); |
| | | _Nodes.Remove(obj); |
| | | } |
| | | |
| | | |
| | | SetMapInvalidate(); |
| | | } |
| | |
| | | selectedObjs.Clear(); |
| | | SetMapInvalidate(); |
| | | } |
| | | #endregion |
| | | |
| | | #endregion 右键菜单 |
| | | |
| | | #region 编辑模式/浏览模式切换工具 |
| | | |
| | | |
| | | |
| | | private void toolStripComboBox_expandRepeater_ButtonClick(object sender, EventArgs e) |
| | | { |
| | |
| | | //toolStripComboBox_浏览模式.Text = isEditMode ? "编辑模式" : "浏览模式"; |
| | | LoadData(true); |
| | | } |
| | | #endregion |
| | | |
| | | #endregion 编辑模式/浏览模式切换工具 |
| | | |
| | | /// <summary> |
| | | /// 工具栏可用 |
| | |
| | | |
| | | private void 水平旋转ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | //var objs = GlobalObject.PropertyForm.selectionSet.selectedObjects; |
| | | //var selectobjs = objs.FindAll(o => o is NodeViewModel); //GlobalObject.PropertyForm.listBox1.SelectedItems; |
| | | //if (selectobjs.Count <= 0) return; |
| | |
| | | //MapObjectExtensions.AddCommand(nodes, "Position", OldPositions, NewPositions); |
| | | |
| | | //SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | public List<PointF> GetRotatedPoints(List<PointF> points, PointF origin, float angle) |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | public List<PointF3D> GetRotatedPoints(List<PointF3D> points, Vector3 line, float angle) |
| | | { |
| | |
| | | |
| | | private void 缩放ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | //var objs = GlobalObject.PropertyForm.selectionSet.selectedObjects; |
| | | //var list = objs.FindAll(o => o is NodeViewModel); //GlobalObject.PropertyForm.listBox1.SelectedItems; |
| | | //if (list.Count <= 0) return; |
| | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public void toolStripButton_计算_Click(object sender, EventArgs e) |
| | | { |
| | | //LoadData(); |
| | | |
| | | } |
| | | |
| | | public void 关阀搜索ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l |
| | | { |
| | | |
| | | var objs = selectedObjs.ToList(); |
| | | var selectsValve = objs.FindAll(o => o is ValveViewModel); |
| | | selectedObjs.ForEach(o => o.Selected = false); |
| | |
| | | selectsValve.ForEach(o => o.Selected = false); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关阀分析(考虑水源的情况) |
| | | /// </summary> |
| | |
| | | { |
| | | if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l |
| | | { |
| | | |
| | | var objs = selectedObjs.ToList(); |
| | | var selectsValve = objs.FindAll(o => o is ValveViewModel); |
| | | selectedObjs.ForEach(o => o.Selected = false); |
| | |
| | | TraversePipeNetwork(objs, null); |
| | | selectsValve.ForEach(o => o.Selected = false); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | } |
| | | |
| | | //Queue<Link> queue2 = null; |
| | | List<LinkViewModel> LinksToFindSource = null; |
| | | Dictionary<LinkViewModel, List<IBaseViewModel>> Sets = null; |
| | | Dictionary<LinkViewModel, bool> Sets_hasSource = null; |
| | | private List<LinkViewModel> LinksToFindSource = null; |
| | | |
| | | private Dictionary<LinkViewModel, List<IBaseViewModel>> Sets = null; |
| | | private Dictionary<LinkViewModel, bool> Sets_hasSource = null; |
| | | |
| | | private void TraversePipeNetwork(List<IBaseViewModel> startObjs, HashSet<NodeViewModel> visitedNodes = null, bool consider = true) |
| | | { |
| | | |
| | | LinksToFindSource = new List<LinkViewModel>(); |
| | | |
| | | if (visitedNodes == null) |
| | |
| | | else if (o is NodeViewModel n) |
| | | { |
| | | n.Links.Select(oo => oo as LinkViewModel).ToList().ForEach(link => TraversePipeNetwork(link, visitedNodes)); |
| | | |
| | | } |
| | | }); |
| | | if (!consider) return; |
| | |
| | | o.Selected = true; |
| | | selectedObjs.Add(o); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | } |
| | | //if (GlobalObject.PropertyForm != null) |
| | | // GlobalObject.PropertyForm.SetObjs(selectedObjs); |
| | | |
| | | } |
| | | |
| | | private void TraversePipeNetwork(LinkViewModel startLink, HashSet<NodeViewModel> visitedNodes = null) |
| | | { |
| | | |
| | | Queue<LinkViewModel> queue = new Queue<LinkViewModel>(); |
| | | |
| | | |
| | | |
| | | queue.Enqueue(startLink); |
| | | if (visitedNodes == null) |
| | |
| | | link.Selected = true; |
| | | selectedObjs.Add(link); |
| | | |
| | | |
| | | if (!(link is ValveViewModel)) |
| | | { |
| | | queue.Enqueue(link); |
| | | |
| | | } |
| | | else |
| | | { |
| | | LinksToFindSource.Add(link); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void TraversePipeNetwork_Set(LinkViewModel startLink, HashSet<NodeViewModel> visitedNodes = null) |
| | | { |
| | | |
| | | Queue<LinkViewModel> queue = new Queue<LinkViewModel>(); |
| | | |
| | | |
| | | |
| | | |
| | | queue.Enqueue(startLink); |
| | | if (visitedNodes == null) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private bool FindSouce(LinkViewModel startLink, HashSet<LinkViewModel> visitedLinks, HashSet<LinkViewModel> visitedLinks2, Dictionary<IBaseViewModel, bool> hasSource = null) |
| | | { |
| | | |
| | | |
| | | foreach (var node in new NodeViewModel[] { startLink.StartNode, startLink.EndNode }) |
| | | { |
| | | |
| | | if (!hasSource.ContainsKey(node)) |
| | | { |
| | | //hasSource.Add(node, false); |
| | |
| | | } |
| | | |
| | | if (hasSource[node] == true) return true; |
| | | |
| | | |
| | | } |
| | | return false; |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private bool FindSouce(NodeViewModel startNode, HashSet<LinkViewModel> visitedLinks, HashSet<LinkViewModel> visitedLinks2, Dictionary<IBaseViewModel, bool> hasSource = null) |
| | | { |
| | | |
| | | foreach (var link in startNode.ViewLinks) |
| | | { |
| | | if (hasSource.ContainsKey(link) && hasSource[link] == true) return true; |
| | |
| | | visitedLinks2.Add(link); |
| | | if (!hasSource.ContainsKey(link)) |
| | | { |
| | | |
| | | //hasSource.Add(link,false); |
| | | hasSource[link] = FindSouce(link, visitedLinks, visitedLinks2, hasSource); |
| | | } |
| | | |
| | | if (hasSource[link] == true) return true; |
| | | |
| | | |
| | | } |
| | | return false; |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //private void 联通性ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | //{ |
| | | // if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l |
| | | // { |
| | | |
| | | // var objs = selectedObjs.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel).ToList(); |
| | | // var visitedNodes = new HashSet<NodeViewModel>(); |
| | | // objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes)); |
| | | |
| | | |
| | | // this.SetInvalidated(); |
| | | |
| | |
| | | //} |
| | | private void TraversePipeNetworkALL(LinkViewModel startLink, HashSet<NodeViewModel> visitedNodes = null, int direction = 0) |
| | | { |
| | | |
| | | Queue<LinkViewModel> queue = new Queue<LinkViewModel>(); |
| | | |
| | | |
| | | |
| | | queue.Enqueue(startLink); |
| | | if (visitedNodes == null) |
| | |
| | | link.Selected = true; |
| | | selectedObjs.Add(link); |
| | | queue.Enqueue(link); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #endregion 分析工具 |
| | | |
| | | #region 显示选项 |
| | | |
| | |
| | | { |
| | | _ShowValve = true; |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | private void 隐藏阀门ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _ShowValve = false; |
| | | SetMapInvalidate(); |
| | | |
| | | |
| | | } |
| | | |
| | | private void 大ToolStripMenuItem1_Click(object sender, EventArgs e) |
| | |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #endregion 显示选项 |
| | | |
| | | #endregion 二、工具栏 |
| | | |
| | | #region 方法 |
| | | |
| | | private void 标高推测ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | int num = UpdateNodesEle(); |
| | |
| | | else |
| | | { |
| | | MessageBox.Show($"没有需要更新的节点"); |
| | | |
| | | } |
| | | } |
| | | |
| | | public int UpdateNodesEle() |
| | | { |
| | | int num = 0; |
| | |
| | | if (link.StartNode == node) |
| | | { |
| | | neighbor = link.EndNode; |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void 标高导出ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | DataTable dt = new DataTable(); |
| | |
| | | } |
| | | } |
| | | dtToSql(dt); |
| | | |
| | | } |
| | | void dtToCsv(DataTable dt) |
| | | |
| | | private void dtToCsv(DataTable dt) |
| | | { |
| | | // 创建 SaveFileDialog 对象 |
| | | SaveFileDialog saveFileDialog = new SaveFileDialog(); |
| | |
| | | MessageBox.Show("文件保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); |
| | | } |
| | | } |
| | | void dtToSql(DataTable dt) |
| | | |
| | | private void dtToSql(DataTable dt) |
| | | { |
| | | // 创建 SaveFileDialog 对象 |
| | | SaveFileDialog saveFileDialog = new SaveFileDialog(); |
| | | saveFileDialog.Filter = "Txt Files (*.txt)|*.txt"; |
| | | |
| | | |
| | | // 如果用户选择了保存位置和文件名,则执行保存操作 |
| | | if (saveFileDialog.ShowDialog() == DialogResult.OK) |
| | |
| | | ); |
| | | END |
| | | |
| | | |
| | | "; |
| | | // 构建 CSV 字符串 |
| | | StringBuilder csvContent = new StringBuilder(); |
| | | |
| | | csvContent.AppendLine(tableString); |
| | | |
| | | |
| | | |
| | | //// 写入表头 |
| | | //foreach (DataColumn column in dt.Columns) |
| | | //{ |
| | | |
| | | // csvContent.Append(column.ColumnName); |
| | | // csvContent.Append(","); |
| | | //} |
| | |
| | | int j = 0; |
| | | while (i < dt.Rows.Count) |
| | | { |
| | | |
| | | if (j == 0) csvContent.AppendLine("INSERT INTO Elev (ID, Elev) VALUES"); |
| | | // 写入数据行 |
| | | |
| | |
| | | i++; |
| | | j++; |
| | | if (j == 1000) j = 0; |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | // 将 CSV 内容写入文件 |
| | | File.WriteAllText(filePath, csvContent.ToString()); |
| | |
| | | LoadData(); |
| | | } |
| | | } |
| | | |
| | | public void Undo() |
| | | { |
| | | SetMapInvalidate(); |
| | | //GlobalObject.PropertyForm.propertyGrid.Refresh(); |
| | | MapObjectExtensions.Undo(); |
| | | } |
| | | |
| | | public void Redo() |
| | | { |
| | | SetMapInvalidate(); |
| | | //GlobalObject.PropertyForm.propertyGrid.Refresh(); |
| | | MapObjectExtensions.Redo(); |
| | | } |
| | | |
| | | public void buttonUndo_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | public void buttonRedo_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | public void toolStripButton_save_ButtonClick(object sender, EventArgs e) |
| | | { |
| | | if (_Template == null) return; |
| | |
| | | |
| | | private void 以当前视角另存ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | |
| | | } |
| | | |
| | | public void SaveAs(string filePath) |
| | | { |
| | | bool isReplace = false; |
| | | _Network.BuildToInp(filePath, null, _filePath, isReplace); |
| | | bool isReplace = false; |
| | | _Network.BuildToInp(filePath, null, _filePath, isReplace); |
| | | } |
| | | |
| | | public void Save() |
| | | { |
| | | if (_Template == null) return; |
| | |
| | | { |
| | | bool isReplace = true; |
| | | //isReplace = !message.show("模板选择", "使用模板新增/替换当前文件", MessageBoxButtons.YesNo); |
| | | _Network.BuildToInp(_filePath, null, null, false); |
| | | _Network.BuildToInp(_filePath, null, null, false); |
| | | } |
| | | } |
| | | |
| | | public void SaveAsByView(string filePath) |
| | | { |
| | | if (_Template == null) return; |
| | |
| | | { |
| | | var p = WorldPointToMapPoint((NodeViewModel)n); |
| | | sb.AppendLine($"{n.ID} {p.X} {p.Y}"); |
| | | |
| | | }); |
| | | |
| | | |
| | | _Network.BuildToInp(filePath, sb.ToString(), _filePath); |
| | | } |
| | | |
| | | public void Calc() |
| | | { |
| | | _Network.Calc(_Template.FullPath, GlobalPath.configPath + "config_calc.wdb"); |
| | |
| | | { |
| | | if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l |
| | | { |
| | | |
| | | var objs = selectedObjs.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel).ToList(); |
| | | if (objs.Count == 0) selectedObjs.FindAll(o => o is NodeViewModel).Select(o => o as NodeViewModel).ToList().ForEach(o => objs.AddRange(o.Links.Select(l => l as LinkViewModel).ToList())); |
| | | //objs去掉重复的元素 |
| | |
| | | var visitedNodes = new HashSet<NodeViewModel>(); |
| | | objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes)); |
| | | |
| | | |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | } |
| | | |
| | | private void 下游连通性ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l |
| | | { |
| | | |
| | | var objs = selectedObjs.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel).ToList(); |
| | | if (objs.Count == 0) selectedObjs.FindAll(o => o is NodeViewModel).Select(o => o as NodeViewModel).ToList().ForEach(o => |
| | | { |
| | |
| | | var visitedNodes = new HashSet<NodeViewModel>(); |
| | | objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes, 1)); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | } |
| | | |
| | | public void 复制ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (hoveredObjs.Count <= 0 || !(hoveredObjs[0] is NodeViewModel)) |
| | |
| | | } |
| | | catch |
| | | { |
| | | //提醒 |
| | | } |
| | | //提醒 |
| | | } |
| | | } |
| | | |
| | | public void 粘贴ToolStripMenuItem1_Click(object sender, EventArgs e) |
| | | { |
| | | { |
| | |
| | | SetMapInvalidate(); |
| | | } |
| | | } |
| | | |
| | | private void 增量保存ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | private void 设为关闭ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | selectedObjs.ForEach(obj => { if (obj is LinkViewModel link) link.Status = Hydro.Core.ObjectEnum.StatusType.CLOSED; }); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 显示全部楼层ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | //this.mapOption.ShowFloor = int.MinValue; |
| | | _Network.MapObjects.ForEach(o => o.Visible = true); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 保存楼层视角ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | //if (_Template?.Floors!=null) |
| | |
| | | // if (fl!=null)fl.MapView = this.mapOption.Copy(); |
| | | //} |
| | | } |
| | | |
| | | public void 南北对齐ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedNodes.Count < 1) return; |
| | |
| | | MapObjectExtensions.AddCommand(selectedNodes, "X", list, list1); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | public void 东西对齐ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedNodes.Count < 1) return; |
| | |
| | | MapObjectExtensions.AddCommand(selectedNodes, "Y", list, list1); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | public void 竖直对齐ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedNodes.Count < 1) return; |
| | |
| | | MapObjectExtensions.AddCommand(selectedNodes, "Position", list, list1); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | public void 自动对齐ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedNodes.Count < 3) return; |
| | |
| | | MapObjectExtensions.AddCommand(selectedNodes, "Position3D", OldPosition3Ds, NewPosition3Ds); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | List<PointF3D> ProjectPointsToLine(List<PointF3D> points) |
| | | |
| | | private List<PointF3D> ProjectPointsToLine(List<PointF3D> points) |
| | | { |
| | | // 使用最小二乘法构造直线,并将点投影到直线上 |
| | | |
| | |
| | | 设置底图ToolStripMenuItem_Click(1, new EventArgs()); |
| | | } |
| | | } |
| | | bool _isSettingBackGroundPictur = false; |
| | | |
| | | private bool _isSettingBackGroundPictur = false; |
| | | |
| | | public void 设置底图ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | if (float.TryParse(inputValue, out float result)) |
| | | { |
| | | zoom = result; |
| | | |
| | | } |
| | | } |
| | | |
| | | private void label_file_DoubleClick(object sender, EventArgs e) |
| | | { |
| | | if (_filePath == null) return; |
| | | FileInfo fi = new FileInfo(_filePath); |
| | | Process.Start("explorer.exe", $"/select,\"{_filePath}\""); |
| | | } |
| | | |
| | | private void label_file_Click(object sender, EventArgs e) |
| | | { |
| | | if (_filePath == null) return; |
| | | FileInfo fi = new FileInfo(_filePath); |
| | | Process.Start("explorer.exe", $"/select,\"{_filePath}\""); |
| | | } |
| | | |
| | | private void 设为立管点ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedNodes.Count == 1) |
| | | { |
| | | _Template.Node2 = _EndPoint = selectedNodes[0].ID; |
| | | } |
| | | |
| | | } |
| | | |
| | | private void 显示水流ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.network.MapObjects.ForEach(o => o.Selected = false); |
| | |
| | | node = link.EndNode; |
| | | node.Selected = true; |
| | | if (!selectedObjs.Contains(node)) selectedObjs.Add(node); |
| | | |
| | | } |
| | | |
| | | }); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | private void 全选ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | selectedObjs.Clear(); |
| | |
| | | o.Selected = true; |
| | | selectedObjs.Add(o); |
| | | } |
| | | |
| | | }); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | private void 反选ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | _Template.network.MapObjects.ForEach(o => |
| | | { |
| | | if (o.Visible) |
| | |
| | | o.Selected = true; |
| | | selectedObjs.Add(o); |
| | | } |
| | | |
| | | } |
| | | |
| | | }); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 显示状态ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowStatus = true; |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 隐藏状态ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowStatus = false; |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | private void 显示流向ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowFlowDirection = true; |
| | | this.SetMapInvalidate(); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void 隐藏流向ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowFlowDirection = false; |
| | | this.SetMapInvalidate(); |
| | | |
| | | |
| | | } |
| | | |
| | | private void 方向修复ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Network.Links.ForEach(l => |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void 刷新楼层ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | ToolStripMenuItem_Floor.DropDownItems.Clear(); |
| | |
| | | var item = ToolStripMenuItem_Floor.DropDownItems.Add(i.ToString() + "楼"); |
| | | item.Click += (oo, ee) => |
| | | { |
| | | |
| | | |
| | | mapobjects.ForEach(o => |
| | | { |
| | | if (o.Tags.Contains(tagstring)) |
| | |
| | | } |
| | | }); |
| | | this.SetMapInvalidate(); |
| | | |
| | | }; |
| | | } |
| | | } |
| | |
| | | _Network.MapObjects.ForEach(o => o.Visible = true); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | public void toolStripButton_CalcMiniLoss_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | private void toolStripButton_ClearMinor_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | |
| | | private void 显示流向ToolStripMenuItem1_Click(object sender, EventArgs e) |
| | | { |
| | | _isShowDirection = !_isShowDirection; |
| | | } |
| | | bool _isShowDirection = false; |
| | | |
| | | private bool _isShowDirection = false; |
| | | |
| | | private void 颜色分级管理ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | //Form_Colour form_Colour = new Form_Colour(_Template.Colours); |
| | |
| | | _Network.Calc(_Template.FullPath, GlobalPath.configPath + "config_calc.wdb"); |
| | | _Network.CalcLinkMinorLoss(); |
| | | } |
| | | |
| | | public void ClearMinorLoss() |
| | | { |
| | | _Network.ClearMinorLoss(); |
| | | } |
| | | |
| | | private void cb_Link_Colour_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_Template == null) return; |
| | |
| | | mapOption.ColourLink = type; |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | private void cb_Node_Colour_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_Template == null) return; |
| | |
| | | mapOption.ColourNode = type; |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | |
| | | |
| | | private void 楼层管理ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | //form_EditFloors.Show(this); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #endregion 方法 |
| | | } |
| | | } |