프로젝트

일반

사용자정보

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

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ ec5dc86d

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

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

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

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

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

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

    
125
            const int tabSize = 2;
126

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
299
                dumpEntityData(pText, indent, TextNode);
300

    
301
                node.AppendChild(TextNode);
302
            }
303

    
304
            return TextNode;
305
        }
306

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

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

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

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

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

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

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

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

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

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

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

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

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

    
400
                XmlAttribute NodePointAttr = Program.xml.CreateAttribute("Nodes");
401
                NodePointAttr.Value = nodePointValue;
402
                BlockReferenceNode.Attributes.SetNamedItem(NodePointAttr);
403

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

    
411
                dumpEntityData(pBlkRef, indent, BlockReferenceNode);
412

    
413
                DBObjectCollection objColl = new DBObjectCollection();
414

    
415
                pBlkRef.Explode(objColl);
416
                foreach (var obj in objColl)
417
                {
418
                    if (obj is DBText)
419
                    {
420
                        dumpTextData(obj as DBText, indent, BlockReferenceNode);
421
                    }
422
                    else if (obj is MText)
423
                    {
424
                        MText mtext = obj as MText;
425

    
426
                        DBObjectCollection objs = new DBObjectCollection();
427
                        mtext.Explode(objs);
428
                        foreach (var item in objs)
429
                        {
430
                            dumpTextData(item as DBText, indent, node);
431
                        }
432
                    }
433
                }                
434

    
435
                /**********************************************************************/
436
                /* Dump the attributes                                                */
437
                /**********************************************************************/
438
                int i = 0;
439
                AttributeCollection attCol = pBlkRef.AttributeCollection;
440
                foreach (ObjectId id in attCol)
441
                {
442
                    try
443
                    {
444
                        using (AttributeReference pAttr = (AttributeReference)id.Open(OpenMode.ForRead))
445
                            dumpAttributeData(indent, pAttr, i++, BlockReferenceNode);
446
                    }
447
                    catch (System.Exception)
448
                    {
449

    
450
                    }
451
                }
452

    
453
                node.AppendChild(BlockReferenceNode);
454

    
455
                return BlockReferenceNode;
456
            }
457

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

    
479
                try
480
                {
481
                    writeLine(indent, "Area", pEntity.Area);
482
                }
483
                catch (System.Exception)
484
                {
485
                }
486
                dumpEntityData(pEntity, indent, node);
487
            }
488
        }
489

    
490
        /************************************************************************/
491
        /* Dump Dimension data                                                  */
492
        /************************************************************************/
493
        static XmlNode dumpDimData(Dimension pDim, int indent, XmlNode node)
494
        {
495
            if (node != null)
496
            {
497
                XmlElement DimDataNode = Program.xml.CreateElement("DimData");
498

    
499
                XmlAttribute CurrentMeasurementAttr = Program.xml.CreateAttribute("CurrentMeasurement");
500
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
501
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
502

    
503
                XmlAttribute DimensionTextAttr = Program.xml.CreateAttribute("DimensionText");
504
                DimensionTextAttr.Value = pDim.DimensionText.ToString();
505
                DimDataNode.Attributes.SetNamedItem(DimensionTextAttr);
506

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

    
527
                XmlAttribute DimBlockPositionAttr = Program.xml.CreateAttribute("DimBlockPosition");
528
                DimBlockPositionAttr.Value = pDim.DimBlockPosition.ToString();
529
                DimDataNode.Attributes.SetNamedItem(DimBlockPositionAttr);
530

    
531
                XmlAttribute TextPositionAttr = Program.xml.CreateAttribute("TextPosition");
532
                TextPositionAttr.Value = pDim.TextPosition.ToString();
533
                DimDataNode.Attributes.SetNamedItem(TextPositionAttr);
534

    
535
                XmlAttribute TextRotationAttr = Program.xml.CreateAttribute("TextRotation");
536
                TextRotationAttr.Value = pDim.TextRotation.ToString();
537
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
538

    
539
                XmlAttribute DimensionStyleNameAttr = Program.xml.CreateAttribute("DimensionStyleName");
540
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
541
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
542

    
543
                XmlAttribute DimtfillclrAttr = Program.xml.CreateAttribute("Dimtfillclr");
544
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
545
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
546

    
547
                XmlAttribute DimtfillAttr = Program.xml.CreateAttribute("Dimtfill");
548
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
549
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
550

    
551
                XmlAttribute Dimltex1Attr = Program.xml.CreateAttribute("Dimltex1");
552
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
553
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
554

    
555
                XmlAttribute Dimltex2Attr = Program.xml.CreateAttribute("Dimltex2");
556
                Dimltex2Attr.Value = pDim.Dimltex2.ToString();
557
                DimDataNode.Attributes.SetNamedItem(Dimltex2Attr);
558

    
559
                XmlAttribute DimltypeAttr = Program.xml.CreateAttribute("Dimltype");
560
                DimltypeAttr.Value = pDim.Dimltype.ToString();
561
                DimDataNode.Attributes.SetNamedItem(DimltypeAttr);
562

    
563
                XmlAttribute HorizontalRotationAttr = Program.xml.CreateAttribute("HorizontalRotation");
564
                HorizontalRotationAttr.Value = pDim.HorizontalRotation.ToString();
565
                DimDataNode.Attributes.SetNamedItem(HorizontalRotationAttr);
566

    
567
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
568
                ElevationAttr.Value = pDim.Elevation.ToString();
569
                DimDataNode.Attributes.SetNamedItem(ElevationAttr);
570

    
571
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
572
                NormalAttr.Value = pDim.Normal.ToString();
573
                DimDataNode.Attributes.SetNamedItem(NormalAttr);
574

    
575
                dumpEntityData(pDim, indent, node);
576

    
577
                return DimDataNode;
578
            }
579

    
580
            return null;
581
        }
582

    
583
        /************************************************************************/
584
        /* 2 Line Angular Dimension Dumper                                      */
585
        /************************************************************************/
586
        static XmlNode dump(LineAngularDimension2 pDim, int indent, XmlNode node)
587
        {
588
            if (node != null)
589
            {
590
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
591

    
592
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
593
                HandleAttr.Value = pDim.Handle.ToString();
594
                DimNode.Attributes.SetNamedItem(HandleAttr);
595

    
596
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
597
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
598
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
599

    
600
                XmlAttribute XLine1StartAttr = Program.xml.CreateAttribute("XLine1Start");
601
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
602
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
603

    
604
                XmlAttribute XLine1EndAttr = Program.xml.CreateAttribute("XLine1End");
605
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
606
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
607

    
608
                XmlAttribute XLine2StartAttr = Program.xml.CreateAttribute("XLine2Start");
609
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
610
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
611

    
612
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
613
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
614
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
615

    
616
                dumpDimData(pDim, indent, DimNode);
617

    
618
                return DimNode;
619
            }
620

    
621
            return null;
622
        }
623

    
624
        /************************************************************************/
625
        /* Dump 2D Vertex data                                                  */
626
        /************************************************************************/
627
        static XmlNode dump2dVertex(int indent, Vertex2d pVertex, int i, XmlNode node)
628
        {
629
            if (node != null)
630
            {
631
                XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
632

    
633
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
634
                HandleAttr.Value = pVertex.Handle.ToString();
635
                VertexNode.Attributes.SetNamedItem(HandleAttr);
636

    
637
                XmlAttribute VertexTypeAttr = Program.xml.CreateAttribute("VertexType");
638
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
639
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
640

    
641
                XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
642
                PositionAttr.Value = pVertex.Position.ToString();
643
                VertexNode.Attributes.SetNamedItem(PositionAttr);
644

    
645
                XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
646
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
647
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
648

    
649
                XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
650
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
651
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
652

    
653
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
654
                BulgeAttr.Value = pVertex.Bulge.ToString();
655
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
656

    
657
                if (pVertex.Bulge != 0)
658
                {
659
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
660
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
661
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
662
                }
663

    
664
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
665
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
666
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
667
                if (pVertex.TangentUsed)
668
                {
669
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
670
                    TangentAttr.Value = pVertex.Tangent.ToString();
671
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
672
                }
673

    
674
                node.AppendChild(VertexNode);
675

    
676
                return VertexNode;
677
            }
678

    
679
            return null;
680
        }
681

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

    
704
            if (node != null)
705
            {
706
                XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
707

    
708
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
709
                HandleAttr.Value = pPolyline.Handle.ToString();
710
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
711

    
712
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
713
                CountAttr.Value = Vertices.Count.ToString();
714
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
715

    
716
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
717
                ElevationAttr.Value = pPolyline.Elevation.ToString();
718
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
719

    
720
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
721
                NormalAttr.Value = pPolyline.Normal.ToString();
722
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
723

    
724
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
725
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
726
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
727

    
728
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
729
                ClosedAttr.Value = pPolyline.Closed.ToString();
730
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
731

    
732
                foreach (var vt in Vertices)
733
                {
734
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
735

    
736
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
737
                    XAttr.Value = vt.Position.X.ToString();
738
                    VertexNode.Attributes.SetNamedItem(XAttr);
739

    
740
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
741
                    YAttr.Value = vt.Position.Y.ToString();
742
                    VertexNode.Attributes.SetNamedItem(YAttr);
743

    
744
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
745
                    ZAttr.Value = vt.Position.Z.ToString();
746
                    VertexNode.Attributes.SetNamedItem(ZAttr);
747

    
748
                    Polyline2dNode.AppendChild(VertexNode);
749
                }
750

    
751
                dumpCurveData(pPolyline, indent, node);
752

    
753
                node.AppendChild(Polyline2dNode);
754

    
755
                return Polyline2dNode;
756
            }
757

    
758
            return null;
759
        }
760

    
761

    
762
        /************************************************************************/
763
        /* Dump 3D Polyline Vertex data                                         */
764
        /************************************************************************/
765
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
766
        {
767
            if (node != null)
768
            {
769
                XmlNode VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
770

    
771
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
772
                HandleAttr.Value = pVertex.Handle.ToString();
773
                VertexNode.Attributes.SetNamedItem(HandleAttr);
774

    
775
                XmlAttribute VertexxTypeAttr = Program.xml.CreateAttribute("VertexType");
776
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
777
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
778

    
779
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
780
                XAttr.Value = pVertex.Position.X.ToString();
781
                VertexNode.Attributes.SetNamedItem(XAttr);
782

    
783
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
784
                YAttr.Value = pVertex.Position.Y.ToString();
785
                VertexNode.Attributes.SetNamedItem(YAttr);
786

    
787
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
788
                ZAttr.Value = pVertex.Position.Z.ToString();
789
                VertexNode.Attributes.SetNamedItem(ZAttr);
790

    
791
                node.AppendChild(VertexNode);
792

    
793
                return VertexNode;
794
            }
795

    
796
            return null;
797
        }
798

    
799
        /************************************************************************/
800
        /* 3D Polyline Dumper                                                   */
801
        /************************************************************************/
802
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
803
        {
804
            if (node != null)
805
            {
806
                XmlNode pPolylineNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
807

    
808
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
809
                HandleAttr.Value = pPolyline.Handle.ToString();
810
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
811

    
812
                /********************************************************************/
813
                /* Dump the vertices                                                */
814
                /********************************************************************/
815
                int i = 0;
816
                foreach (ObjectId obj in pPolyline)
817
                {
818
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
819
                    {
820
                        if (dbObj is PolylineVertex3d)
821
                        {
822
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
823
                        }
824
                    }
825
                }
826
                dumpCurveData(pPolyline, indent, pPolylineNode);
827

    
828
                node.AppendChild(pPolylineNode);
829

    
830
                return pPolylineNode;
831
            }
832

    
833
            return null;
834
        }
835

    
836

    
837
        /************************************************************************/
838
        /* 3DSolid Dumper                                                       */
839
        /************************************************************************/
840
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
841
        {
842
            if (node != null)
843
            {
844
                XmlNode SolidNode = Program.xml.CreateElement(pSolid.GetRXClass().Name);
845

    
846
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
847
                HandleAttr.Value = pSolid.Handle.ToString();
848
                SolidNode.Attributes.SetNamedItem(HandleAttr);
849

    
850
                dumpEntityData(pSolid, indent, node);
851

    
852
                node.AppendChild(SolidNode);
853

    
854
                return SolidNode;
855
            }
856

    
857
            return null;
858
        }
859

    
860

    
861
        /************************************************************************/
862
        /* 3 Point Angular Dimension Dumper                                     */
863
        /************************************************************************/
864
        XmlNode dump(Point3AngularDimension pDim, int indent, XmlNode node)
865
        {
866
            if (node != null)
867
            {
868
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
869

    
870
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
871
                HandleAttr.Value = pDim.Handle.ToString();
872
                DimNode.Attributes.SetNamedItem(HandleAttr);
873

    
874
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
875
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
876
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
877

    
878
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
879
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
880
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
881

    
882
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
883
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
884
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
885

    
886
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
887
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
888
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
889

    
890
                dumpDimData(pDim, indent, DimNode);
891

    
892
                return DimNode;
893
            }
894

    
895
            return null;
896
        }
897

    
898
        /************************************************************************/
899
        /* Aligned Dimension Dumper                                             */
900
        /************************************************************************/
901
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
902
        {
903
            if (node != null)
904
            {
905
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
906

    
907
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
908
                HandleAttr.Value = pDim.Handle.ToString();
909
                DimNode.Attributes.SetNamedItem(HandleAttr);
910

    
911
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
912
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
913
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
914

    
915
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
916
                ObliqueAttr.Value = pDim.Oblique.ToString();
917
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
918

    
919
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
920
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
921
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
922

    
923
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
924
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
925
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
926

    
927
                dumpDimData(pDim, indent, DimNode);
928

    
929
                return DimNode;
930
            }
931

    
932
            return null;
933
        }
934

    
935
        /************************************************************************/
936
        /* Arc Dumper                                                           */
937
        /************************************************************************/
938
        XmlNode dump(Arc pArc, int indent, XmlNode node)
939
        {
940
            if (node != null)
941
            {
942
                XmlElement ArcNode = Program.xml.CreateElement(pArc.GetRXClass().Name);
943

    
944
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
945
                XAttr.Value = pArc.Center.X.ToString();
946
                ArcNode.Attributes.SetNamedItem(XAttr);
947

    
948
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
949
                YAttr.Value = pArc.Center.Y.ToString();
950
                ArcNode.Attributes.SetNamedItem(YAttr);
951

    
952
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
953
                ZAttr.Value = pArc.Center.Z.ToString();
954
                ArcNode.Attributes.SetNamedItem(ZAttr);
955

    
956
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
957
                RadiusAttr.Value = pArc.Radius.ToString();
958
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
959

    
960
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
961
                StartAngleAttr.Value = pArc.StartAngle.ToString();
962
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
963

    
964
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
965
                EndAngleAttr.Value = pArc.EndAngle.ToString();
966
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
967

    
968
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
969
                NormalAttr.Value = pArc.Normal.ToString();
970
                ArcNode.Attributes.SetNamedItem(NormalAttr);
971

    
972
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
973
                ThicknessAttr.Value = pArc.Normal.ToString();
974
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
975

    
976
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
977
                dumpCurveData(pArc, indent, ArcNode);
978

    
979
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
980
                {
981
                    XAttr = Program.xml.CreateAttribute("X");
982
                    XAttr.Value = pArc.StartPoint.X.ToString();
983
                    StartPointNode.Attributes.SetNamedItem(XAttr);
984

    
985
                    YAttr = Program.xml.CreateAttribute("Y");
986
                    YAttr.Value = pArc.StartPoint.Y.ToString();
987
                    StartPointNode.Attributes.SetNamedItem(YAttr);
988

    
989
                    ZAttr = Program.xml.CreateAttribute("Z");
990
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
991
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
992
                }
993
                ArcNode.AppendChild(StartPointNode);
994

    
995
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
996
                {
997
                    XAttr = Program.xml.CreateAttribute("X");
998
                    XAttr.Value = pArc.EndPoint.X.ToString();
999
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1000

    
1001
                    YAttr = Program.xml.CreateAttribute("Y");
1002
                    YAttr.Value = pArc.EndPoint.Y.ToString();
1003
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1004

    
1005
                    ZAttr = Program.xml.CreateAttribute("Z");
1006
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1007
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1008
                }
1009
                ArcNode.AppendChild(EndPointNode);
1010

    
1011
                node.AppendChild(ArcNode);
1012

    
1013
                return ArcNode;
1014
            }
1015

    
1016
            return null;
1017
        }
1018

    
1019
        /************************************************************************/
1020
        /* Arc Dimension Dumper                                                 */
1021
        /************************************************************************/
1022
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
1023
        {
1024
            if (node != null)
1025
            {
1026
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1027

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

    
1032
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
1033
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
1034
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
1035

    
1036
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
1037
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
1038
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
1039

    
1040
                XmlAttribute ArcSymbolTypeAttr = Program.xml.CreateAttribute("ArcSymbolType");
1041
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1042
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1043

    
1044
                XmlAttribute IsPartialAttr = Program.xml.CreateAttribute("IsPartial");
1045
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1046
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1047

    
1048
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1049
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1050
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1051

    
1052
                if (pDim.HasLeader)
1053
                {
1054
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1055
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1056
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1057

    
1058
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1059
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1060
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1061
                }
1062

    
1063
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1064
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1065
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1066

    
1067
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1068
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1069
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1070

    
1071
                dumpDimData(pDim, indent, DimNode);
1072

    
1073
                return DimNode;
1074
            }
1075

    
1076
            return null;
1077
        }
1078

    
1079

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

    
1097
        /************************************************************************/
1098
        /* Body Dumper                                                          */
1099
        /************************************************************************/
1100
        XmlNode dump(Body pBody, int indent, XmlNode node)
1101
        {
1102
            if (node != null)
1103
            {
1104
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1105

    
1106
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1107
                HandleAttr.Value = pBody.Handle.ToString();
1108
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1109

    
1110
                dumpEntityData(pBody, indent, BodyNode);
1111

    
1112
                return BodyNode;
1113
            }
1114

    
1115
            return null;
1116
        }
1117

    
1118

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

    
1128
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1129
                XAttr.Value = pCircle.Center.X.ToString();
1130
                CircleNode.Attributes.SetNamedItem(XAttr);
1131

    
1132
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1133
                YAttr.Value = pCircle.Center.Y.ToString();
1134
                CircleNode.Attributes.SetNamedItem(YAttr);
1135

    
1136
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1137
                RadiusAttr.Value = pCircle.Radius.ToString();
1138
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1139

    
1140
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1141
                NormalAttr.Value = pCircle.Normal.ToString();
1142
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1143

    
1144
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1145
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1146
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1147

    
1148
                dumpCurveData(pCircle, indent, CircleNode);
1149

    
1150
                node.AppendChild(CircleNode);
1151

    
1152
                return CircleNode;
1153
            }
1154

    
1155
            return null;
1156
        }
1157

    
1158
        /************************************************************************/
1159
        /* Diametric Dimension Dumper                                           */
1160
        /************************************************************************/
1161
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1162
        {
1163
            if (node != null)
1164
            {
1165
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1166

    
1167
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1168
                HandleAttr.Value = pDim.Handle.ToString();
1169
                DimNode.Attributes.SetNamedItem(HandleAttr);
1170

    
1171
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
1172
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1173
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1174

    
1175
                XmlAttribute FarChordPointAttr = Program.xml.CreateAttribute("FarChordPoint");
1176
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1177
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1178

    
1179
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1180
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1181
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1182

    
1183
                dumpDimData(pDim, indent, DimNode);
1184

    
1185
                return DimNode;
1186
            }
1187

    
1188
            return null;
1189
        }
1190

    
1191
        /************************************************************************/
1192
        /* Ellipse Dumper                                                       */
1193
        /************************************************************************/
1194
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1195
        {
1196
            if (node != null)
1197
            {
1198
                XmlElement EllipseNode = Program.xml.CreateElement(pEllipse.GetRXClass().Name);
1199

    
1200
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1201

    
1202
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1203
                XAttr.Value = pEllipse.Center.X.ToString();
1204
                EllipseNode.Attributes.SetNamedItem(XAttr);
1205

    
1206
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1207
                YAttr.Value = pEllipse.Center.Y.ToString();
1208
                EllipseNode.Attributes.SetNamedItem(YAttr);
1209

    
1210
                XmlAttribute MajorAxisAttr = Program.xml.CreateAttribute("MajorAxis");
1211
                MajorAxisAttr.Value = pEllipse.MajorAxis.ToString();
1212
                EllipseNode.Attributes.SetNamedItem(MajorAxisAttr);
1213

    
1214
                XmlAttribute MinorAxisAttr = Program.xml.CreateAttribute("MinorAxis");
1215
                MinorAxisAttr.Value = pEllipse.MinorAxis.ToString();
1216
                EllipseNode.Attributes.SetNamedItem(MinorAxisAttr);
1217

    
1218
                XmlAttribute MajorRadiusAttr = Program.xml.CreateAttribute("MajorRadius");
1219
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1220
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1221

    
1222
                XmlAttribute MinorRadiusAttr = Program.xml.CreateAttribute("MinorRadius");
1223
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1224
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1225

    
1226
                XmlAttribute RadiusRatioAttr = Program.xml.CreateAttribute("RadiusRatio");
1227
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1228
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1229

    
1230
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1231
                StartAngleAttr.Value = pEllipse.StartAngle.ToString();
1232
                EllipseNode.Attributes.SetNamedItem(StartAngleAttr);
1233

    
1234
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1235
                EndAngleAttr.Value = pEllipse.EndAngle.ToString();
1236
                EllipseNode.Attributes.SetNamedItem(EndAngleAttr);
1237

    
1238
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1239
                NormalAttr.Value = pEllipse.Normal.ToString();
1240
                EllipseNode.Attributes.SetNamedItem(NormalAttr);
1241

    
1242
                dumpCurveData(pEllipse, indent, EllipseNode);
1243

    
1244
                node.AppendChild(EllipseNode);
1245
            }
1246
        }
