コード例 #1
0
        protected void InitDocument(NDrawingDocument document)
        {
            document.BackgroundStyle.FrameStyle.Visible = false;
            document.AutoBoundsPadding = new Nevron.Diagram.NMargins(10f, 10f, 10f, 10f);
            document.Style.FillStyle   = new NColorFillStyle(Color.White);

            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            NShape outerCircle = factory.CreateShape(BasicShapes.Circle);

            outerCircle.Bounds = new NRectangleF(0f, 0f, 200f, 200f);
            document.ActiveLayer.AddChild(outerCircle);

            NShape rect = factory.CreateShape(BasicShapes.Rectangle);

            rect.Bounds          = new NRectangleF(42f, 42f, 50f, 50f);
            rect.Style.FillStyle = new NColorFillStyle(Color.Orange);
            document.ActiveLayer.AddChild(rect);

            NShape triangle = factory.CreateShape(BasicShapes.Triangle);

            triangle.Bounds          = new NRectangleF(121f, 57f, 60f, 55f);
            triangle.Style.FillStyle = new NColorFillStyle(Color.LightGray);
            document.ActiveLayer.AddChild(triangle);

            NShape pentagon = factory.CreateShape(BasicShapes.Pentagon);

            pentagon.Bounds          = new NRectangleF(60f, 120f, 54f, 50f);
            pentagon.Style.FillStyle = new NColorFillStyle(Color.WhiteSmoke);
            document.ActiveLayer.AddChild(pentagon);

            document.SizeToContent();
        }
コード例 #2
0
        private void CreateDiagram()
        {
            int min = 100;
            int max = 200;

            NShape shape;
            Random random = new Random();
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory(document);

            for (int i = 0; i < 15; i++)
            {
                shape      = basicShapesFactory.CreateShape((int)BasicShapes.Rectangle);
                shape.Text = i.ToString();

                // generate random width and height
                float width  = random.Next(min, max);
                float height = random.Next(min, max);

                // instruct the layouts to use fixed, uses specified desired width and desired height
                shape.LayoutData.UseShapeWidth = false;
                shape.LayoutData.DesiredWidth  = width;

                shape.LayoutData.UseShapeHeight = false;
                shape.LayoutData.DesiredHeight  = height;

                shape.Bounds = new NRectangleF(0, 0, width, height);
                document.ActiveLayer.AddChild(shape);
            }
        }
コード例 #3
0
        private void CreateTree(int levels, int branchNodes)
        {
            // clean up the active layer
            NDrawingView1.Document.ActiveLayer.RemoveAllChildren();

            // we will be using basic shapes with 40, 40 size
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(40, 40);

            NShape cur  = null;
            NShape edge = null;

            List <NShape> curRowNodes  = null;
            List <NShape> prevRowNodes = null;

            int i, level;
            int levelNodesCount;

            for (level = 1; level <= levels; level++)
            {
                curRowNodes = new List <NShape>();

                //Create a balanced tree
                levelNodesCount = (int)Math.Pow(branchNodes, level - 1);
                for (i = 0; i < levelNodesCount; i++)
                {
                    // create the cur node
                    cur = basicShapesFactory.CreateShape(BasicShapes.Circle);
                    ((NDynamicPort)cur.Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                    NDrawingView1.Document.ActiveLayer.AddChild(cur);

                    // connect with ancestor
                    if (level > 1)
                    {
                        edge = new NLineShape();
                        NDrawingView1.Document.ActiveLayer.AddChild(edge);

                        int parentIndex = (int)Math.Floor((double)(i / branchNodes));
                        edge.FromShape = prevRowNodes[parentIndex];
                        edge.ToShape   = cur;
                    }

                    curRowNodes.Add(cur);
                }

                prevRowNodes = curRowNodes;
            }

            // send links to back
            NBatchReorder batchReorder = new NBatchReorder(NDrawingView1.Document);

            batchReorder.Build(NDrawingView1.Document.ActiveLayer.Children(NFilters.Shape1D));
            batchReorder.SendToBack(false);
        }
コード例 #4
0
        private void InitDocument()
        {
            document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8));

            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            factory.DefaultSize = new NSizeF(80, 60);

            int    count = factory.ShapesCount;
            NShape shape = null;

            for (int i = 0; i < count; i++)
            {
                // create a basic shape
                shape      = factory.CreateShape(i);
                shape.Text = shape.Name;

                // add it to the active layer
                document.ActiveLayer.AddChild(shape);
            }

            // Add some content to the table shape
            NTableShape table = (NTableShape)shape;

            table.InitTable(2, 2);
            table.BeginUpdate();
            table.CellMargins          = new Nevron.Diagram.NMargins(8);
            table[0, 0].Text           = "Cell 1";
            table[1, 0].Text           = "Cell 2";
            table[0, 1].Text           = "Cell 3";
            table[1, 1].Text           = "Cell 4";
            table.PortDistributionMode = TablePortDistributionMode.CellBased;
            table.EndUpdate();

            // layout the shapes in the active layer using a table layout
            NTableLayout layout = new NTableLayout();

            // setup the table layout
            layout.Direction     = LayoutDirection.LeftToRight;
            layout.ConstrainMode = CellConstrainMode.Ordinal;
            layout.MaxOrdinal    = 5;
            layout.HorizontalContentPlacement = ContentPlacement.Center;
            layout.VerticalContentPlacement   = ContentPlacement.Center;
            layout.VerticalSpacing            = 20;
            layout.HorizontalSpacing          = 20;

            // get the shapes to layout
            NNodeList shapes = document.ActiveLayer.Children(NFilters.Shape2D);

            // layout the shapes
            layout.Layout(shapes, new NDrawingLayoutContext(document));

            // resize document to fit all shapes
            document.SizeToContent();
        }
コード例 #5
0
        /// <summary>
        /// Creates a new basic shape and adds it to the document's active layer.
        /// </summary>
        /// <param name="basicShape"></param>
        /// <param name="bounds"></param>
        /// <param name="text"></param>
        /// <param name="styleSheetName"></param>
        /// <returns></returns>
        public NShape CreateBasicShape(BasicShapes basicShape, NRectangleF bounds, string text, string styleSheetName)
        {
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)basicShape);

            shape.Bounds         = bounds;
            shape.Text           = text;
            shape.StyleSheetName = styleSheetName;
            document.ActiveLayer.AddChild(shape);

            return(shape);
        }
コード例 #6
0
ファイル: NUndoRedoUC.cs プロジェクト: Nevron-Software/Vision
        private void AddRandomShape()
        {
            Array values = Enum.GetValues(typeof(BasicShapes));

            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)values.GetValue(Random.Next(values.Length)));

            shape.Bounds = new NRectangleF(base.GetRandomPoint(view.Viewport),
                                           base.GetRandomSize(new NSizeF(10, 10), new NSizeF(100, 100)));

            document.ActiveLayer.AddChild(shape);
        }
コード例 #7
0
        protected override void LoadExample()
        {
            // attach the library browser to the command bars manager,
            // in order so that it can display context menus
            Form.CommandBarsManager.LibraryBrowser = libraryBrowser;

            // clear all bands (library groups)
            libraryBrowser.ClearBands();

            // create a new library
            NLibraryDocument library = new NLibraryDocument();

            library.Info.Title = "My first library";

            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            // add several masters in the library
            NShape shape = factory.CreateShape((int)BasicShapes.Pentagram);

            shape.Width  = 130;
            shape.Height = 130;
            library.AddChild(new NMaster(shape, NGraphicsUnit.Pixel, "Star", "My star"));

            shape        = factory.CreateShape((int)BasicShapes.Octagram);
            shape.Width  = 130;
            shape.Height = 130;
            library.AddChild(new NMaster(shape, NGraphicsUnit.Pixel, "Octagon", "My octagon"));

            // create a new library group hosting the library
            libraryBrowser.OpenLibraryGroup(library);

            // start view init
            view.BeginInit();

            document.Style.StartArrowheadStyle.Shape = ArrowheadShape.None;
            document.Style.EndArrowheadStyle.Shape   = ArrowheadShape.None;
            view.AllowDrop = true;

            // init document
            document.BeginInit();
            CreateCustomOpenFigureShape();
            CreateCustomClosedFigureShape();
            document.EndInit();

            // init form controls
            InitFormControls();

            // end view init
            view.EndInit();
        }
コード例 #8
0
        private void AddRandomShape()
        {
            Array values = Enum.GetValues(typeof(BasicShapes));

            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)values.GetValue(Random.Next(values.Length)));

            NSizeF size = new NSizeF(Random.Next(10) + 30, Random.Next(10) + 30);

            shape.Bounds          = new NRectangleF(base.GetRandomPoint(view.Viewport), size);
            shape.Style.FillStyle = new NColorFillStyle(Color.GreenYellow);

            document.ActiveLayer.AddChild(shape);
        }
コード例 #9
0
        /// <summary>
        /// Creates a predefined basic shape
        /// </summary>
        /// <param name="basicShape">basic shape</param>
        /// <param name="bounds">bounds</param>
        /// <param name="text">default label text</param>
        /// <param name="styleSheetName">name of the stylesheet from which to inherit styles</param>
        /// <returns>new basic shape</returns>
        protected NShape CreateBasicShape(BasicShapes basicShape, NRectangleF bounds, string text, string styleSheetName)
        {
            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            factory.DefaultSize = bounds.Size;
            NShape shape = factory.CreateShape((int)basicShape);

            shape.Location       = bounds.Location;
            shape.Text           = text;
            shape.StyleSheetName = styleSheetName;

            document.ActiveLayer.AddChild(shape);
            return(shape);
        }
コード例 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="basicShape"></param>
        /// <param name="bounds"></param>
        /// <param name="text"></param>
        /// <param name="fillStyle"></param>
        /// <param name="addToActiveLayer"></param>
        /// <returns></returns>
        public NShape CreateBasicShape(BasicShapes basicShape, NRectangleF bounds, string text, NFillStyle fillStyle, bool addToActiveLayer)
        {
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)basicShape);

            shape.Bounds          = bounds;
            shape.Text            = text;
            shape.Style.FillStyle = (NFillStyle)fillStyle.Clone();

            if (addToActiveLayer)
            {
                document.ActiveLayer.AddChild(shape);
            }

            return(shape);
        }
コード例 #11
0
        protected static NRectangleShape CreateCell(NDrawingDocument document, int x, int y, int number)
        {
            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            NRectangleShape cell = factory.CreateShape((int)BasicShapes.Rectangle) as NRectangleShape;

            cell.Bounds            = new NRectangleF(boardMarginLeft + cellPixelWidth * x + boardPadding, boardMarginTop + cellPixelWidth * y + boardPadding, cellPixelWidth, cellPixelHeight);
            cell.Style.StrokeStyle = normalCellStrokeStyle;
            cell.Style.FillStyle   = emptyCellFillStyle;
            cell.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(65, Color.Black), new NPointL(shadowOffset, shadowOffset), 1, new NLength(shadowOffset * 2));
            cell.Name = string.Format("{0}, {1}", x, y);
            cell.Tag  = number;
            cell.Text = number.ToString();

            document.ActiveLayer.AddChild(cell);
            return(cell);
        }
コード例 #12
0
        private void CreateDiagram()
        {
            const int           width = 40, height = 40, distance = 80;
            NBasicShapesFactory f = new NBasicShapesFactory(document);
            NRoutableConnector  edge;

            int[]    from        = new int[] { 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6 };
            int[]    to          = new int[] { 2, 3, 4, 4, 5, 8, 6, 7, 5, 8, 10, 8, 9, 10 };
            NShape[] shapes      = new NShape[10];
            int      vertexCount = shapes.Length;
            int      edgeCount   = from.Length;
            int      count       = vertexCount + edgeCount;

            for (int i = 0; i < count; i++)
            {
                if (i < vertexCount)
                {
                    int j = vertexCount % 2 == 0 ? i : i + 1;
                    shapes[i] = f.CreateShape((int)BasicShapes.Rectangle);

                    if (vertexCount % 2 != 0 && i == 0)
                    {
                        shapes[i].Bounds = new NRectangleF((int)(width + (distance * 1.5)) / 2,
                                                           distance + (j / 2) * (int)(distance * 1.5), width, height);
                    }
                    else
                    {
                        shapes[i].Bounds = new NRectangleF(width / 2 + (j % 2) * (int)(distance * 1.5),
                                                           height + (j / 2) * (int)(distance * 1.5), width, height);
                    }

                    document.ActiveLayer.AddChild(shapes[i]);
                }
                else
                {
                    edge = new NRoutableConnector();
                    edge.ConnectorType  = RoutableConnectorType.DynamicPolyline;
                    edge.StyleSheetName = "CustomConnectors";
                    document.ActiveLayer.AddChild(edge);
                    edge.FromShape = shapes[from[i - vertexCount] - 1];
                    edge.ToShape   = shapes[to[i - vertexCount] - 1];
                }
            }
        }
