Ejemplo n.º 1
0
        private void Message(string message)
        {
            string m = message + Path.GetFileName(_sendingFileName);

            GRBLMachinePlugin.Log("\n" + m);
            ThisApplication.AddLogMessage(m);
        }
Ejemplo n.º 2
0
        public override void Draw()
        {
            CamBam.CAD.Line line = new CamBam.CAD.Line(new Point2F(this.X1, this.Y1), new Point2F(this.X2, this.Y2));

            ThisApplication.AddLogMessage(3, string.Format("Add new line ({0}, {1}) ({2}, {3})", this.X1, this.Y1, this.X2, this.Y2));

            CamBam.UI.CamBamUI.MainUI.InsertEntity(line);
        }
Ejemplo n.º 3
0
        public override void Draw()
        {
            Point2F point = new Point2F(this.CenterX, this.CenterY);

            CamBam.CAD.Circle rect = new CamBam.CAD.Circle(point, this.Radius);

            ThisApplication.AddLogMessage(3, string.Format("Add new circle ({0}, {1}) Radius={2}", this.CenterX, this.CenterY, this.Radius));

            CamBam.UI.CamBamUI.MainUI.InsertEntity(rect);
        }
Ejemplo n.º 4
0
        public void DrawSVGFile()
        {
            ThisApplication.AddLogMessage(4, ">> DrawSVGFile()");

            this.Groups.ForEach(g =>
            {
                g.Draw();
            });

            ThisApplication.AddLogMessage(4, "<< DrawSVGFile");
        }
Ejemplo n.º 5
0
        public override void Draw()
        {
            Point3F point = new Point3F(this.X, this.Y, 0);

            PolyRectangle rect = new PolyRectangle(point, this.Width, this.Height);

            rect.CornerRadius = this.RX;

            ThisApplication.AddLogMessage(3, string.Format("Add new rect ({0}, {1}) W={2} H={3}", this.X, this.Y, this.Width, this.Height));

            CamBam.UI.CamBamUI.MainUI.InsertEntity(rect);
        }
Ejemplo n.º 6
0
        private void ProcessGroups(List <XElement> groups)
        {
            ThisApplication.AddLogMessage(4, ">> DrawSVGFile()");

            groups.ForEach(g =>
            {
                Group group = new Group(g);
                this.Groups.Add(group);
            });

            ThisApplication.AddLogMessage(4, "<< DrawSVGFile");
        }
Ejemplo n.º 7
0
        private static void ProcessSVGFilesImport(List <string> files)
        {
            ThisApplication.AddLogMessage(4, string.Format(">> ProcessSVGFileImport({0})", string.Join(",", files.ToArray())));

            files.ForEach(f =>
            {
                SVGFile svg = new SVGFile(f);

                svg.DrawSVGFile();
            });

            ThisApplication.AddLogMessage(4, "<< ProcessSVGFileImport");
        }
Ejemplo n.º 8
0
        public void Draw()
        {
            ThisApplication.AddLogMessage(4, ">> Draw()");

            if (!CamBam.UI.CamBamUI.MainUI.ActiveView.CADFile.Layers.ContainsKey(this.Name))
            {
                CamBam.UI.CamBamUI.MainUI.ActiveView.CADFile.CreateLayer(this.Name);
            }
            CamBam.UI.CamBamUI.MainUI.ActiveView.CADFile.SetActiveLayer(this.Name);

            this.Elements.ForEach(l => l.Draw());

            ThisApplication.AddLogMessage(4, "<< Draw");
        }
Ejemplo n.º 9
0
        private void GotoMouse_Click(object sender, EventArgs e)
        {
            MoveToLocationMode editMode = new MoveToLocationMode(CamBamUI.MainUI.ActiveView);

            editMode.DefaultValue = (object)null;
            editMode.Prompt       = "Select Move Destination";
            editMode.OnReturnOK  += (o, ea) => {
                Point3F moveDelta = editMode.MoveDestination - editMode.MoveSource;
                ThisApplication.AddLogMessage("MoveDelta = " + moveDelta);
                ConnectionExpander.WriteCOMPortFmt("$J=G91 G21 X{0:+#;-#;+0} Y{1:+#;-#;+0} F4000", moveDelta.X, moveDelta.Y);
            };
            CamBamUI.MainUI.ActiveView.SetEditMode((EditMode)editMode);
            CamBamUI.MainUI.ActiveView.RepaintEditMode();
        }
