public override void OnMouseUp(int x, int y) { Point scrollOffset = Ctrl.ScrollOffset; Point startPoint = Ctrl.PointToScreen(new Point(startMouseX - scrollOffset.X + 20, startMouseY - scrollOffset.Y + 20)); ControlPaint.DrawReversibleLine(startPoint, Ctrl.PointToScreen(new Point(endMouseX - scrollOffset.X + 20, endMouseY - scrollOffset.Y + 20)), Color.Black); HitTestResult end = Ctrl.Document.HitTest(x, y); if ((end == null) || (!(end.activity is BaseActivity))) { MessageBox.Show("流向没有结束在节点上"); } else if (end.activity is StartActivity) { MessageBox.Show("流向不能结束于开始节点"); } else { LineActivity line = new LineActivity(startActivity, end.activity as BaseActivity); line.AlignToGrid(); this.Ctrl.Document.ActivityList.Add(line); this.Ctrl.Document.Lines.Add(line); } Ctrl.RedrawAll(); Ctrl.CurrentTool = new SelectorTool(); }
public IList <Activity> DeleteSelected() { IList <Activity> result = new List <Activity>(); foreach (Activity activity in ActivityList) { if (activity.IsSelected) { result.Add(activity); } else { if (activity is LineActivity) { LineActivity line = activity as LineActivity; if (line.Source.IsSelected || line.Target.IsSelected) { result.Add(activity); } } } } foreach (Activity activity in result) { ActivityList.Remove(activity); } return(result); }
BaseActivity GetNextActivity(BaseActivity currActivity, out LineActivity nextLine) { foreach (Activity act in _document.ActivityList) { if (act is LineActivity && (act as LineActivity).Source.ID == currActivity.ID) { nextLine = act as LineActivity; return((act as LineActivity).Target); } } nextLine = null; return(null); }
public void CreateXml(XmlElement xmlElement) { XmlElement processElement = xmlElement.OwnerDocument.CreateElement("process"); XmlAttribute attr = xmlElement.OwnerDocument.CreateAttribute("id"); attr.Value = _id; processElement.Attributes.Append(attr); attr = xmlElement.OwnerDocument.CreateAttribute("description"); attr.Value = _description; processElement.Attributes.Append(attr); XmlElement actsElement = processElement.OwnerDocument.CreateElement("activities"); processElement.AppendChild(actsElement); foreach (Activity activity in _activities) { if (!(activity is LineActivity)) { BaseActivity act = activity as BaseActivity; act.CreateXml(actsElement); } } XmlElement linesElement = processElement.OwnerDocument.CreateElement("lines"); processElement.AppendChild(linesElement); foreach (Activity activity in _activities) { if (activity is LineActivity) { LineActivity line = activity as LineActivity; line.CreateXml(linesElement); } } xmlElement.AppendChild(processElement); }
public void CreateProcess() { XmlNodeList activityNodes = _layout.SelectNodes("process/activities/activity"); List <BaseActivity> activities = new List <BaseActivity>(); foreach (XmlNode activityNode in activityNodes) { BaseActivity activity = null; string type = activityNode.Attributes["type"].Value; int x = Convert.ToInt32(activityNode.Attributes["x"].Value); int y = Convert.ToInt32(activityNode.Attributes["y"].Value); decimal time = 0; if (null != activityNode.Attributes["time"]) { time = Convert.ToDecimal(activityNode.Attributes["time"].Value); } switch (type) { case "0": activity = new StartActivity(x, y); break; case "1": activity = new EndActivity(x, y); break; case "2": activity = new ManualActivity(x, y); (activity as ManualActivity).Time = time; //roles XmlNodeList roleNodes = activityNode.SelectNodes("roles/role"); if (null != roleNodes && roleNodes.Count > 0) { List <SYS_BUSINESSROLE> roles = new List <SYS_BUSINESSROLE>(); foreach (XmlNode node in roleNodes) { SYS_BUSINESSROLE role = new SYS_BUSINESSROLE(); role.ID = Convert.ToInt32(node.Attributes["id"].Value); role.ROLENAME = node.Attributes["name"].Value; role.Selected = Convert.ToInt32(node.Attributes["selected"].Value); roles.Add(role); } (activity as ManualActivity).Roles = roles; } //forms XmlNodeList formNodes = activityNode.SelectNodes("forms/form"); if (null != formNodes && formNodes.Count > 0) { List <SYS_BUSINESSFORM> forms = new List <SYS_BUSINESSFORM>(); foreach (XmlNode node in formNodes) { SYS_BUSINESSFORM form = new SYS_BUSINESSFORM(); form.ID = Convert.ToInt32(node.Attributes["id"].Value); form.FORMNAME = node.Attributes["name"].Value; form.Checked = Convert.ToInt32(node.Attributes["checked"].Value); forms.Add(form); } (activity as ManualActivity).Forms = forms; } break; default: break; } if (activity != null) { activity.ID = activityNode.Attributes["id"].Value; activity.Description = activityNode.Attributes["description"].Value; activity.X = x; activity.Y = y; document.ActivityList.Add(activity); activities.Add(activity); } } XmlNodeList lineNodes = _layout.SelectNodes("process/lines/line"); foreach (XmlNode lineNode in lineNodes) { int x = Convert.ToInt32(lineNode.Attributes["x"].Value); int y = Convert.ToInt32(lineNode.Attributes["y"].Value); string sourceId = lineNode.Attributes["source"].Value; string targetId = lineNode.Attributes["target"].Value; BaseActivity source = null; BaseActivity target = null; foreach (BaseActivity act in activities) { if (act.ID == sourceId) { source = act; continue; } if (act.ID == targetId) { target = act; continue; } } LineActivity activity = new LineActivity(source, target); if (activity != null) { activity.ID = lineNode.Attributes["id"].Value; activity.Description = lineNode.Attributes["description"].Value; activity.X = x; activity.Y = y; document.Lines.Add(activity); document.ActivityList.Add(activity); } } }
private void cmsiArrange_Click(object sender, EventArgs e) { StartActivity startActivity = null; foreach (Activity act in _document.ActivityList) { if (act is BaseActivity) { BaseActivity bAct = act as BaseActivity; if (bAct.GetActivityType() == "0") { startActivity = bAct as StartActivity; } } } LineActivity nextLine = null; BaseActivity nextActivity = null; BaseActivity currActivity = startActivity; int i = 1; string direction = "right"; while ((nextActivity = GetNextActivity(currActivity, out nextLine)) != null) { if (i % 4 == 0) { if (direction == "right") { direction = "left"; } else { direction = "right"; } nextLine.X = currActivity.X; nextLine.Y = currActivity.Y + 50; nextActivity.X = currActivity.X; nextActivity.Y = currActivity.Y + 100; currActivity = nextActivity; } else { if (direction == "right") { nextLine.X = currActivity.X + 100; nextLine.Y = currActivity.Y; nextActivity.X = currActivity.X + 200; nextActivity.Y = currActivity.Y; currActivity = nextActivity; } else { nextLine.X = currActivity.X - 100; nextLine.Y = currActivity.Y; nextActivity.X = currActivity.X - 200; nextActivity.Y = currActivity.Y; currActivity = nextActivity; } } i++; } RedrawAll(); }