private void _setEntitiesFromInnerGrid() { int rowCount = SimpleGride.CalculateCeilingCount(_boundRectg.GetLeftVerticalVector(), _step) + 1; int columnCount = SimpleGride.CalculateCeilingCount(_boundRectg.GetLowertHorizontalVector(), _step) + 1; if (rowCount * columnCount > Math.Pow(50, 2)) { return; } if (rowCount * columnCount == 0d) { return; } Entities.ForEach(ent => ent.Dispose()); Entities.Clear(); CoordinateLable lableFactory = new CoordinateLable(); Tools.StartTransaction(() => { for (int row = 0; row < rowCount; row++) { for (int col = 0; col < columnCount; col++) { //Entities.Add(new DBPoint(_innerGridUcs.CalculateGridPoint(row, col))); Point3d point = _innerGridUcs.CalculateGridPoint(row, col); BlockReference br = lableFactory.CreateItem(point, Matrix3d.Identity).GetObjectForRead <BlockReference>(); Entities.Add((Entity)br.Clone()); br.Erase(true); } } Tools.GetAcadDatabase().TransactionManager.QueueForGraphicsFlush(); }); }
public CartogrammLabels(SimpleGride gride) { _gride = gride; TopRow = new List <TableField>(); BottomRow = new List <TableField>(); PreTopRow = new List <TableField>(); AmountTopRow = new List <TableField>(); PreBottomRow = new List <TableField>(); AmountBottomRow = new List <TableField>(); ObjectContextManager ocm = HostApplicationServices.WorkingDatabase.ObjectContextManager; ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES"); _scale = (AnnotationScale)occ.CurrentContext; _tableRowHeight /= _scale.Scale; _firstColumnWidth /= _scale.Scale; _preOrPostColumnWidth /= _scale.Scale; _tableTextHeight /= _scale.Scale; _grideTextHeight /= _scale.Scale; _volumeTextHeight /= _scale.Scale; _horizontalVector = gride.HorizontalVector; _verticalVector = gride.VerticalVector; }
private void _createGrid(Point3d destPoint) { Entities.Clear(); Vector3d vector = destPoint - Origin; /*Point3d leftTop = Origin.Add(_ucs.CoordinateSystem3d.Yaxis.MultiplyBy(vector.Y)); * Point3d leftLow = Origin; * Point3d rightTop = destPoint; * Point3d rightLow = Origin.Add(_ucs.CoordinateSystem3d.Xaxis.MultiplyBy(vector.X));*/ Point3d leftTop = Origin.Add(Matrix3d.Identity.CoordinateSystem3d.Yaxis.MultiplyBy(vector.Y)); Point3d leftLow = Origin; Point3d rightTop = destPoint; Point3d rightLow = Origin.Add(Matrix3d.Identity.CoordinateSystem3d.Xaxis.MultiplyBy(vector.X)); _mainRec = new Rectangle3d(leftTop, rightTop, leftLow, rightLow); double hLength = Math.Abs((_mainRec.LowerRight - _mainRec.LowerLeft).X); double vLength = Math.Abs((_mainRec.UpperLeft - _mainRec.LowerLeft).Y); double hCount = hLength / _horizontalStep; double vCount = vLength / _verticalStep; int rowsCount = (int)Math.Ceiling(vCount); int columnsCount = (int)Math.Ceiling(hCount); Rectangle3d current = new Rectangle3d( upperLeft: _mainRec.LowerLeft.Add((_mainRec.UpperLeft - _mainRec.LowerLeft).Normalize().MultiplyBy(_verticalStep)), upperRight: _mainRec.LowerLeft.Add((_mainRec.LowerRight - _mainRec.LowerLeft).Normalize().MultiplyBy(_horizontalStep)) .Add((_mainRec.UpperLeft - _mainRec.LowerLeft).Normalize().MultiplyBy(_verticalStep)), lowerLeft: _mainRec.LowerLeft, lowerRight: _mainRec.LowerLeft.Add((_mainRec.LowerRight - _mainRec.LowerLeft).Normalize().MultiplyBy(_horizontalStep)) ); SimpleGride table = new SimpleGride(current); for (int r = 0; r < rowsCount; r++) { for (int c = 0; c < columnsCount; c++) { var rec = table.CalculateRectagle(r, c); rec.TransformBy(_ucs); this.Entities.Add(rec); } } }
public void Calculate(Point3d upperRightPointUcs) { double dx = InsertPointUcs.X % _step; double dy = InsertPointUcs.Y % _step; Matrix3d mat = Matrix3d.Identity; mat = mat.PreMultiplyBy(Matrix3d.Displacement(_ucs.CoordinateSystem3d.Xaxis.Negate().MultiplyBy(dx))) .PreMultiplyBy(Matrix3d.Displacement(_ucs.CoordinateSystem3d.Yaxis.Negate().MultiplyBy(dy))); _boundRectg = SimpleGride.CreateRectangle(InsertPointUcs.TransformBy(mat), upperRightPointUcs, InnerBlockTransform.CoordinateSystem3d); SimpleGride grid = new SimpleGride(InsertPointUcs.TransformBy(mat), _boundRectg.UpperLeft - _boundRectg.LowerLeft, _boundRectg.LowerRight - _boundRectg.LowerLeft, _step, _step); _innerGridUcs = grid; }
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 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); }