Add export to CSV option in cbuffer previewer. Refs #140

This commit is contained in:
baldurk
2015-07-06 18:16:20 +02:00
parent 6afbe8c92b
commit 36f12d1ef2
3 changed files with 114 additions and 17 deletions
@@ -16,9 +16,9 @@
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConstantBufferPreviewer));
TreelistView.TreeListColumn treeListColumn1 = ((TreelistView.TreeListColumn)(new TreelistView.TreeListColumn("VarName", "Name")));
TreelistView.TreeListColumn treeListColumn2 = ((TreelistView.TreeListColumn)(new TreelistView.TreeListColumn("VarValue", "Value")));
TreelistView.TreeListColumn treeListColumn3 = ((TreelistView.TreeListColumn)(new TreelistView.TreeListColumn("VarType", "Type")));
TreelistView.TreeListColumn treeListColumn7 = new TreelistView.TreeListColumn("VarName", "Name");
TreelistView.TreeListColumn treeListColumn8 = new TreelistView.TreeListColumn("VarValue", "Value");
TreelistView.TreeListColumn treeListColumn9 = new TreelistView.TreeListColumn("VarType", "Type");
this.tableLayout = new System.Windows.Forms.TableLayoutPanel();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.slotLabel = new System.Windows.Forms.ToolStripLabel();
@@ -28,6 +28,9 @@
this.setFormat = new System.Windows.Forms.ToolStripButton();
this.split = new System.Windows.Forms.SplitContainer();
this.variables = new TreelistView.TreeListView();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.saveCSV = new System.Windows.Forms.ToolStripButton();
this.exportDialog = new System.Windows.Forms.SaveFileDialog();
this.tableLayout.SuspendLayout();
this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.split)).BeginInit();
@@ -60,7 +63,9 @@
this.toolStripSeparator1,
this.nameLabel,
this.toolStripSeparator2,
this.setFormat});
this.setFormat,
this.toolStripSeparator3,
this.saveCSV});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(491, 25);
@@ -122,17 +127,17 @@
//
// variables
//
treeListColumn1.AutoSizeMinSize = 0;
treeListColumn1.Width = 175;
treeListColumn2.AutoSize = true;
treeListColumn2.AutoSizeMinSize = 0;
treeListColumn2.Width = 50;
treeListColumn3.AutoSizeMinSize = 0;
treeListColumn3.Width = 70;
treeListColumn7.AutoSizeMinSize = 0;
treeListColumn7.Width = 175;
treeListColumn8.AutoSize = true;
treeListColumn8.AutoSizeMinSize = 0;
treeListColumn8.Width = 50;
treeListColumn9.AutoSizeMinSize = 0;
treeListColumn9.Width = 70;
this.variables.Columns.AddRange(new TreelistView.TreeListColumn[] {
treeListColumn1,
treeListColumn2,
treeListColumn3});
treeListColumn7,
treeListColumn8,
treeListColumn9});
this.variables.ColumnsOptions.LeftMargin = 0;
this.variables.Cursor = System.Windows.Forms.Cursors.Arrow;
this.variables.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -145,6 +150,27 @@
this.variables.Text = "treeListView1";
this.variables.KeyDown += new System.Windows.Forms.KeyEventHandler(this.variables_KeyDown);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
//
// saveCSV
//
this.saveCSV.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.saveCSV.Image = global::renderdocui.Properties.Resources.save;
this.saveCSV.ImageTransparentColor = System.Drawing.Color.Magenta;
this.saveCSV.Name = "saveCSV";
this.saveCSV.Size = new System.Drawing.Size(23, 22);
this.saveCSV.Text = "Save as CSV";
this.saveCSV.Click += new System.EventHandler(this.saveCSV_Click);
//
// exportDialog
//
this.exportDialog.DefaultExt = "csv";
this.exportDialog.Filter = "CSV Files (*.csv)|*.csv";
this.exportDialog.Title = "Export buffer data as CSV";
//
// ConstantBufferPreviewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -177,6 +203,9 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.SplitContainer split;
private TreelistView.TreeListView variables;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripButton saveCSV;
private System.Windows.Forms.SaveFileDialog exportDialog;
}
}
@@ -117,6 +117,8 @@ namespace renderdocui.Controls
variables.EndUpdate();
variables.Invalidate();
saveCSV.Enabled = false;
}
public void OnLogfileLoaded()
@@ -126,6 +128,8 @@ namespace renderdocui.Controls
variables.EndUpdate();
variables.Invalidate();
saveCSV.Enabled = false;
}
private void AddVariables(TreelistView.NodeCollection root, ShaderVariable[] vars)
@@ -160,8 +164,13 @@ namespace renderdocui.Controls
variables.BeginUpdate();
variables.Nodes.Clear();
if(vars != null && vars.Length > 0)
saveCSV.Enabled = false;
if (vars != null && vars.Length > 0)
{
AddVariables(variables.Nodes, vars);
saveCSV.Enabled = true;
}
variables.EndUpdate();
variables.Invalidate();
@@ -253,6 +262,47 @@ namespace renderdocui.Controls
slotLabel.Text = Text;
}
private void ExportCSV(StreamWriter sw, string prefix, TreelistView.NodeCollection nodes)
{
foreach (var n in nodes)
{
if (n.Nodes.IsEmpty())
{
sw.WriteLine(prefix + n[0].ToString() + ",\"" + n[1].ToString() + "\"," + n[2].ToString());
}
else
{
sw.WriteLine(prefix + n[0].ToString() + ",," + n[2].ToString());
ExportCSV(sw, n[0].ToString() + ".", n.Nodes);
}
}
}
private void saveCSV_Click(object sender, EventArgs e)
{
if (!m_Core.LogLoaded || variables.Nodes.IsEmpty())
{
MessageBox.Show("Nothing to export!", "Nothing to export!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
DialogResult res = exportDialog.ShowDialog();
if (res == DialogResult.OK)
{
using (Stream s = new FileStream(exportDialog.FileName, FileMode.Create))
{
StreamWriter sw = new StreamWriter(s);
sw.WriteLine("Name,Value,Type");
ExportCSV(sw, "", variables.Nodes);
sw.Dispose();
}
}
}
private void variables_KeyDown(object sender, KeyEventArgs e)
{
if (!m_Core.LogLoaded) return;
@@ -280,8 +330,23 @@ namespace renderdocui.Controls
text += string.Format(fmt, n[0], n[1], n[2]);
}
if (text.Length > 0)
Clipboard.SetText(text);
try
{
if (text.Length > 0)
Clipboard.SetText(text);
}
catch (System.Exception)
{
try
{
if (text.Length > 0)
Clipboard.SetDataObject(text);
}
catch (System.Exception)
{
// give up!
}
}
}
}
@@ -136,4 +136,7 @@
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="exportDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>125, 18</value>
</metadata>
</root>