コード例 #13
0
ファイル: NDragDropUC.cs プロジェクト: Nevron-Software/Vision
        private void CreateSourceScene()
        {
            sourceDocument.AutoBoundsMode = AutoBoundsMode.CustomNonConstrained;

            NRectangleF cell;
            int         row = 0, col = 0;
            int         width = (sourceView.Width - 40) / 3;

            NShape shape = null;
            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            factory.DefaultSize = new NSizeF(50, 50);

            foreach (BasicShapes basicShape in Enum.GetValues(typeof(BasicShapes)))
            {
                shape        = factory.CreateShape((int)basicShape);
                shape.Bounds = GetGridCell(row, col, new NPointF(0, 0), new NSizeF(50, 50), new NSizeF(10, 10));

                sourceDocument.ActiveLayer.AddChild(shape);
                col++;

                if (col > 2)
                {
                    row++;
                    col = 0;
                }
            }

            // Add some content to the table shape
            NTableShape table = (NTableShape)shape;

            table.InitTable(2, 2);
            table.BeginUpdate();
            table.CellMargins          = new Nevron.Diagram.NMargins(8);
            table[0, 0].Text           = "1";
            table[1, 0].Text           = "2";
            table[0, 1].Text           = "3";
            table[1, 1].Text           = "4";
            table.PortDistributionMode = TablePortDistributionMode.CellBased;
            table.EndUpdate();

            sourceDocument.AutoBoundsMode = AutoBoundsMode.AutoSizeToContent;
            sourceDocument.RefreshAllViews();
        }
コード例 #14
0
        private void InitDocument()
        {
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(100, 100);

            // create groups and apply a frame decorator to each one of them
            for (int i = 0; i < 4; i++)
            {
                NShape shape1 = basicShapesFactory.CreateShape(BasicShapes.Octagon);
                shape1.Bounds = new NRectangleF(0, 0, 80, 80);

                NShape shape2 = basicShapesFactory.CreateShape(BasicShapes.Ellipse);
                shape2.Bounds = new NRectangleF(100, 100, 80, 80);

                NGroup group = new NGroup();
                group.Shapes.AddChild(shape1);
                group.Shapes.AddChild(shape2);
                group.Padding = new Nevron.Diagram.NMargins(30);
                group.UpdateModelBounds();

                NFrameDecorator frameDecorator = new NFrameDecorator();
                frameDecorator.StyleSheetName   = "Decorators";
                frameDecorator.ShapeHitTestable = true;
                frameDecorator.Header.Text      = "Header";

                group.CreateShapeElements(ShapeElementsMask.Decorators);
                group.Decorators.AddChild(frameDecorator);

                document.ActiveLayer.AddChild(group);
            }

            // layout them with a table layout
            NTableLayout layout = new NTableLayout();

            layout.ConstrainMode     = CellConstrainMode.Ordinal;
            layout.MaxOrdinal        = 2;
            layout.HorizontalSpacing = 20;
            layout.VerticalSpacing   = 20;
            layout.Layout(document.ActiveLayer.Children(null), new NDrawingLayoutContext(document));

            // size document to content
            document.SizeToContent(NSizeF.Empty, document.AutoBoundsPadding);
        }
コード例 #15
0
        private void CreateShapeWithDynamicPort()
        {
            // NOTE: the triangle shape is by default created with one dynamic port (the default one) and
            // three rotated bounds ports located at the triangle vertices).
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)BasicShapes.Triangle);

            shape.Name   = "Shape with Dynamic Port";
            shape.Bounds = base.GetGridCell(0, 1);

            // connect it with the center shape
            document.ActiveLayer.AddChild(shape);
            ConnectShapes(centerShape, shape);

            // describe it
            NTextShape text = new NTextShape("Shape with Dynamic Port", base.GetGridCell(0, 2, 0, 1));

            document.ActiveLayer.AddChild(text);
        }
コード例 #16
0
        private void InitDocument()
        {
            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            // create interactive rect
            NShape rect = factory.CreateShape((int)BasicShapes.Rectangle);

            rect.Bounds = base.GetGridCell(0, 0);
            rect.Text   = InitialShapeText;
            rect.Name   = "Interactive Rectangle";
            rect.Style.InteractivityStyle = new NInteractivityStyle("I am a rectangle with hand cursor", CursorType.Hand);
            document.ActiveLayer.AddChild(rect);

            // create interactive ellipse
            NShape ellipse = factory.CreateShape((int)BasicShapes.Ellipse);

            ellipse.Bounds = base.GetGridCell(0, 1);
            ellipse.Text   = InitialShapeText;
            ellipse.Name   = "Interactive Ellipse";
            ellipse.Style.InteractivityStyle = new NInteractivityStyle("I am an ellipse with wait cursor", CursorType.WaitCursor);
            document.ActiveLayer.AddChild(ellipse);

            // create interactive rounded rect
            NShape roundedRect = factory.CreateShape((int)BasicShapes.RoundedRectangle);

            roundedRect.Bounds = base.GetGridCell(1, 0);
            roundedRect.Text   = InitialShapeText;
            roundedRect.Name   = "Interactive Rounded Rectangle";
            roundedRect.Style.InteractivityStyle = new NInteractivityStyle("I am a rounded rectangle with cross cursor", CursorType.Cross);
            document.ActiveLayer.AddChild(roundedRect);

            // create interactive hexagram
            NShape hexagram = factory.CreateShape((int)BasicShapes.Hexagram);

            hexagram.Bounds = base.GetGridCell(1, 1);
            hexagram.Text   = InitialShapeText;
            hexagram.Name   = "Interactive Hexagram";
            hexagram.Style.InteractivityStyle = new NInteractivityStyle("I am a hexagram with help cursor", CursorType.Help);
            document.ActiveLayer.AddChild(hexagram);

            // initially focus the rect
            FocusShape(rect);
        }
コード例 #17
0
        private void CreateDiagram()
        {
            const int min = 100, max = 200;

            int    i;
            NShape shape;
            Random random = new Random();
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory(document);

            for (i = 0; i < 5; i++)
            {
                Color[] shapeLightColors = new Color[] { Color.FromArgb(236, 97, 49),
                                                         Color.FromArgb(68, 90, 108),
                                                         Color.FromArgb(247, 150, 56),
                                                         Color.FromArgb(129, 133, 133),
                                                         Color.FromArgb(255, 165, 109) };

                Color[] shapeDarkColors = new Color[] { Color.FromArgb(246, 176, 152),
                                                        Color.FromArgb(162, 173, 182),
                                                        Color.FromArgb(251, 203, 156),
                                                        Color.FromArgb(192, 194, 194),
                                                        Color.FromArgb(255, 210, 182) };

                shape = basicShapesFactory.CreateShape((int)BasicShapes.Rectangle);
                shape.Style.FillStyle   = new NGradientFillStyle(GradientStyle.Vertical, GradientVariant.Variant3, shapeLightColors[i], shapeDarkColors[i]);
                shape.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
                shape.Text = i.ToString();

                // generate random width and height
                float width  = random.Next(min, max);
                float height = random.Next(min, max);

                // instruct the layouts to use fixed, uses specified desired width and desired height
                shape.LayoutData.UseShapeWidth = false;
                shape.LayoutData.DesiredWidth  = width;

                shape.LayoutData.UseShapeHeight = false;
                shape.LayoutData.DesiredHeight  = height;

                shape.Bounds = new NRectangleF(0, 0, width, height);
                document.ActiveLayer.AddChild(shape);
            }
        }
コード例 #18
0
        private void CreateMechanicalEngineeringDocument()
        {
            // create the key shape
            NCompositeShape key = new NCompositeShape();

            NRectanglePath keyRect = new NRectanglePath(new NRectangleF(12.5f, 30, 5f, 50));

            key.Primitives.AddChild(keyRect);

            NEllipsePath keyCircle = new NEllipsePath(new NRectangleF(0, 0, 30, 30));

            key.Primitives.AddChild(keyCircle);

            NEllipsePath keyHole = new NEllipsePath(new NRectangleF(13f, 2f, 4f, 4f));

            NStyle.SetFillStyle(keyHole, new NColorFillStyle(Color.White));
            NStyle.SetStrokeStyle(keyHole, new NStrokeStyle(0, Color.Black));
            key.Primitives.AddChild(keyHole);

            key.UpdateModelBounds();
            key.Style.FillStyle   = new NColorFillStyle(Color.DarkGray);
            key.Style.StrokeStyle = new NStrokeStyle(0, Color.Black);

            document.ActiveLayer.AddChild(key);

            // create the octagram
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape octagram             = factory.CreateShape((int)BasicShapes.Octagram);

            octagram.Bounds            = new NRectangleF(40, 0, 40, 40);
            octagram.Style.FillStyle   = new NColorFillStyle(Color.DarkGray);
            octagram.Style.StrokeStyle = new NStrokeStyle(0, Color.Black);

            document.ActiveLayer.AddChild(octagram);

            // update the drawing bounds to size to content with some margins
            document.AutoBoundsMinSize = new NSizeF(1, 1);
            document.AutoBoundsPadding = new Nevron.Diagram.NMargins(5f);
            document.AutoBoundsMode    = AutoBoundsMode.AutoSizeToContent;
        }
コード例 #19
0
        private void InitDocument()
        {
            document.Style.TextStyle = new NTextStyle(new Font("Arial", 9), Color.Black);

            NGraphTemplate template;

            // create rectangular grid template
            template               = new NRectangularGridTemplate();
            template.Origin        = new NPointF(10, 23);
            template.VerticesShape = BasicShapes.Rectangle;
            template.Create(document);

            // create tree template
            template               = new NGenericTreeTemplate();
            template.Origin        = new NPointF(250, 23);
            template.VerticesShape = BasicShapes.Triangle;
            template.Create(document);

            // create elliptical grid template
            template               = new NEllipticalGridTemplate();
            template.Origin        = new NPointF(10, 250);
            template.VerticesShape = BasicShapes.Ellipse;
            template.Create(document);

            // create a shape with a 1D shape which reflexes it
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)BasicShapes.Rectangle);

            shape.Bounds = new NRectangleF(350, 350, 100, 100);
            document.ActiveLayer.AddChild(shape);

            NBezierCurveShape bezier = new NBezierCurveShape();

            bezier.StyleSheetName = NDR.NameConnectorsStyleSheet;
            document.ActiveLayer.AddChild(bezier);

            bezier.FromShape = shape;
            bezier.ToShape   = shape;
            bezier.Reflex();
        }
コード例 #20
0
        private void CreateShapeWithAutoPrevPort()
        {
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)BasicShapes.Triangle);

            shape.Name              = "Point Port with AutoPrev direction";
            shape.Bounds            = base.GetGridCell(4, 1);
            shape.Style.FillStyle   = new NGradientFillStyle(GradientStyle.DiagonalUp, GradientVariant.Variant4, Color.FromArgb(192, 194, 194), Color.FromArgb(129, 133, 133));
            shape.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));

            NPointPort port = new NPointPort(shape.UniqueId, PointIndexMode.Second, -1);

            port.DirectionMode = PointPortDirectionMode.AutoPrev;
            shape.Ports.RemoveAllChildren();
            shape.Ports.AddChild(port);

            document.ActiveLayer.AddChild(shape);

            // describe it
            NTextShape text = new NTextShape("Point Port with AutoPrev direction", base.GetGridCell(4, 2, 0, 1));

            document.ActiveLayer.AddChild(text);
        }
コード例 #21
0
        private void CreateShapeWithPointPort()
        {
            // create a shape with one point port
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)BasicShapes.Pentagram);

            shape.Name   = "Shape with a Point Port";
            shape.Bounds = base.GetGridCell(4, 1);

            NPointPort port = new NPointPort(shape.UniqueId, PointIndexMode.Second, -1);

            shape.Ports.RemoveAllChildren();
            shape.Ports.AddChild(port);
            shape.Ports.DefaultInwardPortUniqueId = port.UniqueId;

            // connect it with the center shape
            document.ActiveLayer.AddChild(shape);
            ConnectShapes(centerShape, shape);

            // describe it
            NTextShape text = new NTextShape("Shape with Point Port", base.GetGridCell(4, 2, 0, 1));

            document.ActiveLayer.AddChild(text);
        }
コード例 #22
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // init configuration
            InitializeConfigurationFields();

            NDrawingView1.HttpHandlerCallback = new CustomHttpHandlerCallback();

            if (NDrawingView1.RequiresInitialization)
            {
                factory = new NBasicShapesFactory(NDrawingView1.Document);

                // begin view init
                NDrawingView1.ViewLayout     = CanvasLayout.Normal;
                NDrawingView1.ScaleX         = 1;
                NDrawingView1.ScaleY         = 1;
                NDrawingView1.ViewportOrigin = new NPointF();

                // init document
                NDrawingView1.Document.HistoryService.Stop();
                NDrawingView1.Document.BeginInit();
                InitDocument();
                NDrawingView1.Document.EndInit();
            }
        }
