Hi Pramod,
When only portions of the drawing such as shapes and layers are stored, the connections between them are lost, since they are kept globally for each drawing in the drawing document ConnectionContainer.
To persist a layer or a set of shapes together with their connections you need to persist a drawing data object, which will generally records the connections between the elements that are present in the drawing clipping and properly restore them when the data object is inserted in another or the same drawing.
The following code sample demonstrates the approach:
// create a simple diagram with two shapes and one connector
NBasicShapesFactory shapeFactory = new NBasicShapesFactory(document);
NShape fromShape = shapeFactory.CreateShape(BasicShapes.Rectangle);
fromShape.SetBounds(new NRectangleF(10, 10, 100, 100));
document.ActiveLayer.AddChild(fromShape);
NShape toShape = shapeFactory.CreateShape(BasicShapes.Rectangle);
toShape.SetBounds(new NRectangleF(310, 310, 100, 100));
document.ActiveLayer.AddChild(toShape);
NRoutableConnector connector = new NRoutableConnector();
document.ActiveLayer.AddChild(connector);
connector.FromShape = fromShape;
connector.ToShape = toShape;
// create a drawing data object from the document active layer
NDrawingDataObject drawingDataObject = new NDrawingDataObject(document, new INDiagramElement[] { document.ActiveLayer });
// make a section for the data object in the persistency manager
NPersistencyManager persistencyManager = new NPersistencyManager();
persistencyManager.PersistentDocument.Sections.Add(new NPersistentSection("ddo", drawingDataObject));
// save the persistend document to a memory stream
MemoryStream ms = new MemoryStream();
persistencyManager.SaveToStream(ms, Nevron.Serialization.PersistencyFormat.Binary, null);
// remove all layers
view.Document = new NDrawingDocument();
document = view.Document;
document.Layers.RemoveAllChildren();
// now load the persistent document from the memory stream
persistencyManager = new NPersistencyManager();
ms.Seek(0, SeekOrigin.Begin);
persistencyManager.LoadFromStream(ms, Nevron.Serialization.PersistencyFormat.Binary, null);
// restore the data object (which contains a layer) in the document Layers collection
NDrawingDataObject restoredDDO = (NDrawingDataObject)persistencyManager.PersistentDocument.Sections[0].Object;
restoredDDO.AddInComposite(document, document.Layers);
document.ActiveLayerUniqueId = ((NLayer)document.Layers.GetChildAt(0)).UniqueId;
Best Regards,
Nevron Support Team