public void TEST_GetVolume() { TinVolumeSurface tinVolumeSurface; if (!ObjectCollector.TrySelectAllowedClassObject(out tinVolumeSurface, "\nВыберить поверхность для вычисления объема")) { return; } Polyline border; if (!ObjectCollector.TrySelectAllowedClassObject(out border, "\nВыбирите ограничивающею полилинию")) { return; } var volumeInfo = CivilSurfaces.SurfaceTools.GetVolumeInfo(tinVolumeSurface, border); if (!volumeInfo.HasValue) { Tools.GetAcadEditor().WriteMessage("\nОшибка определения объема"); return; } Tools.GetAcadEditor().WriteMessage(string.Format("\n\nПоверхность: {0}", tinVolumeSurface.Name)); Tools.GetAcadEditor().WriteMessage(string.Format("\nНасыпь составила: {0}\nВыемка составила: {1}\nЧистый объем: {2}", volumeInfo.Value.Fill.ToString("#0.00"), volumeInfo.Value.Cut.ToString("#0.00"), volumeInfo.Value.Net.ToString("#0.00"))); }
public static void TestDotProductVectors() { Line firstLine; Line secondLine; if (!ObjectCollector.TrySelectAllowedClassObject(out firstLine)) { return; } if (!ObjectCollector.TrySelectAllowedClassObject(out secondLine)) { return; } double ang = (firstLine.EndPoint - firstLine.StartPoint).GetAngle2d(secondLine.EndPoint - secondLine.StartPoint); double dot = (firstLine.EndPoint - firstLine.StartPoint).DotProduct(secondLine.EndPoint - secondLine.StartPoint); double cos = (firstLine.EndPoint - firstLine.StartPoint).GetCos2d(secondLine.EndPoint - secondLine.StartPoint); double project = cos * secondLine.Length; Tools.GetAcadEditor().WriteMessage("\nAngle = {0}", ang * 180d / Math.PI); Tools.GetAcadEditor().WriteMessage("\nDotProduct = {0}", dot); Tools.GetAcadEditor().WriteMessage("\nCos = {0}", cos); Tools.GetAcadEditor().WriteMessage("\nProject = {0}", project); }
public static void TestPerpendicularToPolyline() { Matrix3d ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; Curve pline; if (!ObjectCollector.TrySelectAllowedClassObject(out pline)) { return; } /*PromptPointOptions ppo = new PromptPointOptions("\nУкажите точку: "); * PromptPointResult ppr = Tools.GetAcadEditor().GetPoint(ppo); * if (ppr.Status != PromptStatus.OK) * return;*/ Tools.StartTransaction(() => { /*Point3d? perpendicularPoint = pline.GetNormalPoint(ppr.Value); * if (perpendicularPoint.HasValue) * { * Line perpendicular = new Line(ppr.Value, perpendicularPoint.Value); * perpendicular.SaveToDatebase(); * }*/ Drawing.PerpendicularVectorJigView view = new Drawing.PerpendicularVectorJigView(pline, ucs); view.StartJig(); }); }
public static void Test() { TinVolumeSurface volSurface; if (!ObjectCollector.TrySelectAllowedClassObject(out volSurface)) { return; } var b = volSurface.BoundariesDefinition[0]; }
public void TEST_ExtractSurfaceBorder() { CivilSurface surface; if (!ObjectCollector.TrySelectAllowedClassObject(out surface, "\nSelect a Surface: ")) { return; } CivilSurfaces.SurfaceTools.ExtractBorder((ITerrainSurface)surface); }
public void DynamicBlockTest() { BlockReference br; if (!ObjectCollector.TrySelectAllowedClassObject(out br)) { return; } Tools.StartTransaction(() => { br = br.Id.GetObjectForRead <BlockReference>(); var pSet = br.DynamicBlockReferencePropertyCollection; BlockTableRecord btr = br.BlockTableRecord.GetObjectForRead <BlockTableRecord>(); if (pSet == null) { return; } foreach (DynamicBlockReferenceProperty p in pSet) { if (p.PropertyTypeCode == (short)PropertyTypeCodes.Mirror) { Type t = p.Value.GetType(); p.Value = (short)((short)p.Value == 0 ? 1 : 0); } } BlockTableRecord btrDyn = br.DynamicBlockTableRecord.GetObjectForRead <BlockTableRecord>(); foreach (ObjectId id in btrDyn.GetBlockReferenceIds(false, false)) { var brDyn = id.GetObjectForRead <BlockReference>(); pSet = brDyn.DynamicBlockReferencePropertyCollection; if (pSet == null) { return; } foreach (DynamicBlockReferenceProperty p in pSet) { object obj = p; } } var rbuffer = btrDyn.XData; byte[] buffer = new byte[System.Runtime.InteropServices.Marshal.SizeOf(rbuffer.UnmanagedObject)]; IntPtr destPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(rbuffer.UnmanagedObject); System.Runtime.InteropServices.Marshal.Copy(rbuffer.UnmanagedObject, buffer, 0, System.Runtime.InteropServices.Marshal.SizeOf(rbuffer.UnmanagedObject)); }); }
public static Curve PromptCurve() { Curve curve; if (!ObjectCollector.TrySelectAllowedClassObject(out curve)) { return(null); } else { return(curve); } }
public static Vector3d?PromptVector() { Curve curve; if (!ObjectCollector.TrySelectAllowedClassObject(out curve)) { return(null); } else { return(curve.EndPoint - curve.StartPoint); } }
public static void TestPerpendicular() { Matrix3d ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; Curve line; if (!ObjectCollector.TrySelectAllowedClassObject(out line)) { return; } PromptPointOptions ppo = new PromptPointOptions("\nУкажите точку: "); PromptPointResult ppr = Tools.GetAcadEditor().GetPoint(ppo); if (ppr.Status != PromptStatus.OK) { return; } Tools.StartTransaction(() => { /*Vector3d vector = ppr.Value - line.StartPoint; * Vector3d lineVector = line.EndPoint - line.StartPoint; * * double cos = lineVector.GetCos2d(vector); * if (cos >=0d && cos*vector.Length <= lineVector.Length) * { * Point3d p = line.GetPointAtDist(cos * vector.Length); * Line perpendicular = new Line(ppr.Value, p); * perpendicular.SaveToDatebase(); * }*/ if (line is Line) { Line perpendicular = ((Line)line).GetOrthoNormalLine(ppr.Value, null, false); if (perpendicular != null) { perpendicular.SaveToDatebase(); } } else if (line is Arc) { Line perpendicular = ((Arc)line).GetOrthoNormalLine(ppr.Value, false); if (perpendicular != null) { perpendicular.SaveToDatebase(); } } }); }
public void TEST_CloningSurface() { TinSurface surface; if (!ObjectCollector.TrySelectAllowedClassObject(out surface)) { return; } TinSurface newSurface = surface.Clone() as TinSurface; newSurface.Name = "Clone_" + surface.Name; using (Transaction trans = Tools.StartTransaction()) { Tools.AppendEntityEx(trans, newSurface); } }
public void TEST_GetCroppingSurface() { TinSurface surface; if (!ObjectCollector.TrySelectAllowedClassObject(out surface)) { return; } Polyline border; if (!ObjectCollector.TrySelectAllowedClassObject(out border)) { return; } CivilSurfaces.SurfaceTools.CroppingSurface5(surface, border); }
public void SelectTextAtBounds() { DBText sourceObj; if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out sourceObj)) { return; } TypedValue[] tvs = new[] { new TypedValue((int)DxfCode.Start, "TEXT") }; Tools.StartTransaction(() => { Rectangle3d?bounds = sourceObj.GetTextBoxCorners(); if (!bounds.HasValue) { return; } Polyline pline = new Polyline(5); pline.AddVertexAt(0, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.1))); pline.AddVertexAt(1, bounds.Value.UpperLeft.Add((bounds.Value.UpperLeft - bounds.Value.LowerRight).MultiplyBy(0.1))); pline.AddVertexAt(2, bounds.Value.UpperRight.Add((bounds.Value.UpperRight - bounds.Value.LowerLeft).MultiplyBy(0.1))); pline.AddVertexAt(3, bounds.Value.LowerRight.Add((bounds.Value.LowerRight - bounds.Value.UpperLeft).MultiplyBy(0.1))); pline.AddVertexAt(4, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.1))); var spres = Tools.GetAcadEditor().SelectWindowPolygon(pline.GetPoints(), new SelectionFilter(tvs)); pline.SaveToDatebase(); if (spres.Status == PromptStatus.OK) { DBText text = spres.Value.GetSelectedItems <DBText>().FirstOrDefault(); if (text != null) { text.UpgradeOpen(); text.ColorIndex = 181; text.DowngradeOpen(); } } }); }
public static void CopyMLeaderTextContext() { MLeader sourceLeader; MLeader destLeader; if (!ObjectCollector.TrySelectAllowedClassObject(out sourceLeader, "\nВыберите мультивыноску - источник")) { return; } if (!ObjectCollector.TrySelectAllowedClassObject(out destLeader, "\nВыберите мультивыноску - назначение")) { return; } //destLeader = trans.GetObject(destLeader.Id, OpenMode.ForWrite) as MLeader; string res = MLeaders.MLeaderTools.CopyTextContents(sourceLeader, destLeader); //trans.Commit(); Tools.GetAcadEditor().WriteMessage("\n" + res); }
public void SelectPointAtPolygon() { Polyline pline; if (!ObjectCollector.TrySelectAllowedClassObject(out pline)) { return; } Vector3d vector = pline.Bounds.Value.MaxPoint - pline.Bounds.Value.MinPoint; Point3d centralPoint = pline.Bounds.Value.MinPoint.Add(vector.DivideBy(2d)); var randomPoints = centralPoint.CreateRandomCirclePoints(10000, vector.Length); List <ObjectId> pointIds = new List <ObjectId>(); Tools.StartTransaction(() => { pointIds = Tools.AppendEntity( randomPoints.Select(x => { return(new DBPoint(x)); })); }); Tools.StartTransaction(() => { foreach (var id in pointIds) { DBPoint p = id.GetObjectForRead <DBPoint>(); if (pline.IsInsidePolygon(p.Position)) { p.UpgradeOpen(); p.Highlight(); } } }); }
public void _drawGridCartogramma() { double step = 20d; //Polyline3d border = null; /*ObjectId surfaceId = CivilSurfaces.SurfaceTools.PromptForTinSurface("\nУкажитье поверхность: "); * if (surfaceId.IsNull) * return; * Tools.StartTransaction(() => * { * TinSurface surface = surfaceId.GetObjectForRead<CivilSurface>() as TinSurface; * if (surface == null) * return; * var borders = surface.ExtractBorders().Select(l => (Polyline3d)l.Clone()); * //borders.SaveToDatebase(); * border = borders.First(); * });*/ Polyline border; if (!ObjectCollector.TrySelectAllowedClassObject(out border)) { return; } if (border == null) { return; } border = border.Id.Open(OpenMode.ForRead).Clone() as Polyline; Matrix3d ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; border.TransformBy(ucs); Extents3d bounds = border.Bounds.Value; Vector3d hVector = Matrix3d.Identity.CoordinateSystem3d.Xaxis.MultiplyBy((bounds.MaxPoint - bounds.MinPoint).X); Vector3d vVector = Matrix3d.Identity.CoordinateSystem3d.Yaxis.MultiplyBy((bounds.MaxPoint - bounds.MinPoint).Y); Polyline polygon = border; /*border.ConvertToPolyline();*/ //((Entity)polygon.Clone()).SaveToDatebase(); ObjectId btrId = ObjectId.Null; ObjectId brId = ObjectId.Null; List <Entity> rectgs = null; CartogrammLabels labelsFactory = null; Action <Point3d> transformProcessor = startPoint => { gride = new SimpleGride(/*bounds.MinPoint*/ startPoint, vVector, hVector, step, step); labelsFactory = new CartogrammLabels(gride); int rowsCount = SimpleGride.CalculateCeilingCount(vVector, step); int columnCount = SimpleGride.CalculateCeilingCount(hVector, step); rectgs = new List <Entity>(rowsCount * columnCount); for (int r = 0; r < rowsCount; r++) { for (int c = 0; c < columnCount; c++) { Polyline line = gride.CalculateRectagle(r, c, polygon, true); if (line != null) { line.TransformBy(ucs.Inverse()); rectgs.Add(line); } /*if (r == 0) * { * var labels = labelsFactory.CreateTableColumn(c); * if (labels != null) * rectgs.AddRange(labels.Select(x => (Polyline)x.GetTransformedCopy(ucs.Inverse()))); * }*/ } } labelsFactory.CreateTeble(columnCount); for (int i = 0; i < columnCount; i++) { labelsFactory.SetValueToField(i, (IgorKL.ACAD3.Model.Helpers.Math.Randoms.RandomGen.NextDouble() - 0.5) * 10000d, labelsFactory.TopRow); } if (!btrId.IsNull) { Tools.StartTransaction(() => { BlockTableRecord btr = btrId.GetObjectForWrite <BlockTableRecord>(); foreach (var id in btr) { Entity ent = id.GetObjectForWrite <DBObject>() as Entity; if (ent != null) { ent.Erase(true); } } BlockReference br = brId.GetObjectForWrite <BlockReference>(); br.Erase(true); btr.Erase(true); btrId = AcadBlocks.BlockTools.CreateBlockTableRecord("*U", startPoint.TransformBy(ucs.Inverse()), rectgs.Cast <Entity>(), AnnotativeStates.NotApplicable, false); brId = AcadBlocks.BlockTools.AppendBlockItem(startPoint.TransformBy(ucs.Inverse()), btrId, null); } ); } }; transformProcessor(bounds.MinPoint); var points = labelsFactory._getGridElevationPoints(rectgs.Cast <Polyline>()).Select(x => new DBPoint(x)); points.SaveToDatebase(); rectgs.AddRange(labelsFactory.Entities.Select(x => x.GetTransformedCopy(ucs.Inverse()))); btrId = AcadBlocks.BlockTools.CreateBlockTableRecord("*U", bounds.MinPoint.TransformBy(ucs.Inverse()), rectgs.Cast <Entity>(), AnnotativeStates.NotApplicable, false); brId = AcadBlocks.BlockTools.AppendBlockItem(bounds.MinPoint.TransformBy(ucs.Inverse()), btrId, null); /*Tools.StartTransaction(() => * { * BlockReference br = brId.GetObjectForWrite<BlockReference>(); * CartogrammGride jigGrid = new CartogrammGride(bounds.MinPoint.TransformBy(ucs), br, transformProcessor); * jigGrid.StartJig(); * });*/ //rectgs.Cast<Entity>().SaveToDatebase(); }
public void _drawGridCartogramma2() { _step = _dataHost.Read("step", 20d); //Создаем представление (форму) CivilSurfaces.Views.SurfaceSelectorUserControl control = new CivilSurfaces.Views.SurfaceSelectorUserControl(); var surfInfos = CivilSurfaces.SurfaceTools.GetAllVolumeSurfaces(); control.comboBox_surfaces.Tag = surfInfos; foreach (var si in surfInfos) { int item = control.comboBox_surfaces.Items.Add(si); } if (surfInfos.Count > 0) { control.comboBox_surfaces.SelectedIndex = 0; } else { Tools.GetAcadEditor().WriteMessage($"\nВ проекте нет ни одной подходящей поверхности."); return; } /*Autodesk.AutoCAD.Windows.PaletteSet acWindow = new Autodesk.AutoCAD.Windows.PaletteSet($"{nameof(_drawGridCartogramma2)}"); * var palette = acWindow.AddVisual("Картограмма", control, true); * acWindow.Visible = true;*/ var mwin = Autodesk.AutoCAD.ApplicationServices.Application.MainWindow; System.Windows.Window acadWin = new CustomWindows.KeywordWindow(mwin, CustomWindows.AcadWindow.Dock.BottomRight); acadWin.Content = control; acadWin.Visibility = System.Windows.Visibility.Visible; KeywordCollection keywords = new KeywordCollection(); keywords.Add("Step", "Шаг", "Шаг сетки", true, true); //keywords.Add("View", "Список", "Список поверхностей", true, true); Func <PromptEntityResult, PromptStatus> promptStep = per => { switch (per.StringResult) { case "Step": { PromptDoubleOptions pdo = new PromptDoubleOptions("\nУкажите шаг сетки картограммы: "); pdo.UseDefaultValue = true; pdo.DefaultValue = _step; pdo.AllowZero = false; pdo.AllowNegative = false; pdo.AllowNone = false; var pdr = Tools.GetAcadEditor().GetDouble(pdo); if (pdr.Status == PromptStatus.OK) { _step = pdr.Value; _dataHost.Write("step", _step); } return(pdr.Status); } } return(PromptStatus.Error); }; ObjectId surfaceId = ObjectId.Null; Autodesk.Civil.DatabaseServices.TinVolumeSurface surface; if (!ObjectCollector.TrySelectAllowedClassObject(out surface, keywords, promptStep)) { surfaceId = ((KeyValuePair <string, ObjectId>)control.comboBox_surfaces.SelectedItem).Value; } else { surfaceId = surface.Id; } Polyline polygon = null; Tools.StartTransaction(() => { surface = surfaceId.GetObjectForRead <CivilSurface>() as Autodesk.Civil.DatabaseServices.TinVolumeSurface; if (surface == null) { return; } polygon = surface.ExtractBorders().ConvertToPolyline(); }); Matrix3d ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; polygon.TransformBy(ucs); Extents3d bounds = polygon.Bounds.Value; Vector3d hVector = Matrix3d.Identity.CoordinateSystem3d.Xaxis.MultiplyBy((bounds.MaxPoint - bounds.MinPoint).X); Vector3d vVector = Matrix3d.Identity.CoordinateSystem3d.Yaxis.MultiplyBy((bounds.MaxPoint - bounds.MinPoint).Y); ObjectId btrId = ObjectId.Null; ObjectId brId = ObjectId.Null; List <Entity> rectgs = null; CartogrammLabels labelsFactory = null; gride = new SimpleGride(bounds.MinPoint, vVector, hVector, _step, _step); labelsFactory = new CartogrammLabels(gride); int rowsCount = SimpleGride.CalculateCeilingCount(vVector, _step); int columnCount = SimpleGride.CalculateCeilingCount(hVector, _step); rectgs = new List <Entity>(rowsCount * columnCount); for (int r = 0; r < rowsCount; r++) { for (int c = 0; c < columnCount; c++) { Polyline line = gride.CalculateRectagle(r, c, polygon, true); if (line != null) { line.TransformBy(ucs.Inverse()); rectgs.Add(line); } } } labelsFactory.CreateTeble(columnCount); Tools.StartTransaction(() => { rectgs.AddRange(labelsFactory.CreateGridLabels(rectgs.Cast <Polyline>(), surface)); }); rectgs.AddRange(labelsFactory.Entities.Select(x => x.GetTransformedCopy(ucs.Inverse()))); btrId = AcadBlocks.BlockTools.CreateBlockTableRecord("*U", bounds.MinPoint.TransformBy(ucs.Inverse()), rectgs.Cast <Entity>(), AnnotativeStates.NotApplicable, false); brId = AcadBlocks.BlockTools.AppendBlockItem(bounds.MinPoint.TransformBy(ucs.Inverse()), btrId, null); acadWin.Visibility = System.Windows.Visibility.Hidden; acadWin.Close(); //acWindow.Close(); }
public static void SelectTextAtGrid() { Matrix3d ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; List <DBText> res = new List <DBText>(); DBText sourceObj; if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out sourceObj, "\nВыберите первый текстовый элемент: ")) { return; } DBText destObj; if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out destObj, "\nВыберите второй текстовый элемент: ")) { return; } List <DBText> selectedTexts; if (!ObjectCollector.TrySelectObjects(out selectedTexts, "\nВыберите исходный массив: ")) { return; } double textHeight = 0; Tools.StartTransaction(() => { textHeight = sourceObj.Id.GetObjectForRead <DBText>(false).Height; }); Vector3d vector = destObj.Position - sourceObj.Position; double angle = vector.GetAngleTo(ucs.CoordinateSystem3d.Xaxis, ucs.CoordinateSystem3d.Zaxis.Negate()); Matrix3d rot = Matrix3d.Rotation(-angle, ucs.CoordinateSystem3d.Zaxis, sourceObj.Position); Matrix3d displace = Matrix3d.Displacement(ucs.CoordinateSystem3d.Origin - sourceObj.Position); var transformedText = selectedTexts.Select(ent => new KeyValuePair <Point3d, ObjectId>(ent.Position.TransformBy(rot).TransformBy(displace), ent.Id)); Tools.StartTransaction(() => { List <ObjectId> selected = new List <ObjectId>(); foreach (var text in transformedText) { Vector3d v = text.Key - sourceObj.Position.TransformBy(displace); double tolerance = textHeight * 0.1 + (v.Length - vector.Length) * Tolerance.Global.EqualPoint * 100; double dx = Math.Abs(v.X % vector.Length); double dy = Math.Abs(v.Y) % vector.Length; if (dx < tolerance || Math.Abs(dx - vector.Length) < tolerance) { if (dy < tolerance || Math.Abs(dy - vector.Length) < tolerance) { //text.Value.GetObjectForWrite<DBText>(false).ColorIndex = 181; selected.Add(text.Value); } } } Tools.GetAcadEditor().SetImpliedSelection(selected.ToArray()); }); }
public void _drawGridCartogramma2() { _step = _dataHost.Read("step", 20d); KeywordCollection keywords = new KeywordCollection(); keywords.Add("Step", "Шаг", "Шаг сетки", true, true); keywords.Add("View", "Список", "Список поверхностей", true, true); Func <PromptEntityResult, PromptStatus> promptStep = per => { switch (per.StringResult) { case "Step": { PromptDoubleOptions pdo = new PromptDoubleOptions("\nУкажите шаг сетки картограммы: "); pdo.UseDefaultValue = true; pdo.DefaultValue = _step; pdo.AllowZero = false; pdo.AllowNegative = false; pdo.AllowNone = false; var pdr = Tools.GetAcadEditor().GetDouble(pdo); if (pdr.Status == PromptStatus.OK) { _step = pdr.Value; _dataHost.Write("step", _step); } return(pdr.Status); } } return(PromptStatus.Error); }; Autodesk.Civil.DatabaseServices.TinVolumeSurface surface; if (!ObjectCollector.TrySelectAllowedClassObject(out surface, keywords, promptStep)) { return; } Polyline polygon = null; Tools.StartTransaction(() => { surface = surface.Id.GetObjectForRead <CivilSurface>() as Autodesk.Civil.DatabaseServices.TinVolumeSurface; if (surface == null) { return; } polygon = surface.ExtractBorders().ConvertToPolyline(); }); Matrix3d ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; polygon.TransformBy(ucs); Extents3d bounds = polygon.Bounds.Value; Vector3d hVector = Matrix3d.Identity.CoordinateSystem3d.Xaxis.MultiplyBy((bounds.MaxPoint - bounds.MinPoint).X); Vector3d vVector = Matrix3d.Identity.CoordinateSystem3d.Yaxis.MultiplyBy((bounds.MaxPoint - bounds.MinPoint).Y); ObjectId btrId = ObjectId.Null; ObjectId brId = ObjectId.Null; List <Entity> rectgs = null; CartogrammLabels labelsFactory = null; gride = new SimpleGride(bounds.MinPoint, vVector, hVector, _step, _step); labelsFactory = new CartogrammLabels(gride); int rowsCount = SimpleGride.CalculateCeilingCount(vVector, _step); int columnCount = SimpleGride.CalculateCeilingCount(hVector, _step); rectgs = new List <Entity>(rowsCount * columnCount); for (int r = 0; r < rowsCount; r++) { for (int c = 0; c < columnCount; c++) { Polyline line = gride.CalculateRectagle(r, c, polygon, true); if (line != null) { line.TransformBy(ucs.Inverse()); rectgs.Add(line); } } } labelsFactory.CreateTeble(columnCount); Tools.StartTransaction(() => { rectgs.AddRange(labelsFactory.CreateGridLabels(rectgs.Cast <Polyline>(), surface)); }); rectgs.AddRange(labelsFactory.Entities.Select(x => x.GetTransformedCopy(ucs.Inverse()))); btrId = AcadBlocks.BlockTools.CreateBlockTableRecord("*U", bounds.MinPoint.TransformBy(ucs.Inverse()), rectgs.Cast <Entity>(), AnnotativeStates.NotApplicable, false); brId = AcadBlocks.BlockTools.AppendBlockItem(bounds.MinPoint.TransformBy(ucs.Inverse()), btrId, null); }
public void EditCogoPointLocation() {//SymbolUtilityServices. MethodOfRandomEdition method = MethodOfRandomEdition.ByCoordinate; List <CogoPoint> points; if (!ObjectCollector.TrySelectObjects(out points, "\nУкажите точки COGO для редактирования: ")) { return; } Polyline pline = null; double tolerance = _dataProvider.Read("tolerance", 0.01); PromptDoubleOptions dopt = new PromptDoubleOptions("Укажите максимальное значение (абс.) смещение, м: "); dopt.AllowNone = false; dopt.AllowNegative = false; dopt.DefaultValue = tolerance; PromptDoubleResult dres = Tools.GetAcadEditor().GetDouble(dopt); if (dres.Status != PromptStatus.OK) { return; } _dataProvider.Write("tolerance", dres.Value); tolerance = dres.Value; PromptKeywordOptions pkwopt = new PromptKeywordOptions("\nУкажите метод расчета: "); pkwopt.Keywords.Add("RADius", "ПОРадиусу", "ПОРадиусу"); pkwopt.Keywords.Add("SIMple", "Координаты", "Координаты"); pkwopt.Keywords.Add("FROmBaseDirection", "ОТЛинии", "ОТЛинии"); pkwopt.Keywords.Add("EXit", "ВЫХод", "ВЫХод"); pkwopt.AllowNone = false; PromptResult kwres = Tools.GetAcadEditor().GetKeywords(pkwopt); if (kwres.Status != PromptStatus.OK) { return; } switch (kwres.StringResult) { case "EXit": { return; } case "SIMple": { method = MethodOfRandomEdition.ByCoordinate; break; } case "FROmBaseDirection": { method = MethodOfRandomEdition.FromBaseDirection; if (!ObjectCollector.TrySelectAllowedClassObject(out pline, "\nУкажите базовую линию: ")) { return; } break; } case "RADius": { method = MethodOfRandomEdition.ByVector; break; } } foreach (var p in points) { Point3d location = p.Location; var rndLoc = _editPointLocationRandomByVector(location, tolerance, method, pline); if (rndLoc == null || !rndLoc.HasValue) { continue; } Tools.StartTransaction(() => { var editedPoint = p.Id.GetObject <CogoPoint>(OpenMode.ForWrite); editedPoint.TransformBy(Matrix3d.Displacement(rndLoc.Value - location)); }); } Tools.GetAcadEditor().Regen(); }
public static void TestRegressSplit() { Matrix3d ucs = Tools.GetAcadEditor().CurrentUserCoordinateSystem; double r2Min = 0.5d; KeywordCollection keys = new KeywordCollection(); keys.Add("R2", "R2", "R2", true, true); Func <PromptEntityResult, PromptStatus> promptAction = pr => { switch (pr.StringResult) { case "R2": { PromptDoubleOptions pdo = new PromptDoubleOptions("\nУкажите R^2: "); pdo.AllowNegative = false; pdo.UseDefaultValue = true; pdo.DefaultValue = r2Min; var res = Tools.GetAcadEditor().GetDouble(pdo); if (res.Status != PromptStatus.OK) { return(PromptStatus.Cancel); } r2Min = res.Value; return(PromptStatus.OK); } } return(PromptStatus.Error); }; Curve curve; if (!ObjectCollector.TrySelectAllowedClassObject(out curve, keys, promptAction)) { return; } Line line = null; Tools.StartTransaction(() => { Polyline pline = curve.ConvertToPolyline(); var points = pline.GetPoints3d(); Line regressTotal = stat.LinearRegression(pline); regressTotal.SaveToDatebase(); int start = 0; for (int i = 1; i < pline.NumberOfVertices; i++) { double r2; stat.LinearRegression(pline, start, i + 1, out r2); r2 = double.IsNaN(r2) ? 1d : r2; if (Math.Abs(r2 - r2Min) < Tolerance.Global.EqualVector) { line = new Line(pline.GetPoint3dAt(start), pline.GetPoint3dAt(i - 1)); start = i - 1; line.SaveToDatebase(); } } line = new Line(pline.GetPoint3dAt(start), pline.EndPoint); line.SaveToDatebase(); }); }
public void iCmd_GetPerpendicularToEntity() { Polyline line; if (!ObjectCollector.TrySelectAllowedClassObject(out line, "\nВыберите линию")) { return; } if (line != null) { PromptPointOptions opt = new PromptPointOptions("\nУкажите точку"); opt.Keywords.Add("EXit", "ВЫХод", "ВЫХод"); opt.Keywords.Add("SELectPoints", "ТОЧки", "ТОЧки"); opt.Keywords.Add("LINe", "ЛИНия", "ЛИНия"); PromptPointResult res = Tools.GetAcadEditor().GetPoint(opt); List <Point3d> points = new List <Point3d>(); while (res.Status == PromptStatus.OK || res.Status == PromptStatus.Keyword) { if (res.Status == PromptStatus.Keyword) { switch (res.StringResult) { case "EXit": { return; } case "SELectPoints": { List <DBPoint> pointSet; if (!ObjectCollector.TrySelectObjects(out pointSet, "\nВыберите точки")) { return; } points.Clear(); foreach (var p in pointSet) { Tools.StartTransaction(() => { points.Add(p.Id.GetObject <DBPoint>(OpenMode.ForRead).Position); }); } break; } case "LINe": { Polyline pline; if (!ObjectCollector.TrySelectAllowedClassObject(out pline, "\nВыберите точки")) { return; } points.Clear(); foreach (var p in pline.GetPoints3d()) { points.Add(p); } break; } } } //Line resLine = line.GetPerpendicularFromPoint(res.Value); if (res.Status == PromptStatus.OK) { points.Add(res.Value); } foreach (var p in points) { Line resLine = line.GetOrthoNormalLine(p, null, true); if (resLine != null) { Tools.AppendEntity(new[] { resLine }); } } points.Clear(); res = Tools.GetAcadEditor().GetPoint(opt); } } }
public void SelectAtDistanseAtVis() { List <DBText> res = new List <DBText>(); DBText sourceObj; if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out sourceObj)) { return; } DBText destObj; if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out destObj)) { return; } Rectangle3d?bounds = sourceObj.GetTextBoxCorners(); if (!bounds.HasValue) { return; } Rectangle3d?destBounds = destObj.GetTextBoxCorners(); if (!destBounds.HasValue) { return; } Vector3d vector = destBounds.Value.LowerLeft - bounds.Value.LowerLeft; Drawing.SimpleGride gride1 = new Drawing.SimpleGride(bounds.Value.LowerLeft, vector.GetPerpendicularVector().Negate(), vector, vector.Length, vector.Length); TypedValue[] tvs = new[] { new TypedValue((int)DxfCode.Start, "TEXT") }; //Tools.GetActiveAcadDocument().SendStringToExecute("._zoom _e ", true, false, false); Polyline rectg = new Polyline(5); rectg.AddVertexAt(0, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.2))); rectg.AddVertexAt(1, bounds.Value.UpperLeft.Add((bounds.Value.UpperLeft - bounds.Value.LowerRight).MultiplyBy(0.2))); rectg.AddVertexAt(2, bounds.Value.UpperRight.Add((bounds.Value.UpperRight - bounds.Value.LowerLeft).MultiplyBy(0.2))); rectg.AddVertexAt(3, bounds.Value.LowerRight.Add((bounds.Value.LowerRight - bounds.Value.UpperLeft).MultiplyBy(0.2))); rectg.AddVertexAt(4, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.2))); int count = 200; Point3d maxPointScreen = sourceObj.Position.Add(vector.MultiplyBy(count) + vector.GetPerpendicularVector().Negate().MultiplyBy(count * vector.Length)); Point3d minPointScreen = sourceObj.Position.Add(vector.Negate().MultiplyBy(count) + vector.GetPerpendicularVector().MultiplyBy(count * vector.Length)); Drawing.Helpers.Zoomer.Zoom(minPointScreen, maxPointScreen, new Point3d(), 1); Tools.StartTransaction(() => { for (int r = -count; r < count; r++) { for (int c = -count; c < count; c++) { var point1 = gride1.CalculateGridPoint(r, c); Matrix3d mat = Matrix3d.Displacement(point1 - bounds.Value.LowerLeft); var spres = Tools.GetAcadEditor().SelectWindowPolygon(((Polyline)rectg.GetTransformedCopy(mat)).GetPoints(), new SelectionFilter(tvs)); //((Polyline)rectg.GetTransformedCopy(mat)).SaveToDatebase(); if (spres.Status == PromptStatus.OK) { DBText text = spres.Value.GetSelectedItems <DBText>().FirstOrDefault(); if (text != null) { text.UpgradeOpen(); text.ColorIndex = 181; text.DowngradeOpen(); } } /*Entity[] marker = new[] { (Entity)new DBPoint(point1), (Entity)new Line(point1, point1.Add(bounds.Value.UpperRight - bounds.Value.LowerLeft)) }; * marker.SaveToDatebase<Entity>();*/ } } }); }