Ejemplo n.º 1
0
        //Deserializes info into a new solid element
        protected SolidElement(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            SuspendEvents = true;

            BackColor      = Color.FromArgb(Convert.ToInt32(info.GetString("BackColor")));
            Clip           = info.GetBoolean("Clip");
            GradientMode   = (LinearGradientMode)Enum.Parse(typeof(LinearGradientMode), info.GetString("GradientMode"), true);
            GradientColor  = Color.FromArgb(Convert.ToInt32(info.GetString("GradientColor")));
            DrawGradient   = info.GetBoolean("DrawGradient");
            DrawBorder     = info.GetBoolean("DrawBorder");
            DrawBackground = info.GetBoolean("DrawBackground");
            Location       = Serialize.GetPointF(info.GetString("Location"));
            SetInternalRectangle(Serialize.GetRectangleF(info.GetString("InternalRectangle")));
            if (Serialize.Contains(info, "Rotation"))
            {
                Rotation = info.GetSingle("Rotation");
            }

            if (Serialize.Contains(info, "Label", typeof(TextLabel)))
            {
                Label = (TextLabel)info.GetValue("Label", typeof(TextLabel));
            }
            if (Serialize.Contains(info, "Image", typeof(Image)))
            {
                Image = (Image)info.GetValue("Image", typeof(Image));
            }
            if (Serialize.Contains(info, "StencilItem", typeof(StencilItem)))
            {
                mStencilItem = (StencilItem)info.GetValue("StencilItem", typeof(StencilItem));
            }

            SuspendEvents = false;
        }
Ejemplo n.º 2
0
        public SolidElement(SolidElement prototype) : base(prototype)
        {
            mBlend          = prototype.Blend;
            mCustomBrush    = prototype.CustomBrush;
            mDrawBackground = prototype.DrawBackground;
            mDrawBorder     = prototype.DrawBorder;
            mDrawGradient   = prototype.DrawGradient;
            mBackColor      = prototype.BackColor;
            mGradientColor  = prototype.GradientColor;
            mGradientMode   = prototype.GradientMode;
            mRotation       = prototype.Rotation;

            mTransformPath              = prototype.TransformPath;
            mTransformRectangle         = prototype.TransformRectangle;
            mTransformInternalRectangle = prototype.TransformInternalRectangle;

            if (prototype.Label != null)
            {
                Label = (TextLabel)prototype.Label.Clone();
            }
            if (prototype.Image != null)
            {
                Image = (Image)prototype.Image.Clone();
            }

            mStencilItem = prototype.StencilItem;
            //if (prototype.StencilItem != null) mStencilItem = (StencilItem) prototype.StencilItem.Clone();

            mInternalRectangle = prototype.InternalRectangle;
        }
Ejemplo n.º 3
0
        public Solid(Solid prototype) : base(prototype)
        {
            _customBrush    = prototype.CustomBrush;
            _drawBackground = prototype.DrawBackground;
            _drawBorder     = prototype.DrawBorder;
            _drawGradient   = prototype.DrawGradient;
            _backColor      = prototype.BackColor;
            _gradientColor  = prototype.GradientColor;
            _gradientMode   = prototype.GradientMode;
            _rotation       = prototype.Rotation;

            _transformPath              = prototype.TransformPath;
            _transformRectangle         = prototype.TransformRectangle;
            _transformInternalRectangle = prototype.TransformInternalRectangle;

            if (prototype.Label != null)
            {
                Label = (Label)prototype.Label.Clone();
            }
            if (prototype.Image != null)
            {
                Image = (Image)prototype.Image.Clone();
            }

            _stencilItem = prototype.StencilItem;
            //if (prototype.StencilItem != null) _stencilItem = (StencilItem) prototype.StencilItem.Clone();

            _internalRectangle = prototype.InternalRectangle;
            _clip = prototype.Clip;
        }
