프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / OdReadExMgd / OdReadExMgd.cs @ cad7f814

이력 | 보기 | 이력해설 | 다운로드 (251 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
                            dumpTextData(obj as DBText, indent, BlockReferenceNode);
503
                        }
504
                        else if (obj is MText)
505
                        {
506
                            MText mtext = obj as MText;
507

    
508
                            DBObjectCollection objs = new DBObjectCollection();
509
                            mtext.Explode(objs);
510
                            foreach (var item in objs)
511
                            {
512
                                dumpTextData(item as DBText, indent, BlockReferenceNode);
513
                            }
514
                        }
515
                    }
516
                }
517

    
518
                /**********************************************************************/
519
                /* Dump the attributes                                                */
520
                /**********************************************************************/
521
                int i = 0;
522
                AttributeCollection attCol = pBlkRef.AttributeCollection;
523
                foreach (ObjectId id in attCol)
524
                {
525
                    try
526
                    {
527
                        using (AttributeReference pAttr = (AttributeReference)id.Open(OpenMode.ForRead))
528
                            dumpAttributeData(indent, pAttr, i++, BlockReferenceNode);
529
                    }
530
                    catch (System.Exception)
531
                    {
532
                    }
533
                }
534

    
535
                node.AppendChild(BlockReferenceNode);
536

    
537
                return BlockReferenceNode;
538
            }
539

    
540
            return null;
541
        }
542
        /************************************************************************/
543
        /* Dump data common to all OdDbCurves                                   */
544
        /************************************************************************/
545
        static void dumpCurveData(Entity pEnt, int indent, XmlNode node)
546
        {
547
            if (node != null)
548
            {
549
                Curve pEntity = (Curve)pEnt;
550
                try
551
                {
552
                    writeLine(indent, "Start Point", pEntity.StartPoint);
553
                    writeLine(indent, "End Point", pEntity.EndPoint);
554
                }
555
                catch (System.Exception)
556
                {
557
                }
558
                writeLine(indent, "Closed", pEntity.Closed);
559
                writeLine(indent, "Periodic", pEntity.IsPeriodic);
560

    
561
                try
562
                {
563
                    writeLine(indent, "Area", pEntity.Area);
564
                }
565
                catch (System.Exception)
566
                {
567
                }
568
                dumpEntityData(pEntity, indent, node);
569
            }
570
        }
571

    
572
        /************************************************************************/
573
        /* Dump Dimension data                                                  */
574
        /************************************************************************/
575
        static XmlNode dumpDimData(Dimension pDim, int indent, XmlNode node)
576
        {
577
            if (node != null)
578
            {
579
                XmlElement DimDataNode = Program.xml.CreateElement("DimData");
580

    
581
                XmlAttribute CurrentMeasurementAttr = Program.xml.CreateAttribute("CurrentMeasurement");
582
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
583
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
584

    
585
                XmlAttribute DimensionTextAttr = Program.xml.CreateAttribute("DimensionText");
586
                DimensionTextAttr.Value = pDim.DimensionText.ToString();
587
                DimDataNode.Attributes.SetNamedItem(DimensionTextAttr);
588

    
589
                if (pDim.CurrentMeasurement >= 0.0)
590
                {
591
                    XmlAttribute FormattedMeasurementAttr = Program.xml.CreateAttribute("FormattedMeasurement");
592
                    FormattedMeasurementAttr.Value = pDim.FormatMeasurement(pDim.CurrentMeasurement, pDim.DimensionText);
593
                    DimDataNode.Attributes.SetNamedItem(FormattedMeasurementAttr);
594
                }
595
                if (pDim.DimBlockId.IsNull)
596
                {
597
                    writeLine(indent, "Dimension Block NULL");
598
                }
599
                else
600
                {
601
                    using (BlockTableRecord btr = (BlockTableRecord)pDim.DimBlockId.Open(OpenMode.ForRead))
602
                    {
603
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
604
                        NameAttr.Value = btr.Name;
605
                        DimDataNode.Attributes.SetNamedItem(NameAttr);
606
                    }
607
                }
608

    
609
                XmlAttribute DimBlockPositionAttr = Program.xml.CreateAttribute("DimBlockPosition");
610
                DimBlockPositionAttr.Value = pDim.DimBlockPosition.ToString();
611
                DimDataNode.Attributes.SetNamedItem(DimBlockPositionAttr);
612

    
613
                XmlAttribute TextPositionAttr = Program.xml.CreateAttribute("TextPosition");
614
                TextPositionAttr.Value = pDim.TextPosition.ToString();
615
                DimDataNode.Attributes.SetNamedItem(TextPositionAttr);
616

    
617
                XmlAttribute TextRotationAttr = Program.xml.CreateAttribute("TextRotation");
618
                TextRotationAttr.Value = pDim.TextRotation.ToString();
619
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
620

    
621
                XmlAttribute DimensionStyleNameAttr = Program.xml.CreateAttribute("DimensionStyleName");
622
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
623
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
624

    
625
                XmlAttribute DimtfillclrAttr = Program.xml.CreateAttribute("Dimtfillclr");
626
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
627
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
628

    
629
                XmlAttribute DimtfillAttr = Program.xml.CreateAttribute("Dimtfill");
630
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
631
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
632

    
633
                XmlAttribute Dimltex1Attr = Program.xml.CreateAttribute("Dimltex1");
634
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
635
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
636

    
637
                XmlAttribute Dimltex2Attr = Program.xml.CreateAttribute("Dimltex2");
638
                Dimltex2Attr.Value = pDim.Dimltex2.ToString();
639
                DimDataNode.Attributes.SetNamedItem(Dimltex2Attr);
640

    
641
                XmlAttribute DimltypeAttr = Program.xml.CreateAttribute("Dimltype");
642
                DimltypeAttr.Value = pDim.Dimltype.ToString();
643
                DimDataNode.Attributes.SetNamedItem(DimltypeAttr);
644

    
645
                XmlAttribute HorizontalRotationAttr = Program.xml.CreateAttribute("HorizontalRotation");
646
                HorizontalRotationAttr.Value = pDim.HorizontalRotation.ToString();
647
                DimDataNode.Attributes.SetNamedItem(HorizontalRotationAttr);
648

    
649
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
650
                ElevationAttr.Value = pDim.Elevation.ToString();
651
                DimDataNode.Attributes.SetNamedItem(ElevationAttr);
652

    
653
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
654
                NormalAttr.Value = pDim.Normal.ToString();
655
                DimDataNode.Attributes.SetNamedItem(NormalAttr);
656

    
657
                dumpEntityData(pDim, indent, node);
658

    
659
                return DimDataNode;
660
            }
661

    
662
            return null;
663
        }
664

    
665
        /************************************************************************/
666
        /* 2 Line Angular Dimension Dumper                                      */
667
        /************************************************************************/
668
        static XmlNode dump(LineAngularDimension2 pDim, int indent, XmlNode node)
669
        {
670
            if (node != null)
671
            {
672
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
673

    
674
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
675
                HandleAttr.Value = pDim.Handle.ToString();
676
                DimNode.Attributes.SetNamedItem(HandleAttr);
677

    
678
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
679
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
680
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
681

    
682
                XmlAttribute XLine1StartAttr = Program.xml.CreateAttribute("XLine1Start");
683
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
684
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
685

    
686
                XmlAttribute XLine1EndAttr = Program.xml.CreateAttribute("XLine1End");
687
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
688
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
689

    
690
                XmlAttribute XLine2StartAttr = Program.xml.CreateAttribute("XLine2Start");
691
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
692
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
693

    
694
                XmlAttribute XLine2EndAttr = Program.xml.CreateAttribute("XLine2End");
695
                XLine2EndAttr.Value = pDim.XLine2End.ToString();
696
                DimNode.Attributes.SetNamedItem(XLine2EndAttr);
697

    
698
                dumpDimData(pDim, indent, DimNode);
699

    
700
                return DimNode;
701
            }
702

    
703
            return null;
704
        }
705

    
706
        /************************************************************************/
707
        /* Dump 2D Vertex data                                                  */
708
        /************************************************************************/
709
        static XmlNode dump2dVertex(int indent, Vertex2d pVertex, int i, XmlNode node)
710
        {
711
            if (node != null)
712
            {
713
                XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
714

    
715
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
716
                HandleAttr.Value = pVertex.Handle.ToString();
717
                VertexNode.Attributes.SetNamedItem(HandleAttr);
718

    
719
                XmlAttribute VertexTypeAttr = Program.xml.CreateAttribute("VertexType");
720
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
721
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
722

    
723
                XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
724
                PositionAttr.Value = pVertex.Position.ToString();
725
                VertexNode.Attributes.SetNamedItem(PositionAttr);
726

    
727
                XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
728
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
729
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
730

    
731
                XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
732
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
733
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
734

    
735
                XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
736
                BulgeAttr.Value = pVertex.Bulge.ToString();
737
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
738

    
739
                if (pVertex.Bulge != 0)
740
                {
741
                    XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
742
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
743
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
744
                }
745

    
746
                XmlAttribute TangentUsedAttr = Program.xml.CreateAttribute("TangentUsed");
747
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
748
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
749
                if (pVertex.TangentUsed)
750
                {
751
                    XmlAttribute TangentAttr = Program.xml.CreateAttribute("Tangent");
752
                    TangentAttr.Value = pVertex.Tangent.ToString();
753
                    VertexNode.Attributes.SetNamedItem(TangentAttr);
754
                }
755

    
756
                node.AppendChild(VertexNode);
757

    
758
                return VertexNode;
759
            }
760

    
761
            return null;
762
        }
763

    
764
        /************************************************************************/
765
        /* 2D Polyline Dumper                                                   */
766
        /************************************************************************/
767
        static XmlNode dump(Polyline2d pPolyline, int indent, XmlNode node)
768
        {
769
            /********************************************************************/
770
            /* Dump the vertices                                                */
771
            /********************************************************************/
772
            Point3dCollection points = new Point3dCollection();
773

    
774
            int count = (int)pPolyline.EndParam + (pPolyline.Closed ? 0 : 1);
775
            for (int i = 0; i < count; i++)
776
            {
777
                points.Add(pPolyline.GetPointAtParameter(i));
778
            }
779
            
780
            if (node != null)
781
            {
782
                //XmlNode Polyline2dNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
783
                XmlNode Polyline2dNode = Program.xml.CreateElement("AcDbPolyline");
784

    
785
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
786
                HandleAttr.Value = pPolyline.Handle.ToString();
787
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
788

    
789
                XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
790
                CountAttr.Value = points.Count.ToString();
791
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
792

    
793
                XmlAttribute ElevationAttr = Program.xml.CreateAttribute("Elevation");
794
                ElevationAttr.Value = pPolyline.Elevation.ToString();
795
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
796

    
797
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
798
                NormalAttr.Value = pPolyline.Normal.ToString();
799
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
800

    
801
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
802
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
803
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
804

    
805
                XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
806
                ClosedAttr.Value = pPolyline.Closed.ToString();
807
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
808

    
809
                foreach (Point3d pt in points)
810
                {
811
                    XmlNode VertexNode = Program.xml.CreateElement("Vertex");
812

    
813
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
814
                    XAttr.Value = pt.X.ToString();
815
                    VertexNode.Attributes.SetNamedItem(XAttr);
816

    
817
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
818
                    YAttr.Value = pt.Y.ToString();
819
                    VertexNode.Attributes.SetNamedItem(YAttr);
820

    
821
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
822
                    ZAttr.Value = pt.Z.ToString();
823
                    VertexNode.Attributes.SetNamedItem(ZAttr);
824

    
825
                    Polyline2dNode.AppendChild(VertexNode);
826
                }
827

    
828
                dumpCurveData(pPolyline, indent, Polyline2dNode);
829

    
830
                node.AppendChild(Polyline2dNode);
831

    
832
                return Polyline2dNode;
833
            }
834

    
835
            return null;
836
        }
837

    
838

    
839
        /************************************************************************/
840
        /* Dump 3D Polyline Vertex data                                         */
841
        /************************************************************************/
842
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
843
        {
844
            if (node != null)
845
            {
846
                XmlNode VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
847

    
848
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
849
                HandleAttr.Value = pVertex.Handle.ToString();
850
                VertexNode.Attributes.SetNamedItem(HandleAttr);
851

    
852
                XmlAttribute VertexxTypeAttr = Program.xml.CreateAttribute("VertexType");
853
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
854
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
855

    
856
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
857
                XAttr.Value = pVertex.Position.X.ToString();
858
                VertexNode.Attributes.SetNamedItem(XAttr);
859

    
860
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
861
                YAttr.Value = pVertex.Position.Y.ToString();
862
                VertexNode.Attributes.SetNamedItem(YAttr);
863

    
864
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
865
                ZAttr.Value = pVertex.Position.Z.ToString();
866
                VertexNode.Attributes.SetNamedItem(ZAttr);
867

    
868
                node.AppendChild(VertexNode);
869

    
870
                return VertexNode;
871
            }
872

    
873
            return null;
874
        }
875

    
876
        /************************************************************************/
877
        /* 3D Polyline Dumper                                                   */
878
        /************************************************************************/
879
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
880
        {
881
            if (node != null)
882
            {
883
                XmlNode pPolylineNode = Program.xml.CreateElement(pPolyline.GetRXClass().Name);
884

    
885
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
886
                HandleAttr.Value = pPolyline.Handle.ToString();
887
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
888

    
889
                /********************************************************************/
890
                /* Dump the vertices                                                */
891
                /********************************************************************/
892
                int i = 0;
893
                foreach (ObjectId obj in pPolyline)
894
                {
895
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
896
                    {
897
                        if (dbObj is PolylineVertex3d)
898
                        {
899
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
900
                        }
901
                    }
902
                }
903
                dumpCurveData(pPolyline, indent, pPolylineNode);
904

    
905
                node.AppendChild(pPolylineNode);
906

    
907
                return pPolylineNode;
908
            }
909

    
910
            return null;
911
        }
912

    
913

    
914
        /************************************************************************/
915
        /* 3DSolid Dumper                                                       */
916
        /************************************************************************/
917
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
918
        {
919
            if (node != null)
920
            {
921
                XmlNode SolidNode = Program.xml.CreateElement(pSolid.GetRXClass().Name);
922

    
923
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
924
                HandleAttr.Value = pSolid.Handle.ToString();
925
                SolidNode.Attributes.SetNamedItem(HandleAttr);
926

    
927
                dumpEntityData(pSolid, indent, node);
928

    
929
                node.AppendChild(SolidNode);
930

    
931
                return SolidNode;
932
            }
933

    
934
            return null;
935
        }
936

    
937

    
938
        /************************************************************************/
939
        /* 3 Point Angular Dimension Dumper                                     */
940
        /************************************************************************/
941
        XmlNode dump(Point3AngularDimension pDim, int indent, XmlNode node)
942
        {
943
            if (node != null)
944
            {
945
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
946

    
947
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
948
                HandleAttr.Value = pDim.Handle.ToString();
949
                DimNode.Attributes.SetNamedItem(HandleAttr);
950

    
951
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
952
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
953
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
954

    
955
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
956
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
957
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
958

    
959
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
960
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
961
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
962

    
963
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
964
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
965
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
966

    
967
                dumpDimData(pDim, indent, DimNode);
968

    
969
                return DimNode;
970
            }
971

    
972
            return null;
973
        }
974

    
975
        /************************************************************************/
976
        /* Aligned Dimension Dumper                                             */
977
        /************************************************************************/
978
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
979
        {
980
            if (node != null)
981
            {
982
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
983

    
984
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
985
                HandleAttr.Value = pDim.Handle.ToString();
986
                DimNode.Attributes.SetNamedItem(HandleAttr);
987

    
988
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
989
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
990
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
991

    
992
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
993
                ObliqueAttr.Value = pDim.Oblique.ToString();
994
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
995

    
996
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
997
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
998
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
999

    
1000
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1001
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1002
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1003

    
1004
                dumpDimData(pDim, indent, DimNode);
1005

    
1006
                return DimNode;
1007
            }
1008

    
1009
            return null;
1010
        }
1011

    
1012
        /************************************************************************/
1013
        /* Arc Dumper                                                           */
1014
        /************************************************************************/
1015
        XmlNode dump(Arc pArc, int indent, XmlNode node)
1016
        {
1017
            if (node != null)
1018
            {
1019
                XmlElement ArcNode = Program.xml.CreateElement(pArc.GetRXClass().Name);
1020

    
1021
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1022
                XAttr.Value = pArc.Center.X.ToString();
1023
                ArcNode.Attributes.SetNamedItem(XAttr);
1024

    
1025
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1026
                YAttr.Value = pArc.Center.Y.ToString();
1027
                ArcNode.Attributes.SetNamedItem(YAttr);
1028

    
1029
                XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1030
                ZAttr.Value = pArc.Center.Z.ToString();
1031
                ArcNode.Attributes.SetNamedItem(ZAttr);
1032

    
1033
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1034
                RadiusAttr.Value = pArc.Radius.ToString();
1035
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
1036

    
1037
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1038
                StartAngleAttr.Value = pArc.StartAngle.ToString();
1039
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
1040

    
1041
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1042
                EndAngleAttr.Value = pArc.EndAngle.ToString();
1043
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
1044

    
1045
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1046
                NormalAttr.Value = pArc.Normal.ToString();
1047
                ArcNode.Attributes.SetNamedItem(NormalAttr);
1048

    
1049
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1050
                ThicknessAttr.Value = pArc.Normal.ToString();
1051
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
1052

    
1053
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
1054
                dumpCurveData(pArc, indent, ArcNode);
1055

    
1056
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1057
                {
1058
                    XAttr = Program.xml.CreateAttribute("X");
1059
                    XAttr.Value = pArc.StartPoint.X.ToString();
1060
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1061

    
1062
                    YAttr = Program.xml.CreateAttribute("Y");
1063
                    YAttr.Value = pArc.StartPoint.Y.ToString();
1064
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1065

    
1066
                    ZAttr = Program.xml.CreateAttribute("Z");
1067
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
1068
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1069
                }
1070
                ArcNode.AppendChild(StartPointNode);
1071

    
1072
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1073
                {
1074
                    XAttr = Program.xml.CreateAttribute("X");
1075
                    XAttr.Value = pArc.EndPoint.X.ToString();
1076
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1077

    
1078
                    YAttr = Program.xml.CreateAttribute("Y");
1079
                    YAttr.Value = pArc.EndPoint.Y.ToString();
1080
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1081

    
1082
                    ZAttr = Program.xml.CreateAttribute("Z");
1083
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1084
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1085
                }
1086
                ArcNode.AppendChild(EndPointNode);
1087

    
1088
                node.AppendChild(ArcNode);
1089

    
1090
                return ArcNode;
1091
            }
1092

    
1093
            return null;
1094
        }
1095

    
1096
        /************************************************************************/
1097
        /* Arc Dimension Dumper                                                 */
1098
        /************************************************************************/
1099
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
1100
        {
1101
            if (node != null)
1102
            {
1103
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1104

    
1105
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1106
                HandleAttr.Value = pDim.Handle.ToString();
1107
                DimNode.Attributes.SetNamedItem(HandleAttr);
1108

    
1109
                XmlAttribute ArcPointAttr = Program.xml.CreateAttribute("ArcPoint");
1110
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
1111
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
1112

    
1113
                XmlAttribute CenterPointAttr = Program.xml.CreateAttribute("CenterPoint");
1114
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
1115
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
1116

    
1117
                XmlAttribute ArcSymbolTypeAttr = Program.xml.CreateAttribute("ArcSymbolType");
1118
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1119
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1120

    
1121
                XmlAttribute IsPartialAttr = Program.xml.CreateAttribute("IsPartial");
1122
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1123
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1124

    
1125
                XmlAttribute HasLeaderAttr = Program.xml.CreateAttribute("HasLeader");
1126
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1127
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1128

    
1129
                if (pDim.HasLeader)
1130
                {
1131
                    XmlAttribute Leader1PointAttr = Program.xml.CreateAttribute("Leader1Point");
1132
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1133
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1134

    
1135
                    XmlAttribute Leader2PointAttr = Program.xml.CreateAttribute("Leader2Point");
1136
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1137
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1138
                }
1139

    
1140
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
1141
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1142
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1143

    
1144
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
1145
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1146
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1147

    
1148
                dumpDimData(pDim, indent, DimNode);
1149

    
1150
                return DimNode;
1151
            }
1152

    
1153
            return null;
1154
        }
1155

    
1156

    
1157
        /************************************************************************/
1158
        /* Block Reference Dumper                                                */
1159
        /************************************************************************/
1160
        void dump(BlockReference pBlkRef, int indent, XmlNode node)
1161
        {
1162
            using (BlockTableRecord pRecord = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead))
1163
            {
1164
                XmlNode BlockRefNode = dumpBlockRefData(pBlkRef, indent, node);
1165
                if (BlockRefNode != null)
1166
                {
1167
                    XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
1168
                    NameAttr.Value = pRecord.Name;
1169
                    BlockRefNode.Attributes.SetNamedItem(NameAttr);
1170
                }
1171
            }
1172
        }
1173

    
1174
        /************************************************************************/
1175
        /* Body Dumper                                                          */
1176
        /************************************************************************/
1177
        XmlNode dump(Body pBody, int indent, XmlNode node)
1178
        {
1179
            if (node != null)
1180
            {
1181
                XmlNode BodyNode = Program.xml.CreateElement(pBody.GetRXClass().Name);
1182

    
1183
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1184
                HandleAttr.Value = pBody.Handle.ToString();
1185
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1186

    
1187
                dumpEntityData(pBody, indent, BodyNode);
1188

    
1189
                return BodyNode;
1190
            }
1191

    
1192
            return null;
1193
        }
1194

    
1195

    
1196
        /************************************************************************/
1197
        /* Circle Dumper                                                        */
1198
        /************************************************************************/
1199
        XmlNode dump(Circle pCircle, int indent, XmlNode node)
1200
        {
1201
            if (node != null)
1202
            {
1203
                XmlElement CircleNode = Program.xml.CreateElement(pCircle.GetRXClass().Name);
1204

    
1205
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1206
                XAttr.Value = pCircle.Center.X.ToString();
1207
                CircleNode.Attributes.SetNamedItem(XAttr);
1208

    
1209
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1210
                YAttr.Value = pCircle.Center.Y.ToString();
1211
                CircleNode.Attributes.SetNamedItem(YAttr);
1212

    
1213
                XmlAttribute RadiusAttr = Program.xml.CreateAttribute("Radius");
1214
                RadiusAttr.Value = pCircle.Radius.ToString();
1215
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1216

    
1217
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1218
                NormalAttr.Value = pCircle.Normal.ToString();
1219
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1220

    
1221
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1222
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1223
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1224

    
1225
                dumpCurveData(pCircle, indent, CircleNode);
1226

    
1227
                node.AppendChild(CircleNode);
1228

    
1229
                return CircleNode;
1230
            }
1231

    
1232
            return null;
1233
        }
1234

    
1235
        /************************************************************************/
1236
        /* Diametric Dimension Dumper                                           */
1237
        /************************************************************************/
1238
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1239
        {
1240
            if (node != null)
1241
            {
1242
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1243

    
1244
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1245
                HandleAttr.Value = pDim.Handle.ToString();
1246
                DimNode.Attributes.SetNamedItem(HandleAttr);
1247

    
1248
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
1249
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1250
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1251

    
1252
                XmlAttribute FarChordPointAttr = Program.xml.CreateAttribute("FarChordPoint");
1253
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1254
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1255

    
1256
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
1257
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1258
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1259

    
1260
                dumpDimData(pDim, indent, DimNode);
1261

    
1262
                return DimNode;
1263
            }
1264

    
1265
            return null;
1266
        }
1267

    
1268
        /************************************************************************/
1269
        /* Ellipse Dumper                                                       */
1270
        /************************************************************************/
1271
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1272
        {
1273
            if (node != null)
1274
            {
1275
                XmlElement EllipseNode = Program.xml.CreateElement(pEllipse.GetRXClass().Name);
1276

    
1277
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1278

    
1279
                XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1280
                XAttr.Value = pEllipse.Center.X.ToString();
1281
                EllipseNode.Attributes.SetNamedItem(XAttr);
1282

    
1283
                XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1284
                YAttr.Value = pEllipse.Center.Y.ToString();
1285
                EllipseNode.Attributes.SetNamedItem(YAttr);
1286

    
1287
                XmlAttribute MajorAxisAttr = Program.xml.CreateAttribute("MajorAxis");
1288
                MajorAxisAttr.Value = pEllipse.MajorAxis.ToString();
1289
                EllipseNode.Attributes.SetNamedItem(MajorAxisAttr);
1290

    
1291
                XmlAttribute MinorAxisAttr = Program.xml.CreateAttribute("MinorAxis");
1292
                MinorAxisAttr.Value = pEllipse.MinorAxis.ToString();
1293
                EllipseNode.Attributes.SetNamedItem(MinorAxisAttr);
1294

    
1295
                XmlAttribute MajorRadiusAttr = Program.xml.CreateAttribute("MajorRadius");
1296
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1297
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1298

    
1299
                XmlAttribute MinorRadiusAttr = Program.xml.CreateAttribute("MinorRadius");
1300
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1301
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1302

    
1303
                XmlAttribute RadiusRatioAttr = Program.xml.CreateAttribute("RadiusRatio");
1304
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1305
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1306

    
1307
                XmlAttribute StartAngleAttr = Program.xml.CreateAttribute("StartAngle");
1308
                StartAngleAttr.Value = pEllipse.StartAngle.ToString();
1309
                EllipseNode.Attributes.SetNamedItem(StartAngleAttr);
1310

    
1311
                XmlAttribute EndAngleAttr = Program.xml.CreateAttribute("EndAngle");
1312
                EndAngleAttr.Value = pEllipse.EndAngle.ToString();
1313
                EllipseNode.Attributes.SetNamedItem(EndAngleAttr);
1314

    
1315
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1316
                NormalAttr.Value = pEllipse.Normal.ToString();
1317
                EllipseNode.Attributes.SetNamedItem(NormalAttr);
1318

    
1319
                dumpCurveData(pEllipse, indent, EllipseNode);
1320

    
1321
                node.AppendChild(EllipseNode);
1322
            }
1323
        }
1324

    
1325
        /************************************************************************/
1326
        /* Face Dumper                                                       */
1327
        /************************************************************************/
1328
        XmlNode dump(Face pFace, int indent, XmlNode node)
1329
        {
1330
            if (node != null)
1331
            {
1332
                XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1333

    
1334
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1335
                HandleAttr.Value = pFace.Handle.ToString();
1336
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1337

    
1338
                for (short i = 0; i < 4; i++)
1339
                {
1340
                    XmlElement VertexNode = Program.xml.CreateElement("Vertex");
1341

    
1342
                    Point3d pt = pFace.GetVertexAt(i);
1343
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1344
                    XAttr.Value = pt.X.ToString();
1345
                    VertexNode.Attributes.SetNamedItem(XAttr);
1346

    
1347
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1348
                    YAttr.Value = pt.Y.ToString();
1349
                    VertexNode.Attributes.SetNamedItem(YAttr);
1350

    
1351
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1352
                    ZAttr.Value = pt.Z.ToString();
1353
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1354

    
1355
                    XmlAttribute VisibleAttr = Program.xml.CreateAttribute("Visible");
1356
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1357
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1358

    
1359
                    FaceNode.AppendChild(VertexNode);
1360
                }
1361
                dumpEntityData(pFace, indent, FaceNode);
1362

    
1363
                node.AppendChild(FaceNode);
1364

    
1365
                return FaceNode;
1366
            }
1367

    
1368
            return null;
1369
        }
1370

    
1371
        /************************************************************************/
1372
        /* FCF Dumper                                                           */
1373
        /************************************************************************/
1374
        void dump(FeatureControlFrame pFcf, int indent)
1375
        {
1376
            writeLine(indent++, pFcf.GetRXClass().Name, pFcf.Handle);
1377
            writeLine(indent, "Location", pFcf.Location);
1378
            writeLine(indent, "Text", pFcf.Text);
1379
            writeLine(indent, "Dimension Style", pFcf.DimensionStyleName);
1380
            writeLine(indent, "Dimension Gap", pFcf.Dimgap);
1381
            writeLine(indent, "Dimension Scale", pFcf.Dimscale);
1382
            writeLine(indent, "Text Height", pFcf.Dimtxt);
1383
            writeLine(indent, "Frame Color", pFcf.Dimclrd);
1384
            writeLine(indent, "Text Style", pFcf.TextStyleName);
1385
            writeLine(indent, "Text Color", pFcf.Dimclrd);
1386
            writeLine(indent, "X-Direction", pFcf.Direction);
1387
            writeLine(indent, "Normal", pFcf.Normal);
1388
            dumpEntityData(pFcf, indent, Program.xml.DocumentElement);
1389
        }
1390

    
1391
        /************************************************************************/
1392
        /* Hatch Dumper                                                         */
1393
        /************************************************************************/
1394
        /***********************************************************************/
1395
        /* Dump Polyline Loop                                                  */
1396
        /***********************************************************************/
1397
        static void dumpPolylineType(int loopIndex, Hatch pHatch, int indent)
1398
        {
1399
            HatchLoop hl = pHatch.GetLoopAt(loopIndex);
1400
            for (int i = 0; i < hl.Polyline.Count; i++)
1401
            {
1402
                BulgeVertex bv = hl.Polyline[i];
1403
                writeLine(indent, "Vertex " + i.ToString(), bv.Vertex.ToString());
1404
                writeLine(indent + 1, "Bulge " + i.ToString(), bv.Bulge);
1405
                writeLine(indent + 1, "Bulge angle " + i.ToString(), toDegreeString(4 * Math.Atan(bv.Bulge)));
1406
            }
1407
        }
1408

    
1409
        /**********************************************************************/
1410
        /* Dump Circular Arc Edge                                             */
1411
        /**********************************************************************/
1412
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1413
        {
1414
            writeLine(indent, "Center", pCircArc.Center);
1415
            writeLine(indent, "Radius", pCircArc.Radius);
1416
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1417
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1418
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1419
        }
1420

    
1421
        /**********************************************************************/
1422
        /* Dump Elliptical Arc Edge                                           */
1423
        /**********************************************************************/
1424
        static void dumpEllipticalArcEdge(int indent, EllipticalArc2d pEllipArc)
1425
        {
1426
            writeLine(indent, "Center", pEllipArc.Center);
1427
            writeLine(indent, "Major Radius", pEllipArc.MajorRadius);
1428
            writeLine(indent, "Minor Radius", pEllipArc.MinorRadius);
1429
            writeLine(indent, "Major Axis", pEllipArc.MajorAxis);
1430
            writeLine(indent, "Minor Axis", pEllipArc.MinorAxis);
1431
            writeLine(indent, "Start Angle", toDegreeString(pEllipArc.StartAngle));
1432
            writeLine(indent, "End Angle", toDegreeString(pEllipArc.EndAngle));
1433
            writeLine(indent, "Clockwise", pEllipArc.IsClockWise);
1434
        }
1435

    
1436
        /**********************************************************************/
1437
        /* Dump NurbCurve Edge                                           */
1438
        /**********************************************************************/
1439
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1440
        {
1441
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1442
            writeLine(indent, "Degree", d.Degree);
1443
            writeLine(indent, "Rational", d.Rational);
1444
            writeLine(indent, "Periodic", d.Periodic);
1445

    
1446
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1447
            for (int i = 0; i < d.ControlPoints.Count; i++)
1448
            {
1449
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1450
            }
1451
            writeLine(indent, "Number of Knots", d.Knots.Count);
1452
            for (int i = 0; i < d.Knots.Count; i++)
1453
            {
1454
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1455
            }
1456

    
1457
            if (d.Rational)
1458
            {
1459
                writeLine(indent, "Number of Weights", d.Weights.Count);
1460
                for (int i = 0; i < d.Weights.Count; i++)
1461
                {
1462
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1463
                }
1464
            }
1465
        }
1466

    
1467
        /***********************************************************************/
1468
        /* Dump Edge Loop                                                      */
1469
        /***********************************************************************/
1470
        static void dumpEdgesType(int loopIndex, Hatch pHatch, int indent)
1471
        {
1472
            Curve2dCollection edges = pHatch.GetLoopAt(loopIndex).Curves;
1473
            for (int i = 0; i < (int)edges.Count; i++)
1474
            {
1475
                using (Curve2d pEdge = edges[i])
1476
                {
1477
                    writeLine(indent, string.Format("Edge {0}", i), pEdge.GetType().Name);
1478
                    switch (pEdge.GetType().Name)
1479
                    {
1480
                        case "LineSegment2d":
1481
                            break;
1482
                        case "CircularArc2d":
1483
                            dumpCircularArcEdge(indent + 1, (CircularArc2d)pEdge);
1484
                            break;
1485
                        case "EllipticalArc2d":
1486
                            dumpEllipticalArcEdge(indent + 1, (EllipticalArc2d)pEdge);
1487
                            break;
1488
                        case "NurbCurve2d":
1489
                            dumpNurbCurveEdge(indent + 1, (NurbCurve2d)pEdge);
1490
                            break;
1491
                    }
1492

    
1493
                    /******************************************************************/
1494
                    /* Common Edge Properties                                         */
1495
                    /******************************************************************/
1496
                    Interval interval = pEdge.GetInterval();
1497
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1498
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1499
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1500
                }
1501
            }
1502
        }
1503

    
1504
        /************************************************************************/
1505
        /* Convert the specified value to a LoopType string                     */
1506
        /************************************************************************/
1507
        string toLooptypeString(HatchLoopTypes loopType)
1508
        {
1509
            string retVal = "";
1510
            if ((loopType & HatchLoopTypes.External) != 0)
1511
                retVal = retVal + " | kExternal";
1512

    
1513
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1514
                retVal = retVal + " | kPolyline";
1515

    
1516
            if ((loopType & HatchLoopTypes.Derived) != 0)
1517
                retVal = retVal + " | kDerived";
1518

    
1519
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1520
                retVal = retVal + " | kTextbox";
1521

    
1522
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1523
                retVal = retVal + " | kOutermost";
1524

    
1525
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1526
                retVal = retVal + " | kNotClosed";
1527

    
1528
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1529
                retVal = retVal + " | kSelfIntersecting";
1530

    
1531
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1532
                retVal = retVal + " | kTextIsland";
1533

    
1534
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1535
                retVal = retVal + " | kDuplicate";
1536

    
1537
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1538
        }
1539

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

    
1616
            /********************************************************************/
1617
            /* Dump Associated Objects                                          */
1618
            /********************************************************************/
1619
            writeLine(indent, "Associated objects", pHatch.Associative);
1620
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1621
            {
1622
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1623
            }
1624

    
1625
            /********************************************************************/
1626
            /* Dump Loops                                                       */
1627
            /********************************************************************/
1628
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1629
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1630
            {
1631
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1632

    
1633
                /******************************************************************/
1634
                /* Dump Loop                                                      */
1635
                /******************************************************************/
1636
                if ((pHatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) != 0)
1637
                {
1638
                    dumpPolylineType(i, pHatch, indent + 2);
1639
                }
1640
                else
1641
                {
1642
                    dumpEdgesType(i, pHatch, indent + 2);
1643
                }
1644
                /******************************************************************/
1645
                /* Dump Associated Objects                                        */
1646
                /******************************************************************/
1647
                if (pHatch.Associative)
1648
                {
1649
                    writeLine(indent + 2, "Associated objects");
1650
                    foreach (ObjectId id in pHatch.GetAssociatedObjectIdsAt(i))
1651
                    {
1652
                        writeLine(indent + 3, id.ObjectClass.Name, id.Handle);
1653
                    }
1654
                }
1655
            }
1656

    
1657
            writeLine(indent, "Elevation", pHatch.Elevation);
1658
            writeLine(indent, "Normal", pHatch.Normal);
1659
            dumpEntityData(pHatch, indent, Program.xml.DocumentElement);
1660
        }
1661

    
1662
        /************************************************************************/
1663
        /* Leader Dumper                                                          */
1664
        /************************************************************************/
1665
        void dump(Leader pLeader, int indent)
1666
        {
1667
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1668
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1669

    
1670
            writeLine(indent, "Annotation");
1671
            if (!pLeader.Annotation.IsNull)
1672
            {
1673
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1674
            }
1675
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1676
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1677
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1678
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1679
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1680
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1681
            writeLine(indent, "Splined", pLeader.IsSplined);
1682

    
1683
            for (int i = 0; i < pLeader.NumVertices; i++)
1684
            {
1685
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1686
            }
1687
            writeLine(indent, "Normal", pLeader.Normal);
1688
            dumpCurveData(pLeader, indent, Program.xml.DocumentElement);
1689
        }
1690

    
1691
        /************************************************************************/
1692
        /* Line Dumper                                                          */
1693
        /************************************************************************/
1694
        void dump(Line pLine, int indent, XmlNode node)
1695
        {
1696
            if (node != null && pLine != null && pLine.Length != 0)
1697
            {
1698
                XmlNode LineNode = Program.xml.CreateElement(pLine.GetRXClass().Name);
1699
                XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
1700
                LengthAttr.Value = pLine.Length.ToString();
1701
                LineNode.Attributes.SetNamedItem(LengthAttr);
1702

    
1703
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1704
                HandleAttr.Value = pLine.Handle.ToString();
1705
                LineNode.Attributes.SetNamedItem(HandleAttr);
1706

    
1707
                XmlNode StartPointNode = Program.xml.CreateElement("Vertex");
1708
                {
1709
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1710
                    XAttr.Value = pLine.StartPoint.X.ToString();
1711
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1712

    
1713
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1714
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1715
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1716

    
1717
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1718
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1719
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1720
                }
1721
                LineNode.AppendChild(StartPointNode);
1722

    
1723
                XmlNode EndPointNode = Program.xml.CreateElement("Vertex");
1724
                {
1725
                    XmlAttribute XAttr = Program.xml.CreateAttribute("X");
1726
                    XAttr.Value = pLine.EndPoint.X.ToString();
1727
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1728

    
1729
                    XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
1730
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1731
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1732

    
1733
                    XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
1734
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1735
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1736
                }
1737
                LineNode.AppendChild(EndPointNode);
1738

    
1739
                XmlAttribute NormalAttr = Program.xml.CreateAttribute("Normal");
1740
                NormalAttr.Value = pLine.Normal.ToString();
1741
                LineNode.Attributes.SetNamedItem(NormalAttr);
1742

    
1743
                XmlAttribute ThicknessAttr = Program.xml.CreateAttribute("Thickness");
1744
                ThicknessAttr.Value = pLine.Thickness.ToString();
1745
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1746

    
1747
                dumpEntityData(pLine, indent, LineNode);
1748

    
1749
                node.AppendChild(LineNode);
1750
            }
1751
            else
1752
            {
1753
                int d = 0;
1754
            }
1755
        }
1756

    
1757
        /************************************************************************/
1758
        /* MInsertBlock Dumper                                                  */
1759
        /************************************************************************/
1760
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1761
        {
1762
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1763

    
1764
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1765
            {
1766
                writeLine(indent, "Name", pRecord.Name);
1767
                writeLine(indent, "Rows", pMInsert.Rows);
1768
                writeLine(indent, "Columns", pMInsert.Columns);
1769
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1770
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1771
                dumpBlockRefData(pMInsert, indent, node);
1772
            }
1773
        }
1774

    
1775
        /************************************************************************/
1776
        /* Mline Dumper                                                         */
1777
        /************************************************************************/
1778
        void dump(Mline pMline, int indent)
1779
        {
1780
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1781
            writeLine(indent, "Style", pMline.Style);
1782
            writeLine(indent, "Closed", pMline.IsClosed);
1783
            writeLine(indent, "Scale", pMline.Scale);
1784
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1785
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1786
            writeLine(indent, "Normal", pMline.Normal);
1787

    
1788
            /********************************************************************/
1789
            /* Dump the segment data                                            */
1790
            /********************************************************************/
1791
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1792
            {
1793
                writeLine(indent, "Segment", i);
1794
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1795
            }
1796
            dumpEntityData(pMline, indent, Program.xml.DocumentElement);
1797
        }
1798

    
1799
        /************************************************************************/
1800
        /* MText Dumper                                                         */
1801
        /************************************************************************/
1802
        /// <summary>
1803
        /// convert MText to normal Text
1804
        /// </summary>
1805
        /// <param name="pMText"></param>
1806
        /// <param name="indent"></param>
1807
        /// <param name="node"></param>
1808
        void dump(MText pMText, int indent, XmlNode node)
1809
        {
1810
            DBObjectCollection objColl = new DBObjectCollection();
1811
            pMText.Explode(objColl);
1812
            foreach (var obj in objColl)
1813
            {
1814
                dumpTextData(obj as DBText, indent, node);
1815
            }
1816
        }
1817

    
1818
        /************************************************************************/
1819
        /* Ordinate Dimension Dumper                                            */
1820
        /************************************************************************/
1821
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1822
        {
1823
            if (node != null)
1824
            {
1825
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
1826

    
1827
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1828
                HandleAttr.Value = pDim.Handle.ToString();
1829
                DimNode.Attributes.SetNamedItem(HandleAttr);
1830

    
1831
                XmlAttribute DefiningPointAttr = Program.xml.CreateAttribute("DefiningPoint");
1832
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1833
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1834

    
1835
                XmlAttribute UsingXAxisAttr = Program.xml.CreateAttribute("UsingXAxis");
1836
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1837
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1838

    
1839
                XmlAttribute UsingYAxisAttr = Program.xml.CreateAttribute("UsingYAxis");
1840
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1841
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1842

    
1843
                XmlAttribute LeaderEndPointAttr = Program.xml.CreateAttribute("LeaderEndPoint");
1844
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1845
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1846

    
1847
                XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
1848
                OriginAttr.Value = pDim.Origin.ToString();
1849
                DimNode.Attributes.SetNamedItem(OriginAttr);
1850

    
1851
                dumpDimData(pDim, indent, DimNode);
1852

    
1853
                return DimNode;
1854
            }
1855

    
1856
            return null;
1857
        }
1858

    
1859
        /************************************************************************/
1860
        /* PolyFaceMesh Dumper                                                  */
1861
        /************************************************************************/
1862
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1863
        {
1864
            if (node != null)
1865
            {
1866
                XmlElement PolyNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
1867

    
1868
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
1869
                HandleAttr.Value = pPoly.Handle.ToString();
1870
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1871

    
1872
                XmlAttribute NumVerticesAttr = Program.xml.CreateAttribute("NumVertices");
1873
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1874
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1875

    
1876
                XmlAttribute NumFacesAttr = Program.xml.CreateAttribute("NumFaces");
1877
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1878
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1879

    
1880
                /********************************************************************/
1881
                /* dump vertices and faces                                          */
1882
                /********************************************************************/
1883
                int vertexCount = 0;
1884
                int faceCount = 0;
1885
                foreach (ObjectId objId in pPoly)
1886
                {
1887
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1888
                    {
1889
                        if (ent is PolyFaceMeshVertex)
1890
                        {
1891
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1892

    
1893
                            XmlElement VertexNode = Program.xml.CreateElement(pVertex.GetRXClass().Name);
1894

    
1895
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1896
                            _HandleAttr.Value = pVertex.Handle.ToString();
1897
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1898

    
1899
                            XmlAttribute PositionAttr = Program.xml.CreateAttribute("Position");
1900
                            PositionAttr.Value = pVertex.Position.ToString();
1901
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1902

    
1903
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1904

    
1905
                            PolyNode.AppendChild(VertexNode);
1906
                        }
1907
                        else if (ent is FaceRecord)
1908
                        {
1909
                            FaceRecord pFace = (FaceRecord)ent;
1910
                            string face = "{";
1911
                            for (short i = 0; i < 4; i++)
1912
                            {
1913
                                if (i > 0)
1914
                                {
1915
                                    face = face + " ";
1916
                                }
1917
                                face = face + pFace.GetVertexAt(i).ToString();
1918
                            }
1919

    
1920
                            face += "}";
1921

    
1922
                            XmlElement FaceNode = Program.xml.CreateElement(pFace.GetRXClass().Name);
1923

    
1924
                            XmlAttribute _HandleAttr = Program.xml.CreateAttribute("Handle");
1925
                            _HandleAttr.Value = pFace.Handle.ToString();
1926
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1927
                            FaceNode.InnerText = face;
1928

    
1929
                            dumpEntityData(pFace, indent + 1, FaceNode);
1930

    
1931
                            PolyNode.AppendChild(FaceNode);
1932
                        }
1933
                        else
1934
                        { // Unknown entity type
1935
                            writeLine(indent, "Unexpected Entity");
1936
                        }
1937
                    }
1938
                }
1939
                dumpEntityData(pPoly, indent, PolyNode);
1940

    
1941
                return PolyNode;
1942
            }
1943

    
1944
            return null;
1945
        }
1946

    
1947
        /************************************************************************/
1948
        /* Ole2Frame                                                            */
1949
        /************************************************************************/
1950
        void dump(Ole2Frame pOle, int indent)
1951
        {
1952
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1953

    
1954
            Rectangle3d pos = (Rectangle3d)pOle.Position3d;
1955
            writeLine(indent, "Lower Left", pos.LowerLeft);
1956
            writeLine(indent, "Lower Right", pos.LowerRight);
1957
            writeLine(indent, "Upper Left", pos.UpperLeft);
1958
            writeLine(indent, "Upper Right", pos.UpperRight);
1959
            writeLine(indent, "Type", pOle.Type);
1960
            writeLine(indent, "User Type", pOle.UserType);
1961
            if (pOle.Type == Ole2Frame.ItemType.Link)
1962
            {
1963
                writeLine(indent, "Link Name", pOle.LinkName);
1964
                writeLine(indent, "Link Path", pOle.LinkPath);
1965
            }
1966
            writeLine(indent, "Output Quality", pOle.OutputQuality);
1967
            dumpEntityData(pOle, indent, Program.xml.DocumentElement);
1968
        }
1969

    
1970
        /************************************************************************/
1971
        /* Point Dumper                                                         */
1972
        /************************************************************************/
1973
        void dump(DBPoint pPoint, int indent)
1974
        {
1975
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1976
            writeLine(indent, "Position", pPoint.Position);
1977
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1978
            writeLine(indent, "Normal", pPoint.Normal);
1979
            writeLine(indent, "Thickness", pPoint.Thickness);
1980
            dumpEntityData(pPoint, indent, Program.xml.DocumentElement);
1981
        }
1982

    
1983
        /************************************************************************/
1984
        /* Polygon Mesh Dumper                                                  */
1985
        /************************************************************************/
1986
        void dump(PolygonMesh pPoly, int indent)
1987
        {
1988
            writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1989
            writeLine(indent, "m Size", pPoly.MSize);
1990
            writeLine(indent, "m-Closed", pPoly.IsMClosed);
1991
            writeLine(indent, "m Surface Density", pPoly.MSurfaceDensity);
1992
            writeLine(indent, "n Size", pPoly.NSize);
1993
            writeLine(indent, "n-Closed", pPoly.IsNClosed);
1994
            writeLine(indent, "n Surface Density", pPoly.NSurfaceDensity);
1995
            /********************************************************************/
1996
            /* dump vertices                                                    */
1997
            /********************************************************************/
1998
            int vertexCount = 0;
1999
            foreach (object o in pPoly)
2000
            {
2001
                PolygonMeshVertex pVertex = o as PolygonMeshVertex;
2002
                if (pVertex != null)
2003
                {
2004
                    writeLine(indent, pVertex.GetRXClass().Name, vertexCount++);
2005
                    writeLine(indent + 1, "Handle", pVertex.Handle);
2006
                    writeLine(indent + 1, "Position", pVertex.Position);
2007
                    writeLine(indent + 1, "Type", pVertex.VertexType);
2008
                }
2009
            }
2010
            dumpEntityData(pPoly, indent, Program.xml.DocumentElement);
2011
        }
2012

    
2013
        /************************************************************************/
2014
        /* Polyline Dumper                                                      */
2015
        /************************************************************************/
2016
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
2017
        {
2018
            if (pPoly != null && pPoly.Length != 0)
2019
            {
2020
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
2021
                writeLine(indent, "Has Width", pPoly.HasWidth);
2022
                if (!pPoly.HasWidth)
2023
                {
2024
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
2025
                }
2026

    
2027
                /********************************************************************/
2028
                /* dump vertices                                                    */
2029
                /********************************************************************/
2030
                if (node != null)
2031
                {
2032
                    XmlNode PolylineNode = Program.xml.CreateElement(pPoly.GetRXClass().Name);
2033
                    XmlAttribute LengthAttr = Program.xml.CreateAttribute("Length");
2034
                    LengthAttr.Value = pPoly.Length.ToString();
2035
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
2036

    
2037
                    XmlAttribute CountAttr = Program.xml.CreateAttribute("Count");
2038
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
2039
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
2040

    
2041
                    XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2042
                    HandleAttr.Value = pPoly.Handle.ToString();
2043
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
2044

    
2045
                    XmlAttribute ClosedAttr = Program.xml.CreateAttribute("Closed");
2046
                    ClosedAttr.Value = pPoly.Closed.ToString();
2047
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
2048

    
2049
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
2050
                    {
2051
                        XmlNode VertexNode = Program.xml.CreateElement("Vertex");
2052

    
2053
                        XmlAttribute SegmentTypeAttr = Program.xml.CreateAttribute("SegmentType");
2054
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
2055

    
2056
                        Point3d pt = pPoly.GetPoint3dAt(i);
2057
                        XmlAttribute XAttr = Program.xml.CreateAttribute("X");
2058
                        XAttr.Value = pt.X.ToString();
2059
                        VertexNode.Attributes.SetNamedItem(XAttr);
2060

    
2061
                        XmlAttribute YAttr = Program.xml.CreateAttribute("Y");
2062
                        YAttr.Value = pt.Y.ToString();
2063
                        VertexNode.Attributes.SetNamedItem(YAttr);
2064

    
2065
                        XmlAttribute ZAttr = Program.xml.CreateAttribute("Z");
2066
                        ZAttr.Value = pt.Z.ToString();
2067
                        VertexNode.Attributes.SetNamedItem(ZAttr);
2068

    
2069
                        if (pPoly.HasWidth)
2070
                        {
2071
                            XmlAttribute StartWidthAttr = Program.xml.CreateAttribute("StartWidth");
2072
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
2073
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
2074

    
2075
                            XmlAttribute EndWidthAttr = Program.xml.CreateAttribute("EndWidth");
2076
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
2077
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
2078
                        }
2079
                        if (pPoly.HasBulges)
2080
                        {
2081
                            XmlAttribute BulgeAttr = Program.xml.CreateAttribute("Bulge");
2082
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
2083
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
2084

    
2085
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2086
                            {
2087
                                XmlAttribute BulgeAngleAttr = Program.xml.CreateAttribute("BulgeAngle");
2088
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2089
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2090
                            }
2091
                        }
2092

    
2093
                        PolylineNode.AppendChild(VertexNode);
2094
                    }
2095

    
2096
                    dumpEntityData(pPoly, indent, PolylineNode);
2097
                    node.AppendChild(PolylineNode);
2098
                }
2099
            }
2100
            else
2101
            {
2102
                int d = 0;
2103
            }
2104
        }
2105

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

    
2165
            protected override void SetLayerFlags(LayerFlags flags)
2166
            {
2167
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2168
            }
2169
            public override void AddLight(ObjectId lightId)
2170
            {
2171
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2172
            }
2173
            public override void SetupForEntity(Entity entity)
2174
            {
2175
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2176
            }
2177

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

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

    
2473
            public override void SetExtents(Extents3d extents)
2474
            {
2475
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2476
            }
2477
            public override void StartAttributesSegment()
2478
            {
2479
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2480
            }
2481
        }
2482

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

    
2562
        /************************************************************************/
2563
        /* Dump the common data and WorldDraw information for all               */
2564
        /* entities without explicit dumpers                                    */
2565
        /************************************************************************/
2566
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2567
        {
2568
            if (node != null)
2569
            {
2570
                XmlElement EntNode = Program.xml.CreateElement(pEnt.GetRXClass().Name);
2571

    
2572
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2573
                HandleAttr.Value = pEnt.Handle.ToString();
2574
                EntNode.Attributes.SetNamedItem(HandleAttr);
2575

    
2576
                dumpEntityData(pEnt, indent, EntNode);
2577
                using (Database db = pEnt.Database)
2578
                {
2579
                    /**********************************************************************/
2580
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2581
                    /**********************************************************************/
2582
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2583
                    /**********************************************************************/
2584
                    /* Call worldDraw()                                                   */
2585
                    /**********************************************************************/
2586
                    pEnt.WorldDraw(wd);
2587
                }
2588

    
2589
                node.AppendChild(EntNode);
2590

    
2591
                return EntNode;
2592
            }
2593

    
2594
            return null;
2595
        }
2596

    
2597
        /************************************************************************/
2598
        /* Proxy Entity Dumper                                                  */
2599
        /************************************************************************/
2600
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2601
        {
2602
            if (node != null)
2603
            {
2604
                XmlElement ProxyNode = Program.xml.CreateElement(pProxy.GetRXClass().Name);
2605

    
2606
                XmlAttribute OriginalClassNameAttr = Program.xml.CreateAttribute("OriginalClassName");
2607
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2608
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2609

    
2610
                // this will dump proxy entity graphics
2611
                dump((Entity)pProxy, indent, node);
2612

    
2613
                DBObjectCollection collection = new DBObjectCollection(); ;
2614
                try
2615
                {
2616
                    pProxy.ExplodeGeometry(collection);
2617
                }
2618
                catch (System.Exception)
2619
                {
2620
                    return null;
2621
                }
2622

    
2623
                foreach (Entity ent in collection)
2624
                {
2625
                    if (ent is Polyline2d)
2626
                    {
2627
                        Polyline2d pline2d = (Polyline2d)ent;
2628
                        int i = 0;
2629

    
2630
                        try
2631
                        {
2632
                            foreach (Entity ent1 in pline2d)
2633
                            {
2634
                                if (ent1 is Vertex2d)
2635
                                {
2636
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2637
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2638
                                }
2639
                            }
2640
                        }
2641
                        catch (System.Exception)
2642
                        {
2643
                            return null;
2644
                        }
2645
                    }
2646
                }
2647

    
2648
                node.AppendChild(ProxyNode);
2649
                return ProxyNode;
2650
            }
2651

    
2652
            return null;
2653
        }
2654

    
2655
        /************************************************************************/
2656
        /* Radial Dimension Dumper                                              */
2657
        /************************************************************************/
2658
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2659
        {
2660
            if (node != null)
2661
            {
2662
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2663

    
2664
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2665
                HandleAttr.Value = pDim.Handle.ToString();
2666
                DimNode.Attributes.SetNamedItem(HandleAttr);
2667

    
2668
                XmlAttribute CenterAttr = Program.xml.CreateAttribute("Center");
2669
                CenterAttr.Value = pDim.Center.ToString();
2670
                DimNode.Attributes.SetNamedItem(CenterAttr);
2671

    
2672
                XmlAttribute ChordPointAttr = Program.xml.CreateAttribute("ChordPoint");
2673
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
2674
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
2675

    
2676
                XmlAttribute LeaderLengthAttr = Program.xml.CreateAttribute("LeaderLength");
2677
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2678
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2679

    
2680
                dumpDimData(pDim, indent, DimNode);
2681

    
2682
                node.AppendChild(DimNode);
2683

    
2684
                return DimNode;
2685
            }
2686

    
2687
            return null;
2688
        }
2689

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

    
2723
            /********************************************************************/
2724
            /* Dump clip boundary                                               */
2725
            /********************************************************************/
2726
            if (pImage.IsClipped)
2727
            {
2728
                writeLine(indent, "Clip Boundary Type", pImage.ClipBoundaryType);
2729
                if (pImage.ClipBoundaryType != ClipBoundaryType.Invalid)
2730
                {
2731
                    Point2dCollection pt = pImage.GetClipBoundary();
2732
                    for (int i = 0; i < pt.Count; i++)
2733
                    {
2734
                        writeLine(indent, string.Format("Clip Point {0}", i), pt[i]);
2735
                    }
2736
                }
2737
            }
2738

    
2739
            /********************************************************************/
2740
            /* Dump frame                                                       */
2741
            /********************************************************************/
2742
            Point3dCollection vertices = pImage.GetVertices();
2743
            for (int i = 0; i < vertices.Count; i++)
2744
            {
2745
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2746
            }
2747

    
2748
            /********************************************************************/
2749
            /* Dump orientation                                                 */
2750
            /********************************************************************/
2751
            writeLine(indent, "Orientation");
2752
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2753
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2754
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2755
            dumpRasterImageDef(pImage.ImageDefId, indent);
2756
            dumpEntityData(pImage, indent, Program.xml.DocumentElement);
2757
        }
2758

    
2759
        /************************************************************************/
2760
        /* Raster Image Dumper                                                  */
2761
        /************************************************************************/
2762
        void dump(RasterImage pImage, int indent)
2763
        {
2764
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2765
            writeLine(indent, "Image size", pImage.ImageSize(true));
2766
            dumpRasterImageData(pImage, indent);
2767
        }
2768

    
2769
        /************************************************************************/
2770
        /* Ray Dumper                                                          */
2771
        /************************************************************************/
2772
        void dump(Ray pRay, int indent)
2773
        {
2774
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2775
            writeLine(indent, "Base Point", pRay.BasePoint);
2776
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2777
            dumpCurveData(pRay, indent, Program.xml.DocumentElement);
2778
        }
2779

    
2780
        /************************************************************************/
2781
        /* Region Dumper                                                        */
2782
        /************************************************************************/
2783
        void dump(Region pRegion, int indent)
2784
        {
2785
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2786
            dumpEntityData(pRegion, indent, Program.xml.DocumentElement);
2787
        }
2788

    
2789
        /************************************************************************/
2790
        /* Rotated Dimension Dumper                                             */
2791
        /************************************************************************/
2792
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2793
        {
2794
            if (node != null)
2795
            {
2796
                XmlElement DimNode = Program.xml.CreateElement(pDim.GetRXClass().Name);
2797

    
2798
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2799
                HandleAttr.Value = pDim.Handle.ToString();
2800
                DimNode.Attributes.SetNamedItem(HandleAttr);
2801

    
2802
                XmlAttribute DimLinePointAttr = Program.xml.CreateAttribute("DimLinePoint");
2803
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2804
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2805

    
2806
                XmlAttribute ObliqueAttr = Program.xml.CreateAttribute("Oblique");
2807
                ObliqueAttr.Value = pDim.Oblique.ToString();
2808
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2809

    
2810
                XmlAttribute RotationAttr = Program.xml.CreateAttribute("Rotation");
2811
                RotationAttr.Value = pDim.Rotation.ToString();
2812
                DimNode.Attributes.SetNamedItem(RotationAttr);
2813

    
2814
                XmlAttribute XLine1PointAttr = Program.xml.CreateAttribute("XLine1Point");
2815
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2816
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2817

    
2818
                XmlAttribute XLine2PointAttr = Program.xml.CreateAttribute("XLine2Point");
2819
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2820
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2821

    
2822
                dumpDimData(pDim, indent, DimNode);
2823
                node.AppendChild(DimNode);
2824

    
2825
                return DimNode;
2826
            }
2827

    
2828
            return null;
2829
        }
2830

    
2831
        /************************************************************************/
2832
        /* Shape Dumper                                                          */
2833
        /************************************************************************/
2834
        void dump(Shape pShape, int indent)
2835
        {
2836
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2837

    
2838
            if (!pShape.StyleId.IsNull)
2839
            {
2840
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2841
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2842
            }
2843

    
2844
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2845
            writeLine(indent, "Shape Name", pShape.Name);
2846
            writeLine(indent, "Position", pShape.Position);
2847
            writeLine(indent, "Size", pShape.Size);
2848
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2849
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2850
            writeLine(indent, "Normal", pShape.Normal);
2851
            writeLine(indent, "Thickness", pShape.Thickness);
2852
            dumpEntityData(pShape, indent, Program.xml.DocumentElement);
2853
        }
2854

    
2855
        /************************************************************************/
2856
        /* Solid Dumper                                                         */
2857
        /************************************************************************/
2858
        // TODO:
2859
        /*  void dump(Solid pSolid, int indent)
2860
      {
2861
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2862

    
2863
        for (int i = 0; i < 4; i++)
2864
        {
2865
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2866
        }
2867
        dumpEntityData(pSolid, indent);
2868
      }
2869
    */
2870
        /************************************************************************/
2871
        /* Spline Dumper                                                        */
2872
        /************************************************************************/
2873
        void dump(Spline pSpline, int indent)
2874
        {
2875
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2876

    
2877
            NurbsData data = pSpline.NurbsData;
2878
            writeLine(indent, "Degree", data.Degree);
2879
            writeLine(indent, "Rational", data.Rational);
2880
            writeLine(indent, "Periodic", data.Periodic);
2881
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2882
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2883

    
2884
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2885
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2886
            {
2887
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2888
            }
2889

    
2890
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2891
            for (int i = 0; i < data.GetKnots().Count; i++)
2892
            {
2893
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2894
            }
2895

    
2896
            if (data.Rational)
2897
            {
2898
                writeLine(indent, "Number of Weights", data.GetWeights().Count);
2899
                for (int i = 0; i < data.GetWeights().Count; i++)
2900
                {
2901
                    writeLine(indent, "Weight " + i.ToString(), data.GetWeights()[i]);
2902
                }
2903
            }
2904
            dumpCurveData(pSpline, indent, Program.xml.DocumentElement);
2905
        }
2906
        /************************************************************************/
2907
        /* Table Dumper                                                         */
2908
        /************************************************************************/
2909
        void dump(Table pTable, int indent)
2910
        {
2911
            writeLine(indent++, pTable.GetRXClass().Name, pTable.Handle);
2912
            writeLine(indent, "Position", pTable.Position);
2913
            writeLine(indent, "X-Direction", pTable.Direction);
2914
            writeLine(indent, "Normal", pTable.Normal);
2915
            writeLine(indent, "Height", (int)pTable.Height);
2916
            writeLine(indent, "Width", (int)pTable.Width);
2917
            writeLine(indent, "Rows", (int)pTable.NumRows);
2918
            writeLine(indent, "Columns", (int)pTable.NumColumns);
2919

    
2920
            // TODO:
2921
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2922
            //writeLine(indent, "Table Style",               pStyle.Name);
2923
            dumpEntityData(pTable, indent, Program.xml.DocumentElement);
2924
        }
2925

    
2926
        /************************************************************************/
2927
        /* Text Dumper                                                          */
2928
        /************************************************************************/
2929
        static void dump(DBText pText, int indent, XmlNode node)
2930
        {
2931
            if (node != null)
2932
            {
2933
                dumpTextData(pText, indent, node);
2934
            }
2935
        }
2936
        /************************************************************************/
2937
        /* Trace Dumper                                                         */
2938
        /************************************************************************/
2939
        void dump(Trace pTrace, int indent)
2940
        {
2941
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2942

    
2943
            for (short i = 0; i < 4; i++)
2944
            {
2945
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2946
            }
2947
            dumpEntityData(pTrace, indent, Program.xml.DocumentElement);
2948
        }
2949

    
2950
        /************************************************************************/
2951
        /* Trace UnderlayReference                                                         */
2952
        /************************************************************************/
2953
        void dump(UnderlayReference pEnt, int indent)
2954
        {
2955
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2956
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2957
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2958
        }
2959

    
2960
        /************************************************************************/
2961
        /* Viewport Dumper                                                       */
2962
        /************************************************************************/
2963
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2964
        {
2965
            if (node != null)
2966
            {
2967
                XmlElement VportNode = Program.xml.CreateElement(pVport.GetRXClass().Name);
2968

    
2969
                XmlAttribute HandleAttr = Program.xml.CreateAttribute("Handle");
2970
                HandleAttr.Value = pVport.Handle.ToString();
2971
                VportNode.Attributes.SetNamedItem(HandleAttr);
2972

    
2973
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2974
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2975
                writeLine(indent, "Center Point", pVport.CenterPoint);
2976
                writeLine(indent, "Circle sides", pVport.CircleSides);
2977
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2978
                writeLine(indent, "Elevation", pVport.Elevation);
2979
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2980
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2981
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2982
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2983

    
2984
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2985
                if (layerIds.Count > 0)
2986
                {
2987
                    writeLine(indent, "Frozen Layers:");
2988
                    for (int i = 0; i < layerIds.Count; i++)
2989
                    {
2990
                        writeLine(indent + 1, i, layerIds[i]);
2991
                    }
2992
                }
2993
                else
2994
                {
2995
                    writeLine(indent, "Frozen Layers", "None");
2996
                }
2997

    
2998
                Point3d origin = new Point3d();
2999
                Vector3d xAxis = new Vector3d();
3000
                Vector3d yAxis = new Vector3d();
3001
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
3002
                writeLine(indent, "UCS origin", origin);
3003
                writeLine(indent, "UCS x-Axis", xAxis);
3004
                writeLine(indent, "UCS y-Axis", yAxis);
3005
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
3006
                writeLine(indent, "Grid On", pVport.GridOn);
3007
                writeLine(indent, "Height", pVport.Height);
3008
                writeLine(indent, "Lens Length", pVport.LensLength);
3009
                writeLine(indent, "Locked", pVport.Locked);
3010
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
3011

    
3012
                if (!pVport.NonRectClipEntityId.IsNull)
3013
                {
3014
                    writeLine(indent, "Non-rectangular Clipper", pVport.NonRectClipEntityId.Handle);
3015
                }
3016
                writeLine(indent, "Render Mode", pVport.RenderMode);
3017
                writeLine(indent, "Remove Hidden Lines", pVport.HiddenLinesRemoved);
3018
                writeLine(indent, "Shade Plot", pVport.ShadePlot);
3019
                writeLine(indent, "Snap Isometric", pVport.SnapIsometric);
3020
                writeLine(indent, "Snap On", pVport.SnapOn);
3021
                writeLine(indent, "Transparent", pVport.Transparent);
3022
                writeLine(indent, "UCS Follow", pVport.UcsFollowModeOn);
3023
                writeLine(indent, "UCS Icon at Origin", pVport.UcsIconAtOrigin);
3024

    
3025
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
3026
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
3027

    
3028
                if (!pVport.UcsName.IsNull)
3029
                {
3030
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
3031
                        writeLine(indent, "UCS Name", pUCS.Name);
3032
                }
3033
                else
3034
                {
3035
                    writeLine(indent, "UCS Name", "Null");
3036
                }
3037

    
3038
                writeLine(indent, "View Center", pVport.ViewCenter);
3039
                writeLine(indent, "View Height", pVport.ViewHeight);
3040
                writeLine(indent, "View Target", pVport.ViewTarget);
3041
                writeLine(indent, "Width", pVport.Width);
3042
                dumpEntityData(pVport, indent, Program.xml.DocumentElement);
3043

    
3044
                {
3045
                    using (DBObjectCollection collection = new DBObjectCollection())
3046
                    {
3047
                        try
3048
                        {
3049
                            pVport.ExplodeGeometry(collection);
3050

    
3051
                            foreach (Entity ent in collection)
3052
                            {
3053
                                if (ent is Polyline2d)
3054
                                {
3055
                                    Polyline2d pline2d = (Polyline2d)ent;
3056
                                    int i = 0;
3057
                                    foreach (Entity ent1 in pline2d)
3058
                                    {
3059
                                        if (ent1 is Vertex2d)
3060
                                        {
3061
                                            Vertex2d vtx2d = (Vertex2d)ent1;
3062
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
3063
                                        }
3064
                                    }
3065
                                }
3066
                            }
3067
                        }
3068
                        catch (System.Exception ex)
3069
                        {
3070
                        }
3071
                    }
3072
                }
3073

    
3074
                node.AppendChild(VportNode);
3075
                return VportNode;
3076
            }
3077

    
3078
            return null;
3079
        }
3080

    
3081
        /************************************************************************/
3082
        /* Wipeout Dumper                                                  */
3083
        /************************************************************************/
3084
        void dump(Wipeout pWipeout, int indent)
3085
        {
3086
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3087
            dumpRasterImageData(pWipeout, indent);
3088
        }
3089

    
3090
        /************************************************************************/
3091
        /* Xline Dumper                                                         */
3092
        /************************************************************************/
3093
        void dump(Xline pXline, int indent)
3094
        {
3095
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
3096
            writeLine(indent, "Base Point", pXline.BasePoint);
3097
            writeLine(indent, "Unit Direction", pXline.UnitDir);
3098
            dumpCurveData(pXline, indent, Program.xml.DocumentElement);
3099
        }
3100

    
3101
        public void dump(Database pDb, int indent, XmlNode node)
3102
        {
3103
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3104
            {
3105
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
3106
                {
3107
                    string layoutName = "";
3108
                    layoutName = pLayout.LayoutName;
3109

    
3110
                    XmlAttribute LayoutNameAttr = Program.xml.CreateAttribute("LayoutName");
3111
                    LayoutNameAttr.Value = layoutName;
3112
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3113
                }
3114
            }
3115

    
3116
            dumpHeader(pDb, indent, node);
3117
            dumpLayers(pDb, indent, node);
3118
            dumpLinetypes(pDb, indent, node);
3119
            dumpTextStyles(pDb, indent, node);
3120
            dumpDimStyles(pDb, indent, node);
3121
            dumpRegApps(pDb, indent);
3122
            dumpViewports(pDb, indent, node);
3123
            dumpViews(pDb, indent, node);
3124
            dumpMLineStyles(pDb, indent);
3125
            dumpUCSTable(pDb, indent, node);
3126
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3127

    
3128
            dumpBlocks(pDb, indent, node);
3129
        }
3130

    
3131
        /************************************************************************/
3132
        /* Export DWG to PDF                                                    */
3133
        /************************************************************************/
3134
        public void ExportPDF(Database pDb, string filePath)
3135
        {
3136
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3137
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3138
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3139

    
3140
            using (mPDFExportParams param = new mPDFExportParams())
3141
            {
3142
                param.Database = pDb;
3143

    
3144
                TransactionManager tm = pDb.TransactionManager;
3145
                using (Transaction ta = tm.StartTransaction())
3146
                {
3147
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3148
                    {
3149
                        param.OutputStream = fileStrem;
3150

    
3151
                        bool embededTTF = false;
3152
                        bool shxTextAsGeometry = true;
3153
                        bool ttfGeometry = true;
3154
                        bool simpleGeomOptimization = false;
3155
                        bool zoomToExtentsMode = true;
3156
                        bool enableLayers = false;
3157
                        bool includeOffLayers = false;
3158
                        bool enablePrcMode = true;
3159
                        bool monochrome = true;
3160
                        bool allLayout = false;
3161
                        double paperWidth = 841;
3162
                        double paperHeight = 594;
3163

    
3164
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3165
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3166
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3167
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3168
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3169
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3170
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3171

    
3172
                        param.Title = "";
3173
                        param.Author = "";
3174
                        param.Subject = "";
3175
                        param.Keywords = "";
3176
                        param.Creator = "";
3177
                        param.Producer = "";
3178
                        param.UseHLR = !enablePrcMode;
3179
                        param.FlateCompression = true;
3180
                        param.ASCIIHEXEncodeStream = true;
3181
                        param.hatchDPI = 720;
3182

    
3183
                        bool bV15 = enableLayers || includeOffLayers;
3184
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3185

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

    
3229
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3230

    
3231
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3232
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3233

    
3234
                        StringCollection strColl = new StringCollection();
3235
                        if (allLayout)
3236
                        {
3237
                            using (DBDictionary layouts = (DBDictionary)pDb.LayoutDictionaryId.GetObject(OpenMode.ForRead))
3238
                            {
3239
                                foreach (DBDictionaryEntry entry in layouts)
3240
                                {
3241
                                    if ("Model" == entry.Key)
3242
                                        strColl.Insert(0, entry.Key);
3243
                                    else
3244
                                        strColl.Add(entry.Key);
3245
                                    if (-1 != iIndexStyle)
3246
                                    {
3247
                                        PlotSettings ps = (PlotSettings)ta.GetObject(entry.Value, OpenMode.ForWrite);
3248
                                        plotSettingVal.SetCurrentStyleSheet(ps, styleCol[iIndexStyle]);
3249
                                    }
3250
                                }
3251
                            }
3252
                        }
3253
                        else if (-1 != iIndexStyle)
3254
                        {
3255
                            using (BlockTableRecord paperBTR = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3256
                            {
3257
                                using (PlotSettings pLayout = (PlotSettings)paperBTR.LayoutId.GetObject(OpenMode.ForWrite))
3258
                                {
3259
                                    plotSettingVal.SetCurrentStyleSheet(pLayout, styleCol[iIndexStyle]);
3260
                                }
3261
                            }
3262
                        }
3263
                        param.Layouts = strColl;
3264

    
3265
                        int nPages = Math.Max(1, strColl.Count);
3266
                        PageParamsCollection pParCol = new PageParamsCollection();
3267
                        for (int i = 0; i < nPages; ++i)
3268
                        {
3269
                            PageParams pp = new PageParams();
3270
                            pp.setParams(paperWidth, paperHeight);
3271
                            pParCol.Add(pp);
3272
                        }
3273
                        param.PageParams = pParCol;
3274
                        Export_Import.ExportPDF(param);
3275
                    }
3276
                    ta.Abort();
3277
                }
3278
            }
3279
        }
3280

    
3281
        /************************************************************************/
3282
        /* Export DWG to PNG                                                    */
3283
        /************************************************************************/
3284
        public void ExportPNG(Database pDb, string filePath)
3285
        {
3286
            ResultBuffer rsb = new ResultBuffer();
3287
            rsb.Add(new TypedValue(5003, 0));
3288
            Teigha.Runtime.Utilities.SetSystemVariables("PDMODE", rsb);
3289

    
3290
            chageColorAllObjects(pDb);
3291

    
3292
            string gdPath = "WinOpenGL_20.5_15.txv";
3293

    
3294
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3295
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3296
            string bmpPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".bmp");
3297
            string pngPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".png");
3298

    
3299
            using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3300
            {
3301
                if (gsModule == null)
3302
                {
3303
                    Console.WriteLine("\nCould not load graphics module {0} \nExport cancelled.", gdPath);
3304
                    return;
3305
                }
3306

    
3307
                // create graphics device
3308
                using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3309
                {
3310
                    // setup device properties
3311
                    using (Dictionary props = dev.Properties)
3312
                    {
3313
                        props.AtPut("BitPerPixel", new RxVariant(32));
3314
                    }
3315
                    using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3316
                    {
3317
                        ctx.PaletteBackground = System.Drawing.Color.White;
3318
                        ctx.SetPlotGeneration(true);
3319

    
3320
                        using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3321
                        {
3322
                            helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3323
                            int width = 9600;
3324
                            int height = 6787;
3325
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
3326
                            helperDevice.OnSize(rect);
3327

    
3328
                            if (ctx.IsPlotGeneration)
3329
                                helperDevice.BackgroundColor = System.Drawing.Color.White;
3330
                            else
3331
                                helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3332

    
3333
                            helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3334
                            helperDevice.ActiveView.Zoom(0.99);
3335
                            helperDevice.Update();
3336

    
3337
                            Export_Import.ExportBitmap(helperDevice, bmpPath);
3338
                        }
3339
                    }
3340
                }
3341
            }
3342

    
3343
            if (File.Exists(bmpPath))
3344
            {
3345
                if (File.Exists(pngPath))
3346
                {
3347
                    File.Delete(pngPath);
3348
                }
3349

    
3350
                ////bmp => grayscale bmp => png
3351
                //using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3352
                //{
3353
                //    System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height);
3354
                //    //get a graphics object from the new image
3355
                //    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
3356
                //    {
3357
                //        //create the grayscale ColorMatrix
3358
                //        System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(new float[][]
3359
                //        {
3360
                //            new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
3361
                //            new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
3362
                //            new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
3363
                //            new float[] { 0,      0,      0,      1, 0 },
3364
                //            new float[] { 0,      0,      0,      0, 1 }
3365
                //        });
3366

    
3367
                //        //create some image attributes
3368
                //        using (System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes())
3369
                //        {
3370
                //            //set the color matrix attribute
3371
                //            attributes.SetColorMatrix(colorMatrix);
3372
                //            //attributes.SetThreshold(0.8F);
3373

    
3374
                //            //draw the original image on the new image
3375
                //            //using the grayscale color matrix
3376
                //            g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
3377
                //                        0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
3378
                //        }
3379

    
3380
                //    }
3381
                //    newBmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3382
                //}
3383

    
3384
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bmpPath))
3385
                {
3386
                    bmp.Save(pngPath, System.Drawing.Imaging.ImageFormat.Png);
3387
                }
3388
                if (File.Exists(bmpPath))
3389
                {
3390
                    File.Delete(bmpPath);
3391
                }
3392
            }
3393
        }
3394

    
3395
        /************************************************************************/
3396
        /* Change the color of all objects                                      */
3397
        /************************************************************************/
3398
        private void chageColorAllObjects(Database pDb)
3399
        {
3400
            List<string> exceptLayerList = new List<string>();
3401
            using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
3402
            {
3403
                foreach (ObjectId id in pTable)
3404
                {
3405
                    using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
3406
                    {
3407
                        if (!pRecord.IsPlottable)
3408
                        {
3409
                            exceptLayerList.Add(pRecord.Name);
3410
                        }
3411
                    }
3412
                }
3413
            }
3414
            
3415
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3416
            {
3417
                LayerTable lt = tr.GetObject(pDb.LayerTableId, OpenMode.ForRead) as LayerTable;
3418
                string layerName = "DWG-FORM";
3419
                if (!lt.Has(layerName))
3420
                {
3421
                    layerName = "0";
3422
                }
3423
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3424
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3425

    
3426
                foreach (ObjectId id in btrModelSpace)
3427
                {
3428
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3429
                    if (ent == null) continue;
3430

    
3431
                    ent.ColorIndex = 7;
3432
                    if (exceptLayerList.Contains(ent.Layer))
3433
                    {
3434
                        ent.Layer = layerName;
3435
                    }
3436

    
3437
                    if (ent is BlockReference)
3438
                    {
3439
                        changeColorBlocks(tr, (BlockReference)ent, exceptLayerList);
3440
                    }
3441
                }
3442

    
3443
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3444
                foreach (DBDictionaryEntry entry in dbdic)
3445
                {
3446
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3447
                    if (group == null) continue;
3448

    
3449
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3450
                    if (idarrTags == null) continue;
3451

    
3452
                    foreach (ObjectId id in idarrTags)
3453
                    {
3454
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3455
                        if (ent == null) continue;
3456

    
3457
                        ent.ColorIndex = 7;
3458
                        if (exceptLayerList.Contains(ent.Layer))
3459
                        {
3460
                            ent.Layer = "0";
3461
                        }
3462
                    }
3463
                }
3464

    
3465
                foreach (ObjectId btrId in bt)
3466
                {
3467
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3468
                    if (btr == null) continue;
3469
                    if (btr.Name.StartsWith("*")) continue;
3470

    
3471
                    foreach (ObjectId entId in btr)
3472
                    {
3473
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3474
                        if (ent == null) continue;
3475
                        ent.ColorIndex = 0;//ByBlock
3476
                        if (exceptLayerList.Contains(ent.Layer))
3477
                        {
3478
                            ent.Layer = "0";
3479
                        }
3480
                    }
3481
                }
3482

    
3483
                tr.Commit();
3484
            }
3485
        }
3486

    
3487
        /************************************************************************/
3488
        /* Change the color of blocks                                           */
3489
        /************************************************************************/
3490
        private void changeColorBlocks(Transaction tr, BlockReference blkRef, List<string> exceptLayerList)
3491
        {
3492
            if (blkRef == null) return;
3493

    
3494
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3495
            {
3496
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3497
                {
3498
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3499
                    attRef.ColorIndex = 7;
3500
                    if (exceptLayerList.Contains(attRef.Layer))
3501
                    {
3502
                        attRef.Layer = "0";
3503
                    }
3504
                }
3505
            }
3506

    
3507
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3508
            if (btrBlock == null) return;
3509

    
3510
            foreach (ObjectId oid in btrBlock)
3511
            {
3512
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3513
                if (ent == null) continue;
3514

    
3515
                ent.ColorIndex = 7;
3516

    
3517
                if (ent is BlockReference)
3518
                {   
3519
                    changeColorBlocks(tr, (BlockReference)ent, exceptLayerList);
3520
                }
3521
            }
3522
        }
3523

    
3524
        /************************************************************************/
3525
        /* Nested block Explode & Purge                                         */
3526
        /************************************************************************/
3527
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3528
        {
3529
            HashSet<string> blockNameList = new HashSet<string>();
3530
            // Explode ModelSpace Nested Block
3531
            blockNameList = explodeNestedBlocks(pDb);
3532

    
3533
            // Prepare Block Purge
3534
            preparePurgeBlocks(pDb, blockNameList);
3535

    
3536
            // Block Purge
3537
            ObjectIdCollection oids = new ObjectIdCollection();
3538
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3539
            {
3540
                foreach (ObjectId id in pTable)
3541
                {
3542
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3543
                    oids.Add(id);
3544
                }
3545
            }
3546
            pDb.Purge(oids);
3547

    
3548
            foreach (ObjectId oid in oids)
3549
            {
3550
                if (oid.IsErased) continue;
3551

    
3552
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3553
                {
3554
                    btr.Erase(true);
3555
                }                
3556
            }
3557
        }
3558

    
3559
        private HashSet<string> explodeNestedBlocks(Database pDb)
3560
        {
3561
            HashSet<string> blockNameList = new HashSet<string>();
3562
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3563

    
3564
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3565
            {
3566
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3567
                {
3568
                    foreach (ObjectId entid in pBlock)
3569
                    {
3570
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3571
                        {
3572
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3573
                            BlockReference blockRef = (BlockReference)pEnt;
3574

    
3575
                            if (blockRef.Name.ToUpper().StartsWith(BLOCK_PIPING))
3576
                            {
3577
                                oidSet.Add(entid);
3578
                                continue;
3579
                            }
3580
                            else if (blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3581
                            {
3582
                                continue;
3583
                            }
3584
                            
3585
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3586
                            {
3587
                                bool isNestedBlock = false;
3588
                                foreach (ObjectId blkid in pBtr)
3589
                                {
3590
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3591
                                    {
3592
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3593
                                        {
3594
                                            oidSet.Add(entid);
3595
                                            isNestedBlock = true;
3596
                                        }
3597
                                    }
3598
                                }
3599
                                if (!isNestedBlock)
3600
                                {
3601
                                    blockNameList.Add(blockRef.Name);
3602
                                }
3603
                            }
3604
                        }
3605
                    }
3606
                }
3607
            }
3608

    
3609
            if (oidSet.Count > 0)
3610
            {
3611
                explodeBlocks(oidSet);
3612
                blockNameList = explodeNestedBlocks(pDb);
3613
            }
3614

    
3615
            return blockNameList;
3616
        }
3617

    
3618
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3619
        {
3620
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3621

    
3622
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3623
            {
3624
                foreach (ObjectId id in pTable)
3625
                {
3626
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForWrite, false, true))
3627
                    {
3628
                        if (pBlock.IsLayout) continue;
3629
                        pBlock.Explodable = true;
3630
                        if (blockNameList.Contains(pBlock.Name)) continue;
3631

    
3632
                        foreach (ObjectId entid in pBlock)
3633
                        {
3634
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3635
                            {
3636
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3637

    
3638
                                oidSet.Add(entid);
3639
                            }
3640
                        }
3641
                    }
3642
                }
3643
            }
3644

    
3645
            if (oidSet.Count > 0)
3646
            {
3647
                explodeBlocks(oidSet);
3648
                preparePurgeBlocks(pDb, blockNameList);
3649
            }
3650

    
3651
            return;
3652
        }
3653
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3654
        {
3655
            foreach (ObjectId blkId in oidSet)
3656
            {
3657
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3658
                blkRef.ExplodeGeometryToOwnerSpace();
3659
                blkRef.Erase();
3660
            }
3661
        }
3662

    
3663
        /************************************************************************/
3664
        /* Save Block as DWG For Auxiliary Graphic                              */
3665
        /************************************************************************/
3666
        public void ExportGraphicBlocks(Database pDb, string savePath)
3667
        {
3668
            try
3669
            {
3670
                using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3671
                {
3672
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3673
                    {
3674
                        foreach (ObjectId entid in pBlock)
3675
                        {
3676
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3677
                            {
3678
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3679
                                BlockReference blockRef = (BlockReference)pEnt;
3680
                                if (!blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3681
                                    continue;
3682

    
3683
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3684
                                objIdCol.Add(blockRef.ObjectId);
3685
                                if (objIdCol.Count == 0) continue;
3686

    
3687
                                string filePath = string.Format("{0}.dwg", blockRef.Name);
3688
                                string directory = Path.GetDirectoryName(savePath);
3689
                                directory = directory.ToLower().Replace("drawings\\native", "graphic");
3690
                                if (!Directory.Exists(directory))
3691
                                {
3692
                                    Directory.CreateDirectory(directory);
3693
                                }
3694
                                filePath = Path.Combine(directory, filePath);
3695
                                
3696
                                using (Database newDb = new Database(true, false))
3697
                                {
3698
                                    pDb.Wblock(newDb, objIdCol, Point3d.Origin, DuplicateRecordCloning.Ignore);
3699
                                    newDb.UpdateExt(true);
3700
                                    newDb.SaveAs(filePath, DwgVersion.Newest);
3701
                                }
3702

    
3703
                                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo();
3704
                                procStartInfo.FileName = @"C:\Program Files (x86)\SmartSketch\Program\Rad2d\bin\Dwg2Igr.exe";
3705
                                procStartInfo.RedirectStandardOutput = true;
3706
                                procStartInfo.RedirectStandardInput = true;
3707
                                procStartInfo.RedirectStandardError = true;
3708
                                procStartInfo.UseShellExecute = false;
3709
                                procStartInfo.CreateNoWindow = false;
3710
                                procStartInfo.Arguments = filePath.Replace(" ", "^");
3711

    
3712
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3713
                                {
3714
                                    proc.StartInfo = procStartInfo;
3715
                                    proc.Start();
3716
                                    proc.StandardInput.Close();
3717
                                    proc.WaitForExit();
3718

    
3719
                                    switch (proc.ExitCode)
3720
                                    {
3721
                                        case -1:
3722
                                            Console.WriteLine("[{0}] path does not exist or there is no file", filePath);
3723
                                            break;
3724
                                        case 0:
3725
                                            Console.WriteLine("[{0}] File conversion error", filePath.Replace(".dwg", ".igr"));
3726
                                            break;
3727
                                        case 1:
3728
                                            Console.WriteLine("[{0}] File conversion success", filePath.Replace(".dwg", ".igr"));
3729
                                            break;
3730
                                        default:
3731
                                            break;
3732
                                    }
3733
                                }
3734
                            }
3735
                        }
3736
                    }
3737
                }
3738
            }
3739
            catch (System.Exception ex)
3740
            {
3741
            }
3742
        }
3743
        /************************************************************************/
3744
        /* Dump the BlockTable                                                  */
3745
        /************************************************************************/
3746
        public void dumpBlocks(Database pDb, int indent, XmlNode node)
3747
        {
3748
            /**********************************************************************/
3749
            /* Get a pointer to the BlockTable                               */
3750
            /**********************************************************************/
3751
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3752
            {
3753
                /**********************************************************************/
3754
                /* Dump the Description                                               */
3755
                /**********************************************************************/
3756
                XmlElement BlocksNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
3757

    
3758
                /**********************************************************************/
3759
                /* Step through the BlockTable                                        */
3760
                /**********************************************************************/
3761
                foreach (ObjectId id in pTable)
3762
                {
3763
                    /********************************************************************/
3764
                    /* Open the BlockTableRecord for Reading                            */
3765
                    /********************************************************************/
3766
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3767
                    {
3768
                        /********************************************************************/
3769
                        /* Dump the BlockTableRecord                                        */
3770
                        /********************************************************************/
3771
                        XmlElement BlockNode = Program.xml.CreateElement(pBlock.GetRXClass().Name);
3772

    
3773
                        XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
3774
                        NameAttr.Value = pBlock.Name;
3775
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3776

    
3777
                        XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
3778
                        CommentsAttr.Value = pBlock.Comments;
3779
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3780

    
3781
                        XmlAttribute OriginAttr = Program.xml.CreateAttribute("Origin");
3782
                        OriginAttr.Value = pBlock.Origin.ToString();
3783
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3784

    
3785
                        writeLine(indent, pBlock.GetRXClass().Name);
3786
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3787
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3788
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3789
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3790
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3791

    
3792
                        try
3793
                        {
3794
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3795
                            extents.AddBlockExtents(pBlock);
3796

    
3797
                            XmlAttribute MinExtentsAttr = Program.xml.CreateAttribute("MinExtents");
3798
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3799
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3800

    
3801
                            XmlAttribute MaxExtentsAttr = Program.xml.CreateAttribute("MaxExtents");
3802
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3803
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3804
                        }
3805
                        catch (System.Exception)
3806
                        {
3807
                        }
3808

    
3809
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3810
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3811
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3812
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3813
                        {
3814
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3815
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3816
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3817
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3818
                        }
3819

    
3820
                        /********************************************************************/
3821
                        /* Step through the BlockTableRecord                                */
3822
                        /********************************************************************/
3823
                        foreach (ObjectId entid in pBlock)
3824
                        {
3825
                            /********************************************************************/
3826
                            /* Dump the Entity                                                  */
3827
                            /********************************************************************/
3828
                            dumpEntity(entid, indent + 1, BlockNode);
3829
                        }
3830

    
3831
                        BlocksNode.AppendChild(BlockNode);
3832
                    }
3833
                }
3834

    
3835
                node.AppendChild(BlocksNode);
3836
            }
3837
        }
3838

    
3839
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3840
        {
3841
            /**********************************************************************/
3842
            /* Get a SmartPointer to the DimStyleTable                            */
3843
            /**********************************************************************/
3844
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3845
            {
3846
                /**********************************************************************/
3847
                /* Dump the Description                                               */
3848
                /**********************************************************************/
3849
                writeLine();
3850
                writeLine(indent++, pTable.GetRXClass().Name);
3851

    
3852
                /**********************************************************************/
3853
                /* Step through the DimStyleTable                                    */
3854
                /**********************************************************************/
3855
                foreach (ObjectId id in pTable)
3856
                {
3857
                    /*********************************************************************/
3858
                    /* Open the DimStyleTableRecord for Reading                         */
3859
                    /*********************************************************************/
3860
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3861
                    {
3862
                        /*********************************************************************/
3863
                        /* Dump the DimStyleTableRecord                                      */
3864
                        /*********************************************************************/
3865
                        writeLine();
3866
                        writeLine(indent, pRecord.GetRXClass().Name);
3867
                        writeLine(indent, "Name", pRecord.Name);
3868
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3869

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

    
3943
                        dumpSymbolTableRecord(pRecord, indent, node);
3944
                    }
3945
                }
3946
            }
3947
        }
3948

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

    
4112
                    /**********************************************************************/
4113
                    /* Dump the Extension Dictionary                                      */
4114
                    /**********************************************************************/
4115
                    if (!pEnt.ExtensionDictionary.IsNull)
4116
                    {
4117
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
4118
                    }
4119
                }
4120
            }
4121
            catch (System.Exception ex)
4122
            {
4123
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
4124
            }
4125
        }
4126
        public void prepareDump(Database pDb)
4127
        {
4128
            // Purge Object(Layer X, Linetype X)
4129
            ObjectIdCollection oids = new ObjectIdCollection();
4130
            using (Transaction tr = pDb.TransactionManager.StartOpenCloseTransaction())
4131
            {
4132
                for (long i = 0; i < pDb.Handseed.Value; i++)
4133
                {
4134
                    ObjectId id = ObjectId.Null;
4135
                    pDb.TryGetObjectId(new Handle(i), out id);
4136
                    if (id != ObjectId.Null && !id.IsErased) oids.Add(id);
4137
                }
4138

    
4139
                pDb.Purge(oids);
4140
                try
4141
                {
4142
                    foreach (ObjectId oid in oids)
4143
                    {
4144
                        if (oid.IsErased) continue;
4145

    
4146
                        DBObject obj = tr.GetObject(oid, OpenMode.ForWrite, false, true) as DBObject;
4147
                        obj.Erase(true);
4148
                    }
4149
                }
4150
                catch (System.Exception ex)
4151
                {
4152
                }
4153

    
4154
                tr.Commit();
4155
            }
4156

    
4157
            // Viewport Ucs
4158
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4159
            {
4160
                foreach (ObjectId id in pTable)
4161
                {
4162
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4163
                    {
4164
                        if (pRecord.Name == "*Active")
4165
                        {
4166
                            CoordinateSystem3d cs3d = pRecord.Ucs;
4167
                            if (cs3d.Origin != Point3d.Origin || cs3d.Xaxis != new Vector3d(1, 0, 0) || cs3d.Yaxis != new Vector3d(0, 1, 0))
4168
                            {
4169
                                pRecord.UpgradeOpen();
4170
                                pRecord.SetUcsToWorld();
4171
                            }
4172
                            if (pRecord.ViewTwist != 0)
4173
                            {
4174
                                pRecord.UpgradeOpen();
4175
                                pRecord.ViewTwist = 0;
4176
                            }
4177
                            if (pRecord.ViewDirection != new Vector3d(0, 0, 1))
4178
                            {
4179
                                pRecord.UpgradeOpen();
4180
                                pRecord.ViewDirection = new Vector3d(0, 0, 1);
4181
                            }
4182
                        }
4183
                    }
4184
                }
4185
            }
4186

    
4187
            // SEC Title box Move & Erase
4188
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
4189
            {
4190
                string blockName = "Titlebox";
4191
                Extents3d extents = new Extents3d();
4192
                bool isOK = false;
4193
                if (pTable.Has(blockName))
4194
                {
4195
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
4196
                    {
4197
                        foreach (ObjectId entid in pBlock)
4198
                        {
4199
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
4200
                            {
4201
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
4202
                                BlockReference blockRef = (BlockReference)pEnt;
4203
                                if (blockRef.Name.Equals(blockName))
4204
                                {
4205
                                    isOK = true;
4206
                                    extents = blockRef.GeometricExtents;
4207
                                    break;
4208
                                }
4209
                            }
4210
                        }
4211
                    }
4212
                }
4213

    
4214
                if (isOK)
4215
                {
4216
                    Vector3d vec = extents.MinPoint.GetVectorTo(Point3d.Origin);
4217
                    extents.TransformBy(Matrix3d.Displacement(vec));
4218
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
4219
                    {
4220
                        foreach (ObjectId entid in pBlock)
4221
                        {
4222
                            using (Entity entity = (Entity)entid.Open(OpenMode.ForWrite, false, true))
4223
                            {
4224
                                if (entity != null)
4225
                                    entity.TransformBy(Matrix3d.Displacement(vec));
4226
                                try
4227
                                {
4228
                                    if (entity.Bounds != null)
4229
                                    {
4230
                                        Extents3d entExtents = entity.GeometricExtents;
4231
                                        if ((entExtents.MinPoint.X >= extents.MinPoint.X && entExtents.MinPoint.Y >= extents.MinPoint.Y
4232
                                            && entExtents.MinPoint.X <= extents.MaxPoint.X && entExtents.MinPoint.Y <= extents.MaxPoint.Y)
4233
                                            || (entExtents.MaxPoint.X >= extents.MinPoint.X && entExtents.MaxPoint.Y >= extents.MinPoint.Y
4234
                                            && entExtents.MaxPoint.X <= extents.MaxPoint.X && entExtents.MaxPoint.Y <= extents.MaxPoint.Y))
4235
                                        {
4236
                                        }
4237
                                        else
4238
                                        {
4239
                                            entity.Erase();
4240
                                        }
4241
                                    }
4242
                                }
4243
                                catch (System.Exception ex)
4244
                                {
4245
                                }
4246
                            }
4247
                        }
4248
                    }
4249
                }
4250
            }
4251
                        
4252
            pDb.UpdateExt(true);
4253
        }
4254
        public void dumpHeader(Database pDb, int indent, XmlNode node)
4255
        {
4256
            if (node != null)
4257
            {
4258
                XmlAttribute FileNameAttr = Program.xml.CreateAttribute("FileName");
4259
                FileNameAttr.Value = shortenPath(pDb.Filename);
4260
                node.Attributes.SetNamedItem(FileNameAttr);
4261

    
4262
                XmlAttribute OriginalFileVersionAttr = Program.xml.CreateAttribute("OriginalFileVersion");
4263
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4264
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4265

    
4266
                writeLine();
4267
                writeLine(indent++, "Header Variables:");
4268

    
4269
                //writeLine();
4270
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4271
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4272

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

    
4428
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4429
        {
4430
            if (node != null)
4431
            {
4432
                /**********************************************************************/
4433
                /* Get a SmartPointer to the LayerTable                               */
4434
                /**********************************************************************/
4435
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4436
                {
4437
                    /**********************************************************************/
4438
                    /* Dump the Description                                               */
4439
                    /**********************************************************************/
4440
                    XmlElement LayerNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4441

    
4442
                    /**********************************************************************/
4443
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4444
                    /**********************************************************************/
4445

    
4446
                    /**********************************************************************/
4447
                    /* Step through the LayerTable                                        */
4448
                    /**********************************************************************/
4449
                    foreach (ObjectId id in pTable)
4450
                    {
4451
                        /********************************************************************/
4452
                        /* Open the LayerTableRecord for Reading                            */
4453
                        /********************************************************************/
4454
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4455
                        {
4456
                            /********************************************************************/
4457
                            /* Dump the LayerTableRecord                                        */
4458
                            /********************************************************************/
4459
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4460

    
4461
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4462
                            NameAttr.Value = pRecord.Name.ToString();
4463
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4464

    
4465
                            XmlAttribute IsUsedAttr = Program.xml.CreateAttribute("IsUsed");
4466
                            IsUsedAttr.Value = pRecord.IsUsed.ToString();
4467
                            RecordNode.Attributes.SetNamedItem(IsUsedAttr);
4468

    
4469
                            XmlAttribute IsOffAttr = Program.xml.CreateAttribute("IsOff");
4470
                            IsOffAttr.Value = pRecord.IsOff.ToString();
4471
                            RecordNode.Attributes.SetNamedItem(IsOffAttr);
4472

    
4473
                            XmlAttribute IsFrozenAttr = Program.xml.CreateAttribute("IsFrozen");
4474
                            IsFrozenAttr.Value = pRecord.IsFrozen.ToString();
4475
                            RecordNode.Attributes.SetNamedItem(IsFrozenAttr);
4476

    
4477
                            XmlAttribute IsLockedAttr = Program.xml.CreateAttribute("IsLocked");
4478
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4479
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4480

    
4481
                            XmlAttribute ColorAttr = Program.xml.CreateAttribute("Color");
4482
                            ColorAttr.Value = pRecord.Color.ToString();
4483
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4484

    
4485
                            XmlAttribute LinetypeObjectIdAttr = Program.xml.CreateAttribute("LinetypeObjectId");
4486
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4487
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4488

    
4489
                            XmlAttribute LineWeightAttr = Program.xml.CreateAttribute("LineWeight");
4490
                            LineWeightAttr.Value = pRecord.LineWeight.ToString();
4491
                            RecordNode.Attributes.SetNamedItem(LineWeightAttr);
4492

    
4493
                            XmlAttribute PlotStyleNameAttr = Program.xml.CreateAttribute("PlotStyleName");
4494
                            PlotStyleNameAttr.Value = pRecord.PlotStyleName.ToString();
4495
                            RecordNode.Attributes.SetNamedItem(PlotStyleNameAttr);
4496

    
4497
                            XmlAttribute IsPlottableAttr = Program.xml.CreateAttribute("IsPlottable");
4498
                            IsPlottableAttr.Value = pRecord.IsPlottable.ToString();
4499
                            RecordNode.Attributes.SetNamedItem(IsPlottableAttr);
4500

    
4501
                            XmlAttribute ViewportVisibilityDefaultAttr = Program.xml.CreateAttribute("ViewportVisibilityDefault");
4502
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4503
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4504

    
4505
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4506
                            LayerNode.AppendChild(RecordNode);
4507
                        }
4508
                    }
4509

    
4510
                    node.AppendChild(LayerNode);
4511
                }
4512
            }
4513
        }
4514

    
4515
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4516
        {
4517
            if (node != null)
4518
            {
4519
                /**********************************************************************/
4520
                /* Get a pointer to the LinetypeTable                            */
4521
                /**********************************************************************/
4522
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4523
                {
4524
                    XmlElement LinetypeNode = Program.xml.CreateElement(pTable.GetRXClass().Name);
4525

    
4526
                    /**********************************************************************/
4527
                    /* Step through the LinetypeTable                                     */
4528
                    /**********************************************************************/
4529
                    foreach (ObjectId id in pTable)
4530
                    {
4531
                        /*********************************************************************/
4532
                        /* Open the LinetypeTableRecord for Reading                          */
4533
                        /*********************************************************************/
4534
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4535
                        {
4536
                            XmlElement RecordNode = Program.xml.CreateElement(pRecord.GetRXClass().Name);
4537

    
4538
                            XmlAttribute ObjectIdAttr = Program.xml.CreateAttribute("ObjectId");
4539
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4540
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4541

    
4542
                            XmlAttribute NameAttr = Program.xml.CreateAttribute("Name");
4543
                            NameAttr.Value = pRecord.Name;
4544
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4545

    
4546
                            XmlAttribute CommentsAttr = Program.xml.CreateAttribute("Comments");
4547
                            CommentsAttr.Value = pRecord.Comments;
4548
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4549

    
4550
                            /********************************************************************/
4551
                            /* Dump the first line of record as in ACAD.LIN                     */
4552
                            /********************************************************************/
4553
                            string buffer = "*" + pRecord.Name;
4554
                            if (pRecord.Comments != "")
4555
                            {
4556
                                buffer = buffer + "," + pRecord.Comments;
4557
                            }
4558
                            writeLine(indent, buffer);
4559

    
4560
                            /********************************************************************/
4561
                            /* Dump the second line of record as in ACAD.LIN                    */
4562
                            /********************************************************************/
4563
                            if (pRecord.NumDashes > 0)
4564
                            {
4565
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4566
                                for (int i = 0; i < pRecord.NumDashes; i++)
4567
                                {
4568
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4569
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4570
                                    string text = pRecord.TextAt(i);
4571

    
4572
                                    /**************************************************************/
4573
                                    /* Dump the Complex Line                                      */
4574
                                    /**************************************************************/
4575
                                    if (shapeNumber != 0 || text != "")
4576
                                    {
4577
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4578
                                        {
4579
                                            if (shapeNumber != 0)
4580
                                            {
4581
                                                buffer = buffer + ",[" + shapeNumber + ",";
4582
                                                if (pTextStyle != null)
4583
                                                    buffer = buffer + pTextStyle.FileName;
4584
                                                else
4585
                                                    buffer = buffer + "NULL style";
4586
                                            }
4587
                                            else
4588
                                            {
4589
                                                buffer = buffer + ",[" + text + ",";
4590
                                                if (pTextStyle != null)
4591
                                                    buffer = buffer + pTextStyle.Name;
4592
                                                else
4593
                                                    buffer = buffer + "NULL style";
4594
                                            }
4595
                                        }
4596

    
4597
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4598
                                        {
4599
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4600
                                        }
4601
                                        if (pRecord.ShapeRotationAt(i) != 0)
4602
                                        {
4603
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4604
                                        }
4605
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4606
                                        {
4607
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4608
                                        }
4609
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4610
                                        {
4611
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4612
                                        }
4613
                                        buffer = buffer + "]";
4614
                                    }
4615
                                }
4616
                                writeLine(indent, buffer);
4617
                            }
4618
                            dumpSymbolTableRecord(pRecord, indent, node);
4619
                            LinetypeNode.AppendChild(RecordNode);
4620
                        }
4621
                    }
4622

    
4623
                    node.AppendChild(LinetypeNode);
4624
                }
4625
            }
4626
        }
4627

    
4628
        public void dumpRegApps(Database pDb, int indent)
4629
        {
4630
            /**********************************************************************/
4631
            /* Get a pointer to the RegAppTable                            */
4632
            /**********************************************************************/
4633
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4634
            {
4635
                /**********************************************************************/
4636
                /* Dump the Description                                               */
4637
                /**********************************************************************/
4638
                writeLine();
4639
                writeLine(indent++, pTable.GetRXClass().Name);
4640

    
4641
                /**********************************************************************/
4642
                /* Step through the RegAppTable                                    */
4643
                /**********************************************************************/
4644
                foreach (ObjectId id in pTable)
4645
                {
4646
                    /*********************************************************************/
4647
                    /* Open the RegAppTableRecord for Reading                         */
4648
                    /*********************************************************************/
4649
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4650
                    {
4651
                        /*********************************************************************/
4652
                        /* Dump the RegAppTableRecord                                      */
4653
                        /*********************************************************************/
4654
                        writeLine();
4655
                        writeLine(indent, pRecord.GetRXClass().Name);
4656
                        writeLine(indent, "Name", pRecord.Name);
4657
                    }
4658
                }
4659
            }
4660
        }
4661

    
4662
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4663
        {
4664
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4665
            if (pRecord.IsDependent)
4666
            {
4667
                writeLine(indent, "Resolved", pRecord.IsResolved);
4668
            }
4669
        }
4670

    
4671
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4672
        {
4673
            /**********************************************************************/
4674
            /* Get a SmartPointer to the TextStyleTable                            */
4675
            /**********************************************************************/
4676
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4677
            {
4678
                /**********************************************************************/
4679
                /* Dump the Description                                               */
4680
                /**********************************************************************/
4681
                writeLine();
4682
                writeLine(indent++, pTable.GetRXClass().Name);
4683

    
4684
                /**********************************************************************/
4685
                /* Step through the TextStyleTable                                    */
4686
                /**********************************************************************/
4687
                foreach (ObjectId id in pTable)
4688
                {
4689
                    /*********************************************************************/
4690
                    /* Open the TextStyleTableRecord for Reading                         */
4691
                    /*********************************************************************/
4692
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4693
                    {
4694
                        /*********************************************************************/
4695
                        /* Dump the TextStyleTableRecord                                      */
4696
                        /*********************************************************************/
4697
                        writeLine();
4698
                        writeLine(indent, pRecord.GetRXClass().Name);
4699
                        writeLine(indent, "Name", pRecord.Name);
4700
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4701
                        writeLine(indent, "Text Height", pRecord.TextSize);
4702
                        writeLine(indent, "Width Factor", pRecord.XScale);
4703
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4704
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4705
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4706
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4707
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4708
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4709

    
4710
                        FontDescriptor fd = pRecord.Font;
4711
                        writeLine(indent, "Typeface", fd.TypeFace);
4712
                        writeLine(indent, "Character Set", fd.CharacterSet);
4713
                        writeLine(indent, "Bold", fd.Bold);
4714
                        writeLine(indent, "Italic", fd.Italic);
4715
                        writeLine(indent, "Font Pitch & Family", toHexString(fd.PitchAndFamily));
4716
                        dumpSymbolTableRecord(pRecord, indent, node);
4717
                    }
4718
                }
4719
            }
4720
        }
4721
        public void dumpAbstractViewTableRecord(AbstractViewTableRecord pView, int indent, XmlNode node)
4722
        {
4723
            /*********************************************************************/
4724
            /* Dump the AbstractViewTableRecord                                  */
4725
            /*********************************************************************/
4726
            writeLine(indent, "Back Clip Dist", pView.BackClipDistance);
4727
            writeLine(indent, "Back Clip Enabled", pView.BackClipEnabled);
4728
            writeLine(indent, "Front Clip Dist", pView.FrontClipDistance);
4729
            writeLine(indent, "Front Clip Enabled", pView.FrontClipEnabled);
4730
            writeLine(indent, "Front Clip at Eye", pView.FrontClipAtEye);
4731
            writeLine(indent, "Elevation", pView.Elevation);
4732
            writeLine(indent, "Height", pView.Height);
4733
            writeLine(indent, "Width", pView.Width);
4734
            writeLine(indent, "Lens Length", pView.LensLength);
4735
            writeLine(indent, "Render Mode", pView.RenderMode);
4736
            writeLine(indent, "Perspective", pView.PerspectiveEnabled);
4737
            writeLine(indent, "UCS Name", pView.UcsName);
4738

    
4739
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4740
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4741

    
4742
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4743
            {
4744
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4745
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4746
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4747
            }
4748

    
4749
            writeLine(indent, "Target", pView.Target);
4750
            writeLine(indent, "View Direction", pView.ViewDirection);
4751
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4752
            dumpSymbolTableRecord(pView, indent, node);
4753
        }
4754
        public void dumpDimAssoc(DBObject pObject, int indent)
4755
        {
4756

    
4757
        }
4758
        public void dumpMLineStyles(Database pDb, int indent)
4759
        {
4760
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4761
            {
4762
                /**********************************************************************/
4763
                /* Dump the Description                                               */
4764
                /**********************************************************************/
4765
                writeLine();
4766
                writeLine(indent++, pDictionary.GetRXClass().Name);
4767

    
4768
                /**********************************************************************/
4769
                /* Step through the MlineStyle dictionary                             */
4770
                /**********************************************************************/
4771
                DbDictionaryEnumerator e = pDictionary.GetEnumerator();
4772
                while (e.MoveNext())
4773
                {
4774
                    try
4775
                    {
4776
                        using (MlineStyle pEntry = (MlineStyle)e.Value.Open(OpenMode.ForRead))
4777
                        {
4778
                            /*********************************************************************/
4779
                            /* Dump the MLineStyle dictionary entry                              */
4780
                            /*********************************************************************/
4781
                            writeLine();
4782
                            writeLine(indent, pEntry.GetRXClass().Name);
4783
                            writeLine(indent, "Name", pEntry.Name);
4784
                            writeLine(indent, "Description", pEntry.Description);
4785
                            writeLine(indent, "Start Angle", toDegreeString(pEntry.StartAngle));
4786
                            writeLine(indent, "End Angle", toDegreeString(pEntry.EndAngle));
4787
                            writeLine(indent, "Start Inner Arcs", pEntry.StartInnerArcs);
4788
                            writeLine(indent, "End Inner Arcs", pEntry.EndInnerArcs);
4789
                            writeLine(indent, "Start Round Cap", pEntry.StartRoundCap);
4790
                            writeLine(indent, "End Round Cap", pEntry.EndRoundCap);
4791
                            writeLine(indent, "Start Square Cap", pEntry.StartRoundCap);
4792
                            writeLine(indent, "End Square Cap", pEntry.EndRoundCap);
4793
                            writeLine(indent, "Show Miters", pEntry.ShowMiters);
4794
                            /*********************************************************************/
4795
                            /* Dump the elements                                                 */
4796
                            /*********************************************************************/
4797
                            if (pEntry.Elements.Count > 0)
4798
                            {
4799
                                writeLine(indent, "Elements:");
4800
                            }
4801
                            int i = 0;
4802
                            foreach (MlineStyleElement el in pEntry.Elements)
4803
                            {
4804
                                writeLine(indent, "Index", (i++));
4805
                                writeLine(indent + 1, "Offset", el.Offset);
4806
                                writeLine(indent + 1, "Color", el.Color);
4807
                                writeLine(indent + 1, "Linetype", el.LinetypeId);
4808
                            }
4809
                        }
4810
                    }
4811
                    catch (System.Exception)
4812
                    {
4813
                    }
4814
                }
4815
            }
4816
        }
4817
        public void dumpObject(ObjectId id, string itemName, int indent)
4818
        {
4819
            using (DBObject pObject = id.Open(OpenMode.ForRead))
4820
            {
4821
                /**********************************************************************/
4822
                /* Dump the item name and class name                                  */
4823
                /**********************************************************************/
4824
                if (pObject is DBDictionary)
4825
                {
4826
                    writeLine();
4827
                }
4828
                writeLine(indent++, itemName, pObject.GetRXClass().Name);
4829

    
4830
                /**********************************************************************/
4831
                /* Dispatch                                                           */
4832
                /**********************************************************************/
4833
                if (pObject is DBDictionary)
4834
                {
4835
                    /********************************************************************/
4836
                    /* Dump the dictionary                                               */
4837
                    /********************************************************************/
4838
                    DBDictionary pDic = (DBDictionary)pObject;
4839

    
4840
                    /********************************************************************/
4841
                    /* Get a pointer to a new DictionaryIterator                   */
4842
                    /********************************************************************/
4843
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4844

    
4845
                    /********************************************************************/
4846
                    /* Step through the Dictionary                                      */
4847
                    /********************************************************************/
4848
                    while (pIter.MoveNext())
4849
                    {
4850
                        /******************************************************************/
4851
                        /* Dump the Dictionary object                                     */
4852
                        /******************************************************************/
4853
                        dumpObject(pIter.Value, pIter.Key, indent);
4854
                    }
4855
                }
4856
                else if (pObject is Xrecord)
4857
                {
4858
                    /********************************************************************/
4859
                    /* Dump an Xrecord                                                  */
4860
                    /********************************************************************/
4861
                    Xrecord pXRec = (Xrecord)pObject;
4862
                    dumpXdata(pXRec.Data, indent);
4863
                }
4864
            }
4865
        }
4866

    
4867
        public void dumpUCSTable(Database pDb, int indent, XmlNode node)
4868
        {
4869
            /**********************************************************************/
4870
            /* Get a pointer to the UCSTable                               */
4871
            /**********************************************************************/
4872
            using (UcsTable pTable = (UcsTable)pDb.UcsTableId.Open(OpenMode.ForRead))
4873
            {
4874
                /**********************************************************************/
4875
                /* Dump the Description                                               */
4876
                /**********************************************************************/
4877
                writeLine();
4878
                writeLine(indent++, pTable.GetRXClass().Name);
4879

    
4880
                /**********************************************************************/
4881
                /* Step through the UCSTable                                          */
4882
                /**********************************************************************/
4883
                foreach (ObjectId id in pTable)
4884
                {
4885
                    /********************************************************************/
4886
                    /* Open the UCSTableRecord for Reading                            */
4887
                    /********************************************************************/
4888
                    using (UcsTableRecord pRecord = (UcsTableRecord)id.Open(OpenMode.ForRead))
4889
                    {
4890
                        /********************************************************************/
4891
                        /* Dump the UCSTableRecord                                        */
4892
                        /********************************************************************/
4893
                        writeLine();
4894
                        writeLine(indent, pRecord.GetRXClass().Name);
4895
                        writeLine(indent, "Name", pRecord.Name);
4896
                        writeLine(indent, "UCS Origin", pRecord.Origin);
4897
                        writeLine(indent, "UCS x-Axis", pRecord.XAxis);
4898
                        writeLine(indent, "UCS y-Axis", pRecord.YAxis);
4899
                        dumpSymbolTableRecord(pRecord, indent, node);
4900
                    }
4901
                }
4902
            }
4903
        }
4904
        public void dumpViewports(Database pDb, int indent, XmlNode node)
4905
        {
4906
            /**********************************************************************/
4907
            /* Get a pointer to the ViewportTable                            */
4908
            /**********************************************************************/
4909
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4910
            {
4911
                /**********************************************************************/
4912
                /* Dump the Description                                               */
4913
                /**********************************************************************/
4914
                writeLine();
4915
                writeLine(indent++, pTable.GetRXClass().Name);
4916

    
4917
                /**********************************************************************/
4918
                /* Step through the ViewportTable                                    */
4919
                /**********************************************************************/
4920
                foreach (ObjectId id in pTable)
4921
                {
4922
                    /*********************************************************************/
4923
                    /* Open the ViewportTableRecord for Reading                          */
4924
                    /*********************************************************************/
4925
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4926
                    {
4927
                        /*********************************************************************/
4928
                        /* Dump the ViewportTableRecord                                      */
4929
                        /*********************************************************************/
4930
                        writeLine();
4931
                        writeLine(indent, pRecord.GetRXClass().Name);
4932
                        writeLine(indent, "Name", pRecord.Name);
4933
                        writeLine(indent, "Circle Sides", pRecord.CircleSides);
4934
                        writeLine(indent, "Fast Zooms Enabled", pRecord.FastZoomsEnabled);
4935
                        writeLine(indent, "Grid Enabled", pRecord.GridEnabled);
4936
                        writeLine(indent, "Grid Increments", pRecord.GridIncrements);
4937
                        writeLine(indent, "Icon at Origin", pRecord.IconAtOrigin);
4938
                        writeLine(indent, "Icon Enabled", pRecord.IconEnabled);
4939
                        writeLine(indent, "Iso snap Enabled", pRecord.IsometricSnapEnabled);
4940
                        writeLine(indent, "Iso Snap Pair", pRecord.SnapPair);
4941
                        writeLine(indent, "UCS Saved w/Vport", pRecord.UcsSavedWithViewport);
4942
                        writeLine(indent, "UCS follow", pRecord.UcsFollowMode);
4943
                        writeLine(indent, "Lower-Left Corner", pRecord.LowerLeftCorner);
4944
                        writeLine(indent, "Upper-Right Corner", pRecord.UpperRightCorner);
4945
                        writeLine(indent, "Snap Angle", toDegreeString(pRecord.SnapAngle));
4946
                        writeLine(indent, "Snap Base", pRecord.SnapBase);
4947
                        writeLine(indent, "Snap Enabled", pRecord.SnapEnabled);
4948
                        writeLine(indent, "Snap Increments", pRecord.SnapIncrements);
4949
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4950
                    }
4951
                }
4952
            }
4953
        }
4954

    
4955
        /************************************************************************/
4956
        /* Dump the ViewTable                                                   */
4957
        /************************************************************************/
4958
        public void dumpViews(Database pDb, int indent, XmlNode node)
4959
        {
4960
            /**********************************************************************/
4961
            /* Get a pointer to the ViewTable                                */
4962
            /**********************************************************************/
4963
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
4964
            {
4965
                /**********************************************************************/
4966
                /* Dump the Description                                               */
4967
                /**********************************************************************/
4968
                writeLine();
4969
                writeLine(indent++, pTable.GetRXClass().Name);
4970

    
4971
                /**********************************************************************/
4972
                /* Step through the ViewTable                                         */
4973
                /**********************************************************************/
4974
                foreach (ObjectId id in pTable)
4975
                {
4976
                    /*********************************************************************/
4977
                    /* Open the ViewTableRecord for Reading                              */
4978
                    /*********************************************************************/
4979
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
4980
                    {
4981
                        /*********************************************************************/
4982
                        /* Dump the ViewTableRecord                                          */
4983
                        /*********************************************************************/
4984
                        writeLine();
4985
                        writeLine(indent, pRecord.GetRXClass().Name);
4986
                        writeLine(indent, "Name", pRecord.Name);
4987
                        writeLine(indent, "Category Name", pRecord.CategoryName);
4988
                        writeLine(indent, "Layer State", pRecord.LayerState);
4989

    
4990
                        string layoutName = "";
4991
                        if (!pRecord.Layout.IsNull)
4992
                        {
4993
                            using (Layout pLayout = (Layout)pRecord.Layout.Open(OpenMode.ForRead))
4994
                                layoutName = pLayout.LayoutName;
4995
                        }
4996
                        writeLine(indent, "Layout Name", layoutName);
4997
                        writeLine(indent, "PaperSpace View", pRecord.IsPaperspaceView);
4998
                        writeLine(indent, "Associated UCS", pRecord.IsUcsAssociatedToView);
4999
                        writeLine(indent, "PaperSpace View", pRecord.ViewAssociatedToViewport);
5000
                        dumpAbstractViewTableRecord(pRecord, indent, node);
5001
                    }
5002
                }
5003
            }
5004
        }
5005
        /************************************************************************/
5006
        /* Dump Xdata                                                           */
5007
        /************************************************************************/
5008
        public void dumpXdata(ResultBuffer xIter, int indent)
5009
        {
5010
            if (xIter == null)
5011
                return;
5012
            writeLine(indent++, "Xdata:");
5013
            /**********************************************************************/
5014
            /* Step through the ResBuf chain                                      */
5015
            /**********************************************************************/
5016
            try
5017
            {
5018
                int rsCount = xIter.Cast<TypedValue>().Count();
5019
                
5020
                foreach (TypedValue resbuf in xIter)
5021
                {
5022
                    writeLine(indent, resbuf);
5023
                }
5024
            }
5025
            catch (System.Exception ex)
5026
            {
5027
            }
5028
            
5029
        }
5030
    }
5031
    class ExProtocolExtension
5032
    {
5033
    }
5034

    
5035
    class Program
5036
    {
5037
        public static XmlDocument xml = null;
5038
        public static double OffsetX = 0;
5039
        public static double OffsetY = 0;
5040
        public static double Scale = 0;
5041
        public static double getDrawing = 0;
5042
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
5043

    
5044
        static void Main(string[] args)
5045
        {
5046
            /********************************************************************/
5047
            /* Initialize Drawings.NET.                                         */
5048
            /********************************************************************/
5049
            bool bSuccess = true;
5050
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
5051
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
5052
            {
5053
                try
5054
                {
5055
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
5056
                    /**********************************************************************/
5057
                    /* Display the Product and Version that created the executable        */
5058
                    /**********************************************************************/
5059
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
5060

    
5061
                    if (args.Length != 5)
5062
                    {
5063
                        Console.WriteLine("\n\n\tusage: OdReadExMgd <filename> <OffsetX> <OffsetY> <Scale> <GenDrawing>");
5064
                        Console.WriteLine("\nPress ENTER to continue...\n");
5065
                        Console.ReadLine();
5066
                        bSuccess = false;
5067
                    }
5068
                    else
5069
                    {
5070
                        Console.WriteLine("\n File Name = " + args[0]);
5071

    
5072
                        double.TryParse(args[1], out Program.OffsetX);
5073
                        double.TryParse(args[2], out Program.OffsetY);
5074
                        double.TryParse(args[3], out Program.Scale);
5075
                        double.TryParse(args[4], out Program.getDrawing);
5076
                        Program.xml = new XmlDocument();
5077
                        {
5078
                            XmlNode root = xml.CreateElement("ID2");
5079
                            Program.xml.AppendChild(root);
5080

    
5081
                            /******************************************************************/
5082
                            /* Create a database and load the drawing into it.                
5083
                            /* first parameter means - do not initialize database- it will be read from file
5084
                             * second parameter is not used by Teigha.NET Classic - it is left for ARX compatibility.
5085
                             * Note the 'using' clause - generally, wrappers should disposed after use, 
5086
                             * to close underlying database objects
5087
                            /******************************************************************/
5088
                            using (Database pDb = new Database(false, false))
5089
                            {
5090
                                pDb.ReadDwgFile(args[0], FileShare.Read, true, "");
5091
                                HostApplicationServices.WorkingDatabase = pDb;
5092
                                /****************************************************************/
5093
                                /* Display the File Version                                     */
5094
                                /****************************************************************/
5095
                                Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion);
5096
                                /****************************************************************/
5097
                                /* Dump the database                                            */
5098
                                /****************************************************************/
5099
                                DbDumper dumper = new DbDumper();
5100
                                dumper.prepareDump(pDb);
5101
                                dumper.ExplodeAndPurgeNestedBlocks(pDb);
5102
                                if (Program.getDrawing == 1)
5103
                                {
5104
                                    dumper.ExportPNG(pDb, args[0]);
5105
                                    dumper.ExportPDF(pDb, args[0]);
5106
                                    dumper.ExportGraphicBlocks(pDb, args[0]);
5107
                                }
5108

    
5109
                                dumper.dump(pDb, 0, Program.xml.DocumentElement);
5110
                            }
5111
                            Program.xml.Save(Path.Combine(Path.GetDirectoryName(args[0]), Path.GetFileNameWithoutExtension(args[0]) + ".xml"));
5112
                        }
5113
                    }
5114
                }
5115
                /********************************************************************/
5116
                /* Display the error                                                */
5117
                /********************************************************************/
5118
                catch (System.Exception e)
5119
                {
5120
                    bSuccess = false;
5121
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
5122
                }
5123

    
5124
                if (bSuccess)
5125
                    Console.WriteLine("OdReadExMgd Finished Successfully");
5126
            }
5127
        }
5128
    }
5129
}
클립보드 이미지 추가 (최대 크기: 500 MB)