프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ e9be061d

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

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

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

    
48
        public DbDumper() { }
49

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

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

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

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

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

    
128
            const int tabSize = 2;
129

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
302
                dumpEntityData(pText, indent, TextNode);
303

    
304
                node.AppendChild(TextNode);
305
            }
306

    
307
            return TextNode;
308
        }
309

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

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

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

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

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

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

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

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

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

    
364
                XmlAttribute ScaleFactorsAttr = Program.xml.CreateAttribute("ScaleFactors");
365
                ScaleFactorsAttr.Value = pBlkRef.ScaleFactors.ToString();
366
                BlockReferenceNode.Attributes.SetNamedItem(ScaleFactorsAttr);
367

    
368
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
369
                NormalAttr.Value = pBlkRef.Normal.ToString();
370
                BlockReferenceNode.Attributes.SetNamedItem(NormalAttr);
371

    
372
                XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
373
                NameAttr.Value = pBlkRef.Name;
374
                BlockReferenceNode.Attributes.SetNamedItem(NameAttr);
375

    
376
                // BlockReference DBPoint
377
                string nodePointValue = string.Empty;
378
                Dictionary<long, Point3d> nodePointDic = new Dictionary<long, Point3d>();
379
                using (BlockTableRecord pBtr = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
380
                {
381
                    foreach (ObjectId blkid in pBtr)
382
                    {
383
                        using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
384
                        {
385
                            if (pBlkEnt.GetRXClass().Name == "AcDbPoint")
386
                            {
387
                                DBPoint pt = (DBPoint)pBlkEnt;
388
                                Point3d nodePt = pt.Position.TransformBy(pBlkRef.BlockTransform);
389
                                nodePointDic.Add(Convert.ToInt64(pt.Handle.ToString(), 16), nodePt);
390
                            }
391
                        }
392
                    }
393
                }
394
                if (nodePointDic.Count > 0)
395
                {
396
                    foreach (KeyValuePair<long, Point3d> item in nodePointDic.OrderBy(o => o.Key))
397
                    {
398
                        nodePointValue += item.Value.ToString() + "/";
399
                    }
400
                    nodePointValue = nodePointValue.Substring(0, nodePointValue.Length - 1);
401
                }
402

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

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

    
414
                dumpEntityData(pBlkRef, indent, BlockReferenceNode);
415

    
416
                DBObjectCollection objColl = new DBObjectCollection();
417

    
418
                if (!pBlkRef.Name.StartsWith(BLOCK_GRAPHIC))
419
                {
420
                    pBlkRef.Explode(objColl);
421
                    foreach (var obj in objColl)
422
                    {
423
                        if (obj is DBText)
424
                        {
425
                            dumpTextData(obj as DBText, indent, BlockReferenceNode);
426
                        }
427
                        else if (obj is MText)
428
                        {
429
                            MText mtext = obj as MText;
430

    
431
                            DBObjectCollection objs = new DBObjectCollection();
432
                            mtext.Explode(objs);
433
                            foreach (var item in objs)
434
                            {
435
                                dumpTextData(item as DBText, indent, node);
436
                            }
437
                        }
438
                    }
439
                }
440

    
441
                /**********************************************************************/
442
                /* Dump the attributes                                                */
443
                /**********************************************************************/
444
                int i = 0;
445
                AttributeCollection attCol = pBlkRef.AttributeCollection;
446
                foreach (ObjectId id in attCol)
447
                {
448
                    try
449
                    {
450
                        using (AttributeReference pAttr = (AttributeReference)id.Open(OpenMode.ForRead))
451
                            dumpAttributeData(indent, pAttr, i++, BlockReferenceNode);
452
                    }
453
                    catch (System.Exception)
454
                    {
455

    
456
                    }
457
                }
458

    
459
                node.AppendChild(BlockReferenceNode);
460

    
461
                return BlockReferenceNode;
462
            }
463

    
464
            return null;
465
        }
466
        /************************************************************************/
467
        /* Dump data common to all OdDbCurves                                   */
468
        /************************************************************************/
469
        static void dumpCurveData(Entity pEnt, int indent, XmlNode node)
470
        {
471
            if (node != null)
472
            {
473
                Curve pEntity = (Curve)pEnt;
474
                try
475
                {
476
                    writeLine(indent, "Start Point", pEntity.StartPoint);
477
                    writeLine(indent, "End Point", pEntity.EndPoint);
478
                }
479
                catch (System.Exception)
480
                {
481
                }
482
                writeLine(indent, "Closed", pEntity.Closed);
483
                writeLine(indent, "Periodic", pEntity.IsPeriodic);
484

    
485
                try
486
                {
487
                    writeLine(indent, "Area", pEntity.Area);
488
                }
489
                catch (System.Exception)
490
                {
491
                }
492
                dumpEntityData(pEntity, indent, node);
493
            }
494
        }
495

    
496
        /************************************************************************/
497
        /* Dump Dimension data                                                  */
498
        /************************************************************************/
499
        static XmlNode dumpDimData(Dimension pDim, int indent, XmlNode node)
500
        {
501
            if (node != null)
502
            {
503
                XmlElement DimDataNode = Program.xml.CreateElement("DimData");
504

    
505
                XmlAttribute CurrentMeasurementAttr = Program.xml.CreateAttribute("CurrentMeasurement");
506
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
507
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
508

    
509
                XmlAttribute DimensionTextAttr = Program.xml.CreateAttribute("DimensionText");
510
                DimensionTextAttr.Value = pDim.DimensionText.ToString();
511
                DimDataNode.Attributes.SetNamedItem(DimensionTextAttr);
512

    
513
                if (pDim.CurrentMeasurement >= 0.0)
514
                {
515
                    XmlAttribute FormattedMeasurementAttr = Program.xml.CreateAttribute("FormattedMeasurement");
516
                    FormattedMeasurementAttr.Value = pDim.FormatMeasurement(pDim.CurrentMeasurement, pDim.DimensionText);
517
                    DimDataNode.Attributes.SetNamedItem(FormattedMeasurementAttr);
518
                }
519
                if (pDim.DimBlockId.IsNull)
520
                {
521
                    writeLine(indent, "Dimension Block NULL");
522
                }
523
                else
524
                {
525
                    using (BlockTableRecord btr = (BlockTableRecord)pDim.DimBlockId.Open(OpenMode.ForRead))
526
                    {
527
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
528
                        NameAttr.Value = btr.Name;
529
                        DimDataNode.Attributes.SetNamedItem(NameAttr);
530
                    }
531
                }
532

    
533
                XmlAttribute DimBlockPositionAttr = Program.xml.CreateAttribute("DimBlockPosition");
534
                DimBlockPositionAttr.Value = pDim.DimBlockPosition.ToString();
535
                DimDataNode.Attributes.SetNamedItem(DimBlockPositionAttr);
536

    
537
                XmlAttribute TextPositionAttr = Program.xml.CreateAttribute("TextPosition");
538
                TextPositionAttr.Value = pDim.TextPosition.ToString();
539
                DimDataNode.Attributes.SetNamedItem(TextPositionAttr);
540

    
541
                XmlAttribute TextRotationAttr = Program.xml.CreateAttribute("TextRotation");
542
                TextRotationAttr.Value = pDim.TextRotation.ToString();
543
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
544

    
545
                XmlAttribute DimensionStyleNameAttr = Program.xml.CreateAttribute("DimensionStyleName");
546
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
547
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
548

    
549
                XmlAttribute DimtfillclrAttr = Program.xml.CreateAttribute("Dimtfillclr");
550
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
551
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
552

    
553
                XmlAttribute DimtfillAttr = Program.xml.CreateAttribute("Dimtfill");
554
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
555
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
556

    
557
                XmlAttribute Dimltex1Attr = Program.xml.CreateAttribute("Dimltex1");
558
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
559
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
560

    
561
                XmlAttribute Dimltex2Attr = Program.xml.CreateAttribute("Dimltex2");
562
                Dimltex2Attr.Value = pDim.Dimltex2.ToString();
563
                DimDataNode.Attributes.SetNamedItem(Dimltex2Attr);
564

    
565
                XmlAttribute DimltypeAttr = Program.xml.CreateAttribute("Dimltype");
566
                DimltypeAttr.Value = pDim.Dimltype.ToString();
567
                DimDataNode.Attributes.SetNamedItem(DimltypeAttr);
568

    
569
                XmlAttribute HorizontalRotationAttr = Program.xml.CreateAttribute("HorizontalRotation");
570
                HorizontalRotationAttr.Value = pDim.HorizontalRotation.ToString();
571
                DimDataNode.Attributes.SetNamedItem(HorizontalRotationAttr);
572

    
573
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
574
                ElevationAttr.Value = pDim.Elevation.ToString();
575
                DimDataNode.Attributes.SetNamedItem(ElevationAttr);
576

    
577
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
578
                NormalAttr.Value = pDim.Normal.ToString();
579
                DimDataNode.Attributes.SetNamedItem(NormalAttr);
580

    
581
                dumpEntityData(pDim, indent, node);
582

    
583
                return DimDataNode;
584
            }
585

    
586
            return null;
587
        }
588

    
589
        /************************************************************************/
590
        /* 2 Line Angular Dimension Dumper                                      */
591
        /************************************************************************/
592
        static XmlNode dump(LineAngularDimension2 pDim, int indent, XmlNode node)
593
        {
594
            if (node != null)
595
            {
596
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
597

    
598
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
599
                HandleAttr.Value = pDim.Handle.ToString();
600
                DimNode.Attributes.SetNamedItem(HandleAttr);
601

    
602
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
603
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
604
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
605

    
606
                XmlAttribute XLine1StartAttr = Program.xml.CreateAttribute("XLine1Start");
607
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
608
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
609

    
610
                XmlAttribute XLine1EndAttr = Program.xml.CreateAttribute("XLine1End");
611
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
612
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
613

    
614
                XmlAttribute XLine2StartAttr = Program.xml.CreateAttribute("XLine2Start");
615
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
616
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
617

    
618
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
619
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
620
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
621

    
622
                dumpDimData(pDim, indent, DimNode);
623

    
624
                return DimNode;
625
            }
626

    
627
            return null;
628
        }
629

    
630
        /************************************************************************/
631
        /* Dump 2D Vertex data                                                  */
632
        /************************************************************************/
633
        static XmlNode dump2dVertex(int indent, Vertex2d pVertex, int i, XmlNode node)
634
        {
635
            if (node != null)
636
            {
637
                XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
638

    
639
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
640
                HandleAttr.Value = pVertex.Handle.ToString();
641
                VertexNode.Attributes.SetNamedItem(HandleAttr);
642

    
643
                XmlAttribute VertexTypeAttr = Program.xml.CreateAttribute("VertexType");
644
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
645
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
646

    
647
                XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
648
                PositionAttr.Value = pVertex.Position.ToString();
649
                VertexNode.Attributes.SetNamedItem(PositionAttr);
650

    
651
                XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
652
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
653
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
654

    
655
                XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
656
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
657
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
658

    
659
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
660
                BulgeAttr.Value = pVertex.Bulge.ToString();
661
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
662

    
663
                if (pVertex.Bulge != 0)
664
                {
665
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
666
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
667
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
668
                }
669

    
670
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
671
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
672
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
673
                if (pVertex.TangentUsed)
674
                {
675
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
676
                    TangentAttr.Value = pVertex.Tangent.ToString();
677
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
678
                }
679

    
680
                node.AppendChild(VertexNode);
681

    
682
                return VertexNode;
683
            }
684

    
685
            return null;
686
        }
687

    
688
        /************************************************************************/
689
        /* 2D Polyline Dumper                                                   */
690
        /************************************************************************/
691
        static XmlNode dump(Polyline2d pPolyline, int indent, XmlNode node)
692
        {
693
            /********************************************************************/
694
            /* Dump the vertices                                                */
695
            /********************************************************************/
696
            List<Vertex2d> Vertices = new List<Vertex2d>();
697
            int i = 0;
698
            foreach (ObjectId obj in pPolyline)
699
            {
700
                using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
701
                {
702
                    if (dbObj is Vertex2d)
703
                    {
704
                        Vertices.Add((Vertex2d)dbObj);
705
                        /// dump2dVertex(indent, (Vertex2d)dbObj, i++);
706
                    }
707
                }
708
            }
709

    
710
            if (node != null)
711
            {
712
                XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
713

    
714
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
715
                HandleAttr.Value = pPolyline.Handle.ToString();
716
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
717

    
718
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
719
                CountAttr.Value = Vertices.Count.ToString();
720
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
721

    
722
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
723
                ElevationAttr.Value = pPolyline.Elevation.ToString();
724
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
725

    
726
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
727
                NormalAttr.Value = pPolyline.Normal.ToString();
728
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
729

    
730
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
731
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
732
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
733

    
734
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
735
                ClosedAttr.Value = pPolyline.Closed.ToString();
736
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
737

    
738
                foreach (var vt in Vertices)
739
                {
740
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
741

    
742
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
743
                    XAttr.Value = vt.Position.X.ToString();
744
                    VertexNode.Attributes.SetNamedItem(XAttr);
745

    
746
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
747
                    YAttr.Value = vt.Position.Y.ToString();
748
                    VertexNode.Attributes.SetNamedItem(YAttr);
749

    
750
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
751
                    ZAttr.Value = vt.Position.Z.ToString();
752
                    VertexNode.Attributes.SetNamedItem(ZAttr);
753

    
754
                    Polyline2dNode.AppendChild(VertexNode);
755
                }
756

    
757
                dumpCurveData(pPolyline, indent, node);
758

    
759
                node.AppendChild(Polyline2dNode);
760

    
761
                return Polyline2dNode;
762
            }
763

    
764
            return null;
765
        }
766

    
767

    
768
        /************************************************************************/
769
        /* Dump 3D Polyline Vertex data                                         */
770
        /************************************************************************/
771
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
772
        {
773
            if (node != null)
774
            {
775
                XmlNode VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
776

    
777
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
778
                HandleAttr.Value = pVertex.Handle.ToString();
779
                VertexNode.Attributes.SetNamedItem(HandleAttr);
780

    
781
                XmlAttribute VertexxTypeAttr = Program.xml.CreateAttribute("VertexType");
782
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
783
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
784

    
785
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
786
                XAttr.Value = pVertex.Position.X.ToString();
787
                VertexNode.Attributes.SetNamedItem(XAttr);
788

    
789
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
790
                YAttr.Value = pVertex.Position.Y.ToString();
791
                VertexNode.Attributes.SetNamedItem(YAttr);
792

    
793
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
794
                ZAttr.Value = pVertex.Position.Z.ToString();
795
                VertexNode.Attributes.SetNamedItem(ZAttr);
796

    
797
                node.AppendChild(VertexNode);
798

    
799
                return VertexNode;
800
            }
801

    
802
            return null;
803
        }
804

    
805
        /************************************************************************/
806
        /* 3D Polyline Dumper                                                   */
807
        /************************************************************************/
808
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
809
        {
810
            if (node != null)
811
            {
812
                XmlNode pPolylineNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
813

    
814
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
815
                HandleAttr.Value = pPolyline.Handle.ToString();
816
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
817

    
818
                /********************************************************************/
819
                /* Dump the vertices                                                */
820
                /********************************************************************/
821
                int i = 0;
822
                foreach (ObjectId obj in pPolyline)
823
                {
824
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
825
                    {
826
                        if (dbObj is PolylineVertex3d)
827
                        {
828
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
829
                        }
830
                    }
831
                }
832
                dumpCurveData(pPolyline, indent, pPolylineNode);
833

    
834
                node.AppendChild(pPolylineNode);
835

    
836
                return pPolylineNode;
837
            }
838

    
839
            return null;
840
        }
841

    
842

    
843
        /************************************************************************/
844
        /* 3DSolid Dumper                                                       */
845
        /************************************************************************/
846
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
847
        {
848
            if (node != null)
849
            {
850
                XmlNode SolidNode = Program.xml.CreateElement(pSolid.GetRXClass().Name);
851

    
852
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
853
                HandleAttr.Value = pSolid.Handle.ToString();
854
                SolidNode.Attributes.SetNamedItem(HandleAttr);
855

    
856
                dumpEntityData(pSolid, indent, node);
857

    
858
                node.AppendChild(SolidNode);
859

    
860
                return SolidNode;
861
            }
862

    
863
            return null;
864
        }
865

    
866

    
867
        /************************************************************************/
868
        /* 3 Point Angular Dimension Dumper                                     */
869
        /************************************************************************/
870
        XmlNode dump(Point3AngularDimension pDim, int indent, XmlNode node)
871
        {
872
            if (node != null)
873
            {
874
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
875

    
876
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
877
                HandleAttr.Value = pDim.Handle.ToString();
878
                DimNode.Attributes.SetNamedItem(HandleAttr);
879

    
880
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
881
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
882
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
883

    
884
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
885
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
886
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
887

    
888
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
889
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
890
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
891

    
892
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
893
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
894
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
895

    
896
                dumpDimData(pDim, indent, DimNode);
897

    
898
                return DimNode;
899
            }
900

    
901
            return null;
902
        }
903

    
904
        /************************************************************************/
905
        /* Aligned Dimension Dumper                                             */
906
        /************************************************************************/
907
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
908
        {
909
            if (node != null)
910
            {
911
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
912

    
913
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
914
                HandleAttr.Value = pDim.Handle.ToString();
915
                DimNode.Attributes.SetNamedItem(HandleAttr);
916

    
917
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
918
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
919
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
920

    
921
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
922
                ObliqueAttr.Value = pDim.Oblique.ToString();
923
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
924

    
925
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
926
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
927
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
928

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

    
933
                dumpDimData(pDim, indent, DimNode);
934

    
935
                return DimNode;
936
            }
937

    
938
            return null;
939
        }
940

    
941
        /************************************************************************/
942
        /* Arc Dumper                                                           */
943
        /************************************************************************/
944
        XmlNode dump(Arc pArc, int indent, XmlNode node)
945
        {
946
            if (node != null)
947
            {
948
                XmlElement ArcNode = Program.xml.CreateElement(pArc.GetRXClass().Name);
949

    
950
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
951
                XAttr.Value = pArc.Center.X.ToString();
952
                ArcNode.Attributes.SetNamedItem(XAttr);
953

    
954
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
955
                YAttr.Value = pArc.Center.Y.ToString();
956
                ArcNode.Attributes.SetNamedItem(YAttr);
957

    
958
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
959
                ZAttr.Value = pArc.Center.Z.ToString();
960
                ArcNode.Attributes.SetNamedItem(ZAttr);
961

    
962
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
963
                RadiusAttr.Value = pArc.Radius.ToString();
964
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
965

    
966
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
967
                StartAngleAttr.Value = pArc.StartAngle.ToString();
968
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
969

    
970
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
971
                EndAngleAttr.Value = pArc.EndAngle.ToString();
972
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
973

    
974
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
975
                NormalAttr.Value = pArc.Normal.ToString();
976
                ArcNode.Attributes.SetNamedItem(NormalAttr);
977

    
978
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
979
                ThicknessAttr.Value = pArc.Normal.ToString();
980
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
981

    
982
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
983
                dumpCurveData(pArc, indent, ArcNode);
984

    
985
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
986
                {
987
                    XAttr = Program.xml.CreateAttribute("X");
988
                    XAttr.Value = pArc.StartPoint.X.ToString();
989
                    StartPointNode.Attributes.SetNamedItem(XAttr);
990

    
991
                    YAttr = Program.xml.CreateAttribute("Y");
992
                    YAttr.Value = pArc.StartPoint.Y.ToString();
993
                    StartPointNode.Attributes.SetNamedItem(YAttr);
994

    
995
                    ZAttr = Program.xml.CreateAttribute("Z");
996
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
997
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
998
                }
999
                ArcNode.AppendChild(StartPointNode);
1000

    
1001
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1002
                {
1003
                    XAttr = Program.xml.CreateAttribute("X");
1004
                    XAttr.Value = pArc.EndPoint.X.ToString();
1005
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1006

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

    
1011
                    ZAttr = Program.xml.CreateAttribute("Z");
1012
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1013
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1014
                }
1015
                ArcNode.AppendChild(EndPointNode);
1016

    
1017
                node.AppendChild(ArcNode);
1018

    
1019
                return ArcNode;
1020
            }
1021

    
1022
            return null;
1023
        }
1024

    
1025
        /************************************************************************/
1026
        /* Arc Dimension Dumper                                                 */
1027
        /************************************************************************/
1028
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
1029
        {
1030
            if (node != null)
1031
            {
1032
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1033

    
1034
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1035
                HandleAttr.Value = pDim.Handle.ToString();
1036
                DimNode.Attributes.SetNamedItem(HandleAttr);
1037

    
1038
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
1039
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
1040
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
1041

    
1042
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
1043
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
1044
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
1045

    
1046
                XmlAttribute ArcSymbolTypeAttr = Program.xml.CreateAttribute("ArcSymbolType");
1047
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1048
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1049

    
1050
                XmlAttribute IsPartialAttr = Program.xml.CreateAttribute("IsPartial");
1051
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1052
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1053

    
1054
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1055
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1056
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1057

    
1058
                if (pDim.HasLeader)
1059
                {
1060
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1061
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1062
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1063

    
1064
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1065
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1066
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1067
                }
1068

    
1069
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1070
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1071
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1072

    
1073
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1074
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1075
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1076

    
1077
                dumpDimData(pDim, indent, DimNode);
1078

    
1079
                return DimNode;
1080
            }
1081

    
1082
            return null;
1083
        }
1084

    
1085

    
1086
        /************************************************************************/
1087
        /* Block Reference Dumper                                                */
1088
        /************************************************************************/
1089
        void dump(BlockReference pBlkRef, int indent, XmlNode node)
1090
        {
1091
            using (BlockTableRecord pRecord = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead))
1092
            {
1093
                XmlNode BlockRefNode = dumpBlockRefData(pBlkRef, indent, node);
1094
                if (BlockRefNode != null)
1095
                {
1096
                    XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
1097
                    NameAttr.Value = pRecord.Name;
1098
                    BlockRefNode.Attributes.SetNamedItem(NameAttr);
1099
                }
1100
            }
1101
        }
1102

    
1103
        /************************************************************************/
1104
        /* Body Dumper                                                          */
1105
        /************************************************************************/
1106
        XmlNode dump(Body pBody, int indent, XmlNode node)
1107
        {
1108
            if (node != null)
1109
            {
1110
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1111

    
1112
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1113
                HandleAttr.Value = pBody.Handle.ToString();
1114
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1115

    
1116
                dumpEntityData(pBody, indent, BodyNode);
1117

    
1118
                return BodyNode;
1119
            }
1120

    
1121
            return null;
1122
        }
1123

    
1124

    
1125
        /************************************************************************/
1126
        /* Circle Dumper                                                        */
1127
        /************************************************************************/
1128
        XmlNode dump(Circle pCircle, int indent, XmlNode node)
1129
        {
1130
            if (node != null)
1131
            {
1132
                XmlElement CircleNode = Program.xml.CreateElement(pCircle.GetRXClass().Name);
1133

    
1134
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1135
                XAttr.Value = pCircle.Center.X.ToString();
1136
                CircleNode.Attributes.SetNamedItem(XAttr);
1137

    
1138
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1139
                YAttr.Value = pCircle.Center.Y.ToString();
1140
                CircleNode.Attributes.SetNamedItem(YAttr);
1141

    
1142
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1143
                RadiusAttr.Value = pCircle.Radius.ToString();
1144
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1145

    
1146
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1147
                NormalAttr.Value = pCircle.Normal.ToString();
1148
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1149

    
1150
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1151
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1152
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1153

    
1154
                dumpCurveData(pCircle, indent, CircleNode);
1155

    
1156
                node.AppendChild(CircleNode);
1157

    
1158
                return CircleNode;
1159
            }
1160

    
1161
            return null;
1162
        }
1163

    
1164
        /************************************************************************/
1165
        /* Diametric Dimension Dumper                                           */
1166
        /************************************************************************/
1167
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1168
        {
1169
            if (node != null)
1170
            {
1171
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1172

    
1173
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1174
                HandleAttr.Value = pDim.Handle.ToString();
1175
                DimNode.Attributes.SetNamedItem(HandleAttr);
1176

    
1177
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
1178
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1179
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1180

    
1181
                XmlAttribute FarChordPointAttr = Program.xml.CreateAttribute("FarChordPoint");
1182
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1183
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1184

    
1185
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1186
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1187
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1188

    
1189
                dumpDimData(pDim, indent, DimNode);
1190

    
1191
                return DimNode;
1192
            }
1193

    
1194
            return null;
1195
        }
1196

    
1197
        /************************************************************************/
1198
        /* Ellipse Dumper                                                       */
1199
        /************************************************************************/
1200
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1201
        {
1202
            if (node != null)
1203
            {
1204
                XmlElement EllipseNode = Program.xml.CreateElement(pEllipse.GetRXClass().Name);
1205

    
1206
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1207

    
1208
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1209
                XAttr.Value = pEllipse.Center.X.ToString();
1210
                EllipseNode.Attributes.SetNamedItem(XAttr);
1211

    
1212
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1213
                YAttr.Value = pEllipse.Center.Y.ToString();
1214
                EllipseNode.Attributes.SetNamedItem(YAttr);
1215

    
1216
                XmlAttribute MajorAxisAttr = Program.xml.CreateAttribute("MajorAxis");
1217
                MajorAxisAttr.Value = pEllipse.MajorAxis.ToString();
1218
                EllipseNode.Attributes.SetNamedItem(MajorAxisAttr);
1219

    
1220
                XmlAttribute MinorAxisAttr = Program.xml.CreateAttribute("MinorAxis");
1221
                MinorAxisAttr.Value = pEllipse.MinorAxis.ToString();
1222
                EllipseNode.Attributes.SetNamedItem(MinorAxisAttr);
1223

    
1224
                XmlAttribute MajorRadiusAttr = Program.xml.CreateAttribute("MajorRadius");
1225
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1226
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1227

    
1228
                XmlAttribute MinorRadiusAttr = Program.xml.CreateAttribute("MinorRadius");
1229
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1230
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1231

    
1232
                XmlAttribute RadiusRatioAttr = Program.xml.CreateAttribute("RadiusRatio");
1233
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1234
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1235

    
1236
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1237
                StartAngleAttr.Value = pEllipse.StartAngle.ToString();
1238
                EllipseNode.Attributes.SetNamedItem(StartAngleAttr);
1239

    
1240
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1241
                EndAngleAttr.Value = pEllipse.EndAngle.ToString();
1242
                EllipseNode.Attributes.SetNamedItem(EndAngleAttr);
1243

    
1244
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1245
                NormalAttr.Value = pEllipse.Normal.ToString();
1246
                EllipseNode.Attributes.SetNamedItem(NormalAttr);
1247

    
1248
                dumpCurveData(pEllipse, indent, EllipseNode);
1249

    
1250
                node.AppendChild(EllipseNode);
1251
            }
1252
        }
1253

    
1254
        /************************************************************************/
1255
        /* Face Dumper                                                       */
1256
        /************************************************************************/
1257
        XmlNode dump(Face pFace, int indent, XmlNode node)
1258
        {
1259
            if (node != null)
1260
            {
1261
                XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1262

    
1263
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1264
                HandleAttr.Value = pFace.Handle.ToString();
1265
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1266

    
1267
                for (short i = 0; i < 4; i++)
1268
                {
1269
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1270

    
1271
                    Point3d pt = pFace.GetVertexAt(i);
1272
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1273
                    XAttr.Value = pt.X.ToString();
1274
                    VertexNode.Attributes.SetNamedItem(XAttr);
1275

    
1276
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1277
                    YAttr.Value = pt.Y.ToString();
1278
                    VertexNode.Attributes.SetNamedItem(YAttr);
1279

    
1280
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1281
                    ZAttr.Value = pt.Z.ToString();
1282
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1283

    
1284
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1285
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1286
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1287

    
1288
                    FaceNode.AppendChild(VertexNode);
1289
                }
1290
                dumpEntityData(pFace, indent, FaceNode);
1291

    
1292
                node.AppendChild(FaceNode);
1293

    
1294
                return FaceNode;
1295
            }
1296

    
1297
            return null;
1298
        }
1299

    
1300
        /************************************************************************/
1301
        /* FCF Dumper                                                           */
1302
        /************************************************************************/
1303
        void dump(FeatureControlFrame pFcf, int indent)
1304
        {
1305
            writeLine(indent++, pFcf.GetRXClass().Name, pFcf.Handle);
1306
            writeLine(indent, "Location", pFcf.Location);
1307
            writeLine(indent, "Text", pFcf.Text);
1308
            writeLine(indent, "Dimension Style", pFcf.DimensionStyleName);
1309
            writeLine(indent, "Dimension Gap", pFcf.Dimgap);
1310
            writeLine(indent, "Dimension Scale", pFcf.Dimscale);
1311
            writeLine(indent, "Text Height", pFcf.Dimtxt);
1312
            writeLine(indent, "Frame Color", pFcf.Dimclrd);
1313
            writeLine(indent, "Text Style", pFcf.TextStyleName);
1314
            writeLine(indent, "Text Color", pFcf.Dimclrd);
1315
            writeLine(indent, "X-Direction", pFcf.Direction);
1316
            writeLine(indent, "Normal", pFcf.Normal);
1317
            dumpEntityData(pFcf, indent, Program.xml.DocumentElement);
1318
        }
1319

    
1320
        /************************************************************************/
1321
        /* Hatch Dumper                                                         */
1322
        /************************************************************************/
1323
        /***********************************************************************/
1324
        /* Dump Polyline Loop                                                  */
1325
        /***********************************************************************/
1326
        static void dumpPolylineType(int loopIndex, Hatch pHatch, int indent)
1327
        {
1328
            HatchLoop hl = pHatch.GetLoopAt(loopIndex);
1329
            for (int i = 0; i < hl.Polyline.Count; i++)
1330
            {
1331
                BulgeVertex bv = hl.Polyline[i];
1332
                writeLine(indent, "Vertex " + i.ToString(), bv.Vertex.ToString());
1333
                writeLine(indent + 1, "Bulge " + i.ToString(), bv.Bulge);
1334
                writeLine(indent + 1, "Bulge angle " + i.ToString(), toDegreeString(4 * Math.Atan(bv.Bulge)));
1335
            }
1336
        }
1337

    
1338
        /**********************************************************************/
1339
        /* Dump Circular Arc Edge                                             */
1340
        /**********************************************************************/
1341
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1342
        {
1343
            writeLine(indent, "Center", pCircArc.Center);
1344
            writeLine(indent, "Radius", pCircArc.Radius);
1345
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1346
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1347
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1348
        }
1349

    
1350
        /**********************************************************************/
1351
        /* Dump Elliptical Arc Edge                                           */
1352
        /**********************************************************************/
1353
        static void dumpEllipticalArcEdge(int indent, EllipticalArc2d pEllipArc)
1354
        {
1355
            writeLine(indent, "Center", pEllipArc.Center);
1356
            writeLine(indent, "Major Radius", pEllipArc.MajorRadius);
1357
            writeLine(indent, "Minor Radius", pEllipArc.MinorRadius);
1358
            writeLine(indent, "Major Axis", pEllipArc.MajorAxis);
1359
            writeLine(indent, "Minor Axis", pEllipArc.MinorAxis);
1360
            writeLine(indent, "Start Angle", toDegreeString(pEllipArc.StartAngle));
1361
            writeLine(indent, "End Angle", toDegreeString(pEllipArc.EndAngle));
1362
            writeLine(indent, "Clockwise", pEllipArc.IsClockWise);
1363
        }
1364

    
1365
        /**********************************************************************/
1366
        /* Dump NurbCurve Edge                                           */
1367
        /**********************************************************************/
1368
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1369
        {
1370
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1371
            writeLine(indent, "Degree", d.Degree);
1372
            writeLine(indent, "Rational", d.Rational);
1373
            writeLine(indent, "Periodic", d.Periodic);
1374

    
1375
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1376
            for (int i = 0; i < d.ControlPoints.Count; i++)
1377
            {
1378
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1379
            }
1380
            writeLine(indent, "Number of Knots", d.Knots.Count);
1381
            for (int i = 0; i < d.Knots.Count; i++)
1382
            {
1383
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1384
            }
1385

    
1386
            if (d.Rational)
1387
            {
1388
                writeLine(indent, "Number of Weights", d.Weights.Count);
1389
                for (int i = 0; i < d.Weights.Count; i++)
1390
                {
1391
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1392
                }
1393
            }
1394
        }
1395

    
1396
        /***********************************************************************/
1397
        /* Dump Edge Loop                                                      */
1398
        /***********************************************************************/
1399
        static void dumpEdgesType(int loopIndex, Hatch pHatch, int indent)
1400
        {
1401
            Curve2dCollection edges = pHatch.GetLoopAt(loopIndex).Curves;
1402
            for (int i = 0; i < (int)edges.Count; i++)
1403
            {
1404
                using (Curve2d pEdge = edges[i])
1405
                {
1406
                    writeLine(indent, string.Format("Edge {0}", i), pEdge.GetType().Name);
1407
                    switch (pEdge.GetType().Name)
1408
                    {
1409
                        case "LineSegment2d":
1410
                            break;
1411
                        case "CircularArc2d":
1412
                            dumpCircularArcEdge(indent + 1, (CircularArc2d)pEdge);
1413
                            break;
1414
                        case "EllipticalArc2d":
1415
                            dumpEllipticalArcEdge(indent + 1, (EllipticalArc2d)pEdge);
1416
                            break;
1417
                        case "NurbCurve2d":
1418
                            dumpNurbCurveEdge(indent + 1, (NurbCurve2d)pEdge);
1419
                            break;
1420
                    }
1421

    
1422
                    /******************************************************************/
1423
                    /* Common Edge Properties                                         */
1424
                    /******************************************************************/
1425
                    Interval interval = pEdge.GetInterval();
1426
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1427
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1428
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1429
                }
1430
            }
1431
        }
1432

    
1433
        /************************************************************************/
1434
        /* Convert the specified value to a LoopType string                     */
1435
        /************************************************************************/
1436
        string toLooptypeString(HatchLoopTypes loopType)
1437
        {
1438
            string retVal = "";
1439
            if ((loopType & HatchLoopTypes.External) != 0)
1440
                retVal = retVal + " | kExternal";
1441

    
1442
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1443
                retVal = retVal + " | kPolyline";
1444

    
1445
            if ((loopType & HatchLoopTypes.Derived) != 0)
1446
                retVal = retVal + " | kDerived";
1447

    
1448
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1449
                retVal = retVal + " | kTextbox";
1450

    
1451
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1452
                retVal = retVal + " | kOutermost";
1453

    
1454
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1455
                retVal = retVal + " | kNotClosed";
1456

    
1457
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1458
                retVal = retVal + " | kSelfIntersecting";
1459

    
1460
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1461
                retVal = retVal + " | kTextIsland";
1462

    
1463
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1464
                retVal = retVal + " | kDuplicate";
1465

    
1466
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1467
        }
1468

    
1469
        void dump(Hatch pHatch, int indent)
1470
        {
1471
            writeLine(indent++, pHatch.GetRXClass().Name, pHatch.Handle);
1472
            writeLine(indent, "Hatch Style", pHatch.HatchStyle);
1473
            writeLine(indent, "Hatch Object Type", pHatch.HatchObjectType);
1474
            writeLine(indent, "Is Hatch", pHatch.IsHatch);
1475
            writeLine(indent, "Is Gradient", !pHatch.IsGradient);
1476
            if (pHatch.IsHatch)
1477
            {
1478
                /******************************************************************/
1479
                /* Dump Hatch Parameters                                          */
1480
                /******************************************************************/
1481
                writeLine(indent, "Pattern Type", pHatch.PatternType);
1482
                switch (pHatch.PatternType)
1483
                {
1484
                    case HatchPatternType.PreDefined:
1485
                    case HatchPatternType.CustomDefined:
1486
                        writeLine(indent, "Pattern Name", pHatch.PatternName);
1487
                        writeLine(indent, "Solid Fill", pHatch.IsSolidFill);
1488
                        if (!pHatch.IsSolidFill)
1489
                        {
1490
                            writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1491
                            writeLine(indent, "Pattern Scale", pHatch.PatternScale);
1492
                        }
1493
                        break;
1494
                    case HatchPatternType.UserDefined:
1495
                        writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1496
                        writeLine(indent, "Pattern Double", pHatch.PatternDouble);
1497
                        writeLine(indent, "Pattern Space", pHatch.PatternSpace);
1498
                        break;
1499
                }
1500
                DBObjectCollection entitySet = new DBObjectCollection();
1501
                Handle hhh = pHatch.Handle;
1502
                if (hhh.Value == 1692) //69C)
1503
                {
1504
                    pHatch.Explode(entitySet);
1505
                    return;
1506
                }
1507
                if (hhh.Value == 1693) //69D)
1508
                {
1509
                    try
1510
                    {
1511
                        pHatch.Explode(entitySet);
1512
                    }
1513
                    catch (System.Exception e)
1514
                    {
1515
                        if (e.Message == "eCannotExplodeEntity")
1516
                        {
1517
                            writeLine(indent, "Hatch " + e.Message + ": ", pHatch.Handle);
1518
                            return;
1519
                        }
1520
                    }
1521
                }
1522
            }
1523
            if (pHatch.IsGradient)
1524
            {
1525
                /******************************************************************/
1526
                /* Dump Gradient Parameters                                       */
1527
                /******************************************************************/
1528
                writeLine(indent, "Gradient Type", pHatch.GradientType);
1529
                writeLine(indent, "Gradient Name", pHatch.GradientName);
1530
                writeLine(indent, "Gradient Angle", toDegreeString(pHatch.GradientAngle));
1531
                writeLine(indent, "Gradient Shift", pHatch.GradientShift);
1532
                writeLine(indent, "Gradient One-Color Mode", pHatch.GradientOneColorMode);
1533
                if (pHatch.GradientOneColorMode)
1534
                {
1535
                    writeLine(indent, "ShadeTintValue", pHatch.ShadeTintValue);
1536
                }
1537
                GradientColor[] colors = pHatch.GetGradientColors();
1538
                for (int i = 0; i < colors.Length; i++)
1539
                {
1540
                    writeLine(indent, string.Format("Color         {0}", i), colors[i].get_Color());
1541
                    writeLine(indent, string.Format("Interpolation {0}", i), colors[i].get_Value());
1542
                }
1543
            }
1544

    
1545
            /********************************************************************/
1546
            /* Dump Associated Objects                                          */
1547
            /********************************************************************/
1548
            writeLine(indent, "Associated objects", pHatch.Associative);
1549
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1550
            {
1551
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1552
            }
1553

    
1554
            /********************************************************************/
1555
            /* Dump Loops                                                       */
1556
            /********************************************************************/
1557
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1558
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1559
            {
1560
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1561

    
1562
                /******************************************************************/
1563
                /* Dump Loop                                                      */
1564
                /******************************************************************/
1565
                if ((pHatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) != 0)
1566
                {
1567
                    dumpPolylineType(i, pHatch, indent + 2);
1568
                }
1569
                else
1570
                {
1571
                    dumpEdgesType(i, pHatch, indent + 2);
1572
                }
1573
                /******************************************************************/
1574
                /* Dump Associated Objects                                        */
1575
                /******************************************************************/
1576
                if (pHatch.Associative)
1577
                {
1578
                    writeLine(indent + 2, "Associated objects");
1579
                    foreach (ObjectId id in pHatch.GetAssociatedObjectIdsAt(i))
1580
                    {
1581
                        writeLine(indent + 3, id.ObjectClass.Name, id.Handle);
1582
                    }
1583
                }
1584
            }
1585

    
1586
            writeLine(indent, "Elevation", pHatch.Elevation);
1587
            writeLine(indent, "Normal", pHatch.Normal);
1588
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1589
        }
1590

    
1591
        /************************************************************************/
1592
        /* Leader Dumper                                                          */
1593
        /************************************************************************/
1594
        void dump(Leader pLeader, int indent)
1595
        {
1596
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1597
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1598

    
1599
            writeLine(indent, "Annotation");
1600
            if (!pLeader.Annotation.IsNull)
1601
            {
1602
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1603
            }
1604
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1605
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1606
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1607
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1608
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1609
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1610
            writeLine(indent, "Splined", pLeader.IsSplined);
1611

    
1612
            for (int i = 0; i < pLeader.NumVertices; i++)
1613
            {
1614
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1615
            }
1616
            writeLine(indent, "Normal", pLeader.Normal);
1617
            dumpCurveData(pLeader, indent, Program.xml.DocumentElement);
1618
        }
1619

    
1620
        /************************************************************************/
1621
        /* Line Dumper                                                          */
1622
        /************************************************************************/
1623
        void dump(Line pLine, int indent, XmlNode node)
1624
        {
1625
            if (node != null && pLine != null && pLine.Length != 0)
1626
            {
1627
                XmlNode LineNode = Program.xml.CreateElement(pLine.GetRXClass().Name);
1628
                XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1629
                LengthAttr.Value = pLine.Length.ToString();
1630
                LineNode.Attributes.SetNamedItem(LengthAttr);
1631

    
1632
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1633
                HandleAttr.Value = pLine.Handle.ToString();
1634
                LineNode.Attributes.SetNamedItem(HandleAttr);
1635

    
1636
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1637
                {
1638
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1639
                    XAttr.Value = pLine.StartPoint.X.ToString();
1640
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1641

    
1642
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1643
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1644
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1645

    
1646
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1647
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1648
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1649
                }
1650
                LineNode.AppendChild(StartPointNode);
1651

    
1652
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1653
                {
1654
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1655
                    XAttr.Value = pLine.EndPoint.X.ToString();
1656
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1657

    
1658
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1659
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1660
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1661

    
1662
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1663
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1664
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1665
                }
1666
                LineNode.AppendChild(EndPointNode);
1667

    
1668
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1669
                NormalAttr.Value = pLine.Normal.ToString();
1670
                LineNode.Attributes.SetNamedItem(NormalAttr);
1671

    
1672
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1673
                ThicknessAttr.Value = pLine.Thickness.ToString();
1674
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1675

    
1676
                dumpEntityData(pLine, indent, LineNode);
1677

    
1678
                node.AppendChild(LineNode);
1679
            }
1680
            else
1681
            {
1682
                int d = 0;
1683
            }
1684
        }
1685

    
1686
        /************************************************************************/
1687
        /* MInsertBlock Dumper                                                  */
1688
        /************************************************************************/
1689
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1690
        {
1691
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1692

    
1693
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1694
            {
1695
                writeLine(indent, "Name", pRecord.Name);
1696
                writeLine(indent, "Rows", pMInsert.Rows);
1697
                writeLine(indent, "Columns", pMInsert.Columns);
1698
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1699
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1700
                dumpBlockRefData(pMInsert, indent, node);
1701
            }
1702
        }
1703

    
1704
        /************************************************************************/
1705
        /* Mline Dumper                                                         */
1706
        /************************************************************************/
1707
        void dump(Mline pMline, int indent)
1708
        {
1709
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1710
            writeLine(indent, "Style", pMline.Style);
1711
            writeLine(indent, "Closed", pMline.IsClosed);
1712
            writeLine(indent, "Scale", pMline.Scale);
1713
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1714
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1715
            writeLine(indent, "Normal", pMline.Normal);
1716

    
1717
            /********************************************************************/
1718
            /* Dump the segment data                                            */
1719
            /********************************************************************/
1720
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1721
            {
1722
                writeLine(indent, "Segment", i);
1723
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1724
            }
1725
            dumpEntityData(pMline, indent, Program.xml.DocumentElement);
1726
        }
1727

    
1728
        /************************************************************************/
1729
        /* MText Dumper                                                         */
1730
        /************************************************************************/
1731
        /// <summary>
1732
        /// convert MText to normal Text
1733
        /// </summary>
1734
        /// <param name="pMText"></param>
1735
        /// <param name="indent"></param>
1736
        /// <param name="node"></param>
1737
        void dump(MText pMText, int indent, XmlNode node)
1738
        {
1739
            DBObjectCollection objColl = new DBObjectCollection();
1740
            pMText.Explode(objColl);
1741
            foreach (var obj in objColl)
1742
            {
1743
                dumpTextData(obj as DBText, indent, node);
1744
            }
1745
        }
1746

    
1747
        /************************************************************************/
1748
        /* Ordinate Dimension Dumper                                            */
1749
        /************************************************************************/
1750
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1751
        {
1752
            if (node != null)
1753
            {
1754
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1755

    
1756
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1757
                HandleAttr.Value = pDim.Handle.ToString();
1758
                DimNode.Attributes.SetNamedItem(HandleAttr);
1759

    
1760
                XmlAttribute DefiningPointAttr = Program.xml.CreateAttribute("DefiningPoint");
1761
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1762
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1763

    
1764
                XmlAttribute UsingXAxisAttr = Program.xml.CreateAttribute("UsingXAxis");
1765
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1766
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1767

    
1768
                XmlAttribute UsingYAxisAttr = Program.xml.CreateAttribute("UsingYAxis");
1769
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1770
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1771

    
1772
                XmlAttribute LeaderEndPointAttr = Program.xml.CreateAttribute("LeaderEndPoint");
1773
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1774
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1775

    
1776
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1777
                OriginAttr.Value = pDim.Origin.ToString();
1778
                DimNode.Attributes.SetNamedItem(OriginAttr);
1779

    
1780
                dumpDimData(pDim, indent, DimNode);
1781

    
1782
                return DimNode;
1783
            }
1784

    
1785
            return null;
1786
        }
1787

    
1788
        /************************************************************************/
1789
        /* PolyFaceMesh Dumper                                                  */
1790
        /************************************************************************/
1791
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1792
        {
1793
            if (node != null)
1794
            {
1795
                XmlElement PolyNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1796

    
1797
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1798
                HandleAttr.Value = pPoly.Handle.ToString();
1799
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1800

    
1801
                XmlAttribute NumVerticesAttr = Program.xml.CreateAttribute("NumVertices");
1802
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1803
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1804

    
1805
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1806
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1807
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1808

    
1809
                /********************************************************************/
1810
                /* dump vertices and faces                                          */
1811
                /********************************************************************/
1812
                int vertexCount = 0;
1813
                int faceCount = 0;
1814
                foreach (ObjectId objId in pPoly)
1815
                {
1816
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1817
                    {
1818
                        if (ent is PolyFaceMeshVertex)
1819
                        {
1820
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1821

    
1822
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1823

    
1824
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1825
                            _HandleAttr.Value = pVertex.Handle.ToString();
1826
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1827

    
1828
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1829
                            PositionAttr.Value = pVertex.Position.ToString();
1830
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1831

    
1832
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1833

    
1834
                            PolyNode.AppendChild(VertexNode);
1835
                        }
1836
                        else if (ent is FaceRecord)
1837
                        {
1838
                            FaceRecord pFace = (FaceRecord)ent;
1839
                            string face = "{";
1840
                            for (short i = 0; i < 4; i++)
1841
                            {
1842
                                if (i > 0)
1843
                                {
1844
                                    face = face + " ";
1845
                                }
1846
                                face = face + pFace.GetVertexAt(i).ToString();
1847
                            }
1848

    
1849
                            face += "}";
1850

    
1851
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1852

    
1853
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1854
                            _HandleAttr.Value = pFace.Handle.ToString();
1855
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1856
                            FaceNode.InnerText = face;
1857

    
1858
                            dumpEntityData(pFace, indent + 1, FaceNode);
1859

    
1860
                            PolyNode.AppendChild(FaceNode);
1861
                        }
1862
                        else
1863
                        { // Unknown entity type
1864
                            writeLine(indent, "Unexpected Entity");
1865
                        }
1866
                    }
1867
                }
1868
                dumpEntityData(pPoly, indent, PolyNode);
1869

    
1870
                return PolyNode;
1871
            }
1872

    
1873
            return null;
1874
        }
1875

    
1876
        /************************************************************************/
1877
        /* Ole2Frame                                                            */
1878
        /************************************************************************/
1879
        void dump(Ole2Frame pOle, int indent)
1880
        {
1881
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1882

    
1883
            Rectangle3d pos = (Rectangle3d)pOle.Position3d;
1884
            writeLine(indent, "Lower Left", pos.LowerLeft);
1885
            writeLine(indent, "Lower Right", pos.LowerRight);
1886
            writeLine(indent, "Upper Left", pos.UpperLeft);
1887
            writeLine(indent, "Upper Right", pos.UpperRight);
1888
            writeLine(indent, "Type", pOle.Type);
1889
            writeLine(indent, "User Type", pOle.UserType);
1890
            if (pOle.Type == Ole2Frame.ItemType.Link)
1891
            {
1892
                writeLine(indent, "Link Name", pOle.LinkName);
1893
                writeLine(indent, "Link Path", pOle.LinkPath);
1894
            }
1895
            writeLine(indent, "Output Quality", pOle.OutputQuality);
1896
            dumpEntityData(pOle, indent, Program.xml.DocumentElement);
1897
        }
1898

    
1899
        /************************************************************************/
1900
        /* Point Dumper                                                         */
1901
        /************************************************************************/
1902
        void dump(DBPoint pPoint, int indent)
1903
        {
1904
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1905
            writeLine(indent, "Position", pPoint.Position);
1906
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1907
            writeLine(indent, "Normal", pPoint.Normal);
1908
            writeLine(indent, "Thickness", pPoint.Thickness);
1909
            dumpEntityData(pPoint, indent, Program.xml.DocumentElement);
1910
        }
1911

    
1912
        /************************************************************************/
1913
        /* Polygon Mesh Dumper                                                  */
1914
        /************************************************************************/
1915
        void dump(PolygonMesh pPoly, int indent)
1916
        {
1917
            writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1918
            writeLine(indent, "m Size", pPoly.MSize);
1919
            writeLine(indent, "m-Closed", pPoly.IsMClosed);
1920
            writeLine(indent, "m Surface Density", pPoly.MSurfaceDensity);
1921
            writeLine(indent, "n Size", pPoly.NSize);
1922
            writeLine(indent, "n-Closed", pPoly.IsNClosed);
1923
            writeLine(indent, "n Surface Density", pPoly.NSurfaceDensity);
1924
            /********************************************************************/
1925
            /* dump vertices                                                    */
1926
            /********************************************************************/
1927
            int vertexCount = 0;
1928
            foreach (object o in pPoly)
1929
            {
1930
                PolygonMeshVertex pVertex = o as PolygonMeshVertex;
1931
                if (pVertex != null)
1932
                {
1933
                    writeLine(indent, pVertex.GetRXClass().Name, vertexCount++);
1934
                    writeLine(indent + 1, "Handle", pVertex.Handle);
1935
                    writeLine(indent + 1, "Position", pVertex.Position);
1936
                    writeLine(indent + 1, "Type", pVertex.VertexType);
1937
                }
1938
            }
1939
            dumpEntityData(pPoly, indent, Program.xml.DocumentElement);
1940
        }
1941

    
1942
        /************************************************************************/
1943
        /* Polyline Dumper                                                      */
1944
        /************************************************************************/
1945
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
1946
        {
1947
            if (pPoly != null && pPoly.Length != 0)
1948
            {
1949
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1950
                writeLine(indent, "Has Width", pPoly.HasWidth);
1951
                if (!pPoly.HasWidth)
1952
                {
1953
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
1954
                }
1955

    
1956
                /********************************************************************/
1957
                /* dump vertices                                                    */
1958
                /********************************************************************/
1959
                if (node != null)
1960
                {
1961
                    XmlNode PolylineNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1962
                    XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1963
                    LengthAttr.Value = pPoly.Length.ToString();
1964
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
1965

    
1966
                    XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
1967
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
1968
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
1969

    
1970
                    XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1971
                    HandleAttr.Value = pPoly.Handle.ToString();
1972
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
1973

    
1974
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
1975
                    ClosedAttr.Value = pPoly.Closed.ToString();
1976
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
1977

    
1978
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
1979
                    {
1980
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
1981

    
1982
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
1983
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
1984

    
1985
                        Point3d pt = pPoly.GetPoint3dAt(i);
1986
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1987
                        XAttr.Value = pt.X.ToString();
1988
                        VertexNode.Attributes.SetNamedItem(XAttr);
1989

    
1990
                        XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1991
                        YAttr.Value = pt.Y.ToString();
1992
                        VertexNode.Attributes.SetNamedItem(YAttr);
1993

    
1994
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1995
                        ZAttr.Value = pt.Z.ToString();
1996
                        VertexNode.Attributes.SetNamedItem(ZAttr);
1997

    
1998
                        if (pPoly.HasWidth)
1999
                        {
2000
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
2001
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
2002
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
2003

    
2004
                            XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
2005
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
2006
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
2007
                        }
2008
                        if (pPoly.HasBulges)
2009
                        {
2010
                            XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
2011
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
2012
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
2013

    
2014
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2015
                            {
2016
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
2017
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2018
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2019
                            }
2020
                        }
2021

    
2022
                        PolylineNode.AppendChild(VertexNode);
2023
                    }
2024

    
2025
                    dumpEntityData(pPoly, indent, PolylineNode);
2026
                    node.AppendChild(PolylineNode);
2027
                }
2028
            }
2029
            else
2030
            {
2031
                int d = 0;
2032
            }
2033
        }
2034

    
2035
        class DrawContextDumper : Context
2036
        {
2037
            Database _db;
2038
            public DrawContextDumper(Database db)
2039
            {
2040
                _db = db;
2041
            }
2042
            public override Database Database
2043
            {
2044
                get { return _db; }
2045
            }
2046
            public override bool IsBoundaryClipping
2047
            {
2048
                get { return false; }
2049
            }
2050
            public override bool IsPlotGeneration
2051
            {
2052
                get { return false; }
2053
            }
2054
            public override bool IsPostScriptOut
2055
            {
2056
                get { return false; }
2057
            }
2058
        }
2059
        class SubEntityTraitsDumper : SubEntityTraits
2060
        {
2061
            short _color;
2062
            int _drawFlags;
2063
            FillType _ft;
2064
            ObjectId _layer;
2065
            ObjectId _linetype;
2066
            LineWeight _lineWeight;
2067
            Mapper _mapper;
2068
            double _lineTypeScale;
2069
            ObjectId _material;
2070
            PlotStyleDescriptor _plotStyleDescriptor;
2071
            bool _sectionable;
2072
            bool _selectionOnlyGeometry;
2073
            ShadowFlags _shadowFlags;
2074
            double _thickness;
2075
            EntityColor _trueColor;
2076
            Transparency _transparency;
2077
            ObjectId _visualStyle;
2078
            public SubEntityTraitsDumper(Database db)
2079
            {
2080
                _drawFlags = 0; // kNoDrawFlags 
2081
                _color = 0;
2082
                _ft = FillType.FillAlways;
2083
                _layer = db.Clayer;
2084
                _linetype = db.Celtype;
2085
                _lineWeight = db.Celweight;
2086
                _lineTypeScale = db.Celtscale;
2087
                _material = db.Cmaterial;
2088
                _shadowFlags = ShadowFlags.ShadowsIgnore;
2089
                _thickness = 0;
2090
                _trueColor = new EntityColor(ColorMethod.None);
2091
                _transparency = new Transparency();
2092
            }
2093

    
2094
            protected override void SetLayerFlags(LayerFlags flags)
2095
            {
2096
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2097
            }
2098
            public override void AddLight(ObjectId lightId)
2099
            {
2100
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2101
            }
2102
            public override void SetupForEntity(Entity entity)
2103
            {
2104
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2105
            }
2106

    
2107
            public override short Color
2108
            {
2109
                get { return _color; }
2110
                set { _color = value; }
2111
            }
2112
            public override int DrawFlags
2113
            {
2114
                get { return _drawFlags; }
2115
                set { _drawFlags = value; }
2116
            }
2117
            public override FillType FillType
2118
            {
2119
                get { return _ft; }
2120
                set { _ft = value; }
2121
            }
2122
            public override ObjectId Layer
2123
            {
2124
                get { return _layer; }
2125
                set { _layer = value; }
2126
            }
2127
            public override ObjectId LineType
2128
            {
2129
                get { return _linetype; }
2130
                set { _linetype = value; }
2131
            }
2132
            public override double LineTypeScale
2133
            {
2134
                get { return _lineTypeScale; }
2135
                set { _lineTypeScale = value; }
2136
            }
2137
            public override LineWeight LineWeight
2138
            {
2139
                get { return _lineWeight; }
2140
                set { _lineWeight = value; }
2141
            }
2142
            public override Mapper Mapper
2143
            {
2144
                get { return _mapper; }
2145
                set { _mapper = value; }
2146
            }
2147
            public override ObjectId Material
2148
            {
2149
                get { return _material; }
2150
                set { _material = value; }
2151
            }
2152
            public override PlotStyleDescriptor PlotStyleDescriptor
2153
            {
2154
                get { return _plotStyleDescriptor; }
2155
                set { _plotStyleDescriptor = value; }
2156
            }
2157
            public override bool Sectionable
2158
            {
2159
                get { return _sectionable; }
2160
                set { _sectionable = value; }
2161
            }
2162
            public override bool SelectionOnlyGeometry
2163
            {
2164
                get { return _selectionOnlyGeometry; }
2165
                set { _selectionOnlyGeometry = value; }
2166
            }
2167
            public override ShadowFlags ShadowFlags
2168
            {
2169
                get { return _shadowFlags; }
2170
                set { _shadowFlags = value; }
2171
            }
2172
            public override double Thickness
2173
            {
2174
                get { return _thickness; }
2175
                set { _thickness = value; }
2176
            }
2177
            public override EntityColor TrueColor
2178
            {
2179
                get { return _trueColor; }
2180
                set { _trueColor = value; }
2181
            }
2182
            public override Transparency Transparency
2183
            {
2184
                get { return _transparency; }
2185
                set { _transparency = value; }
2186
            }
2187
            public override ObjectId VisualStyle
2188
            {
2189
                get { return _visualStyle; }
2190
                set { _visualStyle = value; }
2191
            }
2192
            public override void SetSelectionMarker(IntPtr sm)
2193
            {
2194
            }
2195
        }
2196
        class WorldGeometryDumper : WorldGeometry
2197
        {
2198
            Stack<Matrix3d> modelMatrix;
2199
            Stack<ClipBoundary> clips;
2200
            int indent;
2201
            public WorldGeometryDumper(int indent)
2202
              : base()
2203
            {
2204
                this.indent = indent;
2205
                modelMatrix = new Stack<Matrix3d>();
2206
                clips = new Stack<ClipBoundary>();
2207
                modelMatrix.Push(Matrix3d.Identity);
2208
            }
2209
            public override Matrix3d ModelToWorldTransform
2210
            {
2211
                get { return modelMatrix.Peek(); }
2212
            }
2213
            public override Matrix3d WorldToModelTransform
2214
            {
2215
                get { return modelMatrix.Peek().Inverse(); }
2216
            }
2217

    
2218
            public override Matrix3d PushOrientationTransform(OrientationBehavior behavior)
2219
            {
2220
                writeLine(indent, string.Format("WorldGeometry.PushOrientationTransform(behavior = {0})", behavior));
2221
                return new Matrix3d();
2222
            }
2223
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point2d offset)
2224
            {
2225
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2226
                return new Matrix3d();
2227
            }
2228
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point3d offset)
2229
            {
2230
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2231
                return new Matrix3d();
2232
            }
2233
            public override bool OwnerDraw(GdiDrawObject gdiDrawObject, Point3d position, Vector3d u, Vector3d v)
2234
            {
2235
                writeLine(indent, string.Format("WorldGeometry.OwnerDraw(gdiDrawObject = {0}, position = {1}, u = {2}, v = {3})", gdiDrawObject, position, u, v));
2236
                return false;
2237
            }
2238
            public override bool Polyline(Teigha.GraphicsInterface.Polyline polylineObj)
2239
            {
2240
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}", polylineObj));
2241
                return false;
2242
            }
2243
            public override bool Polypoint(Point3dCollection points, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2244
            {
2245
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, normals = {1}, subentityMarkers = {2}", points, normals, subentityMarkers));
2246
                return false;
2247
            }
2248
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2249
            {
2250
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, normals = {2}, subentityMarkers = {3}", points, colors, normals, subentityMarkers));
2251
                return false;
2252
            }
2253
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, TransparencyCollection transparency, Vector3dCollection normals, IntPtrCollection subentityMarkers, int pointSize)
2254
            {
2255
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, transparency = {2}, normals = {3}, subentityMarkers = {4}, pointSize = {5}", points, colors, transparency, normals, subentityMarkers, pointSize));
2256
                return false;
2257
            }
