/// <summary> /// Add a template into the list /// </summary> /// <param name="val">The template being stored</param> public void Add(GOM_Template val) { rgTemplates.Add(val); }
/// <summary> /// Create a template object from an XML tree /// </summary> /// <param name="node">The root node of the XML tree</param> /// <returns>If successful, a graphic object template is returned. Otherwise, an exception will be thrown out.</returns> private static GOM_Template CreateTemplateFromXML(System.Xml.XmlNode node) { if (System.String.Compare(node.Name, GOM_TAGS.GRAPHIC_TEMPLATE) != 0) { throw new Exception("Invalid input. Not a graphic template node!"); } GOM_Template template = new GOM_Template(); template.LoadFromXML(node, null); return template; }
/// <summary> /// Initialize the graphic object according to a given template /// </summary> /// <param name="template"></param> public void InitializeFromTemplate(GOM_Template template) { //Initialize property this.m_template = template; this.extConnect = template.extConnect; this.extRotate = template.extRotate; this.extScale = template.extScale; this.keepAspectRatio = template.keepAspectRatio; //Clear up existing data this.rgPoints.Clear(); this.rgFillings.Clear(); this.rgDrawings.Clear(); this.rgEditingModes.Clear(); this.rgDrawingStyles.Clear(); this.rgFillingStyles.Clear(); //Initialize editing mode for (int i = 0; i < template.rgEditingModes.Count; i++) { this.rgEditingModes.Add(template.rgEditingModes[i]); } //Initialize drawing styles for (int i = 0; i < template.rgDrawingStyles.Count; i++) { GOM_Style_Drawing style; style = new GOM_Style_Drawing(); style.id = template.rgDrawingStyles[i].id; style.drawingStyle = (System.Drawing.Pen)template.rgDrawingStyles[i].drawingStyle.Clone(); this.rgDrawingStyles.Add(style); } //Initialize filling styles for (int i = 0; i < template.rgFillingStyles.Count; i++) { GOM_Style_Filling style; style = new GOM_Style_Filling(); style.id = template.rgFillingStyles[i].id; style.fillingStyle = (System.Drawing.Brush)template.rgFillingStyles[i].fillingStyle.Clone(); this.rgFillingStyles.Add(style); } //Initialize basic properties of points for (int i = 0; i < template.rgPoints.Count; i++) { GOM_Point pt; pt = new GOM_Point(); pt.id = template.rgPoints[i].id; pt.x = template.rgPoints[i].x; pt.y = template.rgPoints[i].y; pt.Connectable = template.rgPoints[i].Connectable; pt.Controllable = template.rgPoints[i].Controllable; this.rgPoints.Add(pt); } //Initialize drawing operations for (int i = 0; i < template.rgDrawings.Count; i++) { rgDrawings.Add(CloneDrawing(template.rgDrawings[i])); } //Initialize filling operations for (int i = 0; i < template.rgFillings.Count; i++) { rgFillings.Add(CloneFilling(template.rgFillings[i])); } //Initialize constraints of points for (int i = 0; i < template.rgPoints.Count; i++) { for (int j = 0; j < template.rgPoints[i].Constraints.Count; j++) { GOM_Constraint_Set constraintSet; constraintSet = new GOM_Constraint_Set(); for (int k = 0; k < template.rgPoints[i].Constraints[j].Count; k++) { constraintSet.Add(CloneConstraint(template.rgPoints[i].Constraints[j][k])); } rgPoints[i].Constraints.Add(constraintSet); } } CalculateBoundingBox(); //from template #region new_modified if (template.var_list != null) { var_list = template.var_list.clone(); } if (template.res_list != null) { res_list = template.res_list.clone(); } #endregion }
public void LoadFromXML(System.Xml.XmlNode node, GOM_ResourceArrays resources) { GOM_Utility.VerifyXmlNode(node, GOM_TAGS.GRAPHIC_OBJECT); //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) { 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) { m_xOffset = float.Parse(node.Attributes[i].Value); } if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.Y_OFFSET, true) == 0) { m_yOffset = float.Parse(node.Attributes[i].Value); } if (System.String.Compare(node.Attributes[i].Name, GOM_TAGS.ROTATION, true) == 0) { 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 < resources.Templates.Count; j++) { if (resources.Templates[j].id.Equals(node.Attributes[i].Value)) { m_template = resources.Templates[j]; } } if (m_template == null) { throw new Exception("Unknown template"); } } } if (m_template == null) { throw new Exception("Can not find template of the graphic object"); } //Initialize the graphic object according to the template InitializeFromTemplate(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) { UpdatePoints(node.ChildNodes[i]); } if (System.String.Compare(node.ChildNodes[i].Name, GOM_TAGS.STYLES, true) == 0) { UpdateStyles(node.ChildNodes[i]); } if (System.String.Compare(node.ChildNodes[i].Name, GOM_TAGS.TEXT, true) == 0) { 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++) { 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++) { LoadRestrictionFromXML(node.ChildNodes[i].ChildNodes[j], j); } } #endregion } CalculateBoundingBox(); SynchronizeConnectorPosition(); }
/// <summary> /// The constructor of GOM_Object_Primitive /// </summary> public GOM_Object_Primitive() { m_id = Guid.NewGuid().ToString("D"); m_xOffset = 0; m_yOffset = 0; m_rotation = 0; m_template = null; GOM_Constraint_Set constraintSet; m_boundingBox = new System.Drawing.RectangleF(0, 0, 0, 0); m_Top_Connector = new GOM_Point(); m_Top_Connector.id = GOM_Special_Point_Name.TOP_CONNECTOR; m_Top_Connector.Connectable = true; m_Bottom_Connector = new GOM_Point(); m_Bottom_Connector.id = GOM_Special_Point_Name.BOTTOM_CONNECTOR; m_Bottom_Connector.Connectable = true; m_Left_Connector = new GOM_Point(); m_Left_Connector.id = GOM_Special_Point_Name.LEFT_CONNECTOR; m_Left_Connector.Connectable = true; m_Right_Connector = new GOM_Point(); m_Right_Connector.id = GOM_Special_Point_Name.RIGHT_CONNECTOR; m_Right_Connector.Connectable = true; m_SE_Resize_Point = new GOM_Point(); m_SE_Resize_Point.id = GOM_Special_Point_Name.SE_RESIZING_POINT; constraintSet = new GOM_Constraint_Set(); constraintSet.EditingMode = "default"; constraintSet.Add(new GOM_Resizing_SE_Constraint(this, m_SE_Resize_Point)); m_SE_Resize_Point.Constraints.Add(constraintSet); m_NW_Resize_Point = new GOM_Point(); m_NW_Resize_Point.id = GOM_Special_Point_Name.NW_RESIZING_POINT; constraintSet = new GOM_Constraint_Set(); constraintSet.EditingMode = "default"; constraintSet.Add(new GOM_Resizing_NW_Constraint(this, m_NW_Resize_Point)); m_NW_Resize_Point.Constraints.Add(constraintSet); m_SW_Resize_Point = new GOM_Point(); m_SW_Resize_Point.id = GOM_Special_Point_Name.SW_RESIZING_POINT; constraintSet = new GOM_Constraint_Set(); constraintSet.EditingMode = "default"; constraintSet.Add(new GOM_Resizing_SW_Constraint(this, m_SW_Resize_Point)); m_SW_Resize_Point.Constraints.Add(constraintSet); m_NE_Resize_Point = new GOM_Point(); m_NE_Resize_Point.id = GOM_Special_Point_Name.NE_RESIZING_POINT; constraintSet = new GOM_Constraint_Set(); constraintSet.EditingMode = "default"; constraintSet.Add(new GOM_Resizing_NE_Constraint(this, m_NE_Resize_Point)); m_NE_Resize_Point.Constraints.Add(constraintSet); m_Rotation_Point = new GOM_Point(); m_Rotation_Point.id = GOM_Special_Point_Name.ROTATION_POINT; constraintSet = new GOM_Constraint_Set(); constraintSet.EditingMode = "default"; constraintSet.Add(new GOM_Rotation_Constraint(this, m_Rotation_Point)); m_Rotation_Point.Constraints.Add(constraintSet); innerText = ""; font = new System.Drawing.Font("Tahoma", 10); fontColor = System.Drawing.Color.Black; extScale = false; extRotate = false; extConnect = false; keepAspectRatio = false; rgPoints = new GOM_Points(); rgDrawings = new GOM_Drawings(); rgFillings = new GOM_Fillings(); rgEditingModes = new GOM_Strings(); rgDrawingStyles = new GOM_Drawing_Styles(); rgFillingStyles = new GOM_Filling_Styles(); }