Changeset 9973 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Exporters/SymbolicSolutionExcelExporter.cs
- Timestamp:
- 09/16/13 18:52:52 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Exporters
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Exporters/SymbolicSolutionExcelExporter.cs
r9937 r9973 34 34 35 35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 36 public class ExportSymbolicSolutionToExcelMenuItem : MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider {36 public class SymbolicSolutionExcelExporter : IDataAnalysisSolutionExporter { 37 37 private const string TRAININGSTART = "TrainingStart"; 38 38 private const string TRAININGEND = "TrainingEnd"; … … 40 40 private const string TESTEND = "TestEnd"; 41 41 42 public override string Name { 43 get { return "Export Symbolic Solution To Excel"; } 44 } 45 public override IEnumerable<string> Structure { 46 get { return new string[] { "&Data Analysis" }; } 47 } 48 public override int Position { 49 get { return 5200; } 50 } 51 public override string ToolTipText { 52 get { return "Create excel file of symbolic data analysis solutions."; } 53 } 54 55 protected override void OnToolStripItemSet(EventArgs e) { 56 base.OnToolStripItemSet(e); 57 ToolStripItem.Enabled = false; 58 var menuItem = ToolStripItem.OwnerItem as ToolStripMenuItem; 59 if (menuItem != null) 60 menuItem.DropDownOpening += menuItem_DropDownOpening; 61 } 62 63 private void menuItem_DropDownOpening(object sender, EventArgs e) { 64 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 65 Control control = activeView as Control; 66 activeView = control.GetNestedControls((c) => c.Visible) 67 .OfType<IContentView>().FirstOrDefault(v => v.Content is ISymbolicDataAnalysisSolution && v.Content is IRegressionSolution); 68 ToolStripItem.Enabled = activeView != null; 69 } 70 71 public override void Execute() { 72 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 73 Control control = activeView as Control; 74 activeView = control.GetNestedControls((c) => c.Visible) 75 .OfType<IContentView>().First(v => v.Content is ISymbolicDataAnalysisSolution && v.Content is IRegressionSolution); 76 var solution = (ISymbolicDataAnalysisSolution)activeView.Content; 42 43 public string FileTypeFilter { 44 get { return "Excel 2007 file (*.xlsx)|*.xlsx"; } 45 } 46 public bool Supports(IDataAnalysisSolution solution) { 47 return solution is ISymbolicDataAnalysisSolution && 48 solution is IRegressionSolution; 49 } 50 51 public void Export(IDataAnalysisSolution solution, string fileName) { 52 var symbSolution = solution as ISymbolicDataAnalysisSolution; 53 if (symbSolution == null) throw new NotSupportedException("This solution cannot be exported to Excel"); 77 54 var formatter = new SymbolicDataAnalysisExpressionExcelFormatter(); 78 var formula = formatter.Format(solution.Model.SymbolicExpressionTree, solution.ProblemData.Dataset); 79 control = (Control)activeView; 80 81 82 SaveFileDialog saveFileDialog = new SaveFileDialog(); 83 saveFileDialog.Filter = "Excel Workbook|*.xlsx"; 84 saveFileDialog.Title = "Save an Excel File"; 85 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 86 string fileName = saveFileDialog.FileName; 87 using (BackgroundWorker bg = new BackgroundWorker()) { 88 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(control, "Exportion solution to " + fileName + "."); 89 bg.DoWork += (b, e) => ExportChart(fileName, solution, formula); 90 bg.RunWorkerCompleted += (o, e) => MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(control); 91 bg.RunWorkerAsync(); 92 } 93 } 55 var formula = formatter.Format(symbSolution.Model.SymbolicExpressionTree, solution.ProblemData.Dataset); 56 ExportChart(fileName, symbSolution, formula); 94 57 } 95 58
Note: See TracChangeset
for help on using the changeset viewer.