2258
            public override bool PolyPolyline(Teigha.GraphicsInterface.PolylineCollection polylineCollection)
2259
            {
2260
                writeLine(indent, string.Format("WorldGeometry.PolyPolyline(polylineCollection = {0}", polylineCollection));
2261
                return false;
2262
            }
2263
            public override bool PolyPolygon(UInt32Collection numPolygonPositions, Point3dCollection polygonPositions, UInt32Collection numPolygonPoints, Point3dCollection polygonPoints, EntityColorCollection outlineColors, LinetypeCollection outlineTypes, EntityColorCollection fillColors, Teigha.Colors.TransparencyCollection fillOpacities)
2264
            {
2265
                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));
2266
                return false;
2267
            }
2268
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point2d extents)
2269
            {
2270
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2271
                return new Matrix3d();
2272
            }
2273
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point3d extents)
2274
            {
2275
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2276
                return new Matrix3d();
2277
            }
2278
            public override bool EllipticalArc(Point3d center, Vector3d normal, double majorAxisLength, double minorAxisLength, double startDegreeInRads, double endDegreeInRads, double tiltDegreeInRads, ArcType arType)
2279
            {
2280
                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));
2281
                return false;
2282
            }
2283
            public override bool Circle(Point3d center, double radius, Vector3d normal)
2284
            {
2285
                writeLine(indent, string.Format("WorldGeometry.Circle(center = {0}, radius = {1}, normal = {2})", center, radius, normal));
2286
                return false;
2287
            }
2288
            public override bool Circle(Point3d firstPoint, Point3d secondPoint, Point3d thirdPoint)
2289
            {
2290
                writeLine(indent, string.Format("WorldGeometry.Circle(firstPoint = {0}, secondPoint = {1}, thirdPoint = {2})", firstPoint, secondPoint, thirdPoint));
2291
                return false;
2292
            }
2293
            public override bool CircularArc(Point3d start, Point3d point, Point3d endingPoint, ArcType arcType)
2294
            {
2295
                writeLine(indent, string.Format("WorldGeometry.CircularArc(start = {0}, point = {1}, endingPoint = {2}, arcType = {3})", start, point, endingPoint, arcType));
2296
                return false;
2297
            }
2298
            public override bool CircularArc(Point3d center, double radius, Vector3d normal, Vector3d startVector, double sweepAngle, ArcType arcType)
2299
            {
2300
                writeLine(indent, string.Format("WorldGeometry.CircularArc(center = {0}, radius = {1}, normal = {2}, startVector = {3}, sweepAngle = {4}, arcType = {5}", center, radius, normal, startVector, sweepAngle, arcType));
2301
                return false;
2302
            }
2303
            public override bool Draw(Drawable value)
2304
            {
2305
                writeLine(indent, string.Format("WorldGeometry.Draw(value = {0}", value));
2306
                return false;
2307
            }
2308
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v)
2309
            {
2310
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}", position, u, v));
2311
                return false;
2312
            }
2313
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v, TransparencyMode transparencyMode)
2314
            {
2315
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}, transparencyMode = {4}", position, u, v, transparencyMode));
2316
                return false;
2317
            }
2318
            public override bool Mesh(int rows, int columns, Point3dCollection points, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2319
            {
2320
                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));
2321
                return false;
2322
            }
2323
            public override bool Polygon(Point3dCollection points)
2324
            {
2325
                writeLine(indent, string.Format("WorldGeometry.Polygon(points = {0})", points));
2326
                return false;
2327
            }
2328
            public override bool Polyline(Teigha.DatabaseServices.Polyline value, int fromIndex, int segments)
2329
            {
2330
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}, fromIndex = {1}, segments = {2})", value, fromIndex, segments));
2331
                return false;
2332
            }
2333
            public override bool Polyline(Point3dCollection points, Vector3d normal, IntPtr subEntityMarker)
2334
            {
2335
                writeLine(indent, string.Format("WorldGeometry.Polyline(points = {0}, normal = {1}, subEntityMarker = {2})", points, normal, subEntityMarker));
2336
                return false;
2337
            }
2338
            public override void PopClipBoundary()
2339
            {
2340
                writeLine(indent, string.Format("WorldGeometry.PopClipBoundary"));
2341
                clips.Pop();
2342
            }
2343
            public override bool PopModelTransform()
2344
            {
2345
                return true;
2346
            }
2347
            public override bool PushClipBoundary(ClipBoundary boundary)
2348
            {
2349
                writeLine(indent, string.Format("WorldGeometry.PushClipBoundary"));
2350
                clips.Push(boundary);
2351
                return true;
2352
            }
2353
            public override bool PushModelTransform(Matrix3d matrix)
2354
            {
2355
                writeLine(indent, "WorldGeometry.PushModelTransform(Matrix3d)");
2356
                Matrix3d m = modelMatrix.Peek();
2357
                modelMatrix.Push(m * matrix);
2358
                return true;
2359
            }
2360
            public override bool PushModelTransform(Vector3d normal)
2361
            {
2362
                writeLine(indent, "WorldGeometry.PushModelTransform(Vector3d)");
2363
                PushModelTransform(Matrix3d.PlaneToWorld(normal));
2364
                return true;
2365
            }
2366
            public override bool RowOfDots(int count, Point3d start, Vector3d step)
2367
            {
2368
                writeLine(indent, string.Format("ViewportGeometry.RowOfDots(count = {0}, start = {1}, step = {1})", count, start, step));
2369
                return false;
2370
            }
2371
            public override bool Ray(Point3d point1, Point3d point2)
2372
            {
2373
                writeLine(indent, string.Format("WorldGeometry.Ray(point1 = {0}, point2 = {1})", point1, point2));
2374
                return false;
2375
            }
2376
            public override bool Shell(Point3dCollection points, IntegerCollection faces, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2377
            {
2378
                writeLine(indent, string.Format("WorldGeometry.Shell(points = {0}, faces = {1}, edgeData = {2}, faceData = {3}, vertexData = {4}, bAutoGenerateNormals = {5})", points, faces, edgeData, faceData, vertexData, bAutoGenerateNormals));
2379
                return false;
2380
            }
2381
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, string message, bool raw, TextStyle textStyle)
2382
            {
2383
                writeLine(indent, string.Format("WorldGeometry.Text(position = {0}, normal = {1}, direction = {2}, message = {3}, raw = {4}, textStyle = {5})", position, normal, direction, message, raw, textStyle));
2384
                return false;
2385
            }
2386
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, double height, double width, double oblique, string message)
2387
            {
2388
                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));
2389
                return false;
2390
            }
2391
            public override bool WorldLine(Point3d startPoint, Point3d endPoint)
2392
            {
2393
                writeLine(indent, string.Format("WorldGeometry.WorldLine(startPoint = {0}, endPoint = {1})", startPoint, endPoint));
2394
                return false;
2395
            }
2396
            public override bool Xline(Point3d point1, Point3d point2)
2397
            {
2398
                writeLine(indent, string.Format("WorldGeometry.Xline(point1 = {0}, point2 = {1})", point1, point2));
2399
                return false;
2400
            }
2401

    
2402
            public override void SetExtents(Extents3d extents)
2403
            {
2404
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2405
            }
2406
            public override void StartAttributesSegment()
2407
            {
2408
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2409
            }
2410
        }
2411

    
2412
        class WorldDrawDumper : WorldDraw
2413
        {
2414
            WorldGeometryDumper _geom;
2415
            DrawContextDumper _ctx;
2416
            SubEntityTraits _subents;
2417
            RegenType _regenType;
2418
            int indent;
2419
            public WorldDrawDumper(Database db, int indent)
2420
              : base()
2421
            {
2422
                _regenType = RegenType;
2423
                this.indent = indent;
2424
                _geom = new WorldGeometryDumper(indent);
2425
                _ctx = new DrawContextDumper(db);
2426
                _subents = new SubEntityTraitsDumper(db);
2427
            }
2428
            public override double Deviation(DeviationType deviationType, Point3d pointOnCurve)
2429
            {
2430
                return 1e-9;
2431
            }
2432
            public override WorldGeometry Geometry
2433
            {
2434
                get
2435
                {
2436
                    return _geom;
2437
                }
2438
            }
2439
            public override bool IsDragging
2440
            {
2441
                get
2442
                {
2443
                    return false;
2444
                }
2445
            }
2446
            public override Int32 NumberOfIsolines
2447
            {
2448
                get
2449
                {
2450
                    return 10;
2451
                }
2452
            }
2453
            public override Geometry RawGeometry
2454
            {
2455
                get
2456
                {
2457
                    return _geom;
2458
                }
2459
            }
2460
            public override bool RegenAbort
2461
            {
2462
                get
2463
                {
2464
                    return false;
2465
                }
2466
            }
2467
            public override RegenType RegenType
2468
            {
2469
                get
2470
                {
2471
                    writeLine(indent, "RegenType is asked");
2472
                    return _regenType;
2473
                }
2474
            }
2475
            public override SubEntityTraits SubEntityTraits
2476
            {
2477
                get
2478
                {
2479
                    return _subents;
2480
                }
2481
            }
2482
            public override Context Context
2483
            {
2484
                get
2485
                {
2486
                    return _ctx;
2487
                }
2488
            }
2489
        }
2490

    
2491
        /************************************************************************/
2492
        /* Dump the common data and WorldDraw information for all               */
2493
        /* entities without explicit dumpers                                    */
2494
        /************************************************************************/
2495
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2496
        {
2497
            if (node != null)
2498
            {
2499
                XmlElement EntNode = Program.xml.CreateElement(pEnt.GetRXClass().Name);
2500

    
2501
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2502
                HandleAttr.Value = pEnt.Handle.ToString();
2503
                EntNode.Attributes.SetNamedItem(HandleAttr);
2504

    
2505
                dumpEntityData(pEnt, indent, EntNode);
2506
                using (Database db = pEnt.Database)
2507
                {
2508
                    /**********************************************************************/
2509
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2510
                    /**********************************************************************/
2511
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2512
                    /**********************************************************************/
2513
                    /* Call worldDraw()                                                   */
2514
                    /**********************************************************************/
2515
                    pEnt.WorldDraw(wd);
2516
                }
2517

    
2518
                node.AppendChild(EntNode);
2519

    
2520
                return EntNode;
2521
            }
2522

    
2523
            return null;
2524
        }
2525

    
2526
        /************************************************************************/
2527
        /* Proxy Entity Dumper                                                  */
2528
        /************************************************************************/
2529
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2530
        {
2531
            if (node != null)
2532
            {
2533
                XmlElement ProxyNode = Program.xml.CreateElement(pProxy.GetRXClass().Name);
2534

    
2535
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2536
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2537
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2538

    
2539
                // this will dump proxy entity graphics
2540
                dump((Entity)pProxy, indent, node);
2541

    
2542
                DBObjectCollection collection = new DBObjectCollection(); ;
2543
                try
2544
                {
2545
                    pProxy.ExplodeGeometry(collection);
2546
                }
2547
                catch (System.Exception)
2548
                {
2549
                    return null;
2550
                }
2551

    
2552
                foreach (Entity ent in collection)
2553
                {
2554
                    if (ent is Polyline2d)
2555
                    {
2556
                        Polyline2d pline2d = (Polyline2d)ent;
2557
                        int i = 0;
2558

    
2559
                        try
2560
                        {
2561
                            foreach (Entity ent1 in pline2d)
2562
                            {
2563
                                if (ent1 is Vertex2d)
2564
                                {
2565
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2566
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2567
                                }
2568
                            }
2569
                        }
2570
                        catch (System.Exception)
2571
                        {
2572
                            return null;
2573
                        }
2574
                    }
2575
                }
2576

    
2577
                node.AppendChild(ProxyNode);
2578
                return ProxyNode;
2579
            }
2580

    
2581
            return null;
2582
        }
2583

    
2584
        /************************************************************************/
2585
        /* Radial Dimension Dumper                                              */
2586
        /************************************************************************/
2587
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2588
        {
2589
            if (node != null)
2590
            {
2591
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2592

    
2593
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2594
                HandleAttr.Value = pDim.Handle.ToString();
2595
                DimNode.Attributes.SetNamedItem(HandleAttr);
2596

    
2597
                XmlAttribute CenterAttr = Program.xml.CreateAttribute("Center");
2598
                CenterAttr.Value = pDim.Center.ToString();
2599
                DimNode.Attributes.SetNamedItem(CenterAttr);
2600

    
2601
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
2602
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
2603
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
2604

    
2605
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
2606
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2607
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2608

    
2609
                dumpDimData(pDim, indent, DimNode);
2610

    
2611
                node.AppendChild(DimNode);
2612

    
2613
                return DimNode;
2614
            }
2615

    
2616
            return null;
2617
        }
2618

    
2619
        /************************************************************************/
2620
        /* Dump Raster Image Def                                               */
2621
        /************************************************************************/
2622
        void dumpRasterImageDef(ObjectId id, int indent)
2623
        {
2624
            if (!id.IsValid)
2625
                return;
2626
            using (RasterImageDef pDef = (RasterImageDef)id.Open(OpenMode.ForRead))
2627
            {
2628
                writeLine(indent++, pDef.GetRXClass().Name, pDef.Handle);
2629
                writeLine(indent, "Source Filename", shortenPath(pDef.SourceFileName));
2630
                writeLine(indent, "Loaded", pDef.IsLoaded);
2631
                writeLine(indent, "mm per Pixel", pDef.ResolutionMMPerPixel);
2632
                writeLine(indent, "Loaded", pDef.IsLoaded);
2633
                writeLine(indent, "Resolution Units", pDef.ResolutionUnits);
2634
                writeLine(indent, "Size", pDef.Size);
2635
            }
2636
        }
2637
        /************************************************************************/
2638
        /* Dump Raster Image Data                                               */
2639
        /************************************************************************/
2640
        void dumpRasterImageData(RasterImage pImage, int indent)
2641
        {
2642
            writeLine(indent, "Brightness", pImage.Brightness);
2643
            writeLine(indent, "Clipped", pImage.IsClipped);
2644
            writeLine(indent, "Contrast", pImage.Contrast);
2645
            writeLine(indent, "Fade", pImage.Fade);
2646
            writeLine(indent, "kClip", pImage.DisplayOptions & ImageDisplayOptions.Clip);
2647
            writeLine(indent, "kShow", pImage.DisplayOptions & ImageDisplayOptions.Show);
2648
            writeLine(indent, "kShowUnAligned", pImage.DisplayOptions & ImageDisplayOptions.ShowUnaligned);
2649
            writeLine(indent, "kTransparent", pImage.DisplayOptions & ImageDisplayOptions.Transparent);
2650
            writeLine(indent, "Scale", pImage.Scale);
2651

    
2652
            /********************************************************************/
2653
            /* Dump clip boundary                                               */
2654
            /********************************************************************/
2655
            if (pImage.IsClipped)
2656
            {
2657
                writeLine(indent, "Clip Boundary Type", pImage.ClipBoundaryType);
2658
                if (pImage.ClipBoundaryType != ClipBoundaryType.Invalid)
2659
                {
2660
                    Point2dCollection pt = pImage.GetClipBoundary();
2661
                    for (int i = 0; i < pt.Count; i++)
2662
                    {
2663
                        writeLine(indent, string.Format("Clip Point {0}", i), pt[i]);
2664
                    }
2665
                }
2666
            }
2667

    
2668
            /********************************************************************/
2669
            /* Dump frame                                                       */
2670
            /********************************************************************/
2671
            Point3dCollection vertices = pImage.GetVertices();
2672
            for (int i = 0; i < vertices.Count; i++)
2673
            {
2674
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2675
            }
2676

    
2677
            /********************************************************************/
2678
            /* Dump orientation                                                 */
2679
            /********************************************************************/
2680
            writeLine(indent, "Orientation");
2681
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2682
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2683
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2684
            dumpRasterImageDef(pImage.ImageDefId, indent);
2685
            dumpEntityData(pImage, indent, Program.xml.DocumentElement);
2686
        }
2687

    
2688
        /************************************************************************/
2689
        /* Raster Image Dumper                                                  */
2690
        /************************************************************************/
2691
        void dump(RasterImage pImage, int indent)
2692
        {
2693
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2694
            writeLine(indent, "Image size", pImage.ImageSize(true));
2695
            dumpRasterImageData(pImage, indent);
2696
        }
2697

    
2698
        /************************************************************************/
2699
        /* Ray Dumper                                                          */
2700
        /************************************************************************/
2701
        void dump(Ray pRay, int indent)
2702
        {
2703
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2704
            writeLine(indent, "Base Point", pRay.BasePoint);
2705
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2706
            dumpCurveData(pRay, indent, Program.xml.DocumentElement);
2707
        }
2708

    
2709
        /************************************************************************/
2710
        /* Region Dumper                                                        */
2711
        /************************************************************************/
2712
        void dump(Region pRegion, int indent)
2713
        {
2714
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2715
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2716
        }
2717

    
2718
        /************************************************************************/
2719
        /* Rotated Dimension Dumper                                             */
2720
        /************************************************************************/
2721
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2722
        {
2723
            if (node != null)
2724
            {
2725
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2726

    
2727
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2728
                HandleAttr.Value = pDim.Handle.ToString();
2729
                DimNode.Attributes.SetNamedItem(HandleAttr);
2730

    
2731
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
2732
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2733
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2734

    
2735
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
2736
                ObliqueAttr.Value = pDim.Oblique.ToString();
2737
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2738

    
2739
                XmlAttribute RotationAttr = Program.xml.CreateAttribute("Rotation");
2740
                RotationAttr.Value = pDim.Rotation.ToString();
2741
                DimNode.Attributes.SetNamedItem(RotationAttr);
2742

    
2743
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
2744
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2745
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2746

    
2747
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2748
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2749
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2750

    
2751
                dumpDimData(pDim, indent, DimNode);
2752
                node.AppendChild(DimNode);
2753

    
2754
                return DimNode;
2755
            }
2756

    
2757
            return null;
2758
        }
2759

    
2760
        /************************************************************************/
2761
        /* Shape Dumper                                                          */
2762
        /************************************************************************/
2763
        void dump(Shape pShape, int indent)
2764
        {
2765
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2766

    
2767
            if (!pShape.StyleId.IsNull)
2768
            {
2769
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2770
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2771
            }
2772

    
2773
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2774
            writeLine(indent, "Shape Name", pShape.Name);
2775
            writeLine(indent, "Position", pShape.Position);
2776
            writeLine(indent, "Size", pShape.Size);
2777
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2778
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2779
            writeLine(indent, "Normal", pShape.Normal);
2780
            writeLine(indent, "Thickness", pShape.Thickness);
2781
            dumpEntityData(pShape, indent, Program.xml.DocumentElement);
2782
        }
2783

    
2784
        /************************************************************************/
2785
        /* Solid Dumper                                                         */
2786
        /************************************************************************/
2787
        // TODO:
2788
        /*  void dump(Solid pSolid, int indent)
2789
      {
2790
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2791

    
2792
        for (int i = 0; i < 4; i++)
2793
        {
2794
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2795
        }
2796
        dumpEntityData(pSolid, indent);
2797
      }
2798
    */
2799
        /************************************************************************/
2800
        /* Spline Dumper                                                        */
2801
        /************************************************************************/
2802
        void dump(Spline pSpline, int indent)
2803
        {
2804
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2805

    
2806
            NurbsData data = pSpline.NurbsData;
2807
            writeLine(indent, "Degree", data.Degree);
2808
            writeLine(indent, "Rational", data.Rational);
2809
            writeLine(indent, "Periodic", data.Periodic);
2810
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2811
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2812

    
2813
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2814
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2815
            {
2816
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2817
            }
2818

    
2819
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2820
            for (int i = 0; i < data.GetKnots().Count; i++)
2821
            {
2822
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2823
            }
2824

    
2825
            if (data.Rational)
2826
            {
2827
                writeLine(indent, "Number of Weights", data.GetWeights().Count);
2828
                for (int i = 0; i < data.GetWeights().Count; i++)
2829
                {
2830
                    writeLine(indent, "Weight " + i.ToString(), data.GetWeights()[i]);
2831
                }
2832
            }
2833
            dumpCurveData(pSpline, indent, Program.xml.DocumentElement);
2834
        }
2835
        /************************************************************************/
2836
        /* Table Dumper                                                         */
2837
        /************************************************************************/
2838
        void dump(Table pTable, int indent)
2839
        {
2840
            writeLine(indent++, pTable.GetRXClass().Name, pTable.Handle);
2841
            writeLine(indent, "Position", pTable.Position);
2842
            writeLine(indent, "X-Direction", pTable.Direction);
2843
            writeLine(indent, "Normal", pTable.Normal);
2844
            writeLine(indent, "Height", (int)pTable.Height);
2845
            writeLine(indent, "Width", (int)pTable.Width);
2846
            writeLine(indent, "Rows", (int)pTable.NumRows);
2847
            writeLine(indent, "Columns", (int)pTable.NumColumns);
2848

    
2849
            // TODO:
2850
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2851
            //writeLine(indent, "Table Style",               pStyle.Name);
2852
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2853
        }
2854

    
2855
        /************************************************************************/
2856
        /* Text Dumper                                                          */
2857
        /************************************************************************/
2858
        static void dump(DBText pText, int indent, XmlNode node)
2859
        {
2860
            if (node != null)
2861
            {
2862
                dumpTextData(pText, indent, node);
2863
            }
2864
        }
2865
        /************************************************************************/
2866
        /* Trace Dumper                                                         */
2867
        /************************************************************************/
2868
        void dump(Trace pTrace, int indent)
2869
        {
2870
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2871

    
2872
            for (short i = 0; i < 4; i++)
2873
            {
2874
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2875
            }
2876
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2877
        }
2878

    
2879
        /************************************************************************/
2880
        /* Trace UnderlayReference                                                         */
2881
        /************************************************************************/
2882
        void dump(UnderlayReference pEnt, int indent)
2883
        {
2884
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2885
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2886
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2887
        }
2888

    
2889
        /************************************************************************/
2890
        /* Viewport Dumper                                                       */
2891
        /************************************************************************/
2892
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2893
        {
2894
            if (node != null)
2895
            {
2896
                XmlElement VportNode = Program.xml.CreateElement(pVport.GetRXClass().Name);
2897

    
2898
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2899
                HandleAttr.Value = pVport.Handle.ToString();
2900
                VportNode.Attributes.SetNamedItem(HandleAttr);
2901

    
2902
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2903
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2904
                writeLine(indent, "Center Point", pVport.CenterPoint);
2905
                writeLine(indent, "Circle sides", pVport.CircleSides);
2906
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2907
                writeLine(indent, "Elevation", pVport.Elevation);
2908
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2909
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2910
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2911
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2912

    
2913
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2914
                if (layerIds.Count > 0)
2915
                {
2916
                    writeLine(indent, "Frozen Layers:");
2917
                    for (int i = 0; i < layerIds.Count; i++)
2918
                    {
2919
                        writeLine(indent + 1, i, layerIds[i]);
2920
                    }
2921
                }
2922
                else
2923
                {
2924
                    writeLine(indent, "Frozen Layers", "None");
2925
                }
2926

    
2927
                Point3d origin = new Point3d();
2928
                Vector3d xAxis = new Vector3d();
2929
                Vector3d yAxis = new Vector3d();
2930
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
2931
                writeLine(indent, "UCS origin", origin);
2932
                writeLine(indent, "UCS x-Axis", xAxis);
2933
                writeLine(indent, "UCS y-Axis", yAxis);
2934
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
2935
                writeLine(indent, "Grid On", pVport.GridOn);
2936
                writeLine(indent, "Height", pVport.Height);
2937
                writeLine(indent, "Lens Length", pVport.LensLength);
2938
                writeLine(indent, "Locked", pVport.Locked);
2939
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
2940

    
2941
                if (!pVport.NonRectClipEntityId.IsNull)
2942
                {
2943
                    writeLine(indent, "Non-rectangular Clipper", pVport.NonRectClipEntityId.Handle);
2944
                }
2945
                writeLine(indent, "Render Mode", pVport.RenderMode);
2946
                writeLine(indent, "Remove Hidden Lines", pVport.HiddenLinesRemoved);
2947
                writeLine(indent, "Shade Plot", pVport.ShadePlot);
2948
                writeLine(indent, "Snap Isometric", pVport.SnapIsometric);
2949
                writeLine(indent, "Snap On", pVport.SnapOn);
2950
                writeLine(indent, "Transparent", pVport.Transparent);
2951
                writeLine(indent, "UCS Follow", pVport.UcsFollowModeOn);
2952
                writeLine(indent, "UCS Icon at Origin", pVport.UcsIconAtOrigin);
2953

    
2954
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
2955
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
2956

    
2957
                if (!pVport.UcsName.IsNull)
2958
                {
2959
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
2960
                        writeLine(indent, "UCS Name", pUCS.Name);
2961
                }
2962
                else
2963
                {
2964
                    writeLine(indent, "UCS Name", "Null");
2965
                }
2966

    
2967
                writeLine(indent, "View Center", pVport.ViewCenter);
2968
                writeLine(indent, "View Height", pVport.ViewHeight);
2969
                writeLine(indent, "View Target", pVport.ViewTarget);
2970
                writeLine(indent, "Width", pVport.Width);
2971
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
2972

    
2973
                {
2974
                    using (DBObjectCollection collection = new DBObjectCollection())
2975
                    {
2976
                        try
2977
                        {
2978
                            pVport.ExplodeGeometry(collection);
2979

    
2980
                            foreach (Entity ent in collection)
2981
                            {
2982
                                if (ent is Polyline2d)
2983
                                {
2984
                                    Polyline2d pline2d = (Polyline2d)ent;
2985
                                    int i = 0;
2986
                                    foreach (Entity ent1 in pline2d)
2987
                                    {
2988
                                        if (ent1 is Vertex2d)
2989
                                        {
2990
                                            Vertex2d vtx2d = (Vertex2d)ent1;
2991
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
2992
                                        }
2993
                                    }
2994
                                }
2995
                            }
2996
                        }
2997
                        catch (System.Exception)
2998
                        {
2999
                        }
3000
                    }
3001
                }
3002

    
3003
                node.AppendChild(VportNode);
3004
                return VportNode;
3005
            }
3006

    
3007
            return null;
3008
        }
3009

    
3010
        /************************************************************************/
3011
        /* Wipeout Dumper                                                  */
3012
        /************************************************************************/
3013
        void dump(Wipeout pWipeout, int indent)
3014
        {
3015
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3016
            dumpRasterImageData(pWipeout, indent);
3017
        }
3018

    
3019
        /************************************************************************/
3020
        /* Xline Dumper                                                         */
3021
        /************************************************************************/
3022
        void dump(Xline pXline, int indent)
3023
        {
3024
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
3025
            writeLine(indent, "Base Point", pXline.BasePoint);
3026
            writeLine(indent, "Unit Direction", pXline.UnitDir);
3027
            dumpCurveData(pXline, indent, Program.xml.DocumentElement);
3028
        }
3029

    
3030
        public void dump(Database pDb, int indent, XmlNode node)
3031
        {
3032
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3033
            {
3034
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
3035
                {
3036
                    string layoutName = "";
3037
                    layoutName = pLayout.LayoutName;
3038

    
3039
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
3040
                    LayoutNameAttr.Value = layoutName;
3041
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3042
                }
3043
            }
3044

    
3045
            dumpHeader(pDb, indent, node);
3046
            dumpLayers(pDb, indent, node);
3047
            dumpLinetypes(pDb, indent, node);
3048
            dumpTextStyles(pDb, indent, node);
3049
            dumpDimStyles(pDb, indent, node);
3050
            dumpRegApps(pDb, indent);
3051
            dumpViewports(pDb, indent, node);
3052
            dumpViews(pDb, indent, node);
3053
            dumpMLineStyles(pDb, indent);
3054
            dumpUCSTable(pDb, indent, node);
3055
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3056

    
3057
            dumpBlocks(pDb, indent, node);
3058
        }
3059

    
3060
        /************************************************************************/
3061
        /* Export DWG to PDF                                                    */
3062
        /************************************************************************/
3063
        public void ExportPDF(Database pDb, string filePath)
3064
        {
3065
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3066
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3067
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3068

    
3069
            using (mPDFExportParams param = new mPDFExportParams())
3070
            {
3071
                param.Database = pDb;
3072

    
3073
                TransactionManager tm = pDb.TransactionManager;
3074
                using (Transaction ta = tm.StartTransaction())
3075
                {
3076
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3077
                    {
3078
                        param.OutputStream = fileStrem;
3079

    
3080
                        bool embededTTF = false;
3081
                        bool shxTextAsGeometry = true;
3082
                        bool ttfGeometry = true;
3083
                        bool simpleGeomOptimization = false;
3084
                        bool zoomToExtentsMode = true;
3085
                        bool enableLayers = false;
3086
                        bool includeOffLayers = false;
3087
                        bool enablePrcMode = true;
3088
                        bool monochrome = true;
3089
                        bool allLayout = false;
3090
                        double paperWidth = 841;
3091
                        double paperHeight = 594;
3092

    
3093
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3094
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3095
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3096
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3097
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3098
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3099
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3100

    
3101
                        param.Title = "";
3102
                        param.Author = "";
3103
                        param.Subject = "";
3104
                        param.Keywords = "";
3105
                        param.Creator = "";
3106
                        param.Producer = "";
3107
                        param.UseHLR = !enablePrcMode;
3108
                        param.FlateCompression = true;
3109
                        param.ASCIIHEXEncodeStream = true;
3110
                        param.hatchDPI = 720;
3111

    
3112
                        bool bV15 = enableLayers || includeOffLayers;
3113
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3114

    
3115
                        if (enablePrcMode)
3116
                        {
3117
                            Module pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcModule", false, false);
3118
                            if (pModule != null)
3119
                            {
3120
                                pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcExport", false, false);
3121
                            }
3122
                            if (pModule != null)
3123
                            {
3124
                                RXObject pObj = null;
3125
                                bool bUsePRCSingleViewMode = true; // provide a corresponding checkbox in Export to PDF dialog similar to one in OdaMfcApp
3126
                                if (bUsePRCSingleViewMode)
3127
                                {
3128
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_AllInSingleView");
3129
                                }
3130
                                else
3131
                                {
3132
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_Default");
3133
                                }
3134
                                if (pObj != null)
3135
                                {
3136
                                    RXClass pCls = (RXClass)pObj;
3137
                                    if (pCls != null)
3138
                                    {
3139
                                        param.PRCContext = pCls.Create();
3140
                                        param.PRCMode = PRCSupport.AsBrep; //(bUsePRCAsBRep == TRUE ? PRCSupport.AsBrep : PRCSupport.AsMesh);
3141
                                    }
3142
                                    else
3143
                                    {
3144
                                        Console.WriteLine("PDF Export, PRC support - RXClass failed");
3145
                                    }
3146
                                }
3147
                                else
3148
                                {
3149
                                    Console.WriteLine("PDF Export, PRC support - context failed");
3150
                                }
3151
                            }
3152
                            else
3153
                            {
3154
                                Console.WriteLine("PRC module was not loaded", "Error");
3155
                            }
3156
                        }
3157

    
3158
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3159

    
3160
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3161
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3162

    
3163
                        StringCollection strColl = new StringCollection();
3164
                        if (allLayout)
3165
                        {
3166
                            using (DBDictionary layouts = (DBDictionary)pDb.LayoutDictionaryId.GetObject(OpenMode.ForRead))
3167
                            {
3168
                                foreach (DBDictionaryEntry entry in layouts)
3169
                                {
3170
                                    if ("Model" == entry.Key)
3171
                                        strColl.Insert(0, entry.Key);
3172
                                    else
3173
                                        strColl.Add(entry.Key);
3174
                                    if (-1 != iIndexStyle)
3175
                                    {
3176
                                        PlotSettings ps = (PlotSettings)ta.GetObject(entry.Value, OpenMode.ForWrite);
3177
                                        plotSettingVal.SetCurrentStyleSheet(ps, styleCol[iIndexStyle]);
3178
                                    }
3179
                                }
3180
                            }
3181
                        }
3182
                        else if (-1 != iIndexStyle)
3183
                        {
3184
                            using (BlockTableRecord paperBTR = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3185
                            {
3186
                                using (PlotSettings pLayout = (PlotSettings)paperBTR.LayoutId.GetObject(OpenMode.ForWrite))
3187
                                {
3188
                                    plotSettingVal.SetCurrentStyleSheet(pLayout, styleCol[iIndexStyle]);
3189
                                }
3190
                            }
3191
                        }
3192
                        param.Layouts = strColl;
3193

    
3194
                        int nPages = Math.Max(1, strColl.Count);
3195
                        PageParamsCollection pParCol = new PageParamsCollection();
3196
                        for (int i = 0; i < nPages; ++i)
3197
                        {
3198
                            PageParams pp = new PageParams();
3199
                            pp.setParams(paperWidth, paperHeight);
3200
                            pParCol.Add(pp);
3201
                        }
3202
                        param.PageParams = pParCol;
3203
                        Export_Import.ExportPDF(param);
3204
                    }
3205
                    ta.Abort();
3206
                }
3207
            }
3208
        }
3209

    
3210
        /************************************************************************/
3211
        /* Export DWG to PNG                                                    */
3212
        /************************************************************************/
3213
        public void ExportPNG(Database pDb, string filePath)
3214
        {
3215
            chageColorAllObjects(pDb);
3216

    
3217
            string gdPath = "WinOpenGL_20.5_15.txv";
3218

    
3219
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3220
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3221
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3222
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3223

    
3224
            using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3225
            {
3226
                if (gsModule == null)
3227
                {
3228
                    Console.WriteLine("\nCould not load graphics module {0} \nExport cancelled.", gdPath);
3229
                    return;
3230
                }
3231

    
3232
                // create graphics device
3233
                using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3234
                {
3235
                    // setup device properties
3236
                    using (Dictionary props = dev.Properties)
3237
                    {
3238
                        props.AtPut("BitPerPixel", new RxVariant(32));
3239
                    }
3240
                    using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3241
                    {
3242
                        ctx.PaletteBackground = System.Drawing.Color.White;
3243
                        ctx.SetPlotGeneration(true);
3244

    
3245
                        using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3246
                        {
3247
                            helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3248
                            int width = 9600;
3249
                            int height = 6787;
3250
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
3251
                            helperDevice.OnSize(rect);
3252

    
3253
                            if (ctx.IsPlotGeneration)
3254
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3255
                            else
3256
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3257

    
3258
                            helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3259
                            helperDevice.ActiveView.Zoom(0.99);
3260
                            helperDevice.Update();
3261

    
3262
                            Export_Import.ExportBitmap(helperDevice, bmpPath);
3263
                        }
3264
                    }
3265
                }
3266
            }
3267

    
3268
            if (File.Exists(bmpPath))
3269
            {
3270
                if (File.Exists(pngPath))
3271
                {
3272
                    File.Delete(pngPath);
3273
                }
3274

    
3275
                ////bmp => grayscale bmp => png
3276
                //using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3277
                //{
3278
                //    System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height);
3279
                //    //get a graphics object from the new image
3280
                //    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
3281
                //    {
3282
                //        //create the grayscale ColorMatrix
3283
                //        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][]
3284
                //        {
3285
                //            new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
3286
                //            new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
3287
                //            new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
3288
                //            new float[] { 0,      0,      0,      1, 0 },
3289
                //            new float[] { 0,      0,      0,      0, 1 }
3290
                //        });
3291

    
3292
                //        //create some image attributes
3293
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3294
                //        {
3295
                //            //set the color matrix attribute
3296
                //            attributes.SetColorMatrix(colorMatrix);
3297
                //            //attributes.SetThreshold(0.8F);
3298

    
3299
                //            //draw the original image on the new image
3300
                //            //using the grayscale color matrix
3301
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3302
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3303
                //        }
3304

    
3305
                //    }
3306
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3307
                //}
3308

    
3309
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3310
                {
3311
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3312
                }
3313
                if (File.Exists(bmpPath))
3314
                {
3315
                    File.Delete(bmpPath);
3316
                }
3317
            }
3318
        }
3319

    
3320
        /************************************************************************/
3321
        /* Change the color of all objects                                      */
3322
        /************************************************************************/
3323
        private void chageColorAllObjects(Database pDb)
3324
        {
3325
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3326
            {
3327
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3328
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3329

    
3330
                foreach (ObjectId id in btrModelSpace)
3331
                {
3332
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3333
                    if (ent == null) continue;
3334

    
3335
                    ent.ColorIndex = 7;
3336

    
3337
                    if (ent is BlockReference)
3338
                    {
3339
                        changeColorBlocks(tr, (BlockReference)ent);
3340
                    }
3341
                }
3342

    
3343
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3344
                foreach (DBDictionaryEntry entry in dbdic)
3345
                {
3346
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3347
                    if (group == null) continue;
3348

    
3349
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3350
                    if (idarrTags == null) continue;
3351

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

    
3357
                        ent.ColorIndex = 7;
3358
                    }
3359
                }
3360

    
3361
                foreach (ObjectId btrId in bt)
3362
                {
3363
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3364
                    if (btr == null) continue;
3365
                    if (btr.Name.StartsWith("*")) continue;
3366

    
3367
                    foreach (ObjectId entId in btr)
3368
                    {
3369
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3370
                        if (ent == null) continue;
3371
                        ent.ColorIndex = 0;//ByBlock
3372
                    }
3373
                }
3374

    
3375
                tr.Commit();
3376
            }
3377
        }
3378

    
3379
        /************************************************************************/
3380
        /* Change the color of blocks                                           */
3381
        /************************************************************************/
3382
        private void changeColorBlocks(Transaction tr, BlockReference blkRef)
3383
        {
3384
            if (blkRef == null) return;
3385

    
3386
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3387
            {
3388
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3389
                {
3390
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3391
                    attRef.ColorIndex = 7;
3392
                }
3393
            }
3394

    
3395
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3396
            if (btrBlock == null) return;
3397

    
3398
            foreach (ObjectId oid in btrBlock)
3399
            {
3400
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3401
                if (ent == null) continue;
3402

    
3403
                ent.ColorIndex = 7;
3404

    
3405
                if (ent is BlockReference)
3406
                {
3407
                    
3408
                    changeColorBlocks(tr, (BlockReference)ent);
3409
                }
3410
            }
3411
        }
3412

    
3413
        /************************************************************************/
3414
        /* Nested block Explode & Purge                                         */
3415
        /************************************************************************/
3416
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3417
        {
3418
            HashSet<string> blockNameList = new HashSet<string>();
3419
            // Explode ModelSpace Nested Block
3420
            blockNameList = explodeNestedBlocks(pDb);
3421

    
3422
            // Prepare Block Purge
3423
            preparePurgeBlocks(pDb, blockNameList);
3424

    
3425
            // Block Purge
3426
            ObjectIdCollection oids = new ObjectIdCollection();
3427
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3428
            {
3429
                foreach (ObjectId id in pTable)
3430
                {
3431
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3432
                    oids.Add(id);
3433
                }
3434
            }
3435
            pDb.Purge(oids);
3436

    
3437
            foreach (ObjectId oid in oids)
3438
            {
3439
                if (oid.IsErased) continue;
3440

    
3441
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3442
                {
3443
                    btr.Erase(true);
3444
                }                
3445
            }
3446
        }
3447

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

    
3453
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3454
            {
3455
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3456
                {
3457
                    foreach (ObjectId entid in pBlock)
3458
                    {
3459
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3460
                        {
3461
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3462
                            BlockReference blockRef = (BlockReference)pEnt;
3463

    
3464
                            if (blockRef.Name.ToUpper().StartsWith(BLOCK_PIPING))
3465
                            {
3466
                                oidSet.Add(entid);
3467
                                continue;
3468
                            }
3469
                            else if (blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3470
                            {
3471
                                continue;
3472
                            }
3473
                            
3474
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3475
                            {
3476
                                bool isNestedBlock = false;
3477
                                foreach (ObjectId blkid in pBtr)
3478
                                {
3479
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3480
                                    {
3481
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3482
                                        {
3483
                                            oidSet.Add(entid);
3484
                                            isNestedBlock = true;
3485
                                        }
3486
                                    }
3487
                                }
3488
                                if (!isNestedBlock)
3489
                                {
3490
                                    blockNameList.Add(blockRef.Name);
3491
                                }
3492
                            }
3493
                        }
3494
                    }
3495
                }
3496
            }
3497

    
3498
            if (oidSet.Count > 0)
3499
            {
3500
                explodeBlocks(oidSet);
3501
                blockNameList = explodeNestedBlocks(pDb);
3502
            }
3503

    
3504
            return blockNameList;
3505
        }
