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 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); 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); }