Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic custom diagram link lost headshape? (Read 4404 times)
darby
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: May 26th, 2011
custom diagram link lost headshape?
Nov 4th, 2011 at 6:06am
Print Post  
I have some custom classes.
- ScenarioLink : DiagramLink
- ScenarioNode : TemplatedNode
- ScenarioDiagram : Diagram
- ScenarioDiagramBehavior : DrawLinksBehavior

And, ScenarioLink have ArrowHeads.Triangle for HeadShape
this is defined of ScenarioLink class
Code
Select All
public class ScenarioLink : DiagramLink
{
    public ScenarioLinkId LinkId { get; set; }
    public ScenarioLink(Diagram parent)
	  : base(parent)
    {
	  InitLink();
    }
    public ScenarioLink(Diagram parent, DiagramNode origin, DiagramNode dest)
	  : base(parent, origin, dest)
    {
	  InitLink();
    }

    private void InitLink()
    {

    }

    public override DiagramItem Clone(bool clipboard)
    {
	  var link = new ScenarioLink(this.Parent, this.Origin, this.Destination)
		{ Text = this.Text, SegmentCount = 3, AutoRoute = true, HeadShape = ArrowHeads.Triangle };
	  return link;
    }
    protected override void SaveToXml(System.Xml.XmlElement xmlElement, XmlPersistContext context)
    {
	  base.SaveToXml(xmlElement, context);
	  context.WriteString(LinkId.Value, "LinkId", xmlElement);
    }
    protected override void LoadFromXml(System.Xml.XmlElement xmlElement, XmlPersistContext context)
    {
	  base.LoadFromXml(xmlElement, context);
	  LinkId = new ScenarioLinkId(new Guid(context.ReadString("LinkId", xmlElement)));

    }
    protected override void OnAdd()
    {
	  base.OnAdd();
	  LinkId = new ScenarioLinkId();

    }

}
 


and this is properties for diagram
Code
Select All
<vm:ScenarioDiagram x:Name="diagram" AlignToGrid="true" BorderThickness="5" AllowLinksRepeat="True"
BorderBrush="Black" ShapeBrush="LightBlue" BackBrush="#FFDCDCFF" ShowGrid="true" AllowInplaceEdit="true"
SnapToAnchor="OnCreate" Behavior="Custom" LinkCascadeOrientation="Horizontal" LinkHeadShape="Triangle"
DynamicLinks="True" CrossingRadius="90"
LinkCrossings="Straight" RouteLinks="True" LinkRouter="GridRouter" Bounds="0,0,1000,500"
AllowDrop="True" />
 



When I loaded custom diagram after using my custom classes, scenariolink hasn't any headshape.
so, I captured SaveToXml and LoadFromXml methods using debug mode.
And, I found that HeadShape property assigned null after base.LoadFromXml inside my override method, LoadFromXml, is executed.
But previous value was "Triangle", before base.LoadFromXml~ method's execution.
Below is my code..
Code
Select All
protected override void LoadFromXml(System.Xml.XmlElement xmlElement, XmlPersistContext context)
{
    base.LoadFromXml(xmlElement, context);
    LinkId = new ScenarioLinkId(new Guid(context.ReadString("LinkId", xmlElement)));

}
 



How can I solve this problem?????
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom diagram link lost headshape?
Reply #1 - Nov 4th, 2011 at 7:09am
Print Post  
We have this code in the LoadFromXml method:

Code
Select All
if (context.ClassVersion > 1)
{
	baseShape = context.ReadShape("BaseShape", xmlElement, ArrowHeads.None);
	intermediateShape = context.ReadShape("IntermediateShape", xmlElement, ArrowHeads.None);
	headShape = context.ReadShape("HeadShape", xmlElement, ArrowHeads.None);
}
else
{
	headShape = ArrowHeads.HeadShapeFromOldId(context.ReadInt("HeadShape", xmlElement));
	baseShape = ArrowHeads.HeadShapeFromOldId(context.ReadInt("BaseShape", xmlElement));
	intermediateShape = ArrowHeads.HeadShapeFromOldId(context.ReadInt("IntermediateShape", xmlElement));
} 



so you will have to specify at least 2 for the version-id  value when calling RegisterItemClass in order for the link to load shape identifiers by the new format.

It seems we should change the versioning implementation to let you use your own version numbers independent from those of the base classes. The largest version we have at this time is 4 for ContainerNode, so for now you could probably use some larger version identifiers (say starting from 100) to be on the safe side.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
darby
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: May 26th, 2011
Re: custom diagram link lost headshape?
Reply #2 - Nov 4th, 2011 at 8:01am
Print Post  
Hello Stoyo

it works

thanks a lot~~
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint