private void DrawDim( DrawContext dc, CadVertex a, CadVertex b, CadVertex p, DrawPen pen) { CadSegment seg = CadUtil.PerpSeg(a, b, p); dc.Drawing.DrawLine(pen, a.vector, seg.P0.vector); dc.Drawing.DrawLine(pen, b.vector, seg.P1.vector); Vector3d cp = CadMath.CenterPoint(seg.P0.vector, seg.P1.vector); double arrowW = ARROW_W; double arrowL = ARROW_LEN; dc.Drawing.DrawArrow(pen, cp, seg.P0.vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW); dc.Drawing.DrawArrow(pen, cp, seg.P1.vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW); }
private void DrawDim(DrawContext dc, DrawPen linePen, DrawBrush textBrush) { dc.Drawing.DrawLine(linePen, PointList[0].vector, PointList[3].vector); dc.Drawing.DrawLine(linePen, PointList[1].vector, PointList[2].vector); Vector3d cp = CadMath.CenterPoint(PointList[3].vector, PointList[2].vector); double arrowW = ARROW_W; double arrowL = ARROW_LEN; double ww = (PointList[1] - PointList[0]).Norm() / 4.0; if (ww > arrowL) { dc.Drawing.DrawArrow(linePen, cp, PointList[3].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW); dc.Drawing.DrawArrow(linePen, cp, PointList[2].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW); } else { Vector3d v0 = cp - PointList[3].vector; Vector3d v1 = cp - PointList[2].vector; v0 = -(v0.Normalized() * (arrowL * 1.5)) / dc.WorldScale + PointList[3].vector; v1 = -(v1.Normalized() * (arrowL * 1.5)) / dc.WorldScale + PointList[2].vector; dc.Drawing.DrawArrow(linePen, v0, PointList[3].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW); dc.Drawing.DrawArrow(linePen, v1, PointList[2].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW); dc.Drawing.DrawLine(linePen, PointList[2].vector, PointList[3].vector); } CadVertex lineV = PointList[2] - PointList[3]; double len = lineV.Norm(); string lenStr = CadUtil.ValToString(len); CadVertex p = PointList[3] + (lineV / 2); p += (PointList[3] - PointList[0]).UnitVector() * (arrowW); CadVertex up = PointList[3] - PointList[0]; // 裏返しになる場合は、反転する // If it turns over, reverse it Vector3d normal = CadMath.Normal(lineV.vector, up.vector); double scala = CadMath.InnerProduct(normal, dc.ViewDir); if (scala > 0) { lineV = -lineV; } // --- lineV ---> // 3<------------ p ----------->2 // ^ | | // | | | // up 0 1 // dc.Drawing.DrawText(FontID, textBrush, p.vector, lineV.vector, up.vector, new DrawTextOption(DrawTextOption.H_CENTER), lenStr); }
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; } }