프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ 5b85a67f

이력 | 보기 | 이력해설 | 다운로드 (253 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
                    if (pEnt.Bounds != null)
177
                    {
178
                        Extents3d ext = pEnt.GeometricExtents;
179

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

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

    
193
                XmlAttribute LayerAttr = Program.xml.CreateAttribute("Layer");
194
                LayerAttr.Value = pEnt.Layer;
195
                node.Attributes.SetNamedItem(LayerAttr);
196

    
197
                writeLine(indent, "Color Index", pEnt.ColorIndex);
198
                writeLine(indent, "Color", pEnt.Color);
199

    
200
                XmlAttribute LinetypeAttr = Program.xml.CreateAttribute("Linetype");
201
                LinetypeAttr.Value = pEnt.Linetype;
202
                node.Attributes.SetNamedItem(LinetypeAttr);
203

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

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

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

    
239
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
240
                XAttr.Value = pText.Position.X.ToString();
241
                TextNode.Attributes.SetNamedItem(XAttr);
242

    
243
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
244
                YAttr.Value = pText.Position.Y.ToString();
245
                TextNode.Attributes.SetNamedItem(YAttr);
246

    
247
                TextNode.InnerText = pText.TextString.Replace("%%U", "");
248

    
249
                XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
250
                AngleAttr.Value = pText.Rotation.ToString();
251
                TextNode.Attributes.SetNamedItem(AngleAttr);
252

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

    
257
                XmlAttribute HeightAttr = Program.xml.CreateAttribute("Height");
258
                HeightAttr.Value = pText.Height.ToString();
259
                TextNode.Attributes.SetNamedItem(HeightAttr);
260

    
261
                XmlAttribute WidthFactorAttr = Program.xml.CreateAttribute("WidthFactor");
262
                WidthFactorAttr.Value = pText.WidthFactor.ToString();
263
                TextNode.Attributes.SetNamedItem(WidthFactorAttr);
264

    
265
                XmlAttribute IsDefaultAlignmentAttr = Program.xml.CreateAttribute("IsDefaultAlignment");
266
                IsDefaultAlignmentAttr.Value = pText.IsDefaultAlignment.ToString();
267
                TextNode.Attributes.SetNamedItem(IsDefaultAlignmentAttr);
268

    
269
                XmlAttribute AlignmentPointAttr = Program.xml.CreateAttribute("AlignmentPoint");
270
                AlignmentPointAttr.Value = pText.AlignmentPoint.ToString();
271
                TextNode.Attributes.SetNamedItem(AlignmentPointAttr);
272

    
273
                XmlAttribute HorizontalModeAttr = Program.xml.CreateAttribute("HorizontalMode");
274
                HorizontalModeAttr.Value = pText.HorizontalMode.ToString();
275
                TextNode.Attributes.SetNamedItem(HorizontalModeAttr);
276

    
277
                XmlAttribute VerticalModeAttr = Program.xml.CreateAttribute("VerticalMode");
278
                VerticalModeAttr.Value = pText.VerticalMode.ToString();
279
                TextNode.Attributes.SetNamedItem(VerticalModeAttr);
280

    
281
                XmlAttribute IsMirroredInXAttr = Program.xml.CreateAttribute("IsMirroredInX");
282
                IsMirroredInXAttr.Value = pText.IsMirroredInX.ToString();
283
                TextNode.Attributes.SetNamedItem(IsMirroredInXAttr);
284

    
285
                XmlAttribute IsMirroredInYAttr = Program.xml.CreateAttribute("IsMirroredInY");
286
                IsMirroredInYAttr.Value = pText.IsMirroredInY.ToString();
287
                TextNode.Attributes.SetNamedItem(IsMirroredInYAttr);
288

    
289
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
290
                ObliqueAttr.Value = pText.Oblique.ToString();
291
                TextNode.Attributes.SetNamedItem(ObliqueAttr);
292

    
293
                XmlAttribute TextStyleAttr = Program.xml.CreateAttribute("TextStyle");
294
                TextStyleAttr.Value = pText.TextStyleName;
295
                TextNode.Attributes.SetNamedItem(TextStyleAttr);
296

    
297
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
298
                NormalAttr.Value = pText.Normal.ToString();
299
                TextNode.Attributes.SetNamedItem(NormalAttr);
300

    
301
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
302
                ThicknessAttr.Value = pText.Thickness.ToString();
303
                TextNode.Attributes.SetNamedItem(ThicknessAttr);
304

    
305
                dumpEntityData(pText, indent, TextNode);
306

    
307
                node.AppendChild(TextNode);
308
            }
309

    
310
            return TextNode;
311
        }
312

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

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

    
332
                XmlAttribute TagAttr = Program.xml.CreateAttribute("Tag");
333
                TagAttr.Value = pAttr.Tag;
334
                TextNode.Attributes.SetNamedItem(TagAttr);
335
            }
336
        }
337

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

    
345
            XmlNode AttributeDefinitionNode = Program.xml.CreateElement(pAttDef.GetRXClass().Name);
346

    
347
            XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
348
            HandleAttr.Value = pAttDef.Handle.ToString();
349
            AttributeDefinitionNode.Attributes.SetNamedItem(HandleAttr);
350

    
351
            XmlAttribute XAttr = Program.xml.CreateAttribute("X");
352
            XAttr.Value = pAttDef.Position.X.ToString();
353
            AttributeDefinitionNode.Attributes.SetNamedItem(XAttr);
354

    
355
            XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
356
            YAttr.Value = pAttDef.Position.Y.ToString();
357
            AttributeDefinitionNode.Attributes.SetNamedItem(YAttr);
358

    
359
            XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
360
            ZAttr.Value = pAttDef.Position.Z.ToString();
361
            AttributeDefinitionNode.Attributes.SetNamedItem(ZAttr);
362

    
363
            XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
364
            AngleAttr.Value = pAttDef.Rotation.ToString();
365
            AttributeDefinitionNode.Attributes.SetNamedItem(AngleAttr);
366

    
367
            XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
368
            NormalAttr.Value = pAttDef.Normal.ToString();
369
            AttributeDefinitionNode.Attributes.SetNamedItem(NormalAttr);
370

    
371
            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
372
            NameAttr.Value = pAttDef.Tag;
373
            AttributeDefinitionNode.Attributes.SetNamedItem(NameAttr);
374

    
375
            try
376
            {
377
                Extents3d ext = pAttDef.GeometricExtents;
378

    
379
                XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
380
                MinExtentsAttr.Value = ext.MinPoint.ToString();
381
                AttributeDefinitionNode.Attributes.SetNamedItem(MinExtentsAttr);
382

    
383
                XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
384
                MaxExtentsAttr.Value = ext.MaxPoint.ToString();
385
                AttributeDefinitionNode.Attributes.SetNamedItem(MaxExtentsAttr);
386
            }
387
            catch (System.Exception)
388
            {
389
            }
390

    
391
            dumpEntityData(pAttDef, indent, AttributeDefinitionNode);
392

    
393
            using (var text = new DBText())
394
            {
395
            
396
                text.SetPropertiesFrom(pAttDef);
397
                text.TextStyleId = pAttDef.TextStyleId;
398
                text.Position = pAttDef.Position;
399
                text.Rotation = pAttDef.Rotation;
400
                text.WidthFactor = pAttDef.WidthFactor;
401
                text.Height = pAttDef.Height;
402
                text.Thickness = pAttDef.Thickness;
403
                text.Justify = pAttDef.Justify;
404
                text.TextString = !string.IsNullOrWhiteSpace(pAttDef.TextString.Replace("*", "")) ? pAttDef.TextString : pAttDef.Tag;
405
                if (pAttDef.Justify != AttachmentPoint.BaseLeft)
406
                    text.AlignmentPoint = pAttDef.AlignmentPoint;
407
                dumpTextData(text, indent, AttributeDefinitionNode);
408
            }
409
            node.AppendChild(AttributeDefinitionNode);
410
        }
411
        /************************************************************************/
412
        /* Dump Block Reference Data                                             */
413
        /************************************************************************/
414
        static XmlNode dumpBlockRefData(BlockReference pBlkRef, int indent, XmlNode node)
415
        {
416
            if (node != null)
417
            {
418
                XmlNode BlockReferenceNode = Program.xml.CreateElement(pBlkRef.GetRXClass().Name);
419

    
420
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
421
                HandleAttr.Value = pBlkRef.Handle.ToString();
422
                BlockReferenceNode.Attributes.SetNamedItem(HandleAttr);
423

    
424
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
425
                XAttr.Value = pBlkRef.Position.X.ToString();
426
                BlockReferenceNode.Attributes.SetNamedItem(XAttr);
427

    
428
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
429
                YAttr.Value = pBlkRef.Position.Y.ToString();
430
                BlockReferenceNode.Attributes.SetNamedItem(YAttr);
431

    
432
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
433
                ZAttr.Value = pBlkRef.Position.Z.ToString();
434
                BlockReferenceNode.Attributes.SetNamedItem(ZAttr);
435

    
436
                XmlAttribute AngleAttr = Program.xml.CreateAttribute("Angle");
437
                AngleAttr.Value = pBlkRef.Rotation.ToString();
438
                BlockReferenceNode.Attributes.SetNamedItem(AngleAttr);
439

    
440
                XmlAttribute ScaleFactorsAttr = Program.xml.CreateAttribute("ScaleFactors");
441
                ScaleFactorsAttr.Value = pBlkRef.ScaleFactors.ToString();
442
                BlockReferenceNode.Attributes.SetNamedItem(ScaleFactorsAttr);
443

    
444
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
445
                NormalAttr.Value = pBlkRef.Normal.ToString();
446
                BlockReferenceNode.Attributes.SetNamedItem(NormalAttr);
447

    
448
                XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
449
                NameAttr.Value = pBlkRef.Name;
450
                BlockReferenceNode.Attributes.SetNamedItem(NameAttr);
451

    
452
                // BlockReference DBPoint
453
                string nodePointValue = string.Empty;
454
                Dictionary<long, Point3d> nodePointDic = new Dictionary<long, Point3d>();
455
                using (BlockTableRecord pBtr = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
456
                {
457
                    foreach (ObjectId blkid in pBtr)
458
                    {
459
                        using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
460
                        {
461
                            if (pBlkEnt.GetRXClass().Name == "AcDbPoint")
462
                            {
463
                                DBPoint pt = (DBPoint)pBlkEnt;
464
                                Point3d nodePt = pt.Position.TransformBy(pBlkRef.BlockTransform);
465
                                nodePointDic.Add(Convert.ToInt64(pt.Handle.ToString(), 16), nodePt);
466
                            }
467
                        }
468
                    }
469
                }
470
                if (nodePointDic.Count > 0)
471
                {
472
                    foreach (KeyValuePair<long, Point3d> item in nodePointDic.OrderBy(o => o.Key))
473
                    {
474
                        nodePointValue += item.Value.ToString() + "/";
475
                    }
476
                    nodePointValue = nodePointValue.Substring(0, nodePointValue.Length - 1);
477
                }
478

    
479
                XmlAttribute NodePointAttr = Program.xml.CreateAttribute("Nodes");
480
                NodePointAttr.Value = nodePointValue;
481
                BlockReferenceNode.Attributes.SetNamedItem(NodePointAttr);
482

    
483
                Matrix3d blockTransform = pBlkRef.BlockTransform;
484
                CoordinateSystem3d cs = blockTransform.CoordinateSystem3d;
485
                writeLine(indent + 1, "Origin", cs.Origin);
486
                writeLine(indent + 1, "u-Axis", cs.Xaxis);
487
                writeLine(indent + 1, "v-Axis", cs.Yaxis);
488
                writeLine(indent + 1, "z-Axis", cs.Zaxis);
489

    
490
                dumpEntityData(pBlkRef, indent, BlockReferenceNode);
491

    
492
                DBObjectCollection objColl = new DBObjectCollection();
493

    
494
                if (!pBlkRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC) && pBlkRef.Bounds != null)
495
                {
496
                    pBlkRef.Explode(objColl);
497
                    
498
                    foreach (var obj in objColl)
499
                    {
500
                        if (obj is DBText)
501
                        {
502
                            DBText text = obj as DBText;
503
                            if (!(text.TextString.Length == 36 && text.TextString.Replace("-","").Length == 32))
504
                            {
505
                                dumpTextData(text, indent, BlockReferenceNode);
506
                            }
507
                        }
508
                        else if (obj is MText)
509
                        {
510
                            MText mtext = obj as MText;
511
                            if (pBlkRef.BlockId == mtext.BlockId)
512
                            {
513
                                DBObjectCollection objs = new DBObjectCollection();
514
                                mtext.Explode(objs);
515
                                foreach (var item in objs)
516
                                {
517
                                    DBText subText = item as DBText;
518
                                    if (!(subText.TextString.Length == 36 && subText.TextString.Replace("-", "").Length == 32))
519
                                    {
520
                                        dumpTextData(subText, indent, BlockReferenceNode);
521
                                    }
522
                                }
523
                            }
524
                        }
525
                    }
526
                }
527

    
528
                /**********************************************************************/
529
                /* Dump the attributes                                                */
530
                /**********************************************************************/
531
                int i = 0;
532
                AttributeCollection attCol = pBlkRef.AttributeCollection;
533
                foreach (ObjectId id in attCol)
534
                {
535
                    try
536
                    {
537
                        using (AttributeReference pAttr = (AttributeReference)id.Open(OpenMode.ForRead))
538
                            dumpAttributeData(indent, pAttr, i++, BlockReferenceNode);
539
                    }
540
                    catch (System.Exception)
541
                    {
542
                    }
543
                }
544

    
545
                node.AppendChild(BlockReferenceNode);
546

    
547
                return BlockReferenceNode;
548
            }
549

    
550
            return null;
551
        }
552
        /************************************************************************/
553
        /* Dump data common to all OdDbCurves                                   */
554
        /************************************************************************/
555
        static void dumpCurveData(Entity pEnt, int indent, XmlNode node)
556
        {
557
            if (node != null)
558
            {
559
                Curve pEntity = (Curve)pEnt;
560
                try
561
                {
562
                    writeLine(indent, "Start Point", pEntity.StartPoint);
563
                    writeLine(indent, "End Point", pEntity.EndPoint);
564
                }
565
                catch (System.Exception)
566
                {
567
                }
568
                writeLine(indent, "Closed", pEntity.Closed);
569
                writeLine(indent, "Periodic", pEntity.IsPeriodic);
570

    
571
                try
572
                {
573
                    writeLine(indent, "Area", pEntity.Area);
574
                }
575
                catch (System.Exception)
576
                {
577
                }
578
                dumpEntityData(pEntity, indent, node);
579
            }
580
        }
581

    
582
        /************************************************************************/
583
        /* Dump Dimension data                                                  */
584
        /************************************************************************/
585
        static XmlNode dumpDimData(Dimension pDim, int indent, XmlNode node)
586
        {
587
            if (node != null)
588
            {
589
                XmlElement DimDataNode = Program.xml.CreateElement("DimData");
590

    
591
                XmlAttribute CurrentMeasurementAttr = Program.xml.CreateAttribute("CurrentMeasurement");
592
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
593
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
594

    
595
                XmlAttribute DimensionTextAttr = Program.xml.CreateAttribute("DimensionText");
596
                DimensionTextAttr.Value = pDim.DimensionText.ToString();
597
                DimDataNode.Attributes.SetNamedItem(DimensionTextAttr);
598

    
599
                if (pDim.CurrentMeasurement >= 0.0)
600
                {
601
                    XmlAttribute FormattedMeasurementAttr = Program.xml.CreateAttribute("FormattedMeasurement");
602
                    FormattedMeasurementAttr.Value = pDim.FormatMeasurement(pDim.CurrentMeasurement, pDim.DimensionText);
603
                    DimDataNode.Attributes.SetNamedItem(FormattedMeasurementAttr);
604
                }
605
                if (pDim.DimBlockId.IsNull)
606
                {
607
                    writeLine(indent, "Dimension Block NULL");
608
                }
609
                else
610
                {
611
                    using (BlockTableRecord btr = (BlockTableRecord)pDim.DimBlockId.Open(OpenMode.ForRead))
612
                    {
613
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
614
                        NameAttr.Value = btr.Name;
615
                        DimDataNode.Attributes.SetNamedItem(NameAttr);
616
                    }
617
                }
618

    
619
                XmlAttribute DimBlockPositionAttr = Program.xml.CreateAttribute("DimBlockPosition");
620
                DimBlockPositionAttr.Value = pDim.DimBlockPosition.ToString();
621
                DimDataNode.Attributes.SetNamedItem(DimBlockPositionAttr);
622

    
623
                XmlAttribute TextPositionAttr = Program.xml.CreateAttribute("TextPosition");
624
                TextPositionAttr.Value = pDim.TextPosition.ToString();
625
                DimDataNode.Attributes.SetNamedItem(TextPositionAttr);
626

    
627
                XmlAttribute TextRotationAttr = Program.xml.CreateAttribute("TextRotation");
628
                TextRotationAttr.Value = pDim.TextRotation.ToString();
629
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
630

    
631
                XmlAttribute DimensionStyleNameAttr = Program.xml.CreateAttribute("DimensionStyleName");
632
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
633
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
634

    
635
                XmlAttribute DimtfillclrAttr = Program.xml.CreateAttribute("Dimtfillclr");
636
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
637
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
638

    
639
                XmlAttribute DimtfillAttr = Program.xml.CreateAttribute("Dimtfill");
640
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
641
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
642

    
643
                XmlAttribute Dimltex1Attr = Program.xml.CreateAttribute("Dimltex1");
644
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
645
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
646

    
647
                XmlAttribute Dimltex2Attr = Program.xml.CreateAttribute("Dimltex2");
648
                Dimltex2Attr.Value = pDim.Dimltex2.ToString();
649
                DimDataNode.Attributes.SetNamedItem(Dimltex2Attr);
650

    
651
                XmlAttribute DimltypeAttr = Program.xml.CreateAttribute("Dimltype");
652
                DimltypeAttr.Value = pDim.Dimltype.ToString();
653
                DimDataNode.Attributes.SetNamedItem(DimltypeAttr);
654

    
655
                XmlAttribute HorizontalRotationAttr = Program.xml.CreateAttribute("HorizontalRotation");
656
                HorizontalRotationAttr.Value = pDim.HorizontalRotation.ToString();
657
                DimDataNode.Attributes.SetNamedItem(HorizontalRotationAttr);
658

    
659
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
660
                ElevationAttr.Value = pDim.Elevation.ToString();
661
                DimDataNode.Attributes.SetNamedItem(ElevationAttr);
662

    
663
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
664
                NormalAttr.Value = pDim.Normal.ToString();
665
                DimDataNode.Attributes.SetNamedItem(NormalAttr);
666

    
667
                dumpEntityData(pDim, indent, node);
668

    
669
                return DimDataNode;
670
            }
671

    
672
            return null;
673
        }
674

    
675
        /************************************************************************/
676
        /* 2 Line Angular Dimension Dumper                                      */
677
        /************************************************************************/
678
        static XmlNode dump(LineAngularDimension2 pDim, int indent, XmlNode node)
679
        {
680
            if (node != null)
681
            {
682
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
683

    
684
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
685
                HandleAttr.Value = pDim.Handle.ToString();
686
                DimNode.Attributes.SetNamedItem(HandleAttr);
687

    
688
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
689
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
690
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
691

    
692
                XmlAttribute XLine1StartAttr = Program.xml.CreateAttribute("XLine1Start");
693
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
694
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
695

    
696
                XmlAttribute XLine1EndAttr = Program.xml.CreateAttribute("XLine1End");
697
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
698
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
699

    
700
                XmlAttribute XLine2StartAttr = Program.xml.CreateAttribute("XLine2Start");
701
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
702
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
703

    
704
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
705
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
706
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
707

    
708
                dumpDimData(pDim, indent, DimNode);
709

    
710
                return DimNode;
711
            }
712

    
713
            return null;
714
        }
715

    
716
        /************************************************************************/
717
        /* Dump 2D Vertex data                                                  */
718
        /************************************************************************/
719
        static XmlNode dump2dVertex(int indent, Vertex2d pVertex, int i, XmlNode node)
720
        {
721
            if (node != null)
722
            {
723
                XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
724

    
725
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
726
                HandleAttr.Value = pVertex.Handle.ToString();
727
                VertexNode.Attributes.SetNamedItem(HandleAttr);
728

    
729
                XmlAttribute VertexTypeAttr = Program.xml.CreateAttribute("VertexType");
730
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
731
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
732

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

    
737
                XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
738
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
739
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
740

    
741
                XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
742
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
743
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
744

    
745
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
746
                BulgeAttr.Value = pVertex.Bulge.ToString();
747
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
748

    
749
                if (pVertex.Bulge != 0)
750
                {
751
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
752
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
753
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
754
                }
755

    
756
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
757
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
758
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
759
                if (pVertex.TangentUsed)
760
                {
761
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
762
                    TangentAttr.Value = pVertex.Tangent.ToString();
763
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
764
                }
765

    
766
                node.AppendChild(VertexNode);
767

    
768
                return VertexNode;
769
            }
770

    
771
            return null;
772
        }
773

    
774
        /************************************************************************/
775
        /* 2D Polyline Dumper                                                   */
776
        /************************************************************************/
777
        static XmlNode dump(Polyline2d pPolyline, int indent, XmlNode node)
778
        {
779
            /********************************************************************/
780
            /* Dump the vertices                                                */
781
            /********************************************************************/
782
            Point3dCollection points = new Point3dCollection();
783

    
784
            int count = (int)pPolyline.EndParam + (pPolyline.Closed ? 0 : 1);
785
            for (int i = 0; i < count; i++)
786
            {
787
                points.Add(pPolyline.GetPointAtParameter(i));
788
            }
789
            
790
            if (node != null)
791
            {
792
                //XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
793
                XmlNode Polyline2dNode = Program.xml.CreateElement("AcDbPolyline");
794

    
795
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
796
                HandleAttr.Value = pPolyline.Handle.ToString();
797
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
798

    
799
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
800
                CountAttr.Value = points.Count.ToString();
801
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
802

    
803
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
804
                ElevationAttr.Value = pPolyline.Elevation.ToString();
805
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
806

    
807
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
808
                NormalAttr.Value = pPolyline.Normal.ToString();
809
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
810

    
811
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
812
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
813
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
814

    
815
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
816
                ClosedAttr.Value = pPolyline.Closed.ToString();
817
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
818

    
819
                foreach (Point3d pt in points)
820
                {
821
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
822

    
823
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
824
                    XAttr.Value = pt.X.ToString();
825
                    VertexNode.Attributes.SetNamedItem(XAttr);
826

    
827
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
828
                    YAttr.Value = pt.Y.ToString();
829
                    VertexNode.Attributes.SetNamedItem(YAttr);
830

    
831
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
832
                    ZAttr.Value = pt.Z.ToString();
833
                    VertexNode.Attributes.SetNamedItem(ZAttr);
834

    
835
                    Polyline2dNode.AppendChild(VertexNode);
836
                }
837

    
838
                dumpCurveData(pPolyline, indent, Polyline2dNode);
839

    
840
                node.AppendChild(Polyline2dNode);
841

    
842
                return Polyline2dNode;
843
            }
844

    
845
            return null;
846
        }
847

    
848

    
849
        /************************************************************************/
850
        /* Dump 3D Polyline Vertex data                                         */
851
        /************************************************************************/
852
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
853
        {
854
            if (node != null)
855
            {
856
                XmlNode VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
857

    
858
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
859
                HandleAttr.Value = pVertex.Handle.ToString();
860
                VertexNode.Attributes.SetNamedItem(HandleAttr);
861

    
862
                XmlAttribute VertexxTypeAttr = Program.xml.CreateAttribute("VertexType");
863
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
864
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
865

    
866
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
867
                XAttr.Value = pVertex.Position.X.ToString();
868
                VertexNode.Attributes.SetNamedItem(XAttr);
869

    
870
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
871
                YAttr.Value = pVertex.Position.Y.ToString();
872
                VertexNode.Attributes.SetNamedItem(YAttr);
873

    
874
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
875
                ZAttr.Value = pVertex.Position.Z.ToString();
876
                VertexNode.Attributes.SetNamedItem(ZAttr);
877

    
878
                node.AppendChild(VertexNode);
879

    
880
                return VertexNode;
881
            }
882

    
883
            return null;
884
        }
885

    
886
        /************************************************************************/
887
        /* 3D Polyline Dumper                                                   */
888
        /************************************************************************/
889
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
890
        {
891
            if (node != null)
892
            {
893
                XmlNode pPolylineNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
894

    
895
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
896
                HandleAttr.Value = pPolyline.Handle.ToString();
897
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
898

    
899
                /********************************************************************/
900
                /* Dump the vertices                                                */
901
                /********************************************************************/
902
                int i = 0;
903
                foreach (ObjectId obj in pPolyline)
904
                {
905
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
906
                    {
907
                        if (dbObj is PolylineVertex3d)
908
                        {
909
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
910
                        }
911
                    }
912
                }
913
                dumpCurveData(pPolyline, indent, pPolylineNode);
914

    
915
                node.AppendChild(pPolylineNode);
916

    
917
                return pPolylineNode;
918
            }
919

    
920
            return null;
921
        }
922

    
923

    
924
        /************************************************************************/
925
        /* 3DSolid Dumper                                                       */
926
        /************************************************************************/
927
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
928
        {
929
            if (node != null)
930
            {
931
                XmlNode SolidNode = Program.xml.CreateElement(pSolid.GetRXClass().Name);
932

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

    
937
                dumpEntityData(pSolid, indent, node);
938

    
939
                node.AppendChild(SolidNode);
940

    
941
                return SolidNode;
942
            }
943

    
944
            return null;
945
        }
946

    
947

    
948
        /************************************************************************/
949
        /* 3 Point Angular Dimension Dumper                                     */
950
        /************************************************************************/
951
        XmlNode dump(Point3AngularDimension pDim, int indent, XmlNode node)
952
        {
953
            if (node != null)
954
            {
955
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
956

    
957
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
958
                HandleAttr.Value = pDim.Handle.ToString();
959
                DimNode.Attributes.SetNamedItem(HandleAttr);
960

    
961
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
962
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
963
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
964

    
965
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
966
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
967
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
968

    
969
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
970
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
971
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
972

    
973
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
974
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
975
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
976

    
977
                dumpDimData(pDim, indent, DimNode);
978

    
979
                return DimNode;
980
            }
981

    
982
            return null;
983
        }
984

    
985
        /************************************************************************/
986
        /* Aligned Dimension Dumper                                             */
987
        /************************************************************************/
988
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
989
        {
990
            if (node != null)
991
            {
992
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
993

    
994
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
995
                HandleAttr.Value = pDim.Handle.ToString();
996
                DimNode.Attributes.SetNamedItem(HandleAttr);
997

    
998
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
999
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
1000
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
1001

    
1002
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
1003
                ObliqueAttr.Value = pDim.Oblique.ToString();
1004
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
1005

    
1006
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1007
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1008
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1009

    
1010
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1011
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1012
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1013

    
1014
                dumpDimData(pDim, indent, DimNode);
1015

    
1016
                return DimNode;
1017
            }
1018

    
1019
            return null;
1020
        }
1021

    
1022
        /************************************************************************/
1023
        /* Arc Dumper                                                           */
1024
        /************************************************************************/
1025
        XmlNode dump(Arc pArc, int indent, XmlNode node)
1026
        {
1027
            if (node != null)
1028
            {
1029
                XmlElement ArcNode = Program.xml.CreateElement(pArc.GetRXClass().Name);
1030

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

    
1035
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1036
                YAttr.Value = pArc.Center.Y.ToString();
1037
                ArcNode.Attributes.SetNamedItem(YAttr);
1038

    
1039
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1040
                ZAttr.Value = pArc.Center.Z.ToString();
1041
                ArcNode.Attributes.SetNamedItem(ZAttr);
1042

    
1043
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1044
                RadiusAttr.Value = pArc.Radius.ToString();
1045
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
1046

    
1047
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1048
                StartAngleAttr.Value = pArc.StartAngle.ToString();
1049
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
1050

    
1051
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1052
                EndAngleAttr.Value = pArc.EndAngle.ToString();
1053
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
1054

    
1055
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1056
                NormalAttr.Value = pArc.Normal.ToString();
1057
                ArcNode.Attributes.SetNamedItem(NormalAttr);
1058

    
1059
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1060
                ThicknessAttr.Value = pArc.Normal.ToString();
1061
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
1062

    
1063
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
1064
                dumpCurveData(pArc, indent, ArcNode);
1065

    
1066
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1067
                {
1068
                    XAttr = Program.xml.CreateAttribute("X");
1069
                    XAttr.Value = pArc.StartPoint.X.ToString();
1070
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1071

    
1072
                    YAttr = Program.xml.CreateAttribute("Y");
1073
                    YAttr.Value = pArc.StartPoint.Y.ToString();
1074
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1075

    
1076
                    ZAttr = Program.xml.CreateAttribute("Z");
1077
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
1078
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1079
                }
1080
                ArcNode.AppendChild(StartPointNode);
1081

    
1082
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1083
                {
1084
                    XAttr = Program.xml.CreateAttribute("X");
1085
                    XAttr.Value = pArc.EndPoint.X.ToString();
1086
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1087

    
1088
                    YAttr = Program.xml.CreateAttribute("Y");
1089
                    YAttr.Value = pArc.EndPoint.Y.ToString();
1090
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1091

    
1092
                    ZAttr = Program.xml.CreateAttribute("Z");
1093
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1094
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1095
                }
1096
                ArcNode.AppendChild(EndPointNode);
1097

    
1098
                node.AppendChild(ArcNode);
1099

    
1100
                return ArcNode;
1101
            }
1102

    
1103
            return null;
1104
        }
1105

    
1106
        /************************************************************************/
1107
        /* Arc Dimension Dumper                                                 */
1108
        /************************************************************************/
1109
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
1110
        {
1111
            if (node != null)
1112
            {
1113
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1114

    
1115
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1116
                HandleAttr.Value = pDim.Handle.ToString();
1117
                DimNode.Attributes.SetNamedItem(HandleAttr);
1118

    
1119
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
1120
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
1121
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
1122

    
1123
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
1124
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
1125
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
1126

    
1127
                XmlAttribute ArcSymbolTypeAttr = Program.xml.CreateAttribute("ArcSymbolType");
1128
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1129
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1130

    
1131
                XmlAttribute IsPartialAttr = Program.xml.CreateAttribute("IsPartial");
1132
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1133
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1134

    
1135
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1136
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1137
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1138

    
1139
                if (pDim.HasLeader)
1140
                {
1141
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1142
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1143
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1144

    
1145
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1146
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1147
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1148
                }
1149

    
1150
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1151
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1152
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1153

    
1154
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1155
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1156
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1157

    
1158
                dumpDimData(pDim, indent, DimNode);
1159

    
1160
                return DimNode;
1161
            }
1162

    
1163
            return null;
1164
        }
1165

    
1166

    
1167
        /************************************************************************/
1168
        /* Block Reference Dumper                                                */
1169
        /************************************************************************/
1170
        void dump(BlockReference pBlkRef, int indent, XmlNode node)
1171
        {
1172
            using (BlockTableRecord pRecord = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead))
1173
            {
1174
                XmlNode BlockRefNode = dumpBlockRefData(pBlkRef, indent, node);
1175
                if (BlockRefNode != null)
1176
                {
1177
                    XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
1178
                    NameAttr.Value = pRecord.Name;
1179
                    BlockRefNode.Attributes.SetNamedItem(NameAttr);
1180
                }
1181
            }
1182
        }
1183

    
1184
        /************************************************************************/
1185
        /* Body Dumper                                                          */
1186
        /************************************************************************/
1187
        XmlNode dump(Body pBody, int indent, XmlNode node)
1188
        {
1189
            if (node != null)
1190
            {
1191
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1192

    
1193
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1194
                HandleAttr.Value = pBody.Handle.ToString();
1195
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1196

    
1197
                dumpEntityData(pBody, indent, BodyNode);
1198

    
1199
                return BodyNode;
1200
            }
1201

    
1202
            return null;
1203
        }
1204

    
1205

    
1206
        /************************************************************************/
1207
        /* Circle Dumper                                                        */
1208
        /************************************************************************/
1209
        XmlNode dump(Circle pCircle, int indent, XmlNode node)
1210
        {
1211
            if (node != null)
1212
            {
1213
                XmlElement CircleNode = Program.xml.CreateElement(pCircle.GetRXClass().Name);
1214

    
1215
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1216
                XAttr.Value = pCircle.Center.X.ToString();
1217
                CircleNode.Attributes.SetNamedItem(XAttr);
1218

    
1219
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1220
                YAttr.Value = pCircle.Center.Y.ToString();
1221
                CircleNode.Attributes.SetNamedItem(YAttr);
1222

    
1223
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1224
                RadiusAttr.Value = pCircle.Radius.ToString();
1225
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1226

    
1227
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1228
                NormalAttr.Value = pCircle.Normal.ToString();
1229
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1230

    
1231
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1232
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1233
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1234

    
1235
                dumpCurveData(pCircle, indent, CircleNode);
1236

    
1237
                node.AppendChild(CircleNode);
1238

    
1239
                return CircleNode;
1240
            }
1241

    
1242
            return null;
1243
        }
1244

    
1245
        /************************************************************************/
1246
        /* Diametric Dimension Dumper                                           */
1247
        /************************************************************************/
1248
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1249
        {
1250
            if (node != null)
1251
            {
1252
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1253

    
1254
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1255
                HandleAttr.Value = pDim.Handle.ToString();
1256
                DimNode.Attributes.SetNamedItem(HandleAttr);
1257

    
1258
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
1259
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1260
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1261

    
1262
                XmlAttribute FarChordPointAttr = Program.xml.CreateAttribute("FarChordPoint");
1263
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1264
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1265

    
1266
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1267
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1268
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1269

    
1270
                dumpDimData(pDim, indent, DimNode);
1271

    
1272
                return DimNode;
1273
            }
1274

    
1275
            return null;
1276
        }
1277

    
1278
        /************************************************************************/
1279
        /* Ellipse Dumper                                                       */
1280
        /************************************************************************/
1281
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1282
        {
1283
            if (node != null)
1284
            {
1285
                XmlElement EllipseNode = Program.xml.CreateElement(pEllipse.GetRXClass().Name);
1286

    
1287
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1288

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

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

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

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

    
1305
                XmlAttribute MajorRadiusAttr = Program.xml.CreateAttribute("MajorRadius");
1306
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1307
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1308

    
1309
                XmlAttribute MinorRadiusAttr = Program.xml.CreateAttribute("MinorRadius");
1310
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1311
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1312

    
1313
                XmlAttribute RadiusRatioAttr = Program.xml.CreateAttribute("RadiusRatio");
1314
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1315
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1316

    
1317
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1318
                StartAngleAttr.Value = pEllipse.StartAngle.ToString();
1319
                EllipseNode.Attributes.SetNamedItem(StartAngleAttr);
1320

    
1321
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1322
                EndAngleAttr.Value = pEllipse.EndAngle.ToString();
1323
                EllipseNode.Attributes.SetNamedItem(EndAngleAttr);
1324

    
1325
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1326
                NormalAttr.Value = pEllipse.Normal.ToString();
1327
                EllipseNode.Attributes.SetNamedItem(NormalAttr);
1328

    
1329
                dumpCurveData(pEllipse, indent, EllipseNode);
1330

    
1331
                node.AppendChild(EllipseNode);
1332
            }
1333
        }
1334

    
1335
        /************************************************************************/
1336
        /* Face Dumper                                                       */
1337
        /************************************************************************/
1338
        XmlNode dump(Face pFace, int indent, XmlNode node)
1339
        {
1340
            if (node != null)
1341
            {
1342
                XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1343

    
1344
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1345
                HandleAttr.Value = pFace.Handle.ToString();
1346
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1347

    
1348
                for (short i = 0; i < 4; i++)
1349
                {
1350
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1351

    
1352
                    Point3d pt = pFace.GetVertexAt(i);
1353
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1354
                    XAttr.Value = pt.X.ToString();
1355
                    VertexNode.Attributes.SetNamedItem(XAttr);
1356

    
1357
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1358
                    YAttr.Value = pt.Y.ToString();
1359
                    VertexNode.Attributes.SetNamedItem(YAttr);
1360

    
1361
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1362
                    ZAttr.Value = pt.Z.ToString();
1363
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1364

    
1365
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1366
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1367
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1368

    
1369
                    FaceNode.AppendChild(VertexNode);
1370
                }
1371
                dumpEntityData(pFace, indent, FaceNode);
1372

    
1373
                node.AppendChild(FaceNode);
1374

    
1375
                return FaceNode;
1376
            }
1377

    
1378
            return null;
1379
        }
1380

    
1381
        /************************************************************************/
1382
        /* FCF Dumper                                                           */
1383
        /************************************************************************/
1384
        void dump(FeatureControlFrame pFcf, int indent)
1385
        {
1386
            writeLine(indent++, pFcf.GetRXClass().Name, pFcf.Handle);
1387
            writeLine(indent, "Location", pFcf.Location);
1388
            writeLine(indent, "Text", pFcf.Text);
1389
            writeLine(indent, "Dimension Style", pFcf.DimensionStyleName);
1390
            writeLine(indent, "Dimension Gap", pFcf.Dimgap);
1391
            writeLine(indent, "Dimension Scale", pFcf.Dimscale);
1392
            writeLine(indent, "Text Height", pFcf.Dimtxt);
1393
            writeLine(indent, "Frame Color", pFcf.Dimclrd);
1394
            writeLine(indent, "Text Style", pFcf.TextStyleName);
1395
            writeLine(indent, "Text Color", pFcf.Dimclrd);
1396
            writeLine(indent, "X-Direction", pFcf.Direction);
1397
            writeLine(indent, "Normal", pFcf.Normal);
1398
            dumpEntityData(pFcf, indent, Program.xml.DocumentElement);
1399
        }
1400

    
1401
        /************************************************************************/
1402
        /* Hatch Dumper                                                         */
1403
        /************************************************************************/
1404
        /***********************************************************************/
1405
        /* Dump Polyline Loop                                                  */
1406
        /***********************************************************************/
1407
        static void dumpPolylineType(int loopIndex, Hatch pHatch, int indent)
1408
        {
1409
            HatchLoop hl = pHatch.GetLoopAt(loopIndex);
1410
            for (int i = 0; i < hl.Polyline.Count; i++)
1411
            {
1412
                BulgeVertex bv = hl.Polyline[i];
1413
                writeLine(indent, "Vertex " + i.ToString(), bv.Vertex.ToString());
1414
                writeLine(indent + 1, "Bulge " + i.ToString(), bv.Bulge);
1415
                writeLine(indent + 1, "Bulge angle " + i.ToString(), toDegreeString(4 * Math.Atan(bv.Bulge)));
1416
            }
1417
        }
1418

    
1419
        /**********************************************************************/
1420
        /* Dump Circular Arc Edge                                             */
1421
        /**********************************************************************/
1422
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1423
        {
1424
            writeLine(indent, "Center", pCircArc.Center);
1425
            writeLine(indent, "Radius", pCircArc.Radius);
1426
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1427
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1428
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1429
        }
1430

    
1431
        /**********************************************************************/
1432
        /* Dump Elliptical Arc Edge                                           */
1433
        /**********************************************************************/
1434
        static void dumpEllipticalArcEdge(int indent, EllipticalArc2d pEllipArc)
1435
        {
1436
            writeLine(indent, "Center", pEllipArc.Center);
1437
            writeLine(indent, "Major Radius", pEllipArc.MajorRadius);
1438
            writeLine(indent, "Minor Radius", pEllipArc.MinorRadius);
1439
            writeLine(indent, "Major Axis", pEllipArc.MajorAxis);
1440
            writeLine(indent, "Minor Axis", pEllipArc.MinorAxis);
1441
            writeLine(indent, "Start Angle", toDegreeString(pEllipArc.StartAngle));
1442
            writeLine(indent, "End Angle", toDegreeString(pEllipArc.EndAngle));
1443
            writeLine(indent, "Clockwise", pEllipArc.IsClockWise);
1444
        }
1445

    
1446
        /**********************************************************************/
1447
        /* Dump NurbCurve Edge                                           */
1448
        /**********************************************************************/
1449
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1450
        {
1451
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1452
            writeLine(indent, "Degree", d.Degree);
1453
            writeLine(indent, "Rational", d.Rational);
1454
            writeLine(indent, "Periodic", d.Periodic);
1455

    
1456
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1457
            for (int i = 0; i < d.ControlPoints.Count; i++)
1458
            {
1459
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1460
            }
1461
            writeLine(indent, "Number of Knots", d.Knots.Count);
1462
            for (int i = 0; i < d.Knots.Count; i++)
1463
            {
1464
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1465
            }
1466

    
1467
            if (d.Rational)
1468
            {
1469
                writeLine(indent, "Number of Weights", d.Weights.Count);
1470
                for (int i = 0; i < d.Weights.Count; i++)
1471
                {
1472
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1473
                }
1474
            }
1475
        }
1476

    
1477
        /***********************************************************************/
1478
        /* Dump Edge Loop                                                      */
1479
        /***********************************************************************/
1480
        static void dumpEdgesType(int loopIndex, Hatch pHatch, int indent)
1481
        {
1482
            Curve2dCollection edges = pHatch.GetLoopAt(loopIndex).Curves;
1483
            for (int i = 0; i < (int)edges.Count; i++)
1484
            {
1485
                using (Curve2d pEdge = edges[i])
1486
                {
1487
                    writeLine(indent, string.Format("Edge {0}", i), pEdge.GetType().Name);
1488
                    switch (pEdge.GetType().Name)
1489
                    {
1490
                        case "LineSegment2d":
1491
                            break;
1492
                        case "CircularArc2d":
1493
                            dumpCircularArcEdge(indent + 1, (CircularArc2d)pEdge);
1494
                            break;
1495
                        case "EllipticalArc2d":
1496
                            dumpEllipticalArcEdge(indent + 1, (EllipticalArc2d)pEdge);
1497
                            break;
1498
                        case "NurbCurve2d":
1499
                            dumpNurbCurveEdge(indent + 1, (NurbCurve2d)pEdge);
1500
                            break;
1501
                    }
1502

    
1503
                    /******************************************************************/
1504
                    /* Common Edge Properties                                         */
1505
                    /******************************************************************/
1506
                    Interval interval = pEdge.GetInterval();
1507
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1508
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1509
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1510
                }
1511
            }
1512
        }
1513

    
1514
        /************************************************************************/
1515
        /* Convert the specified value to a LoopType string                     */
1516
        /************************************************************************/
1517
        string toLooptypeString(HatchLoopTypes loopType)
1518
        {
1519
            string retVal = "";
1520
            if ((loopType & HatchLoopTypes.External) != 0)
1521
                retVal = retVal + " | kExternal";
1522

    
1523
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1524
                retVal = retVal + " | kPolyline";
1525

    
1526
            if ((loopType & HatchLoopTypes.Derived) != 0)
1527
                retVal = retVal + " | kDerived";
1528

    
1529
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1530
                retVal = retVal + " | kTextbox";
1531

    
1532
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1533
                retVal = retVal + " | kOutermost";
1534

    
1535
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1536
                retVal = retVal + " | kNotClosed";
1537

    
1538
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1539
                retVal = retVal + " | kSelfIntersecting";
1540

    
1541
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1542
                retVal = retVal + " | kTextIsland";
1543

    
1544
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1545
                retVal = retVal + " | kDuplicate";
1546

    
1547
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1548
        }
1549

    
1550
        void dump(Hatch pHatch, int indent)
1551
        {
1552
            writeLine(indent++, pHatch.GetRXClass().Name, pHatch.Handle);
1553
            writeLine(indent, "Hatch Style", pHatch.HatchStyle);
1554
            writeLine(indent, "Hatch Object Type", pHatch.HatchObjectType);
1555
            writeLine(indent, "Is Hatch", pHatch.IsHatch);
1556
            writeLine(indent, "Is Gradient", !pHatch.IsGradient);
1557
            if (pHatch.IsHatch)
1558
            {
1559
                /******************************************************************/
1560
                /* Dump Hatch Parameters                                          */
1561
                /******************************************************************/
1562
                writeLine(indent, "Pattern Type", pHatch.PatternType);
1563
                switch (pHatch.PatternType)
1564
                {
1565
                    case HatchPatternType.PreDefined:
1566
                    case HatchPatternType.CustomDefined:
1567
                        writeLine(indent, "Pattern Name", pHatch.PatternName);
1568
                        writeLine(indent, "Solid Fill", pHatch.IsSolidFill);
1569
                        if (!pHatch.IsSolidFill)
1570
                        {
1571
                            writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1572
                            writeLine(indent, "Pattern Scale", pHatch.PatternScale);
1573
                        }
1574
                        break;
1575
                    case HatchPatternType.UserDefined:
1576
                        writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1577
                        writeLine(indent, "Pattern Double", pHatch.PatternDouble);
1578
                        writeLine(indent, "Pattern Space", pHatch.PatternSpace);
1579
                        break;
1580
                }
1581
                DBObjectCollection entitySet = new DBObjectCollection();
1582
                Handle hhh = pHatch.Handle;
1583
                if (hhh.Value == 1692) //69C)
1584
                {
1585
                    pHatch.Explode(entitySet);
1586
                    return;
1587
                }
1588
                if (hhh.Value == 1693) //69D)
1589
                {
1590
                    try
1591
                    {
1592
                        pHatch.Explode(entitySet);
1593
                    }
1594
                    catch (System.Exception e)
1595
                    {
1596
                        if (e.Message == "eCannotExplodeEntity")
1597
                        {
1598
                            writeLine(indent, "Hatch " + e.Message + ": ", pHatch.Handle);
1599
                            return;
1600
                        }
1601
                    }
1602
                }
1603
            }
1604
            if (pHatch.IsGradient)
1605
            {
1606
                /******************************************************************/
1607
                /* Dump Gradient Parameters                                       */
1608
                /******************************************************************/
1609
                writeLine(indent, "Gradient Type", pHatch.GradientType);
1610
                writeLine(indent, "Gradient Name", pHatch.GradientName);
1611
                writeLine(indent, "Gradient Angle", toDegreeString(pHatch.GradientAngle));
1612
                writeLine(indent, "Gradient Shift", pHatch.GradientShift);
1613
                writeLine(indent, "Gradient One-Color Mode", pHatch.GradientOneColorMode);
1614
                if (pHatch.GradientOneColorMode)
1615
                {
1616
                    writeLine(indent, "ShadeTintValue", pHatch.ShadeTintValue);
1617
                }
1618
                GradientColor[] colors = pHatch.GetGradientColors();
1619
                for (int i = 0; i < colors.Length; i++)
1620
                {
1621
                    writeLine(indent, string.Format("Color         {0}", i), colors[i].get_Color());
1622
                    writeLine(indent, string.Format("Interpolation {0}", i), colors[i].get_Value());
1623
                }
1624
            }
1625

    
1626
            /********************************************************************/
1627
            /* Dump Associated Objects                                          */
1628
            /********************************************************************/
1629
            writeLine(indent, "Associated objects", pHatch.Associative);
1630
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1631
            {
1632
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1633
            }
1634

    
1635
            /********************************************************************/
1636
            /* Dump Loops                                                       */
1637
            /********************************************************************/
1638
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1639
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1640
            {
1641
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1642

    
1643
                /******************************************************************/
1644
                /* Dump Loop                                                      */
1645
                /******************************************************************/
1646
                if ((pHatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) != 0)
1647
                {
1648
                    dumpPolylineType(i, pHatch, indent + 2);
1649
                }
1650
                else
1651
                {
1652
                    dumpEdgesType(i, pHatch, indent + 2);
1653
                }
1654
                /******************************************************************/
1655
                /* Dump Associated Objects                                        */
1656
                /******************************************************************/
1657
                if (pHatch.Associative)
1658
                {
1659
                    writeLine(indent + 2, "Associated objects");
1660
                    foreach (ObjectId id in pHatch.GetAssociatedObjectIdsAt(i))
1661
                    {
1662
                        writeLine(indent + 3, id.ObjectClass.Name, id.Handle);
1663
                    }
1664
                }
1665
            }
1666

    
1667
            writeLine(indent, "Elevation", pHatch.Elevation);
1668
            writeLine(indent, "Normal", pHatch.Normal);
1669
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1670
        }
1671

    
1672
        /************************************************************************/
1673
        /* Leader Dumper                                                          */
1674
        /************************************************************************/
1675
        void dump(Leader pLeader, int indent)
1676
        {
1677
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1678
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1679

    
1680
            writeLine(indent, "Annotation");
1681
            if (!pLeader.Annotation.IsNull)
1682
            {
1683
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1684
            }
1685
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1686
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1687
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1688
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1689
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1690
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1691
            writeLine(indent, "Splined", pLeader.IsSplined);
1692

    
1693
            for (int i = 0; i < pLeader.NumVertices; i++)
1694
            {
1695
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1696
            }
1697
            writeLine(indent, "Normal", pLeader.Normal);
1698
            dumpCurveData(pLeader, indent, Program.xml.DocumentElement);
1699
        }
1700

    
1701
        /************************************************************************/
1702
        /* Line Dumper                                                          */
1703
        /************************************************************************/
1704
        void dump(Line pLine, int indent, XmlNode node)
1705
        {
1706
            if (node != null && pLine != null && pLine.Length != 0)
1707
            {
1708
                XmlNode LineNode = Program.xml.CreateElement(pLine.GetRXClass().Name);
1709
                XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1710
                LengthAttr.Value = pLine.Length.ToString();
1711
                LineNode.Attributes.SetNamedItem(LengthAttr);
1712

    
1713
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1714
                HandleAttr.Value = pLine.Handle.ToString();
1715
                LineNode.Attributes.SetNamedItem(HandleAttr);
1716

    
1717
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1718
                {
1719
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1720
                    XAttr.Value = pLine.StartPoint.X.ToString();
1721
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1722

    
1723
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1724
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1725
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1726

    
1727
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1728
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1729
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1730
                }
1731
                LineNode.AppendChild(StartPointNode);
1732

    
1733
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1734
                {
1735
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1736
                    XAttr.Value = pLine.EndPoint.X.ToString();
1737
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1738

    
1739
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1740
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1741
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1742

    
1743
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1744
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1745
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1746
                }
1747
                LineNode.AppendChild(EndPointNode);
1748

    
1749
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1750
                NormalAttr.Value = pLine.Normal.ToString();
1751
                LineNode.Attributes.SetNamedItem(NormalAttr);
1752

    
1753
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1754
                ThicknessAttr.Value = pLine.Thickness.ToString();
1755
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1756

    
1757
                dumpEntityData(pLine, indent, LineNode);
1758

    
1759
                node.AppendChild(LineNode);
1760
            }
1761
            else
1762
            {
1763
                int d = 0;
1764
            }
1765
        }
1766

    
1767
        /************************************************************************/
1768
        /* MInsertBlock Dumper                                                  */
1769
        /************************************************************************/
1770
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1771
        {
1772
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1773

    
1774
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1775
            {
1776
                writeLine(indent, "Name", pRecord.Name);
1777
                writeLine(indent, "Rows", pMInsert.Rows);
1778
                writeLine(indent, "Columns", pMInsert.Columns);
1779
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1780
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1781
                dumpBlockRefData(pMInsert, indent, node);
1782
            }
1783
        }
1784

    
1785
        /************************************************************************/
1786
        /* Mline Dumper                                                         */
1787
        /************************************************************************/
1788
        void dump(Mline pMline, int indent)
1789
        {
1790
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1791
            writeLine(indent, "Style", pMline.Style);
1792
            writeLine(indent, "Closed", pMline.IsClosed);
1793
            writeLine(indent, "Scale", pMline.Scale);
1794
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1795
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1796
            writeLine(indent, "Normal", pMline.Normal);
1797

    
1798
            /********************************************************************/
1799
            /* Dump the segment data                                            */
1800
            /********************************************************************/
1801
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1802
            {
1803
                writeLine(indent, "Segment", i);
1804
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1805
            }
1806
            dumpEntityData(pMline, indent, Program.xml.DocumentElement);
1807
        }
1808

    
1809
        /************************************************************************/
1810
        /* MText Dumper                                                         */
1811
        /************************************************************************/
1812
        /// <summary>
1813
        /// convert MText to normal Text
1814
        /// </summary>
1815
        /// <param name="pMText"></param>
1816
        /// <param name="indent"></param>
1817
        /// <param name="node"></param>
1818
        void dump(MText pMText, int indent, XmlNode node)
1819
        {
1820
            DBObjectCollection objColl = new DBObjectCollection();
1821
            pMText.Explode(objColl);
1822
            foreach (var obj in objColl)
1823
            {
1824
                dumpTextData(obj as DBText, indent, node);
1825
            }
1826
        }
1827

    
1828
        /************************************************************************/
1829
        /* Ordinate Dimension Dumper                                            */
1830
        /************************************************************************/
1831
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1832
        {
1833
            if (node != null)
1834
            {
1835
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1836

    
1837
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1838
                HandleAttr.Value = pDim.Handle.ToString();
1839
                DimNode.Attributes.SetNamedItem(HandleAttr);
1840

    
1841
                XmlAttribute DefiningPointAttr = Program.xml.CreateAttribute("DefiningPoint");
1842
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1843
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1844

    
1845
                XmlAttribute UsingXAxisAttr = Program.xml.CreateAttribute("UsingXAxis");
1846
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1847
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1848

    
1849
                XmlAttribute UsingYAxisAttr = Program.xml.CreateAttribute("UsingYAxis");
1850
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1851
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1852

    
1853
                XmlAttribute LeaderEndPointAttr = Program.xml.CreateAttribute("LeaderEndPoint");
1854
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1855
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1856

    
1857
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1858
                OriginAttr.Value = pDim.Origin.ToString();
1859
                DimNode.Attributes.SetNamedItem(OriginAttr);
1860

    
1861
                dumpDimData(pDim, indent, DimNode);
1862

    
1863
                return DimNode;
1864
            }
1865

    
1866
            return null;
1867
        }
1868

    
1869
        /************************************************************************/
1870
        /* PolyFaceMesh Dumper                                                  */
1871
        /************************************************************************/
1872
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1873
        {
1874
            if (node != null)
1875
            {
1876
                XmlElement PolyNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1877

    
1878
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1879
                HandleAttr.Value = pPoly.Handle.ToString();
1880
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1881

    
1882
                XmlAttribute NumVerticesAttr = Program.xml.CreateAttribute("NumVertices");
1883
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1884
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1885

    
1886
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1887
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1888
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1889

    
1890
                /********************************************************************/
1891
                /* dump vertices and faces                                          */
1892
                /********************************************************************/
1893
                int vertexCount = 0;
1894
                int faceCount = 0;
1895
                foreach (ObjectId objId in pPoly)
1896
                {
1897
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1898
                    {
1899
                        if (ent is PolyFaceMeshVertex)
1900
                        {
1901
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1902

    
1903
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1904

    
1905
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1906
                            _HandleAttr.Value = pVertex.Handle.ToString();
1907
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1908

    
1909
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1910
                            PositionAttr.Value = pVertex.Position.ToString();
1911
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1912

    
1913
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1914

    
1915
                            PolyNode.AppendChild(VertexNode);
1916
                        }
1917
                        else if (ent is FaceRecord)
1918
                        {
1919
                            FaceRecord pFace = (FaceRecord)ent;
1920
                            string face = "{";
1921
                            for (short i = 0; i < 4; i++)
1922
                            {
1923
                                if (i > 0)
1924
                                {
1925
                                    face = face + " ";
1926
                                }
1927
                                face = face + pFace.GetVertexAt(i).ToString();
1928
                            }
1929

    
1930
                            face += "}";
1931

    
1932
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1933

    
1934
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1935
                            _HandleAttr.Value = pFace.Handle.ToString();
1936
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1937
                            FaceNode.InnerText = face;
1938

    
1939
                            dumpEntityData(pFace, indent + 1, FaceNode);
1940

    
1941
                            PolyNode.AppendChild(FaceNode);
1942
                        }
1943
                        else
1944
                        { // Unknown entity type
1945
                            writeLine(indent, "Unexpected Entity");
1946
                        }
1947
                    }
1948
                }
1949
                dumpEntityData(pPoly, indent, PolyNode);
1950

    
1951
                return PolyNode;
1952
            }
1953

    
1954
            return null;
1955
        }
1956

    
1957
        /************************************************************************/
1958
        /* Ole2Frame                                                            */
1959
        /************************************************************************/
1960
        void dump(Ole2Frame pOle, int indent)
1961
        {
1962
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1963

    
1964
            Rectangle3d pos = (Rectangle3d)pOle.Position3d;
1965
            writeLine(indent, "Lower Left", pos.LowerLeft);
1966
            writeLine(indent, "Lower Right", pos.LowerRight);
1967
            writeLine(indent, "Upper Left", pos.UpperLeft);
1968
            writeLine(indent, "Upper Right", pos.UpperRight);
1969
            writeLine(indent, "Type", pOle.Type);
1970
            writeLine(indent, "User Type", pOle.UserType);
1971
            if (pOle.Type == Ole2Frame.ItemType.Link)
1972
            {
1973
                writeLine(indent, "Link Name", pOle.LinkName);
1974
                writeLine(indent, "Link Path", pOle.LinkPath);
1975
            }
1976
            writeLine(indent, "Output Quality", pOle.OutputQuality);
1977
            dumpEntityData(pOle, indent, Program.xml.DocumentElement);
1978
        }
1979

    
1980
        /************************************************************************/
1981
        /* Point Dumper                                                         */
1982
        /************************************************************************/
1983
        void dump(DBPoint pPoint, int indent)
1984
        {
1985
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1986
            writeLine(indent, "Position", pPoint.Position);
1987
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1988
            writeLine(indent, "Normal", pPoint.Normal);
1989
            writeLine(indent, "Thickness", pPoint.Thickness);
1990
            dumpEntityData(pPoint, indent, Program.xml.DocumentElement);
1991
        }
1992

    
1993
        /************************************************************************/
1994
        /* Polygon Mesh Dumper                                                  */
1995
        /************************************************************************/
1996
        void dump(PolygonMesh pPoly, int indent)
1997
        {
1998
            writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1999
            writeLine(indent, "m Size", pPoly.MSize);
2000
            writeLine(indent, "m-Closed", pPoly.IsMClosed);
2001
            writeLine(indent, "m Surface Density", pPoly.MSurfaceDensity);
2002
            writeLine(indent, "n Size", pPoly.NSize);
2003
            writeLine(indent, "n-Closed", pPoly.IsNClosed);
2004
            writeLine(indent, "n Surface Density", pPoly.NSurfaceDensity);
2005
            /********************************************************************/
2006
            /* dump vertices                                                    */
2007
            /********************************************************************/
2008
            int vertexCount = 0;
2009
            foreach (object o in pPoly)
2010
            {
2011
                PolygonMeshVertex pVertex = o as PolygonMeshVertex;
2012
                if (pVertex != null)
2013
                {
2014
                    writeLine(indent, pVertex.GetRXClass().Name, vertexCount++);
2015
                    writeLine(indent + 1, "Handle", pVertex.Handle);
2016
                    writeLine(indent + 1, "Position", pVertex.Position);
2017
                    writeLine(indent + 1, "Type", pVertex.VertexType);
2018
                }
2019
            }
2020
            dumpEntityData(pPoly, indent, Program.xml.DocumentElement);
2021
        }
2022

    
2023
        /************************************************************************/
2024
        /* Polyline Dumper                                                      */
2025
        /************************************************************************/
2026
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
2027
        {
2028
            if (pPoly != null && pPoly.Length != 0)
2029
            {
2030
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
2031
                writeLine(indent, "Has Width", pPoly.HasWidth);
2032
                if (!pPoly.HasWidth)
2033
                {
2034
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
2035
                }
2036

    
2037
                /********************************************************************/
2038
                /* dump vertices                                                    */
2039
                /********************************************************************/
2040
                if (node != null)
2041
                {
2042
                    XmlNode PolylineNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
2043
                    XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
2044
                    LengthAttr.Value = pPoly.Length.ToString();
2045
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
2046

    
2047
                    XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
2048
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
2049
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
2050

    
2051
                    XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2052
                    HandleAttr.Value = pPoly.Handle.ToString();
2053
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
2054

    
2055
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
2056
                    ClosedAttr.Value = pPoly.Closed.ToString();
2057
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
2058

    
2059
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
2060
                    {
2061
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
2062

    
2063
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
2064
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
2065

    
2066
                        Point3d pt = pPoly.GetPoint3dAt(i);
2067
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
2068
                        XAttr.Value = pt.X.ToString();
2069
                        VertexNode.Attributes.SetNamedItem(XAttr);
2070

    
2071
                        XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
2072
                        YAttr.Value = pt.Y.ToString();
2073
                        VertexNode.Attributes.SetNamedItem(YAttr);
2074

    
2075
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
2076
                        ZAttr.Value = pt.Z.ToString();
2077
                        VertexNode.Attributes.SetNamedItem(ZAttr);
2078

    
2079
                        if (pPoly.HasWidth)
2080
                        {
2081
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
2082
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
2083
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
2084

    
2085
                            XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
2086
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
2087
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
2088
                        }
2089
                        if (pPoly.HasBulges)
2090
                        {
2091
                            XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
2092
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
2093
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
2094

    
2095
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2096
                            {
2097
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
2098
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2099
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2100
                            }
2101
                        }
2102

    
2103
                        PolylineNode.AppendChild(VertexNode);
2104
                    }
2105

    
2106
                    dumpEntityData(pPoly, indent, PolylineNode);
2107
                    node.AppendChild(PolylineNode);
2108
                }
2109
            }
2110
            else
2111
            {
2112
                int d = 0;
2113
            }
2114
        }
2115

    
2116
        class DrawContextDumper : Context
2117
        {
2118
            Database _db;
2119
            public DrawContextDumper(Database db)
2120
            {
2121
                _db = db;
2122
            }
2123
            public override Database Database
2124
            {
2125
                get { return _db; }
2126
            }
2127
            public override bool IsBoundaryClipping
2128
            {
2129
                get { return false; }
2130
            }
2131
            public override bool IsPlotGeneration
2132
            {
2133
                get { return false; }
2134
            }
2135
            public override bool IsPostScriptOut
2136
            {
2137
                get { return false; }
2138
            }
2139
        }
2140
        class SubEntityTraitsDumper : SubEntityTraits
2141
        {
2142
            short _color;
2143
            int _drawFlags;
2144
            FillType _ft;
2145
            ObjectId _layer;
2146
            ObjectId _linetype;
2147
            LineWeight _lineWeight;
2148
            Mapper _mapper;
2149
            double _lineTypeScale;
2150
            ObjectId _material;
2151
            PlotStyleDescriptor _plotStyleDescriptor;
2152
            bool _sectionable;
2153
            bool _selectionOnlyGeometry;
2154
            ShadowFlags _shadowFlags;
2155
            double _thickness;
2156
            EntityColor _trueColor;
2157
            Transparency _transparency;
2158
            ObjectId _visualStyle;
2159
            public SubEntityTraitsDumper(Database db)
2160
            {
2161
                _drawFlags = 0; // kNoDrawFlags 
2162
                _color = 0;
2163
                _ft = FillType.FillAlways;
2164
                _layer = db.Clayer;
2165
                _linetype = db.Celtype;
2166
                _lineWeight = db.Celweight;
2167
                _lineTypeScale = db.Celtscale;
2168
                _material = db.Cmaterial;
2169
                _shadowFlags = ShadowFlags.ShadowsIgnore;
2170
                _thickness = 0;
2171
                _trueColor = new EntityColor(ColorMethod.None);
2172
                _transparency = new Transparency();
2173
            }
2174

    
2175
            protected override void SetLayerFlags(LayerFlags flags)
2176
            {
2177
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2178
            }
2179
            public override void AddLight(ObjectId lightId)
2180
            {
2181
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2182
            }
2183
            public override void SetupForEntity(Entity entity)
2184
            {
2185
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2186
            }
2187

    
2188
            public override short Color
2189
            {
2190
                get { return _color; }
2191
                set { _color = value; }
2192
            }
2193
            public override int DrawFlags
2194
            {
2195
                get { return _drawFlags; }
2196
                set { _drawFlags = value; }
2197
            }
2198
            public override FillType FillType
2199
            {
2200
                get { return _ft; }
2201
                set { _ft = value; }
2202
            }
2203
            public override ObjectId Layer
2204
            {
2205
                get { return _layer; }
2206
                set { _layer = value; }
2207
            }
2208
            public override ObjectId LineType
2209
            {
2210
                get { return _linetype; }
2211
                set { _linetype = value; }
2212
            }
2213
            public override double LineTypeScale
2214
            {
2215
                get { return _lineTypeScale; }
2216
                set { _lineTypeScale = value; }
2217
            }
2218
            public override LineWeight LineWeight
2219
            {
2220
                get { return _lineWeight; }
2221
                set { _lineWeight = value; }
2222
            }
2223
            public override Mapper Mapper
2224
            {
2225
                get { return _mapper; }
2226
                set { _mapper = value; }
2227
            }
2228
            public override ObjectId Material
2229
            {
2230
                get { return _material; }
2231
                set { _material = value; }
2232
            }
2233
            public override PlotStyleDescriptor PlotStyleDescriptor
2234
            {
2235
                get { return _plotStyleDescriptor; }
2236
                set { _plotStyleDescriptor = value; }
2237
            }
2238
            public override bool Sectionable
2239
            {
2240
                get { return _sectionable; }
2241
                set { _sectionable = value; }
2242
            }
2243
            public override bool SelectionOnlyGeometry
2244
            {
2245
                get { return _selectionOnlyGeometry; }
2246
                set { _selectionOnlyGeometry = value; }
2247
            }
2248
            public override ShadowFlags ShadowFlags
2249
            {
2250
                get { return _shadowFlags; }
2251
                set { _shadowFlags = value; }
2252
            }
2253
            public override double Thickness
2254
            {
2255
                get { return _thickness; }
2256
                set { _thickness = value; }
2257
            }
2258
            public override EntityColor TrueColor
2259
            {
2260
                get { return _trueColor; }
2261
                set { _trueColor = value; }
2262
            }
2263
            public override Transparency Transparency
2264
            {
2265
                get { return _transparency; }
2266
                set { _transparency = value; }
2267
            }
2268
            public override ObjectId VisualStyle
2269
            {
2270
                get { return _visualStyle; }
2271
                set { _visualStyle = value; }
2272
            }
2273
            public override void SetSelectionMarker(IntPtr sm)
2274
            {
2275
            }
2276
        }
2277
        class WorldGeometryDumper : WorldGeometry
2278
        {
2279
            Stack<Matrix3d> modelMatrix;
2280
            Stack<ClipBoundary> clips;
2281
            int indent;
2282
            public WorldGeometryDumper(int indent)
2283
              : base()
2284
            {
2285
                this.indent = indent;
2286
                modelMatrix = new Stack<Matrix3d>();
2287
                clips = new Stack<ClipBoundary>();
2288
                modelMatrix.Push(Matrix3d.Identity);
2289
            }
2290
            public override Matrix3d ModelToWorldTransform
2291
            {
2292
                get { return modelMatrix.Peek(); }
2293
            }
2294
            public override Matrix3d WorldToModelTransform
2295
            {
2296
                get { return modelMatrix.Peek().Inverse(); }
2297
            }
2298

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

    
2483
            public override void SetExtents(Extents3d extents)
2484
            {
2485
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2486
            }
2487
            public override void StartAttributesSegment()
2488
            {
2489
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2490
            }
2491
        }
2492

    
2493
        class WorldDrawDumper : WorldDraw
2494
        {
2495
            WorldGeometryDumper _geom;
2496
            DrawContextDumper _ctx;
2497
            SubEntityTraits _subents;
2498
            RegenType _regenType;
2499
            int indent;
2500
            public WorldDrawDumper(Database db, int indent)
2501
              : base()
2502
            {
2503
                _regenType = RegenType;
2504
                this.indent = indent;
2505
                _geom = new WorldGeometryDumper(indent);
2506
                _ctx = new DrawContextDumper(db);
2507
                _subents = new SubEntityTraitsDumper(db);
2508
            }
2509
            public override double Deviation(DeviationType deviationType, Point3d pointOnCurve)
2510
            {
2511
                return 1e-9;
2512
            }
2513
            public override WorldGeometry Geometry
2514
            {
2515
                get
2516
                {
2517
                    return _geom;
2518
                }
2519
            }
2520
            public override bool IsDragging
2521
            {
2522
                get
2523
                {
2524
                    return false;
2525
                }
2526
            }
2527
            public override Int32 NumberOfIsolines
2528
            {
2529
                get
2530
                {
2531
                    return 10;
2532
                }
2533
            }
2534
            public override Geometry RawGeometry
2535
            {
2536
                get
2537
                {
2538
                    return _geom;
2539
                }
2540
            }
2541
            public override bool RegenAbort
2542
            {
2543
                get
2544
                {
2545
                    return false;
2546
                }
2547
            }
2548
            public override RegenType RegenType
2549
            {
2550
                get
2551
                {
2552
                    writeLine(indent, "RegenType is asked");
2553
                    return _regenType;
2554
                }
2555
            }
2556
            public override SubEntityTraits SubEntityTraits
2557
            {
2558
                get
2559
                {
2560
                    return _subents;
2561
                }
2562
            }
2563
            public override Context Context
2564
            {
2565
                get
2566
                {
2567
                    return _ctx;
2568
                }
2569
            }
2570
        }
2571

    
2572
        /************************************************************************/
2573
        /* Dump the common data and WorldDraw information for all               */
2574
        /* entities without explicit dumpers                                    */
2575
        /************************************************************************/
2576
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2577
        {
2578
            if (node != null)
2579
            {
2580
                XmlElement EntNode = Program.xml.CreateElement(pEnt.GetRXClass().Name);
2581

    
2582
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2583
                HandleAttr.Value = pEnt.Handle.ToString();
2584
                EntNode.Attributes.SetNamedItem(HandleAttr);
2585

    
2586
                dumpEntityData(pEnt, indent, EntNode);
2587
                using (Database db = pEnt.Database)
2588
                {
2589
                    /**********************************************************************/
2590
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2591
                    /**********************************************************************/
2592
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2593
                    /**********************************************************************/
2594
                    /* Call worldDraw()                                                   */
2595
                    /**********************************************************************/
2596
                    pEnt.WorldDraw(wd);
2597
                }
2598

    
2599
                node.AppendChild(EntNode);
2600

    
2601
                return EntNode;
2602
            }
2603

    
2604
            return null;
2605
        }
2606

    
2607
        /************************************************************************/
2608
        /* Proxy Entity Dumper                                                  */
2609
        /************************************************************************/
2610
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2611
        {
2612
            if (node != null)
2613
            {
2614
                XmlElement ProxyNode = Program.xml.CreateElement(pProxy.GetRXClass().Name);
2615

    
2616
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2617
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2618
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2619

    
2620
                // this will dump proxy entity graphics
2621
                dump((Entity)pProxy, indent, node);
2622

    
2623
                DBObjectCollection collection = new DBObjectCollection(); ;
2624
                try
2625
                {
2626
                    pProxy.ExplodeGeometry(collection);
2627
                }
2628
                catch (System.Exception)
2629
                {
2630
                    return null;
2631
                }
2632

    
2633
                foreach (Entity ent in collection)
2634
                {
2635
                    if (ent is Polyline2d)
2636
                    {
2637
                        Polyline2d pline2d = (Polyline2d)ent;
2638
                        int i = 0;
2639

    
2640
                        try
2641
                        {
2642
                            foreach (Entity ent1 in pline2d)
2643
                            {
2644
                                if (ent1 is Vertex2d)
2645
                                {
2646
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2647
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2648
                                }
2649
                            }
2650
                        }
2651
                        catch (System.Exception)
2652
                        {
2653
                            return null;
2654
                        }
2655
                    }
2656
                }
2657

    
2658
                node.AppendChild(ProxyNode);
2659
                return ProxyNode;
2660
            }
2661

    
2662
            return null;
2663
        }
2664

    
2665
        /************************************************************************/
2666
        /* Radial Dimension Dumper                                              */
2667
        /************************************************************************/
2668
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2669
        {
2670
            if (node != null)
2671
            {
2672
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2673

    
2674
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2675
                HandleAttr.Value = pDim.Handle.ToString();
2676
                DimNode.Attributes.SetNamedItem(HandleAttr);
2677

    
2678
                XmlAttribute CenterAttr = Program.xml.CreateAttribute("Center");
2679
                CenterAttr.Value = pDim.Center.ToString();
2680
                DimNode.Attributes.SetNamedItem(CenterAttr);
2681

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

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

    
2690
                dumpDimData(pDim, indent, DimNode);
2691

    
2692
                node.AppendChild(DimNode);
2693

    
2694
                return DimNode;
2695
            }
2696

    
2697
            return null;
2698
        }
2699

    
2700
        /************************************************************************/
2701
        /* Dump Raster Image Def                                               */
2702
        /************************************************************************/
2703
        void dumpRasterImageDef(ObjectId id, int indent)
2704
        {
2705
            if (!id.IsValid)
2706
                return;
2707
            using (RasterImageDef pDef = (RasterImageDef)id.Open(OpenMode.ForRead))
2708
            {
2709
                writeLine(indent++, pDef.GetRXClass().Name, pDef.Handle);
2710
                writeLine(indent, "Source Filename", shortenPath(pDef.SourceFileName));
2711
                writeLine(indent, "Loaded", pDef.IsLoaded);
2712
                writeLine(indent, "mm per Pixel", pDef.ResolutionMMPerPixel);
2713
                writeLine(indent, "Loaded", pDef.IsLoaded);
2714
                writeLine(indent, "Resolution Units", pDef.ResolutionUnits);
2715
                writeLine(indent, "Size", pDef.Size);
2716
            }
2717
        }
2718
        /************************************************************************/
2719
        /* Dump Raster Image Data                                               */
2720
        /************************************************************************/
2721
        void dumpRasterImageData(RasterImage pImage, int indent)
2722
        {
2723
            writeLine(indent, "Brightness", pImage.Brightness);
2724
            writeLine(indent, "Clipped", pImage.IsClipped);
2725
            writeLine(indent, "Contrast", pImage.Contrast);
2726
            writeLine(indent, "Fade", pImage.Fade);
2727
            writeLine(indent, "kClip", pImage.DisplayOptions & ImageDisplayOptions.Clip);
2728
            writeLine(indent, "kShow", pImage.DisplayOptions & ImageDisplayOptions.Show);
2729
            writeLine(indent, "kShowUnAligned", pImage.DisplayOptions & ImageDisplayOptions.ShowUnaligned);
2730
            writeLine(indent, "kTransparent", pImage.DisplayOptions & ImageDisplayOptions.Transparent);
2731
            writeLine(indent, "Scale", pImage.Scale);
2732

    
2733
            /********************************************************************/
2734
            /* Dump clip boundary                                               */
2735
            /********************************************************************/
2736
            if (pImage.IsClipped)
2737
            {
2738
                writeLine(indent, "Clip Boundary Type", pImage.ClipBoundaryType);
2739
                if (pImage.ClipBoundaryType != ClipBoundaryType.Invalid)
2740
                {
2741
                    Point2dCollection pt = pImage.GetClipBoundary();
2742
                    for (int i = 0; i < pt.Count; i++)
2743
                    {
2744
                        writeLine(indent, string.Format("Clip Point {0}", i), pt[i]);
2745
                    }
2746
                }
2747
            }
2748

    
2749
            /********************************************************************/
2750
            /* Dump frame                                                       */
2751
            /********************************************************************/
2752
            Point3dCollection vertices = pImage.GetVertices();
2753
            for (int i = 0; i < vertices.Count; i++)
2754
            {
2755
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2756
            }
2757

    
2758
            /********************************************************************/
2759
            /* Dump orientation                                                 */
2760
            /********************************************************************/
2761
            writeLine(indent, "Orientation");
2762
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2763
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2764
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2765
            dumpRasterImageDef(pImage.ImageDefId, indent);
2766
            dumpEntityData(pImage, indent, Program.xml.DocumentElement);
2767
        }
2768

    
2769
        /************************************************************************/
2770
        /* Raster Image Dumper                                                  */
2771
        /************************************************************************/
2772
        void dump(RasterImage pImage, int indent)
2773
        {
2774
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2775
            writeLine(indent, "Image size", pImage.ImageSize(true));
2776
            dumpRasterImageData(pImage, indent);
2777
        }
2778

    
2779
        /************************************************************************/
2780
        /* Ray Dumper                                                          */
2781
        /************************************************************************/
2782
        void dump(Ray pRay, int indent)
2783
        {
2784
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2785
            writeLine(indent, "Base Point", pRay.BasePoint);
2786
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2787
            dumpCurveData(pRay, indent, Program.xml.DocumentElement);
2788
        }
2789

    
2790
        /************************************************************************/
2791
        /* Region Dumper                                                        */
2792
        /************************************************************************/
2793
        void dump(Region pRegion, int indent)
2794
        {
2795
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2796
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2797
        }
2798

    
2799
        /************************************************************************/
2800
        /* Rotated Dimension Dumper                                             */
2801
        /************************************************************************/
2802
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2803
        {
2804
            if (node != null)
2805
            {
2806
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2807

    
2808
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2809
                HandleAttr.Value = pDim.Handle.ToString();
2810
                DimNode.Attributes.SetNamedItem(HandleAttr);
2811

    
2812
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
2813
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2814
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2815

    
2816
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
2817
                ObliqueAttr.Value = pDim.Oblique.ToString();
2818
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2819

    
2820
                XmlAttribute RotationAttr = Program.xml.CreateAttribute("Rotation");
2821
                RotationAttr.Value = pDim.Rotation.ToString();
2822
                DimNode.Attributes.SetNamedItem(RotationAttr);
2823

    
2824
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
2825
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2826
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2827

    
2828
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2829
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2830
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2831

    
2832
                dumpDimData(pDim, indent, DimNode);
2833
                node.AppendChild(DimNode);
2834

    
2835
                return DimNode;
2836
            }
2837

    
2838
            return null;
2839
        }
2840

    
2841
        /************************************************************************/
2842
        /* Shape Dumper                                                          */
2843
        /************************************************************************/
2844
        void dump(Shape pShape, int indent)
2845
        {
2846
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2847

    
2848
            if (!pShape.StyleId.IsNull)
2849
            {
2850
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2851
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2852
            }
2853

    
2854
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2855
            writeLine(indent, "Shape Name", pShape.Name);
2856
            writeLine(indent, "Position", pShape.Position);
2857
            writeLine(indent, "Size", pShape.Size);
2858
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2859
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2860
            writeLine(indent, "Normal", pShape.Normal);
2861
            writeLine(indent, "Thickness", pShape.Thickness);
2862
            dumpEntityData(pShape, indent, Program.xml.DocumentElement);
2863
        }
2864

    
2865
        /************************************************************************/
2866
        /* Solid Dumper                                                         */
2867
        /************************************************************************/
2868
        // TODO:
2869
        /*  void dump(Solid pSolid, int indent)
2870
      {
2871
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2872

    
2873
        for (int i = 0; i < 4; i++)
2874
        {
2875
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2876
        }
2877
        dumpEntityData(pSolid, indent);
2878
      }
2879
    */
2880
        /************************************************************************/
2881
        /* Spline Dumper                                                        */
2882
        /************************************************************************/
2883
        void dump(Spline pSpline, int indent)
2884
        {
2885
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2886

    
2887
            NurbsData data = pSpline.NurbsData;
2888
            writeLine(indent, "Degree", data.Degree);
2889
            writeLine(indent, "Rational", data.Rational);
2890
            writeLine(indent, "Periodic", data.Periodic);
2891
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2892
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2893

    
2894
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2895
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2896
            {
2897
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2898
            }
2899

    
2900
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2901
            for (int i = 0; i < data.GetKnots().Count; i++)
2902
            {
2903
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2904
            }
2905

    
2906
            if (data.Rational)
2907
            {
2908
                writeLine(indent, "Number of Weights", data.GetWeights().Count);
2909
                for (int i = 0; i < data.GetWeights().Count; i++)
2910
                {
2911
                    writeLine(indent, "Weight " + i.ToString(), data.GetWeights()[i]);
2912
                }
2913
            }
2914
            dumpCurveData(pSpline, indent, Program.xml.DocumentElement);
2915
        }
2916
        /************************************************************************/
2917
        /* Table Dumper                                                         */
2918
        /************************************************************************/
2919
        void dump(Table pTable, int indent)
2920
        {
2921
            writeLine(indent++, pTable.GetRXClass().Name, pTable.Handle);
2922
            writeLine(indent, "Position", pTable.Position);
2923
            writeLine(indent, "X-Direction", pTable.Direction);
2924
            writeLine(indent, "Normal", pTable.Normal);
2925
            writeLine(indent, "Height", (int)pTable.Height);
2926
            writeLine(indent, "Width", (int)pTable.Width);
2927
            writeLine(indent, "Rows", (int)pTable.NumRows);
2928
            writeLine(indent, "Columns", (int)pTable.NumColumns);
2929

    
2930
            // TODO:
2931
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2932
            //writeLine(indent, "Table Style",               pStyle.Name);
2933
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2934
        }
2935

    
2936
        /************************************************************************/
2937
        /* Text Dumper                                                          */
2938
        /************************************************************************/
2939
        static void dump(DBText pText, int indent, XmlNode node)
2940
        {
2941
            if (node != null)
2942
            {
2943
                dumpTextData(pText, indent, node);
2944
            }
2945
        }
2946
        /************************************************************************/
2947
        /* Trace Dumper                                                         */
2948
        /************************************************************************/
2949
        void dump(Trace pTrace, int indent)
2950
        {
2951
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2952

    
2953
            for (short i = 0; i < 4; i++)
2954
            {
2955
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2956
            }
2957
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2958
        }
2959

    
2960
        /************************************************************************/
2961
        /* Trace UnderlayReference                                                         */
2962
        /************************************************************************/
2963
        void dump(UnderlayReference pEnt, int indent)
2964
        {
2965
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2966
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2967
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2968
        }
2969

    
2970
        /************************************************************************/
2971
        /* Viewport Dumper                                                       */
2972
        /************************************************************************/
2973
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2974
        {
2975
            if (node != null)
2976
            {
2977
                XmlElement VportNode = Program.xml.CreateElement(pVport.GetRXClass().Name);
2978

    
2979
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2980
                HandleAttr.Value = pVport.Handle.ToString();
2981
                VportNode.Attributes.SetNamedItem(HandleAttr);
2982

    
2983
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2984
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2985
                writeLine(indent, "Center Point", pVport.CenterPoint);
2986
                writeLine(indent, "Circle sides", pVport.CircleSides);
2987
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2988
                writeLine(indent, "Elevation", pVport.Elevation);
2989
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2990
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2991
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2992
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2993

    
2994
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2995
                if (layerIds.Count > 0)
2996
                {
2997
                    writeLine(indent, "Frozen Layers:");
2998
                    for (int i = 0; i < layerIds.Count; i++)
2999
                    {
3000
                        writeLine(indent + 1, i, layerIds[i]);
3001
                    }
3002
                }
3003
                else
3004
                {
3005
                    writeLine(indent, "Frozen Layers", "None");
3006
                }
3007

    
3008
                Point3d origin = new Point3d();
3009
                Vector3d xAxis = new Vector3d();
3010
                Vector3d yAxis = new Vector3d();
3011
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
3012
                writeLine(indent, "UCS origin", origin);
3013
                writeLine(indent, "UCS x-Axis", xAxis);
3014
                writeLine(indent, "UCS y-Axis", yAxis);
3015
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
3016
                writeLine(indent, "Grid On", pVport.GridOn);
3017
                writeLine(indent, "Height", pVport.Height);
3018
                writeLine(indent, "Lens Length", pVport.LensLength);
3019
                writeLine(indent, "Locked", pVport.Locked);
3020
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
3021

    
3022
                if (!pVport.NonRectClipEntityId.IsNull)
3023
                {
3024
                    writeLine(indent, "Non-rectangular Clipper", pVport.NonRectClipEntityId.Handle);
3025
                }
3026
                writeLine(indent, "Render Mode", pVport.RenderMode);
3027
                writeLine(indent, "Remove Hidden Lines", pVport.HiddenLinesRemoved);
3028
                writeLine(indent, "Shade Plot", pVport.ShadePlot);
3029
                writeLine(indent, "Snap Isometric", pVport.SnapIsometric);
3030
                writeLine(indent, "Snap On", pVport.SnapOn);
3031
                writeLine(indent, "Transparent", pVport.Transparent);
3032
                writeLine(indent, "UCS Follow", pVport.UcsFollowModeOn);
3033
                writeLine(indent, "UCS Icon at Origin", pVport.UcsIconAtOrigin);
3034

    
3035
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
3036
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
3037

    
3038
                if (!pVport.UcsName.IsNull)
3039
                {
3040
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
3041
                        writeLine(indent, "UCS Name", pUCS.Name);
3042
                }
3043
                else
3044
                {
3045
                    writeLine(indent, "UCS Name", "Null");
3046
                }
3047

    
3048
                writeLine(indent, "View Center", pVport.ViewCenter);
3049
                writeLine(indent, "View Height", pVport.ViewHeight);
3050
                writeLine(indent, "View Target", pVport.ViewTarget);
3051
                writeLine(indent, "Width", pVport.Width);
3052
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
3053

    
3054
                {
3055
                    using (DBObjectCollection collection = new DBObjectCollection())
3056
                    {
3057
                        try
3058
                        {
3059
                            pVport.ExplodeGeometry(collection);
3060

    
3061
                            foreach (Entity ent in collection)
3062
                            {
3063
                                if (ent is Polyline2d)
3064
                                {
3065
                                    Polyline2d pline2d = (Polyline2d)ent;
3066
                                    int i = 0;
3067
                                    foreach (Entity ent1 in pline2d)
3068
                                    {
3069
                                        if (ent1 is Vertex2d)
3070
                                        {
3071
                                            Vertex2d vtx2d = (Vertex2d)ent1;
3072
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
3073
                                        }
3074
                                    }
3075
                                }
3076
                            }
3077
                        }
3078
                        catch (System.Exception ex)
3079
                        {
3080
                        }
3081
                    }
3082
                }
3083

    
3084
                node.AppendChild(VportNode);
3085
                return VportNode;
3086
            }
3087

    
3088
            return null;
3089
        }
3090

    
3091
        /************************************************************************/
3092
        /* Wipeout Dumper                                                  */
3093
        /************************************************************************/
3094
        void dump(Wipeout pWipeout, int indent)
3095
        {
3096
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3097
            dumpRasterImageData(pWipeout, indent);
3098
        }
3099

    
3100
        /************************************************************************/
3101
        /* Xline Dumper                                                         */
3102
        /************************************************************************/
3103
        void dump(Xline pXline, int indent)
3104
        {
3105
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
3106
            writeLine(indent, "Base Point", pXline.BasePoint);
3107
            writeLine(indent, "Unit Direction", pXline.UnitDir);
3108
            dumpCurveData(pXline, indent, Program.xml.DocumentElement);
3109
        }
3110

    
3111
        public void dump(Database pDb, int indent, XmlNode node)
3112
        {
3113
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3114
            {
3115
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
3116
                {
3117
                    string layoutName = "";
3118
                    layoutName = pLayout.LayoutName;
3119

    
3120
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
3121
                    LayoutNameAttr.Value = layoutName;
3122
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3123
                }
3124
            }
3125

    
3126
            dumpHeader(pDb, indent, node);
3127
            dumpLayers(pDb, indent, node);
3128
            dumpLinetypes(pDb, indent, node);
3129
            dumpTextStyles(pDb, indent, node);
3130
            dumpDimStyles(pDb, indent, node);
3131
            dumpRegApps(pDb, indent);
3132
            dumpViewports(pDb, indent, node);
3133
            dumpViews(pDb, indent, node);
3134
            dumpMLineStyles(pDb, indent);
3135
            dumpUCSTable(pDb, indent, node);
3136
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3137

    
3138
            dumpBlocks(pDb, indent, node);
3139
        }
3140

    
3141
        /************************************************************************/
3142
        /* Export DWG to PDF                                                    */
3143
        /************************************************************************/
3144
        public void ExportPDF(Database pDb, string filePath)
3145
        {
3146
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3147
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3148
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3149

    
3150
            using (mPDFExportParams param = new mPDFExportParams())
3151
            {
3152
                param.Database = pDb;
3153

    
3154
                TransactionManager tm = pDb.TransactionManager;
3155
                using (Transaction ta = tm.StartTransaction())
3156
                {
3157
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3158
                    {
3159
                        param.OutputStream = fileStrem;
3160

    
3161
                        bool embededTTF = false;
3162
                        bool shxTextAsGeometry = true;
3163
                        bool ttfGeometry = true;
3164
                        bool simpleGeomOptimization = false;
3165
                        bool zoomToExtentsMode = true;
3166
                        bool enableLayers = false;
3167
                        bool includeOffLayers = false;
3168
                        bool enablePrcMode = true;
3169
                        bool monochrome = true;
3170
                        bool allLayout = false;
3171
                        double paperWidth = 841;
3172
                        double paperHeight = 594;
3173

    
3174
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3175
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3176
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3177
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3178
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3179
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3180
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3181

    
3182
                        param.Title = "";
3183
                        param.Author = "";
3184
                        param.Subject = "";
3185
                        param.Keywords = "";
3186
                        param.Creator = "";
3187
                        param.Producer = "";
3188
                        param.UseHLR = !enablePrcMode;
3189
                        param.FlateCompression = true;
3190
                        param.ASCIIHEXEncodeStream = true;
3191
                        param.hatchDPI = 720;
3192

    
3193
                        bool bV15 = enableLayers || includeOffLayers;
3194
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3195

    
3196
                        if (enablePrcMode)
3197
                        {
3198
                            Module pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcModule", false, false);
3199
                            if (pModule != null)
3200
                            {
3201
                                pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcExport", false, false);
3202
                            }
3203
                            if (pModule != null)
3204
                            {
3205
                                RXObject pObj = null;
3206
                                bool bUsePRCSingleViewMode = true; // provide a corresponding checkbox in Export to PDF dialog similar to one in OdaMfcApp
3207
                                if (bUsePRCSingleViewMode)
3208
                                {
3209
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_AllInSingleView");
3210
                                }
3211
                                else
3212
                                {
3213
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_Default");
3214
                                }
3215
                                if (pObj != null)
3216
                                {
3217
                                    RXClass pCls = (RXClass)pObj;
3218
                                    if (pCls != null)
3219
                                    {
3220
                                        param.PRCContext = pCls.Create();
3221
                                        param.PRCMode = PRCSupport.AsBrep; //(bUsePRCAsBRep == TRUE ? PRCSupport.AsBrep : PRCSupport.AsMesh);
3222
                                    }
3223
                                    else
3224
                                    {
3225
                                        Console.WriteLine("PDF Export, PRC support - RXClass failed");
3226
                                    }
3227
                                }
3228
                                else
3229
                                {
3230
                                    Console.WriteLine("PDF Export, PRC support - context failed");
3231
                                }
3232
                            }
3233
                            else
3234
                            {
3235
                                Console.WriteLine("PRC module was not loaded", "Error");
3236
                            }
3237
                        }
3238

    
3239
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3240

    
3241
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3242
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3243

    
3244
                        StringCollection strColl = new StringCollection();
3245
                        if (allLayout)
3246
                        {
3247
                            using (DBDictionary layouts = (DBDictionary)pDb.LayoutDictionaryId.GetObject(OpenMode.ForRead))
3248
                            {
3249
                                foreach (DBDictionaryEntry entry in layouts)
3250
                                {
3251
                                    if ("Model" == entry.Key)
3252
                                        strColl.Insert(0, entry.Key);
3253
                                    else
3254
                                        strColl.Add(entry.Key);
3255
                                    if (-1 != iIndexStyle)
3256
                                    {
3257
                                        PlotSettings ps = (PlotSettings)ta.GetObject(entry.Value, OpenMode.ForWrite);
3258
                                        plotSettingVal.SetCurrentStyleSheet(ps, styleCol[iIndexStyle]);
3259
                                    }
3260
                                }
3261
                            }
3262
                        }
3263
                        else if (-1 != iIndexStyle)
3264
                        {
3265
                            using (BlockTableRecord paperBTR = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3266
                            {
3267
                                using (PlotSettings pLayout = (PlotSettings)paperBTR.LayoutId.GetObject(OpenMode.ForWrite))
3268
                                {
3269
                                    plotSettingVal.SetCurrentStyleSheet(pLayout, styleCol[iIndexStyle]);
3270
                                }
3271
                            }
3272
                        }
3273
                        param.Layouts = strColl;
3274

    
3275
                        int nPages = Math.Max(1, strColl.Count);
3276
                        PageParamsCollection pParCol = new PageParamsCollection();
3277
                        for (int i = 0; i < nPages; ++i)
3278
                        {
3279
                            PageParams pp = new PageParams();
3280
                            pp.setParams(paperWidth, paperHeight);
3281
                            pParCol.Add(pp);
3282
                        }
3283
                        param.PageParams = pParCol;
3284
                        Export_Import.ExportPDF(param);
3285
                    }
3286
                    ta.Abort();
3287
                }
3288
            }
3289
        }
3290

    
3291
        /************************************************************************/
3292
        /* Export DWG to PNG                                                    */
3293
        /************************************************************************/
3294
        public void ExportPNG(Database pDb, string filePath)
3295
        {
3296
            ResultBuffer rsb = new ResultBuffer();
3297
            rsb.Add(new TypedValue(5003, 0));
3298
            Teigha.Runtime.Utilities.SetSystemVariables("PDMODE", rsb);
3299

    
3300
            chageColorAllObjects(pDb);
3301

    
3302
            string gdPath = "WinOpenGL_20.5_15.txv";
3303

    
3304
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3305
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3306
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3307
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3308

    
3309
            using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3310
            {
3311
                if (gsModule == null)
3312
                {
3313
                    Console.WriteLine("\nCould not load graphics module {0} \nExport cancelled.", gdPath);
3314
                    return;
3315
                }
3316

    
3317
                // create graphics device
3318
                using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3319
                {
3320
                    // setup device properties
3321
                    using (Dictionary props = dev.Properties)
3322
                    {
3323
                        props.AtPut("BitPerPixel", new RxVariant(32));
3324
                    }
3325
                    using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3326
                    {
3327
                        ctx.PaletteBackground = System.Drawing.Color.White;
3328
                        ctx.SetPlotGeneration(true);
3329

    
3330
                        using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3331
                        {
3332
                            helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3333
                            int width = 9600;
3334
                            int height = 6787;
3335
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
3336
                            helperDevice.OnSize(rect);
3337

    
3338
                            if (ctx.IsPlotGeneration)
3339
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3340
                            else
3341
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3342

    
3343
                            if (helperDevice.ActiveView != null)
3344
                            {
3345
                                helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3346
                                helperDevice.ActiveView.Zoom(0.99);
3347
                                helperDevice.Update();
3348

    
3349
                                Export_Import.ExportBitmap(helperDevice, bmpPath);
3350
                            }
3351
                            else
3352
                            {
3353
                                throw new System.Exception("ViewPort?? ???? ?? ?????????");
3354
                            }
3355
                        }
3356
                    }
3357
                }
3358
            }
3359

    
3360
            if (File.Exists(bmpPath))
3361
            {
3362
                if (File.Exists(pngPath))
3363
                {
3364
                    File.Delete(pngPath);
3365
                }
3366

    
3367
                ////bmp => grayscale bmp => png
3368
                //using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3369
                //{
3370
                //    System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height);
3371
                //    //get a graphics object from the new image
3372
                //    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
3373
                //    {
3374
                //        //create the grayscale ColorMatrix
3375
                //        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][]
3376
                //        {
3377
                //            new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
3378
                //            new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
3379
                //            new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
3380
                //            new float[] { 0,      0,      0,      1, 0 },
3381
                //            new float[] { 0,      0,      0,      0, 1 }
3382
                //        });
3383

    
3384
                //        //create some image attributes
3385
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3386
                //        {
3387
                //            //set the color matrix attribute
3388
                //            attributes.SetColorMatrix(colorMatrix);
3389
                //            //attributes.SetThreshold(0.8F);
3390

    
3391
                //            //draw the original image on the new image
3392
                //            //using the grayscale color matrix
3393
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3394
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3395
                //        }
3396

    
3397
                //    }
3398
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3399
                //}
3400

    
3401
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3402
                {
3403
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3404
                }
3405
                if (File.Exists(bmpPath))
3406
                {
3407
                    File.Delete(bmpPath);
3408
                }
3409
            }
3410
        }
3411

    
3412
        /************************************************************************/
3413
        /* Change the color of all objects                                      */
3414
        /************************************************************************/
3415
        private void chageColorAllObjects(Database pDb)
3416
        {
3417
            List<string> exceptLayerList = new List<string>();
3418
            using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
3419
            {
3420
                foreach (ObjectId id in pTable)
3421
                {
3422
                    using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
3423
                    {
3424
                        if (!pRecord.IsPlottable)
3425
                        {
3426
                            exceptLayerList.Add(pRecord.Name);
3427
                        }
3428
                    }
3429
                }
3430
            }
3431
            
3432
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3433
            {
3434
                LayerTable lt = tr.GetObject(pDb.LayerTableId, OpenMode.ForRead) as LayerTable;
3435
                string layerName = "DWG-FORM";
3436
                if (!lt.Has(layerName))
3437
                {
3438
                    layerName = "0";
3439
                }
3440
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3441
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3442

    
3443
                foreach (ObjectId id in btrModelSpace)
3444
                {
3445
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3446
                    if (ent == null) continue;
3447

    
3448
                    ent.ColorIndex = 7;
3449
                    if (exceptLayerList.Contains(ent.Layer))
3450
                    {
3451
                        ent.Layer = layerName;
3452
                    }
3453

    
3454
                    if (ent is BlockReference)
3455
                    {
3456
                        changeColorBlocks(tr, (BlockReference)ent, exceptLayerList);
3457
                    }
3458
                }
3459

    
3460
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3461
                foreach (DBDictionaryEntry entry in dbdic)
3462
                {
3463
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3464
                    if (group == null) continue;
3465

    
3466
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3467
                    if (idarrTags == null) continue;
3468

    
3469
                    foreach (ObjectId id in idarrTags)
3470
                    {
3471
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3472
                        if (ent == null) continue;
3473

    
3474
                        ent.ColorIndex = 7;
3475
                        if (exceptLayerList.Contains(ent.Layer))
3476
                        {
3477
                            ent.Layer = "0";
3478
                        }
3479
                    }
3480
                }
3481

    
3482
                foreach (ObjectId btrId in bt)
3483
                {
3484
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3485
                    if (btr == null) continue;
3486
                    if (btr.Name.StartsWith("*")) continue;
3487

    
3488
                    foreach (ObjectId entId in btr)
3489
                    {
3490
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3491
                        if (ent == null) continue;
3492
                        ent.ColorIndex = 0;//ByBlock
3493
                        if (exceptLayerList.Contains(ent.Layer))
3494
                        {
3495
                            ent.Layer = "0";
3496
                        }
3497
                    }
3498
                }
3499

    
3500
                tr.Commit();
3501
            }
3502
        }
3503

    
3504
        /************************************************************************/
3505
        /* Change the color of blocks                                           */
3506
        /************************************************************************/
3507
        private void changeColorBlocks(Transaction tr, BlockReference blkRef, List<string> exceptLayerList)
3508
        {
3509
            if (blkRef == null) return;
3510

    
3511
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3512
            {
3513
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3514
                {
3515
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3516
                    attRef.ColorIndex = 7;
3517
                    if (exceptLayerList.Contains(attRef.Layer))
3518
                    {
3519
                        attRef.Layer = "0";
3520
                    }
3521
                }
3522
            }
3523

    
3524
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3525
            if (btrBlock == null) return;
3526

    
3527
            foreach (ObjectId oid in btrBlock)
3528
            {
3529
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3530
                if (ent == null) continue;
3531

    
3532
                ent.ColorIndex = 7;
3533

    
3534
                if (ent is BlockReference)
3535
                {   
3536
                    changeColorBlocks(tr, (BlockReference)ent, exceptLayerList);
3537
                }
3538
            }
3539
        }
3540

    
3541
        /************************************************************************/
3542
        /* Nested block Explode & Purge                                         */
3543
        /************************************************************************/
3544
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3545
        {
3546
            HashSet<string> blockNameList = new HashSet<string>();
3547
            // Explode ModelSpace Nested Block
3548
            blockNameList = explodeNestedBlocks(pDb);
3549

    
3550
            // Prepare Block Purge
3551
            preparePurgeBlocks(pDb, blockNameList);
3552

    
3553
            // Block Purge
3554
            ObjectIdCollection oids = new ObjectIdCollection();
3555
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3556
            {
3557
                foreach (ObjectId id in pTable)
3558
                {
3559
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3560
                    oids.Add(id);
3561
                }
3562
            }
3563
            pDb.Purge(oids);
3564

    
3565
            foreach (ObjectId oid in oids)
3566
            {
3567
                if (oid.IsErased) continue;
3568

    
3569
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3570
                {
3571
                    btr.Erase(true);
3572
                }                
3573
            }
3574
        }
3575

    
3576
        private HashSet<string> explodeNestedBlocks(Database pDb)
3577
        {
3578
            HashSet<string> blockNameList = new HashSet<string>();
3579
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3580

    
3581
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3582
            {
3583
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3584
                {
3585
                    foreach (ObjectId entid in pBlock)
3586
                    {
3587
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3588
                        {
3589
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3590
                            BlockReference blockRef = (BlockReference)pEnt;
3591

    
3592
                            if (blockRef.Name.ToUpper().StartsWith(BLOCK_PIPING))
3593
                            {
3594
                                oidSet.Add(entid);
3595
                                continue;
3596
                            }
3597
                            else if (blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3598
                            {
3599
                                continue;
3600
                            }
3601
                            
3602
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3603
                            {
3604
                                bool isNestedBlock = false;
3605
                                foreach (ObjectId blkid in pBtr)
3606
                                {
3607
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3608
                                    {
3609
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3610
                                        {
3611
                                            oidSet.Add(entid);
3612
                                            isNestedBlock = true;
3613
                                        }
3614
                                    }
3615
                                }
3616
                                if (!isNestedBlock)
3617
                                {
3618
                                    blockNameList.Add(blockRef.Name);
3619
                                }
3620
                            }
3621
                        }
3622
                    }
3623
                }
3624
            }
3625

    
3626
            if (oidSet.Count > 0)
3627
            {
3628
                explodeBlocks(oidSet);
3629
                blockNameList = explodeNestedBlocks(pDb);
3630
            }
3631

    
3632
            return blockNameList;
3633
        }
3634

    
3635
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3636
        {
3637
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3638

    
3639
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3640
            {
3641
                foreach (ObjectId id in pTable)
3642
                {
3643
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForWrite, false, true))
3644
                    {
3645
                        if (pBlock.IsLayout) continue;
3646
                        pBlock.Explodable = true;
3647
                        if (blockNameList.Contains(pBlock.Name)) continue;
3648

    
3649
                        foreach (ObjectId entid in pBlock)
3650
                        {
3651
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3652
                            {
3653
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3654

    
3655
                                oidSet.Add(entid);
3656
                            }
3657
                        }
3658
                    }
3659
                }
3660
            }
3661

    
3662
            if (oidSet.Count > 0)
3663
            {
3664
                explodeBlocks(oidSet);
3665
                preparePurgeBlocks(pDb, blockNameList);
3666
            }
3667

    
3668
            return;
3669
        }
3670
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3671
        {
3672
            foreach (ObjectId blkId in oidSet)
3673
            {
3674
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3675
                blkRef.ExplodeGeometryToOwnerSpace();
3676
                blkRef.Erase();
3677
            }
3678
        }
3679

    
3680
        /************************************************************************/
3681
        /* Save Block as DWG For Auxiliary Graphic                              */
3682
        /************************************************************************/
3683
        public void ExportGraphicBlocks(Database pDb, string savePath)
3684
        {
3685
            try
3686
            {
3687
                using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3688
                {
3689
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3690
                    {
3691
                        foreach (ObjectId entid in pBlock)
3692
                        {
3693
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3694
                            {
3695
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3696
                                BlockReference blockRef = (BlockReference)pEnt;
3697
                                if (!blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3698
                                    continue;
3699

    
3700
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3701
                                objIdCol.Add(blockRef.ObjectId);
3702
                                if (objIdCol.Count == 0) continue;
3703

    
3704
                                string filePath = string.Format("{0}.dwg", blockRef.Name);
3705
                                string directory = Path.GetDirectoryName(savePath);
3706
                                directory = directory.ToLower().Replace("drawings\\native", "graphic");
3707
                                if (!Directory.Exists(directory))
3708
                                {
3709
                                    Directory.CreateDirectory(directory);
3710
                                }
3711
                                filePath = Path.Combine(directory, filePath);
3712
                                
3713
                                using (Database newDb = new Database(true, false))
3714
                                {
3715
                                    pDb.Wblock(newDb, objIdCol, Point3d.Origin, DuplicateRecordCloning.Ignore);
3716
                                    newDb.UpdateExt(false);
3717
                                    newDb.UpdateExt(true);
3718
                                    newDb.SaveAs(filePath, DwgVersion.Newest);
3719
                                }
3720

    
3721
                                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo();
3722
                                procStartInfo.FileName = @"C:\Program Files (x86)\SmartSketch\Program\Rad2d\bin\Dwg2Igr.exe";
3723
                                procStartInfo.RedirectStandardOutput = true;
3724
                                procStartInfo.RedirectStandardInput = true;
3725
                                procStartInfo.RedirectStandardError = true;
3726
                                procStartInfo.UseShellExecute = false;
3727
                                procStartInfo.CreateNoWindow = false;
3728
                                procStartInfo.Arguments = filePath.Replace(" ", "^");
3729

    
3730
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3731
                                {
3732
                                    proc.StartInfo = procStartInfo;
3733
                                    proc.Start();
3734
                                    proc.StandardInput.Close();
3735
                                    proc.WaitForExit();
3736

    
3737
                                    switch (proc.ExitCode)
3738
                                    {
3739
                                        case -1:
3740
                                            Console.WriteLine("[{0}] path does not exist or there is no file", filePath);
3741
                                            break;
3742
                                        case 0:
3743
                                            Console.WriteLine("[{0}] File conversion error", filePath.Replace(".dwg", ".igr"));
3744
                                            break;
3745
                                        case 1:
3746
                                            Console.WriteLine("[{0}] File conversion success", filePath.Replace(".dwg", ".igr"));
3747
                                            break;
3748
                                        default:
3749
                                            break;
3750
                                    }
3751
                                }
3752
                            }
3753
                        }
3754
                    }
3755
                }
3756
            }
3757
            catch (System.Exception ex)
3758
            {
3759
            }
3760
        }
3761
        /************************************************************************/
3762
        /* Dump the BlockTable                                                  */
3763
        /************************************************************************/
3764
        public void dumpBlocks(Database pDb, int indent, XmlNode node)
3765
        {
3766
            /**********************************************************************/
3767
            /* Get a pointer to the BlockTable                               */
3768
            /**********************************************************************/
3769
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3770
            {
3771
                /**********************************************************************/
3772
                /* Dump the Description                                               */
3773
                /**********************************************************************/
3774
                XmlElement BlocksNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
3775

    
3776
                /**********************************************************************/
3777
                /* Step through the BlockTable                                        */
3778
                /**********************************************************************/
3779
                foreach (ObjectId id in pTable)
3780
                {
3781
                    /********************************************************************/
3782
                    /* Open the BlockTableRecord for Reading                            */
3783
                    /********************************************************************/
3784
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3785
                    {
3786
                        /********************************************************************/
3787
                        /* Dump the BlockTableRecord                                        */
3788
                        /********************************************************************/
3789
                        XmlElement BlockNode = Program.xml.CreateElement(pBlock.GetRXClass().Name);
3790

    
3791
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
3792
                        NameAttr.Value = pBlock.Name;
3793
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3794

    
3795
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3796
                        CommentsAttr.Value = pBlock.Comments;
3797
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3798

    
3799
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3800
                        OriginAttr.Value = pBlock.Origin.ToString();
3801
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3802

    
3803
                        writeLine(indent, pBlock.GetRXClass().Name);
3804
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3805
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3806
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3807
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3808
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3809

    
3810
                        try
3811
                        {
3812
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3813
                            extents.AddBlockExtents(pBlock);
3814

    
3815
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3816
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3817
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3818

    
3819
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3820
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3821
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3822
                        }
3823
                        catch (System.Exception)
3824
                        {
3825
                        }
3826

    
3827
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3828
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3829
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3830
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3831
                        {
3832
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3833
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3834
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3835
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3836
                        }
3837

    
3838
                        /********************************************************************/
3839
                        /* Step through the BlockTableRecord                                */
3840
                        /********************************************************************/
3841
                        foreach (ObjectId entid in pBlock)
3842
                        {
3843
                            /********************************************************************/
3844
                            /* Dump the Entity                                                  */
3845
                            /********************************************************************/
3846
                            dumpEntity(entid, indent + 1, BlockNode);
3847
                        }
3848

    
3849
                        BlocksNode.AppendChild(BlockNode);
3850
                    }
3851
                }
3852

    
3853
                node.AppendChild(BlocksNode);
3854
            }
3855
        }
3856

    
3857
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3858
        {
3859
            /**********************************************************************/
3860
            /* Get a SmartPointer to the DimStyleTable                            */
3861
            /**********************************************************************/
3862
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3863
            {
3864
                /**********************************************************************/
3865
                /* Dump the Description                                               */
3866
                /**********************************************************************/
3867
                writeLine();
3868
                writeLine(indent++, pTable.GetRXClass().Name);
3869

    
3870
                /**********************************************************************/
3871
                /* Step through the DimStyleTable                                    */
3872
                /**********************************************************************/
3873
                foreach (ObjectId id in pTable)
3874
                {
3875
                    /*********************************************************************/
3876
                    /* Open the DimStyleTableRecord for Reading                         */
3877
                    /*********************************************************************/
3878
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3879
                    {
3880
                        /*********************************************************************/
3881
                        /* Dump the DimStyleTableRecord                                      */
3882
                        /*********************************************************************/
3883
                        writeLine();
3884
                        writeLine(indent, pRecord.GetRXClass().Name);
3885
                        writeLine(indent, "Name", pRecord.Name);
3886
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3887

    
3888
                        writeLine(indent, "Background Text Color", pRecord.Dimtfillclr);
3889
                        writeLine(indent, "BackgroundText Flags", pRecord.Dimtfill);
3890
                        writeLine(indent, "Extension Line 1 Linetype", pRecord.Dimltex1);
3891
                        writeLine(indent, "Extension Line 2 Linetype", pRecord.Dimltex2);
3892
                        writeLine(indent, "Dimension Line Linetype", pRecord.Dimltype);
3893
                        writeLine(indent, "Extension Line Fixed Len", pRecord.Dimfxlen);
3894
                        writeLine(indent, "Extension Line Fixed Len Enable", pRecord.DimfxlenOn);
3895
                        writeLine(indent, "Jog Angle", toDegreeString(pRecord.Dimjogang));
3896
                        writeLine(indent, "Modified For Recompute", pRecord.IsModifiedForRecompute);
3897
                        writeLine(indent, "DIMADEC", pRecord.Dimadec);
3898
                        writeLine(indent, "DIMALT", pRecord.Dimalt);
3899
                        writeLine(indent, "DIMALTD", pRecord.Dimaltd);
3900
                        writeLine(indent, "DIMALTF", pRecord.Dimaltf);
3901
                        writeLine(indent, "DIMALTRND", pRecord.Dimaltrnd);
3902
                        writeLine(indent, "DIMALTTD", pRecord.Dimalttd);
3903
                        writeLine(indent, "DIMALTTZ", pRecord.Dimalttz);
3904
                        writeLine(indent, "DIMALTU", pRecord.Dimaltu);
3905
                        writeLine(indent, "DIMALTZ", pRecord.Dimaltz);
3906
                        writeLine(indent, "DIMAPOST", pRecord.Dimapost);
3907
                        writeLine(indent, "DIMASZ", pRecord.Dimasz);
3908
                        writeLine(indent, "DIMATFIT", pRecord.Dimatfit);
3909
                        writeLine(indent, "DIMAUNIT", pRecord.Dimaunit);
3910
                        writeLine(indent, "DIMAZIN", pRecord.Dimazin);
3911
                        writeLine(indent, "DIMBLK", pRecord.Dimblk);
3912
                        writeLine(indent, "DIMBLK1", pRecord.Dimblk1);
3913
                        writeLine(indent, "DIMBLK2", pRecord.Dimblk2);
3914
                        writeLine(indent, "DIMCEN", pRecord.Dimcen);
3915
                        writeLine(indent, "DIMCLRD", pRecord.Dimclrd);
3916
                        writeLine(indent, "DIMCLRE", pRecord.Dimclre);
3917
                        writeLine(indent, "DIMCLRT", pRecord.Dimclrt);
3918
                        writeLine(indent, "DIMDEC", pRecord.Dimdec);
3919
                        writeLine(indent, "DIMDLE", pRecord.Dimdle);
3920
                        writeLine(indent, "DIMDLI", pRecord.Dimdli);
3921
                        writeLine(indent, "DIMDSEP", pRecord.Dimdsep);
3922
                        writeLine(indent, "DIMEXE", pRecord.Dimexe);
3923
                        writeLine(indent, "DIMEXO", pRecord.Dimexo);
3924
                        writeLine(indent, "DIMFRAC", pRecord.Dimfrac);
3925
                        writeLine(indent, "DIMGAP", pRecord.Dimgap);
3926
                        writeLine(indent, "DIMJUST", pRecord.Dimjust);
3927
                        writeLine(indent, "DIMLDRBLK", pRecord.Dimldrblk);
3928
                        writeLine(indent, "DIMLFAC", pRecord.Dimlfac);
3929
                        writeLine(indent, "DIMLIM", pRecord.Dimlim);
3930
                        writeLine(indent, "DIMLUNIT", pRecord.Dimlunit);
3931
                        writeLine(indent, "DIMLWD", pRecord.Dimlwd);
3932
                        writeLine(indent, "DIMLWE", pRecord.Dimlwe);
3933
                        writeLine(indent, "DIMPOST", pRecord.Dimpost);
3934
                        writeLine(indent, "DIMRND", pRecord.Dimrnd);
3935
                        writeLine(indent, "DIMSAH", pRecord.Dimsah);
3936
                        writeLine(indent, "DIMSCALE", pRecord.Dimscale);
3937
                        writeLine(indent, "DIMSD1", pRecord.Dimsd1);
3938
                        writeLine(indent, "DIMSD2", pRecord.Dimsd2);
3939
                        writeLine(indent, "DIMSE1", pRecord.Dimse1);
3940
                        writeLine(indent, "DIMSE2", pRecord.Dimse2);
3941
                        writeLine(indent, "DIMSOXD", pRecord.Dimsoxd);
3942
                        writeLine(indent, "DIMTAD", pRecord.Dimtad);
3943
                        writeLine(indent, "DIMTDEC", pRecord.Dimtdec);
3944
                        writeLine(indent, "DIMTFAC", pRecord.Dimtfac);
3945
                        writeLine(indent, "DIMTIH", pRecord.Dimtih);
3946
                        writeLine(indent, "DIMTIX", pRecord.Dimtix);
3947
                        writeLine(indent, "DIMTM", pRecord.Dimtm);
3948
                        writeLine(indent, "DIMTOFL", pRecord.Dimtofl);
3949
                        writeLine(indent, "DIMTOH", pRecord.Dimtoh);
3950
                        writeLine(indent, "DIMTOL", pRecord.Dimtol);
3951
                        writeLine(indent, "DIMTOLJ", pRecord.Dimtolj);
3952
                        writeLine(indent, "DIMTP", pRecord.Dimtp);
3953
                        writeLine(indent, "DIMTSZ", pRecord.Dimtsz);
3954
                        writeLine(indent, "DIMTVP", pRecord.Dimtvp);
3955
                        writeLine(indent, "DIMTXSTY", pRecord.Dimtxsty);
3956
                        writeLine(indent, "DIMTXT", pRecord.Dimtxt);
3957
                        writeLine(indent, "DIMTZIN", pRecord.Dimtzin);
3958
                        writeLine(indent, "DIMUPT", pRecord.Dimupt);
3959
                        writeLine(indent, "DIMZIN", pRecord.Dimzin);
3960

    
3961
                        dumpSymbolTableRecord(pRecord, indent, node);
3962
                    }
3963
                }
3964
            }
3965
        }
3966

    
3967
        /// <summary>
3968
        /// extract information from entity has given id
3969
        /// </summary>
3970
        /// <param name="id"></param>
3971
        /// <param name="indent"></param>
3972
        /// <param name="node">XmlNode</param>
3973
        public void dumpEntity(ObjectId id, int indent, XmlNode node)
3974
        {
3975
            /**********************************************************************/
3976
            /* Get a pointer to the Entity                                   */
3977
            /**********************************************************************/
3978
            try
3979
            {
3980
                using (Entity pEnt = (Entity)id.Open(OpenMode.ForRead, false, true))
3981
                {
3982
                    /**********************************************************************/
3983
                    /* Dump the entity                                                    */
3984
                    /**********************************************************************/
3985
                    writeLine();
3986
                    // Protocol extensions are not supported in DD.NET (as well as in ARX.NET)
3987
                    // so we just switch by entity type here
3988
                    // (maybe it makes sense to make a map: type -> delegate)
3989
                    switch (pEnt.GetRXClass().Name)
3990
                    {
3991
                        case "AcDbAlignedDimension":
3992
                            dump((AlignedDimension)pEnt, indent, node);
3993
                            break;
3994
                        case "AcDbArc":
3995
                            dump((Arc)pEnt, indent, node);
3996
                            break;
3997
                        case "AcDbArcDimension":
3998
                            dump((ArcDimension)pEnt, indent, node);
3999
                            break;
4000
                        case "AcDbBlockReference":
4001
                            dump((BlockReference)pEnt, indent, node);
4002
                            break;
4003
                        case "AcDbBody":
4004
                            dump((Body)pEnt, indent, node);
4005
                            break;
4006
                        case "AcDbCircle":
4007
                            dump((Circle)pEnt, indent, node);
4008
                            break;
4009
                        case "AcDbPoint":
4010
                            dump((DBPoint)pEnt, indent);
4011
                            break;
4012
                        case "AcDbText":
4013
                            dump((DBText)pEnt, indent, node);
4014
                            break;
4015
                        case "AcDbDiametricDimension":
4016
                            dump((DiametricDimension)pEnt, indent, node);
4017
                            break;
4018
                        case "AcDbViewport":
4019
                            dump((Teigha.DatabaseServices.Viewport)pEnt, indent, node);
4020
                            break;
4021
                        case "AcDbEllipse":
4022
                            dump((Ellipse)pEnt, indent, node);
4023
                            break;
4024
                        case "AcDbFace":
4025
                            dump((Face)pEnt, indent, node);
4026
                            break;
4027
                        case "AcDbFcf":
4028
                            dump((FeatureControlFrame)pEnt, indent);
4029
                            break;
4030
                        case "AcDbHatch":
4031
                            dump((Hatch)pEnt, indent);
4032
                            break;
4033
                        case "AcDbLeader":
4034
                            dump((Leader)pEnt, indent);
4035
                            break;
4036
                        case "AcDbLine":
4037
                            dump((Line)pEnt, indent, node);
4038
                            break;
4039
                        case "AcDb2LineAngularDimension":
4040
                            dump((LineAngularDimension2)pEnt, indent, node);
4041
                            break;
4042
                        case "AcDbMInsertBlock":
4043
                            dump((MInsertBlock)pEnt, indent, node);
4044
                            break;
4045
                        case "AcDbMline":
4046
                            dump((Mline)pEnt, indent);
4047
                            break;
4048
                        case "AcDbMText":
4049
                            dump((MText)pEnt, indent, node);
4050
                            break;
4051
                        case "AcDbOle2Frame":
4052
                            dump((Ole2Frame)pEnt, indent);
4053
                            break;
4054
                        case "AcDbOrdinateDimension":
4055
                            dump((OrdinateDimension)pEnt, indent, node);
4056
                            break;
4057
                        case "AcDb3PointAngularDimension":
4058
                            dump((Point3AngularDimension)pEnt, indent, node);
4059
                            break;
4060
                        case "AcDbPolyFaceMesh":
4061
                            dump((PolyFaceMesh)pEnt, indent, node);
4062
                            break;
4063
                        case "AcDbPolygonMesh":
4064
                            dump((PolygonMesh)pEnt, indent);
4065
                            break;
4066
                        case "AcDbPolyline":
4067
                            dump((Teigha.DatabaseServices.Polyline)pEnt, indent, node);
4068
                            break;
4069
                        case "AcDb2dPolyline":
4070
                            dump((Polyline2d)pEnt, indent, node);
4071
                            break;
4072
                        case "AcDb3dPolyline":
4073
                            dump((Polyline3d)pEnt, indent, node);
4074
                            break;
4075
                        case "AcDbProxyEntity":
4076
                            dump((ProxyEntity)pEnt, indent, node);
4077
                            break;
4078
                        case "AcDbRadialDimension":
4079
                            dump((RadialDimension)pEnt, indent, node);
4080
                            break;
4081
                        case "AcDbRasterImage":
4082
                            dump((RasterImage)pEnt, indent);
4083
                            break;
4084
                        case "AcDbRay":
4085
                            dump((Ray)pEnt, indent);
4086
                            break;
4087
                        case "AcDbRegion":
4088
                            dump((Region)pEnt, indent);
4089
                            break;
4090
                        case "AcDbRotatedDimension":
4091
                            dump((RotatedDimension)pEnt, indent, node);
4092
                            break;
4093
                        case "AcDbShape":
4094
                            dump((Shape)pEnt, indent);
4095
                            break;
4096
                        case "AcDb3dSolid":
4097
                            dump((Solid3d)pEnt, indent, node);
4098
                            break;
4099
                        case "AcDbSpline":
4100
                            dump((Spline)pEnt, indent);
4101
                            break;
4102
                        case "AcDbTable":
4103
                            dump((Table)pEnt, indent);
4104
                            break;
4105
                        case "AcDbTrace":
4106
                            dump((Trace)pEnt, indent);
4107
                            break;
4108
                        case "AcDbWipeout":
4109
                            dump((Wipeout)pEnt, indent);
4110
                            break;
4111
                        case "AcDbXline":
4112
                            dump((Xline)pEnt, indent);
4113
                            break;
4114
                        case "AcDbAttributeDefinition":
4115
                            dump((AttributeDefinition)pEnt, indent, node);
4116
                            break; 
4117
                        case "AcDbPdfReference":
4118
                        case "AcDbDwfReference":
4119
                        case "AcDbDgnReference":
4120
                            dump((UnderlayReference)pEnt, indent);
4121
                            break;
4122
                        default:
4123
                            dump(pEnt, indent, node);
4124
                            break;
4125
                    }
4126
                    /* Dump the Xdata                                                     */
4127
                    /**********************************************************************/
4128
                    dumpXdata(pEnt.XData, indent);
4129

    
4130
                    /**********************************************************************/
4131
                    /* Dump the Extension Dictionary                                      */
4132
                    /**********************************************************************/
4133
                    if (!pEnt.ExtensionDictionary.IsNull)
4134
                    {
4135
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
4136
                    }
4137
                }
4138
            }
4139
            catch (System.Exception ex)
4140
            {
4141
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
4142
            }
4143
        }
4144
        public void prepareDump(Database pDb)
4145
        {
4146
            // Purge Object(Layer X, Linetype X)
4147
            ObjectIdCollection oids = new ObjectIdCollection();
4148
            using (Transaction tr = pDb.TransactionManager.StartOpenCloseTransaction())
4149
            {
4150
                for (long i = 0; i < pDb.Handseed.Value; i++)
4151
                {
4152
                    ObjectId id = ObjectId.Null;
4153
                    pDb.TryGetObjectId(new Handle(i), out id);
4154
                    if (id != ObjectId.Null && !id.IsErased) oids.Add(id);
4155
                }
4156

    
4157
                pDb.Purge(oids);
4158
                try
4159
                {
4160
                    foreach (ObjectId oid in oids)
4161
                    {
4162
                        if (oid.IsErased) continue;
4163

    
4164
                        DBObject obj = tr.GetObject(oid, OpenMode.ForWrite, false, true) as DBObject;
4165
                        obj.Erase(true);
4166
                    }
4167
                }
4168
                catch (System.Exception ex)
4169
                {
4170
                }
4171

    
4172
                tr.Commit();
4173
            }
4174

    
4175
            // Viewport Ucs
4176
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4177
            {
4178
                foreach (ObjectId id in pTable)
4179
                {
4180
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4181
                    {
4182
                        if (pRecord.Name == "*Active")
4183
                        {
4184
                            CoordinateSystem3d cs3d = pRecord.Ucs;
4185
                            if (cs3d.Origin != Point3d.Origin || cs3d.Xaxis != new Vector3d(1, 0, 0) || cs3d.Yaxis != new Vector3d(0, 1, 0))
4186
                            {
4187
                                pRecord.UpgradeOpen();
4188
                                pRecord.SetUcsToWorld();
4189
                            }
4190
                            if (pRecord.ViewTwist != 0)
4191
                            {
4192
                                pRecord.UpgradeOpen();
4193
                                pRecord.ViewTwist = 0;
4194
                            }
4195
                            if (pRecord.ViewDirection != new Vector3d(0, 0, 1))
4196
                            {
4197
                                pRecord.UpgradeOpen();
4198
                                pRecord.ViewDirection = new Vector3d(0, 0, 1);
4199
                            }
4200
                        }
4201
                    }
4202
                }
4203
            }
4204

    
4205
            Extents3d extents = new Extents3d(pDb.Extmin, pDb.Extmax);
4206
            // SEC Title box Move & Erase
4207
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
4208
            {
4209
                string blockName = "Titlebox";
4210

    
4211
                bool isOK = false;
4212
                if (pTable.Has(blockName))
4213
                {
4214
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
4215
                    {
4216
                        foreach (ObjectId entid in pBlock)
4217
                        {
4218
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
4219
                            {
4220
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
4221
                                BlockReference blockRef = (BlockReference)pEnt;
4222
                                if (blockRef.Name.Equals(blockName))
4223
                                {
4224
                                    isOK = true;
4225
                                    extents = blockRef.GeometricExtents;
4226
                                    break;
4227
                                }
4228
                            }
4229
                        }
4230
                    }
4231
                }
4232

    
4233
                if (isOK)
4234
                {
4235
                    Vector3d vec = extents.MinPoint.GetVectorTo(Point3d.Origin);
4236
                    extents.TransformBy(Matrix3d.Displacement(vec));
4237
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
4238
                    {
4239
                        foreach (ObjectId entid in pBlock)
4240
                        {
4241
                            using (Entity entity = (Entity)entid.Open(OpenMode.ForWrite, false, true))
4242
                            {
4243
                                if (entity != null)
4244
                                    entity.TransformBy(Matrix3d.Displacement(vec));
4245
                                try
4246
                                {
4247
                                    if (entity.Bounds != null)
4248
                                    {
4249
                                        Extents3d entExtents = entity.GeometricExtents;
4250
                                        if ((entExtents.MinPoint.X >= extents.MinPoint.X && entExtents.MinPoint.Y >= extents.MinPoint.Y
4251
                                            && entExtents.MinPoint.X <= extents.MaxPoint.X && entExtents.MinPoint.Y <= extents.MaxPoint.Y)
4252
                                            || (entExtents.MaxPoint.X >= extents.MinPoint.X && entExtents.MaxPoint.Y >= extents.MinPoint.Y
4253
                                            && entExtents.MaxPoint.X <= extents.MaxPoint.X && entExtents.MaxPoint.Y <= extents.MaxPoint.Y))
4254
                                        {
4255
                                        }
4256
                                        else
4257
                                        {
4258
                                            entity.Erase();
4259
                                        }
4260
                                    }
4261
                                }
4262
                                catch (System.Exception ex)
4263
                                {
4264
                                }
4265
                            }
4266
                        }
4267
                    }
4268
                }
4269
            }
4270
            pDb.UpdateExt(false);
4271
            pDb.UpdateExt(true);
4272
            pDb.Extmin = extents.MinPoint;
4273
            pDb.Extmax = extents.MaxPoint;
4274
        }
4275
        public void dumpHeader(Database pDb, int indent, XmlNode node)
4276
        {
4277
            if (node != null)
4278
            {
4279
                XmlAttribute FileNameAttr = Program.xml.CreateAttribute("FileName");
4280
                FileNameAttr.Value = shortenPath(pDb.Filename);
4281
                node.Attributes.SetNamedItem(FileNameAttr);
4282

    
4283
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
4284
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4285
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4286

    
4287
                writeLine();
4288
                writeLine(indent++, "Header Variables:");
4289

    
4290
                //writeLine();
4291
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4292
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4293

    
4294
                writeLine();
4295
                writeLine(indent, "ANGBASE", pDb.Angbase);
4296
                writeLine(indent, "ANGDIR", pDb.Angdir);
4297
                writeLine(indent, "ATTMODE", pDb.Attmode);
4298
                writeLine(indent, "AUNITS", pDb.Aunits);
4299
                writeLine(indent, "AUPREC", pDb.Auprec);
4300
                writeLine(indent, "CECOLOR", pDb.Cecolor);
4301
                writeLine(indent, "CELTSCALE", pDb.Celtscale);
4302
                writeLine(indent, "CHAMFERA", pDb.Chamfera);
4303
                writeLine(indent, "CHAMFERB", pDb.Chamferb);
4304
                writeLine(indent, "CHAMFERC", pDb.Chamferc);
4305
                writeLine(indent, "CHAMFERD", pDb.Chamferd);
4306
                writeLine(indent, "CMLJUST", pDb.Cmljust);
4307
                writeLine(indent, "CMLSCALE", pDb.Cmljust);
4308
                writeLine(indent, "DIMADEC", pDb.Dimadec);
4309
                writeLine(indent, "DIMALT", pDb.Dimalt);
4310
                writeLine(indent, "DIMALTD", pDb.Dimaltd);
4311
                writeLine(indent, "DIMALTF", pDb.Dimaltf);
4312
                writeLine(indent, "DIMALTRND", pDb.Dimaltrnd);
4313
                writeLine(indent, "DIMALTTD", pDb.Dimalttd);
4314
                writeLine(indent, "DIMALTTZ", pDb.Dimalttz);
4315
                writeLine(indent, "DIMALTU", pDb.Dimaltu);
4316
                writeLine(indent, "DIMALTZ", pDb.Dimaltz);
4317
                writeLine(indent, "DIMAPOST", pDb.Dimapost);
4318
                writeLine(indent, "DIMASZ", pDb.Dimasz);
4319
                writeLine(indent, "DIMATFIT", pDb.Dimatfit);
4320
                writeLine(indent, "DIMAUNIT", pDb.Dimaunit);
4321
                writeLine(indent, "DIMAZIN", pDb.Dimazin);
4322
                writeLine(indent, "DIMBLK", pDb.Dimblk);
4323
                writeLine(indent, "DIMBLK1", pDb.Dimblk1);
4324
                writeLine(indent, "DIMBLK2", pDb.Dimblk2);
4325
                writeLine(indent, "DIMCEN", pDb.Dimcen);
4326
                writeLine(indent, "DIMCLRD", pDb.Dimclrd);
4327
                writeLine(indent, "DIMCLRE", pDb.Dimclre);
4328
                writeLine(indent, "DIMCLRT", pDb.Dimclrt);
4329
                writeLine(indent, "DIMDEC", pDb.Dimdec);
4330
                writeLine(indent, "DIMDLE", pDb.Dimdle);
4331
                writeLine(indent, "DIMDLI", pDb.Dimdli);
4332
                writeLine(indent, "DIMDSEP", pDb.Dimdsep);
4333
                writeLine(indent, "DIMEXE", pDb.Dimexe);
4334
                writeLine(indent, "DIMEXO", pDb.Dimexo);
4335
                writeLine(indent, "DIMFRAC", pDb.Dimfrac);
4336
                writeLine(indent, "DIMGAP", pDb.Dimgap);
4337
                writeLine(indent, "DIMJUST", pDb.Dimjust);
4338
                writeLine(indent, "DIMLDRBLK", pDb.Dimldrblk);
4339
                writeLine(indent, "DIMLFAC", pDb.Dimlfac);
4340
                writeLine(indent, "DIMLIM", pDb.Dimlim);
4341
                writeLine(indent, "DIMLUNIT", pDb.Dimlunit);
4342
                writeLine(indent, "DIMLWD", pDb.Dimlwd);
4343
                writeLine(indent, "DIMLWE", pDb.Dimlwe);
4344
                writeLine(indent, "DIMPOST", pDb.Dimpost);
4345
                writeLine(indent, "DIMRND", pDb.Dimrnd);
4346
                writeLine(indent, "DIMSAH", pDb.Dimsah);
4347
                writeLine(indent, "DIMSCALE", pDb.Dimscale);
4348
                writeLine(indent, "DIMSD1", pDb.Dimsd1);
4349
                writeLine(indent, "DIMSD2", pDb.Dimsd2);
4350
                writeLine(indent, "DIMSE1", pDb.Dimse1);
4351
                writeLine(indent, "DIMSE2", pDb.Dimse2);
4352
                writeLine(indent, "DIMSOXD", pDb.Dimsoxd);
4353
                writeLine(indent, "DIMTAD", pDb.Dimtad);
4354
                writeLine(indent, "DIMTDEC", pDb.Dimtdec);
4355
                writeLine(indent, "DIMTFAC", pDb.Dimtfac);
4356
                writeLine(indent, "DIMTIH", pDb.Dimtih);
4357
                writeLine(indent, "DIMTIX", pDb.Dimtix);
4358
                writeLine(indent, "DIMTM", pDb.Dimtm);
4359
                writeLine(indent, "DIMTOFL", pDb.Dimtofl);
4360
                writeLine(indent, "DIMTOH", pDb.Dimtoh);
4361
                writeLine(indent, "DIMTOL", pDb.Dimtol);
4362
                writeLine(indent, "DIMTOLJ", pDb.Dimtolj);
4363
                writeLine(indent, "DIMTP", pDb.Dimtp);
4364
                writeLine(indent, "DIMTSZ", pDb.Dimtsz);
4365
                writeLine(indent, "DIMTVP", pDb.Dimtvp);
4366
                writeLine(indent, "DIMTXSTY", pDb.Dimtxsty);
4367
                writeLine(indent, "DIMTXT", pDb.Dimtxt);
4368
                writeLine(indent, "DIMTZIN", pDb.Dimtzin);
4369
                writeLine(indent, "DIMUPT", pDb.Dimupt);
4370
                writeLine(indent, "DIMZIN", pDb.Dimzin);
4371
                writeLine(indent, "DISPSILH", pDb.DispSilh);
4372
                writeLine(indent, "DRAWORDERCTL", pDb.DrawOrderCtl);
4373
                writeLine(indent, "ELEVATION", pDb.Elevation);
4374
                writeLine(indent, "EXTMAX", pDb.Extmax);
4375
                writeLine(indent, "EXTMIN", pDb.Extmin);
4376
                writeLine(indent, "FACETRES", pDb.Facetres);
4377
                writeLine(indent, "FILLETRAD", pDb.Filletrad);
4378
                writeLine(indent, "FILLMODE", pDb.Fillmode);
4379
                writeLine(indent, "INSBASE", pDb.Insbase);
4380
                writeLine(indent, "ISOLINES", pDb.Isolines);
4381
                writeLine(indent, "LIMCHECK", pDb.Limcheck);
4382
                writeLine(indent, "LIMMAX", pDb.Limmax);
4383
                writeLine(indent, "LIMMIN", pDb.Limmin);
4384
                writeLine(indent, "LTSCALE", pDb.Ltscale);
4385
                writeLine(indent, "LUNITS", pDb.Lunits);
4386
                writeLine(indent, "LUPREC", pDb.Luprec);
4387
                writeLine(indent, "MAXACTVP", pDb.Maxactvp);
4388
                writeLine(indent, "MIRRTEXT", pDb.Mirrtext);
4389
                writeLine(indent, "ORTHOMODE", pDb.Orthomode);
4390
                writeLine(indent, "PDMODE", pDb.Pdmode);
4391
                writeLine(indent, "PDSIZE", pDb.Pdsize);
4392
                writeLine(indent, "PELEVATION", pDb.Pelevation);
4393
                writeLine(indent, "PELLIPSE", pDb.PlineEllipse);
4394
                writeLine(indent, "PEXTMAX", pDb.Pextmax);
4395
                writeLine(indent, "PEXTMIN", pDb.Pextmin);
4396
                writeLine(indent, "PINSBASE", pDb.Pinsbase);
4397
                writeLine(indent, "PLIMCHECK", pDb.Plimcheck);
4398
                writeLine(indent, "PLIMMAX", pDb.Plimmax);
4399
                writeLine(indent, "PLIMMIN", pDb.Plimmin);
4400
                writeLine(indent, "PLINEGEN", pDb.Plinegen);
4401
                writeLine(indent, "PLINEWID", pDb.Plinewid);
4402
                writeLine(indent, "PROXYGRAPHICS", pDb.Saveproxygraphics);
4403
                writeLine(indent, "PSLTSCALE", pDb.Psltscale);
4404
                writeLine(indent, "PUCSNAME", pDb.Pucsname);
4405
                writeLine(indent, "PUCSORG", pDb.Pucsorg);
4406
                writeLine(indent, "PUCSXDIR", pDb.Pucsxdir);
4407
                writeLine(indent, "PUCSYDIR", pDb.Pucsydir);
4408
                writeLine(indent, "QTEXTMODE", pDb.Qtextmode);
4409
                writeLine(indent, "REGENMODE", pDb.Regenmode);
4410
                writeLine(indent, "SHADEDGE", pDb.Shadedge);
4411
                writeLine(indent, "SHADEDIF", pDb.Shadedif);
4412
                writeLine(indent, "SKETCHINC", pDb.Sketchinc);
4413
                writeLine(indent, "SKPOLY", pDb.Skpoly);
4414
                writeLine(indent, "SPLFRAME", pDb.Splframe);
4415
                writeLine(indent, "SPLINESEGS", pDb.Splinesegs);
4416
                writeLine(indent, "SPLINETYPE", pDb.Splinetype);
4417
                writeLine(indent, "SURFTAB1", pDb.Surftab1);
4418
                writeLine(indent, "SURFTAB2", pDb.Surftab2);
4419
                writeLine(indent, "SURFTYPE", pDb.Surftype);
4420
                writeLine(indent, "SURFU", pDb.Surfu);
4421
                writeLine(indent, "SURFV", pDb.Surfv);
4422
                //writeLine(indent, "TEXTQLTY", pDb.TEXTQLTY);
4423
                writeLine(indent, "TEXTSIZE", pDb.Textsize);
4424
                writeLine(indent, "THICKNESS", pDb.Thickness);
4425
                writeLine(indent, "TILEMODE", pDb.TileMode);
4426
                writeLine(indent, "TRACEWID", pDb.Tracewid);
4427
                writeLine(indent, "TREEDEPTH", pDb.Treedepth);
4428
                writeLine(indent, "UCSNAME", pDb.Ucsname);
4429
                writeLine(indent, "UCSORG", pDb.Ucsorg);
4430
                writeLine(indent, "UCSXDIR", pDb.Ucsxdir);
4431
                writeLine(indent, "UCSYDIR", pDb.Ucsydir);
4432
                writeLine(indent, "UNITMODE", pDb.Unitmode);
4433
                writeLine(indent, "USERI1", pDb.Useri1);
4434
                writeLine(indent, "USERI2", pDb.Useri2);
4435
                writeLine(indent, "USERI3", pDb.Useri3);
4436
                writeLine(indent, "USERI4", pDb.Useri4);
4437
                writeLine(indent, "USERI5", pDb.Useri5);
4438
                writeLine(indent, "USERR1", pDb.Userr1);
4439
                writeLine(indent, "USERR2", pDb.Userr2);
4440
                writeLine(indent, "USERR3", pDb.Userr3);
4441
                writeLine(indent, "USERR4", pDb.Userr4);
4442
                writeLine(indent, "USERR5", pDb.Userr5);
4443
                writeLine(indent, "USRTIMER", pDb.Usrtimer);
4444
                writeLine(indent, "VISRETAIN", pDb.Visretain);
4445
                writeLine(indent, "WORLDVIEW", pDb.Worldview);
4446
            }
4447
        }
4448

    
4449
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4450
        {
4451
            if (node != null)
4452
            {
4453
                /**********************************************************************/
4454
                /* Get a SmartPointer to the LayerTable                               */
4455
                /**********************************************************************/
4456
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4457
                {
4458
                    /**********************************************************************/
4459
                    /* Dump the Description                                               */
4460
                    /**********************************************************************/
4461
                    XmlElement LayerNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4462

    
4463
                    /**********************************************************************/
4464
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4465
                    /**********************************************************************/
4466

    
4467
                    /**********************************************************************/
4468
                    /* Step through the LayerTable                                        */
4469
                    /**********************************************************************/
4470
                    foreach (ObjectId id in pTable)
4471
                    {
4472
                        /********************************************************************/
4473
                        /* Open the LayerTableRecord for Reading                            */
4474
                        /********************************************************************/
4475
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4476
                        {
4477
                            /********************************************************************/
4478
                            /* Dump the LayerTableRecord                                        */
4479
                            /********************************************************************/
4480
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4481

    
4482
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4483
                            NameAttr.Value = pRecord.Name.ToString();
4484
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4485

    
4486
                            XmlAttribute IsUsedAttr = Program.xml.CreateAttribute("IsUsed");
4487
                            IsUsedAttr.Value = pRecord.IsUsed.ToString();
4488
                            RecordNode.Attributes.SetNamedItem(IsUsedAttr);
4489

    
4490
                            XmlAttribute IsOffAttr = Program.xml.CreateAttribute("IsOff");
4491
                            IsOffAttr.Value = pRecord.IsOff.ToString();
4492
                            RecordNode.Attributes.SetNamedItem(IsOffAttr);
4493

    
4494
                            XmlAttribute IsFrozenAttr = Program.xml.CreateAttribute("IsFrozen");
4495
                            IsFrozenAttr.Value = pRecord.IsFrozen.ToString();
4496
                            RecordNode.Attributes.SetNamedItem(IsFrozenAttr);
4497

    
4498
                            XmlAttribute IsLockedAttr = Program.xml.CreateAttribute("IsLocked");
4499
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4500
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4501

    
4502
                            XmlAttribute ColorAttr = Program.xml.CreateAttribute("Color");
4503
                            ColorAttr.Value = pRecord.Color.ToString();
4504
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4505

    
4506
                            XmlAttribute LinetypeObjectIdAttr = Program.xml.CreateAttribute("LinetypeObjectId");
4507
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4508
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4509

    
4510
                            XmlAttribute LineWeightAttr = Program.xml.CreateAttribute("LineWeight");
4511
                            LineWeightAttr.Value = pRecord.LineWeight.ToString();
4512
                            RecordNode.Attributes.SetNamedItem(LineWeightAttr);
4513

    
4514
                            XmlAttribute PlotStyleNameAttr = Program.xml.CreateAttribute("PlotStyleName");
4515
                            PlotStyleNameAttr.Value = pRecord.PlotStyleName.ToString();
4516
                            RecordNode.Attributes.SetNamedItem(PlotStyleNameAttr);
4517

    
4518
                            XmlAttribute IsPlottableAttr = Program.xml.CreateAttribute("IsPlottable");
4519
                            IsPlottableAttr.Value = pRecord.IsPlottable.ToString();
4520
                            RecordNode.Attributes.SetNamedItem(IsPlottableAttr);
4521

    
4522
                            XmlAttribute ViewportVisibilityDefaultAttr = Program.xml.CreateAttribute("ViewportVisibilityDefault");
4523
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4524
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4525

    
4526
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4527
                            LayerNode.AppendChild(RecordNode);
4528
                        }
4529
                    }
4530

    
4531
                    node.AppendChild(LayerNode);
4532
                }
4533
            }
4534
        }
4535

    
4536
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4537
        {
4538
            if (node != null)
4539
            {
4540
                /**********************************************************************/
4541
                /* Get a pointer to the LinetypeTable                            */
4542
                /**********************************************************************/
4543
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4544
                {
4545
                    XmlElement LinetypeNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4546

    
4547
                    /**********************************************************************/
4548
                    /* Step through the LinetypeTable                                     */
4549
                    /**********************************************************************/
4550
                    foreach (ObjectId id in pTable)
4551
                    {
4552
                        /*********************************************************************/
4553
                        /* Open the LinetypeTableRecord for Reading                          */
4554
                        /*********************************************************************/
4555
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4556
                        {
4557
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4558

    
4559
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4560
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4561
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4562

    
4563
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4564
                            NameAttr.Value = pRecord.Name;
4565
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4566

    
4567
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4568
                            CommentsAttr.Value = pRecord.Comments;
4569
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4570

    
4571
                            /********************************************************************/
4572
                            /* Dump the first line of record as in ACAD.LIN                     */
4573
                            /********************************************************************/
4574
                            string buffer = "*" + pRecord.Name;
4575
                            if (pRecord.Comments != "")
4576
                            {
4577
                                buffer = buffer + "," + pRecord.Comments;
4578
                            }
4579
                            writeLine(indent, buffer);
4580

    
4581
                            /********************************************************************/
4582
                            /* Dump the second line of record as in ACAD.LIN                    */
4583
                            /********************************************************************/
4584
                            if (pRecord.NumDashes > 0)
4585
                            {
4586
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4587
                                for (int i = 0; i < pRecord.NumDashes; i++)
4588
                                {
4589
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4590
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4591
                                    string text = pRecord.TextAt(i);
4592

    
4593
                                    /**************************************************************/
4594
                                    /* Dump the Complex Line                                      */
4595
                                    /**************************************************************/
4596
                                    if (shapeNumber != 0 || text != "")
4597
                                    {
4598
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4599
                                        {
4600
                                            if (shapeNumber != 0)
4601
                                            {
4602
                                                buffer = buffer + ",[" + shapeNumber + ",";
4603
                                                if (pTextStyle != null)
4604
                                                    buffer = buffer + pTextStyle.FileName;
4605
                                                else
4606
                                                    buffer = buffer + "NULL style";
4607
                                            }
4608
                                            else
4609
                                            {
4610
                                                buffer = buffer + ",[" + text + ",";
4611
                                                if (pTextStyle != null)
4612
                                                    buffer = buffer + pTextStyle.Name;
4613
                                                else
4614
                                                    buffer = buffer + "NULL style";
4615
                                            }
4616
                                        }
4617

    
4618
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4619
                                        {
4620
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4621
                                        }
4622
                                        if (pRecord.ShapeRotationAt(i) != 0)
4623
                                        {
4624
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4625
                                        }
4626
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4627
                                        {
4628
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4629
                                        }
4630
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4631
                                        {
4632
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4633
                                        }
4634
                                        buffer = buffer + "]";
4635
                                    }
4636
                                }
4637
                                writeLine(indent, buffer);
4638
                            }
4639
                            dumpSymbolTableRecord(pRecord, indent, node);
4640
                            LinetypeNode.AppendChild(RecordNode);
4641
                        }
4642
                    }
4643

    
4644
                    node.AppendChild(LinetypeNode);
4645
                }
4646
            }
4647
        }
4648

    
4649
        public void dumpRegApps(Database pDb, int indent)
4650
        {
4651
            /**********************************************************************/
4652
            /* Get a pointer to the RegAppTable                            */
4653
            /**********************************************************************/
4654
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4655
            {
4656
                /**********************************************************************/
4657
                /* Dump the Description                                               */
4658
                /**********************************************************************/
4659
                writeLine();
4660
                writeLine(indent++, pTable.GetRXClass().Name);
4661

    
4662
                /**********************************************************************/
4663
                /* Step through the RegAppTable                                    */
4664
                /**********************************************************************/
4665
                foreach (ObjectId id in pTable)
4666
                {
4667
                    /*********************************************************************/
4668
                    /* Open the RegAppTableRecord for Reading                         */
4669
                    /*********************************************************************/
4670
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4671
                    {
4672
                        /*********************************************************************/
4673
                        /* Dump the RegAppTableRecord                                      */
4674
                        /*********************************************************************/
4675
                        writeLine();
4676
                        writeLine(indent, pRecord.GetRXClass().Name);
4677
                        writeLine(indent, "Name", pRecord.Name);
4678
                    }
4679
                }
4680
            }
4681
        }
4682

    
4683
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4684
        {
4685
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4686
            if (pRecord.IsDependent)
4687
            {
4688
                writeLine(indent, "Resolved", pRecord.IsResolved);
4689
            }
4690
        }
4691

    
4692
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4693
        {
4694
            /**********************************************************************/
4695
            /* Get a SmartPointer to the TextStyleTable                            */
4696
            /**********************************************************************/
4697
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4698
            {
4699
                /**********************************************************************/
4700
                /* Dump the Description                                               */
4701
                /**********************************************************************/
4702
                writeLine();
4703
                writeLine(indent++, pTable.GetRXClass().Name);
4704

    
4705
                /**********************************************************************/
4706
                /* Step through the TextStyleTable                                    */
4707
                /**********************************************************************/
4708
                foreach (ObjectId id in pTable)
4709
                {
4710
                    /*********************************************************************/
4711
                    /* Open the TextStyleTableRecord for Reading                         */
4712
                    /*********************************************************************/
4713
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4714
                    {
4715
                        /*********************************************************************/
4716
                        /* Dump the TextStyleTableRecord                                      */
4717
                        /*********************************************************************/
4718
                        writeLine();
4719
                        writeLine(indent, pRecord.GetRXClass().Name);
4720
                        writeLine(indent, "Name", pRecord.Name);
4721
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4722
                        writeLine(indent, "Text Height", pRecord.TextSize);
4723
                        writeLine(indent, "Width Factor", pRecord.XScale);
4724
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4725
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4726
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4727
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4728
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4729
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4730

    
4731
                        FontDescriptor fd = pRecord.Font;
4732
                        writeLine(indent, "Typeface", fd.TypeFace);
4733
                        writeLine(indent, "Character Set", fd.CharacterSet);
4734
                        writeLine(indent, "Bold", fd.Bold);
4735
                        writeLine(indent, "Italic", fd.Italic);
4736
                        writeLine(indent, "Font Pitch & Family", toHexString(fd.PitchAndFamily));
4737
                        dumpSymbolTableRecord(pRecord, indent, node);
4738
                    }
4739
                }
4740
            }
4741
        }
4742
        public void dumpAbstractViewTableRecord(AbstractViewTableRecord pView, int indent, XmlNode node)
4743
        {
4744
            /*********************************************************************/
4745
            /* Dump the AbstractViewTableRecord                                  */
4746
            /*********************************************************************/
4747
            writeLine(indent, "Back Clip Dist", pView.BackClipDistance);
4748
            writeLine(indent, "Back Clip Enabled", pView.BackClipEnabled);
4749
            writeLine(indent, "Front Clip Dist", pView.FrontClipDistance);
4750
            writeLine(indent, "Front Clip Enabled", pView.FrontClipEnabled);
4751
            writeLine(indent, "Front Clip at Eye", pView.FrontClipAtEye);
4752
            writeLine(indent, "Elevation", pView.Elevation);
4753
            writeLine(indent, "Height", pView.Height);
4754
            writeLine(indent, "Width", pView.Width);
4755
            writeLine(indent, "Lens Length", pView.LensLength);
4756
            writeLine(indent, "Render Mode", pView.RenderMode);
4757
            writeLine(indent, "Perspective", pView.PerspectiveEnabled);
4758
            writeLine(indent, "UCS Name", pView.UcsName);
4759

    
4760
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4761
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4762

    
4763
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4764
            {
4765
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4766
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4767
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4768
            }
4769

    
4770
            writeLine(indent, "Target", pView.Target);
4771
            writeLine(indent, "View Direction", pView.ViewDirection);
4772
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4773
            dumpSymbolTableRecord(pView, indent, node);
4774
        }
4775
        public void dumpDimAssoc(DBObject pObject, int indent)
4776
        {
4777

    
4778
        }
4779
        public void dumpMLineStyles(Database pDb, int indent)
4780
        {
4781
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4782
            {
4783
                /**********************************************************************/
4784
                /* Dump the Description                                               */
4785
                /**********************************************************************/
4786
                writeLine();
4787
                writeLine(indent++, pDictionary.GetRXClass().Name);
4788

    
4789
                /**********************************************************************/
4790
                /* Step through the MlineStyle dictionary                             */
4791
                /**********************************************************************/
4792
                DbDictionaryEnumerator e = pDictionary.GetEnumerator();
4793
                while (e.MoveNext())
4794
                {
4795
                    try
4796
                    {
4797
                        using (MlineStyle pEntry = (MlineStyle)e.Value.Open(OpenMode.ForRead))
4798
                        {
4799
                            /*********************************************************************/
4800
                            /* Dump the MLineStyle dictionary entry                              */
4801
                            /*********************************************************************/
4802
                            writeLine();
4803
                            writeLine(indent, pEntry.GetRXClass().Name);
4804
                            writeLine(indent, "Name", pEntry.Name);
4805
                            writeLine(indent, "Description", pEntry.Description);
4806
                            writeLine(indent, "Start Angle", toDegreeString(pEntry.StartAngle));
4807
                            writeLine(indent, "End Angle", toDegreeString(pEntry.EndAngle));
4808
                            writeLine(indent, "Start Inner Arcs", pEntry.StartInnerArcs);
4809
                            writeLine(indent, "End Inner Arcs", pEntry.EndInnerArcs);
4810
                            writeLine(indent, "Start Round Cap", pEntry.StartRoundCap);
4811
                            writeLine(indent, "End Round Cap", pEntry.EndRoundCap);
4812
                            writeLine(indent, "Start Square Cap", pEntry.StartRoundCap);
4813
                            writeLine(indent, "End Square Cap", pEntry.EndRoundCap);
4814
                            writeLine(indent, "Show Miters", pEntry.ShowMiters);
4815
                            /*********************************************************************/
4816
                            /* Dump the elements                                                 */
4817
                            /*********************************************************************/
4818
                            if (pEntry.Elements.Count > 0)
4819
                            {
4820
                                writeLine(indent, "Elements:");
4821
                            }
4822
                            int i = 0;
4823
                            foreach (MlineStyleElement el in pEntry.Elements)
4824
                            {
4825
                                writeLine(indent, "Index", (i++));
4826
                                writeLine(indent + 1, "Offset", el.Offset);
4827
                                writeLine(indent + 1, "Color", el.Color);
4828
                                writeLine(indent + 1, "Linetype", el.LinetypeId);
4829
                            }
4830
                        }
4831
                    }
4832
                    catch (System.Exception)
4833
                    {
4834
                    }
4835
                }
4836
            }
4837
        }
4838
        public void dumpObject(ObjectId id, string itemName, int indent)
4839
        {
4840
            using (DBObject pObject = id.Open(OpenMode.ForRead))
4841
            {
4842
                /**********************************************************************/
4843
                /* Dump the item name and class name                                  */
4844
                /**********************************************************************/
4845
                if (pObject is DBDictionary)
4846
                {
4847
                    writeLine();
4848
                }
4849
                writeLine(indent++, itemName, pObject.GetRXClass().Name);
4850

    
4851
                /**********************************************************************/
4852
                /* Dispatch                                                           */
4853
                /**********************************************************************/
4854
                if (pObject is DBDictionary)
4855
                {
4856
                    /********************************************************************/
4857
                    /* Dump the dictionary                                               */
4858
                    /********************************************************************/
4859
                    DBDictionary pDic = (DBDictionary)pObject;
4860

    
4861
                    /********************************************************************/
4862
                    /* Get a pointer to a new DictionaryIterator                   */
4863
                    /********************************************************************/
4864
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4865

    
4866
                    /********************************************************************/
4867
                    /* Step through the Dictionary                                      */
4868
                    /********************************************************************/
4869
                    while (pIter.MoveNext())
4870
                    {
4871
                        /******************************************************************/
4872
                        /* Dump the Dictionary object                                     */
4873
                        /******************************************************************/
4874
                        dumpObject(pIter.Value, pIter.Key, indent);
4875
                    }
4876
                }
4877
                else if (pObject is Xrecord)
4878
                {
4879
                    /********************************************************************/
4880
                    /* Dump an Xrecord                                                  */
4881
                    /********************************************************************/
4882
                    Xrecord pXRec = (Xrecord)pObject;
4883
                    dumpXdata(pXRec.Data, indent);
4884
                }
4885
            }
4886
        }
4887

    
4888
        public void dumpUCSTable(Database pDb, int indent, XmlNode node)
4889
        {
4890
            /**********************************************************************/
4891
            /* Get a pointer to the UCSTable                               */
4892
            /**********************************************************************/
4893
            using (UcsTable pTable = (UcsTable)pDb.UcsTableId.Open(OpenMode.ForRead))
4894
            {
4895
                /**********************************************************************/
4896
                /* Dump the Description                                               */
4897
                /**********************************************************************/
4898
                writeLine();
4899
                writeLine(indent++, pTable.GetRXClass().Name);
4900

    
4901
                /**********************************************************************/
4902
                /* Step through the UCSTable                                          */
4903
                /**********************************************************************/
4904
                foreach (ObjectId id in pTable)
4905
                {
4906
                    /********************************************************************/
4907
                    /* Open the UCSTableRecord for Reading                            */
4908
                    /********************************************************************/
4909
                    using (UcsTableRecord pRecord = (UcsTableRecord)id.Open(OpenMode.ForRead))
4910
                    {
4911
                        /********************************************************************/
4912
                        /* Dump the UCSTableRecord                                        */
4913
                        /********************************************************************/
4914
                        writeLine();
4915
                        writeLine(indent, pRecord.GetRXClass().Name);
4916
                        writeLine(indent, "Name", pRecord.Name);
4917
                        writeLine(indent, "UCS Origin", pRecord.Origin);
4918
                        writeLine(indent, "UCS x-Axis", pRecord.XAxis);
4919
                        writeLine(indent, "UCS y-Axis", pRecord.YAxis);
4920
                        dumpSymbolTableRecord(pRecord, indent, node);
4921
                    }
4922
                }
4923
            }
4924
        }
4925
        public void dumpViewports(Database pDb, int indent, XmlNode node)
4926
        {
4927
            /**********************************************************************/
4928
            /* Get a pointer to the ViewportTable                            */
4929
            /**********************************************************************/
4930
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4931
            {
4932
                /**********************************************************************/
4933
                /* Dump the Description                                               */
4934
                /**********************************************************************/
4935
                writeLine();
4936
                writeLine(indent++, pTable.GetRXClass().Name);
4937

    
4938
                /**********************************************************************/
4939
                /* Step through the ViewportTable                                    */
4940
                /**********************************************************************/
4941
                foreach (ObjectId id in pTable)
4942
                {
4943
                    /*********************************************************************/
4944
                    /* Open the ViewportTableRecord for Reading                          */
4945
                    /*********************************************************************/
4946
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4947
                    {
4948
                        /*********************************************************************/
4949
                        /* Dump the ViewportTableRecord                                      */
4950
                        /*********************************************************************/
4951
                        writeLine();
4952
                        writeLine(indent, pRecord.GetRXClass().Name);
4953
                        writeLine(indent, "Name", pRecord.Name);
4954
                        writeLine(indent, "Circle Sides", pRecord.CircleSides);
4955
                        writeLine(indent, "Fast Zooms Enabled", pRecord.FastZoomsEnabled);
4956
                        writeLine(indent, "Grid Enabled", pRecord.GridEnabled);
4957
                        writeLine(indent, "Grid Increments", pRecord.GridIncrements);
4958
                        writeLine(indent, "Icon at Origin", pRecord.IconAtOrigin);
4959
                        writeLine(indent, "Icon Enabled", pRecord.IconEnabled);
4960
                        writeLine(indent, "Iso snap Enabled", pRecord.IsometricSnapEnabled);
4961
                        writeLine(indent, "Iso Snap Pair", pRecord.SnapPair);
4962
                        writeLine(indent, "UCS Saved w/Vport", pRecord.UcsSavedWithViewport);
4963
                        writeLine(indent, "UCS follow", pRecord.UcsFollowMode);
4964
                        writeLine(indent, "Lower-Left Corner", pRecord.LowerLeftCorner);
4965
                        writeLine(indent, "Upper-Right Corner", pRecord.UpperRightCorner);
4966
                        writeLine(indent, "Snap Angle", toDegreeString(pRecord.SnapAngle));
4967
                        writeLine(indent, "Snap Base", pRecord.SnapBase);
4968
                        writeLine(indent, "Snap Enabled", pRecord.SnapEnabled);
4969
                        writeLine(indent, "Snap Increments", pRecord.SnapIncrements);
4970
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4971
                    }
4972
                }
4973
            }
4974
        }
4975

    
4976
        /************************************************************************/
4977
        /* Dump the ViewTable                                                   */
4978
        /************************************************************************/
4979
        public void dumpViews(Database pDb, int indent, XmlNode node)
4980
        {
4981
            /**********************************************************************/
4982
            /* Get a pointer to the ViewTable                                */
4983
            /**********************************************************************/
4984
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
4985
            {
4986
                /**********************************************************************/
4987
                /* Dump the Description                                               */
4988
                /**********************************************************************/
4989
                writeLine();
4990
                writeLine(indent++, pTable.GetRXClass().Name);
4991

    
4992
                /**********************************************************************/
4993
                /* Step through the ViewTable                                         */
4994
                /**********************************************************************/
4995
                foreach (ObjectId id in pTable)
4996
                {
4997
                    /*********************************************************************/
4998
                    /* Open the ViewTableRecord for Reading                              */
4999
                    /*********************************************************************/
5000
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
5001
                    {
5002
                        /*********************************************************************/
5003
                        /* Dump the ViewTableRecord                                          */
5004
                        /*********************************************************************/
5005
                        writeLine();
5006
                        writeLine(indent, pRecord.GetRXClass().Name);
5007
                        writeLine(indent, "Name", pRecord.Name);
5008
                        writeLine(indent, "Category Name", pRecord.CategoryName);
5009
                        writeLine(indent, "Layer State", pRecord.LayerState);
5010

    
5011
                        string layoutName = "";
5012
                        if (!pRecord.Layout.IsNull)
5013
                        {
5014
                            using (Layout pLayout = (Layout)pRecord.Layout.Open(OpenMode.ForRead))
5015
                                layoutName = pLayout.LayoutName;
5016
                        }
5017
                        writeLine(indent, "Layout Name", layoutName);
5018
                        writeLine(indent, "PaperSpace View", pRecord.IsPaperspaceView);
5019
                        writeLine(indent, "Associated UCS", pRecord.IsUcsAssociatedToView);
5020
                        writeLine(indent, "PaperSpace View", pRecord.ViewAssociatedToViewport);
5021
                        dumpAbstractViewTableRecord(pRecord, indent, node);
5022
                    }
5023
                }
5024
            }
5025
        }
5026
        /************************************************************************/
5027
        /* Dump Xdata                                                           */
5028
        /************************************************************************/
5029
        public void dumpXdata(ResultBuffer xIter, int indent)
5030
        {
5031
            if (xIter == null)
5032
                return;
5033
            writeLine(indent++, "Xdata:");
5034
            /**********************************************************************/
5035
            /* Step through the ResBuf chain                                      */
5036
            /**********************************************************************/
5037
            try
5038
            {
5039
                int rsCount = xIter.Cast<TypedValue>().Count();
5040
                
5041
                foreach (TypedValue resbuf in xIter)
5042
                {
5043
                    writeLine(indent, resbuf);
5044
                }
5045
            }
5046
            catch (System.Exception ex)
5047
            {
5048
            }
5049
            
5050
        }
5051
    }