Ejemplo n.º 4
0
 private void SetSizeInternal(float width, float height, RectangleF internalRectangle)
 {
     if (StencilItem != null && StencilItem.Redraw)
     {
         SetPath(StencilItem.Draw(width, height), internalRectangle);
     }
     else
     {
         float scaleX = Convert.ToSingle(width / Rectangle.Width);
         float scaleY = Convert.ToSingle(height / Rectangle.Height);
         ScalePath(scaleX, scaleY, 0, 0, internalRectangle);
     }
 }
Ejemplo n.º 5
0
        private void CreateStencilItems()
        {
            SetModifiable(true);

            //Loop through each enumeration and add as a stencil item
            foreach (string type in Enum.GetNames(typeof(ArrowStencilType)))
            {
                StencilItem item = new StencilItem();
                item.DrawShape += new DrawShapeEventHandler(StencilItem_DrawShape);

                Add(type, item);
            }

            SetModifiable(false);
        }
Ejemplo n.º 6
0
        private void SetSizeInternal(float width, float height)
        {
            if (StencilItem != null && StencilItem.Redraw)
            {
                SetPath(StencilItem.Draw(width, height), StencilItem.InternalRectangle(width, height));
            }
            else
            {
                float scaleX = Convert.ToSingle(width / Rectangle.Width);
                float scaleY = Convert.ToSingle(height / Rectangle.Height);

                //Scale rectangle
                RectangleF original = InternalRectangle;
                RectangleF rect     = new RectangleF(original.X * scaleX, original.Y * scaleY, original.Width * scaleX, original.Height * scaleY);
                ScalePath(scaleX, scaleY, 0, 0, rect);
            }
        }
Ejemplo n.º 7
0
        public Shape(StencilItem stencil)
        {
            AllowMove    = true;
            AllowScale   = true;
            AllowRotate  = false;
            DrawSelected = true;
            Direction    = Direction.Both;
            Interaction  = UserInteraction.BringToFront;

            MinimumSize = new SizeF(32, 32);
            MaximumSize = new SizeF(320, 320);

            //Set up stencil
            StencilItem = stencil;
            stencil.CopyTo(this);

            Ports = new Ports(Model);
        }
        public object Clone()
        {
            StencilItem item = new StencilItem();

            item.Redraw = _redraw;

            item.BorderColor   = _borderColor;
            item.BorderStyle   = _borderStyle;
            item.SmoothingMode = _smoothingMode;
            item.BackColor     = _backColor;
            item.GradientColor = _gradientColor;
            item.GradientMode  = _gradientMode;
            item.DrawGradient  = _drawGradient;
            item.Options       = _stencilItemOptions;

            item.SetBasePath(_basePath);
            item.SetBaseInternalRectangle(_baseInternalRectangle, _baseSize.Width, _baseSize.Height);

            return(item);
        }
Ejemplo n.º 9
0
        public object Clone()
        {
            StencilItem item = new StencilItem();

            item.Redraw = mRedraw;

            item.BorderColor   = mBorderColor;
            item.BorderStyle   = mBorderStyle;
            item.SmoothingMode = mSmoothingMode;
            item.BackColor     = mBackColor;
            item.GradientColor = mGradientColor;
            item.GradientMode  = mGradientMode;
            item.DrawGradient  = mDrawGradient;
            item.Options       = mStencilItemOptions;

            item.SetBasePath(mBasePath);
            item.SetBaseInternalRectangle(mBaseInternalRectangle, mBaseSize.Width, mBaseSize.Height);

            return(item);
        }
Ejemplo n.º 10
0
        public Shape(StencilItem stencil)
        {
            SuspendEvents = true;

            AllowMove    = true;
            AllowScale   = true;
            AllowRotate  = false;
            DrawSelected = true;
            Direction    = Direction.Both;
            Interaction  = UserInteraction.BringToFront;

            MinimumSize = new SizeF(32, 32);
            MaximumSize = new SizeF(320, 320);

            //Set up stencil
            StencilItem = stencil;
            stencil.CopyTo(this);

            Ports = new Elements(typeof(Port), "Port");

            SuspendEvents = false;
        }
