프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ 7ada4aac

이력 | 보기 | 이력해설 | 다운로드 (232 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
        public DbDumper() { }
46

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

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

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

    
109
            return path;
110
        }
111
        static string shortenPath(string Inpath)
112
        {
113
            return shortenPath(Inpath, 40);
114
        }
115

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

    
125
            const int tabSize = 2;
126

    
127
            /**********************************************************************/
128
            /* Indent leftString with spaces characters                           */
129
            /**********************************************************************/
130
            string newleftString = spaces.Substring(0, tabSize * indent) + leftString.ToString();
131

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

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

    
175
                    XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
176
                    MinExtentsAttr.Value = ext.MinPoint.ToString();
177
                    node.Attributes.SetNamedItem(MinExtentsAttr);
178

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

    
187
                XmlAttribute LayerAttr = Program.xml.CreateAttribute("Layer");
188
                LayerAttr.Value = pEnt.Layer;
189
                node.Attributes.SetNamedItem(LayerAttr);
190

    
191
                writeLine(indent, "Color Index", pEnt.ColorIndex);
192
                writeLine(indent, "Color", pEnt.Color);
193

    
194
                XmlAttribute LinetypeAttr = Program.xml.CreateAttribute("Linetype");
195
                LinetypeAttr.Value = pEnt.Linetype;
196
                node.Attributes.SetNamedItem(LinetypeAttr);
197

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

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

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

    
233
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
234
                XAttr.Value = pText.Position.X.ToString();
235
                TextNode.Attributes.SetNamedItem(XAttr);
236

    
237
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
238
                YAttr.Value = pText.Position.Y.ToString();
239
                TextNode.Attributes.SetNamedItem(YAttr);
240

    
241
                TextNode.InnerText = pText.TextString.Replace("%%U", "");
242

    
243
                XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
244
                AngleAttr.Value = pText.Rotation.ToString();
245
                TextNode.Attributes.SetNamedItem(AngleAttr);
246

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

    
251
                XmlAttribute HeightAttr = Program.xml.CreateAttribute("Height");
252
                HeightAttr.Value = pText.Height.ToString();
253
                TextNode.Attributes.SetNamedItem(HeightAttr);
254

    
255
                XmlAttribute WidthFactorAttr = Program.xml.CreateAttribute("WidthFactor");
256
                WidthFactorAttr.Value = pText.WidthFactor.ToString();
257
                TextNode.Attributes.SetNamedItem(WidthFactorAttr);
258

    
259
                XmlAttribute IsDefaultAlignmentAttr = Program.xml.CreateAttribute("IsDefaultAlignment");
260
                IsDefaultAlignmentAttr.Value = pText.IsDefaultAlignment.ToString();
261
                TextNode.Attributes.SetNamedItem(IsDefaultAlignmentAttr);
262

    
263
                XmlAttribute AlignmentPointAttr = Program.xml.CreateAttribute("AlignmentPoint");
264
                AlignmentPointAttr.Value = pText.AlignmentPoint.ToString();
265
                TextNode.Attributes.SetNamedItem(AlignmentPointAttr);
266

    
267
                XmlAttribute HorizontalModeAttr = Program.xml.CreateAttribute("HorizontalMode");
268
                HorizontalModeAttr.Value = pText.HorizontalMode.ToString();
269
                TextNode.Attributes.SetNamedItem(HorizontalModeAttr);
270

    
271
                XmlAttribute VerticalModeAttr = Program.xml.CreateAttribute("VerticalMode");
272
                VerticalModeAttr.Value = pText.VerticalMode.ToString();
273
                TextNode.Attributes.SetNamedItem(VerticalModeAttr);
274

    
275
                XmlAttribute IsMirroredInXAttr = Program.xml.CreateAttribute("IsMirroredInX");
276
                IsMirroredInXAttr.Value = pText.IsMirroredInX.ToString();
277
                TextNode.Attributes.SetNamedItem(IsMirroredInXAttr);
278

    
279
                XmlAttribute IsMirroredInYAttr = Program.xml.CreateAttribute("IsMirroredInY");
280
                IsMirroredInYAttr.Value = pText.IsMirroredInY.ToString();
281
                TextNode.Attributes.SetNamedItem(IsMirroredInYAttr);
282

    
283
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
284
                ObliqueAttr.Value = pText.Oblique.ToString();
285
                TextNode.Attributes.SetNamedItem(ObliqueAttr);
286

    
287
                XmlAttribute TextStyleAttr = Program.xml.CreateAttribute("TextStyle");
288
                TextStyleAttr.Value = pText.TextStyleName;
289
                TextNode.Attributes.SetNamedItem(TextStyleAttr);
290

    
291
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
292
                NormalAttr.Value = pText.Normal.ToString();
293
                TextNode.Attributes.SetNamedItem(NormalAttr);
294

    
295
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
296
                ThicknessAttr.Value = pText.Thickness.ToString();
297
                TextNode.Attributes.SetNamedItem(ThicknessAttr);
298

    
299
                dumpEntityData(pText, indent, TextNode);
300

    
301
                node.AppendChild(TextNode);
302
            }
303

    
304
            return TextNode;
305
        }
306

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

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

    
326
                XmlAttribute TagAttr = Program.xml.CreateAttribute("Tag");
327
                TagAttr.Value = pAttr.Tag;
328
                TextNode.Attributes.SetNamedItem(TagAttr);
329
            }
330
        }
331

    
332
        /************************************************************************/
333
        /* Dump Block Reference Data                                             */
334
        /************************************************************************/
335
        static XmlNode dumpBlockRefData(BlockReference pBlkRef, int indent, XmlNode node)
336
        {
337
            if (node != null)
338
            {
339
                XmlNode BlockReferenceNode = Program.xml.CreateElement(pBlkRef.GetRXClass().Name);
340

    
341
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
342
                HandleAttr.Value = pBlkRef.Handle.ToString();
343
                BlockReferenceNode.Attributes.SetNamedItem(HandleAttr);
344

    
345
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
346
                XAttr.Value = pBlkRef.Position.X.ToString();
347
                BlockReferenceNode.Attributes.SetNamedItem(XAttr);
348

    
349
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
350
                YAttr.Value = pBlkRef.Position.Y.ToString();
351
                BlockReferenceNode.Attributes.SetNamedItem(YAttr);
352

    
353
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
354
                ZAttr.Value = pBlkRef.Position.Z.ToString();
355
                BlockReferenceNode.Attributes.SetNamedItem(ZAttr);
356

    
357
                XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
358
                AngleAttr.Value = pBlkRef.Rotation.ToString();
359
                BlockReferenceNode.Attributes.SetNamedItem(AngleAttr);
360

    
361
                XmlAttribute ScaleFactorsAttr = Program.xml.CreateAttribute("ScaleFactors");
362
                ScaleFactorsAttr.Value = pBlkRef.ScaleFactors.ToString();
363
                BlockReferenceNode.Attributes.SetNamedItem(ScaleFactorsAttr);
364

    
365
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
366
                NormalAttr.Value = pBlkRef.Normal.ToString();
367
                BlockReferenceNode.Attributes.SetNamedItem(NormalAttr);
368

    
369
                XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
370
                NameAttr.Value = pBlkRef.Name;
371
                BlockReferenceNode.Attributes.SetNamedItem(NameAttr);
372

    
373
                // BlockReference DBPoint
374
                string nodePointValue = string.Empty;
375
                Dictionary<long, Point3d> nodePointDic = new Dictionary<long, Point3d>();
376
                using (BlockTableRecord pBtr = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
377
                {
378
                    foreach (ObjectId blkid in pBtr)
379
                    {
380
                        using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
381
                        {
382
                            if (pBlkEnt.GetRXClass().Name == "AcDbPoint")
383
                            {
384
                                DBPoint pt = (DBPoint)pBlkEnt;
385
                                Point3d nodePt = pt.Position.TransformBy(pBlkRef.BlockTransform);
386
                                if (nodePt == pBlkRef.Position)
387
                                {
388
                                    continue;
389
                                }
390

    
391
                                nodePointDic.Add(Convert.ToInt64(pt.Handle.ToString(), 16), nodePt);
392
                            }
393
                        }
394
                    }
395
                }
396
                if (nodePointDic.Count > 0)
397
                {
398
                    foreach (KeyValuePair<long, Point3d> item in nodePointDic.OrderBy(o => o.Key))
399
                    {
400
                        nodePointValue += item.Value.ToString() + "/";
401
                    }
402
                    nodePointValue = nodePointValue.Substring(0, nodePointValue.Length - 1);
403
                }
404

    
405
                XmlAttribute NodePointAttr = Program.xml.CreateAttribute("Nodes");
406
                NodePointAttr.Value = nodePointValue;
407
                BlockReferenceNode.Attributes.SetNamedItem(NodePointAttr);
408

    
409
                Matrix3d blockTransform = pBlkRef.BlockTransform;
410
                CoordinateSystem3d cs = blockTransform.CoordinateSystem3d;
411
                writeLine(indent + 1, "Origin", cs.Origin);
412
                writeLine(indent + 1, "u-Axis", cs.Xaxis);
413
                writeLine(indent + 1, "v-Axis", cs.Yaxis);
414
                writeLine(indent + 1, "z-Axis", cs.Zaxis);
415

    
416
                dumpEntityData(pBlkRef, indent, BlockReferenceNode);
417

    
418
                DBObjectCollection objColl = new DBObjectCollection();
419
                pBlkRef.Explode(objColl);
420
                foreach (var obj in objColl)
421
                {
422
                    if (obj is DBText)
423
                    {
424
                        dumpTextData(obj as DBText, indent, BlockReferenceNode);
425
                    }
426
                }
427

    
428
                /**********************************************************************/
429
                /* Dump the attributes                                                */
430
                /**********************************************************************/
431
                int i = 0;
432
                AttributeCollection attCol = pBlkRef.AttributeCollection;
433
                foreach (ObjectId id in attCol)
434
                {
435
                    try
436
                    {
437
                        using (AttributeReference pAttr = (AttributeReference)id.Open(OpenMode.ForRead))
438
                            dumpAttributeData(indent, pAttr, i++, BlockReferenceNode);
439
                    }
440
                    catch (System.Exception)
441
                    {
442

    
443
                    }
444
                }
445

    
446
                node.AppendChild(BlockReferenceNode);
447

    
448
                return BlockReferenceNode;
449
            }
450

    
451
            return null;
452
        }
453
        /************************************************************************/
454
        /* Dump data common to all OdDbCurves                                   */
455
        /************************************************************************/
456
        static void dumpCurveData(Entity pEnt, int indent, XmlNode node)
457
        {
458
            if (node != null)
459
            {
460
                Curve pEntity = (Curve)pEnt;
461
                try
462
                {
463
                    writeLine(indent, "Start Point", pEntity.StartPoint);
464
                    writeLine(indent, "End Point", pEntity.EndPoint);
465
                }
466
                catch (System.Exception)
467
                {
468
                }
469
                writeLine(indent, "Closed", pEntity.Closed);
470
                writeLine(indent, "Periodic", pEntity.IsPeriodic);
471

    
472
                try
473
                {
474
                    writeLine(indent, "Area", pEntity.Area);
475
                }
476
                catch (System.Exception)
477
                {
478
                }
479
                dumpEntityData(pEntity, indent, node);
480
            }
481
        }
482

    
483
        /************************************************************************/
484
        /* Dump Dimension data                                                  */
485
        /************************************************************************/
486
        static XmlNode dumpDimData(Dimension pDim, int indent, XmlNode node)
487
        {
488
            if (node != null)
489
            {
490
                XmlElement DimDataNode = Program.xml.CreateElement("DimData");
491

    
492
                XmlAttribute CurrentMeasurementAttr = Program.xml.CreateAttribute("CurrentMeasurement");
493
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
494
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
495

    
496
                XmlAttribute DimensionTextAttr = Program.xml.CreateAttribute("DimensionText");
497
                DimensionTextAttr.Value = pDim.DimensionText.ToString();
498
                DimDataNode.Attributes.SetNamedItem(DimensionTextAttr);
499

    
500
                if (pDim.CurrentMeasurement >= 0.0)
501
                {
502
                    XmlAttribute FormattedMeasurementAttr = Program.xml.CreateAttribute("FormattedMeasurement");
503
                    FormattedMeasurementAttr.Value = pDim.FormatMeasurement(pDim.CurrentMeasurement, pDim.DimensionText);
504
                    DimDataNode.Attributes.SetNamedItem(FormattedMeasurementAttr);
505
                }
506
                if (pDim.DimBlockId.IsNull)
507
                {
508
                    writeLine(indent, "Dimension Block NULL");
509
                }
510
                else
511
                {
512
                    using (BlockTableRecord btr = (BlockTableRecord)pDim.DimBlockId.Open(OpenMode.ForRead))
513
                    {
514
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
515
                        NameAttr.Value = btr.Name;
516
                        DimDataNode.Attributes.SetNamedItem(NameAttr);
517
                    }
518
                }
519

    
520
                XmlAttribute DimBlockPositionAttr = Program.xml.CreateAttribute("DimBlockPosition");
521
                DimBlockPositionAttr.Value = pDim.DimBlockPosition.ToString();
522
                DimDataNode.Attributes.SetNamedItem(DimBlockPositionAttr);
523

    
524
                XmlAttribute TextPositionAttr = Program.xml.CreateAttribute("TextPosition");
525
                TextPositionAttr.Value = pDim.TextPosition.ToString();
526
                DimDataNode.Attributes.SetNamedItem(TextPositionAttr);
527

    
528
                XmlAttribute TextRotationAttr = Program.xml.CreateAttribute("TextRotation");
529
                TextRotationAttr.Value = pDim.TextRotation.ToString();
530
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
531

    
532
                XmlAttribute DimensionStyleNameAttr = Program.xml.CreateAttribute("DimensionStyleName");
533
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
534
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
535

    
536
                XmlAttribute DimtfillclrAttr = Program.xml.CreateAttribute("Dimtfillclr");
537
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
538
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
539

    
540
                XmlAttribute DimtfillAttr = Program.xml.CreateAttribute("Dimtfill");
541
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
542
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
543

    
544
                XmlAttribute Dimltex1Attr = Program.xml.CreateAttribute("Dimltex1");
545
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
546
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
547

    
548
                XmlAttribute Dimltex2Attr = Program.xml.CreateAttribute("Dimltex2");
549
                Dimltex2Attr.Value = pDim.Dimltex2.ToString();
550
                DimDataNode.Attributes.SetNamedItem(Dimltex2Attr);
551

    
552
                XmlAttribute DimltypeAttr = Program.xml.CreateAttribute("Dimltype");
553
                DimltypeAttr.Value = pDim.Dimltype.ToString();
554
                DimDataNode.Attributes.SetNamedItem(DimltypeAttr);
555

    
556
                XmlAttribute HorizontalRotationAttr = Program.xml.CreateAttribute("HorizontalRotation");
557
                HorizontalRotationAttr.Value = pDim.HorizontalRotation.ToString();
558
                DimDataNode.Attributes.SetNamedItem(HorizontalRotationAttr);
559

    
560
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
561
                ElevationAttr.Value = pDim.Elevation.ToString();
562
                DimDataNode.Attributes.SetNamedItem(ElevationAttr);
563

    
564
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
565
                NormalAttr.Value = pDim.Normal.ToString();
566
                DimDataNode.Attributes.SetNamedItem(NormalAttr);
567

    
568
                dumpEntityData(pDim, indent, node);
569

    
570
                return DimDataNode;
571
            }
572

    
573
            return null;
574
        }
575

    
576
        /************************************************************************/
577
        /* 2 Line Angular Dimension Dumper                                      */
578
        /************************************************************************/
579
        static XmlNode dump(LineAngularDimension2 pDim, int indent, XmlNode node)
580
        {
581
            if (node != null)
582
            {
583
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
584

    
585
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
586
                HandleAttr.Value = pDim.Handle.ToString();
587
                DimNode.Attributes.SetNamedItem(HandleAttr);
588

    
589
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
590
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
591
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
592

    
593
                XmlAttribute XLine1StartAttr = Program.xml.CreateAttribute("XLine1Start");
594
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
595
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
596

    
597
                XmlAttribute XLine1EndAttr = Program.xml.CreateAttribute("XLine1End");
598
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
599
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
600

    
601
                XmlAttribute XLine2StartAttr = Program.xml.CreateAttribute("XLine2Start");
602
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
603
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
604

    
605
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
606
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
607
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
608

    
609
                dumpDimData(pDim, indent, DimNode);
610

    
611
                return DimNode;
612
            }
613

    
614
            return null;
615
        }
616

    
617
        /************************************************************************/
618
        /* Dump 2D Vertex data                                                  */
619
        /************************************************************************/
620
        static XmlNode dump2dVertex(int indent, Vertex2d pVertex, int i, XmlNode node)
621
        {
622
            if (node != null)
623
            {
624
                XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
625

    
626
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
627
                HandleAttr.Value = pVertex.Handle.ToString();
628
                VertexNode.Attributes.SetNamedItem(HandleAttr);
629

    
630
                XmlAttribute VertexTypeAttr = Program.xml.CreateAttribute("VertexType");
631
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
632
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
633

    
634
                XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
635
                PositionAttr.Value = pVertex.Position.ToString();
636
                VertexNode.Attributes.SetNamedItem(PositionAttr);
637

    
638
                XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
639
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
640
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
641

    
642
                XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
643
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
644
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
645

    
646
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
647
                BulgeAttr.Value = pVertex.Bulge.ToString();
648
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
649

    
650
                if (pVertex.Bulge != 0)
651
                {
652
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
653
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
654
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
655
                }
656

    
657
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
658
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
659
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
660
                if (pVertex.TangentUsed)
661
                {
662
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
663
                    TangentAttr.Value = pVertex.Tangent.ToString();
664
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
665
                }
666

    
667
                node.AppendChild(VertexNode);
668

    
669
                return VertexNode;
670
            }
671

    
672
            return null;
673
        }
674

    
675
        /************************************************************************/
676
        /* 2D Polyline Dumper                                                   */
677
        /************************************************************************/
678
        static XmlNode dump(Polyline2d pPolyline, int indent, XmlNode node)
679
        {
680
            /********************************************************************/
681
            /* Dump the vertices                                                */
682
            /********************************************************************/
683
            List<Vertex2d> Vertices = new List<Vertex2d>();
684
            int i = 0;
685
            foreach (ObjectId obj in pPolyline)
686
            {
687
                using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
688
                {
689
                    if (dbObj is Vertex2d)
690
                    {
691
                        Vertices.Add((Vertex2d)dbObj);
692
                        /// dump2dVertex(indent, (Vertex2d)dbObj, i++);
693
                    }
694
                }
695
            }
696

    
697
            if (node != null)
698
            {
699
                XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
700

    
701
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
702
                HandleAttr.Value = pPolyline.Handle.ToString();
703
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
704

    
705
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
706
                CountAttr.Value = Vertices.Count.ToString();
707
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
708

    
709
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
710
                ElevationAttr.Value = pPolyline.Elevation.ToString();
711
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
712

    
713
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
714
                NormalAttr.Value = pPolyline.Normal.ToString();
715
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
716

    
717
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
718
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
719
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
720

    
721
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
722
                ClosedAttr.Value = pPolyline.Closed.ToString();
723
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
724

    
725
                foreach (var vt in Vertices)
726
                {
727
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
728

    
729
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
730
                    XAttr.Value = vt.Position.X.ToString();
731
                    VertexNode.Attributes.SetNamedItem(XAttr);
732

    
733
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
734
                    YAttr.Value = vt.Position.Y.ToString();
735
                    VertexNode.Attributes.SetNamedItem(YAttr);
736

    
737
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
738
                    ZAttr.Value = vt.Position.Z.ToString();
739
                    VertexNode.Attributes.SetNamedItem(ZAttr);
740

    
741
                    Polyline2dNode.AppendChild(VertexNode);
742
                }
743

    
744
                dumpCurveData(pPolyline, indent, node);
745

    
746
                node.AppendChild(Polyline2dNode);
747

    
748
                return Polyline2dNode;
749
            }
750

    
751
            return null;
752
        }
753

    
754

    
755
        /************************************************************************/
756
        /* Dump 3D Polyline Vertex data                                         */
757
        /************************************************************************/
758
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
759
        {
760
            if (node != null)
761
            {
762
                XmlNode VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
763

    
764
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
765
                HandleAttr.Value = pVertex.Handle.ToString();
766
                VertexNode.Attributes.SetNamedItem(HandleAttr);
767

    
768
                XmlAttribute VertexxTypeAttr = Program.xml.CreateAttribute("VertexType");
769
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
770
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
771

    
772
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
773
                XAttr.Value = pVertex.Position.X.ToString();
774
                VertexNode.Attributes.SetNamedItem(XAttr);
775

    
776
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
777
                YAttr.Value = pVertex.Position.Y.ToString();
778
                VertexNode.Attributes.SetNamedItem(YAttr);
779

    
780
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
781
                ZAttr.Value = pVertex.Position.Z.ToString();
782
                VertexNode.Attributes.SetNamedItem(ZAttr);
783

    
784
                node.AppendChild(VertexNode);
785

    
786
                return VertexNode;
787
            }
788

    
789
            return null;
790
        }
791

    
792
        /************************************************************************/
793
        /* 3D Polyline Dumper                                                   */
794
        /************************************************************************/
795
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
796
        {
797
            if (node != null)
798
            {
799
                XmlNode pPolylineNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
800

    
801
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
802
                HandleAttr.Value = pPolyline.Handle.ToString();
803
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
804

    
805
                /********************************************************************/
806
                /* Dump the vertices                                                */
807
                /********************************************************************/
808
                int i = 0;
809
                foreach (ObjectId obj in pPolyline)
810
                {
811
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
812
                    {
813
                        if (dbObj is PolylineVertex3d)
814
                        {
815
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
816
                        }
817
                    }
818
                }
819
                dumpCurveData(pPolyline, indent, pPolylineNode);
820

    
821
                node.AppendChild(pPolylineNode);
822

    
823
                return pPolylineNode;
824
            }
825

    
826
            return null;
827
        }
828

    
829

    
830
        /************************************************************************/
831
        /* 3DSolid Dumper                                                       */
832
        /************************************************************************/
833
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
834
        {
835
            if (node != null)
836
            {
837
                XmlNode SolidNode = Program.xml.CreateElement(pSolid.GetRXClass().Name);
838

    
839
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
840
                HandleAttr.Value = pSolid.Handle.ToString();
841
                SolidNode.Attributes.SetNamedItem(HandleAttr);
842

    
843
                dumpEntityData(pSolid, indent, node);
844

    
845
                node.AppendChild(SolidNode);
846

    
847
                return SolidNode;
848
            }
849

    
850
            return null;
851
        }
852

    
853

    
854
        /************************************************************************/
855
        /* 3 Point Angular Dimension Dumper                                     */
856
        /************************************************************************/
857
        XmlNode dump(Point3AngularDimension pDim, int indent, XmlNode node)
858
        {
859
            if (node != null)
860
            {
861
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
862

    
863
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
864
                HandleAttr.Value = pDim.Handle.ToString();
865
                DimNode.Attributes.SetNamedItem(HandleAttr);
866

    
867
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
868
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
869
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
870

    
871
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
872
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
873
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
874

    
875
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
876
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
877
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
878

    
879
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
880
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
881
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
882

    
883
                dumpDimData(pDim, indent, DimNode);
884

    
885
                return DimNode;
886
            }
887

    
888
            return null;
889
        }
890

    
891
        /************************************************************************/
892
        /* Aligned Dimension Dumper                                             */
893
        /************************************************************************/
894
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
895
        {
896
            if (node != null)
897
            {
898
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
899

    
900
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
901
                HandleAttr.Value = pDim.Handle.ToString();
902
                DimNode.Attributes.SetNamedItem(HandleAttr);
903

    
904
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
905
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
906
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
907

    
908
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
909
                ObliqueAttr.Value = pDim.Oblique.ToString();
910
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
911

    
912
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
913
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
914
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
915

    
916
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
917
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
918
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
919

    
920
                dumpDimData(pDim, indent, DimNode);
921

    
922
                return DimNode;
923
            }
924

    
925
            return null;
926
        }
927

    
928
        /************************************************************************/
929
        /* Arc Dumper                                                           */
930
        /************************************************************************/
931
        XmlNode dump(Arc pArc, int indent, XmlNode node)
932
        {
933
            if (node != null)
934
            {
935
                XmlElement ArcNode = Program.xml.CreateElement(pArc.GetRXClass().Name);
936

    
937
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
938
                XAttr.Value = pArc.Center.X.ToString();
939
                ArcNode.Attributes.SetNamedItem(XAttr);
940

    
941
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
942
                YAttr.Value = pArc.Center.Y.ToString();
943
                ArcNode.Attributes.SetNamedItem(YAttr);
944

    
945
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
946
                ZAttr.Value = pArc.Center.Z.ToString();
947
                ArcNode.Attributes.SetNamedItem(ZAttr);
948

    
949
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
950
                RadiusAttr.Value = pArc.Radius.ToString();
951
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
952

    
953
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
954
                StartAngleAttr.Value = pArc.StartAngle.ToString();
955
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
956

    
957
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
958
                EndAngleAttr.Value = pArc.EndAngle.ToString();
959
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
960

    
961
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
962
                NormalAttr.Value = pArc.Normal.ToString();
963
                ArcNode.Attributes.SetNamedItem(NormalAttr);
964

    
965
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
966
                ThicknessAttr.Value = pArc.Normal.ToString();
967
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
968

    
969
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
970
                dumpCurveData(pArc, indent, ArcNode);
971

    
972
                node.AppendChild(ArcNode);
973

    
974
                return ArcNode;
975
            }
976

    
977
            return null;
978
        }
979

    
980
        /************************************************************************/
981
        /* Arc Dimension Dumper                                                 */
982
        /************************************************************************/
983
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
984
        {
985
            if (node != null)
986
            {
987
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
988

    
989
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
990
                HandleAttr.Value = pDim.Handle.ToString();
991
                DimNode.Attributes.SetNamedItem(HandleAttr);
992

    
993
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
994
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
995
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
996

    
997
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
998
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
999
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
1000

    
1001
                XmlAttribute ArcSymbolTypeAttr = Program.xml.CreateAttribute("ArcSymbolType");
1002
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1003
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1004

    
1005
                XmlAttribute IsPartialAttr = Program.xml.CreateAttribute("IsPartial");
1006
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1007
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1008

    
1009
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1010
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1011
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1012

    
1013
                if (pDim.HasLeader)
1014
                {
1015
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1016
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1017
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1018

    
1019
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1020
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1021
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1022
                }
1023

    
1024
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1025
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1026
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1027

    
1028
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1029
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1030
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1031

    
1032
                dumpDimData(pDim, indent, DimNode);
1033

    
1034
                return DimNode;
1035
            }
1036

    
1037
            return null;
1038
        }
1039

    
1040

    
1041
        /************************************************************************/
1042
        /* Block Reference Dumper                                                */
1043
        /************************************************************************/
1044
        void dump(BlockReference pBlkRef, int indent, XmlNode node)
1045
        {
1046
            using (BlockTableRecord pRecord = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead))
1047
            {
1048
                XmlNode BlockRefNode = dumpBlockRefData(pBlkRef, indent, node);
1049
                if (BlockRefNode != null)
1050
                {
1051
                    XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
1052
                    NameAttr.Value = pRecord.Name;
1053
                    BlockRefNode.Attributes.SetNamedItem(NameAttr);
1054
                }
1055
            }
1056
        }
1057

    
1058
        /************************************************************************/
1059
        /* Body Dumper                                                          */
1060
        /************************************************************************/
1061
        XmlNode dump(Body pBody, int indent, XmlNode node)
1062
        {
1063
            if (node != null)
1064
            {
1065
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1066

    
1067
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1068
                HandleAttr.Value = pBody.Handle.ToString();
1069
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1070

    
1071
                dumpEntityData(pBody, indent, BodyNode);
1072

    
1073
                return BodyNode;
1074
            }
1075

    
1076
            return null;
1077
        }
1078

    
1079

    
1080
        /************************************************************************/
1081
        /* Circle Dumper                                                        */
1082
        /************************************************************************/
1083
        XmlNode dump(Circle pCircle, int indent, XmlNode node)
1084
        {
1085
            if (node != null)
1086
            {
1087
                XmlElement CircleNode = Program.xml.CreateElement(pCircle.GetRXClass().Name);
1088

    
1089
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1090
                XAttr.Value = pCircle.Center.X.ToString();
1091
                CircleNode.Attributes.SetNamedItem(XAttr);
1092

    
1093
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1094
                YAttr.Value = pCircle.Center.Y.ToString();
1095
                CircleNode.Attributes.SetNamedItem(YAttr);
1096

    
1097
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1098
                RadiusAttr.Value = pCircle.Radius.ToString();
1099
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1100

    
1101
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1102
                NormalAttr.Value = pCircle.Normal.ToString();
1103
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1104

    
1105
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1106
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1107
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1108

    
1109
                dumpCurveData(pCircle, indent, CircleNode);
1110

    
1111
                node.AppendChild(CircleNode);
1112

    
1113
                return CircleNode;
1114
            }
1115

    
1116
            return null;
1117
        }
1118

    
1119
        /************************************************************************/
1120
        /* Diametric Dimension Dumper                                           */
1121
        /************************************************************************/
1122
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1123
        {
1124
            if (node != null)
1125
            {
1126
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1127

    
1128
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1129
                HandleAttr.Value = pDim.Handle.ToString();
1130
                DimNode.Attributes.SetNamedItem(HandleAttr);
1131

    
1132
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
1133
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1134
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1135

    
1136
                XmlAttribute FarChordPointAttr = Program.xml.CreateAttribute("FarChordPoint");
1137
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1138
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1139

    
1140
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1141
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1142
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1143

    
1144
                dumpDimData(pDim, indent, DimNode);
1145

    
1146
                return DimNode;
1147
            }
1148

    
1149
            return null;
1150
        }
1151

    
1152
        /************************************************************************/
1153
        /* Ellipse Dumper                                                       */
1154
        /************************************************************************/
1155
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1156
        {
1157
            if (node != null)
1158
            {
1159
                XmlElement EllipseNode = Program.xml.CreateElement(pEllipse.GetRXClass().Name);
1160

    
1161
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1162

    
1163
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1164
                XAttr.Value = pEllipse.Center.X.ToString();
1165
                EllipseNode.Attributes.SetNamedItem(XAttr);
1166

    
1167
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1168
                YAttr.Value = pEllipse.Center.Y.ToString();
1169
                EllipseNode.Attributes.SetNamedItem(YAttr);
1170

    
1171
                XmlAttribute MajorAxisAttr = Program.xml.CreateAttribute("MajorAxis");
1172
                MajorAxisAttr.Value = pEllipse.MajorAxis.ToString();
1173
                EllipseNode.Attributes.SetNamedItem(MajorAxisAttr);
1174

    
1175
                XmlAttribute MinorAxisAttr = Program.xml.CreateAttribute("MinorAxis");
1176
                MinorAxisAttr.Value = pEllipse.MinorAxis.ToString();
1177
                EllipseNode.Attributes.SetNamedItem(MinorAxisAttr);
1178

    
1179
                XmlAttribute MajorRadiusAttr = Program.xml.CreateAttribute("MajorRadius");
1180
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1181
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1182

    
1183
                XmlAttribute MinorRadiusAttr = Program.xml.CreateAttribute("MinorRadius");
1184
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1185
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1186

    
1187
                XmlAttribute RadiusRatioAttr = Program.xml.CreateAttribute("RadiusRatio");
1188
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1189
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1190

    
1191
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1192
                StartAngleAttr.Value = pEllipse.StartAngle.ToString();
1193
                EllipseNode.Attributes.SetNamedItem(StartAngleAttr);
1194

    
1195
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1196
                EndAngleAttr.Value = pEllipse.EndAngle.ToString();
1197
                EllipseNode.Attributes.SetNamedItem(EndAngleAttr);
1198

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

    
1203
                dumpCurveData(pEllipse, indent, EllipseNode);
1204

    
1205
                node.AppendChild(EllipseNode);
1206
            }
1207
        }
1208

    
1209
        /************************************************************************/
1210
        /* Face Dumper                                                       */
1211
        /************************************************************************/
1212
        XmlNode dump(Face pFace, int indent, XmlNode node)
1213
        {
1214
            if (node != null)
1215
            {
1216
                XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1217

    
1218
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1219
                HandleAttr.Value = pFace.Handle.ToString();
1220
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1221

    
1222
                for (short i = 0; i < 4; i++)
1223
                {
1224
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1225

    
1226
                    Point3d pt = pFace.GetVertexAt(i);
1227
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1228
                    XAttr.Value = pt.X.ToString();
1229
                    VertexNode.Attributes.SetNamedItem(XAttr);
1230

    
1231
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1232
                    YAttr.Value = pt.Y.ToString();
1233
                    VertexNode.Attributes.SetNamedItem(YAttr);
1234

    
1235
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1236
                    ZAttr.Value = pt.Z.ToString();
1237
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1238

    
1239
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1240
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1241
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1242

    
1243
                    FaceNode.AppendChild(VertexNode);
1244
                }
1245
                dumpEntityData(pFace, indent, FaceNode);
1246

    
1247
                node.AppendChild(FaceNode);
1248

    
1249
                return FaceNode;
1250
            }
1251

    
1252
            return null;
1253
        }
1254

    
1255
        /************************************************************************/
1256
        /* FCF Dumper                                                           */
1257
        /************************************************************************/
1258
        void dump(FeatureControlFrame pFcf, int indent)
1259
        {
1260
            writeLine(indent++, pFcf.GetRXClass().Name, pFcf.Handle);
1261
            writeLine(indent, "Location", pFcf.Location);
1262
            writeLine(indent, "Text", pFcf.Text);
1263
            writeLine(indent, "Dimension Style", pFcf.DimensionStyleName);
1264
            writeLine(indent, "Dimension Gap", pFcf.Dimgap);
1265
            writeLine(indent, "Dimension Scale", pFcf.Dimscale);
1266
            writeLine(indent, "Text Height", pFcf.Dimtxt);
1267
            writeLine(indent, "Frame Color", pFcf.Dimclrd);
1268
            writeLine(indent, "Text Style", pFcf.TextStyleName);
1269
            writeLine(indent, "Text Color", pFcf.Dimclrd);
1270
            writeLine(indent, "X-Direction", pFcf.Direction);
1271
            writeLine(indent, "Normal", pFcf.Normal);
1272
            dumpEntityData(pFcf, indent, Program.xml.DocumentElement);
1273
        }
1274

    
1275
        /************************************************************************/
1276
        /* Hatch Dumper                                                         */
1277
        /************************************************************************/
1278
        /***********************************************************************/
1279
        /* Dump Polyline Loop                                                  */
1280
        /***********************************************************************/
1281
        static void dumpPolylineType(int loopIndex, Hatch pHatch, int indent)
1282
        {
1283
            HatchLoop hl = pHatch.GetLoopAt(loopIndex);
1284
            for (int i = 0; i < hl.Polyline.Count; i++)
1285
            {
1286
                BulgeVertex bv = hl.Polyline[i];
1287
                writeLine(indent, "Vertex " + i.ToString(), bv.Vertex.ToString());
1288
                writeLine(indent + 1, "Bulge " + i.ToString(), bv.Bulge);
1289
                writeLine(indent + 1, "Bulge angle " + i.ToString(), toDegreeString(4 * Math.Atan(bv.Bulge)));
1290
            }
1291
        }
1292

    
1293
        /**********************************************************************/
1294
        /* Dump Circular Arc Edge                                             */
1295
        /**********************************************************************/
1296
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1297
        {
1298
            writeLine(indent, "Center", pCircArc.Center);
1299
            writeLine(indent, "Radius", pCircArc.Radius);
1300
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1301
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1302
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1303
        }
1304

    
1305
        /**********************************************************************/
1306
        /* Dump Elliptical Arc Edge                                           */
1307
        /**********************************************************************/
1308
        static void dumpEllipticalArcEdge(int indent, EllipticalArc2d pEllipArc)
1309
        {
1310
            writeLine(indent, "Center", pEllipArc.Center);
1311
            writeLine(indent, "Major Radius", pEllipArc.MajorRadius);
1312
            writeLine(indent, "Minor Radius", pEllipArc.MinorRadius);
1313
            writeLine(indent, "Major Axis", pEllipArc.MajorAxis);
1314
            writeLine(indent, "Minor Axis", pEllipArc.MinorAxis);
1315
            writeLine(indent, "Start Angle", toDegreeString(pEllipArc.StartAngle));
1316
            writeLine(indent, "End Angle", toDegreeString(pEllipArc.EndAngle));
1317
            writeLine(indent, "Clockwise", pEllipArc.IsClockWise);
1318
        }
1319

    
1320
        /**********************************************************************/
1321
        /* Dump NurbCurve Edge                                           */
1322
        /**********************************************************************/
1323
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1324
        {
1325
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1326
            writeLine(indent, "Degree", d.Degree);
1327
            writeLine(indent, "Rational", d.Rational);
1328
            writeLine(indent, "Periodic", d.Periodic);
1329

    
1330
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1331
            for (int i = 0; i < d.ControlPoints.Count; i++)
1332
            {
1333
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1334
            }
1335
            writeLine(indent, "Number of Knots", d.Knots.Count);
1336
            for (int i = 0; i < d.Knots.Count; i++)
1337
            {
1338
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1339
            }
1340

    
1341
            if (d.Rational)
1342
            {
1343
                writeLine(indent, "Number of Weights", d.Weights.Count);
1344
                for (int i = 0; i < d.Weights.Count; i++)
1345
                {
1346
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1347
                }
1348
            }
1349
        }
1350

    
1351
        /***********************************************************************/
1352
        /* Dump Edge Loop                                                      */
1353
        /***********************************************************************/
1354
        static void dumpEdgesType(int loopIndex, Hatch pHatch, int indent)
1355
        {
1356
            Curve2dCollection edges = pHatch.GetLoopAt(loopIndex).Curves;
1357
            for (int i = 0; i < (int)edges.Count; i++)
1358
            {
1359
                using (Curve2d pEdge = edges[i])
1360
                {
1361
                    writeLine(indent, string.Format("Edge {0}", i), pEdge.GetType().Name);
1362
                    switch (pEdge.GetType().Name)
1363
                    {
1364
                        case "LineSegment2d":
1365
                            break;
1366
                        case "CircularArc2d":
1367
                            dumpCircularArcEdge(indent + 1, (CircularArc2d)pEdge);
1368
                            break;
1369
                        case "EllipticalArc2d":
1370
                            dumpEllipticalArcEdge(indent + 1, (EllipticalArc2d)pEdge);
1371
                            break;
1372
                        case "NurbCurve2d":
1373
                            dumpNurbCurveEdge(indent + 1, (NurbCurve2d)pEdge);
1374
                            break;
1375
                    }
1376

    
1377
                    /******************************************************************/
1378
                    /* Common Edge Properties                                         */
1379
                    /******************************************************************/
1380
                    Interval interval = pEdge.GetInterval();
1381
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1382
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1383
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1384
                }
1385
            }
1386
        }
1387

    
1388
        /************************************************************************/
1389
        /* Convert the specified value to a LoopType string                     */
1390
        /************************************************************************/
1391
        string toLooptypeString(HatchLoopTypes loopType)
1392
        {
1393
            string retVal = "";
1394
            if ((loopType & HatchLoopTypes.External) != 0)
1395
                retVal = retVal + " | kExternal";
1396

    
1397
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1398
                retVal = retVal + " | kPolyline";
1399

    
1400
            if ((loopType & HatchLoopTypes.Derived) != 0)
1401
                retVal = retVal + " | kDerived";
1402

    
1403
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1404
                retVal = retVal + " | kTextbox";
1405

    
1406
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1407
                retVal = retVal + " | kOutermost";
1408

    
1409
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1410
                retVal = retVal + " | kNotClosed";
1411

    
1412
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1413
                retVal = retVal + " | kSelfIntersecting";
1414

    
1415
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1416
                retVal = retVal + " | kTextIsland";
1417

    
1418
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1419
                retVal = retVal + " | kDuplicate";
1420

    
1421
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1422
        }
1423

    
1424
        void dump(Hatch pHatch, int indent)
1425
        {
1426
            writeLine(indent++, pHatch.GetRXClass().Name, pHatch.Handle);
1427
            writeLine(indent, "Hatch Style", pHatch.HatchStyle);
1428
            writeLine(indent, "Hatch Object Type", pHatch.HatchObjectType);
1429
            writeLine(indent, "Is Hatch", pHatch.IsHatch);
1430
            writeLine(indent, "Is Gradient", !pHatch.IsGradient);
1431
            if (pHatch.IsHatch)
1432
            {
1433
                /******************************************************************/
1434
                /* Dump Hatch Parameters                                          */
1435
                /******************************************************************/
1436
                writeLine(indent, "Pattern Type", pHatch.PatternType);
1437
                switch (pHatch.PatternType)
1438
                {
1439
                    case HatchPatternType.PreDefined:
1440
                    case HatchPatternType.CustomDefined:
1441
                        writeLine(indent, "Pattern Name", pHatch.PatternName);
1442
                        writeLine(indent, "Solid Fill", pHatch.IsSolidFill);
1443
                        if (!pHatch.IsSolidFill)
1444
                        {
1445
                            writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1446
                            writeLine(indent, "Pattern Scale", pHatch.PatternScale);
1447
                        }
1448
                        break;
1449
                    case HatchPatternType.UserDefined:
1450
                        writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1451
                        writeLine(indent, "Pattern Double", pHatch.PatternDouble);
1452
                        writeLine(indent, "Pattern Space", pHatch.PatternSpace);
1453
                        break;
1454
                }
1455
                DBObjectCollection entitySet = new DBObjectCollection();
1456
                Handle hhh = pHatch.Handle;
1457
                if (hhh.Value == 1692) //69C)
1458
                {
1459
                    pHatch.Explode(entitySet);
1460
                    return;
1461
                }
1462
                if (hhh.Value == 1693) //69D)
1463
                {
1464
                    try
1465
                    {
1466
                        pHatch.Explode(entitySet);
1467
                    }
1468
                    catch (System.Exception e)
1469
                    {
1470
                        if (e.Message == "eCannotExplodeEntity")
1471
                        {
1472
                            writeLine(indent, "Hatch " + e.Message + ": ", pHatch.Handle);
1473
                            return;
1474
                        }
1475
                    }
1476
                }
1477
            }
1478
            if (pHatch.IsGradient)
1479
            {
1480
                /******************************************************************/
1481
                /* Dump Gradient Parameters                                       */
1482
                /******************************************************************/
1483
                writeLine(indent, "Gradient Type", pHatch.GradientType);
1484
                writeLine(indent, "Gradient Name", pHatch.GradientName);
1485
                writeLine(indent, "Gradient Angle", toDegreeString(pHatch.GradientAngle));
1486
                writeLine(indent, "Gradient Shift", pHatch.GradientShift);
1487
                writeLine(indent, "Gradient One-Color Mode", pHatch.GradientOneColorMode);
1488
                if (pHatch.GradientOneColorMode)
1489
                {
1490
                    writeLine(indent, "ShadeTintValue", pHatch.ShadeTintValue);
1491
                }
1492
                GradientColor[] colors = pHatch.GetGradientColors();
1493
                for (int i = 0; i < colors.Length; i++)
1494
                {
1495
                    writeLine(indent, string.Format("Color         {0}", i), colors[i].get_Color());
1496
                    writeLine(indent, string.Format("Interpolation {0}", i), colors[i].get_Value());
1497
                }
1498
            }
1499

    
1500
            /********************************************************************/
1501
            /* Dump Associated Objects                                          */
1502
            /********************************************************************/
1503
            writeLine(indent, "Associated objects", pHatch.Associative);
1504
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1505
            {
1506
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1507
            }
1508

    
1509
            /********************************************************************/
1510
            /* Dump Loops                                                       */
1511
            /********************************************************************/
1512
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1513
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1514
            {
1515
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1516

    
1517
                /******************************************************************/
1518
                /* Dump Loop                                                      */
1519
                /******************************************************************/
1520
                if ((pHatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) != 0)
1521
                {
1522
                    dumpPolylineType(i, pHatch, indent + 2);
1523
                }
1524
                else
1525
                {
1526
                    dumpEdgesType(i, pHatch, indent + 2);
1527
                }
1528
                /******************************************************************/
1529
                /* Dump Associated Objects                                        */
1530
                /******************************************************************/
1531
                if (pHatch.Associative)
1532
                {
1533
                    writeLine(indent + 2, "Associated objects");
1534
                    foreach (ObjectId id in pHatch.GetAssociatedObjectIdsAt(i))
1535
                    {
1536
                        writeLine(indent + 3, id.ObjectClass.Name, id.Handle);
1537
                    }
1538
                }
1539
            }
1540

    
1541
            writeLine(indent, "Elevation", pHatch.Elevation);
1542
            writeLine(indent, "Normal", pHatch.Normal);
1543
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1544
        }
1545

    
1546
        /************************************************************************/
1547
        /* Leader Dumper                                                          */
1548
        /************************************************************************/
1549
        void dump(Leader pLeader, int indent)
1550
        {
1551
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1552
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1553

    
1554
            writeLine(indent, "Annotation");
1555
            if (!pLeader.Annotation.IsNull)
1556
            {
1557
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1558
            }
1559
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1560
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1561
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1562
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1563
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1564
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1565
            writeLine(indent, "Splined", pLeader.IsSplined);
1566

    
1567
            for (int i = 0; i < pLeader.NumVertices; i++)
1568
            {
1569
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1570
            }
1571
            writeLine(indent, "Normal", pLeader.Normal);
1572
            dumpCurveData(pLeader, indent, Program.xml.DocumentElement);
1573
        }
1574

    
1575
        /************************************************************************/
1576
        /* Line Dumper                                                          */
1577
        /************************************************************************/
1578
        void dump(Line pLine, int indent, XmlNode node)
1579
        {
1580
            if (node != null && pLine != null && pLine.Length != 0)
1581
            {
1582
                XmlNode LineNode = Program.xml.CreateElement(pLine.GetRXClass().Name);
1583
                XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1584
                LengthAttr.Value = pLine.Length.ToString();
1585
                LineNode.Attributes.SetNamedItem(LengthAttr);
1586

    
1587
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1588
                HandleAttr.Value = pLine.Handle.ToString();
1589
                LineNode.Attributes.SetNamedItem(HandleAttr);
1590

    
1591
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1592
                {
1593
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1594
                    XAttr.Value = pLine.StartPoint.X.ToString();
1595
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1596

    
1597
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1598
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1599
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1600

    
1601
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1602
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1603
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1604
                }
1605
                LineNode.AppendChild(StartPointNode);
1606

    
1607
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1608
                {
1609
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1610
                    XAttr.Value = pLine.EndPoint.X.ToString();
1611
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1612

    
1613
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1614
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1615
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1616

    
1617
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1618
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1619
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1620
                }
1621
                LineNode.AppendChild(EndPointNode);
1622

    
1623
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1624
                NormalAttr.Value = pLine.Normal.ToString();
1625
                LineNode.Attributes.SetNamedItem(NormalAttr);
1626

    
1627
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1628
                ThicknessAttr.Value = pLine.Thickness.ToString();
1629
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1630

    
1631
                dumpEntityData(pLine, indent, LineNode);
1632

    
1633
                node.AppendChild(LineNode);
1634
            }
1635
            else
1636
            {
1637
                int d = 0;
1638
            }
1639
        }
1640

    
1641
        /************************************************************************/
1642
        /* MInsertBlock Dumper                                                  */
1643
        /************************************************************************/
1644
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1645
        {
1646
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1647

    
1648
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1649
            {
1650
                writeLine(indent, "Name", pRecord.Name);
1651
                writeLine(indent, "Rows", pMInsert.Rows);
1652
                writeLine(indent, "Columns", pMInsert.Columns);
1653
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1654
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1655
                dumpBlockRefData(pMInsert, indent, node);
1656
            }
1657
        }
1658

    
1659
        /************************************************************************/
1660
        /* Mline Dumper                                                         */
1661
        /************************************************************************/
1662
        void dump(Mline pMline, int indent)
1663
        {
1664
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1665
            writeLine(indent, "Style", pMline.Style);
1666
            writeLine(indent, "Closed", pMline.IsClosed);
1667
            writeLine(indent, "Scale", pMline.Scale);
1668
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1669
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1670
            writeLine(indent, "Normal", pMline.Normal);
1671

    
1672
            /********************************************************************/
1673
            /* Dump the segment data                                            */
1674
            /********************************************************************/
1675
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1676
            {
1677
                writeLine(indent, "Segment", i);
1678
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1679
            }
1680
            dumpEntityData(pMline, indent, Program.xml.DocumentElement);
1681
        }
1682

    
1683
        /************************************************************************/
1684
        /* MText Dumper                                                         */
1685
        /************************************************************************/
1686
        /// <summary>
1687
        /// convert MText to normal Text
1688
        /// </summary>
1689
        /// <param name="pMText"></param>
1690
        /// <param name="indent"></param>
1691
        /// <param name="node"></param>
1692
        void dump(MText pMText, int indent, XmlNode node)
1693
        {
1694
            DBObjectCollection objColl = new DBObjectCollection();
1695
            pMText.Explode(objColl);
1696
            foreach (var obj in objColl)
1697
            {
1698
                dumpTextData(obj as DBText, indent, node);
1699
            }
1700
        }
1701

    
1702
        /************************************************************************/
1703
        /* Ordinate Dimension Dumper                                            */
1704
        /************************************************************************/
1705
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1706
        {
1707
            if (node != null)
1708
            {
1709
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1710

    
1711
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1712
                HandleAttr.Value = pDim.Handle.ToString();
1713
                DimNode.Attributes.SetNamedItem(HandleAttr);
1714

    
1715
                XmlAttribute DefiningPointAttr = Program.xml.CreateAttribute("DefiningPoint");
1716
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1717
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1718

    
1719
                XmlAttribute UsingXAxisAttr = Program.xml.CreateAttribute("UsingXAxis");
1720
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1721
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1722

    
1723
                XmlAttribute UsingYAxisAttr = Program.xml.CreateAttribute("UsingYAxis");
1724
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1725
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1726

    
1727
                XmlAttribute LeaderEndPointAttr = Program.xml.CreateAttribute("LeaderEndPoint");
1728
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1729
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1730

    
1731
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1732
                OriginAttr.Value = pDim.Origin.ToString();
1733
                DimNode.Attributes.SetNamedItem(OriginAttr);
1734

    
1735
                dumpDimData(pDim, indent, DimNode);
1736

    
1737
                return DimNode;
1738
            }
1739

    
1740
            return null;
1741
        }
1742

    
1743
        /************************************************************************/
1744
        /* PolyFaceMesh Dumper                                                  */
1745
        /************************************************************************/
1746
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1747
        {
1748
            if (node != null)
1749
            {
1750
                XmlElement PolyNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1751

    
1752
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1753
                HandleAttr.Value = pPoly.Handle.ToString();
1754
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1755

    
1756
                XmlAttribute NumVerticesAttr = Program.xml.CreateAttribute("NumVertices");
1757
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1758
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1759

    
1760
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1761
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1762
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1763

    
1764
                /********************************************************************/
1765
                /* dump vertices and faces                                          */
1766
                /********************************************************************/
1767
                int vertexCount = 0;
1768
                int faceCount = 0;
1769
                foreach (ObjectId objId in pPoly)
1770
                {
1771
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1772
                    {
1773
                        if (ent is PolyFaceMeshVertex)
1774
                        {
1775
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1776

    
1777
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1778

    
1779
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1780
                            _HandleAttr.Value = pVertex.Handle.ToString();
1781
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1782

    
1783
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1784
                            PositionAttr.Value = pVertex.Position.ToString();
1785
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1786

    
1787
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1788

    
1789
                            PolyNode.AppendChild(VertexNode);
1790
                        }
1791
                        else if (ent is FaceRecord)
1792
                        {
1793
                            FaceRecord pFace = (FaceRecord)ent;
1794
                            string face = "{";
1795
                            for (short i = 0; i < 4; i++)
1796
                            {
1797
                                if (i > 0)
1798
                                {
1799
                                    face = face + " ";
1800
                                }
1801
                                face = face + pFace.GetVertexAt(i).ToString();
1802
                            }
1803

    
1804
                            face += "}";
1805

    
1806
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1807

    
1808
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1809
                            _HandleAttr.Value = pFace.Handle.ToString();
1810
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1811
                            FaceNode.InnerText = face;
1812

    
1813
                            dumpEntityData(pFace, indent + 1, FaceNode);
1814

    
1815
                            PolyNode.AppendChild(FaceNode);
1816
                        }
1817
                        else
1818
                        { // Unknown entity type
1819
                            writeLine(indent, "Unexpected Entity");
1820
                        }
1821
                    }
1822
                }
1823
                dumpEntityData(pPoly, indent, PolyNode);
1824

    
1825
                return PolyNode;
1826
            }
1827

    
1828
            return null;
1829
        }
1830

    
1831
        /************************************************************************/
1832
        /* Ole2Frame                                                            */
1833
        /************************************************************************/
1834
        void dump(Ole2Frame pOle, int indent)
1835
        {
1836
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1837

    
1838
            Rectangle3d pos = (Rectangle3d)pOle.Position3d;
1839
            writeLine(indent, "Lower Left", pos.LowerLeft);
1840
            writeLine(indent, "Lower Right", pos.LowerRight);
1841
            writeLine(indent, "Upper Left", pos.UpperLeft);
1842
            writeLine(indent, "Upper Right", pos.UpperRight);
1843
            writeLine(indent, "Type", pOle.Type);
1844
            writeLine(indent, "User Type", pOle.UserType);
1845
            if (pOle.Type == Ole2Frame.ItemType.Link)
1846
            {
1847
                writeLine(indent, "Link Name", pOle.LinkName);
1848
                writeLine(indent, "Link Path", pOle.LinkPath);
1849
            }
1850
            writeLine(indent, "Output Quality", pOle.OutputQuality);
1851
            dumpEntityData(pOle, indent, Program.xml.DocumentElement);
1852
        }
1853

    
1854
        /************************************************************************/
1855
        /* Point Dumper                                                         */
1856
        /************************************************************************/
1857
        void dump(DBPoint pPoint, int indent)
1858
        {
1859
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1860
            writeLine(indent, "Position", pPoint.Position);
1861
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1862
            writeLine(indent, "Normal", pPoint.Normal);
1863
            writeLine(indent, "Thickness", pPoint.Thickness);
1864
            dumpEntityData(pPoint, indent, Program.xml.DocumentElement);
1865
        }
1866

    
1867
        /************************************************************************/
1868
        /* Polygon Mesh Dumper                                                  */
1869
        /************************************************************************/
1870
        void dump(PolygonMesh pPoly, int indent)
1871
        {
1872
            writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1873
            writeLine(indent, "m Size", pPoly.MSize);
1874
            writeLine(indent, "m-Closed", pPoly.IsMClosed);
1875
            writeLine(indent, "m Surface Density", pPoly.MSurfaceDensity);
1876
            writeLine(indent, "n Size", pPoly.NSize);
1877
            writeLine(indent, "n-Closed", pPoly.IsNClosed);
1878
            writeLine(indent, "n Surface Density", pPoly.NSurfaceDensity);
1879
            /********************************************************************/
1880
            /* dump vertices                                                    */
1881
            /********************************************************************/
1882
            int vertexCount = 0;
1883
            foreach (object o in pPoly)
1884
            {
1885
                PolygonMeshVertex pVertex = o as PolygonMeshVertex;
1886
                if (pVertex != null)
1887
                {
1888
                    writeLine(indent, pVertex.GetRXClass().Name, vertexCount++);
1889
                    writeLine(indent + 1, "Handle", pVertex.Handle);
1890
                    writeLine(indent + 1, "Position", pVertex.Position);
1891
                    writeLine(indent + 1, "Type", pVertex.VertexType);
1892
                }
1893
            }
1894
            dumpEntityData(pPoly, indent, Program.xml.DocumentElement);
1895
        }
1896

    
1897
        /************************************************************************/
1898
        /* Polyline Dumper                                                      */
1899
        /************************************************************************/
1900
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
1901
        {
1902
            if (pPoly != null && pPoly.Length != 0)
1903
            {
1904
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1905
                writeLine(indent, "Has Width", pPoly.HasWidth);
1906
                if (!pPoly.HasWidth)
1907
                {
1908
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
1909
                }
1910

    
1911
                /********************************************************************/
1912
                /* dump vertices                                                    */
1913
                /********************************************************************/
1914
                if (node != null)
1915
                {
1916
                    XmlNode PolylineNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1917
                    XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1918
                    LengthAttr.Value = pPoly.Length.ToString();
1919
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
1920

    
1921
                    XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
1922
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
1923
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
1924

    
1925
                    XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1926
                    HandleAttr.Value = pPoly.Handle.ToString();
1927
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
1928

    
1929
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
1930
                    ClosedAttr.Value = pPoly.Closed.ToString();
1931
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
1932

    
1933
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
1934
                    {
1935
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
1936

    
1937
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
1938
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
1939

    
1940
                        Point3d pt = pPoly.GetPoint3dAt(i);
1941
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1942
                        XAttr.Value = pt.X.ToString();
1943
                        VertexNode.Attributes.SetNamedItem(XAttr);
1944

    
1945
                        XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1946
                        YAttr.Value = pt.Y.ToString();
1947
                        VertexNode.Attributes.SetNamedItem(YAttr);
1948

    
1949
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1950
                        ZAttr.Value = pt.Z.ToString();
1951
                        VertexNode.Attributes.SetNamedItem(ZAttr);
1952

    
1953
                        if (pPoly.HasWidth)
1954
                        {
1955
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
1956
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
1957
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
1958

    
1959
                            XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
1960
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
1961
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
1962
                        }
1963
                        if (pPoly.HasBulges)
1964
                        {
1965
                            XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
1966
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
1967
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
1968

    
1969
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
1970
                            {
1971
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
1972
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
1973
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
1974
                            }
1975
                        }
1976

    
1977
                        PolylineNode.AppendChild(VertexNode);
1978
                    }
1979

    
1980
                    dumpEntityData(pPoly, indent, PolylineNode);
1981
                    node.AppendChild(PolylineNode);
1982
                }
1983
            }
1984
            else
1985
            {
1986
                int d = 0;
1987
            }
1988
        }
1989

    
1990
        class DrawContextDumper : Context
1991
        {
1992
            Database _db;
1993
            public DrawContextDumper(Database db)
1994
            {
1995
                _db = db;
1996
            }
1997
            public override Database Database
1998
            {
1999
                get { return _db; }
2000
            }
2001
            public override bool IsBoundaryClipping
2002
            {
2003
                get { return false; }
2004
            }
2005
            public override bool IsPlotGeneration
2006
            {
2007
                get { return false; }
2008
            }
2009
            public override bool IsPostScriptOut
2010
            {
2011
                get { return false; }
2012
            }
2013
        }
2014
        class SubEntityTraitsDumper : SubEntityTraits
