/// <summary> /// 通过从CAD返回的点坐标进行Form中的添加及更新操作 /// </summary> /// <param name="point">获取的点</param> /// <param name="BEP">起始点为A 结束点为B</param> private void OprateFormData(RxTypeList.AcDbArc arc) { if (SX_AIX.Text == string.Empty || SY_AIX.Text == string.Empty) { MessageBox.Show("未初始化参考坐标!请先初始化参考坐标系!"); return; } int keepValuePoint = Convert.ToInt16(KeepValue.Text); double[] StartPoint = CadOprator.TackAix(arc.StartPoint, RefPoint, ApplyPlantAix.Checked); double[] EndPoint = CadOprator.TackAix(arc.EndPoint, RefPoint, ApplyPlantAix.Checked); double[] TCenter = CadOprator.TackAix(arc.Center, RefPoint, ApplyPlantAix.Checked); double Radius = Math.Round(arc.Radius / 1000 * 20, keepValuePoint); double StartAngle = Math.Round(arc.StartAngle, keepValuePoint); double EndAngle = Math.Round(arc.EndAngle, keepValuePoint); String Ttrack = string.Empty; if (SingeRoadSelected.Checked) { Ttrack = "SingerTrack"; } else { Ttrack = "DoubleTrack"; } if (WriteObjectToDataGrid(StartPoint, TCenter, Radius, StartAngle, EndAngle, "A", Ttrack)) { if (WriteObjectToDataGrid(EndPoint, 0, "B", Ttrack)) { /////////////////////////////////////////////////////// } } try { WriteObjectID(arc.StartPoint, arc.EndPoint, (index + "-A")); } catch (System.Exception) { //throw; } string Res = PlantOnline.WriteTrack("A_" + (index < 10?("0" + index):Convert.ToString(index)), StartPoint, EndPoint, Ttrack, StartAngle, TCenter, EndAngle, 0, Radius, RefPoint); if (Res != string.Empty) { SendDataToSocket(Res); } index += 1; return; }
private void ManulInputLine_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; if (OnlineModel.Checked != true | SX_AIX.Text == string.Empty | SX_AIX.Text == "") { MessageBox.Show("当前未切换到在线设计模式或未设置参考点坐标!,无法继续后续操作!请选择在线模式!"); this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; return; } Reset: AcadDocument caddocument = null; tAcadApplication.Visible = true; try { this.WindowState = FormWindowState.Minimized; tAcadApplication = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application"); caddocument = tAcadApplication.ActiveDocument; caddocument.Utility.Prompt("命令已初始化......!"); } catch (COMException) { //throw; } object obj, pickedObj = null; try { int JS = 0; do { JS += 1; try { caddocument.Utility.GetEntity(out obj, out pickedObj, "请选择一个直线或圆弧,取消点击空白区域、右击、ESC命令即可:"); } catch (COMException E) { if (((dynamic)E).HResult == -2147352567) { //Console.Write(((dynamic)e).Button); this.WindowState = FormWindowState.Maximized; break; } continue; } var db = caddocument.Database; dynamic NlineTaype = ((dynamic)obj).EntityName; string NlineT = Convert.ToString(NlineTaype); AcadObj = obj; switch (NlineT) { case "AcDbLine": { //((dynamic)obj).color = caddocument.ActiveLayer.color; RxTypeList.AcadLine RT = new RxTypeList.AcadLine(); RT.StartPoint = ((dynamic)obj).StartPoint; RT.EndPoint = ((dynamic)obj).EndPoint; RT.FwAngle = ((dynamic)obj).Angle; RT.Length = ((dynamic)obj).length; double[] LineCenter = new double[3] { 0, 0, 0 }; LineCenter[0] = RT.StartPoint[0] + (RT.EndPoint[0] - RT.StartPoint[0]) / 2; LineCenter[1] = RT.StartPoint[1] + (RT.EndPoint[1] - RT.StartPoint[1]) / 2; LineCenter[2] = RT.StartPoint[2] + (RT.EndPoint[2] - RT.StartPoint[2]) / 2; RT.CenterPoint = LineCenter; double Tangle = (180 / Math.PI) * RT.FwAngle; RT.FwAngle = Math.Round(Tangle, 1); OprateFormData(RT); string str = PlantOnline.WriteFence(RT.Length, RT.CenterPoint, RT.FwAngle, RefPoint); if (str != string.Empty) { SendDataToSocket(str); } break; } case "AcDbArc": { //((dynamic)obj).color = caddocument.ActiveLayer.color; RxTypeList.AcDbArc Arc = new RxTypeList.AcDbArc(); Arc.StartPoint = ((dynamic)obj).StartPoint; Arc.EndPoint = ((dynamic)obj).EndPoint; Arc.Center = ((dynamic)obj).Center; Arc.Radius = ((dynamic)obj).Radius; Arc.StartAngle = ((dynamic)obj).StartAngle; Arc.StartAngle = (180 / Math.PI) * Arc.StartAngle; Arc.EndAngle = ((dynamic)obj).EndAngle; Arc.EndAngle = (180 / Math.PI) * Arc.EndAngle; Arc.Normal = ((dynamic)obj).Normal; OprateFormData(Arc); break; } case "AcDbPolyline": { //((dynamic)obj).color = caddocument.ActiveLayer.color; RxTypeList.AcDbPolyline Pl = new RxTypeList.AcDbPolyline(); Pl.Points = ((dynamic)obj).Coordinates; int NumberLine, NumberPoints; NumberPoints = Pl.Points.Count(); //Total Polyline Point Number NumberLine = NumberPoints / 2 - 1; //Total Polyline Number int Cline = 0; for (int i = 0; i < NumberPoints; i++) { RxTypeList.AcadLine Aline = new RxTypeList.AcadLine(); try { Aline.StartPoint = new double[3] { Math.Round(Pl.Points[i], 0), Math.Round(Pl.Points[i + 1], 0), 0 }; Aline.EndPoint = new double[3] { Math.Round(Pl.Points[i + 2], 0), Math.Round(Pl.Points[i + 3], 0), 0 }; if (Aline.StartPoint == Aline.EndPoint) //始点==末点 执行下个循环 { i += 1; continue; } } catch (System.Exception) { i += 1; continue; } Aline.CenterPoint = new double[3]; Aline.CenterPoint[0] = Aline.StartPoint[0] + (Aline.EndPoint[0] - Aline.StartPoint[0]) / 2; Aline.CenterPoint[1] = Aline.StartPoint[1] + (Aline.EndPoint[1] - Aline.StartPoint[1]) / 2; Aline.CenterPoint[2] = Aline.StartPoint[2] + (Aline.EndPoint[2] - Aline.StartPoint[2]) / 2; //Aline.FwAngle = Math.Atan(Math.Abs(Aline.EndPoint[1] - Aline.StartPoint[1]) / Math.Abs(Aline.EndPoint[0] - Aline.StartPoint[0])); Aline.FwAngle = Math.Atan((Aline.EndPoint[1] - Aline.StartPoint[1]) / (Aline.EndPoint[0] - Aline.StartPoint[0])); double ASin = Aline.FwAngle; Aline.FwAngle = Math.Round(180 * Aline.FwAngle / Math.PI, 2); if (Aline.EndPoint[1] - Aline.StartPoint[1] == 0) { Aline.Length = Math.Abs(Aline.EndPoint[0] - Aline.StartPoint[0]); } else if (Aline.EndPoint[0] - Aline.StartPoint[0] == 0) { Aline.Length = Math.Abs(Aline.EndPoint[1] - Aline.StartPoint[1]); } else { double dy = Math.Abs(Aline.EndPoint[1] - Aline.StartPoint[1]); Aline.Length = Math.Round(dy / Math.Sin(ASin), 4); } if (Math.Round(Aline.Length, 0) == 0) { i += 1; continue; } Cline += 1; string str = PlantOnline.WriteFence(Aline.Length, Aline.CenterPoint, Aline.FwAngle, RefPoint); if (str != string.Empty) { SendDataToSocket(str); } //if (Cline== NumberLine) //{ // continue; //} i += 1; } break; } default: MessageBox.Show("您选择的不是一条直线无法获取起始点和结束点!"); this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; break; } try { ((dynamic)obj).color = caddocument.ActiveLayer.color; } catch (System.Exception) { continue; } } while (JS < 99999); } catch (COMException E) { if (((dynamic)E).HResult == -2147352567) { //Console.Write(((dynamic)e).Button); this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; return; } else { goto Reset; } } }
private void ManulInputLine_Click(object sender, EventArgs e) { Reset: AcadDocument caddocument = null; try { this.WindowState = FormWindowState.Minimized; tAcadApplication = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application"); caddocument = tAcadApplication.ActiveDocument; } catch (COMException) { //throw; } object obj, pickedObj = null; try { int JS = 0; do { JS += 1; try { caddocument.Utility.GetEntity(out obj, out pickedObj, "请选择一个直线或圆弧,取消点击空白区域、右击、ESC命令即可:"); } catch (COMException E) { if (((dynamic)E).HResult == -2147352567) { //Console.Write(((dynamic)e).Button); this.WindowState = FormWindowState.Maximized; break; } continue; } var db = caddocument.Database; dynamic NlineTaype = ((dynamic)obj).EntityName; string NlineT = Convert.ToString(NlineTaype); AcadObj = obj; switch (NlineT) { case "AcDbLine": { ((dynamic)obj).color = caddocument.ActiveLayer.color; RxTypeList.AcadLine RT = new RxTypeList.AcadLine(); RT.StartPoint = ((dynamic)obj).StartPoint; RT.EndPoint = ((dynamic)obj).EndPoint; RT.FwAngle = ((dynamic)obj).Angle; double Tangle = (180 / Math.PI) * RT.FwAngle; RT.FwAngle = Math.Round(Tangle, 1); OprateFormData(RT); break; } case "AcDbArc": { ((dynamic)obj).color = caddocument.ActiveLayer.color; RxTypeList.AcDbArc Arc = new RxTypeList.AcDbArc(); Arc.StartPoint = ((dynamic)obj).StartPoint; Arc.EndPoint = ((dynamic)obj).EndPoint; Arc.Center = ((dynamic)obj).Center; Arc.Radius = ((dynamic)obj).Radius; Arc.StartAngle = ((dynamic)obj).StartAngle; Arc.StartAngle = (180 / Math.PI) * Arc.StartAngle; Arc.EndAngle = ((dynamic)obj).EndAngle; Arc.EndAngle = (180 / Math.PI) * Arc.EndAngle; Arc.Normal = ((dynamic)obj).Normal; OprateFormData(Arc); break; } default: MessageBox.Show("您选择的不是一条直线无法获取起始点和结束点!"); this.WindowState = FormWindowState.Maximized; break; } } while (JS < 99999); } catch (COMException E) { if (((dynamic)E).HResult == -2147352567) { //Console.Write(((dynamic)e).Button); this.WindowState = FormWindowState.Maximized; return; } else { goto Reset; } } }