프로젝트

일반

사용자정보

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

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ a930c61a

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

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

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

    
48
        public DbDumper() { }
49

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

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

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

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

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

    
128
            const int tabSize = 2;
129

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
302
                dumpEntityData(pText, indent, TextNode);
303

    
304
                node.AppendChild(TextNode);
305
            }
306

    
307
            return TextNode;
308
        }
309

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

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

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

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

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

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

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

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

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

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

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

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

    
372
            dumpEntityData(pAttDef, indent, AttributeDefinitionNode);
373

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

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

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

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

    
413
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
414
                ZAttr.Value = pBlkRef.Position.Z.ToString();
415
                BlockReferenceNode.Attributes.SetNamedItem(ZAttr);
416

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

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

    
425
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
426
                NormalAttr.Value = pBlkRef.Normal.ToString();
427
                BlockReferenceNode.Attributes.SetNamedItem(NormalAttr);
428

    
429
                XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
430
                NameAttr.Value = pBlkRef.Name;
431
                BlockReferenceNode.Attributes.SetNamedItem(NameAttr);
432

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

    
460
                XmlAttribute NodePointAttr = Program.xml.CreateAttribute("Nodes");
461
                NodePointAttr.Value = nodePointValue;
462
                BlockReferenceNode.Attributes.SetNamedItem(NodePointAttr);
463

    
464
                Matrix3d blockTransform = pBlkRef.BlockTransform;
465
                CoordinateSystem3d cs = blockTransform.CoordinateSystem3d;
466
                writeLine(indent + 1, "Origin", cs.Origin);
467
                writeLine(indent + 1, "u-Axis", cs.Xaxis);
468
                writeLine(indent + 1, "v-Axis", cs.Yaxis);
469
                writeLine(indent + 1, "z-Axis", cs.Zaxis);
470

    
471
                dumpEntityData(pBlkRef, indent, BlockReferenceNode);
472

    
473
                DBObjectCollection objColl = new DBObjectCollection();
474

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

    
488
                            DBObjectCollection objs = new DBObjectCollection();
489
                            mtext.Explode(objs);
490
                            foreach (var item in objs)
491
                            {
492
                                dumpTextData(item as DBText, indent, BlockReferenceNode);
493
                            }
494
                        }
495
                    }
496
                }
497

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

    
513
                    }
514
                }
515

    
516
                node.AppendChild(BlockReferenceNode);
517

    
518
                return BlockReferenceNode;
519
            }
520

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

    
542
                try
543
                {
544
                    writeLine(indent, "Area", pEntity.Area);
545
                }
546
                catch (System.Exception)
547
                {
548
                }
549
                dumpEntityData(pEntity, indent, node);
550
            }
551
        }
552

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
634
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
635
                NormalAttr.Value = pDim.Normal.ToString();
636
                DimDataNode.Attributes.SetNamedItem(NormalAttr);
637

    
638
                dumpEntityData(pDim, indent, node);
639

    
640
                return DimDataNode;
641
            }
642

    
643
            return null;
644
        }
645

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

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

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

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

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

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

    
675
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
676
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
677
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
678

    
679
                dumpDimData(pDim, indent, DimNode);
680

    
681
                return DimNode;
682
            }
683

    
684
            return null;
685
        }
686

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

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

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

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

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

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

    
716
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
717
                BulgeAttr.Value = pVertex.Bulge.ToString();
718
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
719

    
720
                if (pVertex.Bulge != 0)
721
                {
722
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
723
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
724
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
725
                }
726

    
727
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
728
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
729
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
730
                if (pVertex.TangentUsed)
731
                {
732
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
733
                    TangentAttr.Value = pVertex.Tangent.ToString();
734
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
735
                }
736

    
737
                node.AppendChild(VertexNode);
738

    
739
                return VertexNode;
740
            }
741

    
742
            return null;
743
        }
744

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

    
767
            if (node != null)
768
            {
769
                XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
770

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

    
775
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
776
                CountAttr.Value = Vertices.Count.ToString();
777
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
778

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

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

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

    
791
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
792
                ClosedAttr.Value = pPolyline.Closed.ToString();
793
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
794

    
795
                foreach (var vt in Vertices)
796
                {
797
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
798

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

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

    
807
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
808
                    ZAttr.Value = vt.Position.Z.ToString();
809
                    VertexNode.Attributes.SetNamedItem(ZAttr);
810

    
811
                    Polyline2dNode.AppendChild(VertexNode);
812
                }
813

    
814
                dumpCurveData(pPolyline, indent, node);
815

    
816
                node.AppendChild(Polyline2dNode);
817

    
818
                return Polyline2dNode;
819
            }
820

    
821
            return null;
822
        }
823

    
824

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

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

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

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

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

    
850
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
851
                ZAttr.Value = pVertex.Position.Z.ToString();
852
                VertexNode.Attributes.SetNamedItem(ZAttr);
853

    
854
                node.AppendChild(VertexNode);
855

    
856
                return VertexNode;
857
            }
858

    
859
            return null;
860
        }
861

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

    
871
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
872
                HandleAttr.Value = pPolyline.Handle.ToString();
873
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
874

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

    
891
                node.AppendChild(pPolylineNode);
892

    
893
                return pPolylineNode;
894
            }
895

    
896
            return null;
897
        }
898

    
899

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

    
909
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
910
                HandleAttr.Value = pSolid.Handle.ToString();
911
                SolidNode.Attributes.SetNamedItem(HandleAttr);
912

    
913
                dumpEntityData(pSolid, indent, node);
914

    
915
                node.AppendChild(SolidNode);
916

    
917
                return SolidNode;
918
            }
919

    
920
            return null;
921
        }
922

    
923

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

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

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

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

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

    
949
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
950
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
951
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
952

    
953
                dumpDimData(pDim, indent, DimNode);
954

    
955
                return DimNode;
956
            }
957

    
958
            return null;
959
        }
960

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

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

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

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

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

    
986
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
987
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
988
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
989

    
990
                dumpDimData(pDim, indent, DimNode);
991

    
992
                return DimNode;
993
            }
994

    
995
            return null;
996
        }
997

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

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

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

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

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

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

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

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

    
1035
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1036
                ThicknessAttr.Value = pArc.Normal.ToString();
1037
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
1038

    
1039
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
1040
                dumpCurveData(pArc, indent, ArcNode);
1041

    
1042
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1043
                {
1044
                    XAttr = Program.xml.CreateAttribute("X");
1045
                    XAttr.Value = pArc.StartPoint.X.ToString();
1046
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1047

    
1048
                    YAttr = Program.xml.CreateAttribute("Y");
1049
                    YAttr.Value = pArc.StartPoint.Y.ToString();
1050
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1051

    
1052
                    ZAttr = Program.xml.CreateAttribute("Z");
1053
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
1054
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1055
                }
1056
                ArcNode.AppendChild(StartPointNode);
1057

    
1058
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1059
                {
1060
                    XAttr = Program.xml.CreateAttribute("X");
1061
                    XAttr.Value = pArc.EndPoint.X.ToString();
1062
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1063

    
1064
                    YAttr = Program.xml.CreateAttribute("Y");
1065
                    YAttr.Value = pArc.EndPoint.Y.ToString();
1066
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1067

    
1068
                    ZAttr = Program.xml.CreateAttribute("Z");
1069
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1070
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1071
                }
1072
                ArcNode.AppendChild(EndPointNode);
1073

    
1074
                node.AppendChild(ArcNode);
1075

    
1076
                return ArcNode;
1077
            }
1078

    
1079
            return null;
1080
        }
1081

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

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

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

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

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

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

    
1111
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1112
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1113
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1114

    
1115
                if (pDim.HasLeader)
1116
                {
1117
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1118
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1119
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1120

    
1121
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1122
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1123
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1124
                }
1125

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

    
1130
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1131
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1132
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1133

    
1134
                dumpDimData(pDim, indent, DimNode);
1135

    
1136
                return DimNode;
1137
            }
1138

    
1139
            return null;
1140
        }
1141

    
1142

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

    
1160
        /************************************************************************/
1161
        /* Body Dumper                                                          */
1162
        /************************************************************************/
1163
        XmlNode dump(Body pBody, int indent, XmlNode node)
1164
        {
1165
            if (node != null)
1166
            {
1167
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1168

    
1169
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1170
                HandleAttr.Value = pBody.Handle.ToString();
1171
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1172

    
1173
                dumpEntityData(pBody, indent, BodyNode);
1174

    
1175
                return BodyNode;
1176
            }
1177

    
1178
            return null;
1179
        }
1180

    
1181

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

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

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

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

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

    
1207
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1208
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1209
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1210

    
1211
                dumpCurveData(pCircle, indent, CircleNode);
1212

    
1213
                node.AppendChild(CircleNode);
1214

    
1215
                return CircleNode;
1216
            }
1217

    
1218
            return null;
1219
        }
1220

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

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

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

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

    
1242
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1243
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1244
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1245

    
1246
                dumpDimData(pDim, indent, DimNode);
1247

    
1248
                return DimNode;
1249
            }
1250

    
1251
            return null;
1252
        }
1253

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

    
1263
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1264

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

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

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

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

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

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

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

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

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

    
1301
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1302
                NormalAttr.Value = pEllipse.Normal.ToString();
1303
                EllipseNode.Attributes.SetNamedItem(NormalAttr);
1304

    
1305
                dumpCurveData(pEllipse, indent, EllipseNode);
1306

    
1307
                node.AppendChild(EllipseNode);
1308
            }
1309
        }
1310

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

    
1320
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1321
                HandleAttr.Value = pFace.Handle.ToString();
1322
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1323

    
1324
                for (short i = 0; i < 4; i++)
1325
                {
1326
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1327

    
1328
                    Point3d pt = pFace.GetVertexAt(i);
1329
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1330
                    XAttr.Value = pt.X.ToString();
1331
                    VertexNode.Attributes.SetNamedItem(XAttr);
1332

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

    
1337
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1338
                    ZAttr.Value = pt.Z.ToString();
1339
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1340

    
1341
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1342
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1343
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1344

    
1345
                    FaceNode.AppendChild(VertexNode);
1346
                }
1347
                dumpEntityData(pFace, indent, FaceNode);
1348

    
1349
                node.AppendChild(FaceNode);
1350

    
1351
                return FaceNode;
1352
            }
1353

    
1354
            return null;
1355
        }
1356

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

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

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

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

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

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

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

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

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

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

    
1499
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1500
                retVal = retVal + " | kPolyline";
1501

    
1502
            if ((loopType & HatchLoopTypes.Derived) != 0)
1503
                retVal = retVal + " | kDerived";
1504

    
1505
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1506
                retVal = retVal + " | kTextbox";
1507

    
1508
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1509
                retVal = retVal + " | kOutermost";
1510

    
1511
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1512
                retVal = retVal + " | kNotClosed";
1513

    
1514
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1515
                retVal = retVal + " | kSelfIntersecting";
1516

    
1517
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1518
                retVal = retVal + " | kTextIsland";
1519

    
1520
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1521
                retVal = retVal + " | kDuplicate";
1522

    
1523
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1524
        }
1525

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

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

    
1611
            /********************************************************************/
1612
            /* Dump Loops                                                       */
1613
            /********************************************************************/
1614
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1615
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1616
            {
1617
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1618

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

    
1643
            writeLine(indent, "Elevation", pHatch.Elevation);
1644
            writeLine(indent, "Normal", pHatch.Normal);
1645
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1646
        }
1647

    
1648
        /************************************************************************/
1649
        /* Leader Dumper                                                          */
1650
        /************************************************************************/
1651
        void dump(Leader pLeader, int indent)
1652
        {
1653
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1654
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1655

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

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

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

    
1689
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1690
                HandleAttr.Value = pLine.Handle.ToString();
1691
                LineNode.Attributes.SetNamedItem(HandleAttr);
1692

    
1693
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1694
                {
1695
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1696
                    XAttr.Value = pLine.StartPoint.X.ToString();
1697
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1698

    
1699
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1700
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1701
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1702

    
1703
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1704
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1705
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1706
                }
1707
                LineNode.AppendChild(StartPointNode);
1708

    
1709
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1710
                {
1711
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1712
                    XAttr.Value = pLine.EndPoint.X.ToString();
1713
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1714

    
1715
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1716
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1717
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1718

    
1719
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1720
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1721
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1722
                }
1723
                LineNode.AppendChild(EndPointNode);
1724

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

    
1729
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1730
                ThicknessAttr.Value = pLine.Thickness.ToString();
1731
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1732

    
1733
                dumpEntityData(pLine, indent, LineNode);
1734

    
1735
                node.AppendChild(LineNode);
1736
            }
1737
            else
1738
            {
1739
                int d = 0;
1740
            }
1741
        }
1742

    
1743
        /************************************************************************/
1744
        /* MInsertBlock Dumper                                                  */
1745
        /************************************************************************/
1746
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1747
        {
1748
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1749

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

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

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

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

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

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

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

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

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

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

    
1833
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1834
                OriginAttr.Value = pDim.Origin.ToString();
1835
                DimNode.Attributes.SetNamedItem(OriginAttr);
1836

    
1837
                dumpDimData(pDim, indent, DimNode);
1838

    
1839
                return DimNode;
1840
            }
1841

    
1842
            return null;
1843
        }
1844

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

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

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

    
1862
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1863
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1864
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1865

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

    
1879
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1880

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

    
1885
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1886
                            PositionAttr.Value = pVertex.Position.ToString();
1887
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1888

    
1889
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1890

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

    
1906
                            face += "}";
1907

    
1908
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1909

    
1910
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1911
                            _HandleAttr.Value = pFace.Handle.ToString();
1912
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1913
                            FaceNode.InnerText = face;
1914

    
1915
                            dumpEntityData(pFace, indent + 1, FaceNode);
1916

    
1917
                            PolyNode.AppendChild(FaceNode);
1918
                        }
1919
                        else
1920
                        { // Unknown entity type
1921
                            writeLine(indent, "Unexpected Entity");
1922
                        }
1923
                    }
1924
                }
1925
                dumpEntityData(pPoly, indent, PolyNode);
1926

    
1927
                return PolyNode;
1928
            }
1929

    
1930
            return null;
1931
        }
1932

    
1933
        /************************************************************************/
1934
        /* Ole2Frame                                                            */
1935
        /************************************************************************/
1936
        void dump(Ole2Frame pOle, int indent)
1937
        {
1938
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1939

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

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

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

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

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

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

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

    
2031
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
2032
                    ClosedAttr.Value = pPoly.Closed.ToString();
2033
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
2034

    
2035
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
2036
                    {
2037
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
2038

    
2039
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
2040
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
2041

    
2042
                        Point3d pt = pPoly.GetPoint3dAt(i);
2043
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
2044
                        XAttr.Value = pt.X.ToString();
2045
                        VertexNode.Attributes.SetNamedItem(XAttr);
2046

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

    
2051
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
2052
                        ZAttr.Value = pt.Z.ToString();
2053
                        VertexNode.Attributes.SetNamedItem(ZAttr);
2054

    
2055
                        if (pPoly.HasWidth)
2056
                        {
2057
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
2058
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
2059
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
2060

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

    
2071
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2072
                            {
2073
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
2074
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2075
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2076
                            }
2077
                        }
2078

    
2079
                        PolylineNode.AppendChild(VertexNode);
2080
                    }
2081

    
2082
                    dumpEntityData(pPoly, indent, PolylineNode);
2083
                    node.AppendChild(PolylineNode);
2084
                }
2085
            }
2086
            else
2087
            {
2088
                int d = 0;
2089
            }
2090
        }
2091

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

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

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

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

    
2459
            public override void SetExtents(Extents3d extents)
2460
            {
2461
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2462
            }
2463
            public override void StartAttributesSegment()
2464
            {
2465
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2466
            }
2467
        }
2468

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

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

    
2558
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2559
                HandleAttr.Value = pEnt.Handle.ToString();
2560
                EntNode.Attributes.SetNamedItem(HandleAttr);
2561

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

    
2575
                node.AppendChild(EntNode);
2576

    
2577
                return EntNode;
2578
            }
2579

    
2580
            return null;
2581
        }
2582

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

    
2592
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2593
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2594
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2595

    
2596
                // this will dump proxy entity graphics
2597
                dump((Entity)pProxy, indent, node);
2598

    
2599
                DBObjectCollection collection = new DBObjectCollection(); ;
2600
                try
2601
                {
2602
                    pProxy.ExplodeGeometry(collection);
2603
                }
2604
                catch (System.Exception)
2605
                {
2606
                    return null;
2607
                }
2608

    
2609
                foreach (Entity ent in collection)
2610
                {
2611
                    if (ent is Polyline2d)
2612
                    {
2613
                        Polyline2d pline2d = (Polyline2d)ent;
2614
                        int i = 0;
2615

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

    
2634
                node.AppendChild(ProxyNode);
2635
                return ProxyNode;
2636
            }
2637

    
2638
            return null;
2639
        }
2640

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

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

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

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

    
2662
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
2663
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2664
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2665

    
2666
                dumpDimData(pDim, indent, DimNode);
2667

    
2668
                node.AppendChild(DimNode);
2669

    
2670
                return DimNode;
2671
            }
2672

    
2673
            return null;
2674
        }
2675

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

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

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

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

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

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

    
2766
        /************************************************************************/
2767
        /* Region Dumper                                                        */
2768
        /************************************************************************/
2769
        void dump(Region pRegion, int indent)
2770
        {
2771
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2772
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2773
        }
2774

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

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

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

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

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

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

    
2804
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2805
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2806
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2807

    
2808
                dumpDimData(pDim, indent, DimNode);
2809
                node.AppendChild(DimNode);
2810

    
2811
                return DimNode;
2812
            }
2813

    
2814
            return null;
2815
        }
2816

    
2817
        /************************************************************************/
2818
        /* Shape Dumper                                                          */
2819
        /************************************************************************/
2820
        void dump(Shape pShape, int indent)
2821
        {
2822
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2823

    
2824
            if (!pShape.StyleId.IsNull)
2825
            {
2826
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2827
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2828
            }
2829

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

    
2841
        /************************************************************************/
2842
        /* Solid Dumper                                                         */
2843
        /************************************************************************/
2844
        // TODO:
2845
        /*  void dump(Solid pSolid, int indent)
2846
      {
2847
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2848

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

    
2863
            NurbsData data = pSpline.NurbsData;
2864
            writeLine(indent, "Degree", data.Degree);
2865
            writeLine(indent, "Rational", data.Rational);
2866
            writeLine(indent, "Periodic", data.Periodic);
2867
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2868
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2869

    
2870
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2871
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2872
            {
2873
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2874
            }
2875

    
2876
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2877
            for (int i = 0; i < data.GetKnots().Count; i++)
2878
            {
2879
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2880
            }
2881

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

    
2906
            // TODO:
2907
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2908
            //writeLine(indent, "Table Style",               pStyle.Name);
2909
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2910
        }
2911

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

    
2929
            for (short i = 0; i < 4; i++)
2930
            {
2931
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2932
            }
2933
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2934
        }
2935

    
2936
        /************************************************************************/
2937
        /* Trace UnderlayReference                                                         */
2938
        /************************************************************************/
2939
        void dump(UnderlayReference pEnt, int indent)
2940
        {
2941
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2942
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2943
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2944
        }
2945

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

    
2955
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2956
                HandleAttr.Value = pVport.Handle.ToString();
2957
                VportNode.Attributes.SetNamedItem(HandleAttr);
2958

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

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

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

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

    
3011
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
3012
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
3013

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

    
3024
                writeLine(indent, "View Center", pVport.ViewCenter);
3025
                writeLine(indent, "View Height", pVport.ViewHeight);
3026
                writeLine(indent, "View Target", pVport.ViewTarget);
3027
                writeLine(indent, "Width", pVport.Width);
3028
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
3029

    
3030
                {
3031
                    using (DBObjectCollection collection = new DBObjectCollection())
3032
                    {
3033
                        try
3034
                        {
3035
                            pVport.ExplodeGeometry(collection);
3036

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

    
3060
                node.AppendChild(VportNode);
3061
                return VportNode;
3062
            }
3063

    
3064
            return null;
3065
        }
3066

    
3067
        /************************************************************************/
3068
        /* Wipeout Dumper                                                  */
3069
        /************************************************************************/
3070
        void dump(Wipeout pWipeout, int indent)
3071
        {
3072
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3073
            dumpRasterImageData(pWipeout, indent);
3074
        }
3075

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

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

    
3096
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
3097
                    LayoutNameAttr.Value = layoutName;
3098
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3099
                }
3100
            }
3101

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

    
3114
            dumpBlocks(pDb, indent, node);
3115
        }
3116

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

    
3126
            using (mPDFExportParams param = new mPDFExportParams())
3127
            {
3128
                param.Database = pDb;
3129

    
3130
                TransactionManager tm = pDb.TransactionManager;
3131
                using (Transaction ta = tm.StartTransaction())
3132
                {
3133
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3134
                    {
3135
                        param.OutputStream = fileStrem;
3136

    
3137
                        bool embededTTF = false;
3138
                        bool shxTextAsGeometry = true;
3139
                        bool ttfGeometry = true;
3140
                        bool simpleGeomOptimization = false;
3141
                        bool zoomToExtentsMode = true;
3142
                        bool enableLayers = false;
3143
                        bool includeOffLayers = false;
3144
                        bool enablePrcMode = true;
3145
                        bool monochrome = true;
3146
                        bool allLayout = false;
3147
                        double paperWidth = 841;
3148
                        double paperHeight = 594;
3149

    
3150
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3151
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3152
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3153
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3154
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3155
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3156
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3157

    
3158
                        param.Title = "";
3159
                        param.Author = "";
3160
                        param.Subject = "";
3161
                        param.Keywords = "";
3162
                        param.Creator = "";
3163
                        param.Producer = "";
3164
                        param.UseHLR = !enablePrcMode;
3165
                        param.FlateCompression = true;
3166
                        param.ASCIIHEXEncodeStream = true;
3167
                        param.hatchDPI = 720;
3168

    
3169
                        bool bV15 = enableLayers || includeOffLayers;
3170
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3171

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

    
3215
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3216

    
3217
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3218
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3219

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

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

    
3267
        /************************************************************************/
3268
        /* Export DWG to PNG                                                    */
3269
        /************************************************************************/
3270
        public void ExportPNG(Database pDb, string filePath)
3271
        {
3272
            chageColorAllObjects(pDb);
3273

    
3274
            string gdPath = "WinOpenGL_20.5_15.txv";
3275

    
3276
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3277
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3278
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3279
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3280

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

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

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

    
3310
                            if (ctx.IsPlotGeneration)
3311
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3312
                            else
3313
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3314

    
3315
                            helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3316
                            helperDevice.ActiveView.Zoom(0.99);
3317
                            helperDevice.Update();
3318

    
3319
                            Export_Import.ExportBitmap(helperDevice, bmpPath);
3320
                        }
3321
                    }
3322
                }
3323
            }
3324

    
3325
            if (File.Exists(bmpPath))
3326
            {
3327
                if (File.Exists(pngPath))
3328
                {
3329
                    File.Delete(pngPath);
3330
                }
3331

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

    
3349
                //        //create some image attributes
3350
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3351
                //        {
3352
                //            //set the color matrix attribute
3353
                //            attributes.SetColorMatrix(colorMatrix);
3354
                //            //attributes.SetThreshold(0.8F);
3355

    
3356
                //            //draw the original image on the new image
3357
                //            //using the grayscale color matrix
3358
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3359
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3360
                //        }
3361

    
3362
                //    }
3363
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3364
                //}
3365

    
3366
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3367
                {
3368
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3369
                }
3370
                if (File.Exists(bmpPath))
3371
                {
3372
                    File.Delete(bmpPath);
3373
                }
3374
            }
3375
        }
3376

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

    
3387
                foreach (ObjectId id in btrModelSpace)
3388
                {
3389
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3390
                    if (ent == null) continue;
3391

    
3392
                    ent.ColorIndex = 7;
3393

    
3394
                    if (ent is BlockReference)
3395
                    {
3396
                        changeColorBlocks(tr, (BlockReference)ent);
3397
                    }
3398
                }
3399

    
3400
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3401
                foreach (DBDictionaryEntry entry in dbdic)
3402
                {
3403
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3404
                    if (group == null) continue;
3405

    
3406
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3407
                    if (idarrTags == null) continue;
3408

    
3409
                    foreach (ObjectId id in idarrTags)
3410
                    {
3411
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3412
                        if (ent == null) continue;
3413

    
3414
                        ent.ColorIndex = 7;
3415
                    }
3416
                }
3417

    
3418
                foreach (ObjectId btrId in bt)
3419
                {
3420
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3421
                    if (btr == null) continue;
3422
                    if (btr.Name.StartsWith("*")) continue;
3423

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

    
3432
                tr.Commit();
3433
            }
3434
        }
3435

    
3436
        /************************************************************************/
3437
        /* Change the color of blocks                                           */
3438
        /************************************************************************/
3439
        private void changeColorBlocks(Transaction tr, BlockReference blkRef)
3440
        {
3441
            if (blkRef == null) return;
3442

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

    
3452
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3453
            if (btrBlock == null) return;
3454

    
3455
            foreach (ObjectId oid in btrBlock)
3456
            {
3457
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3458
                if (ent == null) continue;
3459

    
3460
                ent.ColorIndex = 7;
3461

    
3462
                if (ent is BlockReference)
3463
                {
3464
                    
3465
                    changeColorBlocks(tr, (BlockReference)ent);
3466
                }
3467
            }
3468
        }
3469

    
3470
        /************************************************************************/
3471
        /* Nested block Explode & Purge                                         */
3472
        /************************************************************************/
3473
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3474
        {
3475
            HashSet<string> blockNameList = new HashSet<string>();
3476
            // Explode ModelSpace Nested Block
3477
            blockNameList = explodeNestedBlocks(pDb);
3478

    
3479
            // Prepare Block Purge
3480
            preparePurgeBlocks(pDb, blockNameList);
3481

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

    
3494
            foreach (ObjectId oid in oids)
3495
            {
3496
                if (oid.IsErased) continue;
3497

    
3498
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3499
                {
3500
                    btr.Erase(true);
3501
                }                
3502
            }
3503
        }
3504

    
3505
        private HashSet<string> explodeNestedBlocks(Database pDb)
3506
        {
3507
            HashSet<string> blockNameList = new HashSet<string>();
3508
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3509

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

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

    
3555
            if (oidSet.Count > 0)
3556
            {
3557
                explodeBlocks(oidSet);
3558
                blockNameList = explodeNestedBlocks(pDb);
3559
            }
3560

    
3561
            return blockNameList;
3562
        }
3563

    
3564
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3565
        {
3566
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3567

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

    
3578
                        foreach (ObjectId entid in pBlock)
3579
                        {
3580
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3581
                            {
3582
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3583

    
3584
                                oidSet.Add(entid);
3585
                            }
3586
                        }
3587
                    }
3588
                }
3589
            }
3590

    
3591
            if (oidSet.Count > 0)
3592
            {
3593
                explodeBlocks(oidSet);
3594
                preparePurgeBlocks(pDb, blockNameList);
3595
            }
3596

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

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

    
3629
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3630
                                objIdCol.Add(blockRef.ObjectId);
3631
                                if (objIdCol.Count == 0) continue;