2015
        {
2016
            short _color;
2017
            int _drawFlags;
2018
            FillType _ft;
2019
            ObjectId _layer;
2020
            ObjectId _linetype;
2021
            LineWeight _lineWeight;
2022
            Mapper _mapper;
2023
            double _lineTypeScale;
2024
            ObjectId _material;
2025
            PlotStyleDescriptor _plotStyleDescriptor;
2026
            bool _sectionable;
2027
            bool _selectionOnlyGeometry;
2028
            ShadowFlags _shadowFlags;
2029
            double _thickness;
2030
            EntityColor _trueColor;
2031
            Transparency _transparency;
2032
            ObjectId _visualStyle;
2033
            public SubEntityTraitsDumper(Database db)
2034
            {
2035
                _drawFlags = 0; // kNoDrawFlags 
2036
                _color = 0;
2037
                _ft = FillType.FillAlways;
2038
                _layer = db.Clayer;
2039
                _linetype = db.Celtype;
2040
                _lineWeight = db.Celweight;
2041
                _lineTypeScale = db.Celtscale;
2042
                _material = db.Cmaterial;
2043
                _shadowFlags = ShadowFlags.ShadowsIgnore;
2044
                _thickness = 0;
2045
                _trueColor = new EntityColor(ColorMethod.None);
2046
                _transparency = new Transparency();
2047
            }
2048

    
2049
            protected override void SetLayerFlags(LayerFlags flags)
2050
            {
2051
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2052
            }
2053
            public override void AddLight(ObjectId lightId)
2054
            {
2055
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2056
            }
2057
            public override void SetupForEntity(Entity entity)
2058
            {
2059
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2060
            }
2061

    
2062
            public override short Color
2063
            {
2064
                get { return _color; }
2065
                set { _color = value; }
2066
            }
2067
            public override int DrawFlags
2068
            {
2069
                get { return _drawFlags; }
2070
                set { _drawFlags = value; }
2071
            }
2072
            public override FillType FillType
2073
            {
2074
                get { return _ft; }
2075
                set { _ft = value; }
2076
            }
2077
            public override ObjectId Layer
2078
            {
2079
                get { return _layer; }
2080
                set { _layer = value; }
2081
            }
2082
            public override ObjectId LineType
2083
            {
2084
                get { return _linetype; }
2085
                set { _linetype = value; }
2086
            }
2087
            public override double LineTypeScale
2088
            {
2089
                get { return _lineTypeScale; }
2090
                set { _lineTypeScale = value; }
2091
            }
2092
            public override LineWeight LineWeight
2093
            {
2094
                get { return _lineWeight; }
2095
                set { _lineWeight = value; }
2096
            }
2097
            public override Mapper Mapper
2098
            {
2099
                get { return _mapper; }
2100
                set { _mapper = value; }
2101
            }
2102
            public override ObjectId Material
2103
            {
2104
                get { return _material; }
2105
                set { _material = value; }
2106
            }
2107
            public override PlotStyleDescriptor PlotStyleDescriptor
2108
            {
2109
                get { return _plotStyleDescriptor; }
2110
                set { _plotStyleDescriptor = value; }
2111
            }
2112
            public override bool Sectionable
2113
            {
2114
                get { return _sectionable; }
2115
                set { _sectionable = value; }
2116
            }
2117
            public override bool SelectionOnlyGeometry
2118
            {
2119
                get { return _selectionOnlyGeometry; }
2120
                set { _selectionOnlyGeometry = value; }
2121
            }
2122
            public override ShadowFlags ShadowFlags
2123
            {
2124
                get { return _shadowFlags; }
2125
                set { _shadowFlags = value; }
2126
            }
2127
            public override double Thickness
2128
            {
2129
                get { return _thickness; }
2130
                set { _thickness = value; }
2131
            }
2132
            public override EntityColor TrueColor
2133
            {
2134
                get { return _trueColor; }
2135
                set { _trueColor = value; }
2136
            }
2137
            public override Transparency Transparency
2138
            {
2139
                get { return _transparency; }
2140
                set { _transparency = value; }
2141
            }
2142
            public override ObjectId VisualStyle
2143
            {
2144
                get { return _visualStyle; }
2145
                set { _visualStyle = value; }
2146
            }
2147
            public override void SetSelectionMarker(IntPtr sm)
2148
            {
2149
            }
2150
        }
2151
        class WorldGeometryDumper : WorldGeometry
2152
        {
2153
            Stack<Matrix3d> modelMatrix;
2154
            Stack<ClipBoundary> clips;
2155
            int indent;
2156
            public WorldGeometryDumper(int indent)
2157
              : base()
2158
            {
2159
                this.indent = indent;
2160
                modelMatrix = new Stack<Matrix3d>();
2161
                clips = new Stack<ClipBoundary>();
2162
                modelMatrix.Push(Matrix3d.Identity);
2163
            }
2164
            public override Matrix3d ModelToWorldTransform
2165
            {
2166
                get { return modelMatrix.Peek(); }
2167
            }
2168
            public override Matrix3d WorldToModelTransform
2169
            {
2170
                get { return modelMatrix.Peek().Inverse(); }
2171
            }
2172

    
2173
            public override Matrix3d PushOrientationTransform(OrientationBehavior behavior)
2174
            {
2175
                writeLine(indent, string.Format("WorldGeometry.PushOrientationTransform(behavior = {0})", behavior));
2176
                return new Matrix3d();
2177
            }
2178
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point2d offset)
2179
            {
2180
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2181
                return new Matrix3d();
2182
            }
2183
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point3d offset)
2184
            {
2185
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2186
                return new Matrix3d();
2187
            }
2188
            public override bool OwnerDraw(GdiDrawObject gdiDrawObject, Point3d position, Vector3d u, Vector3d v)
2189
            {
2190
                writeLine(indent, string.Format("WorldGeometry.OwnerDraw(gdiDrawObject = {0}, position = {1}, u = {2}, v = {3})", gdiDrawObject, position, u, v));
2191
                return false;
2192
            }
2193
            public override bool Polyline(Teigha.GraphicsInterface.Polyline polylineObj)
2194
            {
2195
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}", polylineObj));
2196
                return false;
2197
            }
2198
            public override bool Polypoint(Point3dCollection points, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2199
            {
2200
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, normals = {1}, subentityMarkers = {2}", points, normals, subentityMarkers));
2201
                return false;
2202
            }
2203
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2204
            {
2205
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, normals = {2}, subentityMarkers = {3}", points, colors, normals, subentityMarkers));
2206
                return false;
2207
            }
2208
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, TransparencyCollection transparency, Vector3dCollection normals, IntPtrCollection subentityMarkers, int pointSize)
2209
            {
2210
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, transparency = {2}, normals = {3}, subentityMarkers = {4}, pointSize = {5}", points, colors, transparency, normals, subentityMarkers, pointSize));
2211
                return false;
2212
            }
2213
            public override bool PolyPolyline(Teigha.GraphicsInterface.PolylineCollection polylineCollection)
2214
            {
2215
                writeLine(indent, string.Format("WorldGeometry.PolyPolyline(polylineCollection = {0}", polylineCollection));
2216
                return false;
2217
            }
2218
            public override bool PolyPolygon(UInt32Collection numPolygonPositions, Point3dCollection polygonPositions, UInt32Collection numPolygonPoints, Point3dCollection polygonPoints, EntityColorCollection outlineColors, LinetypeCollection outlineTypes, EntityColorCollection fillColors, Teigha.Colors.TransparencyCollection fillOpacities)
2219
            {
2220
                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));
2221
                return false;
2222
            }
2223
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point2d extents)
2224
            {
2225
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2226
                return new Matrix3d();
2227
            }
2228
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point3d extents)
2229
            {
2230
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2231
                return new Matrix3d();
2232
            }
2233
            public override bool EllipticalArc(Point3d center, Vector3d normal, double majorAxisLength, double minorAxisLength, double startDegreeInRads, double endDegreeInRads, double tiltDegreeInRads, ArcType arType)
2234
            {
2235
                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));
2236
                return false;
2237
            }
2238
            public override bool Circle(Point3d center, double radius, Vector3d normal)
2239
            {
2240
                writeLine(indent, string.Format("WorldGeometry.Circle(center = {0}, radius = {1}, normal = {2})", center, radius, normal));
2241
                return false;
2242
            }
2243
            public override bool Circle(Point3d firstPoint, Point3d secondPoint, Point3d thirdPoint)
2244
            {
2245
                writeLine(indent, string.Format("WorldGeometry.Circle(firstPoint = {0}, secondPoint = {1}, thirdPoint = {2})", firstPoint, secondPoint, thirdPoint));
2246
                return false;
2247
            }
2248
            public override bool CircularArc(Point3d start, Point3d point, Point3d endingPoint, ArcType arcType)
2249
            {
2250
                writeLine(indent, string.Format("WorldGeometry.CircularArc(start = {0}, point = {1}, endingPoint = {2}, arcType = {3})", start, point, endingPoint, arcType));
2251
                return false;
2252
            }
2253
            public override bool CircularArc(Point3d center, double radius, Vector3d normal, Vector3d startVector, double sweepAngle, ArcType arcType)
2254
            {
2255
                writeLine(indent, string.Format("WorldGeometry.CircularArc(center = {0}, radius = {1}, normal = {2}, startVector = {3}, sweepAngle = {4}, arcType = {5}", center, radius, normal, startVector, sweepAngle, arcType));
2256
                return false;
2257
            }
2258
            public override bool Draw(Drawable value)
2259
            {
2260
                writeLine(indent, string.Format("WorldGeometry.Draw(value = {0}", value));
2261
                return false;
2262
            }
2263
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v)
2264
            {
2265
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}", position, u, v));
2266
                return false;
2267
            }
2268
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v, TransparencyMode transparencyMode)
2269
            {
2270
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}, transparencyMode = {4}", position, u, v, transparencyMode));
2271
                return false;
2272
            }
2273
            public override bool Mesh(int rows, int columns, Point3dCollection points, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2274
            {
2275
                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));
2276
                return false;
2277
            }
2278
            public override bool Polygon(Point3dCollection points)
2279
            {
2280
                writeLine(indent, string.Format("WorldGeometry.Polygon(points = {0})", points));
2281
                return false;
2282
            }
2283
            public override bool Polyline(Teigha.DatabaseServices.Polyline value, int fromIndex, int segments)
2284
            {
2285
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}, fromIndex = {1}, segments = {2})", value, fromIndex, segments));
2286
                return false;
2287
            }
2288
            public override bool Polyline(Point3dCollection points, Vector3d normal, IntPtr subEntityMarker)
2289
            {
2290
                writeLine(indent, string.Format("WorldGeometry.Polyline(points = {0}, normal = {1}, subEntityMarker = {2})", points, normal, subEntityMarker));
2291
                return false;
2292
            }
2293
            public override void PopClipBoundary()
2294
            {
2295
                writeLine(indent, string.Format("WorldGeometry.PopClipBoundary"));
2296
                clips.Pop();
2297
            }
2298
            public override bool PopModelTransform()
2299
            {
2300
                return true;
2301
            }
2302
            public override bool PushClipBoundary(ClipBoundary boundary)
2303
            {
2304
                writeLine(indent, string.Format("WorldGeometry.PushClipBoundary"));
2305
                clips.Push(boundary);
2306
                return true;
2307
            }
2308
            public override bool PushModelTransform(Matrix3d matrix)
2309
            {
2310
                writeLine(indent, "WorldGeometry.PushModelTransform(Matrix3d)");
2311
                Matrix3d m = modelMatrix.Peek();
2312
                modelMatrix.Push(m * matrix);
2313
                return true;
2314
            }
2315
            public override bool PushModelTransform(Vector3d normal)
2316
            {
2317
                writeLine(indent, "WorldGeometry.PushModelTransform(Vector3d)");
2318
                PushModelTransform(Matrix3d.PlaneToWorld(normal));
2319
                return true;
2320
            }
2321
            public override bool RowOfDots(int count, Point3d start, Vector3d step)
2322
            {
2323
                writeLine(indent, string.Format("ViewportGeometry.RowOfDots(count = {0}, start = {1}, step = {1})", count, start, step));
2324
                return false;
2325
            }
2326
            public override bool Ray(Point3d point1, Point3d point2)
2327
            {
2328
                writeLine(indent, string.Format("WorldGeometry.Ray(point1 = {0}, point2 = {1})", point1, point2));
2329
                return false;
2330
            }
2331
            public override bool Shell(Point3dCollection points, IntegerCollection faces, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2332
            {
2333
                writeLine(indent, string.Format("WorldGeometry.Shell(points = {0}, faces = {1}, edgeData = {2}, faceData = {3}, vertexData = {4}, bAutoGenerateNormals = {5})", points, faces, edgeData, faceData, vertexData, bAutoGenerateNormals));
2334
                return false;
2335
            }
2336
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, string message, bool raw, TextStyle textStyle)
2337
            {
2338
                writeLine(indent, string.Format("WorldGeometry.Text(position = {0}, normal = {1}, direction = {2}, message = {3}, raw = {4}, textStyle = {5})", position, normal, direction, message, raw, textStyle));
2339
                return false;
2340
            }
2341
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, double height, double width, double oblique, string message)
2342
            {
2343
                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));
2344
                return false;
2345
            }
2346
            public override bool WorldLine(Point3d startPoint, Point3d endPoint)
2347
            {
2348
                writeLine(indent, string.Format("WorldGeometry.WorldLine(startPoint = {0}, endPoint = {1})", startPoint, endPoint));
2349
                return false;
2350
            }
2351
            public override bool Xline(Point3d point1, Point3d point2)
2352
            {
2353
                writeLine(indent, string.Format("WorldGeometry.Xline(point1 = {0}, point2 = {1})", point1, point2));
2354
                return false;
2355
            }
2356

    
2357
            public override void SetExtents(Extents3d extents)
2358
            {
2359
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2360
            }
2361
            public override void StartAttributesSegment()
2362
            {
2363
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2364
            }
2365
        }
2366

    
2367
        class WorldDrawDumper : WorldDraw
2368
        {
2369
            WorldGeometryDumper _geom;
2370
            DrawContextDumper _ctx;
2371
            SubEntityTraits _subents;
2372
            RegenType _regenType;
2373
            int indent;
2374
            public WorldDrawDumper(Database db, int indent)
2375
              : base()
2376
            {
2377
                _regenType = RegenType;
2378
                this.indent = indent;
2379
                _geom = new WorldGeometryDumper(indent);
2380
                _ctx = new DrawContextDumper(db);
2381
                _subents = new SubEntityTraitsDumper(db);
2382
            }
2383
            public override double Deviation(DeviationType deviationType, Point3d pointOnCurve)
2384
            {
2385
                return 1e-9;
2386
            }
2387
            public override WorldGeometry Geometry
2388
            {
2389
                get
2390
                {
2391
                    return _geom;
2392
                }
2393
            }
2394
            public override bool IsDragging
2395
            {
2396
                get
2397
                {
2398
                    return false;
2399
                }
2400
            }
2401
            public override Int32 NumberOfIsolines
2402
            {
2403
                get
2404
                {
2405
                    return 10;
2406
                }
2407
            }
2408
            public override Geometry RawGeometry
2409
            {
2410
                get
2411
                {
2412
                    return _geom;
2413
                }
2414
            }
2415
            public override bool RegenAbort
2416
            {
2417
                get
2418
                {
2419
                    return false;
2420
                }
2421
            }
2422
            public override RegenType RegenType
2423
            {
2424
                get
2425
                {
2426
                    writeLine(indent, "RegenType is asked");
2427
                    return _regenType;
2428
                }
2429
            }
2430
            public override SubEntityTraits SubEntityTraits
2431
            {
2432
                get
2433
                {
2434
                    return _subents;
2435
                }
2436
            }
2437
            public override Context Context
2438
            {
2439
                get
2440
                {
2441
                    return _ctx;
2442
                }
2443
            }
2444
        }
2445

    
2446
        /************************************************************************/
2447
        /* Dump the common data and WorldDraw information for all               */
2448
        /* entities without explicit dumpers                                    */
2449
        /************************************************************************/
2450
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2451
        {
2452
            if (node != null)
2453
            {
2454
                XmlElement EntNode = Program.xml.CreateElement(pEnt.GetRXClass().Name);
2455

    
2456
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2457
                HandleAttr.Value = pEnt.Handle.ToString();
2458
                EntNode.Attributes.SetNamedItem(HandleAttr);
2459

    
2460
                dumpEntityData(pEnt, indent, EntNode);
2461
                using (Database db = pEnt.Database)
2462
                {
2463
                    /**********************************************************************/
2464
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2465
                    /**********************************************************************/
2466
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2467
                    /**********************************************************************/
2468
                    /* Call worldDraw()                                                   */
2469
                    /**********************************************************************/
2470
                    pEnt.WorldDraw(wd);
2471
                }
2472

    
2473
                node.AppendChild(EntNode);
2474

    
2475
                return EntNode;
2476
            }
2477

    
2478
            return null;
2479
        }
2480

    
2481
        /************************************************************************/
2482
        /* Proxy Entity Dumper                                                  */
2483
        /************************************************************************/
2484
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2485
        {
2486
            if (node != null)
2487
            {
2488
                XmlElement ProxyNode = Program.xml.CreateElement(pProxy.GetRXClass().Name);
2489

    
2490
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2491
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2492
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2493

    
2494
                // this will dump proxy entity graphics
2495
                dump((Entity)pProxy, indent, node);
2496

    
2497
                DBObjectCollection collection = new DBObjectCollection(); ;
2498
                try
2499
                {
2500
                    pProxy.ExplodeGeometry(collection);
2501
                }
2502
                catch (System.Exception)
2503
                {
2504
                    return null;
2505
                }
2506

    
2507
                foreach (Entity ent in collection)
2508
                {
2509
                    if (ent is Polyline2d)
2510
                    {
2511
                        Polyline2d pline2d = (Polyline2d)ent;
2512
                        int i = 0;
2513

    
2514
                        try
2515
                        {
2516
                            foreach (Entity ent1 in pline2d)
2517
                            {
2518
                                if (ent1 is Vertex2d)
2519
                                {
2520
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2521
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2522
                                }
2523
                            }
2524
                        }
2525
                        catch (System.Exception)
2526
                        {
2527
                            return null;
2528
                        }
2529
                    }
2530
                }
2531

    
2532
                node.AppendChild(ProxyNode);
2533
                return ProxyNode;
2534
            }
2535

    
2536
            return null;
2537
        }
2538

    
2539
        /************************************************************************/
2540
        /* Radial Dimension Dumper                                              */
2541
        /************************************************************************/
2542
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2543
        {
2544
            if (node != null)
2545
            {
2546
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2547

    
2548
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2549
                HandleAttr.Value = pDim.Handle.ToString();
2550
                DimNode.Attributes.SetNamedItem(HandleAttr);
2551

    
2552
                XmlAttribute CenterAttr = Program.xml.CreateAttribute("Center");
2553
                CenterAttr.Value = pDim.Center.ToString();
2554
                DimNode.Attributes.SetNamedItem(CenterAttr);
2555

    
2556
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
2557
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
2558
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
2559

    
2560
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
2561
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2562
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2563

    
2564
                dumpDimData(pDim, indent, DimNode);
2565

    
2566
                node.AppendChild(DimNode);
2567

    
2568
                return DimNode;
2569
            }
2570

    
2571
            return null;
2572
        }
2573

    
2574
        /************************************************************************/
2575
        /* Dump Raster Image Def                                               */
2576
        /************************************************************************/
2577
        void dumpRasterImageDef(ObjectId id, int indent)
2578
        {
2579
            if (!id.IsValid)
2580
                return;
2581
            using (RasterImageDef pDef = (RasterImageDef)id.Open(OpenMode.ForRead))
2582
            {
2583
                writeLine(indent++, pDef.GetRXClass().Name, pDef.Handle);
2584
                writeLine(indent, "Source Filename", shortenPath(pDef.SourceFileName));
2585
                writeLine(indent, "Loaded", pDef.IsLoaded);
2586
                writeLine(indent, "mm per Pixel", pDef.ResolutionMMPerPixel);
2587
                writeLine(indent, "Loaded", pDef.IsLoaded);
2588
                writeLine(indent, "Resolution Units", pDef.ResolutionUnits);
2589
                writeLine(indent, "Size", pDef.Size);
2590
            }
2591
        }
2592
        /************************************************************************/
2593
        /* Dump Raster Image Data                                               */
2594
        /************************************************************************/
2595
        void dumpRasterImageData(RasterImage pImage, int indent)
2596
        {
2597
            writeLine(indent, "Brightness", pImage.Brightness);
2598
            writeLine(indent, "Clipped", pImage.IsClipped);
2599
            writeLine(indent, "Contrast", pImage.Contrast);
2600
            writeLine(indent, "Fade", pImage.Fade);
2601
            writeLine(indent, "kClip", pImage.DisplayOptions & ImageDisplayOptions.Clip);
2602
            writeLine(indent, "kShow", pImage.DisplayOptions & ImageDisplayOptions.Show);
2603
            writeLine(indent, "kShowUnAligned", pImage.DisplayOptions & ImageDisplayOptions.ShowUnaligned);
2604
            writeLine(indent, "kTransparent", pImage.DisplayOptions & ImageDisplayOptions.Transparent);
2605
            writeLine(indent, "Scale", pImage.Scale);
2606

    
2607
            /********************************************************************/
2608
            /* Dump clip boundary                                               */
2609
            /********************************************************************/
2610
            if (pImage.IsClipped)
2611
            {
2612
                writeLine(indent, "Clip Boundary Type", pImage.ClipBoundaryType);
2613
                if (pImage.ClipBoundaryType != ClipBoundaryType.Invalid)
2614
                {
2615
                    Point2dCollection pt = pImage.GetClipBoundary();
2616
                    for (int i = 0; i < pt.Count; i++)
2617
                    {
2618
                        writeLine(indent, string.Format("Clip Point {0}", i), pt[i]);
2619
                    }
2620
                }
2621
            }
2622

    
2623
            /********************************************************************/
2624
            /* Dump frame                                                       */
2625
            /********************************************************************/
2626
            Point3dCollection vertices = pImage.GetVertices();
2627
            for (int i = 0; i < vertices.Count; i++)
2628
            {
2629
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2630
            }
2631

    
2632
            /********************************************************************/
2633
            /* Dump orientation                                                 */
2634
            /********************************************************************/
2635
            writeLine(indent, "Orientation");
2636
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2637
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2638
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2639
            dumpRasterImageDef(pImage.ImageDefId, indent);
2640
            dumpEntityData(pImage, indent, Program.xml.DocumentElement);
2641
        }
2642

    
2643
        /************************************************************************/
2644
        /* Raster Image Dumper                                                  */
2645
        /************************************************************************/
2646
        void dump(RasterImage pImage, int indent)
2647
        {
2648
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2649
            writeLine(indent, "Image size", pImage.ImageSize(true));
2650
            dumpRasterImageData(pImage, indent);
2651
        }
2652

    
2653
        /************************************************************************/
2654
        /* Ray Dumper                                                          */
2655
        /************************************************************************/
2656
        void dump(Ray pRay, int indent)
2657
        {
2658
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2659
            writeLine(indent, "Base Point", pRay.BasePoint);
2660
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2661
            dumpCurveData(pRay, indent, Program.xml.DocumentElement);
2662
        }
2663

    
2664
        /************************************************************************/
2665
        /* Region Dumper                                                        */
2666
        /************************************************************************/
2667
        void dump(Region pRegion, int indent)
2668
        {
2669
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2670
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2671
        }
2672

    
2673
        /************************************************************************/
2674
        /* Rotated Dimension Dumper                                             */
2675
        /************************************************************************/
2676
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2677
        {
2678
            if (node != null)
2679
            {
2680
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2681

    
2682
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2683
                HandleAttr.Value = pDim.Handle.ToString();
2684
                DimNode.Attributes.SetNamedItem(HandleAttr);
2685

    
2686
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
2687
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2688
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2689

    
2690
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
2691
                ObliqueAttr.Value = pDim.Oblique.ToString();
2692
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2693

    
2694
                XmlAttribute RotationAttr = Program.xml.CreateAttribute("Rotation");
2695
                RotationAttr.Value = pDim.Rotation.ToString();
2696
                DimNode.Attributes.SetNamedItem(RotationAttr);
2697

    
2698
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
2699
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2700
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2701

    
2702
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2703
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2704
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2705

    
2706
                dumpDimData(pDim, indent, DimNode);
2707
                node.AppendChild(DimNode);
2708

    
2709
                return DimNode;
2710
            }
2711

    
2712
            return null;
2713
        }
2714

    
2715
        /************************************************************************/
2716
        /* Shape Dumper                                                          */
2717
        /************************************************************************/
2718
        void dump(Shape pShape, int indent)
2719
        {
2720
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2721

    
2722
            if (!pShape.StyleId.IsNull)
2723
            {
2724
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2725
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2726
            }
2727

    
2728
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2729
            writeLine(indent, "Shape Name", pShape.Name);
2730
            writeLine(indent, "Position", pShape.Position);
2731
            writeLine(indent, "Size", pShape.Size);
2732
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2733
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2734
            writeLine(indent, "Normal", pShape.Normal);
2735
            writeLine(indent, "Thickness", pShape.Thickness);
2736
            dumpEntityData(pShape, indent, Program.xml.DocumentElement);
2737
        }
2738

    
2739
        /************************************************************************/
2740
        /* Solid Dumper                                                         */
2741
        /************************************************************************/
2742
        // TODO:
2743
        /*  void dump(Solid pSolid, int indent)
2744
      {
2745
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2746

    
2747
        for (int i = 0; i < 4; i++)
2748
        {
2749
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2750
        }
2751
        dumpEntityData(pSolid, indent);
2752
      }
2753
    */
2754
        /************************************************************************/
2755
        /* Spline Dumper                                                        */
2756
        /************************************************************************/
2757
        void dump(Spline pSpline, int indent)
2758
        {
2759
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2760

    
2761
            NurbsData data = pSpline.NurbsData;
2762
            writeLine(indent, "Degree", data.Degree);
2763
            writeLine(indent, "Rational", data.Rational);
2764
            writeLine(indent, "Periodic", data.Periodic);
2765
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2766
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2767

    
2768
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2769
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2770
            {
2771
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2772
            }
2773

    
2774
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2775
            for (int i = 0; i < data.GetKnots().Count; i++)
2776
            {
2777
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2778
            }
2779

    
2780
            if (data.Rational)
2781
            {
2782
                writeLine(indent, "Number of Weights", data.GetWeights().Count);
2783
                for (int i = 0; i < data.GetWeights().Count; i++)
2784
                {
2785
                    writeLine(indent, "Weight " + i.ToString(), data.GetWeights()[i]);
2786
                }
2787
            }
2788
            dumpCurveData(pSpline, indent, Program.xml.DocumentElement);
2789
        }
2790
        /************************************************************************/
2791
        /* Table Dumper                                                         */
2792
        /************************************************************************/
2793
        void dump(Table pTable, int indent)
2794
        {
2795
            writeLine(indent++, pTable.GetRXClass().Name, pTable.Handle);
2796
            writeLine(indent, "Position", pTable.Position);
2797
            writeLine(indent, "X-Direction", pTable.Direction);
2798
            writeLine(indent, "Normal", pTable.Normal);
2799
            writeLine(indent, "Height", (int)pTable.Height);
2800
            writeLine(indent, "Width", (int)pTable.Width);
2801
            writeLine(indent, "Rows", (int)pTable.NumRows);
2802
            writeLine(indent, "Columns", (int)pTable.NumColumns);
2803

    
2804
            // TODO:
2805
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2806
            //writeLine(indent, "Table Style",               pStyle.Name);
2807
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2808
        }
2809

    
2810
        /************************************************************************/
2811
        /* Text Dumper                                                          */
2812
        /************************************************************************/
2813
        static void dump(DBText pText, int indent, XmlNode node)
2814
        {
2815
            if (node != null)
2816
            {
2817
                dumpTextData(pText, indent, node);
2818
            }
2819
        }
2820
        /************************************************************************/
2821
        /* Trace Dumper                                                         */
2822
        /************************************************************************/
2823
        void dump(Trace pTrace, int indent)
2824
        {
2825
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2826

    
2827
            for (short i = 0; i < 4; i++)
2828
            {
2829
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2830
            }
2831
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2832
        }
2833

    
2834
        /************************************************************************/
2835
        /* Trace UnderlayReference                                                         */
2836
        /************************************************************************/
2837
        void dump(UnderlayReference pEnt, int indent)
2838
        {
2839
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2840
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2841
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2842
        }
2843

    
2844
        /************************************************************************/
2845
        /* Viewport Dumper                                                       */
2846
        /************************************************************************/
2847
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2848
        {
2849
            if (node != null)
2850
            {
2851
                XmlElement VportNode = Program.xml.CreateElement(pVport.GetRXClass().Name);
2852

    
2853
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2854
                HandleAttr.Value = pVport.Handle.ToString();
2855
                VportNode.Attributes.SetNamedItem(HandleAttr);
2856

    
2857
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2858
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2859
                writeLine(indent, "Center Point", pVport.CenterPoint);
2860
                writeLine(indent, "Circle sides", pVport.CircleSides);
2861
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2862
                writeLine(indent, "Elevation", pVport.Elevation);
2863
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2864
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2865
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2866
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2867

    
2868
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2869
                if (layerIds.Count > 0)
2870
                {
2871
                    writeLine(indent, "Frozen Layers:");
2872
                    for (int i = 0; i < layerIds.Count; i++)
2873
                    {
2874
                        writeLine(indent + 1, i, layerIds[i]);
2875
                    }
2876
                }
2877
                else
2878
                {
2879
                    writeLine(indent, "Frozen Layers", "None");
2880
                }
2881

    
2882
                Point3d origin = new Point3d();
2883
                Vector3d xAxis = new Vector3d();
2884
                Vector3d yAxis = new Vector3d();
2885
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
2886
                writeLine(indent, "UCS origin", origin);
2887
                writeLine(indent, "UCS x-Axis", xAxis);
2888
                writeLine(indent, "UCS y-Axis", yAxis);
2889
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
2890
                writeLine(indent, "Grid On", pVport.GridOn);
2891
                writeLine(indent, "Height", pVport.Height);
2892
                writeLine(indent, "Lens Length", pVport.LensLength);
2893
                writeLine(indent, "Locked", pVport.Locked);
2894
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
2895

    
2896
                if (!pVport.NonRectClipEntityId.IsNull)
2897
                {
2898
                    writeLine(indent, "Non-rectangular Clipper", pVport.NonRectClipEntityId.Handle);
2899
                }
2900
                writeLine(indent, "Render Mode", pVport.RenderMode);
2901
                writeLine(indent, "Remove Hidden Lines", pVport.HiddenLinesRemoved);
2902
                writeLine(indent, "Shade Plot", pVport.ShadePlot);
2903
                writeLine(indent, "Snap Isometric", pVport.SnapIsometric);
2904
                writeLine(indent, "Snap On", pVport.SnapOn);
2905
                writeLine(indent, "Transparent", pVport.Transparent);
2906
                writeLine(indent, "UCS Follow", pVport.UcsFollowModeOn);
2907
                writeLine(indent, "UCS Icon at Origin", pVport.UcsIconAtOrigin);
2908

    
2909
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
2910
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
2911

    
2912
                if (!pVport.UcsName.IsNull)
2913
                {
2914
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
2915
                        writeLine(indent, "UCS Name", pUCS.Name);
2916
                }
2917
                else
2918
                {
2919
                    writeLine(indent, "UCS Name", "Null");
2920
                }
2921

    
2922
                writeLine(indent, "View Center", pVport.ViewCenter);
2923
                writeLine(indent, "View Height", pVport.ViewHeight);
2924
                writeLine(indent, "View Target", pVport.ViewTarget);
2925
                writeLine(indent, "Width", pVport.Width);
2926
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
2927

    
2928
                {
2929
                    using (DBObjectCollection collection = new DBObjectCollection())
2930
                    {
2931
                        try
2932
                        {
2933
                            pVport.ExplodeGeometry(collection);
2934

    
2935
                            foreach (Entity ent in collection)
2936
                            {
2937
                                if (ent is Polyline2d)
2938
                                {
2939
                                    Polyline2d pline2d = (Polyline2d)ent;
2940
                                    int i = 0;
2941
                                    foreach (Entity ent1 in pline2d)
2942
                                    {
2943
                                        if (ent1 is Vertex2d)
2944
                                        {
2945
                                            Vertex2d vtx2d = (Vertex2d)ent1;
2946
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
2947
                                        }
2948
                                    }
2949
                                }
2950
                            }
2951
                        }
2952
                        catch (System.Exception)
2953
                        {
2954
                        }
2955
                    }
2956
                }
2957

    
2958
                node.AppendChild(VportNode);
2959
                return VportNode;
2960
            }
2961

    
2962
            return null;
2963
        }
2964

    
2965
        /************************************************************************/
2966
        /* Wipeout Dumper                                                  */
2967
        /************************************************************************/
2968
        void dump(Wipeout pWipeout, int indent)
2969
        {
2970
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
2971
            dumpRasterImageData(pWipeout, indent);
2972
        }
2973

    
2974
        /************************************************************************/
2975
        /* Xline Dumper                                                         */
2976
        /************************************************************************/
2977
        void dump(Xline pXline, int indent)
2978
        {
2979
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
2980
            writeLine(indent, "Base Point", pXline.BasePoint);
2981
            writeLine(indent, "Unit Direction", pXline.UnitDir);
2982
            dumpCurveData(pXline, indent, Program.xml.DocumentElement);
2983
        }
2984

    
2985
        public void dump(Database pDb, int indent, XmlNode node)
2986
        {
2987
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
2988
            {
2989
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
2990
                {
2991
                    string layoutName = "";
2992
                    layoutName = pLayout.LayoutName;
2993

    
2994
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
2995
                    LayoutNameAttr.Value = layoutName;
2996
                    node.Attributes.SetNamedItem(LayoutNameAttr);
2997
                }
2998
            }
2999

    
3000
            dumpHeader(pDb, indent, node);
3001
            dumpLayers(pDb, indent, node);
3002
            dumpLinetypes(pDb, indent, node);
3003
            dumpTextStyles(pDb, indent, node);
3004
            dumpDimStyles(pDb, indent, node);
3005
            dumpRegApps(pDb, indent);
3006
            dumpViewports(pDb, indent, node);
3007
            dumpViews(pDb, indent, node);
3008
            dumpMLineStyles(pDb, indent);
3009
            dumpUCSTable(pDb, indent, node);
3010
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3011

    
3012
            dumpBlocks(pDb, indent, node);
3013
        }
3014

    
3015
        /************************************************************************/
3016
        /* Export DWG to PDF                                                    */
3017
        /************************************************************************/
3018
        public void ExportPDF(Database pDb, string filePath)
3019
        {
3020
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3021
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3022
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3023

    
3024
            using (mPDFExportParams param = new mPDFExportParams())
3025
            {
3026
                param.Database = pDb;
3027

    
3028
                TransactionManager tm = pDb.TransactionManager;
3029
                using (Transaction ta = tm.StartTransaction())
3030
                {
3031
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3032
                    {
3033
                        param.OutputStream = fileStrem;
3034

    
3035
                        bool embededTTF = false;
3036
                        bool shxTextAsGeometry = true;
3037
                        bool ttfGeometry = true;
3038
                        bool simpleGeomOptimization = false;
3039
                        bool zoomToExtentsMode = true;
3040
                        bool enableLayers = false;
3041
                        bool includeOffLayers = false;
3042
                        bool enablePrcMode = true;
3043
                        bool monochrome = true;
3044
                        bool allLayout = false;
3045
                        double paperWidth = 841;
3046
                        double paperHeight = 594;
3047

    
3048
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3049
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3050
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3051
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3052
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3053
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3054
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3055

    
3056
                        param.Title = "";
3057
                        param.Author = "";
3058
                        param.Subject = "";
3059
                        param.Keywords = "";
3060
                        param.Creator = "";
3061
                        param.Producer = "";
3062
                        param.UseHLR = !enablePrcMode;
3063
                        param.FlateCompression = true;
3064
                        param.ASCIIHEXEncodeStream = true;
3065
                        param.hatchDPI = 720;
3066

    
3067
                        bool bV15 = enableLayers || includeOffLayers;
3068
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3069

    
3070
                        if (enablePrcMode)
3071
                        {
3072
                            Module pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcModule", false, false);
3073
                            if (pModule != null)
3074
                            {
3075
                                pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcExport", false, false);
3076
                            }
3077
                            if (pModule != null)
3078
                            {
3079
                                RXObject pObj = null;
3080
                                bool bUsePRCSingleViewMode = true; // provide a corresponding checkbox in Export to PDF dialog similar to one in OdaMfcApp
3081
                                if (bUsePRCSingleViewMode)
3082
                                {
3083
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_AllInSingleView");
3084
                                }
3085
                                else
3086
                                {
3087
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_Default");
3088
                                }
3089
                                if (pObj != null)
3090
                                {
3091
                                    RXClass pCls = (RXClass)pObj;
3092
                                    if (pCls != null)
3093
                                    {
3094
                                        param.PRCContext = pCls.Create();
3095
                                        param.PRCMode = PRCSupport.AsBrep; //(bUsePRCAsBRep == TRUE ? PRCSupport.AsBrep : PRCSupport.AsMesh);
3096
                                    }
3097
                                    else
3098
                                    {
3099
                                        Console.WriteLine("PDF Export, PRC support - RXClass failed");
3100
                                    }
3101
                                }
3102
                                else
3103
                                {
3104
                                    Console.WriteLine("PDF Export, PRC support - context failed");
3105
                                }
3106
                            }
3107
                            else
3108
                            {
3109
                                Console.WriteLine("PRC module was not loaded", "Error");
3110
                            }
3111
                        }
3112

    
3113
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3114

    
3115
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3116
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3117

    
3118
                        StringCollection strColl = new StringCollection();
3119
                        if (allLayout)
3120
                        {
3121
                            using (DBDictionary layouts = (DBDictionary)pDb.LayoutDictionaryId.GetObject(OpenMode.ForRead))
3122
                            {
3123
                                foreach (DBDictionaryEntry entry in layouts)
3124
                                {
3125
                                    if ("Model" == entry.Key)
3126
                                        strColl.Insert(0, entry.Key);
3127
                                    else
3128
                                        strColl.Add(entry.Key);
3129
                                    if (-1 != iIndexStyle)
3130
                                    {
3131
                                        PlotSettings ps = (PlotSettings)ta.GetObject(entry.Value, OpenMode.ForWrite);
3132
                                        plotSettingVal.SetCurrentStyleSheet(ps, styleCol[iIndexStyle]);
3133
                                    }
3134
                                }
3135
                            }
3136
                        }
3137
                        else if (-1 != iIndexStyle)
3138
                        {
3139
                            using (BlockTableRecord paperBTR = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3140
                            {
3141
                                using (PlotSettings pLayout = (PlotSettings)paperBTR.LayoutId.GetObject(OpenMode.ForWrite))
3142
                                {
3143
                                    plotSettingVal.SetCurrentStyleSheet(pLayout, styleCol[iIndexStyle]);
3144
                                }
3145
                            }
3146
                        }
3147
                        param.Layouts = strColl;
3148

    
3149
                        int nPages = Math.Max(1, strColl.Count);
3150
                        PageParamsCollection pParCol = new PageParamsCollection();
3151
                        for (int i = 0; i < nPages; ++i)
3152
                        {
3153
                            PageParams pp = new PageParams();
3154
                            pp.setParams(paperWidth, paperHeight);
3155
                            pParCol.Add(pp);
3156
                        }
3157
                        param.PageParams = pParCol;
3158
                        Export_Import.ExportPDF(param);
3159
                    }
3160
                    ta.Abort();
3161
                }
3162
            }
3163
        }
3164

    
3165
        /************************************************************************/
3166
        /* Export DWG to PNG                                                    */
3167
        /************************************************************************/
3168
        public void ExportPNG(Database pDb, string filePath)
3169
        {
3170
            chageColorAllObjects(pDb);
3171

    
3172
            string gdPath = "WinOpenGL_20.5_15.txv";
3173

    
3174
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3175
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3176
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3177
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3178

    
3179
            using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3180
            {
3181
                if (gsModule == null)
3182
                {
3183
                    Console.WriteLine("\nCould not load graphics module {0} \nExport cancelled.", gdPath);
3184
                    return;
3185
                }
3186

    
3187
                // create graphics device
3188
                using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3189
                {
3190
                    // setup device properties
3191
                    using (Dictionary props = dev.Properties)
3192
                    {
3193
                        props.AtPut("BitPerPixel", new RxVariant(32));
3194
                    }
3195
                    using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3196
                    {
3197
                        ctx.PaletteBackground = System.Drawing.Color.White;
3198
                        ctx.SetPlotGeneration(true);
3199

    
3200
                        using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3201
                        {
3202
                            helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3203
                            int width = 9600;
3204
                            int height = 6787;
3205
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
3206
                            helperDevice.OnSize(rect);
3207

    
3208
                            if (ctx.IsPlotGeneration)
3209
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3210
                            else
3211
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3212

    
3213
                            helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3214
                            helperDevice.ActiveView.Zoom(0.99);
3215
                            helperDevice.Update();
3216

    
3217
                            Export_Import.ExportBitmap(helperDevice, bmpPath);
3218
                        }
3219
                    }
3220
                }
3221
            }
3222

    
3223
            if (File.Exists(bmpPath))
3224
            {
3225
                if (File.Exists(pngPath))
3226
                {
3227
                    File.Delete(pngPath);
3228
                }
3229

    
3230
                ////bmp => grayscale bmp => png
3231
                //using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3232
                //{
3233
                //    System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height);
3234
                //    //get a graphics object from the new image
3235
                //    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
3236
                //    {
3237
                //        //create the grayscale ColorMatrix
3238
                //        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][]
3239
                //        {
3240
                //            new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
3241
                //            new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
3242
                //            new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
3243
                //            new float[] { 0,      0,      0,      1, 0 },
3244
                //            new float[] { 0,      0,      0,      0, 1 }
3245
                //        });
3246

    
3247
                //        //create some image attributes
3248
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3249
                //        {
3250
                //            //set the color matrix attribute
3251
                //            attributes.SetColorMatrix(colorMatrix);
3252
                //            //attributes.SetThreshold(0.8F);
3253

    
3254
                //            //draw the original image on the new image
3255
                //            //using the grayscale color matrix
3256
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3257
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3258
                //        }
3259

    
3260
                //    }
3261
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3262
                //}
3263

    
3264
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3265
                {
3266
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3267
                }
3268
                if (File.Exists(bmpPath))
3269
                {
3270
                    File.Delete(bmpPath);
3271
                }
3272
            }
3273
        }
3274

    
3275
        /************************************************************************/
3276
        /* Change the color of all objects                                      */
3277
        /************************************************************************/
3278
        private void chageColorAllObjects(Database pDb)
3279
        {
3280
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3281
            {
3282
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3283
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3284

    
3285
                foreach (ObjectId id in btrModelSpace)
3286
                {
3287
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3288
                    if (ent == null) continue;
3289

    
3290
                    ent.ColorIndex = 7;
3291

    
3292
                    if (ent is BlockReference)
3293
                    {
3294
                        changeColorBlocks(tr, (BlockReference)ent);
3295
                    }
3296
                }
3297

    
3298
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3299
                foreach (DBDictionaryEntry entry in dbdic)
3300
                {
3301
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3302
                    if (group == null) continue;
3303

    
3304
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3305
                    if (idarrTags == null) continue;
3306

    
3307
                    foreach (ObjectId id in idarrTags)
3308
                    {
3309
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3310
                        if (ent == null) continue;
3311

    
3312
                        ent.ColorIndex = 7;
3313
                    }
3314
                }
3315

    
3316
                foreach (ObjectId btrId in bt)
3317
                {
3318
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3319
                    if (btr == null) continue;
3320
                    if (btr.Name.StartsWith("*")) continue;
3321

    
3322
                    foreach (ObjectId entId in btr)
3323
                    {
3324
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3325
                        if (ent == null) continue;
3326
                        ent.ColorIndex = 0;//ByBlock
3327
                    }
3328
                }
3329

    
3330
                tr.Commit();
3331
            }
3332
        }
3333

    
3334
        /************************************************************************/
3335
        /* Change the color of blocks                                           */
3336
        /************************************************************************/
3337
        private void changeColorBlocks(Transaction tr, BlockReference blkRef)
3338
        {
3339
            if (blkRef == null) return;
3340

    
3341
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3342
            {
3343
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3344
                {
3345
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3346
                    attRef.ColorIndex = 7;
3347
                }
3348
            }
3349

    
3350
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3351
            if (btrBlock == null) return;
3352

    
3353
            foreach (ObjectId oid in btrBlock)
3354
            {
3355
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3356
                if (ent == null) continue;
3357

    
3358
                ent.ColorIndex = 7;
3359

    
3360
                if (ent is BlockReference)
3361
                {
3362
                    changeColorBlocks(tr, (BlockReference)ent);
3363
                }
3364
            }
3365
        }
3366

    
3367
        /************************************************************************/
3368
        /* Nested block Explode & Purge                                         */
3369
        /************************************************************************/
3370
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3371
        {
3372
            HashSet<string> blockNameList = new HashSet<string>();
3373
            // Explode ModelSpace Nested Block
3374
            blockNameList = explodeNestedBlocks(pDb);
3375

    
3376
            // Prepare Block Purge
3377
            preparePurgeBlocks(pDb, blockNameList);
3378

    
3379
            // Block Purge
3380
            ObjectIdCollection oids = new ObjectIdCollection();
3381
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3382
            {
3383
                foreach (ObjectId id in pTable)
3384
                {
3385
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3386
                    oids.Add(id);
3387
                }
3388
            }
3389
            pDb.Purge(oids);
3390

    
3391
            foreach (ObjectId oid in oids)
3392
            {
3393
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3394
                {
3395
                    btr.Erase(true);
3396
                }
3397
            }
3398
        }
3399

    
3400
        private HashSet<string> explodeNestedBlocks(Database pDb)
3401
        {
3402
            HashSet<string> blockNameList = new HashSet<string>();
3403
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3404

    
3405
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3406
            {
3407
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3408
                {
3409
                    foreach (ObjectId entid in pBlock)
3410
                    {
3411
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3412
                        {
3413
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3414
                            BlockReference blockRef = (BlockReference)pEnt;
3415

    
3416
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3417
                            {
3418
                                bool isNestedBlock = false;
3419
                                foreach (ObjectId blkid in pBtr)
3420
                                {
3421
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3422
                                    {
3423
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3424
                                        {
3425
                                            oidSet.Add(entid);
3426
                                            isNestedBlock = true;                                            
3427
                                        }
3428
                                    }
3429
                                }
3430
                                if (!isNestedBlock)
3431
                                {
3432
                                    blockNameList.Add(blockRef.Name);
3433
                                }
3434
                            }
3435
                        }
3436
                    }
3437
                }
3438
            }
3439

    
3440
            if (oidSet.Count > 0)
3441
            {
3442
                explodeBlocks(oidSet);
3443
                blockNameList = explodeNestedBlocks(pDb);
3444
            }
3445

    
3446
            return blockNameList;
3447
        }
3448

    
3449
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3450
        {
3451
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3452

    
3453
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3454
            {
3455
                foreach (ObjectId id in pTable)
3456
                {
3457
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true))
3458
                    {
3459
                        if (pBlock.IsLayout) continue;
3460
                        if (blockNameList.Contains(pBlock.Name)) continue;
3461

    
3462
                        foreach (ObjectId entid in pBlock)
3463
                        {
3464
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3465
                            {
3466
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3467

    
3468
                                oidSet.Add(entid);
3469
                            }
3470
                        }
3471
                    }
3472
                }
3473
            }
