/// <summary> /// 捕获当前的兴趣点 /// </summary> /// <param name="p"></param> private void SetIntersectPointCatch(IntersectPoint p) { ///首先移除对应的捕捉 this.RemoveTemporaryVisualsByType(0); if (p != null) { if (p.Line != null) { SnapGeometry hotpoint = new SnapGeometry(p); //在当前长度捕捉位置可以输入距离 this.AddTemporaryVisual(hotpoint); //更新捕捉点 hotpoint.Update(); } else { //在当前长度捕捉位置可以输入距离 SnapGeometry hotpoint = new SnapGeometry(p); //更新捕捉点 this.AddTemporaryVisual(hotpoint); hotpoint.Update(); } } }
/// <summary> /// 右键按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawingControl_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { //定义当前右键点击事件 if (RightMenuEvent != null) { Vector2D p = KernelProperty.PixToMM(e.GetPosition(this)); if (EAction != null) { IntersectPoint catchPoint = GetIntersectPointCatch(p); //设置捕获点 if (catchPoint != null) { p = catchPoint.Point; } } RightMouseEventArgs rmea = new RightMouseEventArgs(EAction, p); RightMenuEvent(rmea); } else { EAction.Termimal(); } }
/// <summary> /// 获取捕获点 /// </summary> /// <param name="v"></param> private IntersectPoint GetIntersectPointCatch(Vector2D v) { IntersectPoint catchPoint = null; //是否按住了shift键 if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) || KernelProperty.CanCatchShift) { Vector2D pnt = EAction.GetPreviousPoint(); if (pnt != null) { //安装Shift按钮的选中状态 catchPoint = InterestPointCatch.GetShiftPoint(pnt, v, EAction); } else { catchPoint = InterestPointCatch.Catch(v, EAction); } } else { //查找捕获点 catchPoint = InterestPointCatch.Catch(v, EAction); } //假如不是命令的话,则显示标尺信息 if (!(this.EAction is DrawingKernel.Commands.ICommand)) { //在界面上显示捕获点对象 this.SetIntersectPointCatch(catchPoint); } //返回当前的兴趣点 return(catchPoint); }
/// <summary> /// 对当前进行选择,当前函数,是元素边界选择,非中心选择,元素的图形选择,交给外部实现 /// </summary> /// <param name="v"></param> /// <returns></returns> public virtual IntersectGeometry Select(Vector2D v = null) { if (IsEnabled) { IntersectPoint ip = null; ip = IntersectPoint(v); if (ip != null) { IntersectGeometry ig = new IntersectGeometry(); ig.GeometryShape = this; ig.IntersectPoint = ip; SelectedEventArgs gea = new SelectedEventArgs(ig); if (Selected != null) { Selected(gea); } this.DashStyle = new DashStyle(new double[] { 3, 3 }, 0); this.Update(); return(ig); } else { return(null); } } return(null); }
/// <summary> /// 捕获圆形上的点 /// </summary> /// <param name="v"></param> /// <returns></returns> public override IntersectPoint IntersectPoint(Vector2D v) { if (Math.Abs(v.Distance(this.Start) - this.Radius) < KernelProperty.PixelToSize) { Line2D l = Line2D.Create(this.Start, v); Vector2D nv = this.Start.Offset(this.Radius, l.Direction); IntersectPoint ip = new IntersectPoint(); ip.IntersectPointStyle = 1; ip.Line = l; ip.Point = nv; return(ip); } return(null); }
/// <summary> /// 鼠标的移动事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawingControl_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { Vector2D p = KernelProperty.PixToMM(e.GetPosition(this)); //清除当前所有的捕捉点 this.SetIntersectPointCatch(null); //按着中间键,说明只是想拖动 if (IsDraging) { this.DragMoveView(e.GetPosition(this)); } else { if (EAction != null) { //假如在绘制过程中,则直接捕获兴趣点 IntersectPoint catchPoint = GetIntersectPointCatch(p); //假如设置当前橡皮筋效果 if (EAction.Geometry != null) { //进行橡皮筋效果 if (EAction.Geometry.IsActioning) { if (catchPoint != null) { EAction.Erase(catchPoint.Point); } else { EAction.Erase(p); } } } } else { //判断当前是否是框选状态 if (isBoxSelect) { SelectionBoxCatch.Select(p); } } } }
/// <summary> /// 捕获当前图形信息 /// </summary> /// <param name="v"></param> /// <returns></returns> public override IntersectPoint IntersectPoint(Vector2D v) { for (int i = 0; i < Lines.Count; i++) { var len = Lines[i].Distance(v); if (len < KernelProperty.Tolerance) { IntersectPoint ip = new IntersectPoint(); var nv = v.ProjectOn(Lines[i]); ip.IntersectPointStyle = 1; ip.Line = Lines[i]; ip.Point = nv; return(ip); } } return(null); }
/// <summary> /// 不允许重合出现,所有假如绘制当前图形,则相交点总为空 /// </summary> /// <param name="v"></param> /// <returns></returns> public override IntersectPoint IntersectPoint2(Vector2D v) { if (this.Lines.Count > 0) { var clines = this.Lines; clines.RemoveAt(this.Lines.Count - 1); for (int i = 0; i < clines.Count; i++) { var len = clines[i].Distance(v); if (len < KernelProperty.Tolerance) { IntersectPoint ip = new IntersectPoint(); var nv = v.ProjectOn(Lines[i]); ip.IntersectPointStyle = 1; ip.Line = clines[i]; ip.Point = nv; return(ip); } } } return(null); }
/// <summary> /// 鼠标的按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawingControl_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { //进行坐标转化 Vector2D p = KernelProperty.PixToMM(e.GetPosition(this)); if (EAction != null) { if (EAction is DrawingKernel.Commands.ICommand && (EAction as DrawingKernel.Commands.ICommand).GetTarget() == null) { //没有绘制动作,则是物品选择 isBoxSelect = true; //开始进行选择操作 SelectionBoxCatch.SelectStart(p); } else { IntersectPoint catchPoint = GetIntersectPointCatch(p); //设置捕获点 if (catchPoint != null) { EAction.SetPoint(catchPoint.Point); } else { EAction.SetPoint(p); } } } else { //没有绘制动作,则是物品选择 isBoxSelect = true; SelectionBoxCatch.SelectStart(p); } }
/// <summary> /// 捕获圆形上的点 /// </summary> /// <param name="v"></param> /// <returns></returns> public override IntersectPoint IntersectPoint(Vector2D v) { double ax = 0, ay = 0; switch (ImageAlign) { case Align.CENTER: ax = Central.X - BitmapImage.Width / 2; ay = Central.Y - BitmapImage.Height / 2; break; case Align.CENTER_TOP: ax = Central.X - BitmapImage.Width / 2; ay = Central.Y; break; case Align.CENTER_BOTTOM: ax = Central.X - BitmapImage.Width / 2; ay = Central.Y - BitmapImage.Height; break; case Align.LEFT_TOP: ax = Central.X; ay = Central.Y; break; case Align.LEFT_CENTER: ax = Central.X; ay = Central.Y - BitmapImage.Height / 2; break; case Align.LEFT_BOTTOM: ax = Central.X; ay = Central.Y - BitmapImage.Height; break; case Align.RIGHT_TOP: ax = Central.X - BitmapImage.Width; ay = Central.Y; break; case Align.RIGHT_CENTER: ax = Central.X - BitmapImage.Width; ay = Central.Y - BitmapImage.Height / 2; break; case Align.RIGHT_BOTTOM: ax = Central.X - BitmapImage.Width; ay = Central.Y - BitmapImage.Height; break; } if ((v.X > ax && v.X < ax + bitmapImage.Width) && (v.Y > ay && v.Y < ay + bitmapImage.Height)) { IntersectPoint ip = new IntersectPoint(); ip.IntersectPointStyle = 1; ip.Point = v; return(ip); } return(null); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { interPoints = new List <IntersectPoint>(); DF2DApplication app = DF2DApplication.Application; bool ready = true; if (app == null || app.Current2DMapControl == null) { return; } m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; IGeometry pGeo = null; IPointCollection pIntersectPC; IPointCollection pLandSufPC; double length = 0.0; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine; pLine = pRubberBand.TrackNew(m_Display, null); object symbol = pLineSym as object; app.Current2DMapControl.DrawShape(pLine, ref symbol); WaitForm.Start("正在查询...", "请稍后"); //pGeo = PublicFunction.DoBuffer(pLine,PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); pGeo = pLine; if (pGeo == null) { return; } length = (pGeo as IPolyline).Length; if (ready) { double distemp = 0.0; IPoint tempPoint = null; foreach (LogicGroup lg in LogicDataStructureManage.Instance.RootLogicGroups) { foreach (MajorClass mc in lg.MajorClasses) { foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible2D) { continue; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } if (fc == null || pGeo == null) { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.WhereClause = "SMSCODE = '" + sc.Name + "'"; int count = fc.FeatureCount(pSpatialFilter); if (count == 0) { continue; } pFeatureCursor = fc.Search(pSpatialFilter, false); string fcName = mc.Name; if (pFeatureCursor == null) { continue; } double distance; while ((pFeature = pFeatureCursor.NextFeature()) != null) { IGeometry pPipeLineGeo = pFeature.Shape; ITopologicalOperator pTopo = pPipeLineGeo as ITopologicalOperator; IGeometry geo = pTopo.Intersect(pGeo, esriGeometryDimension.esriGeometry0Dimension); IPoint intersect; if (geo is IPoint) { double distanceF = double.MaxValue; intersect = geo as IPoint; if (pGeo is IPolyline) { IPolyline line = pGeo as IPolyline; IPoint fromPoint = line.FromPoint; distanceF = GetDistanceOfTwoPoints(intersect, fromPoint); } if (distemp == 0.0) { distance = distanceF; distemp = distanceF; } else { distance = Math.Abs(distanceF - distemp); } IntersectPoint interPoint = new IntersectPoint(pFeature, intersect, fcName, distance, distanceF); interPoints.Add(interPoint); } if (geo is IPointCollection) { IPointCollection geoCol = geo as IPointCollection; for (int i = 0; i < geoCol.PointCount; i++) { intersect = geoCol.get_Point(i) as IPoint; double distanceF = double.MaxValue; if (pGeo is IPolyline) { IPolyline line = pGeo as IPolyline; IPoint fromPoint = line.FromPoint; IPoint toPoint = line.ToPoint; if (distemp == 0.0) { double distance1 = GetDistanceOfTwoPoints(intersect, fromPoint); double distance2 = GetDistanceOfTwoPoints(intersect, toPoint); distanceF = distance1 < distance2 ? distance1 : distance2; tempPoint = distance1 < distance2 ? fromPoint:toPoint; } else { if (tempPoint == null) { return; } distanceF = GetDistanceOfTwoPoints(intersect, tempPoint); } } if (distemp == 0.0) { distance = distanceF; distemp = distanceF; } else { distance = Math.Abs(distanceF - distemp); } IntersectPoint interPoint = new IntersectPoint(pFeature, intersect, fcName, distance, distanceF); interPoints.Add(interPoint); } } } } } } } } } DrawPipeTransection(interPoints, length); } catch (System.Exception ex) { } }
private void Draw(Graphics g, int winWidth, int winheight, List <IntersectPoint> listInterPnts, string mapNum, string mapName) { try { Pen pen = new Pen(Color.Black, 2); Font font = new Font("Times New Roman", 9); SolidBrush drawBrush = new SolidBrush(Color.Black); //按距离画线起点对管线交点进行排序 List <IntersectPoint> orderList = listInterPnts.OrderBy(i => i.DistanceF).ToList <IntersectPoint>(); //确定竖向比例 double minHeight = double.MaxValue; double maxHeight = double.MinValue; string road = null; foreach (IntersectPoint inpnt in orderList) { if (inpnt.H < minHeight) { minHeight = inpnt.H; } if (inpnt.H > maxHeight) { maxHeight = inpnt.H; } if (inpnt.ZPipeTop < minHeight) { minHeight = inpnt.ZPipeTop; } if (inpnt.ZPipeTop > maxHeight) { maxHeight = inpnt.ZPipeTop; } if (inpnt.Road != null) { road = inpnt.Road; } else { road = "未知"; } } //计算管线间的相互距离,并写入IntersectPoint类 for (int i = 0; i < orderList.Count; i++) { if (i == 0) { orderList[i].Distance = orderList[i].DistanceF; } else { orderList[i].Distance = orderList[i].DistanceF - orderList[i - 1].DistanceF; } } double constHeight = 20; //高程常数20m //double constwidth = 5;//管线截面两边预留长度5m double totalYSpan = maxHeight - minHeight + constHeight; //画图区域竖向总高度 double totalXSpan = orderList[orderList.Count - 1].DistanceF - orderList[0].DistanceF; //画图区域横向总长度 double paddingLeft = 30; double paddingRight = 30; double paddingBottom = 20; double paddingTop = 40; double canvasTotalWidth = winWidth; //图片横向总像素 double canvasTotalHeight = winheight; //图片纵向总像素 //绘制外图廓 double constOutlineY = 50;//外图廓据顶部边缘距离 double outlineXOrigin = paddingLeft; double outlineYOrigin = paddingTop + constOutlineY; double outlineWidth = canvasTotalWidth - paddingLeft - paddingRight; double outlineHeight = canvasTotalHeight - paddingBottom - outlineYOrigin; g.DrawRectangle(pen, (float)outlineXOrigin, (float)outlineYOrigin, (float)outlineWidth, (float)outlineHeight); Font fontTitle = new Font("宋体", 20); g.DrawString(mapName, fontTitle, drawBrush, new PointF((float)(canvasTotalWidth / 2) - 150, 20)); g.DrawString("所在道路:" + road, font, drawBrush, new PointF((float)outlineXOrigin + 10, (float)outlineYOrigin - 30)); g.DrawString("断面号:" + mapNum, font, drawBrush, new PointF((float)(canvasTotalWidth - paddingRight - 170), (float)outlineYOrigin - 30)); //绘制表格 double constTable = 30; double tableHeight = 150; int rowCount = 5; int rowHeight = (int)tableHeight / rowCount; double tableXOrigin = outlineXOrigin + constTable; double tableYOrigin = canvasTotalHeight - tableHeight - paddingBottom; double tableWidth = outlineWidth - 2 * constTable; g.DrawRectangle(pen, (int)tableXOrigin, (int)tableYOrigin, (float)tableWidth, (float)tableHeight); g.DrawString("地面高程(m)", font, drawBrush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 0 + 10); g.DrawString("管线高程(m)", font, drawBrush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 1 + 10); g.DrawString(" 规 格(mm)", font, drawBrush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 2 + 10); g.DrawString(" 间 距(m)", font, drawBrush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 3 + 10); float constCol = 100;//标题栏右边线 g.DrawLine(pen, new PointF((float)tableXOrigin + constCol, (float)tableYOrigin), new PointF((float)tableXOrigin + constCol, (float)(tableYOrigin + tableHeight))); for (int i = 1; i < rowCount; i++) { pen.Width = 1; g.DrawLine(pen, (float)tableXOrigin, (float)tableYOrigin + rowHeight * i, (float)(tableXOrigin + tableWidth), (float)tableYOrigin + rowHeight * i); } //绘制画图区域 double constCan = constCol + 50; double constCanY = 80; double constCanBlank = 100;//第一根管线距左侧边线的屏幕距离 double canXOrigin = tableXOrigin + constCan; double canYOrigin = outlineYOrigin + constCanY; double canWidth = canvasTotalWidth - canXOrigin - paddingRight - constCol; //double canHeight = canvasTotalHeight - outlineYOrigin - paddingBottom - constCanY; double canHeight = canvasTotalHeight - outlineYOrigin - paddingBottom - constCanY - tableHeight; double xRadio = totalXSpan * 1000 / (canWidth - 2 * constCanBlank); double yRadio = totalYSpan * 1000 / (canHeight); //确定管线在画图区域的相对位置,转换为屏幕距离,并写入IntersectPoint类 for (int i = 0; i < orderList.Count; i++) { if (i == 0) { orderList[i].DistanceDraw = constCanBlank; } else { orderList[i].DistanceDraw = orderList[i].Distance * 1000 / xRadio + orderList[i - 1].DistanceDraw; } } //计算管线交点及地面高在画图区域的相对高程 double dH = maxHeight - minHeight; foreach (IntersectPoint intPnt in orderList) { intPnt.ZDraw = (intPnt.ZPipeTop / maxHeight) * (dH + constHeight); intPnt.HDraw = (intPnt.H / maxHeight) * (dH + constHeight); } g.DrawString("比例尺", font, drawBrush, (float)(canvasTotalWidth / 2) - 80, (float)outlineYOrigin + 40); g.DrawString("水平 1:" + Math.Ceiling(xRadio).ToString(), font, drawBrush, (float)(canvasTotalWidth / 2) - 20, (float)outlineYOrigin + 30); g.DrawString("垂直 1:" + Math.Ceiling(yRadio).ToString(), font, drawBrush, (float)(canvasTotalWidth / 2) - 20, (float)outlineYOrigin + 50); pen.Width = 2; PointF startP = new PointF((float)canXOrigin, (float)canYOrigin); PointF endP = new PointF((float)(canXOrigin + canWidth), (float)canYOrigin); g.DrawLine(pen, startP, new PointF((float)canXOrigin, (float)(canvasTotalHeight - paddingBottom))); g.DrawLine(pen, endP, new PointF((float)(canXOrigin + canWidth), (float)(canvasTotalHeight - paddingBottom))); //方向标 pen.Width = 1; pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; g.DrawLine(pen, new PointF((float)(canXOrigin + canWidth - 160), (float)outlineYOrigin + 40), new PointF((float)(canXOrigin + canWidth - 80), (float)outlineYOrigin + 40)); g.DrawLine(pen, new PointF((float)(canXOrigin + canWidth - 100), (float)outlineYOrigin + 30), new PointF((float)(canXOrigin + canWidth - 80), (float)outlineYOrigin + 40)); g.DrawString("S", font, drawBrush, new PointF((float)(canXOrigin + canWidth - 120), (float)outlineYOrigin + 25)); //绘制地面线 g.DrawLine(pen, startP, new PointF((float)(orderList[0].DistanceDraw + canXOrigin), (float)((totalYSpan - orderList[0].HDraw) * 1000 / yRadio + canYOrigin)));//竖向因坐标方向与高程方向相反,需另行转化屏幕距离 g.DrawLine(pen, endP, new PointF((float)(orderList[orderList.Count - 1].DistanceDraw + canXOrigin), (float)((totalYSpan - orderList[orderList.Count - 1].HDraw) * 1000 / yRadio + canYOrigin))); double x0, y0, x1, y1; for (int i = 1; i < orderList.Count; i++) { x0 = orderList[i - 1].DistanceDraw + canXOrigin; x1 = orderList[i].DistanceDraw + canXOrigin; y0 = (totalYSpan - orderList[i - 1].HDraw) * 1000 / yRadio + canYOrigin; y1 = (totalYSpan - orderList[i].HDraw) * 1000 / yRadio + canYOrigin; pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; pen.Width = 1; g.DrawLine(pen, (int)x0, (int)y0, (int)x1, (int)y1); } //绘制横断面 double zoom = 1; float constfc = 20; float constStrY = 15; float constStrX = 10; double radioTemp = xRadio > yRadio ? xRadio : yRadio; for (int i = 0; i < orderList.Count; i++) { IntersectPoint intPnt = orderList[i]; string diameter = intPnt.Diameter; double distanceDraw = intPnt.DistanceDraw; double diaWidth = 0.0; double diaHeight = 0.0; double dia = 0.0; double x; double y; double xline; double yline; RotateText rotate = new RotateText(); rotate.Graphics = g; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; font = new Font("Times New Roman", 7); if (intPnt.IsCircle) { dia = double.Parse(diameter) / zoom; diaWidth = dia; diaHeight = dia; x = intPnt.DistanceDraw - (dia / 2) / radioTemp + canXOrigin; //获得管线截面外接矩形左上角的坐标x y = (totalYSpan - intPnt.ZDraw) * 1000 / radioTemp + canYOrigin; //获得管线截面外接矩形左上角的坐标y pen.Width = 1; pen.Color = intPnt.Color; pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; g.DrawEllipse(pen, (float)x, (float)y, (float)(diaWidth / radioTemp), (float)(diaHeight / radioTemp)); pen.Color = Color.Black; pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; xline = intPnt.DistanceDraw + canXOrigin; yline = y + dia / radioTemp; g.DrawLine(pen, (int)xline, (int)yline, (int)xline, (int)(tableYOrigin + rowHeight * 4)); g.DrawString(intPnt.FcName, font, drawBrush, (float)(xline - constfc), (float)(tableYOrigin - constStrY)); rotate.DrawString(Math.Round(intPnt.H, 3).ToString(), font, drawBrush, new PointF((float)(xline - constStrX), (float)(tableYOrigin + rowHeight * 0 + constStrY)), format, -90f); rotate.DrawString(Math.Round(intPnt.ZPipeTop - (dia * zoom) / 1000, 3).ToString(), font, drawBrush, new PointF((float)(xline - constStrX), (float)(tableYOrigin + rowHeight * 1 + constStrY)), format, -90f); rotate.DrawString("DN" + intPnt.Diameter, font, drawBrush, new PointF((float)(xline - constStrX), (float)(tableYOrigin + rowHeight * 2 + constStrY)), format, -90f); if (i == 0) { rotate.DrawString("", font, drawBrush, new PointF((float)(x - constStrX), (float)(tableYOrigin + rowHeight * 3 + constStrY + 10)), format, 0f); } else if (intPnt.Distance < 1.0) { rotate.DrawString(Math.Round(intPnt.Distance, 3).ToString(), font, drawBrush, new PointF((float)(x - constStrX), (float)(tableYOrigin + rowHeight * 3 + constStrY + 10)), format, 0f); } else { rotate.DrawString(Math.Round(intPnt.Distance, 3).ToString(), font, drawBrush, new PointF((float)(x - constStrX), (float)(tableYOrigin + rowHeight * 3 + constStrY)), format, 0f); } } else { string[] diameters = diameter.Split('*'); if (diameters != null && diameters.Length == 2) { diaWidth = double.Parse(diameters[0]) / zoom; diaHeight = double.Parse(diameters[1]) / zoom; x = intPnt.DistanceDraw - (diaWidth / 2) / radioTemp + canXOrigin; //获得管线截面外接矩形左上角的坐标x y = (totalYSpan - intPnt.ZDraw) * 1000 / radioTemp + canYOrigin; //获得管线截面外接矩形左上角的坐标y pen.Width = 1; pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; pen.Color = intPnt.Color; g.DrawRectangle(pen, (float)x, (float)y, (float)(diaWidth / radioTemp), (float)(diaHeight / radioTemp)); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.Color = Color.Black; xline = intPnt.DistanceDraw + canXOrigin; yline = y + diaHeight / radioTemp; g.DrawLine(pen, (int)xline, (int)yline, (int)xline, (int)(tableYOrigin + rowHeight * 4)); g.DrawString(intPnt.FcName, font, drawBrush, (float)(xline - constfc), (float)(tableYOrigin - constStrY)); rotate.DrawString(Math.Round(intPnt.H, 3).ToString(), font, drawBrush, new PointF((float)(xline - constStrX), (float)(tableYOrigin + rowHeight * 0 + constStrY)), format, -90f); rotate.DrawString(Math.Round(intPnt.ZPipeTop - (diaHeight * zoom) / 1000, 3).ToString(), font, drawBrush, new PointF((float)(xline - constStrX), (float)(tableYOrigin + rowHeight * 1 + constStrY)), format, -90f); rotate.DrawString(intPnt.Diameter, font, drawBrush, new PointF((float)(xline - constStrX), (float)(tableYOrigin + rowHeight * 2 + constStrY)), format, -90f); if (intPnt.Distance < 1.0) { rotate.DrawString(Math.Round(intPnt.Distance, 3).ToString(), font, drawBrush, new PointF((float)(x - constStrX), (float)(tableYOrigin + rowHeight * 3 + constStrY + 10)), format, 0f); } else { rotate.DrawString(Math.Round(intPnt.Distance, 3).ToString(), font, drawBrush, new PointF((float)(x - constStrX), (float)(tableYOrigin + rowHeight * 3 + constStrY)), format, 0f); } } } } g.DrawString(Math.Round(totalXSpan + 2 * constCanBlank * xRadio / 1000, 3).ToString(), font, drawBrush, (float)canvasTotalWidth / 2 - 20, (float)(tableYOrigin + rowHeight * 4 + 10)); } catch (System.Exception ex) { } }
public static bool FindIntersection(Point StartPoint, Point EndPoint, Point StartPointSec, Point EndPointSec, out IntersectPoint intersectPoint) { if (StartPoint.X != EndPoint.X && StartPoint.Y != EndPoint.Y) { intersectPoint = null; return(false); } if (StartPointSec.X != EndPointSec.X && StartPointSec.Y != EndPointSec.Y) { intersectPoint = null; return(false); } // parallel, also overlapping case if (StartPoint.X == EndPoint.X && StartPointSec.X == EndPointSec.X || StartPoint.Y == EndPoint.Y && StartPointSec.Y == EndPointSec.Y) { intersectPoint = null; return(false); } else { // orthogonal but maybe not intersected Point up, down, left, right; if (StartPoint.X == EndPoint.X) { up = StartPoint; down = EndPoint; left = StartPointSec; right = EndPointSec; } else { up = StartPointSec; down = EndPointSec; left = StartPoint; right = EndPoint; } if (up.Y < down.Y) { double swap = up.Y; up.Y = down.Y; down.Y = swap; } if (left.X > right.X) { double swap = left.X; left.X = right.X; right.X = swap; } //check if is intersected at all if (IsBetween(down.Y, up.Y, left.Y) && IsBetween(left.X, right.X, up.X)) { if (up.Y == left.Y || down.Y == left.Y || left.X == up.X || right.X == up.X) { intersectPoint = new IntersectPoint(new Point(up.X, left.Y), IntersectPointMode.InnerIntersect); } else { intersectPoint = new IntersectPoint(new Point(up.X, left.Y), IntersectPointMode.NormalIntersect); } return(true); } intersectPoint = null; return(false); } }
/// <summary> /// 构造函数,定义当前的捕获点 /// </summary> /// <param name="ip"></param> public SnapGeometry(IntersectPoint ip) { central = ip; }
/// <summary> /// 捕获圆形上的点 /// </summary> /// <param name="v"></param> /// <returns></returns> public override IntersectPoint IntersectPoint(Vector2D v) { double ax = 0, ay = 0; var cv = KernelProperty.MMToPix(Central); switch (ImageAlign) { case Align.CENTER: ax = cv.X - BitmapImage.Width / 2; ay = cv.Y - BitmapImage.Height / 2; break; case Align.CENTER_TOP: ax = cv.X - BitmapImage.Width / 2; ay = cv.Y; break; case Align.CENTER_BOTTOM: ax = cv.X - BitmapImage.Width / 2; ay = cv.Y - BitmapImage.Height; break; case Align.LEFT_TOP: ax = cv.X; ay = cv.Y; break; case Align.LEFT_CENTER: ax = cv.X; ay = cv.Y - BitmapImage.Height / 2; break; case Align.LEFT_BOTTOM: ax = cv.X; ay = cv.Y - BitmapImage.Height; break; case Align.RIGHT_TOP: ax = cv.X - BitmapImage.Width; ay = cv.Y; break; case Align.RIGHT_CENTER: ax = cv.X - BitmapImage.Width; ay = cv.Y - BitmapImage.Height / 2; break; case Align.RIGHT_BOTTOM: ax = cv.X - BitmapImage.Width; ay = cv.Y - BitmapImage.Height; break; } Point v1 = new Point(ax, ay); Point v2 = new Point(ax + BitmapImage.Width, ay + BitmapImage.Height); var lft = KernelProperty.PixToMM(v1); var rfb = KernelProperty.PixToMM(v2); if ((v.X > lft.X && v.X < rfb.X) && (v.Y > rfb.Y && v.Y < lft.Y)) { IntersectPoint ip = new IntersectPoint(); ip.IntersectPointStyle = 1; ip.Point = v; return(ip); } return(null); }