In This Topic
About Libraries
In NOV Diagram for .NET libraries are represented by the NLibrary element. Libraries are the root element of the NLibraryDocument class, which is typically displayed by an instance of the NLibraryView class. A library is designed to contain multiple library items, that can be dragged and dropped on a drawing view. In this way libraries facilitate the management of reusable drawing clippings. Each library item can contain one or multiple shapes, so it is virtually possible to store any drawing clipping in a reusable library item.
Typically in end-user applications the user needs to be presented with multiple libraries from which to create shapes. The Library Browser UI element facilitates the management of multiple libraries in end-user applications.
Library Items
Libraries contain library items. Library items are represented by the NLibraryItem class. Library items contain reusable drawing clippings that you can drag and drop inside drawing views. The content of a library item are the page items contained inside the NPageItemCollection accessible from the Items property of the library item. Inside the library the library item is rendered as an Image-Text pair. The image is automatically generated by the library item. The text can be assigned by the user by setting the library item Text property. The following example demonstrates how to create a library item:
Create Library Item |
Copy Code
|
NShape shape = new NBasicShapesFactory().CreateShape(ENBasicShapes.Rectangle);
NLibraryItem libraryItem = new NLibraryItem();
libraryItem.Name = "Rectangle";
libraryItem.Text = "Rectangle";
libraryItem.Tooltip = new NTooltip("Drag and drop me onto the drawing");
libraryItem.Items.Add(shape);
|
Libraries and Shape Factories
Shape factories are the most common way to create predefined shapes in code. NOV Diagram includes two shape factories:
- Basic shapes factory - includes commonly used basic shapes like rectangles, triangles, circles, stars and so on.
- Connectors shapes factory - includes commonly used connector shapes.
The following code example demonstrates how to create a rectangle basic shape and a line connector shape:
Create shapes from shape factories |
Copy Code
|
NBasicShapeFactory basicShapes = new NBasicShapeFactory();
NShape rectShape = basicShapes.CreateShape(ENBasicShape.Rectangle);
NConnectorShapeFactory connectorShapes = new NConnectorShapeFactory();
NShape connector = connectorShapes.CreateShape(ENConnectorShape.Line);
|
Shape factories can generate entire libraries that contain a library item for each shape generated by the factory. The following code example demonstrates how to create a library from the basic shapes factory:
Create a library from a shape factory |
Copy Code
|
NBasicShapesFactory basicShapesFactory = new NBasicShapesFactory();
NLibrary library = basicShapesFactory.CreateLibrary();
|
Loading and Using Libraries
The NLibraryDocument class provides the following static methods for loading shape libraries:
-
FromStream - loads a library from a stream.
|
Copy Code
|
string filePath = NPath.Current.Combine("ShapeLibraries", "Business", "Brainstorming Shapes.nlb");
using (Stream stream = File.OpenRead(filePath))
{
NLibraryDocument libraryDocument = NLibraryDocument.FromStream(stream);
}
|
-
FromResource - loads a library from an embedded resource.
|
Copy Code
|
NLibraryDocument libraryDocument = NLibraryDocument.FromResource(Assembly.GetExecutingAssembly(), resourceName);
|
-
FromNevronResource - loads a library from a Nevron resource.
|
Copy Code
|
NLibraryDocument libraryDocument = NLibraryDocument.FromNevronResource(NResources.RBIN_MyShapeLibrary_nlb);
|
-
FromFileAsync - asynchronously loads a library from a file.
|
Copy Code
|
NFile libraryFile = NApplication.ResourcesFolder.GetFile(NPath.Current.Combine(
"ShapeLibraries", "Business", "Brainstorming Shapes.nlb"));
NLibraryDocument.FromFileAsync(libraryFile).Then(
libraryDocument =>
{
// Do something with the library
}
);
|
After the library is loaded, you can easily create shapes with it:
Create a shape from the library |
Copy Code
|
NLibrary library = libraryDocument.Content;
NShape shape = library.CreateShape(0);
drawingView.ActivePage.Items.Add(shape);
|
Nevron Open Vision (NOV) comes with more than 350 predefined shape libraries (NLB files). They are placed in the "Resources\ShapeLibraries" sub folder of the Nevron Open Vision installation. For more information open the Predefined Libraries topic.
Libraries View Type
Libraries are designed to be displayed in several view types, which are enumerated by the ENLibraryViewType enumeration, that currently contains the following values:
The view type of a library is controlled by the ViewType property that accepts a value from the ENLibraryViewType enumeration. For each view type the library contains a specific settings object, that is derived from the NLibraryItemsView abstract class. The following table summarizes the library view settings objects for each specific type of view:
View Type |
Class |
Accessible via Property |
Description |
Icons |
NIconsLibraryItemsView
|
IconsItemsView
|
Controls the settings of the Icons items view. By default the preview size is set to 32x32 dips. |
List |
NListLibraryItemsView
|
ListItemsView
|
Controls the settings of the List items view. By default the preview size is set to 16x16 dips. |
Thumbnails |
NThumbnailsLibraryItemsView
|
ThumbnailsItemsView
|
Controls the settings of the Thumbnails items view. By default the preview size is set to 64x64 dips. |
In this way you can adjust the settings for a specific library view type, by altering the properties of the respective view type settings object. The following code example instructs the library to display the previews in Icons view in 24x24 size and specifies the custom horizontal and vertical spacing between the items:
Changing the settings for a specific library view type |
Copy Code
|
library.ViewType = ENLibraryViewType.Icons;
library.IconsItemsView.PreviewSize = new NSize(24, 24);
library.IconsItemsView.HorizontalSpacing = 5;
library.IconsItemsView.VerticalSpacing = 10;
|
Library Display Order
By default libraries are displaying their items in the order in which they are defined (added to the library). It is in many cases useful to order the items by their name, so that the user can search for a specific shape by name more quickly. The library display order is controlled the LibraryDisplayOrder property that accepts value from the ENLibraryDisplayOrder enumeration. The following code example displays the items inside a library by their name ascending order:
Changing the library display order |
Copy Code
|
library.DisplayOrder = ENLibraryDisplayOrder.NameAscending;
|
See Also