3474

    
3475
            if (oidSet.Count > 0)
3476
            {
3477
                explodeBlocks(oidSet);
3478
                preparePurgeBlocks(pDb, blockNameList);
3479
            }
3480

    
3481
            return;
3482
        }
3483
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3484
        {
3485
            foreach (ObjectId blkId in oidSet)
3486
            {
3487
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3488
                blkRef.ExplodeGeometryToOwnerSpace();
3489
                blkRef.Erase();
3490
            }
3491
        }
3492

    
3493
        /************************************************************************/
3494
        /* Dump the BlockTable                                                  */
3495
        /************************************************************************/
3496
        public void dumpBlocks(Database pDb, int indent, XmlNode node)
3497
        {
3498
            /**********************************************************************/
3499
            /* Get a pointer to the BlockTable                               */
3500
            /**********************************************************************/
3501
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3502
            {
3503
                /**********************************************************************/
3504
                /* Dump the Description                                               */
3505
                /**********************************************************************/
3506
                XmlElement BlocksNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
3507

    
3508
                /**********************************************************************/
3509
                /* Step through the BlockTable                                        */
3510
                /**********************************************************************/
3511
                foreach (ObjectId id in pTable)
3512
                {
3513
                    /********************************************************************/
3514
                    /* Open the BlockTableRecord for Reading                            */
3515
                    /********************************************************************/
3516
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3517
                    {
3518
                        /********************************************************************/
3519
                        /* Dump the BlockTableRecord                                        */
3520
                        /********************************************************************/
3521
                        XmlElement BlockNode = Program.xml.CreateElement(pBlock.GetRXClass().Name);
3522

    
3523
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
3524
                        NameAttr.Value = pBlock.Name;
3525
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3526

    
3527
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3528
                        CommentsAttr.Value = pBlock.Comments;
3529
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3530

    
3531
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3532
                        OriginAttr.Value = pBlock.Origin.ToString();
3533
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3534

    
3535
                        writeLine(indent, pBlock.GetRXClass().Name);
3536
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3537
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3538
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3539
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3540
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3541

    
3542
                        try
3543
                        {
3544
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3545
                            extents.AddBlockExtents(pBlock);
3546

    
3547
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3548
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3549
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3550

    
3551
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3552
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3553
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3554
                        }
3555
                        catch (System.Exception)
3556
                        {
3557
                        }
3558

    
3559
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3560
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3561
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3562
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3563
                        {
3564
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3565
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3566
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3567
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3568
                        }
3569

    
3570
                        /********************************************************************/
3571
                        /* Step through the BlockTableRecord                                */
3572
                        /********************************************************************/
3573
                        foreach (ObjectId entid in pBlock)
3574
                        {
3575
                            /********************************************************************/
3576
                            /* Dump the Entity                                                  */
3577
                            /********************************************************************/
3578
                            dumpEntity(entid, indent + 1, BlockNode);
3579
                        }
3580

    
3581
                        BlocksNode.AppendChild(BlockNode);
3582
                    }
3583
                }
3584

    
3585
                node.AppendChild(BlocksNode);
3586
            }
3587
        }
3588

    
3589
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3590
        {
3591
            /**********************************************************************/
3592
            /* Get a SmartPointer to the DimStyleTable                            */
3593
            /**********************************************************************/
3594
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3595
            {
3596
                /**********************************************************************/
3597
                /* Dump the Description                                               */
3598
                /**********************************************************************/
3599
                writeLine();
3600
                writeLine(indent++, pTable.GetRXClass().Name);
3601

    
3602
                /**********************************************************************/
3603
                /* Step through the DimStyleTable                                    */
3604
                /**********************************************************************/
3605
                foreach (ObjectId id in pTable)
3606
                {
3607
                    /*********************************************************************/
3608
                    /* Open the DimStyleTableRecord for Reading                         */
3609
                    /*********************************************************************/
3610
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3611
                    {
3612
                        /*********************************************************************/
3613
                        /* Dump the DimStyleTableRecord                                      */
3614
                        /*********************************************************************/
3615
                        writeLine();
3616
                        writeLine(indent, pRecord.GetRXClass().Name);
3617
                        writeLine(indent, "Name", pRecord.Name);
3618
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3619

    
3620
                        writeLine(indent, "Background Text Color", pRecord.Dimtfillclr);
3621
                        writeLine(indent, "BackgroundText Flags", pRecord.Dimtfill);
3622
                        writeLine(indent, "Extension Line 1 Linetype", pRecord.Dimltex1);
3623
                        writeLine(indent, "Extension Line 2 Linetype", pRecord.Dimltex2);
3624
                        writeLine(indent, "Dimension Line Linetype", pRecord.Dimltype);
3625
                        writeLine(indent, "Extension Line Fixed Len", pRecord.Dimfxlen);
3626
                        writeLine(indent, "Extension Line Fixed Len Enable", pRecord.DimfxlenOn);
3627
                        writeLine(indent, "Jog Angle", toDegreeString(pRecord.Dimjogang));
3628
                        writeLine(indent, "Modified For Recompute", pRecord.IsModifiedForRecompute);
3629
                        writeLine(indent, "DIMADEC", pRecord.Dimadec);
3630
                        writeLine(indent, "DIMALT", pRecord.Dimalt);
3631
                        writeLine(indent, "DIMALTD", pRecord.Dimaltd);
3632
                        writeLine(indent, "DIMALTF", pRecord.Dimaltf);
3633
                        writeLine(indent, "DIMALTRND", pRecord.Dimaltrnd);
3634
                        writeLine(indent, "DIMALTTD", pRecord.Dimalttd);
3635
                        writeLine(indent, "DIMALTTZ", pRecord.Dimalttz);
3636
                        writeLine(indent, "DIMALTU", pRecord.Dimaltu);
3637
                        writeLine(indent, "DIMALTZ", pRecord.Dimaltz);
3638
                        writeLine(indent, "DIMAPOST", pRecord.Dimapost);
3639
                        writeLine(indent, "DIMASZ", pRecord.Dimasz);
3640
                        writeLine(indent, "DIMATFIT", pRecord.Dimatfit);
3641
                        writeLine(indent, "DIMAUNIT", pRecord.Dimaunit);
3642
                        writeLine(indent, "DIMAZIN", pRecord.Dimazin);
3643
                        writeLine(indent, "DIMBLK", pRecord.Dimblk);
3644
                        writeLine(indent, "DIMBLK1", pRecord.Dimblk1);
3645
                        writeLine(indent, "DIMBLK2", pRecord.Dimblk2);
3646
                        writeLine(indent, "DIMCEN", pRecord.Dimcen);
3647
                        writeLine(indent, "DIMCLRD", pRecord.Dimclrd);
3648
                        writeLine(indent, "DIMCLRE", pRecord.Dimclre);
3649
                        writeLine(indent, "DIMCLRT", pRecord.Dimclrt);
3650
                        writeLine(indent, "DIMDEC", pRecord.Dimdec);
3651
                        writeLine(indent, "DIMDLE", pRecord.Dimdle);
3652
                        writeLine(indent, "DIMDLI", pRecord.Dimdli);
3653
                        writeLine(indent, "DIMDSEP", pRecord.Dimdsep);
3654
                        writeLine(indent, "DIMEXE", pRecord.Dimexe);
3655
                        writeLine(indent, "DIMEXO", pRecord.Dimexo);
3656
                        writeLine(indent, "DIMFRAC", pRecord.Dimfrac);
3657
                        writeLine(indent, "DIMGAP", pRecord.Dimgap);
3658
                        writeLine(indent, "DIMJUST", pRecord.Dimjust);
3659
                        writeLine(indent, "DIMLDRBLK", pRecord.Dimldrblk);
3660
                        writeLine(indent, "DIMLFAC", pRecord.Dimlfac);
3661
                        writeLine(indent, "DIMLIM", pRecord.Dimlim);
3662
                        writeLine(indent, "DIMLUNIT", pRecord.Dimlunit);
3663
                        writeLine(indent, "DIMLWD", pRecord.Dimlwd);
3664
                        writeLine(indent, "DIMLWE", pRecord.Dimlwe);
3665
                        writeLine(indent, "DIMPOST", pRecord.Dimpost);
3666
                        writeLine(indent, "DIMRND", pRecord.Dimrnd);
3667
                        writeLine(indent, "DIMSAH", pRecord.Dimsah);
3668
                        writeLine(indent, "DIMSCALE", pRecord.Dimscale);
3669
                        writeLine(indent, "DIMSD1", pRecord.Dimsd1);
3670
                        writeLine(indent, "DIMSD2", pRecord.Dimsd2);
3671
                        writeLine(indent, "DIMSE1", pRecord.Dimse1);
3672
                        writeLine(indent, "DIMSE2", pRecord.Dimse2);
3673
                        writeLine(indent, "DIMSOXD", pRecord.Dimsoxd);
3674
                        writeLine(indent, "DIMTAD", pRecord.Dimtad);
3675
                        writeLine(indent, "DIMTDEC", pRecord.Dimtdec);
3676
                        writeLine(indent, "DIMTFAC", pRecord.Dimtfac);
3677
                        writeLine(indent, "DIMTIH", pRecord.Dimtih);
3678
                        writeLine(indent, "DIMTIX", pRecord.Dimtix);
3679
                        writeLine(indent, "DIMTM", pRecord.Dimtm);
3680
                        writeLine(indent, "DIMTOFL", pRecord.Dimtofl);
3681
                        writeLine(indent, "DIMTOH", pRecord.Dimtoh);
3682
                        writeLine(indent, "DIMTOL", pRecord.Dimtol);
3683
                        writeLine(indent, "DIMTOLJ", pRecord.Dimtolj);
3684
                        writeLine(indent, "DIMTP", pRecord.Dimtp);
3685
                        writeLine(indent, "DIMTSZ", pRecord.Dimtsz);
3686
                        writeLine(indent, "DIMTVP", pRecord.Dimtvp);
3687
                        writeLine(indent, "DIMTXSTY", pRecord.Dimtxsty);
3688
                        writeLine(indent, "DIMTXT", pRecord.Dimtxt);
3689
                        writeLine(indent, "DIMTZIN", pRecord.Dimtzin);
3690
                        writeLine(indent, "DIMUPT", pRecord.Dimupt);
3691
                        writeLine(indent, "DIMZIN", pRecord.Dimzin);
3692

    
3693
                        dumpSymbolTableRecord(pRecord, indent, node);
3694
                    }
3695
                }
3696
            }
3697
        }
3698

    
3699
        /// <summary>
3700
        /// extract information from entity has given id
3701
        /// </summary>
3702
        /// <param name="id"></param>
3703
        /// <param name="indent"></param>
3704
        /// <param name="node">XmlNode</param>
3705
        public void dumpEntity(ObjectId id, int indent, XmlNode node)
3706
        {
3707
            /**********************************************************************/
3708
            /* Get a pointer to the Entity                                   */
3709
            /**********************************************************************/
3710
            try
3711
            {
3712
                using (Entity pEnt = (Entity)id.Open(OpenMode.ForRead, false, true))
3713
                {
3714
                    /**********************************************************************/
3715
                    /* Dump the entity                                                    */
3716
                    /**********************************************************************/
3717
                    writeLine();
3718
                    // Protocol extensions are not supported in DD.NET (as well as in ARX.NET)
3719
                    // so we just switch by entity type here
3720
                    // (maybe it makes sense to make a map: type -> delegate)
3721
                    switch (pEnt.GetRXClass().Name)
3722
                    {
3723
                        case "AcDbAlignedDimension":
3724
                            dump((AlignedDimension)pEnt, indent, node);
3725
                            break;
3726
                        case "AcDbArc":
3727
                            dump((Arc)pEnt, indent, node);
3728
                            break;
3729
                        case "AcDbArcDimension":
3730
                            dump((ArcDimension)pEnt, indent, node);
3731
                            break;
3732
                        case "AcDbBlockReference":
3733
                            dump((BlockReference)pEnt, indent, node);
3734
                            break;
3735
                        case "AcDbBody":
3736
                            dump((Body)pEnt, indent, node);
3737
                            break;
3738
                        case "AcDbCircle":
3739
                            dump((Circle)pEnt, indent, node);
3740
                            break;
3741
                        case "AcDbPoint":
3742
                            dump((DBPoint)pEnt, indent);
3743
                            break;
3744
                        case "AcDbText":
3745
                            dump((DBText)pEnt, indent, node);
3746
                            break;
3747
                        case "AcDbDiametricDimension":
3748
                            dump((DiametricDimension)pEnt, indent, node);
3749
                            break;
3750
                        case "AcDbViewport":
3751
                            dump((Teigha.DatabaseServices.Viewport)pEnt, indent, node);
3752
                            break;
3753
                        case "AcDbEllipse":
3754
                            dump((Ellipse)pEnt, indent, node);
3755
                            break;
3756
                        case "AcDbFace":
3757
                            dump((Face)pEnt, indent, node);
3758
                            break;
3759
                        case "AcDbFcf":
3760
                            dump((FeatureControlFrame)pEnt, indent);
3761
                            break;
3762
                        case "AcDbHatch":
3763
                            dump((Hatch)pEnt, indent);
3764
                            break;
3765
                        case "AcDbLeader":
3766
                            dump((Leader)pEnt, indent);
3767
                            break;
3768
                        case "AcDbLine":
3769
                            dump((Line)pEnt, indent, node);
3770
                            break;
3771
                        case "AcDb2LineAngularDimension":
3772
                            dump((LineAngularDimension2)pEnt, indent, node);
3773
                            break;
3774
                        case "AcDbMInsertBlock":
3775
                            dump((MInsertBlock)pEnt, indent, node);
3776
                            break;
3777
                        case "AcDbMline":
3778
                            dump((Mline)pEnt, indent);
3779
                            break;
3780
                        case "AcDbMText":
3781
                            dump((MText)pEnt, indent, node);
3782
                            break;
3783
                        case "AcDbOle2Frame":
3784
                            dump((Ole2Frame)pEnt, indent);
3785
                            break;
3786
                        case "AcDbOrdinateDimension":
3787
                            dump((OrdinateDimension)pEnt, indent, node);
3788
                            break;
3789
                        case "AcDb3PointAngularDimension":
3790
                            dump((Point3AngularDimension)pEnt, indent, node);
3791
                            break;
3792
                        case "AcDbPolyFaceMesh":
3793
                            dump((PolyFaceMesh)pEnt, indent, node);
3794
                            break;
3795
                        case "AcDbPolygonMesh":
3796
                            dump((PolygonMesh)pEnt, indent);
3797
                            break;
3798
                        case "AcDbPolyline":
3799
                            dump((Teigha.DatabaseServices.Polyline)pEnt, indent, node);
3800
                            break;
3801
                        case "AcDb2dPolyline":
3802
                            dump((Polyline2d)pEnt, indent, node);
3803
                            break;
3804
                        case "AcDb3dPolyline":
3805
                            dump((Polyline3d)pEnt, indent, node);
3806
                            break;
3807
                        case "AcDbProxyEntity":
3808
                            dump((ProxyEntity)pEnt, indent, node);
3809
                            break;
3810
                        case "AcDbRadialDimension":
3811
                            dump((RadialDimension)pEnt, indent, node);
3812
                            break;
3813
                        case "AcDbRasterImage":
3814
                            dump((RasterImage)pEnt, indent);
3815
                            break;
3816
                        case "AcDbRay":
3817
                            dump((Ray)pEnt, indent);
3818
                            break;
3819
                        case "AcDbRegion":
3820
                            dump((Region)pEnt, indent);
3821
                            break;
3822
                        case "AcDbRotatedDimension":
3823
                            dump((RotatedDimension)pEnt, indent, node);
3824
                            break;
3825
                        case "AcDbShape":
3826
                            dump((Shape)pEnt, indent);
3827
                            break;
3828
                        case "AcDb3dSolid":
3829
                            dump((Solid3d)pEnt, indent, node);
3830
                            break;
3831
                        case "AcDbSpline":
3832
                            dump((Spline)pEnt, indent);
3833
                            break;
3834
                        case "AcDbTable":
3835
                            dump((Table)pEnt, indent);
3836
                            break;
3837
                        case "AcDbTrace":
3838
                            dump((Trace)pEnt, indent);
3839
                            break;
3840
                        case "AcDbWipeout":
3841
                            dump((Wipeout)pEnt, indent);
3842
                            break;
3843
                        case "AcDbXline":
3844
                            dump((Xline)pEnt, indent);
3845
                            break;
3846
                        case "AcDbPdfReference":
3847
                        case "AcDbDwfReference":
3848
                        case "AcDbDgnReference":
3849
                            dump((UnderlayReference)pEnt, indent);
3850
                            break;
3851
                        default:
3852
                            dump(pEnt, indent, node);
3853
                            break;
3854
                    }
3855
                    /* Dump the Xdata                                                     */
3856
                    /**********************************************************************/
3857
                    dumpXdata(pEnt.XData, indent);
3858

    
3859
                    /**********************************************************************/
3860
                    /* Dump the Extension Dictionary                                      */
3861
                    /**********************************************************************/
3862
                    if (!pEnt.ExtensionDictionary.IsNull)
3863
                    {
3864
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
3865
                    }
3866
                }
3867
            }
3868
            catch (System.Exception ex)
3869
            {
3870
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
3871
            }
3872
        }
