예제 #1
0
        /// <summary>
        /// Create a copy of current graphic object
        /// </summary>
        /// <returns></returns>
        public GOM_Interface_Graphic_Object Clone()
        {
            GOM_Object_Primitive	obj;

            obj				= new GOM_Object_Primitive();
            obj.m_id		= this.m_id;
            obj.m_xOffset	= this.m_xOffset;
            obj.m_yOffset	= this.m_yOffset;
            obj.m_rotation	= this.m_rotation;
            obj.m_template	= this.m_template;
            obj.innerText	= this.innerText;
            obj.fontColor	= this.fontColor;
            obj.font		= (System.Drawing.Font)this.font.Clone();

            obj.InitializeFromTemplate(this.m_template);

            for (int i = 0; i < obj.rgPoints.Count; i++)
            {
                GOM_Point	pt;

                pt = this.Points(obj.rgPoints[i].id);

                obj.rgPoints[i].x = pt.x;
                obj.rgPoints[i].y = pt.y;
            }

            for (int i = 0; i < obj.rgDrawingStyles.Count; i++)
            {
                obj.rgDrawingStyles[i].drawingStyle = (System.Drawing.Pen)this.DrawingStyles(obj.rgDrawingStyles[i].id).drawingStyle.Clone();
            }

            for (int i = 0; i < obj.rgFillingStyles.Count; i++)
            {
                obj.rgFillingStyles[i].fillingStyle = (System.Drawing.Brush)this.FillingStyles(obj.rgFillingStyles[i].id).fillingStyle.Clone();
            }

            //Clone
            #region new_modified
            //clone var
            if (this.var_list != null)
            {
                obj.var_list = this.var_list.clone();
            }
            //clone restriction list
            if (this.res_list != null)
            {
                obj.res_list = this.res_list.clone();
            }
            #endregion

            return obj;
        }
예제 #2
0
        /// <summary>
        /// Load a primitive object from a node of XML tree
        /// </summary>
        /// <param name="node">The node which is the root of the XML tree</param>
        /// <param name="rgTemplates">The list of known templates</param>
        /// <returns>If successful, a primitve object is returned. Otherwise, an exception will be thrown out</returns>
        public static GOM_Object_Primitive LoadFromXml(System.Xml.XmlNode node, GOM_Templates rgTemplates)
        {
            GOM_Object_Primitive	primitive = null;

            if (System.String.Compare(node.Name, GOM_TAGS.GRAPHIC_OBJECT) != 0)
            {
                throw new Exception("Invalid input. Not a graphic object node!");
            }

            primitive = new GOM_Object_Primitive();
            //Load properties of the graphic object
            for (int i = 0; i < node.Attributes.Count; i++)
            {
                if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.ID, true) == 0)
                {
                    primitive.id = node.Attributes[i].Value;
                }
                if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.TYPE, true) == 0)
                {
                    if (!node.Attributes[i].Value.Equals("primitive"))
                    {
                        throw new Exception("Invalid input. Not a primitive object node!");
                    }
                }
                if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.X_OFFSET, true) == 0)
                {
                    primitive.m_xOffset = float.Parse(node.Attributes[i].Value);
                }
                if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.Y_OFFSET, true) == 0)
                {
                    primitive.m_yOffset = float.Parse(node.Attributes[i].Value);
                }
                if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.ROTATION, true) == 0)
                {
                    primitive.m_rotation = float.Parse(node.Attributes[i].Value);
                }
                if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.TEMPLATE, true) == 0)
                {
                    for (int j = 0; j < rgTemplates.Count; j++)
                    {
                        if (rgTemplates[j].id.Equals(node.Attributes[i].Value))
                        {
                            primitive.m_template = rgTemplates[j];
                        }
                    }

                    if (primitive.m_template == null)
                    {
                        throw new Exception("Unknown template");
                    }
                }
            }

            if (primitive.m_template == null)
            {
                throw new Exception("Can not find template of the graphic object");
            }
            //Initialize the graphic object according to the template
            primitive.InitializeFromTemplate(primitive.m_template);
            //Update status of the graphic object
            for (int i = 0; i < node.ChildNodes.Count; i++)
            {
                if (System.String.Compare(node.ChildNodes[i].Name, GOM_TAGS.POINTS, true) == 0)
                {
                    primitive.UpdatePoints(node.ChildNodes[i]);
                }
                if (System.String.Compare(node.ChildNodes[i].Name, GOM_TAGS.STYLES, true) == 0)
                {
                    primitive.UpdateStyles(node.ChildNodes[i]);
                }
                if (System.String.Compare(node.ChildNodes[i].Name, GOM_TAGS.TEXT, true) == 0)
                {
                    primitive.LoadText(node.ChildNodes[i]);
                }
                #region new_modfied
                //Load attribute
                if (System.String.Compare(node.ChildNodes[i].Name, "attribute", true) == 0)
                {
                    for (int j = 0; j < node.ChildNodes[i].ChildNodes.Count; j++)
                    {
                        primitive.LoadVarFromXML(node.ChildNodes[i].ChildNodes[j], j);
                    }
                }
                //Load restrictions
                if (System.String.Compare(node.ChildNodes[i].Name, "restrictions", true) == 0)
                {
                    for (int j = 0; j < node.ChildNodes[i].ChildNodes.Count; j++)
                    {
                        primitive.LoadRestrictionFromXML(node.ChildNodes[i].ChildNodes[j], j);
                    }
                }
                #endregion
            }

            return primitive;
        }