Browse Source

Merge branch 'master' of http://192.168.1.123:10080/SDD1/HOZ

HaoShuang 5 years ago
parent
commit
c552867641

+ 9 - 9
FileManager/Serialize.cs

@@ -126,7 +126,7 @@ namespace FileManager
 
         public xTime_t()
         {
-            DateTime t = Convert.ToDateTime(0);
+            DateTime t = Convert.ToDateTime(null);
             AssignValue(t);
         }
 
@@ -294,7 +294,7 @@ namespace FileManager
 
 
     //typedef std::map<std::string, CollectionBase*>::iterator __declspec(dllexport) CollectionIterator;  ???
-    public abstract class CollectionBase<T> 
+    public abstract class CollectionBase<T>
     {
         private string m_sCollectionName;
         private string m_sCollectionClassType;
@@ -323,7 +323,7 @@ namespace FileManager
         create new element of type T
         @return empty object of type T
         */
-        public override T newElement() 
+        public override T newElement()
         {
             T newItem = System.Activator.CreateInstance<T>();
             //T newItem = default(T);
@@ -346,7 +346,7 @@ namespace FileManager
             m_vCollection.Add(sIo);/* m_mOwner[item] = false;*/
         }
 
-        public T getItem(int itemID) 
+        public T getItem(int itemID)
         {
             object temp = m_vCollection[itemID];
             T item = (T)temp;
@@ -363,7 +363,7 @@ namespace FileManager
 
     //typedef std::vector<Slo*>::iterator  __declspec(dllexport) SerializableIterator;  //iterator?
 
-    public class Slo<T>: ISlo
+    public class Slo<T> : ISlo
     {
         //private (Slo const &s) { }
         //private Slo operator=(Slo const &s) { return *this; };
@@ -382,8 +382,8 @@ namespace FileManager
         public string m_sClassName;
         public string m_sVersion;
         public SortedDictionary<string, MemberBase> m_AttributeMappings = new SortedDictionary<string, MemberBase>();
-        public SortedDictionary<string, ISlo> m_MemberMappings=new SortedDictionary<string, ISlo>();
-        public SortedDictionary<string, CollectionBase<T>> m_MemberCollections=new SortedDictionary<string, CollectionBase<T>>();
+        public SortedDictionary<string, ISlo> m_MemberMappings = new SortedDictionary<string, ISlo>();
+        public SortedDictionary<string, CollectionBase<T>> m_MemberCollections = new SortedDictionary<string, CollectionBase<T>>();
 
         public void setClassName(string ClassName) { m_sClassName = ClassName; }
         public Slo()
@@ -456,7 +456,7 @@ namespace FileManager
             for (int it_member = 0; it_member < m_AttributeMappings.Count; it_member++)
             {
                 var element = m_AttributeMappings.ElementAt(it_member);
-                
+
                 if (rootNode.Attributes[element.Key] == null)
                 {
                     XmlElement XmlEle = (XmlElement)rootNode;
@@ -644,7 +644,7 @@ namespace FileManager
             }
         }
 
-        string IdentifyClass(XmlNode rootNode, string XMLSource)  
+        string IdentifyClass(XmlNode rootNode, string XMLSource)
         {
             return rootNode.Attributes["RegName"].Value;
         }

+ 2 - 2
FileManager/XmlManager.cs

@@ -20,14 +20,14 @@ namespace FileManager
         /// <param name="rootnode">根节点名</param>
         /// <param name="list_attributes">根节点的属性键值对</param>
         /// <returns></returns>
-        public Boolean CreateXmlFile(String xmlfullname,String rootnode)
+        public static Boolean CreateXmlFile(String xmlfullname )
         {
             XmlDocument xmlDoc = new XmlDocument();
             //创建类型声明节点  
             XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "");
             xmlDoc.AppendChild(node);
             //创建根节点  
-            XmlNode root = xmlDoc.CreateElement(rootnode);
+            XmlNode root = xmlDoc.CreateElement("XMLData");
             xmlDoc.AppendChild(root);
             try
             {

File diff suppressed because it is too large
+ 504 - 462
HOZProject/FormUnitControl.Designer.cs


+ 57 - 29
HOZProject/FormUnitControl.cs

@@ -611,56 +611,84 @@ namespace HOZProject
         }
         #endregion
 
-        private void btnCreatXml_Click(object sender, EventArgs e)
+        private void btnReadXml_Click(object sender, EventArgs e)
         {
-            SaveFileDialog sfd = new SaveFileDialog();
-            sfd.Title = "生成Xml文件位置:";
-            sfd.FileName = "test.xml";
-            sfd.Filter = "XML文件|*.xml";
-            if (sfd.ShowDialog() == DialogResult.OK)
-            {
-                string fn = sfd.FileName;
-                List<KeyValuePair<String, String>> lkvp = new List<KeyValuePair<string, string>>();
-                lkvp.Add(new KeyValuePair<string, string>("key1","value1"));
-                lkvp.Add(new KeyValuePair<string, string>("key2", "value2"));
-                xmg.CreateXmlFile(fn,"XMLData");
-
-                lkvp.Clear();
-                lkvp.Add(new KeyValuePair<string, string>("key3", "value3"));
-                lkvp.Add(new KeyValuePair<string, string>("key4", "value4"));
-                //xmg.CreateNode(fn, "XMLData", "子节点", "", lkvp);
-                //xmg.CreateNode(fn, "子节点", "子bb节点", "", lkvp);
-            }
-        }
+            MeasureFile mf = new MeasureFile();
 
-        private void button1_Click_1(object sender, EventArgs e)
-        {
             XmlDocument doc = new XmlDocument();
             doc.Load("test.xml");//载入xml文件
-
             XmlNode root = doc.SelectSingleNode("XMLData");
 
+            mf.Serialize(false, doc, root);
+
+            doc.Save("test.xml");
+        }
+
+        private void btnWriteXml_Click(object sender, EventArgs e)
+        {
             MeasureFile mf = new MeasureFile();
 
-            mf.FileName = "New FileName";
-            mf.FilePath = "D:\\opton\\New FilePath";
+            mf.FileName = "test_opton.msf";
+            mf.FilePath = path;
 
             CutHole ch = new CutHole();
             ch.SampleName = "SampleName1";
             ch.PT = true;
             ch.FIBTemp = "FIBTemp1";
             ch.PTTemp = "PTTemp1";
-            ch.OPT = MeasureData.Operation.Image;
+            ch.OPT = Operation.Image;
             ch.START = System.DateTime.Now;
             ch.END = System.DateTime.Now.AddHours(2);
-            ch.STATE = MeasureData.State.Success;
+            ch.STATE = State.Success;
             ch.SWITCH = true;
 
+            SemPosition sp = new SemPosition();
+            sp.X = 11;
+            sp.Y = 22;
+            sp.Z = 33;
+            sp.T = 44;
+            sp.R = 55;
+            sp.M = 66;
+
+            ch.Position = sp;
+
             mf.ListCutHole.Add(ch);
 
-            mf.Serialize(true, doc, root);
+            ch = new CutHole();
+            ch.SampleName = "SampleName2";
+            ch.PT = true;
+            ch.FIBTemp = "FIBTemp2";
+            ch.PTTemp = "PTTemp2";
+            ch.OPT = Operation.Image;
+            ch.START = System.DateTime.Now;
+            ch.END = System.DateTime.Now.AddHours(2);
+            ch.STATE = State.Success;
+            ch.SWITCH = true;
+
+            sp = new SemPosition();
+            sp.X = 12;
+            sp.Y = 34;
+            sp.Z = 56;
+            sp.T = 78;
+            sp.R = 90;
+            sp.M = 55;
 
-            doc.Save("test.xml");
+            ch.Position = sp;
+
+            mf.ListCutHole.Add(ch);
+
+            mf.New();
+            //XmlDocument doc = new XmlDocument();
+            //doc.Load(mf.FilePath+"\\" + mf.FileName);//载入xml文件
+
+            //XmlNode root = doc.SelectSingleNode("XMLData");
+
+            //mf.Serialize(true, doc, root);
+
+            //doc.Save("test.aaa");
+            
+
+            
         }
 
         #region SEM模式

+ 51 - 13
MeasureData/CutHole.cs

@@ -164,59 +164,91 @@ namespace MeasureData
             m_opt = Operation.Init;
             m_state = State.Unmeasured;
             m_switch = false;
+            Position = new SemPosition();
         }
 
         //样品孔存储xml文档
         public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
         {
 
-            Slo<CutHole> slo = new Slo<CutHole> ();
+            Slo<CutHole> slo_cuthole = new Slo<CutHole>();
+
+            xString regName = new xString();
+            regName.AssignValue("CutHole");
+            slo_cuthole.Register("RegName", regName);
+
             //样品名称
             xString SampleName = new xString();
             SampleName.AssignValue(this.SampleName);
-            slo.Register("SampleName", SampleName);
+            slo_cuthole.Register("SampleName", SampleName);
+
+            Slo<SemPosition> slo_sp = new Slo<SemPosition>();
+            xDouble ptx = new xDouble();
+            ptx.AssignValue(this.Position.X);
+            slo_sp.Register("X", ptx);
+
+            xDouble pty = new xDouble();
+            pty.AssignValue(this.Position.X);
+            slo_sp.Register("Y", pty);
+
+            xDouble ptz = new xDouble();
+            ptz.AssignValue(this.Position.Z);
+            slo_sp.Register("Z", ptz);
+
+            xDouble ptt = new xDouble();
+            ptt.AssignValue(this.Position.T);
+            slo_sp.Register("T", ptt);
+
+            xDouble ptr = new xDouble();
+            ptr.AssignValue(this.Position.R);
+            slo_sp.Register("R", ptr);
+
+            xDouble ptm = new xDouble();
+            ptx.AssignValue(this.Position.M);
+            slo_sp.Register("M", ptm);
+            slo_cuthole.Register("Position", slo_sp);
 
             //是否有PT沉积
             xBool PT = new xBool();
             PT.AssignValue(this.PT);
-            slo.Register("PT", PT);
+            slo_cuthole.Register("PT", PT);
             //FIB工作模板
             xString FIBTemp = new xString();
             FIBTemp.AssignValue(this.FIBTemp);
-            slo.Register("FIBTemp", FIBTemp);
+            slo_cuthole.Register("FIBTemp", FIBTemp);
             //PT工作模板
             xString PTTemp = new xString();
             PTTemp.AssignValue(this.PTTemp);
-            slo.Register("PTTemp", PTTemp);
+            slo_cuthole.Register("PTTemp", PTTemp);
 
             //操作步骤
             xInt OPT = new xInt();
             OPT.AssignValue(this.OPT.GetHashCode());
-            slo.Register("OPT", OPT);
+            slo_cuthole.Register("OPT", OPT);
             //开始时间
             xTime_t START = new xTime_t();
             START.AssignValue(this.START);
-            slo.Register("START", START);
+            slo_cuthole.Register("START", START);
             //结束时间
             xTime_t END = new xTime_t();
             END.AssignValue(this.END);
-            slo.Register("END", END);
+            slo_cuthole.Register("END", END);
             //测量结果
             xInt STATE = new xInt();
             STATE.AssignValue(this.STATE.GetHashCode());
-            slo.Register("STATE", STATE);
+            slo_cuthole.Register("STATE", STATE);
             //测量开关
             xBool SWITCH = new xBool();
             SWITCH.AssignValue(this.SWITCH);
-            slo.Register("SWITCH", SWITCH);
+            slo_cuthole.Register("SWITCH", SWITCH);
 
             if (isStoring)
             {
-                slo.Serialize(true, xml, rootNode);
+                slo_cuthole.Serialize(true, xml, rootNode);
             }
             else
             {
-                slo.Serialize(false, xml, rootNode);
+                slo_cuthole.Serialize(false, xml, rootNode);
 
                 this.SampleName = SampleName.value();
                 this.PT = PT.value();
@@ -227,9 +259,15 @@ namespace MeasureData
                 this.END = END.value();
                 this.STATE = (State)STATE.value();
                 this.SWITCH = SWITCH.value();
+                this.Position.X = (float)ptx.value();
+                this.Position.Y = (float)pty.value();
+                this.Position.Z = (float)ptz.value();
+                this.Position.T = (float)ptt.value();
+                this.Position.R = (float)ptr.value();
+                this.Position.M = (float)ptm.value();
             }
         }
-    
+
     }
 
 }

+ 58 - 7
MeasureData/MeasureFile.cs

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
 
 using FileManager;
 using System.Xml;
+using System.IO;
 
 namespace MeasureData
 {
@@ -45,33 +46,69 @@ namespace MeasureData
             set { this.m_listCutHole = value; }
         }
 
+        /// <summary>
+        /// 创建XML文件
+        /// </summary>
+        /// <returns>0:失败;1:成功;2:文件已存在</returns>
+        public int CreateXml()
+        {
+            if (!File.Exists(this.FilePath + "\\" + this.FileName))
+            {
+                if( XmlManager.CreateXmlFile(this.FilePath + "\\" + this.FileName))
+                {
+                    return 1;
+                }
+                else
+                {
+                    return 0;
+                }
+            }
+            else
+            {
+                return 2;
+            }
+        }
+
         //XML文件保存
         //样品孔存储xml文档
         public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
         {
+            Slo<MeasureFile> slo_msf = new Slo<MeasureFile>();
 
-            Slo<MeasureFile> slo = new Slo<MeasureFile>();
+            Slo<CutHole> slo_cuthole = new Slo<CutHole>();
+            Collection<CutHole> cot_cuthole = new Collection<CutHole>();
+
+            for (int i = 0; i < this.ListCutHole.Count; i++)
+            {
+                cot_cuthole.addItem(ListCutHole[i]);
+            }
 
             xString FileName = new xString();
             xString FilePath = new xString();
             FileName.AssignValue(this.FileName);
             FilePath.AssignValue(this.FilePath);
-            slo.Register("FileName", FileName);
-            slo.Register("FilePath", FilePath);
+            slo_cuthole.Register("FileName", FileName);
+            slo_cuthole.Register("FilePath", FilePath);
+
+            slo_cuthole.Register("ListCutHole", cot_cuthole);
 
-            Collection<CutHole> ctch = new Collection<CutHole>();
-            ctch.addItem(this.ListCutHole[0]);
+            slo_msf.Register("MeasureFile", slo_cuthole);
 
             if (isStoring)
             {
-                slo.Serialize(true, xml, rootNode);
+                slo_msf.Serialize(true, xml, rootNode);
             }
             else
             {
-                slo.Serialize(false, xml, rootNode);
+                slo_msf.Serialize(false, xml, rootNode);
 
                 this.FileName = FileName.value();
                 this.FilePath = FilePath.value();
+                for (int i = 0; i < cot_cuthole.m_vCollection.Count; i++)
+                {
+                    this.ListCutHole.Add(cot_cuthole.getItem(i));
+                }
+
             }
         }
         #endregion
@@ -88,9 +125,23 @@ namespace MeasureData
         }
         #region 操作
 
+
+
         //新建
         public void New()
         {
+            int ret = CreateXml();
+            if(ret>0)
+            {
+                XmlDocument doc = new XmlDocument();
+                doc.Load(this.FilePath + "\\" + this.FileName);//载入xml文件
+
+                XmlNode root = doc.SelectSingleNode("XMLData");
+
+                Serialize(true, doc, root);
+
+                doc.Save(this.FilePath + "\\" + this.FileName);
+            }
         }
 
         //打开

+ 47 - 1
MeasureData/SemPosition.cs

@@ -6,11 +6,13 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using FileManager;
+using System.Xml;
 
 namespace MeasureData
 {
     //六轴坐标系统
-    public class SemPosition
+    public class SemPosition:ISlo
     {
 
         private float m_x, m_y, m_z, m_r, m_t, m_m;
@@ -150,6 +152,50 @@ namespace MeasureData
         {
 
         }
+
+        public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
+        {
+            Slo<SemPosition> slo_sp = new Slo<SemPosition>();
+
+            xDouble ptx = new xDouble();
+            ptx.AssignValue(this.X);
+            slo_sp.Register("X", ptx);
+
+            xDouble pty = new xDouble();
+            pty.AssignValue(this.X);
+            slo_sp.Register("Y", pty);
+
+            xDouble ptz = new xDouble();
+            ptz.AssignValue(this.Z);
+            slo_sp.Register("Z", ptz);
+
+            xDouble ptt = new xDouble();
+            ptt.AssignValue(this.T);
+            slo_sp.Register("T", ptt);
+
+            xDouble ptr = new xDouble();
+            ptr.AssignValue(this.R);
+            slo_sp.Register("R", ptr);
+
+            xDouble ptm = new xDouble();
+            ptx.AssignValue(this.M);
+            slo_sp.Register("M", ptm);
+
+            if (isStoring)
+            {
+                slo_sp.Serialize(true, xml, rootNode);
+            }
+            else
+            {
+                slo_sp.Serialize(false, xml, rootNode);
+                this.X = (float)ptx.value();
+                this.Y = (float)pty.value();
+                this.Z = (float)ptz.value();
+                this.T = (float)ptt.value();
+                this.R = (float)ptr.value();
+                this.M = (float)ptm.value();
+            }
+        }
     }
 
 }

Some files were not shown because too many files changed in this diff