Ejemplo n.º 1
0
    public static GameObject a(Point A_0)
    {
        Vector2 vector = CoordinateTool.ConvertPoint2Vector(A_0);
        bool    flag   = false;

        return(global::x.a(vector, ref flag));
    }
Ejemplo n.º 2
0
    public static GameObject b(Point A_0)
    {
        Point   pt     = CoordinateTool.ConvertMobile2Unity(A_0);
        Vector2 vector = CoordinateTool.ConvertPoint2Vector(pt);
        bool    flag   = false;

        return(global::x.a(vector, ref flag));
    }
Ejemplo n.º 3
0
    public Rectangle c(Camera A_0, GameObject A_1)
    {
        Collider component = A_1.GetComponent <Collider>();

        if (A_1.activeInHierarchy && component != null && component.enabled)
        {
            return(CoordinateTool.WorldBoundsToScreenRect(A_0, component.bounds));
        }
        return(null);
    }
Ejemplo n.º 4
0
    public Rectangle a(Camera A_0, GameObject A_1)
    {
        Renderer component = A_1.GetComponent <Renderer>();

        if (component != null)
        {
            return(CoordinateTool.WorldBoundsToScreenRect(A_0, component.bounds));
        }
        return(null);
    }
Ejemplo n.º 5
0
    public Rectangle d(Camera A_0, GameObject A_1)
    {
        MeshFilter component = A_1.GetComponent <MeshFilter>();

        if (component != null && component.sharedMesh != null)
        {
            Mesh sharedMesh = component.sharedMesh;
            return(CoordinateTool.WorldBoundsToScreenRect(A_0, sharedMesh.bounds));
        }
        return(null);
    }
