/// <summary> /// 从文件加载一个属性 /// </summary> /// <param name="xt">属性类型</param> /// <param name="xs">属性的集合类型</param> /// <param name="xp">复制匡的位置是在左边还是右边</param> /// <param name="paramterName">属性名称</param> /// <param name="clt">连接方式</param> /// <param name="tiptext">提示信息</param> /// <param name="LastExName">属性类型</param> /// <param name="id">属性框ID</param> /// <param name="opentype">公开类型</param> public XAribute LoadXAribute(XAribute.XAttributeType xt, XAribute.XAttributeSpec xs, XAribute.XPositonStyle xp, string paramterName, XAribute.CanLinkType clt, string tiptext, string LastExName, int id, OpenType opentype) { XAribute xb = new XAribute(id, paramterName, xt, xs, xp, this.ChileEventCallBack, clt, LastExName); xb.Hint = tiptext; xb.MyOpenType = opentype; ///绑定标题改变事件 xb.TitleChange += (e, o, v) => { ///修改Title return(ModifyPropertyTitle(o, v)); }; xb.ExNameChange += (s, o, v) => { ///修改ExName this.ModifyPropetyExName((s as XAribute).Title, v); }; ///检测是否存在 if (!ListXAributes.Contains(xb)) { ListXAributes.Add(xb); return(xb); } return(null); }
/// <summary> /// 初始化基本信息 /// </summary> protected override void InitBaseInfo() { base.InitBaseInfo(); ///创建函数入口代码块 FunctionEnterBox = CreateXCodeBox("方法入口", CenterPoint, CodeBox.XAType.XFunctionEnter); FunctionEnterBox.OpenButton = 2; FunctionEnterBox.AddXExcXAribute(); FunctionEnterBox.XAributeChangeMessage = () => { XAributeChangeMessage(this); };///属性消息变更通知 ///创建函数出口代码块 CodeBox functionExc = CreateXCodeBox("方法出口", new Point(CenterPoint.X + 250, CenterPoint.Y), CodeBox.XAType.XFunctionExc); functionExc.OpenButton = 1; functionExc.AddXEnterXAribute(); functionExc.XAributeChangeMessage = () => { XAributeChangeMessage(this); };///属性消息变更通知 ///保存函数出口代码块的地址 FunctionExcBox = functionExc; ///添加初始连线 XAribute FirstXa = FunctionEnterBox.GetRightExc()[0]; XAribute SecondXa = functionExc.GetLeftEnter(); BezierLine MyBezierLine = new BezierLine(CreateBezierID(), FirstXa.BorderColor, FirstXa.GetWorldPosition(), FirstXa.SelectPositionStyle); AddBezierLine(MyBezierLine); FirstXa.AddBezierLine(MyBezierLine); MyBezierLine.StartPoint.LinkAribute = FirstXa; SecondXa.AddBezierLine(MyBezierLine); MyBezierLine.EndPoint.LinkAribute = SecondXa; MyBezierLine.SetBezierLine(SecondXa.GetWorldPosition(), SecondXa.SelectPositionStyle); }
/// <summary> /// 创建一个类的属性 /// </summary> /// <param name="Title">属性名称</param> /// <returns>是否成功创建</returns> public bool CreatePicXAribute(string Title) { foreach (XAribute xb in ListXAributes) { if (xb.Title == Title) { return(false); } } XAribute bute = new XAribute(1, Title, XAribute.XAttributeType.XBool, XAribute.XAttributeSpec.XNone, XAribute.XPositonStyle.Left, this.ChileEventCallBack, XAribute.CanLinkType.One, "bool"); ///将类设置为属性的父控件 bute.ParentControl = this; ///当ExName改变的时候 bute.ExNameChange = (s, o, v) => { ///修改ExName ModifyPropetyExName((s as XAribute).Title, v); }; ///绑定标题改变事件 bute.TitleChange += (e, o, v) => { ///修改Title return(ModifyPropertyTitle(o, v)); }; ListXAributes.Add(bute); ///回调 if (MessageUpdateCall != null) { MessageUpdateCall(bute, MouseState.XUpdatePropertyData); } return(true); }
/// <summary> /// 修改属性ExName的值 /// </summary> /// <param name="title">要被修改的属性的Title值</param> /// <param name="newVlaue">ExName的新值</param> /// <returns></returns> public bool ModifyPropetyExName(string title, string newVlaue) { ///循环所有代码块 foreach (CodeBox box in ListCodeBoxChild.Values) { if (box.CodeBoxType == CodeBox.XAType.set) { XAribute leftbute = box.LeftAribute.Children[1] as XAribute; XAribute rightbute = box.RightAribute.Children[1] as XAribute; if (leftbute != null && leftbute.Title == title) { leftbute.ExName = newVlaue; rightbute.ExName = newVlaue; } } else if (box.CodeBoxType == CodeBox.XAType.get && box.RightAribute.Children.Count > 0) { XAribute rightbute = box.RightAribute.Children[0] as XAribute; if (rightbute != null && rightbute.Title == title) { rightbute.ExName = newVlaue; } } } return(true); }
/// <summary> /// 当鼠标离开的时候 /// </summary> /// <param name="e"></param> protected override void OnMouseLeave(MouseEventArgs e) { #region 对贝塞尔曲线的处理 if (MyBezierLine != null) { ///删除失败的贝塞尔曲线 DelBezierLine(MyBezierLine); #region 初始化信息 FirstXa = null; SecondXa = null; isOverAribute = false; isDrawBezier = false; SecondXa = null; #endregion } #endregion #region 自身移动初始化 IsMove = false; IsStartMove = false; #endregion #region 取消框选 MyPanel.IsToSelect = false; #endregion #region 焦点控制 ///释放鼠标焦点 this.ReleaseMouseCapture(); #endregion }
/// <summary> /// 子控件事件回调处理 /// </summary> /// <param name="sender"></param> /// <param name="ms"></param> protected virtual object ChileEventCallBack(Object sender, MouseState ms, XObjectData data = null) { switch (ms) { case MouseState.XUpdatePropertyData: XAribute bute = sender as XAribute; if (bute != null) { //更新数据 bute.ProjectUseClassType = ProjectUseClassType; } break; case MouseState.XUpdateTreeViewData: PicTabPage page = sender as PicTabPage; if (page != null && (data.data as PicFunctionTabPage) != null) { MessageOption option = XObject.MessageOptionTypeMapping(data.additional_Information.ToString()); if (option == MessageOption.Add) { ///更新函数 AddPicFunctionToPicData(page, data.data as PicFunctionTabPage); } else if (option == MessageOption.Update) { UpdatePicFunctionToPicData(page, data.data as PicFunctionTabPage); } } break; } return(null); }
/// <summary> /// 组装读取的数据 /// </summary> /// <param name="RootTreeItem">根节点数据</param> /// <param name="root">根节点XML</param> protected void LoadData(MyXTreeItem RootTreeItem, XmlNode root) { ///检查是否已经存在 foreach (XmlNode node in root.SelectNodes("CodeBox")) { XmlElement codeNode = (XmlElement)node; MyXTreeItem RetreeItem = new MyXTreeItem(); RetreeItem.IsSelected = false; RetreeItem.IsExpanded = false; RetreeItem.XName = codeNode.GetAttribute("Name"); RetreeItem.MyHitText = codeNode.GetAttribute("HitText"); RetreeItem.MyCodeBoxType = CodeBox.CodeBoxTypeMapping(codeNode.GetAttribute("CodeBoxType")); RetreeItem.SystemCodeString = codeNode.GetAttribute("SystemCodeString"); RetreeItem.ReturnValue = codeNode.GetAttribute("ReturnValue"); foreach (XmlNode xNode in codeNode.SelectNodes("XAribute")) { ///MyXTreeItem的子项 XAributeItem xaItem = new XAributeItem(); ///将内容提出填装 XmlElement xaNode = (XmlElement)xNode; xaItem.Parameter_name = xaNode.GetAttribute("Name"); xaItem.MyXAttributeType = XAribute.XAttributeTypeMapping(((XmlElement)xaNode.SelectSingleNode("PointTypeitem")).InnerText); xaItem.MyXAttributeSpec = XAribute.XAttributeSpecMapping(((XmlElement)xaNode.SelectSingleNode("ListTypeitem")).InnerText); xaItem.MyXPositonStyle = XAribute.XPositonStyleMapping(((XmlElement)xaNode.SelectSingleNode("PositionTypeitem")).InnerText); xaItem.MyCanLinkType = XAribute.CanLinkTypeMapping(((XmlElement)xaNode.SelectSingleNode("LinkTypeitem")).InnerText); xaItem.MyHittext = ((XmlElement)xaNode.SelectSingleNode("TipTypeitem")).InnerText; xaItem.MyLastExText = ((XmlElement)xaNode.SelectSingleNode("LastExTexteitem")).InnerText; ///添加到子项中 RetreeItem.MyXaributeChildren.Add(xaItem); } ///添加子节点 RootTreeItem.ChildrenItem.Add(RetreeItem); } }
/// <summary> /// 当添加一个子控件控制时候 /// </summary> protected override void AddChildControlMsg(Object sender) { base.AddChildControlMsg(); if (sender.GetType().Name == "XAribute") { _controlXAtribute = (XAribute)sender; } }
/// <summary> /// 构造函数 /// </summary> /// <param name="bute">项</param> public XAributeItem(XAribute bute) { this.Parameter_name = bute.Title; this.MyCanLinkType = bute.CanLinkNum; this.MyXAttributeSpec = bute.SelectSpc; this.MyXAttributeType = bute.SelectType; this.MyXPositonStyle = bute.SelectPositionStyle; this.MyHittext = bute.Hint; this.MyLastExText = bute.ExName; }
/// <summary> /// 更换绑定数据 /// </summary> /// <param name="bute">要更换的绑定数据</param> /// <param name="data">所有类型数据</param> public void ChangeBindingData(XAribute bute, List <string> data) { BindingData = bute; #region 初始化信息 InitOpenType(); InitProType(data); InitListType(); InitHintText(); #endregion }
/// <summary> /// 直接设置贝塞尔曲线的2个点 /// </summary> /// <param name="start">起始位置</param> /// <param name="end">终止位置</param> public void DirectSetBezierLineTwoPoint(XAribute start, XAribute end) { StartPoint.LinkAribute = start; StartPoint.position = start.GetWorldPosition(); StartPoint.positionType = start.SelectPositionStyle; EndPoint.LinkAribute = end; EndPoint.position = end.GetWorldPosition(); EndPoint.positionType = end.SelectPositionStyle; InitLineInformation(); }
/// <summary> /// 解析类的属性 /// </summary> /// <param name="bute">属性</param> /// <returns>返回解析完的字符串</returns> protected string AnalyticalXAribute(XAribute bute, bool isMain = false) { string codeString = XObject.GetOpenTypeCodeString(bute.MyOpenType); if (isMain) { codeString += " static "; } codeString += bute.ExName + " " + bute.Title + ";"; return(codeString); }
/// <summary> /// 删除一个类的属性 /// </summary> /// <param name="butefile">要删除的数据对象</param> /// <returns>是否成功操作</returns> public bool DelXAribute(XAribute bute) { if (!ListXAributes.Contains(bute)) { return(false); } else { ListXAributes.Remove(bute); return(true); } }
/// <summary> /// 事件派送前的鼠标左击事件 /// </summary> /// <param name="sender">信息发送员</param> /// <param name="e">消息</param> private void XAributeListBox_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (XAributeListBox.SelectedIndex != -1) { XAribute item = (sender as ListBox).SelectedItem as XAribute; if (item != null) { ///打包数据 DataObject data = new DataObject(item); DragDrop.DoDragDrop(item, data, DragDropEffects.Copy); } } }
/// <summary> /// 删除一个子控件 /// </summary> /// <param name="addchild"></param> public void DelXAbutrite(XAribute addchild) { try { MyPanel.Children.Remove(addchild); ///修改尺寸 AutoSize(); } catch (Exception ex) { LoggerHelp.WriteLogger(ex.ToString()); } }
/// <summary> /// 添加一个子控件 /// </summary> /// <param name="addchild"></param> public void AddXAbutrite(XAribute addchild) { Children.Add(addchild); ///由于设置了布局流向所以方向相反 if (this.Position == PositonType.Left) { addchild.HorizontalAlignment = HorizontalAlignment.Left; } else { addchild.HorizontalAlignment = HorizontalAlignment.Left; } }
/// <summary> /// 根据ID获取代码块中的XAribute /// </summary> /// <param name="ID">XAribute的ID</param> /// <returns>寻找到的XAribute没找到则为null</returns> protected XAribute GetXAributeByID(int ID, int fatherID) { foreach (CodeBox box in ListCodeBoxChild.Values) { if (box.Id == fatherID) { XAribute rebute = box.GetXAributeByID(ID); if (rebute != null) { return(rebute); } } } return(null); }
/// <summary> /// 判断一个属性的值是否需要保存 /// </summary> /// <param name="bute">要确认的属性</param> /// <returns>是否需要</returns> private static bool ISXAributeToSaveValue(XAribute node) { if (node.SelectType == XAribute.XAttributeType.XString || node.SelectType == XAribute.XAttributeType.XInt || node.SelectType == XAribute.XAttributeType.XFloat || node.SelectType == XAribute.XAttributeType.XDouble || node.SelectType == XAribute.XAttributeType.XChar) { if (node.GetMyBeziers.Count == 0) { return(true); } else { return(false); } } return(false); }
/// <summary> /// 修改尺寸和调整个控件的位置 /// </summary> public override void AutoSize() { double hei = 0; double wid = 0; for (int i = 0; i < MyPanel.Children.Count; i++) { XAribute xa = ((XAribute)MyPanel.Children[i]); hei += xa.Height + DisHeigth; double centerWidth = 0; centerWidth = xa.Width; wid = wid < centerWidth ? centerWidth : wid; } this.Height = hei; this.Width = wid; }
/// <summary> /// 读取XML中的属性内容 /// </summary> /// <param name="aribute">包含属性的XML节点</param> /// <param name="box">属性所在的CodeBox对象</param> /// <returns></returns> public static void ReadXAributeObject(XmlNode node, PicTabPage pic) { XmlElement aributeElement = (XmlElement)node; int Id = int.Parse(aributeElement.GetAttribute("ID")); string Title = aributeElement.GetAttribute("Title"); XAribute.XAttributeType SelectType = XAribute.XAttributeTypeMapping(aributeElement.GetAttribute("PointTypeitem")); XAribute.XAttributeSpec SelectSpc = XAribute.XAttributeSpecMapping(aributeElement.GetAttribute("ListTypeitem")); XAribute.XPositonStyle SelectPositionStyle = XAribute.XPositonStyleMapping(aributeElement.GetAttribute("PositionTypeitem")); XAribute.CanLinkType CanLinkNum = XAribute.CanLinkTypeMapping(aributeElement.GetAttribute("LinkTypeitem")); string Hint = aributeElement.GetAttribute("TipTypeitem"); string ExName = aributeElement.GetAttribute("LastExTexteitem"); XObject.OpenType opentype = XObject.OpenTypeMapping(aributeElement.GetAttribute("OpenType")); ///通过内置函数加载属性 XAribute bute = pic.LoadXAribute(SelectType, SelectSpc, SelectPositionStyle, Title, CanLinkNum, Hint, ExName, Id, opentype); }
/// <summary> /// 修改Title属性的值 /// </summary> /// <param name="forntName">修改前的名字</param> /// <param name="nowName">修改后的名字</param> /// <returns></returns> public bool ModifyPropertyTitle(string forntName, string newName) { ///检测名称是否可以使用 foreach (XAribute bute in ListXAributes) { if (newName == bute.Title) { return(false); } } ///修改代码块内部的属性名称 foreach (CodeBox box in ListCodeBoxChild.Values) { ///如果是get类型 if (box.CodeBoxType == CodeBox.XAType.get) { ///获取get类型代码块右边属性的第一个 XAribute bute = box.RightAribute.Children[0] as XAribute; ///如果该代码块的是改类的属性的话 if (bute != null && bute.Title == forntName) { bute.Title = newName; box.Title = box.Title.Replace(forntName, newName); } } ///如果是set类型 else if (box.CodeBoxType == CodeBox.XAType.set) { ///获取get类型代码块左边边属性的第一个 XAribute lefttbute = box.LeftAribute.Children[1] as XAribute; ///获取get类型代码块右边属性的第一个 XAribute rightbute = box.RightAribute.Children[1] as XAribute; ///如果是该类的属性的话 if (lefttbute != null && rightbute != null && lefttbute.Title == forntName) { ///修改属性的名称和值 lefttbute.Title = newName; rightbute.Title = newName; box.Title = box.Title.Replace(forntName, newName); } } } return(true); }
/// <summary> /// 写入属性 /// </summary> /// <param name="writer">XML写入对象</param> /// <param name="node">XAribute对象</param> public static void WriteXAribute(XmlTextWriter writer, XAribute node) { writer.WriteStartElement("XAribute"); writer.WriteAttributeString("ID", node.Id.ToString()); writer.WriteAttributeString("Title", node.Title); writer.WriteAttributeString("PointTypeitem", node.SelectType.ToString()); writer.WriteAttributeString("ListTypeitem", node.SelectSpc.ToString()); writer.WriteAttributeString("PositionTypeitem", node.SelectPositionStyle.ToString()); writer.WriteAttributeString("LinkTypeitem", node.CanLinkNum.ToString()); writer.WriteAttributeString("TipTypeitem", node.Hint); writer.WriteAttributeString("LastExTexteitem", node.ExName); writer.WriteAttributeString("OpenType", node.MyOpenType.ToString()); if (ISXAributeToSaveValue(node)) { writer.WriteElementString("Value", node.GetValueTextBox()); } /// 关闭XAribute元素节点 writer.WriteEndElement(); }
/// <summary> /// 从文件读取的时候添加一个贝塞尔曲线 /// </summary> /// <param name="bz">贝塞尔曲线对象</param> public bool ReadCreateBezierLine(BezierLine bz, int startID, int endID, int startfatherID, int endfatherID) { XAribute startPoint = GetXAributeByID(startID, startfatherID); XAribute endPoint = GetXAributeByID(endID, endfatherID); if (startPoint != null && endPoint != null) { startPoint.AddBezierLine(bz); endPoint.AddBezierLine(bz); ///设置贝塞尔曲线信息 bz.DirectSetBezierLineTwoPoint(startPoint, endPoint); ///将贝塞尔曲线添加入显示 AddBezierLine(bz); return(true); } else { return(false); } }
/// <summary> /// 鼠标抬起的时候 /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); ///释放鼠标焦点 this.ReleaseMouseCapture(); #region 取消框选 MyPanel.IsToSelect = false; #endregion #region 对贝塞尔曲线的操作 ///成功连接 if (isDrawBezier && isOverAribute && SecondXa != null && SecondXa.IsCanLin(FirstXa)) { #region 将属性和连线的关系赋值 FirstXa.AddBezierLine(MyBezierLine); MyBezierLine.StartPoint.LinkAribute = FirstXa; SecondXa.AddBezierLine(MyBezierLine); MyBezierLine.EndPoint.LinkAribute = SecondXa; MyBezierLine.SetBezierLine(SecondXa.GetWorldPosition(), SecondXa.SelectPositionStyle); #endregion } ///失败连接 else if (isDrawBezier) { ///删除失败的贝塞尔曲线 DelBezierLine(MyBezierLine); } ///清空贝塞尔曲线对象,防止对此的再次操作 if (MyBezierLine != null) { MyBezierLine = null; #region 初始化信息 FirstXa = null; SecondXa = null; isOverAribute = false; isDrawBezier = false; SecondXa = null; #endregion } #endregion }
/// <summary> /// 读取XML中的属性内容 /// </summary> /// <param name="aribute">包含属性的XML节点</param> /// <param name="box">属性所在的CodeBox对象</param> /// <returns></returns> public static void ReadXAributeObject(XmlNode node, CodeBox box) { XmlElement aributeElement = (XmlElement)node; int Id = int.Parse(aributeElement.GetAttribute("ID")); string Title = aributeElement.GetAttribute("Title"); XAribute.XAttributeType SelectType = XAribute.XAttributeTypeMapping(aributeElement.GetAttribute("PointTypeitem")); XAribute.XAttributeSpec SelectSpc = XAribute.XAttributeSpecMapping(aributeElement.GetAttribute("ListTypeitem")); XAribute.XPositonStyle SelectPositionStyle = XAribute.XPositonStyleMapping(aributeElement.GetAttribute("PositionTypeitem")); XAribute.CanLinkType CanLinkNum = XAribute.CanLinkTypeMapping(aributeElement.GetAttribute("LinkTypeitem")); string Hint = aributeElement.GetAttribute("TipTypeitem"); string ExName = aributeElement.GetAttribute("LastExTexteitem"); XObject.OpenType opentype = XObject.OpenTypeMapping(aributeElement.GetAttribute("OpenType")); ///通过内置函数加载属性 XAribute bute = box.LoadAttribute(SelectType, SelectSpc, SelectPositionStyle, Title, CanLinkNum, Hint, ExName, Id, opentype); if (bute != null && ISXAributeToSaveValue(bute)) { bute.SetValueTextBox(aributeElement.GetAttribute("Value")); } }
/// <summary> /// 解析前的一些判断 /// </summary> /// <param name="bute">上一个代码块的出口节点</param> /// <returns></returns> protected string AnalyticalCenterTool(XAribute bute) { XAribute target = bute.GetOtherXAribute(); CodeBox targetBox = (CodeBox)target.ParentControl; ///代码块入口 XAribute targetBoxEnter = targetBox.GetLeftEnter(); if (target.SelectType == XAribute.XAttributeType.XBreak) { if (targetBoxEnter != null && targetBoxEnter.GetMyBeziers.Count > 0) { return("break;" + LineBreaks); } else { return(""); } } else if (target != null) { return(AnalyticalNormal(targetBox)); } return(""); }
/// <summary> /// 当一个子控件退出控制的时候 /// </summary> /// <param name="sender"></param> protected override void DelChildControlMsg(object sender = null) { base.DelChildControlMsg(sender); _controlXAtribute = null; }
/// <summary> /// 读取XML中的贝塞尔曲线内容 /// </summary> /// <param name="beziernode"></param> /// <param name="pic"></param> public static void ReadBezierLine(XmlNode beziernode, PicTabPage pic) { XmlElement bezierElement = (XmlElement)beziernode; int ID = int.Parse(bezierElement.GetAttribute("ID")); double StrokeThickness = double.Parse(bezierElement.GetAttribute("StrokeThickness")); ///读取起始点 XmlElement startPoint = (XmlElement)beziernode.SelectSingleNode("StartPoint"); BezierPoint readStartBezierPoint = new BezierPoint(); int startID = -1; int startfatherID = -1; foreach (XmlNode node in startPoint.ChildNodes) { XmlElement nodeElenemt = (XmlElement)node; switch (nodeElenemt.Name) { case "PositionType": readStartBezierPoint.positionType = XAribute.XPositonStyleMapping(nodeElenemt.InnerText); break; case "LinkAributeID": startID = int.Parse(nodeElenemt.InnerText); break; case "LinkAributeFatherID": startfatherID = int.Parse(nodeElenemt.InnerText); break; default: break; } } ///读取结束点 XmlElement endPoint = (XmlElement)beziernode.SelectSingleNode("EndPoint"); BezierPoint readEndBezierPoint = new BezierPoint(); int endID = -1; int endfatherID = -1; foreach (XmlNode node in endPoint.ChildNodes) { XmlElement nodeElenemt = (XmlElement)node; switch (nodeElenemt.Name) { case "PositionType": readEndBezierPoint.positionType = XAribute.XPositonStyleMapping(nodeElenemt.InnerText); break; case "LinkAributeID": endID = int.Parse(nodeElenemt.InnerText); break; case "LinkAributeFatherID": endfatherID = int.Parse(nodeElenemt.InnerText); break; default: break; } } BezierLine readBezierLine = new BezierLine(ID); readBezierLine.StartPoint = readStartBezierPoint; readBezierLine.EndPoint = readEndBezierPoint; pic.ReadCreateBezierLine(readBezierLine, startID, endID, startfatherID, endfatherID); }
/// <summary> /// 子控件事件回调处理 /// </summary> /// <param name="sender"></param> /// <param name="ms"></param> protected override object ChileEventCallBack(Object sender, MouseState ms, XObjectData data = null) { base.ChileEventCallBack(sender, ms); Type sendtype = sender.GetType(); switch (ms) { case MouseState.XClick: if (SelectIDList.Count <= 1 && sendtype.Name == "CodeBox") { SetChildControlState(((XObject)sender).Id); ///设置选中状态 } break; case MouseState.XDown: break; case MouseState.XToChildControl: AddChildControlMsg(sender); break; case MouseState.XToStopControl: DelChildControlMsg(); break; case MouseState.XToDrawBezier: isDrawBezier = true; FirstXa = (XAribute)sender; ///将发出信号的子控件 赋值 ///如果ALT键被按下则删除该节点上的曲线 if (_isPressingAlt) { FirstXa.ClearBezierLine(); } if (FirstXa != null) { MyBezierLine = new BezierLine(CreateBezierID(), FirstXa.BorderColor, FirstXa.GetWorldPosition(), FirstXa.SelectPositionStyle); AddBezierLine(MyBezierLine); } break; case MouseState.XMouseEnter: if (isDrawBezier) { if (sendtype.Name == "XAribute") { SecondXa = (XAribute)sender; ///将发出信号的子控件 赋值 if (SecondXa != FirstXa) { isOverAribute = true; } } } break; case MouseState.XMouseLeave: isOverAribute = false; break; case MouseState.XMoveControl: if (sendtype.Name == "CodeBox") { MoveSelectControl((Point)data.data, ((CodeBox)sender)); } break; case MouseState.XDelBezier: if (sendtype.Name == "XAribute" && data != null) { DelBezierLine((BezierLine)data.data); } break; case MouseState.XCreateCodeBox: #region 用户选择创建代码块 ///根据用户选择创建代码块 if (sendtype.Name == "XMTreeView") { MyXTreeItem mitem = (MyXTreeItem)data.data; CodeBox box = CreateXCodeBox(mitem.XName, _createBoxPosition, mitem.MyCodeBoxType); box.Hint = mitem.MyHitText; box.SystemCodeString = mitem.SystemCodeString; box.ReturnValueName = mitem.ReturnValue; for (int i = 0; i < mitem.MyXaributeChildren.Count; i++) { XAributeItem aItem = mitem.MyXaributeChildren[i]; box.AddAttribute(aItem.MyXAttributeType, aItem.MyXAttributeSpec, aItem.MyXPositonStyle, aItem.Parameter_name, aItem.MyCanLinkType, aItem.MyHittext, aItem.MyLastExText); } ///创建完成隐藏 HiddenPopup(); } #endregion #region 属性方式选择框的回调事件 ///如果是属性方式选择框的回调事件 else if (sendtype.Name == "XAributeDropSelect") { XAribute bute = data.data as XAribute; string type = data.state as string; ///如果数据没有丢失 if (bute != null && type != null) { if (type == "set") { CodeBox box = CreateXCodeBox("设置:" + bute.Title + " 的值", _createBoxPosition, CodeBox.XAType.set); box.Hint = "设置当前类中的这个属性的值,类型:" + bute.ExName; box.AddAttribute(XAribute.XAttributeType.XEnter, XAribute.XAttributeSpec.XNone, XAribute.XPositonStyle.Left, "入口" , XAribute.CanLinkType.More, "执行入口", ""); box.AddAttribute(XAribute.XAttributeType.XExc, XAribute.XAttributeSpec.XNone, XAribute.XPositonStyle.right, "出口", XAribute.CanLinkType.One, "执行出口", ""); box.AddAttribute(bute.SelectType, bute.SelectSpc, XAribute.XPositonStyle.Left, bute.Title, XAribute.CanLinkType.One , bute.Hint, bute.ExName); XAribute rightBute = box.AddAttribute(bute.SelectType, bute.SelectSpc, XAribute.XPositonStyle.right, bute.Title, XAribute.CanLinkType.More , bute.Hint, bute.ExName); ///同样的属性不用绘制2次名称 rightBute.IsDirText = false; } else if (type == "get") { CodeBox box = CreateXCodeBox("获取:" + bute.Title + " 的值", _createBoxPosition, CodeBox.XAType.get); box.Hint = "获取当前类中的这个属性的值,类型:" + bute.ExName; XAribute rightbute = box.AddAttribute(bute.SelectType, bute.SelectSpc, XAribute.XPositonStyle.right, bute.Title, XAribute.CanLinkType.More , bute.Hint, bute.ExName); } } ///隐藏选择框 HiddenXAributeSelectPopup(); } #endregion break; } return(null); }
/// <summary> /// 解析普通代码块 /// </summary> protected string AnalyticalNormal(CodeBox box) { string codeString = ""; string boxcodestring = ""; switch (box.CodeBoxType) { #region 分支结构 case CodeBox.XAType.XIf: string ifstring = box.GetCodeBoxValue(); codeString += "if ( " + ifstring + "== true )" + LineBreaks; codeString += "{" + LineBreaks; ///条件为真的出口 XAribute trueExc = (XAribute)box.RightAribute.Children[0]; ///如果有后续内容 if (trueExc.GetMyBeziers.Count > 0) { codeString += AnalyticalCenterTool(trueExc); } codeString += LineBreaks; codeString += "}" + LineBreaks; codeString += "else" + LineBreaks; codeString += "{" + LineBreaks; ///条件为假的出口 XAribute falseExc = (XAribute)box.RightAribute.Children[1]; ///如果有后续内容 if (falseExc.GetMyBeziers.Count > 0) { codeString += AnalyticalCenterTool(falseExc); } codeString += LineBreaks; codeString += "}" + LineBreaks; break; #endregion case CodeBox.XAType.XFor: boxcodestring = box.GetCodeBoxValue(); codeString += "for ( " + boxcodestring + " )" + LineBreaks; codeString += "{" + LineBreaks; List <XAribute> butes = box.GetRightExc(); ///如果有后续内容 if (butes[0].GetMyBeziers.Count > 0) { codeString += AnalyticalCenterTool(butes[0]); } codeString += "}" + LineBreaks; if (butes[1].GetMyBeziers.Count > 0) { codeString += AnalyticalCenterTool(butes[1]); } break; #region 顺序结构 default: codeString += box.GetCodeBoxValue() + LineBreaks; foreach (XAribute bute in box.RightAribute.Children) { if (bute.SelectType == XAribute.XAttributeType.XExc) { if (bute.GetMyBeziers.Count > 0) { codeString += AnalyticalCenterTool(bute); } } } break; #endregion } return(codeString); }