/// <summary> /// /// </summary> /// <param name="canvas"></param> /// <param name="point"></param> /// <param name="snappoint"></param> /// <returns></returns> public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { List <IDrawObject> drawitems = canvas.DataModel.GetHitObjects(canvas, point); List <DrawTools.Line> lines = GetLines(drawitems); // add to source lines if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift) { foreach (DrawTools.Line line in lines) { AddLine(point, line); } SetSelectHint(); return(eDrawObjectMouseDown.Continue); } if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control) { foreach (DrawTools.Line line in lines) { if (m_originalLines.ContainsKey(line)) { RemoveLine(line); } else { AddLine(point, line); } } SetSelectHint(); return(eDrawObjectMouseDown.Continue); } if (drawitems.Count == 0) { return(eDrawObjectMouseDown.Continue); } // all lines have been added, now find edge to where to extend if (drawitems[0] is DrawTools.Line) { DrawTools.Line edge = (DrawTools.Line)drawitems[0]; bool modified = false; foreach (LinePoints originalLp in m_originalLines.Values) { UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2); // lines intersect so shrink line if (intersectpoint != UnitPoint.Empty) { LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = originalLp.MousePoint; m_modifiedLines.Add(lp.Line, lp); lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint); modified = true; continue; } // lines do not intersect, find apparent intersect point on existing edge line if (intersectpoint == UnitPoint.Empty) { UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint( edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2, false, true); if (apprarentISPoint == UnitPoint.Empty) { continue; } modified = true; originalLp.Line.ExtendLineToPoint(apprarentISPoint); LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = point; m_modifiedLines.Add(lp.Line, lp); } } if (modified) { canvas.DataModel.AfterEditObjects(this); } return(eDrawObjectMouseDown.Done); } if (drawitems[0] is DrawTools.Arc) { DrawTools.Arc edge = (DrawTools.Arc)drawitems[0]; foreach (LinePoints originalLp in m_originalLines.Values) { } bool modified = false; } return(eDrawObjectMouseDown.Done); }
public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { List <IDrawObject> items = canvas.DataModel.GetHitObjects(canvas, point); DrawTools.Line line = null; // find first line foreach (IDrawObject item in items) { if (item is DrawTools.Line) { line = item as DrawTools.Line; if (line != m_l1Original.Line) { break; } } } if (line == null) { if (m_l1Original.Line == null) { SetHint("No line selected. Select first line"); } else { SetHint("No line selected. Select second line"); } return(eDrawObjectMouseDown.Continue); } if (m_l1Original.Line == null) { line.Highlighted = true; m_l1Original.SetLine(line); m_l1Original.MousePoint = point; SetHint("Select second line"); return(eDrawObjectMouseDown.Continue); } if (m_l2Original.Line == null) { line.Highlighted = true; m_l2Original.SetLine(line); m_l2Original.MousePoint = point; UnitPoint intersectpoint = HitUtil.LinesIntersectPoint( m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2); // if lines do not intersect then extend lines to intersect point if (intersectpoint == UnitPoint.Empty) { UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2); if (apprarentISPoint == UnitPoint.Empty) { return(eDrawObjectMouseDown.Done); } m_l1Original.Line.ExtendLineToPoint(apprarentISPoint); m_l2Original.Line.ExtendLineToPoint(apprarentISPoint); m_l1NewPoint.SetLine(m_l1Original.Line); m_l2NewPoint.SetLine(m_l2Original.Line); canvas.DataModel.AfterEditObjects(this); return(eDrawObjectMouseDown.Done); } m_l1NewPoint.SetNewPoints(m_l1Original.Line, m_l1Original.MousePoint, intersectpoint); m_l2NewPoint.SetNewPoints(m_l2Original.Line, m_l2Original.MousePoint, intersectpoint); canvas.DataModel.AfterEditObjects(this); return(eDrawObjectMouseDown.Done); } return(eDrawObjectMouseDown.Done); }
public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { List<IDrawObject> drawitems = canvas.DataModel.GetHitObjects(canvas, point); List<DrawTools.Line> lines = GetLines(drawitems); // add to source lines if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift) { foreach (DrawTools.Line line in lines) AddLine(point, line); SetSelectHint(); return eDrawObjectMouseDown.Continue; } if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control) { foreach (DrawTools.Line line in lines) { if (m_originalLines.ContainsKey(line)) RemoveLine(line); else AddLine(point, line); } SetSelectHint(); return eDrawObjectMouseDown.Continue; } if (drawitems.Count == 0) return eDrawObjectMouseDown.Continue; // all lines have been added, now find edge to where to extend if (drawitems[0] is DrawTools.Line) { DrawTools.Line edge = (DrawTools.Line)drawitems[0]; bool modified = false; foreach (LinePoints originalLp in m_originalLines.Values) { UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2); // lines intersect so shrink line if (intersectpoint != UnitPoint.Empty) { LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = originalLp.MousePoint; m_modifiedLines.Add(lp.Line, lp); lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint); modified = true; continue; } // lines do not intersect, find apparent intersect point on existing edge line if (intersectpoint == UnitPoint.Empty) { UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint( edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2, false, true); if (apprarentISPoint == UnitPoint.Empty) continue; modified = true; originalLp.Line.ExtendLineToPoint(apprarentISPoint); LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = point; m_modifiedLines.Add(lp.Line, lp); } } if (modified) canvas.DataModel.AfterEditObjects(this); return eDrawObjectMouseDown.Done; } if (drawitems[0] is DrawTools.Arc) { DrawTools.Arc edge = (DrawTools.Arc)drawitems[0]; foreach (LinePoints originalLp in m_originalLines.Values) { } bool modified = false; } return eDrawObjectMouseDown.Done; }
public eDrawObjectMouseDownEnum OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { try { List <IDrawObject> items = canvas.DataModel.GetHitObjects(canvas, point); DrawTools.LineTool line = null; foreach (IDrawObject item in items) { if (item is DrawTools.LineTool) { line = item as DrawTools.LineTool; if (line.Type == DrawTools.LineType.PointLine) { return(eDrawObjectMouseDownEnum.Done); } if (line != m_l1Original.Line) { break; } } } if (line == null) { if (m_l1Original.Line == null) { SetHint("请选择第一个直线"); } else { SetHint("请选择第二个直线"); } return(eDrawObjectMouseDownEnum.Continue); } if (m_l1Original.Line == null) { line.Highlighted = true; m_l1Original.SetLine(line); m_l1Original.MousePoint = point; SetHint("请选择第二个直线"); return(eDrawObjectMouseDownEnum.Continue); } if (m_l2Original.Line == null) { line.Highlighted = true; m_l2Original.SetLine(line); m_l2Original.MousePoint = point; UnitPoint intersectpoint = HitUtil.LinesIntersectPoint( m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2); //如果两条实现没有相交,则将两条直线延长到交点 if (intersectpoint == UnitPoint.Empty) { UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2); if (apprarentISPoint == UnitPoint.Empty) { return(eDrawObjectMouseDownEnum.Done); } m_l1Original.Line.ExtendLineToPoint(apprarentISPoint); m_l2Original.Line.ExtendLineToPoint(apprarentISPoint); m_l1NewPoint.SetLine(m_l1Original.Line); m_l2NewPoint.SetLine(m_l2Original.Line); canvas.DataModel.AfterEditObjects(this); return(eDrawObjectMouseDownEnum.Done); } m_l1NewPoint.SetNewPoints(m_l1Original.Line, m_l1Original.MousePoint, intersectpoint); m_l2NewPoint.SetNewPoints(m_l2Original.Line, m_l2Original.MousePoint, intersectpoint); canvas.DataModel.AfterEditObjects(this); return(eDrawObjectMouseDownEnum.Done); } return(eDrawObjectMouseDownEnum.Done); } catch (Exception ex) { throw ex; } }
public eDrawObjectMouseDownEnum OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { try { List <IDrawObject> drawitems = canvas.DataModel.GetHitObjects(canvas, point); List <DrawTools.LineTool> lines = GetLines(drawitems); if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift) { foreach (DrawTools.LineTool line in lines) { AddLine(point, line); } SetSelectHint(); return(eDrawObjectMouseDownEnum.Continue); } if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control) { foreach (DrawTools.LineTool line in lines) { if (m_originalLines.ContainsKey(line)) { RemoveLine(line); } else { AddLine(point, line); } } SetSelectHint(); return(eDrawObjectMouseDownEnum.Continue); } if (drawitems.Count == 0) { return(eDrawObjectMouseDownEnum.Continue); } if (drawitems[0] is DrawTools.LineTool) { DrawTools.LineTool edge = (DrawTools.LineTool)drawitems[0]; if (edge.Type == DrawTools.LineType.PointLine) { return(eDrawObjectMouseDownEnum.Done); } bool modified = false; foreach (LinePoints originalLp in m_originalLines.Values) { UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2); if (intersectpoint != UnitPoint.Empty) { LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = originalLp.MousePoint; m_modifiedLines.Add(lp.Line, lp); lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint); modified = true; continue; } if (intersectpoint == UnitPoint.Empty) { UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint( edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2, false, true); if (apprarentISPoint == UnitPoint.Empty) { continue; } modified = true; originalLp.Line.ExtendLineToPoint(apprarentISPoint); LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = point; m_modifiedLines.Add(lp.Line, lp); } } if (modified) { canvas.DataModel.AfterEditObjects(this); } return(eDrawObjectMouseDownEnum.Done); } return(eDrawObjectMouseDownEnum.Done); } catch (Exception ex) { throw ex; } }