[7881] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 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;
|
---|
[7956] | 23 | using System.IO;
|
---|
[7881] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[8192] | 27 | using HeuristicLab.PluginInfrastructure;
|
---|
[7881] | 28 | using HeuristicLab.Problems.Instances.Views;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Instances.VehicleRouting.Views {
|
---|
| 31 | [View("VRP InstanceProvider View")]
|
---|
[7956] | 32 | [Content(typeof(IProblemInstanceConsumer<IVRPData>), IsDefaultView = true)]
|
---|
| 33 | public partial class VRPInstanceProviderView<T> : ProblemInstanceConsumerViewGeneric<T> where T : class, IVRPData {
|
---|
[7881] | 34 |
|
---|
[7956] | 35 | public new IProblemInstanceConsumer<T> Content {
|
---|
| 36 | get { return (IProblemInstanceConsumer<T>)base.Content; }
|
---|
[7881] | 37 | set { base.Content = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public VRPInstanceProviderView() {
|
---|
| 41 | InitializeComponent();
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[8192] | 44 | protected override void SetEnabledStateOfControls() {
|
---|
| 45 | problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null && problemInstanceProviderComboBox.Items.Count > 0;
|
---|
| 46 | libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null;
|
---|
| 47 | IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
|
---|
| 48 | importButton.Enabled = !ReadOnly && !Locked && Content != null && Consumer != null &&
|
---|
| 49 | provider != null && provider.CanImportData;
|
---|
| 50 | ProviderImportSplitContainer.Panel2Collapsed = !importButton.Enabled;
|
---|
| 51 | exportButton.Enabled = !ReadOnly && !Locked && Content != null && Exporter != null &&
|
---|
| 52 | provider != null && provider.CanExportData;
|
---|
| 53 | ProviderExportSplitContainer.Panel2Collapsed = !exportButton.Enabled;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[7881] | 56 | protected override void importButton_Click(object sender, EventArgs e) {
|
---|
[7956] | 57 | IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
|
---|
| 58 | if (provider != null) {
|
---|
| 59 | using (var dialog = new VRPImportDialog(SelectedProvider.Name)) {
|
---|
| 60 | if (dialog.ShowDialog() == DialogResult.OK) {
|
---|
[8192] | 61 | var instance = provider.Import(dialog.VRPFileName, dialog.TourFileName);
|
---|
[7956] | 62 | try {
|
---|
| 63 | GenericConsumer.Load(instance as T);
|
---|
| 64 | }
|
---|
| 65 | catch (Exception ex) {
|
---|
| 66 | MessageBox.Show(String.Format("This problem does not support loading the instance {0}: {1}", Path.GetFileName(openFileDialog.FileName), Environment.NewLine + ex.Message), "Cannot load instance");
|
---|
| 67 | }
|
---|
[7881] | 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
[8192] | 72 |
|
---|
| 73 | protected override void exportButton_Click(object sender, EventArgs e) {
|
---|
| 74 | IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
|
---|
| 75 | if (provider != null) {
|
---|
| 76 | if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 77 | try {
|
---|
| 78 | provider.Export(GenericExporter.Export(), saveFileDialog.FileName);
|
---|
| 79 | }
|
---|
| 80 | catch (Exception ex) {
|
---|
| 81 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
[7881] | 86 | }
|
---|
| 87 | }
|
---|