Exemple #1
0
        /// <summary> 计算选择的所有曲线的面积与长度之和 </summary>
        public ExternalCmdResult Polyline2Point(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;
            //
            var pl = SelectUtils.PickEntity <Polyline3d>(docMdf.acEditor, message: "选择一个三维多段线对象");

            if (pl == null)
            {
                return(ExternalCmdResult.Cancel);
            }

            //
            var cs = EditStateIdentifier.GetCurrentEditState(docMdf);

            cs.CurrentBTR.UpgradeOpen();

            foreach (ObjectId id in pl)
            {
                var vert = id.GetObject(OpenMode.ForRead) as PolylineVertex3d;
                if (vert != null)
                {
                    var     pt = vert.Position;
                    DBPoint p  = new DBPoint(pt);
                    cs.CurrentBTR.AppendEntity(p);
                    docMdf.acTransaction.AddNewlyCreatedDBObject(p, true);
                }
            }
            cs.CurrentBTR.DowngradeOpen();

            return(ExternalCmdResult.Commit);
        }
Exemple #2
0
        public override bool Check(string query)
        {
            var arguments = SelectUtils.GetArgumentsFromQuery(query);

            if (arguments[1] != "*" && !arguments[1].StartsWith("("))
            {
                throw new MalformedArgumentsException();
            }

            var fromKeyword = SelectUtils.GetFromKeywordFromArguments(arguments).ToLower();

            if (fromKeyword != "from")
            {
                throw new MalformedArgumentsException();
            }

            var whereKeyword = SelectUtils.GetWhereKeywordFromArguments(arguments);

            if (whereKeyword != null && whereKeyword.ToLower() != "where")
            {
                throw new MalformedArgumentsException();
            }

            return(this.CheckNext(query));
        }
Exemple #3
0
        public void GetColumnNamesFromQuery_MultipleColumnNames_ShouldReturnValidColumnNamesArray(string query)
        {
            var actual = SelectUtils.GetColumnNamesFromQuery(query);

            var expected = new string[] { "email", "isAdult" };

            Assert.Equal(expected, actual);
        }
Exemple #4
0
        public void GetColumnNamesFromQuery_AsteriksSymbol_ShouldReturnValidColumnNamesArray(string query)
        {
            var actual = SelectUtils.GetColumnNamesFromQuery(query);

            var expected = new string[] { "*" };

            Assert.Equal(expected, actual);
        }
Exemple #5
0
        public void GetArgumentsFromQuery_ShouldReturnValidStringArray(string query)
        {
            var actual = SelectUtils.GetArgumentsFromQuery(query);

            var expected = new string[] { "SELECT", "*", "FROM", "users", "WHERE", "id", "=", "50;" };

            Assert.Equal(expected, actual);
        }
Exemple #6
0
        public void GetWhereKeywordFromArguments_KeywordNotExists_ShouldReturnNull(string query)
        {
            var arguments = SelectUtils.GetArgumentsFromQuery(query);

            var actual = SelectUtils.GetWhereKeywordFromArguments(arguments);

            Assert.Null(actual);
        }
Exemple #7
0
        public void GetConditionFromQuery_ConditionExists_ShouldReturnValidCondition(string query)
        {
            var actual = SelectUtils.GetConditionFromQuery(query);

            var expected = new string[] { "isAdult", "true" };

            Assert.Equal(expected, actual);
        }
Exemple #8
0
        public void GetTableNameFromArguments_ShouldReturnValidTableName(string query)
        {
            var arguments = SelectUtils.GetArgumentsFromQuery(query);

            var actual = SelectUtils.GetTableNameFromArguments(arguments);

            var expected = "users";

            Assert.Equal(expected, actual);
        }
Exemple #9
0
        public void GetWhereKeywordFromArguments_KeywordExists_ShouldReturnValidKeyword(string query)
        {
            var arguments = SelectUtils.GetArgumentsFromQuery(query);

            var actual = SelectUtils.GetWhereKeywordFromArguments(arguments);

            var expected = "WHERE";

            Assert.Equal(expected, actual);
        }
Exemple #10
0
        public override bool Check(string query)
        {
            var tableName = SelectUtils.GetTableNameFromArguments(SelectUtils.GetArgumentsFromQuery(query));

            if (tableName == null || !_database.GetTableNames().Contains(tableName.ToLower()))
            {
                throw new TableNotFoundException(tableName);
            }

            return(this.CheckNext(query));
        }
Exemple #11
0
        public override bool Check(string query)
        {
            var arguments = SelectUtils.GetArgumentsFromQuery(query);
            var keyword   = SelectUtils.GetWhereKeywordFromArguments(arguments);

            var condition = SelectUtils.GetConditionFromQuery(query);
            var tableName = SelectUtils.GetTableNameFromArguments(arguments).ToLower();

            if (keyword != null && condition == null)
            {
                throw new MalformedArgumentsException();
            }
            return(CheckNext(query));
        }
