Profile Picture

Connections not persisting while deserializing

Posted By Pramod Sreekanthan 13 Years Ago
Author
Message
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

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



Pramod Sreekanthan
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)Junior Member (17 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 17, Visits: 1

Hi,

I am using Nevron diagramming tool. Iam saving the layer as a stream and loading it back.

The diagram comes fine with all components and connections present.

But, the connections are not persisted and all the components get disconnected.

Please reply soon, its a very critical issue.

Thanks,

Pramod





Similar Topics


Reading This Topic