프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ 3cc356dc

이력 | 보기 | 이력해설 | 다운로드 (242 KB)

1
/////////////////////////////////////////////////////////////////////////////// 
2
// Copyright (C) 2002-2019, Open Design Alliance (the "Alliance"). 
3
// All rights reserved. 
4
// 
5
// This software and its documentation and related materials are owned by 
6
// the Alliance. The software may only be incorporated into application 
7
// programs owned by members of the Alliance, subject to a signed 
8
// Membership Agreement and Supplemental Software License Agreement with the
9
// Alliance. The structure and organization of this software are the valuable  
10
// trade secrets of the Alliance and its suppliers. The software is also 
11
// protected by copyright law and international treaty provisions. Application  
12
// programs incorporating this software must include the following statement 
13
// with their copyright notices:
14
//   
15
//   This application incorporates Open Design Alliance software pursuant to a license 
16
//   agreement with Open Design Alliance.
17
//   Open Design Alliance Copyright (C) 2002-2019 by Open Design Alliance. 
18
//   All rights reserved.
19
//
20
// By use of this software, its documentation or related materials, you 
21
// acknowledge and accept the above terms.
22
///////////////////////////////////////////////////////////////////////////////
23
using System;
24
using System.Collections.Generic;
25
using System.Text;
26
using System.IO;
27
using System.Xml;
28
using System.Linq;
29
using Teigha.DatabaseServices;
30
using Teigha.Geometry;
31
using Teigha.GraphicsInterface;
32
using Teigha.Colors;
33
using Teigha;
34
using Teigha.GraphicsSystem;
35
using Teigha.Runtime;
36
using Teigha.Export_Import;
37
using System.Collections.Specialized;
38
// note that GetObject doesn't work in Acad 2009, so we use "obsolete" Open instead
39
#pragma warning disable 618
40

    
41
namespace OdReadExMgd
42
{
43
    class DbDumper
44
    {
45
        private const string BLOCK_GRAPHIC = "GRAPHIC+";
46
        private const string BLOCK_PIPING = "PIPING+";
47

    
48
        public DbDumper() { }
49

    
50
        static string toDegreeString(double val)
51
        {
52
            return (val * 180.0 / Math.PI) + "d";
53
        }
54
        static string toHexString(int val)
55
        {
56
            return string.Format("0{0:X}", val);
57
        }
58
        static string toArcSymbolTypeString(int val)
59
        {
60
            switch (val)
61
            {
62
                case 0: return "Precedes text";
63
                case 1: return "Above text";
64
                case 2: return "None";
65
            }
66
            return "???";
67
        }
68
        /************************************************************************/
69
        /* Shorten a path with ellipses.                                        */
70
        /************************************************************************/
71
        static string shortenPath(string Inpath, int maxPath)
72
        {
73
            string path = Inpath;
74
            /**********************************************************************/
75
            /* If the path fits, just return it                                   */
76
            /**********************************************************************/
77
            if (path.Length <= maxPath)
78
            {
79
                return path;
80
            }
81
            /**********************************************************************/
82
            /* If there's no backslash, just truncate the path                    */
83
            /**********************************************************************/
84
            int lastBackslash = path.LastIndexOf('\\');
85
            if (lastBackslash < 0)
86
            {
87
                return path.Substring(0, maxPath - 3) + "...";
88
            }
89

    
90
            /**********************************************************************/
91
            /* Shorten the front of the path                                      */
92
            /**********************************************************************/
93
            int fromLeft = (lastBackslash - 3) - (path.Length - maxPath);
94
            // (12 - 3) - (19 - 10) = 9 - 9 = 0 
95
            if ((lastBackslash <= 3) || (fromLeft < 1))
96
            {
97
                path = "..." + path.Substring(lastBackslash);
98
            }
99
            else
100
            {
101
                path = path.Substring(0, fromLeft) + "..." + path.Substring(lastBackslash);
102
            }
103

    
104
            /**********************************************************************/
105
            /* Truncate the path                                                  */
106
            /**********************************************************************/
107
            if (path.Length > maxPath)
108
            {
109
                path = path.Substring(0, maxPath - 3) + "...";
110
            }
111

    
112
            return path;
113
        }
114
        static string shortenPath(string Inpath)
115
        {
116
            return shortenPath(Inpath, 40);
117
        }
118

    
119
        /************************************************************************/
120
        /* Output a string in the form                                          */
121
        /*   leftString:. . . . . . . . . . . .rightString                      */
122
        /************************************************************************/
123
        static void writeLine(int indent, object leftString, object rightString, int colWidth)
124
        {
125
            string spaces = "                                                            ";
126
            string leader = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ";
127

    
128
            const int tabSize = 2;
129

    
130
            /**********************************************************************/
131
            /* Indent leftString with spaces characters                           */
132
            /**********************************************************************/
133
            string newleftString = spaces.Substring(0, tabSize * indent) + leftString.ToString();
134

    
135
            /**********************************************************************/
136
            /* If rightString is not specified, just output the indented          */
137
            /* leftString. Otherwise, fill the space between leftString and       */
138
            /* rightString with leader characters.                                */
139
            /**********************************************************************/
140
            if (rightString == null || ((rightString is string) && ((string)rightString) == ""))
141
            {
142
                Console.WriteLine(newleftString);
143
            }
144
            else
145
            {
146
                int leaders = colWidth - newleftString.Length;
147
                if (leaders > 0)
148
                {
149
                    Console.WriteLine(newleftString + leader.Substring(newleftString.Length, leaders) + rightString.ToString());
150
                }
151
                else
152
                {
153
                    Console.WriteLine(newleftString + ' ' + rightString.ToString());
154
                }
155
            }
156
        }
157
        static void writeLine(int indent, object leftString, object rightString)
158
        {
159
            writeLine(indent, leftString, rightString, 38);
160
        }
161
        static void writeLine(int indent, object leftString)
162
        {
163
            writeLine(indent, leftString, null, 38);
164
        }
165
        static void writeLine()
166
        {
167
            Console.WriteLine();
168
        }
169

    
170
        static void dumpEntityData(Entity pEnt, int indent, XmlNode node)
171
        {
172
            if (node != null)
173
            {
174
                try
175
                {
176
                    Extents3d ext = pEnt.GeometricExtents;
177

    
178
                    XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
179
                    MinExtentsAttr.Value = ext.MinPoint.ToString();
180
                    node.Attributes.SetNamedItem(MinExtentsAttr);
181

    
182
                    XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
183
                    MaxExtentsAttr.Value = ext.MaxPoint.ToString();
184
                    node.Attributes.SetNamedItem(MaxExtentsAttr);
185
                }
186
                catch (System.Exception)
187
                {
188
                }
189

    
190
                XmlAttribute LayerAttr = Program.xml.CreateAttribute("Layer");
191
                LayerAttr.Value = pEnt.Layer;
192
                node.Attributes.SetNamedItem(LayerAttr);
193

    
194
                writeLine(indent, "Color Index", pEnt.ColorIndex);
195
                writeLine(indent, "Color", pEnt.Color);
196

    
197
                XmlAttribute LinetypeAttr = Program.xml.CreateAttribute("Linetype");
198
                LinetypeAttr.Value = pEnt.Linetype;
199
                node.Attributes.SetNamedItem(LinetypeAttr);
200

    
201
                writeLine(indent, "LTscale", pEnt.LinetypeScale);
202
                writeLine(indent, "Lineweight", pEnt.LineWeight);
203
                writeLine(indent, "Plot Style", pEnt.PlotStyleName);
204
                writeLine(indent, "Transparency Method", pEnt.Transparency);
205
                writeLine(indent, "Visibility", pEnt.Visible);
206
                writeLine(indent, "Planar", pEnt.IsPlanar);
207

    
208
                if (pEnt.IsPlanar)
209
                {
210
                    try
211
                    {
212
                        CoordinateSystem3d cs = (CoordinateSystem3d)pEnt.GetPlane().GetCoordinateSystem();
213
                        writeLine(indent + 1, "Origin", cs.Origin);
214
                        writeLine(indent + 1, "u-Axis", cs.Xaxis);
215
                        writeLine(indent + 1, "v-Axis", cs.Yaxis);
216
                    }
217
                    catch (System.Exception ex)
218
                    {
219
                        writeLine(indent + 1, "pEnt.GetPlane().GetCoordinateSystem() failed", ex.Message);
220
                    }
221
                }
222
            }
223
        }
224

    
225
        /************************************************************************/
226
        /* Dump Text data                                                       */
227
        /************************************************************************/
228
        static XmlNode dumpTextData(DBText pText, int indent, XmlNode node)
229
        {
230
            XmlNode TextNode = null;
231
            /// write text information to xml file
232
            if (node != null)
233
            {
234
                TextNode = Program.xml.CreateElement(pText.GetRXClass().Name);
235

    
236
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
237
                XAttr.Value = pText.Position.X.ToString();
238
                TextNode.Attributes.SetNamedItem(XAttr);
239

    
240
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
241
                YAttr.Value = pText.Position.Y.ToString();
242
                TextNode.Attributes.SetNamedItem(YAttr);
243

    
244
                TextNode.InnerText = pText.TextString.Replace("%%U", "");
245

    
246
                XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
247
                AngleAttr.Value = pText.Rotation.ToString();
248
                TextNode.Attributes.SetNamedItem(AngleAttr);
249

    
250
                XmlAttribute WidthAttr = Program.xml.CreateAttribute("Width");
251
                WidthAttr.Value = String.Format("{0}", pText.WidthFactor * pText.Height * pText.TextString.Length);
252
                TextNode.Attributes.SetNamedItem(WidthAttr);
253

    
254
                XmlAttribute HeightAttr = Program.xml.CreateAttribute("Height");
255
                HeightAttr.Value = pText.Height.ToString();
256
                TextNode.Attributes.SetNamedItem(HeightAttr);
257

    
258
                XmlAttribute WidthFactorAttr = Program.xml.CreateAttribute("WidthFactor");
259
                WidthFactorAttr.Value = pText.WidthFactor.ToString();
260
                TextNode.Attributes.SetNamedItem(WidthFactorAttr);
261

    
262
                XmlAttribute IsDefaultAlignmentAttr = Program.xml.CreateAttribute("IsDefaultAlignment");
263
                IsDefaultAlignmentAttr.Value = pText.IsDefaultAlignment.ToString();
264
                TextNode.Attributes.SetNamedItem(IsDefaultAlignmentAttr);
265

    
266
                XmlAttribute AlignmentPointAttr = Program.xml.CreateAttribute("AlignmentPoint");
267
                AlignmentPointAttr.Value = pText.AlignmentPoint.ToString();
268
                TextNode.Attributes.SetNamedItem(AlignmentPointAttr);
269

    
270
                XmlAttribute HorizontalModeAttr = Program.xml.CreateAttribute("HorizontalMode");
271
                HorizontalModeAttr.Value = pText.HorizontalMode.ToString();
272
                TextNode.Attributes.SetNamedItem(HorizontalModeAttr);
273

    
274
                XmlAttribute VerticalModeAttr = Program.xml.CreateAttribute("VerticalMode");
275
                VerticalModeAttr.Value = pText.VerticalMode.ToString();
276
                TextNode.Attributes.SetNamedItem(VerticalModeAttr);
277

    
278
                XmlAttribute IsMirroredInXAttr = Program.xml.CreateAttribute("IsMirroredInX");
279
                IsMirroredInXAttr.Value = pText.IsMirroredInX.ToString();
280
                TextNode.Attributes.SetNamedItem(IsMirroredInXAttr);
281

    
282
                XmlAttribute IsMirroredInYAttr = Program.xml.CreateAttribute("IsMirroredInY");
283
                IsMirroredInYAttr.Value = pText.IsMirroredInY.ToString();
284
                TextNode.Attributes.SetNamedItem(IsMirroredInYAttr);
285

    
286
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
287
                ObliqueAttr.Value = pText.Oblique.ToString();
288
                TextNode.Attributes.SetNamedItem(ObliqueAttr);
289

    
290
                XmlAttribute TextStyleAttr = Program.xml.CreateAttribute("TextStyle");
291
                TextStyleAttr.Value = pText.TextStyleName;
292
                TextNode.Attributes.SetNamedItem(TextStyleAttr);
293

    
294
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
295
                NormalAttr.Value = pText.Normal.ToString();
296
                TextNode.Attributes.SetNamedItem(NormalAttr);
297

    
298
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
299
                ThicknessAttr.Value = pText.Thickness.ToString();
300
                TextNode.Attributes.SetNamedItem(ThicknessAttr);
301

    
302
                dumpEntityData(pText, indent, TextNode);
303

    
304
                node.AppendChild(TextNode);
305
            }
306

    
307
            return TextNode;
308
        }
309

    
310
        /************************************************************************/
311
        /* Dump Attribute data                                                  */
312
        /************************************************************************/
313
        static void dumpAttributeData(int indent, AttributeReference pAttr, int i, XmlNode node)
314
        {
315
            writeLine(indent, "Field Length", pAttr.FieldLength);
316
            writeLine(indent, "Invisible", pAttr.Invisible);
317
            writeLine(indent, "Preset", pAttr.IsPreset);
318
            writeLine(indent, "Verifiable", pAttr.IsVerifiable);
319
            writeLine(indent, "Locked in Position", pAttr.LockPositionInBlock);
320
            writeLine(indent, "Constant", pAttr.IsConstant);
321

    
322
            XmlNode TextNode = dumpTextData(pAttr, indent, node);
323
            if (TextNode != null)
324
            {
325
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
326
                HandleAttr.Value = pAttr.Handle.ToString();
327
                TextNode.Attributes.SetNamedItem(HandleAttr);
328

    
329
                XmlAttribute TagAttr = Program.xml.CreateAttribute("Tag");
330
                TagAttr.Value = pAttr.Tag;
331
                TextNode.Attributes.SetNamedItem(TagAttr);
332
            }
333
        }
334

    
335
        /************************************************************************/
336
        /* Dump AttributeDefinition Data                                         */
337
        /************************************************************************/
338
        void dump(AttributeDefinition pAttDef, int indent, XmlNode node)
339
        {
340
            if (node == null) return;
341

    
342
            XmlNode AttributeDefinitionNode = Program.xml.CreateElement(pAttDef.GetRXClass().Name);
343

    
344
            XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
345
            HandleAttr.Value = pAttDef.Handle.ToString();
346
            AttributeDefinitionNode.Attributes.SetNamedItem(HandleAttr);
347

    
348
            XmlAttribute XAttr = Program.xml.CreateAttribute("X");
349
            XAttr.Value = pAttDef.Position.X.ToString();
350
            AttributeDefinitionNode.Attributes.SetNamedItem(XAttr);
351

    
352
            XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
353
            YAttr.Value = pAttDef.Position.Y.ToString();
354
            AttributeDefinitionNode.Attributes.SetNamedItem(YAttr);
355

    
356
            XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
357
            ZAttr.Value = pAttDef.Position.Z.ToString();
358
            AttributeDefinitionNode.Attributes.SetNamedItem(ZAttr);
359

    
360
            XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
361
            AngleAttr.Value = pAttDef.Rotation.ToString();
362
            AttributeDefinitionNode.Attributes.SetNamedItem(AngleAttr);
363

    
364
            XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
365
            NormalAttr.Value = pAttDef.Normal.ToString();
366
            AttributeDefinitionNode.Attributes.SetNamedItem(NormalAttr);
367

    
368
            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
369
            NameAttr.Value = pAttDef.Tag;
370
            AttributeDefinitionNode.Attributes.SetNamedItem(NameAttr);
371

    
372
            using (var text = new DBText())
373
            {
374
                text.SetPropertiesFrom(pAttDef);
375
                text.TextStyleId = pAttDef.TextStyleId;
376
                text.Position = pAttDef.Position;
377
                text.Rotation = pAttDef.Rotation;
378
                text.WidthFactor = pAttDef.WidthFactor;
379
                text.Height = pAttDef.Height;
380
                text.Thickness = pAttDef.Thickness;
381
                text.Justify = pAttDef.Justify;
382
                text.TextString = !string.IsNullOrWhiteSpace(pAttDef.TextString.Replace("*", "")) ? pAttDef.TextString : pAttDef.Tag;
383
                if (pAttDef.Justify != AttachmentPoint.BaseLeft)
384
                    text.AlignmentPoint = pAttDef.AlignmentPoint;
385
                dumpTextData(text, indent, AttributeDefinitionNode);
386
            }
387
        }
388
        /************************************************************************/
389
        /* Dump Block Reference Data                                             */
390
        /************************************************************************/
391
        static XmlNode dumpBlockRefData(BlockReference pBlkRef, int indent, XmlNode node)
392
        {
393
            if (node != null)
394
            {
395
                XmlNode BlockReferenceNode = Program.xml.CreateElement(pBlkRef.GetRXClass().Name);
396

    
397
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
398
                HandleAttr.Value = pBlkRef.Handle.ToString();
399
                BlockReferenceNode.Attributes.SetNamedItem(HandleAttr);
400

    
401
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
402
                XAttr.Value = pBlkRef.Position.X.ToString();
403
                BlockReferenceNode.Attributes.SetNamedItem(XAttr);
404

    
405
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
406
                YAttr.Value = pBlkRef.Position.Y.ToString();
407
                BlockReferenceNode.Attributes.SetNamedItem(YAttr);
408

    
409
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
410
                ZAttr.Value = pBlkRef.Position.Z.ToString();
411
                BlockReferenceNode.Attributes.SetNamedItem(ZAttr);
412

    
413
                XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
414
                AngleAttr.Value = pBlkRef.Rotation.ToString();
415
                BlockReferenceNode.Attributes.SetNamedItem(AngleAttr);
416

    
417
                XmlAttribute ScaleFactorsAttr = Program.xml.CreateAttribute("ScaleFactors");
418
                ScaleFactorsAttr.Value = pBlkRef.ScaleFactors.ToString();
419
                BlockReferenceNode.Attributes.SetNamedItem(ScaleFactorsAttr);
420

    
421
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
422
                NormalAttr.Value = pBlkRef.Normal.ToString();
423
                BlockReferenceNode.Attributes.SetNamedItem(NormalAttr);
424

    
425
                XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
426
                NameAttr.Value = pBlkRef.Name;
427
                BlockReferenceNode.Attributes.SetNamedItem(NameAttr);
428

    
429
                // BlockReference DBPoint
430
                string nodePointValue = string.Empty;
431
                Dictionary<long, Point3d> nodePointDic = new Dictionary<long, Point3d>();
432
                using (BlockTableRecord pBtr = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
433
                {
434
                    foreach (ObjectId blkid in pBtr)
435
                    {
436
                        using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
437
                        {
438
                            if (pBlkEnt.GetRXClass().Name == "AcDbPoint")
439
                            {
440
                                DBPoint pt = (DBPoint)pBlkEnt;
441
                                Point3d nodePt = pt.Position.TransformBy(pBlkRef.BlockTransform);
442
                                nodePointDic.Add(Convert.ToInt64(pt.Handle.ToString(), 16), nodePt);
443
                            }
444
                        }
445
                    }
446
                }
447
                if (nodePointDic.Count > 0)
448
                {
449
                    foreach (KeyValuePair<long, Point3d> item in nodePointDic.OrderBy(o => o.Key))
450
                    {
451
                        nodePointValue += item.Value.ToString() + "/";
452
                    }
453
                    nodePointValue = nodePointValue.Substring(0, nodePointValue.Length - 1);
454
                }
455

    
456
                XmlAttribute NodePointAttr = Program.xml.CreateAttribute("Nodes");
457
                NodePointAttr.Value = nodePointValue;
458
                BlockReferenceNode.Attributes.SetNamedItem(NodePointAttr);
459

    
460
                Matrix3d blockTransform = pBlkRef.BlockTransform;
461
                CoordinateSystem3d cs = blockTransform.CoordinateSystem3d;
462
                writeLine(indent + 1, "Origin", cs.Origin);
463
                writeLine(indent + 1, "u-Axis", cs.Xaxis);
464
                writeLine(indent + 1, "v-Axis", cs.Yaxis);
465
                writeLine(indent + 1, "z-Axis", cs.Zaxis);
466

    
467
                dumpEntityData(pBlkRef, indent, BlockReferenceNode);
468

    
469
                DBObjectCollection objColl = new DBObjectCollection();
470

    
471
                if (!pBlkRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
472
                {
473
                    pBlkRef.Explode(objColl);
474
                    foreach (var obj in objColl)
475
                    {
476
                        if (obj is DBText)
477
                        {
478
                            dumpTextData(obj as DBText, indent, BlockReferenceNode);
479
                        }
480
                        else if (obj is MText)
481
                        {
482
                            MText mtext = obj as MText;
483

    
484
                            DBObjectCollection objs = new DBObjectCollection();
485
                            mtext.Explode(objs);
486
                            foreach (var item in objs)
487
                            {
488
                                dumpTextData(item as DBText, indent, node);
489
                            }
490
                        }
491
                    }
492
                }
493

    
494
                /**********************************************************************/
495
                /* Dump the attributes                                                */
496
                /**********************************************************************/
497
                int i = 0;
498
                AttributeCollection attCol = pBlkRef.AttributeCollection;
499
                foreach (ObjectId id in attCol)
500
                {
501
                    try
502
                    {
503
                        using (AttributeReference pAttr = (AttributeReference)id.Open(OpenMode.ForRead))
504
                            dumpAttributeData(indent, pAttr, i++, BlockReferenceNode);
505
                    }
506
                    catch (System.Exception)
507
                    {
508

    
509
                    }
510
                }
511

    
512
                node.AppendChild(BlockReferenceNode);
513

    
514
                return BlockReferenceNode;
515
            }
516

    
517
            return null;
518
        }
519
        /************************************************************************/
520
        /* Dump data common to all OdDbCurves                                   */
521
        /************************************************************************/
522
        static void dumpCurveData(Entity pEnt, int indent, XmlNode node)
523
        {
524
            if (node != null)
525
            {
526
                Curve pEntity = (Curve)pEnt;
527
                try
528
                {
529
                    writeLine(indent, "Start Point", pEntity.StartPoint);
530
                    writeLine(indent, "End Point", pEntity.EndPoint);
531
                }
532
                catch (System.Exception)
533
                {
534
                }
535
                writeLine(indent, "Closed", pEntity.Closed);
536
                writeLine(indent, "Periodic", pEntity.IsPeriodic);
537

    
538
                try
539
                {
540
                    writeLine(indent, "Area", pEntity.Area);
541
                }
542
                catch (System.Exception)
543
                {
544
                }
545
                dumpEntityData(pEntity, indent, node);
546
            }
547
        }
548

    
549
        /************************************************************************/
550
        /* Dump Dimension data                                                  */
551
        /************************************************************************/
552
        static XmlNode dumpDimData(Dimension pDim, int indent, XmlNode node)
553
        {
554
            if (node != null)
555
            {
556
                XmlElement DimDataNode = Program.xml.CreateElement("DimData");
557

    
558
                XmlAttribute CurrentMeasurementAttr = Program.xml.CreateAttribute("CurrentMeasurement");
559
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
560
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
561

    
562
                XmlAttribute DimensionTextAttr = Program.xml.CreateAttribute("DimensionText");
563
                DimensionTextAttr.Value = pDim.DimensionText.ToString();
564
                DimDataNode.Attributes.SetNamedItem(DimensionTextAttr);
565

    
566
                if (pDim.CurrentMeasurement >= 0.0)
567
                {
568
                    XmlAttribute FormattedMeasurementAttr = Program.xml.CreateAttribute("FormattedMeasurement");
569
                    FormattedMeasurementAttr.Value = pDim.FormatMeasurement(pDim.CurrentMeasurement, pDim.DimensionText);
570
                    DimDataNode.Attributes.SetNamedItem(FormattedMeasurementAttr);
571
                }
572
                if (pDim.DimBlockId.IsNull)
573
                {
574
                    writeLine(indent, "Dimension Block NULL");
575
                }
576
                else
577
                {
578
                    using (BlockTableRecord btr = (BlockTableRecord)pDim.DimBlockId.Open(OpenMode.ForRead))
579
                    {
580
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
581
                        NameAttr.Value = btr.Name;
582
                        DimDataNode.Attributes.SetNamedItem(NameAttr);
583
                    }
584
                }
585

    
586
                XmlAttribute DimBlockPositionAttr = Program.xml.CreateAttribute("DimBlockPosition");
587
                DimBlockPositionAttr.Value = pDim.DimBlockPosition.ToString();
588
                DimDataNode.Attributes.SetNamedItem(DimBlockPositionAttr);
589

    
590
                XmlAttribute TextPositionAttr = Program.xml.CreateAttribute("TextPosition");
591
                TextPositionAttr.Value = pDim.TextPosition.ToString();
592
                DimDataNode.Attributes.SetNamedItem(TextPositionAttr);
593

    
594
                XmlAttribute TextRotationAttr = Program.xml.CreateAttribute("TextRotation");
595
                TextRotationAttr.Value = pDim.TextRotation.ToString();
596
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
597

    
598
                XmlAttribute DimensionStyleNameAttr = Program.xml.CreateAttribute("DimensionStyleName");
599
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
600
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
601

    
602
                XmlAttribute DimtfillclrAttr = Program.xml.CreateAttribute("Dimtfillclr");
603
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
604
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
605

    
606
                XmlAttribute DimtfillAttr = Program.xml.CreateAttribute("Dimtfill");
607
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
608
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
609

    
610
                XmlAttribute Dimltex1Attr = Program.xml.CreateAttribute("Dimltex1");
611
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
612
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
613

    
614
                XmlAttribute Dimltex2Attr = Program.xml.CreateAttribute("Dimltex2");
615
                Dimltex2Attr.Value = pDim.Dimltex2.ToString();
616
                DimDataNode.Attributes.SetNamedItem(Dimltex2Attr);
617

    
618
                XmlAttribute DimltypeAttr = Program.xml.CreateAttribute("Dimltype");
619
                DimltypeAttr.Value = pDim.Dimltype.ToString();
620
                DimDataNode.Attributes.SetNamedItem(DimltypeAttr);
621

    
622
                XmlAttribute HorizontalRotationAttr = Program.xml.CreateAttribute("HorizontalRotation");
623
                HorizontalRotationAttr.Value = pDim.HorizontalRotation.ToString();
624
                DimDataNode.Attributes.SetNamedItem(HorizontalRotationAttr);
625

    
626
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
627
                ElevationAttr.Value = pDim.Elevation.ToString();
628
                DimDataNode.Attributes.SetNamedItem(ElevationAttr);
629

    
630
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
631
                NormalAttr.Value = pDim.Normal.ToString();
632
                DimDataNode.Attributes.SetNamedItem(NormalAttr);
633

    
634
                dumpEntityData(pDim, indent, node);
635

    
636
                return DimDataNode;
637
            }
638

    
639
            return null;
640
        }
641

    
642
        /************************************************************************/
643
        /* 2 Line Angular Dimension Dumper                                      */
644
        /************************************************************************/
645
        static XmlNode dump(LineAngularDimension2 pDim, int indent, XmlNode node)
646
        {
647
            if (node != null)
648
            {
649
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
650

    
651
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
652
                HandleAttr.Value = pDim.Handle.ToString();
653
                DimNode.Attributes.SetNamedItem(HandleAttr);
654

    
655
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
656
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
657
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
658

    
659
                XmlAttribute XLine1StartAttr = Program.xml.CreateAttribute("XLine1Start");
660
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
661
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
662

    
663
                XmlAttribute XLine1EndAttr = Program.xml.CreateAttribute("XLine1End");
664
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
665
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
666

    
667
                XmlAttribute XLine2StartAttr = Program.xml.CreateAttribute("XLine2Start");
668
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
669
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
670

    
671
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
672
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
673
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
674

    
675
                dumpDimData(pDim, indent, DimNode);
676

    
677
                return DimNode;
678
            }
679

    
680
            return null;
681
        }
682

    
683
        /************************************************************************/
684
        /* Dump 2D Vertex data                                                  */
685
        /************************************************************************/
686
        static XmlNode dump2dVertex(int indent, Vertex2d pVertex, int i, XmlNode node)
687
        {
688
            if (node != null)
689
            {
690
                XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
691

    
692
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
693
                HandleAttr.Value = pVertex.Handle.ToString();
694
                VertexNode.Attributes.SetNamedItem(HandleAttr);
695

    
696
                XmlAttribute VertexTypeAttr = Program.xml.CreateAttribute("VertexType");
697
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
698
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
699

    
700
                XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
701
                PositionAttr.Value = pVertex.Position.ToString();
702
                VertexNode.Attributes.SetNamedItem(PositionAttr);
703

    
704
                XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
705
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
706
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
707

    
708
                XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
709
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
710
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
711

    
712
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
713
                BulgeAttr.Value = pVertex.Bulge.ToString();
714
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
715

    
716
                if (pVertex.Bulge != 0)
717
                {
718
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
719
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
720
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
721
                }
722

    
723
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
724
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
725
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
726
                if (pVertex.TangentUsed)
727
                {
728
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
729
                    TangentAttr.Value = pVertex.Tangent.ToString();
730
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
731
                }
732

    
733
                node.AppendChild(VertexNode);
734

    
735
                return VertexNode;
736
            }
737

    
738
            return null;
739
        }
740

    
741
        /************************************************************************/
742
        /* 2D Polyline Dumper                                                   */
743
        /************************************************************************/
744
        static XmlNode dump(Polyline2d pPolyline, int indent, XmlNode node)
745
        {
746
            /********************************************************************/
747
            /* Dump the vertices                                                */
748
            /********************************************************************/
749
            List<Vertex2d> Vertices = new List<Vertex2d>();
750
            int i = 0;
751
            foreach (ObjectId obj in pPolyline)
752
            {
753
                using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
754
                {
755
                    if (dbObj is Vertex2d)
756
                    {
757
                        Vertices.Add((Vertex2d)dbObj);
758
                        /// dump2dVertex(indent, (Vertex2d)dbObj, i++);
759
                    }
760
                }
761
            }
762

    
763
            if (node != null)
764
            {
765
                XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
766

    
767
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
768
                HandleAttr.Value = pPolyline.Handle.ToString();
769
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
770

    
771
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
772
                CountAttr.Value = Vertices.Count.ToString();
773
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
774

    
775
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
776
                ElevationAttr.Value = pPolyline.Elevation.ToString();
777
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
778

    
779
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
780
                NormalAttr.Value = pPolyline.Normal.ToString();
781
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
782

    
783
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
784
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
785
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
786

    
787
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
788
                ClosedAttr.Value = pPolyline.Closed.ToString();
789
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
790

    
791
                foreach (var vt in Vertices)
792
                {
793
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
794

    
795
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
796
                    XAttr.Value = vt.Position.X.ToString();
797
                    VertexNode.Attributes.SetNamedItem(XAttr);
798

    
799
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
800
                    YAttr.Value = vt.Position.Y.ToString();
801
                    VertexNode.Attributes.SetNamedItem(YAttr);
802

    
803
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
804
                    ZAttr.Value = vt.Position.Z.ToString();
805
                    VertexNode.Attributes.SetNamedItem(ZAttr);
806

    
807
                    Polyline2dNode.AppendChild(VertexNode);
808
                }
809

    
810
                dumpCurveData(pPolyline, indent, node);
811

    
812
                node.AppendChild(Polyline2dNode);
813

    
814
                return Polyline2dNode;
815
            }
816

    
817
            return null;
818
        }
819

    
820

    
821
        /************************************************************************/
822
        /* Dump 3D Polyline Vertex data                                         */
823
        /************************************************************************/
824
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
825
        {
826
            if (node != null)
827
            {
828
                XmlNode VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
829

    
830
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
831
                HandleAttr.Value = pVertex.Handle.ToString();
832
                VertexNode.Attributes.SetNamedItem(HandleAttr);
833

    
834
                XmlAttribute VertexxTypeAttr = Program.xml.CreateAttribute("VertexType");
835
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
836
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
837

    
838
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
839
                XAttr.Value = pVertex.Position.X.ToString();
840
                VertexNode.Attributes.SetNamedItem(XAttr);
841

    
842
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
843
                YAttr.Value = pVertex.Position.Y.ToString();
844
                VertexNode.Attributes.SetNamedItem(YAttr);
845

    
846
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
847
                ZAttr.Value = pVertex.Position.Z.ToString();
848
                VertexNode.Attributes.SetNamedItem(ZAttr);
849

    
850
                node.AppendChild(VertexNode);
851

    
852
                return VertexNode;
853
            }
854

    
855
            return null;
856
        }
857

    
858
        /************************************************************************/
859
        /* 3D Polyline Dumper                                                   */
860
        /************************************************************************/
861
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
862
        {
863
            if (node != null)
864
            {
865
                XmlNode pPolylineNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
866

    
867
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
868
                HandleAttr.Value = pPolyline.Handle.ToString();
869
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
870

    
871
                /********************************************************************/
872
                /* Dump the vertices                                                */
873
                /********************************************************************/
874
                int i = 0;
875
                foreach (ObjectId obj in pPolyline)
876
                {
877
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
878
                    {
879
                        if (dbObj is PolylineVertex3d)
880
                        {
881
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
882
                        }
883
                    }
884
                }
885
                dumpCurveData(pPolyline, indent, pPolylineNode);
886

    
887
                node.AppendChild(pPolylineNode);
888

    
889
                return pPolylineNode;
890
            }
891

    
892
            return null;
893
        }
894

    
895

    
896
        /************************************************************************/
897
        /* 3DSolid Dumper                                                       */
898
        /************************************************************************/
899
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
900
        {
901
            if (node != null)
902
            {
903
                XmlNode SolidNode = Program.xml.CreateElement(pSolid.GetRXClass().Name);
904

    
905
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
906
                HandleAttr.Value = pSolid.Handle.ToString();
907
                SolidNode.Attributes.SetNamedItem(HandleAttr);
908

    
909
                dumpEntityData(pSolid, indent, node);
910

    
911
                node.AppendChild(SolidNode);
912

    
913
                return SolidNode;
914
            }
915

    
916
            return null;
917
        }
918

    
919

    
920
        /************************************************************************/
921
        /* 3 Point Angular Dimension Dumper                                     */
922
        /************************************************************************/
923
        XmlNode dump(Point3AngularDimension pDim, int indent, XmlNode node)
924
        {
925
            if (node != null)
926
            {
927
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
928

    
929
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
930
                HandleAttr.Value = pDim.Handle.ToString();
931
                DimNode.Attributes.SetNamedItem(HandleAttr);
932

    
933
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
934
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
935
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
936

    
937
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
938
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
939
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
940

    
941
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
942
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
943
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
944

    
945
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
946
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
947
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
948

    
949
                dumpDimData(pDim, indent, DimNode);
950

    
951
                return DimNode;
952
            }
953

    
954
            return null;
955
        }
956

    
957
        /************************************************************************/
958
        /* Aligned Dimension Dumper                                             */
959
        /************************************************************************/
960
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
961
        {
962
            if (node != null)
963
            {
964
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
965

    
966
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
967
                HandleAttr.Value = pDim.Handle.ToString();
968
                DimNode.Attributes.SetNamedItem(HandleAttr);
969

    
970
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
971
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
972
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
973

    
974
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
975
                ObliqueAttr.Value = pDim.Oblique.ToString();
976
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
977

    
978
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
979
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
980
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
981

    
982
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
983
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
984
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
985

    
986
                dumpDimData(pDim, indent, DimNode);
987

    
988
                return DimNode;
989
            }
990

    
991
            return null;
992
        }
993

    
994
        /************************************************************************/
995
        /* Arc Dumper                                                           */
996
        /************************************************************************/
997
        XmlNode dump(Arc pArc, int indent, XmlNode node)
998
        {
999
            if (node != null)
1000
            {
1001
                XmlElement ArcNode = Program.xml.CreateElement(pArc.GetRXClass().Name);
1002

    
1003
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1004
                XAttr.Value = pArc.Center.X.ToString();
1005
                ArcNode.Attributes.SetNamedItem(XAttr);
1006

    
1007
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1008
                YAttr.Value = pArc.Center.Y.ToString();
1009
                ArcNode.Attributes.SetNamedItem(YAttr);
1010

    
1011
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1012
                ZAttr.Value = pArc.Center.Z.ToString();
1013
                ArcNode.Attributes.SetNamedItem(ZAttr);
1014

    
1015
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1016
                RadiusAttr.Value = pArc.Radius.ToString();
1017
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
1018

    
1019
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1020
                StartAngleAttr.Value = pArc.StartAngle.ToString();
1021
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
1022

    
1023
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1024
                EndAngleAttr.Value = pArc.EndAngle.ToString();
1025
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
1026

    
1027
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1028
                NormalAttr.Value = pArc.Normal.ToString();
1029
                ArcNode.Attributes.SetNamedItem(NormalAttr);
1030

    
1031
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1032
                ThicknessAttr.Value = pArc.Normal.ToString();
1033
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
1034

    
1035
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
1036
                dumpCurveData(pArc, indent, ArcNode);
1037

    
1038
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1039
                {
1040
                    XAttr = Program.xml.CreateAttribute("X");
1041
                    XAttr.Value = pArc.StartPoint.X.ToString();
1042
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1043

    
1044
                    YAttr = Program.xml.CreateAttribute("Y");
1045
                    YAttr.Value = pArc.StartPoint.Y.ToString();
1046
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1047

    
1048
                    ZAttr = Program.xml.CreateAttribute("Z");
1049
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
1050
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1051
                }
1052
                ArcNode.AppendChild(StartPointNode);
1053

    
1054
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1055
                {
1056
                    XAttr = Program.xml.CreateAttribute("X");
1057
                    XAttr.Value = pArc.EndPoint.X.ToString();
1058
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1059

    
1060
                    YAttr = Program.xml.CreateAttribute("Y");
1061
                    YAttr.Value = pArc.EndPoint.Y.ToString();
1062
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1063

    
1064
                    ZAttr = Program.xml.CreateAttribute("Z");
1065
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1066
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1067
                }
1068
                ArcNode.AppendChild(EndPointNode);
1069

    
1070
                node.AppendChild(ArcNode);
1071

    
1072
                return ArcNode;
1073
            }
1074

    
1075
            return null;
1076
        }
1077

    
1078
        /************************************************************************/
1079
        /* Arc Dimension Dumper                                                 */
1080
        /************************************************************************/
1081
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
1082
        {
1083
            if (node != null)
1084
            {
1085
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1086

    
1087
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1088
                HandleAttr.Value = pDim.Handle.ToString();
1089
                DimNode.Attributes.SetNamedItem(HandleAttr);
1090

    
1091
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
1092
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
1093
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
1094

    
1095
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
1096
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
1097
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
1098

    
1099
                XmlAttribute ArcSymbolTypeAttr = Program.xml.CreateAttribute("ArcSymbolType");
1100
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1101
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1102

    
1103
                XmlAttribute IsPartialAttr = Program.xml.CreateAttribute("IsPartial");
1104
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1105
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1106

    
1107
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1108
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1109
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1110

    
1111
                if (pDim.HasLeader)
1112
                {
1113
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1114
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1115
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1116

    
1117
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1118
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1119
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1120
                }
1121

    
1122
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1123
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1124
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1125

    
1126
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1127
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1128
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1129

    
1130
                dumpDimData(pDim, indent, DimNode);
1131

    
1132
                return DimNode;
1133
            }
1134

    
1135
            return null;
1136
        }
1137

    
1138

    
1139
        /************************************************************************/
1140
        /* Block Reference Dumper                                                */
1141
        /************************************************************************/
1142
        void dump(BlockReference pBlkRef, int indent, XmlNode node)
1143
        {
1144
            using (BlockTableRecord pRecord = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead))
1145
            {
1146
                XmlNode BlockRefNode = dumpBlockRefData(pBlkRef, indent, node);
1147
                if (BlockRefNode != null)
1148
                {
1149
                    XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
1150
                    NameAttr.Value = pRecord.Name;
1151
                    BlockRefNode.Attributes.SetNamedItem(NameAttr);
1152
                }
1153
            }
1154
        }
1155

    
1156
        /************************************************************************/
1157
        /* Body Dumper                                                          */
1158
        /************************************************************************/
1159
        XmlNode dump(Body pBody, int indent, XmlNode node)
1160
        {
1161
            if (node != null)
1162
            {
1163
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1164

    
1165
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1166
                HandleAttr.Value = pBody.Handle.ToString();
1167
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1168

    
1169
                dumpEntityData(pBody, indent, BodyNode);
1170

    
1171
                return BodyNode;
1172
            }
1173

    
1174
            return null;
1175
        }
1176

    
1177

    
1178
        /************************************************************************/
1179
        /* Circle Dumper                                                        */
1180
        /************************************************************************/
1181
        XmlNode dump(Circle pCircle, int indent, XmlNode node)
1182
        {
1183
            if (node != null)
1184
            {
1185
                XmlElement CircleNode = Program.xml.CreateElement(pCircle.GetRXClass().Name);
1186

    
1187
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1188
                XAttr.Value = pCircle.Center.X.ToString();
1189
                CircleNode.Attributes.SetNamedItem(XAttr);
1190

    
1191
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1192
                YAttr.Value = pCircle.Center.Y.ToString();
1193
                CircleNode.Attributes.SetNamedItem(YAttr);
1194

    
1195
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1196
                RadiusAttr.Value = pCircle.Radius.ToString();
1197
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1198

    
1199
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1200
                NormalAttr.Value = pCircle.Normal.ToString();
1201
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1202

    
1203
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1204
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1205
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1206

    
1207
                dumpCurveData(pCircle, indent, CircleNode);
1208

    
1209
                node.AppendChild(CircleNode);
1210

    
1211
                return CircleNode;
1212
            }
1213

    
1214
            return null;
1215
        }
1216

    
1217
        /************************************************************************/
1218
        /* Diametric Dimension Dumper                                           */
1219
        /************************************************************************/
1220
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1221
        {
1222
            if (node != null)
1223
            {
1224
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1225

    
1226
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1227
                HandleAttr.Value = pDim.Handle.ToString();
1228
                DimNode.Attributes.SetNamedItem(HandleAttr);
1229

    
1230
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
1231
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1232
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1233

    
1234
                XmlAttribute FarChordPointAttr = Program.xml.CreateAttribute("FarChordPoint");
1235
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1236
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1237

    
1238
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1239
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1240
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1241

    
1242
                dumpDimData(pDim, indent, DimNode);
1243

    
1244
                return DimNode;
1245
            }
1246

    
1247
            return null;
1248
        }
1249

    
1250
        /************************************************************************/
1251
        /* Ellipse Dumper                                                       */
1252
        /************************************************************************/
1253
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1254
        {
1255
            if (node != null)
1256
            {
1257
                XmlElement EllipseNode = Program.xml.CreateElement(pEllipse.GetRXClass().Name);
1258

    
1259
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1260

    
1261
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1262
                XAttr.Value = pEllipse.Center.X.ToString();
1263
                EllipseNode.Attributes.SetNamedItem(XAttr);
1264

    
1265
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1266
                YAttr.Value = pEllipse.Center.Y.ToString();
1267
                EllipseNode.Attributes.SetNamedItem(YAttr);
1268

    
1269
                XmlAttribute MajorAxisAttr = Program.xml.CreateAttribute("MajorAxis");
1270
                MajorAxisAttr.Value = pEllipse.MajorAxis.ToString();
1271
                EllipseNode.Attributes.SetNamedItem(MajorAxisAttr);
1272

    
1273
                XmlAttribute MinorAxisAttr = Program.xml.CreateAttribute("MinorAxis");
1274
                MinorAxisAttr.Value = pEllipse.MinorAxis.ToString();
1275
                EllipseNode.Attributes.SetNamedItem(MinorAxisAttr);
1276

    
1277
                XmlAttribute MajorRadiusAttr = Program.xml.CreateAttribute("MajorRadius");
1278
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1279
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1280

    
1281
                XmlAttribute MinorRadiusAttr = Program.xml.CreateAttribute("MinorRadius");
1282
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1283
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1284

    
1285
                XmlAttribute RadiusRatioAttr = Program.xml.CreateAttribute("RadiusRatio");
1286
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1287
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1288

    
1289
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1290
                StartAngleAttr.Value = pEllipse.StartAngle.ToString();
1291
                EllipseNode.Attributes.SetNamedItem(StartAngleAttr);
1292

    
1293
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1294
                EndAngleAttr.Value = pEllipse.EndAngle.ToString();
1295
                EllipseNode.Attributes.SetNamedItem(EndAngleAttr);
1296

    
1297
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1298
                NormalAttr.Value = pEllipse.Normal.ToString();
1299
                EllipseNode.Attributes.SetNamedItem(NormalAttr);
1300

    
1301
                dumpCurveData(pEllipse, indent, EllipseNode);
1302

    
1303
                node.AppendChild(EllipseNode);
1304
            }
1305
        }
1306

    
1307
        /************************************************************************/
1308
        /* Face Dumper                                                       */
1309
        /************************************************************************/
1310
        XmlNode dump(Face pFace, int indent, XmlNode node)
1311
        {
1312
            if (node != null)
1313
            {
1314
                XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1315

    
1316
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1317
                HandleAttr.Value = pFace.Handle.ToString();
1318
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1319

    
1320
                for (short i = 0; i < 4; i++)
1321
                {
1322
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1323

    
1324
                    Point3d pt = pFace.GetVertexAt(i);
1325
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1326
                    XAttr.Value = pt.X.ToString();
1327
                    VertexNode.Attributes.SetNamedItem(XAttr);
1328

    
1329
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1330
                    YAttr.Value = pt.Y.ToString();
1331
                    VertexNode.Attributes.SetNamedItem(YAttr);
1332

    
1333
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1334
                    ZAttr.Value = pt.Z.ToString();
1335
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1336

    
1337
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1338
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1339
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1340

    
1341
                    FaceNode.AppendChild(VertexNode);
1342
                }
1343
                dumpEntityData(pFace, indent, FaceNode);
1344

    
1345
                node.AppendChild(FaceNode);
1346

    
1347
                return FaceNode;
1348
            }
1349

    
1350
            return null;
1351
        }
1352

    
1353
        /************************************************************************/
1354
        /* FCF Dumper                                                           */
1355
        /************************************************************************/
1356
        void dump(FeatureControlFrame pFcf, int indent)
1357
        {
1358
            writeLine(indent++, pFcf.GetRXClass().Name, pFcf.Handle);
1359
            writeLine(indent, "Location", pFcf.Location);
1360
            writeLine(indent, "Text", pFcf.Text);
1361
            writeLine(indent, "Dimension Style", pFcf.DimensionStyleName);
1362
            writeLine(indent, "Dimension Gap", pFcf.Dimgap);
1363
            writeLine(indent, "Dimension Scale", pFcf.Dimscale);
1364
            writeLine(indent, "Text Height", pFcf.Dimtxt);
1365
            writeLine(indent, "Frame Color", pFcf.Dimclrd);
1366
            writeLine(indent, "Text Style", pFcf.TextStyleName);
1367
            writeLine(indent, "Text Color", pFcf.Dimclrd);
1368
            writeLine(indent, "X-Direction", pFcf.Direction);
1369
            writeLine(indent, "Normal", pFcf.Normal);
1370
            dumpEntityData(pFcf, indent, Program.xml.DocumentElement);
1371
        }
1372

    
1373
        /************************************************************************/
1374
        /* Hatch Dumper                                                         */
1375
        /************************************************************************/
1376
        /***********************************************************************/
1377
        /* Dump Polyline Loop                                                  */
1378
        /***********************************************************************/
1379
        static void dumpPolylineType(int loopIndex, Hatch pHatch, int indent)
1380
        {
1381
            HatchLoop hl = pHatch.GetLoopAt(loopIndex);
1382
            for (int i = 0; i < hl.Polyline.Count; i++)
1383
            {
1384
                BulgeVertex bv = hl.Polyline[i];
1385
                writeLine(indent, "Vertex " + i.ToString(), bv.Vertex.ToString());
1386
                writeLine(indent + 1, "Bulge " + i.ToString(), bv.Bulge);
1387
                writeLine(indent + 1, "Bulge angle " + i.ToString(), toDegreeString(4 * Math.Atan(bv.Bulge)));
1388
            }
1389
        }
1390

    
1391
        /**********************************************************************/
1392
        /* Dump Circular Arc Edge                                             */
1393
        /**********************************************************************/
1394
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1395
        {
1396
            writeLine(indent, "Center", pCircArc.Center);
1397
            writeLine(indent, "Radius", pCircArc.Radius);
1398
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1399
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1400
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1401
        }
1402

    
1403
        /**********************************************************************/
1404
        /* Dump Elliptical Arc Edge                                           */
1405
        /**********************************************************************/
1406
        static void dumpEllipticalArcEdge(int indent, EllipticalArc2d pEllipArc)
1407
        {
1408
            writeLine(indent, "Center", pEllipArc.Center);
1409
            writeLine(indent, "Major Radius", pEllipArc.MajorRadius);
1410
            writeLine(indent, "Minor Radius", pEllipArc.MinorRadius);
1411
            writeLine(indent, "Major Axis", pEllipArc.MajorAxis);
1412
            writeLine(indent, "Minor Axis", pEllipArc.MinorAxis);
1413
            writeLine(indent, "Start Angle", toDegreeString(pEllipArc.StartAngle));
1414
            writeLine(indent, "End Angle", toDegreeString(pEllipArc.EndAngle));
1415
            writeLine(indent, "Clockwise", pEllipArc.IsClockWise);
1416
        }
1417

    
1418
        /**********************************************************************/
1419
        /* Dump NurbCurve Edge                                           */
1420
        /**********************************************************************/
1421
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1422
        {
1423
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1424
            writeLine(indent, "Degree", d.Degree);
1425
            writeLine(indent, "Rational", d.Rational);
1426
            writeLine(indent, "Periodic", d.Periodic);
1427

    
1428
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1429
            for (int i = 0; i < d.ControlPoints.Count; i++)
1430
            {
1431
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1432
            }
1433
            writeLine(indent, "Number of Knots", d.Knots.Count);
1434
            for (int i = 0; i < d.Knots.Count; i++)
1435
            {
1436
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1437
            }
1438

    
1439
            if (d.Rational)
1440
            {
1441
                writeLine(indent, "Number of Weights", d.Weights.Count);
1442
                for (int i = 0; i < d.Weights.Count; i++)
1443
                {
1444
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1445
                }
1446
            }
1447
        }
1448

    
1449
        /***********************************************************************/
1450
        /* Dump Edge Loop                                                      */
1451
        /***********************************************************************/
1452
        static void dumpEdgesType(int loopIndex, Hatch pHatch, int indent)
1453
        {
1454
            Curve2dCollection edges = pHatch.GetLoopAt(loopIndex).Curves;
1455
            for (int i = 0; i < (int)edges.Count; i++)
1456
            {
1457
                using (Curve2d pEdge = edges[i])
1458
                {
1459
                    writeLine(indent, string.Format("Edge {0}", i), pEdge.GetType().Name);
1460
                    switch (pEdge.GetType().Name)
1461
                    {
1462
                        case "LineSegment2d":
1463
                            break;
1464
                        case "CircularArc2d":
1465
                            dumpCircularArcEdge(indent + 1, (CircularArc2d)pEdge);
1466
                            break;
1467
                        case "EllipticalArc2d":
1468
                            dumpEllipticalArcEdge(indent + 1, (EllipticalArc2d)pEdge);
1469
                            break;
1470
                        case "NurbCurve2d":
1471
                            dumpNurbCurveEdge(indent + 1, (NurbCurve2d)pEdge);
1472
                            break;
1473
                    }
1474

    
1475
                    /******************************************************************/
1476
                    /* Common Edge Properties                                         */
1477
                    /******************************************************************/
1478
                    Interval interval = pEdge.GetInterval();
1479
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1480
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1481
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1482
                }
1483
            }
1484
        }
1485

    
1486
        /************************************************************************/
1487
        /* Convert the specified value to a LoopType string                     */
1488
        /************************************************************************/
1489
        string toLooptypeString(HatchLoopTypes loopType)
1490
        {
1491
            string retVal = "";
1492
            if ((loopType & HatchLoopTypes.External) != 0)
1493
                retVal = retVal + " | kExternal";
1494

    
1495
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1496
                retVal = retVal + " | kPolyline";
1497

    
1498
            if ((loopType & HatchLoopTypes.Derived) != 0)
1499
                retVal = retVal + " | kDerived";
1500

    
1501
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1502
                retVal = retVal + " | kTextbox";
1503

    
1504
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1505
                retVal = retVal + " | kOutermost";
1506

    
1507
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1508
                retVal = retVal + " | kNotClosed";
1509

    
1510
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1511
                retVal = retVal + " | kSelfIntersecting";
1512

    
1513
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1514
                retVal = retVal + " | kTextIsland";
1515

    
1516
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1517
                retVal = retVal + " | kDuplicate";
1518

    
1519
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1520
        }
1521

    
1522
        void dump(Hatch pHatch, int indent)
1523
        {
1524
            writeLine(indent++, pHatch.GetRXClass().Name, pHatch.Handle);
1525
            writeLine(indent, "Hatch Style", pHatch.HatchStyle);
1526
            writeLine(indent, "Hatch Object Type", pHatch.HatchObjectType);
1527
            writeLine(indent, "Is Hatch", pHatch.IsHatch);
1528
            writeLine(indent, "Is Gradient", !pHatch.IsGradient);
1529
            if (pHatch.IsHatch)
1530
            {
1531
                /******************************************************************/
1532
                /* Dump Hatch Parameters                                          */
1533
                /******************************************************************/
1534
                writeLine(indent, "Pattern Type", pHatch.PatternType);
1535
                switch (pHatch.PatternType)
1536
                {
1537
                    case HatchPatternType.PreDefined:
1538
                    case HatchPatternType.CustomDefined:
1539
                        writeLine(indent, "Pattern Name", pHatch.PatternName);
1540
                        writeLine(indent, "Solid Fill", pHatch.IsSolidFill);
1541
                        if (!pHatch.IsSolidFill)
1542
                        {
1543
                            writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1544
                            writeLine(indent, "Pattern Scale", pHatch.PatternScale);
1545
                        }
1546
                        break;
1547
                    case HatchPatternType.UserDefined:
1548
                        writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1549
                        writeLine(indent, "Pattern Double", pHatch.PatternDouble);
1550
                        writeLine(indent, "Pattern Space", pHatch.PatternSpace);
1551
                        break;
1552
                }
1553
                DBObjectCollection entitySet = new DBObjectCollection();
1554
                Handle hhh = pHatch.Handle;
1555
                if (hhh.Value == 1692) //69C)
1556
                {
1557
                    pHatch.Explode(entitySet);
1558
                    return;
1559
                }
1560
                if (hhh.Value == 1693) //69D)
1561
                {
1562
                    try
1563
                    {
1564
                        pHatch.Explode(entitySet);
1565
                    }
1566
                    catch (System.Exception e)
1567
                    {
1568
                        if (e.Message == "eCannotExplodeEntity")
1569
                        {
1570
                            writeLine(indent, "Hatch " + e.Message + ": ", pHatch.Handle);
1571
                            return;
1572
                        }
1573
                    }
1574
                }
1575
            }
1576
            if (pHatch.IsGradient)
1577
            {
1578
                /******************************************************************/
1579
                /* Dump Gradient Parameters                                       */
1580
                /******************************************************************/
1581
                writeLine(indent, "Gradient Type", pHatch.GradientType);
1582
                writeLine(indent, "Gradient Name", pHatch.GradientName);
1583
                writeLine(indent, "Gradient Angle", toDegreeString(pHatch.GradientAngle));
1584
                writeLine(indent, "Gradient Shift", pHatch.GradientShift);
1585
                writeLine(indent, "Gradient One-Color Mode", pHatch.GradientOneColorMode);
1586
                if (pHatch.GradientOneColorMode)
1587
                {
1588
                    writeLine(indent, "ShadeTintValue", pHatch.ShadeTintValue);
1589
                }
1590
                GradientColor[] colors = pHatch.GetGradientColors();
1591
                for (int i = 0; i < colors.Length; i++)
1592
                {
1593
                    writeLine(indent, string.Format("Color         {0}", i), colors[i].get_Color());
1594
                    writeLine(indent, string.Format("Interpolation {0}", i), colors[i].get_Value());
1595
                }
1596
            }
1597

    
1598
            /********************************************************************/
1599
            /* Dump Associated Objects                                          */
1600
            /********************************************************************/
1601
            writeLine(indent, "Associated objects", pHatch.Associative);
1602
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1603
            {
1604
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1605
            }
1606

    
1607
            /********************************************************************/
1608
            /* Dump Loops                                                       */
1609
            /********************************************************************/
1610
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1611
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1612
            {
1613
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1614

    
1615
                /******************************************************************/
1616
                /* Dump Loop                                                      */
1617
                /******************************************************************/
1618
                if ((pHatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) != 0)
1619
                {
1620
                    dumpPolylineType(i, pHatch, indent + 2);
1621
                }
1622
                else
1623
                {
1624
                    dumpEdgesType(i, pHatch, indent + 2);
1625
                }
1626
                /******************************************************************/
1627
                /* Dump Associated Objects                                        */
1628
                /******************************************************************/
1629
                if (pHatch.Associative)
1630
                {
1631
                    writeLine(indent + 2, "Associated objects");
1632
                    foreach (ObjectId id in pHatch.GetAssociatedObjectIdsAt(i))
1633
                    {
1634
                        writeLine(indent + 3, id.ObjectClass.Name, id.Handle);
1635
                    }
1636
                }
1637
            }
1638

    
1639
            writeLine(indent, "Elevation", pHatch.Elevation);
1640
            writeLine(indent, "Normal", pHatch.Normal);
1641
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1642
        }
1643

    
1644
        /************************************************************************/
1645
        /* Leader Dumper                                                          */
1646
        /************************************************************************/
1647
        void dump(Leader pLeader, int indent)
1648
        {
1649
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1650
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1651

    
1652
            writeLine(indent, "Annotation");
1653
            if (!pLeader.Annotation.IsNull)
1654
            {
1655
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1656
            }
1657
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1658
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1659
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1660
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1661
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1662
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1663
            writeLine(indent, "Splined", pLeader.IsSplined);
1664

    
1665
            for (int i = 0; i < pLeader.NumVertices; i++)
1666
            {
1667
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1668
            }
1669
            writeLine(indent, "Normal", pLeader.Normal);
1670
            dumpCurveData(pLeader, indent, Program.xml.DocumentElement);
1671
        }
1672

    
1673
        /************************************************************************/
1674
        /* Line Dumper                                                          */
1675
        /************************************************************************/
1676
        void dump(Line pLine, int indent, XmlNode node)
1677
        {
1678
            if (node != null && pLine != null && pLine.Length != 0)
1679
            {
1680
                XmlNode LineNode = Program.xml.CreateElement(pLine.GetRXClass().Name);
1681
                XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1682
                LengthAttr.Value = pLine.Length.ToString();
1683
                LineNode.Attributes.SetNamedItem(LengthAttr);
1684

    
1685
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1686
                HandleAttr.Value = pLine.Handle.ToString();
1687
                LineNode.Attributes.SetNamedItem(HandleAttr);
1688

    
1689
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1690
                {
1691
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1692
                    XAttr.Value = pLine.StartPoint.X.ToString();
1693
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1694

    
1695
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1696
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1697
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1698

    
1699
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1700
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1701
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1702
                }
1703
                LineNode.AppendChild(StartPointNode);
1704

    
1705
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1706
                {
1707
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1708
                    XAttr.Value = pLine.EndPoint.X.ToString();
1709
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1710

    
1711
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1712
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1713
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1714

    
1715
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1716
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1717
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1718
                }
1719
                LineNode.AppendChild(EndPointNode);
1720

    
1721
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1722
                NormalAttr.Value = pLine.Normal.ToString();
1723
                LineNode.Attributes.SetNamedItem(NormalAttr);
1724

    
1725
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1726
                ThicknessAttr.Value = pLine.Thickness.ToString();
1727
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1728

    
1729
                dumpEntityData(pLine, indent, LineNode);
1730

    
1731
                node.AppendChild(LineNode);
1732
            }
1733
            else
1734
            {
1735
                int d = 0;
1736
            }
1737
        }
1738

    
1739
        /************************************************************************/
1740
        /* MInsertBlock Dumper                                                  */
1741
        /************************************************************************/
1742
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1743
        {
1744
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1745

    
1746
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1747
            {
1748
                writeLine(indent, "Name", pRecord.Name);
1749
                writeLine(indent, "Rows", pMInsert.Rows);
1750
                writeLine(indent, "Columns", pMInsert.Columns);
1751
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1752
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1753
                dumpBlockRefData(pMInsert, indent, node);
1754
            }
1755
        }
1756

    
1757
        /************************************************************************/
1758
        /* Mline Dumper                                                         */
1759
        /************************************************************************/
1760
        void dump(Mline pMline, int indent)
1761
        {
1762
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1763
            writeLine(indent, "Style", pMline.Style);
1764
            writeLine(indent, "Closed", pMline.IsClosed);
1765
            writeLine(indent, "Scale", pMline.Scale);
1766
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1767
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1768
            writeLine(indent, "Normal", pMline.Normal);
1769

    
1770
            /********************************************************************/
1771
            /* Dump the segment data                                            */
1772
            /********************************************************************/
1773
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1774
            {
1775
                writeLine(indent, "Segment", i);
1776
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1777
            }
1778
            dumpEntityData(pMline, indent, Program.xml.DocumentElement);
1779
        }
1780

    
1781
        /************************************************************************/
1782
        /* MText Dumper                                                         */
1783
        /************************************************************************/
1784
        /// <summary>
1785
        /// convert MText to normal Text
1786
        /// </summary>
1787
        /// <param name="pMText"></param>
1788
        /// <param name="indent"></param>
1789
        /// <param name="node"></param>
1790
        void dump(MText pMText, int indent, XmlNode node)
1791
        {
1792
            DBObjectCollection objColl = new DBObjectCollection();
1793
            pMText.Explode(objColl);
1794
            foreach (var obj in objColl)
1795
            {
1796
                dumpTextData(obj as DBText, indent, node);
1797
            }
1798
        }
1799

    
1800
        /************************************************************************/
1801
        /* Ordinate Dimension Dumper                                            */
1802
        /************************************************************************/
1803
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1804
        {
1805
            if (node != null)
1806
            {
1807
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1808

    
1809
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1810
                HandleAttr.Value = pDim.Handle.ToString();
1811
                DimNode.Attributes.SetNamedItem(HandleAttr);
1812

    
1813
                XmlAttribute DefiningPointAttr = Program.xml.CreateAttribute("DefiningPoint");
1814
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1815
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1816

    
1817
                XmlAttribute UsingXAxisAttr = Program.xml.CreateAttribute("UsingXAxis");
1818
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1819
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1820

    
1821
                XmlAttribute UsingYAxisAttr = Program.xml.CreateAttribute("UsingYAxis");
1822
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1823
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1824

    
1825
                XmlAttribute LeaderEndPointAttr = Program.xml.CreateAttribute("LeaderEndPoint");
1826
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1827
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1828

    
1829
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1830
                OriginAttr.Value = pDim.Origin.ToString();
1831
                DimNode.Attributes.SetNamedItem(OriginAttr);
1832

    
1833
                dumpDimData(pDim, indent, DimNode);
1834

    
1835
                return DimNode;
1836
            }
1837

    
1838
            return null;
1839
        }
1840

    
1841
        /************************************************************************/
1842
        /* PolyFaceMesh Dumper                                                  */
1843
        /************************************************************************/
1844
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1845
        {
1846
            if (node != null)
1847
            {
1848
                XmlElement PolyNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1849

    
1850
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1851
                HandleAttr.Value = pPoly.Handle.ToString();
1852
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1853

    
1854
                XmlAttribute NumVerticesAttr = Program.xml.CreateAttribute("NumVertices");
1855
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1856
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1857

    
1858
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1859
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1860
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1861

    
1862
                /********************************************************************/
1863
                /* dump vertices and faces                                          */
1864
                /********************************************************************/
1865
                int vertexCount = 0;
1866
                int faceCount = 0;
1867
                foreach (ObjectId objId in pPoly)
1868
                {
1869
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1870
                    {
1871
                        if (ent is PolyFaceMeshVertex)
1872
                        {
1873
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1874

    
1875
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1876

    
1877
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1878
                            _HandleAttr.Value = pVertex.Handle.ToString();
1879
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1880

    
1881
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1882
                            PositionAttr.Value = pVertex.Position.ToString();
1883
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1884

    
1885
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1886

    
1887
                            PolyNode.AppendChild(VertexNode);
1888
                        }
1889
                        else if (ent is FaceRecord)
1890
                        {
1891
                            FaceRecord pFace = (FaceRecord)ent;
1892
                            string face = "{";
1893
                            for (short i = 0; i < 4; i++)
1894
                            {
1895
                                if (i > 0)
1896
                                {
1897
                                    face = face + " ";
1898
                                }
1899
                                face = face + pFace.GetVertexAt(i).ToString();
1900
                            }
1901

    
1902
                            face += "}";
1903

    
1904
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1905

    
1906
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1907
                            _HandleAttr.Value = pFace.Handle.ToString();
1908
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1909
                            FaceNode.InnerText = face;
1910

    
1911
                            dumpEntityData(pFace, indent + 1, FaceNode);
1912

    
1913
                            PolyNode.AppendChild(FaceNode);
1914
                        }
1915
                        else
1916
                        { // Unknown entity type
1917
                            writeLine(indent, "Unexpected Entity");
1918
                        }
1919
                    }
1920
                }
1921
                dumpEntityData(pPoly, indent, PolyNode);
1922

    
1923
                return PolyNode;
1924
            }
1925

    
1926
            return null;
1927
        }
1928

    
1929
        /************************************************************************/
1930
        /* Ole2Frame                                                            */
1931
        /************************************************************************/
1932
        void dump(Ole2Frame pOle, int indent)
1933
        {
1934
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1935

    
1936
            Rectangle3d pos = (Rectangle3d)pOle.Position3d;
1937
            writeLine(indent, "Lower Left", pos.LowerLeft);
1938
            writeLine(indent, "Lower Right", pos.LowerRight);
1939
            writeLine(indent, "Upper Left", pos.UpperLeft);
1940
            writeLine(indent, "Upper Right", pos.UpperRight);
1941
            writeLine(indent, "Type", pOle.Type);
1942
            writeLine(indent, "User Type", pOle.UserType);
1943
            if (pOle.Type == Ole2Frame.ItemType.Link)
1944
            {
1945
                writeLine(indent, "Link Name", pOle.LinkName);
1946
                writeLine(indent, "Link Path", pOle.LinkPath);
1947
            }
1948
            writeLine(indent, "Output Quality", pOle.OutputQuality);
1949
            dumpEntityData(pOle, indent, Program.xml.DocumentElement);
1950
        }
1951

    
1952
        /************************************************************************/
1953
        /* Point Dumper                                                         */
1954
        /************************************************************************/
1955
        void dump(DBPoint pPoint, int indent)
1956
        {
1957
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1958
            writeLine(indent, "Position", pPoint.Position);
1959
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1960
            writeLine(indent, "Normal", pPoint.Normal);
1961
            writeLine(indent, "Thickness", pPoint.Thickness);
1962
            dumpEntityData(pPoint, indent, Program.xml.DocumentElement);
1963
        }
1964

    
1965
        /************************************************************************/
1966
        /* Polygon Mesh Dumper                                                  */
1967
        /************************************************************************/
1968
        void dump(PolygonMesh pPoly, int indent)
1969
        {
1970
            writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1971
            writeLine(indent, "m Size", pPoly.MSize);
1972
            writeLine(indent, "m-Closed", pPoly.IsMClosed);
1973
            writeLine(indent, "m Surface Density", pPoly.MSurfaceDensity);
1974
            writeLine(indent, "n Size", pPoly.NSize);
1975
            writeLine(indent, "n-Closed", pPoly.IsNClosed);
1976
            writeLine(indent, "n Surface Density", pPoly.NSurfaceDensity);
1977
            /********************************************************************/
1978
            /* dump vertices                                                    */
1979
            /********************************************************************/
1980
            int vertexCount = 0;
1981
            foreach (object o in pPoly)
1982
            {
1983
                PolygonMeshVertex pVertex = o as PolygonMeshVertex;
1984
                if (pVertex != null)
1985
                {
1986
                    writeLine(indent, pVertex.GetRXClass().Name, vertexCount++);
1987
                    writeLine(indent + 1, "Handle", pVertex.Handle);
1988
                    writeLine(indent + 1, "Position", pVertex.Position);
1989
                    writeLine(indent + 1, "Type", pVertex.VertexType);
1990
                }
1991
            }
1992
            dumpEntityData(pPoly, indent, Program.xml.DocumentElement);
1993
        }
1994

    
1995
        /************************************************************************/
1996
        /* Polyline Dumper                                                      */
1997
        /************************************************************************/
1998
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
1999
        {
2000
            if (pPoly != null && pPoly.Length != 0)
2001
            {
2002
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
2003
                writeLine(indent, "Has Width", pPoly.HasWidth);
2004
                if (!pPoly.HasWidth)
2005
                {
2006
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
2007
                }
2008

    
2009
                /********************************************************************/
2010
                /* dump vertices                                                    */
2011
                /********************************************************************/
2012
                if (node != null)
2013
                {
2014
                    XmlNode PolylineNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
2015
                    XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
2016
                    LengthAttr.Value = pPoly.Length.ToString();
2017
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
2018

    
2019
                    XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
2020
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
2021
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
2022

    
2023
                    XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2024
                    HandleAttr.Value = pPoly.Handle.ToString();
2025
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
2026

    
2027
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
2028
                    ClosedAttr.Value = pPoly.Closed.ToString();
2029
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
2030

    
2031
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
2032
                    {
2033
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
2034

    
2035
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
2036
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
2037

    
2038
                        Point3d pt = pPoly.GetPoint3dAt(i);
2039
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
2040
                        XAttr.Value = pt.X.ToString();
2041
                        VertexNode.Attributes.SetNamedItem(XAttr);
2042

    
2043
                        XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
2044
                        YAttr.Value = pt.Y.ToString();
2045
                        VertexNode.Attributes.SetNamedItem(YAttr);
2046

    
2047
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
2048
                        ZAttr.Value = pt.Z.ToString();
2049
                        VertexNode.Attributes.SetNamedItem(ZAttr);
2050

    
2051
                        if (pPoly.HasWidth)
2052
                        {
2053
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
2054
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
2055
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
2056

    
2057
                            XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
2058
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
2059
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
2060
                        }
2061
                        if (pPoly.HasBulges)
2062
                        {
2063
                            XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
2064
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
2065
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
2066

    
2067
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2068
                            {
2069
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
2070
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2071
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2072
                            }
2073
                        }
2074

    
2075
                        PolylineNode.AppendChild(VertexNode);
2076
                    }
2077

    
2078
                    dumpEntityData(pPoly, indent, PolylineNode);
2079
                    node.AppendChild(PolylineNode);
2080
                }
2081
            }
2082
            else
2083
            {
2084
                int d = 0;
2085
            }
2086
        }
2087

    
2088
        class DrawContextDumper : Context
2089
        {
2090
            Database _db;
2091
            public DrawContextDumper(Database db)
2092
            {
2093
                _db = db;
2094
            }
2095
            public override Database Database
2096
            {
2097
                get { return _db; }
2098
            }
2099
            public override bool IsBoundaryClipping
2100
            {
2101
                get { return false; }
2102
            }
2103
            public override bool IsPlotGeneration
2104
            {
2105
                get { return false; }
2106
            }
2107
            public override bool IsPostScriptOut
2108
            {
2109
                get { return false; }
2110
            }
2111
        }
2112
        class SubEntityTraitsDumper : SubEntityTraits
2113
        {
2114
            short _color;
2115
            int _drawFlags;
2116
            FillType _ft;
2117
            ObjectId _layer;
2118
            ObjectId _linetype;
2119
            LineWeight _lineWeight;
2120
            Mapper _mapper;
2121
            double _lineTypeScale;
2122
            ObjectId _material;
2123
            PlotStyleDescriptor _plotStyleDescriptor;
2124
            bool _sectionable;
2125
            bool _selectionOnlyGeometry;
2126
            ShadowFlags _shadowFlags;
2127
            double _thickness;
2128
            EntityColor _trueColor;
2129
            Transparency _transparency;
2130
            ObjectId _visualStyle;
2131
            public SubEntityTraitsDumper(Database db)
2132
            {
2133
                _drawFlags = 0; // kNoDrawFlags 
2134
                _color = 0;
2135
                _ft = FillType.FillAlways;
2136
                _layer = db.Clayer;
2137
                _linetype = db.Celtype;
2138
                _lineWeight = db.Celweight;
2139
                _lineTypeScale = db.Celtscale;
2140
                _material = db.Cmaterial;
2141
                _shadowFlags = ShadowFlags.ShadowsIgnore;
2142
                _thickness = 0;
2143
                _trueColor = new EntityColor(ColorMethod.None);
2144
                _transparency = new Transparency();
2145
            }
2146

    
2147
            protected override void SetLayerFlags(LayerFlags flags)
2148
            {
2149
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2150
            }
2151
            public override void AddLight(ObjectId lightId)
2152
            {
2153
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2154
            }
2155
            public override void SetupForEntity(Entity entity)
2156
            {
2157
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2158
            }
2159

    
2160
            public override short Color
2161
            {
2162
                get { return _color; }
2163
                set { _color = value; }
2164
            }
2165
            public override int DrawFlags
2166
            {
2167
                get { return _drawFlags; }
2168
                set { _drawFlags = value; }
2169
            }
2170
            public override FillType FillType
2171
            {
2172
                get { return _ft; }
2173
                set { _ft = value; }
2174
            }
2175
            public override ObjectId Layer
2176
            {
2177
                get { return _layer; }
2178
                set { _layer = value; }
2179
            }
2180
            public override ObjectId LineType
2181
            {
2182
                get { return _linetype; }
2183
                set { _linetype = value; }
2184
            }
2185
            public override double LineTypeScale
2186
            {
2187
                get { return _lineTypeScale; }
2188
                set { _lineTypeScale = value; }
2189
            }
2190
            public override LineWeight LineWeight
2191
            {
2192
                get { return _lineWeight; }
2193
                set { _lineWeight = value; }
2194
            }
2195
            public override Mapper Mapper
2196
            {
2197
                get { return _mapper; }
2198
                set { _mapper = value; }
2199
            }
2200
            public override ObjectId Material
2201
            {
2202
                get { return _material; }
2203
                set { _material = value; }
2204
            }
2205
            public override PlotStyleDescriptor PlotStyleDescriptor
2206
            {
2207
                get { return _plotStyleDescriptor; }
2208
                set { _plotStyleDescriptor = value; }
2209
            }
2210
            public override bool Sectionable
2211
            {
2212
                get { return _sectionable; }
2213
                set { _sectionable = value; }
2214
            }
2215
            public override bool SelectionOnlyGeometry
2216
            {
2217
                get { return _selectionOnlyGeometry; }
2218
                set { _selectionOnlyGeometry = value; }
2219
            }
2220
            public override ShadowFlags ShadowFlags
2221
            {
2222
                get { return _shadowFlags; }
2223
                set { _shadowFlags = value; }
2224
            }
2225
            public override double Thickness
2226
            {
2227
                get { return _thickness; }
2228
                set { _thickness = value; }
2229
            }
2230
            public override EntityColor TrueColor
2231
            {
2232
                get { return _trueColor; }
2233
                set { _trueColor = value; }
2234
            }
2235
            public override Transparency Transparency
2236
            {
2237
                get { return _transparency; }
2238
                set { _transparency = value; }
2239
            }
2240
            public override ObjectId VisualStyle
2241
            {
2242
                get { return _visualStyle; }
2243
                set { _visualStyle = value; }
2244
            }
2245
            public override void SetSelectionMarker(IntPtr sm)
2246
            {
2247
            }
2248
        }
2249
        class WorldGeometryDumper : WorldGeometry
2250
        {
2251
            Stack<Matrix3d> modelMatrix;
2252
            Stack<ClipBoundary> clips;
2253
            int indent;
2254
            public WorldGeometryDumper(int indent)
2255
              : base()
2256
            {
2257
                this.indent = indent;
2258
                modelMatrix = new Stack<Matrix3d>();
2259
                clips = new Stack<ClipBoundary>();
2260
                modelMatrix.Push(Matrix3d.Identity);
2261
            }
2262
            public override Matrix3d ModelToWorldTransform
2263
            {
2264
                get { return modelMatrix.Peek(); }
2265
            }
2266
            public override Matrix3d WorldToModelTransform
2267
            {
2268
                get { return modelMatrix.Peek().Inverse(); }
2269
            }
2270

    
2271
            public override Matrix3d PushOrientationTransform(OrientationBehavior behavior)
2272
            {
2273
                writeLine(indent, string.Format("WorldGeometry.PushOrientationTransform(behavior = {0})", behavior));
2274
                return new Matrix3d();
2275
            }
2276
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point2d offset)
2277
            {
2278
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2279
                return new Matrix3d();
2280
            }
2281
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point3d offset)
2282
            {
2283
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2284
                return new Matrix3d();
2285
            }
2286
            public override bool OwnerDraw(GdiDrawObject gdiDrawObject, Point3d position, Vector3d u, Vector3d v)
2287
            {
2288
                writeLine(indent, string.Format("WorldGeometry.OwnerDraw(gdiDrawObject = {0}, position = {1}, u = {2}, v = {3})", gdiDrawObject, position, u, v));
2289
                return false;
2290
            }
2291
            public override bool Polyline(Teigha.GraphicsInterface.Polyline polylineObj)
2292
            {
2293
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}", polylineObj));
2294
                return false;
2295
            }
2296
            public override bool Polypoint(Point3dCollection points, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2297
            {
2298
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, normals = {1}, subentityMarkers = {2}", points, normals, subentityMarkers));
2299
                return false;
2300
            }
2301
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2302
            {
2303
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, normals = {2}, subentityMarkers = {3}", points, colors, normals, subentityMarkers));
2304
                return false;
2305
            }
2306
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, TransparencyCollection transparency, Vector3dCollection normals, IntPtrCollection subentityMarkers, int pointSize)
2307
            {
2308
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, transparency = {2}, normals = {3}, subentityMarkers = {4}, pointSize = {5}", points, colors, transparency, normals, subentityMarkers, pointSize));
2309
                return false;
2310
            }
2311
            public override bool PolyPolyline(Teigha.GraphicsInterface.PolylineCollection polylineCollection)
2312
            {
2313
                writeLine(indent, string.Format("WorldGeometry.PolyPolyline(polylineCollection = {0}", polylineCollection));
2314
                return false;
2315
            }
2316
            public override bool PolyPolygon(UInt32Collection numPolygonPositions, Point3dCollection polygonPositions, UInt32Collection numPolygonPoints, Point3dCollection polygonPoints, EntityColorCollection outlineColors, LinetypeCollection outlineTypes, EntityColorCollection fillColors, Teigha.Colors.TransparencyCollection fillOpacities)
2317
            {
2318
                writeLine(indent, string.Format("WorldGeometry.PolyPolygon(numPolygonPositions = {0}, polygonPositions = {1}, numPolygonPoints = {2}, polygonPoints = {3}, outlineColors = {4}, outlineTypes = {5}, fillColors = {6}, fillOpacities = {7})", numPolygonPositions, polygonPositions, numPolygonPoints, polygonPoints, outlineColors, outlineTypes, fillColors, fillOpacities));
2319
                return false;
2320
            }
2321
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point2d extents)
2322
            {
2323
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2324
                return new Matrix3d();
2325
            }
2326
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point3d extents)
2327
            {
2328
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2329
                return new Matrix3d();
2330
            }
2331
            public override bool EllipticalArc(Point3d center, Vector3d normal, double majorAxisLength, double minorAxisLength, double startDegreeInRads, double endDegreeInRads, double tiltDegreeInRads, ArcType arType)
2332
            {
2333
                writeLine(indent, string.Format("WorldGeometry.EllipticalArc(center = {0}, normal = {1}, majorAxisLength = {2}, minorAxisLength = {3}, startDegreeInRads = {4}, endDegreeInRads = {5}, tiltDegreeInRads = {6}, arType = {7}", center, normal, majorAxisLength, minorAxisLength, startDegreeInRads, endDegreeInRads, tiltDegreeInRads, arType));
2334
                return false;
2335
            }
2336
            public override bool Circle(Point3d center, double radius, Vector3d normal)
2337
            {
2338
                writeLine(indent, string.Format("WorldGeometry.Circle(center = {0}, radius = {1}, normal = {2})", center, radius, normal));
2339
                return false;
2340
            }
2341
            public override bool Circle(Point3d firstPoint, Point3d secondPoint, Point3d thirdPoint)
2342
            {
2343
                writeLine(indent, string.Format("WorldGeometry.Circle(firstPoint = {0}, secondPoint = {1}, thirdPoint = {2})", firstPoint, secondPoint, thirdPoint));
2344
                return false;
2345
            }
2346
            public override bool CircularArc(Point3d start, Point3d point, Point3d endingPoint, ArcType arcType)
2347
            {
2348
                writeLine(indent, string.Format("WorldGeometry.CircularArc(start = {0}, point = {1}, endingPoint = {2}, arcType = {3})", start, point, endingPoint, arcType));
2349
                return false;
2350
            }
2351
            public override bool CircularArc(Point3d center, double radius, Vector3d normal, Vector3d startVector, double sweepAngle, ArcType arcType)
2352
            {
2353
                writeLine(indent, string.Format("WorldGeometry.CircularArc(center = {0}, radius = {1}, normal = {2}, startVector = {3}, sweepAngle = {4}, arcType = {5}", center, radius, normal, startVector, sweepAngle, arcType));
2354
                return false;
2355
            }
2356
            public override bool Draw(Drawable value)
2357
            {
2358
                writeLine(indent, string.Format("WorldGeometry.Draw(value = {0}", value));
2359
                return false;
2360
            }
2361
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v)
2362
            {
2363
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}", position, u, v));
2364
                return false;
2365
            }
2366
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v, TransparencyMode transparencyMode)
2367
            {
2368
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}, transparencyMode = {4}", position, u, v, transparencyMode));
2369
                return false;
2370
            }
2371
            public override bool Mesh(int rows, int columns, Point3dCollection points, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2372
            {
2373
                writeLine(indent, string.Format("WorldGeometry.Mesh(rows = {0}, columns = {1}, points = {2}, edgeData = {3}, faceData = {4}, vertexData = {5}, bAutoGenerateNormals = {6})", rows, columns, points, edgeData, faceData, vertexData, bAutoGenerateNormals));
2374
                return false;
2375
            }
2376
            public override bool Polygon(Point3dCollection points)
2377
            {
2378
                writeLine(indent, string.Format("WorldGeometry.Polygon(points = {0})", points));
2379
                return false;
2380
            }
2381
            public override bool Polyline(Teigha.DatabaseServices.Polyline value, int fromIndex, int segments)
2382
            {
2383
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}, fromIndex = {1}, segments = {2})", value, fromIndex, segments));
2384
                return false;
2385
            }
2386
            public override bool Polyline(Point3dCollection points, Vector3d normal, IntPtr subEntityMarker)
2387
            {
2388
                writeLine(indent, string.Format("WorldGeometry.Polyline(points = {0}, normal = {1}, subEntityMarker = {2})", points, normal, subEntityMarker));
2389
                return false;
2390
            }
2391
            public override void PopClipBoundary()
2392
            {
2393
                writeLine(indent, string.Format("WorldGeometry.PopClipBoundary"));
2394
                clips.Pop();
2395
            }
2396
            public override bool PopModelTransform()
2397
            {
2398
                return true;
2399
            }
2400
            public override bool PushClipBoundary(ClipBoundary boundary)
2401
            {
2402
                writeLine(indent, string.Format("WorldGeometry.PushClipBoundary"));
2403
                clips.Push(boundary);
2404
                return true;
2405
            }
2406
            public override bool PushModelTransform(Matrix3d matrix)
2407
            {
2408
                writeLine(indent, "WorldGeometry.PushModelTransform(Matrix3d)");
2409
                Matrix3d m = modelMatrix.Peek();
2410
                modelMatrix.Push(m * matrix);
2411
                return true;
2412
            }
2413
            public override bool PushModelTransform(Vector3d normal)
2414
            {
2415
                writeLine(indent, "WorldGeometry.PushModelTransform(Vector3d)");
2416
                PushModelTransform(Matrix3d.PlaneToWorld(normal));
2417
                return true;
2418
            }
2419
            public override bool RowOfDots(int count, Point3d start, Vector3d step)
2420
            {
2421
                writeLine(indent, string.Format("ViewportGeometry.RowOfDots(count = {0}, start = {1}, step = {1})", count, start, step));
2422
                return false;
2423
            }
2424
            public override bool Ray(Point3d point1, Point3d point2)
2425
            {
2426
                writeLine(indent, string.Format("WorldGeometry.Ray(point1 = {0}, point2 = {1})", point1, point2));
2427
                return false;
2428
            }
2429
            public override bool Shell(Point3dCollection points, IntegerCollection faces, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2430
            {
2431
                writeLine(indent, string.Format("WorldGeometry.Shell(points = {0}, faces = {1}, edgeData = {2}, faceData = {3}, vertexData = {4}, bAutoGenerateNormals = {5})", points, faces, edgeData, faceData, vertexData, bAutoGenerateNormals));
2432
                return false;
2433
            }
2434
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, string message, bool raw, TextStyle textStyle)
2435
            {
2436
                writeLine(indent, string.Format("WorldGeometry.Text(position = {0}, normal = {1}, direction = {2}, message = {3}, raw = {4}, textStyle = {5})", position, normal, direction, message, raw, textStyle));
2437
                return false;
2438
            }
2439
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, double height, double width, double oblique, string message)
2440
            {
2441
                writeLine(indent, string.Format("WorldGeometry.Text(position = {0}, normal = {1}, direction = {2}, height = {3}, width = {4}, oblique = {5}, message = {6})", position, normal, direction, height, width, oblique, message));
2442
                return false;
2443
            }
2444
            public override bool WorldLine(Point3d startPoint, Point3d endPoint)
2445
            {
2446
                writeLine(indent, string.Format("WorldGeometry.WorldLine(startPoint = {0}, endPoint = {1})", startPoint, endPoint));
2447
                return false;
2448
            }
2449
            public override bool Xline(Point3d point1, Point3d point2)
2450
            {
2451
                writeLine(indent, string.Format("WorldGeometry.Xline(point1 = {0}, point2 = {1})", point1, point2));
2452
                return false;
2453
            }
2454

    
2455
            public override void SetExtents(Extents3d extents)
2456
            {
2457
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2458
            }
2459
            public override void StartAttributesSegment()
2460
            {
2461
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2462
            }
2463
        }
2464

    
2465
        class WorldDrawDumper : WorldDraw
2466
        {
2467
            WorldGeometryDumper _geom;
2468
            DrawContextDumper _ctx;
2469
            SubEntityTraits _subents;
2470
            RegenType _regenType;
2471
            int indent;
2472
            public WorldDrawDumper(Database db, int indent)
2473
              : base()
2474
            {
2475
                _regenType = RegenType;
2476
                this.indent = indent;
2477
                _geom = new WorldGeometryDumper(indent);
2478
                _ctx = new DrawContextDumper(db);
2479
                _subents = new SubEntityTraitsDumper(db);
2480
            }
2481
            public override double Deviation(DeviationType deviationType, Point3d pointOnCurve)
2482
            {
2483
                return 1e-9;
2484
            }
2485
            public override WorldGeometry Geometry
2486
            {
2487
                get
2488
                {
2489
                    return _geom;
2490
                }
2491
            }
2492
            public override bool IsDragging
2493
            {
2494
                get
2495
                {
2496
                    return false;
2497
                }
2498
            }
2499
            public override Int32 NumberOfIsolines
2500
            {
2501
                get
2502
                {
2503
                    return 10;
2504
                }
2505
            }
2506
            public override Geometry RawGeometry
2507
            {
2508
                get
2509
                {
2510
                    return _geom;
2511
                }
2512
            }
2513
            public override bool RegenAbort
2514
            {
2515
                get
2516
                {
2517
                    return false;
2518
                }
2519
            }
2520
            public override RegenType RegenType
2521
            {
2522
                get
2523
                {
2524
                    writeLine(indent, "RegenType is asked");
2525
                    return _regenType;
2526
                }
2527
            }
2528
            public override SubEntityTraits SubEntityTraits
2529
            {
2530
                get
2531
                {
2532
                    return _subents;
2533
                }
2534
            }
2535
            public override Context Context
2536
            {
2537
                get
2538
                {
2539
                    return _ctx;
2540
                }
2541
            }
2542
        }
2543

    
2544
        /************************************************************************/
2545
        /* Dump the common data and WorldDraw information for all               */
2546
        /* entities without explicit dumpers                                    */
2547
        /************************************************************************/
2548
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2549
        {
2550
            if (node != null)
2551
            {
2552
                XmlElement EntNode = Program.xml.CreateElement(pEnt.GetRXClass().Name);
2553

    
2554
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2555
                HandleAttr.Value = pEnt.Handle.ToString();
2556
                EntNode.Attributes.SetNamedItem(HandleAttr);
2557

    
2558
                dumpEntityData(pEnt, indent, EntNode);
2559
                using (Database db = pEnt.Database)
2560
                {
2561
                    /**********************************************************************/
2562
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2563
                    /**********************************************************************/
2564
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2565
                    /**********************************************************************/
2566
                    /* Call worldDraw()                                                   */
2567
                    /**********************************************************************/
2568
                    pEnt.WorldDraw(wd);
2569
                }
2570

    
2571
                node.AppendChild(EntNode);
2572

    
2573
                return EntNode;
2574
            }
2575

    
2576
            return null;
2577
        }
2578

    
2579
        /************************************************************************/
2580
        /* Proxy Entity Dumper                                                  */
2581
        /************************************************************************/
