Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to use the ShapeNode designed in Shape-Designer in own code? (Read 5713 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to use the ShapeNode designed in Shape-Designer in own code?
Dec 5th, 2014 at 9:01am
Print Post  
how to use the ShapeNode designed in Shape-Designer in own code and can I inherit the one of the shapes ?
thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #1 - Dec 5th, 2014 at 9:14am
Print Post  
You can save your shapes to a shape library xml file, load it using ShapeLibrary.LoadFromXml method and then assign the custom shapes to nodes by setting ShapeNode.Shape = Shape.FromId(...);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #2 - Dec 8th, 2014 at 5:30am
Print Post  
hi Stoyan,
     I find that if a ues the Node by ShapeLibrary.LoadFromXml method, how can I set some Anchor Points on my mind ?
can I inherit some defeat shapes?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #3 - Dec 8th, 2014 at 11:09am
Print Post  
Hi,

We have a Shape.AnchorPattern property in some versions of the control that let you associate anchor points directly with shapes, but it's not available yet in WPF. For time being you could implement your own association, e.g. using a shape-id to AnchorPattern dictionary, and set node.AnchorPattern when node.Shape is set to one with known id from the the dictionary.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #4 - Dec 9th, 2014 at 1:45am
Print Post  
hi Stoyan,
  I don't clearly know How to implement the Shape With my own AnchorPattern-points. Could you Show me the way more detailed. and I have attached my project.
  Thanks very much ! Smiley
  

EvSwitch_001.rar (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #5 - Dec 10th, 2014 at 9:01am
Print Post  
Hi,

If you will be creating custom types for different shapes as you have an EvRectangle node, you could set base.AnchorPattern in their constructors and don't change it anymore:

Code
Select All
public EvRectangle()
{
	AnchorPattern = AnchorPattern.Decision2In2Out;
	....
} 



For ordinary ShapeNodes you could keep a dictionary mapping shape to anchor pattern identifiers and set node.AnchorPattern from NodeCreated:

Code
Select All
private void OnNodeCreated(object sender, NodeEventArgs e)
{
	var node = e.Node as EvBaseNode;
	var shapeNode = e.Node as ShapeNode;

	if (node != null)
	{
		...
	}
	else if (shapeNode != null)
	{
		if (shapeAnchorPoints.ContainsKey(shapeNode.Shape.Id))
		{
			var anchorPointsId = shapeAnchorPoints[shapeNode.Shape.Id];
			shapeNode.AnchorPattern = AnchorPattern.FromId(anchorPointsId);
		}
	}
}

Dictionary<string, string> shapeAnchorPoints = new Dictionary<string, string> {
	{ "Rectangle", "LeftInRightOut" },
	{ "Decision", "Decision1In3Out" }
}; 



We'll try to port the Shape.AnchorPattern property from our WinForms control for next release.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #6 - Dec 11th, 2014 at 2:54am
Print Post  
hi Stoyan,
Thanks for you help, I can solve the problem on your way.
but I think the AnchorPattern.Regist method is necessary.
because the defeat AnchorPattern-points is so poor.
so I defined like this:
Code
Select All
 public class EvDefaultNodeAnchorPoint
    {
        private Dictionary<string, string> shapeAnchorPoints = new Dictionary<string, string>
        {
            {"Ellipse", "Decision4In4Out"},
            {"RSave", "Decision4In4Out"},
            {"Rectangle", "Decision4In4Out"},
            {"Alternative", "Decision4In4Out"},
            {"Arrow7", "Decision4In4Out"},
            {"Cloud", "Decision4In4Out"},
            {"ConeDown", "Decision4In4Out"},
            {"ConnectedIssues", "Decision4In4Out"},
            {"CreateRequest", "Decision4In4Out"},
            {"Cross", "Decision4In4Out"},
            {"Cylinder", "Decision4In4Out"},
            {"Database", "Decision4In4Out"},
            {"DataTransmition", "Decision4In4Out"},
            {"DividedEvent", "Decision4In4Out"},
            {"Octagon", "Decision4In4Out"}
        };

        public Dictionary<string, string> ShapeAnchorPoints
        {
            get { return shapeAnchorPoints; }
        }

        private AnchorPattern decision4In4Out =
            new AnchorPattern(new AnchorPoint[]
            {
                new AnchorPoint(50, 0, true, true, MarkStyle.None),
                new AnchorPoint(0, 50, true, true, MarkStyle.None),
                new AnchorPoint(50, 100, true, true, MarkStyle.None),
                new AnchorPoint(100, 50, true, true, MarkStyle.None)
            });

        public AnchorPattern Decision4In4Out
        {
            get { return decision4In4Out; }
        }
    }
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #7 - Dec 11th, 2014 at 8:42am
Print Post  
Hi,

You could pass the "Decision4In4Out" id to AnchorPattern constructor and that isntance will be automatically registered and later returned by AnchorPattern.FromId.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #8 - Jan 9th, 2015 at 3:09pm
Print Post  
This version adds Shape.AnchorPattern property:
https://mindfusion.eu/_beta/wpfdiag.3.2.1.zip

Once you assign your anchor pattern to shapes, you won't have to set nodes' own AnchorPattern anymore. I.e. when node.AnchorPattern is null, the control will automatically use node.Shape.AnchorPattern instead.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use the ShapeNode designed in Shape-Designer in own code?
Reply #9 - Jan 27th, 2015 at 1:34am
Print Post  
Thanks Stoyan, I will try in my code.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint