-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModellingWizard.xaml.cs
More file actions
383 lines (328 loc) · 14 KB
/
ModellingWizard.xaml.cs
File metadata and controls
383 lines (328 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
using Aml.Editor.Plugin.Contracts;
using Aml.Engine.CAEX;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace Aml.Editor.Plugin
{
/// <summary>
/// ModellingWizard is an PlugIn, which implements the IAMLEditorView Interface. The PlugIn is
/// a UserControl, which is managed by the AutomationML Editors Window- and Docking - Manager.
/// The Export Attribute enables the AutomationML Editor to load the PlugIn with the <a
/// href="http://msdn.microsoft.com/en-us/library/dd460648%28v=vs.110%29.aspx">Microsoft Managed
/// Extensibility Framework</a>.
/// </summary>
[Export(typeof(IAMLEditorView))]
public partial class ModellingWizard : UserControl, IAMLEditorView
{
/// <summary>
/// <see cref="AboutCommand"/>
/// </summary>
private RelayCommand<object> aboutCommand;
MWController mWController;
public ModellingWizard()
{
mWController = new MWController(this);
// Defines the Command list, which will contain user commands, which a user can select
// via the PlugIn Menu.
Commands = new List<PluginCommand>();
// Every PlugIn needs at least an Activation command, which will be called by a user to activate the PlugIn.
ActivatePlugin = new PluginCommand()
{
Command = new RelayCommand<object>(this.StartCommandExecute,
this.StartCommandCanExecute),
CommandName = "Start",
CommandToolTip = "Start the PlugIn"
};
// Every PlugIn should provide a Termination command, which will be called when the PlugIn window is closed by the user. This can only
// occur, if the PlugIn view is embedded in a docking window by the Editor.
TerminatePlugin = new PluginCommand()
{
Command = new RelayCommand<object>(this.StopCommandExecute, this.StopCommandCanExecute),
CommandName = "Stop",
CommandToolTip = "Stop the PlugIn"
};
ReloadObjects = new PluginCommand()
{
Command = new RelayCommand<object>(this.ReloadObjectsExecute, this.StopCommandCanExecute),
CommandName = "Reload Objects",
CommandToolTip = "Reload all .amlx in the plugin folder"
};
InitializeComponent();
// Add the StartCommand (should exist in any PlugIn)
Commands.Add(ActivatePlugin);
// Add the Stop Command (should exist in any PlugIn)
Commands.Add(TerminatePlugin);
Commands.Add(ReloadObjects);
//// Add the change spelling command (an additional command, only for this special PlugIn)
//Commands.Add(new PluginCommand()
//{
// CommandName = "Load File",
// Command = InvertCase,
// CommandToolTip = "Load a new test file"
//});
// Add the About Command (recommended to exist in any PlugIn)
Commands.Add(new PluginCommand()
{
CommandName = "About",
Command = AboutCommand,
CommandToolTip = "Information about this PlugIn"
});
this.IsActive = false;
}
private void ReloadObjectsExecute(object obj)
{
mWController.ReloadObjects();
}
/// <summary>
/// Occurs when the PlugIn is activated (for example via the <see cref="StartCommand"/> ).
/// </summary>
public event EventHandler PluginActivated;
/// <summary>
/// Occurs when the PlugIn is deactivated (some UserInteraction inside the PlugIn or via the
/// <see cref="StopCommand"/> ).
/// </summary>
public event EventHandler PluginTerminated;
/// <summary>
/// The AboutCommand - Command
/// </summary>
/// <value>The about command.</value>
public System.Windows.Input.ICommand AboutCommand
{
get
{
return this.aboutCommand
??
(this.aboutCommand = new RelayCommand<object>(this.AboutCommandExecute, this.AboutCommandCanExecute));
}
}
/// <summary>
/// Gets the Command to activate the PlugIn.
/// </summary>
public PluginCommand ActivatePlugin
{
get;
private set;
}
/// <summary>
/// Gets the Command to reload the AMLX Files in ./modellingwizard/
/// </summary>
public PluginCommand ReloadObjects
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether this UserControl could be closed from the Editor's
/// WindowManager. When a close occurs from the WindowManager, the StopCommand will be
/// executed via the <see cref="ExecuteCommand"/> Method.
/// </summary>
/// <value><c>true</c> if this instance can close; otherwise, <c>false</c>.</value>
public bool CanClose
{
get { return true; }
}
/// <summary>
/// Gets the List of commands, which are viewed in the PlugIn Menu in the Host Application
/// </summary>
/// <value>The command List.</value>
public List<PluginCommand> Commands
{
get;
private set;
}
/// <summary>
/// Gets the display name which is shown in the PlugIn Menu in the Host Application
/// </summary>
/// <value>The display name.</value>
public string DisplayName
{
get { return "Modeling Wizard for Devices"; }
}
/// <summary>
/// Gets a value indicating whether this instance is active. The Property should be set to
/// true in the <see cref="StartCommand"/> and set to false in the <see cref="StopCommand"/>
/// </summary>
/// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value>
public bool IsActive
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether this instance is reactive. Reactive PlugIn will be
/// notified, when the actual CAEX-Object changes (Selection of the Tree view Item) <see
/// cref="ChangeAMLFilePath"/> and <see cref="ChangeSelectedObject"/>.
/// </summary>
/// <value><c>true</c> if this instance is reactive; otherwise, <c>false</c>.</value>
public bool IsReactive
{
get { return false; }
}
/// <summary>
/// Gets a value indicating whether this instance is read only. A Read only PlugIn should not
/// change any CAEX Objects.
/// </summary>
/// <value>
/// <c>true</c> if this instance is read only; otherwise, <c>false</c>.
/// </value>
public bool IsReadonly
{
get { return false; }
}
/// <summary>
/// Gets the terminate PlugIn command.
/// </summary>
public PluginCommand TerminatePlugin
{
get;
private set;
}
/// <summary>
/// Gets the initial dock position for the PlugIn window.
/// </summary>
public DockPositionEnum InitialDockPosition => DockPositionEnum.Floating;
/// <summary>
/// Gets or sets a value indicating whether this instance is automatic active when loaded.
/// This value can be initially set and will be defined by the user.
/// </summary>
public bool IsAutoActive { get; set; }
/// <summary>
/// Gets the package name which is used to download the PlugIn package from a NuGet feed. If a Package name
/// is defined, the AMLEditor can update PlugIn packages independently from its own update cycle.
/// </summary>
/// <value>
/// The package name.
/// </value>
public string PackageName => "";
/// <summary>
/// Gets the image which should be used in the Header of the PlugIn window.
/// If no image is defined the editor uses a default image.
/// </summary>
public BitmapImage PaneImage => null;
/// <summary>
/// Changes the current amlFilePath. The Host Application will call this method when the
/// PlugIns <see cref="P:Aml.Editor.Plugin.Contracts.IAMLEditorPlugin.IsReactive" /> Property is set to true and the Currently opened
/// AutomationML File changes in the AMLEditor Host Application.
/// </summary>
/// <param name="amlFilePath">The Path to the current AML File in the AML Editor.</param>
public void ChangeAMLFilePath(string amlFilePath)
{
//mWController.ChangeAMLFilePath(amlFilePath);
}
/// <summary>
/// Changes the selected object. The Host Application will call this method when the PlugIns
/// <see cref="P:Aml.Editor.Plugin.Contracts.IAMLEditorPlugin.IsReactive" /> Property is set to true and the Current Selection changes in
/// the AMLEditor Host Application.
/// </summary>
/// <param name="selectedObject">The selected CAEX - object.</param>
public void ChangeSelectedObject(CAEXBasicObject selectedObject)
{
/*if (selectedObject is InternalElementType ie)
{
if (ie.SystemUnitClass != null)
{
PlugInUI.ShowClass(ie.SystemUnitClass);
}
}*/
}
/// <summary>
/// This Method is called from the AutomationML Editor to execute a specific command. The
/// Editor can only execute those commands, which are identified by the <see
/// cref="PluginCommandsEnum"/> Enumeration. The Editor may execute the termination command
/// of the PlugIn, so here some preparations for a clean termination should be performed.
/// </summary>
/// <param name="command"> The command.</param>
/// <param name="amlFilePath">The amlFilePath.</param>
public void ExecuteCommand(PluginCommandsEnum command, string amlFilePath)
{
switch (command)
{
case PluginCommandsEnum.Terminate:
StopCommandExecute(null);
break;
}
}
/// <summary>
/// This Method is called on activation of a PlugIn. The AutomationML Editor 'publishes' its
/// current state to the PlugIn, that is the Path of the loaded AutomationML Document and
/// the currently selected AutomationML Object'. Please note, that the objects may be empty
/// or null.
/// </summary>
/// <param name="amlFilePath"> The AML file path, may be empty.</param>
/// <param name="selectedObject">The selected object, may be null.</param>
public void PublishAutomationMLFileAndObject(string amlFilePath, CAEXBasicObject selectedObject)
{
}
/// <summary>
/// Test, if the <see cref="AboutCommand"/> can execute.
/// </summary>
/// <param name="parameter">unused.</param>
/// <returns>true, if command can execute</returns>
private bool AboutCommandCanExecute(object parameter)
{
// Execution is always possible, also for inactive PlugIns
return true;
}
/// <summary>
/// The <see cref="AboutCommand"/> Execution Action.
/// </summary>
/// <param name="parameter">unused.</param>
private void AboutCommandExecute(object parameter)
{
var dialog = new About();
dialog.ShowDialog();
}
/// <summary>
/// Test, if the <see cref="StartCommand"/> can execute. The <see cref="IsActive"/> Property
/// should be false prior to Activation.
/// </summary>
/// <param name="parameter">unused</param>
/// <returns>true, if command can execute</returns>
private bool StartCommandCanExecute(object parameter)
{
return !this.IsActive;
}
/// <summary>
/// The <see cref="StartCommand"/> s execution Action. The <see cref="PluginActivated"/>
/// event is raised and the <see cref="IsActive"/> Property is set to true.
/// </summary>
/// <param name="parameter">unused</param>
private void StartCommandExecute(object parameter)
{
this.IsActive = true;
// create the new PlugInUI and add it to the forms host
mWController.ChangeGui(MWController.MWGUIType.Start);
PluginActivated?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Test, if the <see cref="StopCommand"/> can execute.
/// </summary>
/// <param name="parameter">unused</param>
/// <returns>true, if command can execute</returns>
private bool StopCommandCanExecute(object parameter)
{
return this.IsActive;
}
/// <summary>
/// The <see cref="StopCommand"/> Execution Action sets the <see cref="IsActive"/> Property
/// to false. The <see cref="PluginTerminated"/> event will be raised.
/// </summary>
/// <param name="parameter">unused</param>
private void StopCommandExecute(object parameter)
{
this.IsActive = false;
PluginTerminated?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Replace the Content in the Plugin window with the Windows Forms GUI
/// </summary>
/// <param name="content">The Form to be displayed in the plugin window</param>
public void changeGUI(System.Windows.Forms.Control content)
{
FormsHost.Child = content;
}
}
}