Ejemplo n.º 11
0
        //Methods
        public virtual void Add(string key, StencilItem value)
        {
            if (!Modifiable)
            {
                throw new CollectionNotModifiableException("This collection is not modifiable.");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value", "StencilItem parameter cannot be null reference.");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key", "Key may not be null.");
            }
            if (key == "")
            {
                throw new ArgumentException("Key may not be null string.", "key");
            }

            value._key = key;
            Dictionary.Add(key, value);

            OnInsert(key, value);
        }
Ejemplo n.º 12
0
        private void CreateStencilItems()
        {
            SetModifiable(true);

            //Loop through each enumeration and add as a stencil item

            /* foreach (string type in Enum.GetNames(typeof(BasicStencilType)))
             * {
             *  StencilItem item = new StencilItem();
             *  item.DrawShape += new DrawShapeEventHandler(StencilItem_DrawShape);
             *
             *  Add(type, item);
             * }*/

            StencilItem item1 = new StencilItem();

            item1.DrawShape += new DrawShapeEventHandler(StencilItem_DrawShape);
            item1.Label      = new Label("Statement");
            Add(Enum.GetName(typeof(BasicStencilType), BasicStencilType.REGRA), item1);

            StencilItem item2 = new StencilItem();

            item2.DrawShape += new DrawShapeEventHandler(StencilItem_DrawShape);
            Add(Enum.GetName(typeof(BasicStencilType), BasicStencilType._E_), item2);

            StencilItem item3 = new StencilItem();

            item3.DrawShape += new DrawShapeEventHandler(StencilItem_DrawShape);
            Add(Enum.GetName(typeof(BasicStencilType), BasicStencilType._OU_), item3);

            //StencilItem item4 = new StencilItem();
            //item4.DrawShape += new DrawShapeEventHandler(StencilItem_DrawShape);
            //Add(Enum.GetName(typeof(BasicStencilType), BasicStencilType.CONECTOR), item4);

            SetModifiable(false);
        }
Ejemplo n.º 13
0
 private void CreateDefaultStencilItem()
 {
     mDefaultStencilItem        = new StencilItem();
     mDefaultStencilItem.Redraw = true;
 }
Ejemplo n.º 14
0
        private void DrawStencilItem(StencilItem stencil, DrawShapeEventArgs e)
        {
            ArrowStencilType stencilType     = (ArrowStencilType)Enum.Parse(typeof(ArrowStencilType), stencil.Key);
            Matrix           translateMatrix = new Matrix();

            if (stencilType == ArrowStencilType.Left || stencilType == ArrowStencilType.Right || stencilType == ArrowStencilType.Up || stencilType == ArrowStencilType.Down)
            {
                //Draw the arrow using a 100x100 grid
                e.Path.AddLine(0, 30, 60, 30);
                e.Path.AddLine(60, 30, 60, 0);
                e.Path.AddLine(60, 0, 100, 50);
                e.Path.AddLine(100, 50, 60, 100);
                e.Path.AddLine(60, 100, 60, 70);
                e.Path.AddLine(60, 70, 0, 70);

                //Close the figure
                e.Path.CloseFigure();

                //Rotate the path depending on the type of arrow
                if (stencilType == ArrowStencilType.Right)
                {
                    translateMatrix.RotateAt(180, new PointF(50, 50));
                }
                if (stencilType == ArrowStencilType.Up)
                {
                    translateMatrix.RotateAt(-90, new PointF(50, 50));
                }
                if (stencilType == ArrowStencilType.Down)
                {
                    translateMatrix.RotateAt(90, new PointF(50, 50));
                }

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 100, e.Height / 100);
                e.Path.Transform(translateMatrix);
            }
            else if (stencilType == ArrowStencilType.LeftRight || stencilType == ArrowStencilType.UpDown)
            {
                //Draw the arrow using a 120x100 grid
                e.Path.AddLine(40, 30, 80, 30);
                e.Path.AddLine(80, 30, 80, 0);
                e.Path.AddLine(80, 0, 120, 50);
                e.Path.AddLine(120, 50, 80, 100);
                e.Path.AddLine(80, 100, 80, 70);
                e.Path.AddLine(80, 70, 40, 70);

                e.Path.AddLine(40, 70, 40, 100);
                e.Path.AddLine(40, 100, 0, 50);
                e.Path.AddLine(0, 50, 40, 0);
                e.Path.AddLine(40, 0, 40, 30);

                if (stencilType == ArrowStencilType.UpDown)
                {
                    translateMatrix.RotateAt(90, new PointF(50, 50));
                }

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 120, e.Height / 100);
                e.Path.Transform(translateMatrix);

                stencil.Options = StencilItemOptions.InnerRectangleFull;
            }
            else if (stencilType == ArrowStencilType.LeftRightUpDown)
            {
                //Draw the arrow using a 140x140 grid
                e.Path.AddLine(80, 60, 110, 60);
                e.Path.AddLine(110, 60, 110, 50);
                e.Path.AddLine(110, 50, 140, 70);
                e.Path.AddLine(140, 70, 110, 90);
                e.Path.AddLine(110, 90, 110, 80);
                e.Path.AddLine(110, 80, 80, 80);

                e.Path.AddLine(80, 80, 80, 110);
                e.Path.AddLine(80, 110, 90, 110);
                e.Path.AddLine(90, 110, 70, 140);
                e.Path.AddLine(70, 140, 50, 110);
                e.Path.AddLine(50, 110, 60, 110);
                e.Path.AddLine(60, 110, 60, 80);

                e.Path.AddLine(60, 80, 30, 80);
                e.Path.AddLine(30, 80, 30, 90);
                e.Path.AddLine(30, 90, 0, 70);
                e.Path.AddLine(0, 70, 30, 50);
                e.Path.AddLine(30, 50, 30, 60);

                e.Path.AddLine(30, 60, 60, 60);
                e.Path.AddLine(60, 60, 60, 30);
                e.Path.AddLine(60, 30, 50, 30);
                e.Path.AddLine(50, 30, 70, 0);
                e.Path.AddLine(70, 0, 90, 30);
                e.Path.AddLine(90, 30, 80, 30);
                e.Path.AddLine(80, 30, 80, 60);

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 140, e.Height / 140);
                e.Path.Transform(translateMatrix);
            }
            if (stencilType == ArrowStencilType.Striped)
            {
                //Draw the arrow using a 100x100 grid
                e.Path.AddRectangle(new Rectangle(0, 30, 4, 40));
                e.Path.AddRectangle(new Rectangle(8, 30, 8, 40));

                e.Path.AddLine(20, 30, 60, 30);
                e.Path.AddLine(60, 30, 60, 0);
                e.Path.AddLine(60, 0, 100, 50);
                e.Path.AddLine(100, 50, 60, 100);
                e.Path.AddLine(60, 100, 60, 70);
                e.Path.AddLine(60, 70, 20, 70);

                //Close the figure
                e.Path.CloseFigure();

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 100, e.Height / 100);
                e.Path.Transform(translateMatrix);

                stencil.Options = StencilItemOptions.InnerRectangleFull;
            }
            if (stencilType == ArrowStencilType.Notched)
            {
                //Draw the arrow using a 100x100 grid
                e.Path.AddLine(0, 30, 60, 30);
                e.Path.AddLine(60, 30, 60, 0);
                e.Path.AddLine(60, 0, 100, 50);
                e.Path.AddLine(100, 50, 60, 100);
                e.Path.AddLine(60, 100, 60, 70);
                e.Path.AddLine(60, 70, 0, 70);
                e.Path.AddLine(0, 70, 20, 50);

                //Close the figure
                e.Path.CloseFigure();

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 100, e.Height / 100);
                e.Path.Transform(translateMatrix);
            }
            if (stencilType == ArrowStencilType.Pentagon)
            {
                //Draw the arrow using a 120x100 grid
                e.Path.AddLine(0, 0, 80, 0);
                e.Path.AddLine(80, 0, 120, 50);
                e.Path.AddLine(120, 50, 80, 100);
                e.Path.AddLine(80, 100, 0, 100);

                //Close the figure
                e.Path.CloseFigure();

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 100, e.Height / 100);
                e.Path.Transform(translateMatrix);
            }
            else if (stencilType == ArrowStencilType.Chevron)
            {
                //Draw the arrow using a 120x100 grid
                e.Path.AddLine(0, 0, 80, 0);
                e.Path.AddLine(80, 0, 120, 50);
                e.Path.AddLine(120, 50, 80, 100);
                e.Path.AddLine(80, 100, 0, 100);
                e.Path.AddLine(0, 100, 20, 50);

                //Close the figure
                e.Path.CloseFigure();

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 100, e.Height / 100);
                e.Path.Transform(translateMatrix);
            }
            else if (stencilType == ArrowStencilType.RightCallout || stencilType == ArrowStencilType.LeftCallout || stencilType == ArrowStencilType.UpCallout || stencilType == ArrowStencilType.DownCallout)
            {
                //Draw the arrow using a 120x100 grid
                e.Path.AddLine(0, 0, 80, 0);
                e.Path.AddLine(80, 0, 80, 40);
                e.Path.AddLine(80, 40, 90, 40);
                e.Path.AddLine(90, 40, 90, 30);
                e.Path.AddLine(90, 30, 120, 50);
                e.Path.AddLine(120, 50, 90, 70);
                e.Path.AddLine(90, 70, 90, 60);
                e.Path.AddLine(90, 60, 80, 60);
                e.Path.AddLine(80, 60, 80, 100);
                e.Path.AddLine(80, 100, 0, 100);

                //Close the figure
                e.Path.CloseFigure();

                //Rotate the matrix depending on type
                if (stencilType == ArrowStencilType.LeftCallout)
                {
                    translateMatrix.RotateAt(180, new PointF(60, 50));
                }
                if (stencilType == ArrowStencilType.UpCallout)
                {
                    translateMatrix.RotateAt(-90, new PointF(60, 50));
                }
                if (stencilType == ArrowStencilType.DownCallout)
                {
                    translateMatrix.RotateAt(90, new PointF(60, 50));
                }

                //Scale the matrix and apply it back to the path
                translateMatrix.Scale(e.Width / 100, e.Height / 100);
                e.Path.Transform(translateMatrix);
            }
        }
Ejemplo n.º 15
0
        private void StencilItem_DrawShape(object sender, DrawShapeEventArgs e)
        {
            StencilItem stencil = (StencilItem)sender;

            DrawStencilItem(stencil, e);
        }
Ejemplo n.º 16
0
        private void DrawStencilItem(StencilItem stencil, DrawShapeEventArgs e)
        {
            GraphicsPath     path        = e.Path;
            RectangleF       rect        = new Rectangle();
            BasicStencilType stencilType = (BasicStencilType)Enum.Parse(typeof(BasicStencilType), stencil.Key);

            float width  = e.Width;
            float height = e.Height;
            float percX  = 0;
            float percY  = 0;
            float midX   = 0;
            float midY   = 0;

            rect.Width  = width;
            rect.Height = height;

            if (stencilType == BasicStencilType.BottomTriangle)
            {
                path.AddLine(0, 0, width, 0);
                path.AddLine(width, 0, width / 2, height);
                path.CloseFigure();
            }
            else if (stencilType == BasicStencilType.Circle)
            {
                percX = Convert.ToSingle(width * 0.5);
                percY = Convert.ToSingle(height * 0.5);

                path.AddEllipse(percX, percY, width, height);
            }
            else if (stencilType == BasicStencilType.Diamond)
            {
                percX = Convert.ToSingle(width * 0.5);
                percY = Convert.ToSingle(height * 0.5);

                path.AddLine(0, percY, percX, 0);
                path.AddLine(percX, 0, width, percY);
                path.AddLine(width, percY, percX, height);
                path.AddLine(percX, height, 0, percY);
            }
            else if (stencilType == BasicStencilType.Ellipse)
            {
                percX = Convert.ToSingle(width * 0.5);
                percY = Convert.ToSingle(height * 0.5);

                path.AddEllipse(percX, percY, width, height);
            }
            else if (stencilType == BasicStencilType.LeftTriangle)
            {
                percX = Convert.ToSingle(width * 0.5);
                percY = Convert.ToSingle(height * 0.5);

                path.AddLine(width, 0, 0, percY);
                path.AddLine(0, percY, width, height);
                path.CloseFigure();
            }
            else if (stencilType == BasicStencilType.Octagon)
            {
                float thirdx    = width * 0.3F;
                float twothirdx = width * 0.7F;
                float thirdy    = height * 0.3F;
                float twothirdy = height * 0.7F;

                path.AddLine(thirdx, 0, twothirdx, 0);
                path.AddLine(twothirdx, 0, width, thirdy);
                path.AddLine(width, thirdy, width, twothirdy);
                path.AddLine(width, twothirdy, twothirdx, height);
                path.AddLine(twothirdx, height, thirdx, height);
                path.AddLine(thirdx, height, 0, twothirdy);
                path.AddLine(0, twothirdy, 0, thirdy);
                path.CloseFigure();
            }
            else if (stencilType == BasicStencilType.Rectangle)
            {
                path.AddRectangle(rect);
            }
            else if (stencilType == BasicStencilType.RightTriangle)
            {
                percY = height * 0.5F;

                path.AddLine(0, 0, width, percY);
                path.AddLine(width, percY, 0, height);
                path.CloseFigure();
            }
            else if (stencilType == BasicStencilType.RoundedRectangle)
            {
                percX = Convert.ToSingle(width * 0.2);
                percY = Convert.ToSingle(height * 0.2);

                if (percX < percY)
                {
                    percY = percX;
                }
                else
                {
                    percX = percY;
                }
                path.AddArc(0, 0, percX, percY, 180, 90);
                path.AddArc(width - percX, 0, percX, percY, 270, 90);
                path.AddArc(width - percX, height - percY, percX, percY, 0, 90);
                path.AddArc(0, height - percY, percX, percY, 90, 90);
                path.CloseFigure();

                stencil.Redraw = true;
            }
            else if (stencilType == BasicStencilType.TopTriangle)
            {
                percX = Convert.ToSingle(width * 0.5);

                path.AddLine(percX, 0, width, height);
                path.AddLine(width, height, 0, height);
                path.CloseFigure();
            }
        }
