Exemple #1
0
        public string CallStippler(string pngFileName, int stipples, double sizingFactor)
        {
            pngFileName = FileNameParser.RemoveDotFileExtensionInFileName(pngFileName);
            var pngFile = new PngFile(pngFileName);
            var svgFile = new SvgFile(pngFile.FileName);

            try
            {
                var command   = GetConsoleCommand(pngFile.FullFileName, svgFile.FullFileName, stipples, sizingFactor);
                var startInfo = new ProcessStartInfo(Constants.VORONOI_RELATIVE_PATH, command);
                var p         = Process.Start(startInfo);
                p.WaitForExit();
                return($"The file {pngFile.FullFileName} has been successfully created!");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
        public string ConvertCircleSVGtoTSP(string svgFileName)
        {
            svgFileName = FileNameParser.RemoveDotFileExtensionInFileName(svgFileName);

            var svgFile = new SvgFile(svgFileName);
            var tspFile = new TspFile(svgFile.FileName)
            {
                Dimension = GetSvgFileCircleLineCount(svgFile)//TSP file must contain information regarding how many circles that there are in the svgfile
            };

            int XwordStart, XwordEnd, YwordStart, YwordEnd;

            if (tspFile.Dimension != 0)
            {
                try
                {
                    tspFile.SvgFileName = svgFile.FullFileName;
                    // Create an instance of StreamReader to read from a file.
                    // The using statement also closes the StreamReader.
                    using (StreamReader svgReader = new StreamReader($"{filepath}{svgFile.FullFileName}"))
                    {
                        using (StreamWriter tspWriter = new StreamWriter($"{filepath}{tspFile.FullFileName}"))
                        {
                            //populate tspfile header
                            tspWriter.WriteLine(TspFile.GetFileHeader(tspFile));

                            var count = 1;

                            string line;
                            // Read and display lines from the file until the end of
                            // the file is reached.
                            while ((line = svgReader.ReadLine()) != null)
                            {
                                if (line.Contains("circle"))
                                {
                                    tspWriter.Write(count + " ");
                                    XwordStart = line.IndexOf(CX) + CX.Length + 2;
                                    XwordEnd   = line.IndexOf(CY, XwordStart);

                                    tspWriter.Write(line.Substring(XwordStart, XwordEnd - XwordStart - 2) + " ");

                                    YwordStart = line.IndexOf(CY) + CY.Length + 2;
                                    YwordEnd   = line.IndexOf(R, YwordStart);

                                    tspWriter.WriteLine(line.Substring(YwordStart, YwordEnd - YwordStart - 2));
                                    //Console.WriteLine($"Xcoord: {svg.xCoord}, Ycoord: {svg.yCoord}");

                                    count++;
                                }
                            }
                            tspWriter.WriteLine(tspFile.EndofFile);
                            return($"The TSP Problem file {filepath}{tspFile.FullFileName} has been created");
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    return($"The file {filepath}{svgFile.FullFileName} could not be read. {e.Message}");
                }
            }
            else
            {
                return($"The file {filepath}{svgFile.FullFileName} does not have a dimension value");
            }
        }