public void PrinterConfigTests()
        {
            string staticDataPath = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData");

            AggContext.StaticData = new FileSystemStaticData(staticDataPath);

            var profilesDirectory = new DirectoryInfo(Path.Combine(staticDataPath, "Profiles"));

            foreach (FileInfo file in profilesDirectory.GetFiles("*.printer", SearchOption.AllDirectories))
            {
                var printerSettings = PrinterSettings.LoadFile(file.FullName);

                // Assert that no UserLayer values exist in production .printer files
                Assert.AreEqual(0, printerSettings.UserLayer.Keys.Count, ".printer files should not contain UserLayer values");

                var layersToInspect = new List <PrinterSettingsLayer>();
                layersToInspect.Add(printerSettings.OemLayer);
                layersToInspect.AddRange(printerSettings.MaterialLayers);
                layersToInspect.AddRange(printerSettings.QualityLayers);

                // Validate each PrinterSettingLayer in the .printer file
                foreach (var layer in layersToInspect.Where(l => l.Keys.Any()))
                {
                    firstLayerSpeedEqualsAcceptableValue(printerSettings, layer, file.FullName);

                    firstLayerHeightLessThanNozzleDiameter(printerSettings, layer, file.FullName);

                    layerHeightLessThanNozzleDiameter(printerSettings, layer, file.FullName);

                    firstLayerExtrusionWidthAcceptableValue(printerSettings, layer, file.FullName);

                    firstLayerExtrusionWidthNotZero(layer, file.FullName);

                    bedSizeXYSeparatedByComma(layer, file.FullName);

                    printCenterFormatSeparatedByComma(layer, file.FullName);

                    testRetractLengthLessThanTwenty(layer, file.FullName);

                    testExtruderCountGreaterThanZero(layer, file.FullName);

                    minimumFanSpeedLessThanOrEqualToOneHundred(layer, file.FullName);

                    maxFanSpeedNotGreaterThanOneHundred(layer, file.FullName);

                    noCurlyBracketsInStartGcode(layer, file.FullName);

                    noCurlyBracketsInEndGcode(layer, file.FullName);

                    testBottomSolidLayersOneMM(layer, file.FullName);

                    testFirstLayerTempNotInStartGcode(layer, file.FullName);

                    testFirstLayerBedTemperatureNotInStartGcode(layer, file.FullName);
                }
            }
        }
Beispiel #2
0
        static OemProfileTests()
        {
            StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            allPrinters = (from printerFile in new DirectoryInfo(printerSettingsDirectory).GetFiles("*.printer", SearchOption.AllDirectories)
                           select new PrinterConfig
            {
                PrinterName = printerFile.Name,
                Oem = printerFile.Directory.Name,
                ConfigPath = printerFile.FullName,
                RelativeFilePath = printerFile.FullName.Substring(printerSettingsDirectory.Length + 1),
                PrinterSettings = PrinterSettings.LoadFile(printerFile.FullName)
            }).ToList();
        }
