public override void MoveSelectedPointsFromStored(DrawContext dc, Vector3d delta) { CadVertex cp = StoreList[0]; if (cp.Selected) { mPointList[0] = cp + delta; mPointList[1] = StoreList[1] + delta; mPointList[2] = StoreList[2] + delta; mPointList[3] = StoreList[3] + delta; mPointList[4] = StoreList[4] + delta; return; } StackArray <CadVertex> vt = default; vt[0] = StoreList[1] - cp; vt[1] = StoreList[2] - cp; vt[2] = StoreList[3] - cp; vt[3] = StoreList[4] - cp; vt.Length = 4; if (vt[0].Norm() < 0.01) { return; } int ai = -1; for (int i = 0; i < 4; i++) { if (StoreList[i + 1].Selected) { ai = i; break; } } if (ai < 0) { return; } int bi = (ai + 1) % 4; int ci = (ai + 2) % 4; int di = (ai + 3) % 4; Vector3d normal = CadMath.CrossProduct(vt[ai].vector, vt[bi].vector); normal = normal.UnitVector(); vt[ai] += delta; CadVertex uva = vt[ai].UnitVector(); CadVertex uvb = vt[bi].UnitVector(); if (!uva.EqualsThreshold(uvb)) { normal = CadMath.CrossProduct(vt[ai].vector, vt[bi].vector); if (normal.IsZero()) { return; } normal = normal.UnitVector(); } CadQuaternion q = CadQuaternion.RotateQuaternion(normal, Math.PI / 2.0); CadQuaternion r = q.Conjugate(); CadQuaternion qp = CadQuaternion.FromPoint(vt[ai].vector); qp = r * qp; qp = qp * q; vt[bi] = (CadVertex)qp.ToPoint(); vt[ci] = -vt[ai]; vt[di] = -vt[bi]; CadVertex tmp; for (int i = 0; i < vt.Length; i++) { tmp = vt[i]; tmp.Selected = false; vt[i] = tmp; } tmp = vt[ai]; tmp.Selected = true; vt[ai] = tmp; mPointList[1] = vt[0] + cp; mPointList[2] = vt[1] + cp; mPointList[3] = vt[2] + cp; mPointList[4] = vt[3] + cp; }
private void CheckCircle(DrawContext dc, CadLayer layer, CadFigure fig) { if (fig.PointCount < 3) { return; } VertexList vl = fig.PointList; if (fig.StoreList != null) { vl = fig.StoreList; } Vector3d c = vl[0].vector; Vector3d a = vl[1].vector; Vector3d b = vl[2].vector; Vector3d normal = CadMath.Normal(a - c, b - c); Vector3d tw = Target.Pos; tw.Z = 0; tw = dc.DevPointToWorldPoint(tw); Vector3d crossP = CadMath.CrossPlane(tw, tw + dc.ViewDir, c, normal); if (crossP.IsInvalid()) { // 真横から見ている場合 // viewed edge-on //DOut.tpl("crossP is invalid"); return; } double r = (a - c).Norm(); double tr = (crossP - c).Norm(); Vector3d cirP = c + (crossP - c) * (r / tr); Vector3d dcirP = dc.WorldPointToDevPoint(cirP); Vector3d dcrossP = dc.WorldPointToDevPoint(crossP); dcirP.Z = 0; dcrossP.Z = 0; double dist = (dcirP - Target.Pos).Norm(); if (dist > Range) { //DOut.tpl($"dist:{dist} Range:{Range}"); return; } if (dist < MinDist) { FigureSegment fseg = new FigureSegment(fig, 0, 0, 0); MarkSeg.Layer = layer; MarkSeg.FigSeg = fseg; MarkSeg.CrossPoint = cirP; MarkSeg.CrossPointScrn = dc.WorldPointToDevPoint(cirP); MarkSeg.Distance = dist; MinDist = dist; } }
public override void StartCreate(DrawContext dc) { // NOP }
public void SetRangePixel(DrawContext dc, double pixel) { Range = pixel; }
public override void DrawSelected(DrawContext dc) { }
public override void Draw(DrawContext dc, DrawParams dp) { drawCircle(dc, dp.LinePen); }
public override void DrawSelected(DrawContext dc) { drawSelected_Circle(dc); }
public DrawParam2(DrawContext dc, DrawPen pen, Vector3d p) { DC = dc; Pen = pen; PrevV = p; }
public override void EndCreate(DrawContext dc) { }
public override void DrawSelected(DrawContext dc) { DrawSelectedLines(dc); }
public DrawParam(DrawContext dc, DrawPen pen) { DC = dc; Pen = pen; }
public override void Draw(DrawContext dc, DrawParams dp) { DrawPolyLines(dc, dp.LinePen); }
public override void Draw(DrawContext dc) { DrawPolyLines(dc, dc.GetPen(DrawTools.PEN_DEFAULT_FIGURE)); }
public override void MoveSelectedPointsFromStored(DrawContext dc, Vector3d delta) { base.MoveSelectedPointsFromStored(dc, delta); }
public override void AddPointInCreating(DrawContext dc, CadVertex p) { mPointList.Add(p); }
private void DrawSelectedLines(DrawContext dc) { int i; int num = PointList.Count; for (i = 0; i < num; i++) { CadVertex p = PointList[i]; if (!p.Selected) { continue; } dc.Drawing.DrawSelectedPoint(p.vector, dc.GetPen(DrawTools.PEN_SELECT_POINT)); if (p.IsHandle) { int idx = i + 1; if (idx >= num) { idx = 0; } CadVertex next = GetPointAt(idx); if (!next.IsHandle) { // Draw handle dc.Drawing.DrawLine(dc.GetPen(DrawTools.PEN_HANDLE_LINE), p.vector, next.vector); dc.Drawing.DrawSelectedPoint(next.vector, dc.GetPen(DrawTools.PEN_SELECT_POINT)); } idx = i - 1; if (idx >= 0) { CadVertex prev = GetPointAt(idx); if (!prev.IsHandle) { // Draw handle dc.Drawing.DrawLine(dc.GetPen(DrawTools.PEN_HANDLE_LINE), p.vector, prev.vector); dc.Drawing.DrawSelectedPoint(prev.vector, dc.GetPen(DrawTools.PEN_SELECT_POINT)); } } } else { int idx = i + 1; if (idx < PointCount) { CadVertex np = GetPointAt(idx); if (np.IsHandle) { dc.Drawing.DrawLine(dc.GetPen(DrawTools.PEN_MATCH_SEG), p.vector, np.vector); dc.Drawing.DrawSelectedPoint(np.vector, dc.GetPen(DrawTools.PEN_SELECT_POINT)); } } idx = i - 1; if (idx >= 0) { CadVertex np = GetPointAt(idx); if (np.IsHandle) { dc.Drawing.DrawLine(dc.GetPen(DrawTools.PEN_MATCH_SEG), p.vector, np.vector); dc.Drawing.DrawSelectedPoint(np.vector, dc.GetPen(DrawTools.PEN_SELECT_POINT)); } } } } }
public override void Draw(DrawContext dc) { drawCircle(dc, dc.GetPen(DrawTools.PEN_DEFAULT_FIGURE)); }
public override void DrawTemp(DrawContext dc, CadVertex tp, DrawPen pen) { }
public override void DrawSeg(DrawContext dc, DrawPen pen, int idxA, int idxB) { //drawCircle(dc, pen); }
public override void AddPointInCreating(DrawContext dc, CadVertex p) { }
//public void Check(DrawContext dc, CadVertex pt) //{ // CheckFigPoint(dc, pt, null, null, 0); //} public void Check(DrawContext dc, Vector3d pt) { CheckFigPoint(dc, pt, null, null, 0); }
private void CheckSeg(DrawContext dc, CadLayer layer, FigureSegment fseg) { CadFigure fig = fseg.Figure; int idxA = fseg.Index0; int idxB = fseg.Index1; Vector3d a = fseg.Point0.vector; Vector3d b = fseg.Point1.vector; if (fig.StoreList != null && fig.StoreList.Count > 1) { if (!CheckStorePoint) { return; } a = fseg.StoredPoint0.vector; b = fseg.StoredPoint1.vector; } Vector3d cwp = dc.DevPointToWorldPoint(Target.Pos); Vector3d xfaceNormal = dc.DevVectorToWorldVector(Target.DirX); Vector3d yfaceNormal = dc.DevVectorToWorldVector(Target.DirY); Vector3d cx = CadMath.CrossSegPlane(a, b, cwp, xfaceNormal); Vector3d cy = CadMath.CrossSegPlane(a, b, cwp, yfaceNormal); if (!cx.IsValid() && !cy.IsValid()) { return; } Vector3d p = VectorExt.InvalidVector3d; double mind = double.MaxValue; Vector3d dcenter = dc.WorldPointToDevPoint(CadMath.CenterPoint(a, b)); double centerDist = (dcenter - Target.Pos).Norm(); if (CheckPriority == Priority.NONE || centerDist < Range) { StackArray <Vector3d> vtbl = default; vtbl[0] = cx; vtbl[1] = cy; vtbl.Length = 2; for (int i = 0; i < vtbl.Length; i++) { Vector3d v = vtbl[i]; if (!v.IsValid()) { continue; } Vector3d devv = dc.WorldPointToDevPoint(v); double td = (devv - Target.Pos).Norm(); if (td < mind) { mind = td; p = v; } } } else { if (CheckPriority == Priority.PRIORITY_X) { p = cx; } else if (CheckPriority == Priority.PRIORITY_Y) { p = cy; } if (p.IsInvalid()) { return; } Vector3d devv = dc.WorldPointToDevPoint(p); mind = (devv - Target.Pos).Norm(); } if (!p.IsValid()) { return; } if (mind > Range) { return; } if (mind < MinDist) { MarkSeg.Layer = layer; MarkSeg.FigSeg = fseg; MarkSeg.CrossPoint = p; MarkSeg.CrossPointScrn = dc.WorldPointToDevPoint(p); MarkSeg.Distance = mind; MinDist = mind; } }
public NearPointSearcher(PlotterController controller) { Controller = controller; DC = Controller.DC; }
public override void DrawSeg(DrawContext dc, DrawPen pen, int idxA, int idxB) { }