diff --git a/Client/View/MainForm.cs b/Client/View/MainForm.cs index 649948ed..17c668b2 100644 --- a/Client/View/MainForm.cs +++ b/Client/View/MainForm.cs @@ -16,620 +16,646 @@ using System.IO; using static Client.Utils.Constants; namespace CMS_Client.View -{ - public partial class MainForm : Form - { - //Struct of PageError - private struct PageError - { - public Boolean Error; - public String ErrorInfo; - } - Random rnd = new Random(); - - //Internal Variables - private PageError LoadingError; - private NcForm NcFrm; - private LoadingForm LdFrm; - private static IntPtr MainHandle; - private static IntPtr NcHandle; - private int X = 0, Y = 0; - private string BrokenUrl; - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region WINDOW_START_&_BEHAVIOUR_METHOD - //Instance Method - public MainForm() - { - LdFrm = new LoadingForm(); - LdFrm.Owner = this; - - //Set the Loading window - ShowLoading("Setup Main View..."); - - //Initialize the Windows - InitializeComponent(); - - //Start Client Setting - InitializeClientSettings(); - - //Initialize the Browser-Components - InitializeBrowser(); - - //Set the client property - this.Text = Application.ProductName + " " + Application.ProductVersion; - this.Opacity = 0.0; - - //Initialize the Nc-Form - InitializeNcForm(); - - //Load the page - Browser.LoadUrl(Config.ConnectionConfig.StartingUrl); - //Set the title of the window in "Loading" - SetWindowTitle("Loading..."); - ShowLoading("Loading Main View..."); - - NcWindow.mainFrm = this; - } - - - - //On windows-Load Method - private void MainForm_Load(object sender, EventArgs e) - { - this.DesktopLocation = new Point(X, Y); - } - - - - //On Resize Form - private void MainForm_Resize(object sender, EventArgs e) - { - if (this.WindowState == FormWindowState.Minimized) - { - NcWindow.ShowTaskBar(); - if (Config.VendorHmiConfig.Enabled) - NcFrm.Hide(); - } - else - { - if (Config.VendorHmiConfig.Enabled) - NcFrm.Show(); +{ + public partial class MainForm : Form + { + //Struct of PageError + private struct PageError + { + public Boolean Error; + public String ErrorInfo; + } + Random rnd = new Random(); - if (NcWindow.State == NcState.SHOW) - { - HideNCWindow(); - ShowNCWindow(); - } - else - HideNCWindow(); - } - - //Refresh Browser Paint - Browser.Refresh(); - this.Refresh(); - } - - - - //Before closing the Window -> Remove the Browser (Increase the speed of closing window) - private void MainForm_FormClosing(object sender, FormClosingEventArgs e) - { - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - //Show Taskbar - NcWindow.ShowTaskBar(); - - //Hide Window - this.Hide(); - - //Close Virtual Keyboard Runtime - if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) - NcWindow.closeVirtualKeyboard(); - - //Close the NC HMI && Stop Following Nc - if (Config.VendorHmiConfig.Enabled) - NcWindow.CloseNcWindow(false); - - - //Close Chromium Runtime - try - { - CfxRuntime.Shutdown(); - } - catch(Exception ex) - { + //Internal Variables + private PageError LoadingError; + private NcForm NcFrm; + private LoadingForm LdFrm; + private static IntPtr MainHandle; + private static IntPtr NcHandle; + private int X = 0, Y = 0; + private string BrokenUrl; - } - } - - - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region SETUP_METHODS - - //Initialize CMS-Client Settings - private void InitializeClientSettings() - { - //Set the Transparency Key - if(Config.ClientConfig.RenderingMethod == Constants.Rendering.CPU && Environment.OSVersion.Version.Major < 10) - TransparencyKey = Config.ClientConfig.TranspColor; - - //Calculate Window Position - CalcWindowPosition(); - } - - - - //Initialize CMS-Client Settings - private void InitializeNcForm() - { - //Create the Nc-Form - if (Config.VendorHmiConfig.Enabled) - { - NcFrm = new NcForm(Config.ClientConfig.TranspColor, X, Y); - NcHandle = NcFrm.Handle; - NcFrm.Show(); - } - - //Steup the Step variables - MainHandle = this.Handle; - } - - - - //Initialize the Browser-Component - private void InitializeBrowser() - { - //Add Custom object to browser - Browser.GlobalObject.Add(Constants.BROWSER_JS_OBJ_NAME, new BrowserJSObject(this)); - - //Add all Handlers - Browser.DisplayHandler.OnTitleChange += BrowserTitleChanged; - Browser.LoadHandler.OnLoadingStateChange += BrowserLoadsChanged; - Browser.LoadHandler.OnLoadError += BrowserLoadsError; - Browser.KeyboardHandler.OnKeyEvent += BrowserKeyPress; - Browser.ContextMenuHandler.OnBeforeContextMenu += BrowserContextMenu; - Browser.DisplayHandler.OnConsoleMessage += BrowserConsoleMessage; - //Filter only < Win_10 Platform - if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) - ChromiumWebBrowser.RemoteProcessCreated += (e) => { e.RenderProcessHandler.OnFocusedNodeChanged += BrowserNodeChanged; }; - } - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region BROWSER_EVENT_HANDLERS_METHODS - - //On browser Load-Error. Event Handler called by Browser - private void BrowserLoadsError(object sender, CfxOnLoadErrorEventArgs e) - { - //Set the Load-Error global variable to TRUE - LoadingError.Error = true; - LoadingError.ErrorInfo = e.ErrorCode.GetHashCode() + " - " + e.ErrorText; - if (e.FailedUrl != Constants.errorPageUrl) - this.BrokenUrl = e.FailedUrl; - - //write the error in the Title Bar - SetWindowTitle(LoadingError.ErrorInfo); - } - - - - //On browser Load-Changed. Event Handler called by Browser - private void BrowserLoadsChanged(object sender, CfxOnLoadingStateChangeEventArgs e) - { - //if the State is NOT "loading" - if (!e.Browser.IsLoading) - { - //Hide Loading Window - HideLoadingWindow(); - - //Show the Main Window, when the page is loaded - ShowWindow(); - - //If is an Error Show the Error page - if (LoadingError.Error && !LoadingError.ErrorInfo.Contains("ERR_ABORTED")) - { - Browser.LoadString(Config.ConnectionConfig.ErrorPage, Constants.errorPageUrl); - } - - //Set focus on the page - BrowserFocus(); - - } - //if the State is "loading" - else - { - //Hide NC Window - NcWindow.SetState(0); - HideNCWindow(); - - //Set the title of the window in "Loading" - SetWindowTitle("Loading..."); - - //Set the Load-Error global variable to FALSE - LoadingError.Error = false; - } - } - - - - //On browser Title-Changed. Event Handler called by Browser - private void BrowserTitleChanged(object sender, CfxOnTitleChangeEventArgs e) - { - if (!LoadingError.Error) - SetWindowTitle(e.Title); - } - - - - // on Key-Press Browser - private void BrowserKeyPress(object sender, CfxOnKeyEventEventArgs e) - { - - } - - - - //Show Dev Tools Window - private void ShowDevTools() { - //Setup Dev Window - CfxWindowInfo windowInfo = new CfxWindowInfo(); - windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); - windowInfo.ParentWindow = MainHandle; - windowInfo.WindowName = Application.ProductName + " | CEF Dev Tools"; - windowInfo.X = 1120; - windowInfo.Y = 0; - windowInfo.Width = 800; - windowInfo.Height = 1080; - - //Show Dev Window - Browser.BrowserHost.ShowDevTools(windowInfo, new CfxClient(), new CfxBrowserSettings(), null); - } - - - - //Show Chrome GPU Window - private void ShowChromeGPU() - { - int w = 1600, h = 800; - - //Setup Window - CfxWindowInfo windowInfo = new CfxWindowInfo(); - windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); - windowInfo.ParentWindow = MainHandle; - windowInfo.WindowName = Application.ProductName + " | CEF Graphic Tools"; - windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); - windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); - windowInfo.Width = w; - windowInfo.Height = h; - - //Show Window - CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://gpu/", ChromiumWebBrowser.DefaultBrowserSettings, null); - } - - - - //Show Chrome Version Window - private void ShowChromeVersion() - { - int w = 1600, h = 800; - - //Setup Window - CfxWindowInfo windowInfo = new CfxWindowInfo(); - windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); - windowInfo.ParentWindow = MainHandle; - windowInfo.WindowName = Application.ProductName + " | CEF Chromium-Version Tools"; - windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); - windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); - windowInfo.Width = w; - windowInfo.Height = h; - - //Show Window - CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://version/", ChromiumWebBrowser.DefaultBrowserSettings, null); - } - - - - //Override default Browser Context Menu - private void BrowserContextMenu(object sender, CfxOnBeforeContextMenuEventArgs e) - { - e.Model.Clear(); - } - - - //Override Javascript Console Message - private void BrowserConsoleMessage(object sender, CfxOnConsoleMessageEventArgs e) - { - e.SetReturnValue(true); - } - - - //Node Changed Handler - private void BrowserNodeChanged(object sender, CfrOnFocusedNodeChangedEventArgs ev) - { - if (ev.Node != null) - { - String NodeName = ev.Node.ElementTagName.ToLower(); - //Filter if this node is an INPUT Node - if (NodeName != null && NodeName.Equals("input")) - { - String dom = ev.Node.GetElementAttribute("type").ToLower(); - - //Filter if the node Type is TEXT or PASSWORD - if (dom != null && (dom.Equals("text") || dom.Equals("password"))) - NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); - } - //Filter if this node is TEXTAREA Node - else if (NodeName != null && NodeName.Equals("textarea")) - NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); - else - NcWindow.hideVirtualKeyboard(); - } - else - NcWindow.hideVirtualKeyboard(); - - } - - - #endregion - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - #region INVOKES_&_OTHER_METHODS - - //Reload Broken Url - public void reloadBrokenPage() - { - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - if (!String.IsNullOrWhiteSpace(this.BrokenUrl)) - Browser.LoadUrl(this.BrokenUrl); - }); - else - { - if (!String.IsNullOrWhiteSpace(this.BrokenUrl)) - Browser.LoadUrl(this.BrokenUrl); - } - } - } - - //Show MainWindow Method - private void ShowWindow() - { - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - this.WindowState = FormWindowState.Maximized; - this.Opacity = 1.0; - }); - else - { - this.WindowState = FormWindowState.Maximized; - this.Opacity = 1.0; - } - } - - - if (!NcWindow.isFollowing) - { - //Start following NC Window - if (Config.VendorHmiConfig.Enabled) - NcWindow.StartNcFollowing(MainHandle, NcHandle, NcFrm.Width, NcFrm.Height); - else - NcWindow.StartStepFollowing(MainHandle); - } - } - - - - //Show Hide window - private void HideLoadingWindow() - { - //Invoke method if is needed or call the method in STD mode - - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - LdFrm.Hide(); - }); - - else - { - LdFrm.Hide(); - } - } - } - - - - //Show Message window - private void ShowLoading(String Message) - { - //Invoke method if is needed or call the method in STD mode - - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - //Set Message Status - LdFrm.Show(Message); - LdFrm.Focus(); - }); - else - { - //Set Message Status - LdFrm.Show(Message); - } - } - } - - - - //Show MainWindow Method - private void BrowserFocus() - { - //Invoke method if is needed or call the method in STD mode - if (Browser.InvokeRequired) - Browser.Invoke((MethodInvoker)delegate () { Browser.Focus(); }); - - else - Browser.Focus(); - } - - - - //Set Window Title - private void SetWindowTitle(String Title) - { - //Setup product label - if (Environment.Is64BitProcess) - Title = Application.ProductName + " x64 | " + Title; - else - Title = Application.ProductName + " x86 | " + Title; - - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () { this.Text = Title; }); - else - this.Text = Title; - } - } - - - //Show NC Method - public void ShowNCWindow() - { - if (!Config.VendorHmiConfig.Enabled) - return; - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () { - if (this.NcFrm.Owner == null) - { - this.Owner = null; - this.NcFrm.Owner = this; - } - this.NcFrm.TopMost = true; - this.NcFrm.TopMost = false; - }); - - else - { - if (this.NcFrm.Owner == null) - { - this.Owner = null; - this.NcFrm.Owner = this; - } - this.NcFrm.TopMost = true; - this.NcFrm.TopMost = false; - } - } - - } - - - - //Hide NC Method - public void HideNCWindow() - { - if (!Config.VendorHmiConfig.Enabled) - return; - - //Invoke method if is needed or call the method in STD mode - if (!this.IsDisposed) - { - if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate () - { - if (this.NcFrm.Owner != null) - { - this.NcFrm.Owner = null; - } - this.TopMost = true; - this.TopMost = false; - }); - - else - { - if (this.NcFrm.Owner != null) - { - this.NcFrm.Owner = null; - } - this.TopMost = true; - this.TopMost = false; - } - } - } - - - //CAlculate Window Position - private void CalcWindowPosition() - { - //Position of the Window - if (Screen.AllScreens.Length > 1 && Config.ClientConfig.RunningOnSecondaryScreen) - { - Screen ps = Screen.AllScreens.FirstOrDefault(S => S.Primary == true); - Screen ss = Screen.AllScreens.FirstOrDefault(S => S.Primary == false); - X = ps.Bounds.Width; - if (ss.Bounds.Top != 0) - Y = ss.Bounds.Top; - } - } - - - //Windows Keys Handler - public void keyPressedHandler(bool altPressed, bool ctrlPressed, bool shiftPressed, int key) - { - //Work only if is a Developer mode - if (Config.ClientConfig.DeveloperMode && altPressed) - { - if (key == (int)Keys.F1) - Browser.GoBack(); - - if (key == (int)Keys.F2) - Browser.GoForward(); - - if (key == (int)Keys.F5) - { - if (Browser.Url.AbsoluteUri != Constants.errorPageUrl) - Browser.Browser.ReloadIgnoreCache(); - else - Browser.LoadUrl(this.BrokenUrl); - } - - if (key == (int)Keys.F10) - ShowChromeVersion(); - - if (key == (int)Keys.F11) - ShowChromeGPU(); - - if (key == (int)Keys.F12) - ShowDevTools(); - } - } - - - #endregion - } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region WINDOW_START_&_BEHAVIOUR_METHOD + //Instance Method + public MainForm() + { + LdFrm = new LoadingForm(); + LdFrm.Owner = this; + + //Set the Loading window + ShowLoading("Setup Main View..."); + + //Initialize the Windows + InitializeComponent(); + + //Start Client Setting + InitializeClientSettings(); + + //Initialize the Browser-Components + InitializeBrowser(); + + //Set the client property + this.Text = Application.ProductName + " " + Application.ProductVersion; + this.Opacity = 0.0; + + //Initialize the Nc-Form + InitializeNcForm(); + + //Load the page + Browser.LoadUrl(Config.ConnectionConfig.StartingUrl); + //Set the title of the window in "Loading" + SetWindowTitle("Loading..."); + ShowLoading("Loading Main View..."); + + NcWindow.mainFrm = this; + } + +#if DEBUG + private void ChooseBestScreen() + { + var candidate = Screen.PrimaryScreen; + + foreach (var s in Screen.AllScreens) + { + if (s.WorkingArea.Width == 1920) candidate = s; + } + + if (candidate != Screen.PrimaryScreen) + { + this.WindowState = FormWindowState.Normal; + this.X = this.Left = candidate.WorkingArea.Left; + this.Y = this.Top = candidate.WorkingArea.Top; + this.Width = candidate.WorkingArea.Width; + this.Height = candidate.WorkingArea.Height; + this.WindowState = FormWindowState.Maximized; + } + } +#endif + + //On windows-Load Method + private void MainForm_Load(object sender, EventArgs e) + { + this.DesktopLocation = new Point(X, Y); + +#if DEBUG + ChooseBestScreen(); +#endif + } + + + + //On Resize Form + private void MainForm_Resize(object sender, EventArgs e) + { + if (this.WindowState == FormWindowState.Minimized) + { + NcWindow.ShowTaskBar(); + if (Config.VendorHmiConfig.Enabled) + NcFrm.Hide(); + } + else + { + if (Config.VendorHmiConfig.Enabled) + NcFrm.Show(); + + if (NcWindow.State == NcState.SHOW) + { + HideNCWindow(); + ShowNCWindow(); + } + else + HideNCWindow(); + } + + //Refresh Browser Paint + Browser.Refresh(); + this.Refresh(); + } + + + + //Before closing the Window -> Remove the Browser (Increase the speed of closing window) + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) + { + //Invoke method if is needed or call the method in STD mode + if (!this.IsDisposed) + { + //Show Taskbar + NcWindow.ShowTaskBar(); + + //Hide Window + this.Hide(); + + //Close Virtual Keyboard Runtime + if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) + NcWindow.closeVirtualKeyboard(); + + //Close the NC HMI && Stop Following Nc + if (Config.VendorHmiConfig.Enabled) + NcWindow.CloseNcWindow(false); + + + //Close Chromium Runtime + try + { + CfxRuntime.Shutdown(); + } + catch (Exception ex) + { + + } + } + + + } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region SETUP_METHODS + + //Initialize CMS-Client Settings + private void InitializeClientSettings() + { + //Set the Transparency Key + if (Config.ClientConfig.RenderingMethod == Constants.Rendering.CPU && Environment.OSVersion.Version.Major < 10) + TransparencyKey = Config.ClientConfig.TranspColor; + + //Calculate Window Position + CalcWindowPosition(); + } + + + + //Initialize CMS-Client Settings + private void InitializeNcForm() + { + //Create the Nc-Form + if (Config.VendorHmiConfig.Enabled) + { + NcFrm = new NcForm(Config.ClientConfig.TranspColor, X, Y); + NcHandle = NcFrm.Handle; + NcFrm.Show(); + } + + //Steup the Step variables + MainHandle = this.Handle; + } + + + + //Initialize the Browser-Component + private void InitializeBrowser() + { + //Add Custom object to browser + Browser.GlobalObject.Add(Constants.BROWSER_JS_OBJ_NAME, new BrowserJSObject(this)); + + //Add all Handlers + Browser.DisplayHandler.OnTitleChange += BrowserTitleChanged; + Browser.LoadHandler.OnLoadingStateChange += BrowserLoadsChanged; + Browser.LoadHandler.OnLoadError += BrowserLoadsError; + Browser.KeyboardHandler.OnKeyEvent += BrowserKeyPress; + Browser.ContextMenuHandler.OnBeforeContextMenu += BrowserContextMenu; + Browser.DisplayHandler.OnConsoleMessage += BrowserConsoleMessage; + //Filter only < Win_10 Platform + if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) + ChromiumWebBrowser.RemoteProcessCreated += (e) => { e.RenderProcessHandler.OnFocusedNodeChanged += BrowserNodeChanged; }; + } + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region BROWSER_EVENT_HANDLERS_METHODS + + //On browser Load-Error. Event Handler called by Browser + private void BrowserLoadsError(object sender, CfxOnLoadErrorEventArgs e) + { + //Set the Load-Error global variable to TRUE + LoadingError.Error = true; + LoadingError.ErrorInfo = e.ErrorCode.GetHashCode() + " - " + e.ErrorText; + if (e.FailedUrl != Constants.errorPageUrl) + this.BrokenUrl = e.FailedUrl; + + //write the error in the Title Bar + SetWindowTitle(LoadingError.ErrorInfo); + } + + + + //On browser Load-Changed. Event Handler called by Browser + private void BrowserLoadsChanged(object sender, CfxOnLoadingStateChangeEventArgs e) + { + //if the State is NOT "loading" + if (!e.Browser.IsLoading) + { + //Hide Loading Window + HideLoadingWindow(); + + //Show the Main Window, when the page is loaded + ShowWindow(); + + //If is an Error Show the Error page + if (LoadingError.Error && !LoadingError.ErrorInfo.Contains("ERR_ABORTED")) + { + Browser.LoadString(Config.ConnectionConfig.ErrorPage, Constants.errorPageUrl); + } + + //Set focus on the page + BrowserFocus(); + + } + //if the State is "loading" + else + { + //Hide NC Window + NcWindow.SetState(0); + HideNCWindow(); + + //Set the title of the window in "Loading" + SetWindowTitle("Loading..."); + + //Set the Load-Error global variable to FALSE + LoadingError.Error = false; + } + } + + + + //On browser Title-Changed. Event Handler called by Browser + private void BrowserTitleChanged(object sender, CfxOnTitleChangeEventArgs e) + { + if (!LoadingError.Error) + SetWindowTitle(e.Title); + } + + + + // on Key-Press Browser + private void BrowserKeyPress(object sender, CfxOnKeyEventEventArgs e) + { + + } + + + + //Show Dev Tools Window + private void ShowDevTools() + { + //Setup Dev Window + CfxWindowInfo windowInfo = new CfxWindowInfo(); + windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); + windowInfo.ParentWindow = MainHandle; + windowInfo.WindowName = Application.ProductName + " | CEF Dev Tools"; + windowInfo.X = 1120; + windowInfo.Y = 0; + windowInfo.Width = 800; + windowInfo.Height = 1080; + + //Show Dev Window + Browser.BrowserHost.ShowDevTools(windowInfo, new CfxClient(), new CfxBrowserSettings(), null); + } + + + + //Show Chrome GPU Window + private void ShowChromeGPU() + { + int w = 1600, h = 800; + + //Setup Window + CfxWindowInfo windowInfo = new CfxWindowInfo(); + windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); + windowInfo.ParentWindow = MainHandle; + windowInfo.WindowName = Application.ProductName + " | CEF Graphic Tools"; + windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); + windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); + windowInfo.Width = w; + windowInfo.Height = h; + + //Show Window + CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://gpu/", ChromiumWebBrowser.DefaultBrowserSettings, null); + } + + + + //Show Chrome Version Window + private void ShowChromeVersion() + { + int w = 1600, h = 800; + + //Setup Window + CfxWindowInfo windowInfo = new CfxWindowInfo(); + windowInfo.Style = (WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_POPUP | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE); + windowInfo.ParentWindow = MainHandle; + windowInfo.WindowName = Application.ProductName + " | CEF Chromium-Version Tools"; + windowInfo.X = (Screen.PrimaryScreen.Bounds.Width / 2) - (w / 2); + windowInfo.Y = (Screen.PrimaryScreen.Bounds.Height / 2) - (h / 2); + windowInfo.Width = w; + windowInfo.Height = h; + + //Show Window + CfxBrowserHost.CreateBrowser(windowInfo, new CfxClient(), "chrome://version/", ChromiumWebBrowser.DefaultBrowserSettings, null); + } + + + + //Override default Browser Context Menu + private void BrowserContextMenu(object sender, CfxOnBeforeContextMenuEventArgs e) + { + e.Model.Clear(); + } + + + //Override Javascript Console Message + private void BrowserConsoleMessage(object sender, CfxOnConsoleMessageEventArgs e) + { + e.SetReturnValue(true); + } + + + //Node Changed Handler + private void BrowserNodeChanged(object sender, CfrOnFocusedNodeChangedEventArgs ev) + { + if (ev.Node != null) + { + String NodeName = ev.Node.ElementTagName.ToLower(); + //Filter if this node is an INPUT Node + if (NodeName != null && NodeName.Equals("input")) + { + String dom = ev.Node.GetElementAttribute("type").ToLower(); + + //Filter if the node Type is TEXT or PASSWORD + if (dom != null && (dom.Equals("text") || dom.Equals("password"))) + NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); + } + //Filter if this node is TEXTAREA Node + else if (NodeName != null && NodeName.Equals("textarea")) + NcWindow.openVirtualKeyboard(ev.Node.ElementBounds, ev.Browser.Identifier > 1, false); + else + NcWindow.hideVirtualKeyboard(); + } + else + NcWindow.hideVirtualKeyboard(); + + } + + + #endregion + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region INVOKES_&_OTHER_METHODS + + //Reload Broken Url + public void reloadBrokenPage() + { + if (!this.IsDisposed) + { + if (this.InvokeRequired) + this.Invoke((MethodInvoker)delegate () + { + if (!String.IsNullOrWhiteSpace(this.BrokenUrl)) + Browser.LoadUrl(this.BrokenUrl); + }); + else + { + if (!String.IsNullOrWhiteSpace(this.BrokenUrl)) + Browser.LoadUrl(this.BrokenUrl); + } + } + } + + //Show MainWindow Method + private void ShowWindow() + { + + //Invoke method if is needed or call the method in STD mode + if (!this.IsDisposed) + { + if (this.InvokeRequired) + this.Invoke((MethodInvoker)delegate () + { + this.WindowState = FormWindowState.Maximized; + this.Opacity = 1.0; + }); + else + { + this.WindowState = FormWindowState.Maximized; + this.Opacity = 1.0; + } + } + + + if (!NcWindow.isFollowing) + { + //Start following NC Window + if (Config.VendorHmiConfig.Enabled) + NcWindow.StartNcFollowing(MainHandle, NcHandle, NcFrm.Width, NcFrm.Height); + else + NcWindow.StartStepFollowing(MainHandle); + } + } + + + + //Show Hide window + private void HideLoadingWindow() + { + //Invoke method if is needed or call the method in STD mode + + if (!this.IsDisposed) + { + if (this.InvokeRequired) + this.Invoke((MethodInvoker)delegate () + { + LdFrm.Hide(); + }); + + else + { + LdFrm.Hide(); + } + } + } + + + + //Show Message window + private void ShowLoading(String Message) + { + //Invoke method if is needed or call the method in STD mode + + if (!this.IsDisposed) + { + if (this.InvokeRequired) + this.Invoke((MethodInvoker)delegate () + { + //Set Message Status + LdFrm.Show(Message); + LdFrm.Focus(); + }); + else + { + //Set Message Status + LdFrm.Show(Message); + } + } + } + + + + //Show MainWindow Method + private void BrowserFocus() + { + //Invoke method if is needed or call the method in STD mode + if (Browser.InvokeRequired) + Browser.Invoke((MethodInvoker)delegate () { Browser.Focus(); }); + + else + Browser.Focus(); + } + + + + //Set Window Title + private void SetWindowTitle(String Title) + { + //Setup product label + if (Environment.Is64BitProcess) + Title = Application.ProductName + " x64 | " + Title; + else + Title = Application.ProductName + " x86 | " + Title; + + + //Invoke method if is needed or call the method in STD mode + if (!this.IsDisposed) + { + if (this.InvokeRequired) + this.Invoke((MethodInvoker)delegate () { this.Text = Title; }); + else + this.Text = Title; + } + } + + + //Show NC Method + public void ShowNCWindow() + { + if (!Config.VendorHmiConfig.Enabled) + return; + + //Invoke method if is needed or call the method in STD mode + if (!this.IsDisposed) + { + if (this.InvokeRequired) + this.Invoke((MethodInvoker)delegate () + { + if (this.NcFrm.Owner == null) + { + this.Owner = null; + this.NcFrm.Owner = this; + } + this.NcFrm.TopMost = true; + this.NcFrm.TopMost = false; + }); + + else + { + if (this.NcFrm.Owner == null) + { + this.Owner = null; + this.NcFrm.Owner = this; + } + this.NcFrm.TopMost = true; + this.NcFrm.TopMost = false; + } + } + + } + + + + //Hide NC Method + public void HideNCWindow() + { + if (!Config.VendorHmiConfig.Enabled) + return; + + //Invoke method if is needed or call the method in STD mode + if (!this.IsDisposed) + { + if (this.InvokeRequired) + this.Invoke((MethodInvoker)delegate () + { + if (this.NcFrm.Owner != null) + { + this.NcFrm.Owner = null; + } + this.TopMost = true; + this.TopMost = false; + }); + + else + { + if (this.NcFrm.Owner != null) + { + this.NcFrm.Owner = null; + } + this.TopMost = true; + this.TopMost = false; + } + } + } + + + //CAlculate Window Position + private void CalcWindowPosition() + { + //Position of the Window + if (Screen.AllScreens.Length > 1 && Config.ClientConfig.RunningOnSecondaryScreen) + { + Screen ps = Screen.AllScreens.FirstOrDefault(S => S.Primary == true); + Screen ss = Screen.AllScreens.FirstOrDefault(S => S.Primary == false); + X = ps.Bounds.Width; + if (ss.Bounds.Top != 0) + Y = ss.Bounds.Top; + } + } + + + //Windows Keys Handler + public void keyPressedHandler(bool altPressed, bool ctrlPressed, bool shiftPressed, int key) + { + //Work only if is a Developer mode + if (Config.ClientConfig.DeveloperMode && altPressed) + { + if (key == (int)Keys.F1) + Browser.GoBack(); + + if (key == (int)Keys.F2) + Browser.GoForward(); + + if (key == (int)Keys.F5) + { + if (Browser.Url.AbsoluteUri != Constants.errorPageUrl) + Browser.Browser.ReloadIgnoreCache(); + else + Browser.LoadUrl(this.BrokenUrl); + } + + if (key == (int)Keys.F10) + ShowChromeVersion(); + + if (key == (int)Keys.F11) + ShowChromeGPU(); + + if (key == (int)Keys.F12) + ShowDevTools(); + } + } + + + #endregion + } } diff --git a/Step/wwwroot/assets/styles/base/job-editor.less b/Step/wwwroot/assets/styles/base/job-editor.less index cd6b1057..ea29769a 100644 --- a/Step/wwwroot/assets/styles/base/job-editor.less +++ b/Step/wwwroot/assets/styles/base/job-editor.less @@ -7,7 +7,7 @@ display: flex; justify-content: center; padding-top: 104px; - + .job-editor-box{ width: 1808px; height: 872px; @@ -42,7 +42,7 @@ // border-radius: 2px; // font-size: 20px; // } - .job-name-box{ + .job-name-box{ font-size: 18px; line-height: 1.11; color: #4b4b4b; @@ -53,11 +53,11 @@ } .btn{ width: 70px; - } - + } + .fa{ font-size: 24px; - cursor: pointer; + cursor: pointer; } span{ @@ -110,7 +110,7 @@ } } .job-editor-body-box{ - width: 1320px; + width: 100%; height: 711px; display: flex; justify-content: flex-end; @@ -522,25 +522,25 @@ margin-top: 14px; .tool{ cursor: pointer; - img{ + img{ background-color: #DDD; } } .tool.selected{ background-color: rgba(23, 145, 255, 0.75); color: white !important; - img{ + img{ background-color: #FFF; } } .notfound{ color: @color-scarlet; - .selected img{ + .selected img{ background-color: @color-scarlet !important; } } .notfound.selected{ - img{ + img{ background-color: @color-scarlet !important; } } diff --git a/Step/wwwroot/assets/styles/style.css b/Step/wwwroot/assets/styles/style.css index 5814a1c5..c7668c40 100644 --- a/Step/wwwroot/assets/styles/style.css +++ b/Step/wwwroot/assets/styles/style.css @@ -12974,7 +12974,7 @@ footer .container button.big:before { margin: 8px 0; } .job-editor-container .job-editor-box .job-editor-body .job-editor-body-box { - width: 1320px; + width: 100%; height: 711px; display: flex; justify-content: flex-end; diff --git a/Step/wwwroot/src/components/job-editor.ts b/Step/wwwroot/src/components/job-editor.ts index 2f0399e9..84040c4c 100644 --- a/Step/wwwroot/src/components/job-editor.ts +++ b/Step/wwwroot/src/components/job-editor.ts @@ -5,12 +5,12 @@ import { objectsJob } from "src/modules/base-components/cards"; import { tool } from "src/modules/base-components/cards"; import { inputBox } from "src/modules/base-components/cards"; import jobEditorDetail from "./job-editor-detail.vue"; -import { store, AppModel } from "../store"; +import { store, AppModel, jobEditorStoreActions } from "../store"; import { ToolingService } from "../services/toolingService"; import { ModalHelper, ModalMissingTools, ModalJobAddParameter } from "../modules/base-components"; import * as iziToast from "izitoast"; import { awaiter } from "src/_base"; -import { ModalImage} from "src/modules/base-components/index"; +import { ModalImage } from "src/modules/base-components/index"; import { Watch } from "vue-property-decorator"; declare let $: any; @@ -20,7 +20,8 @@ export default class JobEditor extends Vue { programName: string = null; editing: boolean = false; - currentJob: server.Job = null; + get currentJob(): server.Job { return this.$store.state.jobEditor.currentJob; } + set currentJob(value: server.Job) { jobEditorStoreActions.setCurrentJob(this.$store, value); } limitationList: number = 3; selectedParam = null; @@ -36,26 +37,25 @@ export default class JobEditor extends Vue { get jobTools() { var $this = this; - return this.currentJob.metadata.tools.map(t => - { - var tool = $this.ncTools.find(i => i.id == t); - if(tool) - return tool - else - return t - }); + return this.currentJob.metadata.tools.map(t => { + var tool = $this.ncTools.find(i => i.id == t); + if (tool) + return tool + else + return t + }); } public get familyOptionActive(): boolean { return (this.$store.state as AppModel).tooling.familyOptionActive; - } + } get jobGenerics() { return this.currentJob ? this.currentJob.metadata.generics : null; } - async mounted(){ - awaiter (Promise.all([ + async mounted() { + awaiter(Promise.all([ await new ToolingService().GetNcTools(), await new ToolingService().GetNcFamilies(), await new ToolingService().GetToolsConfiguration() @@ -78,17 +78,17 @@ export default class JobEditor extends Vue { } deleteImageFromJob(image) { ModalHelper.AskConfirm(this.$options.filters.localize("modal_delete_image_job", "Richiesta di conferma"), - this.$options.filters.localize("modal_delete_image_job_confirm", "Sei sicuro di voler eliminare l'immagine?"), - () => { - var res = cmsClient.delImageFromJob(image.name); - if (this.currentJob) { - var images = this.currentJob.metadata.generics.images; - images.splice(images.indexOf(image), 1); - } - }, null); - + this.$options.filters.localize("modal_delete_image_job_confirm", "Sei sicuro di voler eliminare l'immagine?"), + () => { + var res = cmsClient.delImageFromJob(image.name); + if (this.currentJob) { + var images = this.currentJob.metadata.generics.images; + images.splice(images.indexOf(image), 1); + } + }, null); + } - openImage(image){ + openImage(image) { ModalHelper.modalImage.content = image.base64; ModalHelper.modalImage.title = image.name; ModalHelper.ShowModal(ModalImage); @@ -100,14 +100,14 @@ export default class JobEditor extends Vue { this.$options.filters.localize("modal_open_job_body", "Sei sicuro di aver salvato il Job?"), () => { var res = cmsClient.newJob(); - if(res){ + if (res) { var obj = JSON.parse(res); - if(obj.error) + if (obj.error) this.showError(obj.error); else this.currentJob = obj; } - + }, null); else this.currentJob = JSON.parse(cmsClient.newJob()); @@ -133,11 +133,11 @@ export default class JobEditor extends Vue { async loadJob() { var res = cmsClient.openJob(); - if(res){ + if (res) { var obj = JSON.parse(res); - if(obj.error) + if (obj.error) this.showError(obj.error); - else{ + else { this.currentJob = obj; } } @@ -146,9 +146,9 @@ export default class JobEditor extends Vue { saveJobNewPath() { if (this.currentJob) { var res = cmsClient.saveJobNewPath(JSON.stringify(this.currentJob)); - if(res){ + if (res) { var obj = JSON.parse(res); - if(obj.error) + if (obj.error) this.showError(obj.error); else this.currentJob.name = obj.name; @@ -159,9 +159,9 @@ export default class JobEditor extends Vue { saveJob() { if (this.currentJob) { var res = cmsClient.saveJob(JSON.stringify(this.currentJob)); - if(res){ + if (res) { var obj = JSON.parse(res); - if(obj.error) + if (obj.error) this.showError(obj.error); else this.currentJob.name = obj.name; @@ -176,9 +176,9 @@ export default class JobEditor extends Vue { this.$options.filters.localize("modal_open_job_body", "Sei sicuro di aver salvato il Job?"), () => { var res = cmsClient.closeJob(); - if(res){ + if (res) { var obj = JSON.parse(res); - if(obj.error) + if (obj.error) this.showError(obj.error); } else @@ -233,7 +233,7 @@ export default class JobEditor extends Vue { showError(error) { - + (iziToast as any).error({ title: "Error", message: error, @@ -244,19 +244,19 @@ export default class JobEditor extends Vue { }) } - familyNameFromId(id): any{ + familyNameFromId(id): any { var found = this.ncFamilies.find(k => k.id == id); - if(found) + if (found) return found.name; return ''; } - calcFamilyName(id): any{ - if(this.familyOptionActive) - return this.$options.filters.localize("tooling_family_abbreviation", 'F%d',id) + ' - ' + this.familyNameFromId(id); + calcFamilyName(id): any { + if (this.familyOptionActive) + return this.$options.filters.localize("tooling_family_abbreviation", 'F%d', id) + ' - ' + this.familyNameFromId(id); else return this.familyNameFromId(id); - } + } getToolIcon = function (id) { if (id == 9999) @@ -266,7 +266,7 @@ export default class JobEditor extends Vue { else return "../assets/icons/Tools/Tools.png" } - + } diff --git a/Step/wwwroot/src/components/job-editor.vue b/Step/wwwroot/src/components/job-editor.vue index 62fbb011..8eec8342 100644 --- a/Step/wwwroot/src/components/job-editor.vue +++ b/Step/wwwroot/src/components/job-editor.vue @@ -15,9 +15,9 @@ -
+
-
+
{{'drag_job_items_to_compose_job' | localize('Trascina nella parte centrale della pagina gli oggetti che desideri aggiungere al job')}} diff --git a/Step/wwwroot/src/modules/base-components/cards/input-box.vue b/Step/wwwroot/src/modules/base-components/cards/input-box.vue index 0a8688a0..d981e448 100644 --- a/Step/wwwroot/src/modules/base-components/cards/input-box.vue +++ b/Step/wwwroot/src/modules/base-components/cards/input-box.vue @@ -8,7 +8,7 @@ -
@@ -52,7 +52,7 @@ export default { return this.value; }, set(v) { - + this.$emit("input", v); } } diff --git a/Step/wwwroot/src/store/app.store.ts b/Step/wwwroot/src/store/app.store.ts index f2c4405a..f77bcee0 100644 --- a/Step/wwwroot/src/store/app.store.ts +++ b/Step/wwwroot/src/store/app.store.ts @@ -6,13 +6,13 @@ import { machineStatusStore, MachineStatusModel } from "./machineStatus.store"; import { alarmsStore, AlarmsModel } from "./alarms.store"; import { processStore, RunningProcessModel } from "./runningProcess.store"; import { localizationStore, LocalizationModel, localizationModelActions } from "./localization.store"; -import { toolingStore , ToolingStoreModel } from "./tooling.store"; -import { depotStore, DepotStoreModel} from "./depot.store"; -import { maintenanceStore, MaintenanceStoreModel} from "./maintenance.store"; +import { toolingStore, ToolingStoreModel } from "./tooling.store"; +import { depotStore, DepotStoreModel } from "./depot.store"; +import { maintenanceStore, MaintenanceStoreModel } from "./maintenance.store"; import { LocalizationService, localizationService } from "src/services/localizationService"; import { ProductionStoreModel, productionStore } from "./production.store"; - +import { jobEditorStore } from "./jobEditor.store"; Vue.use(Vuex); @@ -31,6 +31,7 @@ export interface AppModel { depot: DepotStoreModel; production: ProductionStoreModel; maintenance: MaintenanceStoreModel; + } // Mutations Name @@ -65,7 +66,8 @@ const _store = { tooling: toolingStore, depot: depotStore, production: productionStore, - maintenance: maintenanceStore + maintenance: maintenanceStore, + jobEditor: jobEditorStore }, mutations: { @@ -98,10 +100,10 @@ const _store = { // change the current language according to user's preferences. if (userinfo) localizationService.changeCurrentLanguage(userinfo.language); - // localizationModelActions.changeCurrentLanguage(context, userinfo.language); + // localizationModelActions.changeCurrentLanguage(context, userinfo.language); else localizationService.changeCurrentLanguage((context.state as AppModel).machineInfo.defaultLanguage || (context.state as AppModel).machineInfo.clientDefaultLanguage); - // localizationModelActions.changeCurrentLanguage(context, (context.state as AppModel).machineInfo.defaultLanguage || (context.state as AppModel).machineInfo.clientDefaultLanguage); + // localizationModelActions.changeCurrentLanguage(context, (context.state as AppModel).machineInfo.defaultLanguage || (context.state as AppModel).machineInfo.clientDefaultLanguage); }, CheckLogoff(context, userid) { if ((context.state as AppModel).currentUser && (context.state as AppModel).currentUser.id == userid) diff --git a/Step/wwwroot/src/store/index.js b/Step/wwwroot/src/store/index.js index f8182d9d..ba1e8be9 100644 --- a/Step/wwwroot/src/store/index.js +++ b/Step/wwwroot/src/store/index.js @@ -4,6 +4,7 @@ import { machineStatusActions, MachineStatusModel, buttonStatus } from "./machin import { AlarmsModel, alarmsModelActions, alarmsStore, AlarmModel } from "./alarms.store"; import { processModelActions, processStore, RunningProcessModel } from "./runningProcess.store"; import { LocalizationModel, languageModel, localizationModelActions } from "./localization.store"; +import { jobEditorStoreActions } from "./jobEditor.store"; export { store, @@ -21,5 +22,6 @@ export { languageModel, localizationModelActions, AlarmModel, - buttonStatus -} \ No newline at end of file + buttonStatus, + jobEditorStoreActions +} diff --git a/Step/wwwroot/src/store/jobEditor.store.ts b/Step/wwwroot/src/store/jobEditor.store.ts new file mode 100644 index 00000000..78767a1e --- /dev/null +++ b/Step/wwwroot/src/store/jobEditor.store.ts @@ -0,0 +1,27 @@ +export interface JobEditorStoreActions { + setCurrentJob(context, job: any); + clearCurrentJob(context); +} + +export const jobEditorStore = { + + state: { + currentJob: null + }, + mutations: { + setCurrentJob(state, job: any) { + state.currentJob = job; + } + }, + actions: { + setCurrentJob(context, job: any) { + context.commit("setCurrentJob", job); + }, + clearCurrentJob(context) { + context.commit("setCurrentJob", null); + } + } +} + + +export const jobEditorStoreActions = jobEditorStore.actions;