private void button1_Click(object sender, RoutedEventArgs e) { int ret_val; double zero_flow_tolerance = 0.005; //value below which it is assumed that the flow is zero double head_diff_tolerance = 0.2; //if flow path contstructing algorithm arrives at logger's neighbour, it is assumed that it has arrinved at this logger ony if absolute head difference between the enighbour and the logger is smaller than this value WaterNetwork water_network = new WaterNetwork(); //ret_val = Epanet.SimulateInEpanet(); //ret_val = Epanet.ReadEpanetResults(water_network); IO io_object = new IO(); ret_val = io_object.ReadEpanetDll_WindowApp(water_network, false); water_network.GenerateNeighboursLists(zero_flow_tolerance); //TEMP!!! EFavorTest efavor_test = new EFavorTest(); OpenFileDialog file_dialog = new OpenFileDialog(); file_dialog.InitialDirectory = Settings.Default.path; file_dialog.FileName = "EFavor_test_fake.xls"; file_dialog.ShowDialog(); efavor_test.LoadEFavorData(file_dialog.FileName, water_network); List <Valve> inlet_valves = efavor_test.list_of_inlet_flowmeters.ConvertAll <Valve>(new Converter <FlowMeter, Valve>(FlowMeter.GetValve)); //TODO!!!update valve.setting based on FlowMeter.prv_settings, to do so ask efavor object for time_step_pressure_stepping and IO object for hydraulic step (using EN) (and other times if needed) inlet_valves[0].setting = new double[5] { 20, 30, 40, 50, 60 }; //!!!TEMP!!! //inlet_valves[0].setting = new double[6] { 30, 30, 30, 30, 30, 30 }; //!!!TEMP!!! io_object.SimulateUpdateHeadsFlows(water_network, inlet_valves, 1 * 60, 5 * 60, 60); //io_object.SimulateUpdateHeadsFlows(water_network, inlet_valves, 50, 340, 60); io_object.CloseENHydAnalysis(); io_object.CloseENToolkit(); //MessageBox.Show("Nodes: " + water_network.nNodes + " Pipes: " + water_network.nLinks); List <Node> inlet_nodes = efavor_test.list_of_inlet_loggers.ConvertAll <Node>(new Converter <Logger, Node>(Logger.GetLoggerNode)); FlowTree flow_tree = new FlowTree(water_network, inlet_nodes); flow_tree.GenerateFlowTree(); LoggerConnections logger_connections = new LoggerConnections(efavor_test.list_of_loggers, flow_tree); logger_connections.CalculatePathsBetweenLoggers(head_diff_tolerance); logger_connections.LoggerConn2WaterNet(efavor_test, efavor_test.list_of_inlet_set_ids[0]); List <List <Node> > dupa = logger_connections.GetAllPathsBetweenLoggers("6", "5"); return; }
/// <summary>!!!relies on specific coding of logger connection names!!! /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e) { List <Tuple <string, double, double> > listJustSelected = new List <Tuple <string, double, double> >(e.AddedItems.Cast <Tuple <string, double, double> >()); List <Tuple <string, double, double> > listJustUnselected = new List <Tuple <string, double, double> >(e.RemovedItems.Cast <Tuple <string, double, double> >()); MainWindow mainWindow = (MainWindow)this.Owner; LoggerConnections loggerConnections = mainWindow.loggerConnections; int error; if (loggerConnections.logger_water_network == null) //check if logger_water_network exists (it should at this stage!) { error = loggerConnections.LoggerConn2WaterNet(mainWindow.efavorTest, mainWindow.inletSetSelectionComboBox.SelectedValue.ToString(), true); loggerConnections.logger_water_network.isPlotted = true; error = mainWindow.DrawWaterNetwork(); } //unselected: foreach (Tuple <string, double, double> currentTuple in listJustUnselected) { string loggerName = currentTuple.Item1; int loggerIndex = loggerConnections.list_of_loggers.FindIndex(tmp => tmp.logger_id == loggerName); if (loggerIndex < 0) { MessageBox.Show("Can't find logger " + loggerName); return; } //connections outgoing from this logger: for (int i = 0; i < loggerConnections.list_of_loggers.Count; i++) { if (loggerConnections.logger_connection_matrix[loggerIndex, i] == true) { Link linkTemp = loggerConnections.logger_water_network.listOfLinks.Find(tmp => tmp.name == "L" + loggerName + "-" + loggerConnections.list_of_loggers[i].logger_id); if (linkTemp == null) { MessageBox.Show("Can't find connection from logger " + loggerName + " to logger " + loggerConnections.list_of_loggers[i].logger_id); return; } var alreadyInList = mainWindow.pathHitList.Find(tmp => tmp.Tag == linkTemp); // make sure that this logger connection is already in pathHitList if (alreadyInList != null) //add if yes unselect it { mainWindow.ChangeLinkApperance(linkTemp, linkTemp.color, linkTemp.thickness - UI.Default.SelectionLinkThickness); mainWindow.pathHitList.Remove(alreadyInList); //MessageBox.Show(linkTemp.name + " unselected"); } } } //connections incoming to this logger: for (int i = 0; i < loggerConnections.list_of_loggers.Count; i++) { if (loggerConnections.logger_connection_matrix[i, loggerIndex] == true) { Link linkTemp = loggerConnections.logger_water_network.listOfLinks.Find(tmp => tmp.name == "L" + loggerConnections.list_of_loggers[i].logger_id + "-" + loggerName); if (linkTemp == null) { MessageBox.Show("Can't find connection from logger " + loggerConnections.list_of_loggers[i].logger_id + " to logger " + loggerName); return; } var alreadyInList = mainWindow.pathHitList.Find(tmp => tmp.Tag == linkTemp); // make sure that this logger connection is already in pathHitList if (alreadyInList != null) //add if yes unselect it { mainWindow.ChangeLinkApperance(linkTemp, linkTemp.color, linkTemp.thickness - UI.Default.SelectionLinkThickness); mainWindow.pathHitList.Remove(alreadyInList); //MessageBox.Show(linkTemp.name + " unselected"); } } } } //just selected: foreach (Tuple <string, double, double> currentTuple in listJustSelected) { string loggerName = currentTuple.Item1; int loggerIndex = loggerConnections.list_of_loggers.FindIndex(tmp => tmp.logger_id == loggerName); if (loggerIndex < 0) { MessageBox.Show("Can't find logger " + loggerName); return; } //connections outgoing from this logger: for (int i = 0; i < loggerConnections.list_of_loggers.Count; i++) { if (loggerConnections.logger_connection_matrix[loggerIndex, i] == true) { Link linkTemp = loggerConnections.logger_water_network.listOfLinks.Find(tmp => tmp.name == "L" + loggerName + "-" + loggerConnections.list_of_loggers[i].logger_id); if (linkTemp == null) { MessageBox.Show("Can't find connection from logger " + loggerName + " to logger " + loggerConnections.list_of_loggers[i].logger_id); return; } var alreadyInList = mainWindow.pathHitList.Find(tmp => tmp.Tag == linkTemp); // check whether logger connection is already in pathHitList if (alreadyInList == null) //add if not { mainWindow.ChangeLinkApperance(linkTemp, linkTemp.color, linkTemp.thickness + UI.Default.SelectionLinkThickness); mainWindow.pathHitList.Add((System.Windows.Shapes.Path)linkTemp.graphicalObject); //MessageBox.Show(linkTemp.name + " selected"); } } } //connections incoming to this logger: for (int i = 0; i < loggerConnections.list_of_loggers.Count; i++) { if (loggerConnections.logger_connection_matrix[i, loggerIndex] == true) { Link linkTemp = loggerConnections.logger_water_network.listOfLinks.Find(tmp => tmp.name == "L" + loggerConnections.list_of_loggers[i].logger_id + "-" + loggerName); if (linkTemp == null) { MessageBox.Show("Can't find connection from logger " + loggerConnections.list_of_loggers[i].logger_id + " to logger " + loggerName); return; } var alreadyInList = mainWindow.pathHitList.Find(tmp => tmp.Tag == linkTemp); // check whether logger connection is already in pathHitList if (alreadyInList == null) //add if not { mainWindow.ChangeLinkApperance(linkTemp, linkTemp.color, linkTemp.thickness + UI.Default.SelectionLinkThickness); mainWindow.pathHitList.Add((System.Windows.Shapes.Path)linkTemp.graphicalObject); //MessageBox.Show(linkTemp.name + " selected"); } } } } }
private void button_calcLogConnections_Click(object sender, RoutedEventArgs e) { try { MainWindow mainWindow = (MainWindow)this.Owner; List <Node> local_inlet_nodes = new List <Node>(); //check which selected nodes are inlet by comparing to inlet_nodes if ((inletNodes != null) && (inletNodes.Count > 0)) { foreach (Node node in inletNodes) { if (!mainWindow.rectangleHitList.Any(tmp => ((Node)tmp.Tag) == node)) //check if this node is in selected nodes list { //no if (MessageBox.Show("Node " + node.name + " is at the outlet of PRV but has not been selected as logger. Do you want to add this node to list of inlet loggers", "Inlet logger missed?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { //user wants to add this node to list of inlet loggers mainWindow.rectangleHitList.Add(node.graphicalObject); mainWindow.ChangeNodeApperance(node, mainWindow.ToBrush(UI.Default.SelectionNodeColor), UI.Default.SelectionNodeSize); local_inlet_nodes.Add(node); textBox_nAllocatedLog.Text = mainWindow.rectangleHitList.Count.ToString(); } } else //yes { local_inlet_nodes.Add(node); } } } else { throw new Exception("List of inlet nodes unexpectedly empty!"); } if (local_inlet_nodes.Count == 0) { throw new Exception("No loggers at zone inlets have been defined!"); } //Generate loggers from selected nodes List <Logger> listLoggers = new List <Logger>(); for (int i = 0; i < mainWindow.rectangleHitList.Count; i++) { Node node = (Node)mainWindow.rectangleHitList[i].Tag; bool isInlet = local_inlet_nodes.Any(tmp => tmp == node); Logger new_logger = new Logger((i + 1).ToString(), node, isInlet); new_logger.elevation = node.elevation; listLoggers.Add(new_logger); } //check loggers proximity if ((AdvancedOptions.loggerNeighbourhoodLevel > 1) && (LoggerConnections.CheckLoggersProximity(listLoggers))) { if (MessageBox.Show("There are some loggers next to each other and with head difference smaller than the tolerance parameter, but the logger neighbourhood parameter is greater than 1. It is recommended to change the parameters or the logger locations. Do you want to continue calculating logger connections (YES), or to stop and modify the parameters (NO)?", "Continue?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } } //if path highlighting window is open close it as we're redefining all logger connections and paths if (mainWindow.pathsWindow != null) { mainWindow.pathsWindow.Close(); } //clear the list in case some logger connections were highlighed mainWindow.pathHitList.Clear(); //Generate flow tree for the loaded waterNetwork and inlets specified above FlowTree flowTree = new FlowTree(mainWindow.waterNetwork, local_inlet_nodes); int ret_val = flowTree.GenerateFlowTree(); if (ret_val < 0) { throw new Exception("Error while analysing network flow paths!"); } //Calculate and display logger connections mainWindow.loggerConnections = new LoggerConnections(listLoggers, flowTree); ret_val = mainWindow.loggerConnections.CalculatePathsBetweenLoggers(AdvancedOptions.head_diff_tolerance); if (ret_val < 0) { throw new Exception("Error while skeletonizing the network!"); } mainWindow.loggerConnections.LoggerConn2WaterNet(); mainWindow.checkbox_loggerNetworkVisibility.IsChecked = false; //uncheck and check to refresh display mainWindow.checkbox_loggerNetworkVisibility.IsChecked = true; button_saveLogLocation.IsEnabled = true; button_RemoveLoggers.IsEnabled = true; //List<Node> chuj = mainWindow.loggerConnections.GetNodesFromPathsAndSideBranchesBetweenLoggers("5", "9"); //List<Node> allPaths = mainWindow.loggerConnections.GetNodesFromAllPathsAllConnections(); //List<Node> tmpbranch = new List<Node>(); //Node thisNode = mainWindow.waterNetwork.listOfNodes.Find(tmp => tmp.name == "N15"); //mainWindow.loggerConnections.AddBranchesNotInPaths(ref tmpbranch, thisNode, allPaths); //tmpbranch = new List<Node>(); //thisNode = mainWindow.waterNetwork.listOfNodes.Find(tmp => tmp.name == "N63"); //mainWindow.loggerConnections.AddBranchesNotInPaths(ref tmpbranch, thisNode, allPaths); } catch (Exception ex) { MessageBox.Show("Error while calculating connections in logger location tool: " + ex.Message); return; } }