This project has moved and is read-only. For the latest updates, please go here.

How to use NShape as a presentation framework for your existing project.

Jun 29, 2012 at 2:29 AM

Hello all, I am new to NShape and I have been wondering if there is a tutorial on using NShape to extend an existing project or class so that the shapes would represent and have the class properties and behaviours. I would be grateful for a simple step by step guidelines to implement this. I am thinking of using NShape as a property of the class and not the core of the class itself. Thanks. 

Jun 29, 2012 at 2:33 PM

I think what you are looking for is the IModelObject interface in conjunction with PropertyMappings/ModelMappings.

Please have a look at the "ModelMapping Demo" project shipped with NShape (open it with "NShape Designer"):

  • Double click model item "Model 1" on the left. A shape will be selected.
  • Select Tab "Model" in the property area on the right. You will see the properties of "Model 1"
  • Change the value of property "FloatValue" and when applying the change, the shape will display the model's FloatValue as Text.

Behind the scenes, a property mapping links the ModelObject's property value to a property of the shape.
You can change this property mapping in the template designer (right-click the red Ellipse in the tool box, select "Edit", switch to "Model Visualization" tab).
IModelObject is a general interface which you can implement in your classes. The NShape framework is able to interact with the IModelObject interface.

There is also some documantation concerning "Shape and Model", "IModelObject", "PropertyMapping" / "ModelMapping", etc.

If this is what you are looking for, we can provide you additional instructions on the usage.

Jun 30, 2012 at 6:44 PM

Yes, this seems exactly what I am looking for. I will be very happy for guidance on how to do this. I also want to be able to create and destroy instances of my classes with the creation and deletion of shapes on a diagram. 

Jul 2, 2012 at 4:22 PM
Edited Jul 3, 2012 at 11:04 AM

I've made a sample program that shows the required minimum you have to code in order to use model mappings. The demo does not deal with loading/saving in order to keep it simple.

Things to do:

  • Implement IModelObject interface in your business objects (at least some of its methods). See "MyBusinessObject" in the sample
  • Write a NShapeLibraryInitializer (see sample implementation and documentation on details) for registering your model objects
  • Create or modify a template that uses model mappings (or create/assign the mappings with code as shown in the sample)

An email containing the download link is on the way. Please have a look on the sample and if you have more questions, feel free to ask.

Jul 6, 2012 at 8:03 AM
Thanks KurtHolzinger. This is exactly what I need. I am studying the code and will try to implement it in vb.net. Thanks very much and I really appreciate it.


Jul 30, 2012 at 10:17 PM

I'm looking to do something very similar to this and was wondering if I can see this sample program as well so I can understand how to tie the presentation layer to my business objects.

Jul 31, 2012 at 8:09 AM

I've added the sample to the download section.

Jul 31, 2012 at 6:24 PM

Perfect! Thanks so much!