NShape Concepts
Understanding Shape Creation

<< Click to Display Table of Contents >>

Navigation:  Concepts > Shapes >

NShape Concepts
Understanding Shape Creation

Previous pageReturn to chapter overviewNext page

There are a few different cases where a shape gets to be created.

a)When the user creates a shape from the toolbox, a template-based shape is created. It has no private styles but holds a reference to a template that defines the look of the shape.
b)When loading a diagram from a repository, empty shapes are created that do not possess any references and are not workable until the loading is finished.
c)When copying a shape, we need a clone, which is obtained by first creating an empty shape and then taking over the properties from the source shape.
d)When creating a template shape or another self-contained shape not needing a template, the its required styles must be fetched from a style set provider.

In order to realize these different cases, the Shape class supports the following methods:

a)A standard constructor used to create an empty shape. Empty shapes are not functional and must be initialized through one of the initialization functions.
b)A constructor with a style set provider parameter used to create self-contained shapes.
c)Initialization functions for loading a shape from a repository: LoadFields, LoadInnerObjects and additional properties and methods to set required references.
d)An initialization function for copying called CopyFrom.
e)An initialization function for self-contained shapes called: InitializeToDefault.

However, the application will rarely use these functions directly. Referring to the above cases, it usually will

a)Use the ShapeType.CreateInstance method with the template parameter to create a templated shape. The collection of available shape types is provided by the Project instance.
b)Use the repository functions (for example GetDiagram) to create and load shapes.
c)Use Shape.Clone to create a copy of a shape.
d)Use the ShapeType.CreateInstance method without parameter to create a self-contained shape. Alternatively the application might also use the corresponding constructor.

Scenarios

The user always creates shapes from templates by dragging the template onto a diagram. Internally the shape creation process goes like this:

1.The framework uses the CreateInstance method of the template shape's shape type to create a new shape of the same class. The template parameter of the CreateInstance method is set to the selected template.
2.The framework calls the CopyFrom method of the new shape to copy all properties of the template shape to the new shape.
3.The framework continues inserting the new shape.