当前位置: 首页>>代码示例>>C#>>正文


C# Scanner.CreateRegexPattern方法代码示例

本文整理汇总了C#中Scanner.CreateRegexPattern方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.CreateRegexPattern方法的具体用法?C# Scanner.CreateRegexPattern怎么用?C# Scanner.CreateRegexPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scanner的用法示例。


在下文中一共展示了Scanner.CreateRegexPattern方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: handleImageMessage

        // Fields for handling and storing parts of the image messages
        // sent from the executive.
        protected override void handleImageMessage(int id, string line)
        {
            Scanner scanner = new Scanner();
            String r = @"\d+:\s+IMAGE:\s+##\d+ (\d+)x(\d+) (.*)={Double} aspect={Double} " +
                @"from=\({Double},{Double},{Double}\) to=\({Double},{Double},{Double}\) " +
                @"up=\({Double},{Double},{Double}\) " +
                @"box=\({Double},{Double},{Double}\)\({Double},{Double},{Double}\)\({Double},{Double},{Double}\)\({Double},{Double},{Double}\) " +
                @"aamat=\({Double},{Double},{Double}\)\({Double},{Double},{Double}\)\({Double},{Double},{Double}\)\({Double},{Double},{Double}\)\s+" +
                @"ddcamera=(\d+) button=(\d+)";
            r = scanner.CreateRegexPattern(r);

            Regex regex = new Regex(r);
            Match m = regex.Match(line);
            if (m.Success)
            {
                int x = int.Parse(m.Groups[1].Value);
                int y = int.Parse(m.Groups[2].Value);
                String s = m.Groups[3].Value;
                double w = double.Parse(m.Groups[4].Value);
                double a = double.Parse(m.Groups[5].Value);
                double[] from = { double.Parse(m.Groups[6].Value), double.Parse(m.Groups[7].Value), double.Parse(m.Groups[8].Value) };
                double[] to = { double.Parse(m.Groups[9].Value), double.Parse(m.Groups[10].Value), double.Parse(m.Groups[11].Value) };
                double[] up = { double.Parse(m.Groups[12].Value), double.Parse(m.Groups[13].Value), double.Parse(m.Groups[14].Value) };
                double[,] box = {
                { double.Parse(m.Groups[15].Value), double.Parse(m.Groups[16].Value), double.Parse(m.Groups[17].Value) },
                { double.Parse(m.Groups[18].Value), double.Parse(m.Groups[19].Value), double.Parse(m.Groups[20].Value) },
                { double.Parse(m.Groups[21].Value), double.Parse(m.Groups[22].Value), double.Parse(m.Groups[23].Value) },
                { double.Parse(m.Groups[24].Value), double.Parse(m.Groups[25].Value), double.Parse(m.Groups[26].Value) } };
                double[,] aamat = {
                { double.Parse(m.Groups[27].Value), double.Parse(m.Groups[28].Value), double.Parse(m.Groups[29].Value) },
                { double.Parse(m.Groups[30].Value), double.Parse(m.Groups[31].Value), double.Parse(m.Groups[32].Value) },
                { double.Parse(m.Groups[33].Value), double.Parse(m.Groups[34].Value), double.Parse(m.Groups[35].Value) },
                { double.Parse(m.Groups[36].Value), double.Parse(m.Groups[37].Value), double.Parse(m.Groups[38].Value) } };
                int ddcamera = int.Parse(m.Groups[39].Value);
                int button = int.Parse(m.Groups[40].Value);

                bool persp;
                double viewAngle;

                if (s == "width")
                    persp = false;
                else
                    persp = true;

                double xdiff = from[0] - to[0];
                double ydiff = from[1] - to[1];
                double zdiff = from[2] - to[2];
                double dist = Math.Sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);

                if (persp)
                {
                    viewAngle = Math.Atan(w / 2) * 360 / Math.PI;
                    w = dist * w;
                }
                else
                {
                    viewAngle = Math.Atan((w / 2) / dist) * 360 / Math.PI;
                }

                DirectInteractionMode imode = image.getInteractionMode();

                if (ddcamera == 1 || button == 1)
                {
                    // If in navigate mode, then to, from and up are
                    // set elsewhere.
                    if (imode != DirectInteractionMode.NAVIGATE || ddcamera == 1)
                    {
                        this.setTo(to, false);
                        this.setFrom(from, false);
                        this.setUp(up, false);
                    }

                    setResolution(x, y, false);
                    setWidth(w, false);
                    setAspect(a, false);
                    setBox(box, false);
                    setProjection(persp, false);
                    setViewAngle(viewAngle, false);
                    enableVector(true, false);
                    sendValuesQuietly();
                    image.newCamera(box, aamat, from, to, up, x, y, w, persp, viewAngle);
                }
                else if (!image.IsCameraInitialized || imode == DirectInteractionMode.NAVIGATE)
                    image.newCamera(box, aamat, from, to, up, x, y, w, persp, viewAngle);

                image.allowDirectInteraction(true);

                if (this.saveInteractionMode != DirectInteractionMode.NONE)
                {
                    image.setInteractionMode(saveInteractionMode);
                    saveInteractionMode = DirectInteractionMode.NONE;
                }
            }
            else
            {
                regex = new Regex(@"\d+:  IMAGE:  ##\d+ (\d+)x(\d+)");
                m = regex.Match(line);

//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:opendx2,代码行数:101,代码来源:ImageNode.cs

示例2: ParseGeometryComment

        /// <summary>
        ///     ParseGeometryComment actually performs the Window placement and
        ///     Window sizing for shell windows such as the ImageWindow and
        ///     Control Panels. The network saves the placement as a normalized
        ///     vector of where and what size it was on the authors screen
        ///     and then tries to replicate that to fit the screen of others. 
        /// </summary>
        /// <param name="line"></param>
        /// <param name="file"></param>
        /// <param name="lineno"></param>
        /// <param name="xpos"></param>
        /// <param name="ypos"></param>
        /// <param name="xsize"></param>
        /// <param name="ysize"></param>
        /// <param name="tag"></param>
        /// <returns></returns>
        public static bool ParseGeometryComment(String line, String file, int lineno, ref int xpos,
            ref int ypos, ref int xsize, ref int ysize, String tag)
        {
            Scanner scanner = new Scanner();
            Match match = null;
            float norm_xsize, norm_ysize, norm_xpos, norm_ypos;
            Screen[] screens = Screen.AllScreens;
            int screen = -1;
            int width = 0, height = 0, x = 0, y = 0;

            if (tag == null)
                tag = "window";

            if (!line.StartsWith(" " + tag + ": position = ("))
                return false;

            String scanline;
            scanline = tag +
                @":\s*position\s*=\s*\(\s*{Single}\s*\,\s*{Single}\s*\)\s*\,\s*size\s*=\s*{Single}\s*x\s*{Single}\s*,\s*screen\s*=\s*{Int32}";

            scanline = scanner.CreateRegexPattern(scanline);
            //scanner.Scan(line, scanline, targets);
            Regex reggie = new Regex(scanline);

            match = reggie.Match(line);
            if (!match.Success)
            {
                scanline = tag +
                @":\s*position\s*=\s*\(\s*{Single}\s*\,\s*{Single}\s*\)\s*\,\s*size\s*=\s*{Single}\s*x\s*{Single}";
                scanline = scanner.CreateRegexPattern(scanline);
                reggie = new Regex(scanline);
                match = reggie.Match(line);
            }

            if (!match.Success)
            {
                WarningDialog wd = new WarningDialog();
                wd.post("Bad comment found in file {0} line {1}", file, lineno);
                return false;
            }

            string sVal = match.Groups[1].Captures[0].Value;
            norm_xpos = float.Parse(sVal);
            sVal = match.Groups[2].Captures[0].Value;
            norm_ypos = float.Parse(sVal);
            sVal = match.Groups[3].Captures[0].Value;
            norm_xsize = float.Parse(sVal);
            sVal = match.Groups[4].Captures[0].Value;
            norm_ysize = float.Parse(sVal);
            if (match.Captures.Count == 6)
            {
                sVal = match.Groups[5].Captures[0].Value;
                screen = Int32.Parse(sVal);
            }

            if (norm_xsize >= 3 || norm_ysize >= 3)
            {
                xpos = UnspecifiedPosition;
                ypos = UnspecifiedPosition;
                xsize = UnspecifiedDimension;
                ysize = UnspecifiedDimension;
                return true;
            }

            if (screen != -1 && screen < screens.Length)
            {
                width = screens[screen].Bounds.Width;
                height = screens[screen].Bounds.Height;
                x = screens[screen].Bounds.X;
                y = screens[screen].Bounds.Y;
            }
            else
            {
                Screen ps = Screen.PrimaryScreen;
                width = ps.Bounds.Width;
                height = ps.Bounds.Height;
                x = ps.Bounds.X;
                y = ps.Bounds.Y;
            }

            xpos = (Int32)Math.Round(width * norm_xpos + x);
            ypos = (Int32)Math.Round(height * norm_ypos + y);
            xsize = (Int32)Math.Round(width * norm_xsize);
            ysize = (Int32)Math.Round(height * norm_ysize);
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:opendx2,代码行数:101,代码来源:Utils.cs


注:本文中的Scanner.CreateRegexPattern方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。