コード例 #23
0
        private void InitDocument()
        {
            // modify the connectors style sheet
            NStyleSheet styleSheet = (NDrawingView1.Document.StyleSheets.GetChildByName(NDR.NameConnectorsStyleSheet, -1) as NStyleSheet);

            NTextStyle textStyle = new NTextStyle();

            textStyle.BackplaneStyle.Visible = true;
            textStyle.BackplaneStyle.StandardFrameStyle.InnerBorderWidth = new NLength(0);
            textStyle.BackplaneStyle.FillStyle = new NColorFillStyle(Color.FromArgb(200, Color.White));
            styleSheet.Style.TextStyle         = textStyle;

            styleSheet.Style.StrokeStyle = new NStrokeStyle(1, Color.Black);
            styleSheet.Style.StartArrowheadStyle.StrokeStyle = new NStrokeStyle(Color.FromArgb(0, Color.Black));
            styleSheet.Style.StartArrowheadStyle.FillStyle   = new NColorFillStyle(Color.FromArgb(0, Color.White));
            styleSheet.Style.EndArrowheadStyle.StrokeStyle   = new NStrokeStyle(1, Color.Black);

            // modify default stroke style
            NDrawingView1.Document.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(0, Color.White));

            // configure the document
            NDrawingView1.Document.Bounds = new NRectangleF(0, 0, 420, 320);
            NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            NDrawingView1.Document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            NDrawingView1.Document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            NDrawingView1.Document.MeasurementUnit  = NGraphicsUnit.Pixel;
            NDrawingView1.Document.DrawingScaleMode = DrawingScaleMode.NoScale;

            NDrawingView1.Document.BackgroundStyle.FrameStyle.Visible = false;

            //	predefined styles
            NAdvancedGradientFillStyle ag1 = new NAdvancedGradientFillStyle();

            ag1.BackgroundColor = Color.Navy;
            ag1.Points.Add(new NAdvancedGradientPoint(Color.SkyBlue, 50, 50, 0, 79, AGPointShape.Circle));

            NAdvancedGradientFillStyle ag2 = new NAdvancedGradientFillStyle();

            ag2.BackgroundColor = Color.DarkRed;
            ag2.Points.Add(new NAdvancedGradientPoint(Color.Red, 50, 50, 0, 71, AGPointShape.Circle));

            NAdvancedGradientFillStyle ag3 = new NAdvancedGradientFillStyle();

            ag3.BackgroundColor = Color.Orange;
            ag3.Points.Add(new NAdvancedGradientPoint(Color.Yellow, 50, 50, 0, 50, AGPointShape.Circle));

            //	shapes
            NBasicShapesFactory factory = new NBasicShapesFactory(NDrawingView1.Document);

            NEllipseShape centerEllipse = factory.CreateShape((int)BasicShapes.Ellipse) as NEllipseShape;

            centerEllipse.Name                     = "CenterEllipse";
            centerEllipse.Width                    = 50f;
            centerEllipse.Height                   = 50f;
            centerEllipse.Center                   = new NPointF(210, 160);
            centerEllipse.Style.StrokeStyle        = null;
            centerEllipse.Style.FillStyle          = ag3;
            centerEllipse.Style.InteractivityStyle = new NInteractivityStyle(true, centerEllipse.Name);

            NEllipseShape rotatingEllipse = factory.CreateShape((int)BasicShapes.Ellipse) as NEllipseShape;

            rotatingEllipse.Name                     = "RotatingEllipse";
            rotatingEllipse.Width                    = 35f;
            rotatingEllipse.Height                   = 35f;
            rotatingEllipse.Center                   = new NPointF(centerEllipse.Bounds.X - 100, centerEllipse.Center.Y);
            rotatingEllipse.Style.StrokeStyle        = null;
            rotatingEllipse.Style.FillStyle          = ag1;
            rotatingEllipse.PinPoint                 = new NPointF(centerEllipse.Center.X, centerEllipse.Center.Y);
            rotatingEllipse.Style.InteractivityStyle = new NInteractivityStyle(true, rotatingEllipse.Name);

            NEllipseShape rotatingEllipse2 = factory.CreateShape((int)BasicShapes.Ellipse) as NEllipseShape;

            rotatingEllipse2.Name                     = "RotatingEllipse2";
            rotatingEllipse2.Width                    = 15f;
            rotatingEllipse2.Height                   = 15f;
            rotatingEllipse2.Center                   = new NPointF(centerEllipse.Bounds.Right + 30, centerEllipse.Center.Y);
            rotatingEllipse2.Style.StrokeStyle        = null;
            rotatingEllipse2.Style.FillStyle          = ag2;
            rotatingEllipse2.PinPoint                 = new NPointF(centerEllipse.Center.X, centerEllipse.Center.Y);
            rotatingEllipse2.Style.InteractivityStyle = new NInteractivityStyle(true, rotatingEllipse2.Name);

            NEllipseShape orbit1 = factory.CreateShape((int)BasicShapes.Ellipse) as NEllipseShape;

            orbit1.Name                      = "orbit1";
            orbit1.Width                     = 2 * (centerEllipse.Center.X - rotatingEllipse.Center.X);
            orbit1.Height                    = orbit1.Width;
            orbit1.Center                    = new NPointF(centerEllipse.Center.X, centerEllipse.Center.Y);
            orbit1.Style.StrokeStyle         = new NStrokeStyle(Color.Black);
            orbit1.Style.StrokeStyle.Pattern = LinePattern.Dot;
            orbit1.Style.StrokeStyle.Factor  = 2;
            orbit1.Style.FillStyle           = new NColorFillStyle(Color.FromArgb(0, Color.White));

            NEllipseShape orbit2 = factory.CreateShape((int)BasicShapes.Ellipse) as NEllipseShape;

            orbit2.Name                      = "orbit2";
            orbit2.Width                     = 2 * (centerEllipse.Center.X - rotatingEllipse2.Center.X);
            orbit2.Height                    = orbit2.Width;
            orbit2.Center                    = new NPointF(centerEllipse.Center.X, centerEllipse.Center.Y);
            orbit2.Style.StrokeStyle         = new NStrokeStyle(Color.Black);
            orbit2.Style.StrokeStyle.Pattern = LinePattern.Dot;
            orbit2.Style.StrokeStyle.Factor  = 2;
            orbit2.Style.FillStyle           = new NColorFillStyle(Color.FromArgb(0, Color.White));

            NDrawingView1.Document.ActiveLayer.AddChild(orbit1);
            NDrawingView1.Document.ActiveLayer.AddChild(orbit2);
            NDrawingView1.Document.ActiveLayer.AddChild(centerEllipse);
            NDrawingView1.Document.ActiveLayer.AddChild(rotatingEllipse);
            NDrawingView1.Document.ActiveLayer.AddChild(rotatingEllipse2);

            // some shapes need to have extra ports
            NRotatedBoundsPort port = new NRotatedBoundsPort(centerEllipse.UniqueId, ContentAlignment.MiddleCenter);

            port.Name = "MiddleCenter";
            centerEllipse.Ports.AddChild(port);

            port      = new NRotatedBoundsPort(rotatingEllipse.UniqueId, ContentAlignment.MiddleCenter);
            port.Name = "MiddleCenter";
            rotatingEllipse.Ports.AddChild(port);

            // connect shapes in levels
            NShape connector           = base.CreateConnector(NDrawingView1.Document, centerEllipse, "MiddleCenter", rotatingEllipse, "MiddleCenter", ConnectorType.Line, "Radius");
            NInteractivityStyle istyle = connector.ComposeInteractivityStyle();
        }
コード例 #24
0
        protected void InitDocument()
        {
            NDrawingDocument document = NDrawingView1.Document;

            // set drawing preferences
            document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            document.Style.FillStyle = new NColorFillStyle(Color.Linen);
            document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8));
            document.BackgroundStyle.FrameStyle.Visible = false;

            // determine the shapes size and layout options
            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            int maxOrdinal = 0;

            switch (shapeSizeDropDownList.SelectedValue)
            {
            case "Small":
                factory.DefaultSize = new NSizeF(40, 30);
                maxOrdinal          = 7;
                break;

            case "Medium":
                factory.DefaultSize = new NSizeF(80, 60);
                maxOrdinal          = 4;
                break;

            case "Large":
                factory.DefaultSize = new NSizeF(200, 150);
                maxOrdinal          = 1;
                break;

            default:
                throw new NotImplementedException(shapeSizeDropDownList.SelectedValue);
            }

            // create the basic shapes in the active layer
            int    count = factory.ShapesCount;
            NShape shape = null;

            for (int i = 0; i < count; i++)
            {
                // create a basic shape
                shape      = factory.CreateShape(i);
                shape.Text = shape.Name;

                // add it to the active layer
                document.ActiveLayer.AddChild(shape);
            }

            // Add some content to the table shape
            NTableShape table = (NTableShape)shape;

            table.InitTable(2, 2);
            table.BeginUpdate();
            table.CellMargins          = new Nevron.Diagram.NMargins(8);
            table[0, 0].Text           = "Cell 1";
            table[1, 0].Text           = "Cell 2";
            table[0, 1].Text           = "Cell 3";
            table[1, 1].Text           = "Cell 4";
            table.PortDistributionMode = TablePortDistributionMode.CellBased;
            table.EndUpdate();

            // layout the shapes in the active layer using a table layout
            NTableLayout layout = new NTableLayout();

            layout.Direction                  = LayoutDirection.LeftToRight;
            layout.ConstrainMode              = CellConstrainMode.Ordinal;
            layout.MaxOrdinal                 = maxOrdinal;
            layout.VerticalSpacing            = 20;
            layout.HorizontalSpacing          = 20;
            layout.HorizontalContentPlacement = ContentPlacement.Center;
            layout.VerticalContentPlacement   = ContentPlacement.Center;

            NLayoutContext layoutContext = new NLayoutContext();

            layoutContext.GraphAdapter         = new NShapeGraphAdapter();
            layoutContext.BodyAdapter          = new NShapeBodyAdapter(document);
            layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document);

            layout.Layout(document.ActiveLayer.Children(null), layoutContext);

            // resize document to fit all shapes
            document.SizeToContent();
        }
コード例 #25
0
        private void InitDocument()
        {
            NDrawingDocument document = NDrawingView1.Document;

            document.BackgroundStyle.FrameStyle.Visible = false;

            // create two stylesheets - one for the vertices and one for the edges
            NStyleSheet vertexStyleSheet = new NStyleSheet();

            vertexStyleSheet.Name            = "Vertices";
            vertexStyleSheet.Style.FillStyle = new NColorFillStyle(Color.FromArgb(236, 97, 49));
            document.StyleSheets.AddChild(vertexStyleSheet);

            NStyleSheet edgeStyleSheet = new NStyleSheet();

            edgeStyleSheet.Name = "Edges";
            edgeStyleSheet.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(68, 90, 108));
            document.StyleSheets.AddChild(edgeStyleSheet);

            // create the tree data source importer
            NTreeDataSourceImporter treeImporter = new NTreeDataSourceImporter();

            // set the document in the active layer of which the shapes will be imported
            treeImporter.Document = document;

            // SET THE DATA SOURCE
            // the tree data source importer supports the following data sources
            //      DataTable
            //      DataView
            //      OleDbDataAdapter
            //      SqlDataAdapter
            //      OdbcDataAdapter
            //      OleDbCommand
            //      SqlCommand
            //      OdbcCommand
            // in this example we have created an OleDbDataAdapter,
            // which selects all columns and records from the Pages table of the SiteMap.mdb
            string  databasePath = HttpContext.Current.Server.MapPath(@"..\App_Data\SiteMap.xml");
            DataSet dataSet      = new DataSet();

            dataSet.ReadXml(databasePath, XmlReadMode.ReadSchema);

            treeImporter.DataSource = dataSet.Tables["Pages"];

            // records are uniquely identified by their Id column
            // records link to their parent record by their ParentId column
            treeImporter.IdColumnName       = "Id";
            treeImporter.ParentIdColumnName = "ParentId";

            // create vertices as rectangles shapes, with default size (60,30)
            NBasicShapesFactory shapesFactory = new NBasicShapesFactory();

            shapesFactory.DefaultSize        = new NSizeF(60, 30);
            treeImporter.VertexShapesFactory = shapesFactory;
            treeImporter.VertexShapesName    = BasicShapes.Rectangle.ToString();

            // set stylesheets to be applied to imported vertices and edges
            treeImporter.VertexStyleSheetName = "Vertices";
            treeImporter.EdgeStyleSheetName   = "Edges";

            // use layered tree layout
            NLayeredTreeLayout layout = new NLayeredTreeLayout();

            layout.Direction             = LayoutDirection.LeftToRight;
            layout.OrthogonalEdgeRouting = true;
            layout.LayerAlignment        = RelativeAlignment.Near;
            treeImporter.Layout          = layout;

            // subscribe for the vertex imported event,
            // which is raised when a shape was created for a data source record
            treeImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported);

            // import
            treeImporter.Import();
        }
コード例 #26
0
        /// <summary>
        /// Creates a triangular grid diagram with the specified count of levels
        /// </summary>
        /// <param name="levels"></param>
        private void CreateTriangularGridDiagram(int levels)
        {
            // clean up the active layer
            document.ActiveLayer.RemoveAllChildren();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(30, 30);

            NShape        cur = null, prev = null;
            NShape        edge          = null;
            List <NShape> curRowShapes  = null;
            List <NShape> prevRowShapes = null;

            for (int level = 1; level < levels; level++)
            {
                curRowShapes = new List <NShape>();

                for (int i = 0; i < level; i++)
                {
                    cur = basicShapesFactory.CreateShape(BasicShapes.Circle);
                    ((NDynamicPort)cur.Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                    cur.Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(192, 194, 194), Color.FromArgb(129, 133, 133));
                    cur.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
                    document.ActiveLayer.AddChild(cur);

                    // connect with prev
                    if (i > 0)
                    {
                        edge = new NLineShape();
                        document.ActiveLayer.AddChild(edge);

                        edge.FromShape = prev;
                        edge.ToShape   = cur;
                    }

                    // connect with ancestors
                    if (level > 1)
                    {
                        if (i < prevRowShapes.Count)
                        {
                            edge = new NLineShape();
                            document.ActiveLayer.AddChild(edge);

                            edge.FromShape = prevRowShapes[i];
                            edge.ToShape   = cur;
                        }

                        if (i > 0)
                        {
                            edge = new NLineShape();
                            document.ActiveLayer.AddChild(edge);

                            edge.FromShape = prevRowShapes[i - 1];
                            edge.ToShape   = cur;
                        }
                    }

                    // fix the three corner vertices
                    if (level == 1 || (level == levels - 1 && (i == 0 || i == level - 1)))
                    {
                        cur.LayoutData.ForceXMoveable = false;
                        cur.LayoutData.ForceYMoveable = false;
                        cur.Style.FillStyle           = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(251, 203, 156), Color.FromArgb(247, 150, 56));
                        cur.Style.StrokeStyle         = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
                    }

                    curRowShapes.Add(cur);
                    prev = cur;
                }

                prevRowShapes = curRowShapes;
            }

            NBatchReorder batchReorder = new NBatchReorder(document);

            batchReorder.Build(document.ActiveLayer.Children(NFilters.Shape1D));
            batchReorder.SendToBack(false);
        }
コード例 #27
0
        /// <summary>
        /// Creates a random barycenter diagram with the specified settings
        /// </summary>
        /// <param name="fixedCount">number of fixed vertices (must be larger than 3)</param>
        /// <param name="freeCount">number of free vertices</param>
        private void CreateRandomDiagram(int fixedCount, int freeCount)
        {
            if (fixedCount < 3)
            {
                throw new ArgumentException("Needs at least three fixed vertices");
            }

            // clean up the layers
            document.ActiveLayer.RemoveAllChildren();

            // we will be using basic circle shapes with default size of (30, 30)
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(30, 30);

            // create the fixed vertices
            NShape[] fixedShapes = new NShape[fixedCount];

            for (int i = 0; i < fixedCount; i++)
            {
                fixedShapes[i] = basicShapesFactory.CreateShape(BasicShapes.Circle);
                ((NDynamicPort)fixedShapes[i].Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                fixedShapes[i].Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(251, 203, 156), Color.FromArgb(247, 150, 56));
                fixedShapes[i].Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));

                // setting the ForceXMoveable and ForceYMoveable properties to false
                // specifies that the layout cannot move the shape in both X and Y directions
                fixedShapes[i].LayoutData.ForceXMoveable = false;
                fixedShapes[i].LayoutData.ForceYMoveable = false;

                document.ActiveLayer.AddChild(fixedShapes[i]);
            }

            // create the free vertices
            NShape[] freeShapes = new NShape[freeCount];
            for (int i = 0; i < freeCount; i++)
            {
                freeShapes[i] = basicShapesFactory.CreateShape(BasicShapes.Circle);
                ((NDynamicPort)freeShapes[i].Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation;
                freeShapes[i].Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(192, 194, 194), Color.FromArgb(129, 133, 133));
                freeShapes[i].Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
                document.ActiveLayer.AddChild(freeShapes[i]);
            }

            // link the fixed shapes in a circle
            for (int i = 0; i < fixedCount; i++)
            {
                NLineShape lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                if (i == 0)
                {
                    lineShape.FromShape = fixedShapes[fixedCount - 1];
                    lineShape.ToShape   = fixedShapes[0];
                }
                else
                {
                    lineShape.FromShape = fixedShapes[i - 1];
                    lineShape.ToShape   = fixedShapes[i];
                }
            }

            // link each free shape with two different random fixed shapes
            Random rnd = new Random();

            for (int i = 0; i < freeCount; i++)
            {
                int firstFixed  = rnd.Next(fixedCount);
                int secondFixed = (firstFixed + rnd.Next(fixedCount / 3) + 1) % fixedCount;

                // link with first fixed
                NLineShape lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                lineShape.FromShape = freeShapes[i];
                lineShape.ToShape   = fixedShapes[firstFixed];

                // link with second fixed
                lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                lineShape.FromShape = freeShapes[i];
                lineShape.ToShape   = fixedShapes[secondFixed];
            }

            // link each free shape with another free shape
            for (int i = 1; i < freeCount; i++)
            {
                NLineShape lineShape = new NLineShape();
                document.ActiveLayer.AddChild(lineShape);

                lineShape.FromShape = freeShapes[i - 1];
                lineShape.ToShape   = freeShapes[i];
            }

            NBatchReorder batchReorder = new NBatchReorder(document);

            batchReorder.Build(document.ActiveLayer.Children(NFilters.Shape1D));
            batchReorder.SendToBack(false);
        }
コード例 #28
0
        private void CreateDiagram()
        {
            int min = 100;
            int max = 200;

            NShape shape;
            Random random = new Random();
            NBasicShapesFactory basicShapeFactory = new NBasicShapesFactory(document);

            for (int i = 0; i < 5; i++)
            {
                shape = basicShapeFactory.CreateShape((int)BasicShapes.Rectangle);

                Color[] shapeLightColors = new Color[] { Color.FromArgb(236, 97, 49),
                                                         Color.FromArgb(247, 150, 56),
                                                         Color.FromArgb(68, 90, 108),
                                                         Color.FromArgb(129, 133, 133),
                                                         Color.FromArgb(255, 165, 109) };

                Color[] shapeDarkColors = new Color[] { Color.FromArgb(246, 176, 152),
                                                        Color.FromArgb(251, 203, 156),
                                                        Color.FromArgb(162, 173, 182),
                                                        Color.FromArgb(192, 194, 194),
                                                        Color.FromArgb(255, 210, 182) };

                shape.Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, shapeLightColors[i], shapeDarkColors[i]);
                shape.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));


                // generate random width and height
                float width  = random.Next(min, max);
                float height = random.Next(min, max);

                // instruct the layouts to use fixed, uses specified desired width and desired height
                shape.LayoutData.UseShapeWidth = false;
                shape.LayoutData.DesiredWidth  = width;

                shape.LayoutData.UseShapeHeight = false;
                shape.LayoutData.DesiredHeight  = height;

                switch (i)
                {
                case 0:
                    shape.LayoutData.DockArea = DockArea.Top;
                    shape.Text = "Top (" + i.ToString() + ")";
                    break;

                case 1:
                    shape.LayoutData.DockArea = DockArea.Bottom;
                    shape.Text = "Bottom (" + i.ToString() + ")";
                    break;

                case 2:
                    shape.LayoutData.DockArea = DockArea.Left;
                    shape.Text = "Left (" + i.ToString() + ")";
                    break;

                case 3:
                    shape.LayoutData.DockArea = DockArea.Right;
                    shape.Text = "Right (" + i.ToString() + ")";
                    break;

                case 4:
                    shape.LayoutData.DockArea = DockArea.Center;
                    shape.Text = "Center (" + i.ToString() + ")";
                    break;
                }

                //shape.Style.FillStyle = new NColorFillStyle(GetPredefinedColor(i));
                shape.Bounds = new NRectangleF(0, 0, width, height);
                document.ActiveLayer.AddChild(shape);
            }
        }