3506

    
3507
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3508
        {
3509
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3510

    
3511
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3512
            {
3513
                foreach (ObjectId id in pTable)
3514
                {
3515
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForWrite, false, true))
3516
                    {
3517
                        if (pBlock.IsLayout) continue;
3518
                        pBlock.Explodable = true;
3519
                        if (blockNameList.Contains(pBlock.Name)) continue;
3520

    
3521
                        foreach (ObjectId entid in pBlock)
3522
                        {
3523
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3524
                            {
3525
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3526

    
3527
                                oidSet.Add(entid);
3528
                            }
3529
                        }
3530
                    }
3531
                }
3532
            }
3533

    
3534
            if (oidSet.Count > 0)
3535
            {
3536
                explodeBlocks(oidSet);
3537
                preparePurgeBlocks(pDb, blockNameList);
3538
            }
3539

    
3540
            return;
3541
        }
3542
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3543
        {
3544
            foreach (ObjectId blkId in oidSet)
3545
            {
3546
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3547
                blkRef.ExplodeGeometryToOwnerSpace();
3548
                blkRef.Erase();
3549
            }
3550
        }
3551

    
3552
        /************************************************************************/
3553
        /* Save Block as DWG For Auxiliary Graphic                              */
3554
        /************************************************************************/
3555
        public void ExportGraphicBlocks(Database pDb, string savePath)
