Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Load multiple objects on to Canvas once loading (Read 2567 times)
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Load multiple objects on to Canvas once loading
Apr 24th, 2017 at 3:26am
Print Post  
I have a requirement to load few objects to the canvas once this Layout window open.

For an example

I want to Load

5 Rectangles
3 circles
2 triangles

to the canvas once this is loading how can I do that , Actually I want to do this in programming level, not the way like following .

create XML file then populate that XML file
« Last Edit: Apr 24th, 2017 at 5:55am by kelum »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Load multiple objects on to Canvas once loading
Reply #1 - Apr 24th, 2017 at 6:55am
Print Post  
You can create an instance of respective node type and add it to Diagram.Nodes collection, or call shortcut methods provided by Diagram.Factory -

Code
Select All
var node1 = new ShapeNode();
node1.Bounds = new Rect(100, 100, 60, 60);
node1.Shape = Shapes.Rectangle;
diagram.Nodes.Add(node1);

var node2 = diagram.Factory.CreateShapeNode(
	100, 200, 60, 60, Shapes.Ellipse); 

  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Load multiple objects on to Canvas once loading
Reply #2 - Apr 24th, 2017 at 5:38pm
Print Post  
is it possible to load these Nodes like following shapes in programming level

1. Linear 



2. Zig-Zag 



3. U shape


  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Load multiple objects on to Canvas once loading
Reply #3 - Apr 24th, 2017 at 6:02pm
Print Post  
Yes, calculate X,Y and RotationAngle values from the value of an integer loop counter depending on the scenario -

Code
Select All
for (int i = 0; i < 5; i++)
{
	diagram.Factory.CreateShapeNode(
		100 + i * 80, 100, 60, 30, Shapes.Rectangle);
}

for (int i = 0; i < 5; i++)
{
	var node = diagram.Factory.CreateShapeNode(
		100 + i * 60, 200, 60, 30, Shapes.Rectangle);
	node.RotationAngle = 45;
} 



Try doing 3 as an exercise, you'll just need three separate loops for each side of the U and special handling for the corner nodes (at index count/3 and 2*count/3).
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: Load multiple objects on to Canvas once loading
Reply #4 - Apr 25th, 2017 at 9:01am
Print Post  
is it possible to allow to create these node that aligning  with Straight Line or U Line. ?

1. Straight Line




2. U line



Here the scenarios I'm trying to populate these node

1. Top of the Straight Line, Create Nodes After each Inch, Left to Right

2. Bottom of the Straight Line, Create Nodes After each Inch, Left to Right

3. Inside the U shape, create nodes,

    from bottom line of the U shape,  bottom line center to left, then bottom line center to right,
    then left line of the U shape, bottom to up
    then right line of the U shape, bottom to up

4. Outside the U shape, create nodes,

    from bottom line of the U shape,  bottom line center to left, then bottom line center to right,
    then left line of the U shape, bottom to up
    then right line of the U shape, bottom to up
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Load multiple objects on to Canvas once loading
Reply #5 - Apr 25th, 2017 at 10:55am
Print Post  
Use this method to create nodes along a line segment, call it three times for the U shape specifying corresponding end points as arguments -

Code
Select All
void CreateNodesAlongSegment(
	double x1, double y1, double x2, double y2,
	double nodeDist, double nodeWidth, double nodeHeight)
{
	double dx = x2 - x1;
	double dy = y2 - y1;
	double segmentLen = Math.Sqrt(dx * dx + dy * dy);

	// normalize direction vector
	dx /= segmentLen;
	dy /= segmentLen;

	for (double offset = 0; offset < segmentLen; offset += nodeDist)
	{
		double nodeCenterX = x1 + dx * offset;
		double nodeCenterY = y1 + dy * offset;
		diagram.Factory.CreateShapeNode(
			nodeCenterX - nodeWidth / 2, nodeCenterY - nodeHeight / 2, nodeWidth, nodeHeight);
	}
} 



It will also work for inclined lines.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint