Exemplo n.º 1
0
        /// <summary>
        /// Add a key point into this polyline link.
        /// </summary>
        /// <param name="x">X coordinate of the key point.</param>
        /// <param name="y">Y coordinate of the key point.</param>
        /// <param name="rgObjs">GOM object collection.</param>
        public void AddKeyPoint(float x, float y, GOM_Objects rgObjs)
        {
            if ( m_linkingStyle != GOM_Linking_Style.Polyline )
            {
                return;
            }

            System.Drawing.Drawing2D.Matrix	matrix;
            System.Drawing.PointF[]			rgPts, rgAllPts;
            System.Drawing.PointF			startPt, endPt;
            startPt	= StartPointInCanvas(rgObjs);
            endPt	= EndPointInCanvas(rgObjs);

            rgPts = new System.Drawing.PointF[2];
            rgAllPts = new System.Drawing.PointF[m_keyPts.Count+2];

            rgAllPts[0].X = startPt.X;
            rgAllPts[0].Y = startPt.Y;
            for(int i=0; i<m_keyPts.Count; i++)
            {
                rgAllPts[1+i].X = m_keyPts[i].x;
                rgAllPts[1+i].Y = m_keyPts[i].y;
            }
            rgAllPts[rgAllPts.Length-1].X = endPt.X;
            rgAllPts[rgAllPts.Length-1].Y = endPt.Y;

            for(int i=0; i<(rgAllPts.Length-1); i++)
            {
                rgPts[0].X = rgAllPts[i+1].X;
                rgPts[0].Y = rgAllPts[i+1].Y;
                rgPts[1].X = x;
                rgPts[1].Y = y;

                matrix = new System.Drawing.Drawing2D.Matrix();
                matrix.Translate(-rgAllPts[i].X, -rgAllPts[i].Y);
                matrix.TransformPoints(rgPts);

                float angle = (float)(System.Math.Atan2(rgAllPts[i+1].Y - rgAllPts[i].Y, rgAllPts[i+1].X - rgAllPts[i].X) / System.Math.PI) * 180;

                matrix.Reset();
                matrix.Rotate(-angle);
                matrix.TransformPoints(rgPts);

                if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                {
                    GOM_Point point = new GOM_Point();
                    point.x = x;
                    point.y = y;
                    m_keyPts.Insert(i, point);
                    return;
                }
            }
        }
Exemplo n.º 2
0
 public static bool IsPointOnLink(GOM_Point pt, GOM_Link link, GOM_Objects rgObjs)
 {
     return link.IsPointOnLink(pt.x, pt.y, rgObjs);
 }
 public GOM_ResourceArrays( GOM_Points points, GOM_Drawing_Styles drawingStyles, GOM_Filling_Styles fillingStyles, GOM_Objects objects )
 {
     m_points = points;
     m_drawingStyles = drawingStyles;
     m_fillingStyles = fillingStyles;
     m_objects = objects;
 }
 public GOM_ResourceArrays( GOM_Objects objects )
     : this(null, null, null, objects)
 {
 }
Exemplo n.º 5
0
        public void DecomposeGroupObject(GOM_Objects rgObjs)
        {
            GOM_Interface_Graphic_Object	obj;
            System.Drawing.RectangleF		rc;
            System.Drawing.PointF			ptC, ptR;
            float[]							rgOffsetX, rgOffsetY, rgRotation;

            if (rgObjects.Count > 0)
            {
                rgOffsetX	= new float[rgObjects.Count];
                rgOffsetY	= new float[rgObjects.Count];
                rgRotation	= new float[rgObjects.Count];

                for (int i = 0; i < rgObjects.Count; i++)
                {
                    obj = rgObjects[i];
                    rc	= obj.BoundingBox;

                    ptC	= obj.PointToCanvas(new System.Drawing.PointF((rc.Left + rc.Right) / 2, (rc.Top + rc.Bottom) / 2));
                    ptC	= this.PointToCanvas(ptC);

                    ptR = obj.PointToCanvas(new System.Drawing.PointF((rc.Left + rc.Right) / 2, rc.Top - 30));
                    ptR = this.PointToCanvas(ptR);

                    rgOffsetX[i]	= ptC.X - (rc.Left + rc.Right) / 2;
                    rgOffsetY[i]	= ptC.Y - (rc.Top + rc.Bottom) / 2;
                    rgRotation[i]	= (float)((System.Math.Atan2(ptR.X - ptC.X, ptC.Y - ptR.Y) / System.Math.PI) * 180);
                }

                for (int i = 0; i < rgObjects.Count; i++)
                {
                    rgObjects[i].xOffset	= rgOffsetX[i];
                    rgObjects[i].yOffset	= rgOffsetY[i];
                    rgObjects[i].rotation	= rgRotation[i];

                    rgObjs.Add(rgObjects[i]);
                }

                rgObjects.Clear();
            }
        }
Exemplo n.º 6
0
        public static GOM_Object_Group CreateGroupObject(GOM_Objects rgObjs)
        {
            GOM_Object_Group			group = null;
            System.Drawing.PointF		pt;
            System.Drawing.RectangleF	rc;

            if (rgObjs.Count > 0)
            {
                float	minX, minY;

                rc = rgObjs[0].BoundingBox;
                pt = rgObjs[0].PointToCanvas(new System.Drawing.PointF(rc.Left, rc.Top));

                minX = pt.X;
                minY = pt.Y;

                for (int i = 0; i < rgObjs.Count; i++)
                {
                    rc = rgObjs[i].BoundingBox;

                    pt = rgObjs[i].PointToCanvas(new System.Drawing.PointF(rc.Left, rc.Top));
                    minX = System.Math.Min(minX, pt.X);
                    minY = System.Math.Min(minY, pt.Y);

                    pt = rgObjs[i].PointToCanvas(new System.Drawing.PointF(rc.Left, rc.Bottom));
                    minX = System.Math.Min(minX, pt.X);
                    minY = System.Math.Min(minY, pt.Y);

                    pt = rgObjs[i].PointToCanvas(new System.Drawing.PointF(rc.Right, rc.Top));
                    minX = System.Math.Min(minX, pt.X);
                    minY = System.Math.Min(minY, pt.Y);

                    pt = rgObjs[i].PointToCanvas(new System.Drawing.PointF(rc.Right, rc.Bottom));
                    minX = System.Math.Min(minX, pt.X);
                    minY = System.Math.Min(minY, pt.Y);
                }

                group = new GOM_Object_Group();

                for (int i = 0; i < rgObjs.Count; i++)
                {
                    rgObjs[i].xOffset -= minX;
                    rgObjs[i].yOffset -= minY;

                    group.rgObjects.Add(rgObjs[i]);
                }

                group.xOffset = minX;
                group.yOffset = minY;
            }

            group.CalculateBoundingBox();

            return group;
        }
Exemplo n.º 7
0
        public GOM_Object_Group()
        {
            m_id		= Guid.NewGuid().ToString("D");
            m_xOffset	= 0;
            m_yOffset	= 0;
            m_rotation	= 0;

            m_boundingBox = new System.Drawing.RectangleF();

            rgObjects	= new GOM_Objects();

            GOM_Constraint_Set	constraintSet;

            m_Top_Connector = new GOM_Point();
            m_Top_Connector.id = GOM_Special_Point_Name.TOP_CONNECTOR;
            m_Top_Connector.Connectable = true;

            m_Bottom_Connector = new GOM_Point();
            m_Bottom_Connector.id = GOM_Special_Point_Name.BOTTOM_CONNECTOR;
            m_Bottom_Connector.Connectable = true;

            m_Left_Connector = new GOM_Point();
            m_Left_Connector.id = GOM_Special_Point_Name.LEFT_CONNECTOR;
            m_Left_Connector.Connectable = true;

            m_Right_Connector = new GOM_Point();
            m_Right_Connector.id = GOM_Special_Point_Name.RIGHT_CONNECTOR;
            m_Right_Connector.Connectable = true;

            m_SE_Resize_Point			= new GOM_Point();
            m_SE_Resize_Point.id		= GOM_Special_Point_Name.SE_RESIZING_POINT;
            constraintSet				= new GOM_Constraint_Set();
            constraintSet.EditingMode	= "default";
            constraintSet.Add(new GOM_Resizing_SE_Constraint(this, m_SE_Resize_Point));
            m_SE_Resize_Point.Constraints.Add(constraintSet);

            m_NW_Resize_Point			= new GOM_Point();
            m_NW_Resize_Point.id		= GOM_Special_Point_Name.NW_RESIZING_POINT;
            constraintSet				= new GOM_Constraint_Set();
            constraintSet.EditingMode	= "default";
            constraintSet.Add(new GOM_Resizing_NW_Constraint(this, m_NW_Resize_Point));
            m_NW_Resize_Point.Constraints.Add(constraintSet);

            m_SW_Resize_Point			= new GOM_Point();
            m_SW_Resize_Point.id		= GOM_Special_Point_Name.SW_RESIZING_POINT;
            constraintSet				= new GOM_Constraint_Set();
            constraintSet.EditingMode	= "default";
            constraintSet.Add(new GOM_Resizing_SW_Constraint(this, m_SW_Resize_Point));
            m_SW_Resize_Point.Constraints.Add(constraintSet);

            m_NE_Resize_Point			= new GOM_Point();
            m_NE_Resize_Point.id		= GOM_Special_Point_Name.NE_RESIZING_POINT;
            constraintSet				= new GOM_Constraint_Set();
            constraintSet.EditingMode	= "default";
            constraintSet.Add(new GOM_Resizing_NE_Constraint(this, m_NE_Resize_Point));
            m_NE_Resize_Point.Constraints.Add(constraintSet);

            m_Rotation_Point			= new GOM_Point();
            m_Rotation_Point.id			= GOM_Special_Point_Name.ROTATION_POINT;
            constraintSet				= new GOM_Constraint_Set();
            constraintSet.EditingMode	= "default";
            constraintSet.Add(new GOM_Rotation_Constraint(this, m_Rotation_Point));
            m_Rotation_Point.Constraints.Add(constraintSet);
        }
