SnapPoint on non existing object


I’d like to use GoView.SnapPoint when using external drag&drop so that my dropped object is on the grid. The problem is that at that time, I still don’t have any object (I only create some application object, whose graphical counterpart will be added later to the GoDocument through a notification system).

GoView.SnapPoint want, as one of its arguments, a GoObject. What will be done of it ? What happens if I pass a null value ? Should I instead pass a node of the good class, but that is not part of the document, only created for this purpose ?

Best regards,

Set GoView.DragsRealtime to true and GoView.ExternalDragDropsOnEnter to true.
Then when an external drag enters, the object-creation part of a drop actually happens (i.e., the object(s) are created, added to the document, and selected). All the rest of the behavior is now just like when dragging any document object(s) – as if it were an internal drag.
That’s how Planogrammer works:

  • to display the item being dragged from the palette
  • to snap it according to any grid in the document
  • to highlight any object that might receive it

The problem I believe is that, in those terms, a GoNode would be created when the drag&drop enters the diagram, and another one would be created when my application object notifies the graph that it has just been created.

I could probably change my notification system so that instead of creating a GoNode when an application object is created, it tries to reconnects to this newly created (and yet unattached to application object) node, but I’d rather not touch this part of the code.

Perhaps I don’t understand your application, but it seems to me that it really isn’t any different than in the case where GoView.ExternalDragDropsOnEnter is false.
In either case a GoObject is created and added to the GoDocument. The difference is when it happens (whether on drag-enter or on drop) and whether it automatically gets deleted on a drag-leave.
GoView.DoExternalDrop should just be called once during the normal external drag-and-drop scenario. Presumably your code shouldn’t care whether that is due to a drag-enter or a drop.

In fact, in our CustomGoView.DoExternalDrop, we never call GoView.DoExternalDrop, so we never directly create the GoNode. We only create our application object.

The GoNode is only created through some notification mechanisme from our application object.

The problem we have is that the application object also have the notion of coordinates, and in case of this drag&drop, we would like those coordinates to be aligned on the grid, but getting an snap point on the grid seems to require a GoObject in addition to the coordinates of the mouse cursor.

Ah, OK, I see what you mean. So the issue isn’t actually dependent on an external drag-and-drop, nor on when it happens – you just want to be able to snap the location of an object at a time when that object doesn’t actually exist as a GoObject in a GoDocument.
The reason that a GoObject is passed as an argument for the SnapPoint methods is that the particular GoObject can affect how it is snapped and how it positions itself relative to the grid. And each grid-like object itself can decide how to snap a particular object by considering arbitrary properties of the object (depending on the implementations of IGoDragSnapper.CanSnapPoint and .SnapPoint).
However, the implementations of GoGrid.CanSnapPoint and .SnapPoint do handle the case where the given GoObject is actually null. GoGrid.SnapPoint will just return the nearest grid point. So if you are using GoGrids you should be OK.

Ok, thank you once more for your time and your answers !