Link from one GoView to Another


#1

I’m writing a prototype of a State machine editor… The State machine is in a mdi app and States can have child states… they are then called super states… editing of a super state is done in another view (document) …
Inner states can link to Outer states … i want to start a link from the inner state and catch an event when going over the other document to take link and start it from the super state… im not sure im being totally clear… but a mechanism to start a link from som view to another would probably do the trick…without having to display the link crossing the views…

Thanks


#2

Hullo Patrick,
I think I am having a similar problem (See second part of earlier post: http://www.nwoods.com/forum/forum_posts.asp?TID=391&PN=1) I have built my app off the ProtoApp sample. I have created code that responds to a double-click of a Graphnode(image) placed on the drawing area. It roughly works as follows - When double-clicked, the code opens a new GraphViewWindow instance as an MDI child. In addition it creates a new layer for the MDI child (I have used the PartID of the creating Image Node to act as the LayerIdentifier. That way, an image has a direct connection to the layer that serves as its child.
The trouble I am still having, (hope Walter can help) is how to get the new GraphViewWindow to: (1) Use a New View (GraphView) which it does, (2) Point it to the same Document as the base layer (3) Show the newly created Layer. (How do I point a view to a particular document layer?).
Don’t know if this has clarified or helped your problem in any way - but using Layers seems the best way in my opinion. We just need to gain a bit more info on how to manipulate layers. The CreateLayerAfter and similar mechanisms do not have examples in the GoDocumentation.
Rainbirdit


#3

Actually, I suspect (but can’t tell for sure) that Patrick has a different problem. Namely that he would like to have the user’s normal link drawing operation act like a drag-and-drop to create some application-specific data structures that logically link the ports in different documents.
The problem is that GoToolLinkingNew, which implements the user’s drawing of a new link, uses a modal operation that doesn’t use Windows Forms drag-and-drop, so there can’t be any interaction with another window. When I get a chance, I’ll look into the possibilities for implementing such a gesture. I guess one issue is whether Patrick wants to allow users to do the normal linking operation between two ports within the same view/document.
An issue you (Patrick) didn’t raise is how to display such a cross-document “link”. One possibility is implemented by the Processor sample application (but just within one document) where the user can select an existing link and use the context menu command Replace With Remote Connectors. This breaks the link into two short parts, effectively inserting two nodes sharing the same identifier.


#4

Thanks for the replies. Actually the display is not a problem because the way my app works is : I have a State Diagram and linking from a child state to a parent state…links both parents (which are in the same document). I would like to investigate this layer thing…is it possible to use the same document on many views (in different mdi windows)? What im actually doing now is…the constructor of the link class sets the BeingCreatedLink of my main app so that on a mouse up i can find out if a link was dragged out of the mdi window…its not a solution i like very much…so if you have something better to offer I will gladly listen!


#5

Would it be possible to have some code that actually triggers a kind of drag and drop? it would be perfect…and i really need it. If i cant do this part, i dont think we will purchase GoDiagram[this is in no means arrogant]. I would gladly use a patch for now that i could switch later on when GoDiagram supports it the right way. Thanks.


#6

Assuming you don’t need to do regular linking between ports in the same view, I was going to explore using Control.DoDragDrop to start a drag-and-drop operation. This is what GoToolDragging does when it is started.


#7

No. I need to be able to draw links between states of the same view and links to different views…so both are needed. Another thing… i find it weird that while a link is being created (mouse down and dragging) …when PortChanged is called on the Link…i cant find out the From Node…the only way i managed to do it is by reflection this way :
Type t = port.GetType();

if(t.Name == “GoTemporaryPort”)
port = (IGoPort)t.InvokeMember(“Target”, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty, null, port, null);
Transition.FromState = (port.Node as StateView).State;


#8

You should be able to access all the temporary objects as properties of the GoToolLinkingNew tool:
GoToolLinkingNew linktool = goView1.FindMouseTool(typeof(GoToolLinkingNew)) as GoToolLinkingNew;
. . . linktool.Link.FromNode as StateView . . .
Regarding the linking across windows problem–you might be able to subclass the GoToolLinkingNew tool to notice where the mouse is in the DoMouseUp and DoMouseMove methods. If the LastInput.ViewPoint converted to screen coordinates is over another GoView and is near to a port you care about (converting back from screen coordinates to the other view’s coordinates and the other view’s document coordinates), then you could establish the link you wanted between the two ports.
Caveat lector–I haven’t tried anything like this before.


#9

Well. I’m happy to be the one that tries it for the first time! I will keep you informed on this matter! Thanks again!


#10

I tried getting the linkTool and asking for the FromNode property…but it is null…at which point can it be non-null…even overriding the DoMouseUp… the Link points to temporaryPorts and the FromNode is null…


#11

Ooops, that’s right–the temporary link is connected to the temporary ports.
Look at the OriginalStartPort or OriginalEndPort property, depending on whether the Forwards property is true.


#12

Ok i think i found a solution that aint that bad at all provided by your hints…
I subclassed GoToolLinkingNew() and overrided DoMouseUp :
In this class i have two new properties
1- LastFromNode = OriginalStartPort.Node;
2- LastToNode = Application.Instance.FindNodeAt(View.PointToScreen(LastInput .DocPoint))
In my MDI views…i listen on the MouseUp event…and if the tool as non-null LastFromNode && LastToNode…i know that a link was created between those two…Do you think its a good way to go? Thanks


#13

I don’t know if that’s a good way to go, but a couple of suggestions:
You need to convert from document coordinates to view coordinates, by using the GoView.Convert… methods, before you convert to screen coordinates. And vice-versa, going from screen to view to document. That way it will handle scrolled and scaled views.
FindNodeAt might want to use the GoToolLinkingNew.PickPort method to find an eligible port at a particular document point.