示例#1
0
        public void SetTextDataToBuffer()
        {
            const string  sep = "\t";
            List <DBText> data;

            if (!ObjectCollector.TrySelectObjects(out data, "\nВыберете текстовые объекты для импорта в буфер обмена: "))
            {
                return;
            }
            if (data.Count == 0)
            {
                return;
            }
            string res = "";

            using (Transaction trans = Tools.StartTransaction())
            {
                foreach (var text in data)
                {
                    res += text.TextString + sep;
                }
            }
            res = res.Remove(res.Length - sep.Length);
            System.Windows.Forms.Clipboard.SetText(res);
        }
示例#2
0
        public void EditPointElevationRandom()
        {
            var keywords = new { PositiveOnly = "PositiveOnly", NegativeOnly = "NegativeOnly", Both = "Both" };

            List <CogoPoint> points;

            if (!ObjectCollector.TrySelectObjects(out points, "\nSelect points"))
            {
                return;
            }

            PromptDoubleOptions valueOption = new PromptDoubleOptions("\nEnter value");

            valueOption.AllowNone     = false;
            valueOption.DefaultValue  = 0d;
            valueOption.AllowNegative = false;

            PromptDoubleResult valueResult = Tools.GetAcadEditor().GetDouble(valueOption);

            if (valueResult.Status != PromptStatus.OK)
            {
                return;
            }

            PromptKeywordOptions options = new PromptKeywordOptions("\nEnter method");

            options.AppendKeywordsToMessage = true;
            options.AllowArbitraryInput     = true;
            options.Keywords.Add(keywords.PositiveOnly);
            options.Keywords.Add(keywords.NegativeOnly);
            options.Keywords.Add(keywords.Both);
            options.AppendKeywordsToMessage = true;
            options.AllowNone        = true;
            options.Keywords.Default = keywords.Both;

            PromptResult keywordResult = Tools.GetAcadEditor().GetKeywords(options);

            if (keywordResult.Status != PromptStatus.OK)
            {
                return;
            }

            double ratio = keywordResult.StringResult == keywords.Both ? -0.5 : 0d;
            double sign  = keywordResult.StringResult == keywords.NegativeOnly ? -1d : 1d;

            if (keywordResult.StringResult == keywords.Both)
            {
                sign = 2d;
            }

            Random random = new Random(DateTime.Now.Second);

            foreach (CogoPoint point in points)
            {
                point.Elevation += (random.NextDouble() + ratio) * valueResult.Value * sign;
            }
        }
示例#3
0
        public void ReplacePointDescriptionToName()
        {
            List <CogoPoint> points;

            if (!ObjectCollector.TrySelectObjects(out points, "\nSelect points"))
            {
                return;
            }
            foreach (CogoPoint point in points)
            {
                point.PointName = point.FullDescription;
            }
        }
示例#4
0
        public static List <BlockReference> PromptBlocks(string msg = "\nSelect block references: ")
        {
            List <BlockReference> blocks;

            if (!ObjectCollector.TrySelectObjects(out blocks, msg))
            {
                return(null);
            }
            else
            {
                return(blocks);
            }
        }
        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);
        }
示例#6
0
        public void EditPointElevation()
        {
            List <CogoPoint> points;

            if (!ObjectCollector.TrySelectObjects(out points, "\nSelect points"))
            {
                return;
            }

            PromptDoubleOptions valueOption = new PromptDoubleOptions("\nEnter value");

            valueOption.AllowNone    = false;
            valueOption.DefaultValue = 0d;

            PromptDoubleResult valueResult = Tools.GetAcadEditor().GetDouble(valueOption);

            if (valueResult.Status != PromptStatus.OK)
            {
                return;
            }

            IgorKL.ACAD3.Model.CogoPoints.CogoPointEditor.EditElevation(points, valueResult.Value);
        }
