public override bool parseComment(string comment, string filename, int lineno, Network net)
        {
            if (!comment.StartsWith(" page assignment:"))
                return false;

            Regex regex = new Regex(@" page assignment:(.*)\s+order=(\d+), windowed=(\d+), showing=(\d+)");
            Match m = regex.Match(comment);
            if (!m.Success)
            {
                WarningDialog wd = new WarningDialog();
                wd.post("Unrecognized page (file {0}, line {1})", filename, lineno);
                return false;
            }
            String name = m.Groups[1].Value.Trim();
            if (!createGroup(name, net))
                return false;

            PageGroupRecord prec = (PageGroupRecord)getGroup(name);
            prec.order_in_list = int.Parse(m.Groups[2].Value);
            prec.windowed = int.Parse(m.Groups[3].Value) > 0;
            prec.showing = int.Parse(m.Groups[4].Value) > 0;

            return true;
        }
示例#2
0
        /// <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);

            return true;
        }
示例#3
0
        /// <summary>
        /// The messages we deal with can contain one or more of the following...
        ///
        /// 'min=%g' 'max=%g' 'delta=%g' 'value=%g' 'decimals=%d'
        ///
        ///  or one or more of the following...
        ///
        /// 'min=[%g %g %g]' 'max=[%g %g %g]' 'delta=[%g %g %g]' 'value=[%g %g %g]'
        /// 'decimals=[%g %g %g]'
        /// </summary>
        /// <param name="line"></param>
        /// <returns>number of attributes parsed</returns>
        protected override int handleInteractorMsgInfo(string line)
        {
            int values;
            if (IsVectorType)
                values = handleVectorMsgInfo(line);
            else
                values = handleScalarMsgInfo(line);

            // Handle the 'method="%s"' part of the message.
            // We only need to look for the message if we don't already have it.
            if (isInputConnected((int)Params.INCRMETHOD))
            {
                if (line.Contains("method="))
                {
                    Regex regex = new Regex("method=\"(.*)\"");
                    Match m = regex.Match(line);
                    if (m.Success)
                    {
                        values++;
                        setInputAttributeFromServer((int)Params.INCRMETHOD, m.Groups[1].Value,
                            DXTypeVals.StringType);
                    }
                }
            }

            // Make sure that the min or max sent back from the executive is
            // consistent.  If the user has not connected the data tab and has
            // only one of min and max set then it is possible that the value sent
            // back by the module conflicts with the other value stored in the ui.

            if (!isInputDefaulting((int)Params.DATA))
            {
                bool min_dflting = isInputDefaulting((int)Params.MIN);
                bool max_dflting = isInputDefaulting((int)Params.MAX);
                if ((min_dflting && !max_dflting) || (!min_dflting && max_dflting))
                {
                    int comps = getComponentCount();
                    bool issue_warning = false;
                    for (int i = 1; i <= comps; i++)
                    {
                        double minval = getComponentMinimum(i);
                        double maxval = getComponentMaximum(i);
                        if (minval > maxval)
                        {
                            issue_warning = true;
                            if (min_dflting)
                                setComponentMinimum(i, maxval);
                            else
                                setComponentMaximum(i, minval);
                        }
                    }
                    if (issue_warning)
                    {
                        String set, setattr;
                        if (min_dflting)
                        {
                            set = "maximum";
                            setattr = "minimum";
                        }
                        else
                        {
                            set = "minimum";
                            setattr = "maximum";
                        }
                        WarningDialog wd = new WarningDialog();
                        wd.post("{0} value provided to {1} conflicts with {2} value set with " +
                            "'Set Attributes' dialog ...adjusting {2}.", set, NameString,
                            setattr);
                    }
                }
            }
            return values;
        }
        public override bool setLabelString(String label)
        {
            if (label == LabelString)
                return true;

            List<Node> rnl = this.getNetwork().makeClassifiedNodeList(typeof(ReceiverNode), false);

            if (initializing || getNetwork().IsReadingNetwork)
            {
                if (!initializing)
                {
                    //
                    // Because of an old bug (hopefully fixed in 3.1.4), we need to scan
                    // for existing receivers with the same name.  These receivers are supposed
                    // to be placed later in the .net file than the transmitter.  Network::
                    // mergeNetworks() was not connecting up transmitters and receivers properly
                    // until 3.1.4.  So this check will work around a bug.
                    //
                    Network net = this.getNetwork();
                    int net_major = net.getNetMajorVersion();
                    int net_minor = net.getNetMinorVersion();
                    int net_micro = net.getNetMicroVersion();
                    int net_version = Utils.VersionNumber(net_major, net_minor, net_micro);
                    int fixed_version = Utils.VersionNumber(3, 1, 1);
                    if (net_version < fixed_version)
                    {
                        // grab up any receivers that already have this name
                        if (rnl != null)
                        {
                            foreach (Node node in rnl)
                            {
                                ReceiverNode rn = (ReceiverNode)node;
                                if (!rn.IsTransmitterConnected &&
                                    node.LabelString == label)
                                {
                                    Network lnet = getNetwork();
                                    if (!lnet.checkForCycle(this, node))
                                    {
                                        new Ark(this, 0, node, 0);
                                    }
                                    else
                                    {
                                        WarningDialog wd = new WarningDialog();
                                        String msg = "This network contains Transmitter/Receiver " +
                                            "pair \"{0}\" which would cause a cyclic " +
                                            "connection. Executing this network will yield " +
                                            "unpredictable results until this is fixed.";
                                        wd.post(msg, LabelString);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                return base.setLabelString(label);
            }
            if (!verifyRestrictedLabel(label))
                return false;

            String conflict = getNetwork().nameConflictExists(this, label);
            if (conflict != null)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("A {0} with name \"{1}\" already exists.", conflict, label);
                return false;
            }

            if (!getNetwork().IsReadingNetwork)
            {
                if (rnl != null)
                {
                    foreach (Node nd in rnl)
                    {
                        ReceiverNode rn = (ReceiverNode)nd;
                        if (!rn.IsTransmitterConnected &&
                            rn.LabelString == label)
                        {
                            if (getNetwork().checkForCycle(this, rn))
                            {
                                ErrorDialog ed = new ErrorDialog();
                                ed.post("Unable to rename Transmitter \"{0}\" to \"{1}\" because it would create a cyclic connection.",
                                    LabelString, label);
                                return false;
                            }
                        }
                    }
                }
            }

            if (!base.setLabelString(label))
                return false;

            // Rename receivers
            List<Ark> reclist = getOutputArks(0);
            foreach (Ark a in reclist)
            {
                int dummy;
                Node rcvr = a.getDestinationNode(out dummy);
                rcvr.setLabelString(label);
            }

            // grab up any receivers that already have this name
            // We've already done the check for cyclic connections.
            if (rnl != null)
            {
                foreach (Node nd in rnl)
                {
                    ReceiverNode rn = (ReceiverNode)nd;
                    if (!rn.IsTransmitterConnected &&
                        LabelString == label)
                    {
                        new Ark(this, 0, rn, 0);
                    }
                }
            }
            return true;
        }