public override void PropertyChanged(string propertyname, object newvalue)
        {
            PropertyInfo prop = GetType().GetProperty(propertyname);

            if (prop != null)
            {
                object[] attr = prop.GetCustomAttributes(typeof(DescriptionAttribute), true);

                if (attr.Length != 0 && (attr[0] as DescriptionAttribute).Description.StartsWith("$"))
                {
                    if (!GRBLMachinePlugin.Connected || (GRBLMachinePlugin.CurrentMachineState != GRBLMachinePlugin.MachineState.Idle && GRBLMachinePlugin.CurrentMachineState != GRBLMachinePlugin.MachineState.Jog))
                    {
                        MessageBox.Show("Machine not " + (GRBLMachinePlugin.Connected ? "idle" : "connected") + ",\r\n\r\n changes will not be send to the machine", "GRBL Machine", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        string[] dollar = (attr[0] as DescriptionAttribute).Description.Split(' ');

                        string val = newvalue.ToString();

                        if (newvalue.GetType().IsEnum)
                        {
                            val = ((int)newvalue).ToString();
                        }
                        else if (newvalue is Boolean)
                        {
                            val = ((bool)newvalue) ? "1" : "0";
                        }

                        ConnectionExpander.WriteCOMPort(dollar[0] + "=" + val);

                        GRBLMachinePlugin.PropertyChange(propertyname, newvalue);

                        base.PropertyChanged(propertyname, newvalue);
                    }
                }
                else
                {
                    GRBLMachinePlugin.PropertyChange(propertyname, newvalue);

                    base.PropertyChanged(propertyname, newvalue);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method does al the magic of integrating GRBLMachine's UI into CamBam's
        /// </summary>
        /// <returns></returns>
        private static bool InstallTab()
        {
            CamBamUI ui = CamBamUI.MainUI;

            // Since CamBam comes with an unconstructed UI, durin 'InitPlugin' there is no UI content yet...
            if (ui.SysTabs != null)
            {
                // get the tabcontrol which hosts CamBam's 'Drawing' and 'System' pages
                TabControl tabs = ui.SysTabs.Tabs();

                //
                // Controversial action #2: Should a plugin tamper with CamBam's UI ??? ;) :P
                //
                if (Props.EnableVisualStyles == EnabledDisabled.Enabled)
                {
                    // set some properties on SysTabs because it just looks better when VisualStyles ar on.
                    ui.SysTabs.BackColor = SystemColors.Control;
                    ui.SysTabs.Padding   = new Padding(3, 6, 1, 0);

                    foreach (TabPage p in tabs.TabPages)
                    {
                        p.UseVisualStyleBackColor = false;
                    }
                }

                //
                // Just for conveniance: Add a right-click menu to clear the messages
                //
                ThisApplication.TextLogger.ContextMenu = new ContextMenu();
                ThisApplication.TextLogger.ContextMenu.MenuItems.Add(new MenuItem("Clear Messages", (x, y) => { ThisApplication.ClearLogMessages(); }));

                // hook up all eventhandlers
                ThisApplication.TopWindow.FormClosing += TopWindow_FormClosing;

                tabs.SelectedIndexChanged += Tabs_SelectedIndexChanged;
                tabs.Selecting            += Tabs_Selecting;

                State += GRBLMachinePlugin_State;
                ConnectionExpander.Connected    += ConnectionExpander_Connected;
                ConnectionExpander.Disconnected += ConnectionExpander_Disconnected;

                // add the GRBL icon to the tabcontrol's imagelist
                tabs.ImageList.Images.Add(Resources.Grbl_Logo_150px);
                Page.ImageIndex = tabs.ImageList.Images.Count - 1;
                // add our UI to the new tabpage
                Page.Controls.Add(new GRBLMachinePage());
                // finally add the Machine page to the tabcontrol
                tabs.TabPages.Add(Page);

                // set the various UI states according to what was saved in GRBLMachine.config
                (Page.Controls[0] as GRBLMachinePage).DisplayExpander.Expanded    = Props.DisplayExpanded;
                (Page.Controls[0] as GRBLMachinePage).ProductionExpander.Expanded = Props.ProductionExpanded;
                (Page.Controls[0] as GRBLMachinePage).JoggingExpander.Expanded    = Props.JoggingExpanded;
                (Page.Controls[0] as GRBLMachinePage).ConsoleExpander.Expanded    = Props.ConsoleExpanded;
                (Page.Controls[0] as GRBLMachinePage).ConnectionExpander.Expanded = Props.ConnectionExpanded;
                (Page.Controls[0] as GRBLMachinePage).AboutExpander.Expanded      = Props.AboutExpanded;

                CamBamUI.MainUI.SysTabs.SelectedTab = Props.SelectedTab;

                // greet the user :)
                GRBLMachinePlugin.Log("Welcome to GRBL Machine v" + Version + "\n\n");

                return(true);
            }
            return(false);
        }