1247

    
1248
        /************************************************************************/
1249
        /* Face Dumper                                                       */
1250
        /************************************************************************/
1251
        XmlNode dump(Face pFace, int indent, XmlNode node)
1252
        {
1253
            if (node != null)
1254
            {
1255
                XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1256

    
1257
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1258
                HandleAttr.Value = pFace.Handle.ToString();
1259
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1260

    
1261
                for (short i = 0; i < 4; i++)
1262
                {
1263
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1264

    
1265
                    Point3d pt = pFace.GetVertexAt(i);
1266
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1267
                    XAttr.Value = pt.X.ToString();
1268
                    VertexNode.Attributes.SetNamedItem(XAttr);
1269

    
1270
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1271
                    YAttr.Value = pt.Y.ToString();
1272
                    VertexNode.Attributes.SetNamedItem(YAttr);
1273

    
1274
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1275
                    ZAttr.Value = pt.Z.ToString();
1276
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1277

    
1278
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1279
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1280
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1281

    
1282
                    FaceNode.AppendChild(VertexNode);
1283
                }
1284
                dumpEntityData(pFace, indent, FaceNode);
1285

    
1286
                node.AppendChild(FaceNode);
1287

    
1288
                return FaceNode;
1289
            }
1290

    
1291
            return null;
1292
        }
1293

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

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

    
1332
        /**********************************************************************/
1333
        /* Dump Circular Arc Edge                                             */
1334
        /**********************************************************************/
1335
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1336
        {
1337
            writeLine(indent, "Center", pCircArc.Center);
1338
            writeLine(indent, "Radius", pCircArc.Radius);
1339
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1340
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1341
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1342
        }
1343

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

    
1359
        /**********************************************************************/
1360
        /* Dump NurbCurve Edge                                           */
1361
        /**********************************************************************/
1362
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1363
        {
1364
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1365
            writeLine(indent, "Degree", d.Degree);
1366
            writeLine(indent, "Rational", d.Rational);
1367
            writeLine(indent, "Periodic", d.Periodic);
1368

    
1369
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1370
            for (int i = 0; i < d.ControlPoints.Count; i++)
1371
            {
1372
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1373
            }
1374
            writeLine(indent, "Number of Knots", d.Knots.Count);
1375
            for (int i = 0; i < d.Knots.Count; i++)
1376
            {
1377
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1378
            }
1379

    
1380
            if (d.Rational)
1381
            {
1382
                writeLine(indent, "Number of Weights", d.Weights.Count);
1383
                for (int i = 0; i < d.Weights.Count; i++)
1384
                {
1385
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1386
                }
1387
            }
1388
        }
1389

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

    
1416
                    /******************************************************************/
1417
                    /* Common Edge Properties                                         */
1418
                    /******************************************************************/
1419
                    Interval interval = pEdge.GetInterval();
1420
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1421
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1422
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1423
                }
1424
            }
1425
        }
1426

    
1427
        /************************************************************************/
1428
        /* Convert the specified value to a LoopType string                     */
1429
        /************************************************************************/
1430
        string toLooptypeString(HatchLoopTypes loopType)
1431
        {
1432
            string retVal = "";
1433
            if ((loopType & HatchLoopTypes.External) != 0)
1434
                retVal = retVal + " | kExternal";
1435

    
1436
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1437
                retVal = retVal + " | kPolyline";
1438

    
1439
            if ((loopType & HatchLoopTypes.Derived) != 0)
1440
                retVal = retVal + " | kDerived";
1441

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

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

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

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

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

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

    
1460
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1461
        }
1462

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

    
1539
            /********************************************************************/
1540
            /* Dump Associated Objects                                          */
1541
            /********************************************************************/
1542
            writeLine(indent, "Associated objects", pHatch.Associative);
1543
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1544
            {
1545
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1546
            }
1547

    
1548
            /********************************************************************/
1549
            /* Dump Loops                                                       */
1550
            /********************************************************************/
1551
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1552
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1553
            {
1554
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1555

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

    
1580
            writeLine(indent, "Elevation", pHatch.Elevation);
1581
            writeLine(indent, "Normal", pHatch.Normal);
1582
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1583
        }
1584

    
1585
        /************************************************************************/
1586
        /* Leader Dumper                                                          */
1587
        /************************************************************************/
1588
        void dump(Leader pLeader, int indent)
1589
        {
1590
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1591
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1592

    
1593
            writeLine(indent, "Annotation");
1594
            if (!pLeader.Annotation.IsNull)
1595
            {
1596
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1597
            }
1598
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1599
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1600
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1601
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1602
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1603
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1604
            writeLine(indent, "Splined", pLeader.IsSplined);
1605

    
1606
            for (int i = 0; i < pLeader.NumVertices; i++)
1607
            {
1608
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1609
            }
1610
            writeLine(indent, "Normal", pLeader.Normal);
1611
            dumpCurveData(pLeader, indent, Program.xml.DocumentElement);
1612
        }
1613

    
1614
        /************************************************************************/
1615
        /* Line Dumper                                                          */
1616
        /************************************************************************/
1617
        void dump(Line pLine, int indent, XmlNode node)
1618
        {
1619
            if (node != null && pLine != null && pLine.Length != 0)
1620
            {
1621
                XmlNode LineNode = Program.xml.CreateElement(pLine.GetRXClass().Name);
1622
                XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1623
                LengthAttr.Value = pLine.Length.ToString();
1624
                LineNode.Attributes.SetNamedItem(LengthAttr);
1625

    
1626
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1627
                HandleAttr.Value = pLine.Handle.ToString();
1628
                LineNode.Attributes.SetNamedItem(HandleAttr);
1629

    
1630
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1631
                {
1632
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1633
                    XAttr.Value = pLine.StartPoint.X.ToString();
1634
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1635

    
1636
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1637
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1638
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1639

    
1640
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1641
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1642
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1643
                }
1644
                LineNode.AppendChild(StartPointNode);
1645

    
1646
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1647
                {
1648
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1649
                    XAttr.Value = pLine.EndPoint.X.ToString();
1650
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1651

    
1652
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1653
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1654
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1655

    
1656
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1657
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1658
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1659
                }
1660
                LineNode.AppendChild(EndPointNode);
1661

    
1662
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1663
                NormalAttr.Value = pLine.Normal.ToString();
1664
                LineNode.Attributes.SetNamedItem(NormalAttr);
1665

    
1666
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1667
                ThicknessAttr.Value = pLine.Thickness.ToString();
1668
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1669

    
1670
                dumpEntityData(pLine, indent, LineNode);
1671

    
1672
                node.AppendChild(LineNode);
1673
            }
1674
            else
1675
            {
1676
                int d = 0;
1677
            }
1678
        }
1679

    
1680
        /************************************************************************/
1681
        /* MInsertBlock Dumper                                                  */
1682
        /************************************************************************/
1683
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1684
        {
1685
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1686

    
1687
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1688
            {
1689
                writeLine(indent, "Name", pRecord.Name);
1690
                writeLine(indent, "Rows", pMInsert.Rows);
1691
                writeLine(indent, "Columns", pMInsert.Columns);
1692
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1693
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1694
                dumpBlockRefData(pMInsert, indent, node);
1695
            }
1696
        }
1697

    
1698
        /************************************************************************/
1699
        /* Mline Dumper                                                         */
1700
        /************************************************************************/
1701
        void dump(Mline pMline, int indent)
1702
        {
1703
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1704
            writeLine(indent, "Style", pMline.Style);
1705
            writeLine(indent, "Closed", pMline.IsClosed);
1706
            writeLine(indent, "Scale", pMline.Scale);
1707
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1708
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1709
            writeLine(indent, "Normal", pMline.Normal);
1710

    
1711
            /********************************************************************/
1712
            /* Dump the segment data                                            */
1713
            /********************************************************************/
1714
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1715
            {
1716
                writeLine(indent, "Segment", i);
1717
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1718
            }
1719
            dumpEntityData(pMline, indent, Program.xml.DocumentElement);
1720
        }
1721

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

    
1741
        /************************************************************************/
1742
        /* Ordinate Dimension Dumper                                            */
1743
        /************************************************************************/
1744
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1745
        {
1746
            if (node != null)
1747
            {
1748
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1749

    
1750
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1751
                HandleAttr.Value = pDim.Handle.ToString();
1752
                DimNode.Attributes.SetNamedItem(HandleAttr);
1753

    
1754
                XmlAttribute DefiningPointAttr = Program.xml.CreateAttribute("DefiningPoint");
1755
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1756
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1757

    
1758
                XmlAttribute UsingXAxisAttr = Program.xml.CreateAttribute("UsingXAxis");
1759
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1760
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1761

    
1762
                XmlAttribute UsingYAxisAttr = Program.xml.CreateAttribute("UsingYAxis");
1763
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1764
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1765

    
1766
                XmlAttribute LeaderEndPointAttr = Program.xml.CreateAttribute("LeaderEndPoint");
1767
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1768
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1769

    
1770
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1771
                OriginAttr.Value = pDim.Origin.ToString();
1772
                DimNode.Attributes.SetNamedItem(OriginAttr);
1773

    
1774
                dumpDimData(pDim, indent, DimNode);
1775

    
1776
                return DimNode;
1777
            }
1778

    
1779
            return null;
1780
        }
1781

    
1782
        /************************************************************************/
1783
        /* PolyFaceMesh Dumper                                                  */
1784
        /************************************************************************/
1785
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1786
        {
1787
            if (node != null)
1788
            {
1789
                XmlElement PolyNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1790

    
1791
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1792
                HandleAttr.Value = pPoly.Handle.ToString();
1793
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1794

    
1795
                XmlAttribute NumVerticesAttr = Program.xml.CreateAttribute("NumVertices");
1796
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1797
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1798

    
1799
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1800
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1801
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1802

    
1803
                /********************************************************************/
1804
                /* dump vertices and faces                                          */
1805
                /********************************************************************/
1806
                int vertexCount = 0;
1807
                int faceCount = 0;
1808
                foreach (ObjectId objId in pPoly)
1809
                {
1810
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1811
                    {
1812
                        if (ent is PolyFaceMeshVertex)
1813
                        {
1814
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1815

    
1816
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1817

    
1818
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1819
                            _HandleAttr.Value = pVertex.Handle.ToString();
1820
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1821

    
1822
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1823
                            PositionAttr.Value = pVertex.Position.ToString();
1824
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1825

    
1826
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1827

    
1828
                            PolyNode.AppendChild(VertexNode);
1829
                        }
1830
                        else if (ent is FaceRecord)
1831
                        {
1832
                            FaceRecord pFace = (FaceRecord)ent;
1833
                            string face = "{";
1834
                            for (short i = 0; i < 4; i++)
1835
                            {
1836
                                if (i > 0)
1837
                                {
1838
                                    face = face + " ";
1839
                                }
1840
                                face = face + pFace.GetVertexAt(i).ToString();
1841
                            }
1842

    
1843
                            face += "}";
1844

    
1845
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1846

    
1847
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1848
                            _HandleAttr.Value = pFace.Handle.ToString();
1849
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1850
                            FaceNode.InnerText = face;
1851

    
1852
                            dumpEntityData(pFace, indent + 1, FaceNode);
1853

    
1854
                            PolyNode.AppendChild(FaceNode);
1855
                        }
1856
                        else
1857
                        { // Unknown entity type
1858
                            writeLine(indent, "Unexpected Entity");
1859
                        }
1860
                    }
1861
                }
1862
                dumpEntityData(pPoly, indent, PolyNode);
1863

    
1864
                return PolyNode;
1865
            }
1866

    
1867
            return null;
1868
        }
1869

    
1870
        /************************************************************************/
1871
        /* Ole2Frame                                                            */
1872
        /************************************************************************/
1873
        void dump(Ole2Frame pOle, int indent)
1874
        {
1875
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1876

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

    
1893
        /************************************************************************/
1894
        /* Point Dumper                                                         */
1895
        /************************************************************************/
1896
        void dump(DBPoint pPoint, int indent)
1897
        {
1898
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1899
            writeLine(indent, "Position", pPoint.Position);
1900
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1901
            writeLine(indent, "Normal", pPoint.Normal);
1902
            writeLine(indent, "Thickness", pPoint.Thickness);
1903
            dumpEntityData(pPoint, indent, Program.xml.DocumentElement);
1904
        }
1905

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

    
1936
        /************************************************************************/
1937
        /* Polyline Dumper                                                      */
1938
        /************************************************************************/
1939
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
1940
        {
1941
            if (pPoly != null && pPoly.Length != 0)
1942
            {
1943
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1944
                writeLine(indent, "Has Width", pPoly.HasWidth);
1945
                if (!pPoly.HasWidth)
1946
                {
1947
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
1948
                }
1949

    
1950
                /********************************************************************/
1951
                /* dump vertices                                                    */
1952
                /********************************************************************/
1953
                if (node != null)
1954
                {
1955
                    XmlNode PolylineNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1956
                    XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1957
                    LengthAttr.Value = pPoly.Length.ToString();
1958
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
1959

    
1960
                    XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
1961
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
1962
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
1963

    
1964
                    XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1965
                    HandleAttr.Value = pPoly.Handle.ToString();
1966
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
1967

    
1968
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
1969
                    ClosedAttr.Value = pPoly.Closed.ToString();
1970
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
1971

    
1972
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
1973
                    {
1974
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
1975

    
1976
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
1977
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
1978

    
1979
                        Point3d pt = pPoly.GetPoint3dAt(i);
1980
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1981
                        XAttr.Value = pt.X.ToString();
1982
                        VertexNode.Attributes.SetNamedItem(XAttr);
1983

    
1984
                        XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1985
                        YAttr.Value = pt.Y.ToString();
1986
                        VertexNode.Attributes.SetNamedItem(YAttr);
1987

    
1988
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1989
                        ZAttr.Value = pt.Z.ToString();
1990
                        VertexNode.Attributes.SetNamedItem(ZAttr);
1991

    
1992
                        if (pPoly.HasWidth)
1993
                        {
1994
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
1995
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
1996
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
1997

    
1998
                            XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
1999
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
2000
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
2001
                        }
2002
                        if (pPoly.HasBulges)
2003
                        {
2004
                            XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
2005
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
2006
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
2007

    
2008
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2009
                            {
2010
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
2011
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2012
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2013
                            }
2014
                        }
2015

    
2016
                        PolylineNode.AppendChild(VertexNode);
2017
                    }
2018

    
2019
                    dumpEntityData(pPoly, indent, PolylineNode);
2020
                    node.AppendChild(PolylineNode);
2021
                }
2022
            }
2023
            else
2024
            {
2025
                int d = 0;
2026
            }
2027
        }
2028

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

    
2088
            protected override void SetLayerFlags(LayerFlags flags)
2089
            {
2090
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2091
            }
2092
            public override void AddLight(ObjectId lightId)
2093
            {
2094
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2095
            }
2096
            public override void SetupForEntity(Entity entity)
2097
            {
2098
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2099
            }
2100

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

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

    
2396
            public override void SetExtents(Extents3d extents)
2397
            {
2398
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2399
            }
2400
            public override void StartAttributesSegment()
2401
            {
2402
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2403
            }
2404
        }
2405

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

    
2485
        /************************************************************************/
2486
        /* Dump the common data and WorldDraw information for all               */
2487
        /* entities without explicit dumpers                                    */
2488
        /************************************************************************/
2489
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2490
        {
2491
            if (node != null)
2492
            {
2493
                XmlElement EntNode = Program.xml.CreateElement(pEnt.GetRXClass().Name);
2494

    
2495
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2496
                HandleAttr.Value = pEnt.Handle.ToString();
2497
                EntNode.Attributes.SetNamedItem(HandleAttr);
2498

    
2499
                dumpEntityData(pEnt, indent, EntNode);
2500
                using (Database db = pEnt.Database)
2501
                {
2502
                    /**********************************************************************/
2503
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2504
                    /**********************************************************************/
2505
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2506
                    /**********************************************************************/
2507
                    /* Call worldDraw()                                                   */
2508
                    /**********************************************************************/
2509
                    pEnt.WorldDraw(wd);
2510
                }
2511

    
2512
                node.AppendChild(EntNode);
2513

    
2514
                return EntNode;
2515
            }
2516

    
2517
            return null;
2518
        }
2519

    
2520
        /************************************************************************/
2521
        /* Proxy Entity Dumper                                                  */
2522
        /************************************************************************/
2523
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2524
        {
2525
            if (node != null)
2526
            {
2527
                XmlElement ProxyNode = Program.xml.CreateElement(pProxy.GetRXClass().Name);
2528

    
2529
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2530
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2531
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2532

    
2533
                // this will dump proxy entity graphics
2534
                dump((Entity)pProxy, indent, node);
2535

    
2536
                DBObjectCollection collection = new DBObjectCollection(); ;
2537
                try
2538
                {
2539
                    pProxy.ExplodeGeometry(collection);
2540
                }
2541
                catch (System.Exception)
2542
                {
2543
                    return null;
2544
                }
2545

    
2546
                foreach (Entity ent in collection)
2547
                {
2548
                    if (ent is Polyline2d)
2549
                    {
2550
                        Polyline2d pline2d = (Polyline2d)ent;
2551
                        int i = 0;
2552

    
2553
                        try
2554
                        {
2555
                            foreach (Entity ent1 in pline2d)
2556
                            {
2557
                                if (ent1 is Vertex2d)
2558
                                {
2559
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2560
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2561
                                }
2562
                            }
2563
                        }
2564
                        catch (System.Exception)
2565
                        {
2566
                            return null;
2567
                        }
2568
                    }
2569
                }
2570

    
2571
                node.AppendChild(ProxyNode);
2572
                return ProxyNode;
2573
            }
2574

    
2575
            return null;
2576
        }
2577

    
2578
        /************************************************************************/
2579
        /* Radial Dimension Dumper                                              */
2580
        /************************************************************************/
2581
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2582
        {
2583
            if (node != null)
2584
            {
2585
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2586

    
2587
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2588
                HandleAttr.Value = pDim.Handle.ToString();
2589
                DimNode.Attributes.SetNamedItem(HandleAttr);
2590

    
2591
                XmlAttribute CenterAttr = Program.xml.CreateAttribute("Center");
2592
                CenterAttr.Value = pDim.Center.ToString();
2593
                DimNode.Attributes.SetNamedItem(CenterAttr);
2594

    
2595
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
2596
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
2597
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
2598

    
2599
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
2600
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2601
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2602

    
2603
                dumpDimData(pDim, indent, DimNode);
2604

    
2605
                node.AppendChild(DimNode);
2606

    
2607
                return DimNode;
2608
            }
2609

    
2610
            return null;
2611
        }
2612

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

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

    
2662
            /********************************************************************/
2663
            /* Dump frame                                                       */
2664
            /********************************************************************/
2665
            Point3dCollection vertices = pImage.GetVertices();
2666
            for (int i = 0; i < vertices.Count; i++)
2667
            {
2668
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2669
            }
2670

    
2671
            /********************************************************************/
2672
            /* Dump orientation                                                 */
2673
            /********************************************************************/
2674
            writeLine(indent, "Orientation");
2675
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2676
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2677
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2678
            dumpRasterImageDef(pImage.ImageDefId, indent);
2679
            dumpEntityData(pImage, indent, Program.xml.DocumentElement);
2680
        }
2681

    
2682
        /************************************************************************/
2683
        /* Raster Image Dumper                                                  */
2684
        /************************************************************************/
2685
        void dump(RasterImage pImage, int indent)
2686
        {
2687
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2688
            writeLine(indent, "Image size", pImage.ImageSize(true));
2689
            dumpRasterImageData(pImage, indent);
2690
        }
2691

    
2692
        /************************************************************************/
2693
        /* Ray Dumper                                                          */
2694
        /************************************************************************/
2695
        void dump(Ray pRay, int indent)
2696
        {
2697
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2698
            writeLine(indent, "Base Point", pRay.BasePoint);
2699
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2700
            dumpCurveData(pRay, indent, Program.xml.DocumentElement);
2701
        }
2702

    
2703
        /************************************************************************/
2704
        /* Region Dumper                                                        */
2705
        /************************************************************************/
2706
        void dump(Region pRegion, int indent)
2707
        {
2708
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2709
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2710
        }
2711

    
2712
        /************************************************************************/
2713
        /* Rotated Dimension Dumper                                             */
2714
        /************************************************************************/
2715
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2716
        {
2717
            if (node != null)
2718
            {
2719
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2720

    
2721
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2722
                HandleAttr.Value = pDim.Handle.ToString();
2723
                DimNode.Attributes.SetNamedItem(HandleAttr);
2724

    
2725
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
2726
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2727
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2728

    
2729
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
2730
                ObliqueAttr.Value = pDim.Oblique.ToString();
2731
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2732

    
2733
                XmlAttribute RotationAttr = Program.xml.CreateAttribute("Rotation");
2734
                RotationAttr.Value = pDim.Rotation.ToString();
2735
                DimNode.Attributes.SetNamedItem(RotationAttr);
2736

    
2737
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
2738
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2739
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2740

    
2741
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2742
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2743
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2744

    
2745
                dumpDimData(pDim, indent, DimNode);
2746
                node.AppendChild(DimNode);
2747

    
2748
                return DimNode;
2749
            }
2750

    
2751
            return null;
2752
        }
2753

    
2754
        /************************************************************************/
2755
        /* Shape Dumper                                                          */
2756
        /************************************************************************/
2757
        void dump(Shape pShape, int indent)
2758
        {
2759
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2760

    
2761
            if (!pShape.StyleId.IsNull)
2762
            {
2763
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2764
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2765
            }
2766

    
2767
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2768
            writeLine(indent, "Shape Name", pShape.Name);
2769
            writeLine(indent, "Position", pShape.Position);
2770
            writeLine(indent, "Size", pShape.Size);
2771
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2772
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2773
            writeLine(indent, "Normal", pShape.Normal);
2774
            writeLine(indent, "Thickness", pShape.Thickness);
2775
            dumpEntityData(pShape, indent, Program.xml.DocumentElement);
2776
        }
2777

    
2778
        /************************************************************************/
2779
        /* Solid Dumper                                                         */
2780
        /************************************************************************/
2781
        // TODO:
2782
        /*  void dump(Solid pSolid, int indent)
2783
      {
2784
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2785

    
2786
        for (int i = 0; i < 4; i++)
2787
        {
2788
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2789
        }
2790
        dumpEntityData(pSolid, indent);
2791
      }
2792
    */
2793
        /************************************************************************/
2794
        /* Spline Dumper                                                        */
2795
        /************************************************************************/
2796
        void dump(Spline pSpline, int indent)
2797
        {
2798
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2799

    
2800
            NurbsData data = pSpline.NurbsData;
2801
            writeLine(indent, "Degree", data.Degree);
2802
            writeLine(indent, "Rational", data.Rational);
2803
            writeLine(indent, "Periodic", data.Periodic);
2804
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2805
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2806

    
2807
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2808
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2809
            {
2810
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2811
            }
2812

    
2813
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2814
            for (int i = 0; i < data.GetKnots().Count; i++)
2815
            {
2816
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2817
            }
2818

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

    
2843
            // TODO:
2844
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2845
            //writeLine(indent, "Table Style",               pStyle.Name);
2846
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2847
        }
2848

    
2849
        /************************************************************************/
2850
        /* Text Dumper                                                          */
2851
        /************************************************************************/
2852
        static void dump(DBText pText, int indent, XmlNode node)
2853
        {
2854
            if (node != null)
2855
            {
2856
                dumpTextData(pText, indent, node);
2857
            }
2858
        }
2859
        /************************************************************************/
2860
        /* Trace Dumper                                                         */
2861
        /************************************************************************/
2862
        void dump(Trace pTrace, int indent)
2863
        {
2864
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2865

    
2866
            for (short i = 0; i < 4; i++)
2867
            {
2868
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2869
            }
2870
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2871
        }
2872

    
2873
        /************************************************************************/
2874
        /* Trace UnderlayReference                                                         */
2875
        /************************************************************************/
2876
        void dump(UnderlayReference pEnt, int indent)
2877
        {
2878
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2879
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2880
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2881
        }
2882

    
2883
        /************************************************************************/
2884
        /* Viewport Dumper                                                       */
2885
        /************************************************************************/
2886
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2887
        {
2888
            if (node != null)
2889
            {
2890
                XmlElement VportNode = Program.xml.CreateElement(pVport.GetRXClass().Name);
2891

    
2892
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2893
                HandleAttr.Value = pVport.Handle.ToString();
2894
                VportNode.Attributes.SetNamedItem(HandleAttr);
2895

    
2896
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2897
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2898
                writeLine(indent, "Center Point", pVport.CenterPoint);
2899
                writeLine(indent, "Circle sides", pVport.CircleSides);
2900
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2901
                writeLine(indent, "Elevation", pVport.Elevation);
2902
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2903
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2904
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2905
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2906

    
2907
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2908
                if (layerIds.Count > 0)
2909
                {
2910
                    writeLine(indent, "Frozen Layers:");
2911
                    for (int i = 0; i < layerIds.Count; i++)
2912
                    {
2913
                        writeLine(indent + 1, i, layerIds[i]);
2914
                    }
2915
                }
2916
                else
2917
                {
2918
                    writeLine(indent, "Frozen Layers", "None");
2919
                }
2920

    
2921
                Point3d origin = new Point3d();
2922
                Vector3d xAxis = new Vector3d();
2923
                Vector3d yAxis = new Vector3d();
2924
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
2925
                writeLine(indent, "UCS origin", origin);
2926
                writeLine(indent, "UCS x-Axis", xAxis);
2927
                writeLine(indent, "UCS y-Axis", yAxis);
2928
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
2929
                writeLine(indent, "Grid On", pVport.GridOn);
2930
                writeLine(indent, "Height", pVport.Height);
2931
                writeLine(indent, "Lens Length", pVport.LensLength);
2932
                writeLine(indent, "Locked", pVport.Locked);
2933
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
2934

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

    
2948
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
2949
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
2950

    
2951
                if (!pVport.UcsName.IsNull)
2952
                {
2953
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
2954
                        writeLine(indent, "UCS Name", pUCS.Name);
2955
                }
2956
                else
2957
                {
2958
                    writeLine(indent, "UCS Name", "Null");
2959
                }
2960

    
2961
                writeLine(indent, "View Center", pVport.ViewCenter);
2962
                writeLine(indent, "View Height", pVport.ViewHeight);
2963
                writeLine(indent, "View Target", pVport.ViewTarget);
2964
                writeLine(indent, "Width", pVport.Width);
2965
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
2966

    
2967
                {
2968
                    using (DBObjectCollection collection = new DBObjectCollection())
2969
                    {
2970
                        try
2971
                        {
2972
                            pVport.ExplodeGeometry(collection);
2973

    
2974
                            foreach (Entity ent in collection)
2975
                            {
2976
                                if (ent is Polyline2d)
2977
                                {
2978
                                    Polyline2d pline2d = (Polyline2d)ent;
2979
                                    int i = 0;
2980
                                    foreach (Entity ent1 in pline2d)
2981
                                    {
2982
                                        if (ent1 is Vertex2d)
2983
                                        {
2984
                                            Vertex2d vtx2d = (Vertex2d)ent1;
2985
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
2986
                                        }
2987
                                    }
2988
                                }
2989
                            }
2990
                        }
2991
                        catch (System.Exception)
2992
                        {
2993
                        }
2994
                    }
2995
                }
2996

    
2997
                node.AppendChild(VportNode);
2998
                return VportNode;
2999
            }
3000

    
3001
            return null;
3002
        }
3003

    
3004
        /************************************************************************/
3005
        /* Wipeout Dumper                                                  */
3006
        /************************************************************************/
3007
        void dump(Wipeout pWipeout, int indent)
3008
        {
3009
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3010
            dumpRasterImageData(pWipeout, indent);
3011
        }
3012

    
3013
        /************************************************************************/
3014
        /* Xline Dumper                                                         */
3015
        /************************************************************************/
3016
        void dump(Xline pXline, int indent)
3017
        {
3018
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
3019
            writeLine(indent, "Base Point", pXline.BasePoint);
3020
            writeLine(indent, "Unit Direction", pXline.UnitDir);
3021
            dumpCurveData(pXline, indent, Program.xml.DocumentElement);
3022
        }
3023

    
3024
        public void dump(Database pDb, int indent, XmlNode node)
3025
        {
3026
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3027
            {
3028
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
3029
                {
3030
                    string layoutName = "";
3031
                    layoutName = pLayout.LayoutName;
3032

    
3033
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
3034
                    LayoutNameAttr.Value = layoutName;
3035
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3036
                }
3037
            }
3038

    
3039
            dumpHeader(pDb, indent, node);
3040
            dumpLayers(pDb, indent, node);
3041
            dumpLinetypes(pDb, indent, node);
3042
            dumpTextStyles(pDb, indent, node);
3043
            dumpDimStyles(pDb, indent, node);
3044
            dumpRegApps(pDb, indent);
3045
            dumpViewports(pDb, indent, node);
3046
            dumpViews(pDb, indent, node);
3047
            dumpMLineStyles(pDb, indent);
3048
            dumpUCSTable(pDb, indent, node);
3049
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3050

    
3051
            dumpBlocks(pDb, indent, node);
3052
        }
3053

    
3054
        /************************************************************************/
3055
        /* Export DWG to PDF                                                    */
3056
        /************************************************************************/
3057
        public void ExportPDF(Database pDb, string filePath)
3058
        {
3059
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3060
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3061
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3062

    
3063
            using (mPDFExportParams param = new mPDFExportParams())
3064
            {
3065
                param.Database = pDb;
3066

    
3067
                TransactionManager tm = pDb.TransactionManager;
3068
                using (Transaction ta = tm.StartTransaction())
3069
                {
3070
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3071
                    {
3072
                        param.OutputStream = fileStrem;
3073

    
3074
                        bool embededTTF = false;
3075
                        bool shxTextAsGeometry = true;
3076
                        bool ttfGeometry = true;
3077
                        bool simpleGeomOptimization = false;
3078
                        bool zoomToExtentsMode = true;
3079
                        bool enableLayers = false;
3080
                        bool includeOffLayers = false;
3081
                        bool enablePrcMode = true;
3082
                        bool monochrome = true;
3083
                        bool allLayout = false;
3084
                        double paperWidth = 841;
3085
                        double paperHeight = 594;
3086

    
3087
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3088
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3089
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3090
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3091
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3092
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3093
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3094

    
3095
                        param.Title = "";
3096
                        param.Author = "";
3097
                        param.Subject = "";
3098
                        param.Keywords = "";
3099
                        param.Creator = "";
3100
                        param.Producer = "";
3101
                        param.UseHLR = !enablePrcMode;
3102
                        param.FlateCompression = true;
3103
                        param.ASCIIHEXEncodeStream = true;
3104
                        param.hatchDPI = 720;
3105

    
3106
                        bool bV15 = enableLayers || includeOffLayers;
3107
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3108

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

    
3152
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3153

    
3154
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3155
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3156

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

    
3188
                        int nPages = Math.Max(1, strColl.Count);
3189
                        PageParamsCollection pParCol = new PageParamsCollection();
3190
                        for (int i = 0; i < nPages; ++i)
3191
                        {
3192
                            PageParams pp = new PageParams();
3193
                            pp.setParams(paperWidth, paperHeight);
3194
                            pParCol.Add(pp);
3195
                        }
3196
                        param.PageParams = pParCol;
3197
                        Export_Import.ExportPDF(param);
3198
                    }
3199
                    ta.Abort();
3200
                }
3201
            }
3202
        }
3203

    
3204
        /************************************************************************/
3205
        /* Export DWG to PNG                                                    */
3206
        /************************************************************************/
3207
        public void ExportPNG(Database pDb, string filePath)
3208
        {
3209
            chageColorAllObjects(pDb);
3210

    
3211
            string gdPath = "WinOpenGL_20.5_15.txv";
3212

    
3213
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3214
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3215
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3216
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3217

    
3218
            using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3219
            {
3220
                if (gsModule == null)
3221
                {
3222
                    Console.WriteLine("\nCould not load graphics module {0} \nExport cancelled.", gdPath);
3223
                    return;
3224
                }
3225

    
3226
                // create graphics device
3227
                using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3228
                {
3229
                    // setup device properties
3230
                    using (Dictionary props = dev.Properties)
3231
                    {
3232
                        props.AtPut("BitPerPixel", new RxVariant(32));
3233
                    }
3234
                    using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3235
                    {
3236
                        ctx.PaletteBackground = System.Drawing.Color.White;
3237
                        ctx.SetPlotGeneration(true);
3238

    
3239
                        using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3240
                        {
3241
                            helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3242
                            int width = 9600;
3243
                            int height = 6787;
3244
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
3245
                            helperDevice.OnSize(rect);
3246

    
3247
                            if (ctx.IsPlotGeneration)
3248
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3249
                            else
3250
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3251

    
3252
                            helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3253
                            helperDevice.ActiveView.Zoom(0.99);
3254
                            helperDevice.Update();
3255

    
3256
                            Export_Import.ExportBitmap(helperDevice, bmpPath);
3257
                        }
3258
                    }
3259
                }
3260
            }
3261

    
3262
            if (File.Exists(bmpPath))
3263
            {
3264
                if (File.Exists(pngPath))
3265
                {
3266
                    File.Delete(pngPath);
3267
                }
3268

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

    
3286
                //        //create some image attributes
3287
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3288
                //        {
3289
                //            //set the color matrix attribute
3290
                //            attributes.SetColorMatrix(colorMatrix);
3291
                //            //attributes.SetThreshold(0.8F);
3292

    
3293
                //            //draw the original image on the new image
3294
                //            //using the grayscale color matrix
3295
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3296
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3297
                //        }
3298

    
3299
                //    }
3300
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3301
                //}
3302

    
3303
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3304
                {
3305
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3306
                }
3307
                if (File.Exists(bmpPath))
3308
                {
3309
                    File.Delete(bmpPath);
3310
                }
3311
            }
3312
        }
3313

    
3314
        /************************************************************************/
3315
        /* Change the color of all objects                                      */
3316
        /************************************************************************/
3317
        private void chageColorAllObjects(Database pDb)
3318
        {
3319
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3320
            {
3321
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3322
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3323

    
3324
                foreach (ObjectId id in btrModelSpace)
3325
                {
3326
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3327
                    if (ent == null) continue;
3328

    
3329
                    ent.ColorIndex = 7;
3330

    
3331
                    if (ent is BlockReference)
3332
                    {
3333
                        changeColorBlocks(tr, (BlockReference)ent);
3334
                    }
3335
                }
3336

    
3337
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3338
                foreach (DBDictionaryEntry entry in dbdic)
3339
                {
3340
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3341
                    if (group == null) continue;
3342

    
3343
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3344
                    if (idarrTags == null) continue;
3345

    
3346
                    foreach (ObjectId id in idarrTags)
3347
                    {
3348
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3349
                        if (ent == null) continue;
3350

    
3351
                        ent.ColorIndex = 7;
3352
                    }
3353
                }
3354

    
3355
                foreach (ObjectId btrId in bt)
3356
                {
3357
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3358
                    if (btr == null) continue;
3359
                    if (btr.Name.StartsWith("*")) continue;
3360

    
3361
                    foreach (ObjectId entId in btr)
3362
                    {
3363
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3364
                        if (ent == null) continue;
3365
                        ent.ColorIndex = 0;//ByBlock
3366
                    }
3367
                }
3368

    
3369
                tr.Commit();
3370
            }
3371
        }
3372

    
3373
        /************************************************************************/
3374
        /* Change the color of blocks                                           */
3375
        /************************************************************************/
3376
        private void changeColorBlocks(Transaction tr, BlockReference blkRef)
3377
        {
3378
            if (blkRef == null) return;
3379

    
3380
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3381
            {
3382
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3383
                {
3384
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3385
                    attRef.ColorIndex = 7;
3386
                }
3387
            }
3388

    
3389
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3390
            if (btrBlock == null) return;
3391

    
3392
            foreach (ObjectId oid in btrBlock)
3393
            {
3394
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3395
                if (ent == null) continue;
3396

    
3397
                ent.ColorIndex = 7;
3398

    
3399
                if (ent is BlockReference)
3400
                {
3401
                    
3402
                    changeColorBlocks(tr, (BlockReference)ent);
3403
                }
3404
            }
3405
        }
3406

    
3407
        /************************************************************************/
3408
        /* Nested block Explode & Purge                                         */
3409
        /************************************************************************/
3410
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3411
        {
3412
            HashSet<string> blockNameList = new HashSet<string>();
3413
            // Explode ModelSpace Nested Block
3414
            blockNameList = explodeNestedBlocks(pDb);
3415

    
3416
            // Prepare Block Purge
3417
            preparePurgeBlocks(pDb, blockNameList);
3418

    
3419
            // Block Purge
3420
            ObjectIdCollection oids = new ObjectIdCollection();
3421
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3422
            {
3423
                foreach (ObjectId id in pTable)
3424
                {
3425
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3426
                    oids.Add(id);
3427
                }
3428
            }
3429
            pDb.Purge(oids);
3430

    
3431
            foreach (ObjectId oid in oids)
3432
            {
3433
                if (oid.IsErased) continue;
3434

    
3435
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3436
                {
3437
                    btr.Erase(true);
3438
                }                
3439
            }
3440
        }
3441

    
3442
        private HashSet<string> explodeNestedBlocks(Database pDb)
3443
        {
3444
            HashSet<string> blockNameList = new HashSet<string>();
3445
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3446

    
3447
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3448
            {
3449
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3450
                {
3451
                    foreach (ObjectId entid in pBlock)
3452
                    {
3453
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3454
                        {
3455
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3456
                            BlockReference blockRef = (BlockReference)pEnt;
3457

    
3458
                            if (blockRef.Name.ToUpper().StartsWith("PIPING+"))
3459
                            {
3460
                                oidSet.Add(entid);
3461
                                continue;
3462
                            }
3463

    
3464
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3465
                            {
3466
                                bool isNestedBlock = false;
3467
                                foreach (ObjectId blkid in pBtr)
3468
                                {
3469
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3470
                                    {
3471
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3472
                                        {
3473
                                            oidSet.Add(entid);
3474
                                            isNestedBlock = true;
3475
                                        }
3476
                                    }
3477
                                }
3478
                                if (!isNestedBlock)
3479
                                {
3480
                                    blockNameList.Add(blockRef.Name);
3481
                                }
3482
                            }
3483
                        }
3484
                    }
3485
                }
3486
            }
3487

    
3488
            if (oidSet.Count > 0)
3489
            {
3490
                explodeBlocks(oidSet);
3491
                blockNameList = explodeNestedBlocks(pDb);
3492
            }
3493

    
3494
            return blockNameList;
3495
        }
3496

    
3497
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3498
        {
3499
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3500

    
3501
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3502
            {
3503
                foreach (ObjectId id in pTable)
3504
                {
3505
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForWrite, false, true))
3506
                    {
3507
                        if (pBlock.IsLayout) continue;
3508
                        pBlock.Explodable = true;
3509
                        if (blockNameList.Contains(pBlock.Name)) continue;
3510

    
3511
                        foreach (ObjectId entid in pBlock)
3512
                        {
3513
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3514
                            {
3515
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3516

    
3517
                                oidSet.Add(entid);
3518
                            }
3519
                        }
3520
                    }
3521
                }
3522
            }
3523

    
3524
            if (oidSet.Count > 0)
3525
            {
3526
                explodeBlocks(oidSet);
3527
                preparePurgeBlocks(pDb, blockNameList);
3528
            }
3529

    
3530
            return;
3531
        }
3532
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3533
        {
3534
            foreach (ObjectId blkId in oidSet)
3535
            {
3536
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3537
                blkRef.ExplodeGeometryToOwnerSpace();
3538
                blkRef.Erase();
3539
            }
3540
        }
3541

    
3542
        /************************************************************************/
3543
        /* Save Block as DWG For Auxiliary Graphic                              */
3544
        /************************************************************************/
3545
        public void ExportGraphicBlocks(Database pDb, string savePath)
3546
        {
3547
            try
3548
            {
3549
                using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3550
                {
3551
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3552
                    {
3553
                        foreach (ObjectId entid in pBlock)
3554
                        {
3555
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3556
                            {
3557
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3558
                                BlockReference blockRef = (BlockReference)pEnt;
3559
                                if (!blockRef.Name.ToUpper().StartsWith("GRAPHIC+"))
3560
                                    continue;
3561

    
3562
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3563
                                objIdCol.Add(blockRef.ObjectId);
3564
                                if (objIdCol.Count == 0) continue;
3565

    
3566
                                string filePath = string.Format("{0}.dwg", blockRef.Name);
3567
                                string directory = Path.GetDirectoryName(savePath);
3568
                                directory = directory.ToLower().Replace("drawings", "graphic");
3569
                                if (!Directory.Exists(directory))
3570
                                {
3571
                                    Directory.CreateDirectory(directory);
3572
                                }
3573
                                filePath = Path.Combine(directory, filePath);
3574
                                
3575
                                using (Database newDb = new Database(true, false))
3576
                                {
3577
                                    pDb.Wblock(newDb, objIdCol, Point3d.Origin, DuplicateRecordCloning.Ignore);
3578
                                    newDb.UpdateExt(true);
3579
                                    newDb.SaveAs(filePath, DwgVersion.Newest);
3580
                                }
3581

    
3582
                                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo();
3583
                                procStartInfo.FileName = @"C:\Program Files (x86)\SmartSketch\Program\Rad2d\bin\Dwg2Igr.exe";
3584
                                procStartInfo.RedirectStandardOutput = true;
3585
                                procStartInfo.RedirectStandardInput = true;
3586
                                procStartInfo.RedirectStandardError = true;
3587
                                procStartInfo.UseShellExecute = false;
3588
                                procStartInfo.CreateNoWindow = false;
3589
                                procStartInfo.Arguments = filePath.Replace(" ", "^");
3590

    
3591
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3592
                                {
3593
                                    proc.StartInfo = procStartInfo;
3594
                                    proc.Start();
3595
                                    proc.StandardInput.Close();
3596
                                    proc.WaitForExit();
3597

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

    
3637
                /**********************************************************************/
3638
                /* Step through the BlockTable                                        */
3639
                /**********************************************************************/
3640
                foreach (ObjectId id in pTable)
3641
                {
3642
                    /********************************************************************/
3643
                    /* Open the BlockTableRecord for Reading                            */
3644
                    /********************************************************************/
3645
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3646
                    {
3647
                        /********************************************************************/
3648
                        /* Dump the BlockTableRecord                                        */
3649
                        /********************************************************************/
3650
                        XmlElement BlockNode = Program.xml.CreateElement(pBlock.GetRXClass().Name);
3651

    
3652
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
3653
                        NameAttr.Value = pBlock.Name;
3654
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3655

    
3656
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3657
                        CommentsAttr.Value = pBlock.Comments;
3658
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3659

    
3660
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3661
                        OriginAttr.Value = pBlock.Origin.ToString();
3662
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3663

    
3664
                        writeLine(indent, pBlock.GetRXClass().Name);
3665
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3666
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3667
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3668
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3669
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3670

    
3671
                        try
3672
                        {
3673
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3674
                            extents.AddBlockExtents(pBlock);
3675

    
3676
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3677
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3678
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3679

    
3680
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3681
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3682
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3683
                        }
3684
                        catch (System.Exception)
3685
                        {
3686
                        }
3687

    
3688
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3689
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3690
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3691
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3692
                        {
3693
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3694
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3695
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3696
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3697
                        }
3698

    
3699
                        /********************************************************************/
3700
                        /* Step through the BlockTableRecord                                */
3701
                        /********************************************************************/
3702
                        foreach (ObjectId entid in pBlock)
3703
                        {
3704
                            /********************************************************************/
3705
                            /* Dump the Entity                                                  */
3706
                            /********************************************************************/
3707
                            dumpEntity(entid, indent + 1, BlockNode);
3708
                        }
3709

    
3710
                        BlocksNode.AppendChild(BlockNode);
3711
                    }
3712
                }
3713

    
3714
                node.AppendChild(BlocksNode);
3715
            }
3716
        }
3717

    
3718
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3719
        {
3720
            /**********************************************************************/
3721
            /* Get a SmartPointer to the DimStyleTable                            */
3722
            /**********************************************************************/
3723
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3724
            {
3725
                /**********************************************************************/
3726
                /* Dump the Description                                               */
3727
                /**********************************************************************/
3728
                writeLine();
3729
                writeLine(indent++, pTable.GetRXClass().Name);
3730

    
3731
                /**********************************************************************/
3732
                /* Step through the DimStyleTable                                    */
3733
                /**********************************************************************/
3734
                foreach (ObjectId id in pTable)
3735
                {
3736
                    /*********************************************************************/
3737
                    /* Open the DimStyleTableRecord for Reading                         */
3738
                    /*********************************************************************/
3739
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3740
                    {
3741
                        /*********************************************************************/
3742
                        /* Dump the DimStyleTableRecord                                      */
3743
                        /*********************************************************************/
3744
                        writeLine();
3745
                        writeLine(indent, pRecord.GetRXClass().Name);
3746
                        writeLine(indent, "Name", pRecord.Name);
3747
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3748

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

    
3822
                        dumpSymbolTableRecord(pRecord, indent, node);
3823
                    }
3824
                }
3825
            }
3826
        }
3827

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

    
3988
                    /**********************************************************************/
3989
                    /* Dump the Extension Dictionary                                      */
3990
                    /**********************************************************************/
3991
                    if (!pEnt.ExtensionDictionary.IsNull)
3992
                    {
3993
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
3994
                    }
3995
                }
3996
            }
3997
            catch (System.Exception ex)
3998
            {
3999
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
4000
            }
4001
        }
4002
        public void dumpHeader(Database pDb, int indent, XmlNode node)
4003
        {
4004
            if (node != null)
4005
            {
4006
                XmlAttribute FileNameAttr = Program.xml.CreateAttribute("FileName");
4007
                FileNameAttr.Value = shortenPath(pDb.Filename);
4008
                node.Attributes.SetNamedItem(FileNameAttr);
4009

    
4010
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
4011
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4012
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4013

    
4014
                writeLine();
4015
                writeLine(indent++, "Header Variables:");
4016

    
4017
                //writeLine();
4018
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4019
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4020

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

    
4176
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4177
        {
4178
            if (node != null)
4179
            {
4180
                /**********************************************************************/
4181
                /* Get a SmartPointer to the LayerTable                               */
4182
                /**********************************************************************/
4183
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4184
                {
4185
                    /**********************************************************************/
4186
                    /* Dump the Description                                               */
4187
                    /**********************************************************************/
4188
                    XmlElement LayerNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4189

    
4190
                    /**********************************************************************/
4191
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4192
                    /**********************************************************************/
4193

    
4194
                    /**********************************************************************/
4195
                    /* Step through the LayerTable                                        */
4196
                    /**********************************************************************/
4197
                    foreach (ObjectId id in pTable)
4198
                    {
4199
                        /********************************************************************/
4200
                        /* Open the LayerTableRecord for Reading                            */
4201
                        /********************************************************************/
4202
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4203
                        {
4204
                            /********************************************************************/
4205
                            /* Dump the LayerTableRecord                                        */
4206
                            /********************************************************************/
4207
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4208

    
4209
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4210
                            NameAttr.Value = pRecord.Name.ToString();
4211
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4212

    
4213
                            XmlAttribute IsUsedAttr = Program.xml.CreateAttribute("IsUsed");
4214
                            IsUsedAttr.Value = pRecord.IsUsed.ToString();
4215
                            RecordNode.Attributes.SetNamedItem(IsUsedAttr);
4216

    
4217
                            XmlAttribute IsOffAttr = Program.xml.CreateAttribute("IsOff");
4218
                            IsOffAttr.Value = pRecord.IsOff.ToString();
4219
                            RecordNode.Attributes.SetNamedItem(IsOffAttr);
4220

    
4221
                            XmlAttribute IsFrozenAttr = Program.xml.CreateAttribute("IsFrozen");
4222
                            IsFrozenAttr.Value = pRecord.IsFrozen.ToString();
4223
                            RecordNode.Attributes.SetNamedItem(IsFrozenAttr);
4224

    
4225
                            XmlAttribute IsLockedAttr = Program.xml.CreateAttribute("IsLocked");
4226
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4227
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4228

    
4229
                            XmlAttribute ColorAttr = Program.xml.CreateAttribute("Color");
4230
                            ColorAttr.Value = pRecord.Color.ToString();
4231
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4232

    
4233
                            XmlAttribute LinetypeObjectIdAttr = Program.xml.CreateAttribute("LinetypeObjectId");
4234
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4235
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4236

    
4237
                            XmlAttribute LineWeightAttr = Program.xml.CreateAttribute("LineWeight");
4238
                            LineWeightAttr.Value = pRecord.LineWeight.ToString();
4239
                            RecordNode.Attributes.SetNamedItem(LineWeightAttr);
4240

    
4241
                            XmlAttribute PlotStyleNameAttr = Program.xml.CreateAttribute("PlotStyleName");
4242
                            PlotStyleNameAttr.Value = pRecord.PlotStyleName.ToString();
4243
                            RecordNode.Attributes.SetNamedItem(PlotStyleNameAttr);
4244

    
4245
                            XmlAttribute IsPlottableAttr = Program.xml.CreateAttribute("IsPlottable");
4246
                            IsPlottableAttr.Value = pRecord.IsPlottable.ToString();
4247
                            RecordNode.Attributes.SetNamedItem(IsPlottableAttr);
4248

    
4249
                            XmlAttribute ViewportVisibilityDefaultAttr = Program.xml.CreateAttribute("ViewportVisibilityDefault");
4250
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4251
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4252

    
4253
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4254
                            LayerNode.AppendChild(RecordNode);
4255
                        }
4256
                    }
4257

    
4258
                    node.AppendChild(LayerNode);
4259
                }
4260
            }
4261
        }
4262

    
4263
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4264
        {
4265
            if (node != null)
4266
            {
4267
                /**********************************************************************/
4268
                /* Get a pointer to the LinetypeTable                            */
4269
                /**********************************************************************/
4270
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4271
                {
4272
                    XmlElement LinetypeNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4273

    
4274
                    /**********************************************************************/
4275
                    /* Step through the LinetypeTable                                     */
4276
                    /**********************************************************************/
4277
                    foreach (ObjectId id in pTable)
4278
                    {
4279
                        /*********************************************************************/
4280
                        /* Open the LinetypeTableRecord for Reading                          */
4281
                        /*********************************************************************/
4282
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4283
                        {
4284
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4285

    
4286
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4287
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4288
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4289

    
4290
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4291
                            NameAttr.Value = pRecord.Name;
4292
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4293

    
4294
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4295
                            CommentsAttr.Value = pRecord.Comments;
4296
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4297

    
4298
                            /********************************************************************/
4299
                            /* Dump the first line of record as in ACAD.LIN                     */
4300
                            /********************************************************************/
4301
                            string buffer = "*" + pRecord.Name;
4302
                            if (pRecord.Comments != "")
4303
                            {
4304
                                buffer = buffer + "," + pRecord.Comments;
4305
                            }
4306
                            writeLine(indent, buffer);
4307

    
4308
                            /********************************************************************/
4309
                            /* Dump the second line of record as in ACAD.LIN                    */
4310
                            /********************************************************************/
4311
                            if (pRecord.NumDashes > 0)
4312
                            {
4313
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4314
                                for (int i = 0; i < pRecord.NumDashes; i++)
4315
                                {
4316
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4317
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4318
                                    string text = pRecord.TextAt(i);
4319

    
4320
                                    /**************************************************************/
4321
                                    /* Dump the Complex Line                                      */
4322
                                    /**************************************************************/
4323
                                    if (shapeNumber != 0 || text != "")
4324
                                    {
4325
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4326
                                        {
4327
                                            if (shapeNumber != 0)
4328
                                            {
4329
                                                buffer = buffer + ",[" + shapeNumber + ",";
4330
                                                if (pTextStyle != null)
4331
                                                    buffer = buffer + pTextStyle.FileName;
4332
                                                else
4333
                                                    buffer = buffer + "NULL style";
4334
                                            }
4335
                                            else
4336
                                            {
4337
                                                buffer = buffer + ",[" + text + ",";
4338
                                                if (pTextStyle != null)
4339
                                                    buffer = buffer + pTextStyle.Name;
4340
                                                else
4341
                                                    buffer = buffer + "NULL style";
4342
                                            }
4343
                                        }
4344

    
4345
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4346
                                        {
4347
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4348
                                        }
4349
                                        if (pRecord.ShapeRotationAt(i) != 0)
4350
                                        {
4351
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4352
                                        }
4353
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4354
                                        {
4355
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4356
                                        }
4357
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4358
                                        {
4359
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4360
                                        }
4361
                                        buffer = buffer + "]";
4362
                                    }
4363
                                }
4364
                                writeLine(indent, buffer);
4365
                            }
4366
                            dumpSymbolTableRecord(pRecord, indent, node);
4367
                            LinetypeNode.AppendChild(RecordNode);
4368
                        }
4369
                    }
4370

    
4371
                    node.AppendChild(LinetypeNode);
4372
                }
4373
            }
4374
        }
4375

    
4376
        public void dumpRegApps(Database pDb, int indent)
4377
        {
4378
            /**********************************************************************/
4379
            /* Get a pointer to the RegAppTable                            */
4380
            /**********************************************************************/
4381
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4382
            {
4383
                /**********************************************************************/
4384
                /* Dump the Description                                               */
4385
                /**********************************************************************/
4386
                writeLine();
4387
                writeLine(indent++, pTable.GetRXClass().Name);
4388

    
4389
                /**********************************************************************/
4390
                /* Step through the RegAppTable                                    */
4391
                /**********************************************************************/
4392
                foreach (ObjectId id in pTable)
4393
                {
4394
                    /*********************************************************************/
4395
                    /* Open the RegAppTableRecord for Reading                         */
4396
                    /*********************************************************************/
4397
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4398
                    {
4399
                        /*********************************************************************/
4400
                        /* Dump the RegAppTableRecord                                      */
4401
                        /*********************************************************************/
4402
                        writeLine();
4403
                        writeLine(indent, pRecord.GetRXClass().Name);
4404
                        writeLine(indent, "Name", pRecord.Name);
4405
                    }
4406
                }
4407
            }
4408
        }
4409

    
4410
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4411
        {
4412
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4413
            if (pRecord.IsDependent)
4414
            {
4415
                writeLine(indent, "Resolved", pRecord.IsResolved);
4416
            }
4417
        }
4418

    
4419
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4420
        {
4421
            /**********************************************************************/
4422
            /* Get a SmartPointer to the TextStyleTable                            */
4423
            /**********************************************************************/
4424
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4425
            {
4426
                /**********************************************************************/
4427
                /* Dump the Description                                               */
4428
                /**********************************************************************/
4429
                writeLine();
4430
                writeLine(indent++, pTable.GetRXClass().Name);
4431

    
4432
                /**********************************************************************/
4433
                /* Step through the TextStyleTable                                    */
4434
                /**********************************************************************/
4435
                foreach (ObjectId id in pTable)
4436
                {
4437
                    /*********************************************************************/
4438
                    /* Open the TextStyleTableRecord for Reading                         */
4439
                    /*********************************************************************/
4440
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4441
                    {
4442
                        /*********************************************************************/
4443
                        /* Dump the TextStyleTableRecord                                      */
4444
                        /*********************************************************************/
4445
                        writeLine();
4446
                        writeLine(indent, pRecord.GetRXClass().Name);
4447
                        writeLine(indent, "Name", pRecord.Name);
4448
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4449
                        writeLine(indent, "Text Height", pRecord.TextSize);
4450
                        writeLine(indent, "Width Factor", pRecord.XScale);
4451
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4452
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4453
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4454
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4455
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4456
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4457

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

    
4487
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4488
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4489

    
4490
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4491
            {
4492
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4493
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4494
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4495
            }
4496

    
4497
            writeLine(indent, "Target", pView.Target);
4498
            writeLine(indent, "View Direction", pView.ViewDirection);
4499
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4500
            dumpSymbolTableRecord(pView, indent, node);
4501
        }
4502
        public void dumpDimAssoc(DBObject pObject, int indent)
4503
        {
4504

    
4505
        }
4506
        public void dumpMLineStyles(Database pDb, int indent)
4507
        {
4508
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4509
            {
4510
                /**********************************************************************/
4511
                /* Dump the Description                                               */
4512
                /**********************************************************************/
4513
                writeLine();
4514
                writeLine(indent++, pDictionary.GetRXClass().Name);
4515

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

    
4578
                /**********************************************************************/
4579
                /* Dispatch                                                           */
4580
                /**********************************************************************/
4581
                if (pObject is DBDictionary)
4582
                {
4583
                    /********************************************************************/
4584
                    /* Dump the dictionary                                               */
4585
                    /********************************************************************/
4586
                    DBDictionary pDic = (DBDictionary)pObject;
4587

    
4588
                    /********************************************************************/
4589
                    /* Get a pointer to a new DictionaryIterator                   */
4590
                    /********************************************************************/
4591
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4592

    
4593
                    /********************************************************************/
4594
                    /* Step through the Dictionary                                      */
4595
                    /********************************************************************/
4596
                    while (pIter.MoveNext())
4597
                    {
4598
                        /******************************************************************/
4599
                        /* Dump the Dictionary object                                     */
4600
                        /******************************************************************/
4601
                        dumpObject(pIter.Value, pIter.Key, indent);
4602
                    }
4603
                }
4604
                else if (pObject is Xrecord)
4605
                {
4606
                    /********************************************************************/
4607
                    /* Dump an Xrecord                                                  */
4608
                    /********************************************************************/
4609
                    Xrecord pXRec = (Xrecord)pObject;
4610
                    dumpXdata(pXRec.Data, indent);
4611
                }
4612
            }
4613
        }
4614

    
4615
        public void dumpUCSTable(Database pDb, int indent, XmlNode node)
4616
        {
4617
            /**********************************************************************/
4618
            /* Get a pointer to the UCSTable                               */
4619
            /**********************************************************************/
4620
            using (UcsTable pTable = (UcsTable)pDb.UcsTableId.Open(OpenMode.ForRead))
4621
            {
4622
                /**********************************************************************/
4623
                /* Dump the Description                                               */
4624
                /**********************************************************************/
4625
                writeLine();
4626
                writeLine(indent++, pTable.GetRXClass().Name);
4627

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

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

    
4703
        /************************************************************************/
4704
        /* Dump the ViewTable                                                   */
4705
        /************************************************************************/
4706
        public void dumpViews(Database pDb, int indent, XmlNode node)
4707
        {
4708
            /**********************************************************************/
4709
            /* Get a pointer to the ViewTable                                */
4710
            /**********************************************************************/
4711
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
4712
            {
4713
                /**********************************************************************/
4714
                /* Dump the Description                                               */
4715
                /**********************************************************************/
4716
                writeLine();
4717
                writeLine(indent++, pTable.GetRXClass().Name);
4718

    
4719
                /**********************************************************************/
4720
                /* Step through the ViewTable                                         */
4721
                /**********************************************************************/
4722
                foreach (ObjectId id in pTable)
4723
                {
4724
                    /*********************************************************************/
4725
                    /* Open the ViewTableRecord for Reading                              */
4726
                    /*********************************************************************/
4727
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
4728
                    {
4729
                        /*********************************************************************/
4730
                        /* Dump the ViewTableRecord                                          */
4731
                        /*********************************************************************/
4732
                        writeLine();
4733
                        writeLine(indent, pRecord.GetRXClass().Name);
4734
                        writeLine(indent, "Name", pRecord.Name);
4735
                        writeLine(indent, "Category Name", pRecord.CategoryName);
4736
                        writeLine(indent, "Layer State", pRecord.LayerState);
4737

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

    
4783
    class Program
4784
    {
4785
        public static XmlDocument xml = null;
4786
        public static double OffsetX = 0;
4787
        public static double OffsetY = 0;
4788
        public static double Scale = 0;
4789
        public static double getDrawing = 0;
4790
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
4791

    
4792
        static void Main(string[] args)
4793
        {
4794
            /********************************************************************/
4795
            /* Initialize Drawings.NET.                                         */
4796
            /********************************************************************/
4797
            bool bSuccess = true;
4798
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
4799
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
4800
            {
4801
                try
4802
                {
4803
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
4804
                    /**********************************************************************/
4805
                    /* Display the Product and Version that created the executable        */
4806
                    /**********************************************************************/
4807
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
4808

    
4809
                    if (args.Length != 5)
4810
                    {
4811
                        Console.WriteLine("\n\n\tusage: OdReadExMgd <filename> <OffsetX> <OffsetY> <Scale> <GenDrawing>");
4812
                        Console.WriteLine("\nPress ENTER to continue...\n");
4813
                        Console.ReadLine();
4814
                        bSuccess = false;
4815
                    }
4816
                    else
4817
                    {
4818
                        Console.WriteLine("\n File Name = " + args[0]);
4819

    
4820
                        double.TryParse(args[1], out Program.OffsetX);
4821
                        double.TryParse(args[2], out Program.OffsetY);
4822
                        double.TryParse(args[3], out Program.Scale);
4823
                        double.TryParse(args[4], out Program.getDrawing);
4824
                        Program.xml = new XmlDocument();
4825
                        {
4826
                            XmlNode root = xml.CreateElement("ID2");
4827
                            Program.xml.AppendChild(root);
4828

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

    
4856
                                dumper.dump(pDb, 0, Program.xml.DocumentElement);
4857
                            }
4858
                            Program.xml.Save(Path.Combine(Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]) + ".xml"));
4859
                        }
4860
                    }
4861
                }
4862
                /********************************************************************/
4863
                /* Display the error                                                */
4864
                /********************************************************************/
4865
                catch (System.Exception e)
4866
                {
4867
                    bSuccess = false;
4868
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
4869
                }
4870

    
4871
                if (bSuccess)
4872
                    Console.WriteLine("OdReadExMgd Finished Successfully");
4873
            }
4874
        }
4875
    }
4876
}
클립보드 이미지 추가 (최대 크기: 500 MB)