3873
        public void dumpHeader(Database pDb, int indent, XmlNode node)
3874
        {
3875
            if (node != null)
3876
            {
3877
                XmlAttribute FileNameAttr = Program.xml.CreateAttribute("FileName");
3878
                FileNameAttr.Value = shortenPath(pDb.Filename);
3879
                node.Attributes.SetNamedItem(FileNameAttr);
3880

    
3881
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
3882
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
3883
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
3884

    
3885
                writeLine();
3886
                writeLine(indent++, "Header Variables:");
3887

    
3888
                //writeLine();
3889
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
3890
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
3891

    
3892
                writeLine();
3893
                writeLine(indent, "ANGBASE", pDb.Angbase);
3894
                writeLine(indent, "ANGDIR", pDb.Angdir);
3895
                writeLine(indent, "ATTMODE", pDb.Attmode);
3896
                writeLine(indent, "AUNITS", pDb.Aunits);
3897
                writeLine(indent, "AUPREC", pDb.Auprec);
3898
                writeLine(indent, "CECOLOR", pDb.Cecolor);
3899
                writeLine(indent, "CELTSCALE", pDb.Celtscale);
3900
                writeLine(indent, "CHAMFERA", pDb.Chamfera);
3901
                writeLine(indent, "CHAMFERB", pDb.Chamferb);
3902
                writeLine(indent, "CHAMFERC", pDb.Chamferc);
3903
                writeLine(indent, "CHAMFERD", pDb.Chamferd);
3904
                writeLine(indent, "CMLJUST", pDb.Cmljust);
3905
                writeLine(indent, "CMLSCALE", pDb.Cmljust);
3906
                writeLine(indent, "DIMADEC", pDb.Dimadec);
3907
                writeLine(indent, "DIMALT", pDb.Dimalt);
3908
                writeLine(indent, "DIMALTD", pDb.Dimaltd);
3909
                writeLine(indent, "DIMALTF", pDb.Dimaltf);
3910
                writeLine(indent, "DIMALTRND", pDb.Dimaltrnd);
3911
                writeLine(indent, "DIMALTTD", pDb.Dimalttd);
3912
                writeLine(indent, "DIMALTTZ", pDb.Dimalttz);
3913
                writeLine(indent, "DIMALTU", pDb.Dimaltu);
3914
                writeLine(indent, "DIMALTZ", pDb.Dimaltz);
3915
                writeLine(indent, "DIMAPOST", pDb.Dimapost);
3916
                writeLine(indent, "DIMASZ", pDb.Dimasz);
3917
                writeLine(indent, "DIMATFIT", pDb.Dimatfit);
3918
                writeLine(indent, "DIMAUNIT", pDb.Dimaunit);
3919
                writeLine(indent, "DIMAZIN", pDb.Dimazin);
3920
                writeLine(indent, "DIMBLK", pDb.Dimblk);
3921
                writeLine(indent, "DIMBLK1", pDb.Dimblk1);
3922
                writeLine(indent, "DIMBLK2", pDb.Dimblk2);
3923
                writeLine(indent, "DIMCEN", pDb.Dimcen);
3924
                writeLine(indent, "DIMCLRD", pDb.Dimclrd);
3925
                writeLine(indent, "DIMCLRE", pDb.Dimclre);
3926
                writeLine(indent, "DIMCLRT", pDb.Dimclrt);
3927
                writeLine(indent, "DIMDEC", pDb.Dimdec);
3928
                writeLine(indent, "DIMDLE", pDb.Dimdle);
3929
                writeLine(indent, "DIMDLI", pDb.Dimdli);
3930
                writeLine(indent, "DIMDSEP", pDb.Dimdsep);
3931
                writeLine(indent, "DIMEXE", pDb.Dimexe);
3932
                writeLine(indent, "DIMEXO", pDb.Dimexo);
3933
                writeLine(indent, "DIMFRAC", pDb.Dimfrac);
3934
                writeLine(indent, "DIMGAP", pDb.Dimgap);
3935
                writeLine(indent, "DIMJUST", pDb.Dimjust);
3936
                writeLine(indent, "DIMLDRBLK", pDb.Dimldrblk);
3937
                writeLine(indent, "DIMLFAC", pDb.Dimlfac);
3938
                writeLine(indent, "DIMLIM", pDb.Dimlim);
3939
                writeLine(indent, "DIMLUNIT", pDb.Dimlunit);
3940
                writeLine(indent, "DIMLWD", pDb.Dimlwd);
3941
                writeLine(indent, "DIMLWE", pDb.Dimlwe);
3942
                writeLine(indent, "DIMPOST", pDb.Dimpost);
3943
                writeLine(indent, "DIMRND", pDb.Dimrnd);
3944
                writeLine(indent, "DIMSAH", pDb.Dimsah);
3945
                writeLine(indent, "DIMSCALE", pDb.Dimscale);
3946
                writeLine(indent, "DIMSD1", pDb.Dimsd1);
3947
                writeLine(indent, "DIMSD2", pDb.Dimsd2);
3948
                writeLine(indent, "DIMSE1", pDb.Dimse1);
3949
                writeLine(indent, "DIMSE2", pDb.Dimse2);
3950
                writeLine(indent, "DIMSOXD", pDb.Dimsoxd);
3951
                writeLine(indent, "DIMTAD", pDb.Dimtad);
3952
                writeLine(indent, "DIMTDEC", pDb.Dimtdec);
3953
                writeLine(indent, "DIMTFAC", pDb.Dimtfac);
3954
                writeLine(indent, "DIMTIH", pDb.Dimtih);
3955
                writeLine(indent, "DIMTIX", pDb.Dimtix);
3956
                writeLine(indent, "DIMTM", pDb.Dimtm);
3957
                writeLine(indent, "DIMTOFL", pDb.Dimtofl);
3958
                writeLine(indent, "DIMTOH", pDb.Dimtoh);
3959
                writeLine(indent, "DIMTOL", pDb.Dimtol);
3960
                writeLine(indent, "DIMTOLJ", pDb.Dimtolj);
3961
                writeLine(indent, "DIMTP", pDb.Dimtp);
3962
                writeLine(indent, "DIMTSZ", pDb.Dimtsz);
3963
                writeLine(indent, "DIMTVP", pDb.Dimtvp);
3964
                writeLine(indent, "DIMTXSTY", pDb.Dimtxsty);
3965
                writeLine(indent, "DIMTXT", pDb.Dimtxt);
3966
                writeLine(indent, "DIMTZIN", pDb.Dimtzin);
3967
                writeLine(indent, "DIMUPT", pDb.Dimupt);
3968
                writeLine(indent, "DIMZIN", pDb.Dimzin);
3969
                writeLine(indent, "DISPSILH", pDb.DispSilh);
3970
                writeLine(indent, "DRAWORDERCTL", pDb.DrawOrderCtl);
3971
                writeLine(indent, "ELEVATION", pDb.Elevation);
3972
                writeLine(indent, "EXTMAX", pDb.Extmax);
3973
                writeLine(indent, "EXTMIN", pDb.Extmin);
3974
                writeLine(indent, "FACETRES", pDb.Facetres);
3975
                writeLine(indent, "FILLETRAD", pDb.Filletrad);
3976
                writeLine(indent, "FILLMODE", pDb.Fillmode);
3977
                writeLine(indent, "INSBASE", pDb.Insbase);
3978
                writeLine(indent, "ISOLINES", pDb.Isolines);
3979
                writeLine(indent, "LIMCHECK", pDb.Limcheck);
3980
                writeLine(indent, "LIMMAX", pDb.Limmax);
3981
                writeLine(indent, "LIMMIN", pDb.Limmin);
3982
                writeLine(indent, "LTSCALE", pDb.Ltscale);
3983
                writeLine(indent, "LUNITS", pDb.Lunits);
3984
                writeLine(indent, "LUPREC", pDb.Luprec);
3985
                writeLine(indent, "MAXACTVP", pDb.Maxactvp);
3986
                writeLine(indent, "MIRRTEXT", pDb.Mirrtext);
3987
                writeLine(indent, "ORTHOMODE", pDb.Orthomode);
3988
                writeLine(indent, "PDMODE", pDb.Pdmode);
3989
                writeLine(indent, "PDSIZE", pDb.Pdsize);
3990
                writeLine(indent, "PELEVATION", pDb.Pelevation);
3991
                writeLine(indent, "PELLIPSE", pDb.PlineEllipse);
3992
                writeLine(indent, "PEXTMAX", pDb.Pextmax);
3993
                writeLine(indent, "PEXTMIN", pDb.Pextmin);
3994
                writeLine(indent, "PINSBASE", pDb.Pinsbase);
3995
                writeLine(indent, "PLIMCHECK", pDb.Plimcheck);
3996
                writeLine(indent, "PLIMMAX", pDb.Plimmax);
3997
                writeLine(indent, "PLIMMIN", pDb.Plimmin);
3998
                writeLine(indent, "PLINEGEN", pDb.Plinegen);
3999
                writeLine(indent, "PLINEWID", pDb.Plinewid);
4000
                writeLine(indent, "PROXYGRAPHICS", pDb.Saveproxygraphics);
4001
                writeLine(indent, "PSLTSCALE", pDb.Psltscale);
4002
                writeLine(indent, "PUCSNAME", pDb.Pucsname);
4003
                writeLine(indent, "PUCSORG", pDb.Pucsorg);
4004
                writeLine(indent, "PUCSXDIR", pDb.Pucsxdir);
4005
                writeLine(indent, "PUCSYDIR", pDb.Pucsydir);
4006
                writeLine(indent, "QTEXTMODE", pDb.Qtextmode);
4007
                writeLine(indent, "REGENMODE", pDb.Regenmode);
4008
                writeLine(indent, "SHADEDGE", pDb.Shadedge);
4009
                writeLine(indent, "SHADEDIF", pDb.Shadedif);
4010
                writeLine(indent, "SKETCHINC", pDb.Sketchinc);
4011
                writeLine(indent, "SKPOLY", pDb.Skpoly);
4012
                writeLine(indent, "SPLFRAME", pDb.Splframe);
4013
                writeLine(indent, "SPLINESEGS", pDb.Splinesegs);
4014
                writeLine(indent, "SPLINETYPE", pDb.Splinetype);
4015
                writeLine(indent, "SURFTAB1", pDb.Surftab1);
4016
                writeLine(indent, "SURFTAB2", pDb.Surftab2);
4017
                writeLine(indent, "SURFTYPE", pDb.Surftype);
4018
                writeLine(indent, "SURFU", pDb.Surfu);
4019
                writeLine(indent, "SURFV", pDb.Surfv);
4020
                //writeLine(indent, "TEXTQLTY", pDb.TEXTQLTY);
4021
                writeLine(indent, "TEXTSIZE", pDb.Textsize);
4022
                writeLine(indent, "THICKNESS", pDb.Thickness);
4023
                writeLine(indent, "TILEMODE", pDb.TileMode);
4024
                writeLine(indent, "TRACEWID", pDb.Tracewid);
4025
                writeLine(indent, "TREEDEPTH", pDb.Treedepth);
4026
                writeLine(indent, "UCSNAME", pDb.Ucsname);
4027
                writeLine(indent, "UCSORG", pDb.Ucsorg);
4028
                writeLine(indent, "UCSXDIR", pDb.Ucsxdir);
4029
                writeLine(indent, "UCSYDIR", pDb.Ucsydir);
4030
                writeLine(indent, "UNITMODE", pDb.Unitmode);
4031
                writeLine(indent, "USERI1", pDb.Useri1);
4032
                writeLine(indent, "USERI2", pDb.Useri2);
4033
                writeLine(indent, "USERI3", pDb.Useri3);
4034
                writeLine(indent, "USERI4", pDb.Useri4);
4035
                writeLine(indent, "USERI5", pDb.Useri5);
4036
                writeLine(indent, "USERR1", pDb.Userr1);
4037
                writeLine(indent, "USERR2", pDb.Userr2);
4038
                writeLine(indent, "USERR3", pDb.Userr3);
4039
                writeLine(indent, "USERR4", pDb.Userr4);
4040
                writeLine(indent, "USERR5", pDb.Userr5);
4041
                writeLine(indent, "USRTIMER", pDb.Usrtimer);
4042
                writeLine(indent, "VISRETAIN", pDb.Visretain);
4043
                writeLine(indent, "WORLDVIEW", pDb.Worldview);
4044
            }
4045
        }
4046

    
4047
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4048
        {
4049
            if (node != null)
4050
            {
4051
                /**********************************************************************/
4052
                /* Get a SmartPointer to the LayerTable                               */
4053
                /**********************************************************************/
4054
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4055
                {
4056
                    /**********************************************************************/
4057
                    /* Dump the Description                                               */
4058
                    /**********************************************************************/
4059
                    XmlElement LayerNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4060

    
4061
                    /**********************************************************************/
4062
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4063
                    /**********************************************************************/
4064

    
4065
                    /**********************************************************************/
4066
                    /* Step through the LayerTable                                        */
4067
                    /**********************************************************************/
4068
                    foreach (ObjectId id in pTable)
4069
                    {
4070
                        /********************************************************************/
4071
                        /* Open the LayerTableRecord for Reading                            */
4072
                        /********************************************************************/
4073
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4074
                        {
4075
                            /********************************************************************/
4076
                            /* Dump the LayerTableRecord                                        */
4077
                            /********************************************************************/
4078
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4079

    
4080
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4081
                            NameAttr.Value = pRecord.Name.ToString();
4082
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4083

    
4084
                            XmlAttribute IsUsedAttr = Program.xml.CreateAttribute("IsUsed");
4085
                            IsUsedAttr.Value = pRecord.IsUsed.ToString();
4086
                            RecordNode.Attributes.SetNamedItem(IsUsedAttr);
4087

    
4088
                            XmlAttribute IsOffAttr = Program.xml.CreateAttribute("IsOff");
4089
                            IsOffAttr.Value = pRecord.IsOff.ToString();
4090
                            RecordNode.Attributes.SetNamedItem(IsOffAttr);
4091

    
4092
                            XmlAttribute IsFrozenAttr = Program.xml.CreateAttribute("IsFrozen");
4093
                            IsFrozenAttr.Value = pRecord.IsFrozen.ToString();
4094
                            RecordNode.Attributes.SetNamedItem(IsFrozenAttr);
4095

    
4096
                            XmlAttribute IsLockedAttr = Program.xml.CreateAttribute("IsLocked");
4097
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4098
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4099

    
4100
                            XmlAttribute ColorAttr = Program.xml.CreateAttribute("Color");
4101
                            ColorAttr.Value = pRecord.Color.ToString();
4102
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4103

    
4104
                            XmlAttribute LinetypeObjectIdAttr = Program.xml.CreateAttribute("LinetypeObjectId");
4105
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4106
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4107

    
4108
                            XmlAttribute LineWeightAttr = Program.xml.CreateAttribute("LineWeight");
4109
                            LineWeightAttr.Value = pRecord.LineWeight.ToString();
4110
                            RecordNode.Attributes.SetNamedItem(LineWeightAttr);
4111

    
4112
                            XmlAttribute PlotStyleNameAttr = Program.xml.CreateAttribute("PlotStyleName");
4113
                            PlotStyleNameAttr.Value = pRecord.PlotStyleName.ToString();
4114
                            RecordNode.Attributes.SetNamedItem(PlotStyleNameAttr);
4115

    
4116
                            XmlAttribute IsPlottableAttr = Program.xml.CreateAttribute("IsPlottable");
4117
                            IsPlottableAttr.Value = pRecord.IsPlottable.ToString();
4118
                            RecordNode.Attributes.SetNamedItem(IsPlottableAttr);
4119

    
4120
                            XmlAttribute ViewportVisibilityDefaultAttr = Program.xml.CreateAttribute("ViewportVisibilityDefault");
4121
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4122
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4123

    
4124
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4125
                            LayerNode.AppendChild(RecordNode);
4126
                        }
4127
                    }
4128

    
4129
                    node.AppendChild(LayerNode);
4130
                }
4131
            }
4132
        }
4133

    
4134
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4135
        {
4136
            if (node != null)
4137
            {
4138
                /**********************************************************************/
4139
                /* Get a pointer to the LinetypeTable                            */
4140
                /**********************************************************************/
4141
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4142
                {
4143
                    XmlElement LinetypeNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4144

    
4145
                    /**********************************************************************/
4146
                    /* Step through the LinetypeTable                                     */
4147
                    /**********************************************************************/
4148
                    foreach (ObjectId id in pTable)
4149
                    {
4150
                        /*********************************************************************/
4151
                        /* Open the LinetypeTableRecord for Reading                          */
4152
                        /*********************************************************************/
4153
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4154
                        {
4155
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4156

    
4157
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4158
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4159
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4160

    
4161
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4162
                            NameAttr.Value = pRecord.Name;
4163
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4164

    
4165
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4166
                            CommentsAttr.Value = pRecord.Comments;
4167
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4168

    
4169
                            /********************************************************************/
4170
                            /* Dump the first line of record as in ACAD.LIN                     */
4171
                            /********************************************************************/
4172
                            string buffer = "*" + pRecord.Name;
4173
                            if (pRecord.Comments != "")
4174
                            {
4175
                                buffer = buffer + "," + pRecord.Comments;
4176
                            }
4177
                            writeLine(indent, buffer);
4178

    
4179
                            /********************************************************************/
4180
                            /* Dump the second line of record as in ACAD.LIN                    */
4181
                            /********************************************************************/
4182
                            if (pRecord.NumDashes > 0)
4183
                            {
4184
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4185
                                for (int i = 0; i < pRecord.NumDashes; i++)
4186
                                {
4187
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4188
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4189
                                    string text = pRecord.TextAt(i);
4190

    
4191
                                    /**************************************************************/
4192
                                    /* Dump the Complex Line                                      */
4193
                                    /**************************************************************/
4194
                                    if (shapeNumber != 0 || text != "")
4195
                                    {
4196
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4197
                                        {
4198
                                            if (shapeNumber != 0)
4199
                                            {
4200
                                                buffer = buffer + ",[" + shapeNumber + ",";
4201
                                                if (pTextStyle != null)
4202
                                                    buffer = buffer + pTextStyle.FileName;
4203
                                                else
4204
                                                    buffer = buffer + "NULL style";
4205
                                            }
4206
                                            else
4207
                                            {
4208
                                                buffer = buffer + ",[" + text + ",";
4209
                                                if (pTextStyle != null)
4210
                                                    buffer = buffer + pTextStyle.Name;
4211
                                                else
4212
                                                    buffer = buffer + "NULL style";
4213
                                            }
4214
                                        }
4215

    
4216
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4217
                                        {
4218
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4219
                                        }
4220
                                        if (pRecord.ShapeRotationAt(i) != 0)
4221
                                        {
4222
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4223
                                        }
4224
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4225
                                        {
4226
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4227
                                        }
4228
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4229
                                        {
4230
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4231
                                        }
4232
                                        buffer = buffer + "]";
4233
                                    }
4234
                                }
4235
                                writeLine(indent, buffer);
4236
                            }
4237
                            dumpSymbolTableRecord(pRecord, indent, node);
4238
                            LinetypeNode.AppendChild(RecordNode);
4239
                        }
4240
                    }
4241

    
4242
                    node.AppendChild(LinetypeNode);
4243
                }
4244
            }
4245
        }
