프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / MarkusImageCreate / OdReadExMgd.cs @ 7459b663

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

1 30fe44e0 taeseongkim
/////////////////////////////////////////////////////////////////////////////// 
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 = ODA.xml.CreateAttribute("MinExtents");
181
                        MinExtentsAttr.Value = ext.MinPoint.ToString();
182
                        node.Attributes.SetNamedItem(MinExtentsAttr);
183
184
                        XmlAttribute MaxExtentsAttr = ODA.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 = ODA.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 = ODA.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 = ODA.xml.CreateElement(pText.GetRXClass().Name);
238
239
                XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
240
                XAttr.Value = pText.Position.X.ToString();
241
                TextNode.Attributes.SetNamedItem(XAttr);
242
243
                XmlAttribute YAttr = ODA.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 = ODA.xml.CreateAttribute("Angle");
250
                AngleAttr.Value = pText.Rotation.ToString();
251
                TextNode.Attributes.SetNamedItem(AngleAttr);
252
253
                XmlAttribute WidthAttr = ODA.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 = ODA.xml.CreateAttribute("Height");
258
                HeightAttr.Value = pText.Height.ToString();
259
                TextNode.Attributes.SetNamedItem(HeightAttr);
260
261
                XmlAttribute WidthFactorAttr = ODA.xml.CreateAttribute("WidthFactor");
262
                WidthFactorAttr.Value = pText.WidthFactor.ToString();
263
                TextNode.Attributes.SetNamedItem(WidthFactorAttr);
264
265
                XmlAttribute IsDefaultAlignmentAttr = ODA.xml.CreateAttribute("IsDefaultAlignment");
266
                IsDefaultAlignmentAttr.Value = pText.IsDefaultAlignment.ToString();
267
                TextNode.Attributes.SetNamedItem(IsDefaultAlignmentAttr);
268
269
                XmlAttribute AlignmentPointAttr = ODA.xml.CreateAttribute("AlignmentPoint");
270
                AlignmentPointAttr.Value = pText.AlignmentPoint.ToString();
271
                TextNode.Attributes.SetNamedItem(AlignmentPointAttr);
272
273
                XmlAttribute HorizontalModeAttr = ODA.xml.CreateAttribute("HorizontalMode");
274
                HorizontalModeAttr.Value = pText.HorizontalMode.ToString();
275
                TextNode.Attributes.SetNamedItem(HorizontalModeAttr);
276
277
                XmlAttribute VerticalModeAttr = ODA.xml.CreateAttribute("VerticalMode");
278
                VerticalModeAttr.Value = pText.VerticalMode.ToString();
279
                TextNode.Attributes.SetNamedItem(VerticalModeAttr);
280
281
                XmlAttribute IsMirroredInXAttr = ODA.xml.CreateAttribute("IsMirroredInX");
282
                IsMirroredInXAttr.Value = pText.IsMirroredInX.ToString();
283
                TextNode.Attributes.SetNamedItem(IsMirroredInXAttr);
284
285
                XmlAttribute IsMirroredInYAttr = ODA.xml.CreateAttribute("IsMirroredInY");
286
                IsMirroredInYAttr.Value = pText.IsMirroredInY.ToString();
287
                TextNode.Attributes.SetNamedItem(IsMirroredInYAttr);
288
289
                XmlAttribute ObliqueAttr = ODA.xml.CreateAttribute("Oblique");
290
                ObliqueAttr.Value = pText.Oblique.ToString();
291
                TextNode.Attributes.SetNamedItem(ObliqueAttr);
292
293
                XmlAttribute TextStyleAttr = ODA.xml.CreateAttribute("TextStyle");
294
                TextStyleAttr.Value = pText.TextStyleName;
295
                TextNode.Attributes.SetNamedItem(TextStyleAttr);
296
297
                XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
298
                NormalAttr.Value = pText.Normal.ToString();
299
                TextNode.Attributes.SetNamedItem(NormalAttr);
300
301
                XmlAttribute ThicknessAttr = ODA.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 = ODA.xml.CreateAttribute("Handle");
329
                HandleAttr.Value = pAttr.Handle.ToString();
330
                TextNode.Attributes.SetNamedItem(HandleAttr);
331
332
                XmlAttribute TagAttr = ODA.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 = ODA.xml.CreateElement(pAttDef.GetRXClass().Name);
346
347
            XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
348
            HandleAttr.Value = pAttDef.Handle.ToString();
349
            AttributeDefinitionNode.Attributes.SetNamedItem(HandleAttr);
350
351
            XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
352
            XAttr.Value = pAttDef.Position.X.ToString();
353
            AttributeDefinitionNode.Attributes.SetNamedItem(XAttr);
354
355
            XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
356
            YAttr.Value = pAttDef.Position.Y.ToString();
357
            AttributeDefinitionNode.Attributes.SetNamedItem(YAttr);
358
359
            XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
360
            ZAttr.Value = pAttDef.Position.Z.ToString();
361
            AttributeDefinitionNode.Attributes.SetNamedItem(ZAttr);
362
363
            XmlAttribute AngleAttr = ODA.xml.CreateAttribute("Angle");
364
            AngleAttr.Value = pAttDef.Rotation.ToString();
365
            AttributeDefinitionNode.Attributes.SetNamedItem(AngleAttr);
366
367
            XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
368
            NormalAttr.Value = pAttDef.Normal.ToString();
369
            AttributeDefinitionNode.Attributes.SetNamedItem(NormalAttr);
370
371
            XmlAttribute NameAttr = ODA.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 = ODA.xml.CreateAttribute("MinExtents");
380
                MinExtentsAttr.Value = ext.MinPoint.ToString();
381
                AttributeDefinitionNode.Attributes.SetNamedItem(MinExtentsAttr);
382
383
                XmlAttribute MaxExtentsAttr = ODA.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 = ODA.xml.CreateElement(pBlkRef.GetRXClass().Name);
419
420
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
421
                HandleAttr.Value = pBlkRef.Handle.ToString();
422
                BlockReferenceNode.Attributes.SetNamedItem(HandleAttr);
423
424
                XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
425
                XAttr.Value = pBlkRef.Position.X.ToString();
426
                BlockReferenceNode.Attributes.SetNamedItem(XAttr);
427
428
                XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
429
                YAttr.Value = pBlkRef.Position.Y.ToString();
430
                BlockReferenceNode.Attributes.SetNamedItem(YAttr);
431
432
                XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
433
                ZAttr.Value = pBlkRef.Position.Z.ToString();
434
                BlockReferenceNode.Attributes.SetNamedItem(ZAttr);
435
436
                XmlAttribute AngleAttr = ODA.xml.CreateAttribute("Angle");
437
                AngleAttr.Value = pBlkRef.Rotation.ToString();
438
                BlockReferenceNode.Attributes.SetNamedItem(AngleAttr);
439
440
                XmlAttribute ScaleFactorsAttr = ODA.xml.CreateAttribute("ScaleFactors");
441
                ScaleFactorsAttr.Value = pBlkRef.ScaleFactors.ToString();
442
                BlockReferenceNode.Attributes.SetNamedItem(ScaleFactorsAttr);
443
444
                XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
445
                NormalAttr.Value = pBlkRef.Normal.ToString();
446
                BlockReferenceNode.Attributes.SetNamedItem(NormalAttr);
447
448
                XmlAttribute NameAttr = ODA.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 = ODA.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 = ODA.xml.CreateElement("DimData");
580
581
                XmlAttribute CurrentMeasurementAttr = ODA.xml.CreateAttribute("CurrentMeasurement");
582
                CurrentMeasurementAttr.Value = pDim.CurrentMeasurement.ToString();
583
                DimDataNode.Attributes.SetNamedItem(CurrentMeasurementAttr);
584
585
                XmlAttribute DimensionTextAttr = ODA.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 = ODA.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 = ODA.xml.CreateAttribute("Name");
604
                        NameAttr.Value = btr.Name;
605
                        DimDataNode.Attributes.SetNamedItem(NameAttr);
606
                    }
607
                }
608
609
                XmlAttribute DimBlockPositionAttr = ODA.xml.CreateAttribute("DimBlockPosition");
610
                DimBlockPositionAttr.Value = pDim.DimBlockPosition.ToString();
611
                DimDataNode.Attributes.SetNamedItem(DimBlockPositionAttr);
612
613
                XmlAttribute TextPositionAttr = ODA.xml.CreateAttribute("TextPosition");
614
                TextPositionAttr.Value = pDim.TextPosition.ToString();
615
                DimDataNode.Attributes.SetNamedItem(TextPositionAttr);
616
617
                XmlAttribute TextRotationAttr = ODA.xml.CreateAttribute("TextRotation");
618
                TextRotationAttr.Value = pDim.TextRotation.ToString();
619
                DimDataNode.Attributes.SetNamedItem(TextRotationAttr);
620
621
                XmlAttribute DimensionStyleNameAttr = ODA.xml.CreateAttribute("DimensionStyleName");
622
                DimensionStyleNameAttr.Value = pDim.DimensionStyleName.ToString();
623
                DimDataNode.Attributes.SetNamedItem(DimensionStyleNameAttr);
624
625
                XmlAttribute DimtfillclrAttr = ODA.xml.CreateAttribute("Dimtfillclr");
626
                DimtfillclrAttr.Value = pDim.Dimtfillclr.ToString();
627
                DimDataNode.Attributes.SetNamedItem(DimtfillclrAttr);
628
629
                XmlAttribute DimtfillAttr = ODA.xml.CreateAttribute("Dimtfill");
630
                DimtfillAttr.Value = pDim.Dimtfill.ToString();
631
                DimDataNode.Attributes.SetNamedItem(DimtfillAttr);
632
633
                XmlAttribute Dimltex1Attr = ODA.xml.CreateAttribute("Dimltex1");
634
                Dimltex1Attr.Value = pDim.Dimltex1.ToString();
635
                DimDataNode.Attributes.SetNamedItem(Dimltex1Attr);
636
637
                XmlAttribute Dimltex2Attr = ODA.xml.CreateAttribute("Dimltex2");
638
                Dimltex2Attr.Value = pDim.Dimltex2.ToString();
639
                DimDataNode.Attributes.SetNamedItem(Dimltex2Attr);
640
641
                XmlAttribute DimltypeAttr = ODA.xml.CreateAttribute("Dimltype");
642
                DimltypeAttr.Value = pDim.Dimltype.ToString();
643
                DimDataNode.Attributes.SetNamedItem(DimltypeAttr);
644
645
                XmlAttribute HorizontalRotationAttr = ODA.xml.CreateAttribute("HorizontalRotation");
646
                HorizontalRotationAttr.Value = pDim.HorizontalRotation.ToString();
647
                DimDataNode.Attributes.SetNamedItem(HorizontalRotationAttr);
648
649
                XmlAttribute ElevationAttr = ODA.xml.CreateAttribute("Elevation");
650
                ElevationAttr.Value = pDim.Elevation.ToString();
651
                DimDataNode.Attributes.SetNamedItem(ElevationAttr);
652
653
                XmlAttribute NormalAttr = ODA.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 = ODA.xml.CreateElement(pDim.GetRXClass().Name);
673
674
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
675
                HandleAttr.Value = pDim.Handle.ToString();
676
                DimNode.Attributes.SetNamedItem(HandleAttr);
677
678
                XmlAttribute ArcPointAttr = ODA.xml.CreateAttribute("ArcPoint");
679
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
680
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
681
682
                XmlAttribute XLine1StartAttr = ODA.xml.CreateAttribute("XLine1Start");
683
                XLine1StartAttr.Value = pDim.XLine1Start.ToString();
684
                DimNode.Attributes.SetNamedItem(XLine1StartAttr);
685
686
                XmlAttribute XLine1EndAttr = ODA.xml.CreateAttribute("XLine1End");
687
                XLine1EndAttr.Value = pDim.XLine1End.ToString();
688
                DimNode.Attributes.SetNamedItem(XLine1EndAttr);
689
690
                XmlAttribute XLine2StartAttr = ODA.xml.CreateAttribute("XLine2Start");
691
                XLine2StartAttr.Value = pDim.XLine2Start.ToString();
692
                DimNode.Attributes.SetNamedItem(XLine2StartAttr);
693
694
                XmlAttribute XLine2EndAttr = ODA.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 = ODA.xml.CreateElement(pVertex.GetRXClass().Name);
714
715
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
716
                HandleAttr.Value = pVertex.Handle.ToString();
717
                VertexNode.Attributes.SetNamedItem(HandleAttr);
718
719
                XmlAttribute VertexTypeAttr = ODA.xml.CreateAttribute("VertexType");
720
                VertexTypeAttr.Value = pVertex.VertexType.ToString();
721
                VertexNode.Attributes.SetNamedItem(VertexTypeAttr);
722
723
                XmlAttribute PositionAttr = ODA.xml.CreateAttribute("Position");
724
                PositionAttr.Value = pVertex.Position.ToString();
725
                VertexNode.Attributes.SetNamedItem(PositionAttr);
726
727
                XmlAttribute StartWidthAttr = ODA.xml.CreateAttribute("StartWidth");
728
                StartWidthAttr.Value = pVertex.StartWidth.ToString();
729
                VertexNode.Attributes.SetNamedItem(StartWidthAttr);
730
731
                XmlAttribute EndWidthAttr = ODA.xml.CreateAttribute("EndWidth");
732
                EndWidthAttr.Value = pVertex.EndWidth.ToString();
733
                VertexNode.Attributes.SetNamedItem(EndWidthAttr);
734
735
                XmlAttribute BulgeAttr = ODA.xml.CreateAttribute("Bulge");
736
                BulgeAttr.Value = pVertex.Bulge.ToString();
737
                VertexNode.Attributes.SetNamedItem(BulgeAttr);
738
739
                if (pVertex.Bulge != 0)
740
                {
741
                    XmlAttribute BulgeAngleAttr = ODA.xml.CreateAttribute("BulgeAngle");
742
                    BulgeAngleAttr.Value = (4 * Math.Atan(pVertex.Bulge)).ToString();
743
                    VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
744
                }
745
746
                XmlAttribute TangentUsedAttr = ODA.xml.CreateAttribute("TangentUsed");
747
                TangentUsedAttr.Value = pVertex.TangentUsed.ToString();
748
                VertexNode.Attributes.SetNamedItem(TangentUsedAttr);
749
                if (pVertex.TangentUsed)
750
                {
751
                    XmlAttribute TangentAttr = ODA.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
            List<Vertex2d> Vertices = new List<Vertex2d>();
773
            int i = 0;
774
            foreach (ObjectId obj in pPolyline)
775
            {
776
                using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
777
                {
778
                    if (dbObj is Vertex2d)
779
                    {
780
                        Vertices.Add((Vertex2d)dbObj);
781
                        /// dump2dVertex(indent, (Vertex2d)dbObj, i++);
782
                    }
783
                }
784
            }
785
786
            if (node != null)
787
            {
788
                XmlNode Polyline2dNode = ODA.xml.CreateElement(pPolyline.GetRXClass().Name);
789
790
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
791
                HandleAttr.Value = pPolyline.Handle.ToString();
792
                Polyline2dNode.Attributes.SetNamedItem(HandleAttr);
793
794
                XmlAttribute CountAttr = ODA.xml.CreateAttribute("Count");
795
                CountAttr.Value = Vertices.Count.ToString();
796
                Polyline2dNode.Attributes.SetNamedItem(CountAttr);
797
798
                XmlAttribute ElevationAttr = ODA.xml.CreateAttribute("Elevation");
799
                ElevationAttr.Value = pPolyline.Elevation.ToString();
800
                Polyline2dNode.Attributes.SetNamedItem(ElevationAttr);
801
802
                XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
803
                NormalAttr.Value = pPolyline.Normal.ToString();
804
                Polyline2dNode.Attributes.SetNamedItem(NormalAttr);
805
806
                XmlAttribute ThicknessAttr = ODA.xml.CreateAttribute("Thickness");
807
                ThicknessAttr.Value = pPolyline.Thickness.ToString();
808
                Polyline2dNode.Attributes.SetNamedItem(ThicknessAttr);
809
810
                XmlAttribute ClosedAttr = ODA.xml.CreateAttribute("Closed");
811
                ClosedAttr.Value = pPolyline.Closed.ToString();
812
                Polyline2dNode.Attributes.SetNamedItem(ClosedAttr);
813
814
                foreach (var vt in Vertices)
815
                {
816
                    XmlNode VertexNode = ODA.xml.CreateElement("Vertex");
817
818
                    XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
819
                    XAttr.Value = vt.Position.X.ToString();
820
                    VertexNode.Attributes.SetNamedItem(XAttr);
821
822
                    XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
823
                    YAttr.Value = vt.Position.Y.ToString();
824
                    VertexNode.Attributes.SetNamedItem(YAttr);
825
826
                    XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
827
                    ZAttr.Value = vt.Position.Z.ToString();
828
                    VertexNode.Attributes.SetNamedItem(ZAttr);
829
830
                    Polyline2dNode.AppendChild(VertexNode);
831
                }
832
833
                dumpCurveData(pPolyline, indent, node);
834
835
                node.AppendChild(Polyline2dNode);
836
837
                return Polyline2dNode;
838
            }
839
840
            return null;
841
        }
842
843
844
        /************************************************************************/
845
        /* Dump 3D Polyline Vertex data                                         */
846
        /************************************************************************/
847
        XmlNode dump3dPolylineVertex(int indent, PolylineVertex3d pVertex, int i, XmlNode node)
848
        {
849
            if (node != null)
850
            {
851
                XmlNode VertexNode = ODA.xml.CreateElement(pVertex.GetRXClass().Name);
852
853
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
854
                HandleAttr.Value = pVertex.Handle.ToString();
855
                VertexNode.Attributes.SetNamedItem(HandleAttr);
856
857
                XmlAttribute VertexxTypeAttr = ODA.xml.CreateAttribute("VertexType");
858
                VertexxTypeAttr.Value = pVertex.VertexType.ToString();
859
                VertexNode.Attributes.SetNamedItem(VertexxTypeAttr);
860
861
                XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
862
                XAttr.Value = pVertex.Position.X.ToString();
863
                VertexNode.Attributes.SetNamedItem(XAttr);
864
865
                XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
866
                YAttr.Value = pVertex.Position.Y.ToString();
867
                VertexNode.Attributes.SetNamedItem(YAttr);
868
869
                XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
870
                ZAttr.Value = pVertex.Position.Z.ToString();
871
                VertexNode.Attributes.SetNamedItem(ZAttr);
872
873
                node.AppendChild(VertexNode);
874
875
                return VertexNode;
876
            }
877
878
            return null;
879
        }
880
881
        /************************************************************************/
882
        /* 3D Polyline Dumper                                                   */
883
        /************************************************************************/
884
        XmlNode dump(Polyline3d pPolyline, int indent, XmlNode node)
885
        {
886
            if (node != null)
887
            {
888
                XmlNode pPolylineNode = ODA.xml.CreateElement(pPolyline.GetRXClass().Name);
889
890
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
891
                HandleAttr.Value = pPolyline.Handle.ToString();
892
                pPolylineNode.Attributes.SetNamedItem(HandleAttr);
893
894
                /********************************************************************/
895
                /* Dump the vertices                                                */
896
                /********************************************************************/
897
                int i = 0;
898
                foreach (ObjectId obj in pPolyline)
899
                {
900
                    using (DBObject dbObj = (DBObject)obj.GetObject(OpenMode.ForRead))
901
                    {
902
                        if (dbObj is PolylineVertex3d)
903
                        {
904
                            dump3dPolylineVertex(indent, (PolylineVertex3d)dbObj, i++, pPolylineNode);
905
                        }
906
                    }
907
                }
908
                dumpCurveData(pPolyline, indent, pPolylineNode);
909
910
                node.AppendChild(pPolylineNode);
911
912
                return pPolylineNode;
913
            }
914
915
            return null;
916
        }
917
918
919
        /************************************************************************/
920
        /* 3DSolid Dumper                                                       */
921
        /************************************************************************/
922
        XmlNode dump(Solid3d pSolid, int indent, XmlNode node)
923
        {
924
            if (node != null)
925
            {
926
                XmlNode SolidNode = ODA.xml.CreateElement(pSolid.GetRXClass().Name);
927
928
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
929
                HandleAttr.Value = pSolid.Handle.ToString();
930
                SolidNode.Attributes.SetNamedItem(HandleAttr);
931
932
                dumpEntityData(pSolid, indent, node);
933
934
                node.AppendChild(SolidNode);
935
936
                return SolidNode;
937
            }
938
939
            return null;
940
        }
941
942
943
        /************************************************************************/
944
        /* 3 Point Angular Dimension Dumper                                     */
945
        /************************************************************************/
946
        XmlNode dump(Point3AngularDimension pDim, int indent, XmlNode node)
947
        {
948
            if (node != null)
949
            {
950
                XmlElement DimNode = ODA.xml.CreateElement(pDim.GetRXClass().Name);
951
952
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
953
                HandleAttr.Value = pDim.Handle.ToString();
954
                DimNode.Attributes.SetNamedItem(HandleAttr);
955
956
                XmlAttribute ArcPointAttr = ODA.xml.CreateAttribute("ArcPoint");
957
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
958
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
959
960
                XmlAttribute CenterPointAttr = ODA.xml.CreateAttribute("CenterPoint");
961
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
962
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
963
964
                XmlAttribute XLine1PointAttr = ODA.xml.CreateAttribute("XLine1Point");
965
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
966
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
967
968
                XmlAttribute XLine2PointAttr = ODA.xml.CreateAttribute("XLine2Point");
969
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
970
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
971
972
                dumpDimData(pDim, indent, DimNode);
973
974
                return DimNode;
975
            }
976
977
            return null;
978
        }
979
980
        /************************************************************************/
981
        /* Aligned Dimension Dumper                                             */
982
        /************************************************************************/
983
        XmlNode dump(AlignedDimension pDim, int indent, XmlNode node)
984
        {
985
            if (node != null)
986
            {
987
                XmlElement DimNode = ODA.xml.CreateElement(pDim.GetRXClass().Name);
988
989
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
990
                HandleAttr.Value = pDim.Handle.ToString();
991
                DimNode.Attributes.SetNamedItem(HandleAttr);
992
993
                XmlAttribute DimLinePointAttr = ODA.xml.CreateAttribute("DimLinePoint");
994
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
995
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
996
997
                XmlAttribute ObliqueAttr = ODA.xml.CreateAttribute("Oblique");
998
                ObliqueAttr.Value = pDim.Oblique.ToString();
999
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
1000
1001
                XmlAttribute XLine1PointAttr = ODA.xml.CreateAttribute("XLine1Point");
1002
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1003
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1004
1005
                XmlAttribute XLine2PointAttr = ODA.xml.CreateAttribute("XLine2Point");
1006
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1007
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1008
1009
                dumpDimData(pDim, indent, DimNode);
1010
1011
                return DimNode;
1012
            }
1013
1014
            return null;
1015
        }
1016
1017
        /************************************************************************/
1018
        /* Arc Dumper                                                           */
1019
        /************************************************************************/
1020
        XmlNode dump(Arc pArc, int indent, XmlNode node)
1021
        {
1022
            if (node != null)
1023
            {
1024
                XmlElement ArcNode = ODA.xml.CreateElement(pArc.GetRXClass().Name);
1025
1026
                XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
1027
                XAttr.Value = pArc.Center.X.ToString();
1028
                ArcNode.Attributes.SetNamedItem(XAttr);
1029
1030
                XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
1031
                YAttr.Value = pArc.Center.Y.ToString();
1032
                ArcNode.Attributes.SetNamedItem(YAttr);
1033
1034
                XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
1035
                ZAttr.Value = pArc.Center.Z.ToString();
1036
                ArcNode.Attributes.SetNamedItem(ZAttr);
1037
1038
                XmlAttribute RadiusAttr = ODA.xml.CreateAttribute("Radius");
1039
                RadiusAttr.Value = pArc.Radius.ToString();
1040
                ArcNode.Attributes.SetNamedItem(RadiusAttr);
1041
1042
                XmlAttribute StartAngleAttr = ODA.xml.CreateAttribute("StartAngle");
1043
                StartAngleAttr.Value = pArc.StartAngle.ToString();
1044
                ArcNode.Attributes.SetNamedItem(StartAngleAttr);
1045
1046
                XmlAttribute EndAngleAttr = ODA.xml.CreateAttribute("EndAngle");
1047
                EndAngleAttr.Value = pArc.EndAngle.ToString();
1048
                ArcNode.Attributes.SetNamedItem(EndAngleAttr);
1049
1050
                XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
1051
                NormalAttr.Value = pArc.Normal.ToString();
1052
                ArcNode.Attributes.SetNamedItem(NormalAttr);
1053
1054
                XmlAttribute ThicknessAttr = ODA.xml.CreateAttribute("Thickness");
1055
                ThicknessAttr.Value = pArc.Normal.ToString();
1056
                ArcNode.Attributes.SetNamedItem(ThicknessAttr);
1057
1058
                writeLine(indent++, pArc.GetRXClass().Name, pArc.Handle);
1059
                dumpCurveData(pArc, indent, ArcNode);
1060
1061
                XmlNode StartPointNode = ODA.xml.CreateElement("Vertex");
1062
                {
1063
                    XAttr = ODA.xml.CreateAttribute("X");
1064
                    XAttr.Value = pArc.StartPoint.X.ToString();
1065
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1066
1067
                    YAttr = ODA.xml.CreateAttribute("Y");
1068
                    YAttr.Value = pArc.StartPoint.Y.ToString();
1069
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1070
1071
                    ZAttr = ODA.xml.CreateAttribute("Z");
1072
                    ZAttr.Value = pArc.StartPoint.Z.ToString();
1073
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1074
                }
1075
                ArcNode.AppendChild(StartPointNode);
1076
1077
                XmlNode EndPointNode = ODA.xml.CreateElement("Vertex");
1078
                {
1079
                    XAttr = ODA.xml.CreateAttribute("X");
1080
                    XAttr.Value = pArc.EndPoint.X.ToString();
1081
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1082
1083
                    YAttr = ODA.xml.CreateAttribute("Y");
1084
                    YAttr.Value = pArc.EndPoint.Y.ToString();
1085
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1086
1087
                    ZAttr = ODA.xml.CreateAttribute("Z");
1088
                    ZAttr.Value = pArc.EndPoint.Z.ToString();
1089
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1090
                }
1091
                ArcNode.AppendChild(EndPointNode);
1092
1093
                node.AppendChild(ArcNode);
1094
1095
                return ArcNode;
1096
            }
1097
1098
            return null;
1099
        }
1100
1101
        /************************************************************************/
1102
        /* Arc Dimension Dumper                                                 */
1103
        /************************************************************************/
1104
        XmlNode dump(ArcDimension pDim, int indent, XmlNode node)
1105
        {
1106
            if (node != null)
1107
            {
1108
                XmlElement DimNode = ODA.xml.CreateElement(pDim.GetRXClass().Name);
1109
1110
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
1111
                HandleAttr.Value = pDim.Handle.ToString();
1112
                DimNode.Attributes.SetNamedItem(HandleAttr);
1113
1114
                XmlAttribute ArcPointAttr = ODA.xml.CreateAttribute("ArcPoint");
1115
                ArcPointAttr.Value = pDim.ArcPoint.ToString();
1116
                DimNode.Attributes.SetNamedItem(ArcPointAttr);
1117
1118
                XmlAttribute CenterPointAttr = ODA.xml.CreateAttribute("CenterPoint");
1119
                CenterPointAttr.Value = pDim.CenterPoint.ToString();
1120
                DimNode.Attributes.SetNamedItem(CenterPointAttr);
1121
1122
                XmlAttribute ArcSymbolTypeAttr = ODA.xml.CreateAttribute("ArcSymbolType");
1123
                ArcSymbolTypeAttr.Value = pDim.ArcSymbolType.ToString();
1124
                DimNode.Attributes.SetNamedItem(ArcSymbolTypeAttr);
1125
1126
                XmlAttribute IsPartialAttr = ODA.xml.CreateAttribute("IsPartial");
1127
                IsPartialAttr.Value = pDim.IsPartial.ToString();
1128
                DimNode.Attributes.SetNamedItem(IsPartialAttr);
1129
1130
                XmlAttribute HasLeaderAttr = ODA.xml.CreateAttribute("HasLeader");
1131
                HasLeaderAttr.Value = pDim.HasLeader.ToString();
1132
                DimNode.Attributes.SetNamedItem(HasLeaderAttr);
1133
1134
                if (pDim.HasLeader)
1135
                {
1136
                    XmlAttribute Leader1PointAttr = ODA.xml.CreateAttribute("Leader1Point");
1137
                    Leader1PointAttr.Value = pDim.Leader1Point.ToString();
1138
                    DimNode.Attributes.SetNamedItem(Leader1PointAttr);
1139
1140
                    XmlAttribute Leader2PointAttr = ODA.xml.CreateAttribute("Leader2Point");
1141
                    Leader2PointAttr.Value = pDim.Leader2Point.ToString();
1142
                    DimNode.Attributes.SetNamedItem(Leader2PointAttr);
1143
                }
1144
1145
                XmlAttribute XLine1PointAttr = ODA.xml.CreateAttribute("XLine1Point");
1146
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
1147
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
1148
1149
                XmlAttribute XLine2PointAttr = ODA.xml.CreateAttribute("XLine2Point");
1150
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
1151
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
1152
1153
                dumpDimData(pDim, indent, DimNode);
1154
1155
                return DimNode;
1156
            }
1157
1158
            return null;
1159
        }
1160
1161
1162
        /************************************************************************/
1163
        /* Block Reference Dumper                                                */
1164
        /************************************************************************/
1165
        void dump(BlockReference pBlkRef, int indent, XmlNode node)
1166
        {
1167
            using (BlockTableRecord pRecord = (BlockTableRecord)pBlkRef.BlockTableRecord.Open(OpenMode.ForRead))
1168
            {
1169
                XmlNode BlockRefNode = dumpBlockRefData(pBlkRef, indent, node);
1170
                if (BlockRefNode != null)
1171
                {
1172
                    XmlAttribute NameAttr = ODA.xml.CreateAttribute("Name");
1173
                    NameAttr.Value = pRecord.Name;
1174
                    BlockRefNode.Attributes.SetNamedItem(NameAttr);
1175
                }
1176
            }
1177
        }
1178
1179
        /************************************************************************/
1180
        /* Body Dumper                                                          */
1181
        /************************************************************************/
1182
        XmlNode dump(Body pBody, int indent, XmlNode node)
1183
        {
1184
            if (node != null)
1185
            {
1186
                XmlNode BodyNode = ODA.xml.CreateElement(pBody.GetRXClass().Name);
1187
1188
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
1189
                HandleAttr.Value = pBody.Handle.ToString();
1190
                BodyNode.Attributes.SetNamedItem(HandleAttr);
1191
1192
                dumpEntityData(pBody, indent, BodyNode);
1193
1194
                return BodyNode;
1195
            }
1196
1197
            return null;
1198
        }
1199
1200
1201
        /************************************************************************/
1202
        /* Circle Dumper                                                        */
1203
        /************************************************************************/
1204
        XmlNode dump(Circle pCircle, int indent, XmlNode node)
1205
        {
1206
            if (node != null)
1207
            {
1208
                XmlElement CircleNode = ODA.xml.CreateElement(pCircle.GetRXClass().Name);
1209
1210
                XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
1211
                XAttr.Value = pCircle.Center.X.ToString();
1212
                CircleNode.Attributes.SetNamedItem(XAttr);
1213
1214
                XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
1215
                YAttr.Value = pCircle.Center.Y.ToString();
1216
                CircleNode.Attributes.SetNamedItem(YAttr);
1217
1218
                XmlAttribute RadiusAttr = ODA.xml.CreateAttribute("Radius");
1219
                RadiusAttr.Value = pCircle.Radius.ToString();
1220
                CircleNode.Attributes.SetNamedItem(RadiusAttr);
1221
1222
                XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
1223
                NormalAttr.Value = pCircle.Normal.ToString();
1224
                CircleNode.Attributes.SetNamedItem(NormalAttr);
1225
1226
                XmlAttribute ThicknessAttr = ODA.xml.CreateAttribute("Thickness");
1227
                ThicknessAttr.Value = pCircle.Thickness.ToString();
1228
                CircleNode.Attributes.SetNamedItem(ThicknessAttr);
1229
1230
                dumpCurveData(pCircle, indent, CircleNode);
1231
1232
                node.AppendChild(CircleNode);
1233
1234
                return CircleNode;
1235
            }
1236
1237
            return null;
1238
        }
1239
1240
        /************************************************************************/
1241
        /* Diametric Dimension Dumper                                           */
1242
        /************************************************************************/
1243
        XmlNode dump(DiametricDimension pDim, int indent, XmlNode node)
1244
        {
1245
            if (node != null)
1246
            {
1247
                XmlElement DimNode = ODA.xml.CreateElement(pDim.GetRXClass().Name);
1248
1249
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
1250
                HandleAttr.Value = pDim.Handle.ToString();
1251
                DimNode.Attributes.SetNamedItem(HandleAttr);
1252
1253
                XmlAttribute ChordPointAttr = ODA.xml.CreateAttribute("ChordPoint");
1254
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
1255
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
1256
1257
                XmlAttribute FarChordPointAttr = ODA.xml.CreateAttribute("FarChordPoint");
1258
                FarChordPointAttr.Value = pDim.FarChordPoint.ToString();
1259
                DimNode.Attributes.SetNamedItem(FarChordPointAttr);
1260
1261
                XmlAttribute LeaderLengthAttr = ODA.xml.CreateAttribute("LeaderLength");
1262
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
1263
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
1264
1265
                dumpDimData(pDim, indent, DimNode);
1266
1267
                return DimNode;
1268
            }
1269
1270
            return null;
1271
        }
1272
1273
        /************************************************************************/
1274
        /* Ellipse Dumper                                                       */
1275
        /************************************************************************/
1276
        void dump(Ellipse pEllipse, int indent, XmlNode node)
1277
        {
1278
            if (node != null)
1279
            {
1280
                XmlElement EllipseNode = ODA.xml.CreateElement(pEllipse.GetRXClass().Name);
1281
1282
                writeLine(indent++, pEllipse.GetRXClass().Name, pEllipse.Handle);
1283
1284
                XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
1285
                XAttr.Value = pEllipse.Center.X.ToString();
1286
                EllipseNode.Attributes.SetNamedItem(XAttr);
1287
1288
                XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
1289
                YAttr.Value = pEllipse.Center.Y.ToString();
1290
                EllipseNode.Attributes.SetNamedItem(YAttr);
1291
1292
                XmlAttribute MajorAxisAttr = ODA.xml.CreateAttribute("MajorAxis");
1293
                MajorAxisAttr.Value = pEllipse.MajorAxis.ToString();
1294
                EllipseNode.Attributes.SetNamedItem(MajorAxisAttr);
1295
1296
                XmlAttribute MinorAxisAttr = ODA.xml.CreateAttribute("MinorAxis");
1297
                MinorAxisAttr.Value = pEllipse.MinorAxis.ToString();
1298
                EllipseNode.Attributes.SetNamedItem(MinorAxisAttr);
1299
1300
                XmlAttribute MajorRadiusAttr = ODA.xml.CreateAttribute("MajorRadius");
1301
                MajorRadiusAttr.Value = pEllipse.MajorRadius.ToString();
1302
                EllipseNode.Attributes.SetNamedItem(MajorRadiusAttr);
1303
1304
                XmlAttribute MinorRadiusAttr = ODA.xml.CreateAttribute("MinorRadius");
1305
                MinorRadiusAttr.Value = pEllipse.MinorRadius.ToString();
1306
                EllipseNode.Attributes.SetNamedItem(MinorRadiusAttr);
1307
1308
                XmlAttribute RadiusRatioAttr = ODA.xml.CreateAttribute("RadiusRatio");
1309
                RadiusRatioAttr.Value = pEllipse.RadiusRatio.ToString();
1310
                EllipseNode.Attributes.SetNamedItem(RadiusRatioAttr);
1311
1312
                XmlAttribute StartAngleAttr = ODA.xml.CreateAttribute("StartAngle");
1313
                StartAngleAttr.Value = pEllipse.StartAngle.ToString();
1314
                EllipseNode.Attributes.SetNamedItem(StartAngleAttr);
1315
1316
                XmlAttribute EndAngleAttr = ODA.xml.CreateAttribute("EndAngle");
1317
                EndAngleAttr.Value = pEllipse.EndAngle.ToString();
1318
                EllipseNode.Attributes.SetNamedItem(EndAngleAttr);
1319
1320
                XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
1321
                NormalAttr.Value = pEllipse.Normal.ToString();
1322
                EllipseNode.Attributes.SetNamedItem(NormalAttr);
1323
1324
                dumpCurveData(pEllipse, indent, EllipseNode);
1325
1326
                node.AppendChild(EllipseNode);
1327
            }
1328
        }
1329
1330
        /************************************************************************/
1331
        /* Face Dumper                                                       */
1332
        /************************************************************************/
1333
        XmlNode dump(Face pFace, int indent, XmlNode node)
1334
        {
1335
            if (node != null)
1336
            {
1337
                XmlElement FaceNode = ODA.xml.CreateElement(pFace.GetRXClass().Name);
1338
1339
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
1340
                HandleAttr.Value = pFace.Handle.ToString();
1341
                FaceNode.Attributes.SetNamedItem(HandleAttr);
1342
1343
                for (short i = 0; i < 4; i++)
1344
                {
1345
                    XmlElement VertexNode = ODA.xml.CreateElement("Vertex");
1346
1347
                    Point3d pt = pFace.GetVertexAt(i);
1348
                    XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
1349
                    XAttr.Value = pt.X.ToString();
1350
                    VertexNode.Attributes.SetNamedItem(XAttr);
1351
1352
                    XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
1353
                    YAttr.Value = pt.Y.ToString();
1354
                    VertexNode.Attributes.SetNamedItem(YAttr);
1355
1356
                    XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
1357
                    ZAttr.Value = pt.Z.ToString();
1358
                    VertexNode.Attributes.SetNamedItem(ZAttr);
1359
1360
                    XmlAttribute VisibleAttr = ODA.xml.CreateAttribute("Visible");
1361
                    VisibleAttr.Value = pFace.IsEdgeVisibleAt(i).ToString();
1362
                    VertexNode.Attributes.SetNamedItem(VisibleAttr);
1363
1364
                    FaceNode.AppendChild(VertexNode);
1365
                }
1366
                dumpEntityData(pFace, indent, FaceNode);
1367
1368
                node.AppendChild(FaceNode);
1369
1370
                return FaceNode;
1371
            }
1372
1373
            return null;
1374
        }
1375
1376
        /************************************************************************/
1377
        /* FCF Dumper                                                           */
1378
        /************************************************************************/
1379
        void dump(FeatureControlFrame pFcf, int indent)
1380
        {
1381
            writeLine(indent++, pFcf.GetRXClass().Name, pFcf.Handle);
1382
            writeLine(indent, "Location", pFcf.Location);
1383
            writeLine(indent, "Text", pFcf.Text);
1384
            writeLine(indent, "Dimension Style", pFcf.DimensionStyleName);
1385
            writeLine(indent, "Dimension Gap", pFcf.Dimgap);
1386
            writeLine(indent, "Dimension Scale", pFcf.Dimscale);
1387
            writeLine(indent, "Text Height", pFcf.Dimtxt);
1388
            writeLine(indent, "Frame Color", pFcf.Dimclrd);
1389
            writeLine(indent, "Text Style", pFcf.TextStyleName);
1390
            writeLine(indent, "Text Color", pFcf.Dimclrd);
1391
            writeLine(indent, "X-Direction", pFcf.Direction);
1392
            writeLine(indent, "Normal", pFcf.Normal);
1393
            dumpEntityData(pFcf, indent, ODA.xml.DocumentElement);
1394
        }
1395
1396
        /************************************************************************/
1397
        /* Hatch Dumper                                                         */
1398
        /************************************************************************/
1399
        /***********************************************************************/
1400
        /* Dump Polyline Loop                                                  */
1401
        /***********************************************************************/
1402
        static void dumpPolylineType(int loopIndex, Hatch pHatch, int indent)
1403
        {
1404
            HatchLoop hl = pHatch.GetLoopAt(loopIndex);
1405
            for (int i = 0; i < hl.Polyline.Count; i++)
1406
            {
1407
                BulgeVertex bv = hl.Polyline[i];
1408
                writeLine(indent, "Vertex " + i.ToString(), bv.Vertex.ToString());
1409
                writeLine(indent + 1, "Bulge " + i.ToString(), bv.Bulge);
1410
                writeLine(indent + 1, "Bulge angle " + i.ToString(), toDegreeString(4 * Math.Atan(bv.Bulge)));
1411
            }
1412
        }
1413
1414
        /**********************************************************************/
1415
        /* Dump Circular Arc Edge                                             */
1416
        /**********************************************************************/
1417
        static void dumpCircularArcEdge(int indent, CircularArc2d pCircArc)
1418
        {
1419
            writeLine(indent, "Center", pCircArc.Center);
1420
            writeLine(indent, "Radius", pCircArc.Radius);
1421
            writeLine(indent, "Start Angle", toDegreeString(pCircArc.StartAngle));
1422
            writeLine(indent, "End Angle", toDegreeString(pCircArc.EndAngle));
1423
            writeLine(indent, "Clockwise", pCircArc.IsClockWise);
1424
        }
1425
1426
        /**********************************************************************/
1427
        /* Dump Elliptical Arc Edge                                           */
1428
        /**********************************************************************/
1429
        static void dumpEllipticalArcEdge(int indent, EllipticalArc2d pEllipArc)
1430
        {
1431
            writeLine(indent, "Center", pEllipArc.Center);
1432
            writeLine(indent, "Major Radius", pEllipArc.MajorRadius);
1433
            writeLine(indent, "Minor Radius", pEllipArc.MinorRadius);
1434
            writeLine(indent, "Major Axis", pEllipArc.MajorAxis);
1435
            writeLine(indent, "Minor Axis", pEllipArc.MinorAxis);
1436
            writeLine(indent, "Start Angle", toDegreeString(pEllipArc.StartAngle));
1437
            writeLine(indent, "End Angle", toDegreeString(pEllipArc.EndAngle));
1438
            writeLine(indent, "Clockwise", pEllipArc.IsClockWise);
1439
        }
1440
1441
        /**********************************************************************/
1442
        /* Dump NurbCurve Edge                                           */
1443
        /**********************************************************************/
1444
        static void dumpNurbCurveEdge(int indent, NurbCurve2d pNurbCurve)
1445
        {
1446
            NurbCurve2dData d = pNurbCurve.DefinitionData;
1447
            writeLine(indent, "Degree", d.Degree);
1448
            writeLine(indent, "Rational", d.Rational);
1449
            writeLine(indent, "Periodic", d.Periodic);
1450
1451
            writeLine(indent, "Number of Control Points", d.ControlPoints.Count);
1452
            for (int i = 0; i < d.ControlPoints.Count; i++)
1453
            {
1454
                writeLine(indent, "Control Point " + i.ToString(), d.ControlPoints[i]);
1455
            }
1456
            writeLine(indent, "Number of Knots", d.Knots.Count);
1457
            for (int i = 0; i < d.Knots.Count; i++)
1458
            {
1459
                writeLine(indent, "Knot " + i.ToString(), d.Knots[i]);
1460
            }
1461
1462
            if (d.Rational)
1463
            {
1464
                writeLine(indent, "Number of Weights", d.Weights.Count);
1465
                for (int i = 0; i < d.Weights.Count; i++)
1466
                {
1467
                    writeLine(indent, "Weight " + i.ToString(), d.Weights[i]);
1468
                }
1469
            }
1470
        }
1471
1472
        /***********************************************************************/
1473
        /* Dump Edge Loop                                                      */
1474
        /***********************************************************************/
1475
        static void dumpEdgesType(int loopIndex, Hatch pHatch, int indent)
1476
        {
1477
            Curve2dCollection edges = pHatch.GetLoopAt(loopIndex).Curves;
1478
            for (int i = 0; i < (int)edges.Count; i++)
1479
            {
1480
                using (Curve2d pEdge = edges[i])
1481
                {
1482
                    writeLine(indent, string.Format("Edge {0}", i), pEdge.GetType().Name);
1483
                    switch (pEdge.GetType().Name)
1484
                    {
1485
                        case "LineSegment2d":
1486
                            break;
1487
                        case "CircularArc2d":
1488
                            dumpCircularArcEdge(indent + 1, (CircularArc2d)pEdge);
1489
                            break;
1490
                        case "EllipticalArc2d":
1491
                            dumpEllipticalArcEdge(indent + 1, (EllipticalArc2d)pEdge);
1492
                            break;
1493
                        case "NurbCurve2d":
1494
                            dumpNurbCurveEdge(indent + 1, (NurbCurve2d)pEdge);
1495
                            break;
1496
                    }
1497
1498
                    /******************************************************************/
1499
                    /* Common Edge Properties                                         */
1500
                    /******************************************************************/
1501
                    Interval interval = pEdge.GetInterval();
1502
                    writeLine(indent + 1, "Start Point", pEdge.EvaluatePoint(interval.LowerBound));
1503
                    writeLine(indent + 1, "End Point", pEdge.EvaluatePoint(interval.UpperBound));
1504
                    writeLine(indent + 1, "Closed", pEdge.IsClosed());
1505
                }
1506
            }
1507
        }
1508
1509
        /************************************************************************/
1510
        /* Convert the specified value to a LoopType string                     */
1511
        /************************************************************************/
1512
        string toLooptypeString(HatchLoopTypes loopType)
1513
        {
1514
            string retVal = "";
1515
            if ((loopType & HatchLoopTypes.External) != 0)
1516
                retVal = retVal + " | kExternal";
1517
1518
            if ((loopType & HatchLoopTypes.Polyline) != 0)
1519
                retVal = retVal + " | kPolyline";
1520
1521
            if ((loopType & HatchLoopTypes.Derived) != 0)
1522
                retVal = retVal + " | kDerived";
1523
1524
            if ((loopType & HatchLoopTypes.Textbox) != 0)
1525
                retVal = retVal + " | kTextbox";
1526
1527
            if ((loopType & HatchLoopTypes.Outermost) != 0)
1528
                retVal = retVal + " | kOutermost";
1529
1530
            if ((loopType & HatchLoopTypes.NotClosed) != 0)
1531
                retVal = retVal + " | kNotClosed";
1532
1533
            if ((loopType & HatchLoopTypes.SelfIntersecting) != 0)
1534
                retVal = retVal + " | kSelfIntersecting";
1535
1536
            if ((loopType & HatchLoopTypes.TextIsland) != 0)
1537
                retVal = retVal + " | kTextIsland";
1538
1539
            if ((loopType & HatchLoopTypes.Duplicate) != 0)
1540
                retVal = retVal + " | kDuplicate";
1541
1542
            return retVal == "" ? "kDefault" : retVal.Substring(3);
1543
        }
1544
1545
        void dump(Hatch pHatch, int indent)
1546
        {
1547
            writeLine(indent++, pHatch.GetRXClass().Name, pHatch.Handle);
1548
            writeLine(indent, "Hatch Style", pHatch.HatchStyle);
1549
            writeLine(indent, "Hatch Object Type", pHatch.HatchObjectType);
1550
            writeLine(indent, "Is Hatch", pHatch.IsHatch);
1551
            writeLine(indent, "Is Gradient", !pHatch.IsGradient);
1552
            if (pHatch.IsHatch)
1553
            {
1554
                /******************************************************************/
1555
                /* Dump Hatch Parameters                                          */
1556
                /******************************************************************/
1557
                writeLine(indent, "Pattern Type", pHatch.PatternType);
1558
                switch (pHatch.PatternType)
1559
                {
1560
                    case HatchPatternType.PreDefined:
1561
                    case HatchPatternType.CustomDefined:
1562
                        writeLine(indent, "Pattern Name", pHatch.PatternName);
1563
                        writeLine(indent, "Solid Fill", pHatch.IsSolidFill);
1564
                        if (!pHatch.IsSolidFill)
1565
                        {
1566
                            writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1567
                            writeLine(indent, "Pattern Scale", pHatch.PatternScale);
1568
                        }
1569
                        break;
1570
                    case HatchPatternType.UserDefined:
1571
                        writeLine(indent, "Pattern Angle", toDegreeString(pHatch.PatternAngle));
1572
                        writeLine(indent, "Pattern Double", pHatch.PatternDouble);
1573
                        writeLine(indent, "Pattern Space", pHatch.PatternSpace);
1574
                        break;
1575
                }
1576
                DBObjectCollection entitySet = new DBObjectCollection();
1577
                Handle hhh = pHatch.Handle;
1578
                if (hhh.Value == 1692) //69C)
1579
                {
1580
                    pHatch.Explode(entitySet);
1581
                    return;
1582
                }
1583
                if (hhh.Value == 1693) //69D)
1584
                {
1585
                    try
1586
                    {
1587
                        pHatch.Explode(entitySet);
1588
                    }
1589
                    catch (System.Exception e)
1590
                    {
1591
                        if (e.Message == "eCannotExplodeEntity")
1592
                        {
1593
                            writeLine(indent, "Hatch " + e.Message + ": ", pHatch.Handle);
1594
                            return;
1595
                        }
1596
                    }
1597
                }
1598
            }
1599
            if (pHatch.IsGradient)
1600
            {
1601
                /******************************************************************/
1602
                /* Dump Gradient Parameters                                       */
1603
                /******************************************************************/
1604
                writeLine(indent, "Gradient Type", pHatch.GradientType);
1605
                writeLine(indent, "Gradient Name", pHatch.GradientName);
1606
                writeLine(indent, "Gradient Angle", toDegreeString(pHatch.GradientAngle));
1607
                writeLine(indent, "Gradient Shift", pHatch.GradientShift);
1608
                writeLine(indent, "Gradient One-Color Mode", pHatch.GradientOneColorMode);
1609
                if (pHatch.GradientOneColorMode)
1610
                {
1611
                    writeLine(indent, "ShadeTintValue", pHatch.ShadeTintValue);
1612
                }
1613
                GradientColor[] colors = pHatch.GetGradientColors();
1614
                for (int i = 0; i < colors.Length; i++)
1615
                {
1616
                    writeLine(indent, string.Format("Color         {0}", i), colors[i].get_Color());
1617
                    writeLine(indent, string.Format("Interpolation {0}", i), colors[i].get_Value());
1618
                }
1619
            }
1620
1621
            /********************************************************************/
1622
            /* Dump Associated Objects                                          */
1623
            /********************************************************************/
1624
            writeLine(indent, "Associated objects", pHatch.Associative);
1625
            foreach (ObjectId id in pHatch.GetAssociatedObjectIds())
1626
            {
1627
                writeLine(indent + 1, id.ObjectClass.Name, id.Handle);
1628
            }
1629
1630
            /********************************************************************/
1631
            /* Dump Loops                                                       */
1632
            /********************************************************************/
1633
            writeLine(indent, "Loops", pHatch.NumberOfLoops);
1634
            for (int i = 0; i < pHatch.NumberOfLoops; i++)
1635
            {
1636
                writeLine(indent + 1, "Loop " + i.ToString(), toLooptypeString(pHatch.LoopTypeAt(i)));
1637
1638
                /******************************************************************/
1639
                /* Dump Loop                                                      */
1640
                /******************************************************************/
1641
                if ((pHatch.LoopTypeAt(i) & HatchLoopTypes.Polyline) != 0)
1642
                {
1643
                    dumpPolylineType(i, pHatch, indent + 2);
1644
                }
1645
                else
1646
                {
1647
                    dumpEdgesType(i, pHatch, indent + 2);
1648
                }
1649
                /******************************************************************/
1650
                /* Dump Associated Objects                                        */
1651
                /******************************************************************/
1652
                if (pHatch.Associative)
1653
                {
1654
                    writeLine(indent + 2, "Associated objects");
1655
                    foreach (ObjectId id in pHatch.GetAssociatedObjectIdsAt(i))
1656
                    {
1657
                        writeLine(indent + 3, id.ObjectClass.Name, id.Handle);
1658
                    }
1659
                }
1660
            }
1661
1662
            writeLine(indent, "Elevation", pHatch.Elevation);
1663
            writeLine(indent, "Normal", pHatch.Normal);
1664
            dumpEntityData(pHatch, indent, ODA.xml.DocumentElement);
1665
        }
1666
1667
        /************************************************************************/
1668
        /* Leader Dumper                                                          */
1669
        /************************************************************************/
1670
        void dump(Leader pLeader, int indent)
1671
        {
1672
            writeLine(indent++, pLeader.GetRXClass().Name, pLeader.Handle);
1673
            writeLine(indent, "Dimension Style", pLeader.DimensionStyleName);
1674
1675
            writeLine(indent, "Annotation");
1676
            if (!pLeader.Annotation.IsNull)
1677
            {
1678
                writeLine(indent++, pLeader.Annotation.ObjectClass.Name, pLeader.Annotation.Handle);
1679
            }
1680
            writeLine(indent + 1, "Type", pLeader.AnnoType);
1681
            writeLine(indent + 1, "Height", pLeader.AnnoHeight);
1682
            writeLine(indent + 1, "Width", pLeader.AnnoWidth);
1683
            writeLine(indent + 1, "Offset", pLeader.AnnotationOffset);
1684
            writeLine(indent, "Has Arrowhead", pLeader.HasArrowHead);
1685
            writeLine(indent, "Has Hook Line", pLeader.HasHookLine);
1686
            writeLine(indent, "Splined", pLeader.IsSplined);
1687
1688
            for (int i = 0; i < pLeader.NumVertices; i++)
1689
            {
1690
                writeLine(indent, string.Format("Vertex {0}", i), pLeader.VertexAt(i));
1691
            }
1692
            writeLine(indent, "Normal", pLeader.Normal);
1693
            dumpCurveData(pLeader, indent, ODA.xml.DocumentElement);
1694
        }
1695
1696
        /************************************************************************/
1697
        /* Line Dumper                                                          */
1698
        /************************************************************************/
1699
        void dump(Line pLine, int indent, XmlNode node)
1700
        {
1701
            if (node != null && pLine != null && pLine.Length != 0)
1702
            {
1703
                XmlNode LineNode = ODA.xml.CreateElement(pLine.GetRXClass().Name);
1704
                XmlAttribute LengthAttr = ODA.xml.CreateAttribute("Length");
1705
                LengthAttr.Value = pLine.Length.ToString();
1706
                LineNode.Attributes.SetNamedItem(LengthAttr);
1707
1708
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
1709
                HandleAttr.Value = pLine.Handle.ToString();
1710
                LineNode.Attributes.SetNamedItem(HandleAttr);
1711
1712
                XmlNode StartPointNode = ODA.xml.CreateElement("Vertex");
1713
                {
1714
                    XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
1715
                    XAttr.Value = pLine.StartPoint.X.ToString();
1716
                    StartPointNode.Attributes.SetNamedItem(XAttr);
1717
1718
                    XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
1719
                    YAttr.Value = pLine.StartPoint.Y.ToString();
1720
                    StartPointNode.Attributes.SetNamedItem(YAttr);
1721
1722
                    XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
1723
                    ZAttr.Value = pLine.StartPoint.Z.ToString();
1724
                    StartPointNode.Attributes.SetNamedItem(ZAttr);
1725
                }
1726
                LineNode.AppendChild(StartPointNode);
1727
1728
                XmlNode EndPointNode = ODA.xml.CreateElement("Vertex");
1729
                {
1730
                    XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
1731
                    XAttr.Value = pLine.EndPoint.X.ToString();
1732
                    EndPointNode.Attributes.SetNamedItem(XAttr);
1733
1734
                    XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
1735
                    YAttr.Value = pLine.EndPoint.Y.ToString();
1736
                    EndPointNode.Attributes.SetNamedItem(YAttr);
1737
1738
                    XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
1739
                    ZAttr.Value = pLine.EndPoint.Z.ToString();
1740
                    EndPointNode.Attributes.SetNamedItem(ZAttr);
1741
                }
1742
                LineNode.AppendChild(EndPointNode);
1743
1744
                XmlAttribute NormalAttr = ODA.xml.CreateAttribute("Normal");
1745
                NormalAttr.Value = pLine.Normal.ToString();
1746
                LineNode.Attributes.SetNamedItem(NormalAttr);
1747
1748
                XmlAttribute ThicknessAttr = ODA.xml.CreateAttribute("Thickness");
1749
                ThicknessAttr.Value = pLine.Thickness.ToString();
1750
                LineNode.Attributes.SetNamedItem(ThicknessAttr);
1751
1752
                dumpEntityData(pLine, indent, LineNode);
1753
1754
                node.AppendChild(LineNode);
1755
            }
1756
            else
1757
            {
1758
                int d = 0;
1759
            }
1760
        }
1761
1762
        /************************************************************************/
1763
        /* MInsertBlock Dumper                                                  */
1764
        /************************************************************************/
1765
        void dump(MInsertBlock pMInsert, int indent, XmlNode node)
1766
        {
1767
            writeLine(indent++, pMInsert.GetRXClass().Name, pMInsert.Handle);
1768
1769
            using (BlockTableRecord pRecord = (BlockTableRecord)pMInsert.BlockTableRecord.Open(OpenMode.ForRead))
1770
            {
1771
                writeLine(indent, "Name", pRecord.Name);
1772
                writeLine(indent, "Rows", pMInsert.Rows);
1773
                writeLine(indent, "Columns", pMInsert.Columns);
1774
                writeLine(indent, "Row Spacing", pMInsert.RowSpacing);
1775
                writeLine(indent, "Column Spacing", pMInsert.ColumnSpacing);
1776
                dumpBlockRefData(pMInsert, indent, node);
1777
            }
1778
        }
1779
1780
        /************************************************************************/
1781
        /* Mline Dumper                                                         */
1782
        /************************************************************************/
1783
        void dump(Mline pMline, int indent)
1784
        {
1785
            writeLine(indent++, pMline.GetRXClass().Name, pMline.Handle);
1786
            writeLine(indent, "Style", pMline.Style);
1787
            writeLine(indent, "Closed", pMline.IsClosed);
1788
            writeLine(indent, "Scale", pMline.Scale);
1789
            writeLine(indent, "Suppress Start Caps", pMline.SupressStartCaps);
1790
            writeLine(indent, "Suppress End Caps", pMline.SupressEndCaps);
1791
            writeLine(indent, "Normal", pMline.Normal);
1792
1793
            /********************************************************************/
1794
            /* Dump the segment data                                            */
1795
            /********************************************************************/
1796
            for (int i = 0; i < pMline.NumberOfVertices; i++)
1797
            {
1798
                writeLine(indent, "Segment", i);
1799
                writeLine(indent + 1, "Vertex", pMline.VertexAt(i));
1800
            }
1801
            dumpEntityData(pMline, indent, ODA.xml.DocumentElement);
1802
        }
1803
1804
        /************************************************************************/
1805
        /* MText Dumper                                                         */
1806
        /************************************************************************/
1807
        /// <summary>
1808
        /// convert MText to normal Text
1809
        /// </summary>
1810
        /// <param name="pMText"></param>
1811
        /// <param name="indent"></param>
1812
        /// <param name="node"></param>
1813
        void dump(MText pMText, int indent, XmlNode node)
1814
        {
1815
            DBObjectCollection objColl = new DBObjectCollection();
1816
            pMText.Explode(objColl);
1817
            foreach (var obj in objColl)
1818
            {
1819
                dumpTextData(obj as DBText, indent, node);
1820
            }
1821
        }
1822
1823
        /************************************************************************/
1824
        /* Ordinate Dimension Dumper                                            */
1825
        /************************************************************************/
1826
        XmlNode dump(OrdinateDimension pDim, int indent, XmlNode node)
1827
        {
1828
            if (node != null)
1829
            {
1830
                XmlElement DimNode = ODA.xml.CreateElement(pDim.GetRXClass().Name);
1831
1832
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
1833
                HandleAttr.Value = pDim.Handle.ToString();
1834
                DimNode.Attributes.SetNamedItem(HandleAttr);
1835
1836
                XmlAttribute DefiningPointAttr = ODA.xml.CreateAttribute("DefiningPoint");
1837
                DefiningPointAttr.Value = pDim.DefiningPoint.ToString();
1838
                DimNode.Attributes.SetNamedItem(DefiningPointAttr);
1839
1840
                XmlAttribute UsingXAxisAttr = ODA.xml.CreateAttribute("UsingXAxis");
1841
                UsingXAxisAttr.Value = pDim.UsingXAxis.ToString();
1842
                DimNode.Attributes.SetNamedItem(UsingXAxisAttr);
1843
1844
                XmlAttribute UsingYAxisAttr = ODA.xml.CreateAttribute("UsingYAxis");
1845
                UsingYAxisAttr.Value = pDim.UsingYAxis.ToString();
1846
                DimNode.Attributes.SetNamedItem(UsingYAxisAttr);
1847
1848
                XmlAttribute LeaderEndPointAttr = ODA.xml.CreateAttribute("LeaderEndPoint");
1849
                LeaderEndPointAttr.Value = pDim.LeaderEndPoint.ToString();
1850
                DimNode.Attributes.SetNamedItem(LeaderEndPointAttr);
1851
1852
                XmlAttribute OriginAttr = ODA.xml.CreateAttribute("Origin");
1853
                OriginAttr.Value = pDim.Origin.ToString();
1854
                DimNode.Attributes.SetNamedItem(OriginAttr);
1855
1856
                dumpDimData(pDim, indent, DimNode);
1857
1858
                return DimNode;
1859
            }
1860
1861
            return null;
1862
        }
1863
1864
        /************************************************************************/
1865
        /* PolyFaceMesh Dumper                                                  */
1866
        /************************************************************************/
1867
        XmlNode dump(PolyFaceMesh pPoly, int indent, XmlNode node)
1868
        {
1869
            if (node != null)
1870
            {
1871
                XmlElement PolyNode = ODA.xml.CreateElement(pPoly.GetRXClass().Name);
1872
1873
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
1874
                HandleAttr.Value = pPoly.Handle.ToString();
1875
                PolyNode.Attributes.SetNamedItem(HandleAttr);
1876
1877
                XmlAttribute NumVerticesAttr = ODA.xml.CreateAttribute("NumVertices");
1878
                NumVerticesAttr.Value = pPoly.NumVertices.ToString();
1879
                PolyNode.Attributes.SetNamedItem(NumVerticesAttr);
1880
1881
                XmlAttribute NumFacesAttr = ODA.xml.CreateAttribute("NumFaces");
1882
                NumFacesAttr.Value = pPoly.NumFaces.ToString();
1883
                PolyNode.Attributes.SetNamedItem(NumFacesAttr);
1884
1885
                /********************************************************************/
1886
                /* dump vertices and faces                                          */
1887
                /********************************************************************/
1888
                int vertexCount = 0;
1889
                int faceCount = 0;
1890
                foreach (ObjectId objId in pPoly)
1891
                {
1892
                    using (Entity ent = (Entity)objId.GetObject(OpenMode.ForRead))
1893
                    {
1894
                        if (ent is PolyFaceMeshVertex)
1895
                        {
1896
                            PolyFaceMeshVertex pVertex = (PolyFaceMeshVertex)ent;
1897
1898
                            XmlElement VertexNode = ODA.xml.CreateElement(pVertex.GetRXClass().Name);
1899
1900
                            XmlAttribute _HandleAttr = ODA.xml.CreateAttribute("Handle");
1901
                            _HandleAttr.Value = pVertex.Handle.ToString();
1902
                            VertexNode.Attributes.SetNamedItem(_HandleAttr);
1903
1904
                            XmlAttribute PositionAttr = ODA.xml.CreateAttribute("Position");
1905
                            PositionAttr.Value = pVertex.Position.ToString();
1906
                            VertexNode.Attributes.SetNamedItem(PositionAttr);
1907
1908
                            dumpEntityData(pVertex, indent + 1, VertexNode);
1909
1910
                            PolyNode.AppendChild(VertexNode);
1911
                        }
1912
                        else if (ent is FaceRecord)
1913
                        {
1914
                            FaceRecord pFace = (FaceRecord)ent;
1915
                            string face = "{";
1916
                            for (short i = 0; i < 4; i++)
1917
                            {
1918
                                if (i > 0)
1919
                                {
1920
                                    face = face + " ";
1921
                                }
1922
                                face = face + pFace.GetVertexAt(i).ToString();
1923
                            }
1924
1925
                            face += "}";
1926
1927
                            XmlElement FaceNode = ODA.xml.CreateElement(pFace.GetRXClass().Name);
1928
1929
                            XmlAttribute _HandleAttr = ODA.xml.CreateAttribute("Handle");
1930
                            _HandleAttr.Value = pFace.Handle.ToString();
1931
                            FaceNode.Attributes.SetNamedItem(_HandleAttr);
1932
                            FaceNode.InnerText = face;
1933
1934
                            dumpEntityData(pFace, indent + 1, FaceNode);
1935
1936
                            PolyNode.AppendChild(FaceNode);
1937
                        }
1938
                        else
1939
                        { // Unknown entity type
1940
                            writeLine(indent, "Unexpected Entity");
1941
                        }
1942
                    }
1943
                }
1944
                dumpEntityData(pPoly, indent, PolyNode);
1945
1946
                return PolyNode;
1947
            }
1948
1949
            return null;
1950
        }
1951
1952
        /************************************************************************/
1953
        /* Ole2Frame                                                            */
1954
        /************************************************************************/
1955
        void dump(Ole2Frame pOle, int indent)
1956
        {
1957
            writeLine(indent++, pOle.GetRXClass().Name, pOle.Handle);
1958
1959
            Rectangle3d pos = (Rectangle3d)pOle.Position3d;
1960
            writeLine(indent, "Lower Left", pos.LowerLeft);
1961
            writeLine(indent, "Lower Right", pos.LowerRight);
1962
            writeLine(indent, "Upper Left", pos.UpperLeft);
1963
            writeLine(indent, "Upper Right", pos.UpperRight);
1964
            writeLine(indent, "Type", pOle.Type);
1965
            writeLine(indent, "User Type", pOle.UserType);
1966
            if (pOle.Type == Ole2Frame.ItemType.Link)
1967
            {
1968
                writeLine(indent, "Link Name", pOle.LinkName);
1969
                writeLine(indent, "Link Path", pOle.LinkPath);
1970
            }
1971
            writeLine(indent, "Output Quality", pOle.OutputQuality);
1972
            dumpEntityData(pOle, indent, ODA.xml.DocumentElement);
1973
        }
1974
1975
        /************************************************************************/
1976
        /* Point Dumper                                                         */
1977
        /************************************************************************/
1978
        void dump(DBPoint pPoint, int indent)
1979
        {
1980
            writeLine(indent++, pPoint.GetRXClass().Name, pPoint.Handle);
1981
            writeLine(indent, "Position", pPoint.Position);
1982
            writeLine(indent, "ECS Rotation", toDegreeString(pPoint.EcsRotation));
1983
            writeLine(indent, "Normal", pPoint.Normal);
1984
            writeLine(indent, "Thickness", pPoint.Thickness);
1985
            dumpEntityData(pPoint, indent, ODA.xml.DocumentElement);
1986
        }
1987
1988
        /************************************************************************/
1989
        /* Polygon Mesh Dumper                                                  */
1990
        /************************************************************************/
1991
        void dump(PolygonMesh pPoly, int indent)
1992
        {
1993
            writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
1994
            writeLine(indent, "m Size", pPoly.MSize);
1995
            writeLine(indent, "m-Closed", pPoly.IsMClosed);
1996
            writeLine(indent, "m Surface Density", pPoly.MSurfaceDensity);
1997
            writeLine(indent, "n Size", pPoly.NSize);
1998
            writeLine(indent, "n-Closed", pPoly.IsNClosed);
1999
            writeLine(indent, "n Surface Density", pPoly.NSurfaceDensity);
2000
            /********************************************************************/
2001
            /* dump vertices                                                    */
2002
            /********************************************************************/
2003
            int vertexCount = 0;
2004
            foreach (object o in pPoly)
2005
            {
2006
                PolygonMeshVertex pVertex = o as PolygonMeshVertex;
2007
                if (pVertex != null)
2008
                {
2009
                    writeLine(indent, pVertex.GetRXClass().Name, vertexCount++);
2010
                    writeLine(indent + 1, "Handle", pVertex.Handle);
2011
                    writeLine(indent + 1, "Position", pVertex.Position);
2012
                    writeLine(indent + 1, "Type", pVertex.VertexType);
2013
                }
2014
            }
2015
            dumpEntityData(pPoly, indent, ODA.xml.DocumentElement);
2016
        }
2017
2018
        /************************************************************************/
2019
        /* Polyline Dumper                                                      */
2020
        /************************************************************************/
2021
        void dump(Teigha.DatabaseServices.Polyline pPoly, int indent, XmlNode node)
2022
        {
2023
            if (pPoly != null && pPoly.Length != 0)
2024
            {
2025
                writeLine(indent++, pPoly.GetRXClass().Name, pPoly.Handle);
2026
                writeLine(indent, "Has Width", pPoly.HasWidth);
2027
                if (!pPoly.HasWidth)
2028
                {
2029
                    writeLine(indent, "Constant Width", pPoly.ConstantWidth);
2030
                }
2031
2032
                /********************************************************************/
2033
                /* dump vertices                                                    */
2034
                /********************************************************************/
2035
                if (node != null)
2036
                {
2037
                    XmlNode PolylineNode = ODA.xml.CreateElement(pPoly.GetRXClass().Name);
2038
                    XmlAttribute LengthAttr = ODA.xml.CreateAttribute("Length");
2039
                    LengthAttr.Value = pPoly.Length.ToString();
2040
                    PolylineNode.Attributes.SetNamedItem(LengthAttr);
2041
2042
                    XmlAttribute CountAttr = ODA.xml.CreateAttribute("Count");
2043
                    CountAttr.Value = pPoly.NumberOfVertices.ToString();
2044
                    PolylineNode.Attributes.SetNamedItem(CountAttr);
2045
2046
                    XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
2047
                    HandleAttr.Value = pPoly.Handle.ToString();
2048
                    PolylineNode.Attributes.SetNamedItem(HandleAttr);
2049
2050
                    XmlAttribute ClosedAttr = ODA.xml.CreateAttribute("Closed");
2051
                    ClosedAttr.Value = pPoly.Closed.ToString();
2052
                    PolylineNode.Attributes.SetNamedItem(ClosedAttr);
2053
2054
                    for (int i = 0; i < pPoly.NumberOfVertices; i++)
2055
                    {
2056
                        XmlNode VertexNode = ODA.xml.CreateElement("Vertex");
2057
2058
                        XmlAttribute SegmentTypeAttr = ODA.xml.CreateAttribute("SegmentType");
2059
                        SegmentTypeAttr.Value = pPoly.GetSegmentType(i).ToString();
2060
2061
                        Point3d pt = pPoly.GetPoint3dAt(i);
2062
                        XmlAttribute XAttr = ODA.xml.CreateAttribute("X");
2063
                        XAttr.Value = pt.X.ToString();
2064
                        VertexNode.Attributes.SetNamedItem(XAttr);
2065
2066
                        XmlAttribute YAttr = ODA.xml.CreateAttribute("Y");
2067
                        YAttr.Value = pt.Y.ToString();
2068
                        VertexNode.Attributes.SetNamedItem(YAttr);
2069
2070
                        XmlAttribute ZAttr = ODA.xml.CreateAttribute("Z");
2071
                        ZAttr.Value = pt.Z.ToString();
2072
                        VertexNode.Attributes.SetNamedItem(ZAttr);
2073
2074
                        if (pPoly.HasWidth)
2075
                        {
2076
                            XmlAttribute StartWidthAttr = ODA.xml.CreateAttribute("StartWidth");
2077
                            StartWidthAttr.Value = pPoly.GetStartWidthAt(i).ToString();
2078
                            VertexNode.Attributes.SetNamedItem(StartWidthAttr);
2079
2080
                            XmlAttribute EndWidthAttr = ODA.xml.CreateAttribute("EndWidth");
2081
                            EndWidthAttr.Value = pPoly.GetEndWidthAt(i).ToString();
2082
                            VertexNode.Attributes.SetNamedItem(EndWidthAttr);
2083
                        }
2084
                        if (pPoly.HasBulges)
2085
                        {
2086
                            XmlAttribute BulgeAttr = ODA.xml.CreateAttribute("Bulge");
2087
                            BulgeAttr.Value = pPoly.GetBulgeAt(i).ToString();
2088
                            VertexNode.Attributes.SetNamedItem(BulgeAttr);
2089
2090
                            if (pPoly.GetSegmentType(i) == SegmentType.Arc)
2091
                            {
2092
                                XmlAttribute BulgeAngleAttr = ODA.xml.CreateAttribute("BulgeAngle");
2093
                                BulgeAngleAttr.Value = pPoly.GetBulgeAt(i).ToString();
2094
                                VertexNode.Attributes.SetNamedItem(BulgeAngleAttr);
2095
                            }
2096
                        }
2097
2098
                        PolylineNode.AppendChild(VertexNode);
2099
                    }
2100
2101
                    dumpEntityData(pPoly, indent, PolylineNode);
2102
                    node.AppendChild(PolylineNode);
2103
                }
2104
            }
2105
            else
2106
            {
2107
                int d = 0;
2108
            }
2109
        }
2110
2111
        class DrawContextDumper : Context
2112
        {
2113
            Database _db;
2114
            public DrawContextDumper(Database db)
2115
            {
2116
                _db = db;
2117
            }
2118
            public override Database Database
2119
            {
2120
                get { return _db; }
2121
            }
2122
            public override bool IsBoundaryClipping
2123
            {
2124
                get { return false; }
2125
            }
2126
            public override bool IsPlotGeneration
2127
            {
2128
                get { return false; }
2129
            }
2130
            public override bool IsPostScriptOut
2131
            {
2132
                get { return false; }
2133
            }
2134
        }
2135
        class SubEntityTraitsDumper : SubEntityTraits
2136
        {
2137
            short _color;
2138
            int _drawFlags;
2139
            FillType _ft;
2140
            ObjectId _layer;
2141
            ObjectId _linetype;
2142
            LineWeight _lineWeight;
2143
            Mapper _mapper;
2144
            double _lineTypeScale;
2145
            ObjectId _material;
2146
            PlotStyleDescriptor _plotStyleDescriptor;
2147
            bool _sectionable;
2148
            bool _selectionOnlyGeometry;
2149
            ShadowFlags _shadowFlags;
2150
            double _thickness;
2151
            EntityColor _trueColor;
2152
            Transparency _transparency;
2153
            ObjectId _visualStyle;
2154
            public SubEntityTraitsDumper(Database db)
2155
            {
2156
                _drawFlags = 0; // kNoDrawFlags 
2157
                _color = 0;
2158
                _ft = FillType.FillAlways;
2159
                _layer = db.Clayer;
2160
                _linetype = db.Celtype;
2161
                _lineWeight = db.Celweight;
2162
                _lineTypeScale = db.Celtscale;
2163
                _material = db.Cmaterial;
2164
                _shadowFlags = ShadowFlags.ShadowsIgnore;
2165
                _thickness = 0;
2166
                _trueColor = new EntityColor(ColorMethod.None);
2167
                _transparency = new Transparency();
2168
            }
2169
2170
            protected override void SetLayerFlags(LayerFlags flags)
2171
            {
2172
                writeLine(0, string.Format("SubEntityTraitsDumper.SetLayerFlags(flags = {0})", flags));
2173
            }
2174
            public override void AddLight(ObjectId lightId)
2175
            {
2176
                writeLine(0, string.Format("SubEntityTraitsDumper.AddLight(lightId = {0})", lightId.ToString()));
2177
            }
2178
            public override void SetupForEntity(Entity entity)
2179
            {
2180
                writeLine(0, string.Format("SubEntityTraitsDumper.SetupForEntity(entity = {0})", entity.ToString()));
2181
            }
2182
2183
            public override short Color
2184
            {
2185
                get { return _color; }
2186
                set { _color = value; }
2187
            }
2188
            public override int DrawFlags
2189
            {
2190
                get { return _drawFlags; }
2191
                set { _drawFlags = value; }
2192
            }
2193
            public override FillType FillType
2194
            {
2195
                get { return _ft; }
2196
                set { _ft = value; }
2197
            }
2198
            public override ObjectId Layer
2199
            {
2200
                get { return _layer; }
2201
                set { _layer = value; }
2202
            }
2203
            public override ObjectId LineType
2204
            {
2205
                get { return _linetype; }
2206
                set { _linetype = value; }
2207
            }
2208
            public override double LineTypeScale
2209
            {
2210
                get { return _lineTypeScale; }
2211
                set { _lineTypeScale = value; }
2212
            }
2213
            public override LineWeight LineWeight
2214
            {
2215
                get { return _lineWeight; }
2216
                set { _lineWeight = value; }
2217
            }
2218
            public override Mapper Mapper
2219
            {
2220
                get { return _mapper; }
2221
                set { _mapper = value; }
2222
            }
2223
            public override ObjectId Material
2224
            {
2225
                get { return _material; }
2226
                set { _material = value; }
2227
            }
2228
            public override PlotStyleDescriptor PlotStyleDescriptor
2229
            {
2230
                get { return _plotStyleDescriptor; }
2231
                set { _plotStyleDescriptor = value; }
2232
            }
2233
            public override bool Sectionable
2234
            {
2235
                get { return _sectionable; }
2236
                set { _sectionable = value; }
2237
            }
2238
            public override bool SelectionOnlyGeometry
2239
            {
2240
                get { return _selectionOnlyGeometry; }
2241
                set { _selectionOnlyGeometry = value; }
2242
            }
2243
            public override ShadowFlags ShadowFlags
2244
            {
2245
                get { return _shadowFlags; }
2246
                set { _shadowFlags = value; }
2247
            }
2248
            public override double Thickness
2249
            {
2250
                get { return _thickness; }
2251
                set { _thickness = value; }
2252
            }
2253
            public override EntityColor TrueColor
2254
            {
2255
                get { return _trueColor; }
2256
                set { _trueColor = value; }
2257
            }
2258
            public override Transparency Transparency
2259
            {
2260
                get { return _transparency; }
2261
                set { _transparency = value; }
2262
            }
2263
            public override ObjectId VisualStyle
2264
            {
2265
                get { return _visualStyle; }
2266
                set { _visualStyle = value; }
2267
            }
2268
            public override void SetSelectionMarker(IntPtr sm)
2269
            {
2270
            }
2271
        }
2272
        class WorldGeometryDumper : WorldGeometry
2273
        {
2274
            Stack<Matrix3d> modelMatrix;
2275
            Stack<ClipBoundary> clips;
2276
            int indent;
2277
            public WorldGeometryDumper(int indent)
2278
              : base()
2279
            {
2280
                this.indent = indent;
2281
                modelMatrix = new Stack<Matrix3d>();
2282
                clips = new Stack<ClipBoundary>();
2283
                modelMatrix.Push(Matrix3d.Identity);
2284
            }
2285
            public override Matrix3d ModelToWorldTransform
2286
            {
2287
                get { return modelMatrix.Peek(); }
2288
            }
2289
            public override Matrix3d WorldToModelTransform
2290
            {
2291
                get { return modelMatrix.Peek().Inverse(); }
2292
            }
2293
2294
            public override Matrix3d PushOrientationTransform(OrientationBehavior behavior)
2295
            {
2296
                writeLine(indent, string.Format("WorldGeometry.PushOrientationTransform(behavior = {0})", behavior));
2297
                return new Matrix3d();
2298
            }
2299
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point2d offset)
2300
            {
2301
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2302
                return new Matrix3d();
2303
            }
2304
            public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point3d offset)
2305
            {
2306
                writeLine(indent, string.Format("WorldGeometry.PushPositionTransform(behavior = {0}, offset = {1})", behavior, offset));
2307
                return new Matrix3d();
2308
            }
2309
            public override bool OwnerDraw(GdiDrawObject gdiDrawObject, Point3d position, Vector3d u, Vector3d v)
2310
            {
2311
                writeLine(indent, string.Format("WorldGeometry.OwnerDraw(gdiDrawObject = {0}, position = {1}, u = {2}, v = {3})", gdiDrawObject, position, u, v));
2312
                return false;
2313
            }
2314
            public override bool Polyline(Teigha.GraphicsInterface.Polyline polylineObj)
2315
            {
2316
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}", polylineObj));
2317
                return false;
2318
            }
2319
            public override bool Polypoint(Point3dCollection points, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2320
            {
2321
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, normals = {1}, subentityMarkers = {2}", points, normals, subentityMarkers));
2322
                return false;
2323
            }
2324
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, Vector3dCollection normals, IntPtrCollection subentityMarkers)
2325
            {
2326
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, normals = {2}, subentityMarkers = {3}", points, colors, normals, subentityMarkers));
2327
                return false;
2328
            }
2329
            public override bool Polypoint(Point3dCollection points, EntityColorCollection colors, TransparencyCollection transparency, Vector3dCollection normals, IntPtrCollection subentityMarkers, int pointSize)
2330
            {
2331
                writeLine(indent, string.Format("WorldGeometry.Polypoint(points = {0}, colors = {1}, transparency = {2}, normals = {3}, subentityMarkers = {4}, pointSize = {5}", points, colors, transparency, normals, subentityMarkers, pointSize));
2332
                return false;
2333
            }
2334
            public override bool PolyPolyline(Teigha.GraphicsInterface.PolylineCollection polylineCollection)
2335
            {
2336
                writeLine(indent, string.Format("WorldGeometry.PolyPolyline(polylineCollection = {0}", polylineCollection));
2337
                return false;
2338
            }
2339
            public override bool PolyPolygon(UInt32Collection numPolygonPositions, Point3dCollection polygonPositions, UInt32Collection numPolygonPoints, Point3dCollection polygonPoints, EntityColorCollection outlineColors, LinetypeCollection outlineTypes, EntityColorCollection fillColors, Teigha.Colors.TransparencyCollection fillOpacities)
2340
            {
2341
                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));
2342
                return false;
2343
            }
2344
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point2d extents)
2345
            {
2346
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2347
                return new Matrix3d();
2348
            }
2349
            public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point3d extents)
2350
            {
2351
                writeLine(indent, string.Format("WorldGeometry.PushScaleTransform(behavior = {0}, extents = {1})", behavior, extents));
2352
                return new Matrix3d();
2353
            }
2354
            public override bool EllipticalArc(Point3d center, Vector3d normal, double majorAxisLength, double minorAxisLength, double startDegreeInRads, double endDegreeInRads, double tiltDegreeInRads, ArcType arType)
2355
            {
2356
                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));
2357
                return false;
2358
            }
2359
            public override bool Circle(Point3d center, double radius, Vector3d normal)
2360
            {
2361
                writeLine(indent, string.Format("WorldGeometry.Circle(center = {0}, radius = {1}, normal = {2})", center, radius, normal));
2362
                return false;
2363
            }
2364
            public override bool Circle(Point3d firstPoint, Point3d secondPoint, Point3d thirdPoint)
2365
            {
2366
                writeLine(indent, string.Format("WorldGeometry.Circle(firstPoint = {0}, secondPoint = {1}, thirdPoint = {2})", firstPoint, secondPoint, thirdPoint));
2367
                return false;
2368
            }
2369
            public override bool CircularArc(Point3d start, Point3d point, Point3d endingPoint, ArcType arcType)
2370
            {
2371
                writeLine(indent, string.Format("WorldGeometry.CircularArc(start = {0}, point = {1}, endingPoint = {2}, arcType = {3})", start, point, endingPoint, arcType));
2372
                return false;
2373
            }
2374
            public override bool CircularArc(Point3d center, double radius, Vector3d normal, Vector3d startVector, double sweepAngle, ArcType arcType)
2375
            {
2376
                writeLine(indent, string.Format("WorldGeometry.CircularArc(center = {0}, radius = {1}, normal = {2}, startVector = {3}, sweepAngle = {4}, arcType = {5}", center, radius, normal, startVector, sweepAngle, arcType));
2377
                return false;
2378
            }
2379
            public override bool Draw(Drawable value)
2380
            {
2381
                writeLine(indent, string.Format("WorldGeometry.Draw(value = {0}", value));
2382
                return false;
2383
            }
2384
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v)
2385
            {
2386
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}", position, u, v));
2387
                return false;
2388
            }
2389
            public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v, TransparencyMode transparencyMode)
2390
            {
2391
                writeLine(indent, string.Format("WorldGeometry.Image(imageSource = , position = {1}, Vector3d = {2}, Vector3d = {3}, transparencyMode = {4}", position, u, v, transparencyMode));
2392
                return false;
2393
            }
2394
            public override bool Mesh(int rows, int columns, Point3dCollection points, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2395
            {
2396
                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));
2397
                return false;
2398
            }
2399
            public override bool Polygon(Point3dCollection points)
2400
            {
2401
                writeLine(indent, string.Format("WorldGeometry.Polygon(points = {0})", points));
2402
                return false;
2403
            }
2404
            public override bool Polyline(Teigha.DatabaseServices.Polyline value, int fromIndex, int segments)
2405
            {
2406
                writeLine(indent, string.Format("WorldGeometry.Polyline(value = {0}, fromIndex = {1}, segments = {2})", value, fromIndex, segments));
2407
                return false;
2408
            }
2409
            public override bool Polyline(Point3dCollection points, Vector3d normal, IntPtr subEntityMarker)
2410
            {
2411
                writeLine(indent, string.Format("WorldGeometry.Polyline(points = {0}, normal = {1}, subEntityMarker = {2})", points, normal, subEntityMarker));
2412
                return false;
2413
            }
2414
            public override void PopClipBoundary()
2415
            {
2416
                writeLine(indent, string.Format("WorldGeometry.PopClipBoundary"));
2417
                clips.Pop();
2418
            }
2419
            public override bool PopModelTransform()
2420
            {
2421
                return true;
2422
            }
2423
            public override bool PushClipBoundary(ClipBoundary boundary)
2424
            {
2425
                writeLine(indent, string.Format("WorldGeometry.PushClipBoundary"));
2426
                clips.Push(boundary);
2427
                return true;
2428
            }
2429
            public override bool PushModelTransform(Matrix3d matrix)
2430
            {
2431
                writeLine(indent, "WorldGeometry.PushModelTransform(Matrix3d)");
2432
                Matrix3d m = modelMatrix.Peek();
2433
                modelMatrix.Push(m * matrix);
2434
                return true;
2435
            }
2436
            public override bool PushModelTransform(Vector3d normal)
2437
            {
2438
                writeLine(indent, "WorldGeometry.PushModelTransform(Vector3d)");
2439
                PushModelTransform(Matrix3d.PlaneToWorld(normal));
2440
                return true;
2441
            }
2442
            public override bool RowOfDots(int count, Point3d start, Vector3d step)
2443
            {
2444
                writeLine(indent, string.Format("ViewportGeometry.RowOfDots(count = {0}, start = {1}, step = {1})", count, start, step));
2445
                return false;
2446
            }
2447
            public override bool Ray(Point3d point1, Point3d point2)
2448
            {
2449
                writeLine(indent, string.Format("WorldGeometry.Ray(point1 = {0}, point2 = {1})", point1, point2));
2450
                return false;
2451
            }
2452
            public override bool Shell(Point3dCollection points, IntegerCollection faces, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
2453
            {
2454
                writeLine(indent, string.Format("WorldGeometry.Shell(points = {0}, faces = {1}, edgeData = {2}, faceData = {3}, vertexData = {4}, bAutoGenerateNormals = {5})", points, faces, edgeData, faceData, vertexData, bAutoGenerateNormals));
2455
                return false;
2456
            }
2457
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, string message, bool raw, TextStyle textStyle)
2458
            {
2459
                writeLine(indent, string.Format("WorldGeometry.Text(position = {0}, normal = {1}, direction = {2}, message = {3}, raw = {4}, textStyle = {5})", position, normal, direction, message, raw, textStyle));
2460
                return false;
2461
            }
2462
            public override bool Text(Point3d position, Vector3d normal, Vector3d direction, double height, double width, double oblique, string message)
2463
            {
2464
                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));
2465
                return false;
2466
            }
2467
            public override bool WorldLine(Point3d startPoint, Point3d endPoint)
2468
            {
2469
                writeLine(indent, string.Format("WorldGeometry.WorldLine(startPoint = {0}, endPoint = {1})", startPoint, endPoint));
2470
                return false;
2471
            }
2472
            public override bool Xline(Point3d point1, Point3d point2)
2473
            {
2474
                writeLine(indent, string.Format("WorldGeometry.Xline(point1 = {0}, point2 = {1})", point1, point2));
2475
                return false;
2476
            }
2477
2478
            public override void SetExtents(Extents3d extents)
2479
            {
2480
                writeLine(indent, "WorldGeometry.SetExtents({0}) ", extents);
2481
            }
2482
            public override void StartAttributesSegment()
2483
            {
2484
                writeLine(indent, "WorldGeometry.StartAttributesSegment called");
2485
            }
2486
        }
2487
2488
        class WorldDrawDumper : WorldDraw
2489
        {
2490
            WorldGeometryDumper _geom;
2491
            DrawContextDumper _ctx;
2492
            SubEntityTraits _subents;
2493
            RegenType _regenType;
2494
            int indent;
2495
            public WorldDrawDumper(Database db, int indent)
2496
              : base()
2497
            {
2498
                _regenType = RegenType;
2499
                this.indent = indent;
2500
                _geom = new WorldGeometryDumper(indent);
2501
                _ctx = new DrawContextDumper(db);
2502
                _subents = new SubEntityTraitsDumper(db);
2503
            }
2504
            public override double Deviation(DeviationType deviationType, Point3d pointOnCurve)
2505
            {
2506
                return 1e-9;
2507
            }
2508
            public override WorldGeometry Geometry
2509
            {
2510
                get
2511
                {
2512
                    return _geom;
2513
                }
2514
            }
2515
            public override bool IsDragging
2516
            {
2517
                get
2518
                {
2519
                    return false;
2520
                }
2521
            }
2522
            public override Int32 NumberOfIsolines
2523
            {
2524
                get
2525
                {
2526
                    return 10;
2527
                }
2528
            }
2529
            public override Geometry RawGeometry
2530
            {
2531
                get
2532
                {
2533
                    return _geom;
2534
                }
2535
            }
2536
            public override bool RegenAbort
2537
            {
2538
                get
2539
                {
2540
                    return false;
2541
                }
2542
            }
2543
            public override RegenType RegenType
2544
            {
2545
                get
2546
                {
2547
                    writeLine(indent, "RegenType is asked");
2548
                    return _regenType;
2549
                }
2550
            }
2551
            public override SubEntityTraits SubEntityTraits
2552
            {
2553
                get
2554
                {
2555
                    return _subents;
2556
                }
2557
            }
2558
            public override Context Context
2559
            {
2560
                get
2561
                {
2562
                    return _ctx;
2563
                }
2564
            }
2565
        }
2566
2567
        /************************************************************************/
2568
        /* Dump the common data and WorldDraw information for all               */
2569
        /* entities without explicit dumpers                                    */
2570
        /************************************************************************/
2571
        XmlNode dump(Entity pEnt, int indent, XmlNode node)
2572
        {
2573
            if (node != null)
2574
            {
2575
                XmlElement EntNode = ODA.xml.CreateElement(pEnt.GetRXClass().Name);
2576
2577
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
2578
                HandleAttr.Value = pEnt.Handle.ToString();
2579
                EntNode.Attributes.SetNamedItem(HandleAttr);
2580
2581
                dumpEntityData(pEnt, indent, EntNode);
2582
                using (Database db = pEnt.Database)
2583
                {
2584
                    /**********************************************************************/
2585
                    /* Create an OdGiWorldDraw instance for the vectorization             */
2586
                    /**********************************************************************/
2587
                    WorldDrawDumper wd = new WorldDrawDumper(db, indent + 1);
2588
                    /**********************************************************************/
2589
                    /* Call worldDraw()                                                   */
2590
                    /**********************************************************************/
2591
                    pEnt.WorldDraw(wd);
2592
                }
2593
2594
                node.AppendChild(EntNode);
2595
2596
                return EntNode;
2597
            }
2598
2599
            return null;
2600
        }
2601
2602
        /************************************************************************/
2603
        /* Proxy Entity Dumper                                                  */
2604
        /************************************************************************/
2605
        XmlNode dump(ProxyEntity pProxy, int indent, XmlNode node)
2606
        {
2607
            if (node != null)
2608
            {
2609
                XmlElement ProxyNode = ODA.xml.CreateElement(pProxy.GetRXClass().Name);
2610
2611
                XmlAttribute OriginalClassNameAttr = ODA.xml.CreateAttribute("OriginalClassName");
2612
                OriginalClassNameAttr.Value = pProxy.OriginalClassName.ToString();
2613
                ProxyNode.Attributes.SetNamedItem(OriginalClassNameAttr);
2614
2615
                // this will dump proxy entity graphics
2616
                dump((Entity)pProxy, indent, node);
2617
2618
                DBObjectCollection collection = new DBObjectCollection(); ;
2619
                try
2620
                {
2621
                    pProxy.ExplodeGeometry(collection);
2622
                }
2623
                catch (System.Exception)
2624
                {
2625
                    return null;
2626
                }
2627
2628
                foreach (Entity ent in collection)
2629
                {
2630
                    if (ent is Polyline2d)
2631
                    {
2632
                        Polyline2d pline2d = (Polyline2d)ent;
2633
                        int i = 0;
2634
2635
                        try
2636
                        {
2637
                            foreach (Entity ent1 in pline2d)
2638
                            {
2639
                                if (ent1 is Vertex2d)
2640
                                {
2641
                                    Vertex2d vtx2d = (Vertex2d)ent1;
2642
                                    dump2dVertex(indent, vtx2d, i++, ProxyNode);
2643
                                }
2644
                            }
2645
                        }
2646
                        catch (System.Exception)
2647
                        {
2648
                            return null;
2649
                        }
2650
                    }
2651
                }
2652
2653
                node.AppendChild(ProxyNode);
2654
                return ProxyNode;
2655
            }
2656
2657
            return null;
2658
        }
2659
2660
        /************************************************************************/
2661
        /* Radial Dimension Dumper                                              */
2662
        /************************************************************************/
2663
        XmlNode dump(RadialDimension pDim, int indent, XmlNode node)
2664
        {
2665
            if (node != null)
2666
            {
2667
                XmlElement DimNode = ODA.xml.CreateElement(pDim.GetRXClass().Name);
2668
2669
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
2670
                HandleAttr.Value = pDim.Handle.ToString();
2671
                DimNode.Attributes.SetNamedItem(HandleAttr);
2672
2673
                XmlAttribute CenterAttr = ODA.xml.CreateAttribute("Center");
2674
                CenterAttr.Value = pDim.Center.ToString();
2675
                DimNode.Attributes.SetNamedItem(CenterAttr);
2676
2677
                XmlAttribute ChordPointAttr = ODA.xml.CreateAttribute("ChordPoint");
2678
                ChordPointAttr.Value = pDim.ChordPoint.ToString();
2679
                DimNode.Attributes.SetNamedItem(ChordPointAttr);
2680
2681
                XmlAttribute LeaderLengthAttr = ODA.xml.CreateAttribute("LeaderLength");
2682
                LeaderLengthAttr.Value = pDim.LeaderLength.ToString();
2683
                DimNode.Attributes.SetNamedItem(LeaderLengthAttr);
2684
2685
                dumpDimData(pDim, indent, DimNode);
2686
2687
                node.AppendChild(DimNode);
2688
2689
                return DimNode;
2690
            }
2691
2692
            return null;
2693
        }
2694
2695
        /************************************************************************/
2696
        /* Dump Raster Image Def                                               */
2697
        /************************************************************************/
2698
        void dumpRasterImageDef(ObjectId id, int indent)
2699
        {
2700
            if (!id.IsValid)
2701
                return;
2702
            using (RasterImageDef pDef = (RasterImageDef)id.Open(OpenMode.ForRead))
2703
            {
2704
                writeLine(indent++, pDef.GetRXClass().Name, pDef.Handle);
2705
                writeLine(indent, "Source Filename", shortenPath(pDef.SourceFileName));
2706
                writeLine(indent, "Loaded", pDef.IsLoaded);
2707
                writeLine(indent, "mm per Pixel", pDef.ResolutionMMPerPixel);
2708
                writeLine(indent, "Loaded", pDef.IsLoaded);
2709
                writeLine(indent, "Resolution Units", pDef.ResolutionUnits);
2710
                writeLine(indent, "Size", pDef.Size);
2711
            }
2712
        }
2713
        /************************************************************************/
2714
        /* Dump Raster Image Data                                               */
2715
        /************************************************************************/
2716
        void dumpRasterImageData(RasterImage pImage, int indent)
2717
        {
2718
            writeLine(indent, "Brightness", pImage.Brightness);
2719
            writeLine(indent, "Clipped", pImage.IsClipped);
2720
            writeLine(indent, "Contrast", pImage.Contrast);
2721
            writeLine(indent, "Fade", pImage.Fade);
2722
            writeLine(indent, "kClip", pImage.DisplayOptions & ImageDisplayOptions.Clip);
2723
            writeLine(indent, "kShow", pImage.DisplayOptions & ImageDisplayOptions.Show);
2724
            writeLine(indent, "kShowUnAligned", pImage.DisplayOptions & ImageDisplayOptions.ShowUnaligned);
2725
            writeLine(indent, "kTransparent", pImage.DisplayOptions & ImageDisplayOptions.Transparent);
2726
            writeLine(indent, "Scale", pImage.Scale);
2727
2728
            /********************************************************************/
2729
            /* Dump clip boundary                                               */
2730
            /********************************************************************/
2731
            if (pImage.IsClipped)
2732
            {
2733
                writeLine(indent, "Clip Boundary Type", pImage.ClipBoundaryType);
2734
                if (pImage.ClipBoundaryType != ClipBoundaryType.Invalid)
2735
                {
2736
                    Point2dCollection pt = pImage.GetClipBoundary();
2737
                    for (int i = 0; i < pt.Count; i++)
2738
                    {
2739
                        writeLine(indent, string.Format("Clip Point {0}", i), pt[i]);
2740
                    }
2741
                }
2742
            }
2743
2744
            /********************************************************************/
2745
            /* Dump frame                                                       */
2746
            /********************************************************************/
2747
            Point3dCollection vertices = pImage.GetVertices();
2748
            for (int i = 0; i < vertices.Count; i++)
2749
            {
2750
                writeLine(indent, "Frame Vertex " + i.ToString(), vertices[i]);
2751
            }
2752
2753
            /********************************************************************/
2754
            /* Dump orientation                                                 */
2755
            /********************************************************************/
2756
            writeLine(indent, "Orientation");
2757
            writeLine(indent + 1, "Origin", pImage.Orientation.Origin);
2758
            writeLine(indent + 1, "uVector", pImage.Orientation.Xaxis);
2759
            writeLine(indent + 1, "vVector", pImage.Orientation.Yaxis);
2760
            dumpRasterImageDef(pImage.ImageDefId, indent);
2761
            dumpEntityData(pImage, indent, ODA.xml.DocumentElement);
2762
        }
2763
2764
        /************************************************************************/
2765
        /* Raster Image Dumper                                                  */
2766
        /************************************************************************/
2767
        void dump(RasterImage pImage, int indent)
2768
        {
2769
            writeLine(indent++, pImage.GetRXClass().Name, pImage.Handle);
2770
            writeLine(indent, "Image size", pImage.ImageSize(true));
2771
            dumpRasterImageData(pImage, indent);
2772
        }
2773
2774
        /************************************************************************/
2775
        /* Ray Dumper                                                          */
2776
        /************************************************************************/
2777
        void dump(Ray pRay, int indent)
2778
        {
2779
            writeLine(indent++, pRay.GetRXClass().Name, pRay.Handle);
2780
            writeLine(indent, "Base Point", pRay.BasePoint);
2781
            writeLine(indent, "Unit Direction", pRay.UnitDir);
2782
            dumpCurveData(pRay, indent, ODA.xml.DocumentElement);
2783
        }
2784
2785
        /************************************************************************/
2786
        /* Region Dumper                                                        */
2787
        /************************************************************************/
2788
        void dump(Region pRegion, int indent)
2789
        {
2790
            writeLine(indent++, pRegion.GetRXClass().Name, pRegion.Handle);
2791
            dumpEntityData(pRegion, indent, ODA.xml.DocumentElement);
2792
        }
2793
2794
        /************************************************************************/
2795
        /* Rotated Dimension Dumper                                             */
2796
        /************************************************************************/
2797
        XmlNode dump(RotatedDimension pDim, int indent, XmlNode node)
2798
        {
2799
            if (node != null)
2800
            {
2801
                XmlElement DimNode = ODA.xml.CreateElement(pDim.GetRXClass().Name);
2802
2803
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
2804
                HandleAttr.Value = pDim.Handle.ToString();
2805
                DimNode.Attributes.SetNamedItem(HandleAttr);
2806
2807
                XmlAttribute DimLinePointAttr = ODA.xml.CreateAttribute("DimLinePoint");
2808
                DimLinePointAttr.Value = pDim.DimLinePoint.ToString();
2809
                DimNode.Attributes.SetNamedItem(DimLinePointAttr);
2810
2811
                XmlAttribute ObliqueAttr = ODA.xml.CreateAttribute("Oblique");
2812
                ObliqueAttr.Value = pDim.Oblique.ToString();
2813
                DimNode.Attributes.SetNamedItem(ObliqueAttr);
2814
2815
                XmlAttribute RotationAttr = ODA.xml.CreateAttribute("Rotation");
2816
                RotationAttr.Value = pDim.Rotation.ToString();
2817
                DimNode.Attributes.SetNamedItem(RotationAttr);
2818
2819
                XmlAttribute XLine1PointAttr = ODA.xml.CreateAttribute("XLine1Point");
2820
                XLine1PointAttr.Value = pDim.XLine1Point.ToString();
2821
                DimNode.Attributes.SetNamedItem(XLine1PointAttr);
2822
2823
                XmlAttribute XLine2PointAttr = ODA.xml.CreateAttribute("XLine2Point");
2824
                XLine2PointAttr.Value = pDim.XLine2Point.ToString();
2825
                DimNode.Attributes.SetNamedItem(XLine2PointAttr);
2826
2827
                dumpDimData(pDim, indent, DimNode);
2828
                node.AppendChild(DimNode);
2829
2830
                return DimNode;
2831
            }
2832
2833
            return null;
2834
        }
2835
2836
        /************************************************************************/
2837
        /* Shape Dumper                                                          */
2838
        /************************************************************************/
2839
        void dump(Shape pShape, int indent)
2840
        {
2841
            writeLine(indent++, pShape.GetRXClass().Name, pShape.Handle);
2842
2843
            if (!pShape.StyleId.IsNull)
2844
            {
2845
                using (TextStyleTableRecord pStyle = (TextStyleTableRecord)pShape.StyleId.Open(OpenMode.ForRead))
2846
                    writeLine(indent, "Filename", shortenPath(pStyle.FileName));
2847
            }
2848
2849
            writeLine(indent, "Shape Number", pShape.ShapeNumber);
2850
            writeLine(indent, "Shape Name", pShape.Name);
2851
            writeLine(indent, "Position", pShape.Position);
2852
            writeLine(indent, "Size", pShape.Size);
2853
            writeLine(indent, "Rotation", toDegreeString(pShape.Rotation));
2854
            writeLine(indent, "Oblique", toDegreeString(pShape.Oblique));
2855
            writeLine(indent, "Normal", pShape.Normal);
2856
            writeLine(indent, "Thickness", pShape.Thickness);
2857
            dumpEntityData(pShape, indent, ODA.xml.DocumentElement);
2858
        }
2859
2860
        /************************************************************************/
2861
        /* Solid Dumper                                                         */
2862
        /************************************************************************/
2863
        // TODO:
2864
        /*  void dump(Solid pSolid, int indent)
2865
      {
2866
        writeLine(indent++, pSolid.GetRXClass().Name, pSolid.Handle);
2867
2868
        for (int i = 0; i < 4; i++)
2869
        {
2870
          writeLine(indent, "Point " + i.ToString(),  pSolid .GetPointAt(i));
2871
        }
2872
        dumpEntityData(pSolid, indent);
2873
      }
2874
    */
2875
        /************************************************************************/
2876
        /* Spline Dumper                                                        */
2877
        /************************************************************************/
2878
        void dump(Spline pSpline, int indent)
2879
        {
2880
            writeLine(indent++, pSpline.GetRXClass().Name, pSpline.Handle);
2881
2882
            NurbsData data = pSpline.NurbsData;
2883
            writeLine(indent, "Degree", data.Degree);
2884
            writeLine(indent, "Rational", data.Rational);
2885
            writeLine(indent, "Periodic", data.Periodic);
2886
            writeLine(indent, "Control Point Tolerance", data.ControlPointTolerance);
2887
            writeLine(indent, "Knot Tolerance", data.KnotTolerance);
2888
2889
            writeLine(indent, "Number of control points", data.GetControlPoints().Count);
2890
            for (int i = 0; i < data.GetControlPoints().Count; i++)
2891
            {
2892
                writeLine(indent, "Control Point " + i.ToString(), data.GetControlPoints()[i]);
2893
            }
2894
2895
            writeLine(indent, "Number of Knots", data.GetKnots().Count);
2896
            for (int i = 0; i < data.GetKnots().Count; i++)
2897
            {
2898
                writeLine(indent, "Knot " + i.ToString(), data.GetKnots()[i]);
2899
            }
2900
2901
            if (data.Rational)
2902
            {
2903
                writeLine(indent, "Number of Weights", data.GetWeights().Count);
2904
                for (int i = 0; i < data.GetWeights().Count; i++)
2905
                {
2906
                    writeLine(indent, "Weight " + i.ToString(), data.GetWeights()[i]);
2907
                }
2908
            }
2909
            dumpCurveData(pSpline, indent, ODA.xml.DocumentElement);
2910
        }
2911
        /************************************************************************/
2912
        /* Table Dumper                                                         */
2913
        /************************************************************************/
2914
        void dump(Table pTable, int indent)
2915
        {
2916
            writeLine(indent++, pTable.GetRXClass().Name, pTable.Handle);
2917
            writeLine(indent, "Position", pTable.Position);
2918
            writeLine(indent, "X-Direction", pTable.Direction);
2919
            writeLine(indent, "Normal", pTable.Normal);
2920
            writeLine(indent, "Height", (int)pTable.Height);
2921
            writeLine(indent, "Width", (int)pTable.Width);
2922
            writeLine(indent, "Rows", (int)pTable.NumRows);
2923
            writeLine(indent, "Columns", (int)pTable.NumColumns);
2924
2925
            // TODO:
2926
            //TableStyle pStyle = (TableStyle)pTable.TableStyle.Open(OpenMode.ForRead);
2927
            //writeLine(indent, "Table Style",               pStyle.Name);
2928
            dumpEntityData(pTable, indent, ODA.xml.DocumentElement);
2929
        }
2930
2931
        /************************************************************************/
2932
        /* Text Dumper                                                          */
2933
        /************************************************************************/
2934
        static void dump(DBText pText, int indent, XmlNode node)
2935
        {
2936
            if (node != null)
2937
            {
2938
                dumpTextData(pText, indent, node);
2939
            }
2940
        }
2941
        /************************************************************************/
2942
        /* Trace Dumper                                                         */
2943
        /************************************************************************/
2944
        void dump(Trace pTrace, int indent)
2945
        {
2946
            writeLine(indent++, pTrace.GetRXClass().Name, pTrace.Handle);
2947
2948
            for (short i = 0; i < 4; i++)
2949
            {
2950
                writeLine(indent, "Point " + i.ToString(), pTrace.GetPointAt(i));
2951
            }
2952
            dumpEntityData(pTrace, indent, ODA.xml.DocumentElement);
2953
        }
2954
2955
        /************************************************************************/
2956
        /* Trace UnderlayReference                                                         */
2957
        /************************************************************************/
2958
        void dump(UnderlayReference pEnt, int indent)
2959
        {
2960
            writeLine(indent++, pEnt.GetRXClass().Name, pEnt.Handle);
2961
            writeLine(indent, "UnderlayReference Path ", pEnt.Path);
2962
            writeLine(indent, "UnderlayReference Position ", pEnt.Position);
2963
        }
2964
2965
        /************************************************************************/
2966
        /* Viewport Dumper                                                       */
2967
        /************************************************************************/
2968
        XmlNode dump(Teigha.DatabaseServices.Viewport pVport, int indent, XmlNode node)
2969
        {
2970
            if (node != null)
2971
            {
2972
                XmlElement VportNode = ODA.xml.CreateElement(pVport.GetRXClass().Name);
2973
2974
                XmlAttribute HandleAttr = ODA.xml.CreateAttribute("Handle");
2975
                HandleAttr.Value = pVport.Handle.ToString();
2976
                VportNode.Attributes.SetNamedItem(HandleAttr);
2977
2978
                writeLine(indent, "Back Clip Distance", pVport.BackClipDistance);
2979
                writeLine(indent, "Back Clip On", pVport.BackClipOn);
2980
                writeLine(indent, "Center Point", pVport.CenterPoint);
2981
                writeLine(indent, "Circle sides", pVport.CircleSides);
2982
                writeLine(indent, "Custom Scale", pVport.CustomScale);
2983
                writeLine(indent, "Elevation", pVport.Elevation);
2984
                writeLine(indent, "Front Clip at Eye", pVport.FrontClipAtEyeOn);
2985
                writeLine(indent, "Front Clip Distance", pVport.FrontClipDistance);
2986
                writeLine(indent, "Front Clip On", pVport.FrontClipOn);
2987
                writeLine(indent, "Plot style sheet", pVport.EffectivePlotStyleSheet);
2988
2989
                ObjectIdCollection layerIds = pVport.GetFrozenLayers();
2990
                if (layerIds.Count > 0)
2991
                {
2992
                    writeLine(indent, "Frozen Layers:");
2993
                    for (int i = 0; i < layerIds.Count; i++)
2994
                    {
2995
                        writeLine(indent + 1, i, layerIds[i]);
2996
                    }
2997
                }
2998
                else
2999
                {
3000
                    writeLine(indent, "Frozen Layers", "None");
3001
                }
3002
3003
                Point3d origin = new Point3d();
3004
                Vector3d xAxis = new Vector3d();
3005
                Vector3d yAxis = new Vector3d();
3006
                pVport.GetUcs(ref origin, ref xAxis, ref yAxis);
3007
                writeLine(indent, "UCS origin", origin);
3008
                writeLine(indent, "UCS x-Axis", xAxis);
3009
                writeLine(indent, "UCS y-Axis", yAxis);
3010
                writeLine(indent, "Grid Increment", pVport.GridIncrement);
3011
                writeLine(indent, "Grid On", pVport.GridOn);
3012
                writeLine(indent, "Height", pVport.Height);
3013
                writeLine(indent, "Lens Length", pVport.LensLength);
3014
                writeLine(indent, "Locked", pVport.Locked);
3015
                writeLine(indent, "Non-Rectangular Clip", pVport.NonRectClipOn);
3016
3017
                if (!pVport.NonRectClipEntityId.IsNull)
3018
                {
3019
                    writeLine(indent, "Non-rectangular Clipper", pVport.NonRectClipEntityId.Handle);
3020
                }
3021
                writeLine(indent, "Render Mode", pVport.RenderMode);
3022
                writeLine(indent, "Remove Hidden Lines", pVport.HiddenLinesRemoved);
3023
                writeLine(indent, "Shade Plot", pVport.ShadePlot);
3024
                writeLine(indent, "Snap Isometric", pVport.SnapIsometric);
3025
                writeLine(indent, "Snap On", pVport.SnapOn);
3026
                writeLine(indent, "Transparent", pVport.Transparent);
3027
                writeLine(indent, "UCS Follow", pVport.UcsFollowModeOn);
3028
                writeLine(indent, "UCS Icon at Origin", pVport.UcsIconAtOrigin);
3029
3030
                writeLine(indent, "UCS Orthographic", pVport.UcsOrthographic);
3031
                writeLine(indent, "UCS Saved with VP", pVport.UcsPerViewport);
3032
3033
                if (!pVport.UcsName.IsNull)
3034
                {
3035
                    using (UcsTableRecord pUCS = (UcsTableRecord)pVport.UcsName.Open(OpenMode.ForRead))
3036
                        writeLine(indent, "UCS Name", pUCS.Name);
3037
                }
3038
                else
3039
                {
3040
                    writeLine(indent, "UCS Name", "Null");
3041
                }
3042
3043
                writeLine(indent, "View Center", pVport.ViewCenter);
3044
                writeLine(indent, "View Height", pVport.ViewHeight);
3045
                writeLine(indent, "View Target", pVport.ViewTarget);
3046
                writeLine(indent, "Width", pVport.Width);
3047
                dumpEntityData(pVport, indent, ODA.xml.DocumentElement);
3048
3049
                {
3050
                    using (DBObjectCollection collection = new DBObjectCollection())
3051
                    {
3052
                        try
3053
                        {
3054
                            pVport.ExplodeGeometry(collection);
3055
3056
                            foreach (Entity ent in collection)
3057
                            {
3058
                                if (ent is Polyline2d)
3059
                                {
3060
                                    Polyline2d pline2d = (Polyline2d)ent;
3061
                                    int i = 0;
3062
                                    foreach (Entity ent1 in pline2d)
3063
                                    {
3064
                                        if (ent1 is Vertex2d)
3065
                                        {
3066
                                            Vertex2d vtx2d = (Vertex2d)ent1;
3067
                                            dump2dVertex(indent, vtx2d, i++, VportNode);
3068
                                        }
3069
                                    }
3070
                                }
3071
                            }
3072
                        }
3073
                        catch (System.Exception ex)
3074
                        {
3075
                        }
3076
                    }
3077
                }
3078
3079
                node.AppendChild(VportNode);
3080
                return VportNode;
3081
            }
3082
3083
            return null;
3084
        }
3085
3086
        /************************************************************************/
3087
        /* Wipeout Dumper                                                  */
3088
        /************************************************************************/
3089
        void dump(Wipeout pWipeout, int indent)
3090
        {
3091
            writeLine(indent++, pWipeout.GetRXClass().Name, pWipeout.Handle);
3092
            dumpRasterImageData(pWipeout, indent);
3093
        }
3094
3095
        /************************************************************************/
3096
        /* Xline Dumper                                                         */
3097
        /************************************************************************/
3098
        void dump(Xline pXline, int indent)
3099
        {
3100
            writeLine(indent++, pXline.GetRXClass().Name, pXline.Handle);
3101
            writeLine(indent, "Base Point", pXline.BasePoint);
3102
            writeLine(indent, "Unit Direction", pXline.UnitDir);
3103
            dumpCurveData(pXline, indent, ODA.xml.DocumentElement);
3104
        }
3105
3106
        public void dump(Database pDb, int indent, XmlNode node)
3107
        {
3108
            using (BlockTableRecord btr = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3109
            {
3110
                using (Layout pLayout = (Layout)btr.LayoutId.GetObject(OpenMode.ForRead))
3111
                {
3112
                    string layoutName = "";
3113
                    layoutName = pLayout.LayoutName;
3114
3115
                    XmlAttribute LayoutNameAttr = ODA.xml.CreateAttribute("LayoutName");
3116
                    LayoutNameAttr.Value = layoutName;
3117
                    node.Attributes.SetNamedItem(LayoutNameAttr);
3118
                }
3119
            }
3120
3121
            dumpHeader(pDb, indent, node);
3122
            dumpLayers(pDb, indent, node);
3123
            dumpLinetypes(pDb, indent, node);
3124
            dumpTextStyles(pDb, indent, node);
3125
            dumpDimStyles(pDb, indent, node);
3126
            dumpRegApps(pDb, indent);
3127
            dumpViewports(pDb, indent, node);
3128
            dumpViews(pDb, indent, node);
3129
            dumpMLineStyles(pDb, indent);
3130
            dumpUCSTable(pDb, indent, node);
3131
            dumpObject(pDb.NamedObjectsDictionaryId, "Named Objects Dictionary", indent);
3132
3133
            dumpBlocks(pDb, indent, node);
3134
        }
3135
3136
        /************************************************************************/
3137
        /* Export DWG to PDF                                                    */
3138
        /************************************************************************/
3139
        public void ExportPDF(Database pDb, string filePath)
3140
        {
3141
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(filePath));
3142
            string dirPath = di.Parent != null ? di.Parent.FullName : di.FullName;
3143
            string pdfPath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(filePath) + ".pdf");
3144
3145
            using (mPDFExportParams param = new mPDFExportParams())
3146
            {
3147
                param.Database = pDb;
3148
3149
                TransactionManager tm = pDb.TransactionManager;
3150
                using (Transaction ta = tm.StartTransaction())
3151
                {
3152
                    using (FileStreamBuf fileStrem = new FileStreamBuf(pdfPath, false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways))
3153
                    {
3154
                        param.OutputStream = fileStrem;
3155
3156
                        bool embededTTF = false;
3157
                        bool shxTextAsGeometry = true;
3158
                        bool ttfGeometry = true;
3159
                        bool simpleGeomOptimization = false;
3160
                        bool zoomToExtentsMode = true;
3161
                        bool enableLayers = false;
3162
                        bool includeOffLayers = false;
3163
                        bool enablePrcMode = true;
3164
                        bool monochrome = true;
3165
                        bool allLayout = false;
3166
                        double paperWidth = 841;
3167
                        double paperHeight = 594;
3168
3169
                        param.Flags = (embededTTF ? PDFExportFlags.EmbededTTF : 0) |
3170
                                      (shxTextAsGeometry ? PDFExportFlags.SHXTextAsGeometry : 0) |
3171
                                      (ttfGeometry ? PDFExportFlags.TTFTextAsGeometry : 0) |
3172
                                      (simpleGeomOptimization ? PDFExportFlags.SimpleGeomOptimization : 0) |
3173
                                      (zoomToExtentsMode ? PDFExportFlags.ZoomToExtentsMode : 0) |
3174
                                      (enableLayers ? PDFExportFlags.EnableLayers : 0) |
3175
                                      (includeOffLayers ? PDFExportFlags.IncludeOffLayers : 0);
3176
3177
                        param.Title = "";
3178
                        param.Author = "";
3179
                        param.Subject = "";
3180
                        param.Keywords = "";
3181
                        param.Creator = "";
3182
                        param.Producer = "";
3183
                        param.UseHLR = !enablePrcMode;
3184
                        param.FlateCompression = true;
3185
                        param.ASCIIHEXEncodeStream = true;
3186
                        param.hatchDPI = 720;
3187
3188
                        bool bV15 = enableLayers || includeOffLayers;
3189
                        param.Versions = bV15 ? PDFExportVersions.PDFv1_5 : PDFExportVersions.PDFv1_4;
3190
3191
                        if (enablePrcMode)
3192
                        {
3193
                            Module pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcModule", false, false);
3194
                            if (pModule != null)
3195
                            {
3196
                                pModule = SystemObjects.DynamicLinker.LoadApp("OdPrcExport", false, false);
3197
                            }
3198
                            if (pModule != null)
3199
                            {
3200
                                RXObject pObj = null;
3201
                                bool bUsePRCSingleViewMode = true; // provide a corresponding checkbox in Export to PDF dialog similar to one in OdaMfcApp
3202
                                if (bUsePRCSingleViewMode)
3203
                                {
3204
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_AllInSingleView");
3205
                                }
3206
                                else
3207
                                {
3208
                                    pObj = SystemObjects.ClassDictionary.At("OdPrcContextForPdfExport_Default");
3209
                                }
3210
                                if (pObj != null)
3211
                                {
3212
                                    RXClass pCls = (RXClass)pObj;
3213
                                    if (pCls != null)
3214
                                    {
3215
                                        param.PRCContext = pCls.Create();
3216
                                        param.PRCMode = PRCSupport.AsBrep; //(bUsePRCAsBRep == TRUE ? PRCSupport.AsBrep : PRCSupport.AsMesh);
3217
                                    }
3218
                                    else
3219
                                    {
3220
                                        Console.WriteLine("PDF Export, PRC support - RXClass failed");
3221
                                    }
3222
                                }
3223
                                else
3224
                                {
3225
                                    Console.WriteLine("PDF Export, PRC support - context failed");
3226
                                }
3227
                            }
3228
                            else
3229
                            {
3230
                                Console.WriteLine("PRC module was not loaded", "Error");
3231
                            }
3232
                        }
3233
3234
                        PlotSettingsValidator plotSettingVal = PlotSettingsValidator.Current;
3235
3236
                        StringCollection styleCol = plotSettingVal.GetPlotStyleSheetList();
3237
                        int iIndexStyle = monochrome ? styleCol.IndexOf(String.Format("monochrome.ctb")) : -1;
3238
3239
                        StringCollection strColl = new StringCollection();
3240
                        if (allLayout)
3241
                        {
3242
                            using (DBDictionary layouts = (DBDictionary)pDb.LayoutDictionaryId.GetObject(OpenMode.ForRead))
3243
                            {
3244
                                foreach (DBDictionaryEntry entry in layouts)
3245
                                {
3246
                                    if ("Model" == entry.Key)
3247
                                        strColl.Insert(0, entry.Key);
3248
                                    else
3249
                                        strColl.Add(entry.Key);
3250
                                    if (-1 != iIndexStyle)
3251
                                    {
3252
                                        PlotSettings ps = (PlotSettings)ta.GetObject(entry.Value, OpenMode.ForWrite);
3253
                                        plotSettingVal.SetCurrentStyleSheet(ps, styleCol[iIndexStyle]);
3254
                                    }
3255
                                }
3256
                            }
3257
                        }
3258
                        else if (-1 != iIndexStyle)
3259
                        {
3260
                            using (BlockTableRecord paperBTR = (BlockTableRecord)pDb.CurrentSpaceId.GetObject(OpenMode.ForRead))
3261
                            {
3262
                                using (PlotSettings pLayout = (PlotSettings)paperBTR.LayoutId.GetObject(OpenMode.ForWrite))
3263
                                {
3264
                                    plotSettingVal.SetCurrentStyleSheet(pLayout, styleCol[iIndexStyle]);
3265
                                }
3266
                            }
3267
                        }
3268
                        param.Layouts = strColl;
3269
3270
                        int nPages = Math.Max(1, strColl.Count);
3271
                        PageParamsCollection pParCol = new PageParamsCollection();
3272
                        for (int i = 0; i < nPages; ++i)
3273
                        {
3274
                            PageParams pp = new PageParams();
3275
                            pp.setParams(paperWidth, paperHeight);
3276
                            pParCol.Add(pp);
3277
                        }
3278
                        param.PageParams = pParCol;
3279
                        Export_Import.ExportPDF(param);
3280
                    }
3281
                    ta.Abort();
3282
                }
3283
            }
3284
        }
3285
        public void Show(Database pDb, int pngWidth, int pngHeight)
3286
        {
3287
                ResultBuffer rsb = new ResultBuffer();
3288
                rsb.Add(new TypedValue(5003, 0));
3289
                Teigha.Runtime.Utilities.SetSystemVariables("PDMODE", rsb);
3290
3291
                chageColorAllObjects(pDb);
3292
3293
                string gdPath = "WinOpenGL_20.5_15.txv";
3294
3295
                using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3296
                {
3297
                    if (gsModule == null)
3298
                    {
3299
                        throw new System.Exception(string.Format("\nCould not load graphics module {0} \nExport cancelled.", gdPath));
3300
                    }
3301
3302
                    // create graphics device
3303
                    using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3304
                    {
3305
                        // setup device properties
3306
                        using (Dictionary props = dev.Properties)
3307
                        {
3308
                            props.AtPut("BitPerPixel", new RxVariant(8));
3309
                        }
3310
                        using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3311
                        {
3312
                            ctx.PaletteBackground = System.Drawing.Color.White;
3313
                            ctx.SetPlotGeneration(true);
3314
3315
                            using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3316
                            {
3317
                                helperDevice.ActiveView.LineweightToDcScale = 0.1;
3318
3319
                                helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3320
3321
                                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, pngWidth, pngHeight);
3322
                                helperDevice.OnSize(rect);
3323
3324
                                if (ctx.IsPlotGeneration)
3325
                                    helperDevice.BackgroundColor = System.Drawing.Color.White;
3326
                                else
3327
                                    helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3328
3329
                                helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3330
                                helperDevice.ActiveView.Zoom(1);
3331
                                helperDevice.Update();
3332
                                
3333
                                helperDevice.ActiveView.Show();
3334
                            }
3335
                        }
3336
                    }
3337
                }
3338
        }
3339
3340
        /************************************************************************/
3341
        /* Export DWG to PNG                                                    */
3342
        /************************************************************************/
3343
        public bool ExportPNG(Database pDb, string savePngPath,int pngWidth,int pngHeight)
3344
        {
3345
            bool result = false;
3346 7459b663 taeseongkim
            string tempPngPath = null;
3347 30fe44e0 taeseongkim
3348
            try
3349
            {
3350
                ResultBuffer rsb = new ResultBuffer();
3351
                rsb.Add(new TypedValue(5003, 0));
3352
                Teigha.Runtime.Utilities.SetSystemVariables("PDMODE", rsb);
3353
3354
                chageColorAllObjects(pDb);
3355
3356
                string gdPath = "WinOpenGL_20.5_15.txv";
3357
3358 7459b663 taeseongkim
                tempPngPath = System.IO.Path.GetTempFileName().Replace(".tmp", ".png");
3359 30fe44e0 taeseongkim
3360
                using (GsModule gsModule = (GsModule)SystemObjects.DynamicLinker.LoadModule(gdPath, false, true))
3361
                {
3362
                    if (gsModule == null)
3363
                    {
3364
                        throw new System.Exception(string.Format("\nCould not load graphics module {0} \nExport cancelled.", gdPath));
3365
                    }
3366
3367
                    // create graphics device
3368
                    using (Teigha.GraphicsSystem.Device dev = gsModule.CreateBitmapDevice())
3369
                    {
3370
                        // setup device properties
3371
                        using (Dictionary props = dev.Properties)
3372
                        {
3373
                            props.AtPut("BitPerPixel", new RxVariant(8));
3374
                        }
3375
                        using (ContextForDbDatabase ctx = new ContextForDbDatabase(pDb))
3376
                        {
3377
                            ctx.PaletteBackground = System.Drawing.Color.White;
3378
                            ctx.SetPlotGeneration(true);
3379
3380
                            using (LayoutHelperDevice helperDevice = LayoutHelperDevice.SetupActiveLayoutViews(dev, ctx))
3381
                            {
3382
                                helperDevice.ActiveView.LineweightToDcScale = 0.1;
3383
3384
                                helperDevice.SetLogicalPalette(Device.LightPalette); // Drark palette
3385
3386
                                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, pngWidth, pngHeight);
3387
                                helperDevice.OnSize(rect);
3388
3389
                                if (ctx.IsPlotGeneration)
3390
                                    helperDevice.BackgroundColor = System.Drawing.Color.White;
3391
                                else
3392
                                    helperDevice.BackgroundColor = System.Drawing.Color.FromArgb(0, 173, 174, 173);
3393
3394
                                helperDevice.ActiveView.ZoomExtents(pDb.Extmin, pDb.Extmax);
3395
                                helperDevice.ActiveView.Zoom(1);
3396
                                helperDevice.Update();
3397 7459b663 taeseongkim
3398
                                Export_Import.ExportBitmap(helperDevice, tempPngPath);
3399 30fe44e0 taeseongkim
                            }
3400
                        }
3401
                    }
3402
                }
3403
3404 7459b663 taeseongkim
                if (File.Exists(tempPngPath))
3405 30fe44e0 taeseongkim
                {
3406
                    if (File.Exists(savePngPath))
3407
                    {
3408
                        File.Delete(savePngPath);
3409
                    }
3410
3411 7459b663 taeseongkim
                    File.Copy(tempPngPath, savePngPath);
3412 30fe44e0 taeseongkim
3413
                    using (System.Drawing.Image image = System.Drawing.Image.FromFile(savePngPath))
3414
                    {
3415 7459b663 taeseongkim
                        if (image.Width == pngWidth && image.Height == pngHeight)
3416 30fe44e0 taeseongkim
                        {
3417
                            result = true;
3418
                        }
3419
                    }
3420
                }
3421
3422
            }
3423
            catch (System.Exception)
3424
            {
3425
                result = false;
3426
                throw;
3427
            }
3428 7459b663 taeseongkim
            finally
3429
            {
3430
                if (tempPngPath != null)
3431
                {
3432
                    if (File.Exists(tempPngPath))
3433
                    {
3434
                        File.Delete(tempPngPath);
3435
                    }
3436
                }
3437
            }
3438 30fe44e0 taeseongkim
3439
            return result;
3440
        }
3441
3442
        /************************************************************************/
3443
        /* Change the color of all objects                                      */
3444
        /************************************************************************/
3445
        private void chageColorAllObjects(Database pDb)
3446
        {
3447
            List<string> exceptLayerList = new List<string>();
3448
            using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
3449
            {
3450
                foreach (ObjectId id in pTable)
3451
                {
3452
                    using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
3453
                    {
3454
                        if (!pRecord.IsPlottable)
3455
                        {
3456
                            exceptLayerList.Add(pRecord.Name);
3457
                        }
3458
                    }
3459
                }
3460
            }
3461
            
3462
            using (Transaction tr = pDb.TransactionManager.StartTransaction())
3463
            {
3464
                LayerTable lt = tr.GetObject(pDb.LayerTableId, OpenMode.ForRead) as LayerTable;
3465
                string layerName = "DWG-FORM";
3466
                if (!lt.Has(layerName))
3467
                {
3468
                    layerName = "0";
3469
                }
3470
                BlockTable bt = (BlockTable)tr.GetObject(pDb.BlockTableId, OpenMode.ForRead);
3471
                BlockTableRecord btrModelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
3472
3473
                foreach (ObjectId id in btrModelSpace)
3474
                {
3475
                    Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3476
                    if (ent == null) continue;
3477
3478
                    ent.ColorIndex = 7;
3479
                    if (exceptLayerList.Contains(ent.Layer))
3480
                    {
3481
                        ent.Layer = layerName;
3482
                    }
3483
3484
                    if (ent is BlockReference)
3485
                    {
3486
                        changeColorBlocks(tr, (BlockReference)ent, exceptLayerList);
3487
                    }
3488
                }
3489
3490
                DBDictionary dbdic = (DBDictionary)tr.GetObject(pDb.GroupDictionaryId, OpenMode.ForRead);
3491
                foreach (DBDictionaryEntry entry in dbdic)
3492
                {
3493
                    Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
3494
                    if (group == null) continue;
3495
3496
                    ObjectId[] idarrTags = group.GetAllEntityIds();
3497
                    if (idarrTags == null) continue;
3498
3499
                    foreach (ObjectId id in idarrTags)
3500
                    {
3501
                        Entity ent = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
3502
                        if (ent == null) continue;
3503
3504
                        ent.ColorIndex = 7;
3505
                        if (exceptLayerList.Contains(ent.Layer))
3506
                        {
3507
                            ent.Layer = "0";
3508
                        }
3509
                    }
3510
                }
3511
3512
                foreach (ObjectId btrId in bt)
3513
                {
3514
                    BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
3515
                    if (btr == null) continue;
3516
                    if (btr.Name.StartsWith("*")) continue;
3517
3518
                    foreach (ObjectId entId in btr)
3519
                    {
3520
                        Entity ent = tr.GetObject(entId, OpenMode.ForWrite, false, true) as Entity;
3521
                        if (ent == null) continue;
3522
                        ent.ColorIndex = 0;//ByBlock
3523
                        if (exceptLayerList.Contains(ent.Layer))
3524
                        {
3525
                            ent.Layer = "0";
3526
                        }
3527
                    }
3528
                }
3529
3530
                tr.Commit();
3531
            }
3532
        }
3533
3534
        /************************************************************************/
3535
        /* Change the color of blocks                                           */
3536
        /************************************************************************/
3537
        private void changeColorBlocks(Transaction tr, BlockReference blkRef, List<string> exceptLayerList)
3538
        {
3539
            if (blkRef == null) return;
3540
3541
            if (blkRef.AttributeCollection != null && blkRef.AttributeCollection.Count > 0)
3542
            {
3543
                foreach (ObjectId objectId in blkRef.AttributeCollection)
3544
                {
3545
                    AttributeReference attRef = tr.GetObject(objectId, OpenMode.ForWrite, false, true) as AttributeReference;
3546
                    attRef.ColorIndex = 7;
3547
                    if (exceptLayerList.Contains(attRef.Layer))
3548
                    {
3549
                        attRef.Layer = "0";
3550
                    }
3551
                }
3552
            }
3553
3554
            BlockTableRecord btrBlock = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
3555
            if (btrBlock == null) return;
3556
3557
            foreach (ObjectId oid in btrBlock)
3558
            {
3559
                Entity ent = tr.GetObject(oid, OpenMode.ForWrite, false, true) as Entity;
3560
                if (ent == null) continue;
3561
3562
                ent.ColorIndex = 7;
3563
3564
                if (ent is BlockReference)
3565
                {   
3566
                    changeColorBlocks(tr, (BlockReference)ent, exceptLayerList);
3567
                }
3568
            }
3569
        }
3570
3571
        /************************************************************************/
3572
        /* Nested block Explode & Purge                                         */
3573
        /************************************************************************/
3574
        public void ExplodeAndPurgeNestedBlocks(Database pDb)
3575
        {
3576
            HashSet<string> blockNameList = new HashSet<string>();
3577
            // Explode ModelSpace Nested Block
3578
            blockNameList = explodeNestedBlocks(pDb);
3579
3580
            // Prepare Block Purge
3581
            preparePurgeBlocks(pDb, blockNameList);
3582
3583
            // Block Purge
3584
            ObjectIdCollection oids = new ObjectIdCollection();
3585
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3586
            {
3587
                foreach (ObjectId id in pTable)
3588
                {
3589
                    BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead, false, true);
3590
                    oids.Add(id);
3591
                }
3592
            }
3593
            pDb.Purge(oids);
3594
3595
            foreach (ObjectId oid in oids)
3596
            {
3597
                if (oid.IsErased) continue;
3598
3599
                using (BlockTableRecord btr = (BlockTableRecord)oid.Open(OpenMode.ForWrite, false, true))
3600
                {
3601
                    btr.Erase(true);
3602
                }                
3603
            }
3604
        }
3605
3606
        private HashSet<string> explodeNestedBlocks(Database pDb)
3607
        {
3608
            HashSet<string> blockNameList = new HashSet<string>();
3609
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3610
3611
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3612
            {
3613
                using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3614
                {
3615
                    foreach (ObjectId entid in pBlock)
3616
                    {
3617
                        using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3618
                        {
3619
                            if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3620
                            BlockReference blockRef = (BlockReference)pEnt;
3621
3622
                            if (blockRef.Name.ToUpper().StartsWith(BLOCK_PIPING))
3623
                            {
3624
                                oidSet.Add(entid);
3625
                                continue;
3626
                            }
3627
                            else if (blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3628
                            {
3629
                                continue;
3630
                            }
3631
                            
3632
                            using (BlockTableRecord pBtr = (BlockTableRecord)blockRef.BlockTableRecord.Open(OpenMode.ForRead, false, true))
3633
                            {
3634
                                bool isNestedBlock = false;
3635
                                foreach (ObjectId blkid in pBtr)
3636
                                {
3637
                                    using (Entity pBlkEnt = (Entity)blkid.Open(OpenMode.ForRead, false, true))
3638
                                    {
3639
                                        if (pBlkEnt.GetRXClass().Name == "AcDbBlockReference")
3640
                                        {
3641
                                            oidSet.Add(entid);
3642
                                            isNestedBlock = true;
3643
                                        }
3644
                                    }
3645
                                }
3646
                                if (!isNestedBlock)
3647
                                {
3648
                                    blockNameList.Add(blockRef.Name);
3649
                                }
3650
                            }
3651
                        }
3652
                    }
3653
                }
3654
            }
3655
3656
            if (oidSet.Count > 0)
3657
            {
3658
                explodeBlocks(oidSet);
3659
                blockNameList = explodeNestedBlocks(pDb);
3660
            }
3661
3662
            return blockNameList;
3663
        }
3664
3665
        private void preparePurgeBlocks(Database pDb, HashSet<string> blockNameList)
3666
        {
3667
            HashSet<ObjectId> oidSet = new HashSet<ObjectId>();
3668
3669
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3670
            {
3671
                foreach (ObjectId id in pTable)
3672
                {
3673
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForWrite, false, true))
3674
                    {
3675
                        if (pBlock.IsLayout) continue;
3676
                        pBlock.Explodable = true;
3677
                        if (blockNameList.Contains(pBlock.Name)) continue;
3678
3679
                        foreach (ObjectId entid in pBlock)
3680
                        {
3681
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3682
                            {
3683
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3684
3685
                                oidSet.Add(entid);
3686
                            }
3687
                        }
3688
                    }
3689
                }
3690
            }
3691
3692
            if (oidSet.Count > 0)
3693
            {
3694
                explodeBlocks(oidSet);
3695
                preparePurgeBlocks(pDb, blockNameList);
3696
            }
3697
3698
            return;
3699
        }
3700
        private void explodeBlocks(HashSet<ObjectId> oidSet)
3701
        {
3702
            foreach (ObjectId blkId in oidSet)
3703
            {
3704
                BlockReference blkRef = (BlockReference)blkId.Open(OpenMode.ForWrite, false, true);
3705
                blkRef.ExplodeGeometryToOwnerSpace();
3706
                blkRef.Erase();
3707
            }
3708
        }
3709
3710
        /************************************************************************/
3711
        /* Save Block as DWG For Auxiliary Graphic                              */
3712
        /************************************************************************/
3713
        public void ExportGraphicBlocks(Database pDb, string savePath)
3714
        {
3715
            try
3716
            {
3717
                using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3718
                {
3719
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
3720
                    {
3721
                        foreach (ObjectId entid in pBlock)
3722
                        {
3723
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
3724
                            {
3725
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
3726
                                BlockReference blockRef = (BlockReference)pEnt;
3727
                                if (!blockRef.Name.ToUpper().StartsWith(BLOCK_GRAPHIC))
3728
                                    continue;
3729
3730
                                ObjectIdCollection objIdCol = new ObjectIdCollection();
3731
                                objIdCol.Add(blockRef.ObjectId);
3732
                                if (objIdCol.Count == 0) continue;
3733
3734
                                string filePath = string.Format("{0}.dwg", blockRef.Name);
3735
                                string directory = Path.GetDirectoryName(savePath);
3736
                                directory = directory.ToLower().Replace("drawings\\native", "graphic");
3737
                                if (!Directory.Exists(directory))
3738
                                {
3739
                                    Directory.CreateDirectory(directory);
3740
                                }
3741
                                filePath = Path.Combine(directory, filePath);
3742
                                
3743
                                using (Database newDb = new Database(true, false))
3744
                                {
3745
                                    pDb.Wblock(newDb, objIdCol, Point3d.Origin, DuplicateRecordCloning.Ignore);
3746
                                    newDb.UpdateExt(true);
3747
                                    newDb.SaveAs(filePath, DwgVersion.Newest);
3748
                                }
3749
3750
                                System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo();
3751
                                procStartInfo.FileName = @"C:\Program Files (x86)\SmartSketch\Program\Rad2d\bin\Dwg2Igr.exe";
3752
                                procStartInfo.RedirectStandardOutput = true;
3753
                                procStartInfo.RedirectStandardInput = true;
3754
                                procStartInfo.RedirectStandardError = true;
3755
                                procStartInfo.UseShellExecute = false;
3756
                                procStartInfo.CreateNoWindow = false;
3757
                                procStartInfo.Arguments = filePath.Replace(" ", "^");
3758
3759
                                using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
3760
                                {
3761
                                    proc.StartInfo = procStartInfo;
3762
                                    proc.Start();
3763
                                    proc.StandardInput.Close();
3764
                                    proc.WaitForExit();
3765
3766
                                    switch (proc.ExitCode)
3767
                                    {
3768
                                        case -1:
3769
                                            Console.WriteLine("[{0}] path does not exist or there is no file", filePath);
3770
                                            break;
3771
                                        case 0:
3772
                                            Console.WriteLine("[{0}] File conversion error", filePath.Replace(".dwg", ".igr"));
3773
                                            break;
3774
                                        case 1:
3775
                                            Console.WriteLine("[{0}] File conversion success", filePath.Replace(".dwg", ".igr"));
3776
                                            break;
3777
                                        default:
3778
                                            break;
3779
                                    }
3780
                                }
3781
                            }
3782
                        }
3783
                    }
3784
                }
3785
            }
3786
            catch (System.Exception ex)
3787
            {
3788
            }
3789
        }
3790
        /************************************************************************/
3791
        /* Dump the BlockTable                                                  */
3792
        /************************************************************************/
3793
        public void dumpBlocks(Database pDb, int indent, XmlNode node)
3794
        {
3795
            /**********************************************************************/
3796
            /* Get a pointer to the BlockTable                               */
3797
            /**********************************************************************/
3798
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
3799
            {
3800
                /**********************************************************************/
3801
                /* Dump the Description                                               */
3802
                /**********************************************************************/
3803
                XmlElement BlocksNode = ODA.xml.CreateElement(pTable.GetRXClass().Name);
3804
3805
                /**********************************************************************/
3806
                /* Step through the BlockTable                                        */
3807
                /**********************************************************************/
3808
                foreach (ObjectId id in pTable)
3809
                {
3810
                    /********************************************************************/
3811
                    /* Open the BlockTableRecord for Reading                            */
3812
                    /********************************************************************/
3813
                    using (BlockTableRecord pBlock = (BlockTableRecord)id.Open(OpenMode.ForRead))
3814
                    {
3815
                        /********************************************************************/
3816
                        /* Dump the BlockTableRecord                                        */
3817
                        /********************************************************************/
3818
                        XmlElement BlockNode = ODA.xml.CreateElement(pBlock.GetRXClass().Name);
3819
3820
                        XmlAttribute NameAttr = ODA.xml.CreateAttribute("Name");
3821
                        NameAttr.Value = pBlock.Name;
3822
                        BlockNode.Attributes.SetNamedItem(NameAttr);
3823
3824
                        XmlAttribute CommentsAttr = ODA.xml.CreateAttribute("Comments");
3825
                        CommentsAttr.Value = pBlock.Comments;
3826
                        BlockNode.Attributes.SetNamedItem(CommentsAttr);
3827
3828
                        XmlAttribute OriginAttr = ODA.xml.CreateAttribute("Origin");
3829
                        OriginAttr.Value = pBlock.Origin.ToString();
3830
                        BlockNode.Attributes.SetNamedItem(OriginAttr);
3831
3832
                        writeLine(indent, pBlock.GetRXClass().Name);
3833
                        writeLine(indent + 1, "Anonymous", pBlock.IsAnonymous);
3834
                        writeLine(indent + 1, "Block Insert Units", pBlock.Units);
3835
                        writeLine(indent + 1, "Block Scaling", pBlock.BlockScaling);
3836
                        writeLine(indent + 1, "Explodable", pBlock.Explodable);
3837
                        writeLine(indent + 1, "IsDynamicBlock", pBlock.IsDynamicBlock);
3838
3839
                        try
3840
                        {
3841
                            Extents3d extents = new Extents3d(new Point3d(1E+20, 1E+20, 1E+20), new Point3d(1E-20, 1E-20, 1E-20));
3842
                            extents.AddBlockExtents(pBlock);
3843
3844
                            XmlAttribute MinExtentsAttr = ODA.xml.CreateAttribute("MinExtents");
3845
                            MinExtentsAttr.Value = extents.MinPoint.ToString();
3846
                            BlockNode.Attributes.SetNamedItem(MinExtentsAttr);
3847
3848
                            XmlAttribute MaxExtentsAttr = ODA.xml.CreateAttribute("MaxExtents");
3849
                            MaxExtentsAttr.Value = extents.MaxPoint.ToString();
3850
                            BlockNode.Attributes.SetNamedItem(MaxExtentsAttr);
3851
                        }
3852
                        catch (System.Exception)
3853
                        {
3854
                        }
3855
3856
                        writeLine(indent + 1, "Layout", pBlock.IsLayout);
3857
                        writeLine(indent + 1, "Has Attribute Definitions", pBlock.HasAttributeDefinitions);
3858
                        writeLine(indent + 1, "Xref Status", pBlock.XrefStatus);
3859
                        if (pBlock.XrefStatus != XrefStatus.NotAnXref)
3860
                        {
3861
                            writeLine(indent + 1, "Xref Path", pBlock.PathName);
3862
                            writeLine(indent + 1, "From Xref Attach", pBlock.IsFromExternalReference);
3863
                            writeLine(indent + 1, "From Xref Overlay", pBlock.IsFromOverlayReference);
3864
                            writeLine(indent + 1, "Xref Unloaded", pBlock.IsUnloaded);
3865
                        }
3866
3867
                        /********************************************************************/
3868
                        /* Step through the BlockTableRecord                                */
3869
                        /********************************************************************/
3870
                        foreach (ObjectId entid in pBlock)
3871
                        {
3872
                            /********************************************************************/
3873
                            /* Dump the Entity                                                  */
3874
                            /********************************************************************/
3875
                            dumpEntity(entid, indent + 1, BlockNode);
3876
                        }
3877
3878
                        BlocksNode.AppendChild(BlockNode);
3879
                    }
3880
                }
3881
3882
                node.AppendChild(BlocksNode);
3883
            }
3884
        }
3885
3886
        public void dumpDimStyles(Database pDb, int indent, XmlNode node)
3887
        {
3888
            /**********************************************************************/
3889
            /* Get a SmartPointer to the DimStyleTable                            */
3890
            /**********************************************************************/
3891
            using (DimStyleTable pTable = (DimStyleTable)pDb.DimStyleTableId.Open(OpenMode.ForRead))
3892
            {
3893
                /**********************************************************************/
3894
                /* Dump the Description                                               */
3895
                /**********************************************************************/
3896
                writeLine();
3897
                writeLine(indent++, pTable.GetRXClass().Name);
3898
3899
                /**********************************************************************/
3900
                /* Step through the DimStyleTable                                    */
3901
                /**********************************************************************/
3902
                foreach (ObjectId id in pTable)
3903
                {
3904
                    /*********************************************************************/
3905
                    /* Open the DimStyleTableRecord for Reading                         */
3906
                    /*********************************************************************/
3907
                    using (DimStyleTableRecord pRecord = (DimStyleTableRecord)id.Open(OpenMode.ForRead))
3908
                    {
3909
                        /*********************************************************************/
3910
                        /* Dump the DimStyleTableRecord                                      */
3911
                        /*********************************************************************/
3912
                        writeLine();
3913
                        writeLine(indent, pRecord.GetRXClass().Name);
3914
                        writeLine(indent, "Name", pRecord.Name);
3915
                        writeLine(indent, "Arc Symbol", toArcSymbolTypeString(pRecord.Dimarcsym));
3916
3917
                        writeLine(indent, "Background Text Color", pRecord.Dimtfillclr);
3918
                        writeLine(indent, "BackgroundText Flags", pRecord.Dimtfill);
3919
                        writeLine(indent, "Extension Line 1 Linetype", pRecord.Dimltex1);
3920
                        writeLine(indent, "Extension Line 2 Linetype", pRecord.Dimltex2);
3921
                        writeLine(indent, "Dimension Line Linetype", pRecord.Dimltype);
3922
                        writeLine(indent, "Extension Line Fixed Len", pRecord.Dimfxlen);
3923
                        writeLine(indent, "Extension Line Fixed Len Enable", pRecord.DimfxlenOn);
3924
                        writeLine(indent, "Jog Angle", toDegreeString(pRecord.Dimjogang));
3925
                        writeLine(indent, "Modified For Recompute", pRecord.IsModifiedForRecompute);
3926
                        writeLine(indent, "DIMADEC", pRecord.Dimadec);
3927
                        writeLine(indent, "DIMALT", pRecord.Dimalt);
3928
                        writeLine(indent, "DIMALTD", pRecord.Dimaltd);
3929
                        writeLine(indent, "DIMALTF", pRecord.Dimaltf);
3930
                        writeLine(indent, "DIMALTRND", pRecord.Dimaltrnd);
3931
                        writeLine(indent, "DIMALTTD", pRecord.Dimalttd);
3932
                        writeLine(indent, "DIMALTTZ", pRecord.Dimalttz);
3933
                        writeLine(indent, "DIMALTU", pRecord.Dimaltu);
3934
                        writeLine(indent, "DIMALTZ", pRecord.Dimaltz);
3935
                        writeLine(indent, "DIMAPOST", pRecord.Dimapost);
3936
                        writeLine(indent, "DIMASZ", pRecord.Dimasz);
3937
                        writeLine(indent, "DIMATFIT", pRecord.Dimatfit);
3938
                        writeLine(indent, "DIMAUNIT", pRecord.Dimaunit);
3939
                        writeLine(indent, "DIMAZIN", pRecord.Dimazin);
3940
                        writeLine(indent, "DIMBLK", pRecord.Dimblk);
3941
                        writeLine(indent, "DIMBLK1", pRecord.Dimblk1);
3942
                        writeLine(indent, "DIMBLK2", pRecord.Dimblk2);
3943
                        writeLine(indent, "DIMCEN", pRecord.Dimcen);
3944
                        writeLine(indent, "DIMCLRD", pRecord.Dimclrd);
3945
                        writeLine(indent, "DIMCLRE", pRecord.Dimclre);
3946
                        writeLine(indent, "DIMCLRT", pRecord.Dimclrt);
3947
                        writeLine(indent, "DIMDEC", pRecord.Dimdec);
3948
                        writeLine(indent, "DIMDLE", pRecord.Dimdle);
3949
                        writeLine(indent, "DIMDLI", pRecord.Dimdli);
3950
                        writeLine(indent, "DIMDSEP", pRecord.Dimdsep);
3951
                        writeLine(indent, "DIMEXE", pRecord.Dimexe);
3952
                        writeLine(indent, "DIMEXO", pRecord.Dimexo);
3953
                        writeLine(indent, "DIMFRAC", pRecord.Dimfrac);
3954
                        writeLine(indent, "DIMGAP", pRecord.Dimgap);
3955
                        writeLine(indent, "DIMJUST", pRecord.Dimjust);
3956
                        writeLine(indent, "DIMLDRBLK", pRecord.Dimldrblk);
3957
                        writeLine(indent, "DIMLFAC", pRecord.Dimlfac);
3958
                        writeLine(indent, "DIMLIM", pRecord.Dimlim);
3959
                        writeLine(indent, "DIMLUNIT", pRecord.Dimlunit);
3960
                        writeLine(indent, "DIMLWD", pRecord.Dimlwd);
3961
                        writeLine(indent, "DIMLWE", pRecord.Dimlwe);
3962
                        writeLine(indent, "DIMPOST", pRecord.Dimpost);
3963
                        writeLine(indent, "DIMRND", pRecord.Dimrnd);
3964
                        writeLine(indent, "DIMSAH", pRecord.Dimsah);
3965
                        writeLine(indent, "DIMSCALE", pRecord.Dimscale);
3966
                        writeLine(indent, "DIMSD1", pRecord.Dimsd1);
3967
                        writeLine(indent, "DIMSD2", pRecord.Dimsd2);
3968
                        writeLine(indent, "DIMSE1", pRecord.Dimse1);
3969
                        writeLine(indent, "DIMSE2", pRecord.Dimse2);
3970
                        writeLine(indent, "DIMSOXD", pRecord.Dimsoxd);
3971
                        writeLine(indent, "DIMTAD", pRecord.Dimtad);
3972
                        writeLine(indent, "DIMTDEC", pRecord.Dimtdec);
3973
                        writeLine(indent, "DIMTFAC", pRecord.Dimtfac);
3974
                        writeLine(indent, "DIMTIH", pRecord.Dimtih);
3975
                        writeLine(indent, "DIMTIX", pRecord.Dimtix);
3976
                        writeLine(indent, "DIMTM", pRecord.Dimtm);
3977
                        writeLine(indent, "DIMTOFL", pRecord.Dimtofl);
3978
                        writeLine(indent, "DIMTOH", pRecord.Dimtoh);
3979
                        writeLine(indent, "DIMTOL", pRecord.Dimtol);
3980
                        writeLine(indent, "DIMTOLJ", pRecord.Dimtolj);
3981
                        writeLine(indent, "DIMTP", pRecord.Dimtp);
3982
                        writeLine(indent, "DIMTSZ", pRecord.Dimtsz);
3983
                        writeLine(indent, "DIMTVP", pRecord.Dimtvp);
3984
                        writeLine(indent, "DIMTXSTY", pRecord.Dimtxsty);
3985
                        writeLine(indent, "DIMTXT", pRecord.Dimtxt);
3986
                        writeLine(indent, "DIMTZIN", pRecord.Dimtzin);
3987
                        writeLine(indent, "DIMUPT", pRecord.Dimupt);
3988
                        writeLine(indent, "DIMZIN", pRecord.Dimzin);
3989
3990
                        dumpSymbolTableRecord(pRecord, indent, node);
3991
                    }
3992
                }
3993
            }
3994
        }
3995
3996
        /// <summary>
3997
        /// extract information from entity has given id
3998
        /// </summary>
3999
        /// <param name="id"></param>
4000
        /// <param name="indent"></param>
4001
        /// <param name="node">XmlNode</param>
4002
        public void dumpEntity(ObjectId id, int indent, XmlNode node)
4003
        {
4004
            /**********************************************************************/
4005
            /* Get a pointer to the Entity                                   */
4006
            /**********************************************************************/
4007
            try
4008
            {
4009
                using (Entity pEnt = (Entity)id.Open(OpenMode.ForRead, false, true))
4010
                {
4011
                    /**********************************************************************/
4012
                    /* Dump the entity                                                    */
4013
                    /**********************************************************************/
4014
                    writeLine();
4015
                    // Protocol extensions are not supported in DD.NET (as well as in ARX.NET)
4016
                    // so we just switch by entity type here
4017
                    // (maybe it makes sense to make a map: type -> delegate)
4018
                    switch (pEnt.GetRXClass().Name)
4019
                    {
4020
                        case "AcDbAlignedDimension":
4021
                            dump((AlignedDimension)pEnt, indent, node);
4022
                            break;
4023
                        case "AcDbArc":
4024
                            dump((Arc)pEnt, indent, node);
4025
                            break;
4026
                        case "AcDbArcDimension":
4027
                            dump((ArcDimension)pEnt, indent, node);
4028
                            break;
4029
                        case "AcDbBlockReference":
4030
                            dump((BlockReference)pEnt, indent, node);
4031
                            break;
4032
                        case "AcDbBody":
4033
                            dump((Body)pEnt, indent, node);
4034
                            break;
4035
                        case "AcDbCircle":
4036
                            dump((Circle)pEnt, indent, node);
4037
                            break;
4038
                        case "AcDbPoint":
4039
                            dump((DBPoint)pEnt, indent);
4040
                            break;
4041
                        case "AcDbText":
4042
                            dump((DBText)pEnt, indent, node);
4043
                            break;
4044
                        case "AcDbDiametricDimension":
4045
                            dump((DiametricDimension)pEnt, indent, node);
4046
                            break;
4047
                        case "AcDbViewport":
4048
                            dump((Teigha.DatabaseServices.Viewport)pEnt, indent, node);
4049
                            break;
4050
                        case "AcDbEllipse":
4051
                            dump((Ellipse)pEnt, indent, node);
4052
                            break;
4053
                        case "AcDbFace":
4054
                            dump((Face)pEnt, indent, node);
4055
                            break;
4056
                        case "AcDbFcf":
4057
                            dump((FeatureControlFrame)pEnt, indent);
4058
                            break;
4059
                        case "AcDbHatch":
4060
                            dump((Hatch)pEnt, indent);
4061
                            break;
4062
                        case "AcDbLeader":
4063
                            dump((Leader)pEnt, indent);
4064
                            break;
4065
                        case "AcDbLine":
4066
                            dump((Line)pEnt, indent, node);
4067
                            break;
4068
                        case "AcDb2LineAngularDimension":
4069
                            dump((LineAngularDimension2)pEnt, indent, node);
4070
                            break;
4071
                        case "AcDbMInsertBlock":
4072
                            dump((MInsertBlock)pEnt, indent, node);
4073
                            break;
4074
                        case "AcDbMline":
4075
                            dump((Mline)pEnt, indent);
4076
                            break;
4077
                        case "AcDbMText":
4078
                            dump((MText)pEnt, indent, node);
4079
                            break;
4080
                        case "AcDbOle2Frame":
4081
                            dump((Ole2Frame)pEnt, indent);
4082
                            break;
4083
                        case "AcDbOrdinateDimension":
4084
                            dump((OrdinateDimension)pEnt, indent, node);
4085
                            break;
4086
                        case "AcDb3PointAngularDimension":
4087
                            dump((Point3AngularDimension)pEnt, indent, node);
4088
                            break;
4089
                        case "AcDbPolyFaceMesh":
4090
                            dump((PolyFaceMesh)pEnt, indent, node);
4091
                            break;
4092
                        case "AcDbPolygonMesh":
4093
                            dump((PolygonMesh)pEnt, indent);
4094
                            break;
4095
                        case "AcDbPolyline":
4096
                            dump((Teigha.DatabaseServices.Polyline)pEnt, indent, node);
4097
                            break;
4098
                        case "AcDb2dPolyline":
4099
                            dump((Polyline2d)pEnt, indent, node);
4100
                            break;
4101
                        case "AcDb3dPolyline":
4102
                            dump((Polyline3d)pEnt, indent, node);
4103
                            break;
4104
                        case "AcDbProxyEntity":
4105
                            dump((ProxyEntity)pEnt, indent, node);
4106
                            break;
4107
                        case "AcDbRadialDimension":
4108
                            dump((RadialDimension)pEnt, indent, node);
4109
                            break;
4110
                        case "AcDbRasterImage":
4111
                            dump((RasterImage)pEnt, indent);
4112
                            break;
4113
                        case "AcDbRay":
4114
                            dump((Ray)pEnt, indent);
4115
                            break;
4116
                        case "AcDbRegion":
4117
                            dump((Region)pEnt, indent);
4118
                            break;
4119
                        case "AcDbRotatedDimension":
4120
                            dump((RotatedDimension)pEnt, indent, node);
4121
                            break;
4122
                        case "AcDbShape":
4123
                            dump((Shape)pEnt, indent);
4124
                            break;
4125
                        case "AcDb3dSolid":
4126
                            dump((Solid3d)pEnt, indent, node);
4127
                            break;
4128
                        case "AcDbSpline":
4129
                            dump((Spline)pEnt, indent);
4130
                            break;
4131
                        case "AcDbTable":
4132
                            dump((Table)pEnt, indent);
4133
                            break;
4134
                        case "AcDbTrace":
4135
                            dump((Trace)pEnt, indent);
4136
                            break;
4137
                        case "AcDbWipeout":
4138
                            dump((Wipeout)pEnt, indent);
4139
                            break;
4140
                        case "AcDbXline":
4141
                            dump((Xline)pEnt, indent);
4142
                            break;
4143
                        case "AcDbAttributeDefinition":
4144
                            dump((AttributeDefinition)pEnt, indent, node);
4145
                            break; 
4146
                        case "AcDbPdfReference":
4147
                        case "AcDbDwfReference":
4148
                        case "AcDbDgnReference":
4149
                            dump((UnderlayReference)pEnt, indent);
4150
                            break;
4151
                        default:
4152
                            dump(pEnt, indent, node);
4153
                            break;
4154
                    }
4155
                    /* Dump the Xdata                                                     */
4156
                    /**********************************************************************/
4157
                    dumpXdata(pEnt.XData, indent);
4158
4159
                    /**********************************************************************/
4160
                    /* Dump the Extension Dictionary                                      */
4161
                    /**********************************************************************/
4162
                    if (!pEnt.ExtensionDictionary.IsNull)
4163
                    {
4164
                        dumpObject(pEnt.ExtensionDictionary, "ACAD_XDICTIONARY", indent);
4165
                    }
4166
                }
4167
            }
4168
            catch (System.Exception ex)
4169
            {
4170
                writeLine(indent, $"OID = {id.ToString()}, Error = {ex.Message}");
4171
            }
4172
        }
4173
        public void prepareDump(Database pDb)
4174
        {
4175
            // Purge Object(Layer X, Linetype X)
4176
            ObjectIdCollection oids = new ObjectIdCollection();
4177
            using (Transaction tr = pDb.TransactionManager.StartOpenCloseTransaction())
4178
            {
4179
                for (long i = 0; i < pDb.Handseed.Value; i++)
4180
                {
4181
                    ObjectId id = ObjectId.Null;
4182
                    pDb.TryGetObjectId(new Handle(i), out id);
4183
                    if (id != ObjectId.Null && !id.IsErased) oids.Add(id);
4184
                }
4185
4186
                pDb.Purge(oids);
4187
                try
4188
                {
4189
                    foreach (ObjectId oid in oids)
4190
                    {
4191
                        if (oid.IsErased) continue;
4192
4193
                        DBObject obj = tr.GetObject(oid, OpenMode.ForWrite, false, true) as DBObject;
4194
                        obj.Erase(true);
4195
                    }
4196
                }
4197
                catch (System.Exception ex)
4198
                {
4199
                }
4200
4201
                tr.Commit();
4202
            }
4203
4204
            // Viewport Ucs
4205
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4206
            {
4207
                foreach (ObjectId id in pTable)
4208
                {
4209
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4210
                    {
4211
                        if (pRecord.Name == "*Active")
4212
                        {
4213
                            CoordinateSystem3d cs3d = pRecord.Ucs;
4214
                            if (cs3d.Origin != Point3d.Origin || cs3d.Xaxis != new Vector3d(1, 0, 0) || cs3d.Yaxis != new Vector3d(0, 1, 0))
4215
                            {
4216
                                pRecord.UpgradeOpen();
4217
                                pRecord.SetUcsToWorld();
4218
                            }
4219
                            if (pRecord.ViewTwist != 0)
4220
                            {
4221
                                pRecord.UpgradeOpen();
4222
                                pRecord.ViewTwist = 0;
4223
                            }
4224
                            if (pRecord.ViewDirection != new Vector3d(0, 0, 1))
4225
                            {
4226
                                pRecord.UpgradeOpen();
4227
                                pRecord.ViewDirection = new Vector3d(0, 0, 1);
4228
                            }
4229
                        }
4230
                    }
4231
                }
4232
            }
4233
4234
            // SEC Title box Move & Erase
4235
            using (BlockTable pTable = (BlockTable)pDb.BlockTableId.Open(OpenMode.ForRead))
4236
            {
4237
                string blockName = "Titlebox";
4238
                Extents3d extents = new Extents3d();
4239
                bool isOK = false;
4240
                if (pTable.Has(blockName))
4241
                {
4242
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
4243
                    {
4244
                        foreach (ObjectId entid in pBlock)
4245
                        {
4246
                            using (Entity pEnt = (Entity)entid.Open(OpenMode.ForRead, false, true))
4247
                            {
4248
                                if (pEnt.GetRXClass().Name != "AcDbBlockReference") continue;
4249
                                BlockReference blockRef = (BlockReference)pEnt;
4250
                                if (blockRef.Name.Equals(blockName))
4251
                                {
4252
                                    isOK = true;
4253
                                    extents = blockRef.GeometricExtents;
4254
                                    break;
4255
                                }
4256
                            }
4257
                        }
4258
                    }
4259
                }
4260
4261
                if (isOK)
4262
                {
4263
                    Vector3d vec = extents.MinPoint.GetVectorTo(Point3d.Origin);
4264
                    extents.TransformBy(Matrix3d.Displacement(vec));
4265
                    using (BlockTableRecord pBlock = (BlockTableRecord)pTable[BlockTableRecord.ModelSpace].Open(OpenMode.ForRead, false, true))
4266
                    {
4267
                        foreach (ObjectId entid in pBlock)
4268
                        {
4269
                            using (Entity entity = (Entity)entid.Open(OpenMode.ForWrite, false, true))
4270
                            {
4271
                                if (entity != null)
4272
                                    entity.TransformBy(Matrix3d.Displacement(vec));
4273
                                try
4274
                                {
4275
                                    if (entity.Bounds != null)
4276
                                    {
4277
                                        Extents3d entExtents = entity.GeometricExtents;
4278
                                        if ((entExtents.MinPoint.X >= extents.MinPoint.X && entExtents.MinPoint.Y >= extents.MinPoint.Y
4279
                                            && entExtents.MinPoint.X <= extents.MaxPoint.X && entExtents.MinPoint.Y <= extents.MaxPoint.Y)
4280
                                            || (entExtents.MaxPoint.X >= extents.MinPoint.X && entExtents.MaxPoint.Y >= extents.MinPoint.Y
4281
                                            && entExtents.MaxPoint.X <= extents.MaxPoint.X && entExtents.MaxPoint.Y <= extents.MaxPoint.Y))
4282
                                        {
4283
                                        }
4284
                                        else
4285
                                        {
4286
                                            entity.Erase();
4287
                                        }
4288
                                    }
4289
                                }
4290
                                catch (System.Exception ex)
4291
                                {
4292
                                }
4293
                            }
4294
                        }
4295
                    }
4296
                }
4297
            }
4298
                        
4299
            pDb.UpdateExt(true);
4300
        }
4301
        public void dumpHeader(Database pDb, int indent, XmlNode node)
4302
        {
4303
            if (node != null)
4304
            {
4305
                XmlAttribute FileNameAttr = ODA.xml.CreateAttribute("FileName");
4306
                FileNameAttr.Value = shortenPath(pDb.Filename);
4307
                node.Attributes.SetNamedItem(FileNameAttr);
4308
4309
                XmlAttribute OriginalFileVersionAttr = ODA.xml.CreateAttribute("OriginalFileVersion");
4310
                OriginalFileVersionAttr.Value = pDb.OriginalFileVersion.ToString();
4311
                node.Attributes.SetNamedItem(OriginalFileVersionAttr);
4312
4313
                writeLine();
4314
                writeLine(indent++, "Header Variables:");
4315
4316
                //writeLine();
4317
                //writeLine(indent, "TDCREATE:", pDb.TDCREATE);
4318
                //writeLine(indent, "TDUPDATE:", pDb.TDUPDATE);
4319
4320
                writeLine();
4321
                writeLine(indent, "ANGBASE", pDb.Angbase);
4322
                writeLine(indent, "ANGDIR", pDb.Angdir);
4323
                writeLine(indent, "ATTMODE", pDb.Attmode);
4324
                writeLine(indent, "AUNITS", pDb.Aunits);
4325
                writeLine(indent, "AUPREC", pDb.Auprec);
4326
                writeLine(indent, "CECOLOR", pDb.Cecolor);
4327
                writeLine(indent, "CELTSCALE", pDb.Celtscale);
4328
                writeLine(indent, "CHAMFERA", pDb.Chamfera);
4329
                writeLine(indent, "CHAMFERB", pDb.Chamferb);
4330
                writeLine(indent, "CHAMFERC", pDb.Chamferc);
4331
                writeLine(indent, "CHAMFERD", pDb.Chamferd);
4332
                writeLine(indent, "CMLJUST", pDb.Cmljust);
4333
                writeLine(indent, "CMLSCALE", pDb.Cmljust);
4334
                writeLine(indent, "DIMADEC", pDb.Dimadec);
4335
                writeLine(indent, "DIMALT", pDb.Dimalt);
4336
                writeLine(indent, "DIMALTD", pDb.Dimaltd);
4337
                writeLine(indent, "DIMALTF", pDb.Dimaltf);
4338
                writeLine(indent, "DIMALTRND", pDb.Dimaltrnd);
4339
                writeLine(indent, "DIMALTTD", pDb.Dimalttd);
4340
                writeLine(indent, "DIMALTTZ", pDb.Dimalttz);
4341
                writeLine(indent, "DIMALTU", pDb.Dimaltu);
4342
                writeLine(indent, "DIMALTZ", pDb.Dimaltz);
4343
                writeLine(indent, "DIMAPOST", pDb.Dimapost);
4344
                writeLine(indent, "DIMASZ", pDb.Dimasz);
4345
                writeLine(indent, "DIMATFIT", pDb.Dimatfit);
4346
                writeLine(indent, "DIMAUNIT", pDb.Dimaunit);
4347
                writeLine(indent, "DIMAZIN", pDb.Dimazin);
4348
                writeLine(indent, "DIMBLK", pDb.Dimblk);
4349
                writeLine(indent, "DIMBLK1", pDb.Dimblk1);
4350
                writeLine(indent, "DIMBLK2", pDb.Dimblk2);
4351
                writeLine(indent, "DIMCEN", pDb.Dimcen);
4352
                writeLine(indent, "DIMCLRD", pDb.Dimclrd);
4353
                writeLine(indent, "DIMCLRE", pDb.Dimclre);
4354
                writeLine(indent, "DIMCLRT", pDb.Dimclrt);
4355
                writeLine(indent, "DIMDEC", pDb.Dimdec);
4356
                writeLine(indent, "DIMDLE", pDb.Dimdle);
4357
                writeLine(indent, "DIMDLI", pDb.Dimdli);
4358
                writeLine(indent, "DIMDSEP", pDb.Dimdsep);
4359
                writeLine(indent, "DIMEXE", pDb.Dimexe);
4360
                writeLine(indent, "DIMEXO", pDb.Dimexo);
4361
                writeLine(indent, "DIMFRAC", pDb.Dimfrac);
4362
                writeLine(indent, "DIMGAP", pDb.Dimgap);
4363
                writeLine(indent, "DIMJUST", pDb.Dimjust);
4364
                writeLine(indent, "DIMLDRBLK", pDb.Dimldrblk);
4365
                writeLine(indent, "DIMLFAC", pDb.Dimlfac);
4366
                writeLine(indent, "DIMLIM", pDb.Dimlim);
4367
                writeLine(indent, "DIMLUNIT", pDb.Dimlunit);
4368
                writeLine(indent, "DIMLWD", pDb.Dimlwd);
4369
                writeLine(indent, "DIMLWE", pDb.Dimlwe);
4370
                writeLine(indent, "DIMPOST", pDb.Dimpost);
4371
                writeLine(indent, "DIMRND", pDb.Dimrnd);
4372
                writeLine(indent, "DIMSAH", pDb.Dimsah);
4373
                writeLine(indent, "DIMSCALE", pDb.Dimscale);
4374
                writeLine(indent, "DIMSD1", pDb.Dimsd1);
4375
                writeLine(indent, "DIMSD2", pDb.Dimsd2);
4376
                writeLine(indent, "DIMSE1", pDb.Dimse1);
4377
                writeLine(indent, "DIMSE2", pDb.Dimse2);
4378
                writeLine(indent, "DIMSOXD", pDb.Dimsoxd);
4379
                writeLine(indent, "DIMTAD", pDb.Dimtad);
4380
                writeLine(indent, "DIMTDEC", pDb.Dimtdec);
4381
                writeLine(indent, "DIMTFAC", pDb.Dimtfac);
4382
                writeLine(indent, "DIMTIH", pDb.Dimtih);
4383
                writeLine(indent, "DIMTIX", pDb.Dimtix);
4384
                writeLine(indent, "DIMTM", pDb.Dimtm);
4385
                writeLine(indent, "DIMTOFL", pDb.Dimtofl);
4386
                writeLine(indent, "DIMTOH", pDb.Dimtoh);
4387
                writeLine(indent, "DIMTOL", pDb.Dimtol);
4388
                writeLine(indent, "DIMTOLJ", pDb.Dimtolj);
4389
                writeLine(indent, "DIMTP", pDb.Dimtp);
4390
                writeLine(indent, "DIMTSZ", pDb.Dimtsz);
4391
                writeLine(indent, "DIMTVP", pDb.Dimtvp);
4392
                writeLine(indent, "DIMTXSTY", pDb.Dimtxsty);
4393
                writeLine(indent, "DIMTXT", pDb.Dimtxt);
4394
                writeLine(indent, "DIMTZIN", pDb.Dimtzin);
4395
                writeLine(indent, "DIMUPT", pDb.Dimupt);
4396
                writeLine(indent, "DIMZIN", pDb.Dimzin);
4397
                writeLine(indent, "DISPSILH", pDb.DispSilh);
4398
                writeLine(indent, "DRAWORDERCTL", pDb.DrawOrderCtl);
4399
                writeLine(indent, "ELEVATION", pDb.Elevation);
4400
                writeLine(indent, "EXTMAX", pDb.Extmax);
4401
                writeLine(indent, "EXTMIN", pDb.Extmin);
4402
                writeLine(indent, "FACETRES", pDb.Facetres);
4403
                writeLine(indent, "FILLETRAD", pDb.Filletrad);
4404
                writeLine(indent, "FILLMODE", pDb.Fillmode);
4405
                writeLine(indent, "INSBASE", pDb.Insbase);
4406
                writeLine(indent, "ISOLINES", pDb.Isolines);
4407
                writeLine(indent, "LIMCHECK", pDb.Limcheck);
4408
                writeLine(indent, "LIMMAX", pDb.Limmax);
4409
                writeLine(indent, "LIMMIN", pDb.Limmin);
4410
                writeLine(indent, "LTSCALE", pDb.Ltscale);
4411
                writeLine(indent, "LUNITS", pDb.Lunits);
4412
                writeLine(indent, "LUPREC", pDb.Luprec);
4413
                writeLine(indent, "MAXACTVP", pDb.Maxactvp);
4414
                writeLine(indent, "MIRRTEXT", pDb.Mirrtext);
4415
                writeLine(indent, "ORTHOMODE", pDb.Orthomode);
4416
                writeLine(indent, "PDMODE", pDb.Pdmode);
4417
                writeLine(indent, "PDSIZE", pDb.Pdsize);
4418
                writeLine(indent, "PELEVATION", pDb.Pelevation);
4419
                writeLine(indent, "PELLIPSE", pDb.PlineEllipse);
4420
                writeLine(indent, "PEXTMAX", pDb.Pextmax);
4421
                writeLine(indent, "PEXTMIN", pDb.Pextmin);
4422
                writeLine(indent, "PINSBASE", pDb.Pinsbase);
4423
                writeLine(indent, "PLIMCHECK", pDb.Plimcheck);
4424
                writeLine(indent, "PLIMMAX", pDb.Plimmax);
4425
                writeLine(indent, "PLIMMIN", pDb.Plimmin);
4426
                writeLine(indent, "PLINEGEN", pDb.Plinegen);
4427
                writeLine(indent, "PLINEWID", pDb.Plinewid);
4428
                writeLine(indent, "PROXYGRAPHICS", pDb.Saveproxygraphics);
4429
                writeLine(indent, "PSLTSCALE", pDb.Psltscale);
4430
                writeLine(indent, "PUCSNAME", pDb.Pucsname);
4431
                writeLine(indent, "PUCSORG", pDb.Pucsorg);
4432
                writeLine(indent, "PUCSXDIR", pDb.Pucsxdir);
4433
                writeLine(indent, "PUCSYDIR", pDb.Pucsydir);
4434
                writeLine(indent, "QTEXTMODE", pDb.Qtextmode);
4435
                writeLine(indent, "REGENMODE", pDb.Regenmode);
4436
                writeLine(indent, "SHADEDGE", pDb.Shadedge);
4437
                writeLine(indent, "SHADEDIF", pDb.Shadedif);
4438
                writeLine(indent, "SKETCHINC", pDb.Sketchinc);
4439
                writeLine(indent, "SKPOLY", pDb.Skpoly);
4440
                writeLine(indent, "SPLFRAME", pDb.Splframe);
4441
                writeLine(indent, "SPLINESEGS", pDb.Splinesegs);
4442
                writeLine(indent, "SPLINETYPE", pDb.Splinetype);
4443
                writeLine(indent, "SURFTAB1", pDb.Surftab1);
4444
                writeLine(indent, "SURFTAB2", pDb.Surftab2);
4445
                writeLine(indent, "SURFTYPE", pDb.Surftype);
4446
                writeLine(indent, "SURFU", pDb.Surfu);
4447
                writeLine(indent, "SURFV", pDb.Surfv);
4448
                //writeLine(indent, "TEXTQLTY", pDb.TEXTQLTY);
4449
                writeLine(indent, "TEXTSIZE", pDb.Textsize);
4450
                writeLine(indent, "THICKNESS", pDb.Thickness);
4451
                writeLine(indent, "TILEMODE", pDb.TileMode);
4452
                writeLine(indent, "TRACEWID", pDb.Tracewid);
4453
                writeLine(indent, "TREEDEPTH", pDb.Treedepth);
4454
                writeLine(indent, "UCSNAME", pDb.Ucsname);
4455
                writeLine(indent, "UCSORG", pDb.Ucsorg);
4456
                writeLine(indent, "UCSXDIR", pDb.Ucsxdir);
4457
                writeLine(indent, "UCSYDIR", pDb.Ucsydir);
4458
                writeLine(indent, "UNITMODE", pDb.Unitmode);
4459
                writeLine(indent, "USERI1", pDb.Useri1);
4460
                writeLine(indent, "USERI2", pDb.Useri2);
4461
                writeLine(indent, "USERI3", pDb.Useri3);
4462
                writeLine(indent, "USERI4", pDb.Useri4);
4463
                writeLine(indent, "USERI5", pDb.Useri5);
4464
                writeLine(indent, "USERR1", pDb.Userr1);
4465
                writeLine(indent, "USERR2", pDb.Userr2);
4466
                writeLine(indent, "USERR3", pDb.Userr3);
4467
                writeLine(indent, "USERR4", pDb.Userr4);
4468
                writeLine(indent, "USERR5", pDb.Userr5);
4469
                writeLine(indent, "USRTIMER", pDb.Usrtimer);
4470
                writeLine(indent, "VISRETAIN", pDb.Visretain);
4471
                writeLine(indent, "WORLDVIEW", pDb.Worldview);
4472
            }
4473
        }
4474
4475
        public void dumpLayers(Database pDb, int indent, XmlNode node)
4476
        {
4477
            if (node != null)
4478
            {
4479
                /**********************************************************************/
4480
                /* Get a SmartPointer to the LayerTable                               */
4481
                /**********************************************************************/
4482
                using (LayerTable pTable = (LayerTable)pDb.LayerTableId.Open(OpenMode.ForRead))
4483
                {
4484
                    /**********************************************************************/
4485
                    /* Dump the Description                                               */
4486
                    /**********************************************************************/
4487
                    XmlElement LayerNode = ODA.xml.CreateElement(pTable.GetRXClass().Name);
4488
4489
                    /**********************************************************************/
4490
                    /* Get a SmartPointer to a new SymbolTableIterator                    */
4491
                    /**********************************************************************/
4492
4493
                    /**********************************************************************/
4494
                    /* Step through the LayerTable                                        */
4495
                    /**********************************************************************/
4496
                    foreach (ObjectId id in pTable)
4497
                    {
4498
                        /********************************************************************/
4499
                        /* Open the LayerTableRecord for Reading                            */
4500
                        /********************************************************************/
4501
                        using (LayerTableRecord pRecord = (LayerTableRecord)id.Open(OpenMode.ForRead))
4502
                        {
4503
                            /********************************************************************/
4504
                            /* Dump the LayerTableRecord                                        */
4505
                            /********************************************************************/
4506
                            XmlElement RecordNode = ODA.xml.CreateElement(pRecord.GetRXClass().Name);
4507
4508
                            XmlAttribute NameAttr = ODA.xml.CreateAttribute("Name");
4509
                            NameAttr.Value = pRecord.Name.ToString();
4510
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4511
4512
                            XmlAttribute IsUsedAttr = ODA.xml.CreateAttribute("IsUsed");
4513
                            IsUsedAttr.Value = pRecord.IsUsed.ToString();
4514
                            RecordNode.Attributes.SetNamedItem(IsUsedAttr);
4515
4516
                            XmlAttribute IsOffAttr = ODA.xml.CreateAttribute("IsOff");
4517
                            IsOffAttr.Value = pRecord.IsOff.ToString();
4518
                            RecordNode.Attributes.SetNamedItem(IsOffAttr);
4519
4520
                            XmlAttribute IsFrozenAttr = ODA.xml.CreateAttribute("IsFrozen");
4521
                            IsFrozenAttr.Value = pRecord.IsFrozen.ToString();
4522
                            RecordNode.Attributes.SetNamedItem(IsFrozenAttr);
4523
4524
                            XmlAttribute IsLockedAttr = ODA.xml.CreateAttribute("IsLocked");
4525
                            IsLockedAttr.Value = pRecord.IsLocked.ToString();
4526
                            RecordNode.Attributes.SetNamedItem(IsLockedAttr);
4527
4528
                            XmlAttribute ColorAttr = ODA.xml.CreateAttribute("Color");
4529
                            ColorAttr.Value = pRecord.Color.ToString();
4530
                            RecordNode.Attributes.SetNamedItem(ColorAttr);
4531
4532
                            XmlAttribute LinetypeObjectIdAttr = ODA.xml.CreateAttribute("LinetypeObjectId");
4533
                            LinetypeObjectIdAttr.Value = pRecord.LinetypeObjectId.ToString();
4534
                            RecordNode.Attributes.SetNamedItem(LinetypeObjectIdAttr);
4535
4536
                            XmlAttribute LineWeightAttr = ODA.xml.CreateAttribute("LineWeight");
4537
                            LineWeightAttr.Value = pRecord.LineWeight.ToString();
4538
                            RecordNode.Attributes.SetNamedItem(LineWeightAttr);
4539
4540
                            XmlAttribute PlotStyleNameAttr = ODA.xml.CreateAttribute("PlotStyleName");
4541
                            PlotStyleNameAttr.Value = pRecord.PlotStyleName.ToString();
4542
                            RecordNode.Attributes.SetNamedItem(PlotStyleNameAttr);
4543
4544
                            XmlAttribute IsPlottableAttr = ODA.xml.CreateAttribute("IsPlottable");
4545
                            IsPlottableAttr.Value = pRecord.IsPlottable.ToString();
4546
                            RecordNode.Attributes.SetNamedItem(IsPlottableAttr);
4547
4548
                            XmlAttribute ViewportVisibilityDefaultAttr = ODA.xml.CreateAttribute("ViewportVisibilityDefault");
4549
                            ViewportVisibilityDefaultAttr.Value = pRecord.ViewportVisibilityDefault.ToString();
4550
                            RecordNode.Attributes.SetNamedItem(ViewportVisibilityDefaultAttr);
4551
4552
                            dumpSymbolTableRecord(pRecord, indent, RecordNode);
4553
                            LayerNode.AppendChild(RecordNode);
4554
                        }
4555
                    }
4556
4557
                    node.AppendChild(LayerNode);
4558
                }
4559
            }
4560
        }
4561
4562
        public void dumpLinetypes(Database pDb, int indent, XmlNode node)
4563
        {
4564
            if (node != null)
4565
            {
4566
                /**********************************************************************/
4567
                /* Get a pointer to the LinetypeTable                            */
4568
                /**********************************************************************/
4569
                using (LinetypeTable pTable = (LinetypeTable)pDb.LinetypeTableId.Open(OpenMode.ForRead))
4570
                {
4571
                    XmlElement LinetypeNode = ODA.xml.CreateElement(pTable.GetRXClass().Name);
4572
4573
                    /**********************************************************************/
4574
                    /* Step through the LinetypeTable                                     */
4575
                    /**********************************************************************/
4576
                    foreach (ObjectId id in pTable)
4577
                    {
4578
                        /*********************************************************************/
4579
                        /* Open the LinetypeTableRecord for Reading                          */
4580
                        /*********************************************************************/
4581
                        using (LinetypeTableRecord pRecord = (LinetypeTableRecord)id.Open(OpenMode.ForRead))
4582
                        {
4583
                            XmlElement RecordNode = ODA.xml.CreateElement(pRecord.GetRXClass().Name);
4584
4585
                            XmlAttribute ObjectIdAttr = ODA.xml.CreateAttribute("ObjectId");
4586
                            ObjectIdAttr.Value = pRecord.ObjectId.ToString();
4587
                            RecordNode.Attributes.SetNamedItem(ObjectIdAttr);
4588
4589
                            XmlAttribute NameAttr = ODA.xml.CreateAttribute("Name");
4590
                            NameAttr.Value = pRecord.Name;
4591
                            RecordNode.Attributes.SetNamedItem(NameAttr);
4592
4593
                            XmlAttribute CommentsAttr = ODA.xml.CreateAttribute("Comments");
4594
                            CommentsAttr.Value = pRecord.Comments;
4595
                            RecordNode.Attributes.SetNamedItem(CommentsAttr);
4596
4597
                            /********************************************************************/
4598
                            /* Dump the first line of record as in ACAD.LIN                     */
4599
                            /********************************************************************/
4600
                            string buffer = "*" + pRecord.Name;
4601
                            if (pRecord.Comments != "")
4602
                            {
4603
                                buffer = buffer + "," + pRecord.Comments;
4604
                            }
4605
                            writeLine(indent, buffer);
4606
4607
                            /********************************************************************/
4608
                            /* Dump the second line of record as in ACAD.LIN                    */
4609
                            /********************************************************************/
4610
                            if (pRecord.NumDashes > 0)
4611
                            {
4612
                                buffer = pRecord.IsScaledToFit ? "S" : "A";
4613
                                for (int i = 0; i < pRecord.NumDashes; i++)
4614
                                {
4615
                                    buffer = buffer + "," + pRecord.DashLengthAt(i);
4616
                                    int shapeNumber = pRecord.ShapeNumberAt(i);
4617
                                    string text = pRecord.TextAt(i);
4618
4619
                                    /**************************************************************/
4620
                                    /* Dump the Complex Line                                      */
4621
                                    /**************************************************************/
4622
                                    if (shapeNumber != 0 || text != "")
4623
                                    {
4624
                                        using (TextStyleTableRecord pTextStyle = (TextStyleTableRecord)(pRecord.ShapeStyleAt(i) == ObjectId.Null ? null : pRecord.ShapeStyleAt(i).Open(OpenMode.ForRead)))
4625
                                        {
4626
                                            if (shapeNumber != 0)
4627
                                            {
4628
                                                buffer = buffer + ",[" + shapeNumber + ",";
4629
                                                if (pTextStyle != null)
4630
                                                    buffer = buffer + pTextStyle.FileName;
4631
                                                else
4632
                                                    buffer = buffer + "NULL style";
4633
                                            }
4634
                                            else
4635
                                            {
4636
                                                buffer = buffer + ",[" + text + ",";
4637
                                                if (pTextStyle != null)
4638
                                                    buffer = buffer + pTextStyle.Name;
4639
                                                else
4640
                                                    buffer = buffer + "NULL style";
4641
                                            }
4642
                                        }
4643
4644
                                        if (pRecord.ShapeScaleAt(i) != 0.0)
4645
                                        {
4646
                                            buffer = buffer + ",S" + pRecord.ShapeScaleAt(i);
4647
                                        }
4648
                                        if (pRecord.ShapeRotationAt(i) != 0)
4649
                                        {
4650
                                            buffer = buffer + ",R" + toDegreeString(pRecord.ShapeRotationAt(i));
4651
                                        }
4652
                                        if (pRecord.ShapeOffsetAt(i).X != 0)
4653
                                        {
4654
                                            buffer = buffer + ",X" + pRecord.ShapeOffsetAt(i).X;
4655
                                        }
4656
                                        if (pRecord.ShapeOffsetAt(i).Y != 0)
4657
                                        {
4658
                                            buffer = buffer + ",Y" + pRecord.ShapeOffsetAt(i).Y;
4659
                                        }
4660
                                        buffer = buffer + "]";
4661
                                    }
4662
                                }
4663
                                writeLine(indent, buffer);
4664
                            }
4665
                            dumpSymbolTableRecord(pRecord, indent, node);
4666
                            LinetypeNode.AppendChild(RecordNode);
4667
                        }
4668
                    }
4669
4670
                    node.AppendChild(LinetypeNode);
4671
                }
4672
            }
4673
        }
4674
4675
        public void dumpRegApps(Database pDb, int indent)
4676
        {
4677
            /**********************************************************************/
4678
            /* Get a pointer to the RegAppTable                            */
4679
            /**********************************************************************/
4680
            using (RegAppTable pTable = (RegAppTable)pDb.RegAppTableId.Open(OpenMode.ForRead))
4681
            {
4682
                /**********************************************************************/
4683
                /* Dump the Description                                               */
4684
                /**********************************************************************/
4685
                writeLine();
4686
                writeLine(indent++, pTable.GetRXClass().Name);
4687
4688
                /**********************************************************************/
4689
                /* Step through the RegAppTable                                    */
4690
                /**********************************************************************/
4691
                foreach (ObjectId id in pTable)
4692
                {
4693
                    /*********************************************************************/
4694
                    /* Open the RegAppTableRecord for Reading                         */
4695
                    /*********************************************************************/
4696
                    using (RegAppTableRecord pRecord = (RegAppTableRecord)id.Open(OpenMode.ForRead))
4697
                    {
4698
                        /*********************************************************************/
4699
                        /* Dump the RegAppTableRecord                                      */
4700
                        /*********************************************************************/
4701
                        writeLine();
4702
                        writeLine(indent, pRecord.GetRXClass().Name);
4703
                        writeLine(indent, "Name", pRecord.Name);
4704
                    }
4705
                }
4706
            }
4707
        }
4708
4709
        public void dumpSymbolTableRecord(SymbolTableRecord pRecord, int indent, XmlNode node)
4710
        {
4711
            writeLine(indent, "Xref dependent", pRecord.IsDependent);
4712
            if (pRecord.IsDependent)
4713
            {
4714
                writeLine(indent, "Resolved", pRecord.IsResolved);
4715
            }
4716
        }
4717
4718
        public void dumpTextStyles(Database pDb, int indent, XmlNode node)
4719
        {
4720
            /**********************************************************************/
4721
            /* Get a SmartPointer to the TextStyleTable                            */
4722
            /**********************************************************************/
4723
            using (TextStyleTable pTable = (TextStyleTable)pDb.TextStyleTableId.Open(OpenMode.ForRead))
4724
            {
4725
                /**********************************************************************/
4726
                /* Dump the Description                                               */
4727
                /**********************************************************************/
4728
                writeLine();
4729
                writeLine(indent++, pTable.GetRXClass().Name);
4730
4731
                /**********************************************************************/
4732
                /* Step through the TextStyleTable                                    */
4733
                /**********************************************************************/
4734
                foreach (ObjectId id in pTable)
4735
                {
4736
                    /*********************************************************************/
4737
                    /* Open the TextStyleTableRecord for Reading                         */
4738
                    /*********************************************************************/
4739
                    using (TextStyleTableRecord pRecord = (TextStyleTableRecord)id.Open(OpenMode.ForRead))
4740
                    {
4741
                        /*********************************************************************/
4742
                        /* Dump the TextStyleTableRecord                                      */
4743
                        /*********************************************************************/
4744
                        writeLine();
4745
                        writeLine(indent, pRecord.GetRXClass().Name);
4746
                        writeLine(indent, "Name", pRecord.Name);
4747
                        writeLine(indent, "Shape File", pRecord.IsShapeFile);
4748
                        writeLine(indent, "Text Height", pRecord.TextSize);
4749
                        writeLine(indent, "Width Factor", pRecord.XScale);
4750
                        writeLine(indent, "Obliquing Angle", toDegreeString(pRecord.ObliquingAngle));
4751
                        writeLine(indent, "Backwards", (pRecord.FlagBits & 2));
4752
                        writeLine(indent, "Vertical", pRecord.IsVertical);
4753
                        writeLine(indent, "Upside Down", (pRecord.FlagBits & 4));
4754
                        writeLine(indent, "Filename", shortenPath(pRecord.FileName));
4755
                        writeLine(indent, "BigFont Filename", shortenPath(pRecord.BigFontFileName));
4756
4757
                        FontDescriptor fd = pRecord.Font;
4758
                        writeLine(indent, "Typeface", fd.TypeFace);
4759
                        writeLine(indent, "Character Set", fd.CharacterSet);
4760
                        writeLine(indent, "Bold", fd.Bold);
4761
                        writeLine(indent, "Italic", fd.Italic);
4762
                        writeLine(indent, "Font Pitch & Family", toHexString(fd.PitchAndFamily));
4763
                        dumpSymbolTableRecord(pRecord, indent, node);
4764
                    }
4765
                }
4766
            }
4767
        }
4768
        public void dumpAbstractViewTableRecord(AbstractViewTableRecord pView, int indent, XmlNode node)
4769
        {
4770
            /*********************************************************************/
4771
            /* Dump the AbstractViewTableRecord                                  */
4772
            /*********************************************************************/
4773
            writeLine(indent, "Back Clip Dist", pView.BackClipDistance);
4774
            writeLine(indent, "Back Clip Enabled", pView.BackClipEnabled);
4775
            writeLine(indent, "Front Clip Dist", pView.FrontClipDistance);
4776
            writeLine(indent, "Front Clip Enabled", pView.FrontClipEnabled);
4777
            writeLine(indent, "Front Clip at Eye", pView.FrontClipAtEye);
4778
            writeLine(indent, "Elevation", pView.Elevation);
4779
            writeLine(indent, "Height", pView.Height);
4780
            writeLine(indent, "Width", pView.Width);
4781
            writeLine(indent, "Lens Length", pView.LensLength);
4782
            writeLine(indent, "Render Mode", pView.RenderMode);
4783
            writeLine(indent, "Perspective", pView.PerspectiveEnabled);
4784
            writeLine(indent, "UCS Name", pView.UcsName);
4785
4786
            //writeLine(indent, "UCS Orthographic", pView.IsUcsOrthographic(orthoUCS));
4787
            //writeLine(indent, "Orthographic UCS", orthoUCS);
4788
4789
            if (pView.UcsOrthographic != OrthographicView.NonOrthoView)
4790
            {
4791
                writeLine(indent, "UCS Origin", pView.Ucs.Origin);
4792
                writeLine(indent, "UCS x-Axis", pView.Ucs.Xaxis);
4793
                writeLine(indent, "UCS y-Axis", pView.Ucs.Yaxis);
4794
            }
4795
4796
            writeLine(indent, "Target", pView.Target);
4797
            writeLine(indent, "View Direction", pView.ViewDirection);
4798
            writeLine(indent, "Twist Angle", toDegreeString(pView.ViewTwist));
4799
            dumpSymbolTableRecord(pView, indent, node);
4800
        }
4801
        public void dumpDimAssoc(DBObject pObject, int indent)
4802
        {
4803
4804
        }
4805
        public void dumpMLineStyles(Database pDb, int indent)
4806
        {
4807
            using (DBDictionary pDictionary = (DBDictionary)pDb.MLStyleDictionaryId.Open(OpenMode.ForRead))
4808
            {
4809
                /**********************************************************************/
4810
                /* Dump the Description                                               */
4811
                /**********************************************************************/
4812
                writeLine();
4813
                writeLine(indent++, pDictionary.GetRXClass().Name);
4814
4815
                /**********************************************************************/
4816
                /* Step through the MlineStyle dictionary                             */
4817
                /**********************************************************************/
4818
                DbDictionaryEnumerator e = pDictionary.GetEnumerator();
4819
                while (e.MoveNext())
4820
                {
4821
                    try
4822
                    {
4823
                        using (MlineStyle pEntry = (MlineStyle)e.Value.Open(OpenMode.ForRead))
4824
                        {
4825
                            /*********************************************************************/
4826
                            /* Dump the MLineStyle dictionary entry                              */
4827
                            /*********************************************************************/
4828
                            writeLine();
4829
                            writeLine(indent, pEntry.GetRXClass().Name);
4830
                            writeLine(indent, "Name", pEntry.Name);
4831
                            writeLine(indent, "Description", pEntry.Description);
4832
                            writeLine(indent, "Start Angle", toDegreeString(pEntry.StartAngle));
4833
                            writeLine(indent, "End Angle", toDegreeString(pEntry.EndAngle));
4834
                            writeLine(indent, "Start Inner Arcs", pEntry.StartInnerArcs);
4835
                            writeLine(indent, "End Inner Arcs", pEntry.EndInnerArcs);
4836
                            writeLine(indent, "Start Round Cap", pEntry.StartRoundCap);
4837
                            writeLine(indent, "End Round Cap", pEntry.EndRoundCap);
4838
                            writeLine(indent, "Start Square Cap", pEntry.StartRoundCap);
4839
                            writeLine(indent, "End Square Cap", pEntry.EndRoundCap);
4840
                            writeLine(indent, "Show Miters", pEntry.ShowMiters);
4841
                            /*********************************************************************/
4842
                            /* Dump the elements                                                 */
4843
                            /*********************************************************************/
4844
                            if (pEntry.Elements.Count > 0)
4845
                            {
4846
                                writeLine(indent, "Elements:");
4847
                            }
4848
                            int i = 0;
4849
                            foreach (MlineStyleElement el in pEntry.Elements)
4850
                            {
4851
                                writeLine(indent, "Index", (i++));
4852
                                writeLine(indent + 1, "Offset", el.Offset);
4853
                                writeLine(indent + 1, "Color", el.Color);
4854
                                writeLine(indent + 1, "Linetype", el.LinetypeId);
4855
                            }
4856
                        }
4857
                    }
4858
                    catch (System.Exception)
4859
                    {
4860
                    }
4861
                }
4862
            }
4863
        }
4864
        public void dumpObject(ObjectId id, string itemName, int indent)
4865
        {
4866
            using (DBObject pObject = id.Open(OpenMode.ForRead))
4867
            {
4868
                /**********************************************************************/
4869
                /* Dump the item name and class name                                  */
4870
                /**********************************************************************/
4871
                if (pObject is DBDictionary)
4872
                {
4873
                    writeLine();
4874
                }
4875
                writeLine(indent++, itemName, pObject.GetRXClass().Name);
4876
4877
                /**********************************************************************/
4878
                /* Dispatch                                                           */
4879
                /**********************************************************************/
4880
                if (pObject is DBDictionary)
4881
                {
4882
                    /********************************************************************/
4883
                    /* Dump the dictionary                                               */
4884
                    /********************************************************************/
4885
                    DBDictionary pDic = (DBDictionary)pObject;
4886
4887
                    /********************************************************************/
4888
                    /* Get a pointer to a new DictionaryIterator                   */
4889
                    /********************************************************************/
4890
                    DbDictionaryEnumerator pIter = pDic.GetEnumerator();
4891
4892
                    /********************************************************************/
4893
                    /* Step through the Dictionary                                      */
4894
                    /********************************************************************/
4895
                    while (pIter.MoveNext())
4896
                    {
4897
                        /******************************************************************/
4898
                        /* Dump the Dictionary object                                     */
4899
                        /******************************************************************/
4900
                        dumpObject(pIter.Value, pIter.Key, indent);
4901
                    }
4902
                }
4903
                else if (pObject is Xrecord)
4904
                {
4905
                    /********************************************************************/
4906
                    /* Dump an Xrecord                                                  */
4907
                    /********************************************************************/
4908
                    Xrecord pXRec = (Xrecord)pObject;
4909
                    dumpXdata(pXRec.Data, indent);
4910
                }
4911
            }
4912
        }
4913
4914
        public void dumpUCSTable(Database pDb, int indent, XmlNode node)
4915
        {
4916
            /**********************************************************************/
4917
            /* Get a pointer to the UCSTable                               */
4918
            /**********************************************************************/
4919
            using (UcsTable pTable = (UcsTable)pDb.UcsTableId.Open(OpenMode.ForRead))
4920
            {
4921
                /**********************************************************************/
4922
                /* Dump the Description                                               */
4923
                /**********************************************************************/
4924
                writeLine();
4925
                writeLine(indent++, pTable.GetRXClass().Name);
4926
4927
                /**********************************************************************/
4928
                /* Step through the UCSTable                                          */
4929
                /**********************************************************************/
4930
                foreach (ObjectId id in pTable)
4931
                {
4932
                    /********************************************************************/
4933
                    /* Open the UCSTableRecord for Reading                            */
4934
                    /********************************************************************/
4935
                    using (UcsTableRecord pRecord = (UcsTableRecord)id.Open(OpenMode.ForRead))
4936
                    {
4937
                        /********************************************************************/
4938
                        /* Dump the UCSTableRecord                                        */
4939
                        /********************************************************************/
4940
                        writeLine();
4941
                        writeLine(indent, pRecord.GetRXClass().Name);
4942
                        writeLine(indent, "Name", pRecord.Name);
4943
                        writeLine(indent, "UCS Origin", pRecord.Origin);
4944
                        writeLine(indent, "UCS x-Axis", pRecord.XAxis);
4945
                        writeLine(indent, "UCS y-Axis", pRecord.YAxis);
4946
                        dumpSymbolTableRecord(pRecord, indent, node);
4947
                    }
4948
                }
4949
            }
4950
        }
4951
        public void dumpViewports(Database pDb, int indent, XmlNode node)
4952
        {
4953
            /**********************************************************************/
4954
            /* Get a pointer to the ViewportTable                            */
4955
            /**********************************************************************/
4956
            using (ViewportTable pTable = (ViewportTable)pDb.ViewportTableId.Open(OpenMode.ForRead))
4957
            {
4958
                /**********************************************************************/
4959
                /* Dump the Description                                               */
4960
                /**********************************************************************/
4961
                writeLine();
4962
                writeLine(indent++, pTable.GetRXClass().Name);
4963
4964
                /**********************************************************************/
4965
                /* Step through the ViewportTable                                    */
4966
                /**********************************************************************/
4967
                foreach (ObjectId id in pTable)
4968
                {
4969
                    /*********************************************************************/
4970
                    /* Open the ViewportTableRecord for Reading                          */
4971
                    /*********************************************************************/
4972
                    using (ViewportTableRecord pRecord = (ViewportTableRecord)id.Open(OpenMode.ForRead))
4973
                    {
4974
                        /*********************************************************************/
4975
                        /* Dump the ViewportTableRecord                                      */
4976
                        /*********************************************************************/
4977
                        writeLine();
4978
                        writeLine(indent, pRecord.GetRXClass().Name);
4979
                        writeLine(indent, "Name", pRecord.Name);
4980
                        writeLine(indent, "Circle Sides", pRecord.CircleSides);
4981
                        writeLine(indent, "Fast Zooms Enabled", pRecord.FastZoomsEnabled);
4982
                        writeLine(indent, "Grid Enabled", pRecord.GridEnabled);
4983
                        writeLine(indent, "Grid Increments", pRecord.GridIncrements);
4984
                        writeLine(indent, "Icon at Origin", pRecord.IconAtOrigin);
4985
                        writeLine(indent, "Icon Enabled", pRecord.IconEnabled);
4986
                        writeLine(indent, "Iso snap Enabled", pRecord.IsometricSnapEnabled);
4987
                        writeLine(indent, "Iso Snap Pair", pRecord.SnapPair);
4988
                        writeLine(indent, "UCS Saved w/Vport", pRecord.UcsSavedWithViewport);
4989
                        writeLine(indent, "UCS follow", pRecord.UcsFollowMode);
4990
                        writeLine(indent, "Lower-Left Corner", pRecord.LowerLeftCorner);
4991
                        writeLine(indent, "Upper-Right Corner", pRecord.UpperRightCorner);
4992
                        writeLine(indent, "Snap Angle", toDegreeString(pRecord.SnapAngle));
4993
                        writeLine(indent, "Snap Base", pRecord.SnapBase);
4994
                        writeLine(indent, "Snap Enabled", pRecord.SnapEnabled);
4995
                        writeLine(indent, "Snap Increments", pRecord.SnapIncrements);
4996
                        dumpAbstractViewTableRecord(pRecord, indent, node);
4997
                    }
4998
                }
4999
            }
5000
        }
5001
5002
        /************************************************************************/
5003
        /* Dump the ViewTable                                                   */
5004
        /************************************************************************/
5005
        public void dumpViews(Database pDb, int indent, XmlNode node)
5006
        {
5007
            /**********************************************************************/
5008
            /* Get a pointer to the ViewTable                                */
5009
            /**********************************************************************/
5010
            using (ViewTable pTable = (ViewTable)pDb.ViewTableId.Open(OpenMode.ForRead))
5011
            {
5012
                /**********************************************************************/
5013
                /* Dump the Description                                               */
5014
                /**********************************************************************/
5015
                writeLine();
5016
                writeLine(indent++, pTable.GetRXClass().Name);
5017
5018
                /**********************************************************************/
5019
                /* Step through the ViewTable                                         */
5020
                /**********************************************************************/
5021
                foreach (ObjectId id in pTable)
5022
                {
5023
                    /*********************************************************************/
5024
                    /* Open the ViewTableRecord for Reading                              */
5025
                    /*********************************************************************/
5026
                    using (ViewTableRecord pRecord = (ViewTableRecord)id.Open(OpenMode.ForRead))
5027
                    {
5028
                        /*********************************************************************/
5029
                        /* Dump the ViewTableRecord                                          */
5030
                        /*********************************************************************/
5031
                        writeLine();
5032
                        writeLine(indent, pRecord.GetRXClass().Name);
5033
                        writeLine(indent, "Name", pRecord.Name);
5034
                        writeLine(indent, "Category Name", pRecord.CategoryName);
5035
                        writeLine(indent, "Layer State", pRecord.LayerState);
5036
5037
                        string layoutName = "";
5038
                        if (!pRecord.Layout.IsNull)
5039
                        {
5040
                            using (Layout pLayout = (Layout)pRecord.Layout.Open(OpenMode.ForRead))
5041
                                layoutName = pLayout.LayoutName;
5042
                        }
5043
                        writeLine(indent, "Layout Name", layoutName);
5044
                        writeLine(indent, "PaperSpace View", pRecord.IsPaperspaceView);
5045
                        writeLine(indent, "Associated UCS", pRecord.IsUcsAssociatedToView);
5046
                        writeLine(indent, "PaperSpace View", pRecord.ViewAssociatedToViewport);
5047
                        dumpAbstractViewTableRecord(pRecord, indent, node);
5048
                    }
5049
                }
5050
            }
5051
        }
5052
        /************************************************************************/
5053
        /* Dump Xdata                                                           */
5054
        /************************************************************************/
5055
        public void dumpXdata(ResultBuffer xIter, int indent)
5056
        {
5057
            if (xIter == null)
5058
                return;
5059
            writeLine(indent++, "Xdata:");
5060
            /**********************************************************************/
5061
            /* Step through the ResBuf chain                                      */
5062
            /**********************************************************************/
5063
            try
5064
            {
5065
                int rsCount = xIter.Cast<TypedValue>().Count();
5066
                
5067
                foreach (TypedValue resbuf in xIter)
5068
                {
5069
                    writeLine(indent, resbuf);
5070
                }
5071
            }
5072
            catch (System.Exception ex)
5073
            {
5074
            }
5075
            
5076
        }
5077
    }
5078
    class ExProtocolExtension
5079
    {
5080
    }
5081
5082
    public static class ODA
5083
    {
5084
        public static XmlDocument xml = null;
5085
        public static double OffsetX = 0;
5086
        public static double OffsetY = 0;
5087
        public static double Scale = 0;
5088
        public static double getDrawing = 0;
5089
        public static List<string> Layers = new List<string>() { "MINOR", "INSTR", "ELECT", "INSTRUMENT", "LINES" };
5090
5091
       public  static void InintODA()
5092
        {
5093
            /********************************************************************/
5094
            /* Initialize Drawings.NET.                                         */
5095
            /********************************************************************/
5096
            bool bSuccess = true;
5097
            Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
5098
            using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
5099
            {
5100
                try
5101
                {
5102
                    HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
5103
                    /**********************************************************************/
5104
                    /* Display the Product and Version that created the executable        */
5105
                    /**********************************************************************/
5106
                    Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
5107
5108
                }
5109
                /********************************************************************/
5110
                /* Display the error                                                */
5111
                /********************************************************************/
5112
                catch (System.Exception e)
5113
                {
5114
                    bSuccess = false;
5115
                    Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message);
5116
                }
5117
5118
                if (bSuccess)
5119
                    Console.WriteLine("OdReadExMgd Finished Successfully");
5120
            }
5121
        }
5122
    }
5123
}
클립보드 이미지 추가 (최대 크기: 500 MB)