private NCompositeShape CreateCrossPipe()
        {
            NDynamicPort    port;
            NCompositeShape shape   = new NCompositeShape();
            NPolygonPath    polygon = new NPolygonPath(new NPointF[] {
                new NPointF(0, SIZE),
                new NPointF(SIZE, SIZE),
                new NPointF(SIZE, 0),
                new NPointF(2 * SIZE, 0),
                new NPointF(2 * SIZE, SIZE),
                new NPointF(3 * SIZE, SIZE),
                new NPointF(3 * SIZE, 2 * SIZE),
                new NPointF(2 * SIZE, 2 * SIZE),
                new NPointF(2 * SIZE, 3 * SIZE),
                new NPointF(SIZE, 3 * SIZE),
                new NPointF(SIZE, 2 * SIZE),
                new NPointF(0, 2 * SIZE)
            });

            NStyle.SetStrokeStyle(polygon, new NStrokeStyle(0, Color.White));
            shape.Primitives.AddChild(polygon);
            shape.Primitives.AddChild(new NLinePath(0, SIZE, SIZE, SIZE));
            shape.Primitives.AddChild(new NLinePath(SIZE, SIZE, SIZE, 0));
            shape.Primitives.AddChild(new NLinePath(2 * SIZE, 0, 2 * SIZE, SIZE));
            shape.Primitives.AddChild(new NLinePath(2 * SIZE, SIZE, 3 * SIZE, SIZE));
            shape.Primitives.AddChild(new NLinePath(3 * SIZE, 2 * SIZE, 2 * SIZE, 2 * SIZE));
            shape.Primitives.AddChild(new NLinePath(2 * SIZE, 2 * SIZE, 2 * SIZE, 3 * SIZE));
            shape.Primitives.AddChild(new NLinePath(SIZE, 3 * SIZE, SIZE, 2 * SIZE));
            shape.Primitives.AddChild(new NLinePath(SIZE, 2 * SIZE, 0, 2 * SIZE));
            shape.UpdateModelBounds();

            if (shape.Ports == null)
            {
                shape.CreateShapeElements(ShapeElementsMask.Ports);
            }

            port      = new NDynamicPort(shape.UniqueId, LEFT, DynamicPortGlueMode.GlueToContour);
            port.Type = PortType.InwardAndOutward;
            shape.Ports.AddChild(port);

            port      = new NDynamicPort(shape.UniqueId, TOP, DynamicPortGlueMode.GlueToContour);
            port.Type = PortType.InwardAndOutward;
            shape.Ports.AddChild(port);

            port      = new NDynamicPort(shape.UniqueId, RIGHT, DynamicPortGlueMode.GlueToContour);
            port.Type = PortType.InwardAndOutward;
            shape.Ports.AddChild(port);

            port      = new NDynamicPort(shape.UniqueId, BOTTOM, DynamicPortGlueMode.GlueToContour);
            port.Type = PortType.InwardAndOutward;
            shape.Ports.AddChild(port);

            SetProtections(shape);
            return(shape);
        }