3632

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

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

    
3658
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3659
                                {
3660
                                    proc.StartInfo = procStartInfo;
3661
                                    proc.Start();
3662
                                    proc.StandardInput.Close();
3663
                                    proc.WaitForExit();
3664

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

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

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

    
3723
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3724
                        CommentsAttr.Value = pBlock.Comments;
3725
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3726

    
3727
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3728
                        OriginAttr.Value = pBlock.Origin.ToString();
3729
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3730

    
3731
                        writeLine(indent, pBlock.GetRXClass().Name);
3732
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3733
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3734
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3735
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3736
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3737

    
3738
                        try
3739
                        {
3740
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3741
                            extents.AddBlockExtents(pBlock);
3742

    
3743
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3744
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3745
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3746

    
3747
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3748
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3749
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3750
                        }
3751
                        catch (System.Exception)
3752
                        {
3753
                        }
3754

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

    
3766
                        /********************************************************************/
3767
                        /* Step through the BlockTableRecord                                */
3768
                        /********************************************************************/
3769
                        foreach (ObjectId entid in pBlock)
3770
                        {
3771
                            /********************************************************************/
3772
                            /* Dump the Entity                                                  */
3773
                            /********************************************************************/
3774
                            dumpEntity(entid, indent + 1, BlockNode);
3775
                        }
3776

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

    
3781
                node.AppendChild(BlocksNode);
3782
            }
3783
        }
3784

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

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

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

    
3889
                        dumpSymbolTableRecord(pRecord, indent, node);
3890
                    }
3891
                }
3892
            }
3893
        }
3894

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

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

    
4080
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
4081
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4082
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4083

    
4084
                writeLine();
4085
                writeLine(indent++, "Header Variables:");
4086

    
4087
                //writeLine();
4088
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4089
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4090

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

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

    
4260
                    /**********************************************************************/
4261
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4262
                    /**********************************************************************/
4263

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

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

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

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

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

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

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

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

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

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

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

    
4319
                            XmlAttribute ViewportVisibilityDefaultAttr = Program.xml.CreateAttribute("ViewportVisibilityDefault");
4320
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4321
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4322

    
4323
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4324
                            LayerNode.AppendChild(RecordNode);
4325
                        }
4326
                    }
4327

    
4328
                    node.AppendChild(LayerNode);
4329
                }
4330
            }
4331
        }
4332

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

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

    
4356
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4357
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4358
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4359

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

    
4364
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4365
                            CommentsAttr.Value = pRecord.Comments;
4366
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4367

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

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

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

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

    
4441
                    node.AppendChild(LinetypeNode);
4442
                }
4443
            }
4444
        }
4445

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

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

    
4480
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4481
        {
4482
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4483
            if (pRecord.IsDependent)
4484
            {
4485
                writeLine(indent, "Resolved", pRecord.IsResolved);
4486
            }
4487
        }
4488

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

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

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

    
4557
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4558
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4559

    
4560
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4561
            {
4562
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4563
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4564
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4565
            }
4566

    
4567
            writeLine(indent, "Target", pView.Target);
4568
            writeLine(indent, "View Direction", pView.ViewDirection);
4569
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4570
            dumpSymbolTableRecord(pView, indent, node);
4571
        }
4572
        public void dumpDimAssoc(DBObject pObject, int indent)
4573
        {
4574

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

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

    
4648
                /**********************************************************************/
4649
                /* Dispatch                                                           */
4650
                /**********************************************************************/
4651
                if (pObject is DBDictionary)
4652
                {
4653
                    /********************************************************************/
4654
                    /* Dump the dictionary                                               */
4655
                    /********************************************************************/
4656
                    DBDictionary pDic = (DBDictionary)pObject;
4657

    
4658
                    /********************************************************************/
4659
                    /* Get a pointer to a new DictionaryIterator                   */
4660
                    /********************************************************************/
4661
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4662

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

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

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

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

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

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

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

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

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

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

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

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

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

    
4941
                if (bSuccess)
4942
                    Console.WriteLine("OdReadExMgd Finished Successfully");
4943
            }
4944
        }
4945
    }
4946
}
클립보드 이미지 추가 (최대 크기: 500 MB)