Newer
Older
GHFX_REFACTOR / Backup / NewFunction / FrmCreateTunnel.cs
wxn on 2 Nov 2016 7 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using GeoScene.Globe;
using GeoScene.Engine;
using GeoScene.Data;
using DevComponents.DotNetBar;

namespace Cyberpipe
{
    public partial class FrmCreateTunnel : Office2007Form
    {
        public FrmCreateTunnel()
        {
            InitializeComponent();
        }

        private GSOGlobeControl globeControl1;
        private GSOFeature feature;
        private GSOFeature m_feature;       

        public FrmCreateTunnel(GSOGlobeControl ctl, GSOFeature f)
        {
            InitializeComponent();
            this.globeControl1 = ctl;
            this.feature = f;
            if (feature != null)
            {
                m_feature = feature.Clone();
            }            
        }

        private void btnOK_Click(object sender, EventArgs e)
        {            
            feature.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;
            if (feature != null && feature.Geometry != null && feature.Geometry.Type == EnumGeometryType.GeoPolyline3D)
            {
                GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D;
                if (comboBoxTunnelType.SelectedItem != null)
                {
                    if (comboBoxTunnelType.SelectedItem.ToString() == "方形")
                    {
                        GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), pictureBoxFillColor.BackColor);

                        double radius = double.Parse(txtRadius.Text) / 2;
                        double width = radius * 2;
                        double height = width;

                        GSOPoint3ds sectionpts = new GSOPoint3ds();
                        sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                        sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));
                        sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                        style.SetSectionPoints(sectionpts);
                        style.IsClosed = false;
                        style.SetAnchorByAlign(EnumAlign.BottomCenter);

                        line.Style = style;
                    }
                    else if (comboBoxTunnelType.SelectedItem.ToString() == "圆形")
                    {
                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), pictureBoxFillColor.BackColor);
                        style.Radius = double.Parse(txtRadius.Text) / 2;
                        style.Slice = int.Parse(txtSlice.Text);
                        style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text);
                        line.Style = style;
                    }
                    else if (comboBoxTunnelType.SelectedItem.ToString() == "拱形")
                    {
                        GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), pictureBoxFillColor.BackColor);

                        double radius = double.Parse(txtRadius.Text) / 2;
                        double width = radius * 2;
                        double height = width;

                        GSOPoint3ds sectionpts = new GSOPoint3ds();
                        sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                        sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));                        

                        //圆弧需要的点
                        sectionpts.Add(new GSOPoint3d(width / 2 / 2 * Math.Sqrt(3), height / 2 + height / 2 / 2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2 / 2 * Math.Sqrt(2), height / 2 + height / 2 / 2 * Math.Sqrt(2), 0));
                        sectionpts.Add(new GSOPoint3d(width / 2 / 2, height / 2 + height / 2 / 2 * Math.Sqrt(3), 0));
                        sectionpts.Add(new GSOPoint3d(0, height, 0));
                        sectionpts.Add(new GSOPoint3d( -width / 2 / 2, height / 2 + height / 2 / 2 * Math.Sqrt(3), 0));
                        sectionpts.Add(new GSOPoint3d( -width / 2 / 2 * Math.Sqrt(2), height / 2 + height / 2 / 2 * Math.Sqrt(2), 0));
                        sectionpts.Add(new GSOPoint3d( -width / 2 / 2 * Math.Sqrt(3), height / 2 + height / 2 / 2, 0));

                        sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                        style.SetSectionPoints(sectionpts);
                        style.IsClosed = false;
                        style.SetAnchorByAlign(EnumAlign.BottomCenter);

                        line.Style = style;
                    }
                    if (txtMS.Text != "")
                    {
                        line.MoveZ(0 - double.Parse(txtMS.Text));
                    }

                    this.DialogResult = DialogResult.OK;
                    globeControl1.Refresh();

                    this.Close();
                }
                else
                {
                    MessageBox.Show("请选择隧道的类型!", "提示");
                }
            } 
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (feature != null)
            {
                feature.Copy(m_feature);

                globeControl1.Refresh();
            }
            this.Close();
        }

        private void pictureBoxFillColor_Click(object sender, EventArgs e)
        {
            ColorDialog dlg = new ColorDialog();
            dlg.FullOpen = true;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                pictureBoxFillColor.BackColor = Color.FromArgb(255, dlg.Color.R, dlg.Color.G, dlg.Color.B);
            }
        }

        private void txtMS_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox text = sender as TextBox;
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (int)e.KeyChar != 46)
            {
                e.Handled = true;
            }
            if ((int)e.KeyChar == 46)                           //小数点
            {
                if (text.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位
                else                                             //处理不规则的小数点
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(text.Text, out oldf);
                    b2 = float.TryParse(text.Text + e.KeyChar.ToString(), out f);
                    if (b2 == false)
                    {
                        if (b1 == true)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }
        }

        private void FrmCreateTunnel_Load(object sender, EventArgs e)
        {
            if (comboBoxTunnelType.Items.Count > 0)
            {
                comboBoxTunnelType.SelectedIndex = 0;
            }
        }
    }
}