예제 #1
0
 public PromptChainageResult(PromptStatus status, string stringResult)
 {
     Status       = status;
     StringResult = stringResult;
     if (AcadText.TryChainageFromString(stringResult, out double ch))
     {
         DoubleResult = ch;
     }
 }
예제 #2
0
        public static PromptChainageResult GetChainage(this Editor ed, PromptChainageOptions opts)
        {
            while (true)
            {
                PromptResult res;
                if (opts.HasKeywords)
                {
                    res = ed.GetKeywords(opts.ToKeywordOptions());
                }
                else
                {
                    res = ed.GetString(opts.ToStringOptions());
                }

                if (res.Status == PromptStatus.None)
                {
                    if (AcadText.TryChainageFromString(opts.DefaultValue, out _))
                    {
                        return(new PromptChainageResult(PromptStatus.OK, opts.DefaultValue));
                    }
                    else if (AcadText.TryChainageFromString(res.StringResult, out _))
                    {
                        return(new PromptChainageResult(PromptStatus.OK, res.StringResult));
                    }
                    else
                    {
                        ed.WriteMessage("Invalid chainage string.");
                        continue;
                    }
                }
                else if (res.Status == PromptStatus.OK || res.Status == PromptStatus.Keyword)
                {
                    KeywordCollection keywords = (opts.HasKeywords ? opts.ToKeywordOptions().Keywords : opts.ToStringOptions().Keywords);
                    for (int i = 0; i < keywords.Count; i++)
                    {
                        var keyword = keywords[i];
                        if (string.Compare(keyword.GlobalName, res.StringResult, true) == 0)
                        {
                            return(new PromptChainageResult(PromptStatus.Keyword, keyword.GlobalName));
                        }
                    }

                    if (AcadText.TryChainageFromString(res.StringResult, out _))
                    {
                        return(new PromptChainageResult(PromptStatus.OK, res.StringResult));
                    }
                    else
                    {
                        ed.WriteMessage("Invalid chainage string.");
                        continue;
                    }
                }

                return(new PromptChainageResult(res.Status, res.StringResult));
            }
        }