3556
        {
3557
            try
3558
            {
3559
                using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3560
                {
3561
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3562
                    {
3563
                        foreach (ObjectId entid in pBlock)
3564
                        {
3565
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3566
                            {
3567
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3568
                                BlockReference blockRef = (BlockReference)pEnt;
3569
                                if (!blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3570
                                    continue;
3571

    
3572
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3573
                                objIdCol.Add(blockRef.ObjectId);
3574
                                if (objIdCol.Count == 0) continue;
3575

    
3576
                                string filePath = string.Format("{0}.dwg", blockRef.Name);
3577
                                string directory = Path.GetDirectoryName(savePath);
3578
                                directory = directory.ToLower().Replace("drawings\native", "graphic");
3579
                                if (!Directory.Exists(directory))
3580
                                {
3581
                                    Directory.CreateDirectory(directory);
3582
                                }
3583
                                filePath = Path.Combine(directory, filePath);
3584
                                
3585
                                using (Database newDb = new Database(true, false))
3586
                                {
3587
                                    pDb.Wblock(newDb, objIdCol, Point3d.Origin, DuplicateRecordCloning.Ignore);
3588
                                    newDb.UpdateExt(true);
3589
                                    newDb.SaveAs(filePath, DwgVersion.Newest);
3590
                                }
3591

    
3592
                                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo();
3593
                                procStartInfo.FileName = @"C:\Program Files (x86)\SmartSketch\Program\Rad2d\bin\Dwg2Igr.exe";
3594
                                procStartInfo.RedirectStandardOutput = true;
3595
                                procStartInfo.RedirectStandardInput = true;
3596
                                procStartInfo.RedirectStandardError = true;
3597
                                procStartInfo.UseShellExecute = false;
3598
                                procStartInfo.CreateNoWindow = false;
3599
                                procStartInfo.Arguments = filePath.Replace(" ", "^");
3600

    
3601
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3602
                                {
3603
                                    proc.StartInfo = procStartInfo;
3604
                                    proc.Start();
3605
                                    proc.StandardInput.Close();
3606
                                    proc.WaitForExit();
3607

    
3608
                                    switch (proc.ExitCode)
3609
                                    {
3610
                                        case -1:
3611
                                            Console.WriteLine("[{0}] path does not exist or there is no file", filePath);
3612
                                            break;
3613
                                        case 0:
3614
                                            Console.WriteLine("[{0}] File conversion error", filePath.Replace(".dwg", ".igr"));
3615
                                            break;
3616
                                        case 1:
3617
                                            Console.WriteLine("[{0}] File conversion success", filePath.Replace(".dwg", ".igr"));
3618
                                            break;
3619
                                        default:
3620
                                            break;
3621
                                    }
3622
                                }
3623
                            }
3624
                        }
3625
                    }
3626
                }
3627
            }
3628
            catch (System.Exception ex)
3629
            {
3630
            }
3631
        }
3632
        /************************************************************************/
3633
        /* Dump the BlockTable                                                  */
3634
        /************************************************************************/
3635
        public void dumpBlocks(Database pDb, int indent, XmlNode node)
3636
        {
3637
            /**********************************************************************/
3638
            /* Get a pointer to the BlockTable                               */
3639
            /**********************************************************************/
3640
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3641
            {
3642
                /**********************************************************************/
3643
                /* Dump the Description                                               */
3644
                /**********************************************************************/
3645
                XmlElement BlocksNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
3646

    
3647
                /**********************************************************************/
3648
                /* Step through the BlockTable                                        */
3649
                /**********************************************************************/
3650
                foreach (ObjectId id in pTable)
3651
                {
3652
                    /********************************************************************/
3653
                    /* Open the BlockTableRecord for Reading                            */
3654
                    /********************************************************************/
3655
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3656
                    {
3657
                        /********************************************************************/
3658
                        /* Dump the BlockTableRecord                                        */
3659
                        /********************************************************************/
3660
                        XmlElement BlockNode = Program.xml.CreateElement(pBlock.GetRXClass().Name);
3661

    
3662
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
3663
                        NameAttr.Value = pBlock.Name;
3664
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3665

    
3666
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3667
                        CommentsAttr.Value = pBlock.Comments;
3668
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3669

    
3670
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3671
                        OriginAttr.Value = pBlock.Origin.ToString();
3672
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3673

    
3674
                        writeLine(indent, pBlock.GetRXClass().Name);
3675
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3676
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3677
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3678
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3679
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3680

    
3681
                        try
3682
                        {
3683
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3684
                            extents.AddBlockExtents(pBlock);
3685

    
3686
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3687
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3688
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3689

    
3690
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3691
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3692
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3693
                        }
3694
                        catch (System.Exception)
3695
                        {
3696
                        }
3697

    
3698
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3699
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3700
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3701
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3702
                        {
3703
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3704
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3705
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3706
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3707
                        }
3708

    
3709
                        /********************************************************************/
3710
                        /* Step through the BlockTableRecord                                */
3711
                        /********************************************************************/
3712
                        foreach (ObjectId entid in pBlock)
3713
                        {
3714
                            /********************************************************************/
3715
                            /* Dump the Entity                                                  */
3716
                            /********************************************************************/
3717
                            dumpEntity(entid, indent + 1, BlockNode);
3718
                        }
3719

    
3720
                        BlocksNode.AppendChild(BlockNode);
3721
                    }
3722
                }
3723

    
3724
                node.AppendChild(BlocksNode);
3725
            }
3726
        }
3727

    
3728
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3729
        {
3730
            /**********************************************************************/
3731
            /* Get a SmartPointer to the DimStyleTable                            */
3732
            /**********************************************************************/
3733
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3734
            {
3735
                /**********************************************************************/
3736
                /* Dump the Description                                               */
3737
                /**********************************************************************/
3738
                writeLine();
3739
                writeLine(indent++, pTable.GetRXClass().Name);
3740

    
3741
                /**********************************************************************/
3742
                /* Step through the DimStyleTable                                    */
3743
                /**********************************************************************/
3744
                foreach (ObjectId id in pTable)
3745
                {
3746
                    /*********************************************************************/
3747
                    /* Open the DimStyleTableRecord for Reading                         */
3748
                    /*********************************************************************/
3749
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3750
                    {
3751
                        /*********************************************************************/
3752
                        /* Dump the DimStyleTableRecord                                      */
3753
                        /*********************************************************************/
3754
                        writeLine();
3755
                        writeLine(indent, pRecord.GetRXClass().Name);
3756
                        writeLine(indent, "Name", pRecord.Name);
3757
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3758

    
3759
                        writeLine(indent, "Background Text Color", pRecord.Dimtfillclr);
3760
                        writeLine(indent, "BackgroundText Flags", pRecord.Dimtfill);
3761
                        writeLine(indent, "Extension Line 1 Linetype", pRecord.Dimltex1);
3762
                        writeLine(indent, "Extension Line 2 Linetype", pRecord.Dimltex2);
3763
                        writeLine(indent, "Dimension Line Linetype", pRecord.Dimltype);
3764
                        writeLine(indent, "Extension Line Fixed Len", pRecord.Dimfxlen);
3765
                        writeLine(indent, "Extension Line Fixed Len Enable", pRecord.DimfxlenOn);
3766
                        writeLine(indent, "Jog Angle", toDegreeString(pRecord.Dimjogang));
3767
                        writeLine(indent, "Modified For Recompute", pRecord.IsModifiedForRecompute);
3768
                        writeLine(indent, "DIMADEC", pRecord.Dimadec);
3769
                        writeLine(indent, "DIMALT", pRecord.Dimalt);
3770
                        writeLine(indent, "DIMALTD", pRecord.Dimaltd);
3771
                        writeLine(indent, "DIMALTF", pRecord.Dimaltf);
3772
                        writeLine(indent, "DIMALTRND", pRecord.Dimaltrnd);
3773
                        writeLine(indent, "DIMALTTD", pRecord.Dimalttd);
3774
                        writeLine(indent, "DIMALTTZ", pRecord.Dimalttz);
3775
                        writeLine(indent, "DIMALTU", pRecord.Dimaltu);
3776
                        writeLine(indent, "DIMALTZ", pRecord.Dimaltz);
3777
                        writeLine(indent, "DIMAPOST", pRecord.Dimapost);
3778
                        writeLine(indent, "DIMASZ", pRecord.Dimasz);
3779
                        writeLine(indent, "DIMATFIT", pRecord.Dimatfit);
3780
                        writeLine(indent, "DIMAUNIT", pRecord.Dimaunit);
3781
                        writeLine(indent, "DIMAZIN", pRecord.Dimazin);
3782
                        writeLine(indent, "DIMBLK", pRecord.Dimblk);
3783
                        writeLine(indent, "DIMBLK1", pRecord.Dimblk1);
3784
                        writeLine(indent, "DIMBLK2", pRecord.Dimblk2);
3785
                        writeLine(indent, "DIMCEN", pRecord.Dimcen);
3786
                        writeLine(indent, "DIMCLRD", pRecord.Dimclrd);
3787
                        writeLine(indent, "DIMCLRE", pRecord.Dimclre);
3788
                        writeLine(indent, "DIMCLRT", pRecord.Dimclrt);
3789
                        writeLine(indent, "DIMDEC", pRecord.Dimdec);
3790
                        writeLine(indent, "DIMDLE", pRecord.Dimdle);
3791
                        writeLine(indent, "DIMDLI", pRecord.Dimdli);
3792
                        writeLine(indent, "DIMDSEP", pRecord.Dimdsep);
3793
                        writeLine(indent, "DIMEXE", pRecord.Dimexe);
3794
                        writeLine(indent, "DIMEXO", pRecord.Dimexo);
3795
                        writeLine(indent, "DIMFRAC", pRecord.Dimfrac);
3796
                        writeLine(indent, "DIMGAP", pRecord.Dimgap);
3797
                        writeLine(indent, "DIMJUST", pRecord.Dimjust);
3798
                        writeLine(indent, "DIMLDRBLK", pRecord.Dimldrblk);
3799
                        writeLine(indent, "DIMLFAC", pRecord.Dimlfac);
3800
                        writeLine(indent, "DIMLIM", pRecord.Dimlim);
3801
                        writeLine(indent, "DIMLUNIT", pRecord.Dimlunit);
3802
                        writeLine(indent, "DIMLWD", pRecord.Dimlwd);
3803
                        writeLine(indent, "DIMLWE", pRecord.Dimlwe);
3804
                        writeLine(indent, "DIMPOST", pRecord.Dimpost);
3805
                        writeLine(indent, "DIMRND", pRecord.Dimrnd);
3806
                        writeLine(indent, "DIMSAH", pRecord.Dimsah);
3807
                        writeLine(indent, "DIMSCALE", pRecord.Dimscale);
3808
                        writeLine(indent, "DIMSD1", pRecord.Dimsd1);
3809
                        writeLine(indent, "DIMSD2", pRecord.Dimsd2);
3810
                        writeLine(indent, "DIMSE1", pRecord.Dimse1);
3811
                        writeLine(indent, "DIMSE2", pRecord.Dimse2);
3812
                        writeLine(indent, "DIMSOXD", pRecord.Dimsoxd);
3813
                        writeLine(indent, "DIMTAD", pRecord.Dimtad);
3814
                        writeLine(indent, "DIMTDEC", pRecord.Dimtdec);
3815
                        writeLine(indent, "DIMTFAC", pRecord.Dimtfac);
3816
                        writeLine(indent, "DIMTIH", pRecord.Dimtih);
3817
                        writeLine(indent, "DIMTIX", pRecord.Dimtix);
3818
                        writeLine(indent, "DIMTM", pRecord.Dimtm);
3819
                        writeLine(indent, "DIMTOFL", pRecord.Dimtofl);
3820
                        writeLine(indent, "DIMTOH", pRecord.Dimtoh);
3821
                        writeLine(indent, "DIMTOL", pRecord.Dimtol);
3822
                        writeLine(indent, "DIMTOLJ", pRecord.Dimtolj);
3823
                        writeLine(indent, "DIMTP", pRecord.Dimtp);
3824
                        writeLine(indent, "DIMTSZ", pRecord.Dimtsz);
3825
                        writeLine(indent, "DIMTVP", pRecord.Dimtvp);
3826
                        writeLine(indent, "DIMTXSTY", pRecord.Dimtxsty);
3827
                        writeLine(indent, "DIMTXT", pRecord.Dimtxt);
3828
                        writeLine(indent, "DIMTZIN", pRecord.Dimtzin);
3829
                        writeLine(indent, "DIMUPT", pRecord.Dimupt);
3830
                        writeLine(indent, "DIMZIN", pRecord.Dimzin);
3831

    
3832
                        dumpSymbolTableRecord(pRecord, indent, node);
3833
                    }
3834
                }
3835
            }
3836
        }
3837

    
3838
        /// <summary>
3839
        /// extract information from entity has given id
3840
        /// </summary>
3841
        /// <param name="id"></param>
3842
        /// <param name="indent"></param>
3843
        /// <param name="node">XmlNode</param>
3844
        public void dumpEntity(ObjectId id, int indent, XmlNode node)
3845
        {
3846
            /**********************************************************************/
3847
            /* Get a pointer to the Entity                                   */
3848
            /**********************************************************************/
3849
            try
3850
            {
3851
                using (Entity pEnt = (Entity)id.Open(OpenMode.ForRead, false, true))
3852
                {
3853
                    /**********************************************************************/
3854
                    /* Dump the entity                                                    */
3855
                    /**********************************************************************/
3856
                    writeLine();
3857
                    // Protocol extensions are not supported in DD.NET (as well as in ARX.NET)
3858
                    // so we just switch by entity type here
3859
                    // (maybe it makes sense to make a map: type -> delegate)
3860
                    switch (pEnt.GetRXClass().Name)
3861
                    {
3862
                        case "AcDbAlignedDimension":
3863
                            dump((AlignedDimension)pEnt, indent, node);
3864
                            break;
3865
                        case "AcDbArc":
3866
                            dump((Arc)pEnt, indent, node);
3867
                            break;
3868
                        case "AcDbArcDimension":
3869
                            dump((ArcDimension)pEnt, indent, node);
3870
                            break;
3871
                        case "AcDbBlockReference":
3872
                            dump((BlockReference)pEnt, indent, node);
3873
                            break;
3874
                        case "AcDbBody":
3875
                            dump((Body)pEnt, indent, node);
3876
                            break;
3877
                        case "AcDbCircle":
3878
                            dump((Circle)pEnt, indent, node);
3879
                            break;
3880
                        case "AcDbPoint":
3881
                            dump((DBPoint)pEnt, indent);
3882
                            break;
3883
                        case "AcDbText":
3884
                            dump((DBText)pEnt, indent, node);
3885
                            break;
3886
                        case "AcDbDiametricDimension":
3887
                            dump((DiametricDimension)pEnt, indent, node);
3888
                            break;
3889
                        case "AcDbViewport":
3890
                            dump((Teigha.DatabaseServices.Viewport)pEnt, indent, node);
3891
                            break;
3892
                        case "AcDbEllipse":
3893
                            dump((Ellipse)pEnt, indent, node);
3894
                            break;
3895
                        case "AcDbFace":
3896
                            dump((Face)pEnt, indent, node);
3897
                            break;
3898
                        case "AcDbFcf":
3899
                            dump((FeatureControlFrame)pEnt, indent);
3900
                            break;
3901
                        case "AcDbHatch":
3902
                            dump((Hatch)pEnt, indent);
3903
                            break;
3904
                        case "AcDbLeader":
3905
                            dump((Leader)pEnt, indent);
3906
                            break;
3907
                        case "AcDbLine":
3908
                            dump((Line)pEnt, indent, node);
3909
                            break;
3910
                        case "AcDb2LineAngularDimension":
3911
                            dump((LineAngularDimension2)pEnt, indent, node);
3912
                            break;
3913
                        case "AcDbMInsertBlock":
3914
                            dump((MInsertBlock)pEnt, indent, node);
3915
                            break;
3916
                        case "AcDbMline":
3917
                            dump((Mline)pEnt, indent);
3918
                            break;
3919
                        case "AcDbMText":
3920
                            dump((MText)pEnt, indent, node);
3921
                            break;
3922
                        case "AcDbOle2Frame":
3923
                            dump((Ole2Frame)pEnt, indent);
3924
                            break;
3925
                        case "AcDbOrdinateDimension":
3926
                            dump((OrdinateDimension)pEnt, indent, node);
3927
                            break;
3928
                        case "AcDb3PointAngularDimension":
3929
                            dump((Point3AngularDimension)pEnt, indent, node);
3930
                            break;
3931
                        case "AcDbPolyFaceMesh":
3932
                            dump((PolyFaceMesh)pEnt, indent, node);
3933
                            break;
3934
                        case "AcDbPolygonMesh":
3935
                            dump((PolygonMesh)pEnt, indent);
3936
                            break;
3937
                        case "AcDbPolyline":
3938
                            dump((Teigha.DatabaseServices.Polyline)pEnt, indent, node);
3939
                            break;
3940
                        case "AcDb2dPolyline":
3941
                            dump((Polyline2d)pEnt, indent, node);
3942
                            break;
3943
                        case "AcDb3dPolyline":
3944
                            dump((Polyline3d)pEnt, indent, node);
3945
                            break;
3946
                        case "AcDbProxyEntity":
3947
                            dump((ProxyEntity)pEnt, indent, node);
3948
                            break;
3949
                        case "AcDbRadialDimension":
3950
                            dump((RadialDimension)pEnt, indent, node);
3951
                            break;
3952
                        case "AcDbRasterImage":
3953
                            dump((RasterImage)pEnt, indent);
3954
                            break;
3955
                        case "AcDbRay":
3956
                            dump((Ray)pEnt, indent);
3957
                            break;
3958
                        case "AcDbRegion":
3959
                            dump((Region)pEnt, indent);
3960
                            break;
3961
                        case "AcDbRotatedDimension":
3962
                            dump((RotatedDimension)pEnt, indent, node);
3963
                            break;
3964
                        case "AcDbShape":
3965
                            dump((Shape)pEnt, indent);
3966
                            break;
3967
                        case "AcDb3dSolid":
3968
                            dump((Solid3d)pEnt, indent, node);
3969
                            break;
3970
                        case "AcDbSpline":
3971
                            dump((Spline)pEnt, indent);
3972
                            break;
3973
                        case "AcDbTable":
3974
                            dump((Table)pEnt, indent);
3975
                            break;
3976
                        case "AcDbTrace":
3977
                            dump((Trace)pEnt, indent);
3978
                            break;
3979
                        case "AcDbWipeout":
3980
                            dump((Wipeout)pEnt, indent);
3981
                            break;
3982
                        case "AcDbXline":
3983
                            dump((Xline)pEnt, indent);
3984
                            break;
3985
                        case "AcDbPdfReference":
3986
                        case "AcDbDwfReference":
3987
                        case "AcDbDgnReference":
3988
                            dump((UnderlayReference)pEnt, indent);
3989
                            break;
3990
                        default:
3991
                            dump(pEnt, indent, node);
3992
                            break;
3993
                    }
3994
                    /* Dump the Xdata                                                     */
3995
                    /**********************************************************************/
3996
                    dumpXdata(pEnt.XData, indent);
3997

    
3998
                    /**********************************************************************/
3999
                    /* Dump the Extension Dictionary                                      */
4000
                    /**********************************************************************/
4001
                    if (!pEnt.ExtensionDictionary.IsNull)
4002
                    {
4003
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
4004
                    }
4005
                }
4006
            }
4007
            catch (System.Exception ex)
4008
            {
4009
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
4010
            }
4011
        }
4012
        public void dumpHeader(Database pDb, int indent, XmlNode node)
4013
        {
4014
            if (node != null)
4015
            {
4016
                XmlAttribute FileNameAttr = Program.xml.CreateAttribute("FileName");
4017
                FileNameAttr.Value = shortenPath(pDb.Filename);
4018
                node.Attributes.SetNamedItem(FileNameAttr);
4019

    
4020
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
4021
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4022
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4023

    
4024
                writeLine();
4025
                writeLine(indent++, "Header Variables:");
4026

    
4027
                //writeLine();
4028
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4029
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4030

    
4031
                writeLine();
4032
                writeLine(indent, "ANGBASE", pDb.Angbase);
4033
                writeLine(indent, "ANGDIR", pDb.Angdir);
4034
                writeLine(indent, "ATTMODE", pDb.Attmode);
4035
                writeLine(indent, "AUNITS", pDb.Aunits);
4036
                writeLine(indent, "AUPREC", pDb.Auprec);
4037
                writeLine(indent, "CECOLOR", pDb.Cecolor);
4038
                writeLine(indent, "CELTSCALE", pDb.Celtscale);
4039
                writeLine(indent, "CHAMFERA", pDb.Chamfera);
4040
                writeLine(indent, "CHAMFERB", pDb.Chamferb);
4041
                writeLine(indent, "CHAMFERC", pDb.Chamferc);
4042
                writeLine(indent, "CHAMFERD", pDb.Chamferd);
4043
                writeLine(indent, "CMLJUST", pDb.Cmljust);
4044
                writeLine(indent, "CMLSCALE", pDb.Cmljust);
4045
                writeLine(indent, "DIMADEC", pDb.Dimadec);
4046
                writeLine(indent, "DIMALT", pDb.Dimalt);
4047
                writeLine(indent, "DIMALTD", pDb.Dimaltd);
4048
                writeLine(indent, "DIMALTF", pDb.Dimaltf);
4049
                writeLine(indent, "DIMALTRND", pDb.Dimaltrnd);
4050
                writeLine(indent, "DIMALTTD", pDb.Dimalttd);
4051
                writeLine(indent, "DIMALTTZ", pDb.Dimalttz);
4052
                writeLine(indent, "DIMALTU", pDb.Dimaltu);
4053
                writeLine(indent, "DIMALTZ", pDb.Dimaltz);
4054
                writeLine(indent, "DIMAPOST", pDb.Dimapost);
4055
                writeLine(indent, "DIMASZ", pDb.Dimasz);
4056
                writeLine(indent, "DIMATFIT", pDb.Dimatfit);
4057
                writeLine(indent, "DIMAUNIT", pDb.Dimaunit);
4058
                writeLine(indent, "DIMAZIN", pDb.Dimazin);
4059
                writeLine(indent, "DIMBLK", pDb.Dimblk);
4060
                writeLine(indent, "DIMBLK1", pDb.Dimblk1);
4061
                writeLine(indent, "DIMBLK2", pDb.Dimblk2);
4062
                writeLine(indent, "DIMCEN", pDb.Dimcen);
4063
                writeLine(indent, "DIMCLRD", pDb.Dimclrd);
4064
                writeLine(indent, "DIMCLRE", pDb.Dimclre);
4065
                writeLine(indent, "DIMCLRT", pDb.Dimclrt);
4066
                writeLine(indent, "DIMDEC", pDb.Dimdec);
4067
                writeLine(indent, "DIMDLE", pDb.Dimdle);
4068
                writeLine(indent, "DIMDLI", pDb.Dimdli);
4069
                writeLine(indent, "DIMDSEP", pDb.Dimdsep);
4070
                writeLine(indent, "DIMEXE", pDb.Dimexe);
4071
                writeLine(indent, "DIMEXO", pDb.Dimexo);
4072
                writeLine(indent, "DIMFRAC", pDb.Dimfrac);
4073
                writeLine(indent, "DIMGAP", pDb.Dimgap);
4074
                writeLine(indent, "DIMJUST", pDb.Dimjust);
4075
                writeLine(indent, "DIMLDRBLK", pDb.Dimldrblk);
4076
                writeLine(indent, "DIMLFAC", pDb.Dimlfac);
4077
                writeLine(indent, "DIMLIM", pDb.Dimlim);
4078
                writeLine(indent, "DIMLUNIT", pDb.Dimlunit);
4079
                writeLine(indent, "DIMLWD", pDb.Dimlwd);
4080
                writeLine(indent, "DIMLWE", pDb.Dimlwe);
4081
                writeLine(indent, "DIMPOST", pDb.Dimpost);
4082
                writeLine(indent, "DIMRND", pDb.Dimrnd);
4083
                writeLine(indent, "DIMSAH", pDb.Dimsah);
4084
                writeLine(indent, "DIMSCALE", pDb.Dimscale);
4085
                writeLine(indent, "DIMSD1", pDb.Dimsd1);
4086
                writeLine(indent, "DIMSD2", pDb.Dimsd2);
4087
                writeLine(indent, "DIMSE1", pDb.Dimse1);
4088
                writeLine(indent, "DIMSE2", pDb.Dimse2);
4089
                writeLine(indent, "DIMSOXD", pDb.Dimsoxd);
4090
                writeLine(indent, "DIMTAD", pDb.Dimtad);
4091
                writeLine(indent, "DIMTDEC", pDb.Dimtdec);
4092
                writeLine(indent, "DIMTFAC", pDb.Dimtfac);
4093
                writeLine(indent, "DIMTIH", pDb.Dimtih);
4094
                writeLine(indent, "DIMTIX", pDb.Dimtix);
4095
                writeLine(indent, "DIMTM", pDb.Dimtm);
4096
                writeLine(indent, "DIMTOFL", pDb.Dimtofl);
4097
                writeLine(indent, "DIMTOH", pDb.Dimtoh);
4098
                writeLine(indent, "DIMTOL", pDb.Dimtol);
4099
                writeLine(indent, "DIMTOLJ", pDb.Dimtolj);
4100
                writeLine(indent, "DIMTP", pDb.Dimtp);
4101
                writeLine(indent, "DIMTSZ", pDb.Dimtsz);
4102
                writeLine(indent, "DIMTVP", pDb.Dimtvp);
4103
                writeLine(indent, "DIMTXSTY", pDb.Dimtxsty);
4104
                writeLine(indent, "DIMTXT", pDb.Dimtxt);
4105
                writeLine(indent, "DIMTZIN", pDb.Dimtzin);
4106
                writeLine(indent, "DIMUPT", pDb.Dimupt);
4107
                writeLine(indent, "DIMZIN", pDb.Dimzin);
4108
                writeLine(indent, "DISPSILH", pDb.DispSilh);
4109
                writeLine(indent, "DRAWORDERCTL", pDb.DrawOrderCtl);
4110
                writeLine(indent, "ELEVATION", pDb.Elevation);
4111
                writeLine(indent, "EXTMAX", pDb.Extmax);
4112
                writeLine(indent, "EXTMIN", pDb.Extmin);
4113
                writeLine(indent, "FACETRES", pDb.Facetres);
4114
                writeLine(indent, "FILLETRAD", pDb.Filletrad);
4115
                writeLine(indent, "FILLMODE", pDb.Fillmode);
4116
                writeLine(indent, "INSBASE", pDb.Insbase);
4117
                writeLine(indent, "ISOLINES", pDb.Isolines);
4118
                writeLine(indent, "LIMCHECK", pDb.Limcheck);
4119
                writeLine(indent, "LIMMAX", pDb.Limmax);
4120
                writeLine(indent, "LIMMIN", pDb.Limmin);
4121
                writeLine(indent, "LTSCALE", pDb.Ltscale);
4122
                writeLine(indent, "LUNITS", pDb.Lunits);
4123
                writeLine(indent, "LUPREC", pDb.Luprec);
4124
                writeLine(indent, "MAXACTVP", pDb.Maxactvp);
4125
                writeLine(indent, "MIRRTEXT", pDb.Mirrtext);
4126
                writeLine(indent, "ORTHOMODE", pDb.Orthomode);
4127
                writeLine(indent, "PDMODE", pDb.Pdmode);
4128
                writeLine(indent, "PDSIZE", pDb.Pdsize);
4129
                writeLine(indent, "PELEVATION", pDb.Pelevation);
4130
                writeLine(indent, "PELLIPSE", pDb.PlineEllipse);
4131
                writeLine(indent, "PEXTMAX", pDb.Pextmax);
4132
                writeLine(indent, "PEXTMIN", pDb.Pextmin);
4133
                writeLine(indent, "PINSBASE", pDb.Pinsbase);
4134
                writeLine(indent, "PLIMCHECK", pDb.Plimcheck);
4135
                writeLine(indent, "PLIMMAX", pDb.Plimmax);
4136
                writeLine(indent, "PLIMMIN", pDb.Plimmin);
4137
                writeLine(indent, "PLINEGEN", pDb.Plinegen);
4138
                writeLine(indent, "PLINEWID", pDb.Plinewid);
4139
                writeLine(indent, "PROXYGRAPHICS", pDb.Saveproxygraphics);
4140
                writeLine(indent, "PSLTSCALE", pDb.Psltscale);
4141
                writeLine(indent, "PUCSNAME", pDb.Pucsname);
4142
                writeLine(indent, "PUCSORG", pDb.Pucsorg);
4143
                writeLine(indent, "PUCSXDIR", pDb.Pucsxdir);
4144
                writeLine(indent, "PUCSYDIR", pDb.Pucsydir);
4145
                writeLine(indent, "QTEXTMODE", pDb.Qtextmode);
4146
                writeLine(indent, "REGENMODE", pDb.Regenmode);
4147
                writeLine(indent, "SHADEDGE", pDb.Shadedge);
4148
                writeLine(indent, "SHADEDIF", pDb.Shadedif);
4149
                writeLine(indent, "SKETCHINC", pDb.Sketchinc);
4150
                writeLine(indent, "SKPOLY", pDb.Skpoly);
4151
                writeLine(indent, "SPLFRAME", pDb.Splframe);
4152
                writeLine(indent, "SPLINESEGS", pDb.Splinesegs);
4153
                writeLine(indent, "SPLINETYPE", pDb.Splinetype);
4154
                writeLine(indent, "SURFTAB1", pDb.Surftab1);
4155
                writeLine(indent, "SURFTAB2", pDb.Surftab2);
4156
                writeLine(indent, "SURFTYPE", pDb.Surftype);
4157
                writeLine(indent, "SURFU", pDb.Surfu);
4158
                writeLine(indent, "SURFV", pDb.Surfv);
4159
                //writeLine(indent, "TEXTQLTY", pDb.TEXTQLTY);
4160
                writeLine(indent, "TEXTSIZE", pDb.Textsize);
4161
                writeLine(indent, "THICKNESS", pDb.Thickness);
4162
                writeLine(indent, "TILEMODE", pDb.TileMode);
4163
                writeLine(indent, "TRACEWID", pDb.Tracewid);
4164
                writeLine(indent, "TREEDEPTH", pDb.Treedepth);
4165
                writeLine(indent, "UCSNAME", pDb.Ucsname);
4166
                writeLine(indent, "UCSORG", pDb.Ucsorg);
4167
                writeLine(indent, "UCSXDIR", pDb.Ucsxdir);
4168
                writeLine(indent, "UCSYDIR", pDb.Ucsydir);
4169
                writeLine(indent, "UNITMODE", pDb.Unitmode);
4170
                writeLine(indent, "USERI1", pDb.Useri1);
4171
                writeLine(indent, "USERI2", pDb.Useri2);
4172
                writeLine(indent, "USERI3", pDb.Useri3);
4173
                writeLine(indent, "USERI4", pDb.Useri4);
4174
                writeLine(indent, "USERI5", pDb.Useri5);
4175
                writeLine(indent, "USERR1", pDb.Userr1);
4176
                writeLine(indent, "USERR2", pDb.Userr2);
4177
                writeLine(indent, "USERR3", pDb.Userr3);
4178
                writeLine(indent, "USERR4", pDb.Userr4);
4179
                writeLine(indent, "USERR5", pDb.Userr5);
4180
                writeLine(indent, "USRTIMER", pDb.Usrtimer);
4181
                writeLine(indent, "VISRETAIN", pDb.Visretain);
4182
                writeLine(indent, "WORLDVIEW", pDb.Worldview);
4183
            }
4184
        }
4185

    
4186
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4187
        {
4188
            if (node != null)
4189
            {
4190
                /**********************************************************************/
4191
                /* Get a SmartPointer to the LayerTable                               */
4192
                /**********************************************************************/
4193
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4194
                {
4195
                    /**********************************************************************/
4196
                    /* Dump the Description                                               */
4197
                    /**********************************************************************/
4198
                    XmlElement LayerNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4199

    
4200
                    /**********************************************************************/
4201
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4202
                    /**********************************************************************/
4203

    
4204
                    /**********************************************************************/
4205
                    /* Step through the LayerTable                                        */
4206
                    /**********************************************************************/
4207
                    foreach (ObjectId id in pTable)
4208
                    {
4209
                        /********************************************************************/
4210
                        /* Open the LayerTableRecord for Reading                            */
4211
                        /********************************************************************/
4212
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4213
                        {
4214
                            /********************************************************************/
4215
                            /* Dump the LayerTableRecord                                        */
4216
                            /********************************************************************/
4217
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4218

    
4219
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4220
                            NameAttr.Value = pRecord.Name.ToString();
4221
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4222

    
4223
                            XmlAttribute IsUsedAttr = Program.xml.CreateAttribute("IsUsed");
4224
                            IsUsedAttr.Value = pRecord.IsUsed.ToString();
4225
                            RecordNode.Attributes.SetNamedItem(IsUsedAttr);
4226

    
4227
                            XmlAttribute IsOffAttr = Program.xml.CreateAttribute("IsOff");
4228
                            IsOffAttr.Value = pRecord.IsOff.ToString();
4229
                            RecordNode.Attributes.SetNamedItem(IsOffAttr);
4230

    
4231
                            XmlAttribute IsFrozenAttr = Program.xml.CreateAttribute("IsFrozen");
4232
                            IsFrozenAttr.Value = pRecord.IsFrozen.ToString();
4233
                            RecordNode.Attributes.SetNamedItem(IsFrozenAttr);
4234

    
4235
                            XmlAttribute IsLockedAttr = Program.xml.CreateAttribute("IsLocked");
4236
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4237
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4238

    
4239
                            XmlAttribute ColorAttr = Program.xml.CreateAttribute("Color");
4240
                            ColorAttr.Value = pRecord.Color.ToString();
4241
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4242

    
4243
                            XmlAttribute LinetypeObjectIdAttr = Program.xml.CreateAttribute("LinetypeObjectId");
4244
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4245
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4246

    
4247
                            XmlAttribute LineWeightAttr = Program.xml.CreateAttribute("LineWeight");
4248
                            LineWeightAttr.Value = pRecord.LineWeight.ToString();
4249
                            RecordNode.Attributes.SetNamedItem(LineWeightAttr);
4250

    
4251
                            XmlAttribute PlotStyleNameAttr = Program.xml.CreateAttribute("PlotStyleName");
4252
                            PlotStyleNameAttr.Value = pRecord.PlotStyleName.ToString();
4253
                            RecordNode.Attributes.SetNamedItem(PlotStyleNameAttr);
4254

    
4255
                            XmlAttribute IsPlottableAttr = Program.xml.CreateAttribute("IsPlottable");
4256
                            IsPlottableAttr.Value = pRecord.IsPlottable.ToString();
4257
                            RecordNode.Attributes.SetNamedItem(IsPlottableAttr);
4258

    
4259
                            XmlAttribute ViewportVisibilityDefaultAttr = Program.xml.CreateAttribute("ViewportVisibilityDefault");
4260
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4261
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4262

    
4263
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4264
                            LayerNode.AppendChild(RecordNode);
4265
                        }
4266
                    }
4267

    
4268
                    node.AppendChild(LayerNode);
4269
                }
4270
            }
4271
        }
4272

    
4273
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4274
        {
4275
            if (node != null)
4276
            {
4277
                /**********************************************************************/
4278
                /* Get a pointer to the LinetypeTable                            */
4279
                /**********************************************************************/
4280
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4281
                {
4282
                    XmlElement LinetypeNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4283

    
4284
                    /**********************************************************************/
4285
                    /* Step through the LinetypeTable                                     */
4286
                    /**********************************************************************/
4287
                    foreach (ObjectId id in pTable)
4288
                    {
4289
                        /*********************************************************************/
4290
                        /* Open the LinetypeTableRecord for Reading                          */
4291
                        /*********************************************************************/
4292
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4293
                        {
4294
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4295

    
4296
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4297
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4298
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4299

    
4300
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4301
                            NameAttr.Value = pRecord.Name;
4302
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4303

    
4304
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4305
                            CommentsAttr.Value = pRecord.Comments;
4306
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4307

    
4308
                            /********************************************************************/
4309
                            /* Dump the first line of record as in ACAD.LIN                     */
4310
                            /********************************************************************/
4311
                            string buffer = "*" + pRecord.Name;
4312
                            if (pRecord.Comments != "")
4313
                            {
4314
                                buffer = buffer + "," + pRecord.Comments;
4315
                            }
4316
                            writeLine(indent, buffer);
4317

    
4318
                            /********************************************************************/
4319
                            /* Dump the second line of record as in ACAD.LIN                    */
4320
                            /********************************************************************/
4321
                            if (pRecord.NumDashes > 0)
4322
                            {
4323
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4324
                                for (int i = 0; i < pRecord.NumDashes; i++)
4325
                                {
4326
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4327
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4328
                                    string text = pRecord.TextAt(i);
4329

    
4330
                                    /**************************************************************/
4331
                                    /* Dump the Complex Line                                      */
4332
                                    /**************************************************************/
4333
                                    if (shapeNumber != 0 || text != "")
4334
                                    {
4335
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4336
                                        {
4337
                                            if (shapeNumber != 0)
4338
                                            {
4339
                                                buffer = buffer + ",[" + shapeNumber + ",";
4340
                                                if (pTextStyle != null)
4341
                                                    buffer = buffer + pTextStyle.FileName;
4342
                                                else
4343
                                                    buffer = buffer + "NULL style";
4344
                                            }
4345
                                            else
4346
                                            {
4347
                                                buffer = buffer + ",[" + text + ",";
4348
                                                if (pTextStyle != null)
4349
                                                    buffer = buffer + pTextStyle.Name;
4350
                                                else
4351
                                                    buffer = buffer + "NULL style";
4352
                                            }
4353
                                        }
4354

    
4355
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4356
                                        {
4357
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4358
                                        }
4359
                                        if (pRecord.ShapeRotationAt(i) != 0)
4360
                                        {
4361
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4362
                                        }
4363
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4364
                                        {
4365
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4366
                                        }
4367
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4368
                                        {
4369
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4370
                                        }
4371
                                        buffer = buffer + "]";
4372
                                    }
4373
                                }
4374
                                writeLine(indent, buffer);
4375
                            }
4376
                            dumpSymbolTableRecord(pRecord, indent, node);
4377
                            LinetypeNode.AppendChild(RecordNode);
4378
                        }
4379
                    }
4380

    
4381
                    node.AppendChild(LinetypeNode);
4382
                }
4383
            }
4384
        }
4385

    
4386
        public void dumpRegApps(Database pDb, int indent)
4387
        {
4388
            /**********************************************************************/
4389
            /* Get a pointer to the RegAppTable                            */
4390
            /**********************************************************************/
4391
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4392
            {
4393
                /**********************************************************************/
4394
                /* Dump the Description                                               */
4395
                /**********************************************************************/
4396
                writeLine();
4397
                writeLine(indent++, pTable.GetRXClass().Name);
4398

    
4399
                /**********************************************************************/
4400
                /* Step through the RegAppTable                                    */
4401
                /**********************************************************************/
4402
                foreach (ObjectId id in pTable)
4403
                {
4404
                    /*********************************************************************/
4405
                    /* Open the RegAppTableRecord for Reading                         */
4406
                    /*********************************************************************/
4407
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4408
                    {
4409
                        /*********************************************************************/
4410
                        /* Dump the RegAppTableRecord                                      */
4411
                        /*********************************************************************/
4412
                        writeLine();
4413
                        writeLine(indent, pRecord.GetRXClass().Name);
4414
                        writeLine(indent, "Name", pRecord.Name);
4415
                    }
4416
                }
4417
            }
4418
        }
4419

    
4420
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4421
        {
4422
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4423
            if (pRecord.IsDependent)
4424
            {
4425
                writeLine(indent, "Resolved", pRecord.IsResolved);
4426
            }
4427
        }
4428

    
4429
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4430
        {
4431
            /**********************************************************************/
4432
            /* Get a SmartPointer to the TextStyleTable                            */
4433
            /**********************************************************************/
4434
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4435
            {
4436
                /**********************************************************************/
4437
                /* Dump the Description                                               */
4438
                /**********************************************************************/
4439
                writeLine();
4440
                writeLine(indent++, pTable.GetRXClass().Name);
4441

    
4442
                /**********************************************************************/
4443
                /* Step through the TextStyleTable                                    */
4444
                /**********************************************************************/
4445
                foreach (ObjectId id in pTable)
4446
                {
4447
                    /*********************************************************************/
4448
                    /* Open the TextStyleTableRecord for Reading                         */
4449
                    /*********************************************************************/
4450
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4451
                    {
4452
                        /*********************************************************************/
4453
                        /* Dump the TextStyleTableRecord                                      */
4454
                        /*********************************************************************/
4455
                        writeLine();
4456
                        writeLine(indent, pRecord.GetRXClass().Name);
4457
                        writeLine(indent, "Name", pRecord.Name);
4458
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4459
                        writeLine(indent, "Text Height", pRecord.TextSize);
4460
                        writeLine(indent, "Width Factor", pRecord.XScale);
4461
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4462
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4463
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4464
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4465
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4466
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4467

    
4468
                        FontDescriptor fd = pRecord.Font;
4469
                        writeLine(indent, "Typeface", fd.TypeFace);
4470
                        writeLine(indent, "Character Set", fd.CharacterSet);
4471
                        writeLine(indent, "Bold", fd.Bold);
4472
                        writeLine(indent, "Italic", fd.Italic);
4473
                        writeLine(indent, "Font Pitch & Family", toHexString(fd.PitchAndFamily));
4474
                        dumpSymbolTableRecord(pRecord, indent, node);
4475
                    }
4476
                }
4477
            }
4478
        }
4479
        public void dumpAbstractViewTableRecord(AbstractViewTableRecord pView, int indent, XmlNode node)
4480
        {
4481
            /*********************************************************************/
4482
            /* Dump the AbstractViewTableRecord                                  */
4483
            /*********************************************************************/
4484
            writeLine(indent, "Back Clip Dist", pView.BackClipDistance);
4485
            writeLine(indent, "Back Clip Enabled", pView.BackClipEnabled);
4486
            writeLine(indent, "Front Clip Dist", pView.FrontClipDistance);
4487
            writeLine(indent, "Front Clip Enabled", pView.FrontClipEnabled);
4488
            writeLine(indent, "Front Clip at Eye", pView.FrontClipAtEye);
4489
            writeLine(indent, "Elevation", pView.Elevation);
4490
            writeLine(indent, "Height", pView.Height);
4491
            writeLine(indent, "Width", pView.Width);
4492
            writeLine(indent, "Lens Length", pView.LensLength);
4493
            writeLine(indent, "Render Mode", pView.RenderMode);
4494
            writeLine(indent, "Perspective", pView.PerspectiveEnabled);
4495
            writeLine(indent, "UCS Name", pView.UcsName);
4496

    
4497
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4498
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4499

    
4500
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4501
            {
4502
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4503
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4504
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4505
            }
4506

    
4507
            writeLine(indent, "Target", pView.Target);
4508
            writeLine(indent, "View Direction", pView.ViewDirection);
4509
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4510
            dumpSymbolTableRecord(pView, indent, node);
4511
        }
4512
        public void dumpDimAssoc(DBObject pObject, int indent)
4513
        {
4514

    
4515
        }
4516
        public void dumpMLineStyles(Database pDb, int indent)
4517
        {
4518
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4519
            {
4520
                /**********************************************************************/
4521
                /* Dump the Description                                               */
4522
                /**********************************************************************/
4523
                writeLine();
4524
                writeLine(indent++, pDictionary.GetRXClass().Name);
4525

    
4526
                /**********************************************************************/
4527
                /* Step through the MlineStyle dictionary                             */
4528
                /**********************************************************************/
4529
                DbDictionaryEnumerator e = pDictionary.GetEnumerator();
4530
                while (e.MoveNext())
4531
                {
4532
                    try
4533
                    {
4534
                        using (MlineStyle pEntry = (MlineStyle)e.Value.Open(OpenMode.ForRead))
4535
                        {
4536
                            /*********************************************************************/
4537
                            /* Dump the MLineStyle dictionary entry                              */
4538
                            /*********************************************************************/
4539
                            writeLine();
4540
                            writeLine(indent, pEntry.GetRXClass().Name);
4541
                            writeLine(indent, "Name", pEntry.Name);
4542
                            writeLine(indent, "Description", pEntry.Description);
4543
                            writeLine(indent, "Start Angle", toDegreeString(pEntry.StartAngle));
4544
                            writeLine(indent, "End Angle", toDegreeString(pEntry.EndAngle));
4545
                            writeLine(indent, "Start Inner Arcs", pEntry.StartInnerArcs);
4546
                            writeLine(indent, "End Inner Arcs", pEntry.EndInnerArcs);
4547
                            writeLine(indent, "Start Round Cap", pEntry.StartRoundCap);
4548
                            writeLine(indent, "End Round Cap", pEntry.EndRoundCap);
4549
                            writeLine(indent, "Start Square Cap", pEntry.StartRoundCap);
4550
                            writeLine(indent, "End Square Cap", pEntry.EndRoundCap);
4551
                            writeLine(indent, "Show Miters", pEntry.ShowMiters);
4552
                            /*********************************************************************/
4553
                            /* Dump the elements                                                 */
4554
                            /*********************************************************************/
4555
                            if (pEntry.Elements.Count > 0)
4556
                            {
4557
                                writeLine(indent, "Elements:");
4558
                            }
4559
                            int i = 0;
4560
                            foreach (MlineStyleElement el in pEntry.Elements)
4561
                            {
4562
                                writeLine(indent, "Index", (i++));
4563
                                writeLine(indent + 1, "Offset", el.Offset);
4564
                                writeLine(indent + 1, "Color", el.Color);
4565
                                writeLine(indent + 1, "Linetype", el.LinetypeId);
4566
                            }
4567
                        }
4568
                    }
4569
                    catch (System.Exception)
4570
                    {
4571
                    }
4572
                }
4573
            }
4574
        }
4575
        public void dumpObject(ObjectId id, string itemName, int indent)
4576
        {
4577
            using (DBObject pObject = id.Open(OpenMode.ForRead))
4578
            {
4579
                /**********************************************************************/
4580
                /* Dump the item name and class name                                  */
4581
                /**********************************************************************/
4582
                if (pObject is DBDictionary)
4583
                {
4584
                    writeLine();
4585
                }
4586
                writeLine(indent++, itemName, pObject.GetRXClass().Name);
4587

    
4588
                /**********************************************************************/
4589
                /* Dispatch                                                           */
4590
                /**********************************************************************/
4591
                if (pObject is DBDictionary)
4592
                {
4593
                    /********************************************************************/
4594
                    /* Dump the dictionary                                               */
4595
                    /********************************************************************/
4596
                    DBDictionary pDic = (DBDictionary)pObject;
4597

    
4598
                    /********************************************************************/
4599
                    /* Get a pointer to a new DictionaryIterator                   */
4600
                    /********************************************************************/
4601
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4602

    
4603
                    /********************************************************************/
4604
                    /* Step through the Dictionary                                      */
4605
                    /********************************************************************/
4606
                    while (pIter.MoveNext())
4607
                    {
4608
                        /******************************************************************/
4609
                        /* Dump the Dictionary object                                     */
4610
                        /******************************************************************/
4611
                        dumpObject(pIter.Value, pIter.Key, indent);
4612
                    }
4613
                }
4614
                else if (pObject is Xrecord)
4615
                {
4616
                    /********************************************************************/
4617
                    /* Dump an Xrecord                                                  */
4618
                    /********************************************************************/
4619
                    Xrecord pXRec = (Xrecord)pObject;
4620
                    dumpXdata(pXRec.Data, indent);
4621
                }
4622
            }
4623
        }
4624

    
4625
        public void dumpUCSTable(Database pDb, int indent, XmlNode node)
4626
        {
4627
            /**********************************************************************/
4628
            /* Get a pointer to the UCSTable                               */
4629
            /**********************************************************************/
4630
            using (UcsTable pTable = (UcsTable)pDb.UcsTableId.Open(OpenMode.ForRead))
4631
            {
4632
                /**********************************************************************/
4633
                /* Dump the Description                                               */
4634
                /**********************************************************************/
4635
                writeLine();
4636
                writeLine(indent++, pTable.GetRXClass().Name);
4637

    
4638
                /**********************************************************************/
4639
                /* Step through the UCSTable                                          */
4640
                /**********************************************************************/
4641
                foreach (ObjectId id in pTable)
4642
                {
4643
                    /********************************************************************/
4644
                    /* Open the UCSTableRecord for Reading                            */
4645
                    /********************************************************************/
4646
                    using (UcsTableRecord pRecord = (UcsTableRecord)id.Open(OpenMode.ForRead))
4647
                    {
4648
                        /********************************************************************/
4649
                        /* Dump the UCSTableRecord                                        */
4650
                        /********************************************************************/
4651
                        writeLine();
4652
                        writeLine(indent, pRecord.GetRXClass().Name);
4653
                        writeLine(indent, "Name", pRecord.Name);
4654
                        writeLine(indent, "UCS Origin", pRecord.Origin);
4655
                        writeLine(indent, "UCS x-Axis", pRecord.XAxis);
4656
                        writeLine(indent, "UCS y-Axis", pRecord.YAxis);
4657
                        dumpSymbolTableRecord(pRecord, indent, node);
4658
                    }
4659
                }
4660
            }
4661
        }
4662
        public void dumpViewports(Database pDb, int indent, XmlNode node)
4663
        {
4664
            /**********************************************************************/
4665
            /* Get a pointer to the ViewportTable                            */
4666
            /**********************************************************************/
4667
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4668
            {
4669
                /**********************************************************************/
4670
                /* Dump the Description                                               */
4671
                /**********************************************************************/
4672
                writeLine();
4673
                writeLine(indent++, pTable.GetRXClass().Name);
4674

    
4675
                /**********************************************************************/
4676
                /* Step through the ViewportTable                                    */
4677
                /**********************************************************************/
4678
                foreach (ObjectId id in pTable)
4679
                {
4680
                    /*********************************************************************/
4681
                    /* Open the ViewportTableRecord for Reading                          */
4682
                    /*********************************************************************/
4683
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4684
                    {
4685
                        /*********************************************************************/
4686
                        /* Dump the ViewportTableRecord                                      */
4687
                        /*********************************************************************/
4688
                        writeLine();
4689
                        writeLine(indent, pRecord.GetRXClass().Name);
4690
                        writeLine(indent, "Name", pRecord.Name);
4691
                        writeLine(indent, "Circle Sides", pRecord.CircleSides);
4692
                        writeLine(indent, "Fast Zooms Enabled", pRecord.FastZoomsEnabled);
4693
                        writeLine(indent, "Grid Enabled", pRecord.GridEnabled);
4694
                        writeLine(indent, "Grid Increments", pRecord.GridIncrements);
4695
                        writeLine(indent, "Icon at Origin", pRecord.IconAtOrigin);
4696
                        writeLine(indent, "Icon Enabled", pRecord.IconEnabled);
4697
                        writeLine(indent, "Iso snap Enabled", pRecord.IsometricSnapEnabled);
4698
                        writeLine(indent, "Iso Snap Pair", pRecord.SnapPair);
4699
                        writeLine(indent, "UCS Saved w/Vport", pRecord.UcsSavedWithViewport);
4700
                        writeLine(indent, "UCS follow", pRecord.UcsFollowMode);
4701
                        writeLine(indent, "Lower-Left Corner", pRecord.LowerLeftCorner);
4702
                        writeLine(indent, "Upper-Right Corner", pRecord.UpperRightCorner);
4703
                        writeLine(indent, "Snap Angle", toDegreeString(pRecord.SnapAngle));
4704
                        writeLine(indent, "Snap Base", pRecord.SnapBase);
4705
                        writeLine(indent, "Snap Enabled", pRecord.SnapEnabled);
4706
                        writeLine(indent, "Snap Increments", pRecord.SnapIncrements);
4707
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4708
                    }
4709
                }
4710
            }
4711
        }
4712

    
4713
        /************************************************************************/
4714
        /* Dump the ViewTable                                                   */
4715
        /************************************************************************/
4716
        public void dumpViews(Database pDb, int indent, XmlNode node)
4717
        {
4718
            /**********************************************************************/
4719
            /* Get a pointer to the ViewTable                                */
4720
            /**********************************************************************/
4721
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
4722
            {
4723
                /**********************************************************************/
4724
                /* Dump the Description                                               */
4725
                /**********************************************************************/
4726
                writeLine();
4727
                writeLine(indent++, pTable.GetRXClass().Name);
4728

    
4729
                /**********************************************************************/
4730
                /* Step through the ViewTable                                         */
4731
                /**********************************************************************/
4732
                foreach (ObjectId id in pTable)
4733
                {
4734
                    /*********************************************************************/
4735
                    /* Open the ViewTableRecord for Reading                              */
4736
                    /*********************************************************************/
4737
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
4738
                    {
4739
                        /*********************************************************************/
4740
                        /* Dump the ViewTableRecord                                          */
4741
                        /*********************************************************************/
4742
                        writeLine();
4743
                        writeLine(indent, pRecord.GetRXClass().Name);
4744
                        writeLine(indent, "Name", pRecord.Name);
4745
                        writeLine(indent, "Category Name", pRecord.CategoryName);
4746
                        writeLine(indent, "Layer State", pRecord.LayerState);
4747

    
4748
                        string layoutName = "";
4749
                        if (!pRecord.Layout.IsNull)
4750
                        {
4751
                            using (Layout pLayout = (Layout)pRecord.Layout.Open(OpenMode.ForRead))
4752
                                layoutName = pLayout.LayoutName;
4753
                        }
4754
                        writeLine(indent, "Layout Name", layoutName);
4755
                        writeLine(indent, "PaperSpace View", pRecord.IsPaperspaceView);
4756
                        writeLine(indent, "Associated UCS", pRecord.IsUcsAssociatedToView);
4757
                        writeLine(indent, "PaperSpace View", pRecord.ViewAssociatedToViewport);
4758
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4759
                    }
4760
                }
4761
            }
4762
        }
4763
        /************************************************************************/
4764
        /* Dump Xdata                                                           */
4765
        /************************************************************************/
4766
        public void dumpXdata(ResultBuffer xIter, int indent)
4767
        {
4768
            if (xIter == null)
4769
                return;
4770
            writeLine(indent++, "Xdata:");
4771
            /**********************************************************************/
4772
            /* Step through the ResBuf chain                                      */
4773
            /**********************************************************************/
4774
            try
4775
            {
4776
                int rsCount = xIter.Cast<TypedValue>().Count();
4777
                
4778
                foreach (TypedValue resbuf in xIter)
4779
                {
4780
                    writeLine(indent, resbuf);
4781
                }
4782
            }
4783
            catch (System.Exception ex)
4784
            {
4785
            }
4786
            
4787
        }
4788
    }
