public static ObjectId[] CreateMeasurementPoint(Point3d point) => App.LockAndExecute(() => { int radius = 10; var curves = new Curve[] { NoDraw.Line(new Point3d(point.X - radius, point.Y, 0), new Point3d(point.X + radius, point.Y, 0)), NoDraw.Line(new Point3d(point.X, point.Y - radius, 0), new Point3d(point.X, point.Y + radius, 0)), NoDraw.Circle(point, radius) }; var layerId = GetExtraObjectsLayerId(); curves.Select(p => { p.LayerId = layerId; return(p); }).AddToCurrentSpace(); return(Array.ConvertAll(curves, p => p.ObjectId)); });
public static void MT2DT() // newly 20130815 { var ids = Interaction.GetSelection("\nSelect MText", "MTEXT"); var mts = ids.QOpenForRead <MText>().Select(mt => { var dt = NoDraw.Text(mt.Text, mt.TextHeight, mt.Location, mt.Rotation, false, mt.TextStyleName); dt.Layer = mt.Layer; return(dt); }).ToArray(); ids.QForEach(x => x.Erase()); mts.AddToCurrentSpace(); }
private static List <ObjectId> AlignText(string text, double height, Point3d start, Point3d end) { if (text.Length < 2) { return(new List <ObjectId>()); } var chars = text.Select(x => x.ToString()).ToList(); var angle = Math.Atan2(end.Y - start.Y, end.X - start.X); var div = 1.0 / (chars.Count - 1); var texts = Enumerable.Range(0, chars.Count).Select(i => NoDraw.Text(chars[i], height, LerpPoint(start, end, i * div), angle)).ToArray(); return(texts.AddToCurrentSpace().ToList()); }
public static void DT2MT() // newly 20130815 { var ids = Interaction.GetSelection("\nSelect Text", "TEXT"); var dts = ids.QOpenForRead <DBText>().Select(dt => { var mt = NoDraw.MText(dt.TextString, dt.Height, dt.Position, dt.Rotation, false); mt.Layer = dt.Layer; return(mt); }).ToArray(); ids.QForEach(x => x.Erase()); dts.AddToCurrentSpace(); }
public static ObjectId[] CreateOriginObject(Point3d point) { int length = 100; var curves = new Curve[] { NoDraw.Line(point, point + Vector3d.XAxis * length), NoDraw.Line(point, point + Vector3d.YAxis * length), NoDraw.Rectang(new Point3d(point.X - length / 10, point.Y - length / 10, 0), new Point3d(point.X + length / 10, point.Y + length / 10, 0)) }; var layerId = GetExtraObjectsLayerId(); App.LockAndExecute(() => curves.Select(p => { p.LayerId = layerId; return(p); }).AddToCurrentSpace()); return(Array.ConvertAll(curves, p => p.ObjectId)); }
public void GCommand(string name, int gCode, string paramsString = null, Point3d?point = null, double?x = null, double?y = null, double?z = null, double?angleC = null, double?angleA = null, Curve curve = null, int?feed = null, Point2d?center = null) { var command = new ProcessCommand { Name = name }; if (point == null) { point = new Point3d(x ?? ToolLocation.Point.X, y ?? ToolLocation.Point.Y, z ?? ToolLocation.Point.Z); } command.Text = GCommandText(gCode, paramsString, point.Value, curve, angleC, angleA, feed, center); if (ToolLocation.IsDefined) { if (curve == null && ToolLocation.Point.DistanceTo(point.Value) > 1) { curve = NoDraw.Line(ToolLocation.Point, point.Value); } double length = 0; if (curve != null && curve.IsNewObject) { if (Colors.ContainsKey(name)) { curve.Color = Colors[name]; } curve.LayerId = _layerId; _currentSpace.AppendEntity(curve); _transaction.AddNewlyCreatedDBObject(curve, true); length = curve.Length(); } command.ToolpathObjectId = curve?.ObjectId; if ((feed ?? _feed) != 0) { command.Duration = (curve != null ? length : ToolLocation.Point.DistanceTo(point.Value)) / (gCode == 0 ? 10000 : feed ?? _feed) * 60; } } _GCode = gCode; ToolLocation.Set(point.Value, angleC, angleA); _feed = feed ?? _feed; command.HasTool = _hasTool; command.ToolLocation = ToolLocation.Clone(); _commands.Add(command); }
public static ObjectId[] Stairs(Point3d p1, Point3d p2, Point3d p3, double step) { var line1 = NoDraw.Pline(p1, p2); var width = line1.GetDistToPoint(p3, true); var line21 = line1.GetOffsetCurves(width)[0] as Polyline; var line22 = line1.GetOffsetCurves(-width)[0] as Polyline; var line2 = line21.GetDistToPoint(p3) < line22.GetDistToPoint(p3) ? line21 : line22; var length = line1.Length; var lines = Algorithms.Range(step, length, step) .Select(pos => NoDraw.Pline(line1.GetPointAtDistX(pos), line2.GetPointAtDistX(pos))).ToList(); lines.Add(line1); lines.Add(line2); return(lines.ToArray().AddToCurrentSpace()); }
/// <summary> /// Запил /// </summary> public static void CreateGash(Curve curve, Point3d point, Side side, double depth, double diam, double thickness, Point3d?pointС = null) { var gashLength = Math.Sqrt(depth * (diam - depth)); var normal = curve.GetFirstDerivative(point).GetNormal(); var point2 = point + normal * gashLength * (point == curve.StartPoint ? -1 : 1); if (pointС.HasValue) { point2 += pointС.Value - point; } var offsetVector = normal.GetPerpendicularVector() * thickness * (side == Side.Left ? 1 : -1); var gash = NoDraw.Pline(point, point2, point2 + offsetVector, point + offsetVector); gash.LayerId = GetGashLayerId(); App.LockAndExecute(() => gash.AddToCurrentSpace()); }
private void PolygonizationButton_Click(object sender, EventArgs e) { double n; try { n = double.Parse(polygonizationLengthtextBox.Text); } catch (Exception) { Forms.MessageBox.Show("请输入数字"); return; } ObjectId[] ids = Interaction.GetSelection("\n选择多段线", "LWPOLYLINE"); var entsToAdd = new List <Polyline>(); ids.QForEach <Polyline>(poly => { var pts = poly.GetPolylineDivPoints(n); var poly1 = NoDraw.Pline(pts, 0); if (poly1.EndPoint == poly1.StartPoint) { poly1.RemoveVertexAt((int)poly1.EndParam); } poly1.Closed = true; //if (poly.Closed == false) //{ // return poly; //} //poly1.Layer = poly.Layer; //try //{ // poly1.ConstantWidth = poly.ConstantWidth; //} //catch //{ //} poly1.XData = poly.XData; poly.Erase(); entsToAdd.Add(poly1); }); entsToAdd.ToArray().AddToCurrentSpace(); Interaction.WriteLine("{0} handled.", entsToAdd.Count); (Parent.Parent.Parent as Forms.Form).Close(); }
public static void ShowLayerName() { double height = 10; string[] range = { "By entities", "By layers" }; int result = Gui.GetOption("Choose one way", range); if (result == -1) { return; } ObjectId[] ids; if (result == 0) { ids = Interaction.GetSelection("\nSelect entities"); ids .QWhere(entity => !entity.Layer.Contains("_Label")) .QSelect(entity => entity.Layer) .Distinct() .Select(layer => $"{layer}_Label") .ForEach(labelLayer => DbHelper.GetLayerId(labelLayer)); } else { var layers = DbHelper.GetAllLayerNames().Where(layer => !layer.Contains("_Label")).ToArray(); string layerName = Gui.GetChoice("Select a layer", layers); ids = QuickSelection .SelectAll(FilterList.Create().Layer(layerName)) .ToArray(); DbHelper.GetLayerId($"{layerName}_Label"); } var texts = new List <MText>(); ids.QForEach <Entity>(entity => { string layerName = entity.Layer; if (!layerName.Contains("_Label")) { var center = entity.GetCenter(); var text = NoDraw.MText(layerName, height, center, 0, true); text.Layer = $"{layerName}_Label"; texts.Add(text); } }); texts.ToArray().AddToCurrentSpace(); }
public static List <ObjectId> AddTextFill(Polyline boundary, string text, double interval, double rotation = 0) { var scale = EntityManager.GetGlobalScaleFactor(); interval *= scale; var extents = boundary.GeometricExtents; var tjExtents = new Dreambuild.Geometry.Extent2D(extents.MinPoint.X, extents.MinPoint.Y, extents.MaxPoint.X, extents.MaxPoint.Y); var pts = tjExtents.GetHexGrid(interval, 0.5).Select(p => new Point3d(p.X, p.Y, 0)).Where(p => boundary.IsPointIn(p) && boundary.GetDistToPoint(p) > interval / 2).ToList(); if (pts.Count == 0) { pts.Add(boundary.GetCenter()); } var dts = pts.Take(1000).Select(p => { return(NoDraw.Text(text, 2.5 * scale, p, rotation)); }).ToArray(); return(dts.AddToCurrentSpace().ToList()); }
public static List <ObjectId> AddFill(Polyline boundary, string block, double interval) { var scale = EntityManager.GetGlobalScaleFactor(); interval *= scale; var extents = boundary.GeometricExtents; // IsExtentsIn(), GetBlockExtents() var tjExtents = new Dreambuild.Geometry.Extent2D(extents.MinPoint.X, extents.MinPoint.Y, extents.MaxPoint.X, extents.MaxPoint.Y); var pts = tjExtents.GetHexGrid(interval, 0.5).Select(p => new Point3d(p.X, p.Y, 0)).Where(p => boundary.IsPointIn(p) && boundary.GetDistToPoint(p) > interval / 2).ToList(); if (pts.Count == 0) { pts.Add(boundary.GetCenter()); } var bId = DbHelper.GetBlockId(block); var brs = pts.Take(1000).Select(p => { return(NoDraw.Insert(bId, p, 0, scale)); }).ToArray(); return(brs.AddToCurrentSpace().ToList()); }
public static void Test() { ObjectId[] objectId = Interaction.GetSelection("\n选择多段线", "LWPOLYLINE");//选择多段线 if (objectId.Length == 0) { return; //一个都没选的情况下退出操作 } objectId.QForEach <Polyline>(polyline => { int length = (int)polyline.EndParam; for (int i = 0; i <= length; i++) { Line l1 = NoDraw.Line(polyline.GetPointAtParam(i), polyline.GetPreviousPointAtParam(i)); Line l2 = NoDraw.Line(polyline.GetPointAtParam(i), polyline.GetNextPointAtParam(i)); // Checks if lines intersect Plane plane; Line3d line1 = new Line3d(l1.StartPoint, l1.EndPoint); Line3d line2 = new Line3d(l2.StartPoint, l2.EndPoint); if (!line1.IsCoplanarWith(line2, out plane) || line1.IsParallelTo(line2)) { return; } // Calculates the bisector Point3d inters = line1.IntersectWith(line2)[0]; Vector3d vec1 = line1.Direction; Vector3d vec2 = line2.Direction; Vector3d bisectDir = ((vec1 + vec2) / 2.0).Negate(); var angle = bisectDir.GetAngleTo(Vector3d.XAxis); Xline xline = new Xline(); xline.UnitDir = bisectDir.GetNormal(); xline.BasePoint = inters; Draw.Text((i + 1).ToString(), 2, xline.GetPointAtDist(1)); Draw.Circle(polyline.GetPointAtParam(i), 0.5); } }); }
public static void ShowLayerName() { double height = 10; string[] range = { "By entities", "By layers" }; int result = Gui.GetOption("Choose one way", range); if (result == -1) { return; } ObjectId[] ids; if (result == 0) { ids = Interaction.GetSelection("\nSelect entities"); ids.QWhere(x => !x.Layer.Contains("_Label")).QSelect(x => x.Layer).Distinct().Select(x => string.Format("{0}_Label", x)).ToList().ForEach(x => DbHelper.GetLayerId(x)); } else { var layers = DbHelper.GetAllLayerNames().Where(x => !x.Contains("_Label")).ToArray(); string layer = Gui.GetChoice("Select a layer", layers); ids = QuickSelection.SelectAll().QWhere(x => x.Layer == layer).ToArray(); DbHelper.GetLayerId(string.Format("{0}_Label", layer)); } var texts = new List <MText>(); ids.QForEach <Entity>(ent => { string layerName = ent.Layer; if (!layerName.Contains("_Label")) { Point3d center = ent.GetCenter(); MText text = NoDraw.MText(layerName, height, center, 0, true); text.Layer = string.Format("{0}_Label", layerName); texts.Add(text); } }); texts.ToArray().AddToCurrentSpace(); }
public Polyline GetContour() { var points = ProcessingArea.SelectMany(p => p.GetCurve().GetStartEndPoints()); return(NoDraw.Rectang(new Point3d(points.Min(p => p.X), points.Min(p => p.Y), 0), new Point3d(points.Max(p => p.X), points.Max(p => p.Y), 0))); }
/// <summary> /// Рез между точками /// </summary> public void Cutting(Point3d startPoint, Point3d endPoint, int cuttingFeed, int transitionFeed) => Cutting(NoDraw.Line(startPoint, endPoint), cuttingFeed, transitionFeed);
/// <summary> /// Рез между точками /// </summary> public void Cutting(Point3d startPoint, Point3d endPoint, int cuttingFeed, int transitionFeed, double?angleA = null) => Cutting(NoDraw.Line(startPoint, endPoint), cuttingFeed, transitionFeed, angleA: angleA);
public void Cutting(Point3d startPoint, Vector3d delta, double[] zArray, int cuttingFeed, int smallFeed, Side engineSide = Side.None, double?angleC = null, double?angleA = null) { using (var line = NoDraw.Line(startPoint, startPoint + delta)) Cutting(line, zArray, cuttingFeed, smallFeed, engineSide, angleC, angleA); }