GoDiagram trial rookie seeking advice on approach

I’ve been looking at your excellent sample programs and trying to quickly find out where to “dig deeper” into this API and object model.

The drawing in the InstrumentDemo project, specifically that represented on the “Factory” tab, seems close to what I am hoping to achieve.

Is there an example somewhere where a drawing like this gets built according to some data?

        factoryLayer.Identifier = "Factory"
        Dim tank1 As Tank = New Tank()
        tank1.Bounds = New RectangleF(120, 50, 70, 100)
        tank1.Value = 900<span ="Apple-tab-span" style="white-space:pre">							</span>'something more data-driven here ?
        factoryLayer.Add(tank1)

I would like to have 2 visible “hot spots” in a tank object (one near each end of the cylinder). I would like to know how to have a click or double-click event on one of these “hot spots” result in a new “window” or “large tooltip” with some associated data shown in this new “object” something like this:

                  keyword-X: value of X
                  keyword-Y: value of Y

If someone could point me in the next best direction for the scenario above it would help me a lot.

GoDiagram supports XML, for save/load. InstrumentDemo doesn’t show that, but if you search the samples for GoXmlBindingTransformer, you’ll find lots of samples.

Now… if you were talking about data binding in real time of the indicator Value to some external input, you’ll have to do that in your code.

re: hot spots. I’m assuming these are visible hot spots? You can create whatever graphic your need (a GoImage, a GoEllipse…), .Add then to the node, and then place the objects in the LayoutChildren method.

the easiest way to handle the click is probably through a small subclass.

like this:

public Tank() {
  this.Orientation = Orientation.Vertical;
  Initialize(null, null, "Tank");
  this.Editable = true;
  this.Label.Editable = true;
  this.Label.BackgroundColor = Color.White;
  this.Label.TransparentBackground = false;
  this.Label.AddObserver(this);

ClickSpot spot = new ClickSpot();
spot.BrushColor = Color.Red;
spot.Size = new SizeF(10, 10);
spot.Selectable = false;
this.Add(spot);
this.AddChildName(“spot”, spot);
}

at the end of LayoutChildren:

GoObject spot = this.FindChild(“spot”);
if (spot != null) spot.Location = this.Icon.Location;

and the ClickSpot class:

[Serializable]
public class ClickSpot : GoEllipse {

public override bool OnSingleClick(GoInputEventArgs evt, GoView view) {

  MessageBox.Show("Click!");

  return true;
}

}

all together, that will give you a clickable red spot at the top left of Tank.

Tooltip support is built-in, and would be easier than all that, as long as you just wanted a standard Windows tooltip.

Let me know if that isn’t clear or if I missed something…

Hi Jake,

I translated your C# suggestions into VB.Net code and got the single click event handler to show a message box with “click” as you sketched.

I would like to add more info to the MessageBox content - here is the current code with my “notes” commented out:

Namespace InstrumentDemo
<Serializable()>
Public Class ClickSpot
<span =“Apple-tab-span” style=“white-space:pre”> Inherits GoEllipse
Public Sub New()
End Sub
Public Overrides Function OnSingleClick(ByVal evt As GoInputEventArgs, ByVal view As GoView) As Boolean
MessageBox.Show(“Click!”)
'Dim Message As String = “How do I find values for this tank from here? Cancel this operation?”
'Dim Caption As String = “Tank n value display”
'Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo


'Dim Result As DialogResult


''Displays the MessageBox


'Result = MessageBox.Show(Message, Caption, Buttons)
'Return Result
Return True
End Function
End Class
End Namespace
I would like to know how to access the various properties of the Tank that is the containing parent of this ClickSpot. Specifically, how to access:

  • Name of the tank (for the caption of the MessageBox)
  • .Value property of the tank (for the message part of MessageBox)
Your documentation is pretty great and I feel sheepish having to ask for this help but if you have time I'd appreciate it (c# syntax is ok too)

Check the ellipse.Parent property… should be the Tank.

Sorry - still not clear. At a breakpoint in the OnSingleClick function in ClickSpot (as shown above), I see that the parent of ClickSpot is indeed a Tank:

?Me.Parent
{CBMI.InstrumentDemo.InstrumentDemo.Tank}
CBMI.InstrumentDemo.InstrumentDemo.Tank: {CBMI.InstrumentDemo.InstrumentDemo.Tank}

…but what is the syntax I need here in the OnSingleClick function to get at the current properties of the tank (set earlier as here):

<span =“Apple-tab-span” style=“white-space:pre”> tank1.Text = “Tank ID xxxxx”
tank1.ToolTipText = “a big frigging gas tank…”
tank1.Value = 900

I know there are 4 tanks instantiated in the layer and the objects are known as tank1 tank2, etc. But I would like to give them a label or a name property. Something like tank1.Name = “Vessel BZ49W” (i.e. some identifier that could be set from a database.

tank1.Text appears accepted but then seems to be overwritten at runtime with the changing value
tank1.Label appears to want another object GoTextNode which looks possible but way more than I want. I just want some sort of string ID for an object (i.e. a “tank”) and then I want to know how to access it from the OnSingleClick function of the ClickSpot child of the tank.

I should have mentioned ParentNode as well…

Tank tank = e.GoObject.ParentNode as Tank;

or

Dim tank As Tank = TryCast(e.GoObject.ParentNode, Tank )
<pre id=“code-result” =“brush:vbnet”="" style=“margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb46, 46, 46; line-height: normal; “>should give you the specific instance of the tank that was clicked on.<pre id=“code-result” =“brush:vbnet”=”” style=“margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb46, 46, 46; line-height: normal; “>
<pre id=“code-result” =“brush:vbnet”=”” style=“margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb46, 46, 46; line-height: normal; “>If you want a field where you can store an ID, try tank.UserObject. <pre id=“code-result” =“brush:vbnet”=”” style=“margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb46, 46, 46; line-height: normal; “>Look at how DataSetDemo uses UserObject to hold the DataSet Row in ObjectDoubleClicked.<pre id=“code-result” =“brush:vbnet”=”” style=“margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb46, 46, 46; line-height: normal; “>
<pre id=“code-result” =“brush:vbnet”=”” style=“margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb46, 46, 46; line-height: normal; “>
<pre id=“code-result” =“brush:vbnet”=”” style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb46, 46, 46; line-height: normal; ">tank1.Label is going to be a GoText object, not a GoTextNode. tank1.Text should be the text in that Label.

Still not clear. First attempt (case 1 error)

Namespace InstrumentDemo
<Serializable()> Public Class ClickSpot
Inherits GoEllipse
Public Sub New()
End Sub


Public Overrides Function OnSingleClick(ByVal evt As GoInputEventArgs, ByVal view As GoView) As Boolean
Dim clickedTank As Tank = TryCast(evt.GoObject.ParentNode, Tank)

Second attempt (case 2 error)

Namespace InstrumentDemo
<Serializable()> Public Class ClickSpot
Inherits GoEllipse
Public Sub New()
End Sub


Public Overrides Function OnSingleClick(ByVal evt As GoInputEventArgs, ByVal view As GoView) As Boolean
Dim clickedTank As Tank = TryCast(view.GoObject.ParentNode, Tank)Case 1:

Error<span =“Apple-tab-span” style=“white-space:pre”> 1<span =“Apple-tab-span” style=“white-space:pre”> ‘GoObject’ is not a member of ‘Northwoods.Go.GoInputEventArgs’.

Case 2:

Error<span =“Apple-tab-span” style=“white-space:pre”> 1<span =“Apple-tab-span” style=“white-space:pre”> ‘GoObject’ is not a member of ‘Northwoods.Go.GoView’.

oh, right… that’s GoObjectEventArgs, not GoInputEventArgs… different context, not what we’re tanking about here.

Just go back to ellipse.ParentNode … which is “Me.ParentNode” in this context.

Dim tank As Tank = TryCast(Me.ParentNode, Tank )