Profile Picture

Custom shape with Dictionary data type

Posted By Thai Binh 3 Years Ago
Author
Message
Thai Binh
Question Posted 3 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 1, Visits: 42
Hi Nevron support team,

I want to use Diagram .Net to design a software for layouting factory/manufactory floor so I just download Nevron .Net for evalution. After installing, i see Nevron Diagram has a good basic shapes library, very handy GUI. But beside basic shapes, i want to draw rectangular shapes with a custom property. Here i want to draw a custom shape with Dictionary data type. After working around with questions in forum and look at sample code NPersistencyManagerUC in Serializion folder, i find no the same question like me. So i want to ask you that is it possible to draw a custom shape (rectangle and rounded rectangle) by mouse with a custom property of Dictionary data type?
 Like this:
Dictionary<string, NPointF[]> m_Points;

I want to save this property of custom shape along with drawing document to drawing file. Is it possible to implement  such task? And does Diagram support data type editor for Dictionary type?

Thank you so much,

Thai Binh





Nevron Support
Posted 3 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,000
Hello,

We recommend you try our new diagramming component NOV Diagram. It contains more features and is a cross platform solution, which makes it easy to target multiple platforms like Windows (WinForms and WPF), Mac (Xamarin.Mac) and in the near future the web (Blazor WebAssembly) from single codebase.

Regarding your request - with NOV Diagram you can easily make any class serializable and attach an instance of it to the Tag property of the shape. It will then get properly serialized and deserialized.

For example, the following is a serializable NOV map (dictionary) with string keys and NPoint values:

public class PointMap : NMap<string, NPoint>,
    INDomCustomSerializable,
    INDomDeeplyCloneable
{
#region Constructors

public PointMap()
{
}
public PointMap(PointMap source)
: base(source)
{
}

#endregion

#region INDomCustomSerializable

public void Serialize(NDomSerializationContext context, NPropertyBag propertyBag)
{
    string[] keyArray = new string[Count];
    double[] xArray = new double[Count];
    double[] yArray = new double[Count];

    int index = 0;
    var iter = GetIterator();

    while (iter.MoveNext())
    {
        string key = iter.Current.Key;
        NPoint point = iter.Current.Value;

        keyArray[index] = key;
        xArray[index] = point.X;
        yArray[index] = point.Y;
        index++;
    }

    propertyBag.SetStringArrayValue(KeyArrayName, keyArray);
    propertyBag.SetDoubleArrayValue(XArrayName, xArray);
    propertyBag.SetDoubleArrayValue(YArrayName, yArray);
}
public void Deserialize(NDomDeserializationContext context, NPropertyBag propertyBag)
{
    string[] keyArray = propertyBag.GetStringArray(KeyArrayName);
    double[] xArray = propertyBag.GetDoubleArray(XArrayName);
    double[] yArray = propertyBag.GetDoubleArray(YArrayName);
   
    Clear();
    for (int i = 0; i < keyArray.Length; i++)
    {
        Add(keyArray[i], new NPoint(xArray[i], yArray[i]));
    }
}

#endregion

#region INDomDeeplyCloneable

public object DeepClone(NDomDeepCopyContext context)
{
    return new PointMap(this);
}

#endregion

#region Constant

private const string KeyArrayName = "K";
private const string XArrayName = "X";
private const string YArrayName = "Y";

#endregion
}


You can then create and attach an instance of that class to the Tag property of a shape:

NBasicShapeFactory factory = new NBasicShapeFactory();
NShape shape = factory.CreateShape(ENBasicShape.Rectangle);
shape.SetPinPoint(new NPoint(200, 200));

PointMap pointMap = new PointMap();
pointMap.Add("Point 1", new NPoint(0, 0));
pointMap.Add("Point 2", new NPoint(100, 100));
shape.Tag = pointMap;


And then when you save and load your drawing, the Tag property of the shape will be preserved, because it is an instance of a class that implements the INDomCustomSerializable interface:


drawingView.SaveToFile(@"C\test.ndb");
drawingView.Document = new NDrawingDocument();
drawingView.LoadFromFile(@"C:\test.ndb");


Please download and install NOV Diagram and try the code above. Let us know if you have any questions.



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic