프로젝트

일반

사용자정보

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

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ 64fbc9f0

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

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

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

    
48
        public DbDumper() { }
49

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

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

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

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

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

    
128
            const int tabSize = 2;
129

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
302
                dumpEntityData(pText, indent, TextNode);
303

    
304
                node.AppendChild(TextNode);
305
            }
306

    
307
            return TextNode;
308
        }
309

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

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

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

    
335
        /************************************************************************/
336
        /* Dump AttributeDefinition Data                                                         */
337
        /************************************************************************/
338
        void dump(AttributeDefinition pAttDef, int indent)
339
        {
340
            writeLine(indent, "Field Length", pAttDef.FieldLength);
341
            writeLine(indent, "Invisible", pAttDef.Invisible);
342
            writeLine(indent, "Locked in Position", pAttDef.LockPositionInBlock);
343

    
344
            using (var text = new DBText())
345
            {
346
                text.SetPropertiesFrom(pAttDef);
347
                text.TextStyleId = pAttDef.TextStyleId;
348
                text.Position = pAttDef.Position;
349
                text.Rotation = pAttDef.Rotation;
350
                text.WidthFactor = pAttDef.WidthFactor;
351
                text.Height = pAttDef.Height;
352
                text.Thickness = pAttDef.Thickness;
353
                text.Justify = pAttDef.Justify;
354
                text.TextString = !string.IsNullOrWhiteSpace(pAttDef.TextString.Replace("*", "")) ? pAttDef.TextString : pAttDef.Tag;
355
                if (pAttDef.Justify != AttachmentPoint.BaseLeft)
356
                    text.AlignmentPoint = pAttDef.AlignmentPoint;
357
                dumpTextData(text, indent, Program.xml.DocumentElement);
358
            }
359
        }
360
        /************************************************************************/
361
        /* Dump Block Reference Data                                             */
362
        /************************************************************************/
363
        static XmlNode dumpBlockRefData(BlockReference pBlkRef, int indent, XmlNode node)
364
        {
365
            if (node != null)
366
            {
367
                XmlNode BlockReferenceNode = Program.xml.CreateElement(pBlkRef.GetRXClass().Name);
368

    
369
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
370
                HandleAttr.Value = pBlkRef.Handle.ToString();
371
                BlockReferenceNode.Attributes.SetNamedItem(HandleAttr);
372

    
373
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
374
                XAttr.Value = pBlkRef.Position.X.ToString();
375
                BlockReferenceNode.Attributes.SetNamedItem(XAttr);
376

    
377
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
378
                YAttr.Value = pBlkRef.Position.Y.ToString();
379
                BlockReferenceNode.Attributes.SetNamedItem(YAttr);
380

    
381
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
382
                ZAttr.Value = pBlkRef.Position.Z.ToString();
383
                BlockReferenceNode.Attributes.SetNamedItem(ZAttr);
384

    
385
                XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
386
                AngleAttr.Value = pBlkRef.Rotation.ToString();
387
                BlockReferenceNode.Attributes.SetNamedItem(AngleAttr);
388

    
389
                XmlAttribute ScaleFactorsAttr = Program.xml.CreateAttribute("ScaleFactors");
390
                ScaleFactorsAttr.Value = pBlkRef.ScaleFactors.ToString();
391
                BlockReferenceNode.Attributes.SetNamedItem(ScaleFactorsAttr);
392

    
393
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
394
                NormalAttr.Value = pBlkRef.Normal.ToString();
395
                BlockReferenceNode.Attributes.SetNamedItem(NormalAttr);
396

    
397
                XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
398
                NameAttr.Value = pBlkRef.Name;
399
                BlockReferenceNode.Attributes.SetNamedItem(NameAttr);
400

    
401
                // BlockReference DBPoint
402
                string nodePointValue = string.Empty;
403
                Dictionary<long, Point3d> nodePointDic = new Dictionary<long, Point3d>();
404
                using (BlockTableRecord pBtr = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
405
                {
406
                    foreach (ObjectId blkid in pBtr)
407
                    {
408
                        using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
409
                        {
410
                            if (pBlkEnt.GetRXClass().Name == "AcDbPoint")
411
                            {
412
                                DBPoint pt = (DBPoint)pBlkEnt;
413
                                Point3d nodePt = pt.Position.TransformBy(pBlkRef.BlockTransform);
414
                                nodePointDic.Add(Convert.ToInt64(pt.Handle.ToString(), 16), nodePt);
415
                            }
416
                        }
417
                    }
418
                }
419
                if (nodePointDic.Count > 0)
420
                {
421
                    foreach (KeyValuePair<long, Point3d> item in nodePointDic.OrderBy(o => o.Key))
422
                    {
423
                        nodePointValue += item.Value.ToString() + "/";
424
                    }
425
                    nodePointValue = nodePointValue.Substring(0, nodePointValue.Length - 1);
426
                }
427

    
428
                XmlAttribute NodePointAttr = Program.xml.CreateAttribute("Nodes");
429
                NodePointAttr.Value = nodePointValue;
430
                BlockReferenceNode.Attributes.SetNamedItem(NodePointAttr);
431

    
432
                Matrix3d blockTransform = pBlkRef.BlockTransform;
433
                CoordinateSystem3d cs = blockTransform.CoordinateSystem3d;
434
                writeLine(indent + 1, "Origin", cs.Origin);
435
                writeLine(indent + 1, "u-Axis", cs.Xaxis);
436
                writeLine(indent + 1, "v-Axis", cs.Yaxis);
437
                writeLine(indent + 1, "z-Axis", cs.Zaxis);
438

    
439
                dumpEntityData(pBlkRef, indent, BlockReferenceNode);
440

    
441
                DBObjectCollection objColl = new DBObjectCollection();
442

    
443
                if (!pBlkRef.Name.StartsWith(BLOCK_GRAPHIC))
444
                {
445
                    pBlkRef.Explode(objColl);
446
                    foreach (var obj in objColl)
447
                    {
448
                        if (obj is DBText)
449
                        {
450
                            dumpTextData(obj as DBText, indent, BlockReferenceNode);
451
                        }
452
                        else if (obj is MText)
453
                        {
454
                            MText mtext = obj as MText;
455

    
456
                            DBObjectCollection objs = new DBObjectCollection();
457
                            mtext.Explode(objs);
458
                            foreach (var item in objs)
459
                            {
460
                                dumpTextData(item as DBText, indent, node);
461
                            }
462
                        }
463
                    }
464
                }
465

    
466
                /**********************************************************************/
467
                /* Dump the attributes                                                */
468
                /**********************************************************************/
469
                int i = 0;
470
                AttributeCollection attCol = pBlkRef.AttributeCollection;
471
                foreach (ObjectId id in attCol)
472
                {
473
                    try
474
                    {
475
                        using (AttributeReference pAttr = (AttributeReference)id.Open(OpenMode.ForRead))
476
                            dumpAttributeData(indent, pAttr, i++, BlockReferenceNode);
477
                    }
478
                    catch (System.Exception)
479
                    {
480

    
481
                    }
482
                }
483

    
484
                node.AppendChild(BlockReferenceNode);
485

    
486
                return BlockReferenceNode;
487
            }
488

    
489
            return null;
490
        }
491
        /************************************************************************/
492
        /* Dump data common to all OdDbCurves                                   */
493
        /************************************************************************/
494
        static void dumpCurveData(Entity pEnt, int indent, XmlNode node)
495
        {
496
            if (node != null)
497
            {
498
                Curve pEntity = (Curve)pEnt;
499
                try
500
                {
501
                    writeLine(indent, "Start Point", pEntity.StartPoint);
502
                    writeLine(indent, "End Point", pEntity.EndPoint);
503
                }
504
                catch (System.Exception)
505
                {
506
                }
507
                writeLine(indent, "Closed", pEntity.Closed);
508
                writeLine(indent, "Periodic", pEntity.IsPeriodic);
509

    
510
                try
511
                {
512
                    writeLine(indent, "Area", pEntity.Area);
513
                }
514
                catch (System.Exception)
515
                {
516
                }
517
                dumpEntityData(pEntity, indent, node);
518
            }
519
        }
520

    
521
        /************************************************************************/
522
        /* Dump Dimension data                                                  */
523
        /************************************************************************/
524
        static XmlNode dumpDimData(Dimension pDim, int indent, XmlNode node)
525
        {
526
            if (node != null)
527
            {
528
                XmlElement DimDataNode = Program.xml.CreateElement("DimData");
529

    
530
                XmlAttribute CurrentMeasurementAttr = Program.xml.CreateAttribute("CurrentMeasurement");
531
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
532
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
533

    
534
                XmlAttribute DimensionTextAttr = Program.xml.CreateAttribute("DimensionText");
535
                DimensionTextAttr.Value = pDim.DimensionText.ToString();
536
                DimDataNode.Attributes.SetNamedItem(DimensionTextAttr);
537

    
538
                if (pDim.CurrentMeasurement >= 0.0)
539
                {
540
                    XmlAttribute FormattedMeasurementAttr = Program.xml.CreateAttribute("FormattedMeasurement");
541
                    FormattedMeasurementAttr.Value = pDim.FormatMeasurement(pDim.CurrentMeasurement, pDim.DimensionText);
542
                    DimDataNode.Attributes.SetNamedItem(FormattedMeasurementAttr);
543
                }
544
                if (pDim.DimBlockId.IsNull)
545
                {
546
                    writeLine(indent, "Dimension Block NULL");
547
                }
548
                else
549
                {
550
                    using (BlockTableRecord btr = (BlockTableRecord)pDim.DimBlockId.Open(OpenMode.ForRead))
551
                    {
552
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
553
                        NameAttr.Value = btr.Name;
554
                        DimDataNode.Attributes.SetNamedItem(NameAttr);
555
                    }
556
                }
557

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

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

    
566
                XmlAttribute TextRotationAttr = Program.xml.CreateAttribute("TextRotation");
567
                TextRotationAttr.Value = pDim.TextRotation.ToString();
568
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
569

    
570
                XmlAttribute DimensionStyleNameAttr = Program.xml.CreateAttribute("DimensionStyleName");
571
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
572
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
573

    
574
                XmlAttribute DimtfillclrAttr = Program.xml.CreateAttribute("Dimtfillclr");
575
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
576
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
577

    
578
                XmlAttribute DimtfillAttr = Program.xml.CreateAttribute("Dimtfill");
579
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
580
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
581

    
582
                XmlAttribute Dimltex1Attr = Program.xml.CreateAttribute("Dimltex1");
583
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
584
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
585

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

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

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

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

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

    
606
                dumpEntityData(pDim, indent, node);
607

    
608
                return DimDataNode;
609
            }
610

    
611
            return null;
612
        }
613

    
614
        /************************************************************************/
615
        /* 2 Line Angular Dimension Dumper                                      */
616
        /************************************************************************/
617
        static XmlNode dump(LineAngularDimension2 pDim, int indent, XmlNode node)
618
        {
619
            if (node != null)
620
            {
621
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
622

    
623
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
624
                HandleAttr.Value = pDim.Handle.ToString();
625
                DimNode.Attributes.SetNamedItem(HandleAttr);
626

    
627
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
628
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
629
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
630

    
631
                XmlAttribute XLine1StartAttr = Program.xml.CreateAttribute("XLine1Start");
632
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
633
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
634

    
635
                XmlAttribute XLine1EndAttr = Program.xml.CreateAttribute("XLine1End");
636
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
637
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
638

    
639
                XmlAttribute XLine2StartAttr = Program.xml.CreateAttribute("XLine2Start");
640
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
641
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
642

    
643
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
644
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
645
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
646

    
647
                dumpDimData(pDim, indent, DimNode);
648

    
649
                return DimNode;
650
            }
651

    
652
            return null;
653
        }
654

    
655
        /************************************************************************/
656
        /* Dump 2D Vertex data                                                  */
657
        /************************************************************************/
658
        static XmlNode dump2dVertex(int indent, Vertex2d pVertex, int i, XmlNode node)
659
        {
660
            if (node != null)
661
            {
662
                XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
663

    
664
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
665
                HandleAttr.Value = pVertex.Handle.ToString();
666
                VertexNode.Attributes.SetNamedItem(HandleAttr);
667

    
668
                XmlAttribute VertexTypeAttr = Program.xml.CreateAttribute("VertexType");
669
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
670
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
671

    
672
                XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
673
                PositionAttr.Value = pVertex.Position.ToString();
674
                VertexNode.Attributes.SetNamedItem(PositionAttr);
675

    
676
                XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
677
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
678
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
679

    
680
                XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
681
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
682
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
683

    
684
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
685
                BulgeAttr.Value = pVertex.Bulge.ToString();
686
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
687

    
688
                if (pVertex.Bulge != 0)
689
                {
690
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
691
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
692
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
693
                }
694

    
695
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
696
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
697
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
698
                if (pVertex.TangentUsed)
699
                {
700
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
701
                    TangentAttr.Value = pVertex.Tangent.ToString();
702
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
703
                }
704

    
705
                node.AppendChild(VertexNode);
706

    
707
                return VertexNode;
708
            }
709

    
710
            return null;
711
        }
712

    
713
        /************************************************************************/
714
        /* 2D Polyline Dumper                                                   */
715
        /************************************************************************/
716
        static XmlNode dump(Polyline2d pPolyline, int indent, XmlNode node)
717
        {
718
            /********************************************************************/
719
            /* Dump the vertices                                                */
720
            /********************************************************************/
721
            List<Vertex2d> Vertices = new List<Vertex2d>();
722
            int i = 0;
723
            foreach (ObjectId obj in pPolyline)
724
            {
725
                using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
726
                {
727
                    if (dbObj is Vertex2d)
728
                    {
729
                        Vertices.Add((Vertex2d)dbObj);
730
                        /// dump2dVertex(indent, (Vertex2d)dbObj, i++);
731
                    }
732
                }
733
            }
734

    
735
            if (node != null)
736
            {
737
                XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
738

    
739
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
740
                HandleAttr.Value = pPolyline.Handle.ToString();
741
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
742

    
743
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
744
                CountAttr.Value = Vertices.Count.ToString();
745
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
746

    
747
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
748
                ElevationAttr.Value = pPolyline.Elevation.ToString();
749
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
750

    
751
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
752
                NormalAttr.Value = pPolyline.Normal.ToString();
753
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
754

    
755
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
756
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
757
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
758

    
759
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
760
                ClosedAttr.Value = pPolyline.Closed.ToString();
761
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
762

    
763
                foreach (var vt in Vertices)
764
                {
765
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
766

    
767
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
768
                    XAttr.Value = vt.Position.X.ToString();
769
                    VertexNode.Attributes.SetNamedItem(XAttr);
770

    
771
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
772
                    YAttr.Value = vt.Position.Y.ToString();
773
                    VertexNode.Attributes.SetNamedItem(YAttr);
774

    
775
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
776
                    ZAttr.Value = vt.Position.Z.ToString();
777
                    VertexNode.Attributes.SetNamedItem(ZAttr);
778

    
779
                    Polyline2dNode.AppendChild(VertexNode);
780
                }
781

    
782
                dumpCurveData(pPolyline, indent, node);
783

    
784
                node.AppendChild(Polyline2dNode);
785

    
786
                return Polyline2dNode;
787
            }
788

    
789
            return null;
790
        }
791

    
792

    
793
        /************************************************************************/
794
        /* Dump 3D Polyline Vertex data                                         */
795
        /************************************************************************/
796
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
797
        {
798
            if (node != null)
799
            {
800
                XmlNode VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
801

    
802
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
803
                HandleAttr.Value = pVertex.Handle.ToString();
804
                VertexNode.Attributes.SetNamedItem(HandleAttr);
805

    
806
                XmlAttribute VertexxTypeAttr = Program.xml.CreateAttribute("VertexType");
807
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
808
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
809

    
810
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
811
                XAttr.Value = pVertex.Position.X.ToString();
812
                VertexNode.Attributes.SetNamedItem(XAttr);
813

    
814
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
815
                YAttr.Value = pVertex.Position.Y.ToString();
816
                VertexNode.Attributes.SetNamedItem(YAttr);
817

    
818
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
819
                ZAttr.Value = pVertex.Position.Z.ToString();
820
                VertexNode.Attributes.SetNamedItem(ZAttr);
821

    
822
                node.AppendChild(VertexNode);
823

    
824
                return VertexNode;
825
            }
826

    
827
            return null;
828
        }
829

    
830
        /************************************************************************/
831
        /* 3D Polyline Dumper                                                   */
832
        /************************************************************************/
833
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
834
        {
835
            if (node != null)
836
            {
837
                XmlNode pPolylineNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
838

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

    
843
                /********************************************************************/
844
                /* Dump the vertices                                                */
845
                /********************************************************************/
846
                int i = 0;
847
                foreach (ObjectId obj in pPolyline)
848
                {
849
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
850
                    {
851
                        if (dbObj is PolylineVertex3d)
852
                        {
853
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
854
                        }
855
                    }
856
                }
857
                dumpCurveData(pPolyline, indent, pPolylineNode);
858

    
859
                node.AppendChild(pPolylineNode);
860

    
861
                return pPolylineNode;
862
            }
863

    
864
            return null;
865
        }
866

    
867

    
868
        /************************************************************************/
869
        /* 3DSolid Dumper                                                       */
870
        /************************************************************************/
871
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
872
        {
873
            if (node != null)
874
            {
875
                XmlNode SolidNode = Program.xml.CreateElement(pSolid.GetRXClass().Name);
876

    
877
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
878
                HandleAttr.Value = pSolid.Handle.ToString();
879
                SolidNode.Attributes.SetNamedItem(HandleAttr);
880

    
881
                dumpEntityData(pSolid, indent, node);
882

    
883
                node.AppendChild(SolidNode);
884

    
885
                return SolidNode;
886
            }
887

    
888
            return null;
889
        }
890

    
891

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

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

    
905
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
906
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
907
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
908

    
909
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
910
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
911
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
912

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

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

    
921
                dumpDimData(pDim, indent, DimNode);
922

    
923
                return DimNode;
924
            }
925

    
926
            return null;
927
        }
928

    
929
        /************************************************************************/
930
        /* Aligned Dimension Dumper                                             */
931
        /************************************************************************/
932
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
933
        {
934
            if (node != null)
935
            {
936
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
937

    
938
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
939
                HandleAttr.Value = pDim.Handle.ToString();
940
                DimNode.Attributes.SetNamedItem(HandleAttr);
941

    
942
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
943
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
944
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
945

    
946
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
947
                ObliqueAttr.Value = pDim.Oblique.ToString();
948
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
949

    
950
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
951
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
952
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
953

    
954
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
955
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
956
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
957

    
958
                dumpDimData(pDim, indent, DimNode);
959

    
960
                return DimNode;
961
            }
962

    
963
            return null;
964
        }
965

    
966
        /************************************************************************/
967
        /* Arc Dumper                                                           */
968
        /************************************************************************/
969
        XmlNode dump(Arc pArc, int indent, XmlNode node)
970
        {
971
            if (node != null)
972
            {
973
                XmlElement ArcNode = Program.xml.CreateElement(pArc.GetRXClass().Name);
974

    
975
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
976
                XAttr.Value = pArc.Center.X.ToString();
977
                ArcNode.Attributes.SetNamedItem(XAttr);
978

    
979
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
980
                YAttr.Value = pArc.Center.Y.ToString();
981
                ArcNode.Attributes.SetNamedItem(YAttr);
982

    
983
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
984
                ZAttr.Value = pArc.Center.Z.ToString();
985
                ArcNode.Attributes.SetNamedItem(ZAttr);
986

    
987
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
988
                RadiusAttr.Value = pArc.Radius.ToString();
989
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
990

    
991
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
992
                StartAngleAttr.Value = pArc.StartAngle.ToString();
993
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
994

    
995
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
996
                EndAngleAttr.Value = pArc.EndAngle.ToString();
997
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
998

    
999
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1000
                NormalAttr.Value = pArc.Normal.ToString();
1001
                ArcNode.Attributes.SetNamedItem(NormalAttr);
1002

    
1003
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1004
                ThicknessAttr.Value = pArc.Normal.ToString();
1005
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
1006

    
1007
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
1008
                dumpCurveData(pArc, indent, ArcNode);
1009

    
1010
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1011
                {
1012
                    XAttr = Program.xml.CreateAttribute("X");
1013
                    XAttr.Value = pArc.StartPoint.X.ToString();
1014
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1015

    
1016
                    YAttr = Program.xml.CreateAttribute("Y");
1017
                    YAttr.Value = pArc.StartPoint.Y.ToString();
1018
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1019

    
1020
                    ZAttr = Program.xml.CreateAttribute("Z");
1021
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
1022
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1023
                }
1024
                ArcNode.AppendChild(StartPointNode);
1025

    
1026
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1027
                {
1028
                    XAttr = Program.xml.CreateAttribute("X");
1029
                    XAttr.Value = pArc.EndPoint.X.ToString();
1030
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1031

    
1032
                    YAttr = Program.xml.CreateAttribute("Y");
1033
                    YAttr.Value = pArc.EndPoint.Y.ToString();
1034
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1035

    
1036
                    ZAttr = Program.xml.CreateAttribute("Z");
1037
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1038
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1039
                }
1040
                ArcNode.AppendChild(EndPointNode);
1041

    
1042
                node.AppendChild(ArcNode);
1043

    
1044
                return ArcNode;
1045
            }
1046

    
1047
            return null;
1048
        }
1049

    
1050
        /************************************************************************/
1051
        /* Arc Dimension Dumper                                                 */
1052
        /************************************************************************/
1053
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
1054
        {
1055
            if (node != null)
1056
            {
1057
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1058

    
1059
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1060
                HandleAttr.Value = pDim.Handle.ToString();
1061
                DimNode.Attributes.SetNamedItem(HandleAttr);
1062

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

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

    
1071
                XmlAttribute ArcSymbolTypeAttr = Program.xml.CreateAttribute("ArcSymbolType");
1072
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1073
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1074

    
1075
                XmlAttribute IsPartialAttr = Program.xml.CreateAttribute("IsPartial");
1076
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1077
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1078

    
1079
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1080
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1081
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1082

    
1083
                if (pDim.HasLeader)
1084
                {
1085
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1086
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1087
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1088

    
1089
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1090
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1091
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1092
                }
1093

    
1094
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1095
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1096
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1097

    
1098
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1099
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1100
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1101

    
1102
                dumpDimData(pDim, indent, DimNode);
1103

    
1104
                return DimNode;
1105
            }
1106

    
1107
            return null;
1108
        }
1109

    
1110

    
1111
        /************************************************************************/
1112
        /* Block Reference Dumper                                                */
1113
        /************************************************************************/
1114
        void dump(BlockReference pBlkRef, int indent, XmlNode node)
1115
        {
1116
            using (BlockTableRecord pRecord = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead))
1117
            {
1118
                XmlNode BlockRefNode = dumpBlockRefData(pBlkRef, indent, node);
1119
                if (BlockRefNode != null)
1120
                {
1121
                    XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
1122
                    NameAttr.Value = pRecord.Name;
1123
                    BlockRefNode.Attributes.SetNamedItem(NameAttr);
1124
                }
1125
            }
1126
        }
1127

    
1128
        /************************************************************************/
1129
        /* Body Dumper                                                          */
1130
        /************************************************************************/
1131
        XmlNode dump(Body pBody, int indent, XmlNode node)
1132
        {
1133
            if (node != null)
1134
            {
1135
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1136

    
1137
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1138
                HandleAttr.Value = pBody.Handle.ToString();
1139
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1140

    
1141
                dumpEntityData(pBody, indent, BodyNode);
1142

    
1143
                return BodyNode;
1144
            }
1145

    
1146
            return null;
1147
        }
1148

    
1149

    
1150
        /************************************************************************/
1151
        /* Circle Dumper                                                        */
1152
        /************************************************************************/
1153
        XmlNode dump(Circle pCircle, int indent, XmlNode node)
1154
        {
1155
            if (node != null)
1156
            {
1157
                XmlElement CircleNode = Program.xml.CreateElement(pCircle.GetRXClass().Name);
1158

    
1159
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1160
                XAttr.Value = pCircle.Center.X.ToString();
1161
                CircleNode.Attributes.SetNamedItem(XAttr);
1162

    
1163
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1164
                YAttr.Value = pCircle.Center.Y.ToString();
1165
                CircleNode.Attributes.SetNamedItem(YAttr);
1166

    
1167
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1168
                RadiusAttr.Value = pCircle.Radius.ToString();
1169
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1170

    
1171
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1172
                NormalAttr.Value = pCircle.Normal.ToString();
1173
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1174

    
1175
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1176
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1177
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1178

    
1179
                dumpCurveData(pCircle, indent, CircleNode);
1180

    
1181
                node.AppendChild(CircleNode);
1182

    
1183
                return CircleNode;
1184
            }
1185

    
1186
            return null;
1187
        }
1188

    
1189
        /************************************************************************/
1190
        /* Diametric Dimension Dumper                                           */
1191
        /************************************************************************/
1192
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1193
        {
1194
            if (node != null)
1195
            {
1196
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1197

    
1198
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1199
                HandleAttr.Value = pDim.Handle.ToString();
1200
                DimNode.Attributes.SetNamedItem(HandleAttr);
1201

    
1202
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
1203
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1204
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1205

    
1206
                XmlAttribute FarChordPointAttr = Program.xml.CreateAttribute("FarChordPoint");
1207
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1208
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1209

    
1210
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1211
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1212
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1213

    
1214
                dumpDimData(pDim, indent, DimNode);
1215

    
1216
                return DimNode;
1217
            }
1218

    
1219
            return null;
1220
        }
1221

    
1222
        /************************************************************************/
1223
        /* Ellipse Dumper                                                       */
1224
        /************************************************************************/
1225
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1226
        {
1227
            if (node != null)
1228
            {
1229
                XmlElement EllipseNode = Program.xml.CreateElement(pEllipse.GetRXClass().Name);
1230

    
1231
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1232

    
1233
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1234
                XAttr.Value = pEllipse.Center.X.ToString();
1235
                EllipseNode.Attributes.SetNamedItem(XAttr);
1236

    
1237
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1238
                YAttr.Value = pEllipse.Center.Y.ToString();
1239
                EllipseNode.Attributes.SetNamedItem(YAttr);
1240

    
1241
                XmlAttribute MajorAxisAttr = Program.xml.CreateAttribute("MajorAxis");
1242
                MajorAxisAttr.Value = pEllipse.MajorAxis.ToString();
1243
                EllipseNode.Attributes.SetNamedItem(MajorAxisAttr);
1244

    
1245
                XmlAttribute MinorAxisAttr = Program.xml.CreateAttribute("MinorAxis");
1246
                MinorAxisAttr.Value = pEllipse.MinorAxis.ToString();
1247
                EllipseNode.Attributes.SetNamedItem(MinorAxisAttr);
1248

    
1249
                XmlAttribute MajorRadiusAttr = Program.xml.CreateAttribute("MajorRadius");
1250
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1251
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1252

    
1253
                XmlAttribute MinorRadiusAttr = Program.xml.CreateAttribute("MinorRadius");
1254
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1255
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1256

    
1257
                XmlAttribute RadiusRatioAttr = Program.xml.CreateAttribute("RadiusRatio");
1258
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1259
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1260

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

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

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

    
1273
                dumpCurveData(pEllipse, indent, EllipseNode);
1274

    
1275
                node.AppendChild(EllipseNode);
1276
            }
1277
        }
1278

    
1279
        /************************************************************************/
1280
        /* Face Dumper                                                       */
1281
        /************************************************************************/
1282
        XmlNode dump(Face pFace, int indent, XmlNode node)
1283
        {
1284
            if (node != null)
1285
            {
1286
                XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1287

    
1288
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1289
                HandleAttr.Value = pFace.Handle.ToString();
1290
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1291

    
1292
                for (short i = 0; i < 4; i++)
1293
                {
1294
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1295

    
1296
                    Point3d pt = pFace.GetVertexAt(i);
1297
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1298
                    XAttr.Value = pt.X.ToString();
1299
                    VertexNode.Attributes.SetNamedItem(XAttr);
1300

    
1301
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1302
                    YAttr.Value = pt.Y.ToString();
1303
                    VertexNode.Attributes.SetNamedItem(YAttr);
1304

    
1305
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1306
                    ZAttr.Value = pt.Z.ToString();
1307
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1308

    
1309
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1310
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1311
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1312

    
1313
                    FaceNode.AppendChild(VertexNode);
1314
                }
1315
                dumpEntityData(pFace, indent, FaceNode);
1316

    
1317
                node.AppendChild(FaceNode);
1318

    
1319
                return FaceNode;
1320
            }
1321

    
1322
            return null;
1323
        }
1324

    
1325
        /************************************************************************/
1326
        /* FCF Dumper                                                           */
1327
        /************************************************************************/
1328
        void dump(FeatureControlFrame pFcf, int indent)
1329
        {
1330
            writeLine(indent++, pFcf.GetRXClass().Name, pFcf.Handle);
1331
            writeLine(indent, "Location", pFcf.Location);
1332
            writeLine(indent, "Text", pFcf.Text);
1333
            writeLine(indent, "Dimension Style", pFcf.DimensionStyleName);
1334
            writeLine(indent, "Dimension Gap", pFcf.Dimgap);
1335
            writeLine(indent, "Dimension Scale", pFcf.Dimscale);
1336
            writeLine(indent, "Text Height", pFcf.Dimtxt);
1337
            writeLine(indent, "Frame Color", pFcf.Dimclrd);
1338
            writeLine(indent, "Text Style", pFcf.TextStyleName);
1339
            writeLine(indent, "Text Color", pFcf.Dimclrd);
1340
            writeLine(indent, "X-Direction", pFcf.Direction);
1341
            writeLine(indent, "Normal", pFcf.Normal);
1342
            dumpEntityData(pFcf, indent, Program.xml.DocumentElement);
1343
        }
1344

    
1345
        /************************************************************************/
1346
        /* Hatch Dumper                                                         */
1347
        /************************************************************************/
1348
        /***********************************************************************/
1349
        /* Dump Polyline Loop                                                  */
1350
        /***********************************************************************/
1351
        static void dumpPolylineType(int loopIndex, Hatch pHatch, int indent)
1352
        {
1353
            HatchLoop hl = pHatch.GetLoopAt(loopIndex);
1354
            for (int i = 0; i < hl.Polyline.Count; i++)
1355
            {
1356
                BulgeVertex bv = hl.Polyline[i];
1357
                writeLine(indent, "Vertex " + i.ToString(), bv.Vertex.ToString());
1358
                writeLine(indent + 1, "Bulge " + i.ToString(), bv.Bulge);
1359
                writeLine(indent + 1, "Bulge angle " + i.ToString(), toDegreeString(4 * Math.Atan(bv.Bulge)));
1360
            }
1361
        }
1362

    
1363
        /**********************************************************************/
1364
        /* Dump Circular Arc Edge                                             */
1365
        /**********************************************************************/
1366
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1367
        {
1368
            writeLine(indent, "Center", pCircArc.Center);
1369
            writeLine(indent, "Radius", pCircArc.Radius);
1370
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1371
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1372
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1373
        }
1374

    
1375
        /**********************************************************************/
1376
        /* Dump Elliptical Arc Edge                                           */
1377
        /**********************************************************************/
1378
        static void dumpEllipticalArcEdge(int indent, EllipticalArc2d pEllipArc)
1379
        {
1380
            writeLine(indent, "Center", pEllipArc.Center);
1381
            writeLine(indent, "Major Radius", pEllipArc.MajorRadius);
1382
            writeLine(indent, "Minor Radius", pEllipArc.MinorRadius);
1383
            writeLine(indent, "Major Axis", pEllipArc.MajorAxis);
1384
            writeLine(indent, "Minor Axis", pEllipArc.MinorAxis);
1385
            writeLine(indent, "Start Angle", toDegreeString(pEllipArc.StartAngle));
1386
            writeLine(indent, "End Angle", toDegreeString(pEllipArc.EndAngle));
1387
            writeLine(indent, "Clockwise", pEllipArc.IsClockWise);
1388
        }
1389

    
1390
        /**********************************************************************/
1391
        /* Dump NurbCurve Edge                                           */
1392
        /**********************************************************************/
1393
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1394
        {
1395
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1396
            writeLine(indent, "Degree", d.Degree);
1397
            writeLine(indent, "Rational", d.Rational);
1398
            writeLine(indent, "Periodic", d.Periodic);
1399

    
1400
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1401
            for (int i = 0; i < d.ControlPoints.Count; i++)
1402
            {
1403
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1404
            }
1405
            writeLine(indent, "Number of Knots", d.Knots.Count);
1406
            for (int i = 0; i < d.Knots.Count; i++)
1407
            {
1408
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1409
            }
1410

    
1411
            if (d.Rational)
1412
            {
1413
                writeLine(indent, "Number of Weights", d.Weights.Count);
1414
                for (int i = 0; i < d.Weights.Count; i++)
1415
                {
1416
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1417
                }
1418
            }
1419
        }
1420

    
1421
        /***********************************************************************/
1422
        /* Dump Edge Loop                                                      */
1423
        /***********************************************************************/
1424
        static void dumpEdgesType(int loopIndex, Hatch pHatch, int indent)
1425
        {
1426
            Curve2dCollection edges = pHatch.GetLoopAt(loopIndex).Curves;
1427
            for (int i = 0; i < (int)edges.Count; i++)
1428
            {
1429
                using (Curve2d pEdge = edges[i])
1430
                {
1431
                    writeLine(indent, string.Format("Edge {0}", i), pEdge.GetType().Name);
1432
                    switch (pEdge.GetType().Name)
1433
                    {
1434
                        case "LineSegment2d":
1435
                            break;
1436
                        case "CircularArc2d":
1437
                            dumpCircularArcEdge(indent + 1, (CircularArc2d)pEdge);
1438
                            break;
1439
                        case "EllipticalArc2d":
1440
                            dumpEllipticalArcEdge(indent + 1, (EllipticalArc2d)pEdge);
1441
                            break;
1442
                        case "NurbCurve2d":
1443
                            dumpNurbCurveEdge(indent + 1, (NurbCurve2d)pEdge);
1444
                            break;
1445
                    }
1446

    
1447
                    /******************************************************************/
1448
                    /* Common Edge Properties                                         */
1449
                    /******************************************************************/
1450
                    Interval interval = pEdge.GetInterval();
1451
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1452
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1453
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1454
                }
1455
            }
1456
        }
1457

    
1458
        /************************************************************************/
1459
        /* Convert the specified value to a LoopType string                     */
1460
        /************************************************************************/
1461
        string toLooptypeString(HatchLoopTypes loopType)
1462
        {
1463
            string retVal = "";
1464
            if ((loopType & HatchLoopTypes.External) != 0)
1465
                retVal = retVal + " | kExternal";
1466

    
1467
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1468
                retVal = retVal + " | kPolyline";
1469

    
1470
            if ((loopType & HatchLoopTypes.Derived) != 0)
1471
                retVal = retVal + " | kDerived";
1472

    
1473
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1474
                retVal = retVal + " | kTextbox";
1475

    
1476
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1477
                retVal = retVal + " | kOutermost";
1478

    
1479
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1480
                retVal = retVal + " | kNotClosed";
1481

    
1482
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1483
                retVal = retVal + " | kSelfIntersecting";
1484

    
1485
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1486
                retVal = retVal + " | kTextIsland";
1487

    
1488
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1489
                retVal = retVal + " | kDuplicate";
1490

    
1491
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1492
        }
1493

    
1494
        void dump(Hatch pHatch, int indent)
1495
        {
1496
            writeLine(indent++, pHatch.GetRXClass().Name, pHatch.Handle);
1497
            writeLine(indent, "Hatch Style", pHatch.HatchStyle);
1498
            writeLine(indent, "Hatch Object Type", pHatch.HatchObjectType);
1499
            writeLine(indent, "Is Hatch", pHatch.IsHatch);
1500
            writeLine(indent, "Is Gradient", !pHatch.IsGradient);
1501
            if (pHatch.IsHatch)
1502
            {
1503
                /******************************************************************/
1504
                /* Dump Hatch Parameters                                          */
1505
                /******************************************************************/
1506
                writeLine(indent, "Pattern Type", pHatch.PatternType);
1507
                switch (pHatch.PatternType)
1508
                {
1509
                    case HatchPatternType.PreDefined:
1510
                    case HatchPatternType.CustomDefined:
1511
                        writeLine(indent, "Pattern Name", pHatch.PatternName);
1512
                        writeLine(indent, "Solid Fill", pHatch.IsSolidFill);
1513
                        if (!pHatch.IsSolidFill)
1514
                        {
1515
                            writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1516
                            writeLine(indent, "Pattern Scale", pHatch.PatternScale);
1517
                        }
1518
                        break;
1519
                    case HatchPatternType.UserDefined:
1520
                        writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1521
                        writeLine(indent, "Pattern Double", pHatch.PatternDouble);
1522
                        writeLine(indent, "Pattern Space", pHatch.PatternSpace);
1523
                        break;
1524
                }
1525
                DBObjectCollection entitySet = new DBObjectCollection();
1526
                Handle hhh = pHatch.Handle;
1527
                if (hhh.Value == 1692) //69C)
1528
                {
1529
                    pHatch.Explode(entitySet);
1530
                    return;
1531
                }
1532
                if (hhh.Value == 1693) //69D)
1533
                {
1534
                    try
1535
                    {
1536
                        pHatch.Explode(entitySet);
1537
                    }
1538
                    catch (System.Exception e)
1539
                    {
1540
                        if (e.Message == "eCannotExplodeEntity")
1541
                        {
1542
                            writeLine(indent, "Hatch " + e.Message + ": ", pHatch.Handle);
1543
                            return;
1544
                        }
1545
                    }
1546
                }
1547
            }
1548
            if (pHatch.IsGradient)
1549
            {
1550
                /******************************************************************/
1551
                /* Dump Gradient Parameters                                       */
1552
                /******************************************************************/
1553
                writeLine(indent, "Gradient Type", pHatch.GradientType);
1554
                writeLine(indent, "Gradient Name", pHatch.GradientName);
1555
                writeLine(indent, "Gradient Angle", toDegreeString(pHatch.GradientAngle));
1556
                writeLine(indent, "Gradient Shift", pHatch.GradientShift);
1557
                writeLine(indent, "Gradient One-Color Mode", pHatch.GradientOneColorMode);
1558
                if (pHatch.GradientOneColorMode)
1559
                {
1560
                    writeLine(indent, "ShadeTintValue", pHatch.ShadeTintValue);
1561
                }
1562
                GradientColor[] colors = pHatch.GetGradientColors();
1563
                for (int i = 0; i < colors.Length; i++)
1564
                {
1565
                    writeLine(indent, string.Format("Color         {0}", i), colors[i].get_Color());
1566
                    writeLine(indent, string.Format("Interpolation {0}", i), colors[i].get_Value());
1567
                }
1568
            }
1569

    
1570
            /********************************************************************/
1571
            /* Dump Associated Objects                                          */
1572
            /********************************************************************/
1573
            writeLine(indent, "Associated objects", pHatch.Associative);
1574
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1575
            {
1576
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1577
            }
1578

    
1579
            /********************************************************************/
1580
            /* Dump Loops                                                       */
1581
            /********************************************************************/
1582
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1583
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1584
            {
1585
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1586

    
1587
                /******************************************************************/
1588
                /* Dump Loop                                                      */
1589
                /******************************************************************/
1590
                if ((pHatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) != 0)
1591
                {
1592
                    dumpPolylineType(i, pHatch, indent + 2);
1593
                }
1594
                else
1595
                {
1596
                    dumpEdgesType(i, pHatch, indent + 2);
1597
                }
1598
                /******************************************************************/
1599
                /* Dump Associated Objects                                        */
1600
                /******************************************************************/
1601
                if (pHatch.Associative)
1602
                {
1603
                    writeLine(indent + 2, "Associated objects");
1604
                    foreach (ObjectId id in pHatch.GetAssociatedObjectIdsAt(i))
1605
                    {
1606
                        writeLine(indent + 3, id.ObjectClass.Name, id.Handle);
1607
                    }
1608
                }
1609
            }
1610

    
1611
            writeLine(indent, "Elevation", pHatch.Elevation);
1612
            writeLine(indent, "Normal", pHatch.Normal);
1613
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1614
        }
1615

    
1616
        /************************************************************************/
1617
        /* Leader Dumper                                                          */
1618
        /************************************************************************/
1619
        void dump(Leader pLeader, int indent)
1620
        {
1621
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1622
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1623

    
1624
            writeLine(indent, "Annotation");
1625
            if (!pLeader.Annotation.IsNull)
1626
            {
1627
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1628
            }
1629
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1630
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1631
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1632
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1633
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1634
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1635
            writeLine(indent, "Splined", pLeader.IsSplined);
1636

    
1637
            for (int i = 0; i < pLeader.NumVertices; i++)
1638
            {
1639
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1640
            }
1641
            writeLine(indent, "Normal", pLeader.Normal);
1642
            dumpCurveData(pLeader, indent, Program.xml.DocumentElement);
1643
        }
1644

    
1645
        /************************************************************************/
1646
        /* Line Dumper                                                          */
1647
        /************************************************************************/
1648
        void dump(Line pLine, int indent, XmlNode node)
1649
        {
1650
            if (node != null && pLine != null && pLine.Length != 0)
1651
            {
1652
                XmlNode LineNode = Program.xml.CreateElement(pLine.GetRXClass().Name);
1653
                XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1654
                LengthAttr.Value = pLine.Length.ToString();
1655
                LineNode.Attributes.SetNamedItem(LengthAttr);
1656

    
1657
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1658
                HandleAttr.Value = pLine.Handle.ToString();
1659
                LineNode.Attributes.SetNamedItem(HandleAttr);
1660

    
1661
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1662
                {
1663
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1664
                    XAttr.Value = pLine.StartPoint.X.ToString();
1665
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1666

    
1667
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1668
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1669
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1670

    
1671
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1672
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1673
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1674
                }
1675
                LineNode.AppendChild(StartPointNode);
1676

    
1677
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1678
                {
1679
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1680
                    XAttr.Value = pLine.EndPoint.X.ToString();
1681
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1682

    
1683
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1684
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1685
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1686

    
1687
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1688
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1689
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1690
                }
1691
                LineNode.AppendChild(EndPointNode);
1692

    
1693
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1694
                NormalAttr.Value = pLine.Normal.ToString();
1695
                LineNode.Attributes.SetNamedItem(NormalAttr);
1696

    
1697
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1698
                ThicknessAttr.Value = pLine.Thickness.ToString();
1699
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1700

    
1701
                dumpEntityData(pLine, indent, LineNode);
1702

    
1703
                node.AppendChild(LineNode);
1704
            }
1705
            else
1706
            {
1707
                int d = 0;
1708
            }
1709
        }
1710

    
1711
        /************************************************************************/
1712
        /* MInsertBlock Dumper                                                  */
1713
        /************************************************************************/
1714
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1715
        {
1716
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1717

    
1718
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1719
            {
1720
                writeLine(indent, "Name", pRecord.Name);
1721
                writeLine(indent, "Rows", pMInsert.Rows);
1722
                writeLine(indent, "Columns", pMInsert.Columns);
1723
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1724
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1725
                dumpBlockRefData(pMInsert, indent, node);
1726
            }
1727
        }
1728

    
1729
        /************************************************************************/
1730
        /* Mline Dumper                                                         */
1731
        /************************************************************************/
1732
        void dump(Mline pMline, int indent)
1733
        {
1734
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1735
            writeLine(indent, "Style", pMline.Style);
1736
            writeLine(indent, "Closed", pMline.IsClosed);
1737
            writeLine(indent, "Scale", pMline.Scale);
1738
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1739
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1740
            writeLine(indent, "Normal", pMline.Normal);
1741

    
1742
            /********************************************************************/
1743
            /* Dump the segment data                                            */
1744
            /********************************************************************/
1745
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1746
            {
1747
                writeLine(indent, "Segment", i);
1748
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1749
            }
1750
            dumpEntityData(pMline, indent, Program.xml.DocumentElement);
1751
        }
1752

    
1753
        /************************************************************************/
1754
        /* MText Dumper                                                         */
1755
        /************************************************************************/
1756
        /// <summary>
1757
        /// convert MText to normal Text
1758
        /// </summary>
1759
        /// <param name="pMText"></param>
1760
        /// <param name="indent"></param>
1761
        /// <param name="node"></param>
1762
        void dump(MText pMText, int indent, XmlNode node)
1763
        {
1764
            DBObjectCollection objColl = new DBObjectCollection();
1765
            pMText.Explode(objColl);
1766
            foreach (var obj in objColl)
1767
            {
1768
                dumpTextData(obj as DBText, indent, node);
1769
            }
1770
        }
1771

    
1772
        /************************************************************************/
1773
        /* Ordinate Dimension Dumper                                            */
1774
        /************************************************************************/
1775
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1776
        {
1777
            if (node != null)
1778
            {
1779
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1780

    
1781
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1782
                HandleAttr.Value = pDim.Handle.ToString();
1783
                DimNode.Attributes.SetNamedItem(HandleAttr);
1784

    
1785
                XmlAttribute DefiningPointAttr = Program.xml.CreateAttribute("DefiningPoint");
1786
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1787
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1788

    
1789
                XmlAttribute UsingXAxisAttr = Program.xml.CreateAttribute("UsingXAxis");
1790
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1791
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1792

    
1793
                XmlAttribute UsingYAxisAttr = Program.xml.CreateAttribute("UsingYAxis");
1794
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1795
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1796

    
1797
                XmlAttribute LeaderEndPointAttr = Program.xml.CreateAttribute("LeaderEndPoint");
1798
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1799
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1800

    
1801
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1802
                OriginAttr.Value = pDim.Origin.ToString();
1803
                DimNode.Attributes.SetNamedItem(OriginAttr);
1804

    
1805
                dumpDimData(pDim, indent, DimNode);
1806

    
1807
                return DimNode;
1808
            }
1809

    
1810
            return null;
1811
        }
1812

    
1813
        /************************************************************************/
1814
        /* PolyFaceMesh Dumper                                                  */
1815
        /************************************************************************/
1816
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1817
        {
1818
            if (node != null)
1819
            {
1820
                XmlElement PolyNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1821

    
1822
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1823
                HandleAttr.Value = pPoly.Handle.ToString();
1824
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1825

    
1826
                XmlAttribute NumVerticesAttr = Program.xml.CreateAttribute("NumVertices");
1827
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1828
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1829

    
1830
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1831
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1832
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1833

    
1834
                /********************************************************************/
1835
                /* dump vertices and faces                                          */
1836
                /********************************************************************/
1837
                int vertexCount = 0;
1838
                int faceCount = 0;
1839
                foreach (ObjectId objId in pPoly)
1840
                {
1841
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1842
                    {
1843
                        if (ent is PolyFaceMeshVertex)
1844
                        {
1845
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1846

    
1847
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1848

    
1849
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1850
                            _HandleAttr.Value = pVertex.Handle.ToString();
1851
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1852

    
1853
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1854
                            PositionAttr.Value = pVertex.Position.ToString();
1855
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1856

    
1857
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1858

    
1859
                            PolyNode.AppendChild(VertexNode);
1860
                        }
1861
                        else if (ent is FaceRecord)
1862
                        {
1863
                            FaceRecord pFace = (FaceRecord)ent;
1864
                            string face = "{";
1865
                            for (short i = 0; i < 4; i++)
1866
                            {
1867
                                if (i > 0)
1868
                                {
1869
                                    face = face + " ";
1870
                                }
1871
                                face = face + pFace.GetVertexAt(i).ToString();
1872
                            }
1873

    
1874
                            face += "}";
1875

    
1876
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1877

    
1878
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1879
                            _HandleAttr.Value = pFace.Handle.ToString();
1880
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1881
                            FaceNode.InnerText = face;
1882

    
1883
                            dumpEntityData(pFace, indent + 1, FaceNode);
1884

    
1885
                            PolyNode.AppendChild(FaceNode);
1886
                        }
1887
                        else
1888
                        { // Unknown entity type
1889
                            writeLine(indent, "Unexpected Entity");
1890
                        }
1891
                    }
1892
                }
1893
                dumpEntityData(pPoly, indent, PolyNode);
1894

    
1895
                return PolyNode;
1896
            }
1897

    
1898
            return null;
1899
        }
1900

    
1901
        /************************************************************************/
1902
        /* Ole2Frame                                                            */
1903
        /************************************************************************/
1904
        void dump(Ole2Frame pOle, int indent)
1905
        {
1906
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1907

    
1908
            Rectangle3d pos = (Rectangle3d)pOle.Position3d;
1909
            writeLine(indent, "Lower Left", pos.LowerLeft);
1910
            writeLine(indent, "Lower Right", pos.LowerRight);
1911
            writeLine(indent, "Upper Left", pos.UpperLeft);
1912
            writeLine(indent, "Upper Right", pos.UpperRight);
1913
            writeLine(indent, "Type", pOle.Type);
1914
            writeLine(indent, "User Type", pOle.UserType);
1915
            if (pOle.Type == Ole2Frame.ItemType.Link)
1916
            {
1917
                writeLine(indent, "Link Name", pOle.LinkName);
1918
                writeLine(indent, "Link Path", pOle.LinkPath);
1919
            }
1920
            writeLine(indent, "Output Quality", pOle.OutputQuality);
1921
            dumpEntityData(pOle, indent, Program.xml.DocumentElement);
1922
        }
1923

    
1924
        /************************************************************************/
1925
        /* Point Dumper                                                         */
1926
        /************************************************************************/
1927
        void dump(DBPoint pPoint, int indent)
1928
        {
1929
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1930
            writeLine(indent, "Position", pPoint.Position);
1931
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1932
            writeLine(indent, "Normal", pPoint.Normal);
1933
            writeLine(indent, "Thickness", pPoint.Thickness);
1934
            dumpEntityData(pPoint, indent, Program.xml.DocumentElement);
1935
        }
1936

    
1937
        /************************************************************************/
1938
        /* Polygon Mesh Dumper                                                  */
1939
        /************************************************************************/
1940
        void dump(PolygonMesh pPoly, int indent)
1941
        {
1942
            writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1943
            writeLine(indent, "m Size", pPoly.MSize);
1944
            writeLine(indent, "m-Closed", pPoly.IsMClosed);
1945
            writeLine(indent, "m Surface Density", pPoly.MSurfaceDensity);
1946
            writeLine(indent, "n Size", pPoly.NSize);
1947
            writeLine(indent, "n-Closed", pPoly.IsNClosed);
1948
            writeLine(indent, "n Surface Density", pPoly.NSurfaceDensity);
1949
            /********************************************************************/
1950
            /* dump vertices                                                    */
1951
            /********************************************************************/
1952
            int vertexCount = 0;
1953
            foreach (object o in pPoly)
1954
            {
1955
                PolygonMeshVertex pVertex = o as PolygonMeshVertex;
1956
                if (pVertex != null)
1957
                {
1958
                    writeLine(indent, pVertex.GetRXClass().Name, vertexCount++);
1959
                    writeLine(indent + 1, "Handle", pVertex.Handle);
1960
                    writeLine(indent + 1, "Position", pVertex.Position);
1961
                    writeLine(indent + 1, "Type", pVertex.VertexType);
1962
                }
1963
            }
1964
            dumpEntityData(pPoly, indent, Program.xml.DocumentElement);
1965
        }
1966

    
1967
        /************************************************************************/
1968
        /* Polyline Dumper                                                      */
1969
        /************************************************************************/
1970
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
1971
        {
1972
            if (pPoly != null && pPoly.Length != 0)
1973
            {
1974
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1975
                writeLine(indent, "Has Width", pPoly.HasWidth);
1976
                if (!pPoly.HasWidth)
1977
                {
1978
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
1979
                }
1980

    
1981
                /********************************************************************/
1982
                /* dump vertices                                                    */
1983
                /********************************************************************/
1984
                if (node != null)
1985
                {
1986
                    XmlNode PolylineNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1987
                    XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1988
                    LengthAttr.Value = pPoly.Length.ToString();
1989
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
1990

    
1991
                    XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
1992
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
1993
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
1994

    
1995
                    XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1996
                    HandleAttr.Value = pPoly.Handle.ToString();
1997
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
1998

    
1999
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
2000
                    ClosedAttr.Value = pPoly.Closed.ToString();
2001
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
2002

    
2003
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
2004
                    {
2005
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
2006

    
2007
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
2008
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
2009

    
2010
                        Point3d pt = pPoly.GetPoint3dAt(i);
2011
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
2012
                        XAttr.Value = pt.X.ToString();
2013
                        VertexNode.Attributes.SetNamedItem(XAttr);
2014

    
2015
                        XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
2016
                        YAttr.Value = pt.Y.ToString();
2017
                        VertexNode.Attributes.SetNamedItem(YAttr);
2018

    
2019
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
2020
                        ZAttr.Value = pt.Z.ToString();
2021
                        VertexNode.Attributes.SetNamedItem(ZAttr);
2022

    
2023
                        if (pPoly.HasWidth)
2024
                        {
2025
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
2026
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
2027
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
2028

    
2029
                            XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
2030
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
2031
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
2032
                        }
2033
                        if (pPoly.HasBulges)
2034
                        {
2035
                            XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
2036
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
2037
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
2038

    
2039
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2040
                            {
2041
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
2042
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2043
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2044
                            }
2045
                        }
2046

    
2047
                        PolylineNode.AppendChild(VertexNode);
2048
                    }
2049

    
2050
                    dumpEntityData(pPoly, indent, PolylineNode);
2051
                    node.AppendChild(PolylineNode);
2052
                }
2053
            }
2054
            else
2055
            {
2056
                int d = 0;
2057
            }
2058
        }
2059

    
2060
        class DrawContextDumper : Context
2061
        {
2062
            Database _db;
2063
            public DrawContextDumper(Database db)
2064
            {
2065
                _db = db;
2066
            }
2067
            public override Database Database
2068
            {
2069
                get { return _db; }
2070
            }
2071
            public override bool IsBoundaryClipping
2072
            {
2073
                get { return false; }
2074
            }
2075
            public override bool IsPlotGeneration
2076
            {
2077
                get { return false; }
2078
            }
2079
            public override bool IsPostScriptOut
2080
            {
2081
                get { return false; }
2082
            }
2083
        }
2084
        class SubEntityTraitsDumper : SubEntityTraits
2085
        {
2086
            short _color;
2087
            int _drawFlags;
2088
            FillType _ft;
2089
            ObjectId _layer;
2090
            ObjectId _linetype;
2091
            LineWeight _lineWeight;
2092
            Mapper _mapper;
2093
            double _lineTypeScale;
2094
            ObjectId _material;
2095
            PlotStyleDescriptor _plotStyleDescriptor;
2096
            bool _sectionable;
2097
            bool _selectionOnlyGeometry;
2098
            ShadowFlags _shadowFlags;
2099
            double _thickness;
2100
            EntityColor _trueColor;
2101
            Transparency _transparency;
2102
            ObjectId _visualStyle;
2103
            public SubEntityTraitsDumper(Database db)
2104
            {
2105
                _drawFlags = 0; // kNoDrawFlags 
2106
                _color = 0;
2107
                _ft = FillType.FillAlways;
2108
                _layer = db.Clayer;
2109
                _linetype = db.Celtype;
2110
                _lineWeight = db.Celweight;
2111
                _lineTypeScale = db.Celtscale;
2112
                _material = db.Cmaterial;
2113
                _shadowFlags = ShadowFlags.ShadowsIgnore;
2114
                _thickness = 0;
2115
                _trueColor = new EntityColor(ColorMethod.None);
2116
                _transparency = new Transparency();
2117
            }
2118

    
2119
            protected override void SetLayerFlags(LayerFlags flags)
2120
            {
2121
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2122
            }
2123
            public override void AddLight(ObjectId lightId)
2124
            {
2125
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2126
            }
2127
            public override void SetupForEntity(Entity entity)
2128
            {
2129
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2130
            }
2131

    
2132
            public override short Color
2133
            {
2134
                get { return _color; }
2135
                set { _color = value; }
2136
            }
2137
            public override int DrawFlags
2138
            {
2139
                get { return _drawFlags; }
2140
                set { _drawFlags = value; }
2141
            }
2142
            public override FillType FillType
2143
            {
2144
                get { return _ft; }
2145
                set { _ft = value; }
2146
            }
2147
            public override ObjectId Layer
2148
            {
2149
                get { return _layer; }
2150
                set { _layer = value; }
2151
            }
2152
            public override ObjectId LineType
2153
            {
2154
                get { return _linetype; }
2155
                set { _linetype = value; }
2156
            }
2157
            public override double LineTypeScale
2158
            {
2159
                get { return _lineTypeScale; }
2160
                set { _lineTypeScale = value; }
2161
            }
2162
            public override LineWeight LineWeight
2163
            {
2164
                get { return _lineWeight; }
2165
                set { _lineWeight = value; }
2166
            }
2167
            public override Mapper Mapper
2168
            {
2169
                get { return _mapper; }
2170
                set { _mapper = value; }
2171
            }
2172
            public override ObjectId Material
2173
            {
2174
                get { return _material; }
2175
                set { _material = value; }
2176
            }
2177
            public override PlotStyleDescriptor PlotStyleDescriptor
2178
            {
2179
                get { return _plotStyleDescriptor; }
2180
                set { _plotStyleDescriptor = value; }
2181
            }
2182
            public override bool Sectionable
2183
            {
2184
                get { return _sectionable; }
2185
                set { _sectionable = value; }
2186
            }
2187
            public override bool SelectionOnlyGeometry
2188
            {
2189
                get { return _selectionOnlyGeometry; }
2190
                set { _selectionOnlyGeometry = value; }
2191
            }
2192
            public override ShadowFlags ShadowFlags
2193
            {
2194
                get { return _shadowFlags; }
2195
                set { _shadowFlags = value; }
2196
            }
2197
            public override double Thickness
2198
            {
2199
                get { return _thickness; }
2200
                set { _thickness = value; }
2201
            }
2202
            public override EntityColor TrueColor
2203
            {
2204
                get { return _trueColor; }
2205
                set { _trueColor = value; }
2206
            }
2207
            public override Transparency Transparency
2208
            {
2209
                get { return _transparency; }
2210
                set { _transparency = value; }
2211
            }
2212
            public override ObjectId VisualStyle
2213
            {
2214
                get { return _visualStyle; }
2215
                set { _visualStyle = value; }
2216
            }
2217
            public override void SetSelectionMarker(IntPtr sm)
2218
            {
2219
            }
2220
        }
2221
        class WorldGeometryDumper : WorldGeometry
2222
        {
2223
            Stack<Matrix3d> modelMatrix;
2224
            Stack<ClipBoundary> clips;
2225
            int indent;
2226
            public WorldGeometryDumper(int indent)
2227
              : base()
2228
            {
2229
                this.indent = indent;
2230
                modelMatrix = new Stack<Matrix3d>();
2231
                clips = new Stack<ClipBoundary>();
2232
                modelMatrix.Push(Matrix3d.Identity);
2233
            }
2234
            public override Matrix3d ModelToWorldTransform
2235
            {
2236
                get { return modelMatrix.Peek(); }
2237
            }
2238
            public override Matrix3d WorldToModelTransform
2239
            {
2240
                get { return modelMatrix.Peek().Inverse(); }
2241
            }
2242

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

    
2427
            public override void SetExtents(Extents3d extents)
2428
            {
2429
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2430
            }
2431
            public override void StartAttributesSegment()
2432
            {
2433
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2434
            }
2435
        }
2436

    
2437
        class WorldDrawDumper : WorldDraw
2438
        {
2439
            WorldGeometryDumper _geom;
2440
            DrawContextDumper _ctx;
2441
            SubEntityTraits _subents;
2442
            RegenType _regenType;
2443
            int indent;
2444
            public WorldDrawDumper(Database db, int indent)
2445
              : base()
2446
            {
2447
                _regenType = RegenType;
2448
                this.indent = indent;
2449
                _geom = new WorldGeometryDumper(indent);
2450
                _ctx = new DrawContextDumper(db);
2451
                _subents = new SubEntityTraitsDumper(db);
2452
            }
2453
            public override double Deviation(DeviationType deviationType, Point3d pointOnCurve)
2454
            {
2455
                return 1e-9;
2456
            }
2457
            public override WorldGeometry Geometry
2458
            {
2459
                get
2460
                {
2461
                    return _geom;
2462
                }
2463
            }
2464
            public override bool IsDragging
2465
            {
2466
                get
2467
                {
2468
                    return false;
2469
                }
2470
            }
2471
            public override Int32 NumberOfIsolines
2472
            {
2473
                get
2474
                {
2475
                    return 10;
2476
                }
2477
            }
2478
            public override Geometry RawGeometry
2479
            {
2480
                get
2481
                {
2482
                    return _geom;
2483
                }
2484
            }
2485
            public override bool RegenAbort
2486
            {
2487
                get
2488
                {
2489
                    return false;
2490
                }
2491
            }
2492
            public override RegenType RegenType
2493
            {
2494
                get
2495
                {
2496
                    writeLine(indent, "RegenType is asked");
2497
                    return _regenType;
2498
                }
2499
            }
2500
            public override SubEntityTraits SubEntityTraits
2501
            {
2502
                get
2503
                {
2504
                    return _subents;
2505
                }
2506
            }
2507
            public override Context Context
2508
            {
2509
                get
2510
                {
2511
                    return _ctx;
2512
                }
2513
            }
2514
        }
2515

    
2516
        /************************************************************************/
2517
        /* Dump the common data and WorldDraw information for all               */
2518
        /* entities without explicit dumpers                                    */
2519
        /************************************************************************/
2520
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2521
        {
2522
            if (node != null)
2523
            {
2524
                XmlElement EntNode = Program.xml.CreateElement(pEnt.GetRXClass().Name);
2525

    
2526
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2527
                HandleAttr.Value = pEnt.Handle.ToString();
2528
                EntNode.Attributes.SetNamedItem(HandleAttr);
2529

    
2530
                dumpEntityData(pEnt, indent, EntNode);
2531
                using (Database db = pEnt.Database)
2532
                {
2533
                    /**********************************************************************/
2534
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2535
                    /**********************************************************************/
2536
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2537
                    /**********************************************************************/
2538
                    /* Call worldDraw()                                                   */
2539
                    /**********************************************************************/
2540
                    pEnt.WorldDraw(wd);
2541
                }
2542

    
2543
                node.AppendChild(EntNode);
2544

    
2545
                return EntNode;
2546
            }
2547

    
2548
            return null;
2549
        }
2550

    
2551
        /************************************************************************/
2552
        /* Proxy Entity Dumper                                                  */
2553
        /************************************************************************/
2554
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2555
        {
2556
            if (node != null)
2557
            {
2558
                XmlElement ProxyNode = Program.xml.CreateElement(pProxy.GetRXClass().Name);
2559

    
2560
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2561
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2562
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2563

    
2564
                // this will dump proxy entity graphics
2565
                dump((Entity)pProxy, indent, node);
2566

    
2567
                DBObjectCollection collection = new DBObjectCollection(); ;
2568
                try
2569
                {
2570
                    pProxy.ExplodeGeometry(collection);
2571
                }
2572
                catch (System.Exception)
2573
                {
2574
                    return null;
2575
                }
2576

    
2577
                foreach (Entity ent in collection)
2578
                {
2579
                    if (ent is Polyline2d)
2580
                    {
2581
                        Polyline2d pline2d = (Polyline2d)ent;
2582
                        int i = 0;
2583

    
2584
                        try
2585
                        {
2586
                            foreach (Entity ent1 in pline2d)
2587
                            {
2588
                                if (ent1 is Vertex2d)
2589
                                {
2590
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2591
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2592
                                }
2593
                            }
2594
                        }
2595
                        catch (System.Exception)
2596
                        {
2597
                            return null;
2598
                        }
2599
                    }
2600
                }
2601

    
2602
                node.AppendChild(ProxyNode);
2603
                return ProxyNode;
2604
            }
2605

    
2606
            return null;
2607
        }
2608

    
2609
        /************************************************************************/
2610
        /* Radial Dimension Dumper                                              */
2611
        /************************************************************************/
2612
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2613
        {
2614
            if (node != null)
2615
            {
2616
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2617

    
2618
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2619
                HandleAttr.Value = pDim.Handle.ToString();
2620
                DimNode.Attributes.SetNamedItem(HandleAttr);
2621

    
2622
                XmlAttribute CenterAttr = Program.xml.CreateAttribute("Center");
2623
                CenterAttr.Value = pDim.Center.ToString();
2624
                DimNode.Attributes.SetNamedItem(CenterAttr);
2625

    
2626
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
2627
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
2628
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
2629

    
2630
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
2631
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2632
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2633

    
2634
                dumpDimData(pDim, indent, DimNode);
2635

    
2636
                node.AppendChild(DimNode);
2637

    
2638
                return DimNode;
2639
            }
2640

    
2641
            return null;
2642
        }
2643

    
2644
        /************************************************************************/
2645
        /* Dump Raster Image Def                                               */
2646
        /************************************************************************/
2647
        void dumpRasterImageDef(ObjectId id, int indent)
2648
        {
2649
            if (!id.IsValid)
2650
                return;
2651
            using (RasterImageDef pDef = (RasterImageDef)id.Open(OpenMode.ForRead))
2652
            {
2653
                writeLine(indent++, pDef.GetRXClass().Name, pDef.Handle);
2654
                writeLine(indent, "Source Filename", shortenPath(pDef.SourceFileName));
2655
                writeLine(indent, "Loaded", pDef.IsLoaded);
2656
                writeLine(indent, "mm per Pixel", pDef.ResolutionMMPerPixel);
2657
                writeLine(indent, "Loaded", pDef.IsLoaded);
2658
                writeLine(indent, "Resolution Units", pDef.ResolutionUnits);
2659
                writeLine(indent, "Size", pDef.Size);
2660
            }
2661
        }
2662
        /************************************************************************/
2663
        /* Dump Raster Image Data                                               */
2664
        /************************************************************************/
2665
        void dumpRasterImageData(RasterImage pImage, int indent)
2666
        {
2667
            writeLine(indent, "Brightness", pImage.Brightness);
2668
            writeLine(indent, "Clipped", pImage.IsClipped);
2669
            writeLine(indent, "Contrast", pImage.Contrast);
2670
            writeLine(indent, "Fade", pImage.Fade);
2671
            writeLine(indent, "kClip", pImage.DisplayOptions & ImageDisplayOptions.Clip);
2672
            writeLine(indent, "kShow", pImage.DisplayOptions & ImageDisplayOptions.Show);
2673
            writeLine(indent, "kShowUnAligned", pImage.DisplayOptions & ImageDisplayOptions.ShowUnaligned);
2674
            writeLine(indent, "kTransparent", pImage.DisplayOptions & ImageDisplayOptions.Transparent);
2675
            writeLine(indent, "Scale", pImage.Scale);
2676

    
2677
            /********************************************************************/
2678
            /* Dump clip boundary                                               */
2679
            /********************************************************************/
2680
            if (pImage.IsClipped)
2681
            {
2682
                writeLine(indent, "Clip Boundary Type", pImage.ClipBoundaryType);
2683
                if (pImage.ClipBoundaryType != ClipBoundaryType.Invalid)
2684
                {
2685
                    Point2dCollection pt = pImage.GetClipBoundary();
2686
                    for (int i = 0; i < pt.Count; i++)
2687
                    {
2688
                        writeLine(indent, string.Format("Clip Point {0}", i), pt[i]);
2689
                    }
2690
                }
2691
            }
2692

    
2693
            /********************************************************************/
2694
            /* Dump frame                                                       */
2695
            /********************************************************************/
2696
            Point3dCollection vertices = pImage.GetVertices();
2697
            for (int i = 0; i < vertices.Count; i++)
2698
            {
2699
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2700
            }
2701

    
2702
            /********************************************************************/
2703
            /* Dump orientation                                                 */
2704
            /********************************************************************/
2705
            writeLine(indent, "Orientation");
2706
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2707
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2708
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2709
            dumpRasterImageDef(pImage.ImageDefId, indent);
2710
            dumpEntityData(pImage, indent, Program.xml.DocumentElement);
2711
        }
2712

    
2713
        /************************************************************************/
2714
        /* Raster Image Dumper                                                  */
2715
        /************************************************************************/
2716
        void dump(RasterImage pImage, int indent)
2717
        {
2718
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2719
            writeLine(indent, "Image size", pImage.ImageSize(true));
2720
            dumpRasterImageData(pImage, indent);
2721
        }
2722

    
2723
        /************************************************************************/
2724
        /* Ray Dumper                                                          */
2725
        /************************************************************************/
2726
        void dump(Ray pRay, int indent)
2727
        {
2728
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2729
            writeLine(indent, "Base Point", pRay.BasePoint);
2730
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2731
            dumpCurveData(pRay, indent, Program.xml.DocumentElement);
2732
        }
2733

    
2734
        /************************************************************************/
2735
        /* Region Dumper                                                        */
2736
        /************************************************************************/
2737
        void dump(Region pRegion, int indent)
2738
        {
2739
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2740
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2741
        }
2742

    
2743
        /************************************************************************/
2744
        /* Rotated Dimension Dumper                                             */
2745
        /************************************************************************/
2746
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2747
        {
2748
            if (node != null)
2749
            {
2750
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2751

    
2752
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2753
                HandleAttr.Value = pDim.Handle.ToString();
2754
                DimNode.Attributes.SetNamedItem(HandleAttr);
2755

    
2756
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
2757
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2758
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2759

    
2760
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
2761
                ObliqueAttr.Value = pDim.Oblique.ToString();
2762
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2763

    
2764
                XmlAttribute RotationAttr = Program.xml.CreateAttribute("Rotation");
2765
                RotationAttr.Value = pDim.Rotation.ToString();
2766
                DimNode.Attributes.SetNamedItem(RotationAttr);
2767

    
2768
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
2769
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2770
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2771

    
2772
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2773
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2774
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2775

    
2776
                dumpDimData(pDim, indent, DimNode);
2777
                node.AppendChild(DimNode);
2778

    
2779
                return DimNode;
2780
            }
2781

    
2782
            return null;
2783
        }
2784

    
2785
        /************************************************************************/
2786
        /* Shape Dumper                                                          */
2787
        /************************************************************************/
2788
        void dump(Shape pShape, int indent)
2789
        {
2790
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2791

    
2792
            if (!pShape.StyleId.IsNull)
2793
            {
2794
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2795
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2796
            }
2797

    
2798
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2799
            writeLine(indent, "Shape Name", pShape.Name);
2800
            writeLine(indent, "Position", pShape.Position);
2801
            writeLine(indent, "Size", pShape.Size);
2802
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2803
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2804
            writeLine(indent, "Normal", pShape.Normal);
2805
            writeLine(indent, "Thickness", pShape.Thickness);
2806
            dumpEntityData(pShape, indent, Program.xml.DocumentElement);
2807
        }
2808

    
2809
        /************************************************************************/
2810
        /* Solid Dumper                                                         */
2811
        /************************************************************************/
2812
        // TODO:
2813
        /*  void dump(Solid pSolid, int indent)
2814
      {
2815
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2816

    
2817
        for (int i = 0; i < 4; i++)
2818
        {
2819
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2820
        }
2821
        dumpEntityData(pSolid, indent);
2822
      }
2823
    */
2824
        /************************************************************************/
2825
        /* Spline Dumper                                                        */
2826
        /************************************************************************/
2827
        void dump(Spline pSpline, int indent)
2828
        {
2829
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2830

    
2831
            NurbsData data = pSpline.NurbsData;
2832
            writeLine(indent, "Degree", data.Degree);
2833
            writeLine(indent, "Rational", data.Rational);
2834
            writeLine(indent, "Periodic", data.Periodic);
2835
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2836
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2837

    
2838
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2839
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2840
            {
2841
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2842
            }
2843

    
2844
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2845
            for (int i = 0; i < data.GetKnots().Count; i++)
2846
            {
2847
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2848
            }
2849

    
2850
            if (data.Rational)
2851
            {
2852
                writeLine(indent, "Number of Weights", data.GetWeights().Count);
2853
                for (int i = 0; i < data.GetWeights().Count; i++)
2854
                {
2855
                    writeLine(indent, "Weight " + i.ToString(), data.GetWeights()[i]);
2856
                }
2857
            }
2858
            dumpCurveData(pSpline, indent, Program.xml.DocumentElement);
2859
        }
2860
        /************************************************************************/
2861
        /* Table Dumper                                                         */
2862
        /************************************************************************/
2863
        void dump(Table pTable, int indent)
2864
        {
2865
            writeLine(indent++, pTable.GetRXClass().Name, pTable.Handle);
2866
            writeLine(indent, "Position", pTable.Position);
2867
            writeLine(indent, "X-Direction", pTable.Direction);
2868
            writeLine(indent, "Normal", pTable.Normal);
2869
            writeLine(indent, "Height", (int)pTable.Height);
2870
            writeLine(indent, "Width", (int)pTable.Width);
2871
            writeLine(indent, "Rows", (int)pTable.NumRows);
2872
            writeLine(indent, "Columns", (int)pTable.NumColumns);
2873

    
2874
            // TODO:
2875
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2876
            //writeLine(indent, "Table Style",               pStyle.Name);
2877
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2878
        }
2879

    
2880
        /************************************************************************/
2881
        /* Text Dumper                                                          */
2882
        /************************************************************************/
2883
        static void dump(DBText pText, int indent, XmlNode node)
2884
        {
2885
            if (node != null)
2886
            {
2887
                dumpTextData(pText, indent, node);
2888
            }
2889
        }
2890
        /************************************************************************/
2891
        /* Trace Dumper                                                         */
2892
        /************************************************************************/
2893
        void dump(Trace pTrace, int indent)
2894
        {
2895
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2896

    
2897
            for (short i = 0; i < 4; i++)
2898
            {
2899
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2900
            }
2901
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2902
        }
2903

    
2904
        /************************************************************************/
2905
        /* Trace UnderlayReference                                                         */
2906
        /************************************************************************/
2907
        void dump(UnderlayReference pEnt, int indent)
2908
        {
2909
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2910
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2911
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2912
        }
2913

    
2914
        /************************************************************************/
2915
        /* Viewport Dumper                                                       */
2916
        /************************************************************************/
2917
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2918
        {
2919
            if (node != null)
2920
            {
2921
                XmlElement VportNode = Program.xml.CreateElement(pVport.GetRXClass().Name);
2922

    
2923
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2924
                HandleAttr.Value = pVport.Handle.ToString();
2925
                VportNode.Attributes.SetNamedItem(HandleAttr);
2926

    
2927
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2928
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2929
                writeLine(indent, "Center Point", pVport.CenterPoint);
2930
                writeLine(indent, "Circle sides", pVport.CircleSides);
2931
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2932
                writeLine(indent, "Elevation", pVport.Elevation);
2933
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2934
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2935
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2936
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2937

    
2938
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2939
                if (layerIds.Count > 0)
2940
                {
2941
                    writeLine(indent, "Frozen Layers:");
2942
                    for (int i = 0; i < layerIds.Count; i++)
2943
                    {
2944
                        writeLine(indent + 1, i, layerIds[i]);
2945
                    }
2946
                }
2947
                else
2948
                {
2949
                    writeLine(indent, "Frozen Layers", "None");
2950
                }
2951

    
2952
                Point3d origin = new Point3d();
2953
                Vector3d xAxis = new Vector3d();
2954
                Vector3d yAxis = new Vector3d();
2955
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
2956
                writeLine(indent, "UCS origin", origin);
2957
                writeLine(indent, "UCS x-Axis", xAxis);
2958
                writeLine(indent, "UCS y-Axis", yAxis);
2959
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
2960
                writeLine(indent, "Grid On", pVport.GridOn);
2961
                writeLine(indent, "Height", pVport.Height);
2962
                writeLine(indent, "Lens Length", pVport.LensLength);
2963
                writeLine(indent, "Locked", pVport.Locked);
2964
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
2965

    
2966
                if (!pVport.NonRectClipEntityId.IsNull)
2967
                {
2968
                    writeLine(indent, "Non-rectangular Clipper", pVport.NonRectClipEntityId.Handle);
2969
                }
2970
                writeLine(indent, "Render Mode", pVport.RenderMode);
2971
                writeLine(indent, "Remove Hidden Lines", pVport.HiddenLinesRemoved);
2972
                writeLine(indent, "Shade Plot", pVport.ShadePlot);
2973
                writeLine(indent, "Snap Isometric", pVport.SnapIsometric);
2974
                writeLine(indent, "Snap On", pVport.SnapOn);
2975
                writeLine(indent, "Transparent", pVport.Transparent);
2976
                writeLine(indent, "UCS Follow", pVport.UcsFollowModeOn);
2977
                writeLine(indent, "UCS Icon at Origin", pVport.UcsIconAtOrigin);
2978

    
2979
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
2980
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
2981

    
2982
                if (!pVport.UcsName.IsNull)
2983
                {
2984
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
2985
                        writeLine(indent, "UCS Name", pUCS.Name);
2986
                }
2987
                else
2988
                {
2989
                    writeLine(indent, "UCS Name", "Null");
2990
                }
2991

    
2992
                writeLine(indent, "View Center", pVport.ViewCenter);
2993
                writeLine(indent, "View Height", pVport.ViewHeight);
2994
                writeLine(indent, "View Target", pVport.ViewTarget);
2995
                writeLine(indent, "Width", pVport.Width);
2996
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
2997

    
2998
                {
2999
                    using (DBObjectCollection collection = new DBObjectCollection())
3000
                    {
3001
                        try
3002
                        {
3003
                            pVport.ExplodeGeometry(collection);
3004

    
3005
                            foreach (Entity ent in collection)
3006
                            {
3007
                                if (ent is Polyline2d)
3008
                                {
3009
                                    Polyline2d pline2d = (Polyline2d)ent;
3010
                                    int i = 0;
3011
                                    foreach (Entity ent1 in pline2d)
3012
                                    {
3013
                                        if (ent1 is Vertex2d)
3014
                                        {
3015
                                            Vertex2d vtx2d = (Vertex2d)ent1;
3016
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
3017
                                        }
3018
                                    }
3019
                                }
3020
                            }
3021
                        }
3022
                        catch (System.Exception)
3023
                        {
3024
                        }
3025
                    }
3026
                }
3027

    
3028
                node.AppendChild(VportNode);
3029
                return VportNode;
3030
            }
3031

    
3032
            return null;
3033
        }
3034

    
3035
        /************************************************************************/
3036
        /* Wipeout Dumper                                                  */
3037
        /************************************************************************/
3038
        void dump(Wipeout pWipeout, int indent)
3039
        {
3040
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3041
            dumpRasterImageData(pWipeout, indent);
3042
        }
3043

    
3044
        /************************************************************************/
3045
        /* Xline Dumper                                                         */
3046
        /************************************************************************/
3047
        void dump(Xline pXline, int indent)
3048
        {
3049
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
3050
            writeLine(indent, "Base Point", pXline.BasePoint);
3051
            writeLine(indent, "Unit Direction", pXline.UnitDir);
3052
            dumpCurveData(pXline, indent, Program.xml.DocumentElement);
3053
        }
3054

    
3055
        public void dump(Database pDb, int indent, XmlNode node)
3056
        {
3057
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3058
            {
3059
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
3060
                {
3061
                    string layoutName = "";
3062
                    layoutName = pLayout.LayoutName;
3063

    
3064
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
3065
                    LayoutNameAttr.Value = layoutName;
3066
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3067
                }
3068
            }
3069

    
3070
            dumpHeader(pDb, indent, node);
3071
            dumpLayers(pDb, indent, node);
3072
            dumpLinetypes(pDb, indent, node);
3073
            dumpTextStyles(pDb, indent, node);
3074
            dumpDimStyles(pDb, indent, node);
3075
            dumpRegApps(pDb, indent);
3076
            dumpViewports(pDb, indent, node);
3077
            dumpViews(pDb, indent, node);
3078
            dumpMLineStyles(pDb, indent);
3079
            dumpUCSTable(pDb, indent, node);
3080
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3081

    
3082
            dumpBlocks(pDb, indent, node);
3083
        }
3084

    
3085
        /************************************************************************/
3086
        /* Export DWG to PDF                                                    */
3087
        /************************************************************************/
3088
        public void ExportPDF(Database pDb, string filePath)
3089
        {
3090
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3091
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3092
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3093

    
3094
            using (mPDFExportParams param = new mPDFExportParams())
3095
            {
3096
                param.Database = pDb;
3097

    
3098
                TransactionManager tm = pDb.TransactionManager;
3099
                using (Transaction ta = tm.StartTransaction())
3100
                {
3101
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3102
                    {
3103
                        param.OutputStream = fileStrem;
3104

    
3105
                        bool embededTTF = false;
3106
                        bool shxTextAsGeometry = true;
3107
                        bool ttfGeometry = true;
3108
                        bool simpleGeomOptimization = false;
3109
                        bool zoomToExtentsMode = true;
3110
                        bool enableLayers = false;
3111
                        bool includeOffLayers = false;
3112
                        bool enablePrcMode = true;
3113
                        bool monochrome = true;
3114
                        bool allLayout = false;
3115
                        double paperWidth = 841;
3116
                        double paperHeight = 594;
3117

    
3118
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3119
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3120
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3121
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3122
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3123
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3124
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3125

    
3126
                        param.Title = "";
3127
                        param.Author = "";
3128
                        param.Subject = "";
3129
                        param.Keywords = "";
3130
                        param.Creator = "";
3131
                        param.Producer = "";
3132
                        param.UseHLR = !enablePrcMode;
3133
                        param.FlateCompression = true;
3134
                        param.ASCIIHEXEncodeStream = true;
3135
                        param.hatchDPI = 720;
3136

    
3137
                        bool bV15 = enableLayers || includeOffLayers;
3138
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3139

    
3140
                        if (enablePrcMode)
3141
                        {
3142
                            Module pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcModule", false, false);
3143
                            if (pModule != null)
3144
                            {
3145
                                pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcExport", false, false);
3146
                            }
3147
                            if (pModule != null)
3148
                            {
3149
                                RXObject pObj = null;
3150
                                bool bUsePRCSingleViewMode = true; // provide a corresponding checkbox in Export to PDF dialog similar to one in OdaMfcApp
3151
                                if (bUsePRCSingleViewMode)
3152
                                {
3153
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_AllInSingleView");
3154
                                }
3155
                                else
3156
                                {
3157
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_Default");
3158
                                }
3159
                                if (pObj != null)
3160
                                {
3161
                                    RXClass pCls = (RXClass)pObj;
3162
                                    if (pCls != null)
3163
                                    {
3164
                                        param.PRCContext = pCls.Create();
3165
                                        param.PRCMode = PRCSupport.AsBrep; //(bUsePRCAsBRep == TRUE ? PRCSupport.AsBrep : PRCSupport.AsMesh);
3166
                                    }
3167
                                    else
3168
                                    {
3169
                                        Console.WriteLine("PDF Export, PRC support - RXClass failed");
3170
                                    }
3171
                                }
3172
                                else
3173
                                {
3174
                                    Console.WriteLine("PDF Export, PRC support - context failed");
3175
                                }
3176
                            }
3177
                            else
3178
                            {
3179
                                Console.WriteLine("PRC module was not loaded", "Error");
3180
                            }
3181
                        }
3182

    
3183
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3184

    
3185
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3186
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3187

    
3188
                        StringCollection strColl = new StringCollection();
3189
                        if (allLayout)
3190
                        {
3191
                            using (DBDictionary layouts = (DBDictionary)pDb.LayoutDictionaryId.GetObject(OpenMode.ForRead))
3192
                            {
3193
                                foreach (DBDictionaryEntry entry in layouts)
3194
                                {
3195
                                    if ("Model" == entry.Key)
3196
                                        strColl.Insert(0, entry.Key);
3197
                                    else
3198
                                        strColl.Add(entry.Key);
3199
                                    if (-1 != iIndexStyle)
3200
                                    {
3201
                                        PlotSettings ps = (PlotSettings)ta.GetObject(entry.Value, OpenMode.ForWrite);
3202
                                        plotSettingVal.SetCurrentStyleSheet(ps, styleCol[iIndexStyle]);
3203
                                    }
3204
                                }
3205
                            }
3206
                        }
3207
                        else if (-1 != iIndexStyle)
3208
                        {
3209
                            using (BlockTableRecord paperBTR = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3210
                            {
3211
                                using (PlotSettings pLayout = (PlotSettings)paperBTR.LayoutId.GetObject(OpenMode.ForWrite))
3212
                                {
3213
                                    plotSettingVal.SetCurrentStyleSheet(pLayout, styleCol[iIndexStyle]);
3214
                                }
3215
                            }
3216
                        }
3217
                        param.Layouts = strColl;
3218

    
3219
                        int nPages = Math.Max(1, strColl.Count);
3220
                        PageParamsCollection pParCol = new PageParamsCollection();
3221
                        for (int i = 0; i < nPages; ++i)
3222
                        {
3223
                            PageParams pp = new PageParams();
3224
                            pp.setParams(paperWidth, paperHeight);
3225
                            pParCol.Add(pp);
3226
                        }
3227
                        param.PageParams = pParCol;
3228
                        Export_Import.ExportPDF(param);
3229
                    }
3230
                    ta.Abort();
3231
                }
3232
            }
3233
        }
3234

    
3235
        /************************************************************************/
3236
        /* Export DWG to PNG                                                    */
3237
        /************************************************************************/
3238
        public void ExportPNG(Database pDb, string filePath)
3239
        {
3240
            chageColorAllObjects(pDb);
3241

    
3242
            string gdPath = "WinOpenGL_20.5_15.txv";
3243

    
3244
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3245
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3246
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3247
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3248

    
3249
            using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3250
            {
3251
                if (gsModule == null)
3252
                {
3253
                    Console.WriteLine("\nCould not load graphics module {0} \nExport cancelled.", gdPath);
3254
                    return;
3255
                }
3256

    
3257
                // create graphics device
3258
                using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3259
                {
3260
                    // setup device properties
3261
                    using (Dictionary props = dev.Properties)
3262
                    {
3263
                        props.AtPut("BitPerPixel", new RxVariant(32));
3264
                    }
3265
                    using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3266
                    {
3267
                        ctx.PaletteBackground = System.Drawing.Color.White;
3268
                        ctx.SetPlotGeneration(true);
3269

    
3270
                        using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3271
                        {
3272
                            helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3273
                            int width = 9600;
3274
                            int height = 6787;
3275
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
3276
                            helperDevice.OnSize(rect);
3277

    
3278
                            if (ctx.IsPlotGeneration)
3279
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3280
                            else
3281
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3282

    
3283
                            helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3284
                            helperDevice.ActiveView.Zoom(0.99);
3285
                            helperDevice.Update();
3286

    
3287
                            Export_Import.ExportBitmap(helperDevice, bmpPath);
3288
                        }
3289
                    }
3290
                }
3291
            }
3292

    
3293
            if (File.Exists(bmpPath))
3294
            {
3295
                if (File.Exists(pngPath))
3296
                {
3297
                    File.Delete(pngPath);
3298
                }
3299

    
3300
                ////bmp => grayscale bmp => png
3301
                //using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3302
                //{
3303
                //    System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height);
3304
                //    //get a graphics object from the new image
3305
                //    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
3306
                //    {
3307
                //        //create the grayscale ColorMatrix
3308
                //        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][]
3309
                //        {
3310
                //            new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
3311
                //            new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
3312
                //            new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
3313
                //            new float[] { 0,      0,      0,      1, 0 },
3314
                //            new float[] { 0,      0,      0,      0, 1 }
3315
                //        });
3316

    
3317
                //        //create some image attributes
3318
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3319
                //        {
3320
                //            //set the color matrix attribute
3321
                //            attributes.SetColorMatrix(colorMatrix);
3322
                //            //attributes.SetThreshold(0.8F);
3323

    
3324
                //            //draw the original image on the new image
3325
                //            //using the grayscale color matrix
3326
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3327
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3328
                //        }
3329

    
3330
                //    }
3331
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3332
                //}
3333

    
3334
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3335
                {
3336
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3337
                }
3338
                if (File.Exists(bmpPath))
3339
                {
3340
                    File.Delete(bmpPath);
3341
                }
3342
            }
3343
        }
3344

    
3345
        /************************************************************************/
3346
        /* Change the color of all objects                                      */
3347
        /************************************************************************/
3348
        private void chageColorAllObjects(Database pDb)
3349
        {
3350
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3351
            {
3352
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3353
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3354

    
3355
                foreach (ObjectId id in btrModelSpace)
3356
                {
3357
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3358
                    if (ent == null) continue;
3359

    
3360
                    ent.ColorIndex = 7;
3361

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

    
3368
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3369
                foreach (DBDictionaryEntry entry in dbdic)
3370
                {
3371
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3372
                    if (group == null) continue;
3373

    
3374
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3375
                    if (idarrTags == null) continue;
3376

    
3377
                    foreach (ObjectId id in idarrTags)
3378
                    {
3379
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3380
                        if (ent == null) continue;
3381

    
3382
                        ent.ColorIndex = 7;
3383
                    }
3384
                }
3385

    
3386
                foreach (ObjectId btrId in bt)
3387
                {
3388
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3389
                    if (btr == null) continue;
3390
                    if (btr.Name.StartsWith("*")) continue;
3391

    
3392
                    foreach (ObjectId entId in btr)
3393
                    {
3394
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3395
                        if (ent == null) continue;
3396
                        ent.ColorIndex = 0;//ByBlock
3397
                    }
3398
                }
3399

    
3400
                tr.Commit();
3401
            }
3402
        }
3403

    
3404
        /************************************************************************/
3405
        /* Change the color of blocks                                           */
3406
        /************************************************************************/
3407
        private void changeColorBlocks(Transaction tr, BlockReference blkRef)
3408
        {
3409
            if (blkRef == null) return;
3410

    
3411
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3412
            {
3413
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3414
                {
3415
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3416
                    attRef.ColorIndex = 7;
3417
                }
3418
            }
3419

    
3420
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3421
            if (btrBlock == null) return;
3422

    
3423
            foreach (ObjectId oid in btrBlock)
3424
            {
3425
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3426
                if (ent == null) continue;
3427

    
3428
                ent.ColorIndex = 7;
3429

    
3430
                if (ent is BlockReference)
3431
                {
3432
                    
3433
                    changeColorBlocks(tr, (BlockReference)ent);
3434
                }
3435
            }
3436
        }
3437

    
3438
        /************************************************************************/
3439
        /* Nested block Explode & Purge                                         */
3440
        /************************************************************************/
3441
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3442
        {
3443
            HashSet<string> blockNameList = new HashSet<string>();
3444
            // Explode ModelSpace Nested Block
3445
            blockNameList = explodeNestedBlocks(pDb);
3446

    
3447
            // Prepare Block Purge
3448
            preparePurgeBlocks(pDb, blockNameList);
3449

    
3450
            // Block Purge
3451
            ObjectIdCollection oids = new ObjectIdCollection();
3452
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3453
            {
3454
                foreach (ObjectId id in pTable)
3455
                {
3456
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3457
                    oids.Add(id);
3458
                }
3459
            }
3460
            pDb.Purge(oids);
3461

    
3462
            foreach (ObjectId oid in oids)
3463
            {
3464
                if (oid.IsErased) continue;
3465

    
3466
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3467
                {
3468
                    btr.Erase(true);
3469
                }                
3470
            }
3471
        }
3472

    
3473
        private HashSet<string> explodeNestedBlocks(Database pDb)
3474
        {
3475
            HashSet<string> blockNameList = new HashSet<string>();
3476
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3477

    
3478
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3479
            {
3480
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3481
                {
3482
                    foreach (ObjectId entid in pBlock)
3483
                    {
3484
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3485
                        {
3486
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3487
                            BlockReference blockRef = (BlockReference)pEnt;
3488

    
3489
                            if (blockRef.Name.ToUpper().StartsWith(BLOCK_PIPING))
3490
                            {
3491
                                oidSet.Add(entid);
3492
                                continue;
3493
                            }
3494
                            else if (blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3495
                            {
3496
                                continue;
3497
                            }
3498
                            
3499
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3500
                            {
3501
                                bool isNestedBlock = false;
3502
                                foreach (ObjectId blkid in pBtr)
3503
                                {
3504
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3505
                                    {
3506
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3507
                                        {
3508
                                            oidSet.Add(entid);
3509
                                            isNestedBlock = true;
3510
                                        }
3511
                                    }
3512
                                }
3513
                                if (!isNestedBlock)
3514
                                {
3515
                                    blockNameList.Add(blockRef.Name);
3516
                                }
3517
                            }
3518
                        }
3519
                    }
3520
                }
3521
            }
3522

    
3523
            if (oidSet.Count > 0)
3524
            {
3525
                explodeBlocks(oidSet);
3526
                blockNameList = explodeNestedBlocks(pDb);
3527
            }
3528

    
3529
            return blockNameList;
3530
        }
3531

    
3532
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3533
        {
3534
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3535

    
3536
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3537
            {
3538
                foreach (ObjectId id in pTable)
3539
                {
3540
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForWrite, false, true))
3541
                    {
3542
                        if (pBlock.IsLayout) continue;
3543
                        pBlock.Explodable = true;
3544
                        if (blockNameList.Contains(pBlock.Name)) continue;
3545

    
3546
                        foreach (ObjectId entid in pBlock)
3547
                        {
3548
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3549
                            {
3550
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3551

    
3552
                                oidSet.Add(entid);
3553
                            }
3554
                        }
3555
                    }
3556
                }
3557
            }
3558

    
3559
            if (oidSet.Count > 0)
3560
            {
3561
                explodeBlocks(oidSet);
3562
                preparePurgeBlocks(pDb, blockNameList);
3563
            }
3564

    
3565
            return;
3566
        }
3567
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3568
        {
3569
            foreach (ObjectId blkId in oidSet)
3570
            {
3571
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3572
                blkRef.ExplodeGeometryToOwnerSpace();
3573
                blkRef.Erase();
3574
            }
3575
        }
3576

    
3577
        /************************************************************************/
3578
        /* Save Block as DWG For Auxiliary Graphic                              */
3579
        /************************************************************************/
3580
        public void ExportGraphicBlocks(Database pDb, string savePath)
3581
        {
3582
            try
3583
            {
3584
                using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3585
                {
3586
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3587
                    {
3588
                        foreach (ObjectId entid in pBlock)
3589
                        {
3590
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3591
                            {
3592
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3593
                                BlockReference blockRef = (BlockReference)pEnt;
3594
                                if (!blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3595
                                    continue;
3596

    
3597
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3598
                                objIdCol.Add(blockRef.ObjectId);
3599
                                if (objIdCol.Count == 0) continue;
3600

    
3601
                                string filePath = string.Format("{0}.dwg", blockRef.Name);
3602
                                string directory = Path.GetDirectoryName(savePath);
3603
                                directory = directory.ToLower().Replace("drawings\\native", "graphic");
3604
                                if (!Directory.Exists(directory))
3605
                                {
3606
                                    Directory.CreateDirectory(directory);
3607
                                }
3608
                                filePath = Path.Combine(directory, filePath);
3609
                                
3610
                                using (Database newDb = new Database(true, false))
3611
                                {
3612
                                    pDb.Wblock(newDb, objIdCol, Point3d.Origin, DuplicateRecordCloning.Ignore);
3613
                                    newDb.UpdateExt(true);
3614
                                    newDb.SaveAs(filePath, DwgVersion.Newest);
3615
                                }
3616

    
3617
                                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo();
3618
                                procStartInfo.FileName = @"C:\Program Files (x86)\SmartSketch\Program\Rad2d\bin\Dwg2Igr.exe";
3619
                                procStartInfo.RedirectStandardOutput = true;
3620
                                procStartInfo.RedirectStandardInput = true;
3621
                                procStartInfo.RedirectStandardError = true;
3622
                                procStartInfo.UseShellExecute = false;
3623
                                procStartInfo.CreateNoWindow = false;
3624
                                procStartInfo.Arguments = filePath.Replace(" ", "^");
3625

    
3626
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3627
                                {
3628
                                    proc.StartInfo = procStartInfo;
3629
                                    proc.Start();
3630
                                    proc.StandardInput.Close();
3631
                                    proc.WaitForExit();
3632

    
3633
                                    switch (proc.ExitCode)
3634
                                    {
3635
                                        case -1:
3636
                                            Console.WriteLine("[{0}] path does not exist or there is no file", filePath);
3637
                                            break;
3638
                                        case 0:
3639
                                            Console.WriteLine("[{0}] File conversion error", filePath.Replace(".dwg", ".igr"));
3640
                                            break;
3641
                                        case 1:
3642
                                            Console.WriteLine("[{0}] File conversion success", filePath.Replace(".dwg", ".igr"));
3643
                                            break;
3644
                                        default:
3645
                                            break;
3646
                                    }
3647
                                }
3648
                            }
3649
                        }
3650
                    }
3651
                }
3652
            }
3653
            catch (System.Exception ex)
3654
            {
3655
            }
3656
        }
3657
        /************************************************************************/
3658
        /* Dump the BlockTable                                                  */
3659
        /************************************************************************/
3660
        public void dumpBlocks(Database pDb, int indent, XmlNode node)
3661
        {
3662
            /**********************************************************************/
3663
            /* Get a pointer to the BlockTable                               */
3664
            /**********************************************************************/
3665
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3666
            {
3667
                /**********************************************************************/
3668
                /* Dump the Description                                               */
3669
                /**********************************************************************/
3670
                XmlElement BlocksNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
3671

    
3672
                /**********************************************************************/
3673
                /* Step through the BlockTable                                        */
3674
                /**********************************************************************/
3675
                foreach (ObjectId id in pTable)
3676
                {
3677
                    /********************************************************************/
3678
                    /* Open the BlockTableRecord for Reading                            */
3679
                    /********************************************************************/
3680
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3681
                    {
3682
                        /********************************************************************/
3683
                        /* Dump the BlockTableRecord                                        */
3684
                        /********************************************************************/
3685
                        XmlElement BlockNode = Program.xml.CreateElement(pBlock.GetRXClass().Name);
3686

    
3687
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
3688
                        NameAttr.Value = pBlock.Name;
3689
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3690

    
3691
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3692
                        CommentsAttr.Value = pBlock.Comments;
3693
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3694

    
3695
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3696
                        OriginAttr.Value = pBlock.Origin.ToString();
3697
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3698

    
3699
                        writeLine(indent, pBlock.GetRXClass().Name);
3700
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3701
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3702
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3703
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3704
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3705

    
3706
                        try
3707
                        {
3708
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3709
                            extents.AddBlockExtents(pBlock);
3710

    
3711
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3712
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3713
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3714

    
3715
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3716
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3717
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3718
                        }
3719
                        catch (System.Exception)
3720
                        {
3721
                        }
3722

    
3723
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3724
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3725
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3726
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3727
                        {
3728
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3729
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3730
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3731
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3732
                        }
3733

    
3734
                        /********************************************************************/
3735
                        /* Step through the BlockTableRecord                                */
3736
                        /********************************************************************/
3737
                        foreach (ObjectId entid in pBlock)
3738
                        {
3739
                            /********************************************************************/
3740
                            /* Dump the Entity                                                  */
3741
                            /********************************************************************/
3742
                            dumpEntity(entid, indent + 1, BlockNode);
3743
                        }
3744

    
3745
                        BlocksNode.AppendChild(BlockNode);
3746
                    }
3747
                }
3748

    
3749
                node.AppendChild(BlocksNode);
3750
            }
3751
        }
3752

    
3753
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3754
        {
3755
            /**********************************************************************/
3756
            /* Get a SmartPointer to the DimStyleTable                            */
3757
            /**********************************************************************/
3758
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3759
            {
3760
                /**********************************************************************/
3761
                /* Dump the Description                                               */
3762
                /**********************************************************************/
3763
                writeLine();
3764
                writeLine(indent++, pTable.GetRXClass().Name);
3765

    
3766
                /**********************************************************************/
3767
                /* Step through the DimStyleTable                                    */
3768
                /**********************************************************************/
3769
                foreach (ObjectId id in pTable)
3770
                {
3771
                    /*********************************************************************/
3772
                    /* Open the DimStyleTableRecord for Reading                         */
3773
                    /*********************************************************************/
3774
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3775
                    {
3776
                        /*********************************************************************/
3777
                        /* Dump the DimStyleTableRecord                                      */
3778
                        /*********************************************************************/
3779
                        writeLine();
3780
                        writeLine(indent, pRecord.GetRXClass().Name);
3781
                        writeLine(indent, "Name", pRecord.Name);
3782
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3783

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

    
3857
                        dumpSymbolTableRecord(pRecord, indent, node);
3858
                    }
3859
                }
3860
            }
3861
        }
3862

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

    
4026
                    /**********************************************************************/
4027
                    /* Dump the Extension Dictionary                                      */
4028
                    /**********************************************************************/
4029
                    if (!pEnt.ExtensionDictionary.IsNull)
4030
                    {
4031
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
4032
                    }
4033
                }
4034
            }
4035
            catch (System.Exception ex)
4036
            {
4037
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
4038
            }
4039
        }
4040
        public void dumpHeader(Database pDb, int indent, XmlNode node)
4041
        {
4042
            if (node != null)
4043
            {
4044
                XmlAttribute FileNameAttr = Program.xml.CreateAttribute("FileName");
4045
                FileNameAttr.Value = shortenPath(pDb.Filename);
4046
                node.Attributes.SetNamedItem(FileNameAttr);
4047

    
4048
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
4049
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4050
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4051

    
4052
                writeLine();
4053
                writeLine(indent++, "Header Variables:");
4054

    
4055
                //writeLine();
4056
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4057
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4058

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

    
4214
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4215
        {
4216
            if (node != null)
4217
            {
4218
                /**********************************************************************/
4219
                /* Get a SmartPointer to the LayerTable                               */
4220
                /**********************************************************************/
4221
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4222
                {
4223
                    /**********************************************************************/
4224
                    /* Dump the Description                                               */
4225
                    /**********************************************************************/
4226
                    XmlElement LayerNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4227

    
4228
                    /**********************************************************************/
4229
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4230
                    /**********************************************************************/
4231

    
4232
                    /**********************************************************************/
4233
                    /* Step through the LayerTable                                        */
4234
                    /**********************************************************************/
4235
                    foreach (ObjectId id in pTable)
4236
                    {
4237
                        /********************************************************************/
4238
                        /* Open the LayerTableRecord for Reading                            */
4239
                        /********************************************************************/
4240
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4241
                        {
4242
                            /********************************************************************/
4243
                            /* Dump the LayerTableRecord                                        */
4244
                            /********************************************************************/
4245
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4246

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

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

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

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

    
4263
                            XmlAttribute IsLockedAttr = Program.xml.CreateAttribute("IsLocked");
4264
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4265
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4266

    
4267
                            XmlAttribute ColorAttr = Program.xml.CreateAttribute("Color");
4268
                            ColorAttr.Value = pRecord.Color.ToString();
4269
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4270

    
4271
                            XmlAttribute LinetypeObjectIdAttr = Program.xml.CreateAttribute("LinetypeObjectId");
4272
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4273
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4274

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

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

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

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

    
4291
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4292
                            LayerNode.AppendChild(RecordNode);
4293
                        }
4294
                    }
4295

    
4296
                    node.AppendChild(LayerNode);
4297
                }
4298
            }
4299
        }
4300

    
4301
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4302
        {
4303
            if (node != null)
4304
            {
4305
                /**********************************************************************/
4306
                /* Get a pointer to the LinetypeTable                            */
4307
                /**********************************************************************/
4308
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4309
                {
4310
                    XmlElement LinetypeNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4311

    
4312
                    /**********************************************************************/
4313
                    /* Step through the LinetypeTable                                     */
4314
                    /**********************************************************************/
4315
                    foreach (ObjectId id in pTable)
4316
                    {
4317
                        /*********************************************************************/
4318
                        /* Open the LinetypeTableRecord for Reading                          */
4319
                        /*********************************************************************/
4320
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4321
                        {
4322
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4323

    
4324
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4325
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4326
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4327

    
4328
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4329
                            NameAttr.Value = pRecord.Name;
4330
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4331

    
4332
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4333
                            CommentsAttr.Value = pRecord.Comments;
4334
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4335

    
4336
                            /********************************************************************/
4337
                            /* Dump the first line of record as in ACAD.LIN                     */
4338
                            /********************************************************************/
4339
                            string buffer = "*" + pRecord.Name;
4340
                            if (pRecord.Comments != "")
4341
                            {
4342
                                buffer = buffer + "," + pRecord.Comments;
4343
                            }
4344
                            writeLine(indent, buffer);
4345

    
4346
                            /********************************************************************/
4347
                            /* Dump the second line of record as in ACAD.LIN                    */
4348
                            /********************************************************************/
4349
                            if (pRecord.NumDashes > 0)
4350
                            {
4351
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4352
                                for (int i = 0; i < pRecord.NumDashes; i++)
4353
                                {
4354
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4355
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4356
                                    string text = pRecord.TextAt(i);
4357

    
4358
                                    /**************************************************************/
4359
                                    /* Dump the Complex Line                                      */
4360
                                    /**************************************************************/
4361
                                    if (shapeNumber != 0 || text != "")
4362
                                    {
4363
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4364
                                        {
4365
                                            if (shapeNumber != 0)
4366
                                            {
4367
                                                buffer = buffer + ",[" + shapeNumber + ",";
4368
                                                if (pTextStyle != null)
4369
                                                    buffer = buffer + pTextStyle.FileName;
4370
                                                else
4371
                                                    buffer = buffer + "NULL style";
4372
                                            }
4373
                                            else
4374
                                            {
4375
                                                buffer = buffer + ",[" + text + ",";
4376
                                                if (pTextStyle != null)
4377
                                                    buffer = buffer + pTextStyle.Name;
4378
                                                else
4379
                                                    buffer = buffer + "NULL style";
4380
                                            }
4381
                                        }
4382

    
4383
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4384
                                        {
4385
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4386
                                        }
4387
                                        if (pRecord.ShapeRotationAt(i) != 0)
4388
                                        {
4389
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4390
                                        }
4391
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4392
                                        {
4393
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4394
                                        }
4395
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4396
                                        {
4397
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4398
                                        }
4399
                                        buffer = buffer + "]";
4400
                                    }
4401
                                }
4402
                                writeLine(indent, buffer);
4403
                            }
4404
                            dumpSymbolTableRecord(pRecord, indent, node);
4405
                            LinetypeNode.AppendChild(RecordNode);
4406
                        }
4407
                    }
4408

    
4409
                    node.AppendChild(LinetypeNode);
4410
                }
4411
            }
4412
        }
4413

    
4414
        public void dumpRegApps(Database pDb, int indent)
4415
        {
4416
            /**********************************************************************/
4417
            /* Get a pointer to the RegAppTable                            */
4418
            /**********************************************************************/
4419
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4420
            {
4421
                /**********************************************************************/
4422
                /* Dump the Description                                               */
4423
                /**********************************************************************/
4424
                writeLine();
4425
                writeLine(indent++, pTable.GetRXClass().Name);
4426

    
4427
                /**********************************************************************/
4428
                /* Step through the RegAppTable                                    */
4429
                /**********************************************************************/
4430
                foreach (ObjectId id in pTable)
4431
                {
4432
                    /*********************************************************************/
4433
                    /* Open the RegAppTableRecord for Reading                         */
4434
                    /*********************************************************************/
4435
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4436
                    {
4437
                        /*********************************************************************/
4438
                        /* Dump the RegAppTableRecord                                      */
4439
                        /*********************************************************************/
4440
                        writeLine();
4441
                        writeLine(indent, pRecord.GetRXClass().Name);
4442
                        writeLine(indent, "Name", pRecord.Name);
4443
                    }
4444
                }
4445
            }
4446
        }
4447

    
4448
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4449
        {
4450
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4451
            if (pRecord.IsDependent)
4452
            {
4453
                writeLine(indent, "Resolved", pRecord.IsResolved);
4454
            }
4455
        }
4456

    
4457
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4458
        {
4459
            /**********************************************************************/
4460
            /* Get a SmartPointer to the TextStyleTable                            */
4461
            /**********************************************************************/
4462
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4463
            {
4464
                /**********************************************************************/
4465
                /* Dump the Description                                               */
4466
                /**********************************************************************/
4467
                writeLine();
4468
                writeLine(indent++, pTable.GetRXClass().Name);
4469

    
4470
                /**********************************************************************/
4471
                /* Step through the TextStyleTable                                    */
4472
                /**********************************************************************/
4473
                foreach (ObjectId id in pTable)
4474
                {
4475
                    /*********************************************************************/
4476
                    /* Open the TextStyleTableRecord for Reading                         */
4477
                    /*********************************************************************/
4478
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4479
                    {
4480
                        /*********************************************************************/
4481
                        /* Dump the TextStyleTableRecord                                      */
4482
                        /*********************************************************************/
4483
                        writeLine();
4484
                        writeLine(indent, pRecord.GetRXClass().Name);
4485
                        writeLine(indent, "Name", pRecord.Name);
4486
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4487
                        writeLine(indent, "Text Height", pRecord.TextSize);
4488
                        writeLine(indent, "Width Factor", pRecord.XScale);
4489
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4490
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4491
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4492
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4493
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4494
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4495

    
4496
                        FontDescriptor fd = pRecord.Font;
4497
                        writeLine(indent, "Typeface", fd.TypeFace);
4498
                        writeLine(indent, "Character Set", fd.CharacterSet);
4499
                        writeLine(indent, "Bold", fd.Bold);
4500
                        writeLine(indent, "Italic", fd.Italic);
4501
                        writeLine(indent, "Font Pitch & Family", toHexString(fd.PitchAndFamily));
4502
                        dumpSymbolTableRecord(pRecord, indent, node);
4503
                    }
4504
                }
4505
            }
4506
        }
4507
        public void dumpAbstractViewTableRecord(AbstractViewTableRecord pView, int indent, XmlNode node)
4508
        {
4509
            /*********************************************************************/
4510
            /* Dump the AbstractViewTableRecord                                  */
4511
            /*********************************************************************/
4512
            writeLine(indent, "Back Clip Dist", pView.BackClipDistance);
4513
            writeLine(indent, "Back Clip Enabled", pView.BackClipEnabled);
4514
            writeLine(indent, "Front Clip Dist", pView.FrontClipDistance);
4515
            writeLine(indent, "Front Clip Enabled", pView.FrontClipEnabled);
4516
            writeLine(indent, "Front Clip at Eye", pView.FrontClipAtEye);
4517
            writeLine(indent, "Elevation", pView.Elevation);
4518
            writeLine(indent, "Height", pView.Height);
4519
            writeLine(indent, "Width", pView.Width);
4520
            writeLine(indent, "Lens Length", pView.LensLength);
4521
            writeLine(indent, "Render Mode", pView.RenderMode);
4522
            writeLine(indent, "Perspective", pView.PerspectiveEnabled);
4523
            writeLine(indent, "UCS Name", pView.UcsName);
4524

    
4525
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4526
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4527

    
4528
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4529
            {
4530
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4531
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4532
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4533
            }
4534

    
4535
            writeLine(indent, "Target", pView.Target);
4536
            writeLine(indent, "View Direction", pView.ViewDirection);
4537
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4538
            dumpSymbolTableRecord(pView, indent, node);
4539
        }
4540
        public void dumpDimAssoc(DBObject pObject, int indent)
4541
        {
4542

    
4543
        }
4544
        public void dumpMLineStyles(Database pDb, int indent)
4545
        {
4546
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4547
            {
4548
                /**********************************************************************/
4549
                /* Dump the Description                                               */
4550
                /**********************************************************************/
4551
                writeLine();
4552
                writeLine(indent++, pDictionary.GetRXClass().Name);
4553

    
4554
                /**********************************************************************/
4555
                /* Step through the MlineStyle dictionary                             */
4556
                /**********************************************************************/
4557
                DbDictionaryEnumerator e = pDictionary.GetEnumerator();
4558
                while (e.MoveNext())
4559
                {
4560
                    try
4561
                    {
4562
                        using (MlineStyle pEntry = (MlineStyle)e.Value.Open(OpenMode.ForRead))
4563
                        {
4564
                            /*********************************************************************/
4565
                            /* Dump the MLineStyle dictionary entry                              */
4566
                            /*********************************************************************/
4567
                            writeLine();
4568
                            writeLine(indent, pEntry.GetRXClass().Name);
4569
                            writeLine(indent, "Name", pEntry.Name);
4570
                            writeLine(indent, "Description", pEntry.Description);
4571
                            writeLine(indent, "Start Angle", toDegreeString(pEntry.StartAngle));
4572
                            writeLine(indent, "End Angle", toDegreeString(pEntry.EndAngle));
4573
                            writeLine(indent, "Start Inner Arcs", pEntry.StartInnerArcs);
4574
                            writeLine(indent, "End Inner Arcs", pEntry.EndInnerArcs);
4575
                            writeLine(indent, "Start Round Cap", pEntry.StartRoundCap);
4576
                            writeLine(indent, "End Round Cap", pEntry.EndRoundCap);
4577
                            writeLine(indent, "Start Square Cap", pEntry.StartRoundCap);
4578
                            writeLine(indent, "End Square Cap", pEntry.EndRoundCap);
4579
                            writeLine(indent, "Show Miters", pEntry.ShowMiters);
4580
                            /*********************************************************************/
4581
                            /* Dump the elements                                                 */
4582
                            /*********************************************************************/
4583
                            if (pEntry.Elements.Count > 0)
4584
                            {
4585
                                writeLine(indent, "Elements:");
4586
                            }
4587
                            int i = 0;
4588
                            foreach (MlineStyleElement el in pEntry.Elements)
4589
                            {
4590
                                writeLine(indent, "Index", (i++));
4591
                                writeLine(indent + 1, "Offset", el.Offset);
4592
                                writeLine(indent + 1, "Color", el.Color);
4593
                                writeLine(indent + 1, "Linetype", el.LinetypeId);
4594
                            }
4595
                        }
4596
                    }
4597
                    catch (System.Exception)
4598
                    {
4599
                    }
4600
                }
4601
            }
4602
        }
4603
        public void dumpObject(ObjectId id, string itemName, int indent)
4604
        {
4605
            using (DBObject pObject = id.Open(OpenMode.ForRead))
4606
            {
4607
                /**********************************************************************/
4608
                /* Dump the item name and class name                                  */
4609
                /**********************************************************************/
4610
                if (pObject is DBDictionary)
4611
                {
4612
                    writeLine();
4613
                }
4614
                writeLine(indent++, itemName, pObject.GetRXClass().Name);
4615

    
4616
                /**********************************************************************/
4617
                /* Dispatch                                                           */
4618
                /**********************************************************************/
4619
                if (pObject is DBDictionary)
4620
                {
4621
                    /********************************************************************/
4622
                    /* Dump the dictionary                                               */
4623
                    /********************************************************************/
4624
                    DBDictionary pDic = (DBDictionary)pObject;
4625

    
4626
                    /********************************************************************/
4627
                    /* Get a pointer to a new DictionaryIterator                   */
4628
                    /********************************************************************/
4629
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4630

    
4631
                    /********************************************************************/
4632
                    /* Step through the Dictionary                                      */
4633
                    /********************************************************************/
4634
                    while (pIter.MoveNext())
4635
                    {
4636
                        /******************************************************************/
4637
                        /* Dump the Dictionary object                                     */
4638
                        /******************************************************************/
4639
                        dumpObject(pIter.Value, pIter.Key, indent);
4640
                    }
4641
                }
4642
                else if (pObject is Xrecord)
4643
                {
4644
                    /********************************************************************/
4645
                    /* Dump an Xrecord                                                  */
4646
                    /********************************************************************/
4647
                    Xrecord pXRec = (Xrecord)pObject;
4648
                    dumpXdata(pXRec.Data, indent);
4649
                }
4650
            }
4651
        }
4652

    
4653
        public void dumpUCSTable(Database pDb, int indent, XmlNode node)
4654
        {
4655
            /**********************************************************************/
4656
            /* Get a pointer to the UCSTable                               */
4657
            /**********************************************************************/
4658
            using (UcsTable pTable = (UcsTable)pDb.UcsTableId.Open(OpenMode.ForRead))
4659
            {
4660
                /**********************************************************************/
4661
                /* Dump the Description                                               */
4662
                /**********************************************************************/
4663
                writeLine();
4664
                writeLine(indent++, pTable.GetRXClass().Name);
4665

    
4666
                /**********************************************************************/
4667
                /* Step through the UCSTable                                          */
4668
                /**********************************************************************/
4669
                foreach (ObjectId id in pTable)
4670
                {
4671
                    /********************************************************************/
4672
                    /* Open the UCSTableRecord for Reading                            */
4673
                    /********************************************************************/
4674
                    using (UcsTableRecord pRecord = (UcsTableRecord)id.Open(OpenMode.ForRead))
4675
                    {
4676
                        /********************************************************************/
4677
                        /* Dump the UCSTableRecord                                        */
4678
                        /********************************************************************/
4679
                        writeLine();
4680
                        writeLine(indent, pRecord.GetRXClass().Name);
4681
                        writeLine(indent, "Name", pRecord.Name);
4682
                        writeLine(indent, "UCS Origin", pRecord.Origin);
4683
                        writeLine(indent, "UCS x-Axis", pRecord.XAxis);
4684
                        writeLine(indent, "UCS y-Axis", pRecord.YAxis);
4685
                        dumpSymbolTableRecord(pRecord, indent, node);
4686
                    }
4687
                }
4688
            }
4689
        }
4690
        public void dumpViewports(Database pDb, int indent, XmlNode node)
4691
        {
4692
            /**********************************************************************/
4693
            /* Get a pointer to the ViewportTable                            */
4694
            /**********************************************************************/
4695
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4696
            {
4697
                /**********************************************************************/
4698
                /* Dump the Description                                               */
4699
                /**********************************************************************/
4700
                writeLine();
4701
                writeLine(indent++, pTable.GetRXClass().Name);
4702

    
4703
                /**********************************************************************/
4704
                /* Step through the ViewportTable                                    */
4705
                /**********************************************************************/
4706
                foreach (ObjectId id in pTable)
4707
                {
4708
                    /*********************************************************************/
4709
                    /* Open the ViewportTableRecord for Reading                          */
4710
                    /*********************************************************************/
4711
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4712
                    {
4713
                        /*********************************************************************/
4714
                        /* Dump the ViewportTableRecord                                      */
4715
                        /*********************************************************************/
4716
                        writeLine();
4717
                        writeLine(indent, pRecord.GetRXClass().Name);
4718
                        writeLine(indent, "Name", pRecord.Name);
4719
                        writeLine(indent, "Circle Sides", pRecord.CircleSides);
4720
                        writeLine(indent, "Fast Zooms Enabled", pRecord.FastZoomsEnabled);
4721
                        writeLine(indent, "Grid Enabled", pRecord.GridEnabled);
4722
                        writeLine(indent, "Grid Increments", pRecord.GridIncrements);
4723
                        writeLine(indent, "Icon at Origin", pRecord.IconAtOrigin);
4724
                        writeLine(indent, "Icon Enabled", pRecord.IconEnabled);
4725
                        writeLine(indent, "Iso snap Enabled", pRecord.IsometricSnapEnabled);
4726
                        writeLine(indent, "Iso Snap Pair", pRecord.SnapPair);
4727
                        writeLine(indent, "UCS Saved w/Vport", pRecord.UcsSavedWithViewport);
4728
                        writeLine(indent, "UCS follow", pRecord.UcsFollowMode);
4729
                        writeLine(indent, "Lower-Left Corner", pRecord.LowerLeftCorner);
4730
                        writeLine(indent, "Upper-Right Corner", pRecord.UpperRightCorner);
4731
                        writeLine(indent, "Snap Angle", toDegreeString(pRecord.SnapAngle));
4732
                        writeLine(indent, "Snap Base", pRecord.SnapBase);
4733
                        writeLine(indent, "Snap Enabled", pRecord.SnapEnabled);
4734
                        writeLine(indent, "Snap Increments", pRecord.SnapIncrements);
4735
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4736
                    }
4737
                }
4738
            }
4739
        }
4740

    
4741
        /************************************************************************/
4742
        /* Dump the ViewTable                                                   */
4743
        /************************************************************************/
4744
        public void dumpViews(Database pDb, int indent, XmlNode node)
4745
        {
4746
            /**********************************************************************/
4747
            /* Get a pointer to the ViewTable                                */
4748
            /**********************************************************************/
4749
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
4750
            {
4751
                /**********************************************************************/
4752
                /* Dump the Description                                               */
4753
                /**********************************************************************/
4754
                writeLine();
4755
                writeLine(indent++, pTable.GetRXClass().Name);
4756

    
4757
                /**********************************************************************/
4758
                /* Step through the ViewTable                                         */
4759
                /**********************************************************************/
4760
                foreach (ObjectId id in pTable)
4761
                {
4762
                    /*********************************************************************/
4763
                    /* Open the ViewTableRecord for Reading                              */
4764
                    /*********************************************************************/
4765
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
4766
                    {
4767
                        /*********************************************************************/
4768
                        /* Dump the ViewTableRecord                                          */
4769
                        /*********************************************************************/
4770
                        writeLine();
4771
                        writeLine(indent, pRecord.GetRXClass().Name);
4772
                        writeLine(indent, "Name", pRecord.Name);
4773
                        writeLine(indent, "Category Name", pRecord.CategoryName);
4774
                        writeLine(indent, "Layer State", pRecord.LayerState);
4775

    
4776
                        string layoutName = "";
4777
                        if (!pRecord.Layout.IsNull)
4778
                        {
4779
                            using (Layout pLayout = (Layout)pRecord.Layout.Open(OpenMode.ForRead))
4780
                                layoutName = pLayout.LayoutName;
4781
                        }
4782
                        writeLine(indent, "Layout Name", layoutName);
4783
                        writeLine(indent, "PaperSpace View", pRecord.IsPaperspaceView);
4784
                        writeLine(indent, "Associated UCS", pRecord.IsUcsAssociatedToView);
4785
                        writeLine(indent, "PaperSpace View", pRecord.ViewAssociatedToViewport);
4786
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4787
                    }
4788
                }
4789
            }
4790
        }
4791
        /************************************************************************/
4792
        /* Dump Xdata                                                           */
4793
        /************************************************************************/
4794
        public void dumpXdata(ResultBuffer xIter, int indent)
4795
        {
4796
            if (xIter == null)
4797
                return;
4798
            writeLine(indent++, "Xdata:");
4799
            /**********************************************************************/
4800
            /* Step through the ResBuf chain                                      */
4801
            /**********************************************************************/
4802
            try
4803
            {
4804
                int rsCount = xIter.Cast<TypedValue>().Count();
4805
                
4806
                foreach (TypedValue resbuf in xIter)
4807
                {
4808
                    writeLine(indent, resbuf);
4809
                }
4810
            }
4811
            catch (System.Exception ex)
4812
            {
4813
            }
4814
            
4815
        }
4816
    }
4817
    class ExProtocolExtension
4818
    {
4819
    }
4820

    
4821
    class Program
4822
    {
4823
        public static XmlDocument xml = null;
4824
        public static double OffsetX = 0;
4825
        public static double OffsetY = 0;
4826
        public static double Scale = 0;
4827
        public static double getDrawing = 0;
4828
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
4829

    
4830
        static void Main(string[] args)
4831
        {
4832
            /********************************************************************/
4833
            /* Initialize Drawings.NET.                                         */
4834
            /********************************************************************/
4835
            bool bSuccess = true;
4836
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
4837
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
4838
            {
4839
                try
4840
                {
4841
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
4842
                    /**********************************************************************/
4843
                    /* Display the Product and Version that created the executable        */
4844
                    /**********************************************************************/
4845
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
4846

    
4847
                    if (args.Length != 5)
4848
                    {
4849
                        Console.WriteLine("\n\n\tusage: OdReadExMgd <filename> <OffsetX> <OffsetY> <Scale> <GenDrawing>");
4850
                        Console.WriteLine("\nPress ENTER to continue...\n");
4851
                        Console.ReadLine();
4852
                        bSuccess = false;
4853
                    }
4854
                    else
4855
                    {
4856
                        Console.WriteLine("\n File Name = " + args[0]);
4857

    
4858
                        double.TryParse(args[1], out Program.OffsetX);
4859
                        double.TryParse(args[2], out Program.OffsetY);
4860
                        double.TryParse(args[3], out Program.Scale);
4861
                        double.TryParse(args[4], out Program.getDrawing);
4862
                        Program.xml = new XmlDocument();
4863
                        {
4864
                            XmlNode root = xml.CreateElement("ID2");
4865
                            Program.xml.AppendChild(root);
4866

    
4867
                            /******************************************************************/
4868
                            /* Create a database and load the drawing into it.                
4869
                            /* first parameter means - do not initialize database- it will be read from file
4870
                             * second parameter is not used by Teigha.NET Classic - it is left for ARX compatibility.
4871
                             * Note the 'using' clause - generally, wrappers should disposed after use, 
4872
                             * to close underlying database objects
4873
                            /******************************************************************/
4874
                            using (Database pDb = new Database(false, false))
4875
                            {
4876
                                pDb.ReadDwgFile(args[0], FileShare.Read, true, "");
4877
                                HostApplicationServices.WorkingDatabase = pDb;
4878
                                /****************************************************************/
4879
                                /* Display the File Version                                     */
4880
                                /****************************************************************/
4881
                                Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion);
4882
                                /****************************************************************/
4883
                                /* Dump the database                                            */
4884
                                /****************************************************************/
4885
                                DbDumper dumper = new DbDumper();
4886
                                dumper.ExplodeAndPurgeNestedBlocks(pDb);
4887
                                if (Program.getDrawing == 1)
4888
                                {
4889
                                    dumper.ExportPNG(pDb, args[0]);
4890
                                    dumper.ExportPDF(pDb, args[0]);
4891
                                    dumper.ExportGraphicBlocks(pDb, args[0]);
4892
                                }
4893

    
4894
                                dumper.dump(pDb, 0, Program.xml.DocumentElement);
4895
                            }
4896
                            Program.xml.Save(Path.Combine(Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]) + ".xml"));
4897
                        }
4898
                    }
4899
                }
4900
                /********************************************************************/
4901
                /* Display the error                                                */
4902
                /********************************************************************/
4903
                catch (System.Exception e)
4904
                {
4905
                    bSuccess = false;
4906
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
4907
                }
4908

    
4909
                if (bSuccess)
4910
                    Console.WriteLine("OdReadExMgd Finished Successfully");
4911
            }
4912
        }
4913
    }
4914
}
클립보드 이미지 추가 (최대 크기: 500 MB)