示例#7
0
        public void EditDimensionValueRandom()
        {
            var keywords = new { PositiveOnly = "PositiveOnly", NegativeOnly = "NegativeOnly", Both = "Both" };

            List <Dimension> dimensions;

            if (!ObjectCollector.TrySelectObjects(out dimensions, "\nУкажите объект размер: "))
            {
                return;
            }

            PromptDoubleOptions valueOption = new PromptDoubleOptions("\nУкажите значение допусуа: ");

            valueOption.AllowNone     = false;
            valueOption.DefaultValue  = 0d;
            valueOption.AllowNegative = false;

            PromptDoubleResult valueResult = Tools.GetAcadEditor().GetDouble(valueOption);

            if (valueResult.Status != PromptStatus.OK)
            {
                return;
            }

            PromptKeywordOptions options = new PromptKeywordOptions("\nВыбирите метод: ");

            options.AppendKeywordsToMessage = true;
            options.AllowArbitraryInput     = true;
            options.Keywords.Add(keywords.PositiveOnly);
            options.Keywords.Add(keywords.NegativeOnly);
            options.Keywords.Add(keywords.Both);
            options.AppendKeywordsToMessage = true;
            options.AllowNone        = true;
            options.Keywords.Default = keywords.Both;

            PromptResult keywordResult = Tools.GetAcadEditor().GetKeywords(options);

            if (keywordResult.Status != PromptStatus.OK)
            {
                return;
            }

            double ratio = keywordResult.StringResult == keywords.Both ? -0.5 : 0d;
            double sign  = keywordResult.StringResult == keywords.NegativeOnly ? -1d : 1d;

            if (keywordResult.StringResult == keywords.Both)
            {
                sign = 2d;
            }

            Random random = new Random(DateTime.Now.Second);

            using (Transaction trans = Tools.StartTransaction())
            {
                foreach (Dimension d in dimensions)
                {
                    Dimension dbObj = trans.GetObject(d.Id, OpenMode.ForRead) as Dimension;
                    if (dbObj == null)
                    {
                        continue;
                    }

                    /*var pInf = dbObj.GetType().GetProperties();
                     *
                     * foreach (var p in pInf)
                     * {
                     *  try
                     *  {
                     *      Tools.Write(p.Name + "\t" + p.GetValue(dbObj).ToString() + "\n");
                     *  }
                     *  catch (Exception) { }
                     * }*/

                    string format = "#0";
                    if (dbObj.Dimdec > 0)
                    {
                        format += ".";
                        for (int i = 0; i < dbObj.Dimdec; i++)
                        {
                            format += "0";
                        }
                    }

                    string suffix = "\\X" + (Math.Round(dbObj.Measurement, dbObj.Dimdec) + ((random.NextDouble() + ratio) * valueResult.Value * sign) * dbObj.Dimlfac).ToString(format);

                    dbObj        = trans.GetObject(dbObj.Id, OpenMode.ForWrite) as Dimension;
                    dbObj.Suffix = suffix;
                }
                trans.Commit();
            }
        }
示例#8
0
        public void AddDimensionValueRandom()
        {
            var keywords = new { PositiveOnly = "PositiveOnly", NegativeOnly = "NegativeOnly", Both = "Both" };

            List <Dimension> dimensions;

            if (!ObjectCollector.TrySelectObjects(out dimensions, "\nSelect dimensions"))
            {
                return;
            }

            PromptDoubleOptions valueOption = new PromptDoubleOptions("\nEnter value");

            valueOption.AllowNone     = false;
            valueOption.DefaultValue  = 0d;
            valueOption.AllowNegative = false;

            PromptDoubleResult valueResult = Tools.GetAcadEditor().GetDouble(valueOption);

            if (valueResult.Status != PromptStatus.OK)
            {
                return;
            }

            PromptKeywordOptions options = new PromptKeywordOptions("\nEnter method");

            options.AppendKeywordsToMessage = true;
            options.AllowArbitraryInput     = true;
            options.Keywords.Add(keywords.PositiveOnly);
            options.Keywords.Add(keywords.NegativeOnly);
            options.Keywords.Add(keywords.Both);
            options.AppendKeywordsToMessage = true;
            options.AllowNone        = true;
            options.Keywords.Default = keywords.Both;

            PromptResult keywordResult = Tools.GetAcadEditor().GetKeywords(options);

            if (keywordResult.Status != PromptStatus.OK)
            {
                return;
            }

            double ratio = keywordResult.StringResult == keywords.Both ? -0.5 : 0d;
            double sign  = keywordResult.StringResult == keywords.NegativeOnly ? -1d : 1d;

            if (keywordResult.StringResult == keywords.Both)
            {
                sign = 2d;
            }

            Random random = new Random(DateTime.Now.Second);

            using (Transaction trans = Tools.StartTransaction())
            {
                foreach (Dimension d in dimensions)
                {
                    Dimension dbObj = trans.GetObject(d.Id, OpenMode.ForRead) as Dimension;
                    if (dbObj == null)
                    {
                        continue;
                    }

                    if (string.IsNullOrWhiteSpace(dbObj.Suffix))
                    {
                        continue;
                    }
                    if (!dbObj.Suffix.StartsWith("\\X"))
                    {
                        continue;
                    }
                    double val;
                    if (!double.TryParse(dbObj.Suffix.Replace("\\X", ""), out val))
                    {
                        continue;
                    }

                    string format = "#0";
                    if (dbObj.Dimdec > 0)
                    {
                        format += ".";
                        for (int i = 0; i < dbObj.Dimdec; i++)
                        {
                            format += "0";
                        }
                    }

                    string suffix = "\\X" + (Math.Round(val, dbObj.Dimdec) + ((random.NextDouble() + ratio) * valueResult.Value * sign) * dbObj.Dimlfac).ToString(format);

                    dbObj        = trans.GetObject(dbObj.Id, OpenMode.ForWrite) as Dimension;
                    dbObj.Suffix = suffix;
                }
                trans.Commit();
            }
        }
示例#9
0
        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());
            });
        }
示例#10
0
        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 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();
        }