Exemplo n.º 1
0
        /// <summary>
        /// 根据最后一个分子,以及分支数量,划分支线
        /// </summary>
        /// <param name="right_x"></param>
        /// <param name="center_y"></param>
        /// <param name="num"></param>
        private void WriteBranchLine(double right_x, double center_y, List <double> listHigh, MDocument md)
        {
            //水平线部分
            MPoint     p1     = new MPoint(right_x + SpanceX * (0.5 - SpaceLineScale / 2), center_y);
            MPoint     p2     = new MPoint(right_x + SpanceX * 0.5, center_y);
            MRectangle arrow1 = new MRectangle(p1, p2);

            md.addObject(arrow1);;
            //划竖直线
            double topy    = -9999999;
            double bottomy = 9999999;

            foreach (var item in listHigh)
            {
                topy    = topy < item ? item : topy;
                bottomy = bottomy > item ? item : bottomy;
            }
            MPoint     p3     = new MPoint(right_x + SpanceX * 0.5, topy);
            MPoint     p4     = new MPoint(right_x + SpanceX * 0.5, bottomy);
            MRectangle arrow2 = new MRectangle(p3, p4);

            md.addObject(arrow2);
            //根据传入的高度记录划水平分支线
            foreach (double high in listHigh)
            {
                MPoint     p5     = new MPoint(right_x + SpanceX * 0.5, high);
                MPoint     p6     = new MPoint(right_x + SpanceX * (0.5 + SpaceLineScale / 2), high);
                MRectangle arrow3 = new MRectangle(p5, p6);
                md.addObject(arrow3);
            }
        }
Exemplo n.º 2
0
        private MemoryStream writeq()
        {
            //树绘图
            MDocument md    = new MDocument(MolImporter.importMol("O"));
            MPoint    p1    = new MPoint(1, 1);
            MPoint    p2    = new MPoint(1, 2);
            MPolyline arrow = new MRectangle(p1, p2);

            md.addObject(arrow);
            MemoryStream stream = new MemoryStream(MolExporter.exportToBinFormat(md, "mrv"));

            return(stream);
        }
