예제 #1
0
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Bends in mutual opposite directions the specified visual connectors which represents an auto-reference.
        /// </summary>
        public void BendAutoRefConnectors(VisualConnector OriginConnector, VisualConnector TargetConnector)
        {
            double Toleration = 20.0;
            double Expansion = Toleration * 2.0;
            double PosX, PosY;
            bool   TooCloseX, TooCloseY;
            var    PrimaryCenter   = this.MainSymbol.BaseCenter;
            var    SecondaryCenter = (OriginConnector.OriginSymbol == this.MainSymbol
                                   ? OriginConnector.TargetSymbol.BaseCenter
                                   : OriginConnector.OriginSymbol.BaseCenter);

            if (OriginConnector.IntermediatePosition == Display.NULL_POINT)
            {
                PosX      = PrimaryCenter.X;
                PosY      = SecondaryCenter.Y;
                TooCloseX = PosX.IsCloseTo(SecondaryCenter.X, Toleration);
                TooCloseY = PosY.IsCloseTo(PrimaryCenter.Y, Toleration);

                if (TooCloseX)
                {
                    PosX = PrimaryCenter.X - Expansion;
                    PosY = (PrimaryCenter.Y + SecondaryCenter.Y) / 2.0;
                }

                if (TooCloseY)
                {
                    PosY = SecondaryCenter.Y - Expansion;
                    PosX = (PrimaryCenter.X + SecondaryCenter.X) / 2.0;
                }

                OriginConnector.IntermediatePosition = new Point(PosX, PosY);
            }

            if (TargetConnector.IntermediatePosition == Display.NULL_POINT)
            {
                PosX      = SecondaryCenter.X;
                PosY      = PrimaryCenter.Y;
                TooCloseX = PosX.IsCloseTo(PrimaryCenter.X, Toleration);
                TooCloseY = PosY.IsCloseTo(SecondaryCenter.Y, Toleration);

                if (TooCloseX)
                {
                    PosX = SecondaryCenter.X + Expansion;
                    PosY = (PrimaryCenter.Y + SecondaryCenter.Y) / 2.0;
                }

                if (TooCloseY)
                {
                    PosY = PrimaryCenter.Y + Expansion;
                    PosX = (PrimaryCenter.X + SecondaryCenter.X) / 2.0;
                }

                TargetConnector.IntermediatePosition = new Point(PosX, PosY);
            }
        }