Exemplo n.º 1
0
        /// <summary>
        /// Checks the state of the object.
        /// If it is outside print are it starts pulsing
        /// </summary>
        public void updateSTLState(PrintModel stl2)
        {
            bool dataChanged       = false;
            FormPrinterSettings ps = Main.printerSettings;

            stl2.UpdateBoundingBox();
            LinkedList <PrintModel> testList = ListObjects(false);

            foreach (PrintModel pm in testList)
            {
                pm.oldOutside = pm.outside;
                pm.outside    = false;
            }
            foreach (PrintModel pm in testList)
            {
                foreach (PrintModel pm2 in testList)
                {
                    if (pm == pm2)
                    {
                        continue;
                    }
                    if (pm2.bbox.IntersectsBox(pm.bbox))
                    {
                        pm.outside  = true;
                        pm2.outside = true;
                    }
                }
            }
            foreach (PrintModel stl in testList)
            {
                if (!ps.PointInside(stl.xMin, stl.yMin, stl.zMin) ||
                    !ps.PointInside(stl.xMax, stl.yMin, stl.zMin) ||
                    !ps.PointInside(stl.xMin, stl.yMax, stl.zMin) ||
                    !ps.PointInside(stl.xMax, stl.yMax, stl.zMin) ||
                    !ps.PointInside(stl.xMin, stl.yMin, stl.zMax) ||
                    !ps.PointInside(stl.xMax, stl.yMin, stl.zMax) ||
                    !ps.PointInside(stl.xMin, stl.yMax, stl.zMax) ||
                    !ps.PointInside(stl.xMax, stl.yMax, stl.zMax))
                {
                    stl.outside = true;
                }
            }
            foreach (PrintModel pm in testList)
            {
                if (pm.oldOutside != pm.outside)
                {
                    dataChanged = true;
                    pm.ForceViewRegeneration();
                    if (Main.threeDSettings.pulseOutside.Checked)
                    {
                        if (!pm.hasAnimationWithName("pulse") && pm.outside)
                        {
                            pm.addAnimation(new PulseAnimation("pulse", 0.03, 0.03, 0.03, 0.3));
                        }
                        if (pm.hasAnimationWithName("pulse") && !pm.outside)
                        {
                            pm.removeAnimationWithName("pulse");
                        }
                    }
                }
            }

            if (dataChanged)
            {
                listObjects.Refresh();
            }
        }
