Esempio n. 1
0
        private void ShrinkBondLinesPass1(Progress pb)
        {
            // so that they do not overlap label characters

            if (_convexHulls.Count > 1)
            {
                pb.Show();
            }
            pb.Message = "Clipping Bond Lines - Pass 1";
            pb.Value   = 0;
            pb.Maximum = _convexHulls.Count;

            foreach (var hull in _convexHulls)
            {
                pb.Increment(1);

                // select lines which start or end with this atom
                var targeted = from l in _bondLines
                               where (l.StartAtomId == hull.Key | l.EndAtomId == hull.Key)
                               select l;

                foreach (BondLine bl in targeted.ToList())
                {
                    Point start = new Point(bl.Start.X, bl.Start.Y);
                    Point end   = new Point(bl.End.X, bl.End.Y);

                    bool outside;
                    var  r = GeometryTool.ClipLineWithPolygon(start, end, hull.Value, out outside);

                    switch (r.Length)
                    {
                    case 3:
                        if (outside)
                        {
                            bl.Start = new Point(r[0].X, r[0].Y);
                            bl.End   = new Point(r[1].X, r[1].Y);
                        }
                        else
                        {
                            bl.Start = new Point(r[1].X, r[1].Y);
                            bl.End   = new Point(r[2].X, r[2].Y);
                        }
                        break;

                    case 2:
                        if (!outside)
                        {
                            // This line is totally inside so remove it!
                            _bondLines.Remove(bl);
                        }
                        break;
                    }
                }
            }
        }
        private void DrawHatchBond(Wpg.WordprocessingGroup wordprocessingGroup, List <Point> points, string colour = "000000")
        {
            // To Store diagnostic lines
            List <BondLine> diagnostics = new List <BondLine>();

            Point wedgeStart     = points[0];
            Point wedgeEndMiddle = points[2];

            // Draw a small circle for the starting point
            var  xx = 0.5;
            Rect bb = new Rect(new Point(points[0].X - xx, points[0].Y - xx), new Point(points[0].X + xx, points[0].Y + xx));

            DrawShape(wordprocessingGroup, bb, A.ShapeTypeValues.Ellipse, colour);

            // Vector pointing from wedgeStart to wedgeEndMiddle
            Vector direction   = wedgeEndMiddle - wedgeStart;
            Matrix rightAngles = new Matrix();

            rightAngles.Rotate(90);
            Vector perpendicular = direction * rightAngles;

            Vector step = direction;

            step.Normalize();
            step *= 15 * OoXmlHelper.MULTIPLE_BOND_OFFSET_PERCENTAGE;

            int    steps      = (int)Math.Ceiling(direction.Length / step.Length);
            double stepLength = direction.Length / steps;

            step.Normalize();
            step *= stepLength;

            Point p0 = wedgeStart + step;
            Point p1 = p0 + perpendicular;
            Point p2 = p0 - perpendicular;
            //diagnostics.Add(new BondLine(BondLineStyle.Dotted, p1, p2));

            bool outside;
            var  r = GeometryTool.ClipLineWithPolygon(p1, p2, points, out outside);

            while (r.Length > 2)
            {
                if (r.Length == 4)
                {
                    DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, r[1], r[2]));
                }

                if (r.Length == 6)
                {
                    DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, r[1], r[2]));
                    DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, r[3], r[4]));
                }

                p0 = p0 + step;
                p1 = p0 + perpendicular;
                p2 = p0 - perpendicular;
                //diagnostics.Add(new BondLine(BondLineStyle.Dotted, p1, p2));

                r = GeometryTool.ClipLineWithPolygon(p1, p2, points, out outside);
            }

            // Draw Tail Lines
            DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, wedgeEndMiddle, points[1]));
            DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, wedgeEndMiddle, points[3]));

            //diagnostics.Add(new BondLine(BondLineStyle.Dotted, points[0], points[1]));
            //diagnostics.Add(new BondLine(BondLineStyle.Dotted, points[0], points[3]));
            //diagnostics.Add(new BondLine(BondLineStyle.Dotted, points[2], points[1]));
            //diagnostics.Add(new BondLine(BondLineStyle.Dotted, points[2], points[3]));
            //diagnostics.Add(new BondLine(BondLineStyle.Dotted, points[0], points[2]));
            foreach (var line in diagnostics)
            {
                DrawBondLine(wordprocessingGroup, line, "ff0000");
            }
        }