瀏覽代碼

Added DXF import to Design Management

Kenric Nugteren 8 月之前
父節點
當前提交
d97d9595ef

+ 1 - 1
prs.desktop/DockPanels/ProductLookupDock.xaml.cs

@@ -266,7 +266,7 @@ public partial class ProductLookupDock : UserControl, IDockPanel
             //String newfile = Path.ChangeExtension(Path.GetFileName(filename), "png");
             try
             {
-                result = DxfUtils.ProcessImage(stream, Path.GetFileNameWithoutExtension(filename));
+                result = DxfUtils.ProcessImage(stream);
             }
             catch (Exception e)
             {

+ 2 - 2
prs.desktop/Panels/Products/Master List/ProductsPanel.xaml.cs

@@ -291,7 +291,7 @@ namespace PRSDesktop
             return string.Join(", ", Products.SelectedRows.Select(r => r.Get<Product, string>(c => c.Code)));
         }
 
-        private void UpdateProductImages(Guid id, string filename, Bitmap bitmap)
+        private void UpdateProductImages(Guid id, string filename, Bitmap? bitmap)
         {
             var docid = id;
             if (bitmap != null && docid == Guid.Empty)
@@ -355,7 +355,7 @@ namespace PRSDesktop
 
                 Bitmap? bmp = null;
                 if (Path.GetExtension(filename).ToLower().Equals(".dxf"))
-                    bmp = DxfUtils.DXFToBitmap(filename);
+                    DxfUtils.DXFToBitmap(filename).GetOk(out bmp);
                 else
                     bmp = Image.FromFile(filename) as Bitmap;
 

+ 27 - 0
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -15,6 +15,7 @@ using System.Windows.Media.Imaging;
 using InABox.Configuration;
 using System.Reactive.Linq;
 using InABox.Wpf;
+using InABox.Dxf;
 
 namespace PRSDesktop;
 
@@ -471,6 +472,7 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
             "PDF Files (*.pdf)|*.pdf|" +
             "Component Files (*.xls;*.xlsx;*.csv;*.txt)|*.xls;*.xlsx;*.csv;*.txt|" +
             "Image Files (*.bmp;*.png;*.jpg;*.jpeg)|*.bmp;*.png;*.jpg;*.jpeg|" +
+            "DXF Files (*.dxf)|*.dxf|" +
             "All Files (*.*)|*.*"
         };
         if (dlg.ShowDialog() == true)
@@ -478,6 +480,7 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
             var pdfs = new List<string>();
             var images = new List<string>();
             var components = new List<string>();
+            var dxfs = new List<string>();
             foreach(var filename in dlg.FileNames)
             {
                 var ext = Path.GetExtension(filename).ToLower();
@@ -489,6 +492,10 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
                 {
                     images.Add(filename);
                 }
+                else if(ext == ".dxf")
+                {
+                    dxfs.Add(filename);
+                }
                 else
                 {
                     components.Add(filename);
@@ -497,6 +504,7 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
 
             AddPDFFiles(pdfs, doRefresh: false);
             AddImageFiles(images, doRefresh: false);
+            AddDXFFiles(dxfs, doRefresh: false);
             AddComponentFiles(components, Guid.Empty);
 
             Refresh(false, true);
@@ -592,6 +600,25 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
         }
     }
 
+    public void AddDXFFiles(IEnumerable<string> fileNames, bool doRefresh = true)
+    {
+        AddDocuments(fileNames.Select(x =>
+        {
+            var dxf = DxfUtils.LoadDxf(x);
+            var pdf = DxfUtils.ProcessPdf(dxf);
+            var data = pdf.SaveToBytes();
+            return new Tuple<string, Document>(
+                x,
+                new Document
+                {
+                    Data = data,
+                    FileName = Path.GetFileName(x) + ".pdf",
+                    CRC = CoreUtils.CalculateCRC(data),
+                    TimeStamp = new FileInfo(x).LastWriteTime
+                });
+        }), doRefresh: doRefresh);
+    }
+
     public void AddPDFFiles(IEnumerable<string> fileNames, bool doRefresh = true)
     {
         var cancel = new CancelEventArgs();