Newer
Older
GHFX_REFACTOR / ClassExpCad.cs
xiaowei on 15 Mar 2017 3 KB daochu CAD
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeoScene.Data;
using GeoScene.Engine;
using GeoScene.Globe;
using System.IO;
using System.Windows.Forms;
using DXFLibrary;
using System.Drawing;

namespace Cyberpipe
{
    class ClassExpCad
    {
        public static void ExpDxfFromLayers(GSOFeatures features,string saveFilePath)
        {
            Dictionary<string,short> layerNameAndColor=new Dictionary<string, short>();
            for (int i = 0;i < features.Length;i++)
            {
                if (!layerNameAndColor.Keys.Contains(features[i].Dataset.Caption))
                    layerNameAndColor.Add(features[i].Dataset.Caption, getShortColorFromFeature(features[i]));
            }

            expGSOLayerToDxf(layerNameAndColor, features, saveFilePath);
        }

        private static void expGSOLayerToDxf(Dictionary<string, short> layerNameAndColor, 
            GSOFeatures features, string saveFilePath)
        {
            DXFLibrary.Document doc = new DXFLibrary.Document();
            DXFLibrary.Tables tables = new DXFLibrary.Tables();
            doc.SetTables(tables);
            DXFLibrary.Table layers = new DXFLibrary.Table("LAYER");
            tables.addTable(layers);

            DXFLibrary.Layer layerDoors;
            foreach (var layerName in layerNameAndColor)
            {
                layerDoors = new DXFLibrary.Layer(layerName.Key, layerName.Value, "CONTINUOUS");
                layers.AddTableEntry(layerDoors);
            }

            for (int i = 0; i < features.Length; i++)
            {
                GSOGeoPolyline3D polyLine = features[i].Geometry as GSOGeoPolyline3D;
                GSOPoint3d startPt = polyLine[0][0];
                GSOPoint3d endPt = polyLine[0][1];

                DXFLibrary.Line line = new DXFLibrary.Line(features[i].Dataset.Caption, startPt.X, startPt.Y, endPt.X, endPt.Y);
                doc.add(line);
            }

            /*
            DXFLibrary.Circle cc = new DXFLibrary.Circle(5, 5, 0.1d, "PartialHeightDoors");
            doc.add(cc);
            */
            /*
            DXFLibrary.Line line2 = new DXFLibrary.Line("Doors", 0, 0, 10, 0);
            doc.add(line2);
            DXFLibrary.Line line3 = new DXFLibrary.Line("Doors", 10, 10, 0, 10);
            doc.add(line3);
            DXFLibrary.Line line4 = new DXFLibrary.Line("Doors", 10, 10, 10, 0);
            doc.add(line4);
            DXFLibrary.Line3D line5 = new DXFLibrary.Line3D("Doors", 2, 2, 0, 5, 5, 10);
            doc.add(line5);

            //DXFLibrary.Circle cc = new DXFLibrary.Circle(5, 5, 0.1d, "PartialHeightDoors");
            //doc.add(cc);
            */

            FileStream fs = new FileStream(saveFilePath, System.IO.FileMode.Create);
            DXFLibrary.Writer.Write(doc, fs);
            fs.Close();
        }

        private static short getShortColorFromFeature(GSOFeature feature)
        {
           
            short color = 30;
            /*
            GSOGeoPolyline3D polyLine = feature.Geometry as GSOGeoPolyline3D;
            GSOPipeLineStyle3D line = GSOPipeLineStyle3D polyLine;
            GSOExtendSectionLineStyle3D style1 = GSOExtendSectionLineStyle3D polyLine; 
             * * */
            return color;
            
        }

    }
}