Exemplo n.º 2
0
        public void Autoposition()
        {
            if (listObjects.Items.Count == 1)
            {
                PrintModel stl = (PrintModel)listObjects.Items[0].Tag;
                stl.Center(Main.printerSettings.BedLeft + Main.printerSettings.PrintAreaWidth / 2, Main.printerSettings.BedFront + Main.printerSettings.PrintAreaDepth / 2);
                Main.main.threedview.UpdateChanges();
                return;
            }
            if (autosizeFailed)
            {
                return;
            }
            RectPacker          packer = new RectPacker(1, 1);
            int                 border = 3;
            FormPrinterSettings ps = Main.printerSettings;
            float               maxW = ps.PrintAreaWidth;
            float               maxH = ps.PrintAreaDepth;
            float               xOff = ps.BedLeft, yOff = ps.BedFront;

            if (ps.printerType == 1)
            {
                if (ps.DumpAreaFront <= 0)
                {
                    yOff  = ps.BedFront + ps.DumpAreaDepth - ps.DumpAreaFront;
                    maxH -= yOff;
                }
                else if (ps.DumpAreaDepth + ps.DumpAreaFront >= maxH)
                {
                    yOff  = ps.BedFront + -(maxH - ps.DumpAreaFront);
                    maxH += yOff;
                }
                else if (ps.DumpAreaLeft <= 0)
                {
                    xOff  = ps.BedLeft + ps.DumpAreaWidth - ps.DumpAreaLeft;
                    maxW -= xOff;
                }
                else if (ps.DumpAreaWidth + ps.DumpAreaLeft >= maxW)
                {
                    xOff  = ps.BedLeft + maxW - ps.DumpAreaLeft;
                    maxW += xOff;
                }
            }
            foreach (PrintModel stl in ListObjects(false))
            {
                int w = 2 * border + (int)Math.Ceiling(stl.xMax - stl.xMin);
                int h = 2 * border + (int)Math.Ceiling(stl.yMax - stl.yMin);
                if (!packer.addAtEmptySpotAutoGrow(new PackerRect(0, 0, w, h, stl), (int)maxW, (int)maxH))
                {
                    autosizeFailed = true;
                }
            }
            if (autosizeFailed)
            {
                MessageBox.Show("Too many objects on printer bed for automatic packing.\r\nPacking disabled until elements are removed.",
                                "Printer bed full", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            float xAdd = (maxW - packer.w) / 2.0f;
            float yAdd = (maxH - packer.h) / 2.0f;

            foreach (PackerRect rect in packer.vRects)
            {
                PrintModel s    = (PrintModel)rect.obj;
                float      xPos = xOff + xAdd + rect.x + border;
                float      yPos = yOff + yAdd + rect.y + border;
                s.Position.x += xPos - s.xMin;
                s.Position.y += yPos - s.yMin;
                s.UpdateBoundingBox();
            }
            Main.main.threedview.UpdateChanges();
        }
Exemplo n.º 3
0
        public void Autoposition()
        {
            if (PreView.models.Count == 1)
            {
                PrintModel stl = (PrintModel)PreView.models.First(x => true);
                stl.Center(SettingsProvider.Instance.Printer_Settings.BedLeft + SettingsProvider.Instance.Printer_Settings.PrintAreaWidth / 2, SettingsProvider.Instance.Printer_Settings.BedFront + SettingsProvider.Instance.Printer_Settings.PrintAreaDepth / 2);
                return;
            }

            if (autosizeFailed)
            {
                return;
            }
            RectPacker packer = new RectPacker(1, 1);
            int        border = 3;

            PrinterSettingsModel ps = SettingsProvider.Instance.Printer_Settings;
            float maxW = ps.PrintAreaWidth;
            float maxH = ps.PrintAreaDepth;
            float xOff = ps.BedLeft, yOff = ps.BedFront;

            if (ps.printerType == 1)
            {
                if (ps.DumpAreaFront <= 0)
                {
                    yOff  = ps.BedFront + ps.DumpAreaDepth - ps.DumpAreaFront;
                    maxH -= yOff;
                }
                else if (ps.DumpAreaDepth + ps.DumpAreaFront >= maxH)
                {
                    yOff  = ps.BedFront + -(maxH - ps.DumpAreaFront);
                    maxH += yOff;
                }
                else if (ps.DumpAreaLeft <= 0)
                {
                    xOff  = ps.BedLeft + ps.DumpAreaWidth - ps.DumpAreaLeft;
                    maxW -= xOff;
                }
                else if (ps.DumpAreaWidth + ps.DumpAreaLeft >= maxW)
                {
                    xOff  = ps.BedLeft + maxW - ps.DumpAreaLeft;
                    maxW += xOff;
                }
            }
            foreach (PrintModel stl in PreView.models)
            {
                int w = 2 * border + (int)Math.Ceiling(stl.xMax - stl.xMin);
                int h = 2 * border + (int)Math.Ceiling(stl.yMax - stl.yMin);
                if (!packer.addAtEmptySpotAutoGrow(new PackerRect(0, 0, w, h, stl), (int)maxW, (int)maxH))
                {
                    autosizeFailed = true;
                }
            }
            if (autosizeFailed)
            {
                System.Windows.MessageBox.Show("Too many objects on printer bed for automatic packing.\r\nPacking disabled until elements are removed.",
                                               "Printer bed full");
                return;
            }
            float xAdd = (maxW - packer.w) / 2.0f;
            float yAdd = (maxH - packer.h) / 2.0f;

            foreach (PackerRect rect in packer.vRects)
            {
                PrintModel s    = (PrintModel)rect.obj;
                float      xPos = xOff + xAdd + rect.x + border;
                float      yPos = yOff + yAdd + rect.y + border;
                s.Position.X += xPos - s.xMin;
                s.Position.Y += yPos - s.yMin;
                s.UpdateBoundingBox();
            }
        }