4789
    class ExProtocolExtension
4790
    {
4791
    }
4792

    
4793
    class Program
4794
    {
4795
        public static XmlDocument xml = null;
4796
        public static double OffsetX = 0;
4797
        public static double OffsetY = 0;
4798
        public static double Scale = 0;
4799
        public static double getDrawing = 0;
4800
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
4801

    
4802
        static void Main(string[] args)
4803
        {
4804
            /********************************************************************/
4805
            /* Initialize Drawings.NET.                                         */
4806
            /********************************************************************/
4807
            bool bSuccess = true;
4808
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
4809
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
4810
            {
4811
                try
4812
                {
4813
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
4814
                    /**********************************************************************/
4815
                    /* Display the Product and Version that created the executable        */
4816
                    /**********************************************************************/
4817
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
4818

    
4819
                    if (args.Length != 5)
4820
                    {
4821
                        Console.WriteLine("\n\n\tusage: OdReadExMgd <filename> <OffsetX> <OffsetY> <Scale> <GenDrawing>");
4822
                        Console.WriteLine("\nPress ENTER to continue...\n");
4823
                        Console.ReadLine();
4824
                        bSuccess = false;
4825
                    }
4826
                    else
4827
                    {
4828
                        Console.WriteLine("\n File Name = " + args[0]);
4829

    
4830
                        double.TryParse(args[1], out Program.OffsetX);
4831
                        double.TryParse(args[2], out Program.OffsetY);
4832
                        double.TryParse(args[3], out Program.Scale);
4833
                        double.TryParse(args[4], out Program.getDrawing);
4834
                        Program.xml = new XmlDocument();
4835
                        {
4836
                            XmlNode root = xml.CreateElement("ID2");
4837
                            Program.xml.AppendChild(root);
4838

    
4839
                            /******************************************************************/
4840
                            /* Create a database and load the drawing into it.                
4841
                            /* first parameter means - do not initialize database- it will be read from file
4842
                             * second parameter is not used by Teigha.NET Classic - it is left for ARX compatibility.
4843
                             * Note the 'using' clause - generally, wrappers should disposed after use, 
4844
                             * to close underlying database objects
4845
                            /******************************************************************/
4846
                            using (Database pDb = new Database(false, false))
4847
                            {
4848
                                pDb.ReadDwgFile(args[0], FileShare.Read, true, "");
4849
                                HostApplicationServices.WorkingDatabase = pDb;
4850
                                /****************************************************************/
4851
                                /* Display the File Version                                     */
4852
                                /****************************************************************/
4853
                                Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion);
4854
                                /****************************************************************/
4855
                                /* Dump the database                                            */
4856
                                /****************************************************************/
4857
                                DbDumper dumper = new DbDumper();
4858
                                dumper.ExplodeAndPurgeNestedBlocks(pDb);
4859
                                if (Program.getDrawing == 1)
4860
                                {
4861
                                    dumper.ExportPNG(pDb, args[0]);
4862
                                    dumper.ExportPDF(pDb, args[0]);
4863
                                    dumper.ExportGraphicBlocks(pDb, args[0]);
4864
                                }
4865

    
4866
                                dumper.dump(pDb, 0, Program.xml.DocumentElement);
4867
                            }
4868
                            Program.xml.Save(Path.Combine(Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]) + ".xml"));
4869
                        }
4870
                    }
4871
                }
4872
                /********************************************************************/
4873
                /* Display the error                                                */
4874
                /********************************************************************/
4875
                catch (System.Exception e)
4876
                {
4877
                    bSuccess = false;
4878
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
4879
                }
4880

    
4881
                if (bSuccess)
4882
                    Console.WriteLine("OdReadExMgd Finished Successfully");
4883
            }
4884
        }
4885
    }
4886
}
클립보드 이미지 추가 (최대 크기: 500 MB)