GoToolCreating Issue

Hi Im using GoDiagrams version 4.1

I want the user to click on a toolbar button and then when the mouse is clicked on the goview object, I want to paste/add the node (CollapsingRecordNode) to the document.
Im tring to use the GoToolCreating for the same.
The problem is that the node does not retain the width and the header/node text is a little misaligned.

How do I fix the width and the text alignment (By default the width of this node is set to 130)?

If you have a CollapsingRecordNode in your GoView, and you copy/paste it, does that work?

I havent tried that
Will try it out and let you know.
It worked when I did not use GoCreatingTool.
Meaning, On a toolbar button click added a node to the top left corner of GoView.
If it helps Im using the same code to create the node in both cases.

It works if I call Document.AddCopy

OK… what was the creation code that was having problems then?

Here is the code I’m using:

public void AddCreatingTool(string name, string type, int ordinal, int id)

CollapsingStateNode proto = CreateProtoType(name, type, ordinal, id);
GoToolCreating ctool = new GoToolCreating(goView1);
ctool.Prototype = proto;
ctool.Modal = true;
ctool.OneShot = true;
goView1.Tool = ctool;
private CollapsingStateNode CreateProtoType(string name, string type, int ordinal, int id) { CollapsingStateNode sNode = new CollapsingStateNode(name, type); sNode.NodeOrder = ordinal; sNode.ItemWidth = 130; //commented out since using the create tool //sNode.Location = new PointF(0, goView1.DocExtent.Y); sNode.PartID = id; ((GoPort)sNode.List.Header.Ports.Last).IsValidFrom = false; ((GoPort)sNode.List.Header.Ports.First).IsValidFrom = false; return sNode; }

CollapsingStateNode is the customized version of CollapsingRecordNode (has few more properties).

Well, it’s possible the properties you’ve added require you to override CopyObject… or more likely CopyChildren.

Try your CreateTool with the stock CollapsingRecordNode… it that works (it should) and your node doesn’t, that’s probably the problem. Look at how other sample classes implement CopyChildren.

I modified the DrawDemo project to only paste CollapsingRecordNode when using CreateTool and still see the same issue.
Code from MainForm.cs (DrawDemo) that was edited:

private static GoObject GetDropObjectFromPaletteObject(GoObject proto) {
//GoIconicNode ic = proto as GoIconicNode;
//if (ic != null) {
// GoShape shape = ic.Icon.Copy() as GoShape;
// shape.Size = new SizeF(shape.Size.Width * 3, shape.Size.Height * 3);
// shape.Selectable = true;
// shape.Shadowed = false;
// shape.Resizable = true;
// shape.Reshapable = true;
// shape.ResizesRealtime = true;
// proto = shape;
proto = new CollapsingRecordNode();
return proto;

Resulting diagram:

You need to initialize CRN…

  CollapsingRecordNode info9 = new CollapsingRecordNode();
  info9.Text = "CollapsingRecordNode";

Now… Initialize here is “create a sample node”, but you need to add some parts to it.

OK Yeah after Init it worked fine for CRN.

Still didn’t work for me, so I created a new Creating tool inheriting from GoCreatTool.
In DoMouseUp() I set the itemwidth after Document.AddCopy and this worked for me.

Note that Initialize sets ItemWidth too.

Have another question relating to this:

Is there a way to avoid the above behavior (before the nodeDrop event)?

You’re dragging State1 from a GoPalette? And you want the height to be the same while dragging and after the drop?

How do you create / initialize State1? What do you do on the drop?

Hmmm … there is a reply, I somehow did not get a notification for this post.

No im not dragging state1, I have a tool bar which when pressed in, creates this state.

I have customized GoToolCreating:

public class CGToolCreating : GoToolCreating
public delegate void NodeDropped(CollapsingStateNode node, string type);
private NodeDropped mNodeDropped;
public event NodeDropped NodeDroppedEvent
mNodeDropped += value;
mNodeDropped -= value;
public CGToolCreating (GoView view) : base(view)

    public override void DoMouseUp()
        Prototype.Location = this.LastInput.DocPoint;
        if (!IsBeyondDragSize() && this.View.Document.IsUnoccupied(this.Prototype.Bounds, null))
            CollapsingStateNode node = this.View.Document.AddCopy(this.Prototype, this.Prototype.Location) as CollapsingStateNode;
            if (node != null)
                node.ItemWidth = 160;
            this.TransactionResult = "inserted object";
            if (mNodeDropped != null)
                mNodeDropped(node, node.StateType);
            if (this.OneShot)

    public void StopStamping()

I really don’t know why it gets sized that way before the drop.

However, GoToolCreating is for a mouse-down-drag-to-size-mouse-up operation.

I think the rubber stamp (ClickCreateTool in DrawDemo) is probably a better choice as a starting point (although you may want to add the “one shot” feature).