コード例 #1
0
        void CreateLabeledPolyOutline(NPointF[] points, NPolygonShape polyShape, NNodeList labels, string title)
        {
            NNodeList nodes = new NNodeList();

            nodes.Add(polyShape);
            if (labels != null)
            {
                nodes.AddRange(labels);
            }

            int length = points.Length - 1;
            int vIndex = 0, hIndex = 0, index = 0;

            for (int i = 0; i < length; i++)
            {
                nodes.Add(ConnectPointsLabeled(points[i], points[i + 1], ref hIndex, ref vIndex, ref index));
            }
            nodes.Add(ConnectPointsLabeled(points[points.Length - 1], points[0], ref hIndex, ref vIndex, ref index));

            NGroup      g;
            NBatchGroup batchGroup = new NBatchGroup(document);

            batchGroup.Build(nodes);
            batchGroup.Group(document.ActiveLayer, true, out g);
            g.Name = title + " Group";
        }
コード例 #2
0
        private void groupButton_Click(object sender, System.EventArgs e)
        {
            // get the selected nodes
            NNodeList selectedNodes = view.Selection.Nodes;

            // determine whether they can be grouped
            NBatchGroup batchGroup = new NBatchGroup(document, selectedNodes);

            if (batchGroup.CanGroup(document.ActiveLayer, false) == false)
            {
                return;
            }

            // group them
            NGroup             group;
            NTransactionResult res = batchGroup.Group(document.ActiveLayer, false, out group);

            // single select the new group if the group was successful
            if (res.Succeeded)
            {
                view.Selection.SingleSelect(group);
            }

            // ask the view to display any information about the transaction status (if it was not completed)
            view.ProcessTransactionResult(res);
        }
コード例 #3
0
        private void InitDocument()
        {
            // configure the document
            NDrawingView1.Document.Bounds        = new NRectangleF(0, 0, imagePixelWidth, imagePixelHeight);
            NDrawingView1.Document.ShadowsZOrder = ShadowsZOrder.BehindElement;
            NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            NDrawingView1.Document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            NDrawingView1.Document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.None;
            NDrawingView1.Document.MeasurementUnit  = NGraphicsUnit.Pixel;
            NDrawingView1.Document.DrawingScaleMode = DrawingScaleMode.NoScale;

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

            //	shapes
            NRectangleShape backgroundFrame = factory.CreateShape((int)BasicShapes.Rectangle) as NRectangleShape;

            backgroundFrame.Bounds            = new NRectangleF(boardMarginLeft, boardMarginTop, boardPixelWidth, boardPixelHeight);
            backgroundFrame.Style.StrokeStyle = new NStrokeStyle(new NLength(1f, NGraphicsUnit.Pixel), Color.Black);
            backgroundFrame.Style.FillStyle   = new NColorFillStyle(Color.White);
            backgroundFrame.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(65, Color.Black), new NPointL(shadowOffset, shadowOffset), 1, new NLength(shadowOffset * 2));
            backgroundFrame.Name = "background";

            NDrawingView1.Document.ActiveLayer.AddChild(backgroundFrame);

            NNodeList cells = new NNodeList();

            for (int x = 0; x < boardCellCountWidth; x++)
            {
                for (int y = 0; y < boardCellCountHeight; y++)
                {
                    cells.Add(CreateEmptyCell(x, y));
                }
            }

            NGroup      cellsGroup;
            NBatchGroup batchGroup = new NBatchGroup(NDrawingView1.Document);

            batchGroup.Build(cells);
            NTransactionResult result = batchGroup.Group(NDrawingView1.Document.ActiveLayer, true, out cellsGroup);

            cellsGroup.Name = "cellsGroup";
        }
コード例 #4
0
        private void UpdateControlsState()
        {
            PauseEventsHandling();

            // get the selected nodes
            NNodeList selectedNodes = view.Selection.Nodes;

            if (selectedNodes.Count == 0)
            {
                // if not nodes are selected - disable form controls
                selectedGroupsActionsGroup.Enabled = false;
                selectedShapesActionsGroup.Enabled = false;
            }
            else if (selectedNodes.Count == 1)
            {
                // if the selected node is a group
                NGroup group = (view.Selection.AnchorNode as NGroup);
                if (group != null)
                {
                    selectedGroupsActionsGroup.Enabled = true;

                    // check whether the group can be ungrouped to layer
                    NBatchUngroup batchUngroup = new NBatchUngroup(document, selectedNodes);
                    ungroupToLayerButton.Enabled = batchUngroup.CanUngroup(document.ActiveLayer, false);

                    // check whether the group can be ungrouped to a parent group
                    NGroup parentGroup = group.Group;
                    if (parentGroup != null)
                    {
                        ungroupToParentGroupButton.Enabled = batchUngroup.CanUngroup(parentGroup, false);
                    }
                    else
                    {
                        ungroupToParentGroupButton.Enabled = false;
                    }

                    // update the protect from ungroup check button
                    protectFromUngroupCheckBox.Enabled = true;
                    protectFromUngroupCheckBox.Checked = group.Protection.Ungroup;
                }
                else
                {
                    selectedGroupsActionsGroup.Enabled = false;
                }

                // if the selected node is a shape
                NShape shape = (view.Selection.AnchorNode as NShape);
                if (shape != null)
                {
                    selectedShapesActionsGroup.Enabled = true;

                    // check whether the selected shape can be grouped
                    NBatchGroup batchGroup = new NBatchGroup(document, selectedNodes);
                    groupButton.Enabled = batchGroup.CanGroup(document.ActiveLayer, false);

                    // update the protect from group check button
                    protectFromGroupCheckBox.Enabled = true;
                    protectFromGroupCheckBox.Checked = shape.Protection.Group;
                }
                else
                {
                    selectedShapesActionsGroup.Enabled = false;
                }
            }
            else
            {
                // multiple nodes are selected
                selectedGroupsActionsGroup.Enabled = true;
                selectedShapesActionsGroup.Enabled = true;

                // update ungroup buttons
                NBatchUngroup batchUngroup = new NBatchUngroup(document, selectedNodes);
                ungroupToLayerButton.Enabled       = batchUngroup.CanUngroup(document.ActiveLayer, false);
                ungroupToParentGroupButton.Enabled = false;

                // update group button
                NBatchGroup batchGroup = new NBatchGroup(document, selectedNodes);
                groupButton.Enabled = batchGroup.CanGroup(document.ActiveLayer, false);

                // disable protection checks
                protectFromUngroupCheckBox.Enabled = true;
                protectFromGroupCheckBox.Enabled   = false;
            }

            base.ResumeEventsHandling();
        }
コード例 #5
0
        void InitToolbar()
        {
            if (nDrawingViewToolbar.RequiresInitialization)
            {
                ActiveCommand = toolbarButtons[0].CommandName;

                // begin view init
                nDrawingViewToolbar.ViewLayout      = CanvasLayout.Normal;
                nDrawingViewToolbar.DocumentPadding = new Nevron.Diagram.NMargins(0);

                // init document
                nDrawingViewToolbar.Document.BeginInit();

                nDrawingViewToolbar.Document.AutoBoundsPadding = new Nevron.Diagram.NMargins(4);

                nDrawingViewToolbar.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                nDrawingViewToolbar.Document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                nDrawingViewToolbar.Document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                // set up visual formatting
                nDrawingViewToolbar.Document.Style.FillStyle = new NColorFillStyle(Color.White);
                nDrawingViewToolbar.Document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8));

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

                //	set up the shape factories
                NBasicShapesFactory buttonFactory = new NBasicShapesFactory(nDrawingViewToolbar.Document);
                buttonFactory.DefaultSize = new NSizeF(24, 24);

                NBrainstormingShapesFactory iconFactory = new NBrainstormingShapesFactory(nDrawingViewToolbar.Document);
                iconFactory.DefaultSize = new NSizeF(16, 16);

                //	create a batch layout, which will align shapes
                NBatchLayout batchLayout = new NBatchLayout(nDrawingViewToolbar.Document);

                //	create buttons
                int count = toolbarButtons.Length;
                for (int i = 0; i < count; i++)
                {
                    ToolbarButton btn         = toolbarButtons[i];
                    bool          isActive    = (this.ActiveCommand == btn.CommandName);
                    NShape        buttonShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle);

                    //	create the button shape group
                    NGroup      g      = new NGroup();
                    NBatchGroup bgroup = new NBatchGroup(nDrawingViewToolbar.Document);
                    NNodeList   shapes = new NNodeList();
                    if (btn.IsSeparator)
                    {
                        buttonShape.Width            /= 2;
                        buttonShape.Style.StrokeStyle = new NStrokeStyle(Color.White);
                        shapes.Add(buttonShape);
                    }
                    else if (!btn.IsColorSelector)
                    {
                        shapes.Add(buttonShape);
                    }
                    else
                    {
                        buttonShape.Style.FillStyle = new NColorFillStyle(btn.Color);
                        shapes.Add(buttonShape);
                    }

                    NRectanglePath  imagePath = new NRectanglePath(0f, 0f, btn.IconSize.Width, btn.IconSize.Height);
                    NImageFillStyle fs1       = new NImageFillStyle(this.MapPathSecure(@"..\..\..\Images\FlowChartBuilder\" + btn.IconFile));
                    NStyle.SetFillStyle(imagePath, fs1);
                    NStyle.SetStrokeStyle(imagePath, new NStrokeStyle(0, Color.White));
                    NCompositeShape imageShape = new NCompositeShape();
                    imageShape.Primitives.AddChild(imagePath);
                    imageShape.UpdateModelBounds();
                    shapes.Add(imageShape);

                    NShape coverShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle);
                    coverShape.Width = buttonShape.Width;
                    coverShape.Name  = "coverShape";
                    shapes.Add(coverShape);

                    if (!isActive && !btn.IsClientSide && !btn.IsSeparator)
                    {
                        if (btn.IsColorSelector)
                        {
                            coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(180, Color.White));
                        }
                        else
                        {
                            coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(160, Color.White));
                        }
                        coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(160, Color.White));
                    }
                    else
                    {
                        coverShape.Style.FillStyle   = new NColorFillStyle(Color.FromArgb(0, Color.White));
                        coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(0, Color.White));
                        if (!btn.IsSeparator)
                        {
                            coverShape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(70, Color.Black), new NPointL(1, 0));
                        }
                    }

                    // perform layout
                    batchLayout.Build(shapes);
                    batchLayout.AlignVertically(buttonShape, VertAlign.Center, false);
                    batchLayout.AlignHorizontally(buttonShape, HorzAlign.Center, false);

                    // group shapes
                    bgroup.Build(shapes);
                    bgroup.Group(null, false, out g);

                    // enable interactivity
                    if (!btn.IsSeparator)
                    {
                        g.Style.InteractivityStyle = new NInteractivityStyle(true, btn.CommandName, btn.Title, CursorType.Hand);
                    }

                    // set the command of the button
                    g.Tag = btn.CommandName;

                    nDrawingViewToolbar.Document.ActiveLayer.AddChild(g);
                }

                // 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        = toolbarButtons.Length;
                layout.HorizontalSpacing = 7;

                // create a layout context
                NLayoutContext layoutContext = new NLayoutContext();
                layoutContext.GraphAdapter         = new NShapeGraphAdapter();
                layoutContext.BodyAdapter          = new NShapeBodyAdapter(nDrawingViewToolbar.Document);
                layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(nDrawingViewToolbar.Document);

                // layout the shapes
                layout.Layout(nDrawingViewToolbar.Document.ActiveLayer.Children(null), layoutContext);

                nDrawingViewToolbar.Document.EndInit();
            }
        }
