public void read(string fileName, Func <string, string, bool> checkNode, char nodeNameDelimiter, ref int indAvailableLine) { indAvailableLine = 0; // Reading another instance IFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { ChartsData another = (ChartsData)formatter.Deserialize(stream); List <string> anotherCharts = new List <string>(another.type.Keys); // Copying fields string[] selectionInfo; bool isLineCorrect; foreach (string chart in anotherCharts) { if (!type.ContainsKey(chart)) { continue; } // Properties type[chart] = another.type[chart]; units[chart] = another.units[chart]; direction[chart] = another.direction[chart]; normalization[chart] = another.normalization[chart]; axis[chart] = another.axis[chart]; swapAxes[chart] = another.swapAxes[chart]; dependency[chart] = another.dependency[chart]; // Selection List <ISelection> checkedSelection = new List <ISelection>(); foreach (ISelection item in another.selection[chart]) { // Nodes if (item.GetType() == typeof(Nodes)) { string fullName = (string)item.retrieveSelection(); selectionInfo = fullName.Split(nodeNameDelimiter); if (checkNode(selectionInfo[0], selectionInfo[1])) { checkedSelection.Add(item); } } // Lines if (item.GetType() == typeof(Lines)) { List <string> nodes = (List <string>)item.retrieveSelection(); isLineCorrect = true; Lines line = (Lines)item; int indLine = int.Parse(line.lineName_.Replace("Line", "")); if (indLine > indAvailableLine) { indAvailableLine = indLine; } foreach (string fullName in nodes) { selectionInfo = fullName.Split(nodeNameDelimiter); // If the current geometry contains all the specified nodes if (!checkNode(selectionInfo[0], selectionInfo[1])) { isLineCorrect = false; break; } } if (isLineCorrect) { checkedSelection.Add(item); } } } selection[chart] = checkedSelection; } } if (indAvailableLine > 0) { indAvailableLine += 1; } }
// Updating all template properties private void updateExcelTemplateList() { listBoxTemplateCharts.Items.Clear(); treeTemplateObjects.Nodes.Clear(); List <string> chartNames = excelTemplate_.getChartNames(); // Preparing containers to hold the properties of charts charts_ = new ChartsData(); foreach (string chart in chartNames) { listBoxTemplateCharts.Items.Add(chart); ChartTypes defaultType = ChartTypes.UNKNOWN; SignalUnits defaultUnits = SignalUnits.UNKNOWN; // Presetting based on a chart name string lowerChart = chart.ToLower(); // FRF if (lowerChart.Contains("мним")) { defaultType = ChartTypes.IMAG_FRF; if (lowerChart.Contains("-вр")) { defaultType = ChartTypes.MULTI_IMAG_FRF; } defaultUnits = SignalUnits.METERS_PER_SECOND2; } else if (lowerChart.Contains("реал") || lowerChart.Contains("действ")) { defaultType = ChartTypes.REAL_FRF; if (lowerChart.Contains("-вр")) { defaultType = ChartTypes.MULTI_REAL_FRF; } defaultUnits = SignalUnits.METERS_PER_SECOND2; } // Modeset else if (lowerChart.Contains("-ф")) { defaultType = ChartTypes.MODESET; defaultUnits = SignalUnits.METERS_PER_SECOND2; } // Frequency function else if (lowerChart.Contains("f(a)")) { defaultType = ChartTypes.IMAG_FREQUENCY; defaultUnits = SignalUnits.METERS_PER_SECOND2; } // Specifying the data charts_.type.Add(chart, defaultType); charts_.units.Add(chart, defaultUnits); charts_.direction.Add(chart, ChartDirection.UNKNOWN); charts_.selection.Add(chart, new List <ISelection>()); charts_.normalization.Add(chart, 1.0); charts_.axis.Add(chart, ChartDirection.UNKNOWN); charts_.swapAxes.Add(chart, false); charts_.dependency.Add(chart, null); } listBoxTemplateCharts.SelectedIndex = 0; string selectedChart = listBoxTemplateCharts.SelectedItem.ToString(); comboBoxTemplateType.SelectedIndex = (int)charts_.type[selectedChart]; comboBoxTemplateUnits.SelectedIndex = (int)charts_.units[selectedChart]; // Constructing dependencies createDependency(ChartTypes.IMAG_FRF, ChartTypes.REAL_FRF); createDependency(ChartTypes.MULTI_IMAG_FRF, ChartTypes.MULTI_REAL_FRF); setDependencyEnabled(); }