private void ConnectShapes(NShape shape1, NShape shape2) { NStep2Connector connector = new NStep2Connector(true); connector.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector); connector.FromShape = shape1; connector.ToShape = shape2; }
private void InitDocument(NDrawingDocument document) { // setup default NDrawingView1.Document. fill style, background style and shadow style Color color1 = Color.FromArgb(225, 232, 232); Color color2 = Color.FromArgb(32, 136, 178); NLightingImageFilter lightingFilter = new NLightingImageFilter(); lightingFilter.SpecularColor = Color.Black; lightingFilter.DiffuseColor = Color.White; lightingFilter.LightSourceType = LightSourceType.Positional; lightingFilter.Position = new NVector3DF(1, 1, 1); lightingFilter.BevelDepth = new NLength(8, NGraphicsUnit.Pixel); document.Style.FillStyle = new NColorFillStyle(color1); document.Style.FillStyle.ImageFiltersStyle.Filters.Add(lightingFilter); document.BackgroundStyle.FillStyle = new NGradientFillStyle(GradientStyle.DiagonalUp, GradientVariant.Variant1, Color.LightBlue, color2); document.Style.ShadowStyle.Type = ShadowType.GaussianBlur; document.Style.ShadowStyle.Offset = new NPointL(5, 5); document.ShadowsZOrder = ShadowsZOrder.BehindDocument; // create title NTextShape title = new NTextShape("Bubble Sort", GetGridCell(0, 1, 2, 1)); title.Style.TextStyle = new NTextStyle(); title.Style.TextStyle.FillStyle = (document.Style.FillStyle.Clone() as NFillStyle); title.Style.TextStyle.ShadowStyle = new NShadowStyle(); title.Style.TextStyle.ShadowStyle.Type = ShadowType.GaussianBlur; title.Style.TextStyle.FontStyle = new NFontStyle(new Font("Arial", 40, FontStyle.Bold)); document.ActiveLayer.AddChild(title); // begin shape NShape shapeBegin = CreateFlowChartingShape(document, FlowChartingShapes.Termination, GetGridCell(0, 0), "BEGIN", ""); // get array item shape NShape shapeGetItem = CreateFlowChartingShape(document, FlowChartingShapes.Data, GetGridCell(1, 0), "Get array item [1...n]", ""); NRotatedBoundsLabel rotatedBoundsLabel = (NRotatedBoundsLabel)shapeGetItem.Labels.DefaultLabel; rotatedBoundsLabel.Margins = new Nevron.Diagram.NMargins(20, 20, 0, 0); // i = 1 shape NShape shapeI1 = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(2, 0), "i = 1", ""); // j = n shape NShape shapeJEN = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(3, 0), "j = n", ""); // less comparison shape NShape shapeLess = CreateFlowChartingShape(document, FlowChartingShapes.Decision, GetGridCell(4, 0), "item[i] < item[j - 1]?", ""); rotatedBoundsLabel = (NRotatedBoundsLabel)shapeLess.Labels.DefaultLabel; rotatedBoundsLabel.Margins = new Nevron.Diagram.NMargins(15, 15, 0, 0); // swap shape NShape shapeSwap = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(4, 1), "Swap item[i] and item[j-1]", ""); // j > i + 1? shape NShape shapeJQ = CreateFlowChartingShape(document, FlowChartingShapes.Decision, GetGridCell(5, 0), "j = (i + 1)?", ""); // dec j shape NShape shapeDecJ = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(5, 1), "j = j - 1", ""); // i > n - 1? shape NShape shapeIQ = CreateFlowChartingShape(document, FlowChartingShapes.Decision, GetGridCell(6, 0), "i = (n - 1)?", ""); // inc i shape NShape shapeIncI = CreateFlowChartingShape(document, FlowChartingShapes.Process, GetGridCell(6, 1), "i = i + 1", ""); // end shape NShape shapeEnd = CreateFlowChartingShape(document, FlowChartingShapes.Termination, GetGridCell(7, 0), "END", ""); // connect begin with get array item NLineShape connector1 = new NLineShape(); connector1.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector1); connector1.FromShape = shapeBegin; connector1.ToShape = shapeGetItem; // connect get array item with i = 1 NLineShape connector2 = new NLineShape(); connector2.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector2); connector2.FromShape = shapeGetItem; connector2.ToShape = shapeI1; // connect i = 1 and j = n NLineShape connector3 = new NLineShape(); connector3.StyleSheetName = NDR.NameConnectorsStyleSheet; connector3.CreateShapeElements(ShapeElementsMask.Ports); connector3.Ports.AddChild(new NLogicalLinePort(connector3.UniqueId, 50)); connector3.Ports.DefaultInwardPortUniqueId = (connector3.Ports.GetChildAt(0) as INDiagramElement).UniqueId; document.ActiveLayer.AddChild(connector3); connector3.FromShape = shapeI1; connector3.ToShape = shapeJEN; // connect j = n and item[i] < item[j-1]? NLineShape connector4 = new NLineShape(); connector4.StyleSheetName = NDR.NameConnectorsStyleSheet; connector4.CreateShapeElements(ShapeElementsMask.Ports); connector4.Ports.AddChild(new NLogicalLinePort(connector4.UniqueId, 50)); connector4.Ports.DefaultInwardPortUniqueId = (connector4.Ports.GetChildAt(0) as INDiagramElement).UniqueId; document.ActiveLayer.AddChild(connector4); connector4.FromShape = shapeJEN; connector4.ToShape = shapeLess; // connect item[i] < item[j-1]? and j = (i + 1)? NLineShape connector5 = new NLineShape(); connector5.StyleSheetName = NDR.NameConnectorsStyleSheet; connector5.Text = "No"; connector5.Style.TextStyle = new NTextStyle(); connector5.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Top; connector5.CreateShapeElements(ShapeElementsMask.Ports); connector5.Ports.AddChild(new NLogicalLinePort(connector5.UniqueId, 50)); connector5.Ports.DefaultInwardPortUniqueId = (connector5.Ports.GetChildAt(0) as INDiagramElement).UniqueId; document.ActiveLayer.AddChild(connector5); connector5.FromShape = shapeLess; connector5.ToShape = shapeJQ; // connect j = (i + 1)? and i = (n - 1)? NLineShape connector6 = new NLineShape(); connector6.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector6); connector6.FromShape = shapeJQ; connector6.ToShape = shapeIQ; // connect i = (n - 1) and END NLineShape connector7 = new NLineShape(); connector7.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector7); connector7.FromShape = shapeIQ; connector7.ToShape = shapeEnd; // connect item[i] < item[j-1]? and Swap NLineShape connector8 = new NLineShape(); connector8.StyleSheetName = NDR.NameConnectorsStyleSheet; connector8.Text = "Yes"; connector8.Style.TextStyle = new NTextStyle(); connector8.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Bottom; document.ActiveLayer.AddChild(connector8); connector8.FromShape = shapeLess; connector8.ToShape = shapeSwap; // connect j = (i + 1)? and j = (j - 1) NLineShape connector9 = new NLineShape(); connector9.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector9); connector9.FromShape = shapeJQ; connector9.ToShape = shapeDecJ; // connect i = (n - 1)? and i = (i + 1) NLineShape connector10 = new NLineShape(); connector10.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector10); connector10.FromShape = shapeIQ; connector10.ToShape = shapeIncI; // connect Swap to No connector NStep2Connector connector11 = new NStep2Connector(true); connector11.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector11); connector11.FromShape = shapeSwap; connector11.ToShape = connector5; // connect i = i + 1 to connector3 NStep3Connector connector12 = new NStep3Connector(false, 50, 60, false); connector12.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector12); connector12.StartPlug.Connect(shapeIncI.Ports.GetChildByName("Right", 0) as NPort); connector12.EndPlug.Connect(connector3.Ports.DefaultInwardPort); // connect j = j - 1 to connector4 NStep3Connector connector13 = new NStep3Connector(false, 50, 30, false); connector13.StyleSheetName = NDR.NameConnectorsStyleSheet; document.ActiveLayer.AddChild(connector13); connector13.StartPlug.Connect(shapeDecJ.Ports.GetChildByName("Right", 0) as NPort); connector13.EndPlug.Connect(connector4.Ports.DefaultInwardPort); }
private void InitDocument() { document.Style.TextStyle = new NTextStyle(new Font("Arial", 9), Color.Black); // modify the connectors style sheet NStyleSheet styleSheet = (document.StyleSheets.GetChildByName(NDR.NameConnectorsStyleSheet, -1) as NStyleSheet); NTextStyle textStyle = new NTextStyle(); textStyle.BackplaneStyle.Visible = true; textStyle.BackplaneStyle.StandardFrameStyle.InnerBorderWidth = new NLength(0); styleSheet.Style.TextStyle = textStyle; styleSheet.Style.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.StartArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.EndArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); // create a stylesheet for the 2D Shapes styleSheet = new NStyleSheet("SHAPE2D"); styleSheet.Style.FillStyle = new NColorFillStyle(Color.PapayaWhip); document.StyleSheets.AddChild(styleSheet); // create a stylesheet for the arrows, which inherits from the connectors stylesheet styleSheet = new NStyleSheet("ARROW", NDR.NameConnectorsStyleSheet); textStyle = new NTextStyle(); textStyle.FontStyle.InitFromFont(new Font("Arial", 8)); styleSheet.Style.TextStyle = textStyle; document.StyleSheets.AddChild(styleSheet); // create shapes NShape shape1 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(150, 50, 50, 50), "1", "SHAPE2D"); NShape shape2 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(150, 150, 50, 50), "2", "SHAPE2D"); NShape shape3 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(325, 150, 50, 50), "3", "SHAPE2D"); NShape shape4 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(50, 250, 50, 50), "4", "SHAPE2D"); NShape shape5 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(250, 250, 50, 50), "5", "SHAPE2D"); NShape shape6 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(400, 250, 50, 50), "6", "SHAPE2D"); NShape shape7 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(250, 350, 50, 50), "7", "SHAPE2D"); NShape shape8 = base.CreateBasicShape(BasicShapes.Rectangle, new NRectangleF(400, 350, 50, 50), "8", "SHAPE2D"); // create connectors NLineShape line = new NLineShape(); line.StyleSheetName = NDR.NameConnectorsStyleSheet; line.Text = "Line"; document.ActiveLayer.AddChild(line); line.StartPlug.Connect(shape1.Ports.GetChildByName("Bottom", 0) as NPort); line.EndPlug.Connect(shape2.Ports.GetChildByName("Top", 0) as NPort); NStep2Connector hv = new NStep2Connector(false); hv.StyleSheetName = NDR.NameConnectorsStyleSheet; hv.Text = "HV"; document.ActiveLayer.AddChild(hv); hv.StartPlug.Connect(shape1.Ports.GetChildByName("Right", 0) as NPort); hv.EndPlug.Connect(shape3.Ports.GetChildByName("Top", 0) as NPort); NStep2Connector vh = new NStep2Connector(true); vh.StyleSheetName = NDR.NameConnectorsStyleSheet; vh.Text = "VH"; document.ActiveLayer.AddChild(vh); vh.StartPlug.Connect(shape4.Ports.GetChildByName("Bottom", 0) as NPort); vh.EndPlug.Connect(shape7.Ports.GetChildByName("Left", 0) as NPort); NStep3Connector vhv = new NStep3Connector(true, 50, 0, true); vhv.StyleSheetName = NDR.NameConnectorsStyleSheet; vhv.Text = "VHV"; document.ActiveLayer.AddChild(vhv); vhv.StartPlug.Connect(shape2.Ports.GetChildByName("Bottom", 0) as NPort); vhv.EndPlug.Connect(shape4.Ports.GetChildByName("Top", 0) as NPort); NStep3Connector hvh = new NStep3Connector(false, 50, 0, true); hvh.StyleSheetName = NDR.NameConnectorsStyleSheet; hvh.Text = "HVH"; document.ActiveLayer.AddChild(hvh); hvh.StartPlug.Connect(shape2.Ports.GetChildByName("Right", 0) as NPort); hvh.EndPlug.Connect(shape5.Ports.GetChildByName("Left", 0) as NPort); NArrowShape doubleArrow = new NArrowShape(ArrowType.DoubleArrow, new NPointF(0, 0), new NPointF(1, 1), 10, 45, 30); doubleArrow.StyleSheetName = "ARROW"; doubleArrow.Text = "Double Arrow"; document.ActiveLayer.AddChild(doubleArrow); doubleArrow.StartPlug.Connect(shape5.Ports.GetChildByName("Right", 0) as NPort); doubleArrow.EndPlug.Connect(shape6.Ports.GetChildByName("Left", 0) as NPort); NArrowShape singleArrow = new NArrowShape(ArrowType.SingleArrow, new NPointF(0, 0), new NPointF(1, 1), 10, 45, 30); singleArrow.StyleSheetName = "ARROW"; singleArrow.Text = "Single Arrow"; document.ActiveLayer.AddChild(singleArrow); singleArrow.StartPlug.Connect(shape7.Ports.GetChildByName("Right", 0) as NPort); singleArrow.EndPlug.Connect(shape8.Ports.GetChildByName("Left", 0) as NPort); NBezierCurveShape bezier = new NBezierCurveShape(); bezier.StyleSheetName = NDR.NameConnectorsStyleSheet; bezier.Text = "Bezier"; bezier.StartPlug.Connect(shape6.Ports.GetChildByName("Right", 0) as NPort); bezier.EndPlug.Connect(shape6.Ports.GetChildByName("Top", 0) as NPort); bezier.Reflex(); }
private void InitDocument() { NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; NDrawingView1.Document.GraphicsSettings.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 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; // create the flowcharting shapes factory NFlowChartingShapesFactory factory = new NFlowChartingShapesFactory(NDrawingView1.Document); // modify the connectors style sheet NStyleSheet styleSheet = (NDrawingView1.Document.StyleSheets.GetChildByName(NDR.NameConnectorsStyleSheet, -1) as NStyleSheet); NTextStyle textStyle = new NTextStyle(); textStyle.BackplaneStyle.Visible = true; textStyle.BackplaneStyle.StandardFrameStyle.InnerBorderWidth = new NLength(0); styleSheet.Style.TextStyle = textStyle; styleSheet.Style.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.StartArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); styleSheet.Style.EndArrowheadStyle.StrokeStyle = new NStrokeStyle(1, Color.Black); // create the begin shape NShape begin = factory.CreateShape((int)FlowChartingShapes.Termination); begin.Bounds = new NRectangleF(100, 100, 100, 100); begin.Text = "BEGIN"; NDrawingView1.Document.ActiveLayer.AddChild(begin); // create the step1 shape NShape step1 = factory.CreateShape((int)FlowChartingShapes.Process); step1.Bounds = new NRectangleF(100, 400, 100, 100); step1.Text = "STEP1"; NDrawingView1.Document.ActiveLayer.AddChild(step1); // connect begin and step1 with bezier link NBezierCurveShape bezier = new NBezierCurveShape(); bezier.StyleSheetName = NDR.NameConnectorsStyleSheet; bezier.Text = "BEZIER"; bezier.SetPointAt(1, new NPointF(100, 300)); bezier.SetPointAt(2, new NPointF(200, 300)); NDrawingView1.Document.ActiveLayer.AddChild(bezier); bezier.FromShape = begin; bezier.ToShape = step1; // create question1 shape NShape question1 = factory.CreateShape((int)FlowChartingShapes.Decision); question1.Bounds = new NRectangleF(300, 400, 100, 100); question1.Text = "QUESTION1"; NDrawingView1.Document.ActiveLayer.AddChild(question1); // connect step1 and question1 with line link NLineShape line = new NLineShape(); line.StyleSheetName = NDR.NameConnectorsStyleSheet; line.Text = "LINE"; NDrawingView1.Document.ActiveLayer.AddChild(line); line.FromShape = step1; line.ToShape = question1; // create the step2 shape NShape step2 = factory.CreateShape((int)FlowChartingShapes.Process); step2.Bounds = new NRectangleF(500, 100, 100, 100); step2.Text = "STEP2"; NDrawingView1.Document.ActiveLayer.AddChild(step2); // connect step2 and question1 with HV link NStep2Connector hv1 = new NStep2Connector(false); hv1.StyleSheetName = NDR.NameConnectorsStyleSheet; hv1.Text = "HV1"; NDrawingView1.Document.ActiveLayer.AddChild(hv1); hv1.FromShape = step2; hv1.ToShape = question1; // connect question1 and step2 and with HV link NStep2Connector hv2 = new NStep2Connector(false); hv2.StyleSheetName = NDR.NameConnectorsStyleSheet; hv2.Text = "HV2"; NDrawingView1.Document.ActiveLayer.AddChild(hv2); hv2.FromShape = question1; hv2.ToShape = step2; // create a self loof as bezier on step2 NBezierCurveShape selfLoop = new NBezierCurveShape(); selfLoop.StyleSheetName = NDR.NameConnectorsStyleSheet; selfLoop.Text = "SELF LOOP"; NDrawingView1.Document.ActiveLayer.AddChild(selfLoop); selfLoop.FromShape = step2; selfLoop.ToShape = step2; selfLoop.Reflex(); // create step3 shape NShape step3 = factory.CreateShape((int)FlowChartingShapes.Process); step3.Bounds = new NRectangleF(700, 600, 100, 100); step3.Text = "STEP3"; NDrawingView1.Document.ActiveLayer.AddChild(step3); // connect question1 and step3 with an HVH link NStep3Connector hvh1 = new NStep3Connector(false, 50, 0, true); hvh1.StyleSheetName = NDR.NameConnectorsStyleSheet; hvh1.Text = "HVH1"; NDrawingView1.Document.ActiveLayer.AddChild(hvh1); hvh1.FromShape = question1; hvh1.ToShape = step3; // create end shape NShape end = factory.CreateShape((int)FlowChartingShapes.Termination); end.Bounds = new NRectangleF(300, 700, 100, 100); end.Text = "END"; NDrawingView1.Document.ActiveLayer.AddChild(end); // connect step3 and end with VH link NStep2Connector vh1 = new NStep2Connector(true); vh1.StyleSheetName = NDR.NameConnectorsStyleSheet; vh1.Text = "VH1"; NDrawingView1.Document.ActiveLayer.AddChild(vh1); vh1.FromShape = step3; vh1.ToShape = end; // connect question1 and end with curve link (uses explicit ports) NRoutableConnector curve = new NRoutableConnector(RoutableConnectorType.DynamicCurve); curve.StyleSheetName = NDR.NameConnectorsStyleSheet; curve.Text = "CURVE"; NDrawingView1.Document.ActiveLayer.AddChild(curve); curve.StartPlug.Connect(question1.Ports.GetChildAt(3) as NPort); curve.EndPlug.Connect(end.Ports.GetChildAt(1) as NPort); curve.InsertPoint(1, new NPointF(500, 600)); // set a shadow to the document. Since styles are inheritable all objects will reuse this shadow NDrawingView1.Document.Style.ShadowStyle = new NShadowStyle( ShadowType.GaussianBlur, Color.Gray, new NPointL(5, 5), 1, new NLength(3)); // shadows must be displayed behind document content NDrawingView1.Document.ShadowsZOrder = ShadowsZOrder.BehindDocument; }
/// <summary> /// Creates a connector between the ports of the specified shapes /// </summary> /// <param name="fromShape"></param> /// <param name="fromPortName"></param> /// <param name="toShape"></param> /// <param name="toPortName"></param> /// <param name="connectorType"></param> /// <param name="text"></param> /// <returns></returns> public NShape CreateConnector(NShape fromShape, string fromPortName, NShape toShape, string toPortName, ConnectorType connectorType, string text) { // check input if (fromShape == null) { throw new ArgumentNullException("fromShape"); } if (toShape == null) { throw new ArgumentNullException("toShape"); } NPort fromPort = (fromShape.Ports.GetChildByName(fromPortName, 0) as NPort); if (fromPort == null) { throw new ArgumentException("Was not able to find fromPortName in the ports collection of the fromShape", "fromPortName"); } NPort toPort = (toShape.Ports.GetChildByName(toPortName, 0) as NPort); if (toPort == null) { throw new ArgumentException("Was not able to find toPortName in the ports collection of the toShape", "toPortName"); } // create the connector NShape connector = null; switch (connectorType) { case ConnectorType.Line: connector = new NLineShape(); break; case ConnectorType.Bezier: connector = new NBezierCurveShape(); break; case ConnectorType.SingleArrow: connector = new NArrowShape(ArrowType.SingleArrow); break; case ConnectorType.DoubleArrow: connector = new NArrowShape(ArrowType.DoubleArrow); break; case ConnectorType.SideToTopBottom: connector = new NStep2Connector(false); break; case ConnectorType.TopBottomToSide: connector = new NStep2Connector(true); break; case ConnectorType.SideToSide: connector = new NStep3Connector(false, 50, 0, true); break; case ConnectorType.TopToBottom: connector = new NStep3Connector(true, 50, 0, true); break; case ConnectorType.DynamicHV: connector = new NRoutableConnector(RoutableConnectorType.DynamicHV); break; case ConnectorType.DynamicPolyline: connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); break; case ConnectorType.DynamicCurve: connector = new NRoutableConnector(RoutableConnectorType.DynamicCurve); break; default: Debug.Assert(false, "New graph connector type?"); break; } // the connector must be added to the document prior to connecting it document.ActiveLayer.AddChild(connector); connector.StartPlug.Connect(fromPort); connector.EndPlug.Connect(toPort); connector.Style.TextStyle = (connector.ComposeTextStyle().Clone() as NTextStyle); connector.Style.TextStyle.Offset = new Nevron.GraphicsCore.NPointL(0, -7); connector.Text = text; return(connector); }
protected void CreateScene() { // configure title NTextShape title = new NTextShape("The Business Company", 0, 0, Document.Width, 60); Document.ActiveLayer.AddChild(title); NTextStyle textStyle = title.ComposeTextStyle().Clone() as NTextStyle; textStyle.FontStyle.InitFromFont(new Font("Arial Black", 22, FontStyle.Bold | FontStyle.Italic)); // set gradient fill style textStyle.FillStyle = new NGradientFillStyle( GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(241, 100, 34), Color.FromArgb(255, 247, 151)); // add shadow textStyle.ShadowStyle = new NShadowStyle( ShadowType.GaussianBlur, Color.FromArgb(50, 122, 122, 122), new Nevron.GraphicsCore.NPointL(5, 5), 1, new NLength(3)); title.Style.TextStyle = textStyle; NPersonalInfo[] personalInfos = NPersonalInfo.CreateCompanyInfo(); // create an Org chart shape for each person in the Org chart NCompositeShape presidentShape = CreateOrgChartShape(personalInfos[0]); NCompositeShape vpMarketingShape = CreateOrgChartShape(personalInfos[1]); NCompositeShape vpSalesShape = CreateOrgChartShape(personalInfos[2]); NCompositeShape vpProductionShape = CreateOrgChartShape(personalInfos[3]); NCompositeShape mm01Shape = CreateOrgChartShape(personalInfos[4]); NCompositeShape mm02Shape = CreateOrgChartShape(personalInfos[5]); NCompositeShape sm01Shape = CreateOrgChartShape(personalInfos[6]); NCompositeShape sm02Shape = CreateOrgChartShape(personalInfos[7]); NCompositeShape pm01Shape = CreateOrgChartShape(personalInfos[8]); NCompositeShape pm02Shape = CreateOrgChartShape(personalInfos[9]); // connect the Org chart shapes // 1. President to VPs NShape ge = null; ge = new NStep3Connector(true, 50, 0, true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(presidentShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(vpMarketingShape.Ports.GetChildByName("Top", 0) as NPort); ge = new NStep3Connector(true, 50, 0, true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(presidentShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(vpSalesShape.Ports.GetChildByName("Top", 0) as NPort); ge = new NStep3Connector(true, 50, 0, true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(presidentShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(vpProductionShape.Ports.GetChildByName("Top", 0) as NPort); // 1. VPs to managers ge = new NStep2Connector(true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(vpMarketingShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(mm01Shape.Ports.GetChildByName("Left", 0) as NPort); ge = new NStep2Connector(true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(vpMarketingShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(mm02Shape.Ports.GetChildByName("Left", 0) as NPort); ge = new NStep2Connector(true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(vpSalesShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(sm01Shape.Ports.GetChildByName("Left", 0) as NPort); ge = new NStep2Connector(true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(vpSalesShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(sm02Shape.Ports.GetChildByName("Left", 0) as NPort); ge = new NStep2Connector(true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(vpProductionShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(pm01Shape.Ports.GetChildByName("Left", 0) as NPort); ge = new NStep2Connector(true); Document.ActiveLayer.AddChild(ge); ge.StartPlug.Connect(vpProductionShape.Ports.GetChildByName("Bottom", 0) as NPort); ge.EndPlug.Connect(pm02Shape.Ports.GetChildByName("Left", 0) as NPort); }
/// <summary> /// Creates a new connector, which connects the specified shapes /// </summary> /// <param name="fromShape"></param> /// <param name="fromPortName"></param> /// <param name="toShape"></param> /// <param name="toPortName"></param> /// <param name="connectorType"></param> /// <param name="text"></param> /// <returns>new 1D shapes</returns> protected NShape CreateConnector(NShape fromShape, string fromPortName, NShape toShape, string toPortName, ConnectorType connectorType, string text) { // check arguments if (fromShape == null) { throw new ArgumentNullException("fromShape"); } if (toShape == null) { throw new ArgumentNullException("toShape"); } NPort fromPort = (fromShape.Ports.GetChildByName(fromPortName, 0) as NPort); if (fromPort == null) { throw new ArgumentException("Was not able to find fromPortName in the ports collection of the fromShape", "fromPortName"); } NPort toPort = (toShape.Ports.GetChildByName(toPortName, 0) as NPort); if (toPort == null) { throw new ArgumentException("Was not able to find toPortName in the ports collection of the toShape", "toPortName"); } // create the connector NShape connector = null; switch (connectorType) { case ConnectorType.Line: connector = new NLineShape(); break; case ConnectorType.Bezier: connector = new NBezierCurveShape(); break; case ConnectorType.SingleArrow: connector = new NArrowShape(ArrowType.SingleArrow); break; case ConnectorType.DoubleArrow: connector = new NArrowShape(ArrowType.DoubleArrow); break; case ConnectorType.SideToTopBottom: connector = new NStep2Connector(false); break; case ConnectorType.TopBottomToSide: connector = new NStep2Connector(true); break; case ConnectorType.SideToSide: connector = new NStep3Connector(false, 50, 0, true); break; case ConnectorType.TopToBottom: connector = new NStep3Connector(true, 50, 0, true); break; case ConnectorType.DynamicHV: connector = new NRoutableConnector(RoutableConnectorType.DynamicHV); break; case ConnectorType.DynamicPolyline: connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline); break; case ConnectorType.DynamicCurve: connector = new NRoutableConnector(RoutableConnectorType.DynamicCurve); break; default: Debug.Assert(false, "New graph connector type?"); break; } // the connector must be added to the document prior to connecting it DrawingView.Document.ActiveLayer.AddChild(connector); // change the default label text connector.Text = text; // connectors by default inherit styles from the connectors stylesheet connector.StyleSheetName = NDR.NameConnectorsStyleSheet; // connect the connector to the specified ports connector.StartPlug.Connect(fromPort); connector.EndPlug.Connect(toPort); // modify the connector text style connector.Style.TextStyle = (connector.ComposeTextStyle().Clone() as NTextStyle); connector.Style.TextStyle.Offset = new NPointL(0, -7); return(connector); }