protected override void LoadExample()
        {
            // init form fields
            m_Layout = new NLayeredTreeLayout();

            // instruct the layout to perform HV layout of the edges
            m_Layout.OrthogonalEdgeRouting = true;

            // show the layout properties in the property grid
            propertyGrid1.SelectedObject = m_Layout;

            view.BeginInit();
            view.Grid.Visible = false;
            view.GlobalVisibility.ShowPorts      = false;
            view.GlobalVisibility.ShowArrowheads = false;
            view.ViewLayout = ViewLayout.Fit;

            // init document
            document.BeginInit();
            document.Style.FillStyle   = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant3, Color.FromArgb(192, 194, 194), Color.FromArgb(129, 133, 133));
            document.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108));
            InitDocument();
            document.EndInit();

            // init form controls
            InitFormControls();

            // end view init
            view.EndInit();
        }
Beispiel #2
0
        private void btnLayoutGroupB_Click(object sender, System.EventArgs e)
        {
            NLayeredTreeLayout layout = new NLayeredTreeLayout();

            layout.PlugSpacing.Mode = PlugSpacingMode.None;
            layout.Layout(Group2.Shapes.Children(null), new NDrawingLayoutContext(document, Group2));
            Group2.UpdateModelBounds();
            LayoutGroups();
        }
        protected void PerformLayout(Hashtable args)
        {
            // Create the layout
            NLayeredTreeLayout layout = new NLayeredTreeLayout();

            // Configure the layout
            NLayoutsHelper.ConfigureLayout(layout, args);

            // Get the shapes to layout
            NNodeList shapes = NDrawingView1.Document.ActiveLayer.Children(NFilters.Shape2D);

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

            // Resize document to fit all shapes
            NDrawingView1.Document.SizeToContent();
        }
            public void ApplyLayout(NDrawingDocument document, Dictionary <string, string> settings)
            {
                // Create the layout
                NLayeredTreeLayout layout = new NLayeredTreeLayout();

                // Configure the layout
                if (settings != null)
                {
                    NDrawingDocumentHelper helper = new NDrawingDocumentHelper(document);
                    helper.ConfigureLayout(layout, settings);
                }

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

                // Layout the shapes
                layout.Layout(shapes, new NDrawingLayoutContext(document));
            }
Beispiel #5
0
        private void LayoutGroups()
        {
            NLayeredTreeLayout layout = new NLayeredTreeLayout();

            layout.PlugSpacing.Mode = PlugSpacingMode.None;

            NNodeList shapes = new NNodeList();

            shapes.Add(document.ActiveLayer.GetChildByName("treeRoot"));
            shapes.Add(document.ActiveLayer.GetChildByName("leftEdge"));
            shapes.Add(document.ActiveLayer.GetChildByName("rightEdge"));
            shapes.Add(Group1);
            shapes.Add(Group2);

            layout.Layout(shapes, new NDrawingLayoutContext(document, shapes));
            Group1.UpdateModelBounds();
            Group2.UpdateModelBounds();
        }
