/// <summary>
        /// Really draw the tool on the view
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        private void DrawTool(double x, double y, double z)
        {
            CamBamUI ui = CamBamUI.MainUI;

            // setup tool translation

            Matrix4x4F matrix4x4F = new Matrix4x4F();

            // move the identity matrix to our delta? positions

            matrix4x4F.Translate(x - _lastX, y - _lastY, z - _lastZ);

            _lastX = x;
            _lastY = y;
            _lastZ = z;

            // tell the tool
            _tool.ApplyTransformation(matrix4x4F);

            // hijack the current EditMode
            _orgEditMode = _ActiveView.CurrentEditMode;
            _ActiveView.CurrentEditMode = this;

            // trigger OnPaint
            _ActiveView.RepaintEditMode();

            _ActiveView.CurrentEditMode = _orgEditMode;

            _orgEditMode = null;
        }
Exemple #2
0
        public override List <Polyline> GetOutlines()
        {
            List <Polyline> outlines = new List <Polyline>();

            foreach (Toolpath path in _toolpaths)
            {
                foreach (Sliced_path_item p in path.Trajectory)
                {
                    if (p.Item_type != Sliced_path_item_type.SLICE && p.Item_type != Sliced_path_item_type.SPIRAL)
                    {
                        continue;
                    }

                    Matrix4x4F mx = new Matrix4x4F();
                    mx.Translate(0.0, 0.0, path.Bottom);
                    if (Transform.Cached != null)
                    {
                        mx *= Transform.Cached;
                    }

                    Polyline poly = (Polyline)p.Clone();
                    poly.ApplyTransformation(mx);
                    outlines.Add(poly);
                }
            }

            return(outlines);
        }
Exemple #3
0
        private void paint_toolpath(ICADView iv, Display3D d3d, Color arccolor, Color linecolor, Toolpath path)
        {
            Polyline leadin = path.Leadin;

            Color chord_color = Color.FromArgb(128, CamBamConfig.Defaults.ToolpathRapidColor);

            if (leadin != null)
            {
                Matrix4x4F mx = new Matrix4x4F();
                mx.Translate(0.0, 0.0, path.Bottom);
                if (Transform.Cached != null)
                {
                    mx *= Transform.Cached;
                }

                d3d.ModelTransform = mx;
                d3d.LineWidth      = 1F;
                leadin.Paint(d3d, arccolor, linecolor);
                base.PaintDirectionVector(iv, leadin, d3d, mx);
            }

            foreach (Sliced_path_item p in path.Trajectory)
            {
                Color acol = arccolor;
                Color lcol = linecolor;

                if (p.Item_type == Sliced_path_item_type.CHORD || p.Item_type == Sliced_path_item_type.SMOOTH_CHORD || p.Item_type == Sliced_path_item_type.SLICE_SHORTCUT)
                {
                    if (!_should_draw_chords)
                    {
                        continue;
                    }
                    acol = chord_color;
                    lcol = chord_color;
                }

                if (p.Item_type == Sliced_path_item_type.DEBUG_MEDIAL_AXIS)
                {
                    acol = Color.Cyan;
                    lcol = Color.Cyan;
                }

                Matrix4x4F mx = new Matrix4x4F();
                mx.Translate(0.0, 0.0, path.Bottom);
                if (Transform.Cached != null)
                {
                    mx *= Transform.Cached;
                }

                d3d.ModelTransform = mx;
                d3d.LineWidth      = 1F;

                p.Paint(d3d, acol, lcol);
                base.PaintDirectionVector(iv, p, d3d, mx);
            }
        }
Exemple #4
0
        private void PlayButton_Click(object sender, EventArgs e)
        {
            if (!CheckState())
            {
                return;
            }

            if (GRBLMachinePlugin.Props.ToolChangeProcess == IgnoreProcessPassOn.Process)
            {
                string post = CamBamUI.MainUI.ActiveView.CADFile.MachiningOptions.PostProcessor;

                if (!string.IsNullOrEmpty(post) && post != "GRBLMachine")
                {
                    switch (MessageBox.Show("The Post Processor in Machining Options is not 'GRBLMachine'.\r\n\r\nSet Post Processor to 'GRBLMachine' and regenerate GCODE ?", "GRBLMachine - Play", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                    {
                    case DialogResult.Yes:
                        CamBamUI.MainUI.ActiveView.CADFile.MachiningOptions.PostProcessor = "GRBLMachine";
                        CAMUtils.GenerateGCodeOutput(CamBamUI.MainUI.ActiveView);
                        break;

                    case DialogResult.Cancel:
                        return;

                    case DialogResult.No:
                        break;
                    }
                }
            }

            if (GRBLMachinePlugin.Props.TrackMachine == EnabledDisabled.Enabled)
            {
                CamBamUI ui = CamBamUI.MainUI;

                // turn toolpaths et al on
                ui.ActiveView.CADFile.ShowToolpaths       = true;
                ui.ActiveView.CADFile.ShowRapids          = true;
                ui.ActiveView.CADFile.ShowDirectionVector = true;
                ui.ViewContextMenus.RefreshCheckedMenus();

                // runs in background, so just start it, we'll do something else in the meanwhile
                CAMUtils.GenerateToolpaths(ui.ActiveView);

                // fit current drawing and current perspective to fit view
                ui.ActiveView.ZoomToFitEx();

                // setup ISO-like perspective ( inspired from ViewToolbarAddins (y) )
                ViewProjection vp = ui.ActiveView.ViewProjection;
                Matrix4x4F     mx = Matrix4x4F.Identity;

                mx.Scale(vp.ViewMatrix4x4F.GetScale());
                mx.RotZ(-Math.PI / 4f);                 // 90 degrees
                mx.RotX(-Math.PI / (4f * (60f / 90f))); // 60 degrees
                mx.Translate(vp.ViewMatrix4x4F.m[12], vp.ViewMatrix4x4F.m[13], vp.ViewMatrix4x4F.m[14]);

                vp.ViewMatrix4x4F = mx;

                // re-zoom, since drawing may now be outside the view
                ui.ActiveView.ZoomToFitEx();

                // wait until GenerateToolpaths is ready
                while (ui.ActiveView.IsThinking)
                {
                    Application.DoEvents();
                }

                // re-zoom, since toolpaths may be outside the view
                ui.ActiveView.ZoomToFitEx();
            }

            _sendingFileName          = FileName.Text;
            _writeThread              = new Thread(WriteThread);
            _writeThread.Name         = "GCODE-SenderThread";
            _writeThread.IsBackground = true;

            PauseButton.Checked = false;

            EnableButtons();

            FileName.Enabled     = false;
            BrowseButton.Enabled = false;
            LinesSent.Text       = LinesTotal.Text = "-";

            _pauseEvent.Set();
            _fileData.Clear();

            _writeThread.Start();
        }