コード例 #6
0
        NDrawingDocument CreateDocument(int bookId)
        {
            NDrawingDocument document = new NDrawingDocument();

            //	setup the document
            document.AutoBoundsPadding         = new Nevron.Diagram.NMargins(0f, 7f, 7f, 7f);
            document.Style.FillStyle           = new NColorFillStyle(Color.White);
            document.Style.TextStyle.FillStyle = new NColorFillStyle(Color.DarkGray);
            document.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Left;
            document.Style.StrokeStyle = new NStrokeStyle(0, Color.White);
            NStandardFrameStyle frame = document.BackgroundStyle.FrameStyle as NStandardFrameStyle;

            frame.InnerBorderColor   = Color.Gray;
            document.MeasurementUnit = NGraphicsUnit.Pixel;

            //	set up the shape factories
            NBasicShapesFactory bookItemsFactory = new NBasicShapesFactory(document);

            bookItemsFactory.DefaultSize = new NSizeF(320, 200);

            NCustomToolsData.NBookEntry[] books = NCustomToolsData.CreateBooks();
            NCustomToolsData.NBookEntry   book  = null;
            int length = books.Length;

            for (int i = 0; i < length; i++)
            {
                if (books[i].Id == bookId)
                {
                    book = books[i];
                    break;
                }
            }
            if (bookId == -1 || book == null)
            {
                document.Style.StrokeStyle = new NStrokeStyle(1, Color.Red);
                document.ActiveLayer.AddChild(bookItemsFactory.CreateShape(BasicShapes.Pentagram));
                document.SizeToContent();
                return(document);
            }

            //	create a table layout, which will align te thumbnail and the text lines
            //	in two columns
            NTableLayout mainLayout = new NTableLayout();

            mainLayout.Direction                = LayoutDirection.LeftToRight;
            mainLayout.ConstrainMode            = CellConstrainMode.Ordinal;
            mainLayout.MaxOrdinal               = 2;
            mainLayout.VerticalContentPlacement = ContentPlacement.Near;

            //	create a stack layout, which will align the text lines in rows
            NStackLayout textLayout = new NStackLayout();

            textLayout.Direction = LayoutDirection.TopToBottom;
            textLayout.HorizontalContentPlacement = ContentPlacement.Near;
            textLayout.VerticalSpacing            = 13;

            //	create a stack layout, which will align the stars in 5 columns
            NStackLayout starsLayout = new NStackLayout();

            starsLayout.Direction = LayoutDirection.LeftToRight;
            starsLayout.VerticalContentPlacement = ContentPlacement.Center;
            starsLayout.HorizontalSpacing        = 1;

            NLayoutContext layoutContext = new NLayoutContext();

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

            //	create the shapes for the book image and text lines
            NShape bookImageShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle);

            bookImageShape.Width  = 240f;
            bookImageShape.Height = 240f;
            NImageFillStyle fs1 = new NImageFillStyle(HttpContext.Current.Server.MapPath(@"~\Images\CustomTools\" + book.ImageFile));

            fs1.TextureMappingStyle.MapLayout = MapLayout.Centered;
            NStyle.SetFillStyle(bookImageShape, fs1);

            NShape bookTitleShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle);

            bookTitleShape.Text   = book.Title;
            bookTitleShape.Width  = 160f;
            bookTitleShape.Height = 32f;

            NShape bookAuthorShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle);

            bookAuthorShape.Text   = "by " + book.Author;
            bookAuthorShape.Width  = 160f;
            bookAuthorShape.Height = 32f;

            NShape bookPriceShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle);

            bookPriceShape.Text   = "Price: $" + book.Price.ToString();
            bookPriceShape.Width  = 160f;
            bookPriceShape.Height = 32f;

            //	create the star shapes
            NNodeList starShapes = new NNodeList();

            for (int i = 0; i < 5; i++)
            {
                NShape star = bookItemsFactory.CreateShape(BasicShapes.Pentagram);
                star.Width  = 10f;
                star.Height = 10f;
                if (i < book.Rating)
                {
                    star.Style.FillStyle = new NColorFillStyle(Color.Orange);
                }
                else
                {
                    star.Style.FillStyle = new NColorFillStyle(Color.LightGray);
                }
                starShapes.Add(star);
            }

            //	prepare to layout
            NBatchGroup bgroup = new NBatchGroup(document);

            //	create the stars group
            NGroup starsGroup = new NGroup();

            // group the star shapes
            bgroup.Build(starShapes);
            bgroup.Group(null, false, out starsGroup);

            // collect the text shapes
            NNodeList textShapes = new NNodeList();

            textShapes.Add(bookTitleShape);
            textShapes.Add(bookAuthorShape);
            textShapes.Add(bookPriceShape);
            textShapes.Add(starsGroup);

            //	create the text group
            NGroup textGroup = new NGroup();

            // group the text shapes
            bgroup.Build(textShapes);
            bgroup.Group(null, false, out textGroup);

            // collect the main layout shapes
            NNodeList mainElements = new NNodeList();

            mainElements.Add(bookImageShape);
            mainElements.Add(textGroup);

            //	create the main group
            NGroup mainGroup = new NGroup();

            // group the main elements
            bgroup.Build(mainElements);
            bgroup.Group(null, false, out mainGroup);

            document.ActiveLayer.AddChild(mainGroup);

            // size all text shapes to text
            bookTitleShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f));
            bookAuthorShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f));
            bookPriceShape.SizeToText(new NMarginsF(6f, 0f, 6f, 0f));

            // layout the star shapes
            starsLayout.Layout(starShapes, layoutContext);
            starsGroup.UpdateModelBounds();

            // perform layout on the text
            textLayout.Layout(textShapes, layoutContext);
            textGroup.UpdateModelBounds();

            // layout all elements
            mainLayout.Layout(mainElements, layoutContext);
            mainGroup.UpdateModelBounds();

            // correct the text left padding
            bookTitleShape.Location  = new NPointF(bookTitleShape.Location.X - 6f, bookTitleShape.Location.Y);
            bookAuthorShape.Location = new NPointF(bookAuthorShape.Location.X - 6f, bookAuthorShape.Location.Y);
            bookPriceShape.Location  = new NPointF(bookPriceShape.Location.X - 6f, bookPriceShape.Location.Y);

            document.SizeToContent();
            return(document);
        }