Exemplo n.º 3
0
        private void WriteText(MDocument md, int bracnchIndex)
        {
            double max = 9999999;

            foreach (var item in _DicListTextPosition[bracnchIndex])
            {
                var    list = item.Split(',').ToList();
                double y    = Convert.ToDouble(list[2]);
                if (max > y)
                {
                    max = y;
                }
            }
            foreach (var item in _DicListTextPosition[bracnchIndex])
            {
                var    list = item.Split(',').ToList();
                double x    = Convert.ToDouble(list[1]);
                md.addObject(CreateMTextBox(list[0], new MPoint(x, max)));
            }
            _DicListTextPosition[bracnchIndex] = new List <string>();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 不包括根点的树单分支递归绘制
        /// </summary>
        /// <param name="previousMp">前一个mol类</param>
        /// <param name="branchList">分支smiles记录</param>
        /// <param name="index">当前次序</param>
        /// <param name="rootMol">根mol</param>
        /// <param name="md">文档对象</param>
        /// <param name="isRoot">是否是最长分支路线</param>
        private void WriteSimpleBranch(MoleCulePostion previousMp, List <string> branchList, int index, Molecule rootMol, MDocument md, bool isRoot)
        {
            double molLeftSpace = 0;

            if (branchList.Count <= index)
            {
                //WriteText(md);
                return;
            }
            double curY = previousMp.Center_y;
            double curX = previousMp.Right_x;

            if (index % BranchOneLineNum == 0)
            {
                curY -= SpanceY * BranchSPFWithY;
                curX  = 0 - SpanceX * BranchSPFWithX;
                //WriteText(md);
            }
            //写反应的其他物质,仅限最长路线
            int    anotherMolNum = 0;
            double maxLength     = 0;

            if (!string.IsNullOrEmpty(DicBranchSmiles[index]) && isRoot)
            {
                List <string> listSmiles = DicBranchSmiles[index].Split(',').ToList();
                anotherMolNum = listSmiles.Count;
                if (listSmiles.Count == 1)
                {
                    var             molList        = listSmiles[0].Split(';').ToList();
                    MoleCulePostion mp1            = new MoleCulePostion(molList[0]);
                    double          leftDistance   = mp1.Center_x - mp1.Left_x;
                    double          bottomDistance = mp1.Center_y - mp1.Bottom_y;
                    maxLength = mp1.Right_x - mp1.Left_x + BranchAnotherMolDistanceX * 2;
                    SetMolPosition(mp1, previousMp.Right_x + leftDistance + BranchAnotherMolDistanceX,
                                   previousMp.Center_y + bottomDistance + BranchAnotherMolDistanceY + 1.5);
                    //写箭头上mol层次号
                    md.addObject(CreateMTextBox(molList[1],
                                                new MPoint(previousMp.Right_x + leftDistance + BranchAnotherMolDistanceX,
                                                           previousMp.Center_y + 1.5)));
                    rootMol.fuse(mp1.Mol);
                }
                else if (listSmiles.Count == 2)
                {
                    foreach (var smiles in listSmiles)
                    {
                        var             molList        = smiles.Split(';').ToList();
                        MoleCulePostion mp1            = new MoleCulePostion(molList[0]);
                        double          leftDistance   = mp1.Center_x - mp1.Left_x;
                        double          bottomDistance = mp1.Center_y - mp1.Bottom_y;
                        SetMolPosition(mp1, maxLength + previousMp.Right_x + leftDistance + BranchAnotherMolDistanceX,
                                       previousMp.Center_y + bottomDistance + BranchAnotherMolDistanceY + 1.5);
                        //写箭头上mol层次号
                        md.addObject(CreateMTextBox(molList[1],
                                                    new MPoint(maxLength + previousMp.Right_x + leftDistance + BranchAnotherMolDistanceX,
                                                               previousMp.Center_y + 1.5)));
                        rootMol.fuse(mp1.Mol);
                        maxLength += mp1.Right_x - mp1.Left_x + BranchAnotherMolDistanceX * 2;
                    }
                }
            }
            //箭头绘制;
            MPoint p1 = new MPoint(previousMp.Right_x + SpanceX * BranchSPFWithX * 0.15, previousMp.Center_y);
            MPoint p2 = new MPoint(previousMp.Right_x + SpanceX * BranchSPFWithX * 0.85, previousMp.Center_y);

            if (anotherMolNum == 2)
            {
                p1 = new MPoint(previousMp.Right_x + maxLength * 0.15, previousMp.Center_y);
                p2 = new MPoint(previousMp.Right_x + maxLength * 0.85, previousMp.Center_y);
            }
            if (anotherMolNum == 1)
            {
                p1 = new MPoint(previousMp.Right_x + maxLength * 0.15, previousMp.Center_y);
                p2 = new MPoint(previousMp.Right_x + maxLength * 0.85, previousMp.Center_y);
            }
            MPolyline arrow = new MPolyline(p1, p2);

            arrow.setArrow(true);
            arrow.setArrowLength(1, chemaxon.struc.graphics.MPolyline.DEFAULT_ARROW_HEAD_LENGTH / 2);
            arrow.setArrowWidth(1, chemaxon.struc.graphics.MPolyline.DEFAULT_ARROW_HEAD_WIDTH);
            arrow.setArrowFlags(1, chemaxon.struc.graphics.MPolyline.ARROW_DASHED_FLAG);
            md.addObject(arrow);
            //分子绘制
            var             molList1 = branchList[index].Split(';').ToList();
            MoleCulePostion tempMp   = new MoleCulePostion(molList1[0]);

            molLeftSpace = tempMp.Center_x - tempMp.Left_x;
            if (curX == -SpanceX * BranchSPFWithX)
            {
                molLeftSpace = 0;
                maxLength    = SpanceX * BranchSPFWithX;
            }
            if (anotherMolNum == 2)
            {
                SetMolPosition(tempMp, curX + maxLength + molLeftSpace, curY);
            }
            else if (anotherMolNum == 1)
            {
                SetMolPosition(tempMp, curX + maxLength + molLeftSpace, curY);
            }
            else if (anotherMolNum == 0)
            {
                SetMolPosition(tempMp, curX + SpanceX * BranchSPFWithX + molLeftSpace, curY);
            }
            rootMol.fuse(tempMp.Mol);
            //写mol层次号
            string txt = molList1[1];

            if (txt != "0a")
            {
                _ListTextPosition.Add(txt + "," + tempMp.Center_x + "," + (tempMp.Bottom_y - TxtspaceWithMolInY));
            }
            //下一级
            WriteSimpleBranch(tempMp, branchList, index + 1, rootMol, md, isRoot);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 遍历子节点加入画图中
        /// </summary>
        /// <param name="node">当前节点</param>
        /// <param name="md">画图对象</param>
        /// <param name="previousMp">前一个节点的位置坐标对象</param>
        /// <param name="RootMol">根mol</param>
        /// <param name="level">层级</param>
        private void SearchChildNode(TreeNodes node, MDocument md, MoleCulePostion previousMp, Molecule RootMol, int bracnchIndex)
        {
            double molLeftSpace = 0;
            int    num          = node.Children.Count;

            if (num == 1)
            {
                TreeNodes childNode = node.Children[0];
                //绘制
                MoleCulePostion mp = new MoleCulePostion(childNode.Smiles);
                molLeftSpace = mp.Center_x - mp.Left_x;
                SetMolPosition(mp, previousMp.Right_x + SpanceX + molLeftSpace, previousMp.Center_y);
                RootMol.fuse(mp.Mol);
                //写mol层次号
                string txt = ReactionSteps.ToString() + "a";
                _DicListTextPosition[bracnchIndex].Add(txt + "," + mp.Center_x + "," + (mp.Bottom_y - TxtspaceWithMolInY));

                //划水平线
                MPoint     p1    = new MPoint(previousMp.Right_x + SpanceX * (0.5 - SpaceLineScale / 2), previousMp.Center_y);
                MPoint     p2    = new MPoint(previousMp.Right_x + SpanceX * (0.5 + SpaceLineScale / 2), previousMp.Center_y);
                MRectangle arrow = new MRectangle(p1, p2);
                md.addObject(arrow);
                //写反应步次
                md.addObject(CreateMTextBox((ReactionSteps++).ToString(),
                                            new MPoint(previousMp.Right_x + SpanceX * 0.5, previousMp.Center_y + ReactionIndexSpaceWithLine)));

                //遍历子集
                SearchChildNode(childNode, md, mp, RootMol, bracnchIndex);
            }
            else if (num > 1)
            {
                WriteText(md, bracnchIndex);
                if (num % 2 == 0)
                {
                    //对称式绘出节点位置
                    double        topY     = previousMp.Center_y;
                    double        bottomY  = previousMp.Center_y;
                    List <double> listHigh = new List <double>();
                    List <char>   listChar = new List <char>();
                    for (int i = 0; i < num; i++)
                    {
                        listChar.Add((char)('a' + i));
                    }
                    var list = node.Children;
                    for (int i = 0; i < list.Count; i += 2)
                    {
                        //记录当前反应的步数
                        int    curStep = ReactionSteps++;
                        double tempY1  = list[i].ChildLeapNum * SpanceY;
                        double tempY2  = list[i + 1].ChildLeapNum * SpanceY;

                        topY    += tempY1 > tempY2 ? tempY1 : tempY2;
                        bottomY -= tempY1 > tempY2 ? tempY1 : tempY2;
                        listHigh.Add(topY);
                        listHigh.Add(bottomY);
                        //上半部分
                        MoleCulePostion mp1 = new MoleCulePostion(list[i].Smiles);
                        molLeftSpace = mp1.Center_x - mp1.Left_x;
                        SetMolPosition(mp1, previousMp.Right_x + SpanceX + molLeftSpace, topY);
                        RootMol.fuse(mp1.Mol);
                        //写mol层次号
                        string txt1 = curStep.ToString() + listChar[num - (num / 2 + i / 2) - 1];
                        _DicListTextPosition[0].Add(txt1 + "," + mp1.Center_x + "," + (mp1.Bottom_y - TxtspaceWithMolInY));
                        //找子集
                        SearchChildNode(list[i], md, mp1, RootMol, 0);

                        //下半部分
                        MoleCulePostion mp2 = new MoleCulePostion(list[i + 1].Smiles);
                        molLeftSpace = mp2.Center_x - mp2.Left_x;
                        SetMolPosition(mp2, previousMp.Right_x + SpanceX + molLeftSpace, bottomY);
                        RootMol.fuse(mp2.Mol);
                        //写mol层次号
                        string txt2 = curStep.ToString() + listChar[num / 2 + i / 2];
                        _DicListTextPosition[2].Add(txt2 + "," + mp2.Center_x + "," + (mp2.Bottom_y - TxtspaceWithMolInY));
                        //写反应步次
                        double startWithText = 0.5 - SpaceLineScale / 4;
                        md.addObject(CreateMTextBox((curStep).ToString(),
                                                    new MPoint(previousMp.Right_x + SpanceX * startWithText, previousMp.Center_y + ReactionIndexSpaceWithLine)));
                        WriteBranchLine(previousMp.Right_x, previousMp.Center_y, listHigh, md);

                        //找子集
                        SearchChildNode(list[i + 1], md, mp2, RootMol, 2);
                    }
                }
                else
                {
                    //记录当前反应的步数
                    int           curStep  = ReactionSteps++;
                    double        topY     = previousMp.Center_y;
                    double        bottomY  = previousMp.Center_y;
                    List <double> listHigh = new List <double>();
                    List <char>   listChar = new List <char>();
                    for (int i = 0; i < num; i++)
                    {
                        listChar.Add((char)('a' + i));
                    }
                    var list = node.Children;
                    //先绘画水平节点
                    MoleCulePostion mp = new MoleCulePostion(list[0].Smiles);
                    molLeftSpace = mp.Center_x - mp.Left_x;
                    SetMolPosition(mp, previousMp.Right_x + SpanceX + molLeftSpace, previousMp.Center_y);
                    RootMol.fuse(mp.Mol);
                    //写mol层次号
                    string txt = curStep.ToString() + listChar[num / 2];
                    _DicListTextPosition[1].Add(txt + "," + mp.Center_x + "," + (mp.Bottom_y - TxtspaceWithMolInY));
                    //找子集
                    SearchChildNode(list[0], md, mp, RootMol, 1);
                    //分隔两侧间距
                    double high_mp = list[0].ChildLeapNum * SpanceY;
                    topY    += high_mp;
                    bottomY -= high_mp;
                    listHigh.Add(previousMp.Center_y);
                    //两端节点
                    for (int i = 1; i < list.Count; i += 2)
                    {
                        double tempY1 = list[i].ChildLeapNum * SpanceY;
                        double tempY2 = list[i + 1].ChildLeapNum * SpanceY;

                        topY    += tempY1 > tempY2 ? tempY1 : tempY2;
                        bottomY -= tempY1 > tempY2 ? tempY1 : tempY2;
                        listHigh.Add(topY);
                        listHigh.Add(bottomY);
                        //上半部分
                        MoleCulePostion mp1 = new MoleCulePostion(list[i].Smiles);
                        molLeftSpace = mp1.Center_x - mp1.Left_x;
                        SetMolPosition(mp1, previousMp.Right_x + SpanceX + molLeftSpace, topY);
                        RootMol.fuse(mp1.Mol);
                        //写mol层次号
                        string txt1 = curStep.ToString() + listChar[num / 2 - 1 - i / 2];
                        _DicListTextPosition[0].Add(txt1 + "," + mp1.Center_x + "," + (mp1.Bottom_y - TxtspaceWithMolInY));
                        //找子集
                        SearchChildNode(list[i], md, mp1, RootMol, 0);

                        //下半部分
                        MoleCulePostion mp2 = new MoleCulePostion(list[i + 1].Smiles);
                        molLeftSpace = mp2.Center_x - mp2.Left_x;
                        SetMolPosition(mp2, previousMp.Right_x + SpanceX + molLeftSpace, bottomY);
                        RootMol.fuse(mp2.Mol);
                        //写mol层次号
                        string txt2 = curStep.ToString() + listChar[num / 2 + 1 + i / 2];
                        _DicListTextPosition[2].Add(txt2 + "," + mp2.Center_x + "," + (mp2.Bottom_y - TxtspaceWithMolInY));

                        //写反应步次
                        double startWithText = 0.5 - SpaceLineScale / 4;
                        md.addObject(CreateMTextBox((curStep).ToString(), new MPoint(previousMp.Right_x + SpanceX * startWithText, previousMp.Center_y + ReactionIndexSpaceWithLine)));
                        WriteBranchLine(previousMp.Right_x, previousMp.Center_y, listHigh, md);
                        //找子集
                        SearchChildNode(list[i + 1], md, mp2, RootMol, 2);
                    }
                }
            }
            else
            {
                WriteText(md, bracnchIndex);
            }
        }