Ejemplo n.º 17
0
        //Scale a shape using ratios
        private void ScaleShape(float sx, float sy, float dx, float dy, bool maintainAspect)
        {
            //Check min and max sizes
            if (!KeepAspect || Width >= Height)
            {
                if (MaximumSize.Width < (Bounds.Width * sx))
                {
                    sx = Convert.ToSingle(MaximumSize.Width / Bounds.Width);
                }
                if (MinimumSize.Width > (Bounds.Width * sx))
                {
                    sx = Convert.ToSingle(MinimumSize.Width / Bounds.Width);
                }
            }

            if (!KeepAspect || Height >= Width)
            {
                if (MaximumSize.Height < (Bounds.Height * sy))
                {
                    sy = Convert.ToSingle(MaximumSize.Height / Bounds.Height);
                }
                if (MinimumSize.Height > (Bounds.Height * sy))
                {
                    sy = Convert.ToSingle(MinimumSize.Height / Bounds.Height);
                }
            }

            if (maintainAspect)
            {
                if (sx < sy)
                {
                    sy = sx;
                }
                else
                {
                    sx = sy;
                }
            }

            //Get the new size
            float width  = Width * sx;
            float height = Height * sy;

            if (StencilItem != null && StencilItem.Redraw)
            {
                SetPath(StencilItem.Draw(width, height), StencilItem.InternalRectangle(width, height));
                SetRectangle(new PointF(Location.X + dx, Location.Y + dy));
            }
            else
            {
                if (StencilItem == null)
                {
                    RectangleF original = InternalRectangle;
                    RectangleF rect     = new RectangleF(original.X * sx, original.Y * sy, original.Width * sx, original.Height * sy);
                    ScalePath(sx, sy, dx, dy, rect);
                }
                else
                {
                    ScalePath(sx, sy, dx, dy, StencilItem.InternalRectangle(width, height));
                }
            }

            //Offset the ports before the new rectangle is updated
            ScalePorts(sx, sy, dx, dy);
            CreateHandles();
        }