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 { /// /// ModellingWizard is an PlugIn, which implements the AMLEditorView 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 Microsoft Managed /// Extensibility Framework. /// [Export(typeof(IAMLEditorView))] public partial class ModellingWizard : UserControl, IAMLEditorView { /// /// /// private RelayCommand 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(); // 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(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(this.StopCommandExecute, this.StopCommandCanExecute), CommandName = "Stop", CommandToolTip = "Stop the PlugIn" }; ReloadObjects = new PluginCommand() { Command = new RelayCommand(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) { } /// /// Occurs when the PlugIn is activated (for example via the ). /// public event EventHandler PluginActivated; /// /// Occurs when the PlugIn is deactivated (some UserInteraction inside the PlugIn or via the /// ). /// public event EventHandler PluginTerminated; /// /// The AboutCommand - Command /// /// The about command. public System.Windows.Input.ICommand AboutCommand { get { return this.aboutCommand ?? (this.aboutCommand = new RelayCommand(this.AboutCommandExecute, this.AboutCommandCanExecute)); } } /// /// Gets the Command to activate the PlugIn. /// public PluginCommand ActivatePlugin { get; private set; } /// /// Gets the Command to reload the AMLX Files in ./modellingwizard/ /// public PluginCommand ReloadObjects { get; private set; } /// /// 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 Method. /// /// true if this instance can close; otherwise, false. public bool CanClose { get { return true; } } /// /// Gets the List of commands, which are viewed in the PlugIn Menu in the Host Application /// /// The command List. public List Commands { get; private set; } /// /// Gets the display name which is shown in the PlugIn Menu in the Host Application /// /// The display name. public string DisplayName { get { return "Modelling wizard for devices [Version 02.00.00.00 (18.04.2021)]"; } } /// /// Gets a value indicating whether this instance is active. The Property should be set to /// true in the and set to false in the /// /// true if this instance is active; otherwise, false. public bool IsActive { get; private set; } /// /// 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) and . /// /// true if this instance is reactive; otherwise, false. public bool IsReactive { get { return false; } } /// /// Gets a value indicating whether this instance is read only. A Read only PlugIn should not /// change any CAEX Objects. /// /// /// true if this instance is read only; otherwise, false. /// public bool IsReadonly { get { return false; } } /// /// Gets the terminate PlugIn command. /// public PluginCommand TerminatePlugin { get; private set; } /// /// Gets the initial dock position for the PlugIn window. /// public DockPositionEnum InitialDockPosition => DockPositionEnum.Floating; /// /// 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. /// public bool IsAutoActive { get; set; } /// /// 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. /// /// /// The package name. /// public string PackageName => ""; /// /// 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. /// public BitmapImage PaneImage => null; /// /// Changes the current amlFilePath. The Host Application will call this method when the /// PlugIns Property is set to true and the Currently opened /// AutomationML File changes in the AMLEditor Host Application. /// /// The Path to the current AML File in the AML Editor. public void ChangeAMLFilePath(string amlFilePath) { //mWController.ChangeAMLFilePath(amlFilePath); } /// /// Changes the selected object. The Host Application will call this method when the PlugIns /// Property is set to true and the Current Selection changes in /// the AMLEditor Host Application. /// /// The selected CAEX - object. public void ChangeSelectedObject(CAEXBasicObject selectedObject) { /*if (selectedObject is InternalElementType ie) { if (ie.SystemUnitClass != null) { PlugInUI.ShowClass(ie.SystemUnitClass); } }*/ } /// /// 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 Enumeration. The Editor may execute the termination command /// of the PlugIn, so here some preparations for a clean termination should be performed. /// /// The command. /// The amlFilePath. public void ExecuteCommand(PluginCommandsEnum command, string amlFilePath) { switch (command) { case PluginCommandsEnum.Terminate: StopCommandExecute(null); break; } } /// /// 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. /// /// The AML file path, may be empty. /// The selected object, may be null. public void PublishAutomationMLFileAndObject(string amlFilePath, CAEXBasicObject selectedObject) { } /// /// Test, if the can execute. /// /// unused. /// true, if command can execute private bool AboutCommandCanExecute(object parameter) { // Execution is always possible, also for inactive PlugIns return true; } /// /// The Execution Action. /// /// unused. private void AboutCommandExecute(object parameter) { var dialog = new About(); dialog.ShowDialog(); } /// /// Test, if the can execute. The Property /// should be false prior to Activation. /// /// unused /// true, if command can execute private bool StartCommandCanExecute(object parameter) { return !this.IsActive; } /// /// The s execution Action. The /// event is raised and the Property is set to true. /// /// unused private void StartCommandExecute(object parameter) { this.IsActive = true; // create the new PlugInUI and add it to the forms host mWController.ChangeGui(MWController.MWGUIType.DeviceDescription); PluginActivated?.Invoke(this, EventArgs.Empty); } /// /// Test, if the can execute. /// /// unused /// true, if command can execute private bool StopCommandCanExecute(object parameter) { return this.IsActive; } /// /// The Execution Action sets the Property /// to false. The event will be raised. /// /// unused private void StopCommandExecute(object parameter) { this.IsActive = false; PluginTerminated?.Invoke(this, EventArgs.Empty); } /// /// Replace the Content in the Plugin window with the Windows Forms GUI /// /// The Form to be displayed in the plugin window public void changeGUI(System.Windows.Forms.Control content) { FormsHost.Child = content; } } }