Beispiel #3
0
        static OemProfileTests()
        {
            MatterControlUtilities.OverrideAppDataLocation();

            StaticData.Instance = new MatterHackers.Agg.FileSystemStaticData(Path.Combine(matterControlDirectory, "StaticData"));

            allPrinters = (from printerFile in new DirectoryInfo(printerSettingsDirectory).GetFiles("*.printer", SearchOption.AllDirectories)
                           select new PrinterConfig
            {
                PrinterName = printerFile.Name,
                Oem = printerFile.Directory.Name,
                ConfigPath = printerFile.FullName,
                RelativeFilePath = printerFile.FullName.Substring(printerSettingsDirectory.Length + 1),
                PrinterSettings = PrinterSettings.LoadFile(printerFile.FullName)
            }).ToList();
        }
        public override async void OnLoad(EventArgs args)
        {
            if (string.IsNullOrEmpty(this.StoreID) &&
                File.Exists(printerInfo.ProfilePath))
            {
                // load up the printer profile so we can get the MatterHackers Skew-ID out of it
                var printerSettings = PrinterSettings.LoadFile(printerInfo.ProfilePath);

                // Use the make-model mapping table
                if (OemSettings.Instance.OemPrinters.TryGetValue($"{printerInfo.Make}-{ printerInfo.Model}", out StorePrinterID storePrinterID))
                {
                    this.StoreID = storePrinterID?.SID;
                }
            }

            if (!string.IsNullOrWhiteSpace(StoreID))
            {
                try
                {
                    // put in controls from the feed that show relevant printer information
                    WebCache.RetrieveText($"https://mh-pls-prod.appspot.com/p/1/product-sid/{StoreID}?IncludeListingData=True",
                                          (json) =>
                    {
                        UiThread.RunOnIdle(() =>
                        {
                            var result = JsonConvert.DeserializeObject <ProductSidData>(json);
                            productDataContainer.RemoveAllChildren();
                            CreateProductDataWidgets(result.ProductSku);
                        });
                    });
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Error collecting or loading printer details: " + ex.Message);
                }

                // add a section to hold the data about the printer
                this.AddChild(productDataContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    HAnchor = HAnchor.Stretch
                });
            }

            headingRow.Visible = this.ShowHeadingRow;

            base.OnLoad(args);
        }
        public override async void OnLoad(EventArgs args)
        {
            if (File.Exists(printerInfo.ProfilePath))
            {
                // load up the printer profile so we can get the MatterHackers Skew-ID out of it
                var printerSettings = PrinterSettings.LoadFile(printerInfo.ProfilePath);

                // Get the printer sid from settings
                string storeID = null;

                // Use the make-model mapping table
                if (OemSettings.Instance.OemPrinters.TryGetValue($"{printerInfo.Make}-{ printerInfo.Model}", out StorePrinterID storePrinterID))
                {
                    storeID = storePrinterID?.SID;
                }

                if (!string.IsNullOrWhiteSpace(storeID))
                {
                    var product = (await LoadProductData(storeID)).ProductSku;
                    // put in controls from the feed that show relevant printer information

                    var row = new FlowLayoutWidget()
                    {
                        HAnchor = HAnchor.Stretch,
                        Margin  = new BorderDouble(top: theme.DefaultContainerPadding)
                    };
                    this.AddChild(row);

                    var image = new ImageBuffer(150, 10);
                    row.AddChild(new ImageWidget(image)
                    {
                        Margin  = new BorderDouble(right: theme.DefaultContainerPadding),
                        VAnchor = VAnchor.Top
                    });

                    ApplicationController.Instance.DownloadToImageAsync(image, product.FeaturedImage.ImageUrl, scaleToImageX: true);

                    var descriptionBackground = new GuiWidget()
                    {
                        HAnchor = HAnchor.Stretch,
                        VAnchor = VAnchor.Fit | VAnchor.Top,
                        Padding = theme.DefaultContainerPadding
                    };

                    var description = new MarkdownWidget(theme)
                    {
                        MinimumSize = new VectorMath.Vector2(350, 0),
                        HAnchor     = HAnchor.Stretch,
                        VAnchor     = VAnchor.Fit,
                        Markdown    = product.ProductDescription.Trim()
                    };
                    descriptionBackground.AddChild(description);
                    descriptionBackground.BeforeDraw += (s, e) =>
                    {
                        var rect = new RoundedRect(descriptionBackground.LocalBounds, 3);
                        e.Graphics2D.Render(rect, theme.SlightShade);
                    };

                    row.AddChild(descriptionBackground);

                    var padding = theme.DefaultContainerPadding;

                    var addonsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
                    {
                        Padding = new BorderDouble(padding, padding, padding, 0),
                        HAnchor = HAnchor.Stretch
                    };

                    var addonsSection = new SectionWidget("Upgrades and Accessories", addonsColumn, theme);
                    this.AddChild(addonsSection);
                    theme.ApplyBoxStyle(addonsSection);
                    addonsSection.Margin = addonsSection.Margin.Clone(left: 0);

                    foreach (var item in product.ProductListing.AddOns)
                    {
                        var icon = new ImageBuffer(80, 0);
                        ApplicationController.Instance.DownloadToImageAsync(icon, item.FeaturedImage.ImageUrl, scaleToImageX: true);

                        var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, icon)
                        {
                            HAnchor = HAnchor.Stretch,
                            Cursor  = Cursors.Hand
                        };

                        foreach (var child in addOnRow.Children)
                        {
                            child.Selectable = false;
                        }

                        addOnRow.Click += (s, e) =>
                        {
                            ApplicationController.Instance.LaunchBrowser($"https://www.matterhackers.com/store/l/{item.AddOnListingReference}/sk/{item.AddOnSkuReference}");
                        };

                        addonsColumn.AddChild(addOnRow);
                    }

                    if (false)
                    {
                        var settingsPanel = new GuiWidget()
                        {
                            HAnchor         = HAnchor.Stretch,
                            VAnchor         = VAnchor.Stretch,
                            MinimumSize     = new VectorMath.Vector2(20, 20),
                            DebugShowBounds = true
                        };

                        settingsPanel.Load += (s, e) =>
                        {
                            var printer = new PrinterConfig(printerSettings);

                            var settingsContext = new SettingsContext(
                                printer,
                                null,
                                NamedSettingsLayers.All);

                            settingsPanel.AddChild(
                                new ConfigurePrinterWidget(settingsContext, printer, theme)
                            {
                                HAnchor = HAnchor.Stretch,
                                VAnchor = VAnchor.Stretch,
                            });
                        };

                        this.AddChild(new SectionWidget("Settings", settingsPanel, theme, expanded: false, setContentVAnchor: false)
                        {
                            VAnchor = VAnchor.Stretch
                        });
                    }
                }
            }

            base.OnLoad(args);
        }