Ejemplo n.º 10
0
        public SVGFile(string fileName)
        {
            ThisApplication.AddLogMessage(4, string.Format(">> SVGFile({0})", fileName));

            try
            {
                this.FileName = fileName;
                this.Groups   = new List <Group>();

                SVGFile.Provider = new NumberFormatInfo();
                SVGFile.Provider.NumberDecimalSeparator = ".";

                ProcessSVGFile();
            }
            catch (Exception ex)
            {
                ThisApplication.AddLogMessage(0, string.Format("Exception: {0} StackTrace: {1}", ex.Message, ex.StackTrace));
            }

            ThisApplication.AddLogMessage(4, "<< SVGFile");
        }
Ejemplo n.º 11
0
        private void ProcessSVGFile()
        {
            ThisApplication.AddLogMessage(4, string.Format(">> ProcessSVGFile({0})", this.FileName));

            List <XElement> groups = new List <XElement>();

            XDocument XD          = XDocument.Load(this.FileName);
            XElement  SVG_Element = XD.Root;

            groups = SVG_Element.Descendants("{http://www.w3.org/2000/svg}g").ToList();
            if (groups != null && groups.Count > 0)
            {
                ProcessGroups(groups);
            }
            else
            {
                this.Groups.Add(new Group(SVG_Element));
            }

            ThisApplication.AddLogMessage(4, "<< ProcessSVGFile");
        }
Ejemplo n.º 12
0
        public override void Draw()
        {
            Polyline poly = new Polyline();

            for (int i = 0; i < this.Points.Count; i++)
            {
                PathPoint point = this.Points[i];

                switch (point.PType)
                {
                case PointType.M:
                case PointType.L:
                    poly.Add(point.P);

                    break;
                }
            }

            poly.Closed = this.Closed;

            ThisApplication.AddLogMessage(3, string.Format("Add new path (Number of points={0}, Closed={1})", this.Points.Count, this.Closed));

            CamBam.UI.CamBamUI.MainUI.InsertEntity(poly);
        }
Ejemplo n.º 13
0
        // about 9500 lines of code
        // or 25000 lines including styles i made
        // n o   o n e   c a r e s    l m o o o oo

        // My attempt at making the application single instance only,
        // and opening a window on that instance. idk how to get the
        // instance though which is the problem... so rip.

        //[DllImport("user32", CharSet = CharSet.Unicode)]
        //static extern IntPtr FindWindow(string cls, string win);

        //[DllImport("user32")]
        //static extern IntPtr SetForegroundWindow(IntPtr hWnd);

        //public Mutex mMutex;

        //public App()
        //{
        //    SingleInstanceCheck();
        //    Exit += App_Exit;
        //}

        //private void App_Exit(object sender, ExitEventArgs e)
        //{
        //    mMutex?.Dispose();
        //    mMutex.Close();
        //}

        //public void SingleInstanceCheck()
        //{
        //    bool useSingleWindow = true;
        //    if (useSingleWindow)
        //    {
        //        bool isOnlyInstance = false;
        //        mMutex = new Mutex(true, "Notepad2", out isOnlyInstance);
        //        if (!isOnlyInstance)
        //        {
        //            MessageBox.Show("Another instance exists! Adding this instance's window to that one.");
        //            IntPtr winHandle = FindWindow(null, "SharpPad");
        //            // winHandle is null because it's on another thread or something.
        //            if (winHandle != IntPtr.Zero)
        //            {
        //                HwndTarget target = new HwndTarget(winHandle);
        //                HwndSource fromHwnd = HwndSource.FromHwnd(winHandle);
        //                if (fromHwnd.RootVisual is Window window)
        //                {
        //                    MessageBox.Show($"Window fetched: " +
        //                        $"Title: {window.Title}\n");
        //                    if (window is NotepadWindow win)
        //                    {
        //                        MessageBox.Show("Window is notepad window:" +
        //                            $"Items count: {win.Notepad.NotepadItems.Count}");
        //                    }
        //                }
        //            }
        //            Shutdown();
        //        }
        //    }
        //}

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            ThisApplication.Startup(e.Args);
        }
Ejemplo n.º 14
0
 // Simple menu handler
 static void TestPlugin_Click(object sender, EventArgs e)
 {
     ThisApplication.MsgBox(string.Format("SVG Loader (c) j.vater 2019 version {0}", _version));
 }