2582
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2583
        {
2584
            if (node != null)
2585
            {
2586
                XmlElement ProxyNode = Program.xml.CreateElement(pProxy.GetRXClass().Name);
2587

    
2588
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2589
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2590
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2591

    
2592
                // this will dump proxy entity graphics
2593
                dump((Entity)pProxy, indent, node);
2594

    
2595
                DBObjectCollection collection = new DBObjectCollection(); ;
2596
                try
2597
                {
2598
                    pProxy.ExplodeGeometry(collection);
2599
                }
2600
                catch (System.Exception)
2601
                {
2602
                    return null;
2603
                }
2604

    
2605
                foreach (Entity ent in collection)
2606
                {
2607
                    if (ent is Polyline2d)
2608
                    {
2609
                        Polyline2d pline2d = (Polyline2d)ent;
2610
                        int i = 0;
2611

    
2612
                        try
2613
                        {
2614
                            foreach (Entity ent1 in pline2d)
2615
                            {
2616
                                if (ent1 is Vertex2d)
2617
                                {
2618
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2619
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2620
                                }
2621
                            }
2622
                        }
2623
                        catch (System.Exception)
2624
                        {
2625
                            return null;
2626
                        }
2627
                    }
2628
                }
2629

    
2630
                node.AppendChild(ProxyNode);
2631
                return ProxyNode;
2632
            }
2633

    
2634
            return null;
2635
        }
2636

    
2637
        /************************************************************************/
2638
        /* Radial Dimension Dumper                                              */
2639
        /************************************************************************/
2640
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2641
        {
2642
            if (node != null)
2643
            {
2644
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2645

    
2646
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2647
                HandleAttr.Value = pDim.Handle.ToString();
2648
                DimNode.Attributes.SetNamedItem(HandleAttr);
2649

    
2650
                XmlAttribute CenterAttr = Program.xml.CreateAttribute("Center");
2651
                CenterAttr.Value = pDim.Center.ToString();
2652
                DimNode.Attributes.SetNamedItem(CenterAttr);
2653

    
2654
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
2655
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
2656
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
2657

    
2658
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
2659
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2660
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2661

    
2662
                dumpDimData(pDim, indent, DimNode);
2663

    
2664
                node.AppendChild(DimNode);
2665

    
2666
                return DimNode;
2667
            }
2668

    
2669
            return null;
2670
        }
2671

    
2672
        /************************************************************************/
2673
        /* Dump Raster Image Def                                               */
2674
        /************************************************************************/
2675
        void dumpRasterImageDef(ObjectId id, int indent)
2676
        {
2677
            if (!id.IsValid)
2678
                return;
2679
            using (RasterImageDef pDef = (RasterImageDef)id.Open(OpenMode.ForRead))
2680
            {
2681
                writeLine(indent++, pDef.GetRXClass().Name, pDef.Handle);
2682
                writeLine(indent, "Source Filename", shortenPath(pDef.SourceFileName));
2683
                writeLine(indent, "Loaded", pDef.IsLoaded);
2684
                writeLine(indent, "mm per Pixel", pDef.ResolutionMMPerPixel);
2685
                writeLine(indent, "Loaded", pDef.IsLoaded);
2686
                writeLine(indent, "Resolution Units", pDef.ResolutionUnits);
2687
                writeLine(indent, "Size", pDef.Size);
2688
            }
2689
        }
2690
        /************************************************************************/
2691
        /* Dump Raster Image Data                                               */
2692
        /************************************************************************/
2693
        void dumpRasterImageData(RasterImage pImage, int indent)
2694
        {
2695
            writeLine(indent, "Brightness", pImage.Brightness);
2696
            writeLine(indent, "Clipped", pImage.IsClipped);
2697
            writeLine(indent, "Contrast", pImage.Contrast);
2698
            writeLine(indent, "Fade", pImage.Fade);
2699
            writeLine(indent, "kClip", pImage.DisplayOptions & ImageDisplayOptions.Clip);
2700
            writeLine(indent, "kShow", pImage.DisplayOptions & ImageDisplayOptions.Show);
2701
            writeLine(indent, "kShowUnAligned", pImage.DisplayOptions & ImageDisplayOptions.ShowUnaligned);
2702
            writeLine(indent, "kTransparent", pImage.DisplayOptions & ImageDisplayOptions.Transparent);
2703
            writeLine(indent, "Scale", pImage.Scale);
2704

    
2705
            /********************************************************************/
2706
            /* Dump clip boundary                                               */
2707
            /********************************************************************/
2708
            if (pImage.IsClipped)
2709
            {
2710
                writeLine(indent, "Clip Boundary Type", pImage.ClipBoundaryType);
2711
                if (pImage.ClipBoundaryType != ClipBoundaryType.Invalid)
2712
                {
2713
                    Point2dCollection pt = pImage.GetClipBoundary();
2714
                    for (int i = 0; i < pt.Count; i++)
2715
                    {
2716
                        writeLine(indent, string.Format("Clip Point {0}", i), pt[i]);
2717
                    }
2718
                }
2719
            }
2720

    
2721
            /********************************************************************/
2722
            /* Dump frame                                                       */
2723
            /********************************************************************/
2724
            Point3dCollection vertices = pImage.GetVertices();
2725
            for (int i = 0; i < vertices.Count; i++)
2726
            {
2727
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2728
            }
2729

    
2730
            /********************************************************************/
2731
            /* Dump orientation                                                 */
2732
            /********************************************************************/
2733
            writeLine(indent, "Orientation");
2734
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2735
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2736
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2737
            dumpRasterImageDef(pImage.ImageDefId, indent);
2738
            dumpEntityData(pImage, indent, Program.xml.DocumentElement);
2739
        }
2740

    
2741
        /************************************************************************/
2742
        /* Raster Image Dumper                                                  */
2743
        /************************************************************************/
2744
        void dump(RasterImage pImage, int indent)
2745
        {
2746
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2747
            writeLine(indent, "Image size", pImage.ImageSize(true));
2748
            dumpRasterImageData(pImage, indent);
2749
        }
2750

    
2751
        /************************************************************************/
2752
        /* Ray Dumper                                                          */
2753
        /************************************************************************/
2754
        void dump(Ray pRay, int indent)
2755
        {
2756
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2757
            writeLine(indent, "Base Point", pRay.BasePoint);
2758
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2759
            dumpCurveData(pRay, indent, Program.xml.DocumentElement);
2760
        }
2761

    
2762
        /************************************************************************/
2763
        /* Region Dumper                                                        */
2764
        /************************************************************************/
2765
        void dump(Region pRegion, int indent)
2766
        {
2767
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2768
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2769
        }
2770

    
2771
        /************************************************************************/
2772
        /* Rotated Dimension Dumper                                             */
2773
        /************************************************************************/
2774
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2775
        {
2776
            if (node != null)
2777
            {
2778
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2779

    
2780
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2781
                HandleAttr.Value = pDim.Handle.ToString();
2782
                DimNode.Attributes.SetNamedItem(HandleAttr);
2783

    
2784
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
2785
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2786
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2787

    
2788
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
2789
                ObliqueAttr.Value = pDim.Oblique.ToString();
2790
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2791

    
2792
                XmlAttribute RotationAttr = Program.xml.CreateAttribute("Rotation");
2793
                RotationAttr.Value = pDim.Rotation.ToString();
2794
                DimNode.Attributes.SetNamedItem(RotationAttr);
2795

    
2796
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
2797
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2798
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2799

    
2800
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2801
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2802
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2803

    
2804
                dumpDimData(pDim, indent, DimNode);
2805
                node.AppendChild(DimNode);
2806

    
2807
                return DimNode;
2808
            }
2809

    
2810
            return null;
2811
        }
2812

    
2813
        /************************************************************************/
2814
        /* Shape Dumper                                                          */
2815
        /************************************************************************/
2816
        void dump(Shape pShape, int indent)
2817
        {
2818
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2819

    
2820
            if (!pShape.StyleId.IsNull)
2821
            {
2822
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2823
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2824
            }
2825

    
2826
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2827
            writeLine(indent, "Shape Name", pShape.Name);
2828
            writeLine(indent, "Position", pShape.Position);
2829
            writeLine(indent, "Size", pShape.Size);
2830
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2831
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2832
            writeLine(indent, "Normal", pShape.Normal);
2833
            writeLine(indent, "Thickness", pShape.Thickness);
2834
            dumpEntityData(pShape, indent, Program.xml.DocumentElement);
2835
        }
2836

    
2837
        /************************************************************************/
2838
        /* Solid Dumper                                                         */
2839
        /************************************************************************/
2840
        // TODO:
2841
        /*  void dump(Solid pSolid, int indent)
2842
      {
2843
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2844

    
2845
        for (int i = 0; i < 4; i++)
2846
        {
2847
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2848
        }
2849
        dumpEntityData(pSolid, indent);
2850
      }
2851
    */
2852
        /************************************************************************/
2853
        /* Spline Dumper                                                        */
2854
        /************************************************************************/
2855
        void dump(Spline pSpline, int indent)
2856
        {
2857
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2858

    
2859
            NurbsData data = pSpline.NurbsData;
2860
            writeLine(indent, "Degree", data.Degree);
2861
            writeLine(indent, "Rational", data.Rational);
2862
            writeLine(indent, "Periodic", data.Periodic);
2863
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2864
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2865

    
2866
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2867
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2868
            {
2869
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2870
            }
2871

    
2872
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2873
            for (int i = 0; i < data.GetKnots().Count; i++)
2874
            {
2875
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2876
            }
2877

    
2878
            if (data.Rational)
2879
            {
2880
                writeLine(indent, "Number of Weights", data.GetWeights().Count);
2881
                for (int i = 0; i < data.GetWeights().Count; i++)
2882
                {
2883
                    writeLine(indent, "Weight " + i.ToString(), data.GetWeights()[i]);
2884
                }
2885
            }
2886
            dumpCurveData(pSpline, indent, Program.xml.DocumentElement);
2887
        }
2888
        /************************************************************************/
2889
        /* Table Dumper                                                         */
2890
        /************************************************************************/
2891
        void dump(Table pTable, int indent)
2892
        {
2893
            writeLine(indent++, pTable.GetRXClass().Name, pTable.Handle);
2894
            writeLine(indent, "Position", pTable.Position);
2895
            writeLine(indent, "X-Direction", pTable.Direction);
2896
            writeLine(indent, "Normal", pTable.Normal);
2897
            writeLine(indent, "Height", (int)pTable.Height);
2898
            writeLine(indent, "Width", (int)pTable.Width);
2899
            writeLine(indent, "Rows", (int)pTable.NumRows);
2900
            writeLine(indent, "Columns", (int)pTable.NumColumns);
2901

    
2902
            // TODO:
2903
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2904
            //writeLine(indent, "Table Style",               pStyle.Name);
2905
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2906
        }
2907

    
2908
        /************************************************************************/
2909
        /* Text Dumper                                                          */
2910
        /************************************************************************/
2911
        static void dump(DBText pText, int indent, XmlNode node)
2912
        {
2913
            if (node != null)
2914
            {
2915
                dumpTextData(pText, indent, node);
2916
            }
2917
        }
2918
        /************************************************************************/
2919
        /* Trace Dumper                                                         */
2920
        /************************************************************************/
2921
        void dump(Trace pTrace, int indent)
2922
        {
2923
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2924

    
2925
            for (short i = 0; i < 4; i++)
2926
            {
2927
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2928
            }
2929
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2930
        }
2931

    
2932
        /************************************************************************/
2933
        /* Trace UnderlayReference                                                         */
2934
        /************************************************************************/
2935
        void dump(UnderlayReference pEnt, int indent)
2936
        {
2937
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2938
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2939
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2940
        }
2941

    
2942
        /************************************************************************/
2943
        /* Viewport Dumper                                                       */
2944
        /************************************************************************/
2945
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2946
        {
2947
            if (node != null)
2948
            {
2949
                XmlElement VportNode = Program.xml.CreateElement(pVport.GetRXClass().Name);
2950

    
2951
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2952
                HandleAttr.Value = pVport.Handle.ToString();
2953
                VportNode.Attributes.SetNamedItem(HandleAttr);
2954

    
2955
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2956
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2957
                writeLine(indent, "Center Point", pVport.CenterPoint);
2958
                writeLine(indent, "Circle sides", pVport.CircleSides);
2959
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2960
                writeLine(indent, "Elevation", pVport.Elevation);
2961
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2962
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2963
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2964
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2965

    
2966
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2967
                if (layerIds.Count > 0)
2968
                {
2969
                    writeLine(indent, "Frozen Layers:");
2970
                    for (int i = 0; i < layerIds.Count; i++)
2971
                    {
2972
                        writeLine(indent + 1, i, layerIds[i]);
2973
                    }
2974
                }
2975
                else
2976
                {
2977
                    writeLine(indent, "Frozen Layers", "None");
2978
                }
2979

    
2980
                Point3d origin = new Point3d();
2981
                Vector3d xAxis = new Vector3d();
2982
                Vector3d yAxis = new Vector3d();
2983
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
2984
                writeLine(indent, "UCS origin", origin);
2985
                writeLine(indent, "UCS x-Axis", xAxis);
2986
                writeLine(indent, "UCS y-Axis", yAxis);
2987
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
2988
                writeLine(indent, "Grid On", pVport.GridOn);
2989
                writeLine(indent, "Height", pVport.Height);
2990
                writeLine(indent, "Lens Length", pVport.LensLength);
2991
                writeLine(indent, "Locked", pVport.Locked);
2992
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
2993

    
2994
                if (!pVport.NonRectClipEntityId.IsNull)
2995
                {
2996
                    writeLine(indent, "Non-rectangular Clipper", pVport.NonRectClipEntityId.Handle);
2997
                }
2998
                writeLine(indent, "Render Mode", pVport.RenderMode);
2999
                writeLine(indent, "Remove Hidden Lines", pVport.HiddenLinesRemoved);
3000
                writeLine(indent, "Shade Plot", pVport.ShadePlot);
3001
                writeLine(indent, "Snap Isometric", pVport.SnapIsometric);
3002
                writeLine(indent, "Snap On", pVport.SnapOn);
3003
                writeLine(indent, "Transparent", pVport.Transparent);
3004
                writeLine(indent, "UCS Follow", pVport.UcsFollowModeOn);
3005
                writeLine(indent, "UCS Icon at Origin", pVport.UcsIconAtOrigin);
3006

    
3007
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
3008
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
3009

    
3010
                if (!pVport.UcsName.IsNull)
3011
                {
3012
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
3013
                        writeLine(indent, "UCS Name", pUCS.Name);
3014
                }
3015
                else
3016
                {
3017
                    writeLine(indent, "UCS Name", "Null");
3018
                }
3019

    
3020
                writeLine(indent, "View Center", pVport.ViewCenter);
3021
                writeLine(indent, "View Height", pVport.ViewHeight);
3022
                writeLine(indent, "View Target", pVport.ViewTarget);
3023
                writeLine(indent, "Width", pVport.Width);
3024
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
3025

    
3026
                {
3027
                    using (DBObjectCollection collection = new DBObjectCollection())
3028
                    {
3029
                        try
3030
                        {
3031
                            pVport.ExplodeGeometry(collection);
3032

    
3033
                            foreach (Entity ent in collection)
3034
                            {
3035
                                if (ent is Polyline2d)
3036
                                {
3037
                                    Polyline2d pline2d = (Polyline2d)ent;
3038
                                    int i = 0;
3039
                                    foreach (Entity ent1 in pline2d)
3040
                                    {
3041
                                        if (ent1 is Vertex2d)
3042
                                        {
3043
                                            Vertex2d vtx2d = (Vertex2d)ent1;
3044
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
3045
                                        }
3046
                                    }
3047
                                }
3048
                            }
3049
                        }
3050
                        catch (System.Exception)
3051
                        {
3052
                        }
3053
                    }
3054
                }
3055

    
3056
                node.AppendChild(VportNode);
3057
                return VportNode;
3058
            }
3059

    
3060
            return null;
3061
        }
3062

    
3063
        /************************************************************************/
3064
        /* Wipeout Dumper                                                  */
3065
        /************************************************************************/
3066
        void dump(Wipeout pWipeout, int indent)
3067
        {
3068
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3069
            dumpRasterImageData(pWipeout, indent);
3070
        }
3071

    
3072
        /************************************************************************/
3073
        /* Xline Dumper                                                         */
3074
        /************************************************************************/
3075
        void dump(Xline pXline, int indent)
3076
        {
3077
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
3078
            writeLine(indent, "Base Point", pXline.BasePoint);
3079
            writeLine(indent, "Unit Direction", pXline.UnitDir);
3080
            dumpCurveData(pXline, indent, Program.xml.DocumentElement);
3081
        }
3082

    
3083
        public void dump(Database pDb, int indent, XmlNode node)
3084
        {
3085
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3086
            {
3087
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
3088
                {
3089
                    string layoutName = "";
3090
                    layoutName = pLayout.LayoutName;
3091

    
3092
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
3093
                    LayoutNameAttr.Value = layoutName;
3094
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3095
                }
3096
            }
3097

    
3098
            dumpHeader(pDb, indent, node);
3099
            dumpLayers(pDb, indent, node);
3100
            dumpLinetypes(pDb, indent, node);
3101
            dumpTextStyles(pDb, indent, node);
3102
            dumpDimStyles(pDb, indent, node);
3103
            dumpRegApps(pDb, indent);
3104
            dumpViewports(pDb, indent, node);
3105
            dumpViews(pDb, indent, node);
3106
            dumpMLineStyles(pDb, indent);
3107
            dumpUCSTable(pDb, indent, node);
3108
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3109

    
3110
            dumpBlocks(pDb, indent, node);
3111
        }
3112

    
3113
        /************************************************************************/
3114
        /* Export DWG to PDF                                                    */
3115
        /************************************************************************/
3116
        public void ExportPDF(Database pDb, string filePath)
