프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / MarkusImageCreate / OdReadExMgd.cs @ dfb9a03c

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