/// <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> /// 将XML对象转换回CodeBox对象 /// </summary> /// <param name="boxElement"></param> /// <returns></returns> public static void ReadCodeBoxObject(XmlNode boxnode, PicTabPage pic) { XmlElement boxElement = (XmlElement)boxnode; //CodeBox ReBox = new CodeBox(); int Id = int.Parse(boxElement.GetAttribute("ID")); string Title = boxElement.GetAttribute("Title"); string Hint = boxElement.GetAttribute("HitText"); CodeBox.XAType CodeboxType = CodeBox.CodeBoxTypeMapping(boxElement.GetAttribute("CodeBoxType")); Point position = new Point(); position.X = float.Parse(boxElement.GetAttribute("PositionX")); position.Y = float.Parse(boxElement.GetAttribute("PositionY")); string SystemCodeString = boxElement.GetAttribute("SystemCodeString"); string ReturnValueName = boxElement.GetAttribute("ReturnValueName"); ///加载一个CodeBox CodeBox ReBox = pic.LoadXCodeBox(Title, position, Id, CodeboxType); ReBox.SystemCodeString = SystemCodeString; ReBox.ReturnValueName = ReturnValueName; ///循环左边属性 XmlNode LeftXAribute = boxnode.SelectSingleNode("LeftXAribute"); foreach (XmlNode node in LeftXAribute.SelectNodes("XAribute")) { ReadXAributeObject(node, ReBox); } ///循环右边属性 XmlNode RightXAribute = boxnode.SelectSingleNode("RightXAribute"); foreach (XmlNode node in RightXAribute.SelectNodes("XAribute")) { ReadXAributeObject(node, ReBox); } }
/// <summary> /// 添加一个代码类 /// </summary> /// <param name="page"></param> public void AddPicTabPage(PicTabPage page) { while (true) { if (MyListPicPage.ContainsKey(page.Title)) { page.Title = page.Title + "1"; } else { break; } } MyListPicPage.Add(page.Title, page); ///设置回调函数 page.MessageUpdateCall = this.ChileEventCallBack; MyProjectFiles file = new MyProjectFiles(); file.Name = page.Title; file.Path = FilesPath + page.Title; MyListProjectFiles.Add(file); page.PopContentCode.MyData = DataSource; ///初始化数据 ModityPicTabPageFunction(); ///添加数据 foreach (XAribute bute in page.ListXAributes) { ///添加类型 bute.ProjectUseClassType = this.ProjectUseClassType; } }
/// <summary> /// 新建项目 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewProject_Click(object sender, RoutedEventArgs e) { try { NewProject nProject = new NewProject(); ///设置项目类 nProject.SetProjectClass(_myProject, _solution); nProject.ShowDialog(); if (_myProject.RootPath != "") { ///设置项目根目录 Solution.RootPath = _myProject.RootPath; ///创建主类和主函数信息 PicTabPage mainpage = new PicTabPage((new Random()).Next(1, 2000000), this.ChileEventCallBack, "Program.cx"); CodeBox mainbox = mainpage.CreateXCodeBox("Main", PicTabPage.CenterPoint, CodeBox.XAType.XMain); mainbox.AddAttribute(MyXAribute.XAribute.XAttributeType.XExc, MyXAribute.XAribute.XAttributeSpec.XNone, MyXAribute.XAribute.XPositonStyle.right, "出口", MyXAribute.XAribute.CanLinkType.One, "主函数出口", ""); ///添加主信息 _myProject.AddPicTabPage(mainpage); ///将代码图添加到tab页 AddLayoutDocument(ContentPanel, mainpage); ///绑定各个面板数据 BindingPanels(mainpage); } ///保存配置文件路径 Solution.SolutionConfigPath = XCreateConfigurationInformation.SolutionConfigPath; ///添加到解决方案 Solution.AddProjectClass(MyProject); } catch (Exception ex) { LoggerHelp.WriteLogger(ex.ToString()); } }
/// <summary> /// 某个类更新了一个函数属性的通知 /// </summary> /// <param name="page">类</param> /// <param name="fun">函数</param> public void UpdatePicFunctionToPicData(PicTabPage page, PicFunctionTabPage fun) { MyXTreeItem delpicitem = null; MyXTreeItem delfunitem = null; foreach (MyXTreeItem item in DataSource) { if (item.XName == page.Title) { delpicitem = item; foreach (MyXTreeItem funitem in item.ChildrenItem) { if (funitem.XName == fun.Title) { delfunitem = funitem; } } } } if (delpicitem == null || delfunitem == null) { return; } delpicitem.ChildrenItem.Remove(delfunitem); ///重新添加函数信息 AddPicFunctionToPicData(page, fun); }
/// <summary> /// 打开项目 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenProject_Click(object sender, RoutedEventArgs e) { try { System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog(); openFile.Filter = "配置文件 | *.xpl;"; if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ///保存解决方案配置文件路径 Solution.SolutionConfigPath = openFile.FileName; ///加载解决方案 Solution.LoadSolution(openFile.FileName); MyProject = Solution.GetFirstProject(); ///获取主类 PicTabPage mainpage = _myProject.GetFirstPicTabPage(); ///将代码图添加到tab页 AddLayoutDocument(ContentPanel, mainpage); BindingPanels(mainpage); } } catch (Exception ex) { LoggerHelp.WriteLogger(ex.ToString()); } }
/// <summary> /// 向当前添加一个pictabpage /// </summary> /// <param name="page">要添加的page</param> public void AddPicTabPage(PicTabPage page) { AddLayoutDocument(ContentPanel, page); ///设置回调函数 page.CallBackFunction = this.ChileEventCallBack; MyProject.AddPicTabPage(page); }
/// <summary> /// 创建一个空白的Pictabpage /// </summary> /// <param name="Title">页面的标题</param> public void CreatePicTabPage(string Title) { PicTabPage page = new PicTabPage(CreateID(), this.ChileEventCallBack, Title); AddLayoutDocument(ContentPanel, page); MyProject.AddPicTabPage(page); }
/// <summary> /// 绑定属性面板 /// </summary> /// <param name="pic">要绑定的picTabPage</param> public void BindingXAributeWindow(PicTabPage pic) { MyXAributePanel xaributepanel = new MyXAributePanel(); xaributepanel.SetCallFunction(this.ChileEventCallBack); xaributepanel.DirXAribute(pic); _xaributePanel.Content = xaributepanel; }
/// <summary> /// 绑定函数面板 /// </summary> /// <param name="pic">要绑定的picTabPage</param> public void BindingFunctionWindow(PicTabPage pic) { MyFunctionPanel funcpanel = new MyFunctionPanel(); funcpanel.SetCallFunction(this.ChileEventCallBack); funcpanel.DirFunction(pic); _functionPanel.Content = funcpanel; }
/// <summary> /// 绑定所有数据面板 /// </summary> public void BindingPanels(PicTabPage mainpage) { ///绑定各个面板数据 BindingDllWindow(); BindingFunctionWindow(mainpage); BindingXAributeWindow(mainpage); //BindingPropertiesWindow(); BindingSolutionWindow(); }
/// <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> /// 添加一个LayoutDocument元素 /// </summary> /// <param name="fatherPane">LayoutDocumentPane类型LayoutDocument的父级元素</param> /// <param name="Title">标题</param> /// <returns></returns> public bool AddLayoutDocument(LayoutDocumentPane fatherPane, PicTabPage page) { if (!CheckIsOpen(page)) { LayoutDocument lt = new LayoutDocument(); lt.Title = page.Title; lt.Content = page; ///添加回调事件 page.CallBackFunction = this.ChileEventCallBack; fatherPane.Children.Add(lt); return(true); } else { return(false); } }
/// <summary> /// LayoutDocument控件改变时候 /// </summary> /// <param name="sender">消息发送者</param> /// <param name="e">事件</param> public void LayoutDocumentChanged(object sender, PropertyChangedEventArgs e) { try { if (sender.GetType().Name == "LayoutDocument") { LayoutDocument ldt = (LayoutDocument)sender; if (ldt.Content != null) { PicTabPage page = (PicTabPage)ldt.Content; page.Width = ldt.FloatingWidth; page.Height = ldt.FloatingHeight; } } } catch (Exception ex) { LoggerHelp.WriteLogger(ex.ToString()); } }
/// <summary> /// 读取函数内容 /// </summary> /// <param name="picnode">代码图节点</param> /// <param name="pic">代码图(类)</param> public static void ReadFunction(XmlNode functionnode, PicTabPage pic) { XmlElement functionElement = (XmlElement)functionnode; string Title = functionElement.GetAttribute("Title"); int ID = int.Parse(functionElement.GetAttribute("ID")); XObject.OpenType myOpenType = XObject.OpenTypeMapping(functionElement.GetAttribute("OpenType")); OverrideType myOverrideType = XObject.OverrideTypeMapping(functionElement.GetAttribute("OverrideType")); PicFunctionTabPage functionpage = pic.LoadFunctionPage(Title, ID, myOpenType, myOverrideType); ///查找CodeBox节点 foreach (XmlNode node in functionnode.SelectNodes("CodeBox")) { DataWriteFunction.ReadCodeBoxObject(node, functionpage); } ///查找BezierLine节点 foreach (XmlNode node in functionnode.SelectNodes("BezierLine")) { DataWriteFunction.ReadBezierLine(node, functionpage); } }
/// <summary> /// 将文件转换为PicTabPage对象 /// </summary> /// <param name="path">文件路径</param> /// <returns></returns> public PicTabPage XmlToPic(string path) { PicTabPage pic = new PicTabPage(); XmlDocument XmlLoad = new XmlDocument(); XmlLoad.Load(path); ///查询出根节点 XmlNode root = XmlLoad.SelectSingleNode(RootName); XmlElement picroot = (XmlElement)root; pic.Id = int.Parse(picroot.GetAttribute("ID")); pic.Title = picroot.GetAttribute("Title"); ///查找CodeBox节点 XmlNode MainCodeBoxs = root.SelectSingleNode("MainCodeBoxs"); foreach (XmlNode node in MainCodeBoxs.SelectNodes("CodeBox")) { DataWriteFunction.ReadCodeBoxObject(node, pic); } ///查找BezierLine节点 XmlNode MainBezierLines = root.SelectSingleNode("MainBezierLines"); foreach (XmlNode node in MainBezierLines.SelectNodes("BezierLine")) { DataWriteFunction.ReadBezierLine(node, pic); } ///查找函数节点 foreach (XmlNode node in root.SelectNodes("Function")) { DataWriteFunction.ReadFunction(node, pic); } ///查找属性节点 foreach (XmlNode node in root.SelectNodes("XAribute")) { DataWriteFunction.ReadXAributeObject(node, pic); } XmlLoad.Save(path); return(pic); }
/// <summary> /// 检测这个是否已经打开 /// </summary> /// <param name="page">要检查的页面</param> /// <returns>返回结果</returns> public bool CheckIsOpen(PicTabPage page) { try { if (ContentPanel.Children.Count == 0) { return(false); } foreach (LayoutDocument doc in ContentPanel.Children) { if ((doc.Content as PicTabPage).Equals(page)) { return(true); } } }catch (Exception ex) { LoggerHelp.WriteLogger(ex.ToString()); return(false); } return(false); }
/// <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="pro">项目参数</param> public void DirFunction(PicTabPage picPage) { this.picPage = picPage; FunctionListBox.ItemsSource = this.picPage.ListFunction; }
/// <summary> /// 添加dll文件和显示 /// </summary> /// <param name="pro">项目参数</param> public void DirXAribute(PicTabPage picPage) { this.picPage = picPage; XAributeListBox.ItemsSource = this.picPage.ListXAributes; }
/// <summary> /// 某个类添加了一个函数更新通知 /// </summary> /// <param name="page">添加了函数的类</param> /// <param name="fun">被添加的函数</param> public void AddPicFunctionToPicData(PicTabPage page, PicFunctionTabPage fun) { ///新建项 MyXTreeItem item = new MyXTreeItem(); item.ChildrenItem = null; item.MyCodeBoxType = CodeBox.XAType.XFunction; item.MyHitText = fun.Hint; item.TypeImagePath = ""; item.XName = fun.Title; List <XAributeItem> xaitem = new List <XAributeItem>(); ///如果是C#则要加上函数的所属 if (Language == LanguageType.CSharp.ToString()) { XAributeItem buteitem = new XAributeItem(); buteitem.MyXPositonStyle = XAribute.XPositonStyle.Left; buteitem.Parameter_name = "Target"; buteitem.MyCanLinkType = XAribute.CanLinkType.One; buteitem.MyXAttributeSpec = XAribute.XAttributeSpec.XNone; buteitem.MyXAttributeType = XAribute.XAttributeType.XTarget; buteitem.MyHittext = "函数所属的类"; buteitem.MyLastExText = page.Title; xaitem.Add(buteitem); } //else if (Language == LanguageType.C.ToString()) //{ //} ///循环参数 foreach (XAribute bute in fun.FunctionEnterBox.RightAribute.Children) { if (bute.SelectType != XAribute.XAttributeType.XEnter) { ///填装信息 XAributeItem buteitem = new XAributeItem(bute); //buteitem.Parameter_name = bute.Title; //buteitem.MyCanLinkType = bute.CanLinkNum; //buteitem.MyXAttributeSpec = bute.SelectSpc; //buteitem.MyXAttributeType = bute.SelectType; buteitem.MyXPositonStyle = XAribute.XPositonStyle.Left; //buteitem.MyHittext = bute.Hint; //buteitem.MyLastExText = bute.ExName; ///加入列表 xaitem.Add(buteitem); } } ///组成函数的右半边属性 foreach (XAribute bute in fun.FunctionExcBox.LeftAribute.Children) { if (bute.SelectType != XAribute.XAttributeType.XExc) { XAributeItem buteitem = new XAributeItem(bute); buteitem.MyXPositonStyle = XAribute.XPositonStyle.right; xaitem.Add(buteitem); } } item.MyXaributeChildren = xaitem; bool isExect = false; ///是否已经存在类 MyXTreeItem UserTreeItem = null; foreach (MyXTreeItem myitem in DataSource) { if (myitem.XName == page.Title) { isExect = true; myitem.ChildrenItem.Add(item); return; } } if (!isExect && UserTreeItem == null) { UserTreeItem = new MyXTreeItem(); UserTreeItem.XName = page.Title; UserTreeItem.ChildrenItem.Add(item); ///添加信息和修改信息 DataSource.Add(UserTreeItem); } //ModityPicTabPageFunction(); }
/// <summary> /// 将代码图转换为文件 /// </summary> /// <param name="Page">代码图对象</param> /// <param name="path">文件存放路径</param> public void PicToXml(PicTabPage pic, string path) { string filePath = path + pic.Title; ///检测本地文件是否已经存在 #region 如果文件不存在则创建 if (!CheckFile(filePath)) { XmlTextWriter writer = new XmlTextWriter(filePath, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement(RootName); writer.WriteAttributeString("Title", pic.Title); writer.WriteAttributeString("ID", pic.Id.ToString()); ///循环所有代码块 writer.WriteStartElement("MainCodeBoxs"); foreach (CodeBox box in pic.ListCodeBoxChild.Values) { DataWriteFunction.WriteCodeBoxAribute(writer, box); } writer.WriteEndElement(); ///循环所有贝塞尔曲线 writer.WriteStartElement("MainBezierLines"); foreach (BezierLine line in pic.GetBezierLines.Values) { DataWriteFunction.WriteBezierLine(writer, line); } writer.WriteEndElement(); ///循环所有函数 foreach (PicFunctionTabPage func in pic.ListFunction) { DataWriteFunction.WriteFunction(writer, func); } ///循环所有属性 foreach (XAribute bute in pic.ListXAributes) { DataWriteFunction.WriteXAribute(writer, bute); } writer.WriteEndElement(); writer.Close(); } #endregion #region 如果存在则更新 else { XmlDocument XmlLoad = new XmlDocument(); XmlLoad.Load(path + pic.Title); XmlNode root = XmlLoad.SelectSingleNode(RootName); ///先清除所有然后在写入 root.RemoveAll(); XmlElement picroot = (XmlElement)root; picroot.SetAttribute("Title", pic.Title); picroot.SetAttribute("ID", pic.Id.ToString()); ///循环所有代码块 ///创建存放代码块的主节点 XmlElement MainCodeBoxs = XmlLoad.CreateElement("MainCodeBoxs"); foreach (CodeBox box in pic.ListCodeBoxChild.Values) { DataWriteFunction.UpdateCodeBoxAribute(XmlLoad, MainCodeBoxs, box); } picroot.AppendChild(MainCodeBoxs); ///循环所有贝塞尔曲线 ///创建存放贝塞尔曲线的主节点 XmlElement MainBeizierLines = XmlLoad.CreateElement("MainBezierLines"); foreach (BezierLine line in pic.GetBezierLines.Values) { DataWriteFunction.UpdateBezierLine(XmlLoad, MainBeizierLines, line); } ///添加节点 picroot.AppendChild(MainBeizierLines); ///循环所有函数 foreach (PicFunctionTabPage func in pic.ListFunction) { DataWriteFunction.UpdateFunction(XmlLoad, picroot, func); } ///循环所有属性 foreach (XAribute bute in pic.ListXAributes) { DataWriteFunction.UpdateXAribute(XmlLoad, picroot, bute); } XmlLoad.Save(path + pic.Title); } #endregion }