Group: Forum Members
Last Active: 11 Years Ago
Posts: 12,
Visits: 1
|
I am putting together complex shape as groups and/or composites. In the end I add the composites and groups to the document.
Inside the components, I am trying to connect two shapes with a NRoutableConnector, before I have added the shapes to the documents. Is there anyway to accomplish this?
We have separated the complexity of building and relating the complex shapes from the actual adding of these shapes to the document.
Thanks,
- ted
Here are simple example tests showing what we want, vs how it works:
#region
using System; using Drawing.Surface; using Nevron.Diagram; using NUnit.Framework;
#endregion
namespace DrawingTest { [TestFixture] public class ConnectionBuilderTest { private void AddConnectionPorts(NShape shape) { var created = shape.CreateShapeElements(ShapeElementsMask.Ports); if (!created) { throw new ApplicationException("Failed to create ports"); }
shape.Ports.RemoveAllChildren();
var outwardPort = new NLogicalLinePort(shape.UniqueId, 30); outwardPort.Type = PortType.Outward; shape.Ports.AddChild(outwardPort); shape.Ports.DefaultOutwardPortUniqueId = outwardPort.UniqueId;
var inwardPort = new NLogicalLinePort(shape.UniqueId, 30); shape.Ports.AddChild(inwardPort); shape.Ports.DefaultInwardPortUniqueId = inwardPort.UniqueId; }
[Test] public void TestFromAndToShape_ConnectTwoRectangles_NotAddedToDocument_WouldBeNice() { var source = new NRectangleShape(0, 0, 100, 100); var dest = new NRectangleShape(0, 0, 100, 100);
AddConnectionPorts(source); AddConnectionPorts(dest);
var line = new NRoutableConnector();
// execute line.ToShape = dest; line.FromShape = source;
// Assert Assert.AreEqual(source, line.FromShape, "Source"); Assert.AreEqual(dest, line.ToShape, "Dest"); }
[Test] public void TestFromAndToShape_ConnectTwoRectangles_AddedToDocument_CurrentRequiredBehaviour() { var doc = new NDrawingDocument(); //Nevron requires a document to be able to connect shapes. var source = new NRectangleShape(0, 0, 100, 100); var dest = new NRectangleShape(0, 0, 100, 100);
doc.ActiveLayer.AddChild(source); doc.ActiveLayer.AddChild(dest);
AddConnectionPorts(source); AddConnectionPorts(dest);
var line = new NRoutableConnector();
doc.ActiveLayer.AddChild(line);
// execute line.ToShape = dest; line.FromShape = source;
// Assert Assert.AreEqual(source, line.FromShape, "Source"); Assert.AreEqual(dest, line.ToShape, "Dest"); }
} }
|