public bool WireModel(int startX, int startY) { OnListSizeSent(_model.GetNodeCount() * 2); for (int i = 0; i < _model.GetNodeCount(); i++) { //find nodes within 6 inches Node first = _model.GetNode(i); OnProgressSent(first.ToString(), i); first.Id = i; for (int j = i + 1; j < _model.GetNodeCount(); j++) { Node second = _model.GetNode(j); int dist = ModelUtils.GetDistance(first, second); if (dist < 9) { first.CloseIds.Add(j); second.CloseIds.Add(i); } } } //OnListSizeSent() int count = 1; Node start = _model.FindNode(startX, startY); if (start == null) { return(false); } //start.NodeNumber = count; //count++; return(WireNodes(start, count)); return(true); }
private void AutoWire() { //clear old wiring _model.ClearWiring(); var x = nodesDataGridView.CurrentCell.ColumnIndex; var y = nodesDataGridView.CurrentCell.RowIndex; var num = 1; //find first cell var found = _model.FindNode(x, y); if (found == null) { MessageBox.Show("Starting Node Not Found", "Starting Node Not Found"); return; } found.NodeNumber = 1; var i = 0; while (num < _model.GetNodeCount()) { i++; var distance = 10000; Node foundnode = null; foreach (var node in _model.GetNodes()) { if (node.IsWired) { continue; } var newdist = ModelUtils.GetDistance(x, y, node.GridX, node.GridY); if (newdist < distance) { distance = newdist; foundnode = node; } } if (foundnode != null) { num++; foundnode.NodeNumber = num; x = foundnode.GridX; y = foundnode.GridY; } else { MessageBox.Show("Node is Null", "Node is Null"); break; } if (i > 10000000) { MessageBox.Show("Loop error", "Loop error"); break; } } _model.SortNodes(); listDataGridView.Refresh(); DrawGrid(); }