public override void Undo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); layer.InsertFigure(mFigureIndex, fig); }
public override void Redo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); layer.AddFigure(fig); }
public CadOpeRemoveFigure(CadLayer layer, uint figureID) : base(layer.ID, figureID) { int figIndex = layer.GetFigureIndex(figureID); mFigureIndex = figIndex; }
public override void Undo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); if (fig == null) { return; } int idx = PointIndex; int i = 0; if (mPointList == null) { mPointList = new VertexList(); } mPointList.Clear(); for (; i < InsertNum; i++) { mPointList.Add(fig.GetPointAt(idx + i)); } fig.RemovePointsRange(idx, InsertNum); }
public override void Redo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); CadFigure fig = db.GetFigure(FigureID); fig.InsertPointsRange(PointIndex, mPointList); }
private void CheckSegs(DrawContext dc, CadLayer layer, CadFigure fig) { for (int i = 0; i < fig.SegmentCount; i++) { FigureSegment seg = fig.GetFigSegmentAt(i); CheckSeg(dc, layer, seg); } }
public void Search(DrawContext dc, CadObjectDB db, CadLayer layer) { if (layer == null) { return; } for (int i = 0; i < layer.FigureList.Count; i++) { CadFigure fig = layer.FigureList[i]; CheckFigure(dc, layer, fig); } }
private void CheckFigPoint(DrawContext dc, Vector3d pt, CadLayer layer, CadFigure fig, int ptIdx) { Vector3d ppt = dc.WorldPointToDevPoint(pt); double dx = Math.Abs(ppt.X - Target.Pos.X); double dy = Math.Abs(ppt.Y - Target.Pos.Y); CrossInfo cix = CadMath.PerpCrossLine(Target.Pos, Target.Pos + Target.DirX, ppt); CrossInfo ciy = CadMath.PerpCrossLine(Target.Pos, Target.Pos + Target.DirY, ppt); double nx = (ppt - ciy.CrossPoint).Norm(); // Cursor Y軸からの距離 double ny = (ppt - cix.CrossPoint).Norm(); // Cursor X軸からの距離 if (nx <= Range) { if (nx < XMatch.DistanceX || (nx == XMatch.DistanceX && ny < XMatch.DistanceY)) { XMatch = GetMarkPoint(pt, ppt, nx, ny, layer, fig, ptIdx); } } if (ny <= Range) { if (ny < YMatch.DistanceY || (ny == YMatch.DistanceY && nx < YMatch.DistanceX)) { YMatch = GetMarkPoint(pt, ppt, nx, ny, layer, fig, ptIdx); } } if (dx <= Range && dy <= Range) { double minDist = (XYMatch.DistanceX * XYMatch.DistanceX) + (XYMatch.DistanceY * XYMatch.DistanceY); double curDist = (dx * dx) + (dy * dy); if (curDist <= minDist) { MarkPoint t = GetMarkPoint(pt, ppt, dx, dy, layer, fig, ptIdx); //t.dump(); XYMatch = t; if (!XYMatchSet.Contains(t)) { XYMatchList.Add(XYMatch); XYMatchSet.Add(XYMatch); //DOut.pl($"PointSearcher XYMatchList cnt:{XYMatchList.Count}"); } } } }
public void SearchAllLayer(DrawContext dc, CadObjectDB db) { Search(dc, db, db.CurrentLayer); for (int i = 0; i < db.LayerList.Count; i++) { CadLayer layer = db.LayerList[i]; if (layer.ID == db.CurrentLayerID) { continue; } Search(dc, db, layer); } }
private MarkPoint GetMarkPoint( Vector3d pt, Vector3d ppt, double distx, double disty, CadLayer layer, CadFigure fig, int ptIdx) { MarkPoint mp = default; mp.IsValid = true; mp.Layer = layer; mp.Figure = fig; mp.PointIndex = ptIdx; mp.Point = pt; mp.PointScrn = ppt; mp.DistanceX = distx; mp.DistanceY = disty; return(mp); }
public void Search(DrawContext dc, CadObjectDB db, CadLayer layer) { if (layer == null) { return; } if (!layer.Visible) { return; } MinDist = CadConst.MaxValue; for (int i = layer.FigureList.Count - 1; i >= 0; i--) { CadFigure fig = layer.FigureList[i]; CheckFig(dc, layer, fig); } }
private void CheckFig(DrawContext dc, CadLayer layer, CadFigure fig) { switch (fig.Type) { case CadFigure.Types.LINE: case CadFigure.Types.POLY_LINES: case CadFigure.Types.RECT: case CadFigure.Types.DIMENTION_LINE: case CadFigure.Types.MESH: CheckSegs(dc, layer, fig); break; case CadFigure.Types.CIRCLE: CheckCircle(dc, layer, fig); break; default: break; } }
public void CheckFigure(DrawContext dc, CadLayer layer, CadFigure fig) { if (IgnoreFigureIDSet.Contains(fig.ID)) { return; } VertexList list = fig.PointList; if (fig.StoreList != null) { if (CheckStorePoint) { list = fig.StoreList; } else { list = null; } } if (list != null) { int cnt = list.Count; for (int i = 0; i < cnt; i++) { CheckFigPoint(dc, list[i].vector, layer, fig, i); } } if (fig.ChildList != null) { for (int i = 0; i < fig.ChildList.Count; i++) { CadFigure c = fig.ChildList[i]; CheckFigure(dc, layer, c); } } }
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 CadOpeChangeFigureList(CadLayer layer, List <CadFigure> oldList, List <CadFigure> newList) { Layer = layer; OldList = oldList; NewList = newList; }
public override void Redo(CadObjectDB db) { CadLayer layer = db.GetLayer(LayerID); layer.RemoveFigureByID(db, FigureID); }
public CadOpeRemoveLayer(CadLayer layer, int index) { Layer = layer; Index = index; }
void CheckFig(CadLayer layer, CadFigure fig) { int n = fig.PointCount; for (int i = 0; i < n; i++) { CadVertex cp = fig.PointList[i]; CadVertex p = DC.WorldPointToDevPoint(cp); CadVertex d = p - TargetPoint; double dist = d.Norm2D(); if (dist > Range) { continue; } Result res = new ResultPoint(cp, dist, fig, i); ResultList.Add(res); } // // Create segment list that in range. // And check center point of segment // // 範囲内の線分リスト作成 // ついでに中点のチェックも行う // n = fig.SegmentCount; for (int i = 0; i < n; i++) { CadSegment seg = fig.GetSegmentAt(i); CadVertex pw = (seg.P1 - seg.P0) / 2 + seg.P0; CadVertex ps = DC.WorldPointToDevPoint(pw); double dist = (ps - TargetPoint).Norm2D(); if (dist <= Range) { Result res = new ResultSegCenter(pw, dist, fig, i); ResultList.Add(res); } CadVertex p0 = DC.WorldPointToDevPoint(seg.P0); CadVertex p1 = DC.WorldPointToDevPoint(seg.P1); double d = CadMath.DistancePointToSeg(p0.vector, p1.vector, TargetPoint.vector); if (d > Range) { continue; } SegmentItem segItem = new SegmentItem(); segItem.Layer = layer; segItem.Fig = fig; segItem.SegIndex = i; segItem.ScrSegment = new CadSegment(p0, p1); SegList.Add(segItem); } }
public static EditResult Bond(CadObjectDB db, CadFigure fig) { EditResult result = new EditResult(); if (fig.LayerID == 0) { return(result); } if (fig.IsLoop) { return(result); } CadLayer layer = db.GetLayer(fig.LayerID); CadVertex ps = fig.PointList[0]; CadVertex pe = fig.PointList[fig.PointCount - 1]; int pi = -1; int bpi = -1; CadFigure bfig = null; foreach (CadFigure tfig in layer.FigureList) { if (tfig.ID == fig.ID) { continue; } if (tfig.IsLoop) { continue; } CadVertex tps = tfig.PointList[0]; CadVertex tpe = tfig.PointList[tfig.PointCount - 1]; if (tps.Equals(ps)) { bpi = 0; pi = 0; bfig = tfig; break; } if (tps.Equals(pe)) { bpi = 0; pi = fig.PointCount - 1; bfig = tfig; break; } if (tpe.Equals(ps)) { bpi = tfig.PointCount - 1; pi = 0; bfig = tfig; break; } if (tpe.Equals(pe)) { bpi = tfig.PointCount - 1; pi = fig.PointCount - 1; bfig = tfig; break; } } if (pi < 0) { return(result); } CadFigure newFig = db.NewFigure(CadFigure.Types.POLY_LINES); VertexList plist = new VertexList(fig.PointList); VertexList blist = new VertexList(bfig.PointList); if (pi == 0) { plist.Reverse(); } if (bpi != 0) { blist.Reverse(); } newFig.PointList.AddRange(plist); newFig.PointList.AddRange(blist); result.AddList.Add(new EditResult.Item(layer.ID, newFig)); result.RemoveList.Add(new EditResult.Item(layer.ID, fig)); result.RemoveList.Add(new EditResult.Item(layer.ID, bfig)); return(result); }
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; } }