/*Переход на полилинию на перспективу * [RibbonCommandButton("Стрелки отклонения", "Стрелки")] * [Autodesk.AutoCAD.Runtime.CommandMethod("iCmd_DrawValueArrows", Autodesk.AutoCAD.Runtime.CommandFlags.UsePickSet)] * public static void DrawValueArrows() * { * Matrix3d ucs = CoordinateSystem.CoordinateTools.GetCurrentUcs(); * double tolerance = _dataProvider.Read("tolerance", 0.005d); * bool isToleranceOnly = _dataProvider.Read("isToleranceOnly", false); * * Polyline pline; * if (!ObjectCollector.TrySelectAllowedClassObject(out pline)) * return; * * * PromptPointOptions ppo = new PromptPointOptions("\nУкажите фактическое положение:"); * ppo.AllowArbitraryInput = false; * ppo.Keywords.Add("Tolerance", "ДОПуск", "ДОПуск", true, true); * ppo.Keywords.Add("IsToleranceOnlyTrue", "ТОЛькоВДопуске", "ТОЛько В Допуске", true, true); * ppo.Keywords.Add("IsToleranceOnlyFalse", "ФАКТически", "ФАКТические данные", true, true); * ppo.Keywords.Add("Exit", "ВЫХод", "ВЫХод", true, true); * * PromptPointResult ppr; * while ((ppr = Tools.GetAcadEditor().GetPoint(ppo)).Status == PromptStatus.OK || ppr.Status == PromptStatus.Keyword) * { * var insertPoint = pline.GetOrthoNormalPoint(ppr.Value, new Plane()); * if (insertPoint == null || !insertPoint.HasValue) * continue; * try * { * Vector3d axisVector = pline.GetFirstDerivative(insertPoint.Value); * ValueArrow mainBlock = new ValueArrow(axisVector, ucs); * mainBlock._isToleranceOnly = isToleranceOnly; * mainBlock._toleranceBottom = tolerance; * mainBlock._insertPointUcs = insertPoint.Value; * * PromptStatus res = PromptStatus.Cancel; * if ((res = mainBlock.JigDraw()) != PromptStatus.OK) * return; * * _dataProvider.Write("tolerance", mainBlock._toleranceBottom); * _dataProvider.Write("isToleranceOnly", mainBlock._isToleranceOnly); * } * catch (Exception ex) * { * Tools.GetAcadEditor().WriteMessage($"\n\aОшибка \n{ex.Message}"); * return; * } * } * * } */ #endregion /// <summary> /// Основной метод вывода данных. Рисует стрелки по полученным с экрана точкам /// </summary> /// <param name="axisVector">Вектор направления оси/грани (перпендикулярно стрелкам)</param> /// <param name="ucs">Текущая ПСК</param> /// <param name="onlyOnce">ИСТИНА если нужно выполнить только раз, иначе цикл</param> /// <returns></returns> public static PromptStatus DrawWallArrows(Vector3d axisVector, Matrix3d ucs, bool onlyOnce = false, bool mirrorText = false) { double toleranceBottom = /*0.005;*/ _dataProvider.Read("tolerance", 0.005d); bool isToleranceOnly = /*false;*/ _dataProvider.Read("isToleranceOnly", false); object mirrorTextValue = null; if (mirrorText) { mirrorTextValue = SetMirrorTextValue(1); } try { Point3d?insertPoint = Point3d.Origin; while ((insertPoint = GetInsertPoint(axisVector, ucs, ref toleranceBottom, ref isToleranceOnly)).HasValue) { PromptStatus res = PromptStatus.Cancel; ValueArrow mainBlock = new ValueArrow(axisVector, ucs); mainBlock._isToleranceOnly = isToleranceOnly; mainBlock._toleranceBottom = toleranceBottom; mainBlock._insertPointUcs = insertPoint.Value; if ((res = mainBlock.JigDraw()) != PromptStatus.OK) { return(res); } if (onlyOnce) { break; } _dataProvider.Write("tolerance", mainBlock._toleranceBottom); _dataProvider.Write("isToleranceOnly", mainBlock._isToleranceOnly); } return(PromptStatus.OK); } catch (Exception ex) { Tools.GetAcadEditor().WriteMessage(ex.Message); return(PromptStatus.Error); } finally { if (mirrorText) { SetMirrorTextValue(mirrorTextValue); } } }
public static void TestEditText() { string controlName = "Рандом редактор (Настройки)"; Views.EntitiesRandomEditorView view = null; MainMenu.MainPaletteSet pset = MainMenu.MainPaletteSet.CreatedInstance; if ((view = pset.FindVisual(controlName) as Views.EntitiesRandomEditorView) == null) { view = new Views.EntitiesRandomEditorView(); view.CommandAction = TestEditText; view.DataHost = _dataHost; pset.AddControl(controlName, view); pset.Show(); return; } pset.Show(); EntitiesRandomEditor mainBlock = new EntitiesRandomEditor(); List <DBObject> objects; if (!ObjectCollector.TrySelectObjects(out objects)) { return; } if (objects.Count == 0) { return; } Tools.StartTransaction(() => { foreach (DBObject obj in objects) { if (obj is Entity) { mainBlock._editEntity((Entity)obj); } } }); _dataHost.Write("minTolerance", mainBlock._minTolerance); _dataHost.Write("maxTolerance", mainBlock._maxTolerance); }
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 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 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); }