Ejemplo n.º 1
0
        public String DeepValOf(String val, XmlNode node, VectorObject prt)
        {
            String sk = node.Name + ":" +val;
            if (ValueStack.Contains(sk))
            {
                StringBuilder sb = new StringBuilder();
                foreach(String v in ValueStack){
                    sb.Append(v);
                    sb.Append(">");
                }
                sb.Append(sk);
                throw new Exception("����ֵ�ݹ�:" + sb.ToString());
            }
            ValueStack.Add(sk);
            String retval = val;
            if (val != null && val.Length > 0)
            {
                if (R_VAL.IsMatch(val))
                {
                    String key = val.Substring(1);
                    switch (val[0])
                    {
                        case '$':
                            if (this.Values.Contains(key))
                            {
                                retval = DeepValOf(((XmlNode)this.Values[key]).InnerText, node, prt);
                            }
                            else
                            {
                                throw new Exception(String.Format("Ԥ����ֵ{0}������!", key));
                            }
                            break;
                        case '#':
                            if (node != null && node.Attributes!=null && node.Attributes[key] != null)
                            {
                                retval = DeepValOf(node.Attributes[key].Value, node, prt);
                            }
                            else if (prt != null && prt.Attributes != null && prt.Attributes[key] != null)
                            {
                                retval = DeepValOf(prt.Attributes[key].ToString(), node, prt);
                            }
                            else
                            {
                                throw new Exception(String.Format("{0}������{1}������!", node != null ? node.OuterXml : "PRT", key));
                            }
                            break;
                    }
                }
                else
                {
                    //
                    Match m = R_MVAL.Match(val);
                    if (m.Success)
                    {
                        String ns = val.Substring(0, m.Index) + DeepValOf(m.Value, node, prt) + val.Substring(m.Index + m.Length);
                        if (R_MVAL.IsMatch(ns))
                            retval = DeepValOf(ns, node, prt);
                        else
                            retval = ns;
                    }
                }

            }
            ValueStack.Remove(sk);
            return retval;
        }
Ejemplo n.º 2
0
        public VectorObject ParseToVector(XmlNode node, ParseCallback cbk)
        {
            if (node is System.Xml.XmlComment)
                return null;
            if (cbk != null && cbk.BeforeParse != null && cbk.BeforeParse(this, node) == false)
                return null;
            if (BooltAttr(node, "break"))
            {
                System.Diagnostics.Debug.WriteLine("break: " + node.Name);
            }
            String tag = node.Name;
            if (ParseStack.Contains(tag))
            {
                StringBuilder sb = new StringBuilder();
                foreach (String s in ParseStack)
                {
                    sb.Append(s);
                    sb.Append(">");
                }
                sb.Append(tag);
                throw new Exception("����ͼ�εݹ�:"+sb.ToString());
            }
            ParseStack.Add(tag);

            VectorObject vo = null;
            List<String> IgnorAttrs = new List<string>();
            float pscale = this.Scale;
            switch (tag)
            {
                case "line":
                    vo = new VectorLine(FloatAttr(node, "x1") * Scale, FloatAttr(node, "y1") * Scale, FloatAttr(node, "x2") * Scale, FloatAttr(node, "y2") * Scale);
                    IgnorAttrs.Add("x1");
                    IgnorAttrs.Add("y1");
                    IgnorAttrs.Add("x2");
                    IgnorAttrs.Add("y2");
                    break;
                case "box":
                    vo = new VectorBox(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, BooltAttr(node, "fill"));
                    IgnorAttrs.Add("x");
                    IgnorAttrs.Add("y");
                    IgnorAttrs.Add("w");
                    IgnorAttrs.Add("h");
                    IgnorAttrs.Add("fill");
                    break;
                case "ellipse":
                case "circle":
                    if (node.Attributes["r"] != null)
                        vo = new VectorCircle(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "r") * Scale, FloatAttr(node, "r") * Scale, BooltAttr(node, "fill"));
                    else
                        vo = new VectorCircle(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, BooltAttr(node, "fill"));
                    IgnorAttrs.Add("x");
                    IgnorAttrs.Add("y");
                    IgnorAttrs.Add("r");
                    IgnorAttrs.Add("fill");
                    break;
                case "text":
                    vo = new VectorText(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, Escaped(AttrOf(node, "text")));
                    IgnorAttrs.Add("x");
                    IgnorAttrs.Add("y");
                    IgnorAttrs.Add("text");
                    break;
                case "pie":
                    vo = new VectorPie(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, FloatAttr(node, "sta"), FloatAttr(node, "swa"), BooltAttr(node, "fill"));
                    break;
                case "arc":
                    vo = new VectorArc(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale, FloatAttr(node, "w") * Scale, FloatAttr(node, "h") * Scale, FloatAttr(node, "sta"), FloatAttr(node, "swa"));
                    break;
                case "path":
                    if (node.HasChildNodes && node.ChildNodes.Count > 2)
                    {
                        float sx = FloatAttr(node, "x");
                        float sy = FloatAttr(node, "y");
                        List<Object> pathes = new List<Object>(node.ChildNodes.Count);
                        foreach (XmlNode ch in node.ChildNodes)
                        {
                            if (ch is System.Xml.XmlComment)
                                continue;
                            switch (ch.Name)
                            {
                                case "point":
                                    pathes.Add(new VectorPathLine(FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale, FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale));
                                    break;
                                case "line":
                                    pathes.Add(new VectorPathLine(FloatAttr(ch, "x1") * Scale, FloatAttr(ch, "y1") * Scale, FloatAttr(ch, "x2") * Scale, FloatAttr(ch, "y2") * Scale));
                                    break;
                                case "arc":
                                    pathes.Add(new VectorPathArc(FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale, FloatAttr(ch, "w") * Scale, FloatAttr(ch, "h") * Scale, FloatAttr(ch, "sta"), FloatAttr(ch, "swa")));
                                    break;
                                case "pie":
                                    pathes.Add(new VectorPathPie(FloatAttr(ch, "x") * Scale, FloatAttr(ch, "y") * Scale, FloatAttr(ch, "w") * Scale, FloatAttr(ch, "h") * Scale, FloatAttr(ch, "sta"), FloatAttr(ch, "swa")));
                                    break;
                            }
                        }
                        vo = new VectorPath(pathes, BooltAttr(node, "fill"));
                        IgnorAttrs.Add("x");
                        IgnorAttrs.Add("y");
                        IgnorAttrs.Add("fill");
                    }
                    else
                    {
                        throw new Exception(String.Format("·���ڵ�{0}���������������ӽڵ�.", node.OuterXml));
                    }
                    break;
                default:
                    // ���ȳ���ʹ����չ����
                    // �����չ����ʧ�ܣ�����Ϊ�ýڵ�Ϊ����ͼ��
                    List<String> oIgnorAttrs = this.CurIgnorAttrs;
                    this.CurIgnorAttrs = IgnorAttrs;
                    vo = cbk != null && cbk.ExtensionParse != null ? cbk.ExtensionParse(this, node) : null;
                    if (vo != null)
                        break;
                    this.CurIgnorAttrs = oIgnorAttrs;
                    // ��չ����ʧ�ܣ��ж��Ƿ���ڸø���ͼ��
                    if (!Shapes.Contains(tag))
                        throw new Exception(String.Format("δ����ͼ��{0}", tag));
                    else
                    {
                        // ����ע��

                    }
                    // ��������ͼ��
                    VectorComplex vc = new VectorComplex(FloatAttr(node, "x") * Scale, FloatAttr(node, "y") * Scale);
                    IgnorAttrs.Add("x");
                    IgnorAttrs.Add("y");

                    // ���ڸ���ͼ����Ҫ�ȼ�
                    AddExtAttribute(IgnorAttrs, (XmlNode)Shapes[tag], vc);
                    AddExtAttribute(IgnorAttrs, node, vc);

                    float scl = this.Scale;

                    this.Scale *= node.Attributes["scale"] == null ? 1.0f : FloatAttr(node, "scale");
                    foreach (XmlNode cnode in ((XmlNode)Shapes[tag]).ChildNodes)
                    {
                        VectorObject ovo = CurParent;
                        CurParent = vc;
                        VectorObject cvo = this.ParseToVector(cnode, cbk);
                        if (cvo != null)
                            vc.AddChild(cvo);
                        CurParent = ovo;
                    }
                    this.Scale = scl;
                    vo = vc;
                    break;
            }
            vo.ScaleWeight = pscale;
            if (vo!=null && vo.Attributes == null)
                AddExtAttribute(IgnorAttrs, node, vo);
            ParseStack.Remove(tag);

            if (node.Attributes["display"]!=null)
                vo.Display = BooltAttr(node, "display");

            if (cbk != null && cbk.AfterParse != null && cbk.AfterParse(this, node, vo) == false)
                return null;
            else
            {
                return vo;
            }
        }
Ejemplo n.º 3
0
        private void AddExtAttribute(List<String> IgnorAttrs, XmlNode node, VectorObject vo)
        {
            ContextAttributes atts = vo.Attributes == null ? new ContextAttributes() : vo.Attributes;
            foreach (XmlAttribute xa in node.Attributes)
            {
                if (!IgnorAttrs.Contains(xa.Name))
                {
                    // ���ȿ��Ƕ���
                    Object df = GetDefine(DeepValOf(xa.Value, node, CurParent));

                    // ���û�ж���Ļ��ڿ���ʹ��Ԥ����ֵ
                    atts[xa.Name] = df != null ? df : DeepValOf(xa.Value, node, CurParent);
                }
            }
            if (atts.Count != 0)
                vo.Attributes = atts;
        }
Ejemplo n.º 4
0
 public void AddChild(VectorObject vo)
 {
     vo.Parent = this;
     this.Children.Add(vo);
 }