4246

    
4247
        public void dumpRegApps(Database pDb, int indent)
4248
        {
4249
            /**********************************************************************/
4250
            /* Get a pointer to the RegAppTable                            */
4251
            /**********************************************************************/
4252
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4253
            {
4254
                /**********************************************************************/
4255
                /* Dump the Description                                               */
4256
                /**********************************************************************/
4257
                writeLine();
4258
                writeLine(indent++, pTable.GetRXClass().Name);
4259

    
4260
                /**********************************************************************/
4261
                /* Step through the RegAppTable                                    */
4262
                /**********************************************************************/
4263
                foreach (ObjectId id in pTable)
4264
                {
4265
                    /*********************************************************************/
4266
                    /* Open the RegAppTableRecord for Reading                         */
4267
                    /*********************************************************************/
4268
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4269
                    {
4270
                        /*********************************************************************/
4271
                        /* Dump the RegAppTableRecord                                      */
4272
                        /*********************************************************************/
4273
                        writeLine();
4274
                        writeLine(indent, pRecord.GetRXClass().Name);
4275
                        writeLine(indent, "Name", pRecord.Name);
4276
                    }
4277
                }
4278
            }
4279
        }
4280

    
4281
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4282
        {
4283
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4284
            if (pRecord.IsDependent)
4285
            {
4286
                writeLine(indent, "Resolved", pRecord.IsResolved);
4287
            }
4288
        }
4289

    
4290
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4291
        {
4292
            /**********************************************************************/
4293
            /* Get a SmartPointer to the TextStyleTable                            */
4294
            /**********************************************************************/
4295
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4296
            {
4297
                /**********************************************************************/
4298
                /* Dump the Description                                               */
4299
                /**********************************************************************/
4300
                writeLine();
4301
                writeLine(indent++, pTable.GetRXClass().Name);
4302

    
4303
                /**********************************************************************/
4304
                /* Step through the TextStyleTable                                    */
4305
                /**********************************************************************/
4306
                foreach (ObjectId id in pTable)
4307
                {
4308
                    /*********************************************************************/
4309
                    /* Open the TextStyleTableRecord for Reading                         */
4310
                    /*********************************************************************/
4311
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4312
                    {
4313
                        /*********************************************************************/
4314
                        /* Dump the TextStyleTableRecord                                      */
4315
                        /*********************************************************************/
4316
                        writeLine();
4317
                        writeLine(indent, pRecord.GetRXClass().Name);
4318
                        writeLine(indent, "Name", pRecord.Name);
4319
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4320
                        writeLine(indent, "Text Height", pRecord.TextSize);
4321
                        writeLine(indent, "Width Factor", pRecord.XScale);
4322
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4323
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4324
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4325
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4326
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4327
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4328

    
4329
                        FontDescriptor fd = pRecord.Font;
4330
                        writeLine(indent, "Typeface", fd.TypeFace);
4331
                        writeLine(indent, "Character Set", fd.CharacterSet);
4332
                        writeLine(indent, "Bold", fd.Bold);
4333
                        writeLine(indent, "Italic", fd.Italic);
4334
                        writeLine(indent, "Font Pitch & Family", toHexString(fd.PitchAndFamily));
4335
                        dumpSymbolTableRecord(pRecord, indent, node);
4336
                    }
4337
                }
4338
            }
4339
        }
4340
        public void dumpAbstractViewTableRecord(AbstractViewTableRecord pView, int indent, XmlNode node)
4341
        {
4342
            /*********************************************************************/
4343
            /* Dump the AbstractViewTableRecord                                  */
4344
            /*********************************************************************/
4345
            writeLine(indent, "Back Clip Dist", pView.BackClipDistance);
4346
            writeLine(indent, "Back Clip Enabled", pView.BackClipEnabled);
4347
            writeLine(indent, "Front Clip Dist", pView.FrontClipDistance);
4348
            writeLine(indent, "Front Clip Enabled", pView.FrontClipEnabled);
4349
            writeLine(indent, "Front Clip at Eye", pView.FrontClipAtEye);
4350
            writeLine(indent, "Elevation", pView.Elevation);
4351
            writeLine(indent, "Height", pView.Height);
4352
            writeLine(indent, "Width", pView.Width);
4353
            writeLine(indent, "Lens Length", pView.LensLength);
4354
            writeLine(indent, "Render Mode", pView.RenderMode);
4355
            writeLine(indent, "Perspective", pView.PerspectiveEnabled);
4356
            writeLine(indent, "UCS Name", pView.UcsName);
4357

    
4358
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4359
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4360

    
4361
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4362
            {
4363
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4364
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4365
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4366
            }
4367

    
4368
            writeLine(indent, "Target", pView.Target);
4369
            writeLine(indent, "View Direction", pView.ViewDirection);
4370
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4371
            dumpSymbolTableRecord(pView, indent, node);
4372
        }
4373
        public void dumpDimAssoc(DBObject pObject, int indent)
4374
        {
4375

    
4376
        }
4377
        public void dumpMLineStyles(Database pDb, int indent)
4378
        {
4379
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4380
            {
4381
                /**********************************************************************/
4382
                /* Dump the Description                                               */
4383
                /**********************************************************************/
4384
                writeLine();
4385
                writeLine(indent++, pDictionary.GetRXClass().Name);
4386

    
4387
                /**********************************************************************/
4388
                /* Step through the MlineStyle dictionary                             */
4389
                /**********************************************************************/
4390
                DbDictionaryEnumerator e = pDictionary.GetEnumerator();
4391
                while (e.MoveNext())
4392
                {
4393
                    try
4394
                    {
4395
                        using (MlineStyle pEntry = (MlineStyle)e.Value.Open(OpenMode.ForRead))
4396
                        {
4397
                            /*********************************************************************/
4398
                            /* Dump the MLineStyle dictionary entry                              */
4399
                            /*********************************************************************/
4400
                            writeLine();
4401
                            writeLine(indent, pEntry.GetRXClass().Name);
4402
                            writeLine(indent, "Name", pEntry.Name);
4403
                            writeLine(indent, "Description", pEntry.Description);
4404
                            writeLine(indent, "Start Angle", toDegreeString(pEntry.StartAngle));
4405
                            writeLine(indent, "End Angle", toDegreeString(pEntry.EndAngle));
4406
                            writeLine(indent, "Start Inner Arcs", pEntry.StartInnerArcs);
4407
                            writeLine(indent, "End Inner Arcs", pEntry.EndInnerArcs);
4408
                            writeLine(indent, "Start Round Cap", pEntry.StartRoundCap);
4409
                            writeLine(indent, "End Round Cap", pEntry.EndRoundCap);
4410
                            writeLine(indent, "Start Square Cap", pEntry.StartRoundCap);
4411
                            writeLine(indent, "End Square Cap", pEntry.EndRoundCap);
4412
                            writeLine(indent, "Show Miters", pEntry.ShowMiters);
4413
                            /*********************************************************************/
4414
                            /* Dump the elements                                                 */
4415
                            /*********************************************************************/
4416
                            if (pEntry.Elements.Count > 0)
4417
                            {
4418
                                writeLine(indent, "Elements:");
4419
                            }
4420
                            int i = 0;
4421
                            foreach (MlineStyleElement el in pEntry.Elements)
4422
                            {
4423
                                writeLine(indent, "Index", (i++));
4424
                                writeLine(indent + 1, "Offset", el.Offset);
4425
                                writeLine(indent + 1, "Color", el.Color);
4426
                                writeLine(indent + 1, "Linetype", el.LinetypeId);
4427
                            }
4428
                        }
4429
                    }
4430
                    catch (System.Exception)
4431
                    {
4432
                    }
4433
                }
4434
            }
4435
        }
4436
        public void dumpObject(ObjectId id, string itemName, int indent)
4437
        {
4438
            using (DBObject pObject = id.Open(OpenMode.ForRead))
4439
            {
4440
                /**********************************************************************/
4441
                /* Dump the item name and class name                                  */
4442
                /**********************************************************************/
4443
                if (pObject is DBDictionary)
4444
                {
4445
                    writeLine();
4446
                }
4447
                writeLine(indent++, itemName, pObject.GetRXClass().Name);
4448

    
4449
                /**********************************************************************/
4450
                /* Dispatch                                                           */
4451
                /**********************************************************************/
4452
                if (pObject is DBDictionary)
4453
                {
4454
                    /********************************************************************/
4455
                    /* Dump the dictionary                                               */
4456
                    /********************************************************************/
4457
                    DBDictionary pDic = (DBDictionary)pObject;
4458

    
4459
                    /********************************************************************/
4460
                    /* Get a pointer to a new DictionaryIterator                   */
4461
                    /********************************************************************/
4462
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4463

    
4464
                    /********************************************************************/
4465
                    /* Step through the Dictionary                                      */
4466
                    /********************************************************************/
4467
                    while (pIter.MoveNext())
4468
                    {
4469
                        /******************************************************************/
4470
                        /* Dump the Dictionary object                                     */
4471
                        /******************************************************************/
4472
                        dumpObject(pIter.Value, pIter.Key, indent);
4473
                    }
4474
                }
4475
                else if (pObject is Xrecord)
4476
                {
4477
                    /********************************************************************/
4478
                    /* Dump an Xrecord                                                  */
4479
                    /********************************************************************/
4480
                    Xrecord pXRec = (Xrecord)pObject;
4481
                    dumpXdata(pXRec.Data, indent);
4482
                }
4483
            }
4484
        }
4485

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

    
4499
                /**********************************************************************/
4500
                /* Step through the UCSTable                                          */
4501
                /**********************************************************************/
4502
                foreach (ObjectId id in pTable)
4503
                {
4504
                    /********************************************************************/
4505
                    /* Open the UCSTableRecord for Reading                            */
4506
                    /********************************************************************/
4507
                    using (UcsTableRecord pRecord = (UcsTableRecord)id.Open(OpenMode.ForRead))
4508
                    {
4509
                        /********************************************************************/
4510
                        /* Dump the UCSTableRecord                                        */
4511
                        /********************************************************************/
4512
                        writeLine();
4513
                        writeLine(indent, pRecord.GetRXClass().Name);
4514
                        writeLine(indent, "Name", pRecord.Name);
4515
                        writeLine(indent, "UCS Origin", pRecord.Origin);
4516
                        writeLine(indent, "UCS x-Axis", pRecord.XAxis);
4517
                        writeLine(indent, "UCS y-Axis", pRecord.YAxis);
4518
                        dumpSymbolTableRecord(pRecord, indent, node);
4519
                    }
4520
                }
4521
            }
4522
        }
4523
        public void dumpViewports(Database pDb, int indent, XmlNode node)
4524
        {
4525
            /**********************************************************************/
4526
            /* Get a pointer to the ViewportTable                            */
4527
            /**********************************************************************/
4528
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4529
            {
4530
                /**********************************************************************/
4531
                /* Dump the Description                                               */
4532
                /**********************************************************************/
4533
                writeLine();
4534
                writeLine(indent++, pTable.GetRXClass().Name);
4535

    
4536
                /**********************************************************************/
4537
                /* Step through the ViewportTable                                    */
4538
                /**********************************************************************/
4539
                foreach (ObjectId id in pTable)
4540
                {
4541
                    /*********************************************************************/
4542
                    /* Open the ViewportTableRecord for Reading                          */
4543
                    /*********************************************************************/
4544
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4545
                    {
4546
                        /*********************************************************************/
4547
                        /* Dump the ViewportTableRecord                                      */
4548
                        /*********************************************************************/
4549
                        writeLine();
4550
                        writeLine(indent, pRecord.GetRXClass().Name);
4551
                        writeLine(indent, "Name", pRecord.Name);
4552
                        writeLine(indent, "Circle Sides", pRecord.CircleSides);
4553
                        writeLine(indent, "Fast Zooms Enabled", pRecord.FastZoomsEnabled);
4554
                        writeLine(indent, "Grid Enabled", pRecord.GridEnabled);
4555
                        writeLine(indent, "Grid Increments", pRecord.GridIncrements);
4556
                        writeLine(indent, "Icon at Origin", pRecord.IconAtOrigin);
4557
                        writeLine(indent, "Icon Enabled", pRecord.IconEnabled);
4558
                        writeLine(indent, "Iso snap Enabled", pRecord.IsometricSnapEnabled);
4559
                        writeLine(indent, "Iso Snap Pair", pRecord.SnapPair);
4560
                        writeLine(indent, "UCS Saved w/Vport", pRecord.UcsSavedWithViewport);
4561
                        writeLine(indent, "UCS follow", pRecord.UcsFollowMode);
4562
                        writeLine(indent, "Lower-Left Corner", pRecord.LowerLeftCorner);
4563
                        writeLine(indent, "Upper-Right Corner", pRecord.UpperRightCorner);
4564
                        writeLine(indent, "Snap Angle", toDegreeString(pRecord.SnapAngle));
4565
                        writeLine(indent, "Snap Base", pRecord.SnapBase);
4566
                        writeLine(indent, "Snap Enabled", pRecord.SnapEnabled);
4567
                        writeLine(indent, "Snap Increments", pRecord.SnapIncrements);
4568
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4569
                    }
4570
                }
4571
            }
4572
        }
4573

    
4574
        /************************************************************************/
4575
        /* Dump the ViewTable                                                   */
4576
        /************************************************************************/
4577
        public void dumpViews(Database pDb, int indent, XmlNode node)
4578
        {
4579
            /**********************************************************************/
4580
            /* Get a pointer to the ViewTable                                */
4581
            /**********************************************************************/
4582
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
4583
            {
4584
                /**********************************************************************/
4585
                /* Dump the Description                                               */
4586
                /**********************************************************************/
4587
                writeLine();
4588
                writeLine(indent++, pTable.GetRXClass().Name);
4589

    
4590
                /**********************************************************************/
4591
                /* Step through the ViewTable                                         */
4592
                /**********************************************************************/
4593
                foreach (ObjectId id in pTable)
4594
                {
4595
                    /*********************************************************************/
4596
                    /* Open the ViewTableRecord for Reading                              */
4597
                    /*********************************************************************/
4598
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
4599
                    {
4600
                        /*********************************************************************/
4601
                        /* Dump the ViewTableRecord                                          */
4602
                        /*********************************************************************/
4603
                        writeLine();
4604
                        writeLine(indent, pRecord.GetRXClass().Name);
4605
                        writeLine(indent, "Name", pRecord.Name);
4606
                        writeLine(indent, "Category Name", pRecord.CategoryName);
4607
                        writeLine(indent, "Layer State", pRecord.LayerState);
4608

    
4609
                        string layoutName = "";
4610
                        if (!pRecord.Layout.IsNull)
4611
                        {
4612
                            using (Layout pLayout = (Layout)pRecord.Layout.Open(OpenMode.ForRead))
4613
                                layoutName = pLayout.LayoutName;
4614
                        }
4615
                        writeLine(indent, "Layout Name", layoutName);
4616
                        writeLine(indent, "PaperSpace View", pRecord.IsPaperspaceView);
4617
                        writeLine(indent, "Associated UCS", pRecord.IsUcsAssociatedToView);
4618
                        writeLine(indent, "PaperSpace View", pRecord.ViewAssociatedToViewport);
4619
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4620
                    }
4621
                }
4622
            }
4623
        }
4624
        /************************************************************************/
4625
        /* Dump Xdata                                                           */
4626
        /************************************************************************/
4627
        public void dumpXdata(ResultBuffer xIter, int indent)
4628
        {
4629
            if (xIter == null)
4630
                return;
4631
            writeLine(indent++, "Xdata:");
4632
            /**********************************************************************/
4633
            /* Step through the ResBuf chain                                      */
4634
            /**********************************************************************/
4635
            foreach (TypedValue resbuf in xIter)
4636
            {
4637
                writeLine(indent, resbuf);
4638
            }
4639
        }
4640
    }
4641
    class ExProtocolExtension
4642
    {
4643
    }
4644

    
4645
    class Program
4646
    {
4647
        public static XmlDocument xml = null;
4648
        public static double OffsetX = 0;
4649
        public static double OffsetY = 0;
4650
        public static double Scale = 0;
4651
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
4652

    
4653
        static void Main(string[] args)
4654
        {
4655
            /********************************************************************/
4656
            /* Initialize Drawings.NET.                                         */
4657
            /********************************************************************/
4658
            bool bSuccess = true;
4659
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
4660
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
4661
            {
4662
                try
4663
                {
4664
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
4665
                    /**********************************************************************/
4666
                    /* Display the Product and Version that created the executable        */
4667
                    /**********************************************************************/
4668
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
4669

    
4670
                    if (args.Length != 4)
4671
                    {
4672
                        Console.WriteLine("\n\n\tusage: OdReadExMgd <filename> <OffsetX> <OffsetY> <Scale>");
4673
                        Console.WriteLine("\nPress ENTER to continue...\n");
4674
                        Console.ReadLine();
4675
                        bSuccess = false;
4676
                    }
4677
                    else
4678
                    {
4679
                        Console.WriteLine("\n File Name = " + args[0]);
4680

    
4681
                        double.TryParse(args[1], out Program.OffsetX);
4682
                        double.TryParse(args[2], out Program.OffsetY);
4683
                        double.TryParse(args[3], out Program.Scale);
4684
                        Program.xml = new XmlDocument();
4685
                        {
4686
                            XmlNode root = xml.CreateElement("ID2");
4687
                            Program.xml.AppendChild(root);
4688

    
4689
                            /******************************************************************/
4690
                            /* Create a database and load the drawing into it.                
4691
                            /* first parameter means - do not initialize database- it will be read from file
4692
                             * second parameter is not used by Teigha.NET Classic - it is left for ARX compatibility.
4693
                             * Note the 'using' clause - generally, wrappers should disposed after use, 
4694
                             * to close underlying database objects
4695
                            /******************************************************************/
4696
                            using (Database pDb = new Database(false, false))
4697
                            {
4698
                                pDb.ReadDwgFile(args[0], FileShare.Read, true, "");
4699
                                HostApplicationServices.WorkingDatabase = pDb;
4700
                                /****************************************************************/
4701
                                /* Display the File Version                                     */
4702
                                /****************************************************************/
4703
                                Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion);
4704
                                /****************************************************************/
4705
                                /* Dump the database                                            */
4706
                                /****************************************************************/
4707
                                DbDumper dumper = new DbDumper();
4708
                                dumper.ExplodeAndPurgeNestedBlocks(pDb);
4709
                                dumper.ExportPNG(pDb, args[0]);
4710
                                dumper.ExportPDF(pDb, args[0]);
4711

    
4712
                                dumper.dump(pDb, 0, Program.xml.DocumentElement);
4713
                            }
4714
                            Program.xml.Save(Path.Combine(Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]) + ".xml"));
4715
                        }
4716
                    }
4717
                }
4718
                /********************************************************************/
4719
                /* Display the error                                                */
4720
                /********************************************************************/
4721
                catch (System.Exception e)
4722
                {
4723
                    bSuccess = false;
4724
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
4725
                }
4726

    
4727
                if (bSuccess)
4728
                    Console.WriteLine("OdReadExMgd Finished Successfully");
4729
            }
4730
        }
4731
    }
4732
}
클립보드 이미지 추가 (최대 크기: 500 MB)