/// <summary> /// Binds the size of the shape to the embedded widget desired size. /// </summary> /// <param name="shape"></param> private void BindSizeToDesiredSize(NShape shape) { NWidget widget = shape.Widget; // bind shape width to button desired width NBindingFx bx = new NBindingFx(widget, NButton.DesiredWidthProperty); bx.Guard = true; shape.SetFx(NShape.WidthProperty, bx); // bind shape height to button desired height NBindingFx by = new NBindingFx(widget, NButton.DesiredHeightProperty); by.Guard = true; shape.SetFx(NShape.HeightProperty, by); shape.AllowResizeX = false; shape.AllowRotate = false; shape.AllowResizeY = false; }
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 NAnnotationShapeFactory factory = new NAnnotationShapeFactory(); factory.DefaultSize = new NSize(60, 60); int row = 0, col = 0; double cellWidth = 0; // 180; double cellHeight = 150; bool is1D = false; for (int i = 0; i < factory.ShapeCount; i++, col++) { NShape shape = factory.CreateShape(i); NShape tempShape; shape.HorizontalPlacement = ENHorizontalPlacement.Center; shape.VerticalPlacement = ENVerticalPlacement.Center; if (i == (int)ENAnnotationShape.Text || i == (int)ENAnnotationShape.FiveRuledColumn || i == (int)ENAnnotationShape.InfoLine || i == (int)ENAnnotationShape.NorthArrow5 || i == (int)ENAnnotationShape.NoteSymbol || i == (int)ENAnnotationShape.ReferenceTriangle || i == (int)ENAnnotationShape.ReferenceRectangle || i == (int)ENAnnotationShape.ReferenceHexagon || i == (int)ENAnnotationShape.ReferenceCircle || i == (int)ENAnnotationShape.ReferenceOval) { NGroup group = new NGroup(); group.Width = shape.Width; group.Height = shape.Height; if (i == (int)ENAnnotationShape.Text) { shape.PinX = 0; shape.SetFx(NShape.PinYProperty, "Height"); } else { shape.SetFx(NShape.PinXProperty, "Width / 2"); shape.SetFx(NShape.PinYProperty, "Height / 2"); } group.TextBlock = new NTextBlock(factory.GetShapeInfo(i).Name); shape.SetFx(NShape.WidthProperty, "$ParentSheet.Width"); shape.SetFx(NShape.HeightProperty, "$ParentSheet.Height"); MoveTextBelowShape(group); group.Shapes.Add(shape); activePage.Items.Add(group); tempShape = group; } else { if (i != (int)ENAnnotationShape.Benchmark) { shape.Text = factory.GetShapeInfo(i).Name; MoveTextBelowShape(shape); if (i == (int)ENAnnotationShape.ReferenceCallout1) { shape.TextBlock.PinX = 40; shape.TextBlock.PinY = 10; } if (i == (int)ENAnnotationShape.ReferenceCallout2) { shape.TextBlock.Angle = new NAngle(0); shape.TextBlock.PinY = 100; } } activePage.Items.Add(shape); tempShape = shape; } if (col >= 5) { row++; col = 0; cellWidth = 0; is1D = false; } int widthGap = is1D ? 150 : 100; is1D = shape.ShapeType == ENShapeType.Shape1D; NPoint beginPoint = new NPoint(widthGap + cellWidth, 50 + row * cellHeight); if (is1D) { NPoint endPoint = beginPoint + new NPoint(0, cellHeight - 60); if (i == (int)ENAnnotationShape.ReferenceCallout1 || i == (int)ENAnnotationShape.ReferenceCallout2) { tempShape.SetBeginPoint(beginPoint); tempShape.SetEndPoint(endPoint); } else { tempShape.SetBeginPoint(endPoint); tempShape.SetEndPoint(beginPoint); } } else { tempShape.SetBounds(beginPoint.X, beginPoint.Y, shape.Width, shape.Height); } cellWidth += widthGap + tempShape.Width; } // size page to content activePage.Layout.ContentPadding = new NMargins(40); activePage.SizeToContent(); } finally { m_DrawingDocument.HistoryService.Resume(); } }
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 NEpcShapeFactory factory = new NEpcShapeFactory(); factory.DefaultSize = new NSize(80, 60); int row = 0, col = 0; double cellWidth = 180; double cellHeight = 120; for (int i = 0; i < factory.ShapeCount; i++, col++) { NShape shape = factory.CreateShape(i); NShape tempShape; shape.HorizontalPlacement = ENHorizontalPlacement.Center; shape.VerticalPlacement = ENVerticalPlacement.Center; if (i == (int)ENEpcShape.AND || i == (int)ENEpcShape.OR || i == (int)ENEpcShape.XOR) { NGroup group = new NGroup(); group.Width = shape.Width; group.Height = shape.Height; group.Shapes.Add(shape); group.TextBlock = new NTextBlock(factory.GetShapeInfo(i).Name); shape.SetFx(NShape.PinXProperty, "Width / 2"); shape.SetFx(NShape.PinYProperty, "Height / 2"); shape.SetFx(NShape.WidthProperty, "$ParentSheet.Width"); shape.SetFx(NShape.HeightProperty, "$ParentSheet.Height"); MoveTextBelowShape(group); activePage.Items.Add(group); tempShape = group; } else { shape.Text = factory.GetShapeInfo(i).Name; if (i == (int)ENEpcShape.InformationMaterial) { shape.TextBlock.Fill = new NColorFill(NColor.Black); } MoveTextBelowShape(shape); activePage.Items.Add(shape); tempShape = 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 - 100, cellHeight - 100); tempShape.SetBeginPoint(beginPoint); tempShape.SetEndPoint(endPoint); } else { tempShape.SetBounds(beginPoint.X, beginPoint.Y, shape.Width, shape.Height); } } // size page to content activePage.Layout.ContentPadding = new NMargins(40); activePage.SizeToContent(); } finally { m_DrawingDocument.HistoryService.Resume(); } }