/// <summary> /// Prj_Sheet to Xml /// </summary> /// <param name="sheet"></param> public static void GenerateXinHuaSheets(BllManager bll, Prj_Document documet, string outPath) { string pagesPath = outPath + "\\data\\xinhua\\Pages\\"; if (!Directory.Exists(pagesPath)) { Directory.CreateDirectory(pagesPath); } if (session == null) { session = bll.manager.session; } try { // 每个Document只包含一个Sheet int sheetID = bll.manager.SheetCRUD.GetPrj_Sheets_By_Prj_Document_ID(documet.ID)[0].ID; Prj_Sheet sheet = bll.manager.SheetCRUD.Load_Sheet(sheetID); ArrayList symbols = new ArrayList(); // 算法块 foreach (Cld_FCBlock block in sheet.Cld_FCBlock_List) { #region if(特殊块) if (block.FunctionName == "XAI") { GenerateXAIBlock(block, symbols); } else if (block.FunctionName == "XAO") { GenerateXAOBlock(block, symbols); } else if (block.FunctionName == "XDI") { GenerateXDIBlock(block, symbols); } else if (block.FunctionName == "XDO") { GenerateXDOBlock(block, symbols); } else if (block.FunctionName == "XPI") { GenerateXPIBlock(block, symbols); } else if (block.FunctionName == "XPgAI") { GenerateXPgAIBlock(block, symbols); } else if (block.FunctionName == "XPgAO") { GenerateXPgAOBlock(block, symbols); } else if (block.FunctionName == "XPgDI") { GenerateXPgDIBlock(block, symbols); } else if (block.FunctionName == "XPgDO") { GenerateXPgDOBlock(block, symbols); } else if (block.FunctionName == "XNetAI") { GenerateXNetAIBlock(block, symbols); } else if (block.FunctionName == "XNetAO") { GenerateXNetAOBlock(block, symbols); } else if (block.FunctionName == "XNetDI") { GenerateXNetDIBlock(block, symbols); } else if (block.FunctionName == "XNetDO") { GenerateXNetDOBlock(block, symbols); } #endregion else { bll.generate_Rec_symbol(block, BllManager.rela_pos.UPLEFT); GenerateCommonBlock(block, symbols); } } // 文本块 foreach (Cld_Graphic graphic in sheet.Cld_Graphic_List) { if (graphic.Type == "Text") { GenerateText(graphic, symbols); } } //IList constants = sheet.Cld_Constant_List; // 信号线 IDictionary<string, Cld_Signal> signalTable = bll.GenerateSignalLines(sheet); foreach (Cld_Signal signal in signalTable.Values) { string[] signalDataList = signal.Data.TrimEnd(' ', ';').Split(';'); foreach (string signalData in signalDataList) { LogicSignalLine signalline = new LogicSignalLine(signalData, signal.Name, signal.SignalType); symbols.Add(signalline); } } // 创建XmlTextWriter类的实例对象 XmlTextWriter textWriter = new XmlTextWriter(pagesPath + documet.DocumentName.Replace('-', '_') + ".xfig", Encoding.UTF8); textWriter.Indentation = 4; textWriter.Formatting = Formatting.Indented; textWriter.WriteStartElement("document"); textWriter.WriteAttributeString("Type", "BeginNode"); textWriter.WriteAttributeString("GraphicName", documet.DocumentCaption); textWriter.WriteAttributeString("BackColor", "FF FF FF FF"); textWriter.WriteAttributeString("width", Convert.ToString(sheet.Width * 10)); textWriter.WriteAttributeString("heigth", Convert.ToString(sheet.Height * 10)); LogicRectangle pageBounds0 = new LogicRectangle(); pageBounds0.Location = new PointF(0, 0); pageBounds0.Size = new SizeF(sheet.Width, sheet.Height); pageBounds0.LineWidth = 1; pageBounds0.GetXinhuaGraphicXml(textWriter); LogicRectangle pageBounds1 = new LogicRectangle(); pageBounds1.Location = new PointF(30, 30); pageBounds1.Size = new SizeF(sheet.Width - 60f, sheet.Height - 60f); pageBounds1.LineWidth = 2; pageBounds1.GetXinhuaGraphicXml(textWriter); foreach (object obj in symbols) { ((ILogicGraphicFormat)obj).GetXinhuaGraphicXml(textWriter); } textWriter.WriteEndElement(); textWriter.Close(); } catch (System.Exception e) { Console.WriteLine(e.ToString()); } }
/// <summary> /// Prj_Sheet To Xml /// </summary> /// <param name="sheet"></param> public static void Generate_Sheet_Xml(Prj_Sheet sheet, BllManager bll) { //因为此方法采用反射来获取类中的所有共有属性进行输出,因此这里屏蔽对象中的某些不需要输出的属性 List<string> myclass = new List<string>(); myclass.Add("Prj_Project"); myclass.Add("Prj_Network"); myclass.Add("Prj_Unit"); myclass.Add("Prj_Controller"); myclass.Add("Prj_Document"); myclass.Add("Prj_Sheet"); myclass.Add("Cld_FCBlock"); myclass.Add("Cld_Signal"); myclass.Add("Cld_Constant"); myclass.Add("Cld_Graphic"); myclass.Add("X"); myclass.Add("Y"); myclass.Add("PinIndex"); try { // 创建XmlTextWriter类的实例对象 XmlTextWriter textWriter = new XmlTextWriter(sheet.ID.ToString() + ".xml", null); textWriter.Formatting = Formatting.Indented; // 开始写过程,调用WriteStartDocument方法 textWriter.WriteStartDocument(); // 写入说明 textWriter.WriteComment("First Comment XmlTextWriter Sample Example"); textWriter.WriteComment("w3sky.xml in root dir"); Type sheet_type = typeof(Prj_Sheet); Type fcblock_type = typeof(Cld_FCBlock); Type fcconst_type = typeof(Cld_Constant); Type fcgraphic_type = typeof(Cld_Graphic); Type fcsignal_type = typeof(Cld_Signal); Type fcinput_type = typeof(Cld_FCInput); Type fcoutput_type = typeof(Cld_FCOutput); Type fcpara_type = typeof(Cld_FCParameter); //创建sheet结点 textWriter.WriteStartElement("sheet"); foreach (PropertyInfo pi in sheet_type.GetProperties()) { object value_object = pi.GetValue(sheet, null); string value_string = ""; if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) { continue; } if (value_object != null) { value_string = value_object.ToString(); } textWriter.WriteAttributeString(pi.Name, value_string); } //fcblock foreach (Cld_FCBlock fcblock in sheet.Cld_FCBlock_List) { textWriter.WriteStartElement("element"); textWriter.WriteAttributeString("type", "Cld_FCBlock"); bll.generate_Rec_symbol(fcblock, TDK.Core.Logic.BLL.BllManager.rela_pos.UPLEFT); foreach (PropertyInfo pi in fcblock_type.GetProperties()) { object value_object = pi.GetValue(fcblock, null); string value_string = ""; if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) { continue; } if (value_object != null) { value_string = value_object.ToString(); } textWriter.WriteAttributeString(pi.Name, value_string); } foreach (Cld_FCInput input in fcblock.Cld_FCInput_List) { textWriter.WriteStartElement("element"); textWriter.WriteAttributeString("type", "Cld_FCInput"); foreach (PropertyInfo pi in fcinput_type.GetProperties()) { object value_object = pi.GetValue(input, null); string value_string = ""; if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) { continue; } if (value_object != null) { value_string = value_object.ToString(); } textWriter.WriteAttributeString(pi.Name, value_string); } textWriter.WriteEndElement(); } //foreach (Cld_FCOutput output in fcblock.Cld_FCOutput_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "FCOutput"); // foreach (PropertyInfo pi in fcoutput_type.GetProperties()) // { // object value_object = pi.GetValue(output, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object != null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} //foreach (Cld_FCParameter para in fcblock.Cld_FCParameter_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_FCParameter"); // foreach (PropertyInfo pi in fcpara_type.GetProperties()) // { // object value_object = pi.GetValue(para, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object != null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} textWriter.WriteEndElement(); } ////const //foreach (Cld_Constant cldconst in sheet.Cld_Constant_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_Constant"); // foreach (PropertyInfo pi in fcconst_type.GetProperties()) // { // object value_object = pi.GetValue(cldconst, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object == null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} ////graphic //foreach (Cld_Graphic graphic in sheet.Cld_Graphic_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_Graphic"); // foreach (PropertyInfo pi in fcgraphic_type.GetProperties()) // { // object value_object = pi.GetValue(graphic, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object == null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} ////signal //foreach (Cld_Signal signal in sheet.Cld_Signal_List) //{ // textWriter.WriteStartElement("element"); // textWriter.WriteAttributeString("type", "Cld_Signal"); // foreach (PropertyInfo pi in fcsignal_type.GetProperties()) // { // object value_object = pi.GetValue(signal, null); // string value_string = ""; // if (pi.PropertyType.Name.Equals("IList") || myclass.Contains(pi.PropertyType.Name)) // { // continue; // } // if (value_object == null) // { // value_string = value_object.ToString(); // } // textWriter.WriteAttributeString(pi.Name, value_string); // } // textWriter.WriteEndElement(); //} textWriter.WriteEndElement(); // 关闭textWriter textWriter.Close(); } catch (System.Exception e) { Console.WriteLine(e.ToString()); } }