Ejemplo n.º 15
0
        protected override void _GenerateToolpathsWorker()
        {
            try
            {
                base.reset_toolpaths();

                if (base.ToolDiameter.Cached == 0)
                {
                    Logger.err("tool diameter is zero");
                    base.MachineOpStatus = MachineOpStatus.Errors;
                    return;
                }

                if (_stepover.Cached == 0 || _stepover.Cached > 1)
                {
                    Logger.err("stepover should be > 0 and <= 1");
                    base.MachineOpStatus = MachineOpStatus.Errors;
                    return;
                }

                // XXX: is it needed ?
                base.UpdateGeometryExtrema(base._CADFile);
                base._CADFile.MachiningOptions.UpdateGeometryExtrema(base._CADFile);
                ShapeList shapes = new ShapeList();
                shapes.ApplyTransformations = true;
                shapes.AddEntities(base._CADFile, base.PrimitiveIds);
                shapes = shapes.DetectRegions();

                bool found_opened_polylines = false;
                for (int i = shapes.Count - 1; i >= 0; i--)
                {
                    if (shapes[i].Shape is Polyline && !((Polyline)shapes[i].Shape).Closed)
                    {
                        found_opened_polylines = true;
                        shapes.RemoveAt(i);
                    }
                }
                if (found_opened_polylines)
                {
                    Logger.warn("ignoring open polylines");
                    base.MachineOpStatus = MachineOpStatus.Warnings;
                }

                List <Sliced_path> trajectories = new List <Sliced_path>();

                foreach (ShapeListItem shape in shapes)
                {
                    Sliced_path traj = gen_pocket(shape);
                    if (traj != null)
                    {
                        trajectories.Add(traj);
                    }
                }

                if (trajectories.Count == 0)
                {
                    return;
                }

                base.insert_toolpaths(trajectories);

                if (base.MachineOpStatus == MachineOpStatus.Unknown)
                {
                    base.MachineOpStatus = MachineOpStatus.OK;
                }
            }
            catch (Exception ex)
            {
                base.MachineOpStatus = MachineOpStatus.Errors;
                ThisApplication.HandleException(ex);
            }
            finally
            {
                base._GenerateToolpathsFinal();
            }
        }
Ejemplo n.º 16
0
 static public void err(string s, params object[] args)
 {
     ThisApplication.AddLogMessage("Trocho error: " + s, args);
 }
Ejemplo n.º 17
0
 static public void log(string s, params object[] args)
 {
     ThisApplication.AddLogMessage(4, s, args);
 }
Ejemplo n.º 18
0
 static public void warn(string s, params object[] args)
 {
     ThisApplication.AddLogMessage("Trocho warning: " + s, args);
 }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        protected override void _GenerateToolpathsWorker()
        {
            try
            {
                base.reset_toolpaths();

                if (base.ToolDiameter.Cached == 0)
                {
                    Logger.err("tool diameter is zero");
                    base.MachineOpStatus = MachineOpStatus.Errors;
                    return;
                }

                if (_cut_width.Cached != 0 && _cut_width.Cached < base.ToolDiameter.Cached * 1.05)
                {
                    Logger.err("cut width is too small");
                    base.MachineOpStatus = MachineOpStatus.Errors;
                    return;
                }

                if (_stepover.Cached == 0 || _stepover.Cached > 1)
                {
                    Logger.err("stepover should be > 0 and <= 1");
                    base.MachineOpStatus = MachineOpStatus.Errors;
                    return;
                }

                // XXX: is it needed ?
                base.UpdateGeometryExtrema(base._CADFile);
                base._CADFile.MachiningOptions.UpdateGeometryExtrema(base._CADFile);
                ShapeList shapes = new ShapeList();
                shapes.ApplyTransformations = true;
                shapes.AddEntities(base._CADFile, base.PrimitiveIds);
                shapes = shapes.DetectRegions();

                List <Sliced_path> trajectories = new List <Sliced_path>();

                bool is_inside = _cut_side.Cached == InsideOutsideOptions.Inside;

                Point2F startpoint = (Point2F)base.StartPoint.Cached;

                foreach (ShapeListItem shape in shapes)
                {
                    if (trajectories.Count != 0)
                    {
                        startpoint = lastpt(trajectories);
                    }

                    if (shape.Shape is Polyline)
                    {
                        trajectories.AddRange(gen_profile((Polyline)shape.Shape, is_inside, startpoint));
                    }
                    else if (shape.Shape is CamBam.CAD.Region)
                    {
                        trajectories.AddRange(gen_profile((CamBam.CAD.Region)shape.Shape, is_inside, startpoint));
                    }
                }

                if (trajectories.Count == 0)
                {
                    return;
                }

                base.insert_toolpaths(trajectories);

                if (base.MachineOpStatus == MachineOpStatus.Unknown)
                {
                    base.MachineOpStatus = MachineOpStatus.OK;
                }
            }
            catch (Exception ex)
            {
                base.MachineOpStatus = MachineOpStatus.Errors;
                ThisApplication.HandleException(ex);
            }
            finally
            {
                base._GenerateToolpathsFinal();
            }
        }
Ejemplo n.º 21
0
 #pragma warning disable 0467
 private void ThisDocument_Shutdown(object sender, System.EventArgs e)
 {
     ThisApplication.Quit();
 }