protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; // hide the grid drawing.ScreenVisibility.ShowGrid = false; // create two shapes and a line connector between them NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NConnectorShapeFactory connectorShapes = new NConnectorShapeFactory(); m_BeginShape = basicShapes.CreateShape(ENBasicShape.Ellipse); m_BeginShape.Size = new NSize(150, 100); drawing.ActivePage.Items.Add(m_BeginShape); m_EndShape = basicShapes.CreateShape(ENBasicShape.Pentagram); m_EndShape.Size = new NSize(100, 100); drawing.ActivePage.Items.Add(m_EndShape); m_Connector = connectorShapes.CreateShape(ENConnectorShape.Line); m_Connector.GlueBeginToNearestPort(m_BeginShape); m_Connector.GlueEndToNearestPort(m_EndShape); drawing.ActivePage.Items.Add(m_Connector); // perform inital layout of shapes OnTimerTick(); }
protected override void InitDiagram() { base.InitDiagram(); const double width = 40; const double height = 40; const double distance = 80; NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NPage activePage = m_DrawingDocument.Content.ActivePage; 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] = basicShapes.CreateShape(ENBasicShape.Rectangle); if (vertexCount % 2 != 0 && i == 0) { shapes[i].SetBounds(new NRectangle( (width + (distance * 1.5)) / 2, distance + (j / 2) * (distance * 1.5), width, height)); } else { shapes[i].SetBounds(new NRectangle( width / 2 + (j % 2) * (distance * 1.5), height + (j / 2) * (distance * 1.5), width, height)); } activePage.Items.Add(shapes[i]); } else { NRoutableConnector edge = new NRoutableConnector(); edge.UserClass = "Connector"; activePage.Items.Add(edge); edge.GlueBeginToShape(shapes[from[i - vertexCount] - 1]); edge.GlueEndToShape(shapes[to[i - vertexCount] - 1]); } } // arrange diagram ArrangeDiagram(); // fit active page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); double padding = 10; double sizeX = 160; double sizeY = 160; for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { NShape shape1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape1.SetBounds(padding + x * (padding + sizeX), padding + y * (padding + sizeY), sizeX, sizeY); shape1.TextBlock = new NTextBlock(); shape1.TextBlock.Padding = new NMargins(20); shape1.TextBlock.Text = "The quick brown fox jumps over the lazy dog"; drawing.ActivePage.Items.Add(shape1); } } }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); NShape shape1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape1.SetBounds(10, 10, 600, 1000); NTextBlock textBlock = new NTextBlock(); shape1.TextBlock = textBlock; textBlock.Padding = new NMargins(20); textBlock.Content.Blocks.Clear(); textBlock.Content.HorizontalAlignment = ENAlign.Left; AddFormattedTextToContent(textBlock.Content); drawing.ActivePage.Items.Add(shape1); }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); NShape shape1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape1.SetBounds(10, 10, 381, 600); NTextBlock textBlock1 = new NTextBlock(); shape1.TextBlock = textBlock1; textBlock1.Content.Blocks.Clear(); AddFormattedTextToContent(textBlock1.Content); drawing.ActivePage.Items.Add(shape1); NShape shape2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape2.SetBounds(401, 10, 381, 600); NTextBlock textBlock2 = new NTextBlock(); shape2.TextBlock = textBlock2; textBlock2.Content.Blocks.Clear(); AddFormattedTextWithImagesToContent(textBlock2.Content); drawing.ActivePage.Items.Add(shape2); }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; // plotter commands NBasicShapeFactory basicShapes = new NBasicShapeFactory(); // create a rounded rect NShape rectShape = basicShapes.CreateShape(ENBasicShape.Rectangle); rectShape.SetBounds(50, 50, 100, 100); rectShape.Text = "Move me close to the star"; rectShape.GetPortByName("Top").GlueMode = ENPortGlueMode.Outward; activePage.Items.Add(rectShape); // create a star NShape pentagramShape = basicShapes.CreateShape(ENBasicShape.Pentagram); pentagramShape.SetBounds(310, 310, 100, 100); activePage.Items.Add(pentagramShape); }
protected override void InitDiagram() { base.InitDiagram(); // Create a group NGroup group = new NGroup(); m_DrawingDocument.Content.ActivePage.Items.Add(group); group.PinX = 300; group.PinY = 300; // Create some shapes and add them to the group NBasicShapeFactory factory = new NBasicShapeFactory(); NShape root = factory.CreateShape(ENBasicShape.Rectangle); root.Text = "Root"; group.Shapes.Add(root); NShape shape1 = factory.CreateShape(ENBasicShape.Circle); shape1.Text = "Circle 1"; group.Shapes.Add(shape1); NShape shape2 = factory.CreateShape(ENBasicShape.Circle); shape2.Text = "Circle 2"; group.Shapes.Add(shape2); NShape shape3 = factory.CreateShape(ENBasicShape.Circle); shape3.Text = "Circle 3"; group.Shapes.Add(shape3); // Connect the shapes ConnectShapes(root, shape1); ConnectShapes(root, shape2); ConnectShapes(root, shape3); // Update group bounds group.UpdateBounds(); // Create a layout context and configure the area you want the group to be arranged in. // The layout area is in page coordinates NDrawingLayoutContext layoutContext = new NDrawingLayoutContext(m_DrawingDocument, group); layoutContext.LayoutArea = new NRectangle(100, 100, 200, 200); // Layout the shapes in the group NRadialGraphLayout layout = new NRadialGraphLayout(); layout.Arrange(group.Shapes.ToArray(), layoutContext); // Update the group bounds group.UpdateBounds(); }
/// <summary> /// Creates an ellipse shapeand applies the specified class to ut (used for Start and End shapes) /// </summary> /// <param name="bounds"></param> /// <param name="userClass"></param> /// <returns></returns> NShape CreateEllipse(NRectangle bounds, string userClass) { NBasicShapeFactory factory = new NBasicShapeFactory(); NShape shape = factory.CreateShape(ENBasicShape.Ellipse); shape.SetBounds(bounds); shape.UserClass = userClass; m_DrawingDocument.Content.ActivePage.Items.Add(shape); return(shape); }
private void Initialize() { m_fHorizontalSpacing = 30; m_fVerticalSpacing = 30; m_VerticesSize = new NSize(40, 40); m_VerticesShape = ENBasicShape.Rectangle; m_VerticesUserClass = ""; m_EdgesUserClass = ""; m_ShapeFactory = new NBasicShapeFactory(); }
protected override void InitDiagram() { base.InitDiagram(); NBasicShapeFactory factory = new NBasicShapeFactory(); NShape shape = factory.CreateShape(ENBasicShape.Rectangle); shape.SetBounds(100, 100, 150, 100); NPage activePage = m_DrawingDocument.Content.ActivePage; activePage.Items.Add(shape); }
/// <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="userClass">name of the stylesheet from which to inherit styles</param> /// <returns>new basic shape</returns> private NShape CreateBasicShape(ENBasicShape basicShape, NRectangle bounds, string text, string userClass) { // create shape NShape shape = new NBasicShapeFactory().CreateShape(basicShape); // set bounds, text and user class shape.SetBounds(bounds); shape.Text = text; shape.UserClass = userClass; // add to active page m_DrawingDocument.Content.ActivePage.Items.Add(shape); return(shape); }
protected override void InitDiagram() { NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // 1. Create some shape factories NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); NConnectorShapeFactory connectorShapesFactory = new NConnectorShapeFactory(); // 2. Create and add some shapes NShape shape1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape1.SetBounds(new NRectangle(50, 50, 100, 100)); activePage.Items.Add(shape1); NShape shape2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape2.SetBounds(new NRectangle(400, 50, 100, 100)); activePage.Items.Add(shape2); // 3. Connect the shapes NShape connector = connectorShapesFactory.CreateShape(ENConnectorShape.Line); activePage.Items.Add(connector); connector.GlueBeginToShape(shape1); connector.GlueEndToShape(shape2); // Add 2 outward ports to the connector NPort port1 = new NPort(0.3, 0.3, true); port1.GlueMode = ENPortGlueMode.Outward; connector.Ports.Add(port1); NPort port2 = new NPort(0.7, 0.7, true); port2.GlueMode = ENPortGlueMode.Outward; connector.Ports.Add(port2); // Attach label shapes to the outward ports of the connector NShape labelShape1 = CreateLabelShape("Label 1"); activePage.Items.Add(labelShape1); labelShape1.GlueMasterPortToPort(labelShape1.Ports[0], port1); NShape labelShape2 = CreateLabelShape("Label 2"); activePage.Items.Add(labelShape2); labelShape2.GlueMasterPortToPort(labelShape2.Ports[0], port2); }
protected override void InitDiagram() { base.InitDiagram(); // create all shapes NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NConnectorShapeFactory connectorShapes = new NConnectorShapeFactory(); // create the group NGroup group = new NGroup(); // make some background for the group NDrawRectangle drawRect = new NDrawRectangle(0, 0, 1, 1); drawRect.Relative = true; group.Geometry.Add(drawRect); group.Geometry.Fill = new NColorFill(NColor.LightCoral); group.SetBounds(new Nov.Graphics.NRectangle(50, 50, 230, 330)); // create a rectangle that is scaled and repositioned NShape rect1 = basicShapes.CreateShape(ENBasicShape.Rectangle); rect1.Text = "Scale and Reposition"; group.Shapes.Add(rect1); rect1.ResizeInGroup = ENResizeInGroup.ScaleAndReposition; rect1.SetBounds(new Nov.Graphics.NRectangle(10, 10, 100, 100)); // create a rectangle that is only repositioned NShape rect2 = basicShapes.CreateShape(ENBasicShape.Rectangle); rect2.Text = "Reposition Only"; group.Shapes.Add(rect2); rect2.ResizeInGroup = ENResizeInGroup.RepositionOnly; rect2.SetBounds(new Nov.Graphics.NRectangle(120, 120, 100, 100)); // create a 1D shape NShape arrow = connectorShapes.CreateShape(ENConnectorShape.Single45DegreesArrow); arrow.Text = "1D Shape"; group.Shapes.Add(arrow); arrow.SetBeginPoint(new NPoint(10, 250)); arrow.SetEndPoint(new NPoint(220, 290)); // add the group m_DrawingDocument.Content.ActivePage.Items.Add(group); }
protected override void InitDiagram() { base.InitDiagram(); // create some shapes NPage activePage = m_DrawingDocument.Content.ActivePage; NBasicShapeFactory basicShapes = new NBasicShapeFactory(); for (int i = 0; i < 20; i++) { NShape shape = basicShapes.CreateShape(ENBasicShape.Rectangle); activePage.Items.Add(shape); } // arrange diagram ArrangeDiagram(); // fit page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); NShape shape1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape1.SetBounds(10, 10, 200, 200); shape1.TextBlock = new NTextBlock(); shape1.TextBlock.Padding = new NMargins(20); shape1.TextBlock.Text = "This text cantains many typpos. This text contuins manyy typos."; drawing.ActivePage.Items.Add(shape1); }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); NShape shape1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); shape1.SetBounds(10, 10, 600, 1000); NImageBlock imageBlock = shape1.ImageBlock; imageBlock.Image = NResources.Image_FishBowl_wmf; imageBlock.Padding = new NMargins(20); drawing.ActivePage.Items.Add(shape1); }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; // plotter commands NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NConnectorShapeFactory connectorFactory = new NConnectorShapeFactory(); // create a rounded rect NShape rectShape = basicShapes.CreateShape(ENBasicShape.Rectangle); rectShape.DefaultShapeGlue = ENDefaultShapeGlue.GlueToGeometryIntersection; rectShape.Geometry.CornerRounding = 10; rectShape.SetBounds(50, 50, 100, 100); activePage.Items.Add(rectShape); // create a rounded pentagram NShape pentagramShape = basicShapes.CreateShape(ENBasicShape.Pentagram); pentagramShape.DefaultShapeGlue = ENDefaultShapeGlue.GlueToGeometryIntersection; pentagramShape.Geometry.CornerRounding = 20; pentagramShape.SetBounds(310, 310, 100, 100); activePage.Items.Add(pentagramShape); // create a rounded routable connector NShape connector = connectorFactory.CreateShape(ENConnectorShape.RoutableConnector); connector.Geometry.CornerRounding = 30; connector.GlueBeginToShape(rectShape); connector.GlueEndToShape(pentagramShape); activePage.Items.Add(connector); }
/// <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 CreateRandomBarycenterDiagram(int fixedCount, int freeCount) { if (fixedCount < 3) { throw new ArgumentException("Needs at least three fixed vertices"); } // clean up the active page NPage activePage = m_DrawingDocument.Content.ActivePage; activePage.Items.Clear(); // we will be using basic circle shapes with default size of (30, 30) NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); basicShapesFactory.DefaultSize = new NSize(30, 30); NConnectorShapeFactory connectorsShapesFactory = new NConnectorShapeFactory(); // create the fixed vertices NShape[] fixedShapes = new NShape[fixedCount]; for (int i = 0; i < fixedCount; i++) { fixedShapes[i] = basicShapesFactory.CreateShape(ENBasicShape.Circle); //((NDynamicPort)fixedShapes[i].Ports.GetChildByName("Center", -1)).GlueMode = DynamicPortGlueMode.GlueToLocation; fixedShapes[i].Geometry.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(251, 203, 156), new NColor(247, 150, 56)); fixedShapes[i].Geometry.Stroke = new NStroke(1, new NColor(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 NForceDirectedGraphLayout.SetXMoveable(fixedShapes[i], false); NForceDirectedGraphLayout.SetYMoveable(fixedShapes[i], false); activePage.Items.AddChild(fixedShapes[i]); } // create the free vertices NShape[] freeShapes = new NShape[freeCount]; for (int i = 0; i < freeCount; i++) { freeShapes[i] = basicShapesFactory.CreateShape(ENBasicShape.Circle); freeShapes[i].Geometry.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(192, 194, 194), new NColor(129, 133, 133)); freeShapes[i].Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.AddChild(freeShapes[i]); } // link the fixed shapes in a circle for (int i = 0; i < fixedCount; i++) { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); activePage.Items.AddChild(connector); if (i == 0) { connector.GlueBeginToShape(fixedShapes[fixedCount - 1]); connector.GlueEndToShape(fixedShapes[0]); } else { connector.GlueBeginToShape(fixedShapes[i - 1]); connector.GlueEndToShape(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 NRoutableConnector lineShape = new NRoutableConnector(); lineShape.MakeLine(); activePage.Items.AddChild(lineShape); lineShape.GlueBeginToShape(freeShapes[i]); lineShape.GlueEndToShape(fixedShapes[firstFixed]); // link with second fixed lineShape = new NRoutableConnector(); lineShape.MakeLine(); activePage.Items.AddChild(lineShape); lineShape.GlueBeginToShape(freeShapes[i]); lineShape.GlueEndToShape(fixedShapes[secondFixed]); } // link each free shape with another free shape for (int i = 1; i < freeCount; i++) { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); activePage.Items.AddChild(connector); connector.GlueBeginToShape(freeShapes[i - 1]); connector.GlueEndToShape(freeShapes[i]); } // send all edges to back NBatchReorder batchReorder = new NBatchReorder(m_DrawingDocument); batchReorder.Build(activePage.GetShapes(false, NDiagramFilters.ShapeType1D).CastAll <NDiagramItem>()); batchReorder.SendToBack(activePage); // arrange the elements ArrangeDiagram(); }
protected override void InitDiagram() { base.InitDiagram(); NPage activePage = m_DrawingDocument.Content.ActivePage; // we will be using basic shapes for this example NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); basicShapesFactory.DefaultSize = new NSize(80, 80); NList <NPerson> persons = new NList <NPerson>(); // create persons NPerson personEmil = new NPerson("Emil Moore", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personAndre = new NPerson("Andre Smith", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personRobert = new NPerson("Robert Johnson", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personBob = new NPerson("Bob Williams", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personPeter = new NPerson("Peter Brown", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personSilvia = new NPerson("Silvia Moore", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personEmily = new NPerson("Emily Smith", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personMonica = new NPerson("Monica Johnson", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personSamantha = new NPerson("Samantha Miller", basicShapesFactory.CreateShape(ENBasicShape.Circle)); NPerson personIsabella = new NPerson("Isabella Davis", basicShapesFactory.CreateShape(ENBasicShape.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++) { activePage.Items.Add(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) { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); activePage.Items.Add(connector); connector.GlueBeginToShape(currentPerson.m_Shape); connector.GlueEndToShape(currentPerson.m_Family.m_Shape); connector.Geometry.Stroke = new NStroke(2, NColor.Coral); connector.LayoutData.SpringStiffness = 2; connector.LayoutData.SpringLength = 100; } } for (int i = 0; i < persons.Count; i++) { NPerson currentPerson = persons[i]; for (int j = 0; j < currentPerson.m_Friends.Count; j++) { NRoutableConnector connector = new NRoutableConnector(); connector.MakeLine(); activePage.Items.Add(connector); connector.GlueBeginToShape(currentPerson.m_Shape); connector.GlueEndToShape(currentPerson.m_Friends[j].m_Shape); connector.Geometry.Stroke = new NStroke(2, NColor.Green); connector.LayoutData.SpringStiffness = 1; connector.LayoutData.SpringLength = 200; } } // arrange diagram ArrangeDiagram(); // fit active page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
protected override void InitDiagram() { base.InitDiagram(); NStyleSheet sheet = new NStyleSheet(); m_DrawingDocument.StyleSheets.Add(sheet); // create a rule that applies to the geometries of all shapes with user class Connectors const string connectorsClass = "Connector"; { NRule rule = sheet.CreateRule(delegate(NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass(connectorsClass); }); rule.AddValueDeclaration <NArrowhead>(NGeometry.EndArrowheadProperty, new NArrowhead(ENArrowheadShape.TriangleNoFill), true); } // create a rule that applies to the TextBlocks of all shapes with user class Connectors { NRule rule = sheet.CreateRule(delegate(NSelectorBuilder sb) { sb.Type(NTextBlock.NTextBlockSchema); sb.ChildOf(); sb.UserClass(connectorsClass); }); rule.AddValueDeclaration <NFill>(NTextBlock.BackgroundFillProperty, new NColorFill(NColor.White)); } // create a rule that applies to shapes with user class "STARTEND" { NRule rule = sheet.CreateRule(delegate(NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("STARTEND"); }); rule.AddValueDeclaration <NFill>(NGeometry.FillProperty, new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, new NColor(247, 150, 56), new NColor(251, 203, 156))); } // create a rule that applies to shapes with user class "QUESTION" { NRule rule = sheet.CreateRule(delegate(NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("QUESTION"); }); rule.AddValueDeclaration <NFill>(NGeometry.FillProperty, new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, new NColor(129, 133, 133), new NColor(192, 194, 194))); } // create a rule that applies to shapes with user class "ACTION" { NRule rule = sheet.CreateRule(delegate(NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("ACTION"); }); rule.AddValueDeclaration <NFill>(NGeometry.FillProperty, new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, new NColor(68, 90, 108), new NColor(162, 173, 182))); } // get drawing and active page NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide ports and grid drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); NFlowchartingShapeFactory flowChartingShapesFactory = new NFlowchartingShapeFactory(); NConnectorShapeFactory connectorShapesFactory = new NConnectorShapeFactory(); NRectangle bounds; int vSpacing = 35; int hSpacing = 45; int topMargin = 10; int leftMargin = 10; int shapeWidth = 90; int shapeHeight = 55; int col1 = leftMargin; int col2 = col1 + shapeWidth + hSpacing; int col3 = col2 + shapeWidth + hSpacing; int col4 = col3 + shapeWidth + hSpacing; int row1 = topMargin; int row2 = row1 + shapeHeight + vSpacing; int row3 = row2 + shapeHeight + vSpacing; int row4 = row3 + shapeHeight + vSpacing; int row5 = row4 + shapeHeight + vSpacing; int row6 = row5 + shapeHeight + vSpacing; bounds = new NRectangle(col2, row1, shapeWidth, shapeHeight); NShape start = CreateFlowChartingShape(ENFlowchartingShape.Termination, bounds, "START", "STARTEND"); // row 2 bounds = new NRectangle(col2, row2, shapeWidth, shapeHeight); NShape haveSerialNumber = CreateFlowChartingShape(ENFlowchartingShape.Decision, bounds, "Have a serial number?", "QUESTION"); bounds = new NRectangle(col3, row2, shapeWidth, shapeHeight); NShape getSerialNumber = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Get serial number", "ACTION"); // row 3 bounds = new NRectangle(col1, row3, shapeWidth, shapeHeight); NShape enterSerialNumber = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Enter serial number", "ACTION"); bounds = new NRectangle(col2, row3, shapeWidth, shapeHeight); NShape haveDiskSpace = CreateFlowChartingShape(ENFlowchartingShape.Decision, bounds, "Have disk space?", "QUESTION"); bounds = new NRectangle(col3, row3, shapeWidth, shapeHeight); NShape freeUpSpace = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Free up space", "ACTION"); // row 4 bounds = new NRectangle(col1, row4, shapeWidth, shapeHeight); NShape runInstallRect = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Run install file", "ACTION"); bounds = new NRectangle(col2, row4, shapeWidth, shapeHeight); NShape registerNow = CreateFlowChartingShape(ENFlowchartingShape.Decision, bounds, "Register now?", "QUESTION"); bounds = new NRectangle(col3, row4, shapeWidth, shapeHeight); NShape fillForm = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Fill out form", "ACTION"); bounds = new NRectangle(col4, row4, shapeWidth, shapeHeight); NShape submitForm = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Submit form", "ACTION"); // row 5 bounds = new NRectangle(col1, row5, shapeWidth, shapeHeight); NShape finishInstall = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Finish installation", "ACTION"); bounds = new NRectangle(col2, row5, shapeWidth, shapeHeight); NShape restartNeeded = CreateFlowChartingShape(ENFlowchartingShape.Decision, bounds, "Restart needed?", "QUESTION"); bounds = new NRectangle(col3, row5, shapeWidth, shapeHeight); NShape restart = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "Restart", "ACTION"); // row 6 bounds = new NRectangle(col2, row6, shapeWidth, shapeHeight); NShape run = CreateFlowChartingShape(ENFlowchartingShape.Process, bounds, "RUN", "STARTEND"); // create connectors CreateConnector(start, "Bottom", haveSerialNumber, "Top", ENConnectorShape.Line, ""); CreateConnector(getSerialNumber, "Top", haveSerialNumber, "Top", ENConnectorShape.RoutableConnector, ""); CreateConnector(haveSerialNumber, "Right", getSerialNumber, "Left", ENConnectorShape.Line, "No"); CreateConnector(haveSerialNumber, "Bottom", enterSerialNumber, "Top", ENConnectorShape.BottomToTop1, "Yes"); CreateConnector(enterSerialNumber, "Right", haveDiskSpace, "Left", ENConnectorShape.Line, ""); CreateConnector(freeUpSpace, "Top", haveDiskSpace, "Top", ENConnectorShape.RoutableConnector, ""); CreateConnector(haveDiskSpace, "Right", freeUpSpace, "Left", ENConnectorShape.Line, "No"); CreateConnector(haveDiskSpace, "Bottom", runInstallRect, "Top", ENConnectorShape.BottomToTop1, "Yes"); CreateConnector(registerNow, "Right", fillForm, "Left", ENConnectorShape.Line, "Yes"); CreateConnector(registerNow, "Bottom", finishInstall, "Top", ENConnectorShape.BottomToTop1, "No"); CreateConnector(fillForm, "Right", submitForm, "Left", ENConnectorShape.Line, ""); CreateConnector(submitForm, "Bottom", finishInstall, "Top", ENConnectorShape.BottomToTop1, ""); CreateConnector(finishInstall, "Right", restartNeeded, "Left", ENConnectorShape.Line, ""); CreateConnector(restart, "Bottom", run, "Top", ENConnectorShape.BottomToTop1, ""); CreateConnector(restartNeeded, "Right", restart, "Left", ENConnectorShape.Line, "Yes"); CreateConnector(restartNeeded, "Bottom", run, "Top", ENConnectorShape.Line, "No"); }
protected override void InitDiagram() { base.InitDiagram(); NStyleSheet sheet = new NStyleSheet(); m_DrawingDocument.StyleSheets.Add(sheet); // create a rule that applies to the TextBlocks of all shapes with user class Connectors string connectorClass = NDR.StyleSheetNameConnectors; { NRule rule2 = new NRule(); sheet.Add(rule2); NSelectorBuilder sb = rule2.GetSelectorBuilder(); sb.Start(); sb.Type(NTextBlock.NTextBlockSchema); sb.ChildOf(); sb.UserClass(connectorClass); sb.End(); rule2.Declarations.Add(new NValueDeclaration <NFill>(NTextBlock.BackgroundFillProperty, new NColorFill(NColor.White))); } // get drawing and active page NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide ports and grid drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); NFlowchartingShapeFactory flowChartingShapesFactory = new NFlowchartingShapeFactory(); NConnectorShapeFactory connectorShapesFactory = new NConnectorShapeFactory(); // create title NShape titleShape = basicShapesFactory.CreateTextShape("Bubble Sort"); titleShape.SetBounds(GetGridCell(0, 1, 2, 1)); titleShape.TextBlock.FontName = "Arial"; titleShape.TextBlock.FontSize = 40; titleShape.TextBlock.FontStyle = ENFontStyle.Bold; titleShape.TextBlock.Fill = new NColorFill(new NColor(68, 90, 108)); titleShape.TextBlock.Shadow = new NShadow(); activePage.Items.AddChild(titleShape); // begin shape NShape shapeBegin = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Termination); shapeBegin.SetBounds(GetGridCell(0, 0)); shapeBegin.Text = "BEGIN"; activePage.Items.Add(shapeBegin); // get array item shape NShape shapeGetItem = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Data); shapeGetItem.SetBounds(GetGridCell(1, 0)); shapeGetItem.Text = "Get array item [1...n]"; activePage.Items.Add(shapeGetItem); // i = 1 shape NShape shapeI1 = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Process); shapeI1.SetBounds(GetGridCell(2, 0)); shapeI1.Text = "i = 1"; activePage.Items.Add(shapeI1); // j = n shape NShape shapeJEN = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Process); shapeJEN.SetBounds(GetGridCell(3, 0)); shapeJEN.Text = "j = n"; activePage.Items.Add(shapeJEN); // less comparison shape NShape shapeLess = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Decision); shapeLess.SetBounds(GetGridCell(4, 0)); shapeLess.Text = "item[i] < item[j - 1]?"; activePage.Items.Add(shapeLess); // swap shape NShape shapeSwap = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Process); shapeSwap.SetBounds(GetGridCell(4, 1)); shapeSwap.Text = "Swap item[i] and item[j-1]"; activePage.Items.Add(shapeSwap); // j > i + 1? shape NShape shapeJQ = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Decision); shapeJQ.SetBounds(GetGridCell(5, 0)); shapeJQ.Text = "j = (i + 1)?"; activePage.Items.Add(shapeJQ); // dec j shape NShape shapeDecJ = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Process); shapeDecJ.SetBounds(GetGridCell(5, 1)); shapeDecJ.Text = "j = j - 1"; activePage.Items.Add(shapeDecJ); // i > n - 1? shape NShape shapeIQ = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Decision); shapeIQ.SetBounds(GetGridCell(6, 0)); shapeIQ.Text = "i = (n - 1)?"; activePage.Items.Add(shapeIQ); // inc i shape NShape shapeIncI = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Process); shapeIncI.SetBounds(GetGridCell(6, 1)); shapeIncI.Text = "i = i + 1"; activePage.Items.Add(shapeIncI); // end shape NShape shapeEnd = flowChartingShapesFactory.CreateShape(ENFlowchartingShape.Termination); shapeEnd.SetBounds(GetGridCell(7, 0)); shapeEnd.Text = "END"; activePage.Items.Add(shapeEnd); // connect begin with get array item NShape connector1 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector1.UserClass = connectorClass; activePage.Items.AddChild(connector1); connector1.GlueBeginToShape(shapeBegin); connector1.GlueEndToShape(shapeGetItem); // connect get array item with i = 1 NShape connector2 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector2.UserClass = connectorClass; activePage.Items.AddChild(connector2); connector2.GlueBeginToShape(shapeGetItem); connector2.GlueEndToShape(shapeI1); // connect i = 1 and j = n NShape connector3 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector3.UserClass = connectorClass; activePage.Items.AddChild(connector3); connector3.GlueBeginToShape(shapeI1); connector3.GlueEndToShape(shapeJEN); // connect j = n and item[i] < item[j-1]? NShape connector4 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector4.UserClass = connectorClass; activePage.Items.AddChild(connector4); connector4.GlueBeginToShape(shapeJEN); connector4.GlueEndToShape(shapeLess); // connect item[i] < item[j-1]? and j = (i + 1)? NShape connector5 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector5.UserClass = connectorClass; connector5.Text = "No"; activePage.Items.AddChild(connector5); connector5.GlueBeginToShape(shapeLess); connector5.GlueEndToShape(shapeJQ); // connect j = (i + 1)? and i = (n - 1)? NShape connector6 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector6.UserClass = connectorClass; activePage.Items.AddChild(connector6); connector6.GlueBeginToShape(shapeJQ); connector6.GlueEndToShape(shapeIQ); // connect i = (n - 1) and END NShape connector7 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector7.UserClass = connectorClass; activePage.Items.AddChild(connector7); connector7.GlueBeginToShape(shapeIQ); connector7.GlueEndToShape(shapeEnd); // connect item[i] < item[j-1]? and Swap NShape connector8 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector8.UserClass = connectorClass; connector8.Text = "Yes"; activePage.Items.AddChild(connector8); connector8.GlueBeginToShape(shapeLess); connector8.GlueEndToShape(shapeSwap); // connect j = (i + 1)? and j = (j - 1) NShape connector9 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector9.UserClass = connectorClass; activePage.Items.AddChild(connector9); connector9.GlueBeginToShape(shapeJQ); connector9.GlueEndToShape(shapeDecJ); // connect i = (n - 1)? and i = (i + 1) NShape connector10 = connectorShapesFactory.CreateShape(ENConnectorShape.Line); connector10.UserClass = connectorClass; activePage.Items.AddChild(connector10); connector10.GlueBeginToShape(shapeIQ); connector10.GlueEndToShape(shapeIncI); // connect Swap to No connector NShape connector11 = connectorShapesFactory.CreateShape(ENConnectorShape.TopBottomToSide); connector11.UserClass = connectorClass; activePage.Items.AddChild(connector11); connector11.GlueBeginToShape(shapeSwap); connector11.GlueEndToShape(connector5); // connect i = i + 1 to connector3 NShape connector12 = connectorShapesFactory.CreateSideToSide(m_GridSpacing.Width * 2); connector12.UserClass = connectorClass; activePage.Items.AddChild(connector12); connector12.GlueBeginToPort(shapeIncI.GetPortByName("Right")); connector12.GlueEndToGeometryContour(connector3, 0.5f); // connect j = j - 1 to connector4 NShape connector13 = connectorShapesFactory.CreateSideToSide(m_GridSpacing.Width); connector13.UserClass = connectorClass; activePage.Items.AddChild(connector13); connector13.GlueBeginToPort(shapeDecJ.GetPortByName(("Right"))); connector13.GlueEndToGeometryContour(connector4, 0.5f); }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; string[] tableDescription = new string[] { "Table With Column Ports", "Table With Row Ports", "Table With Cell Ports", "Table With Grid Ports" }; ENPortsDistributionMode[] tablePortDistributionModes = new ENPortsDistributionMode[] { ENPortsDistributionMode.ColumnsOnly, ENPortsDistributionMode.RowsOnly, ENPortsDistributionMode.CellBased, ENPortsDistributionMode.GridBased }; NTableBlock[] tableBlocks = new NTableBlock[tablePortDistributionModes.Length]; double margin = 40; double tableSize = 200; double gap = (drawing.ActivePage.Width - margin * 2 - tableSize * 2); double yPos = margin; int portDistributionModeIndex = 0; for (int y = 0; y < 2; y++) { double xPos = margin; for (int x = 0; x < 2; x++) { NShape shape = new NShape(); shape.SetBounds(new NRectangle(xPos, yPos, tableSize, tableSize)); xPos += tableSize + gap; // create table NTableBlock tableBlock = CreateTableBlock(tableDescription[portDistributionModeIndex]); // collect the block to connect it to the center shape tableBlocks[portDistributionModeIndex] = tableBlock; tableBlock.Content.AllowSpacingBetweenCells = false; tableBlock.ResizeMode = ENTableBlockResizeMode.FitToShape; tableBlock.PortsDistributionMode = tablePortDistributionModes[portDistributionModeIndex++]; shape.TextBlock = tableBlock; drawing.ActivePage.Items.AddChild(shape); } yPos += tableSize + gap; } NShape centerShape = new NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle); centerShape.Text = "Table Ports allow you to connect tables to other shapes"; centerShape.TextBlock.FontStyleBold = true; ((NTextBlock)centerShape.TextBlock).VerticalAlignment = ENVerticalAlignment.Center; ((NTextBlock)centerShape.TextBlock).HorizontalAlignment = ENAlign.Center; drawing.ActivePage.Items.AddChild(centerShape); double center = drawing.ActivePage.Width / 2.0; double shapeSize = 100; centerShape.SetBounds(new NRectangle(center - shapeSize / 2.0, center - shapeSize / 2.0, shapeSize, shapeSize)); // get the column port for the first column on the bottom side NTableColumnPort columnPort; if (tableBlocks[0].TryGetColumnPort(0, false, out columnPort)) { Connect(columnPort, centerShape.GetPortByName("Left")); } // get the row port for the second row on the left side NTableRowPort rowPort; if (tableBlocks[1].TryGetRowPort(1, true, out rowPort)) { Connect(rowPort, centerShape.GetPortByName("Top")); } // get the cell port of the first cell on the top side NTableCellPort cellPort; if (tableBlocks[2].TryGetCellPort(0, 0, ENTableCellPortDirection.Top, out cellPort)) { Connect(cellPort, centerShape.GetPortByName("Bottom")); } // get the cell port of the first row on the left side NTableRowPort rowPort1; if (tableBlocks[3].TryGetRowPort(0, true, out rowPort1)) { Connect(rowPort1, centerShape.GetPortByName("Right")); } }
protected override void InitDiagram() { base.InitDiagram(); NPage activePage = m_DrawingDocument.Content.ActivePage; NBasicShapeFactory basicShapes = new NBasicShapeFactory(); int min = 100; int max = 200; NShape shape; Random random = new Random(); for (int i = 0; i < 5; i++) { shape = basicShapes.CreateShape(ENBasicShape.Rectangle); NColor[] shapeLightColors = new NColor[] { new NColor(236, 97, 49), new NColor(247, 150, 56), new NColor(68, 90, 108), new NColor(129, 133, 133), new NColor(255, 165, 109) }; NColor[] shapeDarkColors = new NColor[] { new NColor(246, 176, 152), new NColor(251, 203, 156), new NColor(162, 173, 182), new NColor(192, 194, 194), new NColor(255, 210, 182) }; shape.Geometry.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, shapeLightColors[i], shapeDarkColors[i]); shape.Geometry.Stroke = new NStroke(1, new NColor(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 = ENDockArea.Top; shape.Text = "Top (" + i.ToString() + ")"; break; case 1: shape.LayoutData.DockArea = ENDockArea.Bottom; shape.Text = "Bottom (" + i.ToString() + ")"; break; case 2: shape.LayoutData.DockArea = ENDockArea.Left; shape.Text = "Left (" + i.ToString() + ")"; break; case 3: shape.LayoutData.DockArea = ENDockArea.Right; shape.Text = "Right (" + i.ToString() + ")"; break; case 4: shape.LayoutData.DockArea = ENDockArea.Center; shape.Text = "Center (" + i.ToString() + ")"; break; } //shape.Style.FillStyle = new NColorFillStyle(GetPredefinedColor(i)); shape.SetBounds(new NRectangle(0, 0, width, height)); activePage.Items.Add(shape); } // arrange diagram ArrangeDiagram(); // fit page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
/// <summary> /// Creates the book store interface /// </summary> /// <param name="activePage"></param> void CreateBookStore(NPage activePage) { const double x1 = 50; const double x2 = x1 + 200; const double x3 = x2 + 50; const double x4 = x3 + 400; const double y1 = 50; const double y2 = y1 + 50; const double y3 = y2 + 50; const double y4 = y3 + 20; const double y5 = y4 + 200; const double y6 = y5 + 20; const double y7 = y6 + 50; // prev button NShape prevButtonShape = CreateButtonShape("Show Prev Book"); SetLeftTop(prevButtonShape, new NPoint(x1, y1)); ((NButton)prevButtonShape.Widget).Click += delegate(NEventArgs args) { LoadBook(m_nSelectedBook - 1); }; activePage.Items.Add(prevButtonShape); // next button NShape nextButtonShape = CreateButtonShape("Show Next Book"); SetRightTop(nextButtonShape, new NPoint(x2, y1)); ((NButton)nextButtonShape.Widget).Click += delegate(NEventArgs args) { LoadBook(m_nSelectedBook + 1); }; activePage.Items.Add(nextButtonShape); // add to cart NShape addToCartButton = CreateButtonShape("Add to Cart"); SetRightTop(addToCartButton, new NPoint(x2, y6)); ((NButton)addToCartButton.Widget).Click += delegate(NEventArgs args) { m_ShoppingCart.AddItem(m_Books[m_nSelectedBook], this); }; activePage.Items.Add(addToCartButton); // create selected book shapes NBasicShapeFactory basicShapes = new NBasicShapeFactory(); // selected image m_SelectedBookImage = basicShapes.CreateShape(ENBasicShape.Rectangle); SetLeftTop(m_SelectedBookImage, new NPoint(x1, y2)); NSize minBookSize = GetMinBookImageSize(); m_SelectedBookImage.Width = x2 - x1; m_SelectedBookImage.Height = y5 - y2; activePage.Items.Add(m_SelectedBookImage); // selected title m_SelectedBookTitle = basicShapes.CreateShape(ENBasicShape.Text); m_SelectedBookTitle.TextBlock.InitXForm(ENTextBlockXForm.ShapeBox); m_SelectedBookTitle.TextBlock.FontSize = 25; m_SelectedBookTitle.TextBlock.Fill = new NColorFill(NColor.DarkBlue); SetLeftTop(m_SelectedBookTitle, new NPoint(x3, y2)); m_SelectedBookTitle.Width = x4 - x3; m_SelectedBookTitle.Height = y3 - y2; activePage.Items.Add(m_SelectedBookTitle); // selected description m_SelectedBookDescription = basicShapes.CreateShape(ENBasicShape.Text); m_SelectedBookDescription.TextBlock.InitXForm(ENTextBlockXForm.ShapeBox); SetLeftTop(m_SelectedBookDescription, new NPoint(x3, y4)); m_SelectedBookDescription.Width = x4 - x3; m_SelectedBookDescription.Height = y5 - y4; activePage.Items.Add(m_SelectedBookDescription); // load the first book LoadBook(0); // create the shape that hosts the shopping cart widget NShape shoppingCartShape = new NShape(); shoppingCartShape.Init2DShape(); m_ShoppingCartWidget = new NContentHolder(); m_ShoppingCartWidget.Content = m_ShoppingCart.CreateWidget(this); shoppingCartShape.Widget = m_ShoppingCartWidget; SetLeftTop(shoppingCartShape, new NPoint(x1, y7)); BindSizeToDesiredSize(shoppingCartShape); activePage.Items.Add(shoppingCartShape); }
protected override void InitDiagram() { base.InitDiagram(); NPage activePage = m_DrawingDocument.Content.ActivePage; // we will be using basic shapes with default size of 120, 60 NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); basicShapesFactory.DefaultSize = new NSize(120, 60); // create the president NShape president = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); president.Text = "President"; activePage.Items.Add(president); // create the VPs. // NOTE: The child nodes of the VPs are layed out in cols NShape vpMarketing = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); vpMarketing.Text = "VP Marketing"; vpMarketing.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.Add(vpMarketing); NShape vpSales = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); vpSales.Text = "VP Sales"; vpSales.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.Add(vpSales); NShape vpProduction = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); vpProduction.Text = "VP Production"; vpProduction.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.Add(vpProduction); // connect president with VP NRoutableConnector connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(president); connector.GlueEndToShape(vpMarketing); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(president); connector.GlueEndToShape(vpSales); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(president); connector.GlueEndToShape(vpProduction); // crete the marketing managers NShape marketingManager1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); marketingManager1.Text = "Manager1"; activePage.Items.Add(marketingManager1); NShape marketingManager2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); marketingManager2.Text = "Manager2"; activePage.Items.Add(marketingManager2); // connect the marketing manager with the marketing VP connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpMarketing); connector.GlueEndToShape(marketingManager1); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpMarketing); connector.GlueEndToShape(marketingManager2); // crete the sales managers NShape salesManager1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); salesManager1.Text = "Manager1"; activePage.Items.Add(salesManager1); NShape salesManager2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); salesManager2.Text = "Manager2"; activePage.Items.Add(salesManager2); // connect the sales manager with the sales VP connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpSales); connector.GlueEndToShape(salesManager1); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpSales); connector.GlueEndToShape(salesManager2); // crete the production managers NShape productionManager1 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); productionManager1.Text = "Manager1"; activePage.Items.Add(productionManager1); NShape productionManager2 = basicShapesFactory.CreateShape(ENBasicShape.Rectangle); productionManager2.Text = "Manager2"; activePage.Items.Add(productionManager2); // connect the production manager with the production VP connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpProduction); connector.GlueEndToShape(productionManager1); connector = new NRoutableConnector(); activePage.Items.Add(connector); connector.GlueBeginToShape(vpProduction); connector.GlueEndToShape(productionManager2); // arrange diagram ArrangeDiagram(); // fit active page m_DrawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; }
/// <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 page NPage activePage = m_DrawingDocument.Content.ActivePage; activePage.Items.Clear(); // we will be using basic circle shapes with default size of (30, 30) NBasicShapeFactory basicShapesFactory = new NBasicShapeFactory(); basicShapesFactory.DefaultSize = new NSize(30, 30); NConnectorShapeFactory connectorShapesFactory = new NConnectorShapeFactory(); NShape cur = null, prev = null; NRoutableConnector edge = null; NList <NShape> curRowShapes = null; NList <NShape> prevRowShapes = null; for (int level = 1; level < levels; level++) { curRowShapes = new NList <NShape>(); for (int i = 0; i < level; i++) { cur = basicShapesFactory.CreateShape(ENBasicShape.Circle); cur.Geometry.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(192, 194, 194), new NColor(129, 133, 133)); cur.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); activePage.Items.Add(cur); // connect with prev if (i > 0) { edge = new NRoutableConnector(); edge.MakeLine(); activePage.Items.Add(edge); edge.GlueBeginToShape(prev); edge.GlueEndToShape(cur); } // connect with ancestors if (level > 1) { if (i < prevRowShapes.Count) { edge = new NRoutableConnector(); edge.MakeLine(); activePage.Items.Add(edge); edge.GlueBeginToShape(prevRowShapes[i]); edge.GlueEndToShape(cur); } if (i > 0) { edge = new NRoutableConnector(); edge.MakeLine(); activePage.Items.Add(edge); edge.GlueBeginToShape(prevRowShapes[i - 1]); edge.GlueEndToShape(cur); } } // fix the three corner vertices if (level == 1 || (level == levels - 1 && (i == 0 || i == level - 1))) { NForceDirectedGraphLayout.SetXMoveable(cur, false); NForceDirectedGraphLayout.SetYMoveable(cur, false); cur.Geometry.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant3, new NColor(251, 203, 156), new NColor(247, 150, 56)); cur.Geometry.Stroke = new NStroke(1, new NColor(68, 90, 108)); } curRowShapes.Add(cur); prev = cur; } prevRowShapes = curRowShapes; } // send all edges to back NBatchReorder batchReorder = new NBatchReorder(m_DrawingDocument); batchReorder.Build(activePage.GetShapes(false, NDiagramFilters.ShapeType1D).CastAll <NDiagramItem>()); batchReorder.SendToBack(activePage); // arrange the elements ArrangeDiagram(); }
protected virtual NShape CreateShape() { NBasicShapeFactory factory = new NBasicShapeFactory(); return(factory.CreateShape(ENBasicShape.Rectangle)); }
protected override void InitDiagram() { base.InitDiagram(); m_DrawingDocument.HistoryService.Pause(); try { NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; // Hide grid and ports drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; // create all shapes NBasicShapeFactory factory = new NBasicShapeFactory(); factory.DefaultSize = new NSize(120, 90); int row = 0, col = 0; double cellWidth = 240; double cellHeight = 150; for (int i = 0; i < factory.ShapeCount; i++, col++) { NShape shape = factory.CreateShape(i); shape.HorizontalPlacement = ENHorizontalPlacement.Center; shape.VerticalPlacement = ENVerticalPlacement.Center; shape.Text = factory.GetShapeInfo(i).Name; MoveTextBelowShape(shape); if (i == (int)ENBasicShape.ThreeDBox) { shape.TextBlock.Padding = new NMargins(0, 15, 0, 0); } else if (i == (int)ENBasicShape.Concentric) { shape.TextBlock.Angle = NAngle.Zero; } activePage.Items.Add(shape); if (col >= 4) { row++; col = 0; } NPoint beginPoint = new NPoint(50 + col * cellWidth, 50 + row * cellHeight); if (shape.ShapeType == ENShapeType.Shape1D) { NPoint endPoint = beginPoint + new NPoint(cellWidth - 50, cellHeight - 50); if (i == (int)ENBasicShape.CenterDragCircle) { beginPoint.Translate(cellWidth / 3, cellHeight / 3); endPoint.Translate(-cellWidth / 3, -cellHeight / 3); } shape.SetBeginPoint(beginPoint); shape.SetEndPoint(endPoint); } else { shape.SetBounds(beginPoint.X, beginPoint.Y, shape.Width, shape.Height); } } // size page to content activePage.Layout.ContentPadding = new NMargins(50); activePage.SizeToContent(); } finally { m_DrawingDocument.HistoryService.Resume(); } }
protected override void InitDiagram() { base.InitDiagram(); NDrawing drawing = m_DrawingDocument.Content; NPage activePage = drawing.ActivePage; drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; NBasicShapeFactory basisShapes = new NBasicShapeFactory(); NFlowchartingShapeFactory flowChartingShapes = new NFlowchartingShapeFactory(); NConnectorShapeFactory connectorShapes = new NConnectorShapeFactory(); NShape nonPrintableShape = basisShapes.CreateShape(ENBasicShape.Rectangle); nonPrintableShape.Text = "Non printable shape"; nonPrintableShape.AllowPrint = false; nonPrintableShape.Geometry.Fill = new NColorFill(NColor.Tomato); nonPrintableShape.SetBounds(50, 50, 150, 50); activePage.Items.Add(nonPrintableShape); NShape isLifeGood = flowChartingShapes.CreateShape(ENFlowchartingShape.Decision); isLifeGood.Text = "Is Life Good?"; isLifeGood.SetBounds(300, 50, 150, 100); isLifeGood.Geometry.Fill = new NColorFill(NColor.LightSkyBlue); activePage.Items.Add(isLifeGood); NShape goodShape = flowChartingShapes.CreateShape(ENFlowchartingShape.Termination); goodShape.Text = "Good"; goodShape.SetBounds(200, 200, 100, 100); goodShape.Geometry.Fill = new NColorFill(NColor.Gold); activePage.Items.Add(goodShape); NShape changeSomething = flowChartingShapes.CreateShape(ENFlowchartingShape.Process); changeSomething.Text = "Change Something"; changeSomething.Geometry.Fill = new NColorFill(NColor.Thistle); changeSomething.SetBounds(450, 200, 100, 100); activePage.Items.Add(changeSomething); NShape yesConnector = connectorShapes.CreateShape(ENConnectorShape.RoutableConnector); yesConnector.Text = "Yes"; yesConnector.GlueBeginToPort(isLifeGood.GetPortByName("Left")); yesConnector.GlueEndToPort(goodShape.GetPortByName("Top")); activePage.Items.Add(yesConnector); NShape noConnector = connectorShapes.CreateShape(ENConnectorShape.RoutableConnector); noConnector.Text = "No"; noConnector.GlueBeginToPort(isLifeGood.GetPortByName("Right")); noConnector.GlueEndToPort(changeSomething.GetPortByName("Top")); activePage.Items.Add(noConnector); NShape gobackConnector = connectorShapes.CreateShape(ENConnectorShape.RoutableConnector); gobackConnector.GlueBeginToPort(changeSomething.GetPortByName("Right")); gobackConnector.GlueEndToPort(isLifeGood.GetPortByName("Top")); activePage.Items.Add(gobackConnector); }
private void CreateDiagram(NPage page) { NBasicShapeFactory basisShapes = new NBasicShapeFactory(); NFlowchartingShapeFactory flowChartingShapes = new NFlowchartingShapeFactory(); NConnectorShapeFactory connectorShapes = new NConnectorShapeFactory(); NShape titleShape = basisShapes.CreateShape(ENBasicShape.Rectangle); titleShape.Geometry.Fill = new NColorFill(NColor.LightGray); titleShape.Text = page.Title; titleShape.SetBounds(10, 10, page.Width - 20, 50); page.Items.Add(titleShape); NShape nonPrintableShape = basisShapes.CreateShape(ENBasicShape.Rectangle); nonPrintableShape.Text = "Non printable shape"; nonPrintableShape.AllowPrint = false; nonPrintableShape.Geometry.Fill = new NColorFill(NColor.Tomato); nonPrintableShape.SetBounds(50, 150, 150, 50); page.Items.Add(nonPrintableShape); NShape isLifeGood = flowChartingShapes.CreateShape(ENFlowchartingShape.Decision); isLifeGood.Text = "Is Life Good?"; isLifeGood.SetBounds(300, 150, 150, 100); isLifeGood.Geometry.Fill = new NColorFill(NColor.LightSkyBlue); page.Items.Add(isLifeGood); NShape goodShape = flowChartingShapes.CreateShape(ENFlowchartingShape.Termination); goodShape.Text = "Good"; goodShape.SetBounds(200, 300, 100, 100); goodShape.Geometry.Fill = new NColorFill(NColor.Gold); page.Items.Add(goodShape); NShape changeSomething = flowChartingShapes.CreateShape(ENFlowchartingShape.Process); changeSomething.Text = "Change Something"; changeSomething.Geometry.Fill = new NColorFill(NColor.Thistle); changeSomething.SetBounds(450, 300, 100, 100); page.Items.Add(changeSomething); NShape yesConnector = connectorShapes.CreateShape(ENConnectorShape.RoutableConnector); yesConnector.Text = "Yes"; yesConnector.GlueBeginToPort(isLifeGood.GetPortByName("Left")); yesConnector.GlueEndToPort(goodShape.GetPortByName("Top")); page.Items.Add(yesConnector); NShape noConnector = connectorShapes.CreateShape(ENConnectorShape.RoutableConnector); noConnector.Text = "No"; noConnector.GlueBeginToPort(isLifeGood.GetPortByName("Right")); noConnector.GlueEndToPort(changeSomething.GetPortByName("Top")); page.Items.Add(noConnector); NShape gobackConnector = connectorShapes.CreateShape(ENConnectorShape.RoutableConnector); gobackConnector.GlueBeginToPort(changeSomething.GetPortByName("Right")); gobackConnector.GlueEndToPort(isLifeGood.GetPortByName("Top")); page.Items.Add(gobackConnector); }