Пример #1
0
 private void LogToConsole(TFlexTask entity)
 {
     Console.WriteLine($"{entity.Name} loaded into buffer!");
     Console.WriteLine($"Name: {entity.Name}\nProject type: {entity.ProjectType}");
     Console.WriteLine($"Parts count: {entity.Parts.Count}");
     Console.WriteLine($"Sheets: {entity.Sheets.Count}");
     Console.WriteLine($"Results: {entity.Results.Count}");
 }
Пример #2
0
        public void SaveToTFlex(TFlexTask input, string fileName, string folderPath)
        {
            input.Parts.ForEach(part => part.PartProfile = part.OriginalPartProfile);
            fileName = $"{folderPath}\\{fileName}";
            if (!fileName.EndsWith(".tfnesting"))
            {
                fileName = $"{fileName}.tfnesting";
            }

            var serializer = new XmlSerializer(typeof(TFlexTask));

            using (var xmlFile = File.CreateText(fileName + ".tmp"))        //костылище TODO TODO TODO
            {
                serializer.Serialize(xmlFile, input);
            }

            //костылище TODO
            using (var xmlFile = File.OpenText(fileName + ".tmp"))
            {
                using (var niceFile = File.CreateText(fileName))
                {
                    while (!xmlFile.EndOfStream)
                    {
                        var line = xmlFile.ReadLine();
                        line = line.Replace("<FigureContour>", "<Contour xsi:type=\"FigureContour\">");
                        line = line.Replace("<CircleContour>", "<Contour xsi:type=\"CircleContour\">");
                        line = line.Replace("<RectangularContour>", "<Contour xsi:type=\"RectangularContour\">");
                        line = line.Replace("</FigureContour>", "</Contour>");
                        line = line.Replace("</CircleContour>", "</Contour>");
                        line = line.Replace("</RectangularContour>", "</Contour>");
                        line = line.Replace("<ContourArc>", "<ContourObject xsi:type=\"ContourArc\">");
                        line = line.Replace("<ContourLine>", "<ContourObject xsi:type=\"ContourLine\">");
                        line = line.Replace("</ContourArc>", "</ContourObject>");
                        line = line.Replace("</ContourLine>", "</ContourObject>");
                        line = line.Replace("<RectangularSheet>", "<SheetDefinition xsi:type=\"RectangularSheet\">");
                        line = line.Replace("<ContourSheet>", "<SheetDefinition xsi:type=\"ContourSheet\">");
                        line = line.Replace("</RectangularSheet>", "</SheetDefinition>");
                        line = line.Replace("</ContourSheet>", "</SheetDefinition>");
                        niceFile.WriteLine(line);
                    }
                }
            }
            File.Delete(fileName + ".tmp");
        }
Пример #3
0
        public void SaveToJson(TFlexTask buffer, string fileName)
        {
            var jsonSettings = new JsonSerializerSettings
            {
                DateFormatString      = "yyyy-MM-dd HH:mm:ss",
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                DefaultValueHandling  = DefaultValueHandling.Ignore,
                NullValueHandling     = NullValueHandling.Ignore,
                Culture          = CultureInfo.CurrentCulture,
                TypeNameHandling = TypeNameHandling.None
            };

            if (!fileName.EndsWith(".json"))
            {
                fileName = $"{fileName}.json";
            }
            using (var file = File.CreateText(fileName))
            {
                file.Write(JsonConvert.SerializeObject(buffer, jsonSettings));
                file.Close();
            }
        }
Пример #4
0
        /// <summary>
        /// Экспорт задания на раскрой в папку в формате NF
        /// </summary>
        /// <param name="input">Задание в формате TFlex</param>
        /// <param name="destination">Название папки</param>
        /// <param name="folderPath">Путь к папке</param>
        ///
        public void SaveToNestingFactory(TFlexTask input, string destination, string folderPath)
        {
            if (!Directory.Exists(folderPath))
            {
                throw new Exception("Directory doesn't exits");
            }
            destination = $"{folderPath}\\{destination}";
            if (Directory.Exists(destination))
            {
                Console.WriteLine("Directory is already exists. Overwrite it? y/n");
                var yesOrNo = Console.ReadLine();
                if (yesOrNo.ToLowerInvariant().StartsWith("y"))
                {
                    foreach (var fileToDelete in Directory.GetFiles(destination))
                    {
                        File.Delete(fileToDelete);
                    }
                }
                else
                {
                    return;
                }
            }
            Directory.CreateDirectory(destination);

            foreach (var part in input.Parts)
            {
                if (part.Exclude)
                {
                    continue;
                }
                var filePath = $"{destination}\\{part.ID}.item";

                using (var partFile = File.CreateText(filePath))
                {
                    partFile.Write(string.Join("\t", "ITEMNAME:", part.Name) + "\n");
                    WriteItemToFile(partFile, part.OriginalPartProfile);
                    partFile.Close();
                }
            }

            foreach (var sheet in input.Sheets.Where(sheet => !(sheet is RectangularSheet)))
            {
                var filePath = $"{destination}\\{sheet.ID}_sheet.item";
                using (var sheetFile = File.CreateText(filePath))
                {
                    sheetFile.Write(string.Join("\t", "ITEMNAME:", sheet.Name ?? sheet.ID.ToString()) + "\n");
                    if (sheet is ContourSheet cont)
                    {
                        WriteItemToFile(sheetFile, cont.SheetProfile, true);
                    }
                    sheetFile.Close();
                }
            }

            var taskPath = $"{destination}\\{input.Name ?? "nest"}.task";

            if (!Uri.IsWellFormedUriString(taskPath, UriKind.RelativeOrAbsolute))
            {
                taskPath = $"{destination}\\task.task";
            }
            using (var taskFile = File.CreateText(taskPath))
            {
                taskFile.Write(string.Join("\t", "TASKNAME:", input.Name ?? "nest") + "\n");
                taskFile.Write(string.Join("\t", "TIMELIMIT:", 3600000) + "\n");
                taskFile.Write(string.Join("\t", "TASKTYPE:", "Sheet") + "\n");
                foreach (var sheet in input.Sheets)
                {
                    switch (sheet)
                    {
                    case ContourSheet cont:
                        taskFile.Write(string.Join("\t", "DOMAINFILE:", $"{cont.ID}_sheet.item") + "\n");
                        break;

                    case RectangularSheet rect:
                        taskFile.Write(string.Join("\t", "WIDTH:", Math.Abs((int)rect.Width)) + "\n");
                        taskFile.Write(string.Join("\t", "LENGTH:", Math.Abs((int)rect.Length)) + "\n");
                        break;
                    }
                    taskFile.Write(string.Join("\t", "SHEETQUANT:", sheet.Count) + "\n");
                }
                taskFile.Write(string.Join("\t", "ITEM2DOMAINDIST:", input.FigureParams.PartDistance) + "\n");
                taskFile.Write(string.Join("\t", "ITEM2ITEMDIST:", input.FigureParams.PartDistance) + "\n");
                foreach (var item in input.Parts)
                {
                    if (item.Exclude)
                    {
                        continue;
                    }
                    taskFile.Write(string.Join("\t", "ITEMFILE:", $"{item.ID}.item") + "\n");
                    taskFile.Write(string.Join("\t", "ITEMQUANT:", item.Count) + "\n");
                    taskFile.Write(string.Join("\t", "ROTATE:", item.DisableTurn ? 0 : 1) + "\n");
                    string rotationStep;
                    if (item.AngleStep % 360 == 0)
                    {
                        rotationStep = "NO";
                    }
                    else if (item.AngleStep % 180 == 0)
                    {
                        rotationStep = "PI";
                    }
                    else if (item.AngleStep % 90 == 0)
                    {
                        rotationStep = "PI/2";
                    }
                    else
                    {
                        rotationStep = "FREE";
                    }


                    taskFile.Write(string.Join("\t", "ROTSTEP:", rotationStep) + "\n");
                    taskFile.Write(string.Join("\t", "REFLECT:", item.OverturnAllowed ? 1 : 0) + "\n");
                }
                taskFile.Close();
            }
        }
Пример #5
0
        static void CommandHandler(string s)
        {
            try
            {
                var commandName = string.Join("", s.TakeWhile(ch => ch != ' '));
                var fileName    = string.Join("", s.SkipWhile(ch => ch != ' ').Skip(1));
                if (commandName == "load")
                {
                    var loader = new TaskLoader();


                    var extension = GetExtension(fileName);
                    if (extension == "tfnesting")
                    {
                        Buffer = loader.LoadTFlexTask(fileName);
                        return;
                    }
                    if (extension == "" && Directory.Exists(fileName))
                    {
                        Buffer = loader.LoadNfTask(fileName);
                        return;
                    }

                    if (!File.Exists(fileName))
                    {
                        Console.WriteLine("File doesn't exist!");
                        return;
                    }
                }
                if (commandName == "save")
                {
                    commandName = string.Join("", fileName.TakeWhile(ch => ch != ' '));
                    if (string.IsNullOrEmpty(commandName))
                    {
                        return;
                    }

                    if (commandName.ToLowerInvariant() == "-nf")
                    {
                        fileName = string.Join("", fileName.SkipWhile(ch => ch != ' ').Skip(1));
                        if (string.IsNullOrEmpty(fileName))
                        {
                            return;
                        }
                        var converter = new NestingConverter();
                        converter.SaveToNestingFactory(Buffer, fileName, Directory.GetCurrentDirectory());
                    }
                    else if (commandName.ToLowerInvariant() == "-tflex")
                    {
                        fileName = string.Join("", fileName.SkipWhile(ch => ch != ' ').Skip(1));
                        if (string.IsNullOrEmpty(fileName))
                        {
                            return;
                        }
                        var converter = new NestingConverter();
                        converter.SaveToTFlex(Buffer, fileName, Directory.GetCurrentDirectory());
                    }
                    else if (commandName.ToLowerInvariant() == "-json")
                    {
                        fileName = string.Join("", fileName.SkipWhile(ch => ch != ' ').Skip(1));
                        if (string.IsNullOrEmpty(fileName))
                        {
                            return;
                        }
                        var converter = new NestingConverter();
                        converter.SaveToJson(Buffer, fileName);
                    }
                }
                if (commandName == "toJson")
                {
                }
            }
            catch (Exception ex)
            {
                Console.Write($"{ex.Message}\n{ex.StackTrace}\n");
            }
        }