Exemple #2
0
        protected NCompositeShape CreateCoffeeCupShape(NPointF location, float scale)
        {
            NCompositeShape shape = new NCompositeShape();

            // create the cup as a polygon path
            NPolygonPath cup = new NPolygonPath(new NPointF[] { new NPointF(45, 268),
                                                                new NPointF(63, 331),
                                                                new NPointF(121, 331),
                                                                new NPointF(140, 268) });

            shape.Primitives.AddChild(cup);

            // create the cup hangle as a closed curve path
            NClosedCurvePath handle = new NClosedCurvePath(new NPointF[] { new NPointF(175, 295),
                                                                           new NPointF(171, 278),
                                                                           new NPointF(140, 283),
                                                                           new NPointF(170, 290),
                                                                           new NPointF(128, 323) }, 1);

            NStyle.SetFillStyle(handle, new NColorFillStyle(Color.LightSalmon));
            shape.Primitives.AddChild(handle);

            // create the steam as a custom filled path
            GraphicsPath path = new GraphicsPath();

            path.AddBeziers(new PointF[] { new PointF(92, 258),
                                           new PointF(53, 163),
                                           new PointF(145, 160),
                                           new PointF(86, 50),
                                           new PointF(138, 194),
                                           new PointF(45, 145),
                                           new PointF(92, 258) });
            path.CloseAllFigures();

            NCustomPath steam = new NCustomPath(path, PathType.ClosedFigure);

            NStyle.SetFillStyle(steam, new NColorFillStyle(Color.FromArgb(50, 122, 122, 122)));
            shape.Primitives.AddChild(steam);

            // update the shape model bounds to fit the primitives it contains
            shape.UpdateModelBounds();

            // create the shape ports
            shape.CreateShapeElements(ShapeElementsMask.Ports);

            // create dynamic port anchored to the cup center
            NDynamicPort dynamicPort = new NDynamicPort(cup.UniqueId, ContentAlignment.MiddleCenter, DynamicPortGlueMode.GlueToContour);

            shape.Ports.AddChild(dynamicPort);

            // create rotated bounds port anchored to the middle right side of the handle
            NRotatedBoundsPort rotatedBoundsPort = new NRotatedBoundsPort(handle.UniqueId, ContentAlignment.MiddleRight);

            shape.Ports.AddChild(rotatedBoundsPort);

            // apply style to the shape
            shape.Style.FillStyle = new NColorFillStyle(Color.LightCoral);

            // position it and scale the shape
            shape.Location = location;
            shape.Width    = shape.Width * scale;
            shape.Height   = shape.Height * scale;

            return(shape);
        }
        private NCompositeShape CreateEndPipe(string type)
        {
            NDynamicPort      port;
            NCompositeShape   shape = new NCompositeShape();
            NPolygonPath      polygon;
            NContentAlignment ca;

            switch (type)
            {
            case "W":
                polygon = new NPolygonPath(new NPointF[] {
                    new NPointF(3 * SIZE, SIZE),
                    new NPointF(2 * SIZE, 1.5f * SIZE),
                    new NPointF(3 * SIZE, 2 * SIZE)
                });

                ca = RIGHT;
                break;

            case "N":
                polygon = new NPolygonPath(new NPointF[] {
                    new NPointF(SIZE, 3 * SIZE),
                    new NPointF(1.5f * SIZE, 2 * SIZE),
                    new NPointF(2 * SIZE, 3 * SIZE)
                });

                ca = BOTTOM;
                break;

            case "E":
                polygon = new NPolygonPath(new NPointF[] {
                    new NPointF(0, SIZE),
                    new NPointF(SIZE, 1.5f * SIZE),
                    new NPointF(0, 2 * SIZE)
                });

                ca = LEFT;
                break;

            case "S":
                polygon = new NPolygonPath(new NPointF[] {
                    new NPointF(SIZE, 0),
                    new NPointF(1.5f * SIZE, SIZE),
                    new NPointF(2 * SIZE, 0)
                });

                ca = TOP;
                break;

            default:
                throw new ArgumentException("Unsupported elbow pipe type");
            }

            NStyle.SetStrokeStyle(polygon, new NStrokeStyle(0, Color.White));
            shape.Primitives.AddChild(polygon);
            shape.Primitives.AddChild(new NLinePath(polygon.Points[0], polygon.Points[1]));
            shape.Primitives.AddChild(new NLinePath(polygon.Points[1], polygon.Points[2]));
            shape.UpdateModelBounds(new NRectangleF(0, 0, 3 * SIZE, 3 * SIZE));

            if (shape.Ports == null)
            {
                shape.CreateShapeElements(ShapeElementsMask.Ports);
            }

            port      = new NDynamicPort(shape.UniqueId, ca, DynamicPortGlueMode.GlueToContour);
            port.Type = PortType.InwardAndOutward;
            shape.Ports.AddChild(port);

            SetProtections(shape);
            return(shape);
        }