//获得线的向量角度 public static double GetLineK(MxDrawPoint p1, MxDrawPoint p2) { double k = Math.PI / 2; if (p1.x != p2.x) { double dy = p2.y - p1.y; double dx = p2.x - p1.x; k = dy / dx; k = Math.Atan(k); if (dx < 0) { k = k + Math.PI; } if (k < 0) { k = k + Math.PI * 2; } } else { if (p2.y < p1.y) { k = Math.PI * 3 / 2; } } return(k); }
public static double DistanceForPointToABLine(double x, double y, MxDrawPoint pt1, MxDrawPoint pt2)//所在点到AB线段的垂线长度 { double reVal = 0d; bool retData = false; double cross = (pt2.x - pt1.x) * (x - pt1.x) + (pt2.y - pt1.y) * (y - pt1.y); if (cross <= 0) { reVal = (float)Math.Sqrt((x - pt1.x) * (x - pt1.x) + (y - pt1.y) * (y - pt1.y)); retData = true; } double d2 = (pt2.x - pt1.x) * (pt2.x - pt1.x) + (pt2.y - pt1.y) * (pt2.y - pt1.y); if (cross >= d2) { reVal = (double)Math.Sqrt((x - pt2.x) * (x - pt2.x) + (y - pt2.y) * (y - pt2.y)); retData = true; } if (!retData) { double r = cross / d2; double px = pt1.x + (pt2.x - pt1.x) * r; double py = pt1.y + (pt2.y - pt1.y) * r; reVal = (double)Math.Sqrt((x - px) * (x - px) + (py - y) * (py - y)); } return(reVal); }
//求直线夹角 public static double GetAngle(MxDrawPoint pt, MxDrawPoint p1, MxDrawPoint p2) { double cosfi = 0, fi = 0, norm = 0; double dsx = p1.x - pt.x; double dsy = p1.y - pt.y; double dex = p2.x - pt.x; double dey = p2.y - pt.y; cosfi = dsx * dex + dsy * dey; norm = (dsx * dsx + dsy * dsy) * (dex * dex + dey * dey); cosfi /= Math.Sqrt(norm); if (cosfi >= 1.0) { return(0); } if (cosfi <= -1.0) { return(Math.PI); } fi = Math.Acos(cosfi); if (180 * fi / Math.PI < 180) { return(180 * fi / Math.PI); } else { return(360 - 180 * fi / Math.PI); } }
private void AxMxDrawX1_DynWorldDraw(object sender, _DMxDrawXEvents_DynWorldDrawEvent e) { MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pData; MxDrawWorldDraw pWorldDraw = (MxDrawWorldDraw)e.pWorldDraw; string sGuid = pCustomEntity.Guid; pWorldDraw.Color = 255; pWorldDraw.LineWidth = 1; pWorldDraw.Layer = "tkbox"; MxDrawPoint curPoint = new MxDrawPoint(); pWorldDraw.SetColorIndex(200); curPoint.x = e.dX; curPoint.y = e.dY; if (sGuid == "SelectRangeBox") { //与用户交互在图面上提取一个点 var vBasePt = pCustomEntity.GetPoint("BasePoint"); //绘制一个直线 //参数一直线的开始点x坐标,参数二直线的开始点y坐标,参数三直线的结束点x坐标,参数四直线的结束点y坐标 pWorldDraw.DrawLine(vBasePt.x, vBasePt.y, vBasePt.x, curPoint.y); pWorldDraw.DrawLine(vBasePt.x, curPoint.y, curPoint.x, curPoint.y); pWorldDraw.DrawLine(curPoint.x, curPoint.y, curPoint.x, vBasePt.y); pWorldDraw.DrawLine(curPoint.x, vBasePt.y, vBasePt.x, vBasePt.y); } }
//两条线的交点 public static PointF point_intersection(MxDrawPoint p1, MxDrawPoint p2, MxDrawPoint l1, MxDrawPoint l2) { //p1.x = Math.Round(p1.x,6); //p1.y = Math.Round(p1.y, 6); //p2.x = Math.Round(p2.x, 6); //p2.y = Math.Round(p2.y, 6); //l1.x = Math.Round(l1.x, 6); //l1.x = Math.Round(l1.y, 6); //l2.x = Math.Round(l2.x, 6); //l2.x = Math.Round(l2.y, 6); double A = -(p1.y - p2.y); double B = (p1.x - p2.x); double C = (p1.y * p2.x - p2.y * p1.x); double A1 = -(l1.y - l2.y); double B1 = (l1.x - l2.x); double C1 = (l1.y * l2.x - l2.y * l1.x); double D = A * B1 - A1 * B; if (D != 0) { double x = (B * C1 - B1 * C) / D; double y = (A1 * C - A * C1) / D; return(new PointF((float)x, (float)y)); } else { return(new PointF(0, 0)); } }
//支座与L1最远交点共点梁线 public MxDrawLine GetXpoint(MxDrawPoint pts, MxDrawPoint pte, MxDrawPolyline seat) { MxDrawPoints pty = new MxDrawPoints(); MxDrawSelectionSet collect = new MxDrawSelectionSet(); for (int i = 0; i < seat.NumVerts; i++) { MxDrawPoint temp1 = seat.GetPointAt(i); temp1.x = Math.Round(temp1.x, 6); temp1.y = Math.Round(temp1.y, 6); double angle = MathSience.GetAngle2(pts, pte); if ((angle < 3 && angle > -2) || Math.Round(Math.Abs(angle)) == 180)//左右 { if (Math.Round(pts.x, 6) != temp1.x && Math.Round(pte.x, 6) != temp1.x) { pty.Add2(temp1); } } if ((angle > 80 && angle < 95) || (angle < -80 && angle > -95))//上下 { if (Math.Round(pts.y, 6) != temp1.y && Math.Round(pte.y, 6) != temp1.y) { pty.Add2(temp1); } } } if (pty.Count > 1) { PointF ptx = MathSience.point_intersection(pts, pte, pty.Item(0), pty.Item(1)); collect.AllSelect(); for (int i = 0; i < collect.Count; i++) { MxDrawLine line = collect.Item(i) as MxDrawLine; if (line == null) { continue; } if (line.ObjectName == "McDbLine") { MxDrawPoint t1 = line.StartPoint; MxDrawPoint t2 = line.EndPoint; MxDrawPoint tp = new MxDrawPoint { x = ptx.X, y = ptx.Y }; if (Math.Abs(Math.Round(t1.x) - ptx.X) < 1.5 && Math.Abs(Math.Round(t1.y) - ptx.Y) < 1.5) { return(line); } else if (Math.Abs(Math.Round(t2.x) - ptx.X) < 1.5 && Math.Abs(Math.Round(t2.y) - ptx.Y) < 1.5) { return(line); } } } } return(new MxDrawLine()); }
//求中点坐标 public static MxDrawPoint GetCenterPoint(MxDrawPoint p1, MxDrawPoint p2) { //x =(x1 + x2)/ 2;y =(y1 + y2)/ 2 return(new MxDrawPoint { x = (p1.x + p2.x) / 2, y = (p1.y + p2.y) / 2 }); }
//选择范围 private void T1007() { axMxDrawX1.DynWorldDraw += AxMxDrawX1_DynWorldDraw;//添加动态画框事件 axMxDrawX1.AddLayer("tkbox"); MxDrawPoint pt1 = axMxDrawX1.GetPoint(false, 0, 0, "开始坐标...") as MxDrawPoint; if (pt1 == null) { return; } MxDrawUiPrPoint scpt = new MxDrawUiPrPoint(); scpt.message = "终点坐标..."; scpt.basePoint = pt1; scpt.setUseBasePt(false); var spdata = scpt.InitUserDraw("SelectRangeBox"); axMxDrawX1.SetSysVarLong("ORTHOMODE", 0); spdata.SetPoint("BasePoint", pt1); if (scpt.go() != MCAD_McUiPrStatus.mcOk) { return; } spdata.Draw(); //放大 axMxDrawX1.ZoomWindow(pt1.x, pt1.y, spdata.DragPoint.x, spdata.DragPoint.y); PublicValue = new { Lx = pt1.x, Ly = pt1.y, Lz = pt1.z, Rx = spdata.DragPoint.x, Ry = spdata.DragPoint.y, Rz = spdata.DragPoint.z }; //删除选择框 MxDrawSelectionSet ss = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); filter.AddStringEx("tkbox", 8); ss.Select(MCAD_McSelect.mcSelectionSetAll, null, null, filter); for (int i = 0; i < ss.Count; i++) { axMxDrawX1.Erase(ss.Item(i).ObjectID); } //删掉画框的图层 MxDrawDatabase database = axMxDrawX1.GetDatabase() as MxDrawDatabase; IMxDrawLayerTableRecord layer = database.GetLayerTable().GetAt("tkbox", false); if (layer != null) { layer.Erase(); } return; }
//判断线是否垂直 public static bool vertical(MxDrawPoint p1, MxDrawPoint p2, MxDrawPoint l1, MxDrawPoint l2) { if (((p2.y - p1.y) * (l2.y - l1.y) + (p2.x - p1.x) * (l2.x - l1.x)) <= 1) { return(true); } else { return(false); } }
//判断线是否平行 public static bool parallel(MxDrawPoint p1, MxDrawPoint p2, MxDrawPoint l1, MxDrawPoint l2) { if (Math.Abs((p2.y - p1.y) * (l2.x - l1.x) - (l2.y - l1.y) * (p2.x - p1.x)) <= 1) { return(true); } else { return(false); } }
//获取支座 public MxDrawPolyline GetSeatForRange(MxDrawPoint pt, MxDrawPoint spt) { double range1 = 2000, range2 = 300; MxDrawSelectionSet collect = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); MxDrawLayerTable layer = (Program.MainForm.axMxDrawX1.GetDatabase() as MxDrawDatabase).GetLayerTable(); MxDrawPoint start = new MxDrawPoint { x = pt.x + range1, y = pt.y + range1, z = pt.z }; MxDrawPoint end = new MxDrawPoint { x = pt.x - range1, y = pt.y - range1, z = pt.z }; //Program.MainForm.axMxDrawX1.DrawLine(start.x, start.y, start.x, start.y); //Program.MainForm.axMxDrawX1.DrawLine(start.x, start.y, start.x, end.y); //Program.MainForm.axMxDrawX1.DrawLine(start.x, end.y, end.x, end.y); //Program.MainForm.axMxDrawX1.DrawLine(end.x, end.y, end.x, start.y); //Program.MainForm.axMxDrawX1.DrawLine(end.x, start.y, start.x, start.y); collect.Select(MCAD_McSelect.mcSelectionSetCrossing, start, end, filter); MxDrawEntity entity; //MxDrawLayerTable layer = (Program.MainForm.axMxDrawX1.GetDatabase() as MxDrawDatabase).GetLayerTable(); //MxDrawLayerTableRecord dd; for (int i = 0; i < collect.Count; i++) { entity = collect.Item(i); if (entity == null) { continue; } if (entity.ObjectName == "McDbPolyline") { MxDrawPolyline polyline = entity as MxDrawPolyline; MxDrawLayerTableRecord dd = layer.GetAt(entity.Layer); if (dd.Color.colorIndex != 9) { MxDrawPoint st = polyline.GetStartPoint(); MxDrawPoint et = polyline.GetEndPoint(); if (st.x == et.x && st.y == et.y) { return(polyline); } } } } return(new MxDrawPolyline()); }
/// <summary> /// 判断点是否在图形上 /// </summary> /// <param name="mousePoint">鼠标坐标</param> /// <param name="startPoint">起始点</param> /// <param name="endPoint">终点</param> /// <returns></returns> public static bool IsContains(MxDrawPoint mousePoint, MxDrawPoint startPoint, MxDrawPoint endPoint) { bool result = false; //Point middlePoint = new Point(startPoint.x, endPoint.y); //左上右下 if (endPoint.x > startPoint.x && endPoint.y > startPoint.y) { if (mousePoint.x >= startPoint.x && mousePoint.x <= endPoint.x && mousePoint.y >= startPoint.y && mousePoint.y <= endPoint.y) { result = true; } } //右上左下 else if (endPoint.x < startPoint.x && endPoint.y > startPoint.y) { if (mousePoint.x <= startPoint.x && mousePoint.x >= endPoint.x && mousePoint.y >= startPoint.y && mousePoint.y <= endPoint.y) { result = true; } } //右下左上 else if (endPoint.x < startPoint.x && endPoint.y < startPoint.y) { if (mousePoint.x <= startPoint.x && mousePoint.x >= endPoint.x && mousePoint.y <= startPoint.y && mousePoint.y >= endPoint.y) { result = true; } } //左下右上 else if (endPoint.x > startPoint.x && endPoint.y < startPoint.y) { if (mousePoint.x >= startPoint.x && mousePoint.x <= endPoint.x && mousePoint.y <= startPoint.y && mousePoint.y >= endPoint.y) { result = true; } } return(result); }
//点与直线的垂足 public static MxDrawPoint PointToLineFor90(MxDrawPoint pt1, MxDrawPoint pt2, MxDrawPoint point) { if (pt2.x == pt1.x) { return(new MxDrawPoint()); } double k = (pt2.y - pt1.y) / (pt2.x - pt1.x); double x = (k * k * pt1.x + k * (point.y - pt1.y) + point.x) / (k * k + 1); double y = k * (x - pt1.x) + pt1.y; return(new MxDrawPoint { x = x, y = y }); }
//点与线的距离 public static double Distance_point_line(MxDrawPoint l1, MxDrawPoint l2, MxDrawPoint p1) { double result = 0; double A = -(l1.y - l2.y); double B = (l1.x - l2.x); double C = (l1.y * l2.x - l2.y * l1.x); if (A == 0 && B == 0) { double detax = (l1.x - p1.x); double detay = (l1.y - p1.y); result = Math.Sqrt(Math.Pow(detax, 2) + Math.Pow(detay, 2)); } else { result = Math.Abs(A * p1.x + B * p1.y + C) / Math.Sqrt(Math.Pow(A, 2) + Math.Pow(B, 2)); } return(result); }
public static double PointToSegDist(double x, double y, MxDrawPoint pt1, MxDrawPoint pt2) { double cross = (pt2.x - pt1.x) * (x - pt1.x) + (pt2.y - pt1.y) * (y - pt1.y); if (cross <= 0) { return(Math.Sqrt((x - pt1.x) * (x - pt1.x) + (y - pt1.y) * (y - pt1.y))); } double d2 = (pt2.x - pt1.x) * (pt2.x - pt1.x) + (pt2.y - pt1.y) * (pt2.y - pt1.y); if (cross >= d2) { return(Math.Sqrt((x - pt2.x) * (x - pt2.x) + (y - pt2.y) * (y - pt2.y))); } double r = cross / d2; double px = pt1.x + (pt2.x - pt1.x) * r; double py = pt1.y + (pt2.y - pt1.y) * r; return(Math.Sqrt((x - px) * (x - px) + (py - pt1.y) * (py - pt1.y))); }
//获取梁线 public MxDrawLine GetLineForRange(MxDrawLine et) { MxDrawPoint pt = et.GetStartPoint(); MxDrawPoint ept = et.GetEndPoint(); MxDrawLayerTable layer = (Program.MainForm.axMxDrawX1.GetDatabase() as MxDrawDatabase).GetLayerTable(); MxDrawSelectionSet collect = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); MxDrawLine entity; MxDrawLine result = new MxDrawLine(); double distance = 100000000; collect.Select(MCAD_McSelect.mcSelectionSetAll, null, null, filter); for (int i = 0; i < collect.Count; i++) { entity = collect.Item(i) as MxDrawLine; if (entity == null) { continue; } MxDrawLayerTableRecord dd = layer.GetAt(entity.Layer); if (entity.ObjectName == "McDbLine" && entity.handle != et.handle && dd.Color.colorIndex != 1) { //double rs1 = MathSience.pointToLineDistance(entity.GetStartPoint(), entity.GetEndPoint(), pt.x, pt.y); //double rs2 = MathSience.pointToLineDistance(entity.GetStartPoint(), entity.GetEndPoint(), ept.x, ept.y); double rs1 = MathSience.DistanceForPointToABLine(pt.x, pt.y, entity.GetStartPoint(), entity.GetEndPoint()); double rs2 = MathSience.DistanceForPointToABLine(ept.x, ept.y, entity.GetStartPoint(), entity.GetEndPoint()); if (rs1 <= distance) { distance = rs1; result = entity; } if (rs2 <= distance) { distance = rs2; result = entity; } } } return(result); }
private void AxMxDrawX1_MouseEvent1(object sender, _DMxDrawXEvents_MouseEventEvent e) { if (e.lType == 2 && (Control.ModifierKeys & Keys.Control) == Keys.Control) { MxDrawSelectionSet mxDrawSelection = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); filter.AddStringEx("HLT_BEAM_CLINE", 8); MxDrawPoint point = new MxDrawPoint { x = e.dX, y = e.dY, }; mxDrawSelection.SelectAtPoint(point, filter); if (mxDrawSelection.Count > 0) { axMxDrawX1.TwinkeEnt(mxDrawSelection.Item(0).ObjectID); onePeaceEdit.LineID = mxDrawSelection.Item(0).handle; } axMxDrawX1.MouseEvent -= AxMxDrawX1_MouseEvent1; } }
//判断点是否在直线上 public static bool GetPointIsInLine(PointF pf, MxDrawPoint p1, MxDrawPoint p2, double range = 0) { //range 判断的的误差,不需要误差则赋值0 //点在线段首尾两端之外则return false double cross = (p2.x - p1.x) * (pf.X - p1.x) + (p2.y - p1.y) * (pf.Y - p1.y); if (cross <= 0) { return(false); } double d2 = (p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y); if (cross >= d2) { return(false); } double r = cross / d2; double px = p1.x + (p2.x - p1.x) * r; double py = p1.y + (p2.y - p1.y) * r; //判断距离是否小于误差 return(Math.Sqrt((pf.X - px) * (pf.X - px) + (py - pf.Y) * (py - pf.Y)) <= range); }
//Line的起始坐标变换,左→右,上→下 public void ChangePoint() { MxDrawPoint p1 = StartPoint; MxDrawPoint p2 = EndPoint; double angle = MathSience.GetAngle2(StartPoint, EndPoint); if ((angle < 3 && angle > -2) || Math.Abs(Math.Round(angle)) == 180)//左右 { if (p1.x > p2.x) { StartPoint = p2; EndPoint = p1; } } if ((angle > 80 && angle < 95) || (angle < -80 && angle > -95))//上下 { if (p1.y > p2.y) { StartPoint = p2; EndPoint = p1; } } }
public static double GetAngle2(MxDrawPoint p1, MxDrawPoint p2) { return(Math.Atan2((p2.y - p1.y), (p2.x - p1.x)) * 180 / Math.PI); }
//获取平行线 public MxDrawLine GetparallelLine(MxDrawLine line) { double range = 600, range2 = 600; MxDrawPoint start = line.GetStartPoint(); MxDrawPoint end = line.GetEndPoint(); MxDrawSelectionSet select = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); MxDrawLayerTable layer = (Program.MainForm.axMxDrawX1.GetDatabase() as MxDrawDatabase).GetLayerTable(); double angle = MathSience.GetAngle2(start, end); if (angle < 3 && angle > -2) { range = 0; } else { range2 = 0; } select.Select(MCAD_McSelect.mcSelectionSetCrossing, new MxDrawPoint { x = start.x - range, y = start.y - range2, z = start.z }, new MxDrawPoint { x = end.x + range, y = end.y + range2, z = end.z }, filter); //Program.MainForm.axMxDrawX1.DrawLine(end.x - range, end.y - range2, end.x - range, end.y+range2); //Program.MainForm.axMxDrawX1.DrawLine(end.x - range, end.y + range2, end.x + range, end.y + range2); //Program.MainForm.axMxDrawX1.DrawLine(end.x + range, end.y + range2, end.x + range, end.y - range2); //Program.MainForm.axMxDrawX1.DrawLine(end.x + range, end.y - range2, end.x - range, end.y - range2); for (int i = 0; i < select.Count; i++) { MxDrawLine entity = select.Item(i) as MxDrawLine; if (entity == null) { continue; } if (select.Item(i).ObjectName == "McDbLine") { MxDrawLayerTableRecord dd = layer.GetAt(entity.Layer); if (line.handle != entity.handle && dd.Color.colorIndex != 1) { if (MathSience.parallel(entity.GetStartPoint(), entity.GetEndPoint(), line.GetStartPoint(), line.GetEndPoint())) { PointF point = MathSience.point_intersection(line.GetStartPoint(), line.GetEndPoint(), entity.GetStartPoint(), entity.GetEndPoint()); //if (point.X==0&&point.Y==0) { var c1 = entity.GetStartPoint(); var c2 = entity.GetEndPoint(); //if (MathSience.GetPointIsInLine(point, c1, c2, 2)) { return(entity); } } } } } } return(new MxDrawLine()); }
//获取相邻的梁线 public MxDrawLine GetMoreLine(MxDrawLine line) { int range = 600; MxDrawSelectionSet collect = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); MxDrawPoint start = line.GetStartPoint(); MxDrawPoint end = line.GetEndPoint(); MxDrawLayerTable layer = (Program.MainForm.axMxDrawX1.GetDatabase() as MxDrawDatabase).GetLayerTable(); collect.Select(MCAD_McSelect.mcSelectionSetCrossing, new MxDrawPoint { x = end.x + range, y = end.y + range, z = end.z }, new MxDrawPoint { x = end.x - range, y = end.y - range, z = end.z }, filter); //获取线判断角度<2 for (int i = 0; i < collect.Count; i++) { MxDrawLine entity = collect.Item(i) as MxDrawLine; if (entity == null) { continue; } if (entity.handle == line.handle) { continue; } if (entity.ObjectName == "McDbLine") { MxDrawLayerTableRecord cd = layer.GetAt(entity.Layer); if (cd.Color.colorIndex != 1) { double angleLine = MathSience.GetAngle(line.EndPoint, entity.StartPoint, entity.EndPoint); if (angleLine < 2) { double angle = MathSience.GetAngle2(line.GetStartPoint(), line.GetEndPoint()); double angle2 = MathSience.GetAngle2(entity.GetStartPoint(), entity.GetEndPoint()); if ((angle < 3 && angle > -2) || Math.Abs(Math.Round(angle)) == 180)//左右 { if (angle2 < 3 && angle2 > -2) { if (MathSience.GetDistance(entity.StartPoint.x, entity.StartPoint.y, entity.EndPoint.x, entity.EndPoint.y) > 100) { return(entity); } } } if ((angle > 80 && angle < 95) || (angle < -80 && angle > -95))//上下 { if ((angle2 > 80 && angle2 < 95) || (angle2 < -80 && angle2 > -95)) { if (MathSience.GetDistance(entity.StartPoint.x, entity.StartPoint.y, entity.EndPoint.x, entity.EndPoint.y) > 100) { return(entity); } } } } } } } return(new MxDrawLine()); }
public List <Text> SelectTextByBox(List <Text> texts, MxDrawPoint ps, Point3d pe) { List <Text> re = new List <Text>(); return(re); }
//选择集 private void AxMxDrawX1_MouseEvent(object sender, _DMxDrawXEvents_MouseEventEvent e) { MxDrawPoint start = new MxDrawPoint(), end = new MxDrawPoint(); if (PublicValue != null) { dynamic c = PublicValue; start.x = c.Lx; start.y = c.Ly; start.z = c.Lz; end.x = c.Rx; end.y = c.Ry; end.z = c.Rz; } { MxDrawSelectionSet mxDrawSelection; MxDrawResbuf filter; MxDrawPoint point; if (e.lType == 2 && (Control.ModifierKeys & Keys.Control) == Keys.Control) { mxDrawSelection = new MxDrawSelectionSet(); filter = new MxDrawResbuf(); point = new MxDrawPoint(); point.x = e.dX; point.y = e.dY; mxDrawSelection.SelectAtPoint(point, filter); //MessageBox.Show(mxDrawSelection.Count.ToString()); if (mxDrawSelection.Count > 0) { if (start.x != 0 && end.x != 0) { if (!MathSience.IsContains(point, start, end)) { return; } } //MessageBox.Show(mxDrawSelection.Item(0).handle.ToString()); axMxDrawX1.TwinkeEnt(mxDrawSelection.Item(0).ObjectID); if (BeamType == "change_line") { if (beam.beam.side_lines.Find(x => x == mxDrawSelection.Item(0).handle) == null) { beam.beam.side_lines.Add(mxDrawSelection.Item(0).handle); } else { axMxDrawX1.StopTwinkeEnt(mxDrawSelection.Item(0).ObjectID); beam.beam.side_lines.Remove(mxDrawSelection.Item(0).handle); } } if (BeamType == "change_dim") { if (beam.beam.dim_texts.Find(x => x == mxDrawSelection.Item(0).handle) == null) { beam.beam.dim_texts.Add(mxDrawSelection.Item(0).handle); } else { axMxDrawX1.StopTwinkeEnt(mxDrawSelection.Item(0).ObjectID); beam.beam.dim_texts.Remove(mxDrawSelection.Item(0).handle); } } if (BeamType == "change_seat") { if (beam.beam.seat_lines.Find(x => x == mxDrawSelection.Item(0).handle) == null) { beam.beam.seat_lines.Add(mxDrawSelection.Item(0).handle); } else { axMxDrawX1.StopTwinkeEnt(mxDrawSelection.Item(0).ObjectID); beam.beam.seat_lines.Remove(mxDrawSelection.Item(0).handle); } } } } else if (e.lType == 2 && (Control.ModifierKeys & Keys.Shift) == Keys.Shift) { //dynamic pt = PublicValue; //MxDrawPoint sp = new MxDrawPoint { x = pt.Lx, y = pt.Ly }; //MxDrawPoint ep = new MxDrawPoint { x = pt.Rx, y = pt.Ry }; mxDrawSelection = new MxDrawSelectionSet(); filter = new MxDrawResbuf(); point = new MxDrawPoint(); point.x = e.dX; point.y = e.dY; mxDrawSelection.SelectAtPoint(point, filter); if (mxDrawSelection.Count > 0) { MxDrawEntity entity = mxDrawSelection.Item(0); //MessageBox.Show(entity.Layer); filter = new MxDrawResbuf(); mxDrawSelection = new MxDrawSelectionSet(); filter.AddStringEx(entity.Layer, 8);// if (start.x == 0) { mxDrawSelection.Select(MCAD_McSelect.mcSelectionSetAll, null, null, filter);//获取此图层元素 } else { mxDrawSelection.Select(MCAD_McSelect.mcSelectionSetWindow, start, end, filter);//获取此图层元素 } for (int i = 0; i < mxDrawSelection.Count; i++) { axMxDrawX1.TwinkeEnt(mxDrawSelection.Item(i).ObjectID); if (BeamType == "change_line") { if (beam.beam.side_lines.Find(x => x == mxDrawSelection.Item(i).handle) == null) { beam.beam.side_lines.Add(mxDrawSelection.Item(i).handle); } else { axMxDrawX1.StopTwinkeEnt(mxDrawSelection.Item(i).ObjectID); beam.beam.side_lines.Remove(mxDrawSelection.Item(i).handle); } } if (BeamType == "change_dim") { if (beam.beam.dim_texts.Find(x => x == mxDrawSelection.Item(i).handle) == null) { beam.beam.dim_texts.Add(mxDrawSelection.Item(i).handle); } else { axMxDrawX1.StopTwinkeEnt(mxDrawSelection.Item(i).ObjectID); beam.beam.dim_texts.Remove(mxDrawSelection.Item(i).handle); } } if (BeamType == "change_seat") { if (beam.beam.seat_lines.Find(x => x == mxDrawSelection.Item(i).handle) == null) { beam.beam.seat_lines.Add(mxDrawSelection.Item(i).handle); } else { axMxDrawX1.StopTwinkeEnt(mxDrawSelection.Item(i).ObjectID); beam.beam.seat_lines.Remove(mxDrawSelection.Item(i).handle); } } //beam.beam.seat_lines.Add(mxDrawSelection.Item(i).handle); //选中元素 //axMxDrawX1.AddCurrentSelect(mxDrawSelection.Item(i).ObjectID, false, false); } } } //axMxDrawX1.SendStringToExecute(""); }; }
// 点到直线的距离 public static double pointToLineDistance(MxDrawPoint pt1, MxDrawPoint pt2, double x3, double y3) { double normalLength = Math.Sqrt((pt2.x - pt1.x) * (pt2.x - pt1.x) + (pt2.y - pt1.y) * (pt2.y - pt1.y)); return(Math.Abs((x3 - pt1.x) * (pt2.y - pt1.y) - (y3 - pt1.y) * (pt2.x - pt1.x)) / normalLength); }
//鼠标点击事件 private void axMxDrawX1_MouseEvent(object sender, AxMxDrawXLib._DMxDrawXEvents_MouseEventEvent e) { /* * 事件类型,1鼠标移动,2是鼠标左键按下,3是鼠标右键按下,4是鼠标左键双击 * 5是鼠标左键释放 6是鼠标右键释放 7是鼠标中键按下 8是鼠标中键释放 * 9是鼠标中键双击 10是鼠标中键滚动 */ switch (e.lType) { case 4: //左键选择元素图层--所有元素 //if(bar_state.state==true&& bar_state.id == 1001) { MxDrawSelectionSet mxDrawSelection = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); MxDrawPoint point = new MxDrawPoint(); point.x = e.dX; point.y = e.dY; mxDrawSelection.SelectAtPoint(point, filter); if (mxDrawSelection.Count > 0) { MxDrawEntity entity = mxDrawSelection.Item(1); //MxDrawLayerTable layer = (axMxDrawX1.GetDatabase() as MxDrawDatabase).GetLayerTable(); //MxDrawLayerTableRecord dd = layer.GetAt(entity.Layer); if (entity.ObjectName == "McDbLine") { MessageBox.Show(JsonConvert.SerializeObject(new { handle = entity.handle, ID = entity.ObjectID, Line = entity.ObjectName, B = entity.LineType, pt1 = ((MxDrawLine)entity).GetStartPoint(), pt2 = ((MxDrawLine)entity).GetEndPoint(), //color=dd.Color.colorIndex })); } else { MessageBox.Show(JsonConvert.SerializeObject(new { handle = entity.handle, ID = entity.ObjectID, Line = entity.ObjectName, B = entity.LineType, rotate = ((MxDrawText)entity).Rotation //pt1 = ((MxDrawLine)entity).GetStartPoint(), //pt2 = ((MxDrawLine)entity).GetEndPoint(), //color=dd.Color.colorIndex })); } //double c=Models.MathSience.DistanceForPointToABLine(121324.953422, 33700.002475, ((MxDrawLine)entity).GetStartPoint(),((MxDrawLine)entity).GetEndPoint()); //double c1 = Algorithm.MathSience.GetAngle(new MxDrawPoint { x = 121324.95342187915, y = 54350.00279569807 }, ((MxDrawLine)entity).GetStartPoint(), ((MxDrawLine)entity).GetEndPoint()); double c1 = Algorithm.MathSience.GetLineK(((MxDrawLine)entity).GetStartPoint(), ((MxDrawLine)entity).GetEndPoint()); MessageBox.Show(c1.ToString()); //double c = Algorithm.MathSience.GetAngle2(((MxDrawLine)entity).GetStartPoint(), ((MxDrawLine)entity).GetEndPoint()); //MxDrawLine line = axMxDrawX1.HandleToObject("61FCB") as MxDrawLine; //PointF point1 = Algorithm.MathSience.point_intersection(line.GetStartPoint(), line.GetEndPoint(), ((MxDrawLine)entity).GetStartPoint(), ((MxDrawLine)entity).GetEndPoint()); } } break; } }
private void FillBeamStruct() { #region beam HLTSmart smart = new HLTSmart(); //第一步:遍历所有文字,找出满足如下正则表达式的文字,即为集中标注第一行 List <Regex> regex1 = new List <Regex> { //new Regex(@"(KL|L|WKL|WL|KZL|LL|JL|DL)[-]?\d{1,4}") new Regex(@"((KL|L|WKL|WL|KZL|LL|JL|DL)(\d{1,4})\([A-Z0-9]{1,4}\)\s)?(\d{1,4})X(\d{1,4})") }; List <Text> texts = new List <Text>(); //获取dim_text值 MxDrawText entity; foreach (var item in beam.dim_texts) { entity = Program.MainForm.axMxDrawX1.HandleToObject(item) as MxDrawText; if (entity != null) { texts.Add(new Text { Position = new Point3d { X = entity.Position.x, Y = entity.Position.y, Z = entity.Position.z }, Layer = entity.Layer, TextString = entity.TextString, Height = entity.Height, Rotation = entity.Rotation }); } } List <Text> Restexts = smart.GetWord(texts, regex1); //第二步:找到后还需验证这个字的左侧定位点 字体高度2倍范围内有无直线(即指示线) Point3d pt = new Point3d(); MxDrawSelectionSet select = new MxDrawSelectionSet(); foreach (var item in Restexts) { pt = item.Position; MxDrawPoint pt1 = new MxDrawPoint { x = pt.X - 1 * item.Height, y = pt.Y - 1 * item.Height, z = pt.Z }; MxDrawPoint pt2 = new MxDrawPoint { x = pt.X + 1 * item.Height, y = pt.Y + 1 * item.Height, z = pt.Z }; //Program.MainForm.axMxDrawX1.DrawLine(pt.X, pt.Y, pt.X+1, pt.Y+1); //Program.MainForm.axMxDrawX1.DrawLine(pt1.x, pt1.y, pt1.x, pt2.y); //Program.MainForm.axMxDrawX1.DrawLine(pt1.x, pt2.y, pt2.x, pt2.y); //Program.MainForm.axMxDrawX1.DrawLine(pt2.x, pt2.y, pt2.x, pt1.y); //Program.MainForm.axMxDrawX1.DrawLine(pt2.x, pt1.y, pt1.x, pt1.y); select.Select(MCAD_McSelect.mcSelectionSetCrossing, pt1, pt2, new MxDrawResbuf()); MxDrawLine drawEntity; MxDrawPoint pst, ped; List <Text> text3 = new List <Text>(); for (int i = 0; i < select.Count; i++) { drawEntity = select.Item(i) as MxDrawLine; //第三步:遍历第二步的结果,逐一按下面计算,例如第n个结果 if (drawEntity != null && drawEntity.ObjectName == "McDbLine") { Program.MainForm.axMxDrawX1.TwinkeEnt(drawEntity.ObjectID); pst = drawEntity.GetStartPoint(); ped = drawEntity.GetEndPoint(); text3 = smart.SelectTextByBox(texts, new Point3d { X = pst.x, Y = pst.y, Z = pst.z }, item.Position); //第四步:从第三步结果中逐行用关键字匹配出参数信息 Beam beams = new Beam(); beams.owner = new List <string>(); beams.Sections = new List <Beam_Section>(); beams.Stirrup_info = new List <Stirrup_Dim>(); beams.Public_Bar = new List <Rebar_Dim>(); beams.Mid_Beam_Rebars = new List <List <Rebar_Dim> >(); beams.Waist_Bar = new List <Rebar_Dim>(); beams.Twist_Bar = new List <Rebar_Dim>(); string kval = ""; for (int k = 0; k < text3.Count; k++) { //KL14(1A) 300X400 kval = Regex.Match(text3[k].TextString, @"(KL|L|WKL|WL|KZL|LL|JL|DL)").Value; if (kval != "") { beams.type = kval;//(Side_type)Enum.Parse(typeof(Side_type),kval); beams.owner = GetItemAsync(text3[k].TextString); } //梁截面 kval = Regex.Match(text3[k].TextString, @"(\d{2,4}~)?(\d{2,4})(x|X)(\d{2,4})(~\d{2,4})?").Value; string[] vals = kval.Split(new char[] { '~', 'x', 'X' }); if (kval != "") { if (kval.IndexOf('~') == -1) { beams.Sections.Add(new Beam_Section { a = 1, b = Convert.ToDouble(vals[0]), h = Convert.ToDouble(vals[1]) }); } else { if (kval.IndexOf("x", StringComparison.OrdinalIgnoreCase) > kval.IndexOf('~')) { //变截面宽 350~450x700 beams.Sections.Add(new Beam_Section { a = 1, b = Convert.ToDouble(vals[0]), h = Convert.ToDouble(vals[2]), }); beams.Sections.Add(new Beam_Section { a = 1, b = Convert.ToDouble(vals[1]), h = Convert.ToDouble(vals[2]), }); } else { //变截面高 350x650~800 beams.Sections.Add(new Beam_Section { a = 1, b = Convert.ToDouble(vals[0]), h = Convert.ToDouble(vals[1]), }); beams.Sections.Add(new Beam_Section { a = 1, b = Convert.ToDouble(vals[0]), h = Convert.ToDouble(vals[2]), }); } } continue; } //箍筋 Φ12@100/200(4) kval = Regex.Match(text3[k].TextString, @"((%%130)|(%%131)|(%%132))(\d{1,3})@(\d{2,3})(/\d{2,3})?\(\d{1,2}\)").Value; if (kval != "") { beams.Stirrup_info.Add(new Stirrup_Dim { D = Convert.ToDouble(kval.Substring(5, kval.IndexOf('@') - 5)), Se = Convert.ToDouble(SplitStr(kval, kval.IndexOf('@'), "/(")), Sa = Convert.ToDouble(SplitStr(kval, kval.IndexOf('/'), "((")), n = Convert.ToInt32(SplitStr(kval, kval.IndexOf('('), "))")) }); continue; } //通长钢筋 4Φ20;7Φ20 3/4 kval = Regex.Match(text3[k].TextString, @"^[A-Z]{0}(\(?\d{1,3}%%132\d{1,3}\)?)(\+\(?\d{1,3}%%132\d{1,3}\))?;?(\(?\d{1,3}%%132\d{1,3}\)?)?\s?(/?(\d{1,3})?)*").Value; if (kval != "") { string[] sp1 = kval.Split(';'); for (int v = 0; v < sp1.Count(); v++) { string[] sp2 = sp1[v].Split('+'); for (int f = 0; f < sp2.Count(); f++) { sp2[f] = sp2[f].Replace("(", ""); sp2[f] = sp2[f].Replace(")", ""); sp2[f] = sp2[f].Replace("%%132", "|"); string[] sp3 = sp2[f].Split('|'); List <Rebar_Dim> Bdim = new List <Rebar_Dim>(); if (sp2[f].IndexOf('/') == -1) { int c = 0; if (sp2.Count() > 1) { c = f + 1; } if (v == 1) { Bdim.Add(new Rebar_Dim { C = c, n = Convert.ToInt32(sp3[0]), D = Convert.ToInt32(sp3[1]) }); } else { beams.Public_Bar.Add(new Rebar_Dim { C = c, n = Convert.ToInt32(sp3[0]), D = Convert.ToInt32(sp3[1]) }); } } else { sp3[1] = sp3[1].Split(' ')[0]; string xi = sp2[f].Substring(sp2[f].IndexOf(' ')); string[] sp4 = xi.Trim().Split('/'); for (int s = 0; s < sp4.Count(); s++) { if (v == 1) { Bdim.Add(new Rebar_Dim { n = Convert.ToInt32(sp4[s]), D = Convert.ToInt32(sp3[1]) }); } else { beams.Public_Bar.Add(new Rebar_Dim { n = Convert.ToInt32(sp4[s]), D = Convert.ToInt32(sp3[1]) }); } } } beams.Mid_Beam_Rebars.Add(Bdim); } } continue; } //腰筋 G4Φ12+N4Φ12 kval = Regex.Match(text3[k].TextString, @"(\+?(G|N)\d{1,3}%%132\d{1,3})*").Value; if (kval != null) { string[] sp1 = kval.Split('+'); for (int c = 0; c < sp1.Length; c++) { sp1[c] = sp1[c].Replace("%%132", "|"); string[] sp2 = sp1[c].Split('|'); if (sp2.Length == 2) { char G = sp2[0][0]; int N = Convert.ToInt32(sp2[0].Substring(1)); int C = 0; if (sp1.Length == 2) { C = c + 1; } if (G == 'G') { beams.Waist_Bar.Add(new Rebar_Dim { n = N, C = C, D = Convert.ToDouble(sp2[1]) }); } if (G == 'N') { beams.Twist_Bar.Add(new Rebar_Dim { n = N, C = C, D = Convert.ToDouble(sp2[1]) }); } } } continue; } //标高 (-0.150) kval = Regex.Match(text3[k].TextString, @"(\(?-?\d{1,3}.\d{3}\)?)").Value; if (kval != null) { kval = kval.Replace("(", ""); kval = kval.Replace(")", ""); beams.Sections = beams.Sections.Select(x => { x.H = Convert.ToDouble(kval); return(x); }).ToList(); } } beam.beams.Add(beams); beams.side_lines = new List <string>(); //识别梁 //1.集中标注指示线两个端点分别找到垂直距离最近的梁线,两者最近的就是第一根梁线L1 MxDrawLine LT1; MxDrawLine L1 = GetLineForRange(drawEntity); beams.side_lines.Add(L1.handle); //L1 = Program.MainForm.axMxDrawX1.HandleToObject("61FBA") as MxDrawLine; LT1 = L1; for (int c1 = 0; c1 < 2; c1++) { //2.L1有两个点P1,P2,先从P1开始如下步骤,完了之后再P2 //3.找距离P1点2000内的支座线,并且L1与支座线交点距离P1小于300,若有结果则按3.2若无结果按3.1 L1 = LT1; Program.MainForm.axMxDrawX1.TwinkeEnt(L1.ObjectID); int cs = 0; do { if (c1 == 1) { MxDrawPoint temp = L1.StartPoint; L1.StartPoint = L1.EndPoint; L1.EndPoint = temp; } MxDrawPolyline seat = GetSeatForRange(L1.EndPoint, L1.StartPoint); MxDrawLine L2 = new MxDrawLine(); MxDrawLine L2s = new MxDrawLine(); MxDrawLine Rline = new MxDrawLine(); if (seat.handle != "0") { //有结果3.2 L2 = GetparallelLine(L1); Rline = GetXpoint(L1.EndPoint, L1.StartPoint, seat); L1 = Rline; beams.side_lines.Add(L2.handle); beams.side_lines.Add(Rline.handle); } else { //无结果3.1 L2s = GetMoreLine(L1); L2 = GetparallelLine(L1); L1 = L2s; beams.side_lines.Add(L2s.handle); } //3.1 找到另一根梁线L2,L2的两个端点之一与P1最近且距离小于600且两线角度差别不超过2度,找到后凭L2另一个端点重复3 /*3.2 说明一段梁结束,去寻找这段梁已识别梁线的平行线,即水平距离小于梁宽的1.5倍且两线相关, * 再寻找与这些梁线共点且角度差别小于40度的梁线,找完写入beam; * 然后用3的支座线与L1求到最远相关交点P3,求与P3最近的梁线,且角度差别小于40度,用这根新梁线远端点作为P1重复3 */ cs++; //Program.MainForm.axMxDrawX1.StopAllTwinkeEnt(); Program.MainForm.axMxDrawX1.TwinkeEnt(L1.ObjectID); Program.MainForm.axMxDrawX1.TwinkeEnt(L2s.ObjectID); Program.MainForm.axMxDrawX1.TwinkeEnt(seat.ObjectID); Program.MainForm.axMxDrawX1.TwinkeEnt(L2.ObjectID); Program.MainForm.axMxDrawX1.TwinkeEnt(Rline.ObjectID); if (cs > 10) { break; } } while (L1.handle != "0"); } //break; } } } #endregion over }