[2851] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.Persistence.Default.Xml;
|
---|
| 28 |
|
---|
[2852] | 29 | namespace HeuristicLab.Optimization.Views {
|
---|
[2851] | 30 | /// <summary>
|
---|
| 31 | /// The base class for visual representations of items.
|
---|
| 32 | /// </summary>
|
---|
[2917] | 33 | [View("UserDefinedAlgorithm View")]
|
---|
[2851] | 34 | [Content(typeof(UserDefinedAlgorithm), true)]
|
---|
| 35 | public sealed partial class UserDefinedAlgorithmView : EngineAlgorithmView {
|
---|
| 36 | public new UserDefinedAlgorithm Content {
|
---|
| 37 | get { return (UserDefinedAlgorithm)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /// <summary>
|
---|
| 42 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 43 | /// </summary>
|
---|
| 44 | public UserDefinedAlgorithmView() {
|
---|
| 45 | InitializeComponent();
|
---|
| 46 | }
|
---|
| 47 | /// <summary>
|
---|
| 48 | /// Intializes a new instance of <see cref="ItemBaseView"/> with the given <paramref name="item"/>.
|
---|
| 49 | /// </summary>
|
---|
| 50 | /// <param name="item">The item that should be displayed.</param>
|
---|
| 51 | public UserDefinedAlgorithmView(UserDefinedAlgorithm content)
|
---|
| 52 | : this() {
|
---|
| 53 | Content = content;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | protected override void OnContentChanged() {
|
---|
| 57 | base.OnContentChanged();
|
---|
[3367] | 58 | if (Content == null)
|
---|
[2851] | 59 | globalScopeView.Content = null;
|
---|
[3367] | 60 | else
|
---|
[2851] | 61 | globalScopeView.Content = Content.GlobalScope;
|
---|
[3367] | 62 | SetEnableStateOfControls();
|
---|
[2851] | 63 | }
|
---|
| 64 |
|
---|
[3367] | 65 | protected override void OnReadOnlyChanged() {
|
---|
| 66 | base.OnReadOnlyChanged();
|
---|
| 67 | SetEnableStateOfControls();
|
---|
| 68 | }
|
---|
| 69 | private void SetEnableStateOfControls() {
|
---|
| 70 | globalScopeView.ReadOnly = ReadOnly;
|
---|
| 71 | operatorGraphViewHost.ReadOnly = ReadOnly;
|
---|
| 72 | if (Content == null)
|
---|
| 73 | newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
|
---|
| 74 | else
|
---|
[3262] | 75 | newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
[2998] | 76 | }
|
---|
[2851] | 77 |
|
---|
| 78 | private void newOperatorGraphButton_Click(object sender, EventArgs e) {
|
---|
| 79 | Content.OperatorGraph = new OperatorGraph();
|
---|
| 80 | }
|
---|
| 81 | private void openOperatorGraphButton_Click(object sender, EventArgs e) {
|
---|
| 82 | openFileDialog.Title = "Open Operator Graph";
|
---|
| 83 | if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
[2954] | 84 | this.Cursor = Cursors.AppStarting;
|
---|
| 85 | newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
|
---|
[3177] | 86 | operatorGraphViewHost.Enabled = false;
|
---|
[2954] | 87 |
|
---|
| 88 | var call = new Func<string, object>(XmlParser.Deserialize);
|
---|
| 89 | call.BeginInvoke(openFileDialog.FileName, delegate(IAsyncResult a) {
|
---|
| 90 | OperatorGraph operatorGraph = null;
|
---|
| 91 | try {
|
---|
| 92 | operatorGraph = call.EndInvoke(a) as OperatorGraph;
|
---|
| 93 | }
|
---|
| 94 | catch (Exception ex) {
|
---|
| 95 | Auxiliary.ShowErrorMessageBox(ex);
|
---|
| 96 | }
|
---|
| 97 | Invoke(new Action(delegate() {
|
---|
| 98 | if (operatorGraph == null)
|
---|
| 99 | MessageBox.Show(this, "The selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 100 | else
|
---|
| 101 | Content.OperatorGraph = operatorGraph;
|
---|
[3177] | 102 | operatorGraphViewHost.Enabled = true;
|
---|
[2954] | 103 | newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
|
---|
| 104 | this.Cursor = Cursors.Default;
|
---|
| 105 | }));
|
---|
| 106 | }, null);
|
---|
[2851] | 107 | }
|
---|
| 108 | }
|
---|
| 109 | private void saveOperatorGraphButton_Click(object sender, EventArgs e) {
|
---|
| 110 | saveFileDialog.Title = "Save Operator Graph";
|
---|
| 111 | if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
[2954] | 112 | this.Cursor = Cursors.AppStarting;
|
---|
| 113 | newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
|
---|
[3177] | 114 | operatorGraphViewHost.Enabled = false;
|
---|
[2954] | 115 |
|
---|
| 116 | var call = new Action<OperatorGraph, string, int>(XmlGenerator.Serialize);
|
---|
| 117 | int compression = 9;
|
---|
| 118 | if (saveFileDialog.FilterIndex == 1) compression = 0;
|
---|
| 119 | call.BeginInvoke(Content.OperatorGraph, saveFileDialog.FileName, compression, delegate(IAsyncResult a) {
|
---|
| 120 | try {
|
---|
| 121 | call.EndInvoke(a);
|
---|
| 122 | }
|
---|
| 123 | catch (Exception ex) {
|
---|
| 124 | Auxiliary.ShowErrorMessageBox(ex);
|
---|
| 125 | }
|
---|
| 126 | Invoke(new Action(delegate() {
|
---|
[3177] | 127 | operatorGraphViewHost.Enabled = true;
|
---|
[2954] | 128 | newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
|
---|
| 129 | this.Cursor = Cursors.Default;
|
---|
| 130 | }));
|
---|
| 131 | }, null);
|
---|
[2851] | 132 | }
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | }
|
---|