Exemple #12
0
        public override bool Check(string query)
        {
            var arguments = SelectUtils.GetArgumentsFromQuery(query);

            var condition = SelectUtils.GetConditionFromQuery(query);
            var tableName = SelectUtils.GetTableNameFromArguments(arguments).ToLower();

            var columnNames = _database.GetTable(tableName).GetColumnProperties().Select(x => x.Name).ToArray();

            if (condition != null && !columnNames.Contains(condition[0]))
            {
                throw new UnknownColumnNameException(condition[0]);
            }

            return(CheckNext(query));
        }
Exemple #13
0
        private Record[] SelectData(string query)
        {
            var arguments   = SelectUtils.GetArgumentsFromQuery(query);
            var tableName   = SelectUtils.GetTableNameFromArguments(arguments).ToLower().TrimEnd(';');
            var columnNames = SelectUtils.GetColumnNamesFromQuery(query);

            if (columnNames.Length == 0)
            {
                return(null);
            }
            if (columnNames[0] == "*")
            {
                columnNames = null;
            }

            var condition = SelectUtils.GetConditionFromQuery(query);

            return(_database.GetTable(tableName).GetRecords(columnNames, condition == null ? null : new Condition(condition[0], condition[1])));
        }
Exemple #14
0
        /// <summary>
        /// 具体的高度操作的代码模板
        /// </summary>
        /// <param name="docMdf"></param>
        /// <param name="impliedSelection"></param>
        private void DoSomethingTemplate(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            var obj = SelectUtils.PickEntity <Entity>(docMdf.acEditor);

            if (obj != null)
            {
                var blkTb =
                    docMdf.acTransaction.GetObject(docMdf.acDataBase.BlockTableId, OpenMode.ForRead) as BlockTable;
                var btr =
                    docMdf.acTransaction.GetObject(blkTb[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as
                    BlockTableRecord;

                var ent = new DBText();

                // 将新对象添加到块表记录和事务
                btr.AppendEntity(ent);
                docMdf.acTransaction.AddNewlyCreatedDBObject(ent, true);
            }
        }
Exemple #15
0
        public override bool Check(string query)
        {
            var queryColumnNames = SelectUtils.GetColumnNamesFromQuery(query);

            if (queryColumnNames.Length == 0 || queryColumnNames[0] == "*")
            {
                return(CheckNext(query));
            }

            var tableName           = SelectUtils.GetTableNameFromArguments(SelectUtils.GetArgumentsFromQuery(query)).ToLower();
            var databaseColumnNames = _database.GetTable(tableName).GetColumnProperties().Select(x => x.Name).ToArray();

            foreach (var columnName in (string[])queryColumnNames)
            {
                if (!databaseColumnNames.Contains(columnName) && columnName.ToLower() != "id")
                {
                    throw new UnknownColumnNameException(columnName);
                }
            }

            return(CheckNext(query));
        }
Exemple #16
0
        public override bool Check(string query)
        {
            var arguments = SelectUtils.GetArgumentsFromQuery(query);

            var condition = SelectUtils.GetConditionFromQuery(query);

            if (condition == null)
            {
                return(CheckNext(query));
            }

            var tableName = SelectUtils.GetTableNameFromArguments(arguments).ToLower();

            var columnTypes = _database.GetTable(tableName).GetColumnProperties();
            var type        = columnTypes.First(x => x.Name == condition[0]).Type;

            if (!GeneralUtils.IsTypeValid(type, condition[1]))
            {
                throw new InvalidColumnTypeException(condition[0], type);
            }

            return(CheckNext(query));
        }
Exemple #17
0
        /// <summary> <seealso cref="CommandDescription"/> </summary>
        public ExternalCmdResult GetExtension(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;
            //
            var entis = SelectUtils.PickEntities <Entity>(_docMdf.acEditor, "选择多个对象,提取几何定位");

            if (entis == null || entis.Length == 0)
            {
                return(ExternalCmdResult.Cancel);
            }
            //
            var sb = new StringBuilder();

            sb.AppendLine("Min;Max;Center;Width;Height;Depth;");
            foreach (var ent in entis)
            {
                AppendDescription(ent.GeometricExtents, ref sb);
                sb.AppendLine();
            }
            docMdf.WriteLineIntoDebuger("选择的元素个数:", entis.Length);
            _docMdf.WriteLineIntoDebuger(sb.ToString());
            //
            return(ExternalCmdResult.Commit);
        }
Exemple #18
0
        /// <summary> <seealso cref="CommandDescription"/> </summary>
        public ExternalCmdResult EditEntityAnnotation(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;
            //
            var ent = SelectUtils.PickEntity <Entity>(_docMdf.acEditor, "查看任意一个元素的注释");

            if (ent == null)
            {
                return(ExternalCmdResult.Commit);
            }
            AnnotationEntity.SetAppName(_docMdf);
            var annoEnt = new AnnotationEntity(ent);
            var annots  = annoEnt.ExtractAnnotsFromXdata();

            //
            annoEnt.WriteAnnotationsOnEditor(docMdf);
            bool   cont;
            Entity newEnt = null;

            do
            {
                bool   clearAnnot  = false;
                bool   editInForm  = false;
                bool   setNewValue = false;
                string newAnno     = null;
                cont = ReadEntityAnnot(docMdf.acEditor, out clearAnnot, out editInForm, out setNewValue, out newEnt);
                if (!cont)
                {
                    return(ExternalCmdResult.Commit);
                }
                //
                if (clearAnnot)
                {
                    annoEnt.ClearAnnotations();
                    _docMdf.WriteNow();
                }
                else if (editInForm)
                {
                    _docMdf.WriteNow();
                }
                else if (setNewValue)
                {
                    newAnno = annots.Count == 0 ? "" : annots[0];
                    cont    = SetAnnotations(docMdf.acEditor, ref newAnno);
                    if (!cont)
                    {
                        return(ExternalCmdResult.Commit);
                    }
                    annoEnt.SetAnnotsToXdata(newAnno);
                    //
                    annoEnt.WriteAnnotationsOnEditor(docMdf);
                }
                else
                {
                    // 选择了另一个元素
                    if (newEnt != null)
                    {
                        annoEnt = new AnnotationEntity(newEnt);
                        annots  = annoEnt.ExtractAnnotsFromXdata();
                        //
                        annoEnt.WriteAnnotationsOnEditor(docMdf);
                    }
                }
            } while (cont);

            //
            return(ExternalCmdResult.Commit);
        }
Exemple #19
0
        // 开始具体的调试操作
        private ExternalCmdResult CreateViewport(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;

            //// var vp1 = AddinManagerDebuger.PickObject<Entity>(docMdf.acEditor);
            //var hd = Utils.ConvertToHandle("AA07");
            //var vp2 = hd.GetObjectId(docMdf.acDataBase).GetObject(OpenMode.ForRead) as Viewport;
            //vp2.UpgradeOpen();
            //var lot = LayoutManager.Current.GetLayoutId("NewLayout4011").GetObject(OpenMode.ForRead) as Layout;
            //vp2.RotateViewport(_docMdf, lot, new Point2d(0, 0), 30.0 / 180 * Math.PI);

            //return ExternalCmdResult.Commit;
            // 从模型空间中获取视口裁剪框
            var     pl_Model      = SelectUtils.PickEntity <Curve>(docMdf.acEditor);
            Point3d bottomLeftPt  = default(Point3d);
            Point3d bottomRightPt = default(Point3d);
            double  bottomLength  = 0;
            var     succ          = GraphicalElementsSelector.GetPoint(docMdf.acEditor, "选择图纸的左下角点", out bottomLeftPt);

            if (!succ)
            {
                return(ExternalCmdResult.Cancel);
            }
            succ = GraphicalElementsSelector.GetPoint(docMdf.acEditor, "选择图纸的右下角点", out bottomRightPt);
            if (!succ)
            {
                return(ExternalCmdResult.Cancel);
            }
            succ = GraphicalElementsSelector.GetDouble(docMdf.acEditor, "图纸宽度(布局空间的单位)", out bottomLength,
                                                       defaultValue: 420, allowNegative: false);
            if (!succ)
            {
                return(ExternalCmdResult.Cancel);
            }

            var modelUcs = docMdf.acEditor.GetCurrentView().Ucs;

            // 打开布局
            var               lm = LayoutManager.Current;
            Layout            layout;
            ObjectId          layoutId;
            Form_LayoutLister f = new Form_LayoutLister(docMdf);

            f.ShowDialog();
            if (f.CreateNewLayout)
            {
                //
                MessageBox.Show("请先自行创建带图框的布局");
                return(ExternalCmdResult.Cancel);

                /*
                 * var layoutName = "NewLayout" + DateTime.Now.Minute + DateTime.Now.Second;
                 * layoutId = lm.GetLayoutId(layoutName);
                 * if (!layoutId.IsValid)
                 * {
                 *  // 重启事务
                 *  docMdf.RestartTransaction(commitCancel: false);
                 *  //
                 *  layoutId = LayoutUtil.CreateLayout(layoutName);
                 *  layout = layoutId.GetObject(OpenMode.ForRead) as Layout;
                 *  //
                 *  LayoutUtil.SetPlotSettings(layout, "A3", "monochrome.ctb", "交通院道路室 121");
                 * }
                 * else
                 * {
                 *  layout = LayoutManager.Current.GetLayoutId(name: layoutName).GetObject(OpenMode.ForRead) as Layout;
                 * }
                 */
            }
            else if (f.Layout != null)
            {
                layout = f.Layout;
            }
            else
            {
                return(ExternalCmdResult.Cancel);
            }

            // docMdf.RestartTransaction(true);
            // 切换布局
            // lm.SetCurrentLayoutId(layout.Id); // AutoCAD 2016
            lm.CurrentLayout = layout.LayoutName;

            // 创建视口
            CreateViewport(docMdf, modelUcs, layout, pl_Model, bottomLeftPt, bottomRightPt, bottomLength);

            // 切换回模型空间
            // Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("TILEMODE", 1);
            // LayoutUtil.SwitchLayout();
            return(ExternalCmdResult.Commit);
        }
Exemple #20
0
        public void GetConditionFromQuery_ConditionNotExists_ShouldReturnNull(string query)
        {
            var actual = SelectUtils.GetConditionFromQuery(query);

            Assert.Null(actual);
        }