3117
        {
3118
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3119
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3120
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3121

    
3122
            using (mPDFExportParams param = new mPDFExportParams())
3123
            {
3124
                param.Database = pDb;
3125

    
3126
                TransactionManager tm = pDb.TransactionManager;
3127
                using (Transaction ta = tm.StartTransaction())
3128
                {
3129
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3130
                    {
3131
                        param.OutputStream = fileStrem;
3132

    
3133
                        bool embededTTF = false;
3134
                        bool shxTextAsGeometry = true;
3135
                        bool ttfGeometry = true;
3136
                        bool simpleGeomOptimization = false;
3137
                        bool zoomToExtentsMode = true;
3138
                        bool enableLayers = false;
3139
                        bool includeOffLayers = false;
3140
                        bool enablePrcMode = true;
3141
                        bool monochrome = true;
3142
                        bool allLayout = false;
3143
                        double paperWidth = 841;
3144
                        double paperHeight = 594;
3145

    
3146
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3147
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3148
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3149
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3150
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3151
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3152
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3153

    
3154
                        param.Title = "";
3155
                        param.Author = "";
3156
                        param.Subject = "";
3157
                        param.Keywords = "";
3158
                        param.Creator = "";
3159
                        param.Producer = "";
3160
                        param.UseHLR = !enablePrcMode;
3161
                        param.FlateCompression = true;
3162
                        param.ASCIIHEXEncodeStream = true;
3163
                        param.hatchDPI = 720;
3164

    
3165
                        bool bV15 = enableLayers || includeOffLayers;
3166
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3167

    
3168
                        if (enablePrcMode)
3169
                        {
3170
                            Module pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcModule", false, false);
3171
                            if (pModule != null)
3172
                            {
3173
                                pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcExport", false, false);
3174
                            }
3175
                            if (pModule != null)
3176
                            {
3177
                                RXObject pObj = null;
3178
                                bool bUsePRCSingleViewMode = true; // provide a corresponding checkbox in Export to PDF dialog similar to one in OdaMfcApp
3179
                                if (bUsePRCSingleViewMode)
3180
                                {
3181
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_AllInSingleView");
3182
                                }
3183
                                else
3184
                                {
3185
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_Default");
3186
                                }
3187
                                if (pObj != null)
3188
                                {
3189
                                    RXClass pCls = (RXClass)pObj;
3190
                                    if (pCls != null)
3191
                                    {
3192
                                        param.PRCContext = pCls.Create();
3193
                                        param.PRCMode = PRCSupport.AsBrep; //(bUsePRCAsBRep == TRUE ? PRCSupport.AsBrep : PRCSupport.AsMesh);
3194
                                    }
3195
                                    else
3196
                                    {
3197
                                        Console.WriteLine("PDF Export, PRC support - RXClass failed");
3198
                                    }
3199
                                }
3200
                                else
3201
                                {
3202
                                    Console.WriteLine("PDF Export, PRC support - context failed");
3203
                                }
3204
                            }
3205
                            else
3206
                            {
3207
                                Console.WriteLine("PRC module was not loaded", "Error");
3208
                            }
3209
                        }
3210

    
3211
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3212

    
3213
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3214
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3215

    
3216
                        StringCollection strColl = new StringCollection();
3217
                        if (allLayout)
3218
                        {
3219
                            using (DBDictionary layouts = (DBDictionary)pDb.LayoutDictionaryId.GetObject(OpenMode.ForRead))
3220
                            {
3221
                                foreach (DBDictionaryEntry entry in layouts)
3222
                                {
3223
                                    if ("Model" == entry.Key)
3224
                                        strColl.Insert(0, entry.Key);
3225
                                    else
3226
                                        strColl.Add(entry.Key);
3227
                                    if (-1 != iIndexStyle)
3228
                                    {
3229
                                        PlotSettings ps = (PlotSettings)ta.GetObject(entry.Value, OpenMode.ForWrite);
3230
                                        plotSettingVal.SetCurrentStyleSheet(ps, styleCol[iIndexStyle]);
3231
                                    }
3232
                                }
3233
                            }
3234
                        }
3235
                        else if (-1 != iIndexStyle)
3236
                        {
3237
                            using (BlockTableRecord paperBTR = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3238
                            {
3239
                                using (PlotSettings pLayout = (PlotSettings)paperBTR.LayoutId.GetObject(OpenMode.ForWrite))
3240
                                {
3241
                                    plotSettingVal.SetCurrentStyleSheet(pLayout, styleCol[iIndexStyle]);
3242
                                }
3243
                            }
3244
                        }
3245
                        param.Layouts = strColl;
3246

    
3247
                        int nPages = Math.Max(1, strColl.Count);
3248
                        PageParamsCollection pParCol = new PageParamsCollection();
3249
                        for (int i = 0; i < nPages; ++i)
3250
                        {
3251
                            PageParams pp = new PageParams();
3252
                            pp.setParams(paperWidth, paperHeight);
3253
                            pParCol.Add(pp);
3254
                        }
3255
                        param.PageParams = pParCol;
3256
                        Export_Import.ExportPDF(param);
3257
                    }
3258
                    ta.Abort();
3259
                }
3260
            }
3261
        }
3262

    
3263
        /************************************************************************/
3264
        /* Export DWG to PNG                                                    */
3265
        /************************************************************************/
3266
        public void ExportPNG(Database pDb, string filePath)
3267
        {
3268
            chageColorAllObjects(pDb);
3269

    
3270
            string gdPath = "WinOpenGL_20.5_15.txv";
3271

    
3272
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3273
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3274
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3275
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3276

    
3277
            using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3278
            {
3279
                if (gsModule == null)
3280
                {
3281
                    Console.WriteLine("\nCould not load graphics module {0} \nExport cancelled.", gdPath);
3282
                    return;
3283
                }
3284

    
3285
                // create graphics device
3286
                using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3287
                {
3288
                    // setup device properties
3289
                    using (Dictionary props = dev.Properties)
3290
                    {
3291
                        props.AtPut("BitPerPixel", new RxVariant(32));
3292
                    }
3293
                    using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3294
                    {
3295
                        ctx.PaletteBackground = System.Drawing.Color.White;
3296
                        ctx.SetPlotGeneration(true);
3297

    
3298
                        using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3299
                        {
3300
                            helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3301
                            int width = 9600;
3302
                            int height = 6787;
3303
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
3304
                            helperDevice.OnSize(rect);
3305

    
3306
                            if (ctx.IsPlotGeneration)
3307
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3308
                            else
3309
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3310

    
3311
                            helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3312
                            helperDevice.ActiveView.Zoom(0.99);
3313
                            helperDevice.Update();
3314

    
3315
                            Export_Import.ExportBitmap(helperDevice, bmpPath);
3316
                        }
3317
                    }
3318
                }
3319
            }
3320

    
3321
            if (File.Exists(bmpPath))
3322
            {
3323
                if (File.Exists(pngPath))
3324
                {
3325
                    File.Delete(pngPath);
3326
                }
3327

    
3328
                ////bmp => grayscale bmp => png
3329
                //using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3330
                //{
3331
                //    System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height);
3332
                //    //get a graphics object from the new image
3333
                //    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
3334
                //    {
3335
                //        //create the grayscale ColorMatrix
3336
                //        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][]
3337
                //        {
3338
                //            new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
3339
                //            new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
3340
                //            new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
3341
                //            new float[] { 0,      0,      0,      1, 0 },
3342
                //            new float[] { 0,      0,      0,      0, 1 }
3343
                //        });
3344

    
3345
                //        //create some image attributes
3346
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3347
                //        {
3348
                //            //set the color matrix attribute
3349
                //            attributes.SetColorMatrix(colorMatrix);
3350
                //            //attributes.SetThreshold(0.8F);
3351

    
3352
                //            //draw the original image on the new image
3353
                //            //using the grayscale color matrix
3354
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3355
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3356
                //        }
3357

    
3358
                //    }
3359
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3360
                //}
3361

    
3362
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3363
                {
3364
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3365
                }
3366
                if (File.Exists(bmpPath))
3367
                {
3368
                    File.Delete(bmpPath);
3369
                }
3370
            }
3371
        }
3372

    
3373
        /************************************************************************/
3374
        /* Change the color of all objects                                      */
3375
        /************************************************************************/
3376
        private void chageColorAllObjects(Database pDb)
3377
        {
3378
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3379
            {
3380
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3381
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3382

    
3383
                foreach (ObjectId id in btrModelSpace)
3384
                {
3385
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3386
                    if (ent == null) continue;
3387

    
3388
                    ent.ColorIndex = 7;
3389

    
3390
                    if (ent is BlockReference)
3391
                    {
3392
                        changeColorBlocks(tr, (BlockReference)ent);
3393
                    }
3394
                }
3395

    
3396
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3397
                foreach (DBDictionaryEntry entry in dbdic)
3398
                {
3399
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3400
                    if (group == null) continue;
3401

    
3402
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3403
                    if (idarrTags == null) continue;
3404

    
3405
                    foreach (ObjectId id in idarrTags)
3406
                    {
3407
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3408
                        if (ent == null) continue;
3409

    
3410
                        ent.ColorIndex = 7;
3411
                    }
3412
                }
3413

    
3414
                foreach (ObjectId btrId in bt)
3415
                {
3416
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3417
                    if (btr == null) continue;
3418
                    if (btr.Name.StartsWith("*")) continue;
3419

    
3420
                    foreach (ObjectId entId in btr)
3421
                    {
3422
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3423
                        if (ent == null) continue;
3424
                        ent.ColorIndex = 0;//ByBlock
3425
                    }
3426
                }
3427

    
3428
                tr.Commit();
3429
            }
3430
        }
3431

    
3432
        /************************************************************************/
3433
        /* Change the color of blocks                                           */
3434
        /************************************************************************/
3435
        private void changeColorBlocks(Transaction tr, BlockReference blkRef)
3436
        {
3437
            if (blkRef == null) return;
3438

    
3439
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3440
            {
3441
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3442
                {
3443
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3444
                    attRef.ColorIndex = 7;
3445
                }
3446
            }
3447

    
3448
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3449
            if (btrBlock == null) return;
3450

    
3451
            foreach (ObjectId oid in btrBlock)
3452
            {
3453
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3454
                if (ent == null) continue;
3455

    
3456
                ent.ColorIndex = 7;
3457

    
3458
                if (ent is BlockReference)
3459
                {
3460
                    
3461
                    changeColorBlocks(tr, (BlockReference)ent);
3462
                }
3463
            }
3464
        }
3465

    
3466
        /************************************************************************/
3467
        /* Nested block Explode & Purge                                         */
3468
        /************************************************************************/
3469
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3470
        {
3471
            HashSet<string> blockNameList = new HashSet<string>();
3472
            // Explode ModelSpace Nested Block
3473
            blockNameList = explodeNestedBlocks(pDb);
3474

    
3475
            // Prepare Block Purge
3476
            preparePurgeBlocks(pDb, blockNameList);
3477

    
3478
            // Block Purge
3479
            ObjectIdCollection oids = new ObjectIdCollection();
3480
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3481
            {
3482
                foreach (ObjectId id in pTable)
3483
                {
3484
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3485
                    oids.Add(id);
3486
                }
3487
            }
3488
            pDb.Purge(oids);
3489

    
3490
            foreach (ObjectId oid in oids)
3491
            {
3492
                if (oid.IsErased) continue;
3493

    
3494
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3495
                {
3496
                    btr.Erase(true);
3497
                }                
3498
            }
3499
        }
3500

    
3501
        private HashSet<string> explodeNestedBlocks(Database pDb)
3502
        {
3503
            HashSet<string> blockNameList = new HashSet<string>();
3504
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3505

    
3506
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3507
            {
3508
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3509
                {
3510
                    foreach (ObjectId entid in pBlock)
3511
                    {
3512
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3513
                        {
3514
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3515
                            BlockReference blockRef = (BlockReference)pEnt;
3516

    
3517
                            if (blockRef.Name.ToUpper().StartsWith(BLOCK_PIPING))
3518
                            {
3519
                                oidSet.Add(entid);
3520
                                continue;
3521
                            }
3522
                            else if (blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3523
                            {
3524
                                continue;
3525
                            }
3526
                            
3527
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3528
                            {
3529
                                bool isNestedBlock = false;
3530
                                foreach (ObjectId blkid in pBtr)
3531
                                {
3532
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3533
                                    {
3534
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3535
                                        {
3536
                                            oidSet.Add(entid);
3537
                                            isNestedBlock = true;
3538
                                        }
3539
                                    }
3540
                                }
3541
                                if (!isNestedBlock)
3542
                                {
3543
                                    blockNameList.Add(blockRef.Name);
3544
                                }
3545
                            }
3546
                        }
3547
                    }
3548
                }
3549
            }
3550

    
3551
            if (oidSet.Count > 0)
3552
            {
3553
                explodeBlocks(oidSet);
3554
                blockNameList = explodeNestedBlocks(pDb);
3555
            }
3556

    
3557
            return blockNameList;
3558
        }
3559

    
3560
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3561
        {
3562
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3563

    
3564
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3565
            {
3566
                foreach (ObjectId id in pTable)
3567
                {
3568
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForWrite, false, true))
3569
                    {
3570
                        if (pBlock.IsLayout) continue;
3571
                        pBlock.Explodable = true;
3572
                        if (blockNameList.Contains(pBlock.Name)) continue;
3573

    
3574
                        foreach (ObjectId entid in pBlock)
3575
                        {
3576
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3577
                            {
3578
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3579

    
3580
                                oidSet.Add(entid);
3581
                            }
3582
                        }
3583
                    }
3584
                }
3585
            }
3586

    
3587
            if (oidSet.Count > 0)
3588
            {
3589
                explodeBlocks(oidSet);
3590
                preparePurgeBlocks(pDb, blockNameList);
3591
            }
3592

    
3593
            return;
3594
        }
3595
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3596
        {
3597
            foreach (ObjectId blkId in oidSet)
3598
            {
3599
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3600
                blkRef.ExplodeGeometryToOwnerSpace();
3601
                blkRef.Erase();
3602
            }
3603
        }
3604

    
3605
        /************************************************************************/
3606
        /* Save Block as DWG For Auxiliary Graphic                              */
3607
        /************************************************************************/
3608
        public void ExportGraphicBlocks(Database pDb, string savePath)
3609
        {
3610
            try
3611
            {
3612
                using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3613
                {
3614
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3615
                    {
3616
                        foreach (ObjectId entid in pBlock)
3617
                        {
3618
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3619
                            {
3620
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3621
                                BlockReference blockRef = (BlockReference)pEnt;
3622
                                if (!blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3623
                                    continue;
3624

    
3625
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3626
                                objIdCol.Add(blockRef.ObjectId);
3627
                                if (objIdCol.Count == 0) continue;
3628

    
3629
                                string filePath = string.Format("{0}.dwg", blockRef.Name);
3630
                                string directory = Path.GetDirectoryName(savePath);
3631
                                directory = directory.ToLower().Replace("drawings\\native", "graphic");
3632
                                if (!Directory.Exists(directory))
3633
                                {
3634
                                    Directory.CreateDirectory(directory);
3635
                                }
3636
                                filePath = Path.Combine(directory, filePath);
3637
                                
3638
                                using (Database newDb = new Database(true, false))
3639
                                {
3640
                                    pDb.Wblock(newDb, objIdCol, Point3d.Origin, DuplicateRecordCloning.Ignore);
3641
                                    newDb.UpdateExt(true);
3642
                                    newDb.SaveAs(filePath, DwgVersion.Newest);
3643
                                }
3644

    
3645
                                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo();
3646
                                procStartInfo.FileName = @"C:\Program Files (x86)\SmartSketch\Program\Rad2d\bin\Dwg2Igr.exe";
3647
                                procStartInfo.RedirectStandardOutput = true;
3648
                                procStartInfo.RedirectStandardInput = true;
3649
                                procStartInfo.RedirectStandardError = true;
3650
                                procStartInfo.UseShellExecute = false;
3651
                                procStartInfo.CreateNoWindow = false;
3652
                                procStartInfo.Arguments = filePath.Replace(" ", "^");
3653

    
3654
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3655
                                {
3656
                                    proc.StartInfo = procStartInfo;
3657
                                    proc.Start();
3658
                                    proc.StandardInput.Close();
3659
                                    proc.WaitForExit();
3660

    
3661
                                    switch (proc.ExitCode)
3662
                                    {
3663
                                        case -1:
3664
                                            Console.WriteLine("[{0}] path does not exist or there is no file", filePath);
3665
                                            break;
3666
                                        case 0:
3667
                                            Console.WriteLine("[{0}] File conversion error", filePath.Replace(".dwg", ".igr"));
3668
                                            break;
3669
                                        case 1:
3670
                                            Console.WriteLine("[{0}] File conversion success", filePath.Replace(".dwg", ".igr"));
3671
                                            break;
3672
                                        default:
3673
                                            break;
3674
                                    }
3675
                                }
3676
                            }
3677
                        }
3678
                    }
3679
                }
3680
            }
3681
            catch (System.Exception ex)
3682
            {
3683
            }
3684
        }
3685
        /************************************************************************/
3686
        /* Dump the BlockTable                                                  */
3687
        /************************************************************************/
3688
        public void dumpBlocks(Database pDb, int indent, XmlNode node)
3689
        {
3690
            /**********************************************************************/
3691
            /* Get a pointer to the BlockTable                               */
3692
            /**********************************************************************/
3693
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3694
            {
3695
                /**********************************************************************/
3696
                /* Dump the Description                                               */
3697
                /**********************************************************************/
3698
                XmlElement BlocksNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
3699

    
3700
                /**********************************************************************/
3701
                /* Step through the BlockTable                                        */
3702
                /**********************************************************************/
3703
                foreach (ObjectId id in pTable)
3704
                {
3705
                    /********************************************************************/
3706
                    /* Open the BlockTableRecord for Reading                            */
3707
                    /********************************************************************/
3708
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3709
                    {
3710
                        /********************************************************************/
3711
                        /* Dump the BlockTableRecord                                        */
3712
                        /********************************************************************/
3713
                        XmlElement BlockNode = Program.xml.CreateElement(pBlock.GetRXClass().Name);
3714

    
3715
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
3716
                        NameAttr.Value = pBlock.Name;
3717
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3718

    
3719
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3720
                        CommentsAttr.Value = pBlock.Comments;
3721
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3722

    
3723
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3724
                        OriginAttr.Value = pBlock.Origin.ToString();
3725
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3726

    
3727
                        writeLine(indent, pBlock.GetRXClass().Name);
3728
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3729
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3730
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3731
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3732
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3733

    
3734
                        try
3735
                        {
3736
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3737
                            extents.AddBlockExtents(pBlock);
3738

    
3739
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3740
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3741
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3742

    
3743
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3744
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3745
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3746
                        }
3747
                        catch (System.Exception)
3748
                        {
3749
                        }
3750

    
3751
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3752
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3753
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3754
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3755
                        {
3756
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3757
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3758
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3759
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3760
                        }
3761

    
3762
                        /********************************************************************/
3763
                        /* Step through the BlockTableRecord                                */
3764
                        /********************************************************************/
3765
                        foreach (ObjectId entid in pBlock)
3766
                        {
3767
                            /********************************************************************/
3768
                            /* Dump the Entity                                                  */
3769
                            /********************************************************************/
3770
                            dumpEntity(entid, indent + 1, BlockNode);
3771
                        }
3772

    
3773
                        BlocksNode.AppendChild(BlockNode);
3774
                    }
3775
                }
3776

    
3777
                node.AppendChild(BlocksNode);
3778
            }
3779
        }
3780

    
3781
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3782
        {
3783
            /**********************************************************************/
3784
            /* Get a SmartPointer to the DimStyleTable                            */
3785
            /**********************************************************************/
3786
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3787
            {
3788
                /**********************************************************************/
3789
                /* Dump the Description                                               */
3790
                /**********************************************************************/
3791
                writeLine();
3792
                writeLine(indent++, pTable.GetRXClass().Name);
3793

    
3794
                /**********************************************************************/
3795
                /* Step through the DimStyleTable                                    */
3796
                /**********************************************************************/
3797
                foreach (ObjectId id in pTable)
3798
                {
3799
                    /*********************************************************************/
3800
                    /* Open the DimStyleTableRecord for Reading                         */
3801
                    /*********************************************************************/
3802
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3803
                    {
3804
                        /*********************************************************************/
3805
                        /* Dump the DimStyleTableRecord                                      */
3806
                        /*********************************************************************/
3807
                        writeLine();
3808
                        writeLine(indent, pRecord.GetRXClass().Name);
3809
                        writeLine(indent, "Name", pRecord.Name);
3810
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3811

    
3812
                        writeLine(indent, "Background Text Color", pRecord.Dimtfillclr);
3813
                        writeLine(indent, "BackgroundText Flags", pRecord.Dimtfill);
3814
                        writeLine(indent, "Extension Line 1 Linetype", pRecord.Dimltex1);
3815
                        writeLine(indent, "Extension Line 2 Linetype", pRecord.Dimltex2);
3816
                        writeLine(indent, "Dimension Line Linetype", pRecord.Dimltype);
3817
                        writeLine(indent, "Extension Line Fixed Len", pRecord.Dimfxlen);
3818
                        writeLine(indent, "Extension Line Fixed Len Enable", pRecord.DimfxlenOn);
3819
                        writeLine(indent, "Jog Angle", toDegreeString(pRecord.Dimjogang));
3820
                        writeLine(indent, "Modified For Recompute", pRecord.IsModifiedForRecompute);
3821
                        writeLine(indent, "DIMADEC", pRecord.Dimadec);
3822
                        writeLine(indent, "DIMALT", pRecord.Dimalt);
3823
                        writeLine(indent, "DIMALTD", pRecord.Dimaltd);
3824
                        writeLine(indent, "DIMALTF", pRecord.Dimaltf);
3825
                        writeLine(indent, "DIMALTRND", pRecord.Dimaltrnd);
3826
                        writeLine(indent, "DIMALTTD", pRecord.Dimalttd);
3827
                        writeLine(indent, "DIMALTTZ", pRecord.Dimalttz);
3828
                        writeLine(indent, "DIMALTU", pRecord.Dimaltu);
3829
                        writeLine(indent, "DIMALTZ", pRecord.Dimaltz);
3830
                        writeLine(indent, "DIMAPOST", pRecord.Dimapost);
3831
                        writeLine(indent, "DIMASZ", pRecord.Dimasz);
3832
                        writeLine(indent, "DIMATFIT", pRecord.Dimatfit);
3833
                        writeLine(indent, "DIMAUNIT", pRecord.Dimaunit);
3834
                        writeLine(indent, "DIMAZIN", pRecord.Dimazin);
3835
                        writeLine(indent, "DIMBLK", pRecord.Dimblk);
3836
                        writeLine(indent, "DIMBLK1", pRecord.Dimblk1);
3837
                        writeLine(indent, "DIMBLK2", pRecord.Dimblk2);
3838
                        writeLine(indent, "DIMCEN", pRecord.Dimcen);
3839
                        writeLine(indent, "DIMCLRD", pRecord.Dimclrd);
3840
                        writeLine(indent, "DIMCLRE", pRecord.Dimclre);
3841
                        writeLine(indent, "DIMCLRT", pRecord.Dimclrt);
3842
                        writeLine(indent, "DIMDEC", pRecord.Dimdec);
3843
                        writeLine(indent, "DIMDLE", pRecord.Dimdle);
3844
                        writeLine(indent, "DIMDLI", pRecord.Dimdli);
3845
                        writeLine(indent, "DIMDSEP", pRecord.Dimdsep);
3846
                        writeLine(indent, "DIMEXE", pRecord.Dimexe);
3847
                        writeLine(indent, "DIMEXO", pRecord.Dimexo);
3848
                        writeLine(indent, "DIMFRAC", pRecord.Dimfrac);
3849
                        writeLine(indent, "DIMGAP", pRecord.Dimgap);
3850
                        writeLine(indent, "DIMJUST", pRecord.Dimjust);
3851
                        writeLine(indent, "DIMLDRBLK", pRecord.Dimldrblk);
3852
                        writeLine(indent, "DIMLFAC", pRecord.Dimlfac);
3853
                        writeLine(indent, "DIMLIM", pRecord.Dimlim);
3854
                        writeLine(indent, "DIMLUNIT", pRecord.Dimlunit);
3855
                        writeLine(indent, "DIMLWD", pRecord.Dimlwd);
3856
                        writeLine(indent, "DIMLWE", pRecord.Dimlwe);
3857
                        writeLine(indent, "DIMPOST", pRecord.Dimpost);
3858
                        writeLine(indent, "DIMRND", pRecord.Dimrnd);
3859
                        writeLine(indent, "DIMSAH", pRecord.Dimsah);
3860
                        writeLine(indent, "DIMSCALE", pRecord.Dimscale);
3861
                        writeLine(indent, "DIMSD1", pRecord.Dimsd1);
3862
                        writeLine(indent, "DIMSD2", pRecord.Dimsd2);
3863
                        writeLine(indent, "DIMSE1", pRecord.Dimse1);
3864
                        writeLine(indent, "DIMSE2", pRecord.Dimse2);
3865
                        writeLine(indent, "DIMSOXD", pRecord.Dimsoxd);
3866
                        writeLine(indent, "DIMTAD", pRecord.Dimtad);
3867
                        writeLine(indent, "DIMTDEC", pRecord.Dimtdec);
3868
                        writeLine(indent, "DIMTFAC", pRecord.Dimtfac);
3869
                        writeLine(indent, "DIMTIH", pRecord.Dimtih);
3870
                        writeLine(indent, "DIMTIX", pRecord.Dimtix);
3871
                        writeLine(indent, "DIMTM", pRecord.Dimtm);
3872
                        writeLine(indent, "DIMTOFL", pRecord.Dimtofl);
3873
                        writeLine(indent, "DIMTOH", pRecord.Dimtoh);
3874
                        writeLine(indent, "DIMTOL", pRecord.Dimtol);
3875
                        writeLine(indent, "DIMTOLJ", pRecord.Dimtolj);
3876
                        writeLine(indent, "DIMTP", pRecord.Dimtp);
3877
                        writeLine(indent, "DIMTSZ", pRecord.Dimtsz);
3878
                        writeLine(indent, "DIMTVP", pRecord.Dimtvp);
3879
                        writeLine(indent, "DIMTXSTY", pRecord.Dimtxsty);
3880
                        writeLine(indent, "DIMTXT", pRecord.Dimtxt);
3881
                        writeLine(indent, "DIMTZIN", pRecord.Dimtzin);
3882
                        writeLine(indent, "DIMUPT", pRecord.Dimupt);
3883
                        writeLine(indent, "DIMZIN", pRecord.Dimzin);
3884

    
3885
                        dumpSymbolTableRecord(pRecord, indent, node);
3886
                    }
3887
                }
3888
            }
3889
        }
3890

    
3891
        /// <summary>
3892
        /// extract information from entity has given id
3893
        /// </summary>
3894
        /// <param name="id"></param>
3895
        /// <param name="indent"></param>
3896
        /// <param name="node">XmlNode</param>
3897
        public void dumpEntity(ObjectId id, int indent, XmlNode node)
3898
        {
3899
            /**********************************************************************/
3900
            /* Get a pointer to the Entity                                   */
3901
            /**********************************************************************/
3902
            try
3903
            {
3904
                using (Entity pEnt = (Entity)id.Open(OpenMode.ForRead, false, true))
3905
                {
3906
                    /**********************************************************************/
3907
                    /* Dump the entity                                                    */
3908
                    /**********************************************************************/
3909
                    writeLine();
3910
                    // Protocol extensions are not supported in DD.NET (as well as in ARX.NET)
3911
                    // so we just switch by entity type here
3912
                    // (maybe it makes sense to make a map: type -> delegate)
3913
                    switch (pEnt.GetRXClass().Name)
3914
                    {
3915
                        case "AcDbAlignedDimension":
3916
                            dump((AlignedDimension)pEnt, indent, node);
3917
                            break;
3918
                        case "AcDbArc":
3919
                            dump((Arc)pEnt, indent, node);
3920
                            break;
3921
                        case "AcDbArcDimension":
3922
                            dump((ArcDimension)pEnt, indent, node);
3923
                            break;
3924
                        case "AcDbBlockReference":
3925
                            dump((BlockReference)pEnt, indent, node);
3926
                            break;
3927
                        case "AcDbBody":
3928
                            dump((Body)pEnt, indent, node);
3929
                            break;
3930
                        case "AcDbCircle":
3931
                            dump((Circle)pEnt, indent, node);
3932
                            break;
3933
                        case "AcDbPoint":
3934
                            dump((DBPoint)pEnt, indent);
3935
                            break;
3936
                        case "AcDbText":
3937
                            dump((DBText)pEnt, indent, node);
3938
                            break;
3939
                        case "AcDbDiametricDimension":
3940
                            dump((DiametricDimension)pEnt, indent, node);
3941
                            break;
3942
                        case "AcDbViewport":
3943
                            dump((Teigha.DatabaseServices.Viewport)pEnt, indent, node);
3944
                            break;
3945
                        case "AcDbEllipse":
3946
                            dump((Ellipse)pEnt, indent, node);
3947
                            break;
3948
                        case "AcDbFace":
3949
                            dump((Face)pEnt, indent, node);
3950
                            break;
3951
                        case "AcDbFcf":
3952
                            dump((FeatureControlFrame)pEnt, indent);
3953
                            break;
3954
                        case "AcDbHatch":
3955
                            dump((Hatch)pEnt, indent);
3956
                            break;
3957
                        case "AcDbLeader":
3958
                            dump((Leader)pEnt, indent);
3959
                            break;
3960
                        case "AcDbLine":
3961
                            dump((Line)pEnt, indent, node);
3962
                            break;
3963
                        case "AcDb2LineAngularDimension":
3964
                            dump((LineAngularDimension2)pEnt, indent, node);
3965
                            break;
3966
                        case "AcDbMInsertBlock":
3967
                            dump((MInsertBlock)pEnt, indent, node);
3968
                            break;
3969
                        case "AcDbMline":
3970
                            dump((Mline)pEnt, indent);
3971
                            break;
3972
                        case "AcDbMText":
3973
                            dump((MText)pEnt, indent, node);
3974
                            break;
3975
                        case "AcDbOle2Frame":
3976
                            dump((Ole2Frame)pEnt, indent);
3977
                            break;
3978
                        case "AcDbOrdinateDimension":
3979
                            dump((OrdinateDimension)pEnt, indent, node);
3980
                            break;
3981
                        case "AcDb3PointAngularDimension":
3982
                            dump((Point3AngularDimension)pEnt, indent, node);
3983
                            break;
3984
                        case "AcDbPolyFaceMesh":
3985
                            dump((PolyFaceMesh)pEnt, indent, node);
3986
                            break;
3987
                        case "AcDbPolygonMesh":
3988
                            dump((PolygonMesh)pEnt, indent);
3989
                            break;
3990
                        case "AcDbPolyline":
3991
                            dump((Teigha.DatabaseServices.Polyline)pEnt, indent, node);
3992
                            break;
3993
                        case "AcDb2dPolyline":
3994
                            dump((Polyline2d)pEnt, indent, node);
3995
                            break;
3996
                        case "AcDb3dPolyline":
3997
                            dump((Polyline3d)pEnt, indent, node);
3998
                            break;
3999
                        case "AcDbProxyEntity":
4000
                            dump((ProxyEntity)pEnt, indent, node);
4001
                            break;
4002
                        case "AcDbRadialDimension":
4003
                            dump((RadialDimension)pEnt, indent, node);
4004
                            break;
4005
                        case "AcDbRasterImage":
4006
                            dump((RasterImage)pEnt, indent);
4007
                            break;
4008
                        case "AcDbRay":
4009
                            dump((Ray)pEnt, indent);
4010
                            break;
4011
                        case "AcDbRegion":
4012
                            dump((Region)pEnt, indent);
4013
                            break;
4014
                        case "AcDbRotatedDimension":
4015
                            dump((RotatedDimension)pEnt, indent, node);
4016
                            break;
4017
                        case "AcDbShape":
4018
                            dump((Shape)pEnt, indent);
4019
                            break;
4020
                        case "AcDb3dSolid":
4021
                            dump((Solid3d)pEnt, indent, node);
4022
                            break;
4023
                        case "AcDbSpline":
4024
                            dump((Spline)pEnt, indent);
4025
                            break;
4026
                        case "AcDbTable":
4027
                            dump((Table)pEnt, indent);
4028
                            break;
4029
                        case "AcDbTrace":
4030
                            dump((Trace)pEnt, indent);
4031
                            break;
4032
                        case "AcDbWipeout":
4033
                            dump((Wipeout)pEnt, indent);
4034
                            break;
4035
                        case "AcDbXline":
4036
                            dump((Xline)pEnt, indent);
4037
                            break;
4038
                        case "AcDbAttributeDefinition":
4039
                            dump((AttributeDefinition)pEnt, indent, node);
4040
                            break; 
4041
                        case "AcDbPdfReference":
4042
                        case "AcDbDwfReference":
4043
                        case "AcDbDgnReference":
4044
                            dump((UnderlayReference)pEnt, indent);
4045
                            break;
4046
                        default:
4047
                            dump(pEnt, indent, node);
4048
                            break;
4049
                    }
4050
                    /* Dump the Xdata                                                     */
4051
                    /**********************************************************************/
4052
                    dumpXdata(pEnt.XData, indent);
4053

    
4054
                    /**********************************************************************/
4055
                    /* Dump the Extension Dictionary                                      */
4056
                    /**********************************************************************/
4057
                    if (!pEnt.ExtensionDictionary.IsNull)
4058
                    {
4059
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
4060
                    }
4061
                }
4062
            }
4063
            catch (System.Exception ex)
4064
            {
4065
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
4066
            }
4067
        }
4068
        public void dumpHeader(Database pDb, int indent, XmlNode node)
4069
        {
4070
            if (node != null)
4071
            {
4072
                XmlAttribute FileNameAttr = Program.xml.CreateAttribute("FileName");
4073
                FileNameAttr.Value = shortenPath(pDb.Filename);
4074
                node.Attributes.SetNamedItem(FileNameAttr);
4075

    
4076
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
4077
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4078
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4079

    
4080
                writeLine();
4081
                writeLine(indent++, "Header Variables:");
4082

    
4083
                //writeLine();
4084
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4085
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4086

    
4087
                writeLine();
4088
                writeLine(indent, "ANGBASE", pDb.Angbase);
4089
                writeLine(indent, "ANGDIR", pDb.Angdir);
4090
                writeLine(indent, "ATTMODE", pDb.Attmode);
4091
                writeLine(indent, "AUNITS", pDb.Aunits);
4092
                writeLine(indent, "AUPREC", pDb.Auprec);
4093
                writeLine(indent, "CECOLOR", pDb.Cecolor);
4094
                writeLine(indent, "CELTSCALE", pDb.Celtscale);
4095
                writeLine(indent, "CHAMFERA", pDb.Chamfera);
4096
                writeLine(indent, "CHAMFERB", pDb.Chamferb);
4097
                writeLine(indent, "CHAMFERC", pDb.Chamferc);
4098
                writeLine(indent, "CHAMFERD", pDb.Chamferd);
4099
                writeLine(indent, "CMLJUST", pDb.Cmljust);
4100
                writeLine(indent, "CMLSCALE", pDb.Cmljust);
4101
                writeLine(indent, "DIMADEC", pDb.Dimadec);
4102
                writeLine(indent, "DIMALT", pDb.Dimalt);
4103
                writeLine(indent, "DIMALTD", pDb.Dimaltd);
4104
                writeLine(indent, "DIMALTF", pDb.Dimaltf);
4105
                writeLine(indent, "DIMALTRND", pDb.Dimaltrnd);
4106
                writeLine(indent, "DIMALTTD", pDb.Dimalttd);
4107
                writeLine(indent, "DIMALTTZ", pDb.Dimalttz);
4108
                writeLine(indent, "DIMALTU", pDb.Dimaltu);
4109
                writeLine(indent, "DIMALTZ", pDb.Dimaltz);
4110
                writeLine(indent, "DIMAPOST", pDb.Dimapost);
4111
                writeLine(indent, "DIMASZ", pDb.Dimasz);
4112
                writeLine(indent, "DIMATFIT", pDb.Dimatfit);
4113
                writeLine(indent, "DIMAUNIT", pDb.Dimaunit);
4114
                writeLine(indent, "DIMAZIN", pDb.Dimazin);
4115
                writeLine(indent, "DIMBLK", pDb.Dimblk);
4116
                writeLine(indent, "DIMBLK1", pDb.Dimblk1);
4117
                writeLine(indent, "DIMBLK2", pDb.Dimblk2);
4118
                writeLine(indent, "DIMCEN", pDb.Dimcen);
4119
                writeLine(indent, "DIMCLRD", pDb.Dimclrd);
4120
                writeLine(indent, "DIMCLRE", pDb.Dimclre);
4121
                writeLine(indent, "DIMCLRT", pDb.Dimclrt);
4122
                writeLine(indent, "DIMDEC", pDb.Dimdec);
4123
                writeLine(indent, "DIMDLE", pDb.Dimdle);
4124
                writeLine(indent, "DIMDLI", pDb.Dimdli);
4125
                writeLine(indent, "DIMDSEP", pDb.Dimdsep);
4126
                writeLine(indent, "DIMEXE", pDb.Dimexe);
4127
                writeLine(indent, "DIMEXO", pDb.Dimexo);
4128
                writeLine(indent, "DIMFRAC", pDb.Dimfrac);
4129
                writeLine(indent, "DIMGAP", pDb.Dimgap);
4130
                writeLine(indent, "DIMJUST", pDb.Dimjust);
4131
                writeLine(indent, "DIMLDRBLK", pDb.Dimldrblk);
4132
                writeLine(indent, "DIMLFAC", pDb.Dimlfac);
4133
                writeLine(indent, "DIMLIM", pDb.Dimlim);
4134
                writeLine(indent, "DIMLUNIT", pDb.Dimlunit);
4135
                writeLine(indent, "DIMLWD", pDb.Dimlwd);
4136
                writeLine(indent, "DIMLWE", pDb.Dimlwe);
4137
                writeLine(indent, "DIMPOST", pDb.Dimpost);
4138
                writeLine(indent, "DIMRND", pDb.Dimrnd);
4139
                writeLine(indent, "DIMSAH", pDb.Dimsah);
4140
                writeLine(indent, "DIMSCALE", pDb.Dimscale);
4141
                writeLine(indent, "DIMSD1", pDb.Dimsd1);
4142
                writeLine(indent, "DIMSD2", pDb.Dimsd2);
4143
                writeLine(indent, "DIMSE1", pDb.Dimse1);
4144
                writeLine(indent, "DIMSE2", pDb.Dimse2);
4145
                writeLine(indent, "DIMSOXD", pDb.Dimsoxd);
4146
                writeLine(indent, "DIMTAD", pDb.Dimtad);
4147
                writeLine(indent, "DIMTDEC", pDb.Dimtdec);
4148
                writeLine(indent, "DIMTFAC", pDb.Dimtfac);
4149
                writeLine(indent, "DIMTIH", pDb.Dimtih);
4150
                writeLine(indent, "DIMTIX", pDb.Dimtix);
4151
                writeLine(indent, "DIMTM", pDb.Dimtm);
4152
                writeLine(indent, "DIMTOFL", pDb.Dimtofl);
4153
                writeLine(indent, "DIMTOH", pDb.Dimtoh);
4154
                writeLine(indent, "DIMTOL", pDb.Dimtol);
4155
                writeLine(indent, "DIMTOLJ", pDb.Dimtolj);
4156
                writeLine(indent, "DIMTP", pDb.Dimtp);
4157
                writeLine(indent, "DIMTSZ", pDb.Dimtsz);
4158
                writeLine(indent, "DIMTVP", pDb.Dimtvp);
4159
                writeLine(indent, "DIMTXSTY", pDb.Dimtxsty);
4160
                writeLine(indent, "DIMTXT", pDb.Dimtxt);
4161
                writeLine(indent, "DIMTZIN", pDb.Dimtzin);
4162
                writeLine(indent, "DIMUPT", pDb.Dimupt);
4163
                writeLine(indent, "DIMZIN", pDb.Dimzin);
4164
                writeLine(indent, "DISPSILH", pDb.DispSilh);
4165
                writeLine(indent, "DRAWORDERCTL", pDb.DrawOrderCtl);
4166
                writeLine(indent, "ELEVATION", pDb.Elevation);
4167
                writeLine(indent, "EXTMAX", pDb.Extmax);
4168
                writeLine(indent, "EXTMIN", pDb.Extmin);
4169
                writeLine(indent, "FACETRES", pDb.Facetres);
4170
                writeLine(indent, "FILLETRAD", pDb.Filletrad);
4171
                writeLine(indent, "FILLMODE", pDb.Fillmode);
4172
                writeLine(indent, "INSBASE", pDb.Insbase);
4173
                writeLine(indent, "ISOLINES", pDb.Isolines);
4174
                writeLine(indent, "LIMCHECK", pDb.Limcheck);
4175
                writeLine(indent, "LIMMAX", pDb.Limmax);
4176
                writeLine(indent, "LIMMIN", pDb.Limmin);
4177
                writeLine(indent, "LTSCALE", pDb.Ltscale);
4178
                writeLine(indent, "LUNITS", pDb.Lunits);
4179
                writeLine(indent, "LUPREC", pDb.Luprec);
4180
                writeLine(indent, "MAXACTVP", pDb.Maxactvp);
4181
                writeLine(indent, "MIRRTEXT", pDb.Mirrtext);
4182
                writeLine(indent, "ORTHOMODE", pDb.Orthomode);
4183
                writeLine(indent, "PDMODE", pDb.Pdmode);
4184
                writeLine(indent, "PDSIZE", pDb.Pdsize);
4185
                writeLine(indent, "PELEVATION", pDb.Pelevation);
4186
                writeLine(indent, "PELLIPSE", pDb.PlineEllipse);
4187
                writeLine(indent, "PEXTMAX", pDb.Pextmax);
4188
                writeLine(indent, "PEXTMIN", pDb.Pextmin);
4189
                writeLine(indent, "PINSBASE", pDb.Pinsbase);
4190
                writeLine(indent, "PLIMCHECK", pDb.Plimcheck);
4191
                writeLine(indent, "PLIMMAX", pDb.Plimmax);
4192
                writeLine(indent, "PLIMMIN", pDb.Plimmin);
4193
                writeLine(indent, "PLINEGEN", pDb.Plinegen);
4194
                writeLine(indent, "PLINEWID", pDb.Plinewid);
4195
                writeLine(indent, "PROXYGRAPHICS", pDb.Saveproxygraphics);
4196
                writeLine(indent, "PSLTSCALE", pDb.Psltscale);
4197
                writeLine(indent, "PUCSNAME", pDb.Pucsname);
4198
                writeLine(indent, "PUCSORG", pDb.Pucsorg);
4199
                writeLine(indent, "PUCSXDIR", pDb.Pucsxdir);
4200
                writeLine(indent, "PUCSYDIR", pDb.Pucsydir);
4201
                writeLine(indent, "QTEXTMODE", pDb.Qtextmode);
4202
                writeLine(indent, "REGENMODE", pDb.Regenmode);
4203
                writeLine(indent, "SHADEDGE", pDb.Shadedge);
4204
                writeLine(indent, "SHADEDIF", pDb.Shadedif);
4205
                writeLine(indent, "SKETCHINC", pDb.Sketchinc);
4206
                writeLine(indent, "SKPOLY", pDb.Skpoly);
4207
                writeLine(indent, "SPLFRAME", pDb.Splframe);
4208
                writeLine(indent, "SPLINESEGS", pDb.Splinesegs);
4209
                writeLine(indent, "SPLINETYPE", pDb.Splinetype);
4210
                writeLine(indent, "SURFTAB1", pDb.Surftab1);
4211
                writeLine(indent, "SURFTAB2", pDb.Surftab2);
4212
                writeLine(indent, "SURFTYPE", pDb.Surftype);
4213
                writeLine(indent, "SURFU", pDb.Surfu);
4214
                writeLine(indent, "SURFV", pDb.Surfv);
4215
                //writeLine(indent, "TEXTQLTY", pDb.TEXTQLTY);
4216
                writeLine(indent, "TEXTSIZE", pDb.Textsize);
4217
                writeLine(indent, "THICKNESS", pDb.Thickness);
4218
                writeLine(indent, "TILEMODE", pDb.TileMode);
4219
                writeLine(indent, "TRACEWID", pDb.Tracewid);
4220
                writeLine(indent, "TREEDEPTH", pDb.Treedepth);
4221
                writeLine(indent, "UCSNAME", pDb.Ucsname);
4222
                writeLine(indent, "UCSORG", pDb.Ucsorg);
4223
                writeLine(indent, "UCSXDIR", pDb.Ucsxdir);
4224
                writeLine(indent, "UCSYDIR", pDb.Ucsydir);
4225
                writeLine(indent, "UNITMODE", pDb.Unitmode);
4226
                writeLine(indent, "USERI1", pDb.Useri1);
4227
                writeLine(indent, "USERI2", pDb.Useri2);
4228
                writeLine(indent, "USERI3", pDb.Useri3);
4229
                writeLine(indent, "USERI4", pDb.Useri4);
4230
                writeLine(indent, "USERI5", pDb.Useri5);
4231
                writeLine(indent, "USERR1", pDb.Userr1);
4232
                writeLine(indent, "USERR2", pDb.Userr2);
4233
                writeLine(indent, "USERR3", pDb.Userr3);
4234
                writeLine(indent, "USERR4", pDb.Userr4);
4235
                writeLine(indent, "USERR5", pDb.Userr5);
4236
                writeLine(indent, "USRTIMER", pDb.Usrtimer);
4237
                writeLine(indent, "VISRETAIN", pDb.Visretain);
4238
                writeLine(indent, "WORLDVIEW", pDb.Worldview);
4239
            }
4240
        }
4241

    
4242
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4243
        {
4244
            if (node != null)
4245
            {
4246
                /**********************************************************************/
4247
                /* Get a SmartPointer to the LayerTable                               */
4248
                /**********************************************************************/
4249
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4250
                {
4251
                    /**********************************************************************/
4252
                    /* Dump the Description                                               */
4253
                    /**********************************************************************/
4254
                    XmlElement LayerNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4255

    
4256
                    /**********************************************************************/
4257
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4258
                    /**********************************************************************/
4259

    
4260
                    /**********************************************************************/
4261
                    /* Step through the LayerTable                                        */
4262
                    /**********************************************************************/
4263
                    foreach (ObjectId id in pTable)
4264
                    {
4265
                        /********************************************************************/
4266
                        /* Open the LayerTableRecord for Reading                            */
4267
                        /********************************************************************/
4268
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4269
                        {
4270
                            /********************************************************************/
4271
                            /* Dump the LayerTableRecord                                        */
4272
                            /********************************************************************/
4273
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4274

    
4275
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4276
                            NameAttr.Value = pRecord.Name.ToString();
4277
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4278

    
4279
                            XmlAttribute IsUsedAttr = Program.xml.CreateAttribute("IsUsed");
4280
                            IsUsedAttr.Value = pRecord.IsUsed.ToString();
4281
                            RecordNode.Attributes.SetNamedItem(IsUsedAttr);
4282

    
4283
                            XmlAttribute IsOffAttr = Program.xml.CreateAttribute("IsOff");
4284
                            IsOffAttr.Value = pRecord.IsOff.ToString();
4285
                            RecordNode.Attributes.SetNamedItem(IsOffAttr);
4286

    
4287
                            XmlAttribute IsFrozenAttr = Program.xml.CreateAttribute("IsFrozen");
4288
                            IsFrozenAttr.Value = pRecord.IsFrozen.ToString();
4289
                            RecordNode.Attributes.SetNamedItem(IsFrozenAttr);
4290

    
4291
                            XmlAttribute IsLockedAttr = Program.xml.CreateAttribute("IsLocked");
4292
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4293
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4294

    
4295
                            XmlAttribute ColorAttr = Program.xml.CreateAttribute("Color");
4296
                            ColorAttr.Value = pRecord.Color.ToString();
4297
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4298

    
4299
                            XmlAttribute LinetypeObjectIdAttr = Program.xml.CreateAttribute("LinetypeObjectId");
4300
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4301
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4302

    
4303
                            XmlAttribute LineWeightAttr = Program.xml.CreateAttribute("LineWeight");
4304
                            LineWeightAttr.Value = pRecord.LineWeight.ToString();
4305
                            RecordNode.Attributes.SetNamedItem(LineWeightAttr);
4306

    
4307
                            XmlAttribute PlotStyleNameAttr = Program.xml.CreateAttribute("PlotStyleName");
4308
                            PlotStyleNameAttr.Value = pRecord.PlotStyleName.ToString();
4309
                            RecordNode.Attributes.SetNamedItem(PlotStyleNameAttr);
4310

    
4311
                            XmlAttribute IsPlottableAttr = Program.xml.CreateAttribute("IsPlottable");
4312
                            IsPlottableAttr.Value = pRecord.IsPlottable.ToString();
4313
                            RecordNode.Attributes.SetNamedItem(IsPlottableAttr);
4314

    
4315
                            XmlAttribute ViewportVisibilityDefaultAttr = Program.xml.CreateAttribute("ViewportVisibilityDefault");
4316
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4317
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4318

    
4319
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4320
                            LayerNode.AppendChild(RecordNode);
4321
                        }
4322
                    }
4323

    
4324
                    node.AppendChild(LayerNode);
4325
                }
4326
            }
4327
        }
4328

    
4329
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4330
        {
4331
            if (node != null)
4332
            {
4333
                /**********************************************************************/
4334
                /* Get a pointer to the LinetypeTable                            */
4335
                /**********************************************************************/
4336
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4337
                {
4338
                    XmlElement LinetypeNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4339

    
4340
                    /**********************************************************************/
4341
                    /* Step through the LinetypeTable                                     */
4342
                    /**********************************************************************/
4343
                    foreach (ObjectId id in pTable)
4344
                    {
4345
                        /*********************************************************************/
4346
                        /* Open the LinetypeTableRecord for Reading                          */
4347
                        /*********************************************************************/
4348
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4349
                        {
4350
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4351

    
4352
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4353
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4354
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4355

    
4356
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4357
                            NameAttr.Value = pRecord.Name;
4358
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4359

    
4360
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4361
                            CommentsAttr.Value = pRecord.Comments;
4362
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4363

    
4364
                            /********************************************************************/
4365
                            /* Dump the first line of record as in ACAD.LIN                     */
4366
                            /********************************************************************/
4367
                            string buffer = "*" + pRecord.Name;
4368
                            if (pRecord.Comments != "")
4369
                            {
4370
                                buffer = buffer + "," + pRecord.Comments;
4371
                            }
4372
                            writeLine(indent, buffer);
4373

    
4374
                            /********************************************************************/
4375
                            /* Dump the second line of record as in ACAD.LIN                    */
4376
                            /********************************************************************/
4377
                            if (pRecord.NumDashes > 0)
4378
                            {
4379
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4380
                                for (int i = 0; i < pRecord.NumDashes; i++)
4381
                                {
4382
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4383
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4384
                                    string text = pRecord.TextAt(i);
4385

    
4386
                                    /**************************************************************/
4387
                                    /* Dump the Complex Line                                      */
4388
                                    /**************************************************************/
4389
                                    if (shapeNumber != 0 || text != "")
4390
                                    {
4391
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4392
                                        {
4393
                                            if (shapeNumber != 0)
4394
                                            {
4395
                                                buffer = buffer + ",[" + shapeNumber + ",";
4396
                                                if (pTextStyle != null)
4397
                                                    buffer = buffer + pTextStyle.FileName;
4398
                                                else
4399
                                                    buffer = buffer + "NULL style";
4400
                                            }
4401
                                            else
4402
                                            {
4403
                                                buffer = buffer + ",[" + text + ",";
4404
                                                if (pTextStyle != null)
4405
                                                    buffer = buffer + pTextStyle.Name;
4406
                                                else
4407
                                                    buffer = buffer + "NULL style";
4408
                                            }
4409
                                        }
4410

    
4411
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4412
                                        {
4413
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4414
                                        }
4415
                                        if (pRecord.ShapeRotationAt(i) != 0)
4416
                                        {
4417
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4418
                                        }
4419
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4420
                                        {
4421
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4422
                                        }
4423
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4424
                                        {
4425
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4426
                                        }
4427
                                        buffer = buffer + "]";
4428
                                    }
4429
                                }
4430
                                writeLine(indent, buffer);
4431
                            }
4432
                            dumpSymbolTableRecord(pRecord, indent, node);
4433
                            LinetypeNode.AppendChild(RecordNode);
4434
                        }
4435
                    }
4436

    
4437
                    node.AppendChild(LinetypeNode);
4438
                }
4439
            }
4440
        }
4441

    
4442
        public void dumpRegApps(Database pDb, int indent)
4443
        {
4444
            /**********************************************************************/
4445
            /* Get a pointer to the RegAppTable                            */
4446
            /**********************************************************************/
4447
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4448
            {
4449
                /**********************************************************************/
4450
                /* Dump the Description                                               */
4451
                /**********************************************************************/
4452
                writeLine();
4453
                writeLine(indent++, pTable.GetRXClass().Name);
4454

    
4455
                /**********************************************************************/
4456
                /* Step through the RegAppTable                                    */
4457
                /**********************************************************************/
4458
                foreach (ObjectId id in pTable)
4459
                {
4460
                    /*********************************************************************/
4461
                    /* Open the RegAppTableRecord for Reading                         */
4462
                    /*********************************************************************/
4463
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4464
                    {
4465
                        /*********************************************************************/
4466
                        /* Dump the RegAppTableRecord                                      */
4467
                        /*********************************************************************/
4468
                        writeLine();
4469
                        writeLine(indent, pRecord.GetRXClass().Name);
4470
                        writeLine(indent, "Name", pRecord.Name);
4471
                    }
4472
                }
4473
            }
4474
        }
4475

    
4476
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4477
        {
4478
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4479
            if (pRecord.IsDependent)
4480
            {
4481
                writeLine(indent, "Resolved", pRecord.IsResolved);
4482
            }
4483
        }
4484

    
4485
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4486
        {
4487
            /**********************************************************************/
4488
            /* Get a SmartPointer to the TextStyleTable                            */
4489
            /**********************************************************************/
4490
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4491
            {
4492
                /**********************************************************************/
4493
                /* Dump the Description                                               */
4494
                /**********************************************************************/
4495
                writeLine();
4496
                writeLine(indent++, pTable.GetRXClass().Name);
4497

    
4498
                /**********************************************************************/
4499
                /* Step through the TextStyleTable                                    */
4500
                /**********************************************************************/
4501
                foreach (ObjectId id in pTable)
4502
                {
4503
                    /*********************************************************************/
4504
                    /* Open the TextStyleTableRecord for Reading                         */
4505
                    /*********************************************************************/
4506
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4507
                    {
4508
                        /*********************************************************************/
4509
                        /* Dump the TextStyleTableRecord                                      */
4510
                        /*********************************************************************/
4511
                        writeLine();
4512
                        writeLine(indent, pRecord.GetRXClass().Name);
4513
                        writeLine(indent, "Name", pRecord.Name);
4514
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4515
                        writeLine(indent, "Text Height", pRecord.TextSize);
4516
                        writeLine(indent, "Width Factor", pRecord.XScale);
4517
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4518
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4519
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4520
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4521
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4522
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4523

    
4524
                        FontDescriptor fd = pRecord.Font;
4525
                        writeLine(indent, "Typeface", fd.TypeFace);
4526
                        writeLine(indent, "Character Set", fd.CharacterSet);
4527
                        writeLine(indent, "Bold", fd.Bold);
4528
                        writeLine(indent, "Italic", fd.Italic);
4529
                        writeLine(indent, "Font Pitch & Family", toHexString(fd.PitchAndFamily));
4530
                        dumpSymbolTableRecord(pRecord, indent, node);
4531
                    }
4532
                }
4533
            }
4534
        }
4535
        public void dumpAbstractViewTableRecord(AbstractViewTableRecord pView, int indent, XmlNode node)
4536
        {
4537
            /*********************************************************************/
4538
            /* Dump the AbstractViewTableRecord                                  */
4539
            /*********************************************************************/
4540
            writeLine(indent, "Back Clip Dist", pView.BackClipDistance);
4541
            writeLine(indent, "Back Clip Enabled", pView.BackClipEnabled);
4542
            writeLine(indent, "Front Clip Dist", pView.FrontClipDistance);
4543
            writeLine(indent, "Front Clip Enabled", pView.FrontClipEnabled);
4544
            writeLine(indent, "Front Clip at Eye", pView.FrontClipAtEye);
4545
            writeLine(indent, "Elevation", pView.Elevation);
4546
            writeLine(indent, "Height", pView.Height);
4547
            writeLine(indent, "Width", pView.Width);
4548
            writeLine(indent, "Lens Length", pView.LensLength);
4549
            writeLine(indent, "Render Mode", pView.RenderMode);
4550
            writeLine(indent, "Perspective", pView.PerspectiveEnabled);
4551
            writeLine(indent, "UCS Name", pView.UcsName);
4552

    
4553
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4554
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4555

    
4556
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4557
            {
4558
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4559
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4560
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4561
            }
4562

    
4563
            writeLine(indent, "Target", pView.Target);
4564
            writeLine(indent, "View Direction", pView.ViewDirection);
4565
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4566
            dumpSymbolTableRecord(pView, indent, node);
4567
        }
4568
        public void dumpDimAssoc(DBObject pObject, int indent)
4569
        {
4570

    
4571
        }
4572
        public void dumpMLineStyles(Database pDb, int indent)
4573
        {
4574
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4575
            {
4576
                /**********************************************************************/
4577
                /* Dump the Description                                               */
4578
                /**********************************************************************/
4579
                writeLine();
4580
                writeLine(indent++, pDictionary.GetRXClass().Name);
4581

    
4582
                /**********************************************************************/
4583
                /* Step through the MlineStyle dictionary                             */
4584
                /**********************************************************************/
4585
                DbDictionaryEnumerator e = pDictionary.GetEnumerator();
4586
                while (e.MoveNext())
4587
                {
4588
                    try
4589
                    {
4590
                        using (MlineStyle pEntry = (MlineStyle)e.Value.Open(OpenMode.ForRead))
4591
                        {
4592
                            /*********************************************************************/
4593
                            /* Dump the MLineStyle dictionary entry                              */
4594
                            /*********************************************************************/
4595
                            writeLine();
4596
                            writeLine(indent, pEntry.GetRXClass().Name);
4597
                            writeLine(indent, "Name", pEntry.Name);
4598
                            writeLine(indent, "Description", pEntry.Description);
4599
                            writeLine(indent, "Start Angle", toDegreeString(pEntry.StartAngle));
4600
                            writeLine(indent, "End Angle", toDegreeString(pEntry.EndAngle));
4601
                            writeLine(indent, "Start Inner Arcs", pEntry.StartInnerArcs);
4602
                            writeLine(indent, "End Inner Arcs", pEntry.EndInnerArcs);
4603
                            writeLine(indent, "Start Round Cap", pEntry.StartRoundCap);
4604
                            writeLine(indent, "End Round Cap", pEntry.EndRoundCap);
4605
                            writeLine(indent, "Start Square Cap", pEntry.StartRoundCap);
4606
                            writeLine(indent, "End Square Cap", pEntry.EndRoundCap);
4607
                            writeLine(indent, "Show Miters", pEntry.ShowMiters);
4608
                            /*********************************************************************/
4609
                            /* Dump the elements                                                 */
4610
                            /*********************************************************************/
4611
                            if (pEntry.Elements.Count > 0)
4612
                            {
4613
                                writeLine(indent, "Elements:");
4614
                            }
4615
                            int i = 0;
4616
                            foreach (MlineStyleElement el in pEntry.Elements)
4617
                            {
4618
                                writeLine(indent, "Index", (i++));
4619
                                writeLine(indent + 1, "Offset", el.Offset);
4620
                                writeLine(indent + 1, "Color", el.Color);
4621
                                writeLine(indent + 1, "Linetype", el.LinetypeId);
4622
                            }
4623
                        }
4624
                    }
4625
                    catch (System.Exception)
4626
                    {
4627
                    }
4628
                }
4629
            }
4630
        }
4631
        public void dumpObject(ObjectId id, string itemName, int indent)
4632
        {
4633
            using (DBObject pObject = id.Open(OpenMode.ForRead))
4634
            {
4635
                /**********************************************************************/
4636
                /* Dump the item name and class name                                  */
4637
                /**********************************************************************/
4638
                if (pObject is DBDictionary)
4639
                {
4640
                    writeLine();
4641
                }
4642
                writeLine(indent++, itemName, pObject.GetRXClass().Name);
4643

    
4644
                /**********************************************************************/
4645
                /* Dispatch                                                           */
4646
                /**********************************************************************/
4647
                if (pObject is DBDictionary)
4648
                {
4649
                    /********************************************************************/
4650
                    /* Dump the dictionary                                               */
4651
                    /********************************************************************/
4652
                    DBDictionary pDic = (DBDictionary)pObject;
4653

    
4654
                    /********************************************************************/
4655
                    /* Get a pointer to a new DictionaryIterator                   */
4656
                    /********************************************************************/
4657
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4658

    
4659
                    /********************************************************************/
4660
                    /* Step through the Dictionary                                      */
4661
                    /********************************************************************/
4662
                    while (pIter.MoveNext())
4663
                    {
4664
                        /******************************************************************/
4665
                        /* Dump the Dictionary object                                     */
4666
                        /******************************************************************/
4667
                        dumpObject(pIter.Value, pIter.Key, indent);
4668
                    }
4669
                }
4670
                else if (pObject is Xrecord)
4671
                {
4672
                    /********************************************************************/
4673
                    /* Dump an Xrecord                                                  */
4674
                    /********************************************************************/
4675
                    Xrecord pXRec = (Xrecord)pObject;
4676
                    dumpXdata(pXRec.Data, indent);
4677
                }
4678
            }
4679
        }
4680

    
4681
        public void dumpUCSTable(Database pDb, int indent, XmlNode node)
4682
        {
4683
            /**********************************************************************/
4684
            /* Get a pointer to the UCSTable                               */
4685
            /**********************************************************************/
4686
            using (UcsTable pTable = (UcsTable)pDb.UcsTableId.Open(OpenMode.ForRead))
4687
            {
4688
                /**********************************************************************/
4689
                /* Dump the Description                                               */
4690
                /**********************************************************************/
4691
                writeLine();
4692
                writeLine(indent++, pTable.GetRXClass().Name);
4693

    
4694
                /**********************************************************************/
4695
                /* Step through the UCSTable                                          */
4696
                /**********************************************************************/
4697
                foreach (ObjectId id in pTable)
4698
                {
4699
                    /********************************************************************/
4700
                    /* Open the UCSTableRecord for Reading                            */
4701
                    /********************************************************************/
4702
                    using (UcsTableRecord pRecord = (UcsTableRecord)id.Open(OpenMode.ForRead))
4703
                    {
4704
                        /********************************************************************/
4705
                        /* Dump the UCSTableRecord                                        */
4706
                        /********************************************************************/
4707
                        writeLine();
4708
                        writeLine(indent, pRecord.GetRXClass().Name);
4709
                        writeLine(indent, "Name", pRecord.Name);
4710
                        writeLine(indent, "UCS Origin", pRecord.Origin);
4711
                        writeLine(indent, "UCS x-Axis", pRecord.XAxis);
4712
                        writeLine(indent, "UCS y-Axis", pRecord.YAxis);
4713
                        dumpSymbolTableRecord(pRecord, indent, node);
4714
                    }
4715
                }
4716
            }
4717
        }
4718
        public void dumpViewports(Database pDb, int indent, XmlNode node)
4719
        {
4720
            /**********************************************************************/
4721
            /* Get a pointer to the ViewportTable                            */
4722
            /**********************************************************************/
4723
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4724
            {
4725
                /**********************************************************************/
4726
                /* Dump the Description                                               */
4727
                /**********************************************************************/
4728
                writeLine();
4729
                writeLine(indent++, pTable.GetRXClass().Name);
4730

    
4731
                /**********************************************************************/
4732
                /* Step through the ViewportTable                                    */
4733
                /**********************************************************************/
4734
                foreach (ObjectId id in pTable)
4735
                {
4736
                    /*********************************************************************/
4737
                    /* Open the ViewportTableRecord for Reading                          */
4738
                    /*********************************************************************/
4739
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4740
                    {
4741
                        /*********************************************************************/
4742
                        /* Dump the ViewportTableRecord                                      */
4743
                        /*********************************************************************/
4744
                        writeLine();
4745
                        writeLine(indent, pRecord.GetRXClass().Name);
4746
                        writeLine(indent, "Name", pRecord.Name);
4747
                        writeLine(indent, "Circle Sides", pRecord.CircleSides);
4748
                        writeLine(indent, "Fast Zooms Enabled", pRecord.FastZoomsEnabled);
4749
                        writeLine(indent, "Grid Enabled", pRecord.GridEnabled);
4750
                        writeLine(indent, "Grid Increments", pRecord.GridIncrements);
4751
                        writeLine(indent, "Icon at Origin", pRecord.IconAtOrigin);
4752
                        writeLine(indent, "Icon Enabled", pRecord.IconEnabled);
4753
                        writeLine(indent, "Iso snap Enabled", pRecord.IsometricSnapEnabled);
4754
                        writeLine(indent, "Iso Snap Pair", pRecord.SnapPair);
4755
                        writeLine(indent, "UCS Saved w/Vport", pRecord.UcsSavedWithViewport);
4756
                        writeLine(indent, "UCS follow", pRecord.UcsFollowMode);
4757
                        writeLine(indent, "Lower-Left Corner", pRecord.LowerLeftCorner);
4758
                        writeLine(indent, "Upper-Right Corner", pRecord.UpperRightCorner);
4759
                        writeLine(indent, "Snap Angle", toDegreeString(pRecord.SnapAngle));
4760
                        writeLine(indent, "Snap Base", pRecord.SnapBase);
4761
                        writeLine(indent, "Snap Enabled", pRecord.SnapEnabled);
4762
                        writeLine(indent, "Snap Increments", pRecord.SnapIncrements);
4763
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4764
                    }
4765
                }
4766
            }
4767
        }
4768

    
4769
        /************************************************************************/
4770
        /* Dump the ViewTable                                                   */
4771
        /************************************************************************/
4772
        public void dumpViews(Database pDb, int indent, XmlNode node)
4773
        {
4774
            /**********************************************************************/
4775
            /* Get a pointer to the ViewTable                                */
4776
            /**********************************************************************/
4777
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
4778
            {
4779
                /**********************************************************************/
4780
                /* Dump the Description                                               */
4781
                /**********************************************************************/
4782
                writeLine();
4783
                writeLine(indent++, pTable.GetRXClass().Name);
4784

    
4785
                /**********************************************************************/
4786
                /* Step through the ViewTable                                         */
4787
                /**********************************************************************/
4788
                foreach (ObjectId id in pTable)
4789
                {
4790
                    /*********************************************************************/
4791
                    /* Open the ViewTableRecord for Reading                              */
4792
                    /*********************************************************************/
4793
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
4794
                    {
4795
                        /*********************************************************************/
4796
                        /* Dump the ViewTableRecord                                          */
4797
                        /*********************************************************************/
4798
                        writeLine();
4799
                        writeLine(indent, pRecord.GetRXClass().Name);
4800
                        writeLine(indent, "Name", pRecord.Name);
4801
                        writeLine(indent, "Category Name", pRecord.CategoryName);
4802
                        writeLine(indent, "Layer State", pRecord.LayerState);
4803

    
4804
                        string layoutName = "";
4805
                        if (!pRecord.Layout.IsNull)
4806
                        {
4807
                            using (Layout pLayout = (Layout)pRecord.Layout.Open(OpenMode.ForRead))
4808
                                layoutName = pLayout.LayoutName;
4809
                        }
4810
                        writeLine(indent, "Layout Name", layoutName);
4811
                        writeLine(indent, "PaperSpace View", pRecord.IsPaperspaceView);
4812
                        writeLine(indent, "Associated UCS", pRecord.IsUcsAssociatedToView);
4813
                        writeLine(indent, "PaperSpace View", pRecord.ViewAssociatedToViewport);
4814
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4815
                    }
4816
                }
4817
            }
4818
        }
4819
        /************************************************************************/
4820
        /* Dump Xdata                                                           */
4821
        /************************************************************************/
4822
        public void dumpXdata(ResultBuffer xIter, int indent)
4823
        {
4824
            if (xIter == null)
4825
                return;
4826
            writeLine(indent++, "Xdata:");
4827
            /**********************************************************************/
4828
            /* Step through the ResBuf chain                                      */
4829
            /**********************************************************************/
4830
            try
4831
            {
4832
                int rsCount = xIter.Cast<TypedValue>().Count();
4833
                
4834
                foreach (TypedValue resbuf in xIter)
4835
                {
4836
                    writeLine(indent, resbuf);
4837
                }
4838
            }
4839
            catch (System.Exception ex)
4840
            {
4841
            }
4842
            
4843
        }
4844
    }