5052
    class ExProtocolExtension
5053
    {
5054
    }
5055

    
5056
    class Program
5057
    {
5058
        public static XmlDocument xml = null;
5059
        public static double OffsetX = 0;
5060
        public static double OffsetY = 0;
5061
        public static double Scale = 0;
5062
        public static double getDrawing = 0;
5063
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
5064

    
5065
        static void Main(string[] args)
5066
        {
5067
            /********************************************************************/
5068
            /* Initialize Drawings.NET.                                         */
5069
            /********************************************************************/
5070
            bool bSuccess = true;
5071
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
5072
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
5073
            {
5074
                try
5075
                {
5076
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
5077
                    /**********************************************************************/
5078
                    /* Display the Product and Version that created the executable        */
5079
                    /**********************************************************************/
5080
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
5081

    
5082
                    if (args.Length != 5)
5083
                    {
5084
                        Console.WriteLine("\n\n\tusage: OdReadExMgd <filename> <OffsetX> <OffsetY> <Scale> <GenDrawing>");
5085
                        Console.WriteLine("\nPress ENTER to continue...\n");
5086
                        Console.ReadLine();
5087
                        bSuccess = false;
5088
                    }
5089
                    else
5090
                    {
5091
                        Console.WriteLine("\n File Name = " + args[0]);
5092

    
5093
                        double.TryParse(args[1], out Program.OffsetX);
5094
                        double.TryParse(args[2], out Program.OffsetY);
5095
                        double.TryParse(args[3], out Program.Scale);
5096
                        double.TryParse(args[4], out Program.getDrawing);
5097
                        Program.xml = new XmlDocument();
5098
                        {
5099
                            XmlNode root = xml.CreateElement("ID2");
5100
                            Program.xml.AppendChild(root);
5101

    
5102
                            /******************************************************************/
5103
                            /* Create a database and load the drawing into it.                
5104
                            /* first parameter means - do not initialize database- it will be read from file
5105
                             * second parameter is not used by Teigha.NET Classic - it is left for ARX compatibility.
5106
                             * Note the 'using' clause - generally, wrappers should disposed after use, 
5107
                             * to close underlying database objects
5108
                            /******************************************************************/
5109
                            string recoverPath = args[0];
5110
                            using (AuditInfo auditInfo = new AuditInfo())
5111
                            {
5112
                                auditInfo.FixErrors = true;
5113
                                Teigha.Runtime.FileStreamBuf streamBuf = new FileStreamBuf(args[0]);
5114
                                using (Database rDb = HostApplicationServices.Current.recoverFile(streamBuf, auditInfo, ""))
5115
                                {
5116
                                    int count = auditInfo.NumErrors;
5117
                                    string path = Path.GetDirectoryName(recoverPath);
5118
                                    recoverPath = Path.Combine(path, "Recover.Dwg");
5119
                                    rDb.SaveAs(recoverPath, rDb.OriginalFileVersion);
5120
                                }
5121
                            }
5122
                            using (Database pDb = new Database(false, false))
5123
                            {
5124
                                //pDb.ReadDwgFile(args[0], FileShare.Read, true, "");
5125
                                pDb.ReadDwgFile(recoverPath, FileShare.Read, true, "");
5126
                                HostApplicationServices.WorkingDatabase = pDb;
5127
                                /****************************************************************/
5128
                                /* Display the File Version                                     */
5129
                                /****************************************************************/
5130
                                Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion);
5131
                                /****************************************************************/
5132
                                /* Dump the database                                            */
5133
                                /****************************************************************/
5134
                                DbDumper dumper = new DbDumper();
5135
                                dumper.prepareDump(pDb);
5136
                                dumper.ExplodeAndPurgeNestedBlocks(pDb);
5137
                                if (Program.getDrawing == 1)
5138
                                {
5139
                                    dumper.ExportPNG(pDb, args[0]);
5140
                                    dumper.ExportPDF(pDb, args[0]);
5141
                                    dumper.ExportGraphicBlocks(pDb, args[0]);
5142
                                }
5143

    
5144
                                dumper.dump(pDb, 0, Program.xml.DocumentElement);
5145
                            }
5146
                            Program.xml.Save(Path.Combine(Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]) + ".xml"));
5147
                        }
5148
                    }
5149
                }
5150
                /********************************************************************/
5151
                /* Display the error                                                */
5152
                /********************************************************************/
5153
                catch (System.Exception e)
5154
                {
5155
                    bSuccess = false;
5156
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
5157
                }
5158

    
5159
                if (bSuccess)
5160
                    Console.WriteLine("OdReadExMgd Finished Successfully");
5161
            }
5162
        }
5163
    }
5164
}
클립보드 이미지 추가 (최대 크기: 500 MB)