Exemplo n.º 8
0
        private bool CalculatePointLocation(ref System.Drawing.PointF pt, GOM_Interface_Graphic_Object obj, GOM_Objects rgObjs)
        {
            bool bTranslated = false;

            for (int i = 0; i < rgObjs.Count; i++)
            {
                if (rgObjs[i].Equals(obj))
                {
                    bTranslated = true;
                }
                else if (rgObjs[i] is GOM_Object_Group)
                {
                    bTranslated |= CalculatePointLocation(ref pt, obj, ((GOM_Object_Group)rgObjs[i]).rgObjects);
                }

                if (bTranslated)
                {
                    pt = rgObjs[i].PointToCanvas(pt);
                    break;
                }
            }

            return bTranslated;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Gets the start point in canvas coordinate.
 /// </summary>
 /// <param name="rgObjs">GOM object collection.</param>
 /// <returns>Start point in canvas coordinate.</returns>
 public System.Drawing.PointF StartPointInCanvas(GOM_Objects rgObjs)
 {
     System.Drawing.PointF	pt = new System.Drawing.PointF(m_startPt.x, m_startPt.y);
     if (!CalculatePointLocation(ref pt, this.m_startObj, rgObjs))
     {
         pt.X = -1;
         pt.Y = -1;
     }
     return pt;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Indicates whether a given point is on this link.
        /// </summary>
        /// <param name="x">X coordinate of the given point.</param>
        /// <param name="y">Y coordinate of the given point.</param>
        /// <param name="rgObjs">GOM object collection.</param>
        /// <returns>Whether a given point is on this link.</returns>
        public bool IsPointOnLink(float x, float y, GOM_Objects rgObjs)
        {
            switch (m_linkingStyle)
            {
                case GOM_Linking_Style.Line:
                {
                    System.Drawing.Drawing2D.Matrix	matrix;
                    System.Drawing.PointF[]			rgPts;
                    System.Drawing.PointF			startPt, endPt;

                    startPt	= StartPointInCanvas(rgObjs);
                    endPt	= EndPointInCanvas(rgObjs);

                    rgPts = new System.Drawing.PointF[2];
                    rgPts[0].X = endPt.X;
                    rgPts[0].Y = endPt.Y;
                    rgPts[1].X = x;
                    rgPts[1].Y = y;

                    matrix = new System.Drawing.Drawing2D.Matrix();
                    matrix.Translate(-startPt.X, -startPt.Y);
                    matrix.TransformPoints(rgPts);

                    float angle = (float)(System.Math.Atan2(endPt.Y - startPt.Y, endPt.X - startPt.X) / System.Math.PI) * 180;

                    matrix.Reset();
                    matrix.Rotate(-angle);
                    matrix.TransformPoints(rgPts);

                    if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                    {
                        return true;
                    }

                    break;
                }
                case GOM_Linking_Style.Polyline:
                {
                    System.Drawing.Drawing2D.Matrix	matrix;
                    System.Drawing.PointF[]			rgPts, rgAllPts;
                    System.Drawing.PointF			startPt, endPt;
                    startPt	= StartPointInCanvas(rgObjs);
                    endPt	= EndPointInCanvas(rgObjs);

                    rgPts = new System.Drawing.PointF[2];
                    rgAllPts = new System.Drawing.PointF[m_keyPts.Count+2];

                    rgAllPts[0].X = startPt.X;
                    rgAllPts[0].Y = startPt.Y;
                    for(int i=0; i<m_keyPts.Count; i++)
                    {
                        rgAllPts[1+i].X = m_keyPts[i].x;
                        rgAllPts[1+i].Y = m_keyPts[i].y;
                    }
                    rgAllPts[rgAllPts.Length-1].X = endPt.X;
                    rgAllPts[rgAllPts.Length-1].Y = endPt.Y;

                    for(int i=0; i<(rgAllPts.Length-1); i++)
                    {
                        rgPts[0].X = rgAllPts[i+1].X;
                        rgPts[0].Y = rgAllPts[i+1].Y;
                        rgPts[1].X = x;
                        rgPts[1].Y = y;

                        matrix = new System.Drawing.Drawing2D.Matrix();
                        matrix.Translate(-rgAllPts[i].X, -rgAllPts[i].Y);
                        matrix.TransformPoints(rgPts);

                        float angle = (float)(System.Math.Atan2(rgAllPts[i+1].Y - rgAllPts[i].Y, rgAllPts[i+1].X - rgAllPts[i].X) / System.Math.PI) * 180;

                        matrix.Reset();
                        matrix.Rotate(-angle);
                        matrix.TransformPoints(rgPts);

                        if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                        {
                            return true;
                        }
                    }

                    break;
                }
                case GOM_Linking_Style.Curve:
                {
                    break;
                }
                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown link style.");
                    break;
            }

            return false;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Draw selected link.
        /// </summary>
        /// <param name="canvas">Canvas which link is drawn on.</param>
        /// <param name="rgObjs">GOM object collections.</param>
        public void DrawSelected(System.Drawing.Graphics canvas, GOM_Objects rgObjs)
        {
            System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.BlueViolet, 2);
            pen.DashStyle = m_drawingStyle.drawingStyle.DashStyle;

            switch (m_linkingStyle)
            {
                case GOM_Linking_Style.Line:
                {
                    System.Drawing.PointF pt1 = StartPointInCanvas(rgObjs);
                    System.Drawing.PointF pt2 = EndPointInCanvas(rgObjs);

                    canvas.DrawLine(pen, pt1, pt2);

                    DrawTerminal(canvas, m_startStyle, pt1, pt2);
                    DrawTerminal(canvas, m_endStyle, pt2, pt1);

                    break;
                }
                case GOM_Linking_Style.Polyline:
                {
                    System.Drawing.PointF pt1 = StartPointInCanvas(rgObjs);
                    System.Drawing.PointF pt2 = EndPointInCanvas(rgObjs);

                    if ( m_keyPts.Count > 0 )
                    {
                        System.Drawing.PointF firstKeyPt = new System.Drawing.PointF(m_keyPts[0].x, m_keyPts[0].y);
                        System.Drawing.PointF lastKeyPt = new System.Drawing.PointF(m_keyPts[m_keyPts.Count-1].x, m_keyPts[m_keyPts.Count-1].y);

                        canvas.DrawLine(pen, pt1, firstKeyPt);
                        if ( m_keyPts.Count >= 2 )
                        {
                            for( int i=0; i<(m_keyPts.Count-1); i++ )
                            {
                                canvas.DrawLine(pen, m_keyPts[i].x, m_keyPts[i].y, m_keyPts[i+1].x, m_keyPts[i+1].y);
                            }
                        }
                        canvas.DrawLine(pen, lastKeyPt, pt2);

                        // Draw key points
                        for( int i=0; i<m_keyPts.Count; i++ )
                        {
                            canvas.FillEllipse(System.Drawing.Brushes.YellowGreen, m_keyPts[i].x-3, m_keyPts[i].y-3, 7, 7);
                        }

                        DrawTerminal(canvas, m_startStyle, pt1, firstKeyPt);
                        DrawTerminal(canvas, m_endStyle, pt2, lastKeyPt);
                    }
                    else
                    {
                        canvas.DrawLine(pen, pt1, pt2);
                        DrawTerminal(canvas, m_startStyle, pt1, pt2);
                        DrawTerminal(canvas, m_endStyle, pt2, pt1);
                    }
                    break;
                }
                case GOM_Linking_Style.Curve:
                {
                    break;
                }
                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown link style.");
                    return;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Draw unselected link.
        /// </summary>
        /// <param name="canvas">Canvas which link is drawn on.</param>
        /// <param name="rgObjs">GOM object collection.</param>
        public void Draw(System.Drawing.Graphics canvas, GOM_Objects rgObjs)
        {
            switch (m_linkingStyle)
            {
                case GOM_Linking_Style.Line:
                {
                    System.Drawing.PointF pt1 = StartPointInCanvas(rgObjs);
                    System.Drawing.PointF pt2 = EndPointInCanvas(rgObjs);

                    canvas.DrawLine(m_drawingStyle.drawingStyle, pt1, pt2);

                    DrawTerminal(canvas, m_startStyle, pt1, pt2);
                    DrawTerminal(canvas, m_endStyle, pt2, pt1);

                    break;
                }
                case GOM_Linking_Style.Polyline:
                {
                    System.Drawing.PointF pt1 = StartPointInCanvas(rgObjs);
                    System.Drawing.PointF pt2 = EndPointInCanvas(rgObjs);

                    if ( m_keyPts.Count > 0 )
                    {
                        System.Drawing.PointF firstKeyPt = new System.Drawing.PointF(m_keyPts[0].x, m_keyPts[0].y);
                        System.Drawing.PointF lastKeyPt = new System.Drawing.PointF(m_keyPts[m_keyPts.Count-1].x, m_keyPts[m_keyPts.Count-1].y);

                        canvas.DrawLine(m_drawingStyle.drawingStyle, pt1, firstKeyPt);
                        if ( m_keyPts.Count >= 2 )
                        {
                            for( int i=0; i<(m_keyPts.Count-1); i++ )
                            {
                                canvas.DrawLine(m_drawingStyle.drawingStyle, m_keyPts[i].x, m_keyPts[i].y, m_keyPts[i+1].x, m_keyPts[i+1].y);
                            }
                        }
                        canvas.DrawLine(m_drawingStyle.drawingStyle, lastKeyPt, pt2);
                        DrawTerminal(canvas, m_startStyle, pt1, firstKeyPt);
                        DrawTerminal(canvas, m_endStyle, pt2, lastKeyPt);
                    }
                    else
                    {
                        canvas.DrawLine(m_drawingStyle.drawingStyle, pt1, pt2);
                        DrawTerminal(canvas, m_startStyle, pt1, pt2);
                        DrawTerminal(canvas, m_endStyle, pt2, pt1);
                    }
                    break;
                }
                case GOM_Linking_Style.Curve:
                {
                    break;
                }
                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown link style.");
                    return;
            }
        }