コード例 #29
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                CaptureMouseEventDropDownList.Items.Add("Mouse Down");
                CaptureMouseEventDropDownList.Items.Add("Mouse Up");
                CaptureMouseEventDropDownList.Items.Add("Click");
                CaptureMouseEventDropDownList.Items.Add("Double Click");
                CaptureMouseEventDropDownList.Items.Add("Mouse Enter");
                CaptureMouseEventDropDownList.Items.Add("Mouse Leave");
                CaptureMouseEventDropDownList.SelectedIndex = 0;
            }

            // begin view init
            base.DefaultGridOrigin   = new NPointF(30, 30);
            base.DefaultGridCellSize = new NSizeF(100, 50);
            base.DefaultGridSpacing  = new NSizeF(50, 40);

            NDrawingDocument document = NThinDiagramControl1.Document;

            if (!NThinDiagramControl1.Initialized)
            {
                NThinDiagramControl1.View.Layout = CanvasLayout.Fit;
                // add the client mouse event tool
                NThinDiagramControl1.Controller.Tools.Add(new NClientMouseEventTool());
            }

            // Create a few simple shapes with attached client mouse event interactivity
            document.Reset();
            document.BeginInit();

            document.BackgroundStyle.FrameStyle.Visible = false;
            document.AutoBoundsPadding = new Nevron.Diagram.NMargins(10f, 10f, 10f, 10f);
            document.Style.FillStyle   = new NColorFillStyle(Color.White);

            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            NShape outerCircle = factory.CreateShape(BasicShapes.Circle);

            outerCircle.Bounds = new NRectangleF(0f, 0f, 200f, 200f);
            document.ActiveLayer.AddChild(outerCircle);

            NShape rect = factory.CreateShape(BasicShapes.Rectangle);

            rect.Bounds                   = new NRectangleF(42f, 42f, 50f, 50f);
            rect.Style.FillStyle          = new NColorFillStyle(Color.Orange);
            rect.Style.InteractivityStyle = CreateInteractivityStyle("Rectangle");
            document.ActiveLayer.AddChild(rect);

            NShape triangle = factory.CreateShape(BasicShapes.Triangle);

            triangle.Bounds                   = new NRectangleF(121f, 57f, 60f, 55f);
            triangle.Style.FillStyle          = new NColorFillStyle(Color.LightGray);
            triangle.Style.InteractivityStyle = CreateInteractivityStyle("Triangle");
            document.ActiveLayer.AddChild(triangle);

            NShape pentagon = factory.CreateShape(BasicShapes.Pentagon);

            pentagon.Bounds                   = new NRectangleF(60f, 120f, 54f, 50f);
            pentagon.Style.FillStyle          = new NColorFillStyle(Color.WhiteSmoke);
            pentagon.Style.InteractivityStyle = CreateInteractivityStyle("Pentagon");
            document.ActiveLayer.AddChild(pentagon);

            document.SizeToContent();
            document.EndInit();
        }
コード例 #30
0
        private void CreatePredefinedGraph()
        {
            // we will be using basic shapes for this example
            NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();

            basicShapesFactory.DefaultSize = new NSizeF(80, 80);

            List <NPerson> persons = new List <NPerson>();

            // create persons
            NPerson personEmil     = new NPerson("Emil Moore", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personAndre    = new NPerson("Andre Smith", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personRobert   = new NPerson("Robert Johnson", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personBob      = new NPerson("Bob Williams", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personPeter    = new NPerson("Peter Brown", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personSilvia   = new NPerson("Silvia Moore", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personEmily    = new NPerson("Emily Smith", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personMonica   = new NPerson("Monica Johnson", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personSamantha = new NPerson("Samantha Miller", basicShapesFactory.CreateShape(BasicShapes.Circle));
            NPerson personIsabella = new NPerson("Isabella Davis", basicShapesFactory.CreateShape(BasicShapes.Circle));

            persons.Add(personEmil);
            persons.Add(personAndre);
            persons.Add(personRobert);
            persons.Add(personBob);
            persons.Add(personPeter);
            persons.Add(personSilvia);
            persons.Add(personEmily);
            persons.Add(personMonica);
            persons.Add(personSamantha);
            persons.Add(personIsabella);

            // create family relashionships
            personEmil.m_Family   = personSilvia;
            personAndre.m_Family  = personEmily;
            personRobert.m_Family = personMonica;

            // create friend relationships
            personEmily.m_Friends.Add(personBob);
            personEmily.m_Friends.Add(personMonica);

            personAndre.m_Friends.Add(personPeter);
            personAndre.m_Friends.Add(personIsabella);

            personSilvia.m_Friends.Add(personBob);
            personSilvia.m_Friends.Add(personSamantha);
            personSilvia.m_Friends.Add(personIsabella);

            personEmily.m_Friends.Add(personIsabella);
            personEmily.m_Friends.Add(personPeter);

            personPeter.m_Friends.Add(personRobert);

            // create the person vertices
            for (int i = 0; i < persons.Count; i++)
            {
                NDrawingView1.Document.ActiveLayer.AddChild(persons[i].m_Shape);
            }

            // creeate the family relations
            for (int i = 0; i < persons.Count; i++)
            {
                NPerson currentPerson = persons[i];

                if (currentPerson.m_Family != null)
                {
                    NLineShape connector = new NLineShape();
                    NDrawingView1.Document.ActiveLayer.AddChild(connector);

                    connector.FromShape = currentPerson.m_Shape;
                    connector.ToShape   = currentPerson.m_Family.m_Shape;

                    connector.LayoutData.SpringStiffness = 2;
                    connector.LayoutData.SpringLength    = 100;
                    connector.Style.StrokeStyle          = new NStrokeStyle(2, Color.Coral);
                }
            }

            for (int i = 0; i < persons.Count; i++)
            {
                NPerson currentPerson = persons[i];
                for (int j = 0; j < currentPerson.m_Friends.Count; j++)
                {
                    NLineShape connector = new NLineShape();
                    NDrawingView1.Document.ActiveLayer.AddChild(connector);

                    connector.FromShape = currentPerson.m_Shape;
                    connector.ToShape   = currentPerson.m_Friends[j].m_Shape;

                    connector.LayoutData.SpringStiffness = 1;
                    connector.LayoutData.SpringLength    = 200;
                    connector.Style.StrokeStyle          = new NStrokeStyle(2, Color.Green);
                }
            }
        }