コード例 #7
0
        protected static void InitDocument(NDrawingDocument document, string stateId, int boardCellCount)
        {
            // clean up existing layers
            document.Layers.RemoveAllChildren();

            // modify the connectors style sheet
            document.Style.TextStyle             = new NTextStyle();
            document.Style.TextStyle.FontStyle   = new NFontStyle("Arial", 20f, FontStyle.Bold);
            document.Style.TextStyle.FillStyle   = new NColorFillStyle(Color.SteelBlue);
            document.Style.TextStyle.BorderStyle = new NStrokeStyle(1f, Color.White);

            // configure the document
            document.Bounds        = new NRectangleF(0, 0, imagePixelWidth, imagePixelHeight);
            document.ShadowsZOrder = ShadowsZOrder.BehindLayer;
            document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.None;
            document.MeasurementUnit  = NGraphicsUnit.Pixel;
            document.DrawingScaleMode = DrawingScaleMode.NoScale;

            document.BackgroundStyle.FrameStyle.Visible = false;

            NLayer backgroundLayer = new NLayer();
            NLayer gridLayer       = new NLayer();

            document.Layers.AddChild(gridLayer);
            document.ActiveLayerUniqueId = gridLayer.UniqueId;

            //	frame
            NBasicShapesFactory factory = new NBasicShapesFactory(document);

            //	grid
            ArrayList randomizedNumbers = CreateRandomizedNumbersArray(boardCellCount);

            Hashtable grid  = new Hashtable();
            NNodeList cells = new NNodeList();

            for (int x = 0; x < boardCellCount; x++)
            {
                for (int y = 0; y < boardCellCount; y++)
                {
                    if (x == boardCellCount - 1 && y == boardCellCount - 1)
                    {
                        break;
                    }
                    NRectangleShape cell = CreateCell(document, x, y, (int)randomizedNumbers[y + x * boardCellCount]);
                    cells.Add(cell);
                    grid[new Point((int)cell.Bounds.X, (int)cell.Bounds.Y)] = new Point(x, y);
                }
            }

            NGroup      cellsGroup;
            NBatchGroup batchGroup = new NBatchGroup(document);

            batchGroup.Build(cells);
            NTransactionResult result = batchGroup.Group(document.ActiveLayer, true, out cellsGroup);

            cellsGroup.Name = "cellsGroup";

            //	save the default empty cell coordinates
            Point emptyCellCoords      = new Point(boardCellCount - 1, boardCellCount - 1);
            Point emptyCellPixelCoords = new Point(boardMarginLeft + cellPixelWidth * (boardCellCount - 1) + boardPadding, boardMarginTop + cellPixelWidth * (boardCellCount - 1) + boardPadding);

            HttpContext.Current.Session[stateId.ToString() + "-emptyCellCoords"]      = emptyCellCoords;
            HttpContext.Current.Session[stateId.ToString() + "-emptyCellPixelCoords"] = emptyCellPixelCoords;

            //	save the default cells grid
            grid[new Point(emptyCellPixelCoords.X, emptyCellPixelCoords.Y)] = new Point(emptyCellCoords.X, emptyCellCoords.Y);
            HttpContext.Current.Session[stateId.ToString() + "-grid"]       = grid;

            // clean up any other related session state
            HttpContext.Current.Session.Remove(stateId.ToString() + "-cellsList");
        }
