GoXmlBindingTransformer

I’m trying to modify the example on p 155 in GoUserGuide - WinForms to read and write xml in format listed below.

The modified code for RegisterTransformers() is also enclosed.

two problems:

  • nodes and port show up as I want them to, but no lines.
  • Also when I save the xml (after first reading the original below) from and to attribs in line tag are null…

XML

<?xml version="1.0" encoding="utf-8" ?>
























modified RegisterTransformers():

private void RegisterTransformersModified(GoXmlReaderWriterBase rw)
{
// create a prototype document
GoDocument doc = new GoDocument();
GoXmlBindingTransformer bt = new GoXmlBindingTransformer(“graph”, doc);
rw.AddTransformer(bt);

        //rw.AddTransformer(new GoDiagramTransformNode());
        // create a prototype node 
        GoGeneralNode bn = new GoGeneralNode();
        bn.Initialize(null, @"./NetModels/App.ico", "", "", 0, 0);

        GoXmlBindingTransformer bt1 = new GoXmlBindingTransformer("node", bn);
        // generates attributes for all named ports, to define their id's 
        // without generating separate elements for them 
        bt1.GeneratesPortsAsChildElements = true;
        bt1.BodyConsumesChildElements = true;
        // map the "label" attribute to the GoBasicNode.Text property 
        bt1.AddBinding("label", "Text");
        bt1.AddBinding("psid", "PartID");
        bt1.AddBinding("color", "Shape.BrushColor");
        bt1.AddBinding("loc", "Location");
        rw.AddTransformer(bt1);

        GoGeneralNodePort gnp = bn.MakePort(true);
        GoXmlBindingTransformer bt3 = new GoXmlBindingTransformer("GoPort", gnp);
        bt3.AddBinding("id", "PartID"); 
        bt3.AddBinding("left", "LeftSide");
        bt3.AddBinding("name", "Name");
        rw.AddTransformer(bt3);

        // create a prototype link 
        GoLabeledLink ll = new GoLabeledLink();
        ll.ToArrow = true;
        GoXmlBindingTransformer bt2 = new GoXmlBindingTransformer("line", ll);
        // the "from" attribute will be a reference to the 
        // GoLabeledLink.FromPort object 
        bt2.AddBinding("plid", "PartID");
        bt2.AddBinding("from", "FromPort");
        bt2.AddBinding("to", "ToPort");
        // the "label" value is the GoLabeledLink.MidLabel.Text property 
        bt2.AddBinding("label", "MidLabel.Text");
        rw.AddTransformer(bt2);

    }

ok, let me pull your code into a sample and take a look.

You need



bt3.IdAttributeUsedForSharedObjects = true;



and





GoText lab = new GoText();

lab.Selectable = false;

ll.MidLabel = lab;

Voilà!

Thanx a bunch! Cool

But some strange behaviour still. If I change the line:
from: bt3.AddBinding(“id”, “PartID”);
to: bt3.AddBinding(“portid”, “PartID”);

and the attribs in the xml accordingly; the lines are gone again…

And when saving the drawing with lines (using bt3.AddBinding(“id”, “PartID”); ) I get an Xml-exception: {"‘id’ is a duplicate attribute name."}

Here’s the code for saving:
GoXmlWriter writer = new GoXmlWriter();

RegisterTransformersPromapsSimple(writer);

writer.Objects = document; //goView1.Document; the one displaying the graph in the first place.
using (StreamWriter writeFile = new StreamWriter(@“c:\junk” + new Random().NextDouble().ToString() + “.xml”))
writer.Generate(writeFile);

oh, sorry… I forgot I made that change to portid to avoid the duplicate “id”.



The ids generated and used by XML don’t have anything to do with the PartIDs.

Using the same basic approach as before, but have changed the Node class
to a subclass of GoGeneralNode. This node basically draws a circle and
has support for 12 ports (GoPort) spread evenly around the circle. So
far so good.
In the Graph def (node tag in XML file in previous post) which I’m
reading to render my diagram, I’ve introduced an attrib;
ActivePorts=“0,1,3”. This should tell the node to only enable port 0,1
and 3 (out of the potential 0…11). I’ve implemented a public prop to
handle this but it does not work as expected:

the following line added to RegsiterTransf method:
bt1.AddBinding(“ActivePorts”, “PortsActive”);

property in node class:

public string PortsActive
{
set
{
string[] activePorts = value.Split(’,’);
int[] activePortsIndexes = new int[activePorts.Length];

            for (int j = 0; j < activePorts.Length; j++)
                activePortsIndexes[j] = int.Parse(activePorts[j]);

            for (int i = 0; i < activePortsIndexes.Length; i++ )
            {
                _ports[activePortsIndexes<em>].IsValidFrom = true;
                _ports[activePortsIndexes<em>].IsValidTo = true;
                _ports[activePortsIndexes<em>].BrushColor = Color.WhiteSmoke;
                _ports[activePortsIndexes<em>].FillShadedGradient(Color.Blue);
                _ports[activePortsIndexes<em>].IsValidDuplicateLinks = true;

            }
        }
    }

Some formatting problems in pasting above code: should be _ports[activePortsIndexes(i)] // () replaced by []

The problem is, the first node does not get affected by the setting of the property. Node 3 in the xml gets affectd by the settings from node 2 and so on.

Maybe GoXmlBindingTransfer is not to be used in such a case? Or more likely, there’s is something i’ve overlooked…

Am I starting out in the right direction with GoGeneralNode? As I said I want 12 ports distributed, and need to dynamically enabled/disabled them upon reading XML-def file. Also I need to programmatically change color in three traffic light in the senter if so and so status occurs in the application. See figure below for quick and dirty node model…

Can you give me a full example of the XML for the node and ports?



I can’t think of any way that the settings could get out of sync on which node they were for…