Profile Picture

Connecting Shapes When Objects are not yet attached to the document

Posted By Ted O'Grady 13 Years Ago

Connecting Shapes When Objects are not yet attached to the document

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,

Regarding your questions:
- If you want to connect shapes, they should be placed in a drawing document together with the connector prior to setting the FromShape and ToShape properties of the connector.
- A shape cannot be added to a drawing document multiple times. However if you want to duplicate a gievn shape, you can do so by cloning it with a new unique ID like this:

Hashtable hash = new Hashtable();

document.ActiveLayer.AddChild((NGroup)shape.CloneWithNewUniqueId(hash));



Best Regards,
Nevron Support Team



Ted O'Grady
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 12, Visits: 1
Sorry,

I meant to ask, is there any way to build these connections without using registering all the objects on the document?

If it is not possible, what happens if I add a shape to the document multiple times?

For us, when we put these two responsibilities together it really complicates the code.

- ted

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,

You got it right. Prior to connecting any shapes with a connector, both the shapes and the conector should be added to a drawing document.



Best Regards,
Nevron Support Team



Ted O'Grady
sad Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)

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");
}

}
}



Similar Topics


Reading This Topic