This example shows the annotation shapes created by the NAnnotationShapeFactory.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.Expressions;
using Nevron.Nov.Diagram.Shapes;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NAnnotationShapesExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// Create a simple drawing
NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
drawingViewWithRibbon.GetRibbon().Tab.Expanded = false;
m_DrawingView = drawingViewWithRibbon.View;
m_DrawingView.Document.HistoryService.Pause();
try
{
InitDiagram(m_DrawingView.Document);
}
finally
{
m_DrawingView.Document.HistoryService.Resume();
}
return drawingViewWithRibbon;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"This example shows the annotation shapes created by the NAnnotationShapeFactory.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Predefined Libraries", "https://www.nevron.com/docs/openvision/diagram-predefined-libraries.html"),
("Libraries", "https://www.nevron.com/docs/openvision/diagram-libraries.html"),
("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"),
("Library Browser", "https://www.nevron.com/docs/openvision/diagram-library-browser.html"),
};
}
private void InitDiagram(NDrawingDocument drawingDocument)
{
NDrawing drawing = drawingDocument.Content;
NPage activePage = drawing.ActivePage;
activePage.ZoomMode = ENZoomMode.Fit;
// Hide grid and ports
drawing.ScreenVisibility.ShowGrid = false;
drawing.ScreenVisibility.ShowPorts = false;
// Create all shapes from the factory
NAnnotationShapeFactory factory = new NAnnotationShapeFactory(60, 60);
bool is1D = false;
int row = 0, col = 0;
double cellWidth = 0;
double cellHeight = 260;
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(shape.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 = shape.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();
}
private void MoveTextBelowShape(NShape shape)
{
if (shape.ShapeType == ENShapeType.Shape2D)
{
shape.MoveTextBlockBelowShape();
return;
}
// if the shape is 1D put the text block on the left part of the shape and rotate it on 90 degrees.
NTextBlock textBlock = shape.GetTextBlock();
textBlock.Padding = new NMargins(5, 0, 0, 0);
textBlock.ResizeMode = ENTextBlockResizeMode.TextSize;
textBlock.PinX = shape.BeginX;
textBlock.SetFx(NTextBlock.PinYProperty, new NShapeHeightFactorFx(0));
textBlock.LocPinY = 0;
textBlock.Angle = new NAngle(90);
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
private NDrawingView m_DrawingView;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}