private void Window_Load(object sender, EventArgs e)
        {
            foreach (TabItem tab in UIUtils.FindLogicalChildren <TabItem>(ui.tabMode))
            {
                ICNCView view = getView(tab);
                if (view != null)
                {
                    view.Setup(UIViewModel, AppConfig.Settings);
                    tab.IsEnabled = view.ViewType == ViewType.GRBL || view.ViewType == ViewType.AppConfig;
                }
            }

            if (!AppConfig.Settings.GCodeViewer.IsEnabled)
            {
                ShowView(false, ViewType.GCodeViewer);
            }

            xx.ItemsSource = UIViewModel.SidebarItems;
            UIViewModel.SidebarItems.Add(new SidebarItem("_Jog", jogControl));
            UIViewModel.SidebarItems.Add(new SidebarItem("_Macros", macroControl));
            UIViewModel.SidebarItems.Add(new SidebarItem("_Goto", gotoControl));
            UIViewModel.SidebarItems.Add(new SidebarItem("M_Pos", mposFlyout));
//            UIViewModel.SidebarItems.Add(new SidebarItem("_THC Monitor", thcControl));

            UIViewModel.CurrentView = getView((TabItem)tabMode.Items[tabMode.SelectedIndex = 0]);
            System.Threading.Thread.Sleep(50);
            Comms.com.PurgeQueue();
            UIViewModel.CurrentView.Activate(true, ViewType.Startup);

            if (!string.IsNullOrEmpty(AppConfig.Settings.FileName))
            {
                // Delay loading until app is ready
                Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new System.Action(() =>
                {
                    GCode.File.Load(AppConfig.Settings.FileName);
                }));
            }

            IGCodeConverter c = new Excellon2GCode();

            GCode.File.AddConverter(c.GetType(), c.FileType);
            c = new HpglToGCode();
            GCode.File.AddConverter(c.GetType(), c.FileType);

            GCode.File.AddTransformer(typeof(CNC.Controls.ArcsToLines), "Arcs to lines", UIViewModel.TransformMenuItems);
            GCode.File.AddTransformer(typeof(CNC.Controls.DragKnife.DragKnifeViewModel), "Add drag knife moves", UIViewModel.TransformMenuItems);
        }
Exemple #2
0
        private void Window_Load(object sender, EventArgs e)
        {
            if (AppConfig.Settings.Base.KeepWindowSize)
            {
                if (AppConfig.Settings.Base.WindowWidth == -1)
                {
                    WindowState = WindowState.Maximized;
                }
                else
                {
                    Width  = Math.Max(Math.Min(AppConfig.Settings.Base.WindowWidth, SystemParameters.PrimaryScreenWidth), MinWidth);
                    Height = Math.Max(Math.Min(AppConfig.Settings.Base.WindowHeight, SystemParameters.PrimaryScreenHeight), MinHeight);
                    if (Left + Width > SystemParameters.PrimaryScreenWidth)
                    {
                        Left = 0d;
                    }
                    if (Top + Height > SystemParameters.PrimaryScreenHeight)
                    {
                        Top = 0d;
                    }
                }
            }
            saveWinSize = AppConfig.Settings.Base.KeepWindowSize;
            var appconf = getView(getTab(ViewType.AppConfig));

            appconf.Setup(UIViewModel, AppConfig.Settings);

            foreach (TabItem tab in UIUtils.FindLogicalChildren <TabItem>(ui.tabMode))
            {
                ICNCView view = getView(tab);
                if (view != null && view != appconf)
                {
                    view.Setup(UIViewModel, AppConfig.Settings);
                    tab.IsEnabled = view.ViewType == ViewType.GRBL || view.ViewType == ViewType.AppConfig;
                }
            }
#if ADD_CAMERA
            enableCamera(this);
#else
            menuCamera.Visibility = Visibility.Hidden;
#endif
            if (!AppConfig.Settings.GCodeViewer.IsEnabled)
            {
                ShowView(false, ViewType.GCodeViewer);
            }

            xx.ItemsSource = UIViewModel.SidebarItems;
            if (AppConfig.Settings.Jog.Mode != JogConfig.JogMode.Keypad)
            {
                UIViewModel.SidebarItems.Add(new SidebarItem(jogControl));
            }
            UIViewModel.SidebarItems.Add(new SidebarItem(macroControl));
            UIViewModel.SidebarItems.Add(new SidebarItem(gotoControl));
            UIViewModel.SidebarItems.Add(new SidebarItem(outlineFlyout));
            UIViewModel.SidebarItems.Add(new SidebarItem(mposFlyout));
//          UIViewModel.SidebarItems.Add(new SidebarItem(thcControl));

            UIViewModel.CurrentView = getView((TabItem)tabMode.Items[tabMode.SelectedIndex = 0]);
            System.Threading.Thread.Sleep(50);
            Comms.com.PurgeQueue();
            UIViewModel.CurrentView.Activate(true, ViewType.Startup);

            if (!string.IsNullOrEmpty(AppConfig.Settings.FileName))
            {
                // Delay loading until app is ready
                Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new System.Action(() =>
                {
                    GCode.File.Load(AppConfig.Settings.FileName);
                }));
            }

            IGCodeConverter c = new Excellon2GCode();
            GCode.File.AddConverter(c.GetType(), c.FileType);
            c = new HpglToGCode();
            GCode.File.AddConverter(c.GetType(), c.FileType);

            GCode.File.AddTransformer(typeof(GCodeRotateViewModel), (string)FindResource("MenuRotate"), UIViewModel.TransformMenuItems);
            GCode.File.AddTransformer(typeof(ArcsToLines), (string)FindResource("MenuArcsToLines"), UIViewModel.TransformMenuItems);
            GCode.File.AddTransformer(typeof(GCodeCompress), (string)FindResource("MenuCompress"), UIViewModel.TransformMenuItems);
            GCode.File.AddTransformer(typeof(CNC.Controls.DragKnife.DragKnifeViewModel), (string)FindResource("MenuDragKnife"), UIViewModel.TransformMenuItems);
        }