Ejemplo n.º 6
0
        private void DrawHashBondLines(Wpg.WordprocessingGroup wordprocessingGroup1, List <Point> points)
        {
            // Create modifyable Points
            Point p0 = new Point(points[0].X, points[0].Y);
            Point p1 = new Point(points[1].X, points[1].Y);
            Point p2 = new Point(points[2].X, points[2].Y);

            // Draw Tail Line
            BondLine blTail = new BondLine(points[1], points[2], BondLineStyle.Solid, null, null);

            DrawBondLine(wordprocessingGroup1, blTail);

            // Prep for intermediate lines
            Point  midPoint = CoordinateTool.GetMidPoint(points[1], points[2]);
            Vector v        = points[0] - midPoint;
            double ticks    = v.Length / 2;

            v = v / ticks;

            BondLine blNext;

            Point outIntersectP1;
            Point outIntersectP2;

            Point leftTailEnd  = p1;
            Point rightTailEnd = p2;

            bool linesIntersect;
            bool segmentsIntersect;

            // Draw itermediate lines
            for (int i = 1; i <= (int)ticks; i++)
            {
                p1.Offset(v.X, v.Y);
                p2.Offset(v.X, v.Y);
                CoordinateTool.FindIntersection(leftTailEnd, p0, p1, p2,
                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                CoordinateTool.FindIntersection(rightTailEnd, p0, p1, p2,
                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);
                blNext = new BondLine(outIntersectP1, outIntersectP2, BondLineStyle.Solid, null, null);
                DrawBondLine(wordprocessingGroup1, blNext);
            }

            // Draw small line for nose
            Point n1 = new Point(points[0].X - 0.025, points[0].Y - 0.025);
            Point n2 = new Point(points[0].X + 0.025, points[0].Y + 0.025);

            BondLine blNose = new BondLine(n1, n2, BondLineStyle.Solid, null, null);

            DrawBondLine(wordprocessingGroup1, blNose);
        }
Ejemplo n.º 7
0
        private void TrimVector(Point line1Start, Point line1End, Point line2Start, Point line2End, ref Vector vector)
        {
            bool  intersect;
            Point intersection;

            CoordinateTool.FindIntersection(line1Start, line1End, line2Start, line2End,
                                            out _, out intersect, out intersection);
            if (intersect)
            {
                Vector v = intersection - line1Start;
                if (v.Length < vector.Length)
                {
                    vector = v;
                }
            }
        }
Ejemplo n.º 8
0
    public static List <UINode> a()
    {
        string[] array = new string[]
        {
            global::x.d,
            global::x.e,
            global::x.f
        };
        string[] array2 = new string[]
        {
            global::x.p,
            global::x.q,
            global::x.r
        };
        HashSet <int> hashSet = new HashSet <int>();
        List <UINode> list    = new List <UINode>();
        Rectangle     rect    = new Rectangle();

        for (int i = 0; i < array.Length; i++)
        {
            Type type = Type.GetType(array[i]);
            if (type == null)
            {
                type = Type.GetType(array2[i]);
            }
            if (type != null)
            {
                Component[] array3 = UnityEngine.Object.FindObjectsOfType(type) as Component[];
                Component[] array4 = array3;
                for (int j = 0; j < array4.Length; j++)
                {
                    Component  component  = array4[j];
                    GameObject gameObject = component.gameObject;
                    global::u.d("Find GameObject " + gameObject.name);
                    if (!hashSet.Contains(gameObject.GetInstanceID()) && global::x.a(gameObject, ref rect))
                    {
                        Rectangle bound = CoordinateTool.ConvertUnity2Mobile(rect);
                        UINode    item  = new UINode(gameObject, bound);
                        hashSet.Add(gameObject.GetInstanceID());
                        list.Add(item);
                    }
                }
            }
        }
        return(list);
    }
Ejemplo n.º 9
0
        private bool TrimLine(BondLine leftOrRight, BondLine line, bool isInRing)
        {
            bool  dummy;
            bool  intersect;
            Point intersection;

            // Make a longer version of the line
            Point startLonger = new Point(leftOrRight.Start.X, leftOrRight.Start.Y);
            Point endLonger   = new Point(leftOrRight.End.X, leftOrRight.End.Y);

            CoordinateTool.AdjustLineAboutMidpoint(ref startLonger, ref endLonger, _medianBondLength / 5);

            // See if they intersect at one end
            CoordinateTool.FindIntersection(startLonger, endLonger, line.Start, line.End,
                                            out dummy, out intersect, out intersection);

            // If they intersect update the main line
            if (intersect)
            {
                double l1 = CoordinateTool.DistanceBetween(intersection, leftOrRight.Start);
                double l2 = CoordinateTool.DistanceBetween(intersection, leftOrRight.End);
                if (l1 > l2)
                {
                    leftOrRight.End = new Point(intersection.X, intersection.Y);
                }
                else
                {
                    leftOrRight.Start = new Point(intersection.X, intersection.Y);
                }
                if (!isInRing)
                {
                    l1 = CoordinateTool.DistanceBetween(intersection, line.Start);
                    l2 = CoordinateTool.DistanceBetween(intersection, line.End);
                    if (l1 > l2)
                    {
                        line.End = new Point(intersection.X, intersection.Y);
                    }
                    else
                    {
                        line.Start = new Point(intersection.X, intersection.Y);
                    }
                }
            }

            return(intersect);
        }
Ejemplo n.º 10
0
 protected void d()
 {
     try
     {
         Cmd     a_      = Cmd.TOUCH_NOTIFY;
         j       j       = new j(a_, this.n);
         Touch[] touches = Input.touches;
         int     num     = touches.Length;
         if (num != 0)
         {
             bool        flag            = false;
             TouchNotify touchNotify     = new TouchNotify();
             string      loadedLevelName = Application.loadedLevelName;
             touchNotify.scene = loadedLevelName;
             int num2 = 0;
             while (num2 < num && num2 < 5)
             {
                 Touch touch = touches[num2];
                 global::u.c("Touch delta time = {0},x = {1},y={2} ,fingerId = {3},phase = {4}", new object[]
                 {
                     touch.deltaTime *Time.timeScale,
                     touch.position.x,
                     touch.position.y,
                     touch.fingerId,
                     touch.phase
                 });
                 if (touch.phase == TouchPhase.Began && !flag)
                 {
                     GameObject gameObject = null;
                     try
                     {
                         gameObject = x.a(new Point(touch.position.x, touch.position.y));
                     }
                     catch (Exception ex)
                     {
                         global::u.d(ex.StackTrace);
                     }
                     if (gameObject != null && x.a(gameObject))
                     {
                         flag = true;
                         string text = global::g.b(gameObject);
                         global::u.c("Touch UI = " + text);
                         touchNotify.name = text;
                     }
                 }
                 if (touch.phase != TouchPhase.Canceled && touch.phase != TouchPhase.Stationary && touch.phase != TouchPhase.Moved)
                 {
                     TouchData touchData = new TouchData();
                     touchData.deltatime = (float)(DateTime.Now.Ticks / 10000L - this.a);
                     touchData.fingerId  = (short)touch.fingerId;
                     Point point = CoordinateTool.ConvertUnity2Mobile(touch.position);
                     touchData.x         = point.X;
                     touchData.y         = point.Y;
                     touchData.relativeX = touch.position.x / (float)Screen.width;
                     touchData.relativeY = ((float)Screen.height - touch.position.y) / (float)Screen.height;
                     TouchPhase phase = touch.phase;
                     if (phase != TouchPhase.Began)
                     {
                         if (phase == TouchPhase.Ended)
                         {
                             touchData.phase = 2;
                         }
                     }
                     else
                     {
                         touchData.phase = 1;
                     }
                     touchNotify.touches.Add(touchData);
                 }
                 num2++;
             }
             if (touchNotify.touches.Count > 0)
             {
                 j.b = touchNotify;
                 global::o.a(j);
             }
         }
     }
     catch (Exception ex2)
     {
         global::u.a(ex2.Message + "\n" + ex2.StackTrace);
         Cmd a_2 = Cmd.TOUCH_NOTIFY;
         global::o.a(new j(a_2, this.n)
         {
             b = ex2.Message + "\n" + ex2.StackTrace,
             f = ResponseStatus.UN_KNOW_ERROR
         });
     }
 }
Ejemplo n.º 11
0
    public Rectangle d(GameObject A_0)
    {
        if (A_0 == null)
        {
            return(null);
        }
        Camera camera = base.h(A_0);

        if (camera == null)
        {
            return(null);
        }
        Rectangle rectangle = base.c(camera, A_0);

        if (rectangle == null)
        {
            rectangle = x.a(camera, A_0);
        }
        if (rectangle == null)
        {
            rectangle = base.b(camera, A_0);
        }
        if (rectangle == null)
        {
            return(null);
        }
        u.d(string.Concat(new object[]
        {
            "GetBound gameobject =",
            A_0.name,
            "  rc.x=",
            rectangle.x,
            ", rc.y=",
            rectangle.y,
            ", wight = ",
            rectangle.width,
            ", height=",
            rectangle.height
        }));
        float num  = 0f;
        float num2 = 0f;

        if (CoordinateTool.GetCurrenScreenScale(ref num, ref num2))
        {
            rectangle.x      *= num;
            rectangle.y      *= num2;
            rectangle.width  *= num;
            rectangle.height *= num2;
            u.d(string.Concat(new object[]
            {
                "GetBound() after scale : rc.x=",
                rectangle.x,
                ", rc.y=",
                rectangle.y,
                ", wight = ",
                rectangle.width,
                ", height=",
                rectangle.height
            }));
        }
        return(rectangle);
    }
Ejemplo n.º 12
0
        public void DrawWedgeBond(Wpg.WordprocessingGroup wordprocessingGroup, BondLine bl)
        {
            BondLine leftBondLine  = bl.GetParallel(BondOffset() / 2);
            BondLine rightBondLine = bl.GetParallel(-BondOffset() / 2);

            List <Point> points = new List <Point>();

            points.Add(new Point(bl.Start.X, bl.Start.Y));
            points.Add(new Point(leftBondLine.End.X, leftBondLine.End.Y));
            points.Add(new Point(bl.End.X, bl.End.Y));
            points.Add(new Point(rightBondLine.End.X, rightBondLine.End.Y));

            Point wedgeStart     = new Point(bl.Start.X, bl.Start.Y);
            Point wedgeEndLeft   = new Point(leftBondLine.End.X, leftBondLine.End.Y);
            Point wedgeEndRight  = new Point(rightBondLine.End.X, rightBondLine.End.Y);
            Point wedgeEndMiddle = new Point(bl.End.X, bl.End.Y);

            Bond thisBond = bl.Bond;
            Atom endAtom  = thisBond.EndAtom;

            //Atom startAtom = thisBond.StartAtom;

            // EndAtom == C and Label is ""
            if (endAtom.Element as Element == Globals.PeriodicTable.C &&
                thisBond.Rings.Count == 0 &&
                string.IsNullOrEmpty(endAtom.SymbolText))
            {
                // Has at least one other bond
                if (endAtom.Bonds.Count() > 1)
                {
                    var         otherBonds       = endAtom.Bonds.Except(new[] { thisBond }).ToList();
                    bool        allSingle        = true;
                    List <Bond> nonHydrogenBonds = new List <Bond>();
                    foreach (var otherBond in otherBonds)
                    {
                        if (!otherBond.Order.Equals(Globals.OrderSingle))
                        {
                            allSingle = false;
                            //break;
                        }

                        var otherAtom = otherBond.OtherAtom(endAtom);
                        if (otherAtom.Element as Element != Globals.PeriodicTable.H)
                        {
                            nonHydrogenBonds.Add(otherBond);
                        }
                    }

                    // All other bonds are single
                    if (allSingle)
                    {
                        // Determine chamfer shape
                        Vector left    = (wedgeEndLeft - wedgeStart) * 2;
                        Point  leftEnd = wedgeStart + left;

                        Vector right    = (wedgeEndRight - wedgeStart) * 2;
                        Point  rightEnd = wedgeStart + right;

                        bool  canIntersect;
                        bool  intersect;
                        Point intersection;

                        Vector shortestLeft  = left;
                        Vector shortestRight = right;

                        if (otherBonds.Count - nonHydrogenBonds.Count == 1)
                        {
                            otherBonds = nonHydrogenBonds;
                        }

                        if (otherBonds.Count == 1)
                        {
                            Bond   bond     = otherBonds[0];
                            Atom   atom     = bond.OtherAtom(endAtom);
                            Vector vv       = (endAtom.Position - atom.Position) * 2;
                            Point  otherEnd = atom.Position + vv;

                            CoordinateTool.FindIntersection(wedgeStart, leftEnd,
                                                            atom.Position, otherEnd,
                                                            out canIntersect, out intersect, out intersection);
                            if (intersect)
                            {
                                Vector v = intersection - wedgeStart;
                                if (v.Length < shortestLeft.Length)
                                {
                                    shortestLeft = v;
                                }
                            }

                            CoordinateTool.FindIntersection(wedgeStart, rightEnd,
                                                            atom.Position, otherEnd,
                                                            out canIntersect, out intersect, out intersection);
                            if (intersect)
                            {
                                Vector v = intersection - wedgeStart;
                                if (v.Length < shortestRight.Length)
                                {
                                    shortestRight = v;
                                }
                            }

                            // Re-write list of points
                            points = new List <Point>();
                            points.Add(wedgeStart);
                            points.Add(wedgeStart + shortestLeft);
                            points.Add(endAtom.Position);
                            points.Add(wedgeStart + shortestRight);

                            //DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, wedgeEndMiddle, wedgeEndLeft, "ff0000"));
                            //DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, wedgeEndMiddle, wedgeEndRight, "ff0000"));
                        }
                        else
                        {
                            foreach (var bond in otherBonds)
                            {
                                CoordinateTool.FindIntersection(wedgeStart, leftEnd,
                                                                bond.StartAtom.Position, bond.EndAtom.Position,
                                                                out canIntersect, out intersect, out intersection);
                                if (intersect)
                                {
                                    Vector v = intersection - wedgeStart;
                                    if (v.Length < shortestLeft.Length)
                                    {
                                        shortestLeft = v;
                                    }
                                }

                                CoordinateTool.FindIntersection(wedgeStart, rightEnd,
                                                                bond.StartAtom.Position, bond.EndAtom.Position,
                                                                out canIntersect, out intersect, out intersection);
                                if (intersect)
                                {
                                    Vector v = intersection - wedgeStart;
                                    if (v.Length < shortestRight.Length)
                                    {
                                        shortestRight = v;
                                    }
                                }
                            }

                            // Re-write list of points
                            points = new List <Point>();
                            points.Add(wedgeStart);
                            points.Add(wedgeStart + shortestLeft);
                            points.Add(endAtom.Position);
                            points.Add(wedgeStart + shortestRight);

                            //DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, wedgeEndMiddle, wedgeEndLeft, "ff0000"));
                            //DrawBondLine(wordprocessingGroup, new BondLine(BondLineStyle.Solid, wedgeEndMiddle, wedgeEndRight, "ff0000"));
                        }
                    }
                }
            }

            switch (bl.Style)
            {
            case BondLineStyle.Wedge:
                DrawWedgeBond(wordprocessingGroup, points);
                break;

            case BondLineStyle.Hatch:
                DrawHatchBond(wordprocessingGroup, points);
                break;

            default:
                DrawBondLine(wordprocessingGroup, bl);
                break;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates the lines for a bond
        /// </summary>
        /// <param name="bond"></param>
        public void CreateLines(Bond bond)
        {
            IEnumerable <Ring> rings = bond.Rings;
            int ringCount            = 0;

            foreach (Ring r in rings)
            {
                ringCount++;
            }

            Point bondStart = bond.StartAtom.Position;

            Point bondEnd = bond.EndAtom.Position;

            #region Create Bond Line objects

            switch (bond.Order)
            {
            case Globals.OrderZero:
            case "unknown":
                m_BondLines.Add(new BondLine(BondLineStyle.Dotted, bond));
                break;

            case Globals.OrderPartial01:
                m_BondLines.Add(new BondLine(BondLineStyle.Dashed, bond));
                break;

            case "1":
            case Globals.OrderSingle:
                switch (bond.Stereo)
                {
                case Globals.BondStereo.None:
                    m_BondLines.Add(new BondLine(BondLineStyle.Solid, bond));
                    break;

                case Globals.BondStereo.Hatch:
                    m_BondLines.Add(new BondLine(BondLineStyle.Hatch, bond));
                    break;

                case Globals.BondStereo.Wedge:
                    m_BondLines.Add(new BondLine(BondLineStyle.Wedge, bond));
                    break;

                case Globals.BondStereo.Indeterminate:
                    m_BondLines.Add(new BondLine(BondLineStyle.Wavy, bond));
                    break;

                default:

                    m_BondLines.Add(new BondLine(BondLineStyle.Solid, bond));
                    break;
                }
                break;

            case Globals.OrderPartial12:
            case Globals.OrderAromatic:
                BondLine onePointFive;
                BondLine onePointFiveDotted;
                Point    onePointFiveStart;
                Point    onePointFiveEnd;
                switch (bond.Placement)
                {
                case Globals.BondDirection.Clockwise:
                    onePointFive = new BondLine(BondLineStyle.Solid, bond);
                    m_BondLines.Add(onePointFive);
                    onePointFiveDotted = onePointFive.GetParallel(BondOffset());
                    onePointFiveStart  = new Point(onePointFiveDotted.Start.X, onePointFiveDotted.Start.Y);
                    onePointFiveEnd    = new Point(onePointFiveDotted.End.X, onePointFiveDotted.End.Y);
                    CoordinateTool.AdjustLineAboutMidpoint(ref onePointFiveStart, ref onePointFiveEnd, -(BondOffset() / 1.75));
                    onePointFiveDotted = new BondLine(BondLineStyle.Dotted, onePointFiveStart, onePointFiveEnd, bond);
                    m_BondLines.Add(onePointFiveDotted);
                    break;

                case Globals.BondDirection.Anticlockwise:
                    onePointFive = new BondLine(BondLineStyle.Solid, bond);
                    m_BondLines.Add(onePointFive);
                    onePointFiveDotted = onePointFive.GetParallel(-BondOffset());
                    onePointFiveStart  = new Point(onePointFiveDotted.Start.X, onePointFiveDotted.Start.Y);
                    onePointFiveEnd    = new Point(onePointFiveDotted.End.X, onePointFiveDotted.End.Y);
                    CoordinateTool.AdjustLineAboutMidpoint(ref onePointFiveStart, ref onePointFiveEnd, -(BondOffset() / 1.75));
                    onePointFiveDotted = new BondLine(BondLineStyle.Dotted, onePointFiveStart, onePointFiveEnd, bond);
                    m_BondLines.Add(onePointFiveDotted);
                    break;

                case Globals.BondDirection.None:
                    onePointFive = new BondLine(BondLineStyle.Solid, bond);
                    m_BondLines.Add(onePointFive.GetParallel(-(BondOffset() / 2)));
                    onePointFiveDotted = onePointFive.GetParallel(BondOffset() / 2);
                    onePointFiveDotted.SetLineStyle(BondLineStyle.Dotted);
                    m_BondLines.Add(onePointFiveDotted);
                    break;
                }
                break;

            case "2":
            case Globals.OrderDouble:
                if (bond.Stereo == Globals.BondStereo.Indeterminate)     //crossing bonds
                {
                    // Crossed lines
                    BondLine d  = new BondLine(BondLineStyle.Solid, bondStart, bondEnd, bond);
                    BondLine d1 = d.GetParallel(-(BondOffset() / 2));
                    BondLine d2 = d.GetParallel(BondOffset() / 2);
                    m_BondLines.Add(new BondLine(BondLineStyle.Solid, new Point(d1.Start.X, d1.Start.Y), new Point(d2.End.X, d2.End.Y), bond));
                    m_BondLines.Add(new BondLine(BondLineStyle.Solid, new Point(d2.Start.X, d2.Start.Y), new Point(d1.End.X, d1.End.Y), bond));
                }
                else
                {
                    bool shifted = false;
                    if (ringCount == 0)
                    {
                        if (bond.StartAtom.Element as Element == Globals.PeriodicTable.C && bond.EndAtom.Element as Element == Globals.PeriodicTable.C)
                        {
                            shifted = false;
                        }
                        else
                        {
                            shifted = true;
                        }
                    }

                    if (bond.StartAtom.Degree == 1 | bond.EndAtom.Degree == 1)
                    {
                        shifted = true;
                    }

                    if (shifted)
                    {
                        BondLine d = new BondLine(BondLineStyle.Solid, bond);
                        m_BondLines.Add(d.GetParallel(-(BondOffset() / 2)));
                        m_BondLines.Add(d.GetParallel(BondOffset() / 2));
                    }
                    else
                    {
                        Point outIntersectP1;
                        Point outIntersectP2;
                        bool  linesIntersect;
                        bool  segmentsIntersect;
                        Point centre;

                        switch (bond.Placement)
                        {
                        case Globals.BondDirection.Anticlockwise:
                            BondLine da = new BondLine(BondLineStyle.Solid, bond);
                            m_BondLines.Add(da);

                            BondLine bla         = da.GetParallel(-BondOffset());
                            Point    startPointa = bla.Start;
                            Point    endPointa   = bla.End;

                            if (bond.PrimaryRing != null)
                            {
                                centre = bond.PrimaryRing.Centroid.Value;
                                // Diagnostics
                                //m_BondLines.Add(new BondLine(bondStart, centre, BondLineStyle.Dotted, null));
                                //m_BondLines.Add(new BondLine(bondEnd, centre, BondLineStyle.Dotted, null));

                                CoordinateTool.FindIntersection(startPointa, endPointa, bondStart, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                                CoordinateTool.FindIntersection(startPointa, endPointa, bondEnd, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);

                                m_BondLines.Add(new BondLine(BondLineStyle.Solid, outIntersectP1, outIntersectP2, bond));
                            }
                            else
                            {
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointa, ref endPointa, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(BondLineStyle.Solid, startPointa, endPointa, bond));
                            }
                            break;

                        case Globals.BondDirection.Clockwise:
                            BondLine dc = new BondLine(BondLineStyle.Solid, bond);
                            m_BondLines.Add(dc);

                            BondLine blc         = dc.GetParallel(BondOffset());
                            Point    startPointc = blc.Start;
                            Point    endPointc   = blc.End;

                            if (bond.PrimaryRing != null)
                            {
                                centre = bond.PrimaryRing.Centroid.Value;
                                // Diagnostics
                                //m_BondLines.Add(new BondLine(bondStart, centre, BondLineStyle.Dotted, null));
                                //m_BondLines.Add(new BondLine(bondEnd, centre, BondLineStyle.Dotted, null));

                                CoordinateTool.FindIntersection(startPointc, endPointc, bondStart, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                                CoordinateTool.FindIntersection(startPointc, endPointc, bondEnd, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);

                                m_BondLines.Add(new BondLine(BondLineStyle.Solid, outIntersectP1, outIntersectP2, bond));
                            }
                            else
                            {
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointc, ref endPointc, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(BondLineStyle.Solid, startPointc, endPointc, bond));
                            }
                            break;

                        default:
                            switch (bond.Stereo)
                            {
                            case Globals.BondStereo.Cis:
                                BondLine dcc = new BondLine(BondLineStyle.Solid, bond);
                                m_BondLines.Add(dcc);
                                BondLine blnewc      = dcc.GetParallel(BondOffset());
                                Point    startPointn = blnewc.Start;
                                Point    endPointn   = blnewc.End;
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointn, ref endPointn, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(BondLineStyle.Solid, startPointn, endPointn, bond));
                                break;

                            case Globals.BondStereo.Trans:
                                BondLine dtt = new BondLine(BondLineStyle.Solid, bond);
                                m_BondLines.Add(dtt);
                                BondLine blnewt      = dtt.GetParallel(BondOffset());
                                Point    startPointt = blnewt.Start;
                                Point    endPointt   = blnewt.End;
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointt, ref endPointt, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(BondLineStyle.Solid, startPointt, endPointt, bond));
                                break;

                            default:
                                BondLine dp = new BondLine(BondLineStyle.Solid, bond);
                                m_BondLines.Add(dp.GetParallel(-(BondOffset() / 2)));
                                m_BondLines.Add(dp.GetParallel(BondOffset() / 2));
                                break;
                            }
                            break;
                        }
                    }
                }
                break;

            case Globals.OrderPartial23:
                BondLine twoPointFive;
                BondLine twoPointFiveDotted;
                BondLine twoPointFiveParallel;
                Point    twoPointFiveStart;
                Point    twoPointFiveEnd;
                switch (bond.Placement)
                {
                case Globals.BondDirection.Clockwise:
                    // Central bond line
                    twoPointFive = new BondLine(BondLineStyle.Solid, bond);
                    m_BondLines.Add(twoPointFive);
                    // Solid bond line
                    twoPointFiveParallel = twoPointFive.GetParallel(-BondOffset());
                    twoPointFiveStart    = new Point(twoPointFiveParallel.Start.X, twoPointFiveParallel.Start.Y);
                    twoPointFiveEnd      = new Point(twoPointFiveParallel.End.X, twoPointFiveParallel.End.Y);
                    CoordinateTool.AdjustLineAboutMidpoint(ref twoPointFiveStart, ref twoPointFiveEnd, -(BondOffset() / 1.75));
                    twoPointFiveParallel = new BondLine(BondLineStyle.Solid, twoPointFiveStart, twoPointFiveEnd, bond);
                    m_BondLines.Add(twoPointFiveParallel);
                    // Dotted bond line
                    twoPointFiveDotted = twoPointFive.GetParallel(BondOffset());
                    twoPointFiveStart  = new Point(twoPointFiveDotted.Start.X, twoPointFiveDotted.Start.Y);
                    twoPointFiveEnd    = new Point(twoPointFiveDotted.End.X, twoPointFiveDotted.End.Y);
                    CoordinateTool.AdjustLineAboutMidpoint(ref twoPointFiveStart, ref twoPointFiveEnd, -(BondOffset() / 1.75));
                    twoPointFiveDotted = new BondLine(BondLineStyle.Dotted, twoPointFiveStart, twoPointFiveEnd, bond);
                    m_BondLines.Add(twoPointFiveDotted);
                    break;

                case Globals.BondDirection.Anticlockwise:
                    // Central bond line
                    twoPointFive = new BondLine(BondLineStyle.Solid, bond);
                    m_BondLines.Add(twoPointFive);
                    // Dotted bond line
                    twoPointFiveDotted = twoPointFive.GetParallel(-BondOffset());
                    twoPointFiveStart  = new Point(twoPointFiveDotted.Start.X, twoPointFiveDotted.Start.Y);
                    twoPointFiveEnd    = new Point(twoPointFiveDotted.End.X, twoPointFiveDotted.End.Y);
                    CoordinateTool.AdjustLineAboutMidpoint(ref twoPointFiveStart, ref twoPointFiveEnd, -(BondOffset() / 1.75));
                    twoPointFiveDotted = new BondLine(BondLineStyle.Dotted, twoPointFiveStart, twoPointFiveEnd, bond);
                    m_BondLines.Add(twoPointFiveDotted);
                    // Solid bond line
                    twoPointFiveParallel = twoPointFive.GetParallel(BondOffset());
                    twoPointFiveStart    = new Point(twoPointFiveParallel.Start.X, twoPointFiveParallel.Start.Y);
                    twoPointFiveEnd      = new Point(twoPointFiveParallel.End.X, twoPointFiveParallel.End.Y);
                    CoordinateTool.AdjustLineAboutMidpoint(ref twoPointFiveStart, ref twoPointFiveEnd, -(BondOffset() / 1.75));
                    twoPointFiveParallel = new BondLine(BondLineStyle.Solid, twoPointFiveStart, twoPointFiveEnd, bond);
                    m_BondLines.Add(twoPointFiveParallel);
                    break;

                case Globals.BondDirection.None:
                    twoPointFive = new BondLine(BondLineStyle.Solid, bond);
                    m_BondLines.Add(twoPointFive);
                    m_BondLines.Add(twoPointFive.GetParallel(-BondOffset()));
                    twoPointFiveDotted = twoPointFive.GetParallel(BondOffset());
                    twoPointFiveDotted.SetLineStyle(BondLineStyle.Dotted);
                    m_BondLines.Add(twoPointFiveDotted);
                    break;
                }
                break;

            case "3":
            case Globals.OrderTriple:
                BondLine tripple = new BondLine(BondLineStyle.Solid, bond);
                m_BondLines.Add(tripple);
                m_BondLines.Add(tripple.GetParallel(BondOffset()));
                m_BondLines.Add(tripple.GetParallel(-BondOffset()));
                break;

            default:
                // Draw a single line, so that there is something to see
                m_BondLines.Add(new BondLine(BondLineStyle.Solid, bond));
                break;
            }

            #endregion Create Bond Line objects
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates the lines for a bond
        /// </summary>
        /// <param name="wordprocessingGroup1">Where to add the bond lines</param>
        /// <param name="bond"></param>
        public void CreateLines(Bond bond)
        {
            //Debug.WriteLine("Bond: " + bond.Id);

            //IEnumerable<Atom> bondatoms = bond.GetAtoms();
            IEnumerable <Ring> rings = bond.Rings;
            int ringCount            = 0;

            foreach (Ring r in rings)
            {
                ringCount++;
            }
            //Debug.WriteLine("  Ring Count: " + ringCount);

            Point bondStart = bond.StartAtom.Position;

            Point bondEnd = bond.EndAtom.Position;

            //IEnumerable<CmlBond> toAtomBonds = toAtom.GetLigandBonds();
            //int toAtomBondCount = toAtomBonds.ToArray<CmlBond>().Length;

            //Debug.WriteLine("    From : " + fromAtom.ElementType + " [" + fromAtom.Id + "] at " + bondStart.X + ", " + bondStart.Y);
            //Debug.WriteLine("      To : " + toAtom.ElementType + " [" + toAtom.Id + "] at " + bondEnd.X + ", " + bondEnd.Y);

            #region Create Bond Line objects

            switch (bond.Order)
            {
            case Bond.OrderZero:
            case "unknown":
                m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Dotted, bond.Id));
                break;

            case Bond.OrderPartial01:
                m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Dashed, bond.Id));
                break;

            case "1":
            case Bond.OrderSingle:
                switch (bond.Stereo)
                {
                case BondStereo.None:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id));
                    break;

                case BondStereo.Hatch:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Hash, bond.Id));
                    break;

                case BondStereo.Wedge:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Wedge, bond.Id));
                    break;

                case BondStereo.Indeterminate:
                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Wavy, bond.Id));
                    break;

                default:

                    m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id));
                    break;
                }
                break;

            case Bond.OrderPartial12:
                //case "A":
                BondLine a = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                m_BondLines.Add(a);
                BondLine a1        = a.GetParallel(-BondOffset());
                Point    newStarta = new Point(a1.Start.X, a1.Start.Y);
                Point    newEnda   = new Point(a1.End.X, a1.End.Y);
                CoordinateTool.AdjustLineAboutMidpoint(ref newStarta, ref newEnda, -(BondOffset() / 1.75));
                a1 = new BondLine(newStarta, newEnda, BondLineStyle.Dotted, bond.Id);
                m_BondLines.Add(a1);
                break;

            case Bond.OrderDouble:
                if (bond.Stereo == BondStereo.Indeterminate)     //crossing bonds
                {
                    // Crossed lines
                    BondLine d  = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                    BondLine d1 = d.GetParallel(-(BondOffset() / 2));
                    BondLine d2 = d.GetParallel(BondOffset() / 2);
                    m_BondLines.Add(new BondLine(new Point(d1.Start.X, d1.Start.Y), new Point(d2.End.X, d2.End.Y), BondLineStyle.Solid, bond.Id));
                    m_BondLines.Add(new BondLine(new Point(d2.Start.X, d2.Start.Y), new Point(d1.End.X, d1.End.Y), BondLineStyle.Solid, bond.Id));
                }
                else
                {
                    bool shifted = false;
                    if (ringCount == 0)
                    {
                        if (bond.StartAtom.Element as Element == Globals.PeriodicTable.C && bond.EndAtom.Element as Element == Globals.PeriodicTable.C)
                        {
                            shifted = false;
                        }
                        else
                        {
                            shifted = true;
                        }
                    }

                    if (bond.StartAtom.Degree == 1 | bond.EndAtom.Degree == 1)
                    {
                        shifted = true;
                    }

                    if (shifted)
                    {
                        BondLine d = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                        m_BondLines.Add(d.GetParallel(-(BondOffset() / 2)));
                        m_BondLines.Add(d.GetParallel(BondOffset() / 2));
                    }
                    else
                    {
                        Debug.WriteLine($"bond.Placement {bond.Placement}");
                        Point outIntersectP1;
                        Point outIntersectP2;
                        bool  linesIntersect;
                        bool  segmentsIntersect;
                        Point centre;

                        switch (bond.Placement)
                        {
                        case BondDirection.Anticlockwise:
                            BondLine da = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                            m_BondLines.Add(da);

                            BondLine bla         = da.GetParallel(-BondOffset());
                            Point    startPointa = bla.Start;
                            Point    endPointa   = bla.End;

                            if (bond.PrimaryRing != null)
                            {
                                centre = bond.PrimaryRing.Centroid.Value;
                                // Diagnostics
                                //m_BondLines.Add(new BondLine(bondStart, centre, BondLineStyle.Dotted, null));
                                //m_BondLines.Add(new BondLine(bondEnd, centre, BondLineStyle.Dotted, null));

                                CoordinateTool.FindIntersection(startPointa, endPointa, bondStart, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                                CoordinateTool.FindIntersection(startPointa, endPointa, bondEnd, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);

                                m_BondLines.Add(new BondLine(outIntersectP1, outIntersectP2, BondLineStyle.Solid, bond.Id));
                            }
                            else
                            {
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointa, ref endPointa, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointa, endPointa, BondLineStyle.Solid, bond.Id));
                            }
                            break;

                        case BondDirection.Clockwise:
                            BondLine dc = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                            m_BondLines.Add(dc);

                            BondLine blc         = dc.GetParallel(+BondOffset());
                            Point    startPointc = blc.Start;
                            Point    endPointc   = blc.End;

                            if (bond.PrimaryRing != null)
                            {
                                centre = bond.PrimaryRing.Centroid.Value;
                                // Diagnostics
                                //m_BondLines.Add(new BondLine(bondStart, centre, BondLineStyle.Dotted, null));
                                //m_BondLines.Add(new BondLine(bondEnd, centre, BondLineStyle.Dotted, null));

                                CoordinateTool.FindIntersection(startPointc, endPointc, bondStart, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP1);
                                CoordinateTool.FindIntersection(startPointc, endPointc, bondEnd, centre,
                                                                out linesIntersect, out segmentsIntersect, out outIntersectP2);

                                m_BondLines.Add(new BondLine(outIntersectP1, outIntersectP2, BondLineStyle.Solid, bond.Id));
                            }
                            else
                            {
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointc, ref endPointc, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointc, endPointc, BondLineStyle.Solid, bond.Id));
                            }
                            break;

                        default:
                            switch (bond.Stereo)
                            {
                            case BondStereo.Cis:
                                BondLine dcc = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                                m_BondLines.Add(dcc);
                                BondLine blnewc      = dcc.GetParallel(+BondOffset());
                                Point    startPointn = blnewc.Start;
                                Point    endPointn   = blnewc.End;
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointn, ref endPointn, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointn, endPointn, BondLineStyle.Solid, bond.Id));
                                break;

                            case BondStereo.Trans:
                                BondLine dtt = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                                m_BondLines.Add(dtt);
                                BondLine blnewt      = dtt.GetParallel(+BondOffset());
                                Point    startPointt = blnewt.Start;
                                Point    endPointt   = blnewt.End;
                                CoordinateTool.AdjustLineAboutMidpoint(ref startPointt, ref endPointt, -(BondOffset() / 1.75));
                                m_BondLines.Add(new BondLine(startPointt, endPointt, BondLineStyle.Solid, bond.Id));
                                break;

                            default:
                                BondLine dp = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                                m_BondLines.Add(dp.GetParallel(-(BondOffset() / 2)));
                                m_BondLines.Add(dp.GetParallel(BondOffset() / 2));
                                break;
                            }
                            break;
                        }
                    }
                }
                break;

            case "3":
            case "T":
                // Draw main bond line
                BondLine t = new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id);
                m_BondLines.Add(t);
                m_BondLines.Add(t.GetParallel(BondOffset()));
                m_BondLines.Add(t.GetParallel(-BondOffset()));
                break;

            default:
                m_BondLines.Add(new BondLine(bondStart, bondEnd, BondLineStyle.Solid, bond.Id));
                break;
            }

            #endregion Create Bond Line objects
        }