private void PlotButton_Click(object sender, EventArgs e) { // Select plots int x = 0; int y = 0; using (SelectionForm.SelectionForm sf = new SelectionForm.SelectionForm(DataNames, "Select 2 datasets to display.", "Select Datasets", false)) { sf.ShowDialog(); if (sf.SelectedItems == null || sf.SelectedItems.Count == 0) { return; } else { if (sf.SelectedItems.Count > 2) { MessageBox.Show("Select 2 only."); } else { x = DataNames.IndexOf(sf.SelectedItems[0]); y = DataNames.IndexOf(sf.SelectedItems[1]); } } } // Adjust Data ranges List <double> tempx = new List <double>(); List <double> tempy = new List <double>(); double xmin = DataSets[x].Min(); double xmax = DataSets[x].Max(); double ymin = DataSets[y].Min(); double ymax = DataSets[y].Max(); double yadder = splitContainer1.Panel1.Height / 2.0; double xadder = splitContainer1.Panel1.Width / 2.0; double ydivisor = ((Math.Abs(ymax) > Math.Abs(ymin)) ? ymax : ymin) / yadder; double xdivisor = ((Math.Abs(xmax) > Math.Abs(xmin)) ? xmax : xmin) / xadder; for (int i = 0; i < DataSets[x].Count; i++) { tempx.Add((DataSets[x][i] / xdivisor) + xadder); tempy.Add((DataSets[y][i] / ydivisor) + yadder); } Task.Factory.StartNew(() => Plot(tempx, tempy, Convert.ToInt32(TimeDelayBox.Text))); }
private void GenerateBlenderScript() { List<List<double>> tempDataSets = new List<List<double>>(); char start = 'X'; if (DataSets.Count > 3) { for (int i = 0; i < 3; i++) { char set = (char)((int)start + i); using (SelectionForm.SelectionForm sf = new SelectionForm.SelectionForm(DataNames, "Select " + set + " dataset", "Select " + set + " for Blender", false)) { sf.ShowDialog(); if (sf.SelectedItems == null || sf.SelectedItems.Count != 1) return; else foreach (string selected in sf.SelectedItems) tempDataSets.Add(DataSets[DataNames.IndexOf(selected)]); } } } else tempDataSets.AddRange(DataSets); // Set size of spheres int size = 1; string ret = Microsoft.VisualBasic.Interaction.InputBox("Set size of spheres (default = 1: "); if (ret != "") size = Convert.ToInt16(ret); // Setup datasets in python format string PythonX = "["; string PythonY = "["; string PythonZ = "["; for (int i = 0; i < tempDataSets[0].Count; i++) { PythonX += tempDataSets[0][i].ToString() + ", "; PythonY += tempDataSets[1][i].ToString() + ", "; PythonZ += tempDataSets[2][i].ToString() + ", "; } PythonX += "]"; PythonY += "]"; PythonZ += "]"; string TemplatePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\BlenderPlotter.py"; string[] lines = File.ReadAllLines(TemplatePath); List<string> newlines = new List<string>(); foreach (string line in lines) { string templine = line; if (line.Contains("\"*x*\"")) templine = line.Replace("\"*x*\"", PythonX); else if (line.Contains("\"*y*\"")) templine = line.Replace("\"*y*\"", PythonY); else if (line.Contains("\"*z*\"")) templine = line.Replace("\"*z*\"", PythonZ); else if (line.Contains("*s*")) templine = line.Replace("*s*", size.ToString()); newlines.Add(templine); } using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Title = "Select destination for Blender script"; sfd.Filter = "Python Scripts|*.py"; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return; else File.WriteAllLines(sfd.FileName, newlines.ToArray()); } }
private void PlotButton_Click(object sender, EventArgs e) { // Select plots int x = 0; int y = 0; using (SelectionForm.SelectionForm sf = new SelectionForm.SelectionForm(DataNames, "Select 2 datasets to display.", "Select Datasets", false)) { sf.ShowDialog(); if (sf.SelectedItems == null || sf.SelectedItems.Count == 0) return; else { if (sf.SelectedItems.Count > 2) MessageBox.Show("Select 2 only."); else { x = DataNames.IndexOf(sf.SelectedItems[0]); y = DataNames.IndexOf(sf.SelectedItems[1]); } } } // Adjust Data ranges List<double> tempx = new List<double>(); List<double> tempy = new List<double>(); double xmin = DataSets[x].Min(); double xmax = DataSets[x].Max(); double ymin = DataSets[y].Min(); double ymax = DataSets[y].Max(); double yadder = splitContainer1.Panel1.Height / 2.0; double xadder = splitContainer1.Panel1.Width / 2.0; double ydivisor = ((Math.Abs(ymax) > Math.Abs(ymin)) ? ymax : ymin) / yadder; double xdivisor = ((Math.Abs(xmax) > Math.Abs(xmin)) ? xmax : xmin) / xadder; for (int i = 0; i < DataSets[x].Count; i++) { tempx.Add((DataSets[x][i] / xdivisor) + xadder); tempy.Add((DataSets[y][i] / ydivisor) + yadder); } Task.Factory.StartNew(() => Plot(tempx, tempy, Convert.ToInt32(TimeDelayBox.Text))); }
private void GenerateBlenderScript() { List <List <double> > tempDataSets = new List <List <double> >(); char start = 'X'; if (DataSets.Count > 3) { for (int i = 0; i < 3; i++) { char set = (char)((int)start + i); using (SelectionForm.SelectionForm sf = new SelectionForm.SelectionForm(DataNames, "Select " + set + " dataset", "Select " + set + " for Blender", false)) { sf.ShowDialog(); if (sf.SelectedItems == null || sf.SelectedItems.Count != 1) { return; } else { foreach (string selected in sf.SelectedItems) { tempDataSets.Add(DataSets[DataNames.IndexOf(selected)]); } } } } } else { tempDataSets.AddRange(DataSets); } // Set size of spheres int size = 1; string ret = Microsoft.VisualBasic.Interaction.InputBox("Set size of spheres (default = 1: "); if (ret != "") { size = Convert.ToInt16(ret); } // Setup datasets in python format string PythonX = "["; string PythonY = "["; string PythonZ = "["; for (int i = 0; i < tempDataSets[0].Count; i++) { PythonX += tempDataSets[0][i].ToString() + ", "; PythonY += tempDataSets[1][i].ToString() + ", "; PythonZ += tempDataSets[2][i].ToString() + ", "; } PythonX += "]"; PythonY += "]"; PythonZ += "]"; string TemplatePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\BlenderPlotter.py"; string[] lines = File.ReadAllLines(TemplatePath); List <string> newlines = new List <string>(); foreach (string line in lines) { string templine = line; if (line.Contains("\"*x*\"")) { templine = line.Replace("\"*x*\"", PythonX); } else if (line.Contains("\"*y*\"")) { templine = line.Replace("\"*y*\"", PythonY); } else if (line.Contains("\"*z*\"")) { templine = line.Replace("\"*z*\"", PythonZ); } else if (line.Contains("*s*")) { templine = line.Replace("*s*", size.ToString()); } newlines.Add(templine); } using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.Title = "Select destination for Blender script"; sfd.Filter = "Python Scripts|*.py"; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; } else { File.WriteAllLines(sfd.FileName, newlines.ToArray()); } } }