public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Center point: "); if (p1.Result != ResultMode.OK) { return; } Circle consCircle = new Circle(p1.Value, 0); doc.Jigged.Add(consCircle); var d1 = await ed.GetDistance("Radius: ", p1.Value, (p) => consCircle.Radius = p); doc.Jigged.Remove(consCircle); if (d1.Result != ResultMode.OK) { return; } Drawable newItem = new Circle(p1.Value, d1.Value); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Start point: "); if (p1.Result != ResultMode.OK) { return; } var p2 = await ed.GetPoint("End point: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } QuadraticBezier cons = new QuadraticBezier(p1.Value, Point2D.Average(p1.Value, p2.Value), p2.Value); doc.Jigged.Add(cons); var p3 = await ed.GetPoint("Control point: ", (p) => cons.P1 = p); doc.Jigged.Remove(cons); if (p3.Result != ResultMode.OK) { return; } Drawable newItem = new QuadraticBezier(p1.Value, p3.Value, p2.Value); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { CADView view = doc.ActiveView; if (view == null) { return; } Editor ed = doc.Editor; var p1 = await ed.GetPoint("Base point: "); if (p1.Result == ResultMode.Cancel) { return; } var p2 = await ed.GetPoint("Second point: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } view.Pan(p2.Value - p1.Value); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Center point: "); if (p1.Result != ResultMode.OK) { return; } var p2 = await ed.GetPoint("Semi major axis: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } Ellipse consEllipse = new Ellipse(p1.Value, (p2.Value - p1.Value).Length, 0, (p2.Value - p1.Value).Angle); doc.Jigged.Add(consEllipse); var d2 = await ed.GetDistance("Semi minor axis: ", p1.Value, (p) => consEllipse.SemiMinorAxis = p); if (d2.Result != ResultMode.OK) { doc.Jigged.Remove(consEllipse); return; } doc.Jigged.Remove(consEllipse); Drawable newItem = new Ellipse(p1.Value, (p2.Value - p1.Value).Length, d2.Value, (p2.Value - p1.Value).Angle); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); while (true) { var p1 = await ed.GetPoint("Location: "); if (p1.Result != ResultMode.OK) { return; } if (p1.Result == ResultMode.OK) { Drawable point = new Point(p1.Value); doc.Model.Add(point); } else { return; } } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Center point: "); if (p1.Result != ResultMode.OK) { return; } var p2 = await ed.GetPoint("Width: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } Rectangle consRec = new Rectangle(p1.Value, (p2.Value - p1.Value).Length * 2, 0, (p2.Value - p1.Value).Angle); doc.Jigged.Add(consRec); var d2 = await ed.GetDistance("Height: ", p1.Value, (p) => consRec.Height = p * 2); if (d2.Result != ResultMode.OK) { doc.Jigged.Remove(consRec); return; } doc.Jigged.Remove(consRec); Drawable newItem = new Rectangle(p1.Value, (p2.Value - p1.Value).Length * 2, d2.Value * 2, (p2.Value - p1.Value).Angle); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Start point: "); if (p1.Result != ResultMode.OK) { return; } var p2 = await ed.GetPoint("End point: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } var p3 = await ed.GetDistance("Text height: ", p1.Value); if (p3.Result != ResultMode.OK) { return; } Drawable newItem = new Dimension(p1.Value, p2.Value, p3.Value); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Center point: "); if (p1.Result != ResultMode.OK) { return; } var p2 = await ed.GetPoint("Semi major axis: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } float rot = (p2.Value - p1.Value).Angle; EllipticArc consArc = new EllipticArc( p1.Value, (p2.Value - p1.Value).Length, (p2.Value - p1.Value).Length / 10, 0, 2 * MathF.PI, rot); doc.Jigged.Add(consArc); var p3 = await ed.GetPoint("Semi minor axis: ", p1.Value, (p) => consArc.SemiMinorAxis = (p - p1.Value).Length); if (p3.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } var a1 = await ed.GetAngle("Start angle: ", p1.Value); if (a1.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } consArc.StartAngle = a1.Value - rot; var a2 = await ed.GetAngle("End angle: ", p1.Value, (p) => consArc.EndAngle = p - rot); if (a2.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } doc.Jigged.Remove(consArc); Drawable newItem = new EllipticArc( p1.Value, (p2.Value - p1.Value).Length, (p3.Value - p1.Value).Length, a1.Value - rot, a2.Value - rot, (p2.Value - p1.Value).Angle); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetControlPoints("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } var p1 = await ed.GetPoint("Base point: "); if (p1.Result != ResultMode.OK) { return; } Composite consItems = new Composite(); CPSelectionSet consSet = new CPSelectionSet(); var ext = new Extents2D(); foreach (var pair in s.Value) { Drawable item = pair.Key.Clone(); ext.Add(item.GetExtents()); consItems.Add(item); consSet.Add(item, pair.Value); } doc.Transients.Add(consItems); float size = System.Math.Max(ext.Width, ext.Height); float lastScale = 1; var p2 = await ed.GetDistance("Scale: ", p1.Value, (p) => { p /= size; foreach (Drawable item in consItems) { item.TransformControlPoints(consSet[item], Matrix2D.Scale(p1.Value, p / lastScale)); } lastScale = p; }); doc.Transients.Remove(consItems); if (p2.Result != ResultMode.OK) { return; } foreach (var pair in s.Value) { pair.Key.TransformControlPoints(pair.Value.ToArray(), Matrix2D.Scale(p1.Value, p2.Value)); } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetSelection("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } var p1 = await ed.GetPoint("Base point: "); if (p1.Result != ResultMode.OK) { return; } Composite consItems = new Composite(); foreach (Drawable item in s.Value) { consItems.Add(item.Clone()); } doc.Transients.Add(consItems); Point2D lastPt = p1.Value; bool flag = true; while (flag) { var p2 = await ed.GetPoint("Second point: ", p1.Value, (p) => { consItems.TransformBy(Matrix2D.Translation(p - lastPt)); lastPt = p; }); if (p2.Result != ResultMode.OK) { flag = false; } else { foreach (Drawable item in s.Value) { Drawable newItem = item.Clone(); newItem.TransformBy(Matrix2D.Translation(p2.Value - p1.Value)); doc.Model.Add(newItem); } } } doc.Transients.Remove(consItems); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var res = await ed.GetSaveFilename("Save file"); if (res.Result == ResultMode.OK) { doc.Save(res.Value); } }
public override async Task Apply(CADDocument doc, params string[] args) { CADView view = doc.ActiveView; if (view == null) { return; } Editor ed = doc.Editor; view.SetViewport(); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetSelection("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } var p = await ed.GetPoint("Base point: "); if (p.Result != ResultMode.OK) { return; } var t = await ed.GetText("Name: "); if (t.Result != ResultMode.OK || string.IsNullOrEmpty(t.Value)) { return; } Composite composite = new Composite(); composite.Name = t.Value; Matrix2D matrix = Matrix2D.Translation(-1 * p.Value.AsVector2D()); List <Drawable> toDelete = new List <Drawable>(); foreach (Drawable item in s.Value) { item.TransformBy(matrix); toDelete.Add(item); composite.Add(item); } doc.Composites.Add(composite.Name, composite); foreach (Drawable item in toDelete) { doc.Model.Remove(item); } CompositeReference compRef = new CompositeReference(); compRef.Composite = composite; compRef.Location = p.Value; doc.Model.Add(compRef); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetControlPoints("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } var p1 = await ed.GetPoint("Base point: "); if (p1.Result != ResultMode.OK) { return; } Composite consItems = new Composite(); CPSelectionSet consSet = new CPSelectionSet(); foreach (var pair in s.Value) { Drawable item = pair.Key.Clone(); consItems.Add(item); consSet.Add(item, pair.Value); } doc.Transients.Add(consItems); float lastAngle = 0; var p2 = await ed.GetAngle("Rotation angle: ", p1.Value, (p) => { foreach (Drawable item in consItems) { item.TransformControlPoints(consSet[item], Matrix2D.Rotation(p1.Value, p - lastAngle)); } lastAngle = p; }); doc.Transients.Remove(consItems); if (p2.Result != ResultMode.OK) { return; } foreach (var pair in s.Value) { pair.Key.TransformControlPoints(pair.Value.ToArray(), Matrix2D.Rotation(p1.Value, p2.Value)); } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("First point: "); if (p1.Result != ResultMode.OK) { return; } Point2D lastPt = p1.Value; int i = 0; while (true) { var opts = new PointOptions("Next point: ", lastPt); if (i > 1) { opts.AddKeyword("Close"); } var p3 = await ed.GetPoint(opts); if (p3.Result == ResultMode.OK) { Drawable nextLine = new Line(lastPt, p3.Value); doc.Model.Add(nextLine); lastPt = p3.Value; } else if (p3.Result == ResultMode.Keyword && p3.Keyword == "Close") { Drawable nextLine = new Line(lastPt, p1.Value); doc.Model.Add(nextLine); lastPt = p3.Value; return; } else { return; } i++; } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetSelection("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } var p1 = await ed.GetPoint("Base point: "); if (p1.Result != ResultMode.OK) { return; } Composite consItems = new Composite(); var ext = new Extents2D(); foreach (Drawable item in s.Value) { ext.Add(item.GetExtents()); consItems.Add(item.Clone()); } doc.Transients.Add(consItems); float size = System.Math.Max(ext.Width, ext.Height); float lastScale = 1; var d1 = await ed.GetDistance("Scale: ", p1.Value, (p) => { p /= size; consItems.TransformBy(Matrix2D.Scale(p1.Value, p / lastScale)); lastScale = p; }); doc.Transients.Remove(consItems); if (d1.Result != ResultMode.OK) { return; } foreach (Drawable item in s.Value) { item.TransformBy(Matrix2D.Scale(p1.Value, d1.Value)); } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetSelection("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } var p1 = await ed.GetPoint("Base point: "); if (p1.Result != ResultMode.OK) { return; } Composite consItems = new Composite(); foreach (Drawable item in s.Value) { consItems.Add(item.Clone()); } doc.Transients.Add(consItems); Matrix2D lastTrans = Matrix2D.Identity; var p2 = await ed.GetPoint("Second point: ", p1.Value, (p) => { Matrix2D mirror = Matrix2D.Mirror(p1.Value, p - p1.Value); consItems.TransformBy(lastTrans.Inverse); consItems.TransformBy(mirror); lastTrans = mirror; }); doc.Transients.Remove(consItems); if (p2.Result != ResultMode.OK) { return; } foreach (Drawable item in s.Value) { Drawable newItem = item.Clone(); newItem.TransformBy(Matrix2D.Mirror(p1.Value, p2.Value - p1.Value)); doc.Model.Add(newItem); } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetSelection("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } var p1 = await ed.GetPoint("Base point: "); if (p1.Result != ResultMode.OK) { return; } Composite consItems = new Composite(); foreach (Drawable item in s.Value) { consItems.Add(item.Clone()); } doc.Transients.Add(consItems); float lastAngle = 0; var p2 = await ed.GetAngle("Rotation angle: ", p1.Value, (p) => { consItems.TransformBy(Matrix2D.Rotation(p1.Value, p - lastAngle)); lastAngle = p; }); doc.Transients.Remove(consItems); if (p2.Result != ResultMode.OK) { return; } foreach (Drawable item in s.Value) { item.TransformBy(Matrix2D.Rotation(p1.Value, p2.Value)); } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Base point: "); if (p1.Result != ResultMode.OK) { return; } var a1 = await ed.GetAngle("Rotation: ", p1.Value); if (a1.Result != ResultMode.OK) { return; } var d1 = await ed.GetDistance("Text height: ", p1.Value); if (d1.Result != ResultMode.OK) { return; } Text consText = new Text(p1.Value, " ", d1.Value); consText.Rotation = a1.Value; doc.Jigged.Add(consText); var t1 = await ed.GetText("Text string: ", (p) => consText.String = p); doc.Jigged.Remove(consText); if (t1.Result != ResultMode.OK) { return; } Text newItem = new Text(p1.Value, t1.Value, d1.Value); newItem.Rotation = a1.Value; doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; var s = await ed.GetSelection("Select objects: "); if (s.Result != ResultMode.OK || s.Value.Count == 0) { return; } List <Drawable> toDelete = new List <Drawable>(); foreach (Drawable item in s.Value) { toDelete.Add(item); } foreach (Drawable item in toDelete) { doc.Model.Remove(item); } }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Start point: "); if (p1.Result != ResultMode.OK) { return; } var p2 = await ed.GetPoint("End point: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } var a1 = await ed.GetAngle("Start angle: ", p1.Value); if (a1.Result != ResultMode.OK) { return; } Parabola consPb = new Parabola(p1.Value, p2.Value, a1.Value, 0); doc.Jigged.Add(consPb); var a2 = await ed.GetAngle("End angle: ", p2.Value, (p) => consPb.EndAngle = p); doc.Jigged.Remove(consPb); if (a2.Result != ResultMode.OK) { return; } Drawable newItem = new Parabola(p1.Value, p2.Value, a1.Value, a2.Value); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("Center point: "); if (p1.Result != ResultMode.OK) { return; } Arc consArc = new Arc(p1.Value, 0, 0, 2 * MathF.PI); doc.Jigged.Add(consArc); var p2 = await ed.GetDistance("Radius: ", p1.Value, (p) => consArc.Radius = p); if (p2.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } var a1 = await ed.GetAngle("Start angle: ", p1.Value, (p) => consArc.StartAngle = p); if (a1.Result != ResultMode.OK) { doc.Jigged.Remove(consArc); return; } var a2 = await ed.GetAngle("End angle: ", p1.Value, (p) => consArc.EndAngle = p); doc.Jigged.Remove(consArc); if (a2.Result != ResultMode.OK) { return; } Drawable newItem = new Arc(p1.Value, p2.Value, a1.Value, a2.Value); doc.Model.Add(newItem); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); string filename = doc.FileName; if (string.IsNullOrEmpty(filename)) { var res = await ed.GetSaveFilename("Save file"); if (res.Result == ResultMode.OK) { filename = res.Value; } else { return; } } doc.Save(filename); }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("First point: "); if (p1.Result != ResultMode.OK) { return; } Point2D pt = p1.Value; Polyline consPoly = new Polyline(new Point2D[] { pt, pt }); consPoly.Closed = true; doc.Jigged.Add(consPoly); Point2DCollection points = new Point2DCollection(); points.Add(pt); bool done = false; while (!done) { PointOptions options = new PointOptions("Next point: ", pt, (p) => consPoly.Points[consPoly.Points.Count - 1] = p); options.AddKeyword("End", true); var pNext = await ed.GetPoint(options); if (pNext.Result == ResultMode.OK) { pt = pNext.Value; consPoly.Points.Add(pt); points.Add(pt); } else if (pNext.Result == ResultMode.Cancel) { doc.Jigged.Remove(consPoly); return; } else if (pNext.Result == ResultMode.Keyword) { if (points.Count < 2) { doc.Jigged.Remove(consPoly); return; } if (pNext.Keyword == "End") { done = true; } } } doc.Jigged.Remove(consPoly); Hatch newItem = new Hatch(points); doc.Model.Add(newItem); }
public override Task Apply(CADDocument doc, params string[] args) { doc.Editor.CurrentSelection.Clear(); return(Task.FromResult(default(object))); }
public override async Task Apply(CADDocument doc, params string[] args) { if (cp == null || item == null) { return; } Editor ed = doc.Editor; Drawable consItem = item.Clone(); doc.Transients.Add(consItem); ResultMode result = ResultMode.Cancel; Matrix2D trans = Matrix2D.Identity; if (cp.Type == ControlPointType.Point) { var res = await doc.Editor.GetPoint(cp.Name, cp.BasePoint, (p) => { consItem.TransformControlPoints(new int[] { cp.Index }, trans.Inverse); trans = Matrix2D.Translation(p - cp.BasePoint); consItem.TransformControlPoints(new int[] { cp.Index }, trans); }); trans = Matrix2D.Translation(res.Value - cp.BasePoint); result = res.Result; } else if (cp.Type == ControlPointType.Angle) { float orjVal = (cp.Location - cp.BasePoint).Angle; var res = await doc.Editor.GetAngle(cp.Name, cp.BasePoint, (p) => { consItem.TransformControlPoints(new int[] { cp.Index }, trans.Inverse); trans = Matrix2D.Rotation(cp.BasePoint, p - orjVal); consItem.TransformControlPoints(new int[] { cp.Index }, trans); }); trans = Matrix2D.Rotation(cp.BasePoint, res.Value - orjVal); result = res.Result; } else if (cp.Type == ControlPointType.Distance) { Vector2D dir = (cp.Location - cp.BasePoint).Normal; float orjVal = (cp.Location - cp.BasePoint).Length; var res = await doc.Editor.GetDistance(cp.Name, cp.BasePoint, (p) => { consItem.TransformControlPoints(new int[] { cp.Index }, trans.Inverse); trans = Matrix2D.Scale(cp.BasePoint, p / orjVal); consItem.TransformControlPoints(new int[] { cp.Index }, trans); }); trans = Matrix2D.Scale(cp.BasePoint, res.Value / orjVal); result = res.Result; } doc.Transients.Remove(consItem); // Transform the control point if (result == ResultMode.OK) { item.TransformControlPoints(new int[] { cp.Index }, trans); } }
public override async Task Apply(CADDocument doc, params string[] args) { CADView view = doc.ActiveView; if (view == null) { return; } Editor ed = doc.Editor; PointOptions opts = new PointOptions("Corner of zoom window: "); opts.AddKeyword("Extents"); opts.AddKeyword("Scale"); opts.AddKeyword("Object"); var p1 = await ed.GetPoint(opts); if (p1.Result == ResultMode.Cancel) { return; } if (p1.Result == ResultMode.Keyword && p1.Keyword == "Extents") { view.SetViewport(); } else if (p1.Result == ResultMode.Keyword && p1.Keyword == "Scale") { FloatOptions fopts = new FloatOptions("Scale factor: "); fopts.AllowNegative = false; fopts.AllowZero = false; fopts.AllowPositive = true; var f1 = await ed.GetFloat(fopts); if (f1.Result != ResultMode.OK) { return; } view.Zoom(1f / f1.Value); } else if (p1.Result == ResultMode.Keyword && p1.Keyword == "Object") { var s1 = await ed.GetSelection("Select objects: "); if (s1.Result != ResultMode.OK || s1.Value.Count == 0) { return; } Extents2D ex = new Extents2D(); foreach (Drawable item in s1.Value) { ex.Add(item.GetExtents()); } view.SetViewport(ex); } else { var p2 = await ed.GetCorner("Opposite corner of zoom window: ", p1.Value); if (p2.Result != ResultMode.OK) { return; } view.SetViewport(p1.Value, p2.Value); } }
public override Task Apply(CADDocument doc, params string[] args) { doc.New(); return(Task.FromResult(default(object))); }