コード例 #8
0
        void InitDocument()
        {
            // set up visual formatting
            NDrawingView1.Document.Style.FillStyle = new NColorFillStyle(Color.White);
            NDrawingView1.Document.BackgroundStyle.FrameStyle.Visible = false;

            NCustomToolsData.NBookEntry[] books = NCustomToolsData.CreateBooks();

            //	set up the shape factories
            NBasicShapesFactory bookItemsFactory = new NBasicShapesFactory(NDrawingView1.Document);

            bookItemsFactory.DefaultSize = new NSizeF(150, 100);

            //	create a table layout, which will align te thumbnail and the text within a group
            NTableLayout bookThumbLayout = new NTableLayout();

            bookThumbLayout.Direction     = LayoutDirection.LeftToRight;
            bookThumbLayout.ConstrainMode = CellConstrainMode.Ordinal;
            bookThumbLayout.MaxOrdinal    = 1;

            //	create a table layout, which will align all books in a grid
            NTableLayout tableLayout = new NTableLayout();

            tableLayout.Direction         = LayoutDirection.LeftToRight;
            tableLayout.ConstrainMode     = CellConstrainMode.Ordinal;
            tableLayout.MaxOrdinal        = 4;
            tableLayout.HorizontalSpacing = 7;
            tableLayout.VerticalSpacing   = 7;

            NLayoutContext layoutContext = new NLayoutContext();

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

            int length = books.Length;

            for (int i = 0; i < length; i++)
            {
                NCustomToolsData.NBookEntry book = books[i];

                NShape          bookThumbnailShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle);
                NImageFillStyle fs1 = new NImageFillStyle(this.MapPathSecure(@"..\..\..\..\Images\CustomTools\" + book.ThumbnailFile));
                fs1.TextureMappingStyle.MapLayout = MapLayout.Centered;
                NStyle.SetFillStyle(bookThumbnailShape, fs1);
                NStyle.SetStrokeStyle(bookThumbnailShape, new NStrokeStyle(0, Color.White));

                NShape bookTextShape = bookItemsFactory.CreateShape(BasicShapes.Rectangle);
                NStyle.SetStrokeStyle(bookTextShape, new NStrokeStyle(0, Color.White));
                bookTextShape.Text   = book.Title;
                bookTextShape.Height = 50f;

                bookThumbnailShape.Style.InteractivityStyle = new NInteractivityStyle(true, book.Id.ToString(), null, CursorType.Hand);
                bookTextShape.Style.InteractivityStyle      = new NInteractivityStyle(true, book.Id.ToString(), null, CursorType.Hand);

                //	create the book tumbnail group
                NGroup      g      = new NGroup();
                NBatchGroup bgroup = new NBatchGroup(NDrawingView1.Document);
                NNodeList   shapes = new NNodeList();

                shapes.Add(bookThumbnailShape);
                shapes.Add(bookTextShape);

                // perform layout
                bookThumbLayout.Layout(shapes, layoutContext);

                // group shapes
                bgroup.Build(shapes);
                bgroup.Group(null, false, out g);

                NDrawingView1.Document.ActiveLayer.AddChild(g);
            }

            // layout the books
            tableLayout.Layout(NDrawingView1.Document.ActiveLayer.Children(null), layoutContext);
        }
コード例 #9
0
        private void InitDocument()
        {
            NSimpleNetworkShapesFactory networkShapes = new NSimpleNetworkShapesFactory();

            networkShapes.DefaultSize = new NSizeF(50, 50);
            int i;

            // create computers
            for (i = 0; i < 9; i++)
            {
                NShape computer = networkShapes.CreateShape(SimpleNetworkShapes.Computer);
                switch (i % 3)
                {
                case 0:
                    computer.Location = new NPointF(10, 10);
                    break;

                case 1:
                    computer.Location = new NPointF(110, 10);
                    break;

                case 2:
                    computer.Location = new NPointF(75, 110);
                    break;
                }

                document.ActiveLayer.AddChild(computer);
            }

            // link the computers
            for (i = 0; i < 3; i++)
            {
                NLineShape link = new NLineShape();
                link.StyleSheetName = NDR.NameConnectorsStyleSheet;
                document.ActiveLayer.AddChild(link);

                if (i == 0)
                {
                    link.FromShape = (NShape)document.ActiveLayer.GetChildAt(8);
                    link.ToShape   = (NShape)document.ActiveLayer.GetChildAt(0);
                }
                else
                {
                    link.FromShape = (NShape)document.ActiveLayer.GetChildAt(i * 3 - 1);
                    link.ToShape   = (NShape)document.ActiveLayer.GetChildAt(i * 3);
                }
            }

            // create three groups
            NNodeList   groupNodes1 = new NNodeList();
            NBatchGroup batchGroup1 = new NBatchGroup(document);

            groupNodes1.Add(document.ActiveLayer.GetChildAt(0));
            groupNodes1.Add(document.ActiveLayer.GetChildAt(1));
            groupNodes1.Add(document.ActiveLayer.GetChildAt(2));
            batchGroup1.Build(groupNodes1);

            NNodeList   groupNodes2 = new NNodeList();
            NBatchGroup batchGroup2 = new NBatchGroup(document);

            groupNodes2.Add(document.ActiveLayer.GetChildAt(3));
            groupNodes2.Add(document.ActiveLayer.GetChildAt(4));
            groupNodes2.Add(document.ActiveLayer.GetChildAt(5));
            batchGroup2.Build(groupNodes2);

            NNodeList   groupNodes3 = new NNodeList();
            NBatchGroup batchGroup3 = new NBatchGroup(document);

            groupNodes3.Add(document.ActiveLayer.GetChildAt(6));
            groupNodes3.Add(document.ActiveLayer.GetChildAt(7));
            groupNodes3.Add(document.ActiveLayer.GetChildAt(8));
            batchGroup3.Build(groupNodes3);

            NGroup[] groups = new NGroup[3];
            batchGroup1.Group(document.ActiveLayer, false, out groups[0]);
            batchGroup2.Group(document.ActiveLayer, false, out groups[1]);
            batchGroup3.Group(document.ActiveLayer, false, out groups[2]);

            // add expand-collapse decorator and frame decorator to each group
            for (i = 0; i < groups.Length; i++)
            {
                NGroup group = groups[i];

                // because groups are created after the link we want to ensure
                // that they are behind so that the links are not obscured
                group.SendToBack();

                // create the decorators collection
                group.CreateShapeElements(ShapeElementsMask.Decorators);

                // create a frame decorator
                // we want the user to be able to select the shape when the frame is hit
                NFrameDecorator frameDecorator = new NFrameDecorator();
                frameDecorator.ShapeHitTestable = true;
                frameDecorator.Header.Text      = "Network " + i.ToString();
                group.Decorators.AddChild(frameDecorator);

                // create an expand collapse decorator
                NExpandCollapseDecorator expandCollapseDecorator = new NExpandCollapseDecorator();
                group.Decorators.AddChild(expandCollapseDecorator);

                // update the model bounds so that the computeres
                // are inside the specified padding
                group.Padding = new Nevron.Diagram.NMargins(5, 5, 30, 5);
                group.UpdateModelBounds();
                group.AutoUpdateModelBounds = true;
            }

            // layout them with a table layout
            NLayoutContext context = new NLayoutContext();

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

            NTableLayout layout = new NTableLayout();

            layout.ConstrainMode     = CellConstrainMode.Ordinal;
            layout.MaxOrdinal        = 2;
            layout.HorizontalSpacing = 50;
            layout.VerticalSpacing   = 50;
            layout.Layout(document.ActiveLayer.Children(null), context);

            document.SizeToContent(NSizeF.Empty, document.AutoBoundsPadding);
            document.AutoBoundsMode = AutoBoundsMode.AutoSizeToContent;
        }
コード例 #10
0
        protected NGroup CreateNetwork(NPoint location, string labelText)
        {
            bool       rectValid  = false;
            NRectangle rect       = NRectangle.Zero;
            NPage      activePage = m_DrawingDocument.Content.ActivePage;

            NList <NShape> shapes = activePage.GetShapes(false);

            for (int i = 0; i < shapes.Count; i++)
            {
                NRectangle bounds = shapes[i].GetAlignBoxInPage();
                if (rectValid)
                {
                    rect = NRectangle.Union(rect, bounds);
                }
                else
                {
                    rect      = bounds;
                    rectValid = true;
                }
            }

            if (rectValid)
            {
                // determine how much is out of layout area
            }

            // create computer1
            NShape computer1 = CreateComputer();

            computer1.SetBounds(0, 0, computer1.Width, computer1.Height);

            // create computer2
            NShape computer2 = CreateComputer();

            computer2.SetBounds(150, 0, computer2.Width, computer2.Height);

            // create computer3
            NShape computer3 = CreateComputer();

            computer3.SetBounds(75, 120, computer3.Width, computer3.Height);

            // create the group that contains the comptures
            NGroup      group      = new NGroup();
            NBatchGroup batchGroup = new NBatchGroup(m_DrawingDocument);

            batchGroup.Build(computer1, computer2, computer3);
            batchGroup.Group(m_DrawingDocument.Content.ActivePage, out group);

            // connect the computers in the network
            ConnectComputers(computer1, computer2, group);
            ConnectComputers(computer2, computer3, group);
            ConnectComputers(computer3, computer1, group);

            // insert a frame
            NDrawRectangle drawRect = new NDrawRectangle(0, 0, 1, 1);

            drawRect.Relative = true;
            group.Geometry.Add(drawRect);

            // change group fill style
            group.Geometry.Fill = new NStockGradientFill(ENGradientStyle.FromCenter, ENGradientVariant.Variant2, NColor.Gainsboro, NColor.White);

            // reposition and resize the group
            group.SetBounds(location.X, location.Y, group.Width, group.Height);

            // set label text
            group.TextBlock.Text = labelText;



            return(group);
        }
コード例 #11
0
        /// <summary>
        /// Creates a custom shape that is essentially a group consisting of three other shapes each with different filling.
        /// You need to use groups to have shapes that mix different fill, or stroke styles.
        /// </summary>
        /// <returns></returns>
        protected NShape CreateCoffeeCupShape()
        {
            // create the points and paths from which the shape consits
            NPoint[] cupPoints = new NPoint[] {
                new NPoint(45, 268),
                new NPoint(63, 331),
                new NPoint(121, 331),
                new NPoint(140, 268)
            };

            NGraphicsPath handleGraphicsPath = new NGraphicsPath();

            handleGraphicsPath.AddClosedCurve(new NPoint[] {
                new NPoint(175, 295),
                new NPoint(171, 278),
                new NPoint(140, 283),
                new NPoint(170, 290),
                new NPoint(128, 323)
            }, 1);

            NGraphicsPath steamGraphicsPath = new NGraphicsPath();

            steamGraphicsPath.AddCubicBeziers(new NPoint[] {
                new NPoint(92, 270),
                new NPoint(53, 163),
                new NPoint(145, 160),
                new NPoint(86, 50),
                new NPoint(138, 194),
                new NPoint(45, 145),
                new NPoint(92, 270)
            });
            steamGraphicsPath.CloseFigure();

            // calculate some bounds
            NRectangle handleBounds   = handleGraphicsPath.ExactBounds;
            NRectangle cupBounds      = NGeometry2D.GetBounds(cupPoints);
            NRectangle steamBounds    = steamGraphicsPath.ExactBounds;
            NRectangle geometryBounds = NRectangle.Union(cupBounds, handleBounds, steamBounds);

            // normalize the points and paths by transforming them to relative coordinates
            NRectangle normalRect = new NRectangle(0, 0, 1, 1);
            NMatrix    transform  = NMatrix.CreateBoundsStretchMatrix(geometryBounds, normalRect);

            transform.TransformPoints(cupPoints);
            handleGraphicsPath.Transform(transform);
            steamGraphicsPath.Transform(transform);

            // create the cup shape
            NDrawPolygon cupPolygon = new NDrawPolygon(normalRect, cupPoints);

            cupPolygon.Relative = true;
            NShape cupShape = new NShape();

            cupShape.Init2DShape();
            cupShape.Geometry.Fill = new NColorFill(NColor.Brown);
            cupShape.Geometry.Add(cupPolygon);
            cupShape.SetBounds(geometryBounds);

            // create the cup handle
            NDrawPath handlePath = new NDrawPath(normalRect, handleGraphicsPath);

            handlePath.Relative = true;
            NShape handleShape = new NShape();

            handleShape.Init2DShape();
            handleShape.Geometry.Fill = new NColorFill(NColor.LightSalmon);
            handleShape.Geometry.Add(handlePath);
            handleShape.SetBounds(geometryBounds);

            // create the steam
            NDrawPath steamPath = new NDrawPath(steamGraphicsPath.Bounds, steamGraphicsPath);

            steamPath.Relative = true;
            NShape steamShape = new NShape();

            steamShape.Init2DShape();
            steamShape.Geometry.Fill = new NColorFill(new NColor(50, 122, 122, 122));
            steamShape.Geometry.Add(steamPath);
            steamShape.SetBounds(geometryBounds);

            // group the shapes as a single group
            NGroup      group;
            NBatchGroup batch = new NBatchGroup(m_DrawingDocument);

            batch.Build(cupShape, handleShape, steamShape);
            batch.Group(null, out group);

            // alter some properties of the group
            group.SelectionMode = ENGroupSelectionMode.GroupOnly;
            group.SnapToShapes  = false;

            return(group);
        }