Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            InitConfiguration();

            CleanDir(pathTmp);
            CleanDir(pathRes);


            Log("Started. Scale: " + scale + " angleStep:" + angleStep + " lstSize: " + lstSize.Width + "x" + lstSize.Height);

            // Загрузка из PDF и масштабирование
            //InputHandling.ConvertPDFDirToScaledImg(pathSrc, pathTmp, scale);

            // Масштабирование
            Size scaledLstSize = new Size((int)(lstSize.Width * scale), (int)(lstSize.Height * scale));

            InputHandling.ScaleWholeDirectory(pathSrc, pathTmp, scale);


            // Загрузка фигур
            Console.WriteLine("Starting process. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
            List <Figure> data = Figure.LoadFigures(pathTmp, srcFigColor, angleStep, borderDistance, figAmount);

            data.Sort(Figure.CompareFiguresBySize);
            Figure.UpdIndexes(data);
            //Figure.DeleteWrongAngles(scaledLstSize.Width, scaledLstSize.Height, data);
            SolutionChecker.LoadFigures(data, pathPrologCode, scaleCoefs);

            Console.WriteLine("Figure loading finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
            Log("Loaded Figs.");


            // Поиск решения
            Console.WriteLine("Starting result finding. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
            var preDefArr = SolutionChecker.FindAnAnswer(data, scaledLstSize.Width, scaledLstSize.Height, pathPrologCode, scaleCoefs);
            var result    = SolutionChecker.PlacePreDefinedArrangement(preDefArr, scaledLstSize.Width, scaledLstSize.Height, scaleCoefs);

            if (result == null)
            {
                Log("Prolog finished. No answer.");
            }
            else
            {
                Log("Prolog finished. Answer was found.");
                // Отображение решения
                Console.WriteLine("Starting visualization. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
                OutputImage.SaveResult(data, preDefArr, result, pathRes, scaledLstSize.Width, scaledLstSize.Height);
                OutputText.SaveResult(preDefArr, data, result, pathRes + "result.txt");
            }


            Console.WriteLine("Process finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
            Log("Finished.");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        private void button_FindAnswer_Click(object sender, EventArgs e)
        {
            if (choseenFigsPath.Count == 0)
            {
                MessageBox.Show("Не выбраны детали");
                return;
            }

            InitConfiguration();

            CleanDir(pathTmp);
            CleanDir(pathRes);


            // Масштабирование
            Size scaledLstSize = new Size((int)(lstSize.Width * scale), (int)(lstSize.Height * scale));

            InputHandling.ScaleAllFigs(choseenFigsPath, pathTmp, scale);


            // Загрузка фигур
            Console.WriteLine("Starting process. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
            List <Figure> data = Figure.LoadFigures(pathTmp, srcFigColor, angleStep, borderDistance, figAmount);

            data.Sort(Figure.CompareFiguresBySize);
            Figure.UpdIndexes(data);
            Figure.DeleteWrongAngles(scaledLstSize.Width, scaledLstSize.Height, data);
            SolutionChecker.LoadFigures(data, pathPrologCode, scaleCoefs);

            Console.WriteLine("Figure loading finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);


            // Поиск решения
            Console.WriteLine("Starting result finding. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
            var preDefArr = SolutionChecker.FindAnAnswer(data, scaledLstSize.Width, scaledLstSize.Height, pathPrologCode, scaleCoefs);
            var result    = SolutionChecker.PlacePreDefinedArrangement(preDefArr, scaledLstSize.Width, scaledLstSize.Height, scaleCoefs);

            if (result == null)
            {
                MessageBox.Show("Prolog finished. No answer.");
            }
            else
            {
                MessageBox.Show("Prolog finished. Answer was found.");
                // Отображение решения
                Console.WriteLine("Starting visualization. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
                OutputImage.SaveResult(data, preDefArr, result, pathRes, scaledLstSize.Width, scaledLstSize.Height);
                OutputText.SaveResult(preDefArr, data, result, pathRes + "result.txt");
            }


            Console.WriteLine("Process finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second);
            Console.ReadLine();
        }