| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 | using OTS.WinFormsUI.Docking;using OTSCLRINTERFACE;using OTSCommon;using OTSCommon.Model;using OTSIncAReportApp.OTSDataMgrFunction;using OTSIncAReportApp.OTSSampleReportInfo;using OTSIncAReportApp.SysMgrTools;using OTSModelSharp;using OTSModelSharp.DTLBase;using System;using System.Collections;using System.Collections.Generic;using System.Drawing;using System.Runtime.InteropServices;using System.Windows.Forms;namespace OTSIncAReportApp{    /// <summary>    /// 显示测量结果树控件主窗体    /// </summary>    public partial class frmMeasureRstMgr : DockContent    {        #region 变量定义        /// <summary>        /// 主框架窗体,全局变量        /// </summary>        private frmReportApp m_ReportApp = null;        private frmReportConditionChoose m_ConditionChoose;        private ResultDataMgr m_RstDataMgr;        /// <summary>        /// 树窗口类        /// </summary>        private OTSTreeViewData m_TreeViewData = null;        /// <summary>        /// 测量结果样品节点        /// </summary>        public TreeNode m_WorkSampleNode = null;        /// <summary>        /// 工作样品属性参数        /// </summary>        public CTreeSampleRst m_WorkSampleParam = new CTreeSampleRst();        /// <summary>        /// 当前工作样品名        /// </summary>        private String m_WorkSampleName = "";        /// <summary>        /// 当前鼠标点击节点        /// </summary>        int treeNodeSample = -1;        Hashtable table;        #endregion        #region 构造函数和窗体加载        /// <summary>        /// 构造函数        /// </summary>        /// <param name="reportApp"></param>        public frmMeasureRstMgr(frmReportApp reportApp)        {            InitializeComponent();            m_ReportApp = reportApp;            m_ConditionChoose = reportApp.m_conditionChoose;            m_RstDataMgr = reportApp.m_rstDataMgr;            m_TreeViewData = new OTSTreeViewData(this);            #region 国际化语言            OTSCommon.Language lan = new OTSCommon.Language(this);            table = lan.GetNameTable(this.Name);            #endregion        }        /// <summary>        /// 窗体加载        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void OTSMeasureRetMgrWindow_Load(object sender, EventArgs e)        {            treeView1.LabelEdit = true;//TreeView可编辑状态。         }        #endregion        #region 外部接口函数及相关常量定义        /// <summary>        /// 发送消息        /// </summary>        /// <param name="hWnd"></param>        /// <param name="Msg"></param>        /// <param name="wParam"></param>        /// <param name="lParam"></param>        /// <returns></returns>        [DllImport("user32.dll", CharSet = CharSet.Auto)]        private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TVITEM lParam);        private const int TVIF_STATE = 0x8;        private const int TVIS_STATEIMAGEMASK = 0xF000;        private const int TV_FIRST = 0x1100;        private const int TVM_SETITEM = TV_FIRST + 63;        [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]        private struct TVITEM        {            public int mask;            public IntPtr hItem;            public int state;            public int stateMask;            [MarshalAs(UnmanagedType.LPTStr)]            public string lpszText;            public int cchTextMax;            public int iImage;            public int iSelectedImage; public int cChildren; public IntPtr lParam;        }        #endregion        #region 树控件相关事件        /// <summary>        /// 树控件点击是否选择右键        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeView1_Click(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Right)//判断你点的是不是右键            {                contextMenuStrip1.Show();            }        }        /// <summary>        /// 左键选择树节点事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)        {            //鼠标选中            if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard)            {                if (e.Node.IsSelected)                {                    //判断的选中的CHECKBOX和焦点都在当前被选择的节点上,切换当前工作样品                    m_WorkSampleNode = e.Node;                    treeView1.SelectedNode = e.Node;    //当前被选中                    treeView1.Refresh();                }            }        }        /// <summary>        /// 当Checkbox的状态发生变化时,响应事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)        {            if (e.Action == TreeViewAction.ByMouse)            {     //判断是否由鼠标触发的                             TreeNode TN = e.Node;//点击的节点                 if (TN.Checked)                {      //若是选中,遍历父节点,所属的父节点应为选中                 {                    if (TN.Parent != null)                    {                        TN.Parent.Checked = true;                        if (TN.Parent.Parent != null)                        {                            TN.Parent.Parent.Checked = true;                        }                    }                    DG_Check(TN, true); //本身节点之下还有子节点,遍历,全选中                 }                else                {     //若是取消选中                                    DG_Check(TN, false);//本身节点之下还有子节点,遍历,全取消选中                      if (TN.Parent != null)                    {                        //若有父节点,判断此次取消选中后,是否兄弟节点也是没选中                          TreeNode TNP = TN.Parent;                        bool YXZ = false;//有选中的,以此来判断否兄弟节点也是没选中                         foreach (TreeNode childTN in TNP.Nodes)                        {                            if (childTN.Checked)                            {                                YXZ = true;//还有选中的兄弟节点                                                           break;                            }                        }                        TNP.Checked = YXZ;//将遍历结果赋给父节点                            }                }            }        }        /// <summary>        /// 删除测量结果事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void RDeleteNode_Click(object sender, EventArgs e)        {            TreeNode tn = new TreeNode();            tn = treeView1.SelectedNode;            tn.Remove();        }        /// <summary>        /// 显示树节点        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)        {            e.DrawDefault = true;        }        /// <summary>        /// 当鼠标点击选择了        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        public void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)        {            TreeNode tn = (TreeNode)e.Node;            treeNodeSample = e.Node.Index;            string treeNodeName = e.Node.Text;            //正常indexadd值应该哪个为true哪个给它            int indexadd = e.Node.Index;            string checkednode = "";            foreach (TreeNode item in treeView1.Nodes)            {                if (item.Checked)                {                    checkednode = checkednode + "+" + item.Text;                }            }            if (checkednode.LastIndexOf("+") > 1)            {                checkednode = checkednode.Substring(1);            }            else            {                checkednode = "";            }            //插入多数据源选项            m_ReportApp.MoreSource = checkednode;            m_ConditionChoose.SetDefaultConditionValue();            m_ConditionChoose.DisCurrentPicProperty();//刷新            if (e.Button == MouseButtons.Right)//判断按下鼠标右键            {                Point ClickPoint = new Point(e.X, e.Y);                TreeNode CurrentNode = treeView1.GetNodeAt(ClickPoint);                if (CurrentNode == null && null == CurrentNode.Parent)//判断选择的是不是一个节点                {                    CurrentNode.ContextMenuStrip = contextMenuStrip2;                }                else                {                    CurrentNode.ContextMenuStrip = contextMenuStrip1;                    m_WorkSampleNode = CurrentNode;                }            }            this.Focus();        }        public void AddSampleResult(string str_path)        {            if (m_RstDataMgr.AddDataResult(str_path))            {                m_ConditionChoose.SetDefaultConditionValue();                m_ConditionChoose.GetWorkingPictureConditionVal();                m_ReportApp.m_RstWindow.Show(m_ReportApp.DockWindowPanel);                //在treeview上添加测量结果                m_TreeViewData.DisplayWorkSampleTree(this.m_RstDataMgr.ResultFilesList);                //在grid上添加测量结果                m_ConditionChoose.DisCurrentPicProperty();                //根据标签索引 显示默认的数据图表for test                m_ConditionChoose.ShowsTheDefaultPic();//显示图表            }            else            {                m_TreeViewData.DisplayWorkSampleTree(this.m_RstDataMgr.ResultFilesList);                m_ConditionChoose.SetDefaultConditionValue();                m_ConditionChoose.DisCurrentPicProperty();            }        }        /// <summary>        /// 树节点删除事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void RDeleteNode_Click_1(object sender, EventArgs e)        {            RemoveSample();        }        //ReportApp窗口给 RetMgrWindow 发送窗口删除样品回复        public void RemoveSample()        {            if (this.treeView1.SelectedNode == null) return;            string str1 = table["str1"].ToString();            string str2 = table["str2"].ToString();            string sDeleteSampleName = str1;            var sDeletSName = this.treeView1.SelectedNode.Text;            sDeleteSampleName += sDeletSName;            sDeleteSampleName += str2;            if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))            {                //删除当前选中的节点                treeView1.Nodes.Remove(this.treeView1.SelectedNode);   //移除当前工作样品                if ("" == sDeletSName)                {                    return;                }                //重新获取Treeview上的工作样品节点                this.m_TreeViewData.GetTreeWorkSampleNode(sDeletSName);                //设置工作样品焦点                this.m_TreeViewData.ReSetWorkSampleFoucs();                //当节点全部删除完时刷新树以及主窗口的控件                if (treeView1.Nodes.Count == 0)                {                    //treeView1.Nodes.Clear();                    //如果已经没有测量结果,则将报告程序初始化到刚打开的状态                    m_ReportApp.InitReportProState();                }                else                {                    //重新加载grid窗口                    m_ConditionChoose.DisCurrentPicProperty();                    //删除树上的节点                    m_WorkSampleName = m_ReportApp.m_rstDataMgr.GetSampleName();                    m_TreeViewData.GetTreeWorkSampleNode(m_WorkSampleName);                }            }            m_RstDataMgr.RemoveDataResult(sDeletSName);            var rstlist = m_ConditionChoose.m_conditionData.GetComboDownListByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);            rstlist.Remove(sDeletSName);            m_ConditionChoose.m_conditionData.SetComboDownListByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE, rstlist);            if (rstlist.Count > 0)            {                m_ConditionChoose.m_conditionData.SetPropByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE, rstlist[0]);                m_ConditionChoose.m_conditionData.SetItemvalByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE, 0);            }            m_ConditionChoose.DisCurrentPicProperty();        }        //切换当前工作样品        //string sNewWorkSample : 新的工作样品名        public void MeasureApp_SwitchSample(string sNewName)        {            m_TreeViewData.SetNewWorkSample(sNewName);        }        #endregion        #region 相关树控件方法        //是否为选择工作样品的节点(窗口切换)        public void SelectWorkSampleNode()        {            try            {                //是否添加结果文件                                if (m_RstDataMgr.ResultFilesList.Count != 0)                {                    if (m_RstDataMgr.GetWorkingResultId() != -1)                        if (m_RstDataMgr.ResultFilesList[m_RstDataMgr.GetWorkingResultId()] != null)                        {                            string workSampleName = m_RstDataMgr.ResultFilesList[m_RstDataMgr.GetWorkingResultId()].anotherFileName;                            //设置工作样品                            if (m_ReportApp.m_RstWindow.treeView1.Nodes.Count > 0)                            {                                foreach (TreeNode item in m_ReportApp.m_RstWindow.treeView1.Nodes)                                {                                    //设置选择TreeNode                                    if (item.Text == workSampleName)                                    {                                        m_ReportApp.m_RstWindow.treeView1.SelectedNode = item;                                        break;                                    }                                }                            }                        }                }            }            catch (Exception)            {            }        }        /// <summary>        /// 设置树控件各节点的状态        /// </summary>        /// <param name="TN"></param>        /// <param name="flag"></param>        private void DG_Check(TreeNode TN, bool flag)        {            if (TN.Nodes.Count > 0)            {                foreach (TreeNode childTN in TN.Nodes)                {                    childTN.Checked = flag;                    DG_Check(childTN, flag);                }            }        }        /// <summary>        /// 隐藏树节点,复选框        /// </summary>        /// <param name="tvw"></param>        /// <param name="node"></param>        public void HideCheckBox(TreeView tvw, TreeNode node)        {            TVITEM tvi = new TVITEM();            tvi.hItem = node.Handle;            tvi.mask = TVIF_STATE;            tvi.stateMask = TVIS_STATEIMAGEMASK;            tvi.state = 0;            SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);        }        #endregion        #region 多数据源操作部份相关        private void button1_Click(object sender, EventArgs e)        {            frmMultiSourceSelect frm_Mss = new frmMultiSourceSelect(this.treeView1);            if (frm_Mss.ShowDialog() == DialogResult.OK)            {                //判断是否选择了两个以上的选项,                int iselectcount = 0;                //第一次更新各选项值                for (int i = 0; i < frm_Mss.treeView1.Nodes.Count; i++)                {                    this.treeView1.Nodes[i].Checked = frm_Mss.treeView1.Nodes[i].Checked;                    if (frm_Mss.treeView1.Nodes[i].Checked == true)                    {                        iselectcount++;                    }                }                //主动去更新让其选择上多数据源或非多数据源                if (iselectcount >= 2)                {                    //获取                    //OTSSampleMeaInfo SMInfo = new OTSSampleMeaInfo();                    //DataMgrFun dataMgr = m_ReportApp.m_DataMgrFun;                    //dataMgr.SetSampleParamVal(OTS_RETORT_PROP_GRID_ITEMS.DATA_SOURCE, OTS_ITEM_TYPES.COMBO, 0);                    //获取属性窗口更新显示                    //dataMgr.GetWorkSamplePropertyVal(ref SMInfo);                    //m_ReportApp.m_PropWindow.DisProperyWindow(SMInfo);                    //显示默认的图表                    //m_ReportApp.m_PropWindow.m_SampleGrid.ShowDataDiagram();                }                else                {                    //单一选项时,也要对该属性窗口进行切换                    for (int i = 0; i < frm_Mss.treeView1.Nodes.Count; i++)                    {                        if (frm_Mss.treeView1.Nodes[i].Checked == true)                        {                            //OTSSampleMeaInfo SMInfo = new OTSSampleMeaInfo();                            //DataMgrFun dataMgr = m_ReportApp.m_DataMgrFun;                            //dataMgr.SetSampleParamVal(OTS_RETORT_PROP_GRID_ITEMS.DATA_SOURCE, OTS_ITEM_TYPES.COMBO, i);                            ////获取属性窗口更新显示                            //dataMgr.GetWorkSamplePropertyVal(ref SMInfo);                            //m_ReportApp.m_PropWindow.DisProperyWindow(SMInfo);                            ////显示默认的图表                            //m_ReportApp.m_PropWindow.m_SampleGrid.ShowDataDiagram();                        }                    }                }            }        }        #endregion        private void 计算边界颗粒合成ToolStripMenuItem_Click(object sender, EventArgs e)        {            if (this.treeView1.SelectedNode == null) return;                       //string sDeleteSampleName = str1;            var SampleName = this.treeView1.SelectedNode.Text;          var resultfile=  m_RstDataMgr.GetResultFileObjByName(SampleName);            if (resultfile == null) return;            var log = NLog.LogManager.GetCurrentClassLogger();            log.Info("Merging big particles which are crossing the field edge!");            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;            int scanfldsize = (int)resultfile.GetScanFieldSizeX();            List<COTSParticleClr> mergedParticles = new List<COTSParticleClr>();            double pixelSize = resultfile.GetPixelSize();            Size s = new Size(resultfile.GetImageWidth(), resultfile.GetImageHeight());           MergeBigBoundaryParticles(resultfile.List_OTSField, pixelSize, scanfldsize, s, ref mergedParticles);                       OTSCLRINTERFACE.ImageProForClr imgpro = new OTSCLRINTERFACE.ImageProForClr();                        foreach (COTSParticleClr part in mergedParticles)            {                imgpro.CalcuParticleImagePropertes(part, pixelSize);            }                   string libname = resultfile.GetSTDName();            int steelTech = resultfile.GetIncASteeltech();            ClassifyParticle(mergedParticles, libname, m_ReportApp.m_RptConfigFile.Systype, steelTech);                       log.Info("begin merged particle data db saving...");            SaveMergedParticles(mergedParticles,resultfile.GetResultDBPath());            MessageBox.Show("边界颗粒合成完成!");            this.Cursor = System.Windows.Forms.Cursors.Default;        }        public bool MergeBigBoundaryParticles(List<OTSCommon.Model.Field> allFields, double pixelSize, int scanFieldSize, System.Drawing.Size ResolutionSize, ref List<COTSParticleClr> mergedParts)        {            List<COTSFieldDataClr> fldclrs = new List<COTSFieldDataClr>();            ImageProForClr imgpro = new ImageProForClr();            foreach (var f in allFields)            {                COTSFieldDataClr fldclr = new COTSFieldDataClr();                               PointF p1 = f.GetOTSPosition();                System.Drawing.Point p2 = new System.Drawing.Point((int)p1.X, (int)p1.Y);                fldclr.SetPosition((int)p1.X, (int)p1.Y);                fldclr.SetImageWidth(ResolutionSize.Width);                fldclr.SetImageHeight(ResolutionSize.Height);                var parts = f.ParticleList;                foreach (var p in parts)                {                    COTSParticleClr part = new COTSParticleClr();                    COTSFeatureClr fea = new COTSFeatureClr();                    List<COTSSegmentClr> segs = new List<COTSSegmentClr>();                                       foreach (var s in p.SegmentList)                    {                        COTSSegmentClr seg = new COTSSegmentClr();                        seg.SetStart(s.Start);                        seg.SetHeight(s.Height);                        seg.SetLength(s.Length);                        segs.Add(seg);                                        }                    fea.SetSegmentsList(segs,true);                    part.SetFeature(fea);                    var xray = part.GetXray();                                       foreach (var ele in p.ElementList)                    {                        CElementChemistryClr eleclr = new CElementChemistryClr();                        eleclr.SetName(ele.Name);                        eleclr.SetPercentage(ele.Percentage);                        xray.AddQuantifyElement(eleclr);                    }                    part.SetFieldId(p.FieldId);                    part.SetAnalysisId(p.XrayId);                    part.SetXray(xray);                    part.SetActualArea(p.Area);                    part.SetAbsolutPos(new Point(p.PosX, p.PosY));                    part.CalCoverRect();                    part.CalXrayPos();                                       fldclr.AddParticle(part);                }                fldclrs.Add(fldclr);            }                      imgpro.MergeBigBoundaryParticles(fldclrs, pixelSize, scanFieldSize, ResolutionSize, mergedParts);            return true;        }        private bool ClassifyParticle(List<COTSParticleClr> parts,string libname, OTS_SysType_ID systype,int steeltech)        {            bool r = true;            try            {                if (systype == OTS_SysType_ID.IncA)                {                  r=  COffLineClassifyLogic.ClassifyIncA(parts, libname,steeltech);                }                else if (systype == OTS_SysType_ID.CleannessA)                {                   r= COffLineClassifyLogic.ClassifyCleannessA(parts, libname);                }                return r;            }            catch (Exception e)            {                NLog.LogManager.GetCurrentClassLogger().Error("merged parts classify failed. " + e.Message);                return false;            }        }        public bool SaveMergedParticles(List<COTSParticleClr> mergedParts,string dbfile)        {            CIncAFileMgr pDBFileMgr = new CIncAFileMgr(dbfile);            var mergedpartdb = pDBFileMgr.GetMergedParticleDB();            foreach (COTSParticleClr part in mergedParts)            {                mergedpartdb.SaveAParticle(part, part.GetXray(), (Point)part.GetAbsolutPos());            }            CPosXrayDBMgr pXrayDBMgr = pDBFileMgr.GetPosXrayDBMgr();            CElementChemistryDB xraydb = pXrayDBMgr.GetElementChemistryDB();            List<CPosXrayClr> ches = new List<CPosXrayClr>();            foreach (COTSParticleClr part in mergedParts)            {                ches.Add(part.GetXray());            }            xraydb.SaveElementChemistriesList(ches);            return true;        }    }}
 |