Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Noob questions ... (Read 3234 times)
Florida
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Mar 18th, 2021
Noob questions ...
Mar 18th, 2021 at 5:05am
Print Post  
I am a noob in Mindfusion diagram control.  I am not sure which type of node that I need to start with as my base node for inheriting:  compositenode or shapenode (or other type?).

I need specific shapes:  upside down double lined triangles, double lined circles, double lined squares.  Each shape has specific ENTER and EXIT ports on either side.  I need specific properties stored within each object that are pulled from a database.

The real challenge is:  I must be able to save to a memory stream (as a BLOB or XML storage inside the SQL Server).

How can I do this using Mindfusion Diagram? 

I have went through the samples and read through Help and watched some tutorials.  I have a test project put together but it is not saving and loading the diagram - I am using simple ShapeNodes. It saves and loads but the lines and objects are messed up or not there anymore.

Other requirements:  finding all connected nodes entering and exiting each node.  Searching all node connections and pulling path mappings from source to destination nodes.

I need to get a test example working before we buy the license so does anyone have a suggestion on how to best approach this implementation?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Noob questions ...
Reply #1 - Mar 18th, 2021 at 6:16am
Print Post  
Quote:
I am not sure which type of node that I need to start with as my base node for inheriting: compositenode or shapenode (or other type?). I need specific shapes: upside down double lined triangles, double lined circles, double lined squares.


It sounds like you want ShapeNodes. This code will make them double-lined (e.g. add it to Anchor Points sample project) -

Code
Select All
var doubleLine = new MindFusion.Drawing.Pen(Color.Red, 3);
doubleLine.CompoundArray = new float[] { 0f, 0.3f, 0.7f, 1f };
pb1.Pen = doubleLine;
 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Noob questions ...
Reply #2 - Mar 18th, 2021 at 6:30am
Print Post  
Quote:
I need specific properties stored within each object that are pulled from a database. The real challenge is:  I must be able to save to a memory stream (as a BLOB or XML storage inside the SQL Server). How can I do this using Mindfusion Diagram? 


First consider storing just database records' ID in nodes' Id or Tag property. If you need all record values stored in node, you could create struct for them -

Code
Select All
[Serializable]
class ExtraProps
{
	public string Prop1 { get; set; };
	public int Props2 { get; set; };
	...
} 



and assign its instances to Tag or Id properties. That's shown e.g. in SiteMap sample project. Tag/Id struct is serialized automatically in binary format. If you need it saved in XML, you will need to handle Diagram.SerializeTag event handler.

Otherwise if you need your properties directly in node class, then you can follow approach from IconNodes example -

Code
Select All
public class IconNode : DiagramNode
{
	protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext ctx)
	{
		base.SaveTo(writer, ctx);

		// Save the label using the standard .NET BinaryWriter
		writer.Write(label);

		// Save the image using the MindFusion.Diagramming built-in image saving code,
		// which stores the contents of shared images only once.
		ctx.SaveImage(icon);
	}

	protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext ctx)
	{
		base.LoadFrom(reader, ctx);

		label = reader.ReadString();
		icon = ctx.LoadImage();
	}

	Image icon;
	string label;
}

// Enable serialization of IconNode instances
Diagram.RegisterItemClass(typeof(IconNode), "IconNode", 100);
 

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


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Noob questions ...
Reply #3 - Mar 18th, 2021 at 6:33am
Print Post  
Either way you should be able to save the result of diagram.SaveToString in a TEXT/BLOB field, and restore it back by calling diagram.LoadFromString. E.g. you could play with that in Anchor Points examle replacing the file serialization with strings -

Code
Select All
String blob;

private void button1_Click(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(blob))
        diagram.LoadFromString(blob);
    //if (ofd.ShowDialog() == DialogResult.OK)
    //{
    //    try
    //    {
    //        diagram.LoadFromFile(ofd.FileName);
    //    }
    //    catch (Exception ex)
    //    {
    //        MessageBox.Show(ex.Message);
    //    }
    //}
}

private void button2_Click(object sender, EventArgs e)
{
    blob = diagram.SaveToString();
    //if (sfd.ShowDialog() == DialogResult.OK)
    //{
    //    diagram.SaveToFile(sfd.FileName, true);
    //}
} 

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


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Noob questions ...
Reply #4 - Mar 18th, 2021 at 6:41am
Print Post  
Quote:
I have a test project put together but it is not saving and loading the diagram - I am using simple ShapeNodes. It saves and loads but the lines and objects are messed up or not there anymore.


If you already use custom types, make sure you call the RegisterItemClass method. If it's still not working, please attach the test project.

Quote:
Other requirements: finding all connected nodes entering and exiting each node. Searching all node connections and pulling path mappings from source to destination nodes.


You can find connected nodes through OutgoingLinks and IncomingLinks collections -

Code
Select All
using System.Linq;
var exitingNodes = node.OutgoingLinks.
    Select(l => l.Destination); 



See the PathFinder class for finding paths.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Florida
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Mar 18th, 2021
Re: Noob questions ...
Reply #5 - Mar 18th, 2021 at 3:21pm
Print Post  
A ton of answers ... thank you!!!  I am going through and following each of the posts and changing my code.  And just to clarify ...

I should NOT use a composite node (I thought those node types gave more functionality to the ports and port tracking)?  I should use inherited DiagramNode (not shapenode)- which will give me all layout functionality and port tracking?

I can store in either XML or binary (BLOB).  I can just as easily use the tag and set the custom properties, or even do a general string parsing as the database information is all numeric and string types.  I just want to store in the most complete and stable format - for Mindfusion product, I am not sure which format is the recommended  Wink Wink

Thank you everyone ... I am definitely making progress.  I am re-writing my SAVE/LOAD.  If it still does not work correctly then I will post a VS project or my direct code.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Noob questions ...
Reply #6 - Mar 18th, 2021 at 4:23pm
Print Post  
Quote:
I should NOT use a composite node (I thought those node types gave more functionality to the ports and port tracking)?


Ports (AnchorPattern/Point objects) are defined through base DiagramNode. CompositeNode vs ShapeNode is mostly a matter of node's contents - since you only need to display geometric shapes, ShapeNode should be enough.

Quote:
I should use inherited DiagramNode (not shapenode)- which will give me all layout functionality and port tracking?


You should derive from ShapeNode to inherit shape drawing. That DiagramNode example was only to show the serialization methods (coming from IconNodes sample project where it's not drawing shapes).

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint