├── .gitattributes ├── .gitignore ├── .vs ├── DxfEditor │ └── v17 │ │ └── DocumentLayout.json ├── ProjectSettings.json ├── VSWorkspaceState.json ├── WpfDxfViewer │ ├── FileContentIndex │ │ └── 59cfd238-ea69-41f3-b7a2-936a74817f47.vsidx │ └── v17 │ │ ├── .wsuo │ │ └── DocumentLayout.json └── slnx.sqlite ├── DXFLib ├── BlockParser.cs ├── ClassDiagram.cd ├── ClassParser.cs ├── DXF3DFace.cs ├── DXFAppIDRecord.cs ├── DXFArc.cs ├── DXFBlock.cs ├── DXFBlockRecord.cs ├── DXFCircle.cs ├── DXFClass.cs ├── DXFDimStyleRecord.cs ├── DXFDocument.cs ├── DXFEllipse.cs ├── DXFEntity.cs ├── DXFGenericEntity.cs ├── DXFHeader.cs ├── DXFInsert.cs ├── DXFLWPolyLine.cs ├── DXFLayerRecord.cs ├── DXFLib.csproj ├── DXFLine.cs ├── DXFLineTypeRecord.cs ├── DXFPoint.cs ├── DXFPointEntity.cs ├── DXFPolyLine.cs ├── DXFRay.cs ├── DXFShape.cs ├── DXFSolid.cs ├── DXFSpline.cs ├── DXFStyleRecord.cs ├── DXFTables.cs ├── DXFText.cs ├── DXFTolerance.cs ├── DXFTrace.cs ├── DXFUCSRecord.cs ├── DXFVPortRecord.cs ├── DXFVertex.cs ├── DXFViewPortRecord.cs ├── EntityAttribute.cs ├── EntityParser.cs ├── HeaderAttribute.cs ├── HeaderParser.cs ├── ISectionParser.cs ├── Properties │ └── AssemblyInfo.cs ├── TableAttribute.cs ├── TableParser.cs └── TextReaderExtensions.cs ├── DxfEditor.sln ├── DxfEditor ├── App.config ├── App.xaml ├── App.xaml.cs ├── Dxf │ ├── arc.dxf │ ├── blockTest.dxf │ ├── conveyor.dxf │ ├── draft1.dxf │ ├── draft2.dxf │ ├── draft3.dxf │ ├── draft4.dxf │ ├── gravity.dxf │ ├── hatch_1.dxf │ ├── hatch_16.dxf │ ├── heart.dxf │ ├── lwpolyl.dxf │ └── men.dxf ├── DxfEditor.csproj ├── Images │ ├── folder_document.png │ ├── hand.png │ ├── window_view.png │ ├── zoom_in.png │ └── zoom_out.png ├── MainWindow.xaml ├── MainWindow.xaml.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── ZoomableCanvas ├── LinkedListExtensions.cs ├── MathExtensions.cs ├── PriorityQuadTree.cs ├── PriorityQueue.cs ├── Properties └── AssemblyInfo.cs ├── RectExtensions.cs ├── VirtualPanel.cs ├── ZoomableCanvas.cs └── ZoomableCanvas.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /.vs/DxfEditor/v17/DocumentLayout.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": 1, 3 | "WorkspaceRootPath": "D:\\githubProject\\shao200\\WpfDxfViewer\\", 4 | "Documents": [], 5 | "DocumentGroupContainers": [ 6 | { 7 | "Orientation": 1, 8 | "VerticalTabListWidth": 256, 9 | "DocumentGroups": [ 10 | { 11 | "DockedHeight": 200, 12 | "SelectedChildIndex": -1, 13 | "Children": [ 14 | { 15 | "$type": "Bookmark", 16 | "Name": "ST:0:0:{e506b91c-c606-466a-90a9-123d1d1e12b3}" 17 | }, 18 | { 19 | "$type": "Bookmark", 20 | "Name": "ST:130:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" 21 | }, 22 | { 23 | "$type": "Bookmark", 24 | "Name": "ST:131:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" 25 | }, 26 | { 27 | "$type": "Bookmark", 28 | "Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}" 29 | }, 30 | { 31 | "$type": "Bookmark", 32 | "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" 33 | } 34 | ] 35 | } 36 | ] 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /.vs/ProjectSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "CurrentProjectSetting": null 3 | } -------------------------------------------------------------------------------- /.vs/VSWorkspaceState.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExpandedNodes": [ 3 | "" 4 | ], 5 | "PreviewInSolutionExplorer": false 6 | } -------------------------------------------------------------------------------- /.vs/WpfDxfViewer/FileContentIndex/59cfd238-ea69-41f3-b7a2-936a74817f47.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/.vs/WpfDxfViewer/FileContentIndex/59cfd238-ea69-41f3-b7a2-936a74817f47.vsidx -------------------------------------------------------------------------------- /.vs/WpfDxfViewer/v17/.wsuo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/.vs/WpfDxfViewer/v17/.wsuo -------------------------------------------------------------------------------- /.vs/WpfDxfViewer/v17/DocumentLayout.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": 1, 3 | "WorkspaceRootPath": "D:\\githubProject\\shao200\\WpfDxfViewer\\", 4 | "Documents": [], 5 | "DocumentGroupContainers": [ 6 | { 7 | "Orientation": 1, 8 | "VerticalTabListWidth": 256, 9 | "DocumentGroups": [ 10 | { 11 | "DockedHeight": 200, 12 | "SelectedChildIndex": -1, 13 | "Children": [ 14 | { 15 | "$type": "Bookmark", 16 | "Name": "ST:0:0:{e506b91c-c606-466a-90a9-123d1d1e12b3}" 17 | }, 18 | { 19 | "$type": "Bookmark", 20 | "Name": "ST:130:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" 21 | }, 22 | { 23 | "$type": "Bookmark", 24 | "Name": "ST:131:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" 25 | }, 26 | { 27 | "$type": "Bookmark", 28 | "Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}" 29 | }, 30 | { 31 | "$type": "Bookmark", 32 | "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" 33 | } 34 | ] 35 | } 36 | ] 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/.vs/slnx.sqlite -------------------------------------------------------------------------------- /DXFLib/BlockParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | class BlockParser : ISectionParser 9 | { 10 | #region ISectionParser Member 11 | 12 | private DXFBlock current = null; 13 | private bool parsingBlock = false; 14 | private EntityParser parser = new EntityParser(); 15 | private DXFDocument container; 16 | public static List groups = new List(); 17 | public void ParseGroupCode(DXFDocument doc, int groupcode, string value) 18 | { 19 | if (groupcode == 0) 20 | { 21 | if (current == null) 22 | groups.Add(value + " OUTSIDE"); 23 | else 24 | groups.Add(value); 25 | } 26 | if (current == null) 27 | { 28 | if (groupcode == 0 && value == "BLOCK") 29 | { 30 | current = new DXFBlock(); 31 | container = new DXFDocument(); 32 | parsingBlock = true; 33 | } 34 | } 35 | else 36 | { 37 | if (parsingBlock) 38 | { 39 | if (groupcode == 0 && value == "ENDBLK") 40 | { 41 | current.Children.AddRange(container.Entities); 42 | doc.Blocks.Add(current); 43 | current = null; 44 | container = null; 45 | } 46 | else if (groupcode == 0) 47 | { 48 | parsingBlock = false; 49 | parser.ParseGroupCode(container, groupcode, value); 50 | } 51 | else 52 | current.ParseGroupCode(groupcode, value); 53 | } 54 | else 55 | { 56 | if (groupcode == 0 && value == "ENDBLK") 57 | { 58 | current.Children.AddRange(container.Entities); 59 | doc.Blocks.Add(current); 60 | current = null; 61 | container = null; 62 | } 63 | else 64 | { 65 | parser.ParseGroupCode(container, groupcode, value); 66 | } 67 | } 68 | } 69 | } 70 | 71 | #endregion 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /DXFLib/ClassDiagram.cd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | EAAIAgAAAQqAAAQAAAAEAQAAQAAAABIAAAAABAAAAAA= 7 | DXFEntity.cs 8 | 9 | 10 | 11 | 12 | 13 | AAAABAAAAAAAAAAAQAAAAUAAAAAAAAAAAAAAAAAAAAA= 14 | DXF3DFace.cs 15 | 16 | 17 | 18 | 19 | 20 | CAgIAAAAAAABAAAAAAAAAQAAAAAAAAAABAAIAIAIAAA= 21 | DXFArc.cs 22 | 23 | 24 | 25 | 26 | 27 | CAgIAAAAAAABAAAAAAAAAQAAAAAAAAAABAAAAAAIAAA= 28 | DXFCircle.cs 29 | 30 | 31 | 32 | 33 | 34 | CBgAAAgAAAAAAAAACAAAAQAAAAAAAAAABgAAAAAIAAg= 35 | DXFEllipse.cs 36 | 37 | 38 | 39 | 40 | 41 | CAIAAAACACABAAAgAAAAAQAAAAAAAAAABAAAAAAAAAA= 42 | DXFLine.cs 43 | 44 | 45 | 46 | 47 | 48 | CAAABAEAAAABABQAAAAQAQEAAEAAAAAABAAAAAAAAAA= 49 | DXFLWPolyLine.cs 50 | 51 | 52 | 53 | 54 | 55 | CIAAAAAAAAABAAAAAAIAAQACAAAAAAAABAAAAAAAAAA= 56 | DXFPointEntity.cs 57 | 58 | 59 | 60 | 61 | 62 | CAAABAAAAIhBAAkAAACAAQAABEAAAgAABAAAAAAAAAA= 63 | DXFPolyLine.cs 64 | 65 | 66 | 67 | 68 | 69 | AAAACAAAACAAIAAAACAAAQAAAAAAAAAAAAAAAAAAAAA= 70 | DXFRay.cs 71 | 72 | 73 | 74 | 75 | 76 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= 77 | DXFRay.cs 78 | 79 | 80 | 81 | 82 | 83 | CAAAAAAAAAADgAAAAEAAAQAAAAAAAAABBUAAAAAAAAg= 84 | DXFShape.cs 85 | 86 | 87 | 88 | 89 | 90 | CAAAAAAAAAAAAAAAQAAAAUAAAAAAAAAABAAAAAAAAAA= 91 | DXFSolid.cs 92 | 93 | 94 | 95 | 96 | 97 | ACAABAAASAAAIAECBAABAwgYICAIAAEAAAAAAAVAAEA= 98 | DXFSpline.cs 99 | 100 | 101 | 102 | 103 | 104 | CAAAAAAAAAABAAAAQAAAAUAAAAAAAAAABAAAAAAAAAA= 105 | DXFTrace.cs 106 | 107 | 108 | 109 | 110 | 111 | AADARAAEIAAABAAAAAIAAQACAAAAAAAAAAAAAAAAAAA= 112 | DXFVertex.cs 113 | 114 | 115 | 116 | 117 | 118 | CAAAAAAAAAECAAEhAAAAAQAAAAACAAAAAAAAAAAAAAg= 119 | DXFInsert.cs 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /DXFLib/ClassParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | class ClassParser : ISectionParser 9 | { 10 | private DXFClass currentClass; 11 | #region ISectionParser Member 12 | 13 | public void ParseGroupCode(DXFDocument doc, int groupcode, string value) 14 | { 15 | switch (groupcode) 16 | { 17 | case 0: 18 | currentClass = new DXFClass(); 19 | doc.Classes.Add(currentClass); 20 | break; 21 | case 1: 22 | currentClass.DXFRecord = value; 23 | break; 24 | case 2: 25 | currentClass.ClassName = value; 26 | break; 27 | case 3: 28 | currentClass.AppName = value; 29 | break; 30 | case 90: 31 | currentClass.ClassProxyCapabilities = (DXFClass.Caps)Enum.Parse(typeof(DXFClass.Caps), value); 32 | break; 33 | case 280: 34 | if (int.Parse(value) != 0) 35 | currentClass.WasProxy = true; 36 | else 37 | currentClass.WasProxy = false; 38 | break; 39 | case 281: 40 | if (int.Parse(value) != 0) 41 | currentClass.IsEntity = true; 42 | else 43 | currentClass.IsEntity = false; 44 | break; 45 | } 46 | } 47 | 48 | #endregion 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /DXFLib/DXF3DFace.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("3DFACE")] 9 | public class DXF3DFace : DXFEntity 10 | { 11 | private DXFPoint[] corners = new DXFPoint[] { new DXFPoint(), new DXFPoint(), new DXFPoint(), new DXFPoint() }; 12 | public DXFPoint[] Corners { get { return corners; } } 13 | 14 | [Flags] 15 | public enum FlagsEnum 16 | { 17 | FirstEdgeInvisible = 1, 18 | SecondEdgeInvisible = 2, 19 | ThirdEdgeInvisible = 4, 20 | FourthEdgeInvisible = 8 21 | } 22 | 23 | public FlagsEnum Flags { get; set; } 24 | 25 | public override void ParseGroupCode(int groupcode, string value) 26 | { 27 | base.ParseGroupCode(groupcode, value); 28 | if (groupcode >= 10 && groupcode <= 33) 29 | { 30 | int idx = groupcode % 10; 31 | int component = groupcode / 10; 32 | switch (component) 33 | { 34 | case 1: 35 | Corners[idx].X = double.Parse(value); 36 | break; 37 | case 2: 38 | Corners[idx].Y = double.Parse(value); 39 | break; 40 | case 3: 41 | Corners[idx].Z = double.Parse(value); 42 | break; 43 | } 44 | } 45 | else if (groupcode == 70) 46 | { 47 | Flags = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), value); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /DXFLib/DXFAppIDRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFAppIDRecord : DXFRecord 9 | { 10 | public string ApplicationName { get; set; } 11 | 12 | public override string ToString() 13 | { 14 | return ApplicationName; 15 | } 16 | } 17 | 18 | class DXFAppIDParser : DXFRecordParser 19 | { 20 | #region ISectionParser Member 21 | 22 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 23 | { 24 | base.ParseGroupCode(doc, groupcode, value); 25 | switch (groupcode) 26 | { 27 | case 2: 28 | _currentRecord.ApplicationName = value; 29 | break; 30 | } 31 | } 32 | 33 | #endregion 34 | 35 | DXFAppIDRecord _currentRecord; 36 | protected override DXFRecord currentRecord 37 | { 38 | get { return _currentRecord; } 39 | } 40 | 41 | protected override void createRecord(DXFDocument doc) 42 | { 43 | _currentRecord = new DXFAppIDRecord(); 44 | doc.Tables.AppIDs.Add(_currentRecord); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /DXFLib/DXFArc.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("ARC")] 9 | public class DXFArc : DXFEntity 10 | { 11 | public double Thickness { get; set; } 12 | private DXFPoint center = new DXFPoint(); 13 | public DXFPoint Center { get { return center; } } 14 | 15 | public double Radius { get; set; } 16 | 17 | public double StartAngle { get; set; } 18 | public double EndAngle { get; set; } 19 | 20 | private DXFPoint extrusion = new DXFPoint() { X = 0, Y = 0, Z = 1 }; 21 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 22 | 23 | public override void ParseGroupCode(int groupcode, string value) 24 | { 25 | base.ParseGroupCode(groupcode, value); 26 | switch (groupcode) 27 | { 28 | case 39: 29 | Thickness = double.Parse(value); 30 | break; 31 | case 10: 32 | Center.X = double.Parse(value); 33 | break; 34 | case 20: 35 | Center.Y = double.Parse(value); 36 | break; 37 | case 30: 38 | Center.Z = double.Parse(value); 39 | break; 40 | case 40: 41 | Radius = double.Parse(value); 42 | break; 43 | case 50: 44 | StartAngle = double.Parse(value); 45 | break; 46 | case 51: 47 | EndAngle = double.Parse(value); 48 | break; 49 | case 210: 50 | ExtrusionDirection.X = double.Parse(value); 51 | break; 52 | case 220: 53 | ExtrusionDirection.Y = double.Parse(value); 54 | break; 55 | case 230: 56 | ExtrusionDirection.Z = double.Parse(value); 57 | break; 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /DXFLib/DXFBlock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFBlock : DXFEntity 9 | { 10 | public string BlockName { get; set; } 11 | public int BlockFlags { get; set; } 12 | private DXFPoint basePoint = new DXFPoint(); 13 | public DXFPoint BasePoint { get { return basePoint; } } 14 | public string XRef { get; set; } 15 | 16 | public override string ToString() 17 | { 18 | return string.Format("{0} ({1} child)", BlockName, HasChildren ? Children.Count : 0); 19 | } 20 | 21 | public override void ParseGroupCode(int groupcode, string value) 22 | { 23 | base.ParseGroupCode(groupcode, value); 24 | switch (groupcode) 25 | { 26 | case 2: 27 | case 3: 28 | BlockName = value; 29 | break; 30 | case 70: 31 | BlockFlags = int.Parse(value); 32 | break; 33 | case 1: 34 | XRef = value; 35 | break; 36 | case 10: 37 | BasePoint.X = double.Parse(value); 38 | break; 39 | case 20: 40 | basePoint.Y = double.Parse(value); 41 | break; 42 | case 30: 43 | basePoint.Z = double.Parse(value); 44 | break; 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /DXFLib/DXFBlockRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFBlockRecord : DXFRecord 9 | { 10 | public string BlockName { get; set; } 11 | 12 | public override string ToString() 13 | { 14 | return BlockName; 15 | } 16 | } 17 | 18 | class DXFBlockRecordParser : DXFRecordParser 19 | { 20 | private DXFBlockRecord _currentRecord; 21 | protected override DXFRecord currentRecord 22 | { 23 | get { return _currentRecord; } 24 | } 25 | 26 | protected override void createRecord(DXFDocument doc) 27 | { 28 | _currentRecord = new DXFBlockRecord(); 29 | doc.Tables.Blocks.Add(_currentRecord); 30 | } 31 | 32 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 33 | { 34 | base.ParseGroupCode(doc, groupcode, value); 35 | if (groupcode == 2) 36 | { 37 | _currentRecord.BlockName = value; 38 | } 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /DXFLib/DXFCircle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("CIRCLE")] 9 | public class DXFCircle : DXFEntity 10 | { 11 | public double Thickness { get; set; } 12 | private DXFPoint center = new DXFPoint(); 13 | public DXFPoint Center { get { return center; } } 14 | 15 | public double Radius { get; set; } 16 | 17 | private DXFPoint extrusion = new DXFPoint(); 18 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 19 | 20 | public override void ParseGroupCode(int groupcode, string value) 21 | { 22 | base.ParseGroupCode(groupcode, value); 23 | switch (groupcode) 24 | { 25 | case 39: 26 | Thickness = double.Parse(value); 27 | break; 28 | case 10: 29 | Center.X = double.Parse(value); 30 | break; 31 | case 20: 32 | Center.Y = double.Parse(value); 33 | break; 34 | case 30: 35 | Center.Z = double.Parse(value); 36 | break; 37 | case 40: 38 | Radius = double.Parse(value); 39 | break; 40 | case 210: 41 | ExtrusionDirection.X = double.Parse(value); 42 | break; 43 | case 220: 44 | ExtrusionDirection.Y = double.Parse(value); 45 | break; 46 | case 230: 47 | ExtrusionDirection.Z = double.Parse(value); 48 | break; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /DXFLib/DXFClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFClass 9 | { 10 | [Flags] 11 | public enum Caps 12 | { 13 | NoOperationAllowed = 0, 14 | Erase = 1, 15 | Transform = 2, 16 | ColorChange = 4, 17 | LayerChange = 8, 18 | LineTypeChange = 16, 19 | LineTypeScale = 32, 20 | VisibilityChange = 64, 21 | AllOperationExceptCloning = 127, 22 | Cloning = 128, 23 | AllOp = 255, 24 | R13FormatProxy = 32768 25 | } 26 | 27 | public string DXFRecord { get; set; } 28 | public string AppName { get; set; } 29 | public string ClassName { get; set; } 30 | public Caps? ClassProxyCapabilities { get; set; } 31 | public bool? WasProxy { get; set; } 32 | public bool? IsEntity { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DXFLib/DXFDimStyleRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFDimStyleRecord : DXFRecord 9 | { 10 | public string StyleName { get; set; } 11 | //TODO: weitere Felder unterstützen 12 | 13 | public override string ToString() 14 | { 15 | return StyleName; 16 | } 17 | } 18 | 19 | class DXFDimStyleRecordParser : DXFRecordParser 20 | { 21 | private DXFDimStyleRecord _record; 22 | protected override DXFRecord currentRecord 23 | { 24 | get { return _record; } 25 | } 26 | 27 | protected override void createRecord(DXFDocument doc) 28 | { 29 | _record = new DXFDimStyleRecord(); 30 | doc.Tables.DimStyles.Add(_record); 31 | } 32 | 33 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 34 | { 35 | base.ParseGroupCode(doc, groupcode, value); 36 | if (groupcode == 2) 37 | _record.StyleName = value; 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /DXFLib/DXFDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using System.Threading; 7 | using System.Globalization; 8 | 9 | namespace DXFLib 10 | { 11 | public class DXFDocument 12 | { 13 | private DXFHeader header = new DXFHeader(); 14 | public DXFHeader Header { get { return header; } } 15 | private List classes = new List(); 16 | public List Classes { get { return classes; } } 17 | private List blocks = new List(); 18 | public List Blocks { get { return blocks; } } 19 | private DXFTables tables = new DXFTables(); 20 | public DXFTables Tables { get { return tables; } } 21 | private List entities = new List(); 22 | public List Entities { get { return entities; } } 23 | 24 | public DXFDocument() 25 | { 26 | 27 | } 28 | 29 | public void Load(string filename) 30 | { 31 | FileStream stream = new FileStream(filename, FileMode.Open); 32 | Load(stream); 33 | stream.Close(); 34 | } 35 | 36 | private enum LoadState 37 | { 38 | OutsideSection, 39 | InSection 40 | } 41 | 42 | public event EventHandler OnFileVersionIncompatible; 43 | 44 | public void Load(Stream file) 45 | { 46 | CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; 47 | Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); 48 | bool versionwarningsent = false; 49 | 50 | Dictionary sectionparsers = new Dictionary(); 51 | 52 | sectionparsers["HEADER"] = new HeaderParser(); 53 | sectionparsers["CLASSES"] = new ClassParser(); 54 | sectionparsers["TABLES"] = new TableParser(); 55 | sectionparsers["ENTITIES"] = new EntityParser(); 56 | sectionparsers["BLOCKS"] = new BlockParser(); 57 | ISectionParser currentParser = null; 58 | 59 | TextReader reader = new StreamReader(file); 60 | LoadState state = LoadState.OutsideSection; 61 | int? groupcode; 62 | string value; 63 | reader.ReadDXFEntry(out groupcode, out value); 64 | while (groupcode != null) 65 | { 66 | switch (state) 67 | { 68 | case LoadState.OutsideSection: 69 | if (groupcode == 0 && value.Trim() == "SECTION") 70 | { 71 | state = LoadState.InSection; 72 | reader.ReadDXFEntry(out groupcode, out value); 73 | if (groupcode != 2) 74 | throw new Exception("Sektion gefunden aber keinen Namen zur Sektion"); 75 | value = value.Trim(); 76 | if (sectionparsers.ContainsKey(value)) 77 | currentParser = sectionparsers[value]; 78 | } 79 | break; 80 | case LoadState.InSection: 81 | if (groupcode == 0 && value.Trim() == "ENDSEC") 82 | { 83 | state = LoadState.OutsideSection; 84 | //after each section check wether the File Version is set 85 | if (Header.AutoCADVersion != null && 86 | Header.AutoCADVersion != "AC1014") 87 | { 88 | if (!versionwarningsent) 89 | { 90 | try 91 | { 92 | if (OnFileVersionIncompatible != null) 93 | OnFileVersionIncompatible(this, EventArgs.Empty); 94 | 95 | } 96 | catch (Exception) 97 | { 98 | 99 | } 100 | versionwarningsent = true; 101 | } 102 | } 103 | } 104 | else 105 | { 106 | if (currentParser != null) 107 | { 108 | currentParser.ParseGroupCode(this, (int)groupcode, value); 109 | } 110 | } 111 | break; 112 | default: 113 | break; 114 | } 115 | reader.ReadDXFEntry(out groupcode, out value); 116 | } 117 | if (state == LoadState.InSection) 118 | throw new Exception("Dateiende erreicht aber immer noch offene Sektion vorhanden"); 119 | Thread.CurrentThread.CurrentCulture = currentCulture; 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /DXFLib/DXFEllipse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFEllipse : DXFEntity 9 | { 10 | private DXFPoint center = new DXFPoint(); 11 | public DXFPoint Center { get { return center; } } 12 | 13 | private DXFPoint mainaxis = new DXFPoint(); 14 | public DXFPoint MainAxis { get { return mainaxis; } } 15 | 16 | private DXFPoint extrusion = new DXFPoint(); 17 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 18 | 19 | public double AxisRatio { get; set; } 20 | 21 | public double StartParam { get; set; } 22 | public double EndParam { get; set; } 23 | 24 | public override void ParseGroupCode(int groupcode, string value) 25 | { 26 | base.ParseGroupCode(groupcode, value); 27 | switch (groupcode) 28 | { 29 | case 10: 30 | Center.X = double.Parse(value); 31 | break; 32 | case 20: 33 | Center.Y = double.Parse(value); 34 | break; 35 | case 30: 36 | Center.Z = double.Parse(value); 37 | break; 38 | case 11: 39 | MainAxis.X = double.Parse(value); 40 | break; 41 | case 21: 42 | MainAxis.Y = double.Parse(value); 43 | break; 44 | case 31: 45 | MainAxis.Z = double.Parse(value); 46 | break; 47 | case 210: 48 | ExtrusionDirection.X = double.Parse(value); 49 | break; 50 | case 220: 51 | ExtrusionDirection.Y = double.Parse(value); 52 | break; 53 | case 230: 54 | ExtrusionDirection.Z = double.Parse(value); 55 | break; 56 | case 40: 57 | AxisRatio = double.Parse(value); 58 | break; 59 | case 41: 60 | StartParam = double.Parse(value); 61 | break; 62 | case 42: 63 | EndParam = double.Parse(value); 64 | break; 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /DXFLib/DXFEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFEntity 9 | { 10 | public string EntityType { get; set; } 11 | public string Handle { get; set; } 12 | private List classhierarchy = new List(); 13 | public List ClassHierarchy { get { return classhierarchy; } } 14 | public bool IsInPaperSpace { get; set; } 15 | public string LayerName { get; set; } 16 | public string LineType { get; set; } 17 | public int ColorNumber { get; set; } 18 | public double LineTypeScale { get; set; } 19 | public bool IsInvisible { get; set; } 20 | 21 | public virtual bool HasChildren { get { return (children != null && children.Count > 0); } } 22 | private List children = new List(); 23 | public List Children { get { return children; } } 24 | 25 | public virtual void ParseGroupCode(int groupcode, string value) 26 | { 27 | switch (groupcode) 28 | { 29 | case 0: 30 | EntityType = value; 31 | break; 32 | case 5: 33 | Handle = value; 34 | break; 35 | case 100: 36 | ClassHierarchy.Add(value); 37 | break; 38 | case 67: 39 | IsInPaperSpace = int.Parse(value) == 1; 40 | break; 41 | case 8: 42 | LayerName = value; 43 | break; 44 | case 6: 45 | LineType = value; 46 | break; 47 | case 62: 48 | ColorNumber = int.Parse(value); 49 | break; 50 | case 48: 51 | LineTypeScale = double.Parse(value); 52 | break; 53 | case 60: 54 | IsInvisible = int.Parse(value) == 1; 55 | break; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DXFLib/DXFGenericEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFGenericEntity : DXFEntity 9 | { 10 | public class Entry 11 | { 12 | public int GroupCode { get; set; } 13 | public string Value { get; set; } 14 | public Entry() 15 | { 16 | } 17 | 18 | public Entry(int g, string v) 19 | { 20 | GroupCode = g; 21 | Value = v; 22 | } 23 | } 24 | 25 | private List entries = new List(); 26 | public List Entries { get { return entries; } } 27 | 28 | public override void ParseGroupCode(int groupcode, string value) 29 | { 30 | base.ParseGroupCode(groupcode, value); 31 | Entries.Add(new Entry(groupcode, value)); 32 | } 33 | } 34 | 35 | [Entity("3DSOLID")] 36 | public class DXF3DSolid : DXFGenericEntity 37 | { 38 | } 39 | 40 | [Entity("ACAD_PROXY_ENTITY")] 41 | public class DXF3DAcadProxy : DXFGenericEntity 42 | { 43 | } 44 | 45 | [Entity("ATTDEF")] 46 | public class DXFAttributeDefinition : DXFGenericEntity 47 | { 48 | } 49 | 50 | [Entity("ATTRIB")] 51 | public class DXFAttribute : DXFGenericEntity 52 | { 53 | } 54 | 55 | [Entity("BODY")] 56 | public class DXFBody : DXFGenericEntity 57 | { 58 | } 59 | 60 | [Entity("DIMENSION")] 61 | public class DXFDimension : DXFGenericEntity 62 | { 63 | } 64 | 65 | [Entity("HATCH")] 66 | public class DXFHatch : DXFGenericEntity 67 | { 68 | } 69 | 70 | [Entity("IMAGE")] 71 | public class DXFImage : DXFGenericEntity 72 | { 73 | } 74 | 75 | [Entity("LEADER")] 76 | public class DXFLeader : DXFGenericEntity 77 | { 78 | } 79 | 80 | [Entity("MLINE")] 81 | public class DXFMLine : DXFGenericEntity 82 | { 83 | } 84 | 85 | [Entity("MTEXT")] 86 | public class DXFMText : DXFGenericEntity 87 | { 88 | } 89 | 90 | [Entity("OLEFRAME")] 91 | public class DXFOleFrame : DXFGenericEntity 92 | { 93 | } 94 | 95 | [Entity("OLE2FRAME")] 96 | public class DXFOle2Frame : DXFGenericEntity 97 | { 98 | } 99 | 100 | [Entity("REGION")] 101 | public class DXFRegion : DXFGenericEntity 102 | { 103 | } 104 | 105 | [Entity("VIEWPORT")] 106 | public class DXFViewPort : DXFGenericEntity 107 | { 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /DXFLib/DXFHeader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFHeader 9 | { 10 | [Header("$ACADMAINTVER")] 11 | public int? MaintenanceVersionNumber { get; set; } 12 | 13 | [Header("$ACADVER")] 14 | public string AutoCADVersion { get; set; } 15 | 16 | [Header("$ANGBASE")] 17 | public double? AngleBase { get; set; } 18 | 19 | public enum Direction 20 | { 21 | CounterClockWise=0, 22 | ClockWise=1 23 | } 24 | 25 | [Header("$ANGDIR")] 26 | public Direction? AngleDirection { get; set; } 27 | 28 | [Header("$ATTDIA")] 29 | public bool? AttributeDialogs { get; set; } 30 | 31 | public enum AttribVisibility 32 | { 33 | None = 0, 34 | Normal = 1, 35 | All = 2 36 | } 37 | 38 | [Header("$ATTMODE")] 39 | public AttribVisibility? AttributeVisibility { get; set; } 40 | 41 | [Header("$ATTREQ")] 42 | public bool? RequestAttributesDuringInsert { get; set; } 43 | 44 | [Header("$AUINTS")] 45 | public int? AngleUnits { get; set; } 46 | 47 | [Header("$AUPREC")] 48 | public int? AngleUnitPrecision { get; set; } 49 | 50 | [Header("$BLIPMODE")] 51 | public int? BlipMode { get; set; } 52 | 53 | public enum ColorEntity 54 | { 55 | ByBlock = 0, 56 | ByLayer = 256 57 | } 58 | 59 | [Header("$CECOLOR")] 60 | public ColorEntity? CurrentEntityColor { get; set; } 61 | 62 | [Header("$CELTSCALE")] 63 | public double? CurrentEntityLinetypeScale { get; set; } 64 | 65 | [Header("$CELTYPE")] 66 | public string EntityLinetypeName { get; set; } 67 | 68 | [Header("$CHAMFERA")] 69 | public double? FirstChamferDistance { get; set; } 70 | 71 | [Header("$CHAMFERB")] 72 | public double? SecondChamferDistance { get; set; } 73 | 74 | [Header("$CHAMFERC")] 75 | public double? ChamferLength { get; set; } 76 | 77 | [Header("$CHAMFERD")] 78 | public double? ChamferAngle { get; set; } 79 | 80 | [Header("$CLAYER")] 81 | public string CurrentLayer { get; set; } 82 | 83 | public enum MultilineJustification 84 | { 85 | Top = 0, 86 | Middle = 1, 87 | Bottom = 2 88 | } 89 | 90 | [Header("$CMLJUST")] 91 | public MultilineJustification? CurrentMultilineJustification { get; set; } 92 | 93 | [Header("$CMLSCALE")] 94 | public double? CurrentMultilineScale { get; set; } 95 | 96 | [Header("$CMLSTYLE")] 97 | public string CurrentMultilineStyle { get; set; } 98 | 99 | public enum CoordinateDisplay 100 | { 101 | Static = 0, 102 | UpdateContinuous = 1, 103 | DLessAFormat = 2 104 | } 105 | 106 | [Header("$COORDS")] 107 | public CoordinateDisplay? CoordinateUpdateSetting { get; set; } 108 | 109 | public enum DeletePolicy 110 | { 111 | Deleted = 0, 112 | Retained = 1 113 | } 114 | 115 | [Header("$DELOBJ")] 116 | public DeletePolicy? DeletionPolicy { get; set; } 117 | 118 | [Header("$DIMALT")] 119 | public int? AlternateUnitConversionIfNonzero { get; set; } 120 | 121 | [Header("$DIMALTD")] 122 | public int? AlternateUnitDecimalPlaces { get; set; } 123 | 124 | [Header("$DIMALTF")] 125 | public double? AlternateUnitScaleFactor { get; set; } 126 | 127 | [Header("$DIMALTTD")] 128 | public int? AlternateUnitToleranceDecimals { get; set; } 129 | 130 | public enum SuppressionZeroPolicy 131 | { 132 | SuppressZeroFeetKeepInches = 0, 133 | IncludeZeroFeetKeepInchs = 1, 134 | IncludeZeroFeetSuppressInches = 2, 135 | IncludeZeroInchesSupressFeet = 3 136 | } 137 | 138 | [Header("$DIMALTTZ")] 139 | public SuppressionZeroPolicy? AlternateUnitSuppressionPolicyForTolerances { get; set; } 140 | 141 | public enum UnitType 142 | { 143 | Scientific = 1, 144 | Decimal = 2, 145 | Engineering = 3, 146 | ArchitecturalStacked = 4, 147 | FractionalStacked = 5, 148 | Architectural = 6, 149 | Fractional = 7 150 | } 151 | 152 | [Header("$DIMALTU")] 153 | public UnitType? AlternateUnitFormat { get; set; } 154 | 155 | [Header("$DIMALTZ")] 156 | public SuppressionZeroPolicy? ALternateUnitSuppressionPolicyForValues { get; set; } 157 | 158 | [Header("$DIMAPOST")] 159 | public string AlternateUnitSuffix { get; set; } 160 | 161 | public enum EntityGroupingPolicy 162 | { 163 | CreateAssociations = 1, 164 | DrawIndividual = 0 165 | } 166 | 167 | [Header("$DIMASO")] 168 | public EntityGroupingPolicy? EntityGrouping { get; set; } 169 | 170 | [Header("$DIMASZ")] 171 | public double? DimensioningArrowSize { get; set; } 172 | 173 | public enum Angletype 174 | { 175 | DecimalDegree = 0, 176 | DegreeMinutesSeconds = 1, 177 | Gradians = 2, 178 | Radians = 3, 179 | SurveyoursUnits = 4 180 | } 181 | 182 | [Header("$DIMAUNIT")] 183 | public Angletype? AlternateUnitAngleType { get; set; } 184 | 185 | [Header("$DIMBLK")] 186 | public string ArrowBlockName { get; set; } 187 | 188 | [Header("$DIMBLK1")] 189 | public string FirstArrowBlockName { get; set; } 190 | 191 | [Header("$DIMBLK2")] 192 | public string SecondArrowBlockName { get; set; } 193 | 194 | [Header("$DIMCEN")] 195 | public double? MarkLinesSizeCenter { get; set; } 196 | 197 | [Header("$DIMCLRD")] 198 | public int? DimensionLineColor { get; set; } 199 | 200 | [Header("$DIMCLRE")] 201 | public int? DimensionExtensionLineColor { get; set; } 202 | 203 | [Header("$DIMCLRT")] 204 | public string DimensionLineTextColor { get; set; } 205 | 206 | [Header("$DIMDEC")] 207 | public int? ToleranceDecimalsForPrimaryunit { get; set; } 208 | 209 | [Header("$DIMDLE")] 210 | public double? DimensionLineExtension { get; set; } 211 | 212 | [Header("$DIMDLI")] 213 | public double? DimensionLineIncrement { get; set; } 214 | 215 | [Header("$DIMEXE")] 216 | public double? ExtensionLineExtension { get; set; } 217 | 218 | [Header("$DIMEXO")] 219 | public double? ExtensionLineOffset { get; set; } 220 | 221 | [Header("$DIMFIT")] 222 | public int? TextAndArrowPlacement { get; set; } 223 | 224 | [Header("$DIMGAP")] 225 | public double? DimensionLineGap { get; set; } 226 | 227 | public enum TextPositionings 228 | { 229 | AboveDimensionLineAndCenterJustifiedBetweenExtensionLines = 0, 230 | AboveDimensionLineAndNextToFirstExtensionLine = 1, 231 | AboveDimensionLineAndNextToSecondExtensionLine = 2, 232 | AboveAndCenterJustifiedToFirstExtensionLine = 3, 233 | AboveAndCenterJustifiedToSecondExtensionLine = 4 234 | } 235 | 236 | [Header("$DIMJUST")] 237 | public TextPositionings? HorizontalTextPosition { get; set; } 238 | 239 | [Header("$DIMLFAC")] 240 | public double? LinearMeasurementScaleFactor { get; set; } 241 | 242 | [Header("$DIMLIM")] 243 | public int? DimensionLimitsIfNonZero { get; set; } 244 | 245 | [Header("$DIMPOST")] 246 | public string DimensionSuffix { get; set; } 247 | 248 | [Header("$DIMRND")] 249 | public double? DimensionDistanceRounding { get; set; } 250 | 251 | [Header("$DIMSAH")] 252 | public int? UseSeparateArrowsBlocksIfNonZero { get; set; } 253 | 254 | [Header("$DIMSCALE")] 255 | public double? DimensioningScale { get; set; } 256 | 257 | public enum SuppressionSettings 258 | { 259 | NotSuppressed = 0, 260 | Suppressed = 1 261 | } 262 | 263 | [Header("$DIMSD1")] 264 | public SuppressionSettings? SuppressionOfFirstExtensionLine { get; set; } 265 | 266 | [Header("$DIMSD2")] 267 | public SuppressionSettings? SuppressionOfSecondExtensionLine { get; set; } 268 | 269 | [Header("$DIMSE1")] 270 | public int? SuppressFirstExtensionLineIfNonZero { get; set; } 271 | 272 | [Header("$DIMSE2")] 273 | public int? SuppressSecondExtensionLineIfNonZero { get; set; } 274 | 275 | public enum DraggingPolicy 276 | { 277 | RecomputeDimensionsWhileDragging = 0, 278 | DragOriginalImage = 1 279 | } 280 | 281 | [Header("$DIMSHO")] 282 | public DraggingPolicy? DraggingSettings { get; set; } 283 | 284 | [Header("$DIMSOXD")] 285 | public int? SuppressOutsideExtensionLinesIfNonZero { get; set; } 286 | 287 | [Header("$DIMSTYLE")] 288 | public string DimensionStyleName { get; set; } 289 | 290 | [Header("$DIMTAD")] 291 | public int? TextAboveDimensionLineIfNonZero { get; set; } 292 | 293 | [Header("$DIMTDEC")] 294 | public int? NumberOfDimensionToleranceDecimals { get; set; } 295 | 296 | [Header("$DIMTFAC")] 297 | public double? DimensionToleranceScaleFactor { get; set; } 298 | 299 | [Header("$DIMTIH")] 300 | public int? TextInsideHorizontalIfNonZero { get; set; } 301 | 302 | [Header("$DIMTIX")] 303 | public int? ForceTextInsideExtensionsIfNonZero { get; set; } 304 | 305 | [Header("$DIMTM")] 306 | public double? MinusTolerance { get; set; } 307 | 308 | [Header("$DIMTOFL")] 309 | public int? IfTextOutsideExtensionsForceLineExtensionsBetweenExtensionsIfNonZero { get; set; } 310 | 311 | [Header("$DIMTOH")] 312 | public int? TextOutsideHorizontalIfNonZero { get; set; } 313 | 314 | [Header("$DIMTOL")] 315 | public int? DimensionTolerancesGeneratedIfNonZero { get; set; } 316 | 317 | [Header("$DIMTOLJ")] 318 | public MultilineJustification? ToleranceJustification { get; set; } 319 | 320 | [Header("$DIMTP")] 321 | public double? PlusTolerance { get; set; } 322 | 323 | [Header("$DIMTSZ")] 324 | public double? DimensioningTickSize { get; set; } 325 | 326 | [Header("$DIMTVP")] 327 | public double? TextVerticalPosition { get; set; } 328 | 329 | [Header("$DIMTXSTY")] 330 | public string DimensionTextStyle { get; set; } 331 | 332 | [Header("$DIMTXT")] 333 | public double? DimensionTextHeight { get; set; } 334 | 335 | [Header("$DIMTZIN")] 336 | public SuppressionZeroPolicy? SuppressionOfZerosForToleranceValues { get; set; } 337 | 338 | [Header("$DIMUNIT")] 339 | public UnitType? DimensionUnitType { get; set; } 340 | 341 | public enum CursorControl 342 | { 343 | OnlyDimensionLine = 0, 344 | TextAndDimensionLine = 1 345 | } 346 | 347 | [Header("$DIMUPT")] 348 | public CursorControl? CursorSetting { get; set; } 349 | 350 | [Header("$DIMZIN")] 351 | public SuppressionZeroPolicy? SuppressionOfZerosForPrimaryUnitValues { get; set; } 352 | 353 | public enum DisplaySilhouettePolicy 354 | { 355 | DontDraw = 0, 356 | Draw = 1 357 | } 358 | 359 | [Header("$DISPSILH")] 360 | public DisplaySilhouettePolicy? DisplaySilhoutteInGridMode { get; set; } 361 | 362 | public enum DraggingMode 363 | { 364 | off = 0, 365 | on = 1, 366 | auto = 2 367 | } 368 | 369 | [Header("$DRAGMODE")] 370 | public DraggingMode? DraggingEnabled { get; set; } 371 | 372 | [Header("$DWGCODEPAGE")] 373 | public string CodePage { get; set; } 374 | 375 | [Header("$ELEVATION")] 376 | public double? Elevation { get; set; } 377 | 378 | [Header("$EXTMAX")] 379 | public DXFPoint DrawingExtendsUpperRight { get; set; } 380 | 381 | [Header("$EXTMIN")] 382 | public DXFPoint DrawingExtendsLowerRight { get; set; } 383 | 384 | [Header("$FILLETRAD")] 385 | public double? FilletRadius { get; set; } 386 | 387 | [Header("$FILLMODE")] 388 | public int? FillModeIfNonZero { get; set; } 389 | 390 | [Header("$HANDLING")] 391 | public int? NextAvailableHandle { get; set; } 392 | 393 | [Header("$HANDSEED")] 394 | public string HandleSeed { get; set; } 395 | 396 | [Header("$INSBASE")] 397 | public DXFPoint InsertionBase { get; set; } 398 | 399 | [Header("$LIMCHECK")] 400 | public int? CheckLimitsIfNonZero { get; set; } 401 | 402 | [Header("$LIMMAX")] 403 | public DXFPoint LimitsUpperRight { get; set; } 404 | 405 | [Header("$LIMMIN")] 406 | public DXFPoint LimitsLowerLeft { get; set; } 407 | 408 | [Header("$LTSCALE")] 409 | public double? LineTypeScale { get; set; } 410 | 411 | [Header("$LUNITS")] 412 | public int? UnitsForCoordinatesAndDistances { get; set; } 413 | 414 | [Header("$LUPREC")] 415 | public int? UnitPrecisionForCoordinatesAndDistances { get; set; } 416 | 417 | [Header("$MAXACTVP")] 418 | public int MaximumNumberOfViewPorts { get; set; } 419 | 420 | public enum DrawingUnits 421 | { 422 | English = 0, 423 | Metric = 1 424 | } 425 | 426 | [Header("$MEASUREMENT")] 427 | public DrawingUnits? MeasurementUnits { get; set; } 428 | 429 | [Header("$MENU")] 430 | public string MenuFileName { get; set; } 431 | 432 | [Header("$MIRRTEXT")] 433 | public int? MirrorTextIfNonZero { get; set; } 434 | 435 | [Header("$ORTHOMODE")] 436 | public int? OrthogonalModeOnIfNonZero { get; set; } 437 | 438 | [Header("$OSMODE")] 439 | public int? RunningObjectSnapModes { get; set; } 440 | 441 | [Header("$PDMODE")] 442 | public int? PointDisplayMode { get; set; } 443 | 444 | [Header("$PDSIZE")] 445 | public double? PointDisplaySize { get; set; } 446 | 447 | [Header("$PELEVATION")] 448 | public double? PaperElevation { get; set; } 449 | 450 | [Header("$PEXTMAX")] 451 | public DXFPoint PaperExtensionUpperRight { get; set; } 452 | 453 | [Header("$PEXTMIN")] 454 | public DXFPoint PaperExtensionLowerLeft { get; set; } 455 | 456 | public enum SelectionPolicy 457 | { 458 | NoGroupingAtAll = 0, 459 | GroupSelection = 1, 460 | AssociativeHatchSelection = 2, 461 | Both = 3 462 | } 463 | 464 | [Header("$PICKSTYLE")] 465 | public SelectionPolicy? SelectionBehaviour { get; set; } 466 | 467 | [Header("$PINSBASE")] 468 | public DXFPoint PaperSpaceInsertionBase { get; set; } 469 | 470 | [Header("$PLIMCHECK")] 471 | public int? PaperSpaceLimitCheckingIfNonZero { get; set; } 472 | 473 | [Header("$PLIMMAX")] 474 | public DXFPoint PaperSpaceUpperRightLimit { get; set; } 475 | 476 | [Header("$PLIMMIN")] 477 | public DXFPoint PaperSpaceLowerLeftLimit { get; set; } 478 | 479 | public enum PolyLineGeneration 480 | { 481 | EachVertexADash = 0, 482 | ContinousPatternAroundVertices = 1 483 | } 484 | 485 | [Header("$PLINEGEN")] 486 | public PolyLineGeneration? PolyLineBehaviour { get; set; } 487 | 488 | [Header("$PLINEWID")] 489 | public double? PolyLineWidth { get; set; } 490 | 491 | [Header("$PROXYGRAPHICS")] 492 | public int? ProxyGraphics { get; set; } 493 | 494 | public enum LinetypeScaling 495 | { 496 | ViewportScaling = 0, 497 | NoScaling = 1 498 | } 499 | 500 | [Header("$PSLTSCALE")] 501 | public LinetypeScaling? PaperSpaceLinetypeScaling { get; set; } 502 | 503 | [Header("$PUCSNAME")] 504 | public string PaperSpaceUCSName { get; set; } 505 | 506 | [Header("$PUCSORG")] 507 | public DXFPoint PaperSpaceUCSOrigin { get; set; } 508 | 509 | [Header("$PUCSXDIR")] 510 | public DXFPoint PaperSpaceUCSXAxis { get; set; } 511 | 512 | [Header("$PUCSYDIR")] 513 | public DXFPoint PaperSpaceUCSYAxis { get; set; } 514 | 515 | [Header("$QTEXTMODE")] 516 | public int? QuickTextModeIfNonZero { get; set; } 517 | 518 | [Header("$REGENMODE")] 519 | public int? RegenAutoIfNonZero { get; set; } 520 | 521 | public enum ShadingOptions 522 | { 523 | ShadeFaces = 0, 524 | ShadeFacesHighlightEdgesInBlack = 1, 525 | DontFillFacesAndEdgesInEntityColor = 2, 526 | FacesInEntityColorEdgesInBlack = 3 527 | } 528 | 529 | [Header("$SHADEDGE")] 530 | public ShadingOptions? ShadingSettings { get; set; } 531 | 532 | [Header("$SHADEDIF")] 533 | public int? ShadingAmbientLight { get; set; } 534 | 535 | [Header("$SKETCHINC")] 536 | public double SketchRecordIncrement { get; set; } 537 | 538 | [Header("$SKPOLY")] 539 | public int? SketchLinesIfZeroPolylinesIfOne { get; set; } 540 | 541 | [Header("$SPLFRAME")] 542 | public int? DrawSplineControlPolygonIfOne { get; set; } 543 | 544 | [Header("$SPLINESEGS")] 545 | public int? NumberOfLineSegmentsPerSplinePatch { get; set; } 546 | 547 | [Header("$SPLINETYPE")] 548 | public int? SplineTypeForPEDITSpline { get; set; } 549 | 550 | [Header("$SURFTAB1")] 551 | public int? NumberOfMeshTabulationsInFirstDirection { get; set; } 552 | 553 | [Header("$SURFTAB2")] 554 | public int? NumberOfMeshTabulationsInSecondDirection { get; set; } 555 | 556 | [Header("$SURFTYPE")] 557 | public int? SurfaceTypeForPEDITSmooth { get; set; } 558 | 559 | [Header("$SURFU")] 560 | public int? SurfaceDensityForPEDITSmoothInM { get; set; } 561 | 562 | [Header("$SURFV")] 563 | public int? SurfaceDensityForPEDITSmoothInN { get; set; } 564 | 565 | [Header("$TDCREATE")] 566 | public double? CreationDate { get; set; } 567 | 568 | [Header("$TDINDWG")] 569 | public double? TotalEditingTime { get; set; } 570 | 571 | [Header("$TDUPDATE")] 572 | public double? UpdateDate { get; set; } 573 | 574 | [Header("$TDUSRTIMER")] 575 | public double? UserElapsedTimer { get; set; } 576 | 577 | [Header("$TEXTSIZE")] 578 | public double? DefaultTextSize { get; set; } 579 | 580 | [Header("$TEXTSTYLE")] 581 | public string DefaultTextStyle { get; set; } 582 | 583 | [Header("$THICKNESS")] 584 | public double? Thickness { get; set; } 585 | 586 | [Header("$TILEMODE")] 587 | public int? ReleaseCompatibilityTileModeIfOne { get; set; } 588 | 589 | [Header("$TRACEWID")] 590 | public double? TraceWidth { get; set; } 591 | 592 | [Header("$TREEDEPTH")] 593 | public int? MaximumDepthOfSpatialIndex { get; set; } 594 | 595 | [Header("$UCSNAME")] 596 | public string UCSName { get; set; } 597 | 598 | [Header("$UCSORG")] 599 | public DXFPoint UCSOrigin { get; set; } 600 | 601 | [Header("$UCSXDIR")] 602 | public DXFPoint UCSXAxis { get; set; } 603 | 604 | [Header("$UCSYDIR")] 605 | public DXFPoint UCSYAxis { get; set; } 606 | 607 | [Header("$UNITMODE")] 608 | public int? UnitMode { get; set; } 609 | 610 | [Header("$USERI1")] 611 | public int? UserInt1 { get; set; } 612 | 613 | [Header("$USERI2")] 614 | public int? UserInt2 { get; set; } 615 | 616 | [Header("$USERI3")] 617 | public int? UserInt3 { get; set; } 618 | 619 | [Header("$USERI4")] 620 | public int? UserInt4 { get; set; } 621 | 622 | [Header("$USERI5")] 623 | public int? UserInt5 { get; set; } 624 | 625 | [Header("$USERR1")] 626 | public double? UserReal1 { get; set; } 627 | 628 | [Header("$USERR2")] 629 | public double? UserReal2 { get; set; } 630 | 631 | [Header("$USERR3")] 632 | public double? UserReal3 { get; set; } 633 | 634 | [Header("$USERR4")] 635 | public double? UserReal4 { get; set; } 636 | 637 | [Header("$USERR5")] 638 | public double? UserReal5 { get; set; } 639 | 640 | [Header("$USRTIMER")] 641 | public int? UserTimerEnabledIfOne { get; set; } 642 | 643 | [Header("$VISRETAIN")] 644 | public int? RetainVisibleXRefDependendVisibilitySettingsIfOne { get; set; } 645 | 646 | [Header("$WORLDVIEW")] 647 | public int? SetUCSToWCSDuringVIEWIfOne { get; set; } 648 | 649 | } 650 | } 651 | -------------------------------------------------------------------------------- /DXFLib/DXFInsert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("INSERT")] 9 | public class DXFInsert : DXFEntity 10 | { 11 | public string BlockName { get; set; } 12 | private DXFPoint insertionPoint = new DXFPoint(); 13 | public DXFPoint InsertionPoint { get { return insertionPoint; } } 14 | private DXFPoint scaling = new DXFPoint(); 15 | public DXFPoint Scaling { get { return scaling; } } 16 | public double? RotationAngle { get; set; } 17 | private DXFPoint extrusionDirection = new DXFPoint(); 18 | public DXFPoint ExtrusionDirection { get { return extrusionDirection; } } 19 | 20 | public override void ParseGroupCode(int groupcode, string value) 21 | { 22 | base.ParseGroupCode(groupcode, value); 23 | switch (groupcode) 24 | { 25 | case 2: 26 | BlockName = value; 27 | break; 28 | case 10: 29 | InsertionPoint.X = double.Parse(value); 30 | break; 31 | case 20: 32 | InsertionPoint.Y = double.Parse(value); 33 | break; 34 | case 30: 35 | InsertionPoint.Z = double.Parse(value); 36 | break; 37 | case 41: 38 | Scaling.X = double.Parse(value); 39 | break; 40 | case 42: 41 | Scaling.Y = double.Parse(value); 42 | break; 43 | case 43: 44 | Scaling.Z = double.Parse(value); 45 | break; 46 | case 50: 47 | RotationAngle = double.Parse(value); 48 | break; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /DXFLib/DXFLWPolyLine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("LWPOLYLINE")] 9 | public class DXFLWPolyLine : DXFEntity 10 | { 11 | public int VertexCount { get; set; } 12 | 13 | [Flags] 14 | public enum FlagsEnum 15 | { 16 | closed = 1, 17 | plinegen = 128 18 | } 19 | 20 | public FlagsEnum Flags { get; set; } 21 | 22 | public double? ConstantWidth { get; set; } 23 | public double Elevation { get; set; } 24 | public double Thickness { get; set; } 25 | 26 | public class Element 27 | { 28 | private DXFPoint vertex = new DXFPoint(); 29 | public DXFPoint Vertex { get { return vertex; } } 30 | public double StartWidth { get; set; } 31 | public double EndWidth { get; set; } 32 | public double Bulge { get; set; } 33 | } 34 | 35 | private List elements = new List(); 36 | public List Elements { get { return elements; } } 37 | 38 | private Element LastElement 39 | { 40 | get 41 | { 42 | if (Elements.Count == 0) 43 | return null; 44 | return Elements[Elements.Count - 1]; 45 | } 46 | set 47 | { 48 | Elements.Add(value); 49 | } 50 | } 51 | 52 | private DXFPoint extrusion = new DXFPoint(); 53 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 54 | 55 | public override void ParseGroupCode(int groupcode, string value) 56 | { 57 | base.ParseGroupCode(groupcode, value); 58 | switch (groupcode) 59 | { 60 | case 90: 61 | VertexCount = int.Parse(value); 62 | break; 63 | case 70: 64 | Flags = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), value); 65 | break; 66 | case 43: 67 | ConstantWidth = double.Parse(value); 68 | break; 69 | case 38: 70 | Elevation = double.Parse(value); 71 | break; 72 | case 39: 73 | Thickness = double.Parse(value); 74 | break; 75 | case 10: 76 | if (LastElement == null || LastElement.Vertex.X != null) 77 | LastElement = new Element(); 78 | LastElement.Vertex.X = double.Parse(value); 79 | break; 80 | case 20: 81 | if (LastElement == null || LastElement.Vertex.Y != null) 82 | LastElement = new Element(); 83 | LastElement.Vertex.Y = double.Parse(value); 84 | break; 85 | case 40: 86 | LastElement.StartWidth = double.Parse(value); 87 | break; 88 | case 41: 89 | LastElement.EndWidth = double.Parse(value); 90 | break; 91 | case 42: 92 | LastElement.Bulge = double.Parse(value); 93 | break; 94 | case 210: 95 | ExtrusionDirection.X = double.Parse(value); 96 | break; 97 | case 220: 98 | ExtrusionDirection.Y = double.Parse(value); 99 | break; 100 | case 230: 101 | ExtrusionDirection.Z = double.Parse(value); 102 | break; 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /DXFLib/DXFLayerRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFLayerRecord : DXFRecord 9 | { 10 | public string LayerName { get; set; } 11 | public int Color { get; set; } 12 | public string LineType { get; set; } 13 | 14 | public override string ToString() 15 | { 16 | return string.Format("Name:{0} LineType:{1}", LayerName, LineType); 17 | } 18 | } 19 | 20 | class DXFLayerRecordParser : DXFRecordParser 21 | { 22 | private DXFLayerRecord _record; 23 | protected override DXFRecord currentRecord 24 | { 25 | get { return _record; } 26 | } 27 | 28 | protected override void createRecord(DXFDocument doc) 29 | { 30 | _record = new DXFLayerRecord(); 31 | doc.Tables.Layers.Add(_record); 32 | } 33 | 34 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 35 | { 36 | base.ParseGroupCode(doc, groupcode, value); 37 | switch (groupcode) 38 | { 39 | case 2: 40 | _record.LayerName = value; 41 | break; 42 | case 62: 43 | _record.Color = int.Parse(value); 44 | break; 45 | case 6: 46 | _record.LineType = value; 47 | break; 48 | } 49 | } 50 | } 51 | 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /DXFLib/DXFLib.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {476FA4C4-FA1D-4A2A-985B-8CBF50F82251} 9 | Library 10 | Properties 11 | DXFLib 12 | DXFLib 13 | v4.8 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | 23 | true 24 | full 25 | false 26 | bin\Debug\ 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | false 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | false 40 | 41 | 42 | 43 | 44 | 3.5 45 | 46 | 47 | 3.5 48 | 49 | 50 | 3.5 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 113 | -------------------------------------------------------------------------------- /DXFLib/DXFLine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("LINE")] 9 | public class DXFLine : DXFEntity 10 | { 11 | private DXFPoint start = new DXFPoint(); 12 | public DXFPoint Start { get { return start; } } 13 | 14 | private DXFPoint end = new DXFPoint(); 15 | public DXFPoint End { get { return end; } } 16 | 17 | public double Thickness { get; set; } 18 | 19 | private DXFPoint extrusion = new DXFPoint(); 20 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 21 | 22 | public override void ParseGroupCode(int groupcode, string value) 23 | { 24 | base.ParseGroupCode(groupcode, value); 25 | switch (groupcode) 26 | { 27 | case 39: 28 | Thickness = double.Parse(value); 29 | break; 30 | case 10: 31 | Start.X = double.Parse(value); 32 | break; 33 | case 20: 34 | Start.Y = double.Parse(value); 35 | break; 36 | case 30: 37 | Start.Z = double.Parse(value); 38 | break; 39 | case 11: 40 | End.X = double.Parse(value); 41 | break; 42 | case 21: 43 | End.Y = double.Parse(value); 44 | break; 45 | case 31: 46 | End.Z = double.Parse(value); 47 | break; 48 | case 210: 49 | ExtrusionDirection.X = double.Parse(value); 50 | break; 51 | case 220: 52 | ExtrusionDirection.Y = double.Parse(value); 53 | break; 54 | case 230: 55 | ExtrusionDirection.Z = double.Parse(value); 56 | break; 57 | 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /DXFLib/DXFLineTypeRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFLineTypeRecord : DXFRecord 9 | { 10 | public string LineTypeName { get; set; } 11 | public string Description { get; set; } 12 | public int AlignmentCode { get; set; } 13 | 14 | public override string ToString() 15 | { 16 | return string.Format("{0} ({1}) ({2})", LineTypeName, Description, AlignmentCode); 17 | } 18 | 19 | [Flags] 20 | public enum ElementFlags 21 | { 22 | None=0, 23 | AbsoluteRotation=1, 24 | IsString=2, 25 | IsShape=4 26 | } 27 | 28 | public class LineTypeElement 29 | { 30 | public double Length { get; set; } 31 | public ElementFlags Flags { get; set; } 32 | public int? ShapeNumber { get; set; } 33 | public string Shape { get; set; } 34 | private List scalings = new List(); 35 | public List Scalings { get { return scalings; } } 36 | public double? Rotation { get; set; } 37 | private List xoffsets = new List(); 38 | public List XOffsets { get { return xoffsets; } } 39 | private List yoffsets = new List(); 40 | public List YOffsets { get { return yoffsets; } } 41 | 42 | public string Text { get; set; } 43 | } 44 | 45 | private List elements = new List(); 46 | public List Elements { get { return elements; } } 47 | public int ElementCount { get; set; } 48 | public double PatternLength { get; set; } 49 | } 50 | 51 | class DXFLineTypeRecordParser : DXFRecordParser 52 | { 53 | private DXFLineTypeRecord _record; 54 | private DXFLineTypeRecord.LineTypeElement _subrecord; 55 | 56 | protected override DXFRecord currentRecord 57 | { 58 | get { return _record; } 59 | } 60 | 61 | protected override void createRecord(DXFDocument doc) 62 | { 63 | _record = new DXFLineTypeRecord(); 64 | doc.Tables.LineTypes.Add(_record); 65 | } 66 | 67 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 68 | { 69 | base.ParseGroupCode(doc, groupcode, value); 70 | switch (groupcode) 71 | { 72 | case 2: 73 | _record.LineTypeName = value; 74 | break; 75 | case 3: 76 | _record.Description = value; 77 | break; 78 | case 72: 79 | _record.AlignmentCode = int.Parse(value); 80 | break; 81 | case 73: 82 | _record.ElementCount = int.Parse(value); 83 | break; 84 | case 40: 85 | _record.PatternLength = double.Parse(value); 86 | break; 87 | case 49: 88 | _subrecord = new DXFLineTypeRecord.LineTypeElement(); 89 | _record.Elements.Add(_subrecord); 90 | _subrecord.Length = double.Parse(value); 91 | break; 92 | case 74: 93 | _subrecord.Flags = (DXFLineTypeRecord.ElementFlags)Enum.Parse(typeof(DXFLineTypeRecord.ElementFlags), value); 94 | break; 95 | case 75: 96 | _subrecord.ShapeNumber = int.Parse(value); 97 | break; 98 | case 340: 99 | _subrecord.Shape = value; 100 | break; 101 | case 46: 102 | _subrecord.Scalings.Add(double.Parse(value)); 103 | break; 104 | case 50: 105 | _subrecord.Rotation = double.Parse(value); 106 | break; 107 | case 44: 108 | _subrecord.XOffsets.Add(double.Parse(value)); 109 | break; 110 | case 45: 111 | _subrecord.YOffsets.Add(double.Parse(value)); 112 | break; 113 | case 9: 114 | _subrecord.Text = value; 115 | break; 116 | } 117 | } 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /DXFLib/DXFPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFPoint 9 | { 10 | public double? X { get; set; } 11 | public double? Y { get; set; } 12 | public double? Z { get; set; } 13 | 14 | public override string ToString() 15 | { 16 | return string.Format("X:{0} Y:{1} Z:{2}", X, Y, Z); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DXFLib/DXFPointEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("POINT")] 9 | public class DXFPointEntity : DXFEntity 10 | { 11 | private DXFPoint location = new DXFPoint(); 12 | public DXFPoint Location { get { return location; } } 13 | 14 | public double Thickness { get; set; } 15 | 16 | private DXFPoint extrusion = new DXFPoint(); 17 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 18 | 19 | public double XAxisAngle { get; set; } 20 | 21 | public override void ParseGroupCode(int groupcode, string value) 22 | { 23 | base.ParseGroupCode(groupcode, value); 24 | switch (groupcode) 25 | { 26 | case 10: 27 | Location.X = double.Parse(value); 28 | break; 29 | case 20: 30 | Location.Y = double.Parse(value); 31 | break; 32 | case 30: 33 | Location.Z = double.Parse(value); 34 | break; 35 | case 39: 36 | Thickness = double.Parse(value); 37 | break; 38 | case 50: 39 | XAxisAngle = double.Parse(value); 40 | break; 41 | case 210: 42 | ExtrusionDirection.X = double.Parse(value); 43 | break; 44 | case 220: 45 | ExtrusionDirection.Y = double.Parse(value); 46 | break; 47 | case 230: 48 | ExtrusionDirection.Z = double.Parse(value); 49 | break; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DXFLib/DXFPolyLine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("POLYLINE")] 9 | public class DXFPolyLine : DXFEntity 10 | { 11 | public double Elevation { get; set; } 12 | public double Thickness { get; set; } 13 | [Flags] 14 | public enum FlagsEnum 15 | { 16 | closed = 1, 17 | CurveFitVerticesAdded = 2, 18 | SplineFitVerticesAdded = 4, 19 | Is3DPolyLine = 8, 20 | Is3DPolyMesh = 16, 21 | MeshIsClosed = 32, 22 | IsPolyFace = 64, 23 | LineTypePatternContinous = 128 24 | } 25 | 26 | public FlagsEnum Flags { get; set; } 27 | public double DefaultStartWidth { get; set; } 28 | public double DefaultEndWidth { get; set; } 29 | public int MVertexCount { get; set; } 30 | public int NVertexCount { get; set; } 31 | public int SurfaceMDensity { get; set; } 32 | public int SurfaceNDensity { get; set; } 33 | public int CurvesAndSmoothSurfaceType { get; set; } 34 | 35 | private DXFPoint extrusion = new DXFPoint(); 36 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 37 | 38 | public override bool HasChildren 39 | { 40 | get 41 | { 42 | return true; 43 | } 44 | } 45 | 46 | public override void ParseGroupCode(int groupcode, string value) 47 | { 48 | base.ParseGroupCode(groupcode, value); 49 | switch (groupcode) 50 | { 51 | case 30: 52 | Elevation = double.Parse(value); 53 | break; 54 | case 39: 55 | Thickness = double.Parse(value); 56 | break; 57 | case 70: 58 | Flags = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), value); 59 | break; 60 | case 40: 61 | DefaultStartWidth = double.Parse(value); 62 | break; 63 | case 41: 64 | DefaultEndWidth = double.Parse(value); 65 | break; 66 | case 71: 67 | MVertexCount = int.Parse(value); 68 | break; 69 | case 72: 70 | NVertexCount = int.Parse(value); 71 | break; 72 | case 73: 73 | SurfaceMDensity = int.Parse(value); 74 | break; 75 | case 74: 76 | SurfaceNDensity = int.Parse(value); 77 | break; 78 | case 75: 79 | CurvesAndSmoothSurfaceType = int.Parse(value); 80 | break; 81 | case 210: 82 | ExtrusionDirection.X = double.Parse(value); 83 | break; 84 | case 220: 85 | ExtrusionDirection.Y = double.Parse(value); 86 | break; 87 | case 230: 88 | ExtrusionDirection.Z = double.Parse(value); 89 | break; 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /DXFLib/DXFRay.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("RAY")] 9 | public class DXFRay : DXFEntity 10 | { 11 | private DXFPoint startpoint = new DXFPoint(); 12 | public DXFPoint Start { get { return startpoint; } } 13 | 14 | private DXFPoint direction = new DXFPoint(); 15 | public DXFPoint Direction { get { return direction; } } 16 | 17 | public override void ParseGroupCode(int groupcode, string value) 18 | { 19 | base.ParseGroupCode(groupcode, value); 20 | switch (groupcode) 21 | { 22 | case 10: 23 | Start.X = double.Parse(value); 24 | break; 25 | case 20: 26 | Start.Y = double.Parse(value); 27 | break; 28 | case 30: 29 | Start.Z = double.Parse(value); 30 | break; 31 | case 11: 32 | Direction.X = double.Parse(value); 33 | break; 34 | case 21: 35 | Direction.Y = double.Parse(value); 36 | break; 37 | case 31: 38 | Direction.Z = double.Parse(value); 39 | break; 40 | } 41 | } 42 | } 43 | 44 | [Entity("XLINE")] 45 | public class DXFXLine : DXFRay 46 | { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /DXFLib/DXFShape.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("SHAPE")] 9 | class DXFShape : DXFEntity 10 | { 11 | public double Thickness { get; set; } 12 | private DXFPoint insertion = new DXFPoint(); 13 | public DXFPoint InsertionPoint { get { return insertion; } } 14 | public double Size { get; set; } 15 | public string ShapeName { get; set; } 16 | public double RotationAngle { get; set; } 17 | public double RelativeXScale { get; set; } 18 | public double ObliqueAngle { get; set; } 19 | private DXFPoint extrusion = new DXFPoint(); 20 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 21 | 22 | public override void ParseGroupCode(int groupcode, string value) 23 | { 24 | base.ParseGroupCode(groupcode, value); 25 | switch (groupcode) 26 | { 27 | case 39: 28 | Thickness = double.Parse(value); 29 | break; 30 | case 10: 31 | InsertionPoint.X = double.Parse(value); 32 | break; 33 | case 20: 34 | InsertionPoint.Y = double.Parse(value); 35 | break; 36 | case 30: 37 | InsertionPoint.Z = double.Parse(value); 38 | break; 39 | case 40: 40 | Size = double.Parse(value); 41 | break; 42 | case 2: 43 | ShapeName = value; 44 | break; 45 | case 50: 46 | RotationAngle = double.Parse(value); 47 | break; 48 | case 41: 49 | RelativeXScale = double.Parse(value); 50 | break; 51 | case 51: 52 | ObliqueAngle = double.Parse(value); 53 | break; 54 | case 210: 55 | ExtrusionDirection.X = double.Parse(value); 56 | break; 57 | case 220: 58 | ExtrusionDirection.Y = double.Parse(value); 59 | break; 60 | case 230: 61 | ExtrusionDirection.Z = double.Parse(value); 62 | break; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /DXFLib/DXFSolid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("SOLID")] 9 | public class DXFSolid : DXFEntity 10 | { 11 | private DXFPoint extrusion = new DXFPoint(); 12 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 13 | private DXFPoint[] corners = new DXFPoint[] { new DXFPoint(), new DXFPoint(), new DXFPoint(), new DXFPoint() }; 14 | public DXFPoint[] Corners { get { return corners; } } 15 | 16 | public override void ParseGroupCode(int groupcode, string value) 17 | { 18 | base.ParseGroupCode(groupcode, value); 19 | if (groupcode >= 10 && groupcode <= 33) 20 | { 21 | int idx = groupcode % 10; 22 | int component = groupcode / 10; 23 | switch (component) 24 | { 25 | case 1: 26 | Corners[idx].X = double.Parse(value); 27 | break; 28 | case 2: 29 | Corners[idx].Y = double.Parse(value); 30 | break; 31 | case 3: 32 | Corners[idx].Z = double.Parse(value); 33 | break; 34 | } 35 | } 36 | 37 | switch (groupcode) 38 | { 39 | case 210: 40 | ExtrusionDirection.X = double.Parse(value); 41 | break; 42 | case 220: 43 | ExtrusionDirection.Y = double.Parse(value); 44 | break; 45 | case 230: 46 | ExtrusionDirection.Z = double.Parse(value); 47 | break; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /DXFLib/DXFSpline.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("SPLINE")] 9 | public class DXFSpline : DXFEntity 10 | { 11 | private DXFPoint normal = new DXFPoint(); 12 | public DXFPoint Normal { get { return normal; } } 13 | 14 | [Flags] 15 | public enum FlagsEnum 16 | { 17 | Closed = 1, 18 | Periodic = 2, 19 | Rational = 4, 20 | Planar = 8, 21 | Linear = 16 22 | } 23 | public FlagsEnum Flags { get; set; } 24 | 25 | public int Degree { get; set; } 26 | public int KnotCount { get; set; } 27 | public int ControlPointCount { get; set; } 28 | public int FitPointCount { get; set; } 29 | 30 | public double KnotTolerance { get; set; } 31 | public double ControlPointTolerance { get; set; } 32 | public double FitPointTolerance { get; set; } 33 | 34 | private DXFPoint starttangent = new DXFPoint(); 35 | public DXFPoint StartTangent { get { return starttangent; } } 36 | 37 | private DXFPoint endtangent = new DXFPoint(); 38 | public DXFPoint EndTangent { get { return endtangent; } } 39 | 40 | private List knotvalues = new List(); 41 | public List KnotValues { get { return knotvalues; } } 42 | 43 | public double Weight { get; set; } 44 | 45 | private List controlpoints = new List(); 46 | public List ControlPoints { get { return controlpoints; } } 47 | 48 | private List fitpoints = new List(); 49 | public List FitPoints { get { return fitpoints; } } 50 | 51 | private DXFPoint LastControlPoint 52 | { 53 | get 54 | { 55 | if (ControlPoints.Count == 0) return null; 56 | return ControlPoints[ControlPoints.Count - 1]; 57 | } 58 | set 59 | { 60 | ControlPoints.Add(value); 61 | } 62 | } 63 | 64 | private DXFPoint LastFitPoint 65 | { 66 | get 67 | { 68 | if (FitPoints.Count == 0) return null; 69 | return FitPoints[FitPoints.Count - 1]; 70 | } 71 | set 72 | { 73 | FitPoints.Add(value); 74 | } 75 | } 76 | 77 | public override void ParseGroupCode(int groupcode, string value) 78 | { 79 | base.ParseGroupCode(groupcode, value); 80 | switch (groupcode) 81 | { 82 | case 210: 83 | Normal.X = double.Parse(value); 84 | break; 85 | case 220: 86 | Normal.Y = double.Parse(value); 87 | break; 88 | case 230: 89 | Normal.Z = double.Parse(value); 90 | break; 91 | case 70: 92 | Flags = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), value); 93 | break; 94 | case 71: 95 | Degree = int.Parse(value); 96 | break; 97 | case 72: 98 | KnotCount = int.Parse(value); 99 | break; 100 | case 73: 101 | ControlPointCount = int.Parse(value); 102 | break; 103 | case 74: 104 | FitPointCount = int.Parse(value); 105 | break; 106 | case 42: 107 | KnotTolerance = double.Parse(value); 108 | break; 109 | case 43: 110 | ControlPointTolerance = double.Parse(value); 111 | break; 112 | case 44: 113 | FitPointTolerance = double.Parse(value); 114 | break; 115 | case 12: 116 | StartTangent.X = double.Parse(value); 117 | break; 118 | case 22: 119 | StartTangent.Y = double.Parse(value); 120 | break; 121 | case 32: 122 | StartTangent.Z = double.Parse(value); 123 | break; 124 | case 13: 125 | EndTangent.X = double.Parse(value); 126 | break; 127 | case 23: 128 | EndTangent.Y = double.Parse(value); 129 | break; 130 | case 33: 131 | EndTangent.Z = double.Parse(value); 132 | break; 133 | case 40: 134 | KnotValues.Add(double.Parse(value)); 135 | break; 136 | case 41: 137 | Weight = double.Parse(value); 138 | break; 139 | case 10: 140 | if (LastControlPoint==null || LastControlPoint.X != null) 141 | LastControlPoint = new DXFPoint(); 142 | LastControlPoint.X = double.Parse(value); 143 | break; 144 | case 20: 145 | if (LastControlPoint == null || LastControlPoint.Y != null) 146 | LastControlPoint = new DXFPoint(); 147 | LastControlPoint.Y = double.Parse(value); 148 | break; 149 | case 30: 150 | if (LastControlPoint == null || LastControlPoint.Z != null) 151 | LastControlPoint = new DXFPoint(); 152 | LastControlPoint.Z = double.Parse(value); 153 | break; 154 | case 11: 155 | if (LastFitPoint == null || LastFitPoint.X != null) 156 | LastFitPoint = new DXFPoint(); 157 | LastFitPoint.X = double.Parse(value); 158 | break; 159 | case 21: 160 | if (LastFitPoint == null || LastFitPoint.Y != null) 161 | LastFitPoint = new DXFPoint(); 162 | LastFitPoint.Y = double.Parse(value); 163 | break; 164 | case 31: 165 | if (LastFitPoint == null || LastFitPoint.Z != null) 166 | LastFitPoint = new DXFPoint(); 167 | LastFitPoint.Z = double.Parse(value); 168 | break; 169 | } 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /DXFLib/DXFStyleRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFStyleRecord : DXFRecord 9 | { 10 | public string StyleName { get; set; } 11 | public double FixedHeight { get; set; } 12 | public double WidthFactor { get; set; } 13 | public double ObliqueAngle { get; set; } 14 | 15 | public override string ToString() 16 | { 17 | return string.Format("{0} ({1}) ({2})", StyleName, FixedHeight, WidthFactor); 18 | } 19 | 20 | [Flags] 21 | public enum TextGenerationFlags 22 | { 23 | MirrorX=2, 24 | MirrorY=4 25 | } 26 | 27 | public TextGenerationFlags GenerationFlags { get; set; } 28 | 29 | public double LastUsedHeight { get; set; } 30 | public string FontFileName { get; set; } 31 | public string BigFontFileName { get; set; } 32 | } 33 | 34 | class DXFStyleRecordParser : DXFRecordParser 35 | { 36 | DXFStyleRecord _record; 37 | 38 | protected override DXFRecord currentRecord 39 | { 40 | get { return _record; } 41 | } 42 | 43 | protected override void createRecord(DXFDocument doc) 44 | { 45 | _record = new DXFStyleRecord(); 46 | doc.Tables.Styles.Add(_record); 47 | } 48 | 49 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 50 | { 51 | base.ParseGroupCode(doc, groupcode, value); 52 | switch (groupcode) 53 | { 54 | case 2: 55 | _record.StyleName = value; 56 | break; 57 | case 40: 58 | _record.FixedHeight = double.Parse(value); 59 | break; 60 | case 41: 61 | _record.WidthFactor = double.Parse(value); 62 | break; 63 | case 50: 64 | _record.ObliqueAngle = double.Parse(value); 65 | break; 66 | case 71: 67 | _record.GenerationFlags = (DXFStyleRecord.TextGenerationFlags)Enum.Parse(typeof(DXFStyleRecord.TextGenerationFlags), value); 68 | break; 69 | case 42: 70 | _record.LastUsedHeight = double.Parse(value); 71 | break; 72 | case 3: 73 | _record.FontFileName = value; 74 | break; 75 | case 4: 76 | _record.BigFontFileName = value; 77 | break; 78 | } 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /DXFLib/DXFTables.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFTables 9 | { 10 | private List appids = new List(); 11 | [Table("APPID",typeof(DXFAppIDParser))] 12 | public List AppIDs { get { return appids; } } 13 | 14 | private List blocks = new List(); 15 | [Table("BLOCK_RECORD", typeof(DXFBlockRecordParser))] 16 | public List Blocks { get { return blocks; } } 17 | 18 | private List dimstyles = new List(); 19 | [Table("DIMSTYLE", typeof(DXFDimStyleRecordParser))] 20 | public List DimStyles { get { return dimstyles; } } 21 | 22 | private List layers = new List(); 23 | [Table("LAYER", typeof(DXFLayerRecordParser))] 24 | public List Layers { get { return layers; } } 25 | 26 | private List linetypes = new List(); 27 | [Table("LTYPE", typeof(DXFLineTypeRecordParser))] 28 | public List LineTypes { get { return linetypes; } } 29 | 30 | private List styles = new List(); 31 | [Table("STYLE", typeof(DXFStyleRecordParser))] 32 | public List Styles { get { return styles; } } 33 | 34 | private List ucs = new List(); 35 | [Table("UCS", typeof(DXFUCSRecordParser))] 36 | public List UCS { get { return ucs; } } 37 | 38 | private List views = new List(); 39 | [Table("VIEW", typeof(DXFViewRecordParser))] 40 | public List Views { get { return views; } } 41 | 42 | private List vports = new List(); 43 | [Table("VPORT", typeof(DXFVPortRecordParser))] 44 | public List VPorts { get { return vports; } } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /DXFLib/DXFText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("TEXT")] 9 | public class DXFText : DXFGenericEntity 10 | { 11 | public string Text { get; set; } 12 | 13 | public override void ParseGroupCode(int groupcode, string value) 14 | { 15 | base.ParseGroupCode(groupcode, value); 16 | switch (groupcode) 17 | { 18 | case 1: 19 | Text = value; 20 | break; 21 | default: 22 | base.ParseGroupCode(groupcode, value); 23 | break; 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DXFLib/DXFTolerance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("TOLERANCE")] 9 | public class DXFTolerance : DXFEntity 10 | { 11 | public string DimensionStyle { get; set; } 12 | private DXFPoint insertion = new DXFPoint(); 13 | public DXFPoint InsertionPoint { get { return insertion; } } 14 | private DXFPoint extrusion = new DXFPoint(); 15 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 16 | private DXFPoint direction = new DXFPoint(); 17 | public DXFPoint Direction { get { return direction; } } 18 | 19 | public override void ParseGroupCode(int groupcode, string value) 20 | { 21 | base.ParseGroupCode(groupcode, value); 22 | switch (groupcode) 23 | { 24 | case 3: 25 | DimensionStyle = value; 26 | break; 27 | case 10: 28 | InsertionPoint.X = double.Parse(value); 29 | break; 30 | case 20: 31 | InsertionPoint.Y = double.Parse(value); 32 | break; 33 | case 30: 34 | InsertionPoint.Z = double.Parse(value); 35 | break; 36 | case 11: 37 | Direction.X = double.Parse(value); 38 | break; 39 | case 21: 40 | Direction.Y = double.Parse(value); 41 | break; 42 | case 31: 43 | Direction.Z = double.Parse(value); 44 | break; 45 | case 210: 46 | ExtrusionDirection.X = double.Parse(value); 47 | break; 48 | case 220: 49 | ExtrusionDirection.Y = double.Parse(value); 50 | break; 51 | case 230: 52 | ExtrusionDirection.Z = double.Parse(value); 53 | break; 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /DXFLib/DXFTrace.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("TRACE")] 9 | public class DXFTrace : DXFEntity 10 | { 11 | private DXFPoint extrusion = new DXFPoint(); 12 | public DXFPoint ExtrusionDirection { get { return extrusion; } } 13 | private DXFPoint[] corners = new DXFPoint[] { new DXFPoint(), new DXFPoint(), new DXFPoint(), new DXFPoint() }; 14 | public DXFPoint[] Corners { get { return corners; } } 15 | 16 | public double Thickness { get; set; } 17 | 18 | public override void ParseGroupCode(int groupcode, string value) 19 | { 20 | base.ParseGroupCode(groupcode, value); 21 | if (groupcode >= 10 && groupcode <= 33) 22 | { 23 | int idx = groupcode % 10; 24 | int component = groupcode / 10; 25 | switch (component) 26 | { 27 | case 1: 28 | Corners[idx].X = double.Parse(value); 29 | break; 30 | case 2: 31 | Corners[idx].Y = double.Parse(value); 32 | break; 33 | case 3: 34 | Corners[idx].Z = double.Parse(value); 35 | break; 36 | } 37 | } 38 | 39 | switch (groupcode) 40 | { 41 | case 39: 42 | Thickness = double.Parse(value); 43 | break; 44 | case 210: 45 | ExtrusionDirection.X = double.Parse(value); 46 | break; 47 | case 220: 48 | ExtrusionDirection.Y = double.Parse(value); 49 | break; 50 | case 230: 51 | ExtrusionDirection.Z = double.Parse(value); 52 | break; 53 | } 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /DXFLib/DXFUCSRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFUCSRecord : DXFRecord 9 | { 10 | public string UCSName { get; set; } 11 | private DXFPoint origin = new DXFPoint(); 12 | public DXFPoint Origin { get { return origin; } } 13 | private DXFPoint xaxis=new DXFPoint(); 14 | public DXFPoint XAxis { get { return xaxis; } } 15 | private DXFPoint yaxis = new DXFPoint(); 16 | public DXFPoint YAxis { get { return yaxis; } } 17 | 18 | public override string ToString() 19 | { 20 | return string.Format("{0} Origin:{1}", UCSName, Origin); 21 | } 22 | } 23 | 24 | class DXFUCSRecordParser : DXFRecordParser 25 | { 26 | private DXFUCSRecord _record; 27 | protected override DXFRecord currentRecord 28 | { 29 | get { return _record; } 30 | } 31 | 32 | protected override void createRecord(DXFDocument doc) 33 | { 34 | _record = new DXFUCSRecord(); 35 | doc.Tables.UCS.Add(_record); 36 | } 37 | 38 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 39 | { 40 | base.ParseGroupCode(doc, groupcode, value); 41 | switch (groupcode) 42 | { 43 | case 2: 44 | _record.UCSName = value; 45 | break; 46 | case 10: 47 | _record.Origin.X = double.Parse(value); 48 | break; 49 | case 20: 50 | _record.Origin.Y = double.Parse(value); 51 | break; 52 | case 30: 53 | _record.Origin.Z = double.Parse(value); 54 | break; 55 | case 11: 56 | _record.XAxis.X = double.Parse(value); 57 | break; 58 | case 21: 59 | _record.XAxis.Y = double.Parse(value); 60 | break; 61 | case 31: 62 | _record.XAxis.Z = double.Parse(value); 63 | break; 64 | case 12: 65 | _record.YAxis.X = double.Parse(value); 66 | break; 67 | case 22: 68 | _record.YAxis.Y = double.Parse(value); 69 | break; 70 | case 32: 71 | _record.YAxis.Z = double.Parse(value); 72 | break; 73 | } 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /DXFLib/DXFVPortRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFVPortRecord : DXFRecord 9 | { 10 | public string VPortName { get; set; } 11 | private DXFPoint lowerleft = new DXFPoint(); 12 | public DXFPoint LowerLeftCorner { get { return lowerleft; } } 13 | private DXFPoint upperright = new DXFPoint(); 14 | public DXFPoint UpperRightCorner { get { return upperright; } } 15 | private DXFPoint center = new DXFPoint(); 16 | public DXFPoint Center { get { return center; } } 17 | private DXFPoint snapbase = new DXFPoint(); 18 | public DXFPoint SnapBase { get { return snapbase; } } 19 | private DXFPoint snapspacing = new DXFPoint(); 20 | public DXFPoint SnapSpacing { get { return snapspacing; } } 21 | private DXFPoint gridspacing = new DXFPoint(); 22 | public DXFPoint GridSpacing { get { return gridspacing; } } 23 | private DXFPoint direction = new DXFPoint(); 24 | public DXFPoint Direction { get { return direction; } } 25 | private DXFPoint target = new DXFPoint(); 26 | public DXFPoint Target { get { return target; } } 27 | 28 | public double Height { get; set; } 29 | public double AspectRatio { get; set; } 30 | public double LensLength { get; set; } 31 | public double FrontClippingPlane { get; set; } 32 | public double BackClippingPlane { get; set; } 33 | public double SnapRotationAngle { get; set; } 34 | public double TwistAngle { get; set; } 35 | public int ViewMode { get; set; } 36 | public int CircleZoomPercent { get; set; } 37 | public int FastZoomSetting { get; set; } 38 | public int UCSICONSetting { get; set; } 39 | public int SnapEnabled { get; set; } 40 | public int GridEnabled { get; set; } 41 | public int SnapStyle { get; set; } 42 | public int SnapIsoPair { get; set; } 43 | 44 | } 45 | 46 | class DXFVPortRecordParser : DXFRecordParser 47 | { 48 | private DXFVPortRecord _record; 49 | protected override DXFRecord currentRecord 50 | { 51 | get { return _record; } 52 | } 53 | 54 | protected override void createRecord(DXFDocument doc) 55 | { 56 | _record = new DXFVPortRecord(); 57 | doc.Tables.VPorts.Add(_record); 58 | } 59 | 60 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 61 | { 62 | base.ParseGroupCode(doc, groupcode, value); 63 | switch (groupcode) 64 | { 65 | case 2: 66 | _record.VPortName = value; 67 | break; 68 | case 10: 69 | _record.LowerLeftCorner.X = double.Parse(value); 70 | break; 71 | case 20: 72 | _record.LowerLeftCorner.Y = double.Parse(value); 73 | break; 74 | case 11: 75 | _record.UpperRightCorner.X = double.Parse(value); 76 | break; 77 | case 21: 78 | _record.UpperRightCorner.Y = double.Parse(value); 79 | break; 80 | case 12: 81 | _record.Center.X = double.Parse(value); 82 | break; 83 | case 22: 84 | _record.Center.Y = double.Parse(value); 85 | break; 86 | case 13: 87 | _record.SnapBase.X = double.Parse(value); 88 | break; 89 | case 23: 90 | _record.SnapBase.Y = double.Parse(value); 91 | break; 92 | case 14: 93 | _record.SnapSpacing.X = double.Parse(value); 94 | break; 95 | case 24: 96 | _record.SnapSpacing.Y = double.Parse(value); 97 | break; 98 | case 15: 99 | _record.GridSpacing.X = double.Parse(value); 100 | break; 101 | case 25: 102 | _record.GridSpacing.Y = double.Parse(value); 103 | break; 104 | case 16: 105 | _record.Direction.X = double.Parse(value); 106 | break; 107 | case 26: 108 | _record.Direction.Y = double.Parse(value); 109 | break; 110 | case 36: 111 | _record.Direction.Z = double.Parse(value); 112 | break; 113 | case 17: 114 | _record.Target.X = double.Parse(value); 115 | break; 116 | case 27: 117 | _record.Target.Y = double.Parse(value); 118 | break; 119 | case 37: 120 | _record.Target.Z = double.Parse(value); 121 | break; 122 | case 40: 123 | _record.Height = double.Parse(value); 124 | break; 125 | case 41: 126 | _record.AspectRatio = double.Parse(value); 127 | break; 128 | case 42: 129 | _record.LensLength = double.Parse(value); 130 | break; 131 | case 43: 132 | _record.FrontClippingPlane = double.Parse(value); 133 | break; 134 | case 44: 135 | _record.BackClippingPlane = double.Parse(value); 136 | break; 137 | case 50: 138 | _record.SnapRotationAngle = double.Parse(value); 139 | break; 140 | case 51: 141 | _record.TwistAngle = double.Parse(value); 142 | break; 143 | case 71: 144 | _record.ViewMode = int.Parse(value); 145 | break; 146 | case 72: 147 | _record.CircleZoomPercent = int.Parse(value); 148 | break; 149 | case 73: 150 | _record.FastZoomSetting = int.Parse(value); 151 | break; 152 | case 74: 153 | _record.UCSICONSetting = int.Parse(value); 154 | break; 155 | case 75: 156 | _record.SnapEnabled = int.Parse(value); 157 | break; 158 | case 76: 159 | _record.GridEnabled = int.Parse(value); 160 | break; 161 | case 77: 162 | _record.SnapStyle = int.Parse(value); 163 | break; 164 | case 78: 165 | _record.SnapIsoPair = int.Parse(value); 166 | break; 167 | } 168 | } 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /DXFLib/DXFVertex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [Entity("VERTEX")] 9 | public class DXFVertex : DXFEntity 10 | { 11 | private DXFPoint location = new DXFPoint(); 12 | public DXFPoint Location { get { return location; } } 13 | public double StartWidth { get; set; } 14 | public double EndWidth { get; set; } 15 | public double Buldge { get; set; } 16 | 17 | [Flags] 18 | public enum FlagsEnum 19 | { 20 | IsExtraVertex = 1, 21 | CurveFitTangentDefined = 2, 22 | NotUsed = 4, 23 | SplineVertexCreatedForSplineFitting = 8, 24 | SplineFrameControlPoint = 16, 25 | PolyLineVertex = 32, 26 | PolyLineMesh = 64, 27 | PolyFaceMesh = 128 28 | } 29 | 30 | public FlagsEnum Flags { get; set; } 31 | 32 | private int[] indices = { 0, 0, 0, 0 }; 33 | public int[] PolyfaceIndices { get { return indices; } } 34 | 35 | public double CurveFitTangentDirection { get; set; } 36 | 37 | public override void ParseGroupCode(int groupcode, string value) 38 | { 39 | base.ParseGroupCode(groupcode, value); 40 | switch (groupcode) 41 | { 42 | case 10: 43 | Location.X = double.Parse(value); 44 | break; 45 | case 20: 46 | Location.Y = double.Parse(value); 47 | break; 48 | case 30: 49 | Location.Z = double.Parse(value); 50 | break; 51 | case 40: 52 | StartWidth = double.Parse(value); 53 | break; 54 | case 41: 55 | EndWidth = double.Parse(value); 56 | break; 57 | case 42: 58 | Buldge = double.Parse(value); 59 | break; 60 | case 70: 61 | Flags = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), value); 62 | break; 63 | case 50: 64 | CurveFitTangentDirection = double.Parse(value); 65 | break; 66 | case 71: 67 | case 72: 68 | case 73: 69 | case 74: 70 | { 71 | int idx = groupcode % 10; 72 | idx--; 73 | PolyfaceIndices[idx] = int.Parse(value); 74 | } 75 | break; 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /DXFLib/DXFViewPortRecord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | public class DXFViewRecord : DXFRecord 9 | { 10 | public string ViewPortName { get; set; } 11 | public double Height { get; set; } 12 | public double Width { get; set; } 13 | private DXFPoint center = new DXFPoint(); 14 | public DXFPoint Center { get { return center; } } 15 | private DXFPoint direction = new DXFPoint(); 16 | public DXFPoint Direction { get { return direction; } } 17 | private DXFPoint target = new DXFPoint(); 18 | public DXFPoint Target { get { return target; } } 19 | 20 | public double FrontClippingPlane { get; set; } 21 | public double BackClippingPlane { get; set; } 22 | public double TwistAngle { get; set; } 23 | public double LensLength { get; set; } 24 | public int ViewMode { get; set; } 25 | } 26 | 27 | class DXFViewRecordParser : DXFRecordParser 28 | { 29 | private DXFViewRecord _record; 30 | protected override DXFRecord currentRecord 31 | { 32 | get { return _record; } 33 | } 34 | 35 | protected override void createRecord(DXFDocument doc) 36 | { 37 | _record = new DXFViewRecord(); 38 | doc.Tables.Views.Add(_record); 39 | } 40 | 41 | public override void ParseGroupCode(DXFDocument doc, int groupcode, string value) 42 | { 43 | base.ParseGroupCode(doc, groupcode, value); 44 | switch (groupcode) 45 | { 46 | case 2: 47 | _record.ViewPortName = value; 48 | break; 49 | case 40: 50 | _record.Height = double.Parse(value); 51 | break; 52 | case 41: 53 | _record.Width = double.Parse(value); 54 | break; 55 | case 10: 56 | _record.Center.X = double.Parse(value); 57 | break; 58 | case 20: 59 | _record.Center.Y = double.Parse(value); 60 | break; 61 | case 11: 62 | _record.Direction.X = double.Parse(value); 63 | break; 64 | case 21: 65 | _record.Direction.Y = double.Parse(value); 66 | break; 67 | case 31: 68 | _record.Direction.Z = double.Parse(value); 69 | break; 70 | case 12: 71 | _record.Target.X = double.Parse(value); 72 | break; 73 | case 22: 74 | _record.Target.Y = double.Parse(value); 75 | break; 76 | case 32: 77 | _record.Target.Z = double.Parse(value); 78 | break; 79 | case 42: 80 | _record.LensLength = double.Parse(value); 81 | break; 82 | case 43: 83 | _record.FrontClippingPlane = double.Parse(value); 84 | break; 85 | case 44: 86 | _record.BackClippingPlane = double.Parse(value); 87 | break; 88 | case 50: 89 | _record.TwistAngle = double.Parse(value); 90 | break; 91 | case 71: 92 | _record.ViewMode = int.Parse(value); 93 | break; 94 | } 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /DXFLib/EntityAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [AttributeUsage(AttributeTargets.Class)] 9 | class EntityAttribute : Attribute 10 | { 11 | public string EntityName; 12 | public EntityAttribute(string Name) 13 | { 14 | this.EntityName = Name; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DXFLib/EntityParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | 7 | namespace DXFLib 8 | { 9 | class EntityParser : ISectionParser 10 | { 11 | private Dictionary Entities = new Dictionary(); 12 | private DXFEntity currentEntity = null; 13 | private Stack stack = new Stack(); 14 | #region ISectionParser Member 15 | 16 | public void ParseGroupCode(DXFDocument doc, int groupcode, string value) 17 | { 18 | if (Entities.Count == 0) 19 | { 20 | foreach (Type t in Assembly.GetCallingAssembly().GetTypes()) 21 | { 22 | if (t.IsClass && !t.IsAbstract) 23 | { 24 | object[] attrs = t.GetCustomAttributes(false); 25 | foreach(object attr in attrs) 26 | { 27 | EntityAttribute casted = attr as EntityAttribute; 28 | if (casted != null) 29 | { 30 | Entities.Add(casted.EntityName, t); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | if (groupcode == 0) 37 | { 38 | if (value == "SEQEND") 39 | { 40 | if (stack.Count != 0) 41 | currentEntity = stack.Pop(); 42 | } 43 | if (Entities.ContainsKey(value)) 44 | { 45 | if (currentEntity!=null && currentEntity.HasChildren) 46 | { 47 | stack.Push(currentEntity); 48 | } 49 | currentEntity = Activator.CreateInstance(Entities[value]) as DXFEntity; 50 | if (stack.Count>0 && stack.Peek().HasChildren) 51 | { 52 | stack.Peek().Children.Add(currentEntity); 53 | } 54 | else 55 | { 56 | doc.Entities.Add(currentEntity); 57 | } 58 | } 59 | else 60 | { 61 | currentEntity = null; 62 | //TODO: warning 63 | } 64 | } 65 | if (currentEntity != null) 66 | { 67 | currentEntity.ParseGroupCode(groupcode, value); 68 | } 69 | } 70 | 71 | #endregion 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /DXFLib/HeaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [AttributeUsage(AttributeTargets.Property)] 9 | class HeaderAttribute : Attribute 10 | { 11 | public string Name; 12 | 13 | public HeaderAttribute(string varname) 14 | { 15 | this.Name = varname; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DXFLib/HeaderParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | 7 | namespace DXFLib 8 | { 9 | class HeaderParser: ISectionParser 10 | { 11 | private Dictionary fields = new Dictionary(); 12 | #region ISectionParser Member 13 | 14 | PropertyInfo currentVar = null; 15 | public void ParseGroupCode(DXFDocument doc, int groupcode, string value) 16 | { 17 | if (fields.Count == 0) 18 | { 19 | Type header = doc.Header.GetType(); 20 | foreach (PropertyInfo info in header.GetProperties(BindingFlags.Public | BindingFlags.Instance)) 21 | { 22 | if (info.CanWrite && info.CanRead) 23 | { 24 | object[] attrs = info.GetCustomAttributes(true); 25 | foreach (object attr in attrs) 26 | { 27 | HeaderAttribute casted = attr as HeaderAttribute; 28 | if (casted != null) 29 | { 30 | fields[casted.Name] = info; 31 | } 32 | } 33 | } 34 | } 35 | } 36 | 37 | if (groupcode == 9) 38 | { 39 | string name = value.Trim(); 40 | if (fields.ContainsKey(name)) 41 | { 42 | currentVar = fields[name]; 43 | } 44 | else 45 | { 46 | currentVar = null; 47 | } 48 | } 49 | else if(currentVar!=null) 50 | { 51 | //at first we need to differentiate the types: nullable vs string and nullable vs rest 52 | if (currentVar.PropertyType.Equals(typeof(string))) 53 | { 54 | currentVar.SetValue(doc.Header, value, null); 55 | } 56 | else if (currentVar.PropertyType.IsGenericType && currentVar.PropertyType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) 57 | { 58 | Type boxedType = currentVar.PropertyType.GetGenericArguments()[0]; 59 | if(boxedType.Equals(typeof(int))) 60 | { 61 | int? parsed; 62 | if (value.ToLower().Contains('a') || 63 | value.ToLower().Contains('b') || 64 | value.ToLower().Contains('c') || 65 | value.ToLower().Contains('d') || 66 | value.ToLower().Contains('e') || 67 | value.ToLower().Contains('f')) 68 | { 69 | parsed = int.Parse(value, System.Globalization.NumberStyles.HexNumber); 70 | } 71 | else 72 | parsed = int.Parse(value, System.Globalization.NumberStyles.Any); 73 | currentVar.SetValue(doc.Header, parsed, null); 74 | } 75 | else if(boxedType.Equals(typeof(double))) 76 | { 77 | double? parsed = double.Parse(value); 78 | currentVar.SetValue(doc.Header, parsed, null); 79 | } 80 | else if (boxedType.Equals(typeof(bool))) 81 | { 82 | int? parsed = int.Parse(value); 83 | if (parsed != 0) 84 | currentVar.SetValue(doc.Header, (bool?)true, null); 85 | else 86 | currentVar.SetValue(doc.Header, (bool?)false, null); 87 | } 88 | else if (boxedType.IsEnum) 89 | { 90 | object parsed = Enum.Parse(boxedType, value); 91 | currentVar.SetValue(doc.Header, parsed, null); 92 | } 93 | } 94 | else if (currentVar.PropertyType.Equals(typeof(DXFPoint))) 95 | { 96 | DXFPoint p = (DXFPoint)currentVar.GetValue(doc.Header, null); 97 | if (p == null) 98 | { 99 | p = new DXFPoint(); 100 | currentVar.SetValue(doc.Header, p, null); 101 | } 102 | switch (groupcode) 103 | { 104 | case 10: 105 | p.X = double.Parse(value); 106 | break; 107 | case 20: 108 | p.Y = double.Parse(value); 109 | break; 110 | case 30: 111 | p.Z = double.Parse(value); 112 | break; 113 | default: 114 | break; 115 | } 116 | } 117 | } 118 | } 119 | 120 | #endregion 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /DXFLib/ISectionParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | interface ISectionParser 9 | { 10 | void ParseGroupCode(DXFDocument doc, int groupcode, string value); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DXFLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("DXFLib")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("DXFLib")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("544e3f16-5baa-4772-9e7b-fac2ca4c079e")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /DXFLib/TableAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DXFLib 7 | { 8 | [AttributeUsage(AttributeTargets.Property)] 9 | class TableAttribute : Attribute 10 | { 11 | public string TableName; 12 | public Type TableParser; 13 | 14 | public TableAttribute(string name, Type parser) 15 | { 16 | this.TableName = name; 17 | this.TableParser = parser; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DXFLib/TableParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | 7 | namespace DXFLib 8 | { 9 | class TableParser: ISectionParser 10 | { 11 | private Dictionary tablehandlers = new Dictionary(); 12 | #region ISectionParser Member 13 | 14 | private ISectionParser currentParser = null; 15 | private bool waitingtableheader = false; 16 | private bool ignoretable = false; 17 | private bool firstrecordfound = false; 18 | public void ParseGroupCode(DXFDocument doc, int groupcode, string value) 19 | { 20 | if (tablehandlers.Count == 0) 21 | { 22 | foreach (PropertyInfo info in doc.Tables.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) 23 | { 24 | object[] attrs = info.GetCustomAttributes(true); 25 | foreach (object attr in attrs) 26 | { 27 | TableAttribute casted = attr as TableAttribute; 28 | if (casted != null) 29 | { 30 | tablehandlers[casted.TableName] = (ISectionParser)Activator.CreateInstance(casted.TableParser); 31 | } 32 | } 33 | } 34 | } 35 | if (currentParser == null) 36 | { 37 | if (groupcode == 0 && value.Trim() == "TABLE") 38 | { 39 | waitingtableheader = true; 40 | } 41 | else if (waitingtableheader && groupcode == 2 && !ignoretable) 42 | { 43 | if (tablehandlers.ContainsKey(value.Trim())) 44 | { 45 | currentParser = tablehandlers[value.Trim()]; 46 | waitingtableheader = false; 47 | ignoretable = false; 48 | firstrecordfound = false; 49 | } 50 | else 51 | { 52 | //TODO: generate warning 53 | ignoretable = true; 54 | } 55 | } 56 | else if (waitingtableheader && groupcode == 0 && value.Trim() == "ENDTAB") 57 | { 58 | waitingtableheader = false; 59 | ignoretable = false; 60 | } 61 | } 62 | else 63 | { 64 | if (groupcode == 0 && value.Trim() == "ENDTAB") 65 | { 66 | currentParser = null; 67 | } 68 | else 69 | { 70 | if (groupcode == 0) 71 | { 72 | firstrecordfound = true; 73 | } 74 | if (firstrecordfound) 75 | currentParser.ParseGroupCode(doc, groupcode, value); 76 | } 77 | } 78 | } 79 | 80 | #endregion 81 | } 82 | 83 | public class DXFRecord 84 | { 85 | public string Handle { get; set; } 86 | public string DimStyleHandle { get; set; } 87 | List classhierarchy = new List(); 88 | public List Classhierarchy { get { return classhierarchy; } } 89 | 90 | public int Flags { get; set; } 91 | 92 | } 93 | 94 | abstract class DXFRecordParser : ISectionParser 95 | { 96 | protected abstract DXFRecord currentRecord { get; } 97 | 98 | protected abstract void createRecord(DXFDocument doc); 99 | #region ISectionParser Member 100 | 101 | public virtual void ParseGroupCode(DXFDocument doc, int groupcode, string value) 102 | { 103 | switch (groupcode) 104 | { 105 | case 0: 106 | createRecord(doc); 107 | break; 108 | case 5: 109 | currentRecord.Handle = value; 110 | break; 111 | case 70: 112 | currentRecord.Flags = int.Parse(value); 113 | break; 114 | case 105: 115 | currentRecord.DimStyleHandle = value; 116 | break; 117 | case 100: 118 | currentRecord.Classhierarchy.Add(value); 119 | break; 120 | } 121 | } 122 | 123 | #endregion 124 | } 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /DXFLib/TextReaderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | 7 | namespace DXFLib 8 | { 9 | public static class TextReaderExtensions 10 | { 11 | public static void ReadDXFEntry(this TextReader obj, out int? groupcode, out string value) 12 | { 13 | string line = obj.ReadLine(); 14 | if (line == null) 15 | { 16 | groupcode = null; 17 | value = null; 18 | return; 19 | } 20 | int buf; 21 | if (int.TryParse(line.Trim(), out buf)) 22 | { 23 | groupcode = buf; 24 | value = obj.ReadLine(); 25 | } 26 | else 27 | { 28 | value = null; 29 | groupcode = null; 30 | } 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /DxfEditor.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DxfEditor", "DxfEditor\DxfEditor.csproj", "{38B12E17-6974-4514-A892-0F820066B901}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DXFLib", "DXFLib\DXFLib.csproj", "{476FA4C4-FA1D-4A2A-985B-8CBF50F82251}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{10EB7E91-6E50-4B0A-8943-740DAB10168E}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZoomableCanvas", "ZoomableCanvas\ZoomableCanvas.csproj", "{962F5736-02ED-452A-9950-1A9A419ED4B3}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {38B12E17-6974-4514-A892-0F820066B901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {38B12E17-6974-4514-A892-0F820066B901}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {38B12E17-6974-4514-A892-0F820066B901}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {38B12E17-6974-4514-A892-0F820066B901}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {476FA4C4-FA1D-4A2A-985B-8CBF50F82251}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {476FA4C4-FA1D-4A2A-985B-8CBF50F82251}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {476FA4C4-FA1D-4A2A-985B-8CBF50F82251}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {476FA4C4-FA1D-4A2A-985B-8CBF50F82251}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {962F5736-02ED-452A-9950-1A9A419ED4B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {962F5736-02ED-452A-9950-1A9A419ED4B3}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {962F5736-02ED-452A-9950-1A9A419ED4B3}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {962F5736-02ED-452A-9950-1A9A419ED4B3}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(NestedProjects) = preSolution 37 | {476FA4C4-FA1D-4A2A-985B-8CBF50F82251} = {10EB7E91-6E50-4B0A-8943-740DAB10168E} 38 | {962F5736-02ED-452A-9950-1A9A419ED4B3} = {10EB7E91-6E50-4B0A-8943-740DAB10168E} 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /DxfEditor/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /DxfEditor/App.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DxfEditor/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace DxfEditor 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DxfEditor/Dxf/draft1.dxf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Dxf/draft1.dxf -------------------------------------------------------------------------------- /DxfEditor/Dxf/draft2.dxf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Dxf/draft2.dxf -------------------------------------------------------------------------------- /DxfEditor/Dxf/draft3.dxf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Dxf/draft3.dxf -------------------------------------------------------------------------------- /DxfEditor/Dxf/draft4.dxf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Dxf/draft4.dxf -------------------------------------------------------------------------------- /DxfEditor/Dxf/heart.dxf: -------------------------------------------------------------------------------- 1 | 0 2 | SECTION 3 | 2 4 | HEADER 5 | 9 6 | $ACADVER 7 | 1 8 | AC1009 9 | 9 10 | $EXTMAX 11 | 10 12 | 18.7563037872314 13 | 20 14 | 17.3704471588135 15 | 30 16 | 0.0 17 | 9 18 | $EXTMIN 19 | 10 20 | -18.5722980499268 21 | 20 22 | -18.3061656951904 23 | 30 24 | 0.0 25 | 9 26 | $INSUNITS 27 | 70 28 | 4 29 | 9 30 | $LUNITS 31 | 70 32 | 2 33 | 9 34 | $LUPREC 35 | 70 36 | 4 37 | 9 38 | $MEASUREMENT 39 | 70 40 | 1 41 | 0 42 | ENDSEC 43 | 0 44 | SECTION 45 | 2 46 | TABLES 47 | 0 48 | TABLE 49 | 2 50 | LAYER 51 | 70 52 | 1 53 | 0 54 | LAYER 55 | 2 56 | 0 57 | 70 58 | 0 59 | 62 60 | 7 61 | 6 62 | Continuous 63 | 0 64 | LAYER 65 | 2 66 | Default 67 | 70 68 | 0 69 | 62 70 | 12 71 | 6 72 | Continuous 73 | 0 74 | ENDTAB 75 | 0 76 | TABLE 77 | 2 78 | APPID 79 | 70 80 | 1 81 | 0 82 | APPID 83 | 2 84 | ACAD 85 | 70 86 | 0 87 | 0 88 | ENDTAB 89 | 0 90 | ENDSEC 91 | 0 92 | SECTION 93 | 2 94 | ENTITIES 95 | 0 96 | POLYLINE 97 | 8 98 | Default 99 | 66 100 | 1 101 | 10 102 | 0.0 103 | 20 104 | 0.0 105 | 30 106 | 0.0 107 | 70 108 | 1 109 | 0 110 | VERTEX 111 | 8 112 | Default 113 | 10 114 | -11.044165 115 | 20 116 | 16.958071 117 | 42 118 | -0.0945441500549 119 | 0 120 | VERTEX 121 | 8 122 | Default 123 | 10 124 | -7.9193811120231 125 | 20 126 | 17.3544858935407 127 | 42 128 | -0.0627916675696 129 | 0 130 | VERTEX 131 | 8 132 | Default 133 | 10 134 | -5.6021447082953 135 | 20 136 | 16.9177939893609 137 | 42 138 | -0.0411910462455 139 | 0 140 | VERTEX 141 | 8 142 | Default 143 | 10 144 | -3.9683515695595 145 | 20 146 | 16.2414420285186 147 | 42 148 | -0.1148382442263 149 | 0 150 | VERTEX 151 | 8 152 | Default 153 | 10 154 | 0.036858 155 | 20 156 | 12.827899 157 | 42 158 | -0.0409910683384 159 | 0 160 | VERTEX 161 | 8 162 | Default 163 | 10 164 | 1.8286407920475 165 | 20 166 | 14.6406489084183 167 | 42 168 | -0.0370010462439 169 | 0 170 | VERTEX 171 | 8 172 | Default 173 | 10 174 | 3.3707266689815 175 | 20 176 | 15.7826422391631 177 | 42 178 | -0.0329999312585 179 | 0 180 | VERTEX 181 | 8 182 | Default 183 | 10 184 | 4.6362188151923 185 | 20 186 | 16.4747281889535 187 | 42 188 | -0.0179250164729 189 | 0 190 | VERTEX 191 | 8 192 | Default 193 | 10 194 | 4.7594679139034 195 | 20 196 | 16.5310136352468 197 | 42 198 | -0.0563552071545 199 | 0 200 | VERTEX 201 | 8 202 | Default 203 | 10 204 | 6.7525513958131 205 | 20 206 | 17.1769773163201 207 | 42 208 | -0.0641682515208 209 | 0 210 | VERTEX 211 | 8 212 | Default 213 | 10 214 | 8.842302 215 | 20 216 | 17.327633 217 | 42 218 | -0.0348017462066 219 | 0 220 | VERTEX 221 | 8 222 | Default 223 | 10 224 | 9.7855569599075 225 | 20 226 | 17.28408303492 227 | 42 228 | 0.0 229 | 0 230 | VERTEX 231 | 8 232 | Default 233 | 10 234 | 9.9900810518121 235 | 20 236 | 17.2569979931993 237 | 42 238 | -0.0528378712107 239 | 0 240 | VERTEX 241 | 8 242 | Default 243 | 10 244 | 11.5334978231503 245 | 20 246 | 16.8549982580135 247 | 42 248 | -0.0313060823941 249 | 0 250 | VERTEX 251 | 8 252 | Default 253 | 10 254 | 12.6236016993884 255 | 20 256 | 16.3657465215598 257 | 42 258 | 0.0 259 | 0 260 | VERTEX 261 | 8 262 | Default 263 | 10 264 | 12.8207477231717 265 | 20 266 | 16.2594948408358 267 | 42 268 | -0.0079920788604 269 | 0 270 | VERTEX 271 | 8 272 | Default 273 | 10 274 | 13.184375418984 275 | 20 276 | 16.0493897873807 277 | 42 278 | -0.0275821225592 279 | 0 280 | VERTEX 281 | 8 282 | Default 283 | 10 284 | 14.395907837624 285 | 20 286 | 15.2184098932769 287 | 42 288 | -0.0232533662654 289 | 0 290 | VERTEX 291 | 8 292 | Default 293 | 10 294 | 15.518494 295 | 20 296 | 14.270822 297 | 42 298 | -0.0379212514505 299 | 0 300 | VERTEX 301 | 8 302 | Default 303 | 10 304 | 16.6025229292483 305 | 20 306 | 12.9461236945203 307 | 42 308 | -0.0631459083101 309 | 0 310 | VERTEX 311 | 8 312 | Default 313 | 10 314 | 17.989965025106 315 | 20 316 | 10.2975053256995 317 | 42 318 | -0.0934884939389 319 | 0 320 | VERTEX 321 | 8 322 | Default 323 | 10 324 | 18.7555714659279 325 | 20 326 | 5.889866441974 327 | 42 328 | -0.0508017617255 329 | 0 330 | VERTEX 331 | 8 332 | Default 333 | 10 334 | 18.4927418462803 335 | 20 336 | 3.6560763943616 337 | 42 338 | -0.0551746433587 339 | 0 340 | VERTEX 341 | 8 342 | Default 343 | 10 344 | 17.770015 345 | 20 346 | 1.526095 347 | 42 348 | -0.0501982483982 349 | 0 350 | VERTEX 351 | 8 352 | Default 353 | 10 354 | 16.8908395993521 355 | 20 356 | -0.1659109036573 357 | 42 358 | -0.0255441930063 359 | 0 360 | VERTEX 361 | 8 362 | Default 363 | 10 364 | 16.0487888302989 365 | 20 366 | -1.3189400843113 367 | 42 368 | 0.0 369 | 0 370 | VERTEX 371 | 8 372 | Default 373 | 10 374 | 15.8786380838055 375 | 20 376 | -1.5254589540708 377 | 42 378 | -0.0067785462604 379 | 0 380 | VERTEX 381 | 8 382 | Default 383 | 10 384 | 15.5514386547129 385 | 20 386 | -1.9058936431457 387 | 42 388 | 0.0 389 | 0 390 | VERTEX 391 | 8 392 | Default 393 | 10 394 | 15.4053888953443 395 | 20 396 | -2.0697681591516 397 | 42 398 | 0.0 399 | 0 400 | VERTEX 401 | 8 402 | Default 403 | 10 404 | 15.2670374071794 405 | 20 406 | -2.2221595387619 407 | 42 408 | 0.0 409 | 0 410 | VERTEX 411 | 8 412 | Default 413 | 10 414 | 15.0044949888455 415 | 20 416 | -2.5048307893503 417 | 42 418 | 0.0 419 | 0 420 | VERTEX 421 | 8 422 | Default 423 | 10 424 | 14.7718392678301 425 | 20 426 | -2.7494317131248 427 | 42 428 | -0.0070293131487 429 | 0 430 | VERTEX 431 | 8 432 | Default 433 | 10 434 | 14.5664388903768 435 | 20 436 | -2.9617358561001 437 | 42 438 | -0.0088293360701 439 | 0 440 | VERTEX 441 | 8 442 | Default 443 | 10 444 | 14.4761337728618 445 | 20 446 | -3.0541922648135 447 | 42 448 | 0.0 449 | 0 450 | VERTEX 451 | 8 452 | Default 453 | 10 454 | 14.1357284629266 455 | 20 456 | -3.3990630105133 457 | 42 458 | 0.0 459 | 0 460 | VERTEX 461 | 8 462 | Default 463 | 10 464 | 13.109389 465 | 20 466 | -4.428692 467 | 42 468 | 0.0037787173171 469 | 0 470 | VERTEX 471 | 8 472 | Default 473 | 10 474 | 12.8383119691952 475 | 20 476 | -4.6869726882304 477 | 42 478 | 0.0030948482746 479 | 0 480 | VERTEX 481 | 8 482 | Default 483 | 10 484 | 12.5847454695973 485 | 20 486 | -4.9296952223258 487 | 42 488 | 0.0033872007626 489 | 0 490 | VERTEX 491 | 8 492 | Default 493 | 10 494 | 12.1105370694451 495 | 20 496 | -5.3860620565939 497 | 42 498 | 0.0024354408726 499 | 0 500 | VERTEX 501 | 8 502 | Default 503 | 10 504 | 11.696595095635 505 | 20 506 | -5.7864254286417 507 | 42 508 | 0.0020110753481 509 | 0 510 | VERTEX 511 | 8 512 | Default 513 | 10 514 | 11.3349041175125 515 | 20 516 | -6.1372613261016 517 | 42 518 | 0.0018702371525 519 | 0 520 | VERTEX 521 | 8 522 | Default 523 | 10 524 | 11.018638719214 525 | 20 526 | -6.4444587526666 527 | 42 528 | -0.0026130412217 529 | 0 530 | VERTEX 531 | 8 532 | Default 533 | 10 534 | 10.465211946139 535 | 20 536 | -6.9820817487058 537 | 42 538 | -0.0022939754291 539 | 0 540 | VERTEX 541 | 8 542 | Default 543 | 10 544 | 10.0497868537485 545 | 20 546 | -7.3849230763298 547 | 42 548 | -0.0015520349305 549 | 0 550 | VERTEX 551 | 8 552 | Default 553 | 10 554 | 8.798261 555 | 20 556 | -8.587979 557 | 42 558 | 0.0 559 | 0 560 | VERTEX 561 | 8 562 | Default 563 | 10 564 | 8.0981349166607 565 | 20 566 | -9.2080968647015 567 | 42 568 | 0.0 569 | 0 570 | VERTEX 571 | 8 572 | Default 573 | 10 574 | 7.4849195257678 575 | 20 576 | -9.7503938352285 577 | 42 578 | 0.0 579 | 0 580 | VERTEX 581 | 8 582 | Default 583 | 10 584 | 6.9513408307607 585 | 20 586 | -10.2284670210912 587 | 42 588 | 0.0053554437195 589 | 0 590 | VERTEX 591 | 8 592 | Default 593 | 10 594 | 6.83524860852 595 | 20 596 | -10.3338453255416 597 | 42 598 | 0.0065605348073 599 | 0 600 | VERTEX 601 | 8 602 | Default 603 | 10 604 | 6.7230817609763 605 | 20 606 | -10.436252427881 607 | 42 608 | 0.0063490971596 609 | 0 610 | VERTEX 611 | 8 612 | Default 613 | 10 614 | 5.8668741679578 615 | 20 616 | -11.2437390991392 617 | 42 618 | 0.0090752056922 619 | 0 620 | VERTEX 621 | 8 622 | Default 623 | 10 624 | 5.7880239858207 625 | 20 626 | -11.3210184829878 627 | 42 628 | 0.0202705631592 629 | 0 630 | VERTEX 631 | 8 632 | Default 633 | 10 634 | 4.6124953719187 635 | 20 636 | -12.5634734451353 637 | 42 638 | 0.0 639 | 0 640 | VERTEX 641 | 8 642 | Default 643 | 10 644 | 4.4730386010196 645 | 20 646 | -12.7256328577725 647 | 42 648 | 0.0239516025174 649 | 0 650 | VERTEX 651 | 8 652 | Default 653 | 10 654 | 3.55882 655 | 20 656 | -13.910828 657 | 42 658 | -0.0059282369657 659 | 0 660 | VERTEX 661 | 8 662 | Default 663 | 10 664 | 3.1520775471144 665 | 20 666 | -14.4767277063361 667 | 42 668 | -0.0089653766081 669 | 0 670 | VERTEX 671 | 8 672 | Default 673 | 10 674 | 2.4052532942782 675 | 20 676 | -15.4407271244062 677 | 42 678 | 0.0 679 | 0 680 | VERTEX 681 | 8 682 | Default 683 | 10 684 | 2.1181236637256 685 | 20 686 | -15.7966657256436 687 | 42 688 | 0.0 689 | 0 690 | VERTEX 691 | 8 692 | Default 693 | 10 694 | 1.6121538952935 695 | 20 696 | -16.4166918922048 697 | 42 698 | 0.0048639241932 699 | 0 700 | VERTEX 701 | 8 702 | Default 703 | 10 704 | 0.8581395006064 705 | 20 706 | -17.350749305674 707 | 42 708 | 0.0122252863178 709 | 0 710 | VERTEX 711 | 8 712 | Default 713 | 10 714 | 0.7652709259218 715 | 20 716 | -17.4686708506231 717 | 42 718 | 0.0116833111986 719 | 0 720 | VERTEX 721 | 8 722 | Default 723 | 10 724 | 0.6843999169524 725 | 20 726 | -17.5721506223202 727 | 42 728 | 0.0074944991867 729 | 0 730 | VERTEX 731 | 8 732 | Default 733 | 10 734 | 0.131361 735 | 20 736 | -18.306165 737 | 42 738 | 0.019492680105 739 | 0 740 | VERTEX 741 | 8 742 | Default 743 | 10 744 | -0.120684591669 745 | 20 746 | -17.8728338774093 747 | 42 748 | 0.0 749 | 0 750 | VERTEX 751 | 8 752 | Default 753 | 10 754 | -0.2404775101826 755 | 20 756 | -17.6892417646061 757 | 42 758 | 0.01163568293 759 | 0 760 | VERTEX 761 | 8 762 | Default 763 | 10 764 | -0.4763497347843 765 | 20 766 | -17.3527603941565 767 | 42 768 | 0.0104538828974 769 | 0 770 | VERTEX 771 | 8 772 | Default 773 | 10 774 | -0.692185863281 775 | 20 776 | -17.0652148446201 777 | 42 778 | 0.0 779 | 0 780 | VERTEX 781 | 8 782 | Default 783 | 10 784 | -0.8866229698599 785 | 20 786 | -16.8180456165713 787 | 42 788 | 0.0101289183237 789 | 0 790 | VERTEX 791 | 8 792 | Default 793 | 10 794 | -1.2368403415847 795 | 20 796 | -16.3933411775223 797 | 42 798 | 0.0 799 | 0 800 | VERTEX 801 | 8 802 | Default 803 | 10 804 | -1.5058737121028 805 | 20 806 | -16.0801878297154 807 | 42 808 | 0.0 809 | 0 810 | VERTEX 811 | 8 812 | Default 813 | 10 814 | -1.7103638172088 815 | 20 816 | -15.8477352729268 817 | 42 818 | 0.0 819 | 0 820 | VERTEX 821 | 8 822 | Default 823 | 10 824 | -2.0203585782993 825 | 20 826 | -15.5019782416007 827 | 42 828 | 0.0 829 | 0 830 | VERTEX 831 | 8 832 | Default 833 | 10 834 | -2.1763800526256 835 | 20 836 | -15.3300271624743 837 | 42 838 | 0.0 839 | 0 840 | VERTEX 841 | 8 842 | Default 843 | 10 844 | -2.332761 845 | 20 846 | -15.158414 847 | 42 848 | 0.0 849 | 0 850 | VERTEX 851 | 8 852 | Default 853 | 10 854 | -2.7876113589059 855 | 20 856 | -14.6272431232177 857 | 42 858 | 0.0104982687933 859 | 0 860 | VERTEX 861 | 8 862 | Default 863 | 10 864 | -4.5430516864165 865 | 20 866 | -12.6792638800449 867 | 42 868 | 0.0263239000897 869 | 0 870 | VERTEX 871 | 8 872 | Default 873 | 10 874 | -4.5851242445239 875 | 20 876 | -12.6343642640982 877 | 42 878 | 0.004778930722 879 | 0 880 | VERTEX 881 | 8 882 | Default 883 | 10 884 | -5.2570126687953 885 | 20 886 | -11.9269944196232 887 | 42 888 | 0.0 889 | 0 890 | VERTEX 891 | 8 892 | Default 893 | 10 894 | -5.5536339829392 895 | 20 896 | -11.6200306362472 897 | 42 898 | 0.0 899 | 0 900 | VERTEX 901 | 8 902 | Default 903 | 10 904 | -6.1135606290188 905 | 20 906 | -11.0482186548965 907 | 42 908 | 0.002983439992 909 | 0 910 | VERTEX 911 | 8 912 | Default 913 | 10 914 | -7.1029646724086 915 | 20 916 | -10.0570924536981 917 | 42 918 | 0.0113917898593 919 | 0 920 | VERTEX 921 | 8 922 | Default 923 | 10 924 | -7.1962149032938 925 | 20 926 | -9.9646390721586 927 | 42 928 | 0.0020225491199 929 | 0 930 | VERTEX 931 | 8 932 | Default 933 | 10 934 | -7.5580693929339 935 | 20 936 | -9.6069879203332 937 | 42 938 | 0.0 939 | 0 940 | VERTEX 941 | 8 942 | Default 943 | 10 944 | -8.8280954553895 945 | 20 946 | -8.3589200930842 947 | 42 948 | 0.0 949 | 0 950 | VERTEX 951 | 8 952 | Default 953 | 10 954 | -9.4626550513151 955 | 20 956 | -7.7344897079308 957 | 42 958 | 0.0 959 | 0 960 | VERTEX 961 | 8 962 | Default 963 | 10 964 | -10.095199 965 | 20 966 | -7.107966 967 | 42 968 | 0.0 969 | 0 970 | VERTEX 971 | 8 972 | Default 973 | 10 974 | -10.6995617110704 975 | 20 976 | -6.540362351094 977 | 42 978 | 0.0 979 | 0 980 | VERTEX 981 | 8 982 | Default 983 | 10 984 | -11.841006862959 985 | 20 986 | -5.4833789408426 987 | 42 988 | -0.0018875838249 989 | 0 990 | VERTEX 991 | 8 992 | Default 993 | 10 994 | -12.3398058893695 995 | 20 996 | -5.0187989352652 997 | 42 998 | 0.0 999 | 0 1000 | VERTEX 1001 | 8 1002 | Default 1003 | 10 1004 | -12.5727709248447 1005 | 20 1006 | -4.7997505800703 1007 | 42 1008 | 0.0 1009 | 0 1010 | VERTEX 1011 | 8 1012 | Default 1013 | 10 1014 | -12.7976203460844 1015 | 20 1016 | -4.5866043152697 1017 | 42 1018 | 0.0 1019 | 0 1020 | VERTEX 1021 | 8 1022 | Default 1023 | 10 1024 | -13.230370973939 1025 | 20 1026 | -4.1702843758528 1027 | 42 1028 | -0.0056205807101 1029 | 0 1030 | VERTEX 1031 | 8 1032 | Default 1033 | 10 1034 | -13.3311566632366 1035 | 20 1036 | -4.0719502518201 1037 | 42 1038 | -0.0074451310415 1039 | 0 1040 | VERTEX 1041 | 8 1042 | Default 1043 | 10 1044 | -13.4301109603814 1045 | 20 1046 | -3.9748249710086 1047 | 42 1048 | -0.0056705599971 1049 | 0 1050 | VERTEX 1051 | 8 1052 | Default 1053 | 10 1054 | -14.1973059987263 1055 | 20 1056 | -3.1981910158261 1057 | 42 1058 | 0.0 1059 | 0 1060 | VERTEX 1061 | 8 1062 | Default 1063 | 10 1064 | -14.5251615871659 1065 | 20 1066 | -2.850363677109 1067 | 42 1068 | -0.0011858300601 1069 | 0 1070 | VERTEX 1071 | 8 1072 | Default 1073 | 10 1074 | -14.827230790545 1075 | 20 1076 | -2.519110430857 1077 | 42 1078 | -0.0053925910781 1079 | 0 1080 | VERTEX 1081 | 8 1082 | Default 1083 | 10 1084 | -15.1051179774206 1085 | 20 1086 | -2.2036476020965 1087 | 42 1088 | -0.0084988278592 1089 | 0 1090 | VERTEX 1091 | 8 1092 | Default 1093 | 10 1094 | -15.610089023289 1095 | 20 1096 | -1.5982529515681 1097 | 42 1098 | 0.0 1099 | 0 1100 | VERTEX 1101 | 8 1102 | Default 1103 | 10 1104 | -15.8236334694664 1105 | 20 1106 | -1.3271610464296 1107 | 42 1108 | 0.0 1109 | 0 1110 | VERTEX 1111 | 8 1112 | Default 1113 | 10 1114 | -16.0192108487171 1115 | 20 1116 | -1.0694456362194 1117 | 42 1118 | -0.012573360078 1119 | 0 1120 | VERTEX 1121 | 8 1122 | Default 1123 | 10 1124 | -16.0643980042694 1125 | 20 1126 | -1.0084899217171 1127 | 42 1128 | -0.0177130046158 1129 | 0 1130 | VERTEX 1131 | 8 1132 | Default 1133 | 10 1134 | -16.73768242496 1135 | 20 1136 | -0.0220703016725 1137 | 42 1138 | -0.0343631934119 1139 | 0 1140 | VERTEX 1141 | 8 1142 | Default 1143 | 10 1144 | -17.5856850463752 1145 | 20 1146 | 1.5556427851848 1147 | 42 1148 | -0.0399614625167 1149 | 0 1150 | VERTEX 1151 | 8 1152 | Default 1153 | 10 1154 | -18.189707 1155 | 20 1156 | 3.241899 1157 | 42 1158 | -0.0510991697604 1159 | 0 1160 | VERTEX 1161 | 8 1162 | Default 1163 | 10 1164 | -18.5467543221655 1165 | 20 1166 | 5.3285238031526 1167 | 42 1168 | -0.0426618829683 1169 | 0 1170 | VERTEX 1171 | 8 1172 | Default 1173 | 10 1174 | -18.5195412736521 1175 | 20 1176 | 7.1798619203568 1177 | 42 1178 | -0.0679836321212 1179 | 0 1180 | VERTEX 1181 | 8 1182 | Default 1183 | 10 1184 | -17.7658364159846 1185 | 20 1186 | 10.3243419842417 1187 | 42 1188 | -0.0505084989945 1189 | 0 1190 | VERTEX 1191 | 8 1192 | Default 1193 | 10 1194 | -16.6622992594187 1195 | 20 1196 | 12.490663132693 1197 | 42 1198 | -0.0801050391296 1199 | 0 1200 | VERTEX 1201 | 8 1202 | Default 1203 | 10 1204 | -14.2354169595426 1205 | 20 1206 | 15.2050324068345 1207 | 42 1208 | -0.0442587890547 1209 | 0 1210 | VERTEX 1211 | 8 1212 | Default 1213 | 10 1214 | -12.718520381561 1215 | 20 1216 | 16.2247779602152 1217 | 42 1218 | -0.0462790807821 1219 | 0 1220 | SEQEND 1221 | 0 1222 | ENDSEC 1223 | 0 1224 | EOF 1225 | -------------------------------------------------------------------------------- /DxfEditor/DxfEditor.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {38B12E17-6974-4514-A892-0F820066B901} 8 | WinExe 9 | Properties 10 | DxfEditor 11 | DxfEditor 12 | v4.8 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 4.0 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | MSBuild:Compile 57 | Designer 58 | 59 | 60 | MSBuild:Compile 61 | Designer 62 | 63 | 64 | App.xaml 65 | Code 66 | 67 | 68 | MainWindow.xaml 69 | Code 70 | 71 | 72 | 73 | 74 | Code 75 | 76 | 77 | True 78 | True 79 | Resources.resx 80 | 81 | 82 | True 83 | Settings.settings 84 | True 85 | 86 | 87 | ResXFileCodeGenerator 88 | Resources.Designer.cs 89 | 90 | 91 | PreserveNewest 92 | 93 | 94 | PreserveNewest 95 | 96 | 97 | PreserveNewest 98 | 99 | 100 | PreserveNewest 101 | 102 | 103 | PreserveNewest 104 | 105 | 106 | PreserveNewest 107 | 108 | 109 | PreserveNewest 110 | 111 | 112 | PreserveNewest 113 | 114 | 115 | PreserveNewest 116 | 117 | 118 | PreserveNewest 119 | 120 | 121 | PreserveNewest 122 | 123 | 124 | PreserveNewest 125 | 126 | 127 | PreserveNewest 128 | 129 | 130 | SettingsSingleFileGenerator 131 | Settings.Designer.cs 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | {476fa4c4-fa1d-4a2a-985b-8cbf50f82251} 146 | DXFLib 147 | 148 | 149 | {962f5736-02ed-452a-9950-1a9a419ed4b3} 150 | ZoomableCanvas 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 167 | -------------------------------------------------------------------------------- /DxfEditor/Images/folder_document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Images/folder_document.png -------------------------------------------------------------------------------- /DxfEditor/Images/hand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Images/hand.png -------------------------------------------------------------------------------- /DxfEditor/Images/window_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Images/window_view.png -------------------------------------------------------------------------------- /DxfEditor/Images/zoom_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Images/zoom_in.png -------------------------------------------------------------------------------- /DxfEditor/Images/zoom_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shao200/WpfDxfViewer/92a8f44ef5fd70b21342fd142bc10f0aa7577f4d/DxfEditor/Images/zoom_out.png -------------------------------------------------------------------------------- /DxfEditor/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 39 | 40 | 41 | 42 | 43 | 44 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /DxfEditor/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Collections.Specialized; 5 | using System.Configuration; 6 | using System.Data; 7 | using System.Drawing; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows; 12 | using System.Windows.Controls; 13 | using System.Windows.Data; 14 | using System.Windows.Documents; 15 | using System.Windows.Input; 16 | using System.Windows.Media; 17 | using System.Windows.Media.Animation; 18 | using System.Windows.Media.Imaging; 19 | using System.Windows.Navigation; 20 | using System.Windows.Shapes; 21 | using System.Windows.Threading; 22 | 23 | namespace DxfEditor 24 | { 25 | /// 26 | /// Interaction logic for MainWindow.xaml 27 | /// 28 | public partial class MainWindow : Window 29 | { 30 | private float scaleX = 0.05f; 31 | private float scaleY = 0.05f; 32 | 33 | // DXF Document 34 | DXFLib.DXFDocument doc; 35 | 36 | // Last mouse position 37 | private System.Windows.Point LastMousePosition; 38 | 39 | public MainWindow() 40 | { 41 | InitializeComponent(); 42 | } 43 | 44 | #region Event handlers 45 | 46 | private void OnClickOpen(object sender, RoutedEventArgs e) 47 | { 48 | // Configure open file dialog box 49 | Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); 50 | dlg.FileName = "layout"; 51 | dlg.DefaultExt = ".dxf"; 52 | dlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); 53 | dlg.Filter = "Autocad DXF Files (.dxf)|*.dxf"; 54 | 55 | // Show open file dialog box 56 | Nullable result = dlg.ShowDialog(); 57 | 58 | if (result.HasValue && result.Value) 59 | { 60 | // Load DXF 61 | IList background = LoadDxf(dlg.FileName); 62 | 63 | // Add it to canvas 64 | canvas.Children.Clear(); 65 | foreach (Shape shape in background) 66 | canvas.Children.Add(shape); 67 | 68 | Autofill(); 69 | } 70 | } 71 | 72 | private void OnClickAutofill(object sender, RoutedEventArgs e) 73 | { 74 | Autofill(); 75 | } 76 | 77 | private void OnClickZoomIn(object sender, RoutedEventArgs e) 78 | { 79 | ZoomIn(); 80 | } 81 | 82 | private void OnClickZoomOut(object sender, RoutedEventArgs e) 83 | { 84 | ZoomOut(); 85 | } 86 | 87 | protected override void OnMouseWheel(MouseWheelEventArgs e) 88 | { 89 | var x = Math.Pow(2, e.Delta / 3.0 / Mouse.MouseWheelDeltaForOneLine); 90 | canvas.Scale *= x; 91 | 92 | // Adjust the offset to make the point under the mouse stay still. 93 | var position = (Vector)LastMousePosition; 94 | canvas.Offset = (System.Windows.Point)((Vector)(canvas.Offset + position) * x - position); 95 | } 96 | 97 | protected override void OnMouseMove(MouseEventArgs e) 98 | { 99 | var position = e.GetPosition(this); 100 | 101 | // Print position 102 | lblPosition.Content = position.ToString(); 103 | 104 | // Handle Pan 105 | if (e.MiddleButton == MouseButtonState.Pressed || (e.LeftButton == MouseButtonState.Pressed && btnPan.IsChecked.HasValue && btnPan.IsChecked.Value)) 106 | { 107 | this.Cursor = Cursors.Hand; 108 | canvas.Offset -= position - LastMousePosition; 109 | 110 | } 111 | else this.Cursor = Cursors.Arrow; 112 | 113 | LastMousePosition = position; 114 | } 115 | 116 | #endregion 117 | 118 | #region Private methods 119 | 120 | private IList LoadDxf(string filename) 121 | { 122 | // Process open file dialog box results 123 | if (!string.IsNullOrEmpty(filename)) 124 | { 125 | // Parse DXF 126 | DateTime start = DateTime.UtcNow; 127 | 128 | doc = new DXFLib.DXFDocument(); 129 | 130 | doc.Load(filename); 131 | 132 | System.Diagnostics.Debug.WriteLine("Loaded {0} in {1}ms", System.IO.Path.GetFileName(filename), DateTime.UtcNow.Subtract(start).TotalMilliseconds); 133 | 134 | // Process entities 135 | if (doc.Entities.Count > 0) 136 | { 137 | // Create shapes 138 | start = DateTime.UtcNow; 139 | 140 | IList shapes = new List(); 141 | foreach (DXFLib.DXFEntity entity in doc.Entities) 142 | ConvertDxfEntityToShapes(doc, entity, shapes, System.Windows.Media.Brushes.SteelBlue); 143 | 144 | System.Diagnostics.Debug.WriteLine("Created shapes in {0}ms", DateTime.UtcNow.Subtract(start).TotalMilliseconds); 145 | 146 | return shapes; 147 | } 148 | } 149 | 150 | return null; 151 | } 152 | 153 | private void ConvertDxfEntityToShapes(DXFLib.DXFDocument doc, DXFLib.DXFEntity entity, IList shapes, System.Windows.Media.Brush stroke) 154 | { 155 | if (entity is DXFLib.DXFLine) 156 | { 157 | DXFLib.DXFLine line = (DXFLib.DXFLine)entity; 158 | PointF start = new PointF((float)line.Start.X, (float)-line.Start.Y); 159 | PointF end = new PointF((float)line.End.X, (float)-line.End.Y); 160 | 161 | Line drawLine = new Line(); 162 | drawLine.Stroke = stroke; 163 | drawLine.X1 = end.X * scaleX; 164 | drawLine.X2 = start.X * scaleX; 165 | drawLine.Y1 = end.Y * scaleY; 166 | drawLine.Y2 = start.Y * scaleY; 167 | drawLine.StrokeThickness = 1; 168 | drawLine.IsHitTestVisible = false; 169 | 170 | shapes.Add(drawLine); 171 | } 172 | else if (entity is DXFLib.DXFCircle) 173 | { 174 | 175 | DXFLib.DXFCircle circle = (DXFLib.DXFCircle)entity; 176 | Ellipse drawCircle = new Ellipse(); 177 | drawCircle.StrokeThickness = 1; 178 | drawCircle.Stroke = stroke; 179 | drawCircle.Width = circle.Radius * 2 * scaleX; 180 | drawCircle.Height = circle.Radius * 2 * scaleY; 181 | drawCircle.IsHitTestVisible = false; 182 | Canvas.SetLeft(drawCircle, (circle.Center.X.Value - circle.Radius) * scaleX); 183 | Canvas.SetTop(drawCircle, (-circle.Center.Y.Value - circle.Radius) * scaleY); 184 | 185 | shapes.Add(drawCircle); 186 | 187 | } 188 | else if (entity is DXFLib.DXFArc) 189 | { 190 | DXFLib.DXFArc arc = (DXFLib.DXFArc)entity; 191 | 192 | Path path = new Path(); 193 | path.Stroke = stroke; 194 | path.StrokeThickness = 1; 195 | 196 | System.Windows.Point endPoint = new System.Windows.Point( 197 | (arc.Center.X.Value + Math.Cos(arc.EndAngle * Math.PI / 180) * arc.Radius) * scaleX, 198 | (-arc.Center.Y.Value - Math.Sin(arc.EndAngle * Math.PI / 180) * arc.Radius) * scaleY); 199 | 200 | System.Windows.Point startPoint = new System.Windows.Point( 201 | (arc.Center.X.Value + Math.Cos(arc.StartAngle * Math.PI / 180) * arc.Radius) * scaleX, 202 | (-arc.Center.Y.Value - Math.Sin(arc.StartAngle * Math.PI / 180) * arc.Radius) * scaleY); 203 | 204 | ArcSegment arcSegment = new ArcSegment(); 205 | double sweep = 0.0; 206 | if (arc.EndAngle < arc.StartAngle) 207 | sweep = (360 + arc.EndAngle) - arc.StartAngle; 208 | else sweep = Math.Abs(arc.EndAngle - arc.StartAngle); 209 | 210 | arcSegment.IsLargeArc = sweep >= 180; 211 | arcSegment.Point = endPoint; 212 | arcSegment.Size = new System.Windows.Size(arc.Radius * scaleX, arc.Radius * scaleY); 213 | arcSegment.SweepDirection = arc.ExtrusionDirection.Z >= 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise; 214 | 215 | PathGeometry geometry = new PathGeometry(); 216 | PathFigure pathFigure = new PathFigure(); 217 | pathFigure.StartPoint = startPoint; 218 | pathFigure.Segments.Add(arcSegment); 219 | geometry.Figures.Add(pathFigure); 220 | 221 | path.Data = geometry; 222 | path.IsHitTestVisible = false; 223 | shapes.Add(path); 224 | } 225 | else if (entity is DXFLib.DXFPolyLine) 226 | { 227 | DXFLib.DXFPolyLine polyLine = (DXFLib.DXFPolyLine)entity; 228 | bool isClosed = polyLine.Flags == DXFLib.DXFPolyLine.FlagsEnum.closed; 229 | 230 | int count = isClosed ? polyLine.Children.Count : polyLine.Children.Count - 1; 231 | for (int i = 1; i <= count; i++) 232 | { 233 | DXFLib.DXFVertex vertex1 = (i == polyLine.Children.Count) ? (DXFLib.DXFVertex)polyLine.Children[0] : (DXFLib.DXFVertex)polyLine.Children[i]; 234 | DXFLib.DXFVertex vertex2 = (DXFLib.DXFVertex)polyLine.Children[i - 1]; 235 | 236 | PointF start = new PointF((float)vertex1.Location.X, (float)-vertex1.Location.Y); 237 | PointF end = new PointF((float)vertex2.Location.X, (float)-vertex2.Location.Y); 238 | 239 | // TODO: Handle Vertex.Buldge http://www.afralisp.net/archive/lisp/Bulges1.htm 240 | 241 | Line drawLine = new Line(); 242 | drawLine.Stroke = stroke; 243 | drawLine.X1 = end.X * scaleX; 244 | drawLine.X2 = start.X * scaleX; 245 | drawLine.Y1 = end.Y * scaleY; 246 | drawLine.Y2 = start.Y * scaleY; 247 | drawLine.StrokeThickness = 1; 248 | drawLine.IsHitTestVisible = false; 249 | shapes.Add(drawLine); 250 | } 251 | } 252 | else if (entity is DXFLib.DXFLWPolyLine) 253 | { 254 | DXFLib.DXFLWPolyLine polyLine = (DXFLib.DXFLWPolyLine)entity; 255 | bool isClosed = polyLine.Flags == DXFLib.DXFLWPolyLine.FlagsEnum.closed; 256 | 257 | int count = isClosed ? polyLine.Elements.Count : polyLine.Elements.Count - 1; 258 | for (int i = 1; i <= count; i++) 259 | { 260 | DXFLib.DXFPoint vertex1 = (i == polyLine.Elements.Count) ? polyLine.Elements[0].Vertex : polyLine.Elements[i].Vertex; 261 | DXFLib.DXFPoint vertex2 = polyLine.Elements[i - 1].Vertex; 262 | 263 | // TODO: Handle Element.Bulge http://www.afralisp.net/archive/lisp/Bulges1.htm 264 | 265 | PointF start = new PointF((float)vertex1.X, (float)-vertex1.Y); 266 | PointF end = new PointF((float)vertex2.X, (float)-vertex2.Y); 267 | 268 | Line drawLine = new Line(); 269 | drawLine.Stroke = stroke; 270 | drawLine.X1 = end.X * scaleX; 271 | drawLine.X2 = start.X * scaleX; 272 | drawLine.Y1 = end.Y * scaleY; 273 | drawLine.Y2 = start.Y * scaleY; 274 | drawLine.StrokeThickness = 1; 275 | drawLine.IsHitTestVisible = false; 276 | 277 | shapes.Add(drawLine); 278 | } 279 | } 280 | else if (entity is DXFLib.DXFMText) 281 | { 282 | } 283 | else if (entity is DXFLib.DXFHatch) 284 | { 285 | } 286 | else if (entity is DXFLib.DXF3DFace) 287 | { 288 | } 289 | else if (entity is DXFLib.DXFInsert) 290 | { 291 | return; 292 | 293 | // THIS FUNCTION STILL HAVE SOME PROBLEMS 294 | DXFLib.DXFInsert insert = (DXFLib.DXFInsert)entity; 295 | DXFLib.DXFBlock block = doc.Blocks.FirstOrDefault(x => x.BlockName == insert.BlockName); 296 | if (block != null && block.HasChildren && !block.IsInvisible) 297 | { 298 | IList blockEntities = new List(); 299 | foreach (DXFLib.DXFEntity blockEntity in block.Children) 300 | ConvertDxfEntityToShapes(doc, blockEntity, blockEntities, System.Windows.Media.Brushes.Red); 301 | 302 | double centerX = insert.InsertionPoint.X.Value * scaleX; 303 | double centerY = -insert.InsertionPoint.Y.Value * scaleY; 304 | 305 | foreach (Shape shape in blockEntities) 306 | { 307 | TranslateTransform translateTransform1 = new TranslateTransform(centerX, centerY); 308 | RotateTransform rotateTransform1 = new RotateTransform(insert.RotationAngle.HasValue ? insert.RotationAngle.Value : 0, centerX, centerY); 309 | ScaleTransform scaleTransform1 = null; 310 | 311 | if ((insert.Scaling.X.HasValue && insert.Scaling.X.Value < 100) || (insert.Scaling.Y.HasValue && insert.Scaling.Y.Value < 100)) 312 | scaleTransform1 = new ScaleTransform(insert.Scaling.X.HasValue ? insert.Scaling.X.Value : 1, insert.Scaling.Y.HasValue ? insert.Scaling.Y.Value : 1, centerX, centerY); 313 | //else if (System.Diagnostics.Debugger.IsAttached) 314 | // System.Diagnostics.Debugger.Break(); 315 | 316 | // Create a TransformGroup to contain the transforms 317 | TransformGroup myTransformGroup = new TransformGroup(); 318 | myTransformGroup.Children.Add(translateTransform1); 319 | myTransformGroup.Children.Add(rotateTransform1); 320 | 321 | if (scaleTransform1 != null) 322 | myTransformGroup.Children.Add(scaleTransform1); 323 | 324 | shape.RenderTransform = myTransformGroup; 325 | shapes.Add(shape); 326 | } 327 | } 328 | } 329 | else if (entity is DXFLib.DXFSolid) 330 | { 331 | } 332 | else if (entity is DXFLib.DXFText) 333 | { 334 | DXFLib.DXFText dxfText = (DXFLib.DXFText)entity; 335 | 336 | } 337 | else if (entity is DXFLib.DXFTrace) 338 | { 339 | } 340 | else if (entity is DXFLib.DXFSpline) 341 | { 342 | } 343 | else if (entity is DXFLib.DXFPointEntity) 344 | { 345 | } 346 | else if (entity is DXFLib.DXFXLine) 347 | { 348 | } 349 | else if (entity is DXFLib.DXFViewPort) 350 | { 351 | } 352 | else 353 | { 354 | // 355 | } 356 | } 357 | 358 | private void Autofill() 359 | { 360 | if (canvas.Children.Count == 0) return; 361 | 362 | double minLeft = canvas.Children.OfType().Min(i => Math.Min(i.X1, i.X2)); 363 | double maxLeft = canvas.Children.OfType().Max(i => Math.Max(i.X1, i.X2)); 364 | double minTop = canvas.Children.OfType().Min(i => Math.Min(i.Y1, i.Y2)); 365 | double maxTop = canvas.Children.OfType().Max(i => Math.Max(i.Y1, i.Y2)); 366 | 367 | // Calculate scale 368 | double scale = Math.Min(canvas.ActualWidth / (maxLeft - minLeft), canvas.ActualHeight / (maxTop - minTop)) * 0.95; 369 | if (scale > 0) 370 | { 371 | // Adjust scale 372 | canvas.Scale = scale; 373 | 374 | // Adjust offset 375 | canvas.Offset = new System.Windows.Point(minLeft * scale - (canvas.ActualWidth - (maxLeft - minLeft) * scale) / 2, 376 | minTop * scale - (canvas.ActualHeight - ((maxTop - minTop) * scale)) / 2); 377 | } 378 | } 379 | 380 | private void ZoomIn() 381 | { 382 | var x = Math.Pow(2, 120 / 3.0 / Mouse.MouseWheelDeltaForOneLine); 383 | canvas.Scale *= x; 384 | 385 | var position = new Vector(canvas.ActualWidth / 2, canvas.ActualHeight / 2); 386 | canvas.Offset = (System.Windows.Point)((Vector)(canvas.Offset + position) * x - position); 387 | } 388 | 389 | private void ZoomOut() 390 | { 391 | var x = Math.Pow(2, -120 / 3.0 / Mouse.MouseWheelDeltaForOneLine); 392 | canvas.Scale *= x; 393 | 394 | var position = new Vector(canvas.ActualWidth / 2, canvas.ActualHeight / 2); 395 | canvas.Offset = (System.Windows.Point)((Vector)(canvas.Offset + position) * x - position); 396 | } 397 | 398 | #endregion 399 | 400 | } 401 | } 402 | -------------------------------------------------------------------------------- /DxfEditor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("DxfEditor")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("Microsoft")] 14 | [assembly: AssemblyProduct("DxfEditor")] 15 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /DxfEditor/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DxfEditor.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DxfEditor.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /DxfEditor/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /DxfEditor/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DxfEditor.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DxfEditor/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /ZoomableCanvas/LinkedListExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace System.Collections.Generic 2 | { 3 | /// 4 | /// Provides extension methods for LinkedList. 5 | /// 6 | public static class LinkedListExtensions 7 | { 8 | /// 9 | /// Finds the next node after the given node that contains the specified value. 10 | /// 11 | /// The type of value in the linked list. 12 | /// The linked list. 13 | /// The node after which to search for the value in the linked list, or null to search from the beginning. 14 | /// The value to locate in the linked list. 15 | /// The first node after the given node that contains the specified value, if found; otherwise, null. 16 | public static LinkedListNode FindNext(this LinkedList list, LinkedListNode node, T value) 17 | { 18 | if (list == null) 19 | { 20 | throw new ArgumentNullException("list"); 21 | } 22 | 23 | if (node == null) 24 | { 25 | return list.Find(value); 26 | } 27 | 28 | if (list != node.List) 29 | { 30 | throw new ArgumentException("The list does not contain the given node."); 31 | } 32 | 33 | EqualityComparer comparer = EqualityComparer.Default; 34 | 35 | // Skip the given node. 36 | node = node.Next; 37 | while (node != null) 38 | { 39 | if (value != null) 40 | { 41 | if (comparer.Equals(node.Value, value)) 42 | { 43 | return node; 44 | } 45 | } 46 | else if (node.Value == null) 47 | { 48 | return node; 49 | } 50 | node = node.Next; 51 | } 52 | 53 | return null; 54 | } 55 | 56 | /// 57 | /// Finds the previous node before the given node that contains the specified value. 58 | /// 59 | /// The type of value in the linked list. 60 | /// The linked list. 61 | /// The node before which to search for the value in the linked list, or null to search from the end. 62 | /// The value to locate in the linked list. 63 | /// The first node before the given node that contains the specified value, if found; otherwise, null. 64 | public static LinkedListNode FindPrevious(this LinkedList list, LinkedListNode node, T value) 65 | { 66 | if (list == null) 67 | { 68 | throw new ArgumentNullException("list"); 69 | } 70 | 71 | if (node == null) 72 | { 73 | return list.FindLast(value); 74 | } 75 | 76 | if (list != node.List) 77 | { 78 | throw new ArgumentException("The list does not contain the given node."); 79 | } 80 | 81 | EqualityComparer comparer = EqualityComparer.Default; 82 | 83 | // Skip the given node. 84 | node = node.Previous; 85 | while (node != null) 86 | { 87 | if (value != null) 88 | { 89 | if (comparer.Equals(node.Value, value)) 90 | { 91 | return node; 92 | } 93 | } 94 | else if (node.Value == null) 95 | { 96 | return node; 97 | } 98 | node = node.Previous; 99 | } 100 | 101 | return null; 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /ZoomableCanvas/PriorityQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | namespace System.Collections.Generic 5 | { 6 | /// 7 | /// Represents a queue of items that are sorted based on individual priorities. 8 | /// 9 | /// Specifies the type of elements in the queue. 10 | /// Specifies the type of object representing the priority. 11 | [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] 12 | public class PriorityQueue 13 | { 14 | private readonly List> heap = new List>(); 15 | private readonly Dictionary indexes = new Dictionary(); 16 | 17 | private readonly IComparer comparer; 18 | private readonly bool invert; 19 | 20 | public PriorityQueue() 21 | : this(false) 22 | { 23 | } 24 | 25 | public PriorityQueue(bool invert) 26 | : this(Comparer.Default) 27 | { 28 | this.invert = invert; 29 | } 30 | 31 | public PriorityQueue(IComparer comparer) 32 | { 33 | this.comparer = comparer; 34 | heap.Add(default(KeyValuePair)); 35 | } 36 | 37 | public void Enqueue(T item, TPriority priority) 38 | { 39 | KeyValuePair tail = new KeyValuePair(item, priority); 40 | heap.Add(tail); 41 | 42 | MoveUp(tail, Count); 43 | } 44 | 45 | public KeyValuePair Dequeue() 46 | { 47 | int bound = Count; 48 | if (bound < 1) 49 | throw new InvalidOperationException("Queue is empty."); 50 | 51 | KeyValuePair head = heap[1]; 52 | KeyValuePair tail = heap[bound]; 53 | 54 | heap.RemoveAt(bound); 55 | 56 | if (bound > 1) 57 | MoveDown(tail, 1); 58 | 59 | indexes.Remove(head.Key); 60 | 61 | return head; 62 | } 63 | 64 | public KeyValuePair Peek() 65 | { 66 | if (Count < 1) 67 | throw new InvalidOperationException("Queue is empty."); 68 | 69 | return heap[1]; 70 | } 71 | 72 | public bool TryGetValue(T item, out TPriority priority) 73 | { 74 | int index; 75 | if (indexes.TryGetValue(item, out index)) 76 | { 77 | priority = heap[indexes[item]].Value; 78 | return true; 79 | } 80 | else 81 | { 82 | priority = default(TPriority); 83 | return false; 84 | } 85 | } 86 | 87 | public TPriority this[T item] 88 | { 89 | get 90 | { 91 | return heap[indexes[item]].Value; 92 | } 93 | set 94 | { 95 | int index; 96 | 97 | if (indexes.TryGetValue(item, out index)) 98 | { 99 | int order = comparer.Compare(value, heap[index].Value); 100 | if (order != 0) 101 | { 102 | if (invert) 103 | order = ~order; 104 | 105 | KeyValuePair element = new KeyValuePair(item, value); 106 | if (order < 0) 107 | MoveUp(element, index); 108 | else 109 | MoveDown(element, index); 110 | } 111 | } 112 | else 113 | { 114 | KeyValuePair element = new KeyValuePair(item, value); 115 | heap.Add(element); 116 | 117 | MoveUp(element, Count); 118 | } 119 | } 120 | } 121 | 122 | public int Count 123 | { 124 | get 125 | { 126 | return heap.Count - 1; 127 | } 128 | } 129 | 130 | private void MoveUp(KeyValuePair element, int index) 131 | { 132 | while (index > 1) 133 | { 134 | int parent = index >> 1; 135 | 136 | if (IsPrior(heap[parent], element)) 137 | break; 138 | 139 | heap[index] = heap[parent]; 140 | indexes[heap[parent].Key] = index; 141 | 142 | index = parent; 143 | } 144 | 145 | heap[index] = element; 146 | indexes[element.Key] = index; 147 | } 148 | 149 | private void MoveDown(KeyValuePair element, int index) 150 | { 151 | int count = heap.Count; 152 | 153 | while (index << 1 < count) 154 | { 155 | int child = index << 1; 156 | int sibling = child | 1; 157 | 158 | if (sibling < count && IsPrior(heap[sibling], heap[child])) 159 | child = sibling; 160 | 161 | if (IsPrior(element, heap[child])) 162 | break; 163 | 164 | heap[index] = heap[child]; 165 | indexes[heap[child].Key] = index; 166 | 167 | index = child; 168 | } 169 | 170 | heap[index] = element; 171 | indexes[element.Key] = index; 172 | } 173 | 174 | private bool IsPrior(KeyValuePair element1, KeyValuePair element2) 175 | { 176 | int order = comparer.Compare(element1.Value, element2.Value); 177 | if (invert) 178 | order = ~order; 179 | return order < 0; 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /ZoomableCanvas/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Windows.Markup; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("ZoomableCanvas")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("Microsoft")] 13 | [assembly: AssemblyProduct("ZoomableCanvas")] 14 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("a5d69370-f3b2-4941-8170-4a835c24dc1c")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("1.0.0.0")] 37 | [assembly: AssemblyFileVersion("1.0.0.0")] 38 | [assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls")] 39 | [assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows")] 40 | -------------------------------------------------------------------------------- /ZoomableCanvas/RectExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Windows 4 | { 5 | /// 6 | /// Provides extension methods for rects. 7 | /// 8 | public static class RectExtensions 9 | { 10 | /// 11 | /// Returns the center point of the . 12 | /// 13 | /// The rect to return the center point of. 14 | /// The center of the . 15 | public static Point GetCenter(this Rect rect) 16 | { 17 | return new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); 18 | } 19 | 20 | /// 21 | /// Returns whether the defines a real area in space. 22 | /// 23 | /// The rect to test. 24 | /// true if rect defines an area or point in finite space, which is not the case for or if any of the fields are . 25 | public static bool IsDefined(this Rect rect) 26 | { 27 | return rect.Width >= 0.0 28 | && rect.Height >= 0.0 29 | && rect.Top < Double.PositiveInfinity 30 | && rect.Left < Double.PositiveInfinity 31 | && (rect.Top > Double.NegativeInfinity || rect.Height == Double.PositiveInfinity) 32 | && (rect.Left > Double.NegativeInfinity || rect.Width == Double.PositiveInfinity); 33 | } 34 | 35 | /// 36 | /// Indicates whether the specified rectangle intersects with the current rectangle, properly considering the empty rect and infinities. 37 | /// 38 | /// The current rectangle. 39 | /// The rectangle to check. 40 | /// true if the specified rectangle intersects with the current rectangle; otherwise, false. 41 | public static bool Intersects(this Rect self, Rect rect) 42 | { 43 | return (self.IsEmpty || rect.IsEmpty) 44 | || (self.Width == Double.PositiveInfinity || self.Right >= rect.Left) 45 | && (rect.Width == Double.PositiveInfinity || rect.Right >= self.Left) 46 | && (self.Height == Double.PositiveInfinity || self.Bottom >= rect.Top) 47 | && (rect.Height == Double.PositiveInfinity || rect.Bottom >= self.Top); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /ZoomableCanvas/ZoomableCanvas.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {962F5736-02ED-452A-9950-1A9A419ED4B3} 8 | Library 9 | Properties 10 | ZoomableCanvas 11 | ZoomableCanvas 12 | v4.8 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 62 | --------------------------------------------------------------------------------