Esempio n. 1
0
        public MRecipe GenerateRecipe(string outputFileName)
        {
            if (
                _geometriesBuffer == null ||
                _geometriesBuffer.Keys.Count <= 0 ||
                !File.Exists(PatternFilePath)
                )
            {
                throw new Exception("Missing or Invalid pattern");
            }

            var patternName = Path.GetFileNameWithoutExtension(outputFileName);
            var device      = new MRecipeDevice(patternName);
            var recipe      = new MRecipe(new MRecipePlate("Plate", device));

            // add fiducials to recipe plate
            recipe.Plates.First().Fiducials = new ObservableCollection <MFiducialInfo>(Fiducials);

            if (SeperateLayers)
            {
                var dataDirectory = Path.Combine(
                    Path.GetDirectoryName(outputFileName),
                    $"{patternName} Data"
                    );

                if (!Directory.Exists(dataDirectory))
                {
                    Directory.CreateDirectory(dataDirectory);
                }

                foreach (var layerName in _geometriesBuffer?.Keys)
                {
                    var fileName = Path.Combine(
                        dataDirectory, $"{layerName}.dxf"
                        );
                    GeometricArithmeticModule.SaveDXF(fileName, _geometriesBuffer[layerName]);

                    var layer = new MRecipeDeviceLayer(layerName);
                    layer.AlignmentType             = AlignmentType;
                    layer.PatternFilePath           = fileName;
                    layer.ProcessParametersFilePath = ProcessParametersFilePath;
                    layer.TargetProcessMode         = TargetProcessMode?.Name.EnglishValue;
                    layer.TileSettings = (MTileSettings)TileSettings.Clone();
                    device.AddLayer(layer);
                }

                recipe.Save(
                    Path.Combine(
                        dataDirectory, $"{patternName}.{MRecipe.DefaultFileExtension}"
                        )
                    );
            }
            else
            {
                var layer = new MRecipeDeviceLayer(patternName);
                layer.AlignmentType             = AlignmentType;
                layer.PatternFilePath           = PatternFilePath;
                layer.ProcessParametersFilePath = ProcessParametersFilePath;
                layer.TargetProcessMode         = TargetProcessMode?.Name.EnglishValue;
                layer.TileSettings = (MTileSettings)TileSettings.Clone();
                device.AddLayer(layer);

                recipe.Save(
                    Path.Combine(
                        Path.GetDirectoryName(PatternFilePath), $"{patternName}.{MRecipe.DefaultFileExtension}"
                        )
                    );
            }

            // update recipe's parents
            recipe.UpdateParents();

            return(recipe);
        }
Esempio n. 2
0
        public MRecipe GenerateRecipe(string outputFileName)
        {
            if (
                _stlModel == null ||
                _stlSlices == null ||
                _stlSlices.Count <= 0 ||
                !File.Exists(PatternFilePath)
                )
            {
                throw new Exception("Missing or Invalid pattern");
            }

            try
            {
                IsLoading = true;

                string markParametersFilePath = TargetProcessMode?.ProcessParameterFileManager?.FilePath;

                var recipeName    = Path.GetFileNameWithoutExtension(outputFileName);
                var dataDirectory = Path.Combine(
                    Path.GetDirectoryName(outputFileName),
                    $"{recipeName} Recipe Data"
                    );

                // save recipe in it's Data Directory
                var recipeFilePath = Path.Combine(
                    dataDirectory, Path.GetFileName(outputFileName)
                    );

                // overwrite data directory if it exists
                if (Directory.Exists(dataDirectory))
                {
                    Directory.Delete(dataDirectory);
                }
                Directory.CreateDirectory(dataDirectory);

                // copy the marking parameters to the data directory
                var newMarkParametersFilePath = Path.Combine(
                    dataDirectory, Path.GetFileName(markParametersFilePath)
                    );

                // copy the marking parameters to the data directory
                if (File.Exists(newMarkParametersFilePath))
                {
                    File.Delete(newMarkParametersFilePath);
                }
                File.Copy(markParametersFilePath, newMarkParametersFilePath);

                // create device
                var device = new MRecipeDevice("Slices");

                // centre device about it's reference point
                device.TransformInfo.OffsetX = -StlModelReferencePoint.X;
                device.TransformInfo.OffsetY = -StlModelReferencePoint.Y;

                // create template layers so that
                // they can be updated in parallel
                for (int i = 0; i < _stlSlices.Count; i++)
                {
                    device.Layers.Add(new MRecipeDeviceLayer());
                }

                // generate and export DXFs
                Parallel.For(0, _stlSlices.Count, (i) =>
                {
                    // device - representing slices
                    var layer = device.Layers[i];
                    layer.Tag = $"Slice {i}";
                    layer.TargetProcessMode         = TargetProcessMode?.Name.EnglishValue;
                    layer.ProcessParametersFilePath = markParametersFilePath;
                    layer.PatternFilePath           = Path.Combine(dataDirectory, $"{layer.Tag}.dxf");
                    layer.TileSettings = TileSettings;

                    for (int j = 0; j < _stlSlices[i].Tiles.Count; j++)
                    {
                        layer.TileDescriptions.Add(
                            new MTileDescription(j, _stlSlices[i].Tiles[j])
                            );
                    }

                    _stlSlices[i].SaveAsDXF(layer.PatternFilePath);
                });

                // create recipe
                var recipe = new MRecipe(new MRecipePlate(recipeName, device));

                // set alignment type
                recipe.Plates[0].AlignmentType = AlignmentType;

                // add alignment fiducials to recipe plate
                recipe.Plates[0].Fiducials = new ObservableCollection <MFiducialInfo>(Fiducials);

                // update recipe's parents
                recipe.UpdateParents();

                recipe.Save(Path.Combine(dataDirectory, recipeFilePath));

                return(recipe);
            }
            finally
            {
                IsLoading = false;
            }
        }