1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 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.Drawing;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Clients.Access;
|
---|
26 | using HeuristicLab.Optimizer.Properties;
|
---|
27 | using HeuristicLab.PluginInfrastructure;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Optimizer {
|
---|
30 | [Plugin("HeuristicLab.Optimizer", "3.3.15.$WCREV$")]
|
---|
31 | [PluginFile("HeuristicLab.Optimizer-3.3.dll", PluginFileType.Assembly)]
|
---|
32 | [PluginDependency("HeuristicLab.Clients.Access", "3.3")]
|
---|
33 | [PluginDependency("HeuristicLab.Clients.Common", "3.3")]
|
---|
34 | [PluginDependency("HeuristicLab.Collections", "3.3")]
|
---|
35 | [PluginDependency("HeuristicLab.Common", "3.3")]
|
---|
36 | [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
|
---|
37 | [PluginDependency("HeuristicLab.Core", "3.3")]
|
---|
38 | [PluginDependency("HeuristicLab.Core.Views", "3.3")]
|
---|
39 | [PluginDependency("HeuristicLab.Data", "3.3")]
|
---|
40 | [PluginDependency("HeuristicLab.Data.Views", "3.3")]
|
---|
41 | [PluginDependency("HeuristicLab.MainForm", "3.3")]
|
---|
42 | [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
|
---|
43 | [PluginDependency("HeuristicLab.Optimization", "3.3")]
|
---|
44 | [PluginDependency("HeuristicLab.Parameters", "3.3")]
|
---|
45 | [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
|
---|
46 | public class HeuristicLabOptimizerPlugin : PluginBase {
|
---|
47 | }
|
---|
48 |
|
---|
49 | [Application("Optimizer", "HeuristicLab Optimizer 3.3.15.$WCREV$")]
|
---|
50 | internal class HeuristicLabOptimizerApplication : ApplicationBase {
|
---|
51 | public override void Run(ICommandLineArgument[] args) {
|
---|
52 | HeuristicLab.MainForm.WindowsForms.MainForm mainForm = null;
|
---|
53 |
|
---|
54 | if (Settings.Default.MainFormType == OptimizerMainFormTypes.DockingMainForm) {
|
---|
55 | mainForm = new OptimizerDockingMainForm(typeof(IOptimizerUserInterfaceItemProvider));
|
---|
56 | } else if (Settings.Default.MainFormType == OptimizerMainFormTypes.MultipleDocumentMainForm) {
|
---|
57 | mainForm = new OptimizerMultipleDocumentMainForm(typeof(IOptimizerUserInterfaceItemProvider));
|
---|
58 | } else if (Settings.Default.MainFormType == OptimizerMainFormTypes.SingleDocumentMainForm) {
|
---|
59 | mainForm = new OptimizerSingleDocumentMainForm(typeof(IOptimizerUserInterfaceItemProvider));
|
---|
60 | }
|
---|
61 |
|
---|
62 | if (mainForm != null) {
|
---|
63 | if (CheckSavedMainFormSettings()) {
|
---|
64 | mainForm.Location = Settings.Default.MainFormLocation;
|
---|
65 | mainForm.Size = Settings.Default.MainFormSize;
|
---|
66 | mainForm.WindowState = Settings.Default.MainFormWindowState;
|
---|
67 | }
|
---|
68 |
|
---|
69 | mainForm.FormClosing += (sender, eventArgs) => {
|
---|
70 | if (mainForm.WindowState != FormWindowState.Minimized)
|
---|
71 | Settings.Default.MainFormWindowState = mainForm.WindowState;
|
---|
72 | if (mainForm.WindowState != FormWindowState.Normal) {
|
---|
73 | Settings.Default.MainFormLocation = mainForm.RestoreBounds.Location;
|
---|
74 | Settings.Default.MainFormSize = mainForm.RestoreBounds.Size;
|
---|
75 | } else if (mainForm.WindowState == FormWindowState.Normal) {
|
---|
76 | Settings.Default.MainFormLocation = mainForm.Location;
|
---|
77 | Settings.Default.MainFormSize = mainForm.Size;
|
---|
78 | }
|
---|
79 | };
|
---|
80 |
|
---|
81 |
|
---|
82 | ClientInformation.InitializeAsync();
|
---|
83 | UserInformation.InitializeAsync();
|
---|
84 |
|
---|
85 | mainForm.ShowContentInViewHost = true;
|
---|
86 | var filesToOpen = args.OfType<OpenArgument>().Select(x => x.Value);
|
---|
87 | mainForm.Load += (sender, eventArgs) => FileManager.OpenFiles(filesToOpen);
|
---|
88 | Application.Run(mainForm);
|
---|
89 | } else {
|
---|
90 | MessageBox.Show("Error loading setting for the MainForm Type. Please check your configuration file!", "HeuristicLab", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | private bool CheckSavedMainFormSettings() {
|
---|
95 | var formArea = new Rectangle(Settings.Default.MainFormLocation, Settings.Default.MainFormSize);
|
---|
96 | var screenArea = Screen.FromRectangle(formArea).WorkingArea;
|
---|
97 | var overlappingArea = Rectangle.Intersect(formArea, screenArea);
|
---|
98 | bool offLimits = overlappingArea.IsEmpty || overlappingArea.Width * overlappingArea.Height < formArea.Width * formArea.Height * 0.25;
|
---|
99 | return !formArea.IsEmpty && !offLimits;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|