示例#1
0
        public void openAndAddObject(string file)
        {
            PrintModel model = new PrintModel();
            FileInfo   f     = new FileInfo(file);

            InfoProgressPanel ipp = InfoProgressPanel.Create(Trans.T1("IMPORTING_1", f.Name), true);

            ipp.Action = Trans.T("L_LOADING...");
            ipp.Dock   = DockStyle.Top;
            panelControls.Controls.Add(ipp);
            panelControls.Update();
            model.Load(file, ipp);
            model.Center(Main.printerSettings.PrintAreaWidth / 2, Main.printerSettings.PrintAreaDepth / 2);
            model.Land();
            if (model.ActiveModel.triangles.Count > 0)
            {
                AddObject(model);
                cont.models.AddLast(model);

                Autoposition();
                model.addAnimation(new DropAnimation("drop"));
                updateSTLState(model);
            }
            else
            {
                if (!ipp.IsKilled)
                {
                    MessageBox.Show(Trans.T1("L_LOADING_3D_FAILED", file), Trans.T("L_ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            ipp.Finished();
        }
示例#2
0
        public void AddModels(ModelFromFile fromFile, bool isNew)//(string fileName,byte[] data)
        {
            if (!availableModel)
            {
                availableGCode = false;
                gCode          = "";
                GCodeChange(gCode);
                InitSlicerView();
            }
            availableModel = true;
            IsChanged      = true;
            PrintModel model = new PrintModel(control, fromFile);

            model.Load(fromFile.Name, fromFile.Data);
            model.update();
            if (isNew)
            {
                model.Center(SettingsProvider.Instance.Printer_Settings.PrintAreaWidth / 2, SettingsProvider.Instance.Printer_Settings.PrintAreaDepth / 2);
                model.Land();
            }
            ModelList.Add(model);
            if (model.ActiveModel.triangles.Count > 0)
            {
                PreView.models.AddLast(model);

                if (isNew)
                {
                    Allocate(model);
                    model.addAnimation(new DropAnimation("drop"));
                }

                updateSTLState(model);
            }
        }
示例#3
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();
        }
示例#4
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();
            }
        }
示例#5
0
 public void Allocate(PrintModel stl)
 {
     stl.Center(SettingsProvider.Instance.Printer_Settings.BedLeft + SettingsProvider.Instance.Printer_Settings.PrintAreaWidth / 2, SettingsProvider.Instance.Printer_Settings.BedFront + SettingsProvider.Instance.Printer_Settings.PrintAreaDepth / 2);
 }