Beispiel #6
0
        private void DoLayout()
        {
            // layout with a layered tree layout
            NLayoutContext context = new NLayoutContext();

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

            NLayeredTreeLayout layout = new NLayeredTreeLayout();

            layout.VertexSpacing = 50;
            layout.LayerSpacing  = 50;
            layout.Layout(document.ActiveLayer.Children(null), context);

            // size to visible shapes
            document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding, NFilters.Visible);
        }
        /// <summary>
        /// Overriden to create the tree template
        /// </summary>
        /// <param name="document">document in which to create the template</param>
        protected override void CreateTemplate(NDrawingDocument document)
        {
            // create the tree
            NList <NShape> elements = CreateTree(document);

            if (m_LayoutType == ENTreeLayoutType.None)
            {
                return;
            }

            // layout the tree
            NLayeredTreeLayout layout = new NLayeredTreeLayout();

            // sync measurement unit
            layout.OrthogonalEdgeRouting = false;

            switch (m_LayoutType)
            {
            case ENTreeLayoutType.Layered:
                layout.VertexSpacing = m_fHorizontalSpacing;
                layout.LayerSpacing  = m_fVerticalSpacing;
                break;

            case ENTreeLayoutType.LayeredLeftAligned:
                layout.VertexSpacing             = m_fHorizontalSpacing;
                layout.LayerSpacing              = m_fVerticalSpacing;
                layout.ParentPlacement.Anchor    = ENParentAnchor.SubtreeNear;
                layout.ParentPlacement.Alignment = ENRelativeAlignment.Near;
                break;

            case ENTreeLayoutType.LayeredRightAligned:
                layout.VertexSpacing             = m_fHorizontalSpacing;
                layout.LayerSpacing              = m_fVerticalSpacing;
                layout.ParentPlacement.Anchor    = ENParentAnchor.SubtreeFar;
                layout.ParentPlacement.Alignment = ENRelativeAlignment.Far;
                break;
            }

            // apply layout
            NDrawingLayoutContext context = new NDrawingLayoutContext(document, new NRectangle(Origin, NSize.Zero));

            layout.Arrange(elements.CastAll <object>(), context);
        }
        protected void InitDocument()
        {
            NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            NDrawingView1.Document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            NDrawingView1.Document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            // set up visual formatting
            NDrawingView1.Document.Style.FillStyle = new NColorFillStyle(Color.Linen);

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

            // all shapes will have shadow dropped below document content
            NDrawingView1.Document.Style.ShadowStyle.Type       = ShadowType.GaussianBlur;
            NDrawingView1.Document.Style.ShadowStyle.Offset     = new NPointL(5, 5);
            NDrawingView1.Document.Style.ShadowStyle.FadeLength = new NLength(5);
            NDrawingView1.Document.ShadowsZOrder = ShadowsZOrder.BehindDocument;

            // root
            NExpandableShape company = CreateVertex("The Company");

            // products branch
            NExpandableShape products = CreateVertex("Products and Services");

            ConnectShapes(company, products);

            NExpandableShape product1 = this.CreateVertex("Product1");

            ConnectShapes(products, product1);

            NExpandableShape product2 = this.CreateVertex("Product2");

            ConnectShapes(products, product2);

            // how to reach
            NExpandableShape reach = CreateVertex("How to reach");

            ConnectShapes(company, reach);

            NExpandableShape phone = this.CreateVertex("Phone");

            ConnectShapes(reach, phone);

            NExpandableShape fax = this.CreateVertex("Fax");

            ConnectShapes(reach, fax);

            NExpandableShape website = this.CreateVertex("Website");

            ConnectShapes(reach, website);

            // research
            NExpandableShape research = CreateVertex("Research");

            ConnectShapes(company, research);

            NExpandableShape tech = this.CreateVertex("Techinical");

            ConnectShapes(research, tech);

            NExpandableShape marketing = this.CreateVertex("Marketing");

            ConnectShapes(research, marketing);

            NExpandableShape newTech = this.CreateVertex("New Tech");

            ConnectShapes(research, newTech);

            NNodeList nodes = new NNodeList();

            nodes.Add(company);

            // create a layout context
            NLayoutContext layoutContext = new NLayoutContext();

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

            // first apply a layered tree layout
            // to set a start position of the shapes as a simple tree
            NTreeLayout treeLayout = new NLayeredTreeLayout();

            treeLayout.Layout(nodes, layoutContext);

            // then apply a symmetrical layout to layout them in a ring fasion
            NSymmetricalLayout symmetricalLayout = new NSymmetricalLayout();

            symmetricalLayout.DesiredDistanceForce.DesiredDistance = 100;
            symmetricalLayout.Layout(nodes, layoutContext);

            // size the document to the content (note that we use irregular margins)
            NDrawingView1.Document.SizeToContent(new NSizeF(100, 100), new Nevron.Diagram.NMargins(20, 20, 100, 20));

            // add title spanning the entire document width
            NTextShape text = new NTextShape("Company Structure", new NRectangleF(5, -50, NDrawingView1.Document.Width - 5, 50));

            text.Style.TextStyle = new NTextStyle(new Font("Times New Roman", 23, FontStyle.Bold));
            text.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Center;
            NDrawingView1.Document.ActiveLayer.AddChild(text);
        }
        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();
        }
        private void InitDocument()
        {
            // all shapes will have shadow dropped below document content
            document.Style.ShadowStyle.Type       = ShadowType.GaussianBlur;
            document.Style.ShadowStyle.Offset     = new NPointL(5, 5);
            document.Style.ShadowStyle.FadeLength = new NLength(5);
            document.ShadowsZOrder = ShadowsZOrder.BehindDocument;

            // root
            NExpandableShape company = CreateVertex("The Company");

            // products branch
            NExpandableShape products = CreateVertex("Products and Services");

            ConnectShapes(company, products);

            NExpandableShape product1 = this.CreateVertex("Product1");

            ConnectShapes(products, product1);

            NExpandableShape product2 = this.CreateVertex("Product2");

            ConnectShapes(products, product2);

            // how to reach
            NExpandableShape reach = CreateVertex("How to reach");

            ConnectShapes(company, reach);

            NExpandableShape phone = this.CreateVertex("Phone");

            ConnectShapes(reach, phone);

            NExpandableShape fax = this.CreateVertex("Fax");

            ConnectShapes(reach, fax);

            NExpandableShape website = this.CreateVertex("Website");

            ConnectShapes(reach, website);

            // research
            NExpandableShape research = CreateVertex("Research");

            ConnectShapes(company, research);

            NExpandableShape tech = this.CreateVertex("Techinical");

            ConnectShapes(research, tech);

            NExpandableShape marketing = this.CreateVertex("Marketing");

            ConnectShapes(research, marketing);

            NExpandableShape newTech = this.CreateVertex("New Tech");

            ConnectShapes(research, newTech);

            NNodeList nodes = new NNodeList();

            nodes.Add(company);

            // create a layout context
            NLayoutContext layoutContext = new NLayoutContext();

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

            // first apply a layered tree layout
            // to set a start position of the shapes as a simple tree
            NTreeLayout treeLayout = new NLayeredTreeLayout();

            treeLayout.Layout(nodes, layoutContext);

            // then apply a symmetrical layout to layout them in a ring fasion
            NSymmetricalLayout symmetricalLayout = new NSymmetricalLayout();

            symmetricalLayout.DesiredDistanceForce.DesiredDistance = 100;
            symmetricalLayout.Layout(nodes, layoutContext);

            // size the document to the content (note that we use irregular margins)
            document.SizeToContent(new NSizeF(100, 100), new Nevron.Diagram.NMargins(20, 20, 50, 20));

            // add title spanning the entire document width
            NTextShape text = new NTextShape("Company Structure", new NRectangleF(document.Bounds.X + 5, document.Bounds.Y + 5, document.Width - 10, 50));

            text.Style.TextStyle = new NTextStyle(new Font("Times New Roman", 23, FontStyle.Bold));
            document.ActiveLayer.AddChild(text);
        }
        protected override void LoadExample()
        {
            // begin view init
            view.BeginInit();

            // configure the view
            view.Grid.Visible               = false;
            view.Selection.Mode             = DiagramSelectionMode.Single;
            view.GlobalVisibility.ShowPorts = false;
            view.HorizontalRuler.Visible    = false;
            view.VerticalRuler.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
            m_TreeImporter = new NTreeDataSourceImporter();

            // set the document in the active layer of which the shapes will be imported
            m_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
            oleDbConnection1.ConnectionString = @"Data Source=""" + Application.StartupPath +
                                                @"\..\..\Resources\Data\SiteMap.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";";

            m_TreeImporter.DataSource = oleDbDataAdapter1;

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

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

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

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

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

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

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

            // import
            m_TreeImporter.Import();

            // end view init
            view.EndInit();
        }