diff --git a/RhSolutions.AddIn/Services/DxfWriter.cs b/RhSolutions.AddIn/Services/DxfWriter.cs index 85fe983..d8ed26a 100644 --- a/RhSolutions.AddIn/Services/DxfWriter.cs +++ b/RhSolutions.AddIn/Services/DxfWriter.cs @@ -29,6 +29,47 @@ public class DxfWriter : IWriter WriteProducts(new[] { (string.Empty, products) }); } + private IEnumerable WriteRow(int x, int y, Product product, double amount) + { + string measure = product.ProductMeasure switch + { + Measure.Kg => "кг", + Measure.M => "м", + Measure.M2 => "м2", + Measure.P => "шт", + _ => string.Empty + }; + + return new[] + { + new Text(product.Name, new Vector2(x + 4180, y), 250) + { + Alignment = TextAlignment.MiddleLeft, + WidthFactor = 0.85 + }, + new Text(product.ProductSku, new Vector2(x + 24750, y), 250) + { + Alignment = TextAlignment.MiddleCenter, + WidthFactor = 0.85 + }, + new Text("«РЕХАУ»", new Vector2(x + 28750, y), 250) + { + Alignment = TextAlignment.MiddleCenter, + WidthFactor = 0.85 + }, + new Text(measure, new Vector2(x + 32000, y), 250) + { + Alignment = TextAlignment.MiddleCenter, + WidthFactor = 0.85 + }, + new Text(amount.ToString(), new Vector2(x + 34000, y), 250) + { + Alignment = TextAlignment.MiddleCenter, + WidthFactor = 0.85 + } + }; + } + public void WriteProducts(IEnumerable<(string, Dictionary)> products) { productDict = products.First().Item2; @@ -39,6 +80,8 @@ public class DxfWriter : IWriter for (int i = 0; i < tablesCount; i++) { + int x = i * 43000; + var insertion = new Insert(tableBlock, new Vector2(tablePosition, 0)) { Layer = doc.Layers["Таблицы"] @@ -48,30 +91,8 @@ public class DxfWriter : IWriter for (int row = 0; row < 27 && i * 27 + row < pArray.Length; row++) { - insertion.Attributes.AttributeWithTag($"Name{row}").Value = pArray[i * 27 + row].Name.Replace("\n", " "); - insertion.Attributes.AttributeWithTag($"ProductSku{row}").Value = pArray[i * 27 + row].ProductSku; - insertion.Attributes.AttributeWithTag($"Rh{row}").Value = "«РЕХАУ»"; - insertion.Attributes.AttributeWithTag($"Amount{row}").Value = productDict[pArray[i * 27 + row]].ToString(); - - string measure = string.Empty; - switch (pArray[i * 27 + row].ProductMeasure) - { - case Measure.Kg: - measure = "кг"; - break; - case Measure.M: - measure = "м"; - break; - case Measure.M2: - measure = "м2"; - break; - case Measure.P: - measure = "шт"; - break; - default: - break; - } - insertion.Attributes.AttributeWithTag($"Measure{row}").Value = measure; + int y = 25400 - row * 800; + doc.Entities.Add(WriteRow(x, y, pArray[i * 27 + row], productDict[pArray[i * 27 + row]])); } insertion.Attributes.AttributeWithTag("Sheet").Value = (i + 1).ToString(); @@ -428,47 +449,6 @@ public class DxfWriter : IWriter Block block = new("Таблица спецификации", entities); - y = 25400; - for (int i = 0; i < 27; i++) - { - block.AttributeDefinitions.Add(new AttributeDefinition($"Name{i}") - { - Position = new Vector3(4180, y, 0), - Alignment = TextAlignment.MiddleLeft, - WidthFactor = 0.85, - Height = 250 - }); - block.AttributeDefinitions.Add(new AttributeDefinition($"ProductSku{i}") - { - Position = new Vector3(24750, y, 0), - Alignment = TextAlignment.MiddleCenter, - WidthFactor = 0.85, - Height = 250 - }); - block.AttributeDefinitions.Add(new AttributeDefinition($"Rh{i}") - { - Position = new Vector3(28750, y, 0), - Alignment = TextAlignment.MiddleCenter, - WidthFactor = 0.85, - Height = 250 - }); - block.AttributeDefinitions.Add(new AttributeDefinition($"Measure{i}") - { - Position = new Vector3(32000, y, 0), - Alignment = TextAlignment.MiddleCenter, - WidthFactor = 0.85, - Height = 250 - }); - block.AttributeDefinitions.Add(new AttributeDefinition($"Amount{i}") - { - Position = new Vector3(34000, y, 0), - Alignment = TextAlignment.MiddleCenter, - WidthFactor = 0.85, - Height = 250 - }); - y -= 800; - } - block.AttributeDefinitions.Add(new AttributeDefinition($"Sheet") { Position = new Vector3(41000, 950, 0), @@ -480,6 +460,7 @@ public class DxfWriter : IWriter return block; } + public void Dispose() { Process.Start(file);