4845
    class ExProtocolExtension
4846
    {
4847
    }
4848

    
4849
    class Program
4850
    {
4851
        public static XmlDocument xml = null;
4852
        public static double OffsetX = 0;
4853
        public static double OffsetY = 0;
4854
        public static double Scale = 0;
4855
        public static double getDrawing = 0;
4856
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
4857

    
4858
        static void Main(string[] args)
4859
        {
4860
            /********************************************************************/
4861
            /* Initialize Drawings.NET.                                         */
4862
            /********************************************************************/
4863
            bool bSuccess = true;
4864
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
4865
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
4866
            {
4867
                try
4868
                {
4869
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
4870
                    /**********************************************************************/
4871
                    /* Display the Product and Version that created the executable        */
4872
                    /**********************************************************************/
4873
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
4874

    
4875
                    if (args.Length != 5)
4876
                    {
4877
                        Console.WriteLine("\n\n\tusage: OdReadExMgd <filename> <OffsetX> <OffsetY> <Scale> <GenDrawing>");
4878
                        Console.WriteLine("\nPress ENTER to continue...\n");
4879
                        Console.ReadLine();
4880
                        bSuccess = false;
4881
                    }
4882
                    else
4883
                    {
4884
                        Console.WriteLine("\n File Name = " + args[0]);
4885

    
4886
                        double.TryParse(args[1], out Program.OffsetX);
4887
                        double.TryParse(args[2], out Program.OffsetY);
4888
                        double.TryParse(args[3], out Program.Scale);
4889
                        double.TryParse(args[4], out Program.getDrawing);
4890
                        Program.xml = new XmlDocument();
4891
                        {
4892
                            XmlNode root = xml.CreateElement("ID2");
4893
                            Program.xml.AppendChild(root);
4894

    
4895
                            /******************************************************************/
4896
                            /* Create a database and load the drawing into it.                
4897
                            /* first parameter means - do not initialize database- it will be read from file
4898
                             * second parameter is not used by Teigha.NET Classic - it is left for ARX compatibility.
4899
                             * Note the 'using' clause - generally, wrappers should disposed after use, 
4900
                             * to close underlying database objects
4901
                            /******************************************************************/
4902
                            using (Database pDb = new Database(false, false))
4903
                            {
4904
                                pDb.ReadDwgFile(args[0], FileShare.Read, true, "");
4905
                                HostApplicationServices.WorkingDatabase = pDb;
4906
                                /****************************************************************/
4907
                                /* Display the File Version                                     */
4908
                                /****************************************************************/
4909
                                Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion);
4910
                                /****************************************************************/
4911
                                /* Dump the database                                            */
4912
                                /****************************************************************/
4913
                                DbDumper dumper = new DbDumper();
4914
                                dumper.ExplodeAndPurgeNestedBlocks(pDb);
4915
                                if (Program.getDrawing == 1)
4916
                                {
4917
                                    dumper.ExportPNG(pDb, args[0]);
4918
                                    dumper.ExportPDF(pDb, args[0]);
4919
                                    dumper.ExportGraphicBlocks(pDb, args[0]);
4920
                                }
4921

    
4922
                                dumper.dump(pDb, 0, Program.xml.DocumentElement);
4923
                            }
4924
                            Program.xml.Save(Path.Combine(Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]) + ".xml"));
4925
                        }
4926
                    }
4927
                }
4928
                /********************************************************************/
4929
                /* Display the error                                                */
4930
                /********************************************************************/
4931
                catch (System.Exception e)
4932
                {
4933
                    bSuccess = false;
4934
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
4935
                }
4936

    
4937
                if (bSuccess)
4938
                    Console.WriteLine("OdReadExMgd Finished Successfully");
4939
            }
4940
        }
4941
    }
4942
